From c7035cbb37fe5b3a8ccf98e57596577509263203 Mon Sep 17 00:00:00 2001 From: Alessandro Carminati Date: Fri, 26 Jul 2024 14:17:43 +0200 Subject: [PATCH 1/6] eeprom: at24: Drop at24_get_chip_data() JIRA: https://issues.redhat.com/browse/RHEL-47160 Conflicts: * Avoiding commit ("misc: Switch i2c drivers back to use .probe()") to avoid drop the .probe_new() call-back type commit 4cdc5dbbc1df36c4d7c93c7c15dde88e997922c2 Author: Biju Das Date: Sat Sep 2 18:45:47 2023 +0100 eeprom: at24: Drop at24_get_chip_data() Replace at24_get_chip_data()->i2c_get_match_data() as it is redundant. Signed-off-by: Biju Das Reviewed-by: Andy Shevchenko Signed-off-by: Bartosz Golaszewski Signed-off-by: Alessandro Carminati --- drivers/misc/eeprom/at24.c | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 0885cb2ce422..119a20b49f24 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -509,32 +509,6 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count) return 0; } -static const struct at24_chip_data *at24_get_chip_data(struct device *dev) -{ - struct device_node *of_node = dev->of_node; - const struct at24_chip_data *cdata; - const struct i2c_device_id *id; - - id = i2c_match_id(at24_ids, to_i2c_client(dev)); - - /* - * The I2C core allows OF nodes compatibles to match against the - * I2C device ID table as a fallback, so check not only if an OF - * node is present but also if it matches an OF device ID entry. - */ - if (of_node && of_match_device(at24_of_match, dev)) - cdata = of_device_get_match_data(dev); - else if (id) - cdata = (void *)id->driver_data; - else - cdata = acpi_device_get_match_data(dev); - - if (!cdata) - return ERR_PTR(-ENODEV); - - return cdata; -} - static int at24_make_dummy_client(struct at24_data *at24, unsigned int index, struct i2c_client *base_client, struct regmap_config *regmap_config) @@ -626,9 +600,9 @@ static int at24_probe(struct i2c_client *client) i2c_fn_block = i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WRITE_I2C_BLOCK); - cdata = at24_get_chip_data(dev); - if (IS_ERR(cdata)) - return PTR_ERR(cdata); + cdata = i2c_get_match_data(client); + if (!cdata) + return -ENODEV; err = device_property_read_u32(dev, "pagesize", &page_size); if (err) From bb9af0fe783e7b847657999e3ae42f553c73d682 Mon Sep 17 00:00:00 2001 From: Alessandro Carminati Date: Fri, 26 Jul 2024 14:17:49 +0200 Subject: [PATCH 2/6] eeprom: at24: Annotate struct at24_data with __counted_by JIRA: https://issues.redhat.com/browse/RHEL-47160 Conflicts: * Avoiding commit ("misc: Switch i2c drivers back to use .probe()") to avoid drop the .probe_new() call-back type commit 997a29bbb1e0d6d10ebc2291fac604c4cded5828 Author: Kees Cook Date: Fri Sep 22 10:51:55 2023 -0700 eeprom: at24: Annotate struct at24_data with __counted_by Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). As found with Coccinelle[1], add __counted_by for struct at24_data. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Signed-off-by: Bartosz Golaszewski Signed-off-by: Alessandro Carminati --- drivers/misc/eeprom/at24.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 119a20b49f24..710cf47aabe4 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -92,7 +92,7 @@ struct at24_data { * them for us. */ u8 bank_addr_shift; - struct regmap *client_regmaps[]; + struct regmap *client_regmaps[] __counted_by(num_addresses); }; /* From 7924da3960ab3469c14da053ecf6b1d26f5abdb0 Mon Sep 17 00:00:00 2001 From: Alessandro Carminati Date: Fri, 26 Jul 2024 14:17:54 +0200 Subject: [PATCH 3/6] eeprom: at24: add ST M24C32-D Additional Write lockable page support JIRA: https://issues.redhat.com/browse/RHEL-47160 Conflicts: * Avoiding commit ("misc: Switch i2c drivers back to use .probe()") to avoid drop the .probe_new() call-back type commit 4791146e9055dd4c21a1a725514512167b8ee75b Author: Marek Vasut Date: Tue Oct 10 21:09:26 2023 +0200 eeprom: at24: add ST M24C32-D Additional Write lockable page support The ST M24C32-D behaves as a regular M24C32, except for the -D variant which uses up another I2C address for Additional Write lockable page. This page is 32 Bytes long and can contain additional data. Add entry for it, so users can describe that page in DT. Note that users still have to describe the main M24C32 area separately as that is on separate I2C address from this page. Signed-off-by: Marek Vasut Signed-off-by: Bartosz Golaszewski Signed-off-by: Alessandro Carminati --- drivers/misc/eeprom/at24.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 710cf47aabe4..54a2dead0b44 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -191,6 +191,8 @@ AT24_CHIP_DATA(at24_data_24c16, 16384 / 8, 0); AT24_CHIP_DATA(at24_data_24cs16, 16, AT24_FLAG_SERIAL | AT24_FLAG_READONLY); AT24_CHIP_DATA(at24_data_24c32, 32768 / 8, AT24_FLAG_ADDR16); +/* M24C32-D Additional Write lockable page (M24C32-D order codes) */ +AT24_CHIP_DATA(at24_data_24c32d_wlp, 32, AT24_FLAG_ADDR16); AT24_CHIP_DATA(at24_data_24cs32, 16, AT24_FLAG_ADDR16 | AT24_FLAG_SERIAL | AT24_FLAG_READONLY); AT24_CHIP_DATA(at24_data_24c64, 65536 / 8, AT24_FLAG_ADDR16); @@ -222,6 +224,7 @@ static const struct i2c_device_id at24_ids[] = { { "24c16", (kernel_ulong_t)&at24_data_24c16 }, { "24cs16", (kernel_ulong_t)&at24_data_24cs16 }, { "24c32", (kernel_ulong_t)&at24_data_24c32 }, + { "24c32d-wl", (kernel_ulong_t)&at24_data_24c32d_wlp }, { "24cs32", (kernel_ulong_t)&at24_data_24cs32 }, { "24c64", (kernel_ulong_t)&at24_data_24c64 }, { "24cs64", (kernel_ulong_t)&at24_data_24cs64 }, @@ -252,6 +255,7 @@ static const struct of_device_id at24_of_match[] = { { .compatible = "atmel,24c16", .data = &at24_data_24c16 }, { .compatible = "atmel,24cs16", .data = &at24_data_24cs16 }, { .compatible = "atmel,24c32", .data = &at24_data_24c32 }, + { .compatible = "atmel,24c32d-wl", .data = &at24_data_24c32d_wlp }, { .compatible = "atmel,24cs32", .data = &at24_data_24cs32 }, { .compatible = "atmel,24c64", .data = &at24_data_24c64 }, { .compatible = "atmel,24cs64", .data = &at24_data_24cs64 }, From b58d2648860bff2e2c66318d74173d21c26351ec Mon Sep 17 00:00:00 2001 From: Alessandro Carminati Date: Fri, 26 Jul 2024 14:17:58 +0200 Subject: [PATCH 4/6] eeprom: at24: add ST M24C64-D Additional Write lockable page support JIRA: https://issues.redhat.com/browse/RHEL-47160 Conflicts: * Avoiding commit ("misc: Switch i2c drivers back to use .probe()") to avoid drop the .probe_new() call-back type commit 3774740fb22162d2c50e79629c4b3e11022ed7d9 Author: Alexander Stein Date: Fri Oct 13 08:30:08 2023 +0200 eeprom: at24: add ST M24C64-D Additional Write lockable page support The ST M24C64-D behaves as a regular M24C64, except for the -D variant which uses up another I2C address for Additional Write lockable page. This page is 32 Bytes long and can contain additional data. Add entry for it, so users can describe that page in DT. Note that users still have to describe the main M24C64 area separately as that is on separate I2C address from this page. Signed-off-by: Alexander Stein Reviewed-by: Marek Vasut Signed-off-by: Bartosz Golaszewski Signed-off-by: Alessandro Carminati --- drivers/misc/eeprom/at24.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 54a2dead0b44..2a974fe0dd48 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -196,6 +196,8 @@ AT24_CHIP_DATA(at24_data_24c32d_wlp, 32, AT24_FLAG_ADDR16); AT24_CHIP_DATA(at24_data_24cs32, 16, AT24_FLAG_ADDR16 | AT24_FLAG_SERIAL | AT24_FLAG_READONLY); AT24_CHIP_DATA(at24_data_24c64, 65536 / 8, AT24_FLAG_ADDR16); +/* M24C64-D Additional Write lockable page (M24C64-D order codes) */ +AT24_CHIP_DATA(at24_data_24c64d_wlp, 32, AT24_FLAG_ADDR16); AT24_CHIP_DATA(at24_data_24cs64, 16, AT24_FLAG_ADDR16 | AT24_FLAG_SERIAL | AT24_FLAG_READONLY); AT24_CHIP_DATA(at24_data_24c128, 131072 / 8, AT24_FLAG_ADDR16); @@ -227,6 +229,7 @@ static const struct i2c_device_id at24_ids[] = { { "24c32d-wl", (kernel_ulong_t)&at24_data_24c32d_wlp }, { "24cs32", (kernel_ulong_t)&at24_data_24cs32 }, { "24c64", (kernel_ulong_t)&at24_data_24c64 }, + { "24c64-wl", (kernel_ulong_t)&at24_data_24c64d_wlp }, { "24cs64", (kernel_ulong_t)&at24_data_24cs64 }, { "24c128", (kernel_ulong_t)&at24_data_24c128 }, { "24c256", (kernel_ulong_t)&at24_data_24c256 }, @@ -258,6 +261,7 @@ static const struct of_device_id at24_of_match[] = { { .compatible = "atmel,24c32d-wl", .data = &at24_data_24c32d_wlp }, { .compatible = "atmel,24cs32", .data = &at24_data_24cs32 }, { .compatible = "atmel,24c64", .data = &at24_data_24c64 }, + { .compatible = "atmel,24c64d-wl", .data = &at24_data_24c64d_wlp }, { .compatible = "atmel,24cs64", .data = &at24_data_24cs64 }, { .compatible = "atmel,24c128", .data = &at24_data_24c128 }, { .compatible = "atmel,24c256", .data = &at24_data_24c256 }, From 109552b6f37122fb4e0457637decfd7e46defbf9 Mon Sep 17 00:00:00 2001 From: Alessandro Carminati Date: Fri, 26 Jul 2024 14:18:03 +0200 Subject: [PATCH 5/6] eeprom: at24: Use pm_runtime_resume_and_get to simplify the code JIRA: https://issues.redhat.com/browse/RHEL-47160 Conflicts: * Avoiding commit ("misc: Switch i2c drivers back to use .probe()") to avoid drop the .probe_new() call-back type commit e68f487133d515234bdf00b85fedd0fe6216349e Author: Heiner Kallweit Date: Wed Dec 20 16:11:14 2023 +0100 eeprom: at24: Use pm_runtime_resume_and_get to simplify the code Use helper pm_runtime_resume_and_get() to simplify the code. Signed-off-by: Heiner Kallweit Link: https://lore.kernel.org/r/c3045427-da42-4f7c-8a96-3c4756646cd0@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Alessandro Carminati --- drivers/misc/eeprom/at24.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 2a974fe0dd48..cc879a4c92a3 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -439,12 +439,9 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count) if (off + count > at24->byte_len) return -EINVAL; - ret = pm_runtime_get_sync(dev); - if (ret < 0) { - pm_runtime_put_noidle(dev); + ret = pm_runtime_resume_and_get(dev); + if (ret) return ret; - } - /* * Read data from chip, protecting against concurrent updates * from this host, but not from other I2C masters. @@ -486,12 +483,9 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count) if (off + count > at24->byte_len) return -EINVAL; - ret = pm_runtime_get_sync(dev); - if (ret < 0) { - pm_runtime_put_noidle(dev); + ret = pm_runtime_resume_and_get(dev); + if (ret) return ret; - } - /* * Write data to chip, protecting against concurrent updates * from this host, but not from other I2C masters. From b9265480f8a1873cc4a43538e37bf25f99856ce4 Mon Sep 17 00:00:00 2001 From: Alessandro Carminati Date: Fri, 26 Jul 2024 14:18:07 +0200 Subject: [PATCH 6/6] eeprom: at24: use of_match_ptr() JIRA: https://issues.redhat.com/browse/RHEL-47160 Conflicts: * Avoiding commit ("misc: Switch i2c drivers back to use .probe()") to avoid drop the .probe_new() call-back type * Small context adjustments due to f050bb8f56c64 commit 2b0eee4f6add17a74f696a6f40ad2a4fa173613e Author: Bartosz Golaszewski Date: Thu Nov 23 11:30:32 2023 +0100 eeprom: at24: use of_match_ptr() This driver does not depend on CONFIG_OF so using of_match_ptr() makes sense to reduce the size a bit. Signed-off-by: Bartosz Golaszewski Signed-off-by: Alessandro Carminati --- drivers/misc/eeprom/at24.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index cc879a4c92a3..74b042a8810b 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -242,7 +243,7 @@ static const struct i2c_device_id at24_ids[] = { }; MODULE_DEVICE_TABLE(i2c, at24_ids); -static const struct of_device_id at24_of_match[] = { +static const struct of_device_id __maybe_unused at24_of_match[] = { { .compatible = "atmel,24c00", .data = &at24_data_24c00 }, { .compatible = "atmel,24c01", .data = &at24_data_24c01 }, { .compatible = "atmel,24cs01", .data = &at24_data_24cs01 }, @@ -837,7 +838,7 @@ static struct i2c_driver at24_driver = { .driver = { .name = "at24", .pm = &at24_pm_ops, - .of_match_table = at24_of_match, + .of_match_table = of_match_ptr(at24_of_match), .acpi_match_table = ACPI_PTR(at24_acpi_ids), }, .probe_new = at24_probe,