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