kernel: bump 6.1 to 6.1.78
[openwrt/staging/stintel.git] / target / linux / bcm27xx / patches-6.1 / 950-0865-usb-dwc3-Set-DMA-and-coherent-masks-early.patch
1 From 4ffa5f2c5fc7854683964bb2f2bf23907c18213f Mon Sep 17 00:00:00 2001
2 From: Jonathan Bell <jonathan@raspberrypi.com>
3 Date: Mon, 13 Sep 2021 11:14:32 +0100
4 Subject: [PATCH] usb: dwc3: Set DMA and coherent masks early
5
6 dwc3 allocates scratch and event buffers in the top-level driver. Hack the
7 probe function to set the DMA mask before trying to allocate these.
8
9 I think the event buffers are only used in device mode, but the scratch
10 buffers may be used if core hibernation is enabled.
11
12 usb: dwc3: add support for new DT quirks
13
14 Apply the optional axi-pipe-limit and dis-in-autoretry-quirk properties
15 during driver probe.
16
17 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
18
19 phy: phy-brcm-usb: Add 2712 support
20
21 usb: dwc3: if the host controller instance number is present in DT, use it
22
23 If two instances of a dwc3 host controller are specified in devicetree,
24 then the probe order may be arbitrary which results in the device names
25 swapping on a per-boot basis.
26
27 If a "usb" alias with the instance number is specified, then use
28 that to construct the device name instead of autogenerating one.
29
30 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
31
32 rp1 dwc3 changes
33
34 drivers: usb: dwc3: allow setting GTXTHRCFG on dwc_usb3.0 hardware
35
36 Equivalent register fields exist in the SuperSpeed Host version of the
37 hardware, so allow the use of TX thresholds if specified in devicetree.
38
39 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
40
41 drivers: usb: dwc3: remove downstream quirk dis-in-autoretry
42
43 Upstream have unilaterally disabled the feature.
44
45 Partially reverts 6e9142a26ee0fdc3a5adc49ed6cedc0b16ec2ed1 (downstream)
46
47 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
48 ---
49 drivers/phy/broadcom/Kconfig | 2 +-
50 .../phy/broadcom/phy-brcm-usb-init-synopsys.c | 59 +++++++++++++++++++
51 drivers/phy/broadcom/phy-brcm-usb-init.h | 2 +
52 drivers/phy/broadcom/phy-brcm-usb.c | 18 +++++-
53 drivers/usb/dwc3/core.c | 52 ++++++++++++++++
54 drivers/usb/dwc3/core.h | 10 ++++
55 drivers/usb/dwc3/host.c | 17 ++++--
56 7 files changed, 153 insertions(+), 7 deletions(-)
57
58 --- a/drivers/phy/broadcom/Kconfig
59 +++ b/drivers/phy/broadcom/Kconfig
60 @@ -93,7 +93,7 @@ config PHY_BRCM_SATA
61
62 config PHY_BRCM_USB
63 tristate "Broadcom STB USB PHY driver"
64 - depends on ARCH_BCMBCA || ARCH_BRCMSTB || COMPILE_TEST
65 + depends on ARCH_BCMBCA || ARCH_BRCMSTB || ARCH_BCM2835 || COMPILE_TEST
66 depends on OF
67 select GENERIC_PHY
68 select SOC_BRCMSTB if ARCH_BRCMSTB
69 --- a/drivers/phy/broadcom/phy-brcm-usb-init-synopsys.c
70 +++ b/drivers/phy/broadcom/phy-brcm-usb-init-synopsys.c
71 @@ -318,6 +318,36 @@ static void usb_init_common_7216(struct
72 usb_init_common(params);
73 }
74
75 +static void usb_init_common_2712(struct brcm_usb_init_params *params)
76 +{
77 + void __iomem *ctrl = params->regs[BRCM_REGS_CTRL];
78 + void __iomem *bdc_ec = params->regs[BRCM_REGS_BDC_EC];
79 + u32 reg;
80 +
81 + if (params->syscon_piarbctl)
82 + syscon_piarbctl_init(params->syscon_piarbctl);
83 +
84 + USB_CTRL_UNSET(ctrl, USB_PM, USB_PWRDN);
85 +
86 + usb_wake_enable_7211b0(params, false);
87 +
88 + usb_init_common(params);
89 +
90 + /*
91 + * The BDC controller will get occasional failures with
92 + * the default "Read Transaction Size" of 6 (1024 bytes).
93 + * Set it to 4 (256 bytes).
94 + */
95 + if ((params->mode != USB_CTLR_MODE_HOST) && bdc_ec) {
96 + reg = brcm_usb_readl(bdc_ec + BDC_EC_AXIRDA);
97 + reg &= ~BDC_EC_AXIRDA_RTS_MASK;
98 + reg |= (0x4 << BDC_EC_AXIRDA_RTS_SHIFT);
99 + brcm_usb_writel(reg, bdc_ec + BDC_EC_AXIRDA);
100 + }
101 +
102 + usb2_eye_fix_7211b0(params);
103 +}
104 +
105 static void usb_init_xhci(struct brcm_usb_init_params *params)
106 {
107 pr_debug("%s\n", __func__);
108 @@ -363,6 +393,18 @@ static void usb_uninit_common_7211b0(str
109
110 }
111
112 +static void usb_uninit_common_2712(struct brcm_usb_init_params *params)
113 +{
114 + void __iomem *ctrl = params->regs[BRCM_REGS_CTRL];
115 +
116 + if (params->wake_enabled) {
117 + USB_CTRL_SET(ctrl, TEST_PORT_CTL, TPOUT_SEL_PME_GEN);
118 + usb_wake_enable_7211b0(params, true);
119 + } else {
120 + USB_CTRL_SET(ctrl, USB_PM, USB_PWRDN);
121 + }
122 +}
123 +
124 static void usb_uninit_xhci(struct brcm_usb_init_params *params)
125 {
126
127 @@ -417,6 +459,16 @@ static const struct brcm_usb_init_ops bc
128 .set_dual_select = usb_set_dual_select,
129 };
130
131 +static const struct brcm_usb_init_ops bcm2712_ops = {
132 + .init_ipp = usb_init_ipp,
133 + .init_common = usb_init_common_2712,
134 + .init_xhci = usb_init_xhci,
135 + .uninit_common = usb_uninit_common_2712,
136 + .uninit_xhci = usb_uninit_xhci,
137 + .get_dual_select = usb_get_dual_select,
138 + .set_dual_select = usb_set_dual_select,
139 +};
140 +
141 void brcm_usb_dvr_init_7216(struct brcm_usb_init_params *params)
142 {
143
144 @@ -434,3 +486,10 @@ void brcm_usb_dvr_init_7211b0(struct brc
145 params->family_name = "7211";
146 params->ops = &bcm7211b0_ops;
147 }
148 +
149 +void brcm_usb_dvr_init_2712(struct brcm_usb_init_params *params)
150 +{
151 + params->family_name = "2712";
152 + params->ops = &bcm2712_ops;
153 + params->suspend_with_clocks = true;
154 +}
155 --- a/drivers/phy/broadcom/phy-brcm-usb-init.h
156 +++ b/drivers/phy/broadcom/phy-brcm-usb-init.h
157 @@ -61,12 +61,14 @@ struct brcm_usb_init_params {
158 const struct brcm_usb_init_ops *ops;
159 struct regmap *syscon_piarbctl;
160 bool wake_enabled;
161 + bool suspend_with_clocks;
162 };
163
164 void brcm_usb_dvr_init_4908(struct brcm_usb_init_params *params);
165 void brcm_usb_dvr_init_7445(struct brcm_usb_init_params *params);
166 void brcm_usb_dvr_init_7216(struct brcm_usb_init_params *params);
167 void brcm_usb_dvr_init_7211b0(struct brcm_usb_init_params *params);
168 +void brcm_usb_dvr_init_2712(struct brcm_usb_init_params *params);
169
170 static inline u32 brcm_usb_readl(void __iomem *addr)
171 {
172 --- a/drivers/phy/broadcom/phy-brcm-usb.c
173 +++ b/drivers/phy/broadcom/phy-brcm-usb.c
174 @@ -76,7 +76,7 @@ struct brcm_usb_phy_data {
175 };
176
177 static s8 *node_reg_names[BRCM_REGS_MAX] = {
178 - "crtl", "xhci_ec", "xhci_gbl", "usb_phy", "usb_mdio", "bdc_ec"
179 + "ctrl", "xhci_ec", "xhci_gbl", "usb_phy", "usb_mdio", "bdc_ec"
180 };
181
182 static int brcm_pm_notifier(struct notifier_block *notifier,
183 @@ -315,6 +315,18 @@ static const struct match_chip_info chip
184 .optional_reg = BRCM_REGS_BDC_EC,
185 };
186
187 +static const struct match_chip_info chip_info_2712 = {
188 + .init_func = &brcm_usb_dvr_init_2712,
189 + .required_regs = {
190 + BRCM_REGS_CTRL,
191 + BRCM_REGS_XHCI_EC,
192 + BRCM_REGS_XHCI_GBL,
193 + BRCM_REGS_USB_MDIO,
194 + -1,
195 + },
196 + .optional_reg = BRCM_REGS_BDC_EC,
197 +};
198 +
199 static const struct match_chip_info chip_info_7445 = {
200 .init_func = &brcm_usb_dvr_init_7445,
201 .required_regs = {
202 @@ -338,6 +350,10 @@ static const struct of_device_id brcm_us
203 .data = &chip_info_7211b0,
204 },
205 {
206 + .compatible = "brcm,bcm2712-usb-phy",
207 + .data = &chip_info_2712,
208 + },
209 + {
210 .compatible = "brcm,brcmstb-usb-phy",
211 .data = &chip_info_7445,
212 },
213 --- a/drivers/usb/dwc3/core.c
214 +++ b/drivers/usb/dwc3/core.c
215 @@ -1179,6 +1179,24 @@ static void dwc3_config_threshold(struct
216 }
217 }
218
219 +static void dwc3_set_axi_pipe_limit(struct dwc3 *dwc)
220 +{
221 + struct device *dev = dwc->dev;
222 + u32 cfg;
223 +
224 + if (!dwc->axi_pipe_limit)
225 + return;
226 + if (dwc->axi_pipe_limit > 16) {
227 + dev_err(dev, "Invalid axi_pipe_limit property\n");
228 + return;
229 + }
230 + cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG1);
231 + cfg &= ~DWC3_GSBUSCFG1_PIPETRANSLIMIT(15);
232 + cfg |= DWC3_GSBUSCFG1_PIPETRANSLIMIT(dwc->axi_pipe_limit - 1);
233 +
234 + dwc3_writel(dwc->regs, DWC3_GSBUSCFG1, cfg);
235 +}
236 +
237 /**
238 * dwc3_core_init - Low-level initialization of DWC3 Core
239 * @dwc: Pointer to our controller context structure
240 @@ -1271,6 +1289,8 @@ static int dwc3_core_init(struct dwc3 *d
241
242 dwc3_set_incr_burst_type(dwc);
243
244 + dwc3_set_axi_pipe_limit(dwc);
245 +
246 usb_phy_set_suspend(dwc->usb2_phy, 0);
247 usb_phy_set_suspend(dwc->usb3_phy, 0);
248 ret = phy_power_on(dwc->usb2_generic_phy);
249 @@ -1504,6 +1524,7 @@ static void dwc3_get_properties(struct d
250 u8 tx_thr_num_pkt_prd = 0;
251 u8 tx_max_burst_prd = 0;
252 u8 tx_fifo_resize_max_num;
253 + u8 axi_pipe_limit;
254 const char *usb_psy_name;
255 int ret;
256
257 @@ -1526,6 +1547,9 @@ static void dwc3_get_properties(struct d
258 */
259 tx_fifo_resize_max_num = 6;
260
261 + /* Default to 0 (don't override hardware defaults) */
262 + axi_pipe_limit = 0;
263 +
264 dwc->maximum_speed = usb_get_maximum_speed(dev);
265 dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev);
266 dwc->dr_mode = usb_get_dr_mode(dev);
267 @@ -1641,6 +1665,9 @@ static void dwc3_get_properties(struct d
268 dwc->dis_split_quirk = device_property_read_bool(dev,
269 "snps,dis-split-quirk");
270
271 + device_property_read_u8(dev, "snps,axi-pipe-limit",
272 + &axi_pipe_limit);
273 +
274 dwc->lpm_nyet_threshold = lpm_nyet_threshold;
275 dwc->tx_de_emphasis = tx_de_emphasis;
276
277 @@ -1658,6 +1685,8 @@ static void dwc3_get_properties(struct d
278 dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd;
279 dwc->tx_max_burst_prd = tx_max_burst_prd;
280
281 + dwc->axi_pipe_limit = axi_pipe_limit;
282 +
283 dwc->imod_interval = 0;
284
285 dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num;
286 @@ -1866,6 +1895,12 @@ static int dwc3_probe(struct platform_de
287
288 dwc3_get_properties(dwc);
289
290 + if (!dwc->sysdev_is_parent) {
291 + ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64));
292 + if (ret)
293 + return ret;
294 + }
295 +
296 dwc->reset = devm_reset_control_array_get_optional_shared(dev);
297 if (IS_ERR(dwc->reset)) {
298 ret = PTR_ERR(dwc->reset);
299 --- a/drivers/usb/dwc3/core.h
300 +++ b/drivers/usb/dwc3/core.h
301 @@ -183,6 +183,9 @@
302 #define DWC3_GSBUSCFG0_INCRBRSTENA (1 << 0) /* undefined length enable */
303 #define DWC3_GSBUSCFG0_INCRBRST_MASK 0xff
304
305 +/* Global SoC Bus Configuration Register 1 */
306 +#define DWC3_GSBUSCFG1_PIPETRANSLIMIT(n) (((n) & 0xf) << 8)
307 +
308 /* Global Debug LSP MUX Select */
309 #define DWC3_GDBGLSPMUX_ENDBC BIT(15) /* Host only */
310 #define DWC3_GDBGLSPMUX_HOSTSELECT(n) ((n) & 0x3fff)
311 @@ -1056,6 +1059,7 @@ struct dwc3_scratchpad_array {
312 * @tx_max_burst_prd: max periodic ESS transmit burst size
313 * @tx_fifo_resize_max_num: max number of fifos allocated during txfifo resize
314 * @clear_stall_protocol: endpoint number that requires a delayed status phase
315 + * @axi_max_pipe: set to override the maximum number of pipelined AXI transfers
316 * @hsphy_interface: "utmi" or "ulpi"
317 * @connected: true when we're connected to a host, false otherwise
318 * @softconnect: true when gadget connect is called, false when disconnect runs
319 @@ -1287,6 +1291,7 @@ struct dwc3 {
320 u8 tx_max_burst_prd;
321 u8 tx_fifo_resize_max_num;
322 u8 clear_stall_protocol;
323 + u8 axi_pipe_limit;
324
325 const char *hsphy_interface;
326
327 --- a/drivers/usb/dwc3/host.c
328 +++ b/drivers/usb/dwc3/host.c
329 @@ -30,10 +30,10 @@ static void dwc3_host_fill_xhci_irq_res(
330
331 static int dwc3_host_get_irq(struct dwc3 *dwc)
332 {
333 - struct platform_device *dwc3_pdev = to_platform_device(dwc->dev);
334 + struct platform_device *pdev = to_platform_device(dwc->dev);
335 int irq;
336
337 - irq = platform_get_irq_byname_optional(dwc3_pdev, "host");
338 + irq = platform_get_irq_byname_optional(pdev, "host");
339 if (irq > 0) {
340 dwc3_host_fill_xhci_irq_res(dwc, irq, "host");
341 goto out;
342 @@ -42,7 +42,7 @@ static int dwc3_host_get_irq(struct dwc3
343 if (irq == -EPROBE_DEFER)
344 goto out;
345
346 - irq = platform_get_irq_byname_optional(dwc3_pdev, "dwc_usb3");
347 + irq = platform_get_irq_byname_optional(pdev, "dwc_usb3");
348 if (irq > 0) {
349 dwc3_host_fill_xhci_irq_res(dwc, irq, "dwc_usb3");
350 goto out;
351 @@ -51,7 +51,7 @@ static int dwc3_host_get_irq(struct dwc3
352 if (irq == -EPROBE_DEFER)
353 goto out;
354
355 - irq = platform_get_irq(dwc3_pdev, 0);
356 + irq = platform_get_irq(pdev, 0);
357 if (irq > 0) {
358 dwc3_host_fill_xhci_irq_res(dwc, irq, NULL);
359 goto out;
360 @@ -66,16 +66,23 @@ out:
361
362 int dwc3_host_init(struct dwc3 *dwc)
363 {
364 + struct platform_device *pdev = to_platform_device(dwc->dev);
365 struct property_entry props[5];
366 struct platform_device *xhci;
367 int ret, irq;
368 int prop_idx = 0;
369 + int id;
370
371 irq = dwc3_host_get_irq(dwc);
372 if (irq < 0)
373 return irq;
374
375 - xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
376 + id = of_alias_get_id(pdev->dev.of_node, "usb");
377 + if (id >= 0)
378 + xhci = platform_device_alloc("xhci-hcd", id);
379 + else
380 + xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
381 +
382 if (!xhci) {
383 dev_err(dwc->dev, "couldn't allocate xHCI device\n");
384 return -ENOMEM;