Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp567827imj; Thu, 7 Feb 2019 08:31:28 -0800 (PST) X-Google-Smtp-Source: AHgI3IY+Phsct9++RO4OVLroyACVOuabrL23GaD29n/fz/qAdwPzHy997TfQ+DXqTfzRQpax5mda X-Received: by 2002:a62:4181:: with SMTP id g1mr16946062pfd.45.1549557088790; Thu, 07 Feb 2019 08:31:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549557088; cv=none; d=google.com; s=arc-20160816; b=fdArOVXuJKV3G1kUj5gFrRSY3QuWKOVheKBxBAXKSIdVZYu7hb8oL36J5hSR4l/8m8 eBzadnaYaLz3Xtj0JDrI5EwxEPzs24dMQTFWlSYGAU0xv0aR1cE75jY1c0+3VhODH2Qs 1QHEgFBdkgfldHH8KZ9kbeTR9QUbZjVWrtQeQkuW6OMYqp3urd/b0uJMiUi7wxz535OR 6kyZdc+cX9ls6Q8nLUtaABO7pcWPWho7HVNmtnnu4XVlaTauqdcrtrcWYtTWQ3mcNKXE AVWkvYVGO1aQaYzBmjf8XEdGbXIn8QwDHtB0CWuKsV9Bi7yXYkVwh4YivbBHJDt1GiNo STeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/UPi/I3DzLgi8AxSCxdtKs5W0SVlcYMRdfn6Y70eU4E=; b=cI5C9OL3sgvD+meI+l6kS+wfnbUvLNeDVcmuSl/jZvF50FXLEyZ0lwpev2oUIgQy8C e8hvs3UpqqoEXxrYo9i00Wasmy5nzpxz2J3IRE5zRQeNtfi0xGZYv8TFgt8i9qPVjhWC FV9crMkkW8aw/nSJzTxI32wV5M6dnh8GvCN80j3kL2XTRKG56KGlqwl9UL7QcWQxcZur o9aKROkWRmyuNoV7G5Rx4ZgTakDSZafoVUUdS6mt3H1paE20P1VNbeTmDAf32GRcy24f pxJ58x9ZuPzZb87xCJtGWqy7R9mgwqxr3LeNqvk5iqXqSp146qrUFgH24/ep97HgFclL Ffng== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m10si8780143plt.295.2019.02.07.08.31.13; Thu, 07 Feb 2019 08:31:28 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727120AbfBGQ3V (ORCPT + 99 others); Thu, 7 Feb 2019 11:29:21 -0500 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:49185 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727021AbfBGQ3R (ORCPT ); Thu, 7 Feb 2019 11:29:17 -0500 X-Originating-IP: 90.88.22.177 Received: from localhost (aaubervilliers-681-1-80-177.w90-88.abo.wanadoo.fr [90.88.22.177]) (Authenticated sender: thomas.petazzoni@bootlin.com) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id E65FC20006; Thu, 7 Feb 2019 16:29:13 +0000 (UTC) From: Thomas Petazzoni To: Linus Walleij , Bartosz Golaszewski , Rob Herring , Mark Rutland , Frank Rowand Cc: linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Jan=20Kundr=C3=A1t?= , Thomas Petazzoni Subject: [PATCH v2 4/5] gpio: add core support for pull-up/pull-down configuration Date: Thu, 7 Feb 2019 17:28:58 +0100 Message-Id: <20190207162859.26252-5-thomas.petazzoni@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207162859.26252-1-thomas.petazzoni@bootlin.com> References: <20190207162859.26252-1-thomas.petazzoni@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit adds support for configuring the pull-up and pull-down resistors available in some GPIO controllers. While configuring pull-up/pull-down is already possible through the pinctrl subsystem, some GPIO controllers, especially simple ones such as GPIO expanders on I2C, don't have any pinmuxing capability and therefore do not use the pinctrl subsystem. This commit implements the GPIO_PULL_UP and GPIO_PULL_DOWN flags, which can be used from the Device Tree, to enable a pull-up or pull-down resistor on a given GPIO. The flag is simply propagated all the way to the core GPIO subsystem, where it is used to call the gpio_chip ->set_config callback with the appropriate existing PIN_CONFIG_BIAS_* values. Signed-off-by: Thomas Petazzoni --- drivers/gpio/gpiolib-of.c | 5 +++++ drivers/gpio/gpiolib.c | 18 ++++++++++++++++++ drivers/gpio/gpiolib.h | 2 ++ include/linux/gpio/machine.h | 2 ++ include/linux/of_gpio.h | 2 ++ 5 files changed, 29 insertions(+) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index a6e1891217e2..9a8b78477f79 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -345,6 +345,11 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, if (of_flags & OF_GPIO_TRANSITORY) *flags |= GPIO_TRANSITORY; + if (of_flags & OF_GPIO_PULL_UP) + *flags |= GPIO_PULL_UP; + if (of_flags & OF_GPIO_PULL_DOWN) + *flags |= GPIO_PULL_DOWN; + return desc; } diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 9762a836fec9..9be4c9401172 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2610,6 +2610,13 @@ int gpiod_direction_input(struct gpio_desc *desc) if (status == 0) clear_bit(FLAG_IS_OUT, &desc->flags); + if (test_bit(FLAG_PULL_UP, &desc->flags)) + gpio_set_config(chip, gpio_chip_hwgpio(desc), + PIN_CONFIG_BIAS_PULL_UP); + else if (test_bit(FLAG_PULL_DOWN, &desc->flags)) + gpio_set_config(chip, gpio_chip_hwgpio(desc), + PIN_CONFIG_BIAS_PULL_DOWN); + trace_gpio_direction(desc_to_gpio(desc), 1, status); return status; @@ -4087,6 +4094,17 @@ int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, if (lflags & GPIO_OPEN_SOURCE) set_bit(FLAG_OPEN_SOURCE, &desc->flags); + if ((lflags & GPIO_PULL_UP) && (lflags & GPIO_PULL_DOWN)) { + gpiod_err(desc, + "both pull-up and pull-down enabled, invalid configuration\n"); + return -EINVAL; + } + + if (lflags & GPIO_PULL_UP) + set_bit(FLAG_PULL_UP, &desc->flags); + else if (lflags & GPIO_PULL_DOWN) + set_bit(FLAG_PULL_DOWN, &desc->flags); + status = gpiod_set_transitory(desc, (lflags & GPIO_TRANSITORY)); if (status < 0) return status; diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index bc57f0dc5953..078ab17b96bf 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -219,6 +219,8 @@ struct gpio_desc { #define FLAG_IRQ_IS_ENABLED 10 /* GPIO is connected to an enabled IRQ */ #define FLAG_IS_HOGGED 11 /* GPIO is hogged */ #define FLAG_TRANSITORY 12 /* GPIO may lose value in sleep or reset */ +#define FLAG_PULL_UP 13 /* GPIO has pull up enabled */ +#define FLAG_PULL_DOWN 14 /* GPIO has pull down enabled */ /* Connection label */ const char *label; diff --git a/include/linux/gpio/machine.h b/include/linux/gpio/machine.h index daa44eac9241..69673be10213 100644 --- a/include/linux/gpio/machine.h +++ b/include/linux/gpio/machine.h @@ -12,6 +12,8 @@ enum gpio_lookup_flags { GPIO_OPEN_SOURCE = (1 << 2), GPIO_PERSISTENT = (0 << 3), GPIO_TRANSITORY = (1 << 3), + GPIO_PULL_UP = (1 << 4), + GPIO_PULL_DOWN = (1 << 5), }; /** diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h index 163b79ecd01a..f9737dea9d1f 100644 --- a/include/linux/of_gpio.h +++ b/include/linux/of_gpio.h @@ -28,6 +28,8 @@ enum of_gpio_flags { OF_GPIO_SINGLE_ENDED = 0x2, OF_GPIO_OPEN_DRAIN = 0x4, OF_GPIO_TRANSITORY = 0x8, + OF_GPIO_PULL_UP = 0x10, + OF_GPIO_PULL_DOWN = 0x20, }; #ifdef CONFIG_OF_GPIO -- 2.20.1