* [PATCH 0/4] MMS114 touchscreen patches
@ 2018-01-24 19:38 Dmitry Torokhov
2018-01-24 19:38 ` [PATCH 1/4] Input: mms114 - do not clobber interrupt trigger Dmitry Torokhov
` (4 more replies)
0 siblings, 5 replies; 14+ messages in thread
From: Dmitry Torokhov @ 2018-01-24 19:38 UTC (permalink / raw)
To: Simon Shields, Andi Shyti; +Cc: Rob Herring, linux-input, linux-kernel
Hi,
This is a combination of couple of my patches + Simons patches dropping
support for platform data and adding support for mms152, slightly reworked.
Andi, because patches changed a bit I did not add your reviewed-by or
tested-by, please take another look.
Thanks!
Dmitry Torokhov (2):
Input: mms114 - do not clobber interrupt trigger
Input: mms114 - mark as direct input device
Simon Shields (2):
Input: mms114 - drop platform data and use generic APIs
Input: mms114 - add support for mms152
.../bindings/input/touchscreen/mms114.txt | 35 ++--
drivers/input/touchscreen/mms114.c | 229 ++++++++++++---------
include/linux/platform_data/mms114.h | 24 ---
3 files changed, 151 insertions(+), 137 deletions(-)
delete mode 100644 include/linux/platform_data/mms114.h
--
Dmitry
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 1/4] Input: mms114 - do not clobber interrupt trigger 2018-01-24 19:38 [PATCH 0/4] MMS114 touchscreen patches Dmitry Torokhov @ 2018-01-24 19:38 ` Dmitry Torokhov 2018-01-26 4:54 ` Andi Shyti 2018-01-24 19:38 ` [PATCH 2/4] Input: mms114 - mark as direct input device Dmitry Torokhov ` (3 subsequent siblings) 4 siblings, 1 reply; 14+ messages in thread From: Dmitry Torokhov @ 2018-01-24 19:38 UTC (permalink / raw) To: Simon Shields, Andi Shyti; +Cc: Rob Herring, linux-input, linux-kernel Rely on the platform (device tree, ACPI, etc) to properly configure interrupt trigger/polarity instead of hardcoding the falling edge. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> --- drivers/input/touchscreen/mms114.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c index e5eeb6311f7de..92f2e9da351f1 100644 --- a/drivers/input/touchscreen/mms114.c +++ b/drivers/input/touchscreen/mms114.c @@ -497,9 +497,9 @@ static int mms114_probe(struct i2c_client *client, return error; } - error = devm_request_threaded_irq(&client->dev, client->irq, NULL, - mms114_interrupt, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, - dev_name(&client->dev), data); + error = devm_request_threaded_irq(&client->dev, client->irq, + NULL, mms114_interrupt, IRQF_ONESHOT, + dev_name(&client->dev), data); if (error) { dev_err(&client->dev, "Failed to register interrupt\n"); return error; -- 2.16.0.rc1.238.g530d649a79-goog ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 1/4] Input: mms114 - do not clobber interrupt trigger 2018-01-24 19:38 ` [PATCH 1/4] Input: mms114 - do not clobber interrupt trigger Dmitry Torokhov @ 2018-01-26 4:54 ` Andi Shyti 0 siblings, 0 replies; 14+ messages in thread From: Andi Shyti @ 2018-01-26 4:54 UTC (permalink / raw) To: Dmitry Torokhov; +Cc: Simon Shields, Rob Herring, linux-input, linux-kernel Hi Dmitry, On Wed, Jan 24, 2018 at 11:38:01AM -0800, Dmitry Torokhov wrote: > Rely on the platform (device tree, ACPI, etc) to properly configure > interrupt trigger/polarity instead of hardcoding the falling edge. > > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Reviewed-by: Andi Shyti <andi.shyti@samsung.com> Tested-by: Andi Shyti <andi.shyti@samsung.com> Thanks, Andi ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 2/4] Input: mms114 - mark as direct input device 2018-01-24 19:38 [PATCH 0/4] MMS114 touchscreen patches Dmitry Torokhov 2018-01-24 19:38 ` [PATCH 1/4] Input: mms114 - do not clobber interrupt trigger Dmitry Torokhov @ 2018-01-24 19:38 ` Dmitry Torokhov 2018-01-26 4:55 ` Andi Shyti 2018-01-24 19:38 ` [PATCH 3/4] Input: mms114 - drop platform data and use generic APIs Dmitry Torokhov ` (2 subsequent siblings) 4 siblings, 1 reply; 14+ messages in thread From: Dmitry Torokhov @ 2018-01-24 19:38 UTC (permalink / raw) To: Simon Shields, Andi Shyti; +Cc: Rob Herring, linux-input, linux-kernel mms14 is a touchscreen and thus a direct input device; let's mark it as such. This also allows us to drop some initialization code as input_init_mt_slots() will do that for us. Also add error handling for input_mt_init_slots(). Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> --- drivers/input/touchscreen/mms114.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c index 92f2e9da351f1..c3480db5d21ed 100644 --- a/drivers/input/touchscreen/mms114.c +++ b/drivers/input/touchscreen/mms114.c @@ -462,14 +462,6 @@ static int mms114_probe(struct i2c_client *client, input_dev->open = mms114_input_open; input_dev->close = mms114_input_close; - __set_bit(EV_ABS, input_dev->evbit); - __set_bit(EV_KEY, input_dev->evbit); - __set_bit(BTN_TOUCH, input_dev->keybit); - input_set_abs_params(input_dev, ABS_X, 0, data->pdata->x_size, 0, 0); - input_set_abs_params(input_dev, ABS_Y, 0, data->pdata->y_size, 0, 0); - - /* For multi touch */ - input_mt_init_slots(input_dev, MMS114_MAX_TOUCH, 0); input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, MMS114_MAX_AREA, 0, 0); input_set_abs_params(input_dev, ABS_MT_POSITION_X, @@ -478,6 +470,11 @@ static int mms114_probe(struct i2c_client *client, 0, data->pdata->y_size, 0, 0); input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0); + error = input_mt_init_slots(input_dev, MMS114_MAX_TOUCH, + INPUT_MT_DIRECT); + if (error) + return error; + input_set_drvdata(input_dev, data); i2c_set_clientdata(client, data); -- 2.16.0.rc1.238.g530d649a79-goog ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 2/4] Input: mms114 - mark as direct input device 2018-01-24 19:38 ` [PATCH 2/4] Input: mms114 - mark as direct input device Dmitry Torokhov @ 2018-01-26 4:55 ` Andi Shyti 0 siblings, 0 replies; 14+ messages in thread From: Andi Shyti @ 2018-01-26 4:55 UTC (permalink / raw) To: Dmitry Torokhov; +Cc: Simon Shields, Rob Herring, linux-input, linux-kernel Hi Dmitry, On Wed, Jan 24, 2018 at 11:38:02AM -0800, Dmitry Torokhov wrote: > mms14 is a touchscreen and thus a direct input device; let's mark it > as such. This also allows us to drop some initialization code as > input_init_mt_slots() will do that for us. > > Also add error handling for input_mt_init_slots(). > > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Reviewed-by: Andi Shyti <andi.shyti@samsung.com> Tested-by: Andi Shyti <andi.shyti@samsung.com> Thanks, Andi ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 3/4] Input: mms114 - drop platform data and use generic APIs 2018-01-24 19:38 [PATCH 0/4] MMS114 touchscreen patches Dmitry Torokhov 2018-01-24 19:38 ` [PATCH 1/4] Input: mms114 - do not clobber interrupt trigger Dmitry Torokhov 2018-01-24 19:38 ` [PATCH 2/4] Input: mms114 - mark as direct input device Dmitry Torokhov @ 2018-01-24 19:38 ` Dmitry Torokhov 2018-01-26 5:06 ` Andi Shyti 2018-01-24 19:38 ` [PATCH 4/4] Input: mms114 - add support for mms152 Dmitry Torokhov 2018-01-25 13:01 ` [PATCH 0/4] MMS114 touchscreen patches Simon Shields 4 siblings, 1 reply; 14+ messages in thread From: Dmitry Torokhov @ 2018-01-24 19:38 UTC (permalink / raw) To: Simon Shields, Andi Shyti; +Cc: Rob Herring, linux-input, linux-kernel From: Simon Shields <simon@lineageos.org> The MMS114 platform data has no in-tree users, so drop it. Switch to using the standard touchscreen properties via touchscreen_parse_properties(), and move the old DT parsing code to use device_property_*() APIs. Finally, use touchscreen_report_pos to report x/y coordinates and drop the custom x/y inversion code. Signed-off-by: Simon Shields <simon@lineageos.org> Reviewed-by: Rob Herring <robh@kernel.org> Patchwork-Id: 10162101 Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> --- .../bindings/input/touchscreen/mms114.txt | 29 ++-- drivers/input/touchscreen/mms114.c | 147 +++++++++------------ include/linux/platform_data/mms114.h | 24 ---- 3 files changed, 82 insertions(+), 118 deletions(-) delete mode 100644 include/linux/platform_data/mms114.h diff --git a/Documentation/devicetree/bindings/input/touchscreen/mms114.txt b/Documentation/devicetree/bindings/input/touchscreen/mms114.txt index 89d4c56c56711..8f9f9f38eff4a 100644 --- a/Documentation/devicetree/bindings/input/touchscreen/mms114.txt +++ b/Documentation/devicetree/bindings/input/touchscreen/mms114.txt @@ -4,14 +4,18 @@ Required properties: - compatible: must be "melfas,mms114" - reg: I2C address of the chip - interrupts: interrupt to which the chip is connected -- x-size: horizontal resolution of touchscreen -- y-size: vertical resolution of touchscreen +- touchscreen-size-x: See [1] +- touchscreen-size-y: See [1] Optional properties: -- contact-threshold: -- moving-threshold: -- x-invert: invert X axis -- y-invert: invert Y axis +- touchscreen-fuzz-x: See [1] +- touchscreen-fuzz-y: See [1] +- touchscreen-fuzz-pressure: See [1] +- touchscreen-inverted-x: See [1] +- touchscreen-inverted-y: See [1] +- touchscreen-swapped-x-y: See [1] + +[1]: Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt Example: @@ -22,12 +26,13 @@ Example: compatible = "melfas,mms114"; reg = <0x48>; interrupts = <39 0>; - x-size = <720>; - y-size = <1280>; - contact-threshold = <10>; - moving-threshold = <10>; - x-invert; - y-invert; + touchscreen-size-x = <720>; + touchscreen-size-y = <1280>; + touchscreen-fuzz-x = <10>; + touchscreen-fuzz-y = <10>; + touchscreen-fuzz-pressure = <10>; + touchscreen-inverted-x; + touchscreen-inverted-y; }; /* ... */ diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c index c3480db5d21ed..69e4288bf8aa3 100644 --- a/drivers/input/touchscreen/mms114.c +++ b/drivers/input/touchscreen/mms114.c @@ -12,8 +12,8 @@ #include <linux/of.h> #include <linux/i2c.h> #include <linux/input/mt.h> +#include <linux/input/touchscreen.h> #include <linux/interrupt.h> -#include <linux/platform_data/mms114.h> #include <linux/regulator/consumer.h> #include <linux/slab.h> @@ -55,7 +55,9 @@ struct mms114_data { struct input_dev *input_dev; struct regulator *core_reg; struct regulator *io_reg; - const struct mms114_platform_data *pdata; + struct touchscreen_properties props; + unsigned int contact_threshold; + unsigned int moving_threshold; /* Use cache data for mode control register(write only) */ u8 cache_mode_control; @@ -143,7 +145,6 @@ static int mms114_write_reg(struct mms114_data *data, unsigned int reg, static void mms114_process_mt(struct mms114_data *data, struct mms114_touch *touch) { - const struct mms114_platform_data *pdata = data->pdata; struct i2c_client *client = data->client; struct input_dev *input_dev = data->input_dev; unsigned int id; @@ -163,16 +164,6 @@ static void mms114_process_mt(struct mms114_data *data, struct mms114_touch *tou id = touch->id - 1; x = touch->x_lo | touch->x_hi << 8; y = touch->y_lo | touch->y_hi << 8; - if (x > pdata->x_size || y > pdata->y_size) { - dev_dbg(&client->dev, - "Wrong touch coordinates (%d, %d)\n", x, y); - return; - } - - if (pdata->x_invert) - x = pdata->x_size - x; - if (pdata->y_invert) - y = pdata->y_size - y; dev_dbg(&client->dev, "id: %d, type: %d, pressed: %d, x: %d, y: %d, width: %d, strength: %d\n", @@ -183,9 +174,8 @@ static void mms114_process_mt(struct mms114_data *data, struct mms114_touch *tou input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, touch->pressed); if (touch->pressed) { + touchscreen_report_pos(input_dev, &data->props, x, y, true); input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, touch->width); - input_report_abs(input_dev, ABS_MT_POSITION_X, x); - input_report_abs(input_dev, ABS_MT_POSITION_Y, y); input_report_abs(input_dev, ABS_MT_PRESSURE, touch->strength); } } @@ -263,7 +253,7 @@ static int mms114_get_version(struct mms114_data *data) static int mms114_setup_regs(struct mms114_data *data) { - const struct mms114_platform_data *pdata = data->pdata; + const struct touchscreen_properties *props = &data->props; int val; int error; @@ -275,32 +265,32 @@ static int mms114_setup_regs(struct mms114_data *data) if (error < 0) return error; - val = (pdata->x_size >> 8) & 0xf; - val |= ((pdata->y_size >> 8) & 0xf) << 4; + val = (props->max_x >> 8) & 0xf; + val |= ((props->max_y >> 8) & 0xf) << 4; error = mms114_write_reg(data, MMS114_XY_RESOLUTION_H, val); if (error < 0) return error; - val = pdata->x_size & 0xff; + val = props->max_x & 0xff; error = mms114_write_reg(data, MMS114_X_RESOLUTION, val); if (error < 0) return error; - val = pdata->y_size & 0xff; + val = props->max_x & 0xff; error = mms114_write_reg(data, MMS114_Y_RESOLUTION, val); if (error < 0) return error; - if (pdata->contact_threshold) { + if (data->contact_threshold) { error = mms114_write_reg(data, MMS114_CONTACT_THRESHOLD, - pdata->contact_threshold); + data->contact_threshold); if (error < 0) return error; } - if (pdata->moving_threshold) { + if (data->moving_threshold) { error = mms114_write_reg(data, MMS114_MOVING_THRESHOLD, - pdata->moving_threshold); + data->moving_threshold); if (error < 0) return error; } @@ -335,9 +325,6 @@ static int mms114_start(struct mms114_data *data) return error; } - if (data->pdata->cfg_pin) - data->pdata->cfg_pin(true); - enable_irq(client->irq); return 0; @@ -350,9 +337,6 @@ static void mms114_stop(struct mms114_data *data) disable_irq(client->irq); - if (data->pdata->cfg_pin) - data->pdata->cfg_pin(false); - error = regulator_disable(data->io_reg); if (error) dev_warn(&client->dev, "Failed to disable vdd: %d\n", error); @@ -376,67 +360,43 @@ static void mms114_input_close(struct input_dev *dev) mms114_stop(data); } -#ifdef CONFIG_OF -static struct mms114_platform_data *mms114_parse_dt(struct device *dev) +static int mms114_parse_legacy_bindings(struct mms114_data *data) { - struct mms114_platform_data *pdata; - struct device_node *np = dev->of_node; - - if (!np) - return NULL; + struct device *dev = &data->client->dev; + struct touchscreen_properties *props = &data->props; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); - if (!pdata) { - dev_err(dev, "failed to allocate platform data\n"); - return NULL; + if (device_property_read_u32(dev, "x-size", &props->max_x)) { + dev_dbg(dev, "failed to get legacy x-size property\n"); + return -EINVAL; } - if (of_property_read_u32(np, "x-size", &pdata->x_size)) { - dev_err(dev, "failed to get x-size property\n"); - return NULL; + if (device_property_read_u32(dev, "y-size", &props->max_y)) { + dev_dbg(dev, "failed to get legacy y-size property\n"); + return -EINVAL; } - if (of_property_read_u32(np, "y-size", &pdata->y_size)) { - dev_err(dev, "failed to get y-size property\n"); - return NULL; - } + device_property_read_u32(dev, "contact-threshold", + &data->contact_threshold); + device_property_read_u32(dev, "moving-threshold", + &data->moving_threshold); - of_property_read_u32(np, "contact-threshold", - &pdata->contact_threshold); - of_property_read_u32(np, "moving-threshold", - &pdata->moving_threshold); + if (device_property_read_bool(dev, "x-invert")) + props->invert_x = true; + if (device_property_read_bool(dev, "y-invert")) + props->invert_y = true; - if (of_find_property(np, "x-invert", NULL)) - pdata->x_invert = true; - if (of_find_property(np, "y-invert", NULL)) - pdata->y_invert = true; + props->swap_x_y = false; - return pdata; -} -#else -static inline struct mms114_platform_data *mms114_parse_dt(struct device *dev) -{ - return NULL; + return 0; } -#endif static int mms114_probe(struct i2c_client *client, const struct i2c_device_id *id) { - const struct mms114_platform_data *pdata; struct mms114_data *data; struct input_dev *input_dev; int error; - pdata = dev_get_platdata(&client->dev); - if (!pdata) - pdata = mms114_parse_dt(&client->dev); - - if (!pdata) { - dev_err(&client->dev, "Need platform data\n"); - return -EINVAL; - } - if (!i2c_check_functionality(client->adapter, I2C_FUNC_PROTOCOL_MANGLING)) { dev_err(&client->dev, @@ -454,7 +414,38 @@ static int mms114_probe(struct i2c_client *client, data->client = client; data->input_dev = input_dev; - data->pdata = pdata; + + input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X); + input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y); + input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0); + input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, + 0, MMS114_MAX_AREA, 0, 0); + + touchscreen_parse_properties(input_dev, true, &data->props); + if (!data->props.max_x || !data->props.max_y) { + dev_dbg(&client->dev, + "missing X/Y size properties, trying legacy bindings\n"); + error = mms114_parse_legacy_bindings(data); + if (error) + return error; + + input_set_abs_params(input_dev, ABS_MT_POSITION_X, + 0, data->props.max_x, 0, 0); + input_set_abs_params(input_dev, ABS_MT_POSITION_Y, + 0, data->props.max_y, 0, 0); + } + + /* + * The firmware handles movement and pressure fuzz, so + * don't duplicate that in software. + */ + data->moving_threshold = input_abs_get_fuzz(input_dev, + ABS_MT_POSITION_X); + data->contact_threshold = input_abs_get_fuzz(input_dev, + ABS_MT_PRESSURE); + input_abs_set_fuzz(input_dev, ABS_MT_POSITION_X, 0); + input_abs_set_fuzz(input_dev, ABS_MT_POSITION_Y, 0); + input_abs_set_fuzz(input_dev, ABS_MT_PRESSURE, 0); input_dev->name = "MELFAS MMS114 Touchscreen"; input_dev->id.bustype = BUS_I2C; @@ -462,14 +453,6 @@ static int mms114_probe(struct i2c_client *client, input_dev->open = mms114_input_open; input_dev->close = mms114_input_close; - input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, - 0, MMS114_MAX_AREA, 0, 0); - input_set_abs_params(input_dev, ABS_MT_POSITION_X, - 0, data->pdata->x_size, 0, 0); - input_set_abs_params(input_dev, ABS_MT_POSITION_Y, - 0, data->pdata->y_size, 0, 0); - input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0); - error = input_mt_init_slots(input_dev, MMS114_MAX_TOUCH, INPUT_MT_DIRECT); if (error) diff --git a/include/linux/platform_data/mms114.h b/include/linux/platform_data/mms114.h deleted file mode 100644 index 5722ebfb27382..0000000000000 --- a/include/linux/platform_data/mms114.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2012 Samsung Electronics Co.Ltd - * Author: Joonyoung Shim <jy0922.shim@samsung.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundationr - */ - -#ifndef __LINUX_MMS114_H -#define __LINUX_MMS114_H - -struct mms114_platform_data { - unsigned int x_size; - unsigned int y_size; - unsigned int contact_threshold; - unsigned int moving_threshold; - bool x_invert; - bool y_invert; - - void (*cfg_pin)(bool); -}; - -#endif /* __LINUX_MMS114_H */ -- 2.16.0.rc1.238.g530d649a79-goog ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 3/4] Input: mms114 - drop platform data and use generic APIs 2018-01-24 19:38 ` [PATCH 3/4] Input: mms114 - drop platform data and use generic APIs Dmitry Torokhov @ 2018-01-26 5:06 ` Andi Shyti 0 siblings, 0 replies; 14+ messages in thread From: Andi Shyti @ 2018-01-26 5:06 UTC (permalink / raw) To: Dmitry Torokhov; +Cc: Simon Shields, Rob Herring, linux-input, linux-kernel Hi Simon and Dmitry, On Wed, Jan 24, 2018 at 11:38:03AM -0800, Dmitry Torokhov wrote: > From: Simon Shields <simon@lineageos.org> > > The MMS114 platform data has no in-tree users, so drop it. > > Switch to using the standard touchscreen properties via > touchscreen_parse_properties(), and move the old DT parsing code > to use device_property_*() APIs. > > Finally, use touchscreen_report_pos to report x/y coordinates > and drop the custom x/y inversion code. > > Signed-off-by: Simon Shields <simon@lineageos.org> > Reviewed-by: Rob Herring <robh@kernel.org> > Patchwork-Id: 10162101 > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> yes, looks better. I'm happy you dropped the (mms114_parse_dt(data) < 0). Reviewed-by: Andi Shyti <andi.shyti@samsung.com> Tested-by: Andi Shyti <andi.shyti@samsung.com> Thanks, Andi > --- > .../bindings/input/touchscreen/mms114.txt | 29 ++-- > drivers/input/touchscreen/mms114.c | 147 +++++++++------------ > include/linux/platform_data/mms114.h | 24 ---- > 3 files changed, 82 insertions(+), 118 deletions(-) > delete mode 100644 include/linux/platform_data/mms114.h > > diff --git a/Documentation/devicetree/bindings/input/touchscreen/mms114.txt b/Documentation/devicetree/bindings/input/touchscreen/mms114.txt > index 89d4c56c56711..8f9f9f38eff4a 100644 > --- a/Documentation/devicetree/bindings/input/touchscreen/mms114.txt > +++ b/Documentation/devicetree/bindings/input/touchscreen/mms114.txt > @@ -4,14 +4,18 @@ Required properties: > - compatible: must be "melfas,mms114" > - reg: I2C address of the chip > - interrupts: interrupt to which the chip is connected > -- x-size: horizontal resolution of touchscreen > -- y-size: vertical resolution of touchscreen > +- touchscreen-size-x: See [1] > +- touchscreen-size-y: See [1] > > Optional properties: > -- contact-threshold: > -- moving-threshold: > -- x-invert: invert X axis > -- y-invert: invert Y axis > +- touchscreen-fuzz-x: See [1] > +- touchscreen-fuzz-y: See [1] > +- touchscreen-fuzz-pressure: See [1] > +- touchscreen-inverted-x: See [1] > +- touchscreen-inverted-y: See [1] > +- touchscreen-swapped-x-y: See [1] > + > +[1]: Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt > > Example: > > @@ -22,12 +26,13 @@ Example: > compatible = "melfas,mms114"; > reg = <0x48>; > interrupts = <39 0>; > - x-size = <720>; > - y-size = <1280>; > - contact-threshold = <10>; > - moving-threshold = <10>; > - x-invert; > - y-invert; > + touchscreen-size-x = <720>; > + touchscreen-size-y = <1280>; > + touchscreen-fuzz-x = <10>; > + touchscreen-fuzz-y = <10>; > + touchscreen-fuzz-pressure = <10>; > + touchscreen-inverted-x; > + touchscreen-inverted-y; > }; > > /* ... */ > diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c > index c3480db5d21ed..69e4288bf8aa3 100644 > --- a/drivers/input/touchscreen/mms114.c > +++ b/drivers/input/touchscreen/mms114.c > @@ -12,8 +12,8 @@ > #include <linux/of.h> > #include <linux/i2c.h> > #include <linux/input/mt.h> > +#include <linux/input/touchscreen.h> > #include <linux/interrupt.h> > -#include <linux/platform_data/mms114.h> > #include <linux/regulator/consumer.h> > #include <linux/slab.h> > > @@ -55,7 +55,9 @@ struct mms114_data { > struct input_dev *input_dev; > struct regulator *core_reg; > struct regulator *io_reg; > - const struct mms114_platform_data *pdata; > + struct touchscreen_properties props; > + unsigned int contact_threshold; > + unsigned int moving_threshold; > > /* Use cache data for mode control register(write only) */ > u8 cache_mode_control; > @@ -143,7 +145,6 @@ static int mms114_write_reg(struct mms114_data *data, unsigned int reg, > > static void mms114_process_mt(struct mms114_data *data, struct mms114_touch *touch) > { > - const struct mms114_platform_data *pdata = data->pdata; > struct i2c_client *client = data->client; > struct input_dev *input_dev = data->input_dev; > unsigned int id; > @@ -163,16 +164,6 @@ static void mms114_process_mt(struct mms114_data *data, struct mms114_touch *tou > id = touch->id - 1; > x = touch->x_lo | touch->x_hi << 8; > y = touch->y_lo | touch->y_hi << 8; > - if (x > pdata->x_size || y > pdata->y_size) { > - dev_dbg(&client->dev, > - "Wrong touch coordinates (%d, %d)\n", x, y); > - return; > - } > - > - if (pdata->x_invert) > - x = pdata->x_size - x; > - if (pdata->y_invert) > - y = pdata->y_size - y; > > dev_dbg(&client->dev, > "id: %d, type: %d, pressed: %d, x: %d, y: %d, width: %d, strength: %d\n", > @@ -183,9 +174,8 @@ static void mms114_process_mt(struct mms114_data *data, struct mms114_touch *tou > input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, touch->pressed); > > if (touch->pressed) { > + touchscreen_report_pos(input_dev, &data->props, x, y, true); > input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, touch->width); > - input_report_abs(input_dev, ABS_MT_POSITION_X, x); > - input_report_abs(input_dev, ABS_MT_POSITION_Y, y); > input_report_abs(input_dev, ABS_MT_PRESSURE, touch->strength); > } > } > @@ -263,7 +253,7 @@ static int mms114_get_version(struct mms114_data *data) > > static int mms114_setup_regs(struct mms114_data *data) > { > - const struct mms114_platform_data *pdata = data->pdata; > + const struct touchscreen_properties *props = &data->props; > int val; > int error; > > @@ -275,32 +265,32 @@ static int mms114_setup_regs(struct mms114_data *data) > if (error < 0) > return error; > > - val = (pdata->x_size >> 8) & 0xf; > - val |= ((pdata->y_size >> 8) & 0xf) << 4; > + val = (props->max_x >> 8) & 0xf; > + val |= ((props->max_y >> 8) & 0xf) << 4; > error = mms114_write_reg(data, MMS114_XY_RESOLUTION_H, val); > if (error < 0) > return error; > > - val = pdata->x_size & 0xff; > + val = props->max_x & 0xff; > error = mms114_write_reg(data, MMS114_X_RESOLUTION, val); > if (error < 0) > return error; > > - val = pdata->y_size & 0xff; > + val = props->max_x & 0xff; > error = mms114_write_reg(data, MMS114_Y_RESOLUTION, val); > if (error < 0) > return error; > > - if (pdata->contact_threshold) { > + if (data->contact_threshold) { > error = mms114_write_reg(data, MMS114_CONTACT_THRESHOLD, > - pdata->contact_threshold); > + data->contact_threshold); > if (error < 0) > return error; > } > > - if (pdata->moving_threshold) { > + if (data->moving_threshold) { > error = mms114_write_reg(data, MMS114_MOVING_THRESHOLD, > - pdata->moving_threshold); > + data->moving_threshold); > if (error < 0) > return error; > } > @@ -335,9 +325,6 @@ static int mms114_start(struct mms114_data *data) > return error; > } > > - if (data->pdata->cfg_pin) > - data->pdata->cfg_pin(true); > - > enable_irq(client->irq); > > return 0; > @@ -350,9 +337,6 @@ static void mms114_stop(struct mms114_data *data) > > disable_irq(client->irq); > > - if (data->pdata->cfg_pin) > - data->pdata->cfg_pin(false); > - > error = regulator_disable(data->io_reg); > if (error) > dev_warn(&client->dev, "Failed to disable vdd: %d\n", error); > @@ -376,67 +360,43 @@ static void mms114_input_close(struct input_dev *dev) > mms114_stop(data); > } > > -#ifdef CONFIG_OF > -static struct mms114_platform_data *mms114_parse_dt(struct device *dev) > +static int mms114_parse_legacy_bindings(struct mms114_data *data) > { > - struct mms114_platform_data *pdata; > - struct device_node *np = dev->of_node; > - > - if (!np) > - return NULL; > + struct device *dev = &data->client->dev; > + struct touchscreen_properties *props = &data->props; > > - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); > - if (!pdata) { > - dev_err(dev, "failed to allocate platform data\n"); > - return NULL; > + if (device_property_read_u32(dev, "x-size", &props->max_x)) { > + dev_dbg(dev, "failed to get legacy x-size property\n"); > + return -EINVAL; > } > > - if (of_property_read_u32(np, "x-size", &pdata->x_size)) { > - dev_err(dev, "failed to get x-size property\n"); > - return NULL; > + if (device_property_read_u32(dev, "y-size", &props->max_y)) { > + dev_dbg(dev, "failed to get legacy y-size property\n"); > + return -EINVAL; > } > > - if (of_property_read_u32(np, "y-size", &pdata->y_size)) { > - dev_err(dev, "failed to get y-size property\n"); > - return NULL; > - } > + device_property_read_u32(dev, "contact-threshold", > + &data->contact_threshold); > + device_property_read_u32(dev, "moving-threshold", > + &data->moving_threshold); > > - of_property_read_u32(np, "contact-threshold", > - &pdata->contact_threshold); > - of_property_read_u32(np, "moving-threshold", > - &pdata->moving_threshold); > + if (device_property_read_bool(dev, "x-invert")) > + props->invert_x = true; > + if (device_property_read_bool(dev, "y-invert")) > + props->invert_y = true; > > - if (of_find_property(np, "x-invert", NULL)) > - pdata->x_invert = true; > - if (of_find_property(np, "y-invert", NULL)) > - pdata->y_invert = true; > + props->swap_x_y = false; > > - return pdata; > -} > -#else > -static inline struct mms114_platform_data *mms114_parse_dt(struct device *dev) > -{ > - return NULL; > + return 0; > } > -#endif > > static int mms114_probe(struct i2c_client *client, > const struct i2c_device_id *id) > { > - const struct mms114_platform_data *pdata; > struct mms114_data *data; > struct input_dev *input_dev; > int error; > > - pdata = dev_get_platdata(&client->dev); > - if (!pdata) > - pdata = mms114_parse_dt(&client->dev); > - > - if (!pdata) { > - dev_err(&client->dev, "Need platform data\n"); > - return -EINVAL; > - } > - > if (!i2c_check_functionality(client->adapter, > I2C_FUNC_PROTOCOL_MANGLING)) { > dev_err(&client->dev, > @@ -454,7 +414,38 @@ static int mms114_probe(struct i2c_client *client, > > data->client = client; > data->input_dev = input_dev; > - data->pdata = pdata; > + > + input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X); > + input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y); > + input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0); > + input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, > + 0, MMS114_MAX_AREA, 0, 0); > + > + touchscreen_parse_properties(input_dev, true, &data->props); > + if (!data->props.max_x || !data->props.max_y) { > + dev_dbg(&client->dev, > + "missing X/Y size properties, trying legacy bindings\n"); > + error = mms114_parse_legacy_bindings(data); > + if (error) > + return error; > + > + input_set_abs_params(input_dev, ABS_MT_POSITION_X, > + 0, data->props.max_x, 0, 0); > + input_set_abs_params(input_dev, ABS_MT_POSITION_Y, > + 0, data->props.max_y, 0, 0); > + } > + > + /* > + * The firmware handles movement and pressure fuzz, so > + * don't duplicate that in software. > + */ > + data->moving_threshold = input_abs_get_fuzz(input_dev, > + ABS_MT_POSITION_X); > + data->contact_threshold = input_abs_get_fuzz(input_dev, > + ABS_MT_PRESSURE); > + input_abs_set_fuzz(input_dev, ABS_MT_POSITION_X, 0); > + input_abs_set_fuzz(input_dev, ABS_MT_POSITION_Y, 0); > + input_abs_set_fuzz(input_dev, ABS_MT_PRESSURE, 0); > > input_dev->name = "MELFAS MMS114 Touchscreen"; > input_dev->id.bustype = BUS_I2C; > @@ -462,14 +453,6 @@ static int mms114_probe(struct i2c_client *client, > input_dev->open = mms114_input_open; > input_dev->close = mms114_input_close; > > - input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, > - 0, MMS114_MAX_AREA, 0, 0); > - input_set_abs_params(input_dev, ABS_MT_POSITION_X, > - 0, data->pdata->x_size, 0, 0); > - input_set_abs_params(input_dev, ABS_MT_POSITION_Y, > - 0, data->pdata->y_size, 0, 0); > - input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0); > - > error = input_mt_init_slots(input_dev, MMS114_MAX_TOUCH, > INPUT_MT_DIRECT); > if (error) > diff --git a/include/linux/platform_data/mms114.h b/include/linux/platform_data/mms114.h > deleted file mode 100644 > index 5722ebfb27382..0000000000000 > --- a/include/linux/platform_data/mms114.h > +++ /dev/null > @@ -1,24 +0,0 @@ > -/* > - * Copyright (C) 2012 Samsung Electronics Co.Ltd > - * Author: Joonyoung Shim <jy0922.shim@samsung.com> > - * > - * This program is free software; you can redistribute it and/or modify > - * it under the terms of the GNU General Public License version 2 as > - * published by the Free Software Foundationr > - */ > - > -#ifndef __LINUX_MMS114_H > -#define __LINUX_MMS114_H > - > -struct mms114_platform_data { > - unsigned int x_size; > - unsigned int y_size; > - unsigned int contact_threshold; > - unsigned int moving_threshold; > - bool x_invert; > - bool y_invert; > - > - void (*cfg_pin)(bool); > -}; > - > -#endif /* __LINUX_MMS114_H */ > -- > 2.16.0.rc1.238.g530d649a79-goog > > ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 4/4] Input: mms114 - add support for mms152 2018-01-24 19:38 [PATCH 0/4] MMS114 touchscreen patches Dmitry Torokhov ` (2 preceding siblings ...) 2018-01-24 19:38 ` [PATCH 3/4] Input: mms114 - drop platform data and use generic APIs Dmitry Torokhov @ 2018-01-24 19:38 ` Dmitry Torokhov 2018-01-24 20:04 ` Marcus Folkesson 2018-01-25 13:01 ` [PATCH 0/4] MMS114 touchscreen patches Simon Shields 4 siblings, 1 reply; 14+ messages in thread From: Dmitry Torokhov @ 2018-01-24 19:38 UTC (permalink / raw) To: Simon Shields, Andi Shyti; +Cc: Rob Herring, linux-input, linux-kernel From: Simon Shields <simon@lineageos.org> MMS152 has no configuration registers, but the packet format used in interrupts is identical to mms114. Signed-off-by: Simon Shields <simon@lineageos.org> Patchwork-Id: 10125841 Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> --- .../bindings/input/touchscreen/mms114.txt | 6 +- drivers/input/touchscreen/mms114.c | 89 +++++++++++++++++----- 2 files changed, 74 insertions(+), 21 deletions(-) diff --git a/Documentation/devicetree/bindings/input/touchscreen/mms114.txt b/Documentation/devicetree/bindings/input/touchscreen/mms114.txt index 8f9f9f38eff4a..2cd954051d299 100644 --- a/Documentation/devicetree/bindings/input/touchscreen/mms114.txt +++ b/Documentation/devicetree/bindings/input/touchscreen/mms114.txt @@ -1,7 +1,9 @@ -* MELFAS MMS114 touchscreen controller +* MELFAS MMS114/MMS152 touchscreen controller Required properties: -- compatible: must be "melfas,mms114" +- compatible: should be one of: + - "melfas,mms114" + - "melfas,mms152" - reg: I2C address of the chip - interrupts: interrupt to which the chip is connected - touchscreen-size-x: See [1] diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c index 69e4288bf8aa3..06d4ce9a3e547 100644 --- a/drivers/input/touchscreen/mms114.c +++ b/drivers/input/touchscreen/mms114.c @@ -10,6 +10,7 @@ #include <linux/module.h> #include <linux/delay.h> #include <linux/of.h> +#include <linux/of_device.h> #include <linux/i2c.h> #include <linux/input/mt.h> #include <linux/input/touchscreen.h> @@ -33,6 +34,9 @@ #define MMS114_INFOMATION 0x10 #define MMS114_TSP_REV 0xF0 +#define MMS152_FW_REV 0xE1 +#define MMS152_COMPAT_GROUP 0xF2 + /* Minimum delay time is 50us between stop and start signal of i2c */ #define MMS114_I2C_DELAY 50 @@ -50,12 +54,18 @@ #define MMS114_TYPE_TOUCHSCREEN 1 #define MMS114_TYPE_TOUCHKEY 2 +enum mms_type { + TYPE_MMS114 = 114, + TYPE_MMS152 = 152, +}; + struct mms114_data { struct i2c_client *client; struct input_dev *input_dev; struct regulator *core_reg; struct regulator *io_reg; struct touchscreen_properties props; + enum mms_type type; unsigned int contact_threshold; unsigned int moving_threshold; @@ -241,12 +251,28 @@ static int mms114_get_version(struct mms114_data *data) u8 buf[6]; int error; - error = __mms114_read_reg(data, MMS114_TSP_REV, 6, buf); - if (error < 0) - return error; + switch (data->type) { + case TYPE_MMS152: + error = __mms114_read_reg(data, MMS152_FW_REV, 3, buf); + if (error) + return error; + buf[3] = i2c_smbus_read_byte_data(data->client, + MMS152_COMPAT_GROUP); + if (buf[3] < 0) + return buf[3]; + dev_info(dev, "TSP FW Rev: bootloader 0x%x / core 0x%x / config 0x%x, Compat group: %c\n", + buf[0], buf[1], buf[2], buf[3]); + break; + + case TYPE_MMS114: + error = __mms114_read_reg(data, MMS114_TSP_REV, 6, buf); + if (error) + return error; - dev_info(dev, "TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n", - buf[0], buf[1], buf[3]); + dev_info(dev, "TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n", + buf[0], buf[1], buf[3]); + break; + } return 0; } @@ -261,6 +287,10 @@ static int mms114_setup_regs(struct mms114_data *data) if (error < 0) return error; + /* MMS152 has no configuration or power on registers */ + if (data->type == TYPE_MMS152) + return 0; + error = mms114_set_active(data, true); if (error < 0) return error; @@ -395,6 +425,7 @@ static int mms114_probe(struct i2c_client *client, { struct mms114_data *data; struct input_dev *input_dev; + const void *match_data; int error; if (!i2c_check_functionality(client->adapter, @@ -415,6 +446,13 @@ static int mms114_probe(struct i2c_client *client, data->client = client; data->input_dev = input_dev; + /* FIXME: switch to device_get_match_data() when available */ + match_data = of_device_get_match_data(&client->dev); + if (!match_data) + return -EINVAL; + + data->type = (enum mms_type)match_data; + input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X); input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y); input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0); @@ -435,19 +473,26 @@ static int mms114_probe(struct i2c_client *client, 0, data->props.max_y, 0, 0); } - /* - * The firmware handles movement and pressure fuzz, so - * don't duplicate that in software. - */ - data->moving_threshold = input_abs_get_fuzz(input_dev, - ABS_MT_POSITION_X); - data->contact_threshold = input_abs_get_fuzz(input_dev, - ABS_MT_PRESSURE); - input_abs_set_fuzz(input_dev, ABS_MT_POSITION_X, 0); - input_abs_set_fuzz(input_dev, ABS_MT_POSITION_Y, 0); - input_abs_set_fuzz(input_dev, ABS_MT_PRESSURE, 0); - - input_dev->name = "MELFAS MMS114 Touchscreen"; + if (data->type == TYPE_MMS114) { + /* + * The firmware handles movement and pressure fuzz, so + * don't duplicate that in software. + */ + data->moving_threshold = input_abs_get_fuzz(input_dev, + ABS_MT_POSITION_X); + data->contact_threshold = input_abs_get_fuzz(input_dev, + ABS_MT_PRESSURE); + input_abs_set_fuzz(input_dev, ABS_MT_POSITION_X, 0); + input_abs_set_fuzz(input_dev, ABS_MT_POSITION_Y, 0); + input_abs_set_fuzz(input_dev, ABS_MT_PRESSURE, 0); + } + + input_dev->name = devm_kasprintf(&client->dev, GFP_KERNEL, + "MELFAS MMS%d Touchscreen", + data->type); + if (!input_dev->name) + return -ENOMEM; + input_dev->id.bustype = BUS_I2C; input_dev->dev.parent = &client->dev; input_dev->open = mms114_input_open; @@ -549,7 +594,13 @@ MODULE_DEVICE_TABLE(i2c, mms114_id); #ifdef CONFIG_OF static const struct of_device_id mms114_dt_match[] = { - { .compatible = "melfas,mms114" }, + { + .compatible = "melfas,mms114", + .data = (void *)TYPE_MMS114, + }, { + .compatible = "melfas,mms152", + .data = (void *)TYPE_MMS152, + }, { } }; MODULE_DEVICE_TABLE(of, mms114_dt_match); -- 2.16.0.rc1.238.g530d649a79-goog ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 4/4] Input: mms114 - add support for mms152 2018-01-24 19:38 ` [PATCH 4/4] Input: mms114 - add support for mms152 Dmitry Torokhov @ 2018-01-24 20:04 ` Marcus Folkesson 2018-01-24 21:27 ` Dmitry Torokhov 2018-01-24 21:32 ` [PATCH 4/4 v2] " Dmitry Torokhov 0 siblings, 2 replies; 14+ messages in thread From: Marcus Folkesson @ 2018-01-24 20:04 UTC (permalink / raw) To: Dmitry Torokhov Cc: Simon Shields, Andi Shyti, Rob Herring, linux-input, linux-kernel [-- Attachment #1: Type: text/plain, Size: 1371 bytes --] Hello Dmitry, On Wed, Jan 24, 2018 at 11:38:04AM -0800, Dmitry Torokhov wrote: > From: Simon Shields <simon@lineageos.org> > > @@ -241,12 +251,28 @@ static int mms114_get_version(struct mms114_data *data) > u8 buf[6]; > int error; > > - error = __mms114_read_reg(data, MMS114_TSP_REV, 6, buf); > - if (error < 0) > - return error; > + switch (data->type) { > + case TYPE_MMS152: > + error = __mms114_read_reg(data, MMS152_FW_REV, 3, buf); > + if (error) > + return error; > + buf[3] = i2c_smbus_read_byte_data(data->client, > + MMS152_COMPAT_GROUP); > + if (buf[3] < 0) > + return buf[3]; buf is unsigned. Maybe error = i2c_smbus_read_byte_data(data->client, MMS152_COMPAT_GROUP); if (error < 0) return error; Instead? > + dev_info(dev, "TSP FW Rev: bootloader 0x%x / core 0x%x / config 0x%x, Compat group: %c\n", > + buf[0], buf[1], buf[2], buf[3]); > + break; > + > + case TYPE_MMS114: > + error = __mms114_read_reg(data, MMS114_TSP_REV, 6, buf); > + if (error) > + return error; > > - dev_info(dev, "TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n", > - buf[0], buf[1], buf[3]); > + dev_info(dev, "TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n", > + buf[0], buf[1], buf[3]); > + break; > + } > > return 0; > } Best regards Marcus Folkesson [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 4/4] Input: mms114 - add support for mms152 2018-01-24 20:04 ` Marcus Folkesson @ 2018-01-24 21:27 ` Dmitry Torokhov 2018-01-24 21:32 ` [PATCH 4/4 v2] " Dmitry Torokhov 1 sibling, 0 replies; 14+ messages in thread From: Dmitry Torokhov @ 2018-01-24 21:27 UTC (permalink / raw) To: Marcus Folkesson Cc: Simon Shields, Andi Shyti, Rob Herring, linux-input, linux-kernel On Wed, Jan 24, 2018 at 09:04:08PM +0100, Marcus Folkesson wrote: > Hello Dmitry, > > On Wed, Jan 24, 2018 at 11:38:04AM -0800, Dmitry Torokhov wrote: > > From: Simon Shields <simon@lineageos.org> > > > > @@ -241,12 +251,28 @@ static int mms114_get_version(struct mms114_data *data) > > u8 buf[6]; > > int error; > > > > - error = __mms114_read_reg(data, MMS114_TSP_REV, 6, buf); > > - if (error < 0) > > - return error; > > + switch (data->type) { > > + case TYPE_MMS152: > > + error = __mms114_read_reg(data, MMS152_FW_REV, 3, buf); > > + if (error) > > + return error; > > + buf[3] = i2c_smbus_read_byte_data(data->client, > > + MMS152_COMPAT_GROUP); > > + if (buf[3] < 0) > > + return buf[3]; > > buf is unsigned. > > Maybe > error = i2c_smbus_read_byte_data(data->client, > MMS152_COMPAT_GROUP); > if (error < 0) > return error; > Instead? Good catch. I think I'd rather have a separate variable "group" for this. Thank you. > > > > + dev_info(dev, "TSP FW Rev: bootloader 0x%x / core 0x%x / config 0x%x, Compat group: %c\n", > > + buf[0], buf[1], buf[2], buf[3]); > > + break; > > + > > + case TYPE_MMS114: > > + error = __mms114_read_reg(data, MMS114_TSP_REV, 6, buf); > > + if (error) > > + return error; > > > > - dev_info(dev, "TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n", > > - buf[0], buf[1], buf[3]); > > + dev_info(dev, "TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n", > > + buf[0], buf[1], buf[3]); > > + break; > > + } > > > > return 0; > > } > > > Best regards > Marcus Folkesson -- Dmitry ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 4/4 v2] Input: mms114 - add support for mms152 2018-01-24 20:04 ` Marcus Folkesson 2018-01-24 21:27 ` Dmitry Torokhov @ 2018-01-24 21:32 ` Dmitry Torokhov 2018-01-26 5:14 ` Andi Shyti 1 sibling, 1 reply; 14+ messages in thread From: Dmitry Torokhov @ 2018-01-24 21:32 UTC (permalink / raw) To: Marcus Folkesson Cc: Simon Shields, Andi Shyti, Rob Herring, linux-input, linux-kernel From: Simon Shields <simon@lineageos.org> MMS152 has no configuration registers, but the packet format used in interrupts is identical to mms114. Signed-off-by: Simon Shields <simon@lineageos.org> Patchwork-Id: 10125841 Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> --- V2: Fixed issue pointed by Marcus Folkesson. .../bindings/input/touchscreen/mms114.txt | 6 + drivers/input/touchscreen/mms114.c | 92 ++++++++++++++++---- 2 files changed, 77 insertions(+), 21 deletions(-) diff --git a/Documentation/devicetree/bindings/input/touchscreen/mms114.txt b/Documentation/devicetree/bindings/input/touchscreen/mms114.txt index 8f9f9f38eff4a..2cd954051d299 100644 --- a/Documentation/devicetree/bindings/input/touchscreen/mms114.txt +++ b/Documentation/devicetree/bindings/input/touchscreen/mms114.txt @@ -1,7 +1,9 @@ -* MELFAS MMS114 touchscreen controller +* MELFAS MMS114/MMS152 touchscreen controller Required properties: -- compatible: must be "melfas,mms114" +- compatible: should be one of: + - "melfas,mms114" + - "melfas,mms152" - reg: I2C address of the chip - interrupts: interrupt to which the chip is connected - touchscreen-size-x: See [1] diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c index 69e4288bf8aa3..c54f4afe11037 100644 --- a/drivers/input/touchscreen/mms114.c +++ b/drivers/input/touchscreen/mms114.c @@ -10,6 +10,7 @@ #include <linux/module.h> #include <linux/delay.h> #include <linux/of.h> +#include <linux/of_device.h> #include <linux/i2c.h> #include <linux/input/mt.h> #include <linux/input/touchscreen.h> @@ -33,6 +34,9 @@ #define MMS114_INFOMATION 0x10 #define MMS114_TSP_REV 0xF0 +#define MMS152_FW_REV 0xE1 +#define MMS152_COMPAT_GROUP 0xF2 + /* Minimum delay time is 50us between stop and start signal of i2c */ #define MMS114_I2C_DELAY 50 @@ -50,12 +54,18 @@ #define MMS114_TYPE_TOUCHSCREEN 1 #define MMS114_TYPE_TOUCHKEY 2 +enum mms_type { + TYPE_MMS114 = 114, + TYPE_MMS152 = 152, +}; + struct mms114_data { struct i2c_client *client; struct input_dev *input_dev; struct regulator *core_reg; struct regulator *io_reg; struct touchscreen_properties props; + enum mms_type type; unsigned int contact_threshold; unsigned int moving_threshold; @@ -239,14 +249,33 @@ static int mms114_get_version(struct mms114_data *data) { struct device *dev = &data->client->dev; u8 buf[6]; + int group; int error; - error = __mms114_read_reg(data, MMS114_TSP_REV, 6, buf); - if (error < 0) - return error; + switch (data->type) { + case TYPE_MMS152: + error = __mms114_read_reg(data, MMS152_FW_REV, 3, buf); + if (error) + return error; + + group = i2c_smbus_read_byte_data(data->client, + MMS152_COMPAT_GROUP); + if (group < 0) + return group; + + dev_info(dev, "TSP FW Rev: bootloader 0x%x / core 0x%x / config 0x%x, Compat group: %c\n", + buf[0], buf[1], buf[2], group); + break; + + case TYPE_MMS114: + error = __mms114_read_reg(data, MMS114_TSP_REV, 6, buf); + if (error) + return error; - dev_info(dev, "TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n", - buf[0], buf[1], buf[3]); + dev_info(dev, "TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n", + buf[0], buf[1], buf[3]); + break; + } return 0; } @@ -261,6 +290,10 @@ static int mms114_setup_regs(struct mms114_data *data) if (error < 0) return error; + /* MMS152 has no configuration or power on registers */ + if (data->type == TYPE_MMS152) + return 0; + error = mms114_set_active(data, true); if (error < 0) return error; @@ -395,6 +428,7 @@ static int mms114_probe(struct i2c_client *client, { struct mms114_data *data; struct input_dev *input_dev; + const void *match_data; int error; if (!i2c_check_functionality(client->adapter, @@ -415,6 +449,13 @@ static int mms114_probe(struct i2c_client *client, data->client = client; data->input_dev = input_dev; + /* FIXME: switch to device_get_match_data() when available */ + match_data = of_device_get_match_data(&client->dev); + if (!match_data) + return -EINVAL; + + data->type = (enum mms_type)match_data; + input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X); input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y); input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0); @@ -435,19 +476,26 @@ static int mms114_probe(struct i2c_client *client, 0, data->props.max_y, 0, 0); } - /* - * The firmware handles movement and pressure fuzz, so - * don't duplicate that in software. - */ - data->moving_threshold = input_abs_get_fuzz(input_dev, - ABS_MT_POSITION_X); - data->contact_threshold = input_abs_get_fuzz(input_dev, - ABS_MT_PRESSURE); - input_abs_set_fuzz(input_dev, ABS_MT_POSITION_X, 0); - input_abs_set_fuzz(input_dev, ABS_MT_POSITION_Y, 0); - input_abs_set_fuzz(input_dev, ABS_MT_PRESSURE, 0); - - input_dev->name = "MELFAS MMS114 Touchscreen"; + if (data->type == TYPE_MMS114) { + /* + * The firmware handles movement and pressure fuzz, so + * don't duplicate that in software. + */ + data->moving_threshold = input_abs_get_fuzz(input_dev, + ABS_MT_POSITION_X); + data->contact_threshold = input_abs_get_fuzz(input_dev, + ABS_MT_PRESSURE); + input_abs_set_fuzz(input_dev, ABS_MT_POSITION_X, 0); + input_abs_set_fuzz(input_dev, ABS_MT_POSITION_Y, 0); + input_abs_set_fuzz(input_dev, ABS_MT_PRESSURE, 0); + } + + input_dev->name = devm_kasprintf(&client->dev, GFP_KERNEL, + "MELFAS MMS%d Touchscreen", + data->type); + if (!input_dev->name) + return -ENOMEM; + input_dev->id.bustype = BUS_I2C; input_dev->dev.parent = &client->dev; input_dev->open = mms114_input_open; @@ -549,7 +597,13 @@ MODULE_DEVICE_TABLE(i2c, mms114_id); #ifdef CONFIG_OF static const struct of_device_id mms114_dt_match[] = { - { .compatible = "melfas,mms114" }, + { + .compatible = "melfas,mms114", + .data = (void *)TYPE_MMS114, + }, { + .compatible = "melfas,mms152", + .data = (void *)TYPE_MMS152, + }, { } }; MODULE_DEVICE_TABLE(of, mms114_dt_match); ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 4/4 v2] Input: mms114 - add support for mms152 2018-01-24 21:32 ` [PATCH 4/4 v2] " Dmitry Torokhov @ 2018-01-26 5:14 ` Andi Shyti 2018-01-26 19:25 ` Dmitry Torokhov 0 siblings, 1 reply; 14+ messages in thread From: Andi Shyti @ 2018-01-26 5:14 UTC (permalink / raw) To: Dmitry Torokhov Cc: Marcus Folkesson, Simon Shields, Rob Herring, linux-input, linux-kernel Hi Simon and Dmitry, On Wed, Jan 24, 2018 at 01:32:01PM -0800, Dmitry Torokhov wrote: > From: Simon Shields <simon@lineageos.org> > > MMS152 has no configuration registers, but the packet format used in > interrupts is identical to mms114. > > Signed-off-by: Simon Shields <simon@lineageos.org> > Patchwork-Id: 10125841 > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> also here Reviewed-by: Andi Shyti <andi.shyti@samsung.com> Tested-by: Andi Shyti <andi.shyti@samsung.com> one small nitpick: > @@ -239,14 +249,33 @@ static int mms114_get_version(struct mms114_data *data) > { > struct device *dev = &data->client->dev; > u8 buf[6]; > + int group; > int error; do we really need to define a new 'group' variable? Andi > - error = __mms114_read_reg(data, MMS114_TSP_REV, 6, buf); > - if (error < 0) > - return error; > + switch (data->type) { > + case TYPE_MMS152: > + error = __mms114_read_reg(data, MMS152_FW_REV, 3, buf); > + if (error) > + return error; > + > + group = i2c_smbus_read_byte_data(data->client, > + MMS152_COMPAT_GROUP); > + if (group < 0) > + return group; > + > + dev_info(dev, "TSP FW Rev: bootloader 0x%x / core 0x%x / config 0x%x, Compat group: %c\n", > + buf[0], buf[1], buf[2], group); > + break; > + > + case TYPE_MMS114: > + error = __mms114_read_reg(data, MMS114_TSP_REV, 6, buf); > + if (error) > + return error; > > - dev_info(dev, "TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n", > - buf[0], buf[1], buf[3]); > + dev_info(dev, "TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n", > + buf[0], buf[1], buf[3]); > + break; > + } > > return 0; > } ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 4/4 v2] Input: mms114 - add support for mms152 2018-01-26 5:14 ` Andi Shyti @ 2018-01-26 19:25 ` Dmitry Torokhov 0 siblings, 0 replies; 14+ messages in thread From: Dmitry Torokhov @ 2018-01-26 19:25 UTC (permalink / raw) To: Andi Shyti Cc: Marcus Folkesson, Simon Shields, Rob Herring, linux-input, linux-kernel On Fri, Jan 26, 2018 at 02:14:38PM +0900, Andi Shyti wrote: > Hi Simon and Dmitry, > > On Wed, Jan 24, 2018 at 01:32:01PM -0800, Dmitry Torokhov wrote: > > From: Simon Shields <simon@lineageos.org> > > > > MMS152 has no configuration registers, but the packet format used in > > interrupts is identical to mms114. > > > > Signed-off-by: Simon Shields <simon@lineageos.org> > > Patchwork-Id: 10125841 > > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> > > also here > > Reviewed-by: Andi Shyti <andi.shyti@samsung.com> > Tested-by: Andi Shyti <andi.shyti@samsung.com> > > one small nitpick: > > > @@ -239,14 +249,33 @@ static int mms114_get_version(struct mms114_data *data) > > { > > struct device *dev = &data->client->dev; > > u8 buf[6]; > > + int group; > > int error; > > do we really need to define a new 'group' variable? I like it, that's why I added it ;) As Marcus mentioned, we cant use 'buf' to store the value as buf is unsigned and i2c_smbus_read_byte_data() may return negative error code. And I do not want to use 'error' variable because logically we are trying to get group value, not error. Hence a dedicated variable. It's gonna be optimized away anyway. Thanks. > > Andi > > > - error = __mms114_read_reg(data, MMS114_TSP_REV, 6, buf); > > - if (error < 0) > > - return error; > > + switch (data->type) { > > + case TYPE_MMS152: > > + error = __mms114_read_reg(data, MMS152_FW_REV, 3, buf); > > + if (error) > > + return error; > > + > > + group = i2c_smbus_read_byte_data(data->client, > > + MMS152_COMPAT_GROUP); > > + if (group < 0) > > + return group; > > + > > + dev_info(dev, "TSP FW Rev: bootloader 0x%x / core 0x%x / config 0x%x, Compat group: %c\n", > > + buf[0], buf[1], buf[2], group); > > + break; > > + > > + case TYPE_MMS114: > > + error = __mms114_read_reg(data, MMS114_TSP_REV, 6, buf); > > + if (error) > > + return error; > > > > - dev_info(dev, "TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n", > > - buf[0], buf[1], buf[3]); > > + dev_info(dev, "TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n", > > + buf[0], buf[1], buf[3]); > > + break; > > + } > > > > return 0; > > } -- Dmitry ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 0/4] MMS114 touchscreen patches 2018-01-24 19:38 [PATCH 0/4] MMS114 touchscreen patches Dmitry Torokhov ` (3 preceding siblings ...) 2018-01-24 19:38 ` [PATCH 4/4] Input: mms114 - add support for mms152 Dmitry Torokhov @ 2018-01-25 13:01 ` Simon Shields 4 siblings, 0 replies; 14+ messages in thread From: Simon Shields @ 2018-01-25 13:01 UTC (permalink / raw) To: Dmitry Torokhov; +Cc: Andi Shyti, Rob Herring, linux-input, linux-kernel Hi Dmitry, Thanks for the extra fixes! On Wed, Jan 24, 2018 at 11:38:00AM -0800, Dmitry Torokhov wrote: > Hi, > > This is a combination of couple of my patches + Simons patches dropping > support for platform data and adding support for mms152, slightly reworked. > > Andi, because patches changed a bit I did not add your reviewed-by or > tested-by, please take another look. > > Thanks! > > Dmitry Torokhov (2): > Input: mms114 - do not clobber interrupt trigger > Input: mms114 - mark as direct input device > > Simon Shields (2): > Input: mms114 - drop platform data and use generic APIs > Input: mms114 - add support for mms152 > > .../bindings/input/touchscreen/mms114.txt | 35 ++-- > drivers/input/touchscreen/mms114.c | 229 ++++++++++++--------- > include/linux/platform_data/mms114.h | 24 --- > 3 files changed, 151 insertions(+), 137 deletions(-) > delete mode 100644 include/linux/platform_data/mms114.h > > -- > Dmitry > All looks good to me. Tested on MMS114 and MMS152. Reviewed-by: Simon Shields <simon@lineageos.org> Tested-by: Simon Shields <simon@lineageos.org> Cheers, Simon ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2018-01-26 19:25 UTC | newest] Thread overview: 14+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-01-24 19:38 [PATCH 0/4] MMS114 touchscreen patches Dmitry Torokhov 2018-01-24 19:38 ` [PATCH 1/4] Input: mms114 - do not clobber interrupt trigger Dmitry Torokhov 2018-01-26 4:54 ` Andi Shyti 2018-01-24 19:38 ` [PATCH 2/4] Input: mms114 - mark as direct input device Dmitry Torokhov 2018-01-26 4:55 ` Andi Shyti 2018-01-24 19:38 ` [PATCH 3/4] Input: mms114 - drop platform data and use generic APIs Dmitry Torokhov 2018-01-26 5:06 ` Andi Shyti 2018-01-24 19:38 ` [PATCH 4/4] Input: mms114 - add support for mms152 Dmitry Torokhov 2018-01-24 20:04 ` Marcus Folkesson 2018-01-24 21:27 ` Dmitry Torokhov 2018-01-24 21:32 ` [PATCH 4/4 v2] " Dmitry Torokhov 2018-01-26 5:14 ` Andi Shyti 2018-01-26 19:25 ` Dmitry Torokhov 2018-01-25 13:01 ` [PATCH 0/4] MMS114 touchscreen patches Simon Shields
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).