www.pudn.com > second_drv_led.rar > second_drv.c, change:2016-08-17,size:2459b


 
#include <linux/module.h> 
#include <linux/kernel.h> 
#include <linux/init.h> 
#include <linux/interrupt.h> 
#include <linux/ioport.h> 
#include <linux/device.h> 
#include <linux/serio.h> 
#include <linux/delay.h> 
#include <linux/err.h> 
#include <linux/fs.h> 
#include <linux/bcd.h> 
#include <linux/errno.h> 
#include <linux/slab.h> 
#include <linux/input.h> 
#include <linux/types.h> 
#include <linux/cdev.h> 
#include <linux/miscdevice.h> 
#include <linux/poll.h> 
#include <linux/spinlock.h> 
#include <asm/plat-s3c/regs-adc.h> 
#include <linux/clk.h> 
  
#include <asm/io.h> 
#include <asm/hardware.h> 
#include <linux/sched.h> 
#include <asm/irq.h> 
#include <asm/semaphore.h> 
#include <asm/arch/regs-gpio.h> 
#include <asm/uaccess.h> 
 
static struct class *seconddrv_class; 
static struct class_device	*seconddrv_class_dev; 
 
 
volatile unsigned long *gpccon=NULL; 
volatile unsigned long *gpcdat=NULL; 
  
 
 
static int second_drv_open(struct inode *inode, struct file *file) 
{ 
		printk( "zys  device open!\n"); 
		/*配置gpc5,6,7输出   点灯*/ 
		*gpccon  &= ~(3<<10 |3<<12 | 3<<14); 
		*gpccon  |= (1<<10 |1<<12 | 1<<14); 
		 
		 
		/*5  on 6 off  7 on*/ 
		*gpcdat  &= ~(1<<5 |1<<6 | 1<<7); 
		*gpcdat  |= (0<<5 |1<<6 | 0<<7); 
		 
		 
	  
 
	return 0; 
} 
 
ssize_t second_drv_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) 
{ 
	/* 返回4个引脚的电平 */ 
	unsigned char key_vals[4]; 
 //  printk( "zys device read!\n"); 
	 
	return sizeof(key_vals); 
} 
 
 
static struct file_operations sencod_drv_fops = { 
    .owner  =   THIS_MODULE,    /* 这是一个宏,推向编译模块时自动创建的__this_module变量 */ 
    .open   =   second_drv_open,      
	.read	=	second_drv_read,	    
}; 
 
 
int major; 
static int second_drv_init(void) 
{ 
	major = register_chrdev(0, "second_drv", &sencod_drv_fops); 
 
	seconddrv_class = class_create(THIS_MODULE, "second_drv"); 
 
	seconddrv_class_dev = class_device_create(seconddrv_class, NULL, MKDEV(major, 0), NULL, "buttons"); /* /dev/buttons */ 
 
	gpccon = (volatile unsigned long *)ioremap(0x56000020,16); 
	gpcdat =gpccon+1; 
 
 
	 
	 
	  printk( "zys device init!\n"); 
 
	return 0; 
} 
 
static void second_drv_exit(void) 
{ 
	unregister_chrdev(major, "second_drv"); 
	class_device_unregister(seconddrv_class_dev); 
	class_destroy(seconddrv_class); 
	iounmap(gpccon); 
 
	return 0; 
} 
 
 
module_init(second_drv_init); 
 
module_exit(second_drv_exit); 
 
MODULE_LICENSE("GPL");