drivers: usb: host: Fix the write to W1C fields in HPRT register
PATCH 1/1 drivers: usb: host: Fix the write to W1C fields in HPRT register
From: Teik Heng Chong <[email protected]>
Fix the write to the HPRT register which treat W1C fields
as if they were mere RW. This leads to unintended clearing of such fields
--- drivers/usb/host/dwc2.c | 34 ++++++++-------------------------- drivers/usb/host/dwc2.h | 4 ++++ 2 files changed, 12 insertions(+), 26 deletions(-)
drivers/usb/host/dwc2.c +8 -26
@@ -315,9 +315,7 @@ static void dwc_otg_core_host_init(struct udevice *dev,/* Turn on the vbus power. */ if (readl (®s->gintsts) &DWC2_GINTSTS_CURMODE_HOST ) { - hprt0 =readl (®s->hprt0); - hprt0 &= ~(DWC2_HPRT0_PRTENA |DWC2_HPRT0_PRTCONNDET ); - hprt0 &= ~(DWC2_HPRT0_PRTENCHNG |DWC2_HPRT0_PRTOVRCURRCHNG ); + hprt0 =readl (®s->hprt0) & ~DWC2_HPRT0_W1C_MASK ;if (!(hprt0 &DWC2_HPRT0_PRTPWR )) { hprt0 |=DWC2_HPRT0_PRTPWR ;writel (hprt0, ®s->hprt0);
@@ -748,7 +746,7 @@ static int dwc_otg_submit_rh_msg_out(struct dwc2_priv *priv,case (USB_REQ_CLEAR_FEATURE <<8 ) |USB_RECIP_OTHER |USB_TYPE_CLASS :switch (wValue) {case USB_PORT_FEAT_C_CONNECTION : -setbits_le32 (®s->hprt0,DWC2_HPRT0_PRTCONNDET ); +clrsetbits_le32 (®s->hprt0,DWC2_HPRT0_W1C_MASK ,DWC2_HPRT0_PRTCONNDET );break ; }break ;
@@ -759,21 +757,13 @@ static int dwc_otg_submit_rh_msg_out(struct dwc2_priv *priv,break ;case USB_PORT_FEAT_RESET : -clrsetbits_le32 (®s->hprt0,DWC2_HPRT0_PRTENA | -DWC2_HPRT0_PRTCONNDET | -DWC2_HPRT0_PRTENCHNG | -DWC2_HPRT0_PRTOVRCURRCHNG , -DWC2_HPRT0_PRTRST ); +clrsetbits_le32 (®s->hprt0,DWC2_HPRT0_W1C_MASK ,DWC2_HPRT0_PRTRST );mdelay (50 ); -clrbits_le32 (®s->hprt0,DWC2_HPRT0_PRTRST ); +clrbits_le32 (®s->hprt0,DWC2_HPRT0_W1C_MASK |DWC2_HPRT0_PRTRST );break ;case USB_PORT_FEAT_POWER : -clrsetbits_le32 (®s->hprt0,DWC2_HPRT0_PRTENA | -DWC2_HPRT0_PRTCONNDET | -DWC2_HPRT0_PRTENCHNG | -DWC2_HPRT0_PRTOVRCURRCHNG , -DWC2_HPRT0_PRTRST ); +clrsetbits_le32 (®s->hprt0,DWC2_HPRT0_W1C_MASK ,DWC2_HPRT0_PRTRST );break ;case USB_PORT_FEAT_ENABLE :
@@ -1213,14 +1203,9 @@ static int dwc2_init_common(struct udevice *dev, struct dwc2_priv *priv)dwc_otg_core_host_init (dev, regs); } -clrsetbits_le32 (®s->hprt0,DWC2_HPRT0_PRTENA | -DWC2_HPRT0_PRTCONNDET |DWC2_HPRT0_PRTENCHNG | -DWC2_HPRT0_PRTOVRCURRCHNG , -DWC2_HPRT0_PRTRST ); +clrsetbits_le32 (®s->hprt0,DWC2_HPRT0_W1C_MASK ,DWC2_HPRT0_PRTRST );mdelay (50 ); -clrbits_le32 (®s->hprt0,DWC2_HPRT0_PRTENA |DWC2_HPRT0_PRTCONNDET | -DWC2_HPRT0_PRTENCHNG |DWC2_HPRT0_PRTOVRCURRCHNG | -DWC2_HPRT0_PRTRST ); +clrbits_le32 (®s->hprt0,DWC2_HPRT0_W1C_MASK |DWC2_HPRT0_PRTRST );for (i =0 ; i <MAX_DEVICE ; i++) {for (j =0 ; j <MAX_ENDPOINT ; j++) {
@@ -1246,10 +1231,7 @@ static int dwc2_init_common(struct udevice *dev, struct dwc2_priv *priv)static void dwc2_uninit_common (struct dwc2_core_regs *regs) {/* Put everything in reset. */ -clrsetbits_le32 (®s->hprt0,DWC2_HPRT0_PRTENA | -DWC2_HPRT0_PRTCONNDET |DWC2_HPRT0_PRTENCHNG | -DWC2_HPRT0_PRTOVRCURRCHNG , -DWC2_HPRT0_PRTRST ); +clrsetbits_le32 (®s->hprt0,DWC2_HPRT0_W1C_MASK ,DWC2_HPRT0_PRTRST ); }#if !CONFIG_IS_ENABLED (DM_USB )
drivers/usb/host/dwc2.h +4 -0
@@ -543,6 +543,10 @@ struct dwc2_core_regs {#define DWC2_HPRT0_PRTSPD_LOW (2 << 17)#define DWC2_HPRT0_PRTSPD_MASK (0x3 << 17)#define DWC2_HPRT0_PRTSPD_OFFSET 17 +#define DWC2_HPRT0_W1C_MASK (DWC2_HPRT0_PRTCONNDET | \ + DWC2_HPRT0_PRTENA | \ + DWC2_HPRT0_PRTENCHNG | \ + DWC2_HPRT0_PRTOVRCURRCHNG)#define DWC2_HAINT_CH0 (1 << 0)#define DWC2_HAINT_CH0_OFFSET 0#define DWC2_HAINT_CH1 (1 << 1)
Signature · 1 line
2.25.1
On 2/2/23 02:14, [email protected] wrote:
The subject tags are 'usb: dwc2:' .
Quoted 25 lines
drivers/usb/host/dwc2.c +2
-4@@ -315,9 +315,7 @@ static void dwc_otg_core_host_init(struct udevice *dev,/* Turn on the vbus power. */ if (readl (®s->gintsts) &DWC2_GINTSTS_CURMODE_HOST ) { - hprt0 =readl (®s->hprt0); - hprt0 &= ~(DWC2_HPRT0_PRTENA |DWC2_HPRT0_PRTCONNDET ); - hprt0 &= ~(DWC2_HPRT0_PRTENCHNG |DWC2_HPRT0_PRTOVRCURRCHNG ); + hprt0 =readl (®s->hprt0) & ~DWC2_HPRT0_W1C_MASK ;if (!(hprt0 &DWC2_HPRT0_PRTPWR )) { hprt0 |=DWC2_HPRT0_PRTPWR ;writel (hprt0, ®s->hprt0);@@ -748,7 +746,7 @@ static int dwc_otg_submit_rh_msg_out(struct dwc2_priv *priv,case (USB_REQ_CLEAR_FEATURE <<8 ) |USB_RECIP_OTHER |USB_TYPE_CLASS :switch (wValue) {case USB_PORT_FEAT_C_CONNECTION : -setbits_le32 (®s->hprt0,DWC2_HPRT0_PRTCONNDET ); +clrsetbits_le32 (®s->hprt0,DWC2_HPRT0_W1C_MASK ,DWC2_HPRT0_PRTCONNDET );break ; }break ;
drivers/usb/host/dwc2.c static int dwc_otg_submit_rh_msg_out(struct dwc2_priv *priv, · line 760
Quoted 9 lines
drivers/usb/host/dwc2.c +1
-5@@ -759,21 +757,13 @@ static int dwc_otg_submit_rh_msg_out(struct dwc2_priv *priv,break ;case USB_PORT_FEAT_RESET : -clrsetbits_le32 (®s->hprt0,DWC2_HPRT0_PRTENA | -DWC2_HPRT0_PRTCONNDET | -DWC2_HPRT0_PRTENCHNG | -DWC2_HPRT0_PRTOVRCURRCHNG , -DWC2_HPRT0_PRTRST ); +clrsetbits_le32 (®s->hprt0,DWC2_HPRT0_W1C_MASK ,DWC2_HPRT0_PRTRST );
The code above used to be clearing the W1C (write 1 to clear) bits , while the changed code is no longer clearing those bits. Is that correct ?
[...]
-----Original Message-----
From: Marek Vasut <[email protected]>
Sent: Thursday, 2 February, 2023 11:16 PM
To: Chong, Teik Heng <[email protected]>; [email protected]
Cc: Simon <[email protected]>; Chee, Tien Fong <[email protected]>; Hea, Kok Kiang <[email protected]>; Lim, Elly Siew Chin <[email protected]>; Kho, Sin Hui <[email protected]>; Lokanathan, Raaj <[email protected]>; Maniyam, Dinesh <[email protected]>; Ng, Boon Khai <[email protected]>; Yuslaimi, Alif Zakuan <[email protected]>; Zamri, Muhammad Hazim Izzat <[email protected]>; Lim, Jit Loon <[email protected]>; Tang, Sieu Mun <[email protected]>
Subject: Re: [PATCH] drivers: usb: host: Fix the write to W1C fields in HPRT register
On 2/2/23 02:14, [email protected] wrote:
The subject tags are 'usb: dwc2:' .
Quoted 27 lines
drivers/usb/host/dwc2.c index renamed from drivers/usb/host/dwc2.c +0
-0
23060fc369..9818f9be94100644drivers/usb/host/dwc2.c +1
-3@@ -315,9 +315,7 @@ static void dwc_otg_core_host_init(struct udevice *dev,/* Turn on the vbus power. */ if (readl(®s->gintsts) & DWC2_GINTSTS_CURMODE_HOST) { - hprt0 =readl (®s->hprt0); - hprt0 &= ~(DWC2_HPRT0_PRTENA |DWC2_HPRT0_PRTCONNDET ); - hprt0 &= ~(DWC2_HPRT0_PRTENCHNG |DWC2_HPRT0_PRTOVRCURRCHNG ); + hprt0 =readl (®s->hprt0) & ~DWC2_HPRT0_W1C_MASK ;if (!(hprt0 &DWC2_HPRT0_PRTPWR )) { hprt0 |=DWC2_HPRT0_PRTPWR ;writel(hprt0, ®s->hprt0);drivers/usb/host/dwc2.c +2
-1@@ -748,7 +746,7 @@ static int dwc_otg_submit_rh_msg_out(struct dwc2_priv *priv,case (USB_REQ_CLEAR_FEATURE <<8 ) |USB_RECIP_OTHER |USB_TYPE_CLASS :switch (wValue) {case USB_PORT_FEAT_C_CONNECTION : -setbits_le32 (®s->hprt0,DWC2_HPRT0_PRTCONNDET ); +clrsetbits_le32 (®s->hprt0,DWC2_HPRT0_W1C_MASK , +DWC2_HPRT0_PRTCONNDET );break ; }break ;
drivers/usb/host/dwc2.c static int dwc_otg_submit_rh_msg_out(struct dwc2_priv *priv, · line 761
Quoted 10 lines
drivers/usb/host/dwc2.c +2
-5@@ -759,21 +757,13 @@ static int dwc_otg_submit_rh_msg_out(struct dwc2_priv *priv,break ;case USB_PORT_FEAT_RESET : -clrsetbits_le32 (®s->hprt0,DWC2_HPRT0_PRTENA | -DWC2_HPRT0_PRTCONNDET | -DWC2_HPRT0_PRTENCHNG | -DWC2_HPRT0_PRTOVRCURRCHNG , -DWC2_HPRT0_PRTRST ); +clrsetbits_le32 (®s->hprt0,DWC2_HPRT0_W1C_MASK , +DWC2_HPRT0_PRTRST );
The code above used to be clearing the W1C (write 1 to clear) bits , while the changed code is no longer clearing those bits. Is that correct ?
yes
[...]