1 // SPDX-License-Identifier: GPL-2.0+
5 * Renesas RCar USB HOST xHCI Controller
15 #include <dm/device_compat.h>
18 #include "xhci-rcar-r8a779x_usb3_v3.h"
21 #define RCAR_USB3_DL_CTRL 0x250 /* FW Download Control & Status */
22 #define RCAR_USB3_FW_DATA0 0x258 /* FW Data0 */
24 /* Register Settings */
25 /* FW Download Control & Status */
26 #define RCAR_USB3_DL_CTRL_ENABLE BIT(0)
27 #define RCAR_USB3_DL_CTRL_FW_SUCCESS BIT(4)
28 #define RCAR_USB3_DL_CTRL_FW_SET_DATA0 BIT(8)
30 struct rcar_xhci_platdata {
36 * Contains pointers to register base addresses
37 * for the usb controller.
40 struct xhci_ctrl ctrl; /* Needs to come first in this struct! */
41 struct usb_platdata usb_plat;
42 struct xhci_hccr *hcd;
45 static int xhci_rcar_download_fw(struct rcar_xhci *ctx, const u32 *fw_data,
46 const size_t fw_array_size)
48 void __iomem *regs = (void __iomem *)ctx->hcd;
51 /* Download R-Car USB3.0 firmware */
52 setbits_le32(regs + RCAR_USB3_DL_CTRL, RCAR_USB3_DL_CTRL_ENABLE);
54 for (i = 0; i < fw_array_size; i++) {
55 writel(fw_data[i], regs + RCAR_USB3_FW_DATA0);
56 setbits_le32(regs + RCAR_USB3_DL_CTRL,
57 RCAR_USB3_DL_CTRL_FW_SET_DATA0);
59 ret = wait_for_bit_le32(regs + RCAR_USB3_DL_CTRL,
60 RCAR_USB3_DL_CTRL_FW_SET_DATA0, false,
66 clrbits_le32(regs + RCAR_USB3_DL_CTRL, RCAR_USB3_DL_CTRL_ENABLE);
68 ret = wait_for_bit_le32(regs + RCAR_USB3_DL_CTRL,
69 RCAR_USB3_DL_CTRL_FW_SUCCESS, true,
75 static int xhci_rcar_probe(struct udevice *dev)
77 struct rcar_xhci_platdata *plat = dev_get_platdata(dev);
78 struct rcar_xhci *ctx = dev_get_priv(dev);
79 struct xhci_hcor *hcor;
82 ret = clk_get_by_index(dev, 0, &plat->clk);
84 dev_err(dev, "Failed to get USB3 clock\n");
88 ret = clk_enable(&plat->clk);
90 dev_err(dev, "Failed to enable USB3 clock\n");
94 ctx->hcd = (struct xhci_hccr *)plat->hcd_base;
95 len = HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase));
96 hcor = (struct xhci_hcor *)((uintptr_t)ctx->hcd + len);
98 ret = xhci_rcar_download_fw(ctx, firmware_r8a779x_usb3_v3,
99 ARRAY_SIZE(firmware_r8a779x_usb3_v3));
101 dev_err(dev, "Failed to download firmware\n");
105 ret = xhci_register(dev, ctx->hcd, hcor);
107 dev_err(dev, "Failed to register xHCI\n");
114 clk_disable(&plat->clk);
116 clk_free(&plat->clk);
120 static int xhci_rcar_deregister(struct udevice *dev)
123 struct rcar_xhci_platdata *plat = dev_get_platdata(dev);
125 ret = xhci_deregister(dev);
127 clk_disable(&plat->clk);
128 clk_free(&plat->clk);
133 static int xhci_rcar_ofdata_to_platdata(struct udevice *dev)
135 struct rcar_xhci_platdata *plat = dev_get_platdata(dev);
137 plat->hcd_base = devfdt_get_addr(dev);
138 if (plat->hcd_base == FDT_ADDR_T_NONE) {
139 debug("Can't get the XHCI register base address\n");
146 static const struct udevice_id xhci_rcar_ids[] = {
147 { .compatible = "renesas,xhci-r8a7795" },
148 { .compatible = "renesas,xhci-r8a7796" },
149 { .compatible = "renesas,xhci-r8a77965" },
153 U_BOOT_DRIVER(usb_xhci) = {
156 .probe = xhci_rcar_probe,
157 .remove = xhci_rcar_deregister,
158 .ops = &xhci_usb_ops,
159 .of_match = xhci_rcar_ids,
160 .ofdata_to_platdata = xhci_rcar_ofdata_to_platdata,
161 .platdata_auto_alloc_size = sizeof(struct rcar_xhci_platdata),
162 .priv_auto_alloc_size = sizeof(struct rcar_xhci),
163 .flags = DM_FLAG_ALLOC_PRIV_DMA,