All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/8] DA906x PMIC driver
@ 2012-08-24  8:32 ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24  8:32 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie, Bryan Wu, Liam Girdwood

Greetings,

The following patch set adds new multifunction device providing support for
DA906x PMIC chips.

Please add some comments to the driver, which targets Linux Kernel v3.6.

Thank you,

---
Krystian Garbaciak (8):
  mfd: Add Dialog DA906x core driver.
  regulator: Add Dialog DA906x voltage regulators support.
  rtc: Add RTC driver for DA906x PMIC.
  hwmon: Add DA906x hardware monitoring support.
  input: Add support for DA906x PMIC OnKey detection.
  input: Add support for DA906x vibration motor driver.
  watchdog: Add DA906x PMIC watchdog driver.
  leds: Add DA906x PMIC LED driver.

 drivers/hwmon/Kconfig                 |    6 +
 drivers/hwmon/Makefile                |    1 +
 drivers/hwmon/da906x-hwmon.c          |  393 ++++++++++++
 drivers/input/misc/Kconfig            |   13 +
 drivers/input/misc/Makefile           |    2 +
 drivers/input/misc/da906x-onkey.c     |  139 +++++
 drivers/input/misc/da906x-vibration.c |  153 +++++
 drivers/leds/Kconfig                  |    8 +
 drivers/leds/Makefile                 |    1 +
 drivers/leds/leds-da906x.c            |  438 +++++++++++++
 drivers/mfd/Kconfig                   |   11 +
 drivers/mfd/Makefile                  |    4 +
 drivers/mfd/da906x-core.c             |  228 +++++++
 drivers/mfd/da906x-i2c.c              |  389 ++++++++++++
 drivers/mfd/da906x-irq.c              |  192 ++++++
 drivers/regulator/Kconfig             |    6 +
 drivers/regulator/Makefile            |    1 +
 drivers/regulator/da906x-regulator.c  | 1018 ++++++++++++++++++++++++++++++
 drivers/rtc/Kconfig                   |    7 +
 drivers/rtc/Makefile                  |    1 +
 drivers/rtc/rtc-da906x.c              |  379 ++++++++++++
 drivers/watchdog/Kconfig              |   27 +
 drivers/watchdog/Makefile             |    1 +
 drivers/watchdog/da906x_wdt.c         |  276 +++++++++
 include/linux/mfd/da906x/core.h       |  121 ++++
 include/linux/mfd/da906x/pdata.h      |  114 ++++
 include/linux/mfd/da906x/registers.h  | 1093 +++++++++++++++++++++++++++++++++
 27 files changed, 5022 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/da906x-hwmon.c
 create mode 100644 drivers/input/misc/da906x-onkey.c
 create mode 100644 drivers/input/misc/da906x-vibration.c
 create mode 100644 drivers/leds/leds-da906x.c
 create mode 100644 drivers/mfd/da906x-core.c
 create mode 100644 drivers/mfd/da906x-i2c.c
 create mode 100644 drivers/mfd/da906x-irq.c
 create mode 100644 drivers/regulator/da906x-regulator.c
 create mode 100644 drivers/rtc/rtc-da906x.c
 create mode 100644 drivers/watchdog/da906x_wdt.c
 create mode 100644 include/linux/mfd/da906x/core.h
 create mode 100644 include/linux/mfd/da906x/pdata.h
 create mode 100644 include/linux/mfd/da906x/registers.h


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 1/8] mfd: Add Dialog DA906x core driver.
  2012-08-24  8:32 ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-24  8:32   ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24  8:32 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie, Bryan Wu, Liam Girdwood

This is MFD module providing access to registers and interrupts of DA906x
series PMIC. It is used by other functional modules, registered as MFD cells.
Driver uses regmap with paging to access extended register list. Register map
is divided into two pages, where the second page is used during initialisation.

This module provides support to following functional cells:
 - Regulators
 - RTC
 - HWMON
 - OnKey (power key misc input device)
 - Vibration (force-feedback input device)
 - Watchdog
 - LEDs

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/mfd/Kconfig                  |   11 +
 drivers/mfd/Makefile                 |    4 +
 drivers/mfd/da906x-core.c            |  228 +++++++
 drivers/mfd/da906x-i2c.c             |  389 ++++++++++++
 drivers/mfd/da906x-irq.c             |  192 ++++++
 include/linux/mfd/da906x/core.h      |  121 ++++
 include/linux/mfd/da906x/pdata.h     |  114 ++++
 include/linux/mfd/da906x/registers.h | 1093 ++++++++++++++++++++++++++++++++++
 8 files changed, 2152 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mfd/da906x-core.c
 create mode 100644 drivers/mfd/da906x-i2c.c
 create mode 100644 drivers/mfd/da906x-irq.c
 create mode 100644 include/linux/mfd/da906x/core.h
 create mode 100644 include/linux/mfd/da906x/pdata.h
 create mode 100644 include/linux/mfd/da906x/registers.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index b1a1462..bf2a766 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -441,6 +441,17 @@ config MFD_DA9052_I2C
 	  for accessing the device, additional drivers must be enabled in
 	  order to use the functionality of the device.
 
+config MFD_DA906X
+	bool "Dialog Semiconductor DA906X PMIC Support"
+	depends on I2C=y
+	select MFD_CORE
+	select REGMAP_I2C
+	select REGMAP_IRQ
+	help
+	  Support for the Dialog Semiconductor DA906X PMIC. This includes
+	  I2C driver and core APIs, additional drivers must be enabled in
+	  order to use the functionality of the device.
+
 config PMIC_ADP5520
 	bool "Analog Devices ADP5520/01 MFD PMIC Core Support"
 	depends on I2C=y
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 79dd22d..f5a8432 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -90,8 +90,12 @@ obj-$(CONFIG_PMIC_DA9052)	+= da9052-core.o
 obj-$(CONFIG_MFD_DA9052_SPI)	+= da9052-spi.o
 obj-$(CONFIG_MFD_DA9052_I2C)	+= da9052-i2c.o
 
+da906x-objs			:= da906x-core.o da906x-irq.o da906x-i2c.o
+obj-$(CONFIG_MFD_DA906X)	+= da906x.o
+
 obj-$(CONFIG_MFD_MAX77686)	+= max77686.o max77686-irq.o
 obj-$(CONFIG_MFD_MAX77693)	+= max77693.o max77693-irq.o
+
 max8925-objs			:= max8925-core.o max8925-i2c.o
 obj-$(CONFIG_MFD_MAX8925)	+= max8925.o
 obj-$(CONFIG_MFD_MAX8997)	+= max8997.o max8997-irq.o
diff --git a/drivers/mfd/da906x-core.c b/drivers/mfd/da906x-core.c
new file mode 100644
index 0000000..fb3249f
--- /dev/null
+++ b/drivers/mfd/da906x-core.c
@@ -0,0 +1,228 @@
+/*
+ * da906x-core.c: Device access for Dialog DA906x modules
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>,
+ *         Michal Hajduk <michal.hajduk@diasemi.com>
+ *
+ *  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/init.h>
+#include <linux/slab.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/mutex.h>
+#include <linux/mfd/core.h>
+#include <linux/regmap.h>
+
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+#include <linux/mfd/da906x/registers.h>
+
+#include <linux/proc_fs.h>
+#include <linux/kthread.h>
+#include <linux/uaccess.h>
+
+
+static struct resource da906x_regulators_resources[] = {
+	{
+		.name	= "LDO_LIM",
+		.start	= DA906X_IRQ_LDO_LIM,
+		.end	= DA906X_IRQ_LDO_LIM,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct resource da906x_rtc_resources[] = {
+	{
+		.name	= "ALARM",
+		.start	= DA906X_IRQ_ALARM,
+		.end	= DA906X_IRQ_ALARM,
+		.flags	= IORESOURCE_IRQ,
+	},
+	{
+		.name	= "TICK",
+		.start	= DA906X_IRQ_TICK,
+		.end	= DA906X_IRQ_TICK,
+		.flags	= IORESOURCE_IRQ,
+	}
+};
+
+static struct resource da906x_onkey_resources[] = {
+	{
+		.start	= DA906X_IRQ_ONKEY,
+		.end	= DA906X_IRQ_ONKEY,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct resource da906x_hwmon_resources[] = {
+	{
+		.start	= DA906X_IRQ_ADC_RDY,
+		.end	= DA906X_IRQ_ADC_RDY,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+
+static struct mfd_cell da906x_devs[] = {
+	{
+		.name		= DA906X_DRVNAME_REGULATORS,
+		.num_resources	= ARRAY_SIZE(da906x_regulators_resources),
+		.resources	= da906x_regulators_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_LEDS,
+	},
+	{
+		.name		= DA906X_DRVNAME_WATCHDOG,
+	},
+	{
+		.name		= DA906X_DRVNAME_HWMON,
+		.num_resources	= ARRAY_SIZE(da906x_hwmon_resources),
+		.resources	= da906x_hwmon_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_ONKEY,
+		.num_resources	= ARRAY_SIZE(da906x_onkey_resources),
+		.resources	= da906x_onkey_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_RTC,
+		.num_resources	= ARRAY_SIZE(da906x_rtc_resources),
+		.resources	= da906x_rtc_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_VIBRATION,
+	},
+};
+
+inline unsigned int da906x_to_range_reg(u16 reg)
+{
+	return reg + DA906X_MAPPING_BASE;
+}
+
+int da906x_reg_read(struct da906x *da906x, u16 reg)
+{
+	unsigned int val;
+	int ret;
+
+	ret = regmap_read(da906x->regmap, da906x_to_range_reg(reg), &val);
+	if (ret < 0)
+		return ret;
+
+	return val;
+}
+
+int da906x_reg_write(struct da906x *da906x, u16 reg, u8 val)
+{
+	return regmap_write(da906x->regmap, da906x_to_range_reg(reg), val);
+}
+
+int da906x_block_read(struct da906x *da906x, u16 reg, int bytes, u8 *dst)
+{
+	return regmap_bulk_read(da906x->regmap, da906x_to_range_reg(reg),
+				dst, bytes);
+}
+
+int da906x_block_write(struct da906x *da906x, u16 reg, int bytes, const u8 *src)
+{
+	return regmap_bulk_write(da906x->regmap, da906x_to_range_reg(reg),
+				 src, bytes);
+}
+
+int da906x_reg_update(struct da906x *da906x, u16 reg, u8 mask, u8 val)
+{
+	return regmap_update_bits(da906x->regmap, da906x_to_range_reg(reg),
+				  mask, val);
+}
+
+int da906x_reg_set_bits(struct da906x *da906x, u16 reg, u8 mask)
+{
+	return da906x_reg_update(da906x, reg, mask, mask);
+}
+
+int da906x_reg_clear_bits(struct da906x *da906x, u16 reg, u8 mask)
+{
+	return da906x_reg_update(da906x, reg, mask, 0);
+}
+
+int da906x_device_init(struct da906x *da906x, unsigned int irq)
+{
+	struct da906x_pdata *pdata = da906x->dev->platform_data;
+	int ret = 0;
+	int model;
+	unsigned short revision;
+
+	mutex_init(&da906x->io_mutex);
+
+	if (pdata == NULL) {
+		dev_err(da906x->dev, "Platform data not specified.\n");
+		return -EINVAL;
+	}
+	da906x->flags = pdata->flags;
+	da906x->irq_base = pdata->irq_base;
+	da906x->chip_irq = irq;
+
+	if (pdata->init != NULL) {
+		ret = pdata->init(da906x);
+		if (ret != 0) {
+			dev_err(da906x->dev,
+				"Platform initialization failed.\n");
+			return ret;
+		}
+	}
+
+	model = da906x_reg_read(da906x, DA906X_REG_CHIP_ID);
+	if (model < 0) {
+		dev_err(da906x->dev, "Cannot read chip model id.\n");
+		return -EIO;
+	}
+
+	ret = da906x_reg_read(da906x, DA906X_REG_CHIP_VARIANT);
+	if (ret < 0) {
+		dev_err(da906x->dev, "Cannot read chip revision id.\n");
+		return -EIO;
+	}
+
+	revision = ret >> DA906X_CHIP_VARIANT_SHIFT;
+
+	da906x_set_model_rev(da906x, model, revision);
+
+	dev_info(da906x->dev,
+		 "Device detected (model-ID: 0x%02X  rev-ID: 0x%02X)\n",
+		 model, revision);
+
+	ret = da906x_irq_init(da906x);
+	if (ret) {
+		dev_err(da906x->dev, "Cannot initialize interrupts.\n");
+		return ret;
+	}
+
+	ret = mfd_add_devices(da906x->dev, -1, da906x_devs,
+			      ARRAY_SIZE(da906x_devs), NULL, da906x->irq_base);
+	if (ret)
+		dev_err(da906x->dev, "Cannot add MFD cells\n");
+
+	return ret;
+}
+
+void da906x_device_exit(struct da906x *da906x)
+{
+	mfd_remove_devices(da906x->dev);
+	da906x_irq_exit(da906x);
+}
+
+MODULE_DESCRIPTION("PMIC driver for Dialog DA906X");
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>, Michal Hajduk <michal.hajduk@diasemi.com>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DA906X_DRVNAME_CORE);
diff --git a/drivers/mfd/da906x-i2c.c b/drivers/mfd/da906x-i2c.c
new file mode 100644
index 0000000..90b9e23
--- /dev/null
+++ b/drivers/mfd/da906x-i2c.c
@@ -0,0 +1,389 @@
+/* da906x-i2c.c: Interrupt support for Dialog DA906x
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/i2c.h>
+#include <linux/regmap.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/err.h>
+
+#include <linux/mfd/core.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+#include <linux/mfd/da906x/registers.h>
+
+
+#define RD		0x01	/* Readable register */
+#define WR		0x02	/* Writable register */
+#define VOL		0x04	/* Volatile register */
+
+/* Flags for virtual registers (mapped starting from DA906X_MAPPING_BASE) */
+const unsigned char da906x_reg_flg[] = {
+	[DA906X_REG_STATUS_A] =		RD | VOL,
+	[DA906X_REG_STATUS_B] =		RD | VOL,
+	[DA906X_REG_STATUS_C] =		RD | VOL,
+	[DA906X_REG_STATUS_D] =		RD | VOL,
+	[DA906X_REG_FAULT_LOG] =	RD | WR | VOL,
+	[DA906X_REG_EVENT_A] =		RD | WR | VOL,
+	[DA906X_REG_EVENT_B] =		RD | WR | VOL,
+	[DA906X_REG_EVENT_C] =		RD | WR | VOL,
+	[DA906X_REG_EVENT_D] =		RD | WR | VOL,
+	[DA906X_REG_IRQ_MASK_A] =	RD | WR,
+	[DA906X_REG_IRQ_MASK_B] =	RD | WR,
+	[DA906X_REG_IRQ_MASK_C] =	RD | WR,
+	[DA906X_REG_IRQ_MASK_D] =	RD | WR,
+	[DA906X_REG_CONTROL_A] =	RD | WR,
+	[DA906X_REG_CONTROL_B] =	RD | WR,
+	[DA906X_REG_CONTROL_C] =	RD | WR,
+	[DA906X_REG_CONTROL_D] =	RD | WR,
+	[DA906X_REG_CONTROL_E] =	RD | WR,
+	[DA906X_REG_CONTROL_F] =	RD | WR | VOL,
+	[DA906X_REG_PD_DIS] =		RD | WR,
+
+	[DA906X_REG_GPIO_0_1] =		RD | WR,
+	[DA906X_REG_GPIO_2_3] =		RD | WR,
+	[DA906X_REG_GPIO_4_5] =		RD | WR,
+	[DA906X_REG_GPIO_6_7] =		RD | WR,
+	[DA906X_REG_GPIO_8_9] =		RD | WR,
+	[DA906X_REG_GPIO_10_11] =	RD | WR,
+	[DA906X_REG_GPIO_12_13] =	RD | WR,
+	[DA906X_REG_GPIO_14_15] =	RD | WR,
+	[DA906X_REG_GPIO_MODE_0_7] =	RD | WR,
+	[DA906X_REG_GPIO_MODE_8_15] =	RD | WR,
+	[DA906X_REG_GPIO_SWITCH_CONT] =	RD | WR,
+
+	[DA906X_REG_BCORE2_CONT] =	RD | WR,
+	[DA906X_REG_BCORE1_CONT] =	RD | WR,
+	[DA906X_REG_BPRO_CONT] =	RD | WR,
+	[DA906X_REG_BMEM_CONT] =	RD | WR,
+	[DA906X_REG_BIO_CONT] =		RD | WR,
+	[DA906X_REG_BPERI_CONT] =	RD | WR,
+	[DA906X_REG_LDO1_CONT] =	RD | WR,
+	[DA906X_REG_LDO2_CONT] =	RD | WR,
+	[DA906X_REG_LDO3_CONT] =	RD | WR,
+	[DA906X_REG_LDO4_CONT] =	RD | WR,
+	[DA906X_REG_LDO5_CONT] =	RD | WR,
+	[DA906X_REG_LDO6_CONT] =	RD | WR,
+	[DA906X_REG_LDO7_CONT] =	RD | WR,
+	[DA906X_REG_LDO8_CONT] =	RD | WR,
+	[DA906X_REG_LDO9_CONT] =	RD | WR,
+	[DA906X_REG_LDO10_CONT] =	RD | WR,
+	[DA906X_REG_LDO11_CONT] =	RD | WR,
+	[DA906X_REG_VIB] =		RD | WR,
+	[DA906X_REG_DVC_1] =		RD | WR,
+	[DA906X_REG_DVC_2] =		RD | WR,
+
+	[DA906X_REG_ADC_MAN] =		RD | WR | VOL,
+	[DA906X_REG_ADC_CONT] =		RD | WR,
+	[DA906X_REG_VSYS_MON] =		RD | WR,
+	[DA906X_REG_ADC_RES_L] =	RD | VOL,
+	[DA906X_REG_ADC_RES_H] =	RD | VOL,
+	[DA906X_REG_VSYS_RES] =		RD | VOL,
+	[DA906X_REG_ADCIN1_RES] =	RD | VOL,
+	[DA906X_REG_ADCIN2_RES] =	RD | VOL,
+	[DA906X_REG_ADCIN3_RES] =	RD | VOL,
+	[DA906X_REG_MON1_RES] =		RD | VOL,
+	[DA906X_REG_MON2_RES] =		RD | VOL,
+	[DA906X_REG_MON3_RES] =		RD | VOL,
+
+	[DA906X_REG_COUNT_S] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_MI] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_H] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_D] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_MO] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_Y] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_MI] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_H] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_D] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_MO] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_Y] =		RD | WR | VOL,
+	[DA906X_REG_SECOND_A] =		RD | VOL,
+	[DA906X_REG_SECOND_B] =		RD | VOL,
+	[DA906X_REG_SECOND_C] =		RD | VOL,
+	[DA906X_REG_SECOND_D] =		RD | VOL,
+
+	[DA906X_REG_SEQ] =		RD | WR,
+	[DA906X_REG_SEQ_TIMER] =	RD | WR,
+	[DA906X_REG_ID_2_1] =		RD | WR,
+	[DA906X_REG_ID_4_3] =		RD | WR,
+	[DA906X_REG_ID_6_5] =		RD | WR,
+	[DA906X_REG_ID_8_7] =		RD | WR,
+	[DA906X_REG_ID_10_9] =		RD | WR,
+	[DA906X_REG_ID_12_11] =		RD | WR,
+	[DA906X_REG_ID_14_13] =		RD | WR,
+	[DA906X_REG_ID_16_15] =		RD | WR,
+	[DA906X_REG_ID_18_17] =		RD | WR,
+	[DA906X_REG_ID_20_19] =		RD | WR,
+	[DA906X_REG_ID_22_21] =		RD | WR,
+	[DA906X_REG_ID_24_23] =		RD | WR,
+	[DA906X_REG_ID_26_25] =		RD | WR,
+	[DA906X_REG_ID_28_27] =		RD | WR,
+	[DA906X_REG_ID_30_29] =		RD | WR,
+	[DA906X_REG_ID_32_31] =		RD | WR,
+	[DA906X_REG_SEQ_A] =		RD | WR,
+	[DA906X_REG_SEQ_B] =		RD | WR,
+	[DA906X_REG_WAIT] =		RD | WR,
+	[DA906X_REG_EN_32K] =		RD | WR,
+	[DA906X_REG_RESET] =		RD | WR,
+
+	[DA906X_REG_BUCK_ILIM_A] =	RD | WR,
+	[DA906X_REG_BUCK_ILIM_B] =	RD | WR,
+	[DA906X_REG_BUCK_ILIM_C] =	RD | WR,
+	[DA906X_REG_BCORE2_CFG] =	RD | WR,
+	[DA906X_REG_BCORE1_CFG] =	RD | WR,
+	[DA906X_REG_BPRO_CFG] =		RD | WR,
+	[DA906X_REG_BIO_CFG] =		RD | WR,
+	[DA906X_REG_BMEM_CFG] =		RD | WR,
+	[DA906X_REG_BPERI_CFG] =	RD | WR,
+	[DA906X_REG_VBCORE2_A] =	RD | WR,
+	[DA906X_REG_VBCORE1_A] =	RD | WR,
+	[DA906X_REG_VBPRO_A] =		RD | WR,
+	[DA906X_REG_VBMEM_A] =		RD | WR,
+	[DA906X_REG_VBIO_A] =		RD | WR,
+	[DA906X_REG_VBPERI_A] =		RD | WR,
+	[DA906X_REG_VLDO1_A] =		RD | WR,
+	[DA906X_REG_VLDO2_A] =		RD | WR,
+	[DA906X_REG_VLDO3_A] =		RD | WR,
+	[DA906X_REG_VLDO4_A] =		RD | WR,
+	[DA906X_REG_VLDO5_A] =		RD | WR,
+	[DA906X_REG_VLDO6_A] =		RD | WR,
+	[DA906X_REG_VLDO7_A] =		RD | WR,
+	[DA906X_REG_VLDO8_A] =		RD | WR,
+	[DA906X_REG_VLDO9_A] =		RD | WR,
+	[DA906X_REG_VLDO10_A] =		RD | WR,
+	[DA906X_REG_VLDO11_A] =		RD | WR,
+	[DA906X_REG_VBCORE2_B] =	RD | WR,
+	[DA906X_REG_VBCORE1_B] =	RD | WR,
+	[DA906X_REG_VBPRO_B] =		RD | WR,
+	[DA906X_REG_VBMEM_B] =		RD | WR,
+	[DA906X_REG_VBIO_B] =		RD | WR,
+	[DA906X_REG_VBPERI_B] =		RD | WR,
+	[DA906X_REG_VLDO1_B] =		RD | WR,
+	[DA906X_REG_VLDO2_B] =		RD | WR,
+	[DA906X_REG_VLDO3_B] =		RD | WR,
+	[DA906X_REG_VLDO4_B] =		RD | WR,
+	[DA906X_REG_VLDO5_B] =		RD | WR,
+	[DA906X_REG_VLDO6_B] =		RD | WR,
+	[DA906X_REG_VLDO7_B] =		RD | WR,
+	[DA906X_REG_VLDO8_B] =		RD | WR,
+	[DA906X_REG_VLDO9_B] =		RD | WR,
+	[DA906X_REG_VLDO10_B] =		RD | WR,
+	[DA906X_REG_VLDO11_B] =		RD | WR,
+
+	[DA906X_REG_BBAT_CONT] =	RD | WR,
+
+	[DA906X_REG_GPO11_LED] =	RD | WR,
+	[DA906X_REG_GPO14_LED] =	RD | WR,
+	[DA906X_REG_GPO15_LED] =	RD | WR,
+
+	[DA906X_REG_ADC_CFG] =		RD | WR,
+	[DA906X_REG_AUTO1_HIGH] =	RD | WR,
+	[DA906X_REG_AUTO1_LOW] =	RD | WR,
+	[DA906X_REG_AUTO2_HIGH] =	RD | WR,
+	[DA906X_REG_AUTO2_LOW] =	RD | WR,
+	[DA906X_REG_AUTO3_HIGH] =	RD | WR,
+	[DA906X_REG_AUTO3_LOW] =	RD | WR,
+
+	[DA906X_REG_T_OFFSET] =		RD,
+	[DA906X_REG_CONFIG_H] =		RD,
+	[DA906X_REG_CONFIG_I] =		RD | WR,
+	[DA906X_REG_MON_REG_1] =	RD | WR,
+	[DA906X_REG_MON_REG_2] =	RD | WR,
+	[DA906X_REG_MON_REG_3] =	RD | WR,
+	[DA906X_REG_MON_REG_4] =	RD | WR,
+	[DA906X_REG_MON_REG_5] =	RD | VOL,
+	[DA906X_REG_MON_REG_6] =	RD | VOL,
+	[DA906X_REG_TRIM_CLDR] =	RD,
+
+	[DA906X_REG_GP_ID_0] =		RD | WR,
+	[DA906X_REG_GP_ID_1] =		RD | WR,
+	[DA906X_REG_GP_ID_2] =		RD | WR,
+	[DA906X_REG_GP_ID_3] =		RD | WR,
+	[DA906X_REG_GP_ID_4] =		RD | WR,
+	[DA906X_REG_GP_ID_5] =		RD | WR,
+	[DA906X_REG_GP_ID_6] =		RD | WR,
+	[DA906X_REG_GP_ID_7] =		RD | WR,
+	[DA906X_REG_GP_ID_8] =		RD | WR,
+	[DA906X_REG_GP_ID_9] =		RD | WR,
+	[DA906X_REG_GP_ID_10] =		RD | WR,
+	[DA906X_REG_GP_ID_11] =		RD | WR,
+	[DA906X_REG_GP_ID_12] =		RD | WR,
+	[DA906X_REG_GP_ID_13] =		RD | WR,
+	[DA906X_REG_GP_ID_14] =		RD | WR,
+	[DA906X_REG_GP_ID_15] =		RD | WR,
+	[DA906X_REG_GP_ID_16] =		RD | WR,
+	[DA906X_REG_GP_ID_17] =		RD | WR,
+	[DA906X_REG_GP_ID_18] =		RD | WR,
+	[DA906X_REG_GP_ID_19] =		RD | WR,
+
+	[DA906X_REG_CHIP_ID] =		RD,
+	[DA906X_REG_CHIP_VARIANT] =	RD,
+};
+
+static bool da906x_reg_readable(struct device *dev, unsigned int reg)
+{
+	if (reg < DA906X_MAPPING_BASE) {
+		return true;
+	} else {
+		reg -= DA906X_MAPPING_BASE;
+		if (da906x_reg_flg[reg] & RD)
+			return true;
+		else
+			return false;
+	}
+}
+
+static bool da906x_reg_writable(struct device *dev, unsigned int reg)
+{
+	if (reg < DA906X_MAPPING_BASE) {
+		return true;
+	} else {
+		reg -= DA906X_MAPPING_BASE;
+		if (da906x_reg_flg[reg] & WR)
+			return true;
+		else
+			return false;
+	}
+}
+
+static bool da906x_reg_volatile(struct device *dev, unsigned int reg)
+{
+	if (reg < DA906X_MAPPING_BASE) {
+		switch (reg) {
+		case DA906X_REG_PAGE_CON:    /* Use cache for page selector */
+			return false;
+		default:
+			return true;
+		}
+	} else {
+		reg -= DA906X_MAPPING_BASE;
+		if (da906x_reg_flg[reg] & VOL)
+			return true;
+		else
+			return false;
+	}
+}
+
+static const struct regmap_range_cfg da906x_range_cfg[] = {
+	{
+		.range_min = DA906X_MAPPING_BASE,
+		.range_max = DA906X_MAPPING_BASE +
+			     ARRAY_SIZE(da906x_reg_flg) - 1,
+		.selector_reg = DA906X_REG_PAGE_CON,
+		.selector_mask = 1 << DA906X_I2C_PAGE_SEL_SHIFT,
+		.selector_shift = DA906X_I2C_PAGE_SEL_SHIFT,
+		.window_start = 0,
+		.window_len = 256,
+	}
+};
+
+struct regmap_config da906x_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.ranges = da906x_range_cfg,
+	.n_ranges = ARRAY_SIZE(da906x_range_cfg),
+	.max_register = DA906X_MAPPING_BASE + ARRAY_SIZE(da906x_reg_flg) - 1,
+
+	.cache_type = REGCACHE_RBTREE,
+
+	.writeable_reg = &da906x_reg_writable,
+	.readable_reg = &da906x_reg_readable,
+	.volatile_reg = &da906x_reg_volatile,
+};
+
+struct regmap_config da906x_no_cache_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.ranges = da906x_range_cfg,
+	.n_ranges = ARRAY_SIZE(da906x_range_cfg),
+	.max_register = DA906X_MAPPING_BASE + ARRAY_SIZE(da906x_reg_flg) - 1,
+
+	.cache_type = REGCACHE_NONE,
+
+	.writeable_reg = &da906x_reg_writable,
+	.readable_reg = &da906x_reg_readable,
+};
+
+static int da906x_i2c_probe(struct i2c_client *i2c,
+	const struct i2c_device_id *id)
+{
+	struct da906x *da906x;
+	struct regmap_config *config = &da906x_regmap_config;
+	struct da906x_pdata *pdata = i2c->dev.platform_data;
+	int ret;
+
+	da906x = devm_kzalloc(&i2c->dev, sizeof(struct da906x), GFP_KERNEL);
+	if (da906x == NULL)
+		return -ENOMEM;
+
+	i2c_set_clientdata(i2c, da906x);
+	da906x->dev = &i2c->dev;
+
+	if (pdata->flags & DA906X_FLG_NO_CACHE)
+		config = &da906x_no_cache_regmap_config;
+
+	da906x->regmap = devm_regmap_init_i2c(i2c, config);
+	if (IS_ERR(da906x->regmap)) {
+		ret = PTR_ERR(da906x->regmap);
+		dev_err(da906x->dev, "Failed to allocate register map: %d\n",
+			ret);
+		return ret;
+	}
+
+	return da906x_device_init(da906x, i2c->irq);
+}
+
+static int da906x_i2c_remove(struct i2c_client *i2c)
+{
+	struct da906x *da906x = i2c_get_clientdata(i2c);
+
+	da906x_device_exit(da906x);
+
+	return 0;
+}
+
+static const struct i2c_device_id da906x_i2c_id[] = {
+	{"da906x", PMIC_DA9063},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, da906x_i2c_id);
+
+static struct i2c_driver da906x_i2c_driver = {
+	.driver = {
+		.name = "da906x",
+		.owner = THIS_MODULE,
+	},
+	.probe    = da906x_i2c_probe,
+	.remove   = da906x_i2c_remove,
+	.id_table = da906x_i2c_id,
+};
+
+static int __init da906x_i2c_init(void)
+{
+	int ret;
+
+	ret = i2c_add_driver(&da906x_i2c_driver);
+	if (ret != 0)
+		pr_err("Failed to register da906x I2C driver\n");
+
+	return ret;
+}
+subsys_initcall(da906x_i2c_init);
+
+static void __exit da906x_i2c_exit(void)
+{
+	i2c_del_driver(&da906x_i2c_driver);
+}
+module_exit(da906x_i2c_exit);
diff --git a/drivers/mfd/da906x-irq.c b/drivers/mfd/da906x-irq.c
new file mode 100644
index 0000000..18d2796
--- /dev/null
+++ b/drivers/mfd/da906x-irq.c
@@ -0,0 +1,192 @@
+/* da906x-irq.c: Interrupts support for Dialog DA906X
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ *
+ *  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/irq.h>
+#include <linux/mfd/core.h>
+#include <linux/interrupt.h>
+#include <linux/regmap.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+
+#define	DA906X_REG_EVENT_A_OFFSET	0
+#define	DA906X_REG_EVENT_B_OFFSET	1
+#define	DA906X_REG_EVENT_C_OFFSET	2
+#define	DA906X_REG_EVENT_D_OFFSET	3
+#define EVENTS_BUF_LEN			4
+
+static const u8 mask_events_buf[] = { [0 ... (EVENTS_BUF_LEN - 1)] = ~0 };
+
+struct da906x_irq_data {
+	u16 reg;
+	u8 mask;
+};
+
+static struct regmap_irq da906x_irqs[] = {
+	/* DA906x event A register */
+	[DA906X_IRQ_ONKEY] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_ONKEY,
+	},
+	[DA906X_IRQ_ALARM] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_ALARM,
+	},
+	[DA906X_IRQ_TICK] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_TICK,
+	},
+	[DA906X_IRQ_ADC_RDY] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_ADC_RDY,
+	},
+	[DA906X_IRQ_SEQ_RDY] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_SEQ_RDY,
+	},
+	/* DA906x event B register */
+	[DA906X_IRQ_WAKE] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_WAKE,
+	},
+	[DA906X_IRQ_TEMP] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_TEMP,
+	},
+	[DA906X_IRQ_COMP_1V2] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_COMP_1V2,
+	},
+	[DA906X_IRQ_LDO_LIM] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_LDO_LIM,
+	},
+	[DA906X_IRQ_REG_UVOV] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_UVOV,
+	},
+	[DA906X_IRQ_VDD_MON] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_VDD_MON,
+	},
+	[DA906X_IRQ_WARN] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_VDD_WARN,
+	},
+	/* DA906x event C register */
+	[DA906X_IRQ_GPI0] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI0,
+	},
+	[DA906X_IRQ_GPI1] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI1,
+	},
+	[DA906X_IRQ_GPI2] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI2,
+	},
+	[DA906X_IRQ_GPI3] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI3,
+	},
+	[DA906X_IRQ_GPI4] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI4,
+	},
+	[DA906X_IRQ_GPI5] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI5,
+	},
+	[DA906X_IRQ_GPI6] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI6,
+	},
+	[DA906X_IRQ_GPI7] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI7,
+	},
+	/* DA906x event D register */
+	[DA906X_IRQ_GPI8] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI8,
+	},
+	[DA906X_IRQ_GPI9] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI9,
+	},
+	[DA906X_IRQ_GPI10] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI10,
+	},
+	[DA906X_IRQ_GPI11] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI11,
+	},
+	[DA906X_IRQ_GPI12] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI12,
+	},
+	[DA906X_IRQ_GPI13] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI13,
+	},
+	[DA906X_IRQ_GPI14] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI14,
+	},
+	[DA906X_IRQ_GPI15] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI15,
+	},
+};
+
+static struct regmap_irq_chip da906x_irq_chip = {
+	.name = "da906x-irq",
+	.irqs = da906x_irqs,
+	.num_irqs = DA906X_NUM_IRQ,
+
+	.num_regs = 4,
+	.status_base = DA906X_REG_EVENT_A + DA906X_MAPPING_BASE,
+	.mask_base = DA906X_REG_IRQ_MASK_A + DA906X_MAPPING_BASE,
+	.ack_base = DA906X_REG_EVENT_A + DA906X_MAPPING_BASE,
+};
+
+int da906x_irq_init(struct da906x *da906x)
+{
+	int ret;
+
+	if (!da906x->chip_irq) {
+		dev_err(da906x->dev, "No IRQ configured\n");
+		return -EINVAL;
+	}
+
+	ret = regmap_add_irq_chip(da906x->regmap, da906x->chip_irq,
+			IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED,
+			da906x->irq_base, &da906x_irq_chip,
+			&da906x->regmap_irq);
+	if (ret) {
+		dev_err(da906x->dev, "Failed to reguest IRQ %d: %d\n",
+				da906x->chip_irq, ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+void da906x_irq_exit(struct da906x *da906x)
+{
+	regmap_del_irq_chip(da906x->chip_irq, da906x->regmap_irq);
+}
+
diff --git a/include/linux/mfd/da906x/core.h b/include/linux/mfd/da906x/core.h
new file mode 100644
index 0000000..abd916d
--- /dev/null
+++ b/include/linux/mfd/da906x/core.h
@@ -0,0 +1,121 @@
+/*
+ * Definitions for DA906X MFD driver
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ *	   Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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.
+ *
+ */
+
+#ifndef __MFD_DA906X_CORE_H__
+#define __MFD_DA906X_CORE_H__
+
+#include <linux/interrupt.h>
+#include <linux/mfd/da906x/registers.h>
+
+/* DA906x modules */
+#define DA906X_DRVNAME_CORE		"da906x-core"
+#define DA906X_DRVNAME_REGULATORS	"da906x-regulators"
+#define DA906X_DRVNAME_LEDS		"da906x-leds"
+#define DA906X_DRVNAME_WATCHDOG		"da906x-watchdog"
+#define DA906X_DRVNAME_HWMON		"da906x-hwmon"
+#define DA906X_DRVNAME_ONKEY		"da906x-onkey"
+#define DA906X_DRVNAME_RTC		"da906x-rtc"
+#define DA906X_DRVNAME_VIBRATION	"da906x-vibration"
+
+enum da906x_models {
+	PMIC_DA9063 = 0x61,
+};
+
+/* Interrupts */
+enum da906x_irqs {
+	DA906X_IRQ_ONKEY = 0,
+	DA906X_IRQ_ALARM,
+	DA906X_IRQ_TICK,
+	DA906X_IRQ_ADC_RDY,
+	DA906X_IRQ_SEQ_RDY,
+	DA906X_IRQ_WAKE,
+	DA906X_IRQ_TEMP,
+	DA906X_IRQ_COMP_1V2,
+	DA906X_IRQ_LDO_LIM,
+	DA906X_IRQ_REG_UVOV,
+	DA906X_IRQ_VDD_MON,
+	DA906X_IRQ_WARN,
+	DA906X_IRQ_GPI0,
+	DA906X_IRQ_GPI1,
+	DA906X_IRQ_GPI2,
+	DA906X_IRQ_GPI3,
+	DA906X_IRQ_GPI4,
+	DA906X_IRQ_GPI5,
+	DA906X_IRQ_GPI6,
+	DA906X_IRQ_GPI7,
+	DA906X_IRQ_GPI8,
+	DA906X_IRQ_GPI9,
+	DA906X_IRQ_GPI10,
+	DA906X_IRQ_GPI11,
+	DA906X_IRQ_GPI12,
+	DA906X_IRQ_GPI13,
+	DA906X_IRQ_GPI14,
+	DA906X_IRQ_GPI15,
+};
+
+#define DA906X_IRQ_BASE_OFFSET	0
+#define DA906X_NUM_IRQ		(DA906X_IRQ_GPI15 + 1 - DA906X_IRQ_BASE_OFFSET)
+
+struct da906x {
+	/* Device */
+	struct device	*dev;
+	unsigned short	model;
+	unsigned short	revision;
+	unsigned int	flags;
+
+	/* Control interface */
+	struct mutex	io_mutex;
+	struct regmap	*regmap;
+
+	/* Interrupts */
+	int		chip_irq;
+	unsigned int	irq_base;
+	struct regmap_irq_chip_data *regmap_irq;
+};
+
+static inline unsigned da906x_model(struct da906x *da906x)
+{
+	return da906x->model;
+}
+
+static inline unsigned da906x_revision(struct da906x *da906x)
+{
+	return da906x->revision;
+}
+
+static inline void da906x_set_model_rev(struct da906x *da906x,
+			enum da906x_models model, unsigned short revision)
+{
+	da906x->model = model;
+	da906x->revision = revision;
+}
+
+int da906x_reg_read(struct da906x *da906x, u16 reg);
+int da906x_reg_write(struct da906x *da906x, u16 reg, u8 val);
+
+int da906x_block_write(struct da906x *da906x, u16 reg, int bytes, const u8 *buf);
+int da906x_block_read(struct da906x *da906x, u16 reg, int bytes, u8 *buf);
+
+int da906x_reg_set_bits(struct da906x *da906x, u16 reg, u8 mask);
+int da906x_reg_clear_bits(struct da906x *da906x, u16 reg, u8 mask);
+int da906x_reg_update(struct da906x*, u16 reg, u8 mask, u8 val);
+
+int da906x_device_init(struct da906x *da906x, unsigned int irq);
+int da906x_irq_init(struct da906x *da906x);
+
+void da906x_device_exit(struct da906x *da906x);
+void da906x_irq_exit(struct da906x *da906x);
+
+#endif /* __MFD_DA906X_CORE_H__ */
diff --git a/include/linux/mfd/da906x/pdata.h b/include/linux/mfd/da906x/pdata.h
new file mode 100644
index 0000000..97ae242
--- /dev/null
+++ b/include/linux/mfd/da906x/pdata.h
@@ -0,0 +1,114 @@
+/*
+ * Platform configuration options for DA906x
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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.
+ *
+ */
+
+#ifndef __MFD_DA906X_PDATA_H__
+#define __MFD_DA906X_PDATA_H__
+
+#include <linux/regulator/machine.h>
+
+/*
+ * Regulator configuration
+ */
+/* DA9063 regulator IDs */
+enum {
+	/* BUCKs */
+	DA9063_ID_BCORE1,
+	DA9063_ID_BCORE2,
+	DA9063_ID_BPRO,
+	DA9063_ID_BMEM,
+	DA9063_ID_BIO,
+	DA9063_ID_BPERI,
+
+	/* BCORE1 and BCORE2 in merged mode */
+	DA9063_ID_BCORES_MERGED,
+	/* BMEM and BIO in merged mode */
+	DA9063_ID_BMEM_BIO_MERGED,
+	/* When two BUCKs are merged, they cannot be reused separately */
+
+	/* LDOs */
+	DA9063_ID_LDO1,
+	DA9063_ID_LDO2,
+	DA9063_ID_LDO3,
+	DA9063_ID_LDO4,
+	DA9063_ID_LDO5,
+	DA9063_ID_LDO6,
+	DA9063_ID_LDO7,
+	DA9063_ID_LDO8,
+	DA9063_ID_LDO9,
+	DA9063_ID_LDO10,
+	DA9063_ID_LDO11,
+
+	/* RTC internal oscilator switch */
+	DA9063_ID_32K_OUT,
+};
+
+/* Regulators platform data */
+struct da906x_regulator_data {
+	int				id;
+	struct regulator_init_data	*initdata;
+};
+
+struct da906x_regulators_pdata {
+	unsigned			n_regulators;
+	struct da906x_regulator_data	*regulator_data;
+};
+
+
+/*
+ * RGB LED configuration
+ */
+/* LED IDs for flags in struct led_info. */
+enum {
+	DA906X_GPIO11_LED,
+	DA906X_GPIO14_LED,
+	DA906X_GPIO15_LED,
+
+	DA906X_LED_NUM
+};
+#define DA906X_LED_ID_MASK		0x3
+
+/* LED polarity for flags in struct led_info. */
+#define DA906X_LED_HIGH_LEVEL_ACTIVE	0x0
+#define DA906X_LED_LOW_LEVEL_ACTIVE	0x4
+
+
+/*
+ * General PMIC configuration
+ */
+/* HWMON ADC channels configuration */
+#define DA906X_FLG_FORCE_IN0_MANUAL_MODE	0x0010
+#define DA906X_FLG_FORCE_IN0_AUTO_MODE		0x0020
+#define DA906X_FLG_FORCE_IN1_MANUAL_MODE	0x0040
+#define DA906X_FLG_FORCE_IN1_AUTO_MODE		0x0080
+#define DA906X_FLG_FORCE_IN2_MANUAL_MODE	0x0100
+#define DA906X_FLG_FORCE_IN2_AUTO_MODE		0x0200
+#define DA906X_FLG_FORCE_IN3_MANUAL_MODE	0x0400
+#define DA906X_FLG_FORCE_IN3_AUTO_MODE		0x0800
+
+/* Disable register caching. */
+#define DA906X_FLG_NO_CACHE			0x0008
+
+struct da906x;
+
+/* DA906x platform data */
+struct da906x_pdata {
+	int				(*init)(struct da906x *da906x);
+	int				irq_base;
+	unsigned			flags;
+	struct da906x_regulators_pdata	*regulators_pdata;
+	struct led_platform_data	*leds_pdata;
+};
+
+#endif	/* __MFD_DA906X_PDATA_H__ */
diff --git a/include/linux/mfd/da906x/registers.h b/include/linux/mfd/da906x/registers.h
new file mode 100644
index 0000000..6808977
--- /dev/null
+++ b/include/linux/mfd/da906x/registers.h
@@ -0,0 +1,1093 @@
+/*
+ * Registers definition for DA906X modules
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ *	   Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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.
+ *
+ */
+
+#ifndef _DA906X_REG_H
+#define	_DA906X_REG_H
+
+#define DA906X_I2C_PAGE_SEL_SHIFT	1
+#define DA906X_I2C_PAGE(v)		(((v) >> 8) << \
+						DA906X_I2C_PAGE_SEL_SHIFT)
+#define DA906X_I2C_REG(v)		((v) & 0xFF)
+
+#define	DA906X_EVENT_REG_NUM		4
+#define	DA9210_EVENT_REG_NUM		2
+#define	DA906X_EXT_EVENT_REG_NUM	(DA906X_EVENT_REG_NUM + \
+						DA9210_EVENT_REG_NUM)
+
+/* Page selection I2C or SPI always in the begining of any page. */
+/* Page 0 : I2C access 0x000 - 0x0FF	SPI access 0x000 - 0x07F */
+/* Page 1 :				SPI access 0x080 - 0x0FF */
+/* Page 2 : I2C access 0x100 - 0x1FF	SPI access 0x100 - 0x17F */
+/* Page 3 :				SPI access 0x180 - 0x1FF */
+#define	DA906X_REG_PAGE_CON		0x00
+
+/* Create virtual range for pageable registers just above physical range */
+#define DA906X_MAPPING_BASE		0x100
+
+/* System Control and Event Registers */
+#define	DA906X_REG_STATUS_A		0x01
+#define	DA906X_REG_STATUS_B		0x02
+#define	DA906X_REG_STATUS_C		0x03
+#define	DA906X_REG_STATUS_D		0x04
+#define	DA906X_REG_FAULT_LOG		0x05
+#define	DA906X_REG_EVENT_A		0x06
+#define	DA906X_REG_EVENT_B		0x07
+#define	DA906X_REG_EVENT_C		0x08
+#define	DA906X_REG_EVENT_D		0x09
+#define	DA906X_REG_IRQ_MASK_A		0x0A
+#define	DA906X_REG_IRQ_MASK_B		0x0B
+#define	DA906X_REG_IRQ_MASK_C		0x0C
+#define	DA906X_REG_IRQ_MASK_D		0x0D
+#define	DA906X_REG_CONTROL_A		0x0E
+#define	DA906X_REG_CONTROL_B		0x0F
+#define	DA906X_REG_CONTROL_C		0x10
+#define	DA906X_REG_CONTROL_D		0x11
+#define	DA906X_REG_CONTROL_E		0x12
+#define	DA906X_REG_CONTROL_F		0x13
+#define	DA906X_REG_PD_DIS		0x14
+
+/* GPIO Control Registers */
+#define	DA906X_REG_GPIO_0_1		0x15
+#define	DA906X_REG_GPIO_2_3		0x16
+#define	DA906X_REG_GPIO_4_5		0x17
+#define	DA906X_REG_GPIO_6_7		0x18
+#define	DA906X_REG_GPIO_8_9		0x19
+#define	DA906X_REG_GPIO_10_11		0x1A
+#define	DA906X_REG_GPIO_12_13		0x1B
+#define	DA906X_REG_GPIO_14_15		0x1C
+#define	DA906X_REG_GPIO_MODE_0_7	0x1D
+#define	DA906X_REG_GPIO_MODE_8_15	0x1E
+#define	DA906X_REG_GPIO_SWITCH_CONT	0x1F
+
+/* Regulator Control Registers */
+#define	DA906X_REG_BCORE2_CONT		0x20
+#define	DA906X_REG_BCORE1_CONT		0x21
+#define	DA906X_REG_BPRO_CONT		0x22
+#define	DA906X_REG_BMEM_CONT		0x23
+#define	DA906X_REG_BIO_CONT		0x24
+#define	DA906X_REG_BPERI_CONT		0x25
+#define	DA906X_REG_LDO1_CONT		0x26
+#define	DA906X_REG_LDO2_CONT		0x27
+#define	DA906X_REG_LDO3_CONT		0x28
+#define	DA906X_REG_LDO4_CONT		0x29
+#define	DA906X_REG_LDO5_CONT		0x2A
+#define	DA906X_REG_LDO6_CONT		0x2B
+#define	DA906X_REG_LDO7_CONT		0x2C
+#define	DA906X_REG_LDO8_CONT		0x2D
+#define	DA906X_REG_LDO9_CONT		0x2E
+#define	DA906X_REG_LDO10_CONT		0x2F
+#define	DA906X_REG_LDO11_CONT		0x30
+#define	DA906X_REG_VIB			0x31
+#define	DA906X_REG_DVC_1		0x32
+#define	DA906X_REG_DVC_2		0x33
+
+/* GP-ADC Control Registers */
+#define	DA906X_REG_ADC_MAN		0x34
+#define	DA906X_REG_ADC_CONT		0x35
+#define	DA906X_REG_VSYS_MON		0x36
+#define	DA906X_REG_ADC_RES_L		0x37
+#define	DA906X_REG_ADC_RES_H		0x38
+#define	DA906X_REG_VSYS_RES		0x39
+#define	DA906X_REG_ADCIN1_RES		0x3A
+#define	DA906X_REG_ADCIN2_RES		0x3B
+#define	DA906X_REG_ADCIN3_RES		0x3C
+#define	DA906X_REG_MON1_RES		0x3D
+#define	DA906X_REG_MON2_RES		0x3E
+#define	DA906X_REG_MON3_RES		0x3F
+
+/* RTC Calendar and Alarm Registers */
+#define	DA906X_REG_COUNT_S		0x40
+#define	DA906X_REG_COUNT_MI		0x41
+#define	DA906X_REG_COUNT_H		0x42
+#define	DA906X_REG_COUNT_D		0x43
+#define	DA906X_REG_COUNT_MO		0x44
+#define	DA906X_REG_COUNT_Y		0x45
+#define	DA906X_REG_ALARM_MI		0x46
+#define	DA906X_REG_ALARM_H		0x47
+#define	DA906X_REG_ALARM_D		0x48
+#define	DA906X_REG_ALARM_MO		0x49
+#define	DA906X_REG_ALARM_Y		0x4A
+#define	DA906X_REG_SECOND_A		0x4B
+#define	DA906X_REG_SECOND_B		0x4C
+#define	DA906X_REG_SECOND_C		0x4D
+#define	DA906X_REG_SECOND_D		0x4E
+
+/* Sequencer Control Registers */
+#define	DA906X_REG_SEQ			0x81
+#define	DA906X_REG_SEQ_TIMER		0x82
+#define	DA906X_REG_ID_2_1		0x83
+#define	DA906X_REG_ID_4_3		0x84
+#define	DA906X_REG_ID_6_5		0x85
+#define	DA906X_REG_ID_8_7		0x86
+#define	DA906X_REG_ID_10_9		0x87
+#define	DA906X_REG_ID_12_11		0x88
+#define	DA906X_REG_ID_14_13		0x89
+#define	DA906X_REG_ID_16_15		0x8A
+#define	DA906X_REG_ID_18_17		0x8B
+#define	DA906X_REG_ID_20_19		0x8C
+#define	DA906X_REG_ID_22_21		0x8D
+#define	DA906X_REG_ID_24_23		0x8E
+#define	DA906X_REG_ID_26_25		0x8F
+#define	DA906X_REG_ID_28_27		0x90
+#define	DA906X_REG_ID_30_29		0x91
+#define	DA906X_REG_ID_32_31		0x92
+#define	DA906X_REG_SEQ_A		0x95
+#define	DA906X_REG_SEQ_B		0x96
+#define	DA906X_REG_WAIT			0x97
+#define	DA906X_REG_EN_32K		0x98
+#define	DA906X_REG_RESET		0x99
+
+/* Regulator Setting Registers */
+#define	DA906X_REG_BUCK_ILIM_A		0x9A
+#define	DA906X_REG_BUCK_ILIM_B		0x9B
+#define	DA906X_REG_BUCK_ILIM_C		0x9C
+#define	DA906X_REG_BCORE2_CFG		0x9D
+#define	DA906X_REG_BCORE1_CFG		0x9E
+#define	DA906X_REG_BPRO_CFG		0x9F
+#define	DA906X_REG_BIO_CFG		0xA0
+#define	DA906X_REG_BMEM_CFG		0xA1
+#define	DA906X_REG_BPERI_CFG		0xA2
+#define	DA906X_REG_VBCORE2_A		0xA3
+#define	DA906X_REG_VBCORE1_A		0xA4
+#define	DA906X_REG_VBPRO_A		0xA5
+#define	DA906X_REG_VBMEM_A		0xA6
+#define	DA906X_REG_VBIO_A		0xA7
+#define	DA906X_REG_VBPERI_A		0xA8
+#define	DA906X_REG_VLDO1_A		0xA9
+#define	DA906X_REG_VLDO2_A		0xAA
+#define	DA906X_REG_VLDO3_A		0xAB
+#define	DA906X_REG_VLDO4_A		0xAC
+#define	DA906X_REG_VLDO5_A		0xAD
+#define	DA906X_REG_VLDO6_A		0xAE
+#define	DA906X_REG_VLDO7_A		0xAF
+#define	DA906X_REG_VLDO8_A		0xB0
+#define	DA906X_REG_VLDO9_A		0xB1
+#define	DA906X_REG_VLDO10_A		0xB2
+#define	DA906X_REG_VLDO11_A		0xB3
+#define	DA906X_REG_VBCORE2_B		0xB4
+#define	DA906X_REG_VBCORE1_B		0xB5
+#define	DA906X_REG_VBPRO_B		0xB6
+#define	DA906X_REG_VBMEM_B		0xB7
+#define	DA906X_REG_VBIO_B		0xB8
+#define	DA906X_REG_VBPERI_B		0xB9
+#define	DA906X_REG_VLDO1_B		0xBA
+#define	DA906X_REG_VLDO2_B		0xBB
+#define	DA906X_REG_VLDO3_B		0xBC
+#define	DA906X_REG_VLDO4_B		0xBD
+#define	DA906X_REG_VLDO5_B		0xBE
+#define	DA906X_REG_VLDO6_B		0xBF
+#define	DA906X_REG_VLDO7_B		0xC0
+#define	DA906X_REG_VLDO8_B		0xC1
+#define	DA906X_REG_VLDO9_B		0xC2
+#define	DA906X_REG_VLDO10_B		0xC3
+#define	DA906X_REG_VLDO11_B		0xC4
+
+/* Backup Battery Charger Control Register */
+#define	DA906X_REG_BBAT_CONT		0xC5
+
+/* GPIO PWM (LED) */
+#define	DA906X_REG_GPO11_LED		0xC6
+#define	DA906X_REG_GPO14_LED		0xC7
+#define	DA906X_REG_GPO15_LED		0xC8
+
+/* GP-ADC Threshold Registers */
+#define	DA906X_REG_ADC_CFG		0xC9
+#define	DA906X_REG_AUTO1_HIGH		0xCA
+#define	DA906X_REG_AUTO1_LOW		0xCB
+#define	DA906X_REG_AUTO2_HIGH		0xCC
+#define	DA906X_REG_AUTO2_LOW		0xCD
+#define	DA906X_REG_AUTO3_HIGH		0xCE
+#define	DA906X_REG_AUTO3_LOW		0xCF
+
+/* DA906x Configuration registers */
+/* OTP */
+#define	DA906X_REG_OPT_COUNT		0x101
+#define	DA906X_REG_OPT_ADDR		0x102
+#define	DA906X_REG_OPT_DATA		0x103
+
+/* Customer Trim and Configuration */
+#define	DA906X_REG_T_OFFSET		0x104
+#define	DA906X_REG_INTERFACE		0x105
+#define	DA906X_REG_CONFIG_A		0x106
+#define	DA906X_REG_CONFIG_B		0x107
+#define	DA906X_REG_CONFIG_C		0x108
+#define	DA906X_REG_CONFIG_D		0x109
+#define	DA906X_REG_CONFIG_E		0x10A
+#define	DA906X_REG_CONFIG_F		0x10B
+#define	DA906X_REG_CONFIG_G		0x10C
+#define	DA906X_REG_CONFIG_H		0x10D
+#define	DA906X_REG_CONFIG_I		0x10E
+#define	DA906X_REG_CONFIG_J		0x10F
+#define	DA906X_REG_CONFIG_K		0x110
+#define	DA906X_REG_CONFIG_L		0x111
+#define	DA906X_REG_MON_REG_1		0x112
+#define	DA906X_REG_MON_REG_2		0x113
+#define	DA906X_REG_MON_REG_3		0x114
+#define	DA906X_REG_MON_REG_4		0x115
+#define	DA906X_REG_MON_REG_5		0x116
+#define	DA906X_REG_MON_REG_6		0x117
+#define	DA906X_REG_TRIM_CLDR		0x118
+
+/* General Purpose Registers */
+#define	DA906X_REG_GP_ID_0		0x119
+#define	DA906X_REG_GP_ID_1		0x11A
+#define	DA906X_REG_GP_ID_2		0x11B
+#define	DA906X_REG_GP_ID_3		0x11C
+#define	DA906X_REG_GP_ID_4		0x11D
+#define	DA906X_REG_GP_ID_5		0x11E
+#define	DA906X_REG_GP_ID_6		0x11F
+#define	DA906X_REG_GP_ID_7		0x120
+#define	DA906X_REG_GP_ID_8		0x121
+#define	DA906X_REG_GP_ID_9		0x122
+#define	DA906X_REG_GP_ID_10		0x123
+#define	DA906X_REG_GP_ID_11		0x124
+#define	DA906X_REG_GP_ID_12		0x125
+#define	DA906X_REG_GP_ID_13		0x126
+#define	DA906X_REG_GP_ID_14		0x127
+#define	DA906X_REG_GP_ID_15		0x128
+#define	DA906X_REG_GP_ID_16		0x129
+#define	DA906X_REG_GP_ID_17		0x12A
+#define	DA906X_REG_GP_ID_18		0x12B
+#define	DA906X_REG_GP_ID_19		0x12C
+
+/* Chip ID and variant */
+#define	DA906X_REG_CHIP_ID		0x181
+#define	DA906X_REG_CHIP_VARIANT		0x182
+
+/*
+ * PMIC registers bits
+ */
+/* DA906X_REG_PAGE_CON (addr=0x00) */
+#define	DA906X_PEG_PAGE_SHIFT			0
+#define	DA906X_REG_PAGE_MASK			0x07
+#define		DA906X_REG_PAGE0		0x00
+#define		DA906X_REG_PAGE2		0x02
+#define	DA906X_PAGE_WRITE_MODE			0x00
+#define	DA906X_REPEAT_WRITE_MODE		0x40
+#define	DA906X_PAGE_REVERT			0x80
+
+/* DA906X_REG_STATUS_A (addr=0x01) */
+#define	DA906X_NONKEY				0x01
+#define	DA906X_WAKE				0x02
+#define	DA906X_DVC_BUSY				0x04
+#define	DA906X_COMP_1V2				0x08
+
+/* DA906X_REG_STATUS_B (addr=0x02) */
+#define	DA906X_GPI0				0x01
+#define	DA906X_GPI1				0x02
+#define	DA906X_GPI2				0x04
+#define	DA906X_GPI3				0x08
+#define	DA906X_GPI4				0x10
+#define	DA906X_GPI5				0x20
+#define	DA906X_GPI6				0x40
+#define	DA906X_GPI7				0x80
+
+/* DA906X_REG_STATUS_C (addr=0x03) */
+#define	DA906X_GPI8				0x01
+#define	DA906X_GPI9				0x02
+#define	DA906X_GPI10				0x04
+#define	DA906X_GPI11				0x08
+#define	DA906X_GPI12				0x10
+#define	DA906X_GPI13				0x20
+#define	DA906X_GPI14				0x40
+#define	DA906X_GPI15				0x80
+
+/* DA906X_REG_STATUS_D (addr=0x04) */
+#define	DA906X_LDO3_LIM				0x08
+#define	DA906X_LDO4_LIM				0x10
+#define	DA906X_LDO7_LIM				0x20
+#define	DA906X_LDO8_LIM				0x40
+#define	DA906X_LDO11_LIM			0x80
+
+/* DA906X_REG_FAULT_LOG (addr=0x05) */
+#define	DA906X_TWD_ERROR			0x01
+#define	DA906X_POR				0x02
+#define	DA906X_VDD_FAULT			0x04
+#define	DA906X_VDD_START			0x08
+#define	DA906X_TEMP_CRIT			0x10
+#define	DA906X_KEY_RESET			0x20
+#define	DA906X_NSHUTDOWN			0x40
+#define	DA906X_WAIT_SHUT			0x80
+
+/* DA906X_REG_EVENT_A (addr=0x06) */
+#define	DA906X_E_NONKEY				0x01
+#define	DA906X_E_ALARM				0x02
+#define	DA906X_E_TICK				0x04
+#define	DA906X_E_ADC_RDY			0x08
+#define	DA906X_E_SEQ_RDY			0x10
+#define	DA906X_EVENTS_B				0x20
+#define	DA906X_EVENTS_C				0x40
+#define	DA906X_EVENTS_D				0x80
+
+/* DA906X_REG_EVENT_B (addr=0x07) */
+#define	DA906X_E_WAKE				0x01
+#define	DA906X_E_TEMP				0x02
+#define	DA906X_E_COMP_1V2			0x04
+#define	DA906X_E_LDO_LIM			0x08
+#define	DA906X_E_REG_UVOV			0x10
+#define	DA906X_E_DVC_RDY			0x20
+#define	DA906X_E_VDD_MON			0x40
+#define	DA906X_E_VDD_WARN			0x80
+
+/* DA906X_REG_EVENT_C (addr=0x08) */
+#define	DA906X_E_GPI0				0x01
+#define	DA906X_E_GPI1				0x02
+#define	DA906X_E_GPI2				0x04
+#define	DA906X_E_GPI3				0x08
+#define	DA906X_E_GPI4				0x10
+#define	DA906X_E_GPI5				0x20
+#define	DA906X_E_GPI6				0x40
+#define	DA906X_E_GPI7				0x80
+
+/* DA906X_REG_EVENT_D (addr=0x09) */
+#define	DA906X_E_GPI8				0x01
+#define	DA906X_E_GPI9				0x02
+#define	DA906X_E_GPI10				0x04
+#define	DA906X_E_GPI11				0x08
+#define	DA906X_E_GPI12				0x10
+#define	DA906X_E_GPI13				0x20
+#define	DA906X_E_GPI14				0x40
+#define	DA906X_E_GPI15				0x80
+
+/* DA906X_REG_IRQ_MASK_A (addr=0x0A) */
+#define	DA906X_M_ONKEY				0x01
+#define	DA906X_M_ALARM				0x02
+#define	DA906X_M_TICK				0x04
+#define	DA906X_M_ADC_RDY			0x08
+#define	DA906X_M_SEQ_RDY			0x10
+
+/* DA906X_REG_IRQ_MASK_B (addr=0x0B) */
+#define	DA906X_M_WAKE				0x01
+#define	DA906X_M_TEMP				0x02
+#define	DA906X_M_COMP_1V2			0x04
+#define	DA906X_M_LDO_LIM			0x08
+#define	DA906X_M_UVOV				0x10
+#define	DA906X_M_DVC_RDY			0x20
+#define	DA906X_M_VDD_MON			0x40
+#define	DA906X_M_VDD_WARN			0x80
+
+/* DA906X_REG_IRQ_MASK_C (addr=0x0C) */
+#define	DA906X_M_GPI0				0x01
+#define	DA906X_M_GPI1				0x02
+#define	DA906X_M_GPI2				0x04
+#define	DA906X_M_GPI3				0x08
+#define	DA906X_M_GPI4				0x10
+#define	DA906X_M_GPI5				0x20
+#define	DA906X_M_GPI6				0x40
+#define	DA906X_M_GPI7				0x80
+
+/* DA906X_REG_IRQ_MASK_D (addr=0x0D) */
+#define	DA906X_M_GPI8				0x01
+#define	DA906X_M_GPI9				0x02
+#define	DA906X_M_GPI10				0x04
+#define	DA906X_M_GPI11				0x08
+#define	DA906X_M_GPI12				0x10
+#define	DA906X_M_GPI13				0x20
+#define	DA906X_M_GPI14				0x40
+#define	DA906X_M_GPI15				0x80
+
+/* DA906X_REG_CONTROL_A (addr=0x0E) */
+#define	DA906X_SYSTEM_EN			0x01
+#define	DA906X_POWER_EN				0x02
+#define	DA906X_POWER1_EN			0x04
+#define	DA906X_STANDBY				0x08
+#define	DA906X_M_SYSTEM_EN			0x10
+#define	DA906X_M_POWER_EN			0x20
+#define	DA906X_M_POWER1_EN			0x40
+#define	DA906X_CP_EN				0x80
+
+/* DA906X_REG_CONTROL_B (addr=0x0F) */
+#define	DA906X_CHG_SEL				0x01
+#define	DA906X_WATCHDOG_PD			0x02
+#define	DA906X_NRES_MODE			0x08
+#define	DA906X_NONKEY_LOCK			0x10
+
+/* DA906X_REG_CONTROL_C (addr=0x10) */
+#define	DA906X_DEBOUNCING_SHIFT			0
+#define	DA906X_DEBOUNCING_MASK			0x07
+#define		DA906X_DEBOUNCING_OFF		0x0
+#define		DA906X_DEBOUNCING_0MS1		0x1
+#define		DA906X_DEBOUNCING_1MS		0x2
+#define		DA906X_DEBOUNCING_10MS24	0x3
+#define		DA906X_DEBOUNCING_51MS2		0x4
+#define		DA906X_DEBOUNCING_256MS		0x5
+#define		DA906X_DEBOUNCING_512MS		0x6
+#define		DA906X_DEBOUNCING_1024MS	0x7
+
+#define	DA906X_AUTO_BOOT			0x08
+#define	DA906X_OTPREAD_EN			0x10
+#define	DA906X_SLEW_RATE_SHIFT			5
+#define	DA906X_SLEW_RATE_MASK			0x60
+#define		DA906X_SLEW_RATE_4US		0x00
+#define		DA906X_SLEW_RATE_3US		0x20
+#define		DA906X_SLEW_RATE_1US		0x40
+#define		DA906X_SLEW_RATE_0US5		0x60
+#define	DA906X_DEF_SUPPLY			0x80
+
+/* DA906X_REG_CONTROL_D (addr=0x11) */
+#define	DA906X_TWDSCALE_SHIFT			0
+#define	DA906X_TWDSCALE_MASK			0x07
+#define	DA906X_BLINK_FRQ_SHIFT			3
+#define	DA906X_BLINK_FRQ_MASK			0x38
+#define		DA906X_BLINK_FRQ_OFF		0x00
+#define		DA906X_BLINK_FRQ_1S0		0x08
+#define		DA906X_BLINK_FRQ_2S0		0x10
+#define		DA906X_BLINK_FRQ_4S0		0x18
+#define		DA906X_BLINK_FRQ_0S18		0x20
+#define		DA906X_BLINK_FRQ_2S0_VDD	0x28
+#define		DA906X_BLINK_FRQ_4S0_VDD	0x30
+#define		DA906X_BLINK_FRQ_0S18_VDD	0x38
+
+#define	DA906X_BLINK_DUR_SHIFT			6
+#define	DA906X_BLINK_DUR_MASK			0xC0
+#define		DA906X_BLINK_DUR_10MS		0x00
+#define		DA906X_BLINK_DUR_20MS		0x40
+#define		DA906X_BLINK_DUR_40MS		0x80
+#define		DA906X_BLINK_DUR_20MSDBL	0xC0
+
+/* DA906X_REG_CONTROL_E (addr=0x12) */
+#define	DA906X_RTC_MODE_PD			0x01
+#define	DA906X_RTC_MODE_SD			0x02
+#define	DA906X_RTC_EN				0x04
+#define	DA906X_ECO_MODE				0x08
+#define	DA906X_PM_FB1_PIN			0x10
+#define	DA906X_PM_FB2_PIN			0x20
+#define	DA906X_PM_FB3_PIN			0x40
+#define	DA906X_V_LOCK				0x80
+
+/* DA906X_REG_CONTROL_F (addr=0x13) */
+#define	DA906X_WATCHDOG				0x01
+#define	DA906X_SHUTDOWN				0x02
+#define	DA906X_WAKE_UP				0x04
+
+/* DA906X_REG_PD_DIS (addr=0x14) */
+#define	DA906X_GPI_DIS				0x01
+#define	DA906X_GPADC_PAUSE			0x02
+#define	DA906X_PMIF_DIS				0x04
+#define	DA906X_HS2WIRE_DIS			0x08
+#define	DA906X_BBAT_DIS				0x20
+#define	DA906X_OUT_32K_PAUSE			0x40
+#define	DA906X_PMCONT_DIS			0x80
+
+/* DA906X_REG_GPIO_0_1 (addr=0x15) */
+#define	DA906X_GPIO0_PIN_SHIFT			0
+#define	DA906X_GPIO0_PIN_MASK			0x03
+#define		DA906X_GPIO0_PIN_ADCIN1		0x00
+#define		DA906X_GPIO0_PIN_GPI		0x01
+#define		DA906X_GPIO0_PIN_GPO_OD		0x02
+#define		DA906X_GPIO0_PIN_GPO		0x03
+#define	DA906X_GPIO0_TYPE			0x04
+#define		DA906X_GPIO0_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO0_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO0_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO0_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO0_NO_WAKEUP			0x08
+#define	DA906X_GPIO1_PIN_SHIFT			4
+#define	DA906X_GPIO1_PIN_MASK			0x30
+#define		DA906X_GPIO1_PIN_ADCIN2_COMP	0x00
+#define		DA906X_GPIO1_PIN_GPI		0x10
+#define		DA906X_GPIO1_PIN_GPO_OD		0x20
+#define		DA906X_GPIO1_PIN_GPO		0x30
+#define	DA906X_GPIO1_TYPE			0x40
+#define		DA906X_GPIO1_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO1_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO1_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO1_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO1_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_2_3 (addr=0x16) */
+#define	DA906X_GPIO2_PIN_SHIFT			0
+#define	DA906X_GPIO2_PIN_MASK			0x03
+#define		DA906X_GPIO2_PIN_ADCIN3		0x00
+#define		DA906X_GPIO2_PIN_GPI		0x01
+#define		DA906X_GPIO2_PIN_GPO_PSS	0x02
+#define		DA906X_GPIO2_PIN_GPO		0x03
+#define	DA906X_GPIO2_TYPE			0x04
+#define		DA906X_GPIO2_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO2_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO2_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO2_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO2_NO_WAKEUP			0x08
+#define	DA906X_GPIO3_PIN_SHIFT			4
+#define	DA906X_GPIO3_PIN_MASK			0x30
+#define		DA906X_GPIO3_PIN_CORE_SW_G	0x00
+#define		DA906X_GPIO3_PIN_GPI		0x10
+#define		DA906X_GPIO3_PIN_GPO_OD		0x20
+#define		DA906X_GPIO3_PIN_GPO		0x30
+#define	DA906X_GPIO3_TYPE			0x40
+#define		DA906X_GPIO3_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO3_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO3_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO3_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO3_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_4_5 (addr=0x17) */
+#define	DA906X_GPIO4_PIN_SHIFT			0
+#define	DA906X_GPIO4_PIN_MASK			0x03
+#define		DA906X_GPIO4_PIN_CORE_SW_S	0x00
+#define		DA906X_GPIO4_PIN_GPI		0x01
+#define		DA906X_GPIO4_PIN_GPO_OD		0x02
+#define		DA906X_GPIO4_PIN_GPO		0x03
+#define	DA906X_GPIO4_TYPE			0x04
+#define		DA906X_GPIO4_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO4_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO4_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO4_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO4_NO_WAKEUP			0x08
+#define	DA906X_GPIO5_PIN_SHIFT			4
+#define	DA906X_GPIO5_PIN_MASK			0x30
+#define		DA906X_GPIO5_PIN_PERI_SW_G	0x00
+#define		DA906X_GPIO5_PIN_GPI		0x10
+#define		DA906X_GPIO5_PIN_GPO_OD		0x20
+#define		DA906X_GPIO5_PIN_GPO		0x30
+#define	DA906X_GPIO5_TYPE			0x40
+#define		DA906X_GPIO5_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO5_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO5_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO5_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO5_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_6_7 (addr=0x18) */
+#define	DA906X_GPIO6_PIN_SHIFT			0
+#define	DA906X_GPIO6_PIN_MASK			0x03
+#define		DA906X_GPIO6_PIN_PERI_SW_S	0x00
+#define		DA906X_GPIO6_PIN_GPI		0x01
+#define		DA906X_GPIO6_PIN_GPO_OD		0x02
+#define		DA906X_GPIO6_PIN_GPO		0x03
+#define	DA906X_GPIO6_TYPE			0x04
+#define		DA906X_GPIO6_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO6_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO6_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO6_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO6_NO_WAKEUP			0x08
+#define	DA906X_GPIO7_PIN_SHIFT			4
+#define	DA906X_GPIO7_PIN_MASK			0x30
+#define		DA906X_GPIO7_PIN_GPI		0x10
+#define		DA906X_GPIO7_PIN_GPO_PSS	0x20
+#define		DA906X_GPIO7_PIN_GPO		0x30
+#define	DA906X_GPIO7_TYPE			0x40
+#define		DA906X_GPIO7_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO7_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO7_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO7_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO7_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_8_9 (addr=0x19) */
+#define	DA906X_GPIO8_PIN_SHIFT			0
+#define	DA906X_GPIO8_PIN_MASK			0x03
+#define		DA906X_GPIO8_PIN_GPI_SYS_EN	0x00
+#define		DA906X_GPIO8_PIN_GPI		0x01
+#define		DA906X_GPIO8_PIN_GPO_PSS	0x02
+#define		DA906X_GPIO8_PIN_GPO		0x03
+#define	DA906X_GPIO8_TYPE			0x04
+#define		DA906X_GPIO8_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO8_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO8_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO8_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO8_NO_WAKEUP			0x08
+#define	DA906X_GPIO9_PIN_SHIFT			4
+#define	DA906X_GPIO9_PIN_MASK			0x30
+#define		DA906X_GPIO9_PIN_GPI_PWR_EN	0x00
+#define		DA906X_GPIO9_PIN_GPI		0x10
+#define		DA906X_GPIO9_PIN_GPO_PSS	0x20
+#define		DA906X_GPIO9_PIN_GPO		0x30
+#define	DA906X_GPIO9_TYPE			0x40
+#define		DA906X_GPIO9_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO9_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO9_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO9_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO9_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_10_11 (addr=0x1A) */
+#define	DA906X_GPIO10_PIN_SHIFT			0
+#define	DA906X_GPIO10_PIN_MASK			0x03
+#define		DA906X_GPIO10_PIN_GPI_PWR1_EN	0x00
+#define		DA906X_GPIO10_PIN_GPI		0x01
+#define		DA906X_GPIO10_PIN_GPO_OD	0x02
+#define		DA906X_GPIO10_PIN_GPO		0x03
+#define	DA906X_GPIO10_TYPE			0x04
+#define		DA906X_GPIO10_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO10_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO10_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO10_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO10_NO_WAKEUP			0x08
+#define	DA906X_GPIO11_PIN_SHIFT			4
+#define	DA906X_GPIO11_PIN_MASK			0x30
+#define		DA906X_GPIO11_PIN_GPO_OD	0x00
+#define		DA906X_GPIO11_PIN_GPI		0x10
+#define		DA906X_GPIO11_PIN_GPO_PSS	0x20
+#define		DA906X_GPIO11_PIN_GPO		0x30
+#define	DA906X_GPIO11_TYPE			0x40
+#define		DA906X_GPIO11_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO11_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO11_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO11_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO11_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_12_13 (addr=0x1B) */
+#define	DA906X_GPIO12_PIN_SHIFT			0
+#define	DA906X_GPIO12_PIN_MASK			0x03
+#define		DA906X_GPIO12_PIN_NVDDFLT_OUT	0x00
+#define		DA906X_GPIO12_PIN_GPI		0x01
+#define		DA906X_GPIO12_PIN_VSYSMON_OUT	0x02
+#define		DA906X_GPIO12_PIN_GPO		0x03
+#define	DA906X_GPIO12_TYPE			0x04
+#define		DA906X_GPIO12_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO12_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO12_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO12_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO12_NO_WAKEUP			0x08
+#define	DA906X_GPIO13_PIN_SHIFT			4
+#define	DA906X_GPIO13_PIN_MASK			0x30
+#define		DA906X_GPIO13_PIN_GPFB1_OUT	0x00
+#define		DA906X_GPIO13_PIN_GPI		0x10
+#define		DA906X_GPIO13_PIN_GPFB1_OUTOD	0x20
+#define		DA906X_GPIO13_PIN_GPO		0x30
+#define	DA906X_GPIO13_TYPE			0x40
+#define		DA906X_GPIO13_TYPE_GPFB1_OUT	0x00
+#define		DA906X_GPIO13_TYPE_GPI		0x00
+#define		DA906X_GPIO13_TYPE_GPFB1_OUTOD	0x04
+#define		DA906X_GPIO13_TYPE_GPO		0x04
+#define	DA906X_GPIO13_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_14_15 (addr=0x1C) */
+#define	DA906X_GPIO14_PIN_SHIFT			0
+#define	DA906X_GPIO14_PIN_MASK			0x03
+#define		DA906X_GPIO14_PIN_GPO_OD	0x00
+#define		DA906X_GPIO14_PIN_GPI		0x01
+#define		DA906X_GPIO14_PIN_HS2DATA	0x02
+#define		DA906X_GPIO14_PIN_GPO		0x03
+#define	DA906X_GPIO14_TYPE			0x04
+#define		DA906X_GPIO14_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO14_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO14_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO14_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO14_NO_WAKEUP			0x08
+#define	DA906X_GPIO15_PIN_SHIFT			4
+#define	DA906X_GPIO15_PIN_MASK			0x30
+#define		DA906X_GPIO15_PIN_GPO_OD	0x00
+#define		DA906X_GPIO15_PIN_GPI		0x10
+#define		DA906X_GPIO15_PIN_GPO		0x30
+#define	DA906X_GPIO15_TYPE			0x40
+#define		DA906X_GPIO15_TYPE_GPFB1_OUT	0x00
+#define		DA906X_GPIO15_TYPE_GPI		0x00
+#define		DA906X_GPIO15_TYPE_GPFB1_OUTOD	0x04
+#define		DA906X_GPIO15_TYPE_GPO		0x04
+#define	DA906X_GPIO15_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_MODE_0_7 (addr=0x1D) */
+#define	DA906X_GPIO0_MODE			0x01
+#define	DA906X_GPIO1_MODE			0x02
+#define	DA906X_GPIO2_MODE			0x04
+#define	DA906X_GPIO3_MODE			0x08
+#define	DA906X_GPIO4_MODE			0x10
+#define	DA906X_GPIO5_MODE			0x20
+#define	DA906X_GPIO6_MODE			0x40
+#define	DA906X_GPIO7_MODE			0x80
+
+/* DA906X_REG_GPIO_MODE_8_15 (addr=0x1E) */
+#define	DA906X_GPIO8_MODE			0x01
+#define	DA906X_GPIO9_MODE			0x02
+#define	DA906X_GPIO10_MODE			0x04
+#define	DA906X_GPIO11_MODE			0x08
+#define		DA906X_GPIO11_MODE_LED_ACT_HIGH	0x00
+#define		DA906X_GPIO11_MODE_LED_ACT_LOW	0x08
+#define	DA906X_GPIO12_MODE			0x10
+#define	DA906X_GPIO13_MODE			0x20
+#define	DA906X_GPIO14_MODE			0x40
+#define		DA906X_GPIO14_MODE_LED_ACT_HIGH	0x00
+#define		DA906X_GPIO14_MODE_LED_ACT_LOW	0x40
+#define	DA906X_GPIO15_MODE			0x80
+#define		DA906X_GPIO15_MODE_LED_ACT_HIGH	0x00
+#define		DA906X_GPIO15_MODE_LED_ACT_LOW	0x80
+
+/* DA906X_REG_SWITCH_CONT (addr=0x1F) */
+#define	DA906X_CORE_SW_GPI_SHIFT		0
+#define	DA906X_CORE_SW_GPI_MASK			0x03
+#define		DA906X_CORE_SW_GPI_OFF		0x00
+#define		DA906X_CORE_SW_GPI_GPIO1	0x01
+#define		DA906X_CORE_SW_GPI_GPIO2	0x02
+#define		DA906X_CORE_SW_GPI_GPIO13	0x03
+#define	DA906X_PERI_SW_GPI_SHIFT		2
+#define	DA906X_PERI_SW_GPI_MASK			0x0C
+#define		DA906X_PERI_SW_GPI_OFF		0x00
+#define		DA906X_PERI_SW_GPI_GPIO1	0x04
+#define		DA906X_PERI_SW_GPI_GPIO2	0x08
+#define		DA906X_PERI_SW_GPI_GPIO13	0x0C
+#define	DA906X_SWITCH_SR_SHIFT			4
+#define	DA906X_SWITCH_SR_MASK			0x30
+#define		DA906X_SWITCH_SR_1MV		0x00
+#define		DA906X_SWITCH_SR_5MV		0x10
+#define		DA906X_SWITCH_SR_10MV		0x20
+#define		DA906X_SWITCH_SR_50MV		0x30
+#define	DA906X_SWITCH_SR_DIS			0x40
+#define	DA906X_CP_EN_MODE			0x80
+
+/* DA906X_REGL_Bxxxx_CONT common bits (addr=0x20-0x25) */
+#define	DA906X_BUCK_EN				0x01
+#define	DA906X_BUCK_GPI_SHIFT			1
+#define DA906X_BUCK_GPI_MASK			0x06
+#define		DA906X_BUCK_GPI_OFF		0x00
+#define		DA906X_BUCK_GPI_GPIO1		0x02
+#define		DA906X_BUCK_GPI_GPIO2		0x04
+#define		DA906X_BUCK_GPI_GPIO13		0x06
+#define	DA906X_BUCK_CONF			0x08
+#define	DA906X_VBUCK_GPI_SHIFT			5
+#define	DA906X_VBUCK_GPI_MASK			0x60
+#define		DA906X_VBUCK_GPI_OFF		0x00
+#define		DA906X_VBUCK_GPI_GPIO1		0x20
+#define		DA906X_VBUCK_GPI_GPIO2		0x40
+#define		DA906X_VBUCK_GPI_GPIO13		0x60
+
+/* DA906X_REG_BCORE1_CONT specific bits (addr=0x21) */
+#define	DA906X_CORE_SW_EN			0x10
+#define	DA906X_CORE_SW_CONF			0x80
+
+/* DA906X_REG_BPERI_CONT specific bits (addr=0x25) */
+#define	DA906X_PERI_SW_EN			0x10
+#define	DA906X_PERI_SW_CONF			0x80
+
+/* DA906X_REG_LDOx_CONT common bits (addr=0x26-0x30) */
+#define	DA906X_LDO_EN				0x01
+#define	DA906X_LDO_GPI_SHIFT			1
+#define DA906X_LDO_GPI_MASK			0x06
+#define		DA906X_LDO_GPI_OFF		0x00
+#define		DA906X_LDO_GPI_GPIO1		0x02
+#define		DA906X_LDO_GPI_GPIO2		0x04
+#define		DA906X_LDO_GPI_GPIO13		0x06
+#define	DA906X_LDO_PD_DIS			0x08
+#define	DA906X_VLDO_GPI_SHIFT			5
+#define	DA906X_VLDO_GPI_MASK			0x60
+#define		DA906X_VLDO_GPI_OFF		0x00
+#define		DA906X_VLDO_GPI_GPIO1		0x20
+#define		DA906X_VLDO_GPI_GPIO2		0x40
+#define		DA906X_VLDO_GPI_GPIO13		0x60
+#define	DA906X_LDO_CONF				0x80
+
+/* DA906X_REG_LDO5_CONT specific bits (addr=0x2A) */
+#define	DA906X_VLDO5_SEL			0x10
+
+/* DA906X_REG_LDO6_CONT specific bits (addr=0x2B) */
+#define	DA906X_VLDO6_SEL			0x10
+
+/* DA906X_REG_LDO7_CONT specific bits (addr=0x2C) */
+#define	DA906X_VLDO7_SEL			0x10
+
+/* DA906X_REG_LDO8_CONT specific bits (addr=0x2D) */
+#define	DA906X_VLDO8_SEL			0x10
+
+/* DA906X_REG_LDO9_CONT specific bits (addr=0x2E) */
+#define	DA906X_VLDO9_SEL			0x10
+
+/* DA906X_REG_LDO10_CONT specific bits (addr=0x2F) */
+#define	DA906X_VLDO10_SEL			0x10
+
+/* DA906X_REG_LDO11_CONT specific bits (addr=0x30) */
+#define	DA906X_VLDO11_SEL			0x10
+
+/* DA906X_REG_VIB (addr=0x31) */
+#define DA906X_VIB_SET_MASK			0x3F
+#define		DA906X_VIB_SET_OFF		0
+#define		DA906X_VIB_SET_MAX		0x3F
+
+/* DA906X_REG_DVC_1 (addr=0x32) */
+#define	DA906X_VBCORE1_SEL			0x01
+#define	DA906X_VBCORE2_SEL			0x02
+#define	DA906X_VBPRO_SEL			0x04
+#define	DA906X_VBMEM_SEL			0x08
+#define	DA906X_VBPERI_SEL			0x10
+#define	DA906X_VLDO1_SEL			0x20
+#define	DA906X_VLDO2_SEL			0x40
+#define	DA906X_VLDO3_SEL			0x80
+
+/* DA906X_REG_DVC_2 (addr=0x33) */
+#define	DA906X_VBIO_SEL				0x01
+#define	DA906X_VLDO4_SEL			0x80
+
+/* DA906X_REG_ADC_MAN (addr=0x34) */
+#define	DA906X_ADC_MUX_SHIFT			0
+#define	DA906X_ADC_MUX_MASK			0x0F
+#define		DA906X_ADC_MUX_VSYS		0x00
+#define		DA906X_ADC_MUX_ADCIN1		0x01
+#define		DA906X_ADC_MUX_ADCIN2		0x02
+#define		DA906X_ADC_MUX_ADCIN3		0x03
+#define		DA906X_ADC_MUX_T_SENSE		0x04
+#define		DA906X_ADC_MUX_VBBAT		0x05
+#define		DA906X_ADC_MUX_LDO_G1		0x08
+#define		DA906X_ADC_MUX_LDO_G2		0x09
+#define		DA906X_ADC_MUX_LDO_G3		0x0A
+#define	DA906X_ADC_MAN				0x10
+#define	DA906X_ADC_MODE				0x20
+
+/* DA906X_REG_ADC_CONT (addr=0x35) */
+#define	DA906X_ADC_AUTO_VSYS_EN			0x01
+#define	DA906X_ADC_AUTO_AD1_EN			0x02
+#define	DA906X_ADC_AUTO_AD2_EN			0x04
+#define	DA906X_ADC_AUTO_AD3_EN			0x08
+#define	DA906X_ADC_AD1_ISRC_EN			0x10
+#define	DA906X_ADC_AD2_ISRC_EN			0x20
+#define	DA906X_ADC_AD3_ISRC_EN			0x40
+#define	DA906X_COMP1V2_EN			0x80
+
+/* DA906X_REG_VSYS_MON (addr=0x36) */
+#define	DA906X_VSYS_VAL_SHIFT			0
+#define	DA906X_VSYS_VAL_MASK			0xFF
+#define	DA906X_VSYS_VAL_BASE			0x00
+
+/* DA906X_REG_ADC_RES_L (addr=0x37) */
+#define	DA906X_ADC_RES_L_SHIFT			6
+#define	DA906X_ADC_RES_L_BITS			2
+#define	DA906X_ADC_RES_L_MASK			0xC0
+
+/* DA906X_REG_ADC_RES_H (addr=0x38) */
+#define	DA906X_ADC_RES_M_SHIFT			0
+#define	DA906X_ADC_RES_M_BITS			8
+#define	DA906X_ADC_RES_M_MASK			0xFF
+
+/* DA906X_REG_(xxx_RES/ADC_RES_H) (addr=0x39-0x3F) */
+#define	DA906X_ADC_VAL_SHIFT			0
+#define	DA906X_ADC_VAL_MASK			0xFF
+
+/* DA906X_REG_COUNT_S (addr=0x40) */
+#define DA906X_RTC_READ				0x80
+#define DA906X_COUNT_SEC_MASK			0x3F
+
+/* DA906X_REG_COUNT_MI (addr=0x41) */
+#define DA906X_COUNT_MIN_MASK			0x3F
+
+/* DA906X_REG_COUNT_H (addr=0x42) */
+#define DA906X_COUNT_HOUR_MASK			0x1F
+
+/* DA906X_REG_COUNT_D (addr=0x43) */
+#define DA906X_COUNT_DAY_MASK			0x1F
+
+/* DA906X_REG_COUNT_MO (addr=0x44) */
+#define DA906X_COUNT_MONTH_MASK			0x0F
+
+/* DA906X_REG_COUNT_Y (addr=0x45) */
+#define DA906X_COUNT_YEAR_MASK			0x3F
+#define DA906X_MONITOR				0x40
+
+/* DA906X_REG_ALARM_MI (addr=0x46) */
+#define DA906X_ALARM_STATUS_ALARM		0x80
+#define DA906X_ALARM_STATUS_TICK		0x40
+#define DA906X_ALARM_MIN_MASK			0x3F
+
+/* DA906X_REG_ALARM_H (addr=0x47) */
+#define DA906X_ALARM_HOUR_MASK			0x1F
+
+/* DA906X_REG_ALARM_D (addr=0x48) */
+#define DA906X_ALARM_DAY_MASK			0x1F
+
+/* DA906X_REG_ALARM_MO (addr=0x49) */
+#define DA906X_TICK_WAKE			0x20
+#define DA906X_TICK_TYPE			0x10
+#define		DA906X_TICK_TYPE_SEC		0x00
+#define		DA906X_TICK_TYPE_MIN		0x10
+#define DA906X_ALARM_MONTH_MASK			0x0F
+
+/* DA906X_REG_ALARM_Y (addr=0x4A) */
+#define DA906X_TICK_ON				0x80
+#define DA906X_ALARM_ON				0x40
+#define DA906X_ALARM_YEAR_MASK			0x3F
+
+/* DA906X_REG_WAIT (addr=0x97)*/
+#define	DA906X_REG_WAIT_TIME_SHIFT		0
+#define	DA906X_REG_WAIT_TIME_MASK		0xF
+#define	DA906X_WAIT_TIME_0_US			0x0
+#define	DA906X_WAIT_TIME_512_US			0x1
+#define	DA906X_WAIT_TIME_1_MS			0x2
+#define	DA906X_WAIT_TIME_2_MS			0x3
+#define	DA906X_WAIT_TIME_4_1_MS			0x4
+#define	DA906X_WAIT_TIME_8_2_MS			0x5
+#define	DA906X_WAIT_TIME_16_4_MS		0x6
+#define	DA906X_WAIT_TIME_32_8_MS		0x7
+#define	DA906X_WAIT_TIME_65_5_MS		0x8
+#define	DA906X_WAIT_TIME_128_MS			0x9
+#define	DA906X_WAIT_TIME_256_MS			0xA
+#define	DA906X_WAIT_TIME_512_MS			0xB
+#define	DA906X_WAIT_TIME_1_S			0xC
+#define	DA906X_WAIT_TIME_2_1_S			0xD
+
+/* DA906X_REG_EN_32K  (addr=0x98)*/
+#define	DA906X_STABILIZ_TIME_SHIFT		0
+#define	DA906X_STABILIZ_TIME_MASK		0x7
+#define	DA906X_CRYSTAL				0x08
+#define	DA906X_DELAY_MODE			0x10
+#define	DA906X_OUT_CLOCK			0x20
+#define	DA906X_RTC_CLOCK			0x40
+#define	DA906X_OUT_32K_EN			0x80
+
+/* DA906X_REG_CHIP_VARIANT */
+#define	DA906X_CHIP_VARIANT_SHIFT		4
+
+/* DA906X_REG_BUCK_ILIM_A (addr=0x9A) */
+#define DA906X_BIO_ILIM_SHIFT			0
+#define DA906X_BIO_ILIM_MASK			0x0F
+#define DA906X_BMEM_ILIM_SHIFT			4
+#define DA906X_BMEM_ILIM_MASK			0x0F
+
+/* DA906X_REG_BUCK_ILIM_B (addr=0x9B) */
+#define DA906X_BPRO_ILIM_SHIFT			0
+#define DA906X_BPRO_ILIM_MASK			0x0F
+#define DA906X_BPERI_ILIM_SHIFT			4
+#define DA906X_BPERI_ILIM_MASK			0x0F
+
+/* DA906X_REG_BUCK_ILIM_C (addr=0x9C) */
+#define DA906X_BCORE1_ILIM_SHIFT		0
+#define DA906X_BCORE1_ILIM_MASK			0x0F
+#define DA906X_BCORE2_ILIM_SHIFT		4
+#define DA906X_BCORE2_ILIM_MASK			0x0F
+
+/* DA906X_REG_Bxxxx_CFG common bits (addr=0x9D-0xA2) */
+#define DA906X_BUCK_FB_MASK			0x07
+#define DA906X_BUCK_PD_DIS_SHIFT		5
+#define DA906X_BUCK_MODE_SHIFT			6
+#define DA906X_BUCK_MODE_MASK			0xC0
+#define		DA906X_BUCK_MODE_MANUAL		0x00
+#define		DA906X_BUCK_MODE_SLEEP		0x40
+#define		DA906X_BUCK_MODE_SYNC		0x80
+#define		DA906X_BUCK_MODE_AUTO		0xC0
+
+/* DA906X_REG_BPRO_CFG (addr=0x9F) */
+#define	DA906X_BPRO_VTTR_EN			0x08
+#define	DA906X_BPRO_VTT_EN			0x10
+
+/* DA906X_REG_VBxxxx_A/B (addr=0xA3-0xA8, 0xB4-0xB9) */
+#define DA906X_VBUCK_SHIFT			0
+#define DA906X_VBUCK_MASK			0x7F
+#define DA906X_VBUCK_BIAS			0
+#define DA906X_BUCK_SL				0x80
+
+/* DA906X_REG_VLDOx_A/B (addr=0xA9-0x3, 0xBA-0xC4) */
+#define DA906X_LDO_SL				0x80
+
+/* DA906X_REG_VLDO1_A/B (addr=0xA9, 0xBA) */
+#define DA906X_VLDO1_MASK			0x3F
+#define DA906X_VLDO1_SHIFT			0
+#define DA906X_VLDO1_BIAS			0
+
+/* DA906X_REG_VLDO2_A/B (addr=0xAA, 0xBB) */
+#define DA906X_VLDO2_MASK			0x3F
+#define DA906X_VLDO2_SHIFT			0
+#define DA906X_VLDO2_BIAS			0
+
+/* DA906X_REG_VLDO3_A/B (addr=0xAB, 0xBC) */
+#define DA906X_VLDO3_MASK			0x7F
+#define DA906X_VLDO3_SHIFT			0
+#define DA906X_VLDO3_BIAS			0
+
+/* DA906X_REG_VLDO4_A/B (addr=0xAC, 0xBD) */
+#define DA906X_VLDO4_MASK			0x7F
+#define DA906X_VLDO4_SHIFT			0
+#define DA906X_VLDO4_BIAS			0
+
+/* DA906X_REG_VLDO5_A/B (addr=0xAD, 0xBE) */
+#define DA906X_VLDO5_MASK			0x3F
+#define DA906X_VLDO5_SHIFT			0
+#define DA906X_VLDO5_BIAS			2
+
+/* DA906X_REG_VLDO6_A/B (addr=0xAE, 0xBF) */
+#define DA906X_VLDO6_MASK			0x3F
+#define DA906X_VLDO6_SHIFT			0
+#define DA906X_VLDO6_BIAS			2
+
+/* DA906X_REG_VLDO7_A/B (addr=0xAF, 0xC0) */
+#define DA906X_VLDO7_MASK			0x3F
+#define DA906X_VLDO7_SHIFT			0
+#define DA906X_VLDO7_BIAS			2
+
+/* DA906X_REG_VLDO8_A/B (addr=0xB0, 0xC1) */
+#define DA906X_VLDO8_MASK			0x3F
+#define DA906X_VLDO8_SHIFT			0
+#define DA906X_VLDO8_BIAS			2
+
+/* DA906X_REG_VLDO9_A/B (addr=0xB1, 0xC2) */
+#define DA906X_VLDO9_MASK			0x3F
+#define DA906X_VLDO9_SHIFT			0
+#define DA906X_VLDO9_BIAS			3
+
+/* DA906X_REG_VLDO10_A/B (addr=0xB2, 0xC3) */
+#define DA906X_VLDO10_MASK			0x3F
+#define DA906X_VLDO10_SHIFT			0
+#define DA906X_VLDO10_BIAS			2
+
+/* DA906X_REG_VLDO11_A/B (addr=0xB3, 0xC4) */
+#define DA906X_VLDO11_MASK			0x3F
+#define DA906X_VLDO11_SHIFT			0
+#define DA906X_VLDO11_BIAS			2
+
+/* DA906X_REG_GPO11_LED (addr=0xC6) */
+/* DA906X_REG_GPO14_LED (addr=0xC7) */
+/* DA906X_REG_GPO15_LED (addr=0xC8) */
+#define DA906X_GPIO_DIM				0x80
+#define DA906X_GPIO_PWM_SHIFT			0
+#define DA906X_GPIO_PWM_MASK			0x7F
+
+/* DA906X_REG_CONFIG_H (addr=0x10D) */
+#define DA906X_PWM_CLK_MASK			0x01
+#define		DA906X_PWM_CLK_PWM2MHZ		0x00
+#define		DA906X_PWM_CLK_PWM1MHZ		0x01
+#define DA906X_LDO8_MODE_MASK			0x02
+#define		DA906X_LDO8_MODE_LDO		0
+#define		DA906X_LDO8_MODE_VIBR		0x02
+#define DA906X_MERGE_SENSE_MASK			0x04
+#define 	DA906X_MERGE_SENSE_GP_FB2	0x00
+#define 	DA906X_MERGE_SENSE_GPIO4	0x04
+#define DA906X_BCORE_MERGE			0x08
+#define DA906X_BPRO_OD				0x10
+#define DA906X_BCORE2_OD			0x20
+#define DA906X_BCORE1_OD			0x40
+#define DA906X_BUCK_MERGE			0x80
+
+/* DA906X_REG_CONFIG_I (addr=0x10E) */
+#define DA906X_NONKEY_PIN_MASK			0x03
+#define		DA906X_NONKEY_PIN_PORT		0x00
+#define		DA906X_NONKEY_PIN_SWDOWN	0x01
+#define		DA906X_NONKEY_PIN_AUTODOWN	0x02
+#define		DA906X_NONKEY_PIN_AUTOFLPRT	0x03
+
+/* DA906X_REG_MON_REG_5 (addr=0x116) */
+#define DA906X_MON_A8_IDX_SHIFT			0
+#define DA906X_MON_A8_IDX_MASK			0x07
+#define		DA9063_MON_A8_IDX_NONE		0x00
+#define		DA9063_MON_A8_IDX_BCORE1	0x01
+#define		DA9063_MON_A8_IDX_BCORE2	0x02
+#define		DA9063_MON_A8_IDX_BPRO		0x03
+#define		DA9063_MON_A8_IDX_LDO3		0x04
+#define		DA9063_MON_A8_IDX_LDO4		0x05
+#define		DA9063_MON_A8_IDX_LDO11		0x06
+#define DA906X_MON_A9_IDX_SHIFT			4
+#define DA906X_MON_A9_IDX_MASK			0x70
+#define		DA9063_MON_A9_IDX_NONE		0x00
+#define		DA9063_MON_A9_IDX_BIO		0x01
+#define		DA9063_MON_A9_IDX_BMEM		0x02
+#define		DA9063_MON_A9_IDX_BPERI		0x03
+#define		DA9063_MON_A9_IDX_LDO1		0x04
+#define		DA9063_MON_A9_IDX_LDO2		0x05
+#define		DA9063_MON_A9_IDX_LDO5		0x06
+
+/* DA906X_REG_MON_REG_6 (addr=0x117) */
+#define DA906X_MON_A10_IDX_SHIFT		0
+#define DA906X_MON_A10_IDX_MASK			0x07
+#define		DA9063_MON_A10_IDX_NONE		0x00
+#define		DA9063_MON_A10_IDX_LDO6		0x01
+#define		DA9063_MON_A10_IDX_LDO7		0x02
+#define		DA9063_MON_A10_IDX_LDO8		0x03
+#define		DA9063_MON_A10_IDX_LDO9		0x04
+#define		DA9063_MON_A10_IDX_LDO10	0x05
+
+#endif /* _DA906X_REG_H */
+
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
  2012-08-24  8:32   ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-24  8:32     ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24  8:32 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie, Bryan Wu, Liam Girdwood

The driver adds support for the following DA9063 PMIC regulators:
 - 11x LDOs (named LDO1 - LDO11),
 - 6x buck converters (BCORE1, BCORE2, BPRO, BMEM, BIO, BPERI),
 - 1x power switch to switch on/off 32 KHz oscilator output (32K_OUT).

Regulators provide following operations:
 - REGULATOR_CHANGE_STATUS for all regulators,
 - REGULATOR_CHANGE_VOLTAGE for LDOs and buck converters,
 - REGULATOR_CHANGE_MODE for LDOs and buck converters, where:
     - LDOs allow REGULATOR_MODE_NORMAL and REGULATOR_MODE_STANDBY,
     - buck converters allow REGULATOR_MODE_FAST, REGULATOR_MODE_NORMAL
       and REGULATOR_MODE_STANDBY,
 - REGULATOR_CHANGE_CURRENT for buck converters (current limits).

The driver generates REGULATOR_EVENT_OVER_CURRENT for LDO3, LDO4, LDO7, LDO8
and LDO11.

Internally, PMIC provides two voltage configurations for normal and suspend
system state for each regulator. The driver switches between those on
suspend/wake-up to provide quick and fluent output voltage change.

This driver requires MFD core driver for operation.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/regulator/Kconfig            |    6 +
 drivers/regulator/Makefile           |    1 +
 drivers/regulator/da906x-regulator.c | 1018 ++++++++++++++++++++++++++++++++++
 3 files changed, 1025 insertions(+), 0 deletions(-)
 create mode 100644 drivers/regulator/da906x-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 4e932cc..b57b6c6 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -110,6 +110,12 @@ config REGULATOR_DA9052
 	  This driver supports the voltage regulators of DA9052-BC and
 	  DA9053-AA/Bx PMIC.
 
+config REGULATOR_DA906X
+	bool "Dialog DA906X Regulator family chip"
+	depends on MFD_DA906X
+	help
+	  Support for Dialog Semiconductor DA906x chip.
+
 config REGULATOR_ANATOP
 	tristate "Freescale i.MX on-chip ANATOP LDO regulators"
 	depends on MFD_ANATOP
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 3342615..46a503a 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o
 obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o
 obj-$(CONFIG_REGULATOR_DA903X)	+= da903x.o
 obj-$(CONFIG_REGULATOR_DA9052)	+= da9052-regulator.o
+obj-$(CONFIG_REGULATOR_DA906X) += da906x-regulator.o
 obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o
 obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o
 obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o
diff --git a/drivers/regulator/da906x-regulator.c b/drivers/regulator/da906x-regulator.c
new file mode 100644
index 0000000..1b68de0
--- /dev/null
+++ b/drivers/regulator/da906x-regulator.c
@@ -0,0 +1,1018 @@
+/*
+ * Regulator driver for DA906x PMIC series
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/init.h>
+#include <linux/err.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+#include <linux/mfd/da906x/registers.h>
+
+
+/* Definition for registering bit fields */
+struct bfield {
+	unsigned short	addr;
+	unsigned char	mask;
+};
+#define BFIELD(_addr, _mask) \
+	{ .addr = _addr, .mask = _mask }
+
+struct field {
+	unsigned short	addr;
+	unsigned char	mask;
+	unsigned char	shift;
+	unsigned char	offset;
+};
+#define FIELD(_addr, _mask, _shift, _offset) \
+	{ .addr = _addr, .mask = _mask, .shift = _shift, .offset = _offset }
+
+/* Regulator capabilities and registers description */
+struct da906x_regulator_info {
+	int			id;
+	char			*name;
+	struct regulator_ops	*ops;
+
+	/* Voltage adjust range */
+	int		min_uV;
+	int		max_uV;
+	unsigned	step_uV;
+	unsigned	n_steps;
+
+	/* Current limiting */
+	unsigned	n_current_limits;
+	const int	*current_limits;
+
+	/* DA906x main register fields */
+	struct bfield	enable;		/* bit used to enable regulator,
+					   it returns actual state when read */
+	struct field	mode;		/* buck mode of operation */
+	struct bfield	suspend;
+	struct bfield	sleep;
+	struct bfield	suspend_sleep;
+	struct field	voltage;
+	struct field	suspend_voltage;
+	struct field	ilimit;
+
+	/* DA906x event detection bit */
+	struct bfield	oc_event;
+};
+
+/* Macro for switch regulator */
+#define DA906X_SWITCH(chip, regl_name) \
+	.id = chip##_ID_##regl_name, \
+	.name = __stringify(chip##_##regl_name), \
+	.ops = &da906x_switch_ops, \
+	.n_steps = 0
+
+/* Macros for LDO */
+#define DA906X_LDO(chip, regl_name, min_mV, step_mV, max_mV) \
+	.id = chip##_ID_##regl_name, \
+	.name = __stringify(chip##_##regl_name), \
+	.ops = &da906x_ldo_ops, \
+	.min_uV = (min_mV) * 1000, \
+	.max_uV = (max_mV) * 1000, \
+	.step_uV = (step_mV) * 1000, \
+	.n_steps = (((max_mV) - (min_mV))/(step_mV) + 1)
+
+#define DA906X_LDO_COMMON_FIELDS(regl_name) \
+	.enable = BFIELD(DA906X_REG_##regl_name##_CONT, DA906X_LDO_EN), \
+	.sleep = BFIELD(DA906X_REG_V##regl_name##_A, DA906X_LDO_SL), \
+	.suspend_sleep = BFIELD(DA906X_REG_V##regl_name##_B, DA906X_LDO_SL), \
+	.voltage = FIELD(DA906X_REG_V##regl_name##_A, \
+			DA906X_V##regl_name##_MASK, \
+			DA906X_V##regl_name##_SHIFT, \
+			DA906X_V##regl_name##_BIAS), \
+	.suspend_voltage = FIELD(DA906X_REG_V##regl_name##_B, \
+			DA906X_V##regl_name##_MASK,\
+			DA906X_V##regl_name##_SHIFT, \
+			DA906X_V##regl_name##_BIAS)
+
+/* Macros for voltage DC/DC converters (BUCKs) */
+#define DA906X_BUCK(chip, regl_name, min_mV, step_mV, max_mV, limits_array) \
+	.id = chip##_ID_##regl_name, \
+	.name = __stringify(chip##_##regl_name), \
+	.ops = &da906x_buck_ops, \
+	.min_uV = (min_mV) * 1000, \
+	.max_uV = (max_mV) * 1000, \
+	.step_uV = (step_mV) * 1000, \
+	.n_steps = ((max_mV) - (min_mV))/(step_mV) + 1, \
+	.current_limits = limits_array, \
+	.n_current_limits = ARRAY_SIZE(limits_array)
+
+#define DA906X_BUCK_COMMON_FIELDS(regl_name) \
+	.enable = BFIELD(DA906X_REG_##regl_name##_CONT, DA906X_BUCK_EN), \
+	.sleep = BFIELD(DA906X_REG_V##regl_name##_A, DA906X_BUCK_SL), \
+	.suspend_sleep = BFIELD(DA906X_REG_V##regl_name##_B, DA906X_BUCK_SL), \
+	.voltage = FIELD(DA906X_REG_V##regl_name##_A, \
+			 DA906X_VBUCK_MASK, \
+			 DA906X_VBUCK_SHIFT, \
+			 DA906X_VBUCK_BIAS), \
+	.suspend_voltage = FIELD(DA906X_REG_V##regl_name##_B, \
+				 DA906X_VBUCK_MASK,\
+				 DA906X_VBUCK_SHIFT, \
+				 DA906X_VBUCK_BIAS), \
+	.mode = FIELD(DA906X_REG_##regl_name##_CFG, DA906X_BUCK_MODE_MASK, \
+		      DA906X_BUCK_MODE_SHIFT, 0)
+
+/* Defines asignment of regulators info table to chip model */
+struct da906x_dev_model {
+	const struct da906x_regulator_info	*regulator_info;
+	unsigned				n_regulators;
+	unsigned				dev_model;
+};
+
+/* Single regulator settings */
+struct da906x_regulator {
+	struct regulator_desc			desc;
+	struct regulator_dev			*rdev;
+	struct da906x				*hw;
+	const struct da906x_regulator_info	*info;
+
+	unsigned				mode;
+	unsigned				suspend_mode;
+};
+
+/* Encapsulates all information for the regulators driver */
+struct da906x_regulators {
+	int					irq_ldo_lim;
+	int					irq_uvov;
+
+	unsigned				n_regulators;
+	/* Array size to be defined during init. Keep at end. */
+	struct da906x_regulator			regulator[0];
+};
+
+/* System states for da906x_update_mode_internal()
+   and for da906x_get_mode_internal() */
+enum {
+	SYS_STATE_NORMAL,
+	SYS_STATE_SUSPEND,
+	SYS_STATE_CURRENT
+};
+
+/* BUCK modes for DA906x */
+enum {
+	BUCK_MODE_MANUAL,	/* 0 */
+	BUCK_MODE_SLEEP,	/* 1 */
+	BUCK_MODE_SYNC,		/* 2 */
+	BUCK_MODE_AUTO		/* 3 */
+};
+
+/* Regulator operations */
+static int da906x_set_voltage(struct regulator_dev *rdev, int min_uV,
+			      int max_uV, unsigned *selector);
+static int da906x_get_voltage_sel(struct regulator_dev *rdev);
+static int da906x_set_current_limit(struct regulator_dev *rdev,
+				    int min_uA, int max_uA);
+static int da906x_get_current_limit(struct regulator_dev *rdev);
+static int da906x_enable(struct regulator_dev *rdev);
+static int da906x_set_mode(struct regulator_dev *rdev, unsigned int mode);
+static unsigned da906x_get_mode(struct regulator_dev *rdev);
+static int da906x_get_status(struct regulator_dev *rdev);
+static int da906x_set_suspend_voltage(struct regulator_dev *rdev, int uV);
+static int da906x_suspend_enable(struct regulator_dev *rdev);
+static int da906x_set_suspend_mode(struct regulator_dev *rdev, unsigned mode);
+
+static struct regulator_ops da906x_switch_ops = {
+	.enable			= da906x_enable,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.set_suspend_enable	= da906x_enable,
+	.set_suspend_disable	= regulator_disable_regmap,
+};
+
+static struct regulator_ops da906x_ldo_ops = {
+	.enable			= da906x_enable,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.set_voltage		= da906x_set_voltage,
+	.get_voltage_sel	= da906x_get_voltage_sel,
+	.list_voltage		= regulator_list_voltage_linear,
+	.set_mode		= da906x_set_mode,
+	.get_mode		= da906x_get_mode,
+	.get_status		= da906x_get_status,
+	.set_suspend_voltage	= da906x_set_suspend_voltage,
+	.set_suspend_enable	= da906x_suspend_enable,
+	.set_suspend_disable	= regulator_disable_regmap,
+	.set_suspend_mode	= da906x_set_suspend_mode,
+};
+
+static struct regulator_ops da906x_buck_ops = {
+	.enable			= da906x_enable,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.set_voltage		= da906x_set_voltage,
+	.get_voltage_sel	= da906x_get_voltage_sel,
+	.list_voltage		= regulator_list_voltage_linear,
+	.set_current_limit	= da906x_set_current_limit,
+	.get_current_limit	= da906x_get_current_limit,
+	.set_mode		= da906x_set_mode,
+	.get_mode		= da906x_get_mode,
+	.get_status		= da906x_get_status,
+	.set_suspend_voltage	= da906x_set_suspend_voltage,
+	.set_suspend_enable	= da906x_suspend_enable,
+	.set_suspend_disable	= regulator_disable_regmap,
+	.set_suspend_mode	= da906x_set_suspend_mode,
+};
+
+/* Current limits array (in uA) for BCORE1, BCORE2, BPRO.
+   Entry indexes corresponds to register values. */
+static const int da9063_buck_a_limits[] = {
+	 500000,  600000,  700000,  800000,  900000, 1000000, 1100000, 1200000,
+	1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000
+};
+
+/* Current limits array (in uA) for BMEM, BIO, BPERI.
+   Entry indexes corresponds to register values. */
+static const int da9063_buck_b_limits[] = {
+	1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,
+	2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000
+};
+
+/* Current limits array (in uA) for merged BCORE1 and BCORE2.
+   Entry indexes corresponds to register values. */
+static const int da9063_bcores_merged_limits[] = {
+	1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000,
+	2600000, 2800000, 3000000, 3200000, 3400000, 3600000, 3800000, 4000000
+};
+
+/* Current limits array (in uA) for merged BMEM and BIO.
+   Entry indexes corresponds to register values. */
+static const int da9063_bmem_bio_merged_limits[] = {
+	3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000,
+	4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000
+};
+
+/* Info of regulators for DA9063 */
+static const struct da906x_regulator_info da9063_regulator_info[] = {
+	{
+		DA906X_BUCK(DA9063, BCORE1, 300, 10, 1570,
+			    da9063_buck_a_limits),
+		DA906X_BUCK_COMMON_FIELDS(BCORE1),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBCORE1_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_C, DA906X_BCORE1_ILIM_MASK,
+				DA906X_BCORE1_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BCORE2, 300, 10, 1570,
+			    da9063_buck_a_limits),
+		DA906X_BUCK_COMMON_FIELDS(BCORE2),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBCORE2_SEL),
+
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_C,
+				DA906X_BCORE2_ILIM_MASK,
+				DA906X_BCORE2_ILIM_SHIFT,
+				0),
+	},
+	{
+		DA906X_BUCK(DA9063, BPRO, 530, 10, 1800,
+			    da9063_buck_a_limits),
+		DA906X_BUCK_COMMON_FIELDS(BPRO),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBPRO_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_B, DA906X_BPRO_ILIM_MASK,
+				DA906X_BPRO_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BMEM, 800, 20, 3340,
+			    da9063_buck_b_limits),
+		DA906X_BUCK_COMMON_FIELDS(BMEM),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBMEM_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_A, DA906X_BMEM_ILIM_MASK,
+				DA906X_BMEM_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BIO, 800, 20, 3340,
+			    da9063_buck_b_limits),
+		DA906X_BUCK_COMMON_FIELDS(BIO),
+		.suspend = BFIELD(DA906X_REG_DVC_2, DA906X_VBIO_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_A, DA906X_BIO_ILIM_MASK,
+				DA906X_BIO_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BPERI, 800, 20, 3340,
+			    da9063_buck_b_limits),
+		DA906X_BUCK_COMMON_FIELDS(BPERI),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBPERI_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_B, DA906X_BPERI_ILIM_MASK,
+				DA906X_BPERI_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BCORES_MERGED, 300, 10, 1570,
+			    da9063_bcores_merged_limits),
+		/* BCORES_MERGED uses the same register fields as BCORE1 */
+		DA906X_BUCK_COMMON_FIELDS(BCORE1),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBCORE1_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_C, DA906X_BCORE1_ILIM_MASK,
+				DA906X_BCORE1_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BMEM_BIO_MERGED, 800, 20, 3340,
+			    da9063_bmem_bio_merged_limits),
+		/* BMEM_BIO_MERGED uses the same register fields as BMEM */
+		DA906X_BUCK_COMMON_FIELDS(BMEM),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBMEM_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_A, DA906X_BMEM_ILIM_MASK,
+				DA906X_BMEM_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_LDO(DA9063, LDO1, 600, 20, 1860),
+		DA906X_LDO_COMMON_FIELDS(LDO1),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VLDO1_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO2, 600, 20, 1860),
+		DA906X_LDO_COMMON_FIELDS(LDO2),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VLDO2_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO3, 900, 20, 3440),
+		DA906X_LDO_COMMON_FIELDS(LDO3),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VLDO3_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO3_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO4, 900, 20, 3440),
+		DA906X_LDO_COMMON_FIELDS(LDO4),
+		.suspend = BFIELD(DA906X_REG_DVC_2, DA906X_VLDO4_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO4_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO5, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO5),
+		.suspend = BFIELD(DA906X_REG_LDO5_CONT, DA906X_VLDO5_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO6, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO6),
+		.suspend = BFIELD(DA906X_REG_LDO6_CONT, DA906X_VLDO6_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO7, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO7),
+		.suspend = BFIELD(DA906X_REG_LDO7_CONT, DA906X_VLDO7_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO7_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO8, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO8),
+		.suspend = BFIELD(DA906X_REG_LDO8_CONT, DA906X_VLDO8_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO8_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO9, 950, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO9),
+		.suspend = BFIELD(DA906X_REG_LDO9_CONT, DA906X_VLDO9_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO10, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO10),
+		.suspend = BFIELD(DA906X_REG_LDO10_CONT, DA906X_VLDO10_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO11, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO11),
+		.suspend = BFIELD(DA906X_REG_LDO11_CONT, DA906X_VLDO11_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO11_LIM),
+	},
+	{
+		DA906X_SWITCH(DA9063, 32K_OUT),
+		.enable = BFIELD(DA906X_REG_EN_32K, DA906X_OUT_32K_EN),
+	},
+};
+
+/* Link chip model with regulators info table */
+static struct da906x_dev_model regulators_models[] = {
+	{
+		.regulator_info = da9063_regulator_info,
+		.n_regulators = ARRAY_SIZE(da9063_regulator_info),
+		.dev_model = PMIC_DA9063,
+	},
+	{NULL, 0, 0}	/* End of list */
+};
+
+
+/*
+ * Regulator internal functions
+ */
+static int da906x_update_mode_internal(struct da906x_regulator *regl,
+				       int sys_state)
+{
+	const struct da906x_regulator_info *rinfo = regl->info;
+	unsigned val;
+	unsigned mode;
+	int ret;
+
+	if (sys_state == SYS_STATE_SUSPEND)
+		/* Get mode for regulator in suspend state */
+		mode = regl->suspend_mode;
+	else
+		/* Get mode for regulator in normal operation */
+		mode = regl->mode;
+
+	/* LDOs use sleep flags - one for normal and one for suspend state.
+	   For BUCKs single mode register field is used in normal and
+	   suspend state. */
+	if (rinfo->mode.addr) {
+		/* Set mode for BUCK - 3 modes are supported */
+		switch (mode) {
+		case REGULATOR_MODE_FAST:
+			val = BUCK_MODE_SYNC;
+			break;
+		case REGULATOR_MODE_NORMAL:
+			val = BUCK_MODE_AUTO;
+			break;
+		case REGULATOR_MODE_STANDBY:
+			val = BUCK_MODE_SLEEP;
+			break;
+		default:
+			return -EINVAL;
+		}
+		val = val << rinfo->mode.shift;
+
+		ret = da906x_reg_update(regl->hw, rinfo->mode.addr,
+					rinfo->mode.mask, val);
+	} else {
+		/* Set mode for LDO - 2 modes are supported */
+		switch (mode) {
+		case REGULATOR_MODE_NORMAL:
+			val = 0;
+			break;
+		case REGULATOR_MODE_STANDBY:
+			val = DA906X_LDO_SL;
+			break;
+		default:
+			return -EINVAL;
+		}
+
+		if (sys_state == SYS_STATE_SUSPEND) {
+			if (!rinfo->suspend_sleep.addr)
+				return -EINVAL;
+			ret = da906x_reg_update(regl->hw,
+						rinfo->suspend_sleep.addr,
+						rinfo->suspend_sleep.mask,
+						val);
+		} else {
+			if (!rinfo->sleep.addr)
+				return -EINVAL;
+			ret = da906x_reg_update(regl->hw,
+						rinfo->sleep.addr,
+						rinfo->sleep.mask, val);
+		}
+	}
+
+	return ret;
+}
+
+static unsigned da906x_get_mode_internal(struct da906x_regulator *regl,
+					 int sys_state)
+{
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int val;
+	int addr;
+	int mask;
+	unsigned mode = 0;
+
+	/* Bucks use single mode register field for normal operation
+	   and suspend state. LDOs use sleep flags - one for normal
+	   and one for suspend state. */
+	if (rinfo->mode.addr) {
+		/* For BUCKs, there are 3 modes to map to */
+		val = da906x_reg_read(regl->hw, rinfo->mode.addr);
+		if (val < 0)
+			return val;
+
+		val = (val & rinfo->mode.mask) >> rinfo->mode.shift;
+		switch (val) {
+		default:
+		case BUCK_MODE_MANUAL:
+			mode = REGULATOR_MODE_FAST | REGULATOR_MODE_STANDBY;
+			/* Sleep flag bit decides the mode */
+			break;
+		case BUCK_MODE_SLEEP:
+			return REGULATOR_MODE_STANDBY;
+		case BUCK_MODE_SYNC:
+			return REGULATOR_MODE_FAST;
+		case BUCK_MODE_AUTO:
+			return REGULATOR_MODE_NORMAL;
+		}
+	} else if (rinfo->sleep.addr) {
+		/* For LDOs there are 2 modes to map to */
+		mode = REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
+		/* Sleep flag bit decides the mode */
+	} else {
+		/* No support */
+		return 0;
+	}
+
+	/* If sys_state == SYS_STATE_CURRENT, current regulator state
+	   is detected. */
+	if (sys_state == SYS_STATE_CURRENT && rinfo->suspend.addr) {
+		val = da906x_reg_read(regl->hw,
+					  rinfo->suspend.addr);
+		if (val < 0)
+			return val;
+
+		if (val & rinfo->suspend.mask)
+			sys_state = SYS_STATE_SUSPEND;
+		else
+			sys_state = SYS_STATE_NORMAL;
+	}
+
+	/* Read regulator mode from proper register,
+	   depending on selected system state */
+	if (sys_state == SYS_STATE_SUSPEND && rinfo->suspend_sleep.addr) {
+		addr = rinfo->suspend_sleep.addr;
+		mask = rinfo->suspend_sleep.mask;
+	} else {
+		addr = rinfo->sleep.addr;
+		mask = rinfo->sleep.mask;
+	}
+
+	val = da906x_reg_read(regl->hw, addr);
+	if (val < 0)
+		return val;
+
+	if (val & mask)
+		mode &= REGULATOR_MODE_STANDBY;
+	else
+		mode &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST;
+
+	return mode;
+}
+
+static int da906x_set_voltage(struct regulator_dev *rdev,
+				int min_uV, int max_uV, unsigned *selector)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct field *fvol = &regl->info->voltage;
+	int ret;
+	unsigned val;
+
+	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
+	if (val < 0)
+		return -EINVAL;
+
+	val = (val + fvol->offset) << fvol->shift;
+	ret = da906x_reg_update(regl->hw, fvol->addr, fvol->mask, val);
+	if (ret >= 0)
+		*selector = val;
+
+	return ret;
+}
+
+static int da906x_get_voltage_sel(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int sel;
+
+	sel = da906x_reg_read(regl->hw, rinfo->voltage.addr);
+	if (sel < 0)
+		return sel;
+
+	sel = (sel & rinfo->voltage.mask) >> rinfo->voltage.shift;
+	sel -= rinfo->voltage.offset;
+	if (sel < 0)
+		sel = 0;
+	if (sel >= rinfo->n_steps)
+		sel = rinfo->n_steps - 1;
+
+	return sel;
+}
+
+static int da906x_set_current_limit(struct regulator_dev *rdev,
+							int min_uA, int max_uA)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int val = INT_MAX;
+	unsigned sel = 0;
+	int n;
+	int tval;
+
+	if (!rinfo->current_limits)
+		return -EINVAL;
+
+	for (n = 0; n < rinfo->n_current_limits; n++) {
+		tval = rinfo->current_limits[n];
+		if (tval >= min_uA && tval <= max_uA && val > tval) {
+			val = tval;
+			sel = n;
+		}
+	}
+	if (val == INT_MAX)
+		return -EINVAL;
+
+	sel = (sel + rinfo->ilimit.offset) << rinfo->ilimit.shift;
+	return da906x_reg_update(regl->hw, rinfo->ilimit.addr,
+						rinfo->ilimit.mask, sel);
+}
+
+static int da906x_get_current_limit(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int sel;
+
+	sel = da906x_reg_read(regl->hw, rinfo->ilimit.addr);
+	if (sel < 0)
+		return sel;
+
+	sel = (sel & rinfo->ilimit.mask) >> rinfo->ilimit.shift;
+	sel -= rinfo->ilimit.offset;
+	if (sel < 0)
+		sel = 0;
+	if (sel >= rinfo->n_current_limits)
+		sel = rinfo->n_current_limits - 1;
+
+	return rinfo->current_limits[sel];
+}
+
+static int da906x_enable(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	int ret;
+
+	if (regl->info->suspend.mask) {
+		/* Make sure to exit from suspend mode on enable */
+		ret = da906x_reg_clear_bits(regl->hw, regl->info->suspend.addr,
+					    regl->info->suspend.mask);
+		if (ret < 0)
+			return ret;
+
+		/* BUCKs need mode update after wake-up from suspend state. */
+		ret = da906x_update_mode_internal(regl, SYS_STATE_NORMAL);
+		if (ret < 0)
+			return ret;
+	}
+
+	return regulator_enable_regmap(rdev);
+}
+
+static int da906x_set_mode(struct regulator_dev *rdev, unsigned mode)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	unsigned orig_mode = regl->mode;
+	int ret;
+
+	regl->mode = mode;
+	ret = da906x_update_mode_internal(regl, SYS_STATE_NORMAL);
+	if (ret)
+		regl->mode = orig_mode;
+
+	return ret;
+}
+
+static unsigned da906x_get_mode(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+
+	return da906x_get_mode_internal(regl, SYS_STATE_CURRENT);
+}
+
+static int da906x_get_status(struct regulator_dev *rdev)
+{
+	int ret = regulator_is_enabled_regmap(rdev);
+
+	if (ret == 0) {
+		ret = REGULATOR_STATUS_OFF;
+	} else if (ret > 0) {
+		ret = da906x_get_mode(rdev);
+		if (ret > 0)
+			ret = regulator_mode_to_status(ret);
+		else if (ret == 0)
+			ret = -EIO;
+	}
+
+	return ret;
+}
+
+static int da906x_set_suspend_voltage(struct regulator_dev *rdev, int uV)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	const struct field *fsusvol = &rinfo->suspend_voltage;
+	int val;
+	int ret;
+
+	val = regulator_map_voltage_linear(rdev, uV, uV);
+	if (val < 0)
+		return -EINVAL;
+
+	val = (val + fsusvol->offset) << fsusvol->shift;
+	ret = da906x_reg_update(regl->hw, fsusvol->addr, fsusvol->mask, val);
+
+	return ret;
+}
+
+static int da906x_suspend_enable(struct regulator_dev *rdev)
+{
+	int ret;
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct bfield *bsuspend = &regl->info->suspend;
+
+	ret = da906x_reg_set_bits(regl->hw, bsuspend->addr, bsuspend->mask);
+	return ret;
+}
+
+static int da906x_set_suspend_mode(struct regulator_dev *rdev, unsigned mode)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	int ret;
+
+	regl->suspend_mode = mode;
+	ret = da906x_update_mode_internal(regl, SYS_STATE_SUSPEND);
+	return ret;
+}
+
+/* Regulator event handlers */
+irqreturn_t da906x_ldo_lim_event(int irq, void *data)
+{
+	struct da906x_regulators *regulators = data;
+	struct da906x *hw = regulators->regulator[0].hw;
+	struct da906x_regulator *regl;
+	int bits;
+	int i;
+
+	bits = da906x_reg_read(hw, DA906X_REG_STATUS_D);
+	if (bits < 0)
+		return IRQ_HANDLED;
+
+	for (i = regulators->n_regulators - 1; i >= 0; i--) {
+		regl = &regulators->regulator[i];
+		if (regl->info->oc_event.addr != DA906X_REG_STATUS_D)
+			continue;
+
+		if (regl->info->oc_event.mask & bits)
+			regulator_notifier_call_chain(regl->rdev,
+					REGULATOR_EVENT_OVER_CURRENT, NULL);
+	}
+
+	return IRQ_HANDLED;
+}
+
+/*
+ * Probing and Initialisation functions
+ */
+static __devinit const struct da906x_regulator_info *
+da906x_get_regl_info(const struct da906x *da906x,
+		     const struct da906x_dev_model *model, int id)
+{
+	int m;
+
+	for (m = model->n_regulators - 1;
+	     model->regulator_info[m].id != id; m--) {
+		if (m <= 0)
+			return NULL;
+	}
+	return &model->regulator_info[m];
+}
+
+static __devinit int da906x_regulator_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_pdata *da906x_pdata = dev_get_platdata(da906x->dev);
+	struct da906x_regulators_pdata *regl_pdata;
+	struct da906x_regulator_data *rdata;
+	const struct da906x_dev_model *model;
+	struct da906x_regulators *regulators;
+	struct da906x_regulator *regl;
+	struct regulator_config config;
+	bool bcores_merged, bmem_bio_merged;
+	size_t size;
+	int n;
+	int ret;
+
+	if (!da906x_pdata) {
+		dev_err(&pdev->dev, "No platform init data supplied\n");
+		return -ENODEV;
+	}
+	regl_pdata = da906x_pdata->regulators_pdata;
+
+	if (!regl_pdata || regl_pdata->n_regulators == 0) {
+		dev_err(&pdev->dev,
+			"No regulators defined for the platform\n");
+		return -ENODEV;
+	}
+
+	/* Find regulators set for particular device model */
+	for (model = regulators_models; model->regulator_info; model++) {
+		if (model->dev_model == da906x_model(da906x))
+			break;
+	}
+	if (!model->regulator_info) {
+		dev_err(&pdev->dev, "Chip model not recognised (%u)\n",
+			da906x_model(da906x));
+		return -ENODEV;
+	}
+
+	ret = da906x_reg_read(da906x, DA906X_REG_CONFIG_H);
+	if (ret < 0) {
+		dev_err(&pdev->dev,
+			"Error while reading BUCKs configuration\n");
+		return -EIO;
+	}
+	bcores_merged = (ret & DA906X_BCORE_MERGE) ? true : false;
+	bmem_bio_merged = (ret & DA906X_BUCK_MERGE) ? true : false;
+
+	/* Allocate memory required by usable regulators */
+	size = sizeof(struct da906x_regulators) +
+		regl_pdata->n_regulators * sizeof(struct da906x_regulator);
+	regulators = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
+	if (!regulators) {
+		dev_err(&pdev->dev, "No memory for regulators\n");
+		return -ENOMEM;
+	}
+
+	regulators->n_regulators = regl_pdata->n_regulators;
+	platform_set_drvdata(pdev, regulators);
+
+	/* Register all regulators declared in platform information */
+	n = 0;
+	while (n < regulators->n_regulators) {
+		rdata = &regl_pdata->regulator_data[n];
+
+		/* Check regulator ID against merge mode configuration */
+		switch (rdata->id) {
+		case DA9063_ID_BCORE1:
+		case DA9063_ID_BCORE2:
+			if (bcores_merged) {
+				dev_err(&pdev->dev,
+					"Cannot use BCORE1 and BCORE2 separately, when in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		case DA9063_ID_BMEM:
+		case DA9063_ID_BIO:
+			if (bmem_bio_merged) {
+				dev_err(&pdev->dev,
+					"Cannot use BMEM and BIO separately, when in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		case DA9063_ID_BCORES_MERGED:
+			if (!bcores_merged) {
+				dev_err(&pdev->dev,
+					"BCORE1 and BCORE2 are unavailable in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		case DA9063_ID_BMEM_BIO_MERGED:
+			if (!bmem_bio_merged) {
+				dev_err(&pdev->dev,
+					"BMEM and BIO are unavailable in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		}
+
+		/* Initialise regulator structure */
+		regl = &regulators->regulator[n];
+		regl->hw = da906x;
+		regl->info = da906x_get_regl_info(da906x, model, rdata->id);
+		if (!regl->info) {
+			dev_err(&pdev->dev,
+				"Invalid regulator ID in platform data\n");
+			ret = -EINVAL;
+			goto err;
+		}
+		regl->desc.type = REGULATOR_VOLTAGE;
+		regl->desc.owner = THIS_MODULE;
+		regl->desc.name = regl->info->name;
+		regl->desc.id = rdata->id;
+		regl->desc.ops = regl->info->ops;
+		regl->desc.n_voltages = regl->info->n_steps;
+		regl->desc.min_uV = regl->info->min_uV;
+		regl->desc.uV_step = regl->info->step_uV;
+		regl->desc.enable_reg = regl->info->enable.addr +
+					DA906X_MAPPING_BASE;
+		regl->desc.enable_mask = regl->info->enable.mask;
+
+		/* Register regulator */
+		config.dev = &pdev->dev;
+		config.init_data = rdata->initdata;
+		config.driver_data = regl;
+		config.regmap = da906x->regmap;
+		regl->rdev = regulator_register(&regl->desc, &config);
+		if (IS_ERR_OR_NULL(regl->rdev)) {
+			dev_err(&pdev->dev,
+				"Failed to register %s regulator\n",
+				regl->info->name);
+			ret = PTR_ERR(regl->rdev);
+			goto err;
+		}
+		n++;
+
+		/* Get current modes of operation (A/B voltage selection)
+		   for normal and suspend states */
+		ret = da906x_get_mode_internal(regl, SYS_STATE_NORMAL);
+		if (ret < 0) {
+			dev_err(&pdev->dev,
+				"Failed to read %s regulator's mode\n",
+				regl->info->name);
+			goto err;
+		}
+		if (ret == 0)
+			regl->mode = REGULATOR_MODE_NORMAL;
+		else
+			regl->mode = ret;
+
+		ret = da906x_get_mode_internal(regl, SYS_STATE_SUSPEND);
+		if (ret < 0) {
+			dev_err(&pdev->dev,
+				"Failed to read %s regulator's mode\n",
+				regl->info->name);
+			goto err;
+		}
+		if (ret == 0)
+			regl->suspend_mode = REGULATOR_MODE_NORMAL;
+		else
+			regl->mode = ret;
+	}
+
+	/* LDOs overcurrent event support */
+	regulators->irq_ldo_lim = platform_get_irq_byname(pdev, "LDO_LIM");
+	if (regulators->irq_ldo_lim >= 0) {
+		ret = request_threaded_irq(regulators->irq_ldo_lim,
+					   NULL, da906x_ldo_lim_event,
+					   IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+					   "LDO_LIM", regulators);
+		if (ret) {
+			dev_err(&pdev->dev,
+					"Failed to request LDO_LIM IRQ.\n");
+			regulators->irq_ldo_lim = -ENXIO;
+		}
+	}
+
+	return 0;
+
+err:
+	/* Wind back regulators registeration */
+	while (--n >= 0) {
+		regulator_unregister(regulators->regulator[n].rdev);
+	}
+
+	return ret;
+}
+
+static int __devexit da906x_regulator_remove(struct platform_device *pdev)
+{
+	struct da906x_regulators *regulators = platform_get_drvdata(pdev);
+	struct da906x_regulator *regl;
+
+	free_irq(regulators->irq_ldo_lim, regulators);
+	free_irq(regulators->irq_uvov, regulators);
+
+	for (regl = &regulators->regulator[regulators->n_regulators - 1];
+	     regl >= &regulators->regulator[0]; regl--)
+		regulator_unregister(regl->rdev);
+
+	return 0;
+}
+
+static struct platform_driver da906x_regulator_driver = {
+	.driver = {
+		.name = DA906X_DRVNAME_REGULATORS,
+		.owner = THIS_MODULE,
+	},
+	.probe = da906x_regulator_probe,
+	.remove = __devexit_p(da906x_regulator_remove),
+};
+
+static int __init da906x_regulator_init(void)
+{
+	return platform_driver_register(&da906x_regulator_driver);
+}
+subsys_initcall(da906x_regulator_init);
+
+static void __exit da906x_regulator_cleanup(void)
+{
+	platform_driver_unregister(&da906x_regulator_driver);
+}
+module_exit(da906x_regulator_cleanup);
+
+
+/* Module information */
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>");
+MODULE_DESCRIPTION("DA906x regulators driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("paltform:" DA906X_DRVNAME_REGULATORS);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 3/8] rtc: Add RTC driver for DA906x PMIC.
  2012-08-24  8:32     ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-24  8:32       ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24  8:32 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie, Bryan Wu, Liam Girdwood

DA906x RTC driver supports date/time and alarm.

In hardware, PMIC supports alarm setting with a resolution of one minute and
tick event (every second update event). The driver combines it, providing alarm
with one second resolution.

The driver requires MFD core driver for operation.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/rtc/Kconfig      |    7 +
 drivers/rtc/Makefile     |    1 +
 drivers/rtc/rtc-da906x.c |  379 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 387 insertions(+), 0 deletions(-)
 create mode 100644 drivers/rtc/rtc-da906x.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index fabc99a..e6037cd 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -571,6 +571,13 @@ config RTC_DRV_DA9052
 	  Say y here to support the RTC driver for Dialog Semiconductor
 	  DA9052-BC and DA9053-AA/Bx PMICs.
 
+config RTC_DRV_DA906X
+	tristate "Dialog DA906X RTC"
+	depends on MFD_DA906X
+	help
+	  Say y here to support the RTC driver for
+	  Dialog Semiconductor DA906x PMIC.
+
 config RTC_DRV_EFI
 	tristate "EFI RTC"
 	depends on IA64
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 0d5b2b6..d9c1e9f 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_RTC_DRV_BQ4802)	+= rtc-bq4802.o
 obj-$(CONFIG_RTC_DRV_CMOS)	+= rtc-cmos.o
 obj-$(CONFIG_RTC_DRV_COH901331)	+= rtc-coh901331.o
 obj-$(CONFIG_RTC_DRV_DA9052)	+= rtc-da9052.o
+obj-$(CONFIG_RTC_DRV_DA906X)	+= rtc-da906x.o
 obj-$(CONFIG_RTC_DRV_DAVINCI)	+= rtc-davinci.o
 obj-$(CONFIG_RTC_DRV_DM355EVM)	+= rtc-dm355evm.o
 obj-$(CONFIG_RTC_DRV_VRTC)	+= rtc-mrst.o
diff --git a/drivers/rtc/rtc-da906x.c b/drivers/rtc/rtc-da906x.c
new file mode 100644
index 0000000..0b4fecc
--- /dev/null
+++ b/drivers/rtc/rtc-da906x.c
@@ -0,0 +1,379 @@
+/*
+ * Real Time Clock driver for DA906x PMIC family
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/init.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/rtc.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/mfd/da906x/registers.h>
+#include <linux/mfd/da906x/core.h>
+
+#define YEARS_TO_DA906X(year)		((year) - 100)
+#define MONTHS_TO_DA906X(month)		((month) + 1)
+#define YEARS_FROM_DA906X(year)		((year) + 100)
+#define MONTHS_FROM_DA906X(month)	((month) - 1)
+
+#define CLOCK_DATA_LEN	(DA906X_REG_COUNT_Y - DA906X_REG_COUNT_S + 1)
+#define ALARM_DATA_LEN	(DA906X_REG_ALARM_Y - DA906X_REG_ALARM_MI + 1)
+enum {
+	DATA_SEC = 0,
+	DATA_MIN,
+	DATA_HOUR,
+	DATA_DAY,
+	DATA_MONTH,
+	DATA_YEAR,
+};
+
+struct da906x_rtc {
+	struct rtc_device	*rtc_dev;
+	struct da906x		*hw;
+	int			irq_alarm;
+	int			irq_tick;
+
+	/* Config flag */
+	int			tick_wake;
+
+	/* Used to expand alarm precision from minutes up to seconds
+	   using hardware ticks */
+	unsigned int		alarmSecs;
+	unsigned int		alarmTicks;
+};
+
+static void da906x_data_to_tm(u8 *data, struct rtc_time *tm)
+{
+	tm->tm_sec = data[DATA_SEC] & DA906X_COUNT_SEC_MASK;
+	tm->tm_min = data[DATA_MIN] & DA906X_COUNT_MIN_MASK;
+	tm->tm_hour = data[DATA_HOUR] & DA906X_COUNT_HOUR_MASK;
+	tm->tm_mday = data[DATA_DAY] & DA906X_COUNT_DAY_MASK;
+	tm->tm_mon = MONTHS_FROM_DA906X(data[DATA_MONTH] &
+					 DA906X_COUNT_MONTH_MASK);
+	tm->tm_year = YEARS_FROM_DA906X(data[DATA_YEAR] &
+					 DA906X_COUNT_YEAR_MASK);
+}
+
+static void da906x_tm_to_data(struct rtc_time *tm, u8 *data)
+{
+	data[DATA_SEC] &= ~DA906X_COUNT_SEC_MASK;
+	data[DATA_SEC] |= tm->tm_sec & DA906X_COUNT_SEC_MASK;
+	data[DATA_MIN] &= ~DA906X_COUNT_MIN_MASK;
+	data[DATA_MIN] |= tm->tm_min & DA906X_COUNT_MIN_MASK;
+	data[DATA_HOUR] &= ~DA906X_COUNT_HOUR_MASK;
+	data[DATA_HOUR] |= tm->tm_hour & DA906X_COUNT_HOUR_MASK;
+	data[DATA_DAY] &= ~DA906X_COUNT_DAY_MASK;
+	data[DATA_DAY] |= tm->tm_mday & DA906X_COUNT_DAY_MASK;
+	data[DATA_MONTH] &= ~DA906X_COUNT_MONTH_MASK;
+	data[DATA_MONTH] |= MONTHS_TO_DA906X(tm->tm_mon) &
+			    DA906X_COUNT_MONTH_MASK;
+	data[DATA_YEAR] &= ~DA906X_COUNT_YEAR_MASK;
+	data[DATA_YEAR] |= YEARS_TO_DA906X(tm->tm_year) &
+			   DA906X_COUNT_YEAR_MASK;
+}
+
+#define DA906X_ALARM_DELAY	INT_MAX
+static int da906x_rtc_test_delay(struct rtc_time *alarm, struct rtc_time *cur)
+{
+	unsigned long a_time, c_time;
+
+	rtc_tm_to_time(alarm, &a_time);
+	rtc_tm_to_time(cur, &c_time);
+
+	/* Alarm time has already passed */
+	if (a_time < c_time)
+		return -1;
+
+	/* If alarm is set for current minute, return ticks to count down.
+	   If alarm is set for following minutes, return DA906X_ALARM_DELAY
+	   to set alarm first.
+	   But when it is less than 2 seconds for the former to become true,
+	   return ticks, because alarm needs some time to synchronise. */
+	if (a_time - c_time < alarm->tm_sec + 2)
+		return a_time - c_time;
+	else
+		return DA906X_ALARM_DELAY;
+}
+
+static int da906x_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN];
+	int ret;
+
+	ret = da906x_block_read(rtc->hw,
+				DA906X_REG_COUNT_S, CLOCK_DATA_LEN, data);
+	if (ret < 0)
+		return ret;
+
+	/* Check, if RTC logic is initialised */
+	if (!(data[DATA_SEC] & DA906X_RTC_READ))
+		return -EBUSY;
+
+	da906x_data_to_tm(data, tm);
+
+	return rtc_valid_tm(tm);
+}
+
+static int da906x_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN] = { [0 ... (CLOCK_DATA_LEN - 1)] = 0 };
+	int ret;
+
+	da906x_tm_to_data(tm, data);
+
+	ret = da906x_block_write(rtc->hw,
+				 DA906X_REG_COUNT_S, CLOCK_DATA_LEN, data);
+
+	return ret;
+}
+
+static int da906x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN];
+	int ret;
+
+	ret = da906x_block_read(rtc->hw, DA906X_REG_ALARM_MI, ALARM_DATA_LEN,
+				&data[DATA_MIN]);
+	if (ret < 0)
+		return ret;
+
+	da906x_data_to_tm(data, &alrm->time);
+	alrm->time.tm_sec = rtc->alarmSecs;
+	alrm->enabled = !!(data[DATA_YEAR] & DA906X_ALARM_ON);
+
+	/* If there is no ticks left to count down and RTC event is
+	   not processed yet, indicate pending */
+	if (rtc->alarmTicks == 0) {
+		ret = da906x_reg_read(rtc->hw, DA906X_REG_EVENT_A);
+		if (ret < 0)
+			return ret;
+		if (ret & (DA906X_E_ALARM | DA906X_E_TICK))
+			alrm->pending = 1;
+	} else {
+		alrm->pending = 0;
+	}
+
+	return 0;
+}
+
+static int da906x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN] = { [0 ... (CLOCK_DATA_LEN - 1)] = 0 };
+	struct rtc_time cur_tm;
+	int cmp_val;
+	int ret;
+
+	data[DATA_MIN] = DA906X_ALARM_STATUS_ALARM;
+	data[DATA_MONTH] = DA906X_TICK_TYPE_SEC;
+	if (rtc->tick_wake)
+		data[DATA_MONTH] |= DA906X_TICK_WAKE;
+
+	ret = da906x_rtc_read_time(dev, &cur_tm);
+	if (ret < 0)
+		return ret;
+
+	if (alrm->enabled) {
+		cmp_val = da906x_rtc_test_delay(&alrm->time, &cur_tm);
+		if (cmp_val == DA906X_ALARM_DELAY) {
+			/* Set alarm for longer delay */
+			data[DATA_YEAR] |= DA906X_ALARM_ON;
+		} else if (cmp_val > 0) {
+			/* Count ticks for shorter delay */
+			rtc->alarmTicks = cmp_val - 1;
+			data[DATA_YEAR] |= DA906X_TICK_ON;
+		} else if (cmp_val == 0) {
+			/* Just about time - report event */
+			rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF);
+		}
+	}
+
+	da906x_tm_to_data(&alrm->time, data);
+	rtc->alarmSecs = alrm->time.tm_sec;
+
+	return da906x_block_write(rtc->hw, DA906X_REG_ALARM_MI, ALARM_DATA_LEN,
+				 &data[DATA_MIN]);
+}
+
+static int da906x_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	struct rtc_wkalrm alrm;
+	int ret;
+
+	ret = da906x_reg_read(rtc->hw, DATA_YEAR);
+	if (ret < 0)
+		return ret;
+
+	if (enabled) {
+		/* Enable alarm, if it is not enabled already */
+		if (!(ret & (DA906X_ALARM_ON | DA906X_TICK_ON))) {
+			ret = da906x_rtc_read_alarm(dev, &alrm);
+			if (ret < 0)
+				return ret;
+
+			alrm.enabled = 1;
+			ret = da906x_rtc_set_alarm(dev, &alrm);
+		}
+	} else {
+		ret = da906x_reg_clear_bits(rtc->hw, DA906X_REG_ALARM_Y,
+					    DA906X_ALARM_ON);
+	}
+
+	return ret;
+}
+
+/* On alarm interrupt, start to count ticks to enable seconds precision
+   (if alarm seconds != 0). */
+static irqreturn_t da906x_alarm_event(int irq, void *data)
+{
+	struct da906x_rtc *rtc = data;
+
+	if (rtc->alarmSecs) {
+		rtc->alarmTicks = rtc->alarmSecs - 1;
+		da906x_reg_update(rtc->hw, DA906X_REG_ALARM_Y,
+				  DA906X_ALARM_ON | DA906X_TICK_ON,
+				  DA906X_TICK_ON);
+	} else {
+		da906x_reg_clear_bits(rtc->hw, DA906X_REG_ALARM_Y,
+				      DA906X_ALARM_ON);
+		rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF);
+	}
+
+	return IRQ_HANDLED;
+}
+
+/* On tick interrupt, count down seconds left to timeout */
+static irqreturn_t da906x_tick_event(int irq, void *data)
+{
+	struct da906x_rtc *rtc = data;
+
+	if (rtc->alarmTicks-- == 0) {
+		da906x_reg_clear_bits(rtc->hw,
+				      DA906X_REG_ALARM_Y, DA906X_TICK_ON);
+		rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_UF);
+	}
+
+	return IRQ_HANDLED;
+}
+
+static const struct rtc_class_ops da906x_rtc_ops = {
+	.read_time = da906x_rtc_read_time,
+	.set_time = da906x_rtc_set_time,
+	.read_alarm = da906x_rtc_read_alarm,
+	.set_alarm = da906x_rtc_set_alarm,
+	.alarm_irq_enable = da906x_rtc_alarm_irq_enable,
+};
+
+static __devinit int da906x_rtc_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_rtc *rtc;
+	int ret;
+	int alarm_mo;
+
+	/* Enable RTC hardware */
+	ret = da906x_reg_set_bits(da906x, DA906X_REG_CONTROL_E, DA906X_RTC_EN);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to enable RTC.\n");
+		return ret;
+	}
+
+	ret = da906x_reg_set_bits(da906x, DA906X_REG_EN_32K, DA906X_CRYSTAL);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to run 32 KHz OSC.\n");
+		return ret;
+	}
+
+	ret = da906x_reg_read(da906x, DA906X_REG_ALARM_MO);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to read RTC register.\n");
+		return ret;
+	}
+	alarm_mo = ret;
+
+	/* Register RTC device */
+	rtc = devm_kzalloc(&pdev->dev, sizeof *rtc, GFP_KERNEL);
+	if (!rtc)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, rtc);
+
+	rtc->hw = da906x;
+	rtc->rtc_dev = rtc_device_register(DA906X_DRVNAME_RTC, &pdev->dev,
+					   &da906x_rtc_ops, THIS_MODULE);
+	if (IS_ERR(rtc->rtc_dev)) {
+		dev_err(&pdev->dev, "Failed to register RTC device: %ld\n",
+			PTR_ERR(rtc->rtc_dev));
+		return PTR_ERR(rtc->rtc_dev);
+	}
+
+	if (alarm_mo & DA906X_TICK_WAKE)
+		rtc->tick_wake = 1;
+
+	/* Register interrupts. Complain on errors but let device
+	   to be registered at least for date/time. */
+	rtc->irq_alarm = platform_get_irq_byname(pdev, "ALARM");
+	ret = request_threaded_irq(rtc->irq_alarm, NULL, da906x_alarm_event,
+				IRQF_TRIGGER_LOW | IRQF_ONESHOT, "ALARM", rtc);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request ALARM IRQ.\n");
+		rtc->irq_alarm = -ENXIO;
+		return 0;
+	}
+
+	rtc->irq_tick = platform_get_irq_byname(pdev, "TICK");
+	ret = request_threaded_irq(rtc->irq_tick, NULL, da906x_tick_event,
+			IRQF_TRIGGER_RISING | IRQF_ONESHOT, "TICK", rtc);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request TICK IRQ.\n");
+		rtc->irq_tick = -ENXIO;
+	}
+
+	return 0;
+}
+
+static int __devexit da906x_rtc_remove(struct platform_device *pdev)
+{
+	struct da906x_rtc *rtc = platform_get_drvdata(pdev);
+
+	if (rtc->irq_alarm >= 0)
+		free_irq(rtc->irq_alarm, rtc);
+
+	if (rtc->irq_tick >= 0)
+		free_irq(rtc->irq_tick, rtc);
+
+	rtc_device_unregister(rtc->rtc_dev);
+	return 0;
+}
+
+static struct platform_driver da906x_rtc_driver = {
+	.probe		= da906x_rtc_probe,
+	.remove		= __devexit_p(da906x_rtc_remove),
+	.driver		= {
+		.name	= DA906X_DRVNAME_RTC,
+		.owner	= THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_rtc_driver);
+
+/* Module information */
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>");
+MODULE_DESCRIPTION("DA906x RTC driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DA906X_DRVNAME_RTC);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 4/8] hwmon: Add DA906x hardware monitoring support.
  2012-08-24  8:32       ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-24  8:32         ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24  8:32 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie, Bryan Wu, Liam Girdwood

DA906x PMIC provides ADC for voltage and temperature monitoring.

The driver provides results of following ADC channels:
 - in0 - system voltage (2500 - 5500 mV)
 - in1 - universal voltage channel #1 (0 - 2500 mV)
 - in2 - universal voltage channel #2 (0 - 2500 mV)
 - in3 - universal voltage channel #3 (0 - 2500 mV)
 - in4 - backup battery voltage (0 - 5000 mV)
 - temp1 - PMIC internal junction temperature (-88 - 333 Celcius degrees)

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/hwmon/Kconfig        |    6 +
 drivers/hwmon/Makefile       |    1 +
 drivers/hwmon/da906x-hwmon.c |  393 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 400 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/da906x-hwmon.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index b0a2e4c..7abc9a0 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1373,6 +1373,12 @@ config SENSORS_WM8350
 	  This driver can also be built as a module.  If so, the module
 	  will be called wm8350-hwmon.
 
+config SENSORS_DA906X
+	tristate "DA906X HWMON device drivers"
+	depends on MFD_DA906X
+	help
+	  Support for the HWMON DA906X device driver.
+
 config SENSORS_ULTRA45
 	tristate "Sun Ultra45 PIC16F747"
 	depends on SPARC64
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 7aa9811..ffbe151 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_SENSORS_ASC7621)	+= asc7621.o
 obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
 obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
 obj-$(CONFIG_SENSORS_DA9052_ADC)+= da9052-hwmon.o
+obj-$(CONFIG_SENSORS_DA906X)	+= da906x-hwmon.o
 obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
 obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
diff --git a/drivers/hwmon/da906x-hwmon.c b/drivers/hwmon/da906x-hwmon.c
new file mode 100644
index 0000000..8ece931
--- /dev/null
+++ b/drivers/hwmon/da906x-hwmon.c
@@ -0,0 +1,393 @@
+/*
+ * HW Monitor support for Dialog DA906X PMIC series
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>,
+ *         Michal Hajduk <michal.hajduk@diasemi.com>
+ *
+ *  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/err.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/platform_device.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+
+/* ADC resolutions for manual and auto modes */
+#define DA906X_ADC_RES		\
+		(1 << (DA906X_ADC_RES_L_BITS + DA906X_ADC_RES_M_BITS))
+#define DA906X_ADC_MAX		(DA906X_ADC_RES - 1)
+#define	DA906X_ADC_AUTO_RES	(1 << DA906X_ADC_RES_M_BITS)
+#define	DA906X_ADC_AUTO_MAX	(DA906X_ADC_AUTO_RES - 1)
+
+/* Define interpolation table to calculate ADC values  */
+struct i_table {
+	int x0;
+	int a;
+	int b;
+};
+#define ILINE(x1, x2, y1, y2)	{ \
+		.x0 = (x1), \
+		.a = ((y2) - (y1)) * DA906X_ADC_RES / ((x2) - (x1)), \
+		.b = (y1) - ((y2) - (y1)) * (x1) / ((x2) - (x1)), \
+	}
+
+struct channel_info {
+	const char *name;
+	const struct i_table *tbl;
+	int tbl_max;
+	u16 reg_auto_en;
+};
+
+enum da906x_adc {
+	DA906X_VSYS,
+	DA906X_ADCIN1,
+	DA906X_ADCIN2,
+	DA906X_ADCIN3,
+	DA906X_TJUNC,
+	DA906X_VBBAT,
+
+	DA906X_CHAN_NUM
+};
+
+static const struct i_table vsys_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 2500, 5500)
+};
+
+static const struct i_table adcin_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 0, 2500)
+};
+
+static const struct i_table tjunc_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 333, -86)
+};
+
+static const struct i_table vbbat_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 0, 5000)
+};
+
+static const struct channel_info da906x_channels[] = {
+	[DA906X_VSYS]	= { "VSYS",
+			    vsys_tbl, ARRAY_SIZE(vsys_tbl) - 1,
+			    DA906X_REG_VSYS_RES },
+	[DA906X_ADCIN1]	= { "ADCIN1",
+			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
+			    DA906X_REG_ADCIN1_RES },
+	[DA906X_ADCIN2]	= { "ADCIN2",
+			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
+			    DA906X_REG_ADCIN2_RES },
+	[DA906X_ADCIN3]	= { "ADCIN3",
+			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
+			    DA906X_REG_ADCIN3_RES },
+	[DA906X_TJUNC]	= { "TJUNC",
+			    tjunc_tbl,	ARRAY_SIZE(tjunc_tbl) - 1 },
+	[DA906X_VBBAT]	= { "VBBAT",
+			    vbbat_tbl,	ARRAY_SIZE(vbbat_tbl) - 1}
+};
+#define DA906X_ADC_AUTO_MODE_SUPPORT_MASK	(DA906X_ADC_AUTO_VSYS_EN | \
+						 DA906X_ADC_AUTO_AD1_EN | \
+						 DA906X_ADC_AUTO_AD2_EN | \
+						 DA906X_ADC_AUTO_AD3_EN)
+
+struct da906x_hwmon {
+	struct da906x *da906x;
+	struct device *class_dev;
+	struct completion man_adc_rdy;	/* Manual read completion flag */
+	struct mutex hwmon_mutex;	/* Queue concurent manual reads */
+	int irq;
+	u8 adc_auto_en;     /* Bitmask of channels with auto mode enabled */
+	s8 tjunc_offset;    /* Calibration offset for junction temperature */
+};
+
+int da906x_adc_convert(int channel, int x)
+{
+	const struct channel_info *info = &da906x_channels[channel];
+	int i, ret;
+
+	for (i = info->tbl_max; i > 0; i--)
+		if (info->tbl[i].x0 <= x)
+			break;
+
+	ret = info->tbl[i].a * x;
+	if (ret >= 0)
+		ret += DA906X_ADC_RES / 2;
+	else
+		ret -= DA906X_ADC_RES / 2;
+	ret = ret / DA906X_ADC_RES + info->tbl[i].b;
+	return ret;
+}
+
+static int da906x_adc_manual_read(struct da906x_hwmon *hwmon, int channel)
+{
+	int ret;
+	u8 data[2];
+
+	mutex_lock(&hwmon->hwmon_mutex);
+
+	init_completion(&hwmon->man_adc_rdy);
+
+	/* Start measurment on selected channel */
+	data[0] = (channel << DA906X_ADC_MUX_SHIFT) & DA906X_ADC_MUX_MASK;
+	data[0] |= DA906X_ADC_MAN;
+	ret = da906x_reg_update(hwmon->da906x, DA906X_REG_ADC_MAN,
+				DA906X_ADC_MUX_MASK | DA906X_ADC_MAN, data[0]);
+	if (ret < 0)
+		goto out;
+
+	/* Wait for interrupt from ADC */
+	ret = wait_for_completion_timeout(&hwmon->man_adc_rdy,
+					  msecs_to_jiffies(1000));
+	if (ret == 0) {
+		ret = -EBUSY;
+		goto out;
+	}
+
+	/* Get results */
+	ret = da906x_block_read(hwmon->da906x, DA906X_REG_ADC_RES_L, 2, data);
+	if (ret < 0)
+		goto out;
+	ret = (data[0] & DA906X_ADC_RES_L_MASK) >> DA906X_ADC_RES_L_SHIFT;
+	ret |= data[1] << DA906X_ADC_RES_L_BITS;
+out:
+	mutex_unlock(&hwmon->hwmon_mutex);
+	return ret;
+}
+
+static int da906x_adc_auto_read(struct da906x *da906x, int channel)
+{
+	const struct channel_info *info = &da906x_channels[channel];
+
+	return da906x_reg_read(da906x, info->reg_auto_en);
+}
+
+static irqreturn_t da906x_hwmon_irq_handler(int irq, void *irq_data)
+{
+	struct da906x_hwmon *hwmon = irq_data;
+
+	complete(&hwmon->man_adc_rdy);
+
+	return IRQ_HANDLED;
+}
+
+static ssize_t da906x_adc_read(struct device *dev,
+			       struct device_attribute *devattr, char *buf)
+{
+	struct da906x_hwmon *hwmon = dev_get_drvdata(dev);
+	int channel = to_sensor_dev_attr(devattr)->index;
+	int val;
+
+	if (hwmon->adc_auto_en & (1 << channel)) {
+		val = da906x_adc_auto_read(hwmon->da906x, channel);
+		if (val < 0)
+			return val;
+
+		val *= DA906X_ADC_RES / DA906X_ADC_AUTO_RES;
+		val = da906x_adc_convert(channel, val);
+	} else {
+		val = da906x_adc_manual_read(hwmon, channel);
+		if (val < 0)
+			return val;
+
+		if (channel == DA906X_TJUNC)
+			val += hwmon->tjunc_offset;
+		val = da906x_adc_convert(channel, val);
+	}
+
+	return sprintf(buf, "%d\n", val);
+}
+
+static ssize_t da906x_show_name(struct device *dev,
+	struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, DA906X_DRVNAME_HWMON "\n");
+}
+
+static ssize_t da906x_show_label(struct device *dev,
+				 struct device_attribute *devattr, char *buf)
+{
+	const struct channel_info *info;
+
+	info = &da906x_channels[to_sensor_dev_attr(devattr)->index];
+	return sprintf(buf, "%s\n", info->name);
+}
+
+/* Vsys voltage */
+static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_VSYS);
+static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_VSYS);
+
+/* Universal ADC channel #1 */
+static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_ADCIN1);
+static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_ADCIN1);
+
+/* Universal ADC channel #2 */
+static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO,
+			  da906x_adc_read, NULL,
+			  DA906X_ADCIN2);
+static SENSOR_DEVICE_ATTR(in2_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_ADCIN2);
+
+/* Universal ADC channel #3 */
+static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_ADCIN3);
+static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_ADCIN3);
+
+/* Backup battery voltage */
+static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_VBBAT);
+static SENSOR_DEVICE_ATTR(in4_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_VBBAT);
+
+/* Junction temperature */
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_TJUNC);
+
+static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_TJUNC);
+
+/* Device name */
+static DEVICE_ATTR(name, S_IRUGO, da906x_show_name, NULL);
+
+static struct attribute *da906x_attributes[] = {
+	&dev_attr_name.attr,
+	&sensor_dev_attr_in0_input.dev_attr.attr,
+	&sensor_dev_attr_in0_label.dev_attr.attr,
+	&sensor_dev_attr_in1_input.dev_attr.attr,
+	&sensor_dev_attr_in1_label.dev_attr.attr,
+	&sensor_dev_attr_in2_input.dev_attr.attr,
+	&sensor_dev_attr_in2_label.dev_attr.attr,
+	&sensor_dev_attr_in3_input.dev_attr.attr,
+	&sensor_dev_attr_in3_label.dev_attr.attr,
+	&sensor_dev_attr_in4_input.dev_attr.attr,
+	&sensor_dev_attr_in4_label.dev_attr.attr,
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_label.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group da906x_attr_group = {
+	.attrs = da906x_attributes,
+};
+
+static int __devinit da906x_hwmon_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_pdata *da906x_pdata = dev_get_platdata(da906x->dev);
+	struct da906x_hwmon *hwmon;
+	int ret;
+
+	hwmon = devm_kzalloc(&pdev->dev, sizeof(struct da906x_hwmon),
+			     GFP_KERNEL);
+	if (!hwmon)
+		return -ENOMEM;
+
+	mutex_init(&hwmon->hwmon_mutex);
+	init_completion(&hwmon->man_adc_rdy);
+	hwmon->da906x = da906x;
+
+	ret = da906x_reg_read(da906x, DA906X_REG_ADC_CONT);
+	if (ret < 0)
+		return ret;
+	hwmon->adc_auto_en = ret & DA906X_ADC_AUTO_MODE_SUPPORT_MASK;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN0_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_VSYS_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN0_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_VSYS_EN;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN1_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD1_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN1_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD1_EN;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN2_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD2_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN2_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD2_EN;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN3_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD3_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN3_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD3_EN;
+
+	ret = da906x_reg_update(da906x, DA906X_REG_ADC_CONT,
+				DA906X_ADC_AUTO_MODE_SUPPORT_MASK,
+				hwmon->adc_auto_en);
+	if (ret < 0)
+		return ret;
+
+	hwmon->class_dev = hwmon_device_register(&pdev->dev);
+	if (IS_ERR(hwmon->class_dev))
+		return PTR_ERR(hwmon->class_dev);
+
+	hwmon->irq = platform_get_irq_byname(pdev, DA906X_DRVNAME_HWMON);
+	ret = devm_request_threaded_irq(&pdev->dev, hwmon->irq, NULL,
+					da906x_hwmon_irq_handler,
+					IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+					"HWMON", hwmon);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request IRQ.\n");
+		goto err;
+	}
+
+	platform_set_drvdata(pdev, hwmon);
+
+	ret = da906x_reg_read(da906x, DA906X_REG_T_OFFSET);
+	if (ret < 0)
+		dev_warn(&pdev->dev, "Could not read temp1 callibration offset.\n");
+	else
+		hwmon->tjunc_offset = (s8)ret;
+
+	ret = sysfs_create_group(&pdev->dev.kobj, &da906x_attr_group);
+	if (ret)
+		goto err;
+
+	return 0;
+
+err:
+	hwmon_device_unregister(hwmon->class_dev);
+	return ret;
+}
+
+static int __devexit da906x_hwmon_remove(struct platform_device *pdev)
+{
+	struct da906x_hwmon *hwmon = platform_get_drvdata(pdev);
+
+	hwmon_device_unregister(hwmon->class_dev);
+	sysfs_remove_group(&pdev->dev.kobj, &da906x_attr_group);
+
+	return 0;
+}
+
+static struct platform_driver da906x_hwmon_driver = {
+	.probe = da906x_hwmon_probe,
+	.remove = __devexit_p(da906x_hwmon_remove),
+	.driver = {
+		.name = DA906X_DRVNAME_HWMON,
+		.owner = THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_hwmon_driver);
+
+MODULE_DESCRIPTION("DA906X Hardware monitoring");
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>, Michal Hajduk <michal.hajduk@diasemi.com>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("paltform:" DA906X_DRVNAME_HWMON);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 5/8] input: Add support for DA906x PMIC OnKey detection.
  2012-08-24  8:32         ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-24  8:32           ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24  8:32 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie, Bryan Wu, Liam Girdwood

This driver creates input device that reports a key event on an OnKey button
release. The reported key code depends on the time, the button was holded for.
If holding time < 2 seconds - KEY_SLEEP is reported on button release,
otherwise KEY_POWER is reported after 2 seconds.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/input/misc/Kconfig        |    6 ++
 drivers/input/misc/Makefile       |    1 +
 drivers/input/misc/da906x-onkey.c |  139 +++++++++++++++++++++++++++++++++++++
 3 files changed, 146 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/misc/da906x-onkey.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 7c0f1ec..fd8d951 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -486,6 +486,12 @@ config INPUT_DA9052_ONKEY
 	  To compile this driver as a module, choose M here: the
 	  module will be called da9052_onkey.
 
+config INPUT_DA906X_ONKEY
+	tristate "Dialog DA906x OnKey"
+	depends on MFD_DA906X
+	help
+	  Support for Dialog Semiconductor input onkey device.
+
 config INPUT_DM355EVM
 	tristate "TI DaVinci DM355 EVM Keypad and IR Remote"
 	depends on MFD_DM355EVM_MSP
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 83fe6f5..73406ac 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_INPUT_CMA3000)		+= cma3000_d0x.o
 obj-$(CONFIG_INPUT_CMA3000_I2C)		+= cma3000_d0x_i2c.o
 obj-$(CONFIG_INPUT_COBALT_BTNS)		+= cobalt_btns.o
 obj-$(CONFIG_INPUT_DA9052_ONKEY)	+= da9052_onkey.o
+obj-$(CONFIG_INPUT_DA906X_ONKEY)	+= da906x-onkey.o
 obj-$(CONFIG_INPUT_DM355EVM)		+= dm355evm_keys.o
 obj-$(CONFIG_INPUT_GP2A)		+= gp2ap002a00f.o
 obj-$(CONFIG_INPUT_GPIO_TILT_POLLED)	+= gpio_tilt_polled.o
diff --git a/drivers/input/misc/da906x-onkey.c b/drivers/input/misc/da906x-onkey.c
new file mode 100644
index 0000000..477c554
--- /dev/null
+++ b/drivers/input/misc/da906x-onkey.c
@@ -0,0 +1,139 @@
+/*
+ * OnKey device driver for Dialog DA906x PMIC
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author:  <michal.hajduk@diasemi.com>
+ *
+ *  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/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/workqueue.h>
+
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/registers.h>
+
+
+struct da906x_onkey {
+	struct	da906x *da906x;
+	struct	input_dev *input;
+	int irq;
+};
+
+static irqreturn_t da906x_onkey_irq_handler(int irq, void *data)
+{
+	struct da906x_onkey *onkey = data;
+	unsigned int code;
+	int ret;
+
+	ret = da906x_reg_read(onkey->da906x, DA906X_REG_STATUS_A);
+	if ((ret >= 0) && (ret & DA906X_NONKEY)) {
+		dev_notice(&onkey->input->dev, "KEY_POWER pressed.\n");
+		code = KEY_POWER;
+	} else {
+		dev_notice(&onkey->input->dev, "KEY_SLEEP pressed.\n");
+		code = KEY_SLEEP;
+	}
+
+	/* Interrupt raised for key release only,
+	   so report consecutive button press and release. */
+	input_report_key(onkey->input, code, 1);
+	input_report_key(onkey->input, code, 0);
+	input_sync(onkey->input);
+
+	return IRQ_HANDLED;
+}
+
+static int __devinit da906x_onkey_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_onkey *onkey;
+	int ret = 0;
+
+	onkey = devm_kzalloc(&pdev->dev, sizeof(struct da906x_onkey),
+			     GFP_KERNEL);
+	if (!onkey) {
+		dev_err(&pdev->dev, "Failed to allocate memory.\n");
+		return -ENOMEM;
+	}
+
+	onkey->input = input_allocate_device();
+	if (!onkey->input) {
+		dev_err(&pdev->dev, "Failed to allocated inpute device.\n");
+		return -ENOMEM;
+	}
+
+	onkey->irq = platform_get_irq_byname(pdev, DA906X_DRVNAME_ONKEY);
+	onkey->da906x = da906x;
+
+	onkey->input->evbit[0] = BIT_MASK(EV_KEY);
+	onkey->input->name = DA906X_DRVNAME_ONKEY;
+	onkey->input->phys = DA906X_DRVNAME_ONKEY "/input0";
+	onkey->input->dev.parent = &pdev->dev;
+	input_set_capability(onkey->input, EV_KEY, KEY_POWER);
+	input_set_capability(onkey->input, EV_KEY, KEY_SLEEP);
+
+	ret = request_threaded_irq(onkey->irq, NULL, da906x_onkey_irq_handler,
+			IRQF_TRIGGER_LOW | IRQF_ONESHOT, "ONKEY", onkey);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request IRQ.\n");
+		goto err_input;
+	}
+
+	ret = input_register_device(onkey->input);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request IRQ.\n");
+		goto err_irq;
+	}
+
+	platform_set_drvdata(pdev, onkey);
+
+	/* Interrupt reacts on button release */
+	da906x_reg_update(da906x, DA906X_REG_CONFIG_I,
+			  DA906X_NONKEY_PIN_MASK, DA906X_NONKEY_PIN_SWDOWN);
+
+	return 0;
+
+err_irq:
+	free_irq(onkey->da906x->irq_base + onkey->irq , onkey);
+err_input:
+	input_free_device(onkey->input);
+	return ret;
+}
+
+static int __devexit da906x_onkey_remove(struct platform_device *pdev)
+{
+	struct	da906x_onkey *onkey = platform_get_drvdata(pdev);
+
+	free_irq(onkey->irq, onkey);
+	input_unregister_device(onkey->input);
+	return 0;
+}
+
+static struct platform_driver da906x_onkey_driver = {
+	.probe	= da906x_onkey_probe,
+	.remove	= __devexit_p(da906x_onkey_remove),
+	.driver	= {
+		.name	= DA906X_DRVNAME_ONKEY,
+		.owner	= THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_onkey_driver);
+
+MODULE_AUTHOR("Dialog Semiconductor <michal.hajduk@diasemi.com>");
+MODULE_DESCRIPTION("Onkey driver for DA906X");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("paltform:" DA906X_DRVNAME_ONKEY);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [lm-sensors] [RFC PATCH 0/8] DA906x PMIC driver
@ 2012-08-24  8:32 ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24  8:32 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie, Bryan Wu, Liam Girdwood

Greetings,

The following patch set adds new multifunction device providing support for
DA906x PMIC chips.

Please add some comments to the driver, which targets Linux Kernel v3.6.

Thank you,

---
Krystian Garbaciak (8):
  mfd: Add Dialog DA906x core driver.
  regulator: Add Dialog DA906x voltage regulators support.
  rtc: Add RTC driver for DA906x PMIC.
  hwmon: Add DA906x hardware monitoring support.
  input: Add support for DA906x PMIC OnKey detection.
  input: Add support for DA906x vibration motor driver.
  watchdog: Add DA906x PMIC watchdog driver.
  leds: Add DA906x PMIC LED driver.

 drivers/hwmon/Kconfig                 |    6 +
 drivers/hwmon/Makefile                |    1 +
 drivers/hwmon/da906x-hwmon.c          |  393 ++++++++++++
 drivers/input/misc/Kconfig            |   13 +
 drivers/input/misc/Makefile           |    2 +
 drivers/input/misc/da906x-onkey.c     |  139 +++++
 drivers/input/misc/da906x-vibration.c |  153 +++++
 drivers/leds/Kconfig                  |    8 +
 drivers/leds/Makefile                 |    1 +
 drivers/leds/leds-da906x.c            |  438 +++++++++++++
 drivers/mfd/Kconfig                   |   11 +
 drivers/mfd/Makefile                  |    4 +
 drivers/mfd/da906x-core.c             |  228 +++++++
 drivers/mfd/da906x-i2c.c              |  389 ++++++++++++
 drivers/mfd/da906x-irq.c              |  192 ++++++
 drivers/regulator/Kconfig             |    6 +
 drivers/regulator/Makefile            |    1 +
 drivers/regulator/da906x-regulator.c  | 1018 ++++++++++++++++++++++++++++++
 drivers/rtc/Kconfig                   |    7 +
 drivers/rtc/Makefile                  |    1 +
 drivers/rtc/rtc-da906x.c              |  379 ++++++++++++
 drivers/watchdog/Kconfig              |   27 +
 drivers/watchdog/Makefile             |    1 +
 drivers/watchdog/da906x_wdt.c         |  276 +++++++++
 include/linux/mfd/da906x/core.h       |  121 ++++
 include/linux/mfd/da906x/pdata.h      |  114 ++++
 include/linux/mfd/da906x/registers.h  | 1093 +++++++++++++++++++++++++++++++++
 27 files changed, 5022 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/da906x-hwmon.c
 create mode 100644 drivers/input/misc/da906x-onkey.c
 create mode 100644 drivers/input/misc/da906x-vibration.c
 create mode 100644 drivers/leds/leds-da906x.c
 create mode 100644 drivers/mfd/da906x-core.c
 create mode 100644 drivers/mfd/da906x-i2c.c
 create mode 100644 drivers/mfd/da906x-irq.c
 create mode 100644 drivers/regulator/da906x-regulator.c
 create mode 100644 drivers/rtc/rtc-da906x.c
 create mode 100644 drivers/watchdog/da906x_wdt.c
 create mode 100644 include/linux/mfd/da906x/core.h
 create mode 100644 include/linux/mfd/da906x/pdata.h
 create mode 100644 include/linux/mfd/da906x/registers.h


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [lm-sensors] [PATCH 1/8] mfd: Add Dialog DA906x core driver.
@ 2012-08-24  8:32   ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24  8:32 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie, Bryan Wu, Liam Girdwood

This is MFD module providing access to registers and interrupts of DA906x
series PMIC. It is used by other functional modules, registered as MFD cells.
Driver uses regmap with paging to access extended register list. Register map
is divided into two pages, where the second page is used during initialisation.

This module provides support to following functional cells:
 - Regulators
 - RTC
 - HWMON
 - OnKey (power key misc input device)
 - Vibration (force-feedback input device)
 - Watchdog
 - LEDs

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/mfd/Kconfig                  |   11 +
 drivers/mfd/Makefile                 |    4 +
 drivers/mfd/da906x-core.c            |  228 +++++++
 drivers/mfd/da906x-i2c.c             |  389 ++++++++++++
 drivers/mfd/da906x-irq.c             |  192 ++++++
 include/linux/mfd/da906x/core.h      |  121 ++++
 include/linux/mfd/da906x/pdata.h     |  114 ++++
 include/linux/mfd/da906x/registers.h | 1093 ++++++++++++++++++++++++++++++++++
 8 files changed, 2152 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mfd/da906x-core.c
 create mode 100644 drivers/mfd/da906x-i2c.c
 create mode 100644 drivers/mfd/da906x-irq.c
 create mode 100644 include/linux/mfd/da906x/core.h
 create mode 100644 include/linux/mfd/da906x/pdata.h
 create mode 100644 include/linux/mfd/da906x/registers.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index b1a1462..bf2a766 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -441,6 +441,17 @@ config MFD_DA9052_I2C
 	  for accessing the device, additional drivers must be enabled in
 	  order to use the functionality of the device.
 
+config MFD_DA906X
+	bool "Dialog Semiconductor DA906X PMIC Support"
+	depends on I2C=y
+	select MFD_CORE
+	select REGMAP_I2C
+	select REGMAP_IRQ
+	help
+	  Support for the Dialog Semiconductor DA906X PMIC. This includes
+	  I2C driver and core APIs, additional drivers must be enabled in
+	  order to use the functionality of the device.
+
 config PMIC_ADP5520
 	bool "Analog Devices ADP5520/01 MFD PMIC Core Support"
 	depends on I2C=y
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 79dd22d..f5a8432 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -90,8 +90,12 @@ obj-$(CONFIG_PMIC_DA9052)	+= da9052-core.o
 obj-$(CONFIG_MFD_DA9052_SPI)	+= da9052-spi.o
 obj-$(CONFIG_MFD_DA9052_I2C)	+= da9052-i2c.o
 
+da906x-objs			:= da906x-core.o da906x-irq.o da906x-i2c.o
+obj-$(CONFIG_MFD_DA906X)	+= da906x.o
+
 obj-$(CONFIG_MFD_MAX77686)	+= max77686.o max77686-irq.o
 obj-$(CONFIG_MFD_MAX77693)	+= max77693.o max77693-irq.o
+
 max8925-objs			:= max8925-core.o max8925-i2c.o
 obj-$(CONFIG_MFD_MAX8925)	+= max8925.o
 obj-$(CONFIG_MFD_MAX8997)	+= max8997.o max8997-irq.o
diff --git a/drivers/mfd/da906x-core.c b/drivers/mfd/da906x-core.c
new file mode 100644
index 0000000..fb3249f
--- /dev/null
+++ b/drivers/mfd/da906x-core.c
@@ -0,0 +1,228 @@
+/*
+ * da906x-core.c: Device access for Dialog DA906x modules
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>,
+ *         Michal Hajduk <michal.hajduk@diasemi.com>
+ *
+ *  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/init.h>
+#include <linux/slab.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/mutex.h>
+#include <linux/mfd/core.h>
+#include <linux/regmap.h>
+
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+#include <linux/mfd/da906x/registers.h>
+
+#include <linux/proc_fs.h>
+#include <linux/kthread.h>
+#include <linux/uaccess.h>
+
+
+static struct resource da906x_regulators_resources[] = {
+	{
+		.name	= "LDO_LIM",
+		.start	= DA906X_IRQ_LDO_LIM,
+		.end	= DA906X_IRQ_LDO_LIM,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct resource da906x_rtc_resources[] = {
+	{
+		.name	= "ALARM",
+		.start	= DA906X_IRQ_ALARM,
+		.end	= DA906X_IRQ_ALARM,
+		.flags	= IORESOURCE_IRQ,
+	},
+	{
+		.name	= "TICK",
+		.start	= DA906X_IRQ_TICK,
+		.end	= DA906X_IRQ_TICK,
+		.flags	= IORESOURCE_IRQ,
+	}
+};
+
+static struct resource da906x_onkey_resources[] = {
+	{
+		.start	= DA906X_IRQ_ONKEY,
+		.end	= DA906X_IRQ_ONKEY,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct resource da906x_hwmon_resources[] = {
+	{
+		.start	= DA906X_IRQ_ADC_RDY,
+		.end	= DA906X_IRQ_ADC_RDY,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+
+static struct mfd_cell da906x_devs[] = {
+	{
+		.name		= DA906X_DRVNAME_REGULATORS,
+		.num_resources	= ARRAY_SIZE(da906x_regulators_resources),
+		.resources	= da906x_regulators_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_LEDS,
+	},
+	{
+		.name		= DA906X_DRVNAME_WATCHDOG,
+	},
+	{
+		.name		= DA906X_DRVNAME_HWMON,
+		.num_resources	= ARRAY_SIZE(da906x_hwmon_resources),
+		.resources	= da906x_hwmon_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_ONKEY,
+		.num_resources	= ARRAY_SIZE(da906x_onkey_resources),
+		.resources	= da906x_onkey_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_RTC,
+		.num_resources	= ARRAY_SIZE(da906x_rtc_resources),
+		.resources	= da906x_rtc_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_VIBRATION,
+	},
+};
+
+inline unsigned int da906x_to_range_reg(u16 reg)
+{
+	return reg + DA906X_MAPPING_BASE;
+}
+
+int da906x_reg_read(struct da906x *da906x, u16 reg)
+{
+	unsigned int val;
+	int ret;
+
+	ret = regmap_read(da906x->regmap, da906x_to_range_reg(reg), &val);
+	if (ret < 0)
+		return ret;
+
+	return val;
+}
+
+int da906x_reg_write(struct da906x *da906x, u16 reg, u8 val)
+{
+	return regmap_write(da906x->regmap, da906x_to_range_reg(reg), val);
+}
+
+int da906x_block_read(struct da906x *da906x, u16 reg, int bytes, u8 *dst)
+{
+	return regmap_bulk_read(da906x->regmap, da906x_to_range_reg(reg),
+				dst, bytes);
+}
+
+int da906x_block_write(struct da906x *da906x, u16 reg, int bytes, const u8 *src)
+{
+	return regmap_bulk_write(da906x->regmap, da906x_to_range_reg(reg),
+				 src, bytes);
+}
+
+int da906x_reg_update(struct da906x *da906x, u16 reg, u8 mask, u8 val)
+{
+	return regmap_update_bits(da906x->regmap, da906x_to_range_reg(reg),
+				  mask, val);
+}
+
+int da906x_reg_set_bits(struct da906x *da906x, u16 reg, u8 mask)
+{
+	return da906x_reg_update(da906x, reg, mask, mask);
+}
+
+int da906x_reg_clear_bits(struct da906x *da906x, u16 reg, u8 mask)
+{
+	return da906x_reg_update(da906x, reg, mask, 0);
+}
+
+int da906x_device_init(struct da906x *da906x, unsigned int irq)
+{
+	struct da906x_pdata *pdata = da906x->dev->platform_data;
+	int ret = 0;
+	int model;
+	unsigned short revision;
+
+	mutex_init(&da906x->io_mutex);
+
+	if (pdata = NULL) {
+		dev_err(da906x->dev, "Platform data not specified.\n");
+		return -EINVAL;
+	}
+	da906x->flags = pdata->flags;
+	da906x->irq_base = pdata->irq_base;
+	da906x->chip_irq = irq;
+
+	if (pdata->init != NULL) {
+		ret = pdata->init(da906x);
+		if (ret != 0) {
+			dev_err(da906x->dev,
+				"Platform initialization failed.\n");
+			return ret;
+		}
+	}
+
+	model = da906x_reg_read(da906x, DA906X_REG_CHIP_ID);
+	if (model < 0) {
+		dev_err(da906x->dev, "Cannot read chip model id.\n");
+		return -EIO;
+	}
+
+	ret = da906x_reg_read(da906x, DA906X_REG_CHIP_VARIANT);
+	if (ret < 0) {
+		dev_err(da906x->dev, "Cannot read chip revision id.\n");
+		return -EIO;
+	}
+
+	revision = ret >> DA906X_CHIP_VARIANT_SHIFT;
+
+	da906x_set_model_rev(da906x, model, revision);
+
+	dev_info(da906x->dev,
+		 "Device detected (model-ID: 0x%02X  rev-ID: 0x%02X)\n",
+		 model, revision);
+
+	ret = da906x_irq_init(da906x);
+	if (ret) {
+		dev_err(da906x->dev, "Cannot initialize interrupts.\n");
+		return ret;
+	}
+
+	ret = mfd_add_devices(da906x->dev, -1, da906x_devs,
+			      ARRAY_SIZE(da906x_devs), NULL, da906x->irq_base);
+	if (ret)
+		dev_err(da906x->dev, "Cannot add MFD cells\n");
+
+	return ret;
+}
+
+void da906x_device_exit(struct da906x *da906x)
+{
+	mfd_remove_devices(da906x->dev);
+	da906x_irq_exit(da906x);
+}
+
+MODULE_DESCRIPTION("PMIC driver for Dialog DA906X");
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>, Michal Hajduk <michal.hajduk@diasemi.com>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DA906X_DRVNAME_CORE);
diff --git a/drivers/mfd/da906x-i2c.c b/drivers/mfd/da906x-i2c.c
new file mode 100644
index 0000000..90b9e23
--- /dev/null
+++ b/drivers/mfd/da906x-i2c.c
@@ -0,0 +1,389 @@
+/* da906x-i2c.c: Interrupt support for Dialog DA906x
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/i2c.h>
+#include <linux/regmap.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/err.h>
+
+#include <linux/mfd/core.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+#include <linux/mfd/da906x/registers.h>
+
+
+#define RD		0x01	/* Readable register */
+#define WR		0x02	/* Writable register */
+#define VOL		0x04	/* Volatile register */
+
+/* Flags for virtual registers (mapped starting from DA906X_MAPPING_BASE) */
+const unsigned char da906x_reg_flg[] = {
+	[DA906X_REG_STATUS_A] =		RD | VOL,
+	[DA906X_REG_STATUS_B] =		RD | VOL,
+	[DA906X_REG_STATUS_C] =		RD | VOL,
+	[DA906X_REG_STATUS_D] =		RD | VOL,
+	[DA906X_REG_FAULT_LOG] =	RD | WR | VOL,
+	[DA906X_REG_EVENT_A] =		RD | WR | VOL,
+	[DA906X_REG_EVENT_B] =		RD | WR | VOL,
+	[DA906X_REG_EVENT_C] =		RD | WR | VOL,
+	[DA906X_REG_EVENT_D] =		RD | WR | VOL,
+	[DA906X_REG_IRQ_MASK_A] =	RD | WR,
+	[DA906X_REG_IRQ_MASK_B] =	RD | WR,
+	[DA906X_REG_IRQ_MASK_C] =	RD | WR,
+	[DA906X_REG_IRQ_MASK_D] =	RD | WR,
+	[DA906X_REG_CONTROL_A] =	RD | WR,
+	[DA906X_REG_CONTROL_B] =	RD | WR,
+	[DA906X_REG_CONTROL_C] =	RD | WR,
+	[DA906X_REG_CONTROL_D] =	RD | WR,
+	[DA906X_REG_CONTROL_E] =	RD | WR,
+	[DA906X_REG_CONTROL_F] =	RD | WR | VOL,
+	[DA906X_REG_PD_DIS] =		RD | WR,
+
+	[DA906X_REG_GPIO_0_1] =		RD | WR,
+	[DA906X_REG_GPIO_2_3] =		RD | WR,
+	[DA906X_REG_GPIO_4_5] =		RD | WR,
+	[DA906X_REG_GPIO_6_7] =		RD | WR,
+	[DA906X_REG_GPIO_8_9] =		RD | WR,
+	[DA906X_REG_GPIO_10_11] =	RD | WR,
+	[DA906X_REG_GPIO_12_13] =	RD | WR,
+	[DA906X_REG_GPIO_14_15] =	RD | WR,
+	[DA906X_REG_GPIO_MODE_0_7] =	RD | WR,
+	[DA906X_REG_GPIO_MODE_8_15] =	RD | WR,
+	[DA906X_REG_GPIO_SWITCH_CONT] =	RD | WR,
+
+	[DA906X_REG_BCORE2_CONT] =	RD | WR,
+	[DA906X_REG_BCORE1_CONT] =	RD | WR,
+	[DA906X_REG_BPRO_CONT] =	RD | WR,
+	[DA906X_REG_BMEM_CONT] =	RD | WR,
+	[DA906X_REG_BIO_CONT] =		RD | WR,
+	[DA906X_REG_BPERI_CONT] =	RD | WR,
+	[DA906X_REG_LDO1_CONT] =	RD | WR,
+	[DA906X_REG_LDO2_CONT] =	RD | WR,
+	[DA906X_REG_LDO3_CONT] =	RD | WR,
+	[DA906X_REG_LDO4_CONT] =	RD | WR,
+	[DA906X_REG_LDO5_CONT] =	RD | WR,
+	[DA906X_REG_LDO6_CONT] =	RD | WR,
+	[DA906X_REG_LDO7_CONT] =	RD | WR,
+	[DA906X_REG_LDO8_CONT] =	RD | WR,
+	[DA906X_REG_LDO9_CONT] =	RD | WR,
+	[DA906X_REG_LDO10_CONT] =	RD | WR,
+	[DA906X_REG_LDO11_CONT] =	RD | WR,
+	[DA906X_REG_VIB] =		RD | WR,
+	[DA906X_REG_DVC_1] =		RD | WR,
+	[DA906X_REG_DVC_2] =		RD | WR,
+
+	[DA906X_REG_ADC_MAN] =		RD | WR | VOL,
+	[DA906X_REG_ADC_CONT] =		RD | WR,
+	[DA906X_REG_VSYS_MON] =		RD | WR,
+	[DA906X_REG_ADC_RES_L] =	RD | VOL,
+	[DA906X_REG_ADC_RES_H] =	RD | VOL,
+	[DA906X_REG_VSYS_RES] =		RD | VOL,
+	[DA906X_REG_ADCIN1_RES] =	RD | VOL,
+	[DA906X_REG_ADCIN2_RES] =	RD | VOL,
+	[DA906X_REG_ADCIN3_RES] =	RD | VOL,
+	[DA906X_REG_MON1_RES] =		RD | VOL,
+	[DA906X_REG_MON2_RES] =		RD | VOL,
+	[DA906X_REG_MON3_RES] =		RD | VOL,
+
+	[DA906X_REG_COUNT_S] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_MI] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_H] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_D] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_MO] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_Y] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_MI] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_H] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_D] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_MO] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_Y] =		RD | WR | VOL,
+	[DA906X_REG_SECOND_A] =		RD | VOL,
+	[DA906X_REG_SECOND_B] =		RD | VOL,
+	[DA906X_REG_SECOND_C] =		RD | VOL,
+	[DA906X_REG_SECOND_D] =		RD | VOL,
+
+	[DA906X_REG_SEQ] =		RD | WR,
+	[DA906X_REG_SEQ_TIMER] =	RD | WR,
+	[DA906X_REG_ID_2_1] =		RD | WR,
+	[DA906X_REG_ID_4_3] =		RD | WR,
+	[DA906X_REG_ID_6_5] =		RD | WR,
+	[DA906X_REG_ID_8_7] =		RD | WR,
+	[DA906X_REG_ID_10_9] =		RD | WR,
+	[DA906X_REG_ID_12_11] =		RD | WR,
+	[DA906X_REG_ID_14_13] =		RD | WR,
+	[DA906X_REG_ID_16_15] =		RD | WR,
+	[DA906X_REG_ID_18_17] =		RD | WR,
+	[DA906X_REG_ID_20_19] =		RD | WR,
+	[DA906X_REG_ID_22_21] =		RD | WR,
+	[DA906X_REG_ID_24_23] =		RD | WR,
+	[DA906X_REG_ID_26_25] =		RD | WR,
+	[DA906X_REG_ID_28_27] =		RD | WR,
+	[DA906X_REG_ID_30_29] =		RD | WR,
+	[DA906X_REG_ID_32_31] =		RD | WR,
+	[DA906X_REG_SEQ_A] =		RD | WR,
+	[DA906X_REG_SEQ_B] =		RD | WR,
+	[DA906X_REG_WAIT] =		RD | WR,
+	[DA906X_REG_EN_32K] =		RD | WR,
+	[DA906X_REG_RESET] =		RD | WR,
+
+	[DA906X_REG_BUCK_ILIM_A] =	RD | WR,
+	[DA906X_REG_BUCK_ILIM_B] =	RD | WR,
+	[DA906X_REG_BUCK_ILIM_C] =	RD | WR,
+	[DA906X_REG_BCORE2_CFG] =	RD | WR,
+	[DA906X_REG_BCORE1_CFG] =	RD | WR,
+	[DA906X_REG_BPRO_CFG] =		RD | WR,
+	[DA906X_REG_BIO_CFG] =		RD | WR,
+	[DA906X_REG_BMEM_CFG] =		RD | WR,
+	[DA906X_REG_BPERI_CFG] =	RD | WR,
+	[DA906X_REG_VBCORE2_A] =	RD | WR,
+	[DA906X_REG_VBCORE1_A] =	RD | WR,
+	[DA906X_REG_VBPRO_A] =		RD | WR,
+	[DA906X_REG_VBMEM_A] =		RD | WR,
+	[DA906X_REG_VBIO_A] =		RD | WR,
+	[DA906X_REG_VBPERI_A] =		RD | WR,
+	[DA906X_REG_VLDO1_A] =		RD | WR,
+	[DA906X_REG_VLDO2_A] =		RD | WR,
+	[DA906X_REG_VLDO3_A] =		RD | WR,
+	[DA906X_REG_VLDO4_A] =		RD | WR,
+	[DA906X_REG_VLDO5_A] =		RD | WR,
+	[DA906X_REG_VLDO6_A] =		RD | WR,
+	[DA906X_REG_VLDO7_A] =		RD | WR,
+	[DA906X_REG_VLDO8_A] =		RD | WR,
+	[DA906X_REG_VLDO9_A] =		RD | WR,
+	[DA906X_REG_VLDO10_A] =		RD | WR,
+	[DA906X_REG_VLDO11_A] =		RD | WR,
+	[DA906X_REG_VBCORE2_B] =	RD | WR,
+	[DA906X_REG_VBCORE1_B] =	RD | WR,
+	[DA906X_REG_VBPRO_B] =		RD | WR,
+	[DA906X_REG_VBMEM_B] =		RD | WR,
+	[DA906X_REG_VBIO_B] =		RD | WR,
+	[DA906X_REG_VBPERI_B] =		RD | WR,
+	[DA906X_REG_VLDO1_B] =		RD | WR,
+	[DA906X_REG_VLDO2_B] =		RD | WR,
+	[DA906X_REG_VLDO3_B] =		RD | WR,
+	[DA906X_REG_VLDO4_B] =		RD | WR,
+	[DA906X_REG_VLDO5_B] =		RD | WR,
+	[DA906X_REG_VLDO6_B] =		RD | WR,
+	[DA906X_REG_VLDO7_B] =		RD | WR,
+	[DA906X_REG_VLDO8_B] =		RD | WR,
+	[DA906X_REG_VLDO9_B] =		RD | WR,
+	[DA906X_REG_VLDO10_B] =		RD | WR,
+	[DA906X_REG_VLDO11_B] =		RD | WR,
+
+	[DA906X_REG_BBAT_CONT] =	RD | WR,
+
+	[DA906X_REG_GPO11_LED] =	RD | WR,
+	[DA906X_REG_GPO14_LED] =	RD | WR,
+	[DA906X_REG_GPO15_LED] =	RD | WR,
+
+	[DA906X_REG_ADC_CFG] =		RD | WR,
+	[DA906X_REG_AUTO1_HIGH] =	RD | WR,
+	[DA906X_REG_AUTO1_LOW] =	RD | WR,
+	[DA906X_REG_AUTO2_HIGH] =	RD | WR,
+	[DA906X_REG_AUTO2_LOW] =	RD | WR,
+	[DA906X_REG_AUTO3_HIGH] =	RD | WR,
+	[DA906X_REG_AUTO3_LOW] =	RD | WR,
+
+	[DA906X_REG_T_OFFSET] =		RD,
+	[DA906X_REG_CONFIG_H] =		RD,
+	[DA906X_REG_CONFIG_I] =		RD | WR,
+	[DA906X_REG_MON_REG_1] =	RD | WR,
+	[DA906X_REG_MON_REG_2] =	RD | WR,
+	[DA906X_REG_MON_REG_3] =	RD | WR,
+	[DA906X_REG_MON_REG_4] =	RD | WR,
+	[DA906X_REG_MON_REG_5] =	RD | VOL,
+	[DA906X_REG_MON_REG_6] =	RD | VOL,
+	[DA906X_REG_TRIM_CLDR] =	RD,
+
+	[DA906X_REG_GP_ID_0] =		RD | WR,
+	[DA906X_REG_GP_ID_1] =		RD | WR,
+	[DA906X_REG_GP_ID_2] =		RD | WR,
+	[DA906X_REG_GP_ID_3] =		RD | WR,
+	[DA906X_REG_GP_ID_4] =		RD | WR,
+	[DA906X_REG_GP_ID_5] =		RD | WR,
+	[DA906X_REG_GP_ID_6] =		RD | WR,
+	[DA906X_REG_GP_ID_7] =		RD | WR,
+	[DA906X_REG_GP_ID_8] =		RD | WR,
+	[DA906X_REG_GP_ID_9] =		RD | WR,
+	[DA906X_REG_GP_ID_10] =		RD | WR,
+	[DA906X_REG_GP_ID_11] =		RD | WR,
+	[DA906X_REG_GP_ID_12] =		RD | WR,
+	[DA906X_REG_GP_ID_13] =		RD | WR,
+	[DA906X_REG_GP_ID_14] =		RD | WR,
+	[DA906X_REG_GP_ID_15] =		RD | WR,
+	[DA906X_REG_GP_ID_16] =		RD | WR,
+	[DA906X_REG_GP_ID_17] =		RD | WR,
+	[DA906X_REG_GP_ID_18] =		RD | WR,
+	[DA906X_REG_GP_ID_19] =		RD | WR,
+
+	[DA906X_REG_CHIP_ID] =		RD,
+	[DA906X_REG_CHIP_VARIANT] =	RD,
+};
+
+static bool da906x_reg_readable(struct device *dev, unsigned int reg)
+{
+	if (reg < DA906X_MAPPING_BASE) {
+		return true;
+	} else {
+		reg -= DA906X_MAPPING_BASE;
+		if (da906x_reg_flg[reg] & RD)
+			return true;
+		else
+			return false;
+	}
+}
+
+static bool da906x_reg_writable(struct device *dev, unsigned int reg)
+{
+	if (reg < DA906X_MAPPING_BASE) {
+		return true;
+	} else {
+		reg -= DA906X_MAPPING_BASE;
+		if (da906x_reg_flg[reg] & WR)
+			return true;
+		else
+			return false;
+	}
+}
+
+static bool da906x_reg_volatile(struct device *dev, unsigned int reg)
+{
+	if (reg < DA906X_MAPPING_BASE) {
+		switch (reg) {
+		case DA906X_REG_PAGE_CON:    /* Use cache for page selector */
+			return false;
+		default:
+			return true;
+		}
+	} else {
+		reg -= DA906X_MAPPING_BASE;
+		if (da906x_reg_flg[reg] & VOL)
+			return true;
+		else
+			return false;
+	}
+}
+
+static const struct regmap_range_cfg da906x_range_cfg[] = {
+	{
+		.range_min = DA906X_MAPPING_BASE,
+		.range_max = DA906X_MAPPING_BASE +
+			     ARRAY_SIZE(da906x_reg_flg) - 1,
+		.selector_reg = DA906X_REG_PAGE_CON,
+		.selector_mask = 1 << DA906X_I2C_PAGE_SEL_SHIFT,
+		.selector_shift = DA906X_I2C_PAGE_SEL_SHIFT,
+		.window_start = 0,
+		.window_len = 256,
+	}
+};
+
+struct regmap_config da906x_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.ranges = da906x_range_cfg,
+	.n_ranges = ARRAY_SIZE(da906x_range_cfg),
+	.max_register = DA906X_MAPPING_BASE + ARRAY_SIZE(da906x_reg_flg) - 1,
+
+	.cache_type = REGCACHE_RBTREE,
+
+	.writeable_reg = &da906x_reg_writable,
+	.readable_reg = &da906x_reg_readable,
+	.volatile_reg = &da906x_reg_volatile,
+};
+
+struct regmap_config da906x_no_cache_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.ranges = da906x_range_cfg,
+	.n_ranges = ARRAY_SIZE(da906x_range_cfg),
+	.max_register = DA906X_MAPPING_BASE + ARRAY_SIZE(da906x_reg_flg) - 1,
+
+	.cache_type = REGCACHE_NONE,
+
+	.writeable_reg = &da906x_reg_writable,
+	.readable_reg = &da906x_reg_readable,
+};
+
+static int da906x_i2c_probe(struct i2c_client *i2c,
+	const struct i2c_device_id *id)
+{
+	struct da906x *da906x;
+	struct regmap_config *config = &da906x_regmap_config;
+	struct da906x_pdata *pdata = i2c->dev.platform_data;
+	int ret;
+
+	da906x = devm_kzalloc(&i2c->dev, sizeof(struct da906x), GFP_KERNEL);
+	if (da906x = NULL)
+		return -ENOMEM;
+
+	i2c_set_clientdata(i2c, da906x);
+	da906x->dev = &i2c->dev;
+
+	if (pdata->flags & DA906X_FLG_NO_CACHE)
+		config = &da906x_no_cache_regmap_config;
+
+	da906x->regmap = devm_regmap_init_i2c(i2c, config);
+	if (IS_ERR(da906x->regmap)) {
+		ret = PTR_ERR(da906x->regmap);
+		dev_err(da906x->dev, "Failed to allocate register map: %d\n",
+			ret);
+		return ret;
+	}
+
+	return da906x_device_init(da906x, i2c->irq);
+}
+
+static int da906x_i2c_remove(struct i2c_client *i2c)
+{
+	struct da906x *da906x = i2c_get_clientdata(i2c);
+
+	da906x_device_exit(da906x);
+
+	return 0;
+}
+
+static const struct i2c_device_id da906x_i2c_id[] = {
+	{"da906x", PMIC_DA9063},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, da906x_i2c_id);
+
+static struct i2c_driver da906x_i2c_driver = {
+	.driver = {
+		.name = "da906x",
+		.owner = THIS_MODULE,
+	},
+	.probe    = da906x_i2c_probe,
+	.remove   = da906x_i2c_remove,
+	.id_table = da906x_i2c_id,
+};
+
+static int __init da906x_i2c_init(void)
+{
+	int ret;
+
+	ret = i2c_add_driver(&da906x_i2c_driver);
+	if (ret != 0)
+		pr_err("Failed to register da906x I2C driver\n");
+
+	return ret;
+}
+subsys_initcall(da906x_i2c_init);
+
+static void __exit da906x_i2c_exit(void)
+{
+	i2c_del_driver(&da906x_i2c_driver);
+}
+module_exit(da906x_i2c_exit);
diff --git a/drivers/mfd/da906x-irq.c b/drivers/mfd/da906x-irq.c
new file mode 100644
index 0000000..18d2796
--- /dev/null
+++ b/drivers/mfd/da906x-irq.c
@@ -0,0 +1,192 @@
+/* da906x-irq.c: Interrupts support for Dialog DA906X
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ *
+ *  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/irq.h>
+#include <linux/mfd/core.h>
+#include <linux/interrupt.h>
+#include <linux/regmap.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+
+#define	DA906X_REG_EVENT_A_OFFSET	0
+#define	DA906X_REG_EVENT_B_OFFSET	1
+#define	DA906X_REG_EVENT_C_OFFSET	2
+#define	DA906X_REG_EVENT_D_OFFSET	3
+#define EVENTS_BUF_LEN			4
+
+static const u8 mask_events_buf[] = { [0 ... (EVENTS_BUF_LEN - 1)] = ~0 };
+
+struct da906x_irq_data {
+	u16 reg;
+	u8 mask;
+};
+
+static struct regmap_irq da906x_irqs[] = {
+	/* DA906x event A register */
+	[DA906X_IRQ_ONKEY] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_ONKEY,
+	},
+	[DA906X_IRQ_ALARM] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_ALARM,
+	},
+	[DA906X_IRQ_TICK] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_TICK,
+	},
+	[DA906X_IRQ_ADC_RDY] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_ADC_RDY,
+	},
+	[DA906X_IRQ_SEQ_RDY] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_SEQ_RDY,
+	},
+	/* DA906x event B register */
+	[DA906X_IRQ_WAKE] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_WAKE,
+	},
+	[DA906X_IRQ_TEMP] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_TEMP,
+	},
+	[DA906X_IRQ_COMP_1V2] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_COMP_1V2,
+	},
+	[DA906X_IRQ_LDO_LIM] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_LDO_LIM,
+	},
+	[DA906X_IRQ_REG_UVOV] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_UVOV,
+	},
+	[DA906X_IRQ_VDD_MON] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_VDD_MON,
+	},
+	[DA906X_IRQ_WARN] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_VDD_WARN,
+	},
+	/* DA906x event C register */
+	[DA906X_IRQ_GPI0] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI0,
+	},
+	[DA906X_IRQ_GPI1] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI1,
+	},
+	[DA906X_IRQ_GPI2] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI2,
+	},
+	[DA906X_IRQ_GPI3] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI3,
+	},
+	[DA906X_IRQ_GPI4] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI4,
+	},
+	[DA906X_IRQ_GPI5] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI5,
+	},
+	[DA906X_IRQ_GPI6] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI6,
+	},
+	[DA906X_IRQ_GPI7] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI7,
+	},
+	/* DA906x event D register */
+	[DA906X_IRQ_GPI8] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI8,
+	},
+	[DA906X_IRQ_GPI9] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI9,
+	},
+	[DA906X_IRQ_GPI10] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI10,
+	},
+	[DA906X_IRQ_GPI11] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI11,
+	},
+	[DA906X_IRQ_GPI12] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI12,
+	},
+	[DA906X_IRQ_GPI13] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI13,
+	},
+	[DA906X_IRQ_GPI14] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI14,
+	},
+	[DA906X_IRQ_GPI15] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI15,
+	},
+};
+
+static struct regmap_irq_chip da906x_irq_chip = {
+	.name = "da906x-irq",
+	.irqs = da906x_irqs,
+	.num_irqs = DA906X_NUM_IRQ,
+
+	.num_regs = 4,
+	.status_base = DA906X_REG_EVENT_A + DA906X_MAPPING_BASE,
+	.mask_base = DA906X_REG_IRQ_MASK_A + DA906X_MAPPING_BASE,
+	.ack_base = DA906X_REG_EVENT_A + DA906X_MAPPING_BASE,
+};
+
+int da906x_irq_init(struct da906x *da906x)
+{
+	int ret;
+
+	if (!da906x->chip_irq) {
+		dev_err(da906x->dev, "No IRQ configured\n");
+		return -EINVAL;
+	}
+
+	ret = regmap_add_irq_chip(da906x->regmap, da906x->chip_irq,
+			IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED,
+			da906x->irq_base, &da906x_irq_chip,
+			&da906x->regmap_irq);
+	if (ret) {
+		dev_err(da906x->dev, "Failed to reguest IRQ %d: %d\n",
+				da906x->chip_irq, ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+void da906x_irq_exit(struct da906x *da906x)
+{
+	regmap_del_irq_chip(da906x->chip_irq, da906x->regmap_irq);
+}
+
diff --git a/include/linux/mfd/da906x/core.h b/include/linux/mfd/da906x/core.h
new file mode 100644
index 0000000..abd916d
--- /dev/null
+++ b/include/linux/mfd/da906x/core.h
@@ -0,0 +1,121 @@
+/*
+ * Definitions for DA906X MFD driver
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ *	   Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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.
+ *
+ */
+
+#ifndef __MFD_DA906X_CORE_H__
+#define __MFD_DA906X_CORE_H__
+
+#include <linux/interrupt.h>
+#include <linux/mfd/da906x/registers.h>
+
+/* DA906x modules */
+#define DA906X_DRVNAME_CORE		"da906x-core"
+#define DA906X_DRVNAME_REGULATORS	"da906x-regulators"
+#define DA906X_DRVNAME_LEDS		"da906x-leds"
+#define DA906X_DRVNAME_WATCHDOG		"da906x-watchdog"
+#define DA906X_DRVNAME_HWMON		"da906x-hwmon"
+#define DA906X_DRVNAME_ONKEY		"da906x-onkey"
+#define DA906X_DRVNAME_RTC		"da906x-rtc"
+#define DA906X_DRVNAME_VIBRATION	"da906x-vibration"
+
+enum da906x_models {
+	PMIC_DA9063 = 0x61,
+};
+
+/* Interrupts */
+enum da906x_irqs {
+	DA906X_IRQ_ONKEY = 0,
+	DA906X_IRQ_ALARM,
+	DA906X_IRQ_TICK,
+	DA906X_IRQ_ADC_RDY,
+	DA906X_IRQ_SEQ_RDY,
+	DA906X_IRQ_WAKE,
+	DA906X_IRQ_TEMP,
+	DA906X_IRQ_COMP_1V2,
+	DA906X_IRQ_LDO_LIM,
+	DA906X_IRQ_REG_UVOV,
+	DA906X_IRQ_VDD_MON,
+	DA906X_IRQ_WARN,
+	DA906X_IRQ_GPI0,
+	DA906X_IRQ_GPI1,
+	DA906X_IRQ_GPI2,
+	DA906X_IRQ_GPI3,
+	DA906X_IRQ_GPI4,
+	DA906X_IRQ_GPI5,
+	DA906X_IRQ_GPI6,
+	DA906X_IRQ_GPI7,
+	DA906X_IRQ_GPI8,
+	DA906X_IRQ_GPI9,
+	DA906X_IRQ_GPI10,
+	DA906X_IRQ_GPI11,
+	DA906X_IRQ_GPI12,
+	DA906X_IRQ_GPI13,
+	DA906X_IRQ_GPI14,
+	DA906X_IRQ_GPI15,
+};
+
+#define DA906X_IRQ_BASE_OFFSET	0
+#define DA906X_NUM_IRQ		(DA906X_IRQ_GPI15 + 1 - DA906X_IRQ_BASE_OFFSET)
+
+struct da906x {
+	/* Device */
+	struct device	*dev;
+	unsigned short	model;
+	unsigned short	revision;
+	unsigned int	flags;
+
+	/* Control interface */
+	struct mutex	io_mutex;
+	struct regmap	*regmap;
+
+	/* Interrupts */
+	int		chip_irq;
+	unsigned int	irq_base;
+	struct regmap_irq_chip_data *regmap_irq;
+};
+
+static inline unsigned da906x_model(struct da906x *da906x)
+{
+	return da906x->model;
+}
+
+static inline unsigned da906x_revision(struct da906x *da906x)
+{
+	return da906x->revision;
+}
+
+static inline void da906x_set_model_rev(struct da906x *da906x,
+			enum da906x_models model, unsigned short revision)
+{
+	da906x->model = model;
+	da906x->revision = revision;
+}
+
+int da906x_reg_read(struct da906x *da906x, u16 reg);
+int da906x_reg_write(struct da906x *da906x, u16 reg, u8 val);
+
+int da906x_block_write(struct da906x *da906x, u16 reg, int bytes, const u8 *buf);
+int da906x_block_read(struct da906x *da906x, u16 reg, int bytes, u8 *buf);
+
+int da906x_reg_set_bits(struct da906x *da906x, u16 reg, u8 mask);
+int da906x_reg_clear_bits(struct da906x *da906x, u16 reg, u8 mask);
+int da906x_reg_update(struct da906x*, u16 reg, u8 mask, u8 val);
+
+int da906x_device_init(struct da906x *da906x, unsigned int irq);
+int da906x_irq_init(struct da906x *da906x);
+
+void da906x_device_exit(struct da906x *da906x);
+void da906x_irq_exit(struct da906x *da906x);
+
+#endif /* __MFD_DA906X_CORE_H__ */
diff --git a/include/linux/mfd/da906x/pdata.h b/include/linux/mfd/da906x/pdata.h
new file mode 100644
index 0000000..97ae242
--- /dev/null
+++ b/include/linux/mfd/da906x/pdata.h
@@ -0,0 +1,114 @@
+/*
+ * Platform configuration options for DA906x
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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.
+ *
+ */
+
+#ifndef __MFD_DA906X_PDATA_H__
+#define __MFD_DA906X_PDATA_H__
+
+#include <linux/regulator/machine.h>
+
+/*
+ * Regulator configuration
+ */
+/* DA9063 regulator IDs */
+enum {
+	/* BUCKs */
+	DA9063_ID_BCORE1,
+	DA9063_ID_BCORE2,
+	DA9063_ID_BPRO,
+	DA9063_ID_BMEM,
+	DA9063_ID_BIO,
+	DA9063_ID_BPERI,
+
+	/* BCORE1 and BCORE2 in merged mode */
+	DA9063_ID_BCORES_MERGED,
+	/* BMEM and BIO in merged mode */
+	DA9063_ID_BMEM_BIO_MERGED,
+	/* When two BUCKs are merged, they cannot be reused separately */
+
+	/* LDOs */
+	DA9063_ID_LDO1,
+	DA9063_ID_LDO2,
+	DA9063_ID_LDO3,
+	DA9063_ID_LDO4,
+	DA9063_ID_LDO5,
+	DA9063_ID_LDO6,
+	DA9063_ID_LDO7,
+	DA9063_ID_LDO8,
+	DA9063_ID_LDO9,
+	DA9063_ID_LDO10,
+	DA9063_ID_LDO11,
+
+	/* RTC internal oscilator switch */
+	DA9063_ID_32K_OUT,
+};
+
+/* Regulators platform data */
+struct da906x_regulator_data {
+	int				id;
+	struct regulator_init_data	*initdata;
+};
+
+struct da906x_regulators_pdata {
+	unsigned			n_regulators;
+	struct da906x_regulator_data	*regulator_data;
+};
+
+
+/*
+ * RGB LED configuration
+ */
+/* LED IDs for flags in struct led_info. */
+enum {
+	DA906X_GPIO11_LED,
+	DA906X_GPIO14_LED,
+	DA906X_GPIO15_LED,
+
+	DA906X_LED_NUM
+};
+#define DA906X_LED_ID_MASK		0x3
+
+/* LED polarity for flags in struct led_info. */
+#define DA906X_LED_HIGH_LEVEL_ACTIVE	0x0
+#define DA906X_LED_LOW_LEVEL_ACTIVE	0x4
+
+
+/*
+ * General PMIC configuration
+ */
+/* HWMON ADC channels configuration */
+#define DA906X_FLG_FORCE_IN0_MANUAL_MODE	0x0010
+#define DA906X_FLG_FORCE_IN0_AUTO_MODE		0x0020
+#define DA906X_FLG_FORCE_IN1_MANUAL_MODE	0x0040
+#define DA906X_FLG_FORCE_IN1_AUTO_MODE		0x0080
+#define DA906X_FLG_FORCE_IN2_MANUAL_MODE	0x0100
+#define DA906X_FLG_FORCE_IN2_AUTO_MODE		0x0200
+#define DA906X_FLG_FORCE_IN3_MANUAL_MODE	0x0400
+#define DA906X_FLG_FORCE_IN3_AUTO_MODE		0x0800
+
+/* Disable register caching. */
+#define DA906X_FLG_NO_CACHE			0x0008
+
+struct da906x;
+
+/* DA906x platform data */
+struct da906x_pdata {
+	int				(*init)(struct da906x *da906x);
+	int				irq_base;
+	unsigned			flags;
+	struct da906x_regulators_pdata	*regulators_pdata;
+	struct led_platform_data	*leds_pdata;
+};
+
+#endif	/* __MFD_DA906X_PDATA_H__ */
diff --git a/include/linux/mfd/da906x/registers.h b/include/linux/mfd/da906x/registers.h
new file mode 100644
index 0000000..6808977
--- /dev/null
+++ b/include/linux/mfd/da906x/registers.h
@@ -0,0 +1,1093 @@
+/*
+ * Registers definition for DA906X modules
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ *	   Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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.
+ *
+ */
+
+#ifndef _DA906X_REG_H
+#define	_DA906X_REG_H
+
+#define DA906X_I2C_PAGE_SEL_SHIFT	1
+#define DA906X_I2C_PAGE(v)		(((v) >> 8) << \
+						DA906X_I2C_PAGE_SEL_SHIFT)
+#define DA906X_I2C_REG(v)		((v) & 0xFF)
+
+#define	DA906X_EVENT_REG_NUM		4
+#define	DA9210_EVENT_REG_NUM		2
+#define	DA906X_EXT_EVENT_REG_NUM	(DA906X_EVENT_REG_NUM + \
+						DA9210_EVENT_REG_NUM)
+
+/* Page selection I2C or SPI always in the begining of any page. */
+/* Page 0 : I2C access 0x000 - 0x0FF	SPI access 0x000 - 0x07F */
+/* Page 1 :				SPI access 0x080 - 0x0FF */
+/* Page 2 : I2C access 0x100 - 0x1FF	SPI access 0x100 - 0x17F */
+/* Page 3 :				SPI access 0x180 - 0x1FF */
+#define	DA906X_REG_PAGE_CON		0x00
+
+/* Create virtual range for pageable registers just above physical range */
+#define DA906X_MAPPING_BASE		0x100
+
+/* System Control and Event Registers */
+#define	DA906X_REG_STATUS_A		0x01
+#define	DA906X_REG_STATUS_B		0x02
+#define	DA906X_REG_STATUS_C		0x03
+#define	DA906X_REG_STATUS_D		0x04
+#define	DA906X_REG_FAULT_LOG		0x05
+#define	DA906X_REG_EVENT_A		0x06
+#define	DA906X_REG_EVENT_B		0x07
+#define	DA906X_REG_EVENT_C		0x08
+#define	DA906X_REG_EVENT_D		0x09
+#define	DA906X_REG_IRQ_MASK_A		0x0A
+#define	DA906X_REG_IRQ_MASK_B		0x0B
+#define	DA906X_REG_IRQ_MASK_C		0x0C
+#define	DA906X_REG_IRQ_MASK_D		0x0D
+#define	DA906X_REG_CONTROL_A		0x0E
+#define	DA906X_REG_CONTROL_B		0x0F
+#define	DA906X_REG_CONTROL_C		0x10
+#define	DA906X_REG_CONTROL_D		0x11
+#define	DA906X_REG_CONTROL_E		0x12
+#define	DA906X_REG_CONTROL_F		0x13
+#define	DA906X_REG_PD_DIS		0x14
+
+/* GPIO Control Registers */
+#define	DA906X_REG_GPIO_0_1		0x15
+#define	DA906X_REG_GPIO_2_3		0x16
+#define	DA906X_REG_GPIO_4_5		0x17
+#define	DA906X_REG_GPIO_6_7		0x18
+#define	DA906X_REG_GPIO_8_9		0x19
+#define	DA906X_REG_GPIO_10_11		0x1A
+#define	DA906X_REG_GPIO_12_13		0x1B
+#define	DA906X_REG_GPIO_14_15		0x1C
+#define	DA906X_REG_GPIO_MODE_0_7	0x1D
+#define	DA906X_REG_GPIO_MODE_8_15	0x1E
+#define	DA906X_REG_GPIO_SWITCH_CONT	0x1F
+
+/* Regulator Control Registers */
+#define	DA906X_REG_BCORE2_CONT		0x20
+#define	DA906X_REG_BCORE1_CONT		0x21
+#define	DA906X_REG_BPRO_CONT		0x22
+#define	DA906X_REG_BMEM_CONT		0x23
+#define	DA906X_REG_BIO_CONT		0x24
+#define	DA906X_REG_BPERI_CONT		0x25
+#define	DA906X_REG_LDO1_CONT		0x26
+#define	DA906X_REG_LDO2_CONT		0x27
+#define	DA906X_REG_LDO3_CONT		0x28
+#define	DA906X_REG_LDO4_CONT		0x29
+#define	DA906X_REG_LDO5_CONT		0x2A
+#define	DA906X_REG_LDO6_CONT		0x2B
+#define	DA906X_REG_LDO7_CONT		0x2C
+#define	DA906X_REG_LDO8_CONT		0x2D
+#define	DA906X_REG_LDO9_CONT		0x2E
+#define	DA906X_REG_LDO10_CONT		0x2F
+#define	DA906X_REG_LDO11_CONT		0x30
+#define	DA906X_REG_VIB			0x31
+#define	DA906X_REG_DVC_1		0x32
+#define	DA906X_REG_DVC_2		0x33
+
+/* GP-ADC Control Registers */
+#define	DA906X_REG_ADC_MAN		0x34
+#define	DA906X_REG_ADC_CONT		0x35
+#define	DA906X_REG_VSYS_MON		0x36
+#define	DA906X_REG_ADC_RES_L		0x37
+#define	DA906X_REG_ADC_RES_H		0x38
+#define	DA906X_REG_VSYS_RES		0x39
+#define	DA906X_REG_ADCIN1_RES		0x3A
+#define	DA906X_REG_ADCIN2_RES		0x3B
+#define	DA906X_REG_ADCIN3_RES		0x3C
+#define	DA906X_REG_MON1_RES		0x3D
+#define	DA906X_REG_MON2_RES		0x3E
+#define	DA906X_REG_MON3_RES		0x3F
+
+/* RTC Calendar and Alarm Registers */
+#define	DA906X_REG_COUNT_S		0x40
+#define	DA906X_REG_COUNT_MI		0x41
+#define	DA906X_REG_COUNT_H		0x42
+#define	DA906X_REG_COUNT_D		0x43
+#define	DA906X_REG_COUNT_MO		0x44
+#define	DA906X_REG_COUNT_Y		0x45
+#define	DA906X_REG_ALARM_MI		0x46
+#define	DA906X_REG_ALARM_H		0x47
+#define	DA906X_REG_ALARM_D		0x48
+#define	DA906X_REG_ALARM_MO		0x49
+#define	DA906X_REG_ALARM_Y		0x4A
+#define	DA906X_REG_SECOND_A		0x4B
+#define	DA906X_REG_SECOND_B		0x4C
+#define	DA906X_REG_SECOND_C		0x4D
+#define	DA906X_REG_SECOND_D		0x4E
+
+/* Sequencer Control Registers */
+#define	DA906X_REG_SEQ			0x81
+#define	DA906X_REG_SEQ_TIMER		0x82
+#define	DA906X_REG_ID_2_1		0x83
+#define	DA906X_REG_ID_4_3		0x84
+#define	DA906X_REG_ID_6_5		0x85
+#define	DA906X_REG_ID_8_7		0x86
+#define	DA906X_REG_ID_10_9		0x87
+#define	DA906X_REG_ID_12_11		0x88
+#define	DA906X_REG_ID_14_13		0x89
+#define	DA906X_REG_ID_16_15		0x8A
+#define	DA906X_REG_ID_18_17		0x8B
+#define	DA906X_REG_ID_20_19		0x8C
+#define	DA906X_REG_ID_22_21		0x8D
+#define	DA906X_REG_ID_24_23		0x8E
+#define	DA906X_REG_ID_26_25		0x8F
+#define	DA906X_REG_ID_28_27		0x90
+#define	DA906X_REG_ID_30_29		0x91
+#define	DA906X_REG_ID_32_31		0x92
+#define	DA906X_REG_SEQ_A		0x95
+#define	DA906X_REG_SEQ_B		0x96
+#define	DA906X_REG_WAIT			0x97
+#define	DA906X_REG_EN_32K		0x98
+#define	DA906X_REG_RESET		0x99
+
+/* Regulator Setting Registers */
+#define	DA906X_REG_BUCK_ILIM_A		0x9A
+#define	DA906X_REG_BUCK_ILIM_B		0x9B
+#define	DA906X_REG_BUCK_ILIM_C		0x9C
+#define	DA906X_REG_BCORE2_CFG		0x9D
+#define	DA906X_REG_BCORE1_CFG		0x9E
+#define	DA906X_REG_BPRO_CFG		0x9F
+#define	DA906X_REG_BIO_CFG		0xA0
+#define	DA906X_REG_BMEM_CFG		0xA1
+#define	DA906X_REG_BPERI_CFG		0xA2
+#define	DA906X_REG_VBCORE2_A		0xA3
+#define	DA906X_REG_VBCORE1_A		0xA4
+#define	DA906X_REG_VBPRO_A		0xA5
+#define	DA906X_REG_VBMEM_A		0xA6
+#define	DA906X_REG_VBIO_A		0xA7
+#define	DA906X_REG_VBPERI_A		0xA8
+#define	DA906X_REG_VLDO1_A		0xA9
+#define	DA906X_REG_VLDO2_A		0xAA
+#define	DA906X_REG_VLDO3_A		0xAB
+#define	DA906X_REG_VLDO4_A		0xAC
+#define	DA906X_REG_VLDO5_A		0xAD
+#define	DA906X_REG_VLDO6_A		0xAE
+#define	DA906X_REG_VLDO7_A		0xAF
+#define	DA906X_REG_VLDO8_A		0xB0
+#define	DA906X_REG_VLDO9_A		0xB1
+#define	DA906X_REG_VLDO10_A		0xB2
+#define	DA906X_REG_VLDO11_A		0xB3
+#define	DA906X_REG_VBCORE2_B		0xB4
+#define	DA906X_REG_VBCORE1_B		0xB5
+#define	DA906X_REG_VBPRO_B		0xB6
+#define	DA906X_REG_VBMEM_B		0xB7
+#define	DA906X_REG_VBIO_B		0xB8
+#define	DA906X_REG_VBPERI_B		0xB9
+#define	DA906X_REG_VLDO1_B		0xBA
+#define	DA906X_REG_VLDO2_B		0xBB
+#define	DA906X_REG_VLDO3_B		0xBC
+#define	DA906X_REG_VLDO4_B		0xBD
+#define	DA906X_REG_VLDO5_B		0xBE
+#define	DA906X_REG_VLDO6_B		0xBF
+#define	DA906X_REG_VLDO7_B		0xC0
+#define	DA906X_REG_VLDO8_B		0xC1
+#define	DA906X_REG_VLDO9_B		0xC2
+#define	DA906X_REG_VLDO10_B		0xC3
+#define	DA906X_REG_VLDO11_B		0xC4
+
+/* Backup Battery Charger Control Register */
+#define	DA906X_REG_BBAT_CONT		0xC5
+
+/* GPIO PWM (LED) */
+#define	DA906X_REG_GPO11_LED		0xC6
+#define	DA906X_REG_GPO14_LED		0xC7
+#define	DA906X_REG_GPO15_LED		0xC8
+
+/* GP-ADC Threshold Registers */
+#define	DA906X_REG_ADC_CFG		0xC9
+#define	DA906X_REG_AUTO1_HIGH		0xCA
+#define	DA906X_REG_AUTO1_LOW		0xCB
+#define	DA906X_REG_AUTO2_HIGH		0xCC
+#define	DA906X_REG_AUTO2_LOW		0xCD
+#define	DA906X_REG_AUTO3_HIGH		0xCE
+#define	DA906X_REG_AUTO3_LOW		0xCF
+
+/* DA906x Configuration registers */
+/* OTP */
+#define	DA906X_REG_OPT_COUNT		0x101
+#define	DA906X_REG_OPT_ADDR		0x102
+#define	DA906X_REG_OPT_DATA		0x103
+
+/* Customer Trim and Configuration */
+#define	DA906X_REG_T_OFFSET		0x104
+#define	DA906X_REG_INTERFACE		0x105
+#define	DA906X_REG_CONFIG_A		0x106
+#define	DA906X_REG_CONFIG_B		0x107
+#define	DA906X_REG_CONFIG_C		0x108
+#define	DA906X_REG_CONFIG_D		0x109
+#define	DA906X_REG_CONFIG_E		0x10A
+#define	DA906X_REG_CONFIG_F		0x10B
+#define	DA906X_REG_CONFIG_G		0x10C
+#define	DA906X_REG_CONFIG_H		0x10D
+#define	DA906X_REG_CONFIG_I		0x10E
+#define	DA906X_REG_CONFIG_J		0x10F
+#define	DA906X_REG_CONFIG_K		0x110
+#define	DA906X_REG_CONFIG_L		0x111
+#define	DA906X_REG_MON_REG_1		0x112
+#define	DA906X_REG_MON_REG_2		0x113
+#define	DA906X_REG_MON_REG_3		0x114
+#define	DA906X_REG_MON_REG_4		0x115
+#define	DA906X_REG_MON_REG_5		0x116
+#define	DA906X_REG_MON_REG_6		0x117
+#define	DA906X_REG_TRIM_CLDR		0x118
+
+/* General Purpose Registers */
+#define	DA906X_REG_GP_ID_0		0x119
+#define	DA906X_REG_GP_ID_1		0x11A
+#define	DA906X_REG_GP_ID_2		0x11B
+#define	DA906X_REG_GP_ID_3		0x11C
+#define	DA906X_REG_GP_ID_4		0x11D
+#define	DA906X_REG_GP_ID_5		0x11E
+#define	DA906X_REG_GP_ID_6		0x11F
+#define	DA906X_REG_GP_ID_7		0x120
+#define	DA906X_REG_GP_ID_8		0x121
+#define	DA906X_REG_GP_ID_9		0x122
+#define	DA906X_REG_GP_ID_10		0x123
+#define	DA906X_REG_GP_ID_11		0x124
+#define	DA906X_REG_GP_ID_12		0x125
+#define	DA906X_REG_GP_ID_13		0x126
+#define	DA906X_REG_GP_ID_14		0x127
+#define	DA906X_REG_GP_ID_15		0x128
+#define	DA906X_REG_GP_ID_16		0x129
+#define	DA906X_REG_GP_ID_17		0x12A
+#define	DA906X_REG_GP_ID_18		0x12B
+#define	DA906X_REG_GP_ID_19		0x12C
+
+/* Chip ID and variant */
+#define	DA906X_REG_CHIP_ID		0x181
+#define	DA906X_REG_CHIP_VARIANT		0x182
+
+/*
+ * PMIC registers bits
+ */
+/* DA906X_REG_PAGE_CON (addr=0x00) */
+#define	DA906X_PEG_PAGE_SHIFT			0
+#define	DA906X_REG_PAGE_MASK			0x07
+#define		DA906X_REG_PAGE0		0x00
+#define		DA906X_REG_PAGE2		0x02
+#define	DA906X_PAGE_WRITE_MODE			0x00
+#define	DA906X_REPEAT_WRITE_MODE		0x40
+#define	DA906X_PAGE_REVERT			0x80
+
+/* DA906X_REG_STATUS_A (addr=0x01) */
+#define	DA906X_NONKEY				0x01
+#define	DA906X_WAKE				0x02
+#define	DA906X_DVC_BUSY				0x04
+#define	DA906X_COMP_1V2				0x08
+
+/* DA906X_REG_STATUS_B (addr=0x02) */
+#define	DA906X_GPI0				0x01
+#define	DA906X_GPI1				0x02
+#define	DA906X_GPI2				0x04
+#define	DA906X_GPI3				0x08
+#define	DA906X_GPI4				0x10
+#define	DA906X_GPI5				0x20
+#define	DA906X_GPI6				0x40
+#define	DA906X_GPI7				0x80
+
+/* DA906X_REG_STATUS_C (addr=0x03) */
+#define	DA906X_GPI8				0x01
+#define	DA906X_GPI9				0x02
+#define	DA906X_GPI10				0x04
+#define	DA906X_GPI11				0x08
+#define	DA906X_GPI12				0x10
+#define	DA906X_GPI13				0x20
+#define	DA906X_GPI14				0x40
+#define	DA906X_GPI15				0x80
+
+/* DA906X_REG_STATUS_D (addr=0x04) */
+#define	DA906X_LDO3_LIM				0x08
+#define	DA906X_LDO4_LIM				0x10
+#define	DA906X_LDO7_LIM				0x20
+#define	DA906X_LDO8_LIM				0x40
+#define	DA906X_LDO11_LIM			0x80
+
+/* DA906X_REG_FAULT_LOG (addr=0x05) */
+#define	DA906X_TWD_ERROR			0x01
+#define	DA906X_POR				0x02
+#define	DA906X_VDD_FAULT			0x04
+#define	DA906X_VDD_START			0x08
+#define	DA906X_TEMP_CRIT			0x10
+#define	DA906X_KEY_RESET			0x20
+#define	DA906X_NSHUTDOWN			0x40
+#define	DA906X_WAIT_SHUT			0x80
+
+/* DA906X_REG_EVENT_A (addr=0x06) */
+#define	DA906X_E_NONKEY				0x01
+#define	DA906X_E_ALARM				0x02
+#define	DA906X_E_TICK				0x04
+#define	DA906X_E_ADC_RDY			0x08
+#define	DA906X_E_SEQ_RDY			0x10
+#define	DA906X_EVENTS_B				0x20
+#define	DA906X_EVENTS_C				0x40
+#define	DA906X_EVENTS_D				0x80
+
+/* DA906X_REG_EVENT_B (addr=0x07) */
+#define	DA906X_E_WAKE				0x01
+#define	DA906X_E_TEMP				0x02
+#define	DA906X_E_COMP_1V2			0x04
+#define	DA906X_E_LDO_LIM			0x08
+#define	DA906X_E_REG_UVOV			0x10
+#define	DA906X_E_DVC_RDY			0x20
+#define	DA906X_E_VDD_MON			0x40
+#define	DA906X_E_VDD_WARN			0x80
+
+/* DA906X_REG_EVENT_C (addr=0x08) */
+#define	DA906X_E_GPI0				0x01
+#define	DA906X_E_GPI1				0x02
+#define	DA906X_E_GPI2				0x04
+#define	DA906X_E_GPI3				0x08
+#define	DA906X_E_GPI4				0x10
+#define	DA906X_E_GPI5				0x20
+#define	DA906X_E_GPI6				0x40
+#define	DA906X_E_GPI7				0x80
+
+/* DA906X_REG_EVENT_D (addr=0x09) */
+#define	DA906X_E_GPI8				0x01
+#define	DA906X_E_GPI9				0x02
+#define	DA906X_E_GPI10				0x04
+#define	DA906X_E_GPI11				0x08
+#define	DA906X_E_GPI12				0x10
+#define	DA906X_E_GPI13				0x20
+#define	DA906X_E_GPI14				0x40
+#define	DA906X_E_GPI15				0x80
+
+/* DA906X_REG_IRQ_MASK_A (addr=0x0A) */
+#define	DA906X_M_ONKEY				0x01
+#define	DA906X_M_ALARM				0x02
+#define	DA906X_M_TICK				0x04
+#define	DA906X_M_ADC_RDY			0x08
+#define	DA906X_M_SEQ_RDY			0x10
+
+/* DA906X_REG_IRQ_MASK_B (addr=0x0B) */
+#define	DA906X_M_WAKE				0x01
+#define	DA906X_M_TEMP				0x02
+#define	DA906X_M_COMP_1V2			0x04
+#define	DA906X_M_LDO_LIM			0x08
+#define	DA906X_M_UVOV				0x10
+#define	DA906X_M_DVC_RDY			0x20
+#define	DA906X_M_VDD_MON			0x40
+#define	DA906X_M_VDD_WARN			0x80
+
+/* DA906X_REG_IRQ_MASK_C (addr=0x0C) */
+#define	DA906X_M_GPI0				0x01
+#define	DA906X_M_GPI1				0x02
+#define	DA906X_M_GPI2				0x04
+#define	DA906X_M_GPI3				0x08
+#define	DA906X_M_GPI4				0x10
+#define	DA906X_M_GPI5				0x20
+#define	DA906X_M_GPI6				0x40
+#define	DA906X_M_GPI7				0x80
+
+/* DA906X_REG_IRQ_MASK_D (addr=0x0D) */
+#define	DA906X_M_GPI8				0x01
+#define	DA906X_M_GPI9				0x02
+#define	DA906X_M_GPI10				0x04
+#define	DA906X_M_GPI11				0x08
+#define	DA906X_M_GPI12				0x10
+#define	DA906X_M_GPI13				0x20
+#define	DA906X_M_GPI14				0x40
+#define	DA906X_M_GPI15				0x80
+
+/* DA906X_REG_CONTROL_A (addr=0x0E) */
+#define	DA906X_SYSTEM_EN			0x01
+#define	DA906X_POWER_EN				0x02
+#define	DA906X_POWER1_EN			0x04
+#define	DA906X_STANDBY				0x08
+#define	DA906X_M_SYSTEM_EN			0x10
+#define	DA906X_M_POWER_EN			0x20
+#define	DA906X_M_POWER1_EN			0x40
+#define	DA906X_CP_EN				0x80
+
+/* DA906X_REG_CONTROL_B (addr=0x0F) */
+#define	DA906X_CHG_SEL				0x01
+#define	DA906X_WATCHDOG_PD			0x02
+#define	DA906X_NRES_MODE			0x08
+#define	DA906X_NONKEY_LOCK			0x10
+
+/* DA906X_REG_CONTROL_C (addr=0x10) */
+#define	DA906X_DEBOUNCING_SHIFT			0
+#define	DA906X_DEBOUNCING_MASK			0x07
+#define		DA906X_DEBOUNCING_OFF		0x0
+#define		DA906X_DEBOUNCING_0MS1		0x1
+#define		DA906X_DEBOUNCING_1MS		0x2
+#define		DA906X_DEBOUNCING_10MS24	0x3
+#define		DA906X_DEBOUNCING_51MS2		0x4
+#define		DA906X_DEBOUNCING_256MS		0x5
+#define		DA906X_DEBOUNCING_512MS		0x6
+#define		DA906X_DEBOUNCING_1024MS	0x7
+
+#define	DA906X_AUTO_BOOT			0x08
+#define	DA906X_OTPREAD_EN			0x10
+#define	DA906X_SLEW_RATE_SHIFT			5
+#define	DA906X_SLEW_RATE_MASK			0x60
+#define		DA906X_SLEW_RATE_4US		0x00
+#define		DA906X_SLEW_RATE_3US		0x20
+#define		DA906X_SLEW_RATE_1US		0x40
+#define		DA906X_SLEW_RATE_0US5		0x60
+#define	DA906X_DEF_SUPPLY			0x80
+
+/* DA906X_REG_CONTROL_D (addr=0x11) */
+#define	DA906X_TWDSCALE_SHIFT			0
+#define	DA906X_TWDSCALE_MASK			0x07
+#define	DA906X_BLINK_FRQ_SHIFT			3
+#define	DA906X_BLINK_FRQ_MASK			0x38
+#define		DA906X_BLINK_FRQ_OFF		0x00
+#define		DA906X_BLINK_FRQ_1S0		0x08
+#define		DA906X_BLINK_FRQ_2S0		0x10
+#define		DA906X_BLINK_FRQ_4S0		0x18
+#define		DA906X_BLINK_FRQ_0S18		0x20
+#define		DA906X_BLINK_FRQ_2S0_VDD	0x28
+#define		DA906X_BLINK_FRQ_4S0_VDD	0x30
+#define		DA906X_BLINK_FRQ_0S18_VDD	0x38
+
+#define	DA906X_BLINK_DUR_SHIFT			6
+#define	DA906X_BLINK_DUR_MASK			0xC0
+#define		DA906X_BLINK_DUR_10MS		0x00
+#define		DA906X_BLINK_DUR_20MS		0x40
+#define		DA906X_BLINK_DUR_40MS		0x80
+#define		DA906X_BLINK_DUR_20MSDBL	0xC0
+
+/* DA906X_REG_CONTROL_E (addr=0x12) */
+#define	DA906X_RTC_MODE_PD			0x01
+#define	DA906X_RTC_MODE_SD			0x02
+#define	DA906X_RTC_EN				0x04
+#define	DA906X_ECO_MODE				0x08
+#define	DA906X_PM_FB1_PIN			0x10
+#define	DA906X_PM_FB2_PIN			0x20
+#define	DA906X_PM_FB3_PIN			0x40
+#define	DA906X_V_LOCK				0x80
+
+/* DA906X_REG_CONTROL_F (addr=0x13) */
+#define	DA906X_WATCHDOG				0x01
+#define	DA906X_SHUTDOWN				0x02
+#define	DA906X_WAKE_UP				0x04
+
+/* DA906X_REG_PD_DIS (addr=0x14) */
+#define	DA906X_GPI_DIS				0x01
+#define	DA906X_GPADC_PAUSE			0x02
+#define	DA906X_PMIF_DIS				0x04
+#define	DA906X_HS2WIRE_DIS			0x08
+#define	DA906X_BBAT_DIS				0x20
+#define	DA906X_OUT_32K_PAUSE			0x40
+#define	DA906X_PMCONT_DIS			0x80
+
+/* DA906X_REG_GPIO_0_1 (addr=0x15) */
+#define	DA906X_GPIO0_PIN_SHIFT			0
+#define	DA906X_GPIO0_PIN_MASK			0x03
+#define		DA906X_GPIO0_PIN_ADCIN1		0x00
+#define		DA906X_GPIO0_PIN_GPI		0x01
+#define		DA906X_GPIO0_PIN_GPO_OD		0x02
+#define		DA906X_GPIO0_PIN_GPO		0x03
+#define	DA906X_GPIO0_TYPE			0x04
+#define		DA906X_GPIO0_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO0_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO0_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO0_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO0_NO_WAKEUP			0x08
+#define	DA906X_GPIO1_PIN_SHIFT			4
+#define	DA906X_GPIO1_PIN_MASK			0x30
+#define		DA906X_GPIO1_PIN_ADCIN2_COMP	0x00
+#define		DA906X_GPIO1_PIN_GPI		0x10
+#define		DA906X_GPIO1_PIN_GPO_OD		0x20
+#define		DA906X_GPIO1_PIN_GPO		0x30
+#define	DA906X_GPIO1_TYPE			0x40
+#define		DA906X_GPIO1_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO1_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO1_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO1_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO1_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_2_3 (addr=0x16) */
+#define	DA906X_GPIO2_PIN_SHIFT			0
+#define	DA906X_GPIO2_PIN_MASK			0x03
+#define		DA906X_GPIO2_PIN_ADCIN3		0x00
+#define		DA906X_GPIO2_PIN_GPI		0x01
+#define		DA906X_GPIO2_PIN_GPO_PSS	0x02
+#define		DA906X_GPIO2_PIN_GPO		0x03
+#define	DA906X_GPIO2_TYPE			0x04
+#define		DA906X_GPIO2_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO2_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO2_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO2_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO2_NO_WAKEUP			0x08
+#define	DA906X_GPIO3_PIN_SHIFT			4
+#define	DA906X_GPIO3_PIN_MASK			0x30
+#define		DA906X_GPIO3_PIN_CORE_SW_G	0x00
+#define		DA906X_GPIO3_PIN_GPI		0x10
+#define		DA906X_GPIO3_PIN_GPO_OD		0x20
+#define		DA906X_GPIO3_PIN_GPO		0x30
+#define	DA906X_GPIO3_TYPE			0x40
+#define		DA906X_GPIO3_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO3_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO3_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO3_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO3_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_4_5 (addr=0x17) */
+#define	DA906X_GPIO4_PIN_SHIFT			0
+#define	DA906X_GPIO4_PIN_MASK			0x03
+#define		DA906X_GPIO4_PIN_CORE_SW_S	0x00
+#define		DA906X_GPIO4_PIN_GPI		0x01
+#define		DA906X_GPIO4_PIN_GPO_OD		0x02
+#define		DA906X_GPIO4_PIN_GPO		0x03
+#define	DA906X_GPIO4_TYPE			0x04
+#define		DA906X_GPIO4_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO4_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO4_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO4_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO4_NO_WAKEUP			0x08
+#define	DA906X_GPIO5_PIN_SHIFT			4
+#define	DA906X_GPIO5_PIN_MASK			0x30
+#define		DA906X_GPIO5_PIN_PERI_SW_G	0x00
+#define		DA906X_GPIO5_PIN_GPI		0x10
+#define		DA906X_GPIO5_PIN_GPO_OD		0x20
+#define		DA906X_GPIO5_PIN_GPO		0x30
+#define	DA906X_GPIO5_TYPE			0x40
+#define		DA906X_GPIO5_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO5_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO5_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO5_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO5_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_6_7 (addr=0x18) */
+#define	DA906X_GPIO6_PIN_SHIFT			0
+#define	DA906X_GPIO6_PIN_MASK			0x03
+#define		DA906X_GPIO6_PIN_PERI_SW_S	0x00
+#define		DA906X_GPIO6_PIN_GPI		0x01
+#define		DA906X_GPIO6_PIN_GPO_OD		0x02
+#define		DA906X_GPIO6_PIN_GPO		0x03
+#define	DA906X_GPIO6_TYPE			0x04
+#define		DA906X_GPIO6_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO6_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO6_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO6_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO6_NO_WAKEUP			0x08
+#define	DA906X_GPIO7_PIN_SHIFT			4
+#define	DA906X_GPIO7_PIN_MASK			0x30
+#define		DA906X_GPIO7_PIN_GPI		0x10
+#define		DA906X_GPIO7_PIN_GPO_PSS	0x20
+#define		DA906X_GPIO7_PIN_GPO		0x30
+#define	DA906X_GPIO7_TYPE			0x40
+#define		DA906X_GPIO7_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO7_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO7_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO7_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO7_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_8_9 (addr=0x19) */
+#define	DA906X_GPIO8_PIN_SHIFT			0
+#define	DA906X_GPIO8_PIN_MASK			0x03
+#define		DA906X_GPIO8_PIN_GPI_SYS_EN	0x00
+#define		DA906X_GPIO8_PIN_GPI		0x01
+#define		DA906X_GPIO8_PIN_GPO_PSS	0x02
+#define		DA906X_GPIO8_PIN_GPO		0x03
+#define	DA906X_GPIO8_TYPE			0x04
+#define		DA906X_GPIO8_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO8_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO8_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO8_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO8_NO_WAKEUP			0x08
+#define	DA906X_GPIO9_PIN_SHIFT			4
+#define	DA906X_GPIO9_PIN_MASK			0x30
+#define		DA906X_GPIO9_PIN_GPI_PWR_EN	0x00
+#define		DA906X_GPIO9_PIN_GPI		0x10
+#define		DA906X_GPIO9_PIN_GPO_PSS	0x20
+#define		DA906X_GPIO9_PIN_GPO		0x30
+#define	DA906X_GPIO9_TYPE			0x40
+#define		DA906X_GPIO9_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO9_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO9_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO9_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO9_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_10_11 (addr=0x1A) */
+#define	DA906X_GPIO10_PIN_SHIFT			0
+#define	DA906X_GPIO10_PIN_MASK			0x03
+#define		DA906X_GPIO10_PIN_GPI_PWR1_EN	0x00
+#define		DA906X_GPIO10_PIN_GPI		0x01
+#define		DA906X_GPIO10_PIN_GPO_OD	0x02
+#define		DA906X_GPIO10_PIN_GPO		0x03
+#define	DA906X_GPIO10_TYPE			0x04
+#define		DA906X_GPIO10_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO10_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO10_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO10_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO10_NO_WAKEUP			0x08
+#define	DA906X_GPIO11_PIN_SHIFT			4
+#define	DA906X_GPIO11_PIN_MASK			0x30
+#define		DA906X_GPIO11_PIN_GPO_OD	0x00
+#define		DA906X_GPIO11_PIN_GPI		0x10
+#define		DA906X_GPIO11_PIN_GPO_PSS	0x20
+#define		DA906X_GPIO11_PIN_GPO		0x30
+#define	DA906X_GPIO11_TYPE			0x40
+#define		DA906X_GPIO11_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO11_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO11_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO11_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO11_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_12_13 (addr=0x1B) */
+#define	DA906X_GPIO12_PIN_SHIFT			0
+#define	DA906X_GPIO12_PIN_MASK			0x03
+#define		DA906X_GPIO12_PIN_NVDDFLT_OUT	0x00
+#define		DA906X_GPIO12_PIN_GPI		0x01
+#define		DA906X_GPIO12_PIN_VSYSMON_OUT	0x02
+#define		DA906X_GPIO12_PIN_GPO		0x03
+#define	DA906X_GPIO12_TYPE			0x04
+#define		DA906X_GPIO12_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO12_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO12_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO12_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO12_NO_WAKEUP			0x08
+#define	DA906X_GPIO13_PIN_SHIFT			4
+#define	DA906X_GPIO13_PIN_MASK			0x30
+#define		DA906X_GPIO13_PIN_GPFB1_OUT	0x00
+#define		DA906X_GPIO13_PIN_GPI		0x10
+#define		DA906X_GPIO13_PIN_GPFB1_OUTOD	0x20
+#define		DA906X_GPIO13_PIN_GPO		0x30
+#define	DA906X_GPIO13_TYPE			0x40
+#define		DA906X_GPIO13_TYPE_GPFB1_OUT	0x00
+#define		DA906X_GPIO13_TYPE_GPI		0x00
+#define		DA906X_GPIO13_TYPE_GPFB1_OUTOD	0x04
+#define		DA906X_GPIO13_TYPE_GPO		0x04
+#define	DA906X_GPIO13_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_14_15 (addr=0x1C) */
+#define	DA906X_GPIO14_PIN_SHIFT			0
+#define	DA906X_GPIO14_PIN_MASK			0x03
+#define		DA906X_GPIO14_PIN_GPO_OD	0x00
+#define		DA906X_GPIO14_PIN_GPI		0x01
+#define		DA906X_GPIO14_PIN_HS2DATA	0x02
+#define		DA906X_GPIO14_PIN_GPO		0x03
+#define	DA906X_GPIO14_TYPE			0x04
+#define		DA906X_GPIO14_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO14_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO14_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO14_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO14_NO_WAKEUP			0x08
+#define	DA906X_GPIO15_PIN_SHIFT			4
+#define	DA906X_GPIO15_PIN_MASK			0x30
+#define		DA906X_GPIO15_PIN_GPO_OD	0x00
+#define		DA906X_GPIO15_PIN_GPI		0x10
+#define		DA906X_GPIO15_PIN_GPO		0x30
+#define	DA906X_GPIO15_TYPE			0x40
+#define		DA906X_GPIO15_TYPE_GPFB1_OUT	0x00
+#define		DA906X_GPIO15_TYPE_GPI		0x00
+#define		DA906X_GPIO15_TYPE_GPFB1_OUTOD	0x04
+#define		DA906X_GPIO15_TYPE_GPO		0x04
+#define	DA906X_GPIO15_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_MODE_0_7 (addr=0x1D) */
+#define	DA906X_GPIO0_MODE			0x01
+#define	DA906X_GPIO1_MODE			0x02
+#define	DA906X_GPIO2_MODE			0x04
+#define	DA906X_GPIO3_MODE			0x08
+#define	DA906X_GPIO4_MODE			0x10
+#define	DA906X_GPIO5_MODE			0x20
+#define	DA906X_GPIO6_MODE			0x40
+#define	DA906X_GPIO7_MODE			0x80
+
+/* DA906X_REG_GPIO_MODE_8_15 (addr=0x1E) */
+#define	DA906X_GPIO8_MODE			0x01
+#define	DA906X_GPIO9_MODE			0x02
+#define	DA906X_GPIO10_MODE			0x04
+#define	DA906X_GPIO11_MODE			0x08
+#define		DA906X_GPIO11_MODE_LED_ACT_HIGH	0x00
+#define		DA906X_GPIO11_MODE_LED_ACT_LOW	0x08
+#define	DA906X_GPIO12_MODE			0x10
+#define	DA906X_GPIO13_MODE			0x20
+#define	DA906X_GPIO14_MODE			0x40
+#define		DA906X_GPIO14_MODE_LED_ACT_HIGH	0x00
+#define		DA906X_GPIO14_MODE_LED_ACT_LOW	0x40
+#define	DA906X_GPIO15_MODE			0x80
+#define		DA906X_GPIO15_MODE_LED_ACT_HIGH	0x00
+#define		DA906X_GPIO15_MODE_LED_ACT_LOW	0x80
+
+/* DA906X_REG_SWITCH_CONT (addr=0x1F) */
+#define	DA906X_CORE_SW_GPI_SHIFT		0
+#define	DA906X_CORE_SW_GPI_MASK			0x03
+#define		DA906X_CORE_SW_GPI_OFF		0x00
+#define		DA906X_CORE_SW_GPI_GPIO1	0x01
+#define		DA906X_CORE_SW_GPI_GPIO2	0x02
+#define		DA906X_CORE_SW_GPI_GPIO13	0x03
+#define	DA906X_PERI_SW_GPI_SHIFT		2
+#define	DA906X_PERI_SW_GPI_MASK			0x0C
+#define		DA906X_PERI_SW_GPI_OFF		0x00
+#define		DA906X_PERI_SW_GPI_GPIO1	0x04
+#define		DA906X_PERI_SW_GPI_GPIO2	0x08
+#define		DA906X_PERI_SW_GPI_GPIO13	0x0C
+#define	DA906X_SWITCH_SR_SHIFT			4
+#define	DA906X_SWITCH_SR_MASK			0x30
+#define		DA906X_SWITCH_SR_1MV		0x00
+#define		DA906X_SWITCH_SR_5MV		0x10
+#define		DA906X_SWITCH_SR_10MV		0x20
+#define		DA906X_SWITCH_SR_50MV		0x30
+#define	DA906X_SWITCH_SR_DIS			0x40
+#define	DA906X_CP_EN_MODE			0x80
+
+/* DA906X_REGL_Bxxxx_CONT common bits (addr=0x20-0x25) */
+#define	DA906X_BUCK_EN				0x01
+#define	DA906X_BUCK_GPI_SHIFT			1
+#define DA906X_BUCK_GPI_MASK			0x06
+#define		DA906X_BUCK_GPI_OFF		0x00
+#define		DA906X_BUCK_GPI_GPIO1		0x02
+#define		DA906X_BUCK_GPI_GPIO2		0x04
+#define		DA906X_BUCK_GPI_GPIO13		0x06
+#define	DA906X_BUCK_CONF			0x08
+#define	DA906X_VBUCK_GPI_SHIFT			5
+#define	DA906X_VBUCK_GPI_MASK			0x60
+#define		DA906X_VBUCK_GPI_OFF		0x00
+#define		DA906X_VBUCK_GPI_GPIO1		0x20
+#define		DA906X_VBUCK_GPI_GPIO2		0x40
+#define		DA906X_VBUCK_GPI_GPIO13		0x60
+
+/* DA906X_REG_BCORE1_CONT specific bits (addr=0x21) */
+#define	DA906X_CORE_SW_EN			0x10
+#define	DA906X_CORE_SW_CONF			0x80
+
+/* DA906X_REG_BPERI_CONT specific bits (addr=0x25) */
+#define	DA906X_PERI_SW_EN			0x10
+#define	DA906X_PERI_SW_CONF			0x80
+
+/* DA906X_REG_LDOx_CONT common bits (addr=0x26-0x30) */
+#define	DA906X_LDO_EN				0x01
+#define	DA906X_LDO_GPI_SHIFT			1
+#define DA906X_LDO_GPI_MASK			0x06
+#define		DA906X_LDO_GPI_OFF		0x00
+#define		DA906X_LDO_GPI_GPIO1		0x02
+#define		DA906X_LDO_GPI_GPIO2		0x04
+#define		DA906X_LDO_GPI_GPIO13		0x06
+#define	DA906X_LDO_PD_DIS			0x08
+#define	DA906X_VLDO_GPI_SHIFT			5
+#define	DA906X_VLDO_GPI_MASK			0x60
+#define		DA906X_VLDO_GPI_OFF		0x00
+#define		DA906X_VLDO_GPI_GPIO1		0x20
+#define		DA906X_VLDO_GPI_GPIO2		0x40
+#define		DA906X_VLDO_GPI_GPIO13		0x60
+#define	DA906X_LDO_CONF				0x80
+
+/* DA906X_REG_LDO5_CONT specific bits (addr=0x2A) */
+#define	DA906X_VLDO5_SEL			0x10
+
+/* DA906X_REG_LDO6_CONT specific bits (addr=0x2B) */
+#define	DA906X_VLDO6_SEL			0x10
+
+/* DA906X_REG_LDO7_CONT specific bits (addr=0x2C) */
+#define	DA906X_VLDO7_SEL			0x10
+
+/* DA906X_REG_LDO8_CONT specific bits (addr=0x2D) */
+#define	DA906X_VLDO8_SEL			0x10
+
+/* DA906X_REG_LDO9_CONT specific bits (addr=0x2E) */
+#define	DA906X_VLDO9_SEL			0x10
+
+/* DA906X_REG_LDO10_CONT specific bits (addr=0x2F) */
+#define	DA906X_VLDO10_SEL			0x10
+
+/* DA906X_REG_LDO11_CONT specific bits (addr=0x30) */
+#define	DA906X_VLDO11_SEL			0x10
+
+/* DA906X_REG_VIB (addr=0x31) */
+#define DA906X_VIB_SET_MASK			0x3F
+#define		DA906X_VIB_SET_OFF		0
+#define		DA906X_VIB_SET_MAX		0x3F
+
+/* DA906X_REG_DVC_1 (addr=0x32) */
+#define	DA906X_VBCORE1_SEL			0x01
+#define	DA906X_VBCORE2_SEL			0x02
+#define	DA906X_VBPRO_SEL			0x04
+#define	DA906X_VBMEM_SEL			0x08
+#define	DA906X_VBPERI_SEL			0x10
+#define	DA906X_VLDO1_SEL			0x20
+#define	DA906X_VLDO2_SEL			0x40
+#define	DA906X_VLDO3_SEL			0x80
+
+/* DA906X_REG_DVC_2 (addr=0x33) */
+#define	DA906X_VBIO_SEL				0x01
+#define	DA906X_VLDO4_SEL			0x80
+
+/* DA906X_REG_ADC_MAN (addr=0x34) */
+#define	DA906X_ADC_MUX_SHIFT			0
+#define	DA906X_ADC_MUX_MASK			0x0F
+#define		DA906X_ADC_MUX_VSYS		0x00
+#define		DA906X_ADC_MUX_ADCIN1		0x01
+#define		DA906X_ADC_MUX_ADCIN2		0x02
+#define		DA906X_ADC_MUX_ADCIN3		0x03
+#define		DA906X_ADC_MUX_T_SENSE		0x04
+#define		DA906X_ADC_MUX_VBBAT		0x05
+#define		DA906X_ADC_MUX_LDO_G1		0x08
+#define		DA906X_ADC_MUX_LDO_G2		0x09
+#define		DA906X_ADC_MUX_LDO_G3		0x0A
+#define	DA906X_ADC_MAN				0x10
+#define	DA906X_ADC_MODE				0x20
+
+/* DA906X_REG_ADC_CONT (addr=0x35) */
+#define	DA906X_ADC_AUTO_VSYS_EN			0x01
+#define	DA906X_ADC_AUTO_AD1_EN			0x02
+#define	DA906X_ADC_AUTO_AD2_EN			0x04
+#define	DA906X_ADC_AUTO_AD3_EN			0x08
+#define	DA906X_ADC_AD1_ISRC_EN			0x10
+#define	DA906X_ADC_AD2_ISRC_EN			0x20
+#define	DA906X_ADC_AD3_ISRC_EN			0x40
+#define	DA906X_COMP1V2_EN			0x80
+
+/* DA906X_REG_VSYS_MON (addr=0x36) */
+#define	DA906X_VSYS_VAL_SHIFT			0
+#define	DA906X_VSYS_VAL_MASK			0xFF
+#define	DA906X_VSYS_VAL_BASE			0x00
+
+/* DA906X_REG_ADC_RES_L (addr=0x37) */
+#define	DA906X_ADC_RES_L_SHIFT			6
+#define	DA906X_ADC_RES_L_BITS			2
+#define	DA906X_ADC_RES_L_MASK			0xC0
+
+/* DA906X_REG_ADC_RES_H (addr=0x38) */
+#define	DA906X_ADC_RES_M_SHIFT			0
+#define	DA906X_ADC_RES_M_BITS			8
+#define	DA906X_ADC_RES_M_MASK			0xFF
+
+/* DA906X_REG_(xxx_RES/ADC_RES_H) (addr=0x39-0x3F) */
+#define	DA906X_ADC_VAL_SHIFT			0
+#define	DA906X_ADC_VAL_MASK			0xFF
+
+/* DA906X_REG_COUNT_S (addr=0x40) */
+#define DA906X_RTC_READ				0x80
+#define DA906X_COUNT_SEC_MASK			0x3F
+
+/* DA906X_REG_COUNT_MI (addr=0x41) */
+#define DA906X_COUNT_MIN_MASK			0x3F
+
+/* DA906X_REG_COUNT_H (addr=0x42) */
+#define DA906X_COUNT_HOUR_MASK			0x1F
+
+/* DA906X_REG_COUNT_D (addr=0x43) */
+#define DA906X_COUNT_DAY_MASK			0x1F
+
+/* DA906X_REG_COUNT_MO (addr=0x44) */
+#define DA906X_COUNT_MONTH_MASK			0x0F
+
+/* DA906X_REG_COUNT_Y (addr=0x45) */
+#define DA906X_COUNT_YEAR_MASK			0x3F
+#define DA906X_MONITOR				0x40
+
+/* DA906X_REG_ALARM_MI (addr=0x46) */
+#define DA906X_ALARM_STATUS_ALARM		0x80
+#define DA906X_ALARM_STATUS_TICK		0x40
+#define DA906X_ALARM_MIN_MASK			0x3F
+
+/* DA906X_REG_ALARM_H (addr=0x47) */
+#define DA906X_ALARM_HOUR_MASK			0x1F
+
+/* DA906X_REG_ALARM_D (addr=0x48) */
+#define DA906X_ALARM_DAY_MASK			0x1F
+
+/* DA906X_REG_ALARM_MO (addr=0x49) */
+#define DA906X_TICK_WAKE			0x20
+#define DA906X_TICK_TYPE			0x10
+#define		DA906X_TICK_TYPE_SEC		0x00
+#define		DA906X_TICK_TYPE_MIN		0x10
+#define DA906X_ALARM_MONTH_MASK			0x0F
+
+/* DA906X_REG_ALARM_Y (addr=0x4A) */
+#define DA906X_TICK_ON				0x80
+#define DA906X_ALARM_ON				0x40
+#define DA906X_ALARM_YEAR_MASK			0x3F
+
+/* DA906X_REG_WAIT (addr=0x97)*/
+#define	DA906X_REG_WAIT_TIME_SHIFT		0
+#define	DA906X_REG_WAIT_TIME_MASK		0xF
+#define	DA906X_WAIT_TIME_0_US			0x0
+#define	DA906X_WAIT_TIME_512_US			0x1
+#define	DA906X_WAIT_TIME_1_MS			0x2
+#define	DA906X_WAIT_TIME_2_MS			0x3
+#define	DA906X_WAIT_TIME_4_1_MS			0x4
+#define	DA906X_WAIT_TIME_8_2_MS			0x5
+#define	DA906X_WAIT_TIME_16_4_MS		0x6
+#define	DA906X_WAIT_TIME_32_8_MS		0x7
+#define	DA906X_WAIT_TIME_65_5_MS		0x8
+#define	DA906X_WAIT_TIME_128_MS			0x9
+#define	DA906X_WAIT_TIME_256_MS			0xA
+#define	DA906X_WAIT_TIME_512_MS			0xB
+#define	DA906X_WAIT_TIME_1_S			0xC
+#define	DA906X_WAIT_TIME_2_1_S			0xD
+
+/* DA906X_REG_EN_32K  (addr=0x98)*/
+#define	DA906X_STABILIZ_TIME_SHIFT		0
+#define	DA906X_STABILIZ_TIME_MASK		0x7
+#define	DA906X_CRYSTAL				0x08
+#define	DA906X_DELAY_MODE			0x10
+#define	DA906X_OUT_CLOCK			0x20
+#define	DA906X_RTC_CLOCK			0x40
+#define	DA906X_OUT_32K_EN			0x80
+
+/* DA906X_REG_CHIP_VARIANT */
+#define	DA906X_CHIP_VARIANT_SHIFT		4
+
+/* DA906X_REG_BUCK_ILIM_A (addr=0x9A) */
+#define DA906X_BIO_ILIM_SHIFT			0
+#define DA906X_BIO_ILIM_MASK			0x0F
+#define DA906X_BMEM_ILIM_SHIFT			4
+#define DA906X_BMEM_ILIM_MASK			0x0F
+
+/* DA906X_REG_BUCK_ILIM_B (addr=0x9B) */
+#define DA906X_BPRO_ILIM_SHIFT			0
+#define DA906X_BPRO_ILIM_MASK			0x0F
+#define DA906X_BPERI_ILIM_SHIFT			4
+#define DA906X_BPERI_ILIM_MASK			0x0F
+
+/* DA906X_REG_BUCK_ILIM_C (addr=0x9C) */
+#define DA906X_BCORE1_ILIM_SHIFT		0
+#define DA906X_BCORE1_ILIM_MASK			0x0F
+#define DA906X_BCORE2_ILIM_SHIFT		4
+#define DA906X_BCORE2_ILIM_MASK			0x0F
+
+/* DA906X_REG_Bxxxx_CFG common bits (addr=0x9D-0xA2) */
+#define DA906X_BUCK_FB_MASK			0x07
+#define DA906X_BUCK_PD_DIS_SHIFT		5
+#define DA906X_BUCK_MODE_SHIFT			6
+#define DA906X_BUCK_MODE_MASK			0xC0
+#define		DA906X_BUCK_MODE_MANUAL		0x00
+#define		DA906X_BUCK_MODE_SLEEP		0x40
+#define		DA906X_BUCK_MODE_SYNC		0x80
+#define		DA906X_BUCK_MODE_AUTO		0xC0
+
+/* DA906X_REG_BPRO_CFG (addr=0x9F) */
+#define	DA906X_BPRO_VTTR_EN			0x08
+#define	DA906X_BPRO_VTT_EN			0x10
+
+/* DA906X_REG_VBxxxx_A/B (addr=0xA3-0xA8, 0xB4-0xB9) */
+#define DA906X_VBUCK_SHIFT			0
+#define DA906X_VBUCK_MASK			0x7F
+#define DA906X_VBUCK_BIAS			0
+#define DA906X_BUCK_SL				0x80
+
+/* DA906X_REG_VLDOx_A/B (addr=0xA9-0x3, 0xBA-0xC4) */
+#define DA906X_LDO_SL				0x80
+
+/* DA906X_REG_VLDO1_A/B (addr=0xA9, 0xBA) */
+#define DA906X_VLDO1_MASK			0x3F
+#define DA906X_VLDO1_SHIFT			0
+#define DA906X_VLDO1_BIAS			0
+
+/* DA906X_REG_VLDO2_A/B (addr=0xAA, 0xBB) */
+#define DA906X_VLDO2_MASK			0x3F
+#define DA906X_VLDO2_SHIFT			0
+#define DA906X_VLDO2_BIAS			0
+
+/* DA906X_REG_VLDO3_A/B (addr=0xAB, 0xBC) */
+#define DA906X_VLDO3_MASK			0x7F
+#define DA906X_VLDO3_SHIFT			0
+#define DA906X_VLDO3_BIAS			0
+
+/* DA906X_REG_VLDO4_A/B (addr=0xAC, 0xBD) */
+#define DA906X_VLDO4_MASK			0x7F
+#define DA906X_VLDO4_SHIFT			0
+#define DA906X_VLDO4_BIAS			0
+
+/* DA906X_REG_VLDO5_A/B (addr=0xAD, 0xBE) */
+#define DA906X_VLDO5_MASK			0x3F
+#define DA906X_VLDO5_SHIFT			0
+#define DA906X_VLDO5_BIAS			2
+
+/* DA906X_REG_VLDO6_A/B (addr=0xAE, 0xBF) */
+#define DA906X_VLDO6_MASK			0x3F
+#define DA906X_VLDO6_SHIFT			0
+#define DA906X_VLDO6_BIAS			2
+
+/* DA906X_REG_VLDO7_A/B (addr=0xAF, 0xC0) */
+#define DA906X_VLDO7_MASK			0x3F
+#define DA906X_VLDO7_SHIFT			0
+#define DA906X_VLDO7_BIAS			2
+
+/* DA906X_REG_VLDO8_A/B (addr=0xB0, 0xC1) */
+#define DA906X_VLDO8_MASK			0x3F
+#define DA906X_VLDO8_SHIFT			0
+#define DA906X_VLDO8_BIAS			2
+
+/* DA906X_REG_VLDO9_A/B (addr=0xB1, 0xC2) */
+#define DA906X_VLDO9_MASK			0x3F
+#define DA906X_VLDO9_SHIFT			0
+#define DA906X_VLDO9_BIAS			3
+
+/* DA906X_REG_VLDO10_A/B (addr=0xB2, 0xC3) */
+#define DA906X_VLDO10_MASK			0x3F
+#define DA906X_VLDO10_SHIFT			0
+#define DA906X_VLDO10_BIAS			2
+
+/* DA906X_REG_VLDO11_A/B (addr=0xB3, 0xC4) */
+#define DA906X_VLDO11_MASK			0x3F
+#define DA906X_VLDO11_SHIFT			0
+#define DA906X_VLDO11_BIAS			2
+
+/* DA906X_REG_GPO11_LED (addr=0xC6) */
+/* DA906X_REG_GPO14_LED (addr=0xC7) */
+/* DA906X_REG_GPO15_LED (addr=0xC8) */
+#define DA906X_GPIO_DIM				0x80
+#define DA906X_GPIO_PWM_SHIFT			0
+#define DA906X_GPIO_PWM_MASK			0x7F
+
+/* DA906X_REG_CONFIG_H (addr=0x10D) */
+#define DA906X_PWM_CLK_MASK			0x01
+#define		DA906X_PWM_CLK_PWM2MHZ		0x00
+#define		DA906X_PWM_CLK_PWM1MHZ		0x01
+#define DA906X_LDO8_MODE_MASK			0x02
+#define		DA906X_LDO8_MODE_LDO		0
+#define		DA906X_LDO8_MODE_VIBR		0x02
+#define DA906X_MERGE_SENSE_MASK			0x04
+#define 	DA906X_MERGE_SENSE_GP_FB2	0x00
+#define 	DA906X_MERGE_SENSE_GPIO4	0x04
+#define DA906X_BCORE_MERGE			0x08
+#define DA906X_BPRO_OD				0x10
+#define DA906X_BCORE2_OD			0x20
+#define DA906X_BCORE1_OD			0x40
+#define DA906X_BUCK_MERGE			0x80
+
+/* DA906X_REG_CONFIG_I (addr=0x10E) */
+#define DA906X_NONKEY_PIN_MASK			0x03
+#define		DA906X_NONKEY_PIN_PORT		0x00
+#define		DA906X_NONKEY_PIN_SWDOWN	0x01
+#define		DA906X_NONKEY_PIN_AUTODOWN	0x02
+#define		DA906X_NONKEY_PIN_AUTOFLPRT	0x03
+
+/* DA906X_REG_MON_REG_5 (addr=0x116) */
+#define DA906X_MON_A8_IDX_SHIFT			0
+#define DA906X_MON_A8_IDX_MASK			0x07
+#define		DA9063_MON_A8_IDX_NONE		0x00
+#define		DA9063_MON_A8_IDX_BCORE1	0x01
+#define		DA9063_MON_A8_IDX_BCORE2	0x02
+#define		DA9063_MON_A8_IDX_BPRO		0x03
+#define		DA9063_MON_A8_IDX_LDO3		0x04
+#define		DA9063_MON_A8_IDX_LDO4		0x05
+#define		DA9063_MON_A8_IDX_LDO11		0x06
+#define DA906X_MON_A9_IDX_SHIFT			4
+#define DA906X_MON_A9_IDX_MASK			0x70
+#define		DA9063_MON_A9_IDX_NONE		0x00
+#define		DA9063_MON_A9_IDX_BIO		0x01
+#define		DA9063_MON_A9_IDX_BMEM		0x02
+#define		DA9063_MON_A9_IDX_BPERI		0x03
+#define		DA9063_MON_A9_IDX_LDO1		0x04
+#define		DA9063_MON_A9_IDX_LDO2		0x05
+#define		DA9063_MON_A9_IDX_LDO5		0x06
+
+/* DA906X_REG_MON_REG_6 (addr=0x117) */
+#define DA906X_MON_A10_IDX_SHIFT		0
+#define DA906X_MON_A10_IDX_MASK			0x07
+#define		DA9063_MON_A10_IDX_NONE		0x00
+#define		DA9063_MON_A10_IDX_LDO6		0x01
+#define		DA9063_MON_A10_IDX_LDO7		0x02
+#define		DA9063_MON_A10_IDX_LDO8		0x03
+#define		DA9063_MON_A10_IDX_LDO9		0x04
+#define		DA9063_MON_A10_IDX_LDO10	0x05
+
+#endif /* _DA906X_REG_H */
+
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [lm-sensors] [PATCH 3/8] rtc: Add RTC driver for DA906x PMIC.
@ 2012-08-24  8:32       ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24  8:32 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie, Bryan Wu, Liam Girdwood

DA906x RTC driver supports date/time and alarm.

In hardware, PMIC supports alarm setting with a resolution of one minute and
tick event (every second update event). The driver combines it, providing alarm
with one second resolution.

The driver requires MFD core driver for operation.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/rtc/Kconfig      |    7 +
 drivers/rtc/Makefile     |    1 +
 drivers/rtc/rtc-da906x.c |  379 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 387 insertions(+), 0 deletions(-)
 create mode 100644 drivers/rtc/rtc-da906x.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index fabc99a..e6037cd 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -571,6 +571,13 @@ config RTC_DRV_DA9052
 	  Say y here to support the RTC driver for Dialog Semiconductor
 	  DA9052-BC and DA9053-AA/Bx PMICs.
 
+config RTC_DRV_DA906X
+	tristate "Dialog DA906X RTC"
+	depends on MFD_DA906X
+	help
+	  Say y here to support the RTC driver for
+	  Dialog Semiconductor DA906x PMIC.
+
 config RTC_DRV_EFI
 	tristate "EFI RTC"
 	depends on IA64
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 0d5b2b6..d9c1e9f 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_RTC_DRV_BQ4802)	+= rtc-bq4802.o
 obj-$(CONFIG_RTC_DRV_CMOS)	+= rtc-cmos.o
 obj-$(CONFIG_RTC_DRV_COH901331)	+= rtc-coh901331.o
 obj-$(CONFIG_RTC_DRV_DA9052)	+= rtc-da9052.o
+obj-$(CONFIG_RTC_DRV_DA906X)	+= rtc-da906x.o
 obj-$(CONFIG_RTC_DRV_DAVINCI)	+= rtc-davinci.o
 obj-$(CONFIG_RTC_DRV_DM355EVM)	+= rtc-dm355evm.o
 obj-$(CONFIG_RTC_DRV_VRTC)	+= rtc-mrst.o
diff --git a/drivers/rtc/rtc-da906x.c b/drivers/rtc/rtc-da906x.c
new file mode 100644
index 0000000..0b4fecc
--- /dev/null
+++ b/drivers/rtc/rtc-da906x.c
@@ -0,0 +1,379 @@
+/*
+ * Real Time Clock driver for DA906x PMIC family
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/init.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/rtc.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/mfd/da906x/registers.h>
+#include <linux/mfd/da906x/core.h>
+
+#define YEARS_TO_DA906X(year)		((year) - 100)
+#define MONTHS_TO_DA906X(month)		((month) + 1)
+#define YEARS_FROM_DA906X(year)		((year) + 100)
+#define MONTHS_FROM_DA906X(month)	((month) - 1)
+
+#define CLOCK_DATA_LEN	(DA906X_REG_COUNT_Y - DA906X_REG_COUNT_S + 1)
+#define ALARM_DATA_LEN	(DA906X_REG_ALARM_Y - DA906X_REG_ALARM_MI + 1)
+enum {
+	DATA_SEC = 0,
+	DATA_MIN,
+	DATA_HOUR,
+	DATA_DAY,
+	DATA_MONTH,
+	DATA_YEAR,
+};
+
+struct da906x_rtc {
+	struct rtc_device	*rtc_dev;
+	struct da906x		*hw;
+	int			irq_alarm;
+	int			irq_tick;
+
+	/* Config flag */
+	int			tick_wake;
+
+	/* Used to expand alarm precision from minutes up to seconds
+	   using hardware ticks */
+	unsigned int		alarmSecs;
+	unsigned int		alarmTicks;
+};
+
+static void da906x_data_to_tm(u8 *data, struct rtc_time *tm)
+{
+	tm->tm_sec = data[DATA_SEC] & DA906X_COUNT_SEC_MASK;
+	tm->tm_min = data[DATA_MIN] & DA906X_COUNT_MIN_MASK;
+	tm->tm_hour = data[DATA_HOUR] & DA906X_COUNT_HOUR_MASK;
+	tm->tm_mday = data[DATA_DAY] & DA906X_COUNT_DAY_MASK;
+	tm->tm_mon = MONTHS_FROM_DA906X(data[DATA_MONTH] &
+					 DA906X_COUNT_MONTH_MASK);
+	tm->tm_year = YEARS_FROM_DA906X(data[DATA_YEAR] &
+					 DA906X_COUNT_YEAR_MASK);
+}
+
+static void da906x_tm_to_data(struct rtc_time *tm, u8 *data)
+{
+	data[DATA_SEC] &= ~DA906X_COUNT_SEC_MASK;
+	data[DATA_SEC] |= tm->tm_sec & DA906X_COUNT_SEC_MASK;
+	data[DATA_MIN] &= ~DA906X_COUNT_MIN_MASK;
+	data[DATA_MIN] |= tm->tm_min & DA906X_COUNT_MIN_MASK;
+	data[DATA_HOUR] &= ~DA906X_COUNT_HOUR_MASK;
+	data[DATA_HOUR] |= tm->tm_hour & DA906X_COUNT_HOUR_MASK;
+	data[DATA_DAY] &= ~DA906X_COUNT_DAY_MASK;
+	data[DATA_DAY] |= tm->tm_mday & DA906X_COUNT_DAY_MASK;
+	data[DATA_MONTH] &= ~DA906X_COUNT_MONTH_MASK;
+	data[DATA_MONTH] |= MONTHS_TO_DA906X(tm->tm_mon) &
+			    DA906X_COUNT_MONTH_MASK;
+	data[DATA_YEAR] &= ~DA906X_COUNT_YEAR_MASK;
+	data[DATA_YEAR] |= YEARS_TO_DA906X(tm->tm_year) &
+			   DA906X_COUNT_YEAR_MASK;
+}
+
+#define DA906X_ALARM_DELAY	INT_MAX
+static int da906x_rtc_test_delay(struct rtc_time *alarm, struct rtc_time *cur)
+{
+	unsigned long a_time, c_time;
+
+	rtc_tm_to_time(alarm, &a_time);
+	rtc_tm_to_time(cur, &c_time);
+
+	/* Alarm time has already passed */
+	if (a_time < c_time)
+		return -1;
+
+	/* If alarm is set for current minute, return ticks to count down.
+	   If alarm is set for following minutes, return DA906X_ALARM_DELAY
+	   to set alarm first.
+	   But when it is less than 2 seconds for the former to become true,
+	   return ticks, because alarm needs some time to synchronise. */
+	if (a_time - c_time < alarm->tm_sec + 2)
+		return a_time - c_time;
+	else
+		return DA906X_ALARM_DELAY;
+}
+
+static int da906x_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN];
+	int ret;
+
+	ret = da906x_block_read(rtc->hw,
+				DA906X_REG_COUNT_S, CLOCK_DATA_LEN, data);
+	if (ret < 0)
+		return ret;
+
+	/* Check, if RTC logic is initialised */
+	if (!(data[DATA_SEC] & DA906X_RTC_READ))
+		return -EBUSY;
+
+	da906x_data_to_tm(data, tm);
+
+	return rtc_valid_tm(tm);
+}
+
+static int da906x_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN] = { [0 ... (CLOCK_DATA_LEN - 1)] = 0 };
+	int ret;
+
+	da906x_tm_to_data(tm, data);
+
+	ret = da906x_block_write(rtc->hw,
+				 DA906X_REG_COUNT_S, CLOCK_DATA_LEN, data);
+
+	return ret;
+}
+
+static int da906x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN];
+	int ret;
+
+	ret = da906x_block_read(rtc->hw, DA906X_REG_ALARM_MI, ALARM_DATA_LEN,
+				&data[DATA_MIN]);
+	if (ret < 0)
+		return ret;
+
+	da906x_data_to_tm(data, &alrm->time);
+	alrm->time.tm_sec = rtc->alarmSecs;
+	alrm->enabled = !!(data[DATA_YEAR] & DA906X_ALARM_ON);
+
+	/* If there is no ticks left to count down and RTC event is
+	   not processed yet, indicate pending */
+	if (rtc->alarmTicks = 0) {
+		ret = da906x_reg_read(rtc->hw, DA906X_REG_EVENT_A);
+		if (ret < 0)
+			return ret;
+		if (ret & (DA906X_E_ALARM | DA906X_E_TICK))
+			alrm->pending = 1;
+	} else {
+		alrm->pending = 0;
+	}
+
+	return 0;
+}
+
+static int da906x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN] = { [0 ... (CLOCK_DATA_LEN - 1)] = 0 };
+	struct rtc_time cur_tm;
+	int cmp_val;
+	int ret;
+
+	data[DATA_MIN] = DA906X_ALARM_STATUS_ALARM;
+	data[DATA_MONTH] = DA906X_TICK_TYPE_SEC;
+	if (rtc->tick_wake)
+		data[DATA_MONTH] |= DA906X_TICK_WAKE;
+
+	ret = da906x_rtc_read_time(dev, &cur_tm);
+	if (ret < 0)
+		return ret;
+
+	if (alrm->enabled) {
+		cmp_val = da906x_rtc_test_delay(&alrm->time, &cur_tm);
+		if (cmp_val = DA906X_ALARM_DELAY) {
+			/* Set alarm for longer delay */
+			data[DATA_YEAR] |= DA906X_ALARM_ON;
+		} else if (cmp_val > 0) {
+			/* Count ticks for shorter delay */
+			rtc->alarmTicks = cmp_val - 1;
+			data[DATA_YEAR] |= DA906X_TICK_ON;
+		} else if (cmp_val = 0) {
+			/* Just about time - report event */
+			rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF);
+		}
+	}
+
+	da906x_tm_to_data(&alrm->time, data);
+	rtc->alarmSecs = alrm->time.tm_sec;
+
+	return da906x_block_write(rtc->hw, DA906X_REG_ALARM_MI, ALARM_DATA_LEN,
+				 &data[DATA_MIN]);
+}
+
+static int da906x_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	struct rtc_wkalrm alrm;
+	int ret;
+
+	ret = da906x_reg_read(rtc->hw, DATA_YEAR);
+	if (ret < 0)
+		return ret;
+
+	if (enabled) {
+		/* Enable alarm, if it is not enabled already */
+		if (!(ret & (DA906X_ALARM_ON | DA906X_TICK_ON))) {
+			ret = da906x_rtc_read_alarm(dev, &alrm);
+			if (ret < 0)
+				return ret;
+
+			alrm.enabled = 1;
+			ret = da906x_rtc_set_alarm(dev, &alrm);
+		}
+	} else {
+		ret = da906x_reg_clear_bits(rtc->hw, DA906X_REG_ALARM_Y,
+					    DA906X_ALARM_ON);
+	}
+
+	return ret;
+}
+
+/* On alarm interrupt, start to count ticks to enable seconds precision
+   (if alarm seconds != 0). */
+static irqreturn_t da906x_alarm_event(int irq, void *data)
+{
+	struct da906x_rtc *rtc = data;
+
+	if (rtc->alarmSecs) {
+		rtc->alarmTicks = rtc->alarmSecs - 1;
+		da906x_reg_update(rtc->hw, DA906X_REG_ALARM_Y,
+				  DA906X_ALARM_ON | DA906X_TICK_ON,
+				  DA906X_TICK_ON);
+	} else {
+		da906x_reg_clear_bits(rtc->hw, DA906X_REG_ALARM_Y,
+				      DA906X_ALARM_ON);
+		rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF);
+	}
+
+	return IRQ_HANDLED;
+}
+
+/* On tick interrupt, count down seconds left to timeout */
+static irqreturn_t da906x_tick_event(int irq, void *data)
+{
+	struct da906x_rtc *rtc = data;
+
+	if (rtc->alarmTicks-- = 0) {
+		da906x_reg_clear_bits(rtc->hw,
+				      DA906X_REG_ALARM_Y, DA906X_TICK_ON);
+		rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_UF);
+	}
+
+	return IRQ_HANDLED;
+}
+
+static const struct rtc_class_ops da906x_rtc_ops = {
+	.read_time = da906x_rtc_read_time,
+	.set_time = da906x_rtc_set_time,
+	.read_alarm = da906x_rtc_read_alarm,
+	.set_alarm = da906x_rtc_set_alarm,
+	.alarm_irq_enable = da906x_rtc_alarm_irq_enable,
+};
+
+static __devinit int da906x_rtc_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_rtc *rtc;
+	int ret;
+	int alarm_mo;
+
+	/* Enable RTC hardware */
+	ret = da906x_reg_set_bits(da906x, DA906X_REG_CONTROL_E, DA906X_RTC_EN);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to enable RTC.\n");
+		return ret;
+	}
+
+	ret = da906x_reg_set_bits(da906x, DA906X_REG_EN_32K, DA906X_CRYSTAL);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to run 32 KHz OSC.\n");
+		return ret;
+	}
+
+	ret = da906x_reg_read(da906x, DA906X_REG_ALARM_MO);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to read RTC register.\n");
+		return ret;
+	}
+	alarm_mo = ret;
+
+	/* Register RTC device */
+	rtc = devm_kzalloc(&pdev->dev, sizeof *rtc, GFP_KERNEL);
+	if (!rtc)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, rtc);
+
+	rtc->hw = da906x;
+	rtc->rtc_dev = rtc_device_register(DA906X_DRVNAME_RTC, &pdev->dev,
+					   &da906x_rtc_ops, THIS_MODULE);
+	if (IS_ERR(rtc->rtc_dev)) {
+		dev_err(&pdev->dev, "Failed to register RTC device: %ld\n",
+			PTR_ERR(rtc->rtc_dev));
+		return PTR_ERR(rtc->rtc_dev);
+	}
+
+	if (alarm_mo & DA906X_TICK_WAKE)
+		rtc->tick_wake = 1;
+
+	/* Register interrupts. Complain on errors but let device
+	   to be registered at least for date/time. */
+	rtc->irq_alarm = platform_get_irq_byname(pdev, "ALARM");
+	ret = request_threaded_irq(rtc->irq_alarm, NULL, da906x_alarm_event,
+				IRQF_TRIGGER_LOW | IRQF_ONESHOT, "ALARM", rtc);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request ALARM IRQ.\n");
+		rtc->irq_alarm = -ENXIO;
+		return 0;
+	}
+
+	rtc->irq_tick = platform_get_irq_byname(pdev, "TICK");
+	ret = request_threaded_irq(rtc->irq_tick, NULL, da906x_tick_event,
+			IRQF_TRIGGER_RISING | IRQF_ONESHOT, "TICK", rtc);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request TICK IRQ.\n");
+		rtc->irq_tick = -ENXIO;
+	}
+
+	return 0;
+}
+
+static int __devexit da906x_rtc_remove(struct platform_device *pdev)
+{
+	struct da906x_rtc *rtc = platform_get_drvdata(pdev);
+
+	if (rtc->irq_alarm >= 0)
+		free_irq(rtc->irq_alarm, rtc);
+
+	if (rtc->irq_tick >= 0)
+		free_irq(rtc->irq_tick, rtc);
+
+	rtc_device_unregister(rtc->rtc_dev);
+	return 0;
+}
+
+static struct platform_driver da906x_rtc_driver = {
+	.probe		= da906x_rtc_probe,
+	.remove		= __devexit_p(da906x_rtc_remove),
+	.driver		= {
+		.name	= DA906X_DRVNAME_RTC,
+		.owner	= THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_rtc_driver);
+
+/* Module information */
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>");
+MODULE_DESCRIPTION("DA906x RTC driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DA906X_DRVNAME_RTC);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [lm-sensors] [PATCH 4/8] hwmon: Add DA906x hardware monitoring support.
@ 2012-08-24  8:32         ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24  8:32 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie, Bryan Wu, Liam Girdwood

DA906x PMIC provides ADC for voltage and temperature monitoring.

The driver provides results of following ADC channels:
 - in0 - system voltage (2500 - 5500 mV)
 - in1 - universal voltage channel #1 (0 - 2500 mV)
 - in2 - universal voltage channel #2 (0 - 2500 mV)
 - in3 - universal voltage channel #3 (0 - 2500 mV)
 - in4 - backup battery voltage (0 - 5000 mV)
 - temp1 - PMIC internal junction temperature (-88 - 333 Celcius degrees)

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/hwmon/Kconfig        |    6 +
 drivers/hwmon/Makefile       |    1 +
 drivers/hwmon/da906x-hwmon.c |  393 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 400 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/da906x-hwmon.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index b0a2e4c..7abc9a0 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1373,6 +1373,12 @@ config SENSORS_WM8350
 	  This driver can also be built as a module.  If so, the module
 	  will be called wm8350-hwmon.
 
+config SENSORS_DA906X
+	tristate "DA906X HWMON device drivers"
+	depends on MFD_DA906X
+	help
+	  Support for the HWMON DA906X device driver.
+
 config SENSORS_ULTRA45
 	tristate "Sun Ultra45 PIC16F747"
 	depends on SPARC64
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 7aa9811..ffbe151 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_SENSORS_ASC7621)	+= asc7621.o
 obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
 obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
 obj-$(CONFIG_SENSORS_DA9052_ADC)+= da9052-hwmon.o
+obj-$(CONFIG_SENSORS_DA906X)	+= da906x-hwmon.o
 obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
 obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
diff --git a/drivers/hwmon/da906x-hwmon.c b/drivers/hwmon/da906x-hwmon.c
new file mode 100644
index 0000000..8ece931
--- /dev/null
+++ b/drivers/hwmon/da906x-hwmon.c
@@ -0,0 +1,393 @@
+/*
+ * HW Monitor support for Dialog DA906X PMIC series
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>,
+ *         Michal Hajduk <michal.hajduk@diasemi.com>
+ *
+ *  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/err.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/platform_device.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+
+/* ADC resolutions for manual and auto modes */
+#define DA906X_ADC_RES		\
+		(1 << (DA906X_ADC_RES_L_BITS + DA906X_ADC_RES_M_BITS))
+#define DA906X_ADC_MAX		(DA906X_ADC_RES - 1)
+#define	DA906X_ADC_AUTO_RES	(1 << DA906X_ADC_RES_M_BITS)
+#define	DA906X_ADC_AUTO_MAX	(DA906X_ADC_AUTO_RES - 1)
+
+/* Define interpolation table to calculate ADC values  */
+struct i_table {
+	int x0;
+	int a;
+	int b;
+};
+#define ILINE(x1, x2, y1, y2)	{ \
+		.x0 = (x1), \
+		.a = ((y2) - (y1)) * DA906X_ADC_RES / ((x2) - (x1)), \
+		.b = (y1) - ((y2) - (y1)) * (x1) / ((x2) - (x1)), \
+	}
+
+struct channel_info {
+	const char *name;
+	const struct i_table *tbl;
+	int tbl_max;
+	u16 reg_auto_en;
+};
+
+enum da906x_adc {
+	DA906X_VSYS,
+	DA906X_ADCIN1,
+	DA906X_ADCIN2,
+	DA906X_ADCIN3,
+	DA906X_TJUNC,
+	DA906X_VBBAT,
+
+	DA906X_CHAN_NUM
+};
+
+static const struct i_table vsys_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 2500, 5500)
+};
+
+static const struct i_table adcin_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 0, 2500)
+};
+
+static const struct i_table tjunc_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 333, -86)
+};
+
+static const struct i_table vbbat_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 0, 5000)
+};
+
+static const struct channel_info da906x_channels[] = {
+	[DA906X_VSYS]	= { "VSYS",
+			    vsys_tbl, ARRAY_SIZE(vsys_tbl) - 1,
+			    DA906X_REG_VSYS_RES },
+	[DA906X_ADCIN1]	= { "ADCIN1",
+			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
+			    DA906X_REG_ADCIN1_RES },
+	[DA906X_ADCIN2]	= { "ADCIN2",
+			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
+			    DA906X_REG_ADCIN2_RES },
+	[DA906X_ADCIN3]	= { "ADCIN3",
+			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
+			    DA906X_REG_ADCIN3_RES },
+	[DA906X_TJUNC]	= { "TJUNC",
+			    tjunc_tbl,	ARRAY_SIZE(tjunc_tbl) - 1 },
+	[DA906X_VBBAT]	= { "VBBAT",
+			    vbbat_tbl,	ARRAY_SIZE(vbbat_tbl) - 1}
+};
+#define DA906X_ADC_AUTO_MODE_SUPPORT_MASK	(DA906X_ADC_AUTO_VSYS_EN | \
+						 DA906X_ADC_AUTO_AD1_EN | \
+						 DA906X_ADC_AUTO_AD2_EN | \
+						 DA906X_ADC_AUTO_AD3_EN)
+
+struct da906x_hwmon {
+	struct da906x *da906x;
+	struct device *class_dev;
+	struct completion man_adc_rdy;	/* Manual read completion flag */
+	struct mutex hwmon_mutex;	/* Queue concurent manual reads */
+	int irq;
+	u8 adc_auto_en;     /* Bitmask of channels with auto mode enabled */
+	s8 tjunc_offset;    /* Calibration offset for junction temperature */
+};
+
+int da906x_adc_convert(int channel, int x)
+{
+	const struct channel_info *info = &da906x_channels[channel];
+	int i, ret;
+
+	for (i = info->tbl_max; i > 0; i--)
+		if (info->tbl[i].x0 <= x)
+			break;
+
+	ret = info->tbl[i].a * x;
+	if (ret >= 0)
+		ret += DA906X_ADC_RES / 2;
+	else
+		ret -= DA906X_ADC_RES / 2;
+	ret = ret / DA906X_ADC_RES + info->tbl[i].b;
+	return ret;
+}
+
+static int da906x_adc_manual_read(struct da906x_hwmon *hwmon, int channel)
+{
+	int ret;
+	u8 data[2];
+
+	mutex_lock(&hwmon->hwmon_mutex);
+
+	init_completion(&hwmon->man_adc_rdy);
+
+	/* Start measurment on selected channel */
+	data[0] = (channel << DA906X_ADC_MUX_SHIFT) & DA906X_ADC_MUX_MASK;
+	data[0] |= DA906X_ADC_MAN;
+	ret = da906x_reg_update(hwmon->da906x, DA906X_REG_ADC_MAN,
+				DA906X_ADC_MUX_MASK | DA906X_ADC_MAN, data[0]);
+	if (ret < 0)
+		goto out;
+
+	/* Wait for interrupt from ADC */
+	ret = wait_for_completion_timeout(&hwmon->man_adc_rdy,
+					  msecs_to_jiffies(1000));
+	if (ret = 0) {
+		ret = -EBUSY;
+		goto out;
+	}
+
+	/* Get results */
+	ret = da906x_block_read(hwmon->da906x, DA906X_REG_ADC_RES_L, 2, data);
+	if (ret < 0)
+		goto out;
+	ret = (data[0] & DA906X_ADC_RES_L_MASK) >> DA906X_ADC_RES_L_SHIFT;
+	ret |= data[1] << DA906X_ADC_RES_L_BITS;
+out:
+	mutex_unlock(&hwmon->hwmon_mutex);
+	return ret;
+}
+
+static int da906x_adc_auto_read(struct da906x *da906x, int channel)
+{
+	const struct channel_info *info = &da906x_channels[channel];
+
+	return da906x_reg_read(da906x, info->reg_auto_en);
+}
+
+static irqreturn_t da906x_hwmon_irq_handler(int irq, void *irq_data)
+{
+	struct da906x_hwmon *hwmon = irq_data;
+
+	complete(&hwmon->man_adc_rdy);
+
+	return IRQ_HANDLED;
+}
+
+static ssize_t da906x_adc_read(struct device *dev,
+			       struct device_attribute *devattr, char *buf)
+{
+	struct da906x_hwmon *hwmon = dev_get_drvdata(dev);
+	int channel = to_sensor_dev_attr(devattr)->index;
+	int val;
+
+	if (hwmon->adc_auto_en & (1 << channel)) {
+		val = da906x_adc_auto_read(hwmon->da906x, channel);
+		if (val < 0)
+			return val;
+
+		val *= DA906X_ADC_RES / DA906X_ADC_AUTO_RES;
+		val = da906x_adc_convert(channel, val);
+	} else {
+		val = da906x_adc_manual_read(hwmon, channel);
+		if (val < 0)
+			return val;
+
+		if (channel = DA906X_TJUNC)
+			val += hwmon->tjunc_offset;
+		val = da906x_adc_convert(channel, val);
+	}
+
+	return sprintf(buf, "%d\n", val);
+}
+
+static ssize_t da906x_show_name(struct device *dev,
+	struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, DA906X_DRVNAME_HWMON "\n");
+}
+
+static ssize_t da906x_show_label(struct device *dev,
+				 struct device_attribute *devattr, char *buf)
+{
+	const struct channel_info *info;
+
+	info = &da906x_channels[to_sensor_dev_attr(devattr)->index];
+	return sprintf(buf, "%s\n", info->name);
+}
+
+/* Vsys voltage */
+static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_VSYS);
+static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_VSYS);
+
+/* Universal ADC channel #1 */
+static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_ADCIN1);
+static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_ADCIN1);
+
+/* Universal ADC channel #2 */
+static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO,
+			  da906x_adc_read, NULL,
+			  DA906X_ADCIN2);
+static SENSOR_DEVICE_ATTR(in2_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_ADCIN2);
+
+/* Universal ADC channel #3 */
+static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_ADCIN3);
+static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_ADCIN3);
+
+/* Backup battery voltage */
+static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_VBBAT);
+static SENSOR_DEVICE_ATTR(in4_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_VBBAT);
+
+/* Junction temperature */
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_TJUNC);
+
+static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_TJUNC);
+
+/* Device name */
+static DEVICE_ATTR(name, S_IRUGO, da906x_show_name, NULL);
+
+static struct attribute *da906x_attributes[] = {
+	&dev_attr_name.attr,
+	&sensor_dev_attr_in0_input.dev_attr.attr,
+	&sensor_dev_attr_in0_label.dev_attr.attr,
+	&sensor_dev_attr_in1_input.dev_attr.attr,
+	&sensor_dev_attr_in1_label.dev_attr.attr,
+	&sensor_dev_attr_in2_input.dev_attr.attr,
+	&sensor_dev_attr_in2_label.dev_attr.attr,
+	&sensor_dev_attr_in3_input.dev_attr.attr,
+	&sensor_dev_attr_in3_label.dev_attr.attr,
+	&sensor_dev_attr_in4_input.dev_attr.attr,
+	&sensor_dev_attr_in4_label.dev_attr.attr,
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_label.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group da906x_attr_group = {
+	.attrs = da906x_attributes,
+};
+
+static int __devinit da906x_hwmon_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_pdata *da906x_pdata = dev_get_platdata(da906x->dev);
+	struct da906x_hwmon *hwmon;
+	int ret;
+
+	hwmon = devm_kzalloc(&pdev->dev, sizeof(struct da906x_hwmon),
+			     GFP_KERNEL);
+	if (!hwmon)
+		return -ENOMEM;
+
+	mutex_init(&hwmon->hwmon_mutex);
+	init_completion(&hwmon->man_adc_rdy);
+	hwmon->da906x = da906x;
+
+	ret = da906x_reg_read(da906x, DA906X_REG_ADC_CONT);
+	if (ret < 0)
+		return ret;
+	hwmon->adc_auto_en = ret & DA906X_ADC_AUTO_MODE_SUPPORT_MASK;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN0_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_VSYS_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN0_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_VSYS_EN;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN1_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD1_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN1_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD1_EN;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN2_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD2_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN2_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD2_EN;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN3_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD3_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN3_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD3_EN;
+
+	ret = da906x_reg_update(da906x, DA906X_REG_ADC_CONT,
+				DA906X_ADC_AUTO_MODE_SUPPORT_MASK,
+				hwmon->adc_auto_en);
+	if (ret < 0)
+		return ret;
+
+	hwmon->class_dev = hwmon_device_register(&pdev->dev);
+	if (IS_ERR(hwmon->class_dev))
+		return PTR_ERR(hwmon->class_dev);
+
+	hwmon->irq = platform_get_irq_byname(pdev, DA906X_DRVNAME_HWMON);
+	ret = devm_request_threaded_irq(&pdev->dev, hwmon->irq, NULL,
+					da906x_hwmon_irq_handler,
+					IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+					"HWMON", hwmon);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request IRQ.\n");
+		goto err;
+	}
+
+	platform_set_drvdata(pdev, hwmon);
+
+	ret = da906x_reg_read(da906x, DA906X_REG_T_OFFSET);
+	if (ret < 0)
+		dev_warn(&pdev->dev, "Could not read temp1 callibration offset.\n");
+	else
+		hwmon->tjunc_offset = (s8)ret;
+
+	ret = sysfs_create_group(&pdev->dev.kobj, &da906x_attr_group);
+	if (ret)
+		goto err;
+
+	return 0;
+
+err:
+	hwmon_device_unregister(hwmon->class_dev);
+	return ret;
+}
+
+static int __devexit da906x_hwmon_remove(struct platform_device *pdev)
+{
+	struct da906x_hwmon *hwmon = platform_get_drvdata(pdev);
+
+	hwmon_device_unregister(hwmon->class_dev);
+	sysfs_remove_group(&pdev->dev.kobj, &da906x_attr_group);
+
+	return 0;
+}
+
+static struct platform_driver da906x_hwmon_driver = {
+	.probe = da906x_hwmon_probe,
+	.remove = __devexit_p(da906x_hwmon_remove),
+	.driver = {
+		.name = DA906X_DRVNAME_HWMON,
+		.owner = THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_hwmon_driver);
+
+MODULE_DESCRIPTION("DA906X Hardware monitoring");
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>, Michal Hajduk <michal.hajduk@diasemi.com>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("paltform:" DA906X_DRVNAME_HWMON);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [lm-sensors] [PATCH 5/8] input: Add support for DA906x PMIC OnKey detection.
@ 2012-08-24  8:32           ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24  8:32 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie, Bryan Wu, Liam Girdwood

This driver creates input device that reports a key event on an OnKey button
release. The reported key code depends on the time, the button was holded for.
If holding time < 2 seconds - KEY_SLEEP is reported on button release,
otherwise KEY_POWER is reported after 2 seconds.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/input/misc/Kconfig        |    6 ++
 drivers/input/misc/Makefile       |    1 +
 drivers/input/misc/da906x-onkey.c |  139 +++++++++++++++++++++++++++++++++++++
 3 files changed, 146 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/misc/da906x-onkey.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 7c0f1ec..fd8d951 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -486,6 +486,12 @@ config INPUT_DA9052_ONKEY
 	  To compile this driver as a module, choose M here: the
 	  module will be called da9052_onkey.
 
+config INPUT_DA906X_ONKEY
+	tristate "Dialog DA906x OnKey"
+	depends on MFD_DA906X
+	help
+	  Support for Dialog Semiconductor input onkey device.
+
 config INPUT_DM355EVM
 	tristate "TI DaVinci DM355 EVM Keypad and IR Remote"
 	depends on MFD_DM355EVM_MSP
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 83fe6f5..73406ac 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_INPUT_CMA3000)		+= cma3000_d0x.o
 obj-$(CONFIG_INPUT_CMA3000_I2C)		+= cma3000_d0x_i2c.o
 obj-$(CONFIG_INPUT_COBALT_BTNS)		+= cobalt_btns.o
 obj-$(CONFIG_INPUT_DA9052_ONKEY)	+= da9052_onkey.o
+obj-$(CONFIG_INPUT_DA906X_ONKEY)	+= da906x-onkey.o
 obj-$(CONFIG_INPUT_DM355EVM)		+= dm355evm_keys.o
 obj-$(CONFIG_INPUT_GP2A)		+= gp2ap002a00f.o
 obj-$(CONFIG_INPUT_GPIO_TILT_POLLED)	+= gpio_tilt_polled.o
diff --git a/drivers/input/misc/da906x-onkey.c b/drivers/input/misc/da906x-onkey.c
new file mode 100644
index 0000000..477c554
--- /dev/null
+++ b/drivers/input/misc/da906x-onkey.c
@@ -0,0 +1,139 @@
+/*
+ * OnKey device driver for Dialog DA906x PMIC
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author:  <michal.hajduk@diasemi.com>
+ *
+ *  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/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/workqueue.h>
+
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/registers.h>
+
+
+struct da906x_onkey {
+	struct	da906x *da906x;
+	struct	input_dev *input;
+	int irq;
+};
+
+static irqreturn_t da906x_onkey_irq_handler(int irq, void *data)
+{
+	struct da906x_onkey *onkey = data;
+	unsigned int code;
+	int ret;
+
+	ret = da906x_reg_read(onkey->da906x, DA906X_REG_STATUS_A);
+	if ((ret >= 0) && (ret & DA906X_NONKEY)) {
+		dev_notice(&onkey->input->dev, "KEY_POWER pressed.\n");
+		code = KEY_POWER;
+	} else {
+		dev_notice(&onkey->input->dev, "KEY_SLEEP pressed.\n");
+		code = KEY_SLEEP;
+	}
+
+	/* Interrupt raised for key release only,
+	   so report consecutive button press and release. */
+	input_report_key(onkey->input, code, 1);
+	input_report_key(onkey->input, code, 0);
+	input_sync(onkey->input);
+
+	return IRQ_HANDLED;
+}
+
+static int __devinit da906x_onkey_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_onkey *onkey;
+	int ret = 0;
+
+	onkey = devm_kzalloc(&pdev->dev, sizeof(struct da906x_onkey),
+			     GFP_KERNEL);
+	if (!onkey) {
+		dev_err(&pdev->dev, "Failed to allocate memory.\n");
+		return -ENOMEM;
+	}
+
+	onkey->input = input_allocate_device();
+	if (!onkey->input) {
+		dev_err(&pdev->dev, "Failed to allocated inpute device.\n");
+		return -ENOMEM;
+	}
+
+	onkey->irq = platform_get_irq_byname(pdev, DA906X_DRVNAME_ONKEY);
+	onkey->da906x = da906x;
+
+	onkey->input->evbit[0] = BIT_MASK(EV_KEY);
+	onkey->input->name = DA906X_DRVNAME_ONKEY;
+	onkey->input->phys = DA906X_DRVNAME_ONKEY "/input0";
+	onkey->input->dev.parent = &pdev->dev;
+	input_set_capability(onkey->input, EV_KEY, KEY_POWER);
+	input_set_capability(onkey->input, EV_KEY, KEY_SLEEP);
+
+	ret = request_threaded_irq(onkey->irq, NULL, da906x_onkey_irq_handler,
+			IRQF_TRIGGER_LOW | IRQF_ONESHOT, "ONKEY", onkey);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request IRQ.\n");
+		goto err_input;
+	}
+
+	ret = input_register_device(onkey->input);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request IRQ.\n");
+		goto err_irq;
+	}
+
+	platform_set_drvdata(pdev, onkey);
+
+	/* Interrupt reacts on button release */
+	da906x_reg_update(da906x, DA906X_REG_CONFIG_I,
+			  DA906X_NONKEY_PIN_MASK, DA906X_NONKEY_PIN_SWDOWN);
+
+	return 0;
+
+err_irq:
+	free_irq(onkey->da906x->irq_base + onkey->irq , onkey);
+err_input:
+	input_free_device(onkey->input);
+	return ret;
+}
+
+static int __devexit da906x_onkey_remove(struct platform_device *pdev)
+{
+	struct	da906x_onkey *onkey = platform_get_drvdata(pdev);
+
+	free_irq(onkey->irq, onkey);
+	input_unregister_device(onkey->input);
+	return 0;
+}
+
+static struct platform_driver da906x_onkey_driver = {
+	.probe	= da906x_onkey_probe,
+	.remove	= __devexit_p(da906x_onkey_remove),
+	.driver	= {
+		.name	= DA906X_DRVNAME_ONKEY,
+		.owner	= THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_onkey_driver);
+
+MODULE_AUTHOR("Dialog Semiconductor <michal.hajduk@diasemi.com>");
+MODULE_DESCRIPTION("Onkey driver for DA906X");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("paltform:" DA906X_DRVNAME_ONKEY);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [lm-sensors] [PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
@ 2012-08-24  8:32     ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24  8:32 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie, Bryan Wu, Liam Girdwood

The driver adds support for the following DA9063 PMIC regulators:
 - 11x LDOs (named LDO1 - LDO11),
 - 6x buck converters (BCORE1, BCORE2, BPRO, BMEM, BIO, BPERI),
 - 1x power switch to switch on/off 32 KHz oscilator output (32K_OUT).

Regulators provide following operations:
 - REGULATOR_CHANGE_STATUS for all regulators,
 - REGULATOR_CHANGE_VOLTAGE for LDOs and buck converters,
 - REGULATOR_CHANGE_MODE for LDOs and buck converters, where:
     - LDOs allow REGULATOR_MODE_NORMAL and REGULATOR_MODE_STANDBY,
     - buck converters allow REGULATOR_MODE_FAST, REGULATOR_MODE_NORMAL
       and REGULATOR_MODE_STANDBY,
 - REGULATOR_CHANGE_CURRENT for buck converters (current limits).

The driver generates REGULATOR_EVENT_OVER_CURRENT for LDO3, LDO4, LDO7, LDO8
and LDO11.

Internally, PMIC provides two voltage configurations for normal and suspend
system state for each regulator. The driver switches between those on
suspend/wake-up to provide quick and fluent output voltage change.

This driver requires MFD core driver for operation.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/regulator/Kconfig            |    6 +
 drivers/regulator/Makefile           |    1 +
 drivers/regulator/da906x-regulator.c | 1018 ++++++++++++++++++++++++++++++++++
 3 files changed, 1025 insertions(+), 0 deletions(-)
 create mode 100644 drivers/regulator/da906x-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 4e932cc..b57b6c6 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -110,6 +110,12 @@ config REGULATOR_DA9052
 	  This driver supports the voltage regulators of DA9052-BC and
 	  DA9053-AA/Bx PMIC.
 
+config REGULATOR_DA906X
+	bool "Dialog DA906X Regulator family chip"
+	depends on MFD_DA906X
+	help
+	  Support for Dialog Semiconductor DA906x chip.
+
 config REGULATOR_ANATOP
 	tristate "Freescale i.MX on-chip ANATOP LDO regulators"
 	depends on MFD_ANATOP
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 3342615..46a503a 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o
 obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o
 obj-$(CONFIG_REGULATOR_DA903X)	+= da903x.o
 obj-$(CONFIG_REGULATOR_DA9052)	+= da9052-regulator.o
+obj-$(CONFIG_REGULATOR_DA906X) += da906x-regulator.o
 obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o
 obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o
 obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o
diff --git a/drivers/regulator/da906x-regulator.c b/drivers/regulator/da906x-regulator.c
new file mode 100644
index 0000000..1b68de0
--- /dev/null
+++ b/drivers/regulator/da906x-regulator.c
@@ -0,0 +1,1018 @@
+/*
+ * Regulator driver for DA906x PMIC series
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/init.h>
+#include <linux/err.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+#include <linux/mfd/da906x/registers.h>
+
+
+/* Definition for registering bit fields */
+struct bfield {
+	unsigned short	addr;
+	unsigned char	mask;
+};
+#define BFIELD(_addr, _mask) \
+	{ .addr = _addr, .mask = _mask }
+
+struct field {
+	unsigned short	addr;
+	unsigned char	mask;
+	unsigned char	shift;
+	unsigned char	offset;
+};
+#define FIELD(_addr, _mask, _shift, _offset) \
+	{ .addr = _addr, .mask = _mask, .shift = _shift, .offset = _offset }
+
+/* Regulator capabilities and registers description */
+struct da906x_regulator_info {
+	int			id;
+	char			*name;
+	struct regulator_ops	*ops;
+
+	/* Voltage adjust range */
+	int		min_uV;
+	int		max_uV;
+	unsigned	step_uV;
+	unsigned	n_steps;
+
+	/* Current limiting */
+	unsigned	n_current_limits;
+	const int	*current_limits;
+
+	/* DA906x main register fields */
+	struct bfield	enable;		/* bit used to enable regulator,
+					   it returns actual state when read */
+	struct field	mode;		/* buck mode of operation */
+	struct bfield	suspend;
+	struct bfield	sleep;
+	struct bfield	suspend_sleep;
+	struct field	voltage;
+	struct field	suspend_voltage;
+	struct field	ilimit;
+
+	/* DA906x event detection bit */
+	struct bfield	oc_event;
+};
+
+/* Macro for switch regulator */
+#define DA906X_SWITCH(chip, regl_name) \
+	.id = chip##_ID_##regl_name, \
+	.name = __stringify(chip##_##regl_name), \
+	.ops = &da906x_switch_ops, \
+	.n_steps = 0
+
+/* Macros for LDO */
+#define DA906X_LDO(chip, regl_name, min_mV, step_mV, max_mV) \
+	.id = chip##_ID_##regl_name, \
+	.name = __stringify(chip##_##regl_name), \
+	.ops = &da906x_ldo_ops, \
+	.min_uV = (min_mV) * 1000, \
+	.max_uV = (max_mV) * 1000, \
+	.step_uV = (step_mV) * 1000, \
+	.n_steps = (((max_mV) - (min_mV))/(step_mV) + 1)
+
+#define DA906X_LDO_COMMON_FIELDS(regl_name) \
+	.enable = BFIELD(DA906X_REG_##regl_name##_CONT, DA906X_LDO_EN), \
+	.sleep = BFIELD(DA906X_REG_V##regl_name##_A, DA906X_LDO_SL), \
+	.suspend_sleep = BFIELD(DA906X_REG_V##regl_name##_B, DA906X_LDO_SL), \
+	.voltage = FIELD(DA906X_REG_V##regl_name##_A, \
+			DA906X_V##regl_name##_MASK, \
+			DA906X_V##regl_name##_SHIFT, \
+			DA906X_V##regl_name##_BIAS), \
+	.suspend_voltage = FIELD(DA906X_REG_V##regl_name##_B, \
+			DA906X_V##regl_name##_MASK,\
+			DA906X_V##regl_name##_SHIFT, \
+			DA906X_V##regl_name##_BIAS)
+
+/* Macros for voltage DC/DC converters (BUCKs) */
+#define DA906X_BUCK(chip, regl_name, min_mV, step_mV, max_mV, limits_array) \
+	.id = chip##_ID_##regl_name, \
+	.name = __stringify(chip##_##regl_name), \
+	.ops = &da906x_buck_ops, \
+	.min_uV = (min_mV) * 1000, \
+	.max_uV = (max_mV) * 1000, \
+	.step_uV = (step_mV) * 1000, \
+	.n_steps = ((max_mV) - (min_mV))/(step_mV) + 1, \
+	.current_limits = limits_array, \
+	.n_current_limits = ARRAY_SIZE(limits_array)
+
+#define DA906X_BUCK_COMMON_FIELDS(regl_name) \
+	.enable = BFIELD(DA906X_REG_##regl_name##_CONT, DA906X_BUCK_EN), \
+	.sleep = BFIELD(DA906X_REG_V##regl_name##_A, DA906X_BUCK_SL), \
+	.suspend_sleep = BFIELD(DA906X_REG_V##regl_name##_B, DA906X_BUCK_SL), \
+	.voltage = FIELD(DA906X_REG_V##regl_name##_A, \
+			 DA906X_VBUCK_MASK, \
+			 DA906X_VBUCK_SHIFT, \
+			 DA906X_VBUCK_BIAS), \
+	.suspend_voltage = FIELD(DA906X_REG_V##regl_name##_B, \
+				 DA906X_VBUCK_MASK,\
+				 DA906X_VBUCK_SHIFT, \
+				 DA906X_VBUCK_BIAS), \
+	.mode = FIELD(DA906X_REG_##regl_name##_CFG, DA906X_BUCK_MODE_MASK, \
+		      DA906X_BUCK_MODE_SHIFT, 0)
+
+/* Defines asignment of regulators info table to chip model */
+struct da906x_dev_model {
+	const struct da906x_regulator_info	*regulator_info;
+	unsigned				n_regulators;
+	unsigned				dev_model;
+};
+
+/* Single regulator settings */
+struct da906x_regulator {
+	struct regulator_desc			desc;
+	struct regulator_dev			*rdev;
+	struct da906x				*hw;
+	const struct da906x_regulator_info	*info;
+
+	unsigned				mode;
+	unsigned				suspend_mode;
+};
+
+/* Encapsulates all information for the regulators driver */
+struct da906x_regulators {
+	int					irq_ldo_lim;
+	int					irq_uvov;
+
+	unsigned				n_regulators;
+	/* Array size to be defined during init. Keep at end. */
+	struct da906x_regulator			regulator[0];
+};
+
+/* System states for da906x_update_mode_internal()
+   and for da906x_get_mode_internal() */
+enum {
+	SYS_STATE_NORMAL,
+	SYS_STATE_SUSPEND,
+	SYS_STATE_CURRENT
+};
+
+/* BUCK modes for DA906x */
+enum {
+	BUCK_MODE_MANUAL,	/* 0 */
+	BUCK_MODE_SLEEP,	/* 1 */
+	BUCK_MODE_SYNC,		/* 2 */
+	BUCK_MODE_AUTO		/* 3 */
+};
+
+/* Regulator operations */
+static int da906x_set_voltage(struct regulator_dev *rdev, int min_uV,
+			      int max_uV, unsigned *selector);
+static int da906x_get_voltage_sel(struct regulator_dev *rdev);
+static int da906x_set_current_limit(struct regulator_dev *rdev,
+				    int min_uA, int max_uA);
+static int da906x_get_current_limit(struct regulator_dev *rdev);
+static int da906x_enable(struct regulator_dev *rdev);
+static int da906x_set_mode(struct regulator_dev *rdev, unsigned int mode);
+static unsigned da906x_get_mode(struct regulator_dev *rdev);
+static int da906x_get_status(struct regulator_dev *rdev);
+static int da906x_set_suspend_voltage(struct regulator_dev *rdev, int uV);
+static int da906x_suspend_enable(struct regulator_dev *rdev);
+static int da906x_set_suspend_mode(struct regulator_dev *rdev, unsigned mode);
+
+static struct regulator_ops da906x_switch_ops = {
+	.enable			= da906x_enable,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.set_suspend_enable	= da906x_enable,
+	.set_suspend_disable	= regulator_disable_regmap,
+};
+
+static struct regulator_ops da906x_ldo_ops = {
+	.enable			= da906x_enable,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.set_voltage		= da906x_set_voltage,
+	.get_voltage_sel	= da906x_get_voltage_sel,
+	.list_voltage		= regulator_list_voltage_linear,
+	.set_mode		= da906x_set_mode,
+	.get_mode		= da906x_get_mode,
+	.get_status		= da906x_get_status,
+	.set_suspend_voltage	= da906x_set_suspend_voltage,
+	.set_suspend_enable	= da906x_suspend_enable,
+	.set_suspend_disable	= regulator_disable_regmap,
+	.set_suspend_mode	= da906x_set_suspend_mode,
+};
+
+static struct regulator_ops da906x_buck_ops = {
+	.enable			= da906x_enable,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.set_voltage		= da906x_set_voltage,
+	.get_voltage_sel	= da906x_get_voltage_sel,
+	.list_voltage		= regulator_list_voltage_linear,
+	.set_current_limit	= da906x_set_current_limit,
+	.get_current_limit	= da906x_get_current_limit,
+	.set_mode		= da906x_set_mode,
+	.get_mode		= da906x_get_mode,
+	.get_status		= da906x_get_status,
+	.set_suspend_voltage	= da906x_set_suspend_voltage,
+	.set_suspend_enable	= da906x_suspend_enable,
+	.set_suspend_disable	= regulator_disable_regmap,
+	.set_suspend_mode	= da906x_set_suspend_mode,
+};
+
+/* Current limits array (in uA) for BCORE1, BCORE2, BPRO.
+   Entry indexes corresponds to register values. */
+static const int da9063_buck_a_limits[] = {
+	 500000,  600000,  700000,  800000,  900000, 1000000, 1100000, 1200000,
+	1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000
+};
+
+/* Current limits array (in uA) for BMEM, BIO, BPERI.
+   Entry indexes corresponds to register values. */
+static const int da9063_buck_b_limits[] = {
+	1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,
+	2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000
+};
+
+/* Current limits array (in uA) for merged BCORE1 and BCORE2.
+   Entry indexes corresponds to register values. */
+static const int da9063_bcores_merged_limits[] = {
+	1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000,
+	2600000, 2800000, 3000000, 3200000, 3400000, 3600000, 3800000, 4000000
+};
+
+/* Current limits array (in uA) for merged BMEM and BIO.
+   Entry indexes corresponds to register values. */
+static const int da9063_bmem_bio_merged_limits[] = {
+	3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000,
+	4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000
+};
+
+/* Info of regulators for DA9063 */
+static const struct da906x_regulator_info da9063_regulator_info[] = {
+	{
+		DA906X_BUCK(DA9063, BCORE1, 300, 10, 1570,
+			    da9063_buck_a_limits),
+		DA906X_BUCK_COMMON_FIELDS(BCORE1),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBCORE1_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_C, DA906X_BCORE1_ILIM_MASK,
+				DA906X_BCORE1_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BCORE2, 300, 10, 1570,
+			    da9063_buck_a_limits),
+		DA906X_BUCK_COMMON_FIELDS(BCORE2),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBCORE2_SEL),
+
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_C,
+				DA906X_BCORE2_ILIM_MASK,
+				DA906X_BCORE2_ILIM_SHIFT,
+				0),
+	},
+	{
+		DA906X_BUCK(DA9063, BPRO, 530, 10, 1800,
+			    da9063_buck_a_limits),
+		DA906X_BUCK_COMMON_FIELDS(BPRO),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBPRO_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_B, DA906X_BPRO_ILIM_MASK,
+				DA906X_BPRO_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BMEM, 800, 20, 3340,
+			    da9063_buck_b_limits),
+		DA906X_BUCK_COMMON_FIELDS(BMEM),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBMEM_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_A, DA906X_BMEM_ILIM_MASK,
+				DA906X_BMEM_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BIO, 800, 20, 3340,
+			    da9063_buck_b_limits),
+		DA906X_BUCK_COMMON_FIELDS(BIO),
+		.suspend = BFIELD(DA906X_REG_DVC_2, DA906X_VBIO_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_A, DA906X_BIO_ILIM_MASK,
+				DA906X_BIO_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BPERI, 800, 20, 3340,
+			    da9063_buck_b_limits),
+		DA906X_BUCK_COMMON_FIELDS(BPERI),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBPERI_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_B, DA906X_BPERI_ILIM_MASK,
+				DA906X_BPERI_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BCORES_MERGED, 300, 10, 1570,
+			    da9063_bcores_merged_limits),
+		/* BCORES_MERGED uses the same register fields as BCORE1 */
+		DA906X_BUCK_COMMON_FIELDS(BCORE1),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBCORE1_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_C, DA906X_BCORE1_ILIM_MASK,
+				DA906X_BCORE1_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BMEM_BIO_MERGED, 800, 20, 3340,
+			    da9063_bmem_bio_merged_limits),
+		/* BMEM_BIO_MERGED uses the same register fields as BMEM */
+		DA906X_BUCK_COMMON_FIELDS(BMEM),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBMEM_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_A, DA906X_BMEM_ILIM_MASK,
+				DA906X_BMEM_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_LDO(DA9063, LDO1, 600, 20, 1860),
+		DA906X_LDO_COMMON_FIELDS(LDO1),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VLDO1_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO2, 600, 20, 1860),
+		DA906X_LDO_COMMON_FIELDS(LDO2),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VLDO2_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO3, 900, 20, 3440),
+		DA906X_LDO_COMMON_FIELDS(LDO3),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VLDO3_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO3_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO4, 900, 20, 3440),
+		DA906X_LDO_COMMON_FIELDS(LDO4),
+		.suspend = BFIELD(DA906X_REG_DVC_2, DA906X_VLDO4_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO4_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO5, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO5),
+		.suspend = BFIELD(DA906X_REG_LDO5_CONT, DA906X_VLDO5_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO6, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO6),
+		.suspend = BFIELD(DA906X_REG_LDO6_CONT, DA906X_VLDO6_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO7, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO7),
+		.suspend = BFIELD(DA906X_REG_LDO7_CONT, DA906X_VLDO7_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO7_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO8, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO8),
+		.suspend = BFIELD(DA906X_REG_LDO8_CONT, DA906X_VLDO8_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO8_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO9, 950, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO9),
+		.suspend = BFIELD(DA906X_REG_LDO9_CONT, DA906X_VLDO9_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO10, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO10),
+		.suspend = BFIELD(DA906X_REG_LDO10_CONT, DA906X_VLDO10_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO11, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO11),
+		.suspend = BFIELD(DA906X_REG_LDO11_CONT, DA906X_VLDO11_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO11_LIM),
+	},
+	{
+		DA906X_SWITCH(DA9063, 32K_OUT),
+		.enable = BFIELD(DA906X_REG_EN_32K, DA906X_OUT_32K_EN),
+	},
+};
+
+/* Link chip model with regulators info table */
+static struct da906x_dev_model regulators_models[] = {
+	{
+		.regulator_info = da9063_regulator_info,
+		.n_regulators = ARRAY_SIZE(da9063_regulator_info),
+		.dev_model = PMIC_DA9063,
+	},
+	{NULL, 0, 0}	/* End of list */
+};
+
+
+/*
+ * Regulator internal functions
+ */
+static int da906x_update_mode_internal(struct da906x_regulator *regl,
+				       int sys_state)
+{
+	const struct da906x_regulator_info *rinfo = regl->info;
+	unsigned val;
+	unsigned mode;
+	int ret;
+
+	if (sys_state = SYS_STATE_SUSPEND)
+		/* Get mode for regulator in suspend state */
+		mode = regl->suspend_mode;
+	else
+		/* Get mode for regulator in normal operation */
+		mode = regl->mode;
+
+	/* LDOs use sleep flags - one for normal and one for suspend state.
+	   For BUCKs single mode register field is used in normal and
+	   suspend state. */
+	if (rinfo->mode.addr) {
+		/* Set mode for BUCK - 3 modes are supported */
+		switch (mode) {
+		case REGULATOR_MODE_FAST:
+			val = BUCK_MODE_SYNC;
+			break;
+		case REGULATOR_MODE_NORMAL:
+			val = BUCK_MODE_AUTO;
+			break;
+		case REGULATOR_MODE_STANDBY:
+			val = BUCK_MODE_SLEEP;
+			break;
+		default:
+			return -EINVAL;
+		}
+		val = val << rinfo->mode.shift;
+
+		ret = da906x_reg_update(regl->hw, rinfo->mode.addr,
+					rinfo->mode.mask, val);
+	} else {
+		/* Set mode for LDO - 2 modes are supported */
+		switch (mode) {
+		case REGULATOR_MODE_NORMAL:
+			val = 0;
+			break;
+		case REGULATOR_MODE_STANDBY:
+			val = DA906X_LDO_SL;
+			break;
+		default:
+			return -EINVAL;
+		}
+
+		if (sys_state = SYS_STATE_SUSPEND) {
+			if (!rinfo->suspend_sleep.addr)
+				return -EINVAL;
+			ret = da906x_reg_update(regl->hw,
+						rinfo->suspend_sleep.addr,
+						rinfo->suspend_sleep.mask,
+						val);
+		} else {
+			if (!rinfo->sleep.addr)
+				return -EINVAL;
+			ret = da906x_reg_update(regl->hw,
+						rinfo->sleep.addr,
+						rinfo->sleep.mask, val);
+		}
+	}
+
+	return ret;
+}
+
+static unsigned da906x_get_mode_internal(struct da906x_regulator *regl,
+					 int sys_state)
+{
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int val;
+	int addr;
+	int mask;
+	unsigned mode = 0;
+
+	/* Bucks use single mode register field for normal operation
+	   and suspend state. LDOs use sleep flags - one for normal
+	   and one for suspend state. */
+	if (rinfo->mode.addr) {
+		/* For BUCKs, there are 3 modes to map to */
+		val = da906x_reg_read(regl->hw, rinfo->mode.addr);
+		if (val < 0)
+			return val;
+
+		val = (val & rinfo->mode.mask) >> rinfo->mode.shift;
+		switch (val) {
+		default:
+		case BUCK_MODE_MANUAL:
+			mode = REGULATOR_MODE_FAST | REGULATOR_MODE_STANDBY;
+			/* Sleep flag bit decides the mode */
+			break;
+		case BUCK_MODE_SLEEP:
+			return REGULATOR_MODE_STANDBY;
+		case BUCK_MODE_SYNC:
+			return REGULATOR_MODE_FAST;
+		case BUCK_MODE_AUTO:
+			return REGULATOR_MODE_NORMAL;
+		}
+	} else if (rinfo->sleep.addr) {
+		/* For LDOs there are 2 modes to map to */
+		mode = REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
+		/* Sleep flag bit decides the mode */
+	} else {
+		/* No support */
+		return 0;
+	}
+
+	/* If sys_state = SYS_STATE_CURRENT, current regulator state
+	   is detected. */
+	if (sys_state = SYS_STATE_CURRENT && rinfo->suspend.addr) {
+		val = da906x_reg_read(regl->hw,
+					  rinfo->suspend.addr);
+		if (val < 0)
+			return val;
+
+		if (val & rinfo->suspend.mask)
+			sys_state = SYS_STATE_SUSPEND;
+		else
+			sys_state = SYS_STATE_NORMAL;
+	}
+
+	/* Read regulator mode from proper register,
+	   depending on selected system state */
+	if (sys_state = SYS_STATE_SUSPEND && rinfo->suspend_sleep.addr) {
+		addr = rinfo->suspend_sleep.addr;
+		mask = rinfo->suspend_sleep.mask;
+	} else {
+		addr = rinfo->sleep.addr;
+		mask = rinfo->sleep.mask;
+	}
+
+	val = da906x_reg_read(regl->hw, addr);
+	if (val < 0)
+		return val;
+
+	if (val & mask)
+		mode &= REGULATOR_MODE_STANDBY;
+	else
+		mode &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST;
+
+	return mode;
+}
+
+static int da906x_set_voltage(struct regulator_dev *rdev,
+				int min_uV, int max_uV, unsigned *selector)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct field *fvol = &regl->info->voltage;
+	int ret;
+	unsigned val;
+
+	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
+	if (val < 0)
+		return -EINVAL;
+
+	val = (val + fvol->offset) << fvol->shift;
+	ret = da906x_reg_update(regl->hw, fvol->addr, fvol->mask, val);
+	if (ret >= 0)
+		*selector = val;
+
+	return ret;
+}
+
+static int da906x_get_voltage_sel(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int sel;
+
+	sel = da906x_reg_read(regl->hw, rinfo->voltage.addr);
+	if (sel < 0)
+		return sel;
+
+	sel = (sel & rinfo->voltage.mask) >> rinfo->voltage.shift;
+	sel -= rinfo->voltage.offset;
+	if (sel < 0)
+		sel = 0;
+	if (sel >= rinfo->n_steps)
+		sel = rinfo->n_steps - 1;
+
+	return sel;
+}
+
+static int da906x_set_current_limit(struct regulator_dev *rdev,
+							int min_uA, int max_uA)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int val = INT_MAX;
+	unsigned sel = 0;
+	int n;
+	int tval;
+
+	if (!rinfo->current_limits)
+		return -EINVAL;
+
+	for (n = 0; n < rinfo->n_current_limits; n++) {
+		tval = rinfo->current_limits[n];
+		if (tval >= min_uA && tval <= max_uA && val > tval) {
+			val = tval;
+			sel = n;
+		}
+	}
+	if (val = INT_MAX)
+		return -EINVAL;
+
+	sel = (sel + rinfo->ilimit.offset) << rinfo->ilimit.shift;
+	return da906x_reg_update(regl->hw, rinfo->ilimit.addr,
+						rinfo->ilimit.mask, sel);
+}
+
+static int da906x_get_current_limit(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int sel;
+
+	sel = da906x_reg_read(regl->hw, rinfo->ilimit.addr);
+	if (sel < 0)
+		return sel;
+
+	sel = (sel & rinfo->ilimit.mask) >> rinfo->ilimit.shift;
+	sel -= rinfo->ilimit.offset;
+	if (sel < 0)
+		sel = 0;
+	if (sel >= rinfo->n_current_limits)
+		sel = rinfo->n_current_limits - 1;
+
+	return rinfo->current_limits[sel];
+}
+
+static int da906x_enable(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	int ret;
+
+	if (regl->info->suspend.mask) {
+		/* Make sure to exit from suspend mode on enable */
+		ret = da906x_reg_clear_bits(regl->hw, regl->info->suspend.addr,
+					    regl->info->suspend.mask);
+		if (ret < 0)
+			return ret;
+
+		/* BUCKs need mode update after wake-up from suspend state. */
+		ret = da906x_update_mode_internal(regl, SYS_STATE_NORMAL);
+		if (ret < 0)
+			return ret;
+	}
+
+	return regulator_enable_regmap(rdev);
+}
+
+static int da906x_set_mode(struct regulator_dev *rdev, unsigned mode)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	unsigned orig_mode = regl->mode;
+	int ret;
+
+	regl->mode = mode;
+	ret = da906x_update_mode_internal(regl, SYS_STATE_NORMAL);
+	if (ret)
+		regl->mode = orig_mode;
+
+	return ret;
+}
+
+static unsigned da906x_get_mode(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+
+	return da906x_get_mode_internal(regl, SYS_STATE_CURRENT);
+}
+
+static int da906x_get_status(struct regulator_dev *rdev)
+{
+	int ret = regulator_is_enabled_regmap(rdev);
+
+	if (ret = 0) {
+		ret = REGULATOR_STATUS_OFF;
+	} else if (ret > 0) {
+		ret = da906x_get_mode(rdev);
+		if (ret > 0)
+			ret = regulator_mode_to_status(ret);
+		else if (ret = 0)
+			ret = -EIO;
+	}
+
+	return ret;
+}
+
+static int da906x_set_suspend_voltage(struct regulator_dev *rdev, int uV)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	const struct field *fsusvol = &rinfo->suspend_voltage;
+	int val;
+	int ret;
+
+	val = regulator_map_voltage_linear(rdev, uV, uV);
+	if (val < 0)
+		return -EINVAL;
+
+	val = (val + fsusvol->offset) << fsusvol->shift;
+	ret = da906x_reg_update(regl->hw, fsusvol->addr, fsusvol->mask, val);
+
+	return ret;
+}
+
+static int da906x_suspend_enable(struct regulator_dev *rdev)
+{
+	int ret;
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct bfield *bsuspend = &regl->info->suspend;
+
+	ret = da906x_reg_set_bits(regl->hw, bsuspend->addr, bsuspend->mask);
+	return ret;
+}
+
+static int da906x_set_suspend_mode(struct regulator_dev *rdev, unsigned mode)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	int ret;
+
+	regl->suspend_mode = mode;
+	ret = da906x_update_mode_internal(regl, SYS_STATE_SUSPEND);
+	return ret;
+}
+
+/* Regulator event handlers */
+irqreturn_t da906x_ldo_lim_event(int irq, void *data)
+{
+	struct da906x_regulators *regulators = data;
+	struct da906x *hw = regulators->regulator[0].hw;
+	struct da906x_regulator *regl;
+	int bits;
+	int i;
+
+	bits = da906x_reg_read(hw, DA906X_REG_STATUS_D);
+	if (bits < 0)
+		return IRQ_HANDLED;
+
+	for (i = regulators->n_regulators - 1; i >= 0; i--) {
+		regl = &regulators->regulator[i];
+		if (regl->info->oc_event.addr != DA906X_REG_STATUS_D)
+			continue;
+
+		if (regl->info->oc_event.mask & bits)
+			regulator_notifier_call_chain(regl->rdev,
+					REGULATOR_EVENT_OVER_CURRENT, NULL);
+	}
+
+	return IRQ_HANDLED;
+}
+
+/*
+ * Probing and Initialisation functions
+ */
+static __devinit const struct da906x_regulator_info *
+da906x_get_regl_info(const struct da906x *da906x,
+		     const struct da906x_dev_model *model, int id)
+{
+	int m;
+
+	for (m = model->n_regulators - 1;
+	     model->regulator_info[m].id != id; m--) {
+		if (m <= 0)
+			return NULL;
+	}
+	return &model->regulator_info[m];
+}
+
+static __devinit int da906x_regulator_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_pdata *da906x_pdata = dev_get_platdata(da906x->dev);
+	struct da906x_regulators_pdata *regl_pdata;
+	struct da906x_regulator_data *rdata;
+	const struct da906x_dev_model *model;
+	struct da906x_regulators *regulators;
+	struct da906x_regulator *regl;
+	struct regulator_config config;
+	bool bcores_merged, bmem_bio_merged;
+	size_t size;
+	int n;
+	int ret;
+
+	if (!da906x_pdata) {
+		dev_err(&pdev->dev, "No platform init data supplied\n");
+		return -ENODEV;
+	}
+	regl_pdata = da906x_pdata->regulators_pdata;
+
+	if (!regl_pdata || regl_pdata->n_regulators = 0) {
+		dev_err(&pdev->dev,
+			"No regulators defined for the platform\n");
+		return -ENODEV;
+	}
+
+	/* Find regulators set for particular device model */
+	for (model = regulators_models; model->regulator_info; model++) {
+		if (model->dev_model = da906x_model(da906x))
+			break;
+	}
+	if (!model->regulator_info) {
+		dev_err(&pdev->dev, "Chip model not recognised (%u)\n",
+			da906x_model(da906x));
+		return -ENODEV;
+	}
+
+	ret = da906x_reg_read(da906x, DA906X_REG_CONFIG_H);
+	if (ret < 0) {
+		dev_err(&pdev->dev,
+			"Error while reading BUCKs configuration\n");
+		return -EIO;
+	}
+	bcores_merged = (ret & DA906X_BCORE_MERGE) ? true : false;
+	bmem_bio_merged = (ret & DA906X_BUCK_MERGE) ? true : false;
+
+	/* Allocate memory required by usable regulators */
+	size = sizeof(struct da906x_regulators) +
+		regl_pdata->n_regulators * sizeof(struct da906x_regulator);
+	regulators = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
+	if (!regulators) {
+		dev_err(&pdev->dev, "No memory for regulators\n");
+		return -ENOMEM;
+	}
+
+	regulators->n_regulators = regl_pdata->n_regulators;
+	platform_set_drvdata(pdev, regulators);
+
+	/* Register all regulators declared in platform information */
+	n = 0;
+	while (n < regulators->n_regulators) {
+		rdata = &regl_pdata->regulator_data[n];
+
+		/* Check regulator ID against merge mode configuration */
+		switch (rdata->id) {
+		case DA9063_ID_BCORE1:
+		case DA9063_ID_BCORE2:
+			if (bcores_merged) {
+				dev_err(&pdev->dev,
+					"Cannot use BCORE1 and BCORE2 separately, when in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		case DA9063_ID_BMEM:
+		case DA9063_ID_BIO:
+			if (bmem_bio_merged) {
+				dev_err(&pdev->dev,
+					"Cannot use BMEM and BIO separately, when in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		case DA9063_ID_BCORES_MERGED:
+			if (!bcores_merged) {
+				dev_err(&pdev->dev,
+					"BCORE1 and BCORE2 are unavailable in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		case DA9063_ID_BMEM_BIO_MERGED:
+			if (!bmem_bio_merged) {
+				dev_err(&pdev->dev,
+					"BMEM and BIO are unavailable in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		}
+
+		/* Initialise regulator structure */
+		regl = &regulators->regulator[n];
+		regl->hw = da906x;
+		regl->info = da906x_get_regl_info(da906x, model, rdata->id);
+		if (!regl->info) {
+			dev_err(&pdev->dev,
+				"Invalid regulator ID in platform data\n");
+			ret = -EINVAL;
+			goto err;
+		}
+		regl->desc.type = REGULATOR_VOLTAGE;
+		regl->desc.owner = THIS_MODULE;
+		regl->desc.name = regl->info->name;
+		regl->desc.id = rdata->id;
+		regl->desc.ops = regl->info->ops;
+		regl->desc.n_voltages = regl->info->n_steps;
+		regl->desc.min_uV = regl->info->min_uV;
+		regl->desc.uV_step = regl->info->step_uV;
+		regl->desc.enable_reg = regl->info->enable.addr +
+					DA906X_MAPPING_BASE;
+		regl->desc.enable_mask = regl->info->enable.mask;
+
+		/* Register regulator */
+		config.dev = &pdev->dev;
+		config.init_data = rdata->initdata;
+		config.driver_data = regl;
+		config.regmap = da906x->regmap;
+		regl->rdev = regulator_register(&regl->desc, &config);
+		if (IS_ERR_OR_NULL(regl->rdev)) {
+			dev_err(&pdev->dev,
+				"Failed to register %s regulator\n",
+				regl->info->name);
+			ret = PTR_ERR(regl->rdev);
+			goto err;
+		}
+		n++;
+
+		/* Get current modes of operation (A/B voltage selection)
+		   for normal and suspend states */
+		ret = da906x_get_mode_internal(regl, SYS_STATE_NORMAL);
+		if (ret < 0) {
+			dev_err(&pdev->dev,
+				"Failed to read %s regulator's mode\n",
+				regl->info->name);
+			goto err;
+		}
+		if (ret = 0)
+			regl->mode = REGULATOR_MODE_NORMAL;
+		else
+			regl->mode = ret;
+
+		ret = da906x_get_mode_internal(regl, SYS_STATE_SUSPEND);
+		if (ret < 0) {
+			dev_err(&pdev->dev,
+				"Failed to read %s regulator's mode\n",
+				regl->info->name);
+			goto err;
+		}
+		if (ret = 0)
+			regl->suspend_mode = REGULATOR_MODE_NORMAL;
+		else
+			regl->mode = ret;
+	}
+
+	/* LDOs overcurrent event support */
+	regulators->irq_ldo_lim = platform_get_irq_byname(pdev, "LDO_LIM");
+	if (regulators->irq_ldo_lim >= 0) {
+		ret = request_threaded_irq(regulators->irq_ldo_lim,
+					   NULL, da906x_ldo_lim_event,
+					   IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+					   "LDO_LIM", regulators);
+		if (ret) {
+			dev_err(&pdev->dev,
+					"Failed to request LDO_LIM IRQ.\n");
+			regulators->irq_ldo_lim = -ENXIO;
+		}
+	}
+
+	return 0;
+
+err:
+	/* Wind back regulators registeration */
+	while (--n >= 0) {
+		regulator_unregister(regulators->regulator[n].rdev);
+	}
+
+	return ret;
+}
+
+static int __devexit da906x_regulator_remove(struct platform_device *pdev)
+{
+	struct da906x_regulators *regulators = platform_get_drvdata(pdev);
+	struct da906x_regulator *regl;
+
+	free_irq(regulators->irq_ldo_lim, regulators);
+	free_irq(regulators->irq_uvov, regulators);
+
+	for (regl = &regulators->regulator[regulators->n_regulators - 1];
+	     regl >= &regulators->regulator[0]; regl--)
+		regulator_unregister(regl->rdev);
+
+	return 0;
+}
+
+static struct platform_driver da906x_regulator_driver = {
+	.driver = {
+		.name = DA906X_DRVNAME_REGULATORS,
+		.owner = THIS_MODULE,
+	},
+	.probe = da906x_regulator_probe,
+	.remove = __devexit_p(da906x_regulator_remove),
+};
+
+static int __init da906x_regulator_init(void)
+{
+	return platform_driver_register(&da906x_regulator_driver);
+}
+subsys_initcall(da906x_regulator_init);
+
+static void __exit da906x_regulator_cleanup(void)
+{
+	platform_driver_unregister(&da906x_regulator_driver);
+}
+module_exit(da906x_regulator_cleanup);
+
+
+/* Module information */
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>");
+MODULE_DESCRIPTION("DA906x regulators driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("paltform:" DA906X_DRVNAME_REGULATORS);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [RFC PATCH 0/8] DA906x PMIC driver
  2012-08-24  8:32 ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-24 13:45 ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 13:45 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

Greetings,

The following patch set adds new multifunction device providing support for
DA906x PMIC chips.

I am resending this as it looks, the first send failed.

Please add some comments to the driver patch, which targets Linux Kernel v3.6.

Thank you,

---
Krystian Garbaciak (8):
  mfd: Add Dialog DA906x core driver.
  regulator: Add Dialog DA906x voltage regulators support.
  rtc: Add RTC driver for DA906x PMIC.
  hwmon: Add DA906x hardware monitoring support.
  input: Add support for DA906x PMIC OnKey detection.
  input: Add support for DA906x vibration motor driver.
  watchdog: Add DA906x PMIC watchdog driver.
  leds: Add DA906x PMIC LED driver.

 drivers/hwmon/Kconfig                 |    6 +
 drivers/hwmon/Makefile                |    1 +
 drivers/hwmon/da906x-hwmon.c          |  393 ++++++++++++
 drivers/input/misc/Kconfig            |   13 +
 drivers/input/misc/Makefile           |    2 +
 drivers/input/misc/da906x-onkey.c     |  139 +++++
 drivers/input/misc/da906x-vibration.c |  153 +++++
 drivers/leds/Kconfig                  |    8 +
 drivers/leds/Makefile                 |    1 +
 drivers/leds/leds-da906x.c            |  438 +++++++++++++
 drivers/mfd/Kconfig                   |   11 +
 drivers/mfd/Makefile                  |    4 +
 drivers/mfd/da906x-core.c             |  228 +++++++
 drivers/mfd/da906x-i2c.c              |  389 ++++++++++++
 drivers/mfd/da906x-irq.c              |  192 ++++++
 drivers/regulator/Kconfig             |    6 +
 drivers/regulator/Makefile            |    1 +
 drivers/regulator/da906x-regulator.c  | 1018 ++++++++++++++++++++++++++++++
 drivers/rtc/Kconfig                   |    7 +
 drivers/rtc/Makefile                  |    1 +
 drivers/rtc/rtc-da906x.c              |  379 ++++++++++++
 drivers/watchdog/Kconfig              |   27 +
 drivers/watchdog/Makefile             |    1 +
 drivers/watchdog/da906x_wdt.c         |  276 +++++++++
 include/linux/mfd/da906x/core.h       |  121 ++++
 include/linux/mfd/da906x/pdata.h      |  114 ++++
 include/linux/mfd/da906x/registers.h  | 1093 +++++++++++++++++++++++++++++++++
 27 files changed, 5022 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/da906x-hwmon.c
 create mode 100644 drivers/input/misc/da906x-onkey.c
 create mode 100644 drivers/input/misc/da906x-vibration.c
 create mode 100644 drivers/leds/leds-da906x.c
 create mode 100644 drivers/mfd/da906x-core.c
 create mode 100644 drivers/mfd/da906x-i2c.c
 create mode 100644 drivers/mfd/da906x-irq.c
 create mode 100644 drivers/regulator/da906x-regulator.c
 create mode 100644 drivers/rtc/rtc-da906x.c
 create mode 100644 drivers/watchdog/da906x_wdt.c
 create mode 100644 include/linux/mfd/da906x/core.h
 create mode 100644 include/linux/mfd/da906x/pdata.h
 create mode 100644 include/linux/mfd/da906x/registers.h


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [lm-sensors] [RFC PATCH 0/8] DA906x PMIC driver
@ 2012-08-24 13:45 ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 13:45 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

Greetings,

The following patch set adds new multifunction device providing support for
DA906x PMIC chips.

I am resending this as it looks, the first send failed.

Please add some comments to the driver patch, which targets Linux Kernel v3.6.

Thank you,

---
Krystian Garbaciak (8):
  mfd: Add Dialog DA906x core driver.
  regulator: Add Dialog DA906x voltage regulators support.
  rtc: Add RTC driver for DA906x PMIC.
  hwmon: Add DA906x hardware monitoring support.
  input: Add support for DA906x PMIC OnKey detection.
  input: Add support for DA906x vibration motor driver.
  watchdog: Add DA906x PMIC watchdog driver.
  leds: Add DA906x PMIC LED driver.

 drivers/hwmon/Kconfig                 |    6 +
 drivers/hwmon/Makefile                |    1 +
 drivers/hwmon/da906x-hwmon.c          |  393 ++++++++++++
 drivers/input/misc/Kconfig            |   13 +
 drivers/input/misc/Makefile           |    2 +
 drivers/input/misc/da906x-onkey.c     |  139 +++++
 drivers/input/misc/da906x-vibration.c |  153 +++++
 drivers/leds/Kconfig                  |    8 +
 drivers/leds/Makefile                 |    1 +
 drivers/leds/leds-da906x.c            |  438 +++++++++++++
 drivers/mfd/Kconfig                   |   11 +
 drivers/mfd/Makefile                  |    4 +
 drivers/mfd/da906x-core.c             |  228 +++++++
 drivers/mfd/da906x-i2c.c              |  389 ++++++++++++
 drivers/mfd/da906x-irq.c              |  192 ++++++
 drivers/regulator/Kconfig             |    6 +
 drivers/regulator/Makefile            |    1 +
 drivers/regulator/da906x-regulator.c  | 1018 ++++++++++++++++++++++++++++++
 drivers/rtc/Kconfig                   |    7 +
 drivers/rtc/Makefile                  |    1 +
 drivers/rtc/rtc-da906x.c              |  379 ++++++++++++
 drivers/watchdog/Kconfig              |   27 +
 drivers/watchdog/Makefile             |    1 +
 drivers/watchdog/da906x_wdt.c         |  276 +++++++++
 include/linux/mfd/da906x/core.h       |  121 ++++
 include/linux/mfd/da906x/pdata.h      |  114 ++++
 include/linux/mfd/da906x/registers.h  | 1093 +++++++++++++++++++++++++++++++++
 27 files changed, 5022 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/da906x-hwmon.c
 create mode 100644 drivers/input/misc/da906x-onkey.c
 create mode 100644 drivers/input/misc/da906x-vibration.c
 create mode 100644 drivers/leds/leds-da906x.c
 create mode 100644 drivers/mfd/da906x-core.c
 create mode 100644 drivers/mfd/da906x-i2c.c
 create mode 100644 drivers/mfd/da906x-irq.c
 create mode 100644 drivers/regulator/da906x-regulator.c
 create mode 100644 drivers/rtc/rtc-da906x.c
 create mode 100644 drivers/watchdog/da906x_wdt.c
 create mode 100644 include/linux/mfd/da906x/core.h
 create mode 100644 include/linux/mfd/da906x/pdata.h
 create mode 100644 include/linux/mfd/da906x/registers.h


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 1/8] mfd: Add Dialog DA906x core driver.
  2012-08-24 13:45 ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-24 13:50   ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 13:50 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

This is MFD module providing access to registers and interrupts of DA906x
series PMIC. It is used by other functional modules, registered as MFD cells.
Driver uses regmap with paging to access extended register list. Register map
is divided into two pages, where the second page is used during initialisation.

This module provides support to following functional cells:
 - Regulators
 - RTC
 - HWMON
 - OnKey (power key misc input device)
 - Vibration (force-feedback input device)
 - Watchdog
 - LEDs

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/mfd/Kconfig                  |   11 +
 drivers/mfd/Makefile                 |    4 +
 drivers/mfd/da906x-core.c            |  228 +++++++
 drivers/mfd/da906x-i2c.c             |  389 ++++++++++++
 drivers/mfd/da906x-irq.c             |  192 ++++++
 include/linux/mfd/da906x/core.h      |  121 ++++
 include/linux/mfd/da906x/pdata.h     |  114 ++++
 include/linux/mfd/da906x/registers.h | 1093 ++++++++++++++++++++++++++++++++++
 8 files changed, 2152 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mfd/da906x-core.c
 create mode 100644 drivers/mfd/da906x-i2c.c
 create mode 100644 drivers/mfd/da906x-irq.c
 create mode 100644 include/linux/mfd/da906x/core.h
 create mode 100644 include/linux/mfd/da906x/pdata.h
 create mode 100644 include/linux/mfd/da906x/registers.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index b1a1462..bf2a766 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -441,6 +441,17 @@ config MFD_DA9052_I2C
 	  for accessing the device, additional drivers must be enabled in
 	  order to use the functionality of the device.
 
+config MFD_DA906X
+	bool "Dialog Semiconductor DA906X PMIC Support"
+	depends on I2C=y
+	select MFD_CORE
+	select REGMAP_I2C
+	select REGMAP_IRQ
+	help
+	  Support for the Dialog Semiconductor DA906X PMIC. This includes
+	  I2C driver and core APIs, additional drivers must be enabled in
+	  order to use the functionality of the device.
+
 config PMIC_ADP5520
 	bool "Analog Devices ADP5520/01 MFD PMIC Core Support"
 	depends on I2C=y
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 79dd22d..f5a8432 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -90,8 +90,12 @@ obj-$(CONFIG_PMIC_DA9052)	+= da9052-core.o
 obj-$(CONFIG_MFD_DA9052_SPI)	+= da9052-spi.o
 obj-$(CONFIG_MFD_DA9052_I2C)	+= da9052-i2c.o
 
+da906x-objs			:= da906x-core.o da906x-irq.o da906x-i2c.o
+obj-$(CONFIG_MFD_DA906X)	+= da906x.o
+
 obj-$(CONFIG_MFD_MAX77686)	+= max77686.o max77686-irq.o
 obj-$(CONFIG_MFD_MAX77693)	+= max77693.o max77693-irq.o
+
 max8925-objs			:= max8925-core.o max8925-i2c.o
 obj-$(CONFIG_MFD_MAX8925)	+= max8925.o
 obj-$(CONFIG_MFD_MAX8997)	+= max8997.o max8997-irq.o
diff --git a/drivers/mfd/da906x-core.c b/drivers/mfd/da906x-core.c
new file mode 100644
index 0000000..fb3249f
--- /dev/null
+++ b/drivers/mfd/da906x-core.c
@@ -0,0 +1,228 @@
+/*
+ * da906x-core.c: Device access for Dialog DA906x modules
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>,
+ *         Michal Hajduk <michal.hajduk@diasemi.com>
+ *
+ *  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/init.h>
+#include <linux/slab.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/mutex.h>
+#include <linux/mfd/core.h>
+#include <linux/regmap.h>
+
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+#include <linux/mfd/da906x/registers.h>
+
+#include <linux/proc_fs.h>
+#include <linux/kthread.h>
+#include <linux/uaccess.h>
+
+
+static struct resource da906x_regulators_resources[] = {
+	{
+		.name	= "LDO_LIM",
+		.start	= DA906X_IRQ_LDO_LIM,
+		.end	= DA906X_IRQ_LDO_LIM,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct resource da906x_rtc_resources[] = {
+	{
+		.name	= "ALARM",
+		.start	= DA906X_IRQ_ALARM,
+		.end	= DA906X_IRQ_ALARM,
+		.flags	= IORESOURCE_IRQ,
+	},
+	{
+		.name	= "TICK",
+		.start	= DA906X_IRQ_TICK,
+		.end	= DA906X_IRQ_TICK,
+		.flags	= IORESOURCE_IRQ,
+	}
+};
+
+static struct resource da906x_onkey_resources[] = {
+	{
+		.start	= DA906X_IRQ_ONKEY,
+		.end	= DA906X_IRQ_ONKEY,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct resource da906x_hwmon_resources[] = {
+	{
+		.start	= DA906X_IRQ_ADC_RDY,
+		.end	= DA906X_IRQ_ADC_RDY,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+
+static struct mfd_cell da906x_devs[] = {
+	{
+		.name		= DA906X_DRVNAME_REGULATORS,
+		.num_resources	= ARRAY_SIZE(da906x_regulators_resources),
+		.resources	= da906x_regulators_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_LEDS,
+	},
+	{
+		.name		= DA906X_DRVNAME_WATCHDOG,
+	},
+	{
+		.name		= DA906X_DRVNAME_HWMON,
+		.num_resources	= ARRAY_SIZE(da906x_hwmon_resources),
+		.resources	= da906x_hwmon_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_ONKEY,
+		.num_resources	= ARRAY_SIZE(da906x_onkey_resources),
+		.resources	= da906x_onkey_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_RTC,
+		.num_resources	= ARRAY_SIZE(da906x_rtc_resources),
+		.resources	= da906x_rtc_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_VIBRATION,
+	},
+};
+
+inline unsigned int da906x_to_range_reg(u16 reg)
+{
+	return reg + DA906X_MAPPING_BASE;
+}
+
+int da906x_reg_read(struct da906x *da906x, u16 reg)
+{
+	unsigned int val;
+	int ret;
+
+	ret = regmap_read(da906x->regmap, da906x_to_range_reg(reg), &val);
+	if (ret < 0)
+		return ret;
+
+	return val;
+}
+
+int da906x_reg_write(struct da906x *da906x, u16 reg, u8 val)
+{
+	return regmap_write(da906x->regmap, da906x_to_range_reg(reg), val);
+}
+
+int da906x_block_read(struct da906x *da906x, u16 reg, int bytes, u8 *dst)
+{
+	return regmap_bulk_read(da906x->regmap, da906x_to_range_reg(reg),
+				dst, bytes);
+}
+
+int da906x_block_write(struct da906x *da906x, u16 reg, int bytes, const u8 *src)
+{
+	return regmap_bulk_write(da906x->regmap, da906x_to_range_reg(reg),
+				 src, bytes);
+}
+
+int da906x_reg_update(struct da906x *da906x, u16 reg, u8 mask, u8 val)
+{
+	return regmap_update_bits(da906x->regmap, da906x_to_range_reg(reg),
+				  mask, val);
+}
+
+int da906x_reg_set_bits(struct da906x *da906x, u16 reg, u8 mask)
+{
+	return da906x_reg_update(da906x, reg, mask, mask);
+}
+
+int da906x_reg_clear_bits(struct da906x *da906x, u16 reg, u8 mask)
+{
+	return da906x_reg_update(da906x, reg, mask, 0);
+}
+
+int da906x_device_init(struct da906x *da906x, unsigned int irq)
+{
+	struct da906x_pdata *pdata = da906x->dev->platform_data;
+	int ret = 0;
+	int model;
+	unsigned short revision;
+
+	mutex_init(&da906x->io_mutex);
+
+	if (pdata == NULL) {
+		dev_err(da906x->dev, "Platform data not specified.\n");
+		return -EINVAL;
+	}
+	da906x->flags = pdata->flags;
+	da906x->irq_base = pdata->irq_base;
+	da906x->chip_irq = irq;
+
+	if (pdata->init != NULL) {
+		ret = pdata->init(da906x);
+		if (ret != 0) {
+			dev_err(da906x->dev,
+				"Platform initialization failed.\n");
+			return ret;
+		}
+	}
+
+	model = da906x_reg_read(da906x, DA906X_REG_CHIP_ID);
+	if (model < 0) {
+		dev_err(da906x->dev, "Cannot read chip model id.\n");
+		return -EIO;
+	}
+
+	ret = da906x_reg_read(da906x, DA906X_REG_CHIP_VARIANT);
+	if (ret < 0) {
+		dev_err(da906x->dev, "Cannot read chip revision id.\n");
+		return -EIO;
+	}
+
+	revision = ret >> DA906X_CHIP_VARIANT_SHIFT;
+
+	da906x_set_model_rev(da906x, model, revision);
+
+	dev_info(da906x->dev,
+		 "Device detected (model-ID: 0x%02X  rev-ID: 0x%02X)\n",
+		 model, revision);
+
+	ret = da906x_irq_init(da906x);
+	if (ret) {
+		dev_err(da906x->dev, "Cannot initialize interrupts.\n");
+		return ret;
+	}
+
+	ret = mfd_add_devices(da906x->dev, -1, da906x_devs,
+			      ARRAY_SIZE(da906x_devs), NULL, da906x->irq_base);
+	if (ret)
+		dev_err(da906x->dev, "Cannot add MFD cells\n");
+
+	return ret;
+}
+
+void da906x_device_exit(struct da906x *da906x)
+{
+	mfd_remove_devices(da906x->dev);
+	da906x_irq_exit(da906x);
+}
+
+MODULE_DESCRIPTION("PMIC driver for Dialog DA906X");
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>, Michal Hajduk <michal.hajduk@diasemi.com>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DA906X_DRVNAME_CORE);
diff --git a/drivers/mfd/da906x-i2c.c b/drivers/mfd/da906x-i2c.c
new file mode 100644
index 0000000..90b9e23
--- /dev/null
+++ b/drivers/mfd/da906x-i2c.c
@@ -0,0 +1,389 @@
+/* da906x-i2c.c: Interrupt support for Dialog DA906x
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/i2c.h>
+#include <linux/regmap.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/err.h>
+
+#include <linux/mfd/core.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+#include <linux/mfd/da906x/registers.h>
+
+
+#define RD		0x01	/* Readable register */
+#define WR		0x02	/* Writable register */
+#define VOL		0x04	/* Volatile register */
+
+/* Flags for virtual registers (mapped starting from DA906X_MAPPING_BASE) */
+const unsigned char da906x_reg_flg[] = {
+	[DA906X_REG_STATUS_A] =		RD | VOL,
+	[DA906X_REG_STATUS_B] =		RD | VOL,
+	[DA906X_REG_STATUS_C] =		RD | VOL,
+	[DA906X_REG_STATUS_D] =		RD | VOL,
+	[DA906X_REG_FAULT_LOG] =	RD | WR | VOL,
+	[DA906X_REG_EVENT_A] =		RD | WR | VOL,
+	[DA906X_REG_EVENT_B] =		RD | WR | VOL,
+	[DA906X_REG_EVENT_C] =		RD | WR | VOL,
+	[DA906X_REG_EVENT_D] =		RD | WR | VOL,
+	[DA906X_REG_IRQ_MASK_A] =	RD | WR,
+	[DA906X_REG_IRQ_MASK_B] =	RD | WR,
+	[DA906X_REG_IRQ_MASK_C] =	RD | WR,
+	[DA906X_REG_IRQ_MASK_D] =	RD | WR,
+	[DA906X_REG_CONTROL_A] =	RD | WR,
+	[DA906X_REG_CONTROL_B] =	RD | WR,
+	[DA906X_REG_CONTROL_C] =	RD | WR,
+	[DA906X_REG_CONTROL_D] =	RD | WR,
+	[DA906X_REG_CONTROL_E] =	RD | WR,
+	[DA906X_REG_CONTROL_F] =	RD | WR | VOL,
+	[DA906X_REG_PD_DIS] =		RD | WR,
+
+	[DA906X_REG_GPIO_0_1] =		RD | WR,
+	[DA906X_REG_GPIO_2_3] =		RD | WR,
+	[DA906X_REG_GPIO_4_5] =		RD | WR,
+	[DA906X_REG_GPIO_6_7] =		RD | WR,
+	[DA906X_REG_GPIO_8_9] =		RD | WR,
+	[DA906X_REG_GPIO_10_11] =	RD | WR,
+	[DA906X_REG_GPIO_12_13] =	RD | WR,
+	[DA906X_REG_GPIO_14_15] =	RD | WR,
+	[DA906X_REG_GPIO_MODE_0_7] =	RD | WR,
+	[DA906X_REG_GPIO_MODE_8_15] =	RD | WR,
+	[DA906X_REG_GPIO_SWITCH_CONT] =	RD | WR,
+
+	[DA906X_REG_BCORE2_CONT] =	RD | WR,
+	[DA906X_REG_BCORE1_CONT] =	RD | WR,
+	[DA906X_REG_BPRO_CONT] =	RD | WR,
+	[DA906X_REG_BMEM_CONT] =	RD | WR,
+	[DA906X_REG_BIO_CONT] =		RD | WR,
+	[DA906X_REG_BPERI_CONT] =	RD | WR,
+	[DA906X_REG_LDO1_CONT] =	RD | WR,
+	[DA906X_REG_LDO2_CONT] =	RD | WR,
+	[DA906X_REG_LDO3_CONT] =	RD | WR,
+	[DA906X_REG_LDO4_CONT] =	RD | WR,
+	[DA906X_REG_LDO5_CONT] =	RD | WR,
+	[DA906X_REG_LDO6_CONT] =	RD | WR,
+	[DA906X_REG_LDO7_CONT] =	RD | WR,
+	[DA906X_REG_LDO8_CONT] =	RD | WR,
+	[DA906X_REG_LDO9_CONT] =	RD | WR,
+	[DA906X_REG_LDO10_CONT] =	RD | WR,
+	[DA906X_REG_LDO11_CONT] =	RD | WR,
+	[DA906X_REG_VIB] =		RD | WR,
+	[DA906X_REG_DVC_1] =		RD | WR,
+	[DA906X_REG_DVC_2] =		RD | WR,
+
+	[DA906X_REG_ADC_MAN] =		RD | WR | VOL,
+	[DA906X_REG_ADC_CONT] =		RD | WR,
+	[DA906X_REG_VSYS_MON] =		RD | WR,
+	[DA906X_REG_ADC_RES_L] =	RD | VOL,
+	[DA906X_REG_ADC_RES_H] =	RD | VOL,
+	[DA906X_REG_VSYS_RES] =		RD | VOL,
+	[DA906X_REG_ADCIN1_RES] =	RD | VOL,
+	[DA906X_REG_ADCIN2_RES] =	RD | VOL,
+	[DA906X_REG_ADCIN3_RES] =	RD | VOL,
+	[DA906X_REG_MON1_RES] =		RD | VOL,
+	[DA906X_REG_MON2_RES] =		RD | VOL,
+	[DA906X_REG_MON3_RES] =		RD | VOL,
+
+	[DA906X_REG_COUNT_S] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_MI] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_H] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_D] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_MO] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_Y] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_MI] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_H] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_D] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_MO] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_Y] =		RD | WR | VOL,
+	[DA906X_REG_SECOND_A] =		RD | VOL,
+	[DA906X_REG_SECOND_B] =		RD | VOL,
+	[DA906X_REG_SECOND_C] =		RD | VOL,
+	[DA906X_REG_SECOND_D] =		RD | VOL,
+
+	[DA906X_REG_SEQ] =		RD | WR,
+	[DA906X_REG_SEQ_TIMER] =	RD | WR,
+	[DA906X_REG_ID_2_1] =		RD | WR,
+	[DA906X_REG_ID_4_3] =		RD | WR,
+	[DA906X_REG_ID_6_5] =		RD | WR,
+	[DA906X_REG_ID_8_7] =		RD | WR,
+	[DA906X_REG_ID_10_9] =		RD | WR,
+	[DA906X_REG_ID_12_11] =		RD | WR,
+	[DA906X_REG_ID_14_13] =		RD | WR,
+	[DA906X_REG_ID_16_15] =		RD | WR,
+	[DA906X_REG_ID_18_17] =		RD | WR,
+	[DA906X_REG_ID_20_19] =		RD | WR,
+	[DA906X_REG_ID_22_21] =		RD | WR,
+	[DA906X_REG_ID_24_23] =		RD | WR,
+	[DA906X_REG_ID_26_25] =		RD | WR,
+	[DA906X_REG_ID_28_27] =		RD | WR,
+	[DA906X_REG_ID_30_29] =		RD | WR,
+	[DA906X_REG_ID_32_31] =		RD | WR,
+	[DA906X_REG_SEQ_A] =		RD | WR,
+	[DA906X_REG_SEQ_B] =		RD | WR,
+	[DA906X_REG_WAIT] =		RD | WR,
+	[DA906X_REG_EN_32K] =		RD | WR,
+	[DA906X_REG_RESET] =		RD | WR,
+
+	[DA906X_REG_BUCK_ILIM_A] =	RD | WR,
+	[DA906X_REG_BUCK_ILIM_B] =	RD | WR,
+	[DA906X_REG_BUCK_ILIM_C] =	RD | WR,
+	[DA906X_REG_BCORE2_CFG] =	RD | WR,
+	[DA906X_REG_BCORE1_CFG] =	RD | WR,
+	[DA906X_REG_BPRO_CFG] =		RD | WR,
+	[DA906X_REG_BIO_CFG] =		RD | WR,
+	[DA906X_REG_BMEM_CFG] =		RD | WR,
+	[DA906X_REG_BPERI_CFG] =	RD | WR,
+	[DA906X_REG_VBCORE2_A] =	RD | WR,
+	[DA906X_REG_VBCORE1_A] =	RD | WR,
+	[DA906X_REG_VBPRO_A] =		RD | WR,
+	[DA906X_REG_VBMEM_A] =		RD | WR,
+	[DA906X_REG_VBIO_A] =		RD | WR,
+	[DA906X_REG_VBPERI_A] =		RD | WR,
+	[DA906X_REG_VLDO1_A] =		RD | WR,
+	[DA906X_REG_VLDO2_A] =		RD | WR,
+	[DA906X_REG_VLDO3_A] =		RD | WR,
+	[DA906X_REG_VLDO4_A] =		RD | WR,
+	[DA906X_REG_VLDO5_A] =		RD | WR,
+	[DA906X_REG_VLDO6_A] =		RD | WR,
+	[DA906X_REG_VLDO7_A] =		RD | WR,
+	[DA906X_REG_VLDO8_A] =		RD | WR,
+	[DA906X_REG_VLDO9_A] =		RD | WR,
+	[DA906X_REG_VLDO10_A] =		RD | WR,
+	[DA906X_REG_VLDO11_A] =		RD | WR,
+	[DA906X_REG_VBCORE2_B] =	RD | WR,
+	[DA906X_REG_VBCORE1_B] =	RD | WR,
+	[DA906X_REG_VBPRO_B] =		RD | WR,
+	[DA906X_REG_VBMEM_B] =		RD | WR,
+	[DA906X_REG_VBIO_B] =		RD | WR,
+	[DA906X_REG_VBPERI_B] =		RD | WR,
+	[DA906X_REG_VLDO1_B] =		RD | WR,
+	[DA906X_REG_VLDO2_B] =		RD | WR,
+	[DA906X_REG_VLDO3_B] =		RD | WR,
+	[DA906X_REG_VLDO4_B] =		RD | WR,
+	[DA906X_REG_VLDO5_B] =		RD | WR,
+	[DA906X_REG_VLDO6_B] =		RD | WR,
+	[DA906X_REG_VLDO7_B] =		RD | WR,
+	[DA906X_REG_VLDO8_B] =		RD | WR,
+	[DA906X_REG_VLDO9_B] =		RD | WR,
+	[DA906X_REG_VLDO10_B] =		RD | WR,
+	[DA906X_REG_VLDO11_B] =		RD | WR,
+
+	[DA906X_REG_BBAT_CONT] =	RD | WR,
+
+	[DA906X_REG_GPO11_LED] =	RD | WR,
+	[DA906X_REG_GPO14_LED] =	RD | WR,
+	[DA906X_REG_GPO15_LED] =	RD | WR,
+
+	[DA906X_REG_ADC_CFG] =		RD | WR,
+	[DA906X_REG_AUTO1_HIGH] =	RD | WR,
+	[DA906X_REG_AUTO1_LOW] =	RD | WR,
+	[DA906X_REG_AUTO2_HIGH] =	RD | WR,
+	[DA906X_REG_AUTO2_LOW] =	RD | WR,
+	[DA906X_REG_AUTO3_HIGH] =	RD | WR,
+	[DA906X_REG_AUTO3_LOW] =	RD | WR,
+
+	[DA906X_REG_T_OFFSET] =		RD,
+	[DA906X_REG_CONFIG_H] =		RD,
+	[DA906X_REG_CONFIG_I] =		RD | WR,
+	[DA906X_REG_MON_REG_1] =	RD | WR,
+	[DA906X_REG_MON_REG_2] =	RD | WR,
+	[DA906X_REG_MON_REG_3] =	RD | WR,
+	[DA906X_REG_MON_REG_4] =	RD | WR,
+	[DA906X_REG_MON_REG_5] =	RD | VOL,
+	[DA906X_REG_MON_REG_6] =	RD | VOL,
+	[DA906X_REG_TRIM_CLDR] =	RD,
+
+	[DA906X_REG_GP_ID_0] =		RD | WR,
+	[DA906X_REG_GP_ID_1] =		RD | WR,
+	[DA906X_REG_GP_ID_2] =		RD | WR,
+	[DA906X_REG_GP_ID_3] =		RD | WR,
+	[DA906X_REG_GP_ID_4] =		RD | WR,
+	[DA906X_REG_GP_ID_5] =		RD | WR,
+	[DA906X_REG_GP_ID_6] =		RD | WR,
+	[DA906X_REG_GP_ID_7] =		RD | WR,
+	[DA906X_REG_GP_ID_8] =		RD | WR,
+	[DA906X_REG_GP_ID_9] =		RD | WR,
+	[DA906X_REG_GP_ID_10] =		RD | WR,
+	[DA906X_REG_GP_ID_11] =		RD | WR,
+	[DA906X_REG_GP_ID_12] =		RD | WR,
+	[DA906X_REG_GP_ID_13] =		RD | WR,
+	[DA906X_REG_GP_ID_14] =		RD | WR,
+	[DA906X_REG_GP_ID_15] =		RD | WR,
+	[DA906X_REG_GP_ID_16] =		RD | WR,
+	[DA906X_REG_GP_ID_17] =		RD | WR,
+	[DA906X_REG_GP_ID_18] =		RD | WR,
+	[DA906X_REG_GP_ID_19] =		RD | WR,
+
+	[DA906X_REG_CHIP_ID] =		RD,
+	[DA906X_REG_CHIP_VARIANT] =	RD,
+};
+
+static bool da906x_reg_readable(struct device *dev, unsigned int reg)
+{
+	if (reg < DA906X_MAPPING_BASE) {
+		return true;
+	} else {
+		reg -= DA906X_MAPPING_BASE;
+		if (da906x_reg_flg[reg] & RD)
+			return true;
+		else
+			return false;
+	}
+}
+
+static bool da906x_reg_writable(struct device *dev, unsigned int reg)
+{
+	if (reg < DA906X_MAPPING_BASE) {
+		return true;
+	} else {
+		reg -= DA906X_MAPPING_BASE;
+		if (da906x_reg_flg[reg] & WR)
+			return true;
+		else
+			return false;
+	}
+}
+
+static bool da906x_reg_volatile(struct device *dev, unsigned int reg)
+{
+	if (reg < DA906X_MAPPING_BASE) {
+		switch (reg) {
+		case DA906X_REG_PAGE_CON:    /* Use cache for page selector */
+			return false;
+		default:
+			return true;
+		}
+	} else {
+		reg -= DA906X_MAPPING_BASE;
+		if (da906x_reg_flg[reg] & VOL)
+			return true;
+		else
+			return false;
+	}
+}
+
+static const struct regmap_range_cfg da906x_range_cfg[] = {
+	{
+		.range_min = DA906X_MAPPING_BASE,
+		.range_max = DA906X_MAPPING_BASE +
+			     ARRAY_SIZE(da906x_reg_flg) - 1,
+		.selector_reg = DA906X_REG_PAGE_CON,
+		.selector_mask = 1 << DA906X_I2C_PAGE_SEL_SHIFT,
+		.selector_shift = DA906X_I2C_PAGE_SEL_SHIFT,
+		.window_start = 0,
+		.window_len = 256,
+	}
+};
+
+struct regmap_config da906x_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.ranges = da906x_range_cfg,
+	.n_ranges = ARRAY_SIZE(da906x_range_cfg),
+	.max_register = DA906X_MAPPING_BASE + ARRAY_SIZE(da906x_reg_flg) - 1,
+
+	.cache_type = REGCACHE_RBTREE,
+
+	.writeable_reg = &da906x_reg_writable,
+	.readable_reg = &da906x_reg_readable,
+	.volatile_reg = &da906x_reg_volatile,
+};
+
+struct regmap_config da906x_no_cache_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.ranges = da906x_range_cfg,
+	.n_ranges = ARRAY_SIZE(da906x_range_cfg),
+	.max_register = DA906X_MAPPING_BASE + ARRAY_SIZE(da906x_reg_flg) - 1,
+
+	.cache_type = REGCACHE_NONE,
+
+	.writeable_reg = &da906x_reg_writable,
+	.readable_reg = &da906x_reg_readable,
+};
+
+static int da906x_i2c_probe(struct i2c_client *i2c,
+	const struct i2c_device_id *id)
+{
+	struct da906x *da906x;
+	struct regmap_config *config = &da906x_regmap_config;
+	struct da906x_pdata *pdata = i2c->dev.platform_data;
+	int ret;
+
+	da906x = devm_kzalloc(&i2c->dev, sizeof(struct da906x), GFP_KERNEL);
+	if (da906x == NULL)
+		return -ENOMEM;
+
+	i2c_set_clientdata(i2c, da906x);
+	da906x->dev = &i2c->dev;
+
+	if (pdata->flags & DA906X_FLG_NO_CACHE)
+		config = &da906x_no_cache_regmap_config;
+
+	da906x->regmap = devm_regmap_init_i2c(i2c, config);
+	if (IS_ERR(da906x->regmap)) {
+		ret = PTR_ERR(da906x->regmap);
+		dev_err(da906x->dev, "Failed to allocate register map: %d\n",
+			ret);
+		return ret;
+	}
+
+	return da906x_device_init(da906x, i2c->irq);
+}
+
+static int da906x_i2c_remove(struct i2c_client *i2c)
+{
+	struct da906x *da906x = i2c_get_clientdata(i2c);
+
+	da906x_device_exit(da906x);
+
+	return 0;
+}
+
+static const struct i2c_device_id da906x_i2c_id[] = {
+	{"da906x", PMIC_DA9063},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, da906x_i2c_id);
+
+static struct i2c_driver da906x_i2c_driver = {
+	.driver = {
+		.name = "da906x",
+		.owner = THIS_MODULE,
+	},
+	.probe    = da906x_i2c_probe,
+	.remove   = da906x_i2c_remove,
+	.id_table = da906x_i2c_id,
+};
+
+static int __init da906x_i2c_init(void)
+{
+	int ret;
+
+	ret = i2c_add_driver(&da906x_i2c_driver);
+	if (ret != 0)
+		pr_err("Failed to register da906x I2C driver\n");
+
+	return ret;
+}
+subsys_initcall(da906x_i2c_init);
+
+static void __exit da906x_i2c_exit(void)
+{
+	i2c_del_driver(&da906x_i2c_driver);
+}
+module_exit(da906x_i2c_exit);
diff --git a/drivers/mfd/da906x-irq.c b/drivers/mfd/da906x-irq.c
new file mode 100644
index 0000000..18d2796
--- /dev/null
+++ b/drivers/mfd/da906x-irq.c
@@ -0,0 +1,192 @@
+/* da906x-irq.c: Interrupts support for Dialog DA906X
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ *
+ *  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/irq.h>
+#include <linux/mfd/core.h>
+#include <linux/interrupt.h>
+#include <linux/regmap.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+
+#define	DA906X_REG_EVENT_A_OFFSET	0
+#define	DA906X_REG_EVENT_B_OFFSET	1
+#define	DA906X_REG_EVENT_C_OFFSET	2
+#define	DA906X_REG_EVENT_D_OFFSET	3
+#define EVENTS_BUF_LEN			4
+
+static const u8 mask_events_buf[] = { [0 ... (EVENTS_BUF_LEN - 1)] = ~0 };
+
+struct da906x_irq_data {
+	u16 reg;
+	u8 mask;
+};
+
+static struct regmap_irq da906x_irqs[] = {
+	/* DA906x event A register */
+	[DA906X_IRQ_ONKEY] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_ONKEY,
+	},
+	[DA906X_IRQ_ALARM] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_ALARM,
+	},
+	[DA906X_IRQ_TICK] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_TICK,
+	},
+	[DA906X_IRQ_ADC_RDY] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_ADC_RDY,
+	},
+	[DA906X_IRQ_SEQ_RDY] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_SEQ_RDY,
+	},
+	/* DA906x event B register */
+	[DA906X_IRQ_WAKE] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_WAKE,
+	},
+	[DA906X_IRQ_TEMP] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_TEMP,
+	},
+	[DA906X_IRQ_COMP_1V2] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_COMP_1V2,
+	},
+	[DA906X_IRQ_LDO_LIM] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_LDO_LIM,
+	},
+	[DA906X_IRQ_REG_UVOV] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_UVOV,
+	},
+	[DA906X_IRQ_VDD_MON] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_VDD_MON,
+	},
+	[DA906X_IRQ_WARN] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_VDD_WARN,
+	},
+	/* DA906x event C register */
+	[DA906X_IRQ_GPI0] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI0,
+	},
+	[DA906X_IRQ_GPI1] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI1,
+	},
+	[DA906X_IRQ_GPI2] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI2,
+	},
+	[DA906X_IRQ_GPI3] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI3,
+	},
+	[DA906X_IRQ_GPI4] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI4,
+	},
+	[DA906X_IRQ_GPI5] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI5,
+	},
+	[DA906X_IRQ_GPI6] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI6,
+	},
+	[DA906X_IRQ_GPI7] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI7,
+	},
+	/* DA906x event D register */
+	[DA906X_IRQ_GPI8] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI8,
+	},
+	[DA906X_IRQ_GPI9] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI9,
+	},
+	[DA906X_IRQ_GPI10] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI10,
+	},
+	[DA906X_IRQ_GPI11] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI11,
+	},
+	[DA906X_IRQ_GPI12] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI12,
+	},
+	[DA906X_IRQ_GPI13] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI13,
+	},
+	[DA906X_IRQ_GPI14] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI14,
+	},
+	[DA906X_IRQ_GPI15] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI15,
+	},
+};
+
+static struct regmap_irq_chip da906x_irq_chip = {
+	.name = "da906x-irq",
+	.irqs = da906x_irqs,
+	.num_irqs = DA906X_NUM_IRQ,
+
+	.num_regs = 4,
+	.status_base = DA906X_REG_EVENT_A + DA906X_MAPPING_BASE,
+	.mask_base = DA906X_REG_IRQ_MASK_A + DA906X_MAPPING_BASE,
+	.ack_base = DA906X_REG_EVENT_A + DA906X_MAPPING_BASE,
+};
+
+int da906x_irq_init(struct da906x *da906x)
+{
+	int ret;
+
+	if (!da906x->chip_irq) {
+		dev_err(da906x->dev, "No IRQ configured\n");
+		return -EINVAL;
+	}
+
+	ret = regmap_add_irq_chip(da906x->regmap, da906x->chip_irq,
+			IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED,
+			da906x->irq_base, &da906x_irq_chip,
+			&da906x->regmap_irq);
+	if (ret) {
+		dev_err(da906x->dev, "Failed to reguest IRQ %d: %d\n",
+				da906x->chip_irq, ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+void da906x_irq_exit(struct da906x *da906x)
+{
+	regmap_del_irq_chip(da906x->chip_irq, da906x->regmap_irq);
+}
+
diff --git a/include/linux/mfd/da906x/core.h b/include/linux/mfd/da906x/core.h
new file mode 100644
index 0000000..abd916d
--- /dev/null
+++ b/include/linux/mfd/da906x/core.h
@@ -0,0 +1,121 @@
+/*
+ * Definitions for DA906X MFD driver
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ *	   Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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.
+ *
+ */
+
+#ifndef __MFD_DA906X_CORE_H__
+#define __MFD_DA906X_CORE_H__
+
+#include <linux/interrupt.h>
+#include <linux/mfd/da906x/registers.h>
+
+/* DA906x modules */
+#define DA906X_DRVNAME_CORE		"da906x-core"
+#define DA906X_DRVNAME_REGULATORS	"da906x-regulators"
+#define DA906X_DRVNAME_LEDS		"da906x-leds"
+#define DA906X_DRVNAME_WATCHDOG		"da906x-watchdog"
+#define DA906X_DRVNAME_HWMON		"da906x-hwmon"
+#define DA906X_DRVNAME_ONKEY		"da906x-onkey"
+#define DA906X_DRVNAME_RTC		"da906x-rtc"
+#define DA906X_DRVNAME_VIBRATION	"da906x-vibration"
+
+enum da906x_models {
+	PMIC_DA9063 = 0x61,
+};
+
+/* Interrupts */
+enum da906x_irqs {
+	DA906X_IRQ_ONKEY = 0,
+	DA906X_IRQ_ALARM,
+	DA906X_IRQ_TICK,
+	DA906X_IRQ_ADC_RDY,
+	DA906X_IRQ_SEQ_RDY,
+	DA906X_IRQ_WAKE,
+	DA906X_IRQ_TEMP,
+	DA906X_IRQ_COMP_1V2,
+	DA906X_IRQ_LDO_LIM,
+	DA906X_IRQ_REG_UVOV,
+	DA906X_IRQ_VDD_MON,
+	DA906X_IRQ_WARN,
+	DA906X_IRQ_GPI0,
+	DA906X_IRQ_GPI1,
+	DA906X_IRQ_GPI2,
+	DA906X_IRQ_GPI3,
+	DA906X_IRQ_GPI4,
+	DA906X_IRQ_GPI5,
+	DA906X_IRQ_GPI6,
+	DA906X_IRQ_GPI7,
+	DA906X_IRQ_GPI8,
+	DA906X_IRQ_GPI9,
+	DA906X_IRQ_GPI10,
+	DA906X_IRQ_GPI11,
+	DA906X_IRQ_GPI12,
+	DA906X_IRQ_GPI13,
+	DA906X_IRQ_GPI14,
+	DA906X_IRQ_GPI15,
+};
+
+#define DA906X_IRQ_BASE_OFFSET	0
+#define DA906X_NUM_IRQ		(DA906X_IRQ_GPI15 + 1 - DA906X_IRQ_BASE_OFFSET)
+
+struct da906x {
+	/* Device */
+	struct device	*dev;
+	unsigned short	model;
+	unsigned short	revision;
+	unsigned int	flags;
+
+	/* Control interface */
+	struct mutex	io_mutex;
+	struct regmap	*regmap;
+
+	/* Interrupts */
+	int		chip_irq;
+	unsigned int	irq_base;
+	struct regmap_irq_chip_data *regmap_irq;
+};
+
+static inline unsigned da906x_model(struct da906x *da906x)
+{
+	return da906x->model;
+}
+
+static inline unsigned da906x_revision(struct da906x *da906x)
+{
+	return da906x->revision;
+}
+
+static inline void da906x_set_model_rev(struct da906x *da906x,
+			enum da906x_models model, unsigned short revision)
+{
+	da906x->model = model;
+	da906x->revision = revision;
+}
+
+int da906x_reg_read(struct da906x *da906x, u16 reg);
+int da906x_reg_write(struct da906x *da906x, u16 reg, u8 val);
+
+int da906x_block_write(struct da906x *da906x, u16 reg, int bytes, const u8 *buf);
+int da906x_block_read(struct da906x *da906x, u16 reg, int bytes, u8 *buf);
+
+int da906x_reg_set_bits(struct da906x *da906x, u16 reg, u8 mask);
+int da906x_reg_clear_bits(struct da906x *da906x, u16 reg, u8 mask);
+int da906x_reg_update(struct da906x*, u16 reg, u8 mask, u8 val);
+
+int da906x_device_init(struct da906x *da906x, unsigned int irq);
+int da906x_irq_init(struct da906x *da906x);
+
+void da906x_device_exit(struct da906x *da906x);
+void da906x_irq_exit(struct da906x *da906x);
+
+#endif /* __MFD_DA906X_CORE_H__ */
diff --git a/include/linux/mfd/da906x/pdata.h b/include/linux/mfd/da906x/pdata.h
new file mode 100644
index 0000000..97ae242
--- /dev/null
+++ b/include/linux/mfd/da906x/pdata.h
@@ -0,0 +1,114 @@
+/*
+ * Platform configuration options for DA906x
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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.
+ *
+ */
+
+#ifndef __MFD_DA906X_PDATA_H__
+#define __MFD_DA906X_PDATA_H__
+
+#include <linux/regulator/machine.h>
+
+/*
+ * Regulator configuration
+ */
+/* DA9063 regulator IDs */
+enum {
+	/* BUCKs */
+	DA9063_ID_BCORE1,
+	DA9063_ID_BCORE2,
+	DA9063_ID_BPRO,
+	DA9063_ID_BMEM,
+	DA9063_ID_BIO,
+	DA9063_ID_BPERI,
+
+	/* BCORE1 and BCORE2 in merged mode */
+	DA9063_ID_BCORES_MERGED,
+	/* BMEM and BIO in merged mode */
+	DA9063_ID_BMEM_BIO_MERGED,
+	/* When two BUCKs are merged, they cannot be reused separately */
+
+	/* LDOs */
+	DA9063_ID_LDO1,
+	DA9063_ID_LDO2,
+	DA9063_ID_LDO3,
+	DA9063_ID_LDO4,
+	DA9063_ID_LDO5,
+	DA9063_ID_LDO6,
+	DA9063_ID_LDO7,
+	DA9063_ID_LDO8,
+	DA9063_ID_LDO9,
+	DA9063_ID_LDO10,
+	DA9063_ID_LDO11,
+
+	/* RTC internal oscilator switch */
+	DA9063_ID_32K_OUT,
+};
+
+/* Regulators platform data */
+struct da906x_regulator_data {
+	int				id;
+	struct regulator_init_data	*initdata;
+};
+
+struct da906x_regulators_pdata {
+	unsigned			n_regulators;
+	struct da906x_regulator_data	*regulator_data;
+};
+
+
+/*
+ * RGB LED configuration
+ */
+/* LED IDs for flags in struct led_info. */
+enum {
+	DA906X_GPIO11_LED,
+	DA906X_GPIO14_LED,
+	DA906X_GPIO15_LED,
+
+	DA906X_LED_NUM
+};
+#define DA906X_LED_ID_MASK		0x3
+
+/* LED polarity for flags in struct led_info. */
+#define DA906X_LED_HIGH_LEVEL_ACTIVE	0x0
+#define DA906X_LED_LOW_LEVEL_ACTIVE	0x4
+
+
+/*
+ * General PMIC configuration
+ */
+/* HWMON ADC channels configuration */
+#define DA906X_FLG_FORCE_IN0_MANUAL_MODE	0x0010
+#define DA906X_FLG_FORCE_IN0_AUTO_MODE		0x0020
+#define DA906X_FLG_FORCE_IN1_MANUAL_MODE	0x0040
+#define DA906X_FLG_FORCE_IN1_AUTO_MODE		0x0080
+#define DA906X_FLG_FORCE_IN2_MANUAL_MODE	0x0100
+#define DA906X_FLG_FORCE_IN2_AUTO_MODE		0x0200
+#define DA906X_FLG_FORCE_IN3_MANUAL_MODE	0x0400
+#define DA906X_FLG_FORCE_IN3_AUTO_MODE		0x0800
+
+/* Disable register caching. */
+#define DA906X_FLG_NO_CACHE			0x0008
+
+struct da906x;
+
+/* DA906x platform data */
+struct da906x_pdata {
+	int				(*init)(struct da906x *da906x);
+	int				irq_base;
+	unsigned			flags;
+	struct da906x_regulators_pdata	*regulators_pdata;
+	struct led_platform_data	*leds_pdata;
+};
+
+#endif	/* __MFD_DA906X_PDATA_H__ */
diff --git a/include/linux/mfd/da906x/registers.h b/include/linux/mfd/da906x/registers.h
new file mode 100644
index 0000000..6808977
--- /dev/null
+++ b/include/linux/mfd/da906x/registers.h
@@ -0,0 +1,1093 @@
+/*
+ * Registers definition for DA906X modules
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ *	   Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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.
+ *
+ */
+
+#ifndef _DA906X_REG_H
+#define	_DA906X_REG_H
+
+#define DA906X_I2C_PAGE_SEL_SHIFT	1
+#define DA906X_I2C_PAGE(v)		(((v) >> 8) << \
+						DA906X_I2C_PAGE_SEL_SHIFT)
+#define DA906X_I2C_REG(v)		((v) & 0xFF)
+
+#define	DA906X_EVENT_REG_NUM		4
+#define	DA9210_EVENT_REG_NUM		2
+#define	DA906X_EXT_EVENT_REG_NUM	(DA906X_EVENT_REG_NUM + \
+						DA9210_EVENT_REG_NUM)
+
+/* Page selection I2C or SPI always in the begining of any page. */
+/* Page 0 : I2C access 0x000 - 0x0FF	SPI access 0x000 - 0x07F */
+/* Page 1 :				SPI access 0x080 - 0x0FF */
+/* Page 2 : I2C access 0x100 - 0x1FF	SPI access 0x100 - 0x17F */
+/* Page 3 :				SPI access 0x180 - 0x1FF */
+#define	DA906X_REG_PAGE_CON		0x00
+
+/* Create virtual range for pageable registers just above physical range */
+#define DA906X_MAPPING_BASE		0x100
+
+/* System Control and Event Registers */
+#define	DA906X_REG_STATUS_A		0x01
+#define	DA906X_REG_STATUS_B		0x02
+#define	DA906X_REG_STATUS_C		0x03
+#define	DA906X_REG_STATUS_D		0x04
+#define	DA906X_REG_FAULT_LOG		0x05
+#define	DA906X_REG_EVENT_A		0x06
+#define	DA906X_REG_EVENT_B		0x07
+#define	DA906X_REG_EVENT_C		0x08
+#define	DA906X_REG_EVENT_D		0x09
+#define	DA906X_REG_IRQ_MASK_A		0x0A
+#define	DA906X_REG_IRQ_MASK_B		0x0B
+#define	DA906X_REG_IRQ_MASK_C		0x0C
+#define	DA906X_REG_IRQ_MASK_D		0x0D
+#define	DA906X_REG_CONTROL_A		0x0E
+#define	DA906X_REG_CONTROL_B		0x0F
+#define	DA906X_REG_CONTROL_C		0x10
+#define	DA906X_REG_CONTROL_D		0x11
+#define	DA906X_REG_CONTROL_E		0x12
+#define	DA906X_REG_CONTROL_F		0x13
+#define	DA906X_REG_PD_DIS		0x14
+
+/* GPIO Control Registers */
+#define	DA906X_REG_GPIO_0_1		0x15
+#define	DA906X_REG_GPIO_2_3		0x16
+#define	DA906X_REG_GPIO_4_5		0x17
+#define	DA906X_REG_GPIO_6_7		0x18
+#define	DA906X_REG_GPIO_8_9		0x19
+#define	DA906X_REG_GPIO_10_11		0x1A
+#define	DA906X_REG_GPIO_12_13		0x1B
+#define	DA906X_REG_GPIO_14_15		0x1C
+#define	DA906X_REG_GPIO_MODE_0_7	0x1D
+#define	DA906X_REG_GPIO_MODE_8_15	0x1E
+#define	DA906X_REG_GPIO_SWITCH_CONT	0x1F
+
+/* Regulator Control Registers */
+#define	DA906X_REG_BCORE2_CONT		0x20
+#define	DA906X_REG_BCORE1_CONT		0x21
+#define	DA906X_REG_BPRO_CONT		0x22
+#define	DA906X_REG_BMEM_CONT		0x23
+#define	DA906X_REG_BIO_CONT		0x24
+#define	DA906X_REG_BPERI_CONT		0x25
+#define	DA906X_REG_LDO1_CONT		0x26
+#define	DA906X_REG_LDO2_CONT		0x27
+#define	DA906X_REG_LDO3_CONT		0x28
+#define	DA906X_REG_LDO4_CONT		0x29
+#define	DA906X_REG_LDO5_CONT		0x2A
+#define	DA906X_REG_LDO6_CONT		0x2B
+#define	DA906X_REG_LDO7_CONT		0x2C
+#define	DA906X_REG_LDO8_CONT		0x2D
+#define	DA906X_REG_LDO9_CONT		0x2E
+#define	DA906X_REG_LDO10_CONT		0x2F
+#define	DA906X_REG_LDO11_CONT		0x30
+#define	DA906X_REG_VIB			0x31
+#define	DA906X_REG_DVC_1		0x32
+#define	DA906X_REG_DVC_2		0x33
+
+/* GP-ADC Control Registers */
+#define	DA906X_REG_ADC_MAN		0x34
+#define	DA906X_REG_ADC_CONT		0x35
+#define	DA906X_REG_VSYS_MON		0x36
+#define	DA906X_REG_ADC_RES_L		0x37
+#define	DA906X_REG_ADC_RES_H		0x38
+#define	DA906X_REG_VSYS_RES		0x39
+#define	DA906X_REG_ADCIN1_RES		0x3A
+#define	DA906X_REG_ADCIN2_RES		0x3B
+#define	DA906X_REG_ADCIN3_RES		0x3C
+#define	DA906X_REG_MON1_RES		0x3D
+#define	DA906X_REG_MON2_RES		0x3E
+#define	DA906X_REG_MON3_RES		0x3F
+
+/* RTC Calendar and Alarm Registers */
+#define	DA906X_REG_COUNT_S		0x40
+#define	DA906X_REG_COUNT_MI		0x41
+#define	DA906X_REG_COUNT_H		0x42
+#define	DA906X_REG_COUNT_D		0x43
+#define	DA906X_REG_COUNT_MO		0x44
+#define	DA906X_REG_COUNT_Y		0x45
+#define	DA906X_REG_ALARM_MI		0x46
+#define	DA906X_REG_ALARM_H		0x47
+#define	DA906X_REG_ALARM_D		0x48
+#define	DA906X_REG_ALARM_MO		0x49
+#define	DA906X_REG_ALARM_Y		0x4A
+#define	DA906X_REG_SECOND_A		0x4B
+#define	DA906X_REG_SECOND_B		0x4C
+#define	DA906X_REG_SECOND_C		0x4D
+#define	DA906X_REG_SECOND_D		0x4E
+
+/* Sequencer Control Registers */
+#define	DA906X_REG_SEQ			0x81
+#define	DA906X_REG_SEQ_TIMER		0x82
+#define	DA906X_REG_ID_2_1		0x83
+#define	DA906X_REG_ID_4_3		0x84
+#define	DA906X_REG_ID_6_5		0x85
+#define	DA906X_REG_ID_8_7		0x86
+#define	DA906X_REG_ID_10_9		0x87
+#define	DA906X_REG_ID_12_11		0x88
+#define	DA906X_REG_ID_14_13		0x89
+#define	DA906X_REG_ID_16_15		0x8A
+#define	DA906X_REG_ID_18_17		0x8B
+#define	DA906X_REG_ID_20_19		0x8C
+#define	DA906X_REG_ID_22_21		0x8D
+#define	DA906X_REG_ID_24_23		0x8E
+#define	DA906X_REG_ID_26_25		0x8F
+#define	DA906X_REG_ID_28_27		0x90
+#define	DA906X_REG_ID_30_29		0x91
+#define	DA906X_REG_ID_32_31		0x92
+#define	DA906X_REG_SEQ_A		0x95
+#define	DA906X_REG_SEQ_B		0x96
+#define	DA906X_REG_WAIT			0x97
+#define	DA906X_REG_EN_32K		0x98
+#define	DA906X_REG_RESET		0x99
+
+/* Regulator Setting Registers */
+#define	DA906X_REG_BUCK_ILIM_A		0x9A
+#define	DA906X_REG_BUCK_ILIM_B		0x9B
+#define	DA906X_REG_BUCK_ILIM_C		0x9C
+#define	DA906X_REG_BCORE2_CFG		0x9D
+#define	DA906X_REG_BCORE1_CFG		0x9E
+#define	DA906X_REG_BPRO_CFG		0x9F
+#define	DA906X_REG_BIO_CFG		0xA0
+#define	DA906X_REG_BMEM_CFG		0xA1
+#define	DA906X_REG_BPERI_CFG		0xA2
+#define	DA906X_REG_VBCORE2_A		0xA3
+#define	DA906X_REG_VBCORE1_A		0xA4
+#define	DA906X_REG_VBPRO_A		0xA5
+#define	DA906X_REG_VBMEM_A		0xA6
+#define	DA906X_REG_VBIO_A		0xA7
+#define	DA906X_REG_VBPERI_A		0xA8
+#define	DA906X_REG_VLDO1_A		0xA9
+#define	DA906X_REG_VLDO2_A		0xAA
+#define	DA906X_REG_VLDO3_A		0xAB
+#define	DA906X_REG_VLDO4_A		0xAC
+#define	DA906X_REG_VLDO5_A		0xAD
+#define	DA906X_REG_VLDO6_A		0xAE
+#define	DA906X_REG_VLDO7_A		0xAF
+#define	DA906X_REG_VLDO8_A		0xB0
+#define	DA906X_REG_VLDO9_A		0xB1
+#define	DA906X_REG_VLDO10_A		0xB2
+#define	DA906X_REG_VLDO11_A		0xB3
+#define	DA906X_REG_VBCORE2_B		0xB4
+#define	DA906X_REG_VBCORE1_B		0xB5
+#define	DA906X_REG_VBPRO_B		0xB6
+#define	DA906X_REG_VBMEM_B		0xB7
+#define	DA906X_REG_VBIO_B		0xB8
+#define	DA906X_REG_VBPERI_B		0xB9
+#define	DA906X_REG_VLDO1_B		0xBA
+#define	DA906X_REG_VLDO2_B		0xBB
+#define	DA906X_REG_VLDO3_B		0xBC
+#define	DA906X_REG_VLDO4_B		0xBD
+#define	DA906X_REG_VLDO5_B		0xBE
+#define	DA906X_REG_VLDO6_B		0xBF
+#define	DA906X_REG_VLDO7_B		0xC0
+#define	DA906X_REG_VLDO8_B		0xC1
+#define	DA906X_REG_VLDO9_B		0xC2
+#define	DA906X_REG_VLDO10_B		0xC3
+#define	DA906X_REG_VLDO11_B		0xC4
+
+/* Backup Battery Charger Control Register */
+#define	DA906X_REG_BBAT_CONT		0xC5
+
+/* GPIO PWM (LED) */
+#define	DA906X_REG_GPO11_LED		0xC6
+#define	DA906X_REG_GPO14_LED		0xC7
+#define	DA906X_REG_GPO15_LED		0xC8
+
+/* GP-ADC Threshold Registers */
+#define	DA906X_REG_ADC_CFG		0xC9
+#define	DA906X_REG_AUTO1_HIGH		0xCA
+#define	DA906X_REG_AUTO1_LOW		0xCB
+#define	DA906X_REG_AUTO2_HIGH		0xCC
+#define	DA906X_REG_AUTO2_LOW		0xCD
+#define	DA906X_REG_AUTO3_HIGH		0xCE
+#define	DA906X_REG_AUTO3_LOW		0xCF
+
+/* DA906x Configuration registers */
+/* OTP */
+#define	DA906X_REG_OPT_COUNT		0x101
+#define	DA906X_REG_OPT_ADDR		0x102
+#define	DA906X_REG_OPT_DATA		0x103
+
+/* Customer Trim and Configuration */
+#define	DA906X_REG_T_OFFSET		0x104
+#define	DA906X_REG_INTERFACE		0x105
+#define	DA906X_REG_CONFIG_A		0x106
+#define	DA906X_REG_CONFIG_B		0x107
+#define	DA906X_REG_CONFIG_C		0x108
+#define	DA906X_REG_CONFIG_D		0x109
+#define	DA906X_REG_CONFIG_E		0x10A
+#define	DA906X_REG_CONFIG_F		0x10B
+#define	DA906X_REG_CONFIG_G		0x10C
+#define	DA906X_REG_CONFIG_H		0x10D
+#define	DA906X_REG_CONFIG_I		0x10E
+#define	DA906X_REG_CONFIG_J		0x10F
+#define	DA906X_REG_CONFIG_K		0x110
+#define	DA906X_REG_CONFIG_L		0x111
+#define	DA906X_REG_MON_REG_1		0x112
+#define	DA906X_REG_MON_REG_2		0x113
+#define	DA906X_REG_MON_REG_3		0x114
+#define	DA906X_REG_MON_REG_4		0x115
+#define	DA906X_REG_MON_REG_5		0x116
+#define	DA906X_REG_MON_REG_6		0x117
+#define	DA906X_REG_TRIM_CLDR		0x118
+
+/* General Purpose Registers */
+#define	DA906X_REG_GP_ID_0		0x119
+#define	DA906X_REG_GP_ID_1		0x11A
+#define	DA906X_REG_GP_ID_2		0x11B
+#define	DA906X_REG_GP_ID_3		0x11C
+#define	DA906X_REG_GP_ID_4		0x11D
+#define	DA906X_REG_GP_ID_5		0x11E
+#define	DA906X_REG_GP_ID_6		0x11F
+#define	DA906X_REG_GP_ID_7		0x120
+#define	DA906X_REG_GP_ID_8		0x121
+#define	DA906X_REG_GP_ID_9		0x122
+#define	DA906X_REG_GP_ID_10		0x123
+#define	DA906X_REG_GP_ID_11		0x124
+#define	DA906X_REG_GP_ID_12		0x125
+#define	DA906X_REG_GP_ID_13		0x126
+#define	DA906X_REG_GP_ID_14		0x127
+#define	DA906X_REG_GP_ID_15		0x128
+#define	DA906X_REG_GP_ID_16		0x129
+#define	DA906X_REG_GP_ID_17		0x12A
+#define	DA906X_REG_GP_ID_18		0x12B
+#define	DA906X_REG_GP_ID_19		0x12C
+
+/* Chip ID and variant */
+#define	DA906X_REG_CHIP_ID		0x181
+#define	DA906X_REG_CHIP_VARIANT		0x182
+
+/*
+ * PMIC registers bits
+ */
+/* DA906X_REG_PAGE_CON (addr=0x00) */
+#define	DA906X_PEG_PAGE_SHIFT			0
+#define	DA906X_REG_PAGE_MASK			0x07
+#define		DA906X_REG_PAGE0		0x00
+#define		DA906X_REG_PAGE2		0x02
+#define	DA906X_PAGE_WRITE_MODE			0x00
+#define	DA906X_REPEAT_WRITE_MODE		0x40
+#define	DA906X_PAGE_REVERT			0x80
+
+/* DA906X_REG_STATUS_A (addr=0x01) */
+#define	DA906X_NONKEY				0x01
+#define	DA906X_WAKE				0x02
+#define	DA906X_DVC_BUSY				0x04
+#define	DA906X_COMP_1V2				0x08
+
+/* DA906X_REG_STATUS_B (addr=0x02) */
+#define	DA906X_GPI0				0x01
+#define	DA906X_GPI1				0x02
+#define	DA906X_GPI2				0x04
+#define	DA906X_GPI3				0x08
+#define	DA906X_GPI4				0x10
+#define	DA906X_GPI5				0x20
+#define	DA906X_GPI6				0x40
+#define	DA906X_GPI7				0x80
+
+/* DA906X_REG_STATUS_C (addr=0x03) */
+#define	DA906X_GPI8				0x01
+#define	DA906X_GPI9				0x02
+#define	DA906X_GPI10				0x04
+#define	DA906X_GPI11				0x08
+#define	DA906X_GPI12				0x10
+#define	DA906X_GPI13				0x20
+#define	DA906X_GPI14				0x40
+#define	DA906X_GPI15				0x80
+
+/* DA906X_REG_STATUS_D (addr=0x04) */
+#define	DA906X_LDO3_LIM				0x08
+#define	DA906X_LDO4_LIM				0x10
+#define	DA906X_LDO7_LIM				0x20
+#define	DA906X_LDO8_LIM				0x40
+#define	DA906X_LDO11_LIM			0x80
+
+/* DA906X_REG_FAULT_LOG (addr=0x05) */
+#define	DA906X_TWD_ERROR			0x01
+#define	DA906X_POR				0x02
+#define	DA906X_VDD_FAULT			0x04
+#define	DA906X_VDD_START			0x08
+#define	DA906X_TEMP_CRIT			0x10
+#define	DA906X_KEY_RESET			0x20
+#define	DA906X_NSHUTDOWN			0x40
+#define	DA906X_WAIT_SHUT			0x80
+
+/* DA906X_REG_EVENT_A (addr=0x06) */
+#define	DA906X_E_NONKEY				0x01
+#define	DA906X_E_ALARM				0x02
+#define	DA906X_E_TICK				0x04
+#define	DA906X_E_ADC_RDY			0x08
+#define	DA906X_E_SEQ_RDY			0x10
+#define	DA906X_EVENTS_B				0x20
+#define	DA906X_EVENTS_C				0x40
+#define	DA906X_EVENTS_D				0x80
+
+/* DA906X_REG_EVENT_B (addr=0x07) */
+#define	DA906X_E_WAKE				0x01
+#define	DA906X_E_TEMP				0x02
+#define	DA906X_E_COMP_1V2			0x04
+#define	DA906X_E_LDO_LIM			0x08
+#define	DA906X_E_REG_UVOV			0x10
+#define	DA906X_E_DVC_RDY			0x20
+#define	DA906X_E_VDD_MON			0x40
+#define	DA906X_E_VDD_WARN			0x80
+
+/* DA906X_REG_EVENT_C (addr=0x08) */
+#define	DA906X_E_GPI0				0x01
+#define	DA906X_E_GPI1				0x02
+#define	DA906X_E_GPI2				0x04
+#define	DA906X_E_GPI3				0x08
+#define	DA906X_E_GPI4				0x10
+#define	DA906X_E_GPI5				0x20
+#define	DA906X_E_GPI6				0x40
+#define	DA906X_E_GPI7				0x80
+
+/* DA906X_REG_EVENT_D (addr=0x09) */
+#define	DA906X_E_GPI8				0x01
+#define	DA906X_E_GPI9				0x02
+#define	DA906X_E_GPI10				0x04
+#define	DA906X_E_GPI11				0x08
+#define	DA906X_E_GPI12				0x10
+#define	DA906X_E_GPI13				0x20
+#define	DA906X_E_GPI14				0x40
+#define	DA906X_E_GPI15				0x80
+
+/* DA906X_REG_IRQ_MASK_A (addr=0x0A) */
+#define	DA906X_M_ONKEY				0x01
+#define	DA906X_M_ALARM				0x02
+#define	DA906X_M_TICK				0x04
+#define	DA906X_M_ADC_RDY			0x08
+#define	DA906X_M_SEQ_RDY			0x10
+
+/* DA906X_REG_IRQ_MASK_B (addr=0x0B) */
+#define	DA906X_M_WAKE				0x01
+#define	DA906X_M_TEMP				0x02
+#define	DA906X_M_COMP_1V2			0x04
+#define	DA906X_M_LDO_LIM			0x08
+#define	DA906X_M_UVOV				0x10
+#define	DA906X_M_DVC_RDY			0x20
+#define	DA906X_M_VDD_MON			0x40
+#define	DA906X_M_VDD_WARN			0x80
+
+/* DA906X_REG_IRQ_MASK_C (addr=0x0C) */
+#define	DA906X_M_GPI0				0x01
+#define	DA906X_M_GPI1				0x02
+#define	DA906X_M_GPI2				0x04
+#define	DA906X_M_GPI3				0x08
+#define	DA906X_M_GPI4				0x10
+#define	DA906X_M_GPI5				0x20
+#define	DA906X_M_GPI6				0x40
+#define	DA906X_M_GPI7				0x80
+
+/* DA906X_REG_IRQ_MASK_D (addr=0x0D) */
+#define	DA906X_M_GPI8				0x01
+#define	DA906X_M_GPI9				0x02
+#define	DA906X_M_GPI10				0x04
+#define	DA906X_M_GPI11				0x08
+#define	DA906X_M_GPI12				0x10
+#define	DA906X_M_GPI13				0x20
+#define	DA906X_M_GPI14				0x40
+#define	DA906X_M_GPI15				0x80
+
+/* DA906X_REG_CONTROL_A (addr=0x0E) */
+#define	DA906X_SYSTEM_EN			0x01
+#define	DA906X_POWER_EN				0x02
+#define	DA906X_POWER1_EN			0x04
+#define	DA906X_STANDBY				0x08
+#define	DA906X_M_SYSTEM_EN			0x10
+#define	DA906X_M_POWER_EN			0x20
+#define	DA906X_M_POWER1_EN			0x40
+#define	DA906X_CP_EN				0x80
+
+/* DA906X_REG_CONTROL_B (addr=0x0F) */
+#define	DA906X_CHG_SEL				0x01
+#define	DA906X_WATCHDOG_PD			0x02
+#define	DA906X_NRES_MODE			0x08
+#define	DA906X_NONKEY_LOCK			0x10
+
+/* DA906X_REG_CONTROL_C (addr=0x10) */
+#define	DA906X_DEBOUNCING_SHIFT			0
+#define	DA906X_DEBOUNCING_MASK			0x07
+#define		DA906X_DEBOUNCING_OFF		0x0
+#define		DA906X_DEBOUNCING_0MS1		0x1
+#define		DA906X_DEBOUNCING_1MS		0x2
+#define		DA906X_DEBOUNCING_10MS24	0x3
+#define		DA906X_DEBOUNCING_51MS2		0x4
+#define		DA906X_DEBOUNCING_256MS		0x5
+#define		DA906X_DEBOUNCING_512MS		0x6
+#define		DA906X_DEBOUNCING_1024MS	0x7
+
+#define	DA906X_AUTO_BOOT			0x08
+#define	DA906X_OTPREAD_EN			0x10
+#define	DA906X_SLEW_RATE_SHIFT			5
+#define	DA906X_SLEW_RATE_MASK			0x60
+#define		DA906X_SLEW_RATE_4US		0x00
+#define		DA906X_SLEW_RATE_3US		0x20
+#define		DA906X_SLEW_RATE_1US		0x40
+#define		DA906X_SLEW_RATE_0US5		0x60
+#define	DA906X_DEF_SUPPLY			0x80
+
+/* DA906X_REG_CONTROL_D (addr=0x11) */
+#define	DA906X_TWDSCALE_SHIFT			0
+#define	DA906X_TWDSCALE_MASK			0x07
+#define	DA906X_BLINK_FRQ_SHIFT			3
+#define	DA906X_BLINK_FRQ_MASK			0x38
+#define		DA906X_BLINK_FRQ_OFF		0x00
+#define		DA906X_BLINK_FRQ_1S0		0x08
+#define		DA906X_BLINK_FRQ_2S0		0x10
+#define		DA906X_BLINK_FRQ_4S0		0x18
+#define		DA906X_BLINK_FRQ_0S18		0x20
+#define		DA906X_BLINK_FRQ_2S0_VDD	0x28
+#define		DA906X_BLINK_FRQ_4S0_VDD	0x30
+#define		DA906X_BLINK_FRQ_0S18_VDD	0x38
+
+#define	DA906X_BLINK_DUR_SHIFT			6
+#define	DA906X_BLINK_DUR_MASK			0xC0
+#define		DA906X_BLINK_DUR_10MS		0x00
+#define		DA906X_BLINK_DUR_20MS		0x40
+#define		DA906X_BLINK_DUR_40MS		0x80
+#define		DA906X_BLINK_DUR_20MSDBL	0xC0
+
+/* DA906X_REG_CONTROL_E (addr=0x12) */
+#define	DA906X_RTC_MODE_PD			0x01
+#define	DA906X_RTC_MODE_SD			0x02
+#define	DA906X_RTC_EN				0x04
+#define	DA906X_ECO_MODE				0x08
+#define	DA906X_PM_FB1_PIN			0x10
+#define	DA906X_PM_FB2_PIN			0x20
+#define	DA906X_PM_FB3_PIN			0x40
+#define	DA906X_V_LOCK				0x80
+
+/* DA906X_REG_CONTROL_F (addr=0x13) */
+#define	DA906X_WATCHDOG				0x01
+#define	DA906X_SHUTDOWN				0x02
+#define	DA906X_WAKE_UP				0x04
+
+/* DA906X_REG_PD_DIS (addr=0x14) */
+#define	DA906X_GPI_DIS				0x01
+#define	DA906X_GPADC_PAUSE			0x02
+#define	DA906X_PMIF_DIS				0x04
+#define	DA906X_HS2WIRE_DIS			0x08
+#define	DA906X_BBAT_DIS				0x20
+#define	DA906X_OUT_32K_PAUSE			0x40
+#define	DA906X_PMCONT_DIS			0x80
+
+/* DA906X_REG_GPIO_0_1 (addr=0x15) */
+#define	DA906X_GPIO0_PIN_SHIFT			0
+#define	DA906X_GPIO0_PIN_MASK			0x03
+#define		DA906X_GPIO0_PIN_ADCIN1		0x00
+#define		DA906X_GPIO0_PIN_GPI		0x01
+#define		DA906X_GPIO0_PIN_GPO_OD		0x02
+#define		DA906X_GPIO0_PIN_GPO		0x03
+#define	DA906X_GPIO0_TYPE			0x04
+#define		DA906X_GPIO0_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO0_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO0_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO0_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO0_NO_WAKEUP			0x08
+#define	DA906X_GPIO1_PIN_SHIFT			4
+#define	DA906X_GPIO1_PIN_MASK			0x30
+#define		DA906X_GPIO1_PIN_ADCIN2_COMP	0x00
+#define		DA906X_GPIO1_PIN_GPI		0x10
+#define		DA906X_GPIO1_PIN_GPO_OD		0x20
+#define		DA906X_GPIO1_PIN_GPO		0x30
+#define	DA906X_GPIO1_TYPE			0x40
+#define		DA906X_GPIO1_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO1_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO1_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO1_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO1_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_2_3 (addr=0x16) */
+#define	DA906X_GPIO2_PIN_SHIFT			0
+#define	DA906X_GPIO2_PIN_MASK			0x03
+#define		DA906X_GPIO2_PIN_ADCIN3		0x00
+#define		DA906X_GPIO2_PIN_GPI		0x01
+#define		DA906X_GPIO2_PIN_GPO_PSS	0x02
+#define		DA906X_GPIO2_PIN_GPO		0x03
+#define	DA906X_GPIO2_TYPE			0x04
+#define		DA906X_GPIO2_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO2_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO2_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO2_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO2_NO_WAKEUP			0x08
+#define	DA906X_GPIO3_PIN_SHIFT			4
+#define	DA906X_GPIO3_PIN_MASK			0x30
+#define		DA906X_GPIO3_PIN_CORE_SW_G	0x00
+#define		DA906X_GPIO3_PIN_GPI		0x10
+#define		DA906X_GPIO3_PIN_GPO_OD		0x20
+#define		DA906X_GPIO3_PIN_GPO		0x30
+#define	DA906X_GPIO3_TYPE			0x40
+#define		DA906X_GPIO3_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO3_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO3_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO3_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO3_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_4_5 (addr=0x17) */
+#define	DA906X_GPIO4_PIN_SHIFT			0
+#define	DA906X_GPIO4_PIN_MASK			0x03
+#define		DA906X_GPIO4_PIN_CORE_SW_S	0x00
+#define		DA906X_GPIO4_PIN_GPI		0x01
+#define		DA906X_GPIO4_PIN_GPO_OD		0x02
+#define		DA906X_GPIO4_PIN_GPO		0x03
+#define	DA906X_GPIO4_TYPE			0x04
+#define		DA906X_GPIO4_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO4_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO4_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO4_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO4_NO_WAKEUP			0x08
+#define	DA906X_GPIO5_PIN_SHIFT			4
+#define	DA906X_GPIO5_PIN_MASK			0x30
+#define		DA906X_GPIO5_PIN_PERI_SW_G	0x00
+#define		DA906X_GPIO5_PIN_GPI		0x10
+#define		DA906X_GPIO5_PIN_GPO_OD		0x20
+#define		DA906X_GPIO5_PIN_GPO		0x30
+#define	DA906X_GPIO5_TYPE			0x40
+#define		DA906X_GPIO5_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO5_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO5_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO5_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO5_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_6_7 (addr=0x18) */
+#define	DA906X_GPIO6_PIN_SHIFT			0
+#define	DA906X_GPIO6_PIN_MASK			0x03
+#define		DA906X_GPIO6_PIN_PERI_SW_S	0x00
+#define		DA906X_GPIO6_PIN_GPI		0x01
+#define		DA906X_GPIO6_PIN_GPO_OD		0x02
+#define		DA906X_GPIO6_PIN_GPO		0x03
+#define	DA906X_GPIO6_TYPE			0x04
+#define		DA906X_GPIO6_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO6_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO6_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO6_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO6_NO_WAKEUP			0x08
+#define	DA906X_GPIO7_PIN_SHIFT			4
+#define	DA906X_GPIO7_PIN_MASK			0x30
+#define		DA906X_GPIO7_PIN_GPI		0x10
+#define		DA906X_GPIO7_PIN_GPO_PSS	0x20
+#define		DA906X_GPIO7_PIN_GPO		0x30
+#define	DA906X_GPIO7_TYPE			0x40
+#define		DA906X_GPIO7_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO7_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO7_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO7_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO7_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_8_9 (addr=0x19) */
+#define	DA906X_GPIO8_PIN_SHIFT			0
+#define	DA906X_GPIO8_PIN_MASK			0x03
+#define		DA906X_GPIO8_PIN_GPI_SYS_EN	0x00
+#define		DA906X_GPIO8_PIN_GPI		0x01
+#define		DA906X_GPIO8_PIN_GPO_PSS	0x02
+#define		DA906X_GPIO8_PIN_GPO		0x03
+#define	DA906X_GPIO8_TYPE			0x04
+#define		DA906X_GPIO8_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO8_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO8_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO8_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO8_NO_WAKEUP			0x08
+#define	DA906X_GPIO9_PIN_SHIFT			4
+#define	DA906X_GPIO9_PIN_MASK			0x30
+#define		DA906X_GPIO9_PIN_GPI_PWR_EN	0x00
+#define		DA906X_GPIO9_PIN_GPI		0x10
+#define		DA906X_GPIO9_PIN_GPO_PSS	0x20
+#define		DA906X_GPIO9_PIN_GPO		0x30
+#define	DA906X_GPIO9_TYPE			0x40
+#define		DA906X_GPIO9_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO9_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO9_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO9_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO9_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_10_11 (addr=0x1A) */
+#define	DA906X_GPIO10_PIN_SHIFT			0
+#define	DA906X_GPIO10_PIN_MASK			0x03
+#define		DA906X_GPIO10_PIN_GPI_PWR1_EN	0x00
+#define		DA906X_GPIO10_PIN_GPI		0x01
+#define		DA906X_GPIO10_PIN_GPO_OD	0x02
+#define		DA906X_GPIO10_PIN_GPO		0x03
+#define	DA906X_GPIO10_TYPE			0x04
+#define		DA906X_GPIO10_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO10_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO10_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO10_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO10_NO_WAKEUP			0x08
+#define	DA906X_GPIO11_PIN_SHIFT			4
+#define	DA906X_GPIO11_PIN_MASK			0x30
+#define		DA906X_GPIO11_PIN_GPO_OD	0x00
+#define		DA906X_GPIO11_PIN_GPI		0x10
+#define		DA906X_GPIO11_PIN_GPO_PSS	0x20
+#define		DA906X_GPIO11_PIN_GPO		0x30
+#define	DA906X_GPIO11_TYPE			0x40
+#define		DA906X_GPIO11_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO11_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO11_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO11_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO11_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_12_13 (addr=0x1B) */
+#define	DA906X_GPIO12_PIN_SHIFT			0
+#define	DA906X_GPIO12_PIN_MASK			0x03
+#define		DA906X_GPIO12_PIN_NVDDFLT_OUT	0x00
+#define		DA906X_GPIO12_PIN_GPI		0x01
+#define		DA906X_GPIO12_PIN_VSYSMON_OUT	0x02
+#define		DA906X_GPIO12_PIN_GPO		0x03
+#define	DA906X_GPIO12_TYPE			0x04
+#define		DA906X_GPIO12_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO12_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO12_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO12_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO12_NO_WAKEUP			0x08
+#define	DA906X_GPIO13_PIN_SHIFT			4
+#define	DA906X_GPIO13_PIN_MASK			0x30
+#define		DA906X_GPIO13_PIN_GPFB1_OUT	0x00
+#define		DA906X_GPIO13_PIN_GPI		0x10
+#define		DA906X_GPIO13_PIN_GPFB1_OUTOD	0x20
+#define		DA906X_GPIO13_PIN_GPO		0x30
+#define	DA906X_GPIO13_TYPE			0x40
+#define		DA906X_GPIO13_TYPE_GPFB1_OUT	0x00
+#define		DA906X_GPIO13_TYPE_GPI		0x00
+#define		DA906X_GPIO13_TYPE_GPFB1_OUTOD	0x04
+#define		DA906X_GPIO13_TYPE_GPO		0x04
+#define	DA906X_GPIO13_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_14_15 (addr=0x1C) */
+#define	DA906X_GPIO14_PIN_SHIFT			0
+#define	DA906X_GPIO14_PIN_MASK			0x03
+#define		DA906X_GPIO14_PIN_GPO_OD	0x00
+#define		DA906X_GPIO14_PIN_GPI		0x01
+#define		DA906X_GPIO14_PIN_HS2DATA	0x02
+#define		DA906X_GPIO14_PIN_GPO		0x03
+#define	DA906X_GPIO14_TYPE			0x04
+#define		DA906X_GPIO14_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO14_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO14_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO14_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO14_NO_WAKEUP			0x08
+#define	DA906X_GPIO15_PIN_SHIFT			4
+#define	DA906X_GPIO15_PIN_MASK			0x30
+#define		DA906X_GPIO15_PIN_GPO_OD	0x00
+#define		DA906X_GPIO15_PIN_GPI		0x10
+#define		DA906X_GPIO15_PIN_GPO		0x30
+#define	DA906X_GPIO15_TYPE			0x40
+#define		DA906X_GPIO15_TYPE_GPFB1_OUT	0x00
+#define		DA906X_GPIO15_TYPE_GPI		0x00
+#define		DA906X_GPIO15_TYPE_GPFB1_OUTOD	0x04
+#define		DA906X_GPIO15_TYPE_GPO		0x04
+#define	DA906X_GPIO15_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_MODE_0_7 (addr=0x1D) */
+#define	DA906X_GPIO0_MODE			0x01
+#define	DA906X_GPIO1_MODE			0x02
+#define	DA906X_GPIO2_MODE			0x04
+#define	DA906X_GPIO3_MODE			0x08
+#define	DA906X_GPIO4_MODE			0x10
+#define	DA906X_GPIO5_MODE			0x20
+#define	DA906X_GPIO6_MODE			0x40
+#define	DA906X_GPIO7_MODE			0x80
+
+/* DA906X_REG_GPIO_MODE_8_15 (addr=0x1E) */
+#define	DA906X_GPIO8_MODE			0x01
+#define	DA906X_GPIO9_MODE			0x02
+#define	DA906X_GPIO10_MODE			0x04
+#define	DA906X_GPIO11_MODE			0x08
+#define		DA906X_GPIO11_MODE_LED_ACT_HIGH	0x00
+#define		DA906X_GPIO11_MODE_LED_ACT_LOW	0x08
+#define	DA906X_GPIO12_MODE			0x10
+#define	DA906X_GPIO13_MODE			0x20
+#define	DA906X_GPIO14_MODE			0x40
+#define		DA906X_GPIO14_MODE_LED_ACT_HIGH	0x00
+#define		DA906X_GPIO14_MODE_LED_ACT_LOW	0x40
+#define	DA906X_GPIO15_MODE			0x80
+#define		DA906X_GPIO15_MODE_LED_ACT_HIGH	0x00
+#define		DA906X_GPIO15_MODE_LED_ACT_LOW	0x80
+
+/* DA906X_REG_SWITCH_CONT (addr=0x1F) */
+#define	DA906X_CORE_SW_GPI_SHIFT		0
+#define	DA906X_CORE_SW_GPI_MASK			0x03
+#define		DA906X_CORE_SW_GPI_OFF		0x00
+#define		DA906X_CORE_SW_GPI_GPIO1	0x01
+#define		DA906X_CORE_SW_GPI_GPIO2	0x02
+#define		DA906X_CORE_SW_GPI_GPIO13	0x03
+#define	DA906X_PERI_SW_GPI_SHIFT		2
+#define	DA906X_PERI_SW_GPI_MASK			0x0C
+#define		DA906X_PERI_SW_GPI_OFF		0x00
+#define		DA906X_PERI_SW_GPI_GPIO1	0x04
+#define		DA906X_PERI_SW_GPI_GPIO2	0x08
+#define		DA906X_PERI_SW_GPI_GPIO13	0x0C
+#define	DA906X_SWITCH_SR_SHIFT			4
+#define	DA906X_SWITCH_SR_MASK			0x30
+#define		DA906X_SWITCH_SR_1MV		0x00
+#define		DA906X_SWITCH_SR_5MV		0x10
+#define		DA906X_SWITCH_SR_10MV		0x20
+#define		DA906X_SWITCH_SR_50MV		0x30
+#define	DA906X_SWITCH_SR_DIS			0x40
+#define	DA906X_CP_EN_MODE			0x80
+
+/* DA906X_REGL_Bxxxx_CONT common bits (addr=0x20-0x25) */
+#define	DA906X_BUCK_EN				0x01
+#define	DA906X_BUCK_GPI_SHIFT			1
+#define DA906X_BUCK_GPI_MASK			0x06
+#define		DA906X_BUCK_GPI_OFF		0x00
+#define		DA906X_BUCK_GPI_GPIO1		0x02
+#define		DA906X_BUCK_GPI_GPIO2		0x04
+#define		DA906X_BUCK_GPI_GPIO13		0x06
+#define	DA906X_BUCK_CONF			0x08
+#define	DA906X_VBUCK_GPI_SHIFT			5
+#define	DA906X_VBUCK_GPI_MASK			0x60
+#define		DA906X_VBUCK_GPI_OFF		0x00
+#define		DA906X_VBUCK_GPI_GPIO1		0x20
+#define		DA906X_VBUCK_GPI_GPIO2		0x40
+#define		DA906X_VBUCK_GPI_GPIO13		0x60
+
+/* DA906X_REG_BCORE1_CONT specific bits (addr=0x21) */
+#define	DA906X_CORE_SW_EN			0x10
+#define	DA906X_CORE_SW_CONF			0x80
+
+/* DA906X_REG_BPERI_CONT specific bits (addr=0x25) */
+#define	DA906X_PERI_SW_EN			0x10
+#define	DA906X_PERI_SW_CONF			0x80
+
+/* DA906X_REG_LDOx_CONT common bits (addr=0x26-0x30) */
+#define	DA906X_LDO_EN				0x01
+#define	DA906X_LDO_GPI_SHIFT			1
+#define DA906X_LDO_GPI_MASK			0x06
+#define		DA906X_LDO_GPI_OFF		0x00
+#define		DA906X_LDO_GPI_GPIO1		0x02
+#define		DA906X_LDO_GPI_GPIO2		0x04
+#define		DA906X_LDO_GPI_GPIO13		0x06
+#define	DA906X_LDO_PD_DIS			0x08
+#define	DA906X_VLDO_GPI_SHIFT			5
+#define	DA906X_VLDO_GPI_MASK			0x60
+#define		DA906X_VLDO_GPI_OFF		0x00
+#define		DA906X_VLDO_GPI_GPIO1		0x20
+#define		DA906X_VLDO_GPI_GPIO2		0x40
+#define		DA906X_VLDO_GPI_GPIO13		0x60
+#define	DA906X_LDO_CONF				0x80
+
+/* DA906X_REG_LDO5_CONT specific bits (addr=0x2A) */
+#define	DA906X_VLDO5_SEL			0x10
+
+/* DA906X_REG_LDO6_CONT specific bits (addr=0x2B) */
+#define	DA906X_VLDO6_SEL			0x10
+
+/* DA906X_REG_LDO7_CONT specific bits (addr=0x2C) */
+#define	DA906X_VLDO7_SEL			0x10
+
+/* DA906X_REG_LDO8_CONT specific bits (addr=0x2D) */
+#define	DA906X_VLDO8_SEL			0x10
+
+/* DA906X_REG_LDO9_CONT specific bits (addr=0x2E) */
+#define	DA906X_VLDO9_SEL			0x10
+
+/* DA906X_REG_LDO10_CONT specific bits (addr=0x2F) */
+#define	DA906X_VLDO10_SEL			0x10
+
+/* DA906X_REG_LDO11_CONT specific bits (addr=0x30) */
+#define	DA906X_VLDO11_SEL			0x10
+
+/* DA906X_REG_VIB (addr=0x31) */
+#define DA906X_VIB_SET_MASK			0x3F
+#define		DA906X_VIB_SET_OFF		0
+#define		DA906X_VIB_SET_MAX		0x3F
+
+/* DA906X_REG_DVC_1 (addr=0x32) */
+#define	DA906X_VBCORE1_SEL			0x01
+#define	DA906X_VBCORE2_SEL			0x02
+#define	DA906X_VBPRO_SEL			0x04
+#define	DA906X_VBMEM_SEL			0x08
+#define	DA906X_VBPERI_SEL			0x10
+#define	DA906X_VLDO1_SEL			0x20
+#define	DA906X_VLDO2_SEL			0x40
+#define	DA906X_VLDO3_SEL			0x80
+
+/* DA906X_REG_DVC_2 (addr=0x33) */
+#define	DA906X_VBIO_SEL				0x01
+#define	DA906X_VLDO4_SEL			0x80
+
+/* DA906X_REG_ADC_MAN (addr=0x34) */
+#define	DA906X_ADC_MUX_SHIFT			0
+#define	DA906X_ADC_MUX_MASK			0x0F
+#define		DA906X_ADC_MUX_VSYS		0x00
+#define		DA906X_ADC_MUX_ADCIN1		0x01
+#define		DA906X_ADC_MUX_ADCIN2		0x02
+#define		DA906X_ADC_MUX_ADCIN3		0x03
+#define		DA906X_ADC_MUX_T_SENSE		0x04
+#define		DA906X_ADC_MUX_VBBAT		0x05
+#define		DA906X_ADC_MUX_LDO_G1		0x08
+#define		DA906X_ADC_MUX_LDO_G2		0x09
+#define		DA906X_ADC_MUX_LDO_G3		0x0A
+#define	DA906X_ADC_MAN				0x10
+#define	DA906X_ADC_MODE				0x20
+
+/* DA906X_REG_ADC_CONT (addr=0x35) */
+#define	DA906X_ADC_AUTO_VSYS_EN			0x01
+#define	DA906X_ADC_AUTO_AD1_EN			0x02
+#define	DA906X_ADC_AUTO_AD2_EN			0x04
+#define	DA906X_ADC_AUTO_AD3_EN			0x08
+#define	DA906X_ADC_AD1_ISRC_EN			0x10
+#define	DA906X_ADC_AD2_ISRC_EN			0x20
+#define	DA906X_ADC_AD3_ISRC_EN			0x40
+#define	DA906X_COMP1V2_EN			0x80
+
+/* DA906X_REG_VSYS_MON (addr=0x36) */
+#define	DA906X_VSYS_VAL_SHIFT			0
+#define	DA906X_VSYS_VAL_MASK			0xFF
+#define	DA906X_VSYS_VAL_BASE			0x00
+
+/* DA906X_REG_ADC_RES_L (addr=0x37) */
+#define	DA906X_ADC_RES_L_SHIFT			6
+#define	DA906X_ADC_RES_L_BITS			2
+#define	DA906X_ADC_RES_L_MASK			0xC0
+
+/* DA906X_REG_ADC_RES_H (addr=0x38) */
+#define	DA906X_ADC_RES_M_SHIFT			0
+#define	DA906X_ADC_RES_M_BITS			8
+#define	DA906X_ADC_RES_M_MASK			0xFF
+
+/* DA906X_REG_(xxx_RES/ADC_RES_H) (addr=0x39-0x3F) */
+#define	DA906X_ADC_VAL_SHIFT			0
+#define	DA906X_ADC_VAL_MASK			0xFF
+
+/* DA906X_REG_COUNT_S (addr=0x40) */
+#define DA906X_RTC_READ				0x80
+#define DA906X_COUNT_SEC_MASK			0x3F
+
+/* DA906X_REG_COUNT_MI (addr=0x41) */
+#define DA906X_COUNT_MIN_MASK			0x3F
+
+/* DA906X_REG_COUNT_H (addr=0x42) */
+#define DA906X_COUNT_HOUR_MASK			0x1F
+
+/* DA906X_REG_COUNT_D (addr=0x43) */
+#define DA906X_COUNT_DAY_MASK			0x1F
+
+/* DA906X_REG_COUNT_MO (addr=0x44) */
+#define DA906X_COUNT_MONTH_MASK			0x0F
+
+/* DA906X_REG_COUNT_Y (addr=0x45) */
+#define DA906X_COUNT_YEAR_MASK			0x3F
+#define DA906X_MONITOR				0x40
+
+/* DA906X_REG_ALARM_MI (addr=0x46) */
+#define DA906X_ALARM_STATUS_ALARM		0x80
+#define DA906X_ALARM_STATUS_TICK		0x40
+#define DA906X_ALARM_MIN_MASK			0x3F
+
+/* DA906X_REG_ALARM_H (addr=0x47) */
+#define DA906X_ALARM_HOUR_MASK			0x1F
+
+/* DA906X_REG_ALARM_D (addr=0x48) */
+#define DA906X_ALARM_DAY_MASK			0x1F
+
+/* DA906X_REG_ALARM_MO (addr=0x49) */
+#define DA906X_TICK_WAKE			0x20
+#define DA906X_TICK_TYPE			0x10
+#define		DA906X_TICK_TYPE_SEC		0x00
+#define		DA906X_TICK_TYPE_MIN		0x10
+#define DA906X_ALARM_MONTH_MASK			0x0F
+
+/* DA906X_REG_ALARM_Y (addr=0x4A) */
+#define DA906X_TICK_ON				0x80
+#define DA906X_ALARM_ON				0x40
+#define DA906X_ALARM_YEAR_MASK			0x3F
+
+/* DA906X_REG_WAIT (addr=0x97)*/
+#define	DA906X_REG_WAIT_TIME_SHIFT		0
+#define	DA906X_REG_WAIT_TIME_MASK		0xF
+#define	DA906X_WAIT_TIME_0_US			0x0
+#define	DA906X_WAIT_TIME_512_US			0x1
+#define	DA906X_WAIT_TIME_1_MS			0x2
+#define	DA906X_WAIT_TIME_2_MS			0x3
+#define	DA906X_WAIT_TIME_4_1_MS			0x4
+#define	DA906X_WAIT_TIME_8_2_MS			0x5
+#define	DA906X_WAIT_TIME_16_4_MS		0x6
+#define	DA906X_WAIT_TIME_32_8_MS		0x7
+#define	DA906X_WAIT_TIME_65_5_MS		0x8
+#define	DA906X_WAIT_TIME_128_MS			0x9
+#define	DA906X_WAIT_TIME_256_MS			0xA
+#define	DA906X_WAIT_TIME_512_MS			0xB
+#define	DA906X_WAIT_TIME_1_S			0xC
+#define	DA906X_WAIT_TIME_2_1_S			0xD
+
+/* DA906X_REG_EN_32K  (addr=0x98)*/
+#define	DA906X_STABILIZ_TIME_SHIFT		0
+#define	DA906X_STABILIZ_TIME_MASK		0x7
+#define	DA906X_CRYSTAL				0x08
+#define	DA906X_DELAY_MODE			0x10
+#define	DA906X_OUT_CLOCK			0x20
+#define	DA906X_RTC_CLOCK			0x40
+#define	DA906X_OUT_32K_EN			0x80
+
+/* DA906X_REG_CHIP_VARIANT */
+#define	DA906X_CHIP_VARIANT_SHIFT		4
+
+/* DA906X_REG_BUCK_ILIM_A (addr=0x9A) */
+#define DA906X_BIO_ILIM_SHIFT			0
+#define DA906X_BIO_ILIM_MASK			0x0F
+#define DA906X_BMEM_ILIM_SHIFT			4
+#define DA906X_BMEM_ILIM_MASK			0x0F
+
+/* DA906X_REG_BUCK_ILIM_B (addr=0x9B) */
+#define DA906X_BPRO_ILIM_SHIFT			0
+#define DA906X_BPRO_ILIM_MASK			0x0F
+#define DA906X_BPERI_ILIM_SHIFT			4
+#define DA906X_BPERI_ILIM_MASK			0x0F
+
+/* DA906X_REG_BUCK_ILIM_C (addr=0x9C) */
+#define DA906X_BCORE1_ILIM_SHIFT		0
+#define DA906X_BCORE1_ILIM_MASK			0x0F
+#define DA906X_BCORE2_ILIM_SHIFT		4
+#define DA906X_BCORE2_ILIM_MASK			0x0F
+
+/* DA906X_REG_Bxxxx_CFG common bits (addr=0x9D-0xA2) */
+#define DA906X_BUCK_FB_MASK			0x07
+#define DA906X_BUCK_PD_DIS_SHIFT		5
+#define DA906X_BUCK_MODE_SHIFT			6
+#define DA906X_BUCK_MODE_MASK			0xC0
+#define		DA906X_BUCK_MODE_MANUAL		0x00
+#define		DA906X_BUCK_MODE_SLEEP		0x40
+#define		DA906X_BUCK_MODE_SYNC		0x80
+#define		DA906X_BUCK_MODE_AUTO		0xC0
+
+/* DA906X_REG_BPRO_CFG (addr=0x9F) */
+#define	DA906X_BPRO_VTTR_EN			0x08
+#define	DA906X_BPRO_VTT_EN			0x10
+
+/* DA906X_REG_VBxxxx_A/B (addr=0xA3-0xA8, 0xB4-0xB9) */
+#define DA906X_VBUCK_SHIFT			0
+#define DA906X_VBUCK_MASK			0x7F
+#define DA906X_VBUCK_BIAS			0
+#define DA906X_BUCK_SL				0x80
+
+/* DA906X_REG_VLDOx_A/B (addr=0xA9-0x3, 0xBA-0xC4) */
+#define DA906X_LDO_SL				0x80
+
+/* DA906X_REG_VLDO1_A/B (addr=0xA9, 0xBA) */
+#define DA906X_VLDO1_MASK			0x3F
+#define DA906X_VLDO1_SHIFT			0
+#define DA906X_VLDO1_BIAS			0
+
+/* DA906X_REG_VLDO2_A/B (addr=0xAA, 0xBB) */
+#define DA906X_VLDO2_MASK			0x3F
+#define DA906X_VLDO2_SHIFT			0
+#define DA906X_VLDO2_BIAS			0
+
+/* DA906X_REG_VLDO3_A/B (addr=0xAB, 0xBC) */
+#define DA906X_VLDO3_MASK			0x7F
+#define DA906X_VLDO3_SHIFT			0
+#define DA906X_VLDO3_BIAS			0
+
+/* DA906X_REG_VLDO4_A/B (addr=0xAC, 0xBD) */
+#define DA906X_VLDO4_MASK			0x7F
+#define DA906X_VLDO4_SHIFT			0
+#define DA906X_VLDO4_BIAS			0
+
+/* DA906X_REG_VLDO5_A/B (addr=0xAD, 0xBE) */
+#define DA906X_VLDO5_MASK			0x3F
+#define DA906X_VLDO5_SHIFT			0
+#define DA906X_VLDO5_BIAS			2
+
+/* DA906X_REG_VLDO6_A/B (addr=0xAE, 0xBF) */
+#define DA906X_VLDO6_MASK			0x3F
+#define DA906X_VLDO6_SHIFT			0
+#define DA906X_VLDO6_BIAS			2
+
+/* DA906X_REG_VLDO7_A/B (addr=0xAF, 0xC0) */
+#define DA906X_VLDO7_MASK			0x3F
+#define DA906X_VLDO7_SHIFT			0
+#define DA906X_VLDO7_BIAS			2
+
+/* DA906X_REG_VLDO8_A/B (addr=0xB0, 0xC1) */
+#define DA906X_VLDO8_MASK			0x3F
+#define DA906X_VLDO8_SHIFT			0
+#define DA906X_VLDO8_BIAS			2
+
+/* DA906X_REG_VLDO9_A/B (addr=0xB1, 0xC2) */
+#define DA906X_VLDO9_MASK			0x3F
+#define DA906X_VLDO9_SHIFT			0
+#define DA906X_VLDO9_BIAS			3
+
+/* DA906X_REG_VLDO10_A/B (addr=0xB2, 0xC3) */
+#define DA906X_VLDO10_MASK			0x3F
+#define DA906X_VLDO10_SHIFT			0
+#define DA906X_VLDO10_BIAS			2
+
+/* DA906X_REG_VLDO11_A/B (addr=0xB3, 0xC4) */
+#define DA906X_VLDO11_MASK			0x3F
+#define DA906X_VLDO11_SHIFT			0
+#define DA906X_VLDO11_BIAS			2
+
+/* DA906X_REG_GPO11_LED (addr=0xC6) */
+/* DA906X_REG_GPO14_LED (addr=0xC7) */
+/* DA906X_REG_GPO15_LED (addr=0xC8) */
+#define DA906X_GPIO_DIM				0x80
+#define DA906X_GPIO_PWM_SHIFT			0
+#define DA906X_GPIO_PWM_MASK			0x7F
+
+/* DA906X_REG_CONFIG_H (addr=0x10D) */
+#define DA906X_PWM_CLK_MASK			0x01
+#define		DA906X_PWM_CLK_PWM2MHZ		0x00
+#define		DA906X_PWM_CLK_PWM1MHZ		0x01
+#define DA906X_LDO8_MODE_MASK			0x02
+#define		DA906X_LDO8_MODE_LDO		0
+#define		DA906X_LDO8_MODE_VIBR		0x02
+#define DA906X_MERGE_SENSE_MASK			0x04
+#define 	DA906X_MERGE_SENSE_GP_FB2	0x00
+#define 	DA906X_MERGE_SENSE_GPIO4	0x04
+#define DA906X_BCORE_MERGE			0x08
+#define DA906X_BPRO_OD				0x10
+#define DA906X_BCORE2_OD			0x20
+#define DA906X_BCORE1_OD			0x40
+#define DA906X_BUCK_MERGE			0x80
+
+/* DA906X_REG_CONFIG_I (addr=0x10E) */
+#define DA906X_NONKEY_PIN_MASK			0x03
+#define		DA906X_NONKEY_PIN_PORT		0x00
+#define		DA906X_NONKEY_PIN_SWDOWN	0x01
+#define		DA906X_NONKEY_PIN_AUTODOWN	0x02
+#define		DA906X_NONKEY_PIN_AUTOFLPRT	0x03
+
+/* DA906X_REG_MON_REG_5 (addr=0x116) */
+#define DA906X_MON_A8_IDX_SHIFT			0
+#define DA906X_MON_A8_IDX_MASK			0x07
+#define		DA9063_MON_A8_IDX_NONE		0x00
+#define		DA9063_MON_A8_IDX_BCORE1	0x01
+#define		DA9063_MON_A8_IDX_BCORE2	0x02
+#define		DA9063_MON_A8_IDX_BPRO		0x03
+#define		DA9063_MON_A8_IDX_LDO3		0x04
+#define		DA9063_MON_A8_IDX_LDO4		0x05
+#define		DA9063_MON_A8_IDX_LDO11		0x06
+#define DA906X_MON_A9_IDX_SHIFT			4
+#define DA906X_MON_A9_IDX_MASK			0x70
+#define		DA9063_MON_A9_IDX_NONE		0x00
+#define		DA9063_MON_A9_IDX_BIO		0x01
+#define		DA9063_MON_A9_IDX_BMEM		0x02
+#define		DA9063_MON_A9_IDX_BPERI		0x03
+#define		DA9063_MON_A9_IDX_LDO1		0x04
+#define		DA9063_MON_A9_IDX_LDO2		0x05
+#define		DA9063_MON_A9_IDX_LDO5		0x06
+
+/* DA906X_REG_MON_REG_6 (addr=0x117) */
+#define DA906X_MON_A10_IDX_SHIFT		0
+#define DA906X_MON_A10_IDX_MASK			0x07
+#define		DA9063_MON_A10_IDX_NONE		0x00
+#define		DA9063_MON_A10_IDX_LDO6		0x01
+#define		DA9063_MON_A10_IDX_LDO7		0x02
+#define		DA9063_MON_A10_IDX_LDO8		0x03
+#define		DA9063_MON_A10_IDX_LDO9		0x04
+#define		DA9063_MON_A10_IDX_LDO10	0x05
+
+#endif /* _DA906X_REG_H */
+
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [lm-sensors] [PATCH 1/8] mfd: Add Dialog DA906x core driver.
@ 2012-08-24 13:50   ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 13:50 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

This is MFD module providing access to registers and interrupts of DA906x
series PMIC. It is used by other functional modules, registered as MFD cells.
Driver uses regmap with paging to access extended register list. Register map
is divided into two pages, where the second page is used during initialisation.

This module provides support to following functional cells:
 - Regulators
 - RTC
 - HWMON
 - OnKey (power key misc input device)
 - Vibration (force-feedback input device)
 - Watchdog
 - LEDs

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/mfd/Kconfig                  |   11 +
 drivers/mfd/Makefile                 |    4 +
 drivers/mfd/da906x-core.c            |  228 +++++++
 drivers/mfd/da906x-i2c.c             |  389 ++++++++++++
 drivers/mfd/da906x-irq.c             |  192 ++++++
 include/linux/mfd/da906x/core.h      |  121 ++++
 include/linux/mfd/da906x/pdata.h     |  114 ++++
 include/linux/mfd/da906x/registers.h | 1093 ++++++++++++++++++++++++++++++++++
 8 files changed, 2152 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mfd/da906x-core.c
 create mode 100644 drivers/mfd/da906x-i2c.c
 create mode 100644 drivers/mfd/da906x-irq.c
 create mode 100644 include/linux/mfd/da906x/core.h
 create mode 100644 include/linux/mfd/da906x/pdata.h
 create mode 100644 include/linux/mfd/da906x/registers.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index b1a1462..bf2a766 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -441,6 +441,17 @@ config MFD_DA9052_I2C
 	  for accessing the device, additional drivers must be enabled in
 	  order to use the functionality of the device.
 
+config MFD_DA906X
+	bool "Dialog Semiconductor DA906X PMIC Support"
+	depends on I2C=y
+	select MFD_CORE
+	select REGMAP_I2C
+	select REGMAP_IRQ
+	help
+	  Support for the Dialog Semiconductor DA906X PMIC. This includes
+	  I2C driver and core APIs, additional drivers must be enabled in
+	  order to use the functionality of the device.
+
 config PMIC_ADP5520
 	bool "Analog Devices ADP5520/01 MFD PMIC Core Support"
 	depends on I2C=y
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 79dd22d..f5a8432 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -90,8 +90,12 @@ obj-$(CONFIG_PMIC_DA9052)	+= da9052-core.o
 obj-$(CONFIG_MFD_DA9052_SPI)	+= da9052-spi.o
 obj-$(CONFIG_MFD_DA9052_I2C)	+= da9052-i2c.o
 
+da906x-objs			:= da906x-core.o da906x-irq.o da906x-i2c.o
+obj-$(CONFIG_MFD_DA906X)	+= da906x.o
+
 obj-$(CONFIG_MFD_MAX77686)	+= max77686.o max77686-irq.o
 obj-$(CONFIG_MFD_MAX77693)	+= max77693.o max77693-irq.o
+
 max8925-objs			:= max8925-core.o max8925-i2c.o
 obj-$(CONFIG_MFD_MAX8925)	+= max8925.o
 obj-$(CONFIG_MFD_MAX8997)	+= max8997.o max8997-irq.o
diff --git a/drivers/mfd/da906x-core.c b/drivers/mfd/da906x-core.c
new file mode 100644
index 0000000..fb3249f
--- /dev/null
+++ b/drivers/mfd/da906x-core.c
@@ -0,0 +1,228 @@
+/*
+ * da906x-core.c: Device access for Dialog DA906x modules
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>,
+ *         Michal Hajduk <michal.hajduk@diasemi.com>
+ *
+ *  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/init.h>
+#include <linux/slab.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/mutex.h>
+#include <linux/mfd/core.h>
+#include <linux/regmap.h>
+
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+#include <linux/mfd/da906x/registers.h>
+
+#include <linux/proc_fs.h>
+#include <linux/kthread.h>
+#include <linux/uaccess.h>
+
+
+static struct resource da906x_regulators_resources[] = {
+	{
+		.name	= "LDO_LIM",
+		.start	= DA906X_IRQ_LDO_LIM,
+		.end	= DA906X_IRQ_LDO_LIM,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct resource da906x_rtc_resources[] = {
+	{
+		.name	= "ALARM",
+		.start	= DA906X_IRQ_ALARM,
+		.end	= DA906X_IRQ_ALARM,
+		.flags	= IORESOURCE_IRQ,
+	},
+	{
+		.name	= "TICK",
+		.start	= DA906X_IRQ_TICK,
+		.end	= DA906X_IRQ_TICK,
+		.flags	= IORESOURCE_IRQ,
+	}
+};
+
+static struct resource da906x_onkey_resources[] = {
+	{
+		.start	= DA906X_IRQ_ONKEY,
+		.end	= DA906X_IRQ_ONKEY,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct resource da906x_hwmon_resources[] = {
+	{
+		.start	= DA906X_IRQ_ADC_RDY,
+		.end	= DA906X_IRQ_ADC_RDY,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+
+static struct mfd_cell da906x_devs[] = {
+	{
+		.name		= DA906X_DRVNAME_REGULATORS,
+		.num_resources	= ARRAY_SIZE(da906x_regulators_resources),
+		.resources	= da906x_regulators_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_LEDS,
+	},
+	{
+		.name		= DA906X_DRVNAME_WATCHDOG,
+	},
+	{
+		.name		= DA906X_DRVNAME_HWMON,
+		.num_resources	= ARRAY_SIZE(da906x_hwmon_resources),
+		.resources	= da906x_hwmon_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_ONKEY,
+		.num_resources	= ARRAY_SIZE(da906x_onkey_resources),
+		.resources	= da906x_onkey_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_RTC,
+		.num_resources	= ARRAY_SIZE(da906x_rtc_resources),
+		.resources	= da906x_rtc_resources,
+	},
+	{
+		.name		= DA906X_DRVNAME_VIBRATION,
+	},
+};
+
+inline unsigned int da906x_to_range_reg(u16 reg)
+{
+	return reg + DA906X_MAPPING_BASE;
+}
+
+int da906x_reg_read(struct da906x *da906x, u16 reg)
+{
+	unsigned int val;
+	int ret;
+
+	ret = regmap_read(da906x->regmap, da906x_to_range_reg(reg), &val);
+	if (ret < 0)
+		return ret;
+
+	return val;
+}
+
+int da906x_reg_write(struct da906x *da906x, u16 reg, u8 val)
+{
+	return regmap_write(da906x->regmap, da906x_to_range_reg(reg), val);
+}
+
+int da906x_block_read(struct da906x *da906x, u16 reg, int bytes, u8 *dst)
+{
+	return regmap_bulk_read(da906x->regmap, da906x_to_range_reg(reg),
+				dst, bytes);
+}
+
+int da906x_block_write(struct da906x *da906x, u16 reg, int bytes, const u8 *src)
+{
+	return regmap_bulk_write(da906x->regmap, da906x_to_range_reg(reg),
+				 src, bytes);
+}
+
+int da906x_reg_update(struct da906x *da906x, u16 reg, u8 mask, u8 val)
+{
+	return regmap_update_bits(da906x->regmap, da906x_to_range_reg(reg),
+				  mask, val);
+}
+
+int da906x_reg_set_bits(struct da906x *da906x, u16 reg, u8 mask)
+{
+	return da906x_reg_update(da906x, reg, mask, mask);
+}
+
+int da906x_reg_clear_bits(struct da906x *da906x, u16 reg, u8 mask)
+{
+	return da906x_reg_update(da906x, reg, mask, 0);
+}
+
+int da906x_device_init(struct da906x *da906x, unsigned int irq)
+{
+	struct da906x_pdata *pdata = da906x->dev->platform_data;
+	int ret = 0;
+	int model;
+	unsigned short revision;
+
+	mutex_init(&da906x->io_mutex);
+
+	if (pdata = NULL) {
+		dev_err(da906x->dev, "Platform data not specified.\n");
+		return -EINVAL;
+	}
+	da906x->flags = pdata->flags;
+	da906x->irq_base = pdata->irq_base;
+	da906x->chip_irq = irq;
+
+	if (pdata->init != NULL) {
+		ret = pdata->init(da906x);
+		if (ret != 0) {
+			dev_err(da906x->dev,
+				"Platform initialization failed.\n");
+			return ret;
+		}
+	}
+
+	model = da906x_reg_read(da906x, DA906X_REG_CHIP_ID);
+	if (model < 0) {
+		dev_err(da906x->dev, "Cannot read chip model id.\n");
+		return -EIO;
+	}
+
+	ret = da906x_reg_read(da906x, DA906X_REG_CHIP_VARIANT);
+	if (ret < 0) {
+		dev_err(da906x->dev, "Cannot read chip revision id.\n");
+		return -EIO;
+	}
+
+	revision = ret >> DA906X_CHIP_VARIANT_SHIFT;
+
+	da906x_set_model_rev(da906x, model, revision);
+
+	dev_info(da906x->dev,
+		 "Device detected (model-ID: 0x%02X  rev-ID: 0x%02X)\n",
+		 model, revision);
+
+	ret = da906x_irq_init(da906x);
+	if (ret) {
+		dev_err(da906x->dev, "Cannot initialize interrupts.\n");
+		return ret;
+	}
+
+	ret = mfd_add_devices(da906x->dev, -1, da906x_devs,
+			      ARRAY_SIZE(da906x_devs), NULL, da906x->irq_base);
+	if (ret)
+		dev_err(da906x->dev, "Cannot add MFD cells\n");
+
+	return ret;
+}
+
+void da906x_device_exit(struct da906x *da906x)
+{
+	mfd_remove_devices(da906x->dev);
+	da906x_irq_exit(da906x);
+}
+
+MODULE_DESCRIPTION("PMIC driver for Dialog DA906X");
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>, Michal Hajduk <michal.hajduk@diasemi.com>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DA906X_DRVNAME_CORE);
diff --git a/drivers/mfd/da906x-i2c.c b/drivers/mfd/da906x-i2c.c
new file mode 100644
index 0000000..90b9e23
--- /dev/null
+++ b/drivers/mfd/da906x-i2c.c
@@ -0,0 +1,389 @@
+/* da906x-i2c.c: Interrupt support for Dialog DA906x
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/i2c.h>
+#include <linux/regmap.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/err.h>
+
+#include <linux/mfd/core.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+#include <linux/mfd/da906x/registers.h>
+
+
+#define RD		0x01	/* Readable register */
+#define WR		0x02	/* Writable register */
+#define VOL		0x04	/* Volatile register */
+
+/* Flags for virtual registers (mapped starting from DA906X_MAPPING_BASE) */
+const unsigned char da906x_reg_flg[] = {
+	[DA906X_REG_STATUS_A] =		RD | VOL,
+	[DA906X_REG_STATUS_B] =		RD | VOL,
+	[DA906X_REG_STATUS_C] =		RD | VOL,
+	[DA906X_REG_STATUS_D] =		RD | VOL,
+	[DA906X_REG_FAULT_LOG] =	RD | WR | VOL,
+	[DA906X_REG_EVENT_A] =		RD | WR | VOL,
+	[DA906X_REG_EVENT_B] =		RD | WR | VOL,
+	[DA906X_REG_EVENT_C] =		RD | WR | VOL,
+	[DA906X_REG_EVENT_D] =		RD | WR | VOL,
+	[DA906X_REG_IRQ_MASK_A] =	RD | WR,
+	[DA906X_REG_IRQ_MASK_B] =	RD | WR,
+	[DA906X_REG_IRQ_MASK_C] =	RD | WR,
+	[DA906X_REG_IRQ_MASK_D] =	RD | WR,
+	[DA906X_REG_CONTROL_A] =	RD | WR,
+	[DA906X_REG_CONTROL_B] =	RD | WR,
+	[DA906X_REG_CONTROL_C] =	RD | WR,
+	[DA906X_REG_CONTROL_D] =	RD | WR,
+	[DA906X_REG_CONTROL_E] =	RD | WR,
+	[DA906X_REG_CONTROL_F] =	RD | WR | VOL,
+	[DA906X_REG_PD_DIS] =		RD | WR,
+
+	[DA906X_REG_GPIO_0_1] =		RD | WR,
+	[DA906X_REG_GPIO_2_3] =		RD | WR,
+	[DA906X_REG_GPIO_4_5] =		RD | WR,
+	[DA906X_REG_GPIO_6_7] =		RD | WR,
+	[DA906X_REG_GPIO_8_9] =		RD | WR,
+	[DA906X_REG_GPIO_10_11] =	RD | WR,
+	[DA906X_REG_GPIO_12_13] =	RD | WR,
+	[DA906X_REG_GPIO_14_15] =	RD | WR,
+	[DA906X_REG_GPIO_MODE_0_7] =	RD | WR,
+	[DA906X_REG_GPIO_MODE_8_15] =	RD | WR,
+	[DA906X_REG_GPIO_SWITCH_CONT] =	RD | WR,
+
+	[DA906X_REG_BCORE2_CONT] =	RD | WR,
+	[DA906X_REG_BCORE1_CONT] =	RD | WR,
+	[DA906X_REG_BPRO_CONT] =	RD | WR,
+	[DA906X_REG_BMEM_CONT] =	RD | WR,
+	[DA906X_REG_BIO_CONT] =		RD | WR,
+	[DA906X_REG_BPERI_CONT] =	RD | WR,
+	[DA906X_REG_LDO1_CONT] =	RD | WR,
+	[DA906X_REG_LDO2_CONT] =	RD | WR,
+	[DA906X_REG_LDO3_CONT] =	RD | WR,
+	[DA906X_REG_LDO4_CONT] =	RD | WR,
+	[DA906X_REG_LDO5_CONT] =	RD | WR,
+	[DA906X_REG_LDO6_CONT] =	RD | WR,
+	[DA906X_REG_LDO7_CONT] =	RD | WR,
+	[DA906X_REG_LDO8_CONT] =	RD | WR,
+	[DA906X_REG_LDO9_CONT] =	RD | WR,
+	[DA906X_REG_LDO10_CONT] =	RD | WR,
+	[DA906X_REG_LDO11_CONT] =	RD | WR,
+	[DA906X_REG_VIB] =		RD | WR,
+	[DA906X_REG_DVC_1] =		RD | WR,
+	[DA906X_REG_DVC_2] =		RD | WR,
+
+	[DA906X_REG_ADC_MAN] =		RD | WR | VOL,
+	[DA906X_REG_ADC_CONT] =		RD | WR,
+	[DA906X_REG_VSYS_MON] =		RD | WR,
+	[DA906X_REG_ADC_RES_L] =	RD | VOL,
+	[DA906X_REG_ADC_RES_H] =	RD | VOL,
+	[DA906X_REG_VSYS_RES] =		RD | VOL,
+	[DA906X_REG_ADCIN1_RES] =	RD | VOL,
+	[DA906X_REG_ADCIN2_RES] =	RD | VOL,
+	[DA906X_REG_ADCIN3_RES] =	RD | VOL,
+	[DA906X_REG_MON1_RES] =		RD | VOL,
+	[DA906X_REG_MON2_RES] =		RD | VOL,
+	[DA906X_REG_MON3_RES] =		RD | VOL,
+
+	[DA906X_REG_COUNT_S] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_MI] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_H] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_D] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_MO] =		RD | WR | VOL,
+	[DA906X_REG_COUNT_Y] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_MI] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_H] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_D] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_MO] =		RD | WR | VOL,
+	[DA906X_REG_ALARM_Y] =		RD | WR | VOL,
+	[DA906X_REG_SECOND_A] =		RD | VOL,
+	[DA906X_REG_SECOND_B] =		RD | VOL,
+	[DA906X_REG_SECOND_C] =		RD | VOL,
+	[DA906X_REG_SECOND_D] =		RD | VOL,
+
+	[DA906X_REG_SEQ] =		RD | WR,
+	[DA906X_REG_SEQ_TIMER] =	RD | WR,
+	[DA906X_REG_ID_2_1] =		RD | WR,
+	[DA906X_REG_ID_4_3] =		RD | WR,
+	[DA906X_REG_ID_6_5] =		RD | WR,
+	[DA906X_REG_ID_8_7] =		RD | WR,
+	[DA906X_REG_ID_10_9] =		RD | WR,
+	[DA906X_REG_ID_12_11] =		RD | WR,
+	[DA906X_REG_ID_14_13] =		RD | WR,
+	[DA906X_REG_ID_16_15] =		RD | WR,
+	[DA906X_REG_ID_18_17] =		RD | WR,
+	[DA906X_REG_ID_20_19] =		RD | WR,
+	[DA906X_REG_ID_22_21] =		RD | WR,
+	[DA906X_REG_ID_24_23] =		RD | WR,
+	[DA906X_REG_ID_26_25] =		RD | WR,
+	[DA906X_REG_ID_28_27] =		RD | WR,
+	[DA906X_REG_ID_30_29] =		RD | WR,
+	[DA906X_REG_ID_32_31] =		RD | WR,
+	[DA906X_REG_SEQ_A] =		RD | WR,
+	[DA906X_REG_SEQ_B] =		RD | WR,
+	[DA906X_REG_WAIT] =		RD | WR,
+	[DA906X_REG_EN_32K] =		RD | WR,
+	[DA906X_REG_RESET] =		RD | WR,
+
+	[DA906X_REG_BUCK_ILIM_A] =	RD | WR,
+	[DA906X_REG_BUCK_ILIM_B] =	RD | WR,
+	[DA906X_REG_BUCK_ILIM_C] =	RD | WR,
+	[DA906X_REG_BCORE2_CFG] =	RD | WR,
+	[DA906X_REG_BCORE1_CFG] =	RD | WR,
+	[DA906X_REG_BPRO_CFG] =		RD | WR,
+	[DA906X_REG_BIO_CFG] =		RD | WR,
+	[DA906X_REG_BMEM_CFG] =		RD | WR,
+	[DA906X_REG_BPERI_CFG] =	RD | WR,
+	[DA906X_REG_VBCORE2_A] =	RD | WR,
+	[DA906X_REG_VBCORE1_A] =	RD | WR,
+	[DA906X_REG_VBPRO_A] =		RD | WR,
+	[DA906X_REG_VBMEM_A] =		RD | WR,
+	[DA906X_REG_VBIO_A] =		RD | WR,
+	[DA906X_REG_VBPERI_A] =		RD | WR,
+	[DA906X_REG_VLDO1_A] =		RD | WR,
+	[DA906X_REG_VLDO2_A] =		RD | WR,
+	[DA906X_REG_VLDO3_A] =		RD | WR,
+	[DA906X_REG_VLDO4_A] =		RD | WR,
+	[DA906X_REG_VLDO5_A] =		RD | WR,
+	[DA906X_REG_VLDO6_A] =		RD | WR,
+	[DA906X_REG_VLDO7_A] =		RD | WR,
+	[DA906X_REG_VLDO8_A] =		RD | WR,
+	[DA906X_REG_VLDO9_A] =		RD | WR,
+	[DA906X_REG_VLDO10_A] =		RD | WR,
+	[DA906X_REG_VLDO11_A] =		RD | WR,
+	[DA906X_REG_VBCORE2_B] =	RD | WR,
+	[DA906X_REG_VBCORE1_B] =	RD | WR,
+	[DA906X_REG_VBPRO_B] =		RD | WR,
+	[DA906X_REG_VBMEM_B] =		RD | WR,
+	[DA906X_REG_VBIO_B] =		RD | WR,
+	[DA906X_REG_VBPERI_B] =		RD | WR,
+	[DA906X_REG_VLDO1_B] =		RD | WR,
+	[DA906X_REG_VLDO2_B] =		RD | WR,
+	[DA906X_REG_VLDO3_B] =		RD | WR,
+	[DA906X_REG_VLDO4_B] =		RD | WR,
+	[DA906X_REG_VLDO5_B] =		RD | WR,
+	[DA906X_REG_VLDO6_B] =		RD | WR,
+	[DA906X_REG_VLDO7_B] =		RD | WR,
+	[DA906X_REG_VLDO8_B] =		RD | WR,
+	[DA906X_REG_VLDO9_B] =		RD | WR,
+	[DA906X_REG_VLDO10_B] =		RD | WR,
+	[DA906X_REG_VLDO11_B] =		RD | WR,
+
+	[DA906X_REG_BBAT_CONT] =	RD | WR,
+
+	[DA906X_REG_GPO11_LED] =	RD | WR,
+	[DA906X_REG_GPO14_LED] =	RD | WR,
+	[DA906X_REG_GPO15_LED] =	RD | WR,
+
+	[DA906X_REG_ADC_CFG] =		RD | WR,
+	[DA906X_REG_AUTO1_HIGH] =	RD | WR,
+	[DA906X_REG_AUTO1_LOW] =	RD | WR,
+	[DA906X_REG_AUTO2_HIGH] =	RD | WR,
+	[DA906X_REG_AUTO2_LOW] =	RD | WR,
+	[DA906X_REG_AUTO3_HIGH] =	RD | WR,
+	[DA906X_REG_AUTO3_LOW] =	RD | WR,
+
+	[DA906X_REG_T_OFFSET] =		RD,
+	[DA906X_REG_CONFIG_H] =		RD,
+	[DA906X_REG_CONFIG_I] =		RD | WR,
+	[DA906X_REG_MON_REG_1] =	RD | WR,
+	[DA906X_REG_MON_REG_2] =	RD | WR,
+	[DA906X_REG_MON_REG_3] =	RD | WR,
+	[DA906X_REG_MON_REG_4] =	RD | WR,
+	[DA906X_REG_MON_REG_5] =	RD | VOL,
+	[DA906X_REG_MON_REG_6] =	RD | VOL,
+	[DA906X_REG_TRIM_CLDR] =	RD,
+
+	[DA906X_REG_GP_ID_0] =		RD | WR,
+	[DA906X_REG_GP_ID_1] =		RD | WR,
+	[DA906X_REG_GP_ID_2] =		RD | WR,
+	[DA906X_REG_GP_ID_3] =		RD | WR,
+	[DA906X_REG_GP_ID_4] =		RD | WR,
+	[DA906X_REG_GP_ID_5] =		RD | WR,
+	[DA906X_REG_GP_ID_6] =		RD | WR,
+	[DA906X_REG_GP_ID_7] =		RD | WR,
+	[DA906X_REG_GP_ID_8] =		RD | WR,
+	[DA906X_REG_GP_ID_9] =		RD | WR,
+	[DA906X_REG_GP_ID_10] =		RD | WR,
+	[DA906X_REG_GP_ID_11] =		RD | WR,
+	[DA906X_REG_GP_ID_12] =		RD | WR,
+	[DA906X_REG_GP_ID_13] =		RD | WR,
+	[DA906X_REG_GP_ID_14] =		RD | WR,
+	[DA906X_REG_GP_ID_15] =		RD | WR,
+	[DA906X_REG_GP_ID_16] =		RD | WR,
+	[DA906X_REG_GP_ID_17] =		RD | WR,
+	[DA906X_REG_GP_ID_18] =		RD | WR,
+	[DA906X_REG_GP_ID_19] =		RD | WR,
+
+	[DA906X_REG_CHIP_ID] =		RD,
+	[DA906X_REG_CHIP_VARIANT] =	RD,
+};
+
+static bool da906x_reg_readable(struct device *dev, unsigned int reg)
+{
+	if (reg < DA906X_MAPPING_BASE) {
+		return true;
+	} else {
+		reg -= DA906X_MAPPING_BASE;
+		if (da906x_reg_flg[reg] & RD)
+			return true;
+		else
+			return false;
+	}
+}
+
+static bool da906x_reg_writable(struct device *dev, unsigned int reg)
+{
+	if (reg < DA906X_MAPPING_BASE) {
+		return true;
+	} else {
+		reg -= DA906X_MAPPING_BASE;
+		if (da906x_reg_flg[reg] & WR)
+			return true;
+		else
+			return false;
+	}
+}
+
+static bool da906x_reg_volatile(struct device *dev, unsigned int reg)
+{
+	if (reg < DA906X_MAPPING_BASE) {
+		switch (reg) {
+		case DA906X_REG_PAGE_CON:    /* Use cache for page selector */
+			return false;
+		default:
+			return true;
+		}
+	} else {
+		reg -= DA906X_MAPPING_BASE;
+		if (da906x_reg_flg[reg] & VOL)
+			return true;
+		else
+			return false;
+	}
+}
+
+static const struct regmap_range_cfg da906x_range_cfg[] = {
+	{
+		.range_min = DA906X_MAPPING_BASE,
+		.range_max = DA906X_MAPPING_BASE +
+			     ARRAY_SIZE(da906x_reg_flg) - 1,
+		.selector_reg = DA906X_REG_PAGE_CON,
+		.selector_mask = 1 << DA906X_I2C_PAGE_SEL_SHIFT,
+		.selector_shift = DA906X_I2C_PAGE_SEL_SHIFT,
+		.window_start = 0,
+		.window_len = 256,
+	}
+};
+
+struct regmap_config da906x_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.ranges = da906x_range_cfg,
+	.n_ranges = ARRAY_SIZE(da906x_range_cfg),
+	.max_register = DA906X_MAPPING_BASE + ARRAY_SIZE(da906x_reg_flg) - 1,
+
+	.cache_type = REGCACHE_RBTREE,
+
+	.writeable_reg = &da906x_reg_writable,
+	.readable_reg = &da906x_reg_readable,
+	.volatile_reg = &da906x_reg_volatile,
+};
+
+struct regmap_config da906x_no_cache_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.ranges = da906x_range_cfg,
+	.n_ranges = ARRAY_SIZE(da906x_range_cfg),
+	.max_register = DA906X_MAPPING_BASE + ARRAY_SIZE(da906x_reg_flg) - 1,
+
+	.cache_type = REGCACHE_NONE,
+
+	.writeable_reg = &da906x_reg_writable,
+	.readable_reg = &da906x_reg_readable,
+};
+
+static int da906x_i2c_probe(struct i2c_client *i2c,
+	const struct i2c_device_id *id)
+{
+	struct da906x *da906x;
+	struct regmap_config *config = &da906x_regmap_config;
+	struct da906x_pdata *pdata = i2c->dev.platform_data;
+	int ret;
+
+	da906x = devm_kzalloc(&i2c->dev, sizeof(struct da906x), GFP_KERNEL);
+	if (da906x = NULL)
+		return -ENOMEM;
+
+	i2c_set_clientdata(i2c, da906x);
+	da906x->dev = &i2c->dev;
+
+	if (pdata->flags & DA906X_FLG_NO_CACHE)
+		config = &da906x_no_cache_regmap_config;
+
+	da906x->regmap = devm_regmap_init_i2c(i2c, config);
+	if (IS_ERR(da906x->regmap)) {
+		ret = PTR_ERR(da906x->regmap);
+		dev_err(da906x->dev, "Failed to allocate register map: %d\n",
+			ret);
+		return ret;
+	}
+
+	return da906x_device_init(da906x, i2c->irq);
+}
+
+static int da906x_i2c_remove(struct i2c_client *i2c)
+{
+	struct da906x *da906x = i2c_get_clientdata(i2c);
+
+	da906x_device_exit(da906x);
+
+	return 0;
+}
+
+static const struct i2c_device_id da906x_i2c_id[] = {
+	{"da906x", PMIC_DA9063},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, da906x_i2c_id);
+
+static struct i2c_driver da906x_i2c_driver = {
+	.driver = {
+		.name = "da906x",
+		.owner = THIS_MODULE,
+	},
+	.probe    = da906x_i2c_probe,
+	.remove   = da906x_i2c_remove,
+	.id_table = da906x_i2c_id,
+};
+
+static int __init da906x_i2c_init(void)
+{
+	int ret;
+
+	ret = i2c_add_driver(&da906x_i2c_driver);
+	if (ret != 0)
+		pr_err("Failed to register da906x I2C driver\n");
+
+	return ret;
+}
+subsys_initcall(da906x_i2c_init);
+
+static void __exit da906x_i2c_exit(void)
+{
+	i2c_del_driver(&da906x_i2c_driver);
+}
+module_exit(da906x_i2c_exit);
diff --git a/drivers/mfd/da906x-irq.c b/drivers/mfd/da906x-irq.c
new file mode 100644
index 0000000..18d2796
--- /dev/null
+++ b/drivers/mfd/da906x-irq.c
@@ -0,0 +1,192 @@
+/* da906x-irq.c: Interrupts support for Dialog DA906X
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ *
+ *  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/irq.h>
+#include <linux/mfd/core.h>
+#include <linux/interrupt.h>
+#include <linux/regmap.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+
+#define	DA906X_REG_EVENT_A_OFFSET	0
+#define	DA906X_REG_EVENT_B_OFFSET	1
+#define	DA906X_REG_EVENT_C_OFFSET	2
+#define	DA906X_REG_EVENT_D_OFFSET	3
+#define EVENTS_BUF_LEN			4
+
+static const u8 mask_events_buf[] = { [0 ... (EVENTS_BUF_LEN - 1)] = ~0 };
+
+struct da906x_irq_data {
+	u16 reg;
+	u8 mask;
+};
+
+static struct regmap_irq da906x_irqs[] = {
+	/* DA906x event A register */
+	[DA906X_IRQ_ONKEY] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_ONKEY,
+	},
+	[DA906X_IRQ_ALARM] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_ALARM,
+	},
+	[DA906X_IRQ_TICK] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_TICK,
+	},
+	[DA906X_IRQ_ADC_RDY] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_ADC_RDY,
+	},
+	[DA906X_IRQ_SEQ_RDY] = {
+		.reg_offset = DA906X_REG_EVENT_A_OFFSET,
+		.mask = DA906X_M_SEQ_RDY,
+	},
+	/* DA906x event B register */
+	[DA906X_IRQ_WAKE] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_WAKE,
+	},
+	[DA906X_IRQ_TEMP] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_TEMP,
+	},
+	[DA906X_IRQ_COMP_1V2] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_COMP_1V2,
+	},
+	[DA906X_IRQ_LDO_LIM] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_LDO_LIM,
+	},
+	[DA906X_IRQ_REG_UVOV] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_UVOV,
+	},
+	[DA906X_IRQ_VDD_MON] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_VDD_MON,
+	},
+	[DA906X_IRQ_WARN] = {
+		.reg_offset = DA906X_REG_EVENT_B_OFFSET,
+		.mask = DA906X_M_VDD_WARN,
+	},
+	/* DA906x event C register */
+	[DA906X_IRQ_GPI0] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI0,
+	},
+	[DA906X_IRQ_GPI1] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI1,
+	},
+	[DA906X_IRQ_GPI2] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI2,
+	},
+	[DA906X_IRQ_GPI3] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI3,
+	},
+	[DA906X_IRQ_GPI4] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI4,
+	},
+	[DA906X_IRQ_GPI5] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI5,
+	},
+	[DA906X_IRQ_GPI6] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI6,
+	},
+	[DA906X_IRQ_GPI7] = {
+		.reg_offset = DA906X_REG_EVENT_C_OFFSET,
+		.mask = DA906X_M_GPI7,
+	},
+	/* DA906x event D register */
+	[DA906X_IRQ_GPI8] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI8,
+	},
+	[DA906X_IRQ_GPI9] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI9,
+	},
+	[DA906X_IRQ_GPI10] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI10,
+	},
+	[DA906X_IRQ_GPI11] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI11,
+	},
+	[DA906X_IRQ_GPI12] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI12,
+	},
+	[DA906X_IRQ_GPI13] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI13,
+	},
+	[DA906X_IRQ_GPI14] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI14,
+	},
+	[DA906X_IRQ_GPI15] = {
+		.reg_offset = DA906X_REG_EVENT_D_OFFSET,
+		.mask = DA906X_M_GPI15,
+	},
+};
+
+static struct regmap_irq_chip da906x_irq_chip = {
+	.name = "da906x-irq",
+	.irqs = da906x_irqs,
+	.num_irqs = DA906X_NUM_IRQ,
+
+	.num_regs = 4,
+	.status_base = DA906X_REG_EVENT_A + DA906X_MAPPING_BASE,
+	.mask_base = DA906X_REG_IRQ_MASK_A + DA906X_MAPPING_BASE,
+	.ack_base = DA906X_REG_EVENT_A + DA906X_MAPPING_BASE,
+};
+
+int da906x_irq_init(struct da906x *da906x)
+{
+	int ret;
+
+	if (!da906x->chip_irq) {
+		dev_err(da906x->dev, "No IRQ configured\n");
+		return -EINVAL;
+	}
+
+	ret = regmap_add_irq_chip(da906x->regmap, da906x->chip_irq,
+			IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED,
+			da906x->irq_base, &da906x_irq_chip,
+			&da906x->regmap_irq);
+	if (ret) {
+		dev_err(da906x->dev, "Failed to reguest IRQ %d: %d\n",
+				da906x->chip_irq, ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+void da906x_irq_exit(struct da906x *da906x)
+{
+	regmap_del_irq_chip(da906x->chip_irq, da906x->regmap_irq);
+}
+
diff --git a/include/linux/mfd/da906x/core.h b/include/linux/mfd/da906x/core.h
new file mode 100644
index 0000000..abd916d
--- /dev/null
+++ b/include/linux/mfd/da906x/core.h
@@ -0,0 +1,121 @@
+/*
+ * Definitions for DA906X MFD driver
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ *	   Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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.
+ *
+ */
+
+#ifndef __MFD_DA906X_CORE_H__
+#define __MFD_DA906X_CORE_H__
+
+#include <linux/interrupt.h>
+#include <linux/mfd/da906x/registers.h>
+
+/* DA906x modules */
+#define DA906X_DRVNAME_CORE		"da906x-core"
+#define DA906X_DRVNAME_REGULATORS	"da906x-regulators"
+#define DA906X_DRVNAME_LEDS		"da906x-leds"
+#define DA906X_DRVNAME_WATCHDOG		"da906x-watchdog"
+#define DA906X_DRVNAME_HWMON		"da906x-hwmon"
+#define DA906X_DRVNAME_ONKEY		"da906x-onkey"
+#define DA906X_DRVNAME_RTC		"da906x-rtc"
+#define DA906X_DRVNAME_VIBRATION	"da906x-vibration"
+
+enum da906x_models {
+	PMIC_DA9063 = 0x61,
+};
+
+/* Interrupts */
+enum da906x_irqs {
+	DA906X_IRQ_ONKEY = 0,
+	DA906X_IRQ_ALARM,
+	DA906X_IRQ_TICK,
+	DA906X_IRQ_ADC_RDY,
+	DA906X_IRQ_SEQ_RDY,
+	DA906X_IRQ_WAKE,
+	DA906X_IRQ_TEMP,
+	DA906X_IRQ_COMP_1V2,
+	DA906X_IRQ_LDO_LIM,
+	DA906X_IRQ_REG_UVOV,
+	DA906X_IRQ_VDD_MON,
+	DA906X_IRQ_WARN,
+	DA906X_IRQ_GPI0,
+	DA906X_IRQ_GPI1,
+	DA906X_IRQ_GPI2,
+	DA906X_IRQ_GPI3,
+	DA906X_IRQ_GPI4,
+	DA906X_IRQ_GPI5,
+	DA906X_IRQ_GPI6,
+	DA906X_IRQ_GPI7,
+	DA906X_IRQ_GPI8,
+	DA906X_IRQ_GPI9,
+	DA906X_IRQ_GPI10,
+	DA906X_IRQ_GPI11,
+	DA906X_IRQ_GPI12,
+	DA906X_IRQ_GPI13,
+	DA906X_IRQ_GPI14,
+	DA906X_IRQ_GPI15,
+};
+
+#define DA906X_IRQ_BASE_OFFSET	0
+#define DA906X_NUM_IRQ		(DA906X_IRQ_GPI15 + 1 - DA906X_IRQ_BASE_OFFSET)
+
+struct da906x {
+	/* Device */
+	struct device	*dev;
+	unsigned short	model;
+	unsigned short	revision;
+	unsigned int	flags;
+
+	/* Control interface */
+	struct mutex	io_mutex;
+	struct regmap	*regmap;
+
+	/* Interrupts */
+	int		chip_irq;
+	unsigned int	irq_base;
+	struct regmap_irq_chip_data *regmap_irq;
+};
+
+static inline unsigned da906x_model(struct da906x *da906x)
+{
+	return da906x->model;
+}
+
+static inline unsigned da906x_revision(struct da906x *da906x)
+{
+	return da906x->revision;
+}
+
+static inline void da906x_set_model_rev(struct da906x *da906x,
+			enum da906x_models model, unsigned short revision)
+{
+	da906x->model = model;
+	da906x->revision = revision;
+}
+
+int da906x_reg_read(struct da906x *da906x, u16 reg);
+int da906x_reg_write(struct da906x *da906x, u16 reg, u8 val);
+
+int da906x_block_write(struct da906x *da906x, u16 reg, int bytes, const u8 *buf);
+int da906x_block_read(struct da906x *da906x, u16 reg, int bytes, u8 *buf);
+
+int da906x_reg_set_bits(struct da906x *da906x, u16 reg, u8 mask);
+int da906x_reg_clear_bits(struct da906x *da906x, u16 reg, u8 mask);
+int da906x_reg_update(struct da906x*, u16 reg, u8 mask, u8 val);
+
+int da906x_device_init(struct da906x *da906x, unsigned int irq);
+int da906x_irq_init(struct da906x *da906x);
+
+void da906x_device_exit(struct da906x *da906x);
+void da906x_irq_exit(struct da906x *da906x);
+
+#endif /* __MFD_DA906X_CORE_H__ */
diff --git a/include/linux/mfd/da906x/pdata.h b/include/linux/mfd/da906x/pdata.h
new file mode 100644
index 0000000..97ae242
--- /dev/null
+++ b/include/linux/mfd/da906x/pdata.h
@@ -0,0 +1,114 @@
+/*
+ * Platform configuration options for DA906x
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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.
+ *
+ */
+
+#ifndef __MFD_DA906X_PDATA_H__
+#define __MFD_DA906X_PDATA_H__
+
+#include <linux/regulator/machine.h>
+
+/*
+ * Regulator configuration
+ */
+/* DA9063 regulator IDs */
+enum {
+	/* BUCKs */
+	DA9063_ID_BCORE1,
+	DA9063_ID_BCORE2,
+	DA9063_ID_BPRO,
+	DA9063_ID_BMEM,
+	DA9063_ID_BIO,
+	DA9063_ID_BPERI,
+
+	/* BCORE1 and BCORE2 in merged mode */
+	DA9063_ID_BCORES_MERGED,
+	/* BMEM and BIO in merged mode */
+	DA9063_ID_BMEM_BIO_MERGED,
+	/* When two BUCKs are merged, they cannot be reused separately */
+
+	/* LDOs */
+	DA9063_ID_LDO1,
+	DA9063_ID_LDO2,
+	DA9063_ID_LDO3,
+	DA9063_ID_LDO4,
+	DA9063_ID_LDO5,
+	DA9063_ID_LDO6,
+	DA9063_ID_LDO7,
+	DA9063_ID_LDO8,
+	DA9063_ID_LDO9,
+	DA9063_ID_LDO10,
+	DA9063_ID_LDO11,
+
+	/* RTC internal oscilator switch */
+	DA9063_ID_32K_OUT,
+};
+
+/* Regulators platform data */
+struct da906x_regulator_data {
+	int				id;
+	struct regulator_init_data	*initdata;
+};
+
+struct da906x_regulators_pdata {
+	unsigned			n_regulators;
+	struct da906x_regulator_data	*regulator_data;
+};
+
+
+/*
+ * RGB LED configuration
+ */
+/* LED IDs for flags in struct led_info. */
+enum {
+	DA906X_GPIO11_LED,
+	DA906X_GPIO14_LED,
+	DA906X_GPIO15_LED,
+
+	DA906X_LED_NUM
+};
+#define DA906X_LED_ID_MASK		0x3
+
+/* LED polarity for flags in struct led_info. */
+#define DA906X_LED_HIGH_LEVEL_ACTIVE	0x0
+#define DA906X_LED_LOW_LEVEL_ACTIVE	0x4
+
+
+/*
+ * General PMIC configuration
+ */
+/* HWMON ADC channels configuration */
+#define DA906X_FLG_FORCE_IN0_MANUAL_MODE	0x0010
+#define DA906X_FLG_FORCE_IN0_AUTO_MODE		0x0020
+#define DA906X_FLG_FORCE_IN1_MANUAL_MODE	0x0040
+#define DA906X_FLG_FORCE_IN1_AUTO_MODE		0x0080
+#define DA906X_FLG_FORCE_IN2_MANUAL_MODE	0x0100
+#define DA906X_FLG_FORCE_IN2_AUTO_MODE		0x0200
+#define DA906X_FLG_FORCE_IN3_MANUAL_MODE	0x0400
+#define DA906X_FLG_FORCE_IN3_AUTO_MODE		0x0800
+
+/* Disable register caching. */
+#define DA906X_FLG_NO_CACHE			0x0008
+
+struct da906x;
+
+/* DA906x platform data */
+struct da906x_pdata {
+	int				(*init)(struct da906x *da906x);
+	int				irq_base;
+	unsigned			flags;
+	struct da906x_regulators_pdata	*regulators_pdata;
+	struct led_platform_data	*leds_pdata;
+};
+
+#endif	/* __MFD_DA906X_PDATA_H__ */
diff --git a/include/linux/mfd/da906x/registers.h b/include/linux/mfd/da906x/registers.h
new file mode 100644
index 0000000..6808977
--- /dev/null
+++ b/include/linux/mfd/da906x/registers.h
@@ -0,0 +1,1093 @@
+/*
+ * Registers definition for DA906X modules
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Michal Hajduk <michal.hajduk@diasemi.com>
+ *	   Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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.
+ *
+ */
+
+#ifndef _DA906X_REG_H
+#define	_DA906X_REG_H
+
+#define DA906X_I2C_PAGE_SEL_SHIFT	1
+#define DA906X_I2C_PAGE(v)		(((v) >> 8) << \
+						DA906X_I2C_PAGE_SEL_SHIFT)
+#define DA906X_I2C_REG(v)		((v) & 0xFF)
+
+#define	DA906X_EVENT_REG_NUM		4
+#define	DA9210_EVENT_REG_NUM		2
+#define	DA906X_EXT_EVENT_REG_NUM	(DA906X_EVENT_REG_NUM + \
+						DA9210_EVENT_REG_NUM)
+
+/* Page selection I2C or SPI always in the begining of any page. */
+/* Page 0 : I2C access 0x000 - 0x0FF	SPI access 0x000 - 0x07F */
+/* Page 1 :				SPI access 0x080 - 0x0FF */
+/* Page 2 : I2C access 0x100 - 0x1FF	SPI access 0x100 - 0x17F */
+/* Page 3 :				SPI access 0x180 - 0x1FF */
+#define	DA906X_REG_PAGE_CON		0x00
+
+/* Create virtual range for pageable registers just above physical range */
+#define DA906X_MAPPING_BASE		0x100
+
+/* System Control and Event Registers */
+#define	DA906X_REG_STATUS_A		0x01
+#define	DA906X_REG_STATUS_B		0x02
+#define	DA906X_REG_STATUS_C		0x03
+#define	DA906X_REG_STATUS_D		0x04
+#define	DA906X_REG_FAULT_LOG		0x05
+#define	DA906X_REG_EVENT_A		0x06
+#define	DA906X_REG_EVENT_B		0x07
+#define	DA906X_REG_EVENT_C		0x08
+#define	DA906X_REG_EVENT_D		0x09
+#define	DA906X_REG_IRQ_MASK_A		0x0A
+#define	DA906X_REG_IRQ_MASK_B		0x0B
+#define	DA906X_REG_IRQ_MASK_C		0x0C
+#define	DA906X_REG_IRQ_MASK_D		0x0D
+#define	DA906X_REG_CONTROL_A		0x0E
+#define	DA906X_REG_CONTROL_B		0x0F
+#define	DA906X_REG_CONTROL_C		0x10
+#define	DA906X_REG_CONTROL_D		0x11
+#define	DA906X_REG_CONTROL_E		0x12
+#define	DA906X_REG_CONTROL_F		0x13
+#define	DA906X_REG_PD_DIS		0x14
+
+/* GPIO Control Registers */
+#define	DA906X_REG_GPIO_0_1		0x15
+#define	DA906X_REG_GPIO_2_3		0x16
+#define	DA906X_REG_GPIO_4_5		0x17
+#define	DA906X_REG_GPIO_6_7		0x18
+#define	DA906X_REG_GPIO_8_9		0x19
+#define	DA906X_REG_GPIO_10_11		0x1A
+#define	DA906X_REG_GPIO_12_13		0x1B
+#define	DA906X_REG_GPIO_14_15		0x1C
+#define	DA906X_REG_GPIO_MODE_0_7	0x1D
+#define	DA906X_REG_GPIO_MODE_8_15	0x1E
+#define	DA906X_REG_GPIO_SWITCH_CONT	0x1F
+
+/* Regulator Control Registers */
+#define	DA906X_REG_BCORE2_CONT		0x20
+#define	DA906X_REG_BCORE1_CONT		0x21
+#define	DA906X_REG_BPRO_CONT		0x22
+#define	DA906X_REG_BMEM_CONT		0x23
+#define	DA906X_REG_BIO_CONT		0x24
+#define	DA906X_REG_BPERI_CONT		0x25
+#define	DA906X_REG_LDO1_CONT		0x26
+#define	DA906X_REG_LDO2_CONT		0x27
+#define	DA906X_REG_LDO3_CONT		0x28
+#define	DA906X_REG_LDO4_CONT		0x29
+#define	DA906X_REG_LDO5_CONT		0x2A
+#define	DA906X_REG_LDO6_CONT		0x2B
+#define	DA906X_REG_LDO7_CONT		0x2C
+#define	DA906X_REG_LDO8_CONT		0x2D
+#define	DA906X_REG_LDO9_CONT		0x2E
+#define	DA906X_REG_LDO10_CONT		0x2F
+#define	DA906X_REG_LDO11_CONT		0x30
+#define	DA906X_REG_VIB			0x31
+#define	DA906X_REG_DVC_1		0x32
+#define	DA906X_REG_DVC_2		0x33
+
+/* GP-ADC Control Registers */
+#define	DA906X_REG_ADC_MAN		0x34
+#define	DA906X_REG_ADC_CONT		0x35
+#define	DA906X_REG_VSYS_MON		0x36
+#define	DA906X_REG_ADC_RES_L		0x37
+#define	DA906X_REG_ADC_RES_H		0x38
+#define	DA906X_REG_VSYS_RES		0x39
+#define	DA906X_REG_ADCIN1_RES		0x3A
+#define	DA906X_REG_ADCIN2_RES		0x3B
+#define	DA906X_REG_ADCIN3_RES		0x3C
+#define	DA906X_REG_MON1_RES		0x3D
+#define	DA906X_REG_MON2_RES		0x3E
+#define	DA906X_REG_MON3_RES		0x3F
+
+/* RTC Calendar and Alarm Registers */
+#define	DA906X_REG_COUNT_S		0x40
+#define	DA906X_REG_COUNT_MI		0x41
+#define	DA906X_REG_COUNT_H		0x42
+#define	DA906X_REG_COUNT_D		0x43
+#define	DA906X_REG_COUNT_MO		0x44
+#define	DA906X_REG_COUNT_Y		0x45
+#define	DA906X_REG_ALARM_MI		0x46
+#define	DA906X_REG_ALARM_H		0x47
+#define	DA906X_REG_ALARM_D		0x48
+#define	DA906X_REG_ALARM_MO		0x49
+#define	DA906X_REG_ALARM_Y		0x4A
+#define	DA906X_REG_SECOND_A		0x4B
+#define	DA906X_REG_SECOND_B		0x4C
+#define	DA906X_REG_SECOND_C		0x4D
+#define	DA906X_REG_SECOND_D		0x4E
+
+/* Sequencer Control Registers */
+#define	DA906X_REG_SEQ			0x81
+#define	DA906X_REG_SEQ_TIMER		0x82
+#define	DA906X_REG_ID_2_1		0x83
+#define	DA906X_REG_ID_4_3		0x84
+#define	DA906X_REG_ID_6_5		0x85
+#define	DA906X_REG_ID_8_7		0x86
+#define	DA906X_REG_ID_10_9		0x87
+#define	DA906X_REG_ID_12_11		0x88
+#define	DA906X_REG_ID_14_13		0x89
+#define	DA906X_REG_ID_16_15		0x8A
+#define	DA906X_REG_ID_18_17		0x8B
+#define	DA906X_REG_ID_20_19		0x8C
+#define	DA906X_REG_ID_22_21		0x8D
+#define	DA906X_REG_ID_24_23		0x8E
+#define	DA906X_REG_ID_26_25		0x8F
+#define	DA906X_REG_ID_28_27		0x90
+#define	DA906X_REG_ID_30_29		0x91
+#define	DA906X_REG_ID_32_31		0x92
+#define	DA906X_REG_SEQ_A		0x95
+#define	DA906X_REG_SEQ_B		0x96
+#define	DA906X_REG_WAIT			0x97
+#define	DA906X_REG_EN_32K		0x98
+#define	DA906X_REG_RESET		0x99
+
+/* Regulator Setting Registers */
+#define	DA906X_REG_BUCK_ILIM_A		0x9A
+#define	DA906X_REG_BUCK_ILIM_B		0x9B
+#define	DA906X_REG_BUCK_ILIM_C		0x9C
+#define	DA906X_REG_BCORE2_CFG		0x9D
+#define	DA906X_REG_BCORE1_CFG		0x9E
+#define	DA906X_REG_BPRO_CFG		0x9F
+#define	DA906X_REG_BIO_CFG		0xA0
+#define	DA906X_REG_BMEM_CFG		0xA1
+#define	DA906X_REG_BPERI_CFG		0xA2
+#define	DA906X_REG_VBCORE2_A		0xA3
+#define	DA906X_REG_VBCORE1_A		0xA4
+#define	DA906X_REG_VBPRO_A		0xA5
+#define	DA906X_REG_VBMEM_A		0xA6
+#define	DA906X_REG_VBIO_A		0xA7
+#define	DA906X_REG_VBPERI_A		0xA8
+#define	DA906X_REG_VLDO1_A		0xA9
+#define	DA906X_REG_VLDO2_A		0xAA
+#define	DA906X_REG_VLDO3_A		0xAB
+#define	DA906X_REG_VLDO4_A		0xAC
+#define	DA906X_REG_VLDO5_A		0xAD
+#define	DA906X_REG_VLDO6_A		0xAE
+#define	DA906X_REG_VLDO7_A		0xAF
+#define	DA906X_REG_VLDO8_A		0xB0
+#define	DA906X_REG_VLDO9_A		0xB1
+#define	DA906X_REG_VLDO10_A		0xB2
+#define	DA906X_REG_VLDO11_A		0xB3
+#define	DA906X_REG_VBCORE2_B		0xB4
+#define	DA906X_REG_VBCORE1_B		0xB5
+#define	DA906X_REG_VBPRO_B		0xB6
+#define	DA906X_REG_VBMEM_B		0xB7
+#define	DA906X_REG_VBIO_B		0xB8
+#define	DA906X_REG_VBPERI_B		0xB9
+#define	DA906X_REG_VLDO1_B		0xBA
+#define	DA906X_REG_VLDO2_B		0xBB
+#define	DA906X_REG_VLDO3_B		0xBC
+#define	DA906X_REG_VLDO4_B		0xBD
+#define	DA906X_REG_VLDO5_B		0xBE
+#define	DA906X_REG_VLDO6_B		0xBF
+#define	DA906X_REG_VLDO7_B		0xC0
+#define	DA906X_REG_VLDO8_B		0xC1
+#define	DA906X_REG_VLDO9_B		0xC2
+#define	DA906X_REG_VLDO10_B		0xC3
+#define	DA906X_REG_VLDO11_B		0xC4
+
+/* Backup Battery Charger Control Register */
+#define	DA906X_REG_BBAT_CONT		0xC5
+
+/* GPIO PWM (LED) */
+#define	DA906X_REG_GPO11_LED		0xC6
+#define	DA906X_REG_GPO14_LED		0xC7
+#define	DA906X_REG_GPO15_LED		0xC8
+
+/* GP-ADC Threshold Registers */
+#define	DA906X_REG_ADC_CFG		0xC9
+#define	DA906X_REG_AUTO1_HIGH		0xCA
+#define	DA906X_REG_AUTO1_LOW		0xCB
+#define	DA906X_REG_AUTO2_HIGH		0xCC
+#define	DA906X_REG_AUTO2_LOW		0xCD
+#define	DA906X_REG_AUTO3_HIGH		0xCE
+#define	DA906X_REG_AUTO3_LOW		0xCF
+
+/* DA906x Configuration registers */
+/* OTP */
+#define	DA906X_REG_OPT_COUNT		0x101
+#define	DA906X_REG_OPT_ADDR		0x102
+#define	DA906X_REG_OPT_DATA		0x103
+
+/* Customer Trim and Configuration */
+#define	DA906X_REG_T_OFFSET		0x104
+#define	DA906X_REG_INTERFACE		0x105
+#define	DA906X_REG_CONFIG_A		0x106
+#define	DA906X_REG_CONFIG_B		0x107
+#define	DA906X_REG_CONFIG_C		0x108
+#define	DA906X_REG_CONFIG_D		0x109
+#define	DA906X_REG_CONFIG_E		0x10A
+#define	DA906X_REG_CONFIG_F		0x10B
+#define	DA906X_REG_CONFIG_G		0x10C
+#define	DA906X_REG_CONFIG_H		0x10D
+#define	DA906X_REG_CONFIG_I		0x10E
+#define	DA906X_REG_CONFIG_J		0x10F
+#define	DA906X_REG_CONFIG_K		0x110
+#define	DA906X_REG_CONFIG_L		0x111
+#define	DA906X_REG_MON_REG_1		0x112
+#define	DA906X_REG_MON_REG_2		0x113
+#define	DA906X_REG_MON_REG_3		0x114
+#define	DA906X_REG_MON_REG_4		0x115
+#define	DA906X_REG_MON_REG_5		0x116
+#define	DA906X_REG_MON_REG_6		0x117
+#define	DA906X_REG_TRIM_CLDR		0x118
+
+/* General Purpose Registers */
+#define	DA906X_REG_GP_ID_0		0x119
+#define	DA906X_REG_GP_ID_1		0x11A
+#define	DA906X_REG_GP_ID_2		0x11B
+#define	DA906X_REG_GP_ID_3		0x11C
+#define	DA906X_REG_GP_ID_4		0x11D
+#define	DA906X_REG_GP_ID_5		0x11E
+#define	DA906X_REG_GP_ID_6		0x11F
+#define	DA906X_REG_GP_ID_7		0x120
+#define	DA906X_REG_GP_ID_8		0x121
+#define	DA906X_REG_GP_ID_9		0x122
+#define	DA906X_REG_GP_ID_10		0x123
+#define	DA906X_REG_GP_ID_11		0x124
+#define	DA906X_REG_GP_ID_12		0x125
+#define	DA906X_REG_GP_ID_13		0x126
+#define	DA906X_REG_GP_ID_14		0x127
+#define	DA906X_REG_GP_ID_15		0x128
+#define	DA906X_REG_GP_ID_16		0x129
+#define	DA906X_REG_GP_ID_17		0x12A
+#define	DA906X_REG_GP_ID_18		0x12B
+#define	DA906X_REG_GP_ID_19		0x12C
+
+/* Chip ID and variant */
+#define	DA906X_REG_CHIP_ID		0x181
+#define	DA906X_REG_CHIP_VARIANT		0x182
+
+/*
+ * PMIC registers bits
+ */
+/* DA906X_REG_PAGE_CON (addr=0x00) */
+#define	DA906X_PEG_PAGE_SHIFT			0
+#define	DA906X_REG_PAGE_MASK			0x07
+#define		DA906X_REG_PAGE0		0x00
+#define		DA906X_REG_PAGE2		0x02
+#define	DA906X_PAGE_WRITE_MODE			0x00
+#define	DA906X_REPEAT_WRITE_MODE		0x40
+#define	DA906X_PAGE_REVERT			0x80
+
+/* DA906X_REG_STATUS_A (addr=0x01) */
+#define	DA906X_NONKEY				0x01
+#define	DA906X_WAKE				0x02
+#define	DA906X_DVC_BUSY				0x04
+#define	DA906X_COMP_1V2				0x08
+
+/* DA906X_REG_STATUS_B (addr=0x02) */
+#define	DA906X_GPI0				0x01
+#define	DA906X_GPI1				0x02
+#define	DA906X_GPI2				0x04
+#define	DA906X_GPI3				0x08
+#define	DA906X_GPI4				0x10
+#define	DA906X_GPI5				0x20
+#define	DA906X_GPI6				0x40
+#define	DA906X_GPI7				0x80
+
+/* DA906X_REG_STATUS_C (addr=0x03) */
+#define	DA906X_GPI8				0x01
+#define	DA906X_GPI9				0x02
+#define	DA906X_GPI10				0x04
+#define	DA906X_GPI11				0x08
+#define	DA906X_GPI12				0x10
+#define	DA906X_GPI13				0x20
+#define	DA906X_GPI14				0x40
+#define	DA906X_GPI15				0x80
+
+/* DA906X_REG_STATUS_D (addr=0x04) */
+#define	DA906X_LDO3_LIM				0x08
+#define	DA906X_LDO4_LIM				0x10
+#define	DA906X_LDO7_LIM				0x20
+#define	DA906X_LDO8_LIM				0x40
+#define	DA906X_LDO11_LIM			0x80
+
+/* DA906X_REG_FAULT_LOG (addr=0x05) */
+#define	DA906X_TWD_ERROR			0x01
+#define	DA906X_POR				0x02
+#define	DA906X_VDD_FAULT			0x04
+#define	DA906X_VDD_START			0x08
+#define	DA906X_TEMP_CRIT			0x10
+#define	DA906X_KEY_RESET			0x20
+#define	DA906X_NSHUTDOWN			0x40
+#define	DA906X_WAIT_SHUT			0x80
+
+/* DA906X_REG_EVENT_A (addr=0x06) */
+#define	DA906X_E_NONKEY				0x01
+#define	DA906X_E_ALARM				0x02
+#define	DA906X_E_TICK				0x04
+#define	DA906X_E_ADC_RDY			0x08
+#define	DA906X_E_SEQ_RDY			0x10
+#define	DA906X_EVENTS_B				0x20
+#define	DA906X_EVENTS_C				0x40
+#define	DA906X_EVENTS_D				0x80
+
+/* DA906X_REG_EVENT_B (addr=0x07) */
+#define	DA906X_E_WAKE				0x01
+#define	DA906X_E_TEMP				0x02
+#define	DA906X_E_COMP_1V2			0x04
+#define	DA906X_E_LDO_LIM			0x08
+#define	DA906X_E_REG_UVOV			0x10
+#define	DA906X_E_DVC_RDY			0x20
+#define	DA906X_E_VDD_MON			0x40
+#define	DA906X_E_VDD_WARN			0x80
+
+/* DA906X_REG_EVENT_C (addr=0x08) */
+#define	DA906X_E_GPI0				0x01
+#define	DA906X_E_GPI1				0x02
+#define	DA906X_E_GPI2				0x04
+#define	DA906X_E_GPI3				0x08
+#define	DA906X_E_GPI4				0x10
+#define	DA906X_E_GPI5				0x20
+#define	DA906X_E_GPI6				0x40
+#define	DA906X_E_GPI7				0x80
+
+/* DA906X_REG_EVENT_D (addr=0x09) */
+#define	DA906X_E_GPI8				0x01
+#define	DA906X_E_GPI9				0x02
+#define	DA906X_E_GPI10				0x04
+#define	DA906X_E_GPI11				0x08
+#define	DA906X_E_GPI12				0x10
+#define	DA906X_E_GPI13				0x20
+#define	DA906X_E_GPI14				0x40
+#define	DA906X_E_GPI15				0x80
+
+/* DA906X_REG_IRQ_MASK_A (addr=0x0A) */
+#define	DA906X_M_ONKEY				0x01
+#define	DA906X_M_ALARM				0x02
+#define	DA906X_M_TICK				0x04
+#define	DA906X_M_ADC_RDY			0x08
+#define	DA906X_M_SEQ_RDY			0x10
+
+/* DA906X_REG_IRQ_MASK_B (addr=0x0B) */
+#define	DA906X_M_WAKE				0x01
+#define	DA906X_M_TEMP				0x02
+#define	DA906X_M_COMP_1V2			0x04
+#define	DA906X_M_LDO_LIM			0x08
+#define	DA906X_M_UVOV				0x10
+#define	DA906X_M_DVC_RDY			0x20
+#define	DA906X_M_VDD_MON			0x40
+#define	DA906X_M_VDD_WARN			0x80
+
+/* DA906X_REG_IRQ_MASK_C (addr=0x0C) */
+#define	DA906X_M_GPI0				0x01
+#define	DA906X_M_GPI1				0x02
+#define	DA906X_M_GPI2				0x04
+#define	DA906X_M_GPI3				0x08
+#define	DA906X_M_GPI4				0x10
+#define	DA906X_M_GPI5				0x20
+#define	DA906X_M_GPI6				0x40
+#define	DA906X_M_GPI7				0x80
+
+/* DA906X_REG_IRQ_MASK_D (addr=0x0D) */
+#define	DA906X_M_GPI8				0x01
+#define	DA906X_M_GPI9				0x02
+#define	DA906X_M_GPI10				0x04
+#define	DA906X_M_GPI11				0x08
+#define	DA906X_M_GPI12				0x10
+#define	DA906X_M_GPI13				0x20
+#define	DA906X_M_GPI14				0x40
+#define	DA906X_M_GPI15				0x80
+
+/* DA906X_REG_CONTROL_A (addr=0x0E) */
+#define	DA906X_SYSTEM_EN			0x01
+#define	DA906X_POWER_EN				0x02
+#define	DA906X_POWER1_EN			0x04
+#define	DA906X_STANDBY				0x08
+#define	DA906X_M_SYSTEM_EN			0x10
+#define	DA906X_M_POWER_EN			0x20
+#define	DA906X_M_POWER1_EN			0x40
+#define	DA906X_CP_EN				0x80
+
+/* DA906X_REG_CONTROL_B (addr=0x0F) */
+#define	DA906X_CHG_SEL				0x01
+#define	DA906X_WATCHDOG_PD			0x02
+#define	DA906X_NRES_MODE			0x08
+#define	DA906X_NONKEY_LOCK			0x10
+
+/* DA906X_REG_CONTROL_C (addr=0x10) */
+#define	DA906X_DEBOUNCING_SHIFT			0
+#define	DA906X_DEBOUNCING_MASK			0x07
+#define		DA906X_DEBOUNCING_OFF		0x0
+#define		DA906X_DEBOUNCING_0MS1		0x1
+#define		DA906X_DEBOUNCING_1MS		0x2
+#define		DA906X_DEBOUNCING_10MS24	0x3
+#define		DA906X_DEBOUNCING_51MS2		0x4
+#define		DA906X_DEBOUNCING_256MS		0x5
+#define		DA906X_DEBOUNCING_512MS		0x6
+#define		DA906X_DEBOUNCING_1024MS	0x7
+
+#define	DA906X_AUTO_BOOT			0x08
+#define	DA906X_OTPREAD_EN			0x10
+#define	DA906X_SLEW_RATE_SHIFT			5
+#define	DA906X_SLEW_RATE_MASK			0x60
+#define		DA906X_SLEW_RATE_4US		0x00
+#define		DA906X_SLEW_RATE_3US		0x20
+#define		DA906X_SLEW_RATE_1US		0x40
+#define		DA906X_SLEW_RATE_0US5		0x60
+#define	DA906X_DEF_SUPPLY			0x80
+
+/* DA906X_REG_CONTROL_D (addr=0x11) */
+#define	DA906X_TWDSCALE_SHIFT			0
+#define	DA906X_TWDSCALE_MASK			0x07
+#define	DA906X_BLINK_FRQ_SHIFT			3
+#define	DA906X_BLINK_FRQ_MASK			0x38
+#define		DA906X_BLINK_FRQ_OFF		0x00
+#define		DA906X_BLINK_FRQ_1S0		0x08
+#define		DA906X_BLINK_FRQ_2S0		0x10
+#define		DA906X_BLINK_FRQ_4S0		0x18
+#define		DA906X_BLINK_FRQ_0S18		0x20
+#define		DA906X_BLINK_FRQ_2S0_VDD	0x28
+#define		DA906X_BLINK_FRQ_4S0_VDD	0x30
+#define		DA906X_BLINK_FRQ_0S18_VDD	0x38
+
+#define	DA906X_BLINK_DUR_SHIFT			6
+#define	DA906X_BLINK_DUR_MASK			0xC0
+#define		DA906X_BLINK_DUR_10MS		0x00
+#define		DA906X_BLINK_DUR_20MS		0x40
+#define		DA906X_BLINK_DUR_40MS		0x80
+#define		DA906X_BLINK_DUR_20MSDBL	0xC0
+
+/* DA906X_REG_CONTROL_E (addr=0x12) */
+#define	DA906X_RTC_MODE_PD			0x01
+#define	DA906X_RTC_MODE_SD			0x02
+#define	DA906X_RTC_EN				0x04
+#define	DA906X_ECO_MODE				0x08
+#define	DA906X_PM_FB1_PIN			0x10
+#define	DA906X_PM_FB2_PIN			0x20
+#define	DA906X_PM_FB3_PIN			0x40
+#define	DA906X_V_LOCK				0x80
+
+/* DA906X_REG_CONTROL_F (addr=0x13) */
+#define	DA906X_WATCHDOG				0x01
+#define	DA906X_SHUTDOWN				0x02
+#define	DA906X_WAKE_UP				0x04
+
+/* DA906X_REG_PD_DIS (addr=0x14) */
+#define	DA906X_GPI_DIS				0x01
+#define	DA906X_GPADC_PAUSE			0x02
+#define	DA906X_PMIF_DIS				0x04
+#define	DA906X_HS2WIRE_DIS			0x08
+#define	DA906X_BBAT_DIS				0x20
+#define	DA906X_OUT_32K_PAUSE			0x40
+#define	DA906X_PMCONT_DIS			0x80
+
+/* DA906X_REG_GPIO_0_1 (addr=0x15) */
+#define	DA906X_GPIO0_PIN_SHIFT			0
+#define	DA906X_GPIO0_PIN_MASK			0x03
+#define		DA906X_GPIO0_PIN_ADCIN1		0x00
+#define		DA906X_GPIO0_PIN_GPI		0x01
+#define		DA906X_GPIO0_PIN_GPO_OD		0x02
+#define		DA906X_GPIO0_PIN_GPO		0x03
+#define	DA906X_GPIO0_TYPE			0x04
+#define		DA906X_GPIO0_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO0_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO0_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO0_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO0_NO_WAKEUP			0x08
+#define	DA906X_GPIO1_PIN_SHIFT			4
+#define	DA906X_GPIO1_PIN_MASK			0x30
+#define		DA906X_GPIO1_PIN_ADCIN2_COMP	0x00
+#define		DA906X_GPIO1_PIN_GPI		0x10
+#define		DA906X_GPIO1_PIN_GPO_OD		0x20
+#define		DA906X_GPIO1_PIN_GPO		0x30
+#define	DA906X_GPIO1_TYPE			0x40
+#define		DA906X_GPIO1_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO1_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO1_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO1_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO1_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_2_3 (addr=0x16) */
+#define	DA906X_GPIO2_PIN_SHIFT			0
+#define	DA906X_GPIO2_PIN_MASK			0x03
+#define		DA906X_GPIO2_PIN_ADCIN3		0x00
+#define		DA906X_GPIO2_PIN_GPI		0x01
+#define		DA906X_GPIO2_PIN_GPO_PSS	0x02
+#define		DA906X_GPIO2_PIN_GPO		0x03
+#define	DA906X_GPIO2_TYPE			0x04
+#define		DA906X_GPIO2_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO2_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO2_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO2_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO2_NO_WAKEUP			0x08
+#define	DA906X_GPIO3_PIN_SHIFT			4
+#define	DA906X_GPIO3_PIN_MASK			0x30
+#define		DA906X_GPIO3_PIN_CORE_SW_G	0x00
+#define		DA906X_GPIO3_PIN_GPI		0x10
+#define		DA906X_GPIO3_PIN_GPO_OD		0x20
+#define		DA906X_GPIO3_PIN_GPO		0x30
+#define	DA906X_GPIO3_TYPE			0x40
+#define		DA906X_GPIO3_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO3_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO3_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO3_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO3_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_4_5 (addr=0x17) */
+#define	DA906X_GPIO4_PIN_SHIFT			0
+#define	DA906X_GPIO4_PIN_MASK			0x03
+#define		DA906X_GPIO4_PIN_CORE_SW_S	0x00
+#define		DA906X_GPIO4_PIN_GPI		0x01
+#define		DA906X_GPIO4_PIN_GPO_OD		0x02
+#define		DA906X_GPIO4_PIN_GPO		0x03
+#define	DA906X_GPIO4_TYPE			0x04
+#define		DA906X_GPIO4_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO4_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO4_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO4_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO4_NO_WAKEUP			0x08
+#define	DA906X_GPIO5_PIN_SHIFT			4
+#define	DA906X_GPIO5_PIN_MASK			0x30
+#define		DA906X_GPIO5_PIN_PERI_SW_G	0x00
+#define		DA906X_GPIO5_PIN_GPI		0x10
+#define		DA906X_GPIO5_PIN_GPO_OD		0x20
+#define		DA906X_GPIO5_PIN_GPO		0x30
+#define	DA906X_GPIO5_TYPE			0x40
+#define		DA906X_GPIO5_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO5_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO5_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO5_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO5_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_6_7 (addr=0x18) */
+#define	DA906X_GPIO6_PIN_SHIFT			0
+#define	DA906X_GPIO6_PIN_MASK			0x03
+#define		DA906X_GPIO6_PIN_PERI_SW_S	0x00
+#define		DA906X_GPIO6_PIN_GPI		0x01
+#define		DA906X_GPIO6_PIN_GPO_OD		0x02
+#define		DA906X_GPIO6_PIN_GPO		0x03
+#define	DA906X_GPIO6_TYPE			0x04
+#define		DA906X_GPIO6_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO6_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO6_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO6_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO6_NO_WAKEUP			0x08
+#define	DA906X_GPIO7_PIN_SHIFT			4
+#define	DA906X_GPIO7_PIN_MASK			0x30
+#define		DA906X_GPIO7_PIN_GPI		0x10
+#define		DA906X_GPIO7_PIN_GPO_PSS	0x20
+#define		DA906X_GPIO7_PIN_GPO		0x30
+#define	DA906X_GPIO7_TYPE			0x40
+#define		DA906X_GPIO7_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO7_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO7_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO7_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO7_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_8_9 (addr=0x19) */
+#define	DA906X_GPIO8_PIN_SHIFT			0
+#define	DA906X_GPIO8_PIN_MASK			0x03
+#define		DA906X_GPIO8_PIN_GPI_SYS_EN	0x00
+#define		DA906X_GPIO8_PIN_GPI		0x01
+#define		DA906X_GPIO8_PIN_GPO_PSS	0x02
+#define		DA906X_GPIO8_PIN_GPO		0x03
+#define	DA906X_GPIO8_TYPE			0x04
+#define		DA906X_GPIO8_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO8_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO8_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO8_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO8_NO_WAKEUP			0x08
+#define	DA906X_GPIO9_PIN_SHIFT			4
+#define	DA906X_GPIO9_PIN_MASK			0x30
+#define		DA906X_GPIO9_PIN_GPI_PWR_EN	0x00
+#define		DA906X_GPIO9_PIN_GPI		0x10
+#define		DA906X_GPIO9_PIN_GPO_PSS	0x20
+#define		DA906X_GPIO9_PIN_GPO		0x30
+#define	DA906X_GPIO9_TYPE			0x40
+#define		DA906X_GPIO9_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO9_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO9_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO9_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO9_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_10_11 (addr=0x1A) */
+#define	DA906X_GPIO10_PIN_SHIFT			0
+#define	DA906X_GPIO10_PIN_MASK			0x03
+#define		DA906X_GPIO10_PIN_GPI_PWR1_EN	0x00
+#define		DA906X_GPIO10_PIN_GPI		0x01
+#define		DA906X_GPIO10_PIN_GPO_OD	0x02
+#define		DA906X_GPIO10_PIN_GPO		0x03
+#define	DA906X_GPIO10_TYPE			0x04
+#define		DA906X_GPIO10_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO10_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO10_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO10_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO10_NO_WAKEUP			0x08
+#define	DA906X_GPIO11_PIN_SHIFT			4
+#define	DA906X_GPIO11_PIN_MASK			0x30
+#define		DA906X_GPIO11_PIN_GPO_OD	0x00
+#define		DA906X_GPIO11_PIN_GPI		0x10
+#define		DA906X_GPIO11_PIN_GPO_PSS	0x20
+#define		DA906X_GPIO11_PIN_GPO		0x30
+#define	DA906X_GPIO11_TYPE			0x40
+#define		DA906X_GPIO11_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO11_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO11_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO11_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO11_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_12_13 (addr=0x1B) */
+#define	DA906X_GPIO12_PIN_SHIFT			0
+#define	DA906X_GPIO12_PIN_MASK			0x03
+#define		DA906X_GPIO12_PIN_NVDDFLT_OUT	0x00
+#define		DA906X_GPIO12_PIN_GPI		0x01
+#define		DA906X_GPIO12_PIN_VSYSMON_OUT	0x02
+#define		DA906X_GPIO12_PIN_GPO		0x03
+#define	DA906X_GPIO12_TYPE			0x04
+#define		DA906X_GPIO12_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO12_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO12_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO12_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO12_NO_WAKEUP			0x08
+#define	DA906X_GPIO13_PIN_SHIFT			4
+#define	DA906X_GPIO13_PIN_MASK			0x30
+#define		DA906X_GPIO13_PIN_GPFB1_OUT	0x00
+#define		DA906X_GPIO13_PIN_GPI		0x10
+#define		DA906X_GPIO13_PIN_GPFB1_OUTOD	0x20
+#define		DA906X_GPIO13_PIN_GPO		0x30
+#define	DA906X_GPIO13_TYPE			0x40
+#define		DA906X_GPIO13_TYPE_GPFB1_OUT	0x00
+#define		DA906X_GPIO13_TYPE_GPI		0x00
+#define		DA906X_GPIO13_TYPE_GPFB1_OUTOD	0x04
+#define		DA906X_GPIO13_TYPE_GPO		0x04
+#define	DA906X_GPIO13_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_14_15 (addr=0x1C) */
+#define	DA906X_GPIO14_PIN_SHIFT			0
+#define	DA906X_GPIO14_PIN_MASK			0x03
+#define		DA906X_GPIO14_PIN_GPO_OD	0x00
+#define		DA906X_GPIO14_PIN_GPI		0x01
+#define		DA906X_GPIO14_PIN_HS2DATA	0x02
+#define		DA906X_GPIO14_PIN_GPO		0x03
+#define	DA906X_GPIO14_TYPE			0x04
+#define		DA906X_GPIO14_TYPE_GPI_ACT_LOW	0x00
+#define		DA906X_GPIO14_TYPE_GPO_VDD_IO1	0x00
+#define		DA906X_GPIO14_TYPE_GPI_ACT_HIGH	0x04
+#define		DA906X_GPIO14_TYPE_GPO_VDD_IO2	0x04
+#define	DA906X_GPIO14_NO_WAKEUP			0x08
+#define	DA906X_GPIO15_PIN_SHIFT			4
+#define	DA906X_GPIO15_PIN_MASK			0x30
+#define		DA906X_GPIO15_PIN_GPO_OD	0x00
+#define		DA906X_GPIO15_PIN_GPI		0x10
+#define		DA906X_GPIO15_PIN_GPO		0x30
+#define	DA906X_GPIO15_TYPE			0x40
+#define		DA906X_GPIO15_TYPE_GPFB1_OUT	0x00
+#define		DA906X_GPIO15_TYPE_GPI		0x00
+#define		DA906X_GPIO15_TYPE_GPFB1_OUTOD	0x04
+#define		DA906X_GPIO15_TYPE_GPO		0x04
+#define	DA906X_GPIO15_NO_WAKEUP			0x80
+
+/* DA906X_REG_GPIO_MODE_0_7 (addr=0x1D) */
+#define	DA906X_GPIO0_MODE			0x01
+#define	DA906X_GPIO1_MODE			0x02
+#define	DA906X_GPIO2_MODE			0x04
+#define	DA906X_GPIO3_MODE			0x08
+#define	DA906X_GPIO4_MODE			0x10
+#define	DA906X_GPIO5_MODE			0x20
+#define	DA906X_GPIO6_MODE			0x40
+#define	DA906X_GPIO7_MODE			0x80
+
+/* DA906X_REG_GPIO_MODE_8_15 (addr=0x1E) */
+#define	DA906X_GPIO8_MODE			0x01
+#define	DA906X_GPIO9_MODE			0x02
+#define	DA906X_GPIO10_MODE			0x04
+#define	DA906X_GPIO11_MODE			0x08
+#define		DA906X_GPIO11_MODE_LED_ACT_HIGH	0x00
+#define		DA906X_GPIO11_MODE_LED_ACT_LOW	0x08
+#define	DA906X_GPIO12_MODE			0x10
+#define	DA906X_GPIO13_MODE			0x20
+#define	DA906X_GPIO14_MODE			0x40
+#define		DA906X_GPIO14_MODE_LED_ACT_HIGH	0x00
+#define		DA906X_GPIO14_MODE_LED_ACT_LOW	0x40
+#define	DA906X_GPIO15_MODE			0x80
+#define		DA906X_GPIO15_MODE_LED_ACT_HIGH	0x00
+#define		DA906X_GPIO15_MODE_LED_ACT_LOW	0x80
+
+/* DA906X_REG_SWITCH_CONT (addr=0x1F) */
+#define	DA906X_CORE_SW_GPI_SHIFT		0
+#define	DA906X_CORE_SW_GPI_MASK			0x03
+#define		DA906X_CORE_SW_GPI_OFF		0x00
+#define		DA906X_CORE_SW_GPI_GPIO1	0x01
+#define		DA906X_CORE_SW_GPI_GPIO2	0x02
+#define		DA906X_CORE_SW_GPI_GPIO13	0x03
+#define	DA906X_PERI_SW_GPI_SHIFT		2
+#define	DA906X_PERI_SW_GPI_MASK			0x0C
+#define		DA906X_PERI_SW_GPI_OFF		0x00
+#define		DA906X_PERI_SW_GPI_GPIO1	0x04
+#define		DA906X_PERI_SW_GPI_GPIO2	0x08
+#define		DA906X_PERI_SW_GPI_GPIO13	0x0C
+#define	DA906X_SWITCH_SR_SHIFT			4
+#define	DA906X_SWITCH_SR_MASK			0x30
+#define		DA906X_SWITCH_SR_1MV		0x00
+#define		DA906X_SWITCH_SR_5MV		0x10
+#define		DA906X_SWITCH_SR_10MV		0x20
+#define		DA906X_SWITCH_SR_50MV		0x30
+#define	DA906X_SWITCH_SR_DIS			0x40
+#define	DA906X_CP_EN_MODE			0x80
+
+/* DA906X_REGL_Bxxxx_CONT common bits (addr=0x20-0x25) */
+#define	DA906X_BUCK_EN				0x01
+#define	DA906X_BUCK_GPI_SHIFT			1
+#define DA906X_BUCK_GPI_MASK			0x06
+#define		DA906X_BUCK_GPI_OFF		0x00
+#define		DA906X_BUCK_GPI_GPIO1		0x02
+#define		DA906X_BUCK_GPI_GPIO2		0x04
+#define		DA906X_BUCK_GPI_GPIO13		0x06
+#define	DA906X_BUCK_CONF			0x08
+#define	DA906X_VBUCK_GPI_SHIFT			5
+#define	DA906X_VBUCK_GPI_MASK			0x60
+#define		DA906X_VBUCK_GPI_OFF		0x00
+#define		DA906X_VBUCK_GPI_GPIO1		0x20
+#define		DA906X_VBUCK_GPI_GPIO2		0x40
+#define		DA906X_VBUCK_GPI_GPIO13		0x60
+
+/* DA906X_REG_BCORE1_CONT specific bits (addr=0x21) */
+#define	DA906X_CORE_SW_EN			0x10
+#define	DA906X_CORE_SW_CONF			0x80
+
+/* DA906X_REG_BPERI_CONT specific bits (addr=0x25) */
+#define	DA906X_PERI_SW_EN			0x10
+#define	DA906X_PERI_SW_CONF			0x80
+
+/* DA906X_REG_LDOx_CONT common bits (addr=0x26-0x30) */
+#define	DA906X_LDO_EN				0x01
+#define	DA906X_LDO_GPI_SHIFT			1
+#define DA906X_LDO_GPI_MASK			0x06
+#define		DA906X_LDO_GPI_OFF		0x00
+#define		DA906X_LDO_GPI_GPIO1		0x02
+#define		DA906X_LDO_GPI_GPIO2		0x04
+#define		DA906X_LDO_GPI_GPIO13		0x06
+#define	DA906X_LDO_PD_DIS			0x08
+#define	DA906X_VLDO_GPI_SHIFT			5
+#define	DA906X_VLDO_GPI_MASK			0x60
+#define		DA906X_VLDO_GPI_OFF		0x00
+#define		DA906X_VLDO_GPI_GPIO1		0x20
+#define		DA906X_VLDO_GPI_GPIO2		0x40
+#define		DA906X_VLDO_GPI_GPIO13		0x60
+#define	DA906X_LDO_CONF				0x80
+
+/* DA906X_REG_LDO5_CONT specific bits (addr=0x2A) */
+#define	DA906X_VLDO5_SEL			0x10
+
+/* DA906X_REG_LDO6_CONT specific bits (addr=0x2B) */
+#define	DA906X_VLDO6_SEL			0x10
+
+/* DA906X_REG_LDO7_CONT specific bits (addr=0x2C) */
+#define	DA906X_VLDO7_SEL			0x10
+
+/* DA906X_REG_LDO8_CONT specific bits (addr=0x2D) */
+#define	DA906X_VLDO8_SEL			0x10
+
+/* DA906X_REG_LDO9_CONT specific bits (addr=0x2E) */
+#define	DA906X_VLDO9_SEL			0x10
+
+/* DA906X_REG_LDO10_CONT specific bits (addr=0x2F) */
+#define	DA906X_VLDO10_SEL			0x10
+
+/* DA906X_REG_LDO11_CONT specific bits (addr=0x30) */
+#define	DA906X_VLDO11_SEL			0x10
+
+/* DA906X_REG_VIB (addr=0x31) */
+#define DA906X_VIB_SET_MASK			0x3F
+#define		DA906X_VIB_SET_OFF		0
+#define		DA906X_VIB_SET_MAX		0x3F
+
+/* DA906X_REG_DVC_1 (addr=0x32) */
+#define	DA906X_VBCORE1_SEL			0x01
+#define	DA906X_VBCORE2_SEL			0x02
+#define	DA906X_VBPRO_SEL			0x04
+#define	DA906X_VBMEM_SEL			0x08
+#define	DA906X_VBPERI_SEL			0x10
+#define	DA906X_VLDO1_SEL			0x20
+#define	DA906X_VLDO2_SEL			0x40
+#define	DA906X_VLDO3_SEL			0x80
+
+/* DA906X_REG_DVC_2 (addr=0x33) */
+#define	DA906X_VBIO_SEL				0x01
+#define	DA906X_VLDO4_SEL			0x80
+
+/* DA906X_REG_ADC_MAN (addr=0x34) */
+#define	DA906X_ADC_MUX_SHIFT			0
+#define	DA906X_ADC_MUX_MASK			0x0F
+#define		DA906X_ADC_MUX_VSYS		0x00
+#define		DA906X_ADC_MUX_ADCIN1		0x01
+#define		DA906X_ADC_MUX_ADCIN2		0x02
+#define		DA906X_ADC_MUX_ADCIN3		0x03
+#define		DA906X_ADC_MUX_T_SENSE		0x04
+#define		DA906X_ADC_MUX_VBBAT		0x05
+#define		DA906X_ADC_MUX_LDO_G1		0x08
+#define		DA906X_ADC_MUX_LDO_G2		0x09
+#define		DA906X_ADC_MUX_LDO_G3		0x0A
+#define	DA906X_ADC_MAN				0x10
+#define	DA906X_ADC_MODE				0x20
+
+/* DA906X_REG_ADC_CONT (addr=0x35) */
+#define	DA906X_ADC_AUTO_VSYS_EN			0x01
+#define	DA906X_ADC_AUTO_AD1_EN			0x02
+#define	DA906X_ADC_AUTO_AD2_EN			0x04
+#define	DA906X_ADC_AUTO_AD3_EN			0x08
+#define	DA906X_ADC_AD1_ISRC_EN			0x10
+#define	DA906X_ADC_AD2_ISRC_EN			0x20
+#define	DA906X_ADC_AD3_ISRC_EN			0x40
+#define	DA906X_COMP1V2_EN			0x80
+
+/* DA906X_REG_VSYS_MON (addr=0x36) */
+#define	DA906X_VSYS_VAL_SHIFT			0
+#define	DA906X_VSYS_VAL_MASK			0xFF
+#define	DA906X_VSYS_VAL_BASE			0x00
+
+/* DA906X_REG_ADC_RES_L (addr=0x37) */
+#define	DA906X_ADC_RES_L_SHIFT			6
+#define	DA906X_ADC_RES_L_BITS			2
+#define	DA906X_ADC_RES_L_MASK			0xC0
+
+/* DA906X_REG_ADC_RES_H (addr=0x38) */
+#define	DA906X_ADC_RES_M_SHIFT			0
+#define	DA906X_ADC_RES_M_BITS			8
+#define	DA906X_ADC_RES_M_MASK			0xFF
+
+/* DA906X_REG_(xxx_RES/ADC_RES_H) (addr=0x39-0x3F) */
+#define	DA906X_ADC_VAL_SHIFT			0
+#define	DA906X_ADC_VAL_MASK			0xFF
+
+/* DA906X_REG_COUNT_S (addr=0x40) */
+#define DA906X_RTC_READ				0x80
+#define DA906X_COUNT_SEC_MASK			0x3F
+
+/* DA906X_REG_COUNT_MI (addr=0x41) */
+#define DA906X_COUNT_MIN_MASK			0x3F
+
+/* DA906X_REG_COUNT_H (addr=0x42) */
+#define DA906X_COUNT_HOUR_MASK			0x1F
+
+/* DA906X_REG_COUNT_D (addr=0x43) */
+#define DA906X_COUNT_DAY_MASK			0x1F
+
+/* DA906X_REG_COUNT_MO (addr=0x44) */
+#define DA906X_COUNT_MONTH_MASK			0x0F
+
+/* DA906X_REG_COUNT_Y (addr=0x45) */
+#define DA906X_COUNT_YEAR_MASK			0x3F
+#define DA906X_MONITOR				0x40
+
+/* DA906X_REG_ALARM_MI (addr=0x46) */
+#define DA906X_ALARM_STATUS_ALARM		0x80
+#define DA906X_ALARM_STATUS_TICK		0x40
+#define DA906X_ALARM_MIN_MASK			0x3F
+
+/* DA906X_REG_ALARM_H (addr=0x47) */
+#define DA906X_ALARM_HOUR_MASK			0x1F
+
+/* DA906X_REG_ALARM_D (addr=0x48) */
+#define DA906X_ALARM_DAY_MASK			0x1F
+
+/* DA906X_REG_ALARM_MO (addr=0x49) */
+#define DA906X_TICK_WAKE			0x20
+#define DA906X_TICK_TYPE			0x10
+#define		DA906X_TICK_TYPE_SEC		0x00
+#define		DA906X_TICK_TYPE_MIN		0x10
+#define DA906X_ALARM_MONTH_MASK			0x0F
+
+/* DA906X_REG_ALARM_Y (addr=0x4A) */
+#define DA906X_TICK_ON				0x80
+#define DA906X_ALARM_ON				0x40
+#define DA906X_ALARM_YEAR_MASK			0x3F
+
+/* DA906X_REG_WAIT (addr=0x97)*/
+#define	DA906X_REG_WAIT_TIME_SHIFT		0
+#define	DA906X_REG_WAIT_TIME_MASK		0xF
+#define	DA906X_WAIT_TIME_0_US			0x0
+#define	DA906X_WAIT_TIME_512_US			0x1
+#define	DA906X_WAIT_TIME_1_MS			0x2
+#define	DA906X_WAIT_TIME_2_MS			0x3
+#define	DA906X_WAIT_TIME_4_1_MS			0x4
+#define	DA906X_WAIT_TIME_8_2_MS			0x5
+#define	DA906X_WAIT_TIME_16_4_MS		0x6
+#define	DA906X_WAIT_TIME_32_8_MS		0x7
+#define	DA906X_WAIT_TIME_65_5_MS		0x8
+#define	DA906X_WAIT_TIME_128_MS			0x9
+#define	DA906X_WAIT_TIME_256_MS			0xA
+#define	DA906X_WAIT_TIME_512_MS			0xB
+#define	DA906X_WAIT_TIME_1_S			0xC
+#define	DA906X_WAIT_TIME_2_1_S			0xD
+
+/* DA906X_REG_EN_32K  (addr=0x98)*/
+#define	DA906X_STABILIZ_TIME_SHIFT		0
+#define	DA906X_STABILIZ_TIME_MASK		0x7
+#define	DA906X_CRYSTAL				0x08
+#define	DA906X_DELAY_MODE			0x10
+#define	DA906X_OUT_CLOCK			0x20
+#define	DA906X_RTC_CLOCK			0x40
+#define	DA906X_OUT_32K_EN			0x80
+
+/* DA906X_REG_CHIP_VARIANT */
+#define	DA906X_CHIP_VARIANT_SHIFT		4
+
+/* DA906X_REG_BUCK_ILIM_A (addr=0x9A) */
+#define DA906X_BIO_ILIM_SHIFT			0
+#define DA906X_BIO_ILIM_MASK			0x0F
+#define DA906X_BMEM_ILIM_SHIFT			4
+#define DA906X_BMEM_ILIM_MASK			0x0F
+
+/* DA906X_REG_BUCK_ILIM_B (addr=0x9B) */
+#define DA906X_BPRO_ILIM_SHIFT			0
+#define DA906X_BPRO_ILIM_MASK			0x0F
+#define DA906X_BPERI_ILIM_SHIFT			4
+#define DA906X_BPERI_ILIM_MASK			0x0F
+
+/* DA906X_REG_BUCK_ILIM_C (addr=0x9C) */
+#define DA906X_BCORE1_ILIM_SHIFT		0
+#define DA906X_BCORE1_ILIM_MASK			0x0F
+#define DA906X_BCORE2_ILIM_SHIFT		4
+#define DA906X_BCORE2_ILIM_MASK			0x0F
+
+/* DA906X_REG_Bxxxx_CFG common bits (addr=0x9D-0xA2) */
+#define DA906X_BUCK_FB_MASK			0x07
+#define DA906X_BUCK_PD_DIS_SHIFT		5
+#define DA906X_BUCK_MODE_SHIFT			6
+#define DA906X_BUCK_MODE_MASK			0xC0
+#define		DA906X_BUCK_MODE_MANUAL		0x00
+#define		DA906X_BUCK_MODE_SLEEP		0x40
+#define		DA906X_BUCK_MODE_SYNC		0x80
+#define		DA906X_BUCK_MODE_AUTO		0xC0
+
+/* DA906X_REG_BPRO_CFG (addr=0x9F) */
+#define	DA906X_BPRO_VTTR_EN			0x08
+#define	DA906X_BPRO_VTT_EN			0x10
+
+/* DA906X_REG_VBxxxx_A/B (addr=0xA3-0xA8, 0xB4-0xB9) */
+#define DA906X_VBUCK_SHIFT			0
+#define DA906X_VBUCK_MASK			0x7F
+#define DA906X_VBUCK_BIAS			0
+#define DA906X_BUCK_SL				0x80
+
+/* DA906X_REG_VLDOx_A/B (addr=0xA9-0x3, 0xBA-0xC4) */
+#define DA906X_LDO_SL				0x80
+
+/* DA906X_REG_VLDO1_A/B (addr=0xA9, 0xBA) */
+#define DA906X_VLDO1_MASK			0x3F
+#define DA906X_VLDO1_SHIFT			0
+#define DA906X_VLDO1_BIAS			0
+
+/* DA906X_REG_VLDO2_A/B (addr=0xAA, 0xBB) */
+#define DA906X_VLDO2_MASK			0x3F
+#define DA906X_VLDO2_SHIFT			0
+#define DA906X_VLDO2_BIAS			0
+
+/* DA906X_REG_VLDO3_A/B (addr=0xAB, 0xBC) */
+#define DA906X_VLDO3_MASK			0x7F
+#define DA906X_VLDO3_SHIFT			0
+#define DA906X_VLDO3_BIAS			0
+
+/* DA906X_REG_VLDO4_A/B (addr=0xAC, 0xBD) */
+#define DA906X_VLDO4_MASK			0x7F
+#define DA906X_VLDO4_SHIFT			0
+#define DA906X_VLDO4_BIAS			0
+
+/* DA906X_REG_VLDO5_A/B (addr=0xAD, 0xBE) */
+#define DA906X_VLDO5_MASK			0x3F
+#define DA906X_VLDO5_SHIFT			0
+#define DA906X_VLDO5_BIAS			2
+
+/* DA906X_REG_VLDO6_A/B (addr=0xAE, 0xBF) */
+#define DA906X_VLDO6_MASK			0x3F
+#define DA906X_VLDO6_SHIFT			0
+#define DA906X_VLDO6_BIAS			2
+
+/* DA906X_REG_VLDO7_A/B (addr=0xAF, 0xC0) */
+#define DA906X_VLDO7_MASK			0x3F
+#define DA906X_VLDO7_SHIFT			0
+#define DA906X_VLDO7_BIAS			2
+
+/* DA906X_REG_VLDO8_A/B (addr=0xB0, 0xC1) */
+#define DA906X_VLDO8_MASK			0x3F
+#define DA906X_VLDO8_SHIFT			0
+#define DA906X_VLDO8_BIAS			2
+
+/* DA906X_REG_VLDO9_A/B (addr=0xB1, 0xC2) */
+#define DA906X_VLDO9_MASK			0x3F
+#define DA906X_VLDO9_SHIFT			0
+#define DA906X_VLDO9_BIAS			3
+
+/* DA906X_REG_VLDO10_A/B (addr=0xB2, 0xC3) */
+#define DA906X_VLDO10_MASK			0x3F
+#define DA906X_VLDO10_SHIFT			0
+#define DA906X_VLDO10_BIAS			2
+
+/* DA906X_REG_VLDO11_A/B (addr=0xB3, 0xC4) */
+#define DA906X_VLDO11_MASK			0x3F
+#define DA906X_VLDO11_SHIFT			0
+#define DA906X_VLDO11_BIAS			2
+
+/* DA906X_REG_GPO11_LED (addr=0xC6) */
+/* DA906X_REG_GPO14_LED (addr=0xC7) */
+/* DA906X_REG_GPO15_LED (addr=0xC8) */
+#define DA906X_GPIO_DIM				0x80
+#define DA906X_GPIO_PWM_SHIFT			0
+#define DA906X_GPIO_PWM_MASK			0x7F
+
+/* DA906X_REG_CONFIG_H (addr=0x10D) */
+#define DA906X_PWM_CLK_MASK			0x01
+#define		DA906X_PWM_CLK_PWM2MHZ		0x00
+#define		DA906X_PWM_CLK_PWM1MHZ		0x01
+#define DA906X_LDO8_MODE_MASK			0x02
+#define		DA906X_LDO8_MODE_LDO		0
+#define		DA906X_LDO8_MODE_VIBR		0x02
+#define DA906X_MERGE_SENSE_MASK			0x04
+#define 	DA906X_MERGE_SENSE_GP_FB2	0x00
+#define 	DA906X_MERGE_SENSE_GPIO4	0x04
+#define DA906X_BCORE_MERGE			0x08
+#define DA906X_BPRO_OD				0x10
+#define DA906X_BCORE2_OD			0x20
+#define DA906X_BCORE1_OD			0x40
+#define DA906X_BUCK_MERGE			0x80
+
+/* DA906X_REG_CONFIG_I (addr=0x10E) */
+#define DA906X_NONKEY_PIN_MASK			0x03
+#define		DA906X_NONKEY_PIN_PORT		0x00
+#define		DA906X_NONKEY_PIN_SWDOWN	0x01
+#define		DA906X_NONKEY_PIN_AUTODOWN	0x02
+#define		DA906X_NONKEY_PIN_AUTOFLPRT	0x03
+
+/* DA906X_REG_MON_REG_5 (addr=0x116) */
+#define DA906X_MON_A8_IDX_SHIFT			0
+#define DA906X_MON_A8_IDX_MASK			0x07
+#define		DA9063_MON_A8_IDX_NONE		0x00
+#define		DA9063_MON_A8_IDX_BCORE1	0x01
+#define		DA9063_MON_A8_IDX_BCORE2	0x02
+#define		DA9063_MON_A8_IDX_BPRO		0x03
+#define		DA9063_MON_A8_IDX_LDO3		0x04
+#define		DA9063_MON_A8_IDX_LDO4		0x05
+#define		DA9063_MON_A8_IDX_LDO11		0x06
+#define DA906X_MON_A9_IDX_SHIFT			4
+#define DA906X_MON_A9_IDX_MASK			0x70
+#define		DA9063_MON_A9_IDX_NONE		0x00
+#define		DA9063_MON_A9_IDX_BIO		0x01
+#define		DA9063_MON_A9_IDX_BMEM		0x02
+#define		DA9063_MON_A9_IDX_BPERI		0x03
+#define		DA9063_MON_A9_IDX_LDO1		0x04
+#define		DA9063_MON_A9_IDX_LDO2		0x05
+#define		DA9063_MON_A9_IDX_LDO5		0x06
+
+/* DA906X_REG_MON_REG_6 (addr=0x117) */
+#define DA906X_MON_A10_IDX_SHIFT		0
+#define DA906X_MON_A10_IDX_MASK			0x07
+#define		DA9063_MON_A10_IDX_NONE		0x00
+#define		DA9063_MON_A10_IDX_LDO6		0x01
+#define		DA9063_MON_A10_IDX_LDO7		0x02
+#define		DA9063_MON_A10_IDX_LDO8		0x03
+#define		DA9063_MON_A10_IDX_LDO9		0x04
+#define		DA9063_MON_A10_IDX_LDO10	0x05
+
+#endif /* _DA906X_REG_H */
+
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
  2012-08-24 13:50   ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-24 13:55     ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 13:55 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

The driver adds support for the following DA9063 PMIC regulators:
 - 11x LDOs (named LDO1 - LDO11),
 - 6x buck converters (BCORE1, BCORE2, BPRO, BMEM, BIO, BPERI),
 - 1x power switch to switch on/off 32 KHz oscilator output (32K_OUT).

Regulators provide following operations:
 - REGULATOR_CHANGE_STATUS for all regulators,
 - REGULATOR_CHANGE_VOLTAGE for LDOs and buck converters,
 - REGULATOR_CHANGE_MODE for LDOs and buck converters, where:
     - LDOs allow REGULATOR_MODE_NORMAL and REGULATOR_MODE_STANDBY,
     - buck converters allow REGULATOR_MODE_FAST, REGULATOR_MODE_NORMAL
       and REGULATOR_MODE_STANDBY,
 - REGULATOR_CHANGE_CURRENT for buck converters (current limits).

The driver generates REGULATOR_EVENT_OVER_CURRENT for LDO3, LDO4, LDO7, LDO8
and LDO11.

Internally, PMIC provides two voltage configurations for normal and suspend
system state for each regulator. The driver switches between those on
suspend/wake-up to provide quick and fluent output voltage change.

This driver requires MFD core driver for operation.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/regulator/Kconfig            |    6 +
 drivers/regulator/Makefile           |    1 +
 drivers/regulator/da906x-regulator.c | 1018 ++++++++++++++++++++++++++++++++++
 3 files changed, 1025 insertions(+), 0 deletions(-)
 create mode 100644 drivers/regulator/da906x-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 4e932cc..b57b6c6 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -110,6 +110,12 @@ config REGULATOR_DA9052
 	  This driver supports the voltage regulators of DA9052-BC and
 	  DA9053-AA/Bx PMIC.
 
+config REGULATOR_DA906X
+	bool "Dialog DA906X Regulator family chip"
+	depends on MFD_DA906X
+	help
+	  Support for Dialog Semiconductor DA906x chip.
+
 config REGULATOR_ANATOP
 	tristate "Freescale i.MX on-chip ANATOP LDO regulators"
 	depends on MFD_ANATOP
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 3342615..46a503a 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o
 obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o
 obj-$(CONFIG_REGULATOR_DA903X)	+= da903x.o
 obj-$(CONFIG_REGULATOR_DA9052)	+= da9052-regulator.o
+obj-$(CONFIG_REGULATOR_DA906X) += da906x-regulator.o
 obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o
 obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o
 obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o
diff --git a/drivers/regulator/da906x-regulator.c b/drivers/regulator/da906x-regulator.c
new file mode 100644
index 0000000..1b68de0
--- /dev/null
+++ b/drivers/regulator/da906x-regulator.c
@@ -0,0 +1,1018 @@
+/*
+ * Regulator driver for DA906x PMIC series
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/init.h>
+#include <linux/err.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+#include <linux/mfd/da906x/registers.h>
+
+
+/* Definition for registering bit fields */
+struct bfield {
+	unsigned short	addr;
+	unsigned char	mask;
+};
+#define BFIELD(_addr, _mask) \
+	{ .addr = _addr, .mask = _mask }
+
+struct field {
+	unsigned short	addr;
+	unsigned char	mask;
+	unsigned char	shift;
+	unsigned char	offset;
+};
+#define FIELD(_addr, _mask, _shift, _offset) \
+	{ .addr = _addr, .mask = _mask, .shift = _shift, .offset = _offset }
+
+/* Regulator capabilities and registers description */
+struct da906x_regulator_info {
+	int			id;
+	char			*name;
+	struct regulator_ops	*ops;
+
+	/* Voltage adjust range */
+	int		min_uV;
+	int		max_uV;
+	unsigned	step_uV;
+	unsigned	n_steps;
+
+	/* Current limiting */
+	unsigned	n_current_limits;
+	const int	*current_limits;
+
+	/* DA906x main register fields */
+	struct bfield	enable;		/* bit used to enable regulator,
+					   it returns actual state when read */
+	struct field	mode;		/* buck mode of operation */
+	struct bfield	suspend;
+	struct bfield	sleep;
+	struct bfield	suspend_sleep;
+	struct field	voltage;
+	struct field	suspend_voltage;
+	struct field	ilimit;
+
+	/* DA906x event detection bit */
+	struct bfield	oc_event;
+};
+
+/* Macro for switch regulator */
+#define DA906X_SWITCH(chip, regl_name) \
+	.id = chip##_ID_##regl_name, \
+	.name = __stringify(chip##_##regl_name), \
+	.ops = &da906x_switch_ops, \
+	.n_steps = 0
+
+/* Macros for LDO */
+#define DA906X_LDO(chip, regl_name, min_mV, step_mV, max_mV) \
+	.id = chip##_ID_##regl_name, \
+	.name = __stringify(chip##_##regl_name), \
+	.ops = &da906x_ldo_ops, \
+	.min_uV = (min_mV) * 1000, \
+	.max_uV = (max_mV) * 1000, \
+	.step_uV = (step_mV) * 1000, \
+	.n_steps = (((max_mV) - (min_mV))/(step_mV) + 1)
+
+#define DA906X_LDO_COMMON_FIELDS(regl_name) \
+	.enable = BFIELD(DA906X_REG_##regl_name##_CONT, DA906X_LDO_EN), \
+	.sleep = BFIELD(DA906X_REG_V##regl_name##_A, DA906X_LDO_SL), \
+	.suspend_sleep = BFIELD(DA906X_REG_V##regl_name##_B, DA906X_LDO_SL), \
+	.voltage = FIELD(DA906X_REG_V##regl_name##_A, \
+			DA906X_V##regl_name##_MASK, \
+			DA906X_V##regl_name##_SHIFT, \
+			DA906X_V##regl_name##_BIAS), \
+	.suspend_voltage = FIELD(DA906X_REG_V##regl_name##_B, \
+			DA906X_V##regl_name##_MASK,\
+			DA906X_V##regl_name##_SHIFT, \
+			DA906X_V##regl_name##_BIAS)
+
+/* Macros for voltage DC/DC converters (BUCKs) */
+#define DA906X_BUCK(chip, regl_name, min_mV, step_mV, max_mV, limits_array) \
+	.id = chip##_ID_##regl_name, \
+	.name = __stringify(chip##_##regl_name), \
+	.ops = &da906x_buck_ops, \
+	.min_uV = (min_mV) * 1000, \
+	.max_uV = (max_mV) * 1000, \
+	.step_uV = (step_mV) * 1000, \
+	.n_steps = ((max_mV) - (min_mV))/(step_mV) + 1, \
+	.current_limits = limits_array, \
+	.n_current_limits = ARRAY_SIZE(limits_array)
+
+#define DA906X_BUCK_COMMON_FIELDS(regl_name) \
+	.enable = BFIELD(DA906X_REG_##regl_name##_CONT, DA906X_BUCK_EN), \
+	.sleep = BFIELD(DA906X_REG_V##regl_name##_A, DA906X_BUCK_SL), \
+	.suspend_sleep = BFIELD(DA906X_REG_V##regl_name##_B, DA906X_BUCK_SL), \
+	.voltage = FIELD(DA906X_REG_V##regl_name##_A, \
+			 DA906X_VBUCK_MASK, \
+			 DA906X_VBUCK_SHIFT, \
+			 DA906X_VBUCK_BIAS), \
+	.suspend_voltage = FIELD(DA906X_REG_V##regl_name##_B, \
+				 DA906X_VBUCK_MASK,\
+				 DA906X_VBUCK_SHIFT, \
+				 DA906X_VBUCK_BIAS), \
+	.mode = FIELD(DA906X_REG_##regl_name##_CFG, DA906X_BUCK_MODE_MASK, \
+		      DA906X_BUCK_MODE_SHIFT, 0)
+
+/* Defines asignment of regulators info table to chip model */
+struct da906x_dev_model {
+	const struct da906x_regulator_info	*regulator_info;
+	unsigned				n_regulators;
+	unsigned				dev_model;
+};
+
+/* Single regulator settings */
+struct da906x_regulator {
+	struct regulator_desc			desc;
+	struct regulator_dev			*rdev;
+	struct da906x				*hw;
+	const struct da906x_regulator_info	*info;
+
+	unsigned				mode;
+	unsigned				suspend_mode;
+};
+
+/* Encapsulates all information for the regulators driver */
+struct da906x_regulators {
+	int					irq_ldo_lim;
+	int					irq_uvov;
+
+	unsigned				n_regulators;
+	/* Array size to be defined during init. Keep at end. */
+	struct da906x_regulator			regulator[0];
+};
+
+/* System states for da906x_update_mode_internal()
+   and for da906x_get_mode_internal() */
+enum {
+	SYS_STATE_NORMAL,
+	SYS_STATE_SUSPEND,
+	SYS_STATE_CURRENT
+};
+
+/* BUCK modes for DA906x */
+enum {
+	BUCK_MODE_MANUAL,	/* 0 */
+	BUCK_MODE_SLEEP,	/* 1 */
+	BUCK_MODE_SYNC,		/* 2 */
+	BUCK_MODE_AUTO		/* 3 */
+};
+
+/* Regulator operations */
+static int da906x_set_voltage(struct regulator_dev *rdev, int min_uV,
+			      int max_uV, unsigned *selector);
+static int da906x_get_voltage_sel(struct regulator_dev *rdev);
+static int da906x_set_current_limit(struct regulator_dev *rdev,
+				    int min_uA, int max_uA);
+static int da906x_get_current_limit(struct regulator_dev *rdev);
+static int da906x_enable(struct regulator_dev *rdev);
+static int da906x_set_mode(struct regulator_dev *rdev, unsigned int mode);
+static unsigned da906x_get_mode(struct regulator_dev *rdev);
+static int da906x_get_status(struct regulator_dev *rdev);
+static int da906x_set_suspend_voltage(struct regulator_dev *rdev, int uV);
+static int da906x_suspend_enable(struct regulator_dev *rdev);
+static int da906x_set_suspend_mode(struct regulator_dev *rdev, unsigned mode);
+
+static struct regulator_ops da906x_switch_ops = {
+	.enable			= da906x_enable,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.set_suspend_enable	= da906x_enable,
+	.set_suspend_disable	= regulator_disable_regmap,
+};
+
+static struct regulator_ops da906x_ldo_ops = {
+	.enable			= da906x_enable,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.set_voltage		= da906x_set_voltage,
+	.get_voltage_sel	= da906x_get_voltage_sel,
+	.list_voltage		= regulator_list_voltage_linear,
+	.set_mode		= da906x_set_mode,
+	.get_mode		= da906x_get_mode,
+	.get_status		= da906x_get_status,
+	.set_suspend_voltage	= da906x_set_suspend_voltage,
+	.set_suspend_enable	= da906x_suspend_enable,
+	.set_suspend_disable	= regulator_disable_regmap,
+	.set_suspend_mode	= da906x_set_suspend_mode,
+};
+
+static struct regulator_ops da906x_buck_ops = {
+	.enable			= da906x_enable,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.set_voltage		= da906x_set_voltage,
+	.get_voltage_sel	= da906x_get_voltage_sel,
+	.list_voltage		= regulator_list_voltage_linear,
+	.set_current_limit	= da906x_set_current_limit,
+	.get_current_limit	= da906x_get_current_limit,
+	.set_mode		= da906x_set_mode,
+	.get_mode		= da906x_get_mode,
+	.get_status		= da906x_get_status,
+	.set_suspend_voltage	= da906x_set_suspend_voltage,
+	.set_suspend_enable	= da906x_suspend_enable,
+	.set_suspend_disable	= regulator_disable_regmap,
+	.set_suspend_mode	= da906x_set_suspend_mode,
+};
+
+/* Current limits array (in uA) for BCORE1, BCORE2, BPRO.
+   Entry indexes corresponds to register values. */
+static const int da9063_buck_a_limits[] = {
+	 500000,  600000,  700000,  800000,  900000, 1000000, 1100000, 1200000,
+	1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000
+};
+
+/* Current limits array (in uA) for BMEM, BIO, BPERI.
+   Entry indexes corresponds to register values. */
+static const int da9063_buck_b_limits[] = {
+	1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,
+	2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000
+};
+
+/* Current limits array (in uA) for merged BCORE1 and BCORE2.
+   Entry indexes corresponds to register values. */
+static const int da9063_bcores_merged_limits[] = {
+	1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000,
+	2600000, 2800000, 3000000, 3200000, 3400000, 3600000, 3800000, 4000000
+};
+
+/* Current limits array (in uA) for merged BMEM and BIO.
+   Entry indexes corresponds to register values. */
+static const int da9063_bmem_bio_merged_limits[] = {
+	3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000,
+	4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000
+};
+
+/* Info of regulators for DA9063 */
+static const struct da906x_regulator_info da9063_regulator_info[] = {
+	{
+		DA906X_BUCK(DA9063, BCORE1, 300, 10, 1570,
+			    da9063_buck_a_limits),
+		DA906X_BUCK_COMMON_FIELDS(BCORE1),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBCORE1_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_C, DA906X_BCORE1_ILIM_MASK,
+				DA906X_BCORE1_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BCORE2, 300, 10, 1570,
+			    da9063_buck_a_limits),
+		DA906X_BUCK_COMMON_FIELDS(BCORE2),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBCORE2_SEL),
+
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_C,
+				DA906X_BCORE2_ILIM_MASK,
+				DA906X_BCORE2_ILIM_SHIFT,
+				0),
+	},
+	{
+		DA906X_BUCK(DA9063, BPRO, 530, 10, 1800,
+			    da9063_buck_a_limits),
+		DA906X_BUCK_COMMON_FIELDS(BPRO),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBPRO_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_B, DA906X_BPRO_ILIM_MASK,
+				DA906X_BPRO_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BMEM, 800, 20, 3340,
+			    da9063_buck_b_limits),
+		DA906X_BUCK_COMMON_FIELDS(BMEM),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBMEM_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_A, DA906X_BMEM_ILIM_MASK,
+				DA906X_BMEM_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BIO, 800, 20, 3340,
+			    da9063_buck_b_limits),
+		DA906X_BUCK_COMMON_FIELDS(BIO),
+		.suspend = BFIELD(DA906X_REG_DVC_2, DA906X_VBIO_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_A, DA906X_BIO_ILIM_MASK,
+				DA906X_BIO_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BPERI, 800, 20, 3340,
+			    da9063_buck_b_limits),
+		DA906X_BUCK_COMMON_FIELDS(BPERI),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBPERI_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_B, DA906X_BPERI_ILIM_MASK,
+				DA906X_BPERI_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BCORES_MERGED, 300, 10, 1570,
+			    da9063_bcores_merged_limits),
+		/* BCORES_MERGED uses the same register fields as BCORE1 */
+		DA906X_BUCK_COMMON_FIELDS(BCORE1),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBCORE1_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_C, DA906X_BCORE1_ILIM_MASK,
+				DA906X_BCORE1_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BMEM_BIO_MERGED, 800, 20, 3340,
+			    da9063_bmem_bio_merged_limits),
+		/* BMEM_BIO_MERGED uses the same register fields as BMEM */
+		DA906X_BUCK_COMMON_FIELDS(BMEM),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBMEM_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_A, DA906X_BMEM_ILIM_MASK,
+				DA906X_BMEM_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_LDO(DA9063, LDO1, 600, 20, 1860),
+		DA906X_LDO_COMMON_FIELDS(LDO1),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VLDO1_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO2, 600, 20, 1860),
+		DA906X_LDO_COMMON_FIELDS(LDO2),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VLDO2_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO3, 900, 20, 3440),
+		DA906X_LDO_COMMON_FIELDS(LDO3),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VLDO3_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO3_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO4, 900, 20, 3440),
+		DA906X_LDO_COMMON_FIELDS(LDO4),
+		.suspend = BFIELD(DA906X_REG_DVC_2, DA906X_VLDO4_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO4_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO5, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO5),
+		.suspend = BFIELD(DA906X_REG_LDO5_CONT, DA906X_VLDO5_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO6, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO6),
+		.suspend = BFIELD(DA906X_REG_LDO6_CONT, DA906X_VLDO6_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO7, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO7),
+		.suspend = BFIELD(DA906X_REG_LDO7_CONT, DA906X_VLDO7_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO7_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO8, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO8),
+		.suspend = BFIELD(DA906X_REG_LDO8_CONT, DA906X_VLDO8_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO8_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO9, 950, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO9),
+		.suspend = BFIELD(DA906X_REG_LDO9_CONT, DA906X_VLDO9_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO10, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO10),
+		.suspend = BFIELD(DA906X_REG_LDO10_CONT, DA906X_VLDO10_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO11, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO11),
+		.suspend = BFIELD(DA906X_REG_LDO11_CONT, DA906X_VLDO11_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO11_LIM),
+	},
+	{
+		DA906X_SWITCH(DA9063, 32K_OUT),
+		.enable = BFIELD(DA906X_REG_EN_32K, DA906X_OUT_32K_EN),
+	},
+};
+
+/* Link chip model with regulators info table */
+static struct da906x_dev_model regulators_models[] = {
+	{
+		.regulator_info = da9063_regulator_info,
+		.n_regulators = ARRAY_SIZE(da9063_regulator_info),
+		.dev_model = PMIC_DA9063,
+	},
+	{NULL, 0, 0}	/* End of list */
+};
+
+
+/*
+ * Regulator internal functions
+ */
+static int da906x_update_mode_internal(struct da906x_regulator *regl,
+				       int sys_state)
+{
+	const struct da906x_regulator_info *rinfo = regl->info;
+	unsigned val;
+	unsigned mode;
+	int ret;
+
+	if (sys_state == SYS_STATE_SUSPEND)
+		/* Get mode for regulator in suspend state */
+		mode = regl->suspend_mode;
+	else
+		/* Get mode for regulator in normal operation */
+		mode = regl->mode;
+
+	/* LDOs use sleep flags - one for normal and one for suspend state.
+	   For BUCKs single mode register field is used in normal and
+	   suspend state. */
+	if (rinfo->mode.addr) {
+		/* Set mode for BUCK - 3 modes are supported */
+		switch (mode) {
+		case REGULATOR_MODE_FAST:
+			val = BUCK_MODE_SYNC;
+			break;
+		case REGULATOR_MODE_NORMAL:
+			val = BUCK_MODE_AUTO;
+			break;
+		case REGULATOR_MODE_STANDBY:
+			val = BUCK_MODE_SLEEP;
+			break;
+		default:
+			return -EINVAL;
+		}
+		val = val << rinfo->mode.shift;
+
+		ret = da906x_reg_update(regl->hw, rinfo->mode.addr,
+					rinfo->mode.mask, val);
+	} else {
+		/* Set mode for LDO - 2 modes are supported */
+		switch (mode) {
+		case REGULATOR_MODE_NORMAL:
+			val = 0;
+			break;
+		case REGULATOR_MODE_STANDBY:
+			val = DA906X_LDO_SL;
+			break;
+		default:
+			return -EINVAL;
+		}
+
+		if (sys_state == SYS_STATE_SUSPEND) {
+			if (!rinfo->suspend_sleep.addr)
+				return -EINVAL;
+			ret = da906x_reg_update(regl->hw,
+						rinfo->suspend_sleep.addr,
+						rinfo->suspend_sleep.mask,
+						val);
+		} else {
+			if (!rinfo->sleep.addr)
+				return -EINVAL;
+			ret = da906x_reg_update(regl->hw,
+						rinfo->sleep.addr,
+						rinfo->sleep.mask, val);
+		}
+	}
+
+	return ret;
+}
+
+static unsigned da906x_get_mode_internal(struct da906x_regulator *regl,
+					 int sys_state)
+{
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int val;
+	int addr;
+	int mask;
+	unsigned mode = 0;
+
+	/* Bucks use single mode register field for normal operation
+	   and suspend state. LDOs use sleep flags - one for normal
+	   and one for suspend state. */
+	if (rinfo->mode.addr) {
+		/* For BUCKs, there are 3 modes to map to */
+		val = da906x_reg_read(regl->hw, rinfo->mode.addr);
+		if (val < 0)
+			return val;
+
+		val = (val & rinfo->mode.mask) >> rinfo->mode.shift;
+		switch (val) {
+		default:
+		case BUCK_MODE_MANUAL:
+			mode = REGULATOR_MODE_FAST | REGULATOR_MODE_STANDBY;
+			/* Sleep flag bit decides the mode */
+			break;
+		case BUCK_MODE_SLEEP:
+			return REGULATOR_MODE_STANDBY;
+		case BUCK_MODE_SYNC:
+			return REGULATOR_MODE_FAST;
+		case BUCK_MODE_AUTO:
+			return REGULATOR_MODE_NORMAL;
+		}
+	} else if (rinfo->sleep.addr) {
+		/* For LDOs there are 2 modes to map to */
+		mode = REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
+		/* Sleep flag bit decides the mode */
+	} else {
+		/* No support */
+		return 0;
+	}
+
+	/* If sys_state == SYS_STATE_CURRENT, current regulator state
+	   is detected. */
+	if (sys_state == SYS_STATE_CURRENT && rinfo->suspend.addr) {
+		val = da906x_reg_read(regl->hw,
+					  rinfo->suspend.addr);
+		if (val < 0)
+			return val;
+
+		if (val & rinfo->suspend.mask)
+			sys_state = SYS_STATE_SUSPEND;
+		else
+			sys_state = SYS_STATE_NORMAL;
+	}
+
+	/* Read regulator mode from proper register,
+	   depending on selected system state */
+	if (sys_state == SYS_STATE_SUSPEND && rinfo->suspend_sleep.addr) {
+		addr = rinfo->suspend_sleep.addr;
+		mask = rinfo->suspend_sleep.mask;
+	} else {
+		addr = rinfo->sleep.addr;
+		mask = rinfo->sleep.mask;
+	}
+
+	val = da906x_reg_read(regl->hw, addr);
+	if (val < 0)
+		return val;
+
+	if (val & mask)
+		mode &= REGULATOR_MODE_STANDBY;
+	else
+		mode &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST;
+
+	return mode;
+}
+
+static int da906x_set_voltage(struct regulator_dev *rdev,
+				int min_uV, int max_uV, unsigned *selector)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct field *fvol = &regl->info->voltage;
+	int ret;
+	unsigned val;
+
+	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
+	if (val < 0)
+		return -EINVAL;
+
+	val = (val + fvol->offset) << fvol->shift;
+	ret = da906x_reg_update(regl->hw, fvol->addr, fvol->mask, val);
+	if (ret >= 0)
+		*selector = val;
+
+	return ret;
+}
+
+static int da906x_get_voltage_sel(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int sel;
+
+	sel = da906x_reg_read(regl->hw, rinfo->voltage.addr);
+	if (sel < 0)
+		return sel;
+
+	sel = (sel & rinfo->voltage.mask) >> rinfo->voltage.shift;
+	sel -= rinfo->voltage.offset;
+	if (sel < 0)
+		sel = 0;
+	if (sel >= rinfo->n_steps)
+		sel = rinfo->n_steps - 1;
+
+	return sel;
+}
+
+static int da906x_set_current_limit(struct regulator_dev *rdev,
+							int min_uA, int max_uA)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int val = INT_MAX;
+	unsigned sel = 0;
+	int n;
+	int tval;
+
+	if (!rinfo->current_limits)
+		return -EINVAL;
+
+	for (n = 0; n < rinfo->n_current_limits; n++) {
+		tval = rinfo->current_limits[n];
+		if (tval >= min_uA && tval <= max_uA && val > tval) {
+			val = tval;
+			sel = n;
+		}
+	}
+	if (val == INT_MAX)
+		return -EINVAL;
+
+	sel = (sel + rinfo->ilimit.offset) << rinfo->ilimit.shift;
+	return da906x_reg_update(regl->hw, rinfo->ilimit.addr,
+						rinfo->ilimit.mask, sel);
+}
+
+static int da906x_get_current_limit(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int sel;
+
+	sel = da906x_reg_read(regl->hw, rinfo->ilimit.addr);
+	if (sel < 0)
+		return sel;
+
+	sel = (sel & rinfo->ilimit.mask) >> rinfo->ilimit.shift;
+	sel -= rinfo->ilimit.offset;
+	if (sel < 0)
+		sel = 0;
+	if (sel >= rinfo->n_current_limits)
+		sel = rinfo->n_current_limits - 1;
+
+	return rinfo->current_limits[sel];
+}
+
+static int da906x_enable(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	int ret;
+
+	if (regl->info->suspend.mask) {
+		/* Make sure to exit from suspend mode on enable */
+		ret = da906x_reg_clear_bits(regl->hw, regl->info->suspend.addr,
+					    regl->info->suspend.mask);
+		if (ret < 0)
+			return ret;
+
+		/* BUCKs need mode update after wake-up from suspend state. */
+		ret = da906x_update_mode_internal(regl, SYS_STATE_NORMAL);
+		if (ret < 0)
+			return ret;
+	}
+
+	return regulator_enable_regmap(rdev);
+}
+
+static int da906x_set_mode(struct regulator_dev *rdev, unsigned mode)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	unsigned orig_mode = regl->mode;
+	int ret;
+
+	regl->mode = mode;
+	ret = da906x_update_mode_internal(regl, SYS_STATE_NORMAL);
+	if (ret)
+		regl->mode = orig_mode;
+
+	return ret;
+}
+
+static unsigned da906x_get_mode(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+
+	return da906x_get_mode_internal(regl, SYS_STATE_CURRENT);
+}
+
+static int da906x_get_status(struct regulator_dev *rdev)
+{
+	int ret = regulator_is_enabled_regmap(rdev);
+
+	if (ret == 0) {
+		ret = REGULATOR_STATUS_OFF;
+	} else if (ret > 0) {
+		ret = da906x_get_mode(rdev);
+		if (ret > 0)
+			ret = regulator_mode_to_status(ret);
+		else if (ret == 0)
+			ret = -EIO;
+	}
+
+	return ret;
+}
+
+static int da906x_set_suspend_voltage(struct regulator_dev *rdev, int uV)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	const struct field *fsusvol = &rinfo->suspend_voltage;
+	int val;
+	int ret;
+
+	val = regulator_map_voltage_linear(rdev, uV, uV);
+	if (val < 0)
+		return -EINVAL;
+
+	val = (val + fsusvol->offset) << fsusvol->shift;
+	ret = da906x_reg_update(regl->hw, fsusvol->addr, fsusvol->mask, val);
+
+	return ret;
+}
+
+static int da906x_suspend_enable(struct regulator_dev *rdev)
+{
+	int ret;
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct bfield *bsuspend = &regl->info->suspend;
+
+	ret = da906x_reg_set_bits(regl->hw, bsuspend->addr, bsuspend->mask);
+	return ret;
+}
+
+static int da906x_set_suspend_mode(struct regulator_dev *rdev, unsigned mode)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	int ret;
+
+	regl->suspend_mode = mode;
+	ret = da906x_update_mode_internal(regl, SYS_STATE_SUSPEND);
+	return ret;
+}
+
+/* Regulator event handlers */
+irqreturn_t da906x_ldo_lim_event(int irq, void *data)
+{
+	struct da906x_regulators *regulators = data;
+	struct da906x *hw = regulators->regulator[0].hw;
+	struct da906x_regulator *regl;
+	int bits;
+	int i;
+
+	bits = da906x_reg_read(hw, DA906X_REG_STATUS_D);
+	if (bits < 0)
+		return IRQ_HANDLED;
+
+	for (i = regulators->n_regulators - 1; i >= 0; i--) {
+		regl = &regulators->regulator[i];
+		if (regl->info->oc_event.addr != DA906X_REG_STATUS_D)
+			continue;
+
+		if (regl->info->oc_event.mask & bits)
+			regulator_notifier_call_chain(regl->rdev,
+					REGULATOR_EVENT_OVER_CURRENT, NULL);
+	}
+
+	return IRQ_HANDLED;
+}
+
+/*
+ * Probing and Initialisation functions
+ */
+static __devinit const struct da906x_regulator_info *
+da906x_get_regl_info(const struct da906x *da906x,
+		     const struct da906x_dev_model *model, int id)
+{
+	int m;
+
+	for (m = model->n_regulators - 1;
+	     model->regulator_info[m].id != id; m--) {
+		if (m <= 0)
+			return NULL;
+	}
+	return &model->regulator_info[m];
+}
+
+static __devinit int da906x_regulator_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_pdata *da906x_pdata = dev_get_platdata(da906x->dev);
+	struct da906x_regulators_pdata *regl_pdata;
+	struct da906x_regulator_data *rdata;
+	const struct da906x_dev_model *model;
+	struct da906x_regulators *regulators;
+	struct da906x_regulator *regl;
+	struct regulator_config config;
+	bool bcores_merged, bmem_bio_merged;
+	size_t size;
+	int n;
+	int ret;
+
+	if (!da906x_pdata) {
+		dev_err(&pdev->dev, "No platform init data supplied\n");
+		return -ENODEV;
+	}
+	regl_pdata = da906x_pdata->regulators_pdata;
+
+	if (!regl_pdata || regl_pdata->n_regulators == 0) {
+		dev_err(&pdev->dev,
+			"No regulators defined for the platform\n");
+		return -ENODEV;
+	}
+
+	/* Find regulators set for particular device model */
+	for (model = regulators_models; model->regulator_info; model++) {
+		if (model->dev_model == da906x_model(da906x))
+			break;
+	}
+	if (!model->regulator_info) {
+		dev_err(&pdev->dev, "Chip model not recognised (%u)\n",
+			da906x_model(da906x));
+		return -ENODEV;
+	}
+
+	ret = da906x_reg_read(da906x, DA906X_REG_CONFIG_H);
+	if (ret < 0) {
+		dev_err(&pdev->dev,
+			"Error while reading BUCKs configuration\n");
+		return -EIO;
+	}
+	bcores_merged = (ret & DA906X_BCORE_MERGE) ? true : false;
+	bmem_bio_merged = (ret & DA906X_BUCK_MERGE) ? true : false;
+
+	/* Allocate memory required by usable regulators */
+	size = sizeof(struct da906x_regulators) +
+		regl_pdata->n_regulators * sizeof(struct da906x_regulator);
+	regulators = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
+	if (!regulators) {
+		dev_err(&pdev->dev, "No memory for regulators\n");
+		return -ENOMEM;
+	}
+
+	regulators->n_regulators = regl_pdata->n_regulators;
+	platform_set_drvdata(pdev, regulators);
+
+	/* Register all regulators declared in platform information */
+	n = 0;
+	while (n < regulators->n_regulators) {
+		rdata = &regl_pdata->regulator_data[n];
+
+		/* Check regulator ID against merge mode configuration */
+		switch (rdata->id) {
+		case DA9063_ID_BCORE1:
+		case DA9063_ID_BCORE2:
+			if (bcores_merged) {
+				dev_err(&pdev->dev,
+					"Cannot use BCORE1 and BCORE2 separately, when in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		case DA9063_ID_BMEM:
+		case DA9063_ID_BIO:
+			if (bmem_bio_merged) {
+				dev_err(&pdev->dev,
+					"Cannot use BMEM and BIO separately, when in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		case DA9063_ID_BCORES_MERGED:
+			if (!bcores_merged) {
+				dev_err(&pdev->dev,
+					"BCORE1 and BCORE2 are unavailable in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		case DA9063_ID_BMEM_BIO_MERGED:
+			if (!bmem_bio_merged) {
+				dev_err(&pdev->dev,
+					"BMEM and BIO are unavailable in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		}
+
+		/* Initialise regulator structure */
+		regl = &regulators->regulator[n];
+		regl->hw = da906x;
+		regl->info = da906x_get_regl_info(da906x, model, rdata->id);
+		if (!regl->info) {
+			dev_err(&pdev->dev,
+				"Invalid regulator ID in platform data\n");
+			ret = -EINVAL;
+			goto err;
+		}
+		regl->desc.type = REGULATOR_VOLTAGE;
+		regl->desc.owner = THIS_MODULE;
+		regl->desc.name = regl->info->name;
+		regl->desc.id = rdata->id;
+		regl->desc.ops = regl->info->ops;
+		regl->desc.n_voltages = regl->info->n_steps;
+		regl->desc.min_uV = regl->info->min_uV;
+		regl->desc.uV_step = regl->info->step_uV;
+		regl->desc.enable_reg = regl->info->enable.addr +
+					DA906X_MAPPING_BASE;
+		regl->desc.enable_mask = regl->info->enable.mask;
+
+		/* Register regulator */
+		config.dev = &pdev->dev;
+		config.init_data = rdata->initdata;
+		config.driver_data = regl;
+		config.regmap = da906x->regmap;
+		regl->rdev = regulator_register(&regl->desc, &config);
+		if (IS_ERR_OR_NULL(regl->rdev)) {
+			dev_err(&pdev->dev,
+				"Failed to register %s regulator\n",
+				regl->info->name);
+			ret = PTR_ERR(regl->rdev);
+			goto err;
+		}
+		n++;
+
+		/* Get current modes of operation (A/B voltage selection)
+		   for normal and suspend states */
+		ret = da906x_get_mode_internal(regl, SYS_STATE_NORMAL);
+		if (ret < 0) {
+			dev_err(&pdev->dev,
+				"Failed to read %s regulator's mode\n",
+				regl->info->name);
+			goto err;
+		}
+		if (ret == 0)
+			regl->mode = REGULATOR_MODE_NORMAL;
+		else
+			regl->mode = ret;
+
+		ret = da906x_get_mode_internal(regl, SYS_STATE_SUSPEND);
+		if (ret < 0) {
+			dev_err(&pdev->dev,
+				"Failed to read %s regulator's mode\n",
+				regl->info->name);
+			goto err;
+		}
+		if (ret == 0)
+			regl->suspend_mode = REGULATOR_MODE_NORMAL;
+		else
+			regl->mode = ret;
+	}
+
+	/* LDOs overcurrent event support */
+	regulators->irq_ldo_lim = platform_get_irq_byname(pdev, "LDO_LIM");
+	if (regulators->irq_ldo_lim >= 0) {
+		ret = request_threaded_irq(regulators->irq_ldo_lim,
+					   NULL, da906x_ldo_lim_event,
+					   IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+					   "LDO_LIM", regulators);
+		if (ret) {
+			dev_err(&pdev->dev,
+					"Failed to request LDO_LIM IRQ.\n");
+			regulators->irq_ldo_lim = -ENXIO;
+		}
+	}
+
+	return 0;
+
+err:
+	/* Wind back regulators registeration */
+	while (--n >= 0) {
+		regulator_unregister(regulators->regulator[n].rdev);
+	}
+
+	return ret;
+}
+
+static int __devexit da906x_regulator_remove(struct platform_device *pdev)
+{
+	struct da906x_regulators *regulators = platform_get_drvdata(pdev);
+	struct da906x_regulator *regl;
+
+	free_irq(regulators->irq_ldo_lim, regulators);
+	free_irq(regulators->irq_uvov, regulators);
+
+	for (regl = &regulators->regulator[regulators->n_regulators - 1];
+	     regl >= &regulators->regulator[0]; regl--)
+		regulator_unregister(regl->rdev);
+
+	return 0;
+}
+
+static struct platform_driver da906x_regulator_driver = {
+	.driver = {
+		.name = DA906X_DRVNAME_REGULATORS,
+		.owner = THIS_MODULE,
+	},
+	.probe = da906x_regulator_probe,
+	.remove = __devexit_p(da906x_regulator_remove),
+};
+
+static int __init da906x_regulator_init(void)
+{
+	return platform_driver_register(&da906x_regulator_driver);
+}
+subsys_initcall(da906x_regulator_init);
+
+static void __exit da906x_regulator_cleanup(void)
+{
+	platform_driver_unregister(&da906x_regulator_driver);
+}
+module_exit(da906x_regulator_cleanup);
+
+
+/* Module information */
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>");
+MODULE_DESCRIPTION("DA906x regulators driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("paltform:" DA906X_DRVNAME_REGULATORS);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [lm-sensors] [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
@ 2012-08-24 13:55     ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 13:55 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

The driver adds support for the following DA9063 PMIC regulators:
 - 11x LDOs (named LDO1 - LDO11),
 - 6x buck converters (BCORE1, BCORE2, BPRO, BMEM, BIO, BPERI),
 - 1x power switch to switch on/off 32 KHz oscilator output (32K_OUT).

Regulators provide following operations:
 - REGULATOR_CHANGE_STATUS for all regulators,
 - REGULATOR_CHANGE_VOLTAGE for LDOs and buck converters,
 - REGULATOR_CHANGE_MODE for LDOs and buck converters, where:
     - LDOs allow REGULATOR_MODE_NORMAL and REGULATOR_MODE_STANDBY,
     - buck converters allow REGULATOR_MODE_FAST, REGULATOR_MODE_NORMAL
       and REGULATOR_MODE_STANDBY,
 - REGULATOR_CHANGE_CURRENT for buck converters (current limits).

The driver generates REGULATOR_EVENT_OVER_CURRENT for LDO3, LDO4, LDO7, LDO8
and LDO11.

Internally, PMIC provides two voltage configurations for normal and suspend
system state for each regulator. The driver switches between those on
suspend/wake-up to provide quick and fluent output voltage change.

This driver requires MFD core driver for operation.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/regulator/Kconfig            |    6 +
 drivers/regulator/Makefile           |    1 +
 drivers/regulator/da906x-regulator.c | 1018 ++++++++++++++++++++++++++++++++++
 3 files changed, 1025 insertions(+), 0 deletions(-)
 create mode 100644 drivers/regulator/da906x-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 4e932cc..b57b6c6 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -110,6 +110,12 @@ config REGULATOR_DA9052
 	  This driver supports the voltage regulators of DA9052-BC and
 	  DA9053-AA/Bx PMIC.
 
+config REGULATOR_DA906X
+	bool "Dialog DA906X Regulator family chip"
+	depends on MFD_DA906X
+	help
+	  Support for Dialog Semiconductor DA906x chip.
+
 config REGULATOR_ANATOP
 	tristate "Freescale i.MX on-chip ANATOP LDO regulators"
 	depends on MFD_ANATOP
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 3342615..46a503a 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o
 obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o
 obj-$(CONFIG_REGULATOR_DA903X)	+= da903x.o
 obj-$(CONFIG_REGULATOR_DA9052)	+= da9052-regulator.o
+obj-$(CONFIG_REGULATOR_DA906X) += da906x-regulator.o
 obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o
 obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o
 obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o
diff --git a/drivers/regulator/da906x-regulator.c b/drivers/regulator/da906x-regulator.c
new file mode 100644
index 0000000..1b68de0
--- /dev/null
+++ b/drivers/regulator/da906x-regulator.c
@@ -0,0 +1,1018 @@
+/*
+ * Regulator driver for DA906x PMIC series
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/init.h>
+#include <linux/err.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+#include <linux/mfd/da906x/registers.h>
+
+
+/* Definition for registering bit fields */
+struct bfield {
+	unsigned short	addr;
+	unsigned char	mask;
+};
+#define BFIELD(_addr, _mask) \
+	{ .addr = _addr, .mask = _mask }
+
+struct field {
+	unsigned short	addr;
+	unsigned char	mask;
+	unsigned char	shift;
+	unsigned char	offset;
+};
+#define FIELD(_addr, _mask, _shift, _offset) \
+	{ .addr = _addr, .mask = _mask, .shift = _shift, .offset = _offset }
+
+/* Regulator capabilities and registers description */
+struct da906x_regulator_info {
+	int			id;
+	char			*name;
+	struct regulator_ops	*ops;
+
+	/* Voltage adjust range */
+	int		min_uV;
+	int		max_uV;
+	unsigned	step_uV;
+	unsigned	n_steps;
+
+	/* Current limiting */
+	unsigned	n_current_limits;
+	const int	*current_limits;
+
+	/* DA906x main register fields */
+	struct bfield	enable;		/* bit used to enable regulator,
+					   it returns actual state when read */
+	struct field	mode;		/* buck mode of operation */
+	struct bfield	suspend;
+	struct bfield	sleep;
+	struct bfield	suspend_sleep;
+	struct field	voltage;
+	struct field	suspend_voltage;
+	struct field	ilimit;
+
+	/* DA906x event detection bit */
+	struct bfield	oc_event;
+};
+
+/* Macro for switch regulator */
+#define DA906X_SWITCH(chip, regl_name) \
+	.id = chip##_ID_##regl_name, \
+	.name = __stringify(chip##_##regl_name), \
+	.ops = &da906x_switch_ops, \
+	.n_steps = 0
+
+/* Macros for LDO */
+#define DA906X_LDO(chip, regl_name, min_mV, step_mV, max_mV) \
+	.id = chip##_ID_##regl_name, \
+	.name = __stringify(chip##_##regl_name), \
+	.ops = &da906x_ldo_ops, \
+	.min_uV = (min_mV) * 1000, \
+	.max_uV = (max_mV) * 1000, \
+	.step_uV = (step_mV) * 1000, \
+	.n_steps = (((max_mV) - (min_mV))/(step_mV) + 1)
+
+#define DA906X_LDO_COMMON_FIELDS(regl_name) \
+	.enable = BFIELD(DA906X_REG_##regl_name##_CONT, DA906X_LDO_EN), \
+	.sleep = BFIELD(DA906X_REG_V##regl_name##_A, DA906X_LDO_SL), \
+	.suspend_sleep = BFIELD(DA906X_REG_V##regl_name##_B, DA906X_LDO_SL), \
+	.voltage = FIELD(DA906X_REG_V##regl_name##_A, \
+			DA906X_V##regl_name##_MASK, \
+			DA906X_V##regl_name##_SHIFT, \
+			DA906X_V##regl_name##_BIAS), \
+	.suspend_voltage = FIELD(DA906X_REG_V##regl_name##_B, \
+			DA906X_V##regl_name##_MASK,\
+			DA906X_V##regl_name##_SHIFT, \
+			DA906X_V##regl_name##_BIAS)
+
+/* Macros for voltage DC/DC converters (BUCKs) */
+#define DA906X_BUCK(chip, regl_name, min_mV, step_mV, max_mV, limits_array) \
+	.id = chip##_ID_##regl_name, \
+	.name = __stringify(chip##_##regl_name), \
+	.ops = &da906x_buck_ops, \
+	.min_uV = (min_mV) * 1000, \
+	.max_uV = (max_mV) * 1000, \
+	.step_uV = (step_mV) * 1000, \
+	.n_steps = ((max_mV) - (min_mV))/(step_mV) + 1, \
+	.current_limits = limits_array, \
+	.n_current_limits = ARRAY_SIZE(limits_array)
+
+#define DA906X_BUCK_COMMON_FIELDS(regl_name) \
+	.enable = BFIELD(DA906X_REG_##regl_name##_CONT, DA906X_BUCK_EN), \
+	.sleep = BFIELD(DA906X_REG_V##regl_name##_A, DA906X_BUCK_SL), \
+	.suspend_sleep = BFIELD(DA906X_REG_V##regl_name##_B, DA906X_BUCK_SL), \
+	.voltage = FIELD(DA906X_REG_V##regl_name##_A, \
+			 DA906X_VBUCK_MASK, \
+			 DA906X_VBUCK_SHIFT, \
+			 DA906X_VBUCK_BIAS), \
+	.suspend_voltage = FIELD(DA906X_REG_V##regl_name##_B, \
+				 DA906X_VBUCK_MASK,\
+				 DA906X_VBUCK_SHIFT, \
+				 DA906X_VBUCK_BIAS), \
+	.mode = FIELD(DA906X_REG_##regl_name##_CFG, DA906X_BUCK_MODE_MASK, \
+		      DA906X_BUCK_MODE_SHIFT, 0)
+
+/* Defines asignment of regulators info table to chip model */
+struct da906x_dev_model {
+	const struct da906x_regulator_info	*regulator_info;
+	unsigned				n_regulators;
+	unsigned				dev_model;
+};
+
+/* Single regulator settings */
+struct da906x_regulator {
+	struct regulator_desc			desc;
+	struct regulator_dev			*rdev;
+	struct da906x				*hw;
+	const struct da906x_regulator_info	*info;
+
+	unsigned				mode;
+	unsigned				suspend_mode;
+};
+
+/* Encapsulates all information for the regulators driver */
+struct da906x_regulators {
+	int					irq_ldo_lim;
+	int					irq_uvov;
+
+	unsigned				n_regulators;
+	/* Array size to be defined during init. Keep at end. */
+	struct da906x_regulator			regulator[0];
+};
+
+/* System states for da906x_update_mode_internal()
+   and for da906x_get_mode_internal() */
+enum {
+	SYS_STATE_NORMAL,
+	SYS_STATE_SUSPEND,
+	SYS_STATE_CURRENT
+};
+
+/* BUCK modes for DA906x */
+enum {
+	BUCK_MODE_MANUAL,	/* 0 */
+	BUCK_MODE_SLEEP,	/* 1 */
+	BUCK_MODE_SYNC,		/* 2 */
+	BUCK_MODE_AUTO		/* 3 */
+};
+
+/* Regulator operations */
+static int da906x_set_voltage(struct regulator_dev *rdev, int min_uV,
+			      int max_uV, unsigned *selector);
+static int da906x_get_voltage_sel(struct regulator_dev *rdev);
+static int da906x_set_current_limit(struct regulator_dev *rdev,
+				    int min_uA, int max_uA);
+static int da906x_get_current_limit(struct regulator_dev *rdev);
+static int da906x_enable(struct regulator_dev *rdev);
+static int da906x_set_mode(struct regulator_dev *rdev, unsigned int mode);
+static unsigned da906x_get_mode(struct regulator_dev *rdev);
+static int da906x_get_status(struct regulator_dev *rdev);
+static int da906x_set_suspend_voltage(struct regulator_dev *rdev, int uV);
+static int da906x_suspend_enable(struct regulator_dev *rdev);
+static int da906x_set_suspend_mode(struct regulator_dev *rdev, unsigned mode);
+
+static struct regulator_ops da906x_switch_ops = {
+	.enable			= da906x_enable,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.set_suspend_enable	= da906x_enable,
+	.set_suspend_disable	= regulator_disable_regmap,
+};
+
+static struct regulator_ops da906x_ldo_ops = {
+	.enable			= da906x_enable,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.set_voltage		= da906x_set_voltage,
+	.get_voltage_sel	= da906x_get_voltage_sel,
+	.list_voltage		= regulator_list_voltage_linear,
+	.set_mode		= da906x_set_mode,
+	.get_mode		= da906x_get_mode,
+	.get_status		= da906x_get_status,
+	.set_suspend_voltage	= da906x_set_suspend_voltage,
+	.set_suspend_enable	= da906x_suspend_enable,
+	.set_suspend_disable	= regulator_disable_regmap,
+	.set_suspend_mode	= da906x_set_suspend_mode,
+};
+
+static struct regulator_ops da906x_buck_ops = {
+	.enable			= da906x_enable,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.set_voltage		= da906x_set_voltage,
+	.get_voltage_sel	= da906x_get_voltage_sel,
+	.list_voltage		= regulator_list_voltage_linear,
+	.set_current_limit	= da906x_set_current_limit,
+	.get_current_limit	= da906x_get_current_limit,
+	.set_mode		= da906x_set_mode,
+	.get_mode		= da906x_get_mode,
+	.get_status		= da906x_get_status,
+	.set_suspend_voltage	= da906x_set_suspend_voltage,
+	.set_suspend_enable	= da906x_suspend_enable,
+	.set_suspend_disable	= regulator_disable_regmap,
+	.set_suspend_mode	= da906x_set_suspend_mode,
+};
+
+/* Current limits array (in uA) for BCORE1, BCORE2, BPRO.
+   Entry indexes corresponds to register values. */
+static const int da9063_buck_a_limits[] = {
+	 500000,  600000,  700000,  800000,  900000, 1000000, 1100000, 1200000,
+	1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000
+};
+
+/* Current limits array (in uA) for BMEM, BIO, BPERI.
+   Entry indexes corresponds to register values. */
+static const int da9063_buck_b_limits[] = {
+	1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,
+	2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000
+};
+
+/* Current limits array (in uA) for merged BCORE1 and BCORE2.
+   Entry indexes corresponds to register values. */
+static const int da9063_bcores_merged_limits[] = {
+	1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000,
+	2600000, 2800000, 3000000, 3200000, 3400000, 3600000, 3800000, 4000000
+};
+
+/* Current limits array (in uA) for merged BMEM and BIO.
+   Entry indexes corresponds to register values. */
+static const int da9063_bmem_bio_merged_limits[] = {
+	3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000,
+	4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000
+};
+
+/* Info of regulators for DA9063 */
+static const struct da906x_regulator_info da9063_regulator_info[] = {
+	{
+		DA906X_BUCK(DA9063, BCORE1, 300, 10, 1570,
+			    da9063_buck_a_limits),
+		DA906X_BUCK_COMMON_FIELDS(BCORE1),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBCORE1_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_C, DA906X_BCORE1_ILIM_MASK,
+				DA906X_BCORE1_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BCORE2, 300, 10, 1570,
+			    da9063_buck_a_limits),
+		DA906X_BUCK_COMMON_FIELDS(BCORE2),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBCORE2_SEL),
+
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_C,
+				DA906X_BCORE2_ILIM_MASK,
+				DA906X_BCORE2_ILIM_SHIFT,
+				0),
+	},
+	{
+		DA906X_BUCK(DA9063, BPRO, 530, 10, 1800,
+			    da9063_buck_a_limits),
+		DA906X_BUCK_COMMON_FIELDS(BPRO),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBPRO_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_B, DA906X_BPRO_ILIM_MASK,
+				DA906X_BPRO_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BMEM, 800, 20, 3340,
+			    da9063_buck_b_limits),
+		DA906X_BUCK_COMMON_FIELDS(BMEM),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBMEM_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_A, DA906X_BMEM_ILIM_MASK,
+				DA906X_BMEM_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BIO, 800, 20, 3340,
+			    da9063_buck_b_limits),
+		DA906X_BUCK_COMMON_FIELDS(BIO),
+		.suspend = BFIELD(DA906X_REG_DVC_2, DA906X_VBIO_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_A, DA906X_BIO_ILIM_MASK,
+				DA906X_BIO_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BPERI, 800, 20, 3340,
+			    da9063_buck_b_limits),
+		DA906X_BUCK_COMMON_FIELDS(BPERI),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBPERI_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_B, DA906X_BPERI_ILIM_MASK,
+				DA906X_BPERI_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BCORES_MERGED, 300, 10, 1570,
+			    da9063_bcores_merged_limits),
+		/* BCORES_MERGED uses the same register fields as BCORE1 */
+		DA906X_BUCK_COMMON_FIELDS(BCORE1),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBCORE1_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_C, DA906X_BCORE1_ILIM_MASK,
+				DA906X_BCORE1_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_BUCK(DA9063, BMEM_BIO_MERGED, 800, 20, 3340,
+			    da9063_bmem_bio_merged_limits),
+		/* BMEM_BIO_MERGED uses the same register fields as BMEM */
+		DA906X_BUCK_COMMON_FIELDS(BMEM),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VBMEM_SEL),
+		.ilimit = FIELD(DA906X_REG_BUCK_ILIM_A, DA906X_BMEM_ILIM_MASK,
+				DA906X_BMEM_ILIM_SHIFT, 0),
+	},
+	{
+		DA906X_LDO(DA9063, LDO1, 600, 20, 1860),
+		DA906X_LDO_COMMON_FIELDS(LDO1),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VLDO1_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO2, 600, 20, 1860),
+		DA906X_LDO_COMMON_FIELDS(LDO2),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VLDO2_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO3, 900, 20, 3440),
+		DA906X_LDO_COMMON_FIELDS(LDO3),
+		.suspend = BFIELD(DA906X_REG_DVC_1, DA906X_VLDO3_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO3_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO4, 900, 20, 3440),
+		DA906X_LDO_COMMON_FIELDS(LDO4),
+		.suspend = BFIELD(DA906X_REG_DVC_2, DA906X_VLDO4_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO4_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO5, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO5),
+		.suspend = BFIELD(DA906X_REG_LDO5_CONT, DA906X_VLDO5_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO6, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO6),
+		.suspend = BFIELD(DA906X_REG_LDO6_CONT, DA906X_VLDO6_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO7, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO7),
+		.suspend = BFIELD(DA906X_REG_LDO7_CONT, DA906X_VLDO7_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO7_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO8, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO8),
+		.suspend = BFIELD(DA906X_REG_LDO8_CONT, DA906X_VLDO8_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO8_LIM),
+	},
+	{
+		DA906X_LDO(DA9063, LDO9, 950, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO9),
+		.suspend = BFIELD(DA906X_REG_LDO9_CONT, DA906X_VLDO9_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO10, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO10),
+		.suspend = BFIELD(DA906X_REG_LDO10_CONT, DA906X_VLDO10_SEL),
+	},
+	{
+		DA906X_LDO(DA9063, LDO11, 900, 50, 3600),
+		DA906X_LDO_COMMON_FIELDS(LDO11),
+		.suspend = BFIELD(DA906X_REG_LDO11_CONT, DA906X_VLDO11_SEL),
+		.oc_event = BFIELD(DA906X_REG_STATUS_D, DA906X_LDO11_LIM),
+	},
+	{
+		DA906X_SWITCH(DA9063, 32K_OUT),
+		.enable = BFIELD(DA906X_REG_EN_32K, DA906X_OUT_32K_EN),
+	},
+};
+
+/* Link chip model with regulators info table */
+static struct da906x_dev_model regulators_models[] = {
+	{
+		.regulator_info = da9063_regulator_info,
+		.n_regulators = ARRAY_SIZE(da9063_regulator_info),
+		.dev_model = PMIC_DA9063,
+	},
+	{NULL, 0, 0}	/* End of list */
+};
+
+
+/*
+ * Regulator internal functions
+ */
+static int da906x_update_mode_internal(struct da906x_regulator *regl,
+				       int sys_state)
+{
+	const struct da906x_regulator_info *rinfo = regl->info;
+	unsigned val;
+	unsigned mode;
+	int ret;
+
+	if (sys_state = SYS_STATE_SUSPEND)
+		/* Get mode for regulator in suspend state */
+		mode = regl->suspend_mode;
+	else
+		/* Get mode for regulator in normal operation */
+		mode = regl->mode;
+
+	/* LDOs use sleep flags - one for normal and one for suspend state.
+	   For BUCKs single mode register field is used in normal and
+	   suspend state. */
+	if (rinfo->mode.addr) {
+		/* Set mode for BUCK - 3 modes are supported */
+		switch (mode) {
+		case REGULATOR_MODE_FAST:
+			val = BUCK_MODE_SYNC;
+			break;
+		case REGULATOR_MODE_NORMAL:
+			val = BUCK_MODE_AUTO;
+			break;
+		case REGULATOR_MODE_STANDBY:
+			val = BUCK_MODE_SLEEP;
+			break;
+		default:
+			return -EINVAL;
+		}
+		val = val << rinfo->mode.shift;
+
+		ret = da906x_reg_update(regl->hw, rinfo->mode.addr,
+					rinfo->mode.mask, val);
+	} else {
+		/* Set mode for LDO - 2 modes are supported */
+		switch (mode) {
+		case REGULATOR_MODE_NORMAL:
+			val = 0;
+			break;
+		case REGULATOR_MODE_STANDBY:
+			val = DA906X_LDO_SL;
+			break;
+		default:
+			return -EINVAL;
+		}
+
+		if (sys_state = SYS_STATE_SUSPEND) {
+			if (!rinfo->suspend_sleep.addr)
+				return -EINVAL;
+			ret = da906x_reg_update(regl->hw,
+						rinfo->suspend_sleep.addr,
+						rinfo->suspend_sleep.mask,
+						val);
+		} else {
+			if (!rinfo->sleep.addr)
+				return -EINVAL;
+			ret = da906x_reg_update(regl->hw,
+						rinfo->sleep.addr,
+						rinfo->sleep.mask, val);
+		}
+	}
+
+	return ret;
+}
+
+static unsigned da906x_get_mode_internal(struct da906x_regulator *regl,
+					 int sys_state)
+{
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int val;
+	int addr;
+	int mask;
+	unsigned mode = 0;
+
+	/* Bucks use single mode register field for normal operation
+	   and suspend state. LDOs use sleep flags - one for normal
+	   and one for suspend state. */
+	if (rinfo->mode.addr) {
+		/* For BUCKs, there are 3 modes to map to */
+		val = da906x_reg_read(regl->hw, rinfo->mode.addr);
+		if (val < 0)
+			return val;
+
+		val = (val & rinfo->mode.mask) >> rinfo->mode.shift;
+		switch (val) {
+		default:
+		case BUCK_MODE_MANUAL:
+			mode = REGULATOR_MODE_FAST | REGULATOR_MODE_STANDBY;
+			/* Sleep flag bit decides the mode */
+			break;
+		case BUCK_MODE_SLEEP:
+			return REGULATOR_MODE_STANDBY;
+		case BUCK_MODE_SYNC:
+			return REGULATOR_MODE_FAST;
+		case BUCK_MODE_AUTO:
+			return REGULATOR_MODE_NORMAL;
+		}
+	} else if (rinfo->sleep.addr) {
+		/* For LDOs there are 2 modes to map to */
+		mode = REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
+		/* Sleep flag bit decides the mode */
+	} else {
+		/* No support */
+		return 0;
+	}
+
+	/* If sys_state = SYS_STATE_CURRENT, current regulator state
+	   is detected. */
+	if (sys_state = SYS_STATE_CURRENT && rinfo->suspend.addr) {
+		val = da906x_reg_read(regl->hw,
+					  rinfo->suspend.addr);
+		if (val < 0)
+			return val;
+
+		if (val & rinfo->suspend.mask)
+			sys_state = SYS_STATE_SUSPEND;
+		else
+			sys_state = SYS_STATE_NORMAL;
+	}
+
+	/* Read regulator mode from proper register,
+	   depending on selected system state */
+	if (sys_state = SYS_STATE_SUSPEND && rinfo->suspend_sleep.addr) {
+		addr = rinfo->suspend_sleep.addr;
+		mask = rinfo->suspend_sleep.mask;
+	} else {
+		addr = rinfo->sleep.addr;
+		mask = rinfo->sleep.mask;
+	}
+
+	val = da906x_reg_read(regl->hw, addr);
+	if (val < 0)
+		return val;
+
+	if (val & mask)
+		mode &= REGULATOR_MODE_STANDBY;
+	else
+		mode &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST;
+
+	return mode;
+}
+
+static int da906x_set_voltage(struct regulator_dev *rdev,
+				int min_uV, int max_uV, unsigned *selector)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct field *fvol = &regl->info->voltage;
+	int ret;
+	unsigned val;
+
+	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
+	if (val < 0)
+		return -EINVAL;
+
+	val = (val + fvol->offset) << fvol->shift;
+	ret = da906x_reg_update(regl->hw, fvol->addr, fvol->mask, val);
+	if (ret >= 0)
+		*selector = val;
+
+	return ret;
+}
+
+static int da906x_get_voltage_sel(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int sel;
+
+	sel = da906x_reg_read(regl->hw, rinfo->voltage.addr);
+	if (sel < 0)
+		return sel;
+
+	sel = (sel & rinfo->voltage.mask) >> rinfo->voltage.shift;
+	sel -= rinfo->voltage.offset;
+	if (sel < 0)
+		sel = 0;
+	if (sel >= rinfo->n_steps)
+		sel = rinfo->n_steps - 1;
+
+	return sel;
+}
+
+static int da906x_set_current_limit(struct regulator_dev *rdev,
+							int min_uA, int max_uA)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int val = INT_MAX;
+	unsigned sel = 0;
+	int n;
+	int tval;
+
+	if (!rinfo->current_limits)
+		return -EINVAL;
+
+	for (n = 0; n < rinfo->n_current_limits; n++) {
+		tval = rinfo->current_limits[n];
+		if (tval >= min_uA && tval <= max_uA && val > tval) {
+			val = tval;
+			sel = n;
+		}
+	}
+	if (val = INT_MAX)
+		return -EINVAL;
+
+	sel = (sel + rinfo->ilimit.offset) << rinfo->ilimit.shift;
+	return da906x_reg_update(regl->hw, rinfo->ilimit.addr,
+						rinfo->ilimit.mask, sel);
+}
+
+static int da906x_get_current_limit(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	int sel;
+
+	sel = da906x_reg_read(regl->hw, rinfo->ilimit.addr);
+	if (sel < 0)
+		return sel;
+
+	sel = (sel & rinfo->ilimit.mask) >> rinfo->ilimit.shift;
+	sel -= rinfo->ilimit.offset;
+	if (sel < 0)
+		sel = 0;
+	if (sel >= rinfo->n_current_limits)
+		sel = rinfo->n_current_limits - 1;
+
+	return rinfo->current_limits[sel];
+}
+
+static int da906x_enable(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	int ret;
+
+	if (regl->info->suspend.mask) {
+		/* Make sure to exit from suspend mode on enable */
+		ret = da906x_reg_clear_bits(regl->hw, regl->info->suspend.addr,
+					    regl->info->suspend.mask);
+		if (ret < 0)
+			return ret;
+
+		/* BUCKs need mode update after wake-up from suspend state. */
+		ret = da906x_update_mode_internal(regl, SYS_STATE_NORMAL);
+		if (ret < 0)
+			return ret;
+	}
+
+	return regulator_enable_regmap(rdev);
+}
+
+static int da906x_set_mode(struct regulator_dev *rdev, unsigned mode)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	unsigned orig_mode = regl->mode;
+	int ret;
+
+	regl->mode = mode;
+	ret = da906x_update_mode_internal(regl, SYS_STATE_NORMAL);
+	if (ret)
+		regl->mode = orig_mode;
+
+	return ret;
+}
+
+static unsigned da906x_get_mode(struct regulator_dev *rdev)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+
+	return da906x_get_mode_internal(regl, SYS_STATE_CURRENT);
+}
+
+static int da906x_get_status(struct regulator_dev *rdev)
+{
+	int ret = regulator_is_enabled_regmap(rdev);
+
+	if (ret = 0) {
+		ret = REGULATOR_STATUS_OFF;
+	} else if (ret > 0) {
+		ret = da906x_get_mode(rdev);
+		if (ret > 0)
+			ret = regulator_mode_to_status(ret);
+		else if (ret = 0)
+			ret = -EIO;
+	}
+
+	return ret;
+}
+
+static int da906x_set_suspend_voltage(struct regulator_dev *rdev, int uV)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct da906x_regulator_info *rinfo = regl->info;
+	const struct field *fsusvol = &rinfo->suspend_voltage;
+	int val;
+	int ret;
+
+	val = regulator_map_voltage_linear(rdev, uV, uV);
+	if (val < 0)
+		return -EINVAL;
+
+	val = (val + fsusvol->offset) << fsusvol->shift;
+	ret = da906x_reg_update(regl->hw, fsusvol->addr, fsusvol->mask, val);
+
+	return ret;
+}
+
+static int da906x_suspend_enable(struct regulator_dev *rdev)
+{
+	int ret;
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	const struct bfield *bsuspend = &regl->info->suspend;
+
+	ret = da906x_reg_set_bits(regl->hw, bsuspend->addr, bsuspend->mask);
+	return ret;
+}
+
+static int da906x_set_suspend_mode(struct regulator_dev *rdev, unsigned mode)
+{
+	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
+	int ret;
+
+	regl->suspend_mode = mode;
+	ret = da906x_update_mode_internal(regl, SYS_STATE_SUSPEND);
+	return ret;
+}
+
+/* Regulator event handlers */
+irqreturn_t da906x_ldo_lim_event(int irq, void *data)
+{
+	struct da906x_regulators *regulators = data;
+	struct da906x *hw = regulators->regulator[0].hw;
+	struct da906x_regulator *regl;
+	int bits;
+	int i;
+
+	bits = da906x_reg_read(hw, DA906X_REG_STATUS_D);
+	if (bits < 0)
+		return IRQ_HANDLED;
+
+	for (i = regulators->n_regulators - 1; i >= 0; i--) {
+		regl = &regulators->regulator[i];
+		if (regl->info->oc_event.addr != DA906X_REG_STATUS_D)
+			continue;
+
+		if (regl->info->oc_event.mask & bits)
+			regulator_notifier_call_chain(regl->rdev,
+					REGULATOR_EVENT_OVER_CURRENT, NULL);
+	}
+
+	return IRQ_HANDLED;
+}
+
+/*
+ * Probing and Initialisation functions
+ */
+static __devinit const struct da906x_regulator_info *
+da906x_get_regl_info(const struct da906x *da906x,
+		     const struct da906x_dev_model *model, int id)
+{
+	int m;
+
+	for (m = model->n_regulators - 1;
+	     model->regulator_info[m].id != id; m--) {
+		if (m <= 0)
+			return NULL;
+	}
+	return &model->regulator_info[m];
+}
+
+static __devinit int da906x_regulator_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_pdata *da906x_pdata = dev_get_platdata(da906x->dev);
+	struct da906x_regulators_pdata *regl_pdata;
+	struct da906x_regulator_data *rdata;
+	const struct da906x_dev_model *model;
+	struct da906x_regulators *regulators;
+	struct da906x_regulator *regl;
+	struct regulator_config config;
+	bool bcores_merged, bmem_bio_merged;
+	size_t size;
+	int n;
+	int ret;
+
+	if (!da906x_pdata) {
+		dev_err(&pdev->dev, "No platform init data supplied\n");
+		return -ENODEV;
+	}
+	regl_pdata = da906x_pdata->regulators_pdata;
+
+	if (!regl_pdata || regl_pdata->n_regulators = 0) {
+		dev_err(&pdev->dev,
+			"No regulators defined for the platform\n");
+		return -ENODEV;
+	}
+
+	/* Find regulators set for particular device model */
+	for (model = regulators_models; model->regulator_info; model++) {
+		if (model->dev_model = da906x_model(da906x))
+			break;
+	}
+	if (!model->regulator_info) {
+		dev_err(&pdev->dev, "Chip model not recognised (%u)\n",
+			da906x_model(da906x));
+		return -ENODEV;
+	}
+
+	ret = da906x_reg_read(da906x, DA906X_REG_CONFIG_H);
+	if (ret < 0) {
+		dev_err(&pdev->dev,
+			"Error while reading BUCKs configuration\n");
+		return -EIO;
+	}
+	bcores_merged = (ret & DA906X_BCORE_MERGE) ? true : false;
+	bmem_bio_merged = (ret & DA906X_BUCK_MERGE) ? true : false;
+
+	/* Allocate memory required by usable regulators */
+	size = sizeof(struct da906x_regulators) +
+		regl_pdata->n_regulators * sizeof(struct da906x_regulator);
+	regulators = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
+	if (!regulators) {
+		dev_err(&pdev->dev, "No memory for regulators\n");
+		return -ENOMEM;
+	}
+
+	regulators->n_regulators = regl_pdata->n_regulators;
+	platform_set_drvdata(pdev, regulators);
+
+	/* Register all regulators declared in platform information */
+	n = 0;
+	while (n < regulators->n_regulators) {
+		rdata = &regl_pdata->regulator_data[n];
+
+		/* Check regulator ID against merge mode configuration */
+		switch (rdata->id) {
+		case DA9063_ID_BCORE1:
+		case DA9063_ID_BCORE2:
+			if (bcores_merged) {
+				dev_err(&pdev->dev,
+					"Cannot use BCORE1 and BCORE2 separately, when in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		case DA9063_ID_BMEM:
+		case DA9063_ID_BIO:
+			if (bmem_bio_merged) {
+				dev_err(&pdev->dev,
+					"Cannot use BMEM and BIO separately, when in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		case DA9063_ID_BCORES_MERGED:
+			if (!bcores_merged) {
+				dev_err(&pdev->dev,
+					"BCORE1 and BCORE2 are unavailable in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		case DA9063_ID_BMEM_BIO_MERGED:
+			if (!bmem_bio_merged) {
+				dev_err(&pdev->dev,
+					"BMEM and BIO are unavailable in merge mode\n");
+				ret = -EINVAL;
+				goto err;
+			}
+			break;
+		}
+
+		/* Initialise regulator structure */
+		regl = &regulators->regulator[n];
+		regl->hw = da906x;
+		regl->info = da906x_get_regl_info(da906x, model, rdata->id);
+		if (!regl->info) {
+			dev_err(&pdev->dev,
+				"Invalid regulator ID in platform data\n");
+			ret = -EINVAL;
+			goto err;
+		}
+		regl->desc.type = REGULATOR_VOLTAGE;
+		regl->desc.owner = THIS_MODULE;
+		regl->desc.name = regl->info->name;
+		regl->desc.id = rdata->id;
+		regl->desc.ops = regl->info->ops;
+		regl->desc.n_voltages = regl->info->n_steps;
+		regl->desc.min_uV = regl->info->min_uV;
+		regl->desc.uV_step = regl->info->step_uV;
+		regl->desc.enable_reg = regl->info->enable.addr +
+					DA906X_MAPPING_BASE;
+		regl->desc.enable_mask = regl->info->enable.mask;
+
+		/* Register regulator */
+		config.dev = &pdev->dev;
+		config.init_data = rdata->initdata;
+		config.driver_data = regl;
+		config.regmap = da906x->regmap;
+		regl->rdev = regulator_register(&regl->desc, &config);
+		if (IS_ERR_OR_NULL(regl->rdev)) {
+			dev_err(&pdev->dev,
+				"Failed to register %s regulator\n",
+				regl->info->name);
+			ret = PTR_ERR(regl->rdev);
+			goto err;
+		}
+		n++;
+
+		/* Get current modes of operation (A/B voltage selection)
+		   for normal and suspend states */
+		ret = da906x_get_mode_internal(regl, SYS_STATE_NORMAL);
+		if (ret < 0) {
+			dev_err(&pdev->dev,
+				"Failed to read %s regulator's mode\n",
+				regl->info->name);
+			goto err;
+		}
+		if (ret = 0)
+			regl->mode = REGULATOR_MODE_NORMAL;
+		else
+			regl->mode = ret;
+
+		ret = da906x_get_mode_internal(regl, SYS_STATE_SUSPEND);
+		if (ret < 0) {
+			dev_err(&pdev->dev,
+				"Failed to read %s regulator's mode\n",
+				regl->info->name);
+			goto err;
+		}
+		if (ret = 0)
+			regl->suspend_mode = REGULATOR_MODE_NORMAL;
+		else
+			regl->mode = ret;
+	}
+
+	/* LDOs overcurrent event support */
+	regulators->irq_ldo_lim = platform_get_irq_byname(pdev, "LDO_LIM");
+	if (regulators->irq_ldo_lim >= 0) {
+		ret = request_threaded_irq(regulators->irq_ldo_lim,
+					   NULL, da906x_ldo_lim_event,
+					   IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+					   "LDO_LIM", regulators);
+		if (ret) {
+			dev_err(&pdev->dev,
+					"Failed to request LDO_LIM IRQ.\n");
+			regulators->irq_ldo_lim = -ENXIO;
+		}
+	}
+
+	return 0;
+
+err:
+	/* Wind back regulators registeration */
+	while (--n >= 0) {
+		regulator_unregister(regulators->regulator[n].rdev);
+	}
+
+	return ret;
+}
+
+static int __devexit da906x_regulator_remove(struct platform_device *pdev)
+{
+	struct da906x_regulators *regulators = platform_get_drvdata(pdev);
+	struct da906x_regulator *regl;
+
+	free_irq(regulators->irq_ldo_lim, regulators);
+	free_irq(regulators->irq_uvov, regulators);
+
+	for (regl = &regulators->regulator[regulators->n_regulators - 1];
+	     regl >= &regulators->regulator[0]; regl--)
+		regulator_unregister(regl->rdev);
+
+	return 0;
+}
+
+static struct platform_driver da906x_regulator_driver = {
+	.driver = {
+		.name = DA906X_DRVNAME_REGULATORS,
+		.owner = THIS_MODULE,
+	},
+	.probe = da906x_regulator_probe,
+	.remove = __devexit_p(da906x_regulator_remove),
+};
+
+static int __init da906x_regulator_init(void)
+{
+	return platform_driver_register(&da906x_regulator_driver);
+}
+subsys_initcall(da906x_regulator_init);
+
+static void __exit da906x_regulator_cleanup(void)
+{
+	platform_driver_unregister(&da906x_regulator_driver);
+}
+module_exit(da906x_regulator_cleanup);
+
+
+/* Module information */
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>");
+MODULE_DESCRIPTION("DA906x regulators driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("paltform:" DA906X_DRVNAME_REGULATORS);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [RFC PATCH 3/8] rtc: Add RTC driver for DA906x PMIC.
  2012-08-24 13:55     ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-24 14:00       ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 14:00 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

DA906x RTC driver supports date/time and alarm.

In hardware, PMIC supports alarm setting with a resolution of one minute and
tick event (every second update event). The driver combines it, providing alarm
with one second resolution.

The driver requires MFD core driver for operation.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/rtc/Kconfig      |    7 +
 drivers/rtc/Makefile     |    1 +
 drivers/rtc/rtc-da906x.c |  379 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 387 insertions(+), 0 deletions(-)
 create mode 100644 drivers/rtc/rtc-da906x.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index fabc99a..e6037cd 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -571,6 +571,13 @@ config RTC_DRV_DA9052
 	  Say y here to support the RTC driver for Dialog Semiconductor
 	  DA9052-BC and DA9053-AA/Bx PMICs.
 
+config RTC_DRV_DA906X
+	tristate "Dialog DA906X RTC"
+	depends on MFD_DA906X
+	help
+	  Say y here to support the RTC driver for
+	  Dialog Semiconductor DA906x PMIC.
+
 config RTC_DRV_EFI
 	tristate "EFI RTC"
 	depends on IA64
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 0d5b2b6..d9c1e9f 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_RTC_DRV_BQ4802)	+= rtc-bq4802.o
 obj-$(CONFIG_RTC_DRV_CMOS)	+= rtc-cmos.o
 obj-$(CONFIG_RTC_DRV_COH901331)	+= rtc-coh901331.o
 obj-$(CONFIG_RTC_DRV_DA9052)	+= rtc-da9052.o
+obj-$(CONFIG_RTC_DRV_DA906X)	+= rtc-da906x.o
 obj-$(CONFIG_RTC_DRV_DAVINCI)	+= rtc-davinci.o
 obj-$(CONFIG_RTC_DRV_DM355EVM)	+= rtc-dm355evm.o
 obj-$(CONFIG_RTC_DRV_VRTC)	+= rtc-mrst.o
diff --git a/drivers/rtc/rtc-da906x.c b/drivers/rtc/rtc-da906x.c
new file mode 100644
index 0000000..0b4fecc
--- /dev/null
+++ b/drivers/rtc/rtc-da906x.c
@@ -0,0 +1,379 @@
+/*
+ * Real Time Clock driver for DA906x PMIC family
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/init.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/rtc.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/mfd/da906x/registers.h>
+#include <linux/mfd/da906x/core.h>
+
+#define YEARS_TO_DA906X(year)		((year) - 100)
+#define MONTHS_TO_DA906X(month)		((month) + 1)
+#define YEARS_FROM_DA906X(year)		((year) + 100)
+#define MONTHS_FROM_DA906X(month)	((month) - 1)
+
+#define CLOCK_DATA_LEN	(DA906X_REG_COUNT_Y - DA906X_REG_COUNT_S + 1)
+#define ALARM_DATA_LEN	(DA906X_REG_ALARM_Y - DA906X_REG_ALARM_MI + 1)
+enum {
+	DATA_SEC = 0,
+	DATA_MIN,
+	DATA_HOUR,
+	DATA_DAY,
+	DATA_MONTH,
+	DATA_YEAR,
+};
+
+struct da906x_rtc {
+	struct rtc_device	*rtc_dev;
+	struct da906x		*hw;
+	int			irq_alarm;
+	int			irq_tick;
+
+	/* Config flag */
+	int			tick_wake;
+
+	/* Used to expand alarm precision from minutes up to seconds
+	   using hardware ticks */
+	unsigned int		alarmSecs;
+	unsigned int		alarmTicks;
+};
+
+static void da906x_data_to_tm(u8 *data, struct rtc_time *tm)
+{
+	tm->tm_sec = data[DATA_SEC] & DA906X_COUNT_SEC_MASK;
+	tm->tm_min = data[DATA_MIN] & DA906X_COUNT_MIN_MASK;
+	tm->tm_hour = data[DATA_HOUR] & DA906X_COUNT_HOUR_MASK;
+	tm->tm_mday = data[DATA_DAY] & DA906X_COUNT_DAY_MASK;
+	tm->tm_mon = MONTHS_FROM_DA906X(data[DATA_MONTH] &
+					 DA906X_COUNT_MONTH_MASK);
+	tm->tm_year = YEARS_FROM_DA906X(data[DATA_YEAR] &
+					 DA906X_COUNT_YEAR_MASK);
+}
+
+static void da906x_tm_to_data(struct rtc_time *tm, u8 *data)
+{
+	data[DATA_SEC] &= ~DA906X_COUNT_SEC_MASK;
+	data[DATA_SEC] |= tm->tm_sec & DA906X_COUNT_SEC_MASK;
+	data[DATA_MIN] &= ~DA906X_COUNT_MIN_MASK;
+	data[DATA_MIN] |= tm->tm_min & DA906X_COUNT_MIN_MASK;
+	data[DATA_HOUR] &= ~DA906X_COUNT_HOUR_MASK;
+	data[DATA_HOUR] |= tm->tm_hour & DA906X_COUNT_HOUR_MASK;
+	data[DATA_DAY] &= ~DA906X_COUNT_DAY_MASK;
+	data[DATA_DAY] |= tm->tm_mday & DA906X_COUNT_DAY_MASK;
+	data[DATA_MONTH] &= ~DA906X_COUNT_MONTH_MASK;
+	data[DATA_MONTH] |= MONTHS_TO_DA906X(tm->tm_mon) &
+			    DA906X_COUNT_MONTH_MASK;
+	data[DATA_YEAR] &= ~DA906X_COUNT_YEAR_MASK;
+	data[DATA_YEAR] |= YEARS_TO_DA906X(tm->tm_year) &
+			   DA906X_COUNT_YEAR_MASK;
+}
+
+#define DA906X_ALARM_DELAY	INT_MAX
+static int da906x_rtc_test_delay(struct rtc_time *alarm, struct rtc_time *cur)
+{
+	unsigned long a_time, c_time;
+
+	rtc_tm_to_time(alarm, &a_time);
+	rtc_tm_to_time(cur, &c_time);
+
+	/* Alarm time has already passed */
+	if (a_time < c_time)
+		return -1;
+
+	/* If alarm is set for current minute, return ticks to count down.
+	   If alarm is set for following minutes, return DA906X_ALARM_DELAY
+	   to set alarm first.
+	   But when it is less than 2 seconds for the former to become true,
+	   return ticks, because alarm needs some time to synchronise. */
+	if (a_time - c_time < alarm->tm_sec + 2)
+		return a_time - c_time;
+	else
+		return DA906X_ALARM_DELAY;
+}
+
+static int da906x_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN];
+	int ret;
+
+	ret = da906x_block_read(rtc->hw,
+				DA906X_REG_COUNT_S, CLOCK_DATA_LEN, data);
+	if (ret < 0)
+		return ret;
+
+	/* Check, if RTC logic is initialised */
+	if (!(data[DATA_SEC] & DA906X_RTC_READ))
+		return -EBUSY;
+
+	da906x_data_to_tm(data, tm);
+
+	return rtc_valid_tm(tm);
+}
+
+static int da906x_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN] = { [0 ... (CLOCK_DATA_LEN - 1)] = 0 };
+	int ret;
+
+	da906x_tm_to_data(tm, data);
+
+	ret = da906x_block_write(rtc->hw,
+				 DA906X_REG_COUNT_S, CLOCK_DATA_LEN, data);
+
+	return ret;
+}
+
+static int da906x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN];
+	int ret;
+
+	ret = da906x_block_read(rtc->hw, DA906X_REG_ALARM_MI, ALARM_DATA_LEN,
+				&data[DATA_MIN]);
+	if (ret < 0)
+		return ret;
+
+	da906x_data_to_tm(data, &alrm->time);
+	alrm->time.tm_sec = rtc->alarmSecs;
+	alrm->enabled = !!(data[DATA_YEAR] & DA906X_ALARM_ON);
+
+	/* If there is no ticks left to count down and RTC event is
+	   not processed yet, indicate pending */
+	if (rtc->alarmTicks == 0) {
+		ret = da906x_reg_read(rtc->hw, DA906X_REG_EVENT_A);
+		if (ret < 0)
+			return ret;
+		if (ret & (DA906X_E_ALARM | DA906X_E_TICK))
+			alrm->pending = 1;
+	} else {
+		alrm->pending = 0;
+	}
+
+	return 0;
+}
+
+static int da906x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN] = { [0 ... (CLOCK_DATA_LEN - 1)] = 0 };
+	struct rtc_time cur_tm;
+	int cmp_val;
+	int ret;
+
+	data[DATA_MIN] = DA906X_ALARM_STATUS_ALARM;
+	data[DATA_MONTH] = DA906X_TICK_TYPE_SEC;
+	if (rtc->tick_wake)
+		data[DATA_MONTH] |= DA906X_TICK_WAKE;
+
+	ret = da906x_rtc_read_time(dev, &cur_tm);
+	if (ret < 0)
+		return ret;
+
+	if (alrm->enabled) {
+		cmp_val = da906x_rtc_test_delay(&alrm->time, &cur_tm);
+		if (cmp_val == DA906X_ALARM_DELAY) {
+			/* Set alarm for longer delay */
+			data[DATA_YEAR] |= DA906X_ALARM_ON;
+		} else if (cmp_val > 0) {
+			/* Count ticks for shorter delay */
+			rtc->alarmTicks = cmp_val - 1;
+			data[DATA_YEAR] |= DA906X_TICK_ON;
+		} else if (cmp_val == 0) {
+			/* Just about time - report event */
+			rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF);
+		}
+	}
+
+	da906x_tm_to_data(&alrm->time, data);
+	rtc->alarmSecs = alrm->time.tm_sec;
+
+	return da906x_block_write(rtc->hw, DA906X_REG_ALARM_MI, ALARM_DATA_LEN,
+				 &data[DATA_MIN]);
+}
+
+static int da906x_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	struct rtc_wkalrm alrm;
+	int ret;
+
+	ret = da906x_reg_read(rtc->hw, DATA_YEAR);
+	if (ret < 0)
+		return ret;
+
+	if (enabled) {
+		/* Enable alarm, if it is not enabled already */
+		if (!(ret & (DA906X_ALARM_ON | DA906X_TICK_ON))) {
+			ret = da906x_rtc_read_alarm(dev, &alrm);
+			if (ret < 0)
+				return ret;
+
+			alrm.enabled = 1;
+			ret = da906x_rtc_set_alarm(dev, &alrm);
+		}
+	} else {
+		ret = da906x_reg_clear_bits(rtc->hw, DA906X_REG_ALARM_Y,
+					    DA906X_ALARM_ON);
+	}
+
+	return ret;
+}
+
+/* On alarm interrupt, start to count ticks to enable seconds precision
+   (if alarm seconds != 0). */
+static irqreturn_t da906x_alarm_event(int irq, void *data)
+{
+	struct da906x_rtc *rtc = data;
+
+	if (rtc->alarmSecs) {
+		rtc->alarmTicks = rtc->alarmSecs - 1;
+		da906x_reg_update(rtc->hw, DA906X_REG_ALARM_Y,
+				  DA906X_ALARM_ON | DA906X_TICK_ON,
+				  DA906X_TICK_ON);
+	} else {
+		da906x_reg_clear_bits(rtc->hw, DA906X_REG_ALARM_Y,
+				      DA906X_ALARM_ON);
+		rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF);
+	}
+
+	return IRQ_HANDLED;
+}
+
+/* On tick interrupt, count down seconds left to timeout */
+static irqreturn_t da906x_tick_event(int irq, void *data)
+{
+	struct da906x_rtc *rtc = data;
+
+	if (rtc->alarmTicks-- == 0) {
+		da906x_reg_clear_bits(rtc->hw,
+				      DA906X_REG_ALARM_Y, DA906X_TICK_ON);
+		rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_UF);
+	}
+
+	return IRQ_HANDLED;
+}
+
+static const struct rtc_class_ops da906x_rtc_ops = {
+	.read_time = da906x_rtc_read_time,
+	.set_time = da906x_rtc_set_time,
+	.read_alarm = da906x_rtc_read_alarm,
+	.set_alarm = da906x_rtc_set_alarm,
+	.alarm_irq_enable = da906x_rtc_alarm_irq_enable,
+};
+
+static __devinit int da906x_rtc_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_rtc *rtc;
+	int ret;
+	int alarm_mo;
+
+	/* Enable RTC hardware */
+	ret = da906x_reg_set_bits(da906x, DA906X_REG_CONTROL_E, DA906X_RTC_EN);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to enable RTC.\n");
+		return ret;
+	}
+
+	ret = da906x_reg_set_bits(da906x, DA906X_REG_EN_32K, DA906X_CRYSTAL);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to run 32 KHz OSC.\n");
+		return ret;
+	}
+
+	ret = da906x_reg_read(da906x, DA906X_REG_ALARM_MO);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to read RTC register.\n");
+		return ret;
+	}
+	alarm_mo = ret;
+
+	/* Register RTC device */
+	rtc = devm_kzalloc(&pdev->dev, sizeof *rtc, GFP_KERNEL);
+	if (!rtc)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, rtc);
+
+	rtc->hw = da906x;
+	rtc->rtc_dev = rtc_device_register(DA906X_DRVNAME_RTC, &pdev->dev,
+					   &da906x_rtc_ops, THIS_MODULE);
+	if (IS_ERR(rtc->rtc_dev)) {
+		dev_err(&pdev->dev, "Failed to register RTC device: %ld\n",
+			PTR_ERR(rtc->rtc_dev));
+		return PTR_ERR(rtc->rtc_dev);
+	}
+
+	if (alarm_mo & DA906X_TICK_WAKE)
+		rtc->tick_wake = 1;
+
+	/* Register interrupts. Complain on errors but let device
+	   to be registered at least for date/time. */
+	rtc->irq_alarm = platform_get_irq_byname(pdev, "ALARM");
+	ret = request_threaded_irq(rtc->irq_alarm, NULL, da906x_alarm_event,
+				IRQF_TRIGGER_LOW | IRQF_ONESHOT, "ALARM", rtc);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request ALARM IRQ.\n");
+		rtc->irq_alarm = -ENXIO;
+		return 0;
+	}
+
+	rtc->irq_tick = platform_get_irq_byname(pdev, "TICK");
+	ret = request_threaded_irq(rtc->irq_tick, NULL, da906x_tick_event,
+			IRQF_TRIGGER_RISING | IRQF_ONESHOT, "TICK", rtc);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request TICK IRQ.\n");
+		rtc->irq_tick = -ENXIO;
+	}
+
+	return 0;
+}
+
+static int __devexit da906x_rtc_remove(struct platform_device *pdev)
+{
+	struct da906x_rtc *rtc = platform_get_drvdata(pdev);
+
+	if (rtc->irq_alarm >= 0)
+		free_irq(rtc->irq_alarm, rtc);
+
+	if (rtc->irq_tick >= 0)
+		free_irq(rtc->irq_tick, rtc);
+
+	rtc_device_unregister(rtc->rtc_dev);
+	return 0;
+}
+
+static struct platform_driver da906x_rtc_driver = {
+	.probe		= da906x_rtc_probe,
+	.remove		= __devexit_p(da906x_rtc_remove),
+	.driver		= {
+		.name	= DA906X_DRVNAME_RTC,
+		.owner	= THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_rtc_driver);
+
+/* Module information */
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>");
+MODULE_DESCRIPTION("DA906x RTC driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DA906X_DRVNAME_RTC);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [lm-sensors] [RFC PATCH 3/8] rtc: Add RTC driver for DA906x PMIC.
@ 2012-08-24 14:00       ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 14:00 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

DA906x RTC driver supports date/time and alarm.

In hardware, PMIC supports alarm setting with a resolution of one minute and
tick event (every second update event). The driver combines it, providing alarm
with one second resolution.

The driver requires MFD core driver for operation.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/rtc/Kconfig      |    7 +
 drivers/rtc/Makefile     |    1 +
 drivers/rtc/rtc-da906x.c |  379 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 387 insertions(+), 0 deletions(-)
 create mode 100644 drivers/rtc/rtc-da906x.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index fabc99a..e6037cd 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -571,6 +571,13 @@ config RTC_DRV_DA9052
 	  Say y here to support the RTC driver for Dialog Semiconductor
 	  DA9052-BC and DA9053-AA/Bx PMICs.
 
+config RTC_DRV_DA906X
+	tristate "Dialog DA906X RTC"
+	depends on MFD_DA906X
+	help
+	  Say y here to support the RTC driver for
+	  Dialog Semiconductor DA906x PMIC.
+
 config RTC_DRV_EFI
 	tristate "EFI RTC"
 	depends on IA64
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 0d5b2b6..d9c1e9f 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_RTC_DRV_BQ4802)	+= rtc-bq4802.o
 obj-$(CONFIG_RTC_DRV_CMOS)	+= rtc-cmos.o
 obj-$(CONFIG_RTC_DRV_COH901331)	+= rtc-coh901331.o
 obj-$(CONFIG_RTC_DRV_DA9052)	+= rtc-da9052.o
+obj-$(CONFIG_RTC_DRV_DA906X)	+= rtc-da906x.o
 obj-$(CONFIG_RTC_DRV_DAVINCI)	+= rtc-davinci.o
 obj-$(CONFIG_RTC_DRV_DM355EVM)	+= rtc-dm355evm.o
 obj-$(CONFIG_RTC_DRV_VRTC)	+= rtc-mrst.o
diff --git a/drivers/rtc/rtc-da906x.c b/drivers/rtc/rtc-da906x.c
new file mode 100644
index 0000000..0b4fecc
--- /dev/null
+++ b/drivers/rtc/rtc-da906x.c
@@ -0,0 +1,379 @@
+/*
+ * Real Time Clock driver for DA906x PMIC family
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/init.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/rtc.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/mfd/da906x/registers.h>
+#include <linux/mfd/da906x/core.h>
+
+#define YEARS_TO_DA906X(year)		((year) - 100)
+#define MONTHS_TO_DA906X(month)		((month) + 1)
+#define YEARS_FROM_DA906X(year)		((year) + 100)
+#define MONTHS_FROM_DA906X(month)	((month) - 1)
+
+#define CLOCK_DATA_LEN	(DA906X_REG_COUNT_Y - DA906X_REG_COUNT_S + 1)
+#define ALARM_DATA_LEN	(DA906X_REG_ALARM_Y - DA906X_REG_ALARM_MI + 1)
+enum {
+	DATA_SEC = 0,
+	DATA_MIN,
+	DATA_HOUR,
+	DATA_DAY,
+	DATA_MONTH,
+	DATA_YEAR,
+};
+
+struct da906x_rtc {
+	struct rtc_device	*rtc_dev;
+	struct da906x		*hw;
+	int			irq_alarm;
+	int			irq_tick;
+
+	/* Config flag */
+	int			tick_wake;
+
+	/* Used to expand alarm precision from minutes up to seconds
+	   using hardware ticks */
+	unsigned int		alarmSecs;
+	unsigned int		alarmTicks;
+};
+
+static void da906x_data_to_tm(u8 *data, struct rtc_time *tm)
+{
+	tm->tm_sec = data[DATA_SEC] & DA906X_COUNT_SEC_MASK;
+	tm->tm_min = data[DATA_MIN] & DA906X_COUNT_MIN_MASK;
+	tm->tm_hour = data[DATA_HOUR] & DA906X_COUNT_HOUR_MASK;
+	tm->tm_mday = data[DATA_DAY] & DA906X_COUNT_DAY_MASK;
+	tm->tm_mon = MONTHS_FROM_DA906X(data[DATA_MONTH] &
+					 DA906X_COUNT_MONTH_MASK);
+	tm->tm_year = YEARS_FROM_DA906X(data[DATA_YEAR] &
+					 DA906X_COUNT_YEAR_MASK);
+}
+
+static void da906x_tm_to_data(struct rtc_time *tm, u8 *data)
+{
+	data[DATA_SEC] &= ~DA906X_COUNT_SEC_MASK;
+	data[DATA_SEC] |= tm->tm_sec & DA906X_COUNT_SEC_MASK;
+	data[DATA_MIN] &= ~DA906X_COUNT_MIN_MASK;
+	data[DATA_MIN] |= tm->tm_min & DA906X_COUNT_MIN_MASK;
+	data[DATA_HOUR] &= ~DA906X_COUNT_HOUR_MASK;
+	data[DATA_HOUR] |= tm->tm_hour & DA906X_COUNT_HOUR_MASK;
+	data[DATA_DAY] &= ~DA906X_COUNT_DAY_MASK;
+	data[DATA_DAY] |= tm->tm_mday & DA906X_COUNT_DAY_MASK;
+	data[DATA_MONTH] &= ~DA906X_COUNT_MONTH_MASK;
+	data[DATA_MONTH] |= MONTHS_TO_DA906X(tm->tm_mon) &
+			    DA906X_COUNT_MONTH_MASK;
+	data[DATA_YEAR] &= ~DA906X_COUNT_YEAR_MASK;
+	data[DATA_YEAR] |= YEARS_TO_DA906X(tm->tm_year) &
+			   DA906X_COUNT_YEAR_MASK;
+}
+
+#define DA906X_ALARM_DELAY	INT_MAX
+static int da906x_rtc_test_delay(struct rtc_time *alarm, struct rtc_time *cur)
+{
+	unsigned long a_time, c_time;
+
+	rtc_tm_to_time(alarm, &a_time);
+	rtc_tm_to_time(cur, &c_time);
+
+	/* Alarm time has already passed */
+	if (a_time < c_time)
+		return -1;
+
+	/* If alarm is set for current minute, return ticks to count down.
+	   If alarm is set for following minutes, return DA906X_ALARM_DELAY
+	   to set alarm first.
+	   But when it is less than 2 seconds for the former to become true,
+	   return ticks, because alarm needs some time to synchronise. */
+	if (a_time - c_time < alarm->tm_sec + 2)
+		return a_time - c_time;
+	else
+		return DA906X_ALARM_DELAY;
+}
+
+static int da906x_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN];
+	int ret;
+
+	ret = da906x_block_read(rtc->hw,
+				DA906X_REG_COUNT_S, CLOCK_DATA_LEN, data);
+	if (ret < 0)
+		return ret;
+
+	/* Check, if RTC logic is initialised */
+	if (!(data[DATA_SEC] & DA906X_RTC_READ))
+		return -EBUSY;
+
+	da906x_data_to_tm(data, tm);
+
+	return rtc_valid_tm(tm);
+}
+
+static int da906x_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN] = { [0 ... (CLOCK_DATA_LEN - 1)] = 0 };
+	int ret;
+
+	da906x_tm_to_data(tm, data);
+
+	ret = da906x_block_write(rtc->hw,
+				 DA906X_REG_COUNT_S, CLOCK_DATA_LEN, data);
+
+	return ret;
+}
+
+static int da906x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN];
+	int ret;
+
+	ret = da906x_block_read(rtc->hw, DA906X_REG_ALARM_MI, ALARM_DATA_LEN,
+				&data[DATA_MIN]);
+	if (ret < 0)
+		return ret;
+
+	da906x_data_to_tm(data, &alrm->time);
+	alrm->time.tm_sec = rtc->alarmSecs;
+	alrm->enabled = !!(data[DATA_YEAR] & DA906X_ALARM_ON);
+
+	/* If there is no ticks left to count down and RTC event is
+	   not processed yet, indicate pending */
+	if (rtc->alarmTicks = 0) {
+		ret = da906x_reg_read(rtc->hw, DA906X_REG_EVENT_A);
+		if (ret < 0)
+			return ret;
+		if (ret & (DA906X_E_ALARM | DA906X_E_TICK))
+			alrm->pending = 1;
+	} else {
+		alrm->pending = 0;
+	}
+
+	return 0;
+}
+
+static int da906x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	u8 data[CLOCK_DATA_LEN] = { [0 ... (CLOCK_DATA_LEN - 1)] = 0 };
+	struct rtc_time cur_tm;
+	int cmp_val;
+	int ret;
+
+	data[DATA_MIN] = DA906X_ALARM_STATUS_ALARM;
+	data[DATA_MONTH] = DA906X_TICK_TYPE_SEC;
+	if (rtc->tick_wake)
+		data[DATA_MONTH] |= DA906X_TICK_WAKE;
+
+	ret = da906x_rtc_read_time(dev, &cur_tm);
+	if (ret < 0)
+		return ret;
+
+	if (alrm->enabled) {
+		cmp_val = da906x_rtc_test_delay(&alrm->time, &cur_tm);
+		if (cmp_val = DA906X_ALARM_DELAY) {
+			/* Set alarm for longer delay */
+			data[DATA_YEAR] |= DA906X_ALARM_ON;
+		} else if (cmp_val > 0) {
+			/* Count ticks for shorter delay */
+			rtc->alarmTicks = cmp_val - 1;
+			data[DATA_YEAR] |= DA906X_TICK_ON;
+		} else if (cmp_val = 0) {
+			/* Just about time - report event */
+			rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF);
+		}
+	}
+
+	da906x_tm_to_data(&alrm->time, data);
+	rtc->alarmSecs = alrm->time.tm_sec;
+
+	return da906x_block_write(rtc->hw, DA906X_REG_ALARM_MI, ALARM_DATA_LEN,
+				 &data[DATA_MIN]);
+}
+
+static int da906x_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
+{
+	struct da906x_rtc *rtc = dev_get_drvdata(dev);
+	struct rtc_wkalrm alrm;
+	int ret;
+
+	ret = da906x_reg_read(rtc->hw, DATA_YEAR);
+	if (ret < 0)
+		return ret;
+
+	if (enabled) {
+		/* Enable alarm, if it is not enabled already */
+		if (!(ret & (DA906X_ALARM_ON | DA906X_TICK_ON))) {
+			ret = da906x_rtc_read_alarm(dev, &alrm);
+			if (ret < 0)
+				return ret;
+
+			alrm.enabled = 1;
+			ret = da906x_rtc_set_alarm(dev, &alrm);
+		}
+	} else {
+		ret = da906x_reg_clear_bits(rtc->hw, DA906X_REG_ALARM_Y,
+					    DA906X_ALARM_ON);
+	}
+
+	return ret;
+}
+
+/* On alarm interrupt, start to count ticks to enable seconds precision
+   (if alarm seconds != 0). */
+static irqreturn_t da906x_alarm_event(int irq, void *data)
+{
+	struct da906x_rtc *rtc = data;
+
+	if (rtc->alarmSecs) {
+		rtc->alarmTicks = rtc->alarmSecs - 1;
+		da906x_reg_update(rtc->hw, DA906X_REG_ALARM_Y,
+				  DA906X_ALARM_ON | DA906X_TICK_ON,
+				  DA906X_TICK_ON);
+	} else {
+		da906x_reg_clear_bits(rtc->hw, DA906X_REG_ALARM_Y,
+				      DA906X_ALARM_ON);
+		rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF);
+	}
+
+	return IRQ_HANDLED;
+}
+
+/* On tick interrupt, count down seconds left to timeout */
+static irqreturn_t da906x_tick_event(int irq, void *data)
+{
+	struct da906x_rtc *rtc = data;
+
+	if (rtc->alarmTicks-- = 0) {
+		da906x_reg_clear_bits(rtc->hw,
+				      DA906X_REG_ALARM_Y, DA906X_TICK_ON);
+		rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_UF);
+	}
+
+	return IRQ_HANDLED;
+}
+
+static const struct rtc_class_ops da906x_rtc_ops = {
+	.read_time = da906x_rtc_read_time,
+	.set_time = da906x_rtc_set_time,
+	.read_alarm = da906x_rtc_read_alarm,
+	.set_alarm = da906x_rtc_set_alarm,
+	.alarm_irq_enable = da906x_rtc_alarm_irq_enable,
+};
+
+static __devinit int da906x_rtc_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_rtc *rtc;
+	int ret;
+	int alarm_mo;
+
+	/* Enable RTC hardware */
+	ret = da906x_reg_set_bits(da906x, DA906X_REG_CONTROL_E, DA906X_RTC_EN);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to enable RTC.\n");
+		return ret;
+	}
+
+	ret = da906x_reg_set_bits(da906x, DA906X_REG_EN_32K, DA906X_CRYSTAL);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to run 32 KHz OSC.\n");
+		return ret;
+	}
+
+	ret = da906x_reg_read(da906x, DA906X_REG_ALARM_MO);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to read RTC register.\n");
+		return ret;
+	}
+	alarm_mo = ret;
+
+	/* Register RTC device */
+	rtc = devm_kzalloc(&pdev->dev, sizeof *rtc, GFP_KERNEL);
+	if (!rtc)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, rtc);
+
+	rtc->hw = da906x;
+	rtc->rtc_dev = rtc_device_register(DA906X_DRVNAME_RTC, &pdev->dev,
+					   &da906x_rtc_ops, THIS_MODULE);
+	if (IS_ERR(rtc->rtc_dev)) {
+		dev_err(&pdev->dev, "Failed to register RTC device: %ld\n",
+			PTR_ERR(rtc->rtc_dev));
+		return PTR_ERR(rtc->rtc_dev);
+	}
+
+	if (alarm_mo & DA906X_TICK_WAKE)
+		rtc->tick_wake = 1;
+
+	/* Register interrupts. Complain on errors but let device
+	   to be registered at least for date/time. */
+	rtc->irq_alarm = platform_get_irq_byname(pdev, "ALARM");
+	ret = request_threaded_irq(rtc->irq_alarm, NULL, da906x_alarm_event,
+				IRQF_TRIGGER_LOW | IRQF_ONESHOT, "ALARM", rtc);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request ALARM IRQ.\n");
+		rtc->irq_alarm = -ENXIO;
+		return 0;
+	}
+
+	rtc->irq_tick = platform_get_irq_byname(pdev, "TICK");
+	ret = request_threaded_irq(rtc->irq_tick, NULL, da906x_tick_event,
+			IRQF_TRIGGER_RISING | IRQF_ONESHOT, "TICK", rtc);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request TICK IRQ.\n");
+		rtc->irq_tick = -ENXIO;
+	}
+
+	return 0;
+}
+
+static int __devexit da906x_rtc_remove(struct platform_device *pdev)
+{
+	struct da906x_rtc *rtc = platform_get_drvdata(pdev);
+
+	if (rtc->irq_alarm >= 0)
+		free_irq(rtc->irq_alarm, rtc);
+
+	if (rtc->irq_tick >= 0)
+		free_irq(rtc->irq_tick, rtc);
+
+	rtc_device_unregister(rtc->rtc_dev);
+	return 0;
+}
+
+static struct platform_driver da906x_rtc_driver = {
+	.probe		= da906x_rtc_probe,
+	.remove		= __devexit_p(da906x_rtc_remove),
+	.driver		= {
+		.name	= DA906X_DRVNAME_RTC,
+		.owner	= THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_rtc_driver);
+
+/* Module information */
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>");
+MODULE_DESCRIPTION("DA906x RTC driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DA906X_DRVNAME_RTC);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [RFC PATCH 4/8] hwmon: Add DA906x hardware monitoring support.
  2012-08-24 14:00       ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-24 14:05         ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 14:05 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

DA906x PMIC provides ADC for voltage and temperature monitoring.

The driver provides results of following ADC channels:
 - in0 - system voltage (2500 - 5500 mV)
 - in1 - universal voltage channel #1 (0 - 2500 mV)
 - in2 - universal voltage channel #2 (0 - 2500 mV)
 - in3 - universal voltage channel #3 (0 - 2500 mV)
 - in4 - backup battery voltage (0 - 5000 mV)
 - temp1 - PMIC internal junction temperature (-88 - 333 Celcius degrees)

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/hwmon/Kconfig        |    6 +
 drivers/hwmon/Makefile       |    1 +
 drivers/hwmon/da906x-hwmon.c |  393 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 400 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/da906x-hwmon.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index b0a2e4c..7abc9a0 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1373,6 +1373,12 @@ config SENSORS_WM8350
 	  This driver can also be built as a module.  If so, the module
 	  will be called wm8350-hwmon.
 
+config SENSORS_DA906X
+	tristate "DA906X HWMON device drivers"
+	depends on MFD_DA906X
+	help
+	  Support for the HWMON DA906X device driver.
+
 config SENSORS_ULTRA45
 	tristate "Sun Ultra45 PIC16F747"
 	depends on SPARC64
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 7aa9811..ffbe151 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_SENSORS_ASC7621)	+= asc7621.o
 obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
 obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
 obj-$(CONFIG_SENSORS_DA9052_ADC)+= da9052-hwmon.o
+obj-$(CONFIG_SENSORS_DA906X)	+= da906x-hwmon.o
 obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
 obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
diff --git a/drivers/hwmon/da906x-hwmon.c b/drivers/hwmon/da906x-hwmon.c
new file mode 100644
index 0000000..8ece931
--- /dev/null
+++ b/drivers/hwmon/da906x-hwmon.c
@@ -0,0 +1,393 @@
+/*
+ * HW Monitor support for Dialog DA906X PMIC series
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>,
+ *         Michal Hajduk <michal.hajduk@diasemi.com>
+ *
+ *  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/err.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/platform_device.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+
+/* ADC resolutions for manual and auto modes */
+#define DA906X_ADC_RES		\
+		(1 << (DA906X_ADC_RES_L_BITS + DA906X_ADC_RES_M_BITS))
+#define DA906X_ADC_MAX		(DA906X_ADC_RES - 1)
+#define	DA906X_ADC_AUTO_RES	(1 << DA906X_ADC_RES_M_BITS)
+#define	DA906X_ADC_AUTO_MAX	(DA906X_ADC_AUTO_RES - 1)
+
+/* Define interpolation table to calculate ADC values  */
+struct i_table {
+	int x0;
+	int a;
+	int b;
+};
+#define ILINE(x1, x2, y1, y2)	{ \
+		.x0 = (x1), \
+		.a = ((y2) - (y1)) * DA906X_ADC_RES / ((x2) - (x1)), \
+		.b = (y1) - ((y2) - (y1)) * (x1) / ((x2) - (x1)), \
+	}
+
+struct channel_info {
+	const char *name;
+	const struct i_table *tbl;
+	int tbl_max;
+	u16 reg_auto_en;
+};
+
+enum da906x_adc {
+	DA906X_VSYS,
+	DA906X_ADCIN1,
+	DA906X_ADCIN2,
+	DA906X_ADCIN3,
+	DA906X_TJUNC,
+	DA906X_VBBAT,
+
+	DA906X_CHAN_NUM
+};
+
+static const struct i_table vsys_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 2500, 5500)
+};
+
+static const struct i_table adcin_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 0, 2500)
+};
+
+static const struct i_table tjunc_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 333, -86)
+};
+
+static const struct i_table vbbat_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 0, 5000)
+};
+
+static const struct channel_info da906x_channels[] = {
+	[DA906X_VSYS]	= { "VSYS",
+			    vsys_tbl, ARRAY_SIZE(vsys_tbl) - 1,
+			    DA906X_REG_VSYS_RES },
+	[DA906X_ADCIN1]	= { "ADCIN1",
+			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
+			    DA906X_REG_ADCIN1_RES },
+	[DA906X_ADCIN2]	= { "ADCIN2",
+			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
+			    DA906X_REG_ADCIN2_RES },
+	[DA906X_ADCIN3]	= { "ADCIN3",
+			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
+			    DA906X_REG_ADCIN3_RES },
+	[DA906X_TJUNC]	= { "TJUNC",
+			    tjunc_tbl,	ARRAY_SIZE(tjunc_tbl) - 1 },
+	[DA906X_VBBAT]	= { "VBBAT",
+			    vbbat_tbl,	ARRAY_SIZE(vbbat_tbl) - 1}
+};
+#define DA906X_ADC_AUTO_MODE_SUPPORT_MASK	(DA906X_ADC_AUTO_VSYS_EN | \
+						 DA906X_ADC_AUTO_AD1_EN | \
+						 DA906X_ADC_AUTO_AD2_EN | \
+						 DA906X_ADC_AUTO_AD3_EN)
+
+struct da906x_hwmon {
+	struct da906x *da906x;
+	struct device *class_dev;
+	struct completion man_adc_rdy;	/* Manual read completion flag */
+	struct mutex hwmon_mutex;	/* Queue concurent manual reads */
+	int irq;
+	u8 adc_auto_en;     /* Bitmask of channels with auto mode enabled */
+	s8 tjunc_offset;    /* Calibration offset for junction temperature */
+};
+
+int da906x_adc_convert(int channel, int x)
+{
+	const struct channel_info *info = &da906x_channels[channel];
+	int i, ret;
+
+	for (i = info->tbl_max; i > 0; i--)
+		if (info->tbl[i].x0 <= x)
+			break;
+
+	ret = info->tbl[i].a * x;
+	if (ret >= 0)
+		ret += DA906X_ADC_RES / 2;
+	else
+		ret -= DA906X_ADC_RES / 2;
+	ret = ret / DA906X_ADC_RES + info->tbl[i].b;
+	return ret;
+}
+
+static int da906x_adc_manual_read(struct da906x_hwmon *hwmon, int channel)
+{
+	int ret;
+	u8 data[2];
+
+	mutex_lock(&hwmon->hwmon_mutex);
+
+	init_completion(&hwmon->man_adc_rdy);
+
+	/* Start measurment on selected channel */
+	data[0] = (channel << DA906X_ADC_MUX_SHIFT) & DA906X_ADC_MUX_MASK;
+	data[0] |= DA906X_ADC_MAN;
+	ret = da906x_reg_update(hwmon->da906x, DA906X_REG_ADC_MAN,
+				DA906X_ADC_MUX_MASK | DA906X_ADC_MAN, data[0]);
+	if (ret < 0)
+		goto out;
+
+	/* Wait for interrupt from ADC */
+	ret = wait_for_completion_timeout(&hwmon->man_adc_rdy,
+					  msecs_to_jiffies(1000));
+	if (ret == 0) {
+		ret = -EBUSY;
+		goto out;
+	}
+
+	/* Get results */
+	ret = da906x_block_read(hwmon->da906x, DA906X_REG_ADC_RES_L, 2, data);
+	if (ret < 0)
+		goto out;
+	ret = (data[0] & DA906X_ADC_RES_L_MASK) >> DA906X_ADC_RES_L_SHIFT;
+	ret |= data[1] << DA906X_ADC_RES_L_BITS;
+out:
+	mutex_unlock(&hwmon->hwmon_mutex);
+	return ret;
+}
+
+static int da906x_adc_auto_read(struct da906x *da906x, int channel)
+{
+	const struct channel_info *info = &da906x_channels[channel];
+
+	return da906x_reg_read(da906x, info->reg_auto_en);
+}
+
+static irqreturn_t da906x_hwmon_irq_handler(int irq, void *irq_data)
+{
+	struct da906x_hwmon *hwmon = irq_data;
+
+	complete(&hwmon->man_adc_rdy);
+
+	return IRQ_HANDLED;
+}
+
+static ssize_t da906x_adc_read(struct device *dev,
+			       struct device_attribute *devattr, char *buf)
+{
+	struct da906x_hwmon *hwmon = dev_get_drvdata(dev);
+	int channel = to_sensor_dev_attr(devattr)->index;
+	int val;
+
+	if (hwmon->adc_auto_en & (1 << channel)) {
+		val = da906x_adc_auto_read(hwmon->da906x, channel);
+		if (val < 0)
+			return val;
+
+		val *= DA906X_ADC_RES / DA906X_ADC_AUTO_RES;
+		val = da906x_adc_convert(channel, val);
+	} else {
+		val = da906x_adc_manual_read(hwmon, channel);
+		if (val < 0)
+			return val;
+
+		if (channel == DA906X_TJUNC)
+			val += hwmon->tjunc_offset;
+		val = da906x_adc_convert(channel, val);
+	}
+
+	return sprintf(buf, "%d\n", val);
+}
+
+static ssize_t da906x_show_name(struct device *dev,
+	struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, DA906X_DRVNAME_HWMON "\n");
+}
+
+static ssize_t da906x_show_label(struct device *dev,
+				 struct device_attribute *devattr, char *buf)
+{
+	const struct channel_info *info;
+
+	info = &da906x_channels[to_sensor_dev_attr(devattr)->index];
+	return sprintf(buf, "%s\n", info->name);
+}
+
+/* Vsys voltage */
+static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_VSYS);
+static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_VSYS);
+
+/* Universal ADC channel #1 */
+static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_ADCIN1);
+static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_ADCIN1);
+
+/* Universal ADC channel #2 */
+static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO,
+			  da906x_adc_read, NULL,
+			  DA906X_ADCIN2);
+static SENSOR_DEVICE_ATTR(in2_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_ADCIN2);
+
+/* Universal ADC channel #3 */
+static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_ADCIN3);
+static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_ADCIN3);
+
+/* Backup battery voltage */
+static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_VBBAT);
+static SENSOR_DEVICE_ATTR(in4_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_VBBAT);
+
+/* Junction temperature */
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_TJUNC);
+
+static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_TJUNC);
+
+/* Device name */
+static DEVICE_ATTR(name, S_IRUGO, da906x_show_name, NULL);
+
+static struct attribute *da906x_attributes[] = {
+	&dev_attr_name.attr,
+	&sensor_dev_attr_in0_input.dev_attr.attr,
+	&sensor_dev_attr_in0_label.dev_attr.attr,
+	&sensor_dev_attr_in1_input.dev_attr.attr,
+	&sensor_dev_attr_in1_label.dev_attr.attr,
+	&sensor_dev_attr_in2_input.dev_attr.attr,
+	&sensor_dev_attr_in2_label.dev_attr.attr,
+	&sensor_dev_attr_in3_input.dev_attr.attr,
+	&sensor_dev_attr_in3_label.dev_attr.attr,
+	&sensor_dev_attr_in4_input.dev_attr.attr,
+	&sensor_dev_attr_in4_label.dev_attr.attr,
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_label.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group da906x_attr_group = {
+	.attrs = da906x_attributes,
+};
+
+static int __devinit da906x_hwmon_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_pdata *da906x_pdata = dev_get_platdata(da906x->dev);
+	struct da906x_hwmon *hwmon;
+	int ret;
+
+	hwmon = devm_kzalloc(&pdev->dev, sizeof(struct da906x_hwmon),
+			     GFP_KERNEL);
+	if (!hwmon)
+		return -ENOMEM;
+
+	mutex_init(&hwmon->hwmon_mutex);
+	init_completion(&hwmon->man_adc_rdy);
+	hwmon->da906x = da906x;
+
+	ret = da906x_reg_read(da906x, DA906X_REG_ADC_CONT);
+	if (ret < 0)
+		return ret;
+	hwmon->adc_auto_en = ret & DA906X_ADC_AUTO_MODE_SUPPORT_MASK;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN0_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_VSYS_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN0_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_VSYS_EN;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN1_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD1_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN1_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD1_EN;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN2_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD2_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN2_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD2_EN;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN3_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD3_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN3_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD3_EN;
+
+	ret = da906x_reg_update(da906x, DA906X_REG_ADC_CONT,
+				DA906X_ADC_AUTO_MODE_SUPPORT_MASK,
+				hwmon->adc_auto_en);
+	if (ret < 0)
+		return ret;
+
+	hwmon->class_dev = hwmon_device_register(&pdev->dev);
+	if (IS_ERR(hwmon->class_dev))
+		return PTR_ERR(hwmon->class_dev);
+
+	hwmon->irq = platform_get_irq_byname(pdev, DA906X_DRVNAME_HWMON);
+	ret = devm_request_threaded_irq(&pdev->dev, hwmon->irq, NULL,
+					da906x_hwmon_irq_handler,
+					IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+					"HWMON", hwmon);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request IRQ.\n");
+		goto err;
+	}
+
+	platform_set_drvdata(pdev, hwmon);
+
+	ret = da906x_reg_read(da906x, DA906X_REG_T_OFFSET);
+	if (ret < 0)
+		dev_warn(&pdev->dev, "Could not read temp1 callibration offset.\n");
+	else
+		hwmon->tjunc_offset = (s8)ret;
+
+	ret = sysfs_create_group(&pdev->dev.kobj, &da906x_attr_group);
+	if (ret)
+		goto err;
+
+	return 0;
+
+err:
+	hwmon_device_unregister(hwmon->class_dev);
+	return ret;
+}
+
+static int __devexit da906x_hwmon_remove(struct platform_device *pdev)
+{
+	struct da906x_hwmon *hwmon = platform_get_drvdata(pdev);
+
+	hwmon_device_unregister(hwmon->class_dev);
+	sysfs_remove_group(&pdev->dev.kobj, &da906x_attr_group);
+
+	return 0;
+}
+
+static struct platform_driver da906x_hwmon_driver = {
+	.probe = da906x_hwmon_probe,
+	.remove = __devexit_p(da906x_hwmon_remove),
+	.driver = {
+		.name = DA906X_DRVNAME_HWMON,
+		.owner = THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_hwmon_driver);
+
+MODULE_DESCRIPTION("DA906X Hardware monitoring");
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>, Michal Hajduk <michal.hajduk@diasemi.com>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("paltform:" DA906X_DRVNAME_HWMON);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [lm-sensors] [RFC PATCH 4/8] hwmon: Add DA906x hardware monitoring support.
@ 2012-08-24 14:05         ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 14:05 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

DA906x PMIC provides ADC for voltage and temperature monitoring.

The driver provides results of following ADC channels:
 - in0 - system voltage (2500 - 5500 mV)
 - in1 - universal voltage channel #1 (0 - 2500 mV)
 - in2 - universal voltage channel #2 (0 - 2500 mV)
 - in3 - universal voltage channel #3 (0 - 2500 mV)
 - in4 - backup battery voltage (0 - 5000 mV)
 - temp1 - PMIC internal junction temperature (-88 - 333 Celcius degrees)

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/hwmon/Kconfig        |    6 +
 drivers/hwmon/Makefile       |    1 +
 drivers/hwmon/da906x-hwmon.c |  393 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 400 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/da906x-hwmon.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index b0a2e4c..7abc9a0 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1373,6 +1373,12 @@ config SENSORS_WM8350
 	  This driver can also be built as a module.  If so, the module
 	  will be called wm8350-hwmon.
 
+config SENSORS_DA906X
+	tristate "DA906X HWMON device drivers"
+	depends on MFD_DA906X
+	help
+	  Support for the HWMON DA906X device driver.
+
 config SENSORS_ULTRA45
 	tristate "Sun Ultra45 PIC16F747"
 	depends on SPARC64
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 7aa9811..ffbe151 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_SENSORS_ASC7621)	+= asc7621.o
 obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
 obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
 obj-$(CONFIG_SENSORS_DA9052_ADC)+= da9052-hwmon.o
+obj-$(CONFIG_SENSORS_DA906X)	+= da906x-hwmon.o
 obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
 obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
diff --git a/drivers/hwmon/da906x-hwmon.c b/drivers/hwmon/da906x-hwmon.c
new file mode 100644
index 0000000..8ece931
--- /dev/null
+++ b/drivers/hwmon/da906x-hwmon.c
@@ -0,0 +1,393 @@
+/*
+ * HW Monitor support for Dialog DA906X PMIC series
+ *
+ * Copyright 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>,
+ *         Michal Hajduk <michal.hajduk@diasemi.com>
+ *
+ *  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/err.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/platform_device.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+
+/* ADC resolutions for manual and auto modes */
+#define DA906X_ADC_RES		\
+		(1 << (DA906X_ADC_RES_L_BITS + DA906X_ADC_RES_M_BITS))
+#define DA906X_ADC_MAX		(DA906X_ADC_RES - 1)
+#define	DA906X_ADC_AUTO_RES	(1 << DA906X_ADC_RES_M_BITS)
+#define	DA906X_ADC_AUTO_MAX	(DA906X_ADC_AUTO_RES - 1)
+
+/* Define interpolation table to calculate ADC values  */
+struct i_table {
+	int x0;
+	int a;
+	int b;
+};
+#define ILINE(x1, x2, y1, y2)	{ \
+		.x0 = (x1), \
+		.a = ((y2) - (y1)) * DA906X_ADC_RES / ((x2) - (x1)), \
+		.b = (y1) - ((y2) - (y1)) * (x1) / ((x2) - (x1)), \
+	}
+
+struct channel_info {
+	const char *name;
+	const struct i_table *tbl;
+	int tbl_max;
+	u16 reg_auto_en;
+};
+
+enum da906x_adc {
+	DA906X_VSYS,
+	DA906X_ADCIN1,
+	DA906X_ADCIN2,
+	DA906X_ADCIN3,
+	DA906X_TJUNC,
+	DA906X_VBBAT,
+
+	DA906X_CHAN_NUM
+};
+
+static const struct i_table vsys_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 2500, 5500)
+};
+
+static const struct i_table adcin_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 0, 2500)
+};
+
+static const struct i_table tjunc_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 333, -86)
+};
+
+static const struct i_table vbbat_tbl[] = {
+	ILINE(0, DA906X_ADC_MAX, 0, 5000)
+};
+
+static const struct channel_info da906x_channels[] = {
+	[DA906X_VSYS]	= { "VSYS",
+			    vsys_tbl, ARRAY_SIZE(vsys_tbl) - 1,
+			    DA906X_REG_VSYS_RES },
+	[DA906X_ADCIN1]	= { "ADCIN1",
+			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
+			    DA906X_REG_ADCIN1_RES },
+	[DA906X_ADCIN2]	= { "ADCIN2",
+			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
+			    DA906X_REG_ADCIN2_RES },
+	[DA906X_ADCIN3]	= { "ADCIN3",
+			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
+			    DA906X_REG_ADCIN3_RES },
+	[DA906X_TJUNC]	= { "TJUNC",
+			    tjunc_tbl,	ARRAY_SIZE(tjunc_tbl) - 1 },
+	[DA906X_VBBAT]	= { "VBBAT",
+			    vbbat_tbl,	ARRAY_SIZE(vbbat_tbl) - 1}
+};
+#define DA906X_ADC_AUTO_MODE_SUPPORT_MASK	(DA906X_ADC_AUTO_VSYS_EN | \
+						 DA906X_ADC_AUTO_AD1_EN | \
+						 DA906X_ADC_AUTO_AD2_EN | \
+						 DA906X_ADC_AUTO_AD3_EN)
+
+struct da906x_hwmon {
+	struct da906x *da906x;
+	struct device *class_dev;
+	struct completion man_adc_rdy;	/* Manual read completion flag */
+	struct mutex hwmon_mutex;	/* Queue concurent manual reads */
+	int irq;
+	u8 adc_auto_en;     /* Bitmask of channels with auto mode enabled */
+	s8 tjunc_offset;    /* Calibration offset for junction temperature */
+};
+
+int da906x_adc_convert(int channel, int x)
+{
+	const struct channel_info *info = &da906x_channels[channel];
+	int i, ret;
+
+	for (i = info->tbl_max; i > 0; i--)
+		if (info->tbl[i].x0 <= x)
+			break;
+
+	ret = info->tbl[i].a * x;
+	if (ret >= 0)
+		ret += DA906X_ADC_RES / 2;
+	else
+		ret -= DA906X_ADC_RES / 2;
+	ret = ret / DA906X_ADC_RES + info->tbl[i].b;
+	return ret;
+}
+
+static int da906x_adc_manual_read(struct da906x_hwmon *hwmon, int channel)
+{
+	int ret;
+	u8 data[2];
+
+	mutex_lock(&hwmon->hwmon_mutex);
+
+	init_completion(&hwmon->man_adc_rdy);
+
+	/* Start measurment on selected channel */
+	data[0] = (channel << DA906X_ADC_MUX_SHIFT) & DA906X_ADC_MUX_MASK;
+	data[0] |= DA906X_ADC_MAN;
+	ret = da906x_reg_update(hwmon->da906x, DA906X_REG_ADC_MAN,
+				DA906X_ADC_MUX_MASK | DA906X_ADC_MAN, data[0]);
+	if (ret < 0)
+		goto out;
+
+	/* Wait for interrupt from ADC */
+	ret = wait_for_completion_timeout(&hwmon->man_adc_rdy,
+					  msecs_to_jiffies(1000));
+	if (ret = 0) {
+		ret = -EBUSY;
+		goto out;
+	}
+
+	/* Get results */
+	ret = da906x_block_read(hwmon->da906x, DA906X_REG_ADC_RES_L, 2, data);
+	if (ret < 0)
+		goto out;
+	ret = (data[0] & DA906X_ADC_RES_L_MASK) >> DA906X_ADC_RES_L_SHIFT;
+	ret |= data[1] << DA906X_ADC_RES_L_BITS;
+out:
+	mutex_unlock(&hwmon->hwmon_mutex);
+	return ret;
+}
+
+static int da906x_adc_auto_read(struct da906x *da906x, int channel)
+{
+	const struct channel_info *info = &da906x_channels[channel];
+
+	return da906x_reg_read(da906x, info->reg_auto_en);
+}
+
+static irqreturn_t da906x_hwmon_irq_handler(int irq, void *irq_data)
+{
+	struct da906x_hwmon *hwmon = irq_data;
+
+	complete(&hwmon->man_adc_rdy);
+
+	return IRQ_HANDLED;
+}
+
+static ssize_t da906x_adc_read(struct device *dev,
+			       struct device_attribute *devattr, char *buf)
+{
+	struct da906x_hwmon *hwmon = dev_get_drvdata(dev);
+	int channel = to_sensor_dev_attr(devattr)->index;
+	int val;
+
+	if (hwmon->adc_auto_en & (1 << channel)) {
+		val = da906x_adc_auto_read(hwmon->da906x, channel);
+		if (val < 0)
+			return val;
+
+		val *= DA906X_ADC_RES / DA906X_ADC_AUTO_RES;
+		val = da906x_adc_convert(channel, val);
+	} else {
+		val = da906x_adc_manual_read(hwmon, channel);
+		if (val < 0)
+			return val;
+
+		if (channel = DA906X_TJUNC)
+			val += hwmon->tjunc_offset;
+		val = da906x_adc_convert(channel, val);
+	}
+
+	return sprintf(buf, "%d\n", val);
+}
+
+static ssize_t da906x_show_name(struct device *dev,
+	struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, DA906X_DRVNAME_HWMON "\n");
+}
+
+static ssize_t da906x_show_label(struct device *dev,
+				 struct device_attribute *devattr, char *buf)
+{
+	const struct channel_info *info;
+
+	info = &da906x_channels[to_sensor_dev_attr(devattr)->index];
+	return sprintf(buf, "%s\n", info->name);
+}
+
+/* Vsys voltage */
+static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_VSYS);
+static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_VSYS);
+
+/* Universal ADC channel #1 */
+static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_ADCIN1);
+static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_ADCIN1);
+
+/* Universal ADC channel #2 */
+static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO,
+			  da906x_adc_read, NULL,
+			  DA906X_ADCIN2);
+static SENSOR_DEVICE_ATTR(in2_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_ADCIN2);
+
+/* Universal ADC channel #3 */
+static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_ADCIN3);
+static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_ADCIN3);
+
+/* Backup battery voltage */
+static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_VBBAT);
+static SENSOR_DEVICE_ATTR(in4_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_VBBAT);
+
+/* Junction temperature */
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
+			  da906x_adc_read, NULL, DA906X_TJUNC);
+
+static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO,
+			  da906x_show_label, NULL, DA906X_TJUNC);
+
+/* Device name */
+static DEVICE_ATTR(name, S_IRUGO, da906x_show_name, NULL);
+
+static struct attribute *da906x_attributes[] = {
+	&dev_attr_name.attr,
+	&sensor_dev_attr_in0_input.dev_attr.attr,
+	&sensor_dev_attr_in0_label.dev_attr.attr,
+	&sensor_dev_attr_in1_input.dev_attr.attr,
+	&sensor_dev_attr_in1_label.dev_attr.attr,
+	&sensor_dev_attr_in2_input.dev_attr.attr,
+	&sensor_dev_attr_in2_label.dev_attr.attr,
+	&sensor_dev_attr_in3_input.dev_attr.attr,
+	&sensor_dev_attr_in3_label.dev_attr.attr,
+	&sensor_dev_attr_in4_input.dev_attr.attr,
+	&sensor_dev_attr_in4_label.dev_attr.attr,
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_label.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group da906x_attr_group = {
+	.attrs = da906x_attributes,
+};
+
+static int __devinit da906x_hwmon_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_pdata *da906x_pdata = dev_get_platdata(da906x->dev);
+	struct da906x_hwmon *hwmon;
+	int ret;
+
+	hwmon = devm_kzalloc(&pdev->dev, sizeof(struct da906x_hwmon),
+			     GFP_KERNEL);
+	if (!hwmon)
+		return -ENOMEM;
+
+	mutex_init(&hwmon->hwmon_mutex);
+	init_completion(&hwmon->man_adc_rdy);
+	hwmon->da906x = da906x;
+
+	ret = da906x_reg_read(da906x, DA906X_REG_ADC_CONT);
+	if (ret < 0)
+		return ret;
+	hwmon->adc_auto_en = ret & DA906X_ADC_AUTO_MODE_SUPPORT_MASK;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN0_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_VSYS_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN0_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_VSYS_EN;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN1_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD1_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN1_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD1_EN;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN2_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD2_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN2_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD2_EN;
+
+	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN3_MANUAL_MODE)
+		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD3_EN;
+	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN3_AUTO_MODE)
+		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD3_EN;
+
+	ret = da906x_reg_update(da906x, DA906X_REG_ADC_CONT,
+				DA906X_ADC_AUTO_MODE_SUPPORT_MASK,
+				hwmon->adc_auto_en);
+	if (ret < 0)
+		return ret;
+
+	hwmon->class_dev = hwmon_device_register(&pdev->dev);
+	if (IS_ERR(hwmon->class_dev))
+		return PTR_ERR(hwmon->class_dev);
+
+	hwmon->irq = platform_get_irq_byname(pdev, DA906X_DRVNAME_HWMON);
+	ret = devm_request_threaded_irq(&pdev->dev, hwmon->irq, NULL,
+					da906x_hwmon_irq_handler,
+					IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+					"HWMON", hwmon);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request IRQ.\n");
+		goto err;
+	}
+
+	platform_set_drvdata(pdev, hwmon);
+
+	ret = da906x_reg_read(da906x, DA906X_REG_T_OFFSET);
+	if (ret < 0)
+		dev_warn(&pdev->dev, "Could not read temp1 callibration offset.\n");
+	else
+		hwmon->tjunc_offset = (s8)ret;
+
+	ret = sysfs_create_group(&pdev->dev.kobj, &da906x_attr_group);
+	if (ret)
+		goto err;
+
+	return 0;
+
+err:
+	hwmon_device_unregister(hwmon->class_dev);
+	return ret;
+}
+
+static int __devexit da906x_hwmon_remove(struct platform_device *pdev)
+{
+	struct da906x_hwmon *hwmon = platform_get_drvdata(pdev);
+
+	hwmon_device_unregister(hwmon->class_dev);
+	sysfs_remove_group(&pdev->dev.kobj, &da906x_attr_group);
+
+	return 0;
+}
+
+static struct platform_driver da906x_hwmon_driver = {
+	.probe = da906x_hwmon_probe,
+	.remove = __devexit_p(da906x_hwmon_remove),
+	.driver = {
+		.name = DA906X_DRVNAME_HWMON,
+		.owner = THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_hwmon_driver);
+
+MODULE_DESCRIPTION("DA906X Hardware monitoring");
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>, Michal Hajduk <michal.hajduk@diasemi.com>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("paltform:" DA906X_DRVNAME_HWMON);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [RFC PATCH 5/8] input: Add support for DA906x PMIC OnKey detection.
  2012-08-24 14:05         ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-24 14:10           ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 14:10 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

This driver creates input device that reports a key event on an OnKey button
release. The reported key code depends on the time, the button was holded for.
If holding time < 2 seconds - KEY_SLEEP is reported on button release,
otherwise KEY_POWER is reported after 2 seconds.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/input/misc/Kconfig        |    6 ++
 drivers/input/misc/Makefile       |    1 +
 drivers/input/misc/da906x-onkey.c |  139 +++++++++++++++++++++++++++++++++++++
 3 files changed, 146 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/misc/da906x-onkey.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 7c0f1ec..fd8d951 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -486,6 +486,12 @@ config INPUT_DA9052_ONKEY
 	  To compile this driver as a module, choose M here: the
 	  module will be called da9052_onkey.
 
+config INPUT_DA906X_ONKEY
+	tristate "Dialog DA906x OnKey"
+	depends on MFD_DA906X
+	help
+	  Support for Dialog Semiconductor input onkey device.
+
 config INPUT_DM355EVM
 	tristate "TI DaVinci DM355 EVM Keypad and IR Remote"
 	depends on MFD_DM355EVM_MSP
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 83fe6f5..73406ac 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_INPUT_CMA3000)		+= cma3000_d0x.o
 obj-$(CONFIG_INPUT_CMA3000_I2C)		+= cma3000_d0x_i2c.o
 obj-$(CONFIG_INPUT_COBALT_BTNS)		+= cobalt_btns.o
 obj-$(CONFIG_INPUT_DA9052_ONKEY)	+= da9052_onkey.o
+obj-$(CONFIG_INPUT_DA906X_ONKEY)	+= da906x-onkey.o
 obj-$(CONFIG_INPUT_DM355EVM)		+= dm355evm_keys.o
 obj-$(CONFIG_INPUT_GP2A)		+= gp2ap002a00f.o
 obj-$(CONFIG_INPUT_GPIO_TILT_POLLED)	+= gpio_tilt_polled.o
diff --git a/drivers/input/misc/da906x-onkey.c b/drivers/input/misc/da906x-onkey.c
new file mode 100644
index 0000000..477c554
--- /dev/null
+++ b/drivers/input/misc/da906x-onkey.c
@@ -0,0 +1,139 @@
+/*
+ * OnKey device driver for Dialog DA906x PMIC
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author:  <michal.hajduk@diasemi.com>
+ *
+ *  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/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/workqueue.h>
+
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/registers.h>
+
+
+struct da906x_onkey {
+	struct	da906x *da906x;
+	struct	input_dev *input;
+	int irq;
+};
+
+static irqreturn_t da906x_onkey_irq_handler(int irq, void *data)
+{
+	struct da906x_onkey *onkey = data;
+	unsigned int code;
+	int ret;
+
+	ret = da906x_reg_read(onkey->da906x, DA906X_REG_STATUS_A);
+	if ((ret >= 0) && (ret & DA906X_NONKEY)) {
+		dev_notice(&onkey->input->dev, "KEY_POWER pressed.\n");
+		code = KEY_POWER;
+	} else {
+		dev_notice(&onkey->input->dev, "KEY_SLEEP pressed.\n");
+		code = KEY_SLEEP;
+	}
+
+	/* Interrupt raised for key release only,
+	   so report consecutive button press and release. */
+	input_report_key(onkey->input, code, 1);
+	input_report_key(onkey->input, code, 0);
+	input_sync(onkey->input);
+
+	return IRQ_HANDLED;
+}
+
+static int __devinit da906x_onkey_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_onkey *onkey;
+	int ret = 0;
+
+	onkey = devm_kzalloc(&pdev->dev, sizeof(struct da906x_onkey),
+			     GFP_KERNEL);
+	if (!onkey) {
+		dev_err(&pdev->dev, "Failed to allocate memory.\n");
+		return -ENOMEM;
+	}
+
+	onkey->input = input_allocate_device();
+	if (!onkey->input) {
+		dev_err(&pdev->dev, "Failed to allocated inpute device.\n");
+		return -ENOMEM;
+	}
+
+	onkey->irq = platform_get_irq_byname(pdev, DA906X_DRVNAME_ONKEY);
+	onkey->da906x = da906x;
+
+	onkey->input->evbit[0] = BIT_MASK(EV_KEY);
+	onkey->input->name = DA906X_DRVNAME_ONKEY;
+	onkey->input->phys = DA906X_DRVNAME_ONKEY "/input0";
+	onkey->input->dev.parent = &pdev->dev;
+	input_set_capability(onkey->input, EV_KEY, KEY_POWER);
+	input_set_capability(onkey->input, EV_KEY, KEY_SLEEP);
+
+	ret = request_threaded_irq(onkey->irq, NULL, da906x_onkey_irq_handler,
+			IRQF_TRIGGER_LOW | IRQF_ONESHOT, "ONKEY", onkey);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request IRQ.\n");
+		goto err_input;
+	}
+
+	ret = input_register_device(onkey->input);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request IRQ.\n");
+		goto err_irq;
+	}
+
+	platform_set_drvdata(pdev, onkey);
+
+	/* Interrupt reacts on button release */
+	da906x_reg_update(da906x, DA906X_REG_CONFIG_I,
+			  DA906X_NONKEY_PIN_MASK, DA906X_NONKEY_PIN_SWDOWN);
+
+	return 0;
+
+err_irq:
+	free_irq(onkey->da906x->irq_base + onkey->irq , onkey);
+err_input:
+	input_free_device(onkey->input);
+	return ret;
+}
+
+static int __devexit da906x_onkey_remove(struct platform_device *pdev)
+{
+	struct	da906x_onkey *onkey = platform_get_drvdata(pdev);
+
+	free_irq(onkey->irq, onkey);
+	input_unregister_device(onkey->input);
+	return 0;
+}
+
+static struct platform_driver da906x_onkey_driver = {
+	.probe	= da906x_onkey_probe,
+	.remove	= __devexit_p(da906x_onkey_remove),
+	.driver	= {
+		.name	= DA906X_DRVNAME_ONKEY,
+		.owner	= THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_onkey_driver);
+
+MODULE_AUTHOR("Dialog Semiconductor <michal.hajduk@diasemi.com>");
+MODULE_DESCRIPTION("Onkey driver for DA906X");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("paltform:" DA906X_DRVNAME_ONKEY);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [lm-sensors] [RFC PATCH 5/8] input: Add support for DA906x PMIC OnKey detection.
@ 2012-08-24 14:10           ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 14:10 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

This driver creates input device that reports a key event on an OnKey button
release. The reported key code depends on the time, the button was holded for.
If holding time < 2 seconds - KEY_SLEEP is reported on button release,
otherwise KEY_POWER is reported after 2 seconds.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/input/misc/Kconfig        |    6 ++
 drivers/input/misc/Makefile       |    1 +
 drivers/input/misc/da906x-onkey.c |  139 +++++++++++++++++++++++++++++++++++++
 3 files changed, 146 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/misc/da906x-onkey.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 7c0f1ec..fd8d951 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -486,6 +486,12 @@ config INPUT_DA9052_ONKEY
 	  To compile this driver as a module, choose M here: the
 	  module will be called da9052_onkey.
 
+config INPUT_DA906X_ONKEY
+	tristate "Dialog DA906x OnKey"
+	depends on MFD_DA906X
+	help
+	  Support for Dialog Semiconductor input onkey device.
+
 config INPUT_DM355EVM
 	tristate "TI DaVinci DM355 EVM Keypad and IR Remote"
 	depends on MFD_DM355EVM_MSP
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 83fe6f5..73406ac 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_INPUT_CMA3000)		+= cma3000_d0x.o
 obj-$(CONFIG_INPUT_CMA3000_I2C)		+= cma3000_d0x_i2c.o
 obj-$(CONFIG_INPUT_COBALT_BTNS)		+= cobalt_btns.o
 obj-$(CONFIG_INPUT_DA9052_ONKEY)	+= da9052_onkey.o
+obj-$(CONFIG_INPUT_DA906X_ONKEY)	+= da906x-onkey.o
 obj-$(CONFIG_INPUT_DM355EVM)		+= dm355evm_keys.o
 obj-$(CONFIG_INPUT_GP2A)		+= gp2ap002a00f.o
 obj-$(CONFIG_INPUT_GPIO_TILT_POLLED)	+= gpio_tilt_polled.o
diff --git a/drivers/input/misc/da906x-onkey.c b/drivers/input/misc/da906x-onkey.c
new file mode 100644
index 0000000..477c554
--- /dev/null
+++ b/drivers/input/misc/da906x-onkey.c
@@ -0,0 +1,139 @@
+/*
+ * OnKey device driver for Dialog DA906x PMIC
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author:  <michal.hajduk@diasemi.com>
+ *
+ *  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/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/workqueue.h>
+
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/registers.h>
+
+
+struct da906x_onkey {
+	struct	da906x *da906x;
+	struct	input_dev *input;
+	int irq;
+};
+
+static irqreturn_t da906x_onkey_irq_handler(int irq, void *data)
+{
+	struct da906x_onkey *onkey = data;
+	unsigned int code;
+	int ret;
+
+	ret = da906x_reg_read(onkey->da906x, DA906X_REG_STATUS_A);
+	if ((ret >= 0) && (ret & DA906X_NONKEY)) {
+		dev_notice(&onkey->input->dev, "KEY_POWER pressed.\n");
+		code = KEY_POWER;
+	} else {
+		dev_notice(&onkey->input->dev, "KEY_SLEEP pressed.\n");
+		code = KEY_SLEEP;
+	}
+
+	/* Interrupt raised for key release only,
+	   so report consecutive button press and release. */
+	input_report_key(onkey->input, code, 1);
+	input_report_key(onkey->input, code, 0);
+	input_sync(onkey->input);
+
+	return IRQ_HANDLED;
+}
+
+static int __devinit da906x_onkey_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_onkey *onkey;
+	int ret = 0;
+
+	onkey = devm_kzalloc(&pdev->dev, sizeof(struct da906x_onkey),
+			     GFP_KERNEL);
+	if (!onkey) {
+		dev_err(&pdev->dev, "Failed to allocate memory.\n");
+		return -ENOMEM;
+	}
+
+	onkey->input = input_allocate_device();
+	if (!onkey->input) {
+		dev_err(&pdev->dev, "Failed to allocated inpute device.\n");
+		return -ENOMEM;
+	}
+
+	onkey->irq = platform_get_irq_byname(pdev, DA906X_DRVNAME_ONKEY);
+	onkey->da906x = da906x;
+
+	onkey->input->evbit[0] = BIT_MASK(EV_KEY);
+	onkey->input->name = DA906X_DRVNAME_ONKEY;
+	onkey->input->phys = DA906X_DRVNAME_ONKEY "/input0";
+	onkey->input->dev.parent = &pdev->dev;
+	input_set_capability(onkey->input, EV_KEY, KEY_POWER);
+	input_set_capability(onkey->input, EV_KEY, KEY_SLEEP);
+
+	ret = request_threaded_irq(onkey->irq, NULL, da906x_onkey_irq_handler,
+			IRQF_TRIGGER_LOW | IRQF_ONESHOT, "ONKEY", onkey);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request IRQ.\n");
+		goto err_input;
+	}
+
+	ret = input_register_device(onkey->input);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request IRQ.\n");
+		goto err_irq;
+	}
+
+	platform_set_drvdata(pdev, onkey);
+
+	/* Interrupt reacts on button release */
+	da906x_reg_update(da906x, DA906X_REG_CONFIG_I,
+			  DA906X_NONKEY_PIN_MASK, DA906X_NONKEY_PIN_SWDOWN);
+
+	return 0;
+
+err_irq:
+	free_irq(onkey->da906x->irq_base + onkey->irq , onkey);
+err_input:
+	input_free_device(onkey->input);
+	return ret;
+}
+
+static int __devexit da906x_onkey_remove(struct platform_device *pdev)
+{
+	struct	da906x_onkey *onkey = platform_get_drvdata(pdev);
+
+	free_irq(onkey->irq, onkey);
+	input_unregister_device(onkey->input);
+	return 0;
+}
+
+static struct platform_driver da906x_onkey_driver = {
+	.probe	= da906x_onkey_probe,
+	.remove	= __devexit_p(da906x_onkey_remove),
+	.driver	= {
+		.name	= DA906X_DRVNAME_ONKEY,
+		.owner	= THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_onkey_driver);
+
+MODULE_AUTHOR("Dialog Semiconductor <michal.hajduk@diasemi.com>");
+MODULE_DESCRIPTION("Onkey driver for DA906X");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("paltform:" DA906X_DRVNAME_ONKEY);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [RFC PATCH 6/8] input: Add support for DA906x vibration motor driver.
  2012-08-24 14:10           ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-24 14:15             ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 14:15 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

This driver is registers (memless) force-feedback input device with capability
of FF_RUMBLE effect.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/input/misc/Kconfig            |    7 ++
 drivers/input/misc/Makefile           |    1 +
 drivers/input/misc/da906x-vibration.c |  153 +++++++++++++++++++++++++++++++++
 3 files changed, 161 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/misc/da906x-vibration.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index fd8d951..b8a5fac 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -492,6 +492,13 @@ config INPUT_DA906X_ONKEY
 	help
 	  Support for Dialog Semiconductor input onkey device.
 
+config INPUT_DA906X_VIBRATION
+	tristate "Dialog DA906x Vibration"
+	depends on MFD_DA906X
+	select INPUT_FF_MEMLESS
+	help
+	  Support for Dialog Semiconductor vibration motor driver.
+
 config INPUT_DM355EVM
 	tristate "TI DaVinci DM355 EVM Keypad and IR Remote"
 	depends on MFD_DM355EVM_MSP
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 73406ac..7b284ef 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_INPUT_CMA3000_I2C)		+= cma3000_d0x_i2c.o
 obj-$(CONFIG_INPUT_COBALT_BTNS)		+= cobalt_btns.o
 obj-$(CONFIG_INPUT_DA9052_ONKEY)	+= da9052_onkey.o
 obj-$(CONFIG_INPUT_DA906X_ONKEY)	+= da906x-onkey.o
+obj-$(CONFIG_INPUT_DA906X_VIBRATION)	+= da906x-vibration.o
 obj-$(CONFIG_INPUT_DM355EVM)		+= dm355evm_keys.o
 obj-$(CONFIG_INPUT_GP2A)		+= gp2ap002a00f.o
 obj-$(CONFIG_INPUT_GPIO_TILT_POLLED)	+= gpio_tilt_polled.o
diff --git a/drivers/input/misc/da906x-vibration.c b/drivers/input/misc/da906x-vibration.c
new file mode 100644
index 0000000..0fae20a
--- /dev/null
+++ b/drivers/input/misc/da906x-vibration.c
@@ -0,0 +1,153 @@
+/*
+ * Force Feedback device driver for DA906x PMIC series
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/input.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/registers.h>
+
+struct vibration {
+	struct da906x		*hw;
+	struct input_dev	*input_dev;
+	struct workqueue_struct	*workqueue;
+	struct work_struct	work;
+	unsigned short		strength;
+};
+
+static void vibra_work(struct work_struct *work)
+{
+	struct vibration *vibr = container_of(work, struct vibration, work);
+	unsigned val;
+
+	val = (vibr->strength * (DA906X_VIB_SET_MAX + 1)) /
+	      ((unsigned long)USHRT_MAX + 1);
+
+	da906x_reg_write(vibr->hw, DA906X_REG_VIB, val);
+
+	if (val)
+		da906x_reg_set_bits(vibr->hw, DA906X_REG_LDO8_CONT,
+				    DA906X_LDO_EN);
+	else
+		da906x_reg_clear_bits(vibr->hw, DA906X_REG_LDO8_CONT,
+				      DA906X_LDO_EN);
+}
+
+static int vibra_play(struct input_dev *input, void *data,
+		      struct ff_effect *effect)
+{
+	struct vibration *vibration = input_get_drvdata(input);
+
+	vibration->strength = effect->u.rumble.strong_magnitude;
+
+	queue_work(vibration->workqueue, &vibration->work);
+
+	return 0;
+}
+
+static int __devinit da906x_vibration_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct vibration *vibration;
+	int ret;
+
+	/* Check PMIC vibration configuration */
+	ret = da906x_reg_read(da906x, DA906X_REG_CONFIG_H);
+	if (ret < 0)
+		return ret;
+
+	if (!(ret & DA906X_LDO8_MODE_MASK)) {
+		dev_err(&pdev->dev, "Vibration is disabled\n");
+		return -ENODEV;
+	}
+
+	vibration = devm_kzalloc(&pdev->dev, sizeof(*vibration), GFP_KERNEL);
+	if (!vibration) {
+		dev_err(&pdev->dev, "Could not allocate memory\n");
+		return -ENOMEM;
+	}
+
+	platform_set_drvdata(pdev, vibration);
+	vibration->hw = da906x;
+	INIT_WORK(&vibration->work, vibra_work);
+	vibration->workqueue = alloc_workqueue("da906x-vibration", 0, 0);
+	if (!vibration->workqueue) {
+		dev_err(&pdev->dev, "Could not allocate workqueue\n");
+		return -ENOMEM;
+	}
+
+	vibration->input_dev = input_allocate_device();
+	if (!vibration->input_dev) {
+		dev_err(&pdev->dev, "Could not allocate device\n");
+		ret = -ENOMEM;
+		goto err_ialloc;
+	}
+
+	input_set_drvdata(vibration->input_dev, vibration);
+	vibration->input_dev->name = DA906X_DRVNAME_VIBRATION;
+	vibration->input_dev->id.version = 1;
+	vibration->input_dev->dev.parent = pdev->dev.parent;
+	vibration->input_dev->evbit[0] = BIT_MASK(EV_FF);
+	input_set_capability(vibration->input_dev, EV_FF, FF_RUMBLE);
+
+	ret = input_ff_create_memless(vibration->input_dev, NULL, vibra_play);
+	if (ret < 0) {
+		dev_err(&pdev->dev,
+			"Could not create force-feedback device\n");
+		goto err_ffcreat;
+	}
+
+	ret = input_register_device(vibration->input_dev);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Could not register input device\n");
+		goto err_ireg;
+	}
+	return 0;
+
+err_ireg:
+	input_ff_destroy(vibration->input_dev);
+err_ffcreat:
+	input_free_device(vibration->input_dev);
+err_ialloc:
+	destroy_workqueue(vibration->workqueue);
+
+	return ret;
+}
+
+static int __devexit da906x_vibration_remove(struct platform_device *pdev)
+{
+	struct vibration *vibration = platform_get_drvdata(pdev);
+
+	input_unregister_device(vibration->input_dev);
+	return 0;
+}
+
+static struct platform_driver da906x_vibration_driver = {
+	.probe		= da906x_vibration_probe,
+	.remove		= __devexit_p(da906x_vibration_remove),
+	.driver		= {
+		.name	= DA906X_DRVNAME_VIBRATION,
+		.owner	= THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_vibration_driver);
+
+/* Module information */
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>");
+MODULE_DESCRIPTION("DA906x vibration driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DA906X_DRVNAME_VIBRATION);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [lm-sensors] [RFC PATCH 6/8] input: Add support for DA906x vibration motor driver.
@ 2012-08-24 14:15             ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 14:15 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

This driver is registers (memless) force-feedback input device with capability
of FF_RUMBLE effect.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/input/misc/Kconfig            |    7 ++
 drivers/input/misc/Makefile           |    1 +
 drivers/input/misc/da906x-vibration.c |  153 +++++++++++++++++++++++++++++++++
 3 files changed, 161 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/misc/da906x-vibration.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index fd8d951..b8a5fac 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -492,6 +492,13 @@ config INPUT_DA906X_ONKEY
 	help
 	  Support for Dialog Semiconductor input onkey device.
 
+config INPUT_DA906X_VIBRATION
+	tristate "Dialog DA906x Vibration"
+	depends on MFD_DA906X
+	select INPUT_FF_MEMLESS
+	help
+	  Support for Dialog Semiconductor vibration motor driver.
+
 config INPUT_DM355EVM
 	tristate "TI DaVinci DM355 EVM Keypad and IR Remote"
 	depends on MFD_DM355EVM_MSP
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 73406ac..7b284ef 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_INPUT_CMA3000_I2C)		+= cma3000_d0x_i2c.o
 obj-$(CONFIG_INPUT_COBALT_BTNS)		+= cobalt_btns.o
 obj-$(CONFIG_INPUT_DA9052_ONKEY)	+= da9052_onkey.o
 obj-$(CONFIG_INPUT_DA906X_ONKEY)	+= da906x-onkey.o
+obj-$(CONFIG_INPUT_DA906X_VIBRATION)	+= da906x-vibration.o
 obj-$(CONFIG_INPUT_DM355EVM)		+= dm355evm_keys.o
 obj-$(CONFIG_INPUT_GP2A)		+= gp2ap002a00f.o
 obj-$(CONFIG_INPUT_GPIO_TILT_POLLED)	+= gpio_tilt_polled.o
diff --git a/drivers/input/misc/da906x-vibration.c b/drivers/input/misc/da906x-vibration.c
new file mode 100644
index 0000000..0fae20a
--- /dev/null
+++ b/drivers/input/misc/da906x-vibration.c
@@ -0,0 +1,153 @@
+/*
+ * Force Feedback device driver for DA906x PMIC series
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/input.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/registers.h>
+
+struct vibration {
+	struct da906x		*hw;
+	struct input_dev	*input_dev;
+	struct workqueue_struct	*workqueue;
+	struct work_struct	work;
+	unsigned short		strength;
+};
+
+static void vibra_work(struct work_struct *work)
+{
+	struct vibration *vibr = container_of(work, struct vibration, work);
+	unsigned val;
+
+	val = (vibr->strength * (DA906X_VIB_SET_MAX + 1)) /
+	      ((unsigned long)USHRT_MAX + 1);
+
+	da906x_reg_write(vibr->hw, DA906X_REG_VIB, val);
+
+	if (val)
+		da906x_reg_set_bits(vibr->hw, DA906X_REG_LDO8_CONT,
+				    DA906X_LDO_EN);
+	else
+		da906x_reg_clear_bits(vibr->hw, DA906X_REG_LDO8_CONT,
+				      DA906X_LDO_EN);
+}
+
+static int vibra_play(struct input_dev *input, void *data,
+		      struct ff_effect *effect)
+{
+	struct vibration *vibration = input_get_drvdata(input);
+
+	vibration->strength = effect->u.rumble.strong_magnitude;
+
+	queue_work(vibration->workqueue, &vibration->work);
+
+	return 0;
+}
+
+static int __devinit da906x_vibration_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct vibration *vibration;
+	int ret;
+
+	/* Check PMIC vibration configuration */
+	ret = da906x_reg_read(da906x, DA906X_REG_CONFIG_H);
+	if (ret < 0)
+		return ret;
+
+	if (!(ret & DA906X_LDO8_MODE_MASK)) {
+		dev_err(&pdev->dev, "Vibration is disabled\n");
+		return -ENODEV;
+	}
+
+	vibration = devm_kzalloc(&pdev->dev, sizeof(*vibration), GFP_KERNEL);
+	if (!vibration) {
+		dev_err(&pdev->dev, "Could not allocate memory\n");
+		return -ENOMEM;
+	}
+
+	platform_set_drvdata(pdev, vibration);
+	vibration->hw = da906x;
+	INIT_WORK(&vibration->work, vibra_work);
+	vibration->workqueue = alloc_workqueue("da906x-vibration", 0, 0);
+	if (!vibration->workqueue) {
+		dev_err(&pdev->dev, "Could not allocate workqueue\n");
+		return -ENOMEM;
+	}
+
+	vibration->input_dev = input_allocate_device();
+	if (!vibration->input_dev) {
+		dev_err(&pdev->dev, "Could not allocate device\n");
+		ret = -ENOMEM;
+		goto err_ialloc;
+	}
+
+	input_set_drvdata(vibration->input_dev, vibration);
+	vibration->input_dev->name = DA906X_DRVNAME_VIBRATION;
+	vibration->input_dev->id.version = 1;
+	vibration->input_dev->dev.parent = pdev->dev.parent;
+	vibration->input_dev->evbit[0] = BIT_MASK(EV_FF);
+	input_set_capability(vibration->input_dev, EV_FF, FF_RUMBLE);
+
+	ret = input_ff_create_memless(vibration->input_dev, NULL, vibra_play);
+	if (ret < 0) {
+		dev_err(&pdev->dev,
+			"Could not create force-feedback device\n");
+		goto err_ffcreat;
+	}
+
+	ret = input_register_device(vibration->input_dev);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Could not register input device\n");
+		goto err_ireg;
+	}
+	return 0;
+
+err_ireg:
+	input_ff_destroy(vibration->input_dev);
+err_ffcreat:
+	input_free_device(vibration->input_dev);
+err_ialloc:
+	destroy_workqueue(vibration->workqueue);
+
+	return ret;
+}
+
+static int __devexit da906x_vibration_remove(struct platform_device *pdev)
+{
+	struct vibration *vibration = platform_get_drvdata(pdev);
+
+	input_unregister_device(vibration->input_dev);
+	return 0;
+}
+
+static struct platform_driver da906x_vibration_driver = {
+	.probe		= da906x_vibration_probe,
+	.remove		= __devexit_p(da906x_vibration_remove),
+	.driver		= {
+		.name	= DA906X_DRVNAME_VIBRATION,
+		.owner	= THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_vibration_driver);
+
+/* Module information */
+MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>");
+MODULE_DESCRIPTION("DA906x vibration driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DA906X_DRVNAME_VIBRATION);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [RFC PATCH 7/8] watchdog: Add DA906x PMIC watchdog driver.
  2012-08-24 14:15             ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-24 14:20               ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 14:20 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

This driver supports watchdog device inside DA906x PMIC.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/watchdog/Kconfig      |   27 ++++
 drivers/watchdog/Makefile     |    1 +
 drivers/watchdog/da906x_wdt.c |  276 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 304 insertions(+), 0 deletions(-)
 create mode 100644 drivers/watchdog/da906x_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 53d7571..ef07575 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -76,6 +76,33 @@ config DA9052_WATCHDOG
           Alternatively say M to compile the driver as a module,
           which will be called da9052_wdt.
 
+config DA906X_WATCHDOG
+	tristate "Dialog DA906X Watchdog"
+	depends on MFD_DA906X
+	select WATCHDOG_CORE
+	help
+	  Support for the watchdog in the DA906X PMIC.
+
+config DA906X_WDT_DEFAULT_TIMEOUT
+	int "Watchdog timeout in seconds <2, 4, 8, 16, 32, 65, 131>"
+	depends on DA906X_WATCHDOG
+	default 8
+	range 2 131
+	help
+	  Select the default watchdog timer period to be used by the
+	  Dialog DA906x watchdog driver. Supported values are:
+	  2, 4, 8, 16, 32, 65, 131 seconds.
+
+config DA906X_WDT_FLEXIBLE_TIMEOUT
+	bool "Flexible watchdog timeout (when requested value is unsupported)"
+	depends on DA906X_WATCHDOG
+	default y
+	help
+	  Say Y here to allow to select longer watchdog timer period to be
+	  used when requested value is not supported. The lowest available
+	  value higher than requested will be used (watchdog will never
+	  expire before requested timeout).
+
 config WM831X_WATCHDOG
 	tristate "WM831x watchdog"
 	depends on MFD_WM831X
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 572b39b..0746a87 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -164,6 +164,7 @@ obj-$(CONFIG_XEN_WDT) += xen_wdt.o
 
 # Architecture Independent
 obj-$(CONFIG_DA9052_WATCHDOG) += da9052_wdt.o
+obj-$(CONFIG_DA906X_WATCHDOG) += da906x_wdt.o
 obj-$(CONFIG_WM831X_WATCHDOG) += wm831x_wdt.o
 obj-$(CONFIG_WM8350_WATCHDOG) += wm8350_wdt.o
 obj-$(CONFIG_MAX63XX_WATCHDOG) += max63xx_wdt.o
diff --git a/drivers/watchdog/da906x_wdt.c b/drivers/watchdog/da906x_wdt.c
new file mode 100644
index 0000000..a67e4fa
--- /dev/null
+++ b/drivers/watchdog/da906x_wdt.c
@@ -0,0 +1,276 @@
+/*
+ * Watchdog driver for DA906X PMICs.
+ *
+ * Copyright(c) 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Mariusz Wojtasik <mariusz.wojtasik@diasemi.com>
+ *
+ *  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/watchdog.h>
+#include <linux/platform_device.h>
+#include <linux/uaccess.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+
+#include <linux/mfd/da906x/registers.h>
+#include <linux/mfd/da906x/core.h>
+
+#define	SUPPORTED_TIMEOUTS_STR		"2, 4, 8, 16, 32, 65, 131"
+
+/* Watchdog selector to timeout in seconds.
+   0: WDT disabled;
+   others: timeout = 2048 ms * 2^(TWDSCALE-1). */
+const int wdt_timeout[] = { 0, 2, 4, 8, 16, 32, 65, 131 };
+#define DA906X_TWDSCALE_DISABLE		0
+#define DA906X_TWDSCALE_MIN		1
+#define DA906X_TWDSCALE_MAX		(ARRAY_SIZE(wdt_timeout) - 1)
+#define DA906X_WDT_MIN_TIMEOUT		wdt_timeout[DA906X_TWDSCALE_MIN]
+#define DA906X_WDT_MAX_TIMEOUT		wdt_timeout[DA906X_TWDSCALE_MAX]
+#define WATCHDOG_DEFAULT_TIMEOUT	wdt_timeout[3];
+
+/* module parameters */
+static int default_timeout = CONFIG_DA906X_WDT_DEFAULT_TIMEOUT;
+module_param(default_timeout, int, 0);
+MODULE_PARM_DESC(default_timeout,
+	"Watchdog timeout in seconds (select from: " SUPPORTED_TIMEOUTS_STR
+	" default=" __stringify(CONFIG_DA906X_WDT_DEFAULT_TIMEOUT) ")");
+
+static bool flex_timeout = CONFIG_DA906X_WDT_FLEXIBLE_TIMEOUT;
+module_param(flex_timeout, bool, false);
+MODULE_PARM_DESC(flex_timeout,
+	"Watchdog flexible timeout, allows longer timeout than requested"
+	" (default=" __stringify(CONFIG_DA906X_WDT_FLEXIBLE_TIMEOUT) ")");
+
+static int nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, int, 0);
+MODULE_PARM_DESC(nowayout,
+		 "Watchdog cannot be stopped once started (default="
+		 __stringify(WATCHDOG_NOWAYOUT) ")");
+
+
+struct da906x_watchdog {
+	struct da906x *da906x;
+	struct watchdog_device *wdtdev;
+	struct mutex lock;
+};
+static struct da906x_watchdog da906x_watchdog;
+
+static int _da906x_wdt_timeout_to_sel(int secs)
+{
+	int i;
+
+	for (i = DA906X_TWDSCALE_MIN; i <= DA906X_TWDSCALE_MAX; i++) {
+		if (wdt_timeout[i] == secs ||
+		    (flex_timeout && wdt_timeout[i] > secs))
+			return i;
+	}
+
+	return 0;
+}
+
+static int _da906x_wdt_disable(struct da906x *da906x)
+{
+	return da906x_reg_update(da906x, DA906X_REG_CONTROL_D,
+			DA906X_TWDSCALE_MASK,
+			DA906X_TWDSCALE_DISABLE << DA906X_TWDSCALE_SHIFT);
+}
+
+static int _da906x_wdt_set_timeout(struct da906x *da906x, unsigned int regval)
+{
+	if (regval > DA906X_TWDSCALE_MAX)
+		return -EINVAL;
+
+	return da906x_reg_update(da906x, DA906X_REG_CONTROL_D,
+			DA906X_TWDSCALE_MASK, regval << DA906X_TWDSCALE_SHIFT);
+}
+
+static int _da906x_wdt_kick(struct da906x *da906x)
+{
+	return da906x_reg_write(da906x, DA906X_REG_CONTROL_F, DA906X_WATCHDOG);
+}
+
+static int da906x_wdt_start(struct watchdog_device *wdd)
+{
+	struct da906x_watchdog *wdt = watchdog_get_drvdata(wdd);
+	unsigned int selector;
+	int ret = 0;
+
+	mutex_lock(&wdt->lock);
+	selector = _da906x_wdt_timeout_to_sel(wdt->wdtdev->timeout);
+	ret = _da906x_wdt_set_timeout(wdt->da906x, selector);
+	if (ret != 0) {
+		dev_err(wdt->da906x->dev,
+			"Watchdog failed to start (err = %d)\n", ret);
+	}
+	mutex_unlock(&wdt->lock);
+
+	return ret;
+}
+
+static int da906x_wdt_stop(struct watchdog_device *wdd)
+{
+	struct da906x_watchdog *wdt = watchdog_get_drvdata(wdd);
+	int ret = 0;
+
+	mutex_lock(&wdt->lock);
+	ret = _da906x_wdt_disable(wdt->da906x);
+	if (ret < 0)
+		dev_alert(wdt->da906x->dev,
+			  "Watchdog failed to stop (err = %d)\n", ret);
+	mutex_unlock(&wdt->lock);
+
+	return ret;
+}
+
+static int da906x_wdt_ping(struct watchdog_device *wdd)
+{
+	struct da906x_watchdog *wdt = watchdog_get_drvdata(wdd);
+	int ret = 0;
+
+	mutex_lock(&wdt->lock);
+	ret = _da906x_wdt_kick(wdt->da906x);
+	if (ret < 0)
+		dev_alert(wdt->da906x->dev,
+			  "Failed to ping the watchdog (err = %d)\n", ret);
+	mutex_unlock(&wdt->lock);
+
+	return ret;
+}
+
+static int da906x_wdt_set_timeout(struct watchdog_device *wdd,
+							unsigned int timeout)
+{
+	struct da906x_watchdog *wdt = watchdog_get_drvdata(wdd);
+	unsigned int selector;
+	int ret = 0;
+
+	mutex_lock(&wdt->lock);
+	selector = _da906x_wdt_timeout_to_sel(timeout);
+	if (selector == 0) {
+		dev_err(wdt->da906x->dev,
+			"Unsupported watchdog timeout (selecto from: "
+			SUPPORTED_TIMEOUTS_STR ")\n");
+		ret = -EINVAL;
+		goto out;
+	}
+
+	ret = _da906x_wdt_set_timeout(wdt->da906x, selector);
+	if (ret < 0) {
+		dev_err(wdt->da906x->dev,
+			"Failed to set watchdog timeout (err = %d)\n", ret);
+		goto out;
+	}
+
+	wdd->timeout = wdt_timeout[selector];
+
+out:
+	mutex_unlock(&wdt->lock);
+
+	return ret;
+}
+
+static struct watchdog_info da906x_watchdog_info = {
+	.options	= WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
+	.identity	= "DA906x Watchdog",
+};
+
+static struct watchdog_ops da906x_watchdog_ops = {
+	.owner	= THIS_MODULE,
+	.start		= da906x_wdt_start,
+	.stop		= da906x_wdt_stop,
+	.ping		= da906x_wdt_ping,
+	.set_timeout	= da906x_wdt_set_timeout,
+};
+
+static struct watchdog_device da906x_watchdog_device = {
+	.info	= &da906x_watchdog_info,
+	.ops	= &da906x_watchdog_ops,
+	.driver_data = &da906x_watchdog,
+};
+
+static int __devinit da906x_wdt_probe(struct platform_device *pdev)
+{
+	int ret;
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_watchdog *wdt = &da906x_watchdog;
+	unsigned int selector;
+
+	if (wdt->da906x != NULL) {
+		dev_err(da906x->dev, DA906X_DRVNAME_WATCHDOG
+			" already registered.\n");
+		return -EBUSY;
+	}
+
+	wdt->da906x = da906x;
+	wdt->wdtdev = &da906x_watchdog_device;
+	mutex_init(&wdt->lock);
+
+	if (nowayout)
+		set_bit(WDOG_NO_WAY_OUT, &wdt->wdtdev->status);
+
+	if (flex_timeout)
+		wdt->wdtdev->min_timeout = 1;
+	else
+		wdt->wdtdev->min_timeout = DA906X_WDT_MIN_TIMEOUT;
+
+	wdt->wdtdev->max_timeout = DA906X_WDT_MAX_TIMEOUT;
+
+	selector = _da906x_wdt_timeout_to_sel(default_timeout);
+	if (selector == 0) {
+		wdt->wdtdev->timeout = WATCHDOG_DEFAULT_TIMEOUT;
+		dev_warn(da906x->dev,
+			 "Invalid default timeout: %d "
+			 "(select from: " SUPPORTED_TIMEOUTS_STR ").\n",
+			 default_timeout);
+		dev_warn(da906x->dev, "Default timeout is %d secs.\n",
+			 wdt->wdtdev->timeout);
+	} else {
+		wdt->wdtdev->timeout = wdt_timeout[selector];
+		if (wdt->wdtdev->timeout != default_timeout) {
+			dev_info(da906x->dev, "Using %d secs timeout.\n",
+				 wdt->wdtdev->timeout);
+		}
+	}
+
+	ret = watchdog_register_device(wdt->wdtdev);
+	if (ret)
+		dev_err(da906x->dev, DA906X_DRVNAME_WATCHDOG
+			" registration failed (err = %d)", ret);
+
+	return ret;
+}
+
+static int __devexit da906x_wdt_remove(struct platform_device *dev)
+{
+	struct da906x_watchdog *wdt = &da906x_watchdog;
+
+	watchdog_unregister_device(&da906x_watchdog_device);
+	wdt->da906x = NULL;
+	wdt->wdtdev = NULL;
+
+	return 0;
+}
+
+static struct platform_driver da906x_wdt_driver = {
+	.probe = da906x_wdt_probe,
+	.remove = __devexit_p(da906x_wdt_remove),
+	.driver = {
+		.name	= DA906X_DRVNAME_WATCHDOG,
+		.owner	= THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_wdt_driver);
+
+MODULE_AUTHOR("Mariusz Wojtasik <mariusz.wojtasik@diasemi.com>");
+MODULE_DESCRIPTION("Watchdog driver for Dialog DA906x");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DA906X_DRVNAME_WATCHDOG);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [lm-sensors] [RFC PATCH 7/8] watchdog: Add DA906x PMIC watchdog driver.
@ 2012-08-24 14:20               ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 14:20 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

This driver supports watchdog device inside DA906x PMIC.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/watchdog/Kconfig      |   27 ++++
 drivers/watchdog/Makefile     |    1 +
 drivers/watchdog/da906x_wdt.c |  276 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 304 insertions(+), 0 deletions(-)
 create mode 100644 drivers/watchdog/da906x_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 53d7571..ef07575 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -76,6 +76,33 @@ config DA9052_WATCHDOG
           Alternatively say M to compile the driver as a module,
           which will be called da9052_wdt.
 
+config DA906X_WATCHDOG
+	tristate "Dialog DA906X Watchdog"
+	depends on MFD_DA906X
+	select WATCHDOG_CORE
+	help
+	  Support for the watchdog in the DA906X PMIC.
+
+config DA906X_WDT_DEFAULT_TIMEOUT
+	int "Watchdog timeout in seconds <2, 4, 8, 16, 32, 65, 131>"
+	depends on DA906X_WATCHDOG
+	default 8
+	range 2 131
+	help
+	  Select the default watchdog timer period to be used by the
+	  Dialog DA906x watchdog driver. Supported values are:
+	  2, 4, 8, 16, 32, 65, 131 seconds.
+
+config DA906X_WDT_FLEXIBLE_TIMEOUT
+	bool "Flexible watchdog timeout (when requested value is unsupported)"
+	depends on DA906X_WATCHDOG
+	default y
+	help
+	  Say Y here to allow to select longer watchdog timer period to be
+	  used when requested value is not supported. The lowest available
+	  value higher than requested will be used (watchdog will never
+	  expire before requested timeout).
+
 config WM831X_WATCHDOG
 	tristate "WM831x watchdog"
 	depends on MFD_WM831X
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 572b39b..0746a87 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -164,6 +164,7 @@ obj-$(CONFIG_XEN_WDT) += xen_wdt.o
 
 # Architecture Independent
 obj-$(CONFIG_DA9052_WATCHDOG) += da9052_wdt.o
+obj-$(CONFIG_DA906X_WATCHDOG) += da906x_wdt.o
 obj-$(CONFIG_WM831X_WATCHDOG) += wm831x_wdt.o
 obj-$(CONFIG_WM8350_WATCHDOG) += wm8350_wdt.o
 obj-$(CONFIG_MAX63XX_WATCHDOG) += max63xx_wdt.o
diff --git a/drivers/watchdog/da906x_wdt.c b/drivers/watchdog/da906x_wdt.c
new file mode 100644
index 0000000..a67e4fa
--- /dev/null
+++ b/drivers/watchdog/da906x_wdt.c
@@ -0,0 +1,276 @@
+/*
+ * Watchdog driver for DA906X PMICs.
+ *
+ * Copyright(c) 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: Mariusz Wojtasik <mariusz.wojtasik@diasemi.com>
+ *
+ *  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/watchdog.h>
+#include <linux/platform_device.h>
+#include <linux/uaccess.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+
+#include <linux/mfd/da906x/registers.h>
+#include <linux/mfd/da906x/core.h>
+
+#define	SUPPORTED_TIMEOUTS_STR		"2, 4, 8, 16, 32, 65, 131"
+
+/* Watchdog selector to timeout in seconds.
+   0: WDT disabled;
+   others: timeout = 2048 ms * 2^(TWDSCALE-1). */
+const int wdt_timeout[] = { 0, 2, 4, 8, 16, 32, 65, 131 };
+#define DA906X_TWDSCALE_DISABLE		0
+#define DA906X_TWDSCALE_MIN		1
+#define DA906X_TWDSCALE_MAX		(ARRAY_SIZE(wdt_timeout) - 1)
+#define DA906X_WDT_MIN_TIMEOUT		wdt_timeout[DA906X_TWDSCALE_MIN]
+#define DA906X_WDT_MAX_TIMEOUT		wdt_timeout[DA906X_TWDSCALE_MAX]
+#define WATCHDOG_DEFAULT_TIMEOUT	wdt_timeout[3];
+
+/* module parameters */
+static int default_timeout = CONFIG_DA906X_WDT_DEFAULT_TIMEOUT;
+module_param(default_timeout, int, 0);
+MODULE_PARM_DESC(default_timeout,
+	"Watchdog timeout in seconds (select from: " SUPPORTED_TIMEOUTS_STR
+	" default=" __stringify(CONFIG_DA906X_WDT_DEFAULT_TIMEOUT) ")");
+
+static bool flex_timeout = CONFIG_DA906X_WDT_FLEXIBLE_TIMEOUT;
+module_param(flex_timeout, bool, false);
+MODULE_PARM_DESC(flex_timeout,
+	"Watchdog flexible timeout, allows longer timeout than requested"
+	" (default=" __stringify(CONFIG_DA906X_WDT_FLEXIBLE_TIMEOUT) ")");
+
+static int nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, int, 0);
+MODULE_PARM_DESC(nowayout,
+		 "Watchdog cannot be stopped once started (default="
+		 __stringify(WATCHDOG_NOWAYOUT) ")");
+
+
+struct da906x_watchdog {
+	struct da906x *da906x;
+	struct watchdog_device *wdtdev;
+	struct mutex lock;
+};
+static struct da906x_watchdog da906x_watchdog;
+
+static int _da906x_wdt_timeout_to_sel(int secs)
+{
+	int i;
+
+	for (i = DA906X_TWDSCALE_MIN; i <= DA906X_TWDSCALE_MAX; i++) {
+		if (wdt_timeout[i] = secs ||
+		    (flex_timeout && wdt_timeout[i] > secs))
+			return i;
+	}
+
+	return 0;
+}
+
+static int _da906x_wdt_disable(struct da906x *da906x)
+{
+	return da906x_reg_update(da906x, DA906X_REG_CONTROL_D,
+			DA906X_TWDSCALE_MASK,
+			DA906X_TWDSCALE_DISABLE << DA906X_TWDSCALE_SHIFT);
+}
+
+static int _da906x_wdt_set_timeout(struct da906x *da906x, unsigned int regval)
+{
+	if (regval > DA906X_TWDSCALE_MAX)
+		return -EINVAL;
+
+	return da906x_reg_update(da906x, DA906X_REG_CONTROL_D,
+			DA906X_TWDSCALE_MASK, regval << DA906X_TWDSCALE_SHIFT);
+}
+
+static int _da906x_wdt_kick(struct da906x *da906x)
+{
+	return da906x_reg_write(da906x, DA906X_REG_CONTROL_F, DA906X_WATCHDOG);
+}
+
+static int da906x_wdt_start(struct watchdog_device *wdd)
+{
+	struct da906x_watchdog *wdt = watchdog_get_drvdata(wdd);
+	unsigned int selector;
+	int ret = 0;
+
+	mutex_lock(&wdt->lock);
+	selector = _da906x_wdt_timeout_to_sel(wdt->wdtdev->timeout);
+	ret = _da906x_wdt_set_timeout(wdt->da906x, selector);
+	if (ret != 0) {
+		dev_err(wdt->da906x->dev,
+			"Watchdog failed to start (err = %d)\n", ret);
+	}
+	mutex_unlock(&wdt->lock);
+
+	return ret;
+}
+
+static int da906x_wdt_stop(struct watchdog_device *wdd)
+{
+	struct da906x_watchdog *wdt = watchdog_get_drvdata(wdd);
+	int ret = 0;
+
+	mutex_lock(&wdt->lock);
+	ret = _da906x_wdt_disable(wdt->da906x);
+	if (ret < 0)
+		dev_alert(wdt->da906x->dev,
+			  "Watchdog failed to stop (err = %d)\n", ret);
+	mutex_unlock(&wdt->lock);
+
+	return ret;
+}
+
+static int da906x_wdt_ping(struct watchdog_device *wdd)
+{
+	struct da906x_watchdog *wdt = watchdog_get_drvdata(wdd);
+	int ret = 0;
+
+	mutex_lock(&wdt->lock);
+	ret = _da906x_wdt_kick(wdt->da906x);
+	if (ret < 0)
+		dev_alert(wdt->da906x->dev,
+			  "Failed to ping the watchdog (err = %d)\n", ret);
+	mutex_unlock(&wdt->lock);
+
+	return ret;
+}
+
+static int da906x_wdt_set_timeout(struct watchdog_device *wdd,
+							unsigned int timeout)
+{
+	struct da906x_watchdog *wdt = watchdog_get_drvdata(wdd);
+	unsigned int selector;
+	int ret = 0;
+
+	mutex_lock(&wdt->lock);
+	selector = _da906x_wdt_timeout_to_sel(timeout);
+	if (selector = 0) {
+		dev_err(wdt->da906x->dev,
+			"Unsupported watchdog timeout (selecto from: "
+			SUPPORTED_TIMEOUTS_STR ")\n");
+		ret = -EINVAL;
+		goto out;
+	}
+
+	ret = _da906x_wdt_set_timeout(wdt->da906x, selector);
+	if (ret < 0) {
+		dev_err(wdt->da906x->dev,
+			"Failed to set watchdog timeout (err = %d)\n", ret);
+		goto out;
+	}
+
+	wdd->timeout = wdt_timeout[selector];
+
+out:
+	mutex_unlock(&wdt->lock);
+
+	return ret;
+}
+
+static struct watchdog_info da906x_watchdog_info = {
+	.options	= WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
+	.identity	= "DA906x Watchdog",
+};
+
+static struct watchdog_ops da906x_watchdog_ops = {
+	.owner	= THIS_MODULE,
+	.start		= da906x_wdt_start,
+	.stop		= da906x_wdt_stop,
+	.ping		= da906x_wdt_ping,
+	.set_timeout	= da906x_wdt_set_timeout,
+};
+
+static struct watchdog_device da906x_watchdog_device = {
+	.info	= &da906x_watchdog_info,
+	.ops	= &da906x_watchdog_ops,
+	.driver_data = &da906x_watchdog,
+};
+
+static int __devinit da906x_wdt_probe(struct platform_device *pdev)
+{
+	int ret;
+	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
+	struct da906x_watchdog *wdt = &da906x_watchdog;
+	unsigned int selector;
+
+	if (wdt->da906x != NULL) {
+		dev_err(da906x->dev, DA906X_DRVNAME_WATCHDOG
+			" already registered.\n");
+		return -EBUSY;
+	}
+
+	wdt->da906x = da906x;
+	wdt->wdtdev = &da906x_watchdog_device;
+	mutex_init(&wdt->lock);
+
+	if (nowayout)
+		set_bit(WDOG_NO_WAY_OUT, &wdt->wdtdev->status);
+
+	if (flex_timeout)
+		wdt->wdtdev->min_timeout = 1;
+	else
+		wdt->wdtdev->min_timeout = DA906X_WDT_MIN_TIMEOUT;
+
+	wdt->wdtdev->max_timeout = DA906X_WDT_MAX_TIMEOUT;
+
+	selector = _da906x_wdt_timeout_to_sel(default_timeout);
+	if (selector = 0) {
+		wdt->wdtdev->timeout = WATCHDOG_DEFAULT_TIMEOUT;
+		dev_warn(da906x->dev,
+			 "Invalid default timeout: %d "
+			 "(select from: " SUPPORTED_TIMEOUTS_STR ").\n",
+			 default_timeout);
+		dev_warn(da906x->dev, "Default timeout is %d secs.\n",
+			 wdt->wdtdev->timeout);
+	} else {
+		wdt->wdtdev->timeout = wdt_timeout[selector];
+		if (wdt->wdtdev->timeout != default_timeout) {
+			dev_info(da906x->dev, "Using %d secs timeout.\n",
+				 wdt->wdtdev->timeout);
+		}
+	}
+
+	ret = watchdog_register_device(wdt->wdtdev);
+	if (ret)
+		dev_err(da906x->dev, DA906X_DRVNAME_WATCHDOG
+			" registration failed (err = %d)", ret);
+
+	return ret;
+}
+
+static int __devexit da906x_wdt_remove(struct platform_device *dev)
+{
+	struct da906x_watchdog *wdt = &da906x_watchdog;
+
+	watchdog_unregister_device(&da906x_watchdog_device);
+	wdt->da906x = NULL;
+	wdt->wdtdev = NULL;
+
+	return 0;
+}
+
+static struct platform_driver da906x_wdt_driver = {
+	.probe = da906x_wdt_probe,
+	.remove = __devexit_p(da906x_wdt_remove),
+	.driver = {
+		.name	= DA906X_DRVNAME_WATCHDOG,
+		.owner	= THIS_MODULE,
+	},
+};
+
+module_platform_driver(da906x_wdt_driver);
+
+MODULE_AUTHOR("Mariusz Wojtasik <mariusz.wojtasik@diasemi.com>");
+MODULE_DESCRIPTION("Watchdog driver for Dialog DA906x");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DA906X_DRVNAME_WATCHDOG);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [RFC PATCH 8/8] leds: Add DA906x PMIC LED driver.
  2012-08-24 14:20               ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-24 14:25                 ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 14:25 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

PMIC can control three LEDs, devoted to work as RGB LED.

Beside standard brightness setting, the driver provides some hardware blinking
functionality. Driver brings access to blinking register fields inside PMIC
with LED attributes: hw_blink_dur_regval and hw_blink_frq_regval. When the
latter is not 0, hardware blinking is enabled. As long as hardware blinking
is enabled, brightness is set to its maximum.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/leds/Kconfig       |    8 +
 drivers/leds/Makefile      |    1 +
 drivers/leds/leds-da906x.c |  438 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 447 insertions(+), 0 deletions(-)
 create mode 100644 drivers/leds/leds-da906x.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index c96bbaa..46dc3dd 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -287,6 +287,14 @@ config LEDS_DA9052
 	  This option enables support for on-chip LED drivers found
 	  on Dialog Semiconductor DA9052-BC and DA9053-AA/Bx PMICs.
 
+config LEDS_DA906X
+        tristate "Dialog DA906x LEDS"
+        depends on LEDS_CLASS
+        depends on MFD_DA906X
+        help
+          This option enables support for on-chip LED drivers found
+          on Dialog Semiconductor DA906x PMICs
+
 config LEDS_DAC124S085
 	tristate "LED Support for DAC124S085 SPI DAC"
 	depends on LEDS_CLASS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index a4429a9..1601366 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_LEDS_PCA955X)		+= leds-pca955x.o
 obj-$(CONFIG_LEDS_PCA9633)		+= leds-pca9633.o
 obj-$(CONFIG_LEDS_DA903X)		+= leds-da903x.o
 obj-$(CONFIG_LEDS_DA9052)		+= leds-da9052.o
+obj-$(CONFIG_LEDS_DA906X)		+= leds-da906x.o
 obj-$(CONFIG_LEDS_WM831X_STATUS)	+= leds-wm831x-status.o
 obj-$(CONFIG_LEDS_WM8350)		+= leds-wm8350.o
 obj-$(CONFIG_LEDS_PWM)			+= leds-pwm.o
diff --git a/drivers/leds/leds-da906x.c b/drivers/leds/leds-da906x.c
new file mode 100644
index 0000000..3203fc6
--- /dev/null
+++ b/drivers/leds/leds-da906x.c
@@ -0,0 +1,438 @@
+/*
+ * LEDs driver for Dialog DA906x PMIC series
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Mariusz Wojtasik <mariusz.wojtasik@diasemi.com>,
+ *         Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/init.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/leds.h>
+#include <linux/err.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+
+#define DRIVER_NAME		DA906X_DRVNAME_LEDS
+
+#define	DA906X_GPIO_LED_NUM	3
+
+#define DA906X_PWM_MAX		(DA906X_GPIO_PWM_MASK >> DA906X_GPIO_PWM_SHIFT)
+#define DA906X_MAX_BRIGHTNESS	0x5F
+#define DA906X_BLINK_DUR_MAX	(DA906X_BLINK_DUR_MASK >> \
+							DA906X_BLINK_DUR_SHIFT)
+#define DA906X_BLINK_FRQ_MAX	(DA906X_BLINK_FRQ_MASK >> \
+							DA906X_BLINK_FRQ_SHIFT)
+
+struct da906x_led {
+	int id;
+	struct led_classdev cdev;
+	struct work_struct work;
+	struct da906x *da906x;
+	struct da906x_leds *leds_container;
+
+	int pwm_regval;
+};
+
+struct da906x_leds {
+	int n_leds;
+	/* Array size to be defined during init. Keep at end. */
+	struct da906x_led led[0];
+};
+
+int da906x_led_pwm_reg[DA906X_LED_NUM] = {
+	DA906X_REG_GPO11_LED,
+	DA906X_REG_GPO14_LED,
+	DA906X_REG_GPO15_LED,
+};
+
+static int da906x_led_get_hw_blinking(struct da906x *da906x,
+				      unsigned *frq, unsigned *dur)
+{
+	int ret = da906x_reg_read(da906x, DA906X_REG_CONTROL_D);
+	if (ret < 0)
+		return ret;
+
+	if (frq)
+		*frq = (ret & DA906X_BLINK_FRQ_MASK) >> DA906X_BLINK_FRQ_SHIFT;
+
+	if (dur)
+		*dur = (ret & DA906X_BLINK_DUR_MASK) >> DA906X_BLINK_DUR_SHIFT;
+
+	return 0;
+}
+
+static int
+da906x_led_set_hw_bright(struct da906x *da906x, int id, int pwm_val)
+{
+	unsigned int blink_frq;
+	int ret;
+
+	ret = da906x_led_get_hw_blinking(da906x, &blink_frq, NULL);
+	if (ret)
+		return ret;
+
+	/* For enabled blinking, brightness setting is unavailable */
+	if (!blink_frq)
+		ret = da906x_reg_write(da906x, da906x_led_pwm_reg[id],
+				       pwm_val);
+
+	return ret;
+}
+
+static inline int
+da906x_led_get_hw_bright(struct da906x *da906x, int id)
+{
+	return da906x_reg_read(da906x, da906x_led_pwm_reg[id]);
+}
+
+static void da906x_led_brightness_set(struct led_classdev *cdev,
+	enum led_brightness brightness)
+{
+	struct da906x_led *led = container_of(cdev, struct da906x_led, cdev);
+
+	if (led->pwm_regval != brightness) {
+		led->pwm_regval = brightness;
+		schedule_work(&led->work);
+	}
+}
+
+static void da906x_led_brightness_work(struct work_struct *work)
+{
+	struct da906x_led *led = container_of(work, struct da906x_led, work);
+	int ret;
+
+	ret = da906x_led_set_hw_bright(led->da906x, led->id, led->pwm_regval);
+	if (ret)
+		dev_err(led->da906x->dev,
+			"Failed to set led brightness (err = %d)\n", ret);
+}
+
+static int da906x_configure_led_pin(struct da906x_led *led,
+				    int low_level_driven)
+{
+	int ret;
+	u16 gpio_cfg_reg;
+	u8 gpio_cfg_mask, gpio_cfg_val;
+	u8 mode_cfg_bit;
+
+	switch (led->id) {
+	case DA906X_GPIO11_LED:
+		gpio_cfg_reg = DA906X_REG_GPIO_10_11;
+		gpio_cfg_mask = DA906X_GPIO11_PIN_MASK;
+		gpio_cfg_val = DA906X_GPIO11_PIN_GPO_OD;
+		mode_cfg_bit = DA906X_GPIO11_MODE_LED_ACT_LOW;
+		break;
+
+	case DA906X_GPIO14_LED:
+		gpio_cfg_reg = DA906X_REG_GPIO_14_15;
+		gpio_cfg_mask = DA906X_GPIO14_PIN_MASK;
+		gpio_cfg_val = DA906X_GPIO14_PIN_GPO_OD;
+		mode_cfg_bit = DA906X_GPIO14_MODE_LED_ACT_LOW;
+		break;
+
+	case DA906X_GPIO15_LED:
+		gpio_cfg_reg = DA906X_REG_GPIO_14_15;
+		gpio_cfg_mask = DA906X_GPIO15_PIN_MASK;
+		gpio_cfg_val = DA906X_GPIO15_PIN_GPO_OD;
+		mode_cfg_bit = DA906X_GPIO15_MODE_LED_ACT_LOW;
+		break;
+
+	default:
+		BUG();
+	}
+
+	/* Configure GPOs for open drain */
+	ret = da906x_reg_update(led->da906x, gpio_cfg_reg, gpio_cfg_mask,
+				gpio_cfg_val);
+	if (ret)
+		return ret;
+
+	/* Configure active level */
+	if (low_level_driven)
+		ret = da906x_reg_set_bits(led->da906x,
+					  DA906X_REG_GPIO_MODE_8_15,
+					  mode_cfg_bit);
+	else
+		ret = da906x_reg_clear_bits(led->da906x,
+					    DA906X_REG_GPIO_MODE_8_15,
+					    mode_cfg_bit);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static ssize_t da906x_hw_blink_dur_store(struct device *dev,
+						struct device_attribute *attr,
+						const char *buf, size_t count)
+{
+	struct led_classdev *cdev = dev_get_drvdata(dev);
+	struct da906x_led *led = container_of(cdev, struct da906x_led, cdev);
+	unsigned long dur;
+	int ret;
+
+	ret = kstrtoul(buf, 0, &dur);
+	if (ret || dur > DA906X_BLINK_DUR_MAX) {
+		dev_err(led->da906x->dev,
+			"Invalid parameter (valid are %d..%d)\n",
+			0, DA906X_BLINK_DUR_MAX);
+		return -EINVAL;
+	}
+
+	ret = da906x_reg_update(led->da906x, DA906X_REG_CONTROL_D,
+				DA906X_BLINK_DUR_MASK,
+				dur << DA906X_BLINK_DUR_SHIFT);
+	if (ret < 0)
+		return ret;
+
+	return count;
+}
+
+static ssize_t da906x_hw_blink_dur_show(struct device *dev,
+					struct device_attribute *attr,
+					char *buf)
+{
+	struct led_classdev *cdev = dev_get_drvdata(dev);
+	struct da906x_led *led = container_of(cdev, struct da906x_led, cdev);
+	int ret;
+	unsigned int dur;
+
+	ret = da906x_led_get_hw_blinking(led->da906x, NULL, &dur);
+	if (ret < 0)
+		return ret;
+
+	return sprintf(buf, "%u\n", dur);
+}
+
+static ssize_t da906x_hw_blink_frq_store(struct device *dev,
+						struct device_attribute *attr,
+						const char *buf, size_t count)
+{
+	struct led_classdev *cdev = dev_get_drvdata(dev);
+	struct da906x_led *led = container_of(cdev, struct da906x_led, cdev);
+	struct da906x_leds *leds = led->leds_container;
+	unsigned long frq;
+	int i;
+	int ret;
+
+	ret = kstrtoul(buf, 0, &frq);
+	if (ret || frq > DA906X_BLINK_FRQ_MAX) {
+		dev_err(led->da906x->dev,
+			"Invalid parameter (valid are %d..%d)\n",
+			0, DA906X_BLINK_FRQ_MAX);
+		return -EINVAL;
+	}
+
+	if (frq) {
+		/* Reset all LEDs brightness before blinking */
+		for (i = leds->n_leds - 1; i >= 0; i--) {
+			ret = da906x_led_set_hw_bright(led->da906x, i, 0);
+			if (ret < 0)
+				return ret;
+		}
+	}
+
+	ret = da906x_reg_update(led->da906x, DA906X_REG_CONTROL_D,
+				DA906X_BLINK_FRQ_MASK,
+				frq << DA906X_BLINK_FRQ_SHIFT);
+	if (ret < 0)
+		return ret;
+
+	if (!frq) {
+		/* Restore all LEDs brightness, when blinking is off */
+		for (i = leds->n_leds - 1; i >= 0; i--) {
+			ret = da906x_led_set_hw_bright(led->da906x, i,
+						      leds->led[i].pwm_regval);
+			if (ret < 0)
+				return ret;
+		}
+	}
+
+	return count;
+}
+
+static ssize_t da906x_hw_blink_frq_show(struct device *dev,
+					struct device_attribute *attr,
+					char *buf)
+{
+	struct led_classdev *cdev = dev_get_drvdata(dev);
+	struct da906x_led *led = container_of(cdev, struct da906x_led, cdev);
+	int ret;
+	unsigned int frq;
+
+	ret = da906x_led_get_hw_blinking(led->da906x, &frq, NULL);
+	if (ret < 0)
+		return ret;
+
+	return sprintf(buf, "%u\n", frq);
+}
+
+static DEVICE_ATTR(hw_blink_dur_regval, 0644,
+		   da906x_hw_blink_dur_show, da906x_hw_blink_dur_store);
+static DEVICE_ATTR(hw_blink_frq_regval, 0644,
+		   da906x_hw_blink_frq_show, da906x_hw_blink_frq_store);
+
+static int da906x_led_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x;
+	struct da906x_pdata *pdata;
+	struct led_platform_data *leds_pdata;
+	struct led_info *led_info;
+	struct da906x_leds *leds;
+	struct da906x_led *led;
+	size_t size;
+	int ret;
+	int i, j;
+
+	da906x = dev_get_drvdata(pdev->dev.parent);
+	pdata = da906x->dev->platform_data;
+	if (pdata == NULL) {
+		dev_err(&pdev->dev, "No platform data\n");
+		return -ENODEV;
+	}
+
+	leds_pdata = pdata->leds_pdata;
+	if (leds_pdata == NULL) {
+		dev_err(&pdev->dev, "No platform data for LEDs\n");
+		return -ENODEV;
+	}
+
+	size = sizeof(struct da906x_leds) +
+	       sizeof(struct da906x_led) * leds_pdata->num_leds;
+	leds = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
+	if (leds == NULL) {
+		dev_err(&pdev->dev, "Failed to alloc memory\n");
+		return -ENOMEM;
+	}
+
+	leds->n_leds = leds_pdata->num_leds;
+	platform_set_drvdata(pdev, leds);
+
+	for (i = 0; i < leds_pdata->num_leds; i++) {
+		led_info = &leds_pdata->leds[i];
+
+		if ((led_info->flags & DA906X_LED_ID_MASK) >= DA906X_LED_NUM) {
+			dev_err(&pdev->dev, "Invalid platform data\n");
+			ret = -EINVAL;
+			goto err_register;
+		}
+
+		/* Check, if LED ID is not duplicated */
+		for (led = &leds->led[0], j = 0; j < i; led++, j++) {
+			if (led->id ==
+			    (led_info->flags & DA906X_LED_ID_MASK)) {
+				dev_err(&pdev->dev, "Duplicated LED ID\n");
+				ret = -EINVAL;
+				goto err_register;
+			}
+		}
+
+		led->id = led_info->flags & DA906X_LED_ID_MASK;
+		led->pwm_regval = da906x_led_get_hw_bright(da906x, i);
+		led->cdev.brightness = led->pwm_regval;
+		led->cdev.max_brightness = DA906X_MAX_BRIGHTNESS;
+		led->cdev.brightness_set = da906x_led_brightness_set;
+		led->cdev.default_trigger = led_info->default_trigger;
+		led->cdev.name = led_info->name;
+		led->da906x = da906x;
+		led->leds_container = leds;
+
+		INIT_WORK(&led->work, da906x_led_brightness_work);
+
+		ret = led_classdev_register(pdev->dev.parent, &led->cdev);
+		if (ret) {
+			dev_err(&pdev->dev, "Cannot register LEDs\n");
+			goto err_register;
+		}
+
+		ret = device_create_file(led->cdev.dev,
+					 &dev_attr_hw_blink_dur_regval);
+		if (ret < 0) {
+			dev_err(&pdev->dev,
+				"Failed to create device file (err = %d)\n",
+				ret);
+			goto err_create_dur_attr;
+		}
+
+		ret = device_create_file(led->cdev.dev,
+					 &dev_attr_hw_blink_frq_regval);
+		if (ret < 0) {
+			dev_err(&pdev->dev,
+				"Failed to create device file (err = %d)\n",
+				ret);
+			goto err_create_frq_attr;
+		}
+
+		ret = da906x_configure_led_pin(led,
+				led_info->flags & DA906X_LED_LOW_LEVEL_ACTIVE);
+		if (ret) {
+			dev_err(&pdev->dev, "Failed to configure LED pins\n");
+			goto err_configure_pin;
+		}
+	}
+
+	return 0;
+
+err_register:
+	while (--i >= 0) {
+err_configure_pin:
+		device_remove_file(leds->led[i].cdev.dev,
+				   &dev_attr_hw_blink_frq_regval);
+err_create_frq_attr:
+		device_remove_file(leds->led[i].cdev.dev,
+				   &dev_attr_hw_blink_dur_regval);
+err_create_dur_attr:
+		cancel_work_sync(&leds->led[i].work);
+		led_classdev_unregister(&leds->led[i].cdev);
+	}
+
+	kfree(leds);
+
+	return ret;
+}
+
+static int da906x_led_remove(struct platform_device *pdev)
+{
+	struct da906x_leds *leds = platform_get_drvdata(pdev);
+	int i;
+
+	for (i = leds->n_leds - 1; i >= 0; i--) {
+		device_remove_file(leds->led[i].cdev.dev,
+				   &dev_attr_hw_blink_frq_regval);
+		device_remove_file(leds->led[i].cdev.dev,
+				   &dev_attr_hw_blink_dur_regval);
+		cancel_work_sync(&leds->led[i].work);
+		led_classdev_unregister(&leds->led[i].cdev);
+	}
+
+	kfree(leds);
+
+	return 0;
+}
+
+static struct platform_driver da906x_led_driver = {
+	.driver = {
+		.name = DRIVER_NAME,
+		.owner = THIS_MODULE,
+	},
+	.probe = da906x_led_probe,
+	.remove = __devexit_p(da906x_led_remove),
+};
+
+module_platform_driver(da906x_led_driver);
+
+MODULE_DESCRIPTION("LED driver for Dialog DA906X");
+MODULE_AUTHOR("Mariusz Wojtasik <mariusz.wojtasik@diasemi.com>, Krystian Garbaciak <krystian.garbaciak@diasemi.com>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DRIVER_NAME);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [lm-sensors] [RFC PATCH 8/8] leds: Add DA906x PMIC LED driver.
@ 2012-08-24 14:25                 ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-24 14:25 UTC (permalink / raw)
  To: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds
  Cc: Alessandro Zummo, Andrew Jones, Dmitry Torokhov, Samuel Ortiz,
	Ashish Jangam, Mark Brown, Donggeun Kim, Wim Van Sebroeck,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech, Bryan Wu,
	Liam Girdwood

PMIC can control three LEDs, devoted to work as RGB LED.

Beside standard brightness setting, the driver provides some hardware blinking
functionality. Driver brings access to blinking register fields inside PMIC
with LED attributes: hw_blink_dur_regval and hw_blink_frq_regval. When the
latter is not 0, hardware blinking is enabled. As long as hardware blinking
is enabled, brightness is set to its maximum.

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/leds/Kconfig       |    8 +
 drivers/leds/Makefile      |    1 +
 drivers/leds/leds-da906x.c |  438 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 447 insertions(+), 0 deletions(-)
 create mode 100644 drivers/leds/leds-da906x.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index c96bbaa..46dc3dd 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -287,6 +287,14 @@ config LEDS_DA9052
 	  This option enables support for on-chip LED drivers found
 	  on Dialog Semiconductor DA9052-BC and DA9053-AA/Bx PMICs.
 
+config LEDS_DA906X
+        tristate "Dialog DA906x LEDS"
+        depends on LEDS_CLASS
+        depends on MFD_DA906X
+        help
+          This option enables support for on-chip LED drivers found
+          on Dialog Semiconductor DA906x PMICs
+
 config LEDS_DAC124S085
 	tristate "LED Support for DAC124S085 SPI DAC"
 	depends on LEDS_CLASS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index a4429a9..1601366 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_LEDS_PCA955X)		+= leds-pca955x.o
 obj-$(CONFIG_LEDS_PCA9633)		+= leds-pca9633.o
 obj-$(CONFIG_LEDS_DA903X)		+= leds-da903x.o
 obj-$(CONFIG_LEDS_DA9052)		+= leds-da9052.o
+obj-$(CONFIG_LEDS_DA906X)		+= leds-da906x.o
 obj-$(CONFIG_LEDS_WM831X_STATUS)	+= leds-wm831x-status.o
 obj-$(CONFIG_LEDS_WM8350)		+= leds-wm8350.o
 obj-$(CONFIG_LEDS_PWM)			+= leds-pwm.o
diff --git a/drivers/leds/leds-da906x.c b/drivers/leds/leds-da906x.c
new file mode 100644
index 0000000..3203fc6
--- /dev/null
+++ b/drivers/leds/leds-da906x.c
@@ -0,0 +1,438 @@
+/*
+ * LEDs driver for Dialog DA906x PMIC series
+ *
+ * Copyright 2012 Dialog Semiconductors Ltd.
+ *
+ * Author: Mariusz Wojtasik <mariusz.wojtasik@diasemi.com>,
+ *         Krystian Garbaciak <krystian.garbaciak@diasemi.com>
+ *
+ *  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/init.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/leds.h>
+#include <linux/err.h>
+#include <linux/mfd/da906x/core.h>
+#include <linux/mfd/da906x/pdata.h>
+
+#define DRIVER_NAME		DA906X_DRVNAME_LEDS
+
+#define	DA906X_GPIO_LED_NUM	3
+
+#define DA906X_PWM_MAX		(DA906X_GPIO_PWM_MASK >> DA906X_GPIO_PWM_SHIFT)
+#define DA906X_MAX_BRIGHTNESS	0x5F
+#define DA906X_BLINK_DUR_MAX	(DA906X_BLINK_DUR_MASK >> \
+							DA906X_BLINK_DUR_SHIFT)
+#define DA906X_BLINK_FRQ_MAX	(DA906X_BLINK_FRQ_MASK >> \
+							DA906X_BLINK_FRQ_SHIFT)
+
+struct da906x_led {
+	int id;
+	struct led_classdev cdev;
+	struct work_struct work;
+	struct da906x *da906x;
+	struct da906x_leds *leds_container;
+
+	int pwm_regval;
+};
+
+struct da906x_leds {
+	int n_leds;
+	/* Array size to be defined during init. Keep at end. */
+	struct da906x_led led[0];
+};
+
+int da906x_led_pwm_reg[DA906X_LED_NUM] = {
+	DA906X_REG_GPO11_LED,
+	DA906X_REG_GPO14_LED,
+	DA906X_REG_GPO15_LED,
+};
+
+static int da906x_led_get_hw_blinking(struct da906x *da906x,
+				      unsigned *frq, unsigned *dur)
+{
+	int ret = da906x_reg_read(da906x, DA906X_REG_CONTROL_D);
+	if (ret < 0)
+		return ret;
+
+	if (frq)
+		*frq = (ret & DA906X_BLINK_FRQ_MASK) >> DA906X_BLINK_FRQ_SHIFT;
+
+	if (dur)
+		*dur = (ret & DA906X_BLINK_DUR_MASK) >> DA906X_BLINK_DUR_SHIFT;
+
+	return 0;
+}
+
+static int
+da906x_led_set_hw_bright(struct da906x *da906x, int id, int pwm_val)
+{
+	unsigned int blink_frq;
+	int ret;
+
+	ret = da906x_led_get_hw_blinking(da906x, &blink_frq, NULL);
+	if (ret)
+		return ret;
+
+	/* For enabled blinking, brightness setting is unavailable */
+	if (!blink_frq)
+		ret = da906x_reg_write(da906x, da906x_led_pwm_reg[id],
+				       pwm_val);
+
+	return ret;
+}
+
+static inline int
+da906x_led_get_hw_bright(struct da906x *da906x, int id)
+{
+	return da906x_reg_read(da906x, da906x_led_pwm_reg[id]);
+}
+
+static void da906x_led_brightness_set(struct led_classdev *cdev,
+	enum led_brightness brightness)
+{
+	struct da906x_led *led = container_of(cdev, struct da906x_led, cdev);
+
+	if (led->pwm_regval != brightness) {
+		led->pwm_regval = brightness;
+		schedule_work(&led->work);
+	}
+}
+
+static void da906x_led_brightness_work(struct work_struct *work)
+{
+	struct da906x_led *led = container_of(work, struct da906x_led, work);
+	int ret;
+
+	ret = da906x_led_set_hw_bright(led->da906x, led->id, led->pwm_regval);
+	if (ret)
+		dev_err(led->da906x->dev,
+			"Failed to set led brightness (err = %d)\n", ret);
+}
+
+static int da906x_configure_led_pin(struct da906x_led *led,
+				    int low_level_driven)
+{
+	int ret;
+	u16 gpio_cfg_reg;
+	u8 gpio_cfg_mask, gpio_cfg_val;
+	u8 mode_cfg_bit;
+
+	switch (led->id) {
+	case DA906X_GPIO11_LED:
+		gpio_cfg_reg = DA906X_REG_GPIO_10_11;
+		gpio_cfg_mask = DA906X_GPIO11_PIN_MASK;
+		gpio_cfg_val = DA906X_GPIO11_PIN_GPO_OD;
+		mode_cfg_bit = DA906X_GPIO11_MODE_LED_ACT_LOW;
+		break;
+
+	case DA906X_GPIO14_LED:
+		gpio_cfg_reg = DA906X_REG_GPIO_14_15;
+		gpio_cfg_mask = DA906X_GPIO14_PIN_MASK;
+		gpio_cfg_val = DA906X_GPIO14_PIN_GPO_OD;
+		mode_cfg_bit = DA906X_GPIO14_MODE_LED_ACT_LOW;
+		break;
+
+	case DA906X_GPIO15_LED:
+		gpio_cfg_reg = DA906X_REG_GPIO_14_15;
+		gpio_cfg_mask = DA906X_GPIO15_PIN_MASK;
+		gpio_cfg_val = DA906X_GPIO15_PIN_GPO_OD;
+		mode_cfg_bit = DA906X_GPIO15_MODE_LED_ACT_LOW;
+		break;
+
+	default:
+		BUG();
+	}
+
+	/* Configure GPOs for open drain */
+	ret = da906x_reg_update(led->da906x, gpio_cfg_reg, gpio_cfg_mask,
+				gpio_cfg_val);
+	if (ret)
+		return ret;
+
+	/* Configure active level */
+	if (low_level_driven)
+		ret = da906x_reg_set_bits(led->da906x,
+					  DA906X_REG_GPIO_MODE_8_15,
+					  mode_cfg_bit);
+	else
+		ret = da906x_reg_clear_bits(led->da906x,
+					    DA906X_REG_GPIO_MODE_8_15,
+					    mode_cfg_bit);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static ssize_t da906x_hw_blink_dur_store(struct device *dev,
+						struct device_attribute *attr,
+						const char *buf, size_t count)
+{
+	struct led_classdev *cdev = dev_get_drvdata(dev);
+	struct da906x_led *led = container_of(cdev, struct da906x_led, cdev);
+	unsigned long dur;
+	int ret;
+
+	ret = kstrtoul(buf, 0, &dur);
+	if (ret || dur > DA906X_BLINK_DUR_MAX) {
+		dev_err(led->da906x->dev,
+			"Invalid parameter (valid are %d..%d)\n",
+			0, DA906X_BLINK_DUR_MAX);
+		return -EINVAL;
+	}
+
+	ret = da906x_reg_update(led->da906x, DA906X_REG_CONTROL_D,
+				DA906X_BLINK_DUR_MASK,
+				dur << DA906X_BLINK_DUR_SHIFT);
+	if (ret < 0)
+		return ret;
+
+	return count;
+}
+
+static ssize_t da906x_hw_blink_dur_show(struct device *dev,
+					struct device_attribute *attr,
+					char *buf)
+{
+	struct led_classdev *cdev = dev_get_drvdata(dev);
+	struct da906x_led *led = container_of(cdev, struct da906x_led, cdev);
+	int ret;
+	unsigned int dur;
+
+	ret = da906x_led_get_hw_blinking(led->da906x, NULL, &dur);
+	if (ret < 0)
+		return ret;
+
+	return sprintf(buf, "%u\n", dur);
+}
+
+static ssize_t da906x_hw_blink_frq_store(struct device *dev,
+						struct device_attribute *attr,
+						const char *buf, size_t count)
+{
+	struct led_classdev *cdev = dev_get_drvdata(dev);
+	struct da906x_led *led = container_of(cdev, struct da906x_led, cdev);
+	struct da906x_leds *leds = led->leds_container;
+	unsigned long frq;
+	int i;
+	int ret;
+
+	ret = kstrtoul(buf, 0, &frq);
+	if (ret || frq > DA906X_BLINK_FRQ_MAX) {
+		dev_err(led->da906x->dev,
+			"Invalid parameter (valid are %d..%d)\n",
+			0, DA906X_BLINK_FRQ_MAX);
+		return -EINVAL;
+	}
+
+	if (frq) {
+		/* Reset all LEDs brightness before blinking */
+		for (i = leds->n_leds - 1; i >= 0; i--) {
+			ret = da906x_led_set_hw_bright(led->da906x, i, 0);
+			if (ret < 0)
+				return ret;
+		}
+	}
+
+	ret = da906x_reg_update(led->da906x, DA906X_REG_CONTROL_D,
+				DA906X_BLINK_FRQ_MASK,
+				frq << DA906X_BLINK_FRQ_SHIFT);
+	if (ret < 0)
+		return ret;
+
+	if (!frq) {
+		/* Restore all LEDs brightness, when blinking is off */
+		for (i = leds->n_leds - 1; i >= 0; i--) {
+			ret = da906x_led_set_hw_bright(led->da906x, i,
+						      leds->led[i].pwm_regval);
+			if (ret < 0)
+				return ret;
+		}
+	}
+
+	return count;
+}
+
+static ssize_t da906x_hw_blink_frq_show(struct device *dev,
+					struct device_attribute *attr,
+					char *buf)
+{
+	struct led_classdev *cdev = dev_get_drvdata(dev);
+	struct da906x_led *led = container_of(cdev, struct da906x_led, cdev);
+	int ret;
+	unsigned int frq;
+
+	ret = da906x_led_get_hw_blinking(led->da906x, &frq, NULL);
+	if (ret < 0)
+		return ret;
+
+	return sprintf(buf, "%u\n", frq);
+}
+
+static DEVICE_ATTR(hw_blink_dur_regval, 0644,
+		   da906x_hw_blink_dur_show, da906x_hw_blink_dur_store);
+static DEVICE_ATTR(hw_blink_frq_regval, 0644,
+		   da906x_hw_blink_frq_show, da906x_hw_blink_frq_store);
+
+static int da906x_led_probe(struct platform_device *pdev)
+{
+	struct da906x *da906x;
+	struct da906x_pdata *pdata;
+	struct led_platform_data *leds_pdata;
+	struct led_info *led_info;
+	struct da906x_leds *leds;
+	struct da906x_led *led;
+	size_t size;
+	int ret;
+	int i, j;
+
+	da906x = dev_get_drvdata(pdev->dev.parent);
+	pdata = da906x->dev->platform_data;
+	if (pdata = NULL) {
+		dev_err(&pdev->dev, "No platform data\n");
+		return -ENODEV;
+	}
+
+	leds_pdata = pdata->leds_pdata;
+	if (leds_pdata = NULL) {
+		dev_err(&pdev->dev, "No platform data for LEDs\n");
+		return -ENODEV;
+	}
+
+	size = sizeof(struct da906x_leds) +
+	       sizeof(struct da906x_led) * leds_pdata->num_leds;
+	leds = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
+	if (leds = NULL) {
+		dev_err(&pdev->dev, "Failed to alloc memory\n");
+		return -ENOMEM;
+	}
+
+	leds->n_leds = leds_pdata->num_leds;
+	platform_set_drvdata(pdev, leds);
+
+	for (i = 0; i < leds_pdata->num_leds; i++) {
+		led_info = &leds_pdata->leds[i];
+
+		if ((led_info->flags & DA906X_LED_ID_MASK) >= DA906X_LED_NUM) {
+			dev_err(&pdev->dev, "Invalid platform data\n");
+			ret = -EINVAL;
+			goto err_register;
+		}
+
+		/* Check, if LED ID is not duplicated */
+		for (led = &leds->led[0], j = 0; j < i; led++, j++) {
+			if (led->id =
+			    (led_info->flags & DA906X_LED_ID_MASK)) {
+				dev_err(&pdev->dev, "Duplicated LED ID\n");
+				ret = -EINVAL;
+				goto err_register;
+			}
+		}
+
+		led->id = led_info->flags & DA906X_LED_ID_MASK;
+		led->pwm_regval = da906x_led_get_hw_bright(da906x, i);
+		led->cdev.brightness = led->pwm_regval;
+		led->cdev.max_brightness = DA906X_MAX_BRIGHTNESS;
+		led->cdev.brightness_set = da906x_led_brightness_set;
+		led->cdev.default_trigger = led_info->default_trigger;
+		led->cdev.name = led_info->name;
+		led->da906x = da906x;
+		led->leds_container = leds;
+
+		INIT_WORK(&led->work, da906x_led_brightness_work);
+
+		ret = led_classdev_register(pdev->dev.parent, &led->cdev);
+		if (ret) {
+			dev_err(&pdev->dev, "Cannot register LEDs\n");
+			goto err_register;
+		}
+
+		ret = device_create_file(led->cdev.dev,
+					 &dev_attr_hw_blink_dur_regval);
+		if (ret < 0) {
+			dev_err(&pdev->dev,
+				"Failed to create device file (err = %d)\n",
+				ret);
+			goto err_create_dur_attr;
+		}
+
+		ret = device_create_file(led->cdev.dev,
+					 &dev_attr_hw_blink_frq_regval);
+		if (ret < 0) {
+			dev_err(&pdev->dev,
+				"Failed to create device file (err = %d)\n",
+				ret);
+			goto err_create_frq_attr;
+		}
+
+		ret = da906x_configure_led_pin(led,
+				led_info->flags & DA906X_LED_LOW_LEVEL_ACTIVE);
+		if (ret) {
+			dev_err(&pdev->dev, "Failed to configure LED pins\n");
+			goto err_configure_pin;
+		}
+	}
+
+	return 0;
+
+err_register:
+	while (--i >= 0) {
+err_configure_pin:
+		device_remove_file(leds->led[i].cdev.dev,
+				   &dev_attr_hw_blink_frq_regval);
+err_create_frq_attr:
+		device_remove_file(leds->led[i].cdev.dev,
+				   &dev_attr_hw_blink_dur_regval);
+err_create_dur_attr:
+		cancel_work_sync(&leds->led[i].work);
+		led_classdev_unregister(&leds->led[i].cdev);
+	}
+
+	kfree(leds);
+
+	return ret;
+}
+
+static int da906x_led_remove(struct platform_device *pdev)
+{
+	struct da906x_leds *leds = platform_get_drvdata(pdev);
+	int i;
+
+	for (i = leds->n_leds - 1; i >= 0; i--) {
+		device_remove_file(leds->led[i].cdev.dev,
+				   &dev_attr_hw_blink_frq_regval);
+		device_remove_file(leds->led[i].cdev.dev,
+				   &dev_attr_hw_blink_dur_regval);
+		cancel_work_sync(&leds->led[i].work);
+		led_classdev_unregister(&leds->led[i].cdev);
+	}
+
+	kfree(leds);
+
+	return 0;
+}
+
+static struct platform_driver da906x_led_driver = {
+	.driver = {
+		.name = DRIVER_NAME,
+		.owner = THIS_MODULE,
+	},
+	.probe = da906x_led_probe,
+	.remove = __devexit_p(da906x_led_remove),
+};
+
+module_platform_driver(da906x_led_driver);
+
+MODULE_DESCRIPTION("LED driver for Dialog DA906X");
+MODULE_AUTHOR("Mariusz Wojtasik <mariusz.wojtasik@diasemi.com>, Krystian Garbaciak <krystian.garbaciak@diasemi.com>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DRIVER_NAME);
-- 
1.7.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 66+ messages in thread

* Re: [RFC PATCH 4/8] hwmon: Add DA906x hardware monitoring support.
  2012-08-24 14:05         ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-24 18:45           ` Guenter Roeck
  -1 siblings, 0 replies; 66+ messages in thread
From: Guenter Roeck @ 2012-08-24 18:45 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Mark Brown,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech

On Fri, Aug 24, 2012 at 03:05:00PM +0100, Krystian Garbaciak wrote:
> DA906x PMIC provides ADC for voltage and temperature monitoring.
> 
Hi Krystian,

DA906x seems to be a bad choice for a name. It covers DA906[0-9] and possibly
even DA906[A-Z]. The only chip really in existence seems to be DA9064.

I personally think it is a bad idea to have an 'x' in a driver name. What if
DA9069 shows up at some point and is completely different ? I think the driver
should be named for the first supported chip; reference the others in the code
and documentation.

Worse, I find no information anywhere in your patch set indicating which chips
are actually supported. I don't know how other subsystems handle this, but for
hwmon this is a no-go.

> The driver provides results of following ADC channels:
>  - in0 - system voltage (2500 - 5500 mV)
>  - in1 - universal voltage channel #1 (0 - 2500 mV)
>  - in2 - universal voltage channel #2 (0 - 2500 mV)
>  - in3 - universal voltage channel #3 (0 - 2500 mV)
>  - in4 - backup battery voltage (0 - 5000 mV)
>  - temp1 - PMIC internal junction temperature (-88 - 333 Celcius degrees)
> 
> Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
> ---
>  drivers/hwmon/Kconfig        |    6 +
>  drivers/hwmon/Makefile       |    1 +
>  drivers/hwmon/da906x-hwmon.c |  393 ++++++++++++++++++++++++++++++++++++++++++

Also please provide Documentation/hwmon/da906x-hwmon.

>  3 files changed, 400 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/hwmon/da906x-hwmon.c
> 
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index b0a2e4c..7abc9a0 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -1373,6 +1373,12 @@ config SENSORS_WM8350
>  	  This driver can also be built as a module.  If so, the module
>  	  will be called wm8350-hwmon.
>  
> +config SENSORS_DA906X
> +	tristate "DA906X HWMON device drivers"
> +	depends on MFD_DA906X
> +	help
> +	  Support for the HWMON DA906X device driver.
> +

Alphabetical order, please, and describe which chip(s) are supported. And you
don't really support a device driver, the device driver presumably supports a
chip. Since it is tristate, we also expect you to provide the module name if the
driver is built as module.

>  config SENSORS_ULTRA45
>  	tristate "Sun Ultra45 PIC16F747"
>  	depends on SPARC64
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index 7aa9811..ffbe151 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -43,6 +43,7 @@ obj-$(CONFIG_SENSORS_ASC7621)	+= asc7621.o
>  obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
>  obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
>  obj-$(CONFIG_SENSORS_DA9052_ADC)+= da9052-hwmon.o
> +obj-$(CONFIG_SENSORS_DA906X)	+= da906x-hwmon.o
>  obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
>  obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
>  obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
> diff --git a/drivers/hwmon/da906x-hwmon.c b/drivers/hwmon/da906x-hwmon.c
> new file mode 100644
> index 0000000..8ece931
> --- /dev/null
> +++ b/drivers/hwmon/da906x-hwmon.c
> @@ -0,0 +1,393 @@
> +/*
> + * HW Monitor support for Dialog DA906X PMIC series
> + *
> + * Copyright 2012 Dialog Semiconductor Ltd.
> + *
> + * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>,
> + *         Michal Hajduk <michal.hajduk@diasemi.com>
> + *
> + *  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/err.h>
> +#include <linux/delay.h>
> +#include <linux/init.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +#include <linux/platform_device.h>
> +#include <linux/hwmon.h>
> +#include <linux/hwmon-sysfs.h>
> +#include <linux/mfd/da906x/core.h>
> +#include <linux/mfd/da906x/pdata.h>
> +
> +/* ADC resolutions for manual and auto modes */
> +#define DA906X_ADC_RES		\
> +		(1 << (DA906X_ADC_RES_L_BITS + DA906X_ADC_RES_M_BITS))
> +#define DA906X_ADC_MAX		(DA906X_ADC_RES - 1)
> +#define	DA906X_ADC_AUTO_RES	(1 << DA906X_ADC_RES_M_BITS)
> +#define	DA906X_ADC_AUTO_MAX	(DA906X_ADC_AUTO_RES - 1)
> +
> +/* Define interpolation table to calculate ADC values  */
> +struct i_table {
> +	int x0;
> +	int a;
> +	int b;
> +};
> +#define ILINE(x1, x2, y1, y2)	{ \
> +		.x0 = (x1), \
> +		.a = ((y2) - (y1)) * DA906X_ADC_RES / ((x2) - (x1)), \
> +		.b = (y1) - ((y2) - (y1)) * (x1) / ((x2) - (x1)), \
> +	}
> +
> +struct channel_info {
> +	const char *name;
> +	const struct i_table *tbl;
> +	int tbl_max;
> +	u16 reg_auto_en;
> +};
> +
> +enum da906x_adc {
> +	DA906X_VSYS,
> +	DA906X_ADCIN1,
> +	DA906X_ADCIN2,
> +	DA906X_ADCIN3,
> +	DA906X_TJUNC,
> +	DA906X_VBBAT,
> +
> +	DA906X_CHAN_NUM
> +};
> +
> +static const struct i_table vsys_tbl[] = {
> +	ILINE(0, DA906X_ADC_MAX, 2500, 5500)
> +};
> +
> +static const struct i_table adcin_tbl[] = {
> +	ILINE(0, DA906X_ADC_MAX, 0, 2500)
> +};
> +
> +static const struct i_table tjunc_tbl[] = {
> +	ILINE(0, DA906X_ADC_MAX, 333, -86)
> +};
> +
> +static const struct i_table vbbat_tbl[] = {
> +	ILINE(0, DA906X_ADC_MAX, 0, 5000)
> +};

Since the first parameter to ILINE is always 0, it is not needed. This means
that x0 in itable is also always 0 and thus not needed. 

> +
> +static const struct channel_info da906x_channels[] = {
> +	[DA906X_VSYS]	= { "VSYS",
> +			    vsys_tbl, ARRAY_SIZE(vsys_tbl) - 1,
> +			    DA906X_REG_VSYS_RES },
> +	[DA906X_ADCIN1]	= { "ADCIN1",
> +			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
> +			    DA906X_REG_ADCIN1_RES },
> +	[DA906X_ADCIN2]	= { "ADCIN2",
> +			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
> +			    DA906X_REG_ADCIN2_RES },
> +	[DA906X_ADCIN3]	= { "ADCIN3",
> +			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
> +			    DA906X_REG_ADCIN3_RES },
> +	[DA906X_TJUNC]	= { "TJUNC",
> +			    tjunc_tbl,	ARRAY_SIZE(tjunc_tbl) - 1 },
> +	[DA906X_VBBAT]	= { "VBBAT",
> +			    vbbat_tbl,	ARRAY_SIZE(vbbat_tbl) - 1}

	s/1}/1 }/

> +};

You lost me here a bit (I am missing something ?).

Seems to be each table has exactly one entry. Since the table size is 1,
ARRAY_SIZE(vbbat_tbl) - 1 is 0, and ...

> +#define DA906X_ADC_AUTO_MODE_SUPPORT_MASK	(DA906X_ADC_AUTO_VSYS_EN | \
> +						 DA906X_ADC_AUTO_AD1_EN | \
> +						 DA906X_ADC_AUTO_AD2_EN | \
> +						 DA906X_ADC_AUTO_AD3_EN)
> +
> +struct da906x_hwmon {
> +	struct da906x *da906x;
> +	struct device *class_dev;
> +	struct completion man_adc_rdy;	/* Manual read completion flag */
> +	struct mutex hwmon_mutex;	/* Queue concurent manual reads */
> +	int irq;
> +	u8 adc_auto_en;     /* Bitmask of channels with auto mode enabled */
> +	s8 tjunc_offset;    /* Calibration offset for junction temperature */
> +};
> +
> +int da906x_adc_convert(int channel, int x)
> +{
> +	const struct channel_info *info = &da906x_channels[channel];
> +	int i, ret;
> +
> +	for (i = info->tbl_max; i > 0; i--)
> +		if (info->tbl[i].x0 <= x)
> +			break;

... this loop never does anything because info->tbl_max is always 0.
Besides, even if the loop was used, x0 is always 0 anyway, so you might well
compare against 0 instead which doesn't make sense.

So what is the point for making the code that complex ? For me it just adds a
lot of confusion.

> +
> +	ret = info->tbl[i].a * x;
> +	if (ret >= 0)
> +		ret += DA906X_ADC_RES / 2;
> +	else
> +		ret -= DA906X_ADC_RES / 2;
> +	ret = ret / DA906X_ADC_RES + info->tbl[i].b;

	ret = DIV_ROUND_CLOSEST(ret, DA906X_ADC_RES) + info->tbl[i].b;

has the same effect as the 5 lines above and is simpler.

> +	return ret;
> +}
> +
> +static int da906x_adc_manual_read(struct da906x_hwmon *hwmon, int channel)
> +{
> +	int ret;
> +	u8 data[2];
> +
> +	mutex_lock(&hwmon->hwmon_mutex);
> +
> +	init_completion(&hwmon->man_adc_rdy);
> +
> +	/* Start measurment on selected channel */
> +	data[0] = (channel << DA906X_ADC_MUX_SHIFT) & DA906X_ADC_MUX_MASK;
> +	data[0] |= DA906X_ADC_MAN;
> +	ret = da906x_reg_update(hwmon->da906x, DA906X_REG_ADC_MAN,
> +				DA906X_ADC_MUX_MASK | DA906X_ADC_MAN, data[0]);
> +	if (ret < 0)
> +		goto out;
> +
> +	/* Wait for interrupt from ADC */
> +	ret = wait_for_completion_timeout(&hwmon->man_adc_rdy,
> +					  msecs_to_jiffies(1000));
> +	if (ret == 0) {
> +		ret = -EBUSY;

Should this be -ETIMEDOUT ?

> +		goto out;
> +	}
> +
> +	/* Get results */
> +	ret = da906x_block_read(hwmon->da906x, DA906X_REG_ADC_RES_L, 2, data);
> +	if (ret < 0)
> +		goto out;
> +	ret = (data[0] & DA906X_ADC_RES_L_MASK) >> DA906X_ADC_RES_L_SHIFT;
> +	ret |= data[1] << DA906X_ADC_RES_L_BITS;
> +out:
> +	mutex_unlock(&hwmon->hwmon_mutex);
> +	return ret;
> +}
> +
> +static int da906x_adc_auto_read(struct da906x *da906x, int channel)
> +{
> +	const struct channel_info *info = &da906x_channels[channel];
> +
> +	return da906x_reg_read(da906x, info->reg_auto_en);
> +}
> +
> +static irqreturn_t da906x_hwmon_irq_handler(int irq, void *irq_data)
> +{
> +	struct da906x_hwmon *hwmon = irq_data;
> +
> +	complete(&hwmon->man_adc_rdy);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static ssize_t da906x_adc_read(struct device *dev,
> +			       struct device_attribute *devattr, char *buf)
> +{
> +	struct da906x_hwmon *hwmon = dev_get_drvdata(dev);
> +	int channel = to_sensor_dev_attr(devattr)->index;
> +	int val;
> +
> +	if (hwmon->adc_auto_en & (1 << channel)) {
> +		val = da906x_adc_auto_read(hwmon->da906x, channel);
> +		if (val < 0)
> +			return val;
> +
> +		val *= DA906X_ADC_RES / DA906X_ADC_AUTO_RES;
> +		val = da906x_adc_convert(channel, val);
> +	} else {
> +		val = da906x_adc_manual_read(hwmon, channel);
> +		if (val < 0)
> +			return val;
> +
> +		if (channel == DA906X_TJUNC)
> +			val += hwmon->tjunc_offset;
> +		val = da906x_adc_convert(channel, val);

This call is really the same for both the if and else path. Might as well put it
after the conditional code.

> +	}
> +
> +	return sprintf(buf, "%d\n", val);
> +}
> +
> +static ssize_t da906x_show_name(struct device *dev,
> +	struct device_attribute *attr, char *buf)


Please align all multi-line function parameters with the opening (.

> +{
> +	return sprintf(buf, DA906X_DRVNAME_HWMON "\n");
> +}
> +
> +static ssize_t da906x_show_label(struct device *dev,
> +				 struct device_attribute *devattr, char *buf)
> +{
> +	const struct channel_info *info;
> +
> +	info = &da906x_channels[to_sensor_dev_attr(devattr)->index];
> +	return sprintf(buf, "%s\n", info->name);
> +}
> +
> +/* Vsys voltage */
> +static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO,
> +			  da906x_adc_read, NULL, DA906X_VSYS);
> +static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO,
> +			  da906x_show_label, NULL, DA906X_VSYS);
> +
> +/* Universal ADC channel #1 */
> +static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO,
> +			  da906x_adc_read, NULL, DA906X_ADCIN1);
> +static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO,
> +			  da906x_show_label, NULL, DA906X_ADCIN1);
> +
> +/* Universal ADC channel #2 */
> +static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO,
> +			  da906x_adc_read, NULL,
> +			  DA906X_ADCIN2);
> +static SENSOR_DEVICE_ATTR(in2_label, S_IRUGO,
> +			  da906x_show_label, NULL, DA906X_ADCIN2);
> +
> +/* Universal ADC channel #3 */
> +static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO,
> +			  da906x_adc_read, NULL, DA906X_ADCIN3);
> +static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO,
> +			  da906x_show_label, NULL, DA906X_ADCIN3);
> +
> +/* Backup battery voltage */
> +static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO,
> +			  da906x_adc_read, NULL, DA906X_VBBAT);
> +static SENSOR_DEVICE_ATTR(in4_label, S_IRUGO,
> +			  da906x_show_label, NULL, DA906X_VBBAT);
> +
> +/* Junction temperature */
> +static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
> +			  da906x_adc_read, NULL, DA906X_TJUNC);
> +
> +static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO,
> +			  da906x_show_label, NULL, DA906X_TJUNC);
> +
> +/* Device name */
> +static DEVICE_ATTR(name, S_IRUGO, da906x_show_name, NULL);
> +
> +static struct attribute *da906x_attributes[] = {
> +	&dev_attr_name.attr,
> +	&sensor_dev_attr_in0_input.dev_attr.attr,
> +	&sensor_dev_attr_in0_label.dev_attr.attr,
> +	&sensor_dev_attr_in1_input.dev_attr.attr,
> +	&sensor_dev_attr_in1_label.dev_attr.attr,
> +	&sensor_dev_attr_in2_input.dev_attr.attr,
> +	&sensor_dev_attr_in2_label.dev_attr.attr,
> +	&sensor_dev_attr_in3_input.dev_attr.attr,
> +	&sensor_dev_attr_in3_label.dev_attr.attr,
> +	&sensor_dev_attr_in4_input.dev_attr.attr,
> +	&sensor_dev_attr_in4_label.dev_attr.attr,
> +	&sensor_dev_attr_temp1_input.dev_attr.attr,
> +	&sensor_dev_attr_temp1_label.dev_attr.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group da906x_attr_group = {
> +	.attrs = da906x_attributes,
> +};
> +
> +static int __devinit da906x_hwmon_probe(struct platform_device *pdev)
> +{
> +	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
> +	struct da906x_pdata *da906x_pdata = dev_get_platdata(da906x->dev);
> +	struct da906x_hwmon *hwmon;
> +	int ret;
> +
> +	hwmon = devm_kzalloc(&pdev->dev, sizeof(struct da906x_hwmon),
> +			     GFP_KERNEL);
> +	if (!hwmon)
> +		return -ENOMEM;
> +
> +	mutex_init(&hwmon->hwmon_mutex);
> +	init_completion(&hwmon->man_adc_rdy);
> +	hwmon->da906x = da906x;
> +
> +	ret = da906x_reg_read(da906x, DA906X_REG_ADC_CONT);
> +	if (ret < 0)
> +		return ret;
> +	hwmon->adc_auto_en = ret & DA906X_ADC_AUTO_MODE_SUPPORT_MASK;
> +
> +	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN0_MANUAL_MODE)

You should check if da906x_pdata is NULL before using it.

> +		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_VSYS_EN;
> +	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN0_AUTO_MODE)
> +		hwmon->adc_auto_en |= DA906X_ADC_AUTO_VSYS_EN;
> +
> +	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN1_MANUAL_MODE)
> +		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD1_EN;
> +	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN1_AUTO_MODE)
> +		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD1_EN;
> +
> +	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN2_MANUAL_MODE)
> +		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD2_EN;
> +	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN2_AUTO_MODE)
> +		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD2_EN;
> +
> +	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN3_MANUAL_MODE)
> +		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD3_EN;
> +	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN3_AUTO_MODE)
> +		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD3_EN;
> +
> +	ret = da906x_reg_update(da906x, DA906X_REG_ADC_CONT,
> +				DA906X_ADC_AUTO_MODE_SUPPORT_MASK,
> +				hwmon->adc_auto_en);
> +	if (ret < 0)
> +		return ret;
> +
> +	hwmon->class_dev = hwmon_device_register(&pdev->dev);
> +	if (IS_ERR(hwmon->class_dev))
> +		return PTR_ERR(hwmon->class_dev);
> +
hwmon registration has to be the last call, after sysfs attributes exist.
sysfs entries are expected to exist when the hwmon device is registered.

> +	hwmon->irq = platform_get_irq_byname(pdev, DA906X_DRVNAME_HWMON);

This function can return an error (-ENXIO).

> +	ret = devm_request_threaded_irq(&pdev->dev, hwmon->irq, NULL,
> +					da906x_hwmon_irq_handler,
> +					IRQF_TRIGGER_LOW | IRQF_ONESHOT,
> +					"HWMON", hwmon);
> +	if (ret) {
> +		dev_err(&pdev->dev, "Failed to request IRQ.\n");
> +		goto err;
> +	}
> +
> +	platform_set_drvdata(pdev, hwmon);
> +
> +	ret = da906x_reg_read(da906x, DA906X_REG_T_OFFSET);
> +	if (ret < 0)
> +		dev_warn(&pdev->dev, "Could not read temp1 callibration offset.\n");

	s/callibration/calibration/

> +	else
> +		hwmon->tjunc_offset = (s8)ret;
> +
> +	ret = sysfs_create_group(&pdev->dev.kobj, &da906x_attr_group);
> +	if (ret)
> +		goto err;
> +
> +	return 0;
> +
> +err:
> +	hwmon_device_unregister(hwmon->class_dev);
> +	return ret;
> +}
> +
> +static int __devexit da906x_hwmon_remove(struct platform_device *pdev)
> +{
> +	struct da906x_hwmon *hwmon = platform_get_drvdata(pdev);
> +
> +	hwmon_device_unregister(hwmon->class_dev);
> +	sysfs_remove_group(&pdev->dev.kobj, &da906x_attr_group);
> +
> +	return 0;
> +}
> +
> +static struct platform_driver da906x_hwmon_driver = {
> +	.probe = da906x_hwmon_probe,
> +	.remove = __devexit_p(da906x_hwmon_remove),
> +	.driver = {
> +		.name = DA906X_DRVNAME_HWMON,
> +		.owner = THIS_MODULE,
> +	},
> +};
> +
> +module_platform_driver(da906x_hwmon_driver);
> +
> +MODULE_DESCRIPTION("DA906X Hardware monitoring");
> +MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>, Michal Hajduk <michal.hajduk@diasemi.com>");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("paltform:" DA906X_DRVNAME_HWMON);

s/paltform/platform/

> -- 
> 1.7.0.4
> 
> 

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [lm-sensors] [RFC PATCH 4/8] hwmon: Add DA906x hardware monitoring support.
@ 2012-08-24 18:45           ` Guenter Roeck
  0 siblings, 0 replies; 66+ messages in thread
From: Guenter Roeck @ 2012-08-24 18:45 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Mark Brown,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech

On Fri, Aug 24, 2012 at 03:05:00PM +0100, Krystian Garbaciak wrote:
> DA906x PMIC provides ADC for voltage and temperature monitoring.
> 
Hi Krystian,

DA906x seems to be a bad choice for a name. It covers DA906[0-9] and possibly
even DA906[A-Z]. The only chip really in existence seems to be DA9064.

I personally think it is a bad idea to have an 'x' in a driver name. What if
DA9069 shows up at some point and is completely different ? I think the driver
should be named for the first supported chip; reference the others in the code
and documentation.

Worse, I find no information anywhere in your patch set indicating which chips
are actually supported. I don't know how other subsystems handle this, but for
hwmon this is a no-go.

> The driver provides results of following ADC channels:
>  - in0 - system voltage (2500 - 5500 mV)
>  - in1 - universal voltage channel #1 (0 - 2500 mV)
>  - in2 - universal voltage channel #2 (0 - 2500 mV)
>  - in3 - universal voltage channel #3 (0 - 2500 mV)
>  - in4 - backup battery voltage (0 - 5000 mV)
>  - temp1 - PMIC internal junction temperature (-88 - 333 Celcius degrees)
> 
> Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
> ---
>  drivers/hwmon/Kconfig        |    6 +
>  drivers/hwmon/Makefile       |    1 +
>  drivers/hwmon/da906x-hwmon.c |  393 ++++++++++++++++++++++++++++++++++++++++++

Also please provide Documentation/hwmon/da906x-hwmon.

>  3 files changed, 400 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/hwmon/da906x-hwmon.c
> 
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index b0a2e4c..7abc9a0 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -1373,6 +1373,12 @@ config SENSORS_WM8350
>  	  This driver can also be built as a module.  If so, the module
>  	  will be called wm8350-hwmon.
>  
> +config SENSORS_DA906X
> +	tristate "DA906X HWMON device drivers"
> +	depends on MFD_DA906X
> +	help
> +	  Support for the HWMON DA906X device driver.
> +

Alphabetical order, please, and describe which chip(s) are supported. And you
don't really support a device driver, the device driver presumably supports a
chip. Since it is tristate, we also expect you to provide the module name if the
driver is built as module.

>  config SENSORS_ULTRA45
>  	tristate "Sun Ultra45 PIC16F747"
>  	depends on SPARC64
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index 7aa9811..ffbe151 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -43,6 +43,7 @@ obj-$(CONFIG_SENSORS_ASC7621)	+= asc7621.o
>  obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
>  obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
>  obj-$(CONFIG_SENSORS_DA9052_ADC)+= da9052-hwmon.o
> +obj-$(CONFIG_SENSORS_DA906X)	+= da906x-hwmon.o
>  obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
>  obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
>  obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
> diff --git a/drivers/hwmon/da906x-hwmon.c b/drivers/hwmon/da906x-hwmon.c
> new file mode 100644
> index 0000000..8ece931
> --- /dev/null
> +++ b/drivers/hwmon/da906x-hwmon.c
> @@ -0,0 +1,393 @@
> +/*
> + * HW Monitor support for Dialog DA906X PMIC series
> + *
> + * Copyright 2012 Dialog Semiconductor Ltd.
> + *
> + * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>,
> + *         Michal Hajduk <michal.hajduk@diasemi.com>
> + *
> + *  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/err.h>
> +#include <linux/delay.h>
> +#include <linux/init.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +#include <linux/platform_device.h>
> +#include <linux/hwmon.h>
> +#include <linux/hwmon-sysfs.h>
> +#include <linux/mfd/da906x/core.h>
> +#include <linux/mfd/da906x/pdata.h>
> +
> +/* ADC resolutions for manual and auto modes */
> +#define DA906X_ADC_RES		\
> +		(1 << (DA906X_ADC_RES_L_BITS + DA906X_ADC_RES_M_BITS))
> +#define DA906X_ADC_MAX		(DA906X_ADC_RES - 1)
> +#define	DA906X_ADC_AUTO_RES	(1 << DA906X_ADC_RES_M_BITS)
> +#define	DA906X_ADC_AUTO_MAX	(DA906X_ADC_AUTO_RES - 1)
> +
> +/* Define interpolation table to calculate ADC values  */
> +struct i_table {
> +	int x0;
> +	int a;
> +	int b;
> +};
> +#define ILINE(x1, x2, y1, y2)	{ \
> +		.x0 = (x1), \
> +		.a = ((y2) - (y1)) * DA906X_ADC_RES / ((x2) - (x1)), \
> +		.b = (y1) - ((y2) - (y1)) * (x1) / ((x2) - (x1)), \
> +	}
> +
> +struct channel_info {
> +	const char *name;
> +	const struct i_table *tbl;
> +	int tbl_max;
> +	u16 reg_auto_en;
> +};
> +
> +enum da906x_adc {
> +	DA906X_VSYS,
> +	DA906X_ADCIN1,
> +	DA906X_ADCIN2,
> +	DA906X_ADCIN3,
> +	DA906X_TJUNC,
> +	DA906X_VBBAT,
> +
> +	DA906X_CHAN_NUM
> +};
> +
> +static const struct i_table vsys_tbl[] = {
> +	ILINE(0, DA906X_ADC_MAX, 2500, 5500)
> +};
> +
> +static const struct i_table adcin_tbl[] = {
> +	ILINE(0, DA906X_ADC_MAX, 0, 2500)
> +};
> +
> +static const struct i_table tjunc_tbl[] = {
> +	ILINE(0, DA906X_ADC_MAX, 333, -86)
> +};
> +
> +static const struct i_table vbbat_tbl[] = {
> +	ILINE(0, DA906X_ADC_MAX, 0, 5000)
> +};

Since the first parameter to ILINE is always 0, it is not needed. This means
that x0 in itable is also always 0 and thus not needed. 

> +
> +static const struct channel_info da906x_channels[] = {
> +	[DA906X_VSYS]	= { "VSYS",
> +			    vsys_tbl, ARRAY_SIZE(vsys_tbl) - 1,
> +			    DA906X_REG_VSYS_RES },
> +	[DA906X_ADCIN1]	= { "ADCIN1",
> +			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
> +			    DA906X_REG_ADCIN1_RES },
> +	[DA906X_ADCIN2]	= { "ADCIN2",
> +			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
> +			    DA906X_REG_ADCIN2_RES },
> +	[DA906X_ADCIN3]	= { "ADCIN3",
> +			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
> +			    DA906X_REG_ADCIN3_RES },
> +	[DA906X_TJUNC]	= { "TJUNC",
> +			    tjunc_tbl,	ARRAY_SIZE(tjunc_tbl) - 1 },
> +	[DA906X_VBBAT]	= { "VBBAT",
> +			    vbbat_tbl,	ARRAY_SIZE(vbbat_tbl) - 1}

	s/1}/1 }/

> +};

You lost me here a bit (I am missing something ?).

Seems to be each table has exactly one entry. Since the table size is 1,
ARRAY_SIZE(vbbat_tbl) - 1 is 0, and ...

> +#define DA906X_ADC_AUTO_MODE_SUPPORT_MASK	(DA906X_ADC_AUTO_VSYS_EN | \
> +						 DA906X_ADC_AUTO_AD1_EN | \
> +						 DA906X_ADC_AUTO_AD2_EN | \
> +						 DA906X_ADC_AUTO_AD3_EN)
> +
> +struct da906x_hwmon {
> +	struct da906x *da906x;
> +	struct device *class_dev;
> +	struct completion man_adc_rdy;	/* Manual read completion flag */
> +	struct mutex hwmon_mutex;	/* Queue concurent manual reads */
> +	int irq;
> +	u8 adc_auto_en;     /* Bitmask of channels with auto mode enabled */
> +	s8 tjunc_offset;    /* Calibration offset for junction temperature */
> +};
> +
> +int da906x_adc_convert(int channel, int x)
> +{
> +	const struct channel_info *info = &da906x_channels[channel];
> +	int i, ret;
> +
> +	for (i = info->tbl_max; i > 0; i--)
> +		if (info->tbl[i].x0 <= x)
> +			break;

... this loop never does anything because info->tbl_max is always 0.
Besides, even if the loop was used, x0 is always 0 anyway, so you might well
compare against 0 instead which doesn't make sense.

So what is the point for making the code that complex ? For me it just adds a
lot of confusion.

> +
> +	ret = info->tbl[i].a * x;
> +	if (ret >= 0)
> +		ret += DA906X_ADC_RES / 2;
> +	else
> +		ret -= DA906X_ADC_RES / 2;
> +	ret = ret / DA906X_ADC_RES + info->tbl[i].b;

	ret = DIV_ROUND_CLOSEST(ret, DA906X_ADC_RES) + info->tbl[i].b;

has the same effect as the 5 lines above and is simpler.

> +	return ret;
> +}
> +
> +static int da906x_adc_manual_read(struct da906x_hwmon *hwmon, int channel)
> +{
> +	int ret;
> +	u8 data[2];
> +
> +	mutex_lock(&hwmon->hwmon_mutex);
> +
> +	init_completion(&hwmon->man_adc_rdy);
> +
> +	/* Start measurment on selected channel */
> +	data[0] = (channel << DA906X_ADC_MUX_SHIFT) & DA906X_ADC_MUX_MASK;
> +	data[0] |= DA906X_ADC_MAN;
> +	ret = da906x_reg_update(hwmon->da906x, DA906X_REG_ADC_MAN,
> +				DA906X_ADC_MUX_MASK | DA906X_ADC_MAN, data[0]);
> +	if (ret < 0)
> +		goto out;
> +
> +	/* Wait for interrupt from ADC */
> +	ret = wait_for_completion_timeout(&hwmon->man_adc_rdy,
> +					  msecs_to_jiffies(1000));
> +	if (ret = 0) {
> +		ret = -EBUSY;

Should this be -ETIMEDOUT ?

> +		goto out;
> +	}
> +
> +	/* Get results */
> +	ret = da906x_block_read(hwmon->da906x, DA906X_REG_ADC_RES_L, 2, data);
> +	if (ret < 0)
> +		goto out;
> +	ret = (data[0] & DA906X_ADC_RES_L_MASK) >> DA906X_ADC_RES_L_SHIFT;
> +	ret |= data[1] << DA906X_ADC_RES_L_BITS;
> +out:
> +	mutex_unlock(&hwmon->hwmon_mutex);
> +	return ret;
> +}
> +
> +static int da906x_adc_auto_read(struct da906x *da906x, int channel)
> +{
> +	const struct channel_info *info = &da906x_channels[channel];
> +
> +	return da906x_reg_read(da906x, info->reg_auto_en);
> +}
> +
> +static irqreturn_t da906x_hwmon_irq_handler(int irq, void *irq_data)
> +{
> +	struct da906x_hwmon *hwmon = irq_data;
> +
> +	complete(&hwmon->man_adc_rdy);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static ssize_t da906x_adc_read(struct device *dev,
> +			       struct device_attribute *devattr, char *buf)
> +{
> +	struct da906x_hwmon *hwmon = dev_get_drvdata(dev);
> +	int channel = to_sensor_dev_attr(devattr)->index;
> +	int val;
> +
> +	if (hwmon->adc_auto_en & (1 << channel)) {
> +		val = da906x_adc_auto_read(hwmon->da906x, channel);
> +		if (val < 0)
> +			return val;
> +
> +		val *= DA906X_ADC_RES / DA906X_ADC_AUTO_RES;
> +		val = da906x_adc_convert(channel, val);
> +	} else {
> +		val = da906x_adc_manual_read(hwmon, channel);
> +		if (val < 0)
> +			return val;
> +
> +		if (channel = DA906X_TJUNC)
> +			val += hwmon->tjunc_offset;
> +		val = da906x_adc_convert(channel, val);

This call is really the same for both the if and else path. Might as well put it
after the conditional code.

> +	}
> +
> +	return sprintf(buf, "%d\n", val);
> +}
> +
> +static ssize_t da906x_show_name(struct device *dev,
> +	struct device_attribute *attr, char *buf)


Please align all multi-line function parameters with the opening (.

> +{
> +	return sprintf(buf, DA906X_DRVNAME_HWMON "\n");
> +}
> +
> +static ssize_t da906x_show_label(struct device *dev,
> +				 struct device_attribute *devattr, char *buf)
> +{
> +	const struct channel_info *info;
> +
> +	info = &da906x_channels[to_sensor_dev_attr(devattr)->index];
> +	return sprintf(buf, "%s\n", info->name);
> +}
> +
> +/* Vsys voltage */
> +static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO,
> +			  da906x_adc_read, NULL, DA906X_VSYS);
> +static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO,
> +			  da906x_show_label, NULL, DA906X_VSYS);
> +
> +/* Universal ADC channel #1 */
> +static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO,
> +			  da906x_adc_read, NULL, DA906X_ADCIN1);
> +static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO,
> +			  da906x_show_label, NULL, DA906X_ADCIN1);
> +
> +/* Universal ADC channel #2 */
> +static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO,
> +			  da906x_adc_read, NULL,
> +			  DA906X_ADCIN2);
> +static SENSOR_DEVICE_ATTR(in2_label, S_IRUGO,
> +			  da906x_show_label, NULL, DA906X_ADCIN2);
> +
> +/* Universal ADC channel #3 */
> +static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO,
> +			  da906x_adc_read, NULL, DA906X_ADCIN3);
> +static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO,
> +			  da906x_show_label, NULL, DA906X_ADCIN3);
> +
> +/* Backup battery voltage */
> +static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO,
> +			  da906x_adc_read, NULL, DA906X_VBBAT);
> +static SENSOR_DEVICE_ATTR(in4_label, S_IRUGO,
> +			  da906x_show_label, NULL, DA906X_VBBAT);
> +
> +/* Junction temperature */
> +static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
> +			  da906x_adc_read, NULL, DA906X_TJUNC);
> +
> +static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO,
> +			  da906x_show_label, NULL, DA906X_TJUNC);
> +
> +/* Device name */
> +static DEVICE_ATTR(name, S_IRUGO, da906x_show_name, NULL);
> +
> +static struct attribute *da906x_attributes[] = {
> +	&dev_attr_name.attr,
> +	&sensor_dev_attr_in0_input.dev_attr.attr,
> +	&sensor_dev_attr_in0_label.dev_attr.attr,
> +	&sensor_dev_attr_in1_input.dev_attr.attr,
> +	&sensor_dev_attr_in1_label.dev_attr.attr,
> +	&sensor_dev_attr_in2_input.dev_attr.attr,
> +	&sensor_dev_attr_in2_label.dev_attr.attr,
> +	&sensor_dev_attr_in3_input.dev_attr.attr,
> +	&sensor_dev_attr_in3_label.dev_attr.attr,
> +	&sensor_dev_attr_in4_input.dev_attr.attr,
> +	&sensor_dev_attr_in4_label.dev_attr.attr,
> +	&sensor_dev_attr_temp1_input.dev_attr.attr,
> +	&sensor_dev_attr_temp1_label.dev_attr.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group da906x_attr_group = {
> +	.attrs = da906x_attributes,
> +};
> +
> +static int __devinit da906x_hwmon_probe(struct platform_device *pdev)
> +{
> +	struct da906x *da906x = dev_get_drvdata(pdev->dev.parent);
> +	struct da906x_pdata *da906x_pdata = dev_get_platdata(da906x->dev);
> +	struct da906x_hwmon *hwmon;
> +	int ret;
> +
> +	hwmon = devm_kzalloc(&pdev->dev, sizeof(struct da906x_hwmon),
> +			     GFP_KERNEL);
> +	if (!hwmon)
> +		return -ENOMEM;
> +
> +	mutex_init(&hwmon->hwmon_mutex);
> +	init_completion(&hwmon->man_adc_rdy);
> +	hwmon->da906x = da906x;
> +
> +	ret = da906x_reg_read(da906x, DA906X_REG_ADC_CONT);
> +	if (ret < 0)
> +		return ret;
> +	hwmon->adc_auto_en = ret & DA906X_ADC_AUTO_MODE_SUPPORT_MASK;
> +
> +	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN0_MANUAL_MODE)

You should check if da906x_pdata is NULL before using it.

> +		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_VSYS_EN;
> +	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN0_AUTO_MODE)
> +		hwmon->adc_auto_en |= DA906X_ADC_AUTO_VSYS_EN;
> +
> +	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN1_MANUAL_MODE)
> +		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD1_EN;
> +	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN1_AUTO_MODE)
> +		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD1_EN;
> +
> +	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN2_MANUAL_MODE)
> +		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD2_EN;
> +	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN2_AUTO_MODE)
> +		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD2_EN;
> +
> +	if (da906x_pdata->flags & DA906X_FLG_FORCE_IN3_MANUAL_MODE)
> +		hwmon->adc_auto_en &= ~DA906X_ADC_AUTO_AD3_EN;
> +	else if (da906x_pdata->flags & DA906X_FLG_FORCE_IN3_AUTO_MODE)
> +		hwmon->adc_auto_en |= DA906X_ADC_AUTO_AD3_EN;
> +
> +	ret = da906x_reg_update(da906x, DA906X_REG_ADC_CONT,
> +				DA906X_ADC_AUTO_MODE_SUPPORT_MASK,
> +				hwmon->adc_auto_en);
> +	if (ret < 0)
> +		return ret;
> +
> +	hwmon->class_dev = hwmon_device_register(&pdev->dev);
> +	if (IS_ERR(hwmon->class_dev))
> +		return PTR_ERR(hwmon->class_dev);
> +
hwmon registration has to be the last call, after sysfs attributes exist.
sysfs entries are expected to exist when the hwmon device is registered.

> +	hwmon->irq = platform_get_irq_byname(pdev, DA906X_DRVNAME_HWMON);

This function can return an error (-ENXIO).

> +	ret = devm_request_threaded_irq(&pdev->dev, hwmon->irq, NULL,
> +					da906x_hwmon_irq_handler,
> +					IRQF_TRIGGER_LOW | IRQF_ONESHOT,
> +					"HWMON", hwmon);
> +	if (ret) {
> +		dev_err(&pdev->dev, "Failed to request IRQ.\n");
> +		goto err;
> +	}
> +
> +	platform_set_drvdata(pdev, hwmon);
> +
> +	ret = da906x_reg_read(da906x, DA906X_REG_T_OFFSET);
> +	if (ret < 0)
> +		dev_warn(&pdev->dev, "Could not read temp1 callibration offset.\n");

	s/callibration/calibration/

> +	else
> +		hwmon->tjunc_offset = (s8)ret;
> +
> +	ret = sysfs_create_group(&pdev->dev.kobj, &da906x_attr_group);
> +	if (ret)
> +		goto err;
> +
> +	return 0;
> +
> +err:
> +	hwmon_device_unregister(hwmon->class_dev);
> +	return ret;
> +}
> +
> +static int __devexit da906x_hwmon_remove(struct platform_device *pdev)
> +{
> +	struct da906x_hwmon *hwmon = platform_get_drvdata(pdev);
> +
> +	hwmon_device_unregister(hwmon->class_dev);
> +	sysfs_remove_group(&pdev->dev.kobj, &da906x_attr_group);
> +
> +	return 0;
> +}
> +
> +static struct platform_driver da906x_hwmon_driver = {
> +	.probe = da906x_hwmon_probe,
> +	.remove = __devexit_p(da906x_hwmon_remove),
> +	.driver = {
> +		.name = DA906X_DRVNAME_HWMON,
> +		.owner = THIS_MODULE,
> +	},
> +};
> +
> +module_platform_driver(da906x_hwmon_driver);
> +
> +MODULE_DESCRIPTION("DA906X Hardware monitoring");
> +MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>, Michal Hajduk <michal.hajduk@diasemi.com>");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("paltform:" DA906X_DRVNAME_HWMON);

s/paltform/platform/

> -- 
> 1.7.0.4
> 
> 

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
  2012-08-24 13:55     ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-25 15:10       ` Mark Brown
  -1 siblings, 0 replies; 66+ messages in thread
From: Mark Brown @ 2012-08-25 15:10 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Alessandro Zummo,
	Jean Delvare, Guenter Roeck, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech

On Fri, Aug 24, 2012 at 02:55:00PM +0100, Krystian Garbaciak wrote:

> +static int da906x_set_voltage(struct regulator_dev *rdev,
> +				int min_uV, int max_uV, unsigned *selector)
> +{
> +	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
> +	const struct field *fvol = &regl->info->voltage;
> +	int ret;
> +	unsigned val;
> +
> +	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
> +	if (val < 0)
> +		return -EINVAL;
> +
> +	val = (val + fvol->offset) << fvol->shift;
> +	ret = da906x_reg_update(regl->hw, fvol->addr, fvol->mask, val);
> +	if (ret >= 0)
> +		*selector = val;
> +
> +	return ret;
> +}

This is just set_voltage_sel_regmap().

> +static int da906x_enable(struct regulator_dev *rdev)
> +{
> +	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
> +	int ret;
> +
> +	if (regl->info->suspend.mask) {
> +		/* Make sure to exit from suspend mode on enable */
> +		ret = da906x_reg_clear_bits(regl->hw, regl->info->suspend.addr,
> +					    regl->info->suspend.mask);
> +		if (ret < 0)
> +			return ret;
> +
> +		/* BUCKs need mode update after wake-up from suspend state. */
> +		ret = da906x_update_mode_internal(regl, SYS_STATE_NORMAL);
> +		if (ret < 0)
> +			return ret;
> +	}
> +
> +	return regulator_enable_regmap(rdev);

If suspend_mask is optional the regulators using it should just use the
standard operation.

> +/* Regulator event handlers */
> +irqreturn_t da906x_ldo_lim_event(int irq, void *data)

By "event handler" you mean "interrupt"

> +	bits = da906x_reg_read(hw, DA906X_REG_STATUS_D);
> +	if (bits < 0)
> +		return IRQ_HANDLED;

If you fail to detect an interrupt you report that you handled one...?

> +	if (!da906x_pdata) {
> +		dev_err(&pdev->dev, "No platform init data supplied\n");
> +		return -ENODEV;
> +	}

Platform data should be totally optional.

> +	bcores_merged = (ret & DA906X_BCORE_MERGE) ? true : false;
> +	bmem_bio_merged = (ret & DA906X_BUCK_MERGE) ? true : false;

The use of the ternery operation here is even worse than normal, you can
assign the values directly.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [lm-sensors] [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
@ 2012-08-25 15:10       ` Mark Brown
  0 siblings, 0 replies; 66+ messages in thread
From: Mark Brown @ 2012-08-25 15:10 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Alessandro Zummo,
	Jean Delvare, Guenter Roeck, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech

On Fri, Aug 24, 2012 at 02:55:00PM +0100, Krystian Garbaciak wrote:

> +static int da906x_set_voltage(struct regulator_dev *rdev,
> +				int min_uV, int max_uV, unsigned *selector)
> +{
> +	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
> +	const struct field *fvol = &regl->info->voltage;
> +	int ret;
> +	unsigned val;
> +
> +	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
> +	if (val < 0)
> +		return -EINVAL;
> +
> +	val = (val + fvol->offset) << fvol->shift;
> +	ret = da906x_reg_update(regl->hw, fvol->addr, fvol->mask, val);
> +	if (ret >= 0)
> +		*selector = val;
> +
> +	return ret;
> +}

This is just set_voltage_sel_regmap().

> +static int da906x_enable(struct regulator_dev *rdev)
> +{
> +	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
> +	int ret;
> +
> +	if (regl->info->suspend.mask) {
> +		/* Make sure to exit from suspend mode on enable */
> +		ret = da906x_reg_clear_bits(regl->hw, regl->info->suspend.addr,
> +					    regl->info->suspend.mask);
> +		if (ret < 0)
> +			return ret;
> +
> +		/* BUCKs need mode update after wake-up from suspend state. */
> +		ret = da906x_update_mode_internal(regl, SYS_STATE_NORMAL);
> +		if (ret < 0)
> +			return ret;
> +	}
> +
> +	return regulator_enable_regmap(rdev);

If suspend_mask is optional the regulators using it should just use the
standard operation.

> +/* Regulator event handlers */
> +irqreturn_t da906x_ldo_lim_event(int irq, void *data)

By "event handler" you mean "interrupt"

> +	bits = da906x_reg_read(hw, DA906X_REG_STATUS_D);
> +	if (bits < 0)
> +		return IRQ_HANDLED;

If you fail to detect an interrupt you report that you handled one...?

> +	if (!da906x_pdata) {
> +		dev_err(&pdev->dev, "No platform init data supplied\n");
> +		return -ENODEV;
> +	}

Platform data should be totally optional.

> +	bcores_merged = (ret & DA906X_BCORE_MERGE) ? true : false;
> +	bmem_bio_merged = (ret & DA906X_BUCK_MERGE) ? true : false;

The use of the ternery operation here is even worse than normal, you can
assign the values directly.

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 1/8] mfd: Add Dialog DA906x core driver.
  2012-08-24 13:50   ` [lm-sensors] " Krystian Garbaciak
@ 2012-08-25 18:31     ` Mark Brown
  -1 siblings, 0 replies; 66+ messages in thread
From: Mark Brown @ 2012-08-25 18:31 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Alessandro Zummo,
	Jean Delvare, Guenter Roeck, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech

On Fri, Aug 24, 2012 at 02:50:00PM +0100, Krystian Garbaciak wrote:

> This is MFD module providing access to registers and interrupts of DA906x
> series PMIC. It is used by other functional modules, registered as MFD cells.
> Driver uses regmap with paging to access extended register list. Register map
> is divided into two pages, where the second page is used during initialisation.

Your selection of people to CC here appears both large and random...

> +inline unsigned int da906x_to_range_reg(u16 reg)
> +{
> +	return reg + DA906X_MAPPING_BASE;
> +}

I've no real idea what this stuff is all about, it at least needs some
comments somewhere.  The fact that you're just adding a constant offset
to all registers is at best odd.

> +	if (pdata->flags & DA906X_FLG_NO_CACHE)
> +		config = &da906x_no_cache_regmap_config;

No, why would anyone ever want this and why would this not apply to all
other drivers?

> +static const struct i2c_device_id da906x_i2c_id[] = {
> +	{"da906x", PMIC_DA9063},
> +	{},
> +};
> +MODULE_DEVICE_TABLE(i2c, da906x_i2c_id);

List the actual devices here.

> +#define DA906X_IRQ_BASE_OFFSET	0

Hrm?

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [lm-sensors] [PATCH 1/8] mfd: Add Dialog DA906x core driver.
@ 2012-08-25 18:31     ` Mark Brown
  0 siblings, 0 replies; 66+ messages in thread
From: Mark Brown @ 2012-08-25 18:31 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Alessandro Zummo,
	Jean Delvare, Guenter Roeck, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu,
	Richard Purdie <rpurdie@rpsys.net> Anthony Olech

On Fri, Aug 24, 2012 at 02:50:00PM +0100, Krystian Garbaciak wrote:

> This is MFD module providing access to registers and interrupts of DA906x
> series PMIC. It is used by other functional modules, registered as MFD cells.
> Driver uses regmap with paging to access extended register list. Register map
> is divided into two pages, where the second page is used during initialisation.

Your selection of people to CC here appears both large and random...

> +inline unsigned int da906x_to_range_reg(u16 reg)
> +{
> +	return reg + DA906X_MAPPING_BASE;
> +}

I've no real idea what this stuff is all about, it at least needs some
comments somewhere.  The fact that you're just adding a constant offset
to all registers is at best odd.

> +	if (pdata->flags & DA906X_FLG_NO_CACHE)
> +		config = &da906x_no_cache_regmap_config;

No, why would anyone ever want this and why would this not apply to all
other drivers?

> +static const struct i2c_device_id da906x_i2c_id[] = {
> +	{"da906x", PMIC_DA9063},
> +	{},
> +};
> +MODULE_DEVICE_TABLE(i2c, da906x_i2c_id);

List the actual devices here.

> +#define DA906X_IRQ_BASE_OFFSET	0

Hrm?

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH] regulator: Fix bug in regulator_mode_to_status() core function.
  2012-08-24 18:45           ` [lm-sensors] " Guenter Roeck
@ 2012-08-29 13:25             ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-29 13:25 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Mark Brown,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu, Richard Purdie, Anthony Olech

> +static const struct i_table vsys_tbl[] = {
> > +	ILINE(0, DA906X_ADC_MAX, 2500, 5500)
> > +};
> > +
> > +static const struct i_table adcin_tbl[] = {
> > +	ILINE(0, DA906X_ADC_MAX, 0, 2500)
> > +};
> > +
> > +static const struct i_table tjunc_tbl[] = {
> > +	ILINE(0, DA906X_ADC_MAX, 333, -86)
> > +};
> > +
> > +static const struct i_table vbbat_tbl[] = {
> > +	ILINE(0, DA906X_ADC_MAX, 0, 5000)
> > +};
> 
> Since the first parameter to ILINE is always 0, it is not needed. This means
> that x0 in itable is also always 0 and thus not needed.
> 
> > +
> > +static const struct channel_info da906x_channels[] = {
> > +	[DA906X_VSYS]	= { "VSYS",
> > +			    vsys_tbl, ARRAY_SIZE(vsys_tbl) - 1,
> > +			    DA906X_REG_VSYS_RES },
> > +	[DA906X_ADCIN1]	= { "ADCIN1",
> > +			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
> > +			    DA906X_REG_ADCIN1_RES },
> > +	[DA906X_ADCIN2]	= { "ADCIN2",
> > +			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
> > +			    DA906X_REG_ADCIN2_RES },
> > +	[DA906X_ADCIN3]	= { "ADCIN3",
> > +			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
> > +			    DA906X_REG_ADCIN3_RES },
> > +	[DA906X_TJUNC]	= { "TJUNC",
> > +			    tjunc_tbl,	ARRAY_SIZE(tjunc_tbl) - 1 },
> > +	[DA906X_VBBAT]	= { "VBBAT",
> > +			    vbbat_tbl,	ARRAY_SIZE(vbbat_tbl) - 1}
> 
> 	s/1}/1 }/
> 
> > +};
> 
> You lost me here a bit (I am missing something ?).
> 
> Seems to be each table has exactly one entry. Since the table size is 1,
> ARRAY_SIZE(vbbat_tbl) - 1 is 0, and ...

An initial idea was to make the interpolation of the channel values using more
ILINE segments. Eventually, it ended up with one linear segment for every
channel, so it makes sense to reduce the code as you propose.

As suggested, driver name will be changed from "da906x" to "da9063".
I will adapt proposed changes and fixes.

Thank you for your comments,
Krystian


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [lm-sensors] [PATCH] regulator: Fix bug in regulator_mode_to_status() core function.
@ 2012-08-29 13:25             ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-29 13:25 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Mark Brown,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu, Richard Purdie, Anthony Olech

> +static const struct i_table vsys_tbl[] = {
> > +	ILINE(0, DA906X_ADC_MAX, 2500, 5500)
> > +};
> > +
> > +static const struct i_table adcin_tbl[] = {
> > +	ILINE(0, DA906X_ADC_MAX, 0, 2500)
> > +};
> > +
> > +static const struct i_table tjunc_tbl[] = {
> > +	ILINE(0, DA906X_ADC_MAX, 333, -86)
> > +};
> > +
> > +static const struct i_table vbbat_tbl[] = {
> > +	ILINE(0, DA906X_ADC_MAX, 0, 5000)
> > +};
> 
> Since the first parameter to ILINE is always 0, it is not needed. This means
> that x0 in itable is also always 0 and thus not needed.
> 
> > +
> > +static const struct channel_info da906x_channels[] = {
> > +	[DA906X_VSYS]	= { "VSYS",
> > +			    vsys_tbl, ARRAY_SIZE(vsys_tbl) - 1,
> > +			    DA906X_REG_VSYS_RES },
> > +	[DA906X_ADCIN1]	= { "ADCIN1",
> > +			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
> > +			    DA906X_REG_ADCIN1_RES },
> > +	[DA906X_ADCIN2]	= { "ADCIN2",
> > +			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
> > +			    DA906X_REG_ADCIN2_RES },
> > +	[DA906X_ADCIN3]	= { "ADCIN3",
> > +			    adcin_tbl,	ARRAY_SIZE(adcin_tbl) - 1,
> > +			    DA906X_REG_ADCIN3_RES },
> > +	[DA906X_TJUNC]	= { "TJUNC",
> > +			    tjunc_tbl,	ARRAY_SIZE(tjunc_tbl) - 1 },
> > +	[DA906X_VBBAT]	= { "VBBAT",
> > +			    vbbat_tbl,	ARRAY_SIZE(vbbat_tbl) - 1}
> 
> 	s/1}/1 }/
> 
> > +};
> 
> You lost me here a bit (I am missing something ?).
> 
> Seems to be each table has exactly one entry. Since the table size is 1,
> ARRAY_SIZE(vbbat_tbl) - 1 is 0, and ...

An initial idea was to make the interpolation of the channel values using more
ILINE segments. Eventually, it ended up with one linear segment for every
channel, so it makes sense to reduce the code as you propose.

As suggested, driver name will be changed from "da906x" to "da9063".
I will adapt proposed changes and fixes.

Thank you for your comments,
Krystian


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
  2012-08-25 15:10       ` [lm-sensors] " Mark Brown
  (?)
@ 2012-08-29 14:50         ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-29 14:50 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Mark Brown,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu, Richard Purdie, Anthony Olech

> > +static int da906x_set_voltage(struct regulator_dev *rdev,
> > +				int min_uV, int max_uV, unsigned *selector)
> > +{
> > +	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
> > +	const struct field *fvol = &regl->info->voltage;
> > +	int ret;
> > +	unsigned val;
> > +
> > +	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
> > +	if (val < 0)
> > +		return -EINVAL;
> > +
> > +	val = (val + fvol->offset) << fvol->shift;
> > +	ret = da906x_reg_update(regl->hw, fvol->addr, fvol->mask, val);
> > +	if (ret >= 0)
> > +		*selector = val;
> > +
> > +	return ret;
> > +}
> 
> This is just set_voltage_sel_regmap().

Because, for some regulators, this is required: val += fvol->offset,
I was only able to reduce it to the following form.

+static int da9063_set_voltage(struct regulator_dev *rdev,
+			      int min_uV, int max_uV, unsigned *selector)
+{
+	struct da9063_regulator *regl = rdev_get_drvdata(rdev);
+	const struct field *fvol = &regl->info->voltage;
+	int ret;
+	unsigned val;
+
+	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
+	if (val < 0)
+		return -EINVAL;
+
+	val += fvol->offset;
+
+	ret = regulator_set_voltage_sel_regmap(rdev, val);
+	if (ret >= 0)
+		*selector = val;
+
+	return ret;
+}

> > +static int da906x_enable(struct regulator_dev *rdev)
> > +{
> > +	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
> > +	int ret;
> > +
> > +	if (regl->info->suspend.mask) {
> > +		/* Make sure to exit from suspend mode on enable */
> > +		ret = da906x_reg_clear_bits(regl->hw, regl->info->suspend.addr,
> > +					    regl->info->suspend.mask);
> > +		if (ret < 0)
> > +			return ret;
> > +
> > +		/* BUCKs need mode update after wake-up from suspend state. */
> > +		ret = da906x_update_mode_internal(regl, SYS_STATE_NORMAL);
> > +		if (ret < 0)
> > +			return ret;
> > +	}
> > +
> > +	return regulator_enable_regmap(rdev);
> 
> If suspend_mask is optional the regulators using it should just use the
> standard operation.

I guess, you meant here to call regulator_enable_regmap() directly for
regulators NOT using suspend.mask. Then, I will do it.

> > +/* Regulator event handlers */
> > +irqreturn_t da906x_ldo_lim_event(int irq, void *data)
> 
> By "event handler" you mean "interrupt"

Yes. I think, I will update the comment line.

> > +	bits = da906x_reg_read(hw, DA906X_REG_STATUS_D);
> > +	if (bits < 0)
> > +		return IRQ_HANDLED;
> 
> If you fail to detect an interrupt you report that you handled one...?

For me there is no sensible return value for this case.
However, I consider changing the reaction on read failure by reporting event
for all regulators, that might cause this interrupt:
+	bits = da9063_reg_read(hw, DA9063_REG_STATUS_D);
+	if (bits < 0)
+		bits = ~0;

I will update the driver according to your remaining comments.

Thank you for your comments,
Krystian


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
@ 2012-08-29 14:50         ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-29 14:50 UTC (permalink / raw)
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Mark Brown,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu, Richard Purdie, Anthony Olech

> > +static int da906x_set_voltage(struct regulator_dev *rdev,
> > +				int min_uV, int max_uV, unsigned *selector)
> > +{
> > +	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
> > +	const struct field *fvol = &regl->info->voltage;
> > +	int ret;
> > +	unsigned val;
> > +
> > +	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
> > +	if (val < 0)
> > +		return -EINVAL;
> > +
> > +	val = (val + fvol->offset) << fvol->shift;
> > +	ret = da906x_reg_update(regl->hw, fvol->addr, fvol->mask, val);
> > +	if (ret >= 0)
> > +		*selector = val;
> > +
> > +	return ret;
> > +}
> 
> This is just set_voltage_sel_regmap().

Because, for some regulators, this is required: val += fvol->offset,
I was only able to reduce it to the following form.

+static int da9063_set_voltage(struct regulator_dev *rdev,
+			      int min_uV, int max_uV, unsigned *selector)
+{
+	struct da9063_regulator *regl = rdev_get_drvdata(rdev);
+	const struct field *fvol = &regl->info->voltage;
+	int ret;
+	unsigned val;
+
+	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
+	if (val < 0)
+		return -EINVAL;
+
+	val += fvol->offset;
+
+	ret = regulator_set_voltage_sel_regmap(rdev, val);
+	if (ret >= 0)
+		*selector = val;
+
+	return ret;
+}

> > +static int da906x_enable(struct regulator_dev *rdev)
> > +{
> > +	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
> > +	int ret;
> > +
> > +	if (regl->info->suspend.mask) {
> > +		/* Make sure to exit from suspend mode on enable */
> > +		ret = da906x_reg_clear_bits(regl->hw, regl->info->suspend.addr,
> > +					    regl->info->suspend.mask);
> > +		if (ret < 0)
> > +			return ret;
> > +
> > +		/* BUCKs need mode update after wake-up from suspend state. */
> > +		ret = da906x_update_mode_internal(regl, SYS_STATE_NORMAL);
> > +		if (ret < 0)
> > +			return ret;
> > +	}
> > +
> > +	return regulator_enable_regmap(rdev);
> 
> If suspend_mask is optional the regulators using it should just use the
> standard operation.

I guess, you meant here to call regulator_enable_regmap() directly for
regulators NOT using suspend.mask. Then, I will do it.

> > +/* Regulator event handlers */
> > +irqreturn_t da906x_ldo_lim_event(int irq, void *data)
> 
> By "event handler" you mean "interrupt"

Yes. I think, I will update the comment line.

> > +	bits = da906x_reg_read(hw, DA906X_REG_STATUS_D);
> > +	if (bits < 0)
> > +		return IRQ_HANDLED;
> 
> If you fail to detect an interrupt you report that you handled one...?

For me there is no sensible return value for this case.
However, I consider changing the reaction on read failure by reporting event
for all regulators, that might cause this interrupt:
+	bits = da9063_reg_read(hw, DA9063_REG_STATUS_D);
+	if (bits < 0)
+		bits = ~0;

I will update the driver according to your remaining comments.

Thank you for your comments,
Krystian


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [lm-sensors] [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
@ 2012-08-29 14:50         ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-29 14:50 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Mark Brown,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu, Richard Purdie, Anthony Olech

> > +static int da906x_set_voltage(struct regulator_dev *rdev,
> > +				int min_uV, int max_uV, unsigned *selector)
> > +{
> > +	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
> > +	const struct field *fvol = &regl->info->voltage;
> > +	int ret;
> > +	unsigned val;
> > +
> > +	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
> > +	if (val < 0)
> > +		return -EINVAL;
> > +
> > +	val = (val + fvol->offset) << fvol->shift;
> > +	ret = da906x_reg_update(regl->hw, fvol->addr, fvol->mask, val);
> > +	if (ret >= 0)
> > +		*selector = val;
> > +
> > +	return ret;
> > +}
> 
> This is just set_voltage_sel_regmap().

Because, for some regulators, this is required: val += fvol->offset,
I was only able to reduce it to the following form.

+static int da9063_set_voltage(struct regulator_dev *rdev,
+			      int min_uV, int max_uV, unsigned *selector)
+{
+	struct da9063_regulator *regl = rdev_get_drvdata(rdev);
+	const struct field *fvol = &regl->info->voltage;
+	int ret;
+	unsigned val;
+
+	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
+	if (val < 0)
+		return -EINVAL;
+
+	val += fvol->offset;
+
+	ret = regulator_set_voltage_sel_regmap(rdev, val);
+	if (ret >= 0)
+		*selector = val;
+
+	return ret;
+}

> > +static int da906x_enable(struct regulator_dev *rdev)
> > +{
> > +	struct da906x_regulator *regl = rdev_get_drvdata(rdev);
> > +	int ret;
> > +
> > +	if (regl->info->suspend.mask) {
> > +		/* Make sure to exit from suspend mode on enable */
> > +		ret = da906x_reg_clear_bits(regl->hw, regl->info->suspend.addr,
> > +					    regl->info->suspend.mask);
> > +		if (ret < 0)
> > +			return ret;
> > +
> > +		/* BUCKs need mode update after wake-up from suspend state. */
> > +		ret = da906x_update_mode_internal(regl, SYS_STATE_NORMAL);
> > +		if (ret < 0)
> > +			return ret;
> > +	}
> > +
> > +	return regulator_enable_regmap(rdev);
> 
> If suspend_mask is optional the regulators using it should just use the
> standard operation.

I guess, you meant here to call regulator_enable_regmap() directly for
regulators NOT using suspend.mask. Then, I will do it.

> > +/* Regulator event handlers */
> > +irqreturn_t da906x_ldo_lim_event(int irq, void *data)
> 
> By "event handler" you mean "interrupt"

Yes. I think, I will update the comment line.

> > +	bits = da906x_reg_read(hw, DA906X_REG_STATUS_D);
> > +	if (bits < 0)
> > +		return IRQ_HANDLED;
> 
> If you fail to detect an interrupt you report that you handled one...?

For me there is no sensible return value for this case.
However, I consider changing the reaction on read failure by reporting event
for all regulators, that might cause this interrupt:
+	bits = da9063_reg_read(hw, DA9063_REG_STATUS_D);
+	if (bits < 0)
+		bits = ~0;

I will update the driver according to your remaining comments.

Thank you for your comments,
Krystian


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
  2012-08-29 14:50         ` Krystian Garbaciak
@ 2012-08-30 17:47           ` Mark Brown
  -1 siblings, 0 replies; 66+ messages in thread
From: Mark Brown @ 2012-08-30 17:47 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Alessandro Zummo,
	Jean Delvare, Dmitry Torokhov, Ashish Jangam, Andrew Jones,
	Donggeun Kim, Philippe Rétornaz, Wim Van Sebroeck, Bryan Wu,
	Richard Purdie, Anthony Olech

On Wed, Aug 29, 2012 at 03:50:00PM +0100, Krystian Garbaciak wrote:

> Because, for some regulators, this is required: val += fvol->offset,
> I was only able to reduce it to the following form.

What on earth makes you say this?  The above is obviously linear.

Besides, you're missing several points here.  One is that you should be
using the framework features, another is that you should be implementing
_sel.

> > > +	bits = da906x_reg_read(hw, DA906X_REG_STATUS_D);
> > > +	if (bits < 0)
> > > +		return IRQ_HANDLED;

> > If you fail to detect an interrupt you report that you handled one...?

> For me there is no sensible return value for this case.

IRQ_NONE.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [lm-sensors] [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
@ 2012-08-30 17:47           ` Mark Brown
  0 siblings, 0 replies; 66+ messages in thread
From: Mark Brown @ 2012-08-30 17:47 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Alessandro Zummo,
	Jean Delvare, Dmitry Torokhov, Ashish Jangam, Andrew Jones,
	Donggeun Kim, Philippe Rétornaz, Wim Van Sebroeck, Bryan Wu,
	Richard Purdie, Anthony Olech

On Wed, Aug 29, 2012 at 03:50:00PM +0100, Krystian Garbaciak wrote:

> Because, for some regulators, this is required: val += fvol->offset,
> I was only able to reduce it to the following form.

What on earth makes you say this?  The above is obviously linear.

Besides, you're missing several points here.  One is that you should be
using the framework features, another is that you should be implementing
_sel.

> > > +	bits = da906x_reg_read(hw, DA906X_REG_STATUS_D);
> > > +	if (bits < 0)
> > > +		return IRQ_HANDLED;

> > If you fail to detect an interrupt you report that you handled one...?

> For me there is no sensible return value for this case.

IRQ_NONE.

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
  2012-08-30 17:47           ` [lm-sensors] " Mark Brown
  (?)
@ 2012-08-31 10:00             ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-31 10:00 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Mark Brown,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu, Richard Purdie, Anthony Olech

> On Wed, Aug 29, 2012 at 03:50:00PM +0100, Krystian Garbaciak wrote:
> 
> > Because, for some regulators, this is required: val += fvol->offset,
> > I was only able to reduce it to the following form.
> 
> What on earth makes you say this?  The above is obviously linear.
> 
> Besides, you're missing several points here.  One is that you should be
> using the framework features, another is that you should be implementing
> _sel.

Sorry, I've missed an obvious thing here. Instead of adding selector offset at
runtime, I can substract apropriate voltage from .min_uV. Thanks for pointing
this out.


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
@ 2012-08-31 10:00             ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-31 10:00 UTC (permalink / raw)
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Mark Brown,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu, Richard Purdie, Anthony Olech

> On Wed, Aug 29, 2012 at 03:50:00PM +0100, Krystian Garbaciak wrote:
> 
> > Because, for some regulators, this is required: val += fvol->offset,
> > I was only able to reduce it to the following form.
> 
> What on earth makes you say this?  The above is obviously linear.
> 
> Besides, you're missing several points here.  One is that you should be
> using the framework features, another is that you should be implementing
> _sel.

Sorry, I've missed an obvious thing here. Instead of adding selector offset at
runtime, I can substract apropriate voltage from .min_uV. Thanks for pointing
this out.


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [lm-sensors] [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
@ 2012-08-31 10:00             ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-31 10:00 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Mark Brown,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu, Richard Purdie, Anthony Olech

> On Wed, Aug 29, 2012 at 03:50:00PM +0100, Krystian Garbaciak wrote:
> 
> > Because, for some regulators, this is required: val += fvol->offset,
> > I was only able to reduce it to the following form.
> 
> What on earth makes you say this?  The above is obviously linear.
> 
> Besides, you're missing several points here.  One is that you should be
> using the framework features, another is that you should be implementing
> _sel.

Sorry, I've missed an obvious thing here. Instead of adding selector offset at
runtime, I can substract apropriate voltage from .min_uV. Thanks for pointing
this out.


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 1/8] mfd: Add Dialog DA906x core driver.
  2012-08-25 18:31     ` [lm-sensors] " Mark Brown
  (?)
@ 2012-08-31 11:20       ` Krystian Garbaciak
  -1 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-31 11:20 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Mark Brown,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu, Richard Purdie, Anthony Olech

> On Fri, Aug 24, 2012 at 02:50:00PM +0100, Krystian Garbaciak wrote:
> 
> > This is MFD module providing access to registers and interrupts of DA906x
> > series PMIC. It is used by other functional modules, registered as MFD cells.
> > Driver uses regmap with paging to access extended register list. Register map
> > is divided into two pages, where the second page is used during initialisation.
> 
> Your selection of people to CC here appears both large and random...

I've added any maintainer for my modules from maintainer list.

> > +inline unsigned int da906x_to_range_reg(u16 reg)
> > +{
> > +	return reg + DA906X_MAPPING_BASE;
> > +}
> 
> I've no real idea what this stuff is all about, it at least needs some
> comments somewhere.  The fact that you're just adding a constant offset
> to all registers is at best odd.

I will comment it precisely for next version:

+/* Adding virtual register range starting from address DA9063_MAPPING_BASE.
+   It will be used for registers requiring page switching, which in our case
+   are virtually all PMIC registers.
+   Registers from 0 to 255 are used only as a page window and are volatile,
+   except DA9063_REG_PAGE_CON register (page selector), which is cachable. */
+static const struct regmap_range_cfg da9063_range_cfg[] = {
+	{
+		.range_min = DA9063_MAPPING_BASE,
+		.range_max = DA9063_MAPPING_BASE +
+			     ARRAY_SIZE(da9063_reg_flg) - 1,
+		.selector_reg = DA9063_REG_PAGE_CON,
+		.selector_mask = 1 << DA9063_I2C_PAGE_SEL_SHIFT,
+		.selector_shift = DA9063_I2C_PAGE_SEL_SHIFT,
+		.window_start = 0,
+		.window_len = 256,
+	}
+};

.. and here:

+/* Access to any PMIC register is passed through virtual register range,
+   starting at DA9063_MAPPING_BASE. For those registers, paging is required. */
+inline unsigned int da9063_to_range_reg(u16 reg)
+{
+	return reg + DA9063_MAPPING_BASE;
+}


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 1/8] mfd: Add Dialog DA906x core driver.
@ 2012-08-31 11:20       ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-31 11:20 UTC (permalink / raw)
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Mark Brown,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu, Richard Purdie, Anthony Olech

> On Fri, Aug 24, 2012 at 02:50:00PM +0100, Krystian Garbaciak wrote:
> 
> > This is MFD module providing access to registers and interrupts of DA906x
> > series PMIC. It is used by other functional modules, registered as MFD cells.
> > Driver uses regmap with paging to access extended register list. Register map
> > is divided into two pages, where the second page is used during initialisation.
> 
> Your selection of people to CC here appears both large and random...

I've added any maintainer for my modules from maintainer list.

> > +inline unsigned int da906x_to_range_reg(u16 reg)
> > +{
> > +	return reg + DA906X_MAPPING_BASE;
> > +}
> 
> I've no real idea what this stuff is all about, it at least needs some
> comments somewhere.  The fact that you're just adding a constant offset
> to all registers is at best odd.

I will comment it precisely for next version:

+/* Adding virtual register range starting from address DA9063_MAPPING_BASE.
+   It will be used for registers requiring page switching, which in our case
+   are virtually all PMIC registers.
+   Registers from 0 to 255 are used only as a page window and are volatile,
+   except DA9063_REG_PAGE_CON register (page selector), which is cachable. */
+static const struct regmap_range_cfg da9063_range_cfg[] = {
+	{
+		.range_min = DA9063_MAPPING_BASE,
+		.range_max = DA9063_MAPPING_BASE +
+			     ARRAY_SIZE(da9063_reg_flg) - 1,
+		.selector_reg = DA9063_REG_PAGE_CON,
+		.selector_mask = 1 << DA9063_I2C_PAGE_SEL_SHIFT,
+		.selector_shift = DA9063_I2C_PAGE_SEL_SHIFT,
+		.window_start = 0,
+		.window_len = 256,
+	}
+};

.. and here:

+/* Access to any PMIC register is passed through virtual register range,
+   starting at DA9063_MAPPING_BASE. For those registers, paging is required. */
+inline unsigned int da9063_to_range_reg(u16 reg)
+{
+	return reg + DA9063_MAPPING_BASE;
+}

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [lm-sensors] [PATCH 1/8] mfd: Add Dialog DA906x core driver.
@ 2012-08-31 11:20       ` Krystian Garbaciak
  0 siblings, 0 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-08-31 11:20 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Mark Brown,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Philippe Rétornaz,
	Wim Van Sebroeck, Bryan Wu, Richard Purdie, Anthony Olech

> On Fri, Aug 24, 2012 at 02:50:00PM +0100, Krystian Garbaciak wrote:
> 
> > This is MFD module providing access to registers and interrupts of DA906x
> > series PMIC. It is used by other functional modules, registered as MFD cells.
> > Driver uses regmap with paging to access extended register list. Register map
> > is divided into two pages, where the second page is used during initialisation.
> 
> Your selection of people to CC here appears both large and random...

I've added any maintainer for my modules from maintainer list.

> > +inline unsigned int da906x_to_range_reg(u16 reg)
> > +{
> > +	return reg + DA906X_MAPPING_BASE;
> > +}
> 
> I've no real idea what this stuff is all about, it at least needs some
> comments somewhere.  The fact that you're just adding a constant offset
> to all registers is at best odd.

I will comment it precisely for next version:

+/* Adding virtual register range starting from address DA9063_MAPPING_BASE.
+   It will be used for registers requiring page switching, which in our case
+   are virtually all PMIC registers.
+   Registers from 0 to 255 are used only as a page window and are volatile,
+   except DA9063_REG_PAGE_CON register (page selector), which is cachable. */
+static const struct regmap_range_cfg da9063_range_cfg[] = {
+	{
+		.range_min = DA9063_MAPPING_BASE,
+		.range_max = DA9063_MAPPING_BASE +
+			     ARRAY_SIZE(da9063_reg_flg) - 1,
+		.selector_reg = DA9063_REG_PAGE_CON,
+		.selector_mask = 1 << DA9063_I2C_PAGE_SEL_SHIFT,
+		.selector_shift = DA9063_I2C_PAGE_SEL_SHIFT,
+		.window_start = 0,
+		.window_len = 256,
+	}
+};

.. and here:

+/* Access to any PMIC register is passed through virtual register range,
+   starting at DA9063_MAPPING_BASE. For those registers, paging is required. */
+inline unsigned int da9063_to_range_reg(u16 reg)
+{
+	return reg + DA9063_MAPPING_BASE;
+}


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 1/8] mfd: Add Dialog DA906x core driver.
  2012-08-31 11:20       ` Krystian Garbaciak
  (?)
  (?)
@ 2012-08-31 11:37         ` Philippe Rétornaz
  -1 siblings, 0 replies; 66+ messages in thread
From: Philippe Rétornaz @ 2012-08-31 11:37 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: Mark Brown, linux-kernel, rtc-linux, lm-sensors, linux-input,
	linux-watchdog, linux-leds, Samuel Ortiz, Liam Girdwood,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Wim Van Sebroeck, Bryan Wu,
	Richard Purdie, Anthony Olech

Le vendredi 31 août 2012 12:20:00 Krystian Garbaciak a écrit :
> > On Fri, Aug 24, 2012 at 02:50:00PM +0100, Krystian Garbaciak wrote:
> > > This is MFD module providing access to registers and interrupts of
> > > DA906x
> > > series PMIC. It is used by other functional modules, registered as MFD
> > > cells. Driver uses regmap with paging to access extended register list.
> > > Register map is divided into two pages, where the second page is used
> > > during initialisation.> 
> > Your selection of people to CC here appears both large and random...
> 
> I've added any maintainer for my modules from maintainer list.

You should filter manually what get_maintainer.pl tells you, sometimes it's 
too verbose.

I'm not maintainer of any of the files/tree this patch is touching.

Anyways, it's quite pleasing to see that get_maintainer knows me :)

Regards,

Philippe


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 1/8] mfd: Add Dialog DA906x core driver.
@ 2012-08-31 11:37         ` Philippe Rétornaz
  0 siblings, 0 replies; 66+ messages in thread
From: Philippe Rétornaz @ 2012-08-31 11:37 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: Mark Brown, linux-kernel, rtc-linux, lm-sensors, linux-input,
	linux-watchdog, linux-leds, Samuel Ortiz, Liam Girdwood,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Wim Van Sebroeck, Bryan Wu,
	Richard Purdie, Anthony Olech

Le vendredi 31 août 2012 12:20:00 Krystian Garbaciak a écrit :
> > On Fri, Aug 24, 2012 at 02:50:00PM +0100, Krystian Garbaciak wrote:
> > > This is MFD module providing access to registers and interrupts of
> > > DA906x
> > > series PMIC. It is used by other functional modules, registered as MFD
> > > cells. Driver uses regmap with paging to access extended register list.
> > > Register map is divided into two pages, where the second page is used
> > > during initialisation.> 
> > Your selection of people to CC here appears both large and random...
> 
> I've added any maintainer for my modules from maintainer list.

You should filter manually what get_maintainer.pl tells you, sometimes it's 
too verbose.

I'm not maintainer of any of the files/tree this patch is touching.

Anyways, it's quite pleasing to see that get_maintainer knows me :)

Regards,

Philippe

--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 1/8] mfd: Add Dialog DA906x core driver.
@ 2012-08-31 11:37         ` Philippe Rétornaz
  0 siblings, 0 replies; 66+ messages in thread
From: Philippe Rétornaz @ 2012-08-31 11:37 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: Mark Brown, linux-kernel, rtc-linux, lm-sensors, linux-input,
	linux-watchdog, linux-leds, Samuel Ortiz, Liam Girdwood,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Wim Van Sebroeck, Bryan Wu,
	Richard Purdie, Anthony Olech

Le vendredi 31 août 2012 12:20:00 Krystian Garbaciak a écrit :
> > On Fri, Aug 24, 2012 at 02:50:00PM +0100, Krystian Garbaciak wrote:
> > > This is MFD module providing access to registers and interrupts of
> > > DA906x
> > > series PMIC. It is used by other functional modules, registered as MFD
> > > cells. Driver uses regmap with paging to access extended register list.
> > > Register map is divided into two pages, where the second page is used
> > > during initialisation.> 
> > Your selection of people to CC here appears both large and random...
> 
> I've added any maintainer for my modules from maintainer list.

You should filter manually what get_maintainer.pl tells you, sometimes it's 
too verbose.

I'm not maintainer of any of the files/tree this patch is touching.

Anyways, it's quite pleasing to see that get_maintainer knows me :)

Regards,

Philippe

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [lm-sensors] [PATCH 1/8] mfd: Add Dialog DA906x core driver.
@ 2012-08-31 11:37         ` Philippe Rétornaz
  0 siblings, 0 replies; 66+ messages in thread
From: Philippe Rétornaz @ 2012-08-31 11:37 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: Mark Brown, linux-kernel, rtc-linux, lm-sensors, linux-input,
	linux-watchdog, linux-leds, Samuel Ortiz, Liam Girdwood,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Ashish Jangam,
	Andrew Jones, Donggeun Kim, Wim Van Sebroeck, Bryan Wu,
	Richard Purdie, Anthony Olech

Le vendredi 31 août 2012 12:20:00 Krystian Garbaciak a écrit :
> > On Fri, Aug 24, 2012 at 02:50:00PM +0100, Krystian Garbaciak wrote:
> > > This is MFD module providing access to registers and interrupts of
> > > DA906x
> > > series PMIC. It is used by other functional modules, registered as MFD
> > > cells. Driver uses regmap with paging to access extended register list.
> > > Register map is divided into two pages, where the second page is used
> > > during initialisation.> 
> > Your selection of people to CC here appears both large and random...
> 
> I've added any maintainer for my modules from maintainer list.

You should filter manually what get_maintainer.pl tells you, sometimes it's 
too verbose.

I'm not maintainer of any of the files/tree this patch is touching.

Anyways, it's quite pleasing to see that get_maintainer knows me :)

Regards,

Philippe


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 1/8] mfd: Add Dialog DA906x core driver.
  2012-08-31 11:20       ` Krystian Garbaciak
@ 2012-08-31 17:16         ` Mark Brown
  -1 siblings, 0 replies; 66+ messages in thread
From: Mark Brown @ 2012-08-31 17:16 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Alessandro Zummo,
	Jean Delvare, Dmitry Torokhov, Ashish Jangam, Andrew Jones,
	Donggeun Kim, Philippe Rétornaz, Wim Van Sebroeck, Bryan Wu,
	Richard Purdie, Anthony Olech

On Fri, Aug 31, 2012 at 12:20:00PM +0100, Krystian Garbaciak wrote:
> > On Fri, Aug 24, 2012 at 02:50:00PM +0100, Krystian Garbaciak wrote:

> > Your selection of people to CC here appears both large and random...

> I've added any maintainer for my modules from maintainer list.

You don't need to CC every single persojn on every single patch, and
quite a few of these people are clearly not active in development.

> > > +inline unsigned int da906x_to_range_reg(u16 reg)
> > > +{
> > > +	return reg + DA906X_MAPPING_BASE;
> > > +}

> > I've no real idea what this stuff is all about, it at least needs some
> > comments somewhere.  The fact that you're just adding a constant offset
> > to all registers is at best odd.

> I will comment it precisely for next version:

This still makes very little sense - this function appears to be
accomplishing very little.  You're adding a constant offset to every
single register address that gets used.  Why are we doing this
dynamically at runtime?

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [lm-sensors] [PATCH 1/8] mfd: Add Dialog DA906x core driver.
@ 2012-08-31 17:16         ` Mark Brown
  0 siblings, 0 replies; 66+ messages in thread
From: Mark Brown @ 2012-08-31 17:16 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: linux-kernel, rtc-linux, lm-sensors, linux-input, linux-watchdog,
	linux-leds, Samuel Ortiz, Liam Girdwood, Alessandro Zummo,
	Jean Delvare, Dmitry Torokhov, Ashish Jangam, Andrew Jones,
	Donggeun Kim, Philippe Rétornaz, Wim Van Sebroeck, Bryan Wu,
	Richard Purdie, Anthony Olech

On Fri, Aug 31, 2012 at 12:20:00PM +0100, Krystian Garbaciak wrote:
> > On Fri, Aug 24, 2012 at 02:50:00PM +0100, Krystian Garbaciak wrote:

> > Your selection of people to CC here appears both large and random...

> I've added any maintainer for my modules from maintainer list.

You don't need to CC every single persojn on every single patch, and
quite a few of these people are clearly not active in development.

> > > +inline unsigned int da906x_to_range_reg(u16 reg)
> > > +{
> > > +	return reg + DA906X_MAPPING_BASE;
> > > +}

> > I've no real idea what this stuff is all about, it at least needs some
> > comments somewhere.  The fact that you're just adding a constant offset
> > to all registers is at best odd.

> I will comment it precisely for next version:

This still makes very little sense - this function appears to be
accomplishing very little.  You're adding a constant offset to every
single register address that gets used.  Why are we doing this
dynamically at runtime?

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
  2012-08-31 10:00             ` Krystian Garbaciak
  (?)
  (?)
@ 2013-05-09 14:05             ` Guennadi Liakhovetski
  2013-05-09 14:18               ` Anthony Olech
  -1 siblings, 1 reply; 66+ messages in thread
From: Guennadi Liakhovetski @ 2013-05-09 14:05 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: Mark Brown, linux-kernel, Samuel Ortiz, Alessandro Zummo,
	Jean Delvare, Dmitry Torokhov, Richard Purdie, Anthony Olech

(trimmed the CC a bit)

Hi Krystian

On Fri, 31 Aug 2012, Krystian Garbaciak wrote:

> > On Wed, Aug 29, 2012 at 03:50:00PM +0100, Krystian Garbaciak wrote:

Sorry for picking up a random mail from this old thread, unfortunately, I 
don't have "0/8" in my archive.

I have to write a driver for the da9063 PMIC. Do you have an idea, whether 
it'd be compatible with this driver? Do you plan to continue your work on 
this driver or would you mind if I try to use these your patches and 
mainline them, preserving your authorship and copyright, of course?

Thanks
Guennadi

> > > Because, for some regulators, this is required: val += fvol->offset,
> > > I was only able to reduce it to the following form.
> > 
> > What on earth makes you say this?  The above is obviously linear.
> > 
> > Besides, you're missing several points here.  One is that you should be
> > using the framework features, another is that you should be implementing
> > _sel.
> 
> Sorry, I've missed an obvious thing here. Instead of adding selector offset at
> runtime, I can substract apropriate voltage from .min_uV. Thanks for pointing
> this out.
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

^ permalink raw reply	[flat|nested] 66+ messages in thread

* RE: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
  2013-05-09 14:05             ` Guennadi Liakhovetski
@ 2013-05-09 14:18               ` Anthony Olech
  2013-05-09 14:28                 ` Guennadi Liakhovetski
  0 siblings, 1 reply; 66+ messages in thread
From: Anthony Olech @ 2013-05-09 14:18 UTC (permalink / raw)
  To: Guennadi Liakhovetski, Krystian Garbaciak
  Cc: Mark Brown, linux-kernel, Samuel Ortiz, Alessandro Zummo,
	Jean Delvare, Dmitry Torokhov, Richard Purdie

Hi Guennadi Liakhovetski,

Now that Krystian no longer works for Dialog I think that I might be your best contact.
As far as I am aware without doing any checking, the DA906x driver should possibly cover the DA9063.

If you need a driver, that would imply that you have some chips. Have you tried our marketting department?

Best regards,

Tony Olech


> -----Original Message-----
> From: Guennadi Liakhovetski [mailto:g.liakhovetski@gmx.de]
> Sent: 09 May 2013 15:06
> To: Krystian Garbaciak
> Cc: Mark Brown; linux-kernel@vger.kernel.org; Samuel Ortiz; Alessandro
> Zummo; Jean Delvare; Dmitry Torokhov; Richard Purdie; Anthony Olech
> Subject: Re: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators
> support.
> 
> (trimmed the CC a bit)
> 
> Hi Krystian
> 
> On Fri, 31 Aug 2012, Krystian Garbaciak wrote:
> 
> > > On Wed, Aug 29, 2012 at 03:50:00PM +0100, Krystian Garbaciak wrote:
> 
> Sorry for picking up a random mail from this old thread, unfortunately, I don't
> have "0/8" in my archive.
> 
> I have to write a driver for the da9063 PMIC. Do you have an idea, whether it'd
> be compatible with this driver? Do you plan to continue your work on this driver
> or would you mind if I try to use these your patches and mainline them,
> preserving your authorship and copyright, of course?
> 
> Thanks
> Guennadi
> 
> > > > Because, for some regulators, this is required: val +=
> > > > fvol->offset, I was only able to reduce it to the following form.
> > >
> > > What on earth makes you say this?  The above is obviously linear.
> > >
> > > Besides, you're missing several points here.  One is that you should
> > > be using the framework features, another is that you should be
> > > implementing _sel.
> >
> > Sorry, I've missed an obvious thing here. Instead of adding selector
> > offset at runtime, I can substract apropriate voltage from .min_uV.
> > Thanks for pointing this out.
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe
> > linux-kernel" in the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at  http://www.tux.org/lkml/
> >
> 
> ---
> Guennadi Liakhovetski, Ph.D.
> Freelance Open-Source Software Developer http://www.open-technology.de/
Legal Disclaimer: This e-mail communication (and any attachment/s) is confidential and contains proprietary information, 
some or all of which may be legally privileged. It is intended solely for the use of the individual or entity to which it
is addressed. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any disclosure, 
copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful.

Please consider the environment before printing this e-mail

^ permalink raw reply	[flat|nested] 66+ messages in thread

* RE: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
  2013-05-09 14:18               ` Anthony Olech
@ 2013-05-09 14:28                 ` Guennadi Liakhovetski
  2013-05-09 14:42                   ` Anthony Olech
  0 siblings, 1 reply; 66+ messages in thread
From: Guennadi Liakhovetski @ 2013-05-09 14:28 UTC (permalink / raw)
  To: Anthony Olech
  Cc: Krystian Garbaciak, Mark Brown, linux-kernel, Samuel Ortiz,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Richard Purdie

Hi Tony

On Thu, 9 May 2013, Anthony Olech wrote:

> Hi Guennadi Liakhovetski,
> 
> Now that Krystian no longer works for Dialog I think that I might be 
> your best contact.
> As far as I am aware without doing any checking, the DA906x driver 
> should possibly cover the DA9063.

Good!

> If you need a driver, that would imply that you have some chips. Have 
> you tried our marketting department?

Yes, this (and a da9210) PMICs are used on one of the boards, I'm working 
with. I asked your marketing department for a da9210 datasheet, they tried 
to check with the board vendor, who is also my customer for this project, 
and so far they haven't been able to establish my involvement in this 
development. Have you also got a da9210 Linux driver? Do I have to wait 
for your marketing department clarifying my affiliation or could you make 
that driver available to me too? Or do you mean you might have a newer 
version of this driver available internally too?

Thanks
Guennadi

> Best regards,
> 
> Tony Olech
> 
> 
> > -----Original Message-----
> > From: Guennadi Liakhovetski [mailto:g.liakhovetski@gmx.de]
> > Sent: 09 May 2013 15:06
> > To: Krystian Garbaciak
> > Cc: Mark Brown; linux-kernel@vger.kernel.org; Samuel Ortiz; Alessandro
> > Zummo; Jean Delvare; Dmitry Torokhov; Richard Purdie; Anthony Olech
> > Subject: Re: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators
> > support.
> > 
> > (trimmed the CC a bit)
> > 
> > Hi Krystian
> > 
> > On Fri, 31 Aug 2012, Krystian Garbaciak wrote:
> > 
> > > > On Wed, Aug 29, 2012 at 03:50:00PM +0100, Krystian Garbaciak wrote:
> > 
> > Sorry for picking up a random mail from this old thread, unfortunately, I don't
> > have "0/8" in my archive.
> > 
> > I have to write a driver for the da9063 PMIC. Do you have an idea, whether it'd
> > be compatible with this driver? Do you plan to continue your work on this driver
> > or would you mind if I try to use these your patches and mainline them,
> > preserving your authorship and copyright, of course?
> > 
> > Thanks
> > Guennadi
> > 
> > > > > Because, for some regulators, this is required: val +=
> > > > > fvol->offset, I was only able to reduce it to the following form.
> > > >
> > > > What on earth makes you say this?  The above is obviously linear.
> > > >
> > > > Besides, you're missing several points here.  One is that you should
> > > > be using the framework features, another is that you should be
> > > > implementing _sel.
> > >
> > > Sorry, I've missed an obvious thing here. Instead of adding selector
> > > offset at runtime, I can substract apropriate voltage from .min_uV.
> > > Thanks for pointing this out.
> > >
> > > --
> > > To unsubscribe from this list: send the line "unsubscribe
> > > linux-kernel" in the body of a message to majordomo@vger.kernel.org
> > > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > > Please read the FAQ at  http://www.tux.org/lkml/
> > >
> > 
> > ---
> > Guennadi Liakhovetski, Ph.D.
> > Freelance Open-Source Software Developer http://www.open-technology.de/
> Legal Disclaimer: This e-mail communication (and any attachment/s) is confidential and contains proprietary information, 
> some or all of which may be legally privileged. It is intended solely for the use of the individual or entity to which it
> is addressed. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any disclosure, 
> copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful.
> 
> Please consider the environment before printing this e-mail
> 

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

^ permalink raw reply	[flat|nested] 66+ messages in thread

* RE: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
  2013-05-09 14:28                 ` Guennadi Liakhovetski
@ 2013-05-09 14:42                   ` Anthony Olech
  2013-05-09 14:50                     ` Guennadi Liakhovetski
  0 siblings, 1 reply; 66+ messages in thread
From: Anthony Olech @ 2013-05-09 14:42 UTC (permalink / raw)
  To: Guennadi Liakhovetski
  Cc: Krystian Garbaciak, Mark Brown, linux-kernel, Samuel Ortiz,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Richard Purdie

Hi Guennadi,

without trying to step on our marketing department's toes, I can only suggest that you slurp the online archives of the LKML and ALSA mailing list.
The Linux Kernel Mailing List archive that I use is: http://lkml.indiana.edu/hypermail/linux/kernel
The ALSA mailing list archive that I use is: http://mailman.alsa-project.org/pipermail/alsa-devel

I usually run a perl/bash/wget script to download stuff of interest.

I can answer questions about our Open Source submission (because they are open source), but for definitive product information our marketing department is the first place to try.

Do you mean the da7210 (audio CODEC)? I don't offhand recognise the da9210 part number.

Best regards,

Tony Olech


> -----Original Message-----
> From: Guennadi Liakhovetski [mailto:g.liakhovetski@gmx.de] 
> Sent: 09 May 2013 15:29
> To: Anthony Olech
> Cc: Krystian Garbaciak; Mark Brown; linux-kernel@vger.kernel.org; Samuel
> Ortiz; Alessandro Zummo; Jean Delvare; Dmitry Torokhov; Richard Purdie
> Subject: RE: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators
> support.
> 
> Hi Tony
> 
> On Thu, 9 May 2013, Anthony Olech wrote:
> 
> > Hi Guennadi Liakhovetski,
> >
> > Now that Krystian no longer works for Dialog I think that I might be
> > your best contact.
> > As far as I am aware without doing any checking, the DA906x driver
> > should possibly cover the DA9063.
> 
> Good!
> 
> > If you need a driver, that would imply that you have some chips. Have
> > you tried our marketting department?
> 
> Yes, this (and a da9210) PMICs are used on one of the boards, I'm working with.
> I asked your marketing department for a da9210 datasheet, they tried to check
> with the board vendor, who is also my customer for this project, and so far they
> haven't been able to establish my involvement in this development. Have you
> also got a da9210 Linux driver? Do I have to wait for your marketing
> department clarifying my affiliation or could you make that driver available to
> me too? Or do you mean you might have a newer version of this driver
> available internally too?
> 
> Thanks
> Guennadi
> 
> > Best regards,
> >
> > Tony Olech
> >
> >
> > > -----Original Message-----
> > > From: Guennadi Liakhovetski [mailto:g.liakhovetski@gmx.de]
> > > Sent: 09 May 2013 15:06
> > > To: Krystian Garbaciak
> > > Cc: Mark Brown; linux-kernel@vger.kernel.org; Samuel Ortiz; Alessandro
> > > Zummo; Jean Delvare; Dmitry Torokhov; Richard Purdie; Anthony Olech
> > > Subject: Re: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage
> regulators
> > > support.
> > >
> > > (trimmed the CC a bit)
> > >
> > > Hi Krystian
> > >
> > > On Fri, 31 Aug 2012, Krystian Garbaciak wrote:
> > >
> > > > > On Wed, Aug 29, 2012 at 03:50:00PM +0100, Krystian Garbaciak wrote:
> > >
> > > Sorry for picking up a random mail from this old thread, unfortunately, I
> don't
> > > have "0/8" in my archive.
> > >
> > > I have to write a driver for the da9063 PMIC. Do you have an idea, whether
> it'd
> > > be compatible with this driver? Do you plan to continue your work on this
> driver
> > > or would you mind if I try to use these your patches and mainline them,
> > > preserving your authorship and copyright, of course?
> > >
> > > Thanks
> > > Guennadi
> > >
> > > > > > Because, for some regulators, this is required: val +=
> > > > > > fvol->offset, I was only able to reduce it to the following form.
> > > > >
> > > > > What on earth makes you say this?  The above is obviously linear.
> > > > >
> > > > > Besides, you're missing several points here.  One is that you should
> > > > > be using the framework features, another is that you should be
> > > > > implementing _sel.
> > > >
> > > > Sorry, I've missed an obvious thing here. Instead of adding selector
> > > > offset at runtime, I can substract apropriate voltage from .min_uV.
> > > > Thanks for pointing this out.
> > > >
> > > > --
> > > > To unsubscribe from this list: send the line "unsubscribe
> > > > linux-kernel" in the body of a message to majordomo@vger.kernel.org
> > > > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > > > Please read the FAQ at  http://www.tux.org/lkml/
> > > >
> > >
> > > ---
> > > Guennadi Liakhovetski, Ph.D.
> > > Freelance Open-Source Software Developer http://www.open-
> technology.de/
> > Legal Disclaimer: This e-mail communication (and any attachment/s) is
> confidential and contains proprietary information,
> > some or all of which may be legally privileged. It is intended solely for the use
> of the individual or entity to which it
> > is addressed. Access to this email by anyone else is unauthorized. If you are
> not the intended recipient, any disclosure,
> > copying, distribution or any action taken or omitted to be taken in reliance on
> it, is prohibited and may be unlawful.
> >
> > Please consider the environment before printing this e-mail
> >
> 
> ---
> Guennadi Liakhovetski, Ph.D.
> Freelance Open-Source Software Developer
> http://www.open-technology.de/
Legal Disclaimer: This e-mail communication (and any attachment/s) is confidential and contains proprietary information, 
some or all of which may be legally privileged. It is intended solely for the use of the individual or entity to which it
is addressed. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any disclosure, 
copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful.

Please consider the environment before printing this e-mail

^ permalink raw reply	[flat|nested] 66+ messages in thread

* RE: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support.
  2013-05-09 14:42                   ` Anthony Olech
@ 2013-05-09 14:50                     ` Guennadi Liakhovetski
  0 siblings, 0 replies; 66+ messages in thread
From: Guennadi Liakhovetski @ 2013-05-09 14:50 UTC (permalink / raw)
  To: Anthony Olech
  Cc: Krystian Garbaciak, Mark Brown, linux-kernel, Samuel Ortiz,
	Alessandro Zummo, Jean Delvare, Dmitry Torokhov, Richard Purdie

On Thu, 9 May 2013, Anthony Olech wrote:

> Hi Guennadi,
> 
> without trying to step on our marketing department's toes, I can only 
> suggest that you slurp the online archives of the LKML and ALSA mailing 
> list.
> The Linux Kernel Mailing List archive that I use is: http://lkml.indiana.edu/hypermail/linux/kernel
> The ALSA mailing list archive that I use is: http://mailman.alsa-project.org/pipermail/alsa-devel
> 
> I usually run a perl/bash/wget script to download stuff of interest.

I've got these patches from an online archive, thanks.

> I can answer questions about our Open Source submission (because they 
> are open source), but for definitive product information our marketing 
> department is the first place to try.
> 
> Do you mean the da7210 (audio CODEC)? I don't offhand recognise the da9210 part number.

No, my task description says "a da9210 PMIC." I think this one is meant:

http://www.dialog-semiconductor.com/products/power-management/DA9210

Thanks
Guennadi

> Best regards,
> 
> Tony Olech
> 
> 
> > -----Original Message-----
> > From: Guennadi Liakhovetski [mailto:g.liakhovetski@gmx.de] 
> > Sent: 09 May 2013 15:29
> > To: Anthony Olech
> > Cc: Krystian Garbaciak; Mark Brown; linux-kernel@vger.kernel.org; Samuel
> > Ortiz; Alessandro Zummo; Jean Delvare; Dmitry Torokhov; Richard Purdie
> > Subject: RE: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators
> > support.
> > 
> > Hi Tony
> > 
> > On Thu, 9 May 2013, Anthony Olech wrote:
> > 
> > > Hi Guennadi Liakhovetski,
> > >
> > > Now that Krystian no longer works for Dialog I think that I might be
> > > your best contact.
> > > As far as I am aware without doing any checking, the DA906x driver
> > > should possibly cover the DA9063.
> > 
> > Good!
> > 
> > > If you need a driver, that would imply that you have some chips. Have
> > > you tried our marketting department?
> > 
> > Yes, this (and a da9210) PMICs are used on one of the boards, I'm working with.
> > I asked your marketing department for a da9210 datasheet, they tried to check
> > with the board vendor, who is also my customer for this project, and so far they
> > haven't been able to establish my involvement in this development. Have you
> > also got a da9210 Linux driver? Do I have to wait for your marketing
> > department clarifying my affiliation or could you make that driver available to
> > me too? Or do you mean you might have a newer version of this driver
> > available internally too?
> > 
> > Thanks
> > Guennadi
> > 
> > > Best regards,
> > >
> > > Tony Olech
> > >
> > >
> > > > -----Original Message-----
> > > > From: Guennadi Liakhovetski [mailto:g.liakhovetski@gmx.de]
> > > > Sent: 09 May 2013 15:06
> > > > To: Krystian Garbaciak
> > > > Cc: Mark Brown; linux-kernel@vger.kernel.org; Samuel Ortiz; Alessandro
> > > > Zummo; Jean Delvare; Dmitry Torokhov; Richard Purdie; Anthony Olech
> > > > Subject: Re: [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage
> > regulators
> > > > support.
> > > >
> > > > (trimmed the CC a bit)
> > > >
> > > > Hi Krystian
> > > >
> > > > On Fri, 31 Aug 2012, Krystian Garbaciak wrote:
> > > >
> > > > > > On Wed, Aug 29, 2012 at 03:50:00PM +0100, Krystian Garbaciak wrote:
> > > >
> > > > Sorry for picking up a random mail from this old thread, unfortunately, I
> > don't
> > > > have "0/8" in my archive.
> > > >
> > > > I have to write a driver for the da9063 PMIC. Do you have an idea, whether
> > it'd
> > > > be compatible with this driver? Do you plan to continue your work on this
> > driver
> > > > or would you mind if I try to use these your patches and mainline them,
> > > > preserving your authorship and copyright, of course?
> > > >
> > > > Thanks
> > > > Guennadi
> > > >
> > > > > > > Because, for some regulators, this is required: val +=
> > > > > > > fvol->offset, I was only able to reduce it to the following form.
> > > > > >
> > > > > > What on earth makes you say this?  The above is obviously linear.
> > > > > >
> > > > > > Besides, you're missing several points here.  One is that you should
> > > > > > be using the framework features, another is that you should be
> > > > > > implementing _sel.
> > > > >
> > > > > Sorry, I've missed an obvious thing here. Instead of adding selector
> > > > > offset at runtime, I can substract apropriate voltage from .min_uV.
> > > > > Thanks for pointing this out.
> > > > >
> > > > > --
> > > > > To unsubscribe from this list: send the line "unsubscribe
> > > > > linux-kernel" in the body of a message to majordomo@vger.kernel.org
> > > > > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > > > > Please read the FAQ at  http://www.tux.org/lkml/
> > > > >
> > > >
> > > > ---
> > > > Guennadi Liakhovetski, Ph.D.
> > > > Freelance Open-Source Software Developer http://www.open-
> > technology.de/
> > > Legal Disclaimer: This e-mail communication (and any attachment/s) is
> > confidential and contains proprietary information,
> > > some or all of which may be legally privileged. It is intended solely for the use
> > of the individual or entity to which it
> > > is addressed. Access to this email by anyone else is unauthorized. If you are
> > not the intended recipient, any disclosure,
> > > copying, distribution or any action taken or omitted to be taken in reliance on
> > it, is prohibited and may be unlawful.
> > >
> > > Please consider the environment before printing this e-mail
> > >
> > 
> > ---
> > Guennadi Liakhovetski, Ph.D.
> > Freelance Open-Source Software Developer
> > http://www.open-technology.de/
> Legal Disclaimer: This e-mail communication (and any attachment/s) is confidential and contains proprietary information, 
> some or all of which may be legally privileged. It is intended solely for the use of the individual or entity to which it
> is addressed. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any disclosure, 
> copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful.
> 
> Please consider the environment before printing this e-mail
> 

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH] regulator: Fix bug in regulator_mode_to_status() core function.
  2012-07-11 15:13     ` Krystian Garbaciak
@ 2012-07-11 17:42       ` Mark Brown
  0 siblings, 0 replies; 66+ messages in thread
From: Mark Brown @ 2012-07-11 17:42 UTC (permalink / raw)
  To: Krystian Garbaciak; +Cc: Liam Girdwood, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 396 bytes --]

On Wed, Jul 11, 2012 at 04:13:00PM +0100, Krystian Garbaciak wrote:

> Would it make more sense to have some special enum value for that case, let say
> there would be REGULATOR_STATUS_UNDEFINED?

> Returning 0 is interpreted as REGULATOR_STATUS_OFF outside the function.
> But it may change, if ever the enumeration changes.

That'd be fine.

Also, please do submit separate changes separately.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH] regulator: Fix bug in regulator_mode_to_status() core function.
  2012-07-11 14:18   ` Krystian Garbaciak
  2012-07-11 14:26     ` Mark Brown
@ 2012-07-11 15:13     ` Krystian Garbaciak
  2012-07-11 17:42       ` Mark Brown
  1 sibling, 1 reply; 66+ messages in thread
From: Krystian Garbaciak @ 2012-07-11 15:13 UTC (permalink / raw)
  To: Mark Brown; +Cc: Liam Girdwood, linux-kernel

> > > This is deliberate.  It's not reporting an error, it's reporting an
> > > indeterminate status which is a different thing.
> 
> > Ok, then I would propose to use REGULATOR_STATUS_OFF instead of 0, to present
> > your deliberate decision here.
> 
> I don't think you're fully understanding "indeterminate" there...  the
> whole point is that we can't adequately represent the state, making
> something up isn't helping things.

Would it make more sense to have some special enum value for that case, let say
there would be REGULATOR_STATUS_UNDEFINED?

Returning 0 is interpreted as REGULATOR_STATUS_OFF outside the function.
But it may change, if ever the enumeration changes.


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH] regulator: Fix bug in regulator_mode_to_status() core function.
  2012-07-11 14:18   ` Krystian Garbaciak
@ 2012-07-11 14:26     ` Mark Brown
  2012-07-11 15:13     ` Krystian Garbaciak
  1 sibling, 0 replies; 66+ messages in thread
From: Mark Brown @ 2012-07-11 14:26 UTC (permalink / raw)
  To: Krystian Garbaciak; +Cc: Liam Girdwood, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 483 bytes --]

On Wed, Jul 11, 2012 at 03:18:00PM +0100, Krystian Garbaciak wrote:

> > This is deliberate.  It's not reporting an error, it's reporting an
> > indeterminate status which is a different thing.

> Ok, then I would propose to use REGULATOR_STATUS_OFF instead of 0, to present
> your deliberate decision here.

I don't think you're fully understanding "indeterminate" there...  the
whole point is that we can't adequately represent the state, making
something up isn't helping things.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH] regulator: Fix bug in regulator_mode_to_status() core function.
  2012-07-11 13:28 ` Mark Brown
@ 2012-07-11 14:18   ` Krystian Garbaciak
  2012-07-11 14:26     ` Mark Brown
  2012-07-11 15:13     ` Krystian Garbaciak
  0 siblings, 2 replies; 66+ messages in thread
From: Krystian Garbaciak @ 2012-07-11 14:18 UTC (permalink / raw)
  To: Mark Brown; +Cc: Liam Girdwood, linux-kernel

> From: Mark Brown [mailto:broonie@opensource.wolfsonmicro.com]
> Sent: 11 July 2012 14:29
> 
> On Wed, Jul 11, 2012 at 01:10:01PM +0100, Krystian Garbaciak wrote:
> > Fix typo for case REGULATOR_STATUS_STANDBY -> REGULATOR_MODE_STANDBY.
> > For undefined mode, return REGULATOR_STATUS_ERROR (0 is not valid status).
> 
> This is deliberate.  It's not reporting an error, it's reporting an
> indeterminate status which is a different thing.

Ok, then I would propose to use REGULATOR_STATUS_OFF instead of 0, to present
your deliberate decision here.


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH] regulator: Fix bug in regulator_mode_to_status() core function.
  2012-07-11 12:10 [PATCH] regulator: Fix bug in regulator_mode_to_status() core function Krystian Garbaciak
@ 2012-07-11 13:28 ` Mark Brown
  2012-07-11 14:18   ` Krystian Garbaciak
  0 siblings, 1 reply; 66+ messages in thread
From: Mark Brown @ 2012-07-11 13:28 UTC (permalink / raw)
  To: Krystian Garbaciak; +Cc: Liam Girdwood, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 335 bytes --]

On Wed, Jul 11, 2012 at 01:10:01PM +0100, Krystian Garbaciak wrote:
> Fix typo for case REGULATOR_STATUS_STANDBY -> REGULATOR_MODE_STANDBY.
> For undefined mode, return REGULATOR_STATUS_ERROR (0 is not valid status).

This is deliberate.  It's not reporting an error, it's reporting an
indeterminate status which is a different thing.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH] regulator: Fix bug in regulator_mode_to_status() core function.
@ 2012-07-11 12:10 Krystian Garbaciak
  2012-07-11 13:28 ` Mark Brown
  0 siblings, 1 reply; 66+ messages in thread
From: Krystian Garbaciak @ 2012-07-11 12:10 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood; +Cc: linux-kernel

Fix typo for case REGULATOR_STATUS_STANDBY -> REGULATOR_MODE_STANDBY.
For undefined mode, return REGULATOR_STATUS_ERROR (0 is not valid status).

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/regulator/core.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 09a737c..b821a9f 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2909,10 +2909,10 @@ int regulator_mode_to_status(unsigned int mode)
 		return REGULATOR_STATUS_NORMAL;
 	case REGULATOR_MODE_IDLE:
 		return REGULATOR_STATUS_IDLE;
-	case REGULATOR_STATUS_STANDBY:
+	case REGULATOR_MODE_STANDBY:
 		return REGULATOR_STATUS_STANDBY;
 	default:
-		return 0;
+		return REGULATOR_STATUS_ERROR;
 	}
 }
 EXPORT_SYMBOL_GPL(regulator_mode_to_status);
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 66+ messages in thread

end of thread, other threads:[~2013-05-09 14:50 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-24 13:45 [RFC PATCH 0/8] DA906x PMIC driver Krystian Garbaciak
2012-08-24 13:45 ` [lm-sensors] " Krystian Garbaciak
2012-08-24 13:50 ` [PATCH 1/8] mfd: Add Dialog DA906x core driver Krystian Garbaciak
2012-08-24 13:50   ` [lm-sensors] " Krystian Garbaciak
2012-08-24 13:55   ` [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support Krystian Garbaciak
2012-08-24 13:55     ` [lm-sensors] " Krystian Garbaciak
2012-08-24 14:00     ` [RFC PATCH 3/8] rtc: Add RTC driver for DA906x PMIC Krystian Garbaciak
2012-08-24 14:00       ` [lm-sensors] " Krystian Garbaciak
2012-08-24 14:05       ` [RFC PATCH 4/8] hwmon: Add DA906x hardware monitoring support Krystian Garbaciak
2012-08-24 14:05         ` [lm-sensors] " Krystian Garbaciak
2012-08-24 14:10         ` [RFC PATCH 5/8] input: Add support for DA906x PMIC OnKey detection Krystian Garbaciak
2012-08-24 14:10           ` [lm-sensors] " Krystian Garbaciak
2012-08-24 14:15           ` [RFC PATCH 6/8] input: Add support for DA906x vibration motor driver Krystian Garbaciak
2012-08-24 14:15             ` [lm-sensors] " Krystian Garbaciak
2012-08-24 14:20             ` [RFC PATCH 7/8] watchdog: Add DA906x PMIC watchdog driver Krystian Garbaciak
2012-08-24 14:20               ` [lm-sensors] " Krystian Garbaciak
2012-08-24 14:25               ` [RFC PATCH 8/8] leds: Add DA906x PMIC LED driver Krystian Garbaciak
2012-08-24 14:25                 ` [lm-sensors] " Krystian Garbaciak
2012-08-24 18:45         ` [RFC PATCH 4/8] hwmon: Add DA906x hardware monitoring support Guenter Roeck
2012-08-24 18:45           ` [lm-sensors] " Guenter Roeck
2012-08-29 13:25           ` [PATCH] regulator: Fix bug in regulator_mode_to_status() core function Krystian Garbaciak
2012-08-29 13:25             ` [lm-sensors] " Krystian Garbaciak
2012-08-25 15:10     ` [RFC PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support Mark Brown
2012-08-25 15:10       ` [lm-sensors] " Mark Brown
2012-08-29 14:50       ` Krystian Garbaciak
2012-08-29 14:50         ` [lm-sensors] " Krystian Garbaciak
2012-08-29 14:50         ` Krystian Garbaciak
2012-08-30 17:47         ` Mark Brown
2012-08-30 17:47           ` [lm-sensors] " Mark Brown
2012-08-31 10:00           ` Krystian Garbaciak
2012-08-31 10:00             ` [lm-sensors] " Krystian Garbaciak
2012-08-31 10:00             ` Krystian Garbaciak
2013-05-09 14:05             ` Guennadi Liakhovetski
2013-05-09 14:18               ` Anthony Olech
2013-05-09 14:28                 ` Guennadi Liakhovetski
2013-05-09 14:42                   ` Anthony Olech
2013-05-09 14:50                     ` Guennadi Liakhovetski
2012-08-25 18:31   ` [PATCH 1/8] mfd: Add Dialog DA906x core driver Mark Brown
2012-08-25 18:31     ` [lm-sensors] " Mark Brown
2012-08-31 11:20     ` Krystian Garbaciak
2012-08-31 11:20       ` [lm-sensors] " Krystian Garbaciak
2012-08-31 11:20       ` Krystian Garbaciak
2012-08-31 11:37       ` Philippe Rétornaz
2012-08-31 11:37         ` [lm-sensors] " Philippe Rétornaz
2012-08-31 11:37         ` Philippe Rétornaz
2012-08-31 11:37         ` Philippe Rétornaz
2012-08-31 17:16       ` Mark Brown
2012-08-31 17:16         ` [lm-sensors] " Mark Brown
  -- strict thread matches above, loose matches on Subject: below --
2012-08-24  8:32 [RFC PATCH 0/8] DA906x PMIC driver Krystian Garbaciak
2012-08-24  8:32 ` [lm-sensors] " Krystian Garbaciak
2012-08-24  8:32 ` [PATCH 1/8] mfd: Add Dialog DA906x core driver Krystian Garbaciak
2012-08-24  8:32   ` [lm-sensors] " Krystian Garbaciak
2012-08-24  8:32   ` [PATCH 2/8] regulator: Add Dialog DA906x voltage regulators support Krystian Garbaciak
2012-08-24  8:32     ` [lm-sensors] " Krystian Garbaciak
2012-08-24  8:32     ` [PATCH 3/8] rtc: Add RTC driver for DA906x PMIC Krystian Garbaciak
2012-08-24  8:32       ` [lm-sensors] " Krystian Garbaciak
2012-08-24  8:32       ` [PATCH 4/8] hwmon: Add DA906x hardware monitoring support Krystian Garbaciak
2012-08-24  8:32         ` [lm-sensors] " Krystian Garbaciak
2012-08-24  8:32         ` [PATCH 5/8] input: Add support for DA906x PMIC OnKey detection Krystian Garbaciak
2012-08-24  8:32           ` [lm-sensors] " Krystian Garbaciak
2012-07-11 12:10 [PATCH] regulator: Fix bug in regulator_mode_to_status() core function Krystian Garbaciak
2012-07-11 13:28 ` Mark Brown
2012-07-11 14:18   ` Krystian Garbaciak
2012-07-11 14:26     ` Mark Brown
2012-07-11 15:13     ` Krystian Garbaciak
2012-07-11 17:42       ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.