linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv4 0/4] EXC3000 Updates
@ 2020-08-05 16:05 Sebastian Reichel
  2020-08-05 16:05 ` [PATCHv4 1/4] dt-bindings: touchscreen: Convert EETI EXC3000 touchscreen to json-schema Sebastian Reichel
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Sebastian Reichel @ 2020-08-05 16:05 UTC (permalink / raw)
  To: Dmitry Torokhov, Ahmet Inan, Martin Fuzzey, Rob Herring
  Cc: linux-input, devicetree, linux-kernel, kernel, Sebastian Reichel

Hi,

This is PATCHv3 of the EXC80Hxx support patchset.

Changes since [PATCHv3]:
 - reorder last two patches
 - register 'fw_version' and 'model' sysfs files in i2c device's
   sysfs node instead of input device
 - Add Reviewed-by from Enric
 - Add Rob Herring and DT mailinglist
 - Drop probe_new API patch (applied)

Changes since [PATCHv2]:
 - add #include <linux/size.h> for SZ_4K and SZ_16K (kbuild test bot)
 - fw_version_show must be ssize_t (kbuild test bot)
 - rename YAML binding file to include eeti, prefix (Enric)
 - noise from gpio-reset patch (Enric)
 - add comment for the retry loop (Enric, Martin)
 - document sysfs entries (Enric)

Changes since [PATCHv1]:
 - prepend new patch converting binding document to YAML
 - prepend new patch switching to I2C probe_new
 - append new patch adding reset-gpio support
 - use explicit compatible values for the touchscreen chips instead of
   a wildcast. Since the documentation, that I have is very vague let's
   use different values for exc80h60 and exc80h84. This avoids wildcard
   DT entries and means we are prepared when noticing differences
   between the chips.
 - add accidently removed terminator entry in exc3000_id
 - use device structure with max_xy and name (suggested by Martin)
 - use SZ_4K, SZ_16K defines (suggested by Dmitry)
 - harden event check, so that MT1 and MT2 based chips only allow
   their own event type.
 - write more detailed commit description in the fw_version/model
   sysfs patch to explain why the values are not cached and why
   the simpler read(); sleep(); write() approach has not been used
 - use DEVICE_ATTR_RO() in fw_version/model patch to improve readability
 - fw_version/model: replace memcpy + null termination with strlcpy
 - fw_version/model: increase buffer size for weird firmware versions
 - fw_version/model: use sizeof() instead of hardcoded buffer sizes
 - simplify exc3000_query_interrupt() by moving the complete() call to
   the exc3000_interrupt().

I think I only ignored one review feedback, that the fw_version and
model sysfs nodes are attached to the input device instead of the
i2c device. This was done to avoid being racy:

http://kroah.com/log/blog/2013/06/26/how-to-create-a-sysfs-file-correctly/

Thanks in advance for looking at the patches,

-- Sebastian

[PATCHv3] https://lore.kernel.org/linux-input/20200520153936.46869-1-sebastian.reichel@collabora.com/
[PATCHv2] https://lore.kernel.org/linux-input/20200519182447.73405-1-sebastian.reichel@collabora.com/
[PATCHv1] https://lore.kernel.org/linux-input/20191107181010.17211-1-sebastian.reichel@collabora.com/

Sebastian Reichel (4):
  dt-bindings: touchscreen: Convert EETI EXC3000 touchscreen to
    json-schema
  Input: EXC3000: add EXC80H60 and EXC80H84 support
  Input: EXC3000: Add reset gpio support
  Input: EXC3000: Add support to query model and fw_version

 .../ABI/testing/sysfs-driver-input-exc3000    |  15 ++
 .../input/touchscreen/eeti,exc3000.yaml       |  58 ++++
 .../bindings/input/touchscreen/exc3000.txt    |  26 --
 drivers/input/touchscreen/exc3000.c           | 249 +++++++++++++++++-
 4 files changed, 308 insertions(+), 40 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-driver-input-exc3000
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
 delete mode 100644 Documentation/devicetree/bindings/input/touchscreen/exc3000.txt

-- 
2.27.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCHv4 1/4] dt-bindings: touchscreen: Convert EETI EXC3000 touchscreen to json-schema
  2020-08-05 16:05 [PATCHv4 0/4] EXC3000 Updates Sebastian Reichel
@ 2020-08-05 16:05 ` Sebastian Reichel
  2020-08-06 14:49   ` Rob Herring
  2020-08-07  0:36   ` Dmitry Torokhov
  2020-08-05 16:05 ` [PATCHv4 2/4] Input: EXC3000: add EXC80H60 and EXC80H84 support Sebastian Reichel
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 13+ messages in thread
From: Sebastian Reichel @ 2020-08-05 16:05 UTC (permalink / raw)
  To: Dmitry Torokhov, Ahmet Inan, Martin Fuzzey, Rob Herring
  Cc: linux-input, devicetree, linux-kernel, kernel, Sebastian Reichel

Convert the EETI EXC3000 binding to DT schema format using json-schema

Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 .../input/touchscreen/eeti,exc3000.yaml       | 53 +++++++++++++++++++
 .../bindings/input/touchscreen/exc3000.txt    | 26 ---------
 2 files changed, 53 insertions(+), 26 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
 delete mode 100644 Documentation/devicetree/bindings/input/touchscreen/exc3000.txt

diff --git a/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml b/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
new file mode 100644
index 000000000000..022aa69a5dfe
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/touchscreen/eeti,exc3000.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: EETI EXC3000 series touchscreen controller
+
+maintainers:
+  - Dmitry Torokhov <dmitry.torokhov@gmail.com>
+
+allOf:
+  - $ref: touchscreen.yaml#
+
+properties:
+  compatible:
+    const: eeti,exc3000
+  reg:
+    const: 0x2a
+  interrupts:
+    maxItems: 1
+  touchscreen-size-x: true
+  touchscreen-size-y: true
+  touchscreen-inverted-x: true
+  touchscreen-inverted-y: true
+  touchscreen-swapped-x-y: true
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - touchscreen-size-x
+  - touchscreen-size-y
+
+additionalProperties: false
+
+examples:
+  - |
+    #include "dt-bindings/interrupt-controller/irq.h"
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        touchscreen@2a {
+                compatible = "eeti,exc3000";
+                reg = <0x2a>;
+                interrupt-parent = <&gpio1>;
+                interrupts = <9 IRQ_TYPE_LEVEL_LOW>;
+                touchscreen-size-x = <4096>;
+                touchscreen-size-y = <4096>;
+                touchscreen-inverted-x;
+                touchscreen-swapped-x-y;
+        };
+    };
diff --git a/Documentation/devicetree/bindings/input/touchscreen/exc3000.txt b/Documentation/devicetree/bindings/input/touchscreen/exc3000.txt
deleted file mode 100644
index 68291b94fec2..000000000000
--- a/Documentation/devicetree/bindings/input/touchscreen/exc3000.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-* EETI EXC3000 Multiple Touch Controller
-
-Required properties:
-- compatible: must be "eeti,exc3000"
-- reg: i2c slave address
-- interrupts: touch controller interrupt
-- touchscreen-size-x: See touchscreen.txt
-- touchscreen-size-y: See touchscreen.txt
-
-Optional properties:
-- touchscreen-inverted-x: See touchscreen.txt
-- touchscreen-inverted-y: See touchscreen.txt
-- touchscreen-swapped-x-y: See touchscreen.txt
-
-Example:
-
-	touchscreen@2a {
-		compatible = "eeti,exc3000";
-		reg = <0x2a>;
-		interrupt-parent = <&gpio1>;
-		interrupts = <9 IRQ_TYPE_LEVEL_LOW>;
-		touchscreen-size-x = <4096>;
-		touchscreen-size-y = <4096>;
-		touchscreen-inverted-x;
-		touchscreen-swapped-x-y;
-	};
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCHv4 2/4] Input: EXC3000: add EXC80H60 and EXC80H84 support
  2020-08-05 16:05 [PATCHv4 0/4] EXC3000 Updates Sebastian Reichel
  2020-08-05 16:05 ` [PATCHv4 1/4] dt-bindings: touchscreen: Convert EETI EXC3000 touchscreen to json-schema Sebastian Reichel
