想了解 linux kernel 2.6.24.3 中 Driver 的實做,所以先從看起來比較簡單的 LED driver 來開始研究。
S3c2440 LED GPIO:
紅:GPBDAT4
藍:GPBDAT1
綠:GPBDAT10
menuconfig 設定:
Device Drivers --->
[*] LED Support --->
<*> LED Class Support
<*> LED Support for Samsung S3C24XX GPIO LEDs
相關檔案:
linux/include/linux/leds.h
linux/include/asm-arm/arch-s3c2410/leds-gpio.h
linux/arch/arm/plat-s3c24xx/common-smdk.c
將 led 相關設定內容改成如下:
/* LED devices */
static struct s3c24xx_led_platdata smdk_pdata_led_red = {
.gpio = S3C2410_GPB4,
.flags = S3C24XX_LEDF_TRISTATE,
.name = "led-red",
.def_trigger = "timer",
}
static struct s3c24xx_led_platdata smdk_pdata_led_blue = {
.gpio = S3C2410_GPB1,
.flags = S3C24XX_LEDF_TRISTATE,
.name = "led-blue",
.def_trigger = "nand-disk",
}
static struct s3c24xx_led_platdata smdk_pdata_led_green = {
.gpio = S3C2410_GPB10,
.flags = S3C24XX_LEDF_TRISTATE,
.name = "led-green",
.def_trigger = "led-green",
}
gpio:定義 Led GPIO 接腳
name: device 名字
def_trigger:觸發 led 名稱
static struct platform_device smdk_led_red = {
.name = "s3c24xx_led",
.id = 0,
.dev = {
.platform_data = &smdk_pdata_led_red,
},
}
static struct platform_device smdk_led_blue = {
.name = "s3c24xx_led",
.id = 1,
.dev = {
.platform_data = &smdk_pdata_led_blue,
}
}
static struct platform_device smdk_led_green = {
.name = "s3c24xx_led",
.id = 2,
.dev = {
.platform_data = &smdk_pdata_led_green,
}
}
另外在 smdk_machine_init()
設定初始話 LED 相對應腳位 GPB1 GPB4 GPB10 讓 led 全亮
如下:
s3c2410_gpio_cfgpin(S3C2410_GPB1, S3C2410_GPB1_OUTP);
s3c2410_gpio_cfgpin(S3C2410_GPB4, S3C2410_GPB4_OUTP);
s3c2410_gpio_cfgpin(S3C2410_GPB10,
S3C2410_GPB10_OUTP);
s3c2410_gpio_setpin(S3C2410_GPB1, 1);
s3c2410_gpio_setpin(S3C2410_GPB4, 1);
s3c2410_gpio_setpin(S3C2410_GPB10, 1);
led trigger 在 LED Driver 筆記 - led trigger 會有說明
S3c2440 LED GPIO:
紅:GPBDAT4
藍:GPBDAT1
綠:GPBDAT10
menuconfig 設定:
Device Drivers --->
[*] LED Support --->
<*> LED Class Support
<*> LED Support for Samsung S3C24XX GPIO LEDs
相關檔案:
- linux/include/linux/leds.h
- linux/include/asm-arm/arch-s3c2410/leds-gpio.h
- linux/arch/arm/plat-s3c24xx/common-smdk.c
- linux/driver/leds/leds.h
- linux/driver/leds/led-core.c
- linux/driver/leds/led-class.c
- linux/driver/leds/leds-s3c24xx.c
linux/include/linux/leds.h
/* For the leds-gpio driver */ struct gpio_led { const char *name; char *default_trigger; unsigned gpio; u8 active_low; }; struct gpio_led_platform_data { int num_leds; struct gpio_led *leds; }; |
linux/include/asm-arm/arch-s3c2410/leds-gpio.h
struct s3c24xx_led_platdata { unsigned int gpio; unsigned int flags; char *name; char *def_trigger; }; |
linux/arch/arm/plat-s3c24xx/common-smdk.c
將 led 相關設定內容改成如下:
/* LED devices */
static struct s3c24xx_led_platdata smdk_pdata_led_red = {
.gpio = S3C2410_GPB4,
.flags = S3C24XX_LEDF_TRISTATE,
.name = "led-red",
.def_trigger = "timer",
}
static struct s3c24xx_led_platdata smdk_pdata_led_blue = {
.gpio = S3C2410_GPB1,
.flags = S3C24XX_LEDF_TRISTATE,
.name = "led-blue",
.def_trigger = "nand-disk",
}
static struct s3c24xx_led_platdata smdk_pdata_led_green = {
.gpio = S3C2410_GPB10,
.flags = S3C24XX_LEDF_TRISTATE,
.name = "led-green",
.def_trigger = "led-green",
}
gpio:定義 Led GPIO 接腳
name: device 名字
def_trigger:觸發 led 名稱
static struct platform_device smdk_led_red = {
.name = "s3c24xx_led",
.id = 0,
.dev = {
.platform_data = &smdk_pdata_led_red,
},
}
static struct platform_device smdk_led_blue = {
.name = "s3c24xx_led",
.id = 1,
.dev = {
.platform_data = &smdk_pdata_led_blue,
}
}
static struct platform_device smdk_led_green = {
.name = "s3c24xx_led",
.id = 2,
.dev = {
.platform_data = &smdk_pdata_led_green,
}
}
另外在 smdk_machine_init()
設定初始話 LED 相對應腳位 GPB1 GPB4 GPB10 讓 led 全亮
如下:
s3c2410_gpio_cfgpin(S3C2410_GPB1, S3C2410_GPB1_OUTP);
s3c2410_gpio_cfgpin(S3C2410_GPB4, S3C2410_GPB4_OUTP);
s3c2410_gpio_cfgpin(S3C2410_GPB10,
S3C2410_GPB10_OUTP);
s3c2410_gpio_setpin(S3C2410_GPB1, 1);
s3c2410_gpio_setpin(S3C2410_GPB4, 1);
s3c2410_gpio_setpin(S3C2410_GPB10, 1);
led trigger 在 LED Driver 筆記 - led trigger 會有說明