1 #include <linux/input.h>
2 #include <linux/module.h>
3 #include <linux/init.h>
5 #include <linux/interrupt.h>
9 #include <asm/hp6xx/hp6xx.h>
11 #define MODNAME "hp680_ts_input"
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
18 #define SCPCR 0xa4000116
19 #define PHDR 0xa400012e
20 #define SCPDR 0xa4000136
22 static void do_softint(void *data
);
24 static struct input_dev
*hp680_ts_dev
;
25 static DECLARE_WORK(work
, do_softint
, 0);
27 static void do_softint(void *data
)
29 int absx
= 0, absy
= 0;
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
);
40 absy
= adc_single(ADC_CHANNEL_TS_Y
);
42 scpdr
= ctrl_inb(SCPDR
);
43 scpdr
|= SCPDR_TS_SCAN_Y
;
44 scpdr
&= ~SCPDR_TS_SCAN_X
;
45 ctrl_outb(scpdr
, SCPDR
);
48 absx
= adc_single(ADC_CHANNEL_TS_X
);
50 scpdr
= ctrl_inb(SCPDR
);
51 scpdr
|= SCPDR_TS_SCAN_X
;
52 scpdr
&= ~SCPDR_TS_SCAN_ENABLE
;
53 ctrl_outb(scpdr
, SCPDR
);
55 touched
= ctrl_inb(PHDR
) & PHDR_TS_PEN_DOWN
;
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
);
63 input_report_key(hp680_ts_dev
, BTN_TOUCH
, 0);
66 input_sync(hp680_ts_dev
);
67 enable_irq(HP680_TS_IRQ
);
70 static irqreturn_t
hp680_ts_interrupt(int irq
, void *dev
, struct pt_regs
*regs
)
72 disable_irq_nosync(irq
);
73 schedule_delayed_work(&work
, HZ
/ 20);
78 static int __init
hp680_ts_init(void)
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
);
88 scpcr
= ctrl_inw(SCPCR
);
89 scpcr
&= ~SCPCR_TS_MASK
;
90 scpcr
|= SCPCR_TS_ENABLE
;
91 ctrl_outw(scpcr
, SCPCR
);
93 hp680_ts_dev
= input_allocate_device();
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
);
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
;
106 hp680_ts_dev
->name
= "HP Jornada touchscreen";
107 hp680_ts_dev
->phys
= "hp680_ts/input0";
109 input_register_device(hp680_ts_dev
);
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",
115 input_unregister_device(hp680_ts_dev
);
122 static void __exit
hp680_ts_exit(void)
124 free_irq(HP680_TS_IRQ
, 0);
125 cancel_delayed_work(&work
);
126 flush_scheduled_work();
127 input_unregister_device(hp680_ts_dev
);
130 module_init(hp680_ts_init
);
131 module_exit(hp680_ts_exit
);
133 MODULE_AUTHOR("Andriy Skulysh, askulysh@image.kiev.ua");
134 MODULE_DESCRIPTION("HP Jornada 680 touchscreen driver");
135 MODULE_LICENSE("GPL");