blob: 6c6dbf2bfffddd03f7453e6a5632f240e91f8de2 [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>
Simon Glass52559322019-11-14 12:57:46 -07007#include <init.h>
Horatiu Vultura834cb82019-01-23 16:39:45 +01008#include <asm/io.h>
9#include <led.h>
Horatiu Vulturd2691b42019-04-11 14:11:33 +020010#include <miiphy.h>
Horatiu Vultura834cb82019-01-23 16:39:45 +010011
12enum {
13 BOARD_TYPE_PCB106 = 0xAABBCD00,
14 BOARD_TYPE_PCB105,
15};
16
17int board_early_init_r(void)
18{
19 /* Prepare SPI controller to be used in master mode */
20 writel(0, BASE_CFG + ICPU_SW_MODE);
21
22 /* Address of boot parameters */
23 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE;
24
25 /* LED setup */
26 if (IS_ENABLED(CONFIG_LED))
27 led_default_state();
28
29 return 0;
30}
31
Horatiu Vulturd2691b42019-04-11 14:11:33 +020032int board_phy_config(struct phy_device *phydev)
33{
34 phy_write(phydev, 0, 31, 0x10);
35 phy_write(phydev, 0, 18, 0x80F0);
36 while (phy_read(phydev, 0, 18) & 0x8000)
37 ;
38 phy_write(phydev, 0, 14, 0x800);
39 phy_write(phydev, 0, 31, 0);
40 return 0;
41}
42
Horatiu Vultura834cb82019-01-23 16:39:45 +010043static void do_board_detect(void)
44{
45 u16 gpio_in_reg;
46
47 /* Set MDIO and MDC */
48 mscc_gpio_set_alternate(9, 2);
49 mscc_gpio_set_alternate(10, 2);
50
51 /* Set GPIO page */
52 mscc_phy_wr(1, 16, 31, 0x10);
53 if (!mscc_phy_rd(1, 16, 15, &gpio_in_reg)) {
54 if (gpio_in_reg & 0x200)
55 gd->board_type = BOARD_TYPE_PCB106;
56 else
57 gd->board_type = BOARD_TYPE_PCB105;
Horatiu Vultura834cb82019-01-23 16:39:45 +010058 } else {
59 gd->board_type = BOARD_TYPE_PCB105;
60 }
Horatiu Vulturc6b2e712019-04-15 11:56:37 +020061 mscc_phy_wr(1, 16, 31, 0x0);
Horatiu Vultura834cb82019-01-23 16:39:45 +010062}
63
64#if defined(CONFIG_MULTI_DTB_FIT)
65int board_fit_config_name_match(const char *name)
66{
67 if (gd->board_type == BOARD_TYPE_PCB106 &&
68 strcmp(name, "serval_pcb106") == 0)
69 return 0;
70
71 if (gd->board_type == BOARD_TYPE_PCB105 &&
72 strcmp(name, "serval_pcb105") == 0)
73 return 0;
74
75 return -1;
76}
77#endif
78
79#if defined(CONFIG_DTB_RESELECT)
80int embedded_dtb_select(void)
81{
82 do_board_detect();
83 fdtdec_setup();
84
85 return 0;
86}
87#endif