2 * drivers/input/touchscreen/jornada720_ts.c
4 * Copyright (C) 2007 Kristoffer Ericson <Kristoffer.Ericson@gmail.com>
6 * Copyright (C) 2006 Filip Zyzniewski <filip.zyzniewski@tefnet.pl>
7 * based on HP Jornada 56x touchscreen driver by Alex Lange <chicken@handhelds.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * HP Jornada 710/720/729 Touchscreen Driver
16 #include <linux/platform_device.h>
17 #include <linux/init.h>
18 #include <linux/input.h>
19 #include <linux/interrupt.h>
20 #include <linux/module.h>
22 #include <asm/hardware.h>
23 #include <asm/arch/jornada720.h>
25 MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
26 MODULE_DESCRIPTION("HP Jornada 710/720/728 touchscreen driver");
27 MODULE_LICENSE("GPL v2");
30 struct input_dev *dev;
31 int x_data[4]; /* X sample values */
32 int y_data[4]; /* Y sample values */
35 static void jornada720_ts_collect_data(struct jornada_ts *jornada_ts)
38 /* 3 low word X samples */
39 jornada_ts->x_data[0] = jornada_ssp_byte(TXDUMMY);
40 jornada_ts->x_data[1] = jornada_ssp_byte(TXDUMMY);
41 jornada_ts->x_data[2] = jornada_ssp_byte(TXDUMMY);
43 /* 3 low word Y samples */
44 jornada_ts->y_data[0] = jornada_ssp_byte(TXDUMMY);
45 jornada_ts->y_data[1] = jornada_ssp_byte(TXDUMMY);
46 jornada_ts->y_data[2] = jornada_ssp_byte(TXDUMMY);
48 /* combined x samples bits */
49 jornada_ts->x_data[3] = jornada_ssp_byte(TXDUMMY);
51 /* combined y samples bits */
52 jornada_ts->y_data[3] = jornada_ssp_byte(TXDUMMY);
55 static int jornada720_ts_average(int coords[4])
57 int coord, high_bits = coords[3];
59 coord = coords[0] | ((high_bits & 0x03) << 8);
60 coord += coords[1] | ((high_bits & 0x0c) << 6);
61 coord += coords[2] | ((high_bits & 0x30) << 4);
66 static irqreturn_t jornada720_ts_interrupt(int irq, void *dev_id)
68 struct platform_device *pdev = dev_id;
69 struct jornada_ts *jornada_ts = platform_get_drvdata(pdev);
70 struct input_dev *input = jornada_ts->dev;
73 /* If GPIO_GPIO9 is set to high then report pen up */
74 if (GPLR & GPIO_GPIO(9)) {
75 input_report_key(input, BTN_TOUCH, 0);
80 /* proper reply to request is always TXDUMMY */
81 if (jornada_ssp_inout(GETTOUCHSAMPLES) == TXDUMMY) {
82 jornada720_ts_collect_data(jornada_ts);
84 x = jornada720_ts_average(jornada_ts->x_data);
85 y = jornada720_ts_average(jornada_ts->y_data);
87 input_report_key(input, BTN_TOUCH, 1);
88 input_report_abs(input, ABS_X, x);
89 input_report_abs(input, ABS_Y, y);
99 static int __devinit jornada720_ts_probe(struct platform_device *pdev)
101 struct jornada_ts *jornada_ts;
102 struct input_dev *input_dev;
105 jornada_ts = kzalloc(sizeof(struct jornada_ts), GFP_KERNEL);
106 input_dev = input_allocate_device();
108 if (!jornada_ts || !input_dev) {
113 platform_set_drvdata(pdev, jornada_ts);
115 jornada_ts->dev = input_dev;
117 input_dev->name = "HP Jornada 7xx Touchscreen";
118 input_dev->phys = "jornadats/input0";
119 input_dev->id.bustype = BUS_HOST;
120 input_dev->dev.parent = &pdev->dev;
122 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
123 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
124 input_set_abs_params(input_dev, ABS_X, 270, 3900, 0, 0);
125 input_set_abs_params(input_dev, ABS_Y, 180, 3700, 0, 0);
127 error = request_irq(IRQ_GPIO9,
128 jornada720_ts_interrupt,
129 IRQF_DISABLED | IRQF_TRIGGER_RISING,
130 "HP7XX Touchscreen driver", pdev);
132 printk(KERN_INFO "HP7XX TS : Unable to acquire irq!\n");
136 error = input_register_device(jornada_ts->dev);
143 free_irq(IRQ_GPIO9, pdev);
145 platform_set_drvdata(pdev, NULL);
146 input_free_device(input_dev);
151 static int __devexit jornada720_ts_remove(struct platform_device *pdev)
153 struct jornada_ts *jornada_ts = platform_get_drvdata(pdev);
155 free_irq(IRQ_GPIO9, pdev);
156 platform_set_drvdata(pdev, NULL);
157 input_unregister_device(jornada_ts->dev);
163 /* work with hotplug and coldplug */
164 MODULE_ALIAS("platform:jornada_ts");
166 static struct platform_driver jornada720_ts_driver = {
167 .probe = jornada720_ts_probe,
168 .remove = __devexit_p(jornada720_ts_remove),
170 .name = "jornada_ts",
171 .owner = THIS_MODULE,
175 static int __init jornada720_ts_init(void)
177 return platform_driver_register(&jornada720_ts_driver);
180 static void __exit jornada720_ts_exit(void)
182 platform_driver_unregister(&jornada720_ts_driver);
185 module_init(jornada720_ts_init);
186 module_exit(jornada720_ts_exit);