blob: 60187bd8d294c06a18fa37c426b621cfaa174ffe [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>
Simon Glass5e6201b2019-08-01 09:46:51 -060015#include <env.h>
Heiko Schocher60301192010-02-22 16:43:02 +053016#include <i2c.h>
Simon Glassa7b51302019-11-14 12:57:46 -070017#include <init.h>
Heiko Schocher60301192010-02-22 16:43:02 +053018#include <nand.h>
Simon Glass0c364412019-12-28 10:44:48 -070019#include <net.h>
Heiko Schocher60301192010-02-22 16:43:02 +053020#include <netdev.h>
21#include <miiphy.h>
Valentin Longchamp96957ef2012-06-13 03:01:03 +000022#include <spi.h>
Heiko Schocher60301192010-02-22 16:43:02 +053023#include <asm/io.h>
Lei Wen298ae912011-10-18 20:11:42 +053024#include <asm/arch/cpu.h>
Stefan Roesec2437842014-10-22 12:13:06 +020025#include <asm/arch/soc.h>
Heiko Schocher60301192010-02-22 16:43:02 +053026#include <asm/arch/mpp.h>
27
28#include "../common/common.h"
29
30DECLARE_GLOBAL_DATA_PTR;
31
Holger Brunck4de3cdd2011-05-31 02:12:52 +000032/*
33 * BOCO FPGA definitions
34 */
35#define BOCO 0x10
36#define REG_CTRL_H 0x02
37#define MASK_WRL_UNITRUN 0x01
38#define MASK_RBX_PGY_PRESENT 0x40
39#define REG_IRQ_CIRQ2 0x2d
40#define MASK_RBI_DEFECT_16 0x01
41
Tobias Müllerb0cab2d2015-11-13 15:01:15 +010042/*
43 * PHY registers definitions
44 */
45#define PHY_MARVELL_OUI 0x5043
46#define PHY_MARVELL_88E1118_MODEL 0x0022
47#define PHY_MARVELL_88E1118R_MODEL 0x0024
48
49#define PHY_MARVELL_PAGE_REG 0x0016
50#define PHY_MARVELL_DEFAULT_PAGE 0x0000
51
52#define PHY_MARVELL_88E1118R_LED_CTRL_PAGE 0x0003
53#define PHY_MARVELL_88E1118R_LED_CTRL_REG 0x0010
54
55#define PHY_MARVELL_88E1118R_LED_CTRL_RESERVED 0x1000
Holger Brunckff41a752020-10-30 12:45:49 +010056#define PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB (0x7 << 0)
57#define PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT (0x3 << 4)
58#define PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK (0x0 << 8)
Tobias Müllerb0cab2d2015-11-13 15:01:15 +010059
Holger Brunck43cf3292015-11-13 15:01:16 +010060/* I/O pin to erase flash RGPP09 = MPP43 */
61#define KM_FLASH_ERASE_ENABLE 43
62
Heiko Schocher60301192010-02-22 16:43:02 +053063/* Multi-Purpose Pins Functionality configuration */
Albert ARIBAUD4d424312012-11-26 11:27:36 +000064static const u32 kwmpp_config[] = {
Heiko Schocher60301192010-02-22 16:43:02 +053065 MPP0_NF_IO2,
66 MPP1_NF_IO3,
67 MPP2_NF_IO4,
68 MPP3_NF_IO5,
69 MPP4_NF_IO6,
70 MPP5_NF_IO7,
71 MPP6_SYSRST_OUTn,
72 MPP7_PEX_RST_OUTn,
Heiko Schocher479a4cf2013-01-29 08:53:15 +010073#if defined(CONFIG_SYS_I2C_SOFT)
Heiko Schocher60301192010-02-22 16:43:02 +053074 MPP8_GPIO, /* SDA */
75 MPP9_GPIO, /* SCL */
76#endif
Heiko Schocher60301192010-02-22 16:43:02 +053077 MPP10_UART0_TXD,
78 MPP11_UART0_RXD,
79 MPP12_GPO, /* Reserved */
80 MPP13_UART1_TXD,
81 MPP14_UART1_RXD,
82 MPP15_GPIO, /* Not used */
83 MPP16_GPIO, /* Not used */
84 MPP17_GPIO, /* Reserved */
85 MPP18_NF_IO0,
86 MPP19_NF_IO1,
87 MPP20_GPIO,
88 MPP21_GPIO,
89 MPP22_GPIO,
90 MPP23_GPIO,
91 MPP24_GPIO,
92 MPP25_GPIO,
93 MPP26_GPIO,
94 MPP27_GPIO,
95 MPP28_GPIO,
96 MPP29_GPIO,
97 MPP30_GPIO,
98 MPP31_GPIO,
99 MPP32_GPIO,
100 MPP33_GPIO,
101 MPP34_GPIO, /* CDL1 (input) */
102 MPP35_GPIO, /* CDL2 (input) */
103 MPP36_GPIO, /* MAIN_IRQ (input) */
104 MPP37_GPIO, /* BOARD_LED */
105 MPP38_GPIO, /* Piggy3 LED[1] */
106 MPP39_GPIO, /* Piggy3 LED[2] */
107 MPP40_GPIO, /* Piggy3 LED[3] */
108 MPP41_GPIO, /* Piggy3 LED[4] */
109 MPP42_GPIO, /* Piggy3 LED[5] */
110 MPP43_GPIO, /* Piggy3 LED[6] */
Heiko Schocher9878f992011-02-22 09:13:00 +0100111 MPP44_GPIO, /* Piggy3 LED[7], BIST_EN_L */
Heiko Schocher60301192010-02-22 16:43:02 +0530112 MPP45_GPIO, /* Piggy3 LED[8] */
113 MPP46_GPIO, /* Reserved */
114 MPP47_GPIO, /* Reserved */
115 MPP48_GPIO, /* Reserved */
116 MPP49_GPIO, /* SW_INTOUTn */
117 0
118};
119
Valentin Longchampaea4bb52015-02-10 17:10:14 +0100120static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
121
Holger Brunckd896d0d2012-07-05 05:05:03 +0000122#if (defined(CONFIG_KM_PIGGY4_88E6061)|defined(CONFIG_KM_PIGGY4_88E6352))
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000123/*
Holger Brunck2ef42952012-07-05 05:37:46 +0000124 * All boards with PIGGY4 connected via a simple switch have ethernet always
125 * present.
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000126 */
127int ethernet_present(void)
128{
129 return 1;
130}
131#else
Heiko Schocher60301192010-02-22 16:43:02 +0530132int ethernet_present(void)
133{
134 uchar buf;
135 int ret = 0;
136
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000137 if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100138 printf("%s: Error reading Boco\n", __func__);
Heiko Schocher60301192010-02-22 16:43:02 +0530139 return -1;
140 }
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000141 if ((buf & MASK_RBX_PGY_PRESENT) == MASK_RBX_PGY_PRESENT)
Heiko Schocher60301192010-02-22 16:43:02 +0530142 ret = 1;
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100143
Heiko Schocher60301192010-02-22 16:43:02 +0530144 return ret;
145}
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000146#endif
Heiko Schocher60301192010-02-22 16:43:02 +0530147
Holger Brunck03ab2862013-05-06 15:04:51 +0200148static int initialize_unit_leds(void)
Heiko Schochere4533af2011-03-08 10:53:51 +0100149{
150 /*
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000151 * Init the unit LEDs per default they all are
Heiko Schochere4533af2011-03-08 10:53:51 +0100152 * ok apart from bootstat
Heiko Schochere4533af2011-03-08 10:53:51 +0100153 */
Heiko Schochere4533af2011-03-08 10:53:51 +0100154 uchar buf;
155
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000156 if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
Heiko Schochere4533af2011-03-08 10:53:51 +0100157 printf("%s: Error reading Boco\n", __func__);
158 return -1;
159 }
Holger Brunck4de3cdd2011-05-31 02:12:52 +0000160 buf |= MASK_WRL_UNITRUN;
161 if (i2c_write(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
Heiko Schochere4533af2011-03-08 10:53:51 +0100162 printf("%s: Error writing Boco\n", __func__);
163 return -1;
164 }
165 return 0;
166}
167
Holger Brunck03ab2862013-05-06 15:04:51 +0200168static void set_bootcount_addr(void)
Valentin Longchamp184907a2011-05-31 02:12:47 +0000169{
170 uchar buf[32];
171 unsigned int bootcountaddr;
Holger Brunckff41a752020-10-30 12:45:49 +0100172
Valentin Longchamp184907a2011-05-31 02:12:47 +0000173 bootcountaddr = gd->ram_size - BOOTCOUNT_ADDR;
174 sprintf((char *)buf, "0x%x", bootcountaddr);
Simon Glass6a38e412017-08-03 12:22:09 -0600175 env_set("bootcountaddr", (char *)buf);
Valentin Longchamp184907a2011-05-31 02:12:47 +0000176}
Valentin Longchamp184907a2011-05-31 02:12:47 +0000177
Heiko Schocher60301192010-02-22 16:43:02 +0530178int misc_init_r(void)
179{
Holger Brunck0340b6a2019-11-25 17:24:14 +0100180 ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN,
181 CONFIG_PIGGY_MAC_ADDRESS_OFFSET);
Valentin Longchampaea4bb52015-02-10 17:10:14 +0100182
Heiko Schochere4533af2011-03-08 10:53:51 +0100183 initialize_unit_leds();
Valentin Longchamp184907a2011-05-31 02:12:47 +0000184 set_km_env();
Valentin Longchamp184907a2011-05-31 02:12:47 +0000185 set_bootcount_addr();
Heiko Schocher60301192010-02-22 16:43:02 +0530186 return 0;
187}
188
Heiko Schocher3ebd02b2010-10-20 19:33:26 +0530189int board_early_init_f(void)
Heiko Schocher60301192010-02-22 16:43:02 +0530190{
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100191#if defined(CONFIG_SYS_I2C_SOFT)
Heiko Schocher60301192010-02-22 16:43:02 +0530192 u32 tmp;
193
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000194 /* set the 2 bitbang i2c pins as output gpios */
Stefan Roesec50ab392014-10-22 12:13:11 +0200195 tmp = readl(MVEBU_GPIO0_BASE + 4);
Holger Brunckff41a752020-10-30 12:45:49 +0100196 writel(tmp & (~KM_KIRKWOOD_SOFT_I2C_GPIOS), MVEBU_GPIO0_BASE + 4);
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000197#endif
Holger Brunckb59a9552012-07-25 06:26:03 +0000198 /* adjust SDRAM size for bank 0 */
Stefan Roese0b741752014-10-22 12:13:13 +0200199 mvebu_sdram_size_adjust(0);
Valentin Longchamp7d0d5022012-06-01 01:31:00 +0000200 kirkwood_mpp_conf(kwmpp_config, NULL);
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000201 return 0;
202}
Heiko Schocher60301192010-02-22 16:43:02 +0530203
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000204int board_init(void)
205{
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000206 /* address of boot parameters */
Stefan Roese0b741752014-10-22 12:13:13 +0200207 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000208
209 /*
210 * The KM_FLASH_GPIO_PIN switches between using a
Heiko Schocher60301192010-02-22 16:43:02 +0530211 * NAND or a SPI FLASH. Set this pin on start
212 * to NAND mode.
213 */
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000214 kw_gpio_set_valid(KM_FLASH_GPIO_PIN, 1);
215 kw_gpio_direction_output(KM_FLASH_GPIO_PIN, 1);
Heiko Schocher60301192010-02-22 16:43:02 +0530216
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100217#if defined(CONFIG_SYS_I2C_SOFT)
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000218 /*
219 * Reinit the GPIO for I2C Bitbang driver so that the now
220 * available gpio framework is consistent. The calls to
221 * direction output in are not necessary, they are already done in
222 * board_early_init_f
223 */
Heiko Schocher9878f992011-02-22 09:13:00 +0100224 kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
225 kw_gpio_set_valid(KM_KIRKWOOD_SCL_PIN, 1);
Heiko Schocher60301192010-02-22 16:43:02 +0530226#endif
Holger Brunck7d25a1a2012-07-05 05:05:11 +0000227
Heiko Schocher60301192010-02-22 16:43:02 +0530228#if defined(CONFIG_SYS_EEPROM_WREN)
Heiko Schocher9878f992011-02-22 09:13:00 +0100229 kw_gpio_set_valid(KM_KIRKWOOD_ENV_WP, 38);
230 kw_gpio_direction_output(KM_KIRKWOOD_ENV_WP, 1);
Heiko Schocher60301192010-02-22 16:43:02 +0530231#endif
Heiko Schocher3ebd02b2010-10-20 19:33:26 +0530232
Valentin Longchamp6633fed2012-07-05 05:05:05 +0000233#if defined(CONFIG_KM_FPGA_CONFIG)
234 trigger_fpga_config();
235#endif
236
237 return 0;
238}
239
240int board_late_init(void)
241{
Holger Bruncke306c672019-11-25 17:24:15 +0100242#if defined(CONFIG_KM_COGE5UN)
Thomas Herzmann3ed53142012-07-05 05:05:10 +0000243 u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE);
244
245 /* if pin 1 do full erase */
246 if (dip_switch != 0) {
247 /* start bootloader */
248 puts("DIP: Enabled\n");
Simon Glass6a38e412017-08-03 12:22:09 -0600249 env_set("actual_bank", "0");
Thomas Herzmann3ed53142012-07-05 05:05:10 +0000250 }
251#endif
252
Valentin Longchamp6633fed2012-07-05 05:05:05 +0000253#if defined(CONFIG_KM_FPGA_CONFIG)
254 wait_for_fpga_config();
255 fpga_reset();
256 toggle_eeprom_spi_bus();
257#endif
Heiko Schochercfc58042010-04-26 13:07:28 +0200258 return 0;
259}
260
Pascal Linder6adad982019-06-18 08:41:02 +0200261static const u32 spi_mpp_config[] = {
262 MPP1_SPI_MOSI,
263 MPP2_SPI_SCK,
264 MPP3_SPI_MISO,
265 0
266};
267
268static u32 spi_mpp_backup[4];
269
270int mvebu_board_spi_claim_bus(struct udevice *dev)
271{
272 spi_mpp_backup[3] = 0;
273
274 /* set new spi mpp config and save current one */
275 kirkwood_mpp_conf(spi_mpp_config, spi_mpp_backup);
276
277 kw_gpio_set_value(KM_FLASH_GPIO_PIN, 0);
278
279 return 0;
280}
281
282int mvebu_board_spi_release_bus(struct udevice *dev)
283{
284 /* restore saved mpp config */
285 kirkwood_mpp_conf(spi_mpp_backup, NULL);
286
287 kw_gpio_set_value(KM_FLASH_GPIO_PIN, 1);
288
289 return 0;
290}
291
Holger Brunckc9caa7f2012-07-05 05:05:04 +0000292#if (defined(CONFIG_KM_PIGGY4_88E6061))
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530293
Valentin Longchampa7ef9af2012-07-05 05:05:07 +0000294#define PHY_LED_SEL_REG 0x18
295#define PHY_LED0_LINK (0x5)
Holger Brunckff41a752020-10-30 12:45:49 +0100296#define PHY_LED1_ACT (0x8 << 4)
297#define PHY_LED2_INT (0xe << 8)
Valentin Longchampa7ef9af2012-07-05 05:05:07 +0000298#define PHY_SPEC_CTRL_REG 0x1c
Holger Brunckff41a752020-10-30 12:45:49 +0100299#define PHY_RGMII_CLK_STABLE (0x1 << 10)
300#define PHY_CLSA (0x1 << 1)
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530301
302/* Configure and enable MV88E3018 PHY */
Heiko Schocher60301192010-02-22 16:43:02 +0530303void reset_phy(void)
304{
305 char *name = "egiga0";
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530306 unsigned short reg;
Heiko Schocher60301192010-02-22 16:43:02 +0530307
308 if (miiphy_set_current_dev(name))
309 return;
310
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530311 /* RGMII clk transition on data stable */
Holger Brunck7fef6552014-01-27 16:58:26 +0100312 if (miiphy_read(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG, &reg))
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530313 printf("Error reading PHY spec ctrl reg\n");
Holger Brunck7fef6552014-01-27 16:58:26 +0100314 if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG,
315 reg | PHY_RGMII_CLK_STABLE | PHY_CLSA))
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530316 printf("Error writing PHY spec ctrl reg\n");
317
318 /* leds setup */
Holger Brunck7fef6552014-01-27 16:58:26 +0100319 if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_LED_SEL_REG,
320 PHY_LED0_LINK | PHY_LED1_ACT | PHY_LED2_INT))
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530321 printf("Error writing PHY LED reg\n");
322
Heiko Schocher60301192010-02-22 16:43:02 +0530323 /* reset the phy */
324 miiphy_reset(name, CONFIG_PHY_BASE_ADR);
325}
Valentin Longchamp310164a2012-08-16 23:35:03 +0000326#elif defined(CONFIG_KM_PIGGY4_88E6352)
327
328#include <mv88e6352.h>
329
330#if defined(CONFIG_KM_NUSA)
331struct mv88e_sw_reg extsw_conf[] = {
332 /*
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +0200333 * port 0, PIGGY4, autoneg
Valentin Longchamp310164a2012-08-16 23:35:03 +0000334 * first the fix for the 1000Mbits Autoneg, this is from
335 * a Marvell errata, the regs are undocumented
336 */
337 { PHY(0), PHY_PAGE, AN1000FIX_PAGE },
338 { PHY(0), PHY_STATUS, AN1000FIX },
339 { PHY(0), PHY_PAGE, 0 },
340 /* now the real port and phy configuration */
341 { PORT(0), PORT_PHY, NO_SPEED_FOR },
342 { PORT(0), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
343 { PHY(0), PHY_1000_CTRL, NO_ADV },
344 { PHY(0), PHY_SPEC_CTRL, AUTO_MDIX_EN },
345 { PHY(0), PHY_CTRL, PHY_100_MBPS | AUTONEG_EN | AUTONEG_RST |
346 FULL_DUPLEX },
347 /* port 1, unused */
348 { PORT(1), PORT_CTRL, PORT_DIS },
349 { PHY(1), PHY_CTRL, PHY_PWR_DOWN },
350 { PHY(1), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
351 /* port 2, unused */
352 { PORT(2), PORT_CTRL, PORT_DIS },
353 { PHY(2), PHY_CTRL, PHY_PWR_DOWN },
354 { PHY(2), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
355 /* port 3, unused */
356 { PORT(3), PORT_CTRL, PORT_DIS },
357 { PHY(3), PHY_CTRL, PHY_PWR_DOWN },
358 { PHY(3), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
359 /* port 4, ICNEV, SerDes, SGMII */
360 { PORT(4), PORT_STATUS, NO_PHY_DETECT },
361 { PORT(4), PORT_PHY, SPEED_1000_FOR },
362 { PORT(4), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
363 { PHY(4), PHY_CTRL, PHY_PWR_DOWN },
364 { PHY(4), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
365 /* port 5, CPU_RGMII */
366 { PORT(5), PORT_PHY, RX_RGMII_TIM | TX_RGMII_TIM | FLOW_CTRL_EN |
367 FLOW_CTRL_FOR | LINK_VAL | LINK_FOR | FULL_DPX |
368 FULL_DPX_FOR | SPEED_1000_FOR },
369 { PORT(5), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
370 /* port 6, unused, this port has no phy */
371 { PORT(6), PORT_CTRL, PORT_DIS },
372};
373#else
374struct mv88e_sw_reg extsw_conf[] = {};
375#endif
376
377void reset_phy(void)
378{
379#if defined(CONFIG_KM_MVEXTSW_ADDR)
380 char *name = "egiga0";
381
382 if (miiphy_set_current_dev(name))
383 return;
384
385 mv88e_sw_program(name, CONFIG_KM_MVEXTSW_ADDR, extsw_conf,
386 ARRAY_SIZE(extsw_conf));
387 mv88e_sw_reset(name, CONFIG_KM_MVEXTSW_ADDR);
388#endif
389}
390
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530391#else
392/* Configure and enable MV88E1118 PHY on the piggy*/
393void reset_phy(void)
394{
Tobias Müllerb0cab2d2015-11-13 15:01:15 +0100395 unsigned int oui;
396 unsigned char model, rev;
397
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530398 char *name = "egiga0";
399
400 if (miiphy_set_current_dev(name))
401 return;
402
403 /* reset the phy */
404 miiphy_reset(name, CONFIG_PHY_BASE_ADR);
Tobias Müllerb0cab2d2015-11-13 15:01:15 +0100405
406 /* get PHY model */
407 if (miiphy_info(name, CONFIG_PHY_BASE_ADR, &oui, &model, &rev))
408 return;
409
410 /* check for Marvell 88E1118R Gigabit PHY (PIGGY3) */
Holger Brunckff41a752020-10-30 12:45:49 +0100411 if (oui == PHY_MARVELL_OUI &&
412 model == PHY_MARVELL_88E1118R_MODEL) {
Tobias Müllerb0cab2d2015-11-13 15:01:15 +0100413 /* set page register to 3 */
414 if (miiphy_write(name, CONFIG_PHY_BASE_ADR,
415 PHY_MARVELL_PAGE_REG,
416 PHY_MARVELL_88E1118R_LED_CTRL_PAGE))
417 printf("Error writing PHY page reg\n");
418
419 /*
420 * leds setup as printed on PCB:
421 * LED2 (Link): 0x0 (On Link, Off No Link)
422 * LED1 (Activity): 0x3 (On Activity, Off No Activity)
423 * LED0 (Speed): 0x7 (On 1000 MBits, Off Else)
424 */
425 if (miiphy_write(name, CONFIG_PHY_BASE_ADR,
426 PHY_MARVELL_88E1118R_LED_CTRL_REG,
427 PHY_MARVELL_88E1118R_LED_CTRL_RESERVED |
428 PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB |
429 PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT |
430 PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK))
431 printf("Error writing PHY LED reg\n");
432
433 /* set page register back to 0 */
434 if (miiphy_write(name, CONFIG_PHY_BASE_ADR,
435 PHY_MARVELL_PAGE_REG,
436 PHY_MARVELL_DEFAULT_PAGE))
437 printf("Error writing PHY page reg\n");
438 }
Valentin Longchamp3f29cbb2011-06-16 18:11:15 +0530439}
440#endif
441
Heiko Schocher60301192010-02-22 16:43:02 +0530442#if defined(CONFIG_HUSH_INIT_VAR)
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100443int hush_init_var(void)
Heiko Schocher60301192010-02-22 16:43:02 +0530444{
Valentin Longchampaea4bb52015-02-10 17:10:14 +0100445 ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
Heiko Schocher60301192010-02-22 16:43:02 +0530446 return 0;
447}
448#endif
449
Heiko Schocher479a4cf2013-01-29 08:53:15 +0100450#if defined(CONFIG_SYS_I2C_SOFT)
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100451void set_sda(int state)
Heiko Schocher60301192010-02-22 16:43:02 +0530452{
453 I2C_ACTIVE;
454 I2C_SDA(state);
455}
456
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100457void set_scl(int state)
Heiko Schocher60301192010-02-22 16:43:02 +0530458{
459 I2C_SCL(state);
460}
461
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100462int get_sda(void)
Heiko Schocher60301192010-02-22 16:43:02 +0530463{
464 I2C_TRISTATE;
465 return I2C_READ;
466}
467
Heiko Schocher8ce3dd52011-03-15 16:52:29 +0100468int get_scl(void)
Heiko Schocher60301192010-02-22 16:43:02 +0530469{
Heiko Schocher9878f992011-02-22 09:13:00 +0100470 return kw_gpio_get_value(KM_KIRKWOOD_SCL_PIN) ? 1 : 0;
Heiko Schocher60301192010-02-22 16:43:02 +0530471}
472#endif
473
Valentin Longchamp24ec9932011-09-12 04:18:42 +0000474#if defined(CONFIG_POST)
475
476#define KM_POST_EN_L 44
477#define POST_WORD_OFF 8
478
479int post_hotkeys_pressed(void)
480{
Holger Brunckff41a752020-10-30 12:45:49 +0100481 if (IS_ENABLED(CONFIG_KM_COGE5UN))
482 return kw_gpio_get_value(KM_POST_EN_L);
483 else
484 return !kw_gpio_get_value(KM_POST_EN_L);
Valentin Longchamp24ec9932011-09-12 04:18:42 +0000485}
486
487ulong post_word_load(void)
488{
Holger Brunckff41a752020-10-30 12:45:49 +0100489 void *addr = (void *)(gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
490
Valentin Longchamp24ec9932011-09-12 04:18:42 +0000491 return in_le32(addr);
492
493}
494void post_word_store(ulong value)
495{
Holger Brunckff41a752020-10-30 12:45:49 +0100496 void *addr = (void *)(gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
497
Valentin Longchamp24ec9932011-09-12 04:18:42 +0000498 out_le32(addr, value);
499}
500
501int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
502{
503 *vstart = CONFIG_SYS_SDRAM_BASE;
504
505 /* we go up to relocation plus a 1 MB margin */
Holger Brunckff41a752020-10-30 12:45:49 +0100506 *size = CONFIG_SYS_TEXT_BASE - (1 << 20);
Valentin Longchamp24ec9932011-09-12 04:18:42 +0000507
508 return 0;
509}
510#endif
511
Heiko Schocher60301192010-02-22 16:43:02 +0530512#if defined(CONFIG_SYS_EEPROM_WREN)
Holger Brunckff41a752020-10-30 12:45:49 +0100513int eeprom_write_enable(unsigned int dev_addr, int state)
Heiko Schocher60301192010-02-22 16:43:02 +0530514{
Heiko Schocher9878f992011-02-22 09:13:00 +0100515 kw_gpio_set_value(KM_KIRKWOOD_ENV_WP, !state);
Heiko Schocher60301192010-02-22 16:43:02 +0530516
Heiko Schocher9878f992011-02-22 09:13:00 +0100517 return !kw_gpio_get_value(KM_KIRKWOOD_ENV_WP);
Heiko Schocher60301192010-02-22 16:43:02 +0530518}
519#endif