diff mbox series

[2/3] input/touchscreen: Add device tree support to wacom_i2c

Message ID 20210117042428.1497-2-alistair@alistair23.me (mailing list archive)
State New, archived
Headers show
Series [1/3] devicetree/bindings: Initial commit of wacom,wacom-i2c | expand

Commit Message

Alistair Francis Jan. 17, 2021, 4:24 a.m. UTC
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 | 38 +++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

Comments

Dmitry Torokhov Jan. 20, 2021, 2:17 a.m. UTC | #1
On Sat, Jan 16, 2021 at 08:24:27PM -0800, Alistair Francis wrote:
> Allow the wacom-i2c device to be exposed via device tree.

The patch seems incomplete. I see we are reading and storing properties,
but we are not using them whatsoever, so I do not see the reason to have
this in this form.

Thanks.
Alistair Francis Jan. 21, 2021, 6:51 a.m. UTC | #2
On Tue, Jan 19, 2021 at 6:17 PM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
>
> On Sat, Jan 16, 2021 at 08:24:27PM -0800, Alistair Francis wrote:
> > Allow the wacom-i2c device to be exposed via device tree.
>
> The patch seems incomplete. I see we are reading and storing properties,
> but we are not using them whatsoever, so I do not see the reason to have
> this in this form.

Good point. I am trying to split up the work, but I guess here I split
it up a little too much. I'm sending a v2 that should fix this.

Alistair

>
> Thanks.
>
> --
> Dmitry
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/wacom_i2c.c b/drivers/input/touchscreen/wacom_i2c.c
index 1afc6bde2891..54af2934ba17 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
@@ -35,6 +36,13 @@  struct wacom_i2c {
 	u8 data[WACOM_QUERY_SIZE];
 	bool prox;
 	int tool;
+
+	bool flip_tilt_x;
+	bool flip_tilt_y;
+	bool flip_pos_x;
+	bool flip_pos_y;
+	bool flip_distance;
+	bool flip_pressure;
 };
 
 static int wacom_query_device(struct i2c_client *client,
@@ -144,6 +152,20 @@  static void wacom_i2c_close(struct input_dev *dev)
 	disable_irq(client->irq);
 }
 
+#ifdef CONFIG_OF
+static void wacom_of_read(struct wacom_i2c *wac_i2c)
+{
+	struct i2c_client *client = wac_i2c->client;
+
+	wac_i2c->flip_tilt_x = of_property_read_bool(client->dev.of_node, "flip-tilt-x");
+	wac_i2c->flip_tilt_y = of_property_read_bool(client->dev.of_node, "flip-tilt-y");
+	wac_i2c->flip_pos_x = of_property_read_bool(client->dev.of_node, "flip-pos-x");
+	wac_i2c->flip_pos_y = of_property_read_bool(client->dev.of_node, "flip-pos-y");
+	wac_i2c->flip_distance = of_property_read_bool(client->dev.of_node, "flip-distance");
+	wac_i2c->flip_pressure = of_property_read_bool(client->dev.of_node, "flip-pressure");
+}
+#endif
+
 static int wacom_i2c_probe(struct i2c_client *client,
 				     const struct i2c_device_id *id)
 {
@@ -214,6 +236,11 @@  static int wacom_i2c_probe(struct i2c_client *client,
 	}
 
 	i2c_set_clientdata(client, wac_i2c);
+
+#ifdef CONFIG_OF
+	wacom_of_read(wac_i2c);
+#endif
+
 	return 0;
 
 err_free_irq:
@@ -262,10 +289,21 @@  static const struct i2c_device_id wacom_i2c_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, wacom_i2c_id);
 
+#ifdef CONFIG_OF
+static const struct of_device_id wacom_i2c_of_match_table[] = {
+	{ .compatible = "wacom,wacom-i2c" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, wacom_i2c_of_match_table);
+#endif
+
 static struct i2c_driver wacom_i2c_driver = {
 	.driver	= {
 		.name	= "wacom_i2c",
 		.pm	= &wacom_i2c_pm,
+#ifdef CONFIG_OF
+		.of_match_table = of_match_ptr(wacom_i2c_of_match_table),
+#endif
 	},
 
 	.probe		= wacom_i2c_probe,