Horatiu Vultur | a834cb8 | 2019-01-23 16:39:45 +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> |
| 7 | #include <asm/io.h> |
| 8 | #include <led.h> |
Horatiu Vultur | d2691b4 | 2019-04-11 14:11:33 +0200 | [diff] [blame] | 9 | #include <miiphy.h> |
Horatiu Vultur | a834cb8 | 2019-01-23 16:39:45 +0100 | [diff] [blame] | 10 | |
| 11 | enum { |
| 12 | BOARD_TYPE_PCB106 = 0xAABBCD00, |
| 13 | BOARD_TYPE_PCB105, |
| 14 | }; |
| 15 | |
| 16 | int board_early_init_r(void) |
| 17 | { |
| 18 | /* Prepare SPI controller to be used in master mode */ |
| 19 | writel(0, BASE_CFG + ICPU_SW_MODE); |
| 20 | |
| 21 | /* Address of boot parameters */ |
| 22 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE; |
| 23 | |
| 24 | /* LED setup */ |
| 25 | if (IS_ENABLED(CONFIG_LED)) |
| 26 | led_default_state(); |
| 27 | |
| 28 | return 0; |
| 29 | } |
| 30 | |
Horatiu Vultur | d2691b4 | 2019-04-11 14:11:33 +0200 | [diff] [blame] | 31 | int board_phy_config(struct phy_device *phydev) |
| 32 | { |
| 33 | phy_write(phydev, 0, 31, 0x10); |
| 34 | phy_write(phydev, 0, 18, 0x80F0); |
| 35 | while (phy_read(phydev, 0, 18) & 0x8000) |
| 36 | ; |
| 37 | phy_write(phydev, 0, 14, 0x800); |
| 38 | phy_write(phydev, 0, 31, 0); |
| 39 | return 0; |
| 40 | } |
| 41 | |
Horatiu Vultur | a834cb8 | 2019-01-23 16:39:45 +0100 | [diff] [blame] | 42 | static void do_board_detect(void) |
| 43 | { |
| 44 | u16 gpio_in_reg; |
| 45 | |
| 46 | /* Set MDIO and MDC */ |
| 47 | mscc_gpio_set_alternate(9, 2); |
| 48 | mscc_gpio_set_alternate(10, 2); |
| 49 | |
| 50 | /* Set GPIO page */ |
| 51 | mscc_phy_wr(1, 16, 31, 0x10); |
| 52 | if (!mscc_phy_rd(1, 16, 15, &gpio_in_reg)) { |
| 53 | if (gpio_in_reg & 0x200) |
| 54 | gd->board_type = BOARD_TYPE_PCB106; |
| 55 | else |
| 56 | gd->board_type = BOARD_TYPE_PCB105; |
Horatiu Vultur | a834cb8 | 2019-01-23 16:39:45 +0100 | [diff] [blame] | 57 | } else { |
| 58 | gd->board_type = BOARD_TYPE_PCB105; |
| 59 | } |
Horatiu Vultur | c6b2e71 | 2019-04-15 11:56:37 +0200 | [diff] [blame] | 60 | mscc_phy_wr(1, 16, 31, 0x0); |
Horatiu Vultur | a834cb8 | 2019-01-23 16:39:45 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | #if defined(CONFIG_MULTI_DTB_FIT) |
| 64 | int board_fit_config_name_match(const char *name) |
| 65 | { |
| 66 | if (gd->board_type == BOARD_TYPE_PCB106 && |
| 67 | strcmp(name, "serval_pcb106") == 0) |
| 68 | return 0; |
| 69 | |
| 70 | if (gd->board_type == BOARD_TYPE_PCB105 && |
| 71 | strcmp(name, "serval_pcb105") == 0) |
| 72 | return 0; |
| 73 | |
| 74 | return -1; |
| 75 | } |
| 76 | #endif |
| 77 | |
| 78 | #if defined(CONFIG_DTB_RESELECT) |
| 79 | int embedded_dtb_select(void) |
| 80 | { |
| 81 | do_board_detect(); |
| 82 | fdtdec_setup(); |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | #endif |