⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s3c2410_kaiguanliangshuchu.c

📁 s3c2410开关量输出驱动程序
💻 C
字号:
# include <linux/config.h>
# include <linux/module.h> 
# include <linux/kernel.h> 
# include <linux/init.h> 
# include <linux/device.h>
# include <linux/delay.h> 
# include <linux/devfs_fs_kernel.h>

# include <asm/hardware.h> 
# include <asm/arch/regs-gpio.h> 
# include <asm/uaccess.h> 
# include <asm/delay.h>     


#define DEVICE_NAME "kglsc"
#define KGLSC_MAJOR 0
     

MODULE_AUTHOR("Shu"); 
MODULE_LICENSE("Dual BSD/GPL"); 
MODULE_ALIAS("kglsc"); 
     
static unsigned long kglsc_table [] = { 
	S3C2410_GPG12, 
	S3C2410_GPG13, 
	S3C2410_GPB9, 
	S3C2410_GPB10, 
	S3C2410_GPG12_OUTP, 
	S3C2410_GPG13_OUTP, 
	S3C2410_GPB9_OUTP, 
	S3C2410_GPB10_OUTP, 
}; 
     
     
static int kglsc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long channel) {
	switch(cmd) { 
		case 0: 
		case 1: 
		if (arg > 3) { 
			return -EINVAL; 
		} 
		s3c2410_gpio_setpin(kglsc_table[channel],!cmd); 
		break; 
		default: 
		return -EINVAL; 
	} 
	return channel; 
} 
     
static struct file_operations kglsc_fops = { 
	.owner = THIS_MODULE, 
	.ioctl = kglsc_ioctl, 
}; 
     
static struct class *kglsc_class; 
     
static int __init kglsc_init(void) 
{ 
	int err = 0; 
	int i;

   
               
	if(register_chrdev(KGLSC_MAJOR,"kglsc",&kglsc_fops)){ 
		printk("kglsc driver:Unable to register driver\n"); 
		return -ENODEV; 
	} 
              
	kglsc_class = class_create(THIS_MODULE, "kglsc"); 
	if(IS_ERR(kglsc_class)){ 
		err = PTR_ERR(kglsc_class); 
		goto out_chrdev; 
	} 
	class_device_create(kglsc_class,MKDEV(KGLSC_MAJOR, 0),NULL,"kglsc"); 
               
	err = devfs_mk_cdev(MKDEV(KGLSC_MAJOR,0),S_IFCHR | S_IRUGO | S_IWUSR,"kglsc"); 
	if(err) 
		goto out_class; 
     
	for(i=0;i<4;i++){ 
		s3c2410_gpio_cfgpin(kglsc_table[i],kglsc_table[i+4]); 
		s3c2410_gpio_setpin(kglsc_table[i],1); 
	} 
	printk("KaiGuanLiangShuChu driver initialized\n"); 
	goto out; 
     
	out_class: 
	class_device_destroy(kglsc_class,MKDEV(KGLSC_MAJOR, 0));
	class_destroy(kglsc_class); 
	out_chrdev: 
	unregister_chrdev(KGLSC_MAJOR, "kglsc"); 
	out: 
	return err; 
} 
     
static void __exit kglsc_exit(void){ 
	class_device_destroy(kglsc_class,MKDEV(KGLSC_MAJOR,0)); 
	class_destroy(kglsc_class); 
	unregister_chrdev(KGLSC_MAJOR,"kglsc"); 
	devfs_remove("kglsc"); 
	printk("KaiGuanLiangShuChu driver removed\n"); 
} 
     
module_init(kglsc_init);
module_exit(kglsc_exit);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -