Tony Dinh | 6aebc1a | 2023-02-09 14:00:03 -0800 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2023 Tony Dinh <mibodhi@gmail.com> |
| 4 | * |
| 5 | */ |
| 6 | |
| 7 | #include <i2c.h> |
| 8 | #include <init.h> |
| 9 | #include <miiphy.h> |
| 10 | #include <net.h> |
| 11 | #include <netdev.h> |
| 12 | #include <asm/global_data.h> |
| 13 | #include <asm/io.h> |
| 14 | #include <asm/arch/cpu.h> |
| 15 | #include <asm/arch/soc.h> |
| 16 | #include <linux/bitops.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 | /* |
| 24 | * Those DS116_GPP_xx values and defines in board_serdes_map, and board_topology_map |
| 25 | * are taken from Marvell U-Boot version |
| 26 | * U-Boot 2013.01-g6cc0a6d (Marvell version: 2015_T1.0p16) |
| 27 | */ |
| 28 | #define DS116_GPP_OUT_ENA_LOW \ |
| 29 | (~(BIT(1) | BIT(4) | BIT(6) | BIT(7) | BIT(8) | BIT(9) | \ |
| 30 | BIT(10) | BIT(11) | BIT(15) | BIT(19) | BIT(22) | BIT(23) | \ |
| 31 | BIT(25) | BIT(26) | BIT(27) | BIT(29) | BIT(30) | BIT(31))) |
| 32 | #define DS116_GPP_OUT_ENA_MID \ |
| 33 | (~(BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(15) | \ |
| 34 | BIT(16) | BIT(17) | BIT(18) | BIT(26) | BIT(27))) |
| 35 | |
| 36 | #define DS116_GPP_OUT_VAL_LOW BIT(15) |
| 37 | #define DS116_GPP_OUT_VAL_MID (BIT(26) | BIT(27)) |
| 38 | #define DS116_GPP_POL_LOW 0x0 |
| 39 | #define DS116_GPP_POL_MID 0x0 |
| 40 | |
| 41 | static struct serdes_map board_serdes_map[] = { |
| 42 | {SGMII0, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 43 | {SATA0, SERDES_SPEED_6_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 44 | {DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 45 | {DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 46 | {USB3_HOST0, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 47 | {USB3_HOST1, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 48 | }; |
| 49 | |
| 50 | int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count) |
| 51 | { |
| 52 | *serdes_map_array = board_serdes_map; |
| 53 | *count = ARRAY_SIZE(board_serdes_map); |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * Define the DDR layout / topology here in the board file. This will |
| 59 | * be used by the DDR3 init code in the SPL U-Boot version to configure |
| 60 | * the DDR3 controller. |
| 61 | */ |
| 62 | static struct mv_ddr_topology_map board_topology_map = { |
| 63 | DEBUG_LEVEL_ERROR, |
| 64 | 0x1, /* active interfaces */ |
| 65 | /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */ |
| 66 | { { { {0x1, 0, 0, 0}, |
| 67 | {0x1, 0, 0, 0}, |
| 68 | {0x1, 0, 0, 0}, |
| 69 | {0x1, 0, 0, 0}, |
| 70 | {0x1, 0, 0, 0} }, |
| 71 | SPEED_BIN_DDR_1866L, /* speed_bin */ |
| 72 | MV_DDR_DEV_WIDTH_16BIT, /* memory_width - 16 bits */ |
| 73 | MV_DDR_DIE_CAP_4GBIT, /* mem_size - DS116 board has 2x512MB DRAM banks */ |
| 74 | MV_DDR_FREQ_800, /* frequency */ |
| 75 | 0, 0, /* cas_wl cas_l */ |
| 76 | MV_DDR_TEMP_LOW, /* temperature */ |
| 77 | MV_DDR_TIM_DEFAULT} }, /* timing */ |
| 78 | BUS_MASK_32BIT, /* Busses mask */ |
| 79 | MV_DDR_CFG_DEFAULT, /* ddr configuration data source */ |
| 80 | NOT_COMBINED, /* ddr twin-die combined */ |
| 81 | { {0} }, /* raw spd data */ |
| 82 | {0} /* timing parameters */ |
| 83 | }; |
| 84 | |
| 85 | struct mv_ddr_topology_map *mv_ddr_topology_map_get(void) |
| 86 | { |
| 87 | /* Return the board topology as defined in the board code */ |
| 88 | return &board_topology_map; |
| 89 | } |
| 90 | |
| 91 | int board_early_init_f(void) |
| 92 | { |
| 93 | /* |
| 94 | * Those MPP values are taken from the Marvell U-Boot version |
| 95 | * U-Boot 2013.01-g6cc0a6d (Marvell version: 2015_T1.0p16) |
| 96 | */ |
| 97 | |
| 98 | /* Configure MPP */ |
| 99 | writel(0x00111111, MVEBU_MPP_BASE + 0x00); |
| 100 | writel(0x00000000, MVEBU_MPP_BASE + 0x04); |
| 101 | writel(0x11040330, MVEBU_MPP_BASE + 0x08); |
| 102 | writel(0x00000011, MVEBU_MPP_BASE + 0x0c); |
| 103 | writel(0x00000000, MVEBU_MPP_BASE + 0x10); |
| 104 | writel(0x00000000, MVEBU_MPP_BASE + 0x14); |
| 105 | writel(0x00000000, MVEBU_MPP_BASE + 0x18); |
| 106 | writel(0x00000000, MVEBU_MPP_BASE + 0x1c); |
| 107 | |
| 108 | /* Set GPP Out value */ |
| 109 | writel(DS116_GPP_OUT_VAL_LOW, MVEBU_GPIO0_BASE + 0x00); |
| 110 | writel(DS116_GPP_OUT_VAL_MID, MVEBU_GPIO1_BASE + 0x00); |
| 111 | |
| 112 | /* Set GPP Polarity */ |
| 113 | writel(DS116_GPP_POL_LOW, MVEBU_GPIO0_BASE + 0x0c); |
| 114 | writel(DS116_GPP_POL_MID, MVEBU_GPIO1_BASE + 0x0c); |
| 115 | |
| 116 | /* Set GPP Out Enable */ |
| 117 | writel(DS116_GPP_OUT_ENA_LOW, MVEBU_GPIO0_BASE + 0x04); |
| 118 | writel(DS116_GPP_OUT_ENA_MID, MVEBU_GPIO1_BASE + 0x04); |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | int board_init(void) |
| 124 | { |
| 125 | /* address of boot parameters */ |
| 126 | gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | int board_eth_init(struct bd_info *bis) |
| 132 | { |
| 133 | cpu_eth_init(bis); /* Built in controller(s) come first */ |
| 134 | return pci_eth_init(bis); |
| 135 | } |