Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1286508 > unrolled thread

[PATCH 2/6] nvmem: Add backwards compatibility support for older EEPROM drivers.

Started byAndrew Lunn <andrew@lunn.ch>
First post2015-12-08 15:10 +0100
Last post2015-12-15 11:10 +0100
Articles 6 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 2/6] nvmem: Add backwards compatibility support for older EEPROM drivers. Andrew Lunn <andrew@lunn.ch> - 2015-12-08 15:10 +0100
    Re: [PATCH 2/6] nvmem: Add backwards compatibility support for older  EEPROM drivers. Wolfram Sang <wsa@the-dreams.de> - 2015-12-11 14:10 +0100
      Re: [PATCH 2/6] nvmem: Add backwards compatibility support for older  EEPROM drivers. Andrew Lunn <andrew@lunn.ch> - 2015-12-11 14:50 +0100
        Re: [PATCH 2/6] nvmem: Add backwards compatibility support for older  EEPROM drivers. Wolfram Sang <wsa@the-dreams.de> - 2015-12-12 12:10 +0100
      Re: [PATCH 2/6] nvmem: Add backwards compatibility support for older  EEPROM drivers. Srinivas Kandagatla <srinivas.kandagatla@linaro.org> - 2015-12-15 11:10 +0100
    Re: [PATCH 2/6] nvmem: Add backwards compatibility support for older  EEPROM drivers. Srinivas Kandagatla <srinivas.kandagatla@linaro.org> - 2015-12-15 11:10 +0100

#1286508 — [PATCH 2/6] nvmem: Add backwards compatibility support for older EEPROM drivers.

FromAndrew Lunn <andrew@lunn.ch>
Date2015-12-08 15:10 +0100
Subject[PATCH 2/6] nvmem: Add backwards compatibility support for older EEPROM drivers.
Message-ID<qDr7Q-3nh-13@gated-at.bofh.it>
Older drivers made an 'eeprom' file available in the /sys device
directory. Have the NVMEM core provide this to retain backwards
compatibility.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/nvmem/Kconfig          |  7 ++++
 drivers/nvmem/core.c           | 75 +++++++++++++++++++++++++++++++++++++++---
 include/linux/nvmem-provider.h | 10 ++++++
 3 files changed, 88 insertions(+), 4 deletions(-)

diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index bc4ea585b42e..b4e79ba7d502 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -13,6 +13,13 @@ menuconfig NVMEM
 	  If unsure, say no.
 
 if NVMEM
+config NVMEM_COMPAT
+       bool "Enable /sys compatibility with old eeprom drivers"
+       help
+	 Older EEPROM drivers, such as AT24, AT25, provide access to
+	 the eeprom via a file called "eeprom" in /sys under the
+	 device node. Enabling this option makes the NVMEM core
+	 provide this file to retain backwards compatibility
 
 config NVMEM_IMX_OCOTP
 	tristate "i.MX6 On-Chip OTP Controller support"
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 4ccf03da6467..75a498f5e139 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -38,8 +38,13 @@ struct nvmem_device {
 	int			users;
 	size_t			size;
 	bool			read_only;
+	int			flags;
+	struct bin_attribute	eeprom;
+	struct device		*base_dev;
 };
 
+#define FLAG_COMPAT		BIT(0)
+
 struct nvmem_cell {
 	const char		*name;
 	int			offset;
@@ -62,10 +67,16 @@ static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj,
 				    struct bin_attribute *attr,
 				    char *buf, loff_t pos, size_t count)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct nvmem_device *nvmem = to_nvmem_device(dev);
+	struct device *dev;
+	struct nvmem_device *nvmem;
 	int rc;
 
+	if (attr->private)
+		dev = attr->private;
+	else
+		dev = container_of(kobj, struct device, kobj);
+	nvmem = to_nvmem_device(dev);
+
 	/* Stop the user from reading */
 	if (pos >= nvmem->size)
 		return 0;
@@ -87,10 +98,16 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
 				     struct bin_attribute *attr,
 				     char *buf, loff_t pos, size_t count)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct nvmem_device *nvmem = to_nvmem_device(dev);
