Skip to content

Commit 1172460

Browse files
miquelraynalgregkh
authored andcommitted
nvmem: Move and rename ->fixup_cell_info()
This hook is meant to be used by any provider and instantiating a layout just for this is useless. Let's instead move this hook to the nvmem device and add it to the config structure to be easily shared by the providers. While at moving this hook, rename it ->fixup_dt_cell_info() to clarify its main intended purpose. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Link: https://lore.kernel.org/r/20231215111536.316972-6-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1b7c298 commit 1172460

File tree

5 files changed

+15
-24
lines changed

5 files changed

+15
-24
lines changed

drivers/nvmem/core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,6 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem)
675675

676676
static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
677677
{
678-
struct nvmem_layout *layout = nvmem->layout;
679678
struct device *dev = &nvmem->dev;
680679
struct device_node *child;
681680
const __be32 *addr;
@@ -705,8 +704,8 @@ static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_nod
705704

706705
info.np = of_node_get(child);
707706

708-
if (layout && layout->fixup_cell_info)
709-
layout->fixup_cell_info(nvmem, layout, &info);
707+
if (nvmem->fixup_dt_cell_info)
708+
nvmem->fixup_dt_cell_info(nvmem, &info);
710709

711710
ret = nvmem_add_one_cell(nvmem, &info);
712711
kfree(info.name);
@@ -895,6 +894,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
895894

896895
kref_init(&nvmem->refcnt);
897896
INIT_LIST_HEAD(&nvmem->cells);
897+
nvmem->fixup_dt_cell_info = config->fixup_dt_cell_info;
898898

899899
nvmem->owner = config->owner;
900900
if (!nvmem->owner && config->dev->driver)

drivers/nvmem/imx-ocotp.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -583,17 +583,12 @@ static const struct of_device_id imx_ocotp_dt_ids[] = {
583583
};
584584
MODULE_DEVICE_TABLE(of, imx_ocotp_dt_ids);
585585

586-
static void imx_ocotp_fixup_cell_info(struct nvmem_device *nvmem,
587-
struct nvmem_layout *layout,
588-
struct nvmem_cell_info *cell)
586+
static void imx_ocotp_fixup_dt_cell_info(struct nvmem_device *nvmem,
587+
struct nvmem_cell_info *cell)
589588
{
590589
cell->read_post_process = imx_ocotp_cell_pp;
591590
}
592591

593-
static struct nvmem_layout imx_ocotp_layout = {
594-
.fixup_cell_info = imx_ocotp_fixup_cell_info,
595-
};
596-
597592
static int imx_ocotp_probe(struct platform_device *pdev)
598593
{
599594
struct device *dev = &pdev->dev;
@@ -619,7 +614,7 @@ static int imx_ocotp_probe(struct platform_device *pdev)
619614
imx_ocotp_nvmem_config.size = 4 * priv->params->nregs;
620615
imx_ocotp_nvmem_config.dev = dev;
621616
imx_ocotp_nvmem_config.priv = priv;
622-
imx_ocotp_nvmem_config.layout = &imx_ocotp_layout;
617+
imx_ocotp_nvmem_config.fixup_dt_cell_info = &imx_ocotp_fixup_dt_cell_info;
623618

624619
priv->config = &imx_ocotp_nvmem_config;
625620

drivers/nvmem/internals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ struct nvmem_device {
2323
struct bin_attribute eeprom;
2424
struct device *base_dev;
2525
struct list_head cells;
26+
void (*fixup_dt_cell_info)(struct nvmem_device *nvmem,
27+
struct nvmem_cell_info *cell);
2628
const struct nvmem_keepout *keepout;
2729
unsigned int nkeepout;
2830
nvmem_reg_read_t reg_read;

drivers/nvmem/mtk-efuse.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ static int mtk_efuse_gpu_speedbin_pp(void *context, const char *id, int index,
4545
return 0;
4646
}
4747

48-
static void mtk_efuse_fixup_cell_info(struct nvmem_device *nvmem,
49-
struct nvmem_layout *layout,
50-
struct nvmem_cell_info *cell)
48+
static void mtk_efuse_fixup_dt_cell_info(struct nvmem_device *nvmem,
49+
struct nvmem_cell_info *cell)
5150
{
5251
size_t sz = strlen(cell->name);
5352

@@ -61,10 +60,6 @@ static void mtk_efuse_fixup_cell_info(struct nvmem_device *nvmem,
6160
cell->read_post_process = mtk_efuse_gpu_speedbin_pp;
6261
}
6362

64-
static struct nvmem_layout mtk_efuse_layout = {
65-
.fixup_cell_info = mtk_efuse_fixup_cell_info,
66-
};
67-
6863
static int mtk_efuse_probe(struct platform_device *pdev)
6964
{
7065
struct device *dev = &pdev->dev;
@@ -91,7 +86,7 @@ static int mtk_efuse_probe(struct platform_device *pdev)
9186
econfig.priv = priv;
9287
econfig.dev = dev;
9388
if (pdata->uses_post_processing)
94-
econfig.layout = &mtk_efuse_layout;
89+
econfig.fixup_dt_cell_info = &mtk_efuse_fixup_dt_cell_info;
9590
nvmem = devm_nvmem_register(dev, &econfig);
9691

9792
return PTR_ERR_OR_ZERO(nvmem);

include/linux/nvmem-provider.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ struct nvmem_cell_info {
8383
* @cells: Optional array of pre-defined NVMEM cells.
8484
* @ncells: Number of elements in cells.
8585
* @add_legacy_fixed_of_cells: Read fixed NVMEM cells from old OF syntax.
86+
* @fixup_dt_cell_info: Will be called before a cell is added. Can be
87+
* used to modify the nvmem_cell_info.
8688
* @keepout: Optional array of keepout ranges (sorted ascending by start).
8789
* @nkeepout: Number of elements in the keepout array.
8890
* @type: Type of the nvmem storage
@@ -113,6 +115,8 @@ struct nvmem_config {
113115
const struct nvmem_cell_info *cells;
114116
int ncells;
115117
bool add_legacy_fixed_of_cells;
118+
void (*fixup_dt_cell_info)(struct nvmem_device *nvmem,
119+
struct nvmem_cell_info *cell);
116120
const struct nvmem_keepout *keepout;
117121
unsigned int nkeepout;
118122
enum nvmem_type type;
@@ -158,8 +162,6 @@ struct nvmem_cell_table {
158162
* @of_match_table: Open firmware match table.
159163
* @add_cells: Called to populate the layout using
160164
* nvmem_add_one_cell().
161-
* @fixup_cell_info: Will be called before a cell is added. Can be
162-
* used to modify the nvmem_cell_info.
163165
* @owner: Pointer to struct module.
164166
* @node: List node.
165167
*
@@ -172,9 +174,6 @@ struct nvmem_layout {
172174
const char *name;
173175
const struct of_device_id *of_match_table;
174176
int (*add_cells)(struct device *dev, struct nvmem_device *nvmem);
175-
void (*fixup_cell_info)(struct nvmem_device *nvmem,
176-
struct nvmem_layout *layout,
177-
struct nvmem_cell_info *cell);
178177

179178
/* private */
180179
struct module *owner;

0 commit comments

Comments
 (0)