Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/agpgart
[linux-2.6] / drivers / input / touchscreen / hp680_ts_input.c
1 #include <linux/input.h>
2 #include <linux/module.h>
3 #include <linux/init.h>
4
5 #include <linux/interrupt.h>
6 #include <asm/io.h>
7 #include <asm/delay.h>
8 #include <asm/adc.h>
9 #include <asm/hp6xx/hp6xx.h>
10
11 #define MODNAME "hp680_ts_input"
12
13 #define HP680_TS_ABS_X_MIN      40
14 #define HP680_TS_ABS_X_MAX      950
15 #define HP680_TS_ABS_Y_MIN      80
16 #define HP680_TS_ABS_Y_MAX      910
17
18 #define SCPCR   0xa4000116
19 #define PHDR    0xa400012e
20 #define SCPDR   0xa4000136
21
22 static void do_softint(void *data);
23
24 static struct input_dev *hp680_ts_dev;
25 static DECLARE_WORK(work, do_softint, 0);
26
27 static void do_softint(void *data)
28 {
29         int absx = 0, absy = 0;
30         u8 scpdr;
31         int touched = 0;
32
33         if (ctrl_inb(PHDR) & PHDR_TS_PEN_DOWN) {
34                 scpdr = ctrl_inb(SCPDR);
35                 scpdr |= SCPDR_TS_SCAN_ENABLE;
36                 scpdr &= ~SCPDR_TS_SCAN_Y;
37                 ctrl_outb(scpdr, SCPDR);
38                 udelay(30);
39
40                 absy = adc_single(ADC_CHANNEL_TS_Y);
41
42                 scpdr = ctrl_inb(SCPDR);
43                 scpdr |= SCPDR_TS_SCAN_Y;
44                 scpdr &= ~SCPDR_TS_SCAN_X;
45                 ctrl_outb(scpdr, SCPDR);
46                 udelay(30);
47
48                 absx = adc_single(ADC_CHANNEL_TS_X);
49
50                 scpdr = ctrl_inb(SCPDR);
51                 scpdr |= SCPDR_TS_SCAN_X;
52                 scpdr &= ~SCPDR_TS_SCAN_ENABLE;
53                 ctrl_outb(scpdr, SCPDR);
54                 udelay(100);
55                 touched = ctrl_inb(PHDR) & PHDR_TS_PEN_DOWN;
56         }
57
58         if (touched) {
59                 input_report_key(hp680_ts_dev, BTN_TOUCH, 1);
60                 input_report_abs(hp680_ts_dev, ABS_X, absx);
61                 input_report_abs(hp680_ts_dev, ABS_Y, absy);
62         } else {
63                 input_report_key(hp680_ts_dev, BTN_TOUCH, 0);
64         }
65
66         input_sync(hp680_ts_dev);
67         enable_irq(HP680_TS_IRQ);
68 }
69
70 static irqreturn_t hp680_ts_interrupt(int irq, void *dev, struct pt_regs *regs)
71 {
72         disable_irq_nosync(irq);
73         schedule_delayed_work(&work, HZ / 20);
74
75         return IRQ_HANDLED;
76 }
77
78 static int __init hp680_ts_init(void)
79 {
80         u8 scpdr;
81         u16 scpcr;
82
83         scpdr = ctrl_inb(SCPDR);
84         scpdr |= SCPDR_TS_SCAN_X | SCPDR_TS_SCAN_Y;
85         scpdr &= ~SCPDR_TS_SCAN_ENABLE;
86         ctrl_outb(scpdr, SCPDR);
87
88         scpcr = ctrl_inw(SCPCR);
89         scpcr &= ~SCPCR_TS_MASK;
90         scpcr |= SCPCR_TS_ENABLE;
91         ctrl_outw(scpcr, SCPCR);
92
93         hp680_ts_dev = input_allocate_device();
94         if (!hp680_ts_dev)
95                 return -ENOMEM;
96
97         hp680_ts_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY);
98         hp680_ts_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
99         hp680_ts_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
100
101         hp680_ts_dev->absmin[ABS_X] = HP680_TS_ABS_X_MIN;
102         hp680_ts_dev->absmin[ABS_Y] = HP680_TS_ABS_Y_MIN;
103         hp680_ts_dev->absmax[ABS_X] = HP680_TS_ABS_X_MAX;
104         hp680_ts_dev->absmax[ABS_Y] = HP680_TS_ABS_Y_MAX;
105
106         hp680_ts_dev->name = "HP Jornada touchscreen";
107         hp680_ts_dev->phys = "hp680_ts/input0";
108
109         input_register_device(hp680_ts_dev);
110
111         if (request_irq(HP680_TS_IRQ, hp680_ts_interrupt,
112                         SA_INTERRUPT, MODNAME, 0) < 0) {
113                 printk(KERN_ERR "hp680_touchscreen.c: Can't allocate irq %d\n",
114                        HP680_TS_IRQ);
115                 input_unregister_device(hp680_ts_dev);
116                 return -EBUSY;
117         }
118
119         return 0;
120 }
121
122 static void __exit hp680_ts_exit(void)
123 {
124         free_irq(HP680_TS_IRQ, 0);
125         cancel_delayed_work(&work);
126         flush_scheduled_work();
127         input_unregister_device(hp680_ts_dev);
128 }
129
130 module_init(hp680_ts_init);
131 module_exit(hp680_ts_exit);
132
133 MODULE_AUTHOR("Andriy Skulysh, askulysh@image.kiev.ua");
134 MODULE_DESCRIPTION("HP Jornada 680 touchscreen driver");
135 MODULE_LICENSE("GPL");