+	struct device *dev;
+	struct nvmem_device *nvmem;
 	int rc;
 
+	if (attr->private)
+		dev = attr->private;
+	else
+		dev = container_of(kobj, struct device, kobj);
+	nvmem = to_nvmem_device(dev);
+
 	/* Stop the user from writing */
 	if (pos >= nvmem->size)
 		return 0;
@@ -421,6 +438,53 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 }
 EXPORT_SYMBOL_GPL(nvmem_register);
 
+#if IS_ENABLED(CONFIG_NVMEM_COMPAT)
+/**
+ * nvmem_register_compat() - Register a nvmem device for given nvmem_config.
+ * Also creates an binary entry in /sys/bus/nvmem/devices/dev-name/nvmem and
+ * an eeprom file in the drivers sys directory.
+ *
+ * @config: nvmem device configuration with which nvmem device is created.
+ * @dev: device structure of underlying device
+ *
+ * Return: Will be an ERR_PTR() on error or a valid pointer to nvmem_device
+ * on success.
+ */
+
+struct nvmem_device *nvmem_register_compat(const struct nvmem_config *config,
+					   struct device *base_dev)
+{
+	struct nvmem_device *nvmem;
+	int rval;
+
+	nvmem = nvmem_register(config);
+	if (IS_ERR(nvmem))
+		return nvmem;
+
+	if (nvmem->read_only)
+		nvmem->eeprom = bin_attr_ro_root_nvmem;
+	else
+		nvmem->eeprom = bin_attr_rw_root_nvmem;
+	nvmem->eeprom.attr.name = "eeprom";
+	nvmem->eeprom.size = nvmem->size;
+	nvmem->eeprom.private = &nvmem->dev;
+	nvmem->base_dev = base_dev;
+
+	rval = device_create_bin_file(nvmem->base_dev, &nvmem->eeprom);
+	if (rval) {
+		dev_err(&nvmem->dev,
+			"Failed to create eeprom binary file %d\n", rval);
+		nvmem_unregister(nvmem);
+		return ERR_PTR(rval);
+	}
+
+	nvmem->flags |= FLAG_COMPAT;
+
+	return nvmem;
+}
+EXPORT_SYMBOL_GPL(nvmem_register_compat);
+#endif /* CONFIG_NVMEM_COMPAT */
+
 /**
  * nvmem_unregister() - Unregister previously registered nvmem device
  *
@@ -437,6 +501,9 @@ int nvmem_unregister(struct nvmem_device *nvmem)
 	}
 	mutex_unlock(&nvmem_mutex);
 
+	if (nvmem->flags & FLAG_COMPAT)
+		device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom);
+
 	nvmem_device_remove_all_cells(nvmem);
 	device_del(&nvmem->dev);
 
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index d24fefa0c11d..012030bd4495 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -45,4 +45,14 @@ static inline int nvmem_unregister(struct nvmem_device *nvmem)
 
 #endif /* CONFIG_NVMEM */
 
+#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_NVMEM_COMPAT)
+struct nvmem_device *nvmem_register_compat(const struct nvmem_config *config,
+					   struct device *base_dev);
+#else
+static inline struct nvmem_device *
+nvmem_register_compat(const struct nvmem_config *c, struct device *base_dev)
+{
+	return ERR_PTR(-ENOSYS);
+}
+#endif  /* CONFIG_NVMEM && CONFIG_NVMEM_COMPAT */
 #endif  /* ifndef _LINUX_NVMEM_PROVIDER_H */
-- 
2.6.2

--
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]


#1289551 — Re: [PATCH 2/6] nvmem: Add backwards compatibility support for older EEPROM drivers.

FromWolfram Sang <wsa@the-dreams.de>
Date2015-12-11 14:10 +0100
SubjectRe: [PATCH 2/6] nvmem: Add backwards compatibility support for older EEPROM drivers.
Message-ID<qEvCq-4MO-23@gated-at.bofh.it>
In reply to#1286508

