blob: 2a97d55d32765fe3c57f7f30f04519fd1f190304 [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 Harvey195a1612021-07-27 15:19:37 -070024 const fdt64_t *val;
25 int offset;
26 int len;
27
28 /* get size from dt which SPL updated per EEPROM config */
29 offset = fdt_path_offset(gd->fdt_blob, "/memory");
30 if (offset < 0)
31 return -EINVAL;
Tim Harvey256dba02021-03-02 14:00:21 -080032
Tim Harvey195a1612021-07-27 15:19:37 -070033 val = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
34 if (len < sizeof(*val) * 2)
35 return -EINVAL;
36 *size = get_unaligned_be64(&val[1]);
Tim Harvey256dba02021-03-02 14:00:21 -080037
38 return 0;
39}
40
41int board_fit_config_name_match(const char *name)
42{
43 int i = 0;
44 const char *dtb;
Tim Harvey637b8b12021-06-30 17:07:40 -070045 static char init;
Tim Harvey256dba02021-03-02 14:00:21 -080046 char buf[32];
47
48 do {
49 dtb = gsc_get_dtb_name(i++, buf, sizeof(buf));
Tim Harvey637b8b12021-06-30 17:07:40 -070050 if (!strcmp(dtb, name)) {
51 if (!init++)
52 printf("DTB : %s\n", name);
Tim Harvey256dba02021-03-02 14:00:21 -080053 return 0;
Tim Harvey637b8b12021-06-30 17:07:40 -070054 }
Tim Harvey256dba02021-03-02 14:00:21 -080055 } while (dtb);
56
57 return -1;
58}
59
60#if (IS_ENABLED(CONFIG_FEC_MXC))
61static int setup_fec(void)
62{
63 struct iomuxc_gpr_base_regs *gpr =
64 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
65
66 /* Use 125M anatop REF_CLK1 for ENET1, not from external */
67 clrsetbits_le32(&gpr->gpr[1], 0x2000, 0);
68
69 return 0;
70}
71
72int board_phy_config(struct phy_device *phydev)
73{
74 unsigned short val;
75
76 switch (phydev->phy_id) {
77 case 0x2000a231: /* TI DP83867 GbE PHY */
78 puts("DP83867 ");
79 /* LED configuration */
80 val = 0;
81 val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */
82 val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */
83 phy_write(phydev, MDIO_DEVAD_NONE, 24, val);
84 break;
85 }
86
87 if (phydev->drv->config)
88 phydev->drv->config(phydev);
89
90 return 0;
91}
92#endif // IS_ENABLED(CONFIG_FEC_MXC)
93
94int board_init(void)
95{
96 gsc_init(1);
97
98 if (IS_ENABLED(CONFIG_FEC_MXC))
99 setup_fec();
100
101 gsc_hwmon();
102
103 return 0;
104}
105
106int board_late_init(void)
107{
Tim Harvey68901572021-06-30 17:07:41 -0700108 const char *str;
Tim Harvey256dba02021-03-02 14:00:21 -0800109 char env[32];
110 int ret, i;
111 u8 enetaddr[6];
Tim Harvey68901572021-06-30 17:07:41 -0700112 char fdt[64];
Tim Harvey256dba02021-03-02 14:00:21 -0800113
114 led_default_state();
115
Tim Harvey78b8e072021-07-27 15:19:39 -0700116 /* Set board serial/model */
117 env_set_ulong("serial#", gsc_get_serial());
118 env_set("model", gsc_get_model());
119
Tim Harvey68901572021-06-30 17:07:41 -0700120 /* Set fdt_file vars */
121 i = 0;
122 do {
123 str = gsc_get_dtb_name(i, fdt, sizeof(fdt));
124 if (str) {
125 sprintf(env, "fdt_file%d", i + 1);
126 strcat(fdt, ".dtb");
127 env_set(env, fdt);
128 }
129 i++;
130 } while (str);
131
Tim Harvey256dba02021-03-02 14:00:21 -0800132 /* Set mac addrs */
133 i = 0;
134 do {
135 if (i)
136 sprintf(env, "eth%daddr", i);
137 else
138 sprintf(env, "ethaddr");
Tim Harvey68901572021-06-30 17:07:41 -0700139 str = env_get(env);
140 if (!str) {
Tim Harvey256dba02021-03-02 14:00:21 -0800141 ret = gsc_getmac(i, enetaddr);
142 if (!ret)
143 eth_env_set_enetaddr(env, enetaddr);
144 }
145 i++;
146 } while (!ret);
147
148 return 0;
149}
150
151int board_mmc_get_env_dev(int devno)
152{
153 return devno;
154}
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700155
156int ft_board_setup(void *blob, struct bd_info *bd)
157{
158 /* set board model dt prop */
159 fdt_setprop_string(blob, 0, "board", gsc_get_model());
160
161 return 0;
162}