我是靠谱客的博主 超级金毛,这篇文章主要介绍Linux内核中gpiolibgpiolib库,现在分享给大家,希望可以做个参考。

gpiolib库

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


s5pv210中的gpiolib分析

函数s5pv210_gpiolib_init();分析

kernelarcharmmach-s5pv210gpiolib.c

复制代码
1
2
s5pv210_gpiolib_init();

结构体 s3c_gpio_chip

kernelarcharmplat-samsungincludeplatgpio-core.h

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
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 };

kernelincludeasm-genericgpio,h

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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

复制代码
1
2
int (*request)(struct gpio_chip *chip,unsigned offset);

函数指针: 释放gpio

复制代码
1
2
void (*free)(struct gpio_chip *chip,unsigned offset);

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

复制代码
1
2
int (*direction_input)(struct gpio_chip *chip,unsigned offset);

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

复制代码
1
2
int (*direction_output)(struct gpio_chip *chip,unsigned offset, int value);

函数指针: gpio中断

复制代码
1
2
int (*to_irq)(struct gpio_chip *chip,unsigned offset);

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

复制代码
1
2
3
4
5
6
7
8
9
10
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

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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, }, }, { }

最后

以上就是超级金毛最近收集整理的关于Linux内核中gpiolibgpiolib库的全部内容,更多相关Linux内核中gpiolibgpiolib库内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部