Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1208189 > unrolled thread
| Started by | Andrew Lunn <andrew@lunn.ch> |
|---|---|
| First post | 2015-08-16 05:10 +0200 |
| Last post | 2015-08-17 11:50 +0200 |
| Articles | 10 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework Andrew Lunn <andrew@lunn.ch> - 2015-08-16 05:10 +0200
Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework Stefan Wahren <stefan.wahren@i2se.com> - 2015-08-16 10:30 +0200
Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework Andrew Lunn <andrew@lunn.ch> - 2015-08-16 15:20 +0200
Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework Stefan Wahren <stefan.wahren@i2se.com> - 2015-08-16 17:40 +0200
Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework Srinivas Kandagatla <srinivas.kandagatla@linaro.org> - 2015-08-17 15:10 +0200
Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework Andrew Lunn <andrew@lunn.ch> - 2015-08-17 15:20 +0200
Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework Srinivas Kandagatla <srinivas.kandagatla@linaro.org> - 2015-08-17 17:00 +0200
Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework Andrew Lunn <andrew@lunn.ch> - 2015-08-17 17:40 +0200
Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework Srinivas Kandagatla <srinivas.kandagatla@linaro.org> - 2015-08-17 17:50 +0200
Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework Srinivas Kandagatla <srinivas.kandagatla@linaro.org> - 2015-08-17 11:50 +0200
| From | Andrew Lunn <andrew@lunn.ch> |
|---|---|
| Date | 2015-08-16 05:10 +0200 |
| Subject | [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework |
| Message-ID | <pXWuC-4lr-3@gated-at.bofh.it> |
Add a read only regmap for accessing the EEPROM, and then use that
with the NVMEM framework.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
drivers/misc/eeprom/at24.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 2d3db81be099..0e80c0c09d4e 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -22,6 +22,8 @@
#include <linux/jiffies.h>
#include <linux/of.h>
#include <linux/i2c.h>
+#include <linux/nvmem-provider.h>
+#include <linux/regmap.h>
#include <linux/platform_data/at24.h>
/*
@@ -69,6 +71,10 @@ struct at24_data {
unsigned write_max;
unsigned num_addresses;
+ struct regmap_config regmap_config;
+ struct nvmem_config nvmem_config;
+ struct nvmem_device *nvmem;
+
/*
* Some chips tie up multiple I2C addresses; dummy devices reserve
* them for us, and we'll use them with SMBus calls.
@@ -471,6 +477,34 @@ static ssize_t at24_macc_write(struct memory_accessor *macc, const char *buf,
/*-------------------------------------------------------------------------*/
+/*
+ * Provide a regmap interface, which is registered with the NVMEM
+ * framework
+*/
+static int at24_regmap_read(void *context, const void *reg, size_t reg_size,
+ void *val, size_t val_size)
+{
+ struct at24_data *at24 = context;
+ off_t offset = *(u32 *)reg;
+
+ return at24_read(at24, val, offset, val_size);
+}
+
+static int at24_regmap_write(void *context, const void *data, size_t count)
+{
+ struct at24_data *at24 = context;
+
+ return at24_write(at24, data, 0, count);
+}
+
+static const struct regmap_bus at24_regmap_bus = {
+ .read = at24_regmap_read,
+ .write = at24_regmap_write,
+ .reg_format_endian_default = REGMAP_ENDIAN_NATIVE,
+};
+
+/*-------------------------------------------------------------------------*/
+
#ifdef CONFIG_OF
static void at24_get_ofdata(struct i2c_client *client,
struct at24_platform_data *chip)
@@ -502,6 +536,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
int err;
unsigned i, num_addresses;
kernel_ulong_t magic;
+ struct regmap *regmap;
if (client->dev.platform_data) {
chip = *(struct at24_platform_data *)client->dev.platform_data;
@@ -644,6 +679,30 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
if (err)
goto err_clients;
+ at24->regmap_config.reg_bits = 32;
+ at24->regmap_config.val_bits = 8;
+ at24->regmap_config.reg_stride = 1;
+ at24->regmap_config.max_register = at24->bin.size - 1;
+
+ regmap = devm_regmap_init(&client->dev, &at24_regmap_bus, at24,
+ &at24->regmap_config);
+ if (IS_ERR(regmap)) {
+ dev_err(&client->dev, "regmap init failed\n");
+ err = PTR_ERR(regmap);
+ goto err_sysfs;
+ }
+
+ at24->nvmem_config.name = dev_name(&client->dev);
+ at24->nvmem_config.dev = &client->dev;
+ at24->nvmem_config.read_only = !writable;
+ at24->nvmem_config.owner = THIS_MODULE;
+
+ at24->nvmem = nvmem_register(&at24->nvmem_config);
+ if (IS_ERR(at24->nvmem)) {
+ err = PTR_ERR(at24->nvmem);
+ goto err_sysfs;
+ }
+
i2c_set_clientdata(client, at24);
dev_info(&client->dev, "%zu byte %s EEPROM, %s, %u bytes/write\n",
@@ -662,6 +721,9 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
return 0;
+err_sysfs:
+ sysfs_remove_bin_file(&client->dev.kobj, &at24->bin);
+
err_clients:
for (i = 1; i < num_addresses; i++)
if (at24->client[i])
@@ -676,6 +738,9 @@ static int at24_remove(struct i2c_client *client)
int i;
at24 = i2c_get_clientdata(client);
+
+ nvmem_unregister(at24->nvmem);
+
sysfs_remove_bin_file(&client->dev.kobj, &at24->bin);
for (i = 1; i < at24->num_addresses; i++)
--
2.5.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Stefan Wahren <stefan.wahren@i2se.com> |
|---|---|
| Date | 2015-08-16 10:30 +0200 |
| Subject | Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework |
| Message-ID | <pY1uh-2ZK-9@gated-at.bofh.it> |
| In reply to | #1208189 |
Hi Andrew,
> Andrew Lunn <andrew@lunn.ch> hat am 16. August 2015 um 04:54 geschrieben:
>
>
> Add a read only regmap for accessing the EEPROM, and then use that
> with the NVMEM framework.
>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
> drivers/misc/eeprom/at24.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 65 insertions(+)
>
> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
> index 2d3db81be099..0e80c0c09d4e 100644
> --- a/drivers/misc/eeprom/at24.c
> +++ b/drivers/misc/eeprom/at24.c
> @@ -22,6 +22,8 @@
> #include <linux/jiffies.h>
> #include <linux/of.h>
> #include <linux/i2c.h>
> +#include <linux/nvmem-provider.h>
> +#include <linux/regmap.h>
shouldn't the dependancies in Kconfig updated (depends on REGMAP) too?
> #include <linux/platform_data/at24.h>
>
> /*
> @@ -69,6 +71,10 @@ struct at24_data {
> unsigned write_max;
> unsigned num_addresses;
>
> + struct regmap_config regmap_config;
> + struct nvmem_config nvmem_config;
> + struct nvmem_device *nvmem;
> +
> /*
> * Some chips tie up multiple I2C addresses; dummy devices reserve
> * them for us, and we'll use them with SMBus calls.
> @@ -471,6 +477,34 @@ static ssize_t at24_macc_write(struct memory_accessor
> *macc, const char *buf,
>
> /*-------------------------------------------------------------------------*/
>
> +/*
> + * Provide a regmap interface, which is registered with the NVMEM
> + * framework
> +*/
> +static int at24_regmap_read(void *context, const void *reg, size_t reg_size,
> + void *val, size_t val_size)
> +{
> + struct at24_data *at24 = context;
> + off_t offset = *(u32 *)reg;
> +
> + return at24_read(at24, val, offset, val_size);
> +}
> +
> +static int at24_regmap_write(void *context, const void *data, size_t count)
> +{
> + struct at24_data *at24 = context;
> +
> + return at24_write(at24, data, 0, count);
Since the patch only provides read only support this function could return 0.
Regards
Stefan
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Andrew Lunn <andrew@lunn.ch> |
|---|---|
| Date | 2015-08-16 15:20 +0200 |
| Subject | Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework |
| Message-ID | <pY60X-1am-21@gated-at.bofh.it> |
| In reply to | #1208209 |
On Sun, Aug 16, 2015 at 10:28:06AM +0200, Stefan Wahren wrote:
> Hi Andrew,
>
> > Andrew Lunn <andrew@lunn.ch> hat am 16. August 2015 um 04:54 geschrieben:
> >
> >
> > Add a read only regmap for accessing the EEPROM, and then use that
> > with the NVMEM framework.
> >
> > Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> > ---
> > drivers/misc/eeprom/at24.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 65 insertions(+)
> >
> > diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
> > index 2d3db81be099..0e80c0c09d4e 100644
> > --- a/drivers/misc/eeprom/at24.c
> > +++ b/drivers/misc/eeprom/at24.c
> > @@ -22,6 +22,8 @@
> > #include <linux/jiffies.h>
> > #include <linux/of.h>
> > #include <linux/i2c.h>
> > +#include <linux/nvmem-provider.h>
> > +#include <linux/regmap.h>
>
> shouldn't the dependancies in Kconfig updated (depends on REGMAP) too?
Hi Stefan
This is why the patch is RFC.
REGMAP has stub implementations for when it is not. NVMEM also has
stub implementations. NVMEM does however select REGMAP. So it should
be possible to compile this driver without NVMEM support. Hopefully
0day will find my git branch and compile it in different ways to see
if i've got this right.
As part of RFC, is this O.K?
Another question which spring to mind is, do we want the eeprom to be
in /sys twice, the old and the new way? Backwards compatibility says
the old must stay. Do we want a way to suppress the new? Or should we
be going as far as refractoring the code into a core library, and two
wrapper drivers, old and new?
> > +static int at24_regmap_write(void *context, const void *data, size_t count)
> > +{
> > + struct at24_data *at24 = context;
> > +
> > + return at24_write(at24, data, 0, count);
>
> Since the patch only provides read only support this function could return 0.
Humm, the comment is out of date. Regmap does not work too well
without a write method. So i ended up implementing it. But it has
hardly been tested, where as i have hammered on read.
Thanks
Andrew
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Stefan Wahren <stefan.wahren@i2se.com> |
|---|---|
| Date | 2015-08-16 17:40 +0200 |
| Subject | Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework |
| Message-ID | <pY8cq-4f1-23@gated-at.bofh.it> |
| In reply to | #1208237 |
Hi Andrew,
> Andrew Lunn <andrew@lunn.ch> hat am 16. August 2015 um 15:11 geschrieben:
>
>
> On Sun, Aug 16, 2015 at 10:28:06AM +0200, Stefan Wahren wrote:
> > Hi Andrew,
> >
> > > Andrew Lunn <andrew@lunn.ch> hat am 16. August 2015 um 04:54 geschrieben:
> > >
> > >
> > > Add a read only regmap for accessing the EEPROM, and then use that
> > > with the NVMEM framework.
> > >
> > > Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> > > ---
> > > drivers/misc/eeprom/at24.c | 65
> > > ++++++++++++++++++++++++++++++++++++++++++++++
> > > 1 file changed, 65 insertions(+)
> > >
> > > diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
> > > index 2d3db81be099..0e80c0c09d4e 100644
> > > --- a/drivers/misc/eeprom/at24.c
> > > +++ b/drivers/misc/eeprom/at24.c
> > > @@ -22,6 +22,8 @@
> > > #include <linux/jiffies.h>
> > > #include <linux/of.h>
> > > #include <linux/i2c.h>
> > > +#include <linux/nvmem-provider.h>
> > > +#include <linux/regmap.h>
> >
> > shouldn't the dependancies in Kconfig updated (depends on REGMAP) too?
>
> Hi Stefan
>
> This is why the patch is RFC.
>
> REGMAP has stub implementations for when it is not. NVMEM also has
> stub implementations. NVMEM does however select REGMAP. So it should
> be possible to compile this driver without NVMEM support. Hopefully
> 0day will find my git branch and compile it in different ways to see
> if i've got this right.
you are right.
>
> As part of RFC, is this O.K?
>
> Another question which spring to mind is, do we want the eeprom to be
> in /sys twice, the old and the new way? Backwards compatibility says
> the old must stay. Do we want a way to suppress the new? Or should we
> be going as far as refractoring the code into a core library, and two
> wrapper drivers, old and new?
I think these are questions for the framework maintainers.
>
> > > +static int at24_regmap_write(void *context, const void *data, size_t
> > > count)
> > > +{
> > > + struct at24_data *at24 = context;
> > > +
> > > + return at24_write(at24, data, 0, count);
> >
> > Since the patch only provides read only support this function could return
> > 0.
>
> Humm, the comment is out of date. Regmap does not work too well
> without a write method. So i ended up implementing it. But it has
> hardly been tested, where as i have hammered on read.
I think you didn't understand my comment. I know the write function is
necessary, but
calling at24_write() instead of simply returning 0 does make no sense to me.
Regards
Stefan
>
> Thanks
> Andrew
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Srinivas Kandagatla <srinivas.kandagatla@linaro.org> |
|---|---|
| Date | 2015-08-17 15:10 +0200 |
| Subject | Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework |
| Message-ID | <pYskO-8di-5@gated-at.bofh.it> |
| In reply to | #1208247 |
+Adding Maxime in the loop On 16/08/15 16:37, Stefan Wahren wrote: >> >Another question which spring to mind is, do we want the eeprom to be >> >in /sys twice, the old and the new way? Backwards compatibility says >> >the old must stay. Do we want a way to suppress the new? Or should we >> >be going as far as refractoring the code into a core library, and two >> >wrapper drivers, old and new? > I think these are questions for the framework maintainers. > One of the reasons for the NVMEM framework is to remove that duplicate code in the every driver. There was no framework/ABI which was guiding such old eeprom sysfs entry in first place, so I dont see an issue in removing it for good. Correct me if am wrong. IMHO, its better to move on with nvmem for good reasons, rather than having two sysfs binary files. --srini -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Andrew Lunn <andrew@lunn.ch> |
|---|---|
| Date | 2015-08-17 15:20 +0200 |
| Subject | Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework |
| Message-ID | <pYsuu-8oB-11@gated-at.bofh.it> |
| In reply to | #1208573 |
On Mon, Aug 17, 2015 at 02:01:24PM +0100, Srinivas Kandagatla wrote:
>
> +Adding Maxime in the loop
>
> On 16/08/15 16:37, Stefan Wahren wrote:
> >>>Another question which spring to mind is, do we want the eeprom to be
> >>>in /sys twice, the old and the new way? Backwards compatibility says
> >>>the old must stay. Do we want a way to suppress the new? Or should we
> >>>be going as far as refractoring the code into a core library, and two
> >>>wrapper drivers, old and new?
> >I think these are questions for the framework maintainers.
> >
> One of the reasons for the NVMEM framework is to remove that
> duplicate code in the every driver. There was no framework/ABI
> which was guiding such old eeprom sysfs entry in first place, so I
> dont see an issue in removing it for good. Correct me if am wrong.
The reason for keeping it is backwards compatibility. Having the
contents of the EEPROM as a file in /sys via this driver is now a part
of the Linux ABI. You cannot argue it is not an ABI, just because
there is no framework. Userspace will be assuming it exists at the
specified location. So we cannot remove it, for existing uses of the
driver.
However, for new uses of this driver, it is O.K. to only have the
NVMEM file.
Andrew
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Srinivas Kandagatla <srinivas.kandagatla@linaro.org> |
|---|---|
| Date | 2015-08-17 17:00 +0200 |
| Subject | Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework |
| Message-ID | <pYu3g-220-17@gated-at.bofh.it> |
| In reply to | #1208584 |
On 17/08/15 14:09, Andrew Lunn wrote: > On Mon, Aug 17, 2015 at 02:01:24PM +0100, Srinivas Kandagatla wrote: >> >> +Adding Maxime in the loop >> >> On 16/08/15 16:37, Stefan Wahren wrote: >>>>> Another question which spring to mind is, do we want the eeprom to be >>>>> in /sys twice, the old and the new way? Backwards compatibility says >>>>> the old must stay. Do we want a way to suppress the new? Or should we >>>>> be going as far as refractoring the code into a core library, and two >>>>> wrapper drivers, old and new? >>> I think these are questions for the framework maintainers. >>> >> One of the reasons for the NVMEM framework is to remove that >> duplicate code in the every driver. There was no framework/ABI >> which was guiding such old eeprom sysfs entry in first place, so I >> dont see an issue in removing it for good. Correct me if am wrong. > > The reason for keeping it is backwards compatibility. Having the > contents of the EEPROM as a file in /sys via this driver is now a part > of the Linux ABI. You cannot argue it is not an ABI, just because > there is no framework. Userspace will be assuming it exists at the > specified location. So we cannot remove it, for existing uses of the > driver. Am Ok as long as someone is happy to maintain it. --srini > > However, for new uses of this driver, it is O.K. to only have the > NVMEM file. > > Andrew > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Andrew Lunn <andrew@lunn.ch> |
|---|---|
| Date | 2015-08-17 17:40 +0200 |
| Subject | Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework |
| Message-ID | <pYuFZ-30K-31@gated-at.bofh.it> |
| In reply to | #1208635 |
On Mon, Aug 17, 2015 at 03:59:23PM +0100, Srinivas Kandagatla wrote:
>
>
> On 17/08/15 14:09, Andrew Lunn wrote:
> >On Mon, Aug 17, 2015 at 02:01:24PM +0100, Srinivas Kandagatla wrote:
> >>
> >>+Adding Maxime in the loop
> >>
> >>On 16/08/15 16:37, Stefan Wahren wrote:
> >>>>>Another question which spring to mind is, do we want the eeprom to be
> >>>>>in /sys twice, the old and the new way? Backwards compatibility says
> >>>>>the old must stay. Do we want a way to suppress the new? Or should we
> >>>>>be going as far as refractoring the code into a core library, and two
> >>>>>wrapper drivers, old and new?
> >>>I think these are questions for the framework maintainers.
> >>>
> >>One of the reasons for the NVMEM framework is to remove that
> >>duplicate code in the every driver. There was no framework/ABI
> >>which was guiding such old eeprom sysfs entry in first place, so I
> >>dont see an issue in removing it for good. Correct me if am wrong.
> >
> >The reason for keeping it is backwards compatibility. Having the
> >contents of the EEPROM as a file in /sys via this driver is now a part
> >of the Linux ABI. You cannot argue it is not an ABI, just because
> >there is no framework. Userspace will be assuming it exists at the
> >specified location. So we cannot remove it, for existing uses of the
> >driver.
> Am Ok as long as someone is happy to maintain it.
Wolfram Sang has been maintaining the AT24 driver since 2008. We need
his ACK to this change, and since this is an i2c driver, he is also
probably the path into mainline for this change.
But we should also look at the bigger picture. The AT25, MAX6875 and
sunxi_sid drivers also have a binary file in /sys. It would be good to
have some sort of plan what to do with these drivers, even if at the
moment only AT24 is under discussion.
Andrew
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Srinivas Kandagatla <srinivas.kandagatla@linaro.org> |
|---|---|
| Date | 2015-08-17 17:50 +0200 |
| Subject | Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework |
| Message-ID | <pYuPF-3cv-43@gated-at.bofh.it> |
| In reply to | #1208653 |
On 17/08/15 16:25, Andrew Lunn wrote: > On Mon, Aug 17, 2015 at 03:59:23PM +0100, Srinivas Kandagatla wrote: >> >> >> On 17/08/15 14:09, Andrew Lunn wrote: >>> On Mon, Aug 17, 2015 at 02:01:24PM +0100, Srinivas Kandagatla wrote: >>>> >>>> +Adding Maxime in the loop >>>> >>>> On 16/08/15 16:37, Stefan Wahren wrote: >>>>>>> Another question which spring to mind is, do we want the eeprom to be >>>>>>> in /sys twice, the old and the new way? Backwards compatibility says >>>>>>> the old must stay. Do we want a way to suppress the new? Or should we >>>>>>> be going as far as refractoring the code into a core library, and two >>>>>>> wrapper drivers, old and new? >>>>> I think these are questions for the framework maintainers. >>>>> >>>> One of the reasons for the NVMEM framework is to remove that >>>> duplicate code in the every driver. There was no framework/ABI >>>> which was guiding such old eeprom sysfs entry in first place, so I >>>> dont see an issue in removing it for good. Correct me if am wrong. >>> >>> The reason for keeping it is backwards compatibility. Having the >>> contents of the EEPROM as a file in /sys via this driver is now a part >>> of the Linux ABI. You cannot argue it is not an ABI, just because >>> there is no framework. Userspace will be assuming it exists at the >>> specified location. So we cannot remove it, for existing uses of the >>> driver. >> Am Ok as long as someone is happy to maintain it. > > Wolfram Sang has been maintaining the AT24 driver since 2008. We need > his ACK to this change, and since this is an i2c driver, he is also > probably the path into mainline for this change. > > But we should also look at the bigger picture. The AT25, MAX6875 and > sunxi_sid drivers also have a binary file in /sys. It would be good to > have some sort of plan what to do with these drivers, even if at the > moment only AT24 is under discussion.# +1 > > Andrew > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Srinivas Kandagatla <srinivas.kandagatla@linaro.org> |
|---|---|
| Date | 2015-08-17 11:50 +0200 |
| Subject | Re: [PATCH RFC] eeprom: at24: extend driver to plug into the NVMEM framework |
| Message-ID | <pYpdg-3yi-27@gated-at.bofh.it> |
| In reply to | #1208189 |
Hi Andrew,
Thanks for the patch, few comments other than Stefan's comments.
On 16/08/15 03:54, Andrew Lunn wrote:
> Add a read only regmap for accessing the EEPROM, and then use that
> with the NVMEM framework.
>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
> drivers/misc/eeprom/at24.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 65 insertions(+)
>
> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
> index 2d3db81be099..0e80c0c09d4e 100644
> --- a/drivers/misc/eeprom/at24.c
> +++ b/drivers/misc/eeprom/at24.c
> @@ -22,6 +22,8 @@
> #include <linux/jiffies.h>
> #include <linux/of.h>
> #include <linux/i2c.h>
> +#include <linux/nvmem-provider.h>
> +#include <linux/regmap.h>
> #include <linux/platform_data/at24.h>
>
> /*
> @@ -69,6 +71,10 @@ struct at24_data {
> unsigned write_max;
> unsigned num_addresses;
>
> + struct regmap_config regmap_config;
> + struct nvmem_config nvmem_config;
> + struct nvmem_device *nvmem;
> +
> /*
> * Some chips tie up multiple I2C addresses; dummy devices reserve
> * them for us, and we'll use them with SMBus calls.
> @@ -471,6 +477,34 @@ static ssize_t at24_macc_write(struct memory_accessor *macc, const char *buf,
>
> /*-------------------------------------------------------------------------*/
>
> +/*
> + * Provide a regmap interface, which is registered with the NVMEM
> + * framework
> +*/
> +static int at24_regmap_read(void *context, const void *reg, size_t reg_size,
> + void *val, size_t val_size)
> +{
> + struct at24_data *at24 = context;
> + off_t offset = *(u32 *)reg;
> +
> + return at24_read(at24, val, offset, val_size);
> +}
> +
> +static int at24_regmap_write(void *context, const void *data, size_t count)
> +{
> + struct at24_data *at24 = context;
> +
> + return at24_write(at24, data, 0, count);
> +}
> +
> +static const struct regmap_bus at24_regmap_bus = {
> + .read = at24_regmap_read,
> + .write = at24_regmap_write,
> + .reg_format_endian_default = REGMAP_ENDIAN_NATIVE,
> +};
> +
> +/*-------------------------------------------------------------------------*/
> +
> #ifdef CONFIG_OF
> static void at24_get_ofdata(struct i2c_client *client,
> struct at24_platform_data *chip)
> @@ -502,6 +536,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
> int err;
> unsigned i, num_addresses;
> kernel_ulong_t magic;
> + struct regmap *regmap;
>
> if (client->dev.platform_data) {
> chip = *(struct at24_platform_data *)client->dev.platform_data;
> @@ -644,6 +679,30 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
> if (err)
> goto err_clients;
>
> + at24->regmap_config.reg_bits = 32;
> + at24->regmap_config.val_bits = 8;
> + at24->regmap_config.reg_stride = 1;
> + at24->regmap_config.max_register = at24->bin.size - 1;
> +
> + regmap = devm_regmap_init(&client->dev, &at24_regmap_bus, at24,
> + &at24->regmap_config);
> + if (IS_ERR(regmap)) {
> + dev_err(&client->dev, "regmap init failed\n");
> + err = PTR_ERR(regmap);
> + goto err_sysfs;
> + }
> +
> + at24->nvmem_config.name = dev_name(&client->dev);
> + at24->nvmem_config.dev = &client->dev;
> + at24->nvmem_config.read_only = !writable;
> + at24->nvmem_config.owner = THIS_MODULE;
> +
> + at24->nvmem = nvmem_register(&at24->nvmem_config);
> + if (IS_ERR(at24->nvmem)) {
> + err = PTR_ERR(at24->nvmem);
> + goto err_sysfs;
> + }
> +
> i2c_set_clientdata(client, at24);
>
> dev_info(&client->dev, "%zu byte %s EEPROM, %s, %u bytes/write\n",
> @@ -662,6 +721,9 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>
> return 0;
>
> +err_sysfs:
> + sysfs_remove_bin_file(&client->dev.kobj, &at24->bin);
> +
?? Not sure Why this code is still needed. Can't we remove it?
Is this the the same binary file which is exposed by nvmem in
/sys/bus/nvmem too?
--srini
> err_clients:
> for (i = 1; i < num_addresses; i++)
> if (at24->client[i])
> @@ -676,6 +738,9 @@ static int at24_remove(struct i2c_client *client)
> int i;
>
> at24 = i2c_get_clientdata(client);
> +
> + nvmem_unregister(at24->nvmem);
> +
> sysfs_remove_bin_file(&client->dev.kobj, &at24->bin);
>
> for (i = 1; i < at24->num_addresses; i++)
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web