当前位置: 首页 > news >正文

【Linux 驱动】IMX6ULL gpio驱动

1. 概述

        如果 pinctrl子系统将一个 PIN 复用为 GPIO 的话,那么接下来要用到 gpio 子系统了。gpio 子系统顾名思义,就是用于初始化 GPIO 并且提供相应的 API 函数,比如设置 GPIO为输入输出,设置读取 GPIO 的值等。

        gpio 子系统的主要目的就是方便驱动开发者使用 gpio,驱动开发者在设备树中添加 gpio 相关信息,然后就可以在驱动程序中使用 gpio 子系统提供的 API函数来操作 GPIO,Linux 内核向驱动开发者屏蔽掉了 GPIO 的设置过程,极大的方便了驱动开发者使用 GPIO

Linux的GPIO子系统驱动框架由三个主要部分组成:① GPIO控制器驱动程序、②gpio lib驱动程序 ③GPIO字符设备驱动程序: 

2. gpio 子系统相关结构体

2.1 struct gpio_chip

/*** struct gpio_chip - abstract a GPIO controller* @label: for diagnostics* @dev: optional device providing the GPIOs* @owner: helps prevent removal of modules exporting active GPIOs* @list: links gpio_chips together for traversal* @request: optional hook for chip-specific activation, such as*	enabling module power and clock; may sleep* @free: optional hook for chip-specific deactivation, such as*	disabling module power and clock; may sleep* @get_direction: returns direction for signal "offset", 0=out, 1=in,*	(same as GPIOF_DIR_XXX), or negative error* @direction_input: configures signal "offset" as input, or returns error* @direction_output: configures signal "offset" as output, or returns error* @get: returns value for signal "offset"; for output signals this*	returns either the value actually sensed, or zero* @set: assigns output value for signal "offset"* @set_multiple: assigns output values for multiple signals defined by "mask"* @set_debounce: optional hook for setting debounce time for specified gpio in*      interrupt triggered gpio chips* @to_irq: optional hook supporting non-static gpio_to_irq() mappings;*	implementation may not sleep* @dbg_show: optional routine to show contents in debugfs; default code*	will be used when this is omitted, but custom code can show extra*	state (such as pullup/pulldown configuration).* @base: identifies the first GPIO number handled by this chip; or, if*	negative during registration, requests dynamic ID allocation.* @ngpio: the number of GPIOs handled by this controller; the last GPIO*	handled is (base + ngpio - 1).* @desc: array of ngpio descriptors. Private.* @names: if set, must be an array of strings to use as alternative*      names for the GPIOs in this chip. Any entry in the array*      may be NULL if there is no alias for the GPIO, however the*      array must be @ngpio entries long.  A name can include a single printk*      format specifier for an unsigned int.  It is substituted by the actual*      number of the gpio.* @can_sleep: flag must be set iff get()/set() methods sleep, as they*	must while accessing GPIO expander chips over I2C or SPI. This*	implies that if the chip supports IRQs, these IRQs need to be threaded*	as the chip access may sleep when e.g. reading out the IRQ status*	registers.* @exported: flags if the gpiochip is exported for use from sysfs. Private.* @irq_not_threaded: flag must be set if @can_sleep is set but the*	IRQs don't need to be threaded** A gpio_chip can help platforms abstract various sources of GPIOs so* they can all be accessed through a common programing interface.* Example sources would be SOC controllers, FPGAs, multifunction* chips, dedicated GPIO expanders, and so on.** Each chip controls a number of signals, identified in method calls* by "offset" values in the range 0..(@ngpio - 1).  When those signals* are referenced through calls like gpio_get_value(gpio), the offset* is calculated by subtracting @base from the gpio number.*/
struct gpio_chip {const char		*label;struct device		*dev;struct module		*owner;struct list_head        list;//请求一个 GPIO引脚int			(*request)(struct gpio_chip *chip,unsigned offset);//释放一个GPIO引脚void			(*free)(struct gpio_chip *chip,unsigned offset);//获取方向int			(*get_direction)(struct gpio_chip *chip,unsigned offset);//输入模式int			(*direction_input)(struct gpio_chip *chip,unsigned offset);//输出模式,并且set gpio valint			(*direction_output)(struct gpio_chip *chip,unsigned offset, int value);//读取 GPIO 引脚的值int			(*get)(struct gpio_chip *chip,unsigned offset);//设置gpio 引脚值void			(*set)(struct gpio_chip *chip,unsigned offset, int value);//设置多个gpio 引脚值void			(*set_multiple)(struct gpio_chip *chip,unsigned long *mask,unsigned long *bits);//设置 GPIO 引脚的去抖动时间int			(*set_debounce)(struct gpio_chip *chip,unsigned offset,unsigned debounce);int			(*to_irq)(struct gpio_chip *chip,unsigned offset);void			(*dbg_show)(struct seq_file *s,struct gpio_chip *chip);int			base;     //chip的基地址u16			ngpio;    //GPIO 引脚数量struct gpio_desc	*desc;    //gpio描述结构体数组,里面保存了此控制器可以控制的引脚描述const char		*const *names;bool			can_sleep;bool			irq_not_threaded;bool			exported;#ifdef CONFIG_GPIOLIB_IRQCHIP/** With CONFIG_GPIOLIB_IRQCHIP we get an irqchip inside the gpiolib* to handle IRQs for most practical cases.*/struct irq_chip		*irqchip;struct irq_domain	*irqdomain;unsigned int		irq_base;irq_flow_handler_t	irq_handler;unsigned int		irq_default_type;
#endif#if defined(CONFIG_OF_GPIO)/** If CONFIG_OF is enabled, then all GPIO controllers described in the* device tree automatically may have an OF translation*/struct device_node *of_node;int of_gpio_n_cells;int (*of_xlate)(struct gpio_chip *gc,const struct of_phandle_args *gpiospec, u32 *flags);
#endif
#ifdef CONFIG_PINCTRL/** If CONFIG_PINCTRL is enabled, then gpio controllers can optionally* describe the actual pin range which they serve in an SoC. This* information would be used by pinctrl subsystem to configure* corresponding pins for gpio usage.*/struct list_head pin_ranges;
#endif
};

 2.2 struct gpio_desc

