2 * xHCI host controller driver for R-Car SoCs
4 * Copyright (C) 2014 Renesas Electronics Corporation
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
11 #include <linux/firmware.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/usb/phy.h>
17 #include "xhci-plat.h"
18 #include "xhci-rcar.h"
21 * - The V2 firmware is possible to use on R-Car Gen2. However, the V2 causes
22 * performance degradation. So, this driver continues to use the V1 if R-Car
24 * - The V1 firmware is impossible to use on R-Car Gen3.
26 MODULE_FIRMWARE(XHCI_RCAR_FIRMWARE_NAME_V1
);
27 MODULE_FIRMWARE(XHCI_RCAR_FIRMWARE_NAME_V2
);
29 /*** Register Offset ***/
30 #define RCAR_USB3_INT_ENA 0x224 /* Interrupt Enable */
31 #define RCAR_USB3_DL_CTRL 0x250 /* FW Download Control & Status */
32 #define RCAR_USB3_FW_DATA0 0x258 /* FW Data0 */
34 #define RCAR_USB3_LCLK 0xa44 /* LCLK Select */
35 #define RCAR_USB3_CONF1 0xa48 /* USB3.0 Configuration1 */
36 #define RCAR_USB3_CONF2 0xa5c /* USB3.0 Configuration2 */
37 #define RCAR_USB3_CONF3 0xaa8 /* USB3.0 Configuration3 */
38 #define RCAR_USB3_RX_POL 0xab0 /* USB3.0 RX Polarity */
39 #define RCAR_USB3_TX_POL 0xab8 /* USB3.0 TX Polarity */
41 /*** Register Settings ***/
42 /* Interrupt Enable */
43 #define RCAR_USB3_INT_XHC_ENA 0x00000001
44 #define RCAR_USB3_INT_PME_ENA 0x00000002
45 #define RCAR_USB3_INT_HSE_ENA 0x00000004
46 #define RCAR_USB3_INT_ENA_VAL (RCAR_USB3_INT_XHC_ENA | \
47 RCAR_USB3_INT_PME_ENA | RCAR_USB3_INT_HSE_ENA)
49 /* FW Download Control & Status */
50 #define RCAR_USB3_DL_CTRL_ENABLE 0x00000001
51 #define RCAR_USB3_DL_CTRL_FW_SUCCESS 0x00000010
52 #define RCAR_USB3_DL_CTRL_FW_SET_DATA0 0x00000100
55 #define RCAR_USB3_LCLK_ENA_VAL 0x01030001
57 /* USB3.0 Configuration */
58 #define RCAR_USB3_CONF1_VAL 0x00030204
59 #define RCAR_USB3_CONF2_VAL 0x00030300
60 #define RCAR_USB3_CONF3_VAL 0x13802007
63 #define RCAR_USB3_RX_POL_VAL BIT(21)
64 #define RCAR_USB3_TX_POL_VAL BIT(4)
66 static void xhci_rcar_start_gen2(struct usb_hcd
*hcd
)
69 writel(RCAR_USB3_LCLK_ENA_VAL
, hcd
->regs
+ RCAR_USB3_LCLK
);
70 /* USB3.0 Configuration */
71 writel(RCAR_USB3_CONF1_VAL
, hcd
->regs
+ RCAR_USB3_CONF1
);
72 writel(RCAR_USB3_CONF2_VAL
, hcd
->regs
+ RCAR_USB3_CONF2
);
73 writel(RCAR_USB3_CONF3_VAL
, hcd
->regs
+ RCAR_USB3_CONF3
);
75 writel(RCAR_USB3_RX_POL_VAL
, hcd
->regs
+ RCAR_USB3_RX_POL
);
76 writel(RCAR_USB3_TX_POL_VAL
, hcd
->regs
+ RCAR_USB3_TX_POL
);
79 void xhci_rcar_start(struct usb_hcd
*hcd
)
83 if (hcd
->regs
!= NULL
) {
84 /* Interrupt Enable */
85 temp
= readl(hcd
->regs
+ RCAR_USB3_INT_ENA
);
86 temp
|= RCAR_USB3_INT_ENA_VAL
;
87 writel(temp
, hcd
->regs
+ RCAR_USB3_INT_ENA
);
88 if (xhci_plat_type_is(hcd
, XHCI_PLAT_TYPE_RENESAS_RCAR_GEN2
))
89 xhci_rcar_start_gen2(hcd
);
93 static int xhci_rcar_download_firmware(struct usb_hcd
*hcd
)
95 struct device
*dev
= hcd
->self
.controller
;
96 void __iomem
*regs
= hcd
->regs
;
97 struct xhci_plat_priv
*priv
= hcd_to_xhci_priv(hcd
);
98 const struct firmware
*fw
;
99 int retval
, index
, j
, time
;
103 /* request R-Car USB3.0 firmware */
104 retval
= request_firmware(&fw
, priv
->firmware_name
, dev
);
108 /* download R-Car USB3.0 firmware */
109 temp
= readl(regs
+ RCAR_USB3_DL_CTRL
);
110 temp
|= RCAR_USB3_DL_CTRL_ENABLE
;
111 writel(temp
, regs
+ RCAR_USB3_DL_CTRL
);
113 for (index
= 0; index
< fw
->size
; index
+= 4) {
114 /* to avoid reading beyond the end of the buffer */
115 for (data
= 0, j
= 3; j
>= 0; j
--) {
116 if ((j
+ index
) < fw
->size
)
117 data
|= fw
->data
[index
+ j
] << (8 * j
);
119 writel(data
, regs
+ RCAR_USB3_FW_DATA0
);
120 temp
= readl(regs
+ RCAR_USB3_DL_CTRL
);
121 temp
|= RCAR_USB3_DL_CTRL_FW_SET_DATA0
;
122 writel(temp
, regs
+ RCAR_USB3_DL_CTRL
);
124 for (time
= 0; time
< timeout
; time
++) {
125 val
= readl(regs
+ RCAR_USB3_DL_CTRL
);
126 if ((val
& RCAR_USB3_DL_CTRL_FW_SET_DATA0
) == 0)
130 if (time
== timeout
) {
136 temp
= readl(regs
+ RCAR_USB3_DL_CTRL
);
137 temp
&= ~RCAR_USB3_DL_CTRL_ENABLE
;
138 writel(temp
, regs
+ RCAR_USB3_DL_CTRL
);
140 for (time
= 0; time
< timeout
; time
++) {
141 val
= readl(regs
+ RCAR_USB3_DL_CTRL
);
142 if (val
& RCAR_USB3_DL_CTRL_FW_SUCCESS
) {
151 release_firmware(fw
);
156 /* This function needs to initialize a "phy" of usb before */
157 int xhci_rcar_init_quirk(struct usb_hcd
*hcd
)
159 /* If hcd->regs is NULL, we don't just call the following function */
163 return xhci_rcar_download_firmware(hcd
);