* [PATCH 1/2] usb: chipidea: Add DT vbus-supply parsing @ 2014-07-28 20:23 Markus Pargmann 2014-07-28 20:23 ` [PATCH 2/2] usb: imx-usb-misc: Use reasonable defaults to setup the ports Markus Pargmann 2014-07-28 20:45 ` [PATCH 1/2] usb: chipidea: Add DT vbus-supply parsing Sebastian Hesselbarth 0 siblings, 2 replies; 4+ messages in thread From: Markus Pargmann @ 2014-07-28 20:23 UTC (permalink / raw) To: barebox Add some code to parse and enable vbus supply when probing. Signed-off-by: Markus Pargmann <mpa@pengutronix.de> --- drivers/usb/imx/chipidea-imx.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c index 9b6829b8f59f..a4cf4a1a5f3d 100644 --- a/drivers/usb/imx/chipidea-imx.c +++ b/drivers/usb/imx/chipidea-imx.c @@ -15,6 +15,7 @@ #include <common.h> #include <init.h> #include <io.h> +#include <linux/err.h> #include <of.h> #include <errno.h> #include <driver.h> @@ -23,6 +24,7 @@ #include <usb/chipidea-imx.h> #include <usb/ulpi.h> #include <usb/fsl_usb2.h> +#include <regulator.h> #define MXC_EHCI_PORTSC_MASK ((0xf << 28) | (1 << 25)) @@ -187,6 +189,16 @@ static int imx_chipidea_probe(struct device_d *dev) ret = -ENODEV; } + if (ci->mode == IMX_USB_MODE_HOST) { + struct regulator *vbus = regulator_get(dev, "vbus"); + if (!IS_ERR(vbus)) { + regulator_enable(vbus); + } else { + dev_err(dev, "Failed to get vbus regulator %ld\n", PTR_ERR(vbus)); + ret = PTR_ERR(vbus); + } + } + return ret; }; -- 2.0.1 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] usb: imx-usb-misc: Use reasonable defaults to setup the ports 2014-07-28 20:23 [PATCH 1/2] usb: chipidea: Add DT vbus-supply parsing Markus Pargmann @ 2014-07-28 20:23 ` Markus Pargmann 2014-07-28 20:45 ` [PATCH 1/2] usb: chipidea: Add DT vbus-supply parsing Sebastian Hesselbarth 1 sibling, 0 replies; 4+ messages in thread From: Markus Pargmann @ 2014-07-28 20:23 UTC (permalink / raw) To: barebox This code is partly backported from the linux kernel which also uses some defaults to setup the USB ports. Signed-off-by: Markus Pargmann <mpa@pengutronix.de> --- drivers/usb/imx/imx-usb-misc.c | 44 +++++------------------------------------- 1 file changed, 5 insertions(+), 39 deletions(-) diff --git a/drivers/usb/imx/imx-usb-misc.c b/drivers/usb/imx/imx-usb-misc.c index ed44d78b0f7c..0a3d4ac6badb 100644 --- a/drivers/usb/imx/imx-usb-misc.c +++ b/drivers/usb/imx/imx-usb-misc.c @@ -51,47 +51,13 @@ static __maybe_unused int mx25_initialize_usb_hw(void __iomem *base, int port, u switch (port) { case 0: /* OTG port */ - v &= ~(MX25_OTG_SIC_MASK | MX25_OTG_PM_BIT | MX25_OTG_PP_BIT | - MX25_OTG_OCPOL_BIT); - v |= (flags & MXC_EHCI_INTERFACE_MASK) << MX25_OTG_SIC_SHIFT; - - if (!(flags & MXC_EHCI_POWER_PINS_ENABLED)) - v |= MX25_OTG_PM_BIT; - - if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH) - v |= MX25_OTG_PP_BIT; - - if (!(flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)) - v |= MX25_OTG_OCPOL_BIT; - + v &= ~(MX25_OTG_SIC_MASK | MX25_OTG_PP_BIT); + v |= (MX25_OTG_PM_BIT | MX25_OTG_OCPOL_BIT); break; case 1: /* H1 port */ - v &= ~(MX25_H1_SIC_MASK | MX25_H1_PM_BIT | MX25_H1_PP_BIT | - MX25_H1_OCPOL_BIT | MX25_H1_TLL_BIT | MX25_H1_USBTE_BIT | - MX25_H1_IPPUE_DOWN_BIT | MX25_H1_IPPUE_UP_BIT); - v |= (flags & MXC_EHCI_INTERFACE_MASK) << MX25_H1_SIC_SHIFT; - - if (!(flags & MXC_EHCI_POWER_PINS_ENABLED)) - v |= MX25_H1_PM_BIT; - - if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH) - v |= MX25_H1_PP_BIT; - - if (!(flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)) - v |= MX25_H1_OCPOL_BIT; - - if (!(flags & MXC_EHCI_TLL_ENABLED)) - v |= MX25_H1_TLL_BIT; - - if (flags & MXC_EHCI_INTERNAL_PHY) - v |= MX25_H1_USBTE_BIT; - - if (flags & MXC_EHCI_IPPUE_DOWN) - v |= MX25_H1_IPPUE_DOWN_BIT; - - if (flags & MXC_EHCI_IPPUE_UP) - v |= MX25_H1_IPPUE_UP_BIT; - + v &= ~(MX25_H1_SIC_MASK | MX25_H1_PP_BIT | MX25_H1_IPPUE_UP_BIT); + v |= (MX25_H1_PM_BIT | MX25_H1_OCPOL_BIT | MX25_H1_TLL_BIT | + MX25_H1_USBTE_BIT | MX25_H1_IPPUE_DOWN_BIT); break; default: return -EINVAL; -- 2.0.1 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] usb: chipidea: Add DT vbus-supply parsing 2014-07-28 20:23 [PATCH 1/2] usb: chipidea: Add DT vbus-supply parsing Markus Pargmann 2014-07-28 20:23 ` [PATCH 2/2] usb: imx-usb-misc: Use reasonable defaults to setup the ports Markus Pargmann @ 2014-07-28 20:45 ` Sebastian Hesselbarth 2014-07-28 20:54 ` Markus Pargmann 1 sibling, 1 reply; 4+ messages in thread From: Sebastian Hesselbarth @ 2014-07-28 20:45 UTC (permalink / raw) To: Markus Pargmann, barebox On 07/28/2014 10:23 PM, Markus Pargmann wrote: > Add some code to parse and enable vbus supply when probing. > > Signed-off-by: Markus Pargmann <mpa@pengutronix.de> > --- > drivers/usb/imx/chipidea-imx.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c > index 9b6829b8f59f..a4cf4a1a5f3d 100644 > --- a/drivers/usb/imx/chipidea-imx.c > +++ b/drivers/usb/imx/chipidea-imx.c > @@ -15,6 +15,7 @@ > #include <common.h> > #include <init.h> > #include <io.h> > +#include <linux/err.h> > #include <of.h> > #include <errno.h> > #include <driver.h> > @@ -23,6 +24,7 @@ > #include <usb/chipidea-imx.h> > #include <usb/ulpi.h> > #include <usb/fsl_usb2.h> > +#include <regulator.h> > > #define MXC_EHCI_PORTSC_MASK ((0xf << 28) | (1 << 25)) > > @@ -187,6 +189,16 @@ static int imx_chipidea_probe(struct device_d *dev) > ret = -ENODEV; > } > > + if (ci->mode == IMX_USB_MODE_HOST) { > + struct regulator *vbus = regulator_get(dev, "vbus"); > + if (!IS_ERR(vbus)) { > + regulator_enable(vbus); > + } else { > + dev_err(dev, "Failed to get vbus regulator %ld\n", PTR_ERR(vbus)); > + ret = PTR_ERR(vbus); > + } regulator_get should return a NULL pointer if there is no regulator for "vbus". The NULL regulator is a valid (dummy) regulator that can be used as if there was a real one. That basically means, you should check for an error and always use regulator_enable otherwise: struct regulator *vbus = regulator_get(dev, "vbus"); if (IS_ERR(vbus)) { dev_err(dev, "Failed to get vbus regulator %ld\n", PTR_ERR(vbus)); return PTR_ERR(vbus); } regulator_enable(vbus); But even more important: You should also check for a regulator on peripheral/otg mode. That's the cases where you can actually break things when you don't disable the regulator. Sebastian > + } > + > return ret; > }; > > _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] usb: chipidea: Add DT vbus-supply parsing 2014-07-28 20:45 ` [PATCH 1/2] usb: chipidea: Add DT vbus-supply parsing Sebastian Hesselbarth @ 2014-07-28 20:54 ` Markus Pargmann 0 siblings, 0 replies; 4+ messages in thread From: Markus Pargmann @ 2014-07-28 20:54 UTC (permalink / raw) To: Sebastian Hesselbarth; +Cc: barebox [-- Attachment #1.1: Type: text/plain, Size: 2599 bytes --] On Mon, Jul 28, 2014 at 10:45:57PM +0200, Sebastian Hesselbarth wrote: > On 07/28/2014 10:23 PM, Markus Pargmann wrote: > > Add some code to parse and enable vbus supply when probing. > > > > Signed-off-by: Markus Pargmann <mpa@pengutronix.de> > > --- > > drivers/usb/imx/chipidea-imx.c | 12 ++++++++++++ > > 1 file changed, 12 insertions(+) > > > > diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c > > index 9b6829b8f59f..a4cf4a1a5f3d 100644 > > --- a/drivers/usb/imx/chipidea-imx.c > > +++ b/drivers/usb/imx/chipidea-imx.c > > @@ -15,6 +15,7 @@ > > #include <common.h> > > #include <init.h> > > #include <io.h> > > +#include <linux/err.h> > > #include <of.h> > > #include <errno.h> > > #include <driver.h> > > @@ -23,6 +24,7 @@ > > #include <usb/chipidea-imx.h> > > #include <usb/ulpi.h> > > #include <usb/fsl_usb2.h> > > +#include <regulator.h> > > > > #define MXC_EHCI_PORTSC_MASK ((0xf << 28) | (1 << 25)) > > > > @@ -187,6 +189,16 @@ static int imx_chipidea_probe(struct device_d *dev) > > ret = -ENODEV; > > } > > > > + if (ci->mode == IMX_USB_MODE_HOST) { > > + struct regulator *vbus = regulator_get(dev, "vbus"); > > + if (!IS_ERR(vbus)) { > > + regulator_enable(vbus); > > + } else { > > + dev_err(dev, "Failed to get vbus regulator %ld\n", PTR_ERR(vbus)); > > + ret = PTR_ERR(vbus); > > + } > > regulator_get should return a NULL pointer if there is no regulator for > "vbus". The NULL regulator is a valid (dummy) regulator that can be used > as if there was a real one. > > That basically means, you should check for an error and always use > regulator_enable otherwise: > > struct regulator *vbus = regulator_get(dev, "vbus"); > if (IS_ERR(vbus)) { > dev_err(dev, "Failed to get vbus regulator %ld\n", PTR_ERR(vbus)); > return PTR_ERR(vbus); > } > > regulator_enable(vbus); Thanks, will change that. > > But even more important: You should also check for a regulator on > peripheral/otg mode. That's the cases where you can actually break > things when you don't disable the regulator. Oh right, I didn't thought about that. I will change the code so that it is either enabled or disabled, depending on the mode. Thanks, Markus -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | [-- Attachment #1.2: Digital signature --] [-- Type: application/pgp-signature, Size: 836 bytes --] [-- Attachment #2: Type: text/plain, Size: 149 bytes --] _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-07-28 20:54 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-07-28 20:23 [PATCH 1/2] usb: chipidea: Add DT vbus-supply parsing Markus Pargmann 2014-07-28 20:23 ` [PATCH 2/2] usb: imx-usb-misc: Use reasonable defaults to setup the ports Markus Pargmann 2014-07-28 20:45 ` [PATCH 1/2] usb: chipidea: Add DT vbus-supply parsing Sebastian Hesselbarth 2014-07-28 20:54 ` Markus Pargmann
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox