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