Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6552751ybx; Mon, 11 Nov 2019 10:50:25 -0800 (PST) X-Google-Smtp-Source: APXvYqzawQyRZAV/pwKYzxSfuWzFKPg5HjzbmhOiy8P7LqcmDz0IwdwRkuL1aNHh4K62e5DZHcPN X-Received: by 2002:aa7:c894:: with SMTP id p20mr28848533eds.145.1573498225593; Mon, 11 Nov 2019 10:50:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573498225; cv=none; d=google.com; s=arc-20160816; b=a8vKBzbP0k4bbtixyHcux9erlwrWTAzM8ywhECm+uTtlvu2YlUhKXNHZ8SGyGaL4rF TrL5EhEVud2eULgEm38VqFsCAW0QJXk3tRk8+JG8kkQAhofd2M3oFzdPRXlEPLlSkyxn uZ66Yq4Cp98QERNOYf8uTzimZckcgVUtwC1Zn1/D4TadXPx0LqBIxXrhpd7hCHg/gZxj zT/yv2Y9e/g0EQHST+fQ0ABanyOvAC3sn6kqeZdgGOnLMSmvHKbmavt6g3lkIFnFmR4h cp8lY1OFRemBlua/vGM6jLIZVWaHUfu1fvNq08d+pFc2NyjthXB+fAWc3eamus49yywk 0yGg== 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=S1sEufSskZzTuYLAQNESHLPy2KdeBssbM2OfurwDwH8=; b=0UNsRfHUWO5CD/eWO+8qTKWSEVKWp2L8UtVHYXCjwjirl90U4mK6n5WGnWC5V4KZbJ AlMkh4qXusrxEpbHE+ULnzXaSIiWCRCLsY3eN4vfo64cgzqLnAshdeQseVxB6YzcVGEt U/bQqcg9smTiWQhIn8n4gMW0mKsru3wl+CDbzRQ9KDTatjLt5lUYp8jcO3UtU1a9wKei HTInbf6rXTo8r2cc4PZM3UXyTfl6TCWMC3dwi6OM2+q6xgizLeXz8SoMZRvrn6g8b0eK akul3Dg9uEovBh/SsTUdlPSuzlB/xdByZonQqpZJtVFBuaHvioJ7EpECLAO6Cu3x51M3 tzIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wnCn+ff9; 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 s24si9497235ejz.252.2019.11.11.10.50.01; Mon, 11 Nov 2019 10:50:25 -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=wnCn+ff9; 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 S1730032AbfKKSqq (ORCPT + 99 others); Mon, 11 Nov 2019 13:46:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:39314 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730025AbfKKSqp (ORCPT ); Mon, 11 Nov 2019 13:46:45 -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 4608D20674; Mon, 11 Nov 2019 18:46:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498003; bh=joAlmJwFdGMLIvio/Y3ktCQ43gYYcMvWGpbSsVHlXnM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wnCn+ff9guOI3j0ctRgSFEFjbCBYPzHwHtdM/VtqwlpGlGqdFouLvrK5XXR7Wo/cJ QAboxzVBiC6XNrrYgV3rMVNOZv/Uhl8PniERwqLeN+bzXpEPl802tZXRMijI1vL0PL +7YRd+B5tDuuHzjPH1SPQXqlbVN01zhmP2BczHsI= 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 , Sasha Levin Subject: [PATCH 4.19 118/125] pinctrl: intel: Avoid potential glitches if pin is in GPIO mode Date: Mon, 11 Nov 2019 19:29:17 +0100 Message-Id: <20191111181455.539752769@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181438.945353076@linuxfoundation.org> References: <20191111181438.945353076@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 [ Upstream commit 29c2c6aa32405dfee4a29911a51ba133edcedb0f ] 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: Sasha Levin --- drivers/pinctrl/intel/pinctrl-intel.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c index 1ea3438ea67e9..89ff2795a8b55 100644 --- a/drivers/pinctrl/intel/pinctrl-intel.c +++ b/drivers/pinctrl/intel/pinctrl-intel.c @@ -49,6 +49,7 @@ #define PADCFG0_GPIROUTNMI BIT(17) #define PADCFG0_PMODE_SHIFT 10 #define PADCFG0_PMODE_MASK (0xf << PADCFG0_PMODE_SHIFT) +#define PADCFG0_PMODE_GPIO 0 #define PADCFG0_GPIORXDIS BIT(9) #define PADCFG0_GPIOTXDIS BIT(8) #define PADCFG0_GPIORXSTATE BIT(1) @@ -301,7 +302,7 @@ static void intel_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, 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); @@ -422,6 +423,11 @@ static void __intel_gpio_set_direction(void __iomem *padcfg0, bool input) 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; @@ -450,7 +456,20 @@ static int intel_gpio_request_enable(struct pinctrl_dev *pctldev, } 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); -- 2.20.1