diff options
| author | Bartosz Golaszewski <brgl@bgdev.pl> | 2018-03-19 05:17:21 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-03-23 11:25:45 -0400 |
| commit | 34d43faf3aa80f72617da5f2d460262c1e0bbf48 (patch) | |
| tree | ed62207be4b50e495cfb00976332389608cf453d /drivers/misc | |
| parent | df3da615e3f020d4b689eb23d33d10f285db2fb6 (diff) | |
eeprom: at24: simplify the i2c functionality checking
Save one call and make code prettier by checking the i2c functionality
in the beginning of at24_probe(), saving the relevant values and
reusing them later.
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Tested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc')
| -rw-r--r-- | drivers/misc/eeprom/at24.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index ef937390af13..49b7831c238a 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c | |||
| @@ -564,6 +564,7 @@ static int at24_probe(struct i2c_client *client) | |||
| 564 | struct nvmem_config nvmem_config = { }; | 564 | struct nvmem_config nvmem_config = { }; |
| 565 | struct at24_platform_data pdata = { }; | 565 | struct at24_platform_data pdata = { }; |
| 566 | struct device *dev = &client->dev; | 566 | struct device *dev = &client->dev; |
| 567 | bool i2c_fn_i2c, i2c_fn_block; | ||
| 567 | unsigned int i, num_addresses; | 568 | unsigned int i, num_addresses; |
| 568 | struct at24_data *at24; | 569 | struct at24_data *at24; |
| 569 | struct regmap *regmap; | 570 | struct regmap *regmap; |
| @@ -572,13 +573,15 @@ static int at24_probe(struct i2c_client *client) | |||
| 572 | u8 test_byte; | 573 | u8 test_byte; |
| 573 | int err; | 574 | int err; |
| 574 | 575 | ||
| 576 | i2c_fn_i2c = i2c_check_functionality(client->adapter, I2C_FUNC_I2C); | ||
| 577 | i2c_fn_block = i2c_check_functionality(client->adapter, | ||
| 578 | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK); | ||
| 579 | |||
| 575 | err = at24_get_pdata(dev, &pdata); | 580 | err = at24_get_pdata(dev, &pdata); |
| 576 | if (err) | 581 | if (err) |
| 577 | return err; | 582 | return err; |
| 578 | 583 | ||
| 579 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) && | 584 | if (!i2c_fn_i2c && !i2c_fn_block) |
| 580 | !i2c_check_functionality(client->adapter, | ||
| 581 | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) | ||
| 582 | pdata.page_size = 1; | 585 | pdata.page_size = 1; |
| 583 | 586 | ||
| 584 | if (!pdata.page_size) { | 587 | if (!pdata.page_size) { |
| @@ -631,8 +634,7 @@ static int at24_probe(struct i2c_client *client) | |||
| 631 | if (writable) { | 634 | if (writable) { |
| 632 | at24->write_max = min_t(unsigned int, | 635 | at24->write_max = min_t(unsigned int, |
| 633 | pdata.page_size, at24_io_limit); | 636 | pdata.page_size, at24_io_limit); |
| 634 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) && | 637 | if (!i2c_fn_i2c && at24->write_max > I2C_SMBUS_BLOCK_MAX) |
| 635 | at24->write_max > I2C_SMBUS_BLOCK_MAX) | ||
| 636 | at24->write_max = I2C_SMBUS_BLOCK_MAX; | 638 | at24->write_max = I2C_SMBUS_BLOCK_MAX; |
| 637 | } | 639 | } |
| 638 | 640 | ||