[Multipart message — attachments visible in raw view] — view raw

On Tue, Dec 08, 2015 at 03:05:07PM +0100, Andrew Lunn wrote:
> Older drivers made an 'eeprom' file available in the /sys device
> directory. Have the NVMEM core provide this to retain backwards
> compatibility.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
>  drivers/nvmem/Kconfig          |  7 ++++
>  drivers/nvmem/core.c           | 75 +++++++++++++++++++++++++++++++++++++++---
>  include/linux/nvmem-provider.h | 10 ++++++
>  3 files changed, 88 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index bc4ea585b42e..b4e79ba7d502 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -13,6 +13,13 @@ menuconfig NVMEM
>  	  If unsure, say no.
>  
>  if NVMEM
> +config NVMEM_COMPAT
> +       bool "Enable /sys compatibility with old eeprom drivers"
> +       help
> +	 Older EEPROM drivers, such as AT24, AT25, provide access to
> +	 the eeprom via a file called "eeprom" in /sys under the
> +	 device node. Enabling this option makes the NVMEM core
> +	 provide this file to retain backwards compatibility

I don't like this being a Kconfig option TBH. In most cases, when I read
"retain backwards compatibility" in Kconfig help texts, I keep the
option activated because I don't know the details when exactly it is
safe to disable it. Plus, we have too many Kconfig symbols already.

I suggest to add this flag to nvmem_config and let the old eeprom
drivers always set this flag because they need to provide this file for
some more time, if not forever. New drivers using the nvmem_layer will
probably not want to set this.

BTW how does this NVMEM framework relate to the memory_accessor
framework. Can it be used to replace it? I think we should keep the
number of eeprom interfaces at a sane level, preferably 1 ;)

Also adding Pantelis to CC who also submitted at24 NVMEM support a while
ago.

[toc] | [prev] | [next] | [standalone]


#1289587 — Re: [PATCH 2/6] nvmem: Add backwards compatibility support for older EEPROM drivers.

FromAndrew Lunn <andrew@lunn.ch>
Date2015-12-11 14:50 +0100
SubjectRe: [PATCH 2/6] nvmem: Add backwards compatibility support for older EEPROM drivers.
Message-ID<qEwf8-57t-15@gated-at.bofh.it>
In reply to#1289551
On Fri, Dec 11, 2015 at 02:03:25PM +0100, Wolfram Sang wrote:
> On Tue, Dec 08, 2015 at 03:05:07PM +0100, Andrew Lunn wrote:
> > Older drivers made an 'eeprom' file available in the /sys device
> > directory. Have the NVMEM core provide this to retain backwards
> > compatibility.
> > 
> > Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> > ---
> >  drivers/nvmem/Kconfig          |  7 ++++
> >  drivers/nvmem/core.c           | 75 +++++++++++++++++++++++++++++++++++++++---
> >  include/linux/nvmem-provider.h | 10 ++++++
> >  3 files changed, 88 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> > index bc4ea585b42e..b4e79ba7d502 100644
> > --- a/drivers/nvmem/Kconfig
> > +++ b/drivers/nvmem/Kconfig
> > @@ -13,6 +13,13 @@ menuconfig NVMEM
> >  	  If unsure, say no.
> >  
> >  if NVMEM
> > +config NVMEM_COMPAT
> > +       bool "Enable /sys compatibility with old eeprom drivers"
> > +       help
> > +	 Older EEPROM drivers, such as AT24, AT25, provide access to
> > +	 the eeprom via a file called "eeprom" in /sys under the
> > +	 device node. Enabling this option makes the NVMEM core
> > +	 provide this file to retain backwards compatibility
> 
> I don't like this being a Kconfig option TBH. In most cases, when I read
> "retain backwards compatibility" in Kconfig help texts, I keep the
> option activated because I don't know the details when exactly it is
> safe to disable it. Plus, we have too many Kconfig symbols already.
> 
> I suggest to add this flag to nvmem_config and let the old eeprom
> drivers always set this flag because they need to provide this file for
> some more time, if not forever. New drivers using the nvmem_layer will
> probably not want to set this.

