Commit 6cd1ab0f authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: atmel_mxt_ts - simplify mxt_initialize a bit

I think having control flow with 2 goto/labels/flags is quite hard to read,
this version is a bit more readable IMO.
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: default avatarNick Dyer <nick.dyer@itdev.co.uk>
parent 23526d94
...@@ -359,7 +359,6 @@ static int mxt_bootloader_read(struct mxt_data *data, ...@@ -359,7 +359,6 @@ static int mxt_bootloader_read(struct mxt_data *data,
msg.buf = val; msg.buf = val;
ret = i2c_transfer(data->client->adapter, &msg, 1); ret = i2c_transfer(data->client->adapter, &msg, 1);
if (ret == 1) { if (ret == 1) {
ret = 0; ret = 0;
} else { } else {
...@@ -414,6 +413,7 @@ static int mxt_lookup_bootloader_address(struct mxt_data *data, bool retry) ...@@ -414,6 +413,7 @@ static int mxt_lookup_bootloader_address(struct mxt_data *data, bool retry)
case 0x5b: case 0x5b:
bootloader = appmode - 0x26; bootloader = appmode - 0x26;
break; break;
default: default:
dev_err(&data->client->dev, dev_err(&data->client->dev,
"Appmode i2c address 0x%02x not found\n", "Appmode i2c address 0x%02x not found\n",
...@@ -425,20 +425,20 @@ static int mxt_lookup_bootloader_address(struct mxt_data *data, bool retry) ...@@ -425,20 +425,20 @@ static int mxt_lookup_bootloader_address(struct mxt_data *data, bool retry)
return 0; return 0;
} }
static int mxt_probe_bootloader(struct mxt_data *data, bool retry) static int mxt_probe_bootloader(struct mxt_data *data, bool alt_address)
{ {
struct device *dev = &data->client->dev; struct device *dev = &data->client->dev;
int ret; int error;
u8 val; u8 val;
bool crc_failure; bool crc_failure;
ret = mxt_lookup_bootloader_address(data, retry); error = mxt_lookup_bootloader_address(data, alt_address);
if (ret) if (error)
return ret; return error;
ret = mxt_bootloader_read(data, &val, 1); error = mxt_bootloader_read(data, &val, 1);
if (ret) if (error)
return ret; return error;
/* Check app crc fail mode */ /* Check app crc fail mode */
crc_failure = (val & ~MXT_BOOT_STATUS_MASK) == MXT_APP_CRC_FAIL; crc_failure = (val & ~MXT_BOOT_STATUS_MASK) == MXT_APP_CRC_FAIL;
...@@ -1645,30 +1645,31 @@ static void mxt_config_cb(const struct firmware *cfg, void *ctx) ...@@ -1645,30 +1645,31 @@ static void mxt_config_cb(const struct firmware *cfg, void *ctx)
static int mxt_initialize(struct mxt_data *data) static int mxt_initialize(struct mxt_data *data)
{ {
struct i2c_client *client = data->client; struct i2c_client *client = data->client;
int recovery_attempts = 0;
int error; int error;
bool alt_bootloader_addr = false;
bool retry = false;
retry_info: while (1) {
error = mxt_get_info(data); error = mxt_get_info(data);
if (!error)
break;
/* Check bootloader state */
error = mxt_probe_bootloader(data, false);
if (error) { if (error) {
retry_bootloader: dev_info(&client->dev, "Trying alternate bootloader address\n");
error = mxt_probe_bootloader(data, alt_bootloader_addr); error = mxt_probe_bootloader(data, true);
if (error) { if (error) {
if (alt_bootloader_addr) {
/* Chip is not in appmode or bootloader mode */ /* Chip is not in appmode or bootloader mode */
return error; return error;
} }
}
dev_info(&client->dev, "Trying alternate bootloader address\n"); /* OK, we are in bootloader, see if we can recover */
alt_bootloader_addr = true; if (++recovery_attempts > 1) {
goto retry_bootloader;
} else {
if (retry) {
dev_err(&client->dev, "Could not recover from bootloader mode\n"); dev_err(&client->dev, "Could not recover from bootloader mode\n");
/* /*
* We can reflash from this state, so do not * We can reflash from this state, so do not
* abort init * abort initialization.
*/ */
data->in_bootloader = true; data->in_bootloader = true;
return 0; return 0;
...@@ -1677,9 +1678,6 @@ static int mxt_initialize(struct mxt_data *data) ...@@ -1677,9 +1678,6 @@ static int mxt_initialize(struct mxt_data *data)
/* Attempt to exit bootloader into app mode */ /* Attempt to exit bootloader into app mode */
mxt_send_bootloader_cmd(data, false); mxt_send_bootloader_cmd(data, false);
msleep(MXT_FW_RESET_TIME); msleep(MXT_FW_RESET_TIME);
retry = true;
goto retry_info;
}
} }
/* Get object table information */ /* Get object table information */
...@@ -1693,9 +1691,14 @@ static int mxt_initialize(struct mxt_data *data) ...@@ -1693,9 +1691,14 @@ static int mxt_initialize(struct mxt_data *data)
if (error) if (error)
goto err_free_object_table; goto err_free_object_table;
request_firmware_nowait(THIS_MODULE, true, MXT_CFG_NAME, error = request_firmware_nowait(THIS_MODULE, true, MXT_CFG_NAME,
&data->client->dev, GFP_KERNEL, data, &client->dev, GFP_KERNEL, data,
mxt_config_cb); mxt_config_cb);
if (error) {
dev_err(&client->dev, "Failed to invoke firmware loader: %d\n",
error);
goto err_free_object_table;
}
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment