2022-01-14 22:55:38

by Sean Anderson

[permalink] [raw]
Subject: [PATCH 0/4] usb: phy: generic: Support enabling/disabling VBUS

The generic USB phy has had VBUS-related code for a long time, but it
has always been broken, since the regulator was never gotten from the
device tree. However, the support itself seems not very useful, since
e.g. usb_phy_vbus_on/off has no users and usb_phy_set_power is only
used by gadgets to make sure they don't draw too much current. Instead,
use the VBUS regulator to implement otg_set_vbus, which is called from
several drivers. This results in a change in semantics of VBUS, but
since support was always broken I don't think this will have any affect.


Sean Anderson (4):
dt-bindings: usb: usb-nop-xceiv: Repurpose vbus-regulator
usb: phy: generic: Get the vbus supply
usb: phy: generic: Implement otg->set_vbus
usb: phy: generic: Disable vbus on removal

.../bindings/usb/usb-nop-xceiv.yaml | 8 +--
drivers/usb/phy/phy-generic.c | 55 +++++++++----------
2 files changed, 31 insertions(+), 32 deletions(-)

--
2.25.1


2022-01-14 22:56:10

by Sean Anderson

[permalink] [raw]
Subject: [PATCH 3/4] usb: phy: generic: Implement otg->set_vbus

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 <[email protected]>
---

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.25.1

2022-01-14 22:56:17

by Sean Anderson

[permalink] [raw]
Subject: [PATCH 4/4] usb: phy: generic: Disable vbus on removal

If we enabled vbus, we need to balance that with a disable.

Signed-off-by: Sean Anderson <[email protected]>
---

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.25.1

2022-01-14 22:56:39

by Sean Anderson

[permalink] [raw]
Subject: [PATCH 1/4] dt-bindings: usb: usb-nop-xceiv: Repurpose vbus-regulator

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 <[email protected]>
---

Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml b/Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml
index 2824c17285ee..a79459bb5a4c 100644
--- a/Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml
+++ b/Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml
@@ -34,9 +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.
+ vbus-supply:
+ description: regulator supplying VBUS. It will be enabled and disabled
+ dynamically in OTG mode.
$ref: /schemas/types.yaml#/definitions/phandle

required:
@@ -57,7 +57,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.25.1

2022-01-14 22:56:47

by Sean Anderson

[permalink] [raw]
Subject: [PATCH 2/4] usb: phy: generic: Get the vbus supply

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 <[email protected]>
---

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.25.1

2022-01-16 14:56:46

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH 1/4] dt-bindings: usb: usb-nop-xceiv: Repurpose vbus-regulator

On Fri, 14 Jan 2022 12:09:38 -0500, Sean Anderson 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 <[email protected]>
> ---
>
> Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:
./Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml:37:15: [error] empty value in block mapping (empty-values)
./Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml:40:9: [error] syntax error: mapping values are not allowed here (syntax)

dtschema/dtc warnings/errors:
make[1]: *** Deleting file 'Documentation/devicetree/bindings/usb/usb-nop-xceiv.example.dts'
Traceback (most recent call last):
File "/usr/local/bin/dt-extract-example", line 46, in <module>
binding = yaml.load(open(args.yamlfile, encoding='utf-8').read())
File "/usr/local/lib/python3.8/dist-packages/ruamel/yaml/main.py", line 434, in load
return constructor.get_single_data()
File "/usr/local/lib/python3.8/dist-packages/ruamel/yaml/constructor.py", line 119, in get_single_data
node = self.composer.get_single_node()
File "_ruamel_yaml.pyx", line 706, in _ruamel_yaml.CParser.get_single_node
File "_ruamel_yaml.pyx", line 724, in _ruamel_yaml.CParser._compose_document
File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 891, in _ruamel_yaml.CParser._compose_mapping_node
File "_ruamel_yaml.pyx", line 904, in _ruamel_yaml.CParser._parse_next_event
ruamel.yaml.scanner.ScannerError: mapping values are not allowed in this context
in "<unicode string>", line 40, column 9
make[1]: *** [Documentation/devicetree/bindings/Makefile:25: Documentation/devicetree/bindings/usb/usb-nop-xceiv.example.dts] Error 1
make[1]: *** Waiting for unfinished jobs....
./Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml: mapping values are not allowed in this context
in "<unicode string>", line 40, column 9
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml: ignoring, error parsing file
make: *** [Makefile:1413: dt_binding_check] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/1580217

This check can fail if there are any dependencies. The base for a patch
series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit.

2022-04-06 09:31:37

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 0/4] usb: phy: generic: Support enabling/disabling VBUS

