blob: 8b31045a0743c83bb7b0e717d253bb83952ca410 [file] [log] [blame]
Chris Packhamb55b2c92019-01-10 21:01:00 +13001// 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>
Simon Glass5e6201b2019-08-01 09:46:51 -06009#include <env.h>
Chris Packhamb55b2c92019-01-10 21:01:00 +130010#include <i2c.h>
Simon Glass97589732020-05-10 11:40:02 -060011#include <init.h>
Chris Packham17ca1432019-02-18 10:30:54 +130012#include <wdt.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Chris Packhamb55b2c92019-01-10 21:01:00 +130014#include <asm/gpio.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060015#include <linux/bitops.h>
Chris Packhamb55b2c92019-01-10 21:01:00 +130016#include <linux/mbus.h>
17#include <linux/io.h>
18#include <asm/arch/cpu.h>
19#include <asm/arch/soc.h>
20#include "../common/gpio_hog.h"
21
22#include "../drivers/ddr/marvell/a38x/ddr3_init.h"
23#include <../serdes/a38x/high_speed_env_spec.h>
24
25DECLARE_GLOBAL_DATA_PTR;
26
27#define MVEBU_DEV_BUS_BASE (MVEBU_REGISTER(0x10400))
28
29#define CONFIG_NVS_LOCATION 0xf4800000
30#define CONFIG_NVS_SIZE (512 << 10)
31
32static struct serdes_map board_serdes_map[] = {
33 {PEX0, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
34 {DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
35 {PEX1, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
36 {DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
37 {DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
38 {DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}
39};
40
41int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count)
42{
43 *serdes_map_array = board_serdes_map;
44 *count = ARRAY_SIZE(board_serdes_map);
45 return 0;
46}
47
48/*
49 * Define the DDR layout / topology here in the board file. This will
50 * be used by the DDR3 init code in the SPL U-Boot version to configure
51 * the DDR3 controller.
52 */
53static struct mv_ddr_topology_map board_topology_map = {
54 DEBUG_LEVEL_ERROR,
55 0x1, /* active interfaces */
56 /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
57 { { { {0x1, 0, 0, 0},
58 {0x1, 0, 0, 0},
59 {0x1, 0, 0, 0},
60 {0x1, 0, 0, 0},
61 {0x1, 0, 0, 0} },
62 SPEED_BIN_DDR_1866M, /* speed_bin */
63 MV_DDR_DEV_WIDTH_16BIT, /* sdram device width */
64 MV_DDR_DIE_CAP_4GBIT, /* die capacity */
Chris Packham1e50be32019-02-11 14:19:56 +130065 MV_DDR_FREQ_SAR, /* frequency */
Chris Packhamb55b2c92019-01-10 21:01:00 +130066 0, 0, /* cas_l cas_wl */
67 MV_DDR_TEMP_LOW, /* temperature */
68 MV_DDR_TIM_2T} }, /* timing */
69 BUS_MASK_32BIT_ECC, /* subphys mask */
70 MV_DDR_CFG_DEFAULT, /* ddr configuration data source */
Moti Buskila498475e2021-02-19 17:11:19 +010071 NOT_COMBINED, /* ddr twin-die combined */
Chris Packhamb55b2c92019-01-10 21:01:00 +130072 { {0} }, /* raw spd data */
Chris Packhame422adc2020-01-30 12:50:44 +130073 {0}, /* timing parameters */
74 { {0} }, /* electrical configuration */
75 {0}, /* electrical parameters */
76 0, /* Clock enable mask */
77 160 /* Clock delay */
Chris Packhamb55b2c92019-01-10 21:01:00 +130078};
79
80struct mv_ddr_topology_map *mv_ddr_topology_map_get(void)
81{
82 /* Return the board topology as defined in the board code */
83 return &board_topology_map;
84}
85
86int board_early_init_f(void)
87{
88 /* Configure MPP */
89 writel(0x00001111, MVEBU_MPP_BASE + 0x00);
90 writel(0x00000000, MVEBU_MPP_BASE + 0x04);
91 writel(0x55000000, MVEBU_MPP_BASE + 0x08);
92 writel(0x55550550, MVEBU_MPP_BASE + 0x0c);
93 writel(0x55555555, MVEBU_MPP_BASE + 0x10);
94 writel(0x00100565, MVEBU_MPP_BASE + 0x14);
95 writel(0x40000000, MVEBU_MPP_BASE + 0x18);
96 writel(0x00004444, MVEBU_MPP_BASE + 0x1c);
97
98 return 0;
99}
100
Chris Packham17ca1432019-02-18 10:30:54 +1300101void spl_board_init(void)
102{
Chris Packham17ca1432019-02-18 10:30:54 +1300103}
104
Chris Packhamb55b2c92019-01-10 21:01:00 +1300105int board_init(void)
106{
107 /* address of boot parameters */
108 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
109
110 /* window for NVS */
111 mbus_dt_setup_win(&mbus_state, CONFIG_NVS_LOCATION, CONFIG_NVS_SIZE,
112 CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_DEV_CS1);
113
114 /* DEV_READYn is not needed for NVS, ignore it when accessing CS1 */
115 writel(0x00004001, MVEBU_DEV_BUS_BASE + 0xc8);
116
Chris Packham17ca1432019-02-18 10:30:54 +1300117 spl_board_init();
118
Chris Packhamb55b2c92019-01-10 21:01:00 +1300119 return 0;
120}
Chris Packham17ca1432019-02-18 10:30:54 +1300121
122void arch_preboot_os(void)
123{
Rasmus Villemoes2e713662021-08-19 11:57:02 +0200124 if (CONFIG_IS_ENABLED(WDT))
125 wdt_stop_all();
Chris Packham17ca1432019-02-18 10:30:54 +1300126}
127
Chris Packhamb55b2c92019-01-10 21:01:00 +1300128static int led_7seg_init(unsigned int segments)
129{
130 int node;
131 int ret;
132 int i;
133 struct gpio_desc desc[8];
134
135 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0,
136 "atl,of-led-7seg");
137 if (node < 0)
138 return -ENODEV;
139
140 ret = gpio_request_list_by_name_nodev(offset_to_ofnode(node),
141 "segment-gpios", desc,
142 ARRAY_SIZE(desc), GPIOD_IS_OUT);
143 if (ret < 0)
144 return ret;
145
146 for (i = 0; i < ARRAY_SIZE(desc); i++) {
147 ret = dm_gpio_set_value(&desc[i], !(segments & BIT(i)));
148 if (ret)
149 return ret;
150 }
151
152 return 0;
153}
154
155#ifdef CONFIG_MISC_INIT_R
156int misc_init_r(void)
157{
158 static struct gpio_desc usb_en = {}, nand_wp = {}, phy_reset[2] = {},
159 led_en = {};
160
161 gpio_hog(&usb_en, "atl,usb-enable", "enable-gpio", 1);
162 gpio_hog(&nand_wp, "atl,nand-protect", "protect-gpio", 1);
163 gpio_hog_list(phy_reset, ARRAY_SIZE(phy_reset), "atl,phy-reset", "reset-gpio", 0);
164 gpio_hog(&led_en, "atl,led-enable", "enable-gpio", 1);
165
166#ifdef MTDPARTS_MTDOOPS
167 env_set("mtdoops", MTDPARTS_MTDOOPS);
168#endif
169
170 led_7seg_init(0xff);
171
172 return 0;
173}
174#endif
175
176#ifdef CONFIG_DISPLAY_BOARDINFO
177int checkboard(void)
178{
179 puts("Board: " CONFIG_SYS_BOARD "\n");
180
181 return 0;
182}
183#endif