blob: 94c1c42b79b2c6199573ef03db8b73cd4da6a2e4 [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
27 /* LED setup */
28 if (IS_ENABLED(CONFIG_LED))
29 led_default_state();
30
31 return 0;
32}
33
Horatiu Vulturd2691b42019-04-11 14:11:33 +020034int 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
Horatiu Vultura834cb82019-01-23 16:39:45 +010045static 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;
Horatiu Vultura834cb82019-01-23 16:39:45 +010060 } else {
61 gd->board_type = BOARD_TYPE_PCB105;
62 }
Horatiu Vulturc6b2e712019-04-15 11:56:37 +020063 mscc_phy_wr(1, 16, 31, 0x0);
Horatiu Vultura834cb82019-01-23 16:39:45 +010064}
65
66#if defined(CONFIG_MULTI_DTB_FIT)
67int 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)
82int embedded_dtb_select(void)
83{
84 do_board_detect();
85 fdtdec_setup();
86
87 return 0;
88}
89#endif