Pass the OCOTP unique id as hashable information to machine id
generation.

Signed-off-by: Bastian Krause <[email protected]>
---
Changes since (implicit) v1:
  - remove explicit address-of operator for unique_id_parts
---
 drivers/nvmem/ocotp.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/nvmem/ocotp.c b/drivers/nvmem/ocotp.c
index 3f9f162860..d5e9d72a52 100644
--- a/drivers/nvmem/ocotp.c
+++ b/drivers/nvmem/ocotp.c
@@ -29,6 +29,7 @@
 #include <regmap.h>
 #include <linux/clk.h>
 #include <mach/ocotp.h>
+#include <machine_id.h>
 #include <linux/nvmem-provider.h>
 
 /*
@@ -77,6 +78,9 @@
 #define MAC_OFFSET_1                   (0x24 * 4)
 #define MAX_MAC_OFFSETS                        2
 #define MAC_BYTES                      8
+#define UNIQUE_ID_NUM                  2
+/* 0 <= n < UNIQUE_ID_NUM */
+#define UNIQUE_ID(n)                   (OCOTP_WORD(0x410 + 0x10 * (n)) | 
OCOTP_BIT(0) | OCOTP_WIDTH(32))
 
 enum imx_ocotp_format_mac_direction {
        OCOTP_HW_TO_MAC,
@@ -548,6 +552,23 @@ static int imx_ocotp_read(struct device_d *dev, const int 
offset, void *val,
        return regmap_bulk_read(priv->map, offset, val, bytes);
 }
 
+static int imx_ocotp_set_unique_machine_id(void)
+{
+       uint32_t unique_id_parts[UNIQUE_ID_NUM];
+       int ret, i;
+
+       for (i = 0; i < UNIQUE_ID_NUM; i++) {
+               ret = imx_ocotp_read_field(UNIQUE_ID(i), &unique_id_parts[i]);
+               if (ret < 0)
+                       goto out;
+       }
+
+       machine_id_set_hashable(unique_id_parts, sizeof(unique_id_parts));
+
+out:
+       return ret;
+}
+
 static const struct nvmem_bus imx_ocotp_nvmem_bus = {
        .write = imx_ocotp_write,
        .read  = imx_ocotp_read,
@@ -633,6 +654,9 @@ static int imx_ocotp_probe(struct device_d *dev)
                                  ethaddr->value, ethaddr);
        }
 
+       if (IS_ENABLED(CONFIG_MACHINE_ID))
+               imx_ocotp_set_unique_machine_id();
+
        imx_ocotp_init_dt(priv);
 
        dev_add_param_bool(&(priv->dev), "sense_enable", NULL, NULL, 
&priv->sense_enable, priv);
-- 
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to