From patchwork Wed Jan 16 06:48:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ran Wang X-Patchwork-Id: 10765451 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 260A11390 for ; Wed, 16 Jan 2019 06:48:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FAF52AE1C for ; Wed, 16 Jan 2019 06:48:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01BFB2AE2E; Wed, 16 Jan 2019 06:48:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A6B72AE1C for ; Wed, 16 Jan 2019 06:48:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388107AbfAPGsM (ORCPT ); Wed, 16 Jan 2019 01:48:12 -0500 Received: from mail-eopbgr10086.outbound.protection.outlook.com ([40.107.1.86]:46048 "EHLO EUR02-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388079AbfAPGsL (ORCPT ); Wed, 16 Jan 2019 01:48:11 -0500 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=jW9CAzB5jiiTi6Zgpp8pIkCsKP4et98is9UFOIhHCp0=; b=SpjB51qxTukabhqfuGJzukjpGT38pd9T8V6vtKHmmyHW4EgYoXoilqOKzYaqAMzB2gPwcqrfu85cJ4NUVmPqvNzXP/ciwaR59utvgX+3rEifFI/VQBfKuyMTHPtsy6tmWmlYcRulX3raQ9QYhqqToVAfCJSpeUJeV4kARTZBT3E= Received: from AM5PR0402MB2865.eurprd04.prod.outlook.com (10.175.41.148) by AM5PR0402MB2785.eurprd04.prod.outlook.com (10.175.41.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1537.26; Wed, 16 Jan 2019 06:48:06 +0000 Received: from AM5PR0402MB2865.eurprd04.prod.outlook.com ([fe80::1c0c:51da:f585:5626]) by AM5PR0402MB2865.eurprd04.prod.outlook.com ([fe80::1c0c:51da:f585:5626%2]) with mapi id 15.20.1537.018; Wed, 16 Jan 2019 06:48:06 +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" , Ran Wang Subject: [PATCH 1/2] usb: dwc3: Add avoiding vbus glitch happen during xhci reset Thread-Topic: [PATCH 1/2] usb: dwc3: Add avoiding vbus glitch happen during xhci reset Thread-Index: AQHUrWdviEVntsRQzEWnqfJhKWO2IA== Date: Wed, 16 Jan 2019 06:48:06 +0000 Message-ID: <20190116064820.20007-2-ran.wang_1@nxp.com> References: <20190116064820.20007-1-ran.wang_1@nxp.com> In-Reply-To: <20190116064820.20007-1-ran.wang_1@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HK0PR03CA0077.apcprd03.prod.outlook.com (2603:1096:203:72::17) To AM5PR0402MB2865.eurprd04.prod.outlook.com (2603:10a6:203:99::20) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ran.wang_1@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [119.31.174.73] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;AM5PR0402MB2785;6:8pxTbHtYvbIYazLCuydAm9wdfhellWxSzW4j1odnbv7G0Fr4S4T8pmZGC5/IR89NPMVsawtznDZF/8IMXRngbgyUeWAVCBt6z/JxmDSONjXzs8J0i40zalQPtsUEMNVXoI6UG9SDAWe3rkQzZbzZ3BDzMKYehH4rY3Tw6iYbrZsXgm2itZx75gyLW811C7L8fXAYHvSZjYW+Mc6RKOOtvJBETwfTvALkpyGlhB3N3ndJs+ksMwBXWTo9KAXo/wQueigJvpKmbLtM/fwRXHu3DunSkbBq+LqH0cSab0STyKhaOQK5dv6P2ppJuqLuINpSSoQBwm3lwIRDNjddSIsourbp6JEyEs8B1PZl+rRv3bDkKWglNxEVP1aOWPwG1XE/8M1k9bRHYxH3OrUjRU6OLNhjC0AdOkZxA48Wk+8I26a364lqLJMAo/3Q1mzr0QgiBLokC6If9cqARRlva4UVUw==;5:1n7Bbi43EzcC/g1OYh0UBf3r6CqPZ0N8cAdWZ/FqiCrwqjSzuIdBZn1EHd7fLr/PY0ceDTvPY8IPU1dXLJfSazjX5vOD1i5tXTUzruIpaRDVAq9zqi6SoptGhaHFCv/prmEXOYZwC4CEmjagJtdBSrOwL+9CKzdT+CLFQP1t0/dZoNNiuB9x5dGBz9Cvqzghxo+gcs16/1YtL3bGHb6HlQ==;7:K9wzRy12QLmZVm2jTqB+ts8//HadL+81Tp36I65ZgFih9avz6jRWlYUQTEve/EKeGBAEoB/XfEQopnB9bvyemtJ8GsdcxcZ2J0WoLgf9rPF2ZIcWqyF/JFt3etuXiV/qaO99N9pWjsxxh56ytTKSRw== x-ms-office365-filtering-correlation-id: ad8cae19-7fac-4159-e004-08d67b7e91d9 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:AM5PR0402MB2785; x-ms-traffictypediagnostic: AM5PR0402MB2785: x-microsoft-antispam-prvs: x-forefront-prvs: 091949432C x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39860400002)(396003)(136003)(376002)(346002)(366004)(189003)(199004)(106356001)(105586002)(5660300001)(99286004)(6436002)(6486002)(6512007)(52116002)(76176011)(316002)(54906003)(110136005)(486006)(446003)(11346002)(2616005)(476003)(36756003)(186003)(1076003)(71200400001)(71190400001)(25786009)(4326008)(256004)(386003)(102836004)(26005)(6506007)(66066001)(53936002)(97736004)(86362001)(68736007)(478600001)(14454004)(50226002)(7736002)(2906002)(305945005)(6116002)(3846002)(8936002)(81166006)(8676002)(81156014);DIR:OUT;SFP:1101;SCL:1;SRVR:AM5PR0402MB2785;H:AM5PR0402MB2865.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A: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: UlGxOIYJ8R297czHfLTuFu+NbM+Nqc1UZsODiKacU7/uGArrLtZMwPLrETVcNKuUy77wwOR6ZiVe3hi2PggQgikH1mBth6bGKqH2OhrbM/MqS1nE8hgsySvm5C/ieg9YiaN1wZziZWhGRNwm1R+0o88jX5bag4ZRtzDbTZcheRfb6LSdgv2MpZNVk634HcDC7Gbf0oUTv5T3u8WnBqSdnyCatXkfmoVF+twU4txOv8CyNLkuul2CJP4DN8Q51Ghei4pL3vqY52DStcsShSB4yLE3MpXpVldWUTdaY7AkzklpmrhN/S917ibPwMqtlI2Qp72YH6lryahyP+S3hu1wr7QGwg1hIG4V31nJQeq0ZV0jZamjRHSg/KN4KXVwCzgciwj1TJEHp6+QAxZriMz4+tyMuutKymROJnQzTc/oGDA= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ad8cae19-7fac-4159-e004-08d67b7e91d9 X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Jan 2019 06:48:03.4331 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0402MB2785 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When DWC3 is set to host mode by programming register DWC3_GCTL, VUBS (or its control signal) will on immediately on related Root Hub ports. Then the VUBS will be de-asserted for a little while during xhci reset (conducted by xhci driver) for a little while and back to normal. This VBUS glitch might cause some USB devices emuration fail if kernel boot with them connected. One SW workaround which can fix this is to program all 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). Signed-off-by: Ran Wang --- Documentation/devicetree/bindings/usb/dwc3.txt | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt b/Documentation/devicetree/bindings/usb/dwc3.txt index 8e5265e..dadb530 100644 --- a/Documentation/devicetree/bindings/usb/dwc3.txt +++ b/Documentation/devicetree/bindings/usb/dwc3.txt @@ -106,6 +106,9 @@ Optional properties: When just one value, which means INCRX burst mode enabled. When more than one value, which means undefined length INCR burst type enabled. The values can be 1, 4, 8, 16, 32, 64, 128 and 256. + - snps,avoid-vbus-glitch-when-set-host: Power off all Root Hub ports immediately + after setting host mode to avoid vbus (negative) glitch happen in later + xhci reset. And the vbus will back to 5V automatically when reset done. - in addition all properties from usb-xhci.txt from the current directory are supported as well From patchwork Wed Jan 16 06:48:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ran Wang X-Patchwork-Id: 10765449 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F13691390 for ; Wed, 16 Jan 2019 06:48:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D79A32AE1C for ; Wed, 16 Jan 2019 06:48:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBF652AE2E; Wed, 16 Jan 2019 06:48:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F21A2AE1C for ; Wed, 16 Jan 2019 06:48:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388133AbfAPGsQ (ORCPT ); Wed, 16 Jan 2019 01:48:16 -0500 Received: from mail-eopbgr10086.outbound.protection.outlook.com ([40.107.1.86]:46048 "EHLO EUR02-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728367AbfAPGsO (ORCPT ); Wed, 16 Jan 2019 01:48:14 -0500 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=cX+kK5GdLq7GvxWkkLSXF8AZKbQROjISI9E+V2lw6Co=; b=jdZYwS2iRcA3t9e8K/bo4afGk5iSzOdgpnyNrY9zUwSdBs7fyn91XcCgSXqeiWpEkzNhTqWgxMGBIHpEjsumuRyOpyB1FQm23OUYOKbs453Hs/pYu4L9jG5UuVfXT3PcDY8i6t+EWorXMUmsj2RLFB/Uin8f5ocIlmd15F3zntY= Received: from AM5PR0402MB2865.eurprd04.prod.outlook.com (10.175.41.148) by AM5PR0402MB2785.eurprd04.prod.outlook.com (10.175.41.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1537.26; Wed, 16 Jan 2019 06:48:10 +0000 Received: from AM5PR0402MB2865.eurprd04.prod.outlook.com ([fe80::1c0c:51da:f585:5626]) by AM5PR0402MB2865.eurprd04.prod.outlook.com ([fe80::1c0c:51da:f585:5626%2]) with mapi id 15.20.1537.018; Wed, 16 Jan 2019 06:48:09 +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" , Ran Wang Subject: [PATCH 2/2] usb: dwc3: Add workaround for host mode VBUS glitch when boot Thread-Topic: [PATCH 2/2] usb: dwc3: Add workaround for host mode VBUS glitch when boot Thread-Index: AQHUrWdx3CIJLXThzk+kTWUVQ+nAhw== Date: Wed, 16 Jan 2019 06:48:09 +0000 Message-ID: <20190116064820.20007-3-ran.wang_1@nxp.com> References: <20190116064820.20007-1-ran.wang_1@nxp.com> In-Reply-To: <20190116064820.20007-1-ran.wang_1@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HK0PR03CA0077.apcprd03.prod.outlook.com (2603:1096:203:72::17) To AM5PR0402MB2865.eurprd04.prod.outlook.com (2603:10a6:203:99::20) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ran.wang_1@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [119.31.174.73] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;AM5PR0402MB2785;6:0iABeXupRRQxDEqSnEDDaDf3/YljM3KlgoqY51I5dB2HesQoLf0gdyulFfqvYUsjpvsenKGRM7LG9jfPCzz0kR+ClaFM3NSc3MfRcOZIcRVKNJKfc6FLSw9A8zC9VFav9a0qLhjJ44G3EhuKULzstr8me6sooXnenb8P9ZYof6E2gcmap9eFB42UQ3pELk+4/ZLlbrFMzcS/VwuZxytKfTdBjvIE/BoKaURMEEDFizGnlnXdoaWVcnCF50mrKStAJJk2qNZMDgQnrrSHlMsJT+MVSMdb7AC/74C7qgsD9OxXI5zB6MYIA4PK4HQ9oYqYLgMb54SNrQqJn5ppfRPrCZx5z+2/HH+9K+PbmKkSx1uRU9DpmknoUpSWZZAZV4CFmhy3N1oVUsGvf2F8aI0wjnSMgfxWOl6KOs4EJuMel9GkGFv74XRLte7/mUQfQYjGLw5wfl+4KKKiJsUAt9FV+Q==;5:xRRHUam6txv03TKq21ZK1sLuiTFPigi3rF6av5Q3t6lCUKUGji05Y412cPfugMYUADaoxBykNdGQIr7agEuNWQXp+OVAOQ3Fak74IdJIhpTaQzalQrj9FcIYiIjGYQjh39JXXi0ctNSUoR7Ik1pid0cVKYzIz2r3Tct4N79xeN6fvsHUhkO4XsDnr1yzOlebJeqS/BqtfVgTVP6HbwDB6w==;7:Nn/FAiS645cIhzmEbSVwoiYrF1dosE+pmxykkoGVDDxPwavCScbyVClSDcZ/+SZRevmhEX60or8a4MR1EIsRIeXXEeSD0gCU28lqLqgGnfvj955P1XgUWWozx/Ad4QFJM8/iKG1jc3jrPXr3GulDrA== x-ms-office365-filtering-correlation-id: 8a1d47b0-47bc-4fd7-ea00-08d67b7e93db x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:AM5PR0402MB2785; x-ms-traffictypediagnostic: AM5PR0402MB2785: x-microsoft-antispam-prvs: x-forefront-prvs: 091949432C x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39860400002)(396003)(136003)(376002)(346002)(366004)(189003)(199004)(106356001)(105586002)(5660300001)(99286004)(6436002)(6486002)(6512007)(52116002)(76176011)(316002)(54906003)(110136005)(486006)(446003)(11346002)(2616005)(476003)(36756003)(186003)(1076003)(71200400001)(71190400001)(25786009)(4326008)(256004)(386003)(102836004)(26005)(6506007)(66066001)(53936002)(97736004)(86362001)(68736007)(478600001)(14454004)(50226002)(7736002)(2906002)(305945005)(6116002)(3846002)(8936002)(81166006)(8676002)(81156014);DIR:OUT;SFP:1101;SCL:1;SRVR:AM5PR0402MB2785;H:AM5PR0402MB2865.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A: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: 2cTTEWPH/whbBNBeeCvqb/pcDxkd3b6QMmBhYRrFrYaqGGbpkzu8zC/iPRfCx7Ojm4eaYtWHnbbgKKla+pXrkwqSR7AsuAEVp3LpwQMtIJlffJxTOTUoAwzvcuEHkPdUXaqIiqJtB2QHO29Sp2e2dIQ5fiAbhYAoYled9zNU/ovSMa7n+Qtx+k2qdbaT6nS2lvvxadFvOqEhdxIZEjpIU+yUSsTPALh+Fmm4I9KCQmuKWw3Mv0RM23zfqO0wt00X2dppQ8IcgAGnqFYHxKYd4Bz/xp1JH70U540rE8V8hRRpRrDMUh+b7+YTd/k0/RygED+fKHRNthIZY8fYEGp76tAreceyRdgAfyweM6PCXnKPFPueh30Qk/uw6h+2zeQ/DHlnbMBcZmhpcu1msDKKHFIRD0mX+Nqd2s5vzGXmlQs= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a1d47b0-47bc-4fd7-ea00-08d67b7e93db X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Jan 2019 06:48:06.8059 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0402MB2785 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When DWC3 is set to host mode by programming register DWC3_GCTL, VUBS (or its control signal) will be turned on immediately on related Root Hub ports. Then, the VUBS is turned off for a little while(15us) when do xhci reset (conducted by xhci driver) and back to normal finally, we can observed a negative glitch of related signal from scope. 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. One SW workaround which can fix this is to program 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. Signed-off-by: Ran Wang --- drivers/usb/dwc3/core.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/usb/dwc3/core.h | 10 +++++++++- 2 files changed, 56 insertions(+), 1 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index a1b126f..1508397 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -100,6 +100,41 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc) return 0; } +/* + * 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 = 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 = HC_LENGTH(readl(xhci_regs)); + reg = readl(xhci_regs + XHCI_HCSPARAMS1); + port_num = HCS_MAX_PORTS(reg); + + for (i = 1; i <= port_num; i++) { + offset = op_regs_base + XHCI_PORTSC_BASE + 0x10*(i-1); + reg = readl(xhci_regs + offset); + reg &= ~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 +144,15 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode) reg |= DWC3_GCTL_PRTCAPDIR(mode); dwc3_writel(dwc->regs, DWC3_GCTL, reg); + /* + * 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->avoid_vbus_glitch_when_set_host) { + if (mode == DWC3_GCTL_PRTCAP_HOST) + dwc3_power_off_all_roothub_ports(dwc); + } + dwc->current_dr_role = mode; } @@ -1306,6 +1350,9 @@ static void dwc3_get_properties(struct dwc3 *dwc) dwc->dis_metastability_quirk = device_property_read_bool(dev, "snps,dis_metastability_quirk"); + dwc->avoid_vbus_glitch_when_set_host = device_property_read_bool(dev, + "snps,avoid-vbus-glitch-when-set-host"); + dwc->lpm_nyet_threshold = lpm_nyet_threshold; dwc->tx_de_emphasis = tx_de_emphasis; diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index df87641..691093b 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -606,6 +606,14 @@ #define DWC3_OSTS_VBUSVLD BIT(1) #define DWC3_OSTS_CONIDSTS BIT(0) +/* Partial XHCI Register and Bit fields for quirk */ +#define XHCI_HCSPARAMS1 0x4 +#define XHCI_PORTSC_BASE 0x400 +#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 */ struct dwc3_trb; @@ -1209,6 +1217,7 @@ struct dwc3 { unsigned tx_de_emphasis:2; unsigned dis_metastability_quirk:1; + unsigned avoid_vbus_glitch_when_set_host:1; u16 imod_interval; }; @@ -1217,7 +1226,6 @@ struct dwc3 { #define INCRX_UNDEF_LENGTH_BURST_MODE 1 #define work_to_dwc(w) (container_of((w), struct dwc3, drd_work)) - /* -------------------------------------------------------------------------- */ struct dwc3_event_type {