blob: 31523c081ee8789d0298a166e4e128b89c8e82a3 [file] [log] [blame]
Padmarao Begari4216f342019-05-28 15:47:51 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2019 Microchip Technology Inc.
4 * Padmarao Begari <padmarao.begari@microchip.com>
5 */
6
Tom Riniabb9a042024-05-18 20:20:43 -06007#include <common.h>
Padmarao Begari4216f342019-05-28 15:47:51 +05308#include <dm.h>
Padmarao Begari68eccfa2021-01-15 08:20:40 +05309#include <env.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Padmarao Begari4216f342019-05-28 15:47:51 +053012#include <asm/io.h>
13
Padmarao Begari68eccfa2021-01-15 08:20:40 +053014DECLARE_GLOBAL_DATA_PTR;
15
16#define MPFS_SYSREG_SOFT_RESET ((unsigned int *)0x20002088)
17#define MPFS_SYS_SERVICE_CR ((unsigned int *)0x37020050)
18#define MPFS_SYS_SERVICE_SR ((unsigned int *)0x37020054)
19#define MPFS_SYS_SERVICE_MAILBOX ((unsigned char *)0x37020800)
20
21#define PERIPH_RESET_VALUE 0x1e8u
22#define SERVICE_CR_REQ 0x1u
23#define SERVICE_SR_BUSY 0x2u
24
25static void read_device_serial_number(u8 *response, u8 response_size)
26{
27 u8 idx;
28 u8 *response_buf;
29 unsigned int val;
30
31 response_buf = (u8 *)response;
32
33 writel(SERVICE_CR_REQ, MPFS_SYS_SERVICE_CR);
34 /*
35 * REQ bit will remain set till the system controller starts
36 * processing.
37 */
38 do {
39 val = readl(MPFS_SYS_SERVICE_CR);
40 } while (SERVICE_CR_REQ == (val & SERVICE_CR_REQ));
41
42 /*
43 * Once system controller starts processing the busy bit will
44 * go high and service is completed when busy bit is gone low
45 */
46 do {
47 val = readl(MPFS_SYS_SERVICE_SR);
48 } while (SERVICE_SR_BUSY == (val & SERVICE_SR_BUSY));
49
50 for (idx = 0; idx < response_size; idx++)
51 response_buf[idx] = readb(MPFS_SYS_SERVICE_MAILBOX + idx);
52}
Padmarao Begari4216f342019-05-28 15:47:51 +053053
54int board_init(void)
55{
56 /* For now nothing to do here. */
57
58 return 0;
59}
60
61int board_early_init_f(void)
62{
63 unsigned int val;
64
Padmarao Begari68eccfa2021-01-15 08:20:40 +053065 /* Reset uart, mmc peripheral */
Padmarao Begari4216f342019-05-28 15:47:51 +053066 val = readl(MPFS_SYSREG_SOFT_RESET);
Padmarao Begari68eccfa2021-01-15 08:20:40 +053067 val = (val & ~(PERIPH_RESET_VALUE));
Padmarao Begari4216f342019-05-28 15:47:51 +053068 writel(val, MPFS_SYSREG_SOFT_RESET);
69
70 return 0;
71}
Padmarao Begari68eccfa2021-01-15 08:20:40 +053072
73int board_late_init(void)
74{
75 u32 ret;
Conor Dooley48361242024-05-15 16:04:30 +010076 int node;
Padmarao Begari68eccfa2021-01-15 08:20:40 +053077 u8 idx;
78 u8 device_serial_number[16] = { 0 };
79 unsigned char mac_addr[6];
80 char icicle_mac_addr[20];
81 void *blob = (void *)gd->fdt_blob;
82
Padmarao Begari68eccfa2021-01-15 08:20:40 +053083 read_device_serial_number(device_serial_number, 16);
84
85 /* Update MAC address with device serial number */
86 mac_addr[0] = 0x00;
87 mac_addr[1] = 0x04;
88 mac_addr[2] = 0xA3;
89 mac_addr[3] = device_serial_number[2];
90 mac_addr[4] = device_serial_number[1];
91 mac_addr[5] = device_serial_number[0];
92
Conor Dooleyc40084b2024-05-15 16:04:31 +010093 node = fdt_path_offset(blob, "/soc/ethernet@20112000");
94 if (node >= 0) {
95 ret = fdt_setprop(blob, node, "local-mac-address", mac_addr, 6);
96 if (ret) {
97 printf("Error setting local-mac-address property for ethernet@20112000\n");
98 return -ENODEV;
99 }
Padmarao Begari68eccfa2021-01-15 08:20:40 +0530100 }
101
102 icicle_mac_addr[0] = '[';
103
104 sprintf(&icicle_mac_addr[1], "%pM", mac_addr);
105
106 icicle_mac_addr[18] = ']';
107 icicle_mac_addr[19] = '\0';
108
109 for (idx = 0; idx < 20; idx++) {
110 if (icicle_mac_addr[idx] == ':')
111 icicle_mac_addr[idx] = ' ';
112 }
Padmarao Begari52547d12021-11-17 18:21:18 +0530113 env_set("icicle_mac_addr0", icicle_mac_addr);
114
115 mac_addr[5] = device_serial_number[0] + 1;
116
Conor Dooley00e6b1a2023-06-15 11:12:44 +0100117 node = fdt_path_offset(blob, "/soc/ethernet@20110000");
118 if (node >= 0) {
119 ret = fdt_setprop(blob, node, "local-mac-address", mac_addr, 6);
120 if (ret) {
121 printf("Error setting local-mac-address property for ethernet@20110000\n");
122 return -ENODEV;
123 }
124 }
125
Padmarao Begari52547d12021-11-17 18:21:18 +0530126 icicle_mac_addr[0] = '[';
127
128 sprintf(&icicle_mac_addr[1], "%pM", mac_addr);
129
130 icicle_mac_addr[18] = ']';
131 icicle_mac_addr[19] = '\0';
132
133 for (idx = 0; idx < 20; idx++) {
134 if (icicle_mac_addr[idx] == ':')
135 icicle_mac_addr[idx] = ' ';
136 }
137 env_set("icicle_mac_addr1", icicle_mac_addr);
Padmarao Begari68eccfa2021-01-15 08:20:40 +0530138
139 return 0;
140}