MY-IMX6 Linux-3.0.35 gpio-leds Development

来自明远智睿的wiki
跳转至: 导航搜索

GPIO output & input

GPIO output & input take SD1_CLK leads as an example.

Modification “.h” file

1)Check configuration for SD1_CLK in file.
Example:
$ sed -n "/PAD_SD1_CLK/p" arch/arm/mach-mx6/board-mx6q_sabresd.h

2)Configuration for SD1_CLK in comment header file.
Example:
$ sed -i "s/MX6Q_PAD_SD1_CLK/\/\/ &/g" arch/arm/mach-mx6/board-mx6q_sabresd.h

3)Adding configuration for SD1_CLK in mx6q_sabresd_pads
Configure SD1_CLK function as MX6Q_PAD_SD1_CLK__GPIO_1_20
Example:
$ sed -i "/mx6q_sabresd_pads/a\\\t MX6Q_PAD_SD1_CLK__GPIO_1_20," \
arch/arm/mach-mx6/board-mx6q_sabresd.h

4)Check modified result
Example:
$ sed -n "/PAD_SD1_CLK/p" arch/arm/mach-mx6/board-mx6q_sabresd.h


Configure kernel

  • Mamu position

Device Drivers ---> -*- GPIO Support ---> [*] /sys/class/gpio/... (sysfs interface)
My imx6 gpio 1.2.0.1.jpg


Compilation

make uImage

Re-program system and boot

Device operation

Check out gpio directory

GPIO led out can bee seen under /sys/class/gpio/ directory
$ ls /sys/class/gpio/

  My imx6 gpio 1.5.1.1.jpg

Register GPIO to system

Register GPIO_1_20 to system with echo,then an extra gpio20 directory can be found under gpio directory.
Tips:I.MX6 GPIO value is calculation this way(where grouped - 1) * 32 + order number,so lead number of GPIO_1_20 is(1 – 1) * 32 + 20 = 20.
$ echo 20 > /sys/class/gpio/export

  My imx6 gpio 1.5.2.1.jpg

GPIO output control

  • Set leads as output state

$ echo out > /sys/class/gpio/gpio20/direction

  • Set lead output at high electrical level

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

  • Set lead output at low electrical level

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

Set lead as input state

  • Set lead as input state.

echo in > /sys/class/gpio/gpio20/direction

  • Gain lead value

cat /sys/class/gpio/gpio20/value

Logout GPIO interface

  • Logout GPIO_1_20

echo 20 > /sys/class/gpio/unexport

GPIO LED


Instruction:take GPIO LED以PAD NANDF_CS0 as example.

Enter kernel directory

$ cd ~/MY-I.MX6/linux-3.0.35/
My imx6 gpio 2.1.0.1.jpg

Add code

Modification.h file

1)Check out configuration for NANDF_CS0 in header file.
Example:
$ sed -n "/PAD_NANDF_CS0/p" arch/arm/mach-mx6/board-mx6q_sabresd.h

2)Comment configuration for NANDF_CS0 in header file.
Example:
$ sed -i "s/MX6Q_PAD_NANDF_CS0/\/\/ &/g" arch/arm/mach-mx6/board-mx6q_sabresd.h

3)Add configuration for NANDF_CS0 in mx6q_sabresd_pads.
Configure NANDF_CS0 function as MX6Q_PAD_NANDF_CS0__GPIO_6_11.
Example:
$ sed -i "/mx6q_sabresd_pads/a\\\tMX6Q_PAD_NANDF_CS0__GPIO_6_11," arch/arm/mach-mx6/board-mx6q_sabresd.h

4)Check out modified result.
Example:
$ sed -n "/PAD_NANDF_CS0/p" arch/arm/mach-mx6/board-mx6q_sabresd.h


Modification.c file

1)Check out whether GPIO is used repeatedly in .c file
Example:
$ sed -n '/IMX_GPIO_NR(6,.11)/p' arch/arm/mach-mx6/board-mx6q_sabresd.c

