aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Hartley Sweeten <hsweeten@visionengravers.com>2017-02-10 13:11:57 -0500
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>2017-02-11 19:08:01 -0500
commitb180cf8b0bce3e0e1eb9c5d78bfc9ef2559a0b22 (patch)
treedbaa0128da3c7e3075e5b9f5d34c1028fc720d74
parent8057c86d43a6579421c97b00c6df1ab0bc5e51a0 (diff)
rtc: m48t86: add NVRAM support
This RTC has 114 bytes of NVRAM. Provide access to it via a binary sysfs 'nvram' attribute file. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
-rw-r--r--drivers/rtc/rtc-m48t86.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 4dcdbd2a2408..4dc4af41c03d 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -38,6 +38,8 @@
38#define M48T86_C 0x0c 38#define M48T86_C 0x0c
39#define M48T86_D 0x0d 39#define M48T86_D 0x0d
40#define M48T86_D_VRT BIT(7) 40#define M48T86_D_VRT BIT(7)
41#define M48T86_NVRAM(x) (0x0e + (x))
42#define M48T86_NVRAM_LEN 114
41 43
42struct m48t86_rtc_info { 44struct m48t86_rtc_info {
43 void __iomem *index_reg; 45 void __iomem *index_reg;
@@ -170,6 +172,35 @@ static const struct rtc_class_ops m48t86_rtc_ops = {
170 .proc = m48t86_rtc_proc, 172 .proc = m48t86_rtc_proc,
171}; 173};
172 174
175static ssize_t m48t86_nvram_read(struct file *filp, struct kobject *kobj,
176 struct bin_attribute *attr,
177 char *buf, loff_t off, size_t count)
178{
179 struct device *dev = kobj_to_dev(kobj);
180 unsigned int i;
181
182 for (i = 0; i < count; i++)
183 buf[i] = m48t86_readb(dev, M48T86_NVRAM(off + i));
184
185 return count;
186}
187
188static ssize_t m48t86_nvram_write(struct file *filp, struct kobject *kobj,
189 struct bin_attribute *attr,
190 char *buf, loff_t off, size_t count)
191{
192 struct device *dev = kobj_to_dev(kobj);
193 unsigned int i;
194
195 for (i = 0; i < count; i++)
196 m48t86_writeb(dev, buf[i], M48T86_NVRAM(off + i));
197
198 return count;
199}
200
201static BIN_ATTR(nvram, 0644, m48t86_nvram_read, m48t86_nvram_write,
202 M48T86_NVRAM_LEN);
203
173static int m48t86_rtc_probe(struct platform_device *pdev) 204static int m48t86_rtc_probe(struct platform_device *pdev)
174{ 205{
175 struct m48t86_rtc_info *info; 206 struct m48t86_rtc_info *info;
@@ -210,6 +241,15 @@ static int m48t86_rtc_probe(struct platform_device *pdev)
210 dev_info(&pdev->dev, "battery %s\n", 241 dev_info(&pdev->dev, "battery %s\n",
211 (reg & M48T86_D_VRT) ? "ok" : "exhausted"); 242 (reg & M48T86_D_VRT) ? "ok" : "exhausted");
212 243
244 if (device_create_bin_file(&pdev->dev, &bin_attr_nvram))
245 dev_err(&pdev->dev, "failed to create nvram sysfs entry\n");
246
247 return 0;
248}
249
250static int m48t86_rtc_remove(struct platform_device *pdev)
251{
252 device_remove_bin_file(&pdev->dev, &bin_attr_nvram);
213 return 0; 253 return 0;
214} 254}
215 255
@@ -218,6 +258,7 @@ static struct platform_driver m48t86_rtc_platform_driver = {
218 .name = "rtc-m48t86", 258 .name = "rtc-m48t86",
219 }, 259 },
220 .probe = m48t86_rtc_probe, 260 .probe = m48t86_rtc_probe,
261 .remove = m48t86_rtc_remove,
221}; 262};
222 263
223module_platform_driver(m48t86_rtc_platform_driver); 264module_platform_driver(m48t86_rtc_platform_driver);