blob: 7b9c3223edb820d5f70a26aa4c83cb25303d394b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese6edf27e2016-05-17 15:04:16 +02002/*
3 * Copyright (C) 2016 Stefan Roese <sr@denx.de>
Stefan Roese6edf27e2016-05-17 15:04:16 +02004 */
5
6#include <common.h>
Konstantin Porotchkinf4d32b42017-02-16 13:52:29 +02007#include <dm.h>
Stefan Roese6edf27e2016-05-17 15:04:16 +02008#include <i2c.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Konstantin Porotchkinf4d32b42017-02-16 13:52:29 +020010#include <phy.h>
Stefan Roese6edf27e2016-05-17 15:04:16 +020011#include <asm/io.h>
12#include <asm/arch/cpu.h>
13#include <asm/arch/soc.h>
Simon Glassdbd79542020-05-10 11:40:11 -060014#include <linux/delay.h>
Stefan Roese6edf27e2016-05-17 15:04:16 +020015
16DECLARE_GLOBAL_DATA_PTR;
17
18/* IO expander I2C device */
19#define I2C_IO_EXP_ADDR 0x22
20#define I2C_IO_CFG_REG_0 0x6
21#define I2C_IO_DATA_OUT_REG_0 0x2
22#define I2C_IO_REG_0_SATA_OFF 2
23#define I2C_IO_REG_0_USB_H_OFF 1
24
Konstantin Porotchkinb65ffc42017-02-16 13:52:32 +020025/* The pin control values are the same for DB and Espressobin */
Konstantin Porotchkincfa88a32017-02-16 13:52:26 +020026#define PINCTRL_NB_REG_VALUE 0x000173fa
27#define PINCTRL_SB_REG_VALUE 0x00007a23
28
Konstantin Porotchkinf4d32b42017-02-16 13:52:29 +020029/* Ethernet switch registers */
30/* SMI addresses for multi-chip mode */
31#define MVEBU_PORT_CTRL_SMI_ADDR(p) (16 + (p))
32#define MVEBU_SW_G2_SMI_ADDR (28)
33
34/* Multi-chip mode */
35#define MVEBU_SW_SMI_DATA_REG (1)
36#define MVEBU_SW_SMI_CMD_REG (0)
37 #define SW_SMI_CMD_REG_ADDR_OFF 0
38 #define SW_SMI_CMD_DEV_ADDR_OFF 5
39 #define SW_SMI_CMD_SMI_OP_OFF 10
40 #define SW_SMI_CMD_SMI_MODE_OFF 12
41 #define SW_SMI_CMD_SMI_BUSY_OFF 15
42
43/* Single-chip mode */
44/* Switch Port Registers */
45#define MVEBU_SW_LINK_CTRL_REG (1)
46#define MVEBU_SW_PORT_CTRL_REG (4)
Pali Rohár7325a812020-08-17 16:36:38 +020047#define MVEBU_SW_PORT_BASE_VLAN (6)
Konstantin Porotchkinf4d32b42017-02-16 13:52:29 +020048
49/* Global 2 Registers */
50#define MVEBU_G2_SMI_PHY_CMD_REG (24)
51#define MVEBU_G2_SMI_PHY_DATA_REG (25)
52
Stefan Roese6edf27e2016-05-17 15:04:16 +020053int board_early_init_f(void)
54{
Stefan Roese6edf27e2016-05-17 15:04:16 +020055 return 0;
56}
57
58int board_init(void)
59{
60 /* adress of boot parameters */
61 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
62
63 return 0;
64}
65
66/* Board specific AHCI / SATA enable code */
67int board_ahci_enable(void)
68{
69 struct udevice *dev;
70 int ret;
71 u8 buf[8];
72
Konstantin Porotchkinb65ffc42017-02-16 13:52:32 +020073 /* Only DB requres this configuration */
74 if (!of_machine_is_compatible("marvell,armada-3720-db"))
75 return 0;
76
Stefan Roese6edf27e2016-05-17 15:04:16 +020077 /* Configure IO exander PCA9555: 7bit address 0x22 */
78 ret = i2c_get_chip_for_busnum(0, I2C_IO_EXP_ADDR, 1, &dev);
79 if (ret) {
80 printf("Cannot find PCA9555: %d\n", ret);
81 return 0;
82 }
83
84 ret = dm_i2c_read(dev, I2C_IO_CFG_REG_0, buf, 1);
85 if (ret) {
86 printf("Failed to read IO expander value via I2C\n");
87 return -EIO;
88 }
89
90 /*
91 * Enable SATA power via IO expander connected via I2C by setting
92 * the corresponding bit to output mode to enable power for SATA
93 */
94 buf[0] &= ~(1 << I2C_IO_REG_0_SATA_OFF);
95 ret = dm_i2c_write(dev, I2C_IO_CFG_REG_0, buf, 1);
96 if (ret) {
97 printf("Failed to set IO expander via I2C\n");
98 return -EIO;
99 }
100
101 return 0;
102}
103
104/* Board specific xHCI enable code */
Jon Nettletona81f47c2017-11-06 10:33:19 +0200105int board_xhci_enable(fdt_addr_t base)
Stefan Roese6edf27e2016-05-17 15:04:16 +0200106{
107 struct udevice *dev;
108 int ret;
109 u8 buf[8];
110
Konstantin Porotchkinb65ffc42017-02-16 13:52:32 +0200111 /* Only DB requres this configuration */
112 if (!of_machine_is_compatible("marvell,armada-3720-db"))
113 return 0;
114
Stefan Roese6edf27e2016-05-17 15:04:16 +0200115 /* Configure IO exander PCA9555: 7bit address 0x22 */
116 ret = i2c_get_chip_for_busnum(0, I2C_IO_EXP_ADDR, 1, &dev);
117 if (ret) {
118 printf("Cannot find PCA9555: %d\n", ret);
119 return 0;
120 }
121
122 printf("Enable USB VBUS\n");
123
124 /*
125 * Read configuration (direction) and set VBUS pin as output
126 * (reset pin = output)
127 */
128 ret = dm_i2c_read(dev, I2C_IO_CFG_REG_0, buf, 1);
129 if (ret) {
130 printf("Failed to read IO expander value via I2C\n");
131 return -EIO;
132 }
133 buf[0] &= ~(1 << I2C_IO_REG_0_USB_H_OFF);
134 ret = dm_i2c_write(dev, I2C_IO_CFG_REG_0, buf, 1);
135 if (ret) {
136 printf("Failed to set IO expander via I2C\n");
137 return -EIO;
138 }
139
140 /* Read VBUS output value and disable it */
141 ret = dm_i2c_read(dev, I2C_IO_DATA_OUT_REG_0, buf, 1);
142 if (ret) {
143 printf("Failed to read IO expander value via I2C\n");
144 return -EIO;
145 }
146 buf[0] &= ~(1 << I2C_IO_REG_0_USB_H_OFF);
147 ret = dm_i2c_write(dev, I2C_IO_DATA_OUT_REG_0, buf, 1);
148 if (ret) {
149 printf("Failed to set IO expander via I2C\n");
150 return -EIO;
151 }
152
153 /*
154 * Required delay for configuration to settle - must wait for
155 * power on port is disabled in case VBUS signal was high,
156 * required 3 seconds delay to let VBUS signal fully settle down
157 */
158 mdelay(3000);
159
160 /* Enable VBUS power: Set output value of VBUS pin as enabled */
161 buf[0] |= (1 << I2C_IO_REG_0_USB_H_OFF);
162 ret = dm_i2c_write(dev, I2C_IO_DATA_OUT_REG_0, buf, 1);
163 if (ret) {
164 printf("Failed to set IO expander via I2C\n");
165 return -EIO;
166 }
167
168 mdelay(500); /* required delay to let output value settle */
169
170 return 0;
171}
Konstantin Porotchkinf4d32b42017-02-16 13:52:29 +0200172
173/* Helper function for accessing switch devices in multi-chip connection mode */
174static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
175 int smi_addr, int reg, u16 value)
176{
177 u16 smi_cmd = 0;
178
179 if (bus->write(bus, dev_smi_addr, 0,
180 MVEBU_SW_SMI_DATA_REG, value) != 0) {
181 printf("Error writing to the PHY addr=%02x reg=%02x\n",
182 smi_addr, reg);
183 return -EFAULT;
184 }
185
186 smi_cmd = (1 << SW_SMI_CMD_SMI_BUSY_OFF) |
187 (1 << SW_SMI_CMD_SMI_MODE_OFF) |
188 (1 << SW_SMI_CMD_SMI_OP_OFF) |
189 (smi_addr << SW_SMI_CMD_DEV_ADDR_OFF) |
190 (reg << SW_SMI_CMD_REG_ADDR_OFF);
191 if (bus->write(bus, dev_smi_addr, 0,
192 MVEBU_SW_SMI_CMD_REG, smi_cmd) != 0) {
193 printf("Error writing to the PHY addr=%02x reg=%02x\n",
194 smi_addr, reg);
195 return -EFAULT;
196 }
197
198 return 0;
199}
200
201/* Bring-up board-specific network stuff */
202int board_network_enable(struct mii_dev *bus)
203{
204 if (!of_machine_is_compatible("marvell,armada-3720-espressobin"))
205 return 0;
206
207 /*
208 * FIXME: remove this code once Topaz driver gets available
209 * A3720 Community Board Only
210 * Configure Topaz switch (88E6341)
Pali Rohár7325a812020-08-17 16:36:38 +0200211 * Restrict output to ports 1,2,3 only from port 0 (CPU)
Konstantin Porotchkinf4d32b42017-02-16 13:52:29 +0200212 * Set port 0,1,2,3 to forwarding Mode (through Switch Port registers)
213 */
Pali Rohár7325a812020-08-17 16:36:38 +0200214 mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(1),
215 MVEBU_SW_PORT_BASE_VLAN, BIT(0));
216 mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(2),
217 MVEBU_SW_PORT_BASE_VLAN, BIT(0));
218 mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(3),
219 MVEBU_SW_PORT_BASE_VLAN, BIT(0));
220
Konstantin Porotchkinf4d32b42017-02-16 13:52:29 +0200221 mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(0),
222 MVEBU_SW_PORT_CTRL_REG, 0x7f);
223 mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(1),
224 MVEBU_SW_PORT_CTRL_REG, 0x7f);
225 mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(2),
226 MVEBU_SW_PORT_CTRL_REG, 0x7f);
227 mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(3),
228 MVEBU_SW_PORT_CTRL_REG, 0x7f);
229
230 /* RGMII Delay on Port 0 (CPU port), force link to 1000Mbps */
231 mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(0),
232 MVEBU_SW_LINK_CTRL_REG, 0xe002);
233
234 /* Power up PHY 1, 2, 3 (through Global 2 registers) */
235 mii_multi_chip_mode_write(bus, 1, MVEBU_SW_G2_SMI_ADDR,
236 MVEBU_G2_SMI_PHY_DATA_REG, 0x1140);
237 mii_multi_chip_mode_write(bus, 1, MVEBU_SW_G2_SMI_ADDR,
238 MVEBU_G2_SMI_PHY_CMD_REG, 0x9620);
239 mii_multi_chip_mode_write(bus, 1, MVEBU_SW_G2_SMI_ADDR,
240 MVEBU_G2_SMI_PHY_CMD_REG, 0x9640);
241 mii_multi_chip_mode_write(bus, 1, MVEBU_SW_G2_SMI_ADDR,
242 MVEBU_G2_SMI_PHY_CMD_REG, 0x9660);
243
244 return 0;
245}
Pali Rohárcb00c182020-08-19 16:24:17 +0200246
247#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_ENV_IS_IN_SPI_FLASH)
248int ft_board_setup(void *blob, struct bd_info *bd)
249{
250 int ret;
251 int spi_off;
252 int parts_off;
253 int part_off;
254
255 /* Fill SPI MTD partitions for Linux kernel on Espressobin */
256 if (!of_machine_is_compatible("marvell,armada-3720-espressobin"))
257 return 0;
258
259 spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor");
260 if (spi_off < 0)
261 return 0;
262
263 /* Do not touch partitions if they are already defined */
264 if (fdt_subnode_offset(blob, spi_off, "partitions") >= 0)
265 return 0;
266
267 parts_off = fdt_add_subnode(blob, spi_off, "partitions");
268 if (parts_off < 0) {
269 printf("Can't add partitions node: %s\n", fdt_strerror(parts_off));
270 return 0;
271 }
272
273 ret = fdt_setprop_string(blob, parts_off, "compatible", "fixed-partitions");
274 if (ret < 0) {
275 printf("Can't set compatible property: %s\n", fdt_strerror(ret));
276 return 0;
277 }
278
279 ret = fdt_setprop_u32(blob, parts_off, "#address-cells", 1);
280 if (ret < 0) {
281 printf("Can't set #address-cells property: %s\n", fdt_strerror(ret));
282 return 0;
283 }
284
285 ret = fdt_setprop_u32(blob, parts_off, "#size-cells", 1);
286 if (ret < 0) {
287 printf("Can't set #size-cells property: %s\n", fdt_strerror(ret));
288 return 0;
289 }
290
291 /* Add u-boot-env partition */
292
293 part_off = fdt_add_subnode(blob, parts_off, "partition@u-boot-env");
294 if (part_off < 0) {
295 printf("Can't add partition@u-boot-env node: %s\n", fdt_strerror(part_off));
296 return 0;
297 }
298
299 ret = fdt_setprop_u32(blob, part_off, "reg", CONFIG_ENV_OFFSET);
300 if (ret < 0) {
301 printf("Can't set partition@u-boot-env reg property: %s\n", fdt_strerror(ret));
302 return 0;
303 }
304
305 ret = fdt_appendprop_u32(blob, part_off, "reg", CONFIG_ENV_SIZE);
306 if (ret < 0) {
307 printf("Can't set partition@u-boot-env reg property: %s\n", fdt_strerror(ret));
308 return 0;
309 }
310
311 ret = fdt_setprop_string(blob, part_off, "label", "u-boot-env");
312 if (ret < 0) {
313 printf("Can't set partition@u-boot-env label property: %s\n", fdt_strerror(ret));
314 return 0;
315 }
316
317 /* Add firmware partition */
318
319 part_off = fdt_add_subnode(blob, parts_off, "partition@firmware");
320 if (part_off < 0) {
321 printf("Can't add partition@firmware node: %s\n", fdt_strerror(part_off));
322 return 0;
323 }
324
325 ret = fdt_setprop_u32(blob, part_off, "reg", 0);
326 if (ret < 0) {
327 printf("Can't set partition@firmware reg property: %s\n", fdt_strerror(ret));
328 return 0;
329 }
330
331 ret = fdt_appendprop_u32(blob, part_off, "reg", CONFIG_ENV_OFFSET);
332 if (ret < 0) {
333 printf("Can't set partition@firmware reg property: %s\n", fdt_strerror(ret));
334 return 0;
335 }
336
337 ret = fdt_setprop_string(blob, part_off, "label", "firmware");
338 if (ret < 0) {
339 printf("Can't set partition@firmware label property: %s\n", fdt_strerror(ret));
340 return 0;
341 }
342
343 return 0;
344}
345#endif