I'm happy to do this, if the NVMEM core maintainers agree.

> BTW how does this NVMEM framework relate to the memory_accessor
> framework. Can it be used to replace it? I think we should keep the
> number of eeprom interfaces at a sane level, preferably 1 ;)

The memory_accessor framework only seems to work with old style
platform data devices, where you can register the callback function to
be used during probe. Because it cannot be used in a DT system, there
are very few users of it, only boards in arch/arm/mach-davinci. They
use it to get their MAC address out of the EEPROM. There are no users
of the AT25 equivalent, which is why i removed it. So this API is
dying on its own.

The NVMEM framework has a similar API for accessing the whole EEPROM,
and a much finer grained API for accessing cells within the EEPROM,
for example saying bytes 16-22 is the MAC address cell.

However, the NVMEM APIs are DT only, so are not a replacement for
memory_accessor. We need to keep memory_accessor until Davinci gets
converted to DT.

> Also adding Pantelis to CC who also submitted at24 NVMEM support a while
> ago.

Thanks for pointing this out, i was not aware of that patch.

       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]


#1290163 — Re: [PATCH 2/6] nvmem: Add backwards compatibility support for older EEPROM drivers.

FromWolfram Sang <wsa@the-dreams.de>
Date2015-12-12 12:10 +0100
SubjectRe: [PATCH 2/6] nvmem: Add backwards compatibility support for older EEPROM drivers.
Message-ID<qEQdQ-1ns-3@gated-at.bofh.it>
In reply to#1289587

[Multipart message — attachments visible in raw view] — view raw

> of the AT25 equivalent, which is why i removed it. So this API is
> dying on its own.

Yes, it is dying; but it is lying around, rotting, and smelling. I'd
like to bury it away.

> However, the NVMEM APIs are DT only, so are not a replacement for
> memory_accessor. We need to keep memory_accessor until Davinci gets
> converted to DT.

I don't expect these boards to be converted to DT. We'll have to figure
something else somewhen.

Thanks,

   Wolfram

[toc] | [prev] | [next] | [standalone]


#1292015 — Re: [PATCH 2/6] nvmem: Add backwards compatibility support for older EEPROM drivers.

FromSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Date2015-12-15 11:10 +0100
SubjectRe: [PATCH 2/6] nvmem: Add backwards compatibility support for older EEPROM drivers.
Message-ID<qFUIr-2DP-41@gated-at.bofh.it>
In reply to#1289551

On 11/12/15 13:03, Wolfram Sang wrote:
> On Tue, Dec 08, 2015 at 03:05:07PM +0100, Andrew Lunn wrote:
>> Older drivers made an 'eeprom' file available in the /sys device
>> directory. Have the NVMEM core provide this to retain backwards
>> compatibility.
>>
>> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
>> ---
>>   drivers/nvmem/Kconfig          |  7 ++++
>>   drivers/nvmem/core.c           | 75 +++++++++++++++++++++++++++++++++++++++---
>>   include/linux/nvmem-provider.h | 10 ++++++
>>   3 files changed, 88 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
>> index bc4ea585b42e..b4e79ba7d502 100644
>> --- a/drivers/nvmem/Kconfig
>> +++ b/drivers/nvmem/Kconfig
>> @@ -13,6 +13,13 @@ menuconfig NVMEM
>>   	  If unsure, say no.
>>
>>   if NVMEM
>> +config NVMEM_COMPAT
>> +       bool "Enable /sys compatibility with old eeprom drivers"
>> +       help
>> +	 Older EEPROM drivers, such as AT24, AT25, provide access to
>> +	 the eeprom via a file called "eeprom" in /sys under the
>> +	 device node. Enabling this option makes the NVMEM core
>> +	 provide this file to retain backwards compatibility
>
> I don't like this being a Kconfig option TBH. In most cases, when I read
> "retain backwards compatibility" in Kconfig help texts, I keep the
> option activated because I don't know the details when exactly it is
> safe to disable it. Plus, we have too many Kconfig symbols already.
>
+1 for not adding new Kconfig here.


