Re: [PATCH v4 2/4] mfd: introduce retu-mfd driver

2012-11-21 Thread Samuel Ortiz
Hi Aaro,

On Sun, Nov 18, 2012 at 06:36:20PM +0200, Aaro Koskinen wrote:
 Retu is a multi-function device found on Nokia Internet Tablets
 implementing at least watchdog, RTC, headset detection and power button
 functionality.
 
 This patch implements minimum functionality providing register access,
 IRQ handling and power off functions.
 
 Cc: Samuel Ortiz sa...@linux.intel.com
 Acked-by: Felipe Balbi ba...@ti.com
 Acked-by: Tony Lindgren t...@atomide.com
 Signed-off-by: Aaro Koskinen aaro.koski...@iki.fi
 ---
  drivers/mfd/Kconfig  |9 ++
  drivers/mfd/Makefile |1 +
  drivers/mfd/retu-mfd.c   |  264 
 ++
  include/linux/mfd/retu.h |   22 
  4 files changed, 296 insertions(+)
  create mode 100644 drivers/mfd/retu-mfd.c
  create mode 100644 include/linux/mfd/retu.h
Thanks, I applied this one to my for-next branch.

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 2/4] mfd: introduce retu-mfd driver

2012-11-18 Thread Aaro Koskinen
Retu is a multi-function device found on Nokia Internet Tablets
implementing at least watchdog, RTC, headset detection and power button
functionality.

This patch implements minimum functionality providing register access,
IRQ handling and power off functions.

Cc: Samuel Ortiz sa...@linux.intel.com
Acked-by: Felipe Balbi ba...@ti.com
Acked-by: Tony Lindgren t...@atomide.com
Signed-off-by: Aaro Koskinen aaro.koski...@iki.fi
---
 drivers/mfd/Kconfig  |9 ++
 drivers/mfd/Makefile |1 +
 drivers/mfd/retu-mfd.c   |  264 ++
 include/linux/mfd/retu.h |   22 
 4 files changed, 296 insertions(+)
 create mode 100644 drivers/mfd/retu-mfd.c
 create mode 100644 include/linux/mfd/retu.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index acab3ef..7528c5e 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1044,6 +1044,15 @@ config MFD_PALMAS
  If you say yes here you get support for the Palmas
  series of PMIC chips from Texas Instruments.
 
+config MFD_RETU
+   tristate Support for Retu multi-function device
+   select MFD_CORE
+   depends on I2C
+   select REGMAP_IRQ
+   help
+ Retu is a multi-function device found on Nokia Internet Tablets
+ (770, N800 and N810).
+
 endmenu
 endif
 
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index d8ccb63..ad7879f 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -138,3 +138,4 @@ obj-$(CONFIG_MFD_RC5T583)   += rc5t583.o rc5t583-irq.o
 obj-$(CONFIG_MFD_SEC_CORE) += sec-core.o sec-irq.o
 obj-$(CONFIG_MFD_SYSCON)   += syscon.o
 obj-$(CONFIG_MFD_LM3533)   += lm3533-core.o lm3533-ctrlbank.o
+obj-$(CONFIG_MFD_RETU) += retu-mfd.o
diff --git a/drivers/mfd/retu-mfd.c b/drivers/mfd/retu-mfd.c
new file mode 100644
index 000..7ff4a37
--- /dev/null
+++ b/drivers/mfd/retu-mfd.c
@@ -0,0 +1,264 @@
+/*
+ * Retu MFD driver
+ *
+ * Copyright (C) 2004, 2005 Nokia Corporation
+ *
+ * Based on code written by Juha Yrjölä, David Weinehall and Mikko Ylinen.
+ * Rewritten by Aaro Koskinen.
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file COPYING in the main directory of this
+ * archive for more details.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/err.h
+#include linux/i2c.h
+#include linux/irq.h
+#include linux/init.h
+#include linux/slab.h
+#include linux/mutex.h
+#include linux/module.h
+#include linux/regmap.h
+#include linux/mfd/core.h
+#include linux/mfd/retu.h
+#include linux/interrupt.h
+#include linux/moduleparam.h
+
+/* Registers */
+#define RETU_REG_ASICR 0x00/* ASIC ID and revision */
+#define RETU_REG_ASICR_VILMA   (1  7)/* Bit indicating Vilma */
+#define RETU_REG_IDR   0x01/* Interrupt ID */
+#define RETU_REG_IMR   0x02/* Interrupt mask */
+
+/* Interrupt sources */
+#define RETU_INT_PWR   0   /* Power button */
+
+struct retu_dev {
+   struct regmap   *regmap;
+   struct device   *dev;
+   struct mutexmutex;
+   struct regmap_irq_chip_data *irq_data;
+};
+
+static struct resource retu_pwrbutton_res[] = {
+   {
+   .name   = retu-pwrbutton,
+   .start  = RETU_INT_PWR,
+   .end= RETU_INT_PWR,
+   .flags  = IORESOURCE_IRQ,
+   },
+};
+
+static struct mfd_cell retu_devs[] = {
+   {
+   .name   = retu-wdt
+   },
+   {
+   .name   = retu-pwrbutton,
+   .resources  = retu_pwrbutton_res,
+   .num_resources  = ARRAY_SIZE(retu_pwrbutton_res),
+   }
+};
+
+static struct regmap_irq retu_irqs[] = {
+   [RETU_INT_PWR] = {
+   .mask = 1  RETU_INT_PWR,
+   }
+};
+
+static struct regmap_irq_chip retu_irq_chip = {
+   .name   = RETU,
+   .irqs   = retu_irqs,
+   .num_irqs   = ARRAY_SIZE(retu_irqs),
+   .num_regs   = 1,
+   .status_base= RETU_REG_IDR,
+   .mask_base  = RETU_REG_IMR,
+   .ack_base   = RETU_REG_IDR,
+};
+
+/* Retu device registered for the power off. */
+static struct retu_dev *retu_pm_power_off;
+
+int retu_read(struct retu_dev *rdev, u8 reg)
+{
+   int ret;
+   int value;
+
+   mutex_lock(rdev-mutex);
+   ret = regmap_read(rdev-regmap, reg, value);
+   mutex_unlock(rdev-mutex);
+
+   return ret ? ret : value;
+}
+EXPORT_SYMBOL_GPL(retu_read);
+
+int retu_write(struct retu_dev *rdev, u8 reg, u16 data)
+{
+   int ret;
+
+   mutex_lock(rdev-mutex);
+   ret = regmap_write(rdev-regmap, reg, data);
+