From: Vincent Whitchurch <vincent.whitchurch@axis.com>
To: Mike Looijmans <mike.looijmans@topic.nl>
Cc: <linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<balbi@kernel.org>, <gregkh@linuxfoundation.org>,
<lgirdwood@gmail.com>, <broonie@kernel.org>
Subject: Re: [PATCH v3] usb: dwc3: Add support for VBUS power control
Date: Thu, 23 Jul 2020 09:56:14 +0200 [thread overview]
Message-ID: <20200723075612.tn5dbkhes2chohwh@axis.com> (raw)
In-Reply-To: <20200619142512.19824-1-mike.looijmans@topic.nl>
On Fri, Jun 19, 2020 at 04:25:12PM +0200, Mike Looijmans wrote:
> +void dwc3_set_vbus(struct dwc3 *dwc, bool enable)
> +{
> + int ret;
> +
> + if (enable != dwc->vbus_reg_enabled) {
> + if (enable)
> + ret = regulator_enable(dwc->vbus_reg);
> + else
> + ret = regulator_disable(dwc->vbus_reg);
dwc->vbus_reg is set to NULL when the regulator is not present. These
regulator_* functions expect a non-NULL pointer so a NULL check is
required before calling them.
> + if (!ret)
> + dwc->vbus_reg_enabled = enable;
> + }
> +
> + if (dwc->usb2_phy)
> + otg_set_vbus(dwc->usb2_phy->otg, enable);
> +}
> +
> static void __dwc3_set_mode(struct work_struct *work)
> {
> struct dwc3 *dwc = work_to_dwc(work);
> @@ -164,8 +182,7 @@ static void __dwc3_set_mode(struct work_struct *work)
> if (ret) {
> dev_err(dwc->dev, "failed to initialize host\n");
> } else {
> - if (dwc->usb2_phy)
> - otg_set_vbus(dwc->usb2_phy->otg, true);
> + dwc3_set_vbus(dwc, true);
> phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST);
> phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST);
> }
> @@ -173,8 +190,7 @@ static void __dwc3_set_mode(struct work_struct *work)
> case DWC3_GCTL_PRTCAP_DEVICE:
> dwc3_event_buffers_setup(dwc);
>
> - if (dwc->usb2_phy)
> - otg_set_vbus(dwc->usb2_phy->otg, false);
> + dwc3_set_vbus(dwc, false);
> phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE);
> phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE);
>
> @@ -1183,8 +1199,7 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
> case USB_DR_MODE_PERIPHERAL:
> dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
>
> - if (dwc->usb2_phy)
> - otg_set_vbus(dwc->usb2_phy->otg, false);
> + dwc3_set_vbus(dwc, false);
> phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_DEVICE);
> phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE);
>
> @@ -1198,8 +1213,7 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
> case USB_DR_MODE_HOST:
> dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
>
> - if (dwc->usb2_phy)
> - otg_set_vbus(dwc->usb2_phy->otg, true);
> + dwc3_set_vbus(dwc, true);
> phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST);
> phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST);
>
> @@ -1470,6 +1484,14 @@ static int dwc3_probe(struct platform_device *pdev)
>
> dwc3_get_properties(dwc);
>
> + dwc->vbus_reg = devm_regulator_get_optional(dev, "vbus");
> + if (IS_ERR(dwc->vbus_reg)) {
> + if (PTR_ERR(dwc->vbus_reg) == -EPROBE_DEFER)
> + return -EPROBE_DEFER;
Some drivers seem to do it this way, but I think it would be more
correct to return all errors that aren't ENODEV, like
drivers/gpu/drm/exynos/exynos_hdmi.c does. That way you would allow the
regulator to not be present, but you also wouldn't silently ignore other
errors such as ENOMEM.
> +
> + dwc->vbus_reg = NULL;
> + }
> +
next prev parent reply other threads:[~2020-07-23 7:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-19 14:25 [PATCH v3] usb: dwc3: Add support for VBUS power control Mike Looijmans
2020-07-23 7:56 ` Vincent Whitchurch [this message]
[not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.2698920d-90ba-4c46-abda-83e18e2093c8@emailsignatures365.codetwo.com>
2020-07-23 11:05 ` Mark Brown
2020-07-26 7:10 ` Mike Looijmans
2020-07-27 10:23 ` Mark Brown
2020-07-27 11:50 ` Mike Looijmans
2020-07-27 11:53 ` Mark Brown
2020-07-28 7:29 ` Mike Looijmans
2020-09-07 7:44 ` Felipe Balbi
2020-09-07 7:50 ` Mike Looijmans
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200723075612.tn5dbkhes2chohwh@axis.com \
--to=vincent.whitchurch@axis.com \
--cc=balbi@kernel.org \
--cc=broonie@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mike.looijmans@topic.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox