diff mbox series

[v2,1/2] Input: zinitix - Read and cache device version numbers

Message ID 20240830-zinitix-tk-versions-v2-1-90eae6817eda@linaro.org (mailing list archive)
State Mainlined
Commit 5278bb4cd6e96504ad4700bc1e445fbe7d6711e3
Headers show
Series Input: zinitix - Handle chip revisions for touchkeys | expand

Commit Message

Linus Walleij Aug. 30, 2024, 2:04 p.m. UTC
The chip hardware revision, firmware version and regdata
revision is needed to discern because for example touchkeys
are handled by different registers on different versions of
the chip. Example output from BT404:

Zinitix-TS 3-0020: chip revision 4040 firmware version 0088
  regdata version 0004

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- Move read status into the per-device struct.
---
 drivers/input/touchscreen/zinitix.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

Comments

Dmitry Torokhov Sept. 1, 2024, 2:07 a.m. UTC | #1
Hi Linus,

On Fri, Aug 30, 2024 at 04:04:27PM +0200, Linus Walleij wrote:
> The chip hardware revision, firmware version and regdata
> revision is needed to discern because for example touchkeys
> are handled by different registers on different versions of
> the chip. Example output from BT404:
> 
> Zinitix-TS 3-0020: chip revision 4040 firmware version 0088
>   regdata version 0004
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> ChangeLog v1->v2:
> - Move read status into the per-device struct.

Thanks for making this change.

> ---
>  drivers/input/touchscreen/zinitix.c | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/drivers/input/touchscreen/zinitix.c b/drivers/input/touchscreen/zinitix.c
> index 1df93c96f6bf..e47e0bff80db 100644
> --- a/drivers/input/touchscreen/zinitix.c
> +++ b/drivers/input/touchscreen/zinitix.c
> @@ -150,6 +150,10 @@ struct bt541_ts_data {
>  	u32 zinitix_mode;
>  	u32 keycodes[MAX_SUPPORTED_BUTTON_NUM];
>  	int num_keycodes;
> +	bool read_versioninfo;

I renamed this to "have_versioninfo" and applied.

Thanks.
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/zinitix.c b/drivers/input/touchscreen/zinitix.c
index 1df93c96f6bf..e47e0bff80db 100644
--- a/drivers/input/touchscreen/zinitix.c
+++ b/drivers/input/touchscreen/zinitix.c
@@ -150,6 +150,10 @@  struct bt541_ts_data {
 	u32 zinitix_mode;
 	u32 keycodes[MAX_SUPPORTED_BUTTON_NUM];
 	int num_keycodes;
+	bool read_versioninfo;
+	u16 chip_revision;
+	u16 firmware_version;
+	u16 regdata_version;
 };
 
 static int zinitix_read_data(struct i2c_client *client,
@@ -194,6 +198,18 @@  static int zinitix_write_cmd(struct i2c_client *client, u16 reg)
 	return 0;
 }
 
+static u16 zinitix_get_u16_reg(struct bt541_ts_data *bt541, u16 vreg)
+{
+	struct i2c_client *client = bt541->client;
+	int error;
+	__le16 val;
+
+	error = zinitix_read_data(client, vreg, (void *)&val, 2);
+	if (error)
+		return U8_MAX;
+        return le16_to_cpu(val);
+}
+
 static int zinitix_init_touch(struct bt541_ts_data *bt541)
 {
 	struct i2c_client *client = bt541->client;
@@ -207,6 +223,24 @@  static int zinitix_init_touch(struct bt541_ts_data *bt541)
 		return error;
 	}
 
+	/*
+	 * Read and cache the chip revision and firmware version the first time
+	 * we get here.
+	 */
+	if (!bt541->read_versioninfo) {
+		bt541->chip_revision = zinitix_get_u16_reg(bt541,
+					ZINITIX_CHIP_REVISION);
+		bt541->firmware_version = zinitix_get_u16_reg(bt541,
+					ZINITIX_FIRMWARE_VERSION);
+		bt541->regdata_version = zinitix_get_u16_reg(bt541,
+					ZINITIX_DATA_VERSION_REG);
+		dev_dbg(&client->dev,
+			"chip revision %04x firmware version %04x regdata version %04x\n",
+			bt541->chip_revision, bt541->firmware_version,
+			bt541->regdata_version);
+		bt541->read_versioninfo = true;
+	}
+
 	error = zinitix_write_u16(client, ZINITIX_INT_ENABLE_FLAG, 0x0);
 	if (error) {
 		dev_err(&client->dev,