Hammer LED Driver Module
From eLinux.org
this is an example kernel module that will blink the onboard LED connected to GPIO F0 (source)
/*
* ledblink.c - basic led blinking kernel module
*
* Copyright (c) 2008 TinCanTools
* David Anders <danders@amltd.com>
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/timer.h> /* Needed for kernel timer */
#include <asm/arch/regs-gpio.h> /* Needed for GPIO defines */
#include <asm/io.h> /* Needed for s3c2410 functions */
static int blinkinterval = HZ / 2;
static struct timer_list blink_timer;
static void led_blink(unsigned long dummy)
{
/* the LED is active(on) when low(0) */
if (s3c2410_gpio_getpin(S3C2410_GPF0) == 0) /* check the current value of GPIO F0 */
s3c2410_gpio_setpin(S3C2410_GPF0, 1); /* turn LED off */
else
s3c2410_gpio_setpin(S3C2410_GPF0, 0); /* turn LED on */
mod_timer (&blink_timer, jiffies + blinkinterval); /* restart the timer */
}
int init_module(void)
{
s3c2410_gpio_cfgpin(S3C2410_GPF0, S3C2410_GPIO_OUTPUT); /* set the GPIO line F0 to an output */
s3c2410_gpio_setpin(S3C2410_GPF0, 1); /* make sure the LED starts in the off setting */
printk(KERN_INFO "LED Blink Module Loaded\n");
init_timer (&blink_timer);
blink_timer.function = led_blink;
mod_timer (&blink_timer, jiffies + blinkinterval);
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}
void cleanup_module(void)
{
s3c2410_gpio_setpin(S3C2410_GPF0, 1); /* make sure the LED is off when exiting */
del_timer_sync(&blink_timer); /* sync and delete the timer before exiting */
printk(KERN_INFO "LED Blink Module Unloaded\n");
}
MODULE_LICENSE("GPL");