diff mbox

[2/2] usb: phy: msm: fix connect/disconnect bug for dragonboard OTG port

Message ID 1447202811-3429-2-git-send-email-tim.bird@sonymobile.com (mailing list archive)
State Not Applicable, archived
Delegated to: Andy Gross
Headers show

Commit Message

Bird, Tim Nov. 11, 2015, 12:46 a.m. UTC
This fixes a bug where if you disconnect and re-connect the USB cable,
the gadget driver stops working.

Add support for async_irq to wake up driver from low power mode.
Without this, the power management code never calls resume.
Also, have the phy driver kick the gadget driver (chipidea otg)
by having the chipidea driver register with it, for vbus connect
notifications.

Signed-off-by: Tim Bird <tim.bird@sonymobile.com>
---
 drivers/usb/chipidea/udc.c    |  6 ++++++
 drivers/usb/phy/phy-msm-usb.c | 16 ++++++++++++++++
 include/linux/usb/msm_hsusb.h |  1 +
 3 files changed, 23 insertions(+)

Comments

Peter Chen Nov. 11, 2015, 3:14 a.m. UTC | #1
On Tue, Nov 10, 2015 at 04:46:51PM -0800, Tim Bird wrote:
> This fixes a bug where if you disconnect and re-connect the USB cable,
> the gadget driver stops working.
> 
> Add support for async_irq to wake up driver from low power mode.
> Without this, the power management code never calls resume.
> Also, have the phy driver kick the gadget driver (chipidea otg)
> by having the chipidea driver register with it, for vbus connect
> notifications.
> 
> Signed-off-by: Tim Bird <tim.bird@sonymobile.com>
> ---
>  drivers/usb/chipidea/udc.c    |  6 ++++++
>  drivers/usb/phy/phy-msm-usb.c | 16 ++++++++++++++++
>  include/linux/usb/msm_hsusb.h |  1 +
>  3 files changed, 23 insertions(+)
> 
> diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
> index 8223fe7..06234cd 100644
> --- a/drivers/usb/chipidea/udc.c
> +++ b/drivers/usb/chipidea/udc.c
> @@ -1890,6 +1890,12 @@ static int udc_start(struct ci_hdrc *ci)
>  
>  	ci->gadget.ep0 = &ci->ep0in->ep;
>  
> +	if (ci->usb_phy) {
> +		retval = otg_set_peripheral(ci->usb_phy->otg, &ci->gadget);
> +		if (retval)
> +			goto destroy_eps;
> +	}
> +
>  	retval = usb_add_gadget_udc(dev, &ci->gadget);
>  	if (retval)
>  		goto destroy_eps;

Although it looks no affect for other drivers, it is better you
can split patches between controller and phy, then I can have a test.

In fact, most of phy-msm-usb.c's implementations (except USB PHY related)
are included in chipidea drivers, hope you can try it in future.

> diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
> index 80eb991..eb80f92 100644
> --- a/drivers/usb/phy/phy-msm-usb.c
> +++ b/drivers/usb/phy/phy-msm-usb.c
> @@ -1731,6 +1731,12 @@ static int msm_otg_probe(struct platform_device *pdev)
>  		return motg->irq;
>  	}
>  
> +	motg->async_irq = platform_get_irq_byname(pdev, "async_irq");
> +	if (motg->async_irq < 0) {
> +		dev_info(&pdev->dev, "platform_get_irq for async_irq failed\n");
> +		motg->async_irq = 0;
> +	}
> +

dev_err

>  	regs[0].supply = "vddcx";
>  	regs[1].supply = "v3p3";
>  	regs[2].supply = "v1p8";
> @@ -1780,6 +1786,16 @@ static int msm_otg_probe(struct platform_device *pdev)
>  		goto disable_ldo;
>  	}
>  
> +	if (motg->async_irq) {
> +		ret = devm_request_irq(&pdev->dev, motg->async_irq,
> +				      msm_otg_irq, IRQF_TRIGGER_RISING,
> +				      "msm_otg", motg);
> +		if (ret) {
> +			dev_err(&pdev->dev, "request irq failed (ASYNC INT)\n");
> +			goto disable_ldo;
> +		}
> +	}
> +
>  	phy->init = msm_phy_init;
>  	phy->set_power = msm_otg_set_power;
>  	phy->notify_disconnect = msm_phy_notify_disconnect;
> diff --git a/include/linux/usb/msm_hsusb.h b/include/linux/usb/msm_hsusb.h
> index 8c8f685..08c67a3 100644
> --- a/include/linux/usb/msm_hsusb.h
> +++ b/include/linux/usb/msm_hsusb.h
> @@ -164,6 +164,7 @@ struct msm_otg {
>  	struct usb_phy phy;
>  	struct msm_otg_platform_data *pdata;
>  	int irq;
> +	int async_irq;
>  	struct clk *clk;
>  	struct clk *pclk;
>  	struct clk *core_clk;
> -- 
> 1.8.2.2
>
Bird, Tim Nov. 11, 2015, 5:48 p.m. UTC | #2
On 11/10/2015 07:14 PM, Peter Chen wrote:
> On Tue, Nov 10, 2015 at 04:46:51PM -0800, Tim Bird wrote:
>> This fixes a bug where if you disconnect and re-connect the USB cable,
>> the gadget driver stops working.
>>
>> Add support for async_irq to wake up driver from low power mode.
>> Without this, the power management code never calls resume.
>> Also, have the phy driver kick the gadget driver (chipidea otg)
>> by having the chipidea driver register with it, for vbus connect
>> notifications.
>>
>> Signed-off-by: Tim Bird <tim.bird@sonymobile.com>
>> ---
>>  drivers/usb/chipidea/udc.c    |  6 ++++++
>>  drivers/usb/phy/phy-msm-usb.c | 16 ++++++++++++++++
>>  include/linux/usb/msm_hsusb.h |  1 +
>>  3 files changed, 23 insertions(+)
>>
>> diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
>> index 8223fe7..06234cd 100644
>> --- a/drivers/usb/chipidea/udc.c
>> +++ b/drivers/usb/chipidea/udc.c
>> @@ -1890,6 +1890,12 @@ static int udc_start(struct ci_hdrc *ci)
>>  
>>  	ci->gadget.ep0 = &ci->ep0in->ep;
>>  
>> +	if (ci->usb_phy) {
>> +		retval = otg_set_peripheral(ci->usb_phy->otg, &ci->gadget);
>> +		if (retval)
>> +			goto destroy_eps;
>> +	}
>> +
>>  	retval = usb_add_gadget_udc(dev, &ci->gadget);
>>  	if (retval)
>>  		goto destroy_eps;
> 
> Although it looks no affect for other drivers, it is better you
> can split patches between controller and phy, then I can have a test.

OK.

> In fact, most of phy-msm-usb.c's implementations (except USB PHY related)
> are included in chipidea drivers, hope you can try it in future.

I would like to do this.  I'm pretty confused about the relationship between
ehci, chipidea and the phy code, with regard to managing the controller
hardware.  Is there a phy in mainline that is a good example of having most
of the controller support in the chipidea driver rather than in the phy?

Thanks!
 
>> diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
>> index 80eb991..eb80f92 100644
>> --- a/drivers/usb/phy/phy-msm-usb.c
>> +++ b/drivers/usb/phy/phy-msm-usb.c
>> @@ -1731,6 +1731,12 @@ static int msm_otg_probe(struct platform_device *pdev)
>>  		return motg->irq;
>>  	}
>>  
>> +	motg->async_irq = platform_get_irq_byname(pdev, "async_irq");
>> +	if (motg->async_irq < 0) {
>> +		dev_info(&pdev->dev, "platform_get_irq for async_irq failed\n");
>> +		motg->async_irq = 0;
>> +	}
>> +
> 
> dev_err

OK - I'll change this.  I've listed the async_irq as optional in the binding doc,
so I don't actually error out, but I was unsure the appropriate error level for
this message.

Thanks for the feedback!
 -- Tim
