blob: ea03be9eb37cf30c5223ae81d31cb7543bd438b4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schocher60301192010-02-22 16:43:02 +05302/*
3 * (C) Copyright 2009
4 * Marvell Semiconductor <www.marvell.com>
5 * Prafulla Wadaskar <prafulla@marvell.com>
6 *
7 * (C) Copyright 2009
8 * Stefan Roese, DENX Software Engineering, sr@denx.de.
9 *
10 * (C) Copyright 2010
11 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
Heiko Schocher60301192010-02-22 16:43:02 +053012 */
13
14#include <common.h>
15#include <i2c.h>
16#include <nand.h>
17#include <netdev.h>
18#include <miiphy.h>
Valentin Longchamp96957ef2012-06-13 03:01:03 +000019#include <spi.h>
Heiko Schocher60301192010-02-22 16:43:02 +053020#include <asm/io.h>
Lei Wen298ae912011-10-18 20:11:42 +053021#include <asm/arch/cpu.h>
Stefan Roesec2437842014-10-22 12:13:06 +020022#include <asm/arch/soc.h>
Heiko Schocher60301192010-02-22 16:43:02 +053023#include <asm/arch/mpp.h>
24
25#include "../common/common.h"
26
27DECLARE_GLOBAL_DATA_PTR;
28
Holger Brunck4de3cdd2011-05-31 02:12:52 +000029/*
30 * BOCO FPGA definitions
31 */
32#define BOCO 0x10
33#define REG_CTRL_H 0x02
34#define MASK_WRL_UNITRUN 0x01
35#define MASK_RBX_PGY_PRESENT 0x40
36#define REG_IRQ_CIRQ2 0x2d
37#define MASK_RBI_DEFECT_16 0x01
38
Tobias Müllerb0cab2d2015-11-13 15:01:15 +010039/*
40 * PHY registers definitions
41 */
42#define PHY_MARVELL_OUI 0x5043
43#define PHY_MARVELL_88E1118_MODEL 0x0022
44#define PHY_MARVELL_88E1118R_MODEL 0x0024
45
46#define PHY_MARVELL_PAGE_REG 0x0016
47#define PHY_MARVELL_DEFAULT_PAGE 0x0000
48
49#define PHY_MARVELL_88E1118R_LED_CTRL_PAGE 0x0003
50#define PHY_MARVELL_88E1118R_LED_CTRL_REG 0x0010
51
52#define PHY_MARVELL_88E1118R_LED_CTRL_RESERVED 0x1000
53#define PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB (0x7<<0)
54#define PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT (0x3<<4)
55#define PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK (0x0<<8)
56
Holger Brunck43cf3292015-11-13 15:01:16 +010057/* I/O pin to erase flash RGPP09 = MPP43 */
58#define KM_FLASH_ERASE_ENABLE 43
59
Heiko Schocher60301192010-02-22 16:43:02 +053060/* Multi-Purpose Pins Functionality configuration */
Albert ARIBAUD4d424312012-11-26 11:27:36 +000061static const u32 kwmpp_config[] = {
Heiko Schocher60301192010-02-22 16:43:02 +053062 MPP0_NF_IO2,
63 MPP1_NF_IO3,
64 MPP2_NF_IO4,
65 MPP3_NF_IO5,
66 MPP4_NF_IO6,
67 MPP5_NF_IO7,
68 MPP6_SYSRST_OUTn,
Gerlando Falauto29ff59a2014-02-13 16:43:00 +010069#if defined(KM_PCIE_RESET_MPP7)
70 MPP7_GPO,
71#else
Heiko Schocher60301192010-02-22 16:43:02 +053072 MPP7_PEX_RST_OUTn,
Gerlando Falauto29ff59a2014-02-13 16:43:00 +010073#endif
Heiko Schocher479a4cf2013-01-29 08:53:15 +010074#if defined(CONFIG_SYS_I2C_SOFT)
Heiko Schocher60301192010-02-22 16:43:02 +053075 MPP8_GPIO, /* SDA */
76 MPP9_GPIO, /* SCL */
77#endif
Heiko Schocher60301192010-02-22 16:43:02 +053078 MPP10_UART0_TXD,
79 MPP11_UART0_RXD,
80 MPP12_GPO, /* Reserved */
81 MPP13_UART1_TXD,
82 MPP14_UART1_RXD,
83 MPP15_GPIO, /* Not used */
84 MPP16_GPIO, /* Not used */
85 MPP17_GPIO, /* Reserved */
86 MPP18_NF_IO0,
87 MPP19_NF_IO1,
88 MPP20_GPIO,
89 MPP21_GPIO,
90 MPP22_GPIO,
91 MPP23_GPIO,
92 MPP24_GPIO,
93 MPP25_GPIO,
94 MPP26_GPIO,
95 MPP27_GPIO,
96 MPP28_GPIO,
97 MPP29_GPIO,
98 MPP30_GPIO,
99 MPP31_GPIO,
100 MPP32_GPIO,
101 MPP33_GPIO,
102 MPP34_GPIO, /* CDL1 (input) */
103 MPP35_GPIO, /* CDL2 (input) */
104 MPP36_GPIO, /* MAIN_IRQ (input) */
105 MPP37_GPIO, /* BOARD_LED */
106 MPP38_GPIO, /* Piggy3 LED[1] */
107 MPP39_GPIO, /* Piggy3 LED[2] */
108 MPP40_GPIO, /* Piggy3 LED[3] */
109 MPP41_GPIO, /* Piggy3 LED[4] */
110 MPP42_GPIO, /* Piggy3 LED[5] */
111 MPP43_GPIO, /* Piggy3 LED[6] */
Heiko Schocher9878f992011-02-22 09:13:00 +0100112 MPP44_GPIO, /* Piggy3 LED[7], BIST_EN_L */
Heiko Schocher60301192010-02-22 16:43:02 +0530113 MPP45_GPIO, /* Piggy3 LED[8] */
114 MPP46_GPIO, /* Reserved */
115 MPP47_GPIO, /* Reserved */
116 MPP48_GPIO, /* Reserved */
117 MPP49_GPIO, /* SW_INTOUTn */
118 0
119};
120
Valentin Longchampaea4bb52015-02-10 17:10:14 +0100121static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
122
Holger Brunckd896d0d2012-07-05 05:05:03 +0000123#if defined(CONFIG_KM_MGCOGE3UN)
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000124/*
125 * Wait for startup OK from mgcoge3ne
126 */
Holger Brunck09346ff2014-01-27 16:58:23 +0100127static int startup_allowed(void)
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000128{
129 unsigned char buf;
130
131 /*
132 * Read CIRQ16 bit (bit 0)
133 */
134 if (i2c_read(BOCO, REG_IRQ_CIRQ2, 1, &buf, 1) != 0)
135 printf("%s: Error reading Boco\n", __func__);
136 else
137 if ((buf & MASK_RBI_DEFECT_16) == MASK_RBI_DEFECT_16)
138 return 1;
139 return 0;
140}
Valentin Longchamp2ec63ad2011-06-16 18:11:15 +0530141#endif
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000142
Holger Brunckd896d0d2012-07-05 05:05:03 +0000143#if (defined(CONFIG_KM_PIGGY4_88E6061)|defined(CONFIG_KM_PIGGY4_88E6352))
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000144/*
Holger Brunck2ef42952012-07-05 05:37:46 +0000145 * All boards with PIGGY4 connected via a simple switch have ethernet always
146 * present.
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000147 */
148int ethernet_present(void)
149{
150 return 1;
151}
152#else
Heiko Schocher60301192010-02-22 16:43:02 +0530153int ethernet_present(void)
154{
155 uchar buf;
156 int ret = 0;
157
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000158 if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100159 printf("%s: Error reading Boco\n", __func__);
Heiko Schocher60301192010-02-22 16:43:02 +0530160 return -1;
161 }
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000162 if ((buf & MASK_RBX_PGY_PRESENT) == MASK_RBX_PGY_PRESENT)
Heiko Schocher60301192010-02-22 16:43:02 +0530163 ret = 1;
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100164
Heiko Schocher60301192010-02-22 16:43:02 +0530165 return ret;
166}
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000167#endif
Heiko Schocher60301192010-02-22 16:43:02 +0530168
Holger Brunck03ab2862013-05-06 15:04:51 +0200169static int initialize_unit_leds(void)
Heiko Schochere4533af2011-03-08 10:53:51 +0100170{
171 /*
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000172 * Init the unit LEDs per default they all are
Heiko Schochere4533af2011-03-08 10:53:51 +0100173 * ok apart from bootstat
Heiko Schochere4533af2011-03-08 10:53:51 +0100174 */
Heiko Schochere4533af2011-03-08 10:53:51 +0100175 uchar buf;
176
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000177 if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
Heiko Schochere4533af2011-03-08 10:53:51 +0100178 printf("%s: Error reading Boco\n", __func__);
179 return -1;
180 }
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000181 buf |= MASK_WRL_UNITRUN;
182 if (i2c_write(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
Heiko Schochere4533af2011-03-08 10:53:51 +0100183 printf("%s: Error writing Boco\n", __func__);
184 return -1;
185 }
186 return 0;
187}
188
Holger Brunck03ab2862013-05-06 15:04:51 +0200189static void set_bootcount_addr(void)
Valentin Longchamp184907a2011-05-31 02:12:47 +0000190{
191 uchar buf[32];
192 unsigned int bootcountaddr;
193 bootcountaddr = gd->ram_size - BOOTCOUNT_ADDR;
194 sprintf((char *)buf, "0x%x", bootcountaddr);
Simon Glass6a38e412017-08-03 12:22:09 -0600195 env_set("bootcountaddr", (char *)buf);
Valentin Longchamp184907a2011-05-31 02:12:47 +0000196}
Valentin Longchamp184907a2011-05-31 02:12:47 +0000197
Heiko Schocher60301192010-02-22 16:43:02 +0530198int misc_init_r(void)
199{
Holger Brunckd896d0d2012-07-05 05:05:03 +0000200#if defined(CONFIG_KM_MGCOGE3UN)
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000201 char *wait_for_ne;
Holger Brunck43cf3292015-11-13 15:01:16 +0100202 u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE);
Simon Glass64b723f2017-08-03 12:22:12 -0600203 wait_for_ne = env_get("waitforne");
Holger Brunck43cf3292015-11-13 15:01:16 +0100204
205 if ((wait_for_ne != NULL) && (dip_switch == 0)) {
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000206 if (strcmp(wait_for_ne, "true") == 0) {
207 int cnt = 0;
Holger Brunck42874a72011-09-27 02:54:31 +0000208 int abort = 0;
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000209 puts("NE go: ");
210 while (startup_allowed() == 0) {
Holger Brunck42874a72011-09-27 02:54:31 +0000211 if (tstc()) {
212 (void) getc(); /* consume input */
213 abort = 1;
214 break;
215 }
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000216 udelay(200000);
217 cnt++;
218 if (cnt == 5)
219 puts("wait\b\b\b\b");
220 if (cnt == 10) {
221 cnt = 0;
222 puts(" \b\b\b\b");
223 }
224 }
Holger Brunck42874a72011-09-27 02:54:31 +0000225 if (abort == 1)
226 printf("\nAbort waiting for ne\n");
227 else
228 puts("OK\n");
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000229 }
230 }
231#endif
Heiko Schochere4533af2011-03-08 10:53:51 +0100232
Valentin Longchamp876f7a92015-02-10 17:10:18 +0100233 ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
Valentin Longchampaea4bb52015-02-10 17:10:14 +0100234
Heiko Schochere4533af2011-03-08 10:53:51 +0100235 initialize_unit_leds();
Valentin Longchamp184907a2011-05-31 02:12:47 +0000236 set_km_env();
Valentin Longchamp184907a2011-05-31 02:12:47 +0000237 set_bootcount_addr();
Heiko Schocher60301192010-02-22 16:43:02 +0530238 return 0;
239}
240
Heiko Schocher3ebd02b2010-10-20 19:33:26 +0530241int board_early_init_f(void)
Heiko Schocher60301192010-02-22 16:43:02 +0530242{
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100243#if defined(CONFIG_SYS_I2C_SOFT)
Heiko Schocher60301192010-02-22 16:43:02 +0530244 u32 tmp;
245
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000246 /* set the 2 bitbang i2c pins as output gpios */
Stefan Roesec50ab392014-10-22 12:13:11 +0200247 tmp = readl(MVEBU_GPIO0_BASE + 4);
248 writel(tmp & (~KM_KIRKWOOD_SOFT_I2C_GPIOS) , MVEBU_GPIO0_BASE + 4);
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000249#endif
Holger Brunckb59a9552012-07-25 06:26:03 +0000250 /* adjust SDRAM size for bank 0 */
Stefan Roese0b741752014-10-22 12:13:13 +0200251 mvebu_sdram_size_adjust(0);
Valentin Longchamp7d0d5022012-06-01 01:31:00 +0000252 kirkwood_mpp_conf(kwmpp_config, NULL);
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000253 return 0;
254}
Heiko Schocher60301192010-02-22 16:43:02 +0530255
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000256int board_init(void)
257{
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000258 /* address of boot parameters */
Stefan Roese0b741752014-10-22 12:13:13 +0200259 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000260
261 /*
262 * The KM_FLASH_GPIO_PIN switches between using a
Heiko Schocher60301192010-02-22 16:43:02 +0530263 * NAND or a SPI FLASH. Set this pin on start
264 * to NAND mode.
265 */
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000266 kw_gpio_set_valid(KM_FLASH_GPIO_PIN, 1);
267 kw_gpio_direction_output(KM_FLASH_GPIO_PIN, 1);
Heiko Schocher60301192010-02-22 16:43:02 +0530268
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100269#if defined(CONFIG_SYS_I2C_SOFT)
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000270 /*
271 * Reinit the GPIO for I2C Bitbang driver so that the now
272 * available gpio framework is consistent. The calls to
273 * direction output in are not necessary, they are already done in
274 * board_early_init_f
275 */
Heiko Schocher9878f992011-02-22 09:13:00 +0100276 kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
277 kw_gpio_set_valid(KM_KIRKWOOD_SCL_PIN, 1);
Heiko Schocher60301192010-02-22 16:43:02 +0530278#endif
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000279
Heiko Schocher60301192010-02-22 16:43:02 +0530280#if defined(CONFIG_SYS_EEPROM_WREN)
Heiko Schocher9878f992011-02-22 09:13:00 +0100281 kw_gpio_set_valid(KM_KIRKWOOD_ENV_WP, 38);
282 kw_gpio_direction_output(KM_KIRKWOOD_ENV_WP, 1);
Heiko Schocher60301192010-02-22 16:43:02 +0530283#endif
Heiko Schocher3ebd02b2010-10-20 19:33:26 +0530284
Valentin Longchamp6633fed2012-07-05 05:05:05 +0000285#if defined(CONFIG_KM_FPGA_CONFIG)
286 trigger_fpga_config();
287#endif
288
289 return 0;
290}
291
292int board_late_init(void)
293{
Valentin Longchampbba4e252015-11-13 15:01:17 +0100294#if (defined(CONFIG_KM_COGE5UN) | defined(CONFIG_KM_MGCOGE3UN))
Thomas Herzmann3ed53142012-07-05 05:05:10 +0000295 u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE);
296
297 /* if pin 1 do full erase */
298 if (dip_switch != 0) {
299 /* start bootloader */
300 puts("DIP: Enabled\n");
Simon Glass6a38e412017-08-03 12:22:09 -0600301 env_set("actual_bank", "0");
Thomas Herzmann3ed53142012-07-05 05:05:10 +0000302 }
303#endif
304
Valentin Longchamp6633fed2012-07-05 05:05:05 +0000305#if defined(CONFIG_KM_FPGA_CONFIG)
306 wait_for_fpga_config();
307 fpga_reset();
308 toggle_eeprom_spi_bus();
309#endif
Heiko Schochercfc58042010-04-26 13:07:28 +0200310 return 0;
311}
312
Valentin Longchamp96957ef2012-06-13 03:01:03 +0000313int board_spi_claim_bus(struct spi_slave *slave)
Heiko Schocher60301192010-02-22 16:43:02 +0530314{
Valentin Longchamp96957ef2012-06-13 03:01:03 +0000315 kw_gpio_set_value(KM_FLASH_GPIO_PIN, 0);
Heiko Schocher60301192010-02-22 16:43:02 +0530316
317 return 0;
318}
319
Valentin Longchamp96957ef2012-06-13 03:01:03 +0000320void board_spi_release_bus(struct spi_slave *slave)
321{
322 kw_gpio_set_value(KM_FLASH_GPIO_PIN, 1);
323}
Heiko Schocher60301192010-02-22 16:43:02 +0530324
Holger Brunckc9caa7f2012-07-05 05:05:04 +0000325#if (defined(CONFIG_KM_PIGGY4_88E6061))
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530326
Valentin Longchampa7ef9af2012-07-05 05:05:07 +0000327#define PHY_LED_SEL_REG 0x18
328#define PHY_LED0_LINK (0x5)
329#define PHY_LED1_ACT (0x8<<4)
330#define PHY_LED2_INT (0xe<<8)
331#define PHY_SPEC_CTRL_REG 0x1c
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530332#define PHY_RGMII_CLK_STABLE (0x1<<10)
Valentin Longchampa7ef9af2012-07-05 05:05:07 +0000333#define PHY_CLSA (0x1<<1)
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530334
335/* Configure and enable MV88E3018 PHY */
Heiko Schocher60301192010-02-22 16:43:02 +0530336void reset_phy(void)
337{
338 char *name = "egiga0";
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530339 unsigned short reg;
Heiko Schocher60301192010-02-22 16:43:02 +0530340
341 if (miiphy_set_current_dev(name))
342 return;
343
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530344 /* RGMII clk transition on data stable */
Holger Brunck7fef6552014-01-27 16:58:26 +0100345 if (miiphy_read(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG, &reg))
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530346 printf("Error reading PHY spec ctrl reg\n");
Holger Brunck7fef6552014-01-27 16:58:26 +0100347 if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG,
348 reg | PHY_RGMII_CLK_STABLE | PHY_CLSA))
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530349 printf("Error writing PHY spec ctrl reg\n");
350
351 /* leds setup */
Holger Brunck7fef6552014-01-27 16:58:26 +0100352 if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_LED_SEL_REG,
353 PHY_LED0_LINK | PHY_LED1_ACT | PHY_LED2_INT))
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530354 printf("Error writing PHY LED reg\n");
355
Heiko Schocher60301192010-02-22 16:43:02 +0530356 /* reset the phy */
357 miiphy_reset(name, CONFIG_PHY_BASE_ADR);
358}
Valentin Longchamp310164a2012-08-16 23:35:03 +0000359#elif defined(CONFIG_KM_PIGGY4_88E6352)
360
361#include <mv88e6352.h>
362
363#if defined(CONFIG_KM_NUSA)
364struct mv88e_sw_reg extsw_conf[] = {
365 /*
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +0200366 * port 0, PIGGY4, autoneg
Valentin Longchamp310164a2012-08-16 23:35:03 +0000367 * first the fix for the 1000Mbits Autoneg, this is from
368 * a Marvell errata, the regs are undocumented
369 */
370 { PHY(0), PHY_PAGE, AN1000FIX_PAGE },
371 { PHY(0), PHY_STATUS, AN1000FIX },
372 { PHY(0), PHY_PAGE, 0 },
373 /* now the real port and phy configuration */
374 { PORT(0), PORT_PHY, NO_SPEED_FOR },
375 { PORT(0), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
376 { PHY(0), PHY_1000_CTRL, NO_ADV },
377 { PHY(0), PHY_SPEC_CTRL, AUTO_MDIX_EN },
378 { PHY(0), PHY_CTRL, PHY_100_MBPS | AUTONEG_EN | AUTONEG_RST |
379 FULL_DUPLEX },
380 /* port 1, unused */
381 { PORT(1), PORT_CTRL, PORT_DIS },
382 { PHY(1), PHY_CTRL, PHY_PWR_DOWN },
383 { PHY(1), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
384 /* port 2, unused */
385 { PORT(2), PORT_CTRL, PORT_DIS },
386 { PHY(2), PHY_CTRL, PHY_PWR_DOWN },
387 { PHY(2), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
388 /* port 3, unused */
389 { PORT(3), PORT_CTRL, PORT_DIS },
390 { PHY(3), PHY_CTRL, PHY_PWR_DOWN },
391 { PHY(3), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
392 /* port 4, ICNEV, SerDes, SGMII */
393 { PORT(4), PORT_STATUS, NO_PHY_DETECT },
394 { PORT(4), PORT_PHY, SPEED_1000_FOR },
395 { PORT(4), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
396 { PHY(4), PHY_CTRL, PHY_PWR_DOWN },
397 { PHY(4), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
398 /* port 5, CPU_RGMII */
399 { PORT(5), PORT_PHY, RX_RGMII_TIM | TX_RGMII_TIM | FLOW_CTRL_EN |
400 FLOW_CTRL_FOR | LINK_VAL | LINK_FOR | FULL_DPX |
401 FULL_DPX_FOR | SPEED_1000_FOR },
402 { PORT(5), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
403 /* port 6, unused, this port has no phy */
404 { PORT(6), PORT_CTRL, PORT_DIS },
405};
406#else
407struct mv88e_sw_reg extsw_conf[] = {};
408#endif
409
410void reset_phy(void)
411{
412#if defined(CONFIG_KM_MVEXTSW_ADDR)
413 char *name = "egiga0";
414
415 if (miiphy_set_current_dev(name))
416 return;
417
418 mv88e_sw_program(name, CONFIG_KM_MVEXTSW_ADDR, extsw_conf,
419 ARRAY_SIZE(extsw_conf));
420 mv88e_sw_reset(name, CONFIG_KM_MVEXTSW_ADDR);
421#endif
422}
423
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530424#else
425/* Configure and enable MV88E1118 PHY on the piggy*/
426void reset_phy(void)
427{
Tobias Müllerb0cab2d2015-11-13 15:01:15 +0100428 unsigned int oui;
429 unsigned char model, rev;
430
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530431 char *name = "egiga0";
432
433 if (miiphy_set_current_dev(name))
434 return;
435
436 /* reset the phy */
437 miiphy_reset(name, CONFIG_PHY_BASE_ADR);
Tobias Müllerb0cab2d2015-11-13 15:01:15 +0100438
439 /* get PHY model */
440 if (miiphy_info(name, CONFIG_PHY_BASE_ADR, &oui, &model, &rev))
441 return;
442
443 /* check for Marvell 88E1118R Gigabit PHY (PIGGY3) */
444 if ((oui == PHY_MARVELL_OUI) &&
445 (model == PHY_MARVELL_88E1118R_MODEL)) {
446 /* set page register to 3 */
447 if (miiphy_write(name, CONFIG_PHY_BASE_ADR,
448 PHY_MARVELL_PAGE_REG,
449 PHY_MARVELL_88E1118R_LED_CTRL_PAGE))
450 printf("Error writing PHY page reg\n");
451
452 /*
453 * leds setup as printed on PCB:
454 * LED2 (Link): 0x0 (On Link, Off No Link)
455 * LED1 (Activity): 0x3 (On Activity, Off No Activity)
456 * LED0 (Speed): 0x7 (On 1000 MBits, Off Else)
457 */
458 if (miiphy_write(name, CONFIG_PHY_BASE_ADR,
459 PHY_MARVELL_88E1118R_LED_CTRL_REG,
460 PHY_MARVELL_88E1118R_LED_CTRL_RESERVED |
461 PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB |
462 PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT |
463 PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK))
464 printf("Error writing PHY LED reg\n");
465
466 /* set page register back to 0 */
467 if (miiphy_write(name, CONFIG_PHY_BASE_ADR,
468 PHY_MARVELL_PAGE_REG,
469 PHY_MARVELL_DEFAULT_PAGE))
470 printf("Error writing PHY page reg\n");
471 }
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530472}
473#endif
474
Heiko Schocher60301192010-02-22 16:43:02 +0530475
476#if defined(CONFIG_HUSH_INIT_VAR)
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100477int hush_init_var(void)
Heiko Schocher60301192010-02-22 16:43:02 +0530478{
Valentin Longchampaea4bb52015-02-10 17:10:14 +0100479 ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
Heiko Schocher60301192010-02-22 16:43:02 +0530480 return 0;
481}
482#endif
483
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100484#if defined(CONFIG_SYS_I2C_SOFT)
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100485void set_sda(int state)
Heiko Schocher60301192010-02-22 16:43:02 +0530486{
487 I2C_ACTIVE;
488 I2C_SDA(state);
489}
490
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100491void set_scl(int state)
Heiko Schocher60301192010-02-22 16:43:02 +0530492{
493 I2C_SCL(state);
494}
495
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100496int get_sda(void)
Heiko Schocher60301192010-02-22 16:43:02 +0530497{
498 I2C_TRISTATE;
499 return I2C_READ;
500}
501
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100502int get_scl(void)
Heiko Schocher60301192010-02-22 16:43:02 +0530503{
Heiko Schocher9878f992011-02-22 09:13:00 +0100504 return kw_gpio_get_value(KM_KIRKWOOD_SCL_PIN) ? 1 : 0;
Heiko Schocher60301192010-02-22 16:43:02 +0530505}
506#endif
507
Valentin Longchamp24ec9932011-09-12 04:18:42 +0000508#if defined(CONFIG_POST)
509
510#define KM_POST_EN_L 44
511#define POST_WORD_OFF 8
512
513int post_hotkeys_pressed(void)
514{
Holger Brunckf065ce02012-07-05 05:05:02 +0000515#if defined(CONFIG_KM_COGE5UN)
516 return kw_gpio_get_value(KM_POST_EN_L);
517#else
Valentin Longchamp24ec9932011-09-12 04:18:42 +0000518 return !kw_gpio_get_value(KM_POST_EN_L);
Holger Brunckf065ce02012-07-05 05:05:02 +0000519#endif
Valentin Longchamp24ec9932011-09-12 04:18:42 +0000520}
521
522ulong post_word_load(void)
523{
Holger Brunck763c2dc2011-12-14 05:31:20 +0000524 void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
Valentin Longchamp24ec9932011-09-12 04:18:42 +0000525 return in_le32(addr);
526
527}
528void post_word_store(ulong value)
529{
Holger Brunck763c2dc2011-12-14 05:31:20 +0000530 void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
Valentin Longchamp24ec9932011-09-12 04:18:42 +0000531 out_le32(addr, value);
532}
533
534int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
535{
536 *vstart = CONFIG_SYS_SDRAM_BASE;
537
538 /* we go up to relocation plus a 1 MB margin */
539 *size = CONFIG_SYS_TEXT_BASE - (1<<20);
540
541 return 0;
542}
543#endif
544
Heiko Schocher60301192010-02-22 16:43:02 +0530545#if defined(CONFIG_SYS_EEPROM_WREN)
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100546int eeprom_write_enable(unsigned dev_addr, int state)
Heiko Schocher60301192010-02-22 16:43:02 +0530547{
Heiko Schocher9878f992011-02-22 09:13:00 +0100548 kw_gpio_set_value(KM_KIRKWOOD_ENV_WP, !state);
Heiko Schocher60301192010-02-22 16:43:02 +0530549
Heiko Schocher9878f992011-02-22 09:13:00 +0100550 return !kw_gpio_get_value(KM_KIRKWOOD_ENV_WP);
Heiko Schocher60301192010-02-22 16:43:02 +0530551}
552#endif