From patchwork Mon Nov 14 09:10:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 5092 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 2802123E10 for ; Mon, 14 Nov 2011 09:11:05 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id 16FE2A18059 for ; Mon, 14 Nov 2011 09:11:05 +0000 (UTC) Received: by faaa26 with SMTP id a26so204653faa.11 for ; Mon, 14 Nov 2011 01:11:05 -0800 (PST) Received: by 10.152.104.1 with SMTP id ga1mr13318629lab.40.1321261864876; Mon, 14 Nov 2011 01:11:04 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.40.7 with SMTP id t7cs32407lak; Mon, 14 Nov 2011 01:11:04 -0800 (PST) Received: by 10.14.4.229 with SMTP id 77mr1143249eej.133.1321261863103; Mon, 14 Nov 2011 01:11:03 -0800 (PST) Received: from eu1sys200aog104.obsmtp.com (eu1sys200aog104.obsmtp.com. [207.126.144.117]) by mx.google.com with SMTP id 70si4743051eet.52.2011.11.14.01.10.58 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 14 Nov 2011 01:11:03 -0800 (PST) Received-SPF: neutral (google.com: 207.126.144.117 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.117; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.117 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) smtp.mail=linus.walleij@stericsson.com Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob104.postini.com ([207.126.147.11]) with SMTP ID DSNKTsDbIDeFKnZXff5pSf2RDgKC8KX9z2HI@postini.com; Mon, 14 Nov 2011 09:11:03 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 6561D19F; Mon, 14 Nov 2011 09:10:44 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 9FCFA1B77; Mon, 14 Nov 2011 09:10:43 +0000 (GMT) Received: from exdcvycastm003.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm003", Issuer "exdcvycastm003" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id CA65824C2FB; Mon, 14 Nov 2011 10:10:36 +0100 (CET) Received: from localhost.localdomain (10.230.100.153) by smtp.stericsson.com (10.230.100.1) with Microsoft SMTP Server (TLS) id 8.3.83.0; Mon, 14 Nov 2011 10:10:40 +0100 From: Linus Walleij To: , Stephen Warren Cc: Grant Likely , Barry Song <21cnbao@gmail.com>, Shawn Guo , Thomas Abraham , Linus Walleij Subject: [PATCH] pinctrl: indicate GPIO direction on single GPIO request Date: Mon, 14 Nov 2011 10:10:37 +0100 Message-ID: <1321261837-31320-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.3.2 MIME-Version: 1.0 From: Linus Walleij When requesting a single GPIO pin to be muxed in, some controllers will need to poke a different value into the control register depending on whether the pin will be used for GPIO output or GPIO input. So pass this info along for the gpio_request_enable() function, we assume this is not needed for the gpio_free_disable() function for the time being. Suggested-by: Thomas Abraham Signed-off-by: Linus Walleij --- drivers/pinctrl/pinmux.c | 16 +++++++++++----- include/linux/pinctrl/pinmux.h | 14 ++++++++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c index d27b77d..ef2f812 100644 --- a/drivers/pinctrl/pinmux.c +++ b/drivers/pinctrl/pinmux.c @@ -100,10 +100,13 @@ struct pinmux_hog { * means that you want to mux in the pin for use as GPIO number NN * @gpio_range: the range matching the GPIO pin if this is a request for a * single GPIO pin + * @gpio_direction: if the pin is muxed for GPIO, this provides the direction + * of the GPIO @true means output, @false means input */ static int pin_request(struct pinctrl_dev *pctldev, int pin, const char *function, - struct pinctrl_gpio_range *gpio_range) + struct pinctrl_gpio_range *gpio_range, + bool gpio_direction) { struct pin_desc *desc; const struct pinmux_ops *ops = pctldev->desc->pmxops; @@ -148,7 +151,8 @@ static int pin_request(struct pinctrl_dev *pctldev, */ if (gpio_range && ops->gpio_request_enable) /* This requests and enables a single GPIO pin */ - status = ops->gpio_request_enable(pctldev, gpio_range, pin); + status = ops->gpio_request_enable(pctldev, gpio_range, pin, + gpio_direction); else if (ops->request) status = ops->request(pctldev, pin); else @@ -218,8 +222,10 @@ static const char *pin_free(struct pinctrl_dev *pctldev, int pin, /** * pinmux_request_gpio() - request a single pin to be muxed in as GPIO * @gpio: the GPIO pin number from the GPIO subsystem number space + * @direction: the direction of the GPIO, @true means output, @false + * means input */ -int pinmux_request_gpio(unsigned gpio) +int pinmux_request_gpio(unsigned gpio, bool direction) { char gpiostr[16]; const char *function; @@ -242,7 +248,7 @@ int pinmux_request_gpio(unsigned gpio) if (!function) return -EINVAL; - ret = pin_request(pctldev, pin, function, range); + ret = pin_request(pctldev, pin, function, range, direction); if (ret < 0) kfree(function); @@ -360,7 +366,7 @@ static int acquire_pins(struct pinctrl_dev *pctldev, /* Try to allocate all pins in this group, one by one */ for (i = 0; i < num_pins; i++) { - ret = pin_request(pctldev, pins[i], func, NULL); + ret = pin_request(pctldev, pins[i], func, NULL, false); if (ret) { dev_err(&pctldev->dev, "could not get pin %d for function %s " diff --git a/include/linux/pinctrl/pinmux.h b/include/linux/pinctrl/pinmux.h index bb7a979..7d3841f 100644 --- a/include/linux/pinctrl/pinmux.h +++ b/include/linux/pinctrl/pinmux.h @@ -54,7 +54,12 @@ struct pinctrl_dev; * Implement this only if you can mux every pin individually as GPIO. The * affected GPIO range is passed along with an offset(pin number) into that * specific GPIO range - function selectors and pin groups are orthogonal - * to this, the core will however make sure the pins do not collide + * to this, the core will however make sure the pins do not collide. Since + * controllers may be needing different configurations depending on + * whether the GPIO is configured as input or output, a direction + * indicator is passed along + * @gpio_disable_free: free up GPIO muxing on a certain pin, the reverse of + * @gpio_request_enable */ struct pinmux_ops { int (*request) (struct pinctrl_dev *pctldev, unsigned offset); @@ -72,14 +77,15 @@ struct pinmux_ops { unsigned group_selector); int (*gpio_request_enable) (struct pinctrl_dev *pctldev, struct pinctrl_gpio_range *range, - unsigned offset); + unsigned offset, + bool direction); void (*gpio_disable_free) (struct pinctrl_dev *pctldev, struct pinctrl_gpio_range *range, unsigned offset); }; /* External interface to pinmux */ -extern int pinmux_request_gpio(unsigned gpio); +extern int pinmux_request_gpio(unsigned gpio, bool direction); extern void pinmux_free_gpio(unsigned gpio); extern struct pinmux * __must_check pinmux_get(struct device *dev, const char *name); extern void pinmux_put(struct pinmux *pmx); @@ -88,7 +94,7 @@ extern void pinmux_disable(struct pinmux *pmx); #else /* !CONFIG_PINMUX */ -static inline int pinmux_request_gpio(unsigned gpio) +static inline int pinmux_request_gpio(unsigned gpio, bool direction) { return 0; }