led驱动

#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");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值