blob: bf8a929ec1e6d2f4c14f41552d72eac4d2bc15aa [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese7be1b9b2016-05-25 08:21:21 +02002/*
3 * Copyright (C) 2016 Stefan Roese <sr@denx.de>
Stefan Roese7be1b9b2016-05-25 08:21:21 +02004 */
5
6#include <common.h>
Stefan Roeseb961b862016-10-25 12:41:45 +02007#include <dm.h>
Stefan Roese7be1b9b2016-05-25 08:21:21 +02008#include <i2c.h>
Simon Glassa7b51302019-11-14 12:57:46 -07009#include <init.h>
Stefan Roese7be1b9b2016-05-25 08:21:21 +020010#include <asm/io.h>
11#include <asm/arch/cpu.h>
12#include <asm/arch/soc.h>
Simon Glassdbd79542020-05-10 11:40:11 -060013#include <linux/delay.h>
Stefan Roese7be1b9b2016-05-25 08:21:21 +020014
15DECLARE_GLOBAL_DATA_PTR;
16
Stefan Roeseb961b862016-10-25 12:41:45 +020017/*
18 * Information specific to the DB-88F7040 eval board. We strive to use
19 * DT for such platform specfic configurations. At some point, this
20 * might be removed here and implemented via DT.
21 */
Stefan Roese7be1b9b2016-05-25 08:21:21 +020022/* IO expander I2C device */
23#define I2C_IO_EXP_ADDR 0x21
24#define I2C_IO_CFG_REG_0 0x6
25#define I2C_IO_DATA_OUT_REG_0 0x2
26/* VBus enable */
27#define I2C_IO_REG_0_USB_H0_OFF 0
28#define I2C_IO_REG_0_USB_H1_OFF 1
29#define I2C_IO_REG_VBUS ((1 << I2C_IO_REG_0_USB_H0_OFF) | \
30 (1 << I2C_IO_REG_0_USB_H1_OFF))
31/* Current limit */
32#define I2C_IO_REG_0_USB_H0_CL 4
33#define I2C_IO_REG_0_USB_H1_CL 5
34#define I2C_IO_REG_CL ((1 << I2C_IO_REG_0_USB_H0_CL) | \
35 (1 << I2C_IO_REG_0_USB_H1_CL))
36
Luka Kovacic1f790c62020-08-29 00:35:51 +020037/*
38 * Information specific to the iEi Puzzle-M801 board.
39 */
40
41/* Internal configuration registers */
42#define CP1_CONF_REG_BASE 0xf4440000
43#define CONF_REG_MPP0 0x0
44#define CONF_REG_MPP1 0x4
45#define CONF_REG_MPP2 0x8
46#define CONF_REG_MPP3 0xC
47
Stefan Roese7be1b9b2016-05-25 08:21:21 +020048static int usb_enabled = 0;
49
50/* Board specific xHCI dis-/enable code */
51
52/*
53 * Set USB VBUS signals (via I2C IO expander/GPIO) as output and set
54 * output value as disabled
55 *
56 * Set USB Current Limit signals (via I2C IO expander/GPIO) as output
57 * and set output value as enabled
58 */
59int board_xhci_config(void)
60{
61 struct udevice *dev;
62 int ret;
63 u8 buf[8];
64
Stefan Roeseb961b862016-10-25 12:41:45 +020065 if (of_machine_is_compatible("marvell,armada7040-db")) {
66 /* Configure IO exander PCA9555: 7bit address 0x21 */
67 ret = i2c_get_chip_for_busnum(0, I2C_IO_EXP_ADDR, 1, &dev);
68 if (ret) {
69 printf("Cannot find PCA9555: %d\n", ret);
70 return 0;
71 }
Stefan Roese7be1b9b2016-05-25 08:21:21 +020072
Stefan Roeseb961b862016-10-25 12:41:45 +020073 /*
74 * Read configuration (direction) and set VBUS pin as output
75 * (reset pin = output)
76 */
77 ret = dm_i2c_read(dev, I2C_IO_CFG_REG_0, buf, 1);
78 if (ret) {
79 printf("Failed to read IO expander value via I2C\n");
80 return -EIO;
81 }
82 buf[0] &= ~I2C_IO_REG_VBUS;
83 buf[0] &= ~I2C_IO_REG_CL;
84 ret = dm_i2c_write(dev, I2C_IO_CFG_REG_0, buf, 1);
85 if (ret) {
86 printf("Failed to set IO expander via I2C\n");
87 return -EIO;
88 }
Stefan Roese7be1b9b2016-05-25 08:21:21 +020089
Stefan Roeseb961b862016-10-25 12:41:45 +020090 /* Read output value and configure it */
91 ret = dm_i2c_read(dev, I2C_IO_DATA_OUT_REG_0, buf, 1);
92 if (ret) {
93 printf("Failed to read IO expander value via I2C\n");
94 return -EIO;
95 }
96 buf[0] &= ~I2C_IO_REG_VBUS;
97 buf[0] |= I2C_IO_REG_CL;
98 ret = dm_i2c_write(dev, I2C_IO_DATA_OUT_REG_0, buf, 1);
99 if (ret) {
100 printf("Failed to set IO expander via I2C\n");
101 return -EIO;
102 }
Stefan Roese7be1b9b2016-05-25 08:21:21 +0200103
Stefan Roeseb961b862016-10-25 12:41:45 +0200104 mdelay(500); /* required delay to let output value settle */
105 }
Stefan Roese7be1b9b2016-05-25 08:21:21 +0200106
107 return 0;
108}
109
Jon Nettletona81f47c2017-11-06 10:33:19 +0200110int board_xhci_enable(fdt_addr_t base)
Stefan Roese7be1b9b2016-05-25 08:21:21 +0200111{
112 struct udevice *dev;
113 int ret;
114 u8 buf[8];
115
Stefan Roeseb961b862016-10-25 12:41:45 +0200116 if (of_machine_is_compatible("marvell,armada7040-db")) {
117 /*
118 * This function enables all USB ports simultaniously,
119 * it only needs to get called once
120 */
121 if (usb_enabled)
122 return 0;
Stefan Roese7be1b9b2016-05-25 08:21:21 +0200123
Stefan Roeseb961b862016-10-25 12:41:45 +0200124 /* Configure IO exander PCA9555: 7bit address 0x21 */
125 ret = i2c_get_chip_for_busnum(0, I2C_IO_EXP_ADDR, 1, &dev);
126 if (ret) {
127 printf("Cannot find PCA9555: %d\n", ret);
128 return 0;
129 }
Stefan Roese7be1b9b2016-05-25 08:21:21 +0200130
Stefan Roeseb961b862016-10-25 12:41:45 +0200131 /* Read VBUS output value */
132 ret = dm_i2c_read(dev, I2C_IO_DATA_OUT_REG_0, buf, 1);
133 if (ret) {
134 printf("Failed to read IO expander value via I2C\n");
135 return -EIO;
136 }
Stefan Roese7be1b9b2016-05-25 08:21:21 +0200137
Stefan Roeseb961b862016-10-25 12:41:45 +0200138 /* Enable VBUS power: Set output value of VBUS pin as enabled */
139 buf[0] |= I2C_IO_REG_VBUS;
140 ret = dm_i2c_write(dev, I2C_IO_DATA_OUT_REG_0, buf, 1);
141 if (ret) {
142 printf("Failed to set IO expander via I2C\n");
143 return -EIO;
144 }
Stefan Roese7be1b9b2016-05-25 08:21:21 +0200145
Stefan Roeseb961b862016-10-25 12:41:45 +0200146 mdelay(500); /* required delay to let output value settle */
147 usb_enabled = 1;
148 }
Stefan Roese7be1b9b2016-05-25 08:21:21 +0200149
150 return 0;
151}
152
153int board_early_init_f(void)
154{
Luka Kovacic1f790c62020-08-29 00:35:51 +0200155 /* Initialize some platform specific memory locations */
156 if (of_machine_is_compatible("marvell,armada8040-puzzle-m801")) {
157 /* MPP setup */
158 writel(0x00444444, CP1_CONF_REG_BASE + CONF_REG_MPP0);
159 writel(0x00000000, CP1_CONF_REG_BASE + CONF_REG_MPP1);
160 writel(0x00000000, CP1_CONF_REG_BASE + CONF_REG_MPP2);
161 writel(0x08888000, CP1_CONF_REG_BASE + CONF_REG_MPP3);
162 }
Stefan Roese7be1b9b2016-05-25 08:21:21 +0200163
164 return 0;
165}
166
167int board_init(void)
168{
169 /* adress of boot parameters */
170 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
171
172 return 0;
173}
174
175int board_late_init(void)
176{
177 /* Pre-configure the USB ports (overcurrent, VBus) */
178 board_xhci_config();
179
180 return 0;
181}