linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lee Jones <lee.jones@linaro.org>
To: linux-kernel@vger.kernel.org
Cc: linus.walleij@linaro.org,
	Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>,
	Lee Jones <lee.jones@linaro.org>,
	Bengt Jonsson <bengt.g.jonsson@stericsson.com>
Subject: [PATCH 02/21] gpio: ab8500: Make pins configurable
Date: Fri, 14 Dec 2012 16:19:20 +0000	[thread overview]
Message-ID: <1355501979-1157-3-git-send-email-lee.jones@linaro.org> (raw)
In-Reply-To: <1355501979-1157-1-git-send-email-lee.jones@linaro.org>

From: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>

Make it possible to set the pin configuration either as gpio or specific
functionality through the driver interface.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
Signed-off-by: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
Tested-by: Jonas ABERG <jonas.aberg@stericsson.com>
---
 drivers/gpio/gpio-ab8500.c             |   63 ++++++++++++++++++++++++++++++++
 include/linux/mfd/abx500/ab8500-gpio.h |   51 ++++++++++++++++++++++++++
 2 files changed, 114 insertions(+)

diff --git a/drivers/gpio/gpio-ab8500.c b/drivers/gpio/gpio-ab8500.c
index db40acb..c3c7c5a 100644
--- a/drivers/gpio/gpio-ab8500.c
+++ b/drivers/gpio/gpio-ab8500.c
@@ -495,6 +495,69 @@ static int __devexit ab8500_gpio_remove(struct platform_device *pdev)
 	return 0;
 }
 
