mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: dwc2: disable erroneous overcurrent condition
@ 2017-10-16 13:57 Dinh Nguyen
  2017-10-16 16:37 ` Marek Vasut
  0 siblings, 1 reply; 3+ messages in thread
From: Dinh Nguyen @ 2017-10-16 13:57 UTC (permalink / raw)
  To: johnyoun; +Cc: dinguyen, balbi, marex, linux-usb, linux-kernel

For the case where an external VBUS is used, we should enable the external
VBUS comparator in the driver. This would prevent an unnecessary
overcurrent error which would then disable the host port.

This patch uses the standard 'disable-over-current' binding to allow of the
option of disabling the over-current condition.

Signed-off-by: Dinh Nguyen <dinguyen@kernel.org>
---
 drivers/usb/dwc2/core.h   | 4 ++++
 drivers/usb/dwc2/hcd.c    | 5 +++++
 drivers/usb/dwc2/params.c | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 8367d4f9..730d7eb 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -395,6 +395,9 @@ enum dwc2_ep0_state {
  *                           (default when phy_type is UTMI+ or ULPI)
  *                       1 - 6 MHz
  *                           (default when phy_type is Full Speed)
+ * @oc_disable:		Flag to disable overcurrent condition.
+ *			0 - Allow overcurrent condition to get detected
+ *			1 - Disable overcurrent condtion to get detected
  * @ts_dline:           Enable Term Select Dline pulsing
  *                       0 - No (default)
  *                       1 - Yes
@@ -492,6 +495,7 @@ struct dwc2_core_params {
 	bool dma_desc_fs_enable;
 	bool host_support_fs_ls_low_power;
 	bool host_ls_low_power_phy_clk;
+	bool oc_disable;
 
 	u8 host_channels;
 	u16 host_rx_fifo_size;
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index c263114..5e20336 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -213,6 +213,11 @@ static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
 		usbcfg &= ~(GUSBCFG_PHYIF16 | GUSBCFG_DDRSEL);
 		if (hsotg->params.phy_ulpi_ddr)
 			usbcfg |= GUSBCFG_DDRSEL;
+
+		/* Set external VBUS indicator as needed. */
+		if (hsotg->params.oc_disable)
+			usbcfg |= (GUSBCFG_ULPI_INT_VBUS_IND |
+				   GUSBCFG_INDICATORPASSTHROUGH);
 		break;
 	case DWC2_PHY_TYPE_PARAM_UTMI:
 		/* UTMI+ interface */
diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
index a3ffe97..39e02cd 100644
--- a/drivers/usb/dwc2/params.c
+++ b/drivers/usb/dwc2/params.c
@@ -335,6 +335,9 @@ static void dwc2_get_device_properties(struct dwc2_hsotg *hsotg)
 						       num);
 		}
 	}
+
+	if (of_find_property(hsotg->dev->of_node, "disable-over-current", NULL))
+		p->oc_disable = true;
 }
 
 static void dwc2_check_param_otg_cap(struct dwc2_hsotg *hsotg)
-- 
2.7.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: dwc2: disable erroneous overcurrent condition
  2017-10-16 13:57 [PATCH] usb: dwc2: disable erroneous overcurrent condition Dinh Nguyen
@ 2017-10-16 16:37 ` Marek Vasut
  2017-10-18  6:08   ` Minas Harutyunyan
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Vasut @ 2017-10-16 16:37 UTC (permalink / raw)
  To: Dinh Nguyen, johnyoun; +Cc: balbi, linux-usb, linux-kernel

On 10/16/2017 03:57 PM, Dinh Nguyen wrote:
> For the case where an external VBUS is used, we should enable the external
> VBUS comparator in the driver. This would prevent an unnecessary
> overcurrent error which would then disable the host port.
> 
> This patch uses the standard 'disable-over-current' binding to allow of the
> option of disabling the over-current condition.
> 
> Signed-off-by: Dinh Nguyen <dinguyen@kernel.org>

Reviewed-by: Marek Vasut <marex@denx.de>

Similar patch was in U-Boot for two years now and it does the trick indeed.

> ---
>  drivers/usb/dwc2/core.h   | 4 ++++
>  drivers/usb/dwc2/hcd.c    | 5 +++++
>  drivers/usb/dwc2/params.c | 3 +++
>  3 files changed, 12 insertions(+)
> 
> diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
> index 8367d4f9..730d7eb 100644
> --- a/drivers/usb/dwc2/core.h
> +++ b/drivers/usb/dwc2/core.h
> @@ -395,6 +395,9 @@ enum dwc2_ep0_state {
>   *                           (default when phy_type is UTMI+ or ULPI)
>   *                       1 - 6 MHz
>   *                           (default when phy_type is Full Speed)
> + * @oc_disable:		Flag to disable overcurrent condition.
> + *			0 - Allow overcurrent condition to get detected
> + *			1 - Disable overcurrent condtion to get detected
>   * @ts_dline:           Enable Term Select Dline pulsing
>   *                       0 - No (default)
>   *                       1 - Yes
> @@ -492,6 +495,7 @@ struct dwc2_core_params {
>  	bool dma_desc_fs_enable;
>  	bool host_support_fs_ls_low_power;
>  	bool host_ls_low_power_phy_clk;
> +	bool oc_disable;
>  
>  	u8 host_channels;
>  	u16 host_rx_fifo_size;
> diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
> index c263114..5e20336 100644
> --- a/drivers/usb/dwc2/hcd.c
> +++ b/drivers/usb/dwc2/hcd.c
> @@ -213,6 +213,11 @@ static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
>  		usbcfg &= ~(GUSBCFG_PHYIF16 | GUSBCFG_DDRSEL);
>  		if (hsotg->params.phy_ulpi_ddr)
>  			usbcfg |= GUSBCFG_DDRSEL;
> +
> +		/* Set external VBUS indicator as needed. */
> +		if (hsotg->params.oc_disable)
> +			usbcfg |= (GUSBCFG_ULPI_INT_VBUS_IND |
> +				   GUSBCFG_INDICATORPASSTHROUGH);
>  		break;
>  	case DWC2_PHY_TYPE_PARAM_UTMI:
>  		/* UTMI+ interface */
> diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
> index a3ffe97..39e02cd 100644
> --- a/drivers/usb/dwc2/params.c
> +++ b/drivers/usb/dwc2/params.c
> @@ -335,6 +335,9 @@ static void dwc2_get_device_properties(struct dwc2_hsotg *hsotg)
>  						       num);
>  		}
>  	}
> +
> +	if (of_find_property(hsotg->dev->of_node, "disable-over-current", NULL))
> +		p->oc_disable = true;
>  }
>  
>  static void dwc2_check_param_otg_cap(struct dwc2_hsotg *hsotg)
> 


-- 
Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: dwc2: disable erroneous overcurrent condition
  2017-10-16 16:37 ` Marek Vasut
