From: Mark Brown <broonie@opensource.wolfsonmicro.com>
To: Samuel Ortiz <sameo@openedhand.com>, Liam Girdwood <lrg@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Mark Brown <broonie@opensource.wolfsonmicro.com>
Subject: [PATCH 10/14] mfd: Add GPIO pin configuration support for WM8350
Date: Fri, 10 Oct 2008 15:58:12 +0100 [thread overview]
Message-ID: <1223650696-15552-10-git-send-email-broonie@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1223650696-15552-9-git-send-email-broonie@opensource.wolfsonmicro.com>
The WM8350 provides a number of user-configurable pins providing access
to various signals generated by the functions on the chip. These are
referred to as GPIO pins in the device documentation but in Linux terms
they are more general than that, providing configuration of alternate
functions.
This patch implements support for selecting the alternate functions for
these pins. They can also be used as GPIOs in the normal Linux sense -
a subsequent patch will add support for doing so.
This code was all written by Liam Girdwood and has had minor updates
and rearrangements by Mark Brown.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
drivers/mfd/Makefile | 2 +-
drivers/mfd/wm8350-gpio.c | 222 +++++++++++++++++++++++++++++++++++++++
include/linux/mfd/wm8350/gpio.h | 10 ++
3 files changed, 233 insertions(+), 1 deletions(-)
create mode 100644 drivers/mfd/wm8350-gpio.c
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 746d37b..8c0b7f2 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_MFD_TC6387XB) += tc6387xb.o
obj-$(CONFIG_MFD_TC6393XB) += tc6393xb.o
obj-$(CONFIG_MFD_WM8400) += wm8400-core.o
-wm8350-objs := wm8350-core.o wm8350-regmap.o
+wm8350-objs := wm8350-core.o wm8350-regmap.o wm8350-gpio.o
obj-$(CONFIG_MFD_WM8350) += wm8350.o
obj-$(CONFIG_MFD_WM8350_I2C) += wm8350-i2c.o
diff --git a/drivers/mfd/wm8350-gpio.c b/drivers/mfd/wm8350-gpio.c
new file mode 100644
index 0000000..ebf99be
--- /dev/null
+++ b/drivers/mfd/wm8350-gpio.c
@@ -0,0 +1,222 @@
+/*
+ * wm8350-core.c -- Device access for Wolfson WM8350
+ *
+ * Copyright 2007, 2008 Wolfson Microelectronics PLC.
+ *
+ * Author: Liam Girdwood
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+
+#include <linux/mfd/wm8350/core.h>
+#include <linux/mfd/wm8350/gpio.h>
+#include <linux/mfd/wm8350/pmic.h>
+
+static int gpio_set_dir(struct wm8350 *wm8350, int gpio, int dir)
+{
+ int ret;
+
+ wm8350_reg_unlock(wm8350);
+ if (dir == WM8350_GPIO_DIR_OUT)
+ ret = wm8350_clear_bits(wm8350,
+ WM8350_GPIO_CONFIGURATION_I_O,
+ 1 << gpio);
+ else
+ ret = wm8350_set_bits(wm8350,
+ WM8350_GPIO_CONFIGURATION_I_O,
+ 1 << gpio);
+ wm8350_reg_lock(wm8350);
+ return ret;
+}
+
+static int gpio_set_debounce(struct wm8350 *wm8350, int gpio, int db)
+{
+ if (db == WM8350_GPIO_DEBOUNCE_ON)
+ return wm8350_set_bits(wm8350, WM8350_GPIO_DEBOUNCE,
+ 1 << gpio);
+ else
+ return wm8350_clear_bits(wm8350,
+ WM8350_GPIO_DEBOUNCE, 1 << gpio);
+}
+
+static int gpio_set_func(struct wm8350 *wm8350, int gpio, int func)
+{
+ u16 reg;
+
+ wm8350_reg_unlock(wm8350);
+ switch (gpio) {
+ case 0:
+ reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1)
+ & ~WM8350_GP0_FN_MASK;
+ wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1,
+ reg | ((func & 0xf) << 0));
+ break;
+ case 1:
+ reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1)
+ & ~WM8350_GP1_FN_MASK;
+ wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1,
+ reg | ((func & 0xf) << 4));
+ break;
+ case 2:
+ reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1)
+ & ~WM8350_GP2_FN_MASK;
+ wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1,
+ reg | ((func & 0xf) << 8));
+ break;
+ case 3:
+ reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1)
+ & ~WM8350_GP3_FN_MASK;
+ wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1,
+ reg | ((func & 0xf) << 12));
+ break;
+ case 4:
+ reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2)
+ & ~WM8350_GP4_FN_MASK;
+ wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2,
+ reg | ((func & 0xf) << 0));
+ break;
+ case 5:
+ reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2)
+ & ~WM8350_GP5_FN_MASK;
+ wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2,
+ reg | ((func & 0xf) << 4));
+ break;
+ case 6:
+ reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2)
+ & ~WM8350_GP6_FN_MASK;
+ wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2,
+ reg | ((func & 0xf) << 8));
+ break;
+ case 7:
+ reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2)
+ & ~WM8350_GP7_FN_MASK;
+ wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2,
+ reg | ((func & 0xf) << 12));
+ break;
+ case 8:
+ reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3)
+ & ~WM8350_GP8_FN_MASK;
+ wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3,
+ reg | ((func & 0xf) << 0));
+ break;
+ case 9:
+ reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3)
+ & ~WM8350_GP9_FN_MASK;
+ wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3,
+ reg | ((func & 0xf) << 4));
+ break;
+ case 10:
+ reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3)
+ & ~WM8350_GP10_FN_MASK;
+ wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3,
+ reg | ((func & 0xf) << 8));
+ break;
+ case 11:
+ reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3)
+ & ~WM8350_GP11_FN_MASK;
+ wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3,
+ reg | ((func & 0xf) << 12));
+ break;
+ case 12:
+ reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_4)
+ & ~WM8350_GP12_FN_MASK;
+ wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_4,
+ reg | ((func & 0xf) << 0));
+ break;
+ default:
+ wm8350_reg_lock(wm8350);
+ return -EINVAL;
+ }
+
+ wm8350_reg_lock(wm8350);
+ return 0;
+}
+
+static int gpio_set_pull_up(struct wm8350 *wm8350, int gpio, int up)
+{
+ if (up)
+ return wm8350_set_bits(wm8350,
+ WM8350_GPIO_PIN_PULL_UP_CONTROL,
+ 1 << gpio);
+ else
+ return wm8350_clear_bits(wm8350,
+ WM8350_GPIO_PIN_PULL_UP_CONTROL,
+ 1 << gpio);
+}
+
+static int gpio_set_pull_down(struct wm8350 *wm8350, int gpio, int down)
+{
+ if (down)
+ return wm8350_set_bits(wm8350,
+ WM8350_GPIO_PULL_DOWN_CONTROL,
+ 1 << gpio);
+ else
+ return wm8350_clear_bits(wm8350,
+ WM8350_GPIO_PULL_DOWN_CONTROL,
+ 1 << gpio);
+}
+
+static int gpio_set_polarity(struct wm8350 *wm8350, int gpio, int pol)
+{
+ if (pol == WM8350_GPIO_ACTIVE_HIGH)
+ return wm8350_set_bits(wm8350,
+ WM8350_GPIO_PIN_POLARITY_TYPE,
+ 1 << gpio);
+ else
+ return wm8350_clear_bits(wm8350,
+ WM8350_GPIO_PIN_POLARITY_TYPE,
+ 1 << gpio);
+}
+
+static int gpio_set_invert(struct wm8350 *wm8350, int gpio, int invert)
+{
+ if (invert == WM8350_GPIO_INVERT_ON)
+ return wm8350_set_bits(wm8350, WM8350_GPIO_INT_MODE, 1 << gpio);
+ else
+ return wm8350_clear_bits(wm8350,
+ WM8350_GPIO_INT_MODE, 1 << gpio);
+}
+
+int wm8350_gpio_config(struct wm8350 *wm8350, int gpio, int dir, int func,
+ int pol, int pull, int invert, int debounce)
+{
+ /* make sure we never pull up and down at the same time */
+ if (pull == WM8350_GPIO_PULL_NONE) {
+ if (gpio_set_pull_up(wm8350, gpio, 0))
+ goto err;
+ if (gpio_set_pull_down(wm8350, gpio, 0))
+ goto err;
+ } else if (pull == WM8350_GPIO_PULL_UP) {
+ if (gpio_set_pull_down(wm8350, gpio, 0))
+ goto err;
+ if (gpio_set_pull_up(wm8350, gpio, 1))
+ goto err;
+ } else if (pull == WM8350_GPIO_PULL_DOWN) {
+ if (gpio_set_pull_up(wm8350, gpio, 0))
+ goto err;
+ if (gpio_set_pull_down(wm8350, gpio, 1))
+ goto err;
+ }
+
+ if (gpio_set_invert(wm8350, gpio, invert))
+ goto err;
+ if (gpio_set_polarity(wm8350, gpio, pol))
+ goto err;
+ if (gpio_set_debounce(wm8350, gpio, debounce))
+ goto err;
+ if (gpio_set_dir(wm8350, gpio, dir))
+ goto err;
+ return gpio_set_func(wm8350, gpio, func);
+
+err:
+ return -EIO;
+}
+EXPORT_SYMBOL_GPL(wm8350_gpio_config);
diff --git a/include/linux/mfd/wm8350/gpio.h b/include/linux/mfd/wm8350/gpio.h
index 928aa6e..c6cd2ca 100644
--- a/include/linux/mfd/wm8350/gpio.h
+++ b/include/linux/mfd/wm8350/gpio.h
@@ -323,4 +323,14 @@
#define WM8350_GP1_LVL 0x0002
#define WM8350_GP0_LVL 0x0001
+struct wm8350;
+
+int wm8350_gpio_config(struct wm8350 *wm8350, int gpio, int dir, int func,
+ int pol, int pull, int invert, int debounce);
+
+/*
+ * GPIO Interrupts
+ */
+#define WM8350_IRQ_GPIO(x) (50 + x)
+
#endif
--
1.5.6.5
next prev parent reply other threads:[~2008-10-10 15:00 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-06 12:32 [PATCH 0/13] WM8350 support Mark Brown
2008-10-06 12:37 ` [PATCH 01/13] mfd: Add WM8350 audio register definitions Mark Brown
2008-10-06 12:37 ` [PATCH 02/13] mfd: Add WM8350 GPIO " Mark Brown
2008-10-06 12:37 ` [PATCH 03/13] mfd: Add WM8350 PMIC " Mark Brown
2008-10-06 12:37 ` [PATCH 04/13] mfd: Add WM8350 PMU " Mark Brown
2008-10-06 12:38 ` [PATCH 05/13] mfd: Add WM8350 comparator " Mark Brown
2008-10-06 12:38 ` [PATCH 06/13] mfd: Add WM8350 RTC " Mark Brown
2008-10-06 12:38 ` [PATCH 07/13] mfd: Add WM8350 watchdog " Mark Brown
2008-10-06 12:38 ` [PATCH 08/13] mfd: Core support for the WM8350 AudioPlus PMIC Mark Brown
2008-10-06 12:38 ` [PATCH 09/13] mfd: Add I2C control support for WM8350 Mark Brown
2008-10-06 12:38 ` [PATCH 10/13] mfd: Add GPIO pin configuration " Mark Brown
2008-10-06 12:38 ` [PATCH 11/13] mfd: Add initialisation callback " Mark Brown
2008-10-06 12:38 ` [PATCH 12/13] mfd: Add WM8350 interrupt support Mark Brown
2008-10-06 12:38 ` [PATCH 13/13] regulator: Add WM8350 regulator support Mark Brown
2008-10-09 12:05 ` [PATCH 08/13] mfd: Core support for the WM8350 AudioPlus PMIC Liam Girdwood
2008-10-09 12:53 ` Mark Brown
2008-10-10 14:24 ` [PATCH 0/13] WM8350 support Liam Girdwood
2008-10-10 14:31 ` Samuel Ortiz
2008-10-10 14:38 ` Mark Brown
2008-10-10 14:45 ` Liam Girdwood
2008-10-10 14:58 ` [PATCH 01/14] mfd: Add WM8350 audio register definitions Mark Brown
2008-10-10 14:58 ` [PATCH 02/14] mfd: Add WM8350 GPIO " Mark Brown
2008-10-10 14:58 ` [PATCH 03/14] mfd: Add WM8350 PMIC " Mark Brown
2008-10-10 14:58 ` [PATCH 04/14] mfd: Add WM8350 PMU " Mark Brown
2008-10-10 14:58 ` [PATCH 05/14] mfd: Add WM8350 comparator " Mark Brown
2008-10-10 14:58 ` [PATCH 06/14] mfd: Add WM8350 RTC " Mark Brown
2008-10-10 14:58 ` [PATCH 07/14] mfd: Add WM8350 watchdog " Mark Brown
2008-10-10 14:58 ` [PATCH 08/14] mfd: Core support for the WM8350 AudioPlus PMIC Mark Brown
2008-10-10 14:58 ` [PATCH 09/14] mfd: Add I2C control support for WM8350 Mark Brown
2008-10-10 14:58 ` Mark Brown [this message]
2008-10-10 14:58 ` [PATCH 11/14] mfd: Add initialisation callback " Mark Brown
2008-10-10 14:58 ` [PATCH 12/14] mfd: Add WM8350 interrupt support Mark Brown
2008-10-10 14:58 ` [PATCH 13/14] regulator: Add WM8350 regulator support Mark Brown
2008-10-10 14:58 ` [PATCH 14/14] mfd: Add WM8350 subdevice registration helper Mark Brown
2008-10-11 14:18 ` Samuel Ortiz
2008-10-11 15:38 ` Mark Brown
2008-10-11 14:09 ` [PATCH 10/14] mfd: Add GPIO pin configuration support for WM8350 Samuel Ortiz
2008-10-11 14:46 ` Mark Brown
2008-10-11 14:23 ` [PATCH 0/13] WM8350 support Samuel Ortiz
2008-10-10 14:48 ` Samuel Ortiz
2008-10-10 14:38 ` Liam Girdwood
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=1223650696-15552-10-git-send-email-broonie@opensource.wolfsonmicro.com \
--to=broonie@opensource.wolfsonmicro.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lrg@kernel.org \
--cc=sameo@openedhand.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