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