LED子系统

来源:互联网 发布:淘宝买mlb帽子靠谱吗 编辑:程序博客网 时间:2024/05/05 02:25

通过LED子系统 驱动控制 LED 1 ~ 4,

主要的驱动文件为:

/driver/leds/leds-gpio.c

1、查看/driver/leds/Makefile

obj-$(CONFIG_LEDS_GPIO)                    += leds-gpio.o

查看/driver/leds/Konfig

config LEDS_GPIO

       tristate"LED Support for GPIO connected LEDs"

       dependson LEDS_CLASS && GENERIC_GPIO

其中

config LEDS_CLASS

       tristate"LED Class Support"

所以配置内核makemenuconfig 时,需要选中这两项,此外还要选中 Platform device bindings for GPIO LEDs,加载驱动的时候要判断这个是否配置,不配置,文件系统中不能出现sys/class/leds/led1。

2、修改板级文件 mach-mini6410.c

添加:

//LEDS platform driver
static struct gpio_led s3c_gpio_leds[] = {

       {
              .name                    = "led1",
              .gpio                     = S3C64XX_GPK(4),
              .active_low= 1,
       },
       {
              .name                    = "led2",
              .gpio                     = S3C64XX_GPK(5),
              .active_low= 1,
       },
       {
              .name                    = "led3",
              .gpio                     = S3C64XX_GPK(6),
              .active_low= 1,
       },
       {
              .name                    = "led4",
              .gpio                     = S3C64XX_GPK(7),
              .active_low= 1,
       },
};

static struct gpio_led_platform_data s3c_gpio_led_data = {
       .leds        = s3c_gpio_leds,
       .num_leds       = ARRAY_SIZE(s3c_gpio_leds),
};

static struct platform_device s3c_leds_gpio= {
       .name      = "leds-gpio",
       .id    = -1,
       .dev = {
              .platform_data = &s3c_gpio_led_data,
       },
};

然后把这个s3c_leds_gpio加入到mini6410_devices数组

static struct platform_device*mini6410_devices[] __initdata = {

       ……

       &s3c_leds_gpio, //添加

};

 

3、查看文件:

 ls /sys/class/leds/

led1
led2
led3
led4

cd led1

echo 1 > brightness  led1亮 

echo 0 > brightness  led1灭

依此类推,控制其他的led灯。

PS:echo 1 > brightness    1与brightness 之间要空格,这个是shell语法规则。

参考博客:http://blog.csdn.net/weiqing1981127/article/category/1271694 ,这个博客是有关linux的各种子系统的。

总结:

1.子系统,平台设备,都要到板级文件中注册,驱动名和设备名要一致。

0 0
原创粉丝点击