1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2019 Microchip Technology Inc.
4 * Padmarao Begari <padmarao.begari@microchip.com>
13 DECLARE_GLOBAL_DATA_PTR;
15 #define MPFS_SYSREG_SOFT_RESET ((unsigned int *)0x20002088)
16 #define MPFS_SYS_SERVICE_CR ((unsigned int *)0x37020050)
17 #define MPFS_SYS_SERVICE_SR ((unsigned int *)0x37020054)
18 #define MPFS_SYS_SERVICE_MAILBOX ((unsigned char *)0x37020800)
20 #define PERIPH_RESET_VALUE 0x1e8u
21 #define SERVICE_CR_REQ 0x1u
22 #define SERVICE_SR_BUSY 0x2u
24 static void read_device_serial_number(u8 *response, u8 response_size)
30 response_buf = (u8 *)response;
32 writel(SERVICE_CR_REQ, MPFS_SYS_SERVICE_CR);
34 * REQ bit will remain set till the system controller starts
38 val = readl(MPFS_SYS_SERVICE_CR);
39 } while (SERVICE_CR_REQ == (val & SERVICE_CR_REQ));
42 * Once system controller starts processing the busy bit will
43 * go high and service is completed when busy bit is gone low
46 val = readl(MPFS_SYS_SERVICE_SR);
47 } while (SERVICE_SR_BUSY == (val & SERVICE_SR_BUSY));
49 for (idx = 0; idx < response_size; idx++)
50 response_buf[idx] = readb(MPFS_SYS_SERVICE_MAILBOX + idx);
55 /* For now nothing to do here. */
60 int board_early_init_f(void)
64 /* Reset uart, mmc peripheral */
65 val = readl(MPFS_SYSREG_SOFT_RESET);
66 val = (val & ~(PERIPH_RESET_VALUE));
67 writel(val, MPFS_SYSREG_SOFT_RESET);
72 int board_late_init(void)
77 u8 device_serial_number[16] = { 0 };
78 unsigned char mac_addr[6];
79 char icicle_mac_addr[20];
80 void *blob = (void *)gd->fdt_blob;
82 node = fdt_path_offset(blob, "ethernet0");
84 printf("No ethernet0 path offset\n");
88 ret = fdtdec_get_byte_array(blob, node, "local-mac-address", mac_addr, 6);
90 printf("No local-mac-address property\n");
94 read_device_serial_number(device_serial_number, 16);
96 /* Update MAC address with device serial number */
100 mac_addr[3] = device_serial_number[2];
101 mac_addr[4] = device_serial_number[1];
102 mac_addr[5] = device_serial_number[0];
104 ret = fdt_setprop(blob, node, "local-mac-address", mac_addr, 6);
106 printf("Error setting local-mac-address property\n");
110 icicle_mac_addr[0] = '[';
112 sprintf(&icicle_mac_addr[1], "%pM", mac_addr);
114 icicle_mac_addr[18] = ']';
115 icicle_mac_addr[19] = '\0';
117 for (idx = 0; idx < 20; idx++) {
118 if (icicle_mac_addr[idx] == ':')
119 icicle_mac_addr[idx] = ' ';
121 env_set("icicle_mac_addr", icicle_mac_addr);