summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Lunn <andrew@lunn.ch>2018-05-11 07:06:56 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-05-14 10:20:48 -0400
commitb3db17e4b864e46ad150ebef69c0e0130a1c5fca (patch)
treeaf1a8b70ae44d4f73aa91c98e33489651cc2a418
parent40fe78a242dd39f36e51907129831500f90d7d5b (diff)
drivers: nvmem: Export nvmem_add_cells()
Not all platforms use device tree. It is useful to be able to add cells to a NVMEM device from code. Export nvmem_add_cells() so making this possible. This required changing the parameters a bit, so that just the cells and the number of cells are passed, not the whole nvmem config structure. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/nvmem/core.c24
-rw-r--r--include/linux/nvmem-provider.h11
2 files changed, 28 insertions, 7 deletions
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index b05aa8e81303..b1c95ef78544 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -353,18 +353,27 @@ static int nvmem_cell_info_to_nvmem_cell(struct nvmem_device *nvmem,
353 return 0; 353 return 0;
354} 354}
355 355
356static int nvmem_add_cells(struct nvmem_device *nvmem, 356/**
357 const struct nvmem_config *cfg) 357 * nvmem_add_cells() - Add cell information to an nvmem device
358 *
359 * @nvmem: nvmem device to add cells to.
360 * @info: nvmem cell info to add to the device
361 * @ncells: number of cells in info
362 *
363 * Return: 0 or negative error code on failure.
364 */
365int nvmem_add_cells(struct nvmem_device *nvmem,
366 const struct nvmem_cell_info *info,
367 int ncells)
358{ 368{
359 struct nvmem_cell **cells; 369 struct nvmem_cell **cells;
360 const struct nvmem_cell_info *info = cfg->cells;
361 int i, rval; 370 int i, rval;
362 371
363 cells = kcalloc(cfg->ncells, sizeof(*cells), GFP_KERNEL); 372 cells = kcalloc(ncells, sizeof(*cells), GFP_KERNEL);
364 if (!cells) 373 if (!cells)
365 return -ENOMEM; 374 return -ENOMEM;
366 375
367 for (i = 0; i < cfg->ncells; i++) { 376 for (i = 0; i < ncells; i++) {
368 cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL); 377 cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL);
369 if (!cells[i]) { 378 if (!cells[i]) {
370 rval = -ENOMEM; 379 rval = -ENOMEM;
@@ -380,7 +389,7 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
380 nvmem_cell_add(cells[i]); 389 nvmem_cell_add(cells[i]);
381 } 390 }
382 391
383 nvmem->ncells = cfg->ncells; 392 nvmem->ncells = ncells;
384 /* remove tmp array */ 393 /* remove tmp array */
385 kfree(cells); 394 kfree(cells);
386 395
@@ -393,6 +402,7 @@ err:
393 402
394 return rval; 403 return rval;
395} 404}
405EXPORT_SYMBOL_GPL(nvmem_add_cells);
396 406
397/* 407/*
398 * nvmem_setup_compat() - Create an additional binary entry in 408 * nvmem_setup_compat() - Create an additional binary entry in
@@ -509,7 +519,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
509 } 519 }
510 520
511 if (config->cells) 521 if (config->cells)
512 nvmem_add_cells(nvmem, config); 522 nvmem_add_cells(nvmem, config->cells, config->ncells);
513 523
514 return nvmem; 524 return nvmem;
515 525
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index f89598bc4e1c..24def6ad09bb 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -77,6 +77,9 @@ struct nvmem_device *devm_nvmem_register(struct device *dev,
77 77
78int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem); 78int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem);
79 79
80int nvmem_add_cells(struct nvmem_device *nvmem,
81 const struct nvmem_cell_info *info,
82 int ncells);
80#else 83#else
81 84
82static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c) 85static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
@@ -99,6 +102,14 @@ static inline int
99devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem) 102devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
100{ 103{
101 return nvmem_unregister(nvmem); 104 return nvmem_unregister(nvmem);
105
106}
107
108static inline int nvmem_add_cells(struct nvmem_device *nvmem,
109 const struct nvmem_cell_info *info,
110 int ncells)
111{
112 return -ENOSYS;
102} 113}
103 114
104#endif /* CONFIG_NVMEM */ 115#endif /* CONFIG_NVMEM */