@ 2020-08-05 16:05 ` Sebastian Reichel
  2020-08-06 14:49   ` Rob Herring
  2020-08-07  0:37   ` Dmitry Torokhov
  2020-08-05 16:05 ` [PATCHv4 3/4] Input: EXC3000: Add reset gpio support Sebastian Reichel
  2020-08-05 16:05 ` [PATCHv4 4/4] Input: EXC3000: Add support to query model and fw_version Sebastian Reichel
  3 siblings, 2 replies; 13+ messages in thread
From: Sebastian Reichel @ 2020-08-05 16:05 UTC (permalink / raw)
  To: Dmitry Torokhov, Ahmet Inan, Martin Fuzzey, Rob Herring
  Cc: linux-input, devicetree, linux-kernel, kernel, Sebastian Reichel

This adds support for EXC80H60 and EXCH84 controllers, which
use a different event type id and have two extra bits for the
resolution (so the maximum is 16K instead of 4K).

Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 .../input/touchscreen/eeti,exc3000.yaml       |  5 +-
 drivers/input/touchscreen/exc3000.c           | 80 +++++++++++++++----
 2 files changed, 70 insertions(+), 15 deletions(-)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml b/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
index 022aa69a5dfe..7e6e23f8fa00 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
@@ -14,7 +14,10 @@ allOf:
 
 properties:
   compatible:
-    const: eeti,exc3000
+    enum:
+      - eeti,exc3000
+      - eeti,exc80h60
+      - eeti,exc80h84
   reg:
     const: 0x2a
   interrupts:
diff --git a/drivers/input/touchscreen/exc3000.c b/drivers/input/touchscreen/exc3000.c
index 555a14305cd4..b497bd2ae41d 100644
--- a/drivers/input/touchscreen/exc3000.c
+++ b/drivers/input/touchscreen/exc3000.c
@@ -16,6 +16,7 @@
 #include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/sizes.h>
 #include <linux/timer.h>
 #include <asm/unaligned.h>
 
@@ -23,11 +24,43 @@
 #define EXC3000_SLOTS_PER_FRAME		5
 #define EXC3000_LEN_FRAME		66
 #define EXC3000_LEN_POINT		10
-#define EXC3000_MT_EVENT		6
+
+#define EXC3000_MT1_EVENT		0x06
+#define EXC3000_MT2_EVENT		0x18
+
 #define EXC3000_TIMEOUT_MS		100
 
+static const struct i2c_device_id exc3000_id[];
+
+struct eeti_dev_info {
+	const char *name;
+	int max_xy;
+};
+
+enum eeti_dev_id {
+	EETI_EXC3000,
+	EETI_EXC80H60,
+	EETI_EXC80H84,
+};
+
+static struct eeti_dev_info exc3000_info[] = {
+	[EETI_EXC3000] = {
+		.name = "EETI EXC3000 Touch Screen",
+		.max_xy = SZ_4K - 1,
+	},
+	[EETI_EXC80H60] = {
+		.name = "EETI EXC80H60 Touch Screen",
+		.max_xy = SZ_16K - 1,
+	},
+	[EETI_EXC80H84] = {
+		.name = "EETI EXC80H84 Touch Screen",
+		.max_xy = SZ_16K - 1,
+	},
+};
+
 struct exc3000_data {
 	struct i2c_client *client;
+	const struct eeti_dev_info *info;
 	struct input_dev *input;
 	struct touchscreen_properties prop;
 	struct timer_list timer;
@@ -58,10 +91,15 @@ static void exc3000_timer(struct timer_list *t)
 	input_sync(data->input);
 }
 
-static int exc3000_read_frame(struct i2c_client *client, u8 *buf)
+static int exc3000_read_frame(struct exc3000_data *data, u8 *buf)
 {
+	struct i2c_client *client = data->client;
+	u8 expected_event = EXC3000_MT1_EVENT;
 	int ret;
 
+	if (data->info->max_xy == SZ_16K - 1)
+		expected_event = EXC3000_MT2_EVENT;
+
 	ret = i2c_master_send(client, "'", 2);
 	if (ret < 0)
 		return ret;
@@ -76,19 +114,21 @@ static int exc3000_read_frame(struct i2c_client *client, u8 *buf)
 	if (ret != EXC3000_LEN_FRAME)
 		return -EIO;
 
-	if (get_unaligned_le16(buf) != EXC3000_LEN_FRAME ||
-			buf[2] != EXC3000_MT_EVENT)
+	if (get_unaligned_le16(buf) != EXC3000_LEN_FRAME)
+		return -EINVAL;
+
+	if (buf[2] != expected_event)
 		return -EINVAL;
 
 	return 0;
 }
 
-static int exc3000_read_data(struct i2c_client *client,
+static int exc3000_read_data(struct exc3000_data *data,
 			     u8 *buf, int *n_slots)
 {
 	int error;
 
-	error = exc3000_read_frame(client, buf);
+	error = exc3000_read_frame(data, buf);
 	if (error)
 		return error;
 
@@ -98,7 +138,7 @@ static int exc3000_read_data(struct i2c_client *client,
 
 	if (*n_slots > EXC3000_SLOTS_PER_FRAME) {
 		/* Read 2nd frame to get the rest of the contacts. */
-		error = exc3000_read_frame(client, buf + EXC3000_LEN_FRAME);
+		error = exc3000_read_frame(data, buf + EXC3000_LEN_FRAME);
 		if (error)
 			return error;
 
@@ -118,7 +158,7 @@ static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
 	int slots, total_slots;
 	int error;
 
-	error = exc3000_read_data(data->client, buf, &total_slots);
+	error = exc3000_read_data(data, buf, &total_slots);
 	if (error) {
 		/* Schedule a timer to release "stuck" contacts */
 		mod_timer(&data->timer,
@@ -149,13 +189,19 @@ static int exc3000_probe(struct i2c_client *client)
 {
 	struct exc3000_data *data;
 	struct input_dev *input;
-	int error;
+	int error, max_xy;
 
 	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
 	data->client = client;
+	data->info = device_get_match_data(&client->dev);
+	if (!data->info) {
+		enum eeti_dev_id eeti_dev_id =
+			i2c_match_id(exc3000_id, client)->driver_data;
+		data->info = &exc3000_info[eeti_dev_id];
+	}
 	timer_setup(&data->timer, exc3000_timer, 0);
 
 	input = devm_input_allocate_device(&client->dev);
@@ -164,11 +210,13 @@ static int exc3000_probe(struct i2c_client *client)
 
 	data->input = input;
 
-	input->name = "EETI EXC3000 Touch Screen";
+	input->name = data->info->name;
 	input->id.bustype = BUS_I2C;
 
-	input_set_abs_params(input, ABS_MT_POSITION_X, 0, 4095, 0, 0);
-	input_set_abs_params(input, ABS_MT_POSITION_Y, 0, 4095, 0, 0);
+	max_xy = data->info->max_xy;
+	input_set_abs_params(input, ABS_MT_POSITION_X, 0, max_xy, 0, 0);
+	input_set_abs_params(input, ABS_MT_POSITION_Y, 0, max_xy, 0, 0);
+
 	touchscreen_parse_properties(input, true, &data->prop);
 
 	error = input_mt_init_slots(input, EXC3000_NUM_SLOTS,
@@ -190,14 +238,18 @@ static int exc3000_probe(struct i2c_client *client)
 }
 
 static const struct i2c_device_id exc3000_id[] = {
-	{ "exc3000", 0 },
+	{ "exc3000", EETI_EXC3000 },
+	{ "exc80h60", EETI_EXC80H60 },
+	{ "exc80h84", EETI_EXC80H84 },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, exc3000_id);
 
 #ifdef CONFIG_OF
 static const struct of_device_id exc3000_of_match[] = {
-	{ .compatible = "eeti,exc3000" },
+	{ .compatible = "eeti,exc3000", .data = &exc3000_info[EETI_EXC3000] },
+	{ .compatible = "eeti,exc80h60", .data = &exc3000_info[EETI_EXC80H60] },
+	{ .compatible = "eeti,exc80h84", .data = &exc3000_info[EETI_EXC80H84] },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, exc3000_of_match);
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCHv4 3/4] Input: EXC3000: Add reset gpio support
  2020-08-05 16:05 [PATCHv4 0/4] EXC3000 Updates Sebastian Reichel
  2020-08-05 16:05 ` [PATCHv4 1/4] dt-bindings: touchscreen: Convert EETI EXC3000 touchscreen to json-schema Sebastian Reichel
  2020-08-05 16:05 ` [PATCHv4 2/4] Input: EXC3000: add EXC80H60 and EXC80H84 support Sebastian Reichel
@ 2020-08-05 16:05 ` Sebastian Reichel
  2020-08-06 14:50   ` Rob Herring
  2020-08-07  0:37   ` Dmitry Torokhov
  2020-08-05 16:05 ` [PATCHv4 4/4] Input: EXC3000: Add support to query model and fw_version Sebastian Reichel
  3 siblings, 2 replies; 13+ messages in thread
From: Sebastian Reichel @ 2020-08-05 16:05 UTC (permalink / raw)
  To: Dmitry Torokhov, Ahmet Inan, Martin Fuzzey, Rob Herring
  Cc: linux-input, devicetree, linux-kernel, kernel, Sebastian Reichel,
	Enric Balletbo i Serra

Add basic support for an optional reset gpio.

Reviewed-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 .../input/touchscreen/eeti,exc3000.yaml         |  2 ++
 drivers/input/touchscreen/exc3000.c             | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml b/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
index 7e6e23f8fa00..007adbc89c14 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
@@ -22,6 +22,8 @@ properties:
     const: 0x2a
   interrupts:
     maxItems: 1
+  reset-gpios:
+    maxItems: 1
   touchscreen-size-x: true
   touchscreen-size-y: true
   touchscreen-inverted-x: true
diff --git a/drivers/input/touchscreen/exc3000.c b/drivers/input/touchscreen/exc3000.c
index b497bd2ae41d..203f50acaab7 100644
--- a/drivers/input/touchscreen/exc3000.c
+++ b/drivers/input/touchscreen/exc3000.c
@@ -8,7 +8,9 @@
  */
 
 #include <linux/bitops.h>
+#include <linux/delay.h>
 #include <linux/device.h>
+#include <linux/gpio/consumer.h>
 #include <linux/i2c.h>
 #include <linux/input.h>
 #include <linux/input/mt.h>
@@ -30,6 +32,9 @@
 
 #define EXC3000_TIMEOUT_MS		100
 
+#define EXC3000_RESET_MS		10
+#define EXC3000_READY_MS		100
+
 static const struct i2c_device_id exc3000_id[];
 
 struct eeti_dev_info {
@@ -63,6 +68,7 @@ struct exc3000_data {
 	const struct eeti_dev_info *info;
 	struct input_dev *input;
 	struct touchscreen_properties prop;
+	struct gpio_desc *reset;
 	struct timer_list timer;
 	u8 buf[2 * EXC3000_LEN_FRAME];
 };
@@ -204,6 +210,17 @@ static int exc3000_probe(struct i2c_client *client)
 	}
 	timer_setup(&data->timer, exc3000_timer, 0);
 
+	data->reset = devm_gpiod_get_optional(&client->dev, "reset",
+					      GPIOD_OUT_HIGH);
+	if (IS_ERR(data->reset))
+		return PTR_ERR(data->reset);
+
+	if (data->reset) {
+		msleep(EXC3000_RESET_MS);
+		gpiod_set_value_cansleep(data->reset, 0);
+		msleep(EXC3000_READY_MS);
+	}
+
 	input = devm_input_allocate_device(&client->dev);
 	if (!input)
 		return -ENOMEM;
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCHv4 4/4] Input: EXC3000: Add support to query model and fw_version
  2020-08-05 16:05 [PATCHv4 0/4] EXC3000 Updates Sebastian Reichel
                   ` (2 preceding siblings ...)
  2020-08-05 16:05 ` [PATCHv4 3/4] Input: EXC3000: Add reset gpio support Sebastian Reichel
@ 2020-08-05 16:05 ` Sebastian Reichel
  2020-08-07  0:39   ` Dmitry Torokhov
  3 siblings, 1 reply; 13+ messages in thread
From: Sebastian Reichel @ 2020-08-05 16:05 UTC (permalink / raw)
  To: Dmitry Torokhov, Ahmet Inan, Martin Fuzzey, Rob Herring
  Cc: linux-input, devicetree, linux-kernel, kernel, Sebastian Reichel,
	Enric Balletbo i Serra

Expose model and fw_version via sysfs. Also query the model
in probe to make sure, that the I2C communication with the
device works before successfully probing the driver.

This is a bit complicated, since EETI devices do not have
a sync interface. Sending the commands and directly reading
does not work. Sending the command and waiting for some time
is also not an option, since there might be touch events in
the mean time.

Last but not least we do not cache the results, since this
interface can be used to check the I2C communication is still
working as expected.

Reviewed-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 .../ABI/testing/sysfs-driver-input-exc3000    |  15 ++
 drivers/input/touchscreen/exc3000.c           | 154 +++++++++++++++++-
 2 files changed, 168 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-driver-input-exc3000

diff --git a/Documentation/ABI/testing/sysfs-driver-input-exc3000 b/Documentation/ABI/testing/sysfs-driver-input-exc3000
new file mode 100644
index 000000000000..3d316d54f81c
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-driver-input-exc3000
@@ -0,0 +1,15 @@
+What:		/sys/bus/i2c/devices/xxx/fw_version
+Date:		Aug 2020
+Contact:	linux-input@vger.kernel.org
+Description:    Reports the firmware version provided by the touchscreen, for example "00_T6" on a EXC80H60
+
+		Access: Read
+		Valid values: Represented as string
+
+What:		/sys/bus/i2c/devices/xxx/model
+Date:		Aug 2020
+Contact:	linux-input@vger.kernel.org
+Description:    Reports the model identification provided by the touchscreen, for example "Orion_1320" on a EXC80H60
+
+		Access: Read
+		Valid values: Represented as string
diff --git a/drivers/input/touchscreen/exc3000.c b/drivers/input/touchscreen/exc3000.c
index 203f50acaab7..2e5fdbc9878a 100644
--- a/drivers/input/touchscreen/exc3000.c
+++ b/drivers/input/touchscreen/exc3000.c
@@ -27,6 +27,9 @@
 #define EXC3000_LEN_FRAME		66
 #define EXC3000_LEN_POINT		10
 
+#define EXC3000_LEN_MODEL_NAME		16
+#define EXC3000_LEN_FW_VERSION		16
+
 #define EXC3000_MT1_EVENT		0x06
 #define EXC3000_MT2_EVENT		0x18
 
@@ -71,6 +74,11 @@ struct exc3000_data {
 	struct gpio_desc *reset;
 	struct timer_list timer;
 	u8 buf[2 * EXC3000_LEN_FRAME];
+	struct completion wait_event;
+	struct mutex query_lock;
+	int query_result;
+	char model[EXC3000_LEN_MODEL_NAME];
+	char fw_version[EXC3000_LEN_FW_VERSION];
 };
 
 static void exc3000_report_slots(struct input_dev *input,
@@ -156,6 +164,28 @@ static int exc3000_read_data(struct exc3000_data *data,
 	return 0;
 }
 
+static int exc3000_query_interrupt(struct exc3000_data *data)
+{
+	u8 *buf = data->buf;
+	int err;
+
+	err = i2c_master_recv(data->client, buf, EXC3000_LEN_FRAME);
+	if (err < 0)
+		return err;
+
+	if (buf[0] != 0x42)
+		return -EPROTO;
+
+	if (buf[4] == 'E')
+		strlcpy(data->model, buf+5, sizeof(data->model));
+	else if (buf[4] == 'D')
+		strlcpy(data->fw_version, buf+5, sizeof(data->fw_version));
+	else
+		return -EPROTO;
+
+	return 0;
+}
+
 static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
 {
 	struct exc3000_data *data = dev_id;
@@ -164,6 +194,12 @@ static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
 	int slots, total_slots;
 	int error;
 
+	if (mutex_is_locked(&data->query_lock)) {
+		data->query_result = exc3000_query_interrupt(data);
+		complete(&data->wait_event);
+		goto out;
+	}
+
 	error = exc3000_read_data(data, buf, &total_slots);
 	if (error) {
 		/* Schedule a timer to release "stuck" contacts */
@@ -191,11 +227,95 @@ static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static ssize_t fw_version_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct exc3000_data *data = dev_get_drvdata(dev);
+	static const u8 request[68] = {
+		0x67, 0x00, 0x42, 0x00, 0x03, 0x01, 'D', 0x00
+	};
+	struct i2c_client *client = data->client;
+	int err;
+
+	mutex_lock(&data->query_lock);
+
+	data->query_result = -ETIMEDOUT;
+	reinit_completion(&data->wait_event);
+
+	err = i2c_master_send(client, request, sizeof(request));
+	if (err < 0) {
+		mutex_unlock(&data->query_lock);
+		return err;
+	}
+
+	wait_for_completion_interruptible_timeout(&data->wait_event, 1*HZ);
+	mutex_unlock(&data->query_lock);
+
+	if (data->query_result < 0)
+		return data->query_result;
+
+	return sprintf(buf, "%s\n", data->fw_version);
+}
+static DEVICE_ATTR_RO(fw_version);
+
+static ssize_t exc3000_get_model(struct exc3000_data *data)
+{
+	static const u8 request[68] = {
+		0x67, 0x00, 0x42, 0x00, 0x03, 0x01, 'E', 0x00
+	};
+	struct i2c_client *client = data->client;
+	int err;
+
+	mutex_lock(&data->query_lock);
+	data->query_result = -ETIMEDOUT;
+	reinit_completion(&data->wait_event);
+
+	err = i2c_master_send(client, request, sizeof(request));
+	if (err < 0) {
+		mutex_unlock(&data->query_lock);
+		return err;
+	}
+
+	wait_for_completion_interruptible_timeout(&data->wait_event, 1 * HZ);
+	mutex_unlock(&data->query_lock);
+
+	return data->query_result;
+}
+
+static ssize_t model_show(struct device *dev,
+			  struct device_attribute *attr, char *buf)
+{
+	struct exc3000_data *data = dev_get_drvdata(dev);
+	int err = exc3000_get_model(data);
+
+	if (err < 0)
+		return err;
+
+	return sprintf(buf, "%s\n", data->model);
+}
+static DEVICE_ATTR_RO(model);
+
+static struct attribute *sysfs_attrs[] = {
+	&dev_attr_fw_version.attr,
+	&dev_attr_model.attr,
+	NULL
+};
+
+static struct attribute_group exc3000_attribute_group = {
+	.attrs = sysfs_attrs
+};
+
+static void exc3000_unregister_sysfs(void *_dev)
+{
+	struct device *dev = _dev;
+	sysfs_remove_group(&dev->kobj, &exc3000_attribute_group);
+}
+
 static int exc3000_probe(struct i2c_client *client)
 {
 	struct exc3000_data *data;
 	struct input_dev *input;
-	int error, max_xy;
+	int error, max_xy, retry;
 
 	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
@@ -209,6 +329,8 @@ static int exc3000_probe(struct i2c_client *client)
 		data->info = &exc3000_info[eeti_dev_id];
 	}
 	timer_setup(&data->timer, exc3000_timer, 0);
+	init_completion(&data->wait_event);
+	mutex_init(&data->query_lock);
 
 	data->reset = devm_gpiod_get_optional(&client->dev, "reset",
 					      GPIOD_OUT_HIGH);
@@ -226,6 +348,7 @@ static int exc3000_probe(struct i2c_client *client)
 		return -ENOMEM;
 
 	data->input = input;
+	input_set_drvdata(input, data);
 
 	input->name = data->info->name;
 	input->id.bustype = BUS_I2C;
@@ -251,6 +374,35 @@ static int exc3000_probe(struct i2c_client *client)
 	if (error)
 		return error;
 
+	/*
+	 * I²C does not have built-in recovery, so retry on failure. This ensures,
+	 * that the device probe will not fail for temporary issues on the bus.
+	 * This is not needed for the sysfs calls (userspace will receive the error
+	 * code and can start another query) and cannot be done for touch events
+	 * (but that only means loosing one or two touch events anyways).
+	 */
+	for (retry = 0; retry < 3; ++retry) {
+		error = exc3000_get_model(data);
+		if (!error)
+			break;
+		dev_warn(&client->dev, "Retry %d get EETI EXC3000 model: %d\n",
+			 retry + 1, error);
+	}
+
+	if (error)
+		return error;
+
+	dev_dbg(&client->dev, "TS Model: %s", data->model);
+
+	i2c_set_clientdata(client, data);
+	error = sysfs_create_group(&client->dev.kobj, &exc3000_attribute_group);
+	if (error)
+		return error;
+
+	error = devm_add_action_or_reset(&client->dev, exc3000_unregister_sysfs, &client->dev);
+	if (error)
+		return error;
+
 	return 0;
 }
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCHv4 1/4] dt-bindings: touchscreen: Convert EETI EXC3000 touchscreen to json-schema
  2020-08-05 16:05 ` [PATCHv4 1/4] dt-bindings: touchscreen: Convert EETI EXC3000 touchscreen to json-schema Sebastian Reichel
