1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2017-2019 NXP
5 * Copyright 2019 Siemens AG
12 #include <env_internal.h>
13 #include <fsl_esdhc_imx.h>
17 #include <power-domain.h>
19 #include <asm/arch/imx8-pins.h>
20 #include <asm/arch/iomux.h>
21 #include <asm/arch/sci/sci.h>
22 #include <asm/arch/sys_proto.h>
24 #include <asm/arch-imx8/clock.h>
26 #include "../common/factoryset.h"
28 #define GPIO_PAD_CTRL \
29 ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
30 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
31 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
32 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
34 #define ENET_NORMAL_PAD_CTRL \
35 ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
36 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
37 (SC_PAD_28FDSOI_DSE_18V_10MA << PADRING_DSE_SHIFT) | \
38 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
40 #define UART_PAD_CTRL \
41 ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \
42 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
43 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
44 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
46 static iomux_cfg_t uart2_pads[] = {
47 SC_P_UART2_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
48 SC_P_UART2_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
51 static void setup_iomux_uart(void)
53 imx8_iomux_setup_multiple_pads(uart2_pads, ARRAY_SIZE(uart2_pads));
56 int board_early_init_f(void)
58 /* Set UART clock root to 80 MHz */
59 sc_pm_clock_rate_t rate = SC_80MHZ;
62 ret = sc_pm_setup_uart(SC_R_UART_0, rate);
63 ret |= sc_pm_setup_uart(SC_R_UART_2, rate);
72 #define ENET_PHY_RESET IMX_GPIO_NR(0, 3)
73 #define ENET_TEST_1 IMX_GPIO_NR(0, 8)
74 #define ENET_TEST_2 IMX_GPIO_NR(0, 9)
76 /*#define ETH_IO_TEST*/
77 static iomux_cfg_t enet_reset[] = {
78 SC_P_ESAI0_SCKT | MUX_MODE_ALT(4) | MUX_PAD_CTRL(GPIO_PAD_CTRL),
80 /* GPIO0.IO08 MODE3: TXD0 */
81 SC_P_ESAI0_TX4_RX1 | MUX_MODE_ALT(4) |
82 MUX_PAD_CTRL(ENET_NORMAL_PAD_CTRL),
83 /* GPIO0.IO09 MODE3: TXD1 */
84 SC_P_ESAI0_TX5_RX0 | MUX_MODE_ALT(4) |
85 MUX_PAD_CTRL(ENET_NORMAL_PAD_CTRL),
89 static void enet_device_phy_reset(void)
93 imx8_iomux_setup_multiple_pads(enet_reset, ARRAY_SIZE(enet_reset));
95 ret = gpio_request(ENET_PHY_RESET, "enet_phy_reset");
97 gpio_direction_output(ENET_PHY_RESET, 1);
98 gpio_set_value(ENET_PHY_RESET, 0);
99 /* SMSC9303 TRM chapter 14.5.2 */
101 gpio_set_value(ENET_PHY_RESET, 1);
103 printf("ENET RESET failed!\n");
107 ret = gpio_request(ENET_TEST_1, "enet_test1");
111 printf("ENET TEST 1!\n");
112 for (i = 0; i < 20; i++) {
113 gpio_direction_output(ENET_TEST_1, 1);
114 gpio_set_value(ENET_TEST_1, 0);
116 gpio_set_value(ENET_TEST_1, 1);
119 gpio_free(ENET_TEST_1);
121 printf("GPIO for ENET TEST 1 failed!\n");
123 ret = gpio_request(ENET_TEST_2, "enet_test2");
127 printf("ENET TEST 2!\n");
128 for (i = 0; i < 20; i++) {
129 gpio_direction_output(ENET_TEST_2, 1);
130 gpio_set_value(ENET_TEST_2, 0);
132 gpio_set_value(ENET_TEST_2, 1);
135 gpio_free(ENET_TEST_2);
137 printf("GPIO for ENET TEST 2 failed!\n");
142 int setup_gpr_fec(void)
144 sc_ipc_t ipc_handle = -1;
149 * TX_CLK_SEL: it controls a mux between clock coming from the pad 50M
150 * input pin and clock generated internally to connectivity subsystem
152 * 1: external clock ---> your choice for RMII
154 * CLKDIV_SEL: it controls a div by 2 on the internal clock path à
155 * it should be don’t care when using external clock
156 * 0: non-divided clock
157 * 1: clock divided by 2
158 * 50_DISABLE or 125_DISABLE:
159 * it’s used to disable the clock tree going outside the chip
160 * when reference clock is generated internally.
161 * It should be don’t care when reference clock is provided
163 * 0: clock is enabled
164 * 1: clock is disabled
168 * SC_C_DISABLE_50 = 26,
169 * SC_C_DISABLE_125 = 27,
172 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, 1);
173 if (err != SC_ERR_NONE)
174 printf("Error in setting up SC_C %d\n\r", SC_C_TXCLK);
176 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, &test);
177 debug("TEST SC_C %d-->%d\n\r", SC_C_TXCLK, test);
179 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_CLKDIV, 0);
180 if (err != SC_ERR_NONE)
181 printf("Error in setting up SC_C %d\n\r", SC_C_CLKDIV);
183 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_CLKDIV, &test);
184 debug("TEST SC_C %d-->%d\n\r", SC_C_CLKDIV, test);
186 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_DISABLE_50, 0);
187 if (err != SC_ERR_NONE)
188 printf("Error in setting up SC_C %d\n\r", SC_C_DISABLE_50);
190 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, &test);
191 debug("TEST SC_C %d-->%d\n\r", SC_C_DISABLE_50, test);
193 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_DISABLE_125, 1);
194 if (err != SC_ERR_NONE)
195 printf("Error in setting up SC_C %d\n\r", SC_C_DISABLE_125);
197 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, &test);
198 debug("TEST SC_C %d-->%d\n\r", SC_C_DISABLE_125, test);
200 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_SEL_125, 1);
201 if (err != SC_ERR_NONE)
202 printf("Error in setting up SC_C %d\n\r", SC_C_SEL_125);
204 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_SEL_125, &test);
205 debug("TEST SC_C %d-->%d\n\r", SC_C_SEL_125, test);
210 #if IS_ENABLED(CONFIG_FEC_MXC)
212 int board_phy_config(struct phy_device *phydev)
214 if (phydev->drv->config)
215 phydev->drv->config(phydev);
222 static int setup_fec(void)
226 enet_device_phy_reset();
230 void reset_cpu(ulong addr)
234 #ifndef CONFIG_SPL_BUILD
236 static int board_led_init(void)
238 struct udevice *bus, *dev;
239 u8 pca_led[2] = { 0x00, 0x00 };
242 /* init all GPIO LED's */
243 if (IS_ENABLED(CONFIG_LED))
246 /* enable all leds on PCA9552 */
247 ret = uclass_get_device_by_seq(UCLASS_I2C, PCA9552_1_I2C_BUS, &bus);
249 printf("ERROR: I2C get %d\n", ret);
253 ret = dm_i2c_probe(bus, PCA9552_1_I2C_ADDR, 0, &dev);
255 printf("ERROR: PCA9552 probe failed\n");
259 ret = dm_i2c_write(dev, 0x16, pca_led, sizeof(pca_led));
261 printf("ERROR: PCA9552 write failed\n");
268 #endif /* !CONFIG_SPL_BUILD */
272 puts("Board: Capricorn\n");
275 * Running build_info() doesn't work with current SCFW blob.
276 * Uncomment below call when new blob is available.
290 #ifdef CONFIG_OF_BOARD_SETUP
291 int ft_board_setup(void *blob, bd_t *bd)
297 int board_mmc_get_env_dev(int devno)
302 static int check_mmc_autodetect(void)
304 char *autodetect_str = env_get("mmcautodetect");
306 if (autodetect_str && (strcmp(autodetect_str, "yes") == 0))
312 /* This should be defined for each board */
313 __weak int mmc_map_to_kernel_blk(int dev_no)
318 void board_late_mmc_env_init(void)
322 u32 dev_no = mmc_get_env_dev();
324 if (!check_mmc_autodetect())
327 env_set_ulong("mmcdev", dev_no);
330 sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw",
331 mmc_map_to_kernel_blk(dev_no));
332 env_set("mmcroot", mmcblk);
334 sprintf(cmd, "mmc dev %d", dev_no);
338 #ifndef CONFIG_SPL_BUILD
339 int factoryset_read_eeprom(int i2c_addr);
341 static int load_parameters_from_factoryset(void)
345 ret = factoryset_read_eeprom(EEPROM_I2C_ADDR);
349 return factoryset_env_set();
352 int board_late_init(void)
354 env_set("sec_boot", "no");
355 #ifdef CONFIG_AHAB_BOOT
356 env_set("sec_boot", "yes");
359 #ifdef CONFIG_ENV_IS_IN_MMC
360 board_late_mmc_env_init();
363 if (board_led_init())
364 printf("I2C LED init failed\n");
366 /* Set environment from factoryset */
367 if (load_parameters_from_factoryset())
368 printf("Loading factoryset parameters failed!\n");
374 #define MAX_PIN_NUMBER 128
375 #define BOARD_DEFAULT_BUTTON_GPIO IMX_GPIO_NR(1, 31)
377 unsigned char get_button_state(char * const envname, unsigned char def)
383 /* If button is not found we take default */
384 ptr_env = env_get(envname);
386 printf("Using default: %u\n", def);
389 gpio = (unsigned char)simple_strtoul(ptr_env, NULL, 0);
390 if (gpio > MAX_PIN_NUMBER)
394 gpio_request(gpio, "");
395 gpio_direction_input(gpio);
396 if (gpio_get_value(gpio))
407 * This command returns the status of the user button on
409 * Returns - 1 if button is held down
410 * 0 if button is not held down
413 do_userbutton(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
417 button = get_button_state("button_usr1", BOARD_DEFAULT_BUTTON_GPIO);
420 printf("Button state: %u\n", button);
426 usrbutton, CONFIG_SYS_MAXARGS, 2, do_userbutton,
427 "Return the status of user button",
431 #define ERST IMX_GPIO_NR(0, 3)
434 do_eth_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
436 gpio_request(ERST, "ERST");
437 gpio_direction_output(ERST, 0);
439 gpio_set_value(ERST, 1);
444 switch_rst, CONFIG_SYS_MAXARGS, 2, do_eth_reset,
448 #endif /* ! CONFIG_SPL_BUILD */