1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2017-2019 NXP
5 * Copyright 2019 Siemens AG
16 #include <env_internal.h>
17 #include <fsl_esdhc_imx.h>
21 #include <power-domain.h>
23 #include <asm/arch/imx8-pins.h>
24 #include <asm/arch/iomux.h>
25 #include <asm/arch/sci/sci.h>
26 #include <asm/arch/sys_proto.h>
28 #include <asm/arch-imx8/clock.h>
30 #include "../common/factoryset.h"
32 #define GPIO_PAD_CTRL \
33 ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
34 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
35 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
36 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
38 #define ENET_NORMAL_PAD_CTRL \
39 ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
40 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
41 (SC_PAD_28FDSOI_DSE_18V_10MA << PADRING_DSE_SHIFT) | \
42 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
44 #define UART_PAD_CTRL \
45 ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \
46 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
47 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
48 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
50 static iomux_cfg_t uart2_pads[] = {
51 SC_P_UART2_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
52 SC_P_UART2_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
55 static void setup_iomux_uart(void)
57 imx8_iomux_setup_multiple_pads(uart2_pads, ARRAY_SIZE(uart2_pads));
60 int board_early_init_f(void)
62 /* Set UART clock root to 80 MHz */
63 sc_pm_clock_rate_t rate = SC_80MHZ;
66 ret = sc_pm_setup_uart(SC_R_UART_0, rate);
67 ret |= sc_pm_setup_uart(SC_R_UART_2, rate);
76 #define ENET_PHY_RESET IMX_GPIO_NR(0, 3)
77 #define ENET_TEST_1 IMX_GPIO_NR(0, 8)
78 #define ENET_TEST_2 IMX_GPIO_NR(0, 9)
80 /*#define ETH_IO_TEST*/
81 static iomux_cfg_t enet_reset[] = {
82 SC_P_ESAI0_SCKT | MUX_MODE_ALT(4) | MUX_PAD_CTRL(GPIO_PAD_CTRL),
84 /* GPIO0.IO08 MODE3: TXD0 */
85 SC_P_ESAI0_TX4_RX1 | MUX_MODE_ALT(4) |
86 MUX_PAD_CTRL(ENET_NORMAL_PAD_CTRL),
87 /* GPIO0.IO09 MODE3: TXD1 */
88 SC_P_ESAI0_TX5_RX0 | MUX_MODE_ALT(4) |
89 MUX_PAD_CTRL(ENET_NORMAL_PAD_CTRL),
93 static void enet_device_phy_reset(void)
97 imx8_iomux_setup_multiple_pads(enet_reset, ARRAY_SIZE(enet_reset));
99 ret = gpio_request(ENET_PHY_RESET, "enet_phy_reset");
101 gpio_direction_output(ENET_PHY_RESET, 1);
102 gpio_set_value(ENET_PHY_RESET, 0);
103 /* SMSC9303 TRM chapter 14.5.2 */
105 gpio_set_value(ENET_PHY_RESET, 1);
107 printf("ENET RESET failed!\n");
111 ret = gpio_request(ENET_TEST_1, "enet_test1");
115 printf("ENET TEST 1!\n");
116 for (i = 0; i < 20; i++) {
117 gpio_direction_output(ENET_TEST_1, 1);
118 gpio_set_value(ENET_TEST_1, 0);
120 gpio_set_value(ENET_TEST_1, 1);
123 gpio_free(ENET_TEST_1);
125 printf("GPIO for ENET TEST 1 failed!\n");
127 ret = gpio_request(ENET_TEST_2, "enet_test2");
131 printf("ENET TEST 2!\n");
132 for (i = 0; i < 20; i++) {
133 gpio_direction_output(ENET_TEST_2, 1);
134 gpio_set_value(ENET_TEST_2, 0);
136 gpio_set_value(ENET_TEST_2, 1);
139 gpio_free(ENET_TEST_2);
141 printf("GPIO for ENET TEST 2 failed!\n");
146 int setup_gpr_fec(void)
148 sc_ipc_t ipc_handle = -1;
153 * TX_CLK_SEL: it controls a mux between clock coming from the pad 50M
154 * input pin and clock generated internally to connectivity subsystem
156 * 1: external clock ---> your choice for RMII
158 * CLKDIV_SEL: it controls a div by 2 on the internal clock path à
159 * it should be don’t care when using external clock
160 * 0: non-divided clock
161 * 1: clock divided by 2
162 * 50_DISABLE or 125_DISABLE:
163 * it’s used to disable the clock tree going outside the chip
164 * when reference clock is generated internally.
165 * It should be don’t care when reference clock is provided
167 * 0: clock is enabled
168 * 1: clock is disabled
172 * SC_C_DISABLE_50 = 26,
173 * SC_C_DISABLE_125 = 27,
176 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, 1);
177 if (err != SC_ERR_NONE)
178 printf("Error in setting up SC_C %d\n\r", SC_C_TXCLK);
180 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, &test);
181 debug("TEST SC_C %d-->%d\n\r", SC_C_TXCLK, test);
183 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_CLKDIV, 0);
184 if (err != SC_ERR_NONE)
185 printf("Error in setting up SC_C %d\n\r", SC_C_CLKDIV);
187 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_CLKDIV, &test);
188 debug("TEST SC_C %d-->%d\n\r", SC_C_CLKDIV, test);
190 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_DISABLE_50, 0);
191 if (err != SC_ERR_NONE)
192 printf("Error in setting up SC_C %d\n\r", SC_C_DISABLE_50);
194 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, &test);
195 debug("TEST SC_C %d-->%d\n\r", SC_C_DISABLE_50, test);
197 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_DISABLE_125, 1);
198 if (err != SC_ERR_NONE)
199 printf("Error in setting up SC_C %d\n\r", SC_C_DISABLE_125);
201 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, &test);
202 debug("TEST SC_C %d-->%d\n\r", SC_C_DISABLE_125, test);
204 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_SEL_125, 1);
205 if (err != SC_ERR_NONE)
206 printf("Error in setting up SC_C %d\n\r", SC_C_SEL_125);
208 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_SEL_125, &test);
209 debug("TEST SC_C %d-->%d\n\r", SC_C_SEL_125, test);
214 #if IS_ENABLED(CONFIG_FEC_MXC)
216 int board_phy_config(struct phy_device *phydev)
218 if (phydev->drv->config)
219 phydev->drv->config(phydev);
226 static int setup_fec(void)
230 enet_device_phy_reset();
234 void reset_cpu(ulong addr)
238 #ifndef CONFIG_SPL_BUILD
240 static int board_led_init(void)
242 struct udevice *bus, *dev;
243 u8 pca_led[2] = { 0x00, 0x00 };
246 /* init all GPIO LED's */
247 if (IS_ENABLED(CONFIG_LED))
250 /* enable all leds on PCA9552 */
251 ret = uclass_get_device_by_seq(UCLASS_I2C, PCA9552_1_I2C_BUS, &bus);
253 printf("ERROR: I2C get %d\n", ret);
257 ret = dm_i2c_probe(bus, PCA9552_1_I2C_ADDR, 0, &dev);
259 printf("ERROR: PCA9552 probe failed\n");
263 ret = dm_i2c_write(dev, 0x16, pca_led, sizeof(pca_led));
265 printf("ERROR: PCA9552 write failed\n");
272 #endif /* !CONFIG_SPL_BUILD */
276 puts("Board: Capricorn\n");
279 * Running build_info() doesn't work with current SCFW blob.
280 * Uncomment below call when new blob is available.
294 #ifdef CONFIG_OF_BOARD_SETUP
295 int ft_board_setup(void *blob, bd_t *bd)
301 int board_mmc_get_env_dev(int devno)
306 static int check_mmc_autodetect(void)
308 char *autodetect_str = env_get("mmcautodetect");
310 if (autodetect_str && (strcmp(autodetect_str, "yes") == 0))
316 /* This should be defined for each board */
317 __weak int mmc_map_to_kernel_blk(int dev_no)
322 void board_late_mmc_env_init(void)
326 u32 dev_no = mmc_get_env_dev();
328 if (!check_mmc_autodetect())
331 env_set_ulong("mmcdev", dev_no);
334 sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw",
335 mmc_map_to_kernel_blk(dev_no));
336 env_set("mmcroot", mmcblk);
338 sprintf(cmd, "mmc dev %d", dev_no);
342 #ifndef CONFIG_SPL_BUILD
343 int factoryset_read_eeprom(int i2c_addr);
345 static int load_parameters_from_factoryset(void)
349 ret = factoryset_read_eeprom(EEPROM_I2C_ADDR);
353 return factoryset_env_set();
356 int board_late_init(void)
358 env_set("sec_boot", "no");
359 #ifdef CONFIG_AHAB_BOOT
360 env_set("sec_boot", "yes");
363 #ifdef CONFIG_ENV_IS_IN_MMC
364 board_late_mmc_env_init();
367 if (board_led_init())
368 printf("I2C LED init failed\n");
370 /* Set environment from factoryset */
371 if (load_parameters_from_factoryset())
372 printf("Loading factoryset parameters failed!\n");
378 #define MAX_PIN_NUMBER 128
379 #define BOARD_DEFAULT_BUTTON_GPIO IMX_GPIO_NR(1, 31)
381 unsigned char get_button_state(char * const envname, unsigned char def)
387 /* If button is not found we take default */
388 ptr_env = env_get(envname);
390 printf("Using default: %u\n", def);
393 gpio = (unsigned char)simple_strtoul(ptr_env, NULL, 0);
394 if (gpio > MAX_PIN_NUMBER)
398 gpio_request(gpio, "");
399 gpio_direction_input(gpio);
400 if (gpio_get_value(gpio))
411 * This command returns the status of the user button on
413 * Returns - 1 if button is held down
414 * 0 if button is not held down
417 do_userbutton(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
421 button = get_button_state("button_usr1", BOARD_DEFAULT_BUTTON_GPIO);
424 printf("Button state: %u\n", button);
430 usrbutton, CONFIG_SYS_MAXARGS, 2, do_userbutton,
431 "Return the status of user button",
435 #define ERST IMX_GPIO_NR(0, 3)
438 do_eth_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
440 gpio_request(ERST, "ERST");
441 gpio_direction_output(ERST, 0);
443 gpio_set_value(ERST, 1);
448 switch_rst, CONFIG_SYS_MAXARGS, 2, do_eth_reset,
452 #endif /* ! CONFIG_SPL_BUILD */