blob: ed1aea55cc2fbeaef8747ae02c3c1e7037e7c902 [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 Glass4d72caa2020-05-10 11:40:01 -06007#include <image.h>
Simon Glass52559322019-11-14 12:57:46 -07008#include <init.h>
Horatiu Vultura834cb82019-01-23 16:39:45 +01009#include <asm/io.h>
10#include <led.h>
Horatiu Vulturd2691b42019-04-11 14:11:33 +020011#include <miiphy.h>
Horatiu Vultura834cb82019-01-23 16:39:45 +010012
13enum {
14 BOARD_TYPE_PCB106 = 0xAABBCD00,
15 BOARD_TYPE_PCB105,
16};
17
18int 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
Horatiu Vulturd2691b42019-04-11 14:11:33 +020033int 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
Horatiu Vultura834cb82019-01-23 16:39:45 +010044static 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;
Horatiu Vultura834cb82019-01-23 16:39:45 +010059 } else {
60 gd->board_type = BOARD_TYPE_PCB105;
61 }
Horatiu Vulturc6b2e712019-04-15 11:56:37 +020062 mscc_phy_wr(1, 16, 31, 0x0);
Horatiu Vultura834cb82019-01-23 16:39:45 +010063}
64
65#if defined(CONFIG_MULTI_DTB_FIT)
66int 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)
81int embedded_dtb_select(void)
82{
83 do_board_detect();
84 fdtdec_setup();
85
86 return 0;
87}
88#endif