2021-01-21 07:56:36

by Alistair Francis

[permalink] [raw]
Subject: [PATCH v2 0/6] Add Wacom I2C support to rM2

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 (6):
devicetree/bindings: Initial commit of wacom,wacom-i2c
input/touchscreen: Add device tree support to wacom_i2c
touchscreen/wacom_i2c: Add support for distance and tilt x/y
touchscreen/wacom_i2c: Clean up the query device fields
touchscreen/wacom_i2c: Add support for vdd regulator
arch/arm: reMarkable2: Enable wacom_i2c

.../input/touchscreen/wacom,wacom-i2c.yaml | 48 +++++++
.../devicetree/bindings/vendor-prefixes.yaml | 2 +
arch/arm/boot/dts/imx7d-remarkable2.dts | 41 ++++++
arch/arm/configs/imx_v6_v7_defconfig | 1 +
drivers/input/touchscreen/wacom_i2c.c | 136 +++++++++++++++---
5 files changed, 205 insertions(+), 23 deletions(-)
create mode 100644 Documentation/devicetree/bindings/input/touchscreen/wacom,wacom-i2c.yaml

--
2.29.2


2021-01-21 07:58:08

by Alistair Francis

[permalink] [raw]
Subject: [PATCH v2 1/6] devicetree/bindings: Initial commit of wacom,wacom-i2c

Signed-off-by: Alistair Francis <[email protected]>
---
.../input/touchscreen/wacom,wacom-i2c.yaml | 44 +++++++++++++++++++
.../devicetree/bindings/vendor-prefixes.yaml | 2 +
2 files changed, 46 insertions(+)
create mode 100644 Documentation/devicetree/bindings/input/touchscreen/wacom,wacom-i2c.yaml

diff --git a/Documentation/devicetree/bindings/input/touchscreen/wacom,wacom-i2c.yaml b/Documentation/devicetree/bindings/input/touchscreen/wacom,wacom-i2c.yaml
new file mode 100644
index 000000000000..b36d22cd20a2
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/touchscreen/wacom,wacom-i2c.yaml
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/touchscreen/wacom,wacom-i2c.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Wacom I2C Controller
+
+maintainers:
+ - Alistair Francis <[email protected]>
+
+allOf:
+ - $ref: touchscreen.yaml#
+
+properties:
+ compatible:
+ const: wacom,wacom-i2c
+
+ reg:
+ maxItems: 1
+
+ interrupts:
+ 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,wacom-i2c";
+ reg = <0x9>;
+ interrupt-parent = <&gpio1>;
+ interrupts = <9 IRQ_TYPE_LEVEL_LOW>;
+ };
+ };
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml
index 041ae90b0d8f..5bca22f035a3 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
@@ -1202,6 +1202,8 @@ patternProperties:
description: Vision Optical Technology Co., Ltd.
"^vxt,.*":
description: VXT Ltd
+ "^wacom,.*":
+ description: Wacom Co., Ltd
"^wand,.*":
description: Wandbord (Technexion)
"^waveshare,.*":
--
2.29.2

2021-01-21 20:18:27

by Alistair Francis

[permalink] [raw]
Subject: [PATCH v2 3/6] touchscreen/wacom_i2c: Add support for distance and tilt x/y

This is based on the out of tree rM2 driver.

Signed-off-by: Alistair Francis <[email protected]>
---
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 ec6e0aff8deb..5f0b80d52ad5 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.29.2

2021-01-21 20:36:47

by Alistair Francis

[permalink] [raw]
Subject: [PATCH v2 4/6] touchscreen/wacom_i2c: Clean up the query device fields

Improve the query device fields to be more verbose.

Signed-off-by: Alistair Francis <[email protected]>
---
drivers/input/touchscreen/wacom_i2c.c | 73 +++++++++++++++++++--------
1 file changed, 52 insertions(+), 21 deletions(-)