@ 2020-08-06 14:49   ` Rob Herring
  2020-08-07  0:36   ` Dmitry Torokhov
  1 sibling, 0 replies; 13+ messages in thread
From: Rob Herring @ 2020-08-06 14:49 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: linux-input, Ahmet Inan, linux-kernel, Rob Herring,
	Dmitry Torokhov, Martin Fuzzey, kernel, devicetree

On Wed, 05 Aug 2020 18:05:17 +0200, Sebastian Reichel wrote:
> Convert the EETI EXC3000 binding to DT schema format using json-schema
> 
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> ---
>  .../input/touchscreen/eeti,exc3000.yaml       | 53 +++++++++++++++++++
>  .../bindings/input/touchscreen/exc3000.txt    | 26 ---------
>  2 files changed, 53 insertions(+), 26 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
>  delete mode 100644 Documentation/devicetree/bindings/input/touchscreen/exc3000.txt
> 

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCHv4 2/4] Input: EXC3000: add EXC80H60 and EXC80H84 support
  2020-08-05 16:05 ` [PATCHv4 2/4] Input: EXC3000: add EXC80H60 and EXC80H84 support Sebastian Reichel
@ 2020-08-06 14:49   ` Rob Herring
  2020-08-07  0:37   ` Dmitry Torokhov
  1 sibling, 0 replies; 13+ messages in thread
From: Rob Herring @ 2020-08-06 14:49 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: linux-kernel, Rob Herring, kernel, linux-input, devicetree,
	Ahmet Inan, Dmitry Torokhov, Martin Fuzzey

On Wed, 05 Aug 2020 18:05:18 +0200, Sebastian Reichel wrote:
> This adds support for EXC80H60 and EXCH84 controllers, which
> use a different event type id and have two extra bits for the
> resolution (so the maximum is 16K instead of 4K).
> 
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> ---
>  .../input/touchscreen/eeti,exc3000.yaml       |  5 +-
>  drivers/input/touchscreen/exc3000.c           | 80 +++++++++++++++----
>  2 files changed, 70 insertions(+), 15 deletions(-)
> 

Acked-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCHv4 3/4] Input: EXC3000: Add reset gpio support
  2020-08-05 16:05 ` [PATCHv4 3/4] Input: EXC3000: Add reset gpio support Sebastian Reichel
