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