Skip to content

Commit bfd9b92

Browse files
jinglewudtor
authored andcommitted
Input: elan_i2c - handle firmware updated on newer ICs
Newer ICs with IC type value starting with 0x0D and newer bootloader code use 128-byte firmware pages. Their bootloader also needs to be switched to proper mode before executing firmware update. Signed-off-by: Jingle Wu <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 059d6c2 commit bfd9b92

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

drivers/input/mouse/elan_i2c.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ struct elan_transport_ops {
7474
int (*iap_get_mode)(struct i2c_client *client, enum tp_mode *mode);
7575
int (*iap_reset)(struct i2c_client *client);
7676

77-
int (*prepare_fw_update)(struct i2c_client *client);
77+
int (*prepare_fw_update)(struct i2c_client *client, u16 ic_type,
78+
u8 iap_version);
7879
int (*write_fw_block)(struct i2c_client *client, u16 fw_page_size,
7980
const u8 *page, u16 checksum, int idx);
8081
int (*finish_fw_update)(struct i2c_client *client,

drivers/input/mouse/elan_i2c_core.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct elan_tp_data {
101101
bool middle_button;
102102
};
103103

104-
static int elan_get_fwinfo(u16 ic_type, u16 *validpage_count,
104+
static int elan_get_fwinfo(u16 ic_type, u8 iap_version, u16 *validpage_count,
105105
u32 *signature_address, u16 *page_size)
106106
{
107107
switch (ic_type) {
@@ -138,7 +138,12 @@ static int elan_get_fwinfo(u16 ic_type, u16 *validpage_count,
138138
*signature_address =
139139
(*validpage_count * ETP_FW_PAGE_SIZE) - ETP_FW_SIGNATURE_SIZE;
140140

141-
*page_size = ETP_FW_PAGE_SIZE;
141+
if (ic_type >= 0x0D && iap_version >= 1) {
142+
*validpage_count /= 2;
143+
*page_size = ETP_FW_PAGE_SIZE_128;
144+
} else {
145+
*page_size = ETP_FW_PAGE_SIZE;
146+
}
142147

143148
return 0;
144149
}
@@ -339,7 +344,8 @@ static int elan_query_device_info(struct elan_tp_data *data)
339344
if (error)
340345
return error;
341346

342-
error = elan_get_fwinfo(data->ic_type, &data->fw_validpage_count,
347+
error = elan_get_fwinfo(data->ic_type, data->iap_version,
348+
&data->fw_validpage_count,
343349
&data->fw_signature_address,
344350
&data->fw_page_size);
345351
if (error)
@@ -459,7 +465,8 @@ static int __elan_update_firmware(struct elan_tp_data *data,
459465
u16 boot_page_count;
460466
u16 sw_checksum = 0, fw_checksum = 0;
461467

462-
error = data->ops->prepare_fw_update(client);
468+
error = data->ops->prepare_fw_update(client, data->ic_type,
469+
data->iap_version);
463470
if (error)
464471
return error;
465472

drivers/input/mouse/elan_i2c_i2c.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
#define ETP_I2C_CALIBRATE_CMD 0x0316
5757
#define ETP_I2C_MAX_BASELINE_CMD 0x0317
5858
#define ETP_I2C_MIN_BASELINE_CMD 0x0318
59+
#define ETP_I2C_IAP_TYPE_REG 0x0040
60+
#define ETP_I2C_IAP_TYPE_CMD 0x0304
5961

6062
#define ETP_I2C_REPORT_LEN 34
6163
#define ETP_I2C_DESC_LENGTH 30
@@ -528,7 +530,43 @@ static int elan_i2c_set_flash_key(struct i2c_client *client)
528530
return 0;
529531
}
530532

531-
static int elan_i2c_prepare_fw_update(struct i2c_client *client)
533+
static int elan_read_write_iap_type(struct i2c_client *client)
534+
{
535+
int error;
536+
u16 constant;
537+
u8 val[3];
538+
int retry = 3;
539+
540+
do {
541+
error = elan_i2c_write_cmd(client, ETP_I2C_IAP_TYPE_CMD,
542+
ETP_I2C_IAP_TYPE_REG);
543+
if (error) {
544+
dev_err(&client->dev,
545+
"cannot write iap type: %d\n", error);
546+
return error;
547+
}
548+
549+
error = elan_i2c_read_cmd(client, ETP_I2C_IAP_TYPE_CMD, val);
550+
if (error) {
551+
dev_err(&client->dev,
552+
"failed to read iap type register: %d\n",
553+
error);
554+
return error;
555+
}
556+
constant = le16_to_cpup((__le16 *)val);
557+
dev_dbg(&client->dev, "iap type reg: 0x%04x\n", constant);
558+
559+
if (constant == ETP_I2C_IAP_TYPE_REG)
560+
return 0;
561+
562+
} while (--retry > 0);
563+
564+
dev_err(&client->dev, "cannot set iap type\n");
565+
return -EIO;
566+
}
567+
568+
static int elan_i2c_prepare_fw_update(struct i2c_client *client, u16 ic_type,
569+
u8 iap_version)
532570
{
533571
struct device *dev = &client->dev;
534572
int error;
@@ -568,6 +606,12 @@ static int elan_i2c_prepare_fw_update(struct i2c_client *client)
568606
return -EIO;
569607
}
570608

609+
if (ic_type >= 0x0D && iap_version >= 1) {
610+
error = elan_read_write_iap_type(client);
611+
if (error)
612+
return error;
613+
}
614+
571615
/* Set flash key again */
572616
error = elan_i2c_set_flash_key(client);
573617
if (error)

drivers/input/mouse/elan_i2c_smbus.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ static int elan_smbus_set_flash_key(struct i2c_client *client)
340340
return 0;
341341
}
342342

343-
static int elan_smbus_prepare_fw_update(struct i2c_client *client)
343+
static int elan_smbus_prepare_fw_update(struct i2c_client *client, u16 ic_type,
344+
u8 iap_version)
344345
{
345346
struct device *dev = &client->dev;
346347
int len;

0 commit comments

Comments
 (0)