DTS support needed to control LEDs using /sys/class/leds?

I am working on controling leds via /sys/class/leds/ for a new Mediatek device which doesn't have .dts support. Though all the required driver modules are compiled there are no led entries registered at /sys/class/leds/.

Is the board specific .dts support needed for the leds to control via /sys/class/leds or is there any other way we can control them like using APIs "platform_device_register" and "platform_driver_regisrer"?

If yes, is there any way to allocate the resources for the number of leds tied to gpio?

Please refer the OpenWrt document:
Add new device

First, don't define any gpio in you dts file and use the method above to test the gpio and led.
After you finding the correct gpio and led then add them to you dts file.

Hi @sotux
As per my previous post, my device doesnt have support for .dts file.

Tried your suggestion to test the gpio's. Please find the error logs below:

root@OpenWrt:/sys/class/gpio# ls
export    unexport
root@OpenWrt:/sys/class/gpio# echo $GPIO > export
ash: write error: Invalid argument
root@OpenWrt:/sys/class/gpio# GPIO=3
root@OpenWrt:/sys/class/gpio# echo $GPIO > export
ash: write error: No such device

what's your kernel version?

Linux 3.18.21

May be the factory firmware doesn't support kernel debugfs or not compile the userspace gpio support.
My advice is to create a skeleton dts file and flash this firmware, try to run openwrt on you device. Then you can use the method in the document to detect gpio. But this may be brick your device.

Hey, I'm doing something similar. By "don't define any GPIO in your .dts file" does that also include omitting a line such as compatible = "gpio-leds";, or just not assign any specific GPIO pins to a specific function?

I mean don't define any GPIO to LEDs or buttons, then you can find responsing GPIO to LEDs or buttons easily. If you defined a GPIO to a LED or a button, the GPIO can't exported and you can't write value to the device file.