blob: ada44e0142445d57ccf27f1f7deed2916dacbe6b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasut00671d92017-10-09 21:51:10 +02002/*
3 * DHCOM DH-iMX6 PDK board support
4 *
5 * Copyright (C) 2017 Marek Vasut <marex@denx.de>
Marek Vasut00671d92017-10-09 21:51:10 +02006 */
7
Marek Vasut7937aba2019-05-17 16:58:51 +02008#include <dm.h>
Simon Glass2dc9c342020-05-10 11:40:01 -06009#include <image.h>
Simon Glassa7b51302019-11-14 12:57:46 -070010#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060011#include <net.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Marek Vasut7937aba2019-05-17 16:58:51 +020013#include <dm/device-internal.h>
Marek Vasut00671d92017-10-09 21:51:10 +020014#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 Vasut00671d92017-10-09 21:51:10 +020024#include <asm/mach-imx/sata.h>
Marek Vasut6bd9bba2019-05-17 16:58:52 +020025#include <ahci.h>
26#include <dwc_ahsata.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060027#include <env.h>
Marek Vasut00671d92017-10-09 21:51:10 +020028#include <errno.h>
Yangbo Lu73340382019-06-21 11:42:28 +080029#include <fsl_esdhc_imx.h>
Marek Vasut00671d92017-10-09 21:51:10 +020030#include <fuse.h>
Ludwig Zenz7217dae2019-07-08 15:04:58 +020031#include <i2c_eeprom.h>
Marek Vasut00671d92017-10-09 21:51:10 +020032#include <mmc.h>
Marek Vasut891c5ef2024-09-25 00:08:23 +020033#include <power/regulator.h>
Marek Vasut00671d92017-10-09 21:51:10 +020034#include <usb.h>
Simon Glassdbd79542020-05-10 11:40:11 -060035#include <linux/delay.h>
Marek Vasut00671d92017-10-09 21:51:10 +020036#include <usb/ehci-ci.h>
37
Philip Oberfichtnerff9ccce2022-07-26 15:04:51 +020038#include "../common/dh_common.h"
39#include "../common/dh_imx.h"
40
Marek Vasut00671d92017-10-09 21:51:10 +020041DECLARE_GLOBAL_DATA_PTR;
42
Marek Vasut00671d92017-10-09 21:51:10 +020043int 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 */
53int overwrite_console(void)
54{
55 return 1;
56}
57
Marek Vasut00671d92017-10-09 21:51:10 +020058static 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 Vasut00671d92017-10-09 21:51:10 +020068#ifdef CONFIG_USB_EHCI_MX6
69static 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
78int board_usb_phy_mode(int port)
79{
Marek Vasut00671d92017-10-09 21:51:10 +020080 if (port == 1)
Marek Vasut861b6892017-10-22 10:22:40 +020081 return USB_INIT_HOST;
Marek Vasut00671d92017-10-09 21:51:10 +020082 else
Marek Vasut861b6892017-10-22 10:22:40 +020083 return USB_INIT_DEVICE;
Marek Vasut00671d92017-10-09 21:51:10 +020084}
Marek Vasut00671d92017-10-09 21:51:10 +020085#endif
86
Philip Oberfichtnerff9ccce2022-07-26 15:04:51 +020087int dh_setup_mac_address(void)
Marek Vasut00671d92017-10-09 21:51:10 +020088{
89 unsigned char enetaddr[6];
Marek Vasut00671d92017-10-09 21:51:10 +020090
Philip Oberfichtnerff9ccce2022-07-26 15:04:51 +020091 if (dh_mac_is_in_env("ethaddr"))
Marek Vasut00671d92017-10-09 21:51:10 +020092 return 0;
Marek Vasut00671d92017-10-09 21:51:10 +020093
Marek Vasut29ab1a92024-03-12 22:15:58 +010094 if (dh_get_mac_is_enabled("ethernet0"))
95 return 0;
96
Philip Oberfichtnerff9ccce2022-07-26 15:04:51 +020097 if (!dh_imx_get_mac_from_fuse(enetaddr))
98 goto out;
Ludwig Zenz7217dae2019-07-08 15:04:58 +020099
Philip Oberfichtnerff9ccce2022-07-26 15:04:51 +0200100 if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
101 goto out;
Marek Vasut00671d92017-10-09 21:51:10 +0200102
Philip Oberfichtnerff9ccce2022-07-26 15:04:51 +0200103 printf("%s: Unable to get MAC address!\n", __func__);
104 return -ENXIO;
Marek Vasut00671d92017-10-09 21:51:10 +0200105
Philip Oberfichtnerff9ccce2022-07-26 15:04:51 +0200106out:
107 return eth_env_set_enetaddr("ethaddr", enetaddr);
Marek Vasut00671d92017-10-09 21:51:10 +0200108}
109
110int board_early_init_f(void)
111{
112#ifdef CONFIG_USB_EHCI_MX6
113 setup_usb();
114#endif
115
116 return 0;
117}
118
Marek Vasut00671d92017-10-09 21:51:10 +0200119int 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 Seiler08541042020-04-15 20:04:53 +0200129 setup_fec_clock();
130
Marek Vasut891c5ef2024-09-25 00:08:23 +0200131 regulators_enable_boot_on(_DEBUG);
132
Marek Vasut00671d92017-10-09 21:51:10 +0200133 return 0;
134}
135
136#ifdef CONFIG_CMD_BMODE
137static const struct boot_mode board_boot_modes[] = {
138 /* 4 bit bus width */
139 {"sd2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
140 {"sd3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
141 /* 8 bit bus width */
Claudius Heine868e1d52019-10-29 13:17:55 +0100142 {"emmc", MAKE_CFGVAL(0x60, 0x58, 0x00, 0x00)},
Marek Vasut00671d92017-10-09 21:51:10 +0200143 {NULL, 0},
144};
145#endif
146
147#define HW_CODE_BIT_0 IMX_GPIO_NR(2, 19)
148#define HW_CODE_BIT_1 IMX_GPIO_NR(6, 6)
149#define HW_CODE_BIT_2 IMX_GPIO_NR(2, 16)
150
151static int board_get_hwcode(void)
152{
153 int hw_code;
154
Marek Vasut7bc33632019-05-17 16:58:50 +0200155 gpio_request(HW_CODE_BIT_0, "HW-code-bit-0");
156 gpio_request(HW_CODE_BIT_1, "HW-code-bit-1");
157 gpio_request(HW_CODE_BIT_2, "HW-code-bit-2");
158
Marek Vasut00671d92017-10-09 21:51:10 +0200159 gpio_direction_input(HW_CODE_BIT_0);
160 gpio_direction_input(HW_CODE_BIT_1);
161 gpio_direction_input(HW_CODE_BIT_2);
162
163 /* HW 100 + HW 200 = 00b; HW 300 = 01b */
164 hw_code = ((gpio_get_value(HW_CODE_BIT_2) << 2) |
165 (gpio_get_value(HW_CODE_BIT_1) << 1) |
166 gpio_get_value(HW_CODE_BIT_0)) + 2;
167
168 return hw_code;
169}
170
171int board_late_init(void)
172{
173 u32 hw_code;
174 char buf[16];
175
Philip Oberfichtnerff9ccce2022-07-26 15:04:51 +0200176 dh_setup_mac_address();
Marek Vasut56764b32020-05-14 18:49:10 +0200177
Marek Vasut00671d92017-10-09 21:51:10 +0200178 hw_code = board_get_hwcode();
179
180 switch (get_cpu_type()) {
181 case MXC_CPU_MX6SOLO:
182 snprintf(buf, sizeof(buf), "imx6s-dhcom%1d", hw_code);
183 break;
184 case MXC_CPU_MX6DL:
185 snprintf(buf, sizeof(buf), "imx6dl-dhcom%1d", hw_code);
186 break;
187 case MXC_CPU_MX6D:
188 snprintf(buf, sizeof(buf), "imx6d-dhcom%1d", hw_code);
189 break;
190 case MXC_CPU_MX6Q:
191 snprintf(buf, sizeof(buf), "imx6q-dhcom%1d", hw_code);
192 break;
193 default:
194 snprintf(buf, sizeof(buf), "UNKNOWN%1d", hw_code);
195 break;
196 }
197
198 env_set("dhcom", buf);
199
200#ifdef CONFIG_CMD_BMODE
201 add_board_boot_modes(board_boot_modes);
202#endif
203 return 0;
204}
205
206int checkboard(void)
207{
208 puts("Board: DHCOM i.MX6\n");
209 return 0;
210}
Ludwig Zenz9ea1ba92019-07-02 14:49:49 +0200211
212#ifdef CONFIG_MULTI_DTB_FIT
Philip Oberfichtner4b595a32022-05-20 10:46:26 +0200213static int strcmp_prefix(const char *s1, const char *s2)
214{
215 size_t n;
216
217 n = min(strlen(s1), strlen(s2));
218 return strncmp(s1, s2, n);
219}
220
Ludwig Zenz9ea1ba92019-07-02 14:49:49 +0200221int board_fit_config_name_match(const char *name)
222{
Philip Oberfichtner4b595a32022-05-20 10:46:26 +0200223 char *want;
224 char *have;
225
226 /* Test Board suffix, e.g. -dhcom-drc02 */
227 want = strchr(CONFIG_DEFAULT_DEVICE_TREE, '-');
228 have = strchr(name, '-');
229
230 if (!want || !have || strcmp(want, have))
231 return -EINVAL;
232
233 /* Test SoC prefix */
234 if (is_mx6dq() && !strcmp_prefix(name, "imx6q-"))
235 return 0;
236
237 if (is_mx6sdl()) {
238 if (!strcmp_prefix(name, "imx6s-") || !strcmp_prefix(name, "imx6dl-"))
Ludwig Zenz9ea1ba92019-07-02 14:49:49 +0200239 return 0;
240 }
241
Philip Oberfichtner4b595a32022-05-20 10:46:26 +0200242 return -EINVAL;
Ludwig Zenz9ea1ba92019-07-02 14:49:49 +0200243}
244#endif