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