From patchwork Sun Dec 9 05:40:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 10719843 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 950173E9D for ; Sun, 9 Dec 2018 05:40:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87AE52A8D4 for ; Sun, 9 Dec 2018 05:40:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C00B2A8D8; Sun, 9 Dec 2018 05:40:29 +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 0806F2A8D4 for ; Sun, 9 Dec 2018 05:40:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726206AbeLIFk2 (ORCPT ); Sun, 9 Dec 2018 00:40:28 -0500 Received: from mail-eopbgr80051.outbound.protection.outlook.com ([40.107.8.51]:16469 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726097AbeLIFk1 (ORCPT ); Sun, 9 Dec 2018 00:40:27 -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=8OcLc0Sa8ZNSUgzXx8dJfAmvjR5GJUT0OdXPJ+4wXWk=; b=bHj4AnhasRq38VriqR6mWTGjQMDMUd6xzCVRWoOWKtX4Sr1yY5Eh9VpXYvo8VTdlq3WsfTmEnlKP3OYkJVEh/c2skzCmFvwCALdZtpczqFEex1m3/HbxrH5Y9Cg+BKB1Y/5NdRCLCAT3J+h10YtIOT8KvfSxRK54MGq4BtzVHG8= Received: from VI1PR04MB5327.eurprd04.prod.outlook.com (20.177.52.16) by VI1PR04MB5613.eurprd04.prod.outlook.com (20.178.125.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1404.21; Sun, 9 Dec 2018 05:40:21 +0000 Received: from VI1PR04MB5327.eurprd04.prod.outlook.com ([fe80::811d:1992:9a6a:bb3f]) by VI1PR04MB5327.eurprd04.prod.outlook.com ([fe80::811d:1992:9a6a:bb3f%5]) with mapi id 15.20.1404.025; Sun, 9 Dec 2018 05:40:21 +0000 From: Peter Chen To: "linux-usb@vger.kernel.org" CC: dl-linux-imx , "robh+dt@kernel.org" , "devicetree@vger.kernel.org" , "frieder.schrempf@exceet.de" , "festevam@gmail.com" , Peter Chen Subject: [PATCH v4 3/4] usb: chipidea: host: override ehci->hub_control Thread-Topic: [PATCH v4 3/4] usb: chipidea: host: override ehci->hub_control Thread-Index: AQHUj4GsUvCHoXHKikGp9xg7VTJwiA== Date: Sun, 9 Dec 2018 05:40:21 +0000 Message-ID: <20181209053746.24967-4-peter.chen@nxp.com> References: <20181209053746.24967-1-peter.chen@nxp.com> In-Reply-To: <20181209053746.24967-1-peter.chen@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.14.1 x-clientproxiedby: HK2PR06CA0023.apcprd06.prod.outlook.com (2603:1096:202:2e::35) To VI1PR04MB5327.eurprd04.prod.outlook.com (2603:10a6:803:60::16) authentication-results: spf=none (sender IP is ) smtp.mailfrom=peter.chen@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;VI1PR04MB5613;6:3AalMwvb+lrfd8UQKpeZMZtGGVQUBJfvVzMnIQ27JKMA/U2EFiV36Xlw/5G6Wj4NIm3EyGzIIMG86Z1j3kyAz6cQ8qamNVWsixrppGbBBSEHbxljHYwVOI3h5X6rfZevVrz3rSW1i6kF/tves/yJpe4USzekihiK9S1JGvexpA/PFw49dP9FvtGfRmu/03li6W6CGWYqirwIe9sZkc7AcWVqLyH0KFgRXHZ/WB94S7ldt6prnMoub9qZrtxiGdcb7Bs+kzFnat333T5YfUYEENsPfmpdfyIviLmBuArKDNewlqnAi83HkjzFH1L/x5gLnyWdsFpvUKhP26ur5qbFaJKHRprVODAH8v5JugyLwp6KpQnV01b/FgsYNphd83BREsvXnacNwx+rZExknURn13kQGBQCj+6zckIUlAr1NlFyC0wgXwoCK+OkApwQV7yFPyBZjopeVC6Awxousf631Q==;5:OFVgp8HwIXsFL6Zi64lxEE7xF/mvwYPZhzp6rmI948XmXh2p+m1v1xlSlZ43bhYVwGECJH+aJvAwhdQOeHUTuY96bKSgubGFvEOZxChpaemL2l4Nl40smUE0PjtoecbkMG7z4y9w273c8dg8GJ8xxukxQlAkGRbugCJ52G2Ie9M=;7:VvSwQ6tPO5Nda9aQoiOPz65G3Je1UZ2+xeHWuZ2c9MFzjzKWaqv2GUY6857PE1tf2+8uhQhPH7uzpHZP8+w+YYYVcMwX5izjn9JUFX7HOJLFUZL6B12LBFxX8+qjQHP8T2UxFmbhF8U1egezoH+82g== x-ms-office365-filtering-correlation-id: c2922b1a-d110-4487-445a-08d65d98cee6 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:VI1PR04MB5613; x-ms-traffictypediagnostic: VI1PR04MB5613: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(3231455)(999002)(944501520)(52105112)(93006095)(93001095)(6055026)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(20161123562045)(20161123564045)(201708071742011)(7699051)(76991095);SRVR:VI1PR04MB5613;BCL:0;PCL:0;RULEID:;SRVR:VI1PR04MB5613; x-forefront-prvs: 0881A7A935 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(346002)(376002)(136003)(366004)(39860400002)(199004)(189003)(53936002)(39060400002)(44832011)(3846002)(11346002)(2616005)(316002)(446003)(486006)(6512007)(186003)(476003)(8936002)(52116002)(5640700003)(6116002)(4326008)(8676002)(81156014)(66066001)(1076002)(26005)(81166006)(97736004)(478600001)(68736007)(36756003)(54906003)(551934003)(99286004)(106356001)(71190400001)(6486002)(6436002)(71200400001)(76176011)(5660300001)(50226002)(256004)(25786009)(102836004)(14444005)(2501003)(305945005)(14454004)(6506007)(386003)(6916009)(7736002)(2906002)(2351001)(86362001)(105586002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR04MB5613;H:VI1PR04MB5327.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-microsoft-antispam-message-info: B21FOIoNdhVtbaVrQvlg/qjRWnl9I3ug65s/8urt/bNtPMxPJK07VQJSrBqbTaaBAdHFlrcaLAazB9LrucdBaBHGJBTu85P30FR5X53QgNbbllcHwUtEZctgOtgNxNYivzq85vaSaINkwg+OyFO50PwG4fYd80Y716sGtsCl1Rf9Cj2WYxNEnHoWxSD44zucTJiVOnMz+fHtczsBVV+LAG7CUKe6ZFgzAmwOJ3AqXKHQF/Idm1da3szAdJLAgt61df0q0SWL5LX493bCiIwQazWUlYqD6gc0zyqnf9gL3zoTENRQWtBwQ0foOLiDK2JsA3SIx52aKypMvjFVzHBY51w8AKJwWsaxVDJovrM1gkM= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c2922b1a-d110-4487-445a-08d65d98cee6 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Dec 2018 05:40:21.1366 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5613 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 The chipidea controller has some special requirements during suspend/resume, override common ehci->hub_control to implement it. Reviewed-by: Frieder Schrempf Tested-by: Frieder Schrempf Signed-off-by: Peter Chen --- drivers/usb/chipidea/host.c | 75 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index 028a3574266a..b45ceb91c735 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c @@ -220,6 +220,80 @@ void ci_hdrc_host_destroy(struct ci_hdrc *ci) host_stop(ci); } +/* The below code is based on tegra ehci driver */ +static int ci_ehci_hub_control( + struct usb_hcd *hcd, + u16 typeReq, + u16 wValue, + u16 wIndex, + char *buf, + u16 wLength +) +{ + struct ehci_hcd *ehci = hcd_to_ehci(hcd); + u32 __iomem *status_reg; + u32 temp; + unsigned long flags; + int retval = 0; + struct device *dev = hcd->self.controller; + struct ci_hdrc *ci = dev_get_drvdata(dev); + + status_reg = &ehci->regs->port_status[(wIndex & 0xff) - 1]; + + spin_lock_irqsave(&ehci->lock, flags); + + if (typeReq == SetPortFeature && wValue == USB_PORT_FEAT_SUSPEND) { + temp = ehci_readl(ehci, status_reg); + if ((temp & PORT_PE) == 0 || (temp & PORT_RESET) != 0) { + retval = -EPIPE; + goto done; + } + + temp &= ~(PORT_RWC_BITS | PORT_WKCONN_E); + temp |= PORT_WKDISC_E | PORT_WKOC_E; + ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); + + /* + * If a transaction is in progress, there may be a delay in + * suspending the port. Poll until the port is suspended. + */ + if (ehci_handshake(ehci, status_reg, PORT_SUSPEND, + PORT_SUSPEND, 5000)) + ehci_err(ehci, "timeout waiting for SUSPEND\n"); + + if (ci->platdata->flags & CI_HDRC_IMX_IS_HSIC) { + if (ci->platdata->notify_event) + ci->platdata->notify_event(ci, + CI_HDRC_IMX_HSIC_SUSPEND_EVENT); + + temp = ehci_readl(ehci, status_reg); + temp &= ~(PORT_WKDISC_E | PORT_WKCONN_E); + ehci_writel(ehci, temp, status_reg); + } + + set_bit((wIndex & 0xff) - 1, &ehci->suspended_ports); + goto done; + } + + /* + * After resume has finished, it needs do some post resume + * operation for some SoCs. + */ + else if (typeReq == ClearPortFeature && + wValue == USB_PORT_FEAT_C_SUSPEND) { + /* Make sure the resume has finished, it should be finished */ + if (ehci_handshake(ehci, status_reg, PORT_RESUME, 0, 25000)) + ehci_err(ehci, "timeout waiting for resume\n"); + } + + spin_unlock_irqrestore(&ehci->lock, flags); + + /* Handle the hub control events here */ + return ehci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); +done: + spin_unlock_irqrestore(&ehci->lock, flags); + return retval; +} static int ci_ehci_bus_suspend(struct usb_hcd *hcd) { struct ehci_hcd *ehci = hcd_to_ehci(hcd); @@ -298,4 +372,5 @@ void ci_hdrc_host_driver_init(void) ehci_init_driver(&ci_ehci_hc_driver, &ehci_ci_overrides); orig_bus_suspend = ci_ehci_hc_driver.bus_suspend; ci_ehci_hc_driver.bus_suspend = ci_ehci_bus_suspend; + ci_ehci_hc_driver.hub_control = ci_ehci_hub_control; }