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 | 56c5e31 | 2022-03-30 13:39:02 -0700 | [diff] [blame] | 24 | if (!size) |
Tim Harvey | 195a161 | 2021-07-27 15:19:37 -0700 | [diff] [blame] | 25 | return -EINVAL; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 26 | |
Tim Harvey | 56c5e31 | 2022-03-30 13:39:02 -0700 | [diff] [blame] | 27 | *size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 28 | |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | int board_fit_config_name_match(const char *name) |
| 33 | { |
| 34 | int i = 0; |
| 35 | const char *dtb; |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 36 | static char init; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 37 | char buf[32]; |
| 38 | |
| 39 | do { |
| 40 | dtb = gsc_get_dtb_name(i++, buf, sizeof(buf)); |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 41 | if (!strcmp(dtb, name)) { |
| 42 | if (!init++) |
| 43 | printf("DTB : %s\n", name); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 44 | return 0; |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 45 | } |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 46 | } while (dtb); |
| 47 | |
| 48 | return -1; |
| 49 | } |
| 50 | |
| 51 | #if (IS_ENABLED(CONFIG_FEC_MXC)) |
| 52 | static 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 | |
| 63 | int board_phy_config(struct phy_device *phydev) |
| 64 | { |
| 65 | unsigned short val; |
Tim Harvey | a82c8ff | 2022-03-08 10:47:44 -0800 | [diff] [blame^] | 66 | ofnode node; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 67 | |
| 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 Harvey | a82c8ff | 2022-03-08 10:47:44 -0800 | [diff] [blame^] | 77 | 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 Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | if (phydev->drv->config) |
| 95 | phydev->drv->config(phydev); |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | #endif // IS_ENABLED(CONFIG_FEC_MXC) |
| 100 | |
| 101 | int 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 | |
| 113 | int board_late_init(void) |
| 114 | { |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 115 | const char *str; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 116 | char env[32]; |
| 117 | int ret, i; |
| 118 | u8 enetaddr[6]; |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 119 | char fdt[64]; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 120 | |
| 121 | led_default_state(); |
| 122 | |
Tim Harvey | 78b8e07 | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 123 | /* Set board serial/model */ |
Tim Harvey | 62a1319 | 2021-08-18 15:24:28 -0700 | [diff] [blame] | 124 | if (!env_get("serial#")) |
| 125 | env_set_ulong("serial#", gsc_get_serial()); |
Tim Harvey | 78b8e07 | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 126 | env_set("model", gsc_get_model()); |
| 127 | |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 128 | /* 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 Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 140 | /* Set mac addrs */ |
| 141 | i = 0; |
| 142 | do { |
| 143 | if (i) |
| 144 | sprintf(env, "eth%daddr", i); |
| 145 | else |
| 146 | sprintf(env, "ethaddr"); |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 147 | str = env_get(env); |
| 148 | if (!str) { |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 149 | 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 | |
| 159 | int board_mmc_get_env_dev(int devno) |
| 160 | { |
| 161 | return devno; |
| 162 | } |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 163 | |
| 164 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 165 | { |
Tim Harvey | 547f6aa | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 166 | int off; |
| 167 | |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 168 | /* set board model dt prop */ |
| 169 | fdt_setprop_string(blob, 0, "board", gsc_get_model()); |
| 170 | |
Tim Harvey | 547f6aa | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 171 | /* 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 Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 187 | return 0; |
| 188 | } |