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