Wiki Home » vmx53 » gpio

gpio

Last modified by Administrator on 2015/03/01 18:05

Examples

Common

Device tree

Initial SOC configuration is part the following device tree source files

  • arch/arm/boot/dts/imx53.dtsi

Shared module configuration is part the following device tree source files

  • arch/arm/boot/dts/imx53-vmx53.dtsi

Specific module configuration is part of device tree source files

  • arch/arm/boot/dts/imx53-vmx53-557.dts
  • arch/arm/boot/dts/imx53-vmx53-668.dts
  • arch/arm/boot/dts/imx53-vmx53-779.dts
Usually only the single module HW configuration needs to be edited.

CONFIG bits definition:

PAD_CTL_HVE                     (1 << 13)
PAD_CTL_HYS                     (1
<< 8)
PAD_CTL_PKE                     (1 << 7)
PAD_CTL_PUE                     (1 << 6)
PAD_CTL_PUS_100K_DOWN           (0 << 4)
PAD_CTL_PUS_47
K_UP              (1 << 4)
PAD_CTL_PUS_100K_UP             (2 << 4
)
PAD_CTL_PUS_22K_UP              (3 << 4)
PAD_CTL_ODE                     (1 << 3)
PAD_CTL_DSE_LOW                 (0 << 1)
PAD_CTL_DSE_MED                 (1 << 1)
PAD_CTL_DSE_HIGH                (2 << 1)
PAD_CTL_DSE_MAX                 (3
<< 1)
PAD_CTL_SRE_FAST                (1
<< 0)
PAD_CTL_SRE_SLOW (0
<< 0)

Gpio (Using raw access)

GPIO configuration

Switching PADs CSI0_DAT12 - CSI0_DAT19 into gpio.

Make sure MX53_PAD_CSI0_DAT12_* up to MX53_PAD_CSI0_DAT19_* are set only once in all related device tree source files.

Device tree file

