From patchwork Mon Nov 26 14:17:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10698409 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 70B0013BB for ; Mon, 26 Nov 2018 14:17:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E09F29C75 for ; Mon, 26 Nov 2018 14:17:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EEAC29C7D; Mon, 26 Nov 2018 14:17:31 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 C2F8E29C75 for ; Mon, 26 Nov 2018 14:17:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726176AbeK0BLp (ORCPT ); Mon, 26 Nov 2018 20:11:45 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:44252 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726200AbeK0BLo (ORCPT ); Mon, 26 Nov 2018 20:11:44 -0500 Received: by mail-lf1-f67.google.com with SMTP id z13so13650526lfe.11 for ; Mon, 26 Nov 2018 06:17:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ah7Wi1YXN5Z+uH3YmKJMYEtS/7IoFRB8CU4U8R43QG8=; b=jTUmPQGbOFUgNSDO87c+b2tilyTxk5NyGXJ4JhH1AqrdJkCGBoIldsFEadzMYgDQIs oXdlTs4L6tiNks8clcMXNn07tuiI0jyoEmj7oc2p6cGiCk2bPuOSfM0e0qHQzCj2JAtO 7bVd8budatEoTlOL81AJ8VrqEraC9AdeEg2EU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ah7Wi1YXN5Z+uH3YmKJMYEtS/7IoFRB8CU4U8R43QG8=; b=eSQByXaZRhvsfm0kPDpWJr9PC1mXqkN5W/2ZfPoFPbf8WYOdH6DOlDFugSayFMuJq3 2z+voukSeiFzKsndov5mAGeZTirzZf0/L18N4RYJeHKmP2JwhCPIvqOlbCmFxsdjmBK7 JZzGxtK0LEbZxDCd6o1Awm3BwGdSI24eP1eWHi9cQLgus74PJ8QC4JcwAZcEK7SUW7/0 TwipM27Hlj4+n6T+d0dIFrAtLI7x1G2WjQA1lZoGxSYIarRP28UWJCv8+Jv+oo3IM06f r9Wg8ipyZUIYd20h6RukGfPmi3IuXdsh36LLQ7t6YTzp1XHYJtgRcpLGKdK2aQydW/V1 xHXg== X-Gm-Message-State: AGRZ1gKSonqfBOZvxEz3v+5MxChfioIyJl2wat9iz1L3RRDYBJB1mZy6 ANnM9ATOs6mrvNF5wGFNuhYgAktKu5JQQg== X-Google-Smtp-Source: AJdET5dsDkHseMp7Ol2iIv2jGjCoXP80L/SJJhMK0oYoY5uUYAtu2QGQDUE9W9VmHR5FDUEIzVnfkA== X-Received: by 2002:a19:2395:: with SMTP id j143mr15577891lfj.107.1543241846755; Mon, 26 Nov 2018 06:17:26 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id f8sm76303lfe.72.2018.11.26.06.17.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Nov 2018 06:17:25 -0800 (PST) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Linus Walleij , linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH] gpio: OF: Parse MMC-specific CD and WP properties Date: Mon, 26 Nov 2018 15:17:14 +0100 Message-Id: <20181126141714.18399-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/gpio/gpiolib-of.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 7f1260c78270..50a390251410 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -57,6 +57,45 @@ static void of_gpio_flags_quirks(struct device_node *np, enum of_gpio_flags *flags, int index) { + /* + * 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.