diff options
author | Alexandre Belloni <alexandre.belloni@bootlin.com> | 2018-02-12 23:47:54 +0100 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@bootlin.com> | 2018-03-01 10:49:33 +0100 |
commit | d7ca4299d7c035969652596f0daa76407f6cfbdd (patch) | |
tree | 90bc51697340f50477fafeffd3444e7a96418f68 /drivers/rtc/rtc-stk17ta8.c | |
parent | 8d3e6b55cedaeadd1216d4b548f346c169099f1f (diff) | |
download | blackbird-op-linux-d7ca4299d7c035969652596f0daa76407f6cfbdd.tar.gz blackbird-op-linux-d7ca4299d7c035969652596f0daa76407f6cfbdd.zip |
rtc: stk17ta8: use generic nvmem
Instead of adding a binary sysfs attribute from the driver, use the core to
register an nvmem device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Diffstat (limited to 'drivers/rtc/rtc-stk17ta8.c')
-rw-r--r-- | drivers/rtc/rtc-stk17ta8.c | 64 |
1 files changed, 24 insertions, 40 deletions
diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c index 1d6febbe7d39..01a3bef77aa5 100644 --- a/drivers/rtc/rtc-stk17ta8.c +++ b/drivers/rtc/rtc-stk17ta8.c @@ -242,46 +242,30 @@ static const struct rtc_class_ops stk17ta8_rtc_ops = { .alarm_irq_enable = stk17ta8_rtc_alarm_irq_enable, }; -static ssize_t stk17ta8_nvram_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t pos, size_t size) +static int stk17ta8_nvram_read(void *priv, unsigned int pos, void *val, + size_t bytes) { - struct device *dev = container_of(kobj, struct device, kobj); - struct platform_device *pdev = to_platform_device(dev); - struct rtc_plat_data *pdata = platform_get_drvdata(pdev); + struct rtc_plat_data *pdata = priv; void __iomem *ioaddr = pdata->ioaddr; - ssize_t count; + u8 *buf = val; - for (count = 0; count < size; count++) + for (; bytes; bytes--) *buf++ = readb(ioaddr + pos++); - return count; + return 0; } -static ssize_t stk17ta8_nvram_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t pos, size_t size) +static int stk17ta8_nvram_write(void *priv, unsigned int pos, void *val, + size_t bytes) { - struct device *dev = container_of(kobj, struct device, kobj); - struct platform_device *pdev = to_platform_device(dev); - struct rtc_plat_data *pdata = platform_get_drvdata(pdev); + struct rtc_plat_data *pdata = priv; void __iomem *ioaddr = pdata->ioaddr; - ssize_t count; + u8 *buf = val; - for (count = 0; count < size; count++) + for (; bytes; bytes--) writeb(*buf++, ioaddr + pos++); - return count; + return 0; } -static struct bin_attribute stk17ta8_nvram_attr = { - .attr = { - .name = "nvram", - .mode = S_IRUGO | S_IWUSR, - }, - .size = RTC_OFFSET, - .read = stk17ta8_nvram_read, - .write = stk17ta8_nvram_write, -}; - static int stk17ta8_rtc_probe(struct platform_device *pdev) { struct resource *res; @@ -290,6 +274,14 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev) struct rtc_plat_data *pdata; void __iomem *ioaddr; int ret = 0; + struct nvmem_config nvmem_cfg = { + .name = "stk17ta8_nvram", + .word_size = 1, + .stride = 1, + .size = RTC_OFFSET, + .reg_read = stk17ta8_nvram_read, + .reg_write = stk17ta8_nvram_write, + }; pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) @@ -333,21 +325,14 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev) return PTR_ERR(pdata->rtc); pdata->rtc->ops = &stk17ta8_rtc_ops; + pdata->rtc->nvram_old_abi = true; - ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr); + nvmem_cfg.priv = pdata; + ret = rtc_nvmem_register(pdata->rtc, &nvmem_cfg); if (ret) return ret; - ret = rtc_register_device(pdata->rtc); - - return ret; -} - -static int stk17ta8_rtc_remove(struct platform_device *pdev) -{ - sysfs_remove_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr); - - return 0; + return rtc_register_device(pdata->rtc); } /* work with hotplug and coldplug */ @@ -355,7 +340,6 @@ MODULE_ALIAS("platform:stk17ta8"); static struct platform_driver stk17ta8_rtc_driver = { .probe = stk17ta8_rtc_probe, - .remove = stk17ta8_rtc_remove, .driver = { .name = "stk17ta8", }, |