rtc: ds1305: use generic nvmem
Instead of adding a binary sysfs attribute from the driver (which suffers from a race condition as the attribute appears after the device), use the core to register an nvmem device. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
This commit is contained in:
@@ -514,56 +514,43 @@ static void msg_init(struct spi_message *m, struct spi_transfer *x,
|
|||||||
spi_message_add_tail(x, m);
|
spi_message_add_tail(x, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static int ds1305_nvram_read(void *priv, unsigned int off, void *buf,
|
||||||
ds1305_nvram_read(struct file *filp, struct kobject *kobj,
|
size_t count)
|
||||||
struct bin_attribute *attr,
|
|
||||||
char *buf, loff_t off, size_t count)
|
|
||||||
{
|
{
|
||||||
struct spi_device *spi;
|
struct ds1305 *ds1305 = priv;
|
||||||
|
struct spi_device *spi = ds1305->spi;
|
||||||
u8 addr;
|
u8 addr;
|
||||||
struct spi_message m;
|
struct spi_message m;
|
||||||
struct spi_transfer x[2];
|
struct spi_transfer x[2];
|
||||||
int status;
|
|
||||||
|
|
||||||
spi = to_spi_device(kobj_to_dev(kobj));
|
|
||||||
|
|
||||||
addr = DS1305_NVRAM + off;
|
addr = DS1305_NVRAM + off;
|
||||||
msg_init(&m, x, &addr, count, NULL, buf);
|
msg_init(&m, x, &addr, count, NULL, buf);
|
||||||
|
|
||||||
status = spi_sync(spi, &m);
|
return spi_sync(spi, &m);
|
||||||
if (status < 0)
|
|
||||||
dev_err(&spi->dev, "nvram %s error %d\n", "read", status);
|
|
||||||
return (status < 0) ? status : count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static int ds1305_nvram_write(void *priv, unsigned int off, void *buf,
|
||||||
ds1305_nvram_write(struct file *filp, struct kobject *kobj,
|
size_t count)
|
||||||
struct bin_attribute *attr,
|
|
||||||
char *buf, loff_t off, size_t count)
|
|
||||||
{
|
{
|
||||||
struct spi_device *spi;
|
struct ds1305 *ds1305 = priv;
|
||||||
|
struct spi_device *spi = ds1305->spi;
|
||||||
u8 addr;
|
u8 addr;
|
||||||
struct spi_message m;
|
struct spi_message m;
|
||||||
struct spi_transfer x[2];
|
struct spi_transfer x[2];
|
||||||
int status;
|
|
||||||
|
|
||||||
spi = to_spi_device(kobj_to_dev(kobj));
|
|
||||||
|
|
||||||
addr = (DS1305_WRITE | DS1305_NVRAM) + off;
|
addr = (DS1305_WRITE | DS1305_NVRAM) + off;
|
||||||
msg_init(&m, x, &addr, count, buf, NULL);
|
msg_init(&m, x, &addr, count, buf, NULL);
|
||||||
|
|
||||||
status = spi_sync(spi, &m);
|
return spi_sync(spi, &m);
|
||||||
if (status < 0)
|
|
||||||
dev_err(&spi->dev, "nvram %s error %d\n", "write", status);
|
|
||||||
return (status < 0) ? status : count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct bin_attribute nvram = {
|
static struct nvmem_config ds1305_nvmem_cfg = {
|
||||||
.attr.name = "nvram",
|
.name = "ds1305_nvram",
|
||||||
.attr.mode = S_IRUGO | S_IWUSR,
|
.word_size = 1,
|
||||||
.read = ds1305_nvram_read,
|
.stride = 1,
|
||||||
.write = ds1305_nvram_write,
|
|
||||||
.size = DS1305_NVRAM_LEN,
|
.size = DS1305_NVRAM_LEN,
|
||||||
|
.reg_read = ds1305_nvram_read,
|
||||||
|
.reg_write = ds1305_nvram_write,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*----------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------*/
|
||||||
@@ -715,6 +702,10 @@ static int ds1305_probe(struct spi_device *spi)
|
|||||||
|
|
||||||
ds1305->rtc->ops = &ds1305_ops;
|
ds1305->rtc->ops = &ds1305_ops;
|
||||||
|
|
||||||
|
ds1305_nvmem_cfg.priv = ds1305;
|
||||||
|
ds1305->rtc->nvmem_config = &ds1305_nvmem_cfg;
|
||||||
|
ds1305->rtc->nvram_old_abi = true;
|
||||||
|
|
||||||
status = rtc_register_device(ds1305->rtc);
|
status = rtc_register_device(ds1305->rtc);
|
||||||
if (status) {
|
if (status) {
|
||||||
dev_dbg(&spi->dev, "register rtc --> %d\n", status);
|
dev_dbg(&spi->dev, "register rtc --> %d\n", status);
|
||||||
@@ -739,12 +730,6 @@ static int ds1305_probe(struct spi_device *spi)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* export NVRAM */
|
|
||||||
status = sysfs_create_bin_file(&spi->dev.kobj, &nvram);
|
|
||||||
if (status < 0) {
|
|
||||||
dev_err(&spi->dev, "register nvram --> %d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -752,8 +737,6 @@ static int ds1305_remove(struct spi_device *spi)
|
|||||||
{
|
{
|
||||||
struct ds1305 *ds1305 = spi_get_drvdata(spi);
|
struct ds1305 *ds1305 = spi_get_drvdata(spi);
|
||||||
|
|
||||||
sysfs_remove_bin_file(&spi->dev.kobj, &nvram);
|
|
||||||
|
|
||||||
/* carefully shut down irq and workqueue, if present */
|
/* carefully shut down irq and workqueue, if present */
|
||||||
if (spi->irq) {
|
if (spi->irq) {
|
||||||
set_bit(FLAG_EXITING, &ds1305->flags);
|
set_bit(FLAG_EXITING, &ds1305->flags);
|
||||||
|
|||||||
Reference in New Issue
Block a user