高通平台gpio在dst中的配置

来源:互联网 发布:淘宝买家分数 编辑:程序博客网 时间:2024/05/18 00:47

转自 http://blog.csdn.net/viewsky11/article/details/53402536

GPIO相关的dvice tree设置和interrupt设置

gpoi号以及gpio相关的属性设置

以tsp的proxy_en端口为例:

i2c@78b6000 { /* BLSP1 QUP2 */    compatible = "qcom,i2c-msm-v2";    ...    tmd3782@39 {        compatible = "taos,tmd3782";        ...        taos,en = <&msm_gpio 8 0x1>; //        ...    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

在相应的驱动里边,取gpio编号以及设置输入或者输入

//在tsp驱动里边,可以通过of_get_named_gpio()来取相应的gpio号pdata->enable = of_get_named_gpio(np, "taos,en", 0);gpio_direction_output(pdata->enable, 1);
  • 1
  • 2
  • 3
  • 4

那这个gpio的active的时候和sleep的时候的PULL_DOWN,PULL_UP,NO_PULL等属性在哪里设置呢? 
其实是在pinctrl相关的dtsi文件里边设置的

tlmm_pinmux: pinctrl@1000000 {    compatible = "qcom,msm-tlmm-8916";//看一下相应的驱动    reg = <0x1000000 0x300000>;    interrupts = <0 208 0>;    //gp: general purpose pins    //此外还有两种pin type:        //sdc : SDC pins        //qdsc: QDSC pins    /*General purpose pins*/    gp: gp {         qcom,pin-type-gp;        qcom,num-pins = <122>; //这个pin type里包含的pin的个数        #qcom,pin-cells = <1>;        msm_gpio: msm_gpio {            compatible = "qcom,msm-tlmm-gp";            gpio-controller;//指定当前msm_gpio为一个gpio-controller            #gpio-cells = <2>;             //#gpio-cells的值指定每个msm_gpio后面跟几个数来表示一个gpio。            //如果是2的话,就要像上面tsp一样写成taos,en = <&msm_gpio 8 0x1>;            //前面的8指定gpio号,但后面的还不是很清楚,应该是表示输入输出等,这里0x1表示输出            interrupt-controller; //表示可以用作中断控制器            #interrupt-cells = <2>;//两个的话,前面的表示irq号,后面的一个optional flags            num_irqs = <122>;//表示可以被用作中断源的pin的个数        };    };    //定义sdc pin type    /* Sdc pin type */    sdc: sdc {        qcom,num-pins = <6>;        #qcom,pin-cells = <1>;    };          prox_sensor_power {        qcom,pins = <&gp 8>; //使用的管脚数        qcom,pin-func = <0>;//输出        qcom,num-grp-pins = <1>;        //qcom,num-grp-pins,这个表示一共有几个pin        //msm-pinctrl.txt里边写的是number of pins in the group.        label = "prox_sensor_power";        //label: name to identify the pin group to be used by a client.        //以下是pinctrl的时候的设置,下面有pinctrl的说明        prox_power_active: prox_power_active {            drive-strength = <2>;//2MA            bias-disable; /* No PULL *///也可以写成 bias-disable = <0>;            //这里可以把bias-disable替换成bias-pull-up;或者bias-pull-down;         };        prox_power_suspend: prox_power_suspend {            drive-strength = <2>; //2MA            bias-disable; /* No PULL */        };    };
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56

在dts里边定义gpio相关的中断

以hall id相关的dtsi定义为例

hall {    status = "okay";    compatible = "hall";    interrupt-parent = <&msm_gpio>;//表示当前的中断控制器用的哪个,高通平台的dts文件中,                            //msm_gpio表示msm_tlmm_irq中断控制器。          interrupts = <52 0>;     //第一个52是指中断号,后面的0不知道表示什么,根据文档,这个值有以下意义    //1: low-to-high edge triggered    //2: high-to-low edge triggered    //3: active high-level-sensitive    //4: active low-level-sensitive    //Documentation/devicetree/bindings/arm/gic.txt    hall,gpio_flip_cover = <&msm_gpio 52 0>;};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

如果定义了一个以上的interrupts号该怎么弄呢? 
比如:

hall {...interrupts = <52 0> <62 0>; ...}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

这种可以通过,platform_get_irq(pdev,0)来取第一个irq号,platform_get_irq(pdev,1)来取第二个irq号。

reg相关的设置

以下是regaddress-cells,size-cells的解释,但还不知道从哪里读出来这些并设置??

-reg 
#address-cells 
-#size-cells 
其中reg的组织形式为 
reg = <address1 length1 [address2 length2] [address3 length3] ... >, 
其中的每一组address length表明了设备使用的一个地址范围。address为1个或多个32位的 
整型(即cell),而length则为cell的列表或者为空(若\#size-cells = 0)。 
address 和 length 字段是可变长的,父结点的#address-cells#size-cells分别决定了子结点的 
reg属性的address和length字段的长度。 
在本例中,root结点的#address-cells = <1>;#size-cells = <1>;决定了serial、gpio、spi等结点的address和length字段的长度分别为1。 
cpus 结点的#address-cells = <1>;#size-cells = <0>;决定了2个cpu子结 
点的address为1,而length为空,于是形成了2个cpu的reg = <0>;reg = <1>;。 
external-bus结点的#address-cells = <2>#size-cells = <1>;决定了其下的 
ethernet、i2c、flash的reg字段形如reg = <0 0 0x1000>;reg = <1 0 0x1000>; 
reg = <2 0 0x4000000>;。 
其中,address字段长度为0,开始的第一个cell(0、1、2)是对应的片选,第2个cell(0,0,0)是相对该片选的基地址,第3个cell(0x1000、0x1000、0x4000000)为length。 
特别要留意的是i2c结点中定义的 #address-cells = <1>;#size-cells = <0>;

pinctrl相关的设置

pinctrl相关的的设置到底有什么用呢?在驱动里边常常碰到驱动相关的一个或者几个gpio,在 
醒来或者睡眠的时候需要设置成不同的类型,不如醒来的时候是i2c端口,但睡眠的时候可能要 
设置成GPIO并把输出设置成0等。 
这个时候pinctrl就派上用场了,这个可以大大简化驱动的编写,因为这个可以像下面这样根据 
active和suspend来设置要配置的gpio的管脚配置,然后在驱动里边调用

devm_pinctrl_get_select(dev,"tlmm_motor_active");
  • 1
  • 2

来实现pinctrl-0pinctrl-1里对应tlmm_motor_activetlmm_motor_suspend的配置!!像下面的device tree配置的话,如果是devm_pinctrl_get_select(dev,”tlmm_motor_active”);则应该就是把pinctrl-0里边的gpio相关配置都配置上去。如果是devm_pinctrl_get_select(dev,”tlmm_motor_suspend”);的话就把pinctrl-1里边的设置都配置上去。 
具体devm_pinctrl_xxx这种接口说明也可以参考kernel下面的Documentation/pintrl.txt文件

&soc {    xxx,vibrator {        compatible = "haptic_vib";        //下面的pinctrl的设置,好像是没有在驱动里边读取并进行设置,        //不知道什么用~~        pinctrl-names = "tlmm_motor_active","tlmm_motor_suspend";        pinctrl-0 = <&motor_en_active &motor_pwm_active>;        pinctrl-1 = <&motor_en_suspend &motor_pwm_suspend>;        //下面en,pwm的设置前面已经讲过        xxx,vib_en = <&msm_gpio 76 0x1>;        xxx,vib_pwm = <&msm_gpio 50 0x1>;        xxx,vib_model = <1>;        xxx,is_pmic_vib_pwm = <0>;        xxx,pwm_period_us = <40>;        xxx,duty_us = <36>;        status = "ok";    };    //这里muic_i2c_active,muic_int_pin ,muic_chg_det这种都可以在gpio controller那里找到相应    //的设置,例如下面这样            tlmm_motor_en {            qcom,pins = <&gp 76>;            qcom,pin-func = <0>;            qcom,num-grp-pins = <1>;            label = "tlmm_motor_en";            motor_en_active: motor_en_active {                drive-strength = <2>;                bias-disable = <0>; /* No PULL */            };            motor_en_suspend: motor_en_suspend {                drive-strength = <2>;                bias-disable = <0>; /* No PULL */            };        };
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

在dts里边定义gpio和中断的文档

还有像gpio-ranges这种没有说明,可以再Documentation/devicetree/bindings/gpio/gpio.txt里边找到说明。 
还有一个是高通的gpio说明,在Documentation/devicetree/bindings/pintrl/msm-pintrl.txt。

在gpio和中断debug方法

在debug目录下,可以查到每个gpio的输入输出设置,以及当前的值。

#cat /d/gpio //这个命令只会显示AP设置的GPIO信息,不显示Modem设置的GPIO信息
  • 1
  • 2
  • 3

如果想看更详细的GPIO设置的话

#cat /d/gpiomux//显示AP,CP所有的GPIO的信息
  • 1
  • 2
  • 3

例:

//开始操作GPIO的时候必须要先执行#echo 30 > /sys/class/gpio/export//设置GPIO 30的输入输出#echo "out" > /sys/class/gpio/gpio30/direction#echo "in"  > /sys/class/gpio/gpio30/direction//改变GPIO 30的值#echo 1 > /sys/class/gpio/gpio30/value#echo 0 > /sys/class/gpio/gpio30/value//操作完毕需要执行如下命令#echo 30 > /sys/class/gpio/unexport
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

查找Wakeup IRQ等

#echo 1 > /sys/module/msm_show_resume_irq/parameters/debug_mask.//这样输入完之后,如果被中断唤醒就会输出如下log[ 75.0xxx] pm8xxx_show_resume_irq_chip: 479 triggered[ 75.0xxx] msm_gpio_show_resume_irq: 392 triggered[ 75.0xxx] gic_show_resume_irq: 48 triggered[ 75.0xxx] gic_show_resume_irq: 52 triggered
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

显示整个中断设置情况

#cat /proc/interrupts
  • 1
  • 2

GIC 中断控制器

GIC中断控制器的device tree定义的例子如下:

intc:interrupt-controller@F9000000{compitable = "qcom,msm-qgic2";interrupt-controller;//声明这个为一个中断控制器#interrup-cells = <3>;//高通的这里是3,具体看芯片的GIC中断控制器reg = <0xF9000000 0x1000> , <0xF900200 0x1000>;}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

这里interrupt-controller的意思跟上面解释的一样,但#interrupt-cells的值必须是3。 
高通的是这样的,当然其他芯片的还要具体看GIC控制器驱动。 
申请中断的例子:

device1@f991f000{    compatible = "qcom,msm-device-v1";    reg = <0xf991f000 0x1000>;    interrupt-parent = <&intc>; //指定中断控制器    interrupts = <0 131 0>, <0 179 0>;    interrupt-names = "irq" ,"otg_irq";};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

这里interrupts的3个数中,后面两个和前面说的一样的,分别是中断号和中断类型。 
第三个数指定的中断类型:

//1: low-to-high edge triggered //2: high-to-low edge triggered //3: active high-level-sensitive //4: active low-level-sensitive //Documentation/devicetree/bindings/arm/gic.txt
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

那第一个数表示什么呢?第一个数表示中断GIC的中断类型。 
0 表示:shared processor interrupts (SPI) 
1 表示:Private Pripheral Interrupts (PPI)

还有interrupt mapping内容看一下Linux Device Tree GPIO文档。


以下是打印的某个高通平台的/proc/interrupts的内容 
GIC的中断号有些和msmxxx.dtsi里边设置的终端号不一致,一般有一定的偏移量。之前看到过的是32,还没找在哪里设置的。

root@gtelltevzw:/proc # cat interruptscat interrupts           CPU0       CPU1       CPU2       CPU3 20:   11501064    2634910    1450801    1172471       GIC  arch_timer 35:          0          0          0          0       GIC  apps_wdog_bark 39:    5643824    2599019    1701936    1316131       GIC  arch_mem_timer 47:      52981          0          0          0       GIC  cpr 56:          0          0          0          0       GIC  modem 57:    1527948          0          0          0       GIC  qcom,smd-modem 58:          5          0          0          0       GIC  qcom,smsm-modem 59:          5          0          0          0       GIC  smp2p 61:         10          0          0          0       GIC  sps 65:      23838          0          0          0       GIC  kgsl-3d0 75:          0          0          0          0       GIC  msm_iommu_global_cfg_irq, msm_iommu_global_cfg_irq 76:        420          0          0          0       GIC  msm_vidc 82:         10          0          0          0       GIC  cci 83:          2          0          0          0       GIC  csid 84:          2          0          0          0       GIC  csid 89:          2          0          0          0       GIC102:          0          0          0          0       GIC  msm_iommu_nonsecure_irq, msm_iommu_nonsecure_irq, msm_iommu_nonsecure_irq, msm_iommu_nonsecure_irq, msm_iommu_nonsecure_irq, msm_iommu_nonsecure_irq, msm_iommu_nonsecure_irq, msm_iommu_nonsecure_irq, msm_iommu_secure_irq, msm_iommu_secure_irq, msm_iommu_secure_irq, msm_iommu_secure_irq, msm_iommu_secure_irq, msm_iommu_secure_irq, msm_iommu_nonsecure_irq, msm_iommu_nonsecure_irq, msm_iommu_nonsecure_irq, msm_iommu_nonsecure_irq, msm_iommu_nonsecure_irq, msm_iommu_nonsecure_irq104:     650484          0          0          0       GIC  MDSS110:          0          0          0          0       GIC  csiphy111:          0          0          0          0       GIC  csiphy127:          0          0          0          0       GIC  i2c-msm-v2-irq128:       7585          0          0          0       GIC  i2c-msm-v2-irq130:          0          0          0          0       GIC  i2c-msm-v2-irq131:          0          0          0          0       GIC  i2c-msm-v2-irq132:          0          0          0          0       GIC  i2c-msm-v2-irq140:     384648          0          0          0       GIC  msm_serial_hsl0155:   12681898          0          0          0       GIC  mmc0157:          0          0          0          0       GIC  mmc1166:       1761          0          0          0       GIC  msm_otg, msm_hsusb170:     263953          0          0          0       GIC  7824900.sdhci172:          0          0          0          0       GIC  msm_otg174:        207          0          0          0       GIC  qcom,smd-wcnss175:          5          0          0          0       GIC  smp2p176:          0          0          0          0       GIC  qcom,smsm-wcnss181:          0          0          0          0       GIC  wcnss200:    8461599     379482     175887     113247       GIC  qcom,smd-rpm203:     932778     390645     274255     170499       GIC  601d0.qcom,mpm216:          0          0          0          0       GIC  tsens_interrupt222:          7          0          0          0       GIC  200f000.qcom,spmi239:          0          0          0          0       GIC  sps240:        946          0          0          0       GIC  1000000.pinctrl253:          2          0          0          0       GIC  7864900.sdhci273:          0          0          0          0       GIC  msm_iommu_nonsecure_irq274:          0          0          0          0       GIC  msm_iommu_nonsecure_irq280:          1          0          0          0       GIC  mobicore288:          3          0          0          0  msm_tlmm_irq  sm5703290:          0          0          0          0  msm_tlmm_irq  7864900.sdhci cd291:          6          0          0          0  qpnp-int  qpnp_kpdpwr_status292:          0          0          0          0  qpnp-int  qpnp_resin_status294:          0          0          0          0  qpnp-int  qpnp_kpdpwr_resin_bark295:          0          0          0          0  qpnp-int  qpnp_rtc_alarm297:          0          0          0          0  qpnp-int  pm8916_tz299:          1          0          0          0  qpnp-int  qpnp_adc_tm_high_interrupt300:          0          0          0          0  qpnp-int  qpnp_adc_tm_low_interrupt330:          0          0          0          0  msm_tlmm_irq  k2hh_accel338:          0          0          0          0    sm5703  otffail348:          3          0          0          0    sm5703  topoff349:          0          0          0          0    sm5703  done357:          5          0          0          0  msm_tlmm_irq  sm5703 muic micro USB454:        932          2          1          1  msm_tlmm_irq  zt7554_ts455:          0          0          0          0  msm_tlmm_irq  fuelgauge-irq456:          0          0          0          0  msm_tlmm_irq  sx9500_irq457:          0          0          0          0  msm_tlmm_irq  sx9500_wifi_irq458:          0          0          0          0  smp2p_gpio  modem459:          1          0          0          0  smp2p_gpio  error_ready_interrupt460:          1          0          0          0  smp2p_gpio  modem461:          0          0          0          0  smp2p_gpio  modem490:          0          0          0          0  smp2p_gpio  wcnss491:          1          0          0          0  smp2p_gpio  error_ready_interrupt492:          1          0          0          0  smp2p_gpio  wcnss493:          0          0          0          0  smp2p_gpio  wcnss522:          2          0          0          0  msm_tlmm_irq  home_key523:          0          0          0          0  msm_tlmm_irq  volume_up524:          0          0          0          0  msm_tlmm_irq  sec_headset_detectIPI0:          0      49521      49521      49521  CPU wakeup interruptsIPI1:     263118     216085     322849     349358  Timer broadcast interruptsIPI2:    5221229   10110805    7696353    5534579  Rescheduling interruptsIPI3:     585272    2348936    2593715    2633820  Function call interruptsIPI4:       2127     403855     275707     237116  Single function call interruptsIPI5:          0          0          0          0  CPU stop interruptsIPI6:          0          0          0          0  CPU backtraceErr:          0 
原创粉丝点击