Chris Packham | b55b2c9 | 2019-01-10 21:01:00 +1300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2017 Allied Telesis Labs |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <command.h> |
| 8 | #include <dm.h> |
| 9 | #include <i2c.h> |
Chris Packham | 17ca143 | 2019-02-18 10:30:54 +1300 | [diff] [blame] | 10 | #include <wdt.h> |
Chris Packham | b55b2c9 | 2019-01-10 21:01:00 +1300 | [diff] [blame] | 11 | #include <asm/gpio.h> |
| 12 | #include <linux/mbus.h> |
| 13 | #include <linux/io.h> |
| 14 | #include <asm/arch/cpu.h> |
| 15 | #include <asm/arch/soc.h> |
| 16 | #include "../common/gpio_hog.h" |
| 17 | |
| 18 | #include "../drivers/ddr/marvell/a38x/ddr3_init.h" |
| 19 | #include <../serdes/a38x/high_speed_env_spec.h> |
| 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
| 23 | #define MVEBU_DEV_BUS_BASE (MVEBU_REGISTER(0x10400)) |
| 24 | |
| 25 | #define CONFIG_NVS_LOCATION 0xf4800000 |
| 26 | #define CONFIG_NVS_SIZE (512 << 10) |
| 27 | |
| 28 | static struct serdes_map board_serdes_map[] = { |
| 29 | {PEX0, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0}, |
| 30 | {DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 31 | {PEX1, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0}, |
| 32 | {DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 33 | {DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 34 | {DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0} |
| 35 | }; |
| 36 | |
| 37 | int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count) |
| 38 | { |
| 39 | *serdes_map_array = board_serdes_map; |
| 40 | *count = ARRAY_SIZE(board_serdes_map); |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | /* |
| 45 | * Define the DDR layout / topology here in the board file. This will |
| 46 | * be used by the DDR3 init code in the SPL U-Boot version to configure |
| 47 | * the DDR3 controller. |
| 48 | */ |
| 49 | static struct mv_ddr_topology_map board_topology_map = { |
| 50 | DEBUG_LEVEL_ERROR, |
| 51 | 0x1, /* active interfaces */ |
| 52 | /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */ |
| 53 | { { { {0x1, 0, 0, 0}, |
| 54 | {0x1, 0, 0, 0}, |
| 55 | {0x1, 0, 0, 0}, |
| 56 | {0x1, 0, 0, 0}, |
| 57 | {0x1, 0, 0, 0} }, |
| 58 | SPEED_BIN_DDR_1866M, /* speed_bin */ |
| 59 | MV_DDR_DEV_WIDTH_16BIT, /* sdram device width */ |
| 60 | MV_DDR_DIE_CAP_4GBIT, /* die capacity */ |
Chris Packham | 1e50be3 | 2019-02-11 14:19:56 +1300 | [diff] [blame] | 61 | MV_DDR_FREQ_SAR, /* frequency */ |
Chris Packham | b55b2c9 | 2019-01-10 21:01:00 +1300 | [diff] [blame] | 62 | 0, 0, /* cas_l cas_wl */ |
| 63 | MV_DDR_TEMP_LOW, /* temperature */ |
| 64 | MV_DDR_TIM_2T} }, /* timing */ |
| 65 | BUS_MASK_32BIT_ECC, /* subphys mask */ |
| 66 | MV_DDR_CFG_DEFAULT, /* ddr configuration data source */ |
| 67 | { {0} }, /* raw spd data */ |
| 68 | {0} /* timing parameters */ |
| 69 | }; |
| 70 | |
| 71 | struct mv_ddr_topology_map *mv_ddr_topology_map_get(void) |
| 72 | { |
| 73 | /* Return the board topology as defined in the board code */ |
| 74 | return &board_topology_map; |
| 75 | } |
| 76 | |
| 77 | int board_early_init_f(void) |
| 78 | { |
| 79 | /* Configure MPP */ |
| 80 | writel(0x00001111, MVEBU_MPP_BASE + 0x00); |
| 81 | writel(0x00000000, MVEBU_MPP_BASE + 0x04); |
| 82 | writel(0x55000000, MVEBU_MPP_BASE + 0x08); |
| 83 | writel(0x55550550, MVEBU_MPP_BASE + 0x0c); |
| 84 | writel(0x55555555, MVEBU_MPP_BASE + 0x10); |
| 85 | writel(0x00100565, MVEBU_MPP_BASE + 0x14); |
| 86 | writel(0x40000000, MVEBU_MPP_BASE + 0x18); |
| 87 | writel(0x00004444, MVEBU_MPP_BASE + 0x1c); |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
Chris Packham | 17ca143 | 2019-02-18 10:30:54 +1300 | [diff] [blame] | 92 | void spl_board_init(void) |
| 93 | { |
Chris Packham | 17ca143 | 2019-02-18 10:30:54 +1300 | [diff] [blame] | 94 | } |
| 95 | |
Chris Packham | b55b2c9 | 2019-01-10 21:01:00 +1300 | [diff] [blame] | 96 | int board_init(void) |
| 97 | { |
| 98 | /* address of boot parameters */ |
| 99 | gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; |
| 100 | |
| 101 | /* window for NVS */ |
| 102 | mbus_dt_setup_win(&mbus_state, CONFIG_NVS_LOCATION, CONFIG_NVS_SIZE, |
| 103 | CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_DEV_CS1); |
| 104 | |
| 105 | /* DEV_READYn is not needed for NVS, ignore it when accessing CS1 */ |
| 106 | writel(0x00004001, MVEBU_DEV_BUS_BASE + 0xc8); |
| 107 | |
Chris Packham | 17ca143 | 2019-02-18 10:30:54 +1300 | [diff] [blame] | 108 | spl_board_init(); |
| 109 | |
Chris Packham | b55b2c9 | 2019-01-10 21:01:00 +1300 | [diff] [blame] | 110 | return 0; |
| 111 | } |
Chris Packham | 17ca143 | 2019-02-18 10:30:54 +1300 | [diff] [blame] | 112 | |
| 113 | void arch_preboot_os(void) |
| 114 | { |
| 115 | #ifdef CONFIG_WATCHDOG |
Stefan Roese | 502acb0 | 2019-04-11 15:58:44 +0200 | [diff] [blame] | 116 | wdt_stop(gd->watchdog_dev); |
Chris Packham | 17ca143 | 2019-02-18 10:30:54 +1300 | [diff] [blame] | 117 | #endif |
| 118 | } |
| 119 | |
Chris Packham | b55b2c9 | 2019-01-10 21:01:00 +1300 | [diff] [blame] | 120 | static int led_7seg_init(unsigned int segments) |
| 121 | { |
| 122 | int node; |
| 123 | int ret; |
| 124 | int i; |
| 125 | struct gpio_desc desc[8]; |
| 126 | |
| 127 | node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, |
| 128 | "atl,of-led-7seg"); |
| 129 | if (node < 0) |
| 130 | return -ENODEV; |
| 131 | |
| 132 | ret = gpio_request_list_by_name_nodev(offset_to_ofnode(node), |
| 133 | "segment-gpios", desc, |
| 134 | ARRAY_SIZE(desc), GPIOD_IS_OUT); |
| 135 | if (ret < 0) |
| 136 | return ret; |
| 137 | |
| 138 | for (i = 0; i < ARRAY_SIZE(desc); i++) { |
| 139 | ret = dm_gpio_set_value(&desc[i], !(segments & BIT(i))); |
| 140 | if (ret) |
| 141 | return ret; |
| 142 | } |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | #ifdef CONFIG_MISC_INIT_R |
| 148 | int misc_init_r(void) |
| 149 | { |
| 150 | static struct gpio_desc usb_en = {}, nand_wp = {}, phy_reset[2] = {}, |
| 151 | led_en = {}; |
| 152 | |
| 153 | gpio_hog(&usb_en, "atl,usb-enable", "enable-gpio", 1); |
| 154 | gpio_hog(&nand_wp, "atl,nand-protect", "protect-gpio", 1); |
| 155 | gpio_hog_list(phy_reset, ARRAY_SIZE(phy_reset), "atl,phy-reset", "reset-gpio", 0); |
| 156 | gpio_hog(&led_en, "atl,led-enable", "enable-gpio", 1); |
| 157 | |
| 158 | #ifdef MTDPARTS_MTDOOPS |
| 159 | env_set("mtdoops", MTDPARTS_MTDOOPS); |
| 160 | #endif |
| 161 | |
| 162 | led_7seg_init(0xff); |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | #endif |
| 167 | |
| 168 | #ifdef CONFIG_DISPLAY_BOARDINFO |
| 169 | int checkboard(void) |
| 170 | { |
| 171 | puts("Board: " CONFIG_SYS_BOARD "\n"); |
| 172 | |
| 173 | return 0; |
| 174 | } |
| 175 | #endif |