Difference between revisions of "i.MX53 SODIMM GPIO"
(Created page with "Category:i.MX53 SODIMM PC - Development kit Category:i.MX53 SODIMM PC Peripherals <!-- --> <div style="float:right">__TOC__</div> == Locating configuration file == T...") |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | [[Category:i.MX53 SODIMM PC - Development | + | [[Category:i.MX53 SODIMM PC - Development Kit]] |
[[Category:i.MX53 SODIMM PC Peripherals]] | [[Category:i.MX53 SODIMM PC Peripherals]] | ||
<!-- --> | <!-- --> | ||
Line 73: | Line 73: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | GPIO accessible from CSI0_DAT13 pin is available at this number: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
GPIO_NUMBER = MX53_PAD_CSI0_DAT13__GPIO5_31 = 5_31 = (5-1)*32+31 = 4*32+31 = 159 | GPIO_NUMBER = MX53_PAD_CSI0_DAT13__GPIO5_31 = 5_31 = (5-1)*32+31 = 4*32+31 = 159 | ||
Line 257: | Line 257: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | Printing current state (brightness) of output signals: | + | Printing the current state (brightness) of output signals: |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
root@vmx53 ~$ for i in /sys/class/leds/output-*/ ; do value=$(cat ${i}/brightness); echo $(basename ${i}) :: ${value}; done | root@vmx53 ~$ for i in /sys/class/leds/output-*/ ; do value=$(cat ${i}/brightness); echo $(basename ${i}) :: ${value}; done |
Latest revision as of 21:49, 23 October 2021
Locating configuration file
The initial CPU configuration is part the following device tree source file:
- arch/arm/boot/dts/imx53.dtsi
Shared module configuration can be found in the following file:
- arch/arm/boot/dts/imx53-vmx53.dtsi
The specific module configuration customised for i.MX53 SODIMM PC Module is part of these device tree source files:
- i.MX53 SODIMM PC Module Max: arch/arm/boot/dts/imx53-vmx53-557.dts
- i.MX53 SODIMM PC Module Pro: arch/arm/boot/dts/imx53-vmx53-668.dts
- i.MX53 SODIMM PC Module Basic: arch/arm/boot/dts/imx53-vmx53-779.dts
Note: In most cases just a single file edit is needed to apply modifications.
Definition of configuration macros
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_47K_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)
Controlling GPIO signals using raw access
In this example signals CSI0_DAT12 - CSI0_DAT19 will be configured as GPIOs.
Note: Make sure signals MX53_PAD_CSI0_DAT12_* up to MX53_PAD_CSI0_DAT19_* are set only once in all related device tree source files.
Device tree modification:
&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 >; }; }
Testing the modifications
Calculating GPIO number
GPIO pin numbering follows this general equation:
GPIO_NUMBER = MX53_PAD_NAME__GPIOX_Y = X_Y = (X-1)*32+Y
GPIO accessible from CSI0_DAT13 pin is available at this number:
GPIO_NUMBER = MX53_PAD_CSI0_DAT13__GPIO5_31 = 5_31 = (5-1)*32+31 = 4*32+31 = 159
Setting GPIO as output
root@vmx53 ~$ echo 159 > /sys/class/gpio/export root@vmx53 ~$ echo out > /sys/class/gpio/gpio159/direction root@vmx53 ~$ echo 0 > /sys/class/gpio/gpio159/value #root@vmx53 ~$ echo 1 > /sys/class/gpio/gpio159/value #root@vmx53 ~$ echo 159 > /sys/class/gpio/unexport
Setting GPIO as input
root@vmx53 ~$ echo 159 > /sys/class/gpio/export root@vmx53 ~$ echo in > /sys/class/gpio/gpio159/direction root@vmx53 ~$ cat /sys/class/gpio/gpio159/value 0 #root@vmx53 ~$ echo 159 > /sys/class/gpio/unexport
Controlling GPIO signals using drivers
Signals will be set accordingly:
- pins CSI0_DAT12 - CSI0_DAT14 as input GPIOs
- pins CSI0_DAT15 - CSI0_DAT17 as output GPIOs
Note: Make sure signals MX53_PAD_CSI0_DAT12_* up to MX53_PAD_CSI0_DAT17_* are set only once in all related device tree source files.
Device tree modification:
&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 >; }; ... }; ... }
Input signals
Adding GPIO kernel module
Device Drivers ---> Input device support ---> [*] Keyboards ---> <*> GPIO Buttons
Altering input sources in the device tree
/ { ... inputs { compatible = "gpio-keys"; #address-cells = <1>; #size-cells = <0>; autorepeat; input@0 { label = "input-0"; gpios = <&gpio5 30 GPIO_ACTIVE_HIGH>; linux,code = <0x100>; // BTN_0 }; input@1 { label = "input-1"; gpios = <&gpio5 31 GPIO_ACTIVE_HIGH>; linux,code = <0x101>; // BTN_1 }; input@2 { label = "input-2"; gpios = <&gpio6 0 GPIO_ACTIVE_HIGH>; linux,code = <0x102>; // BTN_2 }; }; ... };
Testing the modifications
root@vmx53 ~$ 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
Output signals
Adding GPIO kernel module
Device Drivers ---> [*] LED Support ---> <*> LED Class Support <*> LED Support for GPIO connected LEDs [*] LED Trigger support --->
Altering output sources in the device tree
/ { ... outputs { compatible = "gpio-leds"; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_out>; output@0 { label = "output-0"; gpios = <&gpio6 1 GPIO_ACTIVE_HIGH>; default-state = "keep"; }; output@1 { label = "output-1"; gpios = <&gpio6 2 GPIO_ACTIVE_HIGH>; default-state = "on"; }; output@2 { label = "output-2"; gpios = <&gpio6 3 GPIO_ACTIVE_HIGH>; default-state = "off"; }; }; ... };
Testing the modifications
root@vmx53 ~$ cat /sys/class/leds/output-0/trigger [none] nand-disk mmc0 mmc1 timer heartbeat backlight gpio default-on root@vmx53 ~$ cat /sys/class/leds/output-0/brightness 0 root@vmx53 ~$ echo 255 > /sys/class/leds/output-0/brightness # On root@vmx53 ~$ echo 0 > /sys/class/leds/output-0/brightness # Off
Printing the current state (brightness) of output signals:
root@vmx53 ~$ 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
root@vmx53 ~$ mount -t debugfs none /sys/kernel/debug
root@vmx53 ~$ 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: