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