This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

how to add a new GPIO based LEDs to sysfs directory .....

Other Parts Discussed in Thread: AM3358

Hi all,


I am using Beagle bone black in this board i am added 3 gpio based leds which is interface to GPIO2_6,GPIO2_7,GPIO2_8 pins for these how to update device tree and  by default 4 leds(usr0 to usr3) updated in DT file ...... i need to add above 3 leds in DT file please tell me process...........

ex of dt file:
        led@2 {
            label = "beaglebone:green:heartbeat";
            gpios = <&gpio1 21 GPIO_ACTIVE_HIGH>;
            linux,default-trigger = "heartbeat";
            default-state = "off";
        };

sysfs class and device nodes:

root@am335x-evm:/sys/class/leds# ls
  beaglebone:green:heartbeat  beaglebone:green:usr2  // attr
  beaglebone:green:mmc0       beaglebone:green:usr3

root@am335x-evm:/sys/class/leds/beaglebone:green:usr3# ls
brightness      max_brightness  subsystem       uevent
device          power           trigger
root@am335x-evm:/sys/class/leds/beaglebone:green:usr3# cat trigger

none nand-disk mmc0 [mmc1] timer oneshot heartbeat backlight gpio cpu0 default-on

Thanks

shankar

  • Hi Shankar,

    What you want to do it there in StarteKit configurations. Please see initializations in am335x-evmsk.dts file. Of course you have to change the gpio pins, but it's a good example for your purpose.

    BR
    Ivan
  • Hi Ivan Matrakov,

      Thanks for reply, I want to control my gpio leds through sysfs filesystem  like user defined leds(usr0 to usr3), how can i approach to sysfs directory in which (sys/class/leds/label_name/attributes) how can i create attributes under label

    Ex :

    root@am335x-evm:/sys/class/leds/beaglebone:green:usr3# ls
    brightness      max_brightness  subsystem       uevent
    device          power           trigger

  • Hi Shankar,

    If you want to control leds through sysfs you have to remove their definitions from the xxx.dts file and from console to write:
    root@am335x-evm:~# echo xx > /sys/class/gpio/export
    root@am335x-evm:~# echo out > /sys/class/gpio/gpioxx/direction
    root@am335x-evm:~# echo 1 > /sys/class/gpio/gpioxx/value
    root@am335x-evm:~# echo 0 > /sys/class/gpio/gpioxx/value
    where the xx is number of gpio calculated as 32*bank + gpio. For example if the gpio is gpio1_22
    root@am335x-evm:~# echo 54 > /sys/class/gpio/export
    root@am335x-evm:~# echo out > /sys/class/gpio/gpio54/direction
    root@am335x-evm:~# echo 1 > /sys/class/gpio/gpio54/value
    root@am335x-evm:~# echo 0 > /sys/class/gpio/gpio54/value

    You can read this in a:
    processors.wiki.ti.com/.../Linux_PSP_GPIO_Driver_Guide
    Please see what is needed to initialize in xxxdefconfig file. In's setting by default, but see it.

    BR
    Ivan
  • Hi Ivan Matrakov,

    Thank you.... using above commands user can control manually gpio leds from shell prompt and above commands are working fine but i want to create sysfs attributes at boot time, like brightness, max_brightness and trigger

    ex of controlling usr3 led:
    root@am335x-evm:~# echo 1 >/sys/class/leds/beaglebone:green:usr3\brightness
    root@am335x-evm:~# echo 1 >/sys/class/leds/beaglebone:green:usr3\brightness
  • Hi Shankar,

    This is not so easy. To do this you have to read:
    <>ti-sdk-am335x-evm-07.00.00.00/board-support/linux-3.12.10-ti2013.12.0/Documentation/leds/leds-class.txt
    <>ti-sdk-am335x-evm-07.00.00.00/board-support/linux-3.12.10-ti2013.12.0/Documentation/leds/leds-blinkm.txt

    You can see that in a /sys/devices/backlight.9/backlight/backlight.9 directory there are some files as:
    actual_brightness
    brightness
    max_brightness

    Changing the value in a brightness file you will change the brightness of the screen.

    BR
    Ivan
  • Hi Ivan Matrakov,
    Thank you ...... I am studied leds txt file as well as I am go through led based platform driver pgms like leds-gpio.c ,led-class.c and their i found sysfs related macro attributes, call back functions sys_ops structure( show,store) is it use full for me,
    In DTS am335x-bone-common.dtsi file i am changed label name and gpio flags and after compilation i able see sysfs attributes all leds, my question is it correct process for controlling user defined gpio-leds through sysfs ,is it correct then i am going to interface gpio-leds for bbb board.
    DTS file:
    pin muxing:
    0xa0 (PIN_INPUT_PULLDOWN | MUX_MODE7) /* lcd_data0.gpio2_6 D0/Away_LED 0x481A_C000*/

    /* shan gpio_led nodes*/
    led@6 {
    label = "Away_led";
    gpios = <&gpio2 6 GPIO_ACTIVE_HIGH>;
    linux,default-trigger = "heartbeat";
    default-state = "on";
    };

    root@am335x-evm:/sys/class/leds# ls
    Alaram_led RGB_cntr2
    Away_led beaglebone:green:heartbeat
    Error_led beaglebone:green:mmc0
    HF_led beaglebone:green:usr2
    RGB_cnt0 beaglebone:green:usr3
    RGB_cntr1

    root@am335x-evm:/sys/class/leds# cd RGB_cnt0
    root@am335x-evm:/sys/class/leds/RGB_cnt0# ls

    brightness max_brightness subsystem uevent
    device power trigger

    root@am335x-evm:/sys/class/leds/RGB_cnt0# cat brightness
    0
  • Hi Shankar,

    For me the better way to control lcds is through kernel, but I don't know your case to give you any advice. For some cases control through sysfs is better.

    BR
    Ivan
  • Hi Ivan Matrakov,

    Thank you ..... I am unable to understand gpio and gpio-leds driver.

    1. from gpio based testing woking fine i am able togole all leds....... ex: echo 70 > /sys/class/gpio/export ; echo out > /sys/class/gpio/gpio70/direction ; echo 1 > /sys/class/gpio/gpio70/value
    2. In gpio-leds driver i am able toggle board defined(usr0 -usr3) leds only not user defined leds like gpio2_6 7 8
    3. Because my custom board we using am3358 processor and ti sdk 7.
    4. my requirement is i am able to control all leds through sysfs(sys/class/leds/device_name/attributes) in this case i able see all leds attributes but no use , if i do any kernel config or any changes driver level , is it possible or please give me suggestion for controlling leds
    5. Is TI sdk 7(3.12 kernel) gpio-leds driver support for board define leds only not others .............
  • Hi Shankar,

    If make what is written on the: processors.wiki.ti.com/.../Linux_PSP_GPIO_Driver_Guide
    you will see that you can control all used gpio's. The gpio2_6 7 8 you have to initialize in dts and kernel. But you have to add gpio_export(xx, true); command (did you see this). Now with this command you can see all exported gpio's with sysfs and can control with kernel and sysfs.

    BR
    Ivan
  • Hi Ivan Matrakov,

    Thank you.....could you explain all used gpio's means these gpio2_6 7 8 pins used some other driver, where can i export these pins....
  • Hi Ivan Matrakov,
    once see gpio debug file...
    root@am335x-evm:/sys/class/leds/RGB_cnt0# cat /sys/kernel/debug/gpio
    GPIOs 0-31, gpio:
    gpio-6 (mmc_cd ) in lo
    gpio-8 (am335x_uda134x ) out hi
    gpio-10 (am335x_uda134x ) out hi

    GPIOs 32-63, gpio:
    gpio-46 (gpio_ouputexport ) out hi
    gpio-53 (beaglebone:green:hea) out lo
    gpio-54 (beaglebone:green:mmc) out lo
    gpio-55 (beaglebone:green:usr) out hi
    gpio-56 (beaglebone:green:usr) out lo

    GPIOs 64-95, gpio:
    gpio-70 (Away_led ) out lo
    gpio-71 (Error_led ) out lo
    gpio-72 (HF_led ) out lo
    gpio-73 (Alaram_led ) out lo
    gpio-74 (RGB_cnt0 ) out lo
    gpio-75 (RGB_cntr1 ) out lo
    gpio-76 (RGB_cntr2 ) out hi
    gpio-81 (am335x_uda134x ) out lo

    GPIOs 96-127, gpio:
  • Hi Ivan,

          Please once check attached file export gpio dr7888.gpio_export.txtiver code.....

  • Hi Shankar,

    I think that the code in attached file is correct and you can use it.

    BR
    Ivan
  • Hi Ivan,

    when i load attached driver it shows the error i.e Device or resource busy here i am using custom board based on AM335x and sdk-7 not beagle bone black board, we are not using HDMI controller and we direct interface leds lcd_data0* to lcd_data7* pins.
    1. In am33xx_pinmux: pinmux@44e10800
    0xa0 (PIN_OUTPUT_PULLUP | MUX_MODE7) /* lcd_data0.gpio2_6 D0/Away_LED shan */
    2. in leds node
    led@6 {
    label = "Away_led";
    gpios = <&gpio2 6 GPIO_ACTIVE_HIGH>;
    linux,default-trigger = "heartbeat";
    default-state = "on";
    };

    3. shell prompt
    root@am335x-evm:/# cd sys/class/leds/
    Away_led/ beaglebone:green:usr2/
    beaglebone:green:heartbeat/ beaglebone:green:usr3/
    beaglebone:green:mmc0/
    root@am335x-evm:/# cd sys/class/leds/Away_led
    root@am335x-evm:/sys/class/leds/Away_led# ls
    brightness max_brightness subsystem uevent
    device power trigger
    root@am335x-evm:/sys/class/leds/Away_led# echo 1 > brightness
    root@am335x-evm:/sys/class/leds/Away_led# echo 0 > brightness

    4. All commands are executed fine but am unable turn on leds please give me any suggestion......

    Thanks and Regards.........
  • Hi Ivan,

    Thank you for your valuable response finally i got it, problem was in hardware........ then i am looking for "gpio-keys" driver in my custom board we are using 4 input buttons can you give me details about gpio-keys driver how to enable kernel configuration and DTS file..........
  • Hi Shankar,

    This thread is closed. Please open the new one with proper title.

    BR
    Ivan