From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: Andrey Smirnov <andrew.smirnov@gmail.com>, linux-kernel@vger.kernel.org
Cc: maxime.ripard@free-electrons.com
Subject: Re: [RESEND RFC 2/3] nvmem: Add 'nvmem-blob' driver
Date: Wed, 2 Mar 2016 13:58:32 +0000 [thread overview]
Message-ID: <56D6F188.2090406@linaro.org> (raw)
In-Reply-To: <1456851552-15913-3-git-send-email-andrew.smirnov@gmail.com>
On 01/03/16 16:59, Andrey Smirnov wrote:
> Add 'nvmem-blob' driver, which allows to access device tree embedded
> data via NVMEM subsystem API.
Patch itself looks simple. Before we review it further could you provide
more details on the exact usecase or some background of this.
Incase you resend the patches, could you split the dt bindings into
separate patch and add dt guys in to the loop, They would have different
opinion on adding dummy stuff into DT itself.
thanks,
srini
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
> Documentation/devicetree/bindings/nvmem/blob.txt | 35 ++++++
> drivers/nvmem/Makefile | 1 +
> drivers/nvmem/blob.c | 132 +++++++++++++++++++++++
> 3 files changed, 168 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/nvmem/blob.txt
> create mode 100644 drivers/nvmem/blob.c
>
> diff --git a/Documentation/devicetree/bindings/nvmem/blob.txt b/Documentation/devicetree/bindings/nvmem/blob.txt
> new file mode 100644
> index 0000000..b299576
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/nvmem/blob.txt
> @@ -0,0 +1,35 @@
> += Deviece Tree Embedded Blob As NVMEM Device =
> +
> +This binding is designed to provide a way for a developer to reference
> +data, built-in into device tree blob file, as NVMEM provider and acccess
> +certain portions of that data as NVMEM cells using NVMEM consumer API.
> +
> +Required properties:
> +- compatible: should be "nvmem-blob"
> +- data: specifies data contained in nvmem device
> +
> += Data cells =
> +Are child nodes of nvmem-composite, bindings of which as described in
> +bindings/nvmem/nvmem.txt
> +
> +Example:
> +
> + a-blob {
> + compatible = "nvmem-blob";
> + data = [aa bb cc dd ee];
> +
> + cell1: cell@0 {
> + reg = <0 5>;
> + };
> + };
> +
> += Data consumers =
> +Are device nodes which consume nvmem data cells.
> +
> +Example:
> +
> + a-node {
> + ...
> + nvmem-cells = <&cell1>;
> + nvmem-cell-names = "some-data";
> + };
> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
> index 95dde3f..1a1adba 100644
> --- a/drivers/nvmem/Makefile
> +++ b/drivers/nvmem/Makefile
> @@ -18,3 +18,4 @@ obj-$(CONFIG_NVMEM_SUNXI_SID) += nvmem_sunxi_sid.o
> nvmem_sunxi_sid-y := sunxi_sid.o
> obj-$(CONFIG_NVMEM_VF610_OCOTP) += nvmem-vf610-ocotp.o
> nvmem-vf610-ocotp-y := vf610-ocotp.o
> +obj-y += blob.o
> diff --git a/drivers/nvmem/blob.c b/drivers/nvmem/blob.c
> new file mode 100644
> index 0000000..3f2296b
> --- /dev/null
> +++ b/drivers/nvmem/blob.c
> @@ -0,0 +1,132 @@
> +#define DEBUG 1
> +
> +#include <linux/device.h>
> +#include <linux/io.h>
> +#include <linux/module.h>
> +#include <linux/nvmem-provider.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +#include <linux/slab.h>
> +
> +struct nvmem_blob {
> + const u8 *data;
> + size_t data_size;
> +};
> +
> +static int nvmem_blob_write(void *context, const void *data,
> + size_t count)
> +{
> + return -ENOTSUPP;
> +}
> +
> +static int nvmem_blob_read(void *context,
> + const void *reg, size_t reg_size,
> + void *val, size_t val_size)
> +{
> + struct nvmem_blob *nblob = context;
> + const unsigned int offset = *(u32 *)reg;
> +
> + memcpy(val, nblob->data + offset,
> + min(val_size, nblob->data_size - offset));
> + return 0;
> +}
> +
> +static const struct regmap_bus nvmem_blob_regmap_bus = {
> + .write = nvmem_blob_write,
> + .read = nvmem_blob_read,
> +};
> +
> +
> +static int nvmem_blob_validate_dt(struct device_node *np)
> +{
> + return 0;
> +}
> +
> +static int nvmem_blob_probe(struct platform_device *pdev)
> +{
> + int ret;
> + struct device *dev = &pdev->dev;
> + struct device_node *np = dev->of_node;
> + struct regmap *map;
> + struct nvmem_device *nvmem;
> + struct nvmem_blob *nblob;
> + struct property *pp;
> + struct nvmem_config nv_cnf = {0};
> + struct regmap_config rm_cnf = {0};
> +
> + ret = nvmem_blob_validate_dt(np);
> + if (ret < 0) {
> + dev_dbg(dev, "Device tree validation failed\n");
> + return ret;
> + }
> +
> + nblob = devm_kzalloc(dev, sizeof(*nblob), GFP_KERNEL);
> + if (!nblob) {
> + dev_dbg(dev, "Not enough memory to allocate a blob\n");
> + return -ENOMEM;
> + }
> +
> + pp = of_find_property(np, "data", NULL);
> + BUG_ON(!pp);
> +
> + nblob->data = pp->value;
> + nblob->data_size = pp->length;
> +
> + rm_cnf.reg_bits = 32;
> + rm_cnf.val_bits = 8;
> + rm_cnf.reg_stride = 1;
> + rm_cnf.name = "nvmem-blob";
> + rm_cnf.max_register = nblob->data_size - 1;
> +
> + map = devm_regmap_init(dev,
> + &nvmem_blob_regmap_bus,
> + nblob,
> + &rm_cnf);
> + if (IS_ERR(map)) {
> + dev_dbg(dev, "Failed to initilize regmap\n");
> + return PTR_ERR(map);
> + }
> +
> + nv_cnf.name = "nvmem-blob";
> + nv_cnf.read_only = true;
> + nv_cnf.dev = dev;
> + nv_cnf.owner = THIS_MODULE;
> +
> + nvmem = nvmem_register(&nv_cnf);
> + if (IS_ERR(nvmem)) {
> + dev_dbg(dev, "Filed to register nvmem device\n");
> + return PTR_ERR(nvmem);
> + }
> +
> + platform_set_drvdata(pdev, nblob);
> + return 0;
> +}
> +
> +static int nvmem_blob_remove(struct platform_device *pdev)
> +{
> + struct nvmem_device *nvmem = platform_get_drvdata(pdev);
> +
> + return nvmem_unregister(nvmem);
> +}
> +
> +static const struct of_device_id nvmem_blob_dt_ids[] = {
> + { .compatible = "nvmem-blob", },
> + { },
> +};
> +MODULE_DEVICE_TABLE(of, nvmem_blob_dt_ids);
> +
> +static struct platform_driver nvmem_blob_driver = {
> + .probe = nvmem_blob_probe,
> + .remove = nvmem_blob_remove,
> + .driver = {
> + .name = "nvmem-blob",
> + .of_match_table = nvmem_blob_dt_ids,
> + },
> +};
> +module_platform_driver(nvmem_blob_driver);
> +
> +MODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>");
> +MODULE_DESCRIPTION("FIXME");
> +MODULE_LICENSE("GPL v2");
>
next prev parent reply other threads:[~2016-03-02 13:58 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-01 16:59 [RESEND RFC 0/3] Proposed extensions for NVMEM Andrey Smirnov
2016-03-01 16:59 ` [RESEND RFC 1/3] nvmem: Add 'of_nvmem_cell_from_device_node()' Andrey Smirnov
2016-03-02 13:58 ` Srinivas Kandagatla
2016-03-02 18:11 ` Andrey Smirnov
2016-03-01 16:59 ` [RESEND RFC 2/3] nvmem: Add 'nvmem-blob' driver Andrey Smirnov
2016-03-02 13:58 ` Srinivas Kandagatla [this message]
2016-03-02 17:21 ` Andrey Smirnov
2016-03-07 8:18 ` Maxime Ripard
2016-03-08 4:07 ` Andrey Smirnov
2016-03-08 22:28 ` Maxime Ripard
2016-03-08 22:46 ` Andrey Smirnov
2016-03-08 23:24 ` Trent Piepho
2016-03-09 10:13 ` Maxime Ripard
2016-03-09 19:50 ` Trent Piepho
2016-03-09 9:58 ` Maxime Ripard
2016-03-09 17:04 ` Andrey Smirnov
2016-03-09 7:59 ` Sascha Hauer
2016-03-01 16:59 ` [RESEND RFC 3/3] nvmem: Add 'nvmem-composite' driver Andrey Smirnov
2016-03-02 13:59 ` Srinivas Kandagatla
2016-03-02 18:33 ` Andrey Smirnov
2016-03-17 11:26 ` Srinivas Kandagatla
2016-03-21 16:12 ` Andrey Smirnov
2016-03-21 16:56 ` Srinivas Kandagatla
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56D6F188.2090406@linaro.org \
--to=srinivas.kandagatla@linaro.org \
--cc=andrew.smirnov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maxime.ripard@free-electrons.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).