Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6552782ybx; Mon, 11 Nov 2019 10:50:27 -0800 (PST) X-Google-Smtp-Source: APXvYqw0EI/Fl2s87T4s9AUr2U0X48R6jsUW0y8b35qbEsiFjum0WexSsp8FJez9m+aE40053pjX X-Received: by 2002:a50:fb8d:: with SMTP id e13mr27461106edq.213.1573498227747; Mon, 11 Nov 2019 10:50:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573498227; cv=none; d=google.com; s=arc-20160816; b=nbob74yJCp4HOkjhBs+7ZLxGxei3fbj5XPSPls4KvD/e0p2TPmVUIVZ8UGb2qgkwWT tQ3uQj0ZiLRbPVwrSuaPVGADaHMvH4pNhT/l/PUeA9iQWZ3OO+OAAR7EcisgJU40X9TM HYAVNqSdKVIniSyoRDALBlQBF7KHcPaJhvN4aC2xLpcby6fchLVz+Srk/l4eeTcitERb sR1gC8W9Pyqfv/AhDprVWjsvcDh1/jhprNXLjM3oEHS8LTgfeR16Jzn1YHWWP2s6VnTs G4hVDZmnMUUhyo6NvFWCmyXur1lRieWZo73yo6d5b8sff0FhaydUriTFOfTa1KkjmTX7 VOmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DwM1ov1rAVgDdMr8hbGkAb4iRta0oDdSYQAeY1vk38g=; b=Ra4T6VorzQBco7fb7G5ivoX+QVz6sBALNGb8945hZK4Y7TB4tZBjlg9mJvaHrgNVmo /jecSFeKkWotENd98gsiguWj0zV+vT7cqnXgJ3pLdkU9HViGTllOhAmx75hOe120EeLA aDgrCuPdr8Lfz48CoToFfWTYfLm16P1q5xphg/JbtYxF1isKokWQSetK5UCcesg/fDCA lKnBWAdotr+ySkagPW2CadGC8ZVECChX1vWXSMSfEvxl3c9/IFEpKmSmgMqI80K+QOlu fFAa0j29ce7Qfw/KFGM5bOXGRtrvD2w4EwAYhG9K0doiSbAywEfR/hiHyg7HrppHs40+ Ebog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0iYMZdS6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m19si10077016ejd.180.2019.11.11.10.50.03; Mon, 11 Nov 2019 10:50:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0iYMZdS6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728397AbfKKStS (ORCPT + 99 others); Mon, 11 Nov 2019 13:49:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:42532 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729892AbfKKStQ (ORCPT ); Mon, 11 Nov 2019 13:49:16 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BB477222BD; Mon, 11 Nov 2019 18:49:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498155; bh=ReCV6BCF2dgrqtu76Vg995A2rTPyxoRVGshvuSNvtHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0iYMZdS6LKpQsdldQYkRllcJ6+9zrI1X9iGLYzp8qkGCa2fyG4Y7WWqXbso4mSvQf BeaKyFry4EupoTT4oa3M2MBQX7ajZieI+orYXZZMW0A4up4CZ18Brntr9hhzDkYygF t6hLCRFDSj9Gg0mFWQb9UGaYgnPkn1jA0AYFFyL8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, fei.yang@intel.com, Oliver Barta , Malin Jonsson , Andy Shevchenko , Mika Westerberg Subject: [PATCH 5.3 039/193] pinctrl: intel: Avoid potential glitches if pin is in GPIO mode Date: Mon, 11 Nov 2019 19:27:01 +0100 Message-Id: <20191111181503.864003752@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181459.850623879@linuxfoundation.org> References: <20191111181459.850623879@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Shevchenko commit 29c2c6aa32405dfee4a29911a51ba133edcedb0f upstream. When consumer requests a pin, in order to be on the safest side, we switch it first to GPIO mode followed by immediate transition to the input state. Due to posted writes it's luckily to be a single I/O transaction. However, if firmware or boot loader already configures the pin to the GPIO mode, user expects no glitches for the requested pin. We may check if the pin is pre-configured and leave it as is till the actual consumer toggles its state to avoid glitches. Fixes: 7981c0015af2 ("pinctrl: intel: Add Intel Sunrisepoint pin controller and GPIO support") Depends-on: f5a26acf0162 ("pinctrl: intel: Initialize GPIO properly when used through irqchip") Cc: stable@vger.kernel.org Cc: fei.yang@intel.com Reported-by: Oliver Barta Reported-by: Malin Jonsson Signed-off-by: Andy Shevchenko Signed-off-by: Mika Westerberg Signed-off-by: Greg Kroah-Hartman --- drivers/pinctrl/intel/pinctrl-intel.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) --- a/drivers/pinctrl/intel/pinctrl-intel.c +++ b/drivers/pinctrl/intel/pinctrl-intel.c @@ -52,6 +52,7 @@ #define PADCFG0_GPIROUTNMI BIT(17) #define PADCFG0_PMODE_SHIFT 10 #define PADCFG0_PMODE_MASK GENMASK(13, 10) +#define PADCFG0_PMODE_GPIO 0 #define PADCFG0_GPIORXDIS BIT(9) #define PADCFG0_GPIOTXDIS BIT(8) #define PADCFG0_GPIORXSTATE BIT(1) @@ -307,7 +308,7 @@ static void intel_pin_dbg_show(struct pi cfg1 = readl(intel_get_padcfg(pctrl, pin, PADCFG1)); mode = (cfg0 & PADCFG0_PMODE_MASK) >> PADCFG0_PMODE_SHIFT; - if (!mode) + if (mode == PADCFG0_PMODE_GPIO) seq_puts(s, "GPIO "); else seq_printf(s, "mode %d ", mode); @@ -428,6 +429,11 @@ static void __intel_gpio_set_direction(v writel(value, padcfg0); } +static int intel_gpio_get_gpio_mode(void __iomem *padcfg0) +{ + return (readl(padcfg0) & PADCFG0_PMODE_MASK) >> PADCFG0_PMODE_SHIFT; +} + static void intel_gpio_set_gpio_mode(void __iomem *padcfg0) { u32 value; @@ -456,7 +462,20 @@ static int intel_gpio_request_enable(str } padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0); + + /* + * If pin is already configured in GPIO mode, we assume that + * firmware provides correct settings. In such case we avoid + * potential glitches on the pin. Otherwise, for the pin in + * alternative mode, consumer has to supply respective flags. + */ + if (intel_gpio_get_gpio_mode(padcfg0) == PADCFG0_PMODE_GPIO) { + raw_spin_unlock_irqrestore(&pctrl->lock, flags); + return 0; + } + intel_gpio_set_gpio_mode(padcfg0); + /* Disable TX buffer and enable RX (this will be input) */ __intel_gpio_set_direction(padcfg0, true);