@ 2020-08-06 14:50   ` Rob Herring
  2020-08-07  0:37   ` Dmitry Torokhov
  1 sibling, 0 replies; 13+ messages in thread
From: Rob Herring @ 2020-08-06 14:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Rob Herring, Enric Balletbo i Serra, Martin Fuzzey, Ahmet Inan,
	kernel, Dmitry Torokhov, linux-input, devicetree, linux-kernel

On Wed, 05 Aug 2020 18:05:19 +0200, Sebastian Reichel wrote:
> Add basic support for an optional reset gpio.
> 
> Reviewed-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> ---
>  .../input/touchscreen/eeti,exc3000.yaml         |  2 ++
>  drivers/input/touchscreen/exc3000.c             | 17 +++++++++++++++++
>  2 files changed, 19 insertions(+)
> 

Acked-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCHv4 1/4] dt-bindings: touchscreen: Convert EETI EXC3000 touchscreen to json-schema
  2020-08-05 16:05 ` [PATCHv4 1/4] dt-bindings: touchscreen: Convert EETI EXC3000 touchscreen to json-schema Sebastian Reichel
  2020-08-06 14:49   ` Rob Herring
@ 2020-08-07  0:36   ` Dmitry Torokhov
  1 sibling, 0 replies; 13+ messages in thread
From: Dmitry Torokhov @ 2020-08-07  0:36 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Ahmet Inan, Martin Fuzzey, Rob Herring, linux-input, devicetree,
	linux-kernel, kernel

On Wed, Aug 05, 2020 at 06:05:17PM +0200, Sebastian Reichel wrote:
> Convert the EETI EXC3000 binding to DT schema format using json-schema
> 
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

Applied, thank you.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCHv4 2/4] Input: EXC3000: add EXC80H60 and EXC80H84 support
  2020-08-05 16:05 ` [PATCHv4 2/4] Input: EXC3000: add EXC80H60 and EXC80H84 support Sebastian Reichel
  2020-08-06 14:49   ` Rob Herring
@ 2020-08-07  0:37   ` Dmitry Torokhov
  1 sibling, 0 replies; 13+ messages in thread