@ 2017-10-18  6:08   ` Minas Harutyunyan
  0 siblings, 0 replies; 3+ messages in thread
From: Minas Harutyunyan @ 2017-10-18  6:08 UTC (permalink / raw)
  To: Marek Vasut, Dinh Nguyen, John.Youn; +Cc: balbi, linux-usb, linux-kernel

On 10/16/2017 8:40 PM, Marek Vasut wrote:
> On 10/16/2017 03:57 PM, Dinh Nguyen wrote:
>> For the case where an external VBUS is used, we should enable the external
>> VBUS comparator in the driver. This would prevent an unnecessary
>> overcurrent error which would then disable the host port.
>>
>> This patch uses the standard 'disable-over-current' binding to allow of the
>> option of disabling the over-current condition.
>>
>> Signed-off-by: Dinh Nguyen <dinguyen@kernel.org>
> 
> Reviewed-by: Marek Vasut <marex@denx.de>
> 
> Similar patch was in U-Boot for two years now and it does the trick indeed.
> 
>> ---
>>   drivers/usb/dwc2/core.h   | 4 ++++
>>   drivers/usb/dwc2/hcd.c    | 5 +++++
>>   drivers/usb/dwc2/params.c | 3 +++
>>   3 files changed, 12 insertions(+)
>>
>> diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
>> index 8367d4f9..730d7eb 100644
>> --- a/drivers/usb/dwc2/core.h
>> +++ b/drivers/usb/dwc2/core.h
>> @@ -395,6 +395,9 @@ enum dwc2_ep0_state {
>>    *                           (default when phy_type is UTMI+ or ULPI)
>>    *                       1 - 6 MHz
>>    *                           (default when phy_type is Full Speed)
>> + * @oc_disable:		Flag to disable overcurrent condition.
>> + *			0 - Allow overcurrent condition to get detected
>> + *			1 - Disable overcurrent condtion to get detected
>>    * @ts_dline:           Enable Term Select Dline pulsing
>>    *                       0 - No (default)
>>    *                       1 - Yes
>> @@ -492,6 +495,7 @@ struct dwc2_core_params {
>>   	bool dma_desc_fs_enable;
>>   	bool host_support_fs_ls_low_power;
>>   	bool host_ls_low_power_phy_clk;
>> +	bool oc_disable;
>>   
>>   	u8 host_channels;
>>   	u16 host_rx_fifo_size;
>> diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
>> index c263114..5e20336 100644
>> --- a/drivers/usb/dwc2/hcd.c
>> +++ b/drivers/usb/dwc2/hcd.c
>> @@ -213,6 +213,11 @@ static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
>>   		usbcfg &= ~(GUSBCFG_PHYIF16 | GUSBCFG_DDRSEL);
>>   		if (hsotg->params.phy_ulpi_ddr)
>>   			usbcfg |= GUSBCFG_DDRSEL;
>> +
>> +		/* Set external VBUS indicator as needed. */
>> +		if (hsotg->params.oc_disable)
>> +			usbcfg |= (GUSBCFG_ULPI_INT_VBUS_IND |
>> +				   GUSBCFG_INDICATORPASSTHROUGH);
>>   		break;
>>   	case DWC2_PHY_TYPE_PARAM_UTMI:
>>   		/* UTMI+ interface */
>> diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
>> index a3ffe97..39e02cd 100644
>> --- a/drivers/usb/dwc2/params.c
>> +++ b/drivers/usb/dwc2/params.c
>> @@ -335,6 +335,9 @@ static void dwc2_get_device_properties(struct dwc2_hsotg *hsotg)
>>   						       num);
>>   		}
>>   	}
>> +
>> +	if (of_find_property(hsotg->dev->of_node, "disable-over-current", NULL))
>> +		p->oc_disable = true;
>>   }
>>   
>>   static void dwc2_check_param_otg_cap(struct dwc2_hsotg *hsotg)
>>
> 
> 
Hi John Youn, I checked with HW team - patch is OK.

Acked-by: Minas Harutyunyan <hminas@synopsys.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-18  6:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-16 13:57 [PATCH] usb: dwc2: disable erroneous overcurrent condition Dinh Nguyen
2017-10-16 16:37 ` Marek Vasut
2017-10-18  6:08   ` Minas Harutyunyan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®