Horatiu Vultur | c75c908 | 2019-01-12 18:57:00 +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> |
Horatiu Vultur | c75c908 | 2019-01-12 18:57:00 +0100 | [diff] [blame] | 9 | #include <asm/io.h> |
| 10 | #include <led.h> |
Horatiu Vultur | 6aa50ae | 2019-04-03 19:54:46 +0200 | [diff] [blame] | 11 | #include <miiphy.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 12 | #include <linux/bitops.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 13 | #include <linux/delay.h> |
Horatiu Vultur | c75c908 | 2019-01-12 18:57:00 +0100 | [diff] [blame] | 14 | |
| 15 | enum { |
| 16 | BOARD_TYPE_PCB110 = 0xAABBCE00, |
| 17 | BOARD_TYPE_PCB111, |
| 18 | BOARD_TYPE_PCB112, |
| 19 | }; |
| 20 | |
| 21 | int board_early_init_r(void) |
| 22 | { |
| 23 | /* Prepare SPI controller to be used in master mode */ |
| 24 | writel(0, BASE_CFG + ICPU_SW_MODE); |
| 25 | clrsetbits_le32(BASE_CFG + ICPU_GENERAL_CTRL, |
| 26 | ICPU_GENERAL_CTRL_IF_SI_OWNER_M, |
| 27 | ICPU_GENERAL_CTRL_IF_SI_OWNER(2)); |
| 28 | |
| 29 | /* Address of boot parameters */ |
| 30 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE; |
| 31 | |
| 32 | /* LED setup */ |
| 33 | if (IS_ENABLED(CONFIG_LED)) |
| 34 | led_default_state(); |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | static void vcoreiii_gpio_set_alternate(int gpio, int mode) |
| 40 | { |
| 41 | u32 mask; |
| 42 | u32 val0, val1; |
| 43 | void __iomem *reg0, *reg1; |
| 44 | |
| 45 | if (gpio < 32) { |
| 46 | mask = BIT(gpio); |
| 47 | reg0 = BASE_DEVCPU_GCB + GPIO_GPIO_ALT(0); |
| 48 | reg1 = BASE_DEVCPU_GCB + GPIO_GPIO_ALT(1); |
| 49 | } else { |
| 50 | gpio -= 32; |
| 51 | mask = BIT(gpio); |
| 52 | reg0 = BASE_DEVCPU_GCB + GPIO_GPIO_ALT1(0); |
| 53 | reg1 = BASE_DEVCPU_GCB + GPIO_GPIO_ALT1(1); |
| 54 | } |
| 55 | val0 = readl(reg0); |
| 56 | val1 = readl(reg1); |
| 57 | if (mode == 1) { |
| 58 | writel(val0 | mask, reg0); |
| 59 | writel(val1 & ~mask, reg1); |
| 60 | } else if (mode == 2) { |
| 61 | writel(val0 & ~mask, reg0); |
| 62 | writel(val1 | mask, reg1); |
| 63 | } else if (mode == 3) { |
| 64 | writel(val0 | mask, reg0); |
| 65 | writel(val1 | mask, reg1); |
| 66 | } else { |
| 67 | writel(val0 & ~mask, reg0); |
| 68 | writel(val1 & ~mask, reg1); |
| 69 | } |
| 70 | } |
| 71 | |
Horatiu Vultur | 6aa50ae | 2019-04-03 19:54:46 +0200 | [diff] [blame] | 72 | int board_phy_config(struct phy_device *phydev) |
| 73 | { |
| 74 | if (gd->board_type == BOARD_TYPE_PCB110 || |
| 75 | gd->board_type == BOARD_TYPE_PCB112) { |
| 76 | phy_write(phydev, 0, 31, 0x10); |
| 77 | phy_write(phydev, 0, 18, 0x80F0); |
| 78 | while (phy_read(phydev, 0, 18) & 0x8000) |
| 79 | ; |
| 80 | phy_write(phydev, 0, 31, 0); |
| 81 | } |
| 82 | if (gd->board_type == BOARD_TYPE_PCB111) { |
| 83 | phy_write(phydev, 0, 31, 0x10); |
| 84 | phy_write(phydev, 0, 18, 0x80A0); |
| 85 | while (phy_read(phydev, 0, 18) & 0x8000) |
| 86 | ; |
| 87 | phy_write(phydev, 0, 14, 0x800); |
| 88 | phy_write(phydev, 0, 31, 0); |
| 89 | } |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Horatiu Vultur | 45988b1 | 2019-01-29 10:50:16 +0100 | [diff] [blame] | 94 | void board_debug_uart_init(void) |
| 95 | { |
| 96 | /* too early for the pinctrl driver, so configure the UART pins here */ |
| 97 | vcoreiii_gpio_set_alternate(10, 1); |
| 98 | vcoreiii_gpio_set_alternate(11, 1); |
| 99 | } |
| 100 | |
Horatiu Vultur | c75c908 | 2019-01-12 18:57:00 +0100 | [diff] [blame] | 101 | static void do_board_detect(void) |
| 102 | { |
| 103 | int i; |
| 104 | u16 pval; |
| 105 | |
| 106 | /* MIIM 1 + 2 MDC/MDIO */ |
| 107 | for (i = 56; i < 60; i++) |
| 108 | vcoreiii_gpio_set_alternate(i, 1); |
| 109 | |
Horatiu Vultur | 78b5431 | 2019-01-29 10:58:34 +0100 | [diff] [blame] | 110 | /* small delay for settling the pins */ |
| 111 | mdelay(30); |
| 112 | |
Horatiu Vultur | c75c908 | 2019-01-12 18:57:00 +0100 | [diff] [blame] | 113 | if (mscc_phy_rd(0, 0x10, 0x3, &pval) == 0 && |
| 114 | ((pval >> 4) & 0x3F) == 0x3c) { |
| 115 | gd->board_type = BOARD_TYPE_PCB112; /* Serval2-NID */ |
| 116 | } else if (mscc_phy_rd(1, 0x0, 0x3, &pval) == 0 && |
| 117 | ((pval >> 4) & 0x3F) == 0x3c) { |
| 118 | gd->board_type = BOARD_TYPE_PCB110; /* Jr2-24 */ |
| 119 | } else { |
| 120 | /* Fall-back */ |
| 121 | gd->board_type = BOARD_TYPE_PCB111; /* Jr2-48 */ |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | #if defined(CONFIG_MULTI_DTB_FIT) |
| 126 | int board_fit_config_name_match(const char *name) |
| 127 | { |
| 128 | if (gd->board_type == BOARD_TYPE_PCB110 && |
| 129 | strcmp(name, "jr2_pcb110") == 0) |
| 130 | return 0; |
| 131 | |
| 132 | if (gd->board_type == BOARD_TYPE_PCB111 && |
| 133 | strcmp(name, "jr2_pcb111") == 0) |
| 134 | return 0; |
| 135 | |
| 136 | if (gd->board_type == BOARD_TYPE_PCB112 && |
| 137 | strcmp(name, "serval2_pcb112") == 0) |
| 138 | return 0; |
| 139 | |
| 140 | return -1; |
| 141 | } |
| 142 | #endif |
| 143 | |
| 144 | #if defined(CONFIG_DTB_RESELECT) |
| 145 | int embedded_dtb_select(void) |
| 146 | { |
| 147 | do_board_detect(); |
| 148 | fdtdec_setup(); |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | #endif |