blob: 0f7a532158ecd11669c5c077791266bc2b2485dc [file] [log] [blame]
Gregory CLEMENT6787c1e2018-12-14 16:16:49 +01001// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2/*
3 * Copyright (c) 2018 Microsemi Corporation
4 */
5
6#include <common.h>
7#include <asm/io.h>
8#include <asm/addrspace.h>
9#include <asm/types.h>
10#include <environment.h>
11#include <spi.h>
Lars Povlsen4deb0962019-01-02 09:52:26 +010012#include <led.h>
Gregory CLEMENT6787c1e2018-12-14 16:16:49 +010013
14DECLARE_GLOBAL_DATA_PTR;
15
Lars Povlsene9f14922018-12-20 09:56:05 +010016enum {
17 BOARD_TYPE_PCB120 = 0xAABBCC00,
18 BOARD_TYPE_PCB123,
19};
Gregory CLEMENT6787c1e2018-12-14 16:16:49 +010020
Gregory CLEMENT6787c1e2018-12-14 16:16:49 +010021void board_debug_uart_init(void)
22{
23 /* too early for the pinctrl driver, so configure the UART pins here */
Lars Povlsene9f14922018-12-20 09:56:05 +010024 mscc_gpio_set_alternate(6, 1);
25 mscc_gpio_set_alternate(7, 1);
Gregory CLEMENT6787c1e2018-12-14 16:16:49 +010026}
27
28int board_early_init_r(void)
29{
30 /* Prepare SPI controller to be used in master mode */
31 writel(0, BASE_CFG + ICPU_SW_MODE);
32 clrsetbits_le32(BASE_CFG + ICPU_GENERAL_CTRL,
33 ICPU_GENERAL_CTRL_IF_SI_OWNER_M,
34 ICPU_GENERAL_CTRL_IF_SI_OWNER(2));
35
36 /* Address of boot parameters */
37 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE;
Lars Povlsen4deb0962019-01-02 09:52:26 +010038
39 /* LED setup */
40 if (IS_ENABLED(CONFIG_LED))
41 led_default_state();
42
Gregory CLEMENT6787c1e2018-12-14 16:16:49 +010043 return 0;
44}
Lars Povlsene9f14922018-12-20 09:56:05 +010045
46static void do_board_detect(void)
47{
48 u16 dummy = 0;
49
50 /* Enable MIIM */
51 mscc_gpio_set_alternate(14, 1);
52 mscc_gpio_set_alternate(15, 1);
53 if (mscc_phy_rd(1, 0, 0, &dummy) == 0)
54 gd->board_type = BOARD_TYPE_PCB120;
55 else
56 gd->board_type = BOARD_TYPE_PCB123;
57}
58
59#if defined(CONFIG_MULTI_DTB_FIT)
60int board_fit_config_name_match(const char *name)
61{
62 if (gd->board_type == BOARD_TYPE_PCB120 &&
63 strcmp(name, "ocelot_pcb120") == 0)
64 return 0;
65
66 if (gd->board_type == BOARD_TYPE_PCB123 &&
67 strcmp(name, "ocelot_pcb123") == 0)
68 return 0;
69
70 return -1;
71}
72#endif
73
74#if defined(CONFIG_DTB_RESELECT)
75int embedded_dtb_select(void)
76{
77 do_board_detect();
78 fdtdec_setup();
79
80 return 0;
81}
82#endif