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
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
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.
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>
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
26 + * fotg210_vbus() - Called by gadget driver to enable/disable VBUS
27 + * @enable: true to enable VBUS, false to disable VBUS
29 +void fotg210_vbus(struct fotg210 *fotg, bool enable)
35 + switch (fotg->port) {
37 + mask = GEMINI_MISC_USB0_VBUS_ON;
38 + val = enable ? GEMINI_MISC_USB0_VBUS_ON : 0;
41 + mask = GEMINI_MISC_USB1_VBUS_ON;
42 + val = enable ? GEMINI_MISC_USB1_VBUS_ON : 0;
47 + ret = regmap_update_bits(fotg->map, GEMINI_GLOBAL_MISC_CTRL, mask, val);
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");
54 static int fotg210_probe(struct platform_device *pdev)
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
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
70 +static int fotg210_vbus_session(struct usb_gadget *g, int is_active)
72 + struct fotg210_udc *fotg210 = gadget_to_fotg210(g);
74 + /* Call down to core integration layer to drive or disable VBUS */
75 + fotg210_vbus(fotg210->fotg, is_active);
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,
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;
92 +void fotg210_vbus(struct fotg210 *fotg, bool enable);
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);