Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2012-2013 Henrik Nordstrom <henrik@henriknordstrom.net> |
| 3 | * (C) Copyright 2013 Luke Kenneth Casson Leighton <lkcl@lkcl.net> |
| 4 | * |
| 5 | * (C) Copyright 2007-2011 |
| 6 | * Allwinner Technology Co., Ltd. <www.allwinnertech.com> |
| 7 | * Tom Cubie <tangliang@allwinnertech.com> |
| 8 | * |
| 9 | * Some board init for the Allwinner A10-evb board. |
| 10 | * |
| 11 | * SPDX-License-Identifier: GPL-2.0+ |
| 12 | */ |
| 13 | |
| 14 | #include <common.h> |
Hans de Goede | e79c7c8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 15 | #include <mmc.h> |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 16 | #include <axp_pmic.h> |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 17 | #include <asm/arch/clock.h> |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 18 | #include <asm/arch/cpu.h> |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 19 | #include <asm/arch/display.h> |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 20 | #include <asm/arch/dram.h> |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 21 | #include <asm/arch/gpio.h> |
| 22 | #include <asm/arch/mmc.h> |
Hans de Goede | 4a8c7c1 | 2016-07-09 09:56:56 +0200 | [diff] [blame] | 23 | #include <asm/arch/spl.h> |
Hans de Goede | 2aacc42 | 2015-04-27 15:05:10 +0200 | [diff] [blame] | 24 | #include <asm/arch/usb_phy.h> |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 25 | #ifndef CONFIG_ARM64 |
| 26 | #include <asm/armv7.h> |
| 27 | #endif |
Hans de Goede | 4f7e01c | 2015-04-23 23:23:50 +0200 | [diff] [blame] | 28 | #include <asm/gpio.h> |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 29 | #include <asm/io.h> |
Hans de Goede | 3f8ea3b | 2016-07-29 11:47:03 +0200 | [diff] [blame] | 30 | #include <crc.h> |
Hans de Goede | 4a8c7c1 | 2016-07-09 09:56:56 +0200 | [diff] [blame] | 31 | #include <environment.h> |
Hans de Goede | f221961 | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 32 | #include <libfdt.h> |
Hans de Goede | f62bfa5 | 2015-08-15 11:55:26 +0200 | [diff] [blame] | 33 | #include <nand.h> |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 34 | #include <net.h> |
Maxime Ripard | f4c3523 | 2017-08-23 10:08:29 +0200 | [diff] [blame] | 35 | #include <spl.h> |
Jelle van der Waa | 0d8382a | 2016-02-23 18:47:19 +0100 | [diff] [blame] | 36 | #include <sy8106a.h> |
Simon Glass | 5d98285 | 2017-05-17 08:23:00 -0600 | [diff] [blame] | 37 | #include <asm/setup.h> |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 38 | |
Hans de Goede | 5541008 | 2015-02-16 17:23:25 +0100 | [diff] [blame] | 39 | #if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD) |
| 40 | /* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */ |
| 41 | int soft_i2c_gpio_sda; |
| 42 | int soft_i2c_gpio_scl; |
Hans de Goede | 4f7e01c | 2015-04-23 23:23:50 +0200 | [diff] [blame] | 43 | |
| 44 | static int soft_i2c_board_init(void) |
| 45 | { |
| 46 | int ret; |
| 47 | |
| 48 | soft_i2c_gpio_sda = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SDA); |
| 49 | if (soft_i2c_gpio_sda < 0) { |
| 50 | printf("Error invalid soft i2c sda pin: '%s', err %d\n", |
| 51 | CONFIG_VIDEO_LCD_PANEL_I2C_SDA, soft_i2c_gpio_sda); |
| 52 | return soft_i2c_gpio_sda; |
| 53 | } |
| 54 | ret = gpio_request(soft_i2c_gpio_sda, "soft-i2c-sda"); |
| 55 | if (ret) { |
| 56 | printf("Error requesting soft i2c sda pin: '%s', err %d\n", |
| 57 | CONFIG_VIDEO_LCD_PANEL_I2C_SDA, ret); |
| 58 | return ret; |
| 59 | } |
| 60 | |
| 61 | soft_i2c_gpio_scl = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SCL); |
| 62 | if (soft_i2c_gpio_scl < 0) { |
| 63 | printf("Error invalid soft i2c scl pin: '%s', err %d\n", |
| 64 | CONFIG_VIDEO_LCD_PANEL_I2C_SCL, soft_i2c_gpio_scl); |
| 65 | return soft_i2c_gpio_scl; |
| 66 | } |
| 67 | ret = gpio_request(soft_i2c_gpio_scl, "soft-i2c-scl"); |
| 68 | if (ret) { |
| 69 | printf("Error requesting soft i2c scl pin: '%s', err %d\n", |
| 70 | CONFIG_VIDEO_LCD_PANEL_I2C_SCL, ret); |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | #else |
| 77 | static int soft_i2c_board_init(void) { return 0; } |
Hans de Goede | 5541008 | 2015-02-16 17:23:25 +0100 | [diff] [blame] | 78 | #endif |
| 79 | |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 80 | DECLARE_GLOBAL_DATA_PTR; |
| 81 | |
Jernej Skrabec | acbc7e0 | 2017-04-27 00:03:35 +0200 | [diff] [blame] | 82 | void i2c_init_board(void) |
| 83 | { |
| 84 | #ifdef CONFIG_I2C0_ENABLE |
| 85 | #if defined(CONFIG_MACH_SUN4I) || \ |
| 86 | defined(CONFIG_MACH_SUN5I) || \ |
| 87 | defined(CONFIG_MACH_SUN7I) || \ |
| 88 | defined(CONFIG_MACH_SUN8I_R40) |
| 89 | sunxi_gpio_set_cfgpin(SUNXI_GPB(0), SUN4I_GPB_TWI0); |
| 90 | sunxi_gpio_set_cfgpin(SUNXI_GPB(1), SUN4I_GPB_TWI0); |
| 91 | clock_twi_onoff(0, 1); |
| 92 | #elif defined(CONFIG_MACH_SUN6I) |
| 93 | sunxi_gpio_set_cfgpin(SUNXI_GPH(14), SUN6I_GPH_TWI0); |
| 94 | sunxi_gpio_set_cfgpin(SUNXI_GPH(15), SUN6I_GPH_TWI0); |
| 95 | clock_twi_onoff(0, 1); |
| 96 | #elif defined(CONFIG_MACH_SUN8I) |
| 97 | sunxi_gpio_set_cfgpin(SUNXI_GPH(2), SUN8I_GPH_TWI0); |
| 98 | sunxi_gpio_set_cfgpin(SUNXI_GPH(3), SUN8I_GPH_TWI0); |
| 99 | clock_twi_onoff(0, 1); |
| 100 | #endif |
| 101 | #endif |
| 102 | |
| 103 | #ifdef CONFIG_I2C1_ENABLE |
| 104 | #if defined(CONFIG_MACH_SUN4I) || \ |
| 105 | defined(CONFIG_MACH_SUN7I) || \ |
| 106 | defined(CONFIG_MACH_SUN8I_R40) |
| 107 | sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN4I_GPB_TWI1); |
| 108 | sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN4I_GPB_TWI1); |
| 109 | clock_twi_onoff(1, 1); |
| 110 | #elif defined(CONFIG_MACH_SUN5I) |
| 111 | sunxi_gpio_set_cfgpin(SUNXI_GPB(15), SUN5I_GPB_TWI1); |
| 112 | sunxi_gpio_set_cfgpin(SUNXI_GPB(16), SUN5I_GPB_TWI1); |
| 113 | clock_twi_onoff(1, 1); |
| 114 | #elif defined(CONFIG_MACH_SUN6I) |
| 115 | sunxi_gpio_set_cfgpin(SUNXI_GPH(16), SUN6I_GPH_TWI1); |
| 116 | sunxi_gpio_set_cfgpin(SUNXI_GPH(17), SUN6I_GPH_TWI1); |
| 117 | clock_twi_onoff(1, 1); |
| 118 | #elif defined(CONFIG_MACH_SUN8I) |
| 119 | sunxi_gpio_set_cfgpin(SUNXI_GPH(4), SUN8I_GPH_TWI1); |
| 120 | sunxi_gpio_set_cfgpin(SUNXI_GPH(5), SUN8I_GPH_TWI1); |
| 121 | clock_twi_onoff(1, 1); |
| 122 | #endif |
| 123 | #endif |
| 124 | |
| 125 | #ifdef CONFIG_I2C2_ENABLE |
| 126 | #if defined(CONFIG_MACH_SUN4I) || \ |
| 127 | defined(CONFIG_MACH_SUN7I) || \ |
| 128 | defined(CONFIG_MACH_SUN8I_R40) |
| 129 | sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN4I_GPB_TWI2); |
| 130 | sunxi_gpio_set_cfgpin(SUNXI_GPB(21), SUN4I_GPB_TWI2); |
| 131 | clock_twi_onoff(2, 1); |
| 132 | #elif defined(CONFIG_MACH_SUN5I) |
| 133 | sunxi_gpio_set_cfgpin(SUNXI_GPB(17), SUN5I_GPB_TWI2); |
| 134 | sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN5I_GPB_TWI2); |
| 135 | clock_twi_onoff(2, 1); |
| 136 | #elif defined(CONFIG_MACH_SUN6I) |
| 137 | sunxi_gpio_set_cfgpin(SUNXI_GPH(18), SUN6I_GPH_TWI2); |
| 138 | sunxi_gpio_set_cfgpin(SUNXI_GPH(19), SUN6I_GPH_TWI2); |
| 139 | clock_twi_onoff(2, 1); |
| 140 | #elif defined(CONFIG_MACH_SUN8I) |
| 141 | sunxi_gpio_set_cfgpin(SUNXI_GPE(12), SUN8I_GPE_TWI2); |
| 142 | sunxi_gpio_set_cfgpin(SUNXI_GPE(13), SUN8I_GPE_TWI2); |
| 143 | clock_twi_onoff(2, 1); |
| 144 | #endif |
| 145 | #endif |
| 146 | |
| 147 | #ifdef CONFIG_I2C3_ENABLE |
| 148 | #if defined(CONFIG_MACH_SUN6I) |
| 149 | sunxi_gpio_set_cfgpin(SUNXI_GPG(10), SUN6I_GPG_TWI3); |
| 150 | sunxi_gpio_set_cfgpin(SUNXI_GPG(11), SUN6I_GPG_TWI3); |
| 151 | clock_twi_onoff(3, 1); |
| 152 | #elif defined(CONFIG_MACH_SUN7I) || \ |
| 153 | defined(CONFIG_MACH_SUN8I_R40) |
| 154 | sunxi_gpio_set_cfgpin(SUNXI_GPI(0), SUN7I_GPI_TWI3); |
| 155 | sunxi_gpio_set_cfgpin(SUNXI_GPI(1), SUN7I_GPI_TWI3); |
| 156 | clock_twi_onoff(3, 1); |
| 157 | #endif |
| 158 | #endif |
| 159 | |
| 160 | #ifdef CONFIG_I2C4_ENABLE |
| 161 | #if defined(CONFIG_MACH_SUN7I) || \ |
| 162 | defined(CONFIG_MACH_SUN8I_R40) |
| 163 | sunxi_gpio_set_cfgpin(SUNXI_GPI(2), SUN7I_GPI_TWI4); |
| 164 | sunxi_gpio_set_cfgpin(SUNXI_GPI(3), SUN7I_GPI_TWI4); |
| 165 | clock_twi_onoff(4, 1); |
| 166 | #endif |
| 167 | #endif |
| 168 | |
| 169 | #ifdef CONFIG_R_I2C_ENABLE |
| 170 | clock_twi_onoff(5, 1); |
| 171 | sunxi_gpio_set_cfgpin(SUNXI_GPL(0), SUN8I_H3_GPL_R_TWI); |
| 172 | sunxi_gpio_set_cfgpin(SUNXI_GPL(1), SUN8I_H3_GPL_R_TWI); |
| 173 | #endif |
| 174 | } |
| 175 | |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 176 | /* add board specific code here */ |
| 177 | int board_init(void) |
| 178 | { |
Mylène Josserand | f5fd788 | 2017-04-02 12:59:10 +0200 | [diff] [blame] | 179 | __maybe_unused int id_pfr1, ret, satapwr_pin, macpwr_pin; |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 180 | |
| 181 | gd->bd->bi_boot_params = (PHYS_SDRAM_0 + 0x100); |
| 182 | |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 183 | #ifndef CONFIG_ARM64 |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 184 | asm volatile("mrc p15, 0, %0, c0, c1, 1" : "=r"(id_pfr1)); |
| 185 | debug("id_pfr1: 0x%08x\n", id_pfr1); |
| 186 | /* Generic Timer Extension available? */ |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 187 | if ((id_pfr1 >> CPUID_ARM_GENTIMER_SHIFT) & 0xf) { |
| 188 | uint32_t freq; |
| 189 | |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 190 | debug("Setting CNTFRQ\n"); |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 191 | |
| 192 | /* |
| 193 | * CNTFRQ is a secure register, so we will crash if we try to |
| 194 | * write this from the non-secure world (read is OK, though). |
| 195 | * In case some bootcode has already set the correct value, |
| 196 | * we avoid the risk of writing to it. |
| 197 | */ |
| 198 | asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r"(freq)); |
Andre Przywara | e4916e8 | 2017-02-16 01:20:19 +0000 | [diff] [blame] | 199 | if (freq != COUNTER_FREQUENCY) { |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 200 | debug("arch timer frequency is %d Hz, should be %d, fixing ...\n", |
Andre Przywara | e4916e8 | 2017-02-16 01:20:19 +0000 | [diff] [blame] | 201 | freq, COUNTER_FREQUENCY); |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 202 | #ifdef CONFIG_NON_SECURE |
| 203 | printf("arch timer frequency is wrong, but cannot adjust it\n"); |
| 204 | #else |
| 205 | asm volatile("mcr p15, 0, %0, c14, c0, 0" |
Andre Przywara | e4916e8 | 2017-02-16 01:20:19 +0000 | [diff] [blame] | 206 | : : "r"(COUNTER_FREQUENCY)); |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 207 | #endif |
| 208 | } |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 209 | } |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 210 | #endif /* !CONFIG_ARM64 */ |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 211 | |
Hans de Goede | 2fcf033 | 2015-04-25 17:25:14 +0200 | [diff] [blame] | 212 | ret = axp_gpio_init(); |
| 213 | if (ret) |
| 214 | return ret; |
| 215 | |
Hans de Goede | 9fbb0c3 | 2016-03-22 20:10:30 +0100 | [diff] [blame] | 216 | #ifdef CONFIG_SATAPWR |
Mylène Josserand | d7b560e | 2017-04-02 12:59:09 +0200 | [diff] [blame] | 217 | satapwr_pin = sunxi_name_to_gpio(CONFIG_SATAPWR); |
| 218 | gpio_request(satapwr_pin, "satapwr"); |
| 219 | gpio_direction_output(satapwr_pin, 1); |
Hans de Goede | 9fbb0c3 | 2016-03-22 20:10:30 +0100 | [diff] [blame] | 220 | #endif |
Hans de Goede | fc8991c | 2016-03-17 13:53:03 +0100 | [diff] [blame] | 221 | #ifdef CONFIG_MACPWR |
Mylène Josserand | f5fd788 | 2017-04-02 12:59:10 +0200 | [diff] [blame] | 222 | macpwr_pin = sunxi_name_to_gpio(CONFIG_MACPWR); |
| 223 | gpio_request(macpwr_pin, "macpwr"); |
| 224 | gpio_direction_output(macpwr_pin, 1); |
Hans de Goede | fc8991c | 2016-03-17 13:53:03 +0100 | [diff] [blame] | 225 | #endif |
| 226 | |
Jernej Skrabec | a8f01cc | 2017-04-27 00:03:36 +0200 | [diff] [blame] | 227 | #ifdef CONFIG_DM_I2C |
| 228 | /* |
| 229 | * Temporary workaround for enabling I2C clocks until proper sunxi DM |
| 230 | * clk, reset and pinctrl drivers land. |
| 231 | */ |
| 232 | i2c_init_board(); |
| 233 | #endif |
| 234 | |
Hans de Goede | 4f7e01c | 2015-04-23 23:23:50 +0200 | [diff] [blame] | 235 | /* Uses dm gpio code so do this here and not in i2c_init_board() */ |
| 236 | return soft_i2c_board_init(); |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | int dram_init(void) |
| 240 | { |
| 241 | gd->ram_size = get_ram_size((long *)PHYS_SDRAM_0, PHYS_SDRAM_0_SIZE); |
| 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | |
Boris Brezillon | 4ccae81 | 2016-06-15 21:09:23 +0200 | [diff] [blame] | 246 | #if defined(CONFIG_NAND_SUNXI) |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 247 | static void nand_pinmux_setup(void) |
| 248 | { |
| 249 | unsigned int pin; |
Hans de Goede | 022a99d | 2015-08-15 13:17:49 +0200 | [diff] [blame] | 250 | |
| 251 | for (pin = SUNXI_GPC(0); pin <= SUNXI_GPC(19); pin++) |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 252 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND); |
| 253 | |
Hans de Goede | 022a99d | 2015-08-15 13:17:49 +0200 | [diff] [blame] | 254 | #if defined CONFIG_MACH_SUN4I || defined CONFIG_MACH_SUN7I |
| 255 | for (pin = SUNXI_GPC(20); pin <= SUNXI_GPC(22); pin++) |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 256 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND); |
Hans de Goede | 022a99d | 2015-08-15 13:17:49 +0200 | [diff] [blame] | 257 | #endif |
| 258 | /* sun4i / sun7i do have a PC23, but it is not used for nand, |
| 259 | * only sun7i has a PC24 */ |
| 260 | #ifdef CONFIG_MACH_SUN7I |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 261 | sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_NAND); |
Hans de Goede | 022a99d | 2015-08-15 13:17:49 +0200 | [diff] [blame] | 262 | #endif |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | static void nand_clock_setup(void) |
| 266 | { |
| 267 | struct sunxi_ccm_reg *const ccm = |
| 268 | (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
Hans de Goede | 31c2147 | 2015-08-15 11:58:03 +0200 | [diff] [blame] | 269 | |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 270 | setbits_le32(&ccm->ahb_gate0, (CLK_GATE_OPEN << AHB_GATE_OFFSET_NAND0)); |
Hans de Goede | 31c2147 | 2015-08-15 11:58:03 +0200 | [diff] [blame] | 271 | #ifdef CONFIG_MACH_SUN9I |
| 272 | setbits_le32(&ccm->ahb_gate1, (1 << AHB_GATE_OFFSET_DMA)); |
| 273 | #else |
| 274 | setbits_le32(&ccm->ahb_gate0, (1 << AHB_GATE_OFFSET_DMA)); |
| 275 | #endif |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 276 | setbits_le32(&ccm->nand0_clk_cfg, CCM_NAND_CTRL_ENABLE | AHB_DIV_1); |
| 277 | } |
Hans de Goede | f62bfa5 | 2015-08-15 11:55:26 +0200 | [diff] [blame] | 278 | |
| 279 | void board_nand_init(void) |
| 280 | { |
| 281 | nand_pinmux_setup(); |
| 282 | nand_clock_setup(); |
Boris Brezillon | 4ccae81 | 2016-06-15 21:09:23 +0200 | [diff] [blame] | 283 | #ifndef CONFIG_SPL_BUILD |
| 284 | sunxi_nand_init(); |
| 285 | #endif |
Hans de Goede | f62bfa5 | 2015-08-15 11:55:26 +0200 | [diff] [blame] | 286 | } |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 287 | #endif |
| 288 | |
Masahiro Yamada | 4aa2ba3 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 289 | #ifdef CONFIG_MMC |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 290 | static void mmc_pinmux_setup(int sdc) |
| 291 | { |
| 292 | unsigned int pin; |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 293 | __maybe_unused int pins; |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 294 | |
| 295 | switch (sdc) { |
| 296 | case 0: |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 297 | /* SDC0: PF0-PF5 */ |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 298 | for (pin = SUNXI_GPF(0); pin <= SUNXI_GPF(5); pin++) { |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 299 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPF_SDC0); |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 300 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 301 | sunxi_gpio_set_drv(pin, 2); |
| 302 | } |
| 303 | break; |
| 304 | |
| 305 | case 1: |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 306 | pins = sunxi_name_to_gpio_bank(CONFIG_MMC1_PINS); |
| 307 | |
Chen-Yu Tsai | 8094a4a | 2016-11-30 16:28:34 +0800 | [diff] [blame] | 308 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) || \ |
| 309 | defined(CONFIG_MACH_SUN8I_R40) |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 310 | if (pins == SUNXI_GPIO_H) { |
| 311 | /* SDC1: PH22-PH-27 */ |
| 312 | for (pin = SUNXI_GPH(22); pin <= SUNXI_GPH(27); pin++) { |
| 313 | sunxi_gpio_set_cfgpin(pin, SUN4I_GPH_SDC1); |
| 314 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 315 | sunxi_gpio_set_drv(pin, 2); |
| 316 | } |
| 317 | } else { |
| 318 | /* SDC1: PG0-PG5 */ |
| 319 | for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) { |
| 320 | sunxi_gpio_set_cfgpin(pin, SUN4I_GPG_SDC1); |
| 321 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 322 | sunxi_gpio_set_drv(pin, 2); |
| 323 | } |
| 324 | } |
| 325 | #elif defined(CONFIG_MACH_SUN5I) |
| 326 | /* SDC1: PG3-PG8 */ |
Hans de Goede | bbff84b | 2014-10-03 16:44:57 +0200 | [diff] [blame] | 327 | for (pin = SUNXI_GPG(3); pin <= SUNXI_GPG(8); pin++) { |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 328 | sunxi_gpio_set_cfgpin(pin, SUN5I_GPG_SDC1); |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 329 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 330 | sunxi_gpio_set_drv(pin, 2); |
| 331 | } |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 332 | #elif defined(CONFIG_MACH_SUN6I) |
| 333 | /* SDC1: PG0-PG5 */ |
| 334 | for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) { |
| 335 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPG_SDC1); |
| 336 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 337 | sunxi_gpio_set_drv(pin, 2); |
| 338 | } |
| 339 | #elif defined(CONFIG_MACH_SUN8I) |
| 340 | if (pins == SUNXI_GPIO_D) { |
| 341 | /* SDC1: PD2-PD7 */ |
| 342 | for (pin = SUNXI_GPD(2); pin <= SUNXI_GPD(7); pin++) { |
| 343 | sunxi_gpio_set_cfgpin(pin, SUN8I_GPD_SDC1); |
| 344 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 345 | sunxi_gpio_set_drv(pin, 2); |
| 346 | } |
| 347 | } else { |
| 348 | /* SDC1: PG0-PG5 */ |
| 349 | for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) { |
| 350 | sunxi_gpio_set_cfgpin(pin, SUN8I_GPG_SDC1); |
| 351 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 352 | sunxi_gpio_set_drv(pin, 2); |
| 353 | } |
| 354 | } |
| 355 | #endif |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 356 | break; |
| 357 | |
| 358 | case 2: |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 359 | pins = sunxi_name_to_gpio_bank(CONFIG_MMC2_PINS); |
| 360 | |
| 361 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) |
| 362 | /* SDC2: PC6-PC11 */ |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 363 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(11); pin++) { |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 364 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 365 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 366 | sunxi_gpio_set_drv(pin, 2); |
| 367 | } |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 368 | #elif defined(CONFIG_MACH_SUN5I) |
| 369 | if (pins == SUNXI_GPIO_E) { |
| 370 | /* SDC2: PE4-PE9 */ |
| 371 | for (pin = SUNXI_GPE(4); pin <= SUNXI_GPD(9); pin++) { |
| 372 | sunxi_gpio_set_cfgpin(pin, SUN5I_GPE_SDC2); |
| 373 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 374 | sunxi_gpio_set_drv(pin, 2); |
| 375 | } |
| 376 | } else { |
| 377 | /* SDC2: PC6-PC15 */ |
| 378 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) { |
| 379 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 380 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 381 | sunxi_gpio_set_drv(pin, 2); |
| 382 | } |
| 383 | } |
| 384 | #elif defined(CONFIG_MACH_SUN6I) |
| 385 | if (pins == SUNXI_GPIO_A) { |
| 386 | /* SDC2: PA9-PA14 */ |
| 387 | for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) { |
| 388 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC2); |
| 389 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 390 | sunxi_gpio_set_drv(pin, 2); |
| 391 | } |
| 392 | } else { |
| 393 | /* SDC2: PC6-PC15, PC24 */ |
| 394 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) { |
| 395 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 396 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 397 | sunxi_gpio_set_drv(pin, 2); |
| 398 | } |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 399 | |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 400 | sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2); |
| 401 | sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP); |
| 402 | sunxi_gpio_set_drv(SUNXI_GPC(24), 2); |
| 403 | } |
Chen-Yu Tsai | 8094a4a | 2016-11-30 16:28:34 +0800 | [diff] [blame] | 404 | #elif defined(CONFIG_MACH_SUN8I_R40) |
| 405 | /* SDC2: PC6-PC15, PC24 */ |
| 406 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) { |
| 407 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 408 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 409 | sunxi_gpio_set_drv(pin, 2); |
| 410 | } |
| 411 | |
| 412 | sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2); |
| 413 | sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP); |
| 414 | sunxi_gpio_set_drv(SUNXI_GPC(24), 2); |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 415 | #elif defined(CONFIG_MACH_SUN8I) || defined(CONFIG_MACH_SUN50I) |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 416 | /* SDC2: PC5-PC6, PC8-PC16 */ |
| 417 | for (pin = SUNXI_GPC(5); pin <= SUNXI_GPC(6); pin++) { |
| 418 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 419 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 420 | sunxi_gpio_set_drv(pin, 2); |
| 421 | } |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 422 | |
| 423 | for (pin = SUNXI_GPC(8); pin <= SUNXI_GPC(16); pin++) { |
| 424 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 425 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 426 | sunxi_gpio_set_drv(pin, 2); |
| 427 | } |
Philipp Tomsich | 3ebb456 | 2016-10-28 18:21:33 +0800 | [diff] [blame] | 428 | #elif defined(CONFIG_MACH_SUN9I) |
| 429 | /* SDC2: PC6-PC16 */ |
| 430 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(16); pin++) { |
| 431 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 432 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 433 | sunxi_gpio_set_drv(pin, 2); |
| 434 | } |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 435 | #endif |
| 436 | break; |
| 437 | |
| 438 | case 3: |
| 439 | pins = sunxi_name_to_gpio_bank(CONFIG_MMC3_PINS); |
| 440 | |
Chen-Yu Tsai | 8094a4a | 2016-11-30 16:28:34 +0800 | [diff] [blame] | 441 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) || \ |
| 442 | defined(CONFIG_MACH_SUN8I_R40) |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 443 | /* SDC3: PI4-PI9 */ |
| 444 | for (pin = SUNXI_GPI(4); pin <= SUNXI_GPI(9); pin++) { |
| 445 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPI_SDC3); |
| 446 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 447 | sunxi_gpio_set_drv(pin, 2); |
| 448 | } |
| 449 | #elif defined(CONFIG_MACH_SUN6I) |
| 450 | if (pins == SUNXI_GPIO_A) { |
| 451 | /* SDC3: PA9-PA14 */ |
| 452 | for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) { |
| 453 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC3); |
| 454 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 455 | sunxi_gpio_set_drv(pin, 2); |
| 456 | } |
| 457 | } else { |
| 458 | /* SDC3: PC6-PC15, PC24 */ |
| 459 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) { |
| 460 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPC_SDC3); |
| 461 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 462 | sunxi_gpio_set_drv(pin, 2); |
| 463 | } |
| 464 | |
| 465 | sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUN6I_GPC_SDC3); |
| 466 | sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP); |
| 467 | sunxi_gpio_set_drv(SUNXI_GPC(24), 2); |
| 468 | } |
| 469 | #endif |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 470 | break; |
| 471 | |
| 472 | default: |
| 473 | printf("sunxi: invalid MMC slot %d for pinmux setup\n", sdc); |
| 474 | break; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | int board_mmc_init(bd_t *bis) |
| 479 | { |
Hans de Goede | e79c7c8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 480 | __maybe_unused struct mmc *mmc0, *mmc1; |
| 481 | __maybe_unused char buf[512]; |
| 482 | |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 483 | mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT); |
Hans de Goede | e79c7c8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 484 | mmc0 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT); |
| 485 | if (!mmc0) |
| 486 | return -1; |
| 487 | |
Hans de Goede | 2ccfac0 | 2014-10-02 20:43:50 +0200 | [diff] [blame] | 488 | #if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1 |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 489 | mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT_EXTRA); |
Hans de Goede | e79c7c8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 490 | mmc1 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT_EXTRA); |
| 491 | if (!mmc1) |
| 492 | return -1; |
| 493 | #endif |
| 494 | |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 495 | return 0; |
| 496 | } |
| 497 | #endif |
| 498 | |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 499 | #ifdef CONFIG_SPL_BUILD |
| 500 | void sunxi_board_init(void) |
| 501 | { |
Henrik Nordstrom | 14bc66b | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 502 | int power_failed = 0; |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 503 | |
Jelle van der Waa | 0d8382a | 2016-02-23 18:47:19 +0100 | [diff] [blame] | 504 | #ifdef CONFIG_SY8106A_POWER |
| 505 | power_failed = sy8106a_set_vout1(CONFIG_SY8106A_VOUT1_VOLT); |
| 506 | #endif |
| 507 | |
vishnupatekar | 95ab8fe | 2015-11-29 01:07:22 +0800 | [diff] [blame] | 508 | #if defined CONFIG_AXP152_POWER || defined CONFIG_AXP209_POWER || \ |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 509 | defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \ |
| 510 | defined CONFIG_AXP818_POWER |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 511 | power_failed = axp_init(); |
| 512 | |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 513 | #if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \ |
| 514 | defined CONFIG_AXP818_POWER |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 515 | power_failed |= axp_set_dcdc1(CONFIG_AXP_DCDC1_VOLT); |
Hans de Goede | 2428920 | 2014-06-13 22:55:51 +0200 | [diff] [blame] | 516 | #endif |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 517 | power_failed |= axp_set_dcdc2(CONFIG_AXP_DCDC2_VOLT); |
| 518 | power_failed |= axp_set_dcdc3(CONFIG_AXP_DCDC3_VOLT); |
vishnupatekar | 95ab8fe | 2015-11-29 01:07:22 +0800 | [diff] [blame] | 519 | #if !defined(CONFIG_AXP209_POWER) && !defined(CONFIG_AXP818_POWER) |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 520 | power_failed |= axp_set_dcdc4(CONFIG_AXP_DCDC4_VOLT); |
Henrik Nordstrom | 14bc66b | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 521 | #endif |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 522 | #if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \ |
| 523 | defined CONFIG_AXP818_POWER |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 524 | power_failed |= axp_set_dcdc5(CONFIG_AXP_DCDC5_VOLT); |
Oliver Schinagl | 5c7f10f | 2013-07-26 12:56:58 +0200 | [diff] [blame] | 525 | #endif |
Henrik Nordstrom | 14bc66b | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 526 | |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 527 | #if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \ |
| 528 | defined CONFIG_AXP818_POWER |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 529 | power_failed |= axp_set_aldo1(CONFIG_AXP_ALDO1_VOLT); |
| 530 | #endif |
| 531 | power_failed |= axp_set_aldo2(CONFIG_AXP_ALDO2_VOLT); |
Chen-Yu Tsai | f3c5045 | 2016-01-12 14:42:40 +0800 | [diff] [blame] | 532 | #if !defined(CONFIG_AXP152_POWER) |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 533 | power_failed |= axp_set_aldo3(CONFIG_AXP_ALDO3_VOLT); |
| 534 | #endif |
| 535 | #ifdef CONFIG_AXP209_POWER |
| 536 | power_failed |= axp_set_aldo4(CONFIG_AXP_ALDO4_VOLT); |
| 537 | #endif |
| 538 | |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 539 | #if defined(CONFIG_AXP221_POWER) || defined(CONFIG_AXP809_POWER) || \ |
| 540 | defined(CONFIG_AXP818_POWER) |
Chen-Yu Tsai | 3517a27 | 2016-01-12 14:42:37 +0800 | [diff] [blame] | 541 | power_failed |= axp_set_dldo(1, CONFIG_AXP_DLDO1_VOLT); |
| 542 | power_failed |= axp_set_dldo(2, CONFIG_AXP_DLDO2_VOLT); |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 543 | #if !defined CONFIG_AXP809_POWER |
Chen-Yu Tsai | 3517a27 | 2016-01-12 14:42:37 +0800 | [diff] [blame] | 544 | power_failed |= axp_set_dldo(3, CONFIG_AXP_DLDO3_VOLT); |
| 545 | power_failed |= axp_set_dldo(4, CONFIG_AXP_DLDO4_VOLT); |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 546 | #endif |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 547 | power_failed |= axp_set_eldo(1, CONFIG_AXP_ELDO1_VOLT); |
| 548 | power_failed |= axp_set_eldo(2, CONFIG_AXP_ELDO2_VOLT); |
| 549 | power_failed |= axp_set_eldo(3, CONFIG_AXP_ELDO3_VOLT); |
| 550 | #endif |
Chen-Yu Tsai | 38491d9 | 2016-03-30 00:26:48 +0800 | [diff] [blame] | 551 | |
| 552 | #ifdef CONFIG_AXP818_POWER |
| 553 | power_failed |= axp_set_fldo(1, CONFIG_AXP_FLDO1_VOLT); |
| 554 | power_failed |= axp_set_fldo(2, CONFIG_AXP_FLDO2_VOLT); |
| 555 | power_failed |= axp_set_fldo(3, CONFIG_AXP_FLDO3_VOLT); |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 556 | #endif |
| 557 | |
| 558 | #if defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER |
Chen-Yu Tsai | 15278cc | 2016-05-02 10:28:12 +0800 | [diff] [blame] | 559 | power_failed |= axp_set_sw(IS_ENABLED(CONFIG_AXP_SW_ON)); |
Chen-Yu Tsai | 38491d9 | 2016-03-30 00:26:48 +0800 | [diff] [blame] | 560 | #endif |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 561 | #endif |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 562 | printf("DRAM:"); |
Andre Przywara | 414eb6f | 2017-04-26 01:32:43 +0100 | [diff] [blame] | 563 | gd->ram_size = sunxi_dram_init(); |
| 564 | printf(" %d MiB\n", (int)(gd->ram_size >> 20)); |
| 565 | if (!gd->ram_size) |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 566 | hang(); |
Henrik Nordstrom | 14bc66b | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 567 | |
| 568 | /* |
| 569 | * Only clock up the CPU to full speed if we are reasonably |
| 570 | * assured it's being powered with suitable core voltage |
| 571 | */ |
| 572 | if (!power_failed) |
Iain Paton | e71b422 | 2015-03-28 10:26:38 +0000 | [diff] [blame] | 573 | clock_set_pll1(CONFIG_SYS_CLK_FREQ); |
Henrik Nordstrom | 14bc66b | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 574 | else |
| 575 | printf("Failed to set core voltage! Can't set CPU frequency\n"); |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 576 | } |
| 577 | #endif |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 578 | |
Paul Kocialkowski | f1df758 | 2015-03-22 18:07:13 +0100 | [diff] [blame] | 579 | #ifdef CONFIG_USB_GADGET |
| 580 | int g_dnl_board_usb_cable_connected(void) |
| 581 | { |
Paul Kocialkowski | 5bfdca0 | 2015-05-16 19:52:10 +0200 | [diff] [blame] | 582 | return sunxi_usb_phy_vbus_detect(0); |
Paul Kocialkowski | f1df758 | 2015-03-22 18:07:13 +0100 | [diff] [blame] | 583 | } |
| 584 | #endif |
| 585 | |
Paul Kocialkowski | 9f85221 | 2015-03-28 18:35:36 +0100 | [diff] [blame] | 586 | #ifdef CONFIG_SERIAL_TAG |
| 587 | void get_board_serial(struct tag_serialnr *serialnr) |
| 588 | { |
| 589 | char *serial_string; |
| 590 | unsigned long long serial; |
| 591 | |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 592 | serial_string = env_get("serial#"); |
Paul Kocialkowski | 9f85221 | 2015-03-28 18:35:36 +0100 | [diff] [blame] | 593 | |
| 594 | if (serial_string) { |
| 595 | serial = simple_strtoull(serial_string, NULL, 16); |
| 596 | |
| 597 | serialnr->high = (unsigned int) (serial >> 32); |
| 598 | serialnr->low = (unsigned int) (serial & 0xffffffff); |
| 599 | } else { |
| 600 | serialnr->high = 0; |
| 601 | serialnr->low = 0; |
| 602 | } |
| 603 | } |
| 604 | #endif |
| 605 | |
Bernhard Nortmann | af654d1 | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 606 | /* |
| 607 | * Check the SPL header for the "sunxi" variant. If found: parse values |
| 608 | * that might have been passed by the loader ("fel" utility), and update |
| 609 | * the environment accordingly. |
| 610 | */ |
| 611 | static void parse_spl_header(const uint32_t spl_addr) |
| 612 | { |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 613 | struct boot_file_head *spl = (void *)(ulong)spl_addr; |
Bernhard Nortmann | 320e057 | 2016-06-09 07:37:35 +0200 | [diff] [blame] | 614 | if (memcmp(spl->spl_signature, SPL_SIGNATURE, 3) != 0) |
| 615 | return; /* signature mismatch, no usable header */ |
| 616 | |
| 617 | uint8_t spl_header_version = spl->spl_signature[3]; |
| 618 | if (spl_header_version != SPL_HEADER_VERSION) { |
Bernhard Nortmann | af654d1 | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 619 | printf("sunxi SPL version mismatch: expected %u, got %u\n", |
| 620 | SPL_HEADER_VERSION, spl_header_version); |
Bernhard Nortmann | 320e057 | 2016-06-09 07:37:35 +0200 | [diff] [blame] | 621 | return; |
Bernhard Nortmann | af654d1 | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 622 | } |
Bernhard Nortmann | 320e057 | 2016-06-09 07:37:35 +0200 | [diff] [blame] | 623 | if (!spl->fel_script_address) |
| 624 | return; |
| 625 | |
| 626 | if (spl->fel_uEnv_length != 0) { |
| 627 | /* |
| 628 | * data is expected in uEnv.txt compatible format, so "env |
| 629 | * import -t" the string(s) at fel_script_address right away. |
| 630 | */ |
Andre Przywara | 5a74a39 | 2016-09-05 01:32:41 +0100 | [diff] [blame] | 631 | himport_r(&env_htab, (char *)(uintptr_t)spl->fel_script_address, |
Bernhard Nortmann | 320e057 | 2016-06-09 07:37:35 +0200 | [diff] [blame] | 632 | spl->fel_uEnv_length, '\n', H_NOCLEAR, 0, 0, NULL); |
| 633 | return; |
| 634 | } |
| 635 | /* otherwise assume .scr format (mkimage-type script) */ |
Simon Glass | 018f530 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 636 | env_set_hex("fel_scriptaddr", spl->fel_script_address); |
Bernhard Nortmann | af654d1 | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 637 | } |
Bernhard Nortmann | af654d1 | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 638 | |
Hans de Goede | f221961 | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 639 | /* |
| 640 | * Note this function gets called multiple times. |
| 641 | * It must not make any changes to env variables which already exist. |
| 642 | */ |
| 643 | static void setup_environment(const void *fdt) |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 644 | { |
Paul Kocialkowski | 8c81657 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 645 | char serial_string[17] = { 0 }; |
Hans de Goede | cac5b1c | 2014-11-26 00:04:24 +0100 | [diff] [blame] | 646 | unsigned int sid[4]; |
Paul Kocialkowski | 8c81657 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 647 | uint8_t mac_addr[6]; |
Hans de Goede | f221961 | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 648 | char ethaddr[16]; |
| 649 | int i, ret; |
| 650 | |
| 651 | ret = sunxi_get_sid(sid); |
Hans de Goede | 3f8ea3b | 2016-07-29 11:47:03 +0200 | [diff] [blame] | 652 | if (ret == 0 && sid[0] != 0) { |
| 653 | /* |
| 654 | * The single words 1 - 3 of the SID have quite a few bits |
| 655 | * which are the same on many models, so we take a crc32 |
| 656 | * of all 3 words, to get a more unique value. |
| 657 | * |
| 658 | * Note we only do this on newer SoCs as we cannot change |
| 659 | * the algorithm on older SoCs since those have been using |
| 660 | * fixed mac-addresses based on only using word 3 for a |
| 661 | * long time and changing a fixed mac-address with an |
| 662 | * u-boot update is not good. |
| 663 | */ |
| 664 | #if !defined(CONFIG_MACH_SUN4I) && !defined(CONFIG_MACH_SUN5I) && \ |
| 665 | !defined(CONFIG_MACH_SUN6I) && !defined(CONFIG_MACH_SUN7I) && \ |
| 666 | !defined(CONFIG_MACH_SUN8I_A23) && !defined(CONFIG_MACH_SUN8I_A33) |
| 667 | sid[3] = crc32(0, (unsigned char *)&sid[1], 12); |
| 668 | #endif |
| 669 | |
Hans de Goede | 97322c3 | 2016-07-27 17:58:06 +0200 | [diff] [blame] | 670 | /* Ensure the NIC specific bytes of the mac are not all 0 */ |
| 671 | if ((sid[3] & 0xffffff) == 0) |
| 672 | sid[3] |= 0x800000; |
| 673 | |
Hans de Goede | f221961 | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 674 | for (i = 0; i < 4; i++) { |
| 675 | sprintf(ethaddr, "ethernet%d", i); |
| 676 | if (!fdt_get_alias(fdt, ethaddr)) |
| 677 | continue; |
| 678 | |
| 679 | if (i == 0) |
| 680 | strcpy(ethaddr, "ethaddr"); |
| 681 | else |
| 682 | sprintf(ethaddr, "eth%daddr", i); |
| 683 | |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 684 | if (env_get(ethaddr)) |
Hans de Goede | f221961 | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 685 | continue; |
| 686 | |
| 687 | /* Non OUI / registered MAC address */ |
| 688 | mac_addr[0] = (i << 4) | 0x02; |
| 689 | mac_addr[1] = (sid[0] >> 0) & 0xff; |
| 690 | mac_addr[2] = (sid[3] >> 24) & 0xff; |
| 691 | mac_addr[3] = (sid[3] >> 16) & 0xff; |
| 692 | mac_addr[4] = (sid[3] >> 8) & 0xff; |
| 693 | mac_addr[5] = (sid[3] >> 0) & 0xff; |
| 694 | |
Simon Glass | fd1e959 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 695 | eth_env_set_enetaddr(ethaddr, mac_addr); |
Hans de Goede | f221961 | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 696 | } |
| 697 | |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 698 | if (!env_get("serial#")) { |
Hans de Goede | f221961 | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 699 | snprintf(serial_string, sizeof(serial_string), |
| 700 | "%08x%08x", sid[0], sid[3]); |
| 701 | |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 702 | env_set("serial#", serial_string); |
Hans de Goede | f221961 | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | } |
| 706 | |
Hans de Goede | f221961 | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 707 | int misc_init_r(void) |
| 708 | { |
| 709 | __maybe_unused int ret; |
Maxime Ripard | f4c3523 | 2017-08-23 10:08:29 +0200 | [diff] [blame] | 710 | uint boot; |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 711 | |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 712 | env_set("fel_booted", NULL); |
| 713 | env_set("fel_scriptaddr", NULL); |
Maxime Ripard | de86fc3 | 2017-08-23 10:12:22 +0200 | [diff] [blame] | 714 | env_set("mmc_bootdev", NULL); |
Maxime Ripard | f4c3523 | 2017-08-23 10:08:29 +0200 | [diff] [blame] | 715 | |
| 716 | boot = sunxi_get_boot_device(); |
Bernhard Nortmann | af654d1 | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 717 | /* determine if we are running in FEL mode */ |
Maxime Ripard | f4c3523 | 2017-08-23 10:08:29 +0200 | [diff] [blame] | 718 | if (boot == BOOT_DEVICE_BOARD) { |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 719 | env_set("fel_booted", "1"); |
Bernhard Nortmann | af654d1 | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 720 | parse_spl_header(SPL_ADDR); |
Maxime Ripard | de86fc3 | 2017-08-23 10:12:22 +0200 | [diff] [blame] | 721 | /* or if we booted from MMC, and which one */ |
| 722 | } else if (boot == BOOT_DEVICE_MMC1) { |
| 723 | env_set("mmc_bootdev", "0"); |
| 724 | } else if (boot == BOOT_DEVICE_MMC2) { |
| 725 | env_set("mmc_bootdev", "1"); |
Bernhard Nortmann | af654d1 | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 726 | } |
Bernhard Nortmann | af654d1 | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 727 | |
Hans de Goede | f221961 | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 728 | setup_environment(gd->fdt_blob); |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 729 | |
Hans de Goede | 1871a8c | 2015-01-13 19:25:06 +0100 | [diff] [blame] | 730 | #ifndef CONFIG_MACH_SUN9I |
Hans de Goede | e13afee | 2015-04-27 16:50:04 +0200 | [diff] [blame] | 731 | ret = sunxi_usb_phy_probe(); |
| 732 | if (ret) |
| 733 | return ret; |
Hans de Goede | 1871a8c | 2015-01-13 19:25:06 +0100 | [diff] [blame] | 734 | #endif |
Hans de Goede | d42faf3 | 2015-06-17 15:49:26 +0200 | [diff] [blame] | 735 | |
Icenowy Zheng | e6ee85a | 2017-09-28 22:16:38 +0800 | [diff] [blame] | 736 | #ifdef CONFIG_USB_ETHER |
Maxime Ripard | 90dd2f1 | 2017-09-06 22:25:03 +0200 | [diff] [blame] | 737 | usb_ether_init(); |
Icenowy Zheng | e6ee85a | 2017-09-28 22:16:38 +0800 | [diff] [blame] | 738 | #endif |
Maxime Ripard | 90dd2f1 | 2017-09-06 22:25:03 +0200 | [diff] [blame] | 739 | |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 740 | return 0; |
| 741 | } |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 742 | |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 743 | int ft_board_setup(void *blob, bd_t *bd) |
| 744 | { |
Hans de Goede | d75111a | 2016-03-22 22:51:52 +0100 | [diff] [blame] | 745 | int __maybe_unused r; |
| 746 | |
Hans de Goede | f221961 | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 747 | /* |
| 748 | * Call setup_environment again in case the boot fdt has |
| 749 | * ethernet aliases the u-boot copy does not have. |
| 750 | */ |
| 751 | setup_environment(blob); |
| 752 | |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 753 | #ifdef CONFIG_VIDEO_DT_SIMPLEFB |
Hans de Goede | d75111a | 2016-03-22 22:51:52 +0100 | [diff] [blame] | 754 | r = sunxi_simplefb_setup(blob); |
| 755 | if (r) |
| 756 | return r; |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 757 | #endif |
Hans de Goede | d75111a | 2016-03-22 22:51:52 +0100 | [diff] [blame] | 758 | return 0; |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 759 | } |
Andre Przywara | 9ea3c35 | 2017-04-26 01:32:44 +0100 | [diff] [blame] | 760 | |
| 761 | #ifdef CONFIG_SPL_LOAD_FIT |
| 762 | int board_fit_config_name_match(const char *name) |
| 763 | { |
Andre Przywara | 54254ba | 2017-04-26 01:32:50 +0100 | [diff] [blame] | 764 | struct boot_file_head *spl = (void *)(ulong)SPL_ADDR; |
| 765 | const char *cmp_str = (void *)(ulong)SPL_ADDR; |
Andre Przywara | 9ea3c35 | 2017-04-26 01:32:44 +0100 | [diff] [blame] | 766 | |
Andre Przywara | 54254ba | 2017-04-26 01:32:50 +0100 | [diff] [blame] | 767 | /* Check if there is a DT name stored in the SPL header and use that. */ |
| 768 | if (spl->dt_name_offset) { |
| 769 | cmp_str += spl->dt_name_offset; |
| 770 | } else { |
Andre Przywara | 9ea3c35 | 2017-04-26 01:32:44 +0100 | [diff] [blame] | 771 | #ifdef CONFIG_DEFAULT_DEVICE_TREE |
Andre Przywara | 54254ba | 2017-04-26 01:32:50 +0100 | [diff] [blame] | 772 | cmp_str = CONFIG_DEFAULT_DEVICE_TREE; |
Andre Przywara | 9ea3c35 | 2017-04-26 01:32:44 +0100 | [diff] [blame] | 773 | #else |
Andre Przywara | 54254ba | 2017-04-26 01:32:50 +0100 | [diff] [blame] | 774 | return 0; |
Andre Przywara | 9ea3c35 | 2017-04-26 01:32:44 +0100 | [diff] [blame] | 775 | #endif |
Andre Przywara | 54254ba | 2017-04-26 01:32:50 +0100 | [diff] [blame] | 776 | }; |
Andre Przywara | 9ea3c35 | 2017-04-26 01:32:44 +0100 | [diff] [blame] | 777 | |
| 778 | /* Differentiate the two Pine64 board DTs by their DRAM size. */ |
| 779 | if (strstr(name, "-pine64") && strstr(cmp_str, "-pine64")) { |
| 780 | if ((gd->ram_size > 512 * 1024 * 1024)) |
| 781 | return !strstr(name, "plus"); |
| 782 | else |
| 783 | return !!strstr(name, "plus"); |
| 784 | } else { |
| 785 | return strcmp(name, cmp_str); |
| 786 | } |
| 787 | } |
| 788 | #endif |