--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Peter Chen Nov. 12, 2015, 9:13 a.m. UTC | #3
On Wed, Nov 11, 2015 at 09:48:00AM -0800, Tim Bird wrote:
> 
> 
> On 11/10/2015 07:14 PM, Peter Chen wrote:
> > On Tue, Nov 10, 2015 at 04:46:51PM -0800, Tim Bird wrote:
> >> This fixes a bug where if you disconnect and re-connect the USB cable,
> >> the gadget driver stops working.
> >>
> >> Add support for async_irq to wake up driver from low power mode.
> >> Without this, the power management code never calls resume.
> >> Also, have the phy driver kick the gadget driver (chipidea otg)
> >> by having the chipidea driver register with it, for vbus connect
> >> notifications.
> >>
> >> Signed-off-by: Tim Bird <tim.bird@sonymobile.com>
> >> ---
> >>  drivers/usb/chipidea/udc.c    |  6 ++++++
> >>  drivers/usb/phy/phy-msm-usb.c | 16 ++++++++++++++++
> >>  include/linux/usb/msm_hsusb.h |  1 +
> >>  3 files changed, 23 insertions(+)
> >>
> >> diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
> >> index 8223fe7..06234cd 100644
> >> --- a/drivers/usb/chipidea/udc.c
> >> +++ b/drivers/usb/chipidea/udc.c
> >> @@ -1890,6 +1890,12 @@ static int udc_start(struct ci_hdrc *ci)
> >>  
> >>  	ci->gadget.ep0 = &ci->ep0in->ep;
> >>  
> >> +	if (ci->usb_phy) {
> >> +		retval = otg_set_peripheral(ci->usb_phy->otg, &ci->gadget);
> >> +		if (retval)
> >> +			goto destroy_eps;
> >> +	}
> >> +
> >>  	retval = usb_add_gadget_udc(dev, &ci->gadget);
> >>  	if (retval)
> >>  		goto destroy_eps;
> > 
> > Although it looks no affect for other drivers, it is better you
> > can split patches between controller and phy, then I can have a test.
> 
> OK.
> 
> > In fact, most of phy-msm-usb.c's implementations (except USB PHY related)
> > are included in chipidea drivers, hope you can try it in future.
> 
> I would like to do this.  I'm pretty confused about the relationship between
> ehci, chipidea and the phy code, with regard to managing the controller
> hardware.

Chipidea is controller driver, it manages ehci (host.c) , udc (udc.c),
and otg (otg.c and otg-fsm.c), all controller related resources are
managed by chipidea driver, and it calls usb_phy (or phy)'s API when
it needs to access PHY.

The PHY code is another driver, and chipidea can get PHY through the
dts, the PHY reference can be phandle in controler's node.
(see arch/arm/boot/dts/imx6qdl.dts for reference).

> Is there a phy in mainline that is a good example of having most
> of the controller support in the chipidea driver rather than in the phy?
> 

Many of them, in fact, the PHY driver should not include controller
access, otherwise, there are two drivers access the same register
region.

drivers/usb/phy/phy-mxs-usb.c
drivers/phy/phy-berlin-usb.c
drivers/usb/phy/phy-generic.c

Just grep compatible string described at
Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt
at ARM dts folder, and find the PHY node at related
dts, then you will know their PHY driver.

Peter

> Thanks!
>  
> >> diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
> >> index 80eb991..eb80f92 100644
> >> --- a/drivers/usb/phy/phy-msm-usb.c
> >> +++ b/drivers/usb/phy/phy-msm-usb.c
> >> @@ -1731,6 +1731,12 @@ static int msm_otg_probe(struct platform_device *pdev)
> >>  		return motg->irq;
> >>  	}
> >>  
> >> +	motg->async_irq = platform_get_irq_byname(pdev, "async_irq");
> >> +	if (motg->async_irq < 0) {
> >> +		dev_info(&pdev->dev, "platform_get_irq for async_irq failed\n");
> >> +		motg->async_irq = 0;
> >> +	}
> >> +
> > 
> > dev_err
> 
> OK - I'll change this.  I've listed the async_irq as optional in the binding doc,
> so I don't actually error out, but I was unsure the appropriate error level for
> this message.
> 
> Thanks for the feedback!
>  -- Tim
Felipe Balbi Nov. 16, 2015, 5:21 p.m. UTC | #4
Hi,

Peter Chen <peter.chen@freescale.com> writes:
> On Wed, Nov 11, 2015 at 09:48:00AM -0800, Tim Bird wrote:
>> 
>> 
>> On 11/10/2015 07:14 PM, Peter Chen wrote:
>> > On Tue, Nov 10, 2015 at 04:46:51PM -0800, Tim Bird wrote:
>> >> This fixes a bug where if you disconnect and re-connect the USB cable,
>> >> the gadget driver stops working.
>> >>
>> >> Add support for async_irq to wake up driver from low power mode.
>> >> Without this, the power management code never calls resume.
>> >> Also, have the phy driver kick the gadget driver (chipidea otg)
>> >> by having the chipidea driver register with it, for vbus connect
>> >> notifications.
>> >>
>> >> Signed-off-by: Tim Bird <tim.bird@sonymobile.com>
>> >> ---
>> >>  drivers/usb/chipidea/udc.c    |  6 ++++++
>> >>  drivers/usb/phy/phy-msm-usb.c | 16 ++++++++++++++++
>> >>  include/linux/usb/msm_hsusb.h |  1 +
>> >>  3 files changed, 23 insertions(+)

