Android驱动开发-Ok6410点灯

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!
Makefile
#added by cjw 2014-09-23 15:35
obj-y                                   += my-led.o
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值