gemini: Add kernel v6.1 patches
[openwrt/openwrt.git] / target / linux / gemini / patches-6.1 / 0005-usb-fotg2-add-Gemini-specific-handling.patch
1 From f7f6c8aca91093e2f886ec97910b1a7d9a69bf9b Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Wed, 9 Nov 2022 21:05:54 +0100
4 Subject: [PATCH 05/29] usb: fotg2: add Gemini-specific handling
5
6 The Cortina Systems Gemini has bolted on a PHY inside the
7 silicon that can be handled by six bits in a MISC register in
8 the system controller.
9
10 If we are running on Gemini, look up a syscon regmap through
11 a phandle and enable VBUS and optionally the Mini-B connector.
12
13 If the device is flagged as "wakeup-source" using the standard
14 DT bindings, we also enable this in the global controller for
15 respective port.
16
17 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
18 Link: https://lore.kernel.org/r/20221109200554.1957185-1-linus.walleij@linaro.org
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20 ---
21 --- a/drivers/usb/fotg210/Kconfig
22 +++ b/drivers/usb/fotg210/Kconfig
23 @@ -5,6 +5,7 @@ config USB_FOTG210
24 depends on USB || USB_GADGET
25 depends on HAS_DMA && HAS_IOMEM
26 default ARCH_GEMINI
27 + select MFD_SYSCON
28 help
29 Faraday FOTG210 is a dual-mode USB controller that can act
30 in both host controller and peripheral controller mode.
31 --- a/drivers/usb/fotg210/fotg210-core.c
32 +++ b/drivers/usb/fotg210/fotg210-core.c
33 @@ -5,15 +5,86 @@
34 * whether to proceed with probing the host or the peripheral
35 * driver.
36 */
37 +#include <linux/bitops.h>
38 #include <linux/device.h>
39 +#include <linux/mfd/syscon.h>
40 #include <linux/module.h>
41 #include <linux/of.h>
42 #include <linux/platform_device.h>
43 +#include <linux/regmap.h>
44 #include <linux/usb.h>
45 #include <linux/usb/otg.h>
46
47 #include "fotg210.h"
48
49 +/*
50 + * Gemini-specific initialization function, only executed on the
51 + * Gemini SoC using the global misc control register.
52 + *
53 + * The gemini USB blocks are connected to either Mini-A (host mode) or
54 + * Mini-B (peripheral mode) plugs. There is no role switch support on the
55 + * Gemini SoC, just either-or.
56 + */
57 +#define GEMINI_GLOBAL_MISC_CTRL 0x30
58 +#define GEMINI_MISC_USB0_WAKEUP BIT(14)
59 +#define GEMINI_MISC_USB1_WAKEUP BIT(15)
60 +#define GEMINI_MISC_USB0_VBUS_ON BIT(22)
61 +#define GEMINI_MISC_USB1_VBUS_ON BIT(23)
62 +#define GEMINI_MISC_USB0_MINI_B BIT(29)
63 +#define GEMINI_MISC_USB1_MINI_B BIT(30)
64 +
65 +static int fotg210_gemini_init(struct device *dev, struct resource *res,
66 + enum usb_dr_mode mode)
67 +{
68 + struct device_node *np = dev->of_node;
69 + struct regmap *map;
70 + bool wakeup;
71 + u32 mask, val;
72 + int ret;
73 +
74 + map = syscon_regmap_lookup_by_phandle(np, "syscon");
75 + if (IS_ERR(map)) {
76 + dev_err(dev, "no syscon\n");
77 + return PTR_ERR(map);
78 + }
79 + wakeup = of_property_read_bool(np, "wakeup-source");
80 +
81 + /*
82 + * Figure out if this is USB0 or USB1 by simply checking the
83 + * physical base address.
84 + */
85 + mask = 0;
86 + if (res->start == 0x69000000) {
87 + mask = GEMINI_MISC_USB1_VBUS_ON | GEMINI_MISC_USB1_MINI_B |
88 + GEMINI_MISC_USB1_WAKEUP;
89 + if (mode == USB_DR_MODE_HOST)
90 + val = GEMINI_MISC_USB1_VBUS_ON;
91 + else
92 + val = GEMINI_MISC_USB1_MINI_B;
93 + if (wakeup)
94 + val |= GEMINI_MISC_USB1_WAKEUP;
95 + } else {
96 + mask = GEMINI_MISC_USB0_VBUS_ON | GEMINI_MISC_USB0_MINI_B |
97 + GEMINI_MISC_USB0_WAKEUP;
98 + if (mode == USB_DR_MODE_HOST)
99 + val = GEMINI_MISC_USB0_VBUS_ON;
100 + else
101 + val = GEMINI_MISC_USB0_MINI_B;
102 + if (wakeup)
103 + val |= GEMINI_MISC_USB0_WAKEUP;
104 + }
105 +
106 + ret = regmap_update_bits(map, GEMINI_GLOBAL_MISC_CTRL, mask, val);
107 + if (ret) {
108 + dev_err(dev, "failed to initialize Gemini PHY\n");
109 + return ret;
110 + }
111 +
112 + dev_info(dev, "initialized Gemini PHY in %s mode\n",
113 + (mode == USB_DR_MODE_HOST) ? "host" : "gadget");
114 + return 0;
115 +}
116 +
117 static int fotg210_probe(struct platform_device *pdev)
118 {
119 struct device *dev = &pdev->dev;
120 @@ -22,6 +93,15 @@ static int fotg210_probe(struct platform
121
122 mode = usb_get_dr_mode(dev);
123
124 + if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) {
125 + struct resource *res;
126 +
127 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
128 + ret = fotg210_gemini_init(dev, res, mode);
129 + if (ret)
130 + return ret;
131 + }
132 +
133 if (mode == USB_DR_MODE_PERIPHERAL)
134 ret = fotg210_udc_probe(pdev);
135 else