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 <linux/delay.h>
31 #include "../common/factoryset.h"
33 #define GPIO_PAD_CTRL \
34 ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
35 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
36 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
37 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
39 #define ENET_NORMAL_PAD_CTRL \
40 ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
41 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
42 (SC_PAD_28FDSOI_DSE_18V_10MA << PADRING_DSE_SHIFT) | \
43 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
45 #define UART_PAD_CTRL \
46 ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \
47 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
48 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
49 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
51 static iomux_cfg_t uart2_pads[] = {
52 SC_P_UART2_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
53 SC_P_UART2_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
56 static void setup_iomux_uart(void)
58 imx8_iomux_setup_multiple_pads(uart2_pads, ARRAY_SIZE(uart2_pads));
61 int board_early_init_f(void)
63 /* Set UART clock root to 80 MHz */
64 sc_pm_clock_rate_t rate = SC_80MHZ;
67 ret = sc_pm_setup_uart(SC_R_UART_0, rate);
68 ret |= sc_pm_setup_uart(SC_R_UART_2, rate);
77 #define ENET_PHY_RESET IMX_GPIO_NR(0, 3)
78 #define ENET_TEST_1 IMX_GPIO_NR(0, 8)
79 #define ENET_TEST_2 IMX_GPIO_NR(0, 9)
81 /*#define ETH_IO_TEST*/
82 static iomux_cfg_t enet_reset[] = {
83 SC_P_ESAI0_SCKT | MUX_MODE_ALT(4) | MUX_PAD_CTRL(GPIO_PAD_CTRL),
85 /* GPIO0.IO08 MODE3: TXD0 */
86 SC_P_ESAI0_TX4_RX1 | MUX_MODE_ALT(4) |
87 MUX_PAD_CTRL(ENET_NORMAL_PAD_CTRL),
88 /* GPIO0.IO09 MODE3: TXD1 */
89 SC_P_ESAI0_TX5_RX0 | MUX_MODE_ALT(4) |
90 MUX_PAD_CTRL(ENET_NORMAL_PAD_CTRL),
94 static void enet_device_phy_reset(void)
98 imx8_iomux_setup_multiple_pads(enet_reset, ARRAY_SIZE(enet_reset));
100 ret = gpio_request(ENET_PHY_RESET, "enet_phy_reset");
102 gpio_direction_output(ENET_PHY_RESET, 1);
103 gpio_set_value(ENET_PHY_RESET, 0);
104 /* SMSC9303 TRM chapter 14.5.2 */
106 gpio_set_value(ENET_PHY_RESET, 1);
108 printf("ENET RESET failed!\n");
112 ret = gpio_request(ENET_TEST_1, "enet_test1");
116 printf("ENET TEST 1!\n");
117 for (i = 0; i < 20; i++) {
118 gpio_direction_output(ENET_TEST_1, 1);
119 gpio_set_value(ENET_TEST_1, 0);
121 gpio_set_value(ENET_TEST_1, 1);
124 gpio_free(ENET_TEST_1);
126 printf("GPIO for ENET TEST 1 failed!\n");
128 ret = gpio_request(ENET_TEST_2, "enet_test2");
132 printf("ENET TEST 2!\n");
133 for (i = 0; i < 20; i++) {
134 gpio_direction_output(ENET_TEST_2, 1);
135 gpio_set_value(ENET_TEST_2, 0);
137 gpio_set_value(ENET_TEST_2, 1);
140 gpio_free(ENET_TEST_2);
142 printf("GPIO for ENET TEST 2 failed!\n");
147 int setup_gpr_fec(void)
149 sc_ipc_t ipc_handle = -1;
154 * TX_CLK_SEL: it controls a mux between clock coming from the pad 50M
155 * input pin and clock generated internally to connectivity subsystem
157 * 1: external clock ---> your choice for RMII
159 * CLKDIV_SEL: it controls a div by 2 on the internal clock path à
160 * it should be don’t care when using external clock
161 * 0: non-divided clock
162 * 1: clock divided by 2
163 * 50_DISABLE or 125_DISABLE:
164 * it’s used to disable the clock tree going outside the chip
165 * when reference clock is generated internally.
166 * It should be don’t care when reference clock is provided
168 * 0: clock is enabled
169 * 1: clock is disabled
173 * SC_C_DISABLE_50 = 26,
174 * SC_C_DISABLE_125 = 27,
177 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, 1);
178 if (err != SC_ERR_NONE)
179 printf("Error in setting up SC_C %d\n\r", SC_C_TXCLK);
181 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, &test);
182 debug("TEST SC_C %d-->%d\n\r", SC_C_TXCLK, test);
184 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_CLKDIV, 0);
185 if (err != SC_ERR_NONE)
186 printf("Error in setting up SC_C %d\n\r", SC_C_CLKDIV);
188 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_CLKDIV, &test);
189 debug("TEST SC_C %d-->%d\n\r", SC_C_CLKDIV, test);
191 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_DISABLE_50, 0);
192 if (err != SC_ERR_NONE)
193 printf("Error in setting up SC_C %d\n\r", SC_C_DISABLE_50);
195 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, &test);
196 debug("TEST SC_C %d-->%d\n\r", SC_C_DISABLE_50, test);
198 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_DISABLE_125, 1);
199 if (err != SC_ERR_NONE)
200 printf("Error in setting up SC_C %d\n\r", SC_C_DISABLE_125);
202 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, &test);
203 debug("TEST SC_C %d-->%d\n\r", SC_C_DISABLE_125, test);
205 err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_SEL_125, 1);
206 if (err != SC_ERR_NONE)
207 printf("Error in setting up SC_C %d\n\r", SC_C_SEL_125);
209 sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_SEL_125, &test);
210 debug("TEST SC_C %d-->%d\n\r", SC_C_SEL_125, test);
215 #if IS_ENABLED(CONFIG_FEC_MXC)
217 int board_phy_config(struct phy_device *phydev)
219 if (phydev->drv->config)
220 phydev->drv->config(phydev);
227 static int setup_fec(void)
231 enet_device_phy_reset();
235 void reset_cpu(ulong addr)
239 #ifndef CONFIG_SPL_BUILD
241 static int board_led_init(void)
243 struct udevice *bus, *dev;
244 u8 pca_led[2] = { 0x00, 0x00 };
247 /* init all GPIO LED's */
248 if (IS_ENABLED(CONFIG_LED))
251 /* enable all leds on PCA9552 */
252 ret = uclass_get_device_by_seq(UCLASS_I2C, PCA9552_1_I2C_BUS, &bus);
254 printf("ERROR: I2C get %d\n", ret);
258 ret = dm_i2c_probe(bus, PCA9552_1_I2C_ADDR, 0, &dev);
260 printf("ERROR: PCA9552 probe failed\n");
264 ret = dm_i2c_write(dev, 0x16, pca_led, sizeof(pca_led));
266 printf("ERROR: PCA9552 write failed\n");
273 #endif /* !CONFIG_SPL_BUILD */
277 puts("Board: Capricorn\n");
280 * Running build_info() doesn't work with current SCFW blob.
281 * Uncomment below call when new blob is available.
295 #ifdef CONFIG_OF_BOARD_SETUP
296 int ft_board_setup(void *blob, bd_t *bd)
302 int board_mmc_get_env_dev(int devno)
307 static int check_mmc_autodetect(void)
309 char *autodetect_str = env_get("mmcautodetect");
311 if (autodetect_str && (strcmp(autodetect_str, "yes") == 0))
317 /* This should be defined for each board */
318 __weak int mmc_map_to_kernel_blk(int dev_no)
323 void board_late_mmc_env_init(void)
327 u32 dev_no = mmc_get_env_dev();
329 if (!check_mmc_autodetect())
332 env_set_ulong("mmcdev", dev_no);
335 sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw",
336 mmc_map_to_kernel_blk(dev_no));
337 env_set("mmcroot", mmcblk);
339 sprintf(cmd, "mmc dev %d", dev_no);
343 #ifndef CONFIG_SPL_BUILD
344 int factoryset_read_eeprom(int i2c_addr);
346 static int load_parameters_from_factoryset(void)
350 ret = factoryset_read_eeprom(EEPROM_I2C_ADDR);
354 return factoryset_env_set();
357 int board_late_init(void)
359 env_set("sec_boot", "no");
360 #ifdef CONFIG_AHAB_BOOT
361 env_set("sec_boot", "yes");
364 #ifdef CONFIG_ENV_IS_IN_MMC
365 board_late_mmc_env_init();
368 if (board_led_init())
369 printf("I2C LED init failed\n");
371 /* Set environment from factoryset */
372 if (load_parameters_from_factoryset())
373 printf("Loading factoryset parameters failed!\n");
379 #define MAX_PIN_NUMBER 128
380 #define BOARD_DEFAULT_BUTTON_GPIO IMX_GPIO_NR(1, 31)
382 unsigned char get_button_state(char * const envname, unsigned char def)
388 /* If button is not found we take default */
389 ptr_env = env_get(envname);
391 printf("Using default: %u\n", def);
394 gpio = (unsigned char)simple_strtoul(ptr_env, NULL, 0);
395 if (gpio > MAX_PIN_NUMBER)
399 gpio_request(gpio, "");
400 gpio_direction_input(gpio);
401 if (gpio_get_value(gpio))
412 * This command returns the status of the user button on
414 * Returns - 1 if button is held down
415 * 0 if button is not held down
418 do_userbutton(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
422 button = get_button_state("button_usr1", BOARD_DEFAULT_BUTTON_GPIO);
425 printf("Button state: %u\n", button);
431 usrbutton, CONFIG_SYS_MAXARGS, 2, do_userbutton,
432 "Return the status of user button",
436 #define ERST IMX_GPIO_NR(0, 3)
439 do_eth_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
441 gpio_request(ERST, "ERST");
442 gpio_direction_output(ERST, 0);
444 gpio_set_value(ERST, 1);
449 switch_rst, CONFIG_SYS_MAXARGS, 2, do_eth_reset,
453 #endif /* ! CONFIG_SPL_BUILD */