#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/input.h>
#include <linux/init.h>
#include <linux/serio.h>
#include <linux/delay.h>
#include <linux/clk.h>
#include <linux/wait.h>
#include <linux/sched.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <linux/cdev.h>
#include <linux/miscdevice.h>
#include <mach/hardware.h>
#include <mach/irqs.h>
#include <mach/w55fa93_reg.h>
#include <linux/input.h>
#include <linux/clk.h>
#define DEVICE_NAME "adc"
#define outp32(addr, value) writel(value, addr)
#define inp32(addr) readl(addr)
static void __iomem *base_addr;
#define ADC_INPUT(x) ((x) << 9)
#define SET_NORMAL_AIN2_WI do{\
outl( (ADC_CON_ADC_EN | ADC_CONV | ADC_INT | (2<<9)), \
REG_ADC_CON);\
}while(0)
#define SET_NORMAL_AIN2_WI_WR \
while( (inl(REG_ADC_CON) & ADC_INT) != ADC_INT )
#define SET_NORMAL_AIN0_WI do{\
outl( (ADC_CON_ADC_EN | ADC_CONV | ADC_INT | (0<<9)), \
REG_ADC_CON);\
}while(0)
#define SET_NORMAL_AIN0_WI_WR \
while( (inl(REG_ADC_CON) & ADC_INT) != ADC_INT )
static ssize_t w55fa93_adc_read(struct file *filp, char *buffer, size_t count, loff_t *ppos)
{
unsigned int adc_data = -1;
SET_NORMAL_AIN2_WI;
SET_NORMAL_AIN2_WI_WR;
adc_data = inl(REG_ADC_XDATA);
// printk("adc_data=%d\n", adc_data);
if (adc_data != -1)
{
copy_to_user(buffer, &adc_data, sizeof(adc_data));
}
return 0;
}
static int w55fa93_adc_open(struct inode *inode, struct file *filp)
{
printk( "adc opened\n");
outp32(REG_APBIPRST, inp32(REG_APBIPRST) | ADCRST);
outp32(REG_APBIPRST, inp32(REG_APBIPRST) & ~ADCRST);
return 0;
}
static int w55fa93_adc_release(struct inode *inode, struct file *filp)
{
printk( "adc closed\n");
return 0;
}
static struct file_operations dev_fops = {
owner: THIS_MODULE,
open: w55fa93_adc_open,
read: w55fa93_adc_read,
release: w55fa93_adc_release,
};
static struct miscdevice misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &dev_fops,
};
static int __init dev_init(void)
{
int ret;
struct clk *clk;
base_addr=ioremap(W55FA93_PA_ADC, 0x20);
if (base_addr == NULL) {
printk(KERN_ERR "Failed to remap register block\n");
return -ENOMEM;
}
printk("base_addr:0x%lx\n", (unsigned long)base_addr);
clk = clk_get(NULL, "ADC");
clk_enable(clk);
ret = misc_register(&misc);
printk (DEVICE_NAME"\tinitialized\n");
return ret;
}
static void __exit dev_exit(void)
{
struct clk *clk;
clk = clk_get(NULL, "ADC");
clk_disable(clk);
iounmap(base_addr);
printk (DEVICE_NAME"\texit!\n");
misc_deregister(&misc);
}
module_init(dev_init);
module_exit(dev_exit);
MODULE_AUTHOR("zpzyf");
MODULE_DESCRIPTION("w55fa93 adc char driver");
MODULE_LICENSE("GPL");
|