gemini: Add kernel v6.1 patches
[openwrt/openwrt.git] / target / linux / gemini / patches-6.1 / 0019-usb-fotg210-Check-role-register-in-core.patch
1 From b1b07abb598211de3ce7f52abdf8dcb24384341e Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Wed, 18 Jan 2023 08:09:19 +0100
4 Subject: [PATCH 19/29] usb: fotg210: Check role register in core
5
6 Read the role register and check that we are in host/peripheral
7 mode and issue warnings if we're not in the right role when
8 probing respective driver.
9
10 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
11 Link: https://lore.kernel.org/r/20230103-gemini-fotg210-usb-v2-5-100388af9810@linaro.org
12 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
13 ---
14 --- a/drivers/usb/fotg210/fotg210-core.c
15 +++ b/drivers/usb/fotg210/fotg210-core.c
16 @@ -18,6 +18,11 @@
17
18 #include "fotg210.h"
19
20 +/* Role Register 0x80 */
21 +#define FOTG210_RR 0x80
22 +#define FOTG210_RR_ID BIT(21) /* 1 = B-device, 0 = A-device */
23 +#define FOTG210_RR_CROLE BIT(20) /* 1 = device, 0 = host */
24 +
25 /*
26 * Gemini-specific initialization function, only executed on the
27 * Gemini SoC using the global misc control register.
28 @@ -95,6 +100,7 @@ static int fotg210_probe(struct platform
29 struct device *dev = &pdev->dev;
30 enum usb_dr_mode mode;
31 struct fotg210 *fotg;
32 + u32 val;
33 int ret;
34
35 fotg = devm_kzalloc(dev, sizeof(*fotg), GFP_KERNEL);
36 @@ -122,10 +128,16 @@ static int fotg210_probe(struct platform
37 return ret;
38 }
39
40 - if (mode == USB_DR_MODE_PERIPHERAL)
41 + val = readl(fotg->base + FOTG210_RR);
42 + if (mode == USB_DR_MODE_PERIPHERAL) {
43 + if (!(val & FOTG210_RR_CROLE))
44 + dev_err(dev, "block not in device role\n");
45 ret = fotg210_udc_probe(pdev, fotg);
46 - else
47 + } else {
48 + if (val & FOTG210_RR_CROLE)
49 + dev_err(dev, "block not in host role\n");
50 ret = fotg210_hcd_probe(pdev, fotg);
51 + }
52
53 return ret;
54 }