ee19228270d1018b3cafa5bd9f473d8de37a23fa
[openwrt/staging/svanheule.git] /
1 From d0221a780cbc99fec6c27a98dba2828dc5735c00 Mon Sep 17 00:00:00 2001
2 From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
3 Date: Wed, 13 Oct 2021 14:19:57 +0100
4 Subject: [PATCH] nvmem: imx-ocotp: add support for post processing
5
6 Add .cell_post_process callback for imx-ocotp to deal with MAC address,
7 since MAC address need to be reversed byte for some i.MX SoCs.
8
9 Tested-by: Joakim Zhang <qiangqing.zhang@nxp.com>
10 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
11 Link: https://lore.kernel.org/r/20211013131957.30271-4-srinivas.kandagatla@linaro.org
12 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
13 ---
14 drivers/nvmem/imx-ocotp.c | 25 +++++++++++++++++++++++++
15 1 file changed, 25 insertions(+)
16
17 --- a/drivers/nvmem/imx-ocotp.c
18 +++ b/drivers/nvmem/imx-ocotp.c
19 @@ -97,6 +97,7 @@ struct ocotp_params {
20 unsigned int bank_address_words;
21 void (*set_timing)(struct ocotp_priv *priv);
22 struct ocotp_ctrl_reg ctrl;
23 + bool reverse_mac_address;
24 };
25
26 static int imx_ocotp_wait_for_busy(struct ocotp_priv *priv, u32 flags)
27 @@ -221,6 +222,25 @@ read_end:
28 return ret;
29 }
30
31 +static int imx_ocotp_cell_pp(void *context, const char *id, unsigned int offset,
32 + void *data, size_t bytes)
33 +{
34 + struct ocotp_priv *priv = context;
35 +
36 + /* Deal with some post processing of nvmem cell data */
37 + if (id && !strcmp(id, "mac-address")) {
38 + if (priv->params->reverse_mac_address) {
39 + u8 *buf = data;
40 + int i;
41 +
42 + for (i = 0; i < bytes/2; i++)
43 + swap(buf[i], buf[bytes - i - 1]);
44 + }
45 + }
46 +
47 + return 0;
48 +}
49 +
50 static void imx_ocotp_set_imx6_timing(struct ocotp_priv *priv)
51 {
52 unsigned long clk_rate;
53 @@ -468,6 +488,7 @@ static struct nvmem_config imx_ocotp_nvm
54 .stride = 1,
55 .reg_read = imx_ocotp_read,
56 .reg_write = imx_ocotp_write,
57 + .cell_post_process = imx_ocotp_cell_pp,
58 };
59
60 static const struct ocotp_params imx6q_params = {
61 @@ -530,6 +551,7 @@ static const struct ocotp_params imx8mq_
62 .bank_address_words = 0,
63 .set_timing = imx_ocotp_set_imx6_timing,
64 .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT,
65 + .reverse_mac_address = true,
66 };
67
68 static const struct ocotp_params imx8mm_params = {
69 @@ -537,6 +559,7 @@ static const struct ocotp_params imx8mm_
70 .bank_address_words = 0,
71 .set_timing = imx_ocotp_set_imx6_timing,
72 .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT,
73 + .reverse_mac_address = true,
74 };
75
76 static const struct ocotp_params imx8mn_params = {
77 @@ -544,6 +567,7 @@ static const struct ocotp_params imx8mn_
78 .bank_address_words = 0,
79 .set_timing = imx_ocotp_set_imx6_timing,
80 .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT,
81 + .reverse_mac_address = true,
82 };
83
84 static const struct ocotp_params imx8mp_params = {
85 @@ -551,6 +575,7 @@ static const struct ocotp_params imx8mp_
86 .bank_address_words = 0,
87 .set_timing = imx_ocotp_set_imx6_timing,
88 .ctrl = IMX_OCOTP_BM_CTRL_8MP,
89 + .reverse_mac_address = true,
90 };
91
92 static const struct of_device_id imx_ocotp_dt_ids[] = {