1、Linux26304在2440上的移植之触摸屏驱动嵌入式Linux之我行,主要讲述和总结了本人在学习嵌入式linux中的每个步骤。一为总结经验,二希望能给想入门嵌入式Linux的朋友提供方便。如有错误之处,谢请指正。 共享资源,欢迎转载: 一、移植环境 主 机:VMWare-Fedora 9 开发板:Mini2440-64MB Nand 编译器:arm-linux-gcc-4.3.2二、移植步骤1. 准备驱动源码。因为linux-2.6.30.4内核中没有提供合适的ADC驱动和触摸屏驱动,所以这里就直接用友善提供的驱动s3c24xx-adc.h#ifndef _S3C2410_ADC_H_#d
2、efine _S3C2410_ADC_H_#define ADC_WRITE(ch, prescale)(ch)16)&0x7)#define ADC_WRITE_GETPRE(data)(data)&0xff)#endif /* _S3C2410_ADC_H_ */mini2440_adc.c #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #includ
3、e #include #include s3c24xx-adc.h#undef DEBUG/#define DEBUG#ifdef DEBUG#define DPRINTK(x.) printk(_FUNCTION_(%d): ,_LINE_);printk(#x);#else#define DPRINTK(x.) (void)(0)#endif#define DEVICE_NAMEadcstatic void _iomem *base_addr;typedef struct wait_queue_head_t wait;int channel;int prescale;ADC_DEV;DEC
4、LARE_MUTEX(ADC_LOCK);static int OwnADC = 0;static ADC_DEV adcdev;static volatile int ev_adc = 0;static int adc_data;static struct clk*adc_clock;#define ADCCON (*(volatile unsigned long *)(base_addr + S3C2410_ADCCON)/ADC control#define ADCTSC (*(volatile unsigned long *)(base_addr + S3C2410_ADCTSC)/A
5、DC touch screen control#define ADCDLY (*(volatile unsigned long *)(base_addr + S3C2410_ADCDLY)/ADC start or Interval Delay#define ADCDAT0 (*(volatile unsigned long *)(base_addr + S3C2410_ADCDAT0)/ADC conversion data 0#define ADCDAT1 (*(volatile unsigned long *)(base_addr + S3C2410_ADCDAT1)/ADC conve
6、rsion data 1#define ADCUPDN (*(volatile unsigned long *)(base_addr + 0x14)/Stylus Up/Down interrupt status#define PRESCALE_DIS (0 14)#define PRESCALE_EN (1 14)#define PRSCVL(x) (x) 6)#define ADC_INPUT(x) (x) 3)#define ADC_START (1 0)#define ADC_ENDCVT (1 = len) int r = copy_to_user(buffer, str, len)
7、;return r ? r : len; else return -EINVAL;static int s3c2410_adc_open(struct inode *inode, struct file *filp)init_waitqueue_head(&(adcdev.wait);adcdev.channel=0;adcdev.prescale=0xff;DPRINTK( adc openedn);return 0;static int s3c2410_adc_release(struct inode *inode, struct file *filp)DPRINTK( adc close
8、dn);return 0;static struct file_operations dev_fops = owner:THIS_MODULE,open:s3c2410_adc_open,read:s3c2410_adc_read,release:s3c2410_adc_release,;static struct miscdevice misc = .minor = MISC_DYNAMIC_MINOR,.name = DEVICE_NAME,.fops = &dev_fops,;static int _init dev_init(void)int ret;base_addr=ioremap
9、(S3C2410_PA_ADC,0x20);if (base_addr = NULL) printk(KERN_ERR Failed to remap register blockn);return -ENOMEM;adc_clock = clk_get(NULL, adc);if (!adc_clock) printk(KERN_ERR failed to get adc clock sourcen);return -ENOENT;clk_enable(adc_clock);/* normal ADC */ADCTSC = 0;ret = request_irq(IRQ_ADC, adcdo
10、ne_int_handler, IRQF_SHARED, DEVICE_NAME, &adcdev);if (ret) iounmap(base_addr);return ret;ret = misc_register(&misc);printk (DEVICE_NAMEtinitializedn);return ret;static void _exit dev_exit(void)free_irq(IRQ_ADC, &adcdev);iounmap(base_addr);if (adc_clock) clk_disable(adc_clock);clk_put(adc_clock);adc
11、_clock = NULL;misc_deregister(&misc);EXPORT_SYMBOL(ADC_LOCK);module_init(dev_init);module_exit(dev_exit);MODULE_LICENSE(GPL);MODULE_AUTHOR(FriendlyARM Inc.);s3c2410_ts.c #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* F
12、or ts.dev.id.version */#define S3C2410TSVERSION0x0101#define WAIT4INT(x) (x)= 2;yp = 2;#ifdef CONFIG_TOUCHSCREEN_MY2440_DEBUGstruct timeval tv;do_gettimeofday(&tv);printk(KERN_DEBUG T: %06d, X: %03ld, Y: %03ldn, (int)tv.tv_usec, xp, yp);#endifinput_report_abs(dev, ABS_X, xp);input_report_abs(dev, AB
13、S_Y, yp);input_report_key(dev, BTN_TOUCH, 1);input_report_abs(dev, ABS_PRESSURE, 1);input_sync(dev);xp = 0;yp = 0;count = 0;iowrite32(S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST, base_addr+S3C2410_ADCTSC);iowrite32(ioread32(base_addr+S3C2410_ADCCON) | S3C2410_ADCCON_ENABLE_START, base_addr+S3C2410_ADCC
14、ON); else count = 0;input_report_key(dev, BTN_TOUCH, 0);input_report_abs(dev, ABS_PRESSURE, 0);input_sync(dev);iowrite32(WAIT4INT(0), base_addr+S3C2410_ADCTSC);if (OwnADC) OwnADC = 0;up(&ADC_LOCK);static struct timer_list touch_timer =TIMER_INITIALIZER(touch_timer_fire, 0, 0);static irqreturn_t styl
15、us_updown(int irq, void *dev_id)unsigned long data0;unsigned long data1;int updown;if (down_trylock(&ADC_LOCK) = 0) OwnADC = 1;data0 = ioread32(base_addr+S3C2410_ADCDAT0);data1 = ioread32(base_addr+S3C2410_ADCDAT1);updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN) & (!(data1 & S3C2410_ADCDAT0_UPDOWN);if (
16、updown) touch_timer_fire(0); else OwnADC = 0;up(&ADC_LOCK);return IRQ_HANDLED;static irqreturn_t stylus_action(int irq, void *dev_id)unsigned long data0;unsigned long data1;if (OwnADC) data0 = ioread32(base_addr+S3C2410_ADCDAT0);data1 = ioread32(base_addr+S3C2410_ADCDAT1);xp += data0 & S3C2410_ADCDA
17、T0_XPDATA_MASK;yp += data1 & S3C2410_ADCDAT1_YPDATA_MASK;count+; if (count (12) iowrite32(S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST, base_addr+S3C2410_ADCTSC);iowrite32(ioread32(base_addr+S3C2410_ADCCON) | S3C2410_ADCCON_ENABLE_START, base_addr+S3C2410_ADCCON); else mod_timer(&touch_timer, jiffies+1);iowrite32(WAIT4INT(1), base_addr+S3C2410_ADCTSC);return IRQ_HANDLED;static struct clk*ad
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1