《原子嵌入式Linux驱动开发详解与实战》第6章 pinctrl和gpio子系统学习结合例程
<p><span style="font-size:16px;"><span style="font-family:Times;">Linux内核提供了pinctrl和gpio子系统用于GPIO驱动</span></span></p><p > </p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">Pinctrl子系统</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">Linux驱动讲究驱动分离与分层,linux内核针对pin的配置推出来pinctrl子系统,对于gpio配置推出来GPIO子系统</span></span></p>
<p > </p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">Pinctrl子系统的工作内容</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">1获取设备书中的pin信息</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">2根据获取的pin信息来设置pin的复用功能</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">3根据获取的Pin信息来设置啤n的电气特性:上下拉 速度</span></span></p>
<p > </p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">驱动文件在</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;"> </span></span></p>
<p > </p>
<p ><span style="font-size:16px;"><span style="font-family:Times;"> </span></span></p>
<p > </p>
<p > </p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">如何添加pinctrl节点模板</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">1创建对应的节点</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">Pinctrl_test:testgrp{</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">//具体的pin信息</span></span></p>
<p > </p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">}</span></span></p>
<p > </p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">2添加fsl,pin属性</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">Pinctrl_test:testgrp{</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;"> fsl,pins = <</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;"> //设备使用的pin配置信息</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">></span></span></p>
<p > </p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">};</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">看下gpio_led的代码</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;"> </span></span></p>
<p > </p>
<p > </p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">GPIO子系统就是用于初始化GPIO并且提供相应的API函数</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">获取 GPIO 编号函数 of_get_named_gpio</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">GPIO 申请函数 gpio_request</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">GPIO 输出设置函数 gpio_direction_output</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">GPIO 输入设置函数 gpio_direction_input</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">获取 GPIO 引脚值函数 gpio_get_value</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">设置 GPIO 输出值 gpio_set_value</span></span></p>
<p > </p>
<p > </p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">Led驱动程序解析</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">1获取设备节点gpio_led</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">gpioled.nd = of_find_node_by_path("/gpioled");</span></span></p>
<p > </p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">2获取设备树的gpio属性得到LED所使用的LED编号</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;"> gpioled.led_gpio = of_get_named_gpio(gpioled.nd, "led-gpio", 0);</span></span></p>
<p > </p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">3设置电平</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;"> gpio_direction_output(gpioled.led_gpio, 1);</span></span></p>
<p > </p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">然后注册设备字符驱动、创建删除设备</span></span></p>
<p > </p>
<p ><span style="font-size:16px;"><span style="font-family:Times;">测试代码</span></span></p>
<p ><span style="font-size:16px;"><span style="font-family:Times;"> </span></span></p>
<p>支持一下楼主,辛苦了,感谢楼主分享的嵌入式Linux驱动开发的技术内容,希望楼主再接再厉</p>
<p>感谢楼主分享的嵌入式Linux驱动开发的技术内容 </p>
<p>不可多得的好东西,多谢楼主分享,接下来花点时间研究研究</p>
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td id="postmessage_3322930">
<p>感谢楼主,分享的嵌入式技术内容,支持一下楼主。 </p>
</td>
</tr>
</tbody>
</table>
页:
[1]