标签:des style blog http io ar 使用 sp for
出处:http://blog.csdn.net/geekcome/article/details/6580981
硬件平台:FL2440
内核版本:2.6.28
主机平台:Ubuntu 11.04
内核版本:2.6.39
原创作品,转载请标明出处http://blog.csdn.net/yming0221/article/details/6580981
1、下面是ADC和触摸屏接口的模块图
![bubuko.com,布布扣](http://hi.csdn.net/attachment/0_130959143293Aa.gif)
当触摸屏接口使用时,XM或YM接触摸屏接口的地
当触摸屏接口不使用时,XM或YM接模拟信号,做普通ADC使用。
2、触摸屏接口的几种操作模式
(1) 正常转换模式
通过设置ADCCON(adc控制寄存器)来完成初始化,并对ADCDAT0数据寄存器进行操作。
(2) 分离XY坐标模式
X坐标模式写X坐标转换数据到ADCDAT0,触摸屏接口产生中断到中断控制寄存器。Y坐标模式写Y坐标转换数据到ADCDAT1,触摸屏接口产生中断到中断控制寄存器。两种模
式可以选择一种模式工作。
相应的引脚连接:
![bubuko.com,布布扣](http://hi.csdn.net/attachment/0_1309593667342U.gif)
(3) 自动XY坐标模式
触摸屏控制器连续的转换X和Y的坐标,在X坐标转换后的值存入ADCDAT0后,自动将Y坐标转换后的值存入ADCDAT1,触摸屏接口产生中断到中断控制器。
相应的引脚连接:
![bubuko.com,布布扣](http://hi.csdn.net/attachment/0_1309593667342U.gif)
(4) 等待中断模式
当光标被按下,触摸屏控制器产生中断IRQ_TC,当产生中断信号时,等待中断模式必须被清除。
引脚定义如下:
![bubuko.com,布布扣](http://hi.csdn.net/attachment/0_1309594217RcN8.gif)
3、下面是s3c2440触摸屏驱动的分析
-
- #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/platform_device.h>
- #include <linux/clk.h>
- #include <asm/io.h>
- #include <asm/irq.h>
-
- #include <mach/regs-gpio.h>
- #include <mach/s3c2410_ts.h>
-
- #include <plat/regs-adc.h>
-
- #define TRUE 1 //CoAsia added
- #define FALSE 0 //CoAsia added
- #define FILTER_LIMIT 25 //CoAsia added
-
- #define S3C2410TSVERSION 0x0101
-
- #define TSC_SLEEP (S3C2410_ADCTSC_PULL_UP_DISABLE | S3C2410_ADCTSC_XY_PST(0))
-
- #define WAIT4INT(x) (((x)<<8) | \
- S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
- S3C2410_ADCTSC_XY_PST(3))
-
- #define AUTOPST (S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
- S3C2410_ADCTSC_AUTO_PST | S3C2410_ADCTSC_XY_PST(0))
-
- #define DEBUG_LVL "<3>" //KERN_DEBUG
-
- static char *s3c2440ts_name = "s3c2440 TouchScreen";
-
- struct s3c2440ts {
- struct input_dev *dev;
- long xp;
- long yp;
- int count;
- int shift;
- };
-
- static struct s3c2440ts ts;
- static struct clk *adc_clock;
-
- static void __iomem *base_addr;
-
- static void touch_timer_fire(unsigned long data);
- static irqreturn_t tc_irq(int irq, void *dev_id);
- static irqreturn_t adc_irq(int irq, void *dev_id);
- static int __init s3c2440ts_probe(struct platform_device *pdev);
- static int s3c2440ts_remove(struct platform_device *pdev);
- static int s3c2440ts_resume(struct platform_device *pdev);
-
- static struct timer_list touch_timer =
- TIMER_INITIALIZER(touch_timer_fire, 0, 0);
-
-
- static irqreturn_t tc_irq(int irq, void *dev_id)
- {
-
- unsigned long data0;
- unsigned long data1;
- int updown;
-
-
- data0 = readl(base_addr+S3C2410_ADCDAT0);
- data1 = readl(base_addr+S3C2410_ADCDAT1);
-
-
- updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));
-
-
-
-
- if (updown)
- touch_timer_fire(0);
-
- return IRQ_HANDLED;
- }
-
- static void touch_timer_fire(unsigned long data)
- {
-
- unsigned long data0;
- unsigned long data1;
-
-
- int updown;
-
- data0 = readl(base_addr+S3C2410_ADCDAT0);
- data1 = readl(base_addr+S3C2410_ADCDAT1);
-
- updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));
-
- if (updown)
- {
-
- if (ts.count != 0)
- {
- ts.xp >>= ts.shift;
- ts.yp >>= ts.shift;
-
- #ifdef CONFIG_TOUCHSCREEN_S3C2410_DEBUG
- {
- struct timeval tv;
- do_gettimeofday(&tv);
- printk(DEBUG_LVL "T: %06d, X: %03ld, Y: %03ld\n", (int)tv.tv_usec, ts.xp, ts.yp);
- }
- #endif
-
- input_report_abs(ts.dev, ABS_X, ts.xp);
- input_report_abs(ts.dev, ABS_Y, ts.yp);
-
-
- input_report_key(ts.dev, BTN_TOUCH, 1);
-
- input_report_abs(ts.dev, ABS_PRESSURE, 1);
-
- input_sync(ts.dev);
- }
-
- ts.xp = 0;
- ts.yp = 0;
- ts.count = 0;
-
-
-
- writel(S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST, base_addr+S3C2410_ADCTSC);
-
- writel(readl(base_addr+S3C2410_ADCCON) | S3C2410_ADCCON_ENABLE_START, base_addr+S3C2410_ADCCON);
- }
- else
- {
- ts.count = 0;
-
- input_report_key(ts.dev, BTN_TOUCH, 0);
- input_report_abs(ts.dev, ABS_PRESSURE, 0);
-
- input_sync(ts.dev);
-
- writel(WAIT4INT(0), base_addr+S3C2410_ADCTSC);
- }
- }
-
-
- static irqreturn_t adc_irq(int irq, void *dev_id)
- {
-
- unsigned long data0;
- unsigned long data1;
-
- data0 = readl(base_addr+S3C2410_ADCDAT0);
- data1 = readl(base_addr+S3C2410_ADCDAT1);
-
- ts.xp += data0 & S3C2410_ADCDAT0_XPDATA_MASK;
- ts.yp += data1 & S3C2410_ADCDAT1_YPDATA_MASK;
-
- ts.count++;
-
-
- if (ts.count < (1<<ts.shift))
- {
-
- writel(S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST, base_addr+S3C2410_ADCTSC);
-
- writel(readl(base_addr+S3C2410_ADCCON) | S3C2410_ADCCON_ENABLE_START, base_addr+S3C2410_ADCCON);
- }
- else
- {
- mod_timer(&touch_timer, jiffies+1);
- writel(WAIT4INT(1), base_addr+S3C2410_ADCTSC);
- }
-
- return IRQ_HANDLED;
- }
-
-
-
- static int __init s3c2440ts_probe(struct platform_device *pdev)
- {
- int rc;
-
- struct s3c2410_ts_mach_info *info;
- struct input_dev *input_dev;
-
- info = ( struct s3c2440_ts_mach_info *)pdev->dev.platform_data;
-
- if (!info)
- {
- printk(KERN_ERR "Hm... too bad : no platform data for ts\n");
- return -EINVAL;
- }
-
- #ifdef CONFIG_TOUCHSCREEN_S3C2410_DEBUG
- printk(DEBUG_LVL "Entering s3c2440ts_init\n");
- #endif
-
- adc_clock = clk_get(NULL, "adc");
- if (!adc_clock) {
- printk(KERN_ERR "failed to get adc clock source\n");
- return -ENOENT;
- }
- clk_enable(adc_clock);
-
- #ifdef CONFIG_TOUCHSCREEN_S3C2410_DEBUG
- printk(DEBUG_LVL "got and enabled clock\n");
- #endif
-
- base_addr = ioremap(S3C2410_PA_ADC,0x20);
- if (base_addr == NULL) {
- printk(KERN_ERR "Failed to remap register block\n");
- return -ENOMEM;
- }
-
-
-
- if ((info->presc&0xff) > 0)
- writel(S3C2410_ADCCON_PRSCEN | S3C2410_ADCCON_PRSCVL(info->presc&0xFF),\
- base_addr+S3C2410_ADCCON);
- else
- writel(0,base_addr+S3C2410_ADCCON);
-
-
-
-
-
- if ((info->delay&0xffff) > 0)
- writel(info->delay & 0xffff, base_addr+S3C2410_ADCDLY);
-
-
- writel(WAIT4INT(0), base_addr+S3C2410_ADCTSC);
-
-
- memset(&ts, 0, sizeof(struct s3c2440ts));
-
-
- input_dev = input_allocate_device();
-
- if (!input_dev) {
- printk(KERN_ERR "Unable to allocate the input device !!\n");
- return -ENOMEM;
- }
-
- ts.dev = input_dev;
- ts.dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) |
- BIT_MASK(EV_ABS);
- ts.dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
- input_set_abs_params(ts.dev, ABS_X, 0, 0x3FF, 0, 0);
- input_set_abs_params(ts.dev, ABS_Y, 0, 0x3FF, 0, 0);
- input_set_abs_params(ts.dev, ABS_PRESSURE, 0, 1, 0, 0);
-
-
- ts.dev->name = s3c2440ts_name;
- ts.dev->id.bustype = BUS_RS232;
- ts.dev->id.vendor = 0xDEAD;
- ts.dev->id.product = 0xBEEF;
- ts.dev->id.version = S3C2410TSVERSION;
-
- ts.shift = info->oversampling_shift;
-
-
-
-
-
- if (request_irq(IRQ_ADC, adc_irq, IRQF_SAMPLE_RANDOM | IRQF_SHARED,
- "s3c2440_action", ts.dev)) {
- printk(KERN_ERR "s3c2440_ts.c: Could not allocate ts IRQ_ADC !\n");
- iounmap(base_addr);
- return -EIO;
- }
-
- if (request_irq(IRQ_TC, tc_irq, IRQF_SAMPLE_RANDOM,
- "s3c2440_action", ts.dev)) {
- printk(KERN_ERR "s3c2440_ts.c: Could not allocate ts IRQ_TC !\n");
- free_irq(IRQ_ADC, ts.dev);
- iounmap(base_addr);
- return -EIO;
- }
-
- printk(KERN_INFO "%s successfully loaded\n", s3c2440ts_name);
-
-
-
-
- rc = input_register_device(ts.dev);
- if (rc) {
- free_irq(IRQ_TC, ts.dev);
- free_irq(IRQ_ADC, ts.dev);
- clk_disable(adc_clock);
- iounmap(base_addr);
- return -EIO;
- }
-
- return 0;
- }
-
- static int s3c2440ts_remove(struct platform_device *pdev)
- {
- disable_irq(IRQ_ADC);
- disable_irq(IRQ_TC);
- free_irq(IRQ_TC,ts.dev);
- free_irq(IRQ_ADC,ts.dev);
-
- if (adc_clock) {
- clk_disable(adc_clock);
- clk_put(adc_clock);
- adc_clock = NULL;
- }
-
- input_unregister_device(ts.dev);
- iounmap(base_addr);
-
- return 0;
- }
-
- #ifdef CONFIG_PM
- static int s3c2440ts_suspend(struct platform_device *pdev, pm_message_t state)
- {
- writel(TSC_SLEEP, base_addr+S3C2410_ADCTSC);
- writel(readl(base_addr+S3C2410_ADCCON) | S3C2410_ADCCON_STDBM,
- base_addr+S3C2410_ADCCON);
-
- disable_irq(IRQ_ADC);
- disable_irq(IRQ_TC);
-
- clk_disable(adc_clock);
-
- return 0;
- }
-
- static int s3c2440ts_resume(struct platform_device *pdev)
- {
- struct s3c2440_ts_mach_info *info =
- ( struct s3c2440_ts_mach_info *)pdev->dev.platform_data;
-
- clk_enable(adc_clock);
- msleep(1);
-
- enable_irq(IRQ_ADC);
- enable_irq(IRQ_TC);
-
- if ((info->presc&0xff) > 0)
- writel(S3C2410_ADCCON_PRSCEN | S3C2410_ADCCON_PRSCVL(info->presc&0xFF),\
- base_addr+S3C2410_ADCCON);
- else
- writel(0,base_addr+S3C2410_ADCCON);
-
-
- if ((info->delay&0xffff) > 0)
- writel(info->delay & 0xffff, base_addr+S3C2410_ADCDLY);
-
- writel(WAIT4INT(0), base_addr+S3C2410_ADCTSC);
-
- return 0;
- }
-
- #else
- #define s3c2440ts_suspend NULL
- #define s3c2440ts_resume NULL
- #endif
- static struct platform_driver s3c2440ts_driver = {
- .driver = {
- .name = "s3c2440-ts",
- .owner = THIS_MODULE,
- },
- .probe = s3c2440ts_probe,
- .remove = s3c2440ts_remove,
- .suspend = s3c2440ts_suspend,
- .resume = s3c2440ts_resume,
-
- };
-
- static int __init s3c2440ts_init(void)
- {
- int rc;
- rc = platform_driver_register(&s3c2440ts_driver);
- if (rc < 0)
- printk(KERN_ERR "platform_driver_register error!\n");
- return rc;
- }
-
- static void __exit s3c2440ts_exit(void)
- {
- platform_driver_unregister(&s3c2440ts_driver);
- }
-
- module_init(s3c2440ts_init);
- module_exit(s3c2440ts_exit);
-
- MODULE_AUTHOR("YANMING");
- MODULE_DESCRIPTION("My s3c2440 touchscreen driver");
- MODULE_LICENSE("GPL");
4、分析完成后对触摸屏的工作过程就有了一个比较明确的认识
从触摸屏被按下到系统相应的过程如下:
(1) 当触摸屏感觉到触摸,触发IRQ_TC中断,然后读取触摸屏控制寄存器的值,判断是否被按下,如果被按下,启动定时器,执行touch_timer_fire()函数启动ADC转换。
(2) ADC转换完成后,会触发IRQ_ADC中断,执行相应的中断处理函数,如果ADC转换次数小于4,再次启动ADC转换;如果ADC转换次数为4,则启动一个系统滴答定时器,执行touch_timer_fire()函数
(3) 执行定时器服务程序时,如果此时触摸屏仍被按下,则上报事件和坐标数据,重复(2);如果没有被按下,上报时间和坐标数据,将触摸屏控制寄存器设置为中断等待状态
可见,触摸屏驱动的服务是一个封闭的循环过程。
ARM-Linux驱动-触摸屏驱动分析
标签:des style blog http io ar 使用 sp for
原文地址:http://www.cnblogs.com/0822vaj/p/4088698.html