blob: 532d06f00031fc15177d12db4305b3bb91f7639e [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 CLEMENT2f8d0672019-01-17 17:07:14 +010013#include <wait_bit.h>
Gregory CLEMENT6787c1e2018-12-14 16:16:49 +010014
15DECLARE_GLOBAL_DATA_PTR;
16
Lars Povlsene9f14922018-12-20 09:56:05 +010017enum {
18 BOARD_TYPE_PCB120 = 0xAABBCC00,
19 BOARD_TYPE_PCB123,
20};
Gregory CLEMENT6787c1e2018-12-14 16:16:49 +010021
Gregory CLEMENT2f8d0672019-01-17 17:07:14 +010022void mscc_switch_reset(bool enter)
23{
24 /* Nasty workaround to avoid GPIO19 (DDR!) being reset */
25 mscc_gpio_set_alternate(19, 2);
26
27 debug("applying SwC reset\n");
28
29 writel(ICPU_RESET_CORE_RST_PROTECT, BASE_CFG + ICPU_RESET);
30 writel(PERF_SOFT_RST_SOFT_CHIP_RST, BASE_DEVCPU_GCB + PERF_SOFT_RST);
31
32 if (wait_for_bit_le32(BASE_DEVCPU_GCB + PERF_SOFT_RST,
33 PERF_SOFT_RST_SOFT_CHIP_RST, false, 5000, false))
34 pr_err("Tiemout while waiting for switch reset\n");
35
36 /*
37 * Reset GPIO19 mode back as regular GPIO, output, high (DDR
38 * not reset) (Order is important)
39 */
40 setbits_le32(BASE_DEVCPU_GCB + PERF_GPIO_OE, BIT(19));
41 writel(BIT(19), BASE_DEVCPU_GCB + PERF_GPIO_OUT_SET);
42 mscc_gpio_set_alternate(19, 0);
43}
44
Gregory CLEMENT6787c1e2018-12-14 16:16:49 +010045void board_debug_uart_init(void)
46{
47 /* too early for the pinctrl driver, so configure the UART pins here */
Lars Povlsene9f14922018-12-20 09:56:05 +010048 mscc_gpio_set_alternate(6, 1);
49 mscc_gpio_set_alternate(7, 1);
Gregory CLEMENT6787c1e2018-12-14 16:16:49 +010050}
51
52int board_early_init_r(void)
53{
54 /* Prepare SPI controller to be used in master mode */
55 writel(0, BASE_CFG + ICPU_SW_MODE);
56 clrsetbits_le32(BASE_CFG + ICPU_GENERAL_CTRL,
57 ICPU_GENERAL_CTRL_IF_SI_OWNER_M,
58 ICPU_GENERAL_CTRL_IF_SI_OWNER(2));
59
60 /* Address of boot parameters */
61 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE;
Lars Povlsen4deb0962019-01-02 09:52:26 +010062
63 /* LED setup */
64 if (IS_ENABLED(CONFIG_LED))
65 led_default_state();
66
Gregory CLEMENT6787c1e2018-12-14 16:16:49 +010067 return 0;
68}
Lars Povlsene9f14922018-12-20 09:56:05 +010069
70static void do_board_detect(void)
71{
72 u16 dummy = 0;
73
74 /* Enable MIIM */
75 mscc_gpio_set_alternate(14, 1);
76 mscc_gpio_set_alternate(15, 1);
77 if (mscc_phy_rd(1, 0, 0, &dummy) == 0)
78 gd->board_type = BOARD_TYPE_PCB120;
79 else
80 gd->board_type = BOARD_TYPE_PCB123;
81}
82
83#if defined(CONFIG_MULTI_DTB_FIT)
84int board_fit_config_name_match(const char *name)
85{
86 if (gd->board_type == BOARD_TYPE_PCB120 &&
87 strcmp(name, "ocelot_pcb120") == 0)
88 return 0;
89
90 if (gd->board_type == BOARD_TYPE_PCB123 &&
91 strcmp(name, "ocelot_pcb123") == 0)
92 return 0;
93
94 return -1;
95}
96#endif
97
98#if defined(CONFIG_DTB_RESELECT)
99int embedded_dtb_select(void)
100{
101 do_board_detect();
102 fdtdec_setup();
103
104 return 0;
105}
106#endif