rtc: ds1511: 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: Alexandre Belloni <alexandre.belloni@free-electrons.com>
This commit is contained in:
Alexandre Belloni 2017-10-13 00:05:29 +02:00
parent a283d27625
commit 9d7ed21ff4

View file

@ -398,42 +398,37 @@ static const struct rtc_class_ops ds1511_rtc_ops = {
.alarm_irq_enable = ds1511_rtc_alarm_irq_enable, .alarm_irq_enable = ds1511_rtc_alarm_irq_enable,
}; };
static ssize_t static int ds1511_nvram_read(void *priv, unsigned int pos, void *buf,
ds1511_nvram_read(struct file *filp, struct kobject *kobj, size_t size)
struct bin_attribute *ba,
char *buf, loff_t pos, size_t size)
{ {
ssize_t count; int i;
rtc_write(pos, DS1511_RAMADDR_LSB); rtc_write(pos, DS1511_RAMADDR_LSB);
for (count = 0; count < size; count++) for (i = 0; i < size; i++)
*buf++ = rtc_read(DS1511_RAMDATA); *(char *)buf++ = rtc_read(DS1511_RAMDATA);
return count; return 0;
} }
static ssize_t static int ds1511_nvram_write(void *priv, unsigned int pos, void *buf,
ds1511_nvram_write(struct file *filp, struct kobject *kobj, size_t size)
struct bin_attribute *bin_attr,
char *buf, loff_t pos, size_t size)
{ {
ssize_t count; int i;
rtc_write(pos, DS1511_RAMADDR_LSB); rtc_write(pos, DS1511_RAMADDR_LSB);
for (count = 0; count < size; count++) for (i = 0; i < size; i++)
rtc_write(*buf++, DS1511_RAMDATA); rtc_write(*(char *)buf++, DS1511_RAMDATA);
return count; return 0;
} }
static struct bin_attribute ds1511_nvram_attr = { static struct nvmem_config ds1511_nvmem_cfg = {
.attr = { .name = "ds1511_nvram",
.name = "nvram", .word_size = 1,
.mode = S_IRUGO | S_IWUSR, .stride = 1,
},
.size = DS1511_RAM_MAX, .size = DS1511_RAM_MAX,
.read = ds1511_nvram_read, .reg_read = ds1511_nvram_read,
.write = ds1511_nvram_write, .reg_write = ds1511_nvram_write,
}; };
static int ds1511_rtc_probe(struct platform_device *pdev) static int ds1511_rtc_probe(struct platform_device *pdev)
@ -483,6 +478,10 @@ static int ds1511_rtc_probe(struct platform_device *pdev)
pdata->rtc->ops = &ds1511_rtc_ops; pdata->rtc->ops = &ds1511_rtc_ops;
ds1511_nvmem_cfg.priv = &pdev->dev;
pdata->rtc->nvmem_config = &ds1511_nvmem_cfg;
pdata->rtc->nvram_old_abi = true;
ret = rtc_register_device(pdata->rtc); ret = rtc_register_device(pdata->rtc);
if (ret) if (ret)
return ret; return ret;
@ -501,18 +500,6 @@ static int ds1511_rtc_probe(struct platform_device *pdev)
} }
} }
ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
if (ret)
dev_err(&pdev->dev, "Unable to create sysfs entry: %s\n",
ds1511_nvram_attr.attr.name);
return 0;
}
static int ds1511_rtc_remove(struct platform_device *pdev)
{
sysfs_remove_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
return 0; return 0;
} }
@ -521,7 +508,6 @@ MODULE_ALIAS("platform:ds1511");
static struct platform_driver ds1511_rtc_driver = { static struct platform_driver ds1511_rtc_driver = {
.probe = ds1511_rtc_probe, .probe = ds1511_rtc_probe,
.remove = ds1511_rtc_remove,
.driver = { .driver = {
.name = "ds1511", .name = "ds1511",
}, },