From: Dmitry Torokhov @ 2020-08-07  0:37 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Ahmet Inan, Martin Fuzzey, Rob Herring, linux-input, devicetree,
	linux-kernel, kernel

On Wed, Aug 05, 2020 at 06:05:18PM +0200, Sebastian Reichel wrote:
> This adds support for EXC80H60 and EXCH84 controllers, which
> use a different event type id and have two extra bits for the
> resolution (so the maximum is 16K instead of 4K).
> 
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

Applied, thank you.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCHv4 3/4] Input: EXC3000: Add reset gpio support
  2020-08-05 16:05 ` [PATCHv4 3/4] Input: EXC3000: Add reset gpio support Sebastian Reichel
  2020-08-06 14:50   ` Rob Herring
@ 2020-08-07  0:37   ` Dmitry Torokhov
  1 sibling, 0 replies; 13+ messages in thread
From: Dmitry Torokhov @ 2020-08-07  0:37 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Ahmet Inan, Martin Fuzzey, Rob Herring, linux-input, devicetree,
	linux-kernel, kernel, Enric Balletbo i Serra

On Wed, Aug 05, 2020 at 06:05:19PM +0200, Sebastian Reichel wrote:
> Add basic support for an optional reset gpio.
> 
> Reviewed-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

Applied, thank you.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCHv4 4/4] Input: EXC3000: Add support to query model and fw_version
  2020-08-05 16:05 ` [PATCHv4 4/4] Input: EXC3000: Add support to query model and fw_version Sebastian Reichel