diff --git a/drivers/input/touchscreen/wacom_i2c.c b/drivers/input/touchscreen/wacom_i2c.c
index 5f0b80d52ad5..a22570adc939 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 {
@@ -45,34 +62,44 @@ struct wacom_i2c {
};

static int wacom_query_device(struct i2c_client *client,
- struct wacom_features *features)
+ 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.29.2

2021-01-22 15:55:55

by Marco Felsch

[permalink] [raw]
Subject: Re: [PATCH v2 1/6] devicetree/bindings: Initial commit of wacom, wacom-i2c

Hi,

thnaks for the patch.

On 21-01-20 22:56, Alistair Francis wrote:
> Signed-off-by: Alistair Francis <[email protected]>
> ---
> .../input/touchscreen/wacom,wacom-i2c.yaml | 44 +++++++++++++++++++
> .../devicetree/bindings/vendor-prefixes.yaml | 2 +

This should be splitted into two patches.

Regards,
Marco


> 2 files changed, 46 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/input/touchscreen/wacom,wacom-i2c.yaml
>
> diff --git a/Documentation/devicetree/bindings/input/touchscreen/wacom,wacom-i2c.yaml b/Documentation/devicetree/bindings/input/touchscreen/wacom,wacom-i2c.yaml
> new file mode 100644
> index 000000000000..b36d22cd20a2
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/input/touchscreen/wacom,wacom-i2c.yaml
> @@ -0,0 +1,44 @@
> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/input/touchscreen/wacom,wacom-i2c.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Wacom I2C Controller
> +
> +maintainers:
> + - Alistair Francis <[email protected]>
> +
> +allOf:
> + - $ref: touchscreen.yaml#
> +
> +properties:
> + compatible:
> + const: wacom,wacom-i2c
> +
> + reg:
> + maxItems: 1
> +
> + interrupts:
> + 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,wacom-i2c";
> + reg = <0x9>;
> + interrupt-parent = <&gpio1>;
> + interrupts = <9 IRQ_TYPE_LEVEL_LOW>;
> + };
> + };
> diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml
> index 041ae90b0d8f..5bca22f035a3 100644
> --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
> +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
> @@ -1202,6 +1202,8 @@ patternProperties:
> description: Vision Optical Technology Co., Ltd.
> "^vxt,.*":
> description: VXT Ltd
> + "^wacom,.*":
> + description: Wacom Co., Ltd
> "^wand,.*":
> description: Wandbord (Technexion)
> "^waveshare,.*":
> --
> 2.29.2
>
>
>

--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |

2021-01-22 16:09:30

by Marco Felsch

[permalink] [raw]
Subject: Re: [PATCH v2 3/6] touchscreen/wacom_i2c: Add support for distance and tilt x/y

Hi,

thanks for the patch. Please align all your patch-subjects belonging to
the driver to: "Input: wacom_i2c - ..."

On 21-01-20 22:56, Alistair Francis wrote:
> This is based on the out of tree rM2 driver.
>
> Signed-off-by: Alistair Francis <[email protected]>
> ---
> 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 ec6e0aff8deb..5f0b80d52ad5 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.29.2
>
>
>

--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |

2021-01-22 17:13:06

by Marco Felsch

[permalink] [raw]
Subject: Re: [PATCH v2 0/6] Add Wacom I2C support to rM2

Hi Alistair,

thanks for the patches. Before getting into the series please check all
your commit subjects. Also please check that you do only one logical
change per patch: e.g. adding DT-Support means: Add the dt-table and not
more.

I looking forward to your v2 :)

Regards,
Marco

On 21-01-20 22:56, Alistair Francis wrote:
> 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 (6):
> devicetree/bindings: Initial commit of wacom,wacom-i2c
> input/touchscreen: Add device tree support to wacom_i2c
> touchscreen/wacom_i2c: Add support for distance and tilt x/y
> touchscreen/wacom_i2c: Clean up the query device fields
> touchscreen/wacom_i2c: Add support for vdd regulator
> arch/arm: reMarkable2: Enable wacom_i2c
>
> .../input/touchscreen/wacom,wacom-i2c.yaml | 48 +++++++
> .../devicetree/bindings/vendor-prefixes.yaml | 2 +
> arch/arm/boot/dts/imx7d-remarkable2.dts | 41 ++++++
> arch/arm/configs/imx_v6_v7_defconfig | 1 +
> drivers/input/touchscreen/wacom_i2c.c | 136 +++++++++++++++---
> 5 files changed, 205 insertions(+), 23 deletions(-)
> create mode 100644 Documentation/devicetree/bindings/input/touchscreen/wacom,wacom-i2c.yaml
>
> --
> 2.29.2
>
>
>

--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |