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