Commit 7335fb9b authored by Alexandre Belloni's avatar Alexandre Belloni

rtc: rp5c01: 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 bcdd5592
...@@ -64,7 +64,6 @@ struct rp5c01_priv { ...@@ -64,7 +64,6 @@ struct rp5c01_priv {
u32 __iomem *regs; u32 __iomem *regs;
struct rtc_device *rtc; struct rtc_device *rtc;
spinlock_t lock; /* against concurrent RTC/NVRAM access */ spinlock_t lock; /* against concurrent RTC/NVRAM access */
struct bin_attribute nvram_attr;
}; };
static inline unsigned int rp5c01_read(struct rp5c01_priv *priv, static inline unsigned int rp5c01_read(struct rp5c01_priv *priv,
...@@ -160,17 +159,15 @@ static const struct rtc_class_ops rp5c01_rtc_ops = { ...@@ -160,17 +159,15 @@ static const struct rtc_class_ops rp5c01_rtc_ops = {
* byte is stored in BLOCK10, the low nibble in BLOCK11. * byte is stored in BLOCK10, the low nibble in BLOCK11.
*/ */
static ssize_t rp5c01_nvram_read(struct file *filp, struct kobject *kobj, static int rp5c01_nvram_read(void *_priv, unsigned int pos, void *val,
struct bin_attribute *bin_attr, size_t bytes)
char *buf, loff_t pos, size_t size)
{ {
struct device *dev = container_of(kobj, struct device, kobj); struct rp5c01_priv *priv = _priv;
struct rp5c01_priv *priv = dev_get_drvdata(dev); u8 *buf = val;
ssize_t count;
spin_lock_irq(&priv->lock); spin_lock_irq(&priv->lock);
for (count = 0; count < size; count++) { for (; bytes; bytes--) {
u8 data; u8 data;
rp5c01_write(priv, rp5c01_write(priv,
...@@ -187,20 +184,18 @@ static ssize_t rp5c01_nvram_read(struct file *filp, struct kobject *kobj, ...@@ -187,20 +184,18 @@ static ssize_t rp5c01_nvram_read(struct file *filp, struct kobject *kobj,
} }
spin_unlock_irq(&priv->lock); spin_unlock_irq(&priv->lock);
return count; return 0;
} }
static ssize_t rp5c01_nvram_write(struct file *filp, struct kobject *kobj, static int rp5c01_nvram_write(void *_priv, unsigned int pos, void *val,
struct bin_attribute *bin_attr, size_t bytes)
char *buf, loff_t pos, size_t size)
{ {
struct device *dev = container_of(kobj, struct device, kobj); struct rp5c01_priv *priv = _priv;
struct rp5c01_priv *priv = dev_get_drvdata(dev); u8 *buf = val;
ssize_t count;
spin_lock_irq(&priv->lock); spin_lock_irq(&priv->lock);
for (count = 0; count < size; count++) { for (; bytes; bytes--) {
u8 data = *buf++; u8 data = *buf++;
rp5c01_write(priv, rp5c01_write(priv,
...@@ -216,7 +211,7 @@ static ssize_t rp5c01_nvram_write(struct file *filp, struct kobject *kobj, ...@@ -216,7 +211,7 @@ static ssize_t rp5c01_nvram_write(struct file *filp, struct kobject *kobj,
} }
spin_unlock_irq(&priv->lock); spin_unlock_irq(&priv->lock);
return count; return 0;
} }
static int __init rp5c01_rtc_probe(struct platform_device *dev) static int __init rp5c01_rtc_probe(struct platform_device *dev)
...@@ -225,6 +220,14 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev) ...@@ -225,6 +220,14 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
struct rp5c01_priv *priv; struct rp5c01_priv *priv;
struct rtc_device *rtc; struct rtc_device *rtc;
int error; int error;
struct nvmem_config nvmem_cfg = {
.name = "rp5c01_nvram",
.word_size = 1,
.stride = 1,
.size = RP5C01_MODE,
.reg_read = rp5c01_nvram_read,
.reg_write = rp5c01_nvram_write,
};
res = platform_get_resource(dev, IORESOURCE_MEM, 0); res = platform_get_resource(dev, IORESOURCE_MEM, 0);
if (!res) if (!res)
...@@ -238,13 +241,6 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev) ...@@ -238,13 +241,6 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
if (!priv->regs) if (!priv->regs)
return -ENOMEM; return -ENOMEM;
sysfs_bin_attr_init(&priv->nvram_attr);
priv->nvram_attr.attr.name = "nvram";
priv->nvram_attr.attr.mode = S_IRUGO | S_IWUSR;
priv->nvram_attr.read = rp5c01_nvram_read;
priv->nvram_attr.write = rp5c01_nvram_write;
priv->nvram_attr.size = RP5C01_MODE;
spin_lock_init(&priv->lock); spin_lock_init(&priv->lock);
platform_set_drvdata(dev, priv); platform_set_drvdata(dev, priv);
...@@ -254,35 +250,22 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev) ...@@ -254,35 +250,22 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
return PTR_ERR(rtc); return PTR_ERR(rtc);
rtc->ops = &rp5c01_rtc_ops; rtc->ops = &rp5c01_rtc_ops;
rtc->nvram_old_abi = true;
priv->rtc = rtc; priv->rtc = rtc;
error = sysfs_create_bin_file(&dev->dev.kobj, &priv->nvram_attr); nvmem_cfg.priv = priv;
error = rtc_nvmem_register(rtc, &nvmem_cfg);
if (error) if (error)
return error; return error;
error = rtc_register_device(rtc); return rtc_register_device(rtc);
if (error) {
sysfs_remove_bin_file(&dev->dev.kobj, &priv->nvram_attr);
return error;
}
return 0;
}
static int __exit rp5c01_rtc_remove(struct platform_device *dev)
{
struct rp5c01_priv *priv = platform_get_drvdata(dev);
sysfs_remove_bin_file(&dev->dev.kobj, &priv->nvram_attr);
return 0;
} }
static struct platform_driver rp5c01_rtc_driver = { static struct platform_driver rp5c01_rtc_driver = {
.driver = { .driver = {
.name = "rtc-rp5c01", .name = "rtc-rp5c01",
}, },
.remove = __exit_p(rp5c01_rtc_remove),
}; };
module_platform_driver_probe(rp5c01_rtc_driver, rp5c01_rtc_probe); module_platform_driver_probe(rp5c01_rtc_driver, rp5c01_rtc_probe);
......
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