From patchwork Tue Jan 9 00:24:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 857179 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="PkohWup9"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zFtJR2p3wz9ryT for ; Tue, 9 Jan 2018 11:27:35 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754473AbeAIA1X (ORCPT ); Mon, 8 Jan 2018 19:27:23 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:44915 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754153AbeAIA1V (ORCPT ); Mon, 8 Jan 2018 19:27:21 -0500 Received: by mail-lf0-f68.google.com with SMTP id w23so3859065lfd.11 for ; Mon, 08 Jan 2018 16:27:21 -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; bh=XsD+hFF+Z4MF6WlkjkvzuCuxJFloNRgGpMgiDrfPYk0=; b=PkohWup9Mp2IH5RXXjf0cSKJ7XEniv2PvxToDk8hfaFZvt7ri8mSoSxuvIR3UO8wMX m8UWyiV9dxgmVgEt/WG046TAiiqvTZsR+YyJED59zoa40oIvHQ2VOWfrE/FKu/6k0e1F L/KyArLJPYkQHL6S+cEZC4xmXLLI0SuHUnW74= 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=XsD+hFF+Z4MF6WlkjkvzuCuxJFloNRgGpMgiDrfPYk0=; b=C5hUsX2HGaLWOYqHq4WCpAmYBMRB4+ENbRbrgy7JGLWhtJ9zrJ5Tq3lRREr9Qbag02 SF1yebQayBQCvQvPHft04tM3wLZmOTrdjyobmFdKvOoygHWcH9EAXhLGctUwIhE7rO5M wZvveo/ShJmx+WrVGhZImdsqpmz1gmTZOTxhkZ+j4AkAP4eIuQWOLwUDUwvSm/0gjrcp tNA5MvsBSVP6AO8gSxDiBe1bP0KI7QAbZVQxAaKvNNXw3qNvZWDM1PvNfm6kuITi96/e nkgVabKwnSvU3nNdpYiz686nneRHnQEEIdQ4wnt7N/gCVKCHaRGtLXQS2SWClQCpVsVF 4HJg== X-Gm-Message-State: AKGB3mIeo8P2iixfmeiG5BLwJ+JhgPaRMpZAXNIXEAxXurKhHfSG3RmF rF9HT/BaOtkZdK2zuFvrvPNGRw== X-Google-Smtp-Source: ACJfBos3NBbrMW2EmTAz0D7uQv5NGffr2kLkJNlgbyfaAjmCdCAXNKnZA8/8lHeUCnJ0f1hmz/k4nw== X-Received: by 10.46.112.24 with SMTP id l24mr7666907ljc.66.1515457640489; Mon, 08 Jan 2018 16:27:20 -0800 (PST) Received: from localhost.localdomain (c-cb7471d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.116.203]) by smtp.gmail.com with ESMTPSA id i1sm2580145lji.22.2018.01.08.16.27.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jan 2018 16:27:19 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown , linux-gpio@vger.kernel.org, Rob Herring Cc: linux-kernel@vger.kernel.org, Linus Walleij Subject: [PATCH 1/4] gpio: of: Support regulator nonstandard GPIO properties Date: Tue, 9 Jan 2018 01:24:51 +0100 Message-Id: <20180109002451.22618-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Before it was clearly established that all GPIO properties in the device tree shall be named "foo-gpios" (with the deprecated variant "foo-gpio" for single lines) we unfortunately merged a few bindings for regulators with random phandle names. As we want to switch the GPIO regulator driver to using descriptors, we need devm_gpiod_get() to return something reasonable when looking up these in the device tree. Put in a special #ifdef:ed kludge to do this special lookup only for the regulator case and gets compiled out if we're not enabling regulators. Supply a whitelist with properties we accept. Cc: Rob Herring Signed-off-by: Linus Walleij --- This patch is preperatory work for converting fixed and GPIO regulators to deal only with GPIO descriptors. --- drivers/gpio/gpiolib-of.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index e0d59e61b52f..9686922310a4 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -117,6 +117,41 @@ int of_get_named_gpio_flags(struct device_node *np, const char *list_name, } EXPORT_SYMBOL(of_get_named_gpio_flags); +/* + * Some regulator bindings happened before we managed to establish that GPIO + * properties should be named "foo-gpios" so we have this special kludge for + * them. + */ +static struct gpio_desc *of_find_regulator_gpio(struct device *dev, const char *con_id, + enum of_gpio_flags *of_flags) +{ + /* These are the connection IDs we accept as legacy GPIO phandles */ + const char *whitelist[] = { + "wlf,ldoena", /* Arizona */ + "wlf,ldo1ena", /* WM8994 */ + "wlf,ldo2ena", /* WM8994 */ + }; + struct device_node *np = dev->of_node; + struct gpio_desc *desc; + int i; + + if (!IS_ENABLED(CONFIG_REGULATOR)) + return ERR_PTR(-ENOENT); + + if (!con_id) + return ERR_PTR(-ENOENT); + + for (i = 0; i < ARRAY_SIZE(whitelist); i++) + if (!strcmp(con_id, whitelist[i])) + break; + + if (i == ARRAY_SIZE(whitelist)) + return ERR_PTR(-ENOENT); + + desc = of_get_named_gpiod_flags(np, con_id, 0, of_flags); + return desc; +} + struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, unsigned int idx, enum gpio_lookup_flags *flags) @@ -126,6 +161,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, struct gpio_desc *desc; unsigned int i; + /* Try GPIO property "foo-gpios" and "foo-gpio" */ for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) { if (con_id) snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id, @@ -140,6 +176,10 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, break; } + /* Special handling for regulator GPIOs if used */ + if (IS_ERR(desc)) + desc = of_find_regulator_gpio(dev, con_id, &of_flags); + if (IS_ERR(desc)) return desc;