blob: 3ecbfd032ff86a9cdcd5e2b34c4438c5ec82f3c9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +05302/*
3 * (C) Copyright 2009
4 * Marvell Semiconductor <www.marvell.com>
5 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +05306 */
7
8#include <common.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053010#include <asm/io.h>
11#include <usb.h>
Simon Glassdbd79542020-05-10 11:40:11 -060012#include <linux/delay.h>
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053013#include "ehci.h"
Stefan Roese9aa31972015-06-29 14:58:15 +020014#include <linux/mbus.h>
Lei Wen298ae912011-10-18 20:11:42 +053015#include <asm/arch/cpu.h>
Stefan Roese03901022015-09-01 11:39:44 +020016#include <dm.h>
Albert ARIBAUD994bca22012-01-15 22:08:40 +000017
Trevor Woernerbb7ab072020-05-06 08:02:40 -040018#if defined(CONFIG_ARCH_KIRKWOOD)
Stefan Roesec2437842014-10-22 12:13:06 +020019#include <asm/arch/soc.h>
Trevor Woernerf9953752020-05-06 08:02:38 -040020#elif defined(CONFIG_ARCH_ORION5X)
Albert ARIBAUD994bca22012-01-15 22:08:40 +000021#include <asm/arch/orion5x.h>
22#endif
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053023
Albert ARIBAUDc3c76452012-01-15 22:08:39 +000024DECLARE_GLOBAL_DATA_PTR;
25
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053026#define USB_WINDOW_CTRL(i) (0x320 + ((i) << 4))
27#define USB_WINDOW_BASE(i) (0x324 + ((i) << 4))
28#define USB_TARGET_DRAM 0x0
29
Stefan Roese46b9db52016-07-18 17:24:56 +020030#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
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053040/*
41 * USB 2.0 Bridge Address Decoding registers setup
42 */
Sven Schwermer8a3cb9f12018-11-21 08:43:56 +010043#if CONFIG_IS_ENABLED(DM_USB)
Stefan Roese9aa31972015-06-29 14:58:15 +020044
Stefan Roese03901022015-09-01 11:39:44 +020045struct ehci_mvebu_priv {
46 struct ehci_ctrl ehci;
47 fdt_addr_t hcd_base;
48};
Stefan Roese9aa31972015-06-29 14:58:15 +020049
50/*
51 * Once all the older Marvell SoC's (Orion, Kirkwood) are converted
52 * to the common mvebu archticture including the mbus setup, this
53 * will be the only function needed to configure the access windows
54 */
Stefan Roese46b9db52016-07-18 17:24:56 +020055static void usb_brg_adrdec_setup(void *base)
Stefan Roese9aa31972015-06-29 14:58:15 +020056{
57 const struct mbus_dram_target_info *dram;
58 int i;
59
60 dram = mvebu_mbus_dram_info();
61
62 for (i = 0; i < 4; i++) {
Stefan Roese03901022015-09-01 11:39:44 +020063 writel(0, base + USB_WINDOW_CTRL(i));
64 writel(0, base + USB_WINDOW_BASE(i));
Stefan Roese9aa31972015-06-29 14:58:15 +020065 }
66
67 for (i = 0; i < dram->num_cs; i++) {
68 const struct mbus_dram_window *cs = dram->cs + i;
69
70 /* Write size, attributes and target id to control register */
Stefan Roese44123cf2015-07-22 10:01:30 +020071 writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
72 (dram->mbus_dram_target_id << 4) | 1,
Stefan Roese03901022015-09-01 11:39:44 +020073 base + USB_WINDOW_CTRL(i));
Stefan Roese9aa31972015-06-29 14:58:15 +020074
75 /* Write base address to base register */
Stefan Roese03901022015-09-01 11:39:44 +020076 writel(cs->base, base + USB_WINDOW_BASE(i));
77 }
78}
79
Stefan Roese46b9db52016-07-18 17:24:56 +020080static void marvell_ehci_powerup_fixup(struct ehci_ctrl *ctrl,
81 uint32_t *status_reg, uint32_t *reg)
82{
83 struct ehci_mvebu_priv *priv = ctrl->priv;
84
85 /*
86 * Set default value for reg SBUSCFG, which is Control for the AMBA
87 * system bus interface:
88 * BAWR = BARD = 4 : Align rd/wr bursts packets larger than 64 bytes
89 * AHBBRST = 7 : Align AHB burst for packets larger than 64 bytes
90 */
91 writel((USB_SBUSCFG_BAWR_ALIGN_64B << USB_SBUSCFG_BAWR_OFF) |
92 (USB_SBUSCFG_BARD_ALIGN_64B << USB_SBUSCFG_BARD_OFF) |
93 (USB_SBUSCFG_AHBBRST_INCR16 << USB_SBUSCFG_AHBBRST_OFF),
94 priv->hcd_base + USB2_SBUSCFG_OFF);
95
96 mdelay(50);
97}
98
99static struct ehci_ops marvell_ehci_ops = {
100 .powerup_fixup = NULL,
101};
102
Stefan Roese03901022015-09-01 11:39:44 +0200103static int ehci_mvebu_probe(struct udevice *dev)
104{
105 struct ehci_mvebu_priv *priv = dev_get_priv(dev);
106 struct ehci_hccr *hccr;
107 struct ehci_hcor *hcor;
108
109 /*
110 * Get the base address for EHCI controller from the device node
111 */
Masahiro Yamadaa89b4de2020-07-17 14:36:48 +0900112 priv->hcd_base = dev_read_addr(dev);
Stefan Roese03901022015-09-01 11:39:44 +0200113 if (priv->hcd_base == FDT_ADDR_T_NONE) {
114 debug("Can't get the EHCI register base address\n");
115 return -ENXIO;
Stefan Roese9aa31972015-06-29 14:58:15 +0200116 }
Stefan Roese03901022015-09-01 11:39:44 +0200117
Stefan Roese46b9db52016-07-18 17:24:56 +0200118 /*
119 * For SoCs without hlock like Armada3700 we need to program the sbuscfg
120 * reg to guarantee AHB master's burst will not overrun or underrun
121 * the FIFO. Otherwise all USB2 write option will fail.
122 * Also, the address decoder doesn't need to get setup with this
123 * SoC, so don't call usb_brg_adrdec_setup().
124 */
Simon Glass54cbcc82017-05-18 20:08:57 -0600125 if (device_is_compatible(dev, "marvell,armada3700-ehci"))
Stefan Roese46b9db52016-07-18 17:24:56 +0200126 marvell_ehci_ops.powerup_fixup = marvell_ehci_powerup_fixup;
127 else
128 usb_brg_adrdec_setup((void *)priv->hcd_base);
Stefan Roese03901022015-09-01 11:39:44 +0200129
130 hccr = (struct ehci_hccr *)(priv->hcd_base + 0x100);
131 hcor = (struct ehci_hcor *)
Stefan Roese46b9db52016-07-18 17:24:56 +0200132 ((uintptr_t)hccr + HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
Stefan Roese03901022015-09-01 11:39:44 +0200133
Stefan Roese46b9db52016-07-18 17:24:56 +0200134 debug("ehci-marvell: init hccr %lx and hcor %lx hc_length %ld\n",
135 (uintptr_t)hccr, (uintptr_t)hcor,
136 (uintptr_t)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
Stefan Roese03901022015-09-01 11:39:44 +0200137
Stefan Roese46b9db52016-07-18 17:24:56 +0200138 return ehci_register(dev, hccr, hcor, &marvell_ehci_ops, 0,
139 USB_INIT_HOST);
Stefan Roese03901022015-09-01 11:39:44 +0200140}
141
Stefan Roese03901022015-09-01 11:39:44 +0200142static const struct udevice_id ehci_usb_ids[] = {
143 { .compatible = "marvell,orion-ehci", },
Stefan Roese46b9db52016-07-18 17:24:56 +0200144 { .compatible = "marvell,armada3700-ehci", },
Stefan Roese03901022015-09-01 11:39:44 +0200145 { }
146};
147
148U_BOOT_DRIVER(ehci_mvebu) = {
149 .name = "ehci_mvebu",
150 .id = UCLASS_USB,
151 .of_match = ehci_usb_ids,
152 .probe = ehci_mvebu_probe,
Masahiro Yamadad41919b2016-09-06 22:17:34 +0900153 .remove = ehci_deregister,
Stefan Roese03901022015-09-01 11:39:44 +0200154 .ops = &ehci_usb_ops,
Simon Glassb75b15b2020-12-03 16:55:23 -0700155 .plat_auto = sizeof(struct usb_plat),
Simon Glass8a2b47f2020-12-03 16:55:17 -0700156 .priv_auto = sizeof(struct ehci_mvebu_priv),
Stefan Roese03901022015-09-01 11:39:44 +0200157 .flags = DM_FLAG_ALLOC_PRIV_DMA,
158};
159
Stefan Roese9aa31972015-06-29 14:58:15 +0200160#else
Anton Schubert11b8ebf2015-07-23 15:02:09 +0200161#define MVUSB_BASE(port) MVUSB0_BASE
162
163static void usb_brg_adrdec_setup(int index)
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530164{
165 int i;
Albert ARIBAUDc3c76452012-01-15 22:08:39 +0000166 u32 size, base, attrib;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530167
168 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
169
170 /* Enable DRAM bank */
171 switch (i) {
172 case 0:
Albert ARIBAUDc3c76452012-01-15 22:08:39 +0000173 attrib = MVUSB0_CPU_ATTR_DRAM_CS0;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530174 break;
175 case 1:
Albert ARIBAUDc3c76452012-01-15 22:08:39 +0000176 attrib = MVUSB0_CPU_ATTR_DRAM_CS1;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530177 break;
178 case 2:
Albert ARIBAUDc3c76452012-01-15 22:08:39 +0000179 attrib = MVUSB0_CPU_ATTR_DRAM_CS2;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530180 break;
181 case 3:
Albert ARIBAUDc3c76452012-01-15 22:08:39 +0000182 attrib = MVUSB0_CPU_ATTR_DRAM_CS3;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530183 break;
184 default:
185 /* invalide bank, disable access */
186 attrib = 0;
187 break;
188 }
189
Albert ARIBAUDc3c76452012-01-15 22:08:39 +0000190 size = gd->bd->bi_dram[i].size;
191 base = gd->bd->bi_dram[i].start;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530192 if ((size) && (attrib))
Stefan Roese44123cf2015-07-22 10:01:30 +0200193 writel(MVCPU_WIN_CTRL_DATA(size, USB_TARGET_DRAM,
194 attrib, MVCPU_WIN_ENABLE),
195 MVUSB0_BASE + USB_WINDOW_CTRL(i));
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530196 else
Stefan Roese44123cf2015-07-22 10:01:30 +0200197 writel(MVCPU_WIN_DISABLE,
198 MVUSB0_BASE + USB_WINDOW_CTRL(i));
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530199
Stefan Roese44123cf2015-07-22 10:01:30 +0200200 writel(base, MVUSB0_BASE + USB_WINDOW_BASE(i));
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530201 }
202}
203
204/*
205 * Create the appropriate control structures to manage
206 * a new EHCI host controller.
207 */
Troy Kisky7d6bbb92013-10-10 15:27:57 -0700208int ehci_hcd_init(int index, enum usb_init_type init,
209 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530210{
Anton Schubert11b8ebf2015-07-23 15:02:09 +0200211 usb_brg_adrdec_setup(index);
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530212
Anton Schubert11b8ebf2015-07-23 15:02:09 +0200213 *hccr = (struct ehci_hccr *)(MVUSB_BASE(index) + 0x100);
Lucas Stach3494a4c2012-09-26 00:14:35 +0200214 *hcor = (struct ehci_hcor *)((uint32_t) *hccr
215 + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530216
Albert ARIBAUDc3c76452012-01-15 22:08:39 +0000217 debug("ehci-marvell: init hccr %x and hcor %x hc_length %d\n",
Lucas Stach3494a4c2012-09-26 00:14:35 +0200218 (uint32_t)*hccr, (uint32_t)*hcor,
219 (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530220
221 return 0;
222}
223
224/*
225 * Destroy the appropriate control structures corresponding
226 * the the EHCI host controller.
227 */
Lucas Stach3494a4c2012-09-26 00:14:35 +0200228int ehci_hcd_stop(int index)
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530229{
230 return 0;
231}
Stefan Roese03901022015-09-01 11:39:44 +0200232
Sven Schwermer8a3cb9f12018-11-21 08:43:56 +0100233#endif /* CONFIG_IS_ENABLED(DM_USB) */