* [PATCH v1 00/10] misc: at25: Code cleanups and improvements
@ 2021-11-25 21:31 Andy Shevchenko
2021-11-25 21:31 ` [PATCH v1 01/10] misc: at25: Use at25->chip instead of local chip everywhere in ->probe() Andy Shevchenko
` (11 more replies)
0 siblings, 12 replies; 15+ messages in thread
From: Andy Shevchenko @ 2021-11-25 21:31 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel
Cc: Arnd Bergmann, Greg Kroah-Hartman, Jiri Prchal
Code cleanups and improvements. Please read individual commit messages.
Series depends on the fixes series [1] sent earlier.
[1]: https://lore.kernel.org/lkml/20211125212729.86585-2-andriy.shevchenko@linux.intel.com/T/#u
Andy Shevchenko (10):
misc: at25: Use at25->chip instead of local chip everywhere in
->probe()
misc: at25: Unshadow error codes in at25_fw_to_chip()
misc: at25: Check new property ("address-width") first
misc: at25: Get platform data via dev_get_platdata()
misc: at25: Get rid of intermediate storage for AT25 chip data
misc: at25: Switch to use BIT() instead of custom approaches
misc: at25: Factor out at_fram_to_chip()
misc: at25: Reorganize headers for better maintenance
misc: at25: Replace commas by spaces in the ID tables
misc: at25: Align comment style
drivers/misc/eeprom/at25.c | 210 +++++++++++++++++++------------------
1 file changed, 110 insertions(+), 100 deletions(-)
--
2.33.0
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v1 01/10] misc: at25: Use at25->chip instead of local chip everywhere in ->probe()
2021-11-25 21:31 [PATCH v1 00/10] misc: at25: Code cleanups and improvements Andy Shevchenko
@ 2021-11-25 21:31 ` Andy Shevchenko
2021-11-25 21:31 ` [PATCH v1 02/10] misc: at25: Unshadow error codes in at25_fw_to_chip() Andy Shevchenko
` (10 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2021-11-25 21:31 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel
Cc: Arnd Bergmann, Greg Kroah-Hartman, Jiri Prchal
Currently some values are compared against the contents of the chip structure
and most are from its updated copy in at25->chip. Use the latter one everywhere
in ->probe().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/misc/eeprom/at25.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index e21216541b0f..6bea9c7c64a0 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -434,8 +434,8 @@ static int at25_probe(struct spi_device *spi)
return -ENODEV;
}
- chip.byte_len = int_pow(2, id[7] - 0x21 + 4) * 1024;
- if (chip.byte_len > 64 * 1024)
+ at25->chip.byte_len = int_pow(2, id[7] - 0x21 + 4) * 1024;
+ if (at25->chip.byte_len > 64 * 1024)
at25->chip.flags |= EE_ADDR3;
else
at25->chip.flags |= EE_ADDR2;
@@ -466,7 +466,7 @@ static int at25_probe(struct spi_device *spi)
at25->nvmem_config.type = is_fram ? NVMEM_TYPE_FRAM : NVMEM_TYPE_EEPROM;
at25->nvmem_config.name = dev_name(&spi->dev);
at25->nvmem_config.dev = &spi->dev;
- at25->nvmem_config.read_only = chip.flags & EE_READONLY;
+ at25->nvmem_config.read_only = at25->chip.flags & EE_READONLY;
at25->nvmem_config.root_only = true;
at25->nvmem_config.owner = THIS_MODULE;
at25->nvmem_config.compat = true;
@@ -476,17 +476,17 @@ static int at25_probe(struct spi_device *spi)
at25->nvmem_config.priv = at25;
at25->nvmem_config.stride = 1;
at25->nvmem_config.word_size = 1;
- at25->nvmem_config.size = chip.byte_len;
+ at25->nvmem_config.size = at25->chip.byte_len;
at25->nvmem = devm_nvmem_register(&spi->dev, &at25->nvmem_config);
if (IS_ERR(at25->nvmem))
return PTR_ERR(at25->nvmem);
dev_info(&spi->dev, "%d %s %s %s%s, pagesize %u\n",
- (chip.byte_len < 1024) ? chip.byte_len : (chip.byte_len / 1024),
- (chip.byte_len < 1024) ? "Byte" : "KByte",
+ (at25->chip.byte_len < 1024) ? at25->chip.byte_len : (at25->chip.byte_len / 1024),
+ (at25->chip.byte_len < 1024) ? "Byte" : "KByte",
at25->chip.name, is_fram ? "fram" : "eeprom",
- (chip.flags & EE_READONLY) ? " (readonly)" : "",
+ (at25->chip.flags & EE_READONLY) ? " (readonly)" : "",
at25->chip.page_size);
return 0;
}
--
2.33.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v1 02/10] misc: at25: Unshadow error codes in at25_fw_to_chip()
2021-11-25 21:31 [PATCH v1 00/10] misc: at25: Code cleanups and improvements Andy Shevchenko
2021-11-25 21:31 ` [PATCH v1 01/10] misc: at25: Use at25->chip instead of local chip everywhere in ->probe() Andy Shevchenko
@ 2021-11-25 21:31 ` Andy Shevchenko
2021-11-25 21:31 ` [PATCH v1 03/10] misc: at25: Check new property ("address-width") first Andy Shevchenko
` (9 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2021-11-25 21:31 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel
Cc: Arnd Bergmann, Greg Kroah-Hartman, Jiri Prchal
device_property_read_u32() may return different error codes.
Unshadow them in the at25_fw_to_chip() to give better error
report.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/misc/eeprom/at25.c | 40 +++++++++++++++++++++-----------------
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index 6bea9c7c64a0..027840c73fc8 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -304,33 +304,35 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count)
static int at25_fw_to_chip(struct device *dev, struct spi_eeprom *chip)
{
u32 val;
+ int err;
memset(chip, 0, sizeof(*chip));
strncpy(chip->name, "at25", sizeof(chip->name));
- if (device_property_read_u32(dev, "size", &val) == 0 ||
- device_property_read_u32(dev, "at25,byte-len", &val) == 0) {
- chip->byte_len = val;
- } else {
+ err = device_property_read_u32(dev, "size", &val);
+ if (err)
+ err = device_property_read_u32(dev, "at25,byte-len", &val);
+ if (err) {
dev_err(dev, "Error: missing \"size\" property\n");
- return -ENODEV;
+ return err;
}
+ chip->byte_len = val;
- if (device_property_read_u32(dev, "pagesize", &val) == 0 ||
- device_property_read_u32(dev, "at25,page-size", &val) == 0) {
- chip->page_size = val;
- } else {
+ err = device_property_read_u32(dev, "pagesize", &val);
+ if (err)
+ err = device_property_read_u32(dev, "at25,page-size", &val);
+ if (err) {
dev_err(dev, "Error: missing \"pagesize\" property\n");
- return -ENODEV;
+ return err;
}
-
- if (device_property_read_u32(dev, "at25,addr-mode", &val) == 0) {
- chip->flags = (u16)val;
- } else {
- if (device_property_read_u32(dev, "address-width", &val)) {
- dev_err(dev,
- "Error: missing \"address-width\" property\n");
- return -ENODEV;
+ chip->page_size = val;
+
+ err = device_property_read_u32(dev, "at25,addr-mode", &val);
+ if (err) {
+ err = device_property_read_u32(dev, "address-width", &val);
+ if (err) {
+ dev_err(dev, "Error: missing \"address-width\" property\n");
+ return err;
}
switch (val) {
case 9:
@@ -353,6 +355,8 @@ static int at25_fw_to_chip(struct device *dev, struct spi_eeprom *chip)
}
if (device_property_present(dev, "read-only"))
chip->flags |= EE_READONLY;
+ } else {
+ chip->flags = (u16)val;
}
return 0;
}
--
2.33.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v1 03/10] misc: at25: Check new property ("address-width") first
2021-11-25 21:31 [PATCH v1 00/10] misc: at25: Code cleanups and improvements Andy Shevchenko
2021-11-25 21:31 ` [PATCH v1 01/10] misc: at25: Use at25->chip instead of local chip everywhere in ->probe() Andy Shevchenko
2021-11-25 21:31 ` [PATCH v1 02/10] misc: at25: Unshadow error codes in at25_fw_to_chip() Andy Shevchenko
@ 2021-11-25 21:31 ` Andy Shevchenko
2021-11-25 21:31 ` [PATCH v1 04/10] misc: at25: Get platform data via dev_get_platdata() Andy Shevchenko
` (8 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2021-11-25 21:31 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel
Cc: Arnd Bergmann, Greg Kroah-Hartman, Jiri Prchal
As it's done elsewhere in at25_fw_to_chip() check new property
("address-width") first.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/misc/eeprom/at25.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index 027840c73fc8..86f5433d0278 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -327,13 +327,15 @@ static int at25_fw_to_chip(struct device *dev, struct spi_eeprom *chip)
}
chip->page_size = val;
- err = device_property_read_u32(dev, "at25,addr-mode", &val);
+ err = device_property_read_u32(dev, "address-width", &val);
if (err) {
- err = device_property_read_u32(dev, "address-width", &val);
+ err = device_property_read_u32(dev, "at25,addr-mode", &val);
if (err) {
dev_err(dev, "Error: missing \"address-width\" property\n");
return err;
}
+ chip->flags = (u16)val;
+ } else {
switch (val) {
case 9:
chip->flags |= EE_INSTR_BIT3_IS_ADDR;
@@ -355,8 +357,6 @@ static int at25_fw_to_chip(struct device *dev, struct spi_eeprom *chip)
}
if (device_property_present(dev, "read-only"))
chip->flags |= EE_READONLY;
- } else {
- chip->flags = (u16)val;
}
return 0;
}
--
2.33.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v1 04/10] misc: at25: Get platform data via dev_get_platdata()
2021-11-25 21:31 [PATCH v1 00/10] misc: at25: Code cleanups and improvements Andy Shevchenko
` (2 preceding siblings ...)
2021-11-25 21:31 ` [PATCH v1 03/10] misc: at25: Check new property ("address-width") first Andy Shevchenko
@ 2021-11-25 21:31 ` Andy Shevchenko
2021-11-25 21:31 ` [PATCH v1 05/10] misc: at25: Get rid of intermediate storage for AT25 chip data Andy Shevchenko
` (7 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2021-11-25 21:31 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel
Cc: Arnd Bergmann, Greg Kroah-Hartman, Jiri Prchal
Access to platform data via dev_get_platdata() getter to make code cleaner.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/misc/eeprom/at25.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index 86f5433d0278..b235f20c56da 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -378,7 +378,7 @@ MODULE_DEVICE_TABLE(spi, at25_spi_ids);
static int at25_probe(struct spi_device *spi)
{
struct at25_data *at25 = NULL;
- struct spi_eeprom chip;
+ struct spi_eeprom chip, *pdata;
int err;
int sr;
u8 id[FM25_ID_LEN];
@@ -393,7 +393,8 @@ static int at25_probe(struct spi_device *spi)
is_fram = false;
/* Chip description */
- if (!spi->dev.platform_data) {
+ pdata = dev_get_platdata(&spi->dev);
+ if (!pdata) {
if (is_fram) {
/* We file fields for FRAM case later on */
memset(&chip, 0, sizeof(chip));
@@ -403,7 +404,7 @@ static int at25_probe(struct spi_device *spi)
return err;
}
} else
- chip = *(struct spi_eeprom *)spi->dev.platform_data;
+ chip = *pdata;
/* Ping the chip ... the status register is pretty portable,
* unlike probing manufacturer IDs. We do expect that system
--
2.33.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v1 05/10] misc: at25: Get rid of intermediate storage for AT25 chip data
2021-11-25 21:31 [PATCH v1 00/10] misc: at25: Code cleanups and improvements Andy Shevchenko
` (3 preceding siblings ...)
2021-11-25 21:31 ` [PATCH v1 04/10] misc: at25: Get platform data via dev_get_platdata() Andy Shevchenko
@ 2021-11-25 21:31 ` Andy Shevchenko
2021-11-25 21:31 ` [PATCH v1 06/10] misc: at25: Switch to use BIT() instead of custom approaches Andy Shevchenko
` (6 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2021-11-25 21:31 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel
Cc: Arnd Bergmann, Greg Kroah-Hartman, Jiri Prchal
There is no need to copy twice the same data. Drop needless local
variable.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/misc/eeprom/at25.c | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index b235f20c56da..70cab386040a 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -306,7 +306,6 @@ static int at25_fw_to_chip(struct device *dev, struct spi_eeprom *chip)
u32 val;
int err;
- memset(chip, 0, sizeof(*chip));
strncpy(chip->name, "at25", sizeof(chip->name));
err = device_property_read_u32(dev, "size", &val);
@@ -378,9 +377,9 @@ MODULE_DEVICE_TABLE(spi, at25_spi_ids);
static int at25_probe(struct spi_device *spi)
{
struct at25_data *at25 = NULL;
- struct spi_eeprom chip, *pdata;
int err;
int sr;
+ struct spi_eeprom *pdata;
u8 id[FM25_ID_LEN];
u8 sernum[FM25_SN_LEN];
bool is_fram;
@@ -392,20 +391,6 @@ static int at25_probe(struct spi_device *spi)
else
is_fram = false;
- /* Chip description */
- pdata = dev_get_platdata(&spi->dev);
- if (!pdata) {
- if (is_fram) {
- /* We file fields for FRAM case later on */
- memset(&chip, 0, sizeof(chip));
- } else {
- err = at25_fw_to_chip(&spi->dev, &chip);
- if (err)
- return err;
- }
- } else
- chip = *pdata;
-
/* Ping the chip ... the status register is pretty portable,
* unlike probing manufacturer IDs. We do expect that system
* firmware didn't write it in the past few milliseconds!
@@ -421,10 +406,23 @@ static int at25_probe(struct spi_device *spi)
return -ENOMEM;
mutex_init(&at25->lock);
- at25->chip = chip;
at25->spi = spi;
spi_set_drvdata(spi, at25);
+ /* Chip description */
+ pdata = dev_get_platdata(&spi->dev);
+ if (pdata) {
+ at25->chip = *pdata;
+ } else {
+ if (is_fram) {
+ /* We file fields for FRAM case later on */
+ } else {
+ err = at25_fw_to_chip(&spi->dev, &at25->chip);
+ if (err)
+ return err;
+ }
+ }
+
if (is_fram) {
/* Get ID of chip */
fm25_aux_read(at25, id, FM25_RDID, FM25_ID_LEN);
--
2.33.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v1 06/10] misc: at25: Switch to use BIT() instead of custom approaches
2021-11-25 21:31 [PATCH v1 00/10] misc: at25: Code cleanups and improvements Andy Shevchenko
` (4 preceding siblings ...)
2021-11-25 21:31 ` [PATCH v1 05/10] misc: at25: Get rid of intermediate storage for AT25 chip data Andy Shevchenko
@ 2021-11-25 21:31 ` Andy Shevchenko
2021-11-25 21:32 ` [PATCH v1 07/10] misc: at25: Factor out at_fram_to_chip() Andy Shevchenko
` (5 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2021-11-25 21:31 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel
Cc: Arnd Bergmann, Greg Kroah-Hartman, Jiri Prchal
It's obvious that custom approach of getting power of 2 number with
int_pow() kinda interesting. Replace it and some others approaches
by using a simple BIT() operation.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/misc/eeprom/at25.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index 70cab386040a..c9660a4625ce 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -6,6 +6,7 @@
* Copyright (C) 2006 David Brownell
*/
+#include <linux/bits.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
@@ -17,7 +18,6 @@
#include <linux/spi/spi.h>
#include <linux/spi/eeprom.h>
#include <linux/property.h>
-#include <linux/math.h>
/*
* NOTE: this is an *EEPROM* driver. The vagaries of product naming
@@ -94,7 +94,7 @@ static int at25_ee_read(void *priv, unsigned int offset,
instr = AT25_READ;
if (at25->chip.flags & EE_INSTR_BIT3_IS_ADDR)
- if (offset >= (1U << (at25->addrlen * 8)))
+ if (offset >= BIT(at25->addrlen * 8))
instr |= AT25_INSTR_BIT3;
*cp++ = instr;
@@ -227,7 +227,7 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count)
instr = AT25_WRITE;
if (at25->chip.flags & EE_INSTR_BIT3_IS_ADDR)
- if (offset >= (1U << (at25->addrlen * 8)))
+ if (offset >= BIT(at25->addrlen * 8))
instr |= AT25_INSTR_BIT3;
*cp++ = instr;
@@ -437,7 +437,7 @@ static int at25_probe(struct spi_device *spi)
return -ENODEV;
}
- at25->chip.byte_len = int_pow(2, id[7] - 0x21 + 4) * 1024;
+ at25->chip.byte_len = BIT(id[7] - 0x21 + 4) * 1024;
if (at25->chip.byte_len > 64 * 1024)
at25->chip.flags |= EE_ADDR3;
else
--
2.33.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v1 07/10] misc: at25: Factor out at_fram_to_chip()
2021-11-25 21:31 [PATCH v1 00/10] misc: at25: Code cleanups and improvements Andy Shevchenko
` (5 preceding siblings ...)
2021-11-25 21:31 ` [PATCH v1 06/10] misc: at25: Switch to use BIT() instead of custom approaches Andy Shevchenko
@ 2021-11-25 21:32 ` Andy Shevchenko
2021-11-25 21:32 ` [PATCH v1 08/10] misc: at25: Reorganize headers for better maintenance Andy Shevchenko
` (4 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2021-11-25 21:32 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel
Cc: Arnd Bergmann, Greg Kroah-Hartman, Jiri Prchal
In the similar way as it's done for EEPROM, factor out
a new helper function for FRAM.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/misc/eeprom/at25.c | 85 ++++++++++++++++++++------------------
1 file changed, 44 insertions(+), 41 deletions(-)
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index c9660a4625ce..b9d26c9ee768 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -31,9 +31,9 @@
#define FM25_SN_LEN 8 /* serial number length */
struct at25_data {
+ struct spi_eeprom chip;
struct spi_device *spi;
struct mutex lock;
- struct spi_eeprom chip;
unsigned addrlen;
struct nvmem_config nvmem_config;
struct nvmem_device *nvmem;
@@ -360,6 +360,44 @@ static int at25_fw_to_chip(struct device *dev, struct spi_eeprom *chip)
return 0;
}
+static int at25_fram_to_chip(struct device *dev, struct spi_eeprom *chip)
+{
+ struct at25_data *at25 = container_of(chip, struct at25_data, chip);
+ u8 sernum[FM25_SN_LEN];
+ u8 id[FM25_ID_LEN];
+ int i;
+
+ strncpy(chip->name, "fm25", sizeof(chip->name));
+
+ /* Get ID of chip */
+ fm25_aux_read(at25, id, FM25_RDID, FM25_ID_LEN);
+ if (id[6] != 0xc2) {
+ dev_err(dev, "Error: no Cypress FRAM (id %02x)\n", id[6]);
+ return -ENODEV;
+ }
+ /* Set size found in ID */
+ if (id[7] < 0x21 || id[7] > 0x26) {
+ dev_err(dev, "Error: unsupported size (id %02x)\n", id[7]);
+ return -ENODEV;
+ }
+
+ chip->byte_len = BIT(id[7] - 0x21 + 4) * 1024;
+ if (chip->byte_len > 64 * 1024)
+ chip->flags |= EE_ADDR3;
+ else
+ chip->flags |= EE_ADDR2;
+
+ if (id[8]) {
+ fm25_aux_read(at25, sernum, FM25_RDSN, FM25_SN_LEN);
+ /* Swap byte order */
+ for (i = 0; i < FM25_SN_LEN; i++)
+ at25->sernum[i] = sernum[FM25_SN_LEN - 1 - i];
+ }
+
+ chip->page_size = PAGE_SIZE;
+ return 0;
+}
+
static const struct of_device_id at25_of_match[] = {
{ .compatible = "atmel,at25",},
{ .compatible = "cypress,fm25",},
@@ -380,10 +418,7 @@ static int at25_probe(struct spi_device *spi)
int err;
int sr;
struct spi_eeprom *pdata;
- u8 id[FM25_ID_LEN];
- u8 sernum[FM25_SN_LEN];
bool is_fram;
- int i;
err = device_property_match_string(&spi->dev, "compatible", "cypress,fm25");
if (err >= 0)
@@ -414,44 +449,12 @@ static int at25_probe(struct spi_device *spi)
if (pdata) {
at25->chip = *pdata;
} else {
- if (is_fram) {
- /* We file fields for FRAM case later on */
- } else {
- err = at25_fw_to_chip(&spi->dev, &at25->chip);
- if (err)
- return err;
- }
- }
-
- if (is_fram) {
- /* Get ID of chip */
- fm25_aux_read(at25, id, FM25_RDID, FM25_ID_LEN);
- if (id[6] != 0xc2) {
- dev_err(&spi->dev,
- "Error: no Cypress FRAM (id %02x)\n", id[6]);
- return -ENODEV;
- }
- /* set size found in ID */
- if (id[7] < 0x21 || id[7] > 0x26) {
- dev_err(&spi->dev, "Error: unsupported size (id %02x)\n", id[7]);
- return -ENODEV;
- }
-
- at25->chip.byte_len = BIT(id[7] - 0x21 + 4) * 1024;
- if (at25->chip.byte_len > 64 * 1024)
- at25->chip.flags |= EE_ADDR3;
+ if (is_fram)
+ err = at25_fram_to_chip(&spi->dev, &at25->chip);
else
- at25->chip.flags |= EE_ADDR2;
-
- if (id[8]) {
- fm25_aux_read(at25, sernum, FM25_RDSN, FM25_SN_LEN);
- /* swap byte order */
- for (i = 0; i < FM25_SN_LEN; i++)
- at25->sernum[i] = sernum[FM25_SN_LEN - 1 - i];
- }
-
- at25->chip.page_size = PAGE_SIZE;
- strncpy(at25->chip.name, "fm25", sizeof(at25->chip.name));
+ err = at25_fw_to_chip(&spi->dev, &at25->chip);
+ if (err)
+ return err;
}
/* For now we only support 8/16/24 bit addressing */
--
2.33.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v1 08/10] misc: at25: Reorganize headers for better maintenance
2021-11-25 21:31 [PATCH v1 00/10] misc: at25: Code cleanups and improvements Andy Shevchenko
` (6 preceding siblings ...)
2021-11-25 21:32 ` [PATCH v1 07/10] misc: at25: Factor out at_fram_to_chip() Andy Shevchenko
@ 2021-11-25 21:32 ` Andy Shevchenko
2021-11-25 21:32 ` [PATCH v1 09/10] misc: at25: Replace commas by spaces in the ID tables Andy Shevchenko
` (3 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2021-11-25 21:32 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel
Cc: Arnd Bergmann, Greg Kroah-Hartman, Jiri Prchal
Split headers to three groups and sort alphabetically in each of them.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/misc/eeprom/at25.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index b9d26c9ee768..3e60124d14a3 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -7,17 +7,18 @@
*/
#include <linux/bits.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/property.h>
#include <linux/sched.h>
+#include <linux/slab.h>
-#include <linux/nvmem-provider.h>
-#include <linux/spi/spi.h>
#include <linux/spi/eeprom.h>
-#include <linux/property.h>
+#include <linux/spi/spi.h>
+
+#include <linux/nvmem-provider.h>
/*
* NOTE: this is an *EEPROM* driver. The vagaries of product naming
--
2.33.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v1 09/10] misc: at25: Replace commas by spaces in the ID tables
2021-11-25 21:31 [PATCH v1 00/10] misc: at25: Code cleanups and improvements Andy Shevchenko
` (7 preceding siblings ...)
2021-11-25 21:32 ` [PATCH v1 08/10] misc: at25: Reorganize headers for better maintenance Andy Shevchenko
@ 2021-11-25 21:32 ` Andy Shevchenko
2021-11-25 21:32 ` [PATCH v1 10/10] misc: at25: Align comment style Andy Shevchenko
` (2 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2021-11-25 21:32 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel
Cc: Arnd Bergmann, Greg Kroah-Hartman, Jiri Prchal
For better readability replace commas by spaces in the ID tables.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/misc/eeprom/at25.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index 3e60124d14a3..9264bb17963e 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -400,15 +400,15 @@ static int at25_fram_to_chip(struct device *dev, struct spi_eeprom *chip)
}
static const struct of_device_id at25_of_match[] = {
- { .compatible = "atmel,at25",},
- { .compatible = "cypress,fm25",},
+ { .compatible = "atmel,at25" },
+ { .compatible = "cypress,fm25" },
{ }
};
MODULE_DEVICE_TABLE(of, at25_of_match);
static const struct spi_device_id at25_spi_ids[] = {
- { .name = "at25",},
- { .name = "fm25",},
+ { .name = "at25" },
+ { .name = "fm25" },
{ }
};
MODULE_DEVICE_TABLE(spi, at25_spi_ids);
--
2.33.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v1 10/10] misc: at25: Align comment style
2021-11-25 21:31 [PATCH v1 00/10] misc: at25: Code cleanups and improvements Andy Shevchenko
` (8 preceding siblings ...)
2021-11-25 21:32 ` [PATCH v1 09/10] misc: at25: Replace commas by spaces in the ID tables Andy Shevchenko
@ 2021-11-25 21:32 ` Andy Shevchenko
2021-11-25 22:03 ` [PATCH v1 00/10] misc: at25: Code cleanups and improvements Arnd Bergmann
2021-12-01 14:19 ` Andy Shevchenko
11 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2021-11-25 21:32 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel
Cc: Arnd Bergmann, Greg Kroah-Hartman, Jiri Prchal
Make multi-line comment style aligned.
While at it, drop filename from the file.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/misc/eeprom/at25.c | 37 ++++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 17 deletions(-)
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index 9264bb17963e..f16f67baf3d2 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * at25.c -- support most SPI EEPROMs, such as Atmel AT25 models
- * and Cypress FRAMs FM25 models
+ * Driver for most of the SPI EEPROMs, such as Atmel AT25 models
+ * and Cypress FRAMs FM25 models.
*
* Copyright (C) 2006 David Brownell
*/
@@ -21,7 +21,7 @@
#include <linux/nvmem-provider.h>
/*
- * NOTE: this is an *EEPROM* driver. The vagaries of product naming
+ * NOTE: this is an *EEPROM* driver. The vagaries of product naming
* mean that some AT25 products are EEPROMs, and others are FLASH.
* Handle FLASH chips with the drivers/mtd/devices/m25p80.c driver,
* not this one!
@@ -57,13 +57,14 @@ struct at25_data {
#define AT25_SR_BP1 0x08
#define AT25_SR_WPEN 0x80 /* writeprotect enable */
-#define AT25_INSTR_BIT3 0x08 /* Additional address bit in instr */
+#define AT25_INSTR_BIT3 0x08 /* additional address bit in instr */
#define FM25_ID_LEN 9 /* ID length */
#define EE_MAXADDRLEN 3 /* 24 bit addresses, up to 2 MBytes */
-/* Specs often allow 5 msec for a page write, sometimes 20 msec;
+/*
+ * Specs often allow 5ms for a page write, sometimes 20ms;
* it's important to recover from write timeouts.
*/
#define EE_TIMEOUT 25
@@ -108,7 +109,7 @@ static int at25_ee_read(void *priv, unsigned int offset,
*cp++ = offset >> 8;
fallthrough;
case 1:
- case 0: /* can't happen: for better codegen */
+ case 0: /* can't happen: for better code generation */
*cp++ = offset >> 0;
}
@@ -125,11 +126,12 @@ static int at25_ee_read(void *priv, unsigned int offset,
mutex_lock(&at25->lock);
- /* Read it all at once.
+ /*
+ * Read it all at once.
*
* REVISIT that's potentially a problem with large chips, if
* other devices on the bus need to be accessed regularly or
- * this chip is clocked very slowly
+ * this chip is clocked very slowly.
*/
status = spi_sync(at25->spi, &m);
dev_dbg(&at25->spi->dev, "read %zu bytes at %d --> %zd\n",
@@ -139,9 +141,7 @@ static int at25_ee_read(void *priv, unsigned int offset,
return status;
}
-/*
- * read extra registers as ID or serial number
- */
+/* Read extra registers as ID or serial number */
static int fm25_aux_read(struct at25_data *at25, u8 *buf, uint8_t command,
int len)
{
@@ -207,7 +207,8 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count)
if (!bounce)
return -ENOMEM;
- /* For write, rollover is within the page ... so we write at
+ /*
+ * For write, rollover is within the page ... so we write at
* most one page, then manually roll over to the next page.
*/
mutex_lock(&at25->lock);
@@ -241,7 +242,7 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count)
*cp++ = offset >> 8;
fallthrough;
case 1:
- case 0: /* can't happen: for better codegen */
+ case 0: /* can't happen: for better code generation */
*cp++ = offset >> 0;
}
@@ -257,8 +258,9 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count)
if (status < 0)
break;
- /* REVISIT this should detect (or prevent) failed writes
- * to readonly sections of the EEPROM...
+ /*
+ * REVISIT this should detect (or prevent) failed writes
+ * to read-only sections of the EEPROM...
*/
/* Wait for non-busy status */
@@ -427,8 +429,9 @@ static int at25_probe(struct spi_device *spi)
else
is_fram = false;
- /* Ping the chip ... the status register is pretty portable,
- * unlike probing manufacturer IDs. We do expect that system
+ /*
+ * Ping the chip ... the status register is pretty portable,
+ * unlike probing manufacturer IDs. We do expect that system
* firmware didn't write it in the past few milliseconds!
*/
sr = spi_w8r8(spi, AT25_RDSR);
--
2.33.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v1 00/10] misc: at25: Code cleanups and improvements
2021-11-25 21:31 [PATCH v1 00/10] misc: at25: Code cleanups and improvements Andy Shevchenko
` (9 preceding siblings ...)
2021-11-25 21:32 ` [PATCH v1 10/10] misc: at25: Align comment style Andy Shevchenko
@ 2021-11-25 22:03 ` Arnd Bergmann
2021-11-26 9:52 ` Andy Shevchenko
2021-12-01 14:19 ` Andy Shevchenko
11 siblings, 1 reply; 15+ messages in thread
From: Arnd Bergmann @ 2021-11-25 22:03 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Linux Kernel Mailing List, Arnd Bergmann, Greg Kroah-Hartman,
Jiri Prchal
On Thu, Nov 25, 2021 at 10:31 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Code cleanups and improvements. Please read individual commit messages.
>
> Series depends on the fixes series [1] sent earlier.
>
> [1]: https://lore.kernel.org/lkml/20211125212729.86585-2-andriy.shevchenko@linux.intel.com/T/#u
>
> Andy Shevchenko (10):
> misc: at25: Use at25->chip instead of local chip everywhere in
> ->probe()
> misc: at25: Unshadow error codes in at25_fw_to_chip()
> misc: at25: Check new property ("address-width") first
> misc: at25: Get platform data via dev_get_platdata()
> misc: at25: Get rid of intermediate storage for AT25 chip data
> misc: at25: Switch to use BIT() instead of custom approaches
> misc: at25: Factor out at_fram_to_chip()
> misc: at25: Reorganize headers for better maintenance
> misc: at25: Replace commas by spaces in the ID tables
> misc: at25: Align comment style
These also look good to me,
Acked-by: Arnd Bergmann <arnd@arndb.de>
It would be nice to change the three remaining board files that fill
struct spi_eeprom so they use device properties and unify the
rest of the probe path. Not sure how much of a change that would
be.
Arnd
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v1 00/10] misc: at25: Code cleanups and improvements
2021-11-25 22:03 ` [PATCH v1 00/10] misc: at25: Code cleanups and improvements Arnd Bergmann
@ 2021-11-26 9:52 ` Andy Shevchenko
2021-11-26 9:59 ` Andy Shevchenko
0 siblings, 1 reply; 15+ messages in thread
From: Andy Shevchenko @ 2021-11-26 9:52 UTC (permalink / raw)
To: Arnd Bergmann; +Cc: Linux Kernel Mailing List, Greg Kroah-Hartman, Jiri Prchal
On Thu, Nov 25, 2021 at 11:03:26PM +0100, Arnd Bergmann wrote:
> On Thu, Nov 25, 2021 at 10:31 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > Code cleanups and improvements. Please read individual commit messages.
> >
> > Series depends on the fixes series [1] sent earlier.
> >
> > [1]: https://lore.kernel.org/lkml/20211125212729.86585-2-andriy.shevchenko@linux.intel.com/T/#u
> >
> > Andy Shevchenko (10):
> > misc: at25: Use at25->chip instead of local chip everywhere in
> > ->probe()
> > misc: at25: Unshadow error codes in at25_fw_to_chip()
> > misc: at25: Check new property ("address-width") first
> > misc: at25: Get platform data via dev_get_platdata()
> > misc: at25: Get rid of intermediate storage for AT25 chip data
> > misc: at25: Switch to use BIT() instead of custom approaches
> > misc: at25: Factor out at_fram_to_chip()
> > misc: at25: Reorganize headers for better maintenance
> > misc: at25: Replace commas by spaces in the ID tables
> > misc: at25: Align comment style
>
> These also look good to me,
>
> Acked-by: Arnd Bergmann <arnd@arndb.de>
Thank you!
> It would be nice to change the three remaining board files that fill
> struct spi_eeprom so they use device properties and unify the
> rest of the probe path. Not sure how much of a change that would
> be.
Do you have a chance to test that if it appears to be the case?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v1 00/10] misc: at25: Code cleanups and improvements
2021-11-26 9:52 ` Andy Shevchenko
@ 2021-11-26 9:59 ` Andy Shevchenko
0 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2021-11-26 9:59 UTC (permalink / raw)
To: Arnd Bergmann; +Cc: Linux Kernel Mailing List, Greg Kroah-Hartman, Jiri Prchal
On Fri, Nov 26, 2021 at 11:52:49AM +0200, Andy Shevchenko wrote:
> On Thu, Nov 25, 2021 at 11:03:26PM +0100, Arnd Bergmann wrote:
> > On Thu, Nov 25, 2021 at 10:31 PM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
...
> > It would be nice to change the three remaining board files that fill
> > struct spi_eeprom so they use device properties and unify the
> > rest of the probe path. Not sure how much of a change that would
> > be.
>
> Do you have a chance to test that if it appears to be the case?
There is one more, actually: arch/mips/txx9/generic/spi_eeprom.c.
But above perhaps some OMAP people can help with... Dunno.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v1 00/10] misc: at25: Code cleanups and improvements
2021-11-25 21:31 [PATCH v1 00/10] misc: at25: Code cleanups and improvements Andy Shevchenko
` (10 preceding siblings ...)
2021-11-25 22:03 ` [PATCH v1 00/10] misc: at25: Code cleanups and improvements Arnd Bergmann
@ 2021-12-01 14:19 ` Andy Shevchenko
11 siblings, 0 replies; 15+ messages in thread
From: Andy Shevchenko @ 2021-12-01 14:19 UTC (permalink / raw)
To: linux-kernel; +Cc: Arnd Bergmann, Greg Kroah-Hartman, Jiri Prchal
On Thu, Nov 25, 2021 at 11:31:53PM +0200, Andy Shevchenko wrote:
> Code cleanups and improvements. Please read individual commit messages.
>
> Series depends on the fixes series [1] sent earlier.
Greg, it seem under your realm, can you apply this for the next cycle, please?
> [1]: https://lore.kernel.org/lkml/20211125212729.86585-2-andriy.shevchenko@linux.intel.com/T/#u
>
> Andy Shevchenko (10):
> misc: at25: Use at25->chip instead of local chip everywhere in
> ->probe()
> misc: at25: Unshadow error codes in at25_fw_to_chip()
> misc: at25: Check new property ("address-width") first
> misc: at25: Get platform data via dev_get_platdata()
> misc: at25: Get rid of intermediate storage for AT25 chip data
> misc: at25: Switch to use BIT() instead of custom approaches
> misc: at25: Factor out at_fram_to_chip()
> misc: at25: Reorganize headers for better maintenance
> misc: at25: Replace commas by spaces in the ID tables
> misc: at25: Align comment style
>
> drivers/misc/eeprom/at25.c | 210 +++++++++++++++++++------------------
> 1 file changed, 110 insertions(+), 100 deletions(-)
>
> --
> 2.33.0
>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2021-12-01 14:20 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-25 21:31 [PATCH v1 00/10] misc: at25: Code cleanups and improvements Andy Shevchenko
2021-11-25 21:31 ` [PATCH v1 01/10] misc: at25: Use at25->chip instead of local chip everywhere in ->probe() Andy Shevchenko
2021-11-25 21:31 ` [PATCH v1 02/10] misc: at25: Unshadow error codes in at25_fw_to_chip() Andy Shevchenko
2021-11-25 21:31 ` [PATCH v1 03/10] misc: at25: Check new property ("address-width") first Andy Shevchenko
2021-11-25 21:31 ` [PATCH v1 04/10] misc: at25: Get platform data via dev_get_platdata() Andy Shevchenko
2021-11-25 21:31 ` [PATCH v1 05/10] misc: at25: Get rid of intermediate storage for AT25 chip data Andy Shevchenko
2021-11-25 21:31 ` [PATCH v1 06/10] misc: at25: Switch to use BIT() instead of custom approaches Andy Shevchenko
2021-11-25 21:32 ` [PATCH v1 07/10] misc: at25: Factor out at_fram_to_chip() Andy Shevchenko
2021-11-25 21:32 ` [PATCH v1 08/10] misc: at25: Reorganize headers for better maintenance Andy Shevchenko
2021-11-25 21:32 ` [PATCH v1 09/10] misc: at25: Replace commas by spaces in the ID tables Andy Shevchenko
2021-11-25 21:32 ` [PATCH v1 10/10] misc: at25: Align comment style Andy Shevchenko
2021-11-25 22:03 ` [PATCH v1 00/10] misc: at25: Code cleanups and improvements Arnd Bergmann
2021-11-26 9:52 ` Andy Shevchenko
2021-11-26 9:59 ` Andy Shevchenko
2021-12-01 14:19 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).