+/*
+ * ab8500_gpio_config_select()
+ *
+ * Configure functionality of pin, either specific use or GPIO.
+ * @dev: device pointer
+ * @gpio: gpio number
+ * @gpio_select: true if the pin should be used as GPIO
+ */
+int ab8500_gpio_config_select(struct device *dev,
+				enum ab8500_pin gpio, bool gpio_select)
+{
+	u8 offset = gpio - AB8500_PIN_GPIO1;
+	u8 reg = AB8500_GPIO_SEL1_REG + (offset / 8);
+	u8 pos = offset % 8;
+	u8 val = gpio_select ? 1 : 0;
+	int ret;
+
+	ret = abx500_mask_and_set_register_interruptible(dev,
+		AB8500_MISC, reg, 1 << pos, val << pos);
+	if (ret < 0)
+		dev_err(dev, "%s write failed\n", __func__);
+
+	dev_vdbg(dev, "%s (bank, addr, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
+		__func__, AB8500_MISC, reg, 1 << pos, val << pos);
+
+	return ret;
+}
+
+/*
+ * ab8500_gpio_config_get_select()
+ *
+ * Read currently configured functionality, either specific use or GPIO.
+ * @dev: device pointer
+ * @gpio: gpio number
+ * @gpio_select: pointer to pin selection status
+ */
+int ab8500_gpio_config_get_select(struct device *dev,
+					enum ab8500_pin gpio, bool *gpio_select)
+{
+	u8 offset =  gpio - AB8500_PIN_GPIO1;
+	u8 reg = AB8500_GPIO_SEL1_REG + (offset / 8);
+	u8 pos = offset % 8;
+	u8 val;
+	int ret;
+
+	ret = abx500_get_register_interruptible(dev,
+				AB8500_MISC, reg, &val);
+	if (ret < 0) {
+		dev_err(dev, "%s read failed\n", __func__);
+		return ret;
+	}
+
+	if (val & (1 << pos))
+		*gpio_select = true;
+	else
+		*gpio_select = false;
+
+	dev_vdbg(dev, "%s (bank, addr, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
+		__func__, AB8500_MISC, reg, 1 << pos, val);
+
+	return 0;
+}
+
 static struct platform_driver ab8500_gpio_driver = {
 	.driver = {
 		.name = "ab8500-gpio",
diff --git a/include/linux/mfd/abx500/ab8500-gpio.h b/include/linux/mfd/abx500/ab8500-gpio.h
index 2387c20..5caa615 100644
--- a/include/linux/mfd/abx500/ab8500-gpio.h
+++ b/include/linux/mfd/abx500/ab8500-gpio.h
@@ -20,4 +20,55 @@ struct ab8500_gpio_platform_data {
 	u8  config_reg[8];
 };
 
+enum ab8500_pin {
+	AB8500_PIN_GPIO1 = 0,
+	AB8500_PIN_GPIO2,
+	AB8500_PIN_GPIO3,
+	AB8500_PIN_GPIO4,
+	AB8500_PIN_GPIO5,
+	AB8500_PIN_GPIO6,
+	AB8500_PIN_GPIO7,
+	AB8500_PIN_GPIO8,
+	AB8500_PIN_GPIO9,
+	AB8500_PIN_GPIO10,
+	AB8500_PIN_GPIO11,
+	AB8500_PIN_GPIO12,
+	AB8500_PIN_GPIO13,
+	AB8500_PIN_GPIO14,
+	AB8500_PIN_GPIO15,
+	AB8500_PIN_GPIO16,
+	AB8500_PIN_GPIO17,
+	AB8500_PIN_GPIO18,
+	AB8500_PIN_GPIO19,
+	AB8500_PIN_GPIO20,
+	AB8500_PIN_GPIO21,
+	AB8500_PIN_GPIO22,
+	AB8500_PIN_GPIO23,
+	AB8500_PIN_GPIO24,
+	AB8500_PIN_GPIO25,
+	AB8500_PIN_GPIO26,
+	AB8500_PIN_GPIO27,
+	AB8500_PIN_GPIO28,
+	AB8500_PIN_GPIO29,
+	AB8500_PIN_GPIO30,
+	AB8500_PIN_GPIO31,
+	AB8500_PIN_GPIO32,
+	AB8500_PIN_GPIO33,
+	AB8500_PIN_GPIO34,
+	AB8500_PIN_GPIO35,
+	AB8500_PIN_GPIO36,
+	AB8500_PIN_GPIO37,
+	AB8500_PIN_GPIO38,
+	AB8500_PIN_GPIO39,
+	AB8500_PIN_GPIO40,
+	AB8500_PIN_GPIO41,
+	AB8500_PIN_GPIO42,
+};
+
+int ab8500_gpio_config_select(struct device *dev,
+				enum ab8500_pin gpio, bool gpio_select);
+
+int ab8500_gpio_config_get_select(struct device *dev,
+				enum ab8500_pin	gpio, bool *gpio_select);
+
 #endif /* _AB8500_GPIO_H */
-- 
1.7.9.5


  parent reply	other threads:[~2012-12-14 16:25 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-14 16:19 [PATCH 00/21] gpio: ab8500: Bring AB8500 back to life Lee Jones
2012-12-14 16:19 ` [PATCH 01/21] gpio: ab8500: Activate and port AB8500 GPIO driver to new framework Lee Jones
2012-12-14 16:19 ` Lee Jones [this message]
2012-12-14 16:19 ` [PATCH 03/21] gpio: ab8500: Fix alternate function register address Lee Jones
2012-12-14 16:19 ` [PATCH 04/21] gpio: ab8500: Read register corrected in get_value api Lee Jones
2012-12-14 16:19 ` [PATCH 05/21] gpio: ab8500: Allow direction and pullups configuration Lee Jones
2012-12-14 16:19 ` [PATCH 06/21] gpio: ab8500: Add api to enable pulldown Lee Jones
2012-12-14 16:19 ` [PATCH 07/21] gpio: ab8500: Write argument value instead of hardwired 1 Lee Jones
2012-12-14 16:19 ` [PATCH 08/21] gpio: ab8500: Fix gpio offset bounds for irq mapping Lee Jones
2012-12-14 16:19 ` [PATCH 09/21] gpio: ab8500: Fix bad include name after renaming Lee Jones
2012-12-14 16:19 ` [PATCH 10/21] gpio: ab8500: Add support for the AB9540 Lee Jones
2012-12-14 16:19 ` [PATCH 11/21] gpio: ab8500: Add support for AB8505 Chip Lee Jones
2012-12-14 16:19 ` [PATCH 12/21] gpio: ab8500: Allow gpios to wake the system from suspend Lee Jones
2012-12-14 16:19 ` [PATCH 13/21] gpio: ab8500: Use most recent run-time platform checker Lee Jones
2012-12-14 16:19 ` [PATCH 14/21] gpio: ab8500: Remove ENUMs from linux/mfd/abx500/ab8500-gpio.h Lee Jones
2012-12-14 16:19 ` [PATCH 15/21] gpio: ab8500: Add support for the ab8540 Lee Jones
2012-12-14 16:19 ` [PATCH 16/21] gpio: ab8500: Add internal pull up on GPIO of ab8540 Lee Jones
2012-12-14 16:19 ` [PATCH 17/21] gpio: ab8500: Add the action range for the internal pull up function on GPIO Lee Jones
2012-12-14 16:19 ` [PATCH 18/21] gpio: ab8500: Fix parameter uninitialized warning for ab8540 Lee Jones
2012-12-14 16:19 ` [PATCH 19/21] gpio: ab8500: Update gpio ab8540 interrupt mapping Lee Jones
2012-12-14 16:19 ` [PATCH 20/21] gpio: ab8500: Fix ab8540 setting direction output error Lee Jones
2012-12-14 16:19 ` [PATCH 21/21] gpio: ab8500: Add explicit dependencies Lee Jones
2012-12-19 14:18 ` [PATCH 00/21] gpio: ab8500: Bring AB8500 back to life Linus Walleij
2012-12-19 22:49   ` Grant Likely
2012-12-20  7:51     ` Lee Jones
2013-01-04 14:17   ` Linus Walleij
2013-01-04 14:46     ` Lee Jones
2012-12-19 22:26 ` Grant Likely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1355501979-1157-3-git-send-email-lee.jones@linaro.org \
    --to=lee.jones@linaro.org \
    --cc=bengt.g.jonsson@stericsson.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mian.yousaf.kaukab@stericsson.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).