diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2019-07-16 00:10:39 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-07-16 00:10:39 -0400 |
| commit | 273cbf61c3ddee9574ef1f4959b9bc6db5b24271 (patch) | |
| tree | 1eb8a54d416453ad7c6adbf57ab05dce2587a012 /drivers/misc/eeprom | |
| parent | 5fe7b600a116187e10317d83fb56922c4ef6b76d (diff) | |
| parent | cc6b9dfb2c5769afeb3335048173c730bdf8dbe1 (diff) | |
Merge branch 'i2c/for-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c updates from Wolfram Sang:
"New stuff from the I2C world:
- in the core, getting irqs from ACPI is now similar to OF
- new driver for MediaTek MT7621/7628/7688 SoCs
- bcm2835, i801, and tegra drivers got some more attention
- GPIO API cleanups
- cleanups in the core headers
- lots of usual driver updates"
* 'i2c/for-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (74 commits)
i2c: mt7621: Fix platform_no_drv_owner.cocci warnings
i2c: cpm: remove casting dma_alloc
dt-bindings: i2c: sun6i-p2wi: Fix the binding example
dt-bindings: i2c: mv64xxx: Fix the example compatible
i2c: i801: Documentation update
i2c: i801: Add support for Intel Tiger Lake
i2c: i801: Fix PCI ID sorting
dt-bindings: i2c-stm32: document optional dmas
i2c: i2c-stm32f7: Add I2C_SMBUS_I2C_BLOCK_DATA support
i2c: core: Tidy up handling of init_irq
i2c: core: Move ACPI gpio IRQ handling into i2c_acpi_get_irq
i2c: core: Move ACPI IRQ handling to probe time
i2c: acpi: Factor out getting the IRQ from ACPI
i2c: acpi: Use available IRQ helper functions
i2c: core: Allow whole core to use i2c_dev_irq_from_resources
eeprom: at24: modify a comment referring to platform data
dt-bindings: i2c: omap: Add new compatible for J721E SoCs
dt-bindings: i2c: mv64xxx: Add YAML schemas
dt-bindings: i2c: sun6i-p2wi: Add YAML schemas
i2c: mt7621: Add MediaTek MT7621/7628/7688 I2C driver
...
Diffstat (limited to 'drivers/misc/eeprom')
| -rw-r--r-- | drivers/misc/eeprom/at24.c | 86 |
1 files changed, 28 insertions, 58 deletions
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 63aa541c9608..35bf2477693d 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c | |||
| @@ -507,38 +507,24 @@ static const struct at24_chip_data *at24_get_chip_data(struct device *dev) | |||
| 507 | return cdata; | 507 | return cdata; |
| 508 | } | 508 | } |
| 509 | 509 | ||
| 510 | static void at24_remove_dummy_clients(struct at24_data *at24) | ||
| 511 | { | ||
| 512 | int i; | ||
| 513 | |||
| 514 | for (i = 1; i < at24->num_addresses; i++) | ||
| 515 | i2c_unregister_device(at24->client[i].client); | ||
| 516 | } | ||
| 517 | |||
| 518 | static int at24_make_dummy_client(struct at24_data *at24, unsigned int index, | 510 | static int at24_make_dummy_client(struct at24_data *at24, unsigned int index, |
| 519 | struct regmap_config *regmap_config) | 511 | struct regmap_config *regmap_config) |
| 520 | { | 512 | { |
| 521 | struct i2c_client *base_client, *dummy_client; | 513 | struct i2c_client *base_client, *dummy_client; |
| 522 | unsigned short int addr; | ||
| 523 | struct regmap *regmap; | 514 | struct regmap *regmap; |
| 524 | struct device *dev; | 515 | struct device *dev; |
| 525 | 516 | ||
| 526 | base_client = at24->client[0].client; | 517 | base_client = at24->client[0].client; |
| 527 | dev = &base_client->dev; | 518 | dev = &base_client->dev; |
| 528 | addr = base_client->addr + index; | ||
| 529 | 519 | ||
| 530 | dummy_client = i2c_new_dummy(base_client->adapter, | 520 | dummy_client = devm_i2c_new_dummy_device(dev, base_client->adapter, |
| 531 | base_client->addr + index); | 521 | base_client->addr + index); |
| 532 | if (!dummy_client) { | 522 | if (IS_ERR(dummy_client)) |
| 533 | dev_err(dev, "address 0x%02x unavailable\n", addr); | 523 | return PTR_ERR(dummy_client); |
| 534 | return -EADDRINUSE; | ||
| 535 | } | ||
| 536 | 524 | ||
| 537 | regmap = devm_regmap_init_i2c(dummy_client, regmap_config); | 525 | regmap = devm_regmap_init_i2c(dummy_client, regmap_config); |
| 538 | if (IS_ERR(regmap)) { | 526 | if (IS_ERR(regmap)) |
| 539 | i2c_unregister_device(dummy_client); | ||
| 540 | return PTR_ERR(regmap); | 527 | return PTR_ERR(regmap); |
| 541 | } | ||
| 542 | 528 | ||
| 543 | at24->client[index].client = dummy_client; | 529 | at24->client[index].client = dummy_client; |
| 544 | at24->client[index].regmap = regmap; | 530 | at24->client[index].regmap = regmap; |
| @@ -580,7 +566,6 @@ static int at24_probe(struct i2c_client *client) | |||
| 580 | unsigned int i, num_addresses; | 566 | unsigned int i, num_addresses; |
| 581 | struct at24_data *at24; | 567 | struct at24_data *at24; |
| 582 | struct regmap *regmap; | 568 | struct regmap *regmap; |
| 583 | size_t at24_size; | ||
| 584 | bool writable; | 569 | bool writable; |
| 585 | u8 test_byte; | 570 | u8 test_byte; |
| 586 | int err; | 571 | int err; |
| @@ -597,8 +582,8 @@ static int at24_probe(struct i2c_client *client) | |||
| 597 | if (err) | 582 | if (err) |
| 598 | /* | 583 | /* |
| 599 | * This is slow, but we can't know all eeproms, so we better | 584 | * This is slow, but we can't know all eeproms, so we better |
| 600 | * play safe. Specifying custom eeprom-types via platform_data | 585 | * play safe. Specifying custom eeprom-types via device tree |
| 601 | * is recommended anyhow. | 586 | * or properties is recommended anyhow. |
| 602 | */ | 587 | */ |
| 603 | page_size = 1; | 588 | page_size = 1; |
| 604 | 589 | ||
| @@ -664,8 +649,8 @@ static int at24_probe(struct i2c_client *client) | |||
| 664 | if (IS_ERR(regmap)) | 649 | if (IS_ERR(regmap)) |
| 665 | return PTR_ERR(regmap); | 650 | return PTR_ERR(regmap); |
| 666 | 651 | ||
| 667 | at24_size = sizeof(*at24) + num_addresses * sizeof(struct at24_client); | 652 | at24 = devm_kzalloc(dev, struct_size(at24, client, num_addresses), |
| 668 | at24 = devm_kzalloc(dev, at24_size, GFP_KERNEL); | 653 | GFP_KERNEL); |
| 669 | if (!at24) | 654 | if (!at24) |
| 670 | return -ENOMEM; | 655 | return -ENOMEM; |
| 671 | 656 | ||
| @@ -693,27 +678,8 @@ static int at24_probe(struct i2c_client *client) | |||
| 693 | /* use dummy devices for multiple-address chips */ | 678 | /* use dummy devices for multiple-address chips */ |
| 694 | for (i = 1; i < num_addresses; i++) { | 679 | for (i = 1; i < num_addresses; i++) { |
| 695 | err = at24_make_dummy_client(at24, i, ®map_config); | 680 | err = at24_make_dummy_client(at24, i, ®map_config); |
| 696 | if (err) { | 681 | if (err) |
| 697 | at24_remove_dummy_clients(at24); | ||
| 698 | return err; | 682 | return err; |
| 699 | } | ||
| 700 | } | ||
| 701 | |||
| 702 | i2c_set_clientdata(client, at24); | ||
| 703 | |||
| 704 | /* enable runtime pm */ | ||
| 705 | pm_runtime_set_active(dev); | ||
| 706 | pm_runtime_enable(dev); | ||
| 707 | |||
| 708 | /* | ||
| 709 | * Perform a one-byte test read to verify that the | ||
| 710 | * chip is functional. | ||
| 711 | */ | ||
| 712 | err = at24_read(at24, 0, &test_byte, 1); | ||
| 713 | pm_runtime_idle(dev); | ||
| 714 | if (err) { | ||
| 715 | err = -ENODEV; | ||
| 716 | goto err_clients; | ||
| 717 | } | 683 | } |
| 718 | 684 | ||
| 719 | nvmem_config.name = dev_name(dev); | 685 | nvmem_config.name = dev_name(dev); |
| @@ -731,9 +697,24 @@ static int at24_probe(struct i2c_client *client) | |||
| 731 | nvmem_config.size = byte_len; | 697 | nvmem_config.size = byte_len; |
| 732 | 698 | ||
| 733 | at24->nvmem = devm_nvmem_register(dev, &nvmem_config); | 699 | at24->nvmem = devm_nvmem_register(dev, &nvmem_config); |
| 734 | if (IS_ERR(at24->nvmem)) { | 700 | if (IS_ERR(at24->nvmem)) |
| 735 | err = PTR_ERR(at24->nvmem); | 701 | return PTR_ERR(at24->nvmem); |
| 736 | goto err_clients; | 702 | |
| 703 | i2c_set_clientdata(client, at24); | ||
| 704 | |||
| 705 | /* enable runtime pm */ | ||
| 706 | pm_runtime_set_active(dev); | ||
| 707 | pm_runtime_enable(dev); | ||
| 708 | |||
| 709 | /* | ||
| 710 | * Perform a one-byte test read to verify that the | ||
| 711 | * chip is functional. | ||
| 712 | */ | ||
| 713 | err = at24_read(at24, 0, &test_byte, 1); | ||
| 714 | pm_runtime_idle(dev); | ||
| 715 | if (err) { | ||
| 716 | pm_runtime_disable(dev); | ||
| 717 | return -ENODEV; | ||
| 737 | } | 718 | } |
| 738 | 719 | ||
| 739 | dev_info(dev, "%u byte %s EEPROM, %s, %u bytes/write\n", | 720 | dev_info(dev, "%u byte %s EEPROM, %s, %u bytes/write\n", |
| @@ -741,21 +722,10 @@ static int at24_probe(struct i2c_client *client) | |||
| 741 | writable ? "writable" : "read-only", at24->write_max); | 722 | writable ? "writable" : "read-only", at24->write_max); |
| 742 | 723 | ||
| 743 | return 0; | 724 | return 0; |
| 744 | |||
| 745 | err_clients: | ||
| 746 | at24_remove_dummy_clients(at24); | ||
| 747 | pm_runtime_disable(dev); | ||
| 748 | |||
| 749 | return err; | ||
| 750 | } | 725 | } |
| 751 | 726 | ||
| 752 | static int at24_remove(struct i2c_client *client) | 727 | static int at24_remove(struct i2c_client *client) |
| 753 | { | 728 | { |
| 754 | struct at24_data *at24; | ||
| 755 | |||
| 756 | at24 = i2c_get_clientdata(client); | ||
| 757 | |||
| 758 | at24_remove_dummy_clients(at24); | ||
| 759 | pm_runtime_disable(&client->dev); | 729 | pm_runtime_disable(&client->dev); |
| 760 | pm_runtime_set_suspended(&client->dev); | 730 | pm_runtime_set_suspended(&client->dev); |
| 761 | 731 | ||
