blob: 6ef5e5da12c42f1f3b174219664c75dadcf6e930 [file] [log] [blame]
Heiko Schocher60301192010-02-22 16:43:02 +05301/*
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>
36#include <asm/io.h>
Lei Wen298ae912011-10-18 20:11:42 +053037#include <asm/arch/cpu.h>
Heiko Schocher60301192010-02-22 16:43:02 +053038#include <asm/arch/kirkwood.h>
39#include <asm/arch/mpp.h>
40
41#include "../common/common.h"
42
43DECLARE_GLOBAL_DATA_PTR;
44
Holger Brunck4de3cdd2011-05-31 02:12:52 +000045/*
46 * BOCO FPGA definitions
47 */
48#define BOCO 0x10
49#define REG_CTRL_H 0x02
50#define MASK_WRL_UNITRUN 0x01
51#define MASK_RBX_PGY_PRESENT 0x40
52#define REG_IRQ_CIRQ2 0x2d
53#define MASK_RBI_DEFECT_16 0x01
54
Heiko Schocher60301192010-02-22 16:43:02 +053055/* Multi-Purpose Pins Functionality configuration */
56u32 kwmpp_config[] = {
57 MPP0_NF_IO2,
58 MPP1_NF_IO3,
59 MPP2_NF_IO4,
60 MPP3_NF_IO5,
61 MPP4_NF_IO6,
62 MPP5_NF_IO7,
63 MPP6_SYSRST_OUTn,
64 MPP7_PEX_RST_OUTn,
65#if defined(CONFIG_SOFT_I2C)
66 MPP8_GPIO, /* SDA */
67 MPP9_GPIO, /* SCL */
68#endif
69#if defined(CONFIG_HARD_I2C)
70 MPP8_TW_SDA,
71 MPP9_TW_SCK,
72#endif
73 MPP10_UART0_TXD,
74 MPP11_UART0_RXD,
75 MPP12_GPO, /* Reserved */
76 MPP13_UART1_TXD,
77 MPP14_UART1_RXD,
78 MPP15_GPIO, /* Not used */
79 MPP16_GPIO, /* Not used */
80 MPP17_GPIO, /* Reserved */
81 MPP18_NF_IO0,
82 MPP19_NF_IO1,
83 MPP20_GPIO,
84 MPP21_GPIO,
85 MPP22_GPIO,
86 MPP23_GPIO,
87 MPP24_GPIO,
88 MPP25_GPIO,
89 MPP26_GPIO,
90 MPP27_GPIO,
91 MPP28_GPIO,
92 MPP29_GPIO,
93 MPP30_GPIO,
94 MPP31_GPIO,
95 MPP32_GPIO,
96 MPP33_GPIO,
97 MPP34_GPIO, /* CDL1 (input) */
98 MPP35_GPIO, /* CDL2 (input) */
99 MPP36_GPIO, /* MAIN_IRQ (input) */
100 MPP37_GPIO, /* BOARD_LED */
101 MPP38_GPIO, /* Piggy3 LED[1] */
102 MPP39_GPIO, /* Piggy3 LED[2] */
103 MPP40_GPIO, /* Piggy3 LED[3] */
104 MPP41_GPIO, /* Piggy3 LED[4] */
105 MPP42_GPIO, /* Piggy3 LED[5] */
106 MPP43_GPIO, /* Piggy3 LED[6] */
Heiko Schocher9878f992011-02-22 09:13:00 +0100107 MPP44_GPIO, /* Piggy3 LED[7], BIST_EN_L */
Heiko Schocher60301192010-02-22 16:43:02 +0530108 MPP45_GPIO, /* Piggy3 LED[8] */
109 MPP46_GPIO, /* Reserved */
110 MPP47_GPIO, /* Reserved */
111 MPP48_GPIO, /* Reserved */
112 MPP49_GPIO, /* SW_INTOUTn */
113 0
114};
115
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000116#if defined(CONFIG_MGCOGE3UN)
117/*
118 * Wait for startup OK from mgcoge3ne
119 */
120int startup_allowed(void)
121{
122 unsigned char buf;
123
124 /*
125 * Read CIRQ16 bit (bit 0)
126 */
127 if (i2c_read(BOCO, REG_IRQ_CIRQ2, 1, &buf, 1) != 0)
128 printf("%s: Error reading Boco\n", __func__);
129 else
130 if ((buf & MASK_RBI_DEFECT_16) == MASK_RBI_DEFECT_16)
131 return 1;
132 return 0;
133}
Valentin Longchamp2ec63ad2011-06-16 18:11:15 +0530134#endif
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000135
Valentin Longchamp2ec63ad2011-06-16 18:11:15 +0530136#if (defined(CONFIG_MGCOGE3UN)|defined(CONFIG_PORTL2))
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000137/*
Valentin Longchamp2ec63ad2011-06-16 18:11:15 +0530138 * These two boards have always ethernet present. Its connected to the mv
139 * switch.
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000140 */
141int ethernet_present(void)
142{
143 return 1;
144}
145#else
Heiko Schocher60301192010-02-22 16:43:02 +0530146int ethernet_present(void)
147{
148 uchar buf;
149 int ret = 0;
150
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000151 if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100152 printf("%s: Error reading Boco\n", __func__);
Heiko Schocher60301192010-02-22 16:43:02 +0530153 return -1;
154 }
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000155 if ((buf & MASK_RBX_PGY_PRESENT) == MASK_RBX_PGY_PRESENT)
Heiko Schocher60301192010-02-22 16:43:02 +0530156 ret = 1;
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100157
Heiko Schocher60301192010-02-22 16:43:02 +0530158 return ret;
159}
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000160#endif
Heiko Schocher60301192010-02-22 16:43:02 +0530161
Heiko Schochere4533af2011-03-08 10:53:51 +0100162int initialize_unit_leds(void)
163{
164 /*
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000165 * Init the unit LEDs per default they all are
Heiko Schochere4533af2011-03-08 10:53:51 +0100166 * ok apart from bootstat
Heiko Schochere4533af2011-03-08 10:53:51 +0100167 */
Heiko Schochere4533af2011-03-08 10:53:51 +0100168 uchar buf;
169
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000170 if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
Heiko Schochere4533af2011-03-08 10:53:51 +0100171 printf("%s: Error reading Boco\n", __func__);
172 return -1;
173 }
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000174 buf |= MASK_WRL_UNITRUN;
175 if (i2c_write(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
Heiko Schochere4533af2011-03-08 10:53:51 +0100176 printf("%s: Error writing Boco\n", __func__);
177 return -1;
178 }
179 return 0;
180}
181
Valentin Longchamp184907a2011-05-31 02:12:47 +0000182#if defined(CONFIG_BOOTCOUNT_LIMIT)
183void set_bootcount_addr(void)
184{
185 uchar buf[32];
186 unsigned int bootcountaddr;
187 bootcountaddr = gd->ram_size - BOOTCOUNT_ADDR;
188 sprintf((char *)buf, "0x%x", bootcountaddr);
189 setenv("bootcountaddr", (char *)buf);
190}
191#endif
192
Heiko Schocher60301192010-02-22 16:43:02 +0530193int misc_init_r(void)
194{
Heiko Schocher60301192010-02-22 16:43:02 +0530195 char *str;
196 int mach_type;
197
Heiko Schocher60301192010-02-22 16:43:02 +0530198 str = getenv("mach_type");
199 if (str != NULL) {
200 mach_type = simple_strtoul(str, NULL, 10);
201 printf("Overwriting MACH_TYPE with %d!!!\n", mach_type);
202 gd->bd->bi_arch_number = mach_type;
203 }
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000204#if defined(CONFIG_MGCOGE3UN)
205 char *wait_for_ne;
206 wait_for_ne = getenv("waitforne");
207 if (wait_for_ne != NULL) {
208 if (strcmp(wait_for_ne, "true") == 0) {
209 int cnt = 0;
210 puts("NE go: ");
211 while (startup_allowed() == 0) {
212 udelay(200000);
213 cnt++;
214 if (cnt == 5)
215 puts("wait\b\b\b\b");
216 if (cnt == 10) {
217 cnt = 0;
218 puts(" \b\b\b\b");
219 }
220 }
221 puts("OK\n");
222 }
223 }
224#endif
Heiko Schochere4533af2011-03-08 10:53:51 +0100225
226 initialize_unit_leds();
Valentin Longchamp184907a2011-05-31 02:12:47 +0000227 set_km_env();
228#if defined(CONFIG_BOOTCOUNT_LIMIT)
229 set_bootcount_addr();
230#endif
Heiko Schocher60301192010-02-22 16:43:02 +0530231 return 0;
232}
233
Heiko Schocher3ebd02b2010-10-20 19:33:26 +0530234int board_early_init_f(void)
Heiko Schocher60301192010-02-22 16:43:02 +0530235{
236 u32 tmp;
237
238 kirkwood_mpp_conf(kwmpp_config);
239
240 /*
241 * The FLASH_GPIO_PIN switches between using a
242 * NAND or a SPI FLASH. Set this pin on start
243 * to NAND mode.
244 */
245 tmp = readl(KW_GPIO0_BASE);
246 writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
247 tmp = readl(KW_GPIO0_BASE + 4);
248 writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE + 4);
Heiko Schocher60301192010-02-22 16:43:02 +0530249
Heiko Schocher60301192010-02-22 16:43:02 +0530250#if defined(CONFIG_SOFT_I2C)
251 /* init the GPIO for I2C Bitbang driver */
Heiko Schocher9878f992011-02-22 09:13:00 +0100252 kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
253 kw_gpio_set_valid(KM_KIRKWOOD_SCL_PIN, 1);
254 kw_gpio_direction_output(KM_KIRKWOOD_SDA_PIN, 0);
255 kw_gpio_direction_output(KM_KIRKWOOD_SCL_PIN, 0);
Heiko Schocher60301192010-02-22 16:43:02 +0530256#endif
257#if defined(CONFIG_SYS_EEPROM_WREN)
Heiko Schocher9878f992011-02-22 09:13:00 +0100258 kw_gpio_set_valid(KM_KIRKWOOD_ENV_WP, 38);
259 kw_gpio_direction_output(KM_KIRKWOOD_ENV_WP, 1);
Heiko Schocher60301192010-02-22 16:43:02 +0530260#endif
Heiko Schocher3ebd02b2010-10-20 19:33:26 +0530261
262 return 0;
263}
264
265int board_init(void)
266{
267 /*
268 * arch number of board
269 */
Holger Brunck34108f12011-03-14 15:31:19 +0100270 gd->bd->bi_arch_number = MACH_TYPE_KM_KIRKWOOD;
Heiko Schocher3ebd02b2010-10-20 19:33:26 +0530271
272 /* address of boot parameters */
273 gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
274
Heiko Schochercfc58042010-04-26 13:07:28 +0200275 return 0;
276}
277
Heiko Schocher60301192010-02-22 16:43:02 +0530278#if defined(CONFIG_CMD_SF)
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200279int do_spi_toggle(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Heiko Schocher60301192010-02-22 16:43:02 +0530280{
281 u32 tmp;
Wolfgang Denk3b683112010-07-17 01:06:04 +0200282 if (argc < 2)
283 return cmd_usage(cmdtp);
Heiko Schocher60301192010-02-22 16:43:02 +0530284
285 if ((strcmp(argv[1], "off") == 0)) {
286 printf("SPI FLASH disabled, NAND enabled\n");
287 /* Multi-Purpose Pins Functionality configuration */
288 kwmpp_config[0] = MPP0_NF_IO2;
289 kwmpp_config[1] = MPP1_NF_IO3;
290 kwmpp_config[2] = MPP2_NF_IO4;
291 kwmpp_config[3] = MPP3_NF_IO5;
292
293 kirkwood_mpp_conf(kwmpp_config);
294 tmp = readl(KW_GPIO0_BASE);
295 writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
296 } else if ((strcmp(argv[1], "on") == 0)) {
297 printf("SPI FLASH enabled, NAND disabled\n");
298 /* Multi-Purpose Pins Functionality configuration */
299 kwmpp_config[0] = MPP0_SPI_SCn;
300 kwmpp_config[1] = MPP1_SPI_MOSI;
301 kwmpp_config[2] = MPP2_SPI_SCK;
302 kwmpp_config[3] = MPP3_SPI_MISO;
303
304 kirkwood_mpp_conf(kwmpp_config);
305 tmp = readl(KW_GPIO0_BASE);
306 writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE);
307 } else {
Wolfgang Denk3b683112010-07-17 01:06:04 +0200308 return cmd_usage(cmdtp);
Heiko Schocher60301192010-02-22 16:43:02 +0530309 }
310
311 return 0;
312}
313
314U_BOOT_CMD(
315 spitoggle, 2, 0, do_spi_toggle,
316 "En-/disable SPI FLASH access",
317 "<on|off> - Enable (on) or disable (off) SPI FLASH access\n"
318 );
319#endif
320
321int dram_init(void)
322{
Heiko Schocher0e2412a2010-09-17 13:10:42 +0200323 /* dram_init must store complete ramsize in gd->ram_size */
324 /* Fix this */
Albert ARIBAUDa9606732011-07-03 05:55:33 +0000325 gd->ram_size = get_ram_size((void *)kw_sdram_bar(0),
Heiko Schocher0e2412a2010-09-17 13:10:42 +0200326 kw_sdram_bs(0));
Heiko Schocher60301192010-02-22 16:43:02 +0530327 return 0;
328}
Heiko Schocher0e2412a2010-09-17 13:10:42 +0200329
330void dram_init_banksize(void)
331{
332 int i;
333
334 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
335 gd->bd->bi_dram[i].start = kw_sdram_bar(i);
Heiko Schocher0e2412a2010-09-17 13:10:42 +0200336 gd->bd->bi_dram[i].size = get_ram_size((long *)kw_sdram_bar(i),
337 kw_sdram_bs(i));
338 }
339}
Heiko Schocher60301192010-02-22 16:43:02 +0530340
Valentin Longchamp2ec63ad2011-06-16 18:11:15 +0530341#if (defined(CONFIG_MGCOGE3UN)|defined(CONFIG_PORTL2))
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530342
343#define PHY_LED_SEL 0x18
344#define PHY_LED0_LINK (0x5)
345#define PHY_LED1_ACT (0x8<<4)
346#define PHY_LED2_INT (0xe<<8)
347#define PHY_SPEC_CTRL 0x1c
348#define PHY_RGMII_CLK_STABLE (0x1<<10)
349#define PHY_CLSA (0x1<<1)
350
351/* Configure and enable MV88E3018 PHY */
Heiko Schocher60301192010-02-22 16:43:02 +0530352void reset_phy(void)
353{
354 char *name = "egiga0";
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530355 unsigned short reg;
Heiko Schocher60301192010-02-22 16:43:02 +0530356
357 if (miiphy_set_current_dev(name))
358 return;
359
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530360 /* RGMII clk transition on data stable */
361 if (miiphy_read(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL, &reg) != 0)
362 printf("Error reading PHY spec ctrl reg\n");
363 if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL,
364 reg | PHY_RGMII_CLK_STABLE | PHY_CLSA) != 0)
365 printf("Error writing PHY spec ctrl reg\n");
366
367 /* leds setup */
368 if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_LED_SEL,
369 PHY_LED0_LINK | PHY_LED1_ACT | PHY_LED2_INT) != 0)
370 printf("Error writing PHY LED reg\n");
371
Heiko Schocher60301192010-02-22 16:43:02 +0530372 /* reset the phy */
373 miiphy_reset(name, CONFIG_PHY_BASE_ADR);
374}
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530375#else
376/* Configure and enable MV88E1118 PHY on the piggy*/
377void reset_phy(void)
378{
379 char *name = "egiga0";
380
381 if (miiphy_set_current_dev(name))
382 return;
383
384 /* reset the phy */
385 miiphy_reset(name, CONFIG_PHY_BASE_ADR);
386}
387#endif
388
Heiko Schocher60301192010-02-22 16:43:02 +0530389
390#if defined(CONFIG_HUSH_INIT_VAR)
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100391int hush_init_var(void)
Heiko Schocher60301192010-02-22 16:43:02 +0530392{
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100393 ivm_read_eeprom();
Heiko Schocher60301192010-02-22 16:43:02 +0530394 return 0;
395}
396#endif
397
398#if defined(CONFIG_BOOTCOUNT_LIMIT)
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100399void bootcount_store(ulong a)
Heiko Schocher60301192010-02-22 16:43:02 +0530400{
401 volatile ulong *save_addr;
402 volatile ulong size = 0;
403 int i;
404 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
405 size += gd->bd->bi_dram[i].size;
406 }
407 save_addr = (ulong*)(size - BOOTCOUNT_ADDR);
408 writel(a, save_addr);
409 writel(BOOTCOUNT_MAGIC, &save_addr[1]);
410}
411
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100412ulong bootcount_load(void)
Heiko Schocher60301192010-02-22 16:43:02 +0530413{
414 volatile ulong *save_addr;
415 volatile ulong size = 0;
416 int i;
417 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
418 size += gd->bd->bi_dram[i].size;
419 }
420 save_addr = (ulong*)(size - BOOTCOUNT_ADDR);
421 if (readl(&save_addr[1]) != BOOTCOUNT_MAGIC)
422 return 0;
423 else
424 return readl(save_addr);
425}
426#endif
427
428#if defined(CONFIG_SOFT_I2C)
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100429void set_sda(int state)
Heiko Schocher60301192010-02-22 16:43:02 +0530430{
431 I2C_ACTIVE;
432 I2C_SDA(state);
433}
434
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100435void set_scl(int state)
Heiko Schocher60301192010-02-22 16:43:02 +0530436{
437 I2C_SCL(state);
438}
439
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100440int get_sda(void)
Heiko Schocher60301192010-02-22 16:43:02 +0530441{
442 I2C_TRISTATE;
443 return I2C_READ;
444}
445
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100446int get_scl(void)
Heiko Schocher60301192010-02-22 16:43:02 +0530447{
Heiko Schocher9878f992011-02-22 09:13:00 +0100448 return kw_gpio_get_value(KM_KIRKWOOD_SCL_PIN) ? 1 : 0;
Heiko Schocher60301192010-02-22 16:43:02 +0530449}
450#endif
451
Valentin Longchamp24ec9932011-09-12 04:18:42 +0000452#if defined(CONFIG_POST)
453
454#define KM_POST_EN_L 44
455#define POST_WORD_OFF 8
456
457int post_hotkeys_pressed(void)
458{
459 return !kw_gpio_get_value(KM_POST_EN_L);
460}
461
462ulong post_word_load(void)
463{
464 volatile void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
465 return in_le32(addr);
466
467}
468void post_word_store(ulong value)
469{
470 volatile void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
471 out_le32(addr, value);
472}
473
474int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
475{
476 *vstart = CONFIG_SYS_SDRAM_BASE;
477
478 /* we go up to relocation plus a 1 MB margin */
479 *size = CONFIG_SYS_TEXT_BASE - (1<<20);
480
481 return 0;
482}
483#endif
484
Heiko Schocher60301192010-02-22 16:43:02 +0530485#if defined(CONFIG_SYS_EEPROM_WREN)
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100486int eeprom_write_enable(unsigned dev_addr, int state)
Heiko Schocher60301192010-02-22 16:43:02 +0530487{
Heiko Schocher9878f992011-02-22 09:13:00 +0100488 kw_gpio_set_value(KM_KIRKWOOD_ENV_WP, !state);
Heiko Schocher60301192010-02-22 16:43:02 +0530489
Heiko Schocher9878f992011-02-22 09:13:00 +0100490 return !kw_gpio_get_value(KM_KIRKWOOD_ENV_WP);
Heiko Schocher60301192010-02-22 16:43:02 +0530491}
492#endif