35b15776fb7e66193fd0bce8bcab37f67e2badc8
[openwrt/staging/blogic.git] /
1 From 2cc3b37f5b6df8189d55d0e812d9658ce256dfec Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Fri, 20 Oct 2023 11:55:41 +0100
4 Subject: [PATCH] nvmem: add explicit config option to read old syntax fixed OF
5 cells
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 Binding for fixed NVMEM cells defined directly as NVMEM device subnodes
11 has been deprecated. It has been replaced by the "fixed-layout" NVMEM
12 layout binding.
13
14 New syntax is meant to be clearer and should help avoiding imprecise
15 bindings.
16
17 NVMEM subsystem already supports the new binding. It should be a good
18 idea to limit support for old syntax to existing drivers that actually
19 support & use it (we can't break backward compatibility!). That way we
20 additionally encourage new bindings & drivers to ignore deprecated
21 binding.
22
23 It wasn't clear (to me) if rtc and w1 code actually uses old syntax
24 fixed cells. I enabled them to don't risk any breakage.
25
26 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
27 [for meson-{efuse,mx-efuse}.c]
28 Acked-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
29 [for mtk-efuse.c, nvmem/core.c, nvmem-provider.h]
30 Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
31 [MT8192, MT8195 Chromebooks]
32 Tested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
33 [for microchip-otpc.c]
34 Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>
35 [SAMA7G5-EK]
36 Tested-by: Claudiu Beznea <claudiu.beznea@microchip.com>
37 Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
38 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
39 Link: https://lore.kernel.org/r/20231020105545.216052-3-srinivas.kandagatla@linaro.org
40 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
41 ---
42 drivers/mtd/mtdcore.c | 2 ++
43 drivers/nvmem/apple-efuses.c | 1 +
44 drivers/nvmem/core.c | 8 +++++---
45 drivers/nvmem/imx-ocotp-scu.c | 1 +
46 drivers/nvmem/imx-ocotp.c | 1 +
47 drivers/nvmem/meson-efuse.c | 1 +
48 drivers/nvmem/meson-mx-efuse.c | 1 +
49 drivers/nvmem/microchip-otpc.c | 1 +
50 drivers/nvmem/mtk-efuse.c | 1 +
51 drivers/nvmem/qcom-spmi-sdam.c | 1 +
52 drivers/nvmem/qfprom.c | 1 +
53 drivers/nvmem/rave-sp-eeprom.c | 1 +
54 drivers/nvmem/rockchip-efuse.c | 1 +
55 drivers/nvmem/sc27xx-efuse.c | 1 +
56 drivers/nvmem/sec-qfprom.c | 1 +
57 drivers/nvmem/sprd-efuse.c | 1 +
58 drivers/nvmem/stm32-romem.c | 1 +
59 drivers/nvmem/sunplus-ocotp.c | 1 +
60 drivers/nvmem/sunxi_sid.c | 1 +
61 drivers/nvmem/uniphier-efuse.c | 1 +
62 drivers/nvmem/zynqmp_nvmem.c | 1 +
63 drivers/rtc/nvmem.c | 1 +
64 drivers/w1/slaves/w1_ds250x.c | 1 +
65 include/linux/nvmem-provider.h | 2 ++
66 24 files changed, 30 insertions(+), 3 deletions(-)
67
68 --- a/drivers/mtd/mtdcore.c
69 +++ b/drivers/mtd/mtdcore.c
70 @@ -523,6 +523,7 @@ static int mtd_nvmem_add(struct mtd_info
71 config.dev = &mtd->dev;
72 config.name = dev_name(&mtd->dev);
73 config.owner = THIS_MODULE;
74 + config.add_legacy_fixed_of_cells = of_device_is_compatible(node, "nvmem-cells");
75 config.reg_read = mtd_nvmem_reg_read;
76 config.size = mtd->size;
77 config.word_size = 1;
78 @@ -891,6 +892,7 @@ static struct nvmem_device *mtd_otp_nvme
79 config.name = compatible;
80 config.id = NVMEM_DEVID_AUTO;
81 config.owner = THIS_MODULE;
82 + config.add_legacy_fixed_of_cells = true;
83 config.type = NVMEM_TYPE_OTP;
84 config.root_only = true;
85 config.ignore_wp = true;
86 --- a/drivers/nvmem/apple-efuses.c
87 +++ b/drivers/nvmem/apple-efuses.c
88 @@ -36,6 +36,7 @@ static int apple_efuses_probe(struct pla
89 struct resource *res;
90 struct nvmem_config config = {
91 .dev = &pdev->dev,
92 + .add_legacy_fixed_of_cells = true,
93 .read_only = true,
94 .reg_read = apple_efuses_read,
95 .stride = sizeof(u32),
96 --- a/drivers/nvmem/core.c
97 +++ b/drivers/nvmem/core.c
98 @@ -998,9 +998,11 @@ struct nvmem_device *nvmem_register(cons
99 if (rval)
100 goto err_remove_cells;
101
102 - rval = nvmem_add_cells_from_legacy_of(nvmem);
103 - if (rval)
104 - goto err_remove_cells;
105 + if (config->add_legacy_fixed_of_cells) {
106 + rval = nvmem_add_cells_from_legacy_of(nvmem);
107 + if (rval)
108 + goto err_remove_cells;
109 + }
110
111 rval = nvmem_add_cells_from_fixed_layout(nvmem);
112 if (rval)
113 --- a/drivers/nvmem/imx-ocotp-scu.c
114 +++ b/drivers/nvmem/imx-ocotp-scu.c
115 @@ -220,6 +220,7 @@ static int imx_scu_ocotp_write(void *con
116
117 static struct nvmem_config imx_scu_ocotp_nvmem_config = {
118 .name = "imx-scu-ocotp",
119 + .add_legacy_fixed_of_cells = true,
120 .read_only = false,
121 .word_size = 4,
122 .stride = 1,
123 --- a/drivers/nvmem/imx-ocotp.c
124 +++ b/drivers/nvmem/imx-ocotp.c
125 @@ -616,6 +616,7 @@ static int imx_ocotp_probe(struct platfo
126 return PTR_ERR(priv->clk);
127
128 priv->params = of_device_get_match_data(&pdev->dev);
129 + imx_ocotp_nvmem_config.add_legacy_fixed_of_cells = true;
130 imx_ocotp_nvmem_config.size = 4 * priv->params->nregs;
131 imx_ocotp_nvmem_config.dev = dev;
132 imx_ocotp_nvmem_config.priv = priv;
133 --- a/drivers/nvmem/meson-efuse.c
134 +++ b/drivers/nvmem/meson-efuse.c
135 @@ -93,6 +93,7 @@ static int meson_efuse_probe(struct plat
136
137 econfig->dev = dev;
138 econfig->name = dev_name(dev);
139 + econfig->add_legacy_fixed_of_cells = true;
140 econfig->stride = 1;
141 econfig->word_size = 1;
142 econfig->reg_read = meson_efuse_read;
143 --- a/drivers/nvmem/meson-mx-efuse.c
144 +++ b/drivers/nvmem/meson-mx-efuse.c
145 @@ -211,6 +211,7 @@ static int meson_mx_efuse_probe(struct p
146 efuse->config.owner = THIS_MODULE;
147 efuse->config.dev = &pdev->dev;
148 efuse->config.priv = efuse;
149 + efuse->config.add_legacy_fixed_of_cells = true;
150 efuse->config.stride = drvdata->word_size;
151 efuse->config.word_size = drvdata->word_size;
152 efuse->config.size = SZ_512;
153 --- a/drivers/nvmem/microchip-otpc.c
154 +++ b/drivers/nvmem/microchip-otpc.c
155 @@ -261,6 +261,7 @@ static int mchp_otpc_probe(struct platfo
156 return ret;
157
158 mchp_nvmem_config.dev = otpc->dev;
159 + mchp_nvmem_config.add_legacy_fixed_of_cells = true;
160 mchp_nvmem_config.size = size;
161 mchp_nvmem_config.priv = otpc;
162 nvmem = devm_nvmem_register(&pdev->dev, &mchp_nvmem_config);
163 --- a/drivers/nvmem/mtk-efuse.c
164 +++ b/drivers/nvmem/mtk-efuse.c
165 @@ -83,6 +83,7 @@ static int mtk_efuse_probe(struct platfo
166 return PTR_ERR(priv->base);
167
168 pdata = device_get_match_data(dev);
169 + econfig.add_legacy_fixed_of_cells = true;
170 econfig.stride = 1;
171 econfig.word_size = 1;
172 econfig.reg_read = mtk_reg_read;
173 --- a/drivers/nvmem/qcom-spmi-sdam.c
174 +++ b/drivers/nvmem/qcom-spmi-sdam.c
175 @@ -142,6 +142,7 @@ static int sdam_probe(struct platform_de
176 sdam->sdam_config.name = "spmi_sdam";
177 sdam->sdam_config.id = NVMEM_DEVID_AUTO;
178 sdam->sdam_config.owner = THIS_MODULE;
179 + sdam->sdam_config.add_legacy_fixed_of_cells = true;
180 sdam->sdam_config.stride = 1;
181 sdam->sdam_config.word_size = 1;
182 sdam->sdam_config.reg_read = sdam_read;
183 --- a/drivers/nvmem/qfprom.c
184 +++ b/drivers/nvmem/qfprom.c
185 @@ -357,6 +357,7 @@ static int qfprom_probe(struct platform_
186 {
187 struct nvmem_config econfig = {
188 .name = "qfprom",
189 + .add_legacy_fixed_of_cells = true,
190 .stride = 1,
191 .word_size = 1,
192 .id = NVMEM_DEVID_AUTO,
193 --- a/drivers/nvmem/rave-sp-eeprom.c
194 +++ b/drivers/nvmem/rave-sp-eeprom.c
195 @@ -328,6 +328,7 @@ static int rave_sp_eeprom_probe(struct p
196 of_property_read_string(np, "zii,eeprom-name", &config.name);
197 config.priv = eeprom;
198 config.dev = dev;
199 + config.add_legacy_fixed_of_cells = true;
200 config.size = size;
201 config.reg_read = rave_sp_eeprom_reg_read;
202 config.reg_write = rave_sp_eeprom_reg_write;
203 --- a/drivers/nvmem/rockchip-efuse.c
204 +++ b/drivers/nvmem/rockchip-efuse.c
205 @@ -205,6 +205,7 @@ static int rockchip_rk3399_efuse_read(vo
206
207 static struct nvmem_config econfig = {
208 .name = "rockchip-efuse",
209 + .add_legacy_fixed_of_cells = true,
210 .stride = 1,
211 .word_size = 1,
212 .read_only = true,
213 --- a/drivers/nvmem/sc27xx-efuse.c
214 +++ b/drivers/nvmem/sc27xx-efuse.c
215 @@ -248,6 +248,7 @@ static int sc27xx_efuse_probe(struct pla
216 econfig.reg_read = sc27xx_efuse_read;
217 econfig.priv = efuse;
218 econfig.dev = &pdev->dev;
219 + econfig.add_legacy_fixed_of_cells = true;
220 nvmem = devm_nvmem_register(&pdev->dev, &econfig);
221 if (IS_ERR(nvmem)) {
222 dev_err(&pdev->dev, "failed to register nvmem config\n");
223 --- a/drivers/nvmem/sec-qfprom.c
224 +++ b/drivers/nvmem/sec-qfprom.c
225 @@ -47,6 +47,7 @@ static int sec_qfprom_probe(struct platf
226 {
227 struct nvmem_config econfig = {
228 .name = "sec-qfprom",
229 + .add_legacy_fixed_of_cells = true,
230 .stride = 1,
231 .word_size = 1,
232 .id = NVMEM_DEVID_AUTO,
233 --- a/drivers/nvmem/sprd-efuse.c
234 +++ b/drivers/nvmem/sprd-efuse.c
235 @@ -408,6 +408,7 @@ static int sprd_efuse_probe(struct platf
236 econfig.read_only = false;
237 econfig.name = "sprd-efuse";
238 econfig.size = efuse->data->blk_nums * SPRD_EFUSE_BLOCK_WIDTH;
239 + econfig.add_legacy_fixed_of_cells = true;
240 econfig.reg_read = sprd_efuse_read;
241 econfig.reg_write = sprd_efuse_write;
242 econfig.priv = efuse;
243 --- a/drivers/nvmem/stm32-romem.c
244 +++ b/drivers/nvmem/stm32-romem.c
245 @@ -207,6 +207,7 @@ static int stm32_romem_probe(struct plat
246 priv->cfg.priv = priv;
247 priv->cfg.owner = THIS_MODULE;
248 priv->cfg.type = NVMEM_TYPE_OTP;
249 + priv->cfg.add_legacy_fixed_of_cells = true;
250
251 priv->lower = 0;
252
253 --- a/drivers/nvmem/sunplus-ocotp.c
254 +++ b/drivers/nvmem/sunplus-ocotp.c
255 @@ -145,6 +145,7 @@ disable_clk:
256
257 static struct nvmem_config sp_ocotp_nvmem_config = {
258 .name = "sp-ocotp",
259 + .add_legacy_fixed_of_cells = true,
260 .read_only = true,
261 .word_size = 1,
262 .size = QAC628_OTP_SIZE,
263 --- a/drivers/nvmem/sunxi_sid.c
264 +++ b/drivers/nvmem/sunxi_sid.c
265 @@ -154,6 +154,7 @@ static int sunxi_sid_probe(struct platfo
266 nvmem_cfg->dev = dev;
267 nvmem_cfg->name = "sunxi-sid";
268 nvmem_cfg->type = NVMEM_TYPE_OTP;
269 + nvmem_cfg->add_legacy_fixed_of_cells = true;
270 nvmem_cfg->read_only = true;
271 nvmem_cfg->size = cfg->size;
272 nvmem_cfg->word_size = 1;
273 --- a/drivers/nvmem/uniphier-efuse.c
274 +++ b/drivers/nvmem/uniphier-efuse.c
275 @@ -52,6 +52,7 @@ static int uniphier_efuse_probe(struct p
276 econfig.size = resource_size(res);
277 econfig.priv = priv;
278 econfig.dev = dev;
279 + econfig.add_legacy_fixed_of_cells = true;
280 nvmem = devm_nvmem_register(dev, &econfig);
281
282 return PTR_ERR_OR_ZERO(nvmem);
283 --- a/drivers/nvmem/zynqmp_nvmem.c
284 +++ b/drivers/nvmem/zynqmp_nvmem.c
285 @@ -58,6 +58,7 @@ static int zynqmp_nvmem_probe(struct pla
286
287 priv->dev = dev;
288 econfig.dev = dev;
289 + econfig.add_legacy_fixed_of_cells = true;
290 econfig.reg_read = zynqmp_nvmem_read;
291 econfig.priv = priv;
292
293 --- a/drivers/rtc/nvmem.c
294 +++ b/drivers/rtc/nvmem.c
295 @@ -21,6 +21,7 @@ int devm_rtc_nvmem_register(struct rtc_d
296
297 nvmem_config->dev = dev;
298 nvmem_config->owner = rtc->owner;
299 + nvmem_config->add_legacy_fixed_of_cells = true;
300 nvmem = devm_nvmem_register(dev, nvmem_config);
301 if (IS_ERR(nvmem))
302 dev_err(dev, "failed to register nvmem device for RTC\n");
303 --- a/drivers/w1/slaves/w1_ds250x.c
304 +++ b/drivers/w1/slaves/w1_ds250x.c
305 @@ -168,6 +168,7 @@ static int w1_eprom_add_slave(struct w1_
306 struct nvmem_device *nvmem;
307 struct nvmem_config nvmem_cfg = {
308 .dev = &sl->dev,
309 + .add_legacy_fixed_of_cells = true,
310 .reg_read = w1_nvmem_read,
311 .type = NVMEM_TYPE_OTP,
312 .read_only = true,
313 --- a/include/linux/nvmem-provider.h
314 +++ b/include/linux/nvmem-provider.h
315 @@ -82,6 +82,7 @@ struct nvmem_cell_info {
316 * @owner: Pointer to exporter module. Used for refcounting.
317 * @cells: Optional array of pre-defined NVMEM cells.
318 * @ncells: Number of elements in cells.
319 + * @add_legacy_fixed_of_cells: Read fixed NVMEM cells from old OF syntax.
320 * @keepout: Optional array of keepout ranges (sorted ascending by start).
321 * @nkeepout: Number of elements in the keepout array.
322 * @type: Type of the nvmem storage
323 @@ -112,6 +113,7 @@ struct nvmem_config {
324 struct module *owner;
325 const struct nvmem_cell_info *cells;
326 int ncells;
327 + bool add_legacy_fixed_of_cells;
328 const struct nvmem_keepout *keepout;
329 unsigned int nkeepout;
330 enum nvmem_type type;