Rayagonda Kokatanur | f59d24e | 2020-04-09 09:23:15 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2019 Broadcom. |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <fdtdec.h> |
| 9 | #include <usb.h> |
| 10 | #include <asm/io.h> |
Stefan Agner | 3fa593d | 2021-10-06 14:05:29 +0200 | [diff] [blame] | 11 | #include <dm/device_compat.h> |
Rayagonda Kokatanur | f59d24e | 2020-04-09 09:23:15 +0530 | [diff] [blame] | 12 | #include <usb/xhci.h> |
| 13 | |
| 14 | #define DRD2U3H_XHC_REGS_AXIWRA 0xC08 |
| 15 | #define DRD2U3H_XHC_REGS_AXIRDA 0xC0C |
| 16 | |
| 17 | #define USBAXI_CACHE 0xF |
| 18 | #define USBAXI_PROT 0x8 |
| 19 | #define USBAXI_SA_MASK 0x1FF |
| 20 | #define USBAXI_UA_MASK (0x1FF << 16) |
| 21 | #define USBAXI_SA_VAL ((USBAXI_CACHE << 4) | USBAXI_PROT) |
| 22 | #define USBAXI_UA_VAL (USBAXI_SA_VAL << 16) |
| 23 | #define USBAXI_SA_UA_MASK (USBAXI_UA_MASK | USBAXI_SA_MASK) |
| 24 | #define USBAXI_SA_UA_VAL (USBAXI_UA_VAL | USBAXI_SA_VAL) |
| 25 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 26 | struct brcm_xhci_plat { |
Rayagonda Kokatanur | f59d24e | 2020-04-09 09:23:15 +0530 | [diff] [blame] | 27 | unsigned int arcache; |
| 28 | unsigned int awcache; |
| 29 | void __iomem *hc_base; |
| 30 | }; |
| 31 | |
| 32 | static int xhci_brcm_probe(struct udevice *dev) |
| 33 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 34 | struct brcm_xhci_plat *plat = dev_get_plat(dev); |
Rayagonda Kokatanur | f59d24e | 2020-04-09 09:23:15 +0530 | [diff] [blame] | 35 | struct xhci_hcor *hcor; |
| 36 | struct xhci_hccr *hcd; |
| 37 | int len, ret = 0; |
| 38 | |
| 39 | if (!plat) { |
| 40 | dev_err(dev, "Can't get xHCI Plat data\n"); |
| 41 | return -ENOMEM; |
| 42 | } |
| 43 | |
| 44 | hcd = dev_read_addr_ptr(dev); |
| 45 | if (!hcd) { |
| 46 | dev_err(dev, "Can't get the xHCI register base address\n"); |
| 47 | return -ENXIO; |
| 48 | } |
| 49 | |
| 50 | plat->hc_base = hcd; |
| 51 | len = HC_LENGTH(xhci_readl(&hcd->cr_capbase)); |
| 52 | hcor = (struct xhci_hcor *)(plat->hc_base + len); |
| 53 | |
| 54 | /* Save the default values of AXI read and write attributes */ |
| 55 | plat->awcache = readl(plat->hc_base + DRD2U3H_XHC_REGS_AXIWRA); |
| 56 | plat->arcache = readl(plat->hc_base + DRD2U3H_XHC_REGS_AXIRDA); |
| 57 | |
| 58 | /* Enable AXI write attributes */ |
| 59 | clrsetbits_le32(plat->hc_base + DRD2U3H_XHC_REGS_AXIWRA, |
| 60 | USBAXI_SA_UA_MASK, USBAXI_SA_UA_VAL); |
| 61 | |
| 62 | /* Enable AXI read attributes */ |
| 63 | clrsetbits_le32(plat->hc_base + DRD2U3H_XHC_REGS_AXIRDA, |
| 64 | USBAXI_SA_UA_MASK, USBAXI_SA_UA_VAL); |
| 65 | |
| 66 | ret = xhci_register(dev, hcd, hcor); |
| 67 | if (ret) |
| 68 | dev_err(dev, "Failed to register xHCI\n"); |
| 69 | |
| 70 | return ret; |
| 71 | } |
| 72 | |
| 73 | static int xhci_brcm_deregister(struct udevice *dev) |
| 74 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 75 | struct brcm_xhci_plat *plat = dev_get_plat(dev); |
Rayagonda Kokatanur | f59d24e | 2020-04-09 09:23:15 +0530 | [diff] [blame] | 76 | |
| 77 | /* Restore the default values for AXI read and write attributes */ |
| 78 | writel(plat->awcache, plat->hc_base + DRD2U3H_XHC_REGS_AXIWRA); |
| 79 | writel(plat->arcache, plat->hc_base + DRD2U3H_XHC_REGS_AXIRDA); |
| 80 | |
| 81 | return xhci_deregister(dev); |
| 82 | } |
| 83 | |
| 84 | static const struct udevice_id xhci_brcm_ids[] = { |
| 85 | { .compatible = "brcm,generic-xhci" }, |
| 86 | { } |
| 87 | }; |
| 88 | |
| 89 | U_BOOT_DRIVER(usb_xhci) = { |
| 90 | .name = "xhci_brcm", |
| 91 | .id = UCLASS_USB, |
| 92 | .probe = xhci_brcm_probe, |
| 93 | .remove = xhci_brcm_deregister, |
| 94 | .ops = &xhci_usb_ops, |
| 95 | .of_match = xhci_brcm_ids, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 96 | .plat_auto = sizeof(struct brcm_xhci_plat), |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 97 | .priv_auto = sizeof(struct xhci_ctrl), |
Rayagonda Kokatanur | f59d24e | 2020-04-09 09:23:15 +0530 | [diff] [blame] | 98 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 99 | }; |