Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #define PHDR 0xa400012e |
| 19 | #define SCPDR 0xa4000136 |
| 20 | |
| 21 | static void do_softint(void *data); |
| 22 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 23 | static struct input_dev *hp680_ts_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | static DECLARE_WORK(work, do_softint, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | static void do_softint(void *data) |
| 27 | { |
| 28 | int absx = 0, absy = 0; |
| 29 | u8 scpdr; |
| 30 | int touched = 0; |
| 31 | |
| 32 | if (ctrl_inb(PHDR) & PHDR_TS_PEN_DOWN) { |
| 33 | scpdr = ctrl_inb(SCPDR); |
| 34 | scpdr |= SCPDR_TS_SCAN_ENABLE; |
| 35 | scpdr &= ~SCPDR_TS_SCAN_Y; |
| 36 | ctrl_outb(scpdr, SCPDR); |
| 37 | udelay(30); |
| 38 | |
| 39 | absy = adc_single(ADC_CHANNEL_TS_Y); |
| 40 | |
| 41 | scpdr = ctrl_inb(SCPDR); |
| 42 | scpdr |= SCPDR_TS_SCAN_Y; |
| 43 | scpdr &= ~SCPDR_TS_SCAN_X; |
| 44 | ctrl_outb(scpdr, SCPDR); |
| 45 | udelay(30); |
| 46 | |
| 47 | absx = adc_single(ADC_CHANNEL_TS_X); |
| 48 | |
| 49 | scpdr = ctrl_inb(SCPDR); |
| 50 | scpdr |= SCPDR_TS_SCAN_X; |
| 51 | scpdr &= ~SCPDR_TS_SCAN_ENABLE; |
| 52 | ctrl_outb(scpdr, SCPDR); |
| 53 | udelay(100); |
| 54 | touched = ctrl_inb(PHDR) & PHDR_TS_PEN_DOWN; |
| 55 | } |
| 56 | |
| 57 | if (touched) { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 58 | input_report_key(hp680_ts_dev, BTN_TOUCH, 1); |
| 59 | input_report_abs(hp680_ts_dev, ABS_X, absx); |
| 60 | input_report_abs(hp680_ts_dev, ABS_Y, absy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } else { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 62 | input_report_key(hp680_ts_dev, BTN_TOUCH, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 65 | input_sync(hp680_ts_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | enable_irq(HP680_TS_IRQ); |
| 67 | } |
| 68 | |
| 69 | static irqreturn_t hp680_ts_interrupt(int irq, void *dev, struct pt_regs *regs) |
| 70 | { |
| 71 | disable_irq_nosync(irq); |
| 72 | schedule_delayed_work(&work, HZ / 20); |
| 73 | |
| 74 | return IRQ_HANDLED; |
| 75 | } |
| 76 | |
| 77 | static int __init hp680_ts_init(void) |
| 78 | { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 79 | hp680_ts_dev = input_allocate_device(); |
| 80 | if (!hp680_ts_dev) |
| 81 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 83 | hp680_ts_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY); |
| 84 | hp680_ts_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y); |
| 85 | hp680_ts_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 87 | hp680_ts_dev->absmin[ABS_X] = HP680_TS_ABS_X_MIN; |
| 88 | hp680_ts_dev->absmin[ABS_Y] = HP680_TS_ABS_Y_MIN; |
| 89 | hp680_ts_dev->absmax[ABS_X] = HP680_TS_ABS_X_MAX; |
| 90 | hp680_ts_dev->absmax[ABS_Y] = HP680_TS_ABS_Y_MAX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 92 | hp680_ts_dev->name = "HP Jornada touchscreen"; |
| 93 | hp680_ts_dev->phys = "hp680_ts/input0"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 95 | input_register_device(hp680_ts_dev); |
| 96 | |
| 97 | if (request_irq(HP680_TS_IRQ, hp680_ts_interrupt, |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 98 | IRQF_DISABLED, MODNAME, 0) < 0) { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 99 | printk(KERN_ERR "hp680_touchscreen.c: Can't allocate irq %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | HP680_TS_IRQ); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 101 | input_unregister_device(hp680_ts_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | return -EBUSY; |
| 103 | } |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static void __exit hp680_ts_exit(void) |
| 109 | { |
| 110 | free_irq(HP680_TS_IRQ, 0); |
| 111 | cancel_delayed_work(&work); |
| 112 | flush_scheduled_work(); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 113 | input_unregister_device(hp680_ts_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | module_init(hp680_ts_init); |
| 117 | module_exit(hp680_ts_exit); |
| 118 | |
| 119 | MODULE_AUTHOR("Andriy Skulysh, askulysh@image.kiev.ua"); |
| 120 | MODULE_DESCRIPTION("HP Jornada 680 touchscreen driver"); |
| 121 | MODULE_LICENSE("GPL"); |