devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ian Lartey <ian@slimlogic.co.uk>
To: linux-kernel@vger.kernel.org
Cc: linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-leds@vger.kernel.org, linux-watchdog@vger.kernel.org,
	devicetree-discuss@lists.ozlabs.org, swarren@wwwdotorg.org,
	grant.likely@secretlab.ca, broonie@opensource.wolfsonmicro.com,
	rob.herring@calxeda.com, rob@landley.net, mturquette@linaro.org,
	linus.walleij@linaro.org, cooloney@gmail.com,
	sfr@canb.auug.org.au, rpurdie@rpsys.net,
	akpm@linux-foundation.org, sameo@linux.intel.com, wim@iguana.be,
	lgirdwood@gmail.com, gg@slimlogic.co.uk, j-keerthy@ti.com,
	ldewangan@nvidia.com, t-kristo@ti.com
Subject: [PATCH v10 06/12] gpio: palmas: add in GPIO support for palmas charger
Date: Fri, 22 Mar 2013 14:55:16 +0000	[thread overview]
Message-ID: <1363964122-19201-7-git-send-email-ian@slimlogic.co.uk> (raw)
In-Reply-To: <1363964122-19201-1-git-send-email-ian@slimlogic.co.uk>

Palmas charger has 16 GPIOs
add palmas_gpio_[read|write|update] api to take account
second bank of GPIOs

