#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/gpio.h>
#include <linux/poll.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <asm/irq.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/device.h>
//#include <asm/hardware.h>
//#include <asm/arch/regs-gpio.h>
#define DEVICE_NAME "EmbedSky-leds"
#define LED_MAJOR 231
#define IOCTL_LED_ON 1
#define IOCTL_LED_OFF 0
static unsigned long led_table[] =
{
S3C2410_GPB5,
S3C2410_GPB6,
S3C2410_GPB7,
S3C2410_GPB8,
};
static int EmbedSky_leds_open(struct inode *inode,struct file *file)
{
return 0;
}
static int EmbedSky_leds_ioctl(
struct inode *inode,
struct file *file,
unsigned int cmd,
unsigned long arg)
{
if (arg > 4)
{
return -EINVAL;
}
switch(cmd)
{
case IOCTL_LED_ON:
s3c2410_gpio_setpin(led_table[arg], 0);
return 0;
case IOCTL_LED_OFF:
s3c2410_gpio_setpin(led_table[arg], 1);
return 0;
default:
return -EINVAL;
}
}
static struct file_operations EmbedSky_leds_fops = {
.owner = THIS_MODULE,
.open = EmbedSky_leds_open,
.ioctl = EmbedSky_leds_ioctl,
};
static char __initdata banner[]="tq2440 led\n";
static struct class *led_class;
static int __init EmbedSky_leds_init(void)
{
int ret;
printk(banner);
ret=register_chrdev(LED_MAJOR,DEVICE_NAME,&EmbedSky_leds_fops);
if(ret<0)
{
printk(DEVICE_NAME"cannot register number\n");
return ret;
}
led_class=class_create(THIS_MODULE,DEVICE_NAME);
if(IS_ERR(led_class))
{
printk("cannot class\n");
return -1;
}
device_create(led_class,NULL,MKDEV(LED_MAJOR,0),NULL,DEVICE_NAME);
printk(DEVICE_NAME"initialized\n");
return 0;
}
static void __exit EmbedSky_leds_exit(void)
{
unregister_chrdev(LED_MAJOR,DEVICE_NAME);
device_destroy(led_class,MKDEV(LED_MAJOR,0));
class_destroy(led_class);
}
module_init(EmbedSky_leds_init);
module_exit(EmbedSky_leds_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("song");
MODULE_DESCRIPTION("GPIO control for EmbedSky SKY2440/TQ2440 Board");