struct gpio_desc {struct gpio_chip	*chip;    //属于哪个gpio_chipunsigned long		flags;    
/* flag symbols are bit numbers */
#define FLAG_REQUESTED	0
#define FLAG_IS_OUT	1
#define FLAG_EXPORT	2	/* protected by sysfs_lock */
#define FLAG_SYSFS	3	/* exported via /sys/class/gpio/control */
#define FLAG_TRIG_FALL	4	/* trigger on falling edge */
#define FLAG_TRIG_RISE	5	/* trigger on rising edge */
#define FLAG_ACTIVE_LOW	6	/* value has active low */
#define FLAG_OPEN_DRAIN	7	/* Gpio is open drain type */
#define FLAG_OPEN_SOURCE 8	/* Gpio is open source type */
#define FLAG_USED_AS_IRQ 9	/* GPIO is connected to an IRQ */
#define FLAG_SYSFS_DIR	10	/* show sysfs direction attribute */
#define FLAG_IS_HOGGED	11	/* GPIO is hogged */#define ID_SHIFT	16	/* add new flags before this one */#define GPIO_FLAGS_MASK		((1 << ID_SHIFT) - 1)
#define GPIO_TRIGGER_MASK	(BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE))const char		*label;   
};

3. IMX6ULL gpio-controller构造过程

 4. gpiochip_add

 

5. gpio api与gpio子系统的调用关系

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • sqlserver 消息 9420,级别 16,状态 1,第 7 行
  • 计算机二级Python经典易错题和题解
  • vue+elmentui 定义狂拽黑金配色的按钮+消息框
  • 如何在 Kubernetes 上快速部署 Python 和 Laravel 应用:一站式 DevOps 集成指南
  • 18.1 使用python进行网络请求与数据解析
  • Linux查看占用内存或者CPU前10的命令
  • Java参数校验(最佳实践)
  • 2024.8.19(静态文件共享、playbook)
  • Python进阶必看:深入解析yield的强大功能
  • Leetcode面试经典150题-15.三数之和
  • 故障诊断 | GNN图神经网络故障诊断(Python)
  • 用QTdesigner制作自己的双目标定软件
  • Java常用API第二篇
  • llama3 结构详解
  • Upload-Lab第12关:如何巧妙利用%00截断法绕过上传验证
  • 【391天】每日项目总结系列128(2018.03.03)
  • canvas 高仿 Apple Watch 表盘
  • idea + plantuml 画流程图
  • IDEA 插件开发入门教程
  • React as a UI Runtime(五、列表)
  • WePY 在小程序性能调优上做出的探究
  • 讲清楚之javascript作用域
  • 使用 Node.js 的 nodemailer 模块发送邮件(支持 QQ、163 等、支持附件)
  • 微信小程序实战练习(仿五洲到家微信版)
  • 我从编程教室毕业
  • Nginx惊现漏洞 百万网站面临“拖库”风险
  • ​Benvista PhotoZoom Pro 9.0.4新功能介绍
  • # Swust 12th acm 邀请赛# [ E ] 01 String [题解]
  • # 利刃出鞘_Tomcat 核心原理解析(八)-- Tomcat 集群
  • #1014 : Trie树
  • $Django python中使用redis, django中使用(封装了),redis开启事务(管道)
  • $jQuery 重写Alert样式方法
  • (2.2w字)前端单元测试之Jest详解篇
  • (Bean工厂的后处理器入门)学习Spring的第七天
  • (delphi11最新学习资料) Object Pascal 学习笔记---第8章第5节(封闭类和Final方法)
  • (Redis使用系列) Springboot 实现Redis消息的订阅与分布 四
  • (Redis使用系列) Springboot 整合Redisson 实现分布式锁 七
  • (经验分享)作为一名普通本科计算机专业学生,我大学四年到底走了多少弯路
  • (力扣记录)235. 二叉搜索树的最近公共祖先
  • (三十)Flask之wtforms库【剖析源码上篇】
  • (实测可用)(3)Git的使用——RT Thread Stdio添加的软件包,github与gitee冲突造成无法上传文件到gitee
  • (一)、软硬件全开源智能手表,与手机互联,标配多表盘,功能丰富(ZSWatch-Zephyr)
  • (译)2019年前端性能优化清单 — 下篇
  • (转载)在C#用WM_COPYDATA消息来实现两个进程之间传递数据
  • (自用)仿写程序
  • .equals()到底是什么意思?
  • .NET Core 和 .NET Framework 中的 MEF2
  • .NET MVC 验证码
  • .NET MVC第三章、三种传值方式
  • .net Stream篇(六)
  • .NET(C#、VB)APP开发——Smobiler平台控件介绍:Bluetooth组件
  • .NET开源纪元:穿越封闭的迷雾,拥抱开放的星辰
  • .net使用excel的cells对象没有value方法——学习.net的Excel工作表问题
  • .net通用权限框架B/S (三)--MODEL层(2)
  • 。。。。。