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