Green Wan | 70415e1 | 2021-05-27 06:52:13 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (c) 2020-2021 SiFive, Inc |
| 4 | * |
| 5 | * Authors: |
| 6 | * Pragnesh Patel <pragnesh.patel@sifive.com> |
| 7 | */ |
| 8 | |
| 9 | #include <init.h> |
| 10 | #include <spl.h> |
| 11 | #include <misc.h> |
| 12 | #include <log.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <linux/io.h> |
| 15 | #include <asm/gpio.h> |
| 16 | #include <asm/arch/gpio.h> |
| 17 | #include <asm/arch/spl.h> |
| 18 | |
| 19 | #define GEM_PHY_RESET SIFIVE_GENERIC_GPIO_NR(0, 12) |
| 20 | |
| 21 | #define MODE_SELECT_REG 0x1000 |
| 22 | #define MODE_SELECT_SD 0xb |
| 23 | #define MODE_SELECT_MASK GENMASK(3, 0) |
| 24 | |
| 25 | int spl_board_init_f(void) |
| 26 | { |
| 27 | int ret; |
| 28 | |
| 29 | ret = spl_soc_init(); |
| 30 | if (ret) { |
| 31 | debug("HiFive Unmatched FU740 SPL init failed: %d\n", ret); |
| 32 | return ret; |
| 33 | } |
| 34 | |
| 35 | /* |
| 36 | * GEMGXL init VSC8541 PHY reset sequence; |
| 37 | * leave pull-down active for 2ms |
| 38 | */ |
| 39 | udelay(2000); |
| 40 | ret = gpio_request(GEM_PHY_RESET, "gem_phy_reset"); |
| 41 | if (ret) { |
| 42 | debug("gem_phy_reset gpio request failed: %d\n", ret); |
| 43 | return ret; |
| 44 | } |
| 45 | |
| 46 | /* Set GPIO 12 (PHY NRESET) */ |
| 47 | ret = gpio_direction_output(GEM_PHY_RESET, 1); |
| 48 | if (ret) { |
| 49 | debug("gem_phy_reset gpio direction set failed: %d\n", ret); |
| 50 | return ret; |
| 51 | } |
| 52 | |
| 53 | udelay(1); |
| 54 | |
| 55 | /* Reset PHY again to enter unmanaged mode */ |
| 56 | gpio_set_value(GEM_PHY_RESET, 0); |
| 57 | udelay(1); |
| 58 | gpio_set_value(GEM_PHY_RESET, 1); |
| 59 | mdelay(15); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | u32 spl_boot_device(void) |
| 65 | { |
| 66 | u32 mode_select = readl((void *)MODE_SELECT_REG); |
| 67 | u32 boot_device = mode_select & MODE_SELECT_MASK; |
| 68 | |
| 69 | switch (boot_device) { |
| 70 | case MODE_SELECT_SD: |
| 71 | return BOOT_DEVICE_MMC1; |
| 72 | default: |
| 73 | debug("Unsupported boot device 0x%x but trying MMC1\n", |
| 74 | boot_device); |
| 75 | return BOOT_DEVICE_MMC1; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | #ifdef CONFIG_SPL_LOAD_FIT |
| 80 | int board_fit_config_name_match(const char *name) |
| 81 | { |
Zong Li | e52b83a | 2021-07-20 14:26:08 +0800 | [diff] [blame^] | 82 | /* boot using first FIT config */ |
| 83 | return 0; |
Green Wan | 70415e1 | 2021-05-27 06:52:13 -0700 | [diff] [blame] | 84 | } |
| 85 | #endif |