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