2
0

806-v5.16-0003-nvmem-imx-ocotp-add-support-for-post-processing.patch 2.8 KB

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