Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2009 |
| 3 | * Marvell Semiconductor <www.marvell.com> |
| 4 | * Written-by: Prafulla Wadaskar <prafulla@marvell.com> |
| 5 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <usb.h> |
| 12 | #include "ehci.h" |
Stefan Roese | fe11ae2 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 13 | #include <linux/mbus.h> |
Lei Wen | a7efd71 | 2011-10-18 20:11:42 +0530 | [diff] [blame] | 14 | #include <asm/arch/cpu.h> |
Albert ARIBAUD | 805ad7e | 2012-01-15 22:08:40 +0000 | [diff] [blame] | 15 | |
| 16 | #if defined(CONFIG_KIRKWOOD) |
Stefan Roese | 3dc23f7 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 17 | #include <asm/arch/soc.h> |
Albert ARIBAUD | 805ad7e | 2012-01-15 22:08:40 +0000 | [diff] [blame] | 18 | #elif defined(CONFIG_ORION5X) |
| 19 | #include <asm/arch/orion5x.h> |
| 20 | #endif |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 21 | |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 24 | #define USB_WINDOW_CTRL(i) (0x320 + ((i) << 4)) |
| 25 | #define USB_WINDOW_BASE(i) (0x324 + ((i) << 4)) |
| 26 | #define USB_TARGET_DRAM 0x0 |
| 27 | |
| 28 | /* |
| 29 | * USB 2.0 Bridge Address Decoding registers setup |
| 30 | */ |
Stefan Roese | fe11ae2 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 31 | #ifdef CONFIG_ARMADA_XP |
| 32 | |
Stefan Roese | dee40d2 | 2015-07-22 18:26:13 +0200 | [diff] [blame] | 33 | /* |
| 34 | * Armada XP and Armada 38x have different base addresses for |
| 35 | * the USB 2.0 EHCI host controller. So we need to provide |
| 36 | * a mechnism to support both here. |
| 37 | */ |
| 38 | #define MVUSB0_BASE \ |
| 39 | (mvebu_soc_family() == MVEBU_SOC_A38X ? \ |
| 40 | MVEBU_USB20_BASE : MVEBU_AXP_USB_BASE) |
Anton Schubert | 8a33371 | 2015-07-23 15:02:09 +0200 | [diff] [blame] | 41 | #define MVUSB_BASE(port) MVUSB0_BASE + ((port) << 12) |
Stefan Roese | fe11ae2 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * Once all the older Marvell SoC's (Orion, Kirkwood) are converted |
| 45 | * to the common mvebu archticture including the mbus setup, this |
| 46 | * will be the only function needed to configure the access windows |
| 47 | */ |
Anton Schubert | 8a33371 | 2015-07-23 15:02:09 +0200 | [diff] [blame] | 48 | static void usb_brg_adrdec_setup(int index) |
Stefan Roese | fe11ae2 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 49 | { |
| 50 | const struct mbus_dram_target_info *dram; |
| 51 | int i; |
| 52 | |
| 53 | dram = mvebu_mbus_dram_info(); |
| 54 | |
| 55 | for (i = 0; i < 4; i++) { |
Anton Schubert | 8a33371 | 2015-07-23 15:02:09 +0200 | [diff] [blame] | 56 | writel(0, MVUSB_BASE(index) + USB_WINDOW_CTRL(i)); |
| 57 | writel(0, MVUSB_BASE(index) + USB_WINDOW_BASE(i)); |
Stefan Roese | fe11ae2 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | for (i = 0; i < dram->num_cs; i++) { |
| 61 | const struct mbus_dram_window *cs = dram->cs + i; |
| 62 | |
| 63 | /* Write size, attributes and target id to control register */ |
Stefan Roese | 82b9143 | 2015-07-22 10:01:30 +0200 | [diff] [blame] | 64 | writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) | |
| 65 | (dram->mbus_dram_target_id << 4) | 1, |
Anton Schubert | 8a33371 | 2015-07-23 15:02:09 +0200 | [diff] [blame] | 66 | MVUSB_BASE(index) + USB_WINDOW_CTRL(i)); |
Stefan Roese | fe11ae2 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 67 | |
| 68 | /* Write base address to base register */ |
Anton Schubert | 8a33371 | 2015-07-23 15:02:09 +0200 | [diff] [blame] | 69 | writel(cs->base, MVUSB_BASE(index) + USB_WINDOW_BASE(i)); |
Stefan Roese | fe11ae2 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | #else |
Anton Schubert | 8a33371 | 2015-07-23 15:02:09 +0200 | [diff] [blame] | 73 | #define MVUSB_BASE(port) MVUSB0_BASE |
| 74 | |
| 75 | static void usb_brg_adrdec_setup(int index) |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 76 | { |
| 77 | int i; |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 78 | u32 size, base, attrib; |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 79 | |
| 80 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 81 | |
| 82 | /* Enable DRAM bank */ |
| 83 | switch (i) { |
| 84 | case 0: |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 85 | attrib = MVUSB0_CPU_ATTR_DRAM_CS0; |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 86 | break; |
| 87 | case 1: |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 88 | attrib = MVUSB0_CPU_ATTR_DRAM_CS1; |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 89 | break; |
| 90 | case 2: |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 91 | attrib = MVUSB0_CPU_ATTR_DRAM_CS2; |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 92 | break; |
| 93 | case 3: |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 94 | attrib = MVUSB0_CPU_ATTR_DRAM_CS3; |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 95 | break; |
| 96 | default: |
| 97 | /* invalide bank, disable access */ |
| 98 | attrib = 0; |
| 99 | break; |
| 100 | } |
| 101 | |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 102 | size = gd->bd->bi_dram[i].size; |
| 103 | base = gd->bd->bi_dram[i].start; |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 104 | if ((size) && (attrib)) |
Stefan Roese | 82b9143 | 2015-07-22 10:01:30 +0200 | [diff] [blame] | 105 | writel(MVCPU_WIN_CTRL_DATA(size, USB_TARGET_DRAM, |
| 106 | attrib, MVCPU_WIN_ENABLE), |
| 107 | MVUSB0_BASE + USB_WINDOW_CTRL(i)); |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 108 | else |
Stefan Roese | 82b9143 | 2015-07-22 10:01:30 +0200 | [diff] [blame] | 109 | writel(MVCPU_WIN_DISABLE, |
| 110 | MVUSB0_BASE + USB_WINDOW_CTRL(i)); |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 111 | |
Stefan Roese | 82b9143 | 2015-07-22 10:01:30 +0200 | [diff] [blame] | 112 | writel(base, MVUSB0_BASE + USB_WINDOW_BASE(i)); |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 113 | } |
| 114 | } |
Stefan Roese | fe11ae2 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 115 | #endif |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 116 | |
| 117 | /* |
| 118 | * Create the appropriate control structures to manage |
| 119 | * a new EHCI host controller. |
| 120 | */ |
Troy Kisky | 127efc4 | 2013-10-10 15:27:57 -0700 | [diff] [blame] | 121 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 122 | struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 123 | { |
Anton Schubert | 8a33371 | 2015-07-23 15:02:09 +0200 | [diff] [blame] | 124 | usb_brg_adrdec_setup(index); |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 125 | |
Anton Schubert | 8a33371 | 2015-07-23 15:02:09 +0200 | [diff] [blame] | 126 | *hccr = (struct ehci_hccr *)(MVUSB_BASE(index) + 0x100); |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 127 | *hcor = (struct ehci_hcor *)((uint32_t) *hccr |
| 128 | + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 129 | |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 130 | debug("ehci-marvell: init hccr %x and hcor %x hc_length %d\n", |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 131 | (uint32_t)*hccr, (uint32_t)*hcor, |
| 132 | (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * Destroy the appropriate control structures corresponding |
| 139 | * the the EHCI host controller. |
| 140 | */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 141 | int ehci_hcd_stop(int index) |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 142 | { |
| 143 | return 0; |
| 144 | } |