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 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 6 | #include <init.h> |
| 7 | #include <led.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 8 | #include <miiphy.h> |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 9 | #include <asm/arch/clock.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 10 | #include <asm/arch/sys_proto.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 11 | |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 12 | #include "eeprom.h" |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 13 | |
| 14 | int board_phys_sdram_size(phys_size_t *size) |
| 15 | { |
Tim Harvey | 56c5e31 | 2022-03-30 13:39:02 -0700 | [diff] [blame] | 16 | if (!size) |
Tim Harvey | 195a161 | 2021-07-27 15:19:37 -0700 | [diff] [blame] | 17 | return -EINVAL; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 18 | |
Tim Harvey | 56c5e31 | 2022-03-30 13:39:02 -0700 | [diff] [blame] | 19 | *size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 20 | |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | int board_fit_config_name_match(const char *name) |
| 25 | { |
| 26 | int i = 0; |
| 27 | const char *dtb; |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 28 | static char init; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 29 | char buf[32]; |
| 30 | |
| 31 | do { |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 32 | dtb = eeprom_get_dtb_name(i++, buf, sizeof(buf)); |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 33 | if (!strcmp(dtb, name)) { |
| 34 | if (!init++) |
| 35 | printf("DTB : %s\n", name); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 36 | return 0; |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 37 | } |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 38 | } while (dtb); |
| 39 | |
| 40 | return -1; |
| 41 | } |
| 42 | |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 43 | #if (IS_ENABLED(CONFIG_NET)) |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 44 | static int setup_fec(void) |
| 45 | { |
| 46 | struct iomuxc_gpr_base_regs *gpr = |
| 47 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 48 | |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 49 | #ifndef CONFIG_IMX8MP |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 50 | /* Use 125M anatop REF_CLK1 for ENET1, not from external */ |
| 51 | clrsetbits_le32(&gpr->gpr[1], 0x2000, 0); |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 52 | #else |
| 53 | /* Enable RGMII TX clk output */ |
| 54 | setbits_le32(&gpr->gpr[1], BIT(22)); |
| 55 | #endif |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 60 | static int setup_eqos(void) |
| 61 | { |
| 62 | struct iomuxc_gpr_base_regs *gpr = |
| 63 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 64 | |
| 65 | /* set INTF as RGMII, enable RGMII TXC clock */ |
| 66 | clrsetbits_le32(&gpr->gpr[1], |
| 67 | IOMUXC_GPR_GPR1_GPR_ENET_QOS_INTF_SEL_MASK, BIT(16)); |
| 68 | setbits_le32(&gpr->gpr[1], BIT(19) | BIT(21)); |
| 69 | |
| 70 | return set_clk_eqos(ENET_125MHZ); |
| 71 | } |
| 72 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 73 | int board_phy_config(struct phy_device *phydev) |
| 74 | { |
| 75 | unsigned short val; |
Tim Harvey | a82c8ff | 2022-03-08 10:47:44 -0800 | [diff] [blame] | 76 | ofnode node; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 77 | |
| 78 | switch (phydev->phy_id) { |
| 79 | case 0x2000a231: /* TI DP83867 GbE PHY */ |
| 80 | puts("DP83867 "); |
| 81 | /* LED configuration */ |
| 82 | val = 0; |
| 83 | val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */ |
| 84 | val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */ |
| 85 | phy_write(phydev, MDIO_DEVAD_NONE, 24, val); |
| 86 | break; |
Tim Harvey | a82c8ff | 2022-03-08 10:47:44 -0800 | [diff] [blame] | 87 | case 0xd565a401: /* MaxLinear GPY111 */ |
| 88 | puts("GPY111 "); |
| 89 | node = phy_get_ofnode(phydev); |
| 90 | if (ofnode_valid(node)) { |
| 91 | u32 rx_delay, tx_delay; |
| 92 | |
| 93 | rx_delay = ofnode_read_u32_default(node, "rx-internal-delay-ps", 2000); |
| 94 | tx_delay = ofnode_read_u32_default(node, "tx-internal-delay-ps", 2000); |
| 95 | val = phy_read(phydev, MDIO_DEVAD_NONE, 0x17); |
| 96 | val &= ~((0x7 << 12) | (0x7 << 8)); |
| 97 | val |= (rx_delay / 500) << 12; |
| 98 | val |= (tx_delay / 500) << 8; |
| 99 | phy_write(phydev, MDIO_DEVAD_NONE, 0x17, val); |
| 100 | } |
| 101 | break; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | if (phydev->drv->config) |
| 105 | phydev->drv->config(phydev); |
| 106 | |
| 107 | return 0; |
| 108 | } |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 109 | #endif // IS_ENABLED(CONFIG_NET) |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 110 | |
| 111 | int board_init(void) |
| 112 | { |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 113 | eeprom_init(1); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 114 | |
| 115 | if (IS_ENABLED(CONFIG_FEC_MXC)) |
| 116 | setup_fec(); |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 117 | if (IS_ENABLED(CONFIG_DWC_ETH_QOS)) |
| 118 | setup_eqos(); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 119 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | int board_late_init(void) |
| 124 | { |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 125 | const char *str; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 126 | char env[32]; |
| 127 | int ret, i; |
| 128 | u8 enetaddr[6]; |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 129 | char fdt[64]; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 130 | |
Tim Harvey | 78b8e07 | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 131 | /* Set board serial/model */ |
Tim Harvey | 62a1319 | 2021-08-18 15:24:28 -0700 | [diff] [blame] | 132 | if (!env_get("serial#")) |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 133 | env_set_ulong("serial#", eeprom_get_serial()); |
| 134 | env_set("model", eeprom_get_model()); |
Tim Harvey | 78b8e07 | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 135 | |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 136 | /* Set fdt_file vars */ |
| 137 | i = 0; |
| 138 | do { |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 139 | str = eeprom_get_dtb_name(i, fdt, sizeof(fdt)); |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 140 | if (str) { |
| 141 | sprintf(env, "fdt_file%d", i + 1); |
| 142 | strcat(fdt, ".dtb"); |
| 143 | env_set(env, fdt); |
| 144 | } |
| 145 | i++; |
| 146 | } while (str); |
| 147 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 148 | /* Set mac addrs */ |
| 149 | i = 0; |
| 150 | do { |
| 151 | if (i) |
| 152 | sprintf(env, "eth%daddr", i); |
| 153 | else |
| 154 | sprintf(env, "ethaddr"); |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 155 | str = env_get(env); |
| 156 | if (!str) { |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 157 | ret = eeprom_getmac(i, enetaddr); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 158 | if (!ret) |
| 159 | eth_env_set_enetaddr(env, enetaddr); |
| 160 | } |
| 161 | i++; |
| 162 | } while (!ret); |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | int board_mmc_get_env_dev(int devno) |
| 168 | { |
| 169 | return devno; |
| 170 | } |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 171 | |
| 172 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 173 | { |
Tim Harvey | 547f6aa | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 174 | int off; |
| 175 | |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 176 | /* set board model dt prop */ |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 177 | fdt_setprop_string(blob, 0, "board", eeprom_get_model()); |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 178 | |
Tim Harvey | 547f6aa | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 179 | /* update temp thresholds */ |
| 180 | off = fdt_path_offset(blob, "/thermal-zones/cpu-thermal/trips"); |
| 181 | if (off >= 0) { |
| 182 | int minc, maxc, prop; |
| 183 | |
| 184 | get_cpu_temp_grade(&minc, &maxc); |
| 185 | fdt_for_each_subnode(prop, blob, off) { |
| 186 | const char *type = fdt_getprop(blob, prop, "type", NULL); |
| 187 | |
| 188 | if (type && (!strcmp("critical", type))) |
| 189 | fdt_setprop_u32(blob, prop, "temperature", maxc * 1000); |
| 190 | else if (type && (!strcmp("passive", type))) |
| 191 | fdt_setprop_u32(blob, prop, "temperature", (maxc - 10) * 1000); |
| 192 | } |
| 193 | } |
| 194 | |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 195 | return 0; |
| 196 | } |