All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] usb: chipidea: imx: remove one duplicated reg define
@ 2023-05-17  8:19 Xu Yang
  2023-05-17  8:19 ` [PATCH 2/3] usb: chipidea: imx: turn off vbus comparator when suspend Xu Yang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Xu Yang @ 2023-05-17  8:19 UTC (permalink / raw)
  To: peter.chen; +Cc: gregkh, linux-usb, linux-imx, jun.li, xu.yang_2

Remove one duplicated definition of MX7D_USB_OTG_PHY_CFG1.

Signed-off-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
 drivers/usb/chipidea/usbmisc_imx.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
index c57c1a71a513..be939e77719d 100644
--- a/drivers/usb/chipidea/usbmisc_imx.c
+++ b/drivers/usb/chipidea/usbmisc_imx.c
@@ -113,7 +113,6 @@
 #define MX7D_USBNC_USB_CTRL2_DP_DM_MASK			(BIT(12) | BIT(13) | \
 							BIT(14) | BIT(15))
 
-#define MX7D_USB_OTG_PHY_CFG1		0x30
 #define MX7D_USB_OTG_PHY_CFG2_CHRG_CHRGSEL	BIT(0)
 #define MX7D_USB_OTG_PHY_CFG2_CHRG_VDATDETENB0	BIT(1)
 #define MX7D_USB_OTG_PHY_CFG2_CHRG_VDATSRCENB0	BIT(2)
-- 
2.34.1


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

* [PATCH 2/3] usb: chipidea: imx: turn off vbus comparator when suspend
  2023-05-17  8:19 [PATCH 1/3] usb: chipidea: imx: remove one duplicated reg define Xu Yang
@ 2023-05-17  8:19 ` Xu Yang
  2023-06-04 23:25   ` Peter Chen
  2023-05-17  8:19 ` [PATCH 3/3] usb: chipidea: imx: add missing USB PHY DPDM wakeup setting Xu Yang
  2023-06-04 23:25 ` [PATCH 1/3] usb: chipidea: imx: remove one duplicated reg define Peter Chen
  2 siblings, 1 reply; 6+ messages in thread
From: Xu Yang @ 2023-05-17  8:19 UTC (permalink / raw)
  To: peter.chen; +Cc: gregkh, linux-usb, linux-imx, jun.li, xu.yang_2

As we use bvalid for vbus wakeup source, to save power when
suspend, turn off the vbus comparator for imx7d and imx8mm.

Below is this bit description from RM of iMX8MM
"VBUS Valid Comparator Enable:

This signal controls the USB OTG PHY VBUS Valid comparator which
indicates whether the voltage on the USB_OTG*_VBUS pin is below
the VBUS Valid threshold. The VBUS Valid threshold is nominally
4.75V on this USB PHY. The VBUS Valid threshold can be adjusted
using the USBNC_OTGn_PHY_CFG1[OTGTUNE0] bit field. Status of the
VBUS Valid comparator, when it is enabled, is reported on the
USBNC_OTGn_PHY_STATUS[VBUS_VLD] bit.
When OTGDISABLE0 (USBNC_USB_OTGx_PHY_CFG2[10])is set to 1'b0 and
DRVVBUS0 is set to 1'b1, the Bandgap circuitry and VBUS Valid
comparator are powered, even in Suspend or Sleep mode.
DRVVBUS0 should be reset to 1'b0 when the internal VBUS Valid comparator
is not required, to reduce quiescent current in Suspend or Sleep mode.
 - 0 The VBUS Valid comparator is disabled
  - 1 The VBUS Valid comparator is enabled"

Signed-off-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
 drivers/usb/chipidea/usbmisc_imx.c | 35 ++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
index be939e77719d..9566022a2183 100644
--- a/drivers/usb/chipidea/usbmisc_imx.c
+++ b/drivers/usb/chipidea/usbmisc_imx.c
@@ -151,6 +151,7 @@ struct usbmisc_ops {
 	int (*charger_detection)(struct imx_usbmisc_data *data);
 	/* It's called when system resume from usb power lost */
 	int (*power_lost_check)(struct imx_usbmisc_data *data);
+	void (*vbus_comparator_on)(struct imx_usbmisc_data *data, bool on);
 };
 
 struct imx_usbmisc {
@@ -874,6 +875,33 @@ static int imx7d_charger_detection(struct imx_usbmisc_data *data)
 	return ret;
 }
 
+static void usbmisc_imx7d_vbus_comparator_on(struct imx_usbmisc_data *data,
+					     bool on)
+{
+	unsigned long flags;
+	struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
+	u32 val;
+
+	if (data->hsic)
+		return;
+
+	spin_lock_irqsave(&usbmisc->lock, flags);
+	/*
+	 * Disable VBUS valid comparator when in suspend mode,
+	 * when OTG is disabled and DRVVBUS0 is asserted case
+	 * the Bandgap circuitry and VBUS Valid comparator are
+	 * still powered, even in Suspend or Sleep mode.
+	 */
+	val = readl(usbmisc->base + MX7D_USB_OTG_PHY_CFG2);
+	if (on)
+		val |= MX7D_USB_OTG_PHY_CFG2_DRVVBUS0;
+	else
+		val &= ~MX7D_USB_OTG_PHY_CFG2_DRVVBUS0;
+
+	writel(val, usbmisc->base + MX7D_USB_OTG_PHY_CFG2);
+	spin_unlock_irqrestore(&usbmisc->lock, flags);
+}
+
 static int usbmisc_imx7ulp_init(struct imx_usbmisc_data *data)
 {
 	struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
@@ -1017,6 +1045,7 @@ static const struct usbmisc_ops imx7d_usbmisc_ops = {
 	.set_wakeup = usbmisc_imx7d_set_wakeup,
 	.charger_detection = imx7d_charger_detection,
 	.power_lost_check = usbmisc_imx7d_power_lost_check,
+	.vbus_comparator_on = usbmisc_imx7d_vbus_comparator_on,
 };
 
 static const struct usbmisc_ops imx7ulp_usbmisc_ops = {
@@ -1131,6 +1160,9 @@ int imx_usbmisc_suspend(struct imx_usbmisc_data *data, bool wakeup)
 
 	usbmisc = dev_get_drvdata(data->dev);
 
+	if (usbmisc->ops->vbus_comparator_on)
+		usbmisc->ops->vbus_comparator_on(data, false);
+
 	if (wakeup && usbmisc->ops->set_wakeup)
 		ret = usbmisc->ops->set_wakeup(data, true);
 	if (ret) {
@@ -1184,6 +1216,9 @@ int imx_usbmisc_resume(struct imx_usbmisc_data *data, bool wakeup)
 		goto hsic_set_clk_fail;
 	}
 
+	if (usbmisc->ops->vbus_comparator_on)
+		usbmisc->ops->vbus_comparator_on(data, true);
+
 	return 0;
 
 hsic_set_clk_fail:
-- 
2.34.1


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

* [PATCH 3/3] usb: chipidea: imx: add missing USB PHY DPDM wakeup setting
  2023-05-17  8:19 [PATCH 1/3] usb: chipidea: imx: remove one duplicated reg define Xu Yang
  2023-05-17  8:19 ` [PATCH 2/3] usb: chipidea: imx: turn off vbus comparator when suspend Xu Yang
