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/gpio/consumer.h>
17 #include <linux/platform_device.h>
18 #include <linux/input.h>
19 #include <linux/interrupt.h>
20 #include <linux/module.h>
21 #include <linux/slab.h>
24 #include <mach/jornada720.h>
26 MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
27 MODULE_DESCRIPTION("HP Jornada 710/720/728 touchscreen driver");
28 MODULE_LICENSE("GPL v2");
31 struct input_dev
*dev
;
32 struct gpio_desc
*gpio
;
33 int x_data
[4]; /* X sample values */
34 int y_data
[4]; /* Y sample values */
37 static void jornada720_ts_collect_data(struct jornada_ts
*jornada_ts
)
39 /* 3 low word X samples */
40 jornada_ts
->x_data
[0] = jornada_ssp_byte(TXDUMMY
);
41 jornada_ts
->x_data
[1] = jornada_ssp_byte(TXDUMMY
);
42 jornada_ts
->x_data
[2] = jornada_ssp_byte(TXDUMMY
);
44 /* 3 low word Y samples */
45 jornada_ts
->y_data
[0] = jornada_ssp_byte(TXDUMMY
);
46 jornada_ts
->y_data
[1] = jornada_ssp_byte(TXDUMMY
);
47 jornada_ts
->y_data
[2] = jornada_ssp_byte(TXDUMMY
);
49 /* combined x samples bits */
50 jornada_ts
->x_data
[3] = jornada_ssp_byte(TXDUMMY
);
52 /* combined y samples bits */
53 jornada_ts
->y_data
[3] = jornada_ssp_byte(TXDUMMY
);
56 static int jornada720_ts_average(int coords
[4])
58 int coord
, high_bits
= coords
[3];
60 coord
= coords
[0] | ((high_bits
& 0x03) << 8);
61 coord
+= coords
[1] | ((high_bits
& 0x0c) << 6);
62 coord
+= coords
[2] | ((high_bits
& 0x30) << 4);
67 static irqreturn_t
jornada720_ts_interrupt(int irq
, void *dev_id
)
69 struct platform_device
*pdev
= dev_id
;
70 struct jornada_ts
*jornada_ts
= platform_get_drvdata(pdev
);
71 struct input_dev
*input
= jornada_ts
->dev
;
74 /* If gpio is high then report pen up */
75 if (gpiod_get_value(jornada_ts
->gpio
)) {
76 input_report_key(input
, BTN_TOUCH
, 0);
81 /* proper reply to request is always TXDUMMY */
82 if (jornada_ssp_inout(GETTOUCHSAMPLES
) == TXDUMMY
) {
83 jornada720_ts_collect_data(jornada_ts
);
85 x
= jornada720_ts_average(jornada_ts
->x_data
);
86 y
= jornada720_ts_average(jornada_ts
->y_data
);
88 input_report_key(input
, BTN_TOUCH
, 1);
89 input_report_abs(input
, ABS_X
, x
);
90 input_report_abs(input
, ABS_Y
, y
);
100 static int jornada720_ts_probe(struct platform_device
*pdev
)
102 struct jornada_ts
*jornada_ts
;
103 struct input_dev
*input_dev
;
106 jornada_ts
= devm_kzalloc(&pdev
->dev
, sizeof(*jornada_ts
), GFP_KERNEL
);
110 input_dev
= devm_input_allocate_device(&pdev
->dev
);
114 platform_set_drvdata(pdev
, jornada_ts
);
116 jornada_ts
->gpio
= devm_gpiod_get(&pdev
->dev
, "penup", GPIOD_IN
);
117 if (IS_ERR(jornada_ts
->gpio
))
118 return PTR_ERR(jornada_ts
->gpio
);
120 irq
= gpiod_to_irq(jornada_ts
->gpio
);
122 return irq
< 0 ? irq
: -EINVAL
;
124 jornada_ts
->dev
= input_dev
;
126 input_dev
->name
= "HP Jornada 7xx Touchscreen";
127 input_dev
->phys
= "jornadats/input0";
128 input_dev
->id
.bustype
= BUS_HOST
;
129 input_dev
->dev
.parent
= &pdev
->dev
;
131 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
132 input_dev
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
133 input_set_abs_params(input_dev
, ABS_X
, 270, 3900, 0, 0);
134 input_set_abs_params(input_dev
, ABS_Y
, 180, 3700, 0, 0);
136 error
= devm_request_irq(&pdev
->dev
, irq
, jornada720_ts_interrupt
,
138 "HP7XX Touchscreen driver", pdev
);
140 dev_err(&pdev
->dev
, "HP7XX TS : Unable to acquire irq!\n");
144 error
= input_register_device(jornada_ts
->dev
);
151 /* work with hotplug and coldplug */
152 MODULE_ALIAS("platform:jornada_ts");
154 static struct platform_driver jornada720_ts_driver
= {
155 .probe
= jornada720_ts_probe
,
157 .name
= "jornada_ts",
160 module_platform_driver(jornada720_ts_driver
);