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