gemini: Add kernel v6.1 patches
[openwrt/staging/mans0n.git] / target / linux / gemini / patches-6.1 / 0021-usb-fotg210-udc-Implement-VBUS-session.patch
1 From 2fbbfb2c556944945639b17b13fcb1e05272b646 Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Wed, 18 Jan 2023 08:09:21 +0100
4 Subject: [PATCH 21/29] usb: fotg210-udc: Implement VBUS session
5
6 Implement VBUS session handling for FOTG210. This is
7 mainly used by the UDC driver which needs to call down to
8 the FOTG210 core and enable/disable VBUS, as this needs to be
9 handled outside of the HCD and UDC drivers, by platform
10 specific glue code.
11
12 The Gemini has a special bit in a system register to turn
13 VBUS on and off so we implement this in the FOTG210 core.
14
15 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
16 Link: https://lore.kernel.org/r/20230103-gemini-fotg210-usb-v2-7-100388af9810@linaro.org
17 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
18 ---
19 --- a/drivers/usb/fotg210/fotg210-core.c
20 +++ b/drivers/usb/fotg210/fotg210-core.c
21 @@ -95,6 +95,35 @@ static int fotg210_gemini_init(struct fo
22 return 0;
23 }
24
25 +/**
26 + * fotg210_vbus() - Called by gadget driver to enable/disable VBUS
27 + * @enable: true to enable VBUS, false to disable VBUS
28 + */
29 +void fotg210_vbus(struct fotg210 *fotg, bool enable)
30 +{
31 + u32 mask;
32 + u32 val;
33 + int ret;
34 +
35 + switch (fotg->port) {
36 + case GEMINI_PORT_0:
37 + mask = GEMINI_MISC_USB0_VBUS_ON;
38 + val = enable ? GEMINI_MISC_USB0_VBUS_ON : 0;
39 + break;
40 + case GEMINI_PORT_1:
41 + mask = GEMINI_MISC_USB1_VBUS_ON;
42 + val = enable ? GEMINI_MISC_USB1_VBUS_ON : 0;
43 + break;
44 + default:
45 + return;
46 + }
47 + ret = regmap_update_bits(fotg->map, GEMINI_GLOBAL_MISC_CTRL, mask, val);
48 + if (ret)
49 + dev_err(fotg->dev, "failed to %s VBUS\n",
50 + enable ? "enable" : "disable");
51 + dev_info(fotg->dev, "%s: %s VBUS\n", __func__, enable ? "enable" : "disable");
52 +}
53 +
54 static int fotg210_probe(struct platform_device *pdev)
55 {
56 struct device *dev = &pdev->dev;
57 --- a/drivers/usb/fotg210/fotg210-udc.c
58 +++ b/drivers/usb/fotg210/fotg210-udc.c
59 @@ -1095,9 +1095,26 @@ static int fotg210_udc_stop(struct usb_g
60 return 0;
61 }
62
63 +/**
64 + * fotg210_vbus_session - Called by external transceiver to enable/disable udc
65 + * @_gadget: usb gadget
66 + * @is_active: 0 if should disable UDC VBUS, 1 if should enable
67 + *
68 + * Returns 0
69 + */
70 +static int fotg210_vbus_session(struct usb_gadget *g, int is_active)
71 +{
72 + struct fotg210_udc *fotg210 = gadget_to_fotg210(g);
73 +
74 + /* Call down to core integration layer to drive or disable VBUS */
75 + fotg210_vbus(fotg210->fotg, is_active);
76 + return 0;
77 +}
78 +
79 static const struct usb_gadget_ops fotg210_gadget_ops = {
80 .udc_start = fotg210_udc_start,
81 .udc_stop = fotg210_udc_stop,
82 + .vbus_session = fotg210_vbus_session,
83 };
84
85 /**
86 --- a/drivers/usb/fotg210/fotg210.h
87 +++ b/drivers/usb/fotg210/fotg210.h
88 @@ -17,6 +17,8 @@ struct fotg210 {
89 enum gemini_port port;
90 };
91
92 +void fotg210_vbus(struct fotg210 *fotg, bool enable);
93 +
94 #ifdef CONFIG_USB_FOTG210_HCD
95 int fotg210_hcd_probe(struct platform_device *pdev, struct fotg210 *fotg);
96 int fotg210_hcd_remove(struct platform_device *pdev);