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 | 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> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 9 | #include <asm/global_data.h> |
Horatiu Vultur | a834cb8 | 2019-01-23 16:39:45 +0100 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | #include <led.h> |
Horatiu Vultur | d2691b4 | 2019-04-11 14:11:33 +0200 | [diff] [blame] | 12 | #include <miiphy.h> |
Horatiu Vultur | a834cb8 | 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 | |
Horatiu Vultur | a834cb8 | 2019-01-23 16:39:45 +0100 | [diff] [blame] | 27 | return 0; |
| 28 | } |
| 29 | |
Horatiu Vultur | d2691b4 | 2019-04-11 14:11:33 +0200 | [diff] [blame] | 30 | int board_phy_config(struct phy_device *phydev) |
| 31 | { |
| 32 | phy_write(phydev, 0, 31, 0x10); |
| 33 | phy_write(phydev, 0, 18, 0x80F0); |
| 34 | while (phy_read(phydev, 0, 18) & 0x8000) |
| 35 | ; |
| 36 | phy_write(phydev, 0, 14, 0x800); |
| 37 | phy_write(phydev, 0, 31, 0); |
| 38 | return 0; |
| 39 | } |
| 40 | |
Horatiu Vultur | a834cb8 | 2019-01-23 16:39:45 +0100 | [diff] [blame] | 41 | static void do_board_detect(void) |
| 42 | { |
| 43 | u16 gpio_in_reg; |
| 44 | |
| 45 | /* Set MDIO and MDC */ |
| 46 | mscc_gpio_set_alternate(9, 2); |
| 47 | mscc_gpio_set_alternate(10, 2); |
| 48 | |
| 49 | /* Set GPIO page */ |
| 50 | mscc_phy_wr(1, 16, 31, 0x10); |
| 51 | if (!mscc_phy_rd(1, 16, 15, &gpio_in_reg)) { |
| 52 | if (gpio_in_reg & 0x200) |
| 53 | gd->board_type = BOARD_TYPE_PCB106; |
| 54 | else |
| 55 | gd->board_type = BOARD_TYPE_PCB105; |
Horatiu Vultur | a834cb8 | 2019-01-23 16:39:45 +0100 | [diff] [blame] | 56 | } else { |
| 57 | gd->board_type = BOARD_TYPE_PCB105; |
| 58 | } |
Horatiu Vultur | c6b2e71 | 2019-04-15 11:56:37 +0200 | [diff] [blame] | 59 | mscc_phy_wr(1, 16, 31, 0x0); |
Horatiu Vultur | a834cb8 | 2019-01-23 16:39:45 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | #if defined(CONFIG_MULTI_DTB_FIT) |
| 63 | int board_fit_config_name_match(const char *name) |
| 64 | { |
| 65 | if (gd->board_type == BOARD_TYPE_PCB106 && |
| 66 | strcmp(name, "serval_pcb106") == 0) |
| 67 | return 0; |
| 68 | |
| 69 | if (gd->board_type == BOARD_TYPE_PCB105 && |
| 70 | strcmp(name, "serval_pcb105") == 0) |
| 71 | return 0; |
| 72 | |
| 73 | return -1; |
| 74 | } |
| 75 | #endif |
| 76 | |
| 77 | #if defined(CONFIG_DTB_RESELECT) |
| 78 | int embedded_dtb_select(void) |
| 79 | { |
| 80 | do_board_detect(); |
| 81 | fdtdec_setup(); |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | #endif |