2a5fa618ea6529b376c50fe50141df25150069f0
[openwrt/staging/xback.git] /
1 From 6c56a82d7895a213a43182a5d01a21a906a79847 Mon Sep 17 00:00:00 2001
2 From: Michael Walle <michael@walle.cc>
3 Date: Tue, 4 Apr 2023 18:21:26 +0100
4 Subject: [PATCH] nvmem: imx-ocotp: replace global post processing with layouts
5
6 In preparation of retiring the global post processing hook change this
7 driver to use layouts. The layout will be supplied during registration
8 and will be used to add the post processing hook to all added cells.
9
10 Signed-off-by: Michael Walle <michael@walle.cc>
11 Tested-by: Michael Walle <michael@walle.cc> # on kontron-pitx-imx8m
12 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
13 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
14 Link: https://lore.kernel.org/r/20230404172148.82422-19-srinivas.kandagatla@linaro.org
15 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
16 ---
17 drivers/nvmem/imx-ocotp.c | 30 +++++++++++++++++++-----------
18 1 file changed, 19 insertions(+), 11 deletions(-)
19
20 --- a/drivers/nvmem/imx-ocotp.c
21 +++ b/drivers/nvmem/imx-ocotp.c
22 @@ -225,18 +225,13 @@ read_end:
23 static int imx_ocotp_cell_pp(void *context, const char *id, int index,
24 unsigned int offset, void *data, size_t bytes)
25 {
26 - struct ocotp_priv *priv = context;
27 + u8 *buf = data;
28 + int i;
29
30 /* Deal with some post processing of nvmem cell data */
31 - if (id && !strcmp(id, "mac-address")) {
32 - if (priv->params->reverse_mac_address) {
33 - u8 *buf = data;
34 - int i;
35 -
36 - for (i = 0; i < bytes/2; i++)
37 - swap(buf[i], buf[bytes - i - 1]);
38 - }
39 - }
40 + if (id && !strcmp(id, "mac-address"))
41 + for (i = 0; i < bytes / 2; i++)
42 + swap(buf[i], buf[bytes - i - 1]);
43
44 return 0;
45 }
46 @@ -488,7 +483,6 @@ static struct nvmem_config imx_ocotp_nvm
47 .stride = 1,
48 .reg_read = imx_ocotp_read,
49 .reg_write = imx_ocotp_write,
50 - .cell_post_process = imx_ocotp_cell_pp,
51 };
52
53 static const struct ocotp_params imx6q_params = {
54 @@ -595,6 +589,17 @@ static const struct of_device_id imx_oco
55 };
56 MODULE_DEVICE_TABLE(of, imx_ocotp_dt_ids);
57
58 +static void imx_ocotp_fixup_cell_info(struct nvmem_device *nvmem,
59 + struct nvmem_layout *layout,
60 + struct nvmem_cell_info *cell)
61 +{
62 + cell->read_post_process = imx_ocotp_cell_pp;
63 +}
64 +
65 +struct nvmem_layout imx_ocotp_layout = {
66 + .fixup_cell_info = imx_ocotp_fixup_cell_info,
67 +};
68 +
69 static int imx_ocotp_probe(struct platform_device *pdev)
70 {
71 struct device *dev = &pdev->dev;
72 @@ -619,6 +624,9 @@ static int imx_ocotp_probe(struct platfo
73 imx_ocotp_nvmem_config.size = 4 * priv->params->nregs;
74 imx_ocotp_nvmem_config.dev = dev;
75 imx_ocotp_nvmem_config.priv = priv;
76 + if (priv->params->reverse_mac_address)
77 + imx_ocotp_nvmem_config.layout = &imx_ocotp_layout;
78 +
79 priv->config = &imx_ocotp_nvmem_config;
80
81 clk_prepare_enable(priv->clk);