Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1346756 > unrolled thread
| Started by | Andrey Smirnov <andrew.smirnov@gmail.com> |
|---|---|
| First post | 2016-03-01 18:00 +0100 |
| Last post | 2016-03-02 19:20 +0100 |
| Articles | 3 — 2 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.
[RESEND RFC 1/3] nvmem: Add 'of_nvmem_cell_from_device_node()' Andrey Smirnov <andrew.smirnov@gmail.com> - 2016-03-01 18:00 +0100
Re: [RESEND RFC 1/3] nvmem: Add 'of_nvmem_cell_from_device_node()' Srinivas Kandagatla <srinivas.kandagatla@linaro.org> - 2016-03-02 15:00 +0100
Re: [RESEND RFC 1/3] nvmem: Add 'of_nvmem_cell_from_device_node()' Andrey Smirnov <andrew.smirnov@gmail.com> - 2016-03-02 19:20 +0100
| From | Andrey Smirnov <andrew.smirnov@gmail.com> |
|---|---|
| Date | 2016-03-01 18:00 +0100 |
| Subject | [RESEND RFC 1/3] nvmem: Add 'of_nvmem_cell_from_device_node()' |
| Message-ID | <r7VOq-3gD-17@gated-at.bofh.it> |
Add 'of_nvmem_cell_from_device_node()' -- a function that allows to
obtain 'struct nvmem_cell' from a device tree node representing it. One
use-case for such a function would be to access nvmem cells with known
phandles.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
drivers/nvmem/core.c | 44 +++++++++++++++++++++++++++++-------------
include/linux/nvmem-consumer.h | 7 +++++++
2 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 6fd4e5a..08550dd 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -601,29 +601,21 @@ static struct nvmem_cell *nvmem_cell_get_from_list(const char *cell_id)
#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
/**
- * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id
+ * of_nvmem_cell_from_device_node() - Get a nvmem cell from device node representation
*
- * @dev node: Device tree node that uses the nvmem cell
- * @id: nvmem cell name from nvmem-cell-names property.
+ * @np node: Device tree node representing NVMEM cell
*
* Return: Will be an ERR_PTR() on error or a valid pointer
* to a struct nvmem_cell. The nvmem_cell will be freed by the
* nvmem_cell_put().
*/
-struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
- const char *name)
+struct nvmem_cell *of_nvmem_cell_from_device_node(struct device_node *cell_np)
{
- struct device_node *cell_np, *nvmem_np;
+ struct device_node *nvmem_np;
struct nvmem_cell *cell;
struct nvmem_device *nvmem;
const __be32 *addr;
- int rval, len, index;
-
- index = of_property_match_string(np, "nvmem-cell-names", name);
-
- cell_np = of_parse_phandle(np, "nvmem-cells", index);
- if (!cell_np)
- return ERR_PTR(-EINVAL);
+ int rval, len;
nvmem_np = of_get_next_parent(cell_np);
if (!nvmem_np)
@@ -682,6 +674,32 @@ err_mem:
return ERR_PTR(rval);
}
+EXPORT_SYMBOL_GPL(of_nvmem_cell_from_device_node);
+
+/**
+ * of_nvmem_cell_get() - Get a nvmem cell from given device node referencing it and cell id
+ *
+ * @dev node: Device tree node that uses the nvmem cell
+ * @id: nvmem cell name from nvmem-cell-names property.
+ *
+ * Return: Will be an ERR_PTR() on error or a valid pointer
+ * to a struct nvmem_cell. The nvmem_cell will be freed by the
+ * nvmem_cell_put().
+ */
+struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
+ const char *name)
+{
+ struct device_node *cell_np;
+ int index;
+
+ index = of_property_match_string(np, "nvmem-cell-names", name);
+
+ cell_np = of_parse_phandle(np, "nvmem-cells", index);
+ if (!cell_np)
+ return ERR_PTR(-EINVAL);
+
+ return of_nvmem_cell_from_device_node(cell_np);
+}
EXPORT_SYMBOL_GPL(of_nvmem_cell_get);
#endif
diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
index 9bb77d3..ff0abb0 100644
--- a/include/linux/nvmem-consumer.h
+++ b/include/linux/nvmem-consumer.h
@@ -136,11 +136,18 @@ static inline int nvmem_device_write(struct nvmem_device *nvmem,
#endif /* CONFIG_NVMEM */
#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
+struct nvmem_cell *of_nvmem_cell_from_device_node(struct device_node *np);
struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
const char *name);
struct nvmem_device *of_nvmem_device_get(struct device_node *np,
const char *name);
#else
+
+static inline struct nvmem_cell *
+of_nvmem_cell_from_device_node(struct device_node *np)
+{
+ return ERR_PTR(-ENOSYS);
+}
static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
const char *name)
{
--
2.5.0
[toc] | [next] | [standalone]
| From | Srinivas Kandagatla <srinivas.kandagatla@linaro.org> |
|---|---|
| Date | 2016-03-02 15:00 +0100 |
| Message-ID | <r8ftM-8on-13@gated-at.bofh.it> |
| In reply to | #1346756 |
Sorry for so late review comments,
On 01/03/16 16:59, Andrey Smirnov wrote:
> Add 'of_nvmem_cell_from_device_node()' -- a function that allows to
> obtain 'struct nvmem_cell' from a device tree node representing it. One
> use-case for such a function would be to access nvmem cells with known
> phandles.
Totally missing the purpose of this new API, Why is of_nvmem_cell_get()
not useful, its exactly doing same thing.
Unless you randomly want to handle phandles without proper dt bindings.
Thanks
srini
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
> drivers/nvmem/core.c | 44 +++++++++++++++++++++++++++++-------------
> include/linux/nvmem-consumer.h | 7 +++++++
> 2 files changed, 38 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 6fd4e5a..08550dd 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -601,29 +601,21 @@ static struct nvmem_cell *nvmem_cell_get_from_list(const char *cell_id)
>
> #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
> /**
> - * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id
> + * of_nvmem_cell_from_device_node() - Get a nvmem cell from device node representation
> *
> - * @dev node: Device tree node that uses the nvmem cell
> - * @id: nvmem cell name from nvmem-cell-names property.
> + * @np node: Device tree node representing NVMEM cell
> *
> * Return: Will be an ERR_PTR() on error or a valid pointer
> * to a struct nvmem_cell. The nvmem_cell will be freed by the
> * nvmem_cell_put().
> */
> -struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
> - const char *name)
> +struct nvmem_cell *of_nvmem_cell_from_device_node(struct device_node *cell_np)
> {
> - struct device_node *cell_np, *nvmem_np;
> + struct device_node *nvmem_np;
> struct nvmem_cell *cell;
> struct nvmem_device *nvmem;
> const __be32 *addr;
> - int rval, len, index;
> -
> - index = of_property_match_string(np, "nvmem-cell-names", name);
> -
> - cell_np = of_parse_phandle(np, "nvmem-cells", index);
> - if (!cell_np)
> - return ERR_PTR(-EINVAL);
> + int rval, len;
>
> nvmem_np = of_get_next_parent(cell_np);
> if (!nvmem_np)
> @@ -682,6 +674,32 @@ err_mem:
>
> return ERR_PTR(rval);
> }
> +EXPORT_SYMBOL_GPL(of_nvmem_cell_from_device_node);
> +
> +/**
> + * of_nvmem_cell_get() - Get a nvmem cell from given device node referencing it and cell id
> + *
> + * @dev node: Device tree node that uses the nvmem cell
> + * @id: nvmem cell name from nvmem-cell-names property.
> + *
> + * Return: Will be an ERR_PTR() on error or a valid pointer
> + * to a struct nvmem_cell. The nvmem_cell will be freed by the
> + * nvmem_cell_put().
> + */
> +struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
> + const char *name)
> +{
> + struct device_node *cell_np;
> + int index;
> +
> + index = of_property_match_string(np, "nvmem-cell-names", name);
> +
> + cell_np = of_parse_phandle(np, "nvmem-cells", index);
> + if (!cell_np)
> + return ERR_PTR(-EINVAL);
> +
> + return of_nvmem_cell_from_device_node(cell_np);
> +}
> EXPORT_SYMBOL_GPL(of_nvmem_cell_get);
> #endif
>
> diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
> index 9bb77d3..ff0abb0 100644
> --- a/include/linux/nvmem-consumer.h
> +++ b/include/linux/nvmem-consumer.h
> @@ -136,11 +136,18 @@ static inline int nvmem_device_write(struct nvmem_device *nvmem,
> #endif /* CONFIG_NVMEM */
>
> #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
> +struct nvmem_cell *of_nvmem_cell_from_device_node(struct device_node *np);
> struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
> const char *name);
> struct nvmem_device *of_nvmem_device_get(struct device_node *np,
> const char *name);
> #else
> +
> +static inline struct nvmem_cell *
> +of_nvmem_cell_from_device_node(struct device_node *np)
> +{
> + return ERR_PTR(-ENOSYS);
> +}
> static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
> const char *name)
> {
>
[toc] | [prev] | [next] | [standalone]
| From | Andrey Smirnov <andrew.smirnov@gmail.com> |
|---|---|
| Date | 2016-03-02 19:20 +0100 |
| Message-ID | <r8jxp-3k9-21@gated-at.bofh.it> |
| In reply to | #1348044 |
On Wed, Mar 2, 2016 at 5:58 AM, Srinivas Kandagatla <srinivas.kandagatla@linaro.org> wrote: > Sorry for so late review comments, > > > On 01/03/16 16:59, Andrey Smirnov wrote: >> >> Add 'of_nvmem_cell_from_device_node()' -- a function that allows to >> obtain 'struct nvmem_cell' from a device tree node representing it. One >> use-case for such a function would be to access nvmem cells with known >> phandles. > > > Totally missing the purpose of this new API, Why is of_nvmem_cell_get() not > useful, its exactly doing same thing. > > Unless you randomly want to handle phandles without proper dt bindings. That about sums up what I was trying to do. In my "composite" driver, the way the layout of the cell is specified is a 3-element tuple containing a phandle to nvmem cell, offset within that cell and the size of the chunk to use, so in order to be able to use that phandle I introduced this function. Andrey
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web