Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2342930ybz; Thu, 23 Apr 2020 16:23:22 -0700 (PDT) X-Google-Smtp-Source: APiQypLRmJ6nABpEAR/q4JSH+81rbRJLjO//H/UVPA3Jm8AUIe1A8TNXYkBSpk2oXEjHsA6hL8V4 X-Received: by 2002:a17:906:315a:: with SMTP id e26mr4661926eje.53.1587684202660; Thu, 23 Apr 2020 16:23:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587684202; cv=none; d=google.com; s=arc-20160816; b=Je/HmO52jxTfoTcRdRiu4XsR6sENnqGrUtv3dU8IKBy/roP7xpqT2Kh3AAt1n0Qezh Vh6vZk8paniBMegxuQ44tC4bO3IlP11dw7OB5KFjGhk82OD9++07o892n6Zi+V8SueGe bh01zEoDUOlZl2aB12QewUIHOEtRntcMKFughyKTqNqXOYvhZA3REDeSKxgM8/AO+J+z eYWxBIjFUYBqLyjlwjzRMKRaFCZVrJn5tFxs8hjkuMKGBFlpHQdN2njQ3vZJUoOEAXte qtGu8e4WqTuSo9iayVpJPdWMXHnjzjBDabmcvQLLbb9nSkI7LEfOlBRo3wgcsnxiGZwh akpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=4P4YwmywK6hknAiLdlplasK5UhI42Bs76EFSDwbLHoA=; b=T+kTT539ASRuJkNCizhN0A1siG2HLBhe5pZUNpNMmLm8ys9QhIcpxz/a0nDMNw18I1 QtUmhyXHLw4ox7K/jVOim3CksD/qrBCltaNwnKxOd96zd1QDnNgYPm2VK9P533QcC6d6 AbPoZhh1duuB2EHOI8mp558eT6fRCaH2iX2rVXMDZes1+UbwfqA62GXTBY1qyepb47UO sAOM3yjhPvA3jvt38sbhmQAn8lKVgNh+9wRpSiDkKBtbf+KsCBmsD97Be9xJYIcMeia0 eov44MKPOZkaVubLZFyhRqp5qd/mw5W4ZSRgm6xbL6CpZ9HOdFMQ8PXt6mGDGEP5Y6D0 s85g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cx18si2085451edb.73.2020.04.23.16.22.59; Thu, 23 Apr 2020 16:23:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729912AbgDWXVq (ORCPT + 99 others); Thu, 23 Apr 2020 19:21:46 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:48520 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728196AbgDWXGc (ORCPT ); Thu, 23 Apr 2020 19:06:32 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1jRkvL-0004bF-Eq; Fri, 24 Apr 2020 00:06:27 +0100 Received: from ben by deadeye with local (Exim 4.93) (envelope-from ) id 1jRkvK-00E6jQ-GP; Fri, 24 Apr 2020 00:06:26 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Benjamin Adler" , "Mika Westerberg" , "Linus Walleij" Date: Fri, 24 Apr 2020 00:04:53 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 066/245] pinctrl: baytrail: Relax GPIO request rules In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.83-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Mika Westerberg commit f8323b6bb2cc7d26941d4838dd4375952980a88a upstream. Zotac ZBOX PI320, a Baytrail based mini-PC, has power button connected to a GPIO pin and it is exposed to the operating system as Windows 8 button array. This is implemented in Linux as a driver using gpio_keys. However, BIOS on this particula machine forgot to mux the pin to be a GPIO instead of native function, which results following message to be seen on the console: byt_gpio INT33FC:02: pin 16 cannot be used as GPIO. This causes power button to not work as the driver was not able to request the GPIO it needs. So instead of completely preventing this we allow turning the pin as GPIO but issue warning that something might be wrong. Reported-by: Benjamin Adler Signed-off-by: Mika Westerberg Signed-off-by: Linus Walleij [bwh: Backported to 3.16: adjust filename] Signed-off-by: Ben Hutchings --- drivers/pinctrl/pinctrl-baytrail.c | 35 +++++++++++++++--------- 1 file changed, 22 insertions(+), 13 deletions(-) --- a/drivers/pinctrl/pinctrl-baytrail.c +++ b/drivers/pinctrl/pinctrl-baytrail.c @@ -160,40 +160,49 @@ static void __iomem *byt_gpio_reg(struct return vg->reg_base + reg_offset + reg; } -static bool is_special_pin(struct byt_gpio *vg, unsigned offset) +static u32 byt_get_gpio_mux(struct byt_gpio *vg, unsigned offset) { /* SCORE pin 92-93 */ if (!strcmp(vg->range->name, BYT_SCORE_ACPI_UID) && offset >= 92 && offset <= 93) - return true; + return 1; /* SUS pin 11-21 */ if (!strcmp(vg->range->name, BYT_SUS_ACPI_UID) && offset >= 11 && offset <= 21) - return true; + return 1; - return false; + return 0; } static int byt_gpio_request(struct gpio_chip *chip, unsigned offset) { struct byt_gpio *vg = to_byt_gpio(chip); void __iomem *reg = byt_gpio_reg(chip, offset, BYT_CONF0_REG); - u32 value; - bool special; + u32 value, gpio_mux; /* * In most cases, func pin mux 000 means GPIO function. * But, some pins may have func pin mux 001 represents - * GPIO function. Only allow user to export pin with - * func pin mux preset as GPIO function by BIOS/FW. + * GPIO function. + * + * Because there are devices out there where some pins were not + * configured correctly we allow changing the mux value from + * request (but print out warning about that). */ value = readl(reg) & BYT_PIN_MUX; - special = is_special_pin(vg, offset); - if ((special && value != 1) || (!special && value)) { - dev_err(&vg->pdev->dev, - "pin %u cannot be used as GPIO.\n", offset); - return -EINVAL; + gpio_mux = byt_get_gpio_mux(vg, offset); + if (WARN_ON(gpio_mux != value)) { + unsigned long flags; + + spin_lock_irqsave(&vg->lock, flags); + value = readl(reg) & ~BYT_PIN_MUX; + value |= gpio_mux; + writel(value, reg); + spin_unlock_irqrestore(&vg->lock, flags); + + dev_warn(&vg->pdev->dev, + "pin %u forcibly re-configured as GPIO\n", offset); } pm_runtime_get(&vg->pdev->dev);