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.

Linux/PROCESSOR-SDK-AM335X: active-delay value using timer for GPIO with device tree

Part Number: PROCESSOR-SDK-AM335X

Tool/software: Linux

Hello, 

We have a LED tied to a GPIO pin we are trying to control using the timer trigger in device tree. The timer trigger is working, however, the blink rate of the LED does not match the values of the active/inactive-delay values. Here's the device tree entry.

		blink_led {
			label = "LED_Blinky";
			gpios = <&gpio1 19 0>;
			linux,default-trigger = "timer";
			active-delay = <250>;
			inactive-delay = <250>;
		};

The LED does blink, but at a period of one second instead of a half second. If I check the delay-on and delay-off values under /sys/class/platform/leds/LED_Blinky both values are set to 500. Is 500 a default value? What else needs to be done?

Regards,

Tim Entinger

  • Hi Timothy,

    Looking in the 4.4.32 kernel (that comes with TI PSDK 3.2), seems like active-delay and inactive-delay values are then used in mdelay() function.

    linux-4.4.32/Documentation/devicetree/bindings/gpio/gpio-restart.txt
    linux-4.4.32/drivers/power/reset/gpio-restart.c

    mdelay(gpio_restart->active_delay_ms);

    Can you check the same is at your side? Does the actual active/inactive delay generated by mdelay() function or something else?

    See also the below wiki page where the same mdelay() function is used with GPIO:
    processors.wiki.ti.com/index.php/WL127x_Porting_Guide#Power_Control_.E2.80.93_without_voltage_regulator

    Regards,
    Pavel
  • Okay.  I didn't understand right away where you were going with your response, but I do now.

    Yes, active_delay_ms does appear to only be used in gpio-restart.

    I looked over the code in ledtrig-timer.c and saw it was passing in values for delay_on and delay_off to led_blink_setup in led-core.c. In led_blink_setup it's setting the delay_on and delay_off values to 500 if no values were passed in.

    	/* blink with 1 Hz as default if nothing specified */
    	if (!*delay_on && !*delay_off)
    		*delay_on = *delay_off = 500;
    
    	led_set_software_blink(led_cdev, *delay_on, *delay_off);

    Since I only care about the blink rate at startup I created a patch to set the value to 250 instead of 500. I'll have to do some testing to see if I can set delay_on and delay_off in the device tree. I would expect that not to work, but I will see.

  • I tried two formats to set the delay values from the device tree. Neither worked and it only picked the default. This would make me conclude that you can only set the "timer" trigger value from the device tree. This seems like oversight since the ideal place to set the delay values would be in the device tree if you are also setting the trigger. In either case here is what I tried that DID NOT WORK.

      blink1_led {
            label = "LED_Blinky1";
            gpios = <&gpio1 20 0>;
            linux,default-trigger = "timer";
            on_delay = <100>;
            off_delay = <100>;
    };
    
      blink2_led {
            label = "LED_Blinky2";
            gpios = <&gpio1 19 0>;
            linux,default-trigger = "timer";
            linux,on_delay = "100";
            linux,off_delay = "100";
    };

  • Timothy Entinger said:
    linux,default-trigger = "timer"; on_delay = <100>; off_delay = <100>;

    Timothy Entinger said:
    linux,default-trigger = "timer"; linux,on_delay = "100"; linux,off_delay = "100";

    By default gpio-leds DTS support:

    -gpios

    - label

    - linux,default-trigger

    - default-state

    - retain-state-suspended

    on/off_delay, linux,on/off_delay are not supported by default. See linux-kernel/Documentation/devicetree/bindings/leds/leds-gpio.txt

    You can add these by yourself. You can use of_property_read_u32() function. See how this function is used to set "active-delay" from DTS to "u32 active_delay_ms" in linux-4.4.32/drivers/power/reset/gpio-restart.c You can also check how this function is used to set "max-brightness" from DTS (i.e. omap4-sdp.dts) to max_brightness value in linux-4.4.32/drivers/leds/leds-pwm.c

    Check also if you can set delay_on/off values from user space, see the below e2e thread for more info:

    Regards,
    Pavel