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