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