|
@@ -566,6 +566,7 @@ static int at24_probe(struct i2c_client *client)
|
|
struct device *dev = &client->dev;
|
|
struct device *dev = &client->dev;
|
|
unsigned int i, num_addresses;
|
|
unsigned int i, num_addresses;
|
|
struct at24_data *at24;
|
|
struct at24_data *at24;
|
|
|
|
+ struct regmap *regmap;
|
|
size_t at24_size;
|
|
size_t at24_size;
|
|
bool writable;
|
|
bool writable;
|
|
u8 test_byte;
|
|
u8 test_byte;
|
|
@@ -575,6 +576,11 @@ static int at24_probe(struct i2c_client *client)
|
|
if (err)
|
|
if (err)
|
|
return err;
|
|
return err;
|
|
|
|
|
|
|
|
+ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) &&
|
|
|
|
+ !i2c_check_functionality(client->adapter,
|
|
|
|
+ I2C_FUNC_SMBUS_WRITE_I2C_BLOCK))
|
|
|
|
+ pdata.page_size = 1;
|
|
|
|
+
|
|
if (!pdata.page_size) {
|
|
if (!pdata.page_size) {
|
|
dev_err(dev, "page_size must not be 0!\n");
|
|
dev_err(dev, "page_size must not be 0!\n");
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
@@ -582,21 +588,26 @@ static int at24_probe(struct i2c_client *client)
|
|
if (!is_power_of_2(pdata.page_size))
|
|
if (!is_power_of_2(pdata.page_size))
|
|
dev_warn(dev, "page_size looks suspicious (no power of 2)!\n");
|
|
dev_warn(dev, "page_size looks suspicious (no power of 2)!\n");
|
|
|
|
|
|
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) &&
|
|
|
|
- !i2c_check_functionality(client->adapter,
|
|
|
|
- I2C_FUNC_SMBUS_WRITE_I2C_BLOCK))
|
|
|
|
- pdata.page_size = 1;
|
|
|
|
-
|
|
|
|
if (pdata.flags & AT24_FLAG_TAKE8ADDR)
|
|
if (pdata.flags & AT24_FLAG_TAKE8ADDR)
|
|
num_addresses = 8;
|
|
num_addresses = 8;
|
|
else
|
|
else
|
|
num_addresses = DIV_ROUND_UP(pdata.byte_len,
|
|
num_addresses = DIV_ROUND_UP(pdata.byte_len,
|
|
(pdata.flags & AT24_FLAG_ADDR16) ? 65536 : 256);
|
|
(pdata.flags & AT24_FLAG_ADDR16) ? 65536 : 256);
|
|
|
|
|
|
|
|
+ if ((pdata.flags & AT24_FLAG_SERIAL) && (pdata.flags & AT24_FLAG_MAC)) {
|
|
|
|
+ dev_err(dev,
|
|
|
|
+ "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC.");
|
|
|
|
+ return -EINVAL;
|
|
|
|
+ }
|
|
|
|
+
|
|
regmap_config.val_bits = 8;
|
|
regmap_config.val_bits = 8;
|
|
regmap_config.reg_bits = (pdata.flags & AT24_FLAG_ADDR16) ? 16 : 8;
|
|
regmap_config.reg_bits = (pdata.flags & AT24_FLAG_ADDR16) ? 16 : 8;
|
|
regmap_config.disable_locking = true;
|
|
regmap_config.disable_locking = true;
|
|
|
|
|
|
|
|
+ regmap = devm_regmap_init_i2c(client, ®map_config);
|
|
|
|
+ if (IS_ERR(regmap))
|
|
|
|
+ return PTR_ERR(regmap);
|
|
|
|
+
|
|
at24_size = sizeof(*at24) + num_addresses * sizeof(struct at24_client);
|
|
at24_size = sizeof(*at24) + num_addresses * sizeof(struct at24_client);
|
|
at24 = devm_kzalloc(dev, at24_size, GFP_KERNEL);
|
|
at24 = devm_kzalloc(dev, at24_size, GFP_KERNEL);
|
|
if (!at24)
|
|
if (!at24)
|
|
@@ -608,22 +619,13 @@ static int at24_probe(struct i2c_client *client)
|
|
at24->flags = pdata.flags;
|
|
at24->flags = pdata.flags;
|
|
at24->num_addresses = num_addresses;
|
|
at24->num_addresses = num_addresses;
|
|
at24->offset_adj = at24_get_offset_adj(pdata.flags, pdata.byte_len);
|
|
at24->offset_adj = at24_get_offset_adj(pdata.flags, pdata.byte_len);
|
|
|
|
+ at24->client[0].client = client;
|
|
|
|
+ at24->client[0].regmap = regmap;
|
|
|
|
|
|
at24->wp_gpio = devm_gpiod_get_optional(dev, "wp", GPIOD_OUT_HIGH);
|
|
at24->wp_gpio = devm_gpiod_get_optional(dev, "wp", GPIOD_OUT_HIGH);
|
|
if (IS_ERR(at24->wp_gpio))
|
|
if (IS_ERR(at24->wp_gpio))
|
|
return PTR_ERR(at24->wp_gpio);
|
|
return PTR_ERR(at24->wp_gpio);
|
|
|
|
|
|
- at24->client[0].client = client;
|
|
|
|
- at24->client[0].regmap = devm_regmap_init_i2c(client, ®map_config);
|
|
|
|
- if (IS_ERR(at24->client[0].regmap))
|
|
|
|
- return PTR_ERR(at24->client[0].regmap);
|
|
|
|
-
|
|
|
|
- if ((pdata.flags & AT24_FLAG_SERIAL) && (pdata.flags & AT24_FLAG_MAC)) {
|
|
|
|
- dev_err(dev,
|
|
|
|
- "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC.");
|
|
|
|
- return -EINVAL;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
writable = !(pdata.flags & AT24_FLAG_READONLY);
|
|
writable = !(pdata.flags & AT24_FLAG_READONLY);
|
|
if (writable) {
|
|
if (writable) {
|
|
at24->write_max = min_t(unsigned int,
|
|
at24->write_max = min_t(unsigned int,
|