Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2009 |
| 4 | * Marvell Semiconductor <www.marvell.com> |
| 5 | * Prafulla Wadaskar <prafulla@marvell.com> |
| 6 | * |
| 7 | * (C) Copyright 2009 |
| 8 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 9 | * |
| 10 | * (C) Copyright 2010 |
| 11 | * Heiko Schocher, DENX Software Engineering, hs@denx.de. |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <common.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 15 | #include <env.h> |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 16 | #include <i2c.h> |
| 17 | #include <nand.h> |
| 18 | #include <netdev.h> |
| 19 | #include <miiphy.h> |
Valentin Longchamp | 96957ef | 2012-06-13 03:01:03 +0000 | [diff] [blame] | 20 | #include <spi.h> |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 21 | #include <asm/io.h> |
Lei Wen | 298ae91 | 2011-10-18 20:11:42 +0530 | [diff] [blame] | 22 | #include <asm/arch/cpu.h> |
Stefan Roese | c243784 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 23 | #include <asm/arch/soc.h> |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 24 | #include <asm/arch/mpp.h> |
| 25 | |
| 26 | #include "../common/common.h" |
| 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 30 | /* |
| 31 | * BOCO FPGA definitions |
| 32 | */ |
| 33 | #define BOCO 0x10 |
| 34 | #define REG_CTRL_H 0x02 |
| 35 | #define MASK_WRL_UNITRUN 0x01 |
| 36 | #define MASK_RBX_PGY_PRESENT 0x40 |
| 37 | #define REG_IRQ_CIRQ2 0x2d |
| 38 | #define MASK_RBI_DEFECT_16 0x01 |
| 39 | |
Tobias Müller | b0cab2d | 2015-11-13 15:01:15 +0100 | [diff] [blame] | 40 | /* |
| 41 | * PHY registers definitions |
| 42 | */ |
| 43 | #define PHY_MARVELL_OUI 0x5043 |
| 44 | #define PHY_MARVELL_88E1118_MODEL 0x0022 |
| 45 | #define PHY_MARVELL_88E1118R_MODEL 0x0024 |
| 46 | |
| 47 | #define PHY_MARVELL_PAGE_REG 0x0016 |
| 48 | #define PHY_MARVELL_DEFAULT_PAGE 0x0000 |
| 49 | |
| 50 | #define PHY_MARVELL_88E1118R_LED_CTRL_PAGE 0x0003 |
| 51 | #define PHY_MARVELL_88E1118R_LED_CTRL_REG 0x0010 |
| 52 | |
| 53 | #define PHY_MARVELL_88E1118R_LED_CTRL_RESERVED 0x1000 |
| 54 | #define PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB (0x7<<0) |
| 55 | #define PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT (0x3<<4) |
| 56 | #define PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK (0x0<<8) |
| 57 | |
Holger Brunck | 43cf329 | 2015-11-13 15:01:16 +0100 | [diff] [blame] | 58 | /* I/O pin to erase flash RGPP09 = MPP43 */ |
| 59 | #define KM_FLASH_ERASE_ENABLE 43 |
| 60 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 61 | /* Multi-Purpose Pins Functionality configuration */ |
Albert ARIBAUD | 4d42431 | 2012-11-26 11:27:36 +0000 | [diff] [blame] | 62 | static const u32 kwmpp_config[] = { |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 63 | MPP0_NF_IO2, |
| 64 | MPP1_NF_IO3, |
| 65 | MPP2_NF_IO4, |
| 66 | MPP3_NF_IO5, |
| 67 | MPP4_NF_IO6, |
| 68 | MPP5_NF_IO7, |
| 69 | MPP6_SYSRST_OUTn, |
Gerlando Falauto | 29ff59a | 2014-02-13 16:43:00 +0100 | [diff] [blame] | 70 | #if defined(KM_PCIE_RESET_MPP7) |
| 71 | MPP7_GPO, |
| 72 | #else |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 73 | MPP7_PEX_RST_OUTn, |
Gerlando Falauto | 29ff59a | 2014-02-13 16:43:00 +0100 | [diff] [blame] | 74 | #endif |
Heiko Schocher | 479a4cf | 2013-01-29 08:53:15 +0100 | [diff] [blame] | 75 | #if defined(CONFIG_SYS_I2C_SOFT) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 76 | MPP8_GPIO, /* SDA */ |
| 77 | MPP9_GPIO, /* SCL */ |
| 78 | #endif |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 79 | MPP10_UART0_TXD, |
| 80 | MPP11_UART0_RXD, |
| 81 | MPP12_GPO, /* Reserved */ |
| 82 | MPP13_UART1_TXD, |
| 83 | MPP14_UART1_RXD, |
| 84 | MPP15_GPIO, /* Not used */ |
| 85 | MPP16_GPIO, /* Not used */ |
| 86 | MPP17_GPIO, /* Reserved */ |
| 87 | MPP18_NF_IO0, |
| 88 | MPP19_NF_IO1, |
| 89 | MPP20_GPIO, |
| 90 | MPP21_GPIO, |
| 91 | MPP22_GPIO, |
| 92 | MPP23_GPIO, |
| 93 | MPP24_GPIO, |
| 94 | MPP25_GPIO, |
| 95 | MPP26_GPIO, |
| 96 | MPP27_GPIO, |
| 97 | MPP28_GPIO, |
| 98 | MPP29_GPIO, |
| 99 | MPP30_GPIO, |
| 100 | MPP31_GPIO, |
| 101 | MPP32_GPIO, |
| 102 | MPP33_GPIO, |
| 103 | MPP34_GPIO, /* CDL1 (input) */ |
| 104 | MPP35_GPIO, /* CDL2 (input) */ |
| 105 | MPP36_GPIO, /* MAIN_IRQ (input) */ |
| 106 | MPP37_GPIO, /* BOARD_LED */ |
| 107 | MPP38_GPIO, /* Piggy3 LED[1] */ |
| 108 | MPP39_GPIO, /* Piggy3 LED[2] */ |
| 109 | MPP40_GPIO, /* Piggy3 LED[3] */ |
| 110 | MPP41_GPIO, /* Piggy3 LED[4] */ |
| 111 | MPP42_GPIO, /* Piggy3 LED[5] */ |
| 112 | MPP43_GPIO, /* Piggy3 LED[6] */ |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 113 | MPP44_GPIO, /* Piggy3 LED[7], BIST_EN_L */ |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 114 | MPP45_GPIO, /* Piggy3 LED[8] */ |
| 115 | MPP46_GPIO, /* Reserved */ |
| 116 | MPP47_GPIO, /* Reserved */ |
| 117 | MPP48_GPIO, /* Reserved */ |
| 118 | MPP49_GPIO, /* SW_INTOUTn */ |
| 119 | 0 |
| 120 | }; |
| 121 | |
Valentin Longchamp | aea4bb5 | 2015-02-10 17:10:14 +0100 | [diff] [blame] | 122 | static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN]; |
| 123 | |
Holger Brunck | d896d0d | 2012-07-05 05:05:03 +0000 | [diff] [blame] | 124 | #if defined(CONFIG_KM_MGCOGE3UN) |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 125 | /* |
| 126 | * Wait for startup OK from mgcoge3ne |
| 127 | */ |
Holger Brunck | 09346ff | 2014-01-27 16:58:23 +0100 | [diff] [blame] | 128 | static int startup_allowed(void) |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 129 | { |
| 130 | unsigned char buf; |
| 131 | |
| 132 | /* |
| 133 | * Read CIRQ16 bit (bit 0) |
| 134 | */ |
| 135 | if (i2c_read(BOCO, REG_IRQ_CIRQ2, 1, &buf, 1) != 0) |
| 136 | printf("%s: Error reading Boco\n", __func__); |
| 137 | else |
| 138 | if ((buf & MASK_RBI_DEFECT_16) == MASK_RBI_DEFECT_16) |
| 139 | return 1; |
| 140 | return 0; |
| 141 | } |
Valentin Longchamp | 2ec63ad | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 142 | #endif |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 143 | |
Holger Brunck | d896d0d | 2012-07-05 05:05:03 +0000 | [diff] [blame] | 144 | #if (defined(CONFIG_KM_PIGGY4_88E6061)|defined(CONFIG_KM_PIGGY4_88E6352)) |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 145 | /* |
Holger Brunck | 2ef4295 | 2012-07-05 05:37:46 +0000 | [diff] [blame] | 146 | * All boards with PIGGY4 connected via a simple switch have ethernet always |
| 147 | * present. |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 148 | */ |
| 149 | int ethernet_present(void) |
| 150 | { |
| 151 | return 1; |
| 152 | } |
| 153 | #else |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 154 | int ethernet_present(void) |
| 155 | { |
| 156 | uchar buf; |
| 157 | int ret = 0; |
| 158 | |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 159 | if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) { |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 160 | printf("%s: Error reading Boco\n", __func__); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 161 | return -1; |
| 162 | } |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 163 | if ((buf & MASK_RBX_PGY_PRESENT) == MASK_RBX_PGY_PRESENT) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 164 | ret = 1; |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 165 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 166 | return ret; |
| 167 | } |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 168 | #endif |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 169 | |
Holger Brunck | 03ab286 | 2013-05-06 15:04:51 +0200 | [diff] [blame] | 170 | static int initialize_unit_leds(void) |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 171 | { |
| 172 | /* |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 173 | * Init the unit LEDs per default they all are |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 174 | * ok apart from bootstat |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 175 | */ |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 176 | uchar buf; |
| 177 | |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 178 | if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) { |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 179 | printf("%s: Error reading Boco\n", __func__); |
| 180 | return -1; |
| 181 | } |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 182 | buf |= MASK_WRL_UNITRUN; |
| 183 | if (i2c_write(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) { |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 184 | printf("%s: Error writing Boco\n", __func__); |
| 185 | return -1; |
| 186 | } |
| 187 | return 0; |
| 188 | } |
| 189 | |
Holger Brunck | 03ab286 | 2013-05-06 15:04:51 +0200 | [diff] [blame] | 190 | static void set_bootcount_addr(void) |
Valentin Longchamp | 184907a | 2011-05-31 02:12:47 +0000 | [diff] [blame] | 191 | { |
| 192 | uchar buf[32]; |
| 193 | unsigned int bootcountaddr; |
| 194 | bootcountaddr = gd->ram_size - BOOTCOUNT_ADDR; |
| 195 | sprintf((char *)buf, "0x%x", bootcountaddr); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 196 | env_set("bootcountaddr", (char *)buf); |
Valentin Longchamp | 184907a | 2011-05-31 02:12:47 +0000 | [diff] [blame] | 197 | } |
Valentin Longchamp | 184907a | 2011-05-31 02:12:47 +0000 | [diff] [blame] | 198 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 199 | int misc_init_r(void) |
| 200 | { |
Holger Brunck | d896d0d | 2012-07-05 05:05:03 +0000 | [diff] [blame] | 201 | #if defined(CONFIG_KM_MGCOGE3UN) |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 202 | char *wait_for_ne; |
Holger Brunck | 43cf329 | 2015-11-13 15:01:16 +0100 | [diff] [blame] | 203 | u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE); |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 204 | wait_for_ne = env_get("waitforne"); |
Holger Brunck | 43cf329 | 2015-11-13 15:01:16 +0100 | [diff] [blame] | 205 | |
| 206 | if ((wait_for_ne != NULL) && (dip_switch == 0)) { |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 207 | if (strcmp(wait_for_ne, "true") == 0) { |
| 208 | int cnt = 0; |
Holger Brunck | 42874a7 | 2011-09-27 02:54:31 +0000 | [diff] [blame] | 209 | int abort = 0; |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 210 | puts("NE go: "); |
| 211 | while (startup_allowed() == 0) { |
Holger Brunck | 42874a7 | 2011-09-27 02:54:31 +0000 | [diff] [blame] | 212 | if (tstc()) { |
| 213 | (void) getc(); /* consume input */ |
| 214 | abort = 1; |
| 215 | break; |
| 216 | } |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 217 | udelay(200000); |
| 218 | cnt++; |
| 219 | if (cnt == 5) |
| 220 | puts("wait\b\b\b\b"); |
| 221 | if (cnt == 10) { |
| 222 | cnt = 0; |
| 223 | puts(" \b\b\b\b"); |
| 224 | } |
| 225 | } |
Holger Brunck | 42874a7 | 2011-09-27 02:54:31 +0000 | [diff] [blame] | 226 | if (abort == 1) |
| 227 | printf("\nAbort waiting for ne\n"); |
| 228 | else |
| 229 | puts("OK\n"); |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | #endif |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 233 | |
Valentin Longchamp | 876f7a9 | 2015-02-10 17:10:18 +0100 | [diff] [blame] | 234 | ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN); |
Valentin Longchamp | aea4bb5 | 2015-02-10 17:10:14 +0100 | [diff] [blame] | 235 | |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 236 | initialize_unit_leds(); |
Valentin Longchamp | 184907a | 2011-05-31 02:12:47 +0000 | [diff] [blame] | 237 | set_km_env(); |
Valentin Longchamp | 184907a | 2011-05-31 02:12:47 +0000 | [diff] [blame] | 238 | set_bootcount_addr(); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 239 | return 0; |
| 240 | } |
| 241 | |
Heiko Schocher | 3ebd02b | 2010-10-20 19:33:26 +0530 | [diff] [blame] | 242 | int board_early_init_f(void) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 243 | { |
Heiko Schocher | 479a4cf | 2013-01-29 08:53:15 +0100 | [diff] [blame] | 244 | #if defined(CONFIG_SYS_I2C_SOFT) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 245 | u32 tmp; |
| 246 | |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 247 | /* set the 2 bitbang i2c pins as output gpios */ |
Stefan Roese | c50ab39 | 2014-10-22 12:13:11 +0200 | [diff] [blame] | 248 | tmp = readl(MVEBU_GPIO0_BASE + 4); |
| 249 | writel(tmp & (~KM_KIRKWOOD_SOFT_I2C_GPIOS) , MVEBU_GPIO0_BASE + 4); |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 250 | #endif |
Holger Brunck | b59a955 | 2012-07-25 06:26:03 +0000 | [diff] [blame] | 251 | /* adjust SDRAM size for bank 0 */ |
Stefan Roese | 0b74175 | 2014-10-22 12:13:13 +0200 | [diff] [blame] | 252 | mvebu_sdram_size_adjust(0); |
Valentin Longchamp | 7d0d502 | 2012-06-01 01:31:00 +0000 | [diff] [blame] | 253 | kirkwood_mpp_conf(kwmpp_config, NULL); |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 254 | return 0; |
| 255 | } |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 256 | |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 257 | int board_init(void) |
| 258 | { |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 259 | /* address of boot parameters */ |
Stefan Roese | 0b74175 | 2014-10-22 12:13:13 +0200 | [diff] [blame] | 260 | gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 261 | |
| 262 | /* |
| 263 | * The KM_FLASH_GPIO_PIN switches between using a |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 264 | * NAND or a SPI FLASH. Set this pin on start |
| 265 | * to NAND mode. |
| 266 | */ |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 267 | kw_gpio_set_valid(KM_FLASH_GPIO_PIN, 1); |
| 268 | kw_gpio_direction_output(KM_FLASH_GPIO_PIN, 1); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 269 | |
Heiko Schocher | 479a4cf | 2013-01-29 08:53:15 +0100 | [diff] [blame] | 270 | #if defined(CONFIG_SYS_I2C_SOFT) |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 271 | /* |
| 272 | * Reinit the GPIO for I2C Bitbang driver so that the now |
| 273 | * available gpio framework is consistent. The calls to |
| 274 | * direction output in are not necessary, they are already done in |
| 275 | * board_early_init_f |
| 276 | */ |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 277 | kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1); |
| 278 | kw_gpio_set_valid(KM_KIRKWOOD_SCL_PIN, 1); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 279 | #endif |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 280 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 281 | #if defined(CONFIG_SYS_EEPROM_WREN) |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 282 | kw_gpio_set_valid(KM_KIRKWOOD_ENV_WP, 38); |
| 283 | kw_gpio_direction_output(KM_KIRKWOOD_ENV_WP, 1); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 284 | #endif |
Heiko Schocher | 3ebd02b | 2010-10-20 19:33:26 +0530 | [diff] [blame] | 285 | |
Valentin Longchamp | 6633fed | 2012-07-05 05:05:05 +0000 | [diff] [blame] | 286 | #if defined(CONFIG_KM_FPGA_CONFIG) |
| 287 | trigger_fpga_config(); |
| 288 | #endif |
| 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | int board_late_init(void) |
| 294 | { |
Valentin Longchamp | bba4e25 | 2015-11-13 15:01:17 +0100 | [diff] [blame] | 295 | #if (defined(CONFIG_KM_COGE5UN) | defined(CONFIG_KM_MGCOGE3UN)) |
Thomas Herzmann | 3ed5314 | 2012-07-05 05:05:10 +0000 | [diff] [blame] | 296 | u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE); |
| 297 | |
| 298 | /* if pin 1 do full erase */ |
| 299 | if (dip_switch != 0) { |
| 300 | /* start bootloader */ |
| 301 | puts("DIP: Enabled\n"); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 302 | env_set("actual_bank", "0"); |
Thomas Herzmann | 3ed5314 | 2012-07-05 05:05:10 +0000 | [diff] [blame] | 303 | } |
| 304 | #endif |
| 305 | |
Valentin Longchamp | 6633fed | 2012-07-05 05:05:05 +0000 | [diff] [blame] | 306 | #if defined(CONFIG_KM_FPGA_CONFIG) |
| 307 | wait_for_fpga_config(); |
| 308 | fpga_reset(); |
| 309 | toggle_eeprom_spi_bus(); |
| 310 | #endif |
Heiko Schocher | cfc5804 | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 311 | return 0; |
| 312 | } |
| 313 | |
Pascal Linder | 6adad98 | 2019-06-18 08:41:02 +0200 | [diff] [blame] | 314 | static const u32 spi_mpp_config[] = { |
| 315 | MPP1_SPI_MOSI, |
| 316 | MPP2_SPI_SCK, |
| 317 | MPP3_SPI_MISO, |
| 318 | 0 |
| 319 | }; |
| 320 | |
| 321 | static u32 spi_mpp_backup[4]; |
| 322 | |
| 323 | int mvebu_board_spi_claim_bus(struct udevice *dev) |
| 324 | { |
| 325 | spi_mpp_backup[3] = 0; |
| 326 | |
| 327 | /* set new spi mpp config and save current one */ |
| 328 | kirkwood_mpp_conf(spi_mpp_config, spi_mpp_backup); |
| 329 | |
| 330 | kw_gpio_set_value(KM_FLASH_GPIO_PIN, 0); |
| 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | int mvebu_board_spi_release_bus(struct udevice *dev) |
| 336 | { |
| 337 | /* restore saved mpp config */ |
| 338 | kirkwood_mpp_conf(spi_mpp_backup, NULL); |
| 339 | |
| 340 | kw_gpio_set_value(KM_FLASH_GPIO_PIN, 1); |
| 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
Holger Brunck | c9caa7f | 2012-07-05 05:05:04 +0000 | [diff] [blame] | 345 | #if (defined(CONFIG_KM_PIGGY4_88E6061)) |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 346 | |
Valentin Longchamp | a7ef9af | 2012-07-05 05:05:07 +0000 | [diff] [blame] | 347 | #define PHY_LED_SEL_REG 0x18 |
| 348 | #define PHY_LED0_LINK (0x5) |
| 349 | #define PHY_LED1_ACT (0x8<<4) |
| 350 | #define PHY_LED2_INT (0xe<<8) |
| 351 | #define PHY_SPEC_CTRL_REG 0x1c |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 352 | #define PHY_RGMII_CLK_STABLE (0x1<<10) |
Valentin Longchamp | a7ef9af | 2012-07-05 05:05:07 +0000 | [diff] [blame] | 353 | #define PHY_CLSA (0x1<<1) |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 354 | |
| 355 | /* Configure and enable MV88E3018 PHY */ |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 356 | void reset_phy(void) |
| 357 | { |
| 358 | char *name = "egiga0"; |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 359 | unsigned short reg; |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 360 | |
| 361 | if (miiphy_set_current_dev(name)) |
| 362 | return; |
| 363 | |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 364 | /* RGMII clk transition on data stable */ |
Holger Brunck | 7fef655 | 2014-01-27 16:58:26 +0100 | [diff] [blame] | 365 | if (miiphy_read(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG, ®)) |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 366 | printf("Error reading PHY spec ctrl reg\n"); |
Holger Brunck | 7fef655 | 2014-01-27 16:58:26 +0100 | [diff] [blame] | 367 | if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG, |
| 368 | reg | PHY_RGMII_CLK_STABLE | PHY_CLSA)) |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 369 | printf("Error writing PHY spec ctrl reg\n"); |
| 370 | |
| 371 | /* leds setup */ |
Holger Brunck | 7fef655 | 2014-01-27 16:58:26 +0100 | [diff] [blame] | 372 | if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_LED_SEL_REG, |
| 373 | PHY_LED0_LINK | PHY_LED1_ACT | PHY_LED2_INT)) |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 374 | printf("Error writing PHY LED reg\n"); |
| 375 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 376 | /* reset the phy */ |
| 377 | miiphy_reset(name, CONFIG_PHY_BASE_ADR); |
| 378 | } |
Valentin Longchamp | 310164a | 2012-08-16 23:35:03 +0000 | [diff] [blame] | 379 | #elif defined(CONFIG_KM_PIGGY4_88E6352) |
| 380 | |
| 381 | #include <mv88e6352.h> |
| 382 | |
| 383 | #if defined(CONFIG_KM_NUSA) |
| 384 | struct mv88e_sw_reg extsw_conf[] = { |
| 385 | /* |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 386 | * port 0, PIGGY4, autoneg |
Valentin Longchamp | 310164a | 2012-08-16 23:35:03 +0000 | [diff] [blame] | 387 | * first the fix for the 1000Mbits Autoneg, this is from |
| 388 | * a Marvell errata, the regs are undocumented |
| 389 | */ |
| 390 | { PHY(0), PHY_PAGE, AN1000FIX_PAGE }, |
| 391 | { PHY(0), PHY_STATUS, AN1000FIX }, |
| 392 | { PHY(0), PHY_PAGE, 0 }, |
| 393 | /* now the real port and phy configuration */ |
| 394 | { PORT(0), PORT_PHY, NO_SPEED_FOR }, |
| 395 | { PORT(0), PORT_CTRL, FORWARDING | EGRS_FLD_ALL }, |
| 396 | { PHY(0), PHY_1000_CTRL, NO_ADV }, |
| 397 | { PHY(0), PHY_SPEC_CTRL, AUTO_MDIX_EN }, |
| 398 | { PHY(0), PHY_CTRL, PHY_100_MBPS | AUTONEG_EN | AUTONEG_RST | |
| 399 | FULL_DUPLEX }, |
| 400 | /* port 1, unused */ |
| 401 | { PORT(1), PORT_CTRL, PORT_DIS }, |
| 402 | { PHY(1), PHY_CTRL, PHY_PWR_DOWN }, |
| 403 | { PHY(1), PHY_SPEC_CTRL, SPEC_PWR_DOWN }, |
| 404 | /* port 2, unused */ |
| 405 | { PORT(2), PORT_CTRL, PORT_DIS }, |
| 406 | { PHY(2), PHY_CTRL, PHY_PWR_DOWN }, |
| 407 | { PHY(2), PHY_SPEC_CTRL, SPEC_PWR_DOWN }, |
| 408 | /* port 3, unused */ |
| 409 | { PORT(3), PORT_CTRL, PORT_DIS }, |
| 410 | { PHY(3), PHY_CTRL, PHY_PWR_DOWN }, |
| 411 | { PHY(3), PHY_SPEC_CTRL, SPEC_PWR_DOWN }, |
| 412 | /* port 4, ICNEV, SerDes, SGMII */ |
| 413 | { PORT(4), PORT_STATUS, NO_PHY_DETECT }, |
| 414 | { PORT(4), PORT_PHY, SPEED_1000_FOR }, |
| 415 | { PORT(4), PORT_CTRL, FORWARDING | EGRS_FLD_ALL }, |
| 416 | { PHY(4), PHY_CTRL, PHY_PWR_DOWN }, |
| 417 | { PHY(4), PHY_SPEC_CTRL, SPEC_PWR_DOWN }, |
| 418 | /* port 5, CPU_RGMII */ |
| 419 | { PORT(5), PORT_PHY, RX_RGMII_TIM | TX_RGMII_TIM | FLOW_CTRL_EN | |
| 420 | FLOW_CTRL_FOR | LINK_VAL | LINK_FOR | FULL_DPX | |
| 421 | FULL_DPX_FOR | SPEED_1000_FOR }, |
| 422 | { PORT(5), PORT_CTRL, FORWARDING | EGRS_FLD_ALL }, |
| 423 | /* port 6, unused, this port has no phy */ |
| 424 | { PORT(6), PORT_CTRL, PORT_DIS }, |
| 425 | }; |
| 426 | #else |
| 427 | struct mv88e_sw_reg extsw_conf[] = {}; |
| 428 | #endif |
| 429 | |
| 430 | void reset_phy(void) |
| 431 | { |
| 432 | #if defined(CONFIG_KM_MVEXTSW_ADDR) |
| 433 | char *name = "egiga0"; |
| 434 | |
| 435 | if (miiphy_set_current_dev(name)) |
| 436 | return; |
| 437 | |
| 438 | mv88e_sw_program(name, CONFIG_KM_MVEXTSW_ADDR, extsw_conf, |
| 439 | ARRAY_SIZE(extsw_conf)); |
| 440 | mv88e_sw_reset(name, CONFIG_KM_MVEXTSW_ADDR); |
| 441 | #endif |
| 442 | } |
| 443 | |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 444 | #else |
| 445 | /* Configure and enable MV88E1118 PHY on the piggy*/ |
| 446 | void reset_phy(void) |
| 447 | { |
Tobias Müller | b0cab2d | 2015-11-13 15:01:15 +0100 | [diff] [blame] | 448 | unsigned int oui; |
| 449 | unsigned char model, rev; |
| 450 | |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 451 | char *name = "egiga0"; |
| 452 | |
| 453 | if (miiphy_set_current_dev(name)) |
| 454 | return; |
| 455 | |
| 456 | /* reset the phy */ |
| 457 | miiphy_reset(name, CONFIG_PHY_BASE_ADR); |
Tobias Müller | b0cab2d | 2015-11-13 15:01:15 +0100 | [diff] [blame] | 458 | |
| 459 | /* get PHY model */ |
| 460 | if (miiphy_info(name, CONFIG_PHY_BASE_ADR, &oui, &model, &rev)) |
| 461 | return; |
| 462 | |
| 463 | /* check for Marvell 88E1118R Gigabit PHY (PIGGY3) */ |
| 464 | if ((oui == PHY_MARVELL_OUI) && |
| 465 | (model == PHY_MARVELL_88E1118R_MODEL)) { |
| 466 | /* set page register to 3 */ |
| 467 | if (miiphy_write(name, CONFIG_PHY_BASE_ADR, |
| 468 | PHY_MARVELL_PAGE_REG, |
| 469 | PHY_MARVELL_88E1118R_LED_CTRL_PAGE)) |
| 470 | printf("Error writing PHY page reg\n"); |
| 471 | |
| 472 | /* |
| 473 | * leds setup as printed on PCB: |
| 474 | * LED2 (Link): 0x0 (On Link, Off No Link) |
| 475 | * LED1 (Activity): 0x3 (On Activity, Off No Activity) |
| 476 | * LED0 (Speed): 0x7 (On 1000 MBits, Off Else) |
| 477 | */ |
| 478 | if (miiphy_write(name, CONFIG_PHY_BASE_ADR, |
| 479 | PHY_MARVELL_88E1118R_LED_CTRL_REG, |
| 480 | PHY_MARVELL_88E1118R_LED_CTRL_RESERVED | |
| 481 | PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB | |
| 482 | PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT | |
| 483 | PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK)) |
| 484 | printf("Error writing PHY LED reg\n"); |
| 485 | |
| 486 | /* set page register back to 0 */ |
| 487 | if (miiphy_write(name, CONFIG_PHY_BASE_ADR, |
| 488 | PHY_MARVELL_PAGE_REG, |
| 489 | PHY_MARVELL_DEFAULT_PAGE)) |
| 490 | printf("Error writing PHY page reg\n"); |
| 491 | } |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 492 | } |
| 493 | #endif |
| 494 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 495 | |
| 496 | #if defined(CONFIG_HUSH_INIT_VAR) |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 497 | int hush_init_var(void) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 498 | { |
Valentin Longchamp | aea4bb5 | 2015-02-10 17:10:14 +0100 | [diff] [blame] | 499 | ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 500 | return 0; |
| 501 | } |
| 502 | #endif |
| 503 | |
Heiko Schocher | 479a4cf | 2013-01-29 08:53:15 +0100 | [diff] [blame] | 504 | #if defined(CONFIG_SYS_I2C_SOFT) |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 505 | void set_sda(int state) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 506 | { |
| 507 | I2C_ACTIVE; |
| 508 | I2C_SDA(state); |
| 509 | } |
| 510 | |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 511 | void set_scl(int state) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 512 | { |
| 513 | I2C_SCL(state); |
| 514 | } |
| 515 | |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 516 | int get_sda(void) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 517 | { |
| 518 | I2C_TRISTATE; |
| 519 | return I2C_READ; |
| 520 | } |
| 521 | |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 522 | int get_scl(void) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 523 | { |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 524 | return kw_gpio_get_value(KM_KIRKWOOD_SCL_PIN) ? 1 : 0; |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 525 | } |
| 526 | #endif |
| 527 | |
Valentin Longchamp | 24ec993 | 2011-09-12 04:18:42 +0000 | [diff] [blame] | 528 | #if defined(CONFIG_POST) |
| 529 | |
| 530 | #define KM_POST_EN_L 44 |
| 531 | #define POST_WORD_OFF 8 |
| 532 | |
| 533 | int post_hotkeys_pressed(void) |
| 534 | { |
Holger Brunck | f065ce0 | 2012-07-05 05:05:02 +0000 | [diff] [blame] | 535 | #if defined(CONFIG_KM_COGE5UN) |
| 536 | return kw_gpio_get_value(KM_POST_EN_L); |
| 537 | #else |
Valentin Longchamp | 24ec993 | 2011-09-12 04:18:42 +0000 | [diff] [blame] | 538 | return !kw_gpio_get_value(KM_POST_EN_L); |
Holger Brunck | f065ce0 | 2012-07-05 05:05:02 +0000 | [diff] [blame] | 539 | #endif |
Valentin Longchamp | 24ec993 | 2011-09-12 04:18:42 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | ulong post_word_load(void) |
| 543 | { |
Holger Brunck | 763c2dc | 2011-12-14 05:31:20 +0000 | [diff] [blame] | 544 | void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF); |
Valentin Longchamp | 24ec993 | 2011-09-12 04:18:42 +0000 | [diff] [blame] | 545 | return in_le32(addr); |
| 546 | |
| 547 | } |
| 548 | void post_word_store(ulong value) |
| 549 | { |
Holger Brunck | 763c2dc | 2011-12-14 05:31:20 +0000 | [diff] [blame] | 550 | void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF); |
Valentin Longchamp | 24ec993 | 2011-09-12 04:18:42 +0000 | [diff] [blame] | 551 | out_le32(addr, value); |
| 552 | } |
| 553 | |
| 554 | int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset) |
| 555 | { |
| 556 | *vstart = CONFIG_SYS_SDRAM_BASE; |
| 557 | |
| 558 | /* we go up to relocation plus a 1 MB margin */ |
| 559 | *size = CONFIG_SYS_TEXT_BASE - (1<<20); |
| 560 | |
| 561 | return 0; |
| 562 | } |
| 563 | #endif |
| 564 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 565 | #if defined(CONFIG_SYS_EEPROM_WREN) |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 566 | int eeprom_write_enable(unsigned dev_addr, int state) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 567 | { |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 568 | kw_gpio_set_value(KM_KIRKWOOD_ENV_WP, !state); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 569 | |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 570 | return !kw_gpio_get_value(KM_KIRKWOOD_ENV_WP); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 571 | } |
| 572 | #endif |