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> |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 21 | #include <asm/gpio.h> |
| 22 | #include <asm/io.h> |
| 23 | #include <asm/arch/imx-regs.h> |
| 24 | #include <asm/arch/iomux-mx28.h> |
| 25 | #include <asm/arch/clock.h> |
| 26 | #include <asm/arch/sys_proto.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 27 | #include <linux/delay.h> |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 28 | #include <linux/mii.h> |
| 29 | #include <miiphy.h> |
| 30 | #include <netdev.h> |
| 31 | #include <errno.h> |
| 32 | #include <usb.h> |
| 33 | #include <serial.h> |
| 34 | |
| 35 | #ifdef CONFIG_SPL_BUILD |
| 36 | #include <spl.h> |
| 37 | #endif |
| 38 | |
| 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
| 41 | /* |
| 42 | * Functions |
| 43 | */ |
| 44 | |
| 45 | static void init_clocks(void) |
| 46 | { |
| 47 | /* IO0 clock at 480MHz */ |
| 48 | mxs_set_ioclk(MXC_IOCLK0, 480000); |
| 49 | /* IO1 clock at 480MHz */ |
| 50 | mxs_set_ioclk(MXC_IOCLK1, 480000); |
| 51 | |
| 52 | /* SSP0 clock at 96MHz */ |
| 53 | mxs_set_sspclk(MXC_SSPCLK0, 96000, 0); |
| 54 | /* SSP2 clock at 160MHz */ |
| 55 | mxs_set_sspclk(MXC_SSPCLK2, 160000, 0); |
| 56 | /* SSP3 clock at 96MHz */ |
| 57 | mxs_set_sspclk(MXC_SSPCLK3, 96000, 0); |
| 58 | } |
| 59 | |
| 60 | #ifdef CONFIG_SPL_BUILD |
| 61 | void board_init_f(ulong arg) |
| 62 | { |
| 63 | init_clocks(); |
| 64 | preloader_console_init(); |
| 65 | } |
| 66 | |
| 67 | static int boot_tiva0, boot_tiva1; |
| 68 | |
| 69 | /* Check if TIVAs request booting via U-Boot proper */ |
| 70 | void spl_board_init(void) |
| 71 | { |
Lukasz Majewski | 07adfb1 | 2020-01-25 09:01:39 +0100 | [diff] [blame] | 72 | struct gpio_desc btiva0, btiva1, en_3_3v; |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 73 | int ret; |
| 74 | |
Lukasz Majewski | 07adfb1 | 2020-01-25 09:01:39 +0100 | [diff] [blame] | 75 | /* |
| 76 | * Setup GPIO0_0 (TIVA power enable pin) to be output high |
| 77 | * to allow TIVA startup. |
| 78 | */ |
| 79 | ret = dm_gpio_lookup_name("GPIO0_0", &en_3_3v); |
| 80 | if (ret) |
| 81 | printf("Cannot get GPIO0_0\n"); |
| 82 | |
| 83 | ret = dm_gpio_request(&en_3_3v, "pwr_3_3v"); |
| 84 | if (ret) |
| 85 | printf("Cannot request GPIO0_0\n"); |
| 86 | |
| 87 | /* Set GPIO0_0 to HIGH */ |
| 88 | dm_gpio_set_dir_flags(&en_3_3v, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 89 | |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 90 | ret = dm_gpio_lookup_name("GPIO0_23", &btiva0); |
| 91 | if (ret) |
| 92 | printf("Cannot get GPIO0_23\n"); |
| 93 | |
| 94 | ret = dm_gpio_lookup_name("GPIO0_25", &btiva1); |
| 95 | if (ret) |
| 96 | printf("Cannot get GPIO0_25\n"); |
| 97 | |
| 98 | ret = dm_gpio_request(&btiva0, "boot-tiva0"); |
| 99 | if (ret) |
| 100 | printf("Cannot request GPIO0_23\n"); |
| 101 | |
| 102 | ret = dm_gpio_request(&btiva1, "boot-tiva1"); |
| 103 | if (ret) |
| 104 | printf("Cannot request GPIO0_25\n"); |
| 105 | |
| 106 | dm_gpio_set_dir_flags(&btiva0, GPIOD_IS_IN); |
| 107 | dm_gpio_set_dir_flags(&btiva1, GPIOD_IS_IN); |
| 108 | |
| 109 | udelay(1000); |
| 110 | |
| 111 | boot_tiva0 = dm_gpio_get_value(&btiva0); |
| 112 | boot_tiva1 = dm_gpio_get_value(&btiva1); |
| 113 | } |
| 114 | |
| 115 | void board_boot_order(u32 *spl_boot_list) |
| 116 | { |
| 117 | spl_boot_list[0] = BOOT_DEVICE_MMC1; |
| 118 | spl_boot_list[1] = BOOT_DEVICE_SPI; |
Lukasz Majewski | 27458d2 | 2020-07-10 09:49:32 +0200 | [diff] [blame] | 119 | spl_boot_list[2] = BOOT_DEVICE_UART; |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | int spl_start_uboot(void) |
| 123 | { |
| 124 | /* break into full u-boot on 'c' */ |
| 125 | if (serial_tstc() && serial_getc() == 'c') |
| 126 | return 1; |
| 127 | |
| 128 | debug("%s: btiva0: %d btiva1: %d\n", __func__, boot_tiva0, boot_tiva1); |
| 129 | return !boot_tiva0 || !boot_tiva1; |
| 130 | } |
| 131 | #else |
| 132 | |
| 133 | int board_early_init_f(void) |
| 134 | { |
| 135 | init_clocks(); |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | int board_init(void) |
| 141 | { |
| 142 | struct gpio_desc phy_rst; |
| 143 | int ret; |
| 144 | |
| 145 | /* Address of boot parameters */ |
| 146 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 147 | |
| 148 | cpu_eth_init(NULL); |
| 149 | |
| 150 | /* PHY INT#/PWDN# */ |
| 151 | ret = dm_gpio_lookup_name("GPIO4_13", &phy_rst); |
| 152 | if (ret) { |
| 153 | printf("Cannot get GPIO4_13\n"); |
| 154 | return ret; |
| 155 | } |
| 156 | |
| 157 | ret = dm_gpio_request(&phy_rst, "phy-rst"); |
| 158 | if (ret) { |
| 159 | printf("Cannot request GPIO4_13\n"); |
| 160 | return ret; |
| 161 | } |
| 162 | |
| 163 | dm_gpio_set_dir_flags(&phy_rst, GPIOD_IS_IN); |
| 164 | udelay(1000); |
| 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | int dram_init(void) |
| 170 | { |
| 171 | return mxs_dram_init(); |
| 172 | } |
| 173 | |
Lukasz Majewski | 363cd97 | 2020-01-25 09:01:37 +0100 | [diff] [blame] | 174 | #ifdef CONFIG_OF_BOARD_SETUP |
| 175 | static int fdt_fixup_l2switch(void *blob) |
| 176 | { |
| 177 | u8 ethaddr[6]; |
| 178 | int ret; |
| 179 | |
| 180 | if (eth_env_get_enetaddr("ethaddr", ethaddr)) { |
| 181 | ret = fdt_find_and_setprop(blob, |
| 182 | "/ahb@80080000/switch@800f0000", |
| 183 | "local-mac-address", ethaddr, 6, 1); |
| 184 | if (ret < 0) |
| 185 | printf("%s: can't find usbether@1 node: %d\n", |
| 186 | __func__, ret); |
| 187 | } |
| 188 | |
| 189 | return 0; |
| 190 | } |
| 191 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 192 | int ft_board_setup(void *blob, struct bd_info *bd) |
Lukasz Majewski | 363cd97 | 2020-01-25 09:01:37 +0100 | [diff] [blame] | 193 | { |
| 194 | /* |
| 195 | * i.MX28 L2 switch needs manual update (fixup) of eth MAC address |
| 196 | * (in 'local-mac-address' property) as it uses "switch@800f0000" |
| 197 | * node, not set by default FIT image handling code in |
| 198 | * "ethernet@800f0000" |
| 199 | */ |
| 200 | fdt_fixup_l2switch(blob); |
| 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | #endif |
| 205 | |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 206 | #endif /* CONFIG_SPL_BUILD */ |