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; |
| 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 | |
| 85 | int 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 | |
| 97 | int board_late_init(void) |
| 98 | { |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 99 | const char *str; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 100 | char env[32]; |
| 101 | int ret, i; |
| 102 | u8 enetaddr[6]; |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 103 | char fdt[64]; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 104 | |
| 105 | led_default_state(); |
| 106 | |
Tim Harvey | 78b8e07 | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 107 | /* Set board serial/model */ |
Tim Harvey | 62a1319 | 2021-08-18 15:24:28 -0700 | [diff] [blame] | 108 | if (!env_get("serial#")) |
| 109 | env_set_ulong("serial#", gsc_get_serial()); |
Tim Harvey | 78b8e07 | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 110 | env_set("model", gsc_get_model()); |
| 111 | |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 112 | /* 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 Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 124 | /* Set mac addrs */ |
| 125 | i = 0; |
| 126 | do { |
| 127 | if (i) |
| 128 | sprintf(env, "eth%daddr", i); |
| 129 | else |
| 130 | sprintf(env, "ethaddr"); |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 131 | str = env_get(env); |
| 132 | if (!str) { |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 133 | 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 | |
| 143 | int board_mmc_get_env_dev(int devno) |
| 144 | { |
| 145 | return devno; |
| 146 | } |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 147 | |
| 148 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 149 | { |
Tim Harvey | 547f6aa | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 150 | int off; |
| 151 | |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 152 | /* set board model dt prop */ |
| 153 | fdt_setprop_string(blob, 0, "board", gsc_get_model()); |
| 154 | |
Tim Harvey | 547f6aa | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 155 | /* 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 Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 171 | return 0; |
| 172 | } |