blob: 079509c979d01e3e2996cd2c90336c8e180785dd [file] [log] [blame]
Heiko Schocher67fa8c22010-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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020012 * SPDX-License-Identifier: GPL-2.0+
Heiko Schocher67fa8c22010-02-22 16:43:02 +053013 */
14
15#include <common.h>
16#include <i2c.h>
17#include <nand.h>
18#include <netdev.h>
19#include <miiphy.h>
Valentin Longchamp0c25def2012-06-13 03:01:03 +000020#include <spi.h>
Heiko Schocher67fa8c22010-02-22 16:43:02 +053021#include <asm/io.h>
Lei Wena7efd712011-10-18 20:11:42 +053022#include <asm/arch/cpu.h>
Stefan Roese3dc23f72014-10-22 12:13:06 +020023#include <asm/arch/soc.h>
Heiko Schocher67fa8c22010-02-22 16:43:02 +053024#include <asm/arch/mpp.h>
25
26#include "../common/common.h"
27
28DECLARE_GLOBAL_DATA_PTR;
29
Holger Brunck8612b702011-05-31 02:12:52 +000030/*
31 * BOCO FPGA definitions
32 */
33#define BOCO 0x10
34#define REG_CTRL_H 0x02
35#define MASK_WRL_UNITRUN 0x01
36#define MASK_RBX_PGY_PRESENT 0x40
37#define REG_IRQ_CIRQ2 0x2d
38#define MASK_RBI_DEFECT_16 0x01
39
Tobias Müller9ff739e2015-11-13 15:01:15 +010040/*
41 * PHY registers definitions
42 */
43#define PHY_MARVELL_OUI 0x5043
44#define PHY_MARVELL_88E1118_MODEL 0x0022
45#define PHY_MARVELL_88E1118R_MODEL 0x0024
46
47#define PHY_MARVELL_PAGE_REG 0x0016
48#define PHY_MARVELL_DEFAULT_PAGE 0x0000
49
50#define PHY_MARVELL_88E1118R_LED_CTRL_PAGE 0x0003
51#define PHY_MARVELL_88E1118R_LED_CTRL_REG 0x0010
52
53#define PHY_MARVELL_88E1118R_LED_CTRL_RESERVED 0x1000
54#define PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB (0x7<<0)
55#define PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT (0x3<<4)
56#define PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK (0x0<<8)
57
Holger Bruncke23fde72015-11-13 15:01:16 +010058/* I/O pin to erase flash RGPP09 = MPP43 */
59#define KM_FLASH_ERASE_ENABLE 43
60
Heiko Schocher67fa8c22010-02-22 16:43:02 +053061/* Multi-Purpose Pins Functionality configuration */
Albert ARIBAUD9d86f0c2012-11-26 11:27:36 +000062static const u32 kwmpp_config[] = {
Heiko Schocher67fa8c22010-02-22 16:43:02 +053063 MPP0_NF_IO2,
64 MPP1_NF_IO3,
65 MPP2_NF_IO4,
66 MPP3_NF_IO5,
67 MPP4_NF_IO6,
68 MPP5_NF_IO7,
69 MPP6_SYSRST_OUTn,
Gerlando Falauto9c134e12014-02-13 16:43:00 +010070#if defined(KM_PCIE_RESET_MPP7)
71 MPP7_GPO,
72#else
Heiko Schocher67fa8c22010-02-22 16:43:02 +053073 MPP7_PEX_RST_OUTn,
Gerlando Falauto9c134e12014-02-13 16:43:00 +010074#endif
Heiko Schocherea818db2013-01-29 08:53:15 +010075#if defined(CONFIG_SYS_I2C_SOFT)
Heiko Schocher67fa8c22010-02-22 16:43:02 +053076 MPP8_GPIO, /* SDA */
77 MPP9_GPIO, /* SCL */
78#endif
79#if defined(CONFIG_HARD_I2C)
80 MPP8_TW_SDA,
81 MPP9_TW_SCK,
82#endif
83 MPP10_UART0_TXD,
84 MPP11_UART0_RXD,
85 MPP12_GPO, /* Reserved */
86 MPP13_UART1_TXD,
87 MPP14_UART1_RXD,
88 MPP15_GPIO, /* Not used */
89 MPP16_GPIO, /* Not used */
90 MPP17_GPIO, /* Reserved */
91 MPP18_NF_IO0,
92 MPP19_NF_IO1,
93 MPP20_GPIO,
94 MPP21_GPIO,
95 MPP22_GPIO,
96 MPP23_GPIO,
97 MPP24_GPIO,
98 MPP25_GPIO,
99 MPP26_GPIO,
100 MPP27_GPIO,
101 MPP28_GPIO,
102 MPP29_GPIO,
103 MPP30_GPIO,
104 MPP31_GPIO,
105 MPP32_GPIO,
106 MPP33_GPIO,
107 MPP34_GPIO, /* CDL1 (input) */
108 MPP35_GPIO, /* CDL2 (input) */
109 MPP36_GPIO, /* MAIN_IRQ (input) */
110 MPP37_GPIO, /* BOARD_LED */
111 MPP38_GPIO, /* Piggy3 LED[1] */
112 MPP39_GPIO, /* Piggy3 LED[2] */
113 MPP40_GPIO, /* Piggy3 LED[3] */
114 MPP41_GPIO, /* Piggy3 LED[4] */
115 MPP42_GPIO, /* Piggy3 LED[5] */
116 MPP43_GPIO, /* Piggy3 LED[6] */
Heiko Schocher44097e22011-02-22 09:13:00 +0100117 MPP44_GPIO, /* Piggy3 LED[7], BIST_EN_L */
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530118 MPP45_GPIO, /* Piggy3 LED[8] */
119 MPP46_GPIO, /* Reserved */
120 MPP47_GPIO, /* Reserved */
121 MPP48_GPIO, /* Reserved */
122 MPP49_GPIO, /* SW_INTOUTn */
123 0
124};
125
Valentin Longchamp0bb95a62015-02-10 17:10:14 +0100126static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
127
Holger Brunckf9454392012-07-05 05:05:03 +0000128#if defined(CONFIG_KM_MGCOGE3UN)
Holger Brunck8612b702011-05-31 02:12:52 +0000129/*
130 * Wait for startup OK from mgcoge3ne
131 */
Holger Brunckaef0bdc2014-01-27 16:58:23 +0100132static int startup_allowed(void)
Holger Brunck8612b702011-05-31 02:12:52 +0000133{
134 unsigned char buf;
135
136 /*
137 * Read CIRQ16 bit (bit 0)
138 */
139 if (i2c_read(BOCO, REG_IRQ_CIRQ2, 1, &buf, 1) != 0)
140 printf("%s: Error reading Boco\n", __func__);
141 else
142 if ((buf & MASK_RBI_DEFECT_16) == MASK_RBI_DEFECT_16)
143 return 1;
144 return 0;
145}
Valentin Longchamp01fa4e82011-06-16 18:11:15 +0530146#endif
Holger Brunck8612b702011-05-31 02:12:52 +0000147
Holger Brunckf9454392012-07-05 05:05:03 +0000148#if (defined(CONFIG_KM_PIGGY4_88E6061)|defined(CONFIG_KM_PIGGY4_88E6352))
Holger Brunck8612b702011-05-31 02:12:52 +0000149/*
Holger Brunck8170aef2012-07-05 05:37:46 +0000150 * All boards with PIGGY4 connected via a simple switch have ethernet always
151 * present.
Holger Brunck8612b702011-05-31 02:12:52 +0000152 */
153int ethernet_present(void)
154{
155 return 1;
156}
157#else
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530158int ethernet_present(void)
159{
160 uchar buf;
161 int ret = 0;
162
Holger Brunck8612b702011-05-31 02:12:52 +0000163 if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100164 printf("%s: Error reading Boco\n", __func__);
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530165 return -1;
166 }
Holger Brunck8612b702011-05-31 02:12:52 +0000167 if ((buf & MASK_RBX_PGY_PRESENT) == MASK_RBX_PGY_PRESENT)
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530168 ret = 1;
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100169
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530170 return ret;
171}
Holger Brunck8612b702011-05-31 02:12:52 +0000172#endif
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530173
Holger Brunck74ae6122013-05-06 15:04:51 +0200174static int initialize_unit_leds(void)
Heiko Schocher731b9682011-03-08 10:53:51 +0100175{
176 /*
Holger Brunck8612b702011-05-31 02:12:52 +0000177 * Init the unit LEDs per default they all are
Heiko Schocher731b9682011-03-08 10:53:51 +0100178 * ok apart from bootstat
Heiko Schocher731b9682011-03-08 10:53:51 +0100179 */
Heiko Schocher731b9682011-03-08 10:53:51 +0100180 uchar buf;
181
Holger Brunck8612b702011-05-31 02:12:52 +0000182 if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
Heiko Schocher731b9682011-03-08 10:53:51 +0100183 printf("%s: Error reading Boco\n", __func__);
184 return -1;
185 }
Holger Brunck8612b702011-05-31 02:12:52 +0000186 buf |= MASK_WRL_UNITRUN;
187 if (i2c_write(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
Heiko Schocher731b9682011-03-08 10:53:51 +0100188 printf("%s: Error writing Boco\n", __func__);
189 return -1;
190 }
191 return 0;
192}
193
Holger Brunck74ae6122013-05-06 15:04:51 +0200194static void set_bootcount_addr(void)
Valentin Longchamp22c67d02011-05-31 02:12:47 +0000195{
196 uchar buf[32];
197 unsigned int bootcountaddr;
198 bootcountaddr = gd->ram_size - BOOTCOUNT_ADDR;
199 sprintf((char *)buf, "0x%x", bootcountaddr);
200 setenv("bootcountaddr", (char *)buf);
201}
Valentin Longchamp22c67d02011-05-31 02:12:47 +0000202
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530203int misc_init_r(void)
204{
Holger Brunckf9454392012-07-05 05:05:03 +0000205#if defined(CONFIG_KM_MGCOGE3UN)
Holger Brunck8612b702011-05-31 02:12:52 +0000206 char *wait_for_ne;
Holger Bruncke23fde72015-11-13 15:01:16 +0100207 u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE);
Holger Brunck8612b702011-05-31 02:12:52 +0000208 wait_for_ne = getenv("waitforne");
Holger Bruncke23fde72015-11-13 15:01:16 +0100209
210 if ((wait_for_ne != NULL) && (dip_switch == 0)) {
Holger Brunck8612b702011-05-31 02:12:52 +0000211 if (strcmp(wait_for_ne, "true") == 0) {
212 int cnt = 0;
Holger Brunck62648002011-09-27 02:54:31 +0000213 int abort = 0;
Holger Brunck8612b702011-05-31 02:12:52 +0000214 puts("NE go: ");
215 while (startup_allowed() == 0) {
Holger Brunck62648002011-09-27 02:54:31 +0000216 if (tstc()) {
217 (void) getc(); /* consume input */
218 abort = 1;
219 break;
220 }
Holger Brunck8612b702011-05-31 02:12:52 +0000221 udelay(200000);
222 cnt++;
223 if (cnt == 5)
224 puts("wait\b\b\b\b");
225 if (cnt == 10) {
226 cnt = 0;
227 puts(" \b\b\b\b");
228 }
229 }
Holger Brunck62648002011-09-27 02:54:31 +0000230 if (abort == 1)
231 printf("\nAbort waiting for ne\n");
232 else
233 puts("OK\n");
Holger Brunck8612b702011-05-31 02:12:52 +0000234 }
235 }
236#endif
Heiko Schocher731b9682011-03-08 10:53:51 +0100237
Valentin Longchamp60c4ae02015-02-10 17:10:18 +0100238 ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
Valentin Longchamp0bb95a62015-02-10 17:10:14 +0100239
Heiko Schocher731b9682011-03-08 10:53:51 +0100240 initialize_unit_leds();
Valentin Longchamp22c67d02011-05-31 02:12:47 +0000241 set_km_env();
Valentin Longchamp22c67d02011-05-31 02:12:47 +0000242 set_bootcount_addr();
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530243 return 0;
244}
245
Heiko Schocher6b0ccc32010-10-20 19:33:26 +0530246int board_early_init_f(void)
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530247{
Heiko Schocherea818db2013-01-29 08:53:15 +0100248#if defined(CONFIG_SYS_I2C_SOFT)
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530249 u32 tmp;
250
Holger Brunckc471d842012-07-05 05:05:11 +0000251 /* set the 2 bitbang i2c pins as output gpios */
Stefan Roesed5c51322014-10-22 12:13:11 +0200252 tmp = readl(MVEBU_GPIO0_BASE + 4);
253 writel(tmp & (~KM_KIRKWOOD_SOFT_I2C_GPIOS) , MVEBU_GPIO0_BASE + 4);
Holger Brunckc471d842012-07-05 05:05:11 +0000254#endif
Holger Brunck3a5b9fe2012-07-25 06:26:03 +0000255 /* adjust SDRAM size for bank 0 */
Stefan Roese96c5f082014-10-22 12:13:13 +0200256 mvebu_sdram_size_adjust(0);
Holger Brunckc471d842012-07-05 05:05:11 +0000257 kirkwood_mpp_conf(kwmpp_config, NULL);
Heiko Schocher6b0ccc32010-10-20 19:33:26 +0530258 return 0;
259}
260
261int board_init(void)
262{
Heiko Schocher6b0ccc32010-10-20 19:33:26 +0530263 /* address of boot parameters */
Stefan Roese96c5f082014-10-22 12:13:13 +0200264 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
Heiko Schocher6b0ccc32010-10-20 19:33:26 +0530265
Holger Brunckc471d842012-07-05 05:05:11 +0000266 /*
267 * The KM_FLASH_GPIO_PIN switches between using a
268 * NAND or a SPI FLASH. Set this pin on start
269 * to NAND mode.
270 */
271 kw_gpio_set_valid(KM_FLASH_GPIO_PIN, 1);
272 kw_gpio_direction_output(KM_FLASH_GPIO_PIN, 1);
273
Heiko Schocherea818db2013-01-29 08:53:15 +0100274#if defined(CONFIG_SYS_I2C_SOFT)
Holger Brunckc471d842012-07-05 05:05:11 +0000275 /*
276 * Reinit the GPIO for I2C Bitbang driver so that the now
277 * available gpio framework is consistent. The calls to
278 * direction output in are not necessary, they are already done in
279 * board_early_init_f
280 */
281 kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
282 kw_gpio_set_valid(KM_KIRKWOOD_SCL_PIN, 1);
283#endif
284
285#if defined(CONFIG_SYS_EEPROM_WREN)
286 kw_gpio_set_valid(KM_KIRKWOOD_ENV_WP, 38);
287 kw_gpio_direction_output(KM_KIRKWOOD_ENV_WP, 1);
288#endif
289
Valentin Longchampb37f7722012-07-05 05:05:05 +0000290#if defined(CONFIG_KM_FPGA_CONFIG)
291 trigger_fpga_config();
292#endif
293
294 return 0;
295}
296
297int board_late_init(void)
298{
Valentin Longchamp30f9ad72015-11-13 15:01:17 +0100299#if (defined(CONFIG_KM_COGE5UN) | defined(CONFIG_KM_MGCOGE3UN))
Thomas Herzmannb8cf7cc2012-07-05 05:05:10 +0000300 u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE);
301
302 /* if pin 1 do full erase */
303 if (dip_switch != 0) {
304 /* start bootloader */
305 puts("DIP: Enabled\n");
306 setenv("actual_bank", "0");
307 }
308#endif
309
Valentin Longchampb37f7722012-07-05 05:05:05 +0000310#if defined(CONFIG_KM_FPGA_CONFIG)
311 wait_for_fpga_config();
312 fpga_reset();
313 toggle_eeprom_spi_bus();
314#endif
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530315 return 0;
316}
317
Valentin Longchamp0c25def2012-06-13 03:01:03 +0000318int board_spi_claim_bus(struct spi_slave *slave)
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530319{
Valentin Longchamp0c25def2012-06-13 03:01:03 +0000320 kw_gpio_set_value(KM_FLASH_GPIO_PIN, 0);
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530321
322 return 0;
323}
324
Valentin Longchamp0c25def2012-06-13 03:01:03 +0000325void board_spi_release_bus(struct spi_slave *slave)
326{
327 kw_gpio_set_value(KM_FLASH_GPIO_PIN, 1);
328}
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530329
Holger Brunck6ef64862012-07-05 05:05:04 +0000330#if (defined(CONFIG_KM_PIGGY4_88E6061))
Valentin Longchamp8f2827f2011-06-16 18:11:15 +0530331
Valentin Longchampc1b85142012-07-05 05:05:07 +0000332#define PHY_LED_SEL_REG 0x18
333#define PHY_LED0_LINK (0x5)
334#define PHY_LED1_ACT (0x8<<4)
335#define PHY_LED2_INT (0xe<<8)
336#define PHY_SPEC_CTRL_REG 0x1c
Valentin Longchamp8f2827f2011-06-16 18:11:15 +0530337#define PHY_RGMII_CLK_STABLE (0x1<<10)
Valentin Longchampc1b85142012-07-05 05:05:07 +0000338#define PHY_CLSA (0x1<<1)
Valentin Longchamp8f2827f2011-06-16 18:11:15 +0530339
340/* Configure and enable MV88E3018 PHY */
341void reset_phy(void)
342{
343 char *name = "egiga0";
344 unsigned short reg;
345
346 if (miiphy_set_current_dev(name))
347 return;
348
349 /* RGMII clk transition on data stable */
Holger Brunckfa6e0ec2014-01-27 16:58:26 +0100350 if (miiphy_read(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG, &reg))
Valentin Longchamp8f2827f2011-06-16 18:11:15 +0530351 printf("Error reading PHY spec ctrl reg\n");
Holger Brunckfa6e0ec2014-01-27 16:58:26 +0100352 if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG,
353 reg | PHY_RGMII_CLK_STABLE | PHY_CLSA))
Valentin Longchamp8f2827f2011-06-16 18:11:15 +0530354 printf("Error writing PHY spec ctrl reg\n");
355
356 /* leds setup */
Holger Brunckfa6e0ec2014-01-27 16:58:26 +0100357 if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_LED_SEL_REG,
358 PHY_LED0_LINK | PHY_LED1_ACT | PHY_LED2_INT))
Valentin Longchamp8f2827f2011-06-16 18:11:15 +0530359 printf("Error writing PHY LED reg\n");
360
361 /* reset the phy */
362 miiphy_reset(name, CONFIG_PHY_BASE_ADR);
363}
Valentin Longchamp52638c42012-08-16 23:35:03 +0000364#elif defined(CONFIG_KM_PIGGY4_88E6352)
365
366#include <mv88e6352.h>
367
368#if defined(CONFIG_KM_NUSA)
369struct mv88e_sw_reg extsw_conf[] = {
370 /*
Wolfgang Denk3765b3e2013-10-07 13:07:26 +0200371 * port 0, PIGGY4, autoneg
Valentin Longchamp52638c42012-08-16 23:35:03 +0000372 * first the fix for the 1000Mbits Autoneg, this is from
373 * a Marvell errata, the regs are undocumented
374 */
375 { PHY(0), PHY_PAGE, AN1000FIX_PAGE },
376 { PHY(0), PHY_STATUS, AN1000FIX },
377 { PHY(0), PHY_PAGE, 0 },
378 /* now the real port and phy configuration */
379 { PORT(0), PORT_PHY, NO_SPEED_FOR },
380 { PORT(0), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
381 { PHY(0), PHY_1000_CTRL, NO_ADV },
382 { PHY(0), PHY_SPEC_CTRL, AUTO_MDIX_EN },
383 { PHY(0), PHY_CTRL, PHY_100_MBPS | AUTONEG_EN | AUTONEG_RST |
384 FULL_DUPLEX },
385 /* port 1, unused */
386 { PORT(1), PORT_CTRL, PORT_DIS },
387 { PHY(1), PHY_CTRL, PHY_PWR_DOWN },
388 { PHY(1), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
389 /* port 2, unused */
390 { PORT(2), PORT_CTRL, PORT_DIS },
391 { PHY(2), PHY_CTRL, PHY_PWR_DOWN },
392 { PHY(2), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
393 /* port 3, unused */
394 { PORT(3), PORT_CTRL, PORT_DIS },
395 { PHY(3), PHY_CTRL, PHY_PWR_DOWN },
396 { PHY(3), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
397 /* port 4, ICNEV, SerDes, SGMII */
398 { PORT(4), PORT_STATUS, NO_PHY_DETECT },
399 { PORT(4), PORT_PHY, SPEED_1000_FOR },
400 { PORT(4), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
401 { PHY(4), PHY_CTRL, PHY_PWR_DOWN },
402 { PHY(4), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
403 /* port 5, CPU_RGMII */
404 { PORT(5), PORT_PHY, RX_RGMII_TIM | TX_RGMII_TIM | FLOW_CTRL_EN |
405 FLOW_CTRL_FOR | LINK_VAL | LINK_FOR | FULL_DPX |
406 FULL_DPX_FOR | SPEED_1000_FOR },
407 { PORT(5), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
408 /* port 6, unused, this port has no phy */
409 { PORT(6), PORT_CTRL, PORT_DIS },
410};
411#else
412struct mv88e_sw_reg extsw_conf[] = {};
413#endif
414
415void reset_phy(void)
416{
417#if defined(CONFIG_KM_MVEXTSW_ADDR)
418 char *name = "egiga0";
419
420 if (miiphy_set_current_dev(name))
421 return;
422
423 mv88e_sw_program(name, CONFIG_KM_MVEXTSW_ADDR, extsw_conf,
424 ARRAY_SIZE(extsw_conf));
425 mv88e_sw_reset(name, CONFIG_KM_MVEXTSW_ADDR);
426#endif
427}
428
Valentin Longchamp8f2827f2011-06-16 18:11:15 +0530429#else
430/* Configure and enable MV88E1118 PHY on the piggy*/
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530431void reset_phy(void)
432{
Tobias Müller9ff739e2015-11-13 15:01:15 +0100433 unsigned int oui;
434 unsigned char model, rev;
435
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530436 char *name = "egiga0";
437
438 if (miiphy_set_current_dev(name))
439 return;
440
441 /* reset the phy */
442 miiphy_reset(name, CONFIG_PHY_BASE_ADR);
Tobias Müller9ff739e2015-11-13 15:01:15 +0100443
444 /* get PHY model */
445 if (miiphy_info(name, CONFIG_PHY_BASE_ADR, &oui, &model, &rev))
446 return;
447
448 /* check for Marvell 88E1118R Gigabit PHY (PIGGY3) */
449 if ((oui == PHY_MARVELL_OUI) &&
450 (model == PHY_MARVELL_88E1118R_MODEL)) {
451 /* set page register to 3 */
452 if (miiphy_write(name, CONFIG_PHY_BASE_ADR,
453 PHY_MARVELL_PAGE_REG,
454 PHY_MARVELL_88E1118R_LED_CTRL_PAGE))
455 printf("Error writing PHY page reg\n");
456
457 /*
458 * leds setup as printed on PCB:
459 * LED2 (Link): 0x0 (On Link, Off No Link)
460 * LED1 (Activity): 0x3 (On Activity, Off No Activity)
461 * LED0 (Speed): 0x7 (On 1000 MBits, Off Else)
462 */
463 if (miiphy_write(name, CONFIG_PHY_BASE_ADR,
464 PHY_MARVELL_88E1118R_LED_CTRL_REG,
465 PHY_MARVELL_88E1118R_LED_CTRL_RESERVED |
466 PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB |
467 PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT |
468 PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK))
469 printf("Error writing PHY LED reg\n");
470
471 /* set page register back to 0 */
472 if (miiphy_write(name, CONFIG_PHY_BASE_ADR,
473 PHY_MARVELL_PAGE_REG,
474 PHY_MARVELL_DEFAULT_PAGE))
475 printf("Error writing PHY page reg\n");
476 }
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530477}
Valentin Longchamp8f2827f2011-06-16 18:11:15 +0530478#endif
479
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530480
481#if defined(CONFIG_HUSH_INIT_VAR)
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100482int hush_init_var(void)
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530483{
Valentin Longchamp0bb95a62015-02-10 17:10:14 +0100484 ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530485 return 0;
486}
487#endif
488
Heiko Schocherea818db2013-01-29 08:53:15 +0100489#if defined(CONFIG_SYS_I2C_SOFT)
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100490void set_sda(int state)
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530491{
492 I2C_ACTIVE;
493 I2C_SDA(state);
494}
495
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100496void set_scl(int state)
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530497{
498 I2C_SCL(state);
499}
500
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100501int get_sda(void)
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530502{
503 I2C_TRISTATE;
504 return I2C_READ;
505}
506
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100507int get_scl(void)
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530508{
Heiko Schocher44097e22011-02-22 09:13:00 +0100509 return kw_gpio_get_value(KM_KIRKWOOD_SCL_PIN) ? 1 : 0;
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530510}
511#endif
512
Valentin Longchamp9400f8f2011-09-12 04:18:42 +0000513#if defined(CONFIG_POST)
514
515#define KM_POST_EN_L 44
516#define POST_WORD_OFF 8
517
518int post_hotkeys_pressed(void)
519{
Holger Brunckd9354532012-07-05 05:05:02 +0000520#if defined(CONFIG_KM_COGE5UN)
521 return kw_gpio_get_value(KM_POST_EN_L);
522#else
Valentin Longchamp9400f8f2011-09-12 04:18:42 +0000523 return !kw_gpio_get_value(KM_POST_EN_L);
Holger Brunckd9354532012-07-05 05:05:02 +0000524#endif
Valentin Longchamp9400f8f2011-09-12 04:18:42 +0000525}
526
527ulong post_word_load(void)
528{
Holger Brunck6a23f312011-12-14 05:31:20 +0000529 void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
Valentin Longchamp9400f8f2011-09-12 04:18:42 +0000530 return in_le32(addr);
531
532}
533void post_word_store(ulong value)
534{
Holger Brunck6a23f312011-12-14 05:31:20 +0000535 void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
Valentin Longchamp9400f8f2011-09-12 04:18:42 +0000536 out_le32(addr, value);
537}
538
539int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
540{
541 *vstart = CONFIG_SYS_SDRAM_BASE;
542
543 /* we go up to relocation plus a 1 MB margin */
544 *size = CONFIG_SYS_TEXT_BASE - (1<<20);
545
546 return 0;
547}
548#endif
549
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530550#if defined(CONFIG_SYS_EEPROM_WREN)
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100551int eeprom_write_enable(unsigned dev_addr, int state)
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530552{
Heiko Schocher44097e22011-02-22 09:13:00 +0100553 kw_gpio_set_value(KM_KIRKWOOD_ENV_WP, !state);
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530554
Heiko Schocher44097e22011-02-22 09:13:00 +0100555 return !kw_gpio_get_value(KM_KIRKWOOD_ENV_WP);
Heiko Schocher67fa8c22010-02-22 16:43:02 +0530556}
557#endif