diff options
author | Vivek Gautam <vivek.gautam@codeaurora.org> | 2017-01-22 18:02:40 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-01-25 05:49:39 -0500 |
commit | fd0c478c0dd800449e2d70025ef742679a16a8de (patch) | |
tree | e86523b9f86717ce44f515b7ed434646eeebd985 | |
parent | 29143268ec7d292ae4531bdf8deb6e55239a0051 (diff) |
nvmem: core: Allow getting nvmem cell with a NULL cell id
The nvmem cell with a NULL cell name/id should be the one
with no accompanying 'nvmem-cell-names' property, and thus
will be the cell at index 0 in the device tree.
So, we default to index 0 and update the cell index only when
nvmem cell name id exists.
Suggested-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Vivek Gautam <vivek.gautam@codeaurora.org>
Reviewed-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/nvmem/core.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 9c0592127d7e..408b521ee520 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c | |||
@@ -747,7 +747,9 @@ static struct nvmem_cell *nvmem_cell_get_from_list(const char *cell_id) | |||
747 | * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id | 747 | * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id |
748 | * | 748 | * |
749 | * @np: Device tree node that uses the nvmem cell. | 749 | * @np: Device tree node that uses the nvmem cell. |
750 | * @name: nvmem cell name from nvmem-cell-names property. | 750 | * @name: nvmem cell name from nvmem-cell-names property, or NULL |
751 | * for the cell at index 0 (the lone cell with no accompanying | ||
752 | * nvmem-cell-names property). | ||
751 | * | 753 | * |
752 | * Return: Will be an ERR_PTR() on error or a valid pointer | 754 | * Return: Will be an ERR_PTR() on error or a valid pointer |
753 | * to a struct nvmem_cell. The nvmem_cell will be freed by the | 755 | * to a struct nvmem_cell. The nvmem_cell will be freed by the |
@@ -760,9 +762,12 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, | |||
760 | struct nvmem_cell *cell; | 762 | struct nvmem_cell *cell; |
761 | struct nvmem_device *nvmem; | 763 | struct nvmem_device *nvmem; |
762 | const __be32 *addr; | 764 | const __be32 *addr; |
763 | int rval, len, index; | 765 | int rval, len; |
766 | int index = 0; | ||
764 | 767 | ||
765 | index = of_property_match_string(np, "nvmem-cell-names", name); | 768 | /* if cell name exists, find index to the name */ |
769 | if (name) | ||
770 | index = of_property_match_string(np, "nvmem-cell-names", name); | ||
766 | 771 | ||
767 | cell_np = of_parse_phandle(np, "nvmem-cells", index); | 772 | cell_np = of_parse_phandle(np, "nvmem-cells", index); |
768 | if (!cell_np) | 773 | if (!cell_np) |