From patchwork Fri Nov 30 20:53:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 1006187 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gcxfk5iz"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4366776Lcjz9s47 for ; Sat, 1 Dec 2018 07:53:39 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=gPWa8VpOTtt/QX3bBuDrEHJtErPpBgOAcu419LUkoNo=; b=gcxfk5izcvZX1W i98myLWG1T0S+Qe7/31ccknD6jsjE+xcG1cXR39btx51VbukAet4e0m+xSyj0wBEwuAw7ACWXp7im MRwg3AN5RSLQ8qJkI7Hkj2TskS8s3MGvsA1+VQuxzOoCinjiMWMA9878iNGQrGbBG8afvdgwXxHta y6lyrLqMDvBb3jJ8B1QgUOgeLLiKarxT0h9YfvUkuVDdBugFRIkWrYc04wJEvQGsPNzH02Y7+ltNJ F6lbtUuyeGXyNXoK/zclF+maM9aidux4zsMLKeuw3uvFLX3K3cHxu1Nr+xNIqDenLRE0mwEmqXK8D /BeouXBR5+igbeVZxfrA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSpn2-00050O-UH; Fri, 30 Nov 2018 20:53:32 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSpmy-0004z6-JB for linux-arm-kernel@lists.infradead.org; Fri, 30 Nov 2018 20:53:30 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gSpmj-0005mp-Rm; Fri, 30 Nov 2018 21:53:13 +0100 Received: from ukl by dude.hi.pengutronix.de with local (Exim 4.91) (envelope-from ) id 1gSpmj-0004uL-2d; Fri, 30 Nov 2018 21:53:13 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Peter Chen , Shawn Guo Subject: [PATCH] usb: chipidea: imx: unify over-current polarity handling Date: Fri, 30 Nov 2018 21:53:09 +0100 Message-Id: <20181130205309.17232-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181130_125328_803863_A1ED61BB X-CRM114-Status: GOOD ( 18.00 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2001:67c:670:201:290:27ff:fe1d:cc33 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fabio Estevam , linux-usb@vger.kernel.org, kernel@pengutronix.de, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org The status quo is: - on i.MX25 the overcurrent polarity is always explicitly configured as active high which matches the reset default. - on i.MX6 and i.MX7 the overcurrent polarity is active high after reset. usbmisc_imx6q_init() and usbmisc_imx7d_init() keep the current state (probably as setup by the bootloader or still the reset default) unless the polarity is explicitly configured as active high which then is configured. (So if the pin is active low and the bootloader didn't set this up the configuration is wrong.) To improve the situation always configure the reset default value unless the device tree configures the polarity (and then use this one). Note that as the reset default is active high on all platforms there is no need to check for the presence of "over-current-active-high". In the absence of "over-current-active-low" it doesn't matter if active high is configured because that's the default or because it is configured explicitly. Signed-off-by: Uwe Kleine-König --- .../devicetree/bindings/usb/ci-hdrc-usb2.txt | 1 + drivers/usb/chipidea/ci_hdrc_imx.c | 9 ++++- drivers/usb/chipidea/ci_hdrc_imx.h | 4 +- drivers/usb/chipidea/usbmisc_imx.c | 39 +++++++++++++++++-- 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt b/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt index 0e03344e2e8b..b733b7c4bfdc 100644 --- a/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt +++ b/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt @@ -83,6 +83,7 @@ i.mx specific properties - disable-over-current: disable over current detect - over-current-active-high: over current signal polarity is high active, typically over current signal polarity is low active. +- over-current-active-low: over current signal polarity is low active. - external-vbus-divider: enables off-chip resistor divider for Vbus Example: diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index 5f4a8157fad8..352bd0bfe161 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c @@ -141,8 +141,13 @@ static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev) if (of_find_property(np, "disable-over-current", NULL)) data->disable_oc = 1; - if (of_find_property(np, "over-current-active-high", NULL)) - data->oc_polarity = 1; + /* + * No need to check for "over-current-active-high" as this is the reset + * default for all platforms and this is configured unless "active-low" + * is specified. + */ + if (of_find_property(np, "over-current-active-low", NULL)) + data->oc_polarity_low = 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 d666c9f036ba..dffa34f3777d 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.h +++ b/drivers/usb/chipidea/ci_hdrc_imx.h @@ -17,7 +17,9 @@ 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 low if oc enabled */ + unsigned int oc_polarity_low:1; + unsigned int evdo:1; /* set external vbus divider option */ unsigned int ulpi:1; /* connected to an ULPI phy */ }; diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c index 9f4a0185dd60..89c1a0c48f80 100644 --- a/drivers/usb/chipidea/usbmisc_imx.c +++ b/drivers/usb/chipidea/usbmisc_imx.c @@ -126,6 +126,15 @@ static int usbmisc_imx25_init(struct imx_usbmisc_data *data) 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); + + /* + * reset default for MX25_OTG_OCPOL_BIT is set (i.e. active + * high). So only unset if explicitly configured and keep set + * otherwise. + */ + if (data->oc_polarity_low) + val &= ~MX25_OTG_OCPOL_BIT; + writel(val, usbmisc->base); break; case 1: @@ -135,6 +144,14 @@ static int usbmisc_imx25_init(struct imx_usbmisc_data *data) val |= (MX25_H1_PM_BIT | MX25_H1_OCPOL_BIT | MX25_H1_TLL_BIT | MX25_H1_USBTE_BIT | MX25_H1_IPPUE_DOWN_BIT); + /* + * reset default for MX25_H1_OCPOL_BIT is set (i.e. active + * high). So only unset if explicitly configured and keep set + * otherwise. + */ + if (data->oc_polarity_low) + val &= ~MX25_H1_OCPOL_BIT; + writel(val, usbmisc->base); break; @@ -340,9 +357,16 @@ 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) { - /* High active */ + } else { reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY); + + /* + * reset default for MX6_BM_OVER_CUR_POLARITY is unset (i.e. + * active high). So only set if explicitly configured and keep + * clear otherwise. + */ + if (data->oc_polarity_low) + reg |= MX6_BM_OVER_CUR_POLARITY; } writel(reg, usbmisc->base + data->index * 4); @@ -442,9 +466,16 @@ 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) { - /* High active */ + } else { reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY); + + /* + * reset default for MX6_BM_OVER_CUR_POLARITY is unset (i.e. + * active high). So only set if explicitly configured and keep + * clear otherwise. + */ + if (data->oc_polarity_low) + reg |= MX6_BM_OVER_CUR_POLARITY; } writel(reg, usbmisc->base);