blob: 62af48bbcc27b84b87e84fd3bd5e2524e5a0c5f5 [file] [log] [blame]
Kristoffer Ericson5637f022007-09-26 00:02:56 -04001/*
2 * drivers/input/touchscreen/jornada720_ts.c
3 *
4 * Copyright (C) 2007 Kristoffer Ericson <Kristoffer.Ericson@gmail.com>
5 *
6 * Copyright (C) 2006 Filip Zyzniewski <filip.zyzniewski@tefnet.pl>
7 * based on HP Jornada 56x touchscreen driver by Alex Lange <chicken@handhelds.org>
8 *
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.
12 *
13 * HP Jornada 710/720/729 Touchscreen Driver
14 */
15
16#include <linux/platform_device.h>
Kristoffer Ericson5637f022007-09-26 00:02:56 -040017#include <linux/input.h>
18#include <linux/interrupt.h>
19#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090020#include <linux/slab.h>
Russell King31696632012-06-06 11:42:36 +010021#include <linux/io.h>
Kristoffer Ericson5637f022007-09-26 00:02:56 -040022
Russell Kinga09e64f2008-08-05 16:14:15 +010023#include <mach/hardware.h>
24#include <mach/jornada720.h>
Rob Herring3638dd22012-02-23 14:28:36 +010025#include <mach/irqs.h>
Kristoffer Ericson5637f022007-09-26 00:02:56 -040026
27MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
28MODULE_DESCRIPTION("HP Jornada 710/720/728 touchscreen driver");
Al Viro839cd312008-05-21 06:32:11 +010029MODULE_LICENSE("GPL v2");
Kristoffer Ericson5637f022007-09-26 00:02:56 -040030
31struct jornada_ts {
32 struct input_dev *dev;
33 int x_data[4]; /* X sample values */
34 int y_data[4]; /* Y sample values */
35};
36
37static void jornada720_ts_collect_data(struct jornada_ts *jornada_ts)
38{
39
40 /* 3 low word X samples */
41 jornada_ts->x_data[0] = jornada_ssp_byte(TXDUMMY);
42 jornada_ts->x_data[1] = jornada_ssp_byte(TXDUMMY);
43 jornada_ts->x_data[2] = jornada_ssp_byte(TXDUMMY);
44
45 /* 3 low word Y samples */
46 jornada_ts->y_data[0] = jornada_ssp_byte(TXDUMMY);
47 jornada_ts->y_data[1] = jornada_ssp_byte(TXDUMMY);
48 jornada_ts->y_data[2] = jornada_ssp_byte(TXDUMMY);
49
50 /* combined x samples bits */
51 jornada_ts->x_data[3] = jornada_ssp_byte(TXDUMMY);
52
53 /* combined y samples bits */
54 jornada_ts->y_data[3] = jornada_ssp_byte(TXDUMMY);
55}
56
57static int jornada720_ts_average(int coords[4])
58{
59 int coord, high_bits = coords[3];
60
61 coord = coords[0] | ((high_bits & 0x03) << 8);
62 coord += coords[1] | ((high_bits & 0x0c) << 6);
63 coord += coords[2] | ((high_bits & 0x30) << 4);
64
65 return coord / 3;
66}
67
68static irqreturn_t jornada720_ts_interrupt(int irq, void *dev_id)
69{
70 struct platform_device *pdev = dev_id;
71 struct jornada_ts *jornada_ts = platform_get_drvdata(pdev);
72 struct input_dev *input = jornada_ts->dev;
73 int x, y;
74
75 /* If GPIO_GPIO9 is set to high then report pen up */
76 if (GPLR & GPIO_GPIO(9)) {
77 input_report_key(input, BTN_TOUCH, 0);
78 input_sync(input);
79 } else {
80 jornada_ssp_start();
81
82 /* proper reply to request is always TXDUMMY */
83 if (jornada_ssp_inout(GETTOUCHSAMPLES) == TXDUMMY) {
84 jornada720_ts_collect_data(jornada_ts);
85
86 x = jornada720_ts_average(jornada_ts->x_data);
87 y = jornada720_ts_average(jornada_ts->y_data);
88
89 input_report_key(input, BTN_TOUCH, 1);
90 input_report_abs(input, ABS_X, x);
91 input_report_abs(input, ABS_Y, y);
92 input_sync(input);
93 }
94
95 jornada_ssp_end();
96 }
97
98 return IRQ_HANDLED;
99}
100
Bill Pemberton5298cc42012-11-23 21:38:25 -0800101static int jornada720_ts_probe(struct platform_device *pdev)
Kristoffer Ericson5637f022007-09-26 00:02:56 -0400102{
103 struct jornada_ts *jornada_ts;
104 struct input_dev *input_dev;
105 int error;
106
Pramod Gurav4b080e32014-07-30 22:13:58 -0700107 jornada_ts = devm_kzalloc(&pdev->dev, sizeof(*jornada_ts), GFP_KERNEL);
108 if (!jornada_ts)
109 return -ENOMEM;
Kristoffer Ericson5637f022007-09-26 00:02:56 -0400110
Pramod Gurav4b080e32014-07-30 22:13:58 -0700111 input_dev = devm_input_allocate_device(&pdev->dev);
112 if (!input_dev)
113 return -ENOMEM;
Kristoffer Ericson5637f022007-09-26 00:02:56 -0400114
115 platform_set_drvdata(pdev, jornada_ts);
116
117 jornada_ts->dev = input_dev;
118
119 input_dev->name = "HP Jornada 7xx Touchscreen";
120 input_dev->phys = "jornadats/input0";
121 input_dev->id.bustype = BUS_HOST;
122 input_dev->dev.parent = &pdev->dev;
123
Kristoffer Ericson1577e4b2008-09-16 14:19:25 -0400124 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
125 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
Kristoffer Ericson5637f022007-09-26 00:02:56 -0400126 input_set_abs_params(input_dev, ABS_X, 270, 3900, 0, 0);
127 input_set_abs_params(input_dev, ABS_Y, 180, 3700, 0, 0);
128
Pramod Gurav4b080e32014-07-30 22:13:58 -0700129 error = devm_request_irq(&pdev->dev, IRQ_GPIO9,
130 jornada720_ts_interrupt,
131 IRQF_TRIGGER_RISING,
132 "HP7XX Touchscreen driver", pdev);
Kristoffer Ericson5637f022007-09-26 00:02:56 -0400133 if (error) {
Pramod Gurav4b080e32014-07-30 22:13:58 -0700134 dev_err(&pdev->dev, "HP7XX TS : Unable to acquire irq!\n");
135 return error;
Kristoffer Ericson5637f022007-09-26 00:02:56 -0400136 }
137
138 error = input_register_device(jornada_ts->dev);
139 if (error)
Pramod Gurav4b080e32014-07-30 22:13:58 -0700140 return error;
Kristoffer Ericson5637f022007-09-26 00:02:56 -0400141
142 return 0;
143}
144
Kay Sieversd7b52472008-04-18 00:24:42 -0400145/* work with hotplug and coldplug */
146MODULE_ALIAS("platform:jornada_ts");
147
Kristoffer Ericson5637f022007-09-26 00:02:56 -0400148static struct platform_driver jornada720_ts_driver = {
149 .probe = jornada720_ts_probe,
Kristoffer Ericson5637f022007-09-26 00:02:56 -0400150 .driver = {
151 .name = "jornada_ts",
Kay Sieversd7b52472008-04-18 00:24:42 -0400152 .owner = THIS_MODULE,
Kristoffer Ericson5637f022007-09-26 00:02:56 -0400153 },
154};
JJ Dingcdcc96e2011-11-29 11:14:13 -0800155module_platform_driver(jornada720_ts_driver);