Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ABF53EB64D8 for ; Wed, 21 Jun 2023 11:17:10 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1764F862FD; Wed, 21 Jun 2023 13:17:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1687346228; bh=UFYlDsBwvcp7XDuhnqAQk0g/+1oJcypY4JWv9qZxfBg=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=n0eGpkmJs1EMpf0eI/WpqTzaiPVP0lhjfP6d05PkWopVwIOBdIDq40rezvMDkrX39 QQ/nyJ2lrRSzrp6njx9sFUVsDAkD2Rr1ML2krN2/904RYJfjWJxid/D/DCVLpGaLvx pLtp5b2HI7xrmr36lhVhV/1Z/1P1MvzmPV2JF/nEGRb4CAysz6n3ccs+w5RB6qaiVQ TNimw/pAi9H43UAR8Pl8ni5xhQ2nC73UdakAK9L3hzKa+YbmXhD47qhvEvx22GDNXs E099qlhSx4dFClfwSG0FAIdbEIsjoy9AFsiQuDOhhqvA24n9f1L5mzi72qR62DSxxl z+6K20DH2Sc/w== Received: from [127.0.0.1] (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 38B858476D; Wed, 21 Jun 2023 13:17:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1687346225; bh=UFYlDsBwvcp7XDuhnqAQk0g/+1oJcypY4JWv9qZxfBg=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=RY3hxpWgzsK1e3HxGKo9CdsMaha9ewDFKE/ufrmgSYNp2d0QQxeYcaGKHkMaQDnhG kelZdpVfK42lz4OHQcwp/LVgvDvBLmxvR8E+i7GFhWPJvnt/ThOhNV8jtJPdoNzomZ QyxJO6gbdNM0MpN/hcJv+ZcBrdqOF1bQCE2k7io1V2lGyHuhM9xq8Kbe3CP/GzAEX9 dTbVxOUPsdTYt8MBeKGcp9MWa+YnFcX9y7sfod5sBYf+kOYgiDD4Ewi2S1UjM+81yz GWdqJg1RVKBCBF0MWdK+NWUWyn4OuiTvwpba6F5sZKXdXg5nzu9PO6bdXp/D9oKSQD /4z0JTwHsO4Cw== Message-ID: <48f5c04c-fe0f-ebe8-06a4-5434be3948bf@denx.de> Date: Wed, 21 Jun 2023 13:16:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v3 1/1] usb: dwc2: Fix the write to W1C fields in HPRT register Content-Language: en-US To: teik.heng.chong@intel.com, u-boot@lists.denx.de Cc: Jagan Teki , Vignesh R , Simon , Kris , Tien Fong , Kok Kiang , Raaj , Dinesh , Boon Khai , Alif , Hazim , Jit Loon Lim , Sieu Mun Tang References: <20230621031358.20462-1-teik.heng.chong@intel.com> From: Marek Vasut In-Reply-To: <20230621031358.20462-1-teik.heng.chong@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean On 6/21/23 05:13, teik.heng.chong@intel.com wrote: > From: Teik Heng Chong > > 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 > > This bug was found during the testing on Simics model. Referring to > specification DesignWare Cores USB 2.0 Hi-Speed On-The-Go (OTG) > Databook (3.30a)"5.3.4.8 Host Port Control and Status Register (HPRT)", the > HPRT.PrtPwr is cleared by this mistake. In the Linux driver (contrary to > U-Boot), HPRT is always read using dwc2_read_hprt0 helper function which > clears W1C bits. So after write back those bits are zeroes. > > Signed-off-by: Teik Heng Chong > > --- > > V2->V3 > - update commit message > --- > drivers/usb/host/dwc2.c | 34 ++++++++-------------------------- > drivers/usb/host/dwc2.h | 4 ++++ > 2 files changed, 12 insertions(+), 26 deletions(-) > > diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c > index 23060fc369..9818f9be94 100644 > --- a/drivers/usb/host/dwc2.c > +++ b/drivers/usb/host/dwc2.c > @@ -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) > diff --git a/drivers/usb/host/dwc2.h b/drivers/usb/host/dwc2.h > index a6f562fe60..6f022e33a1 100644 > --- a/drivers/usb/host/dwc2.h > +++ b/drivers/usb/host/dwc2.h > @@ -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) Applied to usb/master, thanks.