From patchwork Wed Dec 11 15:04:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 181238 Delivered-To: patch@linaro.org Received: by 2002:ac9:44c4:0:0:0:0:0 with SMTP id t4csp915373och; Wed, 11 Dec 2019 07:21:46 -0800 (PST) X-Google-Smtp-Source: APXvYqwNhrHebSFXQvLhmP7/6UeKO/0fM6D220GHeCurCqTsL6+ZJNYiAxVzOaZsa/B8NasyF9EO X-Received: by 2002:a05:6808:f:: with SMTP id u15mr3098035oic.164.1576077705995; Wed, 11 Dec 2019 07:21:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576077705; cv=none; d=google.com; s=arc-20160816; b=lybDZQTA6gPBNJsjs3D+TN4k5ugY+i9iDeGEjsPC1giJ9IFJTFZ3BuSLo7/iTGYFha 0Mfi/J2v9WsNO7HT+HVGEYkZkfOyLbOWytjk9nDB33vgx8eSa3vzIO33ZciU7xXVqjuu M/emKUmY80p81oj4xvezzdusvAZURMMz7PL50WUIKnu0sQRX/ydu7RpNwuw3P+OFgtfi dcFK2htjF944m7Zy0P6iv7+4aNIABkP+RhEMYHLf2WOIsOg+ZD5h+Qq/UmYuMfae9mVK ECKTcxaRV+9hvMeNkWjljhQ+DM6IJT+zIfRVapGKKYMmPcw8BbVLhJ6SYsBtFj/lpyg0 OrLA== 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=sdxFNB4PIvlpD8Z4HD3s9qD85RNeOsdXuuuKHWMDRZ4=; b=JaFXsaIvTHGBZnovHoESBdyzdfIPunXXwjMtDXIH6JACEt6UUySjwpYrXWwi0Iqy/I cwuxQV4dBzGi91D8dO0m/HlBgkzLSv56xNrxL/X/sADJ0B7dcG4AaLfv6JCC0zqklpXp IHNU5MLOGGWkn7zPdeGJQKKKnrqZZis47/r1YegBIx+WhGyNezY54tp3jlfl+rM6oC5Z 6cRsyWShe6nSWZdqW4qMk9T4ThvR+fMMcrFfV0dQo8ppcnMQuNINvu7PtjJrQ2Ctn1r8 lkEVprR+h1HUEJwB4Y3e8Xhkr/lNcoGHR40H93IaIDm0Iiyq6faWTHwot42DHj60ZCvz nfdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WVtOquf2; 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 g25si1314015otp.20.2019.12.11.07.21.45; Wed, 11 Dec 2019 07:21:45 -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=WVtOquf2; 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 S1732501AbfLKPVo (ORCPT + 27 others); Wed, 11 Dec 2019 10:21:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:52050 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731843AbfLKPVl (ORCPT ); Wed, 11 Dec 2019 10:21:41 -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 0189322527; Wed, 11 Dec 2019 15:21:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077700; bh=UV2G6q/DXBthsE3ae57WamEql2zCNb2Q2GjMnMRBGkw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WVtOquf2oudfARqi89sn3/KsjQWYysEwZDWuXJ0m58z4Ma4JA/pzs8g/4gleSf+aL PoKGktQ5kHpTbpK2d57QCM4Ql7yirxLMeQoLeAhuTibWRt4/w0pJdLilsGFa9KrfGa iEVXNYCBkLO8JSwk5RBVkW335ePwd9fMuX2njb8Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, linux-mmc@vger.kernel.org, linux-gpio@vger.kernel.org, Bartosz Golaszewski , Linus Walleij , Sasha Levin Subject: [PATCH 4.19 137/243] gpio: OF: Parse MMC-specific CD and WP properties Date: Wed, 11 Dec 2019 16:04:59 +0100 Message-Id: <20191211150348.405211936@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150339.185439726@linuxfoundation.org> References: <20191211150339.185439726@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Linus Walleij [ Upstream commit 81c85ec15a1946f2e347ec0bf66936121eb97ce7 ] When retrieveing CD (card detect) and WP (write protect) GPIO handles from the device tree, make sure to assign them active low by default unless the "cd-inverted" or "wp-inverted" properties are set. These properties mean that respective signal is active HIGH since the SDHCI specification stipulates that this kind of signals should be treated as active LOW. If the twocell GPIO flag is also specified as active low, well that's nice and we will silently ignore the tautological specification. If however the GPIO line is specified as active low in the GPIO flasg cell and "cd-inverted" or "wp-inverted" is also specified, the latter takes precedence and we print a warning. The current effect on the MMC slot-gpio core are as follows: For CD GPIOs: no effect. The current code in mmc/core/host.c calls mmc_gpiod_request_cd() with the "override_active_level" argument set to true, which means that whatever the GPIO descriptor thinks about active low/high will be ignored, the core will use the MMC_CAP2_CD_ACTIVE_HIGH to keep track of this and reads the raw value from the GPIO descriptor, totally bypassing gpiolibs inversion semantics. I plan to clean this up at a later point passing the handling of inversion semantics over to gpiolib, so this patch prepares the ground for that. Fow WP GPIOs: this is probably fixing a bug, because the code in mmc/core/host.c calls mmc_gpiod_request_ro() with the "override_active_level" argument set to false, which means it will respect the inversion semantics of the gpiolib and ignore the MMC_CAP2_RO_ACTIVE_HIGH flag for everyone using this through device tree. However the code in host.c confusingly goes to great lengths setting up the MMC_CAP2_RO_ACTIVE_HIGH flag from the GPIO descriptor and by reading the "wp-inverted" property of the node. As far as I can tell this is all in vain and the inversion is broken: device trees that use "wp-inverted" do not work as intended, instead the only way to actually get inversion on a line is by setting the second cell flag to GPIO_ACTIVE_HIGH (which will be the default) or GPIO_ACTIVE_LOW if they want the proper MMC semantics. Presumably all device trees do this right but we need to parse and handle this properly. Cc: linux-mmc@vger.kernel.org Cc: linux-gpio@vger.kernel.org Cc: Bartosz Golaszewski Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin --- drivers/gpio/gpiolib-of.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) -- 2.20.1 diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index e0f149bdf98ff..1147ad968fd75 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -60,6 +60,45 @@ static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip, static void of_gpio_flags_quirks(struct device_node *np, enum of_gpio_flags *flags) { + /* + * Handle MMC "cd-inverted" and "wp-inverted" semantics. + */ + if (IS_ENABLED(CONFIG_MMC)) { + if (of_property_read_bool(np, "cd-gpios")) { + if (of_property_read_bool(np, "cd-inverted")) { + if (*flags & OF_GPIO_ACTIVE_LOW) { + /* "cd-inverted" takes precedence */ + *flags &= ~OF_GPIO_ACTIVE_LOW; + pr_warn("%s GPIO handle specifies CD active low - ignored\n", + of_node_full_name(np)); + } + } else { + /* + * Active low is the default according to the + * SDHCI specification. If the GPIO handle + * specifies the same thing - good. + */ + *flags |= OF_GPIO_ACTIVE_LOW; + } + } + if (of_property_read_bool(np, "wp-gpios")) { + if (of_property_read_bool(np, "wp-inverted")) { + /* "wp-inverted" takes precedence */ + if (*flags & OF_GPIO_ACTIVE_LOW) { + *flags &= ~OF_GPIO_ACTIVE_LOW; + pr_warn("%s GPIO handle specifies WP active low - ignored\n", + of_node_full_name(np)); + } + } else { + /* + * Active low is the default according to the + * SDHCI specification. If the GPIO handle + * specifies the same thing - good. + */ + *flags |= OF_GPIO_ACTIVE_LOW; + } + } + } /* * Some GPIO fixed regulator quirks. * Note that active low is the default.