1,点亮LCD代码
my-led.c
#include <linux/module.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/device.h>
#include <linux/io.h>
#include <linux/miscdevice.h>
#include <linux/uaccess.h>
#include <asm/uaccess.h>
#include <asm/atomic.h>
#include <asm/unistd.h>
static int LED_Major = 0;
static struct class *led_driver_class;
volatile unsigned long *GPMCON,*GPMDAT;
static int s3c6410_led_open(struct inode *inode,struct file *file)
{
printk("s3c6410_led_open\n");
(*GPMCON) &= ~(0xffff);
(*GPMCON) |= (0x1111);
return 0;
}
static int s3c6410_led_close(struct inode *inode,struct file *file)
{
printk("s3c6410_led_close\n");
return 0;
}
static int s3c6410_led_write(struct file *file, char __user *buff,size_t count,loff_t *offp)
{
int value;
copy_from_user(&value,buff,count);
if(value == 0)
(*GPMDAT) &= ~(0xf);
else if(value == 1)
(*GPMDAT) |= 0xf;
else{
printk("the writed value must be 1 or 0\n");
return 1;
}
return 0;
}
static struct file_operations led_fops = {
.owner = THIS_MODULE,
.open = s3c6410_led_open,
.write = s3c6410_led_write,
.release = s3c6410_led_close,
};
static int __init led_init(void)
{
LED_Major = register_chrdev(LED_Major,"led_driver",&led_fops);
led_driver_class = class_create(THIS_MODULE,"led_driver");
device_create(led_driver_class,NULL,MKDEV(LED_Major,0),NULL,"led_driver");
GPMCON = (volatile unsigned long*)ioremap(0x7F008820,16);
GPMDAT = (volatile unsigned long*)ioremap(0x7F008824,4);
(*GPMCON) &= ~(0xffff);
(*GPMCON) |= (0x1111);
(*GPMDAT) &= ~(0xf);
printk("led_init\n");
return 0;
}
static void __exit led_exit(void)
{
unregister_chrdev(LED_Major,"led_driver");
device_destroy(led_driver_class,MKDEV(LED_Major,0));
class_destroy(led_driver_class);
iounmap(GPMCON);
iounmap(GPMDAT);
printk("led_exit\n");
}
module_init(led_init);
module_exit(led_exit);
MODULE_AUTHOR("cjw_yyw");
MODULE_DESCRIPTION("yyw_study 6410 led driver");
MODULE_LICENSE("GPL");
2,Kconfig和Makefile添加代码
Kconfig
config LEDS_MY_LED
tristate "Study Android The First Test LED"
help
This is my first Android Driver!
tristate "Study Android The First Test LED"
help
This is my first Android Driver!
Makefile
#added by cjw 2014-09-23 15:35
obj-y += my-led.o
obj-y += my-led.o