]> Git Repo - J-u-boot.git/blame - drivers/usb/host/ehci-marvell.c
rockchip: block: simplify rkmtd driver
[J-u-boot.git] / drivers / usb / host / ehci-marvell.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
1d8937a4
PW
2/*
3 * (C) Copyright 2009
4 * Marvell Semiconductor <www.marvell.com>
5 * Written-by: Prafulla Wadaskar <[email protected]>
1d8937a4
PW
6 */
7
f7ae49fc 8#include <log.h>
401d1c4f 9#include <asm/global_data.h>
1d8937a4
PW
10#include <asm/io.h>
11#include <usb.h>
c05ed00a 12#include <linux/delay.h>
1d8937a4 13#include "ehci.h"
fe11ae24 14#include <linux/mbus.h>
a7efd719 15#include <asm/arch/cpu.h>
cd48225b 16#include <dm.h>
805ad7ee 17
bb0fb4c0 18#if defined(CONFIG_ARCH_KIRKWOOD)
3dc23f78 19#include <asm/arch/soc.h>
b16a3316 20#elif defined(CONFIG_ARCH_ORION5X)
805ad7ee
AA
21#include <asm/arch/orion5x.h>
22#endif
1d8937a4 23
74d34421
AA
24DECLARE_GLOBAL_DATA_PTR;
25
1d8937a4
PW
26#define USB_WINDOW_CTRL(i) (0x320 + ((i) << 4))
27#define USB_WINDOW_BASE(i) (0x324 + ((i) << 4))
28#define USB_TARGET_DRAM 0x0
29
c6cfcc91
SR
30#define USB2_SBUSCFG_OFF 0x90
31
32#define USB_SBUSCFG_BAWR_OFF 0x6
33#define USB_SBUSCFG_BARD_OFF 0x3
34#define USB_SBUSCFG_AHBBRST_OFF 0x0
35
36#define USB_SBUSCFG_BAWR_ALIGN_64B 0x4
37#define USB_SBUSCFG_BARD_ALIGN_64B 0x4
38#define USB_SBUSCFG_AHBBRST_INCR16 0x7
39
1d8937a4
PW
40/*
41 * USB 2.0 Bridge Address Decoding registers setup
42 */
fd09c205 43#if CONFIG_IS_ENABLED(DM_USB)
fe11ae24 44
cd48225b
SR
45struct ehci_mvebu_priv {
46 struct ehci_ctrl ehci;
47 fdt_addr_t hcd_base;
48};
fe11ae24 49
515fe1ee
CP
50#define USB_TO_DRAM_TARGET_ID 0x2
51#define USB_TO_DRAM_ATTR_ID 0x0
52#define USB_DRAM_BASE 0x00000000
53#define USB_DRAM_SIZE 0xfff /* don't overrun u-boot source (was 0xffff) */
54
fe11ae24
SR
55/*
56 * Once all the older Marvell SoC's (Orion, Kirkwood) are converted
57 * to the common mvebu archticture including the mbus setup, this
58 * will be the only function needed to configure the access windows
59 */
515fe1ee 60static void usb_brg_adrdec_setup(struct udevice *dev, void *base)
fe11ae24
SR
61{
62 const struct mbus_dram_target_info *dram;
63 int i;
64
65 dram = mvebu_mbus_dram_info();
66
67 for (i = 0; i < 4; i++) {
cd48225b
SR
68 writel(0, base + USB_WINDOW_CTRL(i));
69 writel(0, base + USB_WINDOW_BASE(i));
fe11ae24
SR
70 }
71
515fe1ee
CP
72 if (device_is_compatible(dev, "marvell,ac5-ehci")) {
73 /*
74 * use decoding window to map dram address seen by usb to 0x0
75 */
fe11ae24
SR
76
77 /* Write size, attributes and target id to control register */
515fe1ee
CP
78 writel((USB_DRAM_SIZE << 16) | (USB_TO_DRAM_ATTR_ID << 8) |
79 (USB_TO_DRAM_TARGET_ID << 4) | 1,
80 base + USB_WINDOW_CTRL(0));
fe11ae24
SR
81
82 /* Write base address to base register */
515fe1ee
CP
83 writel(USB_DRAM_BASE, base + USB_WINDOW_BASE(0));
84
85 debug("## AC5 decoding windows, ctrl[%p]=0x%x, base[%p]=0x%x\n",
86 base + USB_WINDOW_CTRL(0), readl(base + USB_WINDOW_CTRL(0)),
87 base + USB_WINDOW_BASE(0), readl(base + USB_WINDOW_BASE(0)));
88 } else {
89 for (i = 0; i < dram->num_cs; i++) {
90 const struct mbus_dram_window *cs = dram->cs + i;
91
92 /* Write size, attributes and target id to control register */
93 writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
94 (dram->mbus_dram_target_id << 4) | 1,
95 base + USB_WINDOW_CTRL(i));
96
97 /* Write base address to base register */
98 writel(cs->base, base + USB_WINDOW_BASE(i));
99 }
fe11ae24
SR
100 }
101}
cd48225b 102
c6cfcc91
SR
103static void marvell_ehci_powerup_fixup(struct ehci_ctrl *ctrl,
104 uint32_t *status_reg, uint32_t *reg)
105{
106 struct ehci_mvebu_priv *priv = ctrl->priv;
107
108 /*
109 * Set default value for reg SBUSCFG, which is Control for the AMBA
110 * system bus interface:
111 * BAWR = BARD = 4 : Align rd/wr bursts packets larger than 64 bytes
112 * AHBBRST = 7 : Align AHB burst for packets larger than 64 bytes
113 */
114 writel((USB_SBUSCFG_BAWR_ALIGN_64B << USB_SBUSCFG_BAWR_OFF) |
115 (USB_SBUSCFG_BARD_ALIGN_64B << USB_SBUSCFG_BARD_OFF) |
116 (USB_SBUSCFG_AHBBRST_INCR16 << USB_SBUSCFG_AHBBRST_OFF),
117 priv->hcd_base + USB2_SBUSCFG_OFF);
118
119 mdelay(50);
120}
121
122static struct ehci_ops marvell_ehci_ops = {
123 .powerup_fixup = NULL,
124};
125
cd48225b
SR
126static int ehci_mvebu_probe(struct udevice *dev)
127{
128 struct ehci_mvebu_priv *priv = dev_get_priv(dev);
129 struct ehci_hccr *hccr;
130 struct ehci_hcor *hcor;
131
132 /*
133 * Get the base address for EHCI controller from the device node
134 */
2548493a 135 priv->hcd_base = dev_read_addr(dev);
cd48225b
SR
136 if (priv->hcd_base == FDT_ADDR_T_NONE) {
137 debug("Can't get the EHCI register base address\n");
138 return -ENXIO;
139 }
140
c6cfcc91
SR
141 /*
142 * For SoCs without hlock like Armada3700 we need to program the sbuscfg
143 * reg to guarantee AHB master's burst will not overrun or underrun
144 * the FIFO. Otherwise all USB2 write option will fail.
145 * Also, the address decoder doesn't need to get setup with this
146 * SoC, so don't call usb_brg_adrdec_setup().
147 */
af6d0938 148 if (device_is_compatible(dev, "marvell,armada-3700-ehci"))
c6cfcc91
SR
149 marvell_ehci_ops.powerup_fixup = marvell_ehci_powerup_fixup;
150 else
515fe1ee 151 usb_brg_adrdec_setup(dev, (void *)priv->hcd_base);
cd48225b
SR
152
153 hccr = (struct ehci_hccr *)(priv->hcd_base + 0x100);
154 hcor = (struct ehci_hcor *)
c6cfcc91 155 ((uintptr_t)hccr + HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
cd48225b 156
c6cfcc91
SR
157 debug("ehci-marvell: init hccr %lx and hcor %lx hc_length %ld\n",
158 (uintptr_t)hccr, (uintptr_t)hcor,
159 (uintptr_t)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
cd48225b 160
515fe1ee
CP
161#define PHY_CALIB_OFFSET 0x808
162 /*
163 * Trigger calibration during each usb start/reset:
164 * BIT 13 to 0, and then to 1
165 */
166 if (device_is_compatible(dev, "marvell,ac5-ehci")) {
167 void *phy_calib_reg = (void *)(priv->hcd_base + PHY_CALIB_OFFSET);
168 u32 val = readl(phy_calib_reg) & (~BIT(13));
169
170 writel(val, phy_calib_reg);
171 writel(val | BIT(13), phy_calib_reg);
172 }
173
c6cfcc91
SR
174 return ehci_register(dev, hccr, hcor, &marvell_ehci_ops, 0,
175 USB_INIT_HOST);
cd48225b
SR
176}
177
cd48225b
SR
178static const struct udevice_id ehci_usb_ids[] = {
179 { .compatible = "marvell,orion-ehci", },
af6d0938 180 { .compatible = "marvell,armada-3700-ehci", },
515fe1ee 181 { .compatible = "marvell,ac5-ehci", },
cd48225b
SR
182 { }
183};
184
185U_BOOT_DRIVER(ehci_mvebu) = {
186 .name = "ehci_mvebu",
187 .id = UCLASS_USB,
188 .of_match = ehci_usb_ids,
189 .probe = ehci_mvebu_probe,
40527342 190 .remove = ehci_deregister,
cd48225b 191 .ops = &ehci_usb_ops,
8a8d24bd 192 .plat_auto = sizeof(struct usb_plat),
41575d8e 193 .priv_auto = sizeof(struct ehci_mvebu_priv),
cd48225b
SR
194 .flags = DM_FLAG_ALLOC_PRIV_DMA,
195};
196
fe11ae24 197#else
8a333716
AS
198#define MVUSB_BASE(port) MVUSB0_BASE
199
200static void usb_brg_adrdec_setup(int index)
1d8937a4
PW
201{
202 int i;
74d34421 203 u32 size, base, attrib;
1d8937a4
PW
204
205 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
206
207 /* Enable DRAM bank */
208 switch (i) {
209 case 0:
74d34421 210 attrib = MVUSB0_CPU_ATTR_DRAM_CS0;
1d8937a4
PW
211 break;
212 case 1:
74d34421 213 attrib = MVUSB0_CPU_ATTR_DRAM_CS1;
1d8937a4
PW
214 break;
215 case 2:
74d34421 216 attrib = MVUSB0_CPU_ATTR_DRAM_CS2;
1d8937a4
PW
217 break;
218 case 3:
74d34421 219 attrib = MVUSB0_CPU_ATTR_DRAM_CS3;
1d8937a4
PW
220 break;
221 default:
222 /* invalide bank, disable access */
223 attrib = 0;
224 break;
225 }
226
74d34421
AA
227 size = gd->bd->bi_dram[i].size;
228 base = gd->bd->bi_dram[i].start;
1d8937a4 229 if ((size) && (attrib))
82b9143b
SR
230 writel(MVCPU_WIN_CTRL_DATA(size, USB_TARGET_DRAM,
231 attrib, MVCPU_WIN_ENABLE),
232 MVUSB0_BASE + USB_WINDOW_CTRL(i));
1d8937a4 233 else
82b9143b
SR
234 writel(MVCPU_WIN_DISABLE,
235 MVUSB0_BASE + USB_WINDOW_CTRL(i));
1d8937a4 236
82b9143b 237 writel(base, MVUSB0_BASE + USB_WINDOW_BASE(i));
1d8937a4
PW
238 }
239}
240
241/*
242 * Create the appropriate control structures to manage
243 * a new EHCI host controller.
244 */
127efc4f
TK
245int ehci_hcd_init(int index, enum usb_init_type init,
246 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
1d8937a4 247{
8a333716 248 usb_brg_adrdec_setup(index);
1d8937a4 249
8a333716 250 *hccr = (struct ehci_hccr *)(MVUSB_BASE(index) + 0x100);
676ae068
LS
251 *hcor = (struct ehci_hcor *)((uint32_t) *hccr
252 + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
1d8937a4 253
74d34421 254 debug("ehci-marvell: init hccr %x and hcor %x hc_length %d\n",
676ae068
LS
255 (uint32_t)*hccr, (uint32_t)*hcor,
256 (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
1d8937a4
PW
257
258 return 0;
259}
260
261/*
262 * Destroy the appropriate control structures corresponding
263 * the the EHCI host controller.
264 */
676ae068 265int ehci_hcd_stop(int index)
1d8937a4
PW
266{
267 return 0;
268}
cd48225b 269
fd09c205 270#endif /* CONFIG_IS_ENABLED(DM_USB) */
This page took 0.629028 seconds and 4 git commands to generate.