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 */ |
| 57 | u32 kwmpp_config[] = { |
| 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 | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 117 | #if defined(CONFIG_MGCOGE3UN) |
| 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 | 2ef4295 | 2012-07-05 05:37:46 +0000 | [diff] [blame^] | 137 | #if (defined(CONFIG_MGCOGE3UN)|defined(CONFIG_PORTL2)| \ |
| 138 | defined(CONFIG_KM_PIGGY4_88E6352)) |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 139 | /* |
Holger Brunck | 2ef4295 | 2012-07-05 05:37:46 +0000 | [diff] [blame^] | 140 | * All boards with PIGGY4 connected via a simple switch have ethernet always |
| 141 | * present. |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 142 | */ |
| 143 | int ethernet_present(void) |
| 144 | { |
| 145 | return 1; |
| 146 | } |
| 147 | #else |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 148 | int ethernet_present(void) |
| 149 | { |
| 150 | uchar buf; |
| 151 | int ret = 0; |
| 152 | |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 153 | if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) { |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 154 | printf("%s: Error reading Boco\n", __func__); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 155 | return -1; |
| 156 | } |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 157 | if ((buf & MASK_RBX_PGY_PRESENT) == MASK_RBX_PGY_PRESENT) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 158 | ret = 1; |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 159 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 160 | return ret; |
| 161 | } |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 162 | #endif |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 163 | |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 164 | int initialize_unit_leds(void) |
| 165 | { |
| 166 | /* |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 167 | * Init the unit LEDs per default they all are |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 168 | * ok apart from bootstat |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 169 | */ |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 170 | uchar buf; |
| 171 | |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 172 | if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) { |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 173 | printf("%s: Error reading Boco\n", __func__); |
| 174 | return -1; |
| 175 | } |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 176 | buf |= MASK_WRL_UNITRUN; |
| 177 | if (i2c_write(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) { |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 178 | printf("%s: Error writing Boco\n", __func__); |
| 179 | return -1; |
| 180 | } |
| 181 | return 0; |
| 182 | } |
| 183 | |
Valentin Longchamp | 184907a | 2011-05-31 02:12:47 +0000 | [diff] [blame] | 184 | #if defined(CONFIG_BOOTCOUNT_LIMIT) |
| 185 | void set_bootcount_addr(void) |
| 186 | { |
| 187 | uchar buf[32]; |
| 188 | unsigned int bootcountaddr; |
| 189 | bootcountaddr = gd->ram_size - BOOTCOUNT_ADDR; |
| 190 | sprintf((char *)buf, "0x%x", bootcountaddr); |
| 191 | setenv("bootcountaddr", (char *)buf); |
| 192 | } |
| 193 | #endif |
| 194 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 195 | int misc_init_r(void) |
| 196 | { |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 197 | char *str; |
| 198 | int mach_type; |
| 199 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 200 | str = getenv("mach_type"); |
| 201 | if (str != NULL) { |
| 202 | mach_type = simple_strtoul(str, NULL, 10); |
| 203 | printf("Overwriting MACH_TYPE with %d!!!\n", mach_type); |
| 204 | gd->bd->bi_arch_number = mach_type; |
| 205 | } |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 206 | #if defined(CONFIG_MGCOGE3UN) |
| 207 | char *wait_for_ne; |
| 208 | wait_for_ne = getenv("waitforne"); |
| 209 | if (wait_for_ne != NULL) { |
| 210 | if (strcmp(wait_for_ne, "true") == 0) { |
| 211 | int cnt = 0; |
Holger Brunck | 42874a7 | 2011-09-27 02:54:31 +0000 | [diff] [blame] | 212 | int abort = 0; |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 213 | puts("NE go: "); |
| 214 | while (startup_allowed() == 0) { |
Holger Brunck | 42874a7 | 2011-09-27 02:54:31 +0000 | [diff] [blame] | 215 | if (tstc()) { |
| 216 | (void) getc(); /* consume input */ |
| 217 | abort = 1; |
| 218 | break; |
| 219 | } |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 220 | udelay(200000); |
| 221 | cnt++; |
| 222 | if (cnt == 5) |
| 223 | puts("wait\b\b\b\b"); |
| 224 | if (cnt == 10) { |
| 225 | cnt = 0; |
| 226 | puts(" \b\b\b\b"); |
| 227 | } |
| 228 | } |
Holger Brunck | 42874a7 | 2011-09-27 02:54:31 +0000 | [diff] [blame] | 229 | if (abort == 1) |
| 230 | printf("\nAbort waiting for ne\n"); |
| 231 | else |
| 232 | puts("OK\n"); |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | #endif |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 236 | |
| 237 | initialize_unit_leds(); |
Valentin Longchamp | 184907a | 2011-05-31 02:12:47 +0000 | [diff] [blame] | 238 | set_km_env(); |
| 239 | #if defined(CONFIG_BOOTCOUNT_LIMIT) |
| 240 | set_bootcount_addr(); |
| 241 | #endif |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 242 | return 0; |
| 243 | } |
| 244 | |
Heiko Schocher | 3ebd02b | 2010-10-20 19:33:26 +0530 | [diff] [blame] | 245 | int board_early_init_f(void) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 246 | { |
| 247 | u32 tmp; |
| 248 | |
Valentin Longchamp | 7d0d502 | 2012-06-01 01:31:00 +0000 | [diff] [blame] | 249 | kirkwood_mpp_conf(kwmpp_config, NULL); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 250 | |
| 251 | /* |
| 252 | * The FLASH_GPIO_PIN switches between using a |
| 253 | * NAND or a SPI FLASH. Set this pin on start |
| 254 | * to NAND mode. |
| 255 | */ |
| 256 | tmp = readl(KW_GPIO0_BASE); |
| 257 | writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE); |
| 258 | tmp = readl(KW_GPIO0_BASE + 4); |
| 259 | writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE + 4); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 260 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 261 | #if defined(CONFIG_SOFT_I2C) |
| 262 | /* init the GPIO for I2C Bitbang driver */ |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 263 | kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1); |
| 264 | kw_gpio_set_valid(KM_KIRKWOOD_SCL_PIN, 1); |
| 265 | kw_gpio_direction_output(KM_KIRKWOOD_SDA_PIN, 0); |
| 266 | kw_gpio_direction_output(KM_KIRKWOOD_SCL_PIN, 0); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 267 | #endif |
| 268 | #if defined(CONFIG_SYS_EEPROM_WREN) |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 269 | kw_gpio_set_valid(KM_KIRKWOOD_ENV_WP, 38); |
| 270 | kw_gpio_direction_output(KM_KIRKWOOD_ENV_WP, 1); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 271 | #endif |
Holger Brunck | 83270ca | 2011-09-13 22:41:05 +0000 | [diff] [blame] | 272 | #if defined(CONFIG_KM_RECONFIG_XLX) |
| 273 | /* trigger the reconfiguration of the xilinx fpga */ |
| 274 | kw_gpio_set_valid(KM_XLX_PROGRAM_B_PIN, 1); |
| 275 | kw_gpio_direction_output(KM_XLX_PROGRAM_B_PIN, 0); |
| 276 | kw_gpio_direction_input(KM_XLX_PROGRAM_B_PIN); |
| 277 | #endif |
Heiko Schocher | 3ebd02b | 2010-10-20 19:33:26 +0530 | [diff] [blame] | 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | int board_init(void) |
| 282 | { |
Heiko Schocher | 3ebd02b | 2010-10-20 19:33:26 +0530 | [diff] [blame] | 283 | /* address of boot parameters */ |
| 284 | gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100; |
| 285 | |
Heiko Schocher | cfc5804 | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 286 | return 0; |
| 287 | } |
| 288 | |
Valentin Longchamp | 96957ef | 2012-06-13 03:01:03 +0000 | [diff] [blame] | 289 | int board_spi_claim_bus(struct spi_slave *slave) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 290 | { |
Valentin Longchamp | 96957ef | 2012-06-13 03:01:03 +0000 | [diff] [blame] | 291 | kw_gpio_set_value(KM_FLASH_GPIO_PIN, 0); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 292 | |
| 293 | return 0; |
| 294 | } |
| 295 | |
Valentin Longchamp | 96957ef | 2012-06-13 03:01:03 +0000 | [diff] [blame] | 296 | void board_spi_release_bus(struct spi_slave *slave) |
| 297 | { |
| 298 | kw_gpio_set_value(KM_FLASH_GPIO_PIN, 1); |
| 299 | } |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 300 | |
| 301 | int dram_init(void) |
| 302 | { |
Heiko Schocher | 0e2412a | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 303 | /* dram_init must store complete ramsize in gd->ram_size */ |
| 304 | /* Fix this */ |
Albert ARIBAUD | a960673 | 2011-07-03 05:55:33 +0000 | [diff] [blame] | 305 | gd->ram_size = get_ram_size((void *)kw_sdram_bar(0), |
Heiko Schocher | 0e2412a | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 306 | kw_sdram_bs(0)); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 307 | return 0; |
| 308 | } |
Heiko Schocher | 0e2412a | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 309 | |
| 310 | void dram_init_banksize(void) |
| 311 | { |
| 312 | int i; |
| 313 | |
| 314 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 315 | gd->bd->bi_dram[i].start = kw_sdram_bar(i); |
Heiko Schocher | 0e2412a | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 316 | gd->bd->bi_dram[i].size = get_ram_size((long *)kw_sdram_bar(i), |
| 317 | kw_sdram_bs(i)); |
| 318 | } |
| 319 | } |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 320 | |
Valentin Longchamp | 2ec63ad | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 321 | #if (defined(CONFIG_MGCOGE3UN)|defined(CONFIG_PORTL2)) |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 322 | |
| 323 | #define PHY_LED_SEL 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 0x1c |
| 328 | #define PHY_RGMII_CLK_STABLE (0x1<<10) |
| 329 | #define PHY_CLSA (0x1<<1) |
| 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 */ |
| 341 | if (miiphy_read(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL, ®) != 0) |
| 342 | printf("Error reading PHY spec ctrl reg\n"); |
| 343 | if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL, |
| 344 | reg | PHY_RGMII_CLK_STABLE | PHY_CLSA) != 0) |
| 345 | printf("Error writing PHY spec ctrl reg\n"); |
| 346 | |
| 347 | /* leds setup */ |
| 348 | if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_LED_SEL, |
| 349 | PHY_LED0_LINK | PHY_LED1_ACT | PHY_LED2_INT) != 0) |
| 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 | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 355 | #else |
| 356 | /* Configure and enable MV88E1118 PHY on the piggy*/ |
| 357 | void reset_phy(void) |
| 358 | { |
| 359 | char *name = "egiga0"; |
| 360 | |
| 361 | if (miiphy_set_current_dev(name)) |
| 362 | return; |
| 363 | |
| 364 | /* reset the phy */ |
| 365 | miiphy_reset(name, CONFIG_PHY_BASE_ADR); |
| 366 | } |
| 367 | #endif |
| 368 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 369 | |
| 370 | #if defined(CONFIG_HUSH_INIT_VAR) |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 371 | int hush_init_var(void) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 372 | { |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 373 | ivm_read_eeprom(); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 374 | return 0; |
| 375 | } |
| 376 | #endif |
| 377 | |
| 378 | #if defined(CONFIG_BOOTCOUNT_LIMIT) |
Holger Brunck | 90204f2 | 2011-09-13 22:41:02 +0000 | [diff] [blame] | 379 | const ulong patterns[] = { 0x00000000, |
| 380 | 0xFFFFFFFF, |
| 381 | 0xFF00FF00, |
| 382 | 0x0F0F0F0F, |
| 383 | 0xF0F0F0F0}; |
Holger Brunck | 50913d6 | 2012-05-25 01:57:16 +0000 | [diff] [blame] | 384 | const ulong NBR_OF_PATTERNS = ARRAY_SIZE(patterns); |
Holger Brunck | 90204f2 | 2011-09-13 22:41:02 +0000 | [diff] [blame] | 385 | const ulong OFFS_PATTERN = 3; |
| 386 | const ulong REPEAT_PATTERN = 1000; |
| 387 | |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 388 | void bootcount_store(ulong a) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 389 | { |
Holger Brunck | 763c2dc | 2011-12-14 05:31:20 +0000 | [diff] [blame] | 390 | ulong *save_addr; |
| 391 | ulong size = 0; |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 392 | int i; |
Holger Brunck | 763c2dc | 2011-12-14 05:31:20 +0000 | [diff] [blame] | 393 | |
| 394 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 395 | size += gd->bd->bi_dram[i].size; |
Holger Brunck | 763c2dc | 2011-12-14 05:31:20 +0000 | [diff] [blame] | 396 | save_addr = (ulong *)(size - BOOTCOUNT_ADDR); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 397 | writel(a, save_addr); |
| 398 | writel(BOOTCOUNT_MAGIC, &save_addr[1]); |
Holger Brunck | 90204f2 | 2011-09-13 22:41:02 +0000 | [diff] [blame] | 399 | |
| 400 | for (i = 0; i < REPEAT_PATTERN; i++) |
| 401 | writel(patterns[i % NBR_OF_PATTERNS], |
| 402 | &save_addr[i+OFFS_PATTERN]); |
| 403 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 404 | } |
| 405 | |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 406 | ulong bootcount_load(void) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 407 | { |
Holger Brunck | 763c2dc | 2011-12-14 05:31:20 +0000 | [diff] [blame] | 408 | ulong *save_addr; |
| 409 | ulong size = 0; |
Holger Brunck | 90204f2 | 2011-09-13 22:41:02 +0000 | [diff] [blame] | 410 | ulong counter = 0; |
| 411 | int i, tmp; |
| 412 | |
Holger Brunck | 763c2dc | 2011-12-14 05:31:20 +0000 | [diff] [blame] | 413 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 414 | size += gd->bd->bi_dram[i].size; |
Holger Brunck | 763c2dc | 2011-12-14 05:31:20 +0000 | [diff] [blame] | 415 | save_addr = (ulong *)(size - BOOTCOUNT_ADDR); |
Holger Brunck | 90204f2 | 2011-09-13 22:41:02 +0000 | [diff] [blame] | 416 | |
| 417 | counter = readl(&save_addr[0]); |
| 418 | |
| 419 | /* Is the counter reliable, check in the big pattern for bit errors */ |
| 420 | for (i = 0; (i < REPEAT_PATTERN) && (counter != 0); i++) { |
| 421 | tmp = readl(&save_addr[i+OFFS_PATTERN]); |
| 422 | if (tmp != patterns[i % NBR_OF_PATTERNS]) |
| 423 | counter = 0; |
| 424 | } |
| 425 | return counter; |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 426 | } |
| 427 | #endif |
| 428 | |
| 429 | #if defined(CONFIG_SOFT_I2C) |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 430 | void set_sda(int state) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 431 | { |
| 432 | I2C_ACTIVE; |
| 433 | I2C_SDA(state); |
| 434 | } |
| 435 | |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 436 | void set_scl(int state) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 437 | { |
| 438 | I2C_SCL(state); |
| 439 | } |
| 440 | |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 441 | int get_sda(void) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 442 | { |
| 443 | I2C_TRISTATE; |
| 444 | return I2C_READ; |
| 445 | } |
| 446 | |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 447 | int get_scl(void) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 448 | { |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 449 | return kw_gpio_get_value(KM_KIRKWOOD_SCL_PIN) ? 1 : 0; |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 450 | } |
| 451 | #endif |
| 452 | |
Valentin Longchamp | 24ec993 | 2011-09-12 04:18:42 +0000 | [diff] [blame] | 453 | #if defined(CONFIG_POST) |
| 454 | |
| 455 | #define KM_POST_EN_L 44 |
| 456 | #define POST_WORD_OFF 8 |
| 457 | |
| 458 | int post_hotkeys_pressed(void) |
| 459 | { |
| 460 | return !kw_gpio_get_value(KM_POST_EN_L); |
| 461 | } |
| 462 | |
| 463 | ulong post_word_load(void) |
| 464 | { |
Holger Brunck | 763c2dc | 2011-12-14 05:31:20 +0000 | [diff] [blame] | 465 | void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF); |
Valentin Longchamp | 24ec993 | 2011-09-12 04:18:42 +0000 | [diff] [blame] | 466 | return in_le32(addr); |
| 467 | |
| 468 | } |
| 469 | void post_word_store(ulong value) |
| 470 | { |
Holger Brunck | 763c2dc | 2011-12-14 05:31:20 +0000 | [diff] [blame] | 471 | void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF); |
Valentin Longchamp | 24ec993 | 2011-09-12 04:18:42 +0000 | [diff] [blame] | 472 | out_le32(addr, value); |
| 473 | } |
| 474 | |
| 475 | int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset) |
| 476 | { |
| 477 | *vstart = CONFIG_SYS_SDRAM_BASE; |
| 478 | |
| 479 | /* we go up to relocation plus a 1 MB margin */ |
| 480 | *size = CONFIG_SYS_TEXT_BASE - (1<<20); |
| 481 | |
| 482 | return 0; |
| 483 | } |
| 484 | #endif |
| 485 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 486 | #if defined(CONFIG_SYS_EEPROM_WREN) |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 487 | int eeprom_write_enable(unsigned dev_addr, int state) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 488 | { |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 489 | kw_gpio_set_value(KM_KIRKWOOD_ENV_WP, !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 | return !kw_gpio_get_value(KM_KIRKWOOD_ENV_WP); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 492 | } |
| 493 | #endif |