aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2017-02-10 18:18:07 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2017-02-12 17:55:09 -0500
commitd0d89493bff8b7c7bf580197a44a1d49c50395b3 (patch)
tree599941601b9018385965b00d82c062e16408e5a4
parentf7bf6f58675a76c08e6eee7fa5c264884eb5c599 (diff)
Input: tsc2004/5 - switch to using generic device properties
Instead of supporting legacy platform data (of which we have no mainline users) and OF-based properties, let's switch to generic device properties. This will still allow legacy boards to use the driver (by defining property sets and attaching them to the drivers) and will simplify probe and make driver usable on ACPI-based systems as well. Reviewed-By: Sebastian Reichel <sre@kernel.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r--drivers/input/touchscreen/tsc200x-core.c93
-rw-r--r--include/linux/spi/tsc2005.h34
2 files changed, 30 insertions, 97 deletions
diff --git a/drivers/input/touchscreen/tsc200x-core.c b/drivers/input/touchscreen/tsc200x-core.c
index 1c14a38e3748..88ea5e1b72ae 100644
--- a/drivers/input/touchscreen/tsc200x-core.c
+++ b/drivers/input/touchscreen/tsc200x-core.c
@@ -27,7 +27,6 @@
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include <linux/pm.h> 28#include <linux/pm.h>
29#include <linux/of.h> 29#include <linux/of.h>
30#include <linux/spi/tsc2005.h>
31#include <linux/regulator/consumer.h> 30#include <linux/regulator/consumer.h>
32#include <linux/regmap.h> 31#include <linux/regmap.h>
33#include <linux/gpio/consumer.h> 32#include <linux/gpio/consumer.h>
@@ -114,7 +113,6 @@ struct tsc200x {
114 struct regulator *vio; 113 struct regulator *vio;
115 114
116 struct gpio_desc *reset_gpio; 115 struct gpio_desc *reset_gpio;
117 void (*set_reset)(bool enable);
118 int (*tsc200x_cmd)(struct device *dev, u8 cmd); 116 int (*tsc200x_cmd)(struct device *dev, u8 cmd);
119 int irq; 117 int irq;
120}; 118};
@@ -227,12 +225,13 @@ static void tsc200x_stop_scan(struct tsc200x *ts)
227 ts->tsc200x_cmd(ts->dev, TSC200X_CMD_STOP); 225 ts->tsc200x_cmd(ts->dev, TSC200X_CMD_STOP);
228} 226}
229 227
230static void tsc200x_set_reset(struct tsc200x *ts, bool enable) 228static void tsc200x_reset(struct tsc200x *ts)
231{ 229{
232 if (ts->reset_gpio) 230 if (ts->reset_gpio) {
233 gpiod_set_value_cansleep(ts->reset_gpio, enable); 231 gpiod_set_value_cansleep(ts->reset_gpio, 1);
234 else if (ts->set_reset) 232 usleep_range(100, 500); /* only 10us required */
235 ts->set_reset(enable); 233 gpiod_set_value_cansleep(ts->reset_gpio, 0);
234 }
236} 235}
237 236
238/* must be called with ts->mutex held */ 237/* must be called with ts->mutex held */
@@ -253,7 +252,7 @@ static void __tsc200x_enable(struct tsc200x *ts)
253{ 252{
254 tsc200x_start_scan(ts); 253 tsc200x_start_scan(ts);
255 254
256 if (ts->esd_timeout && (ts->set_reset || ts->reset_gpio)) { 255 if (ts->esd_timeout && ts->reset_gpio) {
257 ts->last_valid_interrupt = jiffies; 256 ts->last_valid_interrupt = jiffies;
258 schedule_delayed_work(&ts->esd_work, 257 schedule_delayed_work(&ts->esd_work,
259 round_jiffies_relative( 258 round_jiffies_relative(
@@ -310,9 +309,7 @@ static ssize_t tsc200x_selftest_show(struct device *dev,
310 } 309 }
311 310
312 /* hardware reset */ 311 /* hardware reset */
313 tsc200x_set_reset(ts, false); 312 tsc200x_reset(ts);
314 usleep_range(100, 500); /* only 10us required */
315 tsc200x_set_reset(ts, true);
316 313
317 if (!success) 314 if (!success)
318 goto out; 315 goto out;
@@ -354,7 +351,7 @@ static umode_t tsc200x_attr_is_visible(struct kobject *kobj,
354 umode_t mode = attr->mode; 351 umode_t mode = attr->mode;
355 352
356 if (attr == &dev_attr_selftest.attr) { 353 if (attr == &dev_attr_selftest.attr) {
357 if (!ts->set_reset && !ts->reset_gpio) 354 if (!ts->reset_gpio)
358 mode = 0; 355 mode = 0;
359 } 356 }
360 357
@@ -404,9 +401,7 @@ static void tsc200x_esd_work(struct work_struct *work)
404 401
405 tsc200x_update_pen_state(ts, 0, 0, 0); 402 tsc200x_update_pen_state(ts, 0, 0, 0);
406 403
407 tsc200x_set_reset(ts, false); 404 tsc200x_reset(ts);
408 usleep_range(100, 500); /* only 10us required */
409 tsc200x_set_reset(ts, true);
410 405
411 enable_irq(ts->irq); 406 enable_irq(ts->irq);
412 tsc200x_start_scan(ts); 407 tsc200x_start_scan(ts);
@@ -454,26 +449,12 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id,
454 struct regmap *regmap, 449 struct regmap *regmap,
455 int (*tsc200x_cmd)(struct device *dev, u8 cmd)) 450 int (*tsc200x_cmd)(struct device *dev, u8 cmd))
456{ 451{
457 const struct tsc2005_platform_data *pdata = dev_get_platdata(dev);
458 struct device_node *np = dev->of_node;
459
460 struct tsc200x *ts; 452 struct tsc200x *ts;
461 struct input_dev *input_dev; 453 struct input_dev *input_dev;
462 unsigned int max_x = MAX_12BIT; 454 u32 x_plate_ohm;
463 unsigned int max_y = MAX_12BIT; 455 u32 esd_timeout;
464 unsigned int max_p = MAX_12BIT;
465 unsigned int fudge_x = TSC200X_DEF_X_FUZZ;
466 unsigned int fudge_y = TSC200X_DEF_Y_FUZZ;
467 unsigned int fudge_p = TSC200X_DEF_P_FUZZ;
468 unsigned int x_plate_ohm = TSC200X_DEF_RESISTOR;
469 unsigned int esd_timeout;
470 int error; 456 int error;
471 457
472 if (!np && !pdata) {
473 dev_err(dev, "no platform data\n");
474 return -ENODEV;
475 }
476
477 if (irq <= 0) { 458 if (irq <= 0) {
478 dev_err(dev, "no irq\n"); 459 dev_err(dev, "no irq\n");
479 return -ENODEV; 460 return -ENODEV;
@@ -487,23 +468,6 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id,
487 return -ENODEV; 468 return -ENODEV;
488 } 469 }
489 470
490 if (pdata) {
491 fudge_x = pdata->ts_x_fudge;
492 fudge_y = pdata->ts_y_fudge;
493 fudge_p = pdata->ts_pressure_fudge;
494 max_x = pdata->ts_x_max;
495 max_y = pdata->ts_y_max;
496 max_p = pdata->ts_pressure_max;
497 x_plate_ohm = pdata->ts_x_plate_ohm;
498 esd_timeout = pdata->esd_timeout_ms;
499 } else {
500 x_plate_ohm = TSC200X_DEF_RESISTOR;
501 of_property_read_u32(np, "ti,x-plate-ohms", &x_plate_ohm);
502 esd_timeout = 0;
503 of_property_read_u32(np, "ti,esd-recovery-timeout-ms",
504 &esd_timeout);
505 }
506
507 ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); 471 ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL);
508 if (!ts) 472 if (!ts)
509 return -ENOMEM; 473 return -ENOMEM;
@@ -517,8 +481,13 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id,
517 ts->idev = input_dev; 481 ts->idev = input_dev;
518 ts->regmap = regmap; 482 ts->regmap = regmap;
519 ts->tsc200x_cmd = tsc200x_cmd; 483 ts->tsc200x_cmd = tsc200x_cmd;
520 ts->x_plate_ohm = x_plate_ohm; 484
521 ts->esd_timeout = esd_timeout; 485 error = device_property_read_u32(dev, "ti,x-plate-ohms", &x_plate_ohm);
486 ts->x_plate_ohm = error ? TSC200X_DEF_RESISTOR : x_plate_ohm;
487
488 error = device_property_read_u32(dev, "ti,esd-recovery-timeout-ms",
489 &esd_timeout);
490 ts->esd_timeout = error ? 0 : esd_timeout;
522 491
523 ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); 492 ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
524 if (IS_ERR(ts->reset_gpio)) { 493 if (IS_ERR(ts->reset_gpio)) {
@@ -534,9 +503,6 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id,
534 return error; 503 return error;
535 } 504 }
536 505
537 if (!ts->reset_gpio && pdata)
538 ts->set_reset = pdata->set_reset;
539
540 mutex_init(&ts->mutex); 506 mutex_init(&ts->mutex);
541 507
542 spin_lock_init(&ts->lock); 508 spin_lock_init(&ts->lock);
@@ -559,22 +525,23 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id,
559 525
560 input_dev->phys = ts->phys; 526 input_dev->phys = ts->phys;
561 input_dev->id = *tsc_id; 527 input_dev->id = *tsc_id;
562 input_dev->dev.parent = dev;
563 input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY);
564 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
565
566 input_set_abs_params(input_dev, ABS_X, 0, max_x, fudge_x, 0);
567 input_set_abs_params(input_dev, ABS_Y, 0, max_y, fudge_y, 0);
568 input_set_abs_params(input_dev, ABS_PRESSURE, 0, max_p, fudge_p, 0);
569
570 if (np)
571 touchscreen_parse_properties(input_dev, false, NULL);
572 528
573 input_dev->open = tsc200x_open; 529 input_dev->open = tsc200x_open;
574 input_dev->close = tsc200x_close; 530 input_dev->close = tsc200x_close;
575 531
576 input_set_drvdata(input_dev, ts); 532 input_set_drvdata(input_dev, ts);
577 533
534 input_set_capability(input_dev, EV_KEY, BTN_TOUCH);
535
536 input_set_abs_params(input_dev, ABS_X,
537 0, MAX_12BIT, TSC200X_DEF_X_FUZZ, 0);
538 input_set_abs_params(input_dev, ABS_Y,
539 0, MAX_12BIT, TSC200X_DEF_Y_FUZZ, 0);
540 input_set_abs_params(input_dev, ABS_PRESSURE,
541 0, MAX_12BIT, TSC200X_DEF_P_FUZZ, 0);
542
543 touchscreen_parse_properties(input_dev, false, NULL);
544
578 /* Ensure the touchscreen is off */ 545 /* Ensure the touchscreen is off */
579 tsc200x_stop_scan(ts); 546 tsc200x_stop_scan(ts);
580 547
diff --git a/include/linux/spi/tsc2005.h b/include/linux/spi/tsc2005.h
deleted file mode 100644
index 563b3b1799a8..000000000000
--- a/include/linux/spi/tsc2005.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/*
2 * This file is part of TSC2005 touchscreen driver
3 *
4 * Copyright (C) 2009-2010 Nokia Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#ifndef _LINUX_SPI_TSC2005_H
18#define _LINUX_SPI_TSC2005_H
19
20#include <linux/types.h>
21
22struct tsc2005_platform_data {
23 int ts_pressure_max;
24 int ts_pressure_fudge;
25 int ts_x_max;
26 int ts_x_fudge;
27 int ts_y_max;
28 int ts_y_fudge;
29 int ts_x_plate_ohm;
30 unsigned int esd_timeout_ms;
31 void (*set_reset)(bool enable);
32};
33
34#endif