高通平台gpio在dst中的配置
2017-11-14 16:12
2166 查看
转自 http://blog.csdn.net/viewsky11/article/details/53402536
GPIO相关的dvice tree设置和interrupt设置
gpoi号以及gpio相关的属性设置
以tsp的proxy_en端口为例:
2
3
4
5
6
7
8
9
10
在相应的驱动里边,取gpio编号以及设置输入或者输入
2
3
4
那这个gpio的active的时候和sleep的时候的
其实是在pinctrl相关的dtsi文件里边设置的
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定义为例
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
如果定义了一个以上的interrupts号该怎么弄呢?
比如:
2
3
4
5
6
这种可以通过,
以下是
-
-
-
其中reg的组织形式为
其中的每一组address length表明了设备使用的一个地址范围。address为1个或多个32位的
整型(即cell),而length则为cell的列表或者为空(若
address 和 length 字段是可变长的,父结点的
reg属性的address和length字段的长度。
在本例中,root结点的
cpus 结点的
点的address为1,而length为空,于是形成了2个cpu的
external-bus结点的
ethernet、i2c、flash的reg字段形如
和
其中,address字段长度为0,开始的第一个
特别要留意的是i2c结点中定义的
pinctrl相关的的设置到底有什么用呢?在驱动里边常常碰到驱动相关的一个或者几个gpio,在
醒来或者睡眠的时候需要设置成不同的类型,不如醒来的时候是i2c端口,但睡眠的时候可能要
设置成GPIO并把输出设置成0等。
这个时候pinctrl就派上用场了,这个可以大大简化驱动的编写,因为这个可以像下面这样根据
active和suspend来设置要配置的gpio的管脚配置,然后在驱动里边调用
2
来实现
tree配置的话,如果是
具体
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。
在debug目录下,可以查到每个gpio的输入输出设置,以及当前的值。
2
3
如果想看更详细的GPIO设置的话
2
3
例:
2
3
4
5
6
7
8
9
10
11
12
13
14
查找Wakeup IRQ等
2
3
4
5
6
7
显示整个中断设置情况
2
GIC中断控制器的device tree定义的例子如下:
2
3
4
5
6
7
这里
高通的是这样的,当然其他芯片的还要具体看GIC控制器驱动。
申请中断的例子:
2
3
4
5
6
7
8
这里interrupts的3个数中,后面两个和前面说的一样的,分别是中断号和中断类型。
第三个数指定的中断类型:
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的中断号有些和
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-contro 1d810 ller;//指定当前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相关的设置
以下是reg,
address-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-0和
pinctrl-1里对应
tlmm_motor_active和
tlmm_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/unexport1
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 triggered1
2
3
4
5
6
7
显示整个中断设置情况
#cat /proc/interrupts1
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.txt1
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 interrupts cat 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 GIC 102: 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_irq 104: 650484 0 0 0 GIC MDSS 110: 0 0 0 0 GIC csiphy 111: 0 0 0 0 GIC csiphy 127: 0 0 0 0 GIC i2c-msm-v2-irq 128: 7585 0 0 0 GIC i2c-msm-v2-irq 130: 0 0 0 0 GIC i2c-msm-v2-irq 131: 0 0 0 0 GIC i2c-msm-v2-irq 132: 0 0 0 0 GIC i2c-msm-v2-irq 140: 384648 0 0 0 GIC msm_serial_hsl0 155: 12681898 0 0 0 GIC mmc0 157: 0 0 0 0 GIC mmc1 166: 1761 0 0 0 GIC msm_otg, msm_hsusb 170: 263953 0 0 0 GIC 7824900.sdhci 172: 0 0 0 0 GIC msm_otg 174: 207 0 0 0 GIC qcom,smd-wcnss 175: 5 0 0 0 GIC smp2p 176: 0 0 0 0 GIC qcom,smsm-wcnss 181: 0 0 0 0 GIC wcnss 200: 8461599 379482 175887 113247 GIC qcom,smd-rpm 203: 932778 390645 274255 170499 GIC 601d0.qcom,mpm 216: 0 0 0 0 GIC tsens_interrupt 222: 7 0 0 0 GIC 200f000.qcom,spmi 239: 0 0 0 0 GIC sps 240: 946 0 0 0 GIC 1000000.pinctrl 253: 2 0 0 0 GIC 7864900.sdhci 273: 0 0 0 0 GIC msm_iommu_nonsecure_irq 274: 0 0 0 0 GIC msm_iommu_nonsecure_irq 280: 1 0 0 0 GIC mobicore 288: 3 0 0 0 msm_tlmm_irq sm5703 290: 0 0 0 0 msm_tlmm_irq 7864900.sdhci cd 291: 6 0 0 0 qpnp-int qpnp_kpdpwr_status 292: 0 0 0 0 qpnp-int qpnp_resin_status 294: 0 0 0 0 qpnp-int qpnp_kpdpwr_resin_bark 295: 0 0 0 0 qpnp-int qpnp_rtc_alarm 297: 0 0 0 0 qpnp-int pm8916_tz 299: 1 0 0 0 qpnp-int qpnp_adc_tm_high_interrupt 300: 0 0 0 0 qpnp-int qpnp_adc_tm_low_interrupt 330: 0 0 0 0 msm_tlmm_irq k2hh_accel 338: 0 0 0 0 sm5703 otffail 348: 3 0 0 0 sm5703 topoff 349: 0 0 0 0 sm5703 done 357: 5 0 0 0 msm_tlmm_irq sm5703 muic micro USB 454: 932 2 1 1 msm_tlmm_irq zt7554_ts 455: 0 0 0 0 msm_tlmm_irq fuelgauge-irq 456: 0 0 0 0 msm_tlmm_irq sx9500_irq 457: 0 0 0 0 msm_tlmm_irq sx9500_wifi_irq 458: 0 0 0 0 smp2p_gpio modem 459: 1 0 0 0 smp2p_gpio error_ready_interrupt 460: 1 0 0 0 smp2p_gpio modem 461: 0 0 0 0 smp2p_gpio modem 490: 0 0 0 0 smp2p_gpio wcnss 491: 1 0 0 0 smp2p_gpio error_ready_interrupt 492: 1 0 0 0 smp2p_gpio wcnss 493: 0 0 0 0 smp2p_gpio wcnss 522: 2 0 0 0 msm_tlmm_irq home_key 523: 0 0 0 0 msm_tlmm_irq volume_up 524: 0 0 0 0 msm_tlmm_irq sec_headset_detect IPI0: 0 49521 49521 49521 CPU wakeup interrupts IPI1: 263118 216085 322849 349358 Timer broadcast interrupts IPI2: 5221229 10110805 7696353 5534579 Rescheduling interrupts IPI3: 585272 2348936 2593715 2633820 Function call interrupts IPI4: 2127 403855 275707 237116 Single function call interrupts IPI5: 0 0 0 0 CPU stop interrupts IPI6: 0 0 0 0 CPU backtrace Err: 0
相关文章推荐
- 配置学习总结高通平台GPIO
- 高通平台 GPIO interface Guide
- 高通平台 8074 spi 的配置
- 如何配置高通平台i2c 时序
- [高通平台小米4]的电源管理配置学习
- 在4418平台上如何配置GPIO口的状态
- 关于高通8053平台i2c和spi配置的学习总结
- 高通平台bootloader里面串口log输出配置方法 .
- 高通平台bootloader里面串口log输出配置方法
- imx6q平台的gpio配置方法
- 高通平台串口配置
- imx6q平台的gpio配置方法
- 关于高通8053平台i2c和spi配置的学习总结
- MT7628/MT7688平台上如何配置任何一个管脚为GPIO模式,试用各种平台
- [GPIO]MT2601平台L1.MP9版本DWS配置方法
- 高通GPIO配置简介
- 高通 msm平台GPIO相关的device tree设置
- 高通平台中gpio简单操作和调试