6a19a0aa4d9cb288cc3d9828c9f1e071bbe7c25a
[openwrt/openwrt.git] / target / linux / gemini / patches-6.1 / 0004-usb-fotg210-Select-subdriver-by-mode.patch
1 From 7c0b661926097e935f2711857596fc2277b2304a Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Sun, 23 Oct 2022 16:47:08 +0200
4 Subject: [PATCH 04/29] usb: fotg210: Select subdriver by mode
5
6 Check which mode the hardware is in, and selecte the peripheral
7 driver if the hardware is in explicit peripheral mode, otherwise
8 select host mode.
9
10 This should solve the immediate problem that both subdrivers
11 can get probed.
12
13 Cc: Fabian Vogt <fabian@ritter-vogt.de>
14 Cc: Yuan-Hsin Chen <yhchen@faraday-tech.com>
15 Cc: Felipe Balbi <balbi@kernel.org>
16 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
17 Link: https://lore.kernel.org/r/20221023144708.3596563-3-linus.walleij@linaro.org
18 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
19 ---
20 --- a/drivers/usb/fotg210/fotg210-core.c
21 +++ b/drivers/usb/fotg210/fotg210-core.c
22 @@ -10,30 +10,37 @@
23 #include <linux/of.h>
24 #include <linux/platform_device.h>
25 #include <linux/usb.h>
26 +#include <linux/usb/otg.h>
27
28 #include "fotg210.h"
29
30 static int fotg210_probe(struct platform_device *pdev)
31 {
32 + struct device *dev = &pdev->dev;
33 + enum usb_dr_mode mode;
34 int ret;
35
36 - if (IS_ENABLED(CONFIG_USB_FOTG210_HCD)) {
37 - ret = fotg210_hcd_probe(pdev);
38 - if (ret)
39 - return ret;
40 - }
41 - if (IS_ENABLED(CONFIG_USB_FOTG210_UDC))
42 + mode = usb_get_dr_mode(dev);
43 +
44 + if (mode == USB_DR_MODE_PERIPHERAL)
45 ret = fotg210_udc_probe(pdev);
46 + else
47 + ret = fotg210_hcd_probe(pdev);
48
49 return ret;
50 }
51
52 static int fotg210_remove(struct platform_device *pdev)
53 {
54 - if (IS_ENABLED(CONFIG_USB_FOTG210_HCD))
55 - fotg210_hcd_remove(pdev);
56 - if (IS_ENABLED(CONFIG_USB_FOTG210_UDC))
57 + struct device *dev = &pdev->dev;
58 + enum usb_dr_mode mode;
59 +
60 + mode = usb_get_dr_mode(dev);
61 +
62 + if (mode == USB_DR_MODE_PERIPHERAL)
63 fotg210_udc_remove(pdev);
64 + else
65 + fotg210_hcd_remove(pdev);
66
67 return 0;
68 }