blob: 87e79076574fabea572eadbbfd4305ef6b4e4f45 [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>
Simon Glass401d1c42020-10-30 21:38:53 -06009#include <asm/global_data.h>
Horatiu Vultura834cb82019-01-23 16:39:45 +010010#include <asm/io.h>
11#include <led.h>
Horatiu Vulturd2691b42019-04-11 14:11:33 +020012#include <miiphy.h>
Horatiu Vultura834cb82019-01-23 16:39:45 +010013
14enum {
15 BOARD_TYPE_PCB106 = 0xAABBCD00,
16 BOARD_TYPE_PCB105,
17};
18
19int 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
Horatiu Vultura834cb82019-01-23 16:39:45 +010027 return 0;
28}
29
Horatiu Vulturd2691b42019-04-11 14:11:33 +020030int board_phy_config(struct phy_device *phydev)
31{
32 phy_write(phydev, 0, 31, 0x10);
33 phy_write(phydev, 0, 18, 0x80F0);
34 while (phy_read(phydev, 0, 18) & 0x8000)
35 ;
36 phy_write(phydev, 0, 14, 0x800);
37 phy_write(phydev, 0, 31, 0);
38 return 0;
39}
40
Horatiu Vultura834cb82019-01-23 16:39:45 +010041static void do_board_detect(void)
42{
43 u16 gpio_in_reg;
44
45 /* Set MDIO and MDC */
46 mscc_gpio_set_alternate(9, 2);
47 mscc_gpio_set_alternate(10, 2);
48
49 /* Set GPIO page */
50 mscc_phy_wr(1, 16, 31, 0x10);
51 if (!mscc_phy_rd(1, 16, 15, &gpio_in_reg)) {
52 if (gpio_in_reg & 0x200)
53 gd->board_type = BOARD_TYPE_PCB106;
54 else
55 gd->board_type = BOARD_TYPE_PCB105;
Horatiu Vultura834cb82019-01-23 16:39:45 +010056 } else {
57 gd->board_type = BOARD_TYPE_PCB105;
58 }
Horatiu Vulturc6b2e712019-04-15 11:56:37 +020059 mscc_phy_wr(1, 16, 31, 0x0);
Horatiu Vultura834cb82019-01-23 16:39:45 +010060}
61
62#if defined(CONFIG_MULTI_DTB_FIT)
63int board_fit_config_name_match(const char *name)
64{
65 if (gd->board_type == BOARD_TYPE_PCB106 &&
66 strcmp(name, "serval_pcb106") == 0)
67 return 0;
68
69 if (gd->board_type == BOARD_TYPE_PCB105 &&
70 strcmp(name, "serval_pcb105") == 0)
71 return 0;
72
73 return -1;
74}
75#endif
76
77#if defined(CONFIG_DTB_RESELECT)
78int embedded_dtb_select(void)
79{
80 do_board_detect();
81 fdtdec_setup();
82
83 return 0;
84}
85#endif