1 // SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2 /*
3 * Copyright (c) 2018 Microsemi Corporation
4 */
5
6 #include <common.h>
7 #include <init.h>
8 #include <asm/io.h>
9 #include <led.h>
10 #include <miiphy.h>
11
12 enum {
13 BOARD_TYPE_PCB106 = 0xAABBCD00,
14 BOARD_TYPE_PCB105,
15 };
16
board_early_init_r(void)17 int 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
board_phy_config(struct phy_device * phydev)32 int 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
do_board_detect(void)43 static 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;
58 } else {
59 gd->board_type = BOARD_TYPE_PCB105;
60 }
61 mscc_phy_wr(1, 16, 31, 0x0);
62 }
63
64 #if defined(CONFIG_MULTI_DTB_FIT)
board_fit_config_name_match(const char * name)65 int 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)
embedded_dtb_select(void)80 int embedded_dtb_select(void)
81 {
82 do_board_detect();
83 fdtdec_setup();
84
85 return 0;
86 }
87 #endif
88