MSCC: Add board support for Serval SoC family.
[oweals/u-boot.git] / board / mscc / serval / serval.c
1 // 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>
9
10 enum {
11         BOARD_TYPE_PCB106 = 0xAABBCD00,
12         BOARD_TYPE_PCB105,
13 };
14
15 int board_early_init_r(void)
16 {
17         /* Prepare SPI controller to be used in master mode */
18         writel(0, BASE_CFG + ICPU_SW_MODE);
19
20         /* Address of boot parameters */
21         gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE;
22
23         /* LED setup */
24         if (IS_ENABLED(CONFIG_LED))
25                 led_default_state();
26
27         return 0;
28 }
29
30 static void do_board_detect(void)
31 {
32         u16 gpio_in_reg;
33
34         /* Set MDIO and MDC */
35         mscc_gpio_set_alternate(9, 2);
36         mscc_gpio_set_alternate(10, 2);
37
38         /* Set GPIO page */
39         mscc_phy_wr(1, 16, 31, 0x10);
40         if (!mscc_phy_rd(1, 16, 15, &gpio_in_reg)) {
41                 if (gpio_in_reg & 0x200)
42                         gd->board_type = BOARD_TYPE_PCB106;
43                 else
44                         gd->board_type = BOARD_TYPE_PCB105;
45                 mscc_phy_wr(1, 16, 15, 0);
46         } else {
47                 gd->board_type = BOARD_TYPE_PCB105;
48         }
49 }
50
51 #if defined(CONFIG_MULTI_DTB_FIT)
52 int board_fit_config_name_match(const char *name)
53 {
54         if (gd->board_type == BOARD_TYPE_PCB106 &&
55             strcmp(name, "serval_pcb106") == 0)
56                 return 0;
57
58         if (gd->board_type == BOARD_TYPE_PCB105 &&
59             strcmp(name, "serval_pcb105") == 0)
60                 return 0;
61
62         return -1;
63 }
64 #endif
65
66 #if defined(CONFIG_DTB_RESELECT)
67 int embedded_dtb_select(void)
68 {
69         do_board_detect();
70         fdtdec_setup();
71
72         return 0;
73 }
74 #endif