常见泽1 发表于 2024-4-30 19:40

《原子嵌入式Linux驱动开发详解与实战》第6章 pinctrl和gpio子系统学习结合例程

<p><span style="font-size:16px;"><span style="font-family:Times;">Linux内核提供了pinctrl和gpio子系统用于GPIO驱动</span></span></p>

<p >&nbsp;</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 >&nbsp;</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 >&nbsp;</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;"> &nbsp;</span></span></p>

<p >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:Times;"> &nbsp;</span></span></p>

<p >&nbsp;</p>

<p >&nbsp;</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 >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:Times;">}</span></span></p>

<p >&nbsp;</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;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fsl,pins = &lt;</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:Times;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //设备使用的pin配置信息</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:Times;">&gt;</span></span></p>

<p >&nbsp;</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;"> &nbsp;</span></span></p>

<p >&nbsp;</p>

<p >&nbsp;</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 >&nbsp;</p>

<p >&nbsp;</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(&quot;/gpioled&quot;);</span></span></p>

<p >&nbsp;</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;">&nbsp;gpioled.led_gpio = of_get_named_gpio(gpioled.nd, &quot;led-gpio&quot;, 0);</span></span></p>

<p >&nbsp;</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;">&nbsp;&nbsp;&nbsp;gpio_direction_output(gpioled.led_gpio, 1);</span></span></p>

<p >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:Times;">然后注册设备字符驱动、创建删除设备</span></span></p>

<p >&nbsp;</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;"> &nbsp;</span></span></p>

chejm 发表于 2024-4-30 22:06

<p>支持一下楼主,辛苦了,感谢楼主分享的嵌入式Linux驱动开发的技术内容,希望楼主再接再厉</p>

秦天qintian0303 发表于 2024-5-1 08:33

<p>感谢楼主分享的嵌入式Linux驱动开发的技术内容&nbsp;&nbsp;</p>

孤独的单刀 发表于 2024-5-21 11:16

<p>不可多得的好东西,多谢楼主分享,接下来花点时间研究研究</p>

xhrain 发表于 2024-8-27 11:11

<table cellpadding="0" cellspacing="0">
        <tbody>
                <tr>
                        <td id="postmessage_3322930">
                        <p>感谢楼主,分享的嵌入式技术内容,支持一下楼主。&nbsp;&nbsp;</p>
                        </td>
                </tr>
        </tbody>
</table>

通途科技 发表于 2024-10-1 12:28

页: [1]
查看完整版本: 《原子嵌入式Linux驱动开发详解与实战》第6章 pinctrl和gpio子系统学习结合例程