blob: da7f55620debec24178a77bd12829cdfb9af01cc [file] [log] [blame]
Horatiu Vultura834cb82019-01-23 16:39:45 +01001// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2/*
3 * Copyright (c) 2018 Microsemi Corporation
4 */
5
6#include <common.h>
7#include <asm/io.h>
8#include <led.h>
Horatiu Vulturd2691b42019-04-11 14:11:33 +02009#include <miiphy.h>
Horatiu Vultura834cb82019-01-23 16:39:45 +010010
11enum {
12 BOARD_TYPE_PCB106 = 0xAABBCD00,
13 BOARD_TYPE_PCB105,
14};
15
16int board_early_init_r(void)
17{
18 /* Prepare SPI controller to be used in master mode */
19 writel(0, BASE_CFG + ICPU_SW_MODE);
20
21 /* Address of boot parameters */
22 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE;
23
24 /* LED setup */
25 if (IS_ENABLED(CONFIG_LED))
26 led_default_state();
27
28 return 0;
29}
30
Horatiu Vulturd2691b42019-04-11 14:11:33 +020031int board_phy_config(struct phy_device *phydev)
32{
33 phy_write(phydev, 0, 31, 0x10);
34 phy_write(phydev, 0, 18, 0x80F0);
35 while (phy_read(phydev, 0, 18) & 0x8000)
36 ;
37 phy_write(phydev, 0, 14, 0x800);
38 phy_write(phydev, 0, 31, 0);
39 return 0;
40}
41
Horatiu Vultura834cb82019-01-23 16:39:45 +010042static void do_board_detect(void)
43{
44 u16 gpio_in_reg;
45
46 /* Set MDIO and MDC */
47 mscc_gpio_set_alternate(9, 2);
48 mscc_gpio_set_alternate(10, 2);
49
50 /* Set GPIO page */
51 mscc_phy_wr(1, 16, 31, 0x10);
52 if (!mscc_phy_rd(1, 16, 15, &gpio_in_reg)) {
53 if (gpio_in_reg & 0x200)
54 gd->board_type = BOARD_TYPE_PCB106;
55 else
56 gd->board_type = BOARD_TYPE_PCB105;
Horatiu Vultura834cb82019-01-23 16:39:45 +010057 } else {
58 gd->board_type = BOARD_TYPE_PCB105;
59 }
Horatiu Vulturc6b2e712019-04-15 11:56:37 +020060 mscc_phy_wr(1, 16, 31, 0x0);
Horatiu Vultura834cb82019-01-23 16:39:45 +010061}
62
63#if defined(CONFIG_MULTI_DTB_FIT)
64int board_fit_config_name_match(const char *name)
65{
66 if (gd->board_type == BOARD_TYPE_PCB106 &&
67 strcmp(name, "serval_pcb106") == 0)
68 return 0;
69
70 if (gd->board_type == BOARD_TYPE_PCB105 &&
71 strcmp(name, "serval_pcb105") == 0)
72 return 0;
73
74 return -1;
75}
76#endif
77
78#if defined(CONFIG_DTB_RESELECT)
79int embedded_dtb_select(void)
80{
81 do_board_detect();
82 fdtdec_setup();
83
84 return 0;
85}
86#endif