* [PATCH v2 1/4] dt-bindings: usb: usb-nop-xceiv: Repurpose vbus-regulator
2022-04-25 17:14 [PATCH v2 0/4] usb: phy: generic: Support enabling/disabling VBUS Sean Anderson
@ 2022-04-25 17:14 ` Sean Anderson
2022-04-25 20:26 ` Linus Walleij
2022-04-25 17:14 ` [PATCH v2 2/4] usb: phy: generic: Get the vbus supply Sean Anderson
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Sean Anderson @ 2022-04-25 17:14 UTC (permalink / raw)
To: Greg Kroah-Hartman, linux-usb
Cc: Mike Looijmans, Linus Walleij, Jules Maselbas, Felipe Balbi,
Jonathan Hunter, linux-kernel, Robert Jarzmik, Sean Anderson,
Rob Herring, devicetree
The vbus-regulator property was never actually read from the device tree.
Introduce a new property vbus-supply to represent the regulator powering
the VBUS when acting as an A-Device. This supply will be enabled and
disabled as necessary. Note that this is different from vbus-regulator,
which represented the available current available to draw from VBUS in
B-Device mode. Because no one was using vbus-regulator, remove it.
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---
Changes in v2:
- Fix dt_binding_check errors
Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml b/Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml
index 2824c17285ee..b4517b01616f 100644
--- a/Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml
+++ b/Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml
@@ -34,10 +34,9 @@ properties:
description: Should specify the GPIO detecting a VBus insertion
maxItems: 1
- vbus-regulator:
- description: Should specifiy the regulator supplying current drawn from
- the VBus line.
- $ref: /schemas/types.yaml#/definitions/phandle
+ vbus-supply:
+ description: regulator supplying VBUS. It will be enabled and disabled
+ dynamically in OTG mode.
required:
- compatible
@@ -57,7 +56,7 @@ examples:
vcc-supply = <&hsusb1_vcc_regulator>;
reset-gpios = <&gpio1 7 GPIO_ACTIVE_LOW>;
vbus-detect-gpio = <&gpio2 13 GPIO_ACTIVE_HIGH>;
- vbus-regulator = <&vbus_regulator>;
+ vbus-supply = <&vbus_regulator>;
#phy-cells = <0>;
};
--
2.35.1.1320.gc452695387.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/4] dt-bindings: usb: usb-nop-xceiv: Repurpose vbus-regulator
2022-04-25 17:14 ` [PATCH v2 1/4] dt-bindings: usb: usb-nop-xceiv: Repurpose vbus-regulator Sean Anderson
@ 2022-04-25 20:26 ` Linus Walleij
0 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2022-04-25 20:26 UTC (permalink / raw)
To: Sean Anderson
Cc: Greg Kroah-Hartman, linux-usb, Mike Looijmans, Jules Maselbas,
Felipe Balbi, Jonathan Hunter, linux-kernel, Robert Jarzmik,
Rob Herring, devicetree
On Mon, Apr 25, 2022 at 7:14 PM Sean Anderson <sean.anderson@seco.com> wrote:
> The vbus-regulator property was never actually read from the device tree.
> Introduce a new property vbus-supply to represent the regulator powering
> the VBUS when acting as an A-Device. This supply will be enabled and
> disabled as necessary. Note that this is different from vbus-regulator,
> which represented the available current available to draw from VBUS in
> B-Device mode. Because no one was using vbus-regulator, remove it.
>
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
(...)
> + vbus-supply:
> + description: regulator supplying VBUS. It will be enabled and disabled
> + dynamically in OTG mode.
I would add a small text snippet like this: "If the regulator is controlled by a
GPIO line, this should be modeled as a regulator-fixed and referenced
by this supply" - it's helpful because otherwise people tend to start to
submit weird stuff like adding yet another GPIO for this.
Either way:
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 2/4] usb: phy: generic: Get the vbus supply
2022-04-25 17:14 [PATCH v2 0/4] usb: phy: generic: Support enabling/disabling VBUS Sean Anderson
2022-04-25 17:14 ` [PATCH v2 1/4] dt-bindings: usb: usb-nop-xceiv: Repurpose vbus-regulator Sean Anderson
@ 2022-04-25 17:14 ` Sean Anderson
2022-04-25 17:14 ` [PATCH v2 3/4] usb: phy: generic: Implement otg->set_vbus Sean Anderson
2022-04-25 17:14 ` [PATCH v2 4/4] usb: phy: generic: Disable vbus on removal Sean Anderson
3 siblings, 0 replies; 6+ messages in thread
From: Sean Anderson @ 2022-04-25 17:14 UTC (permalink / raw)
To: Greg Kroah-Hartman, linux-usb
Cc: Mike Looijmans, Linus Walleij, Jules Maselbas, Felipe Balbi,
Jonathan Hunter, linux-kernel, Robert Jarzmik, Sean Anderson
While support for working with a vbus was added, the regulator was never
actually gotten (despite what was documented). Fix this by actually
getting the supply from the device tree.
Fixes: 7acc9973e3c4 ("usb: phy: generic: add vbus support")
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---
(no changes since v1)
drivers/usb/phy/phy-generic.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
index 661a229c105d..34b9f8140187 100644
--- a/drivers/usb/phy/phy-generic.c
+++ b/drivers/usb/phy/phy-generic.c
@@ -268,6 +268,13 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop)
return -EPROBE_DEFER;
}
+ nop->vbus_draw = devm_regulator_get_exclusive(dev, "vbus");
+ if (PTR_ERR(nop->vbus_draw) == -ENODEV)
+ nop->vbus_draw = NULL;
+ if (IS_ERR(nop->vbus_draw))
+ return dev_err_probe(dev, PTR_ERR(nop->vbus_draw),
+ "could not get vbus regulator\n");
+
nop->dev = dev;
nop->phy.dev = nop->dev;
nop->phy.label = "nop-xceiv";
--
2.35.1.1320.gc452695387.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/4] usb: phy: generic: Implement otg->set_vbus
2022-04-25 17:14 [PATCH v2 0/4] usb: phy: generic: Support enabling/disabling VBUS Sean Anderson
2022-04-25 17:14 ` [PATCH v2 1/4] dt-bindings: usb: usb-nop-xceiv: Repurpose vbus-regulator Sean Anderson
2022-04-25 17:14 ` [PATCH v2 2/4] usb: phy: generic: Get the vbus supply Sean Anderson
@ 2022-04-25 17:14 ` Sean Anderson
2022-04-25 17:14 ` [PATCH v2 4/4] usb: phy: generic: Disable vbus on removal Sean Anderson
3 siblings, 0 replies; 6+ messages in thread
From: Sean Anderson @ 2022-04-25 17:14 UTC (permalink / raw)
To: Greg Kroah-Hartman, linux-usb
Cc: Mike Looijmans, Linus Walleij, Jules Maselbas, Felipe Balbi,
Jonathan Hunter, linux-kernel, Robert Jarzmik, Sean Anderson
Some USB controller drivers call otg_set_vbus when entering host or
device mode. Implement this callback so that VBUS can be turned on and
off automatically. This is especially useful when there is no property
for a VBUS supply in the controller's binding.
This results in a change in semantics of the vbus_draw regulator.
Whereas before it represented the VBUS supplied by an A-Device when we
acted as a B-Device, now it represents an internal VBUS source.
Accordingly, we no longer set the current limit or enable/disable the
bus from nop_gpio_vbus_thread. Because this supply was never initialized
before the previous commit, there should be no change in behavior.
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---
(no changes since v1)
drivers/usb/phy/phy-generic.c | 45 +++++++++++++----------------------
1 file changed, 17 insertions(+), 28 deletions(-)
diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
index 34b9f8140187..2c2553bc9b54 100644
--- a/drivers/usb/phy/phy-generic.c
+++ b/drivers/usb/phy/phy-generic.c
@@ -68,33 +68,26 @@ static void nop_reset(struct usb_phy_generic *nop)
}
/* interface to regulator framework */
-static void nop_set_vbus_draw(struct usb_phy_generic *nop, unsigned mA)
+static int nop_set_vbus(struct usb_otg *otg, bool enable)
{
- struct regulator *vbus_draw = nop->vbus_draw;
- int enabled;
- int ret;
+ int ret = 0;
+ struct usb_phy_generic *nop = dev_get_drvdata(otg->usb_phy->dev);
- if (!vbus_draw)
- return;
+ if (!nop->vbus_draw)
+ return 0;
- enabled = nop->vbus_draw_enabled;
- if (mA) {
- regulator_set_current_limit(vbus_draw, 0, 1000 * mA);
- if (!enabled) {
- ret = regulator_enable(vbus_draw);
- if (ret < 0)
- return;
- nop->vbus_draw_enabled = 1;
- }
- } else {
- if (enabled) {
- ret = regulator_disable(vbus_draw);
- if (ret < 0)
- return;
- nop->vbus_draw_enabled = 0;
- }
+ if (enable && !nop->vbus_draw_enabled) {
+ ret = regulator_enable(nop->vbus_draw);
+ if (ret)
+ nop->vbus_draw_enabled = false;
+ else
+ nop->vbus_draw_enabled = true;
+
+ } else if (!enable && nop->vbus_draw_enabled) {
+ ret = regulator_disable(nop->vbus_draw);
+ nop->vbus_draw_enabled = false;
}
- nop->mA = mA;
+ return ret;
}
@@ -114,14 +107,9 @@ static irqreturn_t nop_gpio_vbus_thread(int irq, void *data)
otg->state = OTG_STATE_B_PERIPHERAL;
nop->phy.last_event = status;
- /* drawing a "unit load" is *always* OK, except for OTG */
- nop_set_vbus_draw(nop, 100);
-
atomic_notifier_call_chain(&nop->phy.notifier, status,
otg->gadget);
} else {
- nop_set_vbus_draw(nop, 0);
-
status = USB_EVENT_NONE;
otg->state = OTG_STATE_B_IDLE;
nop->phy.last_event = status;
@@ -285,6 +273,7 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop)
nop->phy.otg->usb_phy = &nop->phy;
nop->phy.otg->set_host = nop_set_host;
nop->phy.otg->set_peripheral = nop_set_peripheral;
+ nop->phy.otg->set_vbus = nop_set_vbus;
return 0;
}
--
2.35.1.1320.gc452695387.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 4/4] usb: phy: generic: Disable vbus on removal
2022-04-25 17:14 [PATCH v2 0/4] usb: phy: generic: Support enabling/disabling VBUS Sean Anderson
` (2 preceding siblings ...)
2022-04-25 17:14 ` [PATCH v2 3/4] usb: phy: generic: Implement otg->set_vbus Sean Anderson
@ 2022-04-25 17:14 ` Sean Anderson
3 siblings, 0 replies; 6+ messages in thread
From: Sean Anderson @ 2022-04-25 17:14 UTC (permalink / raw)
To: Greg Kroah-Hartman, linux-usb
Cc: Mike Looijmans, Linus Walleij, Jules Maselbas, Felipe Balbi,
Jonathan Hunter, linux-kernel, Robert Jarzmik, Sean Anderson
If we enabled vbus, we need to balance that with a disable.
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---
(no changes since v1)
drivers/usb/phy/phy-generic.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
index 2c2553bc9b54..9fc3312d614a 100644
--- a/drivers/usb/phy/phy-generic.c
+++ b/drivers/usb/phy/phy-generic.c
@@ -328,6 +328,9 @@ static int usb_phy_generic_remove(struct platform_device *pdev)
usb_remove_phy(&nop->phy);
+ if (nop->vbus_draw && nop->vbus_draw_enabled)
+ regulator_disable(nop->vbus_draw);
+
return 0;
}
--
2.35.1.1320.gc452695387.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread