* [PATCH 2/5] nvmem: Use already existing dev pointer in nvmem_register_cdev()
2019-08-12 20:19 [PATCH 1/5] nvmem: Use helper variable in nvmem_register_cdev() Andrey Smirnov
@ 2019-08-12 20:19 ` Andrey Smirnov
2019-08-12 20:19 ` [PATCH 3/5] nvmem: Parse partitions information Andrey Smirnov
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Andrey Smirnov @ 2019-08-12 20:19 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
There's already a struct device_d * pointer variable. Use it.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
drivers/nvmem/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 092e3b4f4a..122aac5990 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -97,7 +97,7 @@ static int nvmem_register_cdev(struct nvmem_device *nvmem, const char *name)
cdev->name = xstrdup(alias ?: name);
cdev->ops = &nvmem_chrdev_ops;
- cdev->dev = &nvmem->dev;
+ cdev->dev = dev;
cdev->size = nvmem->size;
return devfs_create(cdev);
--
2.21.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/5] nvmem: Parse partitions information
2019-08-12 20:19 [PATCH 1/5] nvmem: Use helper variable in nvmem_register_cdev() Andrey Smirnov
2019-08-12 20:19 ` [PATCH 2/5] nvmem: Use already existing dev pointer " Andrey Smirnov
@ 2019-08-12 20:19 ` Andrey Smirnov
2019-08-12 20:19 ` [PATCH 4/5] eeprom: at24: Drop at24_cdev_protect() Andrey Smirnov
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Andrey Smirnov @ 2019-08-12 20:19 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Add code to parse partition information that might be specified as a
part of the DT config.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
drivers/nvmem/core.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 122aac5990..25924872ef 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -92,6 +92,7 @@ static int nvmem_register_cdev(struct nvmem_device *nvmem, const char *name)
struct device_d *dev = &nvmem->dev;
struct cdev *cdev = &nvmem->cdev;
const char *alias;
+ int ret;
alias = of_alias_get(dev->device_node);
@@ -100,7 +101,14 @@ static int nvmem_register_cdev(struct nvmem_device *nvmem, const char *name)
cdev->dev = dev;
cdev->size = nvmem->size;
- return devfs_create(cdev);
+ ret = devfs_create(cdev);
+ if (ret)
+ return ret;
+
+ of_parse_partitions(cdev, dev->device_node);
+ of_partitions_register_fixup(cdev);
+
+ return 0;
}
static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
--
2.21.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 4/5] eeprom: at24: Drop at24_cdev_protect()
2019-08-12 20:19 [PATCH 1/5] nvmem: Use helper variable in nvmem_register_cdev() Andrey Smirnov
2019-08-12 20:19 ` [PATCH 2/5] nvmem: Use already existing dev pointer " Andrey Smirnov
2019-08-12 20:19 ` [PATCH 3/5] nvmem: Parse partitions information Andrey Smirnov
@ 2019-08-12 20:19 ` Andrey Smirnov
2019-08-12 20:19 ` [PATCH 5/5] eeprom: at24: Convert the driver to NVMEM Andrey Smirnov
2019-08-16 11:43 ` [PATCH 1/5] nvmem: Use helper variable in nvmem_register_cdev() Sascha Hauer
4 siblings, 0 replies; 8+ messages in thread
From: Andrey Smirnov @ 2019-08-12 20:19 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Instead of exposing a dedictaed .protect() callback, mimic the
behaviour of corresponding driver in Linux and adjust the value of WP
pin in .write() callback as necessary. This is done in order to
convert this driver to NVMEM subsytem.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
drivers/eeprom/at24.c | 37 +++++++++++++++++--------------------
1 file changed, 17 insertions(+), 20 deletions(-)
diff --git a/drivers/eeprom/at24.c b/drivers/eeprom/at24.c
index 1fd4aeaba6..db452c1076 100644
--- a/drivers/eeprom/at24.c
+++ b/drivers/eeprom/at24.c
@@ -317,6 +317,19 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf,
return -ETIMEDOUT;
}
+static void at24_protect(struct at24_data *at24, bool prot)
+{
+ if (gpio_is_valid(at24->wp_gpio)) {
+
+ if (at24->wp_active_low)
+ prot = !prot;
+
+ gpio_set_value(at24->wp_gpio, prot);
+
+ udelay(50);
+ }
+}
+
static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off,
size_t count)
{
@@ -325,6 +338,8 @@ static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off,
if (unlikely(!count))
return count;
+ at24_protect(at24, false);
+
while (count) {
ssize_t status;
@@ -340,6 +355,8 @@ static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off,
retval += status;
}
+ at24_protect(at24, true);
+
return retval;
}
@@ -351,25 +368,6 @@ static ssize_t at24_cdev_write(struct cdev *cdev, const void *buf, size_t count,
return at24_write(at24, buf, off, count);
}
-static int at24_cdev_protect(struct cdev *cdev, size_t count, loff_t offset,
- int prot)
-{
- struct at24_data *at24 = cdev->priv;
-
- if (!gpio_is_valid(at24->wp_gpio))
- return -EOPNOTSUPP;
-
- prot = !!prot;
- if (at24->wp_active_low)
- prot = !prot;
-
- gpio_set_value(at24->wp_gpio, prot);
-
- udelay(50);
-
- return 0;
-}
-
static int at24_probe(struct device_d *dev)
{
struct i2c_client *client = to_i2c_client(dev);
@@ -448,7 +446,6 @@ static int at24_probe(struct device_d *dev)
at24->cdev.dev = dev;
at24->cdev.ops = &at24->fops;
at24->fops.read = at24_cdev_read,
- at24->fops.protect = at24_cdev_protect,
at24->cdev.size = chip.byte_len;
writable = !(chip.flags & AT24_FLAG_READONLY);
--
2.21.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 5/5] eeprom: at24: Convert the driver to NVMEM
2019-08-12 20:19 [PATCH 1/5] nvmem: Use helper variable in nvmem_register_cdev() Andrey Smirnov
` (2 preceding siblings ...)
2019-08-12 20:19 ` [PATCH 4/5] eeprom: at24: Drop at24_cdev_protect() Andrey Smirnov
@ 2019-08-12 20:19 ` Andrey Smirnov
2019-09-05 22:38 ` Antony Pavlov
2019-08-16 11:43 ` [PATCH 1/5] nvmem: Use helper variable in nvmem_register_cdev() Sascha Hauer
4 siblings, 1 reply; 8+ messages in thread
From: Andrey Smirnov @ 2019-08-12 20:19 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Convert AT24 driver to use NVMEM subsystem instead of explicitly
creating a dedicated cdev. This way it becomes possible to access the
contenst of EEPROM via NVMEM API, which could be usefull for things
like MAC-addresses and such.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
drivers/eeprom/at24.c | 48 ++++++++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 21 deletions(-)
diff --git a/drivers/eeprom/at24.c b/drivers/eeprom/at24.c
index db452c1076..568aa02a4c 100644
--- a/drivers/eeprom/at24.c
+++ b/drivers/eeprom/at24.c
@@ -23,6 +23,8 @@
#include <gpio.h>
#include <of_gpio.h>
+#include <linux/nvmem-provider.h>
+
/*
* 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 @@ static ssize_t at24_read(struct at24_data *at24,
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 @@ static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off,
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 @@ static int at24_probe(struct device_d *dev)
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 @@ static int at24_probe(struct device_d *dev)
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 @@ static int at24_probe(struct device_d *dev)
}
}
- 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:
--
2.21.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 5/5] eeprom: at24: Convert the driver to NVMEM
2019-08-12 20:19 ` [PATCH 5/5] eeprom: at24: Convert the driver to NVMEM Andrey Smirnov
@ 2019-09-05 22:38 ` Antony Pavlov
2019-09-06 5:23 ` Andrey Smirnov
0 siblings, 1 reply; 8+ messages in thread
From: Antony Pavlov @ 2019-09-05 22:38 UTC (permalink / raw)
To: Andrey Smirnov; +Cc: barebox
On Mon, 12 Aug 2019 13:19:15 -0700
Andrey Smirnov <andrew.smirnov@gmail.com> wrote:
Hi!
Could you please test this patch with disabled NVMEM?
I see that this patch leads to barebox crash in memory allocation code
if CONFIG_NVMEM is not set.
> Convert AT24 driver to use NVMEM subsystem instead of explicitly
> creating a dedicated cdev. This way it becomes possible to access the
> contenst of EEPROM via NVMEM API, which could be usefull for things
> like MAC-addresses and such.
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
> drivers/eeprom/at24.c | 48 ++++++++++++++++++++++++-------------------
> 1 file changed, 27 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/eeprom/at24.c b/drivers/eeprom/at24.c
> index db452c1076..568aa02a4c 100644
> --- a/drivers/eeprom/at24.c
> +++ b/drivers/eeprom/at24.c
> @@ -23,6 +23,8 @@
> #include <gpio.h>
> #include <of_gpio.h>
>
> +#include <linux/nvmem-provider.h>
> +
> /*
> * 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 @@ static ssize_t at24_read(struct at24_data *at24,
> 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 @@ static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off,
> 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 @@ static int at24_probe(struct device_d *dev)
> 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 @@ static int at24_probe(struct device_d *dev)
> 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 @@ static int at24_probe(struct device_d *dev)
> }
> }
>
> - 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:
> --
> 2.21.0
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
--
Best regards,
Antony Pavlov
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 5/5] eeprom: at24: Convert the driver to NVMEM
2019-09-05 22:38 ` Antony Pavlov
@ 2019-09-06 5:23 ` Andrey Smirnov
0 siblings, 0 replies; 8+ messages in thread
From: Andrey Smirnov @ 2019-09-06 5:23 UTC (permalink / raw)
To: Antony Pavlov; +Cc: Barebox List
On Thu, Sep 5, 2019 at 3:38 PM Antony Pavlov <antonynpavlov@gmail.com> wrote:
>
> On Mon, 12 Aug 2019 13:19:15 -0700
> Andrey Smirnov <andrew.smirnov@gmail.com> wrote:
>
> Hi!
>
> Could you please test this patch with disabled NVMEM?
>
> I see that this patch leads to barebox crash in memory allocation code
> if CONFIG_NVMEM is not set.
>
Hmm, I think driver should just select CONFIG_NVMEM since it seems
pretty pointless without it. Totally missed that in my original patch,
sorry.
Will submit a fix for this shortly.
Thanks,
Andrey Smirnov
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/5] nvmem: Use helper variable in nvmem_register_cdev()
2019-08-12 20:19 [PATCH 1/5] nvmem: Use helper variable in nvmem_register_cdev() Andrey Smirnov
` (3 preceding siblings ...)
2019-08-12 20:19 ` [PATCH 5/5] eeprom: at24: Convert the driver to NVMEM Andrey Smirnov
@ 2019-08-16 11:43 ` Sascha Hauer
4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2019-08-16 11:43 UTC (permalink / raw)
To: Andrey Smirnov; +Cc: barebox
On Mon, Aug 12, 2019 at 01:19:11PM -0700, Andrey Smirnov wrote:
> Add struct cdev * helper variable to nvmem_register_cdev() in order to
> avoid repeating &nvmem->cdev a bunch of times
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
> drivers/nvmem/core.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
Applied, thanks
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread