linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/9] Add Wacom I2C support to rM2
@ 2021-03-21 14:10 Alistair Francis
  2021-03-21 14:10 ` [PATCH v3 1/9] dt-bindings: Add Wacom to vendor bindings Alistair Francis
                   ` (8 more replies)
  0 siblings, 9 replies; 14+ messages in thread
From: Alistair Francis @ 2021-03-21 14:10 UTC (permalink / raw)
  To: dmitry.torokhov, linux-input, linux-imx, kernel
  Cc: linux-kernel, alistair23, Alistair Francis

From: Alistair Francis <alistair@alistair22.me>

Add support to the reMarkable2 (rM2) for the Wacom I2C device.

This is based on the reMarkable Linux fork and with this series I am
able to probe the Wacom digitiser.

Alistair Francis (9):
  dt-bindings: Add Wacom to vendor bindings
  dt-bindings: touchscreen: Initial commit of wacom,generic
  Input: wacom_i2c - Add device tree support to wacom_i2c
  Input: wacom_i2c - Add touchscren properties
  Input: wacom_i2c - Add support for distance and tilt x/y
  Input: wacom_i2c - Clean up the query device fields
  Input: wacom_i2c - Add support for vdd regulator
  ARM: imx_v6_v7_defconfig: Enable Wacom I2C
  ARM: dts: imx7d: remarkable2: add wacom digitizer device

 .../input/touchscreen/wacom,generic.yaml      |  48 +++++++
 .../devicetree/bindings/vendor-prefixes.yaml  |   2 +
 arch/arm/boot/dts/imx7d-remarkable2.dts       |  52 +++++++
 arch/arm/configs/imx_v6_v7_defconfig          |   1 +
 drivers/input/touchscreen/wacom_i2c.c         | 129 +++++++++++++++---
 5 files changed, 210 insertions(+), 22 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/wacom,generic.yaml

-- 
2.30.1


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

* [PATCH v3 1/9] dt-bindings: Add Wacom to vendor bindings
  2021-03-21 14:10 [PATCH v3 0/9] Add Wacom I2C support to rM2 Alistair Francis
@ 2021-03-21 14:10 ` Alistair Francis
  2021-03-21 14:10 ` [PATCH v3 2/9] dt-bindings: touchscreen: Initial commit of wacom,generic Alistair Francis
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 14+ messages in thread
From: Alistair Francis @ 2021-03-21 14:10 UTC (permalink / raw)
  To: dmitry.torokhov, linux-input, linux-imx, kernel
  Cc: linux-kernel, alistair23, Alistair Francis

Signed-off-by: Alistair Francis <alistair@alistair23.me>
---
 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml
index a8e1e8d2ef20..996f4de2fff5 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
@@ -1216,6 +1216,8 @@ patternProperties:
     description: Vision Optical Technology Co., Ltd.
   "^vxt,.*":
     description: VXT Ltd
+  "^wacom,.*":
+    description: Wacom Co., Ltd
   "^wand,.*":
     description: Wandbord (Technexion)
   "^waveshare,.*":
-- 
2.30.1


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

* [PATCH v3 2/9] dt-bindings: touchscreen: Initial commit of wacom,generic
  2021-03-21 14:10 [PATCH v3 0/9] Add Wacom I2C support to rM2 Alistair Francis
  2021-03-21 14:10 ` [PATCH v3 1/9] dt-bindings: Add Wacom to vendor bindings Alistair Francis
@ 2021-03-21 14:10 ` Alistair Francis
  2021-03-21 14:10 ` [PATCH v3 3/9] Input: wacom_i2c - Add device tree support to wacom_i2c Alistair Francis
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 14+ messages in thread
From: Alistair Francis @ 2021-03-21 14:10 UTC (permalink / raw)
  To: dmitry.torokhov, linux-input, linux-imx, kernel
  Cc: linux-kernel, alistair23, Alistair Francis

Signed-off-by: Alistair Francis <alistair@alistair23.me>
---
 .../input/touchscreen/wacom,generic.yaml      | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/wacom,generic.yaml

diff --git a/Documentation/devicetree/bindings/input/touchscreen/wacom,generic.yaml b/Documentation/devicetree/bindings/input/touchscreen/wacom,generic.yaml
new file mode 100644
index 000000000000..19bbfc55ed76
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/touchscreen/wacom,generic.yaml
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/touchscreen/wacom,generic.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Wacom I2C Controller
+
+maintainers:
+  - Alistair Francis <alistair@alistair23.me>
+
+allOf:
+  - $ref: touchscreen.yaml#
+
+properties:
+  compatible:
+    const: wacom,generic
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  vdd-supply:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    #include "dt-bindings/interrupt-controller/irq.h"
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        digitiser@9 {
+                compatible = "wacom,generic";
+                reg = <0x9>;
+                interrupt-parent = <&gpio1>;
+                interrupts = <9 IRQ_TYPE_LEVEL_LOW>;
+                vdd-supply = <&reg_touch>;
+        };
+    };
-- 
2.30.1


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

* [PATCH v3 3/9] Input: wacom_i2c - Add device tree support to wacom_i2c
  2021-03-21 14:10 [PATCH v3 0/9] Add Wacom I2C support to rM2 Alistair Francis
  2021-03-21 14:10 ` [PATCH v3 1/9] dt-bindings: Add Wacom to vendor bindings Alistair Francis
  2021-03-21 14:10 ` [PATCH v3 2/9] dt-bindings: touchscreen: Initial commit of wacom,generic Alistair Francis
@ 2021-03-21 14:10 ` Alistair Francis
  2021-03-21 20:06   ` Dmitry Torokhov
  2021-03-21 14:10 ` [PATCH v3 4/9] Input: wacom_i2c - Add touchscren properties Alistair Francis
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 14+ messages in thread
From: Alistair Francis @ 2021-03-21 14:10 UTC (permalink / raw)
  To: dmitry.torokhov, linux-input, linux-imx, kernel
  Cc: linux-kernel, alistair23, Alistair Francis

