blob: 03c489c014a482eb4f7c66dcc0fbd962f4110ba1 [file] [log] [blame]
Prafulla Wadaskar1d8937a2009-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 Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Prafulla Wadaskar1d8937a2009-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 Roesefe11ae22015-06-29 14:58:15 +020013#include <linux/mbus.h>
Lei Wena7efd712011-10-18 20:11:42 +053014#include <asm/arch/cpu.h>
Albert ARIBAUD805ad7e2012-01-15 22:08:40 +000015
16#if defined(CONFIG_KIRKWOOD)
Stefan Roese3dc23f72014-10-22 12:13:06 +020017#include <asm/arch/soc.h>
Albert ARIBAUD805ad7e2012-01-15 22:08:40 +000018#elif defined(CONFIG_ORION5X)
19#include <asm/arch/orion5x.h>
20#endif
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +053021
Albert ARIBAUD74d34422012-01-15 22:08:39 +000022DECLARE_GLOBAL_DATA_PTR;
23
24#define rdl(off) readl(MVUSB0_BASE + (off))
25#define wrl(off, val) writel((val), MVUSB0_BASE + (off))
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +053026
27#define USB_WINDOW_CTRL(i) (0x320 + ((i) << 4))
28#define USB_WINDOW_BASE(i) (0x324 + ((i) << 4))
29#define USB_TARGET_DRAM 0x0
30
31/*
32 * USB 2.0 Bridge Address Decoding registers setup
33 */
Stefan Roesefe11ae22015-06-29 14:58:15 +020034#ifdef CONFIG_ARMADA_XP
35
36#define MVUSB0_BASE MVEBU_USB20_BASE
37
38/*
39 * Once all the older Marvell SoC's (Orion, Kirkwood) are converted
40 * to the common mvebu archticture including the mbus setup, this
41 * will be the only function needed to configure the access windows
42 */
43static void usb_brg_adrdec_setup(void)
44{
45 const struct mbus_dram_target_info *dram;
46 int i;
47
48 dram = mvebu_mbus_dram_info();
49
50 for (i = 0; i < 4; i++) {
51 wrl(USB_WINDOW_CTRL(i), 0);
52 wrl(USB_WINDOW_BASE(i), 0);
53 }
54
55 for (i = 0; i < dram->num_cs; i++) {
56 const struct mbus_dram_window *cs = dram->cs + i;
57
58 /* Write size, attributes and target id to control register */
59 wrl(USB_WINDOW_CTRL(i),
60 ((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
61 (dram->mbus_dram_target_id << 4) | 1);
62
63 /* Write base address to base register */
64 wrl(USB_WINDOW_BASE(i), cs->base);
65 }
66}
67#else
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +053068static void usb_brg_adrdec_setup(void)
69{
70 int i;
Albert ARIBAUD74d34422012-01-15 22:08:39 +000071 u32 size, base, attrib;
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +053072
73 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
74
75 /* Enable DRAM bank */
76 switch (i) {
77 case 0:
Albert ARIBAUD74d34422012-01-15 22:08:39 +000078 attrib = MVUSB0_CPU_ATTR_DRAM_CS0;
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +053079 break;
80 case 1:
Albert ARIBAUD74d34422012-01-15 22:08:39 +000081 attrib = MVUSB0_CPU_ATTR_DRAM_CS1;
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +053082 break;
83 case 2:
Albert ARIBAUD74d34422012-01-15 22:08:39 +000084 attrib = MVUSB0_CPU_ATTR_DRAM_CS2;
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +053085 break;
86 case 3:
Albert ARIBAUD74d34422012-01-15 22:08:39 +000087 attrib = MVUSB0_CPU_ATTR_DRAM_CS3;
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +053088 break;
89 default:
90 /* invalide bank, disable access */
91 attrib = 0;
92 break;
93 }
94
Albert ARIBAUD74d34422012-01-15 22:08:39 +000095 size = gd->bd->bi_dram[i].size;
96 base = gd->bd->bi_dram[i].start;
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +053097 if ((size) && (attrib))
98 wrl(USB_WINDOW_CTRL(i),
Albert ARIBAUD74d34422012-01-15 22:08:39 +000099 MVCPU_WIN_CTRL_DATA(size, USB_TARGET_DRAM,
100 attrib, MVCPU_WIN_ENABLE));
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +0530101 else
Albert ARIBAUD74d34422012-01-15 22:08:39 +0000102 wrl(USB_WINDOW_CTRL(i), MVCPU_WIN_DISABLE);
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +0530103
Albert ARIBAUD74d34422012-01-15 22:08:39 +0000104 wrl(USB_WINDOW_BASE(i), base);
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +0530105 }
106}
Stefan Roesefe11ae22015-06-29 14:58:15 +0200107#endif
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +0530108
109/*
110 * Create the appropriate control structures to manage
111 * a new EHCI host controller.
112 */
Troy Kisky127efc42013-10-10 15:27:57 -0700113int ehci_hcd_init(int index, enum usb_init_type init,
114 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +0530115{
116 usb_brg_adrdec_setup();
117
Lucas Stach676ae062012-09-26 00:14:35 +0200118 *hccr = (struct ehci_hccr *)(MVUSB0_BASE + 0x100);
119 *hcor = (struct ehci_hcor *)((uint32_t) *hccr
120 + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +0530121
Albert ARIBAUD74d34422012-01-15 22:08:39 +0000122 debug("ehci-marvell: init hccr %x and hcor %x hc_length %d\n",
Lucas Stach676ae062012-09-26 00:14:35 +0200123 (uint32_t)*hccr, (uint32_t)*hcor,
124 (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +0530125
126 return 0;
127}
128
129/*
130 * Destroy the appropriate control structures corresponding
131 * the the EHCI host controller.
132 */
Lucas Stach676ae062012-09-26 00:14:35 +0200133int ehci_hcd_stop(int index)
Prafulla Wadaskar1d8937a2009-06-29 20:56:43 +0530134{
135 return 0;
136}