blob: 19732b573227d11a90833a1da663b7742f33388b [file] [log] [blame]
Jianchun Bian36a281e2011-12-30 15:16:21 -08001/*
2 * Driver for Pixcir I2C touchscreen controllers.
3 *
4 * Copyright (C) 2010-2011 Pixcir, Inc.
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/delay.h>
21#include <linux/module.h>
22#include <linux/interrupt.h>
23#include <linux/slab.h>
24#include <linux/i2c.h>
25#include <linux/input.h>
Roger Quadros62e65b72014-07-28 09:58:54 -070026#include <linux/input/mt.h>
Roger Quadros0dfc8d42014-05-18 22:46:43 -070027#include <linux/gpio.h>
Dmitry Torokhovcb4a5f02015-07-06 11:56:21 -070028#include <linux/gpio/consumer.h>
Roger Quadrosa4054592014-07-28 10:05:39 -070029#include <linux/of.h>
Roger Quadrosa4054592014-07-28 10:05:39 -070030#include <linux/of_device.h>
Dmitry Torokhov28a74c02015-07-06 11:48:47 -070031#include <linux/platform_data/pixcir_i2c_ts.h>
Jianchun Bian36a281e2011-12-30 15:16:21 -080032
Roger Quadros36874c72014-07-28 10:01:07 -070033#define PIXCIR_MAX_SLOTS 5 /* Max fingers supported by driver */
Roger Quadros62e65b72014-07-28 09:58:54 -070034
Jianchun Bian36a281e2011-12-30 15:16:21 -080035struct pixcir_i2c_ts_data {
36 struct i2c_client *client;
37 struct input_dev *input;
Dmitry Torokhovcb4a5f02015-07-06 11:56:21 -070038 struct gpio_desc *gpio_attb;
Roger Quadros36874c72014-07-28 10:01:07 -070039 const struct pixcir_ts_platform_data *pdata;
Roger Quadros3b36fbb2014-05-18 22:44:35 -070040 bool running;
Roger Quadros36874c72014-07-28 10:01:07 -070041 int max_fingers; /* Max fingers supported in this instance */
Jianchun Bian36a281e2011-12-30 15:16:21 -080042};
43
Roger Quadros62e65b72014-07-28 09:58:54 -070044struct pixcir_touch {
45 int x;
46 int y;
Roger Quadros36874c72014-07-28 10:01:07 -070047 int id;
Roger Quadros62e65b72014-07-28 09:58:54 -070048};
49
50struct pixcir_report_data {
51 int num_touches;
52 struct pixcir_touch touches[PIXCIR_MAX_SLOTS];
53};
54
55static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata,
56 struct pixcir_report_data *report)
Jianchun Bian36a281e2011-12-30 15:16:21 -080057{
Roger Quadros36874c72014-07-28 10:01:07 -070058 u8 rdbuf[2 + PIXCIR_MAX_SLOTS * 5];
59 u8 wrbuf[1] = { 0 };
Roger Quadros62e65b72014-07-28 09:58:54 -070060 u8 *bufptr;
Jianchun Bian36a281e2011-12-30 15:16:21 -080061 u8 touch;
Roger Quadros62e65b72014-07-28 09:58:54 -070062 int ret, i;
Roger Quadros36874c72014-07-28 10:01:07 -070063 int readsize;
64 const struct pixcir_i2c_chip_data *chip = &tsdata->pdata->chip;
Roger Quadros62e65b72014-07-28 09:58:54 -070065
66 memset(report, 0, sizeof(struct pixcir_report_data));
Jianchun Bian36a281e2011-12-30 15:16:21 -080067
Roger Quadros36874c72014-07-28 10:01:07 -070068 i = chip->has_hw_ids ? 1 : 0;
69 readsize = 2 + tsdata->max_fingers * (4 + i);
70 if (readsize > sizeof(rdbuf))
71 readsize = sizeof(rdbuf);
72
Jianchun Bian36a281e2011-12-30 15:16:21 -080073 ret = i2c_master_send(tsdata->client, wrbuf, sizeof(wrbuf));
74 if (ret != sizeof(wrbuf)) {
75 dev_err(&tsdata->client->dev,
76 "%s: i2c_master_send failed(), ret=%d\n",
77 __func__, ret);
78 return;
79 }
80
Roger Quadros36874c72014-07-28 10:01:07 -070081 ret = i2c_master_recv(tsdata->client, rdbuf, readsize);
Jianchun Bian36a281e2011-12-30 15:16:21 -080082 if (ret != sizeof(rdbuf)) {
83 dev_err(&tsdata->client->dev,
84 "%s: i2c_master_recv failed(), ret=%d\n",
85 __func__, ret);
86 return;
87 }
88
Roger Quadros62e65b72014-07-28 09:58:54 -070089 touch = rdbuf[0] & 0x7;
Roger Quadros36874c72014-07-28 10:01:07 -070090 if (touch > tsdata->max_fingers)
91 touch = tsdata->max_fingers;
Jianchun Bian36a281e2011-12-30 15:16:21 -080092
Roger Quadros62e65b72014-07-28 09:58:54 -070093 report->num_touches = touch;
94 bufptr = &rdbuf[2];
Jianchun Bian36a281e2011-12-30 15:16:21 -080095
Roger Quadros62e65b72014-07-28 09:58:54 -070096 for (i = 0; i < touch; i++) {
97 report->touches[i].x = (bufptr[1] << 8) | bufptr[0];
98 report->touches[i].y = (bufptr[3] << 8) | bufptr[2];
Jianchun Bian36a281e2011-12-30 15:16:21 -080099
Roger Quadros36874c72014-07-28 10:01:07 -0700100 if (chip->has_hw_ids) {
101 report->touches[i].id = bufptr[4];
102 bufptr = bufptr + 5;
103 } else {
104 bufptr = bufptr + 4;
105 }
Roger Quadros62e65b72014-07-28 09:58:54 -0700106 }
107}
108
109static void pixcir_ts_report(struct pixcir_i2c_ts_data *ts,
110 struct pixcir_report_data *report)
111{
112 struct input_mt_pos pos[PIXCIR_MAX_SLOTS];
113 int slots[PIXCIR_MAX_SLOTS];
114 struct pixcir_touch *touch;
115 int n, i, slot;
116 struct device *dev = &ts->client->dev;
Roger Quadros36874c72014-07-28 10:01:07 -0700117 const struct pixcir_i2c_chip_data *chip = &ts->pdata->chip;
Roger Quadros62e65b72014-07-28 09:58:54 -0700118
119 n = report->num_touches;
120 if (n > PIXCIR_MAX_SLOTS)
121 n = PIXCIR_MAX_SLOTS;
122
Roger Quadros36874c72014-07-28 10:01:07 -0700123 if (!chip->has_hw_ids) {
124 for (i = 0; i < n; i++) {
125 touch = &report->touches[i];
126 pos[i].x = touch->x;
127 pos[i].y = touch->y;
128 }
129
Henrik Rydberg448c7f382015-02-01 11:25:14 -0800130 input_mt_assign_slots(ts->input, slots, pos, n, 0);
Jianchun Bian36a281e2011-12-30 15:16:21 -0800131 }
132
Roger Quadros62e65b72014-07-28 09:58:54 -0700133 for (i = 0; i < n; i++) {
134 touch = &report->touches[i];
Roger Quadros36874c72014-07-28 10:01:07 -0700135
136 if (chip->has_hw_ids) {
137 slot = input_mt_get_slot_by_key(ts->input, touch->id);
138 if (slot < 0) {
139 dev_dbg(dev, "no free slot for id 0x%x\n",
140 touch->id);
141 continue;
142 }
143 } else {
144 slot = slots[i];
145 }
Roger Quadros62e65b72014-07-28 09:58:54 -0700146
147 input_mt_slot(ts->input, slot);
148 input_mt_report_slot_state(ts->input,
149 MT_TOOL_FINGER, true);
150
151 input_event(ts->input, EV_ABS, ABS_MT_POSITION_X, touch->x);
152 input_event(ts->input, EV_ABS, ABS_MT_POSITION_Y, touch->y);
153
154 dev_dbg(dev, "%d: slot %d, x %d, y %d\n",
155 i, slot, touch->x, touch->y);
156 }
157
158 input_mt_sync_frame(ts->input);
159 input_sync(ts->input);
Jianchun Bian36a281e2011-12-30 15:16:21 -0800160}
161
162static irqreturn_t pixcir_ts_isr(int irq, void *dev_id)
163{
164 struct pixcir_i2c_ts_data *tsdata = dev_id;
Roger Quadros62e65b72014-07-28 09:58:54 -0700165 struct pixcir_report_data report;
Jianchun Bian36a281e2011-12-30 15:16:21 -0800166
Roger Quadros3b36fbb2014-05-18 22:44:35 -0700167 while (tsdata->running) {
Roger Quadros62e65b72014-07-28 09:58:54 -0700168 /* parse packet */
169 pixcir_ts_parse(tsdata, &report);
Jianchun Bian36a281e2011-12-30 15:16:21 -0800170
Roger Quadros62e65b72014-07-28 09:58:54 -0700171 /* report it */
172 pixcir_ts_report(tsdata, &report);
173
Dmitry Torokhovcb4a5f02015-07-06 11:56:21 -0700174 if (gpiod_get_value(tsdata->gpio_attb)) {
Roger Quadros62e65b72014-07-28 09:58:54 -0700175 if (report.num_touches) {
176 /*
177 * Last report with no finger up?
178 * Do it now then.
179 */
180 input_mt_sync_frame(tsdata->input);
181 input_sync(tsdata->input);
182 }
Jianchun Bian36a281e2011-12-30 15:16:21 -0800183 break;
Roger Quadros62e65b72014-07-28 09:58:54 -0700184 }
Jianchun Bian36a281e2011-12-30 15:16:21 -0800185
186 msleep(20);
187 }
188
189 return IRQ_HANDLED;
190}
191
Roger Quadros3b36fbb2014-05-18 22:44:35 -0700192static int pixcir_set_power_mode(struct pixcir_i2c_ts_data *ts,
193 enum pixcir_power_mode mode)
194{
195 struct device *dev = &ts->client->dev;
196 int ret;
197
198 ret = i2c_smbus_read_byte_data(ts->client, PIXCIR_REG_POWER_MODE);
199 if (ret < 0) {
200 dev_err(dev, "%s: can't read reg 0x%x : %d\n",
201 __func__, PIXCIR_REG_POWER_MODE, ret);
202 return ret;
203 }
204
205 ret &= ~PIXCIR_POWER_MODE_MASK;
206 ret |= mode;
207
208 /* Always AUTO_IDLE */
209 ret |= PIXCIR_POWER_ALLOW_IDLE;
210
211 ret = i2c_smbus_write_byte_data(ts->client, PIXCIR_REG_POWER_MODE, ret);
212 if (ret < 0) {
213 dev_err(dev, "%s: can't write reg 0x%x : %d\n",
214 __func__, PIXCIR_REG_POWER_MODE, ret);
215 return ret;
216 }
217
218 return 0;
219}
220
221/*
222 * Set the interrupt mode for the device i.e. ATTB line behaviour
223 *
224 * @polarity : 1 for active high, 0 for active low.
225 */
226static int pixcir_set_int_mode(struct pixcir_i2c_ts_data *ts,
227 enum pixcir_int_mode mode, bool polarity)
228{
229 struct device *dev = &ts->client->dev;
230 int ret;
231
232 ret = i2c_smbus_read_byte_data(ts->client, PIXCIR_REG_INT_MODE);
233 if (ret < 0) {
234 dev_err(dev, "%s: can't read reg 0x%x : %d\n",
235 __func__, PIXCIR_REG_INT_MODE, ret);
236 return ret;
237 }
238
239 ret &= ~PIXCIR_INT_MODE_MASK;
240 ret |= mode;
241
242 if (polarity)
243 ret |= PIXCIR_INT_POL_HIGH;
244 else
245 ret &= ~PIXCIR_INT_POL_HIGH;
246
247 ret = i2c_smbus_write_byte_data(ts->client, PIXCIR_REG_INT_MODE, ret);
248 if (ret < 0) {
249 dev_err(dev, "%s: can't write reg 0x%x : %d\n",
250 __func__, PIXCIR_REG_INT_MODE, ret);
251 return ret;
252 }
253
254 return 0;
255}
256
257/*
258 * Enable/disable interrupt generation
259 */
260static int pixcir_int_enable(struct pixcir_i2c_ts_data *ts, bool enable)
261{
262 struct device *dev = &ts->client->dev;
263 int ret;
264
265 ret = i2c_smbus_read_byte_data(ts->client, PIXCIR_REG_INT_MODE);
266 if (ret < 0) {
267 dev_err(dev, "%s: can't read reg 0x%x : %d\n",
268 __func__, PIXCIR_REG_INT_MODE, ret);
269 return ret;
270 }
271
272 if (enable)
273 ret |= PIXCIR_INT_ENABLE;
274 else
275 ret &= ~PIXCIR_INT_ENABLE;
276
277 ret = i2c_smbus_write_byte_data(ts->client, PIXCIR_REG_INT_MODE, ret);
278 if (ret < 0) {
279 dev_err(dev, "%s: can't write reg 0x%x : %d\n",
280 __func__, PIXCIR_REG_INT_MODE, ret);
281 return ret;
282 }
283
284 return 0;
285}
286
287static int pixcir_start(struct pixcir_i2c_ts_data *ts)
288{
289 struct device *dev = &ts->client->dev;
290 int error;
291
292 /* LEVEL_TOUCH interrupt with active low polarity */
293 error = pixcir_set_int_mode(ts, PIXCIR_INT_LEVEL_TOUCH, 0);
294 if (error) {
295 dev_err(dev, "Failed to set interrupt mode: %d\n", error);
296 return error;
297 }
298
299 ts->running = true;
300 mb(); /* Update status before IRQ can fire */
301
302 /* enable interrupt generation */
303 error = pixcir_int_enable(ts, true);
304 if (error) {
305 dev_err(dev, "Failed to enable interrupt generation: %d\n",
306 error);
307 return error;
308 }
309
310 return 0;
311}
312
313static int pixcir_stop(struct pixcir_i2c_ts_data *ts)
314{
315 int error;
316
317 /* Disable interrupt generation */
318 error = pixcir_int_enable(ts, false);
319 if (error) {
320 dev_err(&ts->client->dev,
321 "Failed to disable interrupt generation: %d\n",
322 error);
323 return error;
324 }
325
326 /* Exit ISR if running, no more report parsing */
327 ts->running = false;
328 mb(); /* update status before we synchronize irq */
329
330 /* Wait till running ISR is complete */
331 synchronize_irq(ts->client->irq);
332
333 return 0;
334}
335
336static int pixcir_input_open(struct input_dev *dev)
337{
338 struct pixcir_i2c_ts_data *ts = input_get_drvdata(dev);
339
340 return pixcir_start(ts);
341}
342
343static void pixcir_input_close(struct input_dev *dev)
344{
345 struct pixcir_i2c_ts_data *ts = input_get_drvdata(dev);
346
347 pixcir_stop(ts);
348}
349
Jingoo Han02b6a582014-11-02 00:04:14 -0700350static int __maybe_unused pixcir_i2c_ts_suspend(struct device *dev)
Jianchun Bian36a281e2011-12-30 15:16:21 -0800351{
352 struct i2c_client *client = to_i2c_client(dev);
Roger Quadros7cdcb8d2014-05-18 22:49:20 -0700353 struct pixcir_i2c_ts_data *ts = i2c_get_clientdata(client);
354 struct input_dev *input = ts->input;
355 int ret = 0;
Jianchun Bian36a281e2011-12-30 15:16:21 -0800356
Roger Quadros7cdcb8d2014-05-18 22:49:20 -0700357 mutex_lock(&input->mutex);
358
359 if (device_may_wakeup(&client->dev)) {
360 if (!input->users) {
361 ret = pixcir_start(ts);
362 if (ret) {
363 dev_err(dev, "Failed to start\n");
364 goto unlock;
365 }
366 }
367
Jianchun Bian36a281e2011-12-30 15:16:21 -0800368 enable_irq_wake(client->irq);
Roger Quadros7cdcb8d2014-05-18 22:49:20 -0700369 } else if (input->users) {
370 ret = pixcir_stop(ts);
371 }
Jianchun Bian36a281e2011-12-30 15:16:21 -0800372
Roger Quadros7cdcb8d2014-05-18 22:49:20 -0700373unlock:
374 mutex_unlock(&input->mutex);
375
376 return ret;
Jianchun Bian36a281e2011-12-30 15:16:21 -0800377}
378
Jingoo Han02b6a582014-11-02 00:04:14 -0700379static int __maybe_unused pixcir_i2c_ts_resume(struct device *dev)
Jianchun Bian36a281e2011-12-30 15:16:21 -0800380{
381 struct i2c_client *client = to_i2c_client(dev);
Roger Quadros7cdcb8d2014-05-18 22:49:20 -0700382 struct pixcir_i2c_ts_data *ts = i2c_get_clientdata(client);
383 struct input_dev *input = ts->input;
384 int ret = 0;
Jianchun Bian36a281e2011-12-30 15:16:21 -0800385
Roger Quadros7cdcb8d2014-05-18 22:49:20 -0700386 mutex_lock(&input->mutex);
387
388 if (device_may_wakeup(&client->dev)) {
Jianchun Bian36a281e2011-12-30 15:16:21 -0800389 disable_irq_wake(client->irq);
390
Roger Quadros7cdcb8d2014-05-18 22:49:20 -0700391 if (!input->users) {
392 ret = pixcir_stop(ts);
393 if (ret) {
394 dev_err(dev, "Failed to stop\n");
395 goto unlock;
396 }
397 }
398 } else if (input->users) {
399 ret = pixcir_start(ts);
400 }
401
402unlock:
403 mutex_unlock(&input->mutex);
404
405 return ret;
Jianchun Bian36a281e2011-12-30 15:16:21 -0800406}
Jianchun Bian36a281e2011-12-30 15:16:21 -0800407
408static SIMPLE_DEV_PM_OPS(pixcir_dev_pm_ops,
409 pixcir_i2c_ts_suspend, pixcir_i2c_ts_resume);
410
Roger Quadrosa4054592014-07-28 10:05:39 -0700411#ifdef CONFIG_OF
412static const struct of_device_id pixcir_of_match[];
413
414static struct pixcir_ts_platform_data *pixcir_parse_dt(struct device *dev)
415{
416 struct pixcir_ts_platform_data *pdata;
417 struct device_node *np = dev->of_node;
418 const struct of_device_id *match;
419
420 match = of_match_device(of_match_ptr(pixcir_of_match), dev);
421 if (!match)
422 return ERR_PTR(-EINVAL);
423
424 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
425 if (!pdata)
426 return ERR_PTR(-ENOMEM);
427
428 pdata->chip = *(const struct pixcir_i2c_chip_data *)match->data;
429
Roger Quadrosa4054592014-07-28 10:05:39 -0700430 if (of_property_read_u32(np, "touchscreen-size-x", &pdata->x_max)) {
431 dev_err(dev, "Failed to get touchscreen-size-x property\n");
432 return ERR_PTR(-EINVAL);
433 }
434 pdata->x_max -= 1;
435
436 if (of_property_read_u32(np, "touchscreen-size-y", &pdata->y_max)) {
437 dev_err(dev, "Failed to get touchscreen-size-y property\n");
438 return ERR_PTR(-EINVAL);
439 }
440 pdata->y_max -= 1;
441
Dmitry Torokhovcb4a5f02015-07-06 11:56:21 -0700442 dev_dbg(dev, "%s: x %d, y %d\n", __func__,
443 pdata->x_max + 1, pdata->y_max + 1);
Roger Quadrosa4054592014-07-28 10:05:39 -0700444
445 return pdata;
446}
447#else
448static struct pixcir_ts_platform_data *pixcir_parse_dt(struct device *dev)
449{
450 return ERR_PTR(-EINVAL);
451}
452#endif
453
Bill Pemberton5298cc42012-11-23 21:38:25 -0800454static int pixcir_i2c_ts_probe(struct i2c_client *client,
Jianchun Bian36a281e2011-12-30 15:16:21 -0800455 const struct i2c_device_id *id)
456{
Jingoo Hanc838cb32013-12-05 19:21:10 -0800457 const struct pixcir_ts_platform_data *pdata =
458 dev_get_platdata(&client->dev);
Roger Quadrose9d47182014-05-18 22:43:42 -0700459 struct device *dev = &client->dev;
Roger Quadrosa4054592014-07-28 10:05:39 -0700460 struct device_node *np = dev->of_node;
Jianchun Bian36a281e2011-12-30 15:16:21 -0800461 struct pixcir_i2c_ts_data *tsdata;
462 struct input_dev *input;
463 int error;
464
Roger Quadrosa4054592014-07-28 10:05:39 -0700465 if (np && !pdata) {
466 pdata = pixcir_parse_dt(dev);
467 if (IS_ERR(pdata))
468 return PTR_ERR(pdata);
469 }
470
Jianchun Bian36a281e2011-12-30 15:16:21 -0800471 if (!pdata) {
472 dev_err(&client->dev, "platform data not defined\n");
473 return -EINVAL;
474 }
475
Roger Quadros36874c72014-07-28 10:01:07 -0700476 if (!pdata->chip.max_fingers) {
477 dev_err(dev, "Invalid max_fingers in pdata\n");
478 return -EINVAL;
479 }
480
Roger Quadrose9d47182014-05-18 22:43:42 -0700481 tsdata = devm_kzalloc(dev, sizeof(*tsdata), GFP_KERNEL);
482 if (!tsdata)
483 return -ENOMEM;
484
485 input = devm_input_allocate_device(dev);
486 if (!input) {
487 dev_err(dev, "Failed to allocate input device\n");
488 return -ENOMEM;
Jianchun Bian36a281e2011-12-30 15:16:21 -0800489 }
490
491 tsdata->client = client;
492 tsdata->input = input;
Roger Quadros36874c72014-07-28 10:01:07 -0700493 tsdata->pdata = pdata;
Jianchun Bian36a281e2011-12-30 15:16:21 -0800494
495 input->name = client->name;
496 input->id.bustype = BUS_I2C;
Roger Quadros3b36fbb2014-05-18 22:44:35 -0700497 input->open = pixcir_input_open;
498 input->close = pixcir_input_close;
Jianchun Bian36a281e2011-12-30 15:16:21 -0800499 input->dev.parent = &client->dev;
500
501 __set_bit(EV_KEY, input->evbit);
502 __set_bit(EV_ABS, input->evbit);
503 __set_bit(BTN_TOUCH, input->keybit);
504 input_set_abs_params(input, ABS_X, 0, pdata->x_max, 0, 0);
505 input_set_abs_params(input, ABS_Y, 0, pdata->y_max, 0, 0);
506 input_set_abs_params(input, ABS_MT_POSITION_X, 0, pdata->x_max, 0, 0);
507 input_set_abs_params(input, ABS_MT_POSITION_Y, 0, pdata->y_max, 0, 0);
508
Roger Quadros36874c72014-07-28 10:01:07 -0700509 tsdata->max_fingers = tsdata->pdata->chip.max_fingers;
510 if (tsdata->max_fingers > PIXCIR_MAX_SLOTS) {
511 tsdata->max_fingers = PIXCIR_MAX_SLOTS;
512 dev_info(dev, "Limiting maximum fingers to %d\n",
513 tsdata->max_fingers);
514 }
515
516 error = input_mt_init_slots(input, tsdata->max_fingers,
Roger Quadros62e65b72014-07-28 09:58:54 -0700517 INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
518 if (error) {
519 dev_err(dev, "Error initializing Multi-Touch slots\n");
520 return error;
521 }
522
Jianchun Bian36a281e2011-12-30 15:16:21 -0800523 input_set_drvdata(input, tsdata);
524
Dmitry Torokhovcb4a5f02015-07-06 11:56:21 -0700525 tsdata->gpio_attb = devm_gpiod_get(dev, "attb", GPIOD_IN);
526 if (IS_ERR(tsdata->gpio_attb)) {
527 error = PTR_ERR(tsdata->gpio_attb);
528 dev_err(dev, "Failed to request ATTB gpio: %d\n", error);
Roger Quadros0dfc8d42014-05-18 22:46:43 -0700529 return error;
530 }
531
Roger Quadrose9d47182014-05-18 22:43:42 -0700532 error = devm_request_threaded_irq(dev, client->irq, NULL, pixcir_ts_isr,
533 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
534 client->name, tsdata);
Jianchun Bian36a281e2011-12-30 15:16:21 -0800535 if (error) {
Roger Quadrose9d47182014-05-18 22:43:42 -0700536 dev_err(dev, "failed to request irq %d\n", client->irq);
537 return error;
Jianchun Bian36a281e2011-12-30 15:16:21 -0800538 }
539
Roger Quadros3b36fbb2014-05-18 22:44:35 -0700540 /* Always be in IDLE mode to save power, device supports auto wake */
541 error = pixcir_set_power_mode(tsdata, PIXCIR_POWER_IDLE);
542 if (error) {
543 dev_err(dev, "Failed to set IDLE mode\n");
544 return error;
545 }
546
547 /* Stop device till opened */
548 error = pixcir_stop(tsdata);
549 if (error)
550 return error;
551
Jianchun Bian36a281e2011-12-30 15:16:21 -0800552 error = input_register_device(input);
553 if (error)
Roger Quadrose9d47182014-05-18 22:43:42 -0700554 return error;
Jianchun Bian36a281e2011-12-30 15:16:21 -0800555
Roger Quadros7cdcb8d2014-05-18 22:49:20 -0700556 i2c_set_clientdata(client, tsdata);
Jianchun Bian36a281e2011-12-30 15:16:21 -0800557 device_init_wakeup(&client->dev, 1);
558
559 return 0;
Jianchun Bian36a281e2011-12-30 15:16:21 -0800560}
561
Bill Pembertone2619cf2012-11-23 21:50:47 -0800562static int pixcir_i2c_ts_remove(struct i2c_client *client)
Jianchun Bian36a281e2011-12-30 15:16:21 -0800563{
Jianchun Bian36a281e2011-12-30 15:16:21 -0800564 device_init_wakeup(&client->dev, 0);
565
Jianchun Bian36a281e2011-12-30 15:16:21 -0800566 return 0;
567}
568
569static const struct i2c_device_id pixcir_i2c_ts_id[] = {
570 { "pixcir_ts", 0 },
Roger Quadrosa4054592014-07-28 10:05:39 -0700571 { "pixcir_tangoc", 0 },
Jianchun Bian36a281e2011-12-30 15:16:21 -0800572 { }
573};
574MODULE_DEVICE_TABLE(i2c, pixcir_i2c_ts_id);
575
Roger Quadrosa4054592014-07-28 10:05:39 -0700576#ifdef CONFIG_OF
577static const struct pixcir_i2c_chip_data pixcir_ts_data = {
578 .max_fingers = 2,
579 /* no hw id support */
580};
581
582static const struct pixcir_i2c_chip_data pixcir_tangoc_data = {
583 .max_fingers = 5,
584 .has_hw_ids = true,
585};
586
587static const struct of_device_id pixcir_of_match[] = {
588 { .compatible = "pixcir,pixcir_ts", .data = &pixcir_ts_data },
589 { .compatible = "pixcir,pixcir_tangoc", .data = &pixcir_tangoc_data },
590 { }
591};
592MODULE_DEVICE_TABLE(of, pixcir_of_match);
593#endif
594
Jianchun Bian36a281e2011-12-30 15:16:21 -0800595static struct i2c_driver pixcir_i2c_ts_driver = {
596 .driver = {
597 .owner = THIS_MODULE,
598 .name = "pixcir_ts",
599 .pm = &pixcir_dev_pm_ops,
Roger Quadrosa4054592014-07-28 10:05:39 -0700600 .of_match_table = of_match_ptr(pixcir_of_match),
Jianchun Bian36a281e2011-12-30 15:16:21 -0800601 },
602 .probe = pixcir_i2c_ts_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -0800603 .remove = pixcir_i2c_ts_remove,
Jianchun Bian36a281e2011-12-30 15:16:21 -0800604 .id_table = pixcir_i2c_ts_id,
605};
606
Dmitry Torokhov4a533832012-03-16 23:05:44 -0700607module_i2c_driver(pixcir_i2c_ts_driver);
Jianchun Bian36a281e2011-12-30 15:16:21 -0800608
609MODULE_AUTHOR("Jianchun Bian <jcbian@pixcir.com.cn>, Dequan Meng <dqmeng@pixcir.com.cn>");
610MODULE_DESCRIPTION("Pixcir I2C Touchscreen Driver");
611MODULE_LICENSE("GPL");