Resistive touch screen driver (II)

First look at the hardware and operating what things need doing. Look TSYP, TSXP, TSYM, TSXM four pins received where?

Search TSYP pin

 

 TSYM, TSYP, TSXM, TSXP were received AIN4, AIN5, AIN6, on AIN7, they are not ordinary GPIO pins.

Search AIN4 chip manual in 2440, found either as analog inputs, or used as a touch screen, so no configuration registers.

  1 #include <linux/errno.h>
  2 #include <linux/kernel.h>
  3 #include <linux/module.h>
  4 #include <linux/slab.h>
  5 #include <linux/input.h>
  6 #include <linux/init.h>
  7 #include <linux/serio.h>
  8 #include <linux/delay.h>
  9 #include <linux/platform_device.h>
 10 #include <linux/clk.h>
 11 #include <asm/io.h>
 12 #include <asm/irq.h>
 13 
 14 #include <asm/plat-s3c24xx/ts.h>
 15 
 16 #include <asm/arch/regs-adc.h>
 17 #include <asm/arch/regs-gpio.h>
 18 
 19 struct s3c_ts_regs {
 20     unsigned long adccon;
 21     unsigned long adctsc;
 22     unsigned long adcdly;
 23     unsigned long adcdat0;
 24     unsigned long adcdat1;
 25     unsigned long adcupdn;
 26 };
 27 
 28 static struct input_dev *s3c_ts_dev;
 29 static volatile struct s3c_ts_regs *s3c_ts_regs;
 30 
 31 static void enter_wait_pen_down_mode(void)
 32 {
 33     s3c_ts_regs->adctsc = 0xd3;
 34 }
 35 
 36 static void enter_wait_pen_up_mode(void)
 37 {
 38     s3c_ts_regs->adctsc = 0x1d3;
 39 }
 40 
 41 static irqreturn_t pen_down_up_irq(int irq, void *dev_id)
 42 {
 43     if (s3c_ts_regs->adcdat0 & (1<<15))/*通过该寄存器的第15位判断触摸笔是按下还是松开,如果是1的话表示松开*/
 44     {
 45         printk("pen up\n");
 46         enter_wait_pen_down_mode();  /*松开时,进入等待按下模式*/
 47     }
 48     else/*按下*/
 49     {
 50         printk("pen down\n");
 51         enter_wait_pen_up_mode();/*按下时,进入抬起模式*/
 52     }
 53     return IRQ_HANDLED;
 54 }
 55 
 56 static int s3c_ts_init(void)
 57 {
 58     struct clk* clk;
 59     
 60     /* 1. 分配一个input_dev结构体 */
 61     s3c_ts_dev = input_allocate_device();
 62 
 63     /* 2. 设置 */
 64     /* 2.1 能产生哪类事件 */
 65     set_bit(EV_KEY, s3c_ts_dev->evbit);
 66     set_bit(EV_ABS, s3c_ts_dev->evbit);
 67 
 68     /* 2.2 能产生这类事件里的哪些事件 */
 69     set_bit(BTN_TOUCH, s3c_ts_dev->keybit);
 70 
 71     input_set_abs_params(s3c_ts_dev, ABS_X, 0, 0x3FF, 0, 0);
 72     input_set_abs_params(s3c_ts_dev, ABS_Y, 0, 0x3FF, 0, 0);
 73     input_set_abs_params(s3c_ts_dev, ABS_PRESSURE, 0, 1, 0, 0);
 74 
 75 
 76     /* 3. 注册 */
 77     input_register_device(s3c_ts_dev);
 78 
 79     /* 4. 硬件相关的操作 */
 80     /* 4.1 使能时钟(CLKCON[15]) */
 81     clk = clk_get(NULL, "adc");
 82     clk_enable(clk);
 83     
 84     /* 4.2 设置S3C2440的ADC/TS寄存器 */
 85     s3c_ts_regs = ioremap(0x58000000, sizeof(struct s3c_ts_regs));
 86 
 87     /* bit[14]  : 1-A/D converter prescaler enable
 88      * bit[13:6]: A/D converter prescaler value,
 89      *            49, ADCCLK=PCLK/(49+1)=50MHz/(49+1)=1MHz
 90      * bit[0]: A/D conversion starts by enable. 先设为0
 91      */
 92     s3c_ts_regs->adccon = (1<<14)|(49<<6);
 93 
 94     request_irq(IRQ_TC, pen_down_up_irq, IRQF_SAMPLE_RANDOM, "ts_pen", NULL);
 95 
 96     enter_wait_pen_down_mode();
 97     
 98     return 0;
 99 }
100 
101 static void s3c_ts_exit(void)
102 {
103     free_irq(IRQ_TC, NULL);
104     iounmap(s3c_ts_regs);
105     input_unregister_device(s3c_ts_dev);
106     input_free_device(s3c_ts_dev);
107 }
108 
109 module_init(s3c_ts_init);
110 module_exit(s3c_ts_exit);
111 
112 
113 MODULE_LICENSE("GPL");

 

Guess you like

Origin www.cnblogs.com/-glb/p/11273353.html