Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1292002
| Path | csiph.com!news.mixmin.net!weretis.net!feeder4.news.weretis.net!storethat.news.telefonica.de!telefonica.de!news.panservice.it!bofh.it!news.nic.it!robomod |
|---|---|
| From | Srinivas Kandagatla <srinivas.kandagatla@linaro.org> |
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 2/6] nvmem: Add backwards compatibility support for older EEPROM drivers. |
| Date | Tue, 15 Dec 2015 11:10:02 +0100 |
| Message-ID | <qFUIq-2DP-7@gated-at.bofh.it> (permalink) |
| References | <qDr7P-3nh-3@gated-at.bofh.it> <qDr7Q-3nh-13@gated-at.bofh.it> |
| X-Original-To | Andrew Lunn <andrew@lunn.ch>, GregKH <greg@kroah.com>, maxime.ripard@free-electrons.com, wsa@the-dreams.de, broonie@kernel.org, vz@mleia.com |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=L6AzXPUz9DGnA8sKFUcoLD1vO8IKgze+PAt4JwDvWjk=; b=jGfUOh3GtlCWwOhnU6ANLrNmE69EzvIy8v2vh5Dn1mtq0ihmvLaRKoL14YjcHahvjj dDoCTcI8qscQa18gNskvA+zdm0ic8s31SlT69H7rfz+21RMW3pT1YwV+7y5TLw0n5kq5 BJ5KoBer+GxJLo6lsVkNOCuNRFxed9qnUKTfs= |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=L6AzXPUz9DGnA8sKFUcoLD1vO8IKgze+PAt4JwDvWjk=; b=P6GWGI558cbcaY/iaNkAmy4XoPZl5x7qGY/jiYRA7YMB4ZNrzJEnqh2iMr7ncKnF+D WVRauiMkfoXW7SgTbBAcsaQe6o0r7NQhL9gkx0aa6AA1A0bGJyGXP8veTM+Cwd22eAz1 QS7PPsUfeKhmatgxx6wb0o9NBCxk5Dp3HKInbAzLOeEysiL9KSDAwd0xgLZBdU0I7mbZ VvfaHTEuZTM0hLUYFh6SCx08MINWmCT8rcbiYChWO2K75+56tyl9uF8vc9ToUlnP+xLG 0t9T90PM27ynah3uop8woDfxuKYU/6nLeBcQu/jNDaG2EEtRIV1wnmq8B3NHcYR5umov FQ/g== |
| X-Gm-Message-State | ALoCoQngHhhvfrw+LhVIsyFpM5IzrbUsLpFRQ3U2rdAyRcRwuVq5AjEOG/l1wo7Zu4QiwDxcyHbpFVX87kZVP3qWnqpRpFy70g== |
| X-Received | by 10.194.11.66 with SMTP id o2mr15903434wjb.103.1450173887807; Tue, 15 Dec 2015 02:04:47 -0800 (PST) |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 192 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | afd@ti.com, linux-kernel@vger.kernel.org |
| X-Original-Date | Tue, 15 Dec 2015 10:04:45 +0000 |
| X-Original-Message-ID | <566FE5BD.4040101@linaro.org> |
| X-Original-References | <1449583511-22521-1-git-send-email-andrew@lunn.ch> <1449583511-22521-3-git-send-email-andrew@lunn.ch> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1292002 |
Show key headers only | View raw
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/
Back to linux.kernel | Previous | Next | Find similar | Unroll thread
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
csiph-web