add support for FRAM
Subsystems (3)
v7 cover add support for FRAM
Adds support for Cypress FRAMs.
Jiri Prchal (5):
nvmem: eeprom: at25: prepare basics for FRAM support
nvmem: eeprom: at25: add support for FRAM
nvmem: eeprom: add documentation for FRAM
nvmem: eeprom: at25: export FRAM serial num
nvmem: eeprom: add documentation of sysfs sernum file
.../ABI/testing/sysfs-class-spi-eeprom | 6 + .../devicetree/bindings/eeprom/at25.yaml | 31 +++- drivers/misc/eeprom/Kconfig | 5 +- drivers/misc/eeprom/at25.c | 160 ++++++++++++++---- drivers/nvmem/core.c | 4 + include/linux/nvmem-provider.h | 1 + 6 files changed, 169 insertions(+), 38 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-class-spi-eeprom
Signature · 1 line
2.25.1
PATCH v7 1/5 nvmem: eeprom: at25: prepare basics for FRAM support
Added enum and string for FRAM to expose it as "fram".
---
v2: no change here
v3: resend and added more recipients
v4: resend
v5: no change here
v6: changed commit subject
v7: no change here
--- 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)
Signature · 1 line
2.25.1
Greg Kroah-Hartman
maintainerRe: [PATCH v7 1/5] nvmem: eeprom: at25: prepare basics for FRAM support
Quoted 28 lines · Jiri Prchal
Added enum and string for FRAM to expose it as "fram".
Signed-off-by Jiri Prchal <[email protected]>---
v2: no change here
v3: resend and added more recipients
v4: resend
v5: no change here
v6: changed commit subject
v7: no change here--- drivers/nvmem/core.c | 4 ++++ include/linux/nvmem-provider.h | 1 + 2 files changed, 5 insertions(+)drivers/nvmem/core.c +1
-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
drivers/nvmem/core.c static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem, · line 365
Quoted 6 lines
drivers/nvmem/core.c +3
-0@@ -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" ; +
As this is a new sysfs file, where is the documentation for it?
thanks,
greg k-h
PATCH v7 2/5 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
v5: used in-kernel function int_pow
v6: no change here
v7: moved definition of sernum size to patch 4
--- drivers/misc/eeprom/Kconfig | 5 +- drivers/misc/eeprom/at25.c | 140 ++++++++++++++++++++++++++++-------- 2 files changed, 113 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 +110 -30
218 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v7 3/5 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
v5: no change here
v6: no change here
v7: no change here
--- .../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>; + }; };
Signature · 1 line
2.25.1
Re: [PATCH v7 3/5] nvmem: eeprom: add documentation for FRAM
Quoted 1 line · Jiri Prchal
Added dt binding documentation.
I believe subject should be something like that:
"dt-bindings: nvmem: at25: add for fram support"
--mtx
Signature · 8 lines
--- Hinweis: unverschlüsselte E-Mails können leicht abgehört und manipuliert werden ! Für eine vertrauliche Kommunikation senden Sie bitte ihren GPG/PGP-Schlüssel zu. --- Enrico Weigelt, metux IT consult Free software and Linux embedded engineering [email protected] -- +49-151-27565287
PATCH v7 4/5 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 0000a43644f2ae6c
---
v2: no change here
v3: resend and added more recipients
v4: resend
v5: reworked up on Greg comments: no spaces in string, sysfs done correctly
v6: no change here
v7: moved FM25_SN_LEN, static array, used sysfs_emit, DEVICE_ATTR_RO
--- drivers/misc/eeprom/at25.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/misc/eeprom/at25.c +21 -1
@@ -31,6 +31,7 @@* AT25M02, AT25128B */ +#define FM25_SN_LEN 8/* serial number length */ struct at25_data {struct spi_device *spi;struct mutex lock;
@@ -39,6 +40,7 @@ struct at25_data {struct nvmem_config nvmem_config;struct nvmem_device *nvmem;int has_sernum; +u8 sernum[FM25_SN_LEN ]; };#define AT25_WREN 0x06/* latch the write enable */
@@ -172,6 +174,21 @@ 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; + + at25 =dev_get_drvdata (dev); +return sysfs_emit (buf,"%016llx\n" , *(unsigned long long *)at25->sernum); +} +static DEVICE_ATTR_RO (sernum); + +static struct attribute *sernum_attrs[] = { + &dev_attr_sernum.attr, +NULL , +}; +ATTRIBUTE_GROUPS (sernum); +static int at25_ee_write (void *priv,unsigned int off,void *val,size_t count) {struct at25_data *at25 = priv;
@@ -416,8 +433,10 @@ static int at25_probe(struct spi_device *spi)else at25->chip.flags |=EE_ADDR2 ; -if (id[8 ]) +if (id[8 ]) { at25->has_sernum =1 ; +fm25_aux_read (at25, at25->sernum,FM25_RDSN ,FM25_SN_LEN ); + }else at25->has_sernum =0 ;
@@ -471,6 +490,7 @@ static struct spi_driver at25_driver = { .driver = { .name = "at25", .of_match_table = at25_of_match, + .dev_groups = sernum_groups, }, .probe = at25_probe, };
Signature · 1 line
2.25.1
Greg Kroah-Hartman
maintainerRe: [PATCH v7 4/5] nvmem: eeprom: at25: export FRAM serial num
Quoted 39 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 0000a43644f2ae6cSigned-off-by Jiri Prchal <[email protected]>---
v2: no change here
v3: resend and added more recipients
v4: resend
v5: reworked up on Greg comments: no spaces in string, sysfs done correctly
v6: no change here
v7: movedFM25_SN_LEN, static array, usedsysfs_emit,DEVICE_ATTR_RO--- drivers/misc/eeprom/at25.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)drivers/misc/eeprom/at25.c +2
-0@@ -31,6 +31,7 @@* AT25M02, AT25128B */ +#define FM25_SN_LEN 8/* serial number length */ struct at25_data {struct spi_device *spi;struct mutex lock;@@ -39,6 +40,7 @@ struct at25_data {struct nvmem_config nvmem_config;struct nvmem_device *nvmem;int has_sernum; +u8 sernum[FM25_SN_LEN ]; };#define AT25_WREN 0x06/* latch the write enable */
drivers/misc/eeprom/at25.c static int fm25_aux_read(struct at25_data *at25, char *buf, uint8_t command, · line 182
Quoted 9 lines
drivers/misc/eeprom/at25.c +6
-0@@ -172,6 +174,21 @@ 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; + + at25 =dev_get_drvdata (dev); +return sysfs_emit (buf,"%016llx\n" , *(unsigned long long *)at25->sernum);
That's a horrid hack, why not use the %*phN modifier?
Look in the printk-formats.rst file for help.
thanks,
greg k-h
Re: [PATCH v7 4/5] nvmem: eeprom: at25: export FRAM serial num
Quoted 4 lines · Greg Kroah-Hartman
drivers/misc/eeprom/at25.c static int fm25_aux_read(struct at25_data *at25, char *buf, uint8_t command, · line 182
Quoted 1 line · Jiri Prchal
drivers/misc/eeprom/at25.c +1
-0+return sysfs_emit (buf,"%016llx\n" , *(unsigned long long *)at25->sernum);That's a horrid hack, why not use the %*phN modifier?
Prints as little endian, is that OK?
Jiri
Greg Kroah-Hartman
maintainerRe: [PATCH v7 4/5] nvmem: eeprom: at25: export FRAM serial num
Quoted 9 lines · Jiří Prchal
Quoted 4 lines · Greg Kroah-Hartman
drivers/misc/eeprom/at25.c static int fm25_aux_read(struct at25_data *at25, char *buf, uint8_t command, · line 182
Quoted 1 line · Jiri Prchal
drivers/misc/eeprom/at25.c +1
-0+return sysfs_emit (buf,"%016llx\n" , *(unsigned long long *)at25->sernum);That's a horrid hack, why not use the %*phN modifier?
Prints as little endian, is that OK?
You tell me! What tool is going to be reading this? What do they expect it to look like?
And it's a byte array, why would there be endian issues?
thanks,
greg k-h
Re: [PATCH v7 4/5] nvmem: eeprom: at25: export FRAM serial num
Quoted 5 lines · Greg Kroah-Hartman
Quoted 4 lines · Jiří Prchal
Quoted 1 line · Greg Kroah-Hartman
On Mon, Jun 07, 2021 at 02:26:39PM +0200, Jiri Prchal wrote:
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
drivers/misc/eeprom/at25.c static int fm25_aux_read(struct at25_data *at25, char *buf, uint8_t command, · line 182
Quoted 1 line
drivers/misc/eeprom/at25.c +1
-0+return sysfs_emit (buf,"%016llx\n" , *(unsigned long long *)at25->sernum);That's a horrid hack, why not use the %*phN modifier?
Prints as little endian, is that OK?
You tell me! What tool is going to be reading this? What do they expect it to look like?
sh, php in my usecase as unique id.
So endianess does not matter to me too much. The question is what is usual (like mac address, uuid...?).
Quoted 1 line
And it's a byte array, why would there be endian issues?
Now is printed as one big number. Not real issue. Just human readability? Should I turn back it to space separated bytes?
J
Greg Kroah-Hartman
maintainerRe: [PATCH v7 4/5] nvmem: eeprom: at25: export FRAM serial num
Quoted 12 lines · Jiří Prchal
Quoted 9 lines · Greg Kroah-Hartman
Quoted 8 lines · Jiří Prchal
Quoted 4 lines · Greg Kroah-Hartman
drivers/misc/eeprom/at25.c static int fm25_aux_read(struct at25_data *at25, char *buf, uint8_t command, · line 182
Quoted 1 line · Jiri Prchal
drivers/misc/eeprom/at25.c +1
-0+return sysfs_emit (buf,"%016llx\n" , *(unsigned long long *)at25->sernum);That's a horrid hack, why not use the %*phN modifier?
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Prints as little endian, is that OK?
You tell me! What tool is going to be reading this? What do they expect it to look like?
sh, php in my usecase as unique id.
I am sorry, I do not understand.
Quoted 2 lines
So endianess does not matter to me too much. The question is what is usual (like mac address, uuid...?).
What does the device export? Why not just export it as:
0123456789ABCDEF
if it is 8 bytes long?
Quoted 4 lines
Quoted 1 line
And it's a byte array, why would there be endian issues?
Now is printed as one big number. Not real issue. Just human readability? Should I turn back it to space separated bytes?
It's up to you, what do you want to do with it and what does a tool want it to look like?
thanks,
greg k-h
Re: [PATCH v7 4/5] nvmem: eeprom: at25: export FRAM serial num
Quoted 8 lines · Greg Kroah-Hartman
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Prints as little endian, is that OK?
You tell me! What tool is going to be reading this? What do they expect it to look like?
sh, php in my usecase as unique id.
I am sorry, I do not understand.
In my use case: shell and php.
Quoted 7 lines
Quoted 3 lines
So endianess does not matter to me too much. The question is what is usual (like mac address, uuid...?).
What does the device export? Why not just export it as:
0123456789ABCDEFif it is 8 bytes long?
Yes, device contains 0123456789ABCDEF.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
And it's a byte array, why would there be endian issues?
Now is printed as one big number. Not real issue. Just human readability? Should I turn back it to space separated bytes?
It's up to you, what do you want to do with it and what does a tool want it to look like?
Right now I export it as bytes separated by space. But no problem to change it. Just asking: for generic users what would be better or is there "best practice"?
Quoted 5 lines
thanks,
greg k-h
Re: [PATCH v7 4/5] nvmem: eeprom: at25: export FRAM serial num
Quoted 8 lines · Jiří Prchal
Quoted 2 lines · Greg Kroah-Hartman
It's up to you, what do you want to do with it and what does a tool want it to look like?
Right now I export it as bytes separated by space. But no problem to change it. Just asking: for generic users what would be better or is there "best practice"?
Hi Greg and others,
if nobody bothers I'll make it as space separated bytes, MSB first.
Jiri
PATCH v7 5/5 nvmem: eeprom: add documentation of sysfs sernum file
In reply to Jiri PrchalAdded sysfs sernum file documentation.
---
v5: new
v6: no change here
v7: no change here
--- Documentation/ABI/testing/sysfs-class-spi-eeprom | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-spi-eeprom
Documentation/ABI/testing/sysfs-class-spi-eeprom new file +6 -0
@@ -0,0 +1,6 @@ +What: /sys/class/spi_master/spi<bus>/spi<bus>.<dev>/sernum +Date: May 2021 +KernelVersion: 5.12.1 +Contact: Jiri Prchal <[email protected]> +Description: + Exports serial number of Cypress FRAM (FM25VN). 8 bytes as is in chip in hex string.
Signature · 1 line
2.25.1
Greg Kroah-Hartman
maintainerRe: [PATCH v7 5/5] nvmem: eeprom: add documentation of sysfs sernum file
Quoted 18 lines · Jiri Prchal
Added sysfs sernum file documentation.
Signed-off-by Jiri Prchal <[email protected]>---
v5: new
v6: no change here
v7: no change here--- Documentation/ABI/testing/sysfs-class-spi-eeprom | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-spi-eepromDocumentation/ABI/testing/sysfs-class-spi-eeprom new file +0
-0
Documentation/ABI/testing/sysfs-class-spi-eeprom line 3
Quoted 3 lines
Documentation/ABI/testing/sysfs-class-spi-eeprom new file +3
-0@@ -0,0 +1,6 @@ +What: /sys/class/spi_master/spi<bus>/spi<bus>.<dev>/sernum +Date: May 2021 +KernelVersion: 5.12.1
Odd kernel version number, I do not think it is correct :)
thanks,
greg k-h