Commit d7ca4299 authored by Alexandre Belloni's avatar Alexandre Belloni

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: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 8d3e6b55
......@@ -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",
},
......
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