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: 123791 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3377288qgn; Mon, 8 Jan 2018 16:27:26 -0800 (PST) X-Google-Smtp-Source: ACJfBovdMXiG9BrNzMw24n6xFdTTGVFQOz5QEPkToSkU5Jf4lEtfjJegWqlkAEX5lmovxEn0nFa3 X-Received: by 10.84.248.68 with SMTP id e4mr13843886pln.296.1515457646229; Mon, 08 Jan 2018 16:27:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515457646; cv=none; d=google.com; s=arc-20160816; b=uctTk6Y6cTitZ3pdBgWed02CkPa+wm3bL4vfh1idYbFIAtcZmoDHpsdxNajINcYfsI 7ZWsZhpMMuM3nzgybGq3rb+Ue0CIqF/LHnCAEq9cCmyH3YrPhHU+B4DvAag90lhaT6ew k5YPu/rXrDNXA7ZLjYzBOch8RYihraCXL2A9W8lzB63sEARrgLkbXCrd8fbb38HHjfZN SJdGrE3VPV5QVMpflbZ8cVAJGF3NBt9q8eOwzhZ+aaMtiRr7LtiZpFSOPrE4xKL5pSGJ zt9+TDpSwmlsunabhP4ra4XKQpB3ofoGN9o+wP6B+zKe2L6s8AVzxYUX6Q9X4p9eubs6 Bsog== 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:arc-authentication-results; bh=XsD+hFF+Z4MF6WlkjkvzuCuxJFloNRgGpMgiDrfPYk0=; b=IbrDCLmqFhE2q9yAvOKZbU8DRxJO15fB3jSFwODPdLNEnvKLmchtqR56YmqQ1G8p4p 229ZgqZ2KyBcK2DeQO5ODhxnqO6wl1CNwZimRbkiPMCpBiJrj4o18lkCczPAvONs0sqS lc7DGKGYY0ypIQGdva0OiZU11ApA/Oh9QIAW9lXXqqrb4a0UBvVx+V3rKII+OrGPoJp2 0rb6FV7DfS71jJQw1/0VxoUbNmWx3wTRkx+ozc24DFdvtm1+HgtuX71/XHsDgOCTOlhl pB/x9mM33QPMf2Si0ohwsZ9lOeQGvKA/9iF8NL7L774CC3DSbAbXa5ksMSldIGB5X+nK kFpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PkohWup9; 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 z81si9170471pfa.1.2018.01.08.16.27.25; Mon, 08 Jan 2018 16:27:26 -0800 (PST) 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=PkohWup9; 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 S1754583AbeAIA1X (ORCPT + 28 others); Mon, 8 Jan 2018 19:27:23 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:35039 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754139AbeAIA1V (ORCPT ); Mon, 8 Jan 2018 19:27:21 -0500 Received: by mail-lf0-f68.google.com with SMTP id h5so14022976lfj.2 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=O7A/bHJUjXZtA7cV3poqDNGuKf4YF2dnbz1DJ+C1/sJ9+af3RKXdgrMwBadVvcOYOY uXSKUKTWrA0kCC+XBN1eS8iPrHiTGsmu9HHmPaZdJoCcdgcemQ0P++BYYanneO+fjsaA Y0F6P8fAvr/AuNxZNHlklgvawk8eMmf1987IBqGz/UUahwdUtBJN9ew3e/Am70LYOByi V4WgCCXlyU9cWKMwkQ0ok4LeymWtGFy8q+Uo4guO/Ckb0oL/ybGi5PaeN0Rsp2BaDYUK kfnxEk+ffc2I4UfE5zT+EJMXHSbsc5aTqPM0upzCu8WuGuA/g66Pq+W1/OhsyntnLDMd X3cQ== X-Gm-Message-State: AKGB3mJGj5R6cOL5SOO9AIBMk5c9Zg+wOI638Zcfd/LFdsTt/9o1O4cv RhQj3mXVa2rsgzi5JngLakZl8HqqGpQ= 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(+) -- 2.14.3 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;