Allow the wacom-i2c device to be exposed via device tree.

Signed-off-by: Alistair Francis <alistair@alistair23.me>
---
 drivers/input/touchscreen/wacom_i2c.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/input/touchscreen/wacom_i2c.c b/drivers/input/touchscreen/wacom_i2c.c
index 1afc6bde2891..fc0bf583d33b 100644
--- a/drivers/input/touchscreen/wacom_i2c.c
+++ b/drivers/input/touchscreen/wacom_i2c.c
@@ -12,6 +12,7 @@
 #include <linux/slab.h>
 #include <linux/irq.h>
 #include <linux/interrupt.h>
+#include <linux/of.h>
 #include <asm/unaligned.h>
 
 #define WACOM_CMD_QUERY0	0x04
@@ -262,10 +263,17 @@ static const struct i2c_device_id wacom_i2c_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, wacom_i2c_id);
 
+static const struct of_device_id wacom_i2c_of_match_table[] __maybe_unused = {
+	{ .compatible = "wacom,generic" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, wacom_i2c_of_match_table);
+
 static struct i2c_driver wacom_i2c_driver = {
 	.driver	= {
 		.name	= "wacom_i2c",
 		.pm	= &wacom_i2c_pm,
+		.of_match_table = of_match_ptr(wacom_i2c_of_match_table),
 	},
 
 	.probe		= wacom_i2c_probe,
-- 
2.30.1


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

* [PATCH v3 4/9] Input: wacom_i2c - Add touchscren properties
  2021-03-21 14:10 [PATCH v3 0/9] Add Wacom I2C support to rM2 Alistair Francis
                   ` (2 preceding siblings ...)
  2021-03-21 14:10 ` [PATCH v3 3/9] Input: wacom_i2c - Add device tree support to wacom_i2c Alistair Francis
@ 2021-03-21 14:10 ` Alistair Francis
  2021-03-21 20:08   ` Dmitry Torokhov
  2021-03-21 14:10 ` [PATCH v3 5/9] Input: wacom_i2c - Add support for distance and tilt x/y Alistair Francis
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 14+ messages in thread
From: Alistair Francis @ 2021-03-21 14:10 UTC (permalink / raw)
  To: dmitry.torokhov, linux-input, linux-imx, kernel
  Cc: linux-kernel, alistair23, Alistair Francis

Connect touchscreen properties to the wacom_i2c.

Signed-off-by: Alistair Francis <alistair@alistair23.me>
---
 drivers/input/touchscreen/wacom_i2c.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/input/touchscreen/wacom_i2c.c b/drivers/input/touchscreen/wacom_i2c.c
index fc0bf583d33b..9b2ed0463d09 100644
--- a/drivers/input/touchscreen/wacom_i2c.c
+++ b/drivers/input/touchscreen/wacom_i2c.c
@@ -11,6 +11,7 @@
 #include <linux/i2c.h>
 #include <linux/slab.h>
 #include <linux/irq.h>
+#include <linux/input/touchscreen.h>
 #include <linux/interrupt.h>
 #include <linux/of.h>
 #include <asm/unaligned.h>
@@ -33,6 +34,7 @@ struct wacom_features {
 struct wacom_i2c {
 	struct i2c_client *client;
 	struct input_dev *input;
+	struct touchscreen_properties props;
 	u8 data[WACOM_QUERY_SIZE];
 	bool prox;
 	int tool;
@@ -188,6 +190,7 @@ static int wacom_i2c_probe(struct i2c_client *client,
 	__set_bit(BTN_STYLUS2, input->keybit);
 	__set_bit(BTN_TOUCH, input->keybit);
 
+	touchscreen_parse_properties(input, true, &wac_i2c->props);
 	input_set_abs_params(input, ABS_X, 0, features.x_max, 0, 0);
 	input_set_abs_params(input, ABS_Y, 0, features.y_max, 0, 0);
 	input_set_abs_params(input, ABS_PRESSURE,
-- 
2.30.1


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

* [PATCH v3 5/9] Input: wacom_i2c - Add support for distance and tilt x/y
  2021-03-21 14:10 [PATCH v3 0/9] Add Wacom I2C support to rM2 Alistair Francis
                   ` (3 preceding siblings ...)
  2021-03-21 14:10 ` [PATCH v3 4/9] Input: wacom_i2c - Add touchscren properties Alistair Francis
@ 2021-03-21 14:10 ` Alistair Francis
  2021-03-21 14:10 ` [PATCH v3 6/9] Input: wacom_i2c - Clean up the query device fields Alistair Francis
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 14+ messages in thread
From: Alistair Francis @ 2021-03-21 14:10 UTC (permalink / raw)
  To: dmitry.torokhov, linux-input, linux-imx, kernel
  Cc: linux-kernel, alistair23, Alistair Francis

This is based on the out of tree rM2 driver.

Signed-off-by: Alistair Francis <alistair@alistair23.me>
---
 drivers/input/touchscreen/wacom_i2c.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/input/touchscreen/wacom_i2c.c b/drivers/input/touchscreen/wacom_i2c.c
index 9b2ed0463d09..929680dce9cf 100644
--- a/drivers/input/touchscreen/wacom_i2c.c
+++ b/drivers/input/touchscreen/wacom_i2c.c
@@ -22,12 +22,16 @@
 #define WACOM_CMD_QUERY3	0x02
 #define WACOM_CMD_THROW0	0x05
 #define WACOM_CMD_THROW1	0x00
-#define WACOM_QUERY_SIZE	19
+#define WACOM_QUERY_SIZE	22
 
 struct wacom_features {
 	int x_max;
 	int y_max;
 	int pressure_max;
+	int distance_max;
+	int distance_physical_max;
+	int tilt_x_max;
+	int tilt_y_max;
 	char fw_version;
 };
 
@@ -79,6 +83,10 @@ static int wacom_query_device(struct i2c_client *client,
 	features->y_max = get_unaligned_le16(&data[5]);
 	features->pressure_max = get_unaligned_le16(&data[11]);
 	features->fw_version = get_unaligned_le16(&data[13]);
+	features->distance_max = data[15];
+	features->distance_physical_max = data[16];
+	features->tilt_x_max = get_unaligned_le16(&data[17]);
+	features->tilt_y_max = get_unaligned_le16(&data[19]);
 
 	dev_dbg(&client->dev,
 		"x_max:%d, y_max:%d, pressure:%d, fw:%d\n",
@@ -95,6 +103,7 @@ static irqreturn_t wacom_i2c_irq(int irq, void *dev_id)
 	u8 *data = wac_i2c->data;
 	unsigned int x, y, pressure;
 	unsigned char tsw, f1, f2, ers;
+	short tilt_x, tilt_y, distance;
 	int error;
 
 	error = i2c_master_recv(wac_i2c->client,
@@ -109,6 +118,11 @@ static irqreturn_t wacom_i2c_irq(int irq, void *dev_id)
 	x = le16_to_cpup((__le16 *)&data[4]);
 	y = le16_to_cpup((__le16 *)&data[6]);
 	pressure = le16_to_cpup((__le16 *)&data[8]);
+	distance = data[10];
+
+	/* Signed */
+	tilt_x = le16_to_cpup((__le16 *)&data[11]);
+	tilt_y = le16_to_cpup((__le16 *)&data[13]);
 
 	if (!wac_i2c->prox)
 		wac_i2c->tool = (data[3] & 0x0c) ?
@@ -123,6 +137,9 @@ static irqreturn_t wacom_i2c_irq(int irq, void *dev_id)
 	input_report_abs(input, ABS_X, x);
 	input_report_abs(input, ABS_Y, y);
 	input_report_abs(input, ABS_PRESSURE, pressure);
+	input_report_abs(input, ABS_DISTANCE, distance);
+	input_report_abs(input, ABS_TILT_X, tilt_x);
+	input_report_abs(input, ABS_TILT_Y, tilt_y);
 	input_sync(input);
 
 out:
@@ -195,7 +212,11 @@ static int wacom_i2c_probe(struct i2c_client *client,
 	input_set_abs_params(input, ABS_Y, 0, features.y_max, 0, 0);
 	input_set_abs_params(input, ABS_PRESSURE,
 			     0, features.pressure_max, 0, 0);
-
+	input_set_abs_params(input, ABS_DISTANCE, 0, features.distance_max, 0, 0);
+	input_set_abs_params(input, ABS_TILT_X, -features.tilt_x_max,
+			     features.tilt_x_max, 0, 0);
+	input_set_abs_params(input, ABS_TILT_Y, -features.tilt_y_max,
+			     features.tilt_y_max, 0, 0);
 	input_set_drvdata(input, wac_i2c);
 
 	error = request_threaded_irq(client->irq, NULL, wacom_i2c_irq,
-- 
2.30.1


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

* [PATCH v3 6/9] Input: wacom_i2c - Clean up the query device fields
  2021-03-21 14:10 [PATCH v3 0/9] Add Wacom I2C support to rM2 Alistair Francis
                   ` (4 preceding siblings ...)
  2021-03-21 14:10 ` [PATCH v3 5/9] Input: wacom_i2c - Add support for distance and tilt x/y Alistair Francis
@ 2021-03-21 14:10 ` Alistair Francis
  2021-03-21 20:10   ` Dmitry Torokhov
  2021-03-21 14:10 ` [PATCH v3 7/9] Input: wacom_i2c - Add support for vdd regulator Alistair Francis
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 14+ messages in thread
From: Alistair Francis @ 2021-03-21 14:10 UTC (permalink / raw)
  To: dmitry.torokhov, linux-input, linux-imx, kernel
  Cc: linux-kernel, alistair23, Alistair Francis

Improve the query device fields to be more verbose.

Signed-off-by: Alistair Francis <alistair@alistair23.me>
---
 drivers/input/touchscreen/wacom_i2c.c | 71 +++++++++++++++++++--------
 1 file changed, 51 insertions(+), 20 deletions(-)

diff --git a/drivers/input/touchscreen/wacom_i2c.c b/drivers/input/touchscreen/wacom_i2c.c
index 929680dce9cf..7aa0d1c3dbc9 100644
--- a/drivers/input/touchscreen/wacom_i2c.c
+++ b/drivers/input/touchscreen/wacom_i2c.c
@@ -13,15 +13,32 @@
 #include <linux/irq.h>
 #include <linux/input/touchscreen.h>
 #include <linux/interrupt.h>
+#include <linux/reset.h>
 #include <linux/of.h>
 #include <asm/unaligned.h>
 
-#define WACOM_CMD_QUERY0	0x04
-#define WACOM_CMD_QUERY1	0x00
-#define WACOM_CMD_QUERY2	0x33
-#define WACOM_CMD_QUERY3	0x02
-#define WACOM_CMD_THROW0	0x05
-#define WACOM_CMD_THROW1	0x00
+// Registers
+#define WACOM_COMMAND_LSB   0x04
+#define WACOM_COMMAND_MSB   0x00
+
+#define WACOM_DATA_LSB      0x05
+#define WACOM_DATA_MSB      0x00
+
+// Report types
+#define REPORT_FEATURE      0x30
+
+// Requests / operations
+#define OPCODE_GET_REPORT   0x02
+
+// Power settings
+#define POWER_ON            0x00
+#define POWER_SLEEP         0x01
+
+// Input report ids
+#define WACOM_PEN_DATA_REPORT           2
+#define WACOM_SHINONOME_REPORT          26
+
+#define WACOM_QUERY_REPORT	3
 #define WACOM_QUERY_SIZE	22
 
 struct wacom_features {
@@ -48,31 +65,41 @@ static int wacom_query_device(struct i2c_client *client,
 			      struct wacom_features *features)
 {
 	int ret;
-	u8 cmd1[] = { WACOM_CMD_QUERY0, WACOM_CMD_QUERY1,
-			WACOM_CMD_QUERY2, WACOM_CMD_QUERY3 };
-	u8 cmd2[] = { WACOM_CMD_THROW0, WACOM_CMD_THROW1 };
 	u8 data[WACOM_QUERY_SIZE];
+	struct reset_control *rstc;
+
+	u8 get_query_data_cmd[] = {
+		WACOM_COMMAND_LSB,
+		WACOM_COMMAND_MSB,
+		REPORT_FEATURE | WACOM_QUERY_REPORT,
+		OPCODE_GET_REPORT,
+		WACOM_DATA_LSB,
+		WACOM_DATA_MSB,
+	};
+
 	struct i2c_msg msgs[] = {
+		// Request reading of feature ReportID: 3 (Pen Query Data)
 		{
 			.addr = client->addr,
 			.flags = 0,
-			.len = sizeof(cmd1),
-			.buf = cmd1,
-		},
-		{
-			.addr = client->addr,
-			.flags = 0,
-			.len = sizeof(cmd2),
-			.buf = cmd2,
+			.len = sizeof(get_query_data_cmd),
+			.buf = get_query_data_cmd,
 		},
+		// Read 21 bytes
 		{
 			.addr = client->addr,
 			.flags = I2C_M_RD,
-			.len = sizeof(data),
+			.len = WACOM_QUERY_SIZE - 1,
 			.buf = data,
 		},
 	};
 
+	rstc = devm_reset_control_get_optional_exclusive(&client->dev, NULL);
+	if (IS_ERR(rstc))
+		dev_err(&client->dev, "Failed to get reset control before init\n");
+	else
+		reset_control_reset(rstc);
+
 	ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
 	if (ret < 0)
 		return ret;
@@ -89,9 +116,13 @@ static int wacom_query_device(struct i2c_client *client,
 	features->tilt_y_max = get_unaligned_le16(&data[19]);
 
 	dev_dbg(&client->dev,
-		"x_max:%d, y_max:%d, pressure:%d, fw:%d\n",
+		"x_max:%d, y_max:%d, pressure:%d, fw:%d, "
+		"distance: %d, phys distance: %d, "
+		"tilt_x_max: %d, tilt_y_max: %d\n",
 		features->x_max, features->y_max,
-		features->pressure_max, features->fw_version);
+		features->pressure_max, features->fw_version,
+		features->distance_max, features->distance_physical_max,
+		features->tilt_x_max, features->tilt_y_max);
 
 	return 0;
 }
-- 
2.30.1


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

* [PATCH v3 7/9] Input: wacom_i2c - Add support for vdd regulator
  2021-03-21 14:10 [PATCH v3 0/9] Add Wacom I2C support to rM2 Alistair Francis
                   ` (5 preceding siblings ...)
  2021-03-21 14:10 ` [PATCH v3 6/9] Input: wacom_i2c - Clean up the query device fields Alistair Francis
@ 2021-03-21 14:10 ` Alistair Francis
  2021-03-21 21:43   ` Dmitry Torokhov
  2021-03-21 14:10 ` [PATCH v3 8/9] ARM: imx_v6_v7_defconfig: Enable Wacom I2C Alistair Francis
  2021-03-21 14:10 ` [PATCH v3 9/9] ARM: dts: imx7d: remarkable2: add wacom digitizer device Alistair Francis
  8 siblings, 1 reply; 14+ messages in thread
From: Alistair Francis @ 2021-03-21 14:10 UTC (permalink / raw)
  To: dmitry.torokhov, linux-input, linux-imx, kernel
  Cc: linux-kernel, alistair23, Alistair Francis

Add support for a VDD regulator. This allows the kernel to prove the
Wacom-I2C device on the rM2.

Signed-off-by: Alistair Francis <alistair@alistair23.me>
---
 drivers/input/touchscreen/wacom_i2c.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/input/touchscreen/wacom_i2c.c b/drivers/input/touchscreen/wacom_i2c.c
index 7aa0d1c3dbc9..00db516fa3de 100644
--- a/drivers/input/touchscreen/wacom_i2c.c
+++ b/drivers/input/touchscreen/wacom_i2c.c
@@ -13,6 +13,7 @@
 #include <linux/irq.h>
 #include <linux/input/touchscreen.h>
 #include <linux/interrupt.h>
+#include <linux/regulator/consumer.h>
 #include <linux/reset.h>
 #include <linux/of.h>
 #include <asm/unaligned.h>
@@ -56,6 +57,7 @@ struct wacom_i2c {
 	struct i2c_client *client;
 	struct input_dev *input;
 	struct touchscreen_properties props;
+	struct regulator *vdd;
 	u8 data[WACOM_QUERY_SIZE];
 	bool prox;
 	int tool;
@@ -203,11 +205,29 @@ static int wacom_i2c_probe(struct i2c_client *client,
 	struct wacom_features features = { 0 };
 	int error;
 
+	wac_i2c = kzalloc(sizeof(*wac_i2c), GFP_KERNEL);
+	if (!wac_i2c)
+		return -ENOMEM;
+
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
 		dev_err(&client->dev, "i2c_check_functionality error\n");
 		return -EIO;
 	}
 
+	wac_i2c->vdd = regulator_get(&client->dev, "vdd");
+	if (IS_ERR(wac_i2c->vdd)) {
+		error = PTR_ERR(wac_i2c->vdd);
+		kfree(wac_i2c);
+		return error;
+	}
+
+	error = regulator_enable(wac_i2c->vdd);
+	if (error) {
+		regulator_put(wac_i2c->vdd);
+		kfree(wac_i2c);
+		return error;
+	}
+
 	error = wacom_query_device(client, &features);
 	if (error)
 		return error;
@@ -275,6 +295,8 @@ static int wacom_i2c_probe(struct i2c_client *client,
 err_free_irq:
 	free_irq(client->irq, wac_i2c);
 err_free_mem:
+	regulator_disable(wac_i2c->vdd);
+	regulator_put(wac_i2c->vdd);
 	input_free_device(input);
 	kfree(wac_i2c);
 
-- 
2.30.1


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

* [PATCH v3 8/9] ARM: imx_v6_v7_defconfig: Enable Wacom I2C
  2021-03-21 14:10 [PATCH v3 0/9] Add Wacom I2C support to rM2 Alistair Francis
                   ` (6 preceding siblings ...)
  2021-03-21 14:10 ` [PATCH v3 7/9] Input: wacom_i2c - Add support for vdd regulator Alistair Francis
@ 2021-03-21 14:10 ` Alistair Francis
  2021-03-21 14:10 ` [PATCH v3 9/9] ARM: dts: imx7d: remarkable2: add wacom digitizer device Alistair Francis
  8 siblings, 0 replies; 14+ messages in thread
From: Alistair Francis @ 2021-03-21 14:10 UTC (permalink / raw)
  To: dmitry.torokhov, linux-input, linux-imx, kernel
  Cc: linux-kernel, alistair23, Alistair Francis

Enable the Wacom I2C in the imx defconfig as it is used by the
reMarkable2 tablet.

Signed-off-by: Alistair Francis <alistair@alistair23.me>
---
 arch/arm/configs/imx_v6_v7_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/imx_v6_v7_defconfig b/arch/arm/configs/imx_v6_v7_defconfig
index 70928cc48939..cd80e85d37cf 100644
--- a/arch/arm/configs/imx_v6_v7_defconfig
+++ b/arch/arm/configs/imx_v6_v7_defconfig
@@ -174,6 +174,7 @@ CONFIG_TOUCHSCREEN_DA9052=y
 CONFIG_TOUCHSCREEN_EGALAX=y
 CONFIG_TOUCHSCREEN_GOODIX=y
 CONFIG_TOUCHSCREEN_ILI210X=y
+CONFIG_TOUCHSCREEN_WACOM_I2C=y
 CONFIG_TOUCHSCREEN_MAX11801=y
 CONFIG_TOUCHSCREEN_IMX6UL_TSC=y
 CONFIG_TOUCHSCREEN_EDT_FT5X06=y
-- 
2.30.1


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

* [PATCH v3 9/9] ARM: dts: imx7d: remarkable2: add wacom digitizer device
  2021-03-21 14:10 [PATCH v3 0/9] Add Wacom I2C support to rM2 Alistair Francis
                   ` (7 preceding siblings ...)
  2021-03-21 14:10 ` [PATCH v3 8/9] ARM: imx_v6_v7_defconfig: Enable Wacom I2C Alistair Francis
@ 2021-03-21 14:10 ` Alistair Francis
  8 siblings, 0 replies; 14+ messages in thread
From: Alistair Francis @ 2021-03-21 14:10 UTC (permalink / raw)
  To: dmitry.torokhov, linux-input, linux-imx, kernel
  Cc: linux-kernel, alistair23, Alistair Francis

Enable the wacom_i2c touchscreen for the reMarkable2.

Signed-off-by: Alistair Francis <alistair@alistair23.me>
---
 arch/arm/boot/dts/imx7d-remarkable2.dts | 52 +++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/arch/arm/boot/dts/imx7d-remarkable2.dts b/arch/arm/boot/dts/imx7d-remarkable2.dts
index 7ed4eb5b8ea9..aa22b77af440 100644
--- a/arch/arm/boot/dts/imx7d-remarkable2.dts
+++ b/arch/arm/boot/dts/imx7d-remarkable2.dts
@@ -33,6 +33,19 @@ reg_brcm: regulator-brcm {
 		startup-delay-us = <150>;
 	};
 
+	reg_digitizer: regulator-digitizer {
+		compatible = "regulator-fixed";
+		regulator-name = "VDD_3V3_DIGITIZER";
+		regulator-min-microvolt = <3300000>;
+		regulator-max-microvolt = <3300000>;
+		pinctrl-names = "default", "sleep";
+		pinctrl-0 = <&pinctrl_digitizer_reg>;
+		pinctrl-1 = <&pinctrl_digitizer_reg>;
+		gpio = <&gpio1 6 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+		startup-delay-us = <100000>; /* 100 ms */
+	};
+
 	wifi_pwrseq: wifi_pwrseq {
 		compatible = "mmc-pwrseq-simple";
 		pinctrl-names = "default";
@@ -50,6 +63,28 @@ &clks {
 	assigned-clock-rates = <0>, <32768>;
 };
 
+&i2c1 {
+	clock-frequency = <400000>;
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_i2c1>;
+	status = "okay";
+
+	wacom_digitizer: digitizer@9 {
+		compatible = "wacom,generic";
+		reg = <0x09>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_wacom>;
+		interrupt-parent = <&gpio1>;
+		interrupts = <1 IRQ_TYPE_EDGE_FALLING>;
+		flip-tilt-x;
+		flip-tilt-y;
+		flip-pos-x;
+		flip-pos-y;
+		flip-distance;
+		vdd-supply = <&reg_digitizer>;
+	};
+};
+
 &snvs_pwrkey {
 	status = "okay";
 };
@@ -123,6 +158,16 @@ pinctrl_digitizer_reg: digitizerreggrp {
 			MX7D_PAD_LPSR_GPIO1_IO06__GPIO1_IO6	0x14
 		>;
 	};
+
+	pinctrl_wacom: wacomgrp {
+		fsl,pins = <
+			/*MX7D_PAD_LPSR_GPIO1_IO05__GPIO1_IO5	0x00000014 /* FWE */
+			MX7D_PAD_LPSR_GPIO1_IO04__GPIO1_IO4	0x00000074 /* PDCTB */
+			MX7D_PAD_LPSR_GPIO1_IO01__GPIO1_IO1	0x00000034 /* WACOM INT */
+			/*MX7D_PAD_LPSR_GPIO1_IO06__GPIO1_IO6	0x00000014 /* WACOM PWR ENABLE */
+			/*MX7D_PAD_LPSR_GPIO1_IO00__GPIO1_IO0	0x00000074 /* WACOM RESET */
+		>;
+	};
 };
 
 &iomuxc {
@@ -133,6 +178,13 @@ MX7D_PAD_SAI1_TX_BCLK__GPIO6_IO13	0x14
 		>;
 	};
 
+	pinctrl_i2c1: i2c1grp {
+		fsl,pins = <
+			MX7D_PAD_I2C1_SDA__I2C1_SDA		0x4000007f
+			MX7D_PAD_I2C1_SCL__I2C1_SCL		0x4000007f
+		>;
+	};
+
 	pinctrl_uart1: uart1grp {
 		fsl,pins = <
 			MX7D_PAD_UART1_TX_DATA__UART1_DCE_TX	0x79
-- 
2.30.1


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

* Re: [PATCH v3 3/9] Input: wacom_i2c - Add device tree support to wacom_i2c
  2021-03-21 14:10 ` [PATCH v3 3/9] Input: wacom_i2c - Add device tree support to wacom_i2c Alistair Francis
@ 2021-03-21 20:06   ` Dmitry Torokhov
  0 siblings, 0 replies; 14+ messages in thread
From: Dmitry Torokhov @ 2021-03-21 20:06 UTC (permalink / raw)
  To: Alistair Francis; +Cc: linux-input, linux-imx, kernel, linux-kernel, alistair23

Hi Alistair,

On Sun, Mar 21, 2021 at 10:10:43AM -0400, Alistair Francis wrote:
> Allow the wacom-i2c device to be exposed via device tree.
> 
> Signed-off-by: Alistair Francis <alistair@alistair23.me>
> ---
>  drivers/input/touchscreen/wacom_i2c.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/input/touchscreen/wacom_i2c.c b/drivers/input/touchscreen/wacom_i2c.c
> index 1afc6bde2891..fc0bf583d33b 100644
> --- a/drivers/input/touchscreen/wacom_i2c.c
> +++ b/drivers/input/touchscreen/wacom_i2c.c
> @@ -12,6 +12,7 @@
>  #include <linux/slab.h>
>  #include <linux/irq.h>
>  #include <linux/interrupt.h>
> +#include <linux/of.h>
>  #include <asm/unaligned.h>
>  
>  #define WACOM_CMD_QUERY0	0x04
> @@ -262,10 +263,17 @@ static const struct i2c_device_id wacom_i2c_id[] = {
>  };
>  MODULE_DEVICE_TABLE(i2c, wacom_i2c_id);
>  
> +static const struct of_device_id wacom_i2c_of_match_table[] __maybe_unused = {
> +	{ .compatible = "wacom,generic" },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(of, wacom_i2c_of_match_table);
> +
>  static struct i2c_driver wacom_i2c_driver = {
>  	.driver	= {
>  		.name	= "wacom_i2c",
>  		.pm	= &wacom_i2c_pm,
> +		.of_match_table = of_match_ptr(wacom_i2c_of_match_table),

You need to either guard wacom_i2c_of_match_table by #ifdef CONFIG_OF or
drop of_match_ptr() and assign directly as otherwise you will get
"unused variable" warning.

Thanks.

-- 
Dmitry

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

* Re: [PATCH v3 4/9] Input: wacom_i2c - Add touchscren properties
  2021-03-21 14:10 ` [PATCH v3 4/9] Input: wacom_i2c - Add touchscren properties Alistair Francis
@ 2021-03-21 20:08   ` Dmitry Torokhov
  0 siblings, 0 replies; 14+ messages in thread
From: Dmitry Torokhov @ 2021-03-21 20:08 UTC (permalink / raw)
  To: Alistair Francis; +Cc: linux-input, linux-imx, kernel, linux-kernel, alistair23

On Sun, Mar 21, 2021 at 10:10:44AM -0400, Alistair Francis wrote:
> Connect touchscreen properties to the wacom_i2c.
> 
> Signed-off-by: Alistair Francis <alistair@alistair23.me>
> ---
>  drivers/input/touchscreen/wacom_i2c.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/input/touchscreen/wacom_i2c.c b/drivers/input/touchscreen/wacom_i2c.c
> index fc0bf583d33b..9b2ed0463d09 100644
> --- a/drivers/input/touchscreen/wacom_i2c.c
> +++ b/drivers/input/touchscreen/wacom_i2c.c
> @@ -11,6 +11,7 @@
>  #include <linux/i2c.h>
>  #include <linux/slab.h>
>  #include <linux/irq.h>
> +#include <linux/input/touchscreen.h>
>  #include <linux/interrupt.h>
>  #include <linux/of.h>
>  #include <asm/unaligned.h>
> @@ -33,6 +34,7 @@ struct wacom_features {
>  struct wacom_i2c {
>  	struct i2c_client *client;
>  	struct input_dev *input;
> +	struct touchscreen_properties props;
>  	u8 data[WACOM_QUERY_SIZE];
>  	bool prox;
>  	int tool;
> @@ -188,6 +190,7 @@ static int wacom_i2c_probe(struct i2c_client *client,
>  	__set_bit(BTN_STYLUS2, input->keybit);
>  	__set_bit(BTN_TOUCH, input->keybit);
>  
> +	touchscreen_parse_properties(input, true, &wac_i2c->props);
>  	input_set_abs_params(input, ABS_X, 0, features.x_max, 0, 0);
>  	input_set_abs_params(input, ABS_Y, 0, features.y_max, 0, 0);
>  	input_set_abs_params(input, ABS_PRESSURE,

Please also use touchscreen_report_pos() so flipping and swapping of
axes also works.

Thanks.

-- 
Dmitry

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

* Re: [PATCH v3 6/9] Input: wacom_i2c - Clean up the query device fields
  2021-03-21 14:10 ` [PATCH v3 6/9] Input: wacom_i2c - Clean up the query device fields Alistair Francis
@ 2021-03-21 20:10   ` Dmitry Torokhov
  0 siblings, 0 replies; 14+ messages in thread
From: Dmitry Torokhov @ 2021-03-21 20:10 UTC (permalink / raw)
  To: Alistair Francis; +Cc: linux-input, linux-imx, kernel, linux-kernel, alistair23

On Sun, Mar 21, 2021 at 10:10:46AM -0400, Alistair Francis wrote:
> Improve the query device fields to be more verbose.
> 
> Signed-off-by: Alistair Francis <alistair@alistair23.me>
> ---
>  drivers/input/touchscreen/wacom_i2c.c | 71 +++++++++++++++++++--------
...
>  
> +	rstc = devm_reset_control_get_optional_exclusive(&client->dev, NULL);
> +	if (IS_ERR(rstc))
> +		dev_err(&client->dev, "Failed to get reset control before init\n");
> +	else
> +		reset_control_reset(rstc);

This seems misplaced. Also, reset controls are typically for resetting
the system, for resetting peripherals we expose reset GPIO lines.

Thanks.

-- 
Dmitry

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

* Re: [PATCH v3 7/9] Input: wacom_i2c - Add support for vdd regulator
  2021-03-21 14:10 ` [PATCH v3 7/9] Input: wacom_i2c - Add support for vdd regulator Alistair Francis
@ 2021-03-21 21:43   ` Dmitry Torokhov
  0 siblings, 0 replies; 14+ messages in thread
From: Dmitry Torokhov @ 2021-03-21 21:43 UTC (permalink / raw)
  To: Alistair Francis; +Cc: linux-input, linux-imx, kernel, linux-kernel, alistair23

On Sun, Mar 21, 2021 at 10:10:47AM -0400, Alistair Francis wrote:
> Add support for a VDD regulator. This allows the kernel to prove the
> Wacom-I2C device on the rM2.
> 
> Signed-off-by: Alistair Francis <alistair@alistair23.me>
> ---
>  drivers/input/touchscreen/wacom_i2c.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/drivers/input/touchscreen/wacom_i2c.c b/drivers/input/touchscreen/wacom_i2c.c
> index 7aa0d1c3dbc9..00db516fa3de 100644
> --- a/drivers/input/touchscreen/wacom_i2c.c
> +++ b/drivers/input/touchscreen/wacom_i2c.c
> @@ -13,6 +13,7 @@
>  #include <linux/irq.h>
>  #include <linux/input/touchscreen.h>
>  #include <linux/interrupt.h>
> +#include <linux/regulator/consumer.h>
>  #include <linux/reset.h>
>  #include <linux/of.h>
>  #include <asm/unaligned.h>
> @@ -56,6 +57,7 @@ struct wacom_i2c {
>  	struct i2c_client *client;
>  	struct input_dev *input;
>  	struct touchscreen_properties props;
> +	struct regulator *vdd;
>  	u8 data[WACOM_QUERY_SIZE];
>  	bool prox;
>  	int tool;
> @@ -203,11 +205,29 @@ static int wacom_i2c_probe(struct i2c_client *client,
>  	struct wacom_features features = { 0 };
>  	int error;
>  
> +	wac_i2c = kzalloc(sizeof(*wac_i2c), GFP_KERNEL);
> +	if (!wac_i2c)
> +		return -ENOMEM;
> +
>  	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
>  		dev_err(&client->dev, "i2c_check_functionality error\n");
>  		return -EIO;

You are leaking memory here. Additionally, I do not see you removing the
original allocation below, so I think you end up with 2 instances of
structure wacom_i2c.

Thanks.

-- 
Dmitry

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

end of thread, other threads:[~2021-03-21 21:44 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-21 14:10 [PATCH v3 0/9] Add Wacom I2C support to rM2 Alistair Francis
2021-03-21 14:10 ` [PATCH v3 1/9] dt-bindings: Add Wacom to vendor bindings Alistair Francis
2021-03-21 14:10 ` [PATCH v3 2/9] dt-bindings: touchscreen: Initial commit of wacom,generic Alistair Francis
2021-03-21 14:10 ` [PATCH v3 3/9] Input: wacom_i2c - Add device tree support to wacom_i2c Alistair Francis
2021-03-21 20:06   ` Dmitry Torokhov
2021-03-21 14:10 ` [PATCH v3 4/9] Input: wacom_i2c - Add touchscren properties Alistair Francis
2021-03-21 20:08   ` Dmitry Torokhov
2021-03-21 14:10 ` [PATCH v3 5/9] Input: wacom_i2c - Add support for distance and tilt x/y Alistair Francis
2021-03-21 14:10 ` [PATCH v3 6/9] Input: wacom_i2c - Clean up the query device fields Alistair Francis
2021-03-21 20:10   ` Dmitry Torokhov
2021-03-21 14:10 ` [PATCH v3 7/9] Input: wacom_i2c - Add support for vdd regulator Alistair Francis
2021-03-21 21:43   ` Dmitry Torokhov
2021-03-21 14:10 ` [PATCH v3 8/9] ARM: imx_v6_v7_defconfig: Enable Wacom I2C Alistair Francis
2021-03-21 14:10 ` [PATCH v3 9/9] ARM: dts: imx7d: remarkable2: add wacom digitizer device Alistair Francis

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