Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 1 | // 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 Harvey | 195a161 | 2021-07-27 15:19:37 -0700 | [diff] [blame] | 16 | #include <asm/unaligned.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 17 | |
| 18 | #include "gsc.h" |
| 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
| 22 | int board_phys_sdram_size(phys_size_t *size) |
| 23 | { |
Tim Harvey | 195a161 | 2021-07-27 15:19:37 -0700 | [diff] [blame] | 24 | 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 Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 32 | |
Tim Harvey | 195a161 | 2021-07-27 15:19:37 -0700 | [diff] [blame] | 33 | 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 Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | int board_fit_config_name_match(const char *name) |
| 42 | { |
| 43 | int i = 0; |
| 44 | const char *dtb; |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 45 | static char init; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 46 | char buf[32]; |
| 47 | |
| 48 | do { |
| 49 | dtb = gsc_get_dtb_name(i++, buf, sizeof(buf)); |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 50 | if (!strcmp(dtb, name)) { |
| 51 | if (!init++) |
| 52 | printf("DTB : %s\n", name); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 53 | return 0; |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 54 | } |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 55 | } while (dtb); |
| 56 | |
| 57 | return -1; |
| 58 | } |
| 59 | |
| 60 | #if (IS_ENABLED(CONFIG_FEC_MXC)) |
| 61 | static 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 | |
| 72 | int 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 | |
| 94 | int 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 | |
| 106 | int board_late_init(void) |
| 107 | { |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 108 | const char *str; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 109 | char env[32]; |
| 110 | int ret, i; |
| 111 | u8 enetaddr[6]; |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 112 | char fdt[64]; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 113 | |
| 114 | led_default_state(); |
| 115 | |
Tim Harvey | 78b8e07 | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 116 | /* Set board serial/model */ |
Tim Harvey | 62a1319 | 2021-08-18 15:24:28 -0700 | [diff] [blame] | 117 | if (!env_get("serial#")) |
| 118 | env_set_ulong("serial#", gsc_get_serial()); |
Tim Harvey | 78b8e07 | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 119 | env_set("model", gsc_get_model()); |
| 120 | |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 121 | /* Set fdt_file vars */ |
| 122 | i = 0; |
| 123 | do { |
| 124 | str = gsc_get_dtb_name(i, fdt, sizeof(fdt)); |
| 125 | if (str) { |
| 126 | sprintf(env, "fdt_file%d", i + 1); |
| 127 | strcat(fdt, ".dtb"); |
| 128 | env_set(env, fdt); |
| 129 | } |
| 130 | i++; |
| 131 | } while (str); |
| 132 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 133 | /* Set mac addrs */ |
| 134 | i = 0; |
| 135 | do { |
| 136 | if (i) |
| 137 | sprintf(env, "eth%daddr", i); |
| 138 | else |
| 139 | sprintf(env, "ethaddr"); |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 140 | str = env_get(env); |
| 141 | if (!str) { |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 142 | ret = gsc_getmac(i, enetaddr); |
| 143 | if (!ret) |
| 144 | eth_env_set_enetaddr(env, enetaddr); |
| 145 | } |
| 146 | i++; |
| 147 | } while (!ret); |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | int board_mmc_get_env_dev(int devno) |
| 153 | { |
| 154 | return devno; |
| 155 | } |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 156 | |
| 157 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 158 | { |
Tim Harvey | 547f6aa | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 159 | int off; |
| 160 | |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 161 | /* set board model dt prop */ |
| 162 | fdt_setprop_string(blob, 0, "board", gsc_get_model()); |
| 163 | |
Tim Harvey | 547f6aa | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 164 | /* update temp thresholds */ |
| 165 | off = fdt_path_offset(blob, "/thermal-zones/cpu-thermal/trips"); |
| 166 | if (off >= 0) { |
| 167 | int minc, maxc, prop; |
| 168 | |
| 169 | get_cpu_temp_grade(&minc, &maxc); |
| 170 | fdt_for_each_subnode(prop, blob, off) { |
| 171 | const char *type = fdt_getprop(blob, prop, "type", NULL); |
| 172 | |
| 173 | if (type && (!strcmp("critical", type))) |
| 174 | fdt_setprop_u32(blob, prop, "temperature", maxc * 1000); |
| 175 | else if (type && (!strcmp("passive", type))) |
| 176 | fdt_setprop_u32(blob, prop, "temperature", (maxc - 10) * 1000); |
| 177 | } |
| 178 | } |
| 179 | |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 180 | return 0; |
| 181 | } |