blob: 425c69056da539304756f22dc637b5a39d640370 [file] [log] [blame]
Tim Harvey256dba02021-03-02 14:00:21 -08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2021 Gateworks Corporation
4 */
5
6#include <common.h>
7#include <init.h>
8#include <led.h>
9#include <linux/delay.h>
10#include <miiphy.h>
11#include <netdev.h>
12
13#include <asm/arch/clock.h>
14#include <asm/arch/sys_proto.h>
15#include <asm/io.h>
Tim Harvey195a1612021-07-27 15:19:37 -070016#include <asm/unaligned.h>
Tim Harvey256dba02021-03-02 14:00:21 -080017
18#include "gsc.h"
19
20DECLARE_GLOBAL_DATA_PTR;
21
22int board_phys_sdram_size(phys_size_t *size)
23{
Tim Harvey56c5e312022-03-30 13:39:02 -070024 if (!size)
Tim Harvey195a1612021-07-27 15:19:37 -070025 return -EINVAL;
Tim Harvey256dba02021-03-02 14:00:21 -080026
Tim Harvey56c5e312022-03-30 13:39:02 -070027 *size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
Tim Harvey256dba02021-03-02 14:00:21 -080028
29 return 0;
30}
31
32int board_fit_config_name_match(const char *name)
33{
34 int i = 0;
35 const char *dtb;
Tim Harvey637b8b12021-06-30 17:07:40 -070036 static char init;
Tim Harvey256dba02021-03-02 14:00:21 -080037 char buf[32];
38
39 do {
40 dtb = gsc_get_dtb_name(i++, buf, sizeof(buf));
Tim Harvey637b8b12021-06-30 17:07:40 -070041 if (!strcmp(dtb, name)) {
42 if (!init++)
43 printf("DTB : %s\n", name);
Tim Harvey256dba02021-03-02 14:00:21 -080044 return 0;
Tim Harvey637b8b12021-06-30 17:07:40 -070045 }
Tim Harvey256dba02021-03-02 14:00:21 -080046 } while (dtb);
47
48 return -1;
49}
50
51#if (IS_ENABLED(CONFIG_FEC_MXC))
52static int setup_fec(void)
53{
54 struct iomuxc_gpr_base_regs *gpr =
55 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
56
57 /* Use 125M anatop REF_CLK1 for ENET1, not from external */
58 clrsetbits_le32(&gpr->gpr[1], 0x2000, 0);
59
60 return 0;
61}
62
63int board_phy_config(struct phy_device *phydev)
64{
65 unsigned short val;
Tim Harveya82c8ff2022-03-08 10:47:44 -080066 ofnode node;
Tim Harvey256dba02021-03-02 14:00:21 -080067
68 switch (phydev->phy_id) {
69 case 0x2000a231: /* TI DP83867 GbE PHY */
70 puts("DP83867 ");
71 /* LED configuration */
72 val = 0;
73 val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */
74 val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */
75 phy_write(phydev, MDIO_DEVAD_NONE, 24, val);
76 break;
Tim Harveya82c8ff2022-03-08 10:47:44 -080077 case 0xd565a401: /* MaxLinear GPY111 */
78 puts("GPY111 ");
79 node = phy_get_ofnode(phydev);
80 if (ofnode_valid(node)) {
81 u32 rx_delay, tx_delay;
82
83 rx_delay = ofnode_read_u32_default(node, "rx-internal-delay-ps", 2000);
84 tx_delay = ofnode_read_u32_default(node, "tx-internal-delay-ps", 2000);
85 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x17);
86 val &= ~((0x7 << 12) | (0x7 << 8));
87 val |= (rx_delay / 500) << 12;
88 val |= (tx_delay / 500) << 8;
89 phy_write(phydev, MDIO_DEVAD_NONE, 0x17, val);
90 }
91 break;
Tim Harvey256dba02021-03-02 14:00:21 -080092 }
93
94 if (phydev->drv->config)
95 phydev->drv->config(phydev);
96
97 return 0;
98}
99#endif // IS_ENABLED(CONFIG_FEC_MXC)
100
101int board_init(void)
102{
103 gsc_init(1);
104
105 if (IS_ENABLED(CONFIG_FEC_MXC))
106 setup_fec();
107
108 gsc_hwmon();
109
110 return 0;
111}
112
113int board_late_init(void)
114{
Tim Harvey68901572021-06-30 17:07:41 -0700115 const char *str;
Tim Harvey256dba02021-03-02 14:00:21 -0800116 char env[32];
117 int ret, i;
118 u8 enetaddr[6];
Tim Harvey68901572021-06-30 17:07:41 -0700119 char fdt[64];
Tim Harvey256dba02021-03-02 14:00:21 -0800120
121 led_default_state();
122
Tim Harvey78b8e072021-07-27 15:19:39 -0700123 /* Set board serial/model */
Tim Harvey62a13192021-08-18 15:24:28 -0700124 if (!env_get("serial#"))
125 env_set_ulong("serial#", gsc_get_serial());
Tim Harvey78b8e072021-07-27 15:19:39 -0700126 env_set("model", gsc_get_model());
127
Tim Harvey68901572021-06-30 17:07:41 -0700128 /* Set fdt_file vars */
129 i = 0;
130 do {
131 str = gsc_get_dtb_name(i, fdt, sizeof(fdt));
132 if (str) {
133 sprintf(env, "fdt_file%d", i + 1);
134 strcat(fdt, ".dtb");
135 env_set(env, fdt);
136 }
137 i++;
138 } while (str);
139
Tim Harvey256dba02021-03-02 14:00:21 -0800140 /* Set mac addrs */
141 i = 0;
142 do {
143 if (i)
144 sprintf(env, "eth%daddr", i);
145 else
146 sprintf(env, "ethaddr");
Tim Harvey68901572021-06-30 17:07:41 -0700147 str = env_get(env);
148 if (!str) {
Tim Harvey256dba02021-03-02 14:00:21 -0800149 ret = gsc_getmac(i, enetaddr);
150 if (!ret)
151 eth_env_set_enetaddr(env, enetaddr);
152 }
153 i++;
154 } while (!ret);
155
156 return 0;
157}
158
159int board_mmc_get_env_dev(int devno)
160{
161 return devno;
162}
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700163
164int ft_board_setup(void *blob, struct bd_info *bd)
165{
Tim Harvey547f6aa2021-08-18 15:24:30 -0700166 int off;
167
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700168 /* set board model dt prop */
169 fdt_setprop_string(blob, 0, "board", gsc_get_model());
170
Tim Harvey547f6aa2021-08-18 15:24:30 -0700171 /* update temp thresholds */
172 off = fdt_path_offset(blob, "/thermal-zones/cpu-thermal/trips");
173 if (off >= 0) {
174 int minc, maxc, prop;
175
176 get_cpu_temp_grade(&minc, &maxc);
177 fdt_for_each_subnode(prop, blob, off) {
178 const char *type = fdt_getprop(blob, prop, "type", NULL);
179
180 if (type && (!strcmp("critical", type)))
181 fdt_setprop_u32(blob, prop, "temperature", maxc * 1000);
182 else if (type && (!strcmp("passive", type)))
183 fdt_setprop_u32(blob, prop, "temperature", (maxc - 10) * 1000);
184 }
185 }
186
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700187 return 0;
188}