2 * Touch Screen driver for Renesas MIGO-R Platform
4 * Copyright (c) 2008 Magnus Damm
5 * Copyright (c) 2007 Ujjwal Pande <ujjwal@kenati.com>,
6 * Kenati Technologies Pvt Ltd.
8 * This file is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This file is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/input.h>
25 #include <linux/interrupt.h>
27 #include <linux/slab.h>
29 #include <linux/i2c.h>
30 #include <linux/timer.h>
32 #define EVENT_PENDOWN 1
33 #define EVENT_REPEAT 2
36 struct migor_ts_priv {
37 struct i2c_client *client;
38 struct input_dev *input;
42 static const u_int8_t migor_ts_ena_seq[17] = { 0x33, 0x22, 0x11,
44 static const u_int8_t migor_ts_dis_seq[17] = { };
46 static irqreturn_t migor_ts_isr(int irq, void *dev_id)
48 struct migor_ts_priv *priv = dev_id;
49 unsigned short xpos, ypos;
54 * The touch screen controller chip is hooked up to the CPU
55 * using I2C and a single interrupt line. The interrupt line
56 * is pulled low whenever someone taps the screen. To deassert
57 * the interrupt line we need to acknowledge the interrupt by
58 * communicating with the controller over the slow i2c bus.
60 * Since I2C bus controller may sleep we are using threaded
64 memset(buf, 0, sizeof(buf));
68 if (i2c_master_send(priv->client, buf, 1) != 1) {
69 dev_err(&priv->client->dev, "Unable to write i2c index\n");
73 /* Now do Page Read */
74 if (i2c_master_recv(priv->client, buf, sizeof(buf)) != sizeof(buf)) {
75 dev_err(&priv->client->dev, "Unable to read i2c page\n");
79 ypos = ((buf[9] & 0x03) << 8 | buf[8]);
80 xpos = ((buf[11] & 0x03) << 8 | buf[10]);
86 input_report_key(priv->input, BTN_TOUCH, 1);
87 input_report_abs(priv->input, ABS_X, ypos); /*X-Y swap*/
88 input_report_abs(priv->input, ABS_Y, xpos);
89 input_sync(priv->input);
93 input_report_key(priv->input, BTN_TOUCH, 0);
94 input_sync(priv->input);
102 static int migor_ts_open(struct input_dev *dev)
104 struct migor_ts_priv *priv = input_get_drvdata(dev);
105 struct i2c_client *client = priv->client;
108 /* enable controller */
109 count = i2c_master_send(client, migor_ts_ena_seq,
110 sizeof(migor_ts_ena_seq));
111 if (count != sizeof(migor_ts_ena_seq)) {
112 dev_err(&client->dev, "Unable to enable touchscreen.\n");
119 static void migor_ts_close(struct input_dev *dev)
121 struct migor_ts_priv *priv = input_get_drvdata(dev);
122 struct i2c_client *client = priv->client;
124 disable_irq(priv->irq);
126 /* disable controller */
127 i2c_master_send(client, migor_ts_dis_seq, sizeof(migor_ts_dis_seq));
129 enable_irq(priv->irq);
132 static int migor_ts_probe(struct i2c_client *client,
133 const struct i2c_device_id *idp)
135 struct migor_ts_priv *priv;
136 struct input_dev *input;
139 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
140 input = input_allocate_device();
141 if (!priv || !input) {
142 dev_err(&client->dev, "failed to allocate memory\n");
147 priv->client = client;
149 priv->irq = client->irq;
151 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
153 __set_bit(BTN_TOUCH, input->keybit);
155 input_set_abs_params(input, ABS_X, 95, 955, 0, 0);
156 input_set_abs_params(input, ABS_Y, 85, 935, 0, 0);
158 input->name = client->name;
159 input->id.bustype = BUS_I2C;
160 input->dev.parent = &client->dev;
162 input->open = migor_ts_open;
163 input->close = migor_ts_close;
165 input_set_drvdata(input, priv);
167 error = request_threaded_irq(priv->irq, NULL, migor_ts_isr,
168 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
171 dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
175 error = input_register_device(input);
179 i2c_set_clientdata(client, priv);
180 device_init_wakeup(&client->dev, 1);
185 free_irq(priv->irq, priv);
187 input_free_device(input);
192 static int migor_ts_remove(struct i2c_client *client)
194 struct migor_ts_priv *priv = i2c_get_clientdata(client);
196 free_irq(priv->irq, priv);
197 input_unregister_device(priv->input);
200 dev_set_drvdata(&client->dev, NULL);
205 static int migor_ts_suspend(struct device *dev)
207 struct i2c_client *client = to_i2c_client(dev);
208 struct migor_ts_priv *priv = i2c_get_clientdata(client);
210 if (device_may_wakeup(&client->dev))
211 enable_irq_wake(priv->irq);
216 static int migor_ts_resume(struct device *dev)
218 struct i2c_client *client = to_i2c_client(dev);
219 struct migor_ts_priv *priv = i2c_get_clientdata(client);
221 if (device_may_wakeup(&client->dev))
222 disable_irq_wake(priv->irq);
227 static SIMPLE_DEV_PM_OPS(migor_ts_pm, migor_ts_suspend, migor_ts_resume);
229 static const struct i2c_device_id migor_ts_id[] = {
233 MODULE_DEVICE_TABLE(i2c, migor_ts);
235 static struct i2c_driver migor_ts_driver = {
240 .probe = migor_ts_probe,
241 .remove = migor_ts_remove,
242 .id_table = migor_ts_id,
245 module_i2c_driver(migor_ts_driver);
247 MODULE_DESCRIPTION("MigoR Touchscreen driver");
248 MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
249 MODULE_LICENSE("GPL");