From patchwork Fri Oct 12 12:54:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 148762 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp700588lji; Fri, 12 Oct 2018 05:54:22 -0700 (PDT) X-Google-Smtp-Source: ACcGV62J/O6GBq1bTIdYmXpTOP1l/rkDKqN7sTYHfE2DQVFrnhKLOsO8uqVeLSirYBMEtkfMReal X-Received: by 2002:a63:7506:: with SMTP id q6-v6mr5401376pgc.137.1539348862139; Fri, 12 Oct 2018 05:54:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539348862; cv=none; d=google.com; s=arc-20160816; b=MGsZkMC7lC6nz+UQJFX+MWVXY9ks5bxWpmqP2ZghLpEjclPFB1FrF7FpYU4gJpi3md zm6MHuqKIsBIhjoE7R6HohWEgsABnqMPfw8mweyW42sP/oU8DmPi+ZZI/gO9JpbWzVLO BE9kd/h2wA4vbdyo99naMtKBYEdcLHorsV45+4RkBqYo26dmpUTuC546YIZG2RZAybzM T2V5OvSmVu2191JkwRtsSbpLueIsufGJJu7Z3dJv3ehYBMDg91dEG4KvEmZWNTrASPXu h5BR31hUjOHZwgaM01/7kQ39pfKp2fkdIV0ZriesKfL/idYllwZW5E5PPZy0yzx0aPLO 71Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=QFWh2VY+/WHVnwKgB1Ultl1aw9SB9K99iEk317UWLjQ=; b=yOjw+JP+/5/mXBA1OwDoIYhnZVvqKpEIvT/1bIop/MvX+doolEDoS4TCdOrHKmIlZA mcxXnkzI9eJG5bdF9x94SPqJOM9OcmsHN5YPdjZlmbjrL6QiKRavT9wYjFsXvYSxpV4v x0AHeUddrpi+JQSA+Nh4WQDf6VzG9weOnV46OJl9bBnZnxN3NtFPCnrRxUxEwWbGv5L/ ZbVQdG1dNAU4WaLdPKATpzyHnsWgPCkRf6kW7obWHRI/69etbOeOJHnu+LDx0HWg2/LU cO9DySqfoI9OSELvDImQdaHV3a6pSN30Jq48ySwxc3zBJBvuzDDNjXJIToIxbzyjBnhM 2vyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="caTxx/zx"; 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; 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 q13-v6si1139780pgq.526.2018.10.12.05.54.21; Fri, 12 Oct 2018 05:54:22 -0700 (PDT) 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=@linaro.org header.s=google header.b="caTxx/zx"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728610AbeJLU0k (ORCPT + 32 others); Fri, 12 Oct 2018 16:26:40 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:34088 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728450AbeJLU0j (ORCPT ); Fri, 12 Oct 2018 16:26:39 -0400 Received: by mail-lj1-f194.google.com with SMTP id j17-v6so11303043lja.1 for ; Fri, 12 Oct 2018 05:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=QFWh2VY+/WHVnwKgB1Ultl1aw9SB9K99iEk317UWLjQ=; b=caTxx/zxXkEm9pN8MB3n+ze57S/dfwSqW4I40t+7ScB/77GKpqJ8g4YW0QmGMWp3a6 N+axGj5RkOdMWImrLW5ZZUxN4lT6uMaJ3MgVDVw3RdtNl/V+5cQiNJ0WKiypJIQI/+Mq NQZLW7kSDETeX06MRQ6hggCFLq73gCWVTtbKU= 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; bh=QFWh2VY+/WHVnwKgB1Ultl1aw9SB9K99iEk317UWLjQ=; b=MXKmkoLtIgATbHaFvQPAbV0grT+pG543RL862oqfwzGsjWd36fb99UA53T3ZH8mSIQ N8daSxRhTcHFQV5FuW5jueEWedYMU9a4MUFSaJosYJ+4U5Xa0iE3f/RLPrDlfQwWK6sF UwRziTW6uhZgCBllZ4XcSbhY7vhVl2q4ov4tJzrhM5RSEZMs/Zj8kVPFbB2RJ3eOsVIw VrgBlJcfWE5y7WWHPhWT/hE9+0PqtwkZ4k4wFHBs9YrNmin6gg/qO5CbSFjLdNMpCWLY VgZ4vLr1evqC/xB3t4uzF60zPMDuiqhm20fYfpQrYFpPYPijPsk8glb81J7KD9awHOlT 7eKA== X-Gm-Message-State: ABuFfojayVVXtu8si/bUfw4s+o5+plkd1EPFHnY3UdaHD/Dknmb8bh8t wQsIvDxXM9obDDHwHNb1uWg2AA== X-Received: by 2002:a2e:9dc4:: with SMTP id x4-v6mr4341433ljj.133.1539348857666; Fri, 12 Oct 2018 05:54:17 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id u7-v6sm252741lju.15.2018.10.12.05.54.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Oct 2018 05:54:15 -0700 (PDT) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Linus Walleij , Marek Szyprowski , Jon Hunter Subject: [PATCH v2] regulator/gpio: Allow nonexclusive GPIO access Date: Fri, 12 Oct 2018 14:54:12 +0200 Message-Id: <20181012125412.21324-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This allows nonexclusive (simultaneous) access to a single GPIO line for the fixed regulator enable line. This happens when several regulators use the same GPIO for enabling and disabling a regulator, and all need a handle on their GPIO descriptor. This solution with a special flag is not entirely elegant and should ideally be replaced by something more careful as this makes it possible for several consumers to enable/disable the same GPIO line to the left and right without any consistency. The current use inside the regulator core should however be fine as it takes special care to handle this. For the state of the GPIO backend, this is still the lesser evil compared to going back to global GPIO numbers. Cc: Marek Szyprowski Cc: Jon Hunter Fixes: efdfeb079cc3 ("regulator: fixed: Convert to use GPIO descriptor only") Reported-by: Marek Szyprowski Tested-by: Jon Hunter Tested-by: Marek Szyprowski Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Fix the print string to use ternary operator and alternative text. - Collect Tested-by's from affected systems. - Mark: I tested to apply this on the regulator tree pulled in my for-next branches for GPIO and pin control on top and it seems to work! Could you apply it? --- drivers/gpio/gpiolib.c | 19 +++++++++++++++++-- drivers/regulator/fixed.c | 13 +++++++++++++ include/linux/gpio/consumer.h | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) -- 2.17.2 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 7c222df8f834..56178af4ecd9 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -4144,8 +4144,23 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev, * the device name as label */ status = gpiod_request(desc, con_id ? con_id : devname); - if (status < 0) - return ERR_PTR(status); + if (status < 0) { + if (status == -EBUSY && flags & GPIOD_FLAGS_BIT_NONEXCLUSIVE) { + /* + * This happens when there are several consumers for + * the same GPIO line: we just return here without + * further initialization. It is a bit if a hack. + * This is necessary to support fixed regulators. + * + * FIXME: Make this more sane and safe. + */ + dev_info(dev, "nonexclusive access to GPIO for %s\n", + con_id ? con_id : devname); + return desc; + } else { + return ERR_PTR(status); + } + } status = gpiod_configure_flags(desc, con_id, lookupflags, flags); if (status < 0) { diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index 7d639ad953b6..ccc29038f19a 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c @@ -170,6 +170,19 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev) gflags = GPIOD_OUT_LOW_OPEN_DRAIN; } + /* + * Some fixed regulators share the enable line between two + * regulators which makes it necessary to get a handle on the + * same descriptor for two different consumers. This will get + * the GPIO descriptor, but only the first call will initialize + * it so any flags such as inversion or open drain will only + * be set up by the first caller and assumed identical on the + * next caller. + * + * FIXME: find a better way to deal with this. + */ + gflags |= GPIOD_FLAGS_BIT_NONEXCLUSIVE; + cfg.ena_gpiod = devm_gpiod_get_optional(&pdev->dev, NULL, gflags); if (IS_ERR(cfg.ena_gpiod)) return PTR_ERR(cfg.ena_gpiod); diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index 0f350616d372..f2f887795d43 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -39,6 +39,7 @@ struct gpio_descs { #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) #define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3) +#define GPIOD_FLAGS_BIT_NONEXCLUSIVE BIT(4) /** * Optional flags that can be passed to one of gpiod_* to configure direction