Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Ramneek Mehresh | ba92ee0 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 2 | /* |
Rajesh Bhagat | 707c866 | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 3 | * Copyright 2015,2016 Freescale Semiconductor, Inc. |
Ramneek Mehresh | ba92ee0 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 4 | * |
| 5 | * FSL USB HOST xHCI Controller |
| 6 | * |
| 7 | * Author: Ramneek Mehresh<ramneek.mehresh@freescale.com> |
Ramneek Mehresh | ba92ee0 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Ramneek Mehresh | ba92ee0 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 12 | #include <usb.h> |
Masahiro Yamada | 5d97dff | 2016-09-21 11:28:57 +0900 | [diff] [blame] | 13 | #include <linux/errno.h> |
Ramneek Mehresh | ba92ee0 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 14 | #include <linux/compat.h> |
| 15 | #include <linux/usb/xhci-fsl.h> |
| 16 | #include <linux/usb/dwc3.h> |
Jean-Jacques Hiblot | 1708a12 | 2019-09-11 11:33:46 +0200 | [diff] [blame] | 17 | #include <usb/xhci.h> |
Sriram Dash | ef53b8c | 2016-06-13 09:58:36 +0530 | [diff] [blame] | 18 | #include <fsl_errata.h> |
| 19 | #include <fsl_usb.h> |
Rajesh Bhagat | 707c866 | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 20 | #include <dm.h> |
Ramneek Mehresh | ba92ee0 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 21 | |
| 22 | /* Declare global data pointer */ |
Sven Schwermer | fd09c20 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 23 | #if !CONFIG_IS_ENABLED(DM_USB) |
Ramneek Mehresh | ba92ee0 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 24 | static struct fsl_xhci fsl_xhci; |
| 25 | unsigned long ctr_addr[] = FSL_USB_XHCI_ADDR; |
Rajesh Bhagat | 707c866 | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 26 | #else |
| 27 | struct xhci_fsl_priv { |
| 28 | struct xhci_ctrl xhci; |
| 29 | fdt_addr_t hcd_base; |
| 30 | struct fsl_xhci ctx; |
| 31 | }; |
| 32 | #endif |
Ramneek Mehresh | ba92ee0 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 33 | |
| 34 | __weak int __board_usb_init(int index, enum usb_init_type init) |
| 35 | { |
| 36 | return 0; |
| 37 | } |
| 38 | |
Sriram Dash | ef53b8c | 2016-06-13 09:58:36 +0530 | [diff] [blame] | 39 | static int erratum_a008751(void) |
| 40 | { |
Priyanka Jain | 3049a58 | 2017-04-27 15:08:07 +0530 | [diff] [blame] | 41 | #if defined(CONFIG_TARGET_LS2080AQDS) || defined(CONFIG_TARGET_LS2080ARDB) ||\ |
| 42 | defined(CONFIG_TARGET_LS2080AQDS) |
Sriram Dash | ef53b8c | 2016-06-13 09:58:36 +0530 | [diff] [blame] | 43 | u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE; |
| 44 | writel(SCFG_USB3PRM1CR_INIT, scfg + SCFG_USB3PRM1CR / 4); |
| 45 | return 0; |
| 46 | #endif |
| 47 | return 1; |
| 48 | } |
| 49 | |
| 50 | static void fsl_apply_xhci_errata(void) |
| 51 | { |
| 52 | int ret; |
| 53 | if (has_erratum_a008751()) { |
| 54 | ret = erratum_a008751(); |
| 55 | if (ret != 0) |
| 56 | puts("Failed to apply erratum a008751\n"); |
| 57 | } |
| 58 | } |
| 59 | |
Sriram Dash | e915716 | 2016-08-22 17:55:15 +0530 | [diff] [blame] | 60 | static void fsl_xhci_set_beat_burst_length(struct dwc3 *dwc3_reg) |
| 61 | { |
| 62 | clrsetbits_le32(&dwc3_reg->g_sbuscfg0, USB3_ENABLE_BEAT_BURST_MASK, |
| 63 | USB3_ENABLE_BEAT_BURST); |
| 64 | setbits_le32(&dwc3_reg->g_sbuscfg1, USB3_SET_BEAT_BURST_LIMIT); |
| 65 | } |
| 66 | |
Ramneek Mehresh | ba92ee0 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 67 | static int fsl_xhci_core_init(struct fsl_xhci *fsl_xhci) |
| 68 | { |
| 69 | int ret = 0; |
| 70 | |
| 71 | ret = dwc3_core_init(fsl_xhci->dwc3_reg); |
| 72 | if (ret) { |
| 73 | debug("%s:failed to initialize core\n", __func__); |
| 74 | return ret; |
| 75 | } |
| 76 | |
| 77 | /* We are hard-coding DWC3 core to Host Mode */ |
| 78 | dwc3_set_mode(fsl_xhci->dwc3_reg, DWC3_GCTL_PRTCAP_HOST); |
| 79 | |
Nikhil Badola | 667f4dd | 2015-06-23 09:17:49 +0530 | [diff] [blame] | 80 | /* Set GFLADJ_30MHZ as 20h as per XHCI spec default value */ |
| 81 | dwc3_set_fladj(fsl_xhci->dwc3_reg, GFLADJ_30MHZ_DEFAULT); |
| 82 | |
Sriram Dash | e915716 | 2016-08-22 17:55:15 +0530 | [diff] [blame] | 83 | /* Change beat burst and outstanding pipelined transfers requests */ |
| 84 | fsl_xhci_set_beat_burst_length(fsl_xhci->dwc3_reg); |
| 85 | |
Sriram Dash | 4c04371 | 2016-09-23 12:57:52 +0530 | [diff] [blame] | 86 | /* |
| 87 | * A-010151: The dwc3 phy TSMC 28-nm HPM 0.9/1.8 V does not |
| 88 | * reliably support Rx Detect in P3 mode(P3 is the default |
| 89 | * setting). Therefore, some USB3.0 devices may not be detected |
| 90 | * reliably in Super Speed mode. So, USB controller to configure |
| 91 | * USB in P2 mode whenever the Receive Detect feature is required. |
| 92 | * whenever the Receive Detect feature is required. |
| 93 | */ |
| 94 | if (has_erratum_a010151()) |
| 95 | clrsetbits_le32(&fsl_xhci->dwc3_reg->g_usb3pipectl[0], |
| 96 | DWC3_GUSB3PIPECTL_DISRXDETP3, |
| 97 | DWC3_GUSB3PIPECTL_DISRXDETP3); |
| 98 | |
Ramneek Mehresh | ba92ee0 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 99 | return ret; |
| 100 | } |
| 101 | |
| 102 | static int fsl_xhci_core_exit(struct fsl_xhci *fsl_xhci) |
| 103 | { |
| 104 | /* |
| 105 | * Currently fsl socs do not support PHY shutdown from |
| 106 | * sw. But this support may be added in future socs. |
| 107 | */ |
| 108 | return 0; |
| 109 | } |
| 110 | |
Sven Schwermer | fd09c20 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 111 | #if CONFIG_IS_ENABLED(DM_USB) |
Rajesh Bhagat | 707c866 | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 112 | static int xhci_fsl_probe(struct udevice *dev) |
| 113 | { |
| 114 | struct xhci_fsl_priv *priv = dev_get_priv(dev); |
| 115 | struct xhci_hccr *hccr; |
| 116 | struct xhci_hcor *hcor; |
| 117 | |
| 118 | int ret = 0; |
| 119 | |
| 120 | /* |
| 121 | * Get the base address for XHCI controller from the device node |
| 122 | */ |
Masahiro Yamada | 2548493 | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 123 | priv->hcd_base = dev_read_addr(dev); |
Rajesh Bhagat | 707c866 | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 124 | if (priv->hcd_base == FDT_ADDR_T_NONE) { |
| 125 | debug("Can't get the XHCI register base address\n"); |
| 126 | return -ENXIO; |
| 127 | } |
| 128 | priv->ctx.hcd = (struct xhci_hccr *)priv->hcd_base; |
| 129 | priv->ctx.dwc3_reg = (struct dwc3 *)((char *)(priv->hcd_base) + |
| 130 | DWC3_REG_OFFSET); |
| 131 | |
| 132 | fsl_apply_xhci_errata(); |
| 133 | |
| 134 | ret = fsl_xhci_core_init(&priv->ctx); |
| 135 | if (ret < 0) { |
| 136 | puts("Failed to initialize xhci\n"); |
| 137 | return ret; |
| 138 | } |
| 139 | |
| 140 | hccr = (struct xhci_hccr *)(priv->ctx.hcd); |
| 141 | hcor = (struct xhci_hcor *)((uintptr_t) hccr |
| 142 | + HC_LENGTH(xhci_readl(&hccr->cr_capbase))); |
| 143 | |
| 144 | debug("xhci-fsl: init hccr %lx and hcor %lx hc_length %lx\n", |
| 145 | (uintptr_t)hccr, (uintptr_t)hcor, |
| 146 | (uintptr_t)HC_LENGTH(xhci_readl(&hccr->cr_capbase))); |
| 147 | |
| 148 | return xhci_register(dev, hccr, hcor); |
| 149 | } |
| 150 | |
| 151 | static int xhci_fsl_remove(struct udevice *dev) |
| 152 | { |
| 153 | struct xhci_fsl_priv *priv = dev_get_priv(dev); |
Rajesh Bhagat | 707c866 | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 154 | |
| 155 | fsl_xhci_core_exit(&priv->ctx); |
| 156 | |
Masahiro Yamada | 8319aeb | 2016-09-06 22:17:35 +0900 | [diff] [blame] | 157 | return xhci_deregister(dev); |
Rajesh Bhagat | 707c866 | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static const struct udevice_id xhci_usb_ids[] = { |
| 161 | { .compatible = "fsl,layerscape-dwc3", }, |
| 162 | { } |
| 163 | }; |
| 164 | |
| 165 | U_BOOT_DRIVER(xhci_fsl) = { |
| 166 | .name = "xhci_fsl", |
| 167 | .id = UCLASS_USB, |
| 168 | .of_match = xhci_usb_ids, |
| 169 | .probe = xhci_fsl_probe, |
| 170 | .remove = xhci_fsl_remove, |
| 171 | .ops = &xhci_usb_ops, |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame^] | 172 | .plat_auto = sizeof(struct usb_plat), |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 173 | .priv_auto = sizeof(struct xhci_fsl_priv), |
Rajesh Bhagat | 707c866 | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 174 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 175 | }; |
| 176 | #else |
Ramneek Mehresh | ba92ee0 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 177 | int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor) |
| 178 | { |
| 179 | struct fsl_xhci *ctx = &fsl_xhci; |
| 180 | int ret = 0; |
| 181 | |
| 182 | ctx->hcd = (struct xhci_hccr *)ctr_addr[index]; |
| 183 | ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET); |
| 184 | |
| 185 | ret = board_usb_init(index, USB_INIT_HOST); |
| 186 | if (ret != 0) { |
| 187 | puts("Failed to initialize board for USB\n"); |
| 188 | return ret; |
| 189 | } |
| 190 | |
Sriram Dash | ef53b8c | 2016-06-13 09:58:36 +0530 | [diff] [blame] | 191 | fsl_apply_xhci_errata(); |
| 192 | |
Ramneek Mehresh | ba92ee0 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 193 | ret = fsl_xhci_core_init(ctx); |
| 194 | if (ret < 0) { |
| 195 | puts("Failed to initialize xhci\n"); |
| 196 | return ret; |
| 197 | } |
| 198 | |
| 199 | *hccr = (struct xhci_hccr *)ctx->hcd; |
Nikhil Badola | 7e5a32f | 2015-06-23 09:17:32 +0530 | [diff] [blame] | 200 | *hcor = (struct xhci_hcor *)((uintptr_t) *hccr |
Ramneek Mehresh | ba92ee0 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 201 | + HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase))); |
| 202 | |
Nikhil Badola | 7e5a32f | 2015-06-23 09:17:32 +0530 | [diff] [blame] | 203 | debug("fsl-xhci: init hccr %lx and hcor %lx hc_length %lx\n", |
| 204 | (uintptr_t)*hccr, (uintptr_t)*hcor, |
| 205 | (uintptr_t)HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase))); |
Ramneek Mehresh | ba92ee0 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 206 | |
| 207 | return ret; |
| 208 | } |
| 209 | |
| 210 | void xhci_hcd_stop(int index) |
| 211 | { |
| 212 | struct fsl_xhci *ctx = &fsl_xhci; |
| 213 | |
| 214 | fsl_xhci_core_exit(ctx); |
| 215 | } |
Rajesh Bhagat | 707c866 | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 216 | #endif |