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 | 1f24736 | 2014-06-13 22:55:51 +0200 | [diff] [blame] | 16 | #ifdef CONFIG_AXP152_POWER |
| 17 | #include <axp152.h> |
| 18 | #endif |
Henrik Nordstrom | aa382ad | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 19 | #ifdef CONFIG_AXP209_POWER |
| 20 | #include <axp209.h> |
| 21 | #endif |
Oliver Schinagl | d3a558d | 2013-07-26 12:56:58 +0200 | [diff] [blame] | 22 | #ifdef CONFIG_AXP221_POWER |
| 23 | #include <axp221.h> |
| 24 | #endif |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 25 | #include <asm/arch/clock.h> |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 26 | #include <asm/arch/cpu.h> |
Luc Verhaegen | 4869a8c | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 27 | #include <asm/arch/display.h> |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 28 | #include <asm/arch/dram.h> |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 29 | #include <asm/arch/gpio.h> |
| 30 | #include <asm/arch/mmc.h> |
Hans de Goede | f494cad | 2015-01-11 17:17:00 +0100 | [diff] [blame] | 31 | #include <asm/arch/usbc.h> |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 32 | #include <asm/io.h> |
Hans de Goede | f494cad | 2015-01-11 17:17:00 +0100 | [diff] [blame] | 33 | #include <linux/usb/musb.h> |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 34 | #include <net.h> |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 35 | |
Hans de Goede | a5b4cfe | 2015-02-16 17:23:25 +0100 | [diff] [blame] | 36 | #if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD) |
| 37 | /* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */ |
| 38 | int soft_i2c_gpio_sda; |
| 39 | int soft_i2c_gpio_scl; |
| 40 | #endif |
| 41 | |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 42 | DECLARE_GLOBAL_DATA_PTR; |
| 43 | |
| 44 | /* add board specific code here */ |
| 45 | int board_init(void) |
| 46 | { |
| 47 | int id_pfr1; |
| 48 | |
| 49 | gd->bd->bi_boot_params = (PHYS_SDRAM_0 + 0x100); |
| 50 | |
| 51 | asm volatile("mrc p15, 0, %0, c0, c1, 1" : "=r"(id_pfr1)); |
| 52 | debug("id_pfr1: 0x%08x\n", id_pfr1); |
| 53 | /* Generic Timer Extension available? */ |
| 54 | if ((id_pfr1 >> 16) & 0xf) { |
| 55 | debug("Setting CNTFRQ\n"); |
| 56 | /* CNTFRQ == 24 MHz */ |
| 57 | asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r"(24000000)); |
| 58 | } |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | int dram_init(void) |
| 64 | { |
| 65 | gd->ram_size = get_ram_size((long *)PHYS_SDRAM_0, PHYS_SDRAM_0_SIZE); |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 70 | #ifdef CONFIG_GENERIC_MMC |
| 71 | static void mmc_pinmux_setup(int sdc) |
| 72 | { |
| 73 | unsigned int pin; |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 74 | __maybe_unused int pins; |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 75 | |
| 76 | switch (sdc) { |
| 77 | case 0: |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 78 | /* SDC0: PF0-PF5 */ |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 79 | for (pin = SUNXI_GPF(0); pin <= SUNXI_GPF(5); pin++) { |
Paul Kocialkowski | ae358a4 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 80 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPF_SDC0); |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 81 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 82 | sunxi_gpio_set_drv(pin, 2); |
| 83 | } |
| 84 | break; |
| 85 | |
| 86 | case 1: |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 87 | pins = sunxi_name_to_gpio_bank(CONFIG_MMC1_PINS); |
| 88 | |
| 89 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) |
| 90 | if (pins == SUNXI_GPIO_H) { |
| 91 | /* SDC1: PH22-PH-27 */ |
| 92 | for (pin = SUNXI_GPH(22); pin <= SUNXI_GPH(27); pin++) { |
| 93 | sunxi_gpio_set_cfgpin(pin, SUN4I_GPH_SDC1); |
| 94 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 95 | sunxi_gpio_set_drv(pin, 2); |
| 96 | } |
| 97 | } else { |
| 98 | /* SDC1: PG0-PG5 */ |
| 99 | for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) { |
| 100 | sunxi_gpio_set_cfgpin(pin, SUN4I_GPG_SDC1); |
| 101 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 102 | sunxi_gpio_set_drv(pin, 2); |
| 103 | } |
| 104 | } |
| 105 | #elif defined(CONFIG_MACH_SUN5I) |
| 106 | /* SDC1: PG3-PG8 */ |
Hans de Goede | 4dccfd4 | 2014-10-03 16:44:57 +0200 | [diff] [blame] | 107 | for (pin = SUNXI_GPG(3); pin <= SUNXI_GPG(8); pin++) { |
Paul Kocialkowski | ae358a4 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 108 | sunxi_gpio_set_cfgpin(pin, SUN5I_GPG_SDC1); |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 109 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 110 | sunxi_gpio_set_drv(pin, 2); |
| 111 | } |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 112 | #elif defined(CONFIG_MACH_SUN6I) |
| 113 | /* SDC1: PG0-PG5 */ |
| 114 | for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) { |
| 115 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPG_SDC1); |
| 116 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 117 | sunxi_gpio_set_drv(pin, 2); |
| 118 | } |
| 119 | #elif defined(CONFIG_MACH_SUN8I) |
| 120 | if (pins == SUNXI_GPIO_D) { |
| 121 | /* SDC1: PD2-PD7 */ |
| 122 | for (pin = SUNXI_GPD(2); pin <= SUNXI_GPD(7); pin++) { |
| 123 | sunxi_gpio_set_cfgpin(pin, SUN8I_GPD_SDC1); |
| 124 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 125 | sunxi_gpio_set_drv(pin, 2); |
| 126 | } |
| 127 | } else { |
| 128 | /* SDC1: PG0-PG5 */ |
| 129 | for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) { |
| 130 | sunxi_gpio_set_cfgpin(pin, SUN8I_GPG_SDC1); |
| 131 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 132 | sunxi_gpio_set_drv(pin, 2); |
| 133 | } |
| 134 | } |
| 135 | #endif |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 136 | break; |
| 137 | |
| 138 | case 2: |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 139 | pins = sunxi_name_to_gpio_bank(CONFIG_MMC2_PINS); |
| 140 | |
| 141 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) |
| 142 | /* SDC2: PC6-PC11 */ |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 143 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(11); pin++) { |
Paul Kocialkowski | ae358a4 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 144 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 145 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 146 | sunxi_gpio_set_drv(pin, 2); |
| 147 | } |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 148 | #elif defined(CONFIG_MACH_SUN5I) |
| 149 | if (pins == SUNXI_GPIO_E) { |
| 150 | /* SDC2: PE4-PE9 */ |
| 151 | for (pin = SUNXI_GPE(4); pin <= SUNXI_GPD(9); pin++) { |
| 152 | sunxi_gpio_set_cfgpin(pin, SUN5I_GPE_SDC2); |
| 153 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 154 | sunxi_gpio_set_drv(pin, 2); |
| 155 | } |
| 156 | } else { |
| 157 | /* SDC2: PC6-PC15 */ |
| 158 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) { |
| 159 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 160 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 161 | sunxi_gpio_set_drv(pin, 2); |
| 162 | } |
| 163 | } |
| 164 | #elif defined(CONFIG_MACH_SUN6I) |
| 165 | if (pins == SUNXI_GPIO_A) { |
| 166 | /* SDC2: PA9-PA14 */ |
| 167 | for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) { |
| 168 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC2); |
| 169 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 170 | sunxi_gpio_set_drv(pin, 2); |
| 171 | } |
| 172 | } else { |
| 173 | /* SDC2: PC6-PC15, PC24 */ |
| 174 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) { |
| 175 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 176 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 177 | sunxi_gpio_set_drv(pin, 2); |
| 178 | } |
| 179 | |
| 180 | sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2); |
| 181 | sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP); |
| 182 | sunxi_gpio_set_drv(SUNXI_GPC(24), 2); |
| 183 | } |
| 184 | #elif defined(CONFIG_MACH_SUN8I) |
| 185 | /* SDC2: PC5-PC6, PC8-PC16 */ |
| 186 | for (pin = SUNXI_GPC(5); pin <= SUNXI_GPC(6); pin++) { |
| 187 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 188 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 189 | sunxi_gpio_set_drv(pin, 2); |
| 190 | } |
| 191 | |
| 192 | for (pin = SUNXI_GPC(8); pin <= SUNXI_GPC(16); pin++) { |
| 193 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 194 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 195 | sunxi_gpio_set_drv(pin, 2); |
| 196 | } |
| 197 | #endif |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 198 | break; |
| 199 | |
| 200 | case 3: |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 201 | pins = sunxi_name_to_gpio_bank(CONFIG_MMC3_PINS); |
| 202 | |
| 203 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) |
| 204 | /* SDC3: PI4-PI9 */ |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 205 | for (pin = SUNXI_GPI(4); pin <= SUNXI_GPI(9); pin++) { |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 206 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPI_SDC3); |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 207 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 208 | sunxi_gpio_set_drv(pin, 2); |
| 209 | } |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 210 | #elif defined(CONFIG_MACH_SUN6I) |
| 211 | if (pins == SUNXI_GPIO_A) { |
| 212 | /* SDC3: PA9-PA14 */ |
| 213 | for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) { |
| 214 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC3); |
| 215 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 216 | sunxi_gpio_set_drv(pin, 2); |
| 217 | } |
| 218 | } else { |
| 219 | /* SDC3: PC6-PC15, PC24 */ |
| 220 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) { |
| 221 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPC_SDC3); |
| 222 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 223 | sunxi_gpio_set_drv(pin, 2); |
| 224 | } |
| 225 | |
| 226 | sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUN6I_GPC_SDC3); |
| 227 | sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP); |
| 228 | sunxi_gpio_set_drv(SUNXI_GPC(24), 2); |
| 229 | } |
| 230 | #endif |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 231 | break; |
| 232 | |
| 233 | default: |
| 234 | printf("sunxi: invalid MMC slot %d for pinmux setup\n", sdc); |
| 235 | break; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | int board_mmc_init(bd_t *bis) |
| 240 | { |
Hans de Goede | 63deaa8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 241 | __maybe_unused struct mmc *mmc0, *mmc1; |
| 242 | __maybe_unused char buf[512]; |
| 243 | |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 244 | mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT); |
Hans de Goede | 63deaa8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 245 | mmc0 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT); |
| 246 | if (!mmc0) |
| 247 | return -1; |
| 248 | |
Hans de Goede | af593e4 | 2014-10-02 20:43:50 +0200 | [diff] [blame] | 249 | #if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1 |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 250 | mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT_EXTRA); |
Hans de Goede | 63deaa8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 251 | mmc1 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT_EXTRA); |
| 252 | if (!mmc1) |
| 253 | return -1; |
| 254 | #endif |
| 255 | |
| 256 | #if CONFIG_MMC_SUNXI_SLOT == 0 && CONFIG_MMC_SUNXI_SLOT_EXTRA == 2 |
| 257 | /* |
| 258 | * Both mmc0 and mmc2 are bootable, figure out where we're booting |
| 259 | * from. Try mmc0 first, just like the brom does. |
| 260 | */ |
| 261 | if (mmc_getcd(mmc0) && mmc_init(mmc0) == 0 && |
| 262 | mmc0->block_dev.block_read(0, 16, 1, buf) == 1) { |
| 263 | buf[12] = 0; |
| 264 | if (strcmp(&buf[4], "eGON.BT0") == 0) |
| 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | /* no bootable card in mmc0, so we must be booting from mmc2, swap */ |
| 269 | mmc0->block_dev.dev = 1; |
| 270 | mmc1->block_dev.dev = 0; |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 271 | #endif |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | #endif |
| 276 | |
Hans de Goede | 3352b22 | 2014-06-13 22:55:49 +0200 | [diff] [blame] | 277 | void i2c_init_board(void) |
| 278 | { |
Paul Kocialkowski | 0a3ec0a | 2015-04-10 23:09:52 +0200 | [diff] [blame] | 279 | #ifdef CONFIG_I2C0_ENABLE |
| 280 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN5I) || defined(CONFIG_MACH_SUN7I) |
| 281 | sunxi_gpio_set_cfgpin(SUNXI_GPB(0), SUN4I_GPB_TWI0); |
| 282 | sunxi_gpio_set_cfgpin(SUNXI_GPB(1), SUN4I_GPB_TWI0); |
| 283 | clock_twi_onoff(0, 1); |
| 284 | #elif defined(CONFIG_MACH_SUN6I) |
| 285 | sunxi_gpio_set_cfgpin(SUNXI_GPH(14), SUN6I_GPH_TWI0); |
| 286 | sunxi_gpio_set_cfgpin(SUNXI_GPH(15), SUN6I_GPH_TWI0); |
| 287 | clock_twi_onoff(0, 1); |
| 288 | #elif defined(CONFIG_MACH_SUN8I) |
| 289 | sunxi_gpio_set_cfgpin(SUNXI_GPH(2), SUN8I_GPH_TWI0); |
| 290 | sunxi_gpio_set_cfgpin(SUNXI_GPH(3), SUN8I_GPH_TWI0); |
Hans de Goede | 3352b22 | 2014-06-13 22:55:49 +0200 | [diff] [blame] | 291 | clock_twi_onoff(0, 1); |
Paul Kocialkowski | 0a3ec0a | 2015-04-10 23:09:52 +0200 | [diff] [blame] | 292 | #endif |
| 293 | #endif |
| 294 | |
| 295 | #ifdef CONFIG_I2C1_ENABLE |
| 296 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) |
| 297 | sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN4I_GPB_TWI1); |
| 298 | sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN4I_GPB_TWI1); |
| 299 | clock_twi_onoff(1, 1); |
| 300 | #elif defined(CONFIG_MACH_SUN5I) |
| 301 | sunxi_gpio_set_cfgpin(SUNXI_GPB(15), SUN5I_GPB_TWI1); |
| 302 | sunxi_gpio_set_cfgpin(SUNXI_GPB(16), SUN5I_GPB_TWI1); |
| 303 | clock_twi_onoff(1, 1); |
| 304 | #elif defined(CONFIG_MACH_SUN6I) |
| 305 | sunxi_gpio_set_cfgpin(SUNXI_GPH(16), SUN6I_GPH_TWI1); |
| 306 | sunxi_gpio_set_cfgpin(SUNXI_GPH(17), SUN6I_GPH_TWI1); |
| 307 | clock_twi_onoff(1, 1); |
| 308 | #elif defined(CONFIG_MACH_SUN8I) |
| 309 | sunxi_gpio_set_cfgpin(SUNXI_GPH(4), SUN8I_GPH_TWI1); |
| 310 | sunxi_gpio_set_cfgpin(SUNXI_GPH(5), SUN8I_GPH_TWI1); |
| 311 | clock_twi_onoff(1, 1); |
| 312 | #endif |
| 313 | #endif |
| 314 | |
| 315 | #ifdef CONFIG_I2C2_ENABLE |
| 316 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) |
| 317 | sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN4I_GPB_TWI2); |
| 318 | sunxi_gpio_set_cfgpin(SUNXI_GPB(21), SUN4I_GPB_TWI2); |
| 319 | clock_twi_onoff(2, 1); |
| 320 | #elif defined(CONFIG_MACH_SUN5I) |
| 321 | sunxi_gpio_set_cfgpin(SUNXI_GPB(17), SUN5I_GPB_TWI2); |
| 322 | sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN5I_GPB_TWI2); |
| 323 | clock_twi_onoff(2, 1); |
| 324 | #elif defined(CONFIG_MACH_SUN6I) |
| 325 | sunxi_gpio_set_cfgpin(SUNXI_GPH(18), SUN6I_GPH_TWI2); |
| 326 | sunxi_gpio_set_cfgpin(SUNXI_GPH(19), SUN6I_GPH_TWI2); |
| 327 | clock_twi_onoff(2, 1); |
| 328 | #elif defined(CONFIG_MACH_SUN8I) |
| 329 | sunxi_gpio_set_cfgpin(SUNXI_GPE(12), SUN8I_GPE_TWI2); |
| 330 | sunxi_gpio_set_cfgpin(SUNXI_GPE(13), SUN8I_GPE_TWI2); |
| 331 | clock_twi_onoff(2, 1); |
| 332 | #endif |
| 333 | #endif |
| 334 | |
| 335 | #ifdef CONFIG_I2C3_ENABLE |
| 336 | #if defined(CONFIG_MACH_SUN6I) |
| 337 | sunxi_gpio_set_cfgpin(SUNXI_GPG(10), SUN6I_GPG_TWI3); |
| 338 | sunxi_gpio_set_cfgpin(SUNXI_GPG(11), SUN6I_GPG_TWI3); |
| 339 | clock_twi_onoff(3, 1); |
| 340 | #elif defined(CONFIG_MACH_SUN7I) |
| 341 | sunxi_gpio_set_cfgpin(SUNXI_GPI(0), SUN7I_GPI_TWI3); |
| 342 | sunxi_gpio_set_cfgpin(SUNXI_GPI(1), SUN7I_GPI_TWI3); |
| 343 | clock_twi_onoff(3, 1); |
| 344 | #endif |
| 345 | #endif |
| 346 | |
| 347 | #ifdef CONFIG_I2C4_ENABLE |
| 348 | #if defined(CONFIG_MACH_SUN7I) |
| 349 | sunxi_gpio_set_cfgpin(SUNXI_GPI(2), SUN7I_GPI_TWI4); |
| 350 | sunxi_gpio_set_cfgpin(SUNXI_GPI(3), SUN7I_GPI_TWI4); |
| 351 | clock_twi_onoff(4, 1); |
| 352 | #endif |
| 353 | #endif |
| 354 | |
Hans de Goede | a5b4cfe | 2015-02-16 17:23:25 +0100 | [diff] [blame] | 355 | #if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD) |
| 356 | soft_i2c_gpio_sda = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SDA); |
| 357 | soft_i2c_gpio_scl = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SCL); |
| 358 | #endif |
Hans de Goede | 3352b22 | 2014-06-13 22:55:49 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 361 | #ifdef CONFIG_SPL_BUILD |
| 362 | void sunxi_board_init(void) |
| 363 | { |
Henrik Nordstrom | aa382ad | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 364 | int power_failed = 0; |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 365 | unsigned long ramsize; |
| 366 | |
Hans de Goede | 1f24736 | 2014-06-13 22:55:51 +0200 | [diff] [blame] | 367 | #ifdef CONFIG_AXP152_POWER |
| 368 | power_failed = axp152_init(); |
| 369 | power_failed |= axp152_set_dcdc2(1400); |
| 370 | power_failed |= axp152_set_dcdc3(1500); |
| 371 | power_failed |= axp152_set_dcdc4(1250); |
| 372 | power_failed |= axp152_set_ldo2(3000); |
| 373 | #endif |
Henrik Nordstrom | aa382ad | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 374 | #ifdef CONFIG_AXP209_POWER |
| 375 | power_failed |= axp209_init(); |
| 376 | power_failed |= axp209_set_dcdc2(1400); |
| 377 | power_failed |= axp209_set_dcdc3(1250); |
| 378 | power_failed |= axp209_set_ldo2(3000); |
| 379 | power_failed |= axp209_set_ldo3(2800); |
| 380 | power_failed |= axp209_set_ldo4(2800); |
| 381 | #endif |
Oliver Schinagl | d3a558d | 2013-07-26 12:56:58 +0200 | [diff] [blame] | 382 | #ifdef CONFIG_AXP221_POWER |
| 383 | power_failed = axp221_init(); |
Hans de Goede | 7865548 | 2014-12-13 14:12:06 +0100 | [diff] [blame] | 384 | power_failed |= axp221_set_dcdc1(CONFIG_AXP221_DCDC1_VOLT); |
Hans de Goede | 013c9ce | 2014-12-13 14:20:09 +0100 | [diff] [blame] | 385 | power_failed |= axp221_set_dcdc2(1200); /* A31:VDD-GPU, A23:VDD-SYS */ |
| 386 | power_failed |= axp221_set_dcdc3(1200); /* VDD-CPU */ |
| 387 | #ifdef CONFIG_MACH_SUN6I |
| 388 | power_failed |= axp221_set_dcdc4(1200); /* A31:VDD-SYS */ |
| 389 | #else |
| 390 | power_failed |= axp221_set_dcdc4(0); /* A23:unused */ |
| 391 | #endif |
| 392 | power_failed |= axp221_set_dcdc5(1500); /* VCC-DRAM */ |
Oliver Schinagl | d3a558d | 2013-07-26 12:56:58 +0200 | [diff] [blame] | 393 | power_failed |= axp221_set_dldo1(CONFIG_AXP221_DLDO1_VOLT); |
Oliver Schinagl | d3a558d | 2013-07-26 12:56:58 +0200 | [diff] [blame] | 394 | power_failed |= axp221_set_dldo4(CONFIG_AXP221_DLDO4_VOLT); |
Oliver Schinagl | d3a558d | 2013-07-26 12:56:58 +0200 | [diff] [blame] | 395 | power_failed |= axp221_set_aldo1(CONFIG_AXP221_ALDO1_VOLT); |
Oliver Schinagl | d3a558d | 2013-07-26 12:56:58 +0200 | [diff] [blame] | 396 | power_failed |= axp221_set_aldo2(CONFIG_AXP221_ALDO2_VOLT); |
Oliver Schinagl | d3a558d | 2013-07-26 12:56:58 +0200 | [diff] [blame] | 397 | power_failed |= axp221_set_aldo3(CONFIG_AXP221_ALDO3_VOLT); |
Siarhei Siamashka | 7e4eb6c | 2015-01-19 05:23:30 +0200 | [diff] [blame] | 398 | power_failed |= axp221_set_eldo(3, CONFIG_AXP221_ELDO3_VOLT); |
Oliver Schinagl | d3a558d | 2013-07-26 12:56:58 +0200 | [diff] [blame] | 399 | #endif |
Henrik Nordstrom | aa382ad | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 400 | |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 401 | printf("DRAM:"); |
| 402 | ramsize = sunxi_dram_init(); |
| 403 | printf(" %lu MiB\n", ramsize >> 20); |
| 404 | if (!ramsize) |
| 405 | hang(); |
Henrik Nordstrom | aa382ad | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 406 | |
| 407 | /* |
| 408 | * Only clock up the CPU to full speed if we are reasonably |
| 409 | * assured it's being powered with suitable core voltage |
| 410 | */ |
| 411 | if (!power_failed) |
Iain Paton | 630df14 | 2015-03-28 10:26:38 +0000 | [diff] [blame] | 412 | clock_set_pll1(CONFIG_SYS_CLK_FREQ); |
Henrik Nordstrom | aa382ad | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 413 | else |
| 414 | printf("Failed to set core voltage! Can't set CPU frequency\n"); |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 415 | } |
| 416 | #endif |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 417 | |
Hans de Goede | f494cad | 2015-01-11 17:17:00 +0100 | [diff] [blame] | 418 | #if defined(CONFIG_MUSB_HOST) || defined(CONFIG_MUSB_GADGET) |
| 419 | static struct musb_hdrc_config musb_config = { |
| 420 | .multipoint = 1, |
| 421 | .dyn_fifo = 1, |
| 422 | .num_eps = 6, |
| 423 | .ram_bits = 11, |
| 424 | }; |
| 425 | |
| 426 | static struct musb_hdrc_platform_data musb_plat = { |
| 427 | #if defined(CONFIG_MUSB_HOST) |
| 428 | .mode = MUSB_HOST, |
| 429 | #else |
| 430 | .mode = MUSB_PERIPHERAL, |
| 431 | #endif |
| 432 | .config = &musb_config, |
| 433 | .power = 250, |
| 434 | .platform_ops = &sunxi_musb_ops, |
| 435 | }; |
| 436 | #endif |
| 437 | |
Paul Kocialkowski | dbbccaf | 2015-03-22 18:07:13 +0100 | [diff] [blame] | 438 | #ifdef CONFIG_USB_GADGET |
| 439 | int g_dnl_board_usb_cable_connected(void) |
| 440 | { |
| 441 | return sunxi_usbc_vbus_detect(0); |
| 442 | } |
| 443 | #endif |
| 444 | |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 445 | #ifdef CONFIG_MISC_INIT_R |
| 446 | int misc_init_r(void) |
| 447 | { |
Paul Kocialkowski | 9293594 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 448 | char serial_string[17] = { 0 }; |
Hans de Goede | 11d7098 | 2014-11-26 00:04:24 +0100 | [diff] [blame] | 449 | unsigned int sid[4]; |
Paul Kocialkowski | 9293594 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 450 | uint8_t mac_addr[6]; |
| 451 | int ret; |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 452 | |
Paul Kocialkowski | 9293594 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 453 | ret = sunxi_get_sid(sid); |
| 454 | if (ret == 0 && sid[0] != 0 && sid[3] != 0) { |
| 455 | if (!getenv("ethaddr")) { |
| 456 | /* Non OUI / registered MAC address */ |
| 457 | mac_addr[0] = 0x02; |
| 458 | mac_addr[1] = (sid[0] >> 0) & 0xff; |
| 459 | mac_addr[2] = (sid[3] >> 24) & 0xff; |
| 460 | mac_addr[3] = (sid[3] >> 16) & 0xff; |
| 461 | mac_addr[4] = (sid[3] >> 8) & 0xff; |
| 462 | mac_addr[5] = (sid[3] >> 0) & 0xff; |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 463 | |
Paul Kocialkowski | 9293594 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 464 | eth_setenv_enetaddr("ethaddr", mac_addr); |
| 465 | } |
| 466 | |
| 467 | if (!getenv("serial#")) { |
| 468 | snprintf(serial_string, sizeof(serial_string), |
| 469 | "%08x%08x", sid[0], sid[3]); |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 470 | |
Paul Kocialkowski | 9293594 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 471 | setenv("serial#", serial_string); |
| 472 | } |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 473 | } |
| 474 | |
Hans de Goede | f494cad | 2015-01-11 17:17:00 +0100 | [diff] [blame] | 475 | #if defined(CONFIG_MUSB_HOST) || defined(CONFIG_MUSB_GADGET) |
| 476 | musb_register(&musb_plat, NULL, (void *)SUNXI_USB0_BASE); |
| 477 | #endif |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 478 | return 0; |
| 479 | } |
| 480 | #endif |
Luc Verhaegen | 4869a8c | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 481 | |
| 482 | #ifdef CONFIG_OF_BOARD_SETUP |
| 483 | int ft_board_setup(void *blob, bd_t *bd) |
| 484 | { |
| 485 | #ifdef CONFIG_VIDEO_DT_SIMPLEFB |
| 486 | return sunxi_simplefb_setup(blob); |
| 487 | #endif |
| 488 | } |
| 489 | #endif /* CONFIG_OF_BOARD_SETUP */ |