Linux内核中gpiolib

gpiolib库

Linux中的gpio属于资源型外设,所以内核要统一管理它的申请和释放。当一个以上的驱动
同时使用某个gpio时,gpiolib避免一个io同时被几个驱动和设备使用。


s5pv210中的gpiolib分析

函数s5pv210_gpiolib_init();分析

kernel\arch\arm\mach-s5pv210\gpiolib.c

s5pv210_gpiolib_init();

结构体 s3c_gpio_chip

kernel\arch\arm\plat-samsung\include\plat\gpio-core.h

struct s3c_gpio_chip 
{
	struct gpio_chip	chip;        //记录gpio设置方法和信息
	struct s3c_gpio_cfg	*config;     //记录gpio配置信息
	struct s3c_gpio_pm	*pm;         //电源管理
	void __iomem    *base;           //gpio对于的虚拟地址
	int	    eint_offset;
	spinlock_t	 lock;
#ifdef CONFIG_PM
	u32	 pm_save[7];
#endif
};

kernel\include\asm-generic\gpio,h

struct gpio_chip 
{
	const char	 *label;
	struct device   *dev;
	struct module   *owner;
	int		(*request)(struct gpio_chip *chip,unsigned offset);
	void	(*free)(struct gpio_chip *chip,unsigned offset);
	int		(*direction_input)(struct gpio_chip *chip,unsigned offset);
	int		(*get)(struct gpio_chip *chip,unsigned offset);
	int		(*direction_output)(struct gpio_chip *chip,unsigned offset, int value);
	int		(*set_debounce)(struct gpio_chip *chip,unsigned offset, unsigned debounce);
	void	(*set)(struct gpio_chip *chip,unsigned offset, int value);
	int		(*to_irq)(struct gpio_chip *chip,unsigned offset);
	void	(*dbg_show)(struct seq_file *s,struct gpio_chip *chip);
	int		base;
	u16		ngpio;
	const char	*const *names;
	unsigned	can_sleep:1;
	unsigned	exported:1;
};

函数指针: 申请使用gpio

int		(*request)(struct gpio_chip *chip,unsigned offset);

函数指针: 释放gpio

void	(*free)(struct gpio_chip *chip,unsigned offset);

函数指针: gpio方向设置成输入模式

int		(*direction_input)(struct gpio_chip *chip,unsigned offset);

函数指针: gpio方向设置成输出模式

int		(*direction_output)(struct gpio_chip *chip,unsigned offset, int value);

函数指针: gpio中断

int		(*to_irq)(struct gpio_chip *chip,unsigned offset);

==================================================================

struct s3c_gpio_cfg 
{
	unsigned int	cfg_eint;
	s3c_gpio_pull_t	(*get_pull)(struct s3c_gpio_chip *chip, unsigned offs);
	int		(*set_pull)(struct s3c_gpio_chip *chip, unsigned offs, s3c_gpio_pull_t pull);
	int		(*set_pin)(struct s3c_gpio_chip *chip, unsigned offs, s3c_gpio_pull_t level);
	unsigned (*get_config)(struct s3c_gpio_chip *chip, unsigned offs);
	int	 (*set_config)(struct s3c_gpio_chip *chip, unsigned offs,unsigned config);
};

结构体数组s5pv210_gpio_4bit

static struct s3c_gpio_chip s5pv210_gpio_4bit[] = {
	{
		.chip	= {
			.base	= S5PV210_GPA0(0),
			.ngpio	= S5PV210_GPIO_A0_NR,
			.label	= "GPA0",
			.to_irq = s5p_gpiolib_gpioint_to_irq,
		},
	}, {
		.chip	= {
			.base	= S5PV210_GPA1(0),
			.ngpio	= S5PV210_GPIO_A1_NR,
			.label	= "GPA1",
			.to_irq = s5p_gpiolib_gpioint_to_irq,
		},
	}, {
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值