2)Add macro definition of GPIOin .c file
Add #define SABRESD_USER_LED IMX_GPIO_NR(6, 11)
Example:
$ GPIO_DEFINE="#define SABRESD_USER_LED\tIMX_GPIO_NR(6, 11)"
$ sed -i "1,/#define/{/#define/s/#define/${GPIO_DEFINE}\n&/}" arch/arm/mach-mx6/board-mx6q_sabresd.c

2)Check out data definition with gpio_led
Example:
$ sed -n '/struct gpio_led /,/\}/p' arch/arm/mach-mx6/board-mx6q_sabresd.c

3)Add data definition of user_led
static struct gpio_led imx6q_gpio_leds[] = {
    GPIO_LED(SABRESD_USER_LED, "user_led", 0, 1,
        "charger"),
};

Kernel configuration

  • manu position

Device Drivers ---> [*] LED Support ---> <*> LED Support for GPIO connected LEDs
My imx6 gpio 2.3.0.1.jpg

Compilation

make uImage

Re-program system and boot

GPIO_LED operation

Device file directory

To be saved under /sys/class/leds/user_led directory after booting system,which can be seen with ls.
$ ls /sys/class/leds/user_led

  My imx6 gpio 2.6.1.1.jpg

Operating example

1)Set NANDF_CS0 as 1
$ echo 1 > /sys/class/leds/user_led/brightness
2)Set NANDF_CS0 as 0
$ echo 0 > /sys/class/leds/user_led/brightness

GPIO按键(GPIO key)


GPIO按键以GPIO_4、EIM_BCLK、CSI0_DATA_EN为例,分别是原理图的按键SW2,SW3和SW4。
GPIO key by taking GPIO_4、EIM_BCLK、CSI0_DATA_EN as example,are separetely SW2,SW3和SW4 in schematic。

Modification.h file

1)Check out configuration for PAD in header file.
Example:
$ sed -n "/PAD_GPIO_4/p" arch/arm/mach-mx6/board-mx6q_sabresd.h
$ sed -n "/PAD_EIM_BCLK/p" arch/arm/mach-mx6/board-mx6q_sabresd.h
$ sed -n "/PAD_CSI0_DATA_EN/p" arch/arm/mach-mx6/board-mx6q_sabresd.h

2)Comment configuration for PAD in header file.
Example:
$ sed -i "s/MX6Q_PAD_GPIO_4/\/\/ &/g" arch/arm/mach-mx6/board-mx6q_sabresd.h
$ sed -i "s/MX6Q_PAD_EIM_BCLK/\/\/ &/g" arch/arm/mach-mx6/board-mx6q_sabresd.h
$ sed -i "s/MX6Q_PAD_CSI0_DATA_EN/\/\/ &/g" arch/arm/mach-mx6/board-mx6q_sabresd.h

3)Add configuration for PAD in mx6q_sabresd_pads.
Configure GPIO_4 function as MX6Q_PAD_GPIO_4__GPIO_1_4.
Example:
$ sed -i "/mx6q_sabresd_pads/a\\\tMX6Q_PAD_GPIO_4__GPIO_1_4," arch/arm/mach-mx6/board-mx6q_sabresd.h
Configure EIM_BCLK function as MX6Q_PAD_EIM_BCLK__GPIO_6_31.
Example:
$ sed -i "/mx6q_sabresd_pads/a\\\tMX6Q_PAD_EIM_BCLK__GPIO_6_31," arch/arm/mach-mx6/board-mx6q_sabresd.h
Configrue PAD function of CSI0_DATA_EN as MX6Q_PAD_CSI0_DATA_EN__GPIO_5_20.
Example:
$ sed -i "/mx6q_sabresd_pads/a\\\tMX6Q_PAD_CSI0_DATA_EN__GPIO_5_20," arch/arm/mach-mx6/board-mx6q_sabresd.h

