blob: 85cf9bee80183bc117475cc562af0fac459b2473 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/input.h>
2#include <linux/module.h>
3#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <linux/interrupt.h>
5#include <asm/io.h>
6#include <asm/delay.h>
7#include <asm/adc.h>
Paul Mundt7639a452008-10-20 13:02:48 +09008#include <mach/hp6xx.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#define MODNAME "hp680_ts_input"
11
12#define HP680_TS_ABS_X_MIN 40
13#define HP680_TS_ABS_X_MAX 950
14#define HP680_TS_ABS_Y_MIN 80
15#define HP680_TS_ABS_Y_MAX 910
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#define PHDR 0xa400012e
18#define SCPDR 0xa4000136
19
Kristoffer Ericson049fa572007-05-12 20:28:05 +090020static void do_softint(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050022static struct input_dev *hp680_ts_dev;
Kristoffer Ericson049fa572007-05-12 20:28:05 +090023static DECLARE_DELAYED_WORK(work, do_softint);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Kristoffer Ericson049fa572007-05-12 20:28:05 +090025static void do_softint(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
27 int absx = 0, absy = 0;
28 u8 scpdr;
29 int touched = 0;
30
Paul Mundte28abaf2010-10-27 15:25:42 +090031 if (__raw_readb(PHDR) & PHDR_TS_PEN_DOWN) {
32 scpdr = __raw_readb(SCPDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 scpdr |= SCPDR_TS_SCAN_ENABLE;
34 scpdr &= ~SCPDR_TS_SCAN_Y;
Paul Mundte28abaf2010-10-27 15:25:42 +090035 __raw_writeb(scpdr, SCPDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 udelay(30);
37
38 absy = adc_single(ADC_CHANNEL_TS_Y);
39
Paul Mundte28abaf2010-10-27 15:25:42 +090040 scpdr = __raw_readb(SCPDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 scpdr |= SCPDR_TS_SCAN_Y;
42 scpdr &= ~SCPDR_TS_SCAN_X;
Paul Mundte28abaf2010-10-27 15:25:42 +090043 __raw_writeb(scpdr, SCPDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 udelay(30);
45
46 absx = adc_single(ADC_CHANNEL_TS_X);
47
Paul Mundte28abaf2010-10-27 15:25:42 +090048 scpdr = __raw_readb(SCPDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 scpdr |= SCPDR_TS_SCAN_X;
50 scpdr &= ~SCPDR_TS_SCAN_ENABLE;
Paul Mundte28abaf2010-10-27 15:25:42 +090051 __raw_writeb(scpdr, SCPDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 udelay(100);
Paul Mundte28abaf2010-10-27 15:25:42 +090053 touched = __raw_readb(PHDR) & PHDR_TS_PEN_DOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 }
55
56 if (touched) {
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050057 input_report_key(hp680_ts_dev, BTN_TOUCH, 1);
58 input_report_abs(hp680_ts_dev, ABS_X, absx);
59 input_report_abs(hp680_ts_dev, ABS_Y, absy);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 } else {
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050061 input_report_key(hp680_ts_dev, BTN_TOUCH, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 }
63
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050064 input_sync(hp680_ts_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 enable_irq(HP680_TS_IRQ);
66}
67
David Howells7d12e782006-10-05 14:55:46 +010068static irqreturn_t hp680_ts_interrupt(int irq, void *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
70 disable_irq_nosync(irq);
71 schedule_delayed_work(&work, HZ / 20);
72
73 return IRQ_HANDLED;
74}
75
76static int __init hp680_ts_init(void)
77{
Dmitry Torokhov52c1f572006-11-05 22:40:03 -050078 int err;
79
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050080 hp680_ts_dev = input_allocate_device();
81 if (!hp680_ts_dev)
82 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Jiri Slaby7b19ada2007-10-18 23:40:32 -070084 hp680_ts_dev->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY);
85 hp680_ts_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Dmitry Torokhov52c1f572006-11-05 22:40:03 -050087 input_set_abs_params(hp680_ts_dev, ABS_X,
88 HP680_TS_ABS_X_MIN, HP680_TS_ABS_X_MAX, 0, 0);
89 input_set_abs_params(hp680_ts_dev, ABS_Y,
90 HP680_TS_ABS_Y_MIN, HP680_TS_ABS_Y_MAX, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050092 hp680_ts_dev->name = "HP Jornada touchscreen";
93 hp680_ts_dev->phys = "hp680_ts/input0";
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050095 if (request_irq(HP680_TS_IRQ, hp680_ts_interrupt,
Julia Lawallb51425b2012-03-11 16:06:03 -070096 0, MODNAME, NULL) < 0) {
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050097 printk(KERN_ERR "hp680_touchscreen.c: Can't allocate irq %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 HP680_TS_IRQ);
Dmitry Torokhov52c1f572006-11-05 22:40:03 -050099 err = -EBUSY;
100 goto fail1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 }
102
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500103 err = input_register_device(hp680_ts_dev);
104 if (err)
105 goto fail2;
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 return 0;
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500108
109 fail2: free_irq(HP680_TS_IRQ, NULL);
Tejun Heo790d5c82010-10-15 09:47:15 -0700110 cancel_delayed_work_sync(&work);
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500111 fail1: input_free_device(hp680_ts_dev);
112 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
114
115static void __exit hp680_ts_exit(void)
116{
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500117 free_irq(HP680_TS_IRQ, NULL);
Tejun Heo790d5c82010-10-15 09:47:15 -0700118 cancel_delayed_work_sync(&work);
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500119 input_unregister_device(hp680_ts_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120}
121
122module_init(hp680_ts_init);
123module_exit(hp680_ts_exit);
124
125MODULE_AUTHOR("Andriy Skulysh, askulysh@image.kiev.ua");
126MODULE_DESCRIPTION("HP Jornada 680 touchscreen driver");
127MODULE_LICENSE("GPL");