Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nvmem: imx-ocotp: add support for post processing

Add .cell_post_process callback for imx-ocotp to deal with MAC address,
since MAC address need to be reversed byte for some i.MX SoCs.

Tested-by: Joakim Zhang <qiangqing.zhang@nxp.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20211013131957.30271-4-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Srinivas Kandagatla and committed by
Greg Kroah-Hartman
d0221a78 5008062f

+25
+25
drivers/nvmem/imx-ocotp.c
··· 97 97 unsigned int bank_address_words; 98 98 void (*set_timing)(struct ocotp_priv *priv); 99 99 struct ocotp_ctrl_reg ctrl; 100 + bool reverse_mac_address; 100 101 }; 101 102 102 103 static int imx_ocotp_wait_for_busy(struct ocotp_priv *priv, u32 flags) ··· 220 219 kfree(p); 221 220 222 221 return ret; 222 + } 223 + 224 + static int imx_ocotp_cell_pp(void *context, const char *id, unsigned int offset, 225 + void *data, size_t bytes) 226 + { 227 + struct ocotp_priv *priv = context; 228 + 229 + /* Deal with some post processing of nvmem cell data */ 230 + if (id && !strcmp(id, "mac-address")) { 231 + if (priv->params->reverse_mac_address) { 232 + u8 *buf = data; 233 + int i; 234 + 235 + for (i = 0; i < bytes/2; i++) 236 + swap(buf[i], buf[bytes - i - 1]); 237 + } 238 + } 239 + 240 + return 0; 223 241 } 224 242 225 243 static void imx_ocotp_set_imx6_timing(struct ocotp_priv *priv) ··· 488 468 .stride = 1, 489 469 .reg_read = imx_ocotp_read, 490 470 .reg_write = imx_ocotp_write, 471 + .cell_post_process = imx_ocotp_cell_pp, 491 472 }; 492 473 493 474 static const struct ocotp_params imx6q_params = { ··· 551 530 .bank_address_words = 0, 552 531 .set_timing = imx_ocotp_set_imx6_timing, 553 532 .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT, 533 + .reverse_mac_address = true, 554 534 }; 555 535 556 536 static const struct ocotp_params imx8mm_params = { ··· 559 537 .bank_address_words = 0, 560 538 .set_timing = imx_ocotp_set_imx6_timing, 561 539 .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT, 540 + .reverse_mac_address = true, 562 541 }; 563 542 564 543 static const struct ocotp_params imx8mn_params = { ··· 567 544 .bank_address_words = 0, 568 545 .set_timing = imx_ocotp_set_imx6_timing, 569 546 .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT, 547 + .reverse_mac_address = true, 570 548 }; 571 549 572 550 static const struct ocotp_params imx8mp_params = { ··· 575 551 .bank_address_words = 0, 576 552 .set_timing = imx_ocotp_set_imx6_timing, 577 553 .ctrl = IMX_OCOTP_BM_CTRL_8MP, 554 + .reverse_mac_address = true, 578 555 }; 579 556 580 557 static const struct of_device_id imx_ocotp_dt_ids[] = {