?? s3c2410_kaiguanliangshuchu.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 + -