From f0fbeaa82028eaa4e2481ab49534c2e1465c99ce Mon Sep 17 00:00:00 2001 From: Marco Felsch Date: Fri, 9 Aug 2019 07:37:32 -0700 Subject: dt-bindings: input: ads7846: fix property description The ti,y-max is used for the maximum value of the Y axis. Signed-off-by: Marco Felsch Reviewed-by: Rob Herring Signed-off-by: Dmitry Torokhov --- Documentation/devicetree/bindings/input/touchscreen/ads7846.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Documentation/devicetree') diff --git a/Documentation/devicetree/bindings/input/touchscreen/ads7846.txt b/Documentation/devicetree/bindings/input/touchscreen/ads7846.txt index 04413da51391..ce540ddac902 100644 --- a/Documentation/devicetree/bindings/input/touchscreen/ads7846.txt +++ b/Documentation/devicetree/bindings/input/touchscreen/ads7846.txt @@ -52,7 +52,7 @@ Optional properties: ti,x-min Minimum value on the X axis (u16). ti,y-min Minimum value on the Y axis (u16). ti,x-max Maximum value on the X axis (u16). - ti,y-max Minimum value on the Y axis (u16). + ti,y-max Maximum value on the Y axis (u16). ti,pressure-min Minimum reported pressure value (threshold) - u16. ti,pressure-max Maximum reported pressure value (u16). -- cgit v1.2.3 From a2f99330c50bb89fe2625d374fdf22f021163b55 Mon Sep 17 00:00:00 2001 From: Marco Felsch Date: Fri, 9 Aug 2019 07:40:00 -0700 Subject: Input: ads7846 - add support for general touchscreen bindings A few vendor specific bindings are now covered by common bindings. Let the driver parse the common bindings to make use of common inverting and swapping mechnism. Aslo make use of touchscreen_report_pos() to ensure the correct inverting-swapping order. The vendor specific properties are used as default (backward compatibility) and gets overwritten by common bindings. Signed-off-by: Marco Felsch Reviewed-by: Rob Herring Signed-off-by: Dmitry Torokhov --- .../bindings/input/touchscreen/ads7846.txt | 29 ++++++++++++----- drivers/input/touchscreen/ads7846.c | 38 +++++++++++++++++----- 2 files changed, 51 insertions(+), 16 deletions(-) (limited to 'Documentation/devicetree') diff --git a/Documentation/devicetree/bindings/input/touchscreen/ads7846.txt b/Documentation/devicetree/bindings/input/touchscreen/ads7846.txt index ce540ddac902..81f6bda97d3c 100644 --- a/Documentation/devicetree/bindings/input/touchscreen/ads7846.txt +++ b/Documentation/devicetree/bindings/input/touchscreen/ads7846.txt @@ -32,7 +32,6 @@ Optional properties: (ADS7846). ti,keep-vref-on set to keep vref on for differential measurements as well - ti,swap-xy swap x and y axis ti,settle-delay-usec Settling time of the analog signals; a function of Vcc and the capacitance on the X/Y drivers. If set to non-zero, @@ -51,13 +50,6 @@ Optional properties: in Ohms (u16). ti,x-min Minimum value on the X axis (u16). ti,y-min Minimum value on the Y axis (u16). - ti,x-max Maximum value on the X axis (u16). - ti,y-max Maximum value on the Y axis (u16). - ti,pressure-min Minimum reported pressure value - (threshold) - u16. - ti,pressure-max Maximum reported pressure value (u16). - ti,debounce-max Max number of additional readings per - sample (u16). ti,debounce-tol Tolerance used for filtering (u16). ti,debounce-rep Additional consecutive good readings required after the first two (u16). @@ -67,7 +59,28 @@ Optional properties: line is connected to. wakeup-source use any event on touchscreen as wakeup event. (Legacy property support: "linux,wakeup") + touchscreen-size-x General touchscreen binding, see [1]. + touchscreen-size-y General touchscreen binding, see [1]. + touchscreen-max-pressure General touchscreen binding, see [1]. + touchscreen-min-pressure General touchscreen binding, see [1]. + touchscreen-average-samples General touchscreen binding, see [1]. + touchscreen-inverted-x General touchscreen binding, see [1]. + touchscreen-inverted-y General touchscreen binding, see [1]. + touchscreen-swapped-x-y General touchscreen binding, see [1]. + +[1] All general touchscreen properties are described in + Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt. +Deprecated properties: + + ti,swap-xy swap x and y axis + ti,x-max Maximum value on the X axis (u16). + ti,y-max Maximum value on the Y axis (u16). + ti,pressure-min Minimum reported pressure value + (threshold) - u16. + ti,pressure-max Maximum reported pressure value (u16). + ti,debounce-max Max number of additional readings per + sample (u16). Example for a TSC2046 chip connected to an McSPI controller of an OMAP SoC:: diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index accbbe8d2966..51ddb204ca1b 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -129,6 +130,8 @@ struct ads7846 { u16 penirq_recheck_delay_usecs; + struct touchscreen_properties core_prop; + struct mutex lock; bool stopped; /* P: lock */ bool disabled; /* P: lock */ @@ -823,17 +826,13 @@ static void ads7846_report_state(struct ads7846 *ts) if (Rt) { struct input_dev *input = ts->input; - if (ts->swap_xy) - swap(x, y); - if (!ts->pendown) { input_report_key(input, BTN_TOUCH, 1); ts->pendown = true; dev_vdbg(&ts->spi->dev, "DOWN\n"); } - input_report_abs(input, ABS_X, x); - input_report_abs(input, ABS_Y, y); + touchscreen_report_pos(input, &ts->core_prop, x, y, false); input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt); input_sync(input); @@ -1185,6 +1184,7 @@ static const struct ads7846_platform_data *ads7846_probe_dt(struct device *dev) struct ads7846_platform_data *pdata; struct device_node *node = dev->of_node; const struct of_device_id *match; + u32 value; if (!node) { dev_err(dev, "Device does not have associated DT data\n"); @@ -1223,10 +1223,18 @@ static const struct ads7846_platform_data *ads7846_probe_dt(struct device *dev) of_property_read_u16(node, "ti,x-max", &pdata->x_max); of_property_read_u16(node, "ti,y-max", &pdata->y_max); + /* + * touchscreen-max-pressure gets parsed during + * touchscreen_parse_properties() + */ of_property_read_u16(node, "ti,pressure-min", &pdata->pressure_min); + if (!of_property_read_u32(node, "touchscreen-min-pressure", &value)) + pdata->pressure_min = (u16) value; of_property_read_u16(node, "ti,pressure-max", &pdata->pressure_max); of_property_read_u16(node, "ti,debounce-max", &pdata->debounce_max); + if (!of_property_read_u32(node, "touchscreen-average-samples", &value)) + pdata->debounce_max = (u16) value; of_property_read_u16(node, "ti,debounce-tol", &pdata->debounce_tol); of_property_read_u16(node, "ti,debounce-rep", &pdata->debounce_rep); @@ -1309,10 +1317,7 @@ static int ads7846_probe(struct spi_device *spi) ts->model = pdata->model ? : 7846; ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; - ts->pressure_max = pdata->pressure_max ? : ~0; - ts->vref_mv = pdata->vref_mv; - ts->swap_xy = pdata->swap_xy; if (pdata->filter != NULL) { if (pdata->filter_init != NULL) { @@ -1364,6 +1369,23 @@ static int ads7846_probe(struct spi_device *spi) input_set_abs_params(input_dev, ABS_PRESSURE, pdata->pressure_min, pdata->pressure_max, 0, 0); + /* + * Parse common framework properties. Must be done here to ensure the + * correct behaviour in case of using the legacy vendor bindings. The + * general binding value overrides the vendor specific one. + */ + touchscreen_parse_properties(ts->input, false, &ts->core_prop); + ts->pressure_max = input_abs_get_max(input_dev, ABS_PRESSURE) ? : ~0; + + /* + * Check if legacy ti,swap-xy binding is used instead of + * touchscreen-swapped-x-y + */ + if (!ts->core_prop.swap_x_y && pdata->swap_xy) { + swap(input_dev->absinfo[ABS_X], input_dev->absinfo[ABS_Y]); + ts->core_prop.swap_x_y = true; + } + ads7846_setup_spi_msg(ts, pdata); ts->reg = regulator_get(&spi->dev, "vcc"); -- cgit v1.2.3 From a1b70a44b80af641a441937803cb8251e8e6d8e3 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Thu, 8 Aug 2019 11:03:59 -0700 Subject: Input: bu21013_ts - convert to use GPIO descriptors This driver can use GPIO descriptors rather than GPIO numbers without any problems, convert it. Name the field variables after the actual pins on the chip rather than the "reset" and "touch" names from the devicetree bindings that are vaguely inaccurate. No in-tree users pass GPIO numbers in platform data so drop this. Descriptor tables can be used to get these GPIOs from a board file if need be. Signed-off-by: Linus Walleij Signed-off-by: Dmitry Torokhov --- .../bindings/input/touchscreen/bu21013.txt | 5 +- drivers/input/touchscreen/bu21013_ts.c | 86 ++++++++++------------ include/linux/input/bu21013.h | 4 - 3 files changed, 41 insertions(+), 54 deletions(-) (limited to 'Documentation/devicetree') diff --git a/Documentation/devicetree/bindings/input/touchscreen/bu21013.txt b/Documentation/devicetree/bindings/input/touchscreen/bu21013.txt index 56d835242af2..43899fc36ecf 100644 --- a/Documentation/devicetree/bindings/input/touchscreen/bu21013.txt +++ b/Documentation/devicetree/bindings/input/touchscreen/bu21013.txt @@ -2,10 +2,11 @@ Required properties: - compatible : "rohm,bu21013_tp" - - reg : I2C device address + - reg : I2C device address + - reset-gpios : GPIO pin enabling (selecting) chip (CS) Optional properties: - - touch-gpio : GPIO pin registering a touch event + - touch-gpios : GPIO pin registering a touch event - -supply : Phandle to a regulator supply - rohm,touch-max-x : Maximum outward permitted limit in the X axis - rohm,touch-max-y : Maximum outward permitted limit in the Y axis diff --git a/drivers/input/touchscreen/bu21013_ts.c b/drivers/input/touchscreen/bu21013_ts.c index 1d703e230ac3..c20f86f98ffc 100644 --- a/drivers/input/touchscreen/bu21013_ts.c +++ b/drivers/input/touchscreen/bu21013_ts.c @@ -14,11 +14,9 @@ #include #include #include -#include +#include #include -#include -#define PEN_DOWN_INTR 0 #define MAX_FINGERS 2 #define RESET_DELAY 30 #define PENUP_TIMEOUT (10) @@ -143,8 +141,9 @@ * @touch_stopped: touch stop flag * @chip: pointer to the touch panel controller * @in_dev: pointer to the input device structure - * @intr_pin: interrupt pin value * @regulator: pointer to the Regulator used for touch screen + * @cs_gpiod: chip select GPIO line + * @int_gpiod: touch interrupt GPIO line * * Touch panel device data structure */ @@ -154,8 +153,9 @@ struct bu21013_ts_data { const struct bu21013_platform_device *chip; struct input_dev *in_dev; struct regulator *regulator; + struct gpio_desc *cs_gpiod; + struct gpio_desc *int_gpiod; unsigned int irq; - unsigned int intr_pin; bool touch_stopped; }; @@ -257,20 +257,21 @@ static irqreturn_t bu21013_gpio_irq(int irq, void *device_data) { struct bu21013_ts_data *data = device_data; struct i2c_client *i2c = data->client; + int keep_polling; int retval; do { retval = bu21013_do_touch_report(data); if (retval < 0) { dev_err(&i2c->dev, "bu21013_do_touch_report failed\n"); - return IRQ_NONE; + break; } - data->intr_pin = gpio_get_value(data->chip->touch_pin); - if (data->intr_pin == PEN_DOWN_INTR) + keep_polling = gpiod_get_value(data->int_gpiod); + if (keep_polling) wait_event_timeout(data->wait, data->touch_stopped, msecs_to_jiffies(2)); - } while (!data->intr_pin && !data->touch_stopped); + } while (keep_polling && !data->touch_stopped); return IRQ_HANDLED; } @@ -425,28 +426,6 @@ static void bu21013_free_irq(struct bu21013_ts_data *bu21013_data) free_irq(bu21013_data->irq, bu21013_data); } -/** - * bu21013_cs_disable() - deconfigures the touch panel controller - * @bu21013_data: device structure pointer - * - * This function is used to deconfigure the chip selection - * for touch panel controller. - */ -static void bu21013_cs_disable(struct bu21013_ts_data *bu21013_data) -{ - int error; - - error = gpio_direction_output(bu21013_data->chip->cs_pin, 0); - if (error < 0) - dev_warn(&bu21013_data->client->dev, - "%s: gpio direction failed, error: %d\n", - __func__, error); - else - gpio_set_value(bu21013_data->chip->cs_pin, 0); - - gpio_free(bu21013_data->chip->cs_pin); -} - #ifdef CONFIG_OF static const struct bu21013_platform_device * bu21013_parse_dt(struct device *dev) @@ -471,9 +450,6 @@ bu21013_parse_dt(struct device *dev) of_property_read_u32(np, "rohm,touch-max-x", &pdata->touch_x_max); of_property_read_u32(np, "rohm,touch-max-y", &pdata->touch_y_max); - pdata->touch_pin = of_get_named_gpio(np, "touch-gpio", 0); - pdata->cs_pin = of_get_named_gpio(np, "reset-gpio", 0); - pdata->ext_clk = false; return pdata; @@ -516,11 +492,6 @@ static int bu21013_probe(struct i2c_client *client, return PTR_ERR(pdata); } - if (!gpio_is_valid(pdata->touch_pin)) { - dev_err(&client->dev, "invalid touch_pin supplied\n"); - return -EINVAL; - } - bu21013_data = kzalloc(sizeof(struct bu21013_ts_data), GFP_KERNEL); in_dev = input_allocate_device(); if (!bu21013_data || !in_dev) { @@ -529,16 +500,26 @@ static int bu21013_probe(struct i2c_client *client, goto err_free_mem; } + /* Named "INT" on the chip, DT binding is "touch" */ + bu21013_data->int_gpiod = gpiod_get(&client->dev, "touch", GPIOD_IN); + error = PTR_ERR_OR_ZERO(bu21013_data->int_gpiod); + if (error) { + if (error != -EPROBE_DEFER) + dev_err(&client->dev, "failed to get INT GPIO\n"); + goto err_free_mem; + } + gpiod_set_consumer_name(bu21013_data->int_gpiod, "BU21013 INT"); + bu21013_data->in_dev = in_dev; bu21013_data->chip = pdata; bu21013_data->client = client; - bu21013_data->irq = gpio_to_irq(pdata->touch_pin); + bu21013_data->irq = gpiod_to_irq(bu21013_data->int_gpiod); bu21013_data->regulator = regulator_get(&client->dev, "avdd"); if (IS_ERR(bu21013_data->regulator)) { dev_err(&client->dev, "regulator_get failed\n"); error = PTR_ERR(bu21013_data->regulator); - goto err_free_mem; + goto err_put_int_gpio; } error = regulator_enable(bu21013_data->regulator); @@ -550,13 +531,16 @@ static int bu21013_probe(struct i2c_client *client, bu21013_data->touch_stopped = false; init_waitqueue_head(&bu21013_data->wait); - /* configure the gpio pins */ - error = gpio_request_one(pdata->cs_pin, GPIOF_OUT_INIT_HIGH, - "touchp_reset"); - if (error < 0) { - dev_err(&client->dev, "Unable to request gpio reset_pin\n"); + /* Named "CS" on the chip, DT binding is "reset" */ + bu21013_data->cs_gpiod = gpiod_get(&client->dev, "reset", + GPIOD_OUT_HIGH); + error = PTR_ERR_OR_ZERO(bu21013_data->cs_gpiod); + if (error) { + if (error != -EPROBE_DEFER) + dev_err(&client->dev, "failed to get CS GPIO\n"); goto err_disable_regulator; } + gpiod_set_consumer_name(bu21013_data->cs_gpiod, "BU21013 CS"); /* configure the touch panel controller */ error = bu21013_init_chip(bu21013_data); @@ -604,11 +588,14 @@ static int bu21013_probe(struct i2c_client *client, err_free_irq: bu21013_free_irq(bu21013_data); err_cs_disable: - bu21013_cs_disable(bu21013_data); + gpiod_set_value(bu21013_data->cs_gpiod, 0); + gpiod_put(bu21013_data->cs_gpiod); err_disable_regulator: regulator_disable(bu21013_data->regulator); err_put_regulator: regulator_put(bu21013_data->regulator); +err_put_int_gpio: + gpiod_put(bu21013_data->int_gpiod); err_free_mem: input_free_device(in_dev); kfree(bu21013_data); @@ -628,13 +615,16 @@ static int bu21013_remove(struct i2c_client *client) bu21013_free_irq(bu21013_data); - bu21013_cs_disable(bu21013_data); + gpiod_set_value(bu21013_data->cs_gpiod, 0); + gpiod_put(bu21013_data->cs_gpiod); input_unregister_device(bu21013_data->in_dev); regulator_disable(bu21013_data->regulator); regulator_put(bu21013_data->regulator); + gpiod_put(bu21013_data->int_gpiod); + kfree(bu21013_data); return 0; diff --git a/include/linux/input/bu21013.h b/include/linux/input/bu21013.h index 7e5b7e978e8a..58b1a9d44443 100644 --- a/include/linux/input/bu21013.h +++ b/include/linux/input/bu21013.h @@ -11,8 +11,6 @@ * struct bu21013_platform_device - Handle the platform data * @touch_x_max: touch x max * @touch_y_max: touch y max - * @cs_pin: chip select pin - * @touch_pin: touch gpio pin * @ext_clk: external clock flag * @x_flip: x flip flag * @y_flip: y flip flag @@ -23,8 +21,6 @@ struct bu21013_platform_device { int touch_x_max; int touch_y_max; - unsigned int cs_pin; - unsigned int touch_pin; bool ext_clk; bool x_flip; bool y_flip; -- cgit v1.2.3 From db3e34d4036db59cbacc1bff1c622b23d85b766b Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 9 Aug 2019 10:07:06 -0700 Subject: Input: bu21013_ts - use interrupt from I2C client Instead of trying to map INT GPIO to interrupt, let's use one supplied by I2C client. If there is none - bail. This will also allow us to treat INT GPIO as optional, as per the binding. Tested-by: Linus Walleij Signed-off-by: Dmitry Torokhov --- .../bindings/input/touchscreen/bu21013.txt | 6 +++- drivers/input/touchscreen/bu21013_ts.c | 35 ++++++++++++---------- 2 files changed, 24 insertions(+), 17 deletions(-) (limited to 'Documentation/devicetree') diff --git a/Documentation/devicetree/bindings/input/touchscreen/bu21013.txt b/Documentation/devicetree/bindings/input/touchscreen/bu21013.txt index 43899fc36ecf..7ddb5de8343d 100644 --- a/Documentation/devicetree/bindings/input/touchscreen/bu21013.txt +++ b/Documentation/devicetree/bindings/input/touchscreen/bu21013.txt @@ -4,6 +4,8 @@ Required properties: - compatible : "rohm,bu21013_tp" - reg : I2C device address - reset-gpios : GPIO pin enabling (selecting) chip (CS) + - interrupt-parent : the phandle for the gpio controller + - interrupts : (gpio) interrupt to which the chip is connected Optional properties: - touch-gpios : GPIO pin registering a touch event @@ -19,7 +21,9 @@ Example: bu21013_tp@5c { compatible = "rohm,bu21013_tp"; reg = <0x5c>; - touch-gpio = <&gpio2 20 0x4>; + interrupt-parent = <&gpio2>; + interrupts <&20 IRQ_TYPE_LEVEL_LOW>; + touch-gpio = <&gpio2 20 GPIO_ACTIVE_LOW>; avdd-supply = <&ab8500_ldo_aux1_reg>; rohm,touch-max-x = <384>; diff --git a/drivers/input/touchscreen/bu21013_ts.c b/drivers/input/touchscreen/bu21013_ts.c index f3b3e4c72c84..77ef0275c447 100644 --- a/drivers/input/touchscreen/bu21013_ts.c +++ b/drivers/input/touchscreen/bu21013_ts.c @@ -141,7 +141,6 @@ * @regulator: pointer to the Regulator used for touch screen * @cs_gpiod: chip select GPIO line * @int_gpiod: touch interrupt GPIO line - * @irq: interrupt number the device is using * @touch_x_max: maximum X coordinate reported by the device * @touch_y_max: maximum Y coordinate reported by the device * @x_flip: indicates that the driver should invert X coordinate before @@ -158,7 +157,6 @@ struct bu21013_ts { struct regulator *regulator; struct gpio_desc *cs_gpiod; struct gpio_desc *int_gpiod; - unsigned int irq; u32 touch_x_max; u32 touch_y_max; bool x_flip; @@ -252,7 +250,8 @@ static irqreturn_t bu21013_gpio_irq(int irq, void *device_data) if (unlikely(ts->touch_stopped)) break; - keep_polling = gpiod_get_value(ts->int_gpiod); + keep_polling = ts->int_gpiod ? + gpiod_get_value(ts->int_gpiod) : false; if (keep_polling) usleep_range(2000, 2500); } while (keep_polling); @@ -419,6 +418,11 @@ static int bu21013_probe(struct i2c_client *client, return -EIO; } + if (!client->irq) { + dev_err(&client->dev, "No IRQ set up\n"); + return -EINVAL; + } + ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); if (!ts) return -ENOMEM; @@ -491,14 +495,17 @@ static int bu21013_probe(struct i2c_client *client, } /* Named "INT" on the chip, DT binding is "touch" */ - ts->int_gpiod = devm_gpiod_get(&client->dev, "touch", GPIOD_IN); + ts->int_gpiod = devm_gpiod_get_optional(&client->dev, + "touch", GPIOD_IN); error = PTR_ERR_OR_ZERO(ts->int_gpiod); if (error) { if (error != -EPROBE_DEFER) dev_err(&client->dev, "failed to get INT GPIO\n"); return error; } - gpiod_set_consumer_name(ts->int_gpiod, "BU21013 INT"); + + if (ts->int_gpiod) + gpiod_set_consumer_name(ts->int_gpiod, "BU21013 INT"); /* configure the touch panel controller */ error = bu21013_init_chip(ts); @@ -507,16 +514,12 @@ static int bu21013_probe(struct i2c_client *client, return error; } - ts->irq = gpiod_to_irq(ts->int_gpiod); - error = devm_request_threaded_irq(&client->dev, ts->irq, + error = devm_request_threaded_irq(&client->dev, client->irq, NULL, bu21013_gpio_irq, - IRQF_TRIGGER_FALLING | - IRQF_SHARED | - IRQF_ONESHOT, - DRIVER_TP, ts); + IRQF_ONESHOT, DRIVER_TP, ts); if (error) { dev_err(&client->dev, "request irq %d failed\n", - ts->irq); + client->irq); return error; } @@ -549,9 +552,9 @@ static int __maybe_unused bu21013_suspend(struct device *dev) ts->touch_stopped = true; if (device_may_wakeup(&client->dev)) - enable_irq_wake(ts->irq); + enable_irq_wake(client->irq); else - disable_irq(ts->irq); + disable_irq(client->irq); regulator_disable(ts->regulator); @@ -579,9 +582,9 @@ static int __maybe_unused bu21013_resume(struct device *dev) ts->touch_stopped = false; if (device_may_wakeup(&client->dev)) - disable_irq_wake(ts->irq); + disable_irq_wake(client->irq); else - enable_irq(ts->irq); + enable_irq(client->irq); return 0; } -- cgit v1.2.3 From 4b6253fa736494346bab381114611e358afae545 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 9 Aug 2019 12:50:15 -0700 Subject: Input: bu21013_ts - switch to using standard touchscreen properties This switches the driver over to the standard touchscreen properties for coordinate transformation, while keeping old bindings working as well. Tested-by: Linus Walleij Signed-off-by: Dmitry Torokhov --- .../bindings/input/touchscreen/bu21013.txt | 16 +++++-- drivers/input/touchscreen/bu21013_ts.c | 54 +++++++++++++--------- 2 files changed, 46 insertions(+), 24 deletions(-) (limited to 'Documentation/devicetree') diff --git a/Documentation/devicetree/bindings/input/touchscreen/bu21013.txt b/Documentation/devicetree/bindings/input/touchscreen/bu21013.txt index 7ddb5de8343d..da4c9d8b99b1 100644 --- a/Documentation/devicetree/bindings/input/touchscreen/bu21013.txt +++ b/Documentation/devicetree/bindings/input/touchscreen/bu21013.txt @@ -10,6 +10,16 @@ Required properties: Optional properties: - touch-gpios : GPIO pin registering a touch event - -supply : Phandle to a regulator supply + - touchscreen-size-x : General touchscreen binding, see [1]. + - touchscreen-size-y : General touchscreen binding, see [1]. + - touchscreen-inverted-x : General touchscreen binding, see [1]. + - touchscreen-inverted-y : General touchscreen binding, see [1]. + - touchscreen-swapped-x-y : General touchscreen binding, see [1]. + +[1] All general touchscreen properties are described in + Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt. + +Deprecated properties: - rohm,touch-max-x : Maximum outward permitted limit in the X axis - rohm,touch-max-y : Maximum outward permitted limit in the Y axis - rohm,flip-x : Flip touch coordinates on the X axis @@ -26,8 +36,8 @@ Example: touch-gpio = <&gpio2 20 GPIO_ACTIVE_LOW>; avdd-supply = <&ab8500_ldo_aux1_reg>; - rohm,touch-max-x = <384>; - rohm,touch-max-y = <704>; - rohm,flip-y; + touchscreen-size-x = <384>; + touchscreen-size-y = <704>; + touchscreen-inverted-y; }; }; diff --git a/drivers/input/touchscreen/bu21013_ts.c b/drivers/input/touchscreen/bu21013_ts.c index 2bff3f3f4464..2f1f0d7607f8 100644 --- a/drivers/input/touchscreen/bu21013_ts.c +++ b/drivers/input/touchscreen/bu21013_ts.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -139,6 +140,7 @@ * struct bu21013_ts - touch panel data structure * @client: pointer to the i2c client * @in_dev: pointer to the input device structure + * @props: the device coordinate transformation properties * @regulator: pointer to the Regulator used for touch screen * @cs_gpiod: chip select GPIO line * @int_gpiod: touch interrupt GPIO line @@ -155,6 +157,7 @@ struct bu21013_ts { struct i2c_client *client; struct input_dev *in_dev; + struct touchscreen_properties props; struct regulator *regulator; struct gpio_desc *cs_gpiod; struct gpio_desc *int_gpiod; @@ -201,19 +204,13 @@ static int bu21013_do_touch_report(struct bu21013_ts *ts) for (i = 0; i < MAX_FINGERS; i++) { const u8 *data = &buf[4 * i + 3]; - struct input_mt_pos *p = &pos[finger_down_count]; + unsigned int x, y; - p->x = data[0] << SHIFT_2 | (data[1] & MASK_BITS); - p->y = data[2] << SHIFT_2 | (data[3] & MASK_BITS); - if (p->x == 0 || p->y == 0) - continue; - - finger_down_count++; - - if (ts->x_flip) - p->x = ts->touch_x_max - p->x; - if (ts->y_flip) - p->y = ts->touch_y_max - p->y; + x = data[0] << SHIFT_2 | (data[1] & MASK_BITS); + y = data[2] << SHIFT_2 | (data[3] & MASK_BITS); + if (x != 0 && y != 0) + touchscreen_set_mt_pos(&pos[finger_down_count++], + &ts->props, x, y); } if (finger_down_count == 2 && @@ -412,6 +409,8 @@ static int bu21013_probe(struct i2c_client *client, { struct bu21013_ts *ts; struct input_dev *in_dev; + struct input_absinfo *info; + u32 max_x = 0, max_y = 0; int error; if (!i2c_check_functionality(client->adapter, @@ -434,11 +433,6 @@ static int bu21013_probe(struct i2c_client *client, ts->x_flip = device_property_read_bool(&client->dev, "rohm,flip-x"); ts->y_flip = device_property_read_bool(&client->dev, "rohm,flip-y"); - device_property_read_u32(&client->dev, "rohm,touch-max-x", - &ts->touch_x_max); - device_property_read_u32(&client->dev, "rohm,touch-max-y", - &ts->touch_y_max); - in_dev = devm_input_allocate_device(&client->dev); if (!in_dev) { dev_err(&client->dev, "device memory alloc failed\n"); @@ -451,10 +445,28 @@ static int bu21013_probe(struct i2c_client *client, in_dev->name = DRIVER_TP; in_dev->id.bustype = BUS_I2C; - input_set_abs_params(in_dev, ABS_MT_POSITION_X, - 0, ts->touch_x_max, 0, 0); - input_set_abs_params(in_dev, ABS_MT_POSITION_Y, - 0, ts->touch_y_max, 0, 0); + device_property_read_u32(&client->dev, "rohm,touch-max-x", &max_x); + device_property_read_u32(&client->dev, "rohm,touch-max-y", &max_y); + + input_set_abs_params(in_dev, ABS_MT_POSITION_X, 0, max_x, 0, 0); + input_set_abs_params(in_dev, ABS_MT_POSITION_Y, 0, max_y, 0, 0); + + touchscreen_parse_properties(in_dev, true, &ts->props); + + /* Adjust for the legacy "flip" properties, if present */ + if (!ts->props.invert_x && + device_property_read_bool(&client->dev, "rohm,flip-x")) { + info = &in_dev->absinfo[ABS_MT_POSITION_X]; + info->maximum -= info->minimum; + info->minimum = 0; + } + + if (!ts->props.invert_y && + device_property_read_bool(&client->dev, "rohm,flip-y")) { + info = &in_dev->absinfo[ABS_MT_POSITION_Y]; + info->maximum -= info->minimum; + info->minimum = 0; + } error = input_mt_init_slots(in_dev, MAX_FINGERS, INPUT_MT_DIRECT | INPUT_MT_TRACK | -- cgit v1.2.3