&iomuxc {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_hog>;

imx53-vmx53 {
pinctrl_hog: hoggrp {
fsl,pins = <
                            MX53_PAD_CSI0_DAT12__GPIO5_30 0x80000000 // PAD default config
                            MX53_PAD_CSI0_DAT13__GPIO5_31 0x000000e0 // PKE + PUE + PUS_47K_UP + DSE_LOW + SRE_SLOW
                            MX53_PAD_CSI0_DAT14__GPIO6_0  0x00000100 // HYS + DSE_LOW + SRE_SLOW
                            MX53_PAD_CSI0_DAT15__GPIO6_1  0x000000c0 // PKE + PUE + PUS_100K_DOWN + DSE_LOW + SRE_SLOW
                            MX53_PAD_CSI0_DAT16__GPIO6_2  0x80000000 // PAD default config
                            MX53_PAD_CSI0_DAT17__GPIO6_3  0x80000000 // PAD default config
                            MX53_PAD_CSI0_DAT18__GPIO6_4  0x80000000 // PAD default config
                            MX53_PAD_CSI0_DAT19__GPIO6_5  0x80000000 // PAD default config
>;
};
}

Test

Calculating GPIO number

GPIO_NUMBER = MX53_PAD_CSI0_DAT13__GPIOX_Y  = X_Y  = (X-1)*32+Y
GPIO_NUMBER = MX53_PAD_CSI0_DAT13__GPIO5_31 = 5_31 = (5-1)*32+31 = 4*32+31 = 159

Set GPIO as output

[email protected] ~echo 159 > /sys/class/gpio/export
[email protected] ~echo out > /sys/class/gpio/gpio159/direction
[email protected] ~echo 0 > /sys/class/gpio/gpio159/value
#[email protected] ~$ echo 1 > /sys/class/gpio/gpio159/value
#[email protected] ~$ echo 159 > /sys/class/gpio/unexport

Set GPIO as input

[email protected] ~echo 159 > /sys/class/gpio/export
[email protected] ~echo in > /sys/class/gpio/gpio159/direction
[email protected] ~cat /sys/class/gpio/gpio159/value
0
#[email protected] ~$ echo 159 > /sys/class/gpio/unexport

Gpio (Using drivers)

GPIO configuration

Switching PADs CSI0_DAT12 - CSI0_DAT14 into input gpio.
Switching PADs CSI0_DAT15 - CSI0_DAT17 into output gpio.

Make sure MX53_PAD_CSI0_DAT12_* up to MX53_PAD_CSI0_DAT17_* are set only once in all related device tree source files.

Device tree file

&iomuxc {
    ...

imx53-vmx53 {
        ...

pinctrl_inp: inpgrp {
        fsl,pins = <
                            MX53_PAD_CSI0_DAT12__GPIO5_30 0x80000000 // PAD default config
                            MX53_PAD_CSI0_DAT13__GPIO5_31 0x80000000 // PAD default config
                            MX53_PAD_CSI0_DAT14__GPIO6_0  0x80000000 // PAD default config
>;
};

pinctrl_out: outgrp {
fsl,pins = <
                            MX53_PAD_CSI0_DAT15__GPIO6_1  0x80000000 // PAD default config
                            MX53_PAD_CSI0_DAT16__GPIO6_2  0x80000000 // PAD default config
                            MX53_PAD_CSI0_DAT17__GPIO6_3  0x80000000 // PAD default config
>;
};
        ...
       };
    ...
}

GPIO input ("gpio-keys")

Kernel driver

    Device Drivers  --->
        Input device support  --->
   [*]   Keyboards  --->
                <*>   GPIO Buttons

Device tree file

/ {
    ...

inputs {
           compatible = "gpio-keys";
           #address-cells = <1>;
           #size-cells = <0>;
           autorepeat;

[email protected] {
label = "input-0";
gpios = <&gpio5 30 GPIO_ACTIVE_HIGH>;
linux,code = <0x100>; // BTN_0
};

[email protected] {
label = "input-1";
gpios = <&gpio5 31 GPIO_ACTIVE_HIGH>;
linux,code = <0x101>; // BTN_1
};

[email protected] {
label = "input-2";
gpios = <&gpio6 0 GPIO_ACTIVE_HIGH>;
linux,code = <0x102>; // BTN_2
};
};
    ...
};

Test

[email protected] ~evtest /dev/input/event4
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "inputs.12"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 256 (BTN_0)
    Event code 257 (BTN_1)
    Event code 258 (BTN_2)
Properties:
  Property type 20 (EV_REP)
    Property code 0 (REP_DELAY)
      Value    250
    Property code 1 (REP_PERIOD)
      Value     33
Testing ... (interrupt to exit)
Event: time 946946772.718139, type 1 (EV_KEY), code 256 (BTN_0), value 1
Event: time 946946772.718139, -------------- SYN_REPORT ------------
Event: time 946946772.968114, type 1 (EV_KEY), code 256 (BTN_0), value 2
Event: time 946946772.968114, -------------- SYN_REPORT ------------
Event: time 946946773.008115, type 1 (EV_KEY), code 256 (BTN_0), value 2
Event: time 946946773.008115, -------------- SYN_REPORT ------------
Event: time 946946773.018134, type 1 (EV_KEY), code 256 (BTN_0), value 0
Event: time 946946773.018134, -------------- SYN_REPORT ------------
Event: time 946946786.688130, type 1 (EV_KEY), code 256 (BTN_0), value 1
Event: time 946946786.688130, -------------- SYN_REPORT ------------
Event: time 946946786.908131, type 1 (EV_KEY), code 256 (BTN_0), value 0

GPIO output ("gpio-leds")

Kernel driver

    Device Drivers  --->
       [*] LED Support  --->
            <*>   LED Class Support
            <*>   LED Support for GPIO connected LEDs
           [*]   LED Trigger support  ---> 

Device tree file

/ {
    ...
outputs {
compatible = "gpio-leds";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_out>;

[email protected] {
label = "output-0";
gpios = <&gpio6 1 GPIO_ACTIVE_HIGH>;
default-state = "keep";
};

[email protected] {
label = "output-1";
gpios = <&gpio6 2 GPIO_ACTIVE_HIGH>;
default-state = "on";
};

[email protected] {
label = "output-2";
gpios = <&gpio6 3 GPIO_ACTIVE_HIGH>;
default-state = "off";
};
};
    ...
};

Test

[email protected] ~cat /sys/class/leds/output-0/trigger
[none] nand-disk mmc0 mmc1 timer heartbeat backlight gpio default-on
[email protected] ~cat /sys/class/leds/output-0/brightness
0
[email protected] ~echo 255 > /sys/class/leds/output-0/brightness # On
[email protected] ~echo 0 > /sys/class/leds/output-0/brightness # Off
[email protected] ~for i in /sys/class/leds/output-*/ ; do value=$(cat ${i}/brightness); echo $(basename ${i}) :: ${value}; done
output-0 :: 0
output-1 :: 255
output-2 :: 0

Debugging

[email protected] ~mount -t debugfs none /sys/kernel/debug
[email protected] ~cat /sys/kernel/debug/gpio
GPIOs 0-31, platform/53f84000.gpio, 53f84000.gpio:
 gpio-7   (usbotg_vbus         ) out lo

GPIOs 32-63, platform/53f88000.gpio, 53f88000.gpio:
 gpio-48  (spi_imx             ) out lo
 gpio-49  (spi_imx             ) out lo
 gpio-52  (ads7846_pendown     ) in  hi
 gpio-62  (spi_imx             ) out lo

GPIOs 64-95, platform/53f8c000.gpio, 53f8c000.gpio:
 gpio-83  (spi_imx             ) out lo
 gpio-88  (50004000.esdhc cd   ) in  hi
 gpio-89  (50008000.esdhc cd   ) in  hi
 gpio-93  (led-red             ) out lo
 gpio-95  (usbh1_vbus          ) out lo

GPIOs 96-127, platform/53f90000.gpio, 53f90000.gpio:

GPIOs 128-159, platform/53fdc000.gpio, 53fdc000.gpio:
 gpio-132 (LCD PEN             ) out lo
 gpio-158 (input-0             ) in  lo
 gpio-159 (input-1             ) in  lo

GPIOs 160-191, platform/53fe0000.gpio, 53fe0000.gpio:
 gpio-160 (input-2             ) in  lo
 gpio-161 (output-0            ) out lo
 gpio-162 (output-1            ) out lo
 gpio-163 (output-2            ) out lo

GPIOs 192-223, platform/53fe4000.gpio, 53fe4000.gpio:
Tags:
Created by Administrator on 2015/01/17 19:46

This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 6.1 - Documentation