linux2.6.37.4内核在XC2440开发板上移植(十三)LED驱动移植

1170阅读 0评论2015-01-26 梦剧场的记忆
分类:LINUX

内核中带有GPIO控制LED的驱动,通用的驱动文件为:drivers/leds/leds-gpio.c

硬件接法:
LED1 -->  GPF0
LED2 -->  GPF1
LED3 -->  GPF2
LED4 -->  GPF3

低电平点亮,高电平熄灭

在mach-xc2440.c中添加LED驱动的支持:

加入必要的头文件:
#include

在xc2440_devices[ ]结构体中加入:
    &xc2440_device_led,

构建LED设备的platform_device:
  1. static struct platform_device xc2440_device_led = {
  2.     .name        = "leds-gpio",
  3.     .id        = -1,
  4.     .dev        = {
  5.         .platform_data = &xc2440_gpio_led_pdata,
  6.     },
  7. };

构建LED设备的platform_data:
  1. /* LEDS */
  2. static struct gpio_led xc2440_leds[] = {
  3.     [0] = {
  4.         .name = "led1",
  5.         .gpio = S3C2410_GPF(0),
  6.         .active_low = 1,
  7.     },
  8.     [1] = {
  9.         .name = "led2",
  10.         .gpio = S3C2410_GPF(1),
  11.         .active_low = 1,
  12.     },
  13.     [2] = {
  14.         .name = "led3",
  15.         .gpio = S3C2410_GPF(2),
  16.         .active_low = 1,
  17.     },
  18.     [3] = {
  19.         .name = "led4",
  20.         .gpio = S3C2410_GPF(3),
  21.         .active_low = 1,
  22.     },
  23. };

  24. static struct gpio_led_platform_data xc2440_gpio_led_pdata = {
  25.     .num_leds = ARRAY_SIZE(xc2440_leds),
  26.     .leds = xc2440_leds,
  27. };

参数说明:
name: led的name,一个字符串
gpio:操作它的GPIO管脚
active_low:为1是低电平点亮,为0是高电平点亮

配置内核,支持LED驱动:
  1. Device Drivers --->
  2.     [*] LED Support --->
  3. <*> LED Support for GPIO connected LEDs
  4. [*] Platform device bindings for GPIO LEDs(NEW)

查看设备:
/sys/class/leds/ledx   (x为0,1,2,3)

操作方法:
#echo 1 > /sys/class/leds/led0/brightness     让LED0亮
#echo 0 > /sys/class/leds/led0/brightness     让LED0灭
上一篇:linux2.6.32.2 mini2440平台移植-- 串口驱动、I2C-EEPROM 驱动、看门狗驱动移植
下一篇:Linux-2.6.32.2内核在mini2440上的移植(十八)---将UART2更成普通串口驱动