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