4)Check out modified result
Example:
$ sed -n "/PAD_GPIO_4/p" arch/arm/mach-mx6/board-mx6q_sabresd.h
$ sed -n "/PAD_EIM_BCLK/p" arch/arm/mach-mx6/board-mx6q_sabresd.h
$ sed -n "/PAD_CSI0_DATA_EN/p" arch/arm/mach-mx6/board-mx6q_sabresd.h

Modification.c file

1)Check out whether GPIO is used repeatedly in .c file.
Example:
$ sed -n '/IMX_GPIO_NR(1,.4)/p' arch/arm/mach-mx6/board-mx6q_sabresd.c
$ sed -n '/IMX_GPIO_NR(6,.31)/p' arch/arm/mach-mx6/board-mx6q_sabresd.c
$ sed -n '/IMX_GPIO_NR(5,.20)/p' arch/arm/mach-mx6/board-mx6q_sabresd.c

2)Add macro definition of GPIO in .c file.

  • MX6Q_PAD_GPIO_4__GPIO_1_4

In .c file add #define SABRESD_POWER_OFF IMX_GPIO_NR(1, 4))
Example:
$ GPIO_DEFINE="#define SABRESD_POWER_OFF\tIMX_GPIO_NR(1, 4)"
$ sed -i "1,/#define/{/#define/s/#define/${GPIO_DEFINE}\n&/}" arch/arm/mach-mx6/board-mx6q_sabresd.c

  • MX6Q_PAD_CSI0_DATA_EN__GPIO_5_20

In .c file add #define SABRESD_VOLUME_UP IMX_GPIO_NR(6, 31).
Example:
$ GPIO_DEFINE="#define SABRESD_VOLUME_UP\tIMX_GPIO_NR(6, 31)"
$ sed -i "1,/#define/{/#define/s/#define/${GPIO_DEFINE}\n&/}" arch/arm/mach-mx6/board-mx6q_sabresd.c

  • MX6Q_PAD_CSI0_DATA_EN__GPIO_5_20

In .c file add #define SABRESD_VOLUME_DN IMX_GPIO_NR(5, 20))
Example:
$ GPIO_DEFINE="#define SABRESD_VOLUME_DN\tIMX_GPIO_NR(5, 20)"
$ sed -i "1,/#define/{/#define/s/#define/${GPIO_DEFINE}\n&/}" arch/arm/mach-mx6/board-mx6q_sabresd.c

3)Chech out data definition with gpio_keys_button.
Example:
$ sed -n '/gpio_keys_button/,/\}/p' arch/arm/mach-mx6/board-mx6q_sabresd.c

4)Add data definition for volume-up、volume-down、power.
static struct gpio_keys_button imx6q_buttons[] = {
GPIO_BUTTON(SABRESD_VOLUME_UP, KEY_VOLUMEUP, 1, "volume-up", 0, 1),
GPIO_BUTTON(SABRESD_VOLUME_DN, KEY_VOLUMEDOWN, 1, "volume-down", 0, 1),
GPIO_BUTTON(SABRESD_POWER_OFF, KEY_POWER, 1, "power", 1, 1),
};

Kernel configuration

  • manu position:

Device Drivers ---> Input device support ---> [*] Keyboards ---> <*> GPIO Buttons
My imx6 gpio 3.2.0.1.jpg

Compilation

make uImage

Re-program system and boot

GPIO key operation

GPIO_KEYS device

To be saved under /sys/devices/platform/gpio-keys directory after booting system,which can be seen with ls.

  My imx6 gpio 3.5.1.1.jpg

$ ls /sys/devices/platform/gpio-keys

Check out device information

Relatie information can be found in proc file system.
$ cat /proc/bus/input/devices

  My imx6 gpio 3.5.2.1.jpg

Device file

Event0 is matched up with device file corresponding to gpio key,check out with ls.

  My imx6 gpio 3.5.3.1.jpg

$ ls /dev/input/event0 –la

Operating example

Refer to Linux test manual.