diff options
author | Srinivas Kandagatla <srinivas.kandagatla@linaro.org> | 2016-04-24 15:28:06 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-05-01 17:01:00 -0400 |
commit | cf0361a2d2b809c6f5b73313544711648fd7afdd (patch) | |
tree | 4056f36a0db43419bee2bca4d6626692ca313591 /drivers/misc/eeprom | |
parent | 795ddd18d38f9762fbfefceab9aa16caef0cf431 (diff) |
eeprom: at24: remove nvmem regmap dependency
This patch moves to nvmem support in the driver to use callback instead
of regmap.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc/eeprom')
-rw-r--r-- | drivers/misc/eeprom/Kconfig | 1 | ||||
-rw-r--r-- | drivers/misc/eeprom/at24.c | 103 |
2 files changed, 22 insertions, 82 deletions
diff --git a/drivers/misc/eeprom/Kconfig b/drivers/misc/eeprom/Kconfig index cfc493c2e30a..2d70464e8c8d 100644 --- a/drivers/misc/eeprom/Kconfig +++ b/drivers/misc/eeprom/Kconfig | |||
@@ -3,7 +3,6 @@ menu "EEPROM support" | |||
3 | config EEPROM_AT24 | 3 | config EEPROM_AT24 |
4 | tristate "I2C EEPROMs / RAMs / ROMs from most vendors" | 4 | tristate "I2C EEPROMs / RAMs / ROMs from most vendors" |
5 | depends on I2C && SYSFS | 5 | depends on I2C && SYSFS |
6 | select REGMAP | ||
7 | select NVMEM | 6 | select NVMEM |
8 | help | 7 | help |
9 | Enable this driver to get read/write support to most I2C EEPROMs | 8 | Enable this driver to get read/write support to most I2C EEPROMs |
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 089d6943f68a..de550a605f7d 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c | |||
@@ -23,7 +23,6 @@ | |||
23 | #include <linux/acpi.h> | 23 | #include <linux/acpi.h> |
24 | #include <linux/i2c.h> | 24 | #include <linux/i2c.h> |
25 | #include <linux/nvmem-provider.h> | 25 | #include <linux/nvmem-provider.h> |
26 | #include <linux/regmap.h> | ||
27 | #include <linux/platform_data/at24.h> | 26 | #include <linux/platform_data/at24.h> |
28 | 27 | ||
29 | /* | 28 | /* |
@@ -69,7 +68,6 @@ struct at24_data { | |||
69 | unsigned write_max; | 68 | unsigned write_max; |
70 | unsigned num_addresses; | 69 | unsigned num_addresses; |
71 | 70 | ||
72 | struct regmap_config regmap_config; | ||
73 | struct nvmem_config nvmem_config; | 71 | struct nvmem_config nvmem_config; |
74 | struct nvmem_device *nvmem; | 72 | struct nvmem_device *nvmem; |
75 | 73 | ||
@@ -252,10 +250,10 @@ static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf, | |||
252 | return -ETIMEDOUT; | 250 | return -ETIMEDOUT; |
253 | } | 251 | } |
254 | 252 | ||
255 | static ssize_t at24_read(struct at24_data *at24, | 253 | static int at24_read(void *priv, unsigned int off, void *val, size_t count) |
256 | char *buf, loff_t off, size_t count) | ||
257 | { | 254 | { |
258 | ssize_t retval = 0; | 255 | struct at24_data *at24 = priv; |
256 | char *buf = val; | ||
259 | 257 | ||
260 | if (unlikely(!count)) | 258 | if (unlikely(!count)) |
261 | return count; | 259 | return count; |
@@ -267,23 +265,21 @@ static ssize_t at24_read(struct at24_data *at24, | |||
267 | mutex_lock(&at24->lock); | 265 | mutex_lock(&at24->lock); |
268 | 266 | ||
269 | while (count) { | 267 | while (count) { |
270 | ssize_t status; | 268 | int status; |
271 | 269 | ||
272 | status = at24_eeprom_read(at24, buf, off, count); | 270 | status = at24_eeprom_read(at24, buf, off, count); |
273 | if (status <= 0) { | 271 | if (status < 0) { |
274 | if (retval == 0) | 272 | mutex_unlock(&at24->lock); |
275 | retval = status; | 273 | return status; |
276 | break; | ||
277 | } | 274 | } |
278 | buf += status; | 275 | buf += status; |
279 | off += status; | 276 | off += status; |
280 | count -= status; | 277 | count -= status; |
281 | retval += status; | ||
282 | } | 278 | } |
283 | 279 | ||
284 | mutex_unlock(&at24->lock); | 280 | mutex_unlock(&at24->lock); |
285 | 281 | ||
286 | return retval; | 282 | return 0; |
287 | } | 283 | } |
288 | 284 | ||
289 | /* | 285 | /* |
@@ -372,13 +368,13 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf, | |||
372 | return -ETIMEDOUT; | 368 | return -ETIMEDOUT; |
373 | } | 369 | } |
374 | 370 | ||
375 | static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off, | 371 | static int at24_write(void *priv, unsigned int off, void *val, size_t count) |
376 | size_t count) | ||
377 | { | 372 | { |
378 | ssize_t retval = 0; | 373 | struct at24_data *at24 = priv; |
374 | char *buf = val; | ||
379 | 375 | ||
380 | if (unlikely(!count)) | 376 | if (unlikely(!count)) |
381 | return count; | 377 | return -EINVAL; |
382 | 378 | ||
383 | /* | 379 | /* |
384 | * Write data to chip, protecting against concurrent updates | 380 | * Write data to chip, protecting against concurrent updates |
@@ -387,70 +383,23 @@ static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off, | |||
387 | mutex_lock(&at24->lock); | 383 | mutex_lock(&at24->lock); |
388 | 384 | ||
389 | while (count) { | 385 | while (count) { |
390 | ssize_t status; | 386 | int status; |
391 | 387 | ||
392 | status = at24_eeprom_write(at24, buf, off, count); | 388 | status = at24_eeprom_write(at24, buf, off, count); |
393 | if (status <= 0) { | 389 | if (status < 0) { |
394 | if (retval == 0) | 390 | mutex_unlock(&at24->lock); |
395 | retval = status; | 391 | return status; |
396 | break; | ||
397 | } | 392 | } |
398 | buf += status; | 393 | buf += status; |
399 | off += status; | 394 | off += status; |
400 | count -= status; | 395 | count -= status; |
401 | retval += status; | ||
402 | } | 396 | } |
403 | 397 | ||
404 | mutex_unlock(&at24->lock); | 398 | mutex_unlock(&at24->lock); |
405 | 399 | ||
406 | return retval; | ||
407 | } | ||
408 | |||
409 | /*-------------------------------------------------------------------------*/ | ||
410 | |||
411 | /* | ||
412 | * Provide a regmap interface, which is registered with the NVMEM | ||
413 | * framework | ||
414 | */ | ||
415 | static int at24_regmap_read(void *context, const void *reg, size_t reg_size, | ||
416 | void *val, size_t val_size) | ||
417 | { | ||
418 | struct at24_data *at24 = context; | ||
419 | off_t offset = *(u32 *)reg; | ||
420 | int err; | ||
421 | |||
422 | err = at24_read(at24, val, offset, val_size); | ||
423 | if (err) | ||
424 | return err; | ||
425 | return 0; | ||
426 | } | ||
427 | |||
428 | static int at24_regmap_write(void *context, const void *data, size_t count) | ||
429 | { | ||
430 | struct at24_data *at24 = context; | ||
431 | const char *buf; | ||
432 | u32 offset; | ||
433 | size_t len; | ||
434 | int err; | ||
435 | |||
436 | memcpy(&offset, data, sizeof(offset)); | ||
437 | buf = (const char *)data + sizeof(offset); | ||
438 | len = count - sizeof(offset); | ||
439 | |||
440 | err = at24_write(at24, buf, offset, len); | ||
441 | if (err) | ||
442 | return err; | ||
443 | return 0; | 400 | return 0; |
444 | } | 401 | } |
445 | 402 | ||
446 | static const struct regmap_bus at24_regmap_bus = { | ||
447 | .read = at24_regmap_read, | ||
448 | .write = at24_regmap_write, | ||
449 | .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, | ||
450 | }; | ||
451 | |||
452 | /*-------------------------------------------------------------------------*/ | ||
453 | |||
454 | #ifdef CONFIG_OF | 403 | #ifdef CONFIG_OF |
455 | static void at24_get_ofdata(struct i2c_client *client, | 404 | static void at24_get_ofdata(struct i2c_client *client, |
456 | struct at24_platform_data *chip) | 405 | struct at24_platform_data *chip) |
@@ -482,7 +431,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
482 | struct at24_data *at24; | 431 | struct at24_data *at24; |
483 | int err; | 432 | int err; |
484 | unsigned i, num_addresses; | 433 | unsigned i, num_addresses; |
485 | struct regmap *regmap; | ||
486 | 434 | ||
487 | if (client->dev.platform_data) { | 435 | if (client->dev.platform_data) { |
488 | chip = *(struct at24_platform_data *)client->dev.platform_data; | 436 | chip = *(struct at24_platform_data *)client->dev.platform_data; |
@@ -612,19 +560,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
612 | } | 560 | } |
613 | } | 561 | } |
614 | 562 | ||
615 | at24->regmap_config.reg_bits = 32; | ||
616 | at24->regmap_config.val_bits = 8; | ||
617 | at24->regmap_config.reg_stride = 1; | ||
618 | at24->regmap_config.max_register = chip.byte_len - 1; | ||
619 | |||
620 | regmap = devm_regmap_init(&client->dev, &at24_regmap_bus, at24, | ||
621 | &at24->regmap_config); | ||
622 | if (IS_ERR(regmap)) { | ||
623 | dev_err(&client->dev, "regmap init failed\n"); | ||
624 | err = PTR_ERR(regmap); | ||
625 | goto err_clients; | ||
626 | } | ||
627 | |||
628 | at24->nvmem_config.name = dev_name(&client->dev); | 563 | at24->nvmem_config.name = dev_name(&client->dev); |
629 | at24->nvmem_config.dev = &client->dev; | 564 | at24->nvmem_config.dev = &client->dev; |
630 | at24->nvmem_config.read_only = !writable; | 565 | at24->nvmem_config.read_only = !writable; |
@@ -632,6 +567,12 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
632 | at24->nvmem_config.owner = THIS_MODULE; | 567 | at24->nvmem_config.owner = THIS_MODULE; |
633 | at24->nvmem_config.compat = true; | 568 | at24->nvmem_config.compat = true; |
634 | at24->nvmem_config.base_dev = &client->dev; | 569 | at24->nvmem_config.base_dev = &client->dev; |
570 | at24->nvmem_config.reg_read = at24_read; | ||
571 | at24->nvmem_config.reg_write = at24_write; | ||
572 | at24->nvmem_config.priv = at24; | ||
573 | at24->nvmem_config.stride = 4; | ||
574 | at24->nvmem_config.word_size = 1; | ||
575 | at24->nvmem_config.size = chip.byte_len; | ||
635 | 576 | ||
636 | at24->nvmem = nvmem_register(&at24->nvmem_config); | 577 | at24->nvmem = nvmem_register(&at24->nvmem_config); |
637 | 578 | ||