分类: LINUX
2008-12-05 15:17:58
Linux2.6内核2410 adc驱动程序
1、驱动程序,代码不是很多,直接贴出来了!
/*
* s
*
* S
* exclusive with s
*
* Author: SeonKon Choi
* Date : $Date: 2003/01/20 14:24:49 $
*
* $Revision:
*
Fri Dec 03 2002 SeonKon Choi
- initial
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "s
MODULE_LICENSE("Dual BSD/GPL");
int adc_major;
int adc_minor;
struct cdev adc_cdev;
static void __iomem *base_addr;
struct clk *clk;
static int ch;
int adc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
printk(KERN_ERR "cmd %d\n",cmd);
ch=cmd; //set up channel
return 0;
}
ssize_t s
{
int i,LOOP=10000;
clk_enable(clk); //enable clk
writel((1<<14)|S
for(i=0;i
writel((readl(base_addr+S
while((readl(base_addr+S
while(!(readl(base_addr+S
writel(0,base_addr+S
i=readl(base_addr+S
i= i & 0x3ff;
copy_to_user(buf, &i, sizeof i);
return sizeof i;
}
static ssize_t s
{
int data;
if(count!=sizeof(data)){
printk("the size of input data must be %d\n", sizeof(data));
return 0;
}
copy_from_user(&data, buffer, count);
ch=ADC_WRITE_GETCH(data);
return count;
}
struct file_operations adc_fops = {
.owner = THIS_MODULE,
.ioctl = adc_ioctl,
.read = s
.write = s
};
int S
{
int result,err;
dev_t dev =0;
result=alloc_chrdev_region(&dev,adc_minor,0,"2410adc");
adc_major = MAJOR(dev);
adc_minor = MINOR(dev);
if(result < 0)
printk(KERN_ERR "can't get major %d\n",adc_major);
else
printk("adc_major: %d\n",adc_major);
cdev_init(&adc_cdev,&adc_fops);
adc_cdev.owner=THIS_MODULE;
adc_cdev.ops=&adc_fops;
err=cdev_add(&adc_cdev,dev,1);
if (err < 0)
printk(KERN_ERR "can't add 2410_adc");
base_addr = ioremap(0x58000000, 0x20);
if (base_addr == NULL) {
printk(KERN_ERR "Failed to remap register block\n");
return -ENOMEM;
}
/* get our clock */
clk = clk_get(NULL, "adc");
if (IS_ERR(clk) || clk == NULL) {
printk(KERN_ERR "ADC clk_get err!!!!!!!!!!!!!\n");
}
/* only enable the clock when we are actually using the adc */
printk(KERN_ERR "add 2410_adc ok!!!!!!!!!!!!\n");
return 0;
}
void S
{
dev_t dev=MKDEV(adc_major,adc_minor);
cdev_del(&adc_cdev);
iounmap(base_addr);
unregister_chrdev_region(dev,1);
}
module_init(S
module_exit(S
2、驱动的头文件定义
#ifndef _S
#define _S
#define ADC_WRITE(ch, prescale) ((ch)<<16|(prescale))
#define ADC_WRITE_GETCH(data) (((data)>>16)&0x7)
#define ADC_WRITE_GETPRE(data) ((data)&0xff)
#endif /* _S
3、应用程序就不多说了,按照原来linux2.4的内核使用就可以了,不用做任何的改动。
4、需要注意的就是,这个驱动程序不能和触摸屏驱动一起使用。原来在linux
于北京
MSN:liuyingjie201000@hotmail.com