From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: linux-rtc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Alexandre Belloni <alexandre.belloni@bootlin.com>
Subject: [PATCH 24/45] rtc: ds1343: use generic nvmem
Date: Mon, 12 Feb 2018 23:47:38 +0100 [thread overview]
Message-ID: <20180212224759.15999-25-alexandre.belloni@bootlin.com> (raw)
In-Reply-To: <20180212224759.15999-1-alexandre.belloni@bootlin.com>
Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
drivers/rtc/rtc-ds1343.c | 66 +++++++++++++++---------------------------------
1 file changed, 20 insertions(+), 46 deletions(-)
diff --git a/drivers/rtc/rtc-ds1343.c b/drivers/rtc/rtc-ds1343.c
index 67cae0dd8154..59d27db2fd37 100644
--- a/drivers/rtc/rtc-ds1343.c
+++ b/drivers/rtc/rtc-ds1343.c
@@ -153,52 +153,22 @@ static ssize_t ds1343_store_glitchfilter(struct device *dev,
static DEVICE_ATTR(glitch_filter, S_IRUGO | S_IWUSR, ds1343_show_glitchfilter,
ds1343_store_glitchfilter);
-static ssize_t ds1343_nvram_write(struct file *filp, struct kobject *kobj,
- struct bin_attribute *attr,
- char *buf, loff_t off, size_t count)
+static int ds1343_nvram_write(void *priv, unsigned int off, void *val,
+ size_t bytes)
{
- int ret;
- unsigned char address;
- struct device *dev = kobj_to_dev(kobj);
- struct ds1343_priv *priv = dev_get_drvdata(dev);
-
- address = DS1343_NVRAM + off;
+ struct ds1343_priv *ds1343 = priv;
- ret = regmap_bulk_write(priv->map, address, buf, count);
- if (ret < 0)
- dev_err(&priv->spi->dev, "Error in nvram write %d", ret);
-
- return (ret < 0) ? ret : count;
+ return regmap_bulk_write(ds1343->map, DS1343_NVRAM + off, val, bytes);
}
-
-static ssize_t ds1343_nvram_read(struct file *filp, struct kobject *kobj,
- struct bin_attribute *attr,
- char *buf, loff_t off, size_t count)
+static int ds1343_nvram_read(void *priv, unsigned int off, void *val,
+ size_t bytes)
{
- int ret;
- unsigned char address;
- struct device *dev = kobj_to_dev(kobj);
- struct ds1343_priv *priv = dev_get_drvdata(dev);
-
- address = DS1343_NVRAM + off;
+ struct ds1343_priv *ds1343 = priv;
- ret = regmap_bulk_read(priv->map, address, buf, count);
- if (ret < 0)
- dev_err(&priv->spi->dev, "Error in nvram read %d\n", ret);
-
- return (ret < 0) ? ret : count;
+ return regmap_bulk_read(ds1343->map, DS1343_NVRAM + off, val, bytes);
}
-
-static struct bin_attribute nvram_attr = {
- .attr.name = "nvram",
- .attr.mode = S_IRUGO | S_IWUSR,
- .read = ds1343_nvram_read,
- .write = ds1343_nvram_write,
- .size = DS1343_NVRAM_LEN,
-};
-
static ssize_t ds1343_show_tricklecharger(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -252,16 +222,9 @@ static int ds1343_sysfs_register(struct device *dev)
return err;
err = device_create_file(dev, &dev_attr_trickle_charger);
- if (err)
- goto error1;
-
- err = device_create_bin_file(dev, &nvram_attr);
if (!err)
return 0;
- device_remove_file(dev, &dev_attr_trickle_charger);
-
-error1:
device_remove_file(dev, &dev_attr_glitch_filter);
return err;
@@ -271,7 +234,6 @@ static void ds1343_sysfs_unregister(struct device *dev)
{
device_remove_file(dev, &dev_attr_glitch_filter);
device_remove_file(dev, &dev_attr_trickle_charger);
- device_remove_bin_file(dev, &nvram_attr);
}
static int ds1343_read_time(struct device *dev, struct rtc_time *dt)
@@ -509,6 +471,14 @@ static int ds1343_probe(struct spi_device *spi)
.write_flag_mask = 0x80, };
unsigned int data;
int res;
+ struct nvmem_config nvmem_cfg = {
+ .name = "ds1343-",
+ .word_size = 1,
+ .stride = 1,
+ .size = DS1343_NVRAM_LEN,
+ .reg_read = ds1343_nvram_read,
+ .reg_write = ds1343_nvram_write,
+ };
priv = devm_kzalloc(&spi->dev, sizeof(struct ds1343_priv), GFP_KERNEL);
if (!priv)
@@ -552,12 +522,16 @@ static int ds1343_probe(struct spi_device *spi)
if (IS_ERR(priv->rtc))
return PTR_ERR(priv->rtc);
+ priv->rtc->nvram_old_abi = true;
priv->rtc->ops = &ds1343_rtc_ops;
res = rtc_register_device(priv->rtc);
if (res)
return res;
+ nvmem_cfg.priv = priv;
+ rtc_nvmem_register(priv->rtc, &nvmem_cfg);
+
priv->irq = spi->irq;
if (priv->irq >= 0) {
--
2.16.1
next prev parent reply other threads:[~2018-02-12 22:48 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-12 22:47 [PATCH 00/45] RTC: nvmem improvements Alexandre Belloni
2018-02-12 22:47 ` [PATCH 01/45] rtc: documentation: correct nvmem date and version Alexandre Belloni
2018-02-12 22:47 ` [PATCH 02/45] rtc: nvmem: pass nvmem_config to rtc_nvmem_register() Alexandre Belloni
2018-02-12 22:47 ` [PATCH 03/45] rtc: nvmem: return error values Alexandre Belloni
2018-02-12 22:47 ` [PATCH 04/45] rtc: nvmem: disallow registering nvmem more than once Alexandre Belloni
2018-02-12 22:47 ` [PATCH 05/45] rtc: export rtc_nvmem_register() to drivers Alexandre Belloni
2018-02-12 22:47 ` [PATCH 06/45] rtc: ds1305: call rtc_nvmem_register() Alexandre Belloni
2018-02-12 22:47 ` [PATCH 07/45] rtc: ds1305: put ds1305_nvmem_cfg on the stack Alexandre Belloni
2018-02-12 22:47 ` [PATCH 08/45] rtc: ds1307: call rtc_nvmem_register() Alexandre Belloni
2018-02-12 22:47 ` [PATCH 09/45] rtc: ds1307: put struct nvmem_config on the stack Alexandre Belloni
2018-02-12 22:47 ` [PATCH 10/45] rtc: ds1511: call rtc_nvmem_register() Alexandre Belloni
2018-02-12 22:47 ` [PATCH 11/45] rtc: ds1511: put ds1511_nvmem_cfg on the stack Alexandre Belloni
2018-02-12 22:47 ` [PATCH 12/45] rtc: m48t86: call rtc_nvmem_register() Alexandre Belloni
2018-02-12 22:47 ` [PATCH 13/45] rtc: m48t86: put m48t86_nvmem_cfg on the stack Alexandre Belloni
2018-02-12 22:47 ` [PATCH 14/45] rtc: omap: call rtc_nvmem_register() Alexandre Belloni
2018-02-12 22:47 ` [PATCH 15/45] rtc: pcf85363: " Alexandre Belloni
2018-02-12 22:47 ` [PATCH 16/45] rtc: pcf85363: put struct nvmem_config on the stack Alexandre Belloni
2018-02-12 22:47 ` [PATCH 17/45] rtc: rv8803: call rtc_nvmem_register() Alexandre Belloni
2018-02-12 22:47 ` [PATCH 18/45] rtc: rv8803: put struct nvmem_config on the stack Alexandre Belloni
2018-02-12 22:47 ` [PATCH 19/45] rtc: rv8803: fix possible race condition Alexandre Belloni
2018-02-12 22:47 ` [PATCH 20/45] rtc: remove nvmem_config Alexandre Belloni
2018-02-12 22:47 ` [PATCH 21/45] rtc: ds1343: simplify regmap initialization Alexandre Belloni
2018-02-12 22:47 ` [PATCH 22/45] rtc: ds1343: switch to rtc_register_device Alexandre Belloni
2018-02-12 22:47 ` [PATCH 23/45] rtc: ds1343: remove undocumented and useless sysfs files Alexandre Belloni
2018-02-12 22:47 ` Alexandre Belloni [this message]
2018-02-12 22:47 ` [PATCH 25/45] rtc: m48t59: switch to rtc_register_device Alexandre Belloni
2018-02-12 22:47 ` [PATCH 26/45] rtc: m48t59: use generic nvmem Alexandre Belloni
2018-02-12 22:47 ` [PATCH 27/45] rtc: sirfsoc: remove useless sirfsoc_rtc_ioctl Alexandre Belloni
2018-02-12 22:47 ` [PATCH 28/45] rtc: ds1553: switch to rtc_register_device Alexandre Belloni
2018-02-12 22:47 ` [PATCH 29/45] rtc: ds1553: use generic nvmem Alexandre Belloni
2018-02-12 22:47 ` [PATCH 30/45] rtc: ds1553: make alarms useful Alexandre Belloni
2018-02-12 22:47 ` [PATCH 31/45] rtc: cmos: fix possible race condition Alexandre Belloni
2018-02-12 22:47 ` [PATCH 32/45] rtc: cmos: use generic nvmem Alexandre Belloni
2018-02-12 22:47 ` [PATCH 33/45] rtc: ds1742: switch to rtc_register_device Alexandre Belloni
2018-02-12 22:47 ` [PATCH 34/45] rtc: ds1742: use generic nvmem Alexandre Belloni
2018-02-12 22:47 ` [PATCH 35/45] rtc: rp5c01: fix possible race condition Alexandre Belloni
2018-02-12 22:47 ` [PATCH 36/45] rtc: rp5c01: use generic nvmem Alexandre Belloni
2018-02-12 22:47 ` [PATCH 37/45] rtc: stk17ta8: make alarms useful Alexandre Belloni
2018-02-12 22:47 ` [PATCH 38/45] rtc: stk17ta8: switch to rtc_register_device Alexandre Belloni
2018-02-12 22:47 ` [PATCH 39/45] rtc: stk17ta8: fix possible race condition Alexandre Belloni
2018-02-12 22:47 ` [PATCH 40/45] rtc: stk17ta8: use generic nvmem Alexandre Belloni
2018-02-12 22:47 ` [PATCH 41/45] rtc: tx4939: remove arch/mips dependency Alexandre Belloni
2018-02-12 22:47 ` [PATCH 42/45] rtc: tx4939: extend test coverage Alexandre Belloni
2018-02-12 22:47 ` [PATCH 43/45] rtc: tx4939: switch to rtc_register_device Alexandre Belloni
2018-02-12 22:47 ` [PATCH 44/45] rtc: tx4939: fix possible race condition Alexandre Belloni
2018-02-12 22:47 ` [PATCH 45/45] rtc: tx4939: use generic nvmem Alexandre Belloni
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=20180212224759.15999-25-alexandre.belloni@bootlin.com \
--to=alexandre.belloni@bootlin.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.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
all inboxes | Powered by JetHome®