Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * XEA iMX28 board |
| 4 | * |
| 5 | * Copyright (C) 2019 DENX Software Engineering |
| 6 | * Lukasz Majewski, DENX Software Engineering, lukma@denx.de |
| 7 | * |
| 8 | * Copyright (C) 2018 DENX Software Engineering |
| 9 | * Måns Rullgård, DENX Software Engineering, mans@mansr.com |
| 10 | * |
| 11 | * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com> |
| 12 | * on behalf of DENX Software Engineering GmbH |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <common.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 17 | #include <fdt_support.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 18 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 19 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 20 | #include <net.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 21 | #include <asm/global_data.h> |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 22 | #include <asm/gpio.h> |
| 23 | #include <asm/io.h> |
| 24 | #include <asm/arch/imx-regs.h> |
| 25 | #include <asm/arch/iomux-mx28.h> |
| 26 | #include <asm/arch/clock.h> |
| 27 | #include <asm/arch/sys_proto.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 28 | #include <linux/delay.h> |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 29 | #include <linux/mii.h> |
| 30 | #include <miiphy.h> |
| 31 | #include <netdev.h> |
| 32 | #include <errno.h> |
| 33 | #include <usb.h> |
| 34 | #include <serial.h> |
| 35 | |
| 36 | #ifdef CONFIG_SPL_BUILD |
| 37 | #include <spl.h> |
| 38 | #endif |
| 39 | |
| 40 | DECLARE_GLOBAL_DATA_PTR; |
| 41 | |
| 42 | /* |
| 43 | * Functions |
| 44 | */ |
| 45 | |
| 46 | static void init_clocks(void) |
| 47 | { |
| 48 | /* IO0 clock at 480MHz */ |
| 49 | mxs_set_ioclk(MXC_IOCLK0, 480000); |
| 50 | /* IO1 clock at 480MHz */ |
| 51 | mxs_set_ioclk(MXC_IOCLK1, 480000); |
| 52 | |
| 53 | /* SSP0 clock at 96MHz */ |
| 54 | mxs_set_sspclk(MXC_SSPCLK0, 96000, 0); |
| 55 | /* SSP2 clock at 160MHz */ |
| 56 | mxs_set_sspclk(MXC_SSPCLK2, 160000, 0); |
| 57 | /* SSP3 clock at 96MHz */ |
| 58 | mxs_set_sspclk(MXC_SSPCLK3, 96000, 0); |
| 59 | } |
| 60 | |
Lukasz Majewski | 0920716 | 2021-12-27 11:38:21 +0100 | [diff] [blame] | 61 | #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_FRAMEWORK) |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 62 | void board_init_f(ulong arg) |
| 63 | { |
| 64 | init_clocks(); |
Lukasz Majewski | bc6026d | 2023-05-19 12:43:55 +0200 | [diff] [blame^] | 65 | spl_early_init(); |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 66 | preloader_console_init(); |
| 67 | } |
| 68 | |
| 69 | static int boot_tiva0, boot_tiva1; |
| 70 | |
| 71 | /* Check if TIVAs request booting via U-Boot proper */ |
| 72 | void spl_board_init(void) |
| 73 | { |
Lukasz Majewski | 07adfb1 | 2020-01-25 09:01:39 +0100 | [diff] [blame] | 74 | struct gpio_desc btiva0, btiva1, en_3_3v; |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 75 | int ret; |
| 76 | |
Lukasz Majewski | 07adfb1 | 2020-01-25 09:01:39 +0100 | [diff] [blame] | 77 | /* |
| 78 | * Setup GPIO0_0 (TIVA power enable pin) to be output high |
| 79 | * to allow TIVA startup. |
| 80 | */ |
| 81 | ret = dm_gpio_lookup_name("GPIO0_0", &en_3_3v); |
| 82 | if (ret) |
| 83 | printf("Cannot get GPIO0_0\n"); |
| 84 | |
| 85 | ret = dm_gpio_request(&en_3_3v, "pwr_3_3v"); |
| 86 | if (ret) |
| 87 | printf("Cannot request GPIO0_0\n"); |
| 88 | |
| 89 | /* Set GPIO0_0 to HIGH */ |
| 90 | dm_gpio_set_dir_flags(&en_3_3v, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 91 | |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 92 | ret = dm_gpio_lookup_name("GPIO0_23", &btiva0); |
| 93 | if (ret) |
| 94 | printf("Cannot get GPIO0_23\n"); |
| 95 | |
| 96 | ret = dm_gpio_lookup_name("GPIO0_25", &btiva1); |
| 97 | if (ret) |
| 98 | printf("Cannot get GPIO0_25\n"); |
| 99 | |
| 100 | ret = dm_gpio_request(&btiva0, "boot-tiva0"); |
| 101 | if (ret) |
| 102 | printf("Cannot request GPIO0_23\n"); |
| 103 | |
| 104 | ret = dm_gpio_request(&btiva1, "boot-tiva1"); |
| 105 | if (ret) |
| 106 | printf("Cannot request GPIO0_25\n"); |
| 107 | |
| 108 | dm_gpio_set_dir_flags(&btiva0, GPIOD_IS_IN); |
| 109 | dm_gpio_set_dir_flags(&btiva1, GPIOD_IS_IN); |
| 110 | |
| 111 | udelay(1000); |
| 112 | |
| 113 | boot_tiva0 = dm_gpio_get_value(&btiva0); |
| 114 | boot_tiva1 = dm_gpio_get_value(&btiva1); |
| 115 | } |
| 116 | |
| 117 | void board_boot_order(u32 *spl_boot_list) |
| 118 | { |
| 119 | spl_boot_list[0] = BOOT_DEVICE_MMC1; |
| 120 | spl_boot_list[1] = BOOT_DEVICE_SPI; |
Lukasz Majewski | 27458d2 | 2020-07-10 09:49:32 +0200 | [diff] [blame] | 121 | spl_boot_list[2] = BOOT_DEVICE_UART; |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | int spl_start_uboot(void) |
| 125 | { |
| 126 | /* break into full u-boot on 'c' */ |
| 127 | if (serial_tstc() && serial_getc() == 'c') |
| 128 | return 1; |
| 129 | |
| 130 | debug("%s: btiva0: %d btiva1: %d\n", __func__, boot_tiva0, boot_tiva1); |
| 131 | return !boot_tiva0 || !boot_tiva1; |
| 132 | } |
| 133 | #else |
| 134 | |
| 135 | int board_early_init_f(void) |
| 136 | { |
| 137 | init_clocks(); |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | int board_init(void) |
| 143 | { |
| 144 | struct gpio_desc phy_rst; |
| 145 | int ret; |
| 146 | |
| 147 | /* Address of boot parameters */ |
| 148 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 149 | |
| 150 | cpu_eth_init(NULL); |
| 151 | |
| 152 | /* PHY INT#/PWDN# */ |
| 153 | ret = dm_gpio_lookup_name("GPIO4_13", &phy_rst); |
| 154 | if (ret) { |
| 155 | printf("Cannot get GPIO4_13\n"); |
| 156 | return ret; |
| 157 | } |
| 158 | |
| 159 | ret = dm_gpio_request(&phy_rst, "phy-rst"); |
| 160 | if (ret) { |
| 161 | printf("Cannot request GPIO4_13\n"); |
| 162 | return ret; |
| 163 | } |
| 164 | |
| 165 | dm_gpio_set_dir_flags(&phy_rst, GPIOD_IS_IN); |
| 166 | udelay(1000); |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | int dram_init(void) |
| 172 | { |
| 173 | return mxs_dram_init(); |
| 174 | } |
| 175 | |
Lukasz Majewski | 363cd97 | 2020-01-25 09:01:37 +0100 | [diff] [blame] | 176 | #ifdef CONFIG_OF_BOARD_SETUP |
| 177 | static int fdt_fixup_l2switch(void *blob) |
| 178 | { |
| 179 | u8 ethaddr[6]; |
| 180 | int ret; |
| 181 | |
| 182 | if (eth_env_get_enetaddr("ethaddr", ethaddr)) { |
| 183 | ret = fdt_find_and_setprop(blob, |
| 184 | "/ahb@80080000/switch@800f0000", |
| 185 | "local-mac-address", ethaddr, 6, 1); |
| 186 | if (ret < 0) |
| 187 | printf("%s: can't find usbether@1 node: %d\n", |
| 188 | __func__, ret); |
| 189 | } |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 194 | int ft_board_setup(void *blob, struct bd_info *bd) |
Lukasz Majewski | 363cd97 | 2020-01-25 09:01:37 +0100 | [diff] [blame] | 195 | { |
| 196 | /* |
| 197 | * i.MX28 L2 switch needs manual update (fixup) of eth MAC address |
| 198 | * (in 'local-mac-address' property) as it uses "switch@800f0000" |
| 199 | * node, not set by default FIT image handling code in |
| 200 | * "ethernet@800f0000" |
| 201 | */ |
| 202 | fdt_fixup_l2switch(blob); |
| 203 | |
| 204 | return 0; |
| 205 | } |
| 206 | #endif |
Lukasz Majewski | d70cd28 | 2023-05-19 12:43:46 +0200 | [diff] [blame] | 207 | /* |
| 208 | * NOTE: |
| 209 | * |
| 210 | * IMX28 clock "stub" DM driver! |
| 211 | * |
| 212 | * Only used for SPL stage, which is NOT using DM; serial and |
| 213 | * eMMC configuration. |
| 214 | */ |
| 215 | static const struct udevice_id imx28_clk_ids[] = { |
| 216 | { .compatible = "fsl,imx28-clkctrl", }, |
| 217 | { } |
| 218 | }; |
Lukasz Majewski | 363cd97 | 2020-01-25 09:01:37 +0100 | [diff] [blame] | 219 | |
Lukasz Majewski | d70cd28 | 2023-05-19 12:43:46 +0200 | [diff] [blame] | 220 | U_BOOT_DRIVER(fsl_imx28_clkctrl) = { |
| 221 | .name = "fsl_imx28_clkctrl", |
| 222 | .id = UCLASS_CLK, |
| 223 | .of_match = imx28_clk_ids, |
| 224 | }; |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 225 | #endif /* CONFIG_SPL_BUILD */ |