@ 2023-05-17  8:19 ` Xu Yang
  2023-06-04 23:27   ` Peter Chen
  2023-06-04 23:25 ` [PATCH 1/3] usb: chipidea: imx: remove one duplicated reg define Peter Chen
  2 siblings, 1 reply; 6+ messages in thread
From: Xu Yang @ 2023-05-17  8:19 UTC (permalink / raw)
  To: peter.chen; +Cc: gregkh, linux-usb, linux-imx, jun.li, xu.yang_2

USB PHY DPDM wakeup bit is enabled by default, when USB wakeup
is not required(/sys/.../wakeup is disabled), this bit should be
disabled, otherwise we will have unexpected wakeup if do USB device
connect/disconnect while system sleep.
This bit can be enabled for both host and device mode.

Signed-off-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
 drivers/usb/chipidea/usbmisc_imx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
index 9566022a2183..9ee9621e2ccc 100644
--- a/drivers/usb/chipidea/usbmisc_imx.c
+++ b/drivers/usb/chipidea/usbmisc_imx.c
@@ -134,7 +134,7 @@
 #define TXVREFTUNE0_MASK		(0xf << 20)
 
 #define MX6_USB_OTG_WAKEUP_BITS (MX6_BM_WAKEUP_ENABLE | MX6_BM_VBUS_WAKEUP | \
-				 MX6_BM_ID_WAKEUP)
+				 MX6_BM_ID_WAKEUP | MX6SX_BM_DPDM_WAKEUP_EN)
 
 struct usbmisc_ops {
 	/* It's called once when probe a usb device */
-- 
2.34.1


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

* Re: [PATCH 1/3] usb: chipidea: imx: remove one duplicated reg define
  2023-05-17  8:19 [PATCH 1/3] usb: chipidea: imx: remove one duplicated reg define Xu Yang
  2023-05-17  8:19 ` [PATCH 2/3] usb: chipidea: imx: turn off vbus comparator when suspend Xu Yang
  2023-05-17  8:19 ` [PATCH 3/3] usb: chipidea: imx: add missing USB PHY DPDM wakeup setting Xu Yang
@ 2023-06-04 23:25 ` Peter Chen
  2 siblings, 0 replies; 6+ messages in thread
