一、基本概念
1、配置 Linux 内核 LED 驱动
Device Drivers
---》LED Support
---》LED Support for GPIO connected LEDs
二、确定内核LED驱动源码
1、配置 Linux
内核 LED
驱动。
2、在 LED Support for GPIO connected LEDs
选项中按下 '?'
,确定配置项
通过以上信息可以确定 Linux
内核 LED
驱动配置项为 CONFIG_LEDS_GPIO
。
3、在 .config
中查看 CONFIG_LEDS_GPIO
配置是否成功。
4、在 Linux
内核源码中查找 CONFIG_LEDS_GPIO
配置项,根据相关 Makefile
中描述确定 LED
驱动源代码。
5、查找 leds-gpio.c
确定 Linux
内核 LED
相关源码。
三、分析内核LED驱动源码
待完成……
四、添加设备树节点
1、设备树添加说明
Linux 驱动开发 五十八:《leds-gpio.txt》翻译_lqonlylove的博客-CSDN博客
Linux 驱动开发 五十九:《common.txt》翻译_lqonlylove的博客-CSDN博客
2、添加设备树节点
1、确定 LED
使用的 GPIO
为 GPIO1_IO03
。
2、查找引脚是否被使用。
3、添加 pinctrl
相关配置。
4、添加 led
相关配置。
3、设备树节点示例
1、应用程序控制
leds {
compatible = "gpio-leds";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_led>;
led0 {
label = "red";
gpios = <&gpio1 3 GPIO_ACTIVE_LOW>;
default-state = "off";
};
};
2、呼吸灯配置
leds {
compatible = "gpio-leds"; # 必须为 gpio-leds
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_led>;
led0 {
label = "red";
gpios = <&gpio1 3 GPIO_ACTIVE_LOW>; # gpio子系统相关配置
linux,default-trigger = "heartbeat"; # 功能设置(可不设置,不设置default-state配置为off)
default-state = "on"; # 默认状态
};
};
4、设备树编译
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15$ pwd
/home/onlylove/my/linux/linux-imx-4.1.15
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15$ make dtbs
CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
make[1]: 'include/generated/mach-types.h' is up to date.
CHK include/generated/bounds.h
CHK include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh
DTC arch/arm/boot/dts/imx6ull-alientek-emmc.dtb
DTC arch/arm/boot/dts/imx6ull-alientek-nand.dtb
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15$
五、LED相关操作
1、LED 操作路径
# pwd
/sys/bus/platform
# ls -l
total 0
drwxr-xr-x 2 root root 0 Jan 1 00:04 devices
drwxr-xr-x 111 root root 0 Jan 1 00:04 drivers
-rw-r--r-- 1 root root 4096 Jan 1 00:04 drivers_autoprobe
--w------- 1 root root 4096 Jan 1 00:04 drivers_probe
--w------- 1 root root 4096 Jan 1 00:04 uevent
# cd devices/
# pwd
/sys/bus/platform/devices
# ls -l
total 0
lrwxrwxrwx 1 root root 0 Jan 1 00:04 1804000.dma-apbh -> ../../../devices/platform/soc/1804000.dma-apbh
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2000000.aips-bus -> ../../../devices/platform/soc/2000000.aips-bus
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2000000.aips-bus:tempmon -> ../../../devices/platform/soc/2000000.aips-bus/2000000.aips-bus:tempmon
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2000000.spba-bus -> ../../../devices/platform/soc/2000000.aips-bus/2000000.spba-bus
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2010000.ecspi -> ../../../devices/platform/soc/2000000.aips-bus/2000000.spba-bus/2010000.ecspi
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2020000.serial -> ../../../devices/platform/soc/2000000.aips-bus/2000000.spba-bus/2020000.serial
lrwxrwxrwx 1 root root 0 Jan 1 00:04 202c000.sai -> ../../../devices/platform/soc/2000000.aips-bus/2000000.spba-bus/202c000.sai
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2034000.asrc -> ../../../devices/platform/soc/2000000.aips-bus/2000000.spba-bus/2034000.asrc
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2080000.pwm -> ../../../devices/platform/soc/2000000.aips-bus/2080000.pwm
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2084000.pwm -> ../../../devices/platform/soc/2000000.aips-bus/2084000.pwm
lrwxrwxrwx 1 root root 0 Jan 1 00:04 208c000.pwm -> ../../../devices/platform/soc/2000000.aips-bus/208c000.pwm
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2090000.can -> ../../../devices/platform/soc/2000000.aips-bus/2090000.can
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2098000.gpt -> ../../../devices/platform/soc/2000000.aips-bus/2098000.gpt
lrwxrwxrwx 1 root root 0 Jan 1 00:04 209c000.gpio -> ../../../devices/platform/soc/2000000.aips-bus/209c000.gpio
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20a0000.gpio -> ../../../devices/platform/soc/2000000.aips-bus/20a0000.gpio
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20a4000.gpio -> ../../../devices/platform/soc/2000000.aips-bus/20a4000.gpio
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20a8000.gpio -> ../../../devices/platform/soc/2000000.aips-bus/20a8000.gpio
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20ac000.gpio -> ../../../devices/platform/soc/2000000.aips-bus/20ac000.gpio
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20b0000.snvs -> ../../../devices/platform/soc/2000000.aips-bus/20b0000.snvs
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20b4000.ethernet -> ../../../devices/platform/soc/2000000.aips-bus/20b4000.ethernet
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20bc000.wdog -> ../../../devices/platform/soc/2000000.aips-bus/20bc000.wdog
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20c4000.ccm -> ../../../devices/platform/soc/2000000.aips-bus/20c4000.ccm
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20c406c.alphaled -> ../../../devices/platform/20c406c.alphaled
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20c8000.anatop -> ../../../devices/platform/soc/2000000.aips-bus/20c8000.anatop
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20c8000.anatop:regulator-3p0@120 -> ../../../devices/platform/soc/2000000.aips-bus/20c8000.anatop/20c8000.anatop:regulator-3p0@120
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20c8000.anatop:regulator-vddcore@140 -> ../../../devices/platform/soc/2000000.aips-bus/20c8000.anatop/20c8000.anatop:regulator-vddcore@140
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20c8000.anatop:regulator-vddsoc@140 -> ../../../devices/platform/soc/2000000.aips-bus/20c8000.anatop/20c8000.anatop:regulator-vddsoc@140
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20c9000.usbphy -> ../../../devices/platform/soc/2000000.aips-bus/20c9000.usbphy
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20ca000.usbphy -> ../../../devices/platform/soc/2000000.aips-bus/20ca000.usbphy
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20cc000.snvs -> ../../../devices/platform/soc/2000000.aips-bus/20cc000.snvs
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20cc000.snvs:snvs-powerkey -> ../../../devices/platform/soc/2000000.aips-bus/20cc000.snvs/20cc000.snvs:snvs-powerkey
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20cc000.snvs:snvs-poweroff -> ../../../devices/platform/soc/2000000.aips-bus/20cc000.snvs/20cc000.snvs:snvs-poweroff
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20cc000.snvs:snvs-rtc-lp -> ../../../devices/platform/soc/2000000.aips-bus/20cc000.snvs/20cc000.snvs:snvs-rtc-lp
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20d8000.src -> ../../../devices/platform/soc/2000000.aips-bus/20d8000.src
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20dc000.gpc -> ../../../devices/platform/soc/2000000.aips-bus/20dc000.gpc
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20e0000.iomuxc -> ../../../devices/platform/soc/2000000.aips-bus/20e0000.iomuxc
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20e4000.iomuxc-gpr -> ../../../devices/platform/soc/2000000.aips-bus/20e4000.iomuxc-gpr
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20e8000.gpt -> ../../../devices/platform/soc/2000000.aips-bus/20e8000.gpt
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20ec000.sdma -> ../../../devices/platform/soc/2000000.aips-bus/20ec000.sdma
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20f0000.pwm -> ../../../devices/platform/soc/2000000.aips-bus/20f0000.pwm
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20f4000.pwm -> ../../../devices/platform/soc/2000000.aips-bus/20f4000.pwm
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20f8000.pwm -> ../../../devices/platform/soc/2000000.aips-bus/20f8000.pwm
lrwxrwxrwx 1 root root 0 Jan 1 00:04 20fc000.pwm -> ../../../devices/platform/soc/2000000.aips-bus/20fc000.pwm
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2100000.aips-bus -> ../../../devices/platform/soc/2100000.aips-bus
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2184000.usb -> ../../../devices/platform/soc/2100000.aips-bus/2184000.usb
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2184200.usb -> ../../../devices/platform/soc/2100000.aips-bus/2184200.usb
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2184800.usbmisc -> ../../../devices/platform/soc/2100000.aips-bus/2184800.usbmisc
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2188000.ethernet -> ../../../devices/platform/soc/2100000.aips-bus/2188000.ethernet
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2190000.usdhc -> ../../../devices/platform/soc/2100000.aips-bus/2190000.usdhc
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2194000.usdhc -> ../../../devices/platform/soc/2100000.aips-bus/2194000.usdhc
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2198000.adc -> ../../../devices/platform/soc/2100000.aips-bus/2198000.adc
lrwxrwxrwx 1 root root 0 Jan 1 00:04 21a0000.i2c -> ../../../devices/platform/soc/2100000.aips-bus/21a0000.i2c
lrwxrwxrwx 1 root root 0 Jan 1 00:04 21a4000.i2c -> ../../../devices/platform/soc/2100000.aips-bus/21a4000.i2c
lrwxrwxrwx 1 root root 0 Jan 1 00:04 21ac000.romcp -> ../../../devices/platform/soc/2100000.aips-bus/21ac000.romcp
lrwxrwxrwx 1 root root 0 Jan 1 00:04 21b0000.mmdc -> ../../../devices/platform/soc/2100000.aips-bus/21b0000.mmdc
lrwxrwxrwx 1 root root 0 Jan 1 00:04 21b8000.weim -> ../../../devices/platform/soc/2100000.aips-bus/21b8000.weim
lrwxrwxrwx 1 root root 0 Jan 1 00:04 21bc000.ocotp-ctrl -> ../../../devices/platform/soc/2100000.aips-bus/21bc000.ocotp-ctrl
lrwxrwxrwx 1 root root 0 Jan 1 00:04 21c4000.csi -> ../../../devices/platform/soc/2100000.aips-bus/21c4000.csi
lrwxrwxrwx 1 root root 0 Jan 1 00:04 21c8000.lcdif -> ../../../devices/platform/soc/2100000.aips-bus/21c8000.lcdif
lrwxrwxrwx 1 root root 0 Jan 1 00:04 21cc000.pxp -> ../../../devices/platform/soc/2100000.aips-bus/21cc000.pxp
lrwxrwxrwx 1 root root 0 Jan 1 00:04 21e0000.qspi -> ../../../devices/platform/soc/2100000.aips-bus/21e0000.qspi
lrwxrwxrwx 1 root root 0 Jan 1 00:04 21ec000.serial -> ../../../devices/platform/soc/2100000.aips-bus/21ec000.serial
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2200000.aips-bus -> ../../../devices/platform/soc/2200000.aips-bus
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2280000.dcp -> ../../../devices/platform/soc/2200000.aips-bus/2280000.dcp
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2284000.rngb -> ../../../devices/platform/soc/2200000.aips-bus/2284000.rngb
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2290000.iomuxc-snvs -> ../../../devices/platform/soc/2200000.aips-bus/2290000.iomuxc-snvs
lrwxrwxrwx 1 root root 0 Jan 1 00:04 2294000.snvs-gpr -> ../../../devices/platform/soc/2200000.aips-bus/2294000.snvs-gpr
lrwxrwxrwx 1 root root 0 Jan 1 00:04 900000.sram -> ../../../devices/platform/soc/900000.sram
lrwxrwxrwx 1 root root 0 Jan 1 00:04 904000.sram -> ../../../devices/platform/soc/904000.sram
lrwxrwxrwx 1 root root 0 Jan 1 00:04 905000.sram -> ../../../devices/platform/soc/905000.sram
lrwxrwxrwx 1 root root 0 Jan 1 00:04 Vivante GCCore -> ../../../devices/platform/Vivante GCCore
lrwxrwxrwx 1 root root 0 Jan 1 00:04 a01000.interrupt-controller -> ../../../devices/platform/a01000.interrupt-controller
lrwxrwxrwx 1 root root 0 Jan 1 00:04 alarmtimer -> ../../../devices/platform/alarmtimer
lrwxrwxrwx 1 root root 0 Jan 1 00:04 backlight -> ../../../devices/platform/backlight
lrwxrwxrwx 1 root root 0 Jan 1 00:04 beep -> ../../../devices/platform/beep
lrwxrwxrwx 1 root root 0 Jan 1 00:04 ci_hdrc.0 -> ../../../devices/platform/soc/2100000.aips-bus/2184000.usb/ci_hdrc.0
lrwxrwxrwx 1 root root 0 Jan 1 00:04 ci_hdrc.1 -> ../../../devices/platform/soc/2100000.aips-bus/2184200.usb/ci_hdrc.1
lrwxrwxrwx 1 root root 0 Jan 1 00:04 gpioled -> ../../../devices/platform/gpioled
lrwxrwxrwx 1 root root 0 Jan 1 00:04 imx6q-cpufreq -> ../../../devices/platform/imx6q-cpufreq
lrwxrwxrwx 1 root root 0 Jan 1 00:04 key -> ../../../devices/platform/key
lrwxrwxrwx 1 root root 0 Jan 1 00:04 leds -> ../../../devices/platform/leds
lrwxrwxrwx 1 root root 0 Jan 1 00:04 pxp_v4l2 -> ../../../devices/platform/pxp_v4l2
lrwxrwxrwx 1 root root 0 Jan 1 00:04 reg-dummy -> ../../../devices/platform/reg-dummy
lrwxrwxrwx 1 root root 0 Jan 1 00:04 regulators -> ../../../devices/platform/regulators
lrwxrwxrwx 1 root root 0 Jan 1 00:04 regulators:regulator-gpio -> ../../../devices/platform/regulators/regulators:regulator-gpio
lrwxrwxrwx 1 root root 0 Jan 1 00:04 regulators:regulator@0 -> ../../../devices/platform/regulators/regulators:regulator@0
lrwxrwxrwx 1 root root 0 Jan 1 00:04 regulators:regulator@1 -> ../../../devices/platform/regulators/regulators:regulator@1
lrwxrwxrwx 1 root root 0 Jan 1 00:04 regulators:regulator@2 -> ../../../devices/platform/regulators/regulators:regulator@2
lrwxrwxrwx 1 root root 0 Jan 1 00:04 regulatory.0 -> ../../../devices/platform/regulatory.0
lrwxrwxrwx 1 root root 0 Jan 1 00:04 snd-soc-dummy -> ../../../devices/platform/snd-soc-dummy
lrwxrwxrwx 1 root root 0 Jan 1 00:04 soc -> ../../../devices/platform/soc
lrwxrwxrwx 1 root root 0 Jan 1 00:04 soc:busfreq -> ../../../devices/platform/soc/soc:busfreq
lrwxrwxrwx 1 root root 0 Jan 1 00:04 sound -> ../../../devices/platform/sound
lrwxrwxrwx 1 root root 0 Jan 1 00:04 spi4 -> ../../../devices/platform/spi4
# cd leds/
# pwd
/sys/bus/platform/devices/leds
# ls -l
total 0
lrwxrwxrwx 1 root root 0 Jan 1 00:04 driver -> ../../../bus/platform/drivers/leds-gpio
-rw-r--r-- 1 root root 4096 Jan 1 00:04 driver_override
drwxr-xr-x 3 root root 0 Jan 1 00:04 leds
-r--r--r-- 1 root root 4096 Jan 1 00:04 modalias
lrwxrwxrwx 1 root root 0 Jan 1 00:04 of_node -> ../../../firmware/devicetree/base/leds
drwxr-xr-x 2 root root 0 Jan 1 00:04 power
lrwxrwxrwx 1 root root 0 Jan 1 00:04 subsystem -> ../../../bus/platform
-rw-r--r-- 1 root root 4096 Jan 1 00:04 uevent
# cd leds/
# pwd
/sys/bus/platform/devices/leds/leds
# ls -l
total 0
drwxr-xr-x 3 root root 0 Jan 1 00:04 red
# cd red/
# pwd
/sys/bus/platform/devices/leds/leds/red
# ls -l
total 0
-rw-r--r-- 1 root root 4096 Jan 1 00:23 brightness
lrwxrwxrwx 1 root root 0 Jan 1 00:04 device -> ../../../leds
-r--r--r-- 1 root root 4096 Jan 1 00:04 max_brightness
drwxr-xr-x 2 root root 0 Jan 1 00:04 power
lrwxrwxrwx 1 root root 0 Jan 1 00:04 subsystem -> ../../../../../class/leds
-rw-r--r-- 1 root root 4096 Jan 1 00:04 trigger
-rw-r--r-- 1 root root 4096 Jan 1 00:04 uevent
#
#
#
#
# cat brightness
0
# cat trigger
[none] rc-feedback nand-disk mmc0 mmc1 timer oneshot heartbeat backlight gpio
# cat max_brightness
255
#
# pwd
/sys/class
# ls -l
total 0
drwxr-xr-x 2 root root 0 Jan 1 00:04 GobiQMI
drwxr-xr-x 2 root root 0 Jan 1 00:04 ata_device
drwxr-xr-x 2 root root 0 Jan 1 00:04 ata_link
drwxr-xr-x 2 root root 0 Jan 1 00:04 ata_port
drwxr-xr-x 2 root root 0 Jan 1 00:04 backlight
drwxr-xr-x 2 root root 0 Jan 1 00:04 bdi
drwxr-xr-x 2 root root 0 Jan 1 00:04 block
drwxr-xr-x 2 root root 0 Jan 1 00:04 dma
drwxr-xr-x 2 root root 0 Jan 1 00:04 drm
drwxr-xr-x 2 root root 0 Jan 1 00:04 firmware
drwxr-xr-x 2 root root 0 Jan 1 00:04 gpio
drwxr-xr-x 2 root root 0 Jan 1 00:04 graphics
drwxr-xr-x 2 root root 0 Jan 1 00:04 i2c-dev
drwxr-xr-x 2 root root 0 Jan 1 00:04 ieee80211
drwxr-xr-x 2 root root 0 Jan 1 00:04 input
drwxr-xr-x 2 root root 0 Jan 1 00:04 lcd
drwxr-xr-x 2 root root 0 Jan 1 00:04 leds
drwxr-xr-x 2 root root 0 Jan 1 00:04 mdio_bus
drwxr-xr-x 2 root root 0 Jan 1 00:04 mem
drwxr-xr-x 2 root root 0 Jan 1 00:04 misc
drwxr-xr-x 2 root root 0 Jan 1 00:04 mmc_host
drwxr-xr-x 2 root root 0 Jan 1 00:04 mtd
drwxr-xr-x 2 root root 0 Jan 1 00:04 net
drwxr-xr-x 2 root root 0 Jan 1 00:04 power_supply
drwxr-xr-x 2 root root 0 Jan 1 00:04 ppp
drwxr-xr-x 2 root root 0 Jan 1 00:04 pps
drwxr-xr-x 2 root root 0 Jan 1 00:04 ptp
drwxr-xr-x 2 root root 0 Jan 1 00:04 pwm
drwxr-xr-x 2 root root 0 Jan 1 00:04 rc
drwxr-xr-x 2 root root 0 Jan 1 00:04 regulator
drwxr-xr-x 2 root root 0 Jan 1 00:04 rfkill
drwxr-xr-x 2 root root 0 Jan 1 00:04 rtc
drwxr-xr-x 2 root root 0 Jan 1 00:04 scsi_device
drwxr-xr-x 2 root root 0 Jan 1 00:04 scsi_disk
drwxr-xr-x 2 root root 0 Jan 1 00:04 scsi_host
drwxr-xr-x 2 root root 0 Jan 1 00:04 sound
drwxr-xr-x 2 root root 0 Jan 1 00:04 spi_master
drwxr-xr-x 2 root root 0 Jan 1 00:04 thermal
drwxr-xr-x 2 root root 0 Jan 1 00:04 tty
drwxr-xr-x 2 root root 0 Jan 1 00:04 ubi
drwxr-xr-x 2 root root 0 Jan 1 00:04 udc
drwxr-xr-x 2 root root 0 Jan 1 00:04 vc
drwxr-xr-x 2 root root 0 Jan 1 00:04 video4linux
drwxr-xr-x 2 root root 0 Jan 1 00:04 vtconsole
drwxr-xr-x 2 root root 0 Jan 1 00:04 watchdog
# cd leds/
# pwd
/sys/class/leds
# ls -l
total 0
lrwxrwxrwx 1 root root 0 Jan 1 00:04 mmc0:: -> ../../devices/platform/soc/2100000.aips-bus/2190000.usdhc/leds/mmc0::
lrwxrwxrwx 1 root root 0 Jan 1 00:04 mmc1:: -> ../../devices/platform/soc/2100000.aips-bus/2194000.usdhc/leds/mmc1::
lrwxrwxrwx 1 root root 0 Jan 1 00:04 red -> ../../devices/platform/leds/leds/red
# cd red/
# pwd
/sys/class/leds/red
# ls -l
total 0
-rw-r--r-- 1 root root 4096 Jan 1 00:23 brightness
lrwxrwxrwx 1 root root 0 Jan 1 00:04 device -> ../../../leds
-r--r--r-- 1 root root 4096 Jan 1 00:04 max_brightness
drwxr-xr-x 2 root root 0 Jan 1 00:04 power
lrwxrwxrwx 1 root root 0 Jan 1 00:04 subsystem -> ../../../../../class/leds
-rw-r--r-- 1 root root 4096 Jan 1 00:04 trigger
-rw-r--r-- 1 root root 4096 Jan 1 00:04 uevent
# cat brightness
0
# cat trigger
[none] rc-feedback nand-disk mmc0 mmc1 timer oneshot heartbeat backlight gpio
# cat max_brightness
255
#
# pwd
/sys/devices/platform
# ls -l
total 0
drwxr-xr-x 3 root root 0 Jan 1 00:04 20c406c.alphaled
drwxr-xr-x 4 root root 0 Jan 1 00:04 Vivante GCCore
drwxr-xr-x 3 root root 0 Jan 1 00:04 a01000.interrupt-controller
drwxr-xr-x 3 root root 0 Jan 1 00:04 alarmtimer
drwxr-xr-x 4 root root 0 Jan 1 00:04 backlight
drwxr-xr-x 3 root root 0 Jan 1 00:04 beep
drwxr-xr-x 3 root root 0 Jan 1 00:04 gpioled
drwxr-xr-x 3 root root 0 Jan 1 00:04 imx6q-cpufreq
drwxr-xr-x 3 root root 0 Jan 1 00:04 key
drwxr-xr-x 4 root root 0 Jan 1 00:04 leds
drwxr-xr-x 2 root root 0 Jan 1 00:04 power
drwxr-xr-x 4 root root 0 Jan 1 00:04 pxp_v4l2
drwxr-xr-x 4 root root 0 Jan 1 00:04 reg-dummy
drwxr-xr-x 7 root root 0 Jan 1 00:04 regulators
drwxr-xr-x 3 root root 0 Jan 1 00:04 regulatory.0
drwxr-xr-x 3 root root 0 Jan 1 00:04 snd-soc-dummy
drwxr-xr-x 11 root root 0 Jan 1 00:04 soc
drwxr-xr-x 7 root root 0 Jan 1 00:04 sound
drwxr-xr-x 3 root root 0 Jan 1 00:04 spi4
-rw-r--r-- 1 root root 4096 Jan 1 00:04 uevent
# cd leds/
# pwd
/sys/devices/platform/leds
# ls -l
total 0
lrwxrwxrwx 1 root root 0 Jan 1 00:04 driver -> ../../../bus/platform/drivers/leds-gpio
-rw-r--r-- 1 root root 4096 Jan 1 00:04 driver_override
drwxr-xr-x 3 root root 0 Jan 1 00:04 leds
-r--r--r-- 1 root root 4096 Jan 1 00:04 modalias
lrwxrwxrwx 1 root root 0 Jan 1 00:04 of_node -> ../../../firmware/devicetree/base/leds
drwxr-xr-x 2 root root 0 Jan 1 00:04 power
lrwxrwxrwx 1 root root 0 Jan 1 00:04 subsystem -> ../../../bus/platform
-rw-r--r-- 1 root root 4096 Jan 1 00:04 uevent
# cd leds/
# pwd
/sys/devices/platform/leds/leds
# ls -l
total 0
drwxr-xr-x 3 root root 0 Jan 1 00:04 red
# cd red/
# pwd
/sys/devices/platform/leds/leds/red
# ls -l
total 0
-rw-r--r-- 1 root root 4096 Jan 1 00:23 brightness
lrwxrwxrwx 1 root root 0 Jan 1 00:04 device -> ../../../leds
-r--r--r-- 1 root root 4096 Jan 1 00:04 max_brightness
drwxr-xr-x 2 root root 0 Jan 1 00:04 power
lrwxrwxrwx 1 root root 0 Jan 1 00:04 subsystem -> ../../../../../class/leds
-rw-r--r-- 1 root root 4096 Jan 1 00:04 trigger
-rw-r--r-- 1 root root 4096 Jan 1 00:04 uevent
# cat brightness
0
# cat trigger
[none] rc-feedback nand-disk mmc0 mmc1 timer oneshot heartbeat backlight gpio
# cat max_brightness
255
#
说明:
brightness
:LED
当前状态。trigger
:功能设置。
2、修改 LED 状态
echo 1 > /sys/class/leds/red/brightness # 打开 LED
echo 0 > /sys/class/leds/red/brightness # 关闭 LED
3、修改 LED 功能
echo heartbeat > /sys/class/leds/red/trigger # 将按键作为心跳灯