Input: elan_i2c - make fetching IC type of older controllers more robust
authorJingle Wu <jingle.wu@emc.com.tw>
Thu, 16 Jul 2020 05:25:59 +0000 (22:25 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Sat, 18 Jul 2020 00:35:58 +0000 (17:35 -0700)
On older controllers IC type is reported in the 2nd byte of
ETP_I2C_OSM_VERSION_CMD, however if controller's firmware is not flashed
correctly it may return incorrect data. Fortunately there is also
ETP_I2C_IAP_VERSION_P0_CMD command that can be used when controller in
either normal or IAP mode, and which is guaranteed to return accurate data,
so let's use it.

Signed-off-by: Jingle Wu <jingle.wu@emc.com.tw>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/mouse/elan_i2c_core.c
drivers/input/mouse/elan_i2c_i2c.c

index 8719da5..f1dade6 100644 (file)
@@ -312,7 +312,6 @@ static int elan_initialize(struct elan_tp_data *data)
 static int elan_query_device_info(struct elan_tp_data *data)
 {
        int error;
-       u16 ic_type;
 
        error = data->ops->get_version(data->client, false, &data->fw_version);
        if (error)
@@ -336,12 +335,7 @@ static int elan_query_device_info(struct elan_tp_data *data)
        if (error)
                return error;
 
-       if (data->pattern == 0x01)
-               ic_type = data->ic_type;
-       else
-               ic_type = data->iap_version;
-
-       error = elan_get_fwinfo(ic_type, &data->fw_validpage_count,
+       error = elan_get_fwinfo(data->ic_type, &data->fw_validpage_count,
                                &data->fw_signature_address);
        if (error)
                dev_warn(&data->client->dev,
index 0d8a6a1..bceb4bc 100644 (file)
@@ -43,6 +43,7 @@
 #define ETP_I2C_RESOLUTION_CMD         0x0108
 #define ETP_I2C_PRESSURE_CMD           0x010A
 #define ETP_I2C_IAP_VERSION_CMD                0x0110
+#define ETP_I2C_IC_TYPE_P0_CMD         0x0110
 #define ETP_I2C_SET_CMD                        0x0300
 #define ETP_I2C_POWER_CMD              0x0307
 #define ETP_I2C_FW_CHECKSUM_CMD                0x030F
@@ -330,7 +331,14 @@ static int elan_i2c_get_sm_version(struct i2c_client *client,
                        return error;
                }
                *version = val[0];
-               *ic_type = val[1];
+
+               error = elan_i2c_read_cmd(client, ETP_I2C_IC_TYPE_P0_CMD, val);
+               if (error) {
+                       dev_err(&client->dev, "failed to get ic type: %d\n",
+                               error);
+                       return error;
+               }
+               *ic_type = val[0];
 
                error = elan_i2c_read_cmd(client, ETP_I2C_NSM_VERSION_CMD,
                                          val);