blob: 1a5fd6eefc296bfee80552530cbb7237dffd3792 [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"
Lei Wen298ae912011-10-18 20:11:42 +053013#include <asm/arch/cpu.h>
Albert ARIBAUD994bca22012-01-15 22:08:40 +000014
15#if defined(CONFIG_KIRKWOOD)
Stefan Roesec2437842014-10-22 12:13:06 +020016#include <asm/arch/soc.h>
Albert ARIBAUD994bca22012-01-15 22:08:40 +000017#elif defined(CONFIG_ORION5X)
18#include <asm/arch/orion5x.h>
19#endif
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053020
Albert ARIBAUDc3c76452012-01-15 22:08:39 +000021DECLARE_GLOBAL_DATA_PTR;
22
23#define rdl(off) readl(MVUSB0_BASE + (off))
24#define wrl(off, val) writel((val), MVUSB0_BASE + (off))
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053025
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
30/*
31 * USB 2.0 Bridge Address Decoding registers setup
32 */
33static void usb_brg_adrdec_setup(void)
34{
35 int i;
Albert ARIBAUDc3c76452012-01-15 22:08:39 +000036 u32 size, base, attrib;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053037
38 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
39
40 /* Enable DRAM bank */
41 switch (i) {
42 case 0:
Albert ARIBAUDc3c76452012-01-15 22:08:39 +000043 attrib = MVUSB0_CPU_ATTR_DRAM_CS0;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053044 break;
45 case 1:
Albert ARIBAUDc3c76452012-01-15 22:08:39 +000046 attrib = MVUSB0_CPU_ATTR_DRAM_CS1;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053047 break;
48 case 2:
Albert ARIBAUDc3c76452012-01-15 22:08:39 +000049 attrib = MVUSB0_CPU_ATTR_DRAM_CS2;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053050 break;
51 case 3:
Albert ARIBAUDc3c76452012-01-15 22:08:39 +000052 attrib = MVUSB0_CPU_ATTR_DRAM_CS3;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053053 break;
54 default:
55 /* invalide bank, disable access */
56 attrib = 0;
57 break;
58 }
59
Albert ARIBAUDc3c76452012-01-15 22:08:39 +000060 size = gd->bd->bi_dram[i].size;
61 base = gd->bd->bi_dram[i].start;
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053062 if ((size) && (attrib))
63 wrl(USB_WINDOW_CTRL(i),
Albert ARIBAUDc3c76452012-01-15 22:08:39 +000064 MVCPU_WIN_CTRL_DATA(size, USB_TARGET_DRAM,
65 attrib, MVCPU_WIN_ENABLE));
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053066 else
Albert ARIBAUDc3c76452012-01-15 22:08:39 +000067 wrl(USB_WINDOW_CTRL(i), MVCPU_WIN_DISABLE);
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053068
Albert ARIBAUDc3c76452012-01-15 22:08:39 +000069 wrl(USB_WINDOW_BASE(i), base);
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053070 }
71}
72
73/*
74 * Create the appropriate control structures to manage
75 * a new EHCI host controller.
76 */
Troy Kisky7d6bbb92013-10-10 15:27:57 -070077int ehci_hcd_init(int index, enum usb_init_type init,
78 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053079{
80 usb_brg_adrdec_setup();
81
Lucas Stach3494a4c2012-09-26 00:14:35 +020082 *hccr = (struct ehci_hccr *)(MVUSB0_BASE + 0x100);
83 *hcor = (struct ehci_hcor *)((uint32_t) *hccr
84 + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053085
Albert ARIBAUDc3c76452012-01-15 22:08:39 +000086 debug("ehci-marvell: init hccr %x and hcor %x hc_length %d\n",
Lucas Stach3494a4c2012-09-26 00:14:35 +020087 (uint32_t)*hccr, (uint32_t)*hcor,
88 (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053089
90 return 0;
91}
92
93/*
94 * Destroy the appropriate control structures corresponding
95 * the the EHCI host controller.
96 */
Lucas Stach3494a4c2012-09-26 00:14:35 +020097int ehci_hcd_stop(int index)
Prafulla Wadaskar46c54fd2009-06-29 20:56:43 +053098{
99 return 0;
100}