From patchwork Tue Feb 16 14:46:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 62035 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1706127lbl; Tue, 16 Feb 2016 06:46:26 -0800 (PST) X-Received: by 10.66.152.204 with SMTP id va12mr31418618pab.0.1455633986367; Tue, 16 Feb 2016 06:46:26 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id tx10si17493754pac.146.2016.02.16.06.46.26; Tue, 16 Feb 2016 06:46:26 -0800 (PST) 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; 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; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932142AbcBPOqZ (ORCPT + 4 others); Tue, 16 Feb 2016 09:46:25 -0500 Received: from mail-lb0-f175.google.com ([209.85.217.175]:36416 "EHLO mail-lb0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754189AbcBPOqY (ORCPT ); Tue, 16 Feb 2016 09:46:24 -0500 Received: by mail-lb0-f175.google.com with SMTP id x1so18169656lbj.3 for ; Tue, 16 Feb 2016 06:46:24 -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=c94gi7A6ezcLaJ/lWDX8UXYSJ8Mx7oMEsnT7uUzR0zU=; b=NT49wGcWVveY/6qYtyCqBnUEUAiEHB1bAmmyzb5jkTwaX4df6RFvAS2+6lMSg+PgDQ Qy5RIEPFiz26U5GweOhTT8Y7R+cIWPN9QfKYWoepHIY6SmNbTL9pSnDQA2gdX3WSMMpe bxOP7xDwhCFVni+IGkwlVOQPaANlFPxVB0gy0= 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=c94gi7A6ezcLaJ/lWDX8UXYSJ8Mx7oMEsnT7uUzR0zU=; b=IVpYmO0ghHXo6ushF8wLM+uzVwQIK1PkqRNixBzIBmyFJjRpyp/1yqeFwpgKGg9SRb OAVYP7NePbj6aO1ODLu5aTcmoRiLlM0XX7pX7d0e43W62upy3mAPADdtNtj+VdHaPx11 ELBeID96NCRolwpkrD7zdKbEwtWwHM8ehZK9Zt5+de3NBuV7gGxQBJppuVpAyOiPtfx6 6MKYqzCzQGhNKBvR097NYcyOljXH6YnhxOLMHTh6cbiwudoU2tZw1UPJ8fqPJ3Hxexl9 C+ZFVS4qTSJW/ql1yHcSRB+e7ngNlETm3Y0qJCsRMvTJzvyOQC/IUApFORJfVXPFuk2H JJUw== X-Gm-Message-State: AG10YOQmAImP64Iuh6vS1D4PIBdvxMRXdawNYsrqhjtOP/5Ntq7Z6nmI4eIIPa0ELVJZTESI X-Received: by 10.112.161.104 with SMTP id xr8mr9849003lbb.29.1455633983341; Tue, 16 Feb 2016 06:46:23 -0800 (PST) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id rk1sm4399877lbb.0.2016.02.16.06.46.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Feb 2016 06:46:22 -0800 (PST) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot , Stephen Rothwell Cc: Linus Walleij , Nicolas Saenz Julienne Subject: [PATCH] gpio: create an API to detect open drain/source on lines Date: Tue, 16 Feb 2016 15:46:19 +0100 Message-Id: <1455633979-30970-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org My left hand merges code to privatize the descriptor handling while my right hand merges drivers that poke around and disrespect with the same gpiolib internals. So let's expose the proper APIs for drivers to ask the gpiolib core if a line is marked as open drain or open source and get some order around things so this driver compiles again. Reported-by: Stephen Rothwell Cc: Nicolas Saenz Julienne Signed-off-by: Linus Walleij --- drivers/gpio/gpio-tps65218.c | 9 ++++----- drivers/gpio/gpiolib.c | 18 ++++++++++++++++++ include/linux/gpio/driver.h | 4 ++++ 3 files changed, 26 insertions(+), 5 deletions(-) -- 2.4.3 -- 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/gpio-tps65218.c b/drivers/gpio/gpio-tps65218.c index 7b02f7be9bc9..9eb1a5ab2d95 100644 --- a/drivers/gpio/gpio-tps65218.c +++ b/drivers/gpio/gpio-tps65218.c @@ -71,17 +71,16 @@ static int tps65218_gpio_request(struct gpio_chip *gc, unsigned offset) { struct tps65218_gpio *tps65218_gpio = gpiochip_get_data(gc); struct tps65218 *tps65218 = tps65218_gpio->tps65218; - unsigned long flags = gc->desc[offset].flags; int ret; - if (flags & FLAG_OPEN_SOURCE) { + if (gpiochip_line_is_open_source(gc, offset)) { dev_err(gc->parent, "can't work as open source\n"); return -EINVAL; } switch (offset) { case 0: - if (!(flags & FLAG_OPEN_DRAIN)) { + if (!gpiochip_line_is_open_drain(gc, offset)) { dev_err(gc->parent, "GPO1 works only as open drain\n"); return -EINVAL; } @@ -103,7 +102,7 @@ static int tps65218_gpio_request(struct gpio_chip *gc, unsigned offset) break; case 1: /* GP02 is push-pull by default, can be set as open drain. */ - if (flags & FLAG_OPEN_DRAIN) { + if (gpiochip_line_is_open_drain(gc, offset)) { ret = tps65218_clear_bits(tps65218, TPS65218_REG_CONFIG1, TPS65218_CONFIG1_GPO2_BUF, @@ -122,7 +121,7 @@ static int tps65218_gpio_request(struct gpio_chip *gc, unsigned offset) break; case 2: - if (!(flags & FLAG_OPEN_DRAIN)) { + if (!gpiochip_line_is_open_drain(gc, offset)) { dev_err(gc->parent, "GPO3 works only as open drain\n"); return -EINVAL; } diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index aa4a60e19339..d8511cd68e7b 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1901,6 +1901,24 @@ bool gpiochip_line_is_irq(struct gpio_chip *chip, unsigned int offset) } EXPORT_SYMBOL_GPL(gpiochip_line_is_irq); +bool gpiochip_line_is_open_drain(struct gpio_chip *chip, unsigned int offset) +{ + if (offset >= chip->ngpio) + return false; + + return test_bit(FLAG_OPEN_DRAIN, &chip->gpiodev->descs[offset].flags); +} +EXPORT_SYMBOL_GPL(gpiochip_line_is_open_drain); + +bool gpiochip_line_is_open_source(struct gpio_chip *chip, unsigned int offset) +{ + if (offset >= chip->ngpio) + return false; + + return test_bit(FLAG_OPEN_SOURCE, &chip->gpiodev->descs[offset].flags); +} +EXPORT_SYMBOL_GPL(gpiochip_line_is_open_source); + /** * gpiod_get_raw_value_cansleep() - return a gpio's raw value * @desc: gpio whose value will be returned diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index b92ab9efdb69..ff96d0f9fceb 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -199,6 +199,10 @@ int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset); void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset); bool gpiochip_line_is_irq(struct gpio_chip *chip, unsigned int offset); +/* Line status inquiry for drivers */ +bool gpiochip_line_is_open_drain(struct gpio_chip *chip, unsigned int offset); +bool gpiochip_line_is_open_source(struct gpio_chip *chip, unsigned int offset); + /* get driver data */ void *gpiochip_get_data(struct gpio_chip *chip);