Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4771360yba; Wed, 10 Apr 2019 04:44:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwoIGMZq1Mkipz51B4HuRebXOYgLGhz9jiYah5X3knsl/MOEfJxr66d4ICp0Vhgz/JTHqxv X-Received: by 2002:a17:902:2a89:: with SMTP id j9mr43548198plb.272.1554896643711; Wed, 10 Apr 2019 04:44:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554896643; cv=none; d=google.com; s=arc-20160816; b=VCqUwLd8ZRBhot9zKYLGHfj651za8vPISEPEd26kjOuNQmh4rQv8TN1ETBKOqRoWHB 8xcAvmaE9JwkrVqSqsctFGQ/soOJwOHr77+VQvExygmfcQWzQubN0HrJqPw+S81NHO0Q zBwOn7Hdxd9sWgppJfBkZStWuw04kkQfSm9bjzC1WwKlY1NABIrjUXvi6BgNWaf+x4Wb e0xrFV8YdGB+NZ6uSNrDsOKj/BVJHCZMM7ukVNAWbAH+GRvIZX+UHkMHWE3YTmyVAv9F rs+4eSUuU9EwKMgYF0rLI6P/o3sgTM2+edp6DYa0WlDKlrjFADfKeZOXbajRYHtFLXKg LzXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=4zynkMfCsns+/mIKPUxlc5A89I9aL7xUDpAfSkNX77o=; b=eRs9mAJEG8ASKDq+Cnln14rqF1+Ed+nWdrgPirZuOUaJZEDniqCShWjCHmHNwUlkO/ 9gwgheBAnTF1QfQQP4BJyZDrpXUQODKqO17ArUDzeX5aVlkdLgW9DsbfQKTpc/6ltJE8 pBwe2jQS/RlIpgEyNDkpdwOJ76SP4c3BXfVr/QLsAvXoqT1qqqXQuYjqdgFR3JLhwFxn /S7sO4Onk9UTZbbo36230sqIYwFNPy4jM8y2WhmTPkvbtZpk1oxYPRdkoqxAmPzTgSqW 8cb2NJrYgc5ueQeJJoz6lptxGvjP1u/Aw3n0DK5/UN1m/bMXLh+O2SiJggiZ9iOhTRIB 74Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=eIf49my9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t26si5586183pgu.327.2019.04.10.04.43.47; Wed, 10 Apr 2019 04:44:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=eIf49my9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729979AbfDJJlG (ORCPT + 99 others); Wed, 10 Apr 2019 05:41:06 -0400 Received: from mail-eopbgr70054.outbound.protection.outlook.com ([40.107.7.54]:53373 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726699AbfDJJlF (ORCPT ); Wed, 10 Apr 2019 05:41:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4zynkMfCsns+/mIKPUxlc5A89I9aL7xUDpAfSkNX77o=; b=eIf49my9oiO8Uv4y9385jtftawXTEghX2EVgqeeZPBRkCE1Sk4CEu8/eEljN+rqkoqrsIMrdz4DgGeBGYBgS3BIrnSrMmvVh/UoQe0Bz5pYRakdzigSLoozh3y4UMn/GPbFb38JLAR0fqGZF15uG4nfgXFiXFHOfjAknV71XbY8= Received: from AM5PR0402MB2865.eurprd04.prod.outlook.com (10.175.41.148) by AM5PR0402MB2836.eurprd04.prod.outlook.com (10.175.41.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1771.16; Wed, 10 Apr 2019 09:40:59 +0000 Received: from AM5PR0402MB2865.eurprd04.prod.outlook.com ([fe80::d017:34d9:4a70:bb8]) by AM5PR0402MB2865.eurprd04.prod.outlook.com ([fe80::d017:34d9:4a70:bb8%11]) with mapi id 15.20.1771.016; Wed, 10 Apr 2019 09:40:59 +0000 From: Ran Wang To: Greg Kroah-Hartman , Rob Herring , Mark Rutland , Felipe Balbi CC: "linux-usb@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Yang Li Subject: RE: [PATCH v3 2/2] usb: dwc3: Add workaround for host mode VBUS glitch when boot Thread-Topic: [PATCH v3 2/2] usb: dwc3: Add workaround for host mode VBUS glitch when boot Thread-Index: AQHUzaDPFcJ4hglFSU2evLYpi8IQf6Y1ZsZg Date: Wed, 10 Apr 2019 09:40:59 +0000 Message-ID: References: <20190226070016.27372-1-ran.wang_1@nxp.com> <20190226070016.27372-2-ran.wang_1@nxp.com> In-Reply-To: <20190226070016.27372-2-ran.wang_1@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=ran.wang_1@nxp.com; x-originating-ip: [92.121.36.198] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4b8231df-ff1e-415d-8170-08d6bd98a3b1 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600139)(711020)(4605104)(4618075)(2017052603328)(7193020);SRVR:AM5PR0402MB2836; x-ms-traffictypediagnostic: AM5PR0402MB2836: x-microsoft-antispam-prvs: x-forefront-prvs: 00032065B2 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(136003)(396003)(366004)(376002)(39860400002)(346002)(199004)(189003)(256004)(110136005)(81166006)(76176011)(8936002)(6246003)(6436002)(229853002)(316002)(97736004)(4326008)(8676002)(6506007)(102836004)(33656002)(53546011)(81156014)(186003)(53936002)(74316002)(25786009)(305945005)(7736002)(99286004)(54906003)(52536014)(106356001)(105586002)(2906002)(446003)(5660300002)(68736007)(476003)(6116002)(11346002)(7696005)(3846002)(26005)(71190400001)(508600001)(14454004)(71200400001)(86362001)(66066001)(9686003)(55016002)(486006);DIR:OUT;SFP:1101;SCL:1;SRVR:AM5PR0402MB2836;H:AM5PR0402MB2865.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: ybnTwflFy7MXfZXbXkr4naMygbeVscgfOOikAWUex86PScQm0QIhL5Vy91rJLkl4vfmwvgtO+ugXMzaffyR1hXGpEg2bAf2iu8qT+WLQJpeGL/1qCsbtkUA3R+L2gQmFxIQ9XOplgrwuh1uCZe1y8xH2GfFv9qazgehCcr+3o9lgFm9ar9ePetMCoJtbN1hbq33HYaEJEEe5baFb6lhfjNE+hPLm+k6TI+3B39H4HrRQe7yNs4PnnSOtviVu5of+f96m7yDBHwwJ2gRA+5r7A12c9QZgMhiKlS61W04YLTQuy9voZ2+j4TkENDEPyC2gdLA5sKBAA3aDENZrBGsJiCqX9vxWDPXT99e1nz5qN8FcSOLnXacs41OTRhQY+Mg6gsKqUmtMq+xKq9JWUfhTL4G0ltUaNuY7cskVw5k93dY= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4b8231df-ff1e-415d-8170-08d6bd98a3b1 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Apr 2019 09:40:59.6900 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0402MB2836 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Sirs, May I have your comment on this version patch, please? Thanks. Regards, Ran On Tuesday, February 26, 2019 14:59, Ran Wang wrote: > When DWC3 is set to host mode by programming register DWC3_GCTL, VBUS > (or its control signal) will be turned on immediately on related Root Hub= ports. > Then, the VBUS is turned off for a little while(15us) when do xhci reset > (conducted by xhci driver) and back to normal finally, we can observe a n= egative > glitch of related signal happen. >=20 > This VBUS glitch might cause some USB devices enumeration fail if kernel = boot > with them connected. Such as LS1012AFWRY/LS1043ARDB/LX2160AQDS > /LS1088ARDB with Kingston 16GB USB2.0/Kingston USB3.0/JetFlash Transcend > 4GB USB2.0 drives. The fail cases include enumerated as full-speed device= or > report wrong device descriptor, etc. >=20 > One SW workaround which can fix this is by programing all xhci PORTSC[PP]= to 0 > to turn off VBUS immediately after setting host mode in DWC3 driver (per = signal > measurement result, it will be too late to do it in xhci-plat.c or xhci.c= ). Then, > after xhci reset complete in xhci driver, PORTSC[PP]s' value will back to= 1 > automatically and VBUS on at that time, no glitch happen and normal > enumeration process has no impact. >=20 > Signed-off-by: Ran Wang > --- > Changes in v3: > - Add macro PORT_REGS_SIZE to replace 0x10 > - Change initial value of i to 0 for the for loop > - Cosmetic changes >=20 > Changes in v2: > - Rename related property to 'snps,host-vbus-glitches' > - Rename related dwc member to 'host_vbus_glitches' > - Add member 'host_vbus_glitches' description in 'dwc3' >=20 > drivers/usb/dwc3/core.c | 48 > +++++++++++++++++++++++++++++++++++++++++++++++ > drivers/usb/dwc3/core.h | 12 +++++++++++ > 2 files changed, 60 insertions(+), 0 deletions(-) >=20 > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index > a1b126f..dd80e3d 100644 > --- a/drivers/usb/dwc3/core.c > +++ b/drivers/usb/dwc3/core.c > @@ -100,6 +100,42 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc) > return 0; > } >=20 > +/* > + * dwc3_power_of_all_roothub_ports - Power off all Root hub ports > + * @dwc3: Pointer to our controller context structure */ static void > +dwc3_power_off_all_roothub_ports(struct dwc3 *dwc) { > + int i, port_num; > + u32 reg, op_regs_base, offset; > + void __iomem *xhci_regs; > + > + /* xhci regs is not mapped yet, do it temperary here */ > + if (dwc->xhci_resources[0].start) { > + xhci_regs =3D ioremap(dwc->xhci_resources[0].start, > + DWC3_XHCI_REGS_END); > + if (IS_ERR(xhci_regs)) { > + dev_err(dwc->dev, "Failed to ioremap xhci_regs\n"); > + return; > + } > + > + op_regs_base =3D HC_LENGTH(readl(xhci_regs)); > + reg =3D readl(xhci_regs + XHCI_HCSPARAMS1); > + port_num =3D HCS_MAX_PORTS(reg); > + > + for (i =3D 0; i < port_num; i++) { > + offset =3D op_regs_base + XHCI_PORTSC_BASE + > + PORT_REGS_SIZE * i; > + reg =3D readl(xhci_regs + offset); > + reg &=3D ~PORT_POWER; > + writel(reg, xhci_regs + offset); > + } > + > + iounmap(xhci_regs); > + } else > + dev_err(dwc->dev, "xhci base reg invalid\n"); } > + > void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode) { > u32 reg; > @@ -109,6 +145,15 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode) > reg |=3D DWC3_GCTL_PRTCAPDIR(mode); > dwc3_writel(dwc->regs, DWC3_GCTL, reg); >=20 > + /* > + * We have to power off all Root hub ports immediately after DWC3 set > + * to host mode to avoid VBUS glitch happen when xhci get reset later. > + */ > + if (dwc->host_vbus_glitches) { > + if (mode =3D=3D DWC3_GCTL_PRTCAP_HOST) > + dwc3_power_off_all_roothub_ports(dwc); > + } > + > dwc->current_dr_role =3D mode; > } >=20 > @@ -1306,6 +1351,9 @@ static void dwc3_get_properties(struct dwc3 *dwc) > dwc->dis_metastability_quirk =3D device_property_read_bool(dev, > "snps,dis_metastability_quirk"); >=20 > + dwc->host_vbus_glitches =3D device_property_read_bool(dev, > + "snps,host-vbus-glitches"); > + > dwc->lpm_nyet_threshold =3D lpm_nyet_threshold; > dwc->tx_de_emphasis =3D tx_de_emphasis; >=20 > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index > df87641..c2dee0b 100644 > --- a/drivers/usb/dwc3/core.h > +++ b/drivers/usb/dwc3/core.h > @@ -606,6 +606,15 @@ > #define DWC3_OSTS_VBUSVLD BIT(1) > #define DWC3_OSTS_CONIDSTS BIT(0) >=20 > +/* Partial XHCI Register and Bit fields for quirk */ > +#define XHCI_HCSPARAMS1 0x4 > +#define XHCI_PORTSC_BASE 0x400 > +#define PORT_REGS_SIZE 0x10 > +#define PORT_POWER (1 << 9) > +#define HCS_MAX_PORTS(p) (((p) >> 24) & 0x7f) > +#define XHCI_HC_LENGTH(p) (((p)>>00)&0x00ff) > +#define HC_LENGTH(p) XHCI_HC_LENGTH(p) > + > /* Structures */ >=20 > struct dwc3_trb; > @@ -1024,6 +1033,8 @@ struct dwc3_scratchpad_array { > * 2 - No de-emphasis > * 3 - Reserved > * @dis_metastability_quirk: set to disable metastability quirk. > + * @host-vbus-glitches: set to avoid vbus glitch during > + * xhci reset. > * @imod_interval: set the interrupt moderation interval in 250ns > * increments or 0 to disable. > */ > @@ -1209,6 +1220,7 @@ struct dwc3 { > unsigned tx_de_emphasis:2; >=20 > unsigned dis_metastability_quirk:1; > + unsigned host_vbus_glitches:1; >=20 > u16 imod_interval; > }; > -- > 1.7.1