Hammer LED Class Driver

From eLinux.org
Revision as of 13:37, 16 June 2008 by Prpplague (Talk | contribs)

Jump to: navigation, search

UserSpace Access

the LED onboard the hammer as well as the LED on the carrier board can be accessed from userspace via the sysfs interface. example interfaces are in /sys/devices/platform/s3c24xx_led.0/leds:led0/ and /sys/devices/platform/s3c24xx_led.1/leds:led1/. both directories include a file entry "brightness". to turn a LED on, echo a non zero value to the brightness file entry:

echo 1 > /sys/devices/platform/s3c24xx_led.0/leds:led0/brightness

to turn a LED off, echo a zero to the the brightness file entry:

echo 0 > /sys/devices/platform/s3c24xx_led.0/leds:led0/brightness

you can also check the current status of the LED by using cat on the brightness file entry:

cat /sys/devices/platform/s3c24xx_led.0/leds:led0/brightness

Adding New LEDS

a new LED connected via a GPIO can be defined in the linux-2.6.xx/arch/arm/mach-s3c2410/mach-tct_hammer.c file. each LED will need to include some platform data and a platform device definition:

static struct s3c24xx_led_platdata tct_hammer_pdata_led0 = {
	.gpio		= S3C2410_GPF0,
	.name		= "led0",
	.def_trigger	= "timer",

static struct platform_device tct_hammer_led0 = {
	.name		= "s3c24xx_led",
	.id		= 0,
	.dev		= {
		.platform_data = &tct_hammer_pdata_led0,

this uses the standard LEDS class in the main kernel tree. for additional information see the linux-2.6.xx/Documentation/leds-class.txt file.

Nail Board LED's

static struct s3c24xx_led_platdata tct_hammer_pdata_led1 = {
	.gpio		= S3C2410_GPH0,
	.name		= "led1",
	.def_trigger	= "timer",

static struct s3c24xx_led_platdata tct_hammer_pdata_led2 = {
	.gpio		= S3C2410_GPH1,
	.name		= "led2",
	.def_trigger	= "timer",

static struct platform_device tct_hammer_led1 = {
	.name		= "s3c24xx_led",
	.id		= 1,
	.dev		= {
		.platform_data = &tct_hammer_pdata_led1,

static struct platform_device tct_hammer_led2 = {
	.name		= "s3c24xx_led",
	.id		= 2,
	.dev		= {
		.platform_data = &tct_hammer_pdata_led2,

you will also need to add some gpio setup in the machine init function:

static void __init tct_hammer_init(void)

	s3c2410_gpio_cfgpin(S3C2410_GPF0, S3C2410_GPIO_OUTPUT);
	s3c2410_gpio_setpin(S3C2410_GPF0, 1);

/* add these lines to setup the leds on the nail board */
	s3c2410_gpio_cfgpin(S3C2410_GPH0, S3C2410_GPIO_OUTPUT);
	s3c2410_gpio_setpin(S3C2410_GPH0, 1);
	s3c2410_gpio_cfgpin(S3C2410_GPH1, S3C2410_GPIO_OUTPUT);
	s3c2410_gpio_setpin(S3C2410_GPH1, 1);

	s3c2410_gpio_cfgpin(S3C2410_GPC12, S3C2410_GPIO_OUTPUT);
	s3c2410_gpio_setpin(S3C2410_GPC12, 1);

/*uncomment these these to enable the second serial port */
	s3c2410_gpio_cfgpin(S3C2410_GPH6, S3C2410_GPH6_TXD0);
	s3c2410_gpio_pullup(S3C2410_GPH6, 1);
	s3c2410_gpio_cfgpin(S3C2410_GPH7, S3C2410_GPH7_RXD0);
	s3c2410_gpio_pullup(S3C2410_GPH7, 1);
#ifdef CONFIG_FB_S3C2410
	platform_add_devices(tct_hammer_devices, ARRAY_SIZE(tct_hammer_devices));

in addition you will need to add the leds to the device list:

static struct platform_device *tct_hammer_devices[] __initdata = {
#ifdef CONFIG_FB_S3C2410
/* add these two entries for the new LEDs */