diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-08-08 12:28:45 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-08-13 12:16:10 -0400 |
commit | 6cd1ab0fb67f21e6e35eee35106d8dd2f08b544c (patch) | |
tree | b2d2b462312e24ffa1a28ea82f12995be9f0db1d | |
parent | 23526d94977af1b006bb8d14639f2f33a444db7b (diff) |
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: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
-rw-r--r-- | drivers/input/touchscreen/atmel_mxt_ts.c | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index d50c6147bb76..a5f943dedb20 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c | |||
@@ -359,7 +359,6 @@ static int mxt_bootloader_read(struct mxt_data *data, | |||
359 | msg.buf = val; | 359 | msg.buf = val; |
360 | 360 | ||
361 | ret = i2c_transfer(data->client->adapter, &msg, 1); | 361 | ret = i2c_transfer(data->client->adapter, &msg, 1); |
362 | |||
363 | if (ret == 1) { | 362 | if (ret == 1) { |
364 | ret = 0; | 363 | ret = 0; |
365 | } else { | 364 | } else { |
@@ -414,6 +413,7 @@ static int mxt_lookup_bootloader_address(struct mxt_data *data, bool retry) | |||
414 | case 0x5b: | 413 | case 0x5b: |
415 | bootloader = appmode - 0x26; | 414 | bootloader = appmode - 0x26; |
416 | break; | 415 | break; |
416 | |||
417 | default: | 417 | default: |
418 | dev_err(&data->client->dev, | 418 | dev_err(&data->client->dev, |
419 | "Appmode i2c address 0x%02x not found\n", | 419 | "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 | return 0; | 425 | return 0; |
426 | } | 426 | } |
427 | 427 | ||
428 | static int mxt_probe_bootloader(struct mxt_data *data, bool retry) | 428 | static int mxt_probe_bootloader(struct mxt_data *data, bool alt_address) |
429 | { | 429 | { |
430 | struct device *dev = &data->client->dev; | 430 | struct device *dev = &data->client->dev; |
431 | int ret; | 431 | int error; |
432 | u8 val; | 432 | u8 val; |
433 | bool crc_failure; | 433 | bool crc_failure; |
434 | 434 | ||
435 | ret = mxt_lookup_bootloader_address(data, retry); | 435 | error = mxt_lookup_bootloader_address(data, alt_address); |
436 | if (ret) | 436 | if (error) |
437 | return ret; | 437 | return error; |
438 | 438 | ||
439 | ret = mxt_bootloader_read(data, &val, 1); | 439 | error = mxt_bootloader_read(data, &val, 1); |
440 | if (ret) | 440 | if (error) |
441 | return ret; | 441 | return error; |
442 | 442 | ||
443 | /* Check app crc fail mode */ | 443 | /* Check app crc fail mode */ |
444 | crc_failure = (val & ~MXT_BOOT_STATUS_MASK) == MXT_APP_CRC_FAIL; | 444 | crc_failure = (val & ~MXT_BOOT_STATUS_MASK) == MXT_APP_CRC_FAIL; |
@@ -1645,41 +1645,39 @@ static void mxt_config_cb(const struct firmware *cfg, void *ctx) | |||
1645 | static int mxt_initialize(struct mxt_data *data) | 1645 | static int mxt_initialize(struct mxt_data *data) |
1646 | { | 1646 | { |
1647 | struct i2c_client *client = data->client; | 1647 | struct i2c_client *client = data->client; |
1648 | int recovery_attempts = 0; | ||
1648 | int error; | 1649 | int error; |
1649 | bool alt_bootloader_addr = false; | ||
1650 | bool retry = false; | ||
1651 | 1650 | ||
1652 | retry_info: | 1651 | while (1) { |
1653 | error = mxt_get_info(data); | 1652 | error = mxt_get_info(data); |
1654 | if (error) { | 1653 | if (!error) |
1655 | retry_bootloader: | 1654 | break; |
1656 | error = mxt_probe_bootloader(data, alt_bootloader_addr); | 1655 | |
1656 | /* Check bootloader state */ | ||
1657 | error = mxt_probe_bootloader(data, false); | ||
1657 | if (error) { | 1658 | if (error) { |
1658 | if (alt_bootloader_addr) { | 1659 | dev_info(&client->dev, "Trying alternate bootloader address\n"); |
1660 | error = mxt_probe_bootloader(data, true); | ||
1661 | if (error) { | ||
1659 | /* Chip is not in appmode or bootloader mode */ | 1662 | /* Chip is not in appmode or bootloader mode */ |
1660 | return error; | 1663 | return error; |
1661 | } | 1664 | } |
1665 | } | ||
1662 | 1666 | ||
1663 | dev_info(&client->dev, "Trying alternate bootloader address\n"); | 1667 | /* OK, we are in bootloader, see if we can recover */ |
1664 | alt_bootloader_addr = true; | 1668 | if (++recovery_attempts > 1) { |
1665 | goto retry_bootloader; | 1669 | dev_err(&client->dev, "Could not recover from bootloader mode\n"); |
1666 | } else { | 1670 | /* |
1667 | if (retry) { | 1671 | * We can reflash from this state, so do not |
1668 | dev_err(&client->dev, "Could not recover from bootloader mode\n"); | 1672 | * abort initialization. |
1669 | /* | 1673 | */ |
1670 | * We can reflash from this state, so do not | 1674 | data->in_bootloader = true; |
1671 | * abort init | 1675 | return 0; |
1672 | */ | ||
1673 | data->in_bootloader = true; | ||
1674 | return 0; | ||
1675 | } | ||
1676 | |||
1677 | /* Attempt to exit bootloader into app mode */ | ||
1678 | mxt_send_bootloader_cmd(data, false); | ||
1679 | msleep(MXT_FW_RESET_TIME); | ||
1680 | retry = true; | ||
1681 | goto retry_info; | ||
1682 | } | 1676 | } |
1677 | |||
1678 | /* Attempt to exit bootloader into app mode */ | ||
1679 | mxt_send_bootloader_cmd(data, false); | ||
1680 | msleep(MXT_FW_RESET_TIME); | ||
1683 | } | 1681 | } |
1684 | 1682 | ||
1685 | /* Get object table information */ | 1683 | /* Get object table information */ |
@@ -1693,9 +1691,14 @@ retry_bootloader: | |||
1693 | if (error) | 1691 | if (error) |
1694 | goto err_free_object_table; | 1692 | goto err_free_object_table; |
1695 | 1693 | ||
1696 | request_firmware_nowait(THIS_MODULE, true, MXT_CFG_NAME, | 1694 | error = request_firmware_nowait(THIS_MODULE, true, MXT_CFG_NAME, |
1697 | &data->client->dev, GFP_KERNEL, data, | 1695 | &client->dev, GFP_KERNEL, data, |
1698 | mxt_config_cb); | 1696 | mxt_config_cb); |
1697 | if (error) { | ||
1698 | dev_err(&client->dev, "Failed to invoke firmware loader: %d\n", | ||
1699 | error); | ||
1700 | goto err_free_object_table; | ||
1701 | } | ||
1699 | 1702 | ||
1700 | return 0; | 1703 | return 0; |
1701 | 1704 | ||