Commit 41c9e132 authored by Alexandre Belloni's avatar Alexandre Belloni

rtc: nvmem: remove nvmem from struct rtc_device

Using devm_nvmem_register allows to avoid tracking the nvmem pointer in the
rtc_device structure.
This ultimately allows to register multiple nvmem devices from an RTC
driver.
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 461e557b
...@@ -25,11 +25,9 @@ rtc_nvram_read(struct file *filp, struct kobject *kobj, ...@@ -25,11 +25,9 @@ rtc_nvram_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr, struct bin_attribute *attr,
char *buf, loff_t off, size_t count) char *buf, loff_t off, size_t count)
{ {
struct rtc_device *rtc = attr->private;
dev_warn_once(kobj_to_dev(kobj), nvram_warning); dev_warn_once(kobj_to_dev(kobj), nvram_warning);
return nvmem_device_read(rtc->nvmem, off, count, buf); return nvmem_device_read(attr->private, off, count, buf);
} }
static ssize_t static ssize_t
...@@ -37,14 +35,13 @@ rtc_nvram_write(struct file *filp, struct kobject *kobj, ...@@ -37,14 +35,13 @@ rtc_nvram_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr, struct bin_attribute *attr,
char *buf, loff_t off, size_t count) char *buf, loff_t off, size_t count)
{ {
struct rtc_device *rtc = attr->private;
dev_warn_once(kobj_to_dev(kobj), nvram_warning); dev_warn_once(kobj_to_dev(kobj), nvram_warning);
return nvmem_device_write(rtc->nvmem, off, count, buf); return nvmem_device_write(attr->private, off, count, buf);
} }
static int rtc_nvram_register(struct rtc_device *rtc, size_t size) static int rtc_nvram_register(struct rtc_device *rtc,
struct nvmem_device *nvmem, size_t size)
{ {
int err; int err;
...@@ -56,7 +53,7 @@ static int rtc_nvram_register(struct rtc_device *rtc, size_t size) ...@@ -56,7 +53,7 @@ static int rtc_nvram_register(struct rtc_device *rtc, size_t size)
rtc->nvram->attr.name = "nvram"; rtc->nvram->attr.name = "nvram";
rtc->nvram->attr.mode = 0644; rtc->nvram->attr.mode = 0644;
rtc->nvram->private = rtc; rtc->nvram->private = nvmem;
sysfs_bin_attr_init(rtc->nvram); sysfs_bin_attr_init(rtc->nvram);
...@@ -85,21 +82,20 @@ static void rtc_nvram_unregister(struct rtc_device *rtc) ...@@ -85,21 +82,20 @@ static void rtc_nvram_unregister(struct rtc_device *rtc)
int rtc_nvmem_register(struct rtc_device *rtc, int rtc_nvmem_register(struct rtc_device *rtc,
struct nvmem_config *nvmem_config) struct nvmem_config *nvmem_config)
{ {
if (!IS_ERR_OR_NULL(rtc->nvmem)) struct nvmem_device *nvmem;
return -EBUSY;
if (!nvmem_config) if (!nvmem_config)
return -ENODEV; return -ENODEV;
nvmem_config->dev = rtc->dev.parent; nvmem_config->dev = rtc->dev.parent;
nvmem_config->owner = rtc->owner; nvmem_config->owner = rtc->owner;
rtc->nvmem = devm_nvmem_register(rtc->dev.parent, nvmem_config); nvmem = devm_nvmem_register(rtc->dev.parent, nvmem_config);
if (IS_ERR(rtc->nvmem)) if (IS_ERR(nvmem))
return PTR_ERR(rtc->nvmem); return PTR_ERR(nvmem);
/* Register the old ABI */ /* Register the old ABI */
if (rtc->nvram_old_abi) if (rtc->nvram_old_abi)
rtc_nvram_register(rtc, nvmem_config->size); rtc_nvram_register(rtc, nvmem, nvmem_config->size);
return 0; return 0;
} }
......
...@@ -138,7 +138,6 @@ struct rtc_device { ...@@ -138,7 +138,6 @@ struct rtc_device {
bool registered; bool registered;
struct nvmem_device *nvmem;
/* Old ABI support */ /* Old ABI support */
bool nvram_old_abi; bool nvram_old_abi;
struct bin_attribute *nvram; struct bin_attribute *nvram;
......
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