summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Belloni <alexandre.belloni@bootlin.com>2018-11-10 15:29:03 -0500
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2018-11-22 12:10:07 -0500
commit41c9e132c5cc3e5f28cf44032ff82f7614a42989 (patch)
treecf3e3e8684653cbdbf78b257f4fd75115ed82bdb
parent461e557b97277b693cd8008c32a9d01c7f8f453b (diff)
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: Alexandre Belloni <alexandre.belloni@bootlin.com>
-rw-r--r--drivers/rtc/nvmem.c24
-rw-r--r--include/linux/rtc.h1
2 files changed, 10 insertions, 15 deletions
diff --git a/drivers/rtc/nvmem.c b/drivers/rtc/nvmem.c
index 2a7220d8b02d..ebdfe8e3a1a0 100644
--- a/drivers/rtc/nvmem.c
+++ b/drivers/rtc/nvmem.c
@@ -25,11 +25,9 @@ rtc_nvram_read(struct file *filp, struct kobject *kobj,
25 struct bin_attribute *attr, 25 struct bin_attribute *attr,
26 char *buf, loff_t off, size_t count) 26 char *buf, loff_t off, size_t count)
27{ 27{
28 struct rtc_device *rtc = attr->private;
29
30 dev_warn_once(kobj_to_dev(kobj), nvram_warning); 28 dev_warn_once(kobj_to_dev(kobj), nvram_warning);
31 29
32 return nvmem_device_read(rtc->nvmem, off, count, buf); 30 return nvmem_device_read(attr->private, off, count, buf);
33} 31}
34 32
35static ssize_t 33static ssize_t
@@ -37,14 +35,13 @@ rtc_nvram_write(struct file *filp, struct kobject *kobj,
37 struct bin_attribute *attr, 35 struct bin_attribute *attr,
38 char *buf, loff_t off, size_t count) 36 char *buf, loff_t off, size_t count)
39{ 37{
40 struct rtc_device *rtc = attr->private;
41
42 dev_warn_once(kobj_to_dev(kobj), nvram_warning); 38 dev_warn_once(kobj_to_dev(kobj), nvram_warning);
43 39
44 return nvmem_device_write(rtc->nvmem, off, count, buf); 40 return nvmem_device_write(attr->private, off, count, buf);
45} 41}
46 42
47static int rtc_nvram_register(struct rtc_device *rtc, size_t size) 43static int rtc_nvram_register(struct rtc_device *rtc,
44 struct nvmem_device *nvmem, size_t size)
48{ 45{
49 int err; 46 int err;
50 47
@@ -56,7 +53,7 @@ static int rtc_nvram_register(struct rtc_device *rtc, size_t size)
56 53
57 rtc->nvram->attr.name = "nvram"; 54 rtc->nvram->attr.name = "nvram";
58 rtc->nvram->attr.mode = 0644; 55 rtc->nvram->attr.mode = 0644;
59 rtc->nvram->private = rtc; 56 rtc->nvram->private = nvmem;
60 57
61 sysfs_bin_attr_init(rtc->nvram); 58 sysfs_bin_attr_init(rtc->nvram);
62 59
@@ -85,21 +82,20 @@ static void rtc_nvram_unregister(struct rtc_device *rtc)
85int rtc_nvmem_register(struct rtc_device *rtc, 82int rtc_nvmem_register(struct rtc_device *rtc,
86 struct nvmem_config *nvmem_config) 83 struct nvmem_config *nvmem_config)
87{ 84{
88 if (!IS_ERR_OR_NULL(rtc->nvmem)) 85 struct nvmem_device *nvmem;
89 return -EBUSY;
90 86
91 if (!nvmem_config) 87 if (!nvmem_config)
92 return -ENODEV; 88 return -ENODEV;
93 89
94 nvmem_config->dev = rtc->dev.parent; 90 nvmem_config->dev = rtc->dev.parent;
95 nvmem_config->owner = rtc->owner; 91 nvmem_config->owner = rtc->owner;
96 rtc->nvmem = devm_nvmem_register(rtc->dev.parent, nvmem_config); 92 nvmem = devm_nvmem_register(rtc->dev.parent, nvmem_config);
97 if (IS_ERR(rtc->nvmem)) 93 if (IS_ERR(nvmem))
98 return PTR_ERR(rtc->nvmem); 94 return PTR_ERR(nvmem);
99 95
100 /* Register the old ABI */ 96 /* Register the old ABI */
101 if (rtc->nvram_old_abi) 97 if (rtc->nvram_old_abi)
102 rtc_nvram_register(rtc, nvmem_config->size); 98 rtc_nvram_register(rtc, nvmem, nvmem_config->size);
103 99
104 return 0; 100 return 0;
105} 101}
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 311375dbb673..58147b057acd 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -138,7 +138,6 @@ struct rtc_device {
138 138
139 bool registered; 139 bool registered;
140 140
141 struct nvmem_device *nvmem;
142 /* Old ABI support */ 141 /* Old ABI support */
143 bool nvram_old_abi; 142 bool nvram_old_abi;
144 struct bin_attribute *nvram; 143 struct bin_attribute *nvram;