From: Peter Chen @ 2023-06-04 23:25 UTC (permalink / raw)
  To: Xu Yang; +Cc: gregkh, linux-usb, linux-imx, jun.li

On 23-05-17 16:19:05, Xu Yang wrote:
> Remove one duplicated definition of MX7D_USB_OTG_PHY_CFG1.
> 
> Signed-off-by: Li Jun <jun.li@nxp.com>
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> ---
>  drivers/usb/chipidea/usbmisc_imx.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
> index c57c1a71a513..be939e77719d 100644
> --- a/drivers/usb/chipidea/usbmisc_imx.c
> +++ b/drivers/usb/chipidea/usbmisc_imx.c
> @@ -113,7 +113,6 @@
>  #define MX7D_USBNC_USB_CTRL2_DP_DM_MASK			(BIT(12) | BIT(13) | \
>  							BIT(14) | BIT(15))
>  
> -#define MX7D_USB_OTG_PHY_CFG1		0x30
>  #define MX7D_USB_OTG_PHY_CFG2_CHRG_CHRGSEL	BIT(0)
>  #define MX7D_USB_OTG_PHY_CFG2_CHRG_VDATDETENB0	BIT(1)
>  #define MX7D_USB_OTG_PHY_CFG2_CHRG_VDATSRCENB0	BIT(2)
> -- 
> 2.34.1
> 

Acked-by: Peter Chen <peter.chen@kenrel.org>

-- 

Thanks,
Peter Chen

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

* Re: [PATCH 2/3] usb: chipidea: imx: turn off vbus comparator when suspend
  2023-05-17  8:19 ` [PATCH 2/3] usb: chipidea: imx: turn off vbus comparator when suspend Xu Yang
@ 2023-06-04 23:25   ` Peter Chen
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Chen @ 2023-06-04 23:25 UTC (permalink / raw)
  To: Xu Yang; +Cc: gregkh, linux-usb, linux-imx, jun.li