On Tue, Apr 05, 2022 at 10:51:34AM -0400, Sean Anderson wrote:
>
>
> On 1/14/22 12:09 PM, Sean Anderson wrote:
> > The generic USB phy has had VBUS-related code for a long time, but it
> > has always been broken, since the regulator was never gotten from the
> > device tree. However, the support itself seems not very useful, since
> > e.g. usb_phy_vbus_on/off has no users and usb_phy_set_power is only
> > used by gadgets to make sure they don't draw too much current. Instead,
> > use the VBUS regulator to implement otg_set_vbus, which is called from
> > several drivers. This results in a change in semantics of VBUS, but
> > since support was always broken I don't think this will have any affect.
> >
> >
> > Sean Anderson (4):
> > dt-bindings: usb: usb-nop-xceiv: Repurpose vbus-regulator
> > usb: phy: generic: Get the vbus supply
> > usb: phy: generic: Implement otg->set_vbus
> > usb: phy: generic: Disable vbus on removal
> >
> > .../bindings/usb/usb-nop-xceiv.yaml | 8 +--
> > drivers/usb/phy/phy-generic.c | 55 +++++++++----------
> > 2 files changed, 31 insertions(+), 32 deletions(-)
> >
>
> ping?
>
> When this was submitted I got an email saying that the merge window was
> closed... but I think it has opened and closed again during the
> intervening time.

It opened yesterday. Please give us a chance to catch up.

While that happens, please take the time to review other changes on the
mailing lists, we can always use the help.

thanks,

greg k-h

2022-04-06 12:06:33

by Sean Anderson

[permalink] [raw]
Subject: Re: [PATCH 0/4] usb: phy: generic: Support enabling/disabling VBUS



On 1/14/22 12:09 PM, Sean Anderson wrote:
> The generic USB phy has had VBUS-related code for a long time, but it
> has always been broken, since the regulator was never gotten from the
> device tree. However, the support itself seems not very useful, since
> e.g. usb_phy_vbus_on/off has no users and usb_phy_set_power is only
> used by gadgets to make sure they don't draw too much current. Instead,
> use the VBUS regulator to implement otg_set_vbus, which is called from
> several drivers. This results in a change in semantics of VBUS, but
> since support was always broken I don't think this will have any affect.
>
>
> Sean Anderson (4):
> dt-bindings: usb: usb-nop-xceiv: Repurpose vbus-regulator
> usb: phy: generic: Get the vbus supply
> usb: phy: generic: Implement otg->set_vbus
> usb: phy: generic: Disable vbus on removal
>
> .../bindings/usb/usb-nop-xceiv.yaml | 8 +--
> drivers/usb/phy/phy-generic.c | 55 +++++++++----------
> 2 files changed, 31 insertions(+), 32 deletions(-)
>

ping?

When this was submitted I got an email saying that the merge window was
closed... but I think it has opened and closed again during the
intervening time.

--Sean

2022-04-06 13:20:19

by Sean Anderson

[permalink] [raw]
Subject: Re: [PATCH 0/4] usb: phy: generic: Support enabling/disabling VBUS



On 4/5/22 11:02 AM, Greg Kroah-Hartman wrote:
> On Tue, Apr 05, 2022 at 10:51:34AM -0400, Sean Anderson wrote:
>>
>>
>> On 1/14/22 12:09 PM, Sean Anderson wrote:
>> > The generic USB phy has had VBUS-related code for a long time, but it
>> > has always been broken, since the regulator was never gotten from the
>> > device tree. However, the support itself seems not very useful, since
>> > e.g. usb_phy_vbus_on/off has no users and usb_phy_set_power is only
>> > used by gadgets to make sure they don't draw too much current. Instead,
>> > use the VBUS regulator to implement otg_set_vbus, which is called from
>> > several drivers. This results in a change in semantics of VBUS, but
>> > since support was always broken I don't think this will have any affect.
>> >
>> >
>> > Sean Anderson (4):
>> > dt-bindings: usb: usb-nop-xceiv: Repurpose vbus-regulator
>> > usb: phy: generic: Get the vbus supply
>> > usb: phy: generic: Implement otg->set_vbus
>> > usb: phy: generic: Disable vbus on removal
>> >
>> > .../bindings/usb/usb-nop-xceiv.yaml | 8 +--
>> > drivers/usb/phy/phy-generic.c | 55 +++++++++----------
>> > 2 files changed, 31 insertions(+), 32 deletions(-)
>> >
>>
>> ping?
>>
>> When this was submitted I got an email saying that the merge window was
>> closed... but I think it has opened and closed again during the
>> intervening time.
>
> It opened yesterday. Please give us a chance to catch up.

Ah, sorry. I thought this series had just gotten lost.

> While that happens, please take the time to review other changes on the
> mailing lists, we can always use the help.

Noted.

--Sean