From patchwork Mon Oct 3 09:02:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 77207 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp1548246qgf; Mon, 3 Oct 2016 02:02:48 -0700 (PDT) X-Received: by 10.66.185.133 with SMTP id fc5mr36368770pac.71.1475485368091; Mon, 03 Oct 2016 02:02:48 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id lw6si13588199pab.233.2016.10.03.02.02.47; Mon, 03 Oct 2016 02:02:48 -0700 (PDT) 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=neutral (body hash did not verify) header.i=@linaro.org; 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=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751542AbcJCJCr (ORCPT + 4 others); Mon, 3 Oct 2016 05:02:47 -0400 Received: from mail-lf0-f54.google.com ([209.85.215.54]:35611 "EHLO mail-lf0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751469AbcJCJCq (ORCPT ); Mon, 3 Oct 2016 05:02:46 -0400 Received: by mail-lf0-f54.google.com with SMTP id l131so149109488lfl.2 for ; Mon, 03 Oct 2016 02:02:45 -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=GtiDRGXmbvjD7tG5VDDvfwapOZuuJO40glanbbeDUHo=; b=h3YkLzzJcar+fjnptR3VKIh9ThQGcPzBLp9GUR48rwuOzCxvv31am8Aw8PubMY6k1m v9zzO3Dhk5cjX+WMIK5x1BEfO6euakL4aR28QeqOToE8hnzzPNveEw+d7Zr+M4SGtDgO mYavy+0YkL/rfB233h0kyF3y6lYCfD02GsvyU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=GtiDRGXmbvjD7tG5VDDvfwapOZuuJO40glanbbeDUHo=; b=SZXCPYG0lSsIGXd9O9zCg+kbtL1OX64p9tbkJFORqxr9W4dHLHQvCH1EZB9vPfIn2e n0fENnEfVh8bK2pCE1MSWBc7g4+i9R4iBpVHn6UHDCpKe6bvHqW2I77NQEK53fJg5KIy t8MDQAWWUu3yFh6WJDPn+OQZTrYkZVHkAj22j278zVXrY4rwHJyyUgSFK80sRwX4ZHIG gSDtJI8GtBDYZl5k+1cCwqZwE55M1ECusBSiGjBeuO1p1V4U1blPZBm5UDpKTTiDKy7b JQGY8kBrQVeycmK9ZWpm7BLqgI/sSQ6l06a2gex7I1HVylrTHL+7iPghBKvBo0bJgZCk rNww== X-Gm-Message-State: AA6/9RkSbxCiOSvozo57pA8Z7aDmQNtTcLjQ9kMh1PbKYqY/mWrGJjTlMZALA8sNPzZ1zyrH X-Received: by 10.25.206.80 with SMTP id e77mr7473561lfg.103.1475485364211; Mon, 03 Oct 2016 02:02:44 -0700 (PDT) Received: from linuslaptop.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id j196sm5482594lfg.9.2016.10.03.02.02.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Oct 2016 02:02:43 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot Cc: Linus Walleij Subject: [PATCH 1/3] gpio: OF: separation of concerns Date: Mon, 3 Oct 2016 11:02:38 +0200 Message-Id: <1475485360-15127-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The generic GPIO library directly implement code for of_find_gpio() which is only used with CONFIG_OF and causes compilation problems on archs that do not even have stubs for OF functions, especially on UM that does not implement any IO remap functions. Move the function to gpiolib-of.c, implement a static inline stub in gpiolib.h returning PTR_ERR(-ENOENT) if CONFIG_OF_GPIO is not set and be done with it. Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib-of.c | 39 +++++++++++++++++++++++++++++++++++++++ drivers/gpio/gpiolib.c | 39 --------------------------------------- drivers/gpio/gpiolib.h | 16 ++++++++++++++++ 3 files changed, 55 insertions(+), 39 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 75e7b3919ea7..33b05c8de42f 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -114,6 +114,45 @@ int of_get_named_gpio_flags(struct device_node *np, const char *list_name, } EXPORT_SYMBOL(of_get_named_gpio_flags); +struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, + unsigned int idx, + enum gpio_lookup_flags *flags) +{ + char prop_name[32]; /* 32 is max size of property name */ + enum of_gpio_flags of_flags; + struct gpio_desc *desc; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) { + if (con_id) + snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id, + gpio_suffixes[i]); + else + snprintf(prop_name, sizeof(prop_name), "%s", + gpio_suffixes[i]); + + desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx, + &of_flags); + if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT)) + break; + } + + if (IS_ERR(desc)) + return desc; + + if (of_flags & OF_GPIO_ACTIVE_LOW) + *flags |= GPIO_ACTIVE_LOW; + + if (of_flags & OF_GPIO_SINGLE_ENDED) { + if (of_flags & OF_GPIO_ACTIVE_LOW) + *flags |= GPIO_OPEN_DRAIN; + else + *flags |= GPIO_OPEN_SOURCE; + } + + return desc; +} + /** * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API * @np: device node to get GPIO from diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 19a665f8d455..5404cdcfed19 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2883,45 +2883,6 @@ void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) mutex_unlock(&gpio_lookup_lock); } -static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, - unsigned int idx, - enum gpio_lookup_flags *flags) -{ - char prop_name[32]; /* 32 is max size of property name */ - enum of_gpio_flags of_flags; - struct gpio_desc *desc; - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) { - if (con_id) - snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id, - gpio_suffixes[i]); - else - snprintf(prop_name, sizeof(prop_name), "%s", - gpio_suffixes[i]); - - desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx, - &of_flags); - if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT)) - break; - } - - if (IS_ERR(desc)) - return desc; - - if (of_flags & OF_GPIO_ACTIVE_LOW) - *flags |= GPIO_ACTIVE_LOW; - - if (of_flags & OF_GPIO_SINGLE_ENDED) { - if (of_flags & OF_GPIO_ACTIVE_LOW) - *flags |= GPIO_OPEN_DRAIN; - else - *flags |= GPIO_OPEN_SOURCE; - } - - return desc; -} - static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id, unsigned int idx, diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 2d9ea5e0cab3..cc7fd56d7c9b 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -13,6 +13,7 @@ #define GPIOLIB_H #include +#include #include #include #include @@ -86,6 +87,21 @@ struct acpi_gpio_info { /* gpio suffixes used for ACPI and device tree lookup */ static const char * const gpio_suffixes[] = { "gpios", "gpio" }; +#ifdef CONFIG_OF_GPIO +struct gpio_desc *of_find_gpio(struct device *dev, + const char *con_id, + unsigned int idx, + enum gpio_lookup_flags *flags); +#else +static inline struct gpio_desc *of_find_gpio(struct device *dev, + const char *con_id, + unsigned int idx, + enum gpio_lookup_flags *flags) +{ + return ERR_PTR(-ENOENT); +} +#endif /* CONFIG_OF_GPIO */ + #ifdef CONFIG_ACPI void acpi_gpiochip_add(struct gpio_chip *chip); void acpi_gpiochip_remove(struct gpio_chip *chip);