On 23-05-17 16:19:06, Xu Yang wrote:
> As we use bvalid for vbus wakeup source, to save power when
> suspend, turn off the vbus comparator for imx7d and imx8mm.
> 
> Below is this bit description from RM of iMX8MM
> "VBUS Valid Comparator Enable:
> 
> This signal controls the USB OTG PHY VBUS Valid comparator which
> indicates whether the voltage on the USB_OTG*_VBUS pin is below
> the VBUS Valid threshold. The VBUS Valid threshold is nominally
> 4.75V on this USB PHY. The VBUS Valid threshold can be adjusted
> using the USBNC_OTGn_PHY_CFG1[OTGTUNE0] bit field. Status of the
> VBUS Valid comparator, when it is enabled, is reported on the
> USBNC_OTGn_PHY_STATUS[VBUS_VLD] bit.
> When OTGDISABLE0 (USBNC_USB_OTGx_PHY_CFG2[10])is set to 1'b0 and
> DRVVBUS0 is set to 1'b1, the Bandgap circuitry and VBUS Valid
> comparator are powered, even in Suspend or Sleep mode.
> DRVVBUS0 should be reset to 1'b0 when the internal VBUS Valid comparator
> is not required, to reduce quiescent current in Suspend or Sleep mode.
>  - 0 The VBUS Valid comparator is disabled
>   - 1 The VBUS Valid comparator is enabled"
> 
> Signed-off-by: Li Jun <jun.li@nxp.com>
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> ---
>  drivers/usb/chipidea/usbmisc_imx.c | 35 ++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 
> diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
> index be939e77719d..9566022a2183 100644
> --- a/drivers/usb/chipidea/usbmisc_imx.c
> +++ b/drivers/usb/chipidea/usbmisc_imx.c
> @@ -151,6 +151,7 @@ struct usbmisc_ops {
>  	int (*charger_detection)(struct imx_usbmisc_data *data);
>  	/* It's called when system resume from usb power lost */
>  	int (*power_lost_check)(struct imx_usbmisc_data *data);
> +	void (*vbus_comparator_on)(struct imx_usbmisc_data *data, bool on);
>  };
>  
>  struct imx_usbmisc {
> @@ -874,6 +875,33 @@ static int imx7d_charger_detection(struct imx_usbmisc_data *data)
>  	return ret;
>  }
>  
> +static void usbmisc_imx7d_vbus_comparator_on(struct imx_usbmisc_data *data,
> +					     bool on)
> +{
> +	unsigned long flags;
> +	struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
> +	u32 val;
> +
> +	if (data->hsic)
> +		return;
> +
> +	spin_lock_irqsave(&usbmisc->lock, flags);
> +	/*
> +	 * Disable VBUS valid comparator when in suspend mode,
> +	 * when OTG is disabled and DRVVBUS0 is asserted case
> +	 * the Bandgap circuitry and VBUS Valid comparator are
> +	 * still powered, even in Suspend or Sleep mode.
> +	 */
> +	val = readl(usbmisc->base + MX7D_USB_OTG_PHY_CFG2);
> +	if (on)
> +		val |= MX7D_USB_OTG_PHY_CFG2_DRVVBUS0;
> +	else
> +		val &= ~MX7D_USB_OTG_PHY_CFG2_DRVVBUS0;
> +
> +	writel(val, usbmisc->base + MX7D_USB_OTG_PHY_CFG2);
> +	spin_unlock_irqrestore(&usbmisc->lock, flags);
> +}
> +
>  static int usbmisc_imx7ulp_init(struct imx_usbmisc_data *data)
>  {
>  	struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
> @@ -1017,6 +1045,7 @@ static const struct usbmisc_ops imx7d_usbmisc_ops = {
>  	.set_wakeup = usbmisc_imx7d_set_wakeup,
>  	.charger_detection = imx7d_charger_detection,
>  	.power_lost_check = usbmisc_imx7d_power_lost_check,
> +	.vbus_comparator_on = usbmisc_imx7d_vbus_comparator_on,
>  };
>  
>  static const struct usbmisc_ops imx7ulp_usbmisc_ops = {
> @@ -1131,6 +1160,9 @@ int imx_usbmisc_suspend(struct imx_usbmisc_data *data, bool wakeup)
>  
>  	usbmisc = dev_get_drvdata(data->dev);
>  
> +	if (usbmisc->ops->vbus_comparator_on)
> +		usbmisc->ops->vbus_comparator_on(data, false);
> +
>  	if (wakeup && usbmisc->ops->set_wakeup)
>  		ret = usbmisc->ops->set_wakeup(data, true);
>  	if (ret) {
> @@ -1184,6 +1216,9 @@ int imx_usbmisc_resume(struct imx_usbmisc_data *data, bool wakeup)
>  		goto hsic_set_clk_fail;
>  	}
>  
> +	if (usbmisc->ops->vbus_comparator_on)
> +		usbmisc->ops->vbus_comparator_on(data, true);
> +
>  	return 0;
>  

Acked-by: Peter Chen <peter.chen@kernel.org>

-- 

Thanks,
Peter Chen

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

* Re: [PATCH 3/3] usb: chipidea: imx: add missing USB PHY DPDM wakeup setting
  2023-05-17  8:19 ` [PATCH 3/3] usb: chipidea: imx: add missing USB PHY DPDM wakeup setting Xu Yang
@ 2023-06-04 23:27   ` Peter Chen
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Chen @ 2023-06-04 23:27 UTC (permalink / raw)
  To: Xu Yang; +Cc: gregkh, linux-usb, linux-imx, jun.li

On 23-05-17 16:19:07, Xu Yang wrote:
> USB PHY DPDM wakeup bit is enabled by default, when USB wakeup
> is not required(/sys/.../wakeup is disabled), this bit should be
> disabled, otherwise we will have unexpected wakeup if do USB device
> connect/disconnect while system sleep.
> This bit can be enabled for both host and device mode.
> 
> Signed-off-by: Li Jun <jun.li@nxp.com>
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> ---
>  drivers/usb/chipidea/usbmisc_imx.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
> index 9566022a2183..9ee9621e2ccc 100644
> --- a/drivers/usb/chipidea/usbmisc_imx.c
> +++ b/drivers/usb/chipidea/usbmisc_imx.c
> @@ -134,7 +134,7 @@
>  #define TXVREFTUNE0_MASK		(0xf << 20)
>  
>  #define MX6_USB_OTG_WAKEUP_BITS (MX6_BM_WAKEUP_ENABLE | MX6_BM_VBUS_WAKEUP | \
> -				 MX6_BM_ID_WAKEUP)
> +				 MX6_BM_ID_WAKEUP | MX6SX_BM_DPDM_WAKEUP_EN)

Acked-by: Peter Chen <peter.chen@kernel.org>

-- 

Thanks,
Peter Chen

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

end of thread, other threads:[~2023-06-04 23:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-17  8:19 [PATCH 1/3] usb: chipidea: imx: remove one duplicated reg define Xu Yang
2023-05-17  8:19 ` [PATCH 2/3] usb: chipidea: imx: turn off vbus comparator when suspend Xu Yang
2023-06-04 23:25   ` Peter Chen
2023-05-17  8:19 ` [PATCH 3/3] usb: chipidea: imx: add missing USB PHY DPDM wakeup setting Xu Yang
2023-06-04 23:27   ` Peter Chen
2023-06-04 23:25 ` [PATCH 1/3] usb: chipidea: imx: remove one duplicated reg define Peter Chen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.