summaryrefslogtreecommitdiff
path: root/board/microchip/mpfs_icicle/mpfs_icicle.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/microchip/mpfs_icicle/mpfs_icicle.c')
-rw-r--r--board/microchip/mpfs_icicle/mpfs_icicle.c121
1 files changed, 57 insertions, 64 deletions
diff --git a/board/microchip/mpfs_icicle/mpfs_icicle.c b/board/microchip/mpfs_icicle/mpfs_icicle.c
index ba622e38ee5..739a9b6cd76 100644
--- a/board/microchip/mpfs_icicle/mpfs_icicle.c
+++ b/board/microchip/mpfs_icicle/mpfs_icicle.c
@@ -4,52 +4,21 @@
* Padmarao Begari <padmarao.begari@microchip.com>
*/
-#include <dm.h>
-#include <env.h>
-#include <init.h>
#include <asm/global_data.h>
#include <asm/io.h>
#include <asm/sections.h>
+#include <dm.h>
+#include <dm/devres.h>
+#include <env.h>
+#include <linux/compat.h>
+#include <mpfs-mailbox.h>
DECLARE_GLOBAL_DATA_PTR;
-#define MPFS_SYSREG_SOFT_RESET ((unsigned int *)0x20002088)
-#define MPFS_SYS_SERVICE_CR ((unsigned int *)0x37020050)
-#define MPFS_SYS_SERVICE_SR ((unsigned int *)0x37020054)
-#define MPFS_SYS_SERVICE_MAILBOX ((unsigned char *)0x37020800)
-
+#define MPFS_SYSREG_SOFT_RESET ((unsigned int *)0x20002088)
#define PERIPH_RESET_VALUE 0x1e8u
-#define SERVICE_CR_REQ 0x1u
-#define SERVICE_SR_BUSY 0x2u
-static void read_device_serial_number(u8 *response, u8 response_size)
-{
- u8 idx;
- u8 *response_buf;
- unsigned int val;
-
- response_buf = (u8 *)response;
-
- writel(SERVICE_CR_REQ, MPFS_SYS_SERVICE_CR);
- /*
- * REQ bit will remain set till the system controller starts
- * processing.
- */
- do {
- val = readl(MPFS_SYS_SERVICE_CR);
- } while (SERVICE_CR_REQ == (val & SERVICE_CR_REQ));
-
- /*
- * Once system controller starts processing the busy bit will
- * go high and service is completed when busy bit is gone low
- */
- do {
- val = readl(MPFS_SYS_SERVICE_SR);
- } while (SERVICE_SR_BUSY == (val & SERVICE_SR_BUSY));
-
- for (idx = 0; idx < response_size; idx++)
- response_buf[idx] = readb(MPFS_SYS_SERVICE_MAILBOX + idx);
-}
+static unsigned char mac_addr[6];
#if defined(CONFIG_MULTI_DTB_FIT)
int board_fit_config_name_match(const char *name)
@@ -145,13 +114,35 @@ int board_late_init(void)
{
u32 ret;
int node;
- u8 idx;
- u8 device_serial_number[16] = { 0 };
- unsigned char mac_addr[6];
- char icicle_mac_addr[20];
+ u8 device_serial_number[16] = {0};
void *blob = (void *)gd->fdt_blob;
+ struct udevice *dev;
+ struct mpfs_sys_serv *sys_serv_priv;
+
+ ret = uclass_get_device_by_name(UCLASS_MISC, "syscontroller", &dev);
+ if (ret) {
+ debug("%s: system controller setup failed\n", __func__);
+ return ret;
+ }
+
+ sys_serv_priv = kzalloc(sizeof(*sys_serv_priv), GFP_KERNEL);
+ if (!sys_serv_priv)
+ return -ENOMEM;
- read_device_serial_number(device_serial_number, 16);
+ sys_serv_priv->dev = dev;
+
+ sys_serv_priv->sys_controller = mpfs_syscontroller_get(dev);
+ ret = IS_ERR(sys_serv_priv->sys_controller);
+ if (ret) {
+ debug("%s: Failed to register system controller sub device ret=%d\n", __func__, ret);
+ return -ENODEV;
+ }
+
+ ret = mpfs_syscontroller_read_sernum(sys_serv_priv, device_serial_number);
+ if (ret) {
+ printf("Cannot read device serial number\n");
+ return -EINVAL;
+ }
/* Update MAC address with device serial number */
mac_addr[0] = 0x00;
@@ -170,19 +161,6 @@ int board_late_init(void)
}
}
- icicle_mac_addr[0] = '[';
-
- sprintf(&icicle_mac_addr[1], "%pM", mac_addr);
-
- icicle_mac_addr[18] = ']';
- icicle_mac_addr[19] = '\0';
-
- for (idx = 0; idx < 20; idx++) {
- if (icicle_mac_addr[idx] == ':')
- icicle_mac_addr[idx] = ' ';
- }
- env_set("icicle_mac_addr0", icicle_mac_addr);
-
mac_addr[5] = device_serial_number[0] + 1;
node = fdt_path_offset(blob, "/soc/ethernet@20110000");
@@ -194,18 +172,33 @@ int board_late_init(void)
}
}
- icicle_mac_addr[0] = '[';
+ return 0;
+}
- sprintf(&icicle_mac_addr[1], "%pM", mac_addr);
+int ft_board_setup(void *blob, struct bd_info *bd)
+{
+ u32 ret;
+ int node;
- icicle_mac_addr[18] = ']';
- icicle_mac_addr[19] = '\0';
+ node = fdt_path_offset(blob, "/soc/ethernet@20110000");
+ if (node >= 0) {
+ ret = fdt_setprop(blob, node, "local-mac-address", mac_addr, 6);
+ if (ret) {
+ printf("Error setting local-mac-address property for ethernet@20110000\n");
+ return -ENODEV;
+ }
+ }
+
+ mac_addr[5] -= 1;
- for (idx = 0; idx < 20; idx++) {
- if (icicle_mac_addr[idx] == ':')
- icicle_mac_addr[idx] = ' ';
+ node = fdt_path_offset(blob, "/soc/ethernet@20112000");
+ if (node >= 0) {
+ ret = fdt_setprop(blob, node, "local-mac-address", mac_addr, 6);
+ if (ret) {
+ printf("Error setting local-mac-address property for ethernet@20112000\n");
+ return -ENODEV;
+ }
}
- env_set("icicle_mac_addr1", icicle_mac_addr);
return 0;
}