Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 2 | /* |
| 3 | * DHCOM DH-iMX6 PDK board support |
| 4 | * |
| 5 | * Copyright (C) 2017 Marek Vasut <marex@denx.de> |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Marek Vasut | 7937aba | 2019-05-17 16:58:51 +0200 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | eba6b8d | 2019-11-14 12:57:50 -0700 | [diff] [blame] | 10 | #include <eeprom.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 11 | #include <init.h> |
Marek Vasut | 7937aba | 2019-05-17 16:58:51 +0200 | [diff] [blame] | 12 | #include <dm/device-internal.h> |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 13 | #include <asm/arch/clock.h> |
| 14 | #include <asm/arch/crm_regs.h> |
| 15 | #include <asm/arch/imx-regs.h> |
| 16 | #include <asm/arch/iomux.h> |
| 17 | #include <asm/arch/mx6-pins.h> |
| 18 | #include <asm/arch/sys_proto.h> |
| 19 | #include <asm/gpio.h> |
| 20 | #include <asm/io.h> |
| 21 | #include <asm/mach-imx/boot_mode.h> |
| 22 | #include <asm/mach-imx/iomux-v3.h> |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 23 | #include <asm/mach-imx/sata.h> |
Marek Vasut | 6bd9bba | 2019-05-17 16:58:52 +0200 | [diff] [blame] | 24 | #include <ahci.h> |
| 25 | #include <dwc_ahsata.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 26 | #include <env.h> |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 27 | #include <errno.h> |
Yangbo Lu | 7334038 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 28 | #include <fsl_esdhc_imx.h> |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 29 | #include <fuse.h> |
Ludwig Zenz | 7217dae | 2019-07-08 15:04:58 +0200 | [diff] [blame] | 30 | #include <i2c_eeprom.h> |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 31 | #include <miiphy.h> |
| 32 | #include <mmc.h> |
| 33 | #include <net.h> |
| 34 | #include <netdev.h> |
| 35 | #include <usb.h> |
| 36 | #include <usb/ehci-ci.h> |
| 37 | |
| 38 | DECLARE_GLOBAL_DATA_PTR; |
| 39 | |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 40 | int dram_init(void) |
| 41 | { |
| 42 | gd->ram_size = imx_ddr_size(); |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | /* |
| 47 | * Do not overwrite the console |
| 48 | * Use always serial for U-Boot console |
| 49 | */ |
| 50 | int overwrite_console(void) |
| 51 | { |
| 52 | return 1; |
| 53 | } |
| 54 | |
| 55 | #ifdef CONFIG_FEC_MXC |
| 56 | static void eth_phy_reset(void) |
| 57 | { |
| 58 | /* Reset PHY */ |
| 59 | gpio_direction_output(IMX_GPIO_NR(5, 0) , 0); |
| 60 | udelay(500); |
| 61 | gpio_set_value(IMX_GPIO_NR(5, 0), 1); |
| 62 | |
| 63 | /* Enable VIO */ |
| 64 | gpio_direction_output(IMX_GPIO_NR(1, 7) , 0); |
| 65 | |
| 66 | /* |
| 67 | * KSZ9021 PHY needs at least 10 mSec after PHY reset |
| 68 | * is released to stabilize |
| 69 | */ |
| 70 | mdelay(10); |
| 71 | } |
| 72 | |
| 73 | static int setup_fec_clock(void) |
| 74 | { |
| 75 | struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 76 | |
| 77 | /* set gpr1[21] to select anatop clock */ |
| 78 | clrsetbits_le32(&iomuxc_regs->gpr[1], 0x1 << 21, 0x1 << 21); |
| 79 | |
| 80 | return enable_fec_anatop_clock(0, ENET_50MHZ); |
| 81 | } |
| 82 | |
| 83 | int board_eth_init(bd_t *bis) |
| 84 | { |
| 85 | uint32_t base = IMX_FEC_BASE; |
| 86 | struct mii_dev *bus = NULL; |
| 87 | struct phy_device *phydev = NULL; |
| 88 | |
Marek Vasut | 7bc3363 | 2019-05-17 16:58:50 +0200 | [diff] [blame] | 89 | gpio_request(IMX_GPIO_NR(5, 0), "PHY-reset"); |
| 90 | gpio_request(IMX_GPIO_NR(1, 7), "VIO"); |
| 91 | |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 92 | setup_fec_clock(); |
| 93 | |
| 94 | eth_phy_reset(); |
| 95 | |
| 96 | bus = fec_get_miibus(base, -1); |
| 97 | if (!bus) |
| 98 | return -EINVAL; |
| 99 | |
| 100 | /* Scan PHY 0 */ |
| 101 | phydev = phy_find_by_mask(bus, 0xf, PHY_INTERFACE_MODE_RGMII); |
| 102 | if (!phydev) { |
| 103 | printf("Ethernet PHY not found!\n"); |
| 104 | return -EINVAL; |
| 105 | } |
| 106 | |
| 107 | return fec_probe(bis, -1, base, bus, phydev); |
| 108 | } |
| 109 | #endif |
| 110 | |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 111 | #ifdef CONFIG_USB_EHCI_MX6 |
| 112 | static void setup_usb(void) |
| 113 | { |
| 114 | /* |
| 115 | * Set daisy chain for otg_pin_id on MX6Q. |
| 116 | * For MX6DL, this bit is reserved. |
| 117 | */ |
| 118 | imx_iomux_set_gpr_register(1, 13, 1, 0); |
| 119 | } |
| 120 | |
| 121 | int board_usb_phy_mode(int port) |
| 122 | { |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 123 | if (port == 1) |
Marek Vasut | 861b689 | 2017-10-22 10:22:40 +0200 | [diff] [blame] | 124 | return USB_INIT_HOST; |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 125 | else |
Marek Vasut | 861b689 | 2017-10-22 10:22:40 +0200 | [diff] [blame] | 126 | return USB_INIT_DEVICE; |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 127 | } |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 128 | #endif |
| 129 | |
| 130 | static int setup_dhcom_mac_from_fuse(void) |
| 131 | { |
Ludwig Zenz | 7217dae | 2019-07-08 15:04:58 +0200 | [diff] [blame] | 132 | struct udevice *dev; |
| 133 | ofnode eeprom; |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 134 | unsigned char enetaddr[6]; |
| 135 | int ret; |
| 136 | |
| 137 | ret = eth_env_get_enetaddr("ethaddr", enetaddr); |
| 138 | if (ret) /* ethaddr is already set */ |
| 139 | return 0; |
| 140 | |
| 141 | imx_get_mac_from_fuse(0, enetaddr); |
| 142 | |
| 143 | if (is_valid_ethaddr(enetaddr)) { |
| 144 | eth_env_set_enetaddr("ethaddr", enetaddr); |
| 145 | return 0; |
| 146 | } |
| 147 | |
Ludwig Zenz | 7217dae | 2019-07-08 15:04:58 +0200 | [diff] [blame] | 148 | eeprom = ofnode_path("/soc/aips-bus@2100000/i2c@21a8000/eeprom@50"); |
| 149 | if (!ofnode_valid(eeprom)) { |
| 150 | printf("Invalid hardware path to EEPROM!\n"); |
| 151 | return -ENODEV; |
| 152 | } |
| 153 | |
| 154 | ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev); |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 155 | if (ret) { |
Ludwig Zenz | 7217dae | 2019-07-08 15:04:58 +0200 | [diff] [blame] | 156 | printf("Cannot find EEPROM!\n"); |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 157 | return ret; |
| 158 | } |
| 159 | |
Ludwig Zenz | 7217dae | 2019-07-08 15:04:58 +0200 | [diff] [blame] | 160 | ret = i2c_eeprom_read(dev, 0xfa, enetaddr, 0x6); |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 161 | if (ret) { |
| 162 | printf("Error reading configuration EEPROM!\n"); |
| 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | if (is_valid_ethaddr(enetaddr)) |
| 167 | eth_env_set_enetaddr("ethaddr", enetaddr); |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | int board_early_init_f(void) |
| 173 | { |
| 174 | #ifdef CONFIG_USB_EHCI_MX6 |
| 175 | setup_usb(); |
| 176 | #endif |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 181 | int board_init(void) |
| 182 | { |
| 183 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 184 | |
| 185 | /* address of boot parameters */ |
| 186 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 187 | |
| 188 | /* Enable eim_slow clocks */ |
| 189 | setbits_le32(&mxc_ccm->CCGR6, 0x1 << MXC_CCM_CCGR6_EMI_SLOW_OFFSET); |
| 190 | |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 191 | setup_dhcom_mac_from_fuse(); |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | #ifdef CONFIG_CMD_BMODE |
| 197 | static const struct boot_mode board_boot_modes[] = { |
| 198 | /* 4 bit bus width */ |
| 199 | {"sd2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)}, |
| 200 | {"sd3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)}, |
| 201 | /* 8 bit bus width */ |
Claudius Heine | 868e1d5 | 2019-10-29 13:17:55 +0100 | [diff] [blame] | 202 | {"emmc", MAKE_CFGVAL(0x60, 0x58, 0x00, 0x00)}, |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 203 | {NULL, 0}, |
| 204 | }; |
| 205 | #endif |
| 206 | |
| 207 | #define HW_CODE_BIT_0 IMX_GPIO_NR(2, 19) |
| 208 | #define HW_CODE_BIT_1 IMX_GPIO_NR(6, 6) |
| 209 | #define HW_CODE_BIT_2 IMX_GPIO_NR(2, 16) |
| 210 | |
| 211 | static int board_get_hwcode(void) |
| 212 | { |
| 213 | int hw_code; |
| 214 | |
Marek Vasut | 7bc3363 | 2019-05-17 16:58:50 +0200 | [diff] [blame] | 215 | gpio_request(HW_CODE_BIT_0, "HW-code-bit-0"); |
| 216 | gpio_request(HW_CODE_BIT_1, "HW-code-bit-1"); |
| 217 | gpio_request(HW_CODE_BIT_2, "HW-code-bit-2"); |
| 218 | |
Marek Vasut | 00671d9 | 2017-10-09 21:51:10 +0200 | [diff] [blame] | 219 | gpio_direction_input(HW_CODE_BIT_0); |
| 220 | gpio_direction_input(HW_CODE_BIT_1); |
| 221 | gpio_direction_input(HW_CODE_BIT_2); |
| 222 | |
| 223 | /* HW 100 + HW 200 = 00b; HW 300 = 01b */ |
| 224 | hw_code = ((gpio_get_value(HW_CODE_BIT_2) << 2) | |
| 225 | (gpio_get_value(HW_CODE_BIT_1) << 1) | |
| 226 | gpio_get_value(HW_CODE_BIT_0)) + 2; |
| 227 | |
| 228 | return hw_code; |
| 229 | } |
| 230 | |
| 231 | int board_late_init(void) |
| 232 | { |
| 233 | u32 hw_code; |
| 234 | char buf[16]; |
| 235 | |
| 236 | hw_code = board_get_hwcode(); |
| 237 | |
| 238 | switch (get_cpu_type()) { |
| 239 | case MXC_CPU_MX6SOLO: |
| 240 | snprintf(buf, sizeof(buf), "imx6s-dhcom%1d", hw_code); |
| 241 | break; |
| 242 | case MXC_CPU_MX6DL: |
| 243 | snprintf(buf, sizeof(buf), "imx6dl-dhcom%1d", hw_code); |
| 244 | break; |
| 245 | case MXC_CPU_MX6D: |
| 246 | snprintf(buf, sizeof(buf), "imx6d-dhcom%1d", hw_code); |
| 247 | break; |
| 248 | case MXC_CPU_MX6Q: |
| 249 | snprintf(buf, sizeof(buf), "imx6q-dhcom%1d", hw_code); |
| 250 | break; |
| 251 | default: |
| 252 | snprintf(buf, sizeof(buf), "UNKNOWN%1d", hw_code); |
| 253 | break; |
| 254 | } |
| 255 | |
| 256 | env_set("dhcom", buf); |
| 257 | |
| 258 | #ifdef CONFIG_CMD_BMODE |
| 259 | add_board_boot_modes(board_boot_modes); |
| 260 | #endif |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | int checkboard(void) |
| 265 | { |
| 266 | puts("Board: DHCOM i.MX6\n"); |
| 267 | return 0; |
| 268 | } |
Ludwig Zenz | 9ea1ba9 | 2019-07-02 14:49:49 +0200 | [diff] [blame] | 269 | |
| 270 | #ifdef CONFIG_MULTI_DTB_FIT |
| 271 | int board_fit_config_name_match(const char *name) |
| 272 | { |
| 273 | if (is_mx6dq()) { |
| 274 | if (!strcmp(name, "imx6q-dhcom-pdk2")) |
| 275 | return 0; |
| 276 | } else if (is_mx6sdl()) { |
| 277 | if (!strcmp(name, "imx6dl-dhcom-pdk2")) |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | return -1; |
| 282 | } |
| 283 | #endif |