From: Jiri Prchal <jiri.prchal@aksignal.cz>
To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Rob Herring <robh+dt@kernel.org>,
Christian Eggers <ceggers@arri.de>, Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Prchal <jiri.prchal@aksignal.cz>
Subject: [PATCH v6 4/5] nvmem: eeprom: at25: export FRAM serial num
Date: Mon, 7 Jun 2021 10:26:37 +0200 [thread overview]
Message-ID: <20210607082638.52409-5-jiri.prchal@aksignal.cz> (raw)
In-Reply-To: <20210607082638.52409-1-jiri.prchal@aksignal.cz>
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
0000a43644f2ae6c
Signed-off-by: Jiri Prchal <jiri.prchal@aksignal.cz>
---
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
---
drivers/misc/eeprom/at25.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index 45a486994828..4e4fa8d3ba5d 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -39,6 +39,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 */
@@ -173,6 +174,25 @@ 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 = FM25_SN_LEN - 1; i >= 0; i--)
+ buf += sprintf(buf, "%02x", at25->sernum[i]);
+ sprintf(buf, "\n");
+ return (2 * FM25_SN_LEN + 1);
+}
+static DEVICE_ATTR(sernum, 0440, sernum_show, NULL);
+
+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;
@@ -417,8 +437,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;
@@ -472,6 +497,7 @@ static struct spi_driver at25_driver = {
.driver = {
.name = "at25",
.of_match_table = at25_of_match,
+ .dev_groups = sernum_groups,
},
.probe = at25_probe,
};
--
2.25.1
next prev parent reply other threads:[~2021-06-07 8:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-07 8:26 [PATCH v6 0/5] add support for FRAM Jiri Prchal
2021-06-07 8:26 ` [PATCH v6 1/5] nvmem: eeprom: at25: prepare basics for FRAM support Jiri Prchal
2021-06-07 13:05 ` Enrico Weigelt, metux IT consult
2021-06-07 8:26 ` [PATCH v6 2/5] nvmem: eeprom: at25: add support for FRAM Jiri Prchal
2021-06-07 8:26 ` [PATCH v6 3/5] nvmem: eeprom: add documentation " Jiri Prchal
2021-06-07 8:26 ` Jiri Prchal [this message]
2021-06-07 9:31 ` [PATCH v6 4/5] nvmem: eeprom: at25: export FRAM serial num Greg Kroah-Hartman
2021-06-07 9:31 ` Greg Kroah-Hartman
2021-06-07 8:26 ` [PATCH v6 5/5] nvmem: eeprom: add documentation of sysfs sernum file Jiri Prchal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210607082638.52409-5-jiri.prchal@aksignal.cz \
--to=jiri.prchal@aksignal.cz \
--cc=arnd@arndb.de \
--cc=ceggers@arri.de \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).