From patchwork Thu Oct 11 14:35:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 148646 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp2204030lji; Thu, 11 Oct 2018 07:35:42 -0700 (PDT) X-Google-Smtp-Source: ACcGV603tXKOLX6Hf94LCUZfSMg0Ay8FifrkiTic+tOlQyNvqZ9jGtbZq2SEjLfXTNfzOtt323ra X-Received: by 2002:a17:902:ab93:: with SMTP id f19-v6mr1822157plr.63.1539268542169; Thu, 11 Oct 2018 07:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539268542; cv=none; d=google.com; s=arc-20160816; b=vSr/dpAmlCCzByHJEIelylY9AxpWoJwcO/ofzMQpfW/4yqZp6/bFxiwEkNjQ7rRVHh fXAZRQGiKYmGTMwtedWbYX3n4Vc5nTwfeSJP43P9nPQWktf3dXzw3c1LlSUYY90tGAv0 r+6dsu3S/y8jLNgcaf8mjv4UJF2BNC5zTFouorSxd24DCQOij/U2jAhf9B1hjJQuFk41 ZYd00TNDvKUK3fg9a4bCq4g5U7ze2+/cwVE+Vk/i34hvYNhLAmiEEmA+LPvxQxpy5Mna ru/3JluDyGzFHx9lONORWZN68QOtXf+XJVBDi9AjOLW2WEJ/0JYeeoISXQTj403Szztk mDkA== 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=3Flfwyl0NkT5SQooUVYbkxhb13sv0hTuLStxlsvlvhg=; b=Oj/vNWZwCivNPNBl4WkMXWBZlU2sg2QcL+Ytgy1ZWWI31/qgwxYxpa3IrSKh1dyK5I 1gySL9hbBPj+GXtNMU1iycvSBg+ugVKbEZjiA62Fr0h5DyYRp9akLepThz4JiyJ95Ilf f3Hb8u6KckEYzqCUPYx+AfJn3tVmvgBnHNIE1RUeMRzb877nMsvHKoGO0Hj2LJOnpZkL hlMRt6aN5xzNZUESmjcjKDy5O+7i7KzMJXtJQslc9kL5tMQCRZvBDyFn220H6Mopj8Js 7jyXFZ9DfSvxrgeD3o1FAo0f0w9UJi4Xwua+kw/gfo7TMocAKXFlEQoKJQnRbvQ7k4s7 KAFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AUnzHrw0; 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 b31-v6si26473041pgm.441.2018.10.11.07.35.41; Thu, 11 Oct 2018 07:35:42 -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=AUnzHrw0; 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 S1728632AbeJKWDG (ORCPT + 32 others); Thu, 11 Oct 2018 18:03:06 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:35193 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727510AbeJKWDF (ORCPT ); Thu, 11 Oct 2018 18:03:05 -0400 Received: by mail-lf1-f67.google.com with SMTP id r191-v6so6873096lff.2 for ; Thu, 11 Oct 2018 07:35:37 -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=3Flfwyl0NkT5SQooUVYbkxhb13sv0hTuLStxlsvlvhg=; b=AUnzHrw0Os3ZLwURY8I5PtZ9NBx3evD4Dv2cD5RQcgQx4qXo3ZDJ4xQkV26QcA6Q+c xI+XJx1cJGgON6N0O47aMy6/qKmn8xoG8wD/dgrAbCpu6ixzeDorCDQELDk5Z50DfI9P Ny+Spnx29XIQMAIk66APUZ6IE1CMvdb0IqzTE= 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=3Flfwyl0NkT5SQooUVYbkxhb13sv0hTuLStxlsvlvhg=; b=eEJ54sBPUupEg/0qo7TwtZf111Ym3w70DlhMi8Ly/N2DKcLvMGEIV5JueMe6bgpPnA x5MNQtihu8SdV8gRqFv4dYmiD8KJJKhhi7GpszkghLFEvbWMEJouoGl+R6FkPnqCIhP3 bQRcQBxFWdK6GkwOiIt1eMEPy2rC5+MSrXP2p/amMiq3WnKQ74YXg4LSTdK2U622Ocdu 7KBDuaZw6YJ/wBVqOgW88sJHkDQqRNVDlEOyI7mELHQfgXLwwUlESFuyNrnh2mZU9oq6 sbgQ8LRNtEsyJzds7qssy3LHxnkiDYoWB6J/V4IacYHN4mRtSKJglHhli+xCpmtvjnjt BxvQ== X-Gm-Message-State: ABuFfogtyPSQ6dyFLPkgFiz8tMN7bn7ZgJENimHTCyD2gQl+PZfxQKk1 vjvJV9dUJ3D914Bk249LNfgRzg== X-Received: by 2002:a19:18e3:: with SMTP id 96-v6mr1373960lfy.133.1539268536594; Thu, 11 Oct 2018 07:35:36 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id v4-v6sm6018745ljd.86.2018.10.11.07.35.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Oct 2018 07:35:35 -0700 (PDT) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Linus Walleij , Marek Szyprowski Subject: [PATCH] gpio/regulator: Allow nonexclusive GPIO access Date: Thu, 11 Oct 2018 16:35:31 +0200 Message-Id: <20181011143531.7195-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 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. Fixes: efdfeb079cc3 ("regulator: fixed: Convert to use GPIO descriptor only") Reported-by: Marek Szyprowski Cc: Marek Szyprowski Signed-off-by: Linus Walleij --- Hi Marek, it would be great if you could try this on top of linux-next and report if it solves your problem on the Samsung Exynos. If it does I hope it will apply cleanly on the regulator tree. --- 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.1 Tested-by: Marek Szyprowski Tested-by: Jon Hunter diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 7c222df8f834..f82a741ff428 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); + 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