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> |
Stefan Roese | cd48225 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 15 | #include <dm.h> |
Albert ARIBAUD | 805ad7e | 2012-01-15 22:08:40 +0000 | [diff] [blame] | 16 | |
| 17 | #if defined(CONFIG_KIRKWOOD) |
Stefan Roese | 3dc23f7 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 18 | #include <asm/arch/soc.h> |
Albert ARIBAUD | 805ad7e | 2012-01-15 22:08:40 +0000 | [diff] [blame] | 19 | #elif defined(CONFIG_ORION5X) |
| 20 | #include <asm/arch/orion5x.h> |
| 21 | #endif |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 22 | |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 25 | #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 Roese | cd48225 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 32 | #ifdef CONFIG_DM_USB |
Stefan Roese | fe11ae2 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 33 | |
Stefan Roese | cd48225 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 34 | struct ehci_mvebu_priv { |
| 35 | struct ehci_ctrl ehci; |
| 36 | fdt_addr_t hcd_base; |
| 37 | }; |
Stefan Roese | fe11ae2 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 38 | |
| 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 Roese | cd48225 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 44 | static void usb_brg_adrdec_setup(u32 base) |
Stefan Roese | fe11ae2 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 45 | { |
| 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 Roese | cd48225 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 52 | writel(0, base + USB_WINDOW_CTRL(i)); |
| 53 | writel(0, base + USB_WINDOW_BASE(i)); |
Stefan Roese | fe11ae2 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 54 | } |
| 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 Roese | 82b9143 | 2015-07-22 10:01:30 +0200 | [diff] [blame] | 60 | writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) | |
| 61 | (dram->mbus_dram_target_id << 4) | 1, |
Stefan Roese | cd48225 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 62 | base + USB_WINDOW_CTRL(i)); |
Stefan Roese | fe11ae2 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 63 | |
| 64 | /* Write base address to base register */ |
Stefan Roese | cd48225 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 65 | writel(cs->base, base + USB_WINDOW_BASE(i)); |
Stefan Roese | fe11ae2 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 66 | } |
| 67 | } |
Stefan Roese | cd48225 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 68 | |
| 69 | static 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; |
| 82 | } |
| 83 | |
| 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 | |
Stefan Roese | cd48225 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 97 | static const struct udevice_id ehci_usb_ids[] = { |
| 98 | { .compatible = "marvell,orion-ehci", }, |
| 99 | { } |
| 100 | }; |
| 101 | |
| 102 | U_BOOT_DRIVER(ehci_mvebu) = { |
| 103 | .name = "ehci_mvebu", |
| 104 | .id = UCLASS_USB, |
| 105 | .of_match = ehci_usb_ids, |
| 106 | .probe = ehci_mvebu_probe, |
Masahiro Yamada | 4052734 | 2016-09-06 22:17:34 +0900 | [diff] [blame^] | 107 | .remove = ehci_deregister, |
Stefan Roese | cd48225 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 108 | .ops = &ehci_usb_ops, |
| 109 | .platdata_auto_alloc_size = sizeof(struct usb_platdata), |
| 110 | .priv_auto_alloc_size = sizeof(struct ehci_mvebu_priv), |
| 111 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 112 | }; |
| 113 | |
Stefan Roese | fe11ae2 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 114 | #else |
Anton Schubert | 8a33371 | 2015-07-23 15:02:09 +0200 | [diff] [blame] | 115 | #define MVUSB_BASE(port) MVUSB0_BASE |
| 116 | |
| 117 | static void usb_brg_adrdec_setup(int index) |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 118 | { |
| 119 | int i; |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 120 | u32 size, base, attrib; |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 121 | |
| 122 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 123 | |
| 124 | /* Enable DRAM bank */ |
| 125 | switch (i) { |
| 126 | case 0: |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 127 | attrib = MVUSB0_CPU_ATTR_DRAM_CS0; |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 128 | break; |
| 129 | case 1: |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 130 | attrib = MVUSB0_CPU_ATTR_DRAM_CS1; |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 131 | break; |
| 132 | case 2: |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 133 | attrib = MVUSB0_CPU_ATTR_DRAM_CS2; |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 134 | break; |
| 135 | case 3: |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 136 | attrib = MVUSB0_CPU_ATTR_DRAM_CS3; |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 137 | break; |
| 138 | default: |
| 139 | /* invalide bank, disable access */ |
| 140 | attrib = 0; |
| 141 | break; |
| 142 | } |
| 143 | |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 144 | size = gd->bd->bi_dram[i].size; |
| 145 | base = gd->bd->bi_dram[i].start; |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 146 | if ((size) && (attrib)) |
Stefan Roese | 82b9143 | 2015-07-22 10:01:30 +0200 | [diff] [blame] | 147 | writel(MVCPU_WIN_CTRL_DATA(size, USB_TARGET_DRAM, |
| 148 | attrib, MVCPU_WIN_ENABLE), |
| 149 | MVUSB0_BASE + USB_WINDOW_CTRL(i)); |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 150 | else |
Stefan Roese | 82b9143 | 2015-07-22 10:01:30 +0200 | [diff] [blame] | 151 | writel(MVCPU_WIN_DISABLE, |
| 152 | MVUSB0_BASE + USB_WINDOW_CTRL(i)); |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 153 | |
Stefan Roese | 82b9143 | 2015-07-22 10:01:30 +0200 | [diff] [blame] | 154 | writel(base, MVUSB0_BASE + USB_WINDOW_BASE(i)); |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
| 158 | /* |
| 159 | * Create the appropriate control structures to manage |
| 160 | * a new EHCI host controller. |
| 161 | */ |
Troy Kisky | 127efc4 | 2013-10-10 15:27:57 -0700 | [diff] [blame] | 162 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 163 | struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 164 | { |
Anton Schubert | 8a33371 | 2015-07-23 15:02:09 +0200 | [diff] [blame] | 165 | usb_brg_adrdec_setup(index); |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 166 | |
Anton Schubert | 8a33371 | 2015-07-23 15:02:09 +0200 | [diff] [blame] | 167 | *hccr = (struct ehci_hccr *)(MVUSB_BASE(index) + 0x100); |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 168 | *hcor = (struct ehci_hcor *)((uint32_t) *hccr |
| 169 | + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 170 | |
Albert ARIBAUD | 74d3442 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 171 | 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] | 172 | (uint32_t)*hccr, (uint32_t)*hcor, |
| 173 | (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | /* |
| 179 | * Destroy the appropriate control structures corresponding |
| 180 | * the the EHCI host controller. |
| 181 | */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 182 | int ehci_hcd_stop(int index) |
Prafulla Wadaskar | 1d8937a | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 183 | { |
| 184 | return 0; |
| 185 | } |
Stefan Roese | cd48225 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 186 | |
| 187 | #endif /* CONFIG_DM_USB */ |