Chinaunix首页 | 论坛 | 博客
  • 博客访问: 30995133
  • 博文数量: 230
  • 博客积分: 2868
  • 博客等级: 少校
  • 技术积分: 2223
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-08 21:48
个人简介

Live & Learn

文章分类

全部博文(230)

文章存档

2022年(2)

2019年(5)

2018年(15)

2017年(42)

2016年(24)

2015年(13)

2014年(1)

2012年(5)

2011年(58)

2010年(56)

2009年(9)

我的朋友

分类: LINUX

2017-03-22 15:01:00

内核版本:linux-3.14.38

以GPIO1_IO13为例:
1. 在arch/arm/boot/dts/imx6ul-14x14-evk.dts中:
 pinctrl_hog_1: hoggrp-1 {
                        fsl,pins = <
 
                               MX6UL_PAD_LCD_RESET__WDOG1_WDOG_ANY   0x30b0
                                MX6UL_PAD_UART1_RTS_B__GPIO1_IO19       0x17059
                                MX6UL_PAD_GPIO1_IO05__USDHC1_VSELECT    0x17059
                                MX6UL_PAD_GPIO1_IO09__GPIO1_IO09        0x17059

                                MX6UL_PAD_JTAG_TDI__GPIO1_IO13          0xC0000000     
                        >;
                };
MX6UL_PAD_JTAG_TDI__GPIO1_IO13:宏定义引脚JTAG_TDI功能复用为GPIO13;

0xC0000000:
  • 0x80000000 is special and means "I don't know and don't change from the default"
  • Bit 30 set to 1 means: software input on (SION) whcih means that the logical value of an output can be read back
注意:要把SION设为1,才可以用在gpio为output时读回,否则读回将为0。但根据Refernce Manual中,SION应该在software mux control registers的第四位,而0xC0000000设置的却是SW_PAD_CTL Register,而且Manual中也没看见这个寄存器能设置SION,这里很奇怪。

2. 在用户空间可控制gpio13:


echo 13 > /sys/class/gpio/export

echo out > /sys/class/gpio/gpio2/direction

echo 1 > /sys/class/gpio/gpio2/value

echo 0 > /sys/class/gpio/gpio2/value




参考链接:






imx6ul gpio_spi用法

  (2016-04-01 14:14:33)
在imx6ul-14x14-evk.dts中有这个一个设备树节点:
     spi4 {
                compatible = "spi-gpio";
                pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_spi4>;
                pinctrl-assert-gpios = <&gpio5 8 GPIO_ACTIVE_LOW>;
                status = "okay";
                gpio-sck = <&gpio5 11 0>;
                gpio-mosi = <&gpio5 10 0>;
                cs-gpios = <&gpio5 7 0>;
                num-chipselects = <1>;
                #address-cells = <1>;
                #size-cells = <0>;

                gpio_spi: gpio_spi@0 {
                        compatible = "fairchild,74hc595";
                        gpio-controller;
                        #gpio-cells = <2>;
                        reg = <0>;
                        registers-number = <1>;
                        registers-default = /bits/ 8 <0xb7>;
                        spi-max-frequency = <100000>;
                };
        };

这个设备对应的是移位寄存器(74hc595),作用是拓展gpio口,linux中驱动代码位于drivers/gpio/gpio-74x164.c。
SN74HC595N是德州仪器公司生产的集成电路芯片,是一个8位串行输入变串行输出或并行输出移位寄存器,具有高阻关断,高电平和低电平三态输出。在IO扩充上,可以最多串联15片,也就是高达120个IO扩充。



那么这种扩展出来的gpio应如何使用呢?原理图中Q0~Q7对应&gpio_spi0~7
举两个栗子说明:
1. 在用户空间控制Q7 -- LCD_nPWREN:
   ~# cat /sys/kernel/debug/gpio
   GPIOs 248-255, spi/spi32766.0, 74hc595, can sleep:
   所以,Q0~Q7对应gpio248~255

   ~# echo 255 > /sys/class/gpio/export
   ~# echo 0/1 > /sys/class/gpio/gpio255/value
 
 2. 在device tree中添加控制节点:
  backlight {
                compatible = "pwm-backlight";
                pwms = <&pwm1 0 5000000>;
                brightness-levels = <0 4 8 16 32 64 128 255>;
                default-brightness-level = <6>;
                enable-gpios = <&gpio_spi 7 GPIO_ACTIVE_LOW>;
                status = "okay";
        };
 
  在backlight的驱动中drivers/video/backlight/pwm_bl.c中已经有enable-gpio的获取和使用。
  系统启动后可以看到:
~# cat /sys/kernel/debug/gpio

GPIOs 248-255, spi/spi32766.0, 74hc595, can sleep:
 gpio-255 (enable              ) out lo
阅读(6998) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~