Signed-off-by: Ian Lartey <ian@slimlogic.co.uk>
Signed-off-by: Graeme Gregory <gg@slimlogic.co.uk>
---
 drivers/gpio/gpio-palmas.c |   77 ++++++++++++++++++++++++++++++++++++--------
 include/linux/mfd/palmas.h |   12 ++++++-
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/drivers/gpio/gpio-palmas.c b/drivers/gpio/gpio-palmas.c
index e3a4e56..636648c 100644
--- a/drivers/gpio/gpio-palmas.c
+++ b/drivers/gpio/gpio-palmas.c
@@ -1,7 +1,7 @@
 /*
- * TI Palma series PMIC's GPIO driver.
+ * TI Palmas series PMIC's GPIO driver.
  *
- * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (c) 2012-2012, NVIDIA CORPORATION.  All rights reserved.
  *
  * Author: Laxman Dewangan <ldewangan@nvidia.com>
  *
@@ -31,6 +31,36 @@ struct palmas_gpio {
 	struct palmas *palmas;
 };
 
+static int palmas_gpio_read(struct palmas *palmas, unsigned int reg,
+		int gpio, unsigned int *dest)
+{
+	/* registers for second bank are identical and offset by 0x9 */
+	if (gpio > 7)
+		reg += PALMAS_GPIO_DATA_IN2;
+
+	return palmas_read(palmas, PALMAS_GPIO_BASE, reg, dest);
+}
+
+static int palmas_gpio_write(struct palmas *palmas, unsigned int reg,
+		int gpio, unsigned int data)
+{
+	/* registers for second bank are identical and offset by 0x9 */
+	if (gpio > 7)
+		reg += PALMAS_GPIO_DATA_IN2;
+
+	return palmas_write(palmas, PALMAS_GPIO_BASE, reg, data);
+}
+
+static int palmas_gpio_update_bits(struct palmas *palmas, unsigned int reg,
+		int gpio, unsigned int mask, unsigned int data)
+{
+	/* registers for second bank are identical and offset by 0x9 */
+	if (gpio > 7)
+		reg += PALMAS_GPIO_DATA_IN2;
+
+	return palmas_update_bits(palmas, PALMAS_GPIO_BASE, reg, mask, data);
+}
+
 static inline struct palmas_gpio *to_palmas_gpio(struct gpio_chip *chip)
 {
 	return container_of(chip, struct palmas_gpio, gpio_chip);
@@ -43,12 +73,12 @@ static int palmas_gpio_get(struct gpio_chip *gc, unsigned offset)
 	unsigned int val;
 	int ret;
 
-	ret = palmas_read(palmas, PALMAS_GPIO_BASE, PALMAS_GPIO_DATA_IN, &val);
+	ret = palmas_gpio_read(palmas, PALMAS_GPIO_DATA_IN, offset, &val);
 	if (ret < 0) {
 		dev_err(gc->dev, "GPIO_DATA_IN read failed, err = %d\n", ret);
 		return ret;
 	}
-	return !!(val & BIT(offset));
+	return !!(val & BIT(offset % 8));
 }
 
 static void palmas_gpio_set(struct gpio_chip *gc, unsigned offset,
@@ -59,11 +89,11 @@ static void palmas_gpio_set(struct gpio_chip *gc, unsigned offset,
 	int ret;
 
 	if (value)
-		ret = palmas_write(palmas, PALMAS_GPIO_BASE,
-				PALMAS_GPIO_SET_DATA_OUT, BIT(offset));
+		ret = palmas_gpio_write(palmas, PALMAS_GPIO_SET_DATA_OUT,
+				offset, BIT(offset % 8));
 	else
-		ret = palmas_write(palmas, PALMAS_GPIO_BASE,
-				PALMAS_GPIO_CLEAR_DATA_OUT, BIT(offset));
+		ret = palmas_gpio_write(palmas, PALMAS_GPIO_CLEAR_DATA_OUT,
+				offset, BIT(offset % 8));
 	if (ret < 0)
 		dev_err(gc->dev, "%s write failed, err = %d\n",
 			(value) ? "GPIO_SET_DATA_OUT" : "GPIO_CLEAR_DATA_OUT",
@@ -80,8 +110,8 @@ static int palmas_gpio_output(struct gpio_chip *gc, unsigned offset,
 	/* Set the initial value */
 	palmas_gpio_set(gc, offset, value);
 
-	ret = palmas_update_bits(palmas, PALMAS_GPIO_BASE,
-		PALMAS_GPIO_DATA_DIR, BIT(offset), BIT(offset));
+	ret = palmas_gpio_update_bits(palmas, PALMAS_GPIO_DATA_DIR,
+			offset, 1 << (offset % 8), 1 << (offset % 8));
 	if (ret < 0)
 		dev_err(gc->dev, "GPIO_DATA_DIR write failed, err = %d\n", ret);
 	return ret;
@@ -93,8 +123,8 @@ static int palmas_gpio_input(struct gpio_chip *gc, unsigned offset)
 	struct palmas *palmas = pg->palmas;
 	int ret;
 
-	ret = palmas_update_bits(palmas, PALMAS_GPIO_BASE,
-		PALMAS_GPIO_DATA_DIR, BIT(offset), 0);
+	ret =  palmas_gpio_update_bits(palmas, PALMAS_GPIO_DATA_DIR,
+				offset, 1 << (offset % 8), 0);
 	if (ret < 0)
 		dev_err(gc->dev, "GPIO_DATA_DIR write failed, err = %d\n", ret);
 	return ret;
@@ -108,7 +138,21 @@ static int palmas_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
 	return palmas_irq_get_virq(palmas, PALMAS_GPIO_0_IRQ + offset);
 }
 
-static int palmas_gpio_probe(struct platform_device *pdev)
+static int palmas_gpio_set_debounce(struct gpio_chip *gc, unsigned offset,
+				    unsigned debounce)
+{
+	struct palmas_gpio *palmas_gpio = to_palmas_gpio(gc);
+	struct palmas *palmas = palmas_gpio->palmas;
+	unsigned int data = 0;
+
+	if (debounce)
+		data = 0xff;
+
+	return palmas_gpio_update_bits(palmas, PALMAS_GPIO_DEBOUNCE_EN,
+			offset, 1 << (offset % 8), data);
+}
+
+static int  palmas_gpio_probe(struct platform_device *pdev)
 {
 	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
 	struct palmas_platform_data *palmas_pdata;
@@ -125,10 +169,15 @@ static int palmas_gpio_probe(struct platform_device *pdev)
 	palmas_gpio->palmas = palmas;
 	palmas_gpio->gpio_chip.owner = THIS_MODULE;
 	palmas_gpio->gpio_chip.label = dev_name(&pdev->dev);
-	palmas_gpio->gpio_chip.ngpio = 8;
+	/* palmas charger has 16 gpios */
+	if (is_palmas_charger(palmas->product_id))
+		palmas_gpio->gpio_chip.ngpio = 16;
+	else
+		palmas_gpio->gpio_chip.ngpio = 8;
 	palmas_gpio->gpio_chip.can_sleep = 1;
 	palmas_gpio->gpio_chip.direction_input = palmas_gpio_input;
 	palmas_gpio->gpio_chip.direction_output = palmas_gpio_output;
+	palmas_gpio->gpio_chip.set_debounce = palmas_gpio_set_debounce,
 	palmas_gpio->gpio_chip.to_irq = palmas_gpio_to_irq;
 	palmas_gpio->gpio_chip.set	= palmas_gpio_set;
 	palmas_gpio->gpio_chip.get	= palmas_gpio_get;
diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
index 4cffe31..d8c303b 100644
--- a/include/linux/mfd/palmas.h
+++ b/include/linux/mfd/palmas.h
@@ -244,7 +244,7 @@ struct palmas_platform_data {
 	 * then the two value to load into the registers if true
 	 */
 	int mux_from_pdata;
-	u8 pad1, pad2;
+	u8 pad1, pad2, pad3, pad4;
 
 	struct palmas_pmic_platform_data *pmic_pdata;
 	struct palmas_gpadc_platform_data *gpadc_pdata;
@@ -2513,6 +2513,16 @@ enum usb_irq_events {
 #define PALMAS_PU_PD_GPIO_CTRL1					0x6
 #define PALMAS_PU_PD_GPIO_CTRL2					0x7
 #define PALMAS_OD_OUTPUT_GPIO_CTRL				0x8
+#define PALMAS_GPIO_DATA_IN2					0x9
+#define PALMAS_GPIO_DATA_DIR2					0xA
+#define PALMAS_GPIO_DATA_OUT2					0xB
+#define PALMAS_GPIO_DEBOUNCE_EN2				0xC
+#define PALMAS_GPIO_CLEAR_DATA_OUT2				0xD
+#define PALMAS_GPIO_SET_DATA_OUT2				0xE
+#define PALMAS_PU_PD_GPIO_CTRL3					0xF
+#define PALMAS_PU_PD_GPIO_CTRL4					0x10
+#define PALMAS_OD_OUTPUT_GPIO_CTRL2				0x11
+#define PALMAS_GPO_CTRL						0x12
 
 /* Bit definitions for GPIO_DATA_IN */
 #define PALMAS_GPIO_DATA_IN_GPIO_7_IN				0x80
-- 
1.7.0.4

  parent reply	other threads:[~2013-03-22 14:55 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-22 14:55 [PATCH v10 0/12] Palmas updates Ian Lartey
2013-03-22 14:55 ` [PATCH v10 01/12] mfd: DT bindings for the palmas family MFD Ian Lartey
2013-03-25 17:59   ` Stephen Warren
2013-03-25 19:47     ` Mark Brown
2013-05-30 11:33     ` keerthy
     [not found]       ` <51A73908.7020206-l0cyMroinI0@public.gmane.org>
2013-05-30 23:03         ` Stephen Warren
2013-06-03  6:55           ` J, KEERTHY
2013-06-04  6:24             ` gg
2013-03-22 14:55 ` [PATCH v10 02/12] mfd: palmas: is_palmas_charger needed by multiple drivers Ian Lartey
     [not found]   ` <1363964122-19201-3-git-send-email-ian-kDsPt+C1G03kYMGBc/C6ZA@public.gmane.org>
2013-04-08 15:51     ` Samuel Ortiz
2013-03-22 14:55 ` [PATCH v10 03/12] mfd: palmas add variant and OTP detection Ian Lartey
2013-04-05 16:32   ` Samuel Ortiz
2013-03-22 14:55 ` [PATCH v10 04/12] watchdog: add Palmas Watchdog support Ian Lartey
2013-03-24  3:19   ` Guenter Roeck
2013-08-20 20:31   ` Wim Van Sebroeck
2013-03-22 14:55 ` [PATCH v10 05/12] watchdog: Kconfig for Palmas watchdog Ian Lartey
2013-03-24  4:09   ` Guenter Roeck
2013-03-22 14:55 ` Ian Lartey [this message]
2013-03-22 14:55 ` [PATCH v10 07/12] gpio: palmas: Enable DT support for palmas gpio Ian Lartey
2013-03-22 14:55 ` [PATCH v10 08/12] gpio: Palmas palmas_gpio_(read|write|update) factoring Ian Lartey
2013-03-22 14:55 ` [PATCH v10 09/12] leds: Add support for Palmas LEDs Ian Lartey
2013-03-26  2:55   ` Kim, Milo
2013-03-22 14:55 ` [PATCH v10 10/12] clk: add a clock driver for palmas Ian Lartey
2013-03-22 14:55 ` [PATCH v10 11/12] clk: Kconfig for Palmas clock driver Ian Lartey
2013-03-22 14:55 ` [PATCH v10 12/12] regulator: palmas remove palmas-charger option from DT bindings Ian Lartey
2013-03-25  1:07   ` Mark Brown
2013-03-22 19:04 ` [PATCH v10 0/12] Palmas updates Stephen Rothwell
2013-03-24 21:13   ` Mark Brown
     [not found] ` <1363964122-19201-1-git-send-email-ian-kDsPt+C1G03kYMGBc/C6ZA@public.gmane.org>
2013-03-25  7:30   ` Laxman Dewangan
2013-04-05 16:30 ` Samuel Ortiz
2013-04-08 15:55   ` Graeme Gregory
     [not found]     ` <5162E88E.9010204-kDsPt+C1G03kYMGBc/C6ZA@public.gmane.org>
2013-04-08 16:11       ` Samuel Ortiz

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=1363964122-19201-7-git-send-email-ian@slimlogic.co.uk \
    --to=ian@slimlogic.co.uk \
    --cc=akpm@linux-foundation.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=cooloney@gmail.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=gg@slimlogic.co.uk \
    --cc=grant.likely@secretlab.ca \
    --cc=j-keerthy@ti.com \
    --cc=ldewangan@nvidia.com \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=mturquette@linaro.org \
    --cc=rob.herring@calxeda.com \
    --cc=rob@landley.net \
    --cc=rpurdie@rpsys.net \
    --cc=sameo@linux.intel.com \
    --cc=sfr@canb.auug.org.au \
    --cc=swarren@wwwdotorg.org \
    --cc=t-kristo@ti.com \
    --cc=wim@iguana.be \
    /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).