diff --git a/drivers/eeprom/at24.c b/drivers/eeprom/at24.c index db452c1..568aa02 100644 --- a/drivers/eeprom/at24.c +++ b/drivers/eeprom/at24.c @@ -23,6 +23,8 @@ #include #include +#include + /* * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable. * Differences between different vendor product lines (like Atmel AT24C or @@ -50,8 +52,8 @@ struct at24_data { struct at24_platform_data chip; - struct cdev cdev; - struct cdev_operations fops; + struct nvmem_config nvmem_config; + struct nvmem_device *nvmem; u8 *writebuf; unsigned write_max; @@ -242,10 +244,10 @@ return retval; } -static ssize_t at24_cdev_read(struct cdev *cdev, void *buf, size_t count, - loff_t off, ulong flags) +static int at24_nvmem_read(struct device_d *dev, int off, + void *buf, int count) { - struct at24_data *at24 = cdev->priv; + struct at24_data *at24 = dev->parent->priv; return at24_read(at24, buf, off, count); } @@ -360,14 +362,19 @@ return retval; } -static ssize_t at24_cdev_write(struct cdev *cdev, const void *buf, size_t count, - loff_t off, ulong flags) +static int at24_nvmem_write(struct device_d *dev, const int off, + const void *buf, int count) { - struct at24_data *at24 = cdev->priv; + struct at24_data *at24 = dev->parent->priv; return at24_write(at24, buf, off, count); } +static const struct nvmem_bus at24_nvmem_bus = { + .write = at24_nvmem_write, + .read = at24_nvmem_read, +}; + static int at24_probe(struct device_d *dev) { struct i2c_client *client = to_i2c_client(dev); @@ -441,13 +448,6 @@ devname = xasprintf("eeprom%d", err); } - at24->cdev.name = devname; - at24->cdev.priv = at24; - at24->cdev.dev = dev; - at24->cdev.ops = &at24->fops; - at24->fops.read = at24_cdev_read, - at24->cdev.size = chip.byte_len; - writable = !(chip.flags & AT24_FLAG_READONLY); if (of_get_property(dev->device_node, "read-only", NULL)) @@ -456,8 +456,6 @@ if (writable) { unsigned write_max = chip.page_size; - at24->fops.write = at24_cdev_write; - if (write_max > io_limit) write_max = io_limit; at24->write_max = write_max; @@ -494,13 +492,21 @@ } } - err = devfs_create(&at24->cdev); + at24->nvmem_config.name = devname; + at24->nvmem_config.dev = dev; + at24->nvmem_config.read_only = !writable; + at24->nvmem_config.bus = &at24_nvmem_bus; + at24->nvmem_config.stride = 1; + at24->nvmem_config.word_size = 1; + at24->nvmem_config.size = chip.byte_len; + + dev->priv = at24; + + at24->nvmem = nvmem_register(&at24->nvmem_config); + err = PTR_ERR_OR_ZERO(at24->nvmem); if (err) goto err_devfs_create; - of_parse_partitions(&at24->cdev, dev->device_node); - of_partitions_register_fixup(&at24->cdev); - return 0; err_devfs_create: