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

2012-11-20 Thread Tony Lindgren
* Tony Lindgren  [121120 10:36]:
> * Aaro Koskinen  [121112 11:11]:
> > 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.
> 
> Samuel, you can pick this one up separately now that Wolfram has taken
> the i2c-cbus driver.
> 
> Also, just noticed that this probably should depend on I2C_CBUS as this
> chip will not communicate over other I2C adapters?

Sorry meant to reply to "[PATCH v4 2/4] mfd: introduce retu-mfd driver"
instead of this v3 thread.

Regards,

Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2012-11-20 Thread Tony Lindgren
* Aaro Koskinen  [121112 11:11]:
> 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.

Samuel, you can pick this one up separately now that Wolfram has taken
the i2c-cbus driver.

Also, just noticed that this probably should depend on I2C_CBUS as this
chip will not communicate over other I2C adapters?

Regards,

Tony
 
> Cc: sa...@linux.intel.com
> Acked-by: Felipe Balbi 
> Acked-by: Tony Lindgren 
> Signed-off-by: Aaro Koskinen 
> ---
>  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(+), 0 deletions(-)
>  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 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/* 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(>mutex);
> + ret = regmap_read(rdev->regmap, reg, );
> +   

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

2012-11-20 Thread Tony Lindgren
* Aaro Koskinen aaro.koski...@iki.fi [121112 11:11]:
 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.

Samuel, you can pick this one up separately now that Wolfram has taken
the i2c-cbus driver.

Also, just noticed that this probably should depend on I2C_CBUS as this
chip will not communicate over other I2C adapters?

Regards,

Tony
 
 Cc: 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(+), 0 deletions(-)
  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;
 +
 + 

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

2012-11-20 Thread Tony Lindgren
* Tony Lindgren t...@atomide.com [121120 10:36]:
 * Aaro Koskinen aaro.koski...@iki.fi [121112 11:11]:
  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.
 
 Samuel, you can pick this one up separately now that Wolfram has taken
 the i2c-cbus driver.
 
 Also, just noticed that this probably should depend on I2C_CBUS as this
 chip will not communicate over other I2C adapters?

Sorry meant to reply to [PATCH v4 2/4] mfd: introduce retu-mfd driver
instead of this v3 thread.

Regards,

Tony
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2012-11-12 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: sa...@linux.intel.com
Acked-by: Felipe Balbi 
Acked-by: Tony Lindgren 
Signed-off-by: Aaro Koskinen 
---
 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(+), 0 deletions(-)
 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* 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(>mutex);
+   ret = regmap_read(rdev->regmap, reg, );
+   mutex_unlock(>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(>mutex);
+   ret = regmap_write(rdev->regmap, reg, data);
+   mutex_unlock(>mutex);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(retu_write);
+
+static void retu_power_off(void)
+{
+   struct retu_dev *rdev = retu_pm_power_off;
+   int reg;
+
+   

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

2012-11-12 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: 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(+), 0 deletions(-)
 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);
+   

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

2012-11-01 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: sa...@linux.intel.com
Acked-by: Felipe Balbi 
Acked-by: Tony Lindgren 
Signed-off-by: Aaro Koskinen 
---
 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(+), 0 deletions(-)
 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* 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(>mutex);
+   ret = regmap_read(rdev->regmap, reg, );
+   mutex_unlock(>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(>mutex);
+   ret = regmap_write(rdev->regmap, reg, data);
+   mutex_unlock(>mutex);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(retu_write);
+
+static void retu_power_off(void)
+{
+   struct retu_dev *rdev = retu_pm_power_off;
+   int reg;
+
+   

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

2012-11-01 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: 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(+), 0 deletions(-)
 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);
+