blob: 5334500ef6a7c10be4330b5dd5b5c82f2045d4e1 [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;
66
67 switch (phydev->phy_id) {
68 case 0x2000a231: /* TI DP83867 GbE PHY */
69 puts("DP83867 ");
70 /* LED configuration */
71 val = 0;
72 val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */
73 val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */
74 phy_write(phydev, MDIO_DEVAD_NONE, 24, val);
75 break;
76 }
77
78 if (phydev->drv->config)
79 phydev->drv->config(phydev);
80
81 return 0;
82}
83#endif // IS_ENABLED(CONFIG_FEC_MXC)
84
85int board_init(void)
86{
87 gsc_init(1);
88
89 if (IS_ENABLED(CONFIG_FEC_MXC))
90 setup_fec();
91
92 gsc_hwmon();
93
94 return 0;
95}
96
97int board_late_init(void)
98{
Tim Harvey68901572021-06-30 17:07:41 -070099 const char *str;
Tim Harvey256dba02021-03-02 14:00:21 -0800100 char env[32];
101 int ret, i;
102 u8 enetaddr[6];
Tim Harvey68901572021-06-30 17:07:41 -0700103 char fdt[64];
Tim Harvey256dba02021-03-02 14:00:21 -0800104
105 led_default_state();
106
Tim Harvey78b8e072021-07-27 15:19:39 -0700107 /* Set board serial/model */
Tim Harvey62a13192021-08-18 15:24:28 -0700108 if (!env_get("serial#"))
109 env_set_ulong("serial#", gsc_get_serial());
Tim Harvey78b8e072021-07-27 15:19:39 -0700110 env_set("model", gsc_get_model());
111
Tim Harvey68901572021-06-30 17:07:41 -0700112 /* Set fdt_file vars */
113 i = 0;
114 do {
115 str = gsc_get_dtb_name(i, fdt, sizeof(fdt));
116 if (str) {
117 sprintf(env, "fdt_file%d", i + 1);
118 strcat(fdt, ".dtb");
119 env_set(env, fdt);
120 }
121 i++;
122 } while (str);
123
Tim Harvey256dba02021-03-02 14:00:21 -0800124 /* Set mac addrs */
125 i = 0;
126 do {
127 if (i)
128 sprintf(env, "eth%daddr", i);
129 else
130 sprintf(env, "ethaddr");
Tim Harvey68901572021-06-30 17:07:41 -0700131 str = env_get(env);
132 if (!str) {
Tim Harvey256dba02021-03-02 14:00:21 -0800133 ret = gsc_getmac(i, enetaddr);
134 if (!ret)
135 eth_env_set_enetaddr(env, enetaddr);
136 }
137 i++;
138 } while (!ret);
139
140 return 0;
141}
142
143int board_mmc_get_env_dev(int devno)
144{
145 return devno;
146}
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700147
148int ft_board_setup(void *blob, struct bd_info *bd)
149{
Tim Harvey547f6aa2021-08-18 15:24:30 -0700150 int off;
151
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700152 /* set board model dt prop */
153 fdt_setprop_string(blob, 0, "board", gsc_get_model());
154
Tim Harvey547f6aa2021-08-18 15:24:30 -0700155 /* update temp thresholds */
156 off = fdt_path_offset(blob, "/thermal-zones/cpu-thermal/trips");
157 if (off >= 0) {
158 int minc, maxc, prop;
159
160 get_cpu_temp_grade(&minc, &maxc);
161 fdt_for_each_subnode(prop, blob, off) {
162 const char *type = fdt_getprop(blob, prop, "type", NULL);
163
164 if (type && (!strcmp("critical", type)))
165 fdt_setprop_u32(blob, prop, "temperature", maxc * 1000);
166 else if (type && (!strcmp("passive", type)))
167 fdt_setprop_u32(blob, prop, "temperature", (maxc - 10) * 1000);
168 }
169 }
170
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700171 return 0;
172}