From patchwork Mon Dec 3 03:13:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 10708553 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 AA16C13AF for ; Mon, 3 Dec 2018 03:13:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A3322A958 for ; Mon, 3 Dec 2018 03:13:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DFC72A95A; Mon, 3 Dec 2018 03:13:08 +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 EBC0B2A958 for ; Mon, 3 Dec 2018 03:13:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725804AbeLCDNK (ORCPT ); Sun, 2 Dec 2018 22:13:10 -0500 Received: from mail-eopbgr30073.outbound.protection.outlook.com ([40.107.3.73]:50324 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725798AbeLCDNK (ORCPT ); Sun, 2 Dec 2018 22:13:10 -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=CbwkZGMa/y36mefS8toq0DP+bIOgNM8dJmubv/400DA=; b=o+BBaERzlvdoO74rYRJqwXRZmWb2eo06F1io7OGiLzo/fFb4bbUoknXctMJXSFfYlsWN2mfQoFBD9gh9iVPLh7LxsDwNwPAJnU0KcA6VR5OSzMO1Ho07+4f+i+QqLFJtMihtT5KjlljD0qlWlGQZcmwNBKBEeYyN2pIH8i5X0RU= Received: from VI1PR04MB5327.eurprd04.prod.outlook.com (20.177.52.16) by VI1PR04MB5198.eurprd04.prod.outlook.com (20.177.51.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1382.22; Mon, 3 Dec 2018 03:13:01 +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.1382.020; Mon, 3 Dec 2018 03:13:01 +0000 From: PETER CHEN To: "linux-usb@vger.kernel.org" CC: dl-linux-imx , PETER CHEN , stable , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , "mstarr@hedonline.com" Subject: [PATCH 1/1] usb: chipidea: imx: improve the over current handling Thread-Topic: [PATCH 1/1] usb: chipidea: imx: improve the over current handling Thread-Index: AQHUirYZXBvryAfDB0K1fwvbMmVSgg== Date: Mon, 3 Dec 2018 03:13:01 +0000 Message-ID: <20181203031037.5740-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: HK0PR03CA0015.apcprd03.prod.outlook.com (2603:1096:203:2e::27) 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;VI1PR04MB5198;6:mjiCKVAZpK5AaKX4+UB0weXKIexVdQXcwVhnMQtxRxpUTBhLBTish3Eh8jORYNNRDbY5JoUpRM1zXvU4wAiCI3mezjtJHegn9zbol3mBHZZRkrJVSm193ypbkC1u0mPk1KvPY6KqVgzmbOewiFoGF4/0j8/dSeZpFBlW2DZ2Mvicgi7edqnU2LmlQ/hv3EPKmzsOSiMpDN/ME2Xnn9nXl6Zoz6pC5WgAobkCLlDUrn7TRBt3UwmNYtUGaaNl4/JeImTG8In7sPxveYdQDXRKMATUjm8b8aJxsULCepLfCAvwDj/ARYVHz282/KC1S8AD3qm06//mzj9LvPZxZH0m5AE+nq7YeNaq2edofLjz4xdxQAFVvcRCvc6QGQ9EbrvnMdmirTyTMDc3caL/tRV3WSU9ztrM9Ppn6nAob3JoWxqUyA09OhcpEqAGCLleLAyUU2/vbMxtTvBhsq8bzTwnew==;5:91NbM/+K6XF5Suf18T8GHS7OAIx5r2yFtYEssiJETWVwiEg29mWeCgIwRsVAei+hbfwjgPN76ITM1ThTsnb5V8mwY4IGtAkUX0/jZ6H+rvSSZsMHVPICwu78/slhjqtFpJoj26Rs+wxaBcqrWbZko3n6e4R/V7bE+fQrfDSrDu0=;7:IhtSxunQQ/OV9r5f9Uw6axI5sMoDeXSZbsb5CBzNopSgP2UBoE+pMLfeivEb4uEgQRkRY7K0rBIpgg547JZ2jfUF0TR4AqBX+PmtZ/8L3ZxtnQmg7nBWibiKffDTiy2VtBDRKusYV+7EPBcEwidTLA== x-ms-office365-filtering-correlation-id: 60856846-3c93-4713-99e3-08d658cd3b41 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:VI1PR04MB5198; x-ms-traffictypediagnostic: VI1PR04MB5198: x-ld-processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(3231455)(999002)(944501493)(52105112)(10201501046)(6055026)(148016)(149066)(150057)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123564045)(201708071742011)(7699051)(76991095);SRVR:VI1PR04MB5198;BCL:0;PCL:0;RULEID:;SRVR:VI1PR04MB5198; x-forefront-prvs: 08756AC3C8 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(979002)(366004)(136003)(39860400002)(376002)(346002)(396003)(199004)(189003)(68736007)(14444005)(26005)(256004)(186003)(8936002)(6486002)(6436002)(2616005)(2906002)(52116002)(50226002)(6506007)(476003)(478600001)(102836004)(386003)(486006)(36756003)(6512007)(86362001)(53936002)(316002)(14454004)(2501003)(4326008)(5640700003)(8676002)(81156014)(81166006)(25786009)(71200400001)(66574009)(97736004)(53346004)(71190400001)(105586002)(106356001)(5660300001)(99286004)(54906003)(6916009)(6116002)(3846002)(1076002)(66066001)(2351001)(7736002)(305945005)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR04MB5198;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: ZN95xFhFsl7g83tHHBYUvXZukW895e/7QzFf8eLdclV0Teg4QSTZI9JC2a+1i4GLmICV0kEpLqH/ycPANTTGRYNZApy4cG+MSZaAfMK6tPw3SdSvEYqn7U6+eXW/2TqFy9EUw9eZ9bvSrCu0GPImKICGxB6QrLRkP6+QySaCFfNPXDzEfLtJ0pbQsiIhnEhwZrYkcOI0gTNZx1sIP5/sIe1heRwSvgImPapi6cd3daheoog/JHdEhZQ9h6nBKxEu3IoqHIa7ZOobSRwuczdOgPNUZnoPGCRyqe/1avBhod+GGKQlLPzsXjU3w/ZRjCgyPpRvQX8NeY3heSYhYjlIK+BwBNTcBi1AaEcH5JumSug= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60856846-3c93-4713-99e3-08d658cd3b41 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Dec 2018 03:13:01.1363 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5198 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 current OC (Over Current) handling does not consider the default and bootloader OC setting well, in this commit, we reset OC setting according to dts value: - If property "disable-over-current" is set, we will disable OC at code; otherwise, we will enable OC. - Since most of USB power control chips are low active for OC, we keep "over-current-active-high" property unchanging to reduce users effort. If this property is set, we set OC polarity as high explicitly; otherwise, we set it as low explicitly. Cc: stable Cc: Peter Chen Cc: Uwe Kleine-König Cc: Matthew Starr Signed-off-by: Peter Chen --- drivers/usb/chipidea/ci_hdrc_imx.c | 2 +- drivers/usb/chipidea/ci_hdrc_imx.h | 3 ++- drivers/usb/chipidea/usbmisc_imx.c | 27 ++++++++++++++++++++++----- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index 56781c329db0..058468f2de8d 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c @@ -140,7 +140,7 @@ static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev) data->disable_oc = 1; if (of_find_property(np, "over-current-active-high", NULL)) - data->oc_polarity = 1; + data->oc_polarity_high = 1; if (of_find_property(np, "external-vbus-divider", NULL)) data->evdo = 1; diff --git a/drivers/usb/chipidea/ci_hdrc_imx.h b/drivers/usb/chipidea/ci_hdrc_imx.h index fcecab478934..5ea8bb239b38 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.h +++ b/drivers/usb/chipidea/ci_hdrc_imx.h @@ -11,7 +11,8 @@ struct imx_usbmisc_data { int index; unsigned int disable_oc:1; /* over current detect disabled */ - unsigned int oc_polarity:1; /* over current polarity if oc enabled */ + /* over current polarity high if oc enabled */ + unsigned int oc_polarity_high:1; unsigned int evdo:1; /* set external vbus divider option */ unsigned int ulpi:1; /* connected to an ULPI phy */ unsigned int hsic:1; /* HSIC controlller */ diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c index 43a15a6e86f5..30d1ada952e1 100644 --- a/drivers/usb/chipidea/usbmisc_imx.c +++ b/drivers/usb/chipidea/usbmisc_imx.c @@ -135,15 +135,26 @@ static int usbmisc_imx25_init(struct imx_usbmisc_data *data) val = readl(usbmisc->base); val &= ~(MX25_OTG_SIC_MASK | MX25_OTG_PP_BIT); val |= (MX25_EHCI_INTERFACE_DIFF_UNI & MX25_EHCI_INTERFACE_MASK) << MX25_OTG_SIC_SHIFT; - val |= (MX25_OTG_PM_BIT | MX25_OTG_OCPOL_BIT); + val |= MX25_OTG_PM_BIT; + if (data->oc_polarity_high) + /* High active */ + val |= MX25_OTG_OCPOL_BIT; + else + val &= ~MX25_OTG_OCPOL_BIT; + writel(val, usbmisc->base); break; case 1: val = readl(usbmisc->base); val &= ~(MX25_H1_SIC_MASK | MX25_H1_PP_BIT | MX25_H1_IPPUE_UP_BIT); val |= (MX25_EHCI_INTERFACE_SINGLE_UNI & MX25_EHCI_INTERFACE_MASK) << MX25_H1_SIC_SHIFT; - val |= (MX25_H1_PM_BIT | MX25_H1_OCPOL_BIT | MX25_H1_TLL_BIT | + val |= (MX25_H1_PM_BIT | MX25_H1_TLL_BIT | MX25_H1_USBTE_BIT | MX25_H1_IPPUE_DOWN_BIT); + if (data->oc_polarity_high) + /* High active */ + val |= MX25_H1_OCPOL_BIT; + else + val &= ~MX25_H1_OCPOL_BIT; writel(val, usbmisc->base); @@ -356,12 +367,14 @@ static int usbmisc_imx6q_init(struct imx_usbmisc_data *data) reg = readl(usbmisc->base + data->index * 4); if (data->disable_oc) { reg |= MX6_BM_OVER_CUR_DIS; - } else if (data->oc_polarity == 1) { + } else if (data->oc_polarity_high == 1) { /* High active */ reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY); } else { - reg &= ~(MX6_BM_OVER_CUR_DIS); + reg &= ~MX6_BM_OVER_CUR_DIS; + reg |= MX6_BM_OVER_CUR_POLARITY; } + writel(reg, usbmisc->base + data->index * 4); /* SoC non-burst setting */ @@ -552,10 +565,14 @@ static int usbmisc_imx7d_init(struct imx_usbmisc_data *data) reg = readl(usbmisc->base); if (data->disable_oc) { reg |= MX6_BM_OVER_CUR_DIS; - } else if (data->oc_polarity == 1) { + } else if (data->oc_polarity_high == 1) { /* High active */ reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY); + } else { + reg &= ~MX6_BM_OVER_CUR_DIS; + reg |= MX6_BM_OVER_CUR_POLARITY; } + writel(reg, usbmisc->base); reg = readl(usbmisc->base + MX7D_USBNC_USB_CTRL2);