add support for FRAM
Subsystems (3)
v4 cover add support for FRAM
Adds support for Cypress FRAMs.
Jiri Prchal (4):
nvmem: eeprom: at25: add support for FRAM
nvmem: eeprom: at25: add support for FRAM
nvmem: eeprom: add documentation for FRAM
nvmem: eeprom: at25: export FRAM serial num
.../devicetree/bindings/eeprom/at25.yaml | 31 ++- drivers/misc/eeprom/Kconfig | 5 +- drivers/misc/eeprom/at25.c | 177 +++++++++++++++--- drivers/nvmem/core.c | 4 + include/linux/nvmem-provider.h | 1 + 5 files changed, 180 insertions(+), 38 deletions(-)
--
v2: fixes in some files
v3: resend and added more recipients
v4: resend
---
2.25.1
PATCH v4 1/4 nvmem: eeprom: at25: add support for FRAM
Added enum and string for FRAM to expose it as "fram".
---
v2: no change here
v3: resend and added more recipients
v4: resend
--- drivers/nvmem/core.c | 4 ++++ include/linux/nvmem-provider.h | 1 + 2 files changed, 5 insertions(+)
drivers/nvmem/core.c +4 -0
@@ -180,6 +180,7 @@ static const char * const nvmem_type_str[] = { [NVMEM_TYPE_EEPROM] = "EEPROM", [NVMEM_TYPE_OTP] = "OTP", [NVMEM_TYPE_BATTERY_BACKED] = "Battery backed", + [NVMEM_TYPE_FRAM] = "FRAM", };#ifdef CONFIG_DEBUG_LOCK_ALLOC
@@ -359,6 +360,9 @@ static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem,if (!config->base_dev)return -EINVAL ; +if (config->type ==NVMEM_TYPE_FRAM ) + bin_attr_nvmem_eeprom_compat.attr.name ="fram" ; + nvmem->eeprom = bin_attr_nvmem_eeprom_compat; nvmem->eeprom.attr.mode =nvmem_bin_attr_get_umode (nvmem); nvmem->eeprom.size = nvmem->size;
include/linux/nvmem-provider.h +1 -0
@@ -25,6 +25,7 @@ enum nvmem_type {NVMEM_TYPE_EEPROM ,NVMEM_TYPE_OTP ,NVMEM_TYPE_BATTERY_BACKED , + NVMEM_TYPE_FRAM, };#define NVMEM_DEVID_NONE (-1)
--
2.25.1
Greg Kroah-Hartman
maintainerRe: [PATCH v4 1/4] nvmem: eeprom: at25: add support for FRAM
Quoted 1 line · Jiri Prchal
Added enum and string for FRAM to expose it as "fram".
documentation???
Re: [PATCH v4 1/4] nvmem: eeprom: at25: add support for FRAM
Quoted 5 lines · Greg Kroah-Hartman
Quoted 1 line · Jiri Prchal
Added enum and string for FRAM to expose it as "fram".
documentation???
Hi Greg,
please help me, you mean more explanation in commit message?
Greg Kroah-Hartman
maintainerRe: [PATCH v4 1/4] nvmem: eeprom: at25: add support for FRAM
Quoted 9 lines · Jiří Prchal
Quoted 5 lines · Greg Kroah-Hartman
Quoted 1 line · Jiri Prchal
Added enum and string for FRAM to expose it as "fram".
documentation???
Hi Greg,
please help me, you mean more explanation in commit message?
No, I mean you need to document user/kernel apis that you add in Documentation/ABI/ please.
thanks,
greg k-h
PATCH v4 2/4 nvmem: eeprom: at25: add support for FRAM
In reply to Jiri PrchalAdded support for Cypress FRAMs.
These frams have ID and some of them have serial number too. Size of them is recognized by ID. They don't have pages, it could be read or written at once, but it's limited in this driver to io limit 4096.
---
v2: fixed warning at %zd at int
v3: resend and added more recipients
v4: resend
--- drivers/misc/eeprom/Kconfig | 5 +- drivers/misc/eeprom/at25.c | 151 +++++++++++++++++++++++++++++------- 2 files changed, 124 insertions(+), 32 deletions(-)
drivers/misc/eeprom/Kconfig +3 -2
@@ -32,12 +32,13 @@ config EEPROM_AT24 will be called at24. config EEPROM_AT25 - tristate "SPI EEPROMs from most vendors" + tristate "SPI EEPROMs (FRAMs) from most vendors" depends on SPI && SYSFS select NVMEM select NVMEM_SYSFS help - Enable this driver to get read/write support to most SPI EEPROMs, + Enable this driver to get read/write support to most SPI EEPROMs + and Cypress FRAMs, after you configure the board init code to know about each eeprom on your target board.
drivers/misc/eeprom/at25.c +121 -30
229 lines not on this page · raw message
--
2.25.1
Greg Kroah-Hartman
maintainerRe: [PATCH v4 2/4] nvmem: eeprom: at25: add support for FRAM
drivers/misc/eeprom/at25.c static int at25_fw_to_chip(struct device *dev, struct spi_eeprom *chip) · line 365
Quoted 10 lines · Jiri Prchal
drivers/misc/eeprom/at25.c +10
-0+static int mypow (int x,int n) +{ +int i; +int res =1 ; + +for (i =0 ; i < n; ++i) + res *= x; + +return res; +}
We really don't have a in-kernel function for this today?
PATCH v4 3/4 nvmem: eeprom: add documentation for FRAM
In reply to Jiri PrchalAdded dt binding documentation.
---
v2: fixed dt_binding_check warnings thanks to Rob Herring
v3: resend and added more recipients
v4: resend
--- .../devicetree/bindings/eeprom/at25.yaml | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/eeprom/at25.yaml +25 -6
@@ -4,14 +4,16 @@ $id: "http://devicetree.org/schemas/eeprom/at25.yaml#" $schema: "http://devicetree.org/meta-schemas/core.yaml#" -title: SPI EEPROMs compatible with Atmel's AT25 +title: SPI EEPROMs or FRAMs compatible with Atmel's AT25 maintainers: - Christian Eggers <[email protected]> properties: $nodename: - pattern: "^eeprom@[0-9a-f]{1,2}$" + anyOf: + - pattern: "^eeprom@[0-9a-f]{1,2}$" + - pattern: "^fram@[0-9a-f]{1,2}$" # There are multiple known vendors who manufacture EEPROM chips compatible # with Atmel's AT25. The compatible string requires two items where the
@@ -31,6 +33,7 @@ properties: - microchip,25lc040 - st,m95m02 - st,m95256 + - cypress,fm25 - const: atmel,at25
@@ -48,7 +51,7 @@ properties: $ref: /schemas/types.yaml#/definitions/uint32 enum: [1, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072] description: - Size of the eeprom page. + Size of the eeprom page. FRAMs don't have pages. size: $ref: /schemas/types.yaml#/definitions/uint32
@@ -101,9 +104,19 @@ required: - compatible - reg - spi-max-frequency - - pagesize - - size - - address-width + +allOf: + - if: + properties: + compatible: + not: + contains: + const: cypress,fm25 + then: + required: + - pagesize + - size + - address-width additionalProperties: false
@@ -126,4 +139,10 @@ examples: size = <32768>; address-width = <16>; }; + + fram@1 { + compatible = "cypress,fm25", "atmel,at25"; + reg = <1>; + spi-max-frequency = <40000000>; + }; };
--
2.25.1
PATCH v4 4/4 nvmem: eeprom: at25: export FRAM serial num
In reply to Jiri PrchalThis exports serial number of FRAM in sysfs file named "sernum". Formatted in hex, each byte separated by space. Example:
$ cat /sys/class/spi_master/spi0/spi0.0/sernum a4 36 44 f2 ae 6c 00 00
---
v2: no change here
v3: resend and added more recipients
v4: resend
--- drivers/misc/eeprom/at25.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/misc/eeprom/at25.c +27 -1
@@ -38,6 +38,7 @@ struct at25_data {struct nvmem_config nvmem_config;struct nvmem_device *nvmem;int has_sernum; +char *sernum; };#define AT25_WREN 0x06/* latch the write enable */
@@ -172,6 +173,19 @@ static int fm25_aux_read(struct at25_data *at25, char *buf, uint8_t command,return status; } +static ssize_t sernum_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct at25_data *at25; +int i; + + at25 =dev_get_drvdata (dev); +for (i =0 ; i <FM25_SN_LEN ; i++) + buf +=sprintf (buf,"%02x " , at25->sernum[i]); +sprintf (--buf,"\n" ); +return (3 * i); +} +static DEVICE_ATTR_RO (sernum); +static int at25_ee_write (void *priv,unsigned int off,void *val,size_t count) {struct at25_data *at25 = priv;
@@ -427,8 +441,13 @@ static int at25_probe(struct spi_device *spi)else at25->chip.flags |=EE_ADDR2 ; -if (id[8 ]) +if (id[8 ]) { at25->has_sernum =1 ; + at25->sernum =kzalloc (FM25_SN_LEN ,GFP_KERNEL ); +if (!at25->sernum) +return -ENOMEM ; +fm25_aux_read (at25, at25->sernum,FM25_RDSN ,FM25_SN_LEN ); + }else at25->has_sernum =0 ;
@@ -467,6 +486,13 @@ static int at25_probe(struct spi_device *spi)if (IS_ERR (at25->nvmem))return PTR_ERR (at25->nvmem); +/* Export the FM25 serial number */ +if (at25->has_sernum) { + err =device_create_file (&spi->dev, &dev_attr_sernum); +if (err) +return err; + } + 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",
--
2.25.1
Greg Kroah-Hartman
maintainerRe: [PATCH v4 4/4] nvmem: eeprom: at25: export FRAM serial num
Quoted 4 lines · Jiri Prchal
This exports serial number of FRAM in sysfs file named "sernum". Formatted in hex, each byte separated by space. Example:
$ cat /sys/class/spi_master/spi0/spi0.0/sernum
No new Documentation/ABI/ entry for this?
Quoted 27 lines
a4 36 44 f2 ae 6c 00 00
Signed-off-by Jiri Prchal <[email protected]>---
v2: no change here
v3: resend and added more recipients
v4: resend--- drivers/misc/eeprom/at25.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)drivers/misc/eeprom/at25.c +1
-0@@ -38,6 +38,7 @@ struct at25_data {struct nvmem_config nvmem_config;struct nvmem_device *nvmem;int has_sernum; +char *sernum; };#define AT25_WREN 0x06/* latch the write enable */ @@ -172,6 +173,19 @@ static int fm25_aux_read(struct at25_data *at25, char *buf, uint8_t command,return status; }
drivers/misc/eeprom/at25.c static int fm25_aux_read(struct at25_data *at25, char *buf, uint8_t command, · line 185
Quoted 10 lines
drivers/misc/eeprom/at25.c +10
-0+static ssize_t sernum_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct at25_data *at25; +int i; + + at25 =dev_get_drvdata (dev); +for (i =0 ; i <FM25_SN_LEN ; i++) + buf +=sprintf (buf,"%02x " , at25->sernum[i]); +sprintf (--buf,"\n" ); +return (3 * i);
No, that is not how sysfs files work, sorry. They are "one value per file". This looks like multiple values in the same file, why not just one file per "sernum"?
Also, please use sysfs_emit() in the future.
Quoted 22 lines
drivers/misc/eeprom/at25.c +9
-1+} +static DEVICE_ATTR_RO (sernum); +static int at25_ee_write (void *priv,unsigned int off,void *val,size_t count) {struct at25_data *at25 = priv;@@ -427,8 +441,13 @@ static int at25_probe(struct spi_device *spi)else at25->chip.flags |=EE_ADDR2 ; -if (id[8 ]) +if (id[8 ]) { at25->has_sernum =1 ; + at25->sernum =kzalloc (FM25_SN_LEN ,GFP_KERNEL ); +if (!at25->sernum) +return -ENOMEM ; +fm25_aux_read (at25, at25->sernum,FM25_RDSN ,FM25_SN_LEN ); + }else at25->has_sernum =0 ;
drivers/misc/eeprom/at25.c static int at25_probe(struct spi_device *spi) · line 491
Quoted 6 lines
drivers/misc/eeprom/at25.c +3
-0@@ -467,6 +486,13 @@ static int at25_probe(struct spi_device *spi)if (IS_ERR (at25->nvmem))return PTR_ERR (at25->nvmem); +/* Export the FM25 serial number */ +if (at25->has_sernum) { + err =device_create_file (&spi->dev, &dev_attr_sernum);
You just raced with userspace and lost :(
Please do this correctly, by setting the driver group if you need a file like this.
thanks,
greg k-h
Re: [PATCH v4 4/4] nvmem: eeprom: at25: export FRAM serial num
Here I'm completlly lost:
Quoted 7 lines · Greg Kroah-Hartman
Quoted 4 lines · Jiri Prchal
This exports serial number of FRAM in sysfs file named "sernum". Formatted in hex, each byte separated by space. Example:
$ cat /sys/class/spi_master/spi0/spi0.0/sernumNo new
Documentation/ABI/entry for this?
No, should I do and how / where?
Quoted 6 lines
Quoted 6 lines
drivers/misc/eeprom/at25.c +6
-0+static ssize_t sernum_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct at25_data *at25; +int i; + + at25 =dev_get_drvdata (dev);
Quoted 8 lines
drivers/misc/eeprom/at25.c static int fm25_aux_read(struct at25_data *at25, char *buf, uint8_t command, · line 185
Quoted 4 lines
drivers/misc/eeprom/at25.c +4
-0+for (i =0 ; i <FM25_SN_LEN ; i++) + buf +=sprintf (buf,"%02x " , at25->sernum[i]); +sprintf (--buf,"\n" ); +return (3 * i);No, that is not how sysfs files work, sorry. They are "one value per file". This looks like multiple values in the same file, why not just one file per "sernum"?
It's formatted by spaces. It's one long number like MAC addr, so is better to expose it as hex string without spaces? Or like MAC separated by colon?
Quoted 2 lines
Also, please use
sysfs_emit()in the future.
Will do...
Quoted 28 lines
Quoted 28 lines
drivers/misc/eeprom/at25.c +9
-1+} +static DEVICE_ATTR_RO (sernum); +static int at25_ee_write (void *priv,unsigned int off,void *val,size_t count) {struct at25_data *at25 = priv;@@ -427,8 +441,13 @@ static int at25_probe(struct spi_device *spi)else at25->chip.flags |=EE_ADDR2 ; -if (id[8 ]) +if (id[8 ]) { at25->has_sernum =1 ; + at25->sernum =kzalloc (FM25_SN_LEN ,GFP_KERNEL ); +if (!at25->sernum) +return -ENOMEM ; +fm25_aux_read (at25, at25->sernum,FM25_RDSN ,FM25_SN_LEN ); + }else at25->has_sernum =0 ;@@ -467,6 +486,13 @@ static int at25_probe(struct spi_device *spi)if (IS_ERR (at25->nvmem))return PTR_ERR (at25->nvmem);
Quoted 5 lines
drivers/misc/eeprom/at25.c static int at25_probe(struct spi_device *spi) · line 491
Quoted 3 lines
drivers/misc/eeprom/at25.c +3
-0+/* Export the FM25 serial number */ +if (at25->has_sernum) { + err =device_create_file (&spi->dev, &dev_attr_sernum);You just raced with userspace and lost :(
?
Quoted 3 lines
Please do this correctly, by setting the driver group if you need a file like this.
Any example, please?
Quoted 5 lines
thanks,
greg k-h
thanks
Jiri
Greg Kroah-Hartman
maintainerRe: [PATCH v4 4/4] nvmem: eeprom: at25: export FRAM serial num
Quoted 11 lines · Jiří Prchal
Here I'm completlly lost:
Quoted 7 lines · Greg Kroah-Hartman
Quoted 4 lines · Jiri Prchal
This exports serial number of FRAM in sysfs file named "sernum". Formatted in hex, each byte separated by space. Example:
$ cat /sys/class/spi_master/spi0/spi0.0/sernumNo new
Documentation/ABI/entry for this?No, should I do and how / where?
All sysfs files need a Documentation/ABI/ entry.
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
drivers/misc/eeprom/at25.c +6
-0+static ssize_t sernum_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct at25_data *at25; +int i; + + at25 =dev_get_drvdata (dev);Quoted 8 lines
drivers/misc/eeprom/at25.c static int fm25_aux_read(struct at25_data *at25, char *buf, uint8_t command, · line 185
Quoted 4 lines
drivers/misc/eeprom/at25.c +4
-0+for (i =0 ; i <FM25_SN_LEN ; i++) + buf +=sprintf (buf,"%02x " , at25->sernum[i]); +sprintf (--buf,"\n" ); +return (3 * i);No, that is not how sysfs files work, sorry. They are "one value per file". This looks like multiple values in the same file, why not just one file per "sernum"?
Quoted 2 lines
It's formatted by spaces. It's one long number like MAC addr, so is better to expose it as hex string without spaces? Or like MAC separated by colon?
Why format it at all? Just dump out the whole thing as a string.
But who is going to care about this? What tool will be reading it and what will it be for? The Documentation/ABI/ entry would help explain all of this.
Quoted 10 lines
Quoted 5 lines
drivers/misc/eeprom/at25.c static int at25_probe(struct spi_device *spi) · line 491
Quoted 3 lines
drivers/misc/eeprom/at25.c +3
-0+/* Export the FM25 serial number */ +if (at25->has_sernum) { + err =device_create_file (&spi->dev, &dev_attr_sernum);You just raced with userspace and lost :(
?
Quoted 3 lines
Please do this correctly, by setting the driver group if you need a file like this.
Any example, please?
Loads, see any platform driver that sets the dev_groups pointer.
thanks,
greg k-h