blob: 5b0f46aaef878a4e8e80effcf26762d1b4a6d3ab [file] [log] [blame]
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +05301/*
2 * (C) Copyright 2009
3 * Marvell Semiconductor <www.marvell.com>
4 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
5 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +05307 */
8
9#include <common.h>
10#include <asm/io.h>
11#include <usb.h>
12#include "ehci.h"
Stefan Roese9aa31972015-06-29 14:58:15 +020013#include <linux/mbus.h>
Lei Wen298ae912011-10-18 20:11:42 +053014#include <asm/arch/cpu.h>
Stefan Roese03901022015-09-01 11:39:44 +020015#include <dm.h>
Albert ARIBAUD994bca22012-01-15 22:08:40 +000016
17#if defined(CONFIG_KIRKWOOD)
Stefan Roesec2437842014-10-22 12:13:06 +020018#include <asm/arch/soc.h>
Albert ARIBAUD994bca22012-01-15 22:08:40 +000019#elif defined(CONFIG_ORION5X)
20#include <asm/arch/orion5x.h>
21#endif
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053022
Albert ARIBAUDc3c76452012-01-15 22:08:39 +000023DECLARE_GLOBAL_DATA_PTR;
24
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053025#define USB_WINDOW_CTRL(i) (0x320 + ((i) << 4))
26#define USB_WINDOW_BASE(i) (0x324 + ((i) << 4))
27#define USB_TARGET_DRAM 0x0
28
29/*
30 * USB 2.0 Bridge Address Decoding registers setup
31 */
Stefan Roese03901022015-09-01 11:39:44 +020032#ifdef CONFIG_DM_USB
Stefan Roese9aa31972015-06-29 14:58:15 +020033
Stefan Roese03901022015-09-01 11:39:44 +020034struct ehci_mvebu_priv {
35 struct ehci_ctrl ehci;
36 fdt_addr_t hcd_base;
37};
Stefan Roese9aa31972015-06-29 14:58:15 +020038
39/*
40 * Once all the older Marvell SoC's (Orion, Kirkwood) are converted
41 * to the common mvebu archticture including the mbus setup, this
42 * will be the only function needed to configure the access windows
43 */
Stefan Roese03901022015-09-01 11:39:44 +020044static void usb_brg_adrdec_setup(u32 base)
Stefan Roese9aa31972015-06-29 14:58:15 +020045{
46 const struct mbus_dram_target_info *dram;
47 int i;
48
49 dram = mvebu_mbus_dram_info();
50
51 for (i = 0; i < 4; i++) {
Stefan Roese03901022015-09-01 11:39:44 +020052 writel(0, base + USB_WINDOW_CTRL(i));
53 writel(0, base + USB_WINDOW_BASE(i));
Stefan Roese9aa31972015-06-29 14:58:15 +020054 }
55
56 for (i = 0; i < dram->num_cs; i++) {
57 const struct mbus_dram_window *cs = dram->cs + i;
58
59 /* Write size, attributes and target id to control register */
Stefan Roese44123cf2015-07-22 10:01:30 +020060 writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
61 (dram->mbus_dram_target_id << 4) | 1,
Stefan Roese03901022015-09-01 11:39:44 +020062 base + USB_WINDOW_CTRL(i));
Stefan Roese9aa31972015-06-29 14:58:15 +020063
64 /* Write base address to base register */
Stefan Roese03901022015-09-01 11:39:44 +020065 writel(cs->base, base + USB_WINDOW_BASE(i));
66 }
67}
68
69static int ehci_mvebu_probe(struct udevice *dev)
70{
71 struct ehci_mvebu_priv *priv = dev_get_priv(dev);
72 struct ehci_hccr *hccr;
73 struct ehci_hcor *hcor;
74
75 /*
76 * Get the base address for EHCI controller from the device node
77 */
78 priv->hcd_base = dev_get_addr(dev);
79 if (priv->hcd_base == FDT_ADDR_T_NONE) {
80 debug("Can't get the EHCI register base address\n");
81 return -ENXIO;
Stefan Roese9aa31972015-06-29 14:58:15 +020082 }
Stefan Roese03901022015-09-01 11:39:44 +020083
84 usb_brg_adrdec_setup(priv->hcd_base);
85
86 hccr = (struct ehci_hccr *)(priv->hcd_base + 0x100);
87 hcor = (struct ehci_hcor *)
88 ((u32)hccr + HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
89
90 debug("ehci-marvell: init hccr %x and hcor %x hc_length %d\n",
91 (u32)hccr, (u32)hcor,
92 (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
93
94 return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
95}
96
97static int ehci_mvebu_remove(struct udevice *dev)
98{
99 int ret;
100
101 ret = ehci_deregister(dev);
102 if (ret)
103 return ret;
104
105 return 0;
Stefan Roese9aa31972015-06-29 14:58:15 +0200106}
Stefan Roese03901022015-09-01 11:39:44 +0200107
108static const struct udevice_id ehci_usb_ids[] = {
109 { .compatible = "marvell,orion-ehci", },
110 { }
111};
112
113U_BOOT_DRIVER(ehci_mvebu) = {
114 .name = "ehci_mvebu",
115 .id = UCLASS_USB,
116 .of_match = ehci_usb_ids,
117 .probe = ehci_mvebu_probe,
118 .remove = ehci_mvebu_remove,
119 .ops = &ehci_usb_ops,
120 .platdata_auto_alloc_size = sizeof(struct usb_platdata),
121 .priv_auto_alloc_size = sizeof(struct ehci_mvebu_priv),
122 .flags = DM_FLAG_ALLOC_PRIV_DMA,
123};
124
Stefan Roese9aa31972015-06-29 14:58:15 +0200125#else
Anton Schubert11b8ebf2015-07-23 15:02:09 +0200126#define MVUSB_BASE(port) MVUSB0_BASE
127
128static void usb_brg_adrdec_setup(int index)
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530129{
130 int i;
Albert ARIBAUDc3c76452012-01-15 22:08:39 +0000131 u32 size, base, attrib;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530132
133 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
134
135 /* Enable DRAM bank */
136 switch (i) {
137 case 0:
Albert ARIBAUDc3c76452012-01-15 22:08:39 +0000138 attrib = MVUSB0_CPU_ATTR_DRAM_CS0;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530139 break;
140 case 1:
Albert ARIBAUDc3c76452012-01-15 22:08:39 +0000141 attrib = MVUSB0_CPU_ATTR_DRAM_CS1;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530142 break;
143 case 2:
Albert ARIBAUDc3c76452012-01-15 22:08:39 +0000144 attrib = MVUSB0_CPU_ATTR_DRAM_CS2;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530145 break;
146 case 3:
Albert ARIBAUDc3c76452012-01-15 22:08:39 +0000147 attrib = MVUSB0_CPU_ATTR_DRAM_CS3;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530148 break;
149 default:
150 /* invalide bank, disable access */
151 attrib = 0;
152 break;
153 }
154
Albert ARIBAUDc3c76452012-01-15 22:08:39 +0000155 size = gd->bd->bi_dram[i].size;
156 base = gd->bd->bi_dram[i].start;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530157 if ((size) && (attrib))
Stefan Roese44123cf2015-07-22 10:01:30 +0200158 writel(MVCPU_WIN_CTRL_DATA(size, USB_TARGET_DRAM,
159 attrib, MVCPU_WIN_ENABLE),
160 MVUSB0_BASE + USB_WINDOW_CTRL(i));
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530161 else
Stefan Roese44123cf2015-07-22 10:01:30 +0200162 writel(MVCPU_WIN_DISABLE,
163 MVUSB0_BASE + USB_WINDOW_CTRL(i));
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530164
Stefan Roese44123cf2015-07-22 10:01:30 +0200165 writel(base, MVUSB0_BASE + USB_WINDOW_BASE(i));
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530166 }
167}
168
169/*
170 * Create the appropriate control structures to manage
171 * a new EHCI host controller.
172 */
Troy Kisky7d6bbb92013-10-10 15:27:57 -0700173int ehci_hcd_init(int index, enum usb_init_type init,
174 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530175{
Anton Schubert11b8ebf2015-07-23 15:02:09 +0200176 usb_brg_adrdec_setup(index);
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530177
Anton Schubert11b8ebf2015-07-23 15:02:09 +0200178 *hccr = (struct ehci_hccr *)(MVUSB_BASE(index) + 0x100);
Lucas Stach3494a4c2012-09-26 00:14:35 +0200179 *hcor = (struct ehci_hcor *)((uint32_t) *hccr
180 + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530181
Albert ARIBAUDc3c76452012-01-15 22:08:39 +0000182 debug("ehci-marvell: init hccr %x and hcor %x hc_length %d\n",
Lucas Stach3494a4c2012-09-26 00:14:35 +0200183 (uint32_t)*hccr, (uint32_t)*hcor,
184 (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530185
186 return 0;
187}
188
189/*
190 * Destroy the appropriate control structures corresponding
191 * the the EHCI host controller.
192 */
Lucas Stach3494a4c2012-09-26 00:14:35 +0200193int ehci_hcd_stop(int index)
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +0530194{
195 return 0;
196}
Stefan Roese03901022015-09-01 11:39:44 +0200197
198#endif /* CONFIG_DM_USB */