Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Ramneek Mehresh | f4de407 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 2 | /* |
Rajesh Bhagat | 885f29a | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 3 | * Copyright 2015,2016 Freescale Semiconductor, Inc. |
Ramneek Mehresh | f4de407 | 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 | f4de407 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Ramneek Mehresh | f4de407 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 12 | #include <usb.h> |
Masahiro Yamada | 64e4f7f | 2016-09-21 11:28:57 +0900 | [diff] [blame] | 13 | #include <linux/errno.h> |
Ramneek Mehresh | f4de407 | 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 | ad4142b | 2019-09-11 11:33:46 +0200 | [diff] [blame] | 17 | #include <usb/xhci.h> |
Sriram Dash | 0182095 | 2016-06-13 09:58:36 +0530 | [diff] [blame] | 18 | #include <fsl_errata.h> |
| 19 | #include <fsl_usb.h> |
Rajesh Bhagat | 885f29a | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 20 | #include <dm.h> |
Ramneek Mehresh | f4de407 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 21 | |
| 22 | /* Declare global data pointer */ |
Rajesh Bhagat | 885f29a | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 23 | struct xhci_fsl_priv { |
| 24 | struct xhci_ctrl xhci; |
| 25 | fdt_addr_t hcd_base; |
| 26 | struct fsl_xhci ctx; |
| 27 | }; |
Ramneek Mehresh | f4de407 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 28 | |
| 29 | __weak int __board_usb_init(int index, enum usb_init_type init) |
| 30 | { |
| 31 | return 0; |
| 32 | } |
| 33 | |
Sriram Dash | 0182095 | 2016-06-13 09:58:36 +0530 | [diff] [blame] | 34 | static int erratum_a008751(void) |
| 35 | { |
Priyanka Jain | 75cd67f | 2017-04-27 15:08:07 +0530 | [diff] [blame] | 36 | #if defined(CONFIG_TARGET_LS2080AQDS) || defined(CONFIG_TARGET_LS2080ARDB) ||\ |
| 37 | defined(CONFIG_TARGET_LS2080AQDS) |
Sriram Dash | 0182095 | 2016-06-13 09:58:36 +0530 | [diff] [blame] | 38 | u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE; |
| 39 | writel(SCFG_USB3PRM1CR_INIT, scfg + SCFG_USB3PRM1CR / 4); |
| 40 | return 0; |
| 41 | #endif |
| 42 | return 1; |
| 43 | } |
| 44 | |
| 45 | static void fsl_apply_xhci_errata(void) |
| 46 | { |
| 47 | int ret; |
| 48 | if (has_erratum_a008751()) { |
| 49 | ret = erratum_a008751(); |
| 50 | if (ret != 0) |
| 51 | puts("Failed to apply erratum a008751\n"); |
| 52 | } |
| 53 | } |
| 54 | |
Sriram Dash | 16f1d2b | 2016-08-22 17:55:15 +0530 | [diff] [blame] | 55 | static void fsl_xhci_set_beat_burst_length(struct dwc3 *dwc3_reg) |
| 56 | { |
| 57 | clrsetbits_le32(&dwc3_reg->g_sbuscfg0, USB3_ENABLE_BEAT_BURST_MASK, |
| 58 | USB3_ENABLE_BEAT_BURST); |
| 59 | setbits_le32(&dwc3_reg->g_sbuscfg1, USB3_SET_BEAT_BURST_LIMIT); |
| 60 | } |
| 61 | |
Ramneek Mehresh | f4de407 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 62 | static int fsl_xhci_core_init(struct fsl_xhci *fsl_xhci) |
| 63 | { |
| 64 | int ret = 0; |
| 65 | |
| 66 | ret = dwc3_core_init(fsl_xhci->dwc3_reg); |
| 67 | if (ret) { |
| 68 | debug("%s:failed to initialize core\n", __func__); |
| 69 | return ret; |
| 70 | } |
| 71 | |
| 72 | /* We are hard-coding DWC3 core to Host Mode */ |
| 73 | dwc3_set_mode(fsl_xhci->dwc3_reg, DWC3_GCTL_PRTCAP_HOST); |
| 74 | |
Nikhil Badola | 807babb | 2015-06-23 09:17:49 +0530 | [diff] [blame] | 75 | /* Set GFLADJ_30MHZ as 20h as per XHCI spec default value */ |
| 76 | dwc3_set_fladj(fsl_xhci->dwc3_reg, GFLADJ_30MHZ_DEFAULT); |
| 77 | |
Sriram Dash | 16f1d2b | 2016-08-22 17:55:15 +0530 | [diff] [blame] | 78 | /* Change beat burst and outstanding pipelined transfers requests */ |
| 79 | fsl_xhci_set_beat_burst_length(fsl_xhci->dwc3_reg); |
| 80 | |
Sriram Dash | a1f422e | 2016-09-23 12:57:52 +0530 | [diff] [blame] | 81 | /* |
| 82 | * A-010151: The dwc3 phy TSMC 28-nm HPM 0.9/1.8 V does not |
| 83 | * reliably support Rx Detect in P3 mode(P3 is the default |
| 84 | * setting). Therefore, some USB3.0 devices may not be detected |
| 85 | * reliably in Super Speed mode. So, USB controller to configure |
| 86 | * USB in P2 mode whenever the Receive Detect feature is required. |
| 87 | * whenever the Receive Detect feature is required. |
| 88 | */ |
| 89 | if (has_erratum_a010151()) |
| 90 | clrsetbits_le32(&fsl_xhci->dwc3_reg->g_usb3pipectl[0], |
| 91 | DWC3_GUSB3PIPECTL_DISRXDETP3, |
| 92 | DWC3_GUSB3PIPECTL_DISRXDETP3); |
| 93 | |
Ramneek Mehresh | f4de407 | 2015-05-29 14:47:19 +0530 | [diff] [blame] | 94 | return ret; |
| 95 | } |
| 96 | |
| 97 | static int fsl_xhci_core_exit(struct fsl_xhci *fsl_xhci) |
| 98 | { |
| 99 | /* |
| 100 | * Currently fsl socs do not support PHY shutdown from |
| 101 | * sw. But this support may be added in future socs. |
| 102 | */ |
| 103 | return 0; |
| 104 | } |
| 105 | |
Rajesh Bhagat | 885f29a | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 106 | static int xhci_fsl_probe(struct udevice *dev) |
| 107 | { |
| 108 | struct xhci_fsl_priv *priv = dev_get_priv(dev); |
| 109 | struct xhci_hccr *hccr; |
| 110 | struct xhci_hcor *hcor; |
| 111 | |
| 112 | int ret = 0; |
| 113 | |
| 114 | /* |
| 115 | * Get the base address for XHCI controller from the device node |
| 116 | */ |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 117 | priv->hcd_base = dev_read_addr(dev); |
Rajesh Bhagat | 885f29a | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 118 | if (priv->hcd_base == FDT_ADDR_T_NONE) { |
| 119 | debug("Can't get the XHCI register base address\n"); |
| 120 | return -ENXIO; |
| 121 | } |
| 122 | priv->ctx.hcd = (struct xhci_hccr *)priv->hcd_base; |
| 123 | priv->ctx.dwc3_reg = (struct dwc3 *)((char *)(priv->hcd_base) + |
| 124 | DWC3_REG_OFFSET); |
| 125 | |
| 126 | fsl_apply_xhci_errata(); |
| 127 | |
| 128 | ret = fsl_xhci_core_init(&priv->ctx); |
| 129 | if (ret < 0) { |
| 130 | puts("Failed to initialize xhci\n"); |
| 131 | return ret; |
| 132 | } |
| 133 | |
| 134 | hccr = (struct xhci_hccr *)(priv->ctx.hcd); |
| 135 | hcor = (struct xhci_hcor *)((uintptr_t) hccr |
| 136 | + HC_LENGTH(xhci_readl(&hccr->cr_capbase))); |
| 137 | |
| 138 | debug("xhci-fsl: init hccr %lx and hcor %lx hc_length %lx\n", |
| 139 | (uintptr_t)hccr, (uintptr_t)hcor, |
| 140 | (uintptr_t)HC_LENGTH(xhci_readl(&hccr->cr_capbase))); |
| 141 | |
| 142 | return xhci_register(dev, hccr, hcor); |
| 143 | } |
| 144 | |
| 145 | static int xhci_fsl_remove(struct udevice *dev) |
| 146 | { |
| 147 | struct xhci_fsl_priv *priv = dev_get_priv(dev); |
Rajesh Bhagat | 885f29a | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 148 | |
| 149 | fsl_xhci_core_exit(&priv->ctx); |
| 150 | |
Masahiro Yamada | 9b70df5 | 2016-09-06 22:17:35 +0900 | [diff] [blame] | 151 | return xhci_deregister(dev); |
Rajesh Bhagat | 885f29a | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | static const struct udevice_id xhci_usb_ids[] = { |
| 155 | { .compatible = "fsl,layerscape-dwc3", }, |
Michael Walle | 3ae724c | 2021-10-13 18:14:21 +0200 | [diff] [blame] | 156 | { .compatible = "fsl,ls1028a-dwc3", }, |
Rajesh Bhagat | 885f29a | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 157 | { } |
| 158 | }; |
| 159 | |
| 160 | U_BOOT_DRIVER(xhci_fsl) = { |
| 161 | .name = "xhci_fsl", |
| 162 | .id = UCLASS_USB, |
| 163 | .of_match = xhci_usb_ids, |
| 164 | .probe = xhci_fsl_probe, |
| 165 | .remove = xhci_fsl_remove, |
| 166 | .ops = &xhci_usb_ops, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 167 | .plat_auto = sizeof(struct usb_plat), |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 168 | .priv_auto = sizeof(struct xhci_fsl_priv), |
Rajesh Bhagat | 885f29a | 2016-07-01 18:51:47 +0530 | [diff] [blame] | 169 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 170 | }; |