📄 s3c2410_adc.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/io.h># include <asm/hardware.h> # include <asm/arch/regs-gpio.h> # include <asm/uaccess.h> # include <asm/delay.h> # include <asm-arm/arch-s3c2410/regs-adc.h># include <asm/hardware/clock.h>#define DEVICE_NAME "adc" #define ADC_MAJOR 223 int i;//#define base_addr 0x58000000#define START_ADC {S3C2410_ADCCON_PRSCEN | S3C2410_ADCCON_PRSCVL(49) | S3C2410_ADCCON_SELMUX(i) | S3C2410_ADCCON_READ_START; } MODULE_AUTHOR("Luofuchong"); MODULE_LICENSE("Dual BSD/GPL"); MODULE_ALIAS("led"); static void __iomem *base_addr;/*static unsigned long led_table [] = { S3C2410_GPG12, S3C2410_GPG13, S3C2410_GPB9, S3C2410_GPB10, S3C2410_GPG12_OUTP, S3C2410_GPG13_OUTP, S3C2410_GPB9_OUTP, S3C2410_GPB10_OUTP, };*/ static int s3c2410_adc_ioctl(struct inode *inode, struct file *file, unsigned int channel, unsigned long arg) { long int tmp=100; int dianya; i=channel; writel(START_ADC, base_addr+S3C2410_ADCCON); tmp = (readl( base_addr + S3C2410_ADCDAT0) & 0x3ff); dianya = tmp * 3300 /1024;// dianya = base_addr;/* switch(cmd) { case 0: case 1: if (arg > 3) { return -EINVAL; } s3c2410_gpio_setpin(led_table[arg],!cmd); break; default: return -EINVAL; }*/ return dianya; } static struct file_operations s3c2410_adc_fops = { .owner = THIS_MODULE, .ioctl = s3c2410_adc_ioctl, }; static struct class *led_class; static struct clk *adc_clock; static int __init s3c2410_adc_init(void) { int err = 0; if(register_chrdev(ADC_MAJOR,"adc",&s3c2410_adc_fops)){ printk("led driver:Unable to register driver\n"); return -ENODEV; } adc_clock = clk_get(NULL, "adc"); if (!adc_clock) { printk(KERN_ERR "failed to get adc clock source\n"); return -ENOENT; } clk_use(adc_clock); clk_enable(adc_clock); base_addr=ioremap(S3C2410_PA_ADC,0x20); if (base_addr == NULL) { printk(KERN_ERR "Failed to remap register block\n"); return -ENOMEM; } led_class = class_create(THIS_MODULE, "adc"); if(IS_ERR(led_class)){ err = PTR_ERR(led_class); goto out_chrdev; } class_device_create(led_class,MKDEV(ADC_MAJOR, 0),NULL,"adc"); err = devfs_mk_cdev(MKDEV(ADC_MAJOR,0), S_IFCHR | S_IRUGO | S_IWUSR,"adc"); if(err) goto out_class; /* for(i=0;i<4;i++){ s3c2410_gpio_cfgpin(led_table[i],led_table[i+4]); s3c2410_gpio_setpin(led_table[i],1); } */ printk("adc driver initialized\n"); goto out; out_class: class_device_destroy(led_class,MKDEV(ADC_MAJOR, 0)); class_destroy(led_class); out_chrdev: unregister_chrdev(ADC_MAJOR, "adc"); out: return err; } static void __exit s3c2410_adc_exit(void) { class_device_destroy(led_class,MKDEV(ADC_MAJOR,0)); class_destroy(led_class); unregister_chrdev(ADC_MAJOR,"adc"); devfs_remove("adc"); printk("adc driver removed\n"); } module_init(s3c2410_adc_init);module_exit(s3c2410_adc_exit);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -