blob: fe17924028cd22ede5c28a79dd38c8fb9d9c64a8 [file] [log] [blame]
Rayagonda Kokatanurf59d24e2020-04-09 09:23:15 +05301// 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 Agner3fa593d2021-10-06 14:05:29 +020011#include <dm/device_compat.h>
Rayagonda Kokatanurf59d24e2020-04-09 09:23:15 +053012#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 Glassb75b15b2020-12-03 16:55:23 -070026struct brcm_xhci_plat {
Rayagonda Kokatanurf59d24e2020-04-09 09:23:15 +053027 unsigned int arcache;
28 unsigned int awcache;
29 void __iomem *hc_base;
30};
31
32static int xhci_brcm_probe(struct udevice *dev)
33{
Simon Glassb75b15b2020-12-03 16:55:23 -070034 struct brcm_xhci_plat *plat = dev_get_plat(dev);
Rayagonda Kokatanurf59d24e2020-04-09 09:23:15 +053035 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
73static int xhci_brcm_deregister(struct udevice *dev)
74{
Simon Glassb75b15b2020-12-03 16:55:23 -070075 struct brcm_xhci_plat *plat = dev_get_plat(dev);
Rayagonda Kokatanurf59d24e2020-04-09 09:23:15 +053076
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
84static const struct udevice_id xhci_brcm_ids[] = {
85 { .compatible = "brcm,generic-xhci" },
86 { }
87};
88
89U_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 Glassb75b15b2020-12-03 16:55:23 -070096 .plat_auto = sizeof(struct brcm_xhci_plat),
Simon Glass8a2b47f2020-12-03 16:55:17 -070097 .priv_auto = sizeof(struct xhci_ctrl),
Rayagonda Kokatanurf59d24e2020-04-09 09:23:15 +053098 .flags = DM_FLAG_ALLOC_PRIV_DMA,
99};