Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2009 |
| 4 | * Marvell Semiconductor <www.marvell.com> |
| 5 | * Written-by: Prafulla Wadaskar <prafulla@marvell.com> |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 11 | #include <asm/io.h> |
| 12 | #include <usb.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 13 | #include <linux/delay.h> |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 14 | #include "ehci.h" |
Stefan Roese | 9aa3197 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 15 | #include <linux/mbus.h> |
Lei Wen | 298ae91 | 2011-10-18 20:11:42 +0530 | [diff] [blame] | 16 | #include <asm/arch/cpu.h> |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 17 | #include <dm.h> |
Albert ARIBAUD | 994bca2 | 2012-01-15 22:08:40 +0000 | [diff] [blame] | 18 | |
Trevor Woerner | bb7ab07 | 2020-05-06 08:02:40 -0400 | [diff] [blame] | 19 | #if defined(CONFIG_ARCH_KIRKWOOD) |
Stefan Roese | c243784 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 20 | #include <asm/arch/soc.h> |
Trevor Woerner | f995375 | 2020-05-06 08:02:38 -0400 | [diff] [blame] | 21 | #elif defined(CONFIG_ARCH_ORION5X) |
Albert ARIBAUD | 994bca2 | 2012-01-15 22:08:40 +0000 | [diff] [blame] | 22 | #include <asm/arch/orion5x.h> |
| 23 | #endif |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 24 | |
Albert ARIBAUD | c3c7645 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 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 | |
Stefan Roese | 46b9db5 | 2016-07-18 17:24:56 +0200 | [diff] [blame] | 31 | #define USB2_SBUSCFG_OFF 0x90 |
| 32 | |
| 33 | #define USB_SBUSCFG_BAWR_OFF 0x6 |
| 34 | #define USB_SBUSCFG_BARD_OFF 0x3 |
| 35 | #define USB_SBUSCFG_AHBBRST_OFF 0x0 |
| 36 | |
| 37 | #define USB_SBUSCFG_BAWR_ALIGN_64B 0x4 |
| 38 | #define USB_SBUSCFG_BARD_ALIGN_64B 0x4 |
| 39 | #define USB_SBUSCFG_AHBBRST_INCR16 0x7 |
| 40 | |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 41 | /* |
| 42 | * USB 2.0 Bridge Address Decoding registers setup |
| 43 | */ |
Sven Schwermer | 8a3cb9f1 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 44 | #if CONFIG_IS_ENABLED(DM_USB) |
Stefan Roese | 9aa3197 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 45 | |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 46 | struct ehci_mvebu_priv { |
| 47 | struct ehci_ctrl ehci; |
| 48 | fdt_addr_t hcd_base; |
| 49 | }; |
Stefan Roese | 9aa3197 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * Once all the older Marvell SoC's (Orion, Kirkwood) are converted |
| 53 | * to the common mvebu archticture including the mbus setup, this |
| 54 | * will be the only function needed to configure the access windows |
| 55 | */ |
Stefan Roese | 46b9db5 | 2016-07-18 17:24:56 +0200 | [diff] [blame] | 56 | static void usb_brg_adrdec_setup(void *base) |
Stefan Roese | 9aa3197 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 57 | { |
| 58 | const struct mbus_dram_target_info *dram; |
| 59 | int i; |
| 60 | |
| 61 | dram = mvebu_mbus_dram_info(); |
| 62 | |
| 63 | for (i = 0; i < 4; i++) { |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 64 | writel(0, base + USB_WINDOW_CTRL(i)); |
| 65 | writel(0, base + USB_WINDOW_BASE(i)); |
Stefan Roese | 9aa3197 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | for (i = 0; i < dram->num_cs; i++) { |
| 69 | const struct mbus_dram_window *cs = dram->cs + i; |
| 70 | |
| 71 | /* Write size, attributes and target id to control register */ |
Stefan Roese | 44123cf | 2015-07-22 10:01:30 +0200 | [diff] [blame] | 72 | writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) | |
| 73 | (dram->mbus_dram_target_id << 4) | 1, |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 74 | base + USB_WINDOW_CTRL(i)); |
Stefan Roese | 9aa3197 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 75 | |
| 76 | /* Write base address to base register */ |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 77 | writel(cs->base, base + USB_WINDOW_BASE(i)); |
| 78 | } |
| 79 | } |
| 80 | |
Stefan Roese | 46b9db5 | 2016-07-18 17:24:56 +0200 | [diff] [blame] | 81 | static void marvell_ehci_powerup_fixup(struct ehci_ctrl *ctrl, |
| 82 | uint32_t *status_reg, uint32_t *reg) |
| 83 | { |
| 84 | struct ehci_mvebu_priv *priv = ctrl->priv; |
| 85 | |
| 86 | /* |
| 87 | * Set default value for reg SBUSCFG, which is Control for the AMBA |
| 88 | * system bus interface: |
| 89 | * BAWR = BARD = 4 : Align rd/wr bursts packets larger than 64 bytes |
| 90 | * AHBBRST = 7 : Align AHB burst for packets larger than 64 bytes |
| 91 | */ |
| 92 | writel((USB_SBUSCFG_BAWR_ALIGN_64B << USB_SBUSCFG_BAWR_OFF) | |
| 93 | (USB_SBUSCFG_BARD_ALIGN_64B << USB_SBUSCFG_BARD_OFF) | |
| 94 | (USB_SBUSCFG_AHBBRST_INCR16 << USB_SBUSCFG_AHBBRST_OFF), |
| 95 | priv->hcd_base + USB2_SBUSCFG_OFF); |
| 96 | |
| 97 | mdelay(50); |
| 98 | } |
| 99 | |
| 100 | static struct ehci_ops marvell_ehci_ops = { |
| 101 | .powerup_fixup = NULL, |
| 102 | }; |
| 103 | |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 104 | static int ehci_mvebu_probe(struct udevice *dev) |
| 105 | { |
| 106 | struct ehci_mvebu_priv *priv = dev_get_priv(dev); |
| 107 | struct ehci_hccr *hccr; |
| 108 | struct ehci_hcor *hcor; |
| 109 | |
| 110 | /* |
| 111 | * Get the base address for EHCI controller from the device node |
| 112 | */ |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 113 | priv->hcd_base = dev_read_addr(dev); |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 114 | if (priv->hcd_base == FDT_ADDR_T_NONE) { |
| 115 | debug("Can't get the EHCI register base address\n"); |
| 116 | return -ENXIO; |
Stefan Roese | 9aa3197 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 117 | } |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 118 | |
Stefan Roese | 46b9db5 | 2016-07-18 17:24:56 +0200 | [diff] [blame] | 119 | /* |
| 120 | * For SoCs without hlock like Armada3700 we need to program the sbuscfg |
| 121 | * reg to guarantee AHB master's burst will not overrun or underrun |
| 122 | * the FIFO. Otherwise all USB2 write option will fail. |
| 123 | * Also, the address decoder doesn't need to get setup with this |
| 124 | * SoC, so don't call usb_brg_adrdec_setup(). |
| 125 | */ |
Pali Rohár | ecdc7bf | 2022-02-14 11:34:24 +0100 | [diff] [blame] | 126 | if (device_is_compatible(dev, "marvell,armada-3700-ehci")) |
Stefan Roese | 46b9db5 | 2016-07-18 17:24:56 +0200 | [diff] [blame] | 127 | marvell_ehci_ops.powerup_fixup = marvell_ehci_powerup_fixup; |
| 128 | else |
| 129 | usb_brg_adrdec_setup((void *)priv->hcd_base); |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 130 | |
| 131 | hccr = (struct ehci_hccr *)(priv->hcd_base + 0x100); |
| 132 | hcor = (struct ehci_hcor *) |
Stefan Roese | 46b9db5 | 2016-07-18 17:24:56 +0200 | [diff] [blame] | 133 | ((uintptr_t)hccr + HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 134 | |
Stefan Roese | 46b9db5 | 2016-07-18 17:24:56 +0200 | [diff] [blame] | 135 | debug("ehci-marvell: init hccr %lx and hcor %lx hc_length %ld\n", |
| 136 | (uintptr_t)hccr, (uintptr_t)hcor, |
| 137 | (uintptr_t)HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 138 | |
Stefan Roese | 46b9db5 | 2016-07-18 17:24:56 +0200 | [diff] [blame] | 139 | return ehci_register(dev, hccr, hcor, &marvell_ehci_ops, 0, |
| 140 | USB_INIT_HOST); |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 141 | } |
| 142 | |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 143 | static const struct udevice_id ehci_usb_ids[] = { |
| 144 | { .compatible = "marvell,orion-ehci", }, |
Pali Rohár | ecdc7bf | 2022-02-14 11:34:24 +0100 | [diff] [blame] | 145 | { .compatible = "marvell,armada-3700-ehci", }, |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 146 | { } |
| 147 | }; |
| 148 | |
| 149 | U_BOOT_DRIVER(ehci_mvebu) = { |
| 150 | .name = "ehci_mvebu", |
| 151 | .id = UCLASS_USB, |
| 152 | .of_match = ehci_usb_ids, |
| 153 | .probe = ehci_mvebu_probe, |
Masahiro Yamada | d41919b | 2016-09-06 22:17:34 +0900 | [diff] [blame] | 154 | .remove = ehci_deregister, |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 155 | .ops = &ehci_usb_ops, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 156 | .plat_auto = sizeof(struct usb_plat), |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 157 | .priv_auto = sizeof(struct ehci_mvebu_priv), |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 158 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 159 | }; |
| 160 | |
Stefan Roese | 9aa3197 | 2015-06-29 14:58:15 +0200 | [diff] [blame] | 161 | #else |
Anton Schubert | 11b8ebf | 2015-07-23 15:02:09 +0200 | [diff] [blame] | 162 | #define MVUSB_BASE(port) MVUSB0_BASE |
| 163 | |
| 164 | static void usb_brg_adrdec_setup(int index) |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 165 | { |
| 166 | int i; |
Albert ARIBAUD | c3c7645 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 167 | u32 size, base, attrib; |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 168 | |
| 169 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 170 | |
| 171 | /* Enable DRAM bank */ |
| 172 | switch (i) { |
| 173 | case 0: |
Albert ARIBAUD | c3c7645 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 174 | attrib = MVUSB0_CPU_ATTR_DRAM_CS0; |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 175 | break; |
| 176 | case 1: |
Albert ARIBAUD | c3c7645 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 177 | attrib = MVUSB0_CPU_ATTR_DRAM_CS1; |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 178 | break; |
| 179 | case 2: |
Albert ARIBAUD | c3c7645 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 180 | attrib = MVUSB0_CPU_ATTR_DRAM_CS2; |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 181 | break; |
| 182 | case 3: |
Albert ARIBAUD | c3c7645 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 183 | attrib = MVUSB0_CPU_ATTR_DRAM_CS3; |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 184 | break; |
| 185 | default: |
| 186 | /* invalide bank, disable access */ |
| 187 | attrib = 0; |
| 188 | break; |
| 189 | } |
| 190 | |
Albert ARIBAUD | c3c7645 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 191 | size = gd->bd->bi_dram[i].size; |
| 192 | base = gd->bd->bi_dram[i].start; |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 193 | if ((size) && (attrib)) |
Stefan Roese | 44123cf | 2015-07-22 10:01:30 +0200 | [diff] [blame] | 194 | writel(MVCPU_WIN_CTRL_DATA(size, USB_TARGET_DRAM, |
| 195 | attrib, MVCPU_WIN_ENABLE), |
| 196 | MVUSB0_BASE + USB_WINDOW_CTRL(i)); |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 197 | else |
Stefan Roese | 44123cf | 2015-07-22 10:01:30 +0200 | [diff] [blame] | 198 | writel(MVCPU_WIN_DISABLE, |
| 199 | MVUSB0_BASE + USB_WINDOW_CTRL(i)); |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 200 | |
Stefan Roese | 44123cf | 2015-07-22 10:01:30 +0200 | [diff] [blame] | 201 | writel(base, MVUSB0_BASE + USB_WINDOW_BASE(i)); |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
| 205 | /* |
| 206 | * Create the appropriate control structures to manage |
| 207 | * a new EHCI host controller. |
| 208 | */ |
Troy Kisky | 7d6bbb9 | 2013-10-10 15:27:57 -0700 | [diff] [blame] | 209 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 210 | struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 211 | { |
Anton Schubert | 11b8ebf | 2015-07-23 15:02:09 +0200 | [diff] [blame] | 212 | usb_brg_adrdec_setup(index); |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 213 | |
Anton Schubert | 11b8ebf | 2015-07-23 15:02:09 +0200 | [diff] [blame] | 214 | *hccr = (struct ehci_hccr *)(MVUSB_BASE(index) + 0x100); |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 215 | *hcor = (struct ehci_hcor *)((uint32_t) *hccr |
| 216 | + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 217 | |
Albert ARIBAUD | c3c7645 | 2012-01-15 22:08:39 +0000 | [diff] [blame] | 218 | debug("ehci-marvell: init hccr %x and hcor %x hc_length %d\n", |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 219 | (uint32_t)*hccr, (uint32_t)*hcor, |
| 220 | (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | /* |
| 226 | * Destroy the appropriate control structures corresponding |
| 227 | * the the EHCI host controller. |
| 228 | */ |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 229 | int ehci_hcd_stop(int index) |
Prafulla Wadaskar | 46c54fd | 2009-06-29 20:56:43 +0530 | [diff] [blame] | 230 | { |
| 231 | return 0; |
| 232 | } |
Stefan Roese | 0390102 | 2015-09-01 11:39:44 +0200 | [diff] [blame] | 233 | |
Sven Schwermer | 8a3cb9f1 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 234 | #endif /* CONFIG_IS_ENABLED(DM_USB) */ |