@ 2020-08-07  0:39   ` Dmitry Torokhov
  2020-08-13 12:20     ` Sebastian Reichel
  0 siblings, 1 reply; 13+ messages in thread
From: Dmitry Torokhov @ 2020-08-07  0:39 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Ahmet Inan, Martin Fuzzey, Rob Herring, linux-input, devicetree,
	linux-kernel, kernel, Enric Balletbo i Serra

Hi Sebastian,

On Wed, Aug 05, 2020 at 06:05:20PM +0200, Sebastian Reichel wrote:
>  
> +static int exc3000_query_interrupt(struct exc3000_data *data)
> +{
> +	u8 *buf = data->buf;
> +	int err;
> +
> +	err = i2c_master_recv(data->client, buf, EXC3000_LEN_FRAME);
> +	if (err < 0)
> +		return err;
> +
> +	if (buf[0] != 0x42)

I changed this to 'B' to match the rest of the function.

> +		return -EPROTO;
> +
> +	if (buf[4] == 'E')
> +		strlcpy(data->model, buf+5, sizeof(data->model));
> +	else if (buf[4] == 'D')
> +		strlcpy(data->fw_version, buf+5, sizeof(data->fw_version));
> +	else
> +		return -EPROTO;
> +
> +	return 0;
> +}
> +
> +	error = sysfs_create_group(&client->dev.kobj, &exc3000_attribute_group);
> +	if (error)
> +		return error;
> +
> +	error = devm_add_action_or_reset(&client->dev, exc3000_unregister_sysfs, &client->dev);
> +	if (error)
> +		return error;

