1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2017-2019 NXP
5 * Copyright 2019 Siemens AG
15 #include <env_internal.h>
16 #include <fsl_esdhc_imx.h>
20 #include <power-domain.h>
22 #include <asm/arch/imx8-pins.h>
23 #include <asm/arch/iomux.h>
24 #include <asm/arch/sci/sci.h>
25 #include <asm/arch/sys_proto.h>
27 #include <asm/arch-imx8/clock.h>
29 #include "../common/factoryset.h"
31 #define GPIO_PAD_CTRL \
32 ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
33 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
34 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
35 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
37 #define ENET_NORMAL_PAD_CTRL \
38 ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
39 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
40 (SC_PAD_28FDSOI_DSE_18V_10MA << PADRING_DSE_SHIFT) | \
41 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
43 #define UART_PAD_CTRL \
44 ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \
45 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
46 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
47 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
49 static iomux_cfg_t uart2_pads[] = {
50 SC_P_UART2_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
51 SC_P_UART2_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
54 static void setup_iomux_uart(void)
56 imx8_iomux_setup_multiple_pads(uart2_pads, ARRAY_SIZE(uart2_pads));
59 int board_early_init_f(void)
61 /* Set UART clock root to 80 MHz */
62 sc_pm_clock_rate_t rate = SC_80MHZ;
65 ret = sc_pm_setup_uart(SC_R_UART_0, rate);
66 ret |= sc_pm_setup_uart(SC_R_UART_2, rate);
75 #define ENET_PHY_RESET IMX_GPIO_NR(0, 3)
76 #define ENET_TEST_1 IMX_GPIO_NR(0, 8)
77 #define ENET_TEST_2 IMX_GPIO_NR(0, 9)
79 /*#define ETH_IO_TEST*/
80 static iomux_cfg_t enet_reset[] = {
81 SC_P_ESAI0_SCKT | MUX_MODE_ALT(4) | MUX_PAD_CTRL(GPIO_PAD_CTRL),
83 /* GPIO0.IO08 MODE3: TXD0 */
84 SC_P_ESAI0_TX4_RX1 | MUX_MODE_ALT(4) |
85 MUX_PAD_CTRL(ENET_NORMAL_PAD_CTRL),
86 /* GPIO0.IO09 MODE3: TXD1 */
87 SC_P_ESAI0_TX5_RX0 | MUX_MODE_ALT(4) |
88 MUX_PAD_CTRL(ENET_NORMAL_PAD_CTRL),
92 static void enet_device_phy_reset(void)
96 imx8_iomux_setup_multiple_pads(enet_reset, ARRAY_SIZE(enet_reset));
98 ret = gpio_request(ENET_PHY_RESET, "enet_phy_reset");
100 gpio_direction_output(ENET_PHY_RESET, 1);
101 gpio_set_value(ENET_PHY_RESET, 0);
102 /* SMSC9303 TRM chapter 14.5.2 */
104 gpio_set_value(ENET_PHY_RESET, 1);
106 printf("ENET RESET failed!\n");
110 ret = gpio_request(ENET_TEST_1, "enet_test1");
114 printf("ENET TEST 1!\n");
115 for (i = 0; i < 20; i++) {
116 gpio_direction_output(ENET_TEST_1, 1);
117 gpio_set_value(ENET_TEST_1, 0);
119 gpio_set_value(ENET_TEST_1, 1);
122 gpio_free(ENET_TEST_1);
124 printf("GPIO for ENET TEST 1 failed!\n");
126 ret = gpio_request(ENET_TEST_2, "enet_test2");
130 printf("ENET TEST 2!\n");
131 for (i = 0; i < 20; i++) {
132 gpio_direction_output(ENET_TEST_2, 1);
133 gpio_set_value(ENET_TEST_2, 0);
135 gpio_set_value(ENET_TEST_2, 1);
138 gpio_free(ENET_TEST_2);
140 printf("GPIO for ENET TEST 2 failed!\n");
145 int setup_gpr_fec(void)
147 sc_ipc_t ipc_handle = -1;
152 * TX_CLK_SEL: it controls a mux between clock coming from the pad 50M
153 * input pin and clock generated internally to connectivity subsystem
155 * 1: external clock ---> your choice for RMII
157 * CLKDIV_SEL: it controls a div by 2 on the internal clock path à
158 * it should be don’t care when using external clock
159 * 0: non-divided clock
160 * 1: clock divided by 2
161 * 50_DISABLE or 125_DISABLE:
162 * it’s used to disable the clock tree going outside the chip
163 * when reference clock is generated internally.
164 * It should be don’t care when reference clock is provided
166 * 0: clock is enabled
167 * 1: clock is disabled
171 * SC_C_DISABLE_50 = 26,
172 * SC_C_DISABLE_125 = 27,
175 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, 1);
176 if (err != SC_ERR_NONE)
177 printf("Error in setting up SC_C %d\n\r", SC_C_TXCLK);
179 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, &test);
180 debug("TEST SC_C %d-->%d\n\r", SC_C_TXCLK, test);
182 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_CLKDIV, 0);
183 if (err != SC_ERR_NONE)
184 printf("Error in setting up SC_C %d\n\r", SC_C_CLKDIV);
186 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_CLKDIV, &test);
187 debug("TEST SC_C %d-->%d\n\r", SC_C_CLKDIV, test);
189 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_DISABLE_50, 0);
190 if (err != SC_ERR_NONE)
191 printf("Error in setting up SC_C %d\n\r", SC_C_DISABLE_50);
193 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, &test);
194 debug("TEST SC_C %d-->%d\n\r", SC_C_DISABLE_50, test);
196 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_DISABLE_125, 1);
197 if (err != SC_ERR_NONE)
198 printf("Error in setting up SC_C %d\n\r", SC_C_DISABLE_125);
200 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, &test);
201 debug("TEST SC_C %d-->%d\n\r", SC_C_DISABLE_125, test);
203 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_SEL_125, 1);
204 if (err != SC_ERR_NONE)
205 printf("Error in setting up SC_C %d\n\r", SC_C_SEL_125);
207 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_SEL_125, &test);
208 debug("TEST SC_C %d-->%d\n\r", SC_C_SEL_125, test);
213 #if IS_ENABLED(CONFIG_FEC_MXC)
215 int board_phy_config(struct phy_device *phydev)
217 if (phydev->drv->config)
218 phydev->drv->config(phydev);
225 static int setup_fec(void)
229 enet_device_phy_reset();
233 void reset_cpu(ulong addr)
237 #ifndef CONFIG_SPL_BUILD
239 static int board_led_init(void)
241 struct udevice *bus, *dev;
242 u8 pca_led[2] = { 0x00, 0x00 };
245 /* init all GPIO LED's */
246 if (IS_ENABLED(CONFIG_LED))
249 /* enable all leds on PCA9552 */
250 ret = uclass_get_device_by_seq(UCLASS_I2C, PCA9552_1_I2C_BUS, &bus);
252 printf("ERROR: I2C get %d\n", ret);
256 ret = dm_i2c_probe(bus, PCA9552_1_I2C_ADDR, 0, &dev);
258 printf("ERROR: PCA9552 probe failed\n");
262 ret = dm_i2c_write(dev, 0x16, pca_led, sizeof(pca_led));
264 printf("ERROR: PCA9552 write failed\n");
271 #endif /* !CONFIG_SPL_BUILD */
275 puts("Board: Capricorn\n");
278 * Running build_info() doesn't work with current SCFW blob.
279 * Uncomment below call when new blob is available.
293 #ifdef CONFIG_OF_BOARD_SETUP
294 int ft_board_setup(void *blob, bd_t *bd)
300 int board_mmc_get_env_dev(int devno)
305 static int check_mmc_autodetect(void)
307 char *autodetect_str = env_get("mmcautodetect");
309 if (autodetect_str && (strcmp(autodetect_str, "yes") == 0))
315 /* This should be defined for each board */
316 __weak int mmc_map_to_kernel_blk(int dev_no)
321 void board_late_mmc_env_init(void)
325 u32 dev_no = mmc_get_env_dev();
327 if (!check_mmc_autodetect())
330 env_set_ulong("mmcdev", dev_no);
333 sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw",
334 mmc_map_to_kernel_blk(dev_no));
335 env_set("mmcroot", mmcblk);
337 sprintf(cmd, "mmc dev %d", dev_no);
341 #ifndef CONFIG_SPL_BUILD
342 int factoryset_read_eeprom(int i2c_addr);
344 static int load_parameters_from_factoryset(void)
348 ret = factoryset_read_eeprom(EEPROM_I2C_ADDR);
352 return factoryset_env_set();
355 int board_late_init(void)
357 env_set("sec_boot", "no");
358 #ifdef CONFIG_AHAB_BOOT
359 env_set("sec_boot", "yes");
362 #ifdef CONFIG_ENV_IS_IN_MMC
363 board_late_mmc_env_init();
366 if (board_led_init())
367 printf("I2C LED init failed\n");
369 /* Set environment from factoryset */
370 if (load_parameters_from_factoryset())
371 printf("Loading factoryset parameters failed!\n");
377 #define MAX_PIN_NUMBER 128
378 #define BOARD_DEFAULT_BUTTON_GPIO IMX_GPIO_NR(1, 31)
380 unsigned char get_button_state(char * const envname, unsigned char def)
386 /* If button is not found we take default */
387 ptr_env = env_get(envname);
389 printf("Using default: %u\n", def);
392 gpio = (unsigned char)simple_strtoul(ptr_env, NULL, 0);
393 if (gpio > MAX_PIN_NUMBER)
397 gpio_request(gpio, "");
398 gpio_direction_input(gpio);
399 if (gpio_get_value(gpio))
410 * This command returns the status of the user button on
412 * Returns - 1 if button is held down
413 * 0 if button is not held down
416 do_userbutton(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
420 button = get_button_state("button_usr1", BOARD_DEFAULT_BUTTON_GPIO);
423 printf("Button state: %u\n", button);
429 usrbutton, CONFIG_SYS_MAXARGS, 2, do_userbutton,
430 "Return the status of user button",
434 #define ERST IMX_GPIO_NR(0, 3)
437 do_eth_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
439 gpio_request(ERST, "ERST");
440 gpio_direction_output(ERST, 0);
442 gpio_set_value(ERST, 1);
447 switch_rst, CONFIG_SYS_MAXARGS, 2, do_eth_reset,
451 #endif /* ! CONFIG_SPL_BUILD */