參考ldd6410-manual[1].pdf
向s3c6410系統曾加LED設備的驅動.有四個led 的燈分別與GPIO 的GPK4,GPK5,GPK6,GPK7相連,四個led爲共陽。
Linux 內核下的drivers/leds/ledsgpio.c 實現了一個體繫結構無關的 GPIO LED 驅動, 使用此 LED 驅動,開發者不需要修改一行代碼,只需要在BSP的板文件(/home/wsh/s3c-linux-2.6.28.6-Real6410/arch/arm/mach-s3c6410/mach-smdk6410.c)中定義相關的平臺的設備和數據。
///*led driver support*/
static struct gpio_led s3c6410_leds[] = {
[0] = {
.name = "LED10",
.gpio = S3C64XX_GPK(4),
},
[1] = {
.name = "LED12",
.gpio = S3C64XX_GPK(5),
},
[2] = {
.name = "LED13",
.gpio = S3C64XX_GPK(6),
},
[3] = {
.name = "LED14",
.gpio = S3C64XX_GPK(7),
},
};
/*platform data support 其中gpio_led_platform_data在/linux/leds.h中定義了應將此文件包含在bsp文件當中*/
static struct gpio_led_platform_data s3c6410_gpio_led_pdata = {
.num_leds = ARRAY_SIZE(s3c6410_leds),
.leds = s3c6410_leds,
};
/*platform device struct in /linux/platform_device.h define */
static struct platform_device s3c_device_led = {
.name = "leds-gpio",//註冊device name 要於加進去的設備驅動一致,不一致就註冊不成功
.id = 1,
.dev = {
.platform_data = &s3c6410_gpio_led_pdata,
},
};
並將“&s3c_device_led,”語句填入 struct platform_device *smdk6410_devices[]數組,作爲該數組的一個成
員。
編譯內核make menuconfig
時會應選擇
--- LED Support │ │
│ │ <*> LED Class Support │ │
│ │ *** LED drivers *** │ │
│ │ < > LED driver for PCA9532 dimmer │ │
│ │ <*> LED Support for GPIO connected LEDs │ │
│ │ < > LED Support for PCA955x I2C chips │ │
│ │ *** LED Triggers *** │ │
│ │ [ ] LED Trigger support
通過以下方式能查看系統的驅動
在系統打印的時候會打印如下信息
Registered led device: LED10
Registered led device: LED12
Registered led device: LED13
Registered led device: LED13
[root@FriendlyARM leds]# pwd
/sys/class/leds
[root@FriendlyARM leds]# ls
LED10 LED12 LED13 LED14 mmc0
控制燈亮
[root@FriendlyARM leds]# echo 0 >LED10/brightness
控制燈滅
[root@FriendlyARM leds]# echo 1 >LED10/brightness