1 // SPDX-License-Identifier: GPL-2.0+
5 * Renesas RCar USB HOST xHCI Controller
16 #include <dm/device_compat.h>
19 #include "xhci-rcar-r8a779x_usb3_v3.h"
22 #define RCAR_USB3_DL_CTRL 0x250 /* FW Download Control & Status */
23 #define RCAR_USB3_FW_DATA0 0x258 /* FW Data0 */
25 /* Register Settings */
26 /* FW Download Control & Status */
27 #define RCAR_USB3_DL_CTRL_ENABLE BIT(0)
28 #define RCAR_USB3_DL_CTRL_FW_SUCCESS BIT(4)
29 #define RCAR_USB3_DL_CTRL_FW_SET_DATA0 BIT(8)
31 struct rcar_xhci_platdata {
37 * Contains pointers to register base addresses
38 * for the usb controller.
41 struct xhci_ctrl ctrl; /* Needs to come first in this struct! */
42 struct usb_platdata usb_plat;
43 struct xhci_hccr *hcd;
46 static int xhci_rcar_download_fw(struct rcar_xhci *ctx, const u32 *fw_data,
47 const size_t fw_array_size)
49 void __iomem *regs = (void __iomem *)ctx->hcd;
52 /* Download R-Car USB3.0 firmware */
53 setbits_le32(regs + RCAR_USB3_DL_CTRL, RCAR_USB3_DL_CTRL_ENABLE);
55 for (i = 0; i < fw_array_size; i++) {
56 writel(fw_data[i], regs + RCAR_USB3_FW_DATA0);
57 setbits_le32(regs + RCAR_USB3_DL_CTRL,
58 RCAR_USB3_DL_CTRL_FW_SET_DATA0);
60 ret = wait_for_bit_le32(regs + RCAR_USB3_DL_CTRL,
61 RCAR_USB3_DL_CTRL_FW_SET_DATA0, false,
67 clrbits_le32(regs + RCAR_USB3_DL_CTRL, RCAR_USB3_DL_CTRL_ENABLE);
69 ret = wait_for_bit_le32(regs + RCAR_USB3_DL_CTRL,
70 RCAR_USB3_DL_CTRL_FW_SUCCESS, true,
76 static int xhci_rcar_probe(struct udevice *dev)
78 struct rcar_xhci_platdata *plat = dev_get_platdata(dev);
79 struct rcar_xhci *ctx = dev_get_priv(dev);
80 struct xhci_hcor *hcor;
83 ret = clk_get_by_index(dev, 0, &plat->clk);
85 dev_err(dev, "Failed to get USB3 clock\n");
89 ret = clk_enable(&plat->clk);
91 dev_err(dev, "Failed to enable USB3 clock\n");
95 ctx->hcd = (struct xhci_hccr *)plat->hcd_base;
96 len = HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase));
97 hcor = (struct xhci_hcor *)((uintptr_t)ctx->hcd + len);
99 ret = xhci_rcar_download_fw(ctx, firmware_r8a779x_usb3_v3,
100 ARRAY_SIZE(firmware_r8a779x_usb3_v3));
102 dev_err(dev, "Failed to download firmware\n");
106 ret = xhci_register(dev, ctx->hcd, hcor);
108 dev_err(dev, "Failed to register xHCI\n");
115 clk_disable(&plat->clk);
117 clk_free(&plat->clk);
121 static int xhci_rcar_deregister(struct udevice *dev)
124 struct rcar_xhci_platdata *plat = dev_get_platdata(dev);
126 ret = xhci_deregister(dev);
128 clk_disable(&plat->clk);
129 clk_free(&plat->clk);
134 static int xhci_rcar_ofdata_to_platdata(struct udevice *dev)
136 struct rcar_xhci_platdata *plat = dev_get_platdata(dev);
138 plat->hcd_base = devfdt_get_addr(dev);
139 if (plat->hcd_base == FDT_ADDR_T_NONE) {
140 debug("Can't get the XHCI register base address\n");
147 static const struct udevice_id xhci_rcar_ids[] = {
148 { .compatible = "renesas,xhci-r8a7795" },
149 { .compatible = "renesas,xhci-r8a7796" },
150 { .compatible = "renesas,xhci-r8a77965" },
154 U_BOOT_DRIVER(usb_xhci) = {
157 .probe = xhci_rcar_probe,
158 .remove = xhci_rcar_deregister,
159 .ops = &xhci_usb_ops,
160 .of_match = xhci_rcar_ids,
161 .ofdata_to_platdata = xhci_rcar_ofdata_to_platdata,
162 .platdata_auto_alloc_size = sizeof(struct rcar_xhci_platdata),
163 .priv_auto_alloc_size = sizeof(struct rcar_xhci),
164 .flags = DM_FLAG_ALLOC_PRIV_DMA,