Commit d7501f70 authored by Alexandre Belloni's avatar Alexandre Belloni

rtc: ds1343: use generic nvmem

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: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent ab392864
...@@ -153,52 +153,22 @@ static ssize_t ds1343_store_glitchfilter(struct device *dev, ...@@ -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, static DEVICE_ATTR(glitch_filter, S_IRUGO | S_IWUSR, ds1343_show_glitchfilter,
ds1343_store_glitchfilter); ds1343_store_glitchfilter);
static ssize_t ds1343_nvram_write(struct file *filp, struct kobject *kobj, static int ds1343_nvram_write(void *priv, unsigned int off, void *val,
struct bin_attribute *attr, size_t bytes)
char *buf, loff_t off, size_t count)
{ {
int ret; struct ds1343_priv *ds1343 = priv;
unsigned char address;
struct device *dev = kobj_to_dev(kobj);
struct ds1343_priv *priv = dev_get_drvdata(dev);
address = DS1343_NVRAM + off;
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 int ds1343_nvram_read(void *priv, unsigned int off, void *val,
static ssize_t ds1343_nvram_read(struct file *filp, struct kobject *kobj, size_t bytes)
struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
{ {
int ret; struct ds1343_priv *ds1343 = priv;
unsigned char address;
struct device *dev = kobj_to_dev(kobj);
struct ds1343_priv *priv = dev_get_drvdata(dev);
address = DS1343_NVRAM + off; return regmap_bulk_read(ds1343->map, DS1343_NVRAM + off, val, bytes);
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;
} }
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, static ssize_t ds1343_show_tricklecharger(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
...@@ -252,16 +222,9 @@ static int ds1343_sysfs_register(struct device *dev) ...@@ -252,16 +222,9 @@ static int ds1343_sysfs_register(struct device *dev)
return err; return err;
err = device_create_file(dev, &dev_attr_trickle_charger); err = device_create_file(dev, &dev_attr_trickle_charger);
if (err)
goto error1;
err = device_create_bin_file(dev, &nvram_attr);
if (!err) if (!err)
return 0; return 0;
device_remove_file(dev, &dev_attr_trickle_charger);
error1:
device_remove_file(dev, &dev_attr_glitch_filter); device_remove_file(dev, &dev_attr_glitch_filter);
return err; return err;
...@@ -271,7 +234,6 @@ static void ds1343_sysfs_unregister(struct device *dev) ...@@ -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_glitch_filter);
device_remove_file(dev, &dev_attr_trickle_charger); 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) static int ds1343_read_time(struct device *dev, struct rtc_time *dt)
...@@ -509,6 +471,14 @@ static int ds1343_probe(struct spi_device *spi) ...@@ -509,6 +471,14 @@ static int ds1343_probe(struct spi_device *spi)
.write_flag_mask = 0x80, }; .write_flag_mask = 0x80, };
unsigned int data; unsigned int data;
int res; 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); priv = devm_kzalloc(&spi->dev, sizeof(struct ds1343_priv), GFP_KERNEL);
if (!priv) if (!priv)
...@@ -552,12 +522,16 @@ static int ds1343_probe(struct spi_device *spi) ...@@ -552,12 +522,16 @@ static int ds1343_probe(struct spi_device *spi)
if (IS_ERR(priv->rtc)) if (IS_ERR(priv->rtc))
return PTR_ERR(priv->rtc); return PTR_ERR(priv->rtc);
priv->rtc->nvram_old_abi = true;
priv->rtc->ops = &ds1343_rtc_ops; priv->rtc->ops = &ds1343_rtc_ops;
res = rtc_register_device(priv->rtc); res = rtc_register_device(priv->rtc);
if (res) if (res)
return res; return res;
nvmem_cfg.priv = priv;
rtc_nvmem_register(priv->rtc, &nvmem_cfg);
priv->irq = spi->irq; priv->irq = spi->irq;
if (priv->irq >= 0) { if (priv->irq >= 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment