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: 10707189 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 7791217D5 for ; Fri, 30 Nov 2018 20:53:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AF66303E4 for ; Fri, 30 Nov 2018 20:53:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F24D3056B; Fri, 30 Nov 2018 20:53:20 +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=-7.9 required=2.0 tests=BAYES_00,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 A4FAB30594 for ; Fri, 30 Nov 2018 20:53:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725991AbeLAIDt (ORCPT ); Sat, 1 Dec 2018 03:03:49 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:46443 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725847AbeLAIDt (ORCPT ); Sat, 1 Dec 2018 03:03:49 -0500 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 Cc: Fabio Estevam , linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de 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-usb@vger.kernel.org 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 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);