> I suggest to add this flag to nvmem_config and let the old eeprom
> drivers always set this flag because they need to provide this file for
> some more time, if not forever. New drivers using the nvmem_layer will
> probably not want to set this.

yes, thats my view to, we should move the flag to nvmem_config and let 
nvmem_register() do what it wants with it, this would avoid adding new 
api too.
>
> BTW how does this NVMEM framework relate to the memory_accessor
> framework. Can it be used to replace it? I think we should keep the
> number of eeprom interfaces at a sane level, preferably 1 ;)

Non DT users can still get access to nvmem by passing nvmem provider 
name to nvmem_device_get(), this should be able to replace the need of 
memory_accessor.

--srini


>
> Also adding Pantelis to CC who also submitted at24 NVMEM support a while
> ago.
>
--
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]


#1292002 — Re: [PATCH 2/6] nvmem: Add backwards compatibility support for older EEPROM drivers.

FromSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Date2015-12-15 11:10 +0100
SubjectRe: [PATCH 2/6] nvmem: Add backwards compatibility support for older EEPROM drivers.
Message-ID<qFUIq-2DP-7@gated-at.bofh.it>
In reply to#1286508
Below are few comments.

On 08/12/15 14:05, Andrew Lunn wrote:
> Older drivers made an 'eeprom' file available in the /sys device
> directory. Have the NVMEM core provide this to retain backwards
> compatibility.
>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
>   drivers/nvmem/Kconfig          |  7 ++++
>   drivers/nvmem/core.c           | 75 +++++++++++++++++++++++++++++++++++++++---
>   include/linux/nvmem-provider.h | 10 ++++++
>   3 files changed, 88 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index bc4ea585b42e..b4e79ba7d502 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -13,6 +13,13 @@ menuconfig NVMEM
>   	  If unsure, say no.
>
>   if NVMEM
> +config NVMEM_COMPAT
> +       bool "Enable /sys compatibility with old eeprom drivers"
> +       help
> +	 Older EEPROM drivers, such as AT24, AT25, provide access to
> +	 the eeprom via a file called "eeprom" in /sys under the
> +	 device node. Enabling this option makes the NVMEM core
> +	 provide this file to retain backwards compatibility
>
Lets get rid of this Kconfig as Wolfram suggested.
We are already adding NVMEM_COMPAT in the nvmem_device structrure lets 
move the flags into the struct nvmem_config and use the nvmem_register 
api as it is.

nvmem_register() can decide what do do with that from there.
I would also prefer a warning if this flag is set, this is to deter any 
new users.

Let me know your thoughts?

