Gregory CLEMENT | 6787c1e | 2018-12-14 16:16:49 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0+ OR MIT) |
| 2 | /* |
| 3 | * Copyright (c) 2018 Microsemi Corporation |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 7 | #include <image.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Gregory CLEMENT | 6787c1e | 2018-12-14 16:16:49 +0100 | [diff] [blame] | 11 | #include <asm/io.h> |
| 12 | #include <asm/addrspace.h> |
| 13 | #include <asm/types.h> |
Gregory CLEMENT | 6787c1e | 2018-12-14 16:16:49 +0100 | [diff] [blame] | 14 | #include <spi.h> |
Lars Povlsen | 4deb096 | 2019-01-02 09:52:26 +0100 | [diff] [blame] | 15 | #include <led.h> |
Gregory CLEMENT | 2f8d067 | 2019-01-17 17:07:14 +0100 | [diff] [blame] | 16 | #include <wait_bit.h> |
Horatiu Vultur | 06d270c | 2019-04-24 11:27:58 +0200 | [diff] [blame] | 17 | #include <miiphy.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 18 | #include <linux/bitops.h> |
Simon Glass | 1e94b46 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 19 | #include <linux/printk.h> |
Gregory CLEMENT | 6787c1e | 2018-12-14 16:16:49 +0100 | [diff] [blame] | 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Lars Povlsen | e9f1492 | 2018-12-20 09:56:05 +0100 | [diff] [blame] | 23 | enum { |
| 24 | BOARD_TYPE_PCB120 = 0xAABBCC00, |
| 25 | BOARD_TYPE_PCB123, |
| 26 | }; |
Gregory CLEMENT | 6787c1e | 2018-12-14 16:16:49 +0100 | [diff] [blame] | 27 | |
Gregory CLEMENT | 2f8d067 | 2019-01-17 17:07:14 +0100 | [diff] [blame] | 28 | void mscc_switch_reset(bool enter) |
| 29 | { |
| 30 | /* Nasty workaround to avoid GPIO19 (DDR!) being reset */ |
| 31 | mscc_gpio_set_alternate(19, 2); |
| 32 | |
| 33 | debug("applying SwC reset\n"); |
| 34 | |
| 35 | writel(ICPU_RESET_CORE_RST_PROTECT, BASE_CFG + ICPU_RESET); |
| 36 | writel(PERF_SOFT_RST_SOFT_CHIP_RST, BASE_DEVCPU_GCB + PERF_SOFT_RST); |
| 37 | |
| 38 | if (wait_for_bit_le32(BASE_DEVCPU_GCB + PERF_SOFT_RST, |
| 39 | PERF_SOFT_RST_SOFT_CHIP_RST, false, 5000, false)) |
| 40 | pr_err("Tiemout while waiting for switch reset\n"); |
| 41 | |
| 42 | /* |
| 43 | * Reset GPIO19 mode back as regular GPIO, output, high (DDR |
| 44 | * not reset) (Order is important) |
| 45 | */ |
| 46 | setbits_le32(BASE_DEVCPU_GCB + PERF_GPIO_OE, BIT(19)); |
| 47 | writel(BIT(19), BASE_DEVCPU_GCB + PERF_GPIO_OUT_SET); |
| 48 | mscc_gpio_set_alternate(19, 0); |
| 49 | } |
| 50 | |
Horatiu Vultur | 06d270c | 2019-04-24 11:27:58 +0200 | [diff] [blame] | 51 | int board_phy_config(struct phy_device *phydev) |
| 52 | { |
| 53 | if (gd->board_type == BOARD_TYPE_PCB123) |
| 54 | return 0; |
| 55 | |
| 56 | phy_write(phydev, 0, 31, 0x10); |
| 57 | phy_write(phydev, 0, 18, 0x80F0); |
| 58 | while (phy_read(phydev, 0, 18) & 0x8000) |
| 59 | ; |
| 60 | phy_write(phydev, 0, 31, 0); |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
Gregory CLEMENT | 6787c1e | 2018-12-14 16:16:49 +0100 | [diff] [blame] | 65 | void board_debug_uart_init(void) |
| 66 | { |
| 67 | /* too early for the pinctrl driver, so configure the UART pins here */ |
Lars Povlsen | e9f1492 | 2018-12-20 09:56:05 +0100 | [diff] [blame] | 68 | mscc_gpio_set_alternate(6, 1); |
| 69 | mscc_gpio_set_alternate(7, 1); |
Gregory CLEMENT | 6787c1e | 2018-12-14 16:16:49 +0100 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | int board_early_init_r(void) |
| 73 | { |
| 74 | /* Prepare SPI controller to be used in master mode */ |
| 75 | writel(0, BASE_CFG + ICPU_SW_MODE); |
| 76 | clrsetbits_le32(BASE_CFG + ICPU_GENERAL_CTRL, |
| 77 | ICPU_GENERAL_CTRL_IF_SI_OWNER_M, |
| 78 | ICPU_GENERAL_CTRL_IF_SI_OWNER(2)); |
| 79 | |
| 80 | /* Address of boot parameters */ |
Tom Rini | aa6e94d | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 81 | gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE; |
Lars Povlsen | 4deb096 | 2019-01-02 09:52:26 +0100 | [diff] [blame] | 82 | |
Gregory CLEMENT | 6787c1e | 2018-12-14 16:16:49 +0100 | [diff] [blame] | 83 | return 0; |
| 84 | } |
Lars Povlsen | e9f1492 | 2018-12-20 09:56:05 +0100 | [diff] [blame] | 85 | |
| 86 | static void do_board_detect(void) |
| 87 | { |
| 88 | u16 dummy = 0; |
| 89 | |
| 90 | /* Enable MIIM */ |
| 91 | mscc_gpio_set_alternate(14, 1); |
| 92 | mscc_gpio_set_alternate(15, 1); |
| 93 | if (mscc_phy_rd(1, 0, 0, &dummy) == 0) |
| 94 | gd->board_type = BOARD_TYPE_PCB120; |
| 95 | else |
| 96 | gd->board_type = BOARD_TYPE_PCB123; |
| 97 | } |
| 98 | |
| 99 | #if defined(CONFIG_MULTI_DTB_FIT) |
| 100 | int board_fit_config_name_match(const char *name) |
| 101 | { |
| 102 | if (gd->board_type == BOARD_TYPE_PCB120 && |
| 103 | strcmp(name, "ocelot_pcb120") == 0) |
| 104 | return 0; |
| 105 | |
| 106 | if (gd->board_type == BOARD_TYPE_PCB123 && |
| 107 | strcmp(name, "ocelot_pcb123") == 0) |
| 108 | return 0; |
| 109 | |
| 110 | return -1; |
| 111 | } |
| 112 | #endif |
| 113 | |
| 114 | #if defined(CONFIG_DTB_RESELECT) |
| 115 | int embedded_dtb_select(void) |
| 116 | { |
| 117 | do_board_detect(); |
| 118 | fdtdec_setup(); |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | #endif |