[3/5] usb: chipidea: tegra: add dr_mode checking to tegra-udc
diff mbox series

Message ID 20191002014153.29831-4-pgwipeout@gmail.com
State New
Headers show
Series
  • enable tegra-udc host mode
Related show

Commit Message

Peter Geis Oct. 2, 2019, 1:41 a.m. UTC
As the tegra-udc driver does not yet support all modes, add dr_mode
checking capability.
Warn about invalid configurations and explicitly assign dr_mode before
handing off to the chipidea core driver.

Signed-off-by: Peter Geis <pgwipeout@gmail.com>
---
 drivers/usb/chipidea/ci_hdrc_tegra.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

Comments

Thierry Reding Oct. 2, 2019, 11:09 a.m. UTC | #1
On Tue, Oct 01, 2019 at 09:41:51PM -0400, Peter Geis wrote:
> As the tegra-udc driver does not yet support all modes, add dr_mode
> checking capability.
> Warn about invalid configurations and explicitly assign dr_mode before
> handing off to the chipidea core driver.
> 
> Signed-off-by: Peter Geis <pgwipeout@gmail.com>
> ---
>  drivers/usb/chipidea/ci_hdrc_tegra.c | 24 +++++++++++++++++++++++-
>  1 file changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/chipidea/ci_hdrc_tegra.c b/drivers/usb/chipidea/ci_hdrc_tegra.c
> index 0c9911d44ee5..29415c3a2f48 100644
> --- a/drivers/usb/chipidea/ci_hdrc_tegra.c
> +++ b/drivers/usb/chipidea/ci_hdrc_tegra.c
> @@ -25,7 +25,7 @@ struct tegra_udc_soc_info {
>  };
>  
>  static const struct tegra_udc_soc_info tegra_udc_soc_info = {
> -	.flags = CI_HDRC_REQUIRES_ALIGNED_DMA,
> +	.flags = CI_HDRC_REQUIRES_ALIGNED_DMA | CI_HDRC_TEGRA_HOST,

This seems to be not at all related to the rest of this patch. Also, I
think this patch makes sense standalone, so it may be worth sending it
out separately, perhaps marked for integration into stable branches if
you think it worth it.

Thierry

>  };
>  
>  static const struct of_device_id tegra_udc_of_match[] = {
> @@ -63,6 +63,28 @@ static int tegra_udc_probe(struct platform_device *pdev)
>  		return -EINVAL;
>  	}
>  
> +	/* check the dual mode and warn about bad configurations */
> +	switch (usb_get_dr_mode(&pdev->dev)) {
> +	case USB_DR_MODE_HOST:
> +		dev_dbg(&pdev->dev, "dr_mode is set to host\n");
> +		udc->data.dr_mode = USB_DR_MODE_HOST;
> +		break;
> +
> +	case USB_DR_MODE_UNKNOWN:
> +		dev_warn(&pdev->dev, "dr_mode is unset or unknown, setting host mode\n");
> +		udc->data.dr_mode = USB_DR_MODE_HOST;
> +		break;
> +
> +	case USB_DR_MODE_PERIPHERAL:
> +		dev_dbg(&pdev->dev, "dr_mode is set to peripheral\n");
> +		udc->data.dr_mode = USB_DR_MODE_PERIPHERAL;
> +		break;
> +
> +	case USB_DR_MODE_OTG:
> +		dev_err(&pdev->dev, "dr_mode is otg, tegra-udc does not support otg at this time\n");
> +		return -EINVAL;
> +	}
> +
>  	udc->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0);
>  	if (IS_ERR(udc->phy)) {
>  		err = PTR_ERR(udc->phy);
> -- 
> 2.17.1
>
Peter Geis Oct. 2, 2019, 12:03 p.m. UTC | #2
On Wed, Oct 2, 2019 at 7:09 AM Thierry Reding <thierry.reding@gmail.com> wrote:
>
> On Tue, Oct 01, 2019 at 09:41:51PM -0400, Peter Geis wrote:
> > As the tegra-udc driver does not yet support all modes, add dr_mode
> > checking capability.
> > Warn about invalid configurations and explicitly assign dr_mode before
> > handing off to the chipidea core driver.
> >
> > Signed-off-by: Peter Geis <pgwipeout@gmail.com>
> > ---
> >  drivers/usb/chipidea/ci_hdrc_tegra.c | 24 +++++++++++++++++++++++-
> >  1 file changed, 23 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/usb/chipidea/ci_hdrc_tegra.c b/drivers/usb/chipidea/ci_hdrc_tegra.c
> > index 0c9911d44ee5..29415c3a2f48 100644
> > --- a/drivers/usb/chipidea/ci_hdrc_tegra.c
> > +++ b/drivers/usb/chipidea/ci_hdrc_tegra.c
> > @@ -25,7 +25,7 @@ struct tegra_udc_soc_info {
> >  };
> >
> >  static const struct tegra_udc_soc_info tegra_udc_soc_info = {
> > -     .flags = CI_HDRC_REQUIRES_ALIGNED_DMA,
> > +     .flags = CI_HDRC_REQUIRES_ALIGNED_DMA | CI_HDRC_TEGRA_HOST,
>
> This seems to be not at all related to the rest of this patch. Also, I
> think this patch makes sense standalone, so it may be worth sending it
> out separately, perhaps marked for integration into stable branches if
> you think it worth it.
>
> Thierry

Considering I wrote this because host mode caused me issues, I'll
split this out as a separate patch.

>
> >  };
> >
> >  static const struct of_device_id tegra_udc_of_match[] = {
> > @@ -63,6 +63,28 @@ static int tegra_udc_probe(struct platform_device *pdev)
> >               return -EINVAL;
> >       }
> >
> > +     /* check the dual mode and warn about bad configurations */
> > +     switch (usb_get_dr_mode(&pdev->dev)) {
> > +     case USB_DR_MODE_HOST:
> > +             dev_dbg(&pdev->dev, "dr_mode is set to host\n");
> > +             udc->data.dr_mode = USB_DR_MODE_HOST;
> > +             break;
> > +
> > +     case USB_DR_MODE_UNKNOWN:
> > +             dev_warn(&pdev->dev, "dr_mode is unset or unknown, setting host mode\n");
> > +             udc->data.dr_mode = USB_DR_MODE_HOST;
> > +             break;
> > +
> > +     case USB_DR_MODE_PERIPHERAL:
> > +             dev_dbg(&pdev->dev, "dr_mode is set to peripheral\n");
> > +             udc->data.dr_mode = USB_DR_MODE_PERIPHERAL;
> > +             break;
> > +
> > +     case USB_DR_MODE_OTG:
> > +             dev_err(&pdev->dev, "dr_mode is otg, tegra-udc does not support otg at this time\n");
> > +             return -EINVAL;
> > +     }
> > +
> >       udc->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0);
> >       if (IS_ERR(udc->phy)) {
> >               err = PTR_ERR(udc->phy);
> > --
> > 2.17.1
> >

Patch
diff mbox series

diff --git a/drivers/usb/chipidea/ci_hdrc_tegra.c b/drivers/usb/chipidea/ci_hdrc_tegra.c
index 0c9911d44ee5..29415c3a2f48 100644
--- a/drivers/usb/chipidea/ci_hdrc_tegra.c
+++ b/drivers/usb/chipidea/ci_hdrc_tegra.c
@@ -25,7 +25,7 @@  struct tegra_udc_soc_info {
 };
 
 static const struct tegra_udc_soc_info tegra_udc_soc_info = {
-	.flags = CI_HDRC_REQUIRES_ALIGNED_DMA,
+	.flags = CI_HDRC_REQUIRES_ALIGNED_DMA | CI_HDRC_TEGRA_HOST,
 };
 
 static const struct of_device_id tegra_udc_of_match[] = {
@@ -63,6 +63,28 @@  static int tegra_udc_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
+	/* check the dual mode and warn about bad configurations */
+	switch (usb_get_dr_mode(&pdev->dev)) {
+	case USB_DR_MODE_HOST:
+		dev_dbg(&pdev->dev, "dr_mode is set to host\n");
+		udc->data.dr_mode = USB_DR_MODE_HOST;
+		break;
+
+	case USB_DR_MODE_UNKNOWN:
+		dev_warn(&pdev->dev, "dr_mode is unset or unknown, setting host mode\n");
+		udc->data.dr_mode = USB_DR_MODE_HOST;
+		break;
+
+	case USB_DR_MODE_PERIPHERAL:
+		dev_dbg(&pdev->dev, "dr_mode is set to peripheral\n");
+		udc->data.dr_mode = USB_DR_MODE_PERIPHERAL;
+		break;
+
+	case USB_DR_MODE_OTG:
+		dev_err(&pdev->dev, "dr_mode is otg, tegra-udc does not support otg at this time\n");
+		return -EINVAL;
+	}
+
 	udc->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0);
 	if (IS_ERR(udc->phy)) {
 		err = PTR_ERR(udc->phy);