>   config NVMEM_IMX_OCOTP
>   	tristate "i.MX6 On-Chip OTP Controller support"
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 4ccf03da6467..75a498f5e139 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -38,8 +38,13 @@ struct nvmem_device {
>   	int			users;
>   	size_t			size;
>   	bool			read_only;
> +	int			flags;
> +	struct bin_attribute	eeprom;
> +	struct device		*base_dev;
>   };
>
> +#define FLAG_COMPAT		BIT(0)
> +
>   struct nvmem_cell {
>   	const char		*name;
>   	int			offset;
> @@ -62,10 +67,16 @@ static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj,
>   				    struct bin_attribute *attr,
>   				    char *buf, loff_t pos, size_t count)
>   {
> -	struct device *dev = container_of(kobj, struct device, kobj);
> -	struct nvmem_device *nvmem = to_nvmem_device(dev);
> +	struct device *dev;
> +	struct nvmem_device *nvmem;
>   	int rc;
>
> +	if (attr->private)
> +		dev = attr->private;
> +	else
> +		dev = container_of(kobj, struct device, kobj);
> +	nvmem = to_nvmem_device(dev);
> +
>   	/* Stop the user from reading */
>   	if (pos >= nvmem->size)
>   		return 0;
> @@ -87,10 +98,16 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
>   				     struct bin_attribute *attr,
>   				     char *buf, loff_t pos, size_t count)
>   {
> -	struct device *dev = container_of(kobj, struct device, kobj);
> -	struct nvmem_device *nvmem = to_nvmem_device(dev);
> +	struct device *dev;
> +	struct nvmem_device *nvmem;
>   	int rc;
>
> +	if (attr->private)
> +		dev = attr->private;
> +	else
> +		dev = container_of(kobj, struct device, kobj);
> +	nvmem = to_nvmem_device(dev);
> +
>   	/* Stop the user from writing */
>   	if (pos >= nvmem->size)
>   		return 0;
> @@ -421,6 +438,53 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
>   }
>   EXPORT_SYMBOL_GPL(nvmem_register);
>
> +#if IS_ENABLED(CONFIG_NVMEM_COMPAT)
> +/**
> + * nvmem_register_compat() - Register a nvmem device for given nvmem_config.
> + * Also creates an binary entry in /sys/bus/nvmem/devices/dev-name/nvmem and
> + * an eeprom file in the drivers sys directory.
> + *
> + * @config: nvmem device configuration with which nvmem device is created.
> + * @dev: device structure of underlying device
> + *
> + * Return: Will be an ERR_PTR() on error or a valid pointer to nvmem_device
> + * on success.
> + */
> +
> +struct nvmem_device *nvmem_register_compat(const struct nvmem_config *config,
> +					   struct device *base_dev)
> +{
Possibly move most of it or some of it a local static function which 
will be called from nvmem_register depending on the NVMEM_FLAG_COMPAT.

> +	struct nvmem_device *nvmem;
> +	int rval;
> +
> +	nvmem = nvmem_register(config);
> +	if (IS_ERR(nvmem))
> +		return nvmem;
> +
> +	if (nvmem->read_only)
> +		nvmem->eeprom = bin_attr_ro_root_nvmem;
> +	else
> +		nvmem->eeprom = bin_attr_rw_root_nvmem;
> +	nvmem->eeprom.attr.name = "eeprom";
> +	nvmem->eeprom.size = nvmem->size;
> +	nvmem->eeprom.private = &nvmem->dev;
> +	nvmem->base_dev = base_dev;
> +
> +	rval = device_create_bin_file(nvmem->base_dev, &nvmem->eeprom);
> +	if (rval) {
> +		dev_err(&nvmem->dev,
> +			"Failed to create eeprom binary file %d\n", rval);
> +		nvmem_unregister(nvmem);
> +		return ERR_PTR(rval);
> +	}
> +
> +	nvmem->flags |= FLAG_COMPAT;
> +
> +	return nvmem;
> +}
> +EXPORT_SYMBOL_GPL(nvmem_register_compat);
> +#endif /* CONFIG_NVMEM_COMPAT */
> +
>   /**
>    * nvmem_unregister() - Unregister previously registered nvmem device
>    *
> @@ -437,6 +501,9 @@ int nvmem_unregister(struct nvmem_device *nvmem)
>   	}
>   	mutex_unlock(&nvmem_mutex);
>
> +	if (nvmem->flags & FLAG_COMPAT)
> +		device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom);
> +
>   	nvmem_device_remove_all_cells(nvmem);
>   	device_del(&nvmem->dev);
>
> diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
> index d24fefa0c11d..012030bd4495 100644
> --- a/include/linux/nvmem-provider.h
> +++ b/include/linux/nvmem-provider.h
> @@ -45,4 +45,14 @@ static inline int nvmem_unregister(struct nvmem_device *nvmem)
>
>   #endif /* CONFIG_NVMEM */
>
> +#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_NVMEM_COMPAT)
> +struct nvmem_device *nvmem_register_compat(const struct nvmem_config *config,
> +					   struct device *base_dev);
> +#else
> +static inline struct nvmem_device *
> +nvmem_register_compat(const struct nvmem_config *c, struct device *base_dev)
> +{
> +	return ERR_PTR(-ENOSYS);
> +}
> +#endif  /* CONFIG_NVMEM && CONFIG_NVMEM_COMPAT */
>   #endif  /* ifndef _LINUX_NVMEM_PROVIDER_H */
>
--
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