Skip to content

Commit

Permalink
Input: elan_i2c - make fetching IC type of older controllers more robust
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jingle Wu authored and Dmitry Torokhov committed Jul 18, 2020
1 parent 77da21c commit fc7c882
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 1 addition & 7 deletions drivers/input/mouse/elan_i2c_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion drivers/input/mouse/elan_i2c_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fc7c882

Please sign in to comment.