summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2016-09-15 22:51:50 -0700
committerGerrit - the friendly Code Review server <code-review@localhost>2016-09-15 22:51:49 -0700
commit38f8a6a3133af23ca9140406e058c210c584078d (patch)
tree63add9cc4049a8d028c2347a1eab7f731fb3375f /drivers
parent4ab368becd625ba1a02b4f852328d6f012200ef4 (diff)
parent45e3baf40bf8aed8217a42bdb3ed1bea0f92369d (diff)
Merge "input: touchscreen: pull down reset and interrupt pin before GT9xx powerup"
Diffstat (limited to 'drivers')
-rw-r--r--drivers/input/touchscreen/gt9xx/goodix_tool.c59
-rw-r--r--drivers/input/touchscreen/gt9xx/gt9xx.c233
-rw-r--r--drivers/input/touchscreen/gt9xx/gt9xx.h58
-rw-r--r--drivers/input/touchscreen/gt9xx/gt9xx_update.c254
4 files changed, 282 insertions, 322 deletions
diff --git a/drivers/input/touchscreen/gt9xx/goodix_tool.c b/drivers/input/touchscreen/gt9xx/goodix_tool.c
index 59de914cceef..c67c4c8f1207 100644
--- a/drivers/input/touchscreen/gt9xx/goodix_tool.c
+++ b/drivers/input/touchscreen/gt9xx/goodix_tool.c
@@ -91,18 +91,21 @@ static void tool_set_proc_name(char *procname)
static s32 tool_i2c_read_no_extra(u8 *buf, u16 len)
{
s32 ret = -1;
- s32 i = 0;
- struct i2c_msg msgs[2];
-
- msgs[0].flags = !I2C_M_RD;
- msgs[0].addr = gt_client->addr;
- msgs[0].len = cmd_head.addr_len;
- msgs[0].buf = &buf[0];
-
- msgs[1].flags = I2C_M_RD;
- msgs[1].addr = gt_client->addr;
- msgs[1].len = len;
- msgs[1].buf = &buf[GTP_ADDR_LENGTH];
+ u8 i = 0;
+ struct i2c_msg msgs[2] = {
+ {
+ .flags = !I2C_M_RD,
+ .addr = gt_client->addr,
+ .len = cmd_head.addr_len,
+ .buf = &buf[0],
+ },
+ {
+ .flags = I2C_M_RD,
+ .addr = gt_client->addr,
+ .len = len,
+ .buf = &buf[GTP_ADDR_LENGTH],
+ },
+ };
for (i = 0; i < cmd_head.retry; i++) {
ret = i2c_transfer(gt_client->adapter, msgs, 2);
@@ -110,25 +113,35 @@ static s32 tool_i2c_read_no_extra(u8 *buf, u16 len)
break;
}
+ if (i == cmd_head.retry) {
+ dev_err(&client->dev, "I2C read retry limit over.\n");
+ ret = -EIO;
+ }
+
return ret;
}
static s32 tool_i2c_write_no_extra(u8 *buf, u16 len)
{
s32 ret = -1;
- s32 i = 0;
- struct i2c_msg msg;
-
- msg.flags = !I2C_M_RD;
- msg.addr = gt_client->addr;
- msg.len = len;
- msg.buf = buf;
+ u8 i = 0;
+ struct i2c_msg msg = {
+ .flags = !I2C_M_RD,
+ .addr = gt_client->addr,
+ .len = len,
+ .buf = buf,
+ };
for (i = 0; i < cmd_head.retry; i++) {
ret = i2c_transfer(gt_client->adapter, &msg, 1);
if (ret > 0)
break;
- }
+ }
+
+ if (i == cmd_head.retry) {
+ dev_err(&client->dev, "I2C write retry limit over.\n");
+ ret = -EIO;
+ }
return ret;
}
@@ -192,8 +205,9 @@ s32 init_wr_node(struct i2c_client *client)
i = 5;
while ((!cmd_head.data) && i) {
- cmd_head.data = kzalloc(i * DATA_LENGTH_UINT, GFP_KERNEL);
- if (cmd_head.data != NULL)
+ cmd_head.data = devm_kzalloc(&client->dev,
+ i * DATA_LENGTH_UINT, GFP_KERNEL);
+ if (cmd_head.data)
break;
i--;
}
@@ -226,7 +240,6 @@ s32 init_wr_node(struct i2c_client *client)
void uninit_wr_node(void)
{
- kfree(cmd_head.data);
cmd_head.data = NULL;
unregister_i2c_func();
remove_proc_entry(procname, NULL);
diff --git a/drivers/input/touchscreen/gt9xx/gt9xx.c b/drivers/input/touchscreen/gt9xx/gt9xx.c
index 4d71d474c113..6c3747108d75 100644
--- a/drivers/input/touchscreen/gt9xx/gt9xx.c
+++ b/drivers/input/touchscreen/gt9xx/gt9xx.c
@@ -68,7 +68,8 @@
#define RESET_DELAY_T3_US 200 /* T3: > 100us */
#define RESET_DELAY_T4 20 /* T4: > 5ms */
-#define PHY_BUF_SIZE 32
+#define PHY_BUF_SIZE 32
+#define PROP_NAME_SIZE 24
#define GTP_MAX_TOUCH 5
#define GTP_ESD_CHECK_CIRCLE_MS 2000
@@ -151,13 +152,13 @@ int gtp_i2c_read(struct i2c_client *client, u8 *buf, int len)
},
};
- for (retries = 0; retries < 5; retries++) {
+ for (retries = 0; retries < GTP_I2C_RETRY_5; retries++) {
ret = i2c_transfer(client->adapter, msgs, 2);
if (ret == 2)
break;
dev_err(&client->dev, "I2C retry: %d\n", retries + 1);
}
- if (retries == 5) {
+ if (retries == GTP_I2C_RETRY_5) {
#if GTP_SLIDE_WAKEUP
/* reset chip would quit doze mode */
if (doze_status == DOZE_ENABLED)
@@ -197,13 +198,13 @@ int gtp_i2c_write(struct i2c_client *client, u8 *buf, int len)
.buf = buf,
};
- for (retries = 0; retries < 5; retries++) {
+ for (retries = 0; retries < GTP_I2C_RETRY_5; retries++) {
ret = i2c_transfer(client->adapter, &msg, 1);
if (ret == 1)
break;
dev_err(&client->dev, "I2C retry: %d\n", retries + 1);
}
- if ((retries == 5)) {
+ if (retries == GTP_I2C_RETRY_5) {
#if GTP_SLIDE_WAKEUP
if (doze_status == DOZE_ENABLED)
return ret;
@@ -237,7 +238,7 @@ int gtp_i2c_read_dbl_check(struct i2c_client *client,
u8 confirm_buf[16] = {0};
u8 retry = 0;
- while (retry++ < 3) {
+ while (retry++ < GTP_I2C_RETRY_3) {
memset(buf, 0xAA, 16);
buf[0] = (u8)(addr >> 8);
buf[1] = (u8)(addr & 0xFF);
@@ -251,7 +252,7 @@ int gtp_i2c_read_dbl_check(struct i2c_client *client,
if (!memcmp(buf, confirm_buf, len + 2))
break;
}
- if (retry < 3) {
+ if (retry < GTP_I2C_RETRY_3) {
memcpy(rxbuf, confirm_buf + 2, len);
return SUCCESS;
}
@@ -280,7 +281,7 @@ static int gtp_send_cfg(struct goodix_ts_data *ts)
"Ic fixed config, no config sent!");
ret = 2;
} else {
- for (retry = 0; retry < 5; retry++) {
+ for (retry = 0; retry < GTP_I2C_RETRY_5; retry++) {
ret = gtp_i2c_write(ts->client,
ts->config_data,
GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH);
@@ -719,7 +720,7 @@ static s8 gtp_enter_doze(struct goodix_ts_data *ts)
#endif
gtp_irq_disable(ts);
- while (retry++ < 5) {
+ while (retry++ < GTP_I2C_RETRY_3) {
i2c_control_buf[0] = 0x80;
i2c_control_buf[1] = 0x46;
ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);
@@ -765,7 +766,7 @@ static s8 gtp_enter_sleep(struct goodix_ts_data *ts)
ret = gpio_direction_output(ts->pdata->irq_gpio, 0);
usleep(5000);
- while (retry++ < 5) {
+ while (retry++ < GTP_I2C_RETRY_5) {
ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);
if (ret > 0) {
dev_dbg(&ts->client->dev,
@@ -803,7 +804,7 @@ static s8 gtp_wakeup_sleep(struct goodix_ts_data *ts)
return 1;
}
#else
- while (retry++ < 10) {
+ while (retry++ < GTP_I2C_RETRY_10) {
#if GTP_SLIDE_WAKEUP
/* wakeup not by slide */
if (doze_status != DOZE_WAKEUP)
@@ -863,22 +864,9 @@ static int gtp_init_panel(struct goodix_ts_data *ts)
u8 opr_buf[16];
u8 sensor_id = 0;
- u8 cfg_info_group1[] = CTP_CFG_GROUP1;
- u8 cfg_info_group2[] = CTP_CFG_GROUP2;
- u8 cfg_info_group3[] = CTP_CFG_GROUP3;
- u8 cfg_info_group4[] = CTP_CFG_GROUP4;
- u8 cfg_info_group5[] = CTP_CFG_GROUP5;
- u8 cfg_info_group6[] = CTP_CFG_GROUP6;
- u8 *send_cfg_buf[] = {cfg_info_group1, cfg_info_group2,
- cfg_info_group3, cfg_info_group4,
- cfg_info_group5, cfg_info_group6};
-
- u8 cfg_info_len[] = {ARRAY_SIZE(cfg_info_group1),
- ARRAY_SIZE(cfg_info_group2),
- ARRAY_SIZE(cfg_info_group3),
- ARRAY_SIZE(cfg_info_group4),
- ARRAY_SIZE(cfg_info_group5),
- ARRAY_SIZE(cfg_info_group6)};
+ for (i = 0; i < GOODIX_MAX_CFG_GROUP; i++)
+ dev_dbg(&client->dev, "Config Groups(%d) Lengths: %d",
+ i, ts->pdata->config_data_len[i]);
ret = gtp_i2c_read_dbl_check(ts->client, 0x41E4, opr_buf, 1);
if (ret == SUCCESS) {
@@ -889,14 +877,18 @@ static int gtp_init_panel(struct goodix_ts_data *ts)
return -EINVAL;
}
}
- if ((!cfg_info_len[1]) && (!cfg_info_len[2]) && (!cfg_info_len[3])
- && (!cfg_info_len[4]) && (!cfg_info_len[5])) {
+
+ for (i = 1; i < GOODIX_MAX_CFG_GROUP; i++) {
+ if (ts->pdata->config_data_len[i])
+ break;
+ }
+ if (i == GOODIX_MAX_CFG_GROUP) {
sensor_id = 0;
} else {
ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_SENSOR_ID,
&sensor_id, 1);
if (ret == SUCCESS) {
- if (sensor_id >= 0x06) {
+ if (sensor_id >= GOODIX_MAX_CFG_GROUP) {
dev_err(&client->dev,
"Invalid sensor_id(0x%02X), No Config Sent!",
sensor_id);
@@ -908,22 +900,26 @@ static int gtp_init_panel(struct goodix_ts_data *ts)
return -EINVAL;
}
}
- ts->gtp_cfg_len = cfg_info_len[sensor_id];
- if (ts->gtp_cfg_len < GTP_CONFIG_MIN_LENGTH) {
+ dev_dbg(&client->dev, "Sensor ID selected: %d", sensor_id);
+
+ if (ts->pdata->config_data_len[sensor_id] < GTP_CONFIG_MIN_LENGTH ||
+ !ts->pdata->config_data[sensor_id]) {
dev_err(&client->dev,
- "Sensor_ID(%d) matches with NULL or INVALID CONFIG GROUP! NO Config Sent! You need to check you header file CFG_GROUP section!\n",
+ "Sensor_ID(%d) matches with NULL or invalid config group!\n",
sensor_id);
return -EINVAL;
}
+
ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_CONFIG_DATA,
&opr_buf[0], 1);
-
if (ret == SUCCESS) {
if (opr_buf[0] < 90) {
/* backup group config version */
- grp_cfg_version = send_cfg_buf[sensor_id][0];
- send_cfg_buf[sensor_id][0] = 0x00;
+ grp_cfg_version =
+ ts->pdata->config_data[sensor_id][GTP_ADDR_LENGTH];
+ ts->pdata->config_data[sensor_id][GTP_ADDR_LENGTH] =
+ 0x00;
ts->fixed_cfg = 0;
} else {
/* treated as fixed config, not send config */
@@ -938,27 +934,9 @@ static int gtp_init_panel(struct goodix_ts_data *ts)
return -EINVAL;
}
- if (ts->pdata->gtp_cfg_len) {
- config_data = ts->pdata->config_data;
- ts->config_data = ts->pdata->config_data;
- ts->gtp_cfg_len = ts->pdata->gtp_cfg_len;
- } else {
- config_data = devm_kzalloc(&client->dev,
- GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH,
- GFP_KERNEL);
- if (!config_data) {
- dev_err(&client->dev,
- "Not enough memory for panel config data\n");
- return -ENOMEM;
- }
-
- ts->config_data = config_data;
- config_data[0] = GTP_REG_CONFIG_DATA >> 8;
- config_data[1] = GTP_REG_CONFIG_DATA & 0xff;
- memset(&config_data[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);
- memcpy(&config_data[GTP_ADDR_LENGTH], send_cfg_buf[sensor_id],
- ts->gtp_cfg_len);
- }
+ config_data = ts->pdata->config_data[sensor_id];
+ ts->config_data = ts->pdata->config_data[sensor_id];
+ ts->gtp_cfg_len = ts->pdata->config_data_len[sensor_id];
#if GTP_CUSTOM_CFG
config_data[RESOLUTION_LOC] =
@@ -1094,7 +1072,7 @@ Output:
static int gtp_i2c_test(struct i2c_client *client)
{
u8 buf[3] = { GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff };
- int retry = 5;
+ int retry = GTP_I2C_RETRY_5;
int ret = -EIO;
while (retry--) {
@@ -1125,50 +1103,66 @@ static int gtp_request_io_port(struct goodix_ts_data *ts)
if (gpio_is_valid(pdata->irq_gpio)) {
ret = gpio_request(pdata->irq_gpio, "goodix_ts_irq_gpio");
if (ret) {
- dev_err(&client->dev, "irq gpio request failed\n");
- goto pwr_off;
+ dev_err(&client->dev, "Unable to request irq gpio [%d]\n",
+ pdata->irq_gpio);
+ goto err_pwr_off;
}
ret = gpio_direction_input(pdata->irq_gpio);
if (ret) {
- dev_err(&client->dev,
- "set_direction for irq gpio failed\n");
- goto free_irq_gpio;
+ dev_err(&client->dev, "Unable to set direction for irq gpio [%d]\n",
+ pdata->irq_gpio);
+ goto err_free_irq_gpio;
}
} else {
- dev_err(&client->dev, "irq gpio is invalid!\n");
+ dev_err(&client->dev, "Invalid irq gpio [%d]!\n",
+ pdata->irq_gpio);
ret = -EINVAL;
- goto free_irq_gpio;
+ goto err_pwr_off;
}
if (gpio_is_valid(pdata->reset_gpio)) {
- ret = gpio_request(pdata->reset_gpio, "goodix_ts__reset_gpio");
+ ret = gpio_request(pdata->reset_gpio, "goodix_ts_reset_gpio");
if (ret) {
- dev_err(&client->dev, "reset gpio request failed\n");
- goto free_irq_gpio;
+ dev_err(&client->dev, "Unable to request reset gpio [%d]\n",
+ pdata->reset_gpio);
+ goto err_free_irq_gpio;
}
ret = gpio_direction_output(pdata->reset_gpio, 0);
if (ret) {
- dev_err(&client->dev,
- "set_direction for reset gpio failed\n");
- goto free_reset_gpio;
+ dev_err(&client->dev, "Unable to set direction for reset gpio [%d]\n",
+ pdata->reset_gpio);
+ goto err_free_reset_gpio;
}
} else {
- dev_err(&client->dev, "reset gpio is invalid!\n");
+ dev_err(&client->dev, "Invalid irq gpio [%d]!\n",
+ pdata->reset_gpio);
ret = -EINVAL;
- goto free_reset_gpio;
- }
- gpio_direction_input(pdata->reset_gpio);
+ goto err_free_irq_gpio;
+ }
+ /* IRQ GPIO is an input signal, but we are setting it to output
+ * direction and pulling it down, to comply with power up timing
+ * requirements, mentioned in power up timing section of device
+ * datasheet.
+ */
+ ret = gpio_direction_output(pdata->irq_gpio, 0);
+ if (ret)
+ dev_warn(&client->dev,
+ "pull down interrupt gpio failed\n");
+ ret = gpio_direction_output(pdata->reset_gpio, 0);
+ if (ret)
+ dev_warn(&client->dev,
+ "pull down reset gpio failed\n");
return ret;
-free_reset_gpio:
+err_free_reset_gpio:
if (gpio_is_valid(pdata->reset_gpio))
gpio_free(pdata->reset_gpio);
-free_irq_gpio:
+err_free_irq_gpio:
if (gpio_is_valid(pdata->irq_gpio))
gpio_free(pdata->irq_gpio);
-pwr_off:
+err_pwr_off:
return ret;
}
@@ -1539,6 +1533,8 @@ static int goodix_parse_dt(struct device *dev,
struct property *prop;
u32 temp_val, num_buttons;
u32 button_map[MAX_BUTTONS];
+ char prop_name[PROP_NAME_SIZE];
+ int i, read_cfg_num;
rc = goodix_ts_get_dt_coords(dev, "goodix,panel-coords", pdata);
if (rc && (rc != -EINVAL))
@@ -1584,24 +1580,32 @@ static int goodix_parse_dt(struct device *dev,
}
}
- prop = of_find_property(np, "goodix,cfg-data", &pdata->gtp_cfg_len);
- if (prop && prop->value) {
- pdata->config_data = devm_kzalloc(dev,
- GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH, GFP_KERNEL);
- if (!pdata->config_data)
+ read_cfg_num = 0;
+ for (i = 0; i < GOODIX_MAX_CFG_GROUP; i++) {
+ snprintf(prop_name, sizeof(prop_name), "goodix,cfg-data%d", i);
+ prop = of_find_property(np, prop_name,
+ &pdata->config_data_len[i]);
+ if (!prop || !prop->value) {
+ pdata->config_data_len[i] = 0;
+ pdata->config_data[i] = NULL;
+ continue;
+ }
+ pdata->config_data[i] = devm_kzalloc(dev,
+ GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH,
+ GFP_KERNEL);
+ if (!pdata->config_data[i]) {
+ dev_err(dev,
+ "Not enough memory for panel config data %d\n",
+ i);
return -ENOMEM;
-
- pdata->config_data[0] = GTP_REG_CONFIG_DATA >> 8;
- pdata->config_data[1] = GTP_REG_CONFIG_DATA & 0xff;
- memset(&pdata->config_data[GTP_ADDR_LENGTH], 0,
- GTP_CONFIG_MAX_LENGTH);
- memcpy(&pdata->config_data[GTP_ADDR_LENGTH],
- prop->value, pdata->gtp_cfg_len);
- } else {
- dev_err(dev,
- "Unable to get configure data, default will be used.\n");
- pdata->gtp_cfg_len = 0;
+ }
+ pdata->config_data[i][0] = GTP_REG_CONFIG_DATA >> 8;
+ pdata->config_data[i][1] = GTP_REG_CONFIG_DATA & 0xff;
+ memcpy(&pdata->config_data[i][GTP_ADDR_LENGTH],
+ prop->value, pdata->config_data_len[i]);
+ read_cfg_num++;
}
+ dev_dbg(dev, "%d config data read from device tree.\n", read_cfg_num);
return 0;
}
@@ -1653,7 +1657,7 @@ static int goodix_ts_probe(struct i2c_client *client,
return -ENODEV;
}
- ts = kzalloc(sizeof(*ts), GFP_KERNEL);
+ ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL);
if (!ts)
return -ENOMEM;
@@ -1667,10 +1671,16 @@ static int goodix_ts_probe(struct i2c_client *client,
i2c_set_clientdata(client, ts);
ts->gtp_rawdiff_mode = 0;
+ ret = gtp_request_io_port(ts);
+ if (ret) {
+ dev_err(&client->dev, "GTP request IO port failed.\n");
+ goto exit_free_client_data;
+ }
+
ret = goodix_power_init(ts);
if (ret) {
dev_err(&client->dev, "GTP power init failed\n");
- goto exit_free_client_data;
+ goto exit_free_io_port;
}
ret = goodix_power_on(ts);
@@ -1679,18 +1689,12 @@ static int goodix_ts_probe(struct i2c_client *client,
goto exit_deinit_power;
}
- ret = gtp_request_io_port(ts);
- if (ret) {
- dev_err(&client->dev, "GTP request IO port failed.\n");
- goto exit_power_off;
- }
-
gtp_reset_guitar(ts, 20);
ret = gtp_i2c_test(client);
if (ret != 2) {
dev_err(&client->dev, "I2C communication ERROR!\n");
- goto exit_free_io_port;
+ goto exit_power_off;
}
#if GTP_AUTO_UPDATE
@@ -1783,18 +1787,17 @@ exit_free_irq:
}
exit_free_inputdev:
kfree(ts->config_data);
+exit_power_off:
+ goodix_power_off(ts);
+exit_deinit_power:
+ goodix_power_deinit(ts);
exit_free_io_port:
if (gpio_is_valid(pdata->reset_gpio))
gpio_free(pdata->reset_gpio);
if (gpio_is_valid(pdata->irq_gpio))
gpio_free(pdata->irq_gpio);
-exit_power_off:
- goodix_power_off(ts);
-exit_deinit_power:
- goodix_power_deinit(ts);
exit_free_client_data:
i2c_set_clientdata(client, NULL);
- kfree(ts);
return ret;
}
@@ -1843,7 +1846,6 @@ static int goodix_ts_remove(struct i2c_client *client)
input_free_device(ts->input_dev);
ts->input_dev = NULL;
}
- kfree(ts->config_data);
if (gpio_is_valid(ts->pdata->reset_gpio))
gpio_free(ts->pdata->reset_gpio);
@@ -1853,7 +1855,6 @@ static int goodix_ts_remove(struct i2c_client *client)
goodix_power_off(ts);
goodix_power_deinit(ts);
i2c_set_clientdata(client, NULL);
- kfree(ts);
}
return 0;
@@ -2043,13 +2044,13 @@ static int gtp_init_ext_watchdog(struct i2c_client *client)
msg.len = 4;
msg.buf = opr_buffer;
- while (retries < 5) {
+ while (retries < GTP_I2C_RETRY_5) {
ret = i2c_transfer(client->adapter, &msg, 1);
if (ret == 1)
return 1;
retries++;
}
- if (retries >= 5)
+ if (retries == GTP_I2C_RETRY_5)
dev_err(&client->dev, "init external watchdog failed!");
return 0;
}
@@ -2065,7 +2066,7 @@ Output:
*******************************************************/
static void gtp_esd_check_func(struct work_struct *work)
{
- s32 i;
+ s32 retry;
s32 ret = -1;
struct goodix_ts_data *ts = NULL;
u8 test[4] = {0x80, 0x40};
@@ -2082,7 +2083,7 @@ static void gtp_esd_check_func(struct work_struct *work)
return;
#endif
- for (i = 0; i < 3; i++) {
+ for (retry = 0; retry < GTP_I2C_RETRY_3; retry++) {
ret = gtp_i2c_read(ts->client, test, 4);
if ((ret < 0)) {
@@ -2091,7 +2092,7 @@ static void gtp_esd_check_func(struct work_struct *work)
} else {
if ((test[2] == 0xAA) || (test[3] != 0xAA)) {
/* IC works abnormally..*/
- i = 3;
+ retry = GTP_I2C_RETRY_3;
break;
}
/* IC works normally, Write 0x8040 0xAA*/
@@ -2100,7 +2101,7 @@ static void gtp_esd_check_func(struct work_struct *work)
break;
}
}
- if (i >= 3) {
+ if (retry == GTP_I2C_RETRY_3) {
dev_err(&ts->client->dev,
"IC Working ABNORMALLY, Resetting Guitar...\n");
gtp_reset_guitar(ts, 50);
diff --git a/drivers/input/touchscreen/gt9xx/gt9xx.h b/drivers/input/touchscreen/gt9xx/gt9xx.h
index 1cae9fa3b0ab..843e3d6c05b2 100644
--- a/drivers/input/touchscreen/gt9xx/gt9xx.h
+++ b/drivers/input/touchscreen/gt9xx/gt9xx.h
@@ -42,6 +42,7 @@
#define GOODIX_SUSPEND_LEVEL 1
#endif
+#define GOODIX_MAX_CFG_GROUP 6
struct goodix_ts_platform_data {
int irq_gpio;
u32 irq_gpio_flags;
@@ -58,8 +59,8 @@ struct goodix_ts_platform_data {
u32 panel_maxy;
bool no_force_update;
bool i2c_pull_up;
- int gtp_cfg_len;
- u8 *config_data;
+ size_t config_data_len[GOODIX_MAX_CFG_GROUP];
+ u8 *config_data[GOODIX_MAX_CFG_GROUP];
};
struct goodix_ts_data {
spinlock_t irq_lock;
@@ -134,56 +135,7 @@ extern u16 total_len;
* GND NC/300K 3
* VDDIO NC/300K 4
* NC NC/300K 5
-*/
-/* Define your own default or for Sensor_ID == 0 config here */
-/* The predefined one is just a sample config,
- * which is not suitable for your tp in most cases.
*/
-#define CTP_CFG_GROUP1 {\
- 0x41, 0x1C, 0x02, 0xC0, 0x03, 0x0A, 0x05, 0x01, 0x01, 0x0F,\
- 0x23, 0x0F, 0x5F, 0x41, 0x03, 0x05, 0x00, 0x00, 0x00, 0x00,\
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x0A,\
- 0x28, 0x00, 0xB8, 0x0B, 0x00, 0x00, 0x00, 0x9A, 0x03, 0x25,\
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x64, 0x32, 0x00, 0x00,\
- 0x00, 0x32, 0x8C, 0x94, 0x05, 0x01, 0x05, 0x00, 0x00, 0x96,\
- 0x0C, 0x22, 0xD8, 0x0E, 0x23, 0x56, 0x11, 0x25, 0xFF, 0x13,\
- 0x28, 0xA7, 0x15, 0x2E, 0x00, 0x00, 0x10, 0x30, 0x48, 0x00,\
- 0x56, 0x4A, 0x3A, 0xFF, 0xFF, 0x16, 0x00, 0x00, 0x00, 0x00,\
- 0x00, 0x01, 0x1B, 0x14, 0x0D, 0x19, 0x00, 0x00, 0x01, 0x00,\
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
- 0x00, 0x00, 0x1A, 0x18, 0x16, 0x14, 0x12, 0x10, 0x0E, 0x0C,\
- 0x0A, 0x08, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,\
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,\
- 0xFF, 0xFF, 0x1D, 0x1E, 0x1F, 0x20, 0x22, 0x24, 0x28, 0x29,\
- 0x0C, 0x0A, 0x08, 0x00, 0x02, 0x04, 0x05, 0x06, 0x0E, 0xFF,\
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,\
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,\
- 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0x01\
- }
-
-/* Define your config for Sensor_ID == 1 here, if needed */
-#define CTP_CFG_GROUP2 {\
- }
-
-/* Define your config for Sensor_ID == 2 here, if needed */
-#define CTP_CFG_GROUP3 {\
- }
-
-/* Define your config for Sensor_ID == 3 here, if needed */
-#define CTP_CFG_GROUP4 {\
- }
-
-/* Define your config for Sensor_ID == 4 here, if needed */
-#define CTP_CFG_GROUP5 {\
- }
-
-/* Define your config for Sensor_ID == 5 here, if needed */
-#define CTP_CFG_GROUP6 {\
- }
#define GTP_IRQ_TAB {\
IRQ_TYPE_EDGE_RISING,\
@@ -231,6 +183,10 @@ extern u16 total_len;
#define GTP_REG_FW_VERSION 0x8144
#define GTP_REG_PRODUCT_ID 0x8140
+#define GTP_I2C_RETRY_3 3
+#define GTP_I2C_RETRY_5 5
+#define GTP_I2C_RETRY_10 10
+
#define RESOLUTION_LOC 3
#define TRIGGER_LOC 8
diff --git a/drivers/input/touchscreen/gt9xx/gt9xx_update.c b/drivers/input/touchscreen/gt9xx/gt9xx_update.c
index 29459b6d9ad1..9fcf7f0bef86 100644
--- a/drivers/input/touchscreen/gt9xx/gt9xx_update.c
+++ b/drivers/input/touchscreen/gt9xx/gt9xx_update.c
@@ -109,24 +109,25 @@ Output:
*********************************************************/
s32 gup_i2c_read(struct i2c_client *client, u8 *buf, s32 len)
{
- struct i2c_msg msgs[2];
s32 ret = -1;
- s32 retries = 0;
+ u8 retries = 0;
+ struct i2c_msg msgs[2] = {
+ {
+ .flags = !I2C_M_RD,
+ .addr = client->addr,
+ .len = GTP_ADDR_LENGTH,
+ .buf = &buf[0],
+ },
+ {
+ .flags = I2C_M_RD,
+ .addr = client->addr,
+ .len = len - GTP_ADDR_LENGTH,
+ .buf = &buf[GTP_ADDR_LENGTH],
+ },
+ };
GTP_DEBUG_FUNC();
- msgs[0].flags = !I2C_M_RD;
- msgs[0].addr = client->addr;
- msgs[0].len = GTP_ADDR_LENGTH;
- msgs[0].buf = &buf[0];
- /* msgs[0].scl_rate = 300 * 1000; (for Rockchip) */
-
- msgs[1].flags = I2C_M_RD;
- msgs[1].addr = client->addr;
- msgs[1].len = len - GTP_ADDR_LENGTH;
- msgs[1].buf = &buf[GTP_ADDR_LENGTH];
- /* msgs[1].scl_rate = 300 * 1000; */
-
while (retries < 5) {
ret = i2c_transfer(client->adapter, msgs, 2);
if (ret == 2)
@@ -134,6 +135,11 @@ s32 gup_i2c_read(struct i2c_client *client, u8 *buf, s32 len)
retries++;
}
+ if (retries == 5) {
+ dev_err(&client->dev, "I2C read retry limit over.\n");
+ ret = -EIO;
+ }
+
return ret;
}
@@ -151,18 +157,17 @@ Output:
*********************************************************/
s32 gup_i2c_write(struct i2c_client *client, u8 *buf, s32 len)
{
- struct i2c_msg msg;
s32 ret = -1;
- s32 retries = 0;
+ u8 retries = 0;
+ struct i2c_msg msg = {
+ .flags = !I2C_M_RD,
+ .addr = client->addr,
+ .len = len,
+ .buf = buf,
+ };
GTP_DEBUG_FUNC();
- msg.flags = !I2C_M_RD;
- msg.addr = client->addr;
- msg.len = len;
- msg.buf = buf;
- /* msg.scl_rate = 300 * 1000; (for Rockchip) */
-
while (retries < 5) {
ret = i2c_transfer(client->adapter, &msg, 1);
if (ret == 1)
@@ -170,6 +175,11 @@ s32 gup_i2c_write(struct i2c_client *client, u8 *buf, s32 len)
retries++;
}
+ if (retries == 5) {
+ dev_err(&client->dev, "I2C write retry limit over.\n");
+ ret = -EIO;
+ }
+
return ret;
}
@@ -288,7 +298,7 @@ static s32 gup_init_panel(struct goodix_ts_data *ts)
static u8 gup_get_ic_msg(struct i2c_client *client, u16 addr, u8 *msg, s32 len)
{
- s32 i = 0;
+ u8 i = 0;
msg[0] = (addr >> 8) & 0xff;
msg[1] = addr & 0xff;
@@ -307,12 +317,12 @@ static u8 gup_get_ic_msg(struct i2c_client *client, u16 addr, u8 *msg, s32 len)
static u8 gup_set_ic_msg(struct i2c_client *client, u16 addr, u8 val)
{
- s32 i = 0;
- u8 msg[3];
-
- msg[0] = (addr >> 8) & 0xff;
- msg[1] = addr & 0xff;
- msg[2] = val;
+ u8 i = 0;
+ u8 msg[3] = {
+ (addr >> 8) & 0xff,
+ addr & 0xff,
+ val,
+ };
for (i = 0; i < 5; i++)
if (gup_i2c_write(client, msg, GTP_ADDR_LENGTH + 1) > 0)
@@ -411,7 +421,7 @@ static u8 gup_get_ic_fw_msg(struct i2c_client *client)
s32 gup_enter_update_mode(struct i2c_client *client)
{
s32 ret = -1;
- s32 retry = 0;
+ u8 retry = 0;
u8 rd_buf[3];
/* step1:RST output low last at least 2ms */
@@ -575,11 +585,11 @@ static u8 ascii2hex(u8 a)
static s8 gup_update_config(struct i2c_client *client)
{
- s32 file_len = 0;
+ u32 file_len = 0;
s32 ret = 0;
s32 i = 0;
s32 file_cfg_len = 0;
- s32 chip_cfg_len = 0;
+ u32 chip_cfg_len = 0;
s32 count = 0;
u8 *buf;
u8 *pre_buf;
@@ -615,9 +625,19 @@ static s8 gup_update_config(struct i2c_client *client)
return -EINVAL;
}
- buf = kzalloc(file_len, GFP_KERNEL);
- pre_buf = kzalloc(file_len, GFP_KERNEL);
- file_config = kzalloc(chip_cfg_len + GTP_ADDR_LENGTH, GFP_KERNEL);
+ buf = devm_kzalloc(&client->dev, file_len, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
+ pre_buf = devm_kzalloc(&client->dev, file_len, GFP_KERNEL);
+ if (!pre_buf)
+ return -ENOMEM;
+
+ file_config = devm_kzalloc(&client->dev, chip_cfg_len + GTP_ADDR_LENGTH,
+ GFP_KERNEL);
+ if (!file_config)
+ return -ENOMEM;
+
update_msg.cfg_file->f_op->llseek(update_msg.cfg_file, 0, SEEK_SET);
GTP_DEBUG("[update_cfg]Read config from file.");
@@ -625,7 +645,7 @@ static s8 gup_update_config(struct i2c_client *client)
(char *)pre_buf, file_len, &update_msg.cfg_file->f_pos);
if (ret < 0) {
GTP_ERROR("[update_cfg]Read config file failed.");
- goto update_cfg_file_failed;
+ return ret;
}
GTP_DEBUG("[update_cfg]Delete illegal character.");
@@ -650,13 +670,13 @@ static s8 gup_update_config(struct i2c_client *client)
if ((high == 0xFF) || (low == 0xFF)) {
ret = 0;
GTP_ERROR("[update_cfg]Illegal config file.");
- goto update_cfg_file_failed;
+ return ret;
}
file_config[file_cfg_len++] = (high<<4) + low;
} else {
ret = 0;
GTP_ERROR("[update_cfg]Illegal config file.");
- goto update_cfg_file_failed;
+ return ret;
}
}
@@ -680,10 +700,6 @@ static s8 gup_update_config(struct i2c_client *client)
GTP_ERROR("[update_cfg]Send config i2c error.");
}
-update_cfg_file_failed:
- kfree(pre_buf);
- kfree(buf);
- kfree(file_config);
return ret;
}
@@ -787,16 +803,22 @@ static u8 gup_check_update_file(struct i2c_client *client, st_fw_head *fw_head,
sizeof(UPDATE_FILE_PATH_2));
u8 cfp_len = max(sizeof(CONFIG_FILE_PATH_1),
sizeof(CONFIG_FILE_PATH_2));
- u8 *search_update_path = kzalloc(fp_len, GFP_KERNEL);
- u8 *search_cfg_path = kzalloc(cfp_len, GFP_KERNEL);
+
+ u8 *search_update_path = devm_kzalloc(&client->dev, fp_len,
+ GFP_KERNEL);
+ if (!search_update_path)
+ goto load_failed;
+
+ u8 *search_cfg_path = devm_kzalloc(&client->dev, cfp_len,
+ GFP_KERNEL);
+ if (!search_cfg_path)
+ goto load_failed;
/* Begin to search update file,the config file & firmware
* file must be in the same path,single or double.
*/
searching_file = 1;
for (i = 0; i < GUP_SEARCH_FILE_TIMES; i++) {
if (searching_file == 0) {
- kfree(search_update_path);
- kfree(search_cfg_path);
GTP_INFO(".bin/.cfg update file search ",
"forcely terminated!");
return FAIL;
@@ -843,8 +865,6 @@ static u8 gup_check_update_file(struct i2c_client *client, st_fw_head *fw_head,
}
searching_file = 0;
- kfree(search_update_path);
- kfree(search_cfg_path);
if (!got_file_flag) {
GTP_ERROR("Can't find update file.");
@@ -1168,7 +1188,8 @@ static u8 gup_burn_dsp_isp(struct i2c_client *client)
/* step1:alloc memory */
GTP_DEBUG("[burn_dsp_isp]step1:alloc memory");
while (retry++ < 5) {
- fw_dsp_isp = kzalloc(FW_DSP_ISP_LENGTH, GFP_KERNEL);
+ fw_dsp_isp = devm_kzalloc(&client->dev, FW_DSP_ISP_LENGTH,
+ GFP_KERNEL);
if (fw_dsp_isp == NULL) {
continue;
} else {
@@ -1177,7 +1198,7 @@ static u8 gup_burn_dsp_isp(struct i2c_client *client)
break;
}
}
- if (retry >= 5) {
+ if (retry == 5) {
GTP_ERROR("[burn_dsp_isp]Alloc memory fail,exit.");
return FAIL;
}
@@ -1188,7 +1209,7 @@ static u8 gup_burn_dsp_isp(struct i2c_client *client)
FW_DSP_LENGTH + FW_BOOT_LENGTH), FW_DSP_ISP_LENGTH);
if (ret == FAIL) {
GTP_ERROR("[burn_dsp_isp]load firmware dsp_isp fail.");
- goto exit_burn_dsp_isp;
+ return FAIL;
}
/* step3:disable wdt,clear cache enable */
@@ -1196,14 +1217,12 @@ static u8 gup_burn_dsp_isp(struct i2c_client *client)
ret = gup_set_ic_msg(client, _bRW_MISCTL__TMR0_EN, 0x00);
if (ret <= 0) {
GTP_ERROR("[burn_dsp_isp]disable wdt fail.");
- ret = FAIL;
- goto exit_burn_dsp_isp;
+ return FAIL;
}
ret = gup_set_ic_msg(client, _bRW_MISCTL__CACHE_EN, 0x00);
if (ret <= 0) {
GTP_ERROR("[burn_dsp_isp]clear cache enable fail.");
- ret = FAIL;
- goto exit_burn_dsp_isp;
+ return FAIL;
}
/* step4:hold ss51 & dsp */
@@ -1211,8 +1230,7 @@ static u8 gup_burn_dsp_isp(struct i2c_client *client)
ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
if (ret <= 0) {
GTP_ERROR("[burn_dsp_isp]hold ss51 & dsp fail.");
- ret = FAIL;
- goto exit_burn_dsp_isp;
+ return FAIL;
}
/* step5:set boot from sram */
@@ -1220,8 +1238,7 @@ static u8 gup_burn_dsp_isp(struct i2c_client *client)
ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOTCTL_B0_, 0x02);
if (ret <= 0) {
GTP_ERROR("[burn_dsp_isp]set boot from sram fail.");
- ret = FAIL;
- goto exit_burn_dsp_isp;
+ return FAIL;
}
/* step6:software reboot */
@@ -1229,8 +1246,7 @@ static u8 gup_burn_dsp_isp(struct i2c_client *client)
ret = gup_set_ic_msg(client, _bWO_MISCTL__CPU_SWRST_PULSE, 0x01);
if (ret <= 0) {
GTP_ERROR("[burn_dsp_isp]software reboot fail.");
- ret = FAIL;
- goto exit_burn_dsp_isp;
+ return FAIL;
}
/* step7:select bank2 */
@@ -1238,8 +1254,7 @@ static u8 gup_burn_dsp_isp(struct i2c_client *client)
ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x02);
if (ret <= 0) {
GTP_ERROR("[burn_dsp_isp]select bank2 fail.");
- ret = FAIL;
- goto exit_burn_dsp_isp;
+ return FAIL;
}
/* step8:enable accessing code */
@@ -1247,8 +1262,7 @@ static u8 gup_burn_dsp_isp(struct i2c_client *client)
ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01);
if (ret <= 0) {
GTP_ERROR("[burn_dsp_isp]enable accessing code fail.");
- ret = FAIL;
- goto exit_burn_dsp_isp;
+ return FAIL;
}
/* step9:burn 4k dsp_isp */
@@ -1256,7 +1270,7 @@ static u8 gup_burn_dsp_isp(struct i2c_client *client)
ret = gup_burn_proc(client, fw_dsp_isp, 0xC000, FW_DSP_ISP_LENGTH);
if (ret == FAIL) {
GTP_ERROR("[burn_dsp_isp]burn dsp_isp fail.");
- goto exit_burn_dsp_isp;
+ return FAIL;
}
/* step10:set scramble */
@@ -1264,14 +1278,10 @@ static u8 gup_burn_dsp_isp(struct i2c_client *client)
ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
if (ret <= 0) {
GTP_ERROR("[burn_dsp_isp]set scramble fail.");
- ret = FAIL;
- goto exit_burn_dsp_isp;
+ return FAIL;
}
- ret = SUCCESS;
-exit_burn_dsp_isp:
- kfree(fw_dsp_isp);
- return ret;
+ return SUCCESS;
}
static u8 gup_burn_fw_ss51(struct i2c_client *client)
@@ -1285,7 +1295,8 @@ static u8 gup_burn_fw_ss51(struct i2c_client *client)
/* step1:alloc memory */
GTP_DEBUG("[burn_fw_ss51]step1:alloc memory");
while (retry++ < 5) {
- fw_ss51 = kzalloc(FW_SECTION_LENGTH, GFP_KERNEL);
+ fw_ss51 = devm_kzalloc(&client->dev, FW_SECTION_LENGTH,
+ GFP_KERNEL);
if (fw_ss51 == NULL) {
continue;
} else {
@@ -1294,7 +1305,7 @@ static u8 gup_burn_fw_ss51(struct i2c_client *client)
break;
}
}
- if (retry >= 5) {
+ if (retry == 5) {
GTP_ERROR("[burn_fw_ss51]Alloc memory fail,exit.");
return FAIL;
}
@@ -1304,7 +1315,7 @@ static u8 gup_burn_fw_ss51(struct i2c_client *client)
ret = gup_load_section_file(fw_ss51, 0, FW_SECTION_LENGTH);
if (ret == FAIL) {
GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 1 fail.");
- goto exit_burn_fw_ss51;
+ return FAIL;
}
/* step3:clear control flag */
@@ -1312,8 +1323,7 @@ static u8 gup_burn_fw_ss51(struct i2c_client *client)
ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x00);
if (ret <= 0) {
GTP_ERROR("[burn_fw_ss51]clear control flag fail.");
- ret = FAIL;
- goto exit_burn_fw_ss51;
+ return FAIL;
}
/* step4:burn ss51 firmware section 1 */
@@ -1321,7 +1331,7 @@ static u8 gup_burn_fw_ss51(struct i2c_client *client)
ret = gup_burn_fw_section(client, fw_ss51, 0xC000, 0x01);
if (ret == FAIL) {
GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 1 fail.");
- goto exit_burn_fw_ss51;
+ return FAIL;
}
/* step5:load ss51 firmware section 2 file data */
@@ -1330,7 +1340,7 @@ static u8 gup_burn_fw_ss51(struct i2c_client *client)
FW_SECTION_LENGTH);
if (ret == FAIL) {
GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 2 fail.");
- goto exit_burn_fw_ss51;
+ return FAIL;
}
/* step6:burn ss51 firmware section 2 */
@@ -1338,7 +1348,7 @@ static u8 gup_burn_fw_ss51(struct i2c_client *client)
ret = gup_burn_fw_section(client, fw_ss51, 0xE000, 0x02);
if (ret == FAIL) {
GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 2 fail.");
- goto exit_burn_fw_ss51;
+ return FAIL;
}
/* step7:load ss51 firmware section 3 file data */
@@ -1347,7 +1357,7 @@ static u8 gup_burn_fw_ss51(struct i2c_client *client)
FW_SECTION_LENGTH);
if (ret == FAIL) {
GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 3 fail.");
- goto exit_burn_fw_ss51;
+ return FAIL;
}
/* step8:burn ss51 firmware section 3 */
@@ -1355,7 +1365,7 @@ static u8 gup_burn_fw_ss51(struct i2c_client *client)
ret = gup_burn_fw_section(client, fw_ss51, 0xC000, 0x13);
if (ret == FAIL) {
GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 3 fail.");
- goto exit_burn_fw_ss51;
+ return FAIL;
}
/* step9:load ss51 firmware section 4 file data */
@@ -1364,7 +1374,7 @@ static u8 gup_burn_fw_ss51(struct i2c_client *client)
FW_SECTION_LENGTH);
if (ret == FAIL) {
GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 4 fail.");
- goto exit_burn_fw_ss51;
+ return FAIL;
}
/* step10:burn ss51 firmware section 4 */
@@ -1372,14 +1382,10 @@ static u8 gup_burn_fw_ss51(struct i2c_client *client)
ret = gup_burn_fw_section(client, fw_ss51, 0xE000, 0x14);
if (ret == FAIL) {
GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 4 fail.");
- goto exit_burn_fw_ss51;
+ return FAIL;
}
- ret = SUCCESS;
-
-exit_burn_fw_ss51:
- kfree(fw_ss51);
- return ret;
+ return SUCCESS;
}
static u8 gup_burn_fw_dsp(struct i2c_client *client)
@@ -1393,7 +1399,8 @@ static u8 gup_burn_fw_dsp(struct i2c_client *client)
/* step1:alloc memory */
GTP_DEBUG("[burn_fw_dsp]step1:alloc memory");
while (retry++ < 5) {
- fw_dsp = kzalloc(FW_DSP_LENGTH, GFP_KERNEL);
+ fw_dsp = devm_kzalloc(&client->dev, FW_DSP_LENGTH,
+ GFP_KERNEL);
if (fw_dsp == NULL) {
continue;
} else {
@@ -1402,7 +1409,7 @@ static u8 gup_burn_fw_dsp(struct i2c_client *client)
break;
}
}
- if (retry >= 5) {
+ if (retry == 5) {
GTP_ERROR("[burn_fw_dsp]Alloc memory fail,exit.");
return FAIL;
}
@@ -1412,7 +1419,7 @@ static u8 gup_burn_fw_dsp(struct i2c_client *client)
ret = gup_load_section_file(fw_dsp, 4*FW_SECTION_LENGTH, FW_DSP_LENGTH);
if (ret == FAIL) {
GTP_ERROR("[burn_fw_dsp]load firmware dsp fail.");
- goto exit_burn_fw_dsp;
+ return ret;
}
/* step3:select bank3 */
@@ -1420,8 +1427,7 @@ static u8 gup_burn_fw_dsp(struct i2c_client *client)
ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x03);
if (ret <= 0) {
GTP_ERROR("[burn_fw_dsp]select bank3 fail.");
- ret = FAIL;
- goto exit_burn_fw_dsp;
+ return FAIL;
}
/* Step4:hold ss51 & dsp */
@@ -1429,8 +1435,7 @@ static u8 gup_burn_fw_dsp(struct i2c_client *client)
ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
if (ret <= 0) {
GTP_ERROR("[burn_fw_dsp]hold ss51 & dsp fail.");
- ret = FAIL;
- goto exit_burn_fw_dsp;
+ return FAIL;
}
/* step5:set scramble */
@@ -1438,8 +1443,7 @@ static u8 gup_burn_fw_dsp(struct i2c_client *client)
ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
if (ret <= 0) {
GTP_ERROR("[burn_fw_dsp]set scramble fail.");
- ret = FAIL;
- goto exit_burn_fw_dsp;
+ return FAIL;
}
/* step6:release ss51 & dsp */
@@ -1447,8 +1451,7 @@ static u8 gup_burn_fw_dsp(struct i2c_client *client)
ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x04);
if (ret <= 0) {
GTP_ERROR("[burn_fw_dsp]release ss51 & dsp fail.");
- ret = FAIL;
- goto exit_burn_fw_dsp;
+ return FAIL;
}
/* must delay */
msleep(20);
@@ -1458,7 +1461,7 @@ static u8 gup_burn_fw_dsp(struct i2c_client *client)
ret = gup_burn_proc(client, fw_dsp, 0x9000, FW_DSP_LENGTH);
if (ret == FAIL) {
GTP_ERROR("[burn_fw_dsp]burn fw_section fail.");
- goto exit_burn_fw_dsp;
+ return ret;
}
/* step8:send burn cmd to move data to flash from sram */
@@ -1467,14 +1470,14 @@ static u8 gup_burn_fw_dsp(struct i2c_client *client)
ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x05);
if (ret <= 0) {
GTP_ERROR("[burn_fw_dsp]send burn cmd fail.");
- goto exit_burn_fw_dsp;
+ return ret;
}
GTP_DEBUG("[burn_fw_dsp]Wait for the burn is complete......");
do {
ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1);
if (ret <= 0) {
GTP_ERROR("[burn_fw_dsp]Get burn state fail");
- goto exit_burn_fw_dsp;
+ return ret;
}
msleep(20);
/* GTP_DEBUG("[burn_fw_dsp]Get burn state:%d.",
@@ -1487,14 +1490,10 @@ static u8 gup_burn_fw_dsp(struct i2c_client *client)
ret = gup_recall_check(client, fw_dsp, 0x9000, FW_DSP_LENGTH);
if (ret == FAIL) {
GTP_ERROR("[burn_fw_dsp]recall check 4k dsp firmware fail.");
- goto exit_burn_fw_dsp;
+ return ret;
}
ret = SUCCESS;
-
-exit_burn_fw_dsp:
- kfree(fw_dsp);
- return ret;
}
static u8 gup_burn_fw_boot(struct i2c_client *client)
@@ -1509,7 +1508,8 @@ static u8 gup_burn_fw_boot(struct i2c_client *client)
/* step1:Alloc memory */
GTP_DEBUG("[burn_fw_boot]step1:Alloc memory");
while (retry++ < 5) {
- fw_boot = kzalloc(FW_BOOT_LENGTH, GFP_KERNEL);
+ fw_boot = devm_kzalloc(&client->dev, FW_BOOT_LENGTH,
+ GFP_KERNEL);
if (fw_boot == NULL) {
continue;
} else {
@@ -1518,7 +1518,7 @@ static u8 gup_burn_fw_boot(struct i2c_client *client)
break;
}
}
- if (retry >= 5) {
+ if (retry == 5) {
GTP_ERROR("[burn_fw_boot]Alloc memory fail,exit.");
return FAIL;
}
@@ -1529,7 +1529,7 @@ static u8 gup_burn_fw_boot(struct i2c_client *client)
FW_DSP_LENGTH), FW_BOOT_LENGTH);
if (ret == FAIL) {
GTP_ERROR("[burn_fw_boot]load firmware dsp fail.");
- goto exit_burn_fw_boot;
+ return ret;
}
/* step3:hold ss51 & dsp */
@@ -1537,8 +1537,7 @@ static u8 gup_burn_fw_boot(struct i2c_client *client)
ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
if (ret <= 0) {
GTP_ERROR("[burn_fw_boot]hold ss51 & dsp fail.");
- ret = FAIL;
- goto exit_burn_fw_boot;
+ return FAIL;
}
/* step4:set scramble */
@@ -1546,8 +1545,7 @@ static u8 gup_burn_fw_boot(struct i2c_client *client)
ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
if (ret <= 0) {
GTP_ERROR("[burn_fw_boot]set scramble fail.");
- ret = FAIL;
- goto exit_burn_fw_boot;
+ return FAIL;
}
/* step5:release ss51 & dsp */
@@ -1555,8 +1553,7 @@ static u8 gup_burn_fw_boot(struct i2c_client *client)
ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x04);
if (ret <= 0) {
GTP_ERROR("[burn_fw_boot]release ss51 & dsp fail.");
- ret = FAIL;
- goto exit_burn_fw_boot;
+ return FAIL;
}
/* must delay */
msleep(20);
@@ -1566,8 +1563,7 @@ static u8 gup_burn_fw_boot(struct i2c_client *client)
ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x03);
if (ret <= 0) {
GTP_ERROR("[burn_fw_boot]select bank3 fail.");
- ret = FAIL;
- goto exit_burn_fw_boot;
+ return FAIL;
}
/* step7:burn 2k bootloader firmware */
@@ -1575,7 +1571,7 @@ static u8 gup_burn_fw_boot(struct i2c_client *client)
ret = gup_burn_proc(client, fw_boot, 0x9000, FW_BOOT_LENGTH);
if (ret == FAIL) {
GTP_ERROR("[burn_fw_boot]burn fw_section fail.");
- goto exit_burn_fw_boot;
+ return ret;
}
/* step7:send burn cmd to move data to flash from sram */
@@ -1584,14 +1580,14 @@ static u8 gup_burn_fw_boot(struct i2c_client *client)
ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x06);
if (ret <= 0) {
GTP_ERROR("[burn_fw_boot]send burn cmd fail.");
- goto exit_burn_fw_boot;
+ return ret;
}
GTP_DEBUG("[burn_fw_boot]Wait for the burn is complete......");
do {
ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1);
if (ret <= 0) {
GTP_ERROR("[burn_fw_boot]Get burn state fail");
- goto exit_burn_fw_boot;
+ return ret;
}
msleep(20);
/* GTP_DEBUG("[burn_fw_boot]Get burn state:%d.",
@@ -1604,7 +1600,7 @@ static u8 gup_burn_fw_boot(struct i2c_client *client)
ret = gup_recall_check(client, fw_boot, 0x9000, FW_BOOT_LENGTH);
if (ret == FAIL) {
GTP_ERROR("[burn_fw_boot]recall check 4k dsp firmware fail.");
- goto exit_burn_fw_boot;
+ return ret;
}
/* step9:enable download DSP code */
@@ -1612,8 +1608,7 @@ static u8 gup_burn_fw_boot(struct i2c_client *client)
ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x99);
if (ret <= 0) {
GTP_ERROR("[burn_fw_boot]enable download DSP code fail.");
- ret = FAIL;
- goto exit_burn_fw_boot;
+ return FAIL;
}
/* step10:release ss51 & hold dsp */
@@ -1621,15 +1616,10 @@ static u8 gup_burn_fw_boot(struct i2c_client *client)
ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x08);
if (ret <= 0) {
GTP_ERROR("[burn_fw_boot]release ss51 & hold dsp fail.");
- ret = FAIL;
- goto exit_burn_fw_boot;
+ return FAIL;
}
- ret = SUCCESS;
-
-exit_burn_fw_boot:
- kfree(fw_boot);
- return ret;
+ return SUCCESS;
}
s32 gup_update_proc(void *dir)