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: 152044 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5759738ljp; Mon, 26 Nov 2018 06:17:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/URj4/nB/V4ZfH5Try8vK7eaech97FXYJE3CFE868xR0iX9XwWVCghMyJs1f6wtrEuAaKKz X-Received: by 2002:a62:5486:: with SMTP id i128mr19830387pfb.215.1543241868415; Mon, 26 Nov 2018 06:17:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543241868; cv=none; d=google.com; s=arc-20160816; b=QhjH2goPnBtGot7cNQzy8HA3Yl3K9Lx6WBCGg36iiONI4P6ts+6OWgscJ2l4+50SrZ qpQrwOLk+zIRPy+USWMPKWJyWGTfVA5LUKjEytd1j50ZN9YHusBRkjGac3HgS3qIhk6r dL1NKtj/MJhokIc+lwVjrFawPk2y3eiUJlxsl2ZS/nqFiUZXSbUqwxI8MzEdsYB/1IlF hjyhyuVv6PRYYqAX0am4PRK5RI1UBdCcvwB2Vlqnmr08xQXwNDsn3XuoYWOMs++9apJj BYPEHa04WmaoJS6lkBTXMVdumPINEU96s2nPBdapEuRsZyvF7+ZshBwavVrJNWKRPcLf WfBA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Ah7Wi1YXN5Z+uH3YmKJMYEtS/7IoFRB8CU4U8R43QG8=; b=s8wcCK5/iZU56BXGkNkTjnI5mJzejn/FOV722L30n4TlO3ewt/Dz20qnHbOQl3iqLO ofCOKIg04Bx3+kwJAGbzbI0tfSZjx1LVusx+Ep2wLXjnwkHRuoimTI8BQjPHHhyciZmM SFKoJ0+6w4eDs+hu8GdmD5X7KSXebvZt+0qiXpCknyQ5lqf0KrVO2Yi5SAgftD7QaTEU AfguS0tcKXUiEMKFPzSzgct6pqeNCcNJEeEhUdFMx22xryM1jCWMxF38OJFg8T1K1D4+ /fDs0+Hw5scqplC93OXTg4WPLcT8nQx4jHccNXcme0Hx6oePz3nO7ehDgrUuT71Z/N1h /V9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jTUmPQGb; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p26si466747pfj.244.2018.11.26.06.17.38; Mon, 26 Nov 2018 06:17:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-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=@linaro.org header.s=google header.b=jTUmPQGb; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726289AbeK0BLo (ORCPT + 5 others); Mon, 26 Nov 2018 20:11:44 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:41632 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726176AbeK0BLo (ORCPT ); Mon, 26 Nov 2018 20:11:44 -0500 Received: by mail-lf1-f66.google.com with SMTP id c16so13666818lfj.8 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=iX8KT8ulgBaCftH/xjYC2KT/s93aDaSx8jVGvlU/wNqLjUb8ui7S9GFuxPttK4ZQlK ivNgO+9FByNGqOZ5J54pegzS4PfEh1QBgCGtiUGxO+u2+12H/IW4i1CF1oc2zHZNELGh UFiX/VmckQzbhwj3uGQT28GhBsg/MqeXuzID43ePU9C/Q3j556aOwL3HPdKSJ6qkbRZx d6dp2/KJFn1Z6jpEMxrfbYU5Sh0WPUNlKVvnCnuoqcJgscDPqLPxlTISeY7kK4bndSoF web6boSZoiDwUH+g2CqGTAIC7HpLLay0l7a6i3pGoOLGFVrF26hlhqQM0SXZzR8lUONO S1AQ== X-Gm-Message-State: AGRZ1gLe6rZXFoUreMjaTg8yCvRPSvNMrac9v2togmLBV5IB8SF0IQJx 3RbSzbl3ss+RxRwAe25eDUNJlMJ2K1qafA== 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-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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(+) -- 2.19.1 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.