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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/interrupt.h> |
| 5 | #include <asm/io.h> |
| 6 | #include <asm/delay.h> |
| 7 | #include <asm/adc.h> |
Paul Mundt | 082c44d | 2006-10-19 16:16:18 +0900 | [diff] [blame] | 8 | #include <asm/hp6xx.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #define PHDR 0xa400012e |
| 18 | #define SCPDR 0xa4000136 |
| 19 | |
Kristoffer Ericson | 049fa57 | 2007-05-12 20:28:05 +0900 | [diff] [blame] | 20 | static void do_softint(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 22 | static struct input_dev *hp680_ts_dev; |
Kristoffer Ericson | 049fa57 | 2007-05-12 20:28:05 +0900 | [diff] [blame] | 23 | static DECLARE_DELAYED_WORK(work, do_softint); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Kristoffer Ericson | 049fa57 | 2007-05-12 20:28:05 +0900 | [diff] [blame] | 25 | static void do_softint(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | { |
| 27 | int absx = 0, absy = 0; |
| 28 | u8 scpdr; |
| 29 | int touched = 0; |
| 30 | |
| 31 | if (ctrl_inb(PHDR) & PHDR_TS_PEN_DOWN) { |
| 32 | scpdr = ctrl_inb(SCPDR); |
| 33 | scpdr |= SCPDR_TS_SCAN_ENABLE; |
| 34 | scpdr &= ~SCPDR_TS_SCAN_Y; |
| 35 | ctrl_outb(scpdr, SCPDR); |
| 36 | udelay(30); |
| 37 | |
| 38 | absy = adc_single(ADC_CHANNEL_TS_Y); |
| 39 | |
| 40 | scpdr = ctrl_inb(SCPDR); |
| 41 | scpdr |= SCPDR_TS_SCAN_Y; |
| 42 | scpdr &= ~SCPDR_TS_SCAN_X; |
| 43 | ctrl_outb(scpdr, SCPDR); |
| 44 | udelay(30); |
| 45 | |
| 46 | absx = adc_single(ADC_CHANNEL_TS_X); |
| 47 | |
| 48 | scpdr = ctrl_inb(SCPDR); |
| 49 | scpdr |= SCPDR_TS_SCAN_X; |
| 50 | scpdr &= ~SCPDR_TS_SCAN_ENABLE; |
| 51 | ctrl_outb(scpdr, SCPDR); |
| 52 | udelay(100); |
| 53 | touched = ctrl_inb(PHDR) & PHDR_TS_PEN_DOWN; |
| 54 | } |
| 55 | |
| 56 | if (touched) { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 57 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } else { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 61 | input_report_key(hp680_ts_dev, BTN_TOUCH, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 64 | input_sync(hp680_ts_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | enable_irq(HP680_TS_IRQ); |
| 66 | } |
| 67 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 68 | static irqreturn_t hp680_ts_interrupt(int irq, void *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
| 70 | disable_irq_nosync(irq); |
| 71 | schedule_delayed_work(&work, HZ / 20); |
| 72 | |
| 73 | return IRQ_HANDLED; |
| 74 | } |
| 75 | |
| 76 | static int __init hp680_ts_init(void) |
| 77 | { |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 78 | int err; |
| 79 | |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 80 | hp680_ts_dev = input_allocate_device(); |
| 81 | if (!hp680_ts_dev) |
| 82 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 84 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 87 | 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 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 | if (request_irq(HP680_TS_IRQ, hp680_ts_interrupt, |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 96 | IRQF_DISABLED, MODNAME, 0) < 0) { |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 97 | printk(KERN_ERR "hp680_touchscreen.c: Can't allocate irq %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | HP680_TS_IRQ); |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 99 | err = -EBUSY; |
| 100 | goto fail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 103 | err = input_register_device(hp680_ts_dev); |
| 104 | if (err) |
| 105 | goto fail2; |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | return 0; |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 108 | |
| 109 | fail2: free_irq(HP680_TS_IRQ, NULL); |
| 110 | cancel_delayed_work(&work); |
| 111 | flush_scheduled_work(); |
| 112 | fail1: input_free_device(hp680_ts_dev); |
| 113 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | static void __exit hp680_ts_exit(void) |
| 117 | { |
Dmitry Torokhov | 52c1f57 | 2006-11-05 22:40:03 -0500 | [diff] [blame] | 118 | free_irq(HP680_TS_IRQ, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | cancel_delayed_work(&work); |
| 120 | flush_scheduled_work(); |
Dmitry Torokhov | eca1ed1 | 2005-09-15 02:01:46 -0500 | [diff] [blame] | 121 | input_unregister_device(hp680_ts_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | module_init(hp680_ts_init); |
| 125 | module_exit(hp680_ts_exit); |
| 126 | |
| 127 | MODULE_AUTHOR("Andriy Skulysh, askulysh@image.kiev.ua"); |
| 128 | MODULE_DESCRIPTION("HP Jornada 680 touchscreen driver"); |
| 129 | MODULE_LICENSE("GPL"); |