summaryrefslogtreecommitdiff
path: root/board/mscc/serval/serval.c
blob: 24ee5e528d9f9de85da837ba799e6e3cc552b168 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2018 Microsemi Corporation
 */

#include <common.h>
#include <asm/io.h>
#include <led.h>

enum {
	BOARD_TYPE_PCB106 = 0xAABBCD00,
	BOARD_TYPE_PCB105,
};

int board_early_init_r(void)
{
	/* Prepare SPI controller to be used in master mode */
	writel(0, BASE_CFG + ICPU_SW_MODE);

	/* Address of boot parameters */
	gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE;

	/* LED setup */
	if (IS_ENABLED(CONFIG_LED))
		led_default_state();

	return 0;
}

static void do_board_detect(void)
{
	u16 gpio_in_reg;

	/* Set MDIO and MDC */
	mscc_gpio_set_alternate(9, 2);
	mscc_gpio_set_alternate(10, 2);

	/* Set GPIO page */
	mscc_phy_wr(1, 16, 31, 0x10);
	if (!mscc_phy_rd(1, 16, 15, &gpio_in_reg)) {
		if (gpio_in_reg & 0x200)
			gd->board_type = BOARD_TYPE_PCB106;
		else
			gd->board_type = BOARD_TYPE_PCB105;
		mscc_phy_wr(1, 16, 15, 0);
	} else {
		gd->board_type = BOARD_TYPE_PCB105;
	}
}

#if defined(CONFIG_MULTI_DTB_FIT)
int board_fit_config_name_match(const char *name)
{
	if (gd->board_type == BOARD_TYPE_PCB106 &&
	    strcmp(name, "serval_pcb106") == 0)
		return 0;

	if (gd->board_type == BOARD_TYPE_PCB105 &&
	    strcmp(name, "serval_pcb105") == 0)
		return 0;

	return -1;
}
#endif

#if defined(CONFIG_DTB_RESELECT)
int embedded_dtb_select(void)
{
	do_board_detect();
	fdtdec_setup();

	return 0;
}
#endif