Replaced 2 calls with devm_device_add_group().

Please yell if I managed to break it...

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCHv4 4/4] Input: EXC3000: Add support to query model and fw_version
  2020-08-07  0:39   ` Dmitry Torokhov
@ 2020-08-13 12:20     ` Sebastian Reichel
  0 siblings, 0 replies; 13+ messages in thread
From: Sebastian Reichel @ 2020-08-13 12:20 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Ahmet Inan, Martin Fuzzey, Rob Herring, linux-input, devicetree,
	linux-kernel, kernel, Enric Balletbo i Serra

Hi Dmitry,

On Thu, Aug 06, 2020 at 05:39:01PM -0700, Dmitry Torokhov wrote:
> Hi Sebastian,
> 
> On Wed, Aug 05, 2020 at 06:05:20PM +0200, Sebastian Reichel wrote:
> >  
> > +static int exc3000_query_interrupt(struct exc3000_data *data)
> > +{
> > +	u8 *buf = data->buf;
> > +	int err;
> > +
> > +	err = i2c_master_recv(data->client, buf, EXC3000_LEN_FRAME);
> > +	if (err < 0)
> > +		return err;
> > +
> > +	if (buf[0] != 0x42)
> 
> I changed this to 'B' to match the rest of the function.

OK. I assumed this to be a easter egg reference to the Answer to
the Ultimate Question of Life, the Universe, and Everything from
the Hitchhiker's Guide, so I left it as a number. I might be totally
wrong on that one, so fine with me.

> > +		return -EPROTO;
> > +
> > +	if (buf[4] == 'E')
> > +		strlcpy(data->model, buf+5, sizeof(data->model));
> > +	else if (buf[4] == 'D')
> > +		strlcpy(data->fw_version, buf+5, sizeof(data->fw_version));
> > +	else
> > +		return -EPROTO;
> > +
> > +	return 0;
> > +}
> > +
> > +	error = sysfs_create_group(&client->dev.kobj, &exc3000_attribute_group);
> > +	if (error)
> > +		return error;
> > +
> > +	error = devm_add_action_or_reset(&client->dev, exc3000_unregister_sysfs, &client->dev);
> > +	if (error)
> > +		return error;
> 
> Replaced 2 calls with devm_device_add_group().