I just wanna know how you guys want this to be handled ? Through my tree
or chipidea's ? Or do we break the dependencies between the changes ?
Bird, Tim Nov. 20, 2015, 10:36 p.m. UTC | #5
On 11/16/2015 09:21 AM, Felipe Balbi wrote:
> 
> Hi,
> 
> Peter Chen <peter.chen@freescale.com> writes:
>> On Wed, Nov 11, 2015 at 09:48:00AM -0800, Tim Bird wrote:
>>>
>>>
>>> On 11/10/2015 07:14 PM, Peter Chen wrote:
>>>> On Tue, Nov 10, 2015 at 04:46:51PM -0800, Tim Bird wrote:
>>>>> This fixes a bug where if you disconnect and re-connect the USB cable,
>>>>> the gadget driver stops working.
>>>>>
>>>>> Add support for async_irq to wake up driver from low power mode.
>>>>> Without this, the power management code never calls resume.
>>>>> Also, have the phy driver kick the gadget driver (chipidea otg)
>>>>> by having the chipidea driver register with it, for vbus connect
>>>>> notifications.
>>>>>
>>>>> Signed-off-by: Tim Bird <tim.bird@sonymobile.com>
>>>>> ---
>>>>>  drivers/usb/chipidea/udc.c    |  6 ++++++
>>>>>  drivers/usb/phy/phy-msm-usb.c | 16 ++++++++++++++++
>>>>>  include/linux/usb/msm_hsusb.h |  1 +
>>>>>  3 files changed, 23 insertions(+)
> 
> I just wanna know how you guys want this to be handled ? Through my tree
> or chipidea's ? Or do we break the dependencies between the changes ?

I'm fine with splitting it up.  I'm sending a new series with 3 patches
right after this message.  Do both trees go to linux-next?
 -- Tim

--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Felipe Balbi Nov. 21, 2015, 12:58 a.m. UTC | #6
Hi,

Tim Bird <tim.bird@sonymobile.com> writes:
> On 11/16/2015 09:21 AM, Felipe Balbi wrote:
>> 
>> Hi,
>> 
>> Peter Chen <peter.chen@freescale.com> writes:
>>> On Wed, Nov 11, 2015 at 09:48:00AM -0800, Tim Bird wrote:
>>>>
>>>>
>>>> On 11/10/2015 07:14 PM, Peter Chen wrote:
>>>>> On Tue, Nov 10, 2015 at 04:46:51PM -0800, Tim Bird wrote:
>>>>>> This fixes a bug where if you disconnect and re-connect the USB cable,
>>>>>> the gadget driver stops working.
>>>>>>
>>>>>> Add support for async_irq to wake up driver from low power mode.
>>>>>> Without this, the power management code never calls resume.
>>>>>> Also, have the phy driver kick the gadget driver (chipidea otg)
>>>>>> by having the chipidea driver register with it, for vbus connect
>>>>>> notifications.
>>>>>>
>>>>>> Signed-off-by: Tim Bird <tim.bird@sonymobile.com>
>>>>>> ---
>>>>>>  drivers/usb/chipidea/udc.c    |  6 ++++++
>>>>>>  drivers/usb/phy/phy-msm-usb.c | 16 ++++++++++++++++
>>>>>>  include/linux/usb/msm_hsusb.h |  1 +
>>>>>>  3 files changed, 23 insertions(+)
>> 
>> I just wanna know how you guys want this to be handled ? Through my tree
>> or chipidea's ? Or do we break the dependencies between the changes ?
>
> I'm fine with splitting it up.  I'm sending a new series with 3 patches
> right after this message.  Do both trees go to linux-next?

