1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <common.h>
15#include <env.h>
16#include <i2c.h>
17#include <init.h>
18#include <nand.h>
19#include <net.h>
20#include <netdev.h>
21#include <miiphy.h>
22#include <spi.h>
23#include <asm/global_data.h>
24#include <asm/io.h>
25#include <asm/arch/cpu.h>
26#include <asm/arch/soc.h>
27#include <asm/arch/mpp.h>
28
29#include "../common/common.h"
30
31DECLARE_GLOBAL_DATA_PTR;
32
33
34
35
36#define BOCO 0x10
37#define REG_CTRL_H 0x02
38#define MASK_WRL_UNITRUN 0x01
39#define MASK_RBX_PGY_PRESENT 0x40
40#define REG_IRQ_CIRQ2 0x2d
41#define MASK_RBI_DEFECT_16 0x01
42
43
44
45
46#define PHY_MARVELL_OUI 0x5043
47#define PHY_MARVELL_88E1118_MODEL 0x0022
48#define PHY_MARVELL_88E1118R_MODEL 0x0024
49
50#define PHY_MARVELL_PAGE_REG 0x0016
51#define PHY_MARVELL_DEFAULT_PAGE 0x0000
52
53#define PHY_MARVELL_88E1118R_LED_CTRL_PAGE 0x0003
54#define PHY_MARVELL_88E1118R_LED_CTRL_REG 0x0010
55
56#define PHY_MARVELL_88E1118R_LED_CTRL_RESERVED 0x1000
57#define PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB (0x7 << 0)
58#define PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT (0x3 << 4)
59#define PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK (0x0 << 8)
60
61
62#define KM_FLASH_ERASE_ENABLE 43
63
64
65static const u32 kwmpp_config[] = {
66 MPP0_NF_IO2,
67 MPP1_NF_IO3,
68 MPP2_NF_IO4,
69 MPP3_NF_IO5,
70 MPP4_NF_IO6,
71 MPP5_NF_IO7,
72 MPP6_SYSRST_OUTn,
73 MPP7_PEX_RST_OUTn,
74#if defined(CONFIG_SYS_I2C_SOFT)
75 MPP8_GPIO,
76 MPP9_GPIO,
77#endif
78 MPP10_UART0_TXD,
79 MPP11_UART0_RXD,
80 MPP12_GPO,
81 MPP13_UART1_TXD,
82 MPP14_UART1_RXD,
83 MPP15_GPIO,
84 MPP16_GPIO,
85 MPP17_GPIO,
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,
103 MPP35_GPIO,
104 MPP36_GPIO,
105 MPP37_GPIO,
106 MPP38_GPIO,
107 MPP39_GPIO,
108 MPP40_GPIO,
109 MPP41_GPIO,
110 MPP42_GPIO,
111 MPP43_GPIO,
112 MPP44_GPIO,
113 MPP45_GPIO,
114 MPP46_GPIO,
115 MPP47_GPIO,
116 MPP48_GPIO,
117 MPP49_GPIO,
118 0
119};
120
121static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
122
123#if (defined(CONFIG_KM_PIGGY4_88E6061)|defined(CONFIG_KM_PIGGY4_88E6352))
124
125
126
127
128int ethernet_present(void)
129{
130 return 1;
131}
132#else
133int ethernet_present(void)
134{
135 uchar buf;
136 int ret = 0;
137
138 if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
139 printf("%s: Error reading Boco\n", __func__);
140 return -1;
141 }
142 if ((buf & MASK_RBX_PGY_PRESENT) == MASK_RBX_PGY_PRESENT)
143 ret = 1;
144
145 return ret;
146}
147#endif
148
149static int initialize_unit_leds(void)
150{
151
152
153
154
155 uchar buf;
156
157 if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
158 printf("%s: Error reading Boco\n", __func__);
159 return -1;
160 }
161 buf |= MASK_WRL_UNITRUN;
162 if (i2c_write(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
163 printf("%s: Error writing Boco\n", __func__);
164 return -1;
165 }
166 return 0;
167}
168
169static void set_bootcount_addr(void)
170{
171 uchar buf[32];
172 unsigned int bootcountaddr;
173
174 bootcountaddr = gd->ram_size - BOOTCOUNT_ADDR;
175 sprintf((char *)buf, "0x%x", bootcountaddr);
176 env_set("bootcountaddr", (char *)buf);
177}
178
179int misc_init_r(void)
180{
181 ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN,
182 CONFIG_PIGGY_MAC_ADDRESS_OFFSET);
183
184 initialize_unit_leds();
185 set_km_env();
186 set_bootcount_addr();
187 return 0;
188}
189
190int board_early_init_f(void)
191{
192#if defined(CONFIG_SYS_I2C_SOFT)
193 u32 tmp;
194
195
196 tmp = readl(MVEBU_GPIO0_BASE + 4);
197 writel(tmp & (~KM_KIRKWOOD_SOFT_I2C_GPIOS), MVEBU_GPIO0_BASE + 4);
198#endif
199
200 mvebu_sdram_size_adjust(0);
201 kirkwood_mpp_conf(kwmpp_config, NULL);
202 return 0;
203}
204
205int board_init(void)
206{
207
208 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
209
210
211
212
213
214
215 kw_gpio_set_valid(KM_FLASH_GPIO_PIN, 1);
216 kw_gpio_direction_output(KM_FLASH_GPIO_PIN, 1);
217
218#if defined(CONFIG_SYS_I2C_SOFT)
219
220
221
222
223
224
225 kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
226 kw_gpio_set_valid(KM_KIRKWOOD_SCL_PIN, 1);
227#endif
228
229#if defined(CONFIG_SYS_EEPROM_WREN)
230 kw_gpio_set_valid(KM_KIRKWOOD_ENV_WP, 38);
231 kw_gpio_direction_output(KM_KIRKWOOD_ENV_WP, 1);
232#endif
233
234#if defined(CONFIG_KM_FPGA_CONFIG)
235 trigger_fpga_config();
236#endif
237
238 return 0;
239}
240
241int board_late_init(void)
242{
243#if defined(CONFIG_KM_COGE5UN)
244 u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE);
245
246
247 if (dip_switch != 0) {
248
249 puts("DIP: Enabled\n");
250 env_set("actual_bank", "0");
251 }
252#endif
253
254#if defined(CONFIG_KM_FPGA_CONFIG)
255 wait_for_fpga_config();
256 fpga_reset();
257 toggle_eeprom_spi_bus();
258#endif
259 return 0;
260}
261
262static const u32 spi_mpp_config[] = {
263 MPP1_SPI_MOSI,
264 MPP2_SPI_SCK,
265 MPP3_SPI_MISO,
266 0
267};
268
269static u32 spi_mpp_backup[4];
270
271int mvebu_board_spi_claim_bus(struct udevice *dev)
272{
273 spi_mpp_backup[3] = 0;
274
275
276 kirkwood_mpp_conf(spi_mpp_config, spi_mpp_backup);
277
278 kw_gpio_set_value(KM_FLASH_GPIO_PIN, 0);
279
280 return 0;
281}
282
283int mvebu_board_spi_release_bus(struct udevice *dev)
284{
285
286 kirkwood_mpp_conf(spi_mpp_backup, NULL);
287
288 kw_gpio_set_value(KM_FLASH_GPIO_PIN, 1);
289
290 return 0;
291}
292
293#if (defined(CONFIG_KM_PIGGY4_88E6061))
294
295#define PHY_LED_SEL_REG 0x18
296#define PHY_LED0_LINK (0x5)
297#define PHY_LED1_ACT (0x8 << 4)
298#define PHY_LED2_INT (0xe << 8)
299#define PHY_SPEC_CTRL_REG 0x1c
300#define PHY_RGMII_CLK_STABLE (0x1 << 10)
301#define PHY_CLSA (0x1 << 1)
302
303
304void reset_phy(void)
305{
306 char *name = "egiga0";
307 unsigned short reg;
308
309 if (miiphy_set_current_dev(name))
310 return;
311
312
313 if (miiphy_read(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG, ®))
314 printf("Error reading PHY spec ctrl reg\n");
315 if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG,
316 reg | PHY_RGMII_CLK_STABLE | PHY_CLSA))
317 printf("Error writing PHY spec ctrl reg\n");
318
319
320 if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_LED_SEL_REG,
321 PHY_LED0_LINK | PHY_LED1_ACT | PHY_LED2_INT))
322 printf("Error writing PHY LED reg\n");
323
324
325 miiphy_reset(name, CONFIG_PHY_BASE_ADR);
326}
327#elif defined(CONFIG_KM_PIGGY4_88E6352)
328
329#include <mv88e6352.h>
330
331#if defined(CONFIG_KM_NUSA)
332struct mv88e_sw_reg extsw_conf[] = {
333
334
335
336
337
338 { PHY(0), PHY_PAGE, AN1000FIX_PAGE },
339 { PHY(0), PHY_STATUS, AN1000FIX },
340 { PHY(0), PHY_PAGE, 0 },
341
342 { PORT(0), PORT_PHY, NO_SPEED_FOR },
343 { PORT(0), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
344 { PHY(0), PHY_1000_CTRL, NO_ADV },
345 { PHY(0), PHY_SPEC_CTRL, AUTO_MDIX_EN },
346 { PHY(0), PHY_CTRL, PHY_100_MBPS | AUTONEG_EN | AUTONEG_RST |
347 FULL_DUPLEX },
348
349 { PORT(1), PORT_CTRL, PORT_DIS },
350 { PHY(1), PHY_CTRL, PHY_PWR_DOWN },
351 { PHY(1), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
352
353 { PORT(2), PORT_CTRL, PORT_DIS },
354 { PHY(2), PHY_CTRL, PHY_PWR_DOWN },
355 { PHY(2), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
356
357 { PORT(3), PORT_CTRL, PORT_DIS },
358 { PHY(3), PHY_CTRL, PHY_PWR_DOWN },
359 { PHY(3), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
360
361 { PORT(4), PORT_STATUS, NO_PHY_DETECT },
362 { PORT(4), PORT_PHY, SPEED_1000_FOR },
363 { PORT(4), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
364 { PHY(4), PHY_CTRL, PHY_PWR_DOWN },
365 { PHY(4), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
366
367 { PORT(5), PORT_PHY, RX_RGMII_TIM | TX_RGMII_TIM | FLOW_CTRL_EN |
368 FLOW_CTRL_FOR | LINK_VAL | LINK_FOR | FULL_DPX |
369 FULL_DPX_FOR | SPEED_1000_FOR },
370 { PORT(5), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
371
372 { PORT(6), PORT_CTRL, PORT_DIS },
373};
374#else
375struct mv88e_sw_reg extsw_conf[] = {};
376#endif
377
378void reset_phy(void)
379{
380#if defined(CONFIG_KM_MVEXTSW_ADDR)
381 char *name = "egiga0";
382
383 if (miiphy_set_current_dev(name))
384 return;
385
386 mv88e_sw_program(name, CONFIG_KM_MVEXTSW_ADDR, extsw_conf,
387 ARRAY_SIZE(extsw_conf));
388 mv88e_sw_reset(name, CONFIG_KM_MVEXTSW_ADDR);
389#endif
390}
391
392#else
393
394void reset_phy(void)
395{
396 unsigned int oui;
397 unsigned char model, rev;
398
399 char *name = "egiga0";
400
401 if (miiphy_set_current_dev(name))
402 return;
403
404
405 miiphy_reset(name, CONFIG_PHY_BASE_ADR);
406
407
408 if (miiphy_info(name, CONFIG_PHY_BASE_ADR, &oui, &model, &rev))
409 return;
410
411
412 if (oui == PHY_MARVELL_OUI &&
413 model == PHY_MARVELL_88E1118R_MODEL) {
414
415 if (miiphy_write(name, CONFIG_PHY_BASE_ADR,
416 PHY_MARVELL_PAGE_REG,
417 PHY_MARVELL_88E1118R_LED_CTRL_PAGE))
418 printf("Error writing PHY page reg\n");
419
420
421
422
423
424
425
426 if (miiphy_write(name, CONFIG_PHY_BASE_ADR,
427 PHY_MARVELL_88E1118R_LED_CTRL_REG,
428 PHY_MARVELL_88E1118R_LED_CTRL_RESERVED |
429 PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB |
430 PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT |
431 PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK))
432 printf("Error writing PHY LED reg\n");
433
434
435 if (miiphy_write(name, CONFIG_PHY_BASE_ADR,
436 PHY_MARVELL_PAGE_REG,
437 PHY_MARVELL_DEFAULT_PAGE))
438 printf("Error writing PHY page reg\n");
439 }
440}
441#endif
442
443#if defined(CONFIG_HUSH_INIT_VAR)
444int hush_init_var(void)
445{
446 ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
447 return 0;
448}
449#endif
450
451#if defined(CONFIG_SYS_I2C_SOFT)
452void set_sda(int state)
453{
454 I2C_ACTIVE;
455 I2C_SDA(state);
456}
457
458void set_scl(int state)
459{
460 I2C_SCL(state);
461}
462
463int get_sda(void)
464{
465 I2C_TRISTATE;
466 return I2C_READ;
467}
468
469int get_scl(void)
470{
471 return kw_gpio_get_value(KM_KIRKWOOD_SCL_PIN) ? 1 : 0;
472}
473#endif
474
475#if defined(CONFIG_POST)
476
477#define KM_POST_EN_L 44
478#define POST_WORD_OFF 8
479
480int post_hotkeys_pressed(void)
481{
482 if (IS_ENABLED(CONFIG_KM_COGE5UN))
483 return kw_gpio_get_value(KM_POST_EN_L);
484 else
485 return !kw_gpio_get_value(KM_POST_EN_L);
486}
487
488ulong post_word_load(void)
489{
490 void *addr = (void *)(gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
491
492 return in_le32(addr);
493
494}
495void post_word_store(ulong value)
496{
497 void *addr = (void *)(gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
498
499 out_le32(addr, value);
500}
501
502int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
503{
504 *vstart = CONFIG_SYS_SDRAM_BASE;
505
506
507 *size = CONFIG_SYS_TEXT_BASE - (1 << 20);
508
509 return 0;
510}
511#endif
512
513#if defined(CONFIG_SYS_EEPROM_WREN)
514int eeprom_write_enable(unsigned int dev_addr, int state)
515{
516 kw_gpio_set_value(KM_KIRKWOOD_ENV_WP, !state);
517
518 return !kw_gpio_get_value(KM_KIRKWOOD_ENV_WP);
519}
520#endif
521