ah, I missed that because it does not have sysfs in its name and its
not in the <linux/sysfs.h>.

> Please yell if I managed to break it...

The touchscreen works as expected, sysfs files are created and
removed correctly and also work as expected. All looks good.

-- Sebastian

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-08-13 12:21 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-05 16:05 [PATCHv4 0/4] EXC3000 Updates Sebastian Reichel
2020-08-05 16:05 ` [PATCHv4 1/4] dt-bindings: touchscreen: Convert EETI EXC3000 touchscreen to json-schema Sebastian Reichel
2020-08-06 14:49   ` Rob Herring
2020-08-07  0:36   ` Dmitry Torokhov
2020-08-05 16:05 ` [PATCHv4 2/4] Input: EXC3000: add EXC80H60 and EXC80H84 support Sebastian Reichel
2020-08-06 14:49   ` Rob Herring
2020-08-07  0:37   ` Dmitry Torokhov
2020-08-05 16:05 ` [PATCHv4 3/4] Input: EXC3000: Add reset gpio support Sebastian Reichel
2020-08-06 14:50   ` Rob Herring
2020-08-07  0:37   ` Dmitry Torokhov
2020-08-05 16:05 ` [PATCHv4 4/4] Input: EXC3000: Add support to query model and fw_version Sebastian Reichel
2020-08-07  0:39   ` Dmitry Torokhov
2020-08-13 12:20     ` Sebastian Reichel

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).