I have my fixes and next branches both on next. Not sure about chipidea.
Peter Chen Nov. 23, 2015, 2:10 a.m. UTC | #7
On Fri, Nov 20, 2015 at 06:58:59PM -0600, Felipe Balbi wrote:
> 
> Hi,
> 
> Tim Bird <tim.bird@sonymobile.com> writes:
> > On 11/16/2015 09:21 AM, Felipe Balbi wrote:
> >> 
> >> Hi,
> >> 
> >> Peter Chen <peter.chen@freescale.com> writes:
> >>> On Wed, Nov 11, 2015 at 09:48:00AM -0800, Tim Bird wrote:
> >>>>
> >>>>
> >>>> On 11/10/2015 07:14 PM, Peter Chen wrote:
> >>>>> On Tue, Nov 10, 2015 at 04:46:51PM -0800, Tim Bird wrote:
> >>>>>> This fixes a bug where if you disconnect and re-connect the USB cable,
> >>>>>> the gadget driver stops working.
> >>>>>>
> >>>>>> Add support for async_irq to wake up driver from low power mode.
> >>>>>> Without this, the power management code never calls resume.
> >>>>>> Also, have the phy driver kick the gadget driver (chipidea otg)
> >>>>>> by having the chipidea driver register with it, for vbus connect
> >>>>>> notifications.
> >>>>>>
> >>>>>> Signed-off-by: Tim Bird <tim.bird@sonymobile.com>
> >>>>>> ---
> >>>>>>  drivers/usb/chipidea/udc.c    |  6 ++++++
> >>>>>>  drivers/usb/phy/phy-msm-usb.c | 16 ++++++++++++++++
> >>>>>>  include/linux/usb/msm_hsusb.h |  1 +
> >>>>>>  3 files changed, 23 insertions(+)
> >> 
> >> I just wanna know how you guys want this to be handled ? Through my tree
> >> or chipidea's ? Or do we break the dependencies between the changes ?
> >
> > I'm fine with splitting it up.  I'm sending a new series with 3 patches
> > right after this message.  Do both trees go to linux-next?
> 
> I have my fixes and next branches both on next. Not sure about chipidea.
> 

Chipidea's fixes and next branches on next too.
diff mbox

Patch

diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 8223fe7..06234cd 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -1890,6 +1890,12 @@  static int udc_start(struct ci_hdrc *ci)
 
 	ci->gadget.ep0 = &ci->ep0in->ep;
 
+	if (ci->usb_phy) {
+		retval = otg_set_peripheral(ci->usb_phy->otg, &ci->gadget);
+		if (retval)
+			goto destroy_eps;
+	}
+
 	retval = usb_add_gadget_udc(dev, &ci->gadget);
 	if (retval)
 		goto destroy_eps;
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 80eb991..eb80f92 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -1731,6 +1731,12 @@  static int msm_otg_probe(struct platform_device *pdev)
 		return motg->irq;
 	}
 
+	motg->async_irq = platform_get_irq_byname(pdev, "async_irq");
+	if (motg->async_irq < 0) {
+		dev_info(&pdev->dev, "platform_get_irq for async_irq failed\n");
+		motg->async_irq = 0;
+	}
+
 	regs[0].supply = "vddcx";
 	regs[1].supply = "v3p3";
 	regs[2].supply = "v1p8";
@@ -1780,6 +1786,16 @@  static int msm_otg_probe(struct platform_device *pdev)
 		goto disable_ldo;
 	}
 
+	if (motg->async_irq) {
+		ret = devm_request_irq(&pdev->dev, motg->async_irq,
+				      msm_otg_irq, IRQF_TRIGGER_RISING,
+				      "msm_otg", motg);
+		if (ret) {
+			dev_err(&pdev->dev, "request irq failed (ASYNC INT)\n");
+			goto disable_ldo;
+		}
+	}
+
 	phy->init = msm_phy_init;
 	phy->set_power = msm_otg_set_power;
 	phy->notify_disconnect = msm_phy_notify_disconnect;
diff --git a/include/linux/usb/msm_hsusb.h b/include/linux/usb/msm_hsusb.h
index 8c8f685..08c67a3 100644
--- a/include/linux/usb/msm_hsusb.h
+++ b/include/linux/usb/msm_hsusb.h
@@ -164,6 +164,7 @@  struct msm_otg {
 	struct usb_phy phy;
 	struct msm_otg_platform_data *pdata;
 	int irq;
+	int async_irq;
 	struct clk *clk;
 	struct clk *pclk;
 	struct clk *core_clk;