From patchwork Fri Dec 14 16:19:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 13603 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 B292023FB4 for ; Fri, 14 Dec 2012 16:20:15 +0000 (UTC) Received: from mail-ia0-f180.google.com (mail-ia0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 3B652A18D6B for ; Fri, 14 Dec 2012 16:20:15 +0000 (UTC) Received: by mail-ia0-f180.google.com with SMTP id t4so3226409iag.11 for ; Fri, 14 Dec 2012 08:20:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:received-spf :from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=V4KUofwU/3Vvf8tC2VGDhjZYBIFJSCMPlfZEPvxeqRM=; b=Ma0IhvsTCM3zcUgRzdH63iw0hF2Ie2fYlNiiIBUnipXm+dE/QuuOVctEerLjmtQGuX xgY2ehkZR6rhaGmqKJZvXNsknHyjPV6SiV6kVqqKAXFRom6b8Ca63hlHVUozMlafeBSN Flza1OsJaTNvU0ZkZ3nZR2Jb96PYkpDq5TNxAa4Z5KWD8KJh6U+ReVIOe4dFcvDobsGI 1jSJhh2ScsJh2BnYrBmI8luXSCbBtXrCk9LcdERaJAHM7xPDNUuudFrxJaXRAk7xgomD PkU+AtYfg+oGXE37phbEpJnT8JQN6IRE59K6M6ON39NXXGICID/7YPdI8h2Pk3XSf6k/ YIKQ== X-Received: by 10.50.213.69 with SMTP id nq5mr2002181igc.70.1355502014664; Fri, 14 Dec 2012 08:20:14 -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.50.67.148 with SMTP id n20csp81609igt; Fri, 14 Dec 2012 08:20:14 -0800 (PST) Received: by 10.180.19.136 with SMTP id f8mr3250853wie.0.1355502013528; Fri, 14 Dec 2012 08:20:13 -0800 (PST) Received: from mail-wg0-f53.google.com (mail-wg0-f53.google.com [74.125.82.53]) by mx.google.com with ESMTPS id cx5si7991313wib.11.2012.12.14.08.20.13 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 14 Dec 2012 08:20:13 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.53 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.53; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.53 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by mail-wg0-f53.google.com with SMTP id ei8so1477567wgb.32 for ; Fri, 14 Dec 2012 08:20:13 -0800 (PST) Received: by 10.194.157.227 with SMTP id wp3mr4611796wjb.3.1355502013031; Fri, 14 Dec 2012 08:20:13 -0800 (PST) Received: from localhost.localdomain (cpc1-aztw13-0-0-cust473.18-1.cable.virginmedia.com. [77.102.241.218]) by mx.google.com with ESMTPS id u6sm8325248wif.2.2012.12.14.08.20.11 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 14 Dec 2012 08:20:12 -0800 (PST) From: Lee Jones To: linux-kernel@vger.kernel.org Cc: linus.walleij@linaro.org, Yang QU , Lee Jones Subject: [PATCH 17/21] gpio: ab8500: Add the action range for the internal pull up function on GPIO Date: Fri, 14 Dec 2012 16:19:35 +0000 Message-Id: <1355501979-1157-18-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1355501979-1157-1-git-send-email-lee.jones@linaro.org> References: <1355501979-1157-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQknydls1oc/mqL4AnETNJCX4XIvVXfvhqPeH+b48SgwiMLEbNxlRVCq6K9KeEJxgFyKV9oz From: Yang QU Only 4 GPIOs named GPIOx_VBAT have both internal pull up and pull down capability on ab8540. Limit the action range for this function. Signed-off-by: Lee Jones Signed-off-by: Yang QU Reviewed-by: Per FORLIN --- drivers/gpio/gpio-ab8500.c | 54 +++++++++++++++++--------------- include/linux/mfd/abx500/ab8500-gpio.h | 6 ++-- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/drivers/gpio/gpio-ab8500.c b/drivers/gpio/gpio-ab8500.c index ff8df1f..b4f631a 100644 --- a/drivers/gpio/gpio-ab8500.c +++ b/drivers/gpio/gpio-ab8500.c @@ -23,10 +23,12 @@ /* - * The AB9540 GPIO support is an extended version of the - * AB8500 GPIO support. The AB9540 supports an additional - * (7th) register so that more GPIO may be configured and - * used. + * The AB9540 and AB8540 GPIO support are extended versions + * of the AB8500 GPIO support. + * The AB9540 supports an additional (7th) register so that + * more GPIO may be configured and used. + * The AB8540 supports 4 new gpios (GPIOx_VBAT) that have + * internal pull-up and pull-down capabilities. */ /* @@ -636,46 +638,46 @@ int ab8500_config_pulldown(struct device *dev, } EXPORT_SYMBOL(ab8500_config_pulldown); -/* - * ab8540_config_pull_updown() only available for following GPIOs: - * GPIO51(GPIO1_VBAT) - * GPIO52(GPIO2_VBAT) - * GPIO53(GPIO3_VBAT) - * GPIO54(GPIO4_VBAT) - */ int ab8540_config_pull_updown(struct device *dev, - int gpio, enum ab8540_gpio_pull_updown reg) + int gpio, enum ab8540_gpio_pull_updown val) { - u8 offset = gpio - AB8500_PIN_GPIO(51); - u8 pos = 2 * offset; + u8 pos; int ret; + if ((gpio < AB8500_PIN_GPIO(51)) || (gpio > AB8500_PIN_GPIO(54))) { + ret = -EINVAL; + goto out; + } + + pos = (gpio - AB8500_PIN_GPIO(51)) << 1; + ret = abx500_mask_and_set_register_interruptible(dev, AB8500_MISC, AB8540_GPIO_PULL_UPDOWN_REG, - AB8540_GPIO_PULL_UPDOWN_MASK << pos, reg << pos); + AB8540_GPIO_PULL_UPDOWN_MASK << pos, val << pos); + +out: if (ret < 0) dev_err(dev, "%s failed (%d)\n", __func__, ret); return ret; } EXPORT_SYMBOL(ab8540_config_pull_updown); -/* - * ab8540_gpio_config_vinsel() only available for following GPIOs: - * GPIO51(GPIO1_VBAT) - * GPIO52(GPIO2_VBAT) - * GPIO53(GPIO3_VBAT) - * GPIO54(GPIO4_VBAT) - */ int ab8540_gpio_config_vinsel(struct device *dev, - int gpio, enum ab8540_gpio_vinsel reg) + int gpio, enum ab8540_gpio_vinsel val) { - u8 offset = gpio - AB8500_PIN_GPIO(51); - u8 pos = 2 * offset; + u8 pos; int ret; + if ((gpio < AB8500_PIN_GPIO(51)) || (gpio > AB8500_PIN_GPIO(54))) { + ret = -EINVAL; + goto out; + } + ret = abx500_mask_and_set_register_interruptible(dev, AB8500_MISC, AB8540_GPIO_VINSEL_REG, - AB8540_GPIO_VINSEL_MASK << pos, reg << pos); + AB8540_GPIO_VINSEL_MASK << pos, val << pos); + +out: if (ret < 0) dev_err(dev, "%s failed (%d)\n", __func__, ret); return ret; diff --git a/include/linux/mfd/abx500/ab8500-gpio.h b/include/linux/mfd/abx500/ab8500-gpio.h index 20df07d..86ccb33 100644 --- a/include/linux/mfd/abx500/ab8500-gpio.h +++ b/include/linux/mfd/abx500/ab8500-gpio.h @@ -39,11 +39,13 @@ enum ab8540_gpio_vinsel { int ab8500_config_pulldown(struct device *dev, int gpio, bool enable); +/* Selects pull up/pull down for GPIOx_VBAT, x=1 to 4 */ int ab8540_config_pull_updown(struct device *dev, - int gpio, enum ab8540_gpio_pull_updown reg); + int gpio, enum ab8540_gpio_pull_updown val); +/* Selects voltage for GPIOx_VBAT, x=1 to 4 */ int ab8540_gpio_config_vinsel(struct device *dev, - int gpio, enum ab8540_gpio_vinsel reg); + int gpio, enum ab8540_gpio_vinsel val); int ab8500_gpio_config_select(struct device *dev, int gpio, bool gpio_select);