LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v5 0/3] mfd: max8997: add regmap support
@ 2014-11-12  7:23 Robert Baldyga
  2014-11-12  7:23 ` [PATCH v5 1/3] mfd: max8997: use regmap to access registers Robert Baldyga
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Robert Baldyga @ 2014-11-12  7:23 UTC (permalink / raw)
  To: lee.jones
  Cc: sameo, myungjoo.ham, cw00.choi, dmitry.torokhov, cooloney,
	rpurdie, sre, dbaryshkov, dwmw2, lgirdwood, broonie, a.zummo,
	paul.gortmaker, sachin.kamat, k.kozlowski, linux-kernel,
	linux-input, linux-leds, linux-pm, rtc-linux, Robert Baldyga

This patchset modifies max8997 driver and associated function drivers to use
register maps instead of operating directly on i2c bus. This change allowed
to simplify irq handling, and to move some initializations to individual
function drivers. Hence now when some functions are not enabled, their i2c
clients, regmaps and irqs are not registered.

Because patches are under review for very long time and I still don't have
all needed Acks, I'm resending this series rebased to the latest next branch.

Best regards
Robert Baldyga
Samsung R&D Institute Poland

Changelog:

v5:
- rebase patches to last next branch

v4:
- remove patch moving regmap handling to function drivers

v3: https://lkml.org/lkml/2014/3/13/101
- fix error handling
- fix deinitializations order
- move muic irq enum values renaming to separate patch

v2: https://lkml.org/lkml/2014/3/12/237
- rebase patches on Lee Jones' MFD tree
- add missing selects in Kconfig
- add missing deinitializations
- add interrupt disabling when suspend
- few minor changes and typo fixes

v1: https://lkml.org/lkml/2014/3/11/291

Robert Baldyga (3):
  mfd: max8997: use regmap to access registers
  mfd: max8997: handle IRQs using regmap
  mfd: max8997: change irq names to upper case

 drivers/extcon/extcon-max8997.c     |  66 +++---
 drivers/input/misc/max8997_haptic.c |  34 ++--
 drivers/leds/leds-max8997.c         |  13 +-
 drivers/mfd/Kconfig                 |   3 +-
 drivers/mfd/Makefile                |   2 +-
 drivers/mfd/max8997-irq.c           | 387 ------------------------------------
 drivers/mfd/max8997.c               | 245 +++++++++++++++--------
 drivers/power/max8997_charger.c     |  33 +--
 drivers/regulator/max8997.c         |  87 ++++----
 drivers/rtc/rtc-max8997.c           |  58 +++---
 include/linux/mfd/max8997-private.h |  82 ++++++--
 11 files changed, 381 insertions(+), 629 deletions(-)
 delete mode 100644 drivers/mfd/max8997-irq.c

-- 
1.9.1


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

* [PATCH v5 1/3] mfd: max8997: use regmap to access registers
  2014-11-12  7:23 [PATCH v5 0/3] mfd: max8997: add regmap support Robert Baldyga
@ 2014-11-12  7:23 ` Robert Baldyga
  2014-11-12 17:01   ` Sebastian Reichel
  2015-01-29 18:01   ` Dmitry Torokhov
  2014-11-12  7:23 ` [PATCH v5 2/3] mfd: max8997: handle IRQs using regmap Robert Baldyga
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 11+ messages in thread
From: Robert Baldyga @ 2014-11-12  7:23 UTC (permalink / raw)
  To: lee.jones
  Cc: sameo, myungjoo.ham, cw00.choi, dmitry.torokhov, cooloney,
	rpurdie, sre, dbaryshkov, dwmw2, lgirdwood, broonie, a.zummo,
	paul.gortmaker, sachin.kamat, k.kozlowski, linux-kernel,
	linux-input, linux-leds, linux-pm, rtc-linux, Robert Baldyga

This patch modifies max8997 driver and each associated function driver,
to use regmap instead of operating directly on i2c bus. It will allow to
simplify IRQ handling using regmap-irq.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

[For extcon part]
Acked-by: Chanwoo Choi <cw00.choi@samsung.com>

[For leds part]
Acked-by: Bryan Wu <cooloney@gmail.com>

[For the mfd part]
Acked-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/extcon/extcon-max8997.c     |  31 ++++----
 drivers/input/misc/max8997_haptic.c |  34 +++++----
 drivers/leds/leds-max8997.c         |  13 ++--
 drivers/mfd/Kconfig                 |   1 +
 drivers/mfd/max8997-irq.c           |  64 +++++++---------
 drivers/mfd/max8997.c               | 141 ++++++++++++++++--------------------
 drivers/power/max8997_charger.c     |  33 +++++----
 drivers/regulator/max8997.c         |  87 +++++++++++-----------
 drivers/rtc/rtc-max8997.c           |  56 +++++++-------
 include/linux/mfd/max8997-private.h |  17 ++---
 10 files changed, 228 insertions(+), 249 deletions(-)

diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
index 75e501c..2aafd5b 100644
--- a/drivers/extcon/extcon-max8997.c
+++ b/drivers/extcon/extcon-max8997.c
@@ -27,6 +27,7 @@
 #include <linux/mfd/max8997-private.h>
 #include <linux/extcon.h>
 #include <linux/irqdomain.h>
+#include <linux/regmap.h>
 
 #define	DEV_NAME			"max8997-muic"
 #define	DELAY_MS_DEFAULT		20000		/* unit: millisecond */
@@ -116,7 +117,7 @@ enum max8997_muic_charger_type {
 
 struct max8997_muic_info {
 	struct device *dev;
-	struct i2c_client *muic;
+	struct max8997_dev *max8997;
 	struct extcon_dev *edev;
 	int prev_cable_type;
 	int prev_chg_type;
@@ -190,10 +191,10 @@ static int max8997_muic_set_debounce_time(struct max8997_muic_info *info,
 	case ADC_DEBOUNCE_TIME_10MS:
 	case ADC_DEBOUNCE_TIME_25MS:
 	case ADC_DEBOUNCE_TIME_38_62MS:
-		ret = max8997_update_reg(info->muic,
+		ret = regmap_update_bits(info->max8997->regmap_muic,
 					  MAX8997_MUIC_REG_CONTROL3,
-					  time << CONTROL3_ADCDBSET_SHIFT,
-					  CONTROL3_ADCDBSET_MASK);
+					  CONTROL3_ADCDBSET_MASK,
+					  time << CONTROL3_ADCDBSET_SHIFT);
 		if (ret) {
 			dev_err(info->dev, "failed to set ADC debounce time\n");
 			return ret;
@@ -228,8 +229,8 @@ static int max8997_muic_set_path(struct max8997_muic_info *info,
 	else
 		ctrl1 = CONTROL1_SW_OPEN;
 
-	ret = max8997_update_reg(info->muic,
-			MAX8997_MUIC_REG_CONTROL1, ctrl1, COMP_SW_MASK);
+	ret = regmap_update_bits(info->max8997->regmap_muic,
+			MAX8997_MUIC_REG_CONTROL1, COMP_SW_MASK, ctrl1);
 	if (ret < 0) {
 		dev_err(info->dev, "failed to update MUIC register\n");
 		return ret;
@@ -240,9 +241,9 @@ static int max8997_muic_set_path(struct max8997_muic_info *info,
 	else
 		ctrl2 |= CONTROL2_LOWPWR_MASK;	/* LowPwr=1, CPEn=0 */
 
-	ret = max8997_update_reg(info->muic,
-			MAX8997_MUIC_REG_CONTROL2, ctrl2,
-			CONTROL2_LOWPWR_MASK | CONTROL2_CPEN_MASK);
+	ret = regmap_update_bits(info->max8997->regmap_muic,
+			MAX8997_MUIC_REG_CONTROL2,
+			CONTROL2_LOWPWR_MASK | CONTROL2_CPEN_MASK, ctrl2);
 	if (ret < 0) {
 		dev_err(info->dev, "failed to update MUIC register\n");
 		return ret;
@@ -543,8 +544,8 @@ static void max8997_muic_irq_work(struct work_struct *work)
 		if (info->irq == muic_irqs[i].virq)
 			irq_type = muic_irqs[i].irq;
 
-	ret = max8997_bulk_read(info->muic, MAX8997_MUIC_REG_STATUS1,
-				2, info->status);
+	ret = regmap_bulk_read(info->max8997->regmap_muic,
+				MAX8997_MUIC_REG_STATUS1, info->status, 2);
 	if (ret) {
 		dev_err(info->dev, "failed to read muic register\n");
 		mutex_unlock(&info->mutex);
@@ -605,8 +606,8 @@ static int max8997_muic_detect_dev(struct max8997_muic_info *info)
 	mutex_lock(&info->mutex);
 
 	/* Read STATUSx register to detect accessory */
-	ret = max8997_bulk_read(info->muic,
-			MAX8997_MUIC_REG_STATUS1, 2, info->status);
+	ret = regmap_bulk_read(info->max8997->regmap_muic,
+			MAX8997_MUIC_REG_STATUS1, info->status, 2);
 	if (ret) {
 		dev_err(info->dev, "failed to read MUIC register\n");
 		mutex_unlock(&info->mutex);
@@ -665,7 +666,7 @@ static int max8997_muic_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	info->dev = &pdev->dev;
-	info->muic = max8997->muic;
+	info->max8997 = max8997;
 
 	platform_set_drvdata(pdev, info);
 	mutex_init(&info->mutex);
@@ -717,7 +718,7 @@ static int max8997_muic_probe(struct platform_device *pdev)
 
 		/* Initialize registers according to platform data */
 		for (i = 0; i < muic_pdata->num_init_data; i++) {
-			max8997_write_reg(info->muic,
+			regmap_write(info->max8997->regmap_muic,
 					muic_pdata->init_data[i].addr,
 					muic_pdata->init_data[i].data);
 		}
diff --git a/drivers/input/misc/max8997_haptic.c b/drivers/input/misc/max8997_haptic.c
index a363ebb..53b32b5 100644
--- a/drivers/input/misc/max8997_haptic.c
+++ b/drivers/input/misc/max8997_haptic.c
@@ -31,6 +31,7 @@
 #include <linux/mfd/max8997-private.h>
 #include <linux/mfd/max8997.h>
 #include <linux/regulator/consumer.h>
+#include <linux/regmap.h>
 
 /* Haptic configuration 2 register */
 #define MAX8997_MOTOR_TYPE_SHIFT	7
@@ -45,7 +46,7 @@
 
 struct max8997_haptic {
 	struct device *dev;
-	struct i2c_client *client;
+	struct max8997_dev *max8997;
 	struct input_dev *input_dev;
 	struct regulator *regulator;
 
@@ -86,19 +87,19 @@ static int max8997_haptic_set_duty_cycle(struct max8997_haptic *chip)
 		}
 		switch (chip->internal_mode_pattern) {
 		case 0:
-			max8997_write_reg(chip->client,
+			regmap_write(chip->max8997->regmap_haptic,
 				MAX8997_HAPTIC_REG_SIGPWMDC1, duty_index);
 			break;
 		case 1:
-			max8997_write_reg(chip->client,
+			regmap_write(chip->max8997->regmap_haptic,
 				MAX8997_HAPTIC_REG_SIGPWMDC2, duty_index);
 			break;
 		case 2:
-			max8997_write_reg(chip->client,
+			regmap_write(chip->max8997->regmap_haptic,
 				MAX8997_HAPTIC_REG_SIGPWMDC3, duty_index);
 			break;
 		case 3:
-			max8997_write_reg(chip->client,
+			regmap_write(chip->max8997->regmap_haptic,
 				MAX8997_HAPTIC_REG_SIGPWMDC4, duty_index);
 			break;
 		default:
@@ -115,50 +116,51 @@ static void max8997_haptic_configure(struct max8997_haptic *chip)
 	value = chip->type << MAX8997_MOTOR_TYPE_SHIFT |
 		chip->enabled << MAX8997_ENABLE_SHIFT |
 		chip->mode << MAX8997_MODE_SHIFT | chip->pwm_divisor;
-	max8997_write_reg(chip->client, MAX8997_HAPTIC_REG_CONF2, value);
+	regmap_write(chip->max8997->regmap_haptic,
+		MAX8997_HAPTIC_REG_CONF2, value);
 
 	if (chip->mode == MAX8997_INTERNAL_MODE && chip->enabled) {
 		value = chip->internal_mode_pattern << MAX8997_CYCLE_SHIFT |
 			chip->internal_mode_pattern << MAX8997_SIG_PERIOD_SHIFT |
 			chip->internal_mode_pattern << MAX8997_SIG_DUTY_SHIFT |
 			chip->internal_mode_pattern << MAX8997_PWM_DUTY_SHIFT;
-		max8997_write_reg(chip->client,
+		regmap_write(chip->max8997->regmap_haptic,
 			MAX8997_HAPTIC_REG_DRVCONF, value);
 
 		switch (chip->internal_mode_pattern) {
 		case 0:
 			value = chip->pattern_cycle << 4;
-			max8997_write_reg(chip->client,
+			regmap_write(chip->max8997->regmap_haptic,
 				MAX8997_HAPTIC_REG_CYCLECONF1, value);
 			value = chip->pattern_signal_period;
-			max8997_write_reg(chip->client,
+			regmap_write(chip->max8997->regmap_haptic,
 				MAX8997_HAPTIC_REG_SIGCONF1, value);
 			break;
 
 		case 1:
 			value = chip->pattern_cycle;
-			max8997_write_reg(chip->client,
+			regmap_write(chip->max8997->regmap_haptic,
 				MAX8997_HAPTIC_REG_CYCLECONF1, value);
 			value = chip->pattern_signal_period;
-			max8997_write_reg(chip->client,
+			regmap_write(chip->max8997->regmap_haptic,
 				MAX8997_HAPTIC_REG_SIGCONF2, value);
 			break;
 
 		case 2:
 			value = chip->pattern_cycle << 4;
-			max8997_write_reg(chip->client,
+			regmap_write(chip->max8997->regmap_haptic,
 				MAX8997_HAPTIC_REG_CYCLECONF2, value);
 			value = chip->pattern_signal_period;
-			max8997_write_reg(chip->client,
+			regmap_write(chip->max8997->regmap_haptic,
 				MAX8997_HAPTIC_REG_SIGCONF3, value);
 			break;
 
 		case 3:
 			value = chip->pattern_cycle;
-			max8997_write_reg(chip->client,
+			regmap_write(chip->max8997->regmap_haptic,
 				MAX8997_HAPTIC_REG_CYCLECONF2, value);
 			value = chip->pattern_signal_period;
-			max8997_write_reg(chip->client,
+			regmap_write(chip->max8997->regmap_haptic,
 				MAX8997_HAPTIC_REG_SIGCONF4, value);
 			break;
 
@@ -277,7 +279,7 @@ static int max8997_haptic_probe(struct platform_device *pdev)
 	INIT_WORK(&chip->work, max8997_haptic_play_effect_work);
 	mutex_init(&chip->mutex);
 
-	chip->client = iodev->haptic;
+	chip->max8997 = iodev;
 	chip->dev = &pdev->dev;
 	chip->input_dev = input_dev;
 	chip->pwm_period = haptic_pdata->pwm_period;
diff --git a/drivers/leds/leds-max8997.c b/drivers/leds/leds-max8997.c
index 607bc27..49bb128 100644
--- a/drivers/leds/leds-max8997.c
+++ b/drivers/leds/leds-max8997.c
@@ -18,6 +18,7 @@
 #include <linux/mfd/max8997.h>
 #include <linux/mfd/max8997-private.h>
 #include <linux/platform_device.h>
+#include <linux/regmap.h>
 
 #define MAX8997_LED_FLASH_SHIFT			3
 #define MAX8997_LED_FLASH_CUR_MASK		0xf8
@@ -53,7 +54,6 @@ static void max8997_led_set_mode(struct max8997_led *led,
 			enum max8997_led_mode mode)
 {
 	int ret;
-	struct i2c_client *client = led->iodev->i2c;
 	u8 mask = 0, val;
 
 	switch (mode) {
@@ -89,8 +89,8 @@ static void max8997_led_set_mode(struct max8997_led *led,
 	}
 
 	if (mask) {
-		ret = max8997_update_reg(client, MAX8997_REG_LEN_CNTL, val,
-					 mask);
+		ret = regmap_update_bits(led->iodev->regmap,
+					MAX8997_REG_LEN_CNTL, mask, val);
 		if (ret)
 			dev_err(led->iodev->dev,
 				"failed to update register(%d)\n", ret);
@@ -102,7 +102,6 @@ static void max8997_led_set_mode(struct max8997_led *led,
 static void max8997_led_enable(struct max8997_led *led, bool enable)
 {
 	int ret;
-	struct i2c_client *client = led->iodev->i2c;
 	u8 val = 0, mask = MAX8997_LED_BOOST_ENABLE_MASK;
 
 	if (led->enabled == enable)
@@ -110,7 +109,8 @@ static void max8997_led_enable(struct max8997_led *led, bool enable)
 
 	val = enable ? MAX8997_LED_BOOST_ENABLE_MASK : 0;
 
-	ret = max8997_update_reg(client, MAX8997_REG_BOOST_CNTL, val, mask);
+	ret = regmap_update_bits(led->iodev->regmap,
+				MAX8997_REG_BOOST_CNTL, mask, val);
 	if (ret)
 		dev_err(led->iodev->dev,
 			"failed to update register(%d)\n", ret);
@@ -122,7 +122,6 @@ static void max8997_led_set_current(struct max8997_led *led,
 				enum led_brightness value)
 {
 	int ret;
-	struct i2c_client *client = led->iodev->i2c;
 	u8 val = 0, mask = 0, reg = 0;
 
 	switch (led->led_mode) {
@@ -143,7 +142,7 @@ static void max8997_led_set_current(struct max8997_led *led,
 	}
 
 	if (mask) {
-		ret = max8997_update_reg(client, reg, val, mask);
+		ret = regmap_update_bits(led->iodev->regmap, reg, mask, val);
 		if (ret)
 			dev_err(led->iodev->dev,
 				"failed to update register(%d)\n", ret);
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 72d3808..ca57035 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -463,6 +463,7 @@ config MFD_MAX8997
 	bool "Maxim Semiconductor MAX8997/8966 PMIC Support"
 	depends on I2C=y
 	select MFD_CORE
+	select REGMAP_I2C
 	select IRQ_DOMAIN
 	help
 	  Say yes here to add support for Maxim Semiconductor MAX8997/8966.
diff --git a/drivers/mfd/max8997-irq.c b/drivers/mfd/max8997-irq.c
index 43fa614..0e7ff39 100644
--- a/drivers/mfd/max8997-irq.c
+++ b/drivers/mfd/max8997-irq.c
@@ -26,6 +26,7 @@
 #include <linux/interrupt.h>
 #include <linux/mfd/max8997.h>
 #include <linux/mfd/max8997-private.h>
+#include <linux/regmap.h>
 
 static const u8 max8997_mask_reg[] = {
 	[PMIC_INT1] = MAX8997_REG_INT1MSK,
@@ -41,25 +42,6 @@ static const u8 max8997_mask_reg[] = {
 	[FLASH_STATUS] = MAX8997_REG_INVALID,
 };
 
-static struct i2c_client *get_i2c(struct max8997_dev *max8997,
-				enum max8997_irq_source src)
-{
-	switch (src) {
-	case PMIC_INT1 ... PMIC_INT4:
-		return max8997->i2c;
-	case FUEL_GAUGE:
-		return NULL;
-	case MUIC_INT1 ... MUIC_INT3:
-		return max8997->muic;
-	case GPIO_LOW ... GPIO_HI:
-		return max8997->i2c;
-	case FLASH_STATUS:
-		return max8997->i2c;
-	default:
-		return ERR_PTR(-EINVAL);
-	}
-}
-
 struct max8997_irq_data {
 	int mask;
 	enum max8997_irq_source group;
@@ -124,15 +106,20 @@ static void max8997_irq_sync_unlock(struct irq_data *data)
 	int i;
 
 	for (i = 0; i < MAX8997_IRQ_GROUP_NR; i++) {
+		struct regmap *map;
 		u8 mask_reg = max8997_mask_reg[i];
-		struct i2c_client *i2c = get_i2c(max8997, i);
+
+		if (i >= MUIC_INT1 && i <= MUIC_INT3)
+			map = max8997->regmap_muic;
+		else
+			map = max8997->regmap;
 
 		if (mask_reg == MAX8997_REG_INVALID ||
-				IS_ERR_OR_NULL(i2c))
+				IS_ERR_OR_NULL(map))
 			continue;
 		max8997->irq_masks_cache[i] = max8997->irq_masks_cur[i];
 
-		max8997_write_reg(i2c, max8997_mask_reg[i],
+		regmap_write(map, max8997_mask_reg[i],
 				max8997->irq_masks_cur[i]);
 	}
 
@@ -181,11 +168,11 @@ static irqreturn_t max8997_irq_thread(int irq, void *data)
 {
 	struct max8997_dev *max8997 = data;
 	u8 irq_reg[MAX8997_IRQ_GROUP_NR] = {};
-	u8 irq_src;
+	unsigned int irq_src;
 	int ret;
 	int i, cur_irq;
 
-	ret = max8997_read_reg(max8997->i2c, MAX8997_REG_INTSRC, &irq_src);
+	ret = regmap_read(max8997->regmap, MAX8997_REG_INTSRC, &irq_src);
 	if (ret < 0) {
 		dev_err(max8997->dev, "Failed to read interrupt source: %d\n",
 				ret);
@@ -194,8 +181,8 @@ static irqreturn_t max8997_irq_thread(int irq, void *data)
 
 	if (irq_src & MAX8997_IRQSRC_PMIC) {
 		/* PMIC INT1 ~ INT4 */
-		max8997_bulk_read(max8997->i2c, MAX8997_REG_INT1, 4,
-				&irq_reg[PMIC_INT1]);
+		regmap_bulk_read(max8997->regmap, MAX8997_REG_INT1,
+				&irq_reg[PMIC_INT1], 4);
 	}
 	if (irq_src & MAX8997_IRQSRC_FUELGAUGE) {
 		/*
@@ -215,8 +202,8 @@ static irqreturn_t max8997_irq_thread(int irq, void *data)
 	}
 	if (irq_src & MAX8997_IRQSRC_MUIC) {
 		/* MUIC INT1 ~ INT3 */
-		max8997_bulk_read(max8997->muic, MAX8997_MUIC_REG_INT1, 3,
-				&irq_reg[MUIC_INT1]);
+		regmap_bulk_read(max8997->regmap_muic, MAX8997_MUIC_REG_INT1,
+				&irq_reg[MUIC_INT1], 3);
 	}
 	if (irq_src & MAX8997_IRQSRC_GPIO) {
 		/* GPIO Interrupt */
@@ -225,8 +212,8 @@ static irqreturn_t max8997_irq_thread(int irq, void *data)
 		irq_reg[GPIO_LOW] = 0;
 		irq_reg[GPIO_HI] = 0;
 
-		max8997_bulk_read(max8997->i2c, MAX8997_REG_GPIOCNTL1,
-				MAX8997_NUM_GPIO, gpio_info);
+		regmap_bulk_read(max8997->regmap, MAX8997_REG_GPIOCNTL1,
+				gpio_info, MAX8997_NUM_GPIO);
 		for (i = 0; i < MAX8997_NUM_GPIO; i++) {
 			bool interrupt = false;
 
@@ -260,8 +247,10 @@ static irqreturn_t max8997_irq_thread(int irq, void *data)
 	}
 	if (irq_src & MAX8997_IRQSRC_FLASH) {
 		/* Flash Status Interrupt */
-		ret = max8997_read_reg(max8997->i2c, MAX8997_REG_FLASHSTATUS,
-				&irq_reg[FLASH_STATUS]);
+		unsigned int data;
+		ret = regmap_read(max8997->regmap,
+				MAX8997_REG_FLASHSTATUS, &data);
+		irq_reg[FLASH_STATUS] = data;
 	}
 
 	/* Apply masking */
@@ -312,7 +301,7 @@ int max8997_irq_init(struct max8997_dev *max8997)
 	struct irq_domain *domain;
 	int i;
 	int ret;
-	u8 val;
+	unsigned int val;
 
 	if (!max8997->irq) {
 		dev_warn(max8997->dev, "No interrupt specified.\n");
@@ -323,22 +312,19 @@ int max8997_irq_init(struct max8997_dev *max8997)
 
 	/* Mask individual interrupt sources */
 	for (i = 0; i < MAX8997_IRQ_GROUP_NR; i++) {
-		struct i2c_client *i2c;
-
 		max8997->irq_masks_cur[i] = 0xff;
 		max8997->irq_masks_cache[i] = 0xff;
-		i2c = get_i2c(max8997, i);
 
-		if (IS_ERR_OR_NULL(i2c))
+		if (IS_ERR_OR_NULL(max8997->regmap))
 			continue;
 		if (max8997_mask_reg[i] == MAX8997_REG_INVALID)
 			continue;
 
-		max8997_write_reg(i2c, max8997_mask_reg[i], 0xff);
+		regmap_write(max8997->regmap, max8997_mask_reg[i], 0xff);
 	}
 
 	for (i = 0; i < MAX8997_NUM_GPIO; i++) {
-		max8997->gpio_status[i] = (max8997_read_reg(max8997->i2c,
+		max8997->gpio_status[i] = (regmap_read(max8997->regmap,
 						MAX8997_REG_GPIOCNTL1 + i,
 						&val)
 					& MAX8997_GPIO_DATA_MASK) ?
diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c
index 595364e..c4a1072 100644
--- a/drivers/mfd/max8997.c
+++ b/drivers/mfd/max8997.c
@@ -33,6 +33,7 @@
 #include <linux/mfd/core.h>
 #include <linux/mfd/max8997.h>
 #include <linux/mfd/max8997-private.h>
+#include <linux/regmap.h>
 
 #define I2C_ADDR_PMIC	(0xCC >> 1)
 #define I2C_ADDR_MUIC	(0x4A >> 1)
@@ -57,81 +58,29 @@ static const struct of_device_id max8997_pmic_dt_match[] = {
 };
 #endif
 
-int max8997_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest)
-{
-	struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
-	int ret;
-
-	mutex_lock(&max8997->iolock);
-	ret = i2c_smbus_read_byte_data(i2c, reg);
-	mutex_unlock(&max8997->iolock);
-	if (ret < 0)
-		return ret;
-
-	ret &= 0xff;
-	*dest = ret;
-	return 0;
-}
-EXPORT_SYMBOL_GPL(max8997_read_reg);
-
-int max8997_bulk_read(struct i2c_client *i2c, u8 reg, int count, u8 *buf)
-{
-	struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
-	int ret;
-
-	mutex_lock(&max8997->iolock);
-	ret = i2c_smbus_read_i2c_block_data(i2c, reg, count, buf);
-	mutex_unlock(&max8997->iolock);
-	if (ret < 0)
-		return ret;
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(max8997_bulk_read);
-
-int max8997_write_reg(struct i2c_client *i2c, u8 reg, u8 value)
-{
-	struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
-	int ret;
-
-	mutex_lock(&max8997->iolock);
-	ret = i2c_smbus_write_byte_data(i2c, reg, value);
-	mutex_unlock(&max8997->iolock);
-	return ret;
-}
-EXPORT_SYMBOL_GPL(max8997_write_reg);
-
-int max8997_bulk_write(struct i2c_client *i2c, u8 reg, int count, u8 *buf)
-{
-	struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
-	int ret;
+static const struct regmap_config max8997_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = MAX8997_REG_PMIC_END,
+};
 
-	mutex_lock(&max8997->iolock);
-	ret = i2c_smbus_write_i2c_block_data(i2c, reg, count, buf);
-	mutex_unlock(&max8997->iolock);
-	if (ret < 0)
-		return ret;
+static const struct regmap_config max8997_regmap_rtc_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = MAX8997_RTC_REG_END,
+};
 
-	return 0;
-}
-EXPORT_SYMBOL_GPL(max8997_bulk_write);
+static const struct regmap_config max8997_regmap_haptic_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = MAX8997_HAPTIC_REG_END,
+};
 
-int max8997_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask)
-{
-	struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
-	int ret;
-
-	mutex_lock(&max8997->iolock);
-	ret = i2c_smbus_read_byte_data(i2c, reg);
-	if (ret >= 0) {
-		u8 old_val = ret & 0xff;
-		u8 new_val = (val & mask) | (old_val & (~mask));
-		ret = i2c_smbus_write_byte_data(i2c, reg, new_val);
-	}
-	mutex_unlock(&max8997->iolock);
-	return ret;
-}
-EXPORT_SYMBOL_GPL(max8997_update_reg);
+static const struct regmap_config max8997_regmap_muic_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = MAX8997_MUIC_REG_END,
+};
 
 /*
  * Only the common platform data elements for max8997 are parsed here from the
@@ -230,6 +179,41 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
 	}
 	i2c_set_clientdata(max8997->muic, max8997);
 
+	max8997->regmap = devm_regmap_init_i2c(i2c, &max8997_regmap_config);
+	if (IS_ERR(max8997->regmap)) {
+		ret = PTR_ERR(max8997->regmap);
+		dev_err(max8997->dev,
+				"failed to allocate register map: %d\n", ret);
+		return ret;
+	}
+
+	max8997->regmap_rtc = devm_regmap_init_i2c(max8997->rtc,
+					&max8997_regmap_rtc_config);
+	if (IS_ERR(max8997->regmap_rtc)) {
+		ret = PTR_ERR(max8997->regmap_rtc);
+		dev_err(max8997->dev,
+				"failed to allocate register map: %d\n", ret);
+		goto err_regmap;
+	}
+
+	max8997->regmap_haptic = devm_regmap_init_i2c(max8997->haptic,
+					&max8997_regmap_haptic_config);
+	if (IS_ERR(max8997->regmap_haptic)) {
+		ret = PTR_ERR(max8997->regmap_haptic);
+		dev_err(max8997->dev,
+				"failed to allocate register map: %d\n", ret);
+		goto err_regmap;
+	}
+
+	max8997->regmap_muic = devm_regmap_init_i2c(max8997->muic,
+					&max8997_regmap_muic_config);
+	if (IS_ERR(max8997->regmap_muic)) {
+		ret = PTR_ERR(max8997->regmap_muic);
+		dev_err(max8997->dev,
+				"failed to allocate register map: %d\n", ret);
+		goto err_regmap;
+	}
+
 	pm_runtime_set_active(max8997->dev);
 
 	max8997_irq_init(max8997);
@@ -254,6 +238,7 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
 
 err_mfd:
 	mfd_remove_devices(max8997->dev);
+err_regmap:
 	i2c_unregister_device(max8997->muic);
 err_i2c_muic:
 	i2c_unregister_device(max8997->haptic);
@@ -441,15 +426,15 @@ static int max8997_freeze(struct device *dev)
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_pmic); i++)
-		max8997_read_reg(i2c, max8997_dumpaddr_pmic[i],
+		regmap_read(max8997->regmap, max8997_dumpaddr_pmic[i],
 				&max8997->reg_dump[i]);
 
 	for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_muic); i++)
-		max8997_read_reg(i2c, max8997_dumpaddr_muic[i],
+		regmap_read(max8997->regmap_muic, max8997_dumpaddr_muic[i],
 				&max8997->reg_dump[i + MAX8997_REG_PMIC_END]);
 
 	for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_haptic); i++)
-		max8997_read_reg(i2c, max8997_dumpaddr_haptic[i],
+		regmap_read(max8997->regmap_haptic, max8997_dumpaddr_haptic[i],
 				&max8997->reg_dump[i + MAX8997_REG_PMIC_END +
 				MAX8997_MUIC_REG_END]);
 
@@ -463,15 +448,15 @@ static int max8997_restore(struct device *dev)
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_pmic); i++)
-		max8997_write_reg(i2c, max8997_dumpaddr_pmic[i],
+		regmap_write(max8997->regmap, max8997_dumpaddr_pmic[i],
 				max8997->reg_dump[i]);
 
 	for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_muic); i++)
-		max8997_write_reg(i2c, max8997_dumpaddr_muic[i],
+		regmap_write(max8997->regmap_muic, max8997_dumpaddr_muic[i],
 				max8997->reg_dump[i + MAX8997_REG_PMIC_END]);
 
 	for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_haptic); i++)
-		max8997_write_reg(i2c, max8997_dumpaddr_haptic[i],
+		regmap_write(max8997->regmap_haptic, max8997_dumpaddr_haptic[i],
 				max8997->reg_dump[i + MAX8997_REG_PMIC_END +
 				MAX8997_MUIC_REG_END]);
 
diff --git a/drivers/power/max8997_charger.c b/drivers/power/max8997_charger.c
index 4bdedfe..43d8481 100644
--- a/drivers/power/max8997_charger.c
+++ b/drivers/power/max8997_charger.c
@@ -26,6 +26,7 @@
 #include <linux/power_supply.h>
 #include <linux/mfd/max8997.h>
 #include <linux/mfd/max8997-private.h>
+#include <linux/regmap.h>
 
 struct charger_data {
 	struct device *dev;
@@ -46,14 +47,14 @@ static int max8997_battery_get_property(struct power_supply *psy,
 {
 	struct charger_data *charger = container_of(psy,
 			struct charger_data, battery);
-	struct i2c_client *i2c = charger->iodev->i2c;
 	int ret;
-	u8 reg;
+	unsigned int reg;
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_STATUS:
 		val->intval = 0;
-		ret = max8997_read_reg(i2c, MAX8997_REG_STATUS4, &reg);
+		ret = regmap_read(charger->iodev->regmap,
+				MAX8997_REG_STATUS4, &reg);
 		if (ret)
 			return ret;
 		if ((reg & (1 << 0)) == 0x1)
@@ -62,7 +63,8 @@ static int max8997_battery_get_property(struct power_supply *psy,
 		break;
 	case POWER_SUPPLY_PROP_PRESENT:
 		val->intval = 0;
-		ret = max8997_read_reg(i2c, MAX8997_REG_STATUS4, &reg);
+		ret = regmap_read(charger->iodev->regmap,
+				MAX8997_REG_STATUS4, &reg);
 		if (ret)
 			return ret;
 		if ((reg & (1 << 2)) == 0x0)
@@ -71,7 +73,8 @@ static int max8997_battery_get_property(struct power_supply *psy,
 		break;
 	case POWER_SUPPLY_PROP_ONLINE:
 		val->intval = 0;
-		ret = max8997_read_reg(i2c, MAX8997_REG_STATUS4, &reg);
+		ret = regmap_read(charger->iodev->regmap,
+				MAX8997_REG_STATUS4, &reg);
 		if (ret)
 			return ret;
 		/* DCINOK */
@@ -103,8 +106,8 @@ static int max8997_battery_probe(struct platform_device *pdev)
 		if (val > 0xf)
 			val = 0xf;
 
-		ret = max8997_update_reg(iodev->i2c,
-				MAX8997_REG_MBCCTRL5, val, 0xf);
+		ret = regmap_update_bits(iodev->regmap,
+				MAX8997_REG_MBCCTRL5, 0xf, val);
 		if (ret < 0) {
 			dev_err(&pdev->dev, "Cannot use i2c bus.\n");
 			return ret;
@@ -113,20 +116,20 @@ static int max8997_battery_probe(struct platform_device *pdev)
 
 	switch (pdata->timeout) {
 	case 5:
-		ret = max8997_update_reg(iodev->i2c, MAX8997_REG_MBCCTRL1,
-				0x2 << 4, 0x7 << 4);
+		ret = regmap_update_bits(iodev->regmap,
+				MAX8997_REG_MBCCTRL1, 0x7 << 4, 0x2 << 4);
 		break;
 	case 6:
-		ret = max8997_update_reg(iodev->i2c, MAX8997_REG_MBCCTRL1,
-				0x3 << 4, 0x7 << 4);
+		ret = regmap_update_bits(iodev->regmap,
+				MAX8997_REG_MBCCTRL1, 0x7 << 4, 0x3 << 4);
 		break;
 	case 7:
-		ret = max8997_update_reg(iodev->i2c, MAX8997_REG_MBCCTRL1,
-				0x4 << 4, 0x7 << 4);
+		ret = regmap_update_bits(iodev->regmap,
+				MAX8997_REG_MBCCTRL1, 0x7 << 4, 0x4 << 4);
 		break;
 	case 0:
-		ret = max8997_update_reg(iodev->i2c, MAX8997_REG_MBCCTRL1,
-				0x7 << 4, 0x7 << 4);
+		ret = regmap_update_bits(iodev->regmap,
+				MAX8997_REG_MBCCTRL1, 0x7 << 4, 0x7 << 4);
 		break;
 	default:
 		dev_err(&pdev->dev, "incorrect timeout value (%d)\n",
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c
index 9c31e21..faefd1c 100644
--- a/drivers/regulator/max8997.c
+++ b/drivers/regulator/max8997.c
@@ -33,6 +33,7 @@
 #include <linux/mfd/max8997.h>
 #include <linux/mfd/max8997-private.h>
 #include <linux/regulator/of_regulator.h>
+#include <linux/regmap.h>
 
 struct max8997_data {
 	struct device *dev;
@@ -50,7 +51,7 @@ struct max8997_data {
 	int buck125_gpioindex;
 	bool ignore_gpiodvs_side_effect;
 
-	u8 saved_states[MAX8997_REG_MAX];
+	unsigned int saved_states[MAX8997_REG_MAX];
 };
 
 static const unsigned int safeoutvolt[] = {
@@ -257,15 +258,14 @@ static int max8997_get_enable_register(struct regulator_dev *rdev,
 static int max8997_reg_is_enabled(struct regulator_dev *rdev)
 {
 	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
-	struct i2c_client *i2c = max8997->iodev->i2c;
 	int ret, reg, mask, pattern;
-	u8 val;
+	unsigned int val;
 
 	ret = max8997_get_enable_register(rdev, &reg, &mask, &pattern);
 	if (ret)
 		return ret;
 
-	ret = max8997_read_reg(i2c, reg, &val);
+	ret = regmap_read(max8997->iodev->regmap, reg, &val);
 	if (ret)
 		return ret;
 
@@ -275,27 +275,25 @@ static int max8997_reg_is_enabled(struct regulator_dev *rdev)
 static int max8997_reg_enable(struct regulator_dev *rdev)
 {
 	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
-	struct i2c_client *i2c = max8997->iodev->i2c;
 	int ret, reg, mask, pattern;
 
 	ret = max8997_get_enable_register(rdev, &reg, &mask, &pattern);
 	if (ret)
 		return ret;
 
-	return max8997_update_reg(i2c, reg, pattern, mask);
+	return regmap_update_bits(max8997->iodev->regmap, reg, mask, pattern);
 }
 
 static int max8997_reg_disable(struct regulator_dev *rdev)
 {
 	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
-	struct i2c_client *i2c = max8997->iodev->i2c;
 	int ret, reg, mask, pattern;
 
 	ret = max8997_get_enable_register(rdev, &reg, &mask, &pattern);
 	if (ret)
 		return ret;
 
-	return max8997_update_reg(i2c, reg, ~pattern, mask);
+	return regmap_update_bits(max8997->iodev->regmap, reg, mask, ~pattern);
 }
 
 static int max8997_get_voltage_register(struct regulator_dev *rdev,
@@ -367,15 +365,14 @@ static int max8997_get_voltage_register(struct regulator_dev *rdev,
 static int max8997_get_voltage_sel(struct regulator_dev *rdev)
 {
 	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
-	struct i2c_client *i2c = max8997->iodev->i2c;
 	int reg, shift, mask, ret;
-	u8 val;
+	unsigned int val;
 
 	ret = max8997_get_voltage_register(rdev, &reg, &shift, &mask);
 	if (ret)
 		return ret;
 
-	ret = max8997_read_reg(i2c, reg, &val);
+	ret = regmap_read(max8997->iodev->regmap, reg, &val);
 	if (ret)
 		return ret;
 
@@ -412,7 +409,6 @@ static int max8997_set_voltage_charger_cv(struct regulator_dev *rdev,
 		int min_uV, int max_uV, unsigned *selector)
 {
 	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
-	struct i2c_client *i2c = max8997->iodev->i2c;
 	int rid = rdev_get_id(rdev);
 	int lb, ub;
 	int reg, shift = 0, mask, ret = 0;
@@ -454,7 +450,8 @@ static int max8997_set_voltage_charger_cv(struct regulator_dev *rdev,
 
 	*selector = val;
 
-	ret = max8997_update_reg(i2c, reg, val << shift, mask);
+	ret = regmap_update_bits(max8997->iodev->regmap,
+				reg, mask, val << shift);
 
 	return ret;
 }
@@ -467,7 +464,6 @@ static int max8997_set_voltage_ldobuck(struct regulator_dev *rdev,
 		int min_uV, int max_uV, unsigned *selector)
 {
 	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
-	struct i2c_client *i2c = max8997->iodev->i2c;
 	const struct voltage_map_desc *desc;
 	int rid = rdev_get_id(rdev);
 	int i, reg, shift, mask, ret;
@@ -499,7 +495,8 @@ static int max8997_set_voltage_ldobuck(struct regulator_dev *rdev,
 	if (ret)
 		return ret;
 
-	ret = max8997_update_reg(i2c, reg, i << shift, mask << shift);
+	ret = regmap_update_bits(max8997->iodev->regmap,
+				reg, mask << shift, i << shift);
 	*selector = i;
 
 	return ret;
@@ -709,7 +706,6 @@ static int max8997_set_voltage_safeout_sel(struct regulator_dev *rdev,
 					   unsigned selector)
 {
 	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
-	struct i2c_client *i2c = max8997->iodev->i2c;
 	int rid = rdev_get_id(rdev);
 	int reg, shift = 0, mask, ret;
 
@@ -720,13 +716,13 @@ static int max8997_set_voltage_safeout_sel(struct regulator_dev *rdev,
 	if (ret)
 		return ret;
 
-	return max8997_update_reg(i2c, reg, selector << shift, mask << shift);
+	return regmap_update_bits(max8997->iodev->regmap,
+				reg, mask << shift, selector << shift);
 }
 
 static int max8997_reg_disable_suspend(struct regulator_dev *rdev)
 {
 	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
-	struct i2c_client *i2c = max8997->iodev->i2c;
 	int ret, reg, mask, pattern;
 	int rid = rdev_get_id(rdev);
 
@@ -734,20 +730,22 @@ static int max8997_reg_disable_suspend(struct regulator_dev *rdev)
 	if (ret)
 		return ret;
 
-	max8997_read_reg(i2c, reg, &max8997->saved_states[rid]);
+	regmap_read(max8997->iodev->regmap,
+			reg, &max8997->saved_states[rid]);
 
 	if (rid == MAX8997_LDO1 ||
 			rid == MAX8997_LDO10 ||
 			rid == MAX8997_LDO21) {
 		dev_dbg(&rdev->dev, "Conditional Power-Off for %s\n",
 				rdev->desc->name);
-		return max8997_update_reg(i2c, reg, 0x40, mask);
+		return regmap_update_bits(max8997->iodev->regmap,
+				reg, mask, 0x40);
 	}
 
 	dev_dbg(&rdev->dev, "Full Power-Off for %s (%xh -> %xh)\n",
 			rdev->desc->name, max8997->saved_states[rid] & mask,
 			(~pattern) & mask);
-	return max8997_update_reg(i2c, reg, ~pattern, mask);
+	return regmap_update_bits(max8997->iodev->regmap, reg, mask, ~pattern);
 }
 
 static struct regulator_ops max8997_ldo_ops = {
@@ -1030,7 +1028,6 @@ static int max8997_pmic_probe(struct platform_device *pdev)
 	struct regulator_config config = { };
 	struct regulator_dev *rdev;
 	struct max8997_data *max8997;
-	struct i2c_client *i2c;
 	int i, ret, nr_dvs;
 	u8 max_buck1 = 0, max_buck2 = 0, max_buck5 = 0;
 
@@ -1054,7 +1051,6 @@ static int max8997_pmic_probe(struct platform_device *pdev)
 	max8997->iodev = iodev;
 	max8997->num_regulators = pdata->num_regulators;
 	platform_set_drvdata(pdev, max8997);
-	i2c = max8997->iodev->i2c;
 
 	max8997->buck125_gpioindex = pdata->buck125_default_idx;
 	max8997->buck1_gpiodvs = pdata->buck1_gpiodvs;
@@ -1104,25 +1100,25 @@ static int max8997_pmic_probe(struct platform_device *pdev)
 
 	/* For the safety, set max voltage before setting up */
 	for (i = 0; i < 8; i++) {
-		max8997_update_reg(i2c, MAX8997_REG_BUCK1DVS1 + i,
-				max_buck1, 0x3f);
-		max8997_update_reg(i2c, MAX8997_REG_BUCK2DVS1 + i,
-				max_buck2, 0x3f);
-		max8997_update_reg(i2c, MAX8997_REG_BUCK5DVS1 + i,
-				max_buck5, 0x3f);
+		regmap_update_bits(max8997->iodev->regmap,
+				MAX8997_REG_BUCK1DVS1 + i, 0x3f, max_buck1);
+		regmap_update_bits(max8997->iodev->regmap,
+				MAX8997_REG_BUCK2DVS1 + i, 0x3f, max_buck2);
+		regmap_update_bits(max8997->iodev->regmap,
+				MAX8997_REG_BUCK5DVS1 + i, 0x3f, max_buck5);
 	}
 
 	/* Initialize all the DVS related BUCK registers */
 	for (i = 0; i < nr_dvs; i++) {
-		max8997_update_reg(i2c, MAX8997_REG_BUCK1DVS1 + i,
-				max8997->buck1_vol[i],
-				0x3f);
-		max8997_update_reg(i2c, MAX8997_REG_BUCK2DVS1 + i,
-				max8997->buck2_vol[i],
-				0x3f);
-		max8997_update_reg(i2c, MAX8997_REG_BUCK5DVS1 + i,
-				max8997->buck5_vol[i],
-				0x3f);
+		regmap_update_bits(max8997->iodev->regmap,
+				MAX8997_REG_BUCK1DVS1 + i,
+				0x3f, max8997->buck1_vol[i]);
+		regmap_update_bits(max8997->iodev->regmap,
+				MAX8997_REG_BUCK2DVS1 + i,
+				0x3f, max8997->buck2_vol[i]);
+		regmap_update_bits(max8997->iodev->regmap,
+				MAX8997_REG_BUCK5DVS1 + i,
+				0x3f, max8997->buck5_vol[i]);
 	}
 
 	/*
@@ -1166,16 +1162,17 @@ static int max8997_pmic_probe(struct platform_device *pdev)
 	}
 
 	/* DVS-GPIO disabled */
-	max8997_update_reg(i2c, MAX8997_REG_BUCK1CTRL, (pdata->buck1_gpiodvs) ?
-			(1 << 1) : (0 << 1), 1 << 1);
-	max8997_update_reg(i2c, MAX8997_REG_BUCK2CTRL, (pdata->buck2_gpiodvs) ?
-			(1 << 1) : (0 << 1), 1 << 1);
-	max8997_update_reg(i2c, MAX8997_REG_BUCK5CTRL, (pdata->buck5_gpiodvs) ?
-			(1 << 1) : (0 << 1), 1 << 1);
+	regmap_update_bits(max8997->iodev->regmap, MAX8997_REG_BUCK1CTRL,
+			1 << 1, (pdata->buck1_gpiodvs) ? (1 << 1) : (0 << 1));
+	regmap_update_bits(max8997->iodev->regmap, MAX8997_REG_BUCK2CTRL,
+			1 << 1, (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1));
+	regmap_update_bits(max8997->iodev->regmap, MAX8997_REG_BUCK5CTRL,
+			1 << 1, (pdata->buck5_gpiodvs) ? (1 << 1) : (0 << 1));
 
 	/* Misc Settings */
 	max8997->ramp_delay = 10; /* set 10mV/us, which is the default */
-	max8997_write_reg(i2c, MAX8997_REG_BUCKRAMP, (0xf << 4) | 0x9);
+	regmap_write(max8997->iodev->regmap,
+			MAX8997_REG_BUCKRAMP, (0xf << 4) | 0x9);
 
 	for (i = 0; i < pdata->num_regulators; i++) {
 		const struct voltage_map_desc *desc;
diff --git a/drivers/rtc/rtc-max8997.c b/drivers/rtc/rtc-max8997.c
index 0777c01..b866f7d5 100644
--- a/drivers/rtc/rtc-max8997.c
+++ b/drivers/rtc/rtc-max8997.c
@@ -20,6 +20,7 @@
 #include <linux/platform_device.h>
 #include <linux/mfd/max8997-private.h>
 #include <linux/irqdomain.h>
+#include <linux/regmap.h>
 
 /* Module parameter for WTSR function control */
 static int wtsr_en = 1;
@@ -68,7 +69,6 @@ enum {
 struct max8997_rtc_info {
 	struct device		*dev;
 	struct max8997_dev	*max8997;
-	struct i2c_client	*rtc;
 	struct rtc_device	*rtc_dev;
 	struct mutex		lock;
 	int virq;
@@ -118,8 +118,8 @@ static inline int max8997_rtc_set_update_reg(struct max8997_rtc_info *info)
 {
 	int ret;
 
-	ret = max8997_write_reg(info->rtc, MAX8997_RTC_UPDATE1,
-						RTC_UDR_MASK);
+	ret = regmap_write(info->max8997->regmap_rtc,
+				MAX8997_RTC_UPDATE1, RTC_UDR_MASK);
 	if (ret < 0)
 		dev_err(info->dev, "%s: fail to write update reg(%d)\n",
 				__func__, ret);
@@ -140,7 +140,8 @@ static int max8997_rtc_read_time(struct device *dev, struct rtc_time *tm)
 	int ret;
 
 	mutex_lock(&info->lock);
-	ret = max8997_bulk_read(info->rtc, MAX8997_RTC_SEC, RTC_NR_TIME, data);
+	ret = regmap_bulk_read(info->max8997->regmap_rtc,
+				MAX8997_RTC_SEC, data, RTC_NR_TIME);
 	mutex_unlock(&info->lock);
 
 	if (ret < 0) {
@@ -166,7 +167,8 @@ static int max8997_rtc_set_time(struct device *dev, struct rtc_time *tm)
 
 	mutex_lock(&info->lock);
 
-	ret = max8997_bulk_write(info->rtc, MAX8997_RTC_SEC, RTC_NR_TIME, data);
+	ret = regmap_bulk_write(info->max8997->regmap_rtc,
+				MAX8997_RTC_SEC, data, RTC_NR_TIME);
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
 				ret);
@@ -183,13 +185,13 @@ static int max8997_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
 	struct max8997_rtc_info *info = dev_get_drvdata(dev);
 	u8 data[RTC_NR_TIME];
-	u8 val;
+	unsigned int val;
 	int i, ret;
 
 	mutex_lock(&info->lock);
 
-	ret = max8997_bulk_read(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
-			data);
+	ret = regmap_bulk_read(info->max8997->regmap_rtc,
+				MAX8997_RTC_ALARM1_SEC, data, RTC_NR_TIME);
 	if (ret < 0) {
 		dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
 				__func__, __LINE__, ret);
@@ -207,7 +209,8 @@ static int max8997_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	}
 
 	alrm->pending = 0;
-	ret = max8997_read_reg(info->max8997->i2c, MAX8997_REG_STATUS1, &val);
+	ret = regmap_read(info->max8997->regmap_rtc,
+			       MAX8997_REG_STATUS1, &val);
 	if (ret < 0) {
 		dev_err(info->dev, "%s:%d fail to read status1 reg(%d)\n",
 				__func__, __LINE__, ret);
@@ -230,8 +233,8 @@ static int max8997_rtc_stop_alarm(struct max8997_rtc_info *info)
 	if (!mutex_is_locked(&info->lock))
 		dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
 
-	ret = max8997_bulk_read(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
-				data);
+	ret = regmap_bulk_read(info->max8997->regmap_rtc,
+				MAX8997_RTC_ALARM1_SEC, data, RTC_NR_TIME);
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
 				__func__, ret);
@@ -241,8 +244,8 @@ static int max8997_rtc_stop_alarm(struct max8997_rtc_info *info)
 	for (i = 0; i < RTC_NR_TIME; i++)
 		data[i] &= ~ALARM_ENABLE_MASK;
 
-	ret = max8997_bulk_write(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
-				 data);
+	ret = regmap_bulk_write(info->max8997->regmap_rtc,
+				 MAX8997_RTC_ALARM1_SEC, data, RTC_NR_TIME);
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
 				__func__, ret);
@@ -262,8 +265,8 @@ static int max8997_rtc_start_alarm(struct max8997_rtc_info *info)
 	if (!mutex_is_locked(&info->lock))
 		dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
 
-	ret = max8997_bulk_read(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
-				data);
+	ret = regmap_bulk_read(info->max8997->regmap_rtc,
+				MAX8997_RTC_ALARM1_SEC, data, RTC_NR_TIME);
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
 				__func__, ret);
@@ -281,8 +284,8 @@ static int max8997_rtc_start_alarm(struct max8997_rtc_info *info)
 	if (data[RTC_DATE] & 0x1f)
 		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
 
-	ret = max8997_bulk_write(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
-				 data);
+	ret = regmap_bulk_write(info->max8997->regmap_rtc,
+				 MAX8997_RTC_ALARM1_SEC, data, RTC_NR_TIME);
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
 				__func__, ret);
@@ -313,8 +316,8 @@ static int max8997_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	if (ret < 0)
 		goto out;
 
-	ret = max8997_bulk_write(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
-				data);
+	ret = regmap_bulk_write(info->max8997->regmap_rtc,
+				 MAX8997_RTC_ALARM1_SEC, data, RTC_NR_TIME);
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
 				__func__, ret);
@@ -385,7 +388,8 @@ static void max8997_rtc_enable_wtsr(struct max8997_rtc_info *info, bool enable)
 	dev_info(info->dev, "%s: %s WTSR\n", __func__,
 			enable ? "enable" : "disable");
 
-	ret = max8997_update_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, val, mask);
+	ret = regmap_update_bits(info->max8997->regmap_rtc,
+				 MAX8997_RTC_WTSR_SMPL, mask, val);
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to update WTSR reg(%d)\n",
 				__func__, ret);
@@ -398,7 +402,7 @@ static void max8997_rtc_enable_wtsr(struct max8997_rtc_info *info, bool enable)
 static void max8997_rtc_enable_smpl(struct max8997_rtc_info *info, bool enable)
 {
 	int ret;
-	u8 val, mask;
+	unsigned int val, mask;
 
 	if (!smpl_en)
 		return;
@@ -413,7 +417,8 @@ static void max8997_rtc_enable_smpl(struct max8997_rtc_info *info, bool enable)
 	dev_info(info->dev, "%s: %s SMPL\n", __func__,
 			enable ? "enable" : "disable");
 
-	ret = max8997_update_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, val, mask);
+	ret = regmap_update_bits(info->max8997->regmap_rtc,
+				 MAX8997_RTC_WTSR_SMPL, mask, val);
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to update SMPL reg(%d)\n",
 				__func__, ret);
@@ -423,7 +428,8 @@ static void max8997_rtc_enable_smpl(struct max8997_rtc_info *info, bool enable)
 	max8997_rtc_set_update_reg(info);
 
 	val = 0;
-	max8997_read_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, &val);
+	regmap_read(info->max8997->regmap_rtc,
+			 MAX8997_RTC_WTSR_SMPL, &val);
 	pr_info("%s: WTSR_SMPL(0x%02x)\n", __func__, val);
 }
 
@@ -438,7 +444,8 @@ static int max8997_rtc_init_reg(struct max8997_rtc_info *info)
 
 	info->rtc_24hr_mode = 1;
 
-	ret = max8997_bulk_write(info->rtc, MAX8997_RTC_CTRLMASK, 2, data);
+	ret = regmap_bulk_write(info->max8997->regmap_rtc,
+				 MAX8997_RTC_CTRLMASK, data, 2);
 	if (ret < 0) {
 		dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
 				__func__, ret);
@@ -463,7 +470,6 @@ static int max8997_rtc_probe(struct platform_device *pdev)
 	mutex_init(&info->lock);
 	info->dev = &pdev->dev;
 	info->max8997 = max8997;
-	info->rtc = max8997->rtc;
 
 	platform_set_drvdata(pdev, info);
 
diff --git a/include/linux/mfd/max8997-private.h b/include/linux/mfd/max8997-private.h
index 78c76cd..ea80ef8 100644
--- a/include/linux/mfd/max8997-private.h
+++ b/include/linux/mfd/max8997-private.h
@@ -309,6 +309,8 @@ enum max8997_rtc_reg {
 	MAX8997_RTC_ALARM2_MONTH	= 0x22,
 	MAX8997_RTC_ALARM2_YEAR		= 0x23,
 	MAX8997_RTC_ALARM2_DAY_OF_MONTH	= 0x24,
+
+	MAX8997_RTC_REG_END		= 0x25,
 };
 
 enum max8997_irq_source {
@@ -390,6 +392,11 @@ struct max8997_dev {
 	unsigned long type;
 	struct platform_device *battery; /* battery control (not fuel gauge) */
 
+	struct regmap *regmap;
+	struct regmap *regmap_rtc;
+	struct regmap *regmap_haptic;
+	struct regmap *regmap_muic;
+
 	int irq;
 	int ono;
 	struct irq_domain *irq_domain;
@@ -398,7 +405,7 @@ struct max8997_dev {
 	int irq_masks_cache[MAX8997_IRQ_GROUP_NR];
 
 	/* For hibernation */
-	u8 reg_dump[MAX8997_REG_PMIC_END + MAX8997_MUIC_REG_END +
+	unsigned int reg_dump[MAX8997_REG_PMIC_END + MAX8997_MUIC_REG_END +
 		MAX8997_HAPTIC_REG_END];
 
 	bool gpio_status[MAX8997_NUM_GPIO];
@@ -413,14 +420,6 @@ extern int max8997_irq_init(struct max8997_dev *max8997);
 extern void max8997_irq_exit(struct max8997_dev *max8997);
 extern int max8997_irq_resume(struct max8997_dev *max8997);
 
-extern int max8997_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest);
-extern int max8997_bulk_read(struct i2c_client *i2c, u8 reg, int count,
-				u8 *buf);
-extern int max8997_write_reg(struct i2c_client *i2c, u8 reg, u8 value);
-extern int max8997_bulk_write(struct i2c_client *i2c, u8 reg, int count,
-				u8 *buf);
-extern int max8997_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask);
-
 #define MAX8997_GPIO_INT_BOTH	(0x3 << 4)
 #define MAX8997_GPIO_INT_RISE	(0x2 << 4)
 #define MAX8997_GPIO_INT_FALL	(0x1 << 4)
-- 
1.9.1


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

* [PATCH v5 2/3] mfd: max8997: handle IRQs using regmap
  2014-11-12  7:23 [PATCH v5 0/3] mfd: max8997: add regmap support Robert Baldyga
  2014-11-12  7:23 ` [PATCH v5 1/3] mfd: max8997: use regmap to access registers Robert Baldyga
@ 2014-11-12  7:23 ` Robert Baldyga
  2014-11-12  7:23 ` [PATCH v5 3/3] mfd: max8997: change irq names to upper case Robert Baldyga
  2015-01-28 14:20 ` [PATCH v5 0/3] mfd: max8997: add regmap support Robert Baldyga
  3 siblings, 0 replies; 11+ messages in thread
From: Robert Baldyga @ 2014-11-12  7:23 UTC (permalink / raw)
  To: lee.jones
  Cc: sameo, myungjoo.ham, cw00.choi, dmitry.torokhov, cooloney,
	rpurdie, sre, dbaryshkov, dwmw2, lgirdwood, broonie, a.zummo,
	paul.gortmaker, sachin.kamat, k.kozlowski, linux-kernel,
	linux-input, linux-leds, linux-pm, rtc-linux, Robert Baldyga

This patch modifies mfd driver to use regmap for handling interrupts.
It allows to simplify irq handling process. This modifications needed
to make small changes in function drivers, which use interrupts.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

[For extcon part]
Acked-by: Chanwoo Choi <cw00.choi@samsung.com>

[For the mfd part]
Acked-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/extcon/extcon-max8997.c     |   3 +-
 drivers/mfd/Kconfig                 |   2 +-
 drivers/mfd/Makefile                |   2 +-
 drivers/mfd/max8997-irq.c           | 373 ------------------------------------
 drivers/mfd/max8997.c               | 112 ++++++++++-
 drivers/rtc/rtc-max8997.c           |   2 +-
 include/linux/mfd/max8997-private.h |  63 +++++-
 7 files changed, 165 insertions(+), 392 deletions(-)
 delete mode 100644 drivers/mfd/max8997-irq.c

diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
index 2aafd5b..172dbd6 100644
--- a/drivers/extcon/extcon-max8997.c
+++ b/drivers/extcon/extcon-max8997.c
@@ -677,7 +677,8 @@ static int max8997_muic_probe(struct platform_device *pdev)
 		struct max8997_muic_irq *muic_irq = &muic_irqs[i];
 		unsigned int virq = 0;
 
-		virq = irq_create_mapping(max8997->irq_domain, muic_irq->irq);
+		virq = regmap_irq_get_virq(max8997->irq_data_muic,
+					muic_irq->irq);
 		if (!virq) {
 			ret = -EINVAL;
 			goto err_irq;
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index ca57035..8cfc11b 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -464,7 +464,7 @@ config MFD_MAX8997
 	depends on I2C=y
 	select MFD_CORE
 	select REGMAP_I2C
-	select IRQ_DOMAIN
+	select REGMAP_IRQ
 	help
 	  Say yes here to add support for Maxim Semiconductor MAX8997/8966.
 	  This is a Power Management IC with RTC, Flash, Fuel Gauge, Haptic,
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 53467e2..e043ee4 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -120,7 +120,7 @@ obj-$(CONFIG_MFD_MAX77693)	+= max77693.o
 obj-$(CONFIG_MFD_MAX8907)	+= max8907.o
 max8925-objs			:= max8925-core.o max8925-i2c.o
 obj-$(CONFIG_MFD_MAX8925)	+= max8925.o
-obj-$(CONFIG_MFD_MAX8997)	+= max8997.o max8997-irq.o
+obj-$(CONFIG_MFD_MAX8997)	+= max8997.o
 obj-$(CONFIG_MFD_MAX8998)	+= max8998.o max8998-irq.o
 
 pcf50633-objs			:= pcf50633-core.o pcf50633-irq.o
diff --git a/drivers/mfd/max8997-irq.c b/drivers/mfd/max8997-irq.c
deleted file mode 100644
index 0e7ff39..0000000
--- a/drivers/mfd/max8997-irq.c
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
- * max8997-irq.c - Interrupt controller support for MAX8997
- *
- * Copyright (C) 2011 Samsung Electronics Co.Ltd
- * MyungJoo Ham <myungjoo.ham@samsung.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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * This driver is based on max8998-irq.c
- */
-
-#include <linux/err.h>
-#include <linux/irq.h>
-#include <linux/interrupt.h>
-#include <linux/mfd/max8997.h>
-#include <linux/mfd/max8997-private.h>
-#include <linux/regmap.h>
-
-static const u8 max8997_mask_reg[] = {
-	[PMIC_INT1] = MAX8997_REG_INT1MSK,
-	[PMIC_INT2] = MAX8997_REG_INT2MSK,
-	[PMIC_INT3] = MAX8997_REG_INT3MSK,
-	[PMIC_INT4] = MAX8997_REG_INT4MSK,
-	[FUEL_GAUGE] = MAX8997_REG_INVALID,
-	[MUIC_INT1] = MAX8997_MUIC_REG_INTMASK1,
-	[MUIC_INT2] = MAX8997_MUIC_REG_INTMASK2,
-	[MUIC_INT3] = MAX8997_MUIC_REG_INTMASK3,
-	[GPIO_LOW] = MAX8997_REG_INVALID,
-	[GPIO_HI] = MAX8997_REG_INVALID,
-	[FLASH_STATUS] = MAX8997_REG_INVALID,
-};
-
-struct max8997_irq_data {
-	int mask;
-	enum max8997_irq_source group;
-};
-
-#define DECLARE_IRQ(idx, _group, _mask)		\
-	[(idx)] = { .group = (_group), .mask = (_mask) }
-static const struct max8997_irq_data max8997_irqs[] = {
-	DECLARE_IRQ(MAX8997_PMICIRQ_PWRONR,	PMIC_INT1, 1 << 0),
-	DECLARE_IRQ(MAX8997_PMICIRQ_PWRONF,	PMIC_INT1, 1 << 1),
-	DECLARE_IRQ(MAX8997_PMICIRQ_PWRON1SEC,	PMIC_INT1, 1 << 3),
-	DECLARE_IRQ(MAX8997_PMICIRQ_JIGONR,	PMIC_INT1, 1 << 4),
-	DECLARE_IRQ(MAX8997_PMICIRQ_JIGONF,	PMIC_INT1, 1 << 5),
-	DECLARE_IRQ(MAX8997_PMICIRQ_LOWBAT2,	PMIC_INT1, 1 << 6),
-	DECLARE_IRQ(MAX8997_PMICIRQ_LOWBAT1,	PMIC_INT1, 1 << 7),
-
-	DECLARE_IRQ(MAX8997_PMICIRQ_JIGR,	PMIC_INT2, 1 << 0),
-	DECLARE_IRQ(MAX8997_PMICIRQ_JIGF,	PMIC_INT2, 1 << 1),
-	DECLARE_IRQ(MAX8997_PMICIRQ_MR,		PMIC_INT2, 1 << 2),
-	DECLARE_IRQ(MAX8997_PMICIRQ_DVS1OK,	PMIC_INT2, 1 << 3),
-	DECLARE_IRQ(MAX8997_PMICIRQ_DVS2OK,	PMIC_INT2, 1 << 4),
-	DECLARE_IRQ(MAX8997_PMICIRQ_DVS3OK,	PMIC_INT2, 1 << 5),
-	DECLARE_IRQ(MAX8997_PMICIRQ_DVS4OK,	PMIC_INT2, 1 << 6),
-
-	DECLARE_IRQ(MAX8997_PMICIRQ_CHGINS,	PMIC_INT3, 1 << 0),
-	DECLARE_IRQ(MAX8997_PMICIRQ_CHGRM,	PMIC_INT3, 1 << 1),
-	DECLARE_IRQ(MAX8997_PMICIRQ_DCINOVP,	PMIC_INT3, 1 << 2),
-	DECLARE_IRQ(MAX8997_PMICIRQ_TOPOFFR,	PMIC_INT3, 1 << 3),
-	DECLARE_IRQ(MAX8997_PMICIRQ_CHGRSTF,	PMIC_INT3, 1 << 5),
-	DECLARE_IRQ(MAX8997_PMICIRQ_MBCHGTMEXPD,	PMIC_INT3, 1 << 7),
-
-	DECLARE_IRQ(MAX8997_PMICIRQ_RTC60S,	PMIC_INT4, 1 << 0),
-	DECLARE_IRQ(MAX8997_PMICIRQ_RTCA1,	PMIC_INT4, 1 << 1),
-	DECLARE_IRQ(MAX8997_PMICIRQ_RTCA2,	PMIC_INT4, 1 << 2),
-	DECLARE_IRQ(MAX8997_PMICIRQ_SMPL_INT,	PMIC_INT4, 1 << 3),
-	DECLARE_IRQ(MAX8997_PMICIRQ_RTC1S,	PMIC_INT4, 1 << 4),
-	DECLARE_IRQ(MAX8997_PMICIRQ_WTSR,	PMIC_INT4, 1 << 5),
-
-	DECLARE_IRQ(MAX8997_MUICIRQ_ADCError,	MUIC_INT1, 1 << 2),
-	DECLARE_IRQ(MAX8997_MUICIRQ_ADCLow,	MUIC_INT1, 1 << 1),
-	DECLARE_IRQ(MAX8997_MUICIRQ_ADC,	MUIC_INT1, 1 << 0),
-
-	DECLARE_IRQ(MAX8997_MUICIRQ_VBVolt,	MUIC_INT2, 1 << 4),
-	DECLARE_IRQ(MAX8997_MUICIRQ_DBChg,	MUIC_INT2, 1 << 3),
-	DECLARE_IRQ(MAX8997_MUICIRQ_DCDTmr,	MUIC_INT2, 1 << 2),
-	DECLARE_IRQ(MAX8997_MUICIRQ_ChgDetRun,	MUIC_INT2, 1 << 1),
-	DECLARE_IRQ(MAX8997_MUICIRQ_ChgTyp,	MUIC_INT2, 1 << 0),
-
-	DECLARE_IRQ(MAX8997_MUICIRQ_OVP,	MUIC_INT3, 1 << 2),
-};
-
-static void max8997_irq_lock(struct irq_data *data)
-{
-	struct max8997_dev *max8997 = irq_get_chip_data(data->irq);
-
-	mutex_lock(&max8997->irqlock);
-}
-
-static void max8997_irq_sync_unlock(struct irq_data *data)
-{
-	struct max8997_dev *max8997 = irq_get_chip_data(data->irq);
-	int i;
-
-	for (i = 0; i < MAX8997_IRQ_GROUP_NR; i++) {
-		struct regmap *map;
-		u8 mask_reg = max8997_mask_reg[i];
-
-		if (i >= MUIC_INT1 && i <= MUIC_INT3)
-			map = max8997->regmap_muic;
-		else
-			map = max8997->regmap;
-
-		if (mask_reg == MAX8997_REG_INVALID ||
-				IS_ERR_OR_NULL(map))
-			continue;
-		max8997->irq_masks_cache[i] = max8997->irq_masks_cur[i];
-
-		regmap_write(map, max8997_mask_reg[i],
-				max8997->irq_masks_cur[i]);
-	}
-
-	mutex_unlock(&max8997->irqlock);
-}
-
-static const inline struct max8997_irq_data *
-irq_to_max8997_irq(struct max8997_dev *max8997, int irq)
-{
-	struct irq_data *data = irq_get_irq_data(irq);
-	return &max8997_irqs[data->hwirq];
-}
-
-static void max8997_irq_mask(struct irq_data *data)
-{
-	struct max8997_dev *max8997 = irq_get_chip_data(data->irq);
-	const struct max8997_irq_data *irq_data = irq_to_max8997_irq(max8997,
-								data->irq);
-
-	max8997->irq_masks_cur[irq_data->group] |= irq_data->mask;
-}
-
-static void max8997_irq_unmask(struct irq_data *data)
-{
-	struct max8997_dev *max8997 = irq_get_chip_data(data->irq);
-	const struct max8997_irq_data *irq_data = irq_to_max8997_irq(max8997,
-								data->irq);
-
-	max8997->irq_masks_cur[irq_data->group] &= ~irq_data->mask;
-}
-
-static struct irq_chip max8997_irq_chip = {
-	.name			= "max8997",
-	.irq_bus_lock		= max8997_irq_lock,
-	.irq_bus_sync_unlock	= max8997_irq_sync_unlock,
-	.irq_mask		= max8997_irq_mask,
-	.irq_unmask		= max8997_irq_unmask,
-};
-
-#define MAX8997_IRQSRC_PMIC		(1 << 1)
-#define MAX8997_IRQSRC_FUELGAUGE	(1 << 2)
-#define MAX8997_IRQSRC_MUIC		(1 << 3)
-#define MAX8997_IRQSRC_GPIO		(1 << 4)
-#define MAX8997_IRQSRC_FLASH		(1 << 5)
-static irqreturn_t max8997_irq_thread(int irq, void *data)
-{
-	struct max8997_dev *max8997 = data;
-	u8 irq_reg[MAX8997_IRQ_GROUP_NR] = {};
-	unsigned int irq_src;
-	int ret;
-	int i, cur_irq;
-
-	ret = regmap_read(max8997->regmap, MAX8997_REG_INTSRC, &irq_src);
-	if (ret < 0) {
-		dev_err(max8997->dev, "Failed to read interrupt source: %d\n",
-				ret);
-		return IRQ_NONE;
-	}
-
-	if (irq_src & MAX8997_IRQSRC_PMIC) {
-		/* PMIC INT1 ~ INT4 */
-		regmap_bulk_read(max8997->regmap, MAX8997_REG_INT1,
-				&irq_reg[PMIC_INT1], 4);
-	}
-	if (irq_src & MAX8997_IRQSRC_FUELGAUGE) {
-		/*
-		 * TODO: FUEL GAUGE
-		 *
-		 * This is to be supported by Max17042 driver. When
-		 * an interrupt incurs here, it should be relayed to a
-		 * Max17042 device that is connected (probably by
-		 * platform-data). However, we do not have interrupt
-		 * handling in Max17042 driver currently. The Max17042 IRQ
-		 * driver should be ready to be used as a stand-alone device and
-		 * a Max8997-dependent device. Because it is not ready in
-		 * Max17042-side and it is not too critical in operating
-		 * Max8997, we do not implement this in initial releases.
-		 */
-		irq_reg[FUEL_GAUGE] = 0;
-	}
-	if (irq_src & MAX8997_IRQSRC_MUIC) {
-		/* MUIC INT1 ~ INT3 */
-		regmap_bulk_read(max8997->regmap_muic, MAX8997_MUIC_REG_INT1,
-				&irq_reg[MUIC_INT1], 3);
-	}
-	if (irq_src & MAX8997_IRQSRC_GPIO) {
-		/* GPIO Interrupt */
-		u8 gpio_info[MAX8997_NUM_GPIO];
-
-		irq_reg[GPIO_LOW] = 0;
-		irq_reg[GPIO_HI] = 0;
-
-		regmap_bulk_read(max8997->regmap, MAX8997_REG_GPIOCNTL1,
-				gpio_info, MAX8997_NUM_GPIO);
-		for (i = 0; i < MAX8997_NUM_GPIO; i++) {
-			bool interrupt = false;
-
-			switch (gpio_info[i] & MAX8997_GPIO_INT_MASK) {
-			case MAX8997_GPIO_INT_BOTH:
-				if (max8997->gpio_status[i] != gpio_info[i])
-					interrupt = true;
-				break;
-			case MAX8997_GPIO_INT_RISE:
-				if ((max8997->gpio_status[i] != gpio_info[i]) &&
-				    (gpio_info[i] & MAX8997_GPIO_DATA_MASK))
-					interrupt = true;
-				break;
-			case MAX8997_GPIO_INT_FALL:
-				if ((max8997->gpio_status[i] != gpio_info[i]) &&
-				    !(gpio_info[i] & MAX8997_GPIO_DATA_MASK))
-					interrupt = true;
-				break;
-			default:
-				break;
-			}
-
-			if (interrupt) {
-				if (i < 8)
-					irq_reg[GPIO_LOW] |= (1 << i);
-				else
-					irq_reg[GPIO_HI] |= (1 << (i - 8));
-			}
-
-		}
-	}
-	if (irq_src & MAX8997_IRQSRC_FLASH) {
-		/* Flash Status Interrupt */
-		unsigned int data;
-		ret = regmap_read(max8997->regmap,
-				MAX8997_REG_FLASHSTATUS, &data);
-		irq_reg[FLASH_STATUS] = data;
-	}
-
-	/* Apply masking */
-	for (i = 0; i < MAX8997_IRQ_GROUP_NR; i++)
-		irq_reg[i] &= ~max8997->irq_masks_cur[i];
-
-	/* Report */
-	for (i = 0; i < MAX8997_IRQ_NR; i++) {
-		if (irq_reg[max8997_irqs[i].group] & max8997_irqs[i].mask) {
-			cur_irq = irq_find_mapping(max8997->irq_domain, i);
-			if (cur_irq)
-				handle_nested_irq(cur_irq);
-		}
-	}
-
-	return IRQ_HANDLED;
-}
-
-int max8997_irq_resume(struct max8997_dev *max8997)
-{
-	if (max8997->irq && max8997->irq_domain)
-		max8997_irq_thread(0, max8997);
-	return 0;
-}
-
-static int max8997_irq_domain_map(struct irq_domain *d, unsigned int irq,
-					irq_hw_number_t hw)
-{
-	struct max8997_dev *max8997 = d->host_data;
-
-	irq_set_chip_data(irq, max8997);
-	irq_set_chip_and_handler(irq, &max8997_irq_chip, handle_edge_irq);
-	irq_set_nested_thread(irq, 1);
-#ifdef CONFIG_ARM
-	set_irq_flags(irq, IRQF_VALID);
-#else
-	irq_set_noprobe(irq);
-#endif
-	return 0;
-}
-
-static struct irq_domain_ops max8997_irq_domain_ops = {
-	.map = max8997_irq_domain_map,
-};
-
-int max8997_irq_init(struct max8997_dev *max8997)
-{
-	struct irq_domain *domain;
-	int i;
-	int ret;
-	unsigned int val;
-
-	if (!max8997->irq) {
-		dev_warn(max8997->dev, "No interrupt specified.\n");
-		return 0;
-	}
-
-	mutex_init(&max8997->irqlock);
-
-	/* Mask individual interrupt sources */
-	for (i = 0; i < MAX8997_IRQ_GROUP_NR; i++) {
-		max8997->irq_masks_cur[i] = 0xff;
-		max8997->irq_masks_cache[i] = 0xff;
-
-		if (IS_ERR_OR_NULL(max8997->regmap))
-			continue;
-		if (max8997_mask_reg[i] == MAX8997_REG_INVALID)
-			continue;
-
-		regmap_write(max8997->regmap, max8997_mask_reg[i], 0xff);
-	}
-
-	for (i = 0; i < MAX8997_NUM_GPIO; i++) {
-		max8997->gpio_status[i] = (regmap_read(max8997->regmap,
-						MAX8997_REG_GPIOCNTL1 + i,
-						&val)
-					& MAX8997_GPIO_DATA_MASK) ?
-					true : false;
-	}
-
-	domain = irq_domain_add_linear(NULL, MAX8997_IRQ_NR,
-					&max8997_irq_domain_ops, max8997);
-	if (!domain) {
-		dev_err(max8997->dev, "could not create irq domain\n");
-		return -ENODEV;
-	}
-	max8997->irq_domain = domain;
-
-	ret = request_threaded_irq(max8997->irq, NULL, max8997_irq_thread,
-			IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
-			"max8997-irq", max8997);
-
-	if (ret) {
-		dev_err(max8997->dev, "Failed to request IRQ %d: %d\n",
-				max8997->irq, ret);
-		return ret;
-	}
-
-	if (!max8997->ono)
-		return 0;
-
-	ret = request_threaded_irq(max8997->ono, NULL, max8997_irq_thread,
-			IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING |
-			IRQF_ONESHOT, "max8997-ono", max8997);
-
-	if (ret)
-		dev_err(max8997->dev, "Failed to request ono-IRQ %d: %d\n",
-				max8997->ono, ret);
-
-	return 0;
-}
-
-void max8997_irq_exit(struct max8997_dev *max8997)
-{
-	if (max8997->ono)
-		free_irq(max8997->ono, max8997);
-
-	if (max8997->irq)
-		free_irq(max8997->irq, max8997);
-}
diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c
index c4a1072..8f50716 100644
--- a/drivers/mfd/max8997.c
+++ b/drivers/mfd/max8997.c
@@ -64,6 +64,49 @@ static const struct regmap_config max8997_regmap_config = {
 	.max_register = MAX8997_REG_PMIC_END,
 };
 
+static const struct regmap_irq max8997_irqs[] = {
+	/* PMIC_INT1 interrupts */
+	{ .reg_offset = 0, .mask = PMIC_INT1_PWRONR_MASK, },
+	{ .reg_offset = 0, .mask = PMIC_INT1_PWRONF_MASK, },
+	{ .reg_offset = 0, .mask = PMIC_INT1_PWRON1SEC_MASK, },
+	{ .reg_offset = 0, .mask = PMIC_INT1_JIGONR_MASK, },
+	{ .reg_offset = 0, .mask = PMIC_INT1_JIGONF_MASK, },
+	{ .reg_offset = 0, .mask = PMIC_INT1_LOWBAT2_MASK, },
+	{ .reg_offset = 0, .mask = PMIC_INT1_LOWBAT1_MASK, },
+	/* PMIC_INT2 interrupts */
+	{ .reg_offset = 1, .mask = PMIC_INT2_JIGR_MASK, },
+	{ .reg_offset = 1, .mask = PMIC_INT2_JIGF_MASK, },
+	{ .reg_offset = 1, .mask = PMIC_INT2_MR_MASK, },
+	{ .reg_offset = 1, .mask = PMIC_INT2_DVS1OK_MASK, },
+	{ .reg_offset = 1, .mask = PMIC_INT2_DVS2OK_MASK, },
+	{ .reg_offset = 1, .mask = PMIC_INT2_DVS3OK_MASK, },
+	{ .reg_offset = 1, .mask = PMIC_INT2_DVS4OK_MASK, },
+	/* PMIC_INT3 interrupts */
+	{ .reg_offset = 2, .mask = PMIC_INT3_CHGINS_MASK, },
+	{ .reg_offset = 2, .mask = PMIC_INT3_CHGRM_MASK, },
+	{ .reg_offset = 2, .mask = PMIC_INT3_DCINOVP_MASK, },
+	{ .reg_offset = 2, .mask = PMIC_INT3_TOPOFFR_MASK, },
+	{ .reg_offset = 2, .mask = PMIC_INT3_CHGRSTF_MASK, },
+	{ .reg_offset = 2, .mask = PMIC_INT3_MBCHGTMEXPD_MASK, },
+	/* PMIC_INT4 interrupts */
+	{ .reg_offset = 3, .mask = PMIC_INT4_RTC60S_MASK, },
+	{ .reg_offset = 3, .mask = PMIC_INT4_RTCA1_MASK, },
+	{ .reg_offset = 3, .mask = PMIC_INT4_RTCA2_MASK, },
+	{ .reg_offset = 3, .mask = PMIC_INT4_SMPL_INT_MASK, },
+	{ .reg_offset = 3, .mask = PMIC_INT4_RTC1S_MASK, },
+	{ .reg_offset = 3, .mask = PMIC_INT4_WTSR_MASK, },
+};
+
+static const struct regmap_irq_chip max8997_irq_chip = {
+	.name			= "max8997",
+	.status_base		= MAX8997_REG_INT1,
+	.mask_base		= MAX8997_REG_INT1MSK,
+	.mask_invert		= false,
+	.num_regs		= 4,
+	.irqs			= max8997_irqs,
+	.num_irqs		= ARRAY_SIZE(max8997_irqs),
+};
+
 static const struct regmap_config max8997_regmap_rtc_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
@@ -82,6 +125,31 @@ static const struct regmap_config max8997_regmap_muic_config = {
 	.max_register = MAX8997_MUIC_REG_END,
 };
 
+static const struct regmap_irq max8997_irqs_muic[] = {
+	/* MUIC_INT1 interrupts */
+	{ .reg_offset = 0, .mask = MUIC_INT1_ADC_MASK, },
+	{ .reg_offset = 0, .mask = MUIC_INT1_ADCLOW_MASK, },
+	{ .reg_offset = 0, .mask = MUIC_INT1_ADCERROR_MASK, },
+	/* MUIC_INT2 interrupts */
+	{ .reg_offset = 1, .mask = MUIC_INT2_CHGTYP_MASK, },
+	{ .reg_offset = 1, .mask = MUIC_INT2_CHGDETRUN_MASK, },
+	{ .reg_offset = 1, .mask = MUIC_INT2_DCDTMR_MASK, },
+	{ .reg_offset = 1, .mask = MUIC_INT2_DBCHG_MASK, },
+	{ .reg_offset = 1, .mask = MUIC_INT2_VBVOLT_MASK, },
+	/* MUIC_INT3 interrupts */
+	{ .reg_offset = 2, .mask = MUIC_INT3_OVP_MASK, },
+};
+
+static const struct regmap_irq_chip max8997_irq_chip_muic = {
+	.name			= "max8997-muic",
+	.status_base		= MAX8997_MUIC_REG_INT1,
+	.mask_base		= MAX8997_MUIC_REG_INTMASK1,
+	.mask_invert		= true,
+	.num_regs		= 3,
+	.irqs			= max8997_irqs_muic,
+	.num_irqs		= ARRAY_SIZE(max8997_irqs_muic),
+};
+
 /*
  * Only the common platform data elements for max8997 are parsed here from the
  * device tree. Other sub-modules of max8997 such as pmic, rtc and others have
@@ -214,9 +282,26 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
 		goto err_regmap;
 	}
 
-	pm_runtime_set_active(max8997->dev);
+	ret = regmap_add_irq_chip(max8997->regmap, max8997->irq,
+				IRQF_ONESHOT | IRQF_SHARED |
+				IRQF_TRIGGER_FALLING, 0,
+				&max8997_irq_chip, &max8997->irq_data);
+	if (ret) {
+		dev_err(max8997->dev, "failed to add irq chip: %d\n", ret);
+		goto err_regmap;
+	}
 
-	max8997_irq_init(max8997);
+	ret = regmap_add_irq_chip(max8997->regmap_muic, max8997->irq,
+				IRQF_ONESHOT | IRQF_SHARED |
+				IRQF_TRIGGER_FALLING, 0,
+				&max8997_irq_chip_muic,
+				&max8997->irq_data_muic);
+	if (ret) {
+		dev_err(max8997->dev, "failed to add irq chip: %d\n", ret);
+		goto err_irq_muic;
+	}
+
+	pm_runtime_set_active(max8997->dev);
 
 	ret = mfd_add_devices(max8997->dev, -1, max8997_devs,
 			ARRAY_SIZE(max8997_devs),
@@ -238,6 +323,9 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
 
 err_mfd:
 	mfd_remove_devices(max8997->dev);
+	regmap_del_irq_chip(max8997->irq, max8997->irq_data_muic);
+err_irq_muic:
+	regmap_del_irq_chip(max8997->irq, max8997->irq_data);
 err_regmap:
 	i2c_unregister_device(max8997->muic);
 err_i2c_muic:
@@ -252,6 +340,10 @@ static int max8997_i2c_remove(struct i2c_client *i2c)
 	struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
 
 	mfd_remove_devices(max8997->dev);
+
+	regmap_del_irq_chip(max8997->irq, max8997->irq_data_muic);
+	regmap_del_irq_chip(max8997->irq, max8997->irq_data);
+
 	i2c_unregister_device(max8997->muic);
 	i2c_unregister_device(max8997->haptic);
 	i2c_unregister_device(max8997->rtc);
@@ -468,8 +560,11 @@ static int max8997_suspend(struct device *dev)
 	struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
 	struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
 
-	if (device_may_wakeup(dev))
-		irq_set_irq_wake(max8997->irq, 1);
+	if (device_may_wakeup(dev)) {
+		enable_irq_wake(max8997->irq);
+		disable_irq(max8997->irq);
+	}
+
 	return 0;
 }
 
@@ -478,9 +573,12 @@ static int max8997_resume(struct device *dev)
 	struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
 	struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
 
-	if (device_may_wakeup(dev))
-		irq_set_irq_wake(max8997->irq, 0);
-	return max8997_irq_resume(max8997);
+	if (device_may_wakeup(dev)) {
+		disable_irq_wake(max8997->irq);
+		enable_irq(max8997->irq);
+	}
+
+	return 0;
 }
 
 static const struct dev_pm_ops max8997_pm = {
diff --git a/drivers/rtc/rtc-max8997.c b/drivers/rtc/rtc-max8997.c
index b866f7d5..22769ea 100644
--- a/drivers/rtc/rtc-max8997.c
+++ b/drivers/rtc/rtc-max8997.c
@@ -494,7 +494,7 @@ static int max8997_rtc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	virq = irq_create_mapping(max8997->irq_domain, MAX8997_PMICIRQ_RTCA1);
+	virq = regmap_irq_get_virq(max8997->irq_data, MAX8997_PMICIRQ_RTCA1);
 	if (!virq) {
 		dev_err(&pdev->dev, "Failed to create mapping alarm IRQ\n");
 		ret = -ENXIO;
diff --git a/include/linux/mfd/max8997-private.h b/include/linux/mfd/max8997-private.h
index ea80ef8..f42ea22 100644
--- a/include/linux/mfd/max8997-private.h
+++ b/include/linux/mfd/max8997-private.h
@@ -333,6 +333,48 @@ enum max8997_irq_source {
 	MAX8997_IRQ_GROUP_NR,
 };
 
+#define PMIC_INT1_PWRONR_MASK		(0x1 << 0)
+#define PMIC_INT1_PWRONF_MASK		(0x1 << 1)
+#define PMIC_INT1_PWRON1SEC_MASK	(0x1 << 3)
+#define PMIC_INT1_JIGONR_MASK		(0x1 << 4)
+#define PMIC_INT1_JIGONF_MASK		(0x1 << 5)
+#define PMIC_INT1_LOWBAT2_MASK		(0x1 << 6)
+#define PMIC_INT1_LOWBAT1_MASK		(0x1 << 7)
+
+#define PMIC_INT2_JIGR_MASK		(0x1 << 0)
+#define PMIC_INT2_JIGF_MASK		(0x1 << 1)
+#define PMIC_INT2_MR_MASK		(0x1 << 2)
+#define PMIC_INT2_DVS1OK_MASK		(0x1 << 3)
+#define PMIC_INT2_DVS2OK_MASK		(0x1 << 4)
+#define PMIC_INT2_DVS3OK_MASK		(0x1 << 5)
+#define PMIC_INT2_DVS4OK_MASK		(0x1 << 6)
+
+#define PMIC_INT3_CHGINS_MASK		(0x1 << 0)
+#define PMIC_INT3_CHGRM_MASK		(0x1 << 1)
+#define PMIC_INT3_DCINOVP_MASK		(0x1 << 2)
+#define PMIC_INT3_TOPOFFR_MASK		(0x1 << 3)
+#define PMIC_INT3_CHGRSTF_MASK		(0x1 << 5)
+#define PMIC_INT3_MBCHGTMEXPD_MASK	(0x1 << 7)
+
+#define PMIC_INT4_RTC60S_MASK		(0x1 << 0)
+#define PMIC_INT4_RTCA1_MASK		(0x1 << 1)
+#define PMIC_INT4_RTCA2_MASK		(0x1 << 2)
+#define PMIC_INT4_SMPL_INT_MASK		(0x1 << 3)
+#define PMIC_INT4_RTC1S_MASK		(0x1 << 4)
+#define PMIC_INT4_WTSR_MASK		(0x1 << 5)
+
+#define MUIC_INT1_ADC_MASK		(0x1 << 0)
+#define MUIC_INT1_ADCLOW_MASK		(0x1 << 1)
+#define MUIC_INT1_ADCERROR_MASK		(0x1 << 2)
+
+#define MUIC_INT2_CHGTYP_MASK		(0x1 << 0)
+#define MUIC_INT2_CHGDETRUN_MASK	(0x1 << 1)
+#define MUIC_INT2_DCDTMR_MASK		(0x1 << 2)
+#define MUIC_INT2_DBCHG_MASK		(0x1 << 3)
+#define MUIC_INT2_VBVOLT_MASK		(0x1 << 4)
+
+#define MUIC_INT3_OVP_MASK		(0x1 << 2)
+
 enum max8997_irq {
 	MAX8997_PMICIRQ_PWRONR,
 	MAX8997_PMICIRQ_PWRONF,
@@ -364,19 +406,23 @@ enum max8997_irq {
 	MAX8997_PMICIRQ_RTC1S,
 	MAX8997_PMICIRQ_WTSR,
 
-	MAX8997_MUICIRQ_ADCError,
-	MAX8997_MUICIRQ_ADCLow,
+	MAX8997_PMICIRQ_NR,
+};
+
+enum max8997_irq_muic {
 	MAX8997_MUICIRQ_ADC,
+	MAX8997_MUICIRQ_ADCLow,
+	MAX8997_MUICIRQ_ADCError,
 
-	MAX8997_MUICIRQ_VBVolt,
-	MAX8997_MUICIRQ_DBChg,
-	MAX8997_MUICIRQ_DCDTmr,
-	MAX8997_MUICIRQ_ChgDetRun,
 	MAX8997_MUICIRQ_ChgTyp,
+	MAX8997_MUICIRQ_ChgDetRun,
+	MAX8997_MUICIRQ_DCDTmr,
+	MAX8997_MUICIRQ_DBChg,
+	MAX8997_MUICIRQ_VBVolt,
 
 	MAX8997_MUICIRQ_OVP,
 
-	MAX8997_IRQ_NR,
+	MAX8997_MUCIRQ_NR,
 };
 
 #define MAX8997_NUM_GPIO	12
@@ -397,9 +443,10 @@ struct max8997_dev {
 	struct regmap *regmap_haptic;
 	struct regmap *regmap_muic;
 
+	struct regmap_irq_chip_data *irq_data;
+	struct regmap_irq_chip_data *irq_data_muic;
 	int irq;
 	int ono;
-	struct irq_domain *irq_domain;
 	struct mutex irqlock;
 	int irq_masks_cur[MAX8997_IRQ_GROUP_NR];
 	int irq_masks_cache[MAX8997_IRQ_GROUP_NR];
-- 
1.9.1


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

* [PATCH v5 3/3] mfd: max8997: change irq names to upper case
  2014-11-12  7:23 [PATCH v5 0/3] mfd: max8997: add regmap support Robert Baldyga
  2014-11-12  7:23 ` [PATCH v5 1/3] mfd: max8997: use regmap to access registers Robert Baldyga
  2014-11-12  7:23 ` [PATCH v5 2/3] mfd: max8997: handle IRQs using regmap Robert Baldyga
@ 2014-11-12  7:23 ` Robert Baldyga
  2015-01-30  1:00   ` Chanwoo Choi
  2015-01-28 14:20 ` [PATCH v5 0/3] mfd: max8997: add regmap support Robert Baldyga
  3 siblings, 1 reply; 11+ messages in thread
From: Robert Baldyga @ 2014-11-12  7:23 UTC (permalink / raw)
  To: lee.jones
  Cc: sameo, myungjoo.ham, cw00.choi, dmitry.torokhov, cooloney,
	rpurdie, sre, dbaryshkov, dwmw2, lgirdwood, broonie, a.zummo,
	paul.gortmaker, sachin.kamat, k.kozlowski, linux-kernel,
	linux-input, linux-leds, linux-pm, rtc-linux, Robert Baldyga

This patch changes naming convention of MUIC interrupts form CamelCase
to upper case. It makes names more readable and consistent with another
interrupt names in max8997 driver.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

[For the mfd part]
Acked-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/extcon/extcon-max8997.c     | 32 ++++++++++++++++----------------
 include/linux/mfd/max8997-private.h | 16 ++++++++--------
 2 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
index 172dbd6..834b72f 100644
--- a/drivers/extcon/extcon-max8997.c
+++ b/drivers/extcon/extcon-max8997.c
@@ -46,15 +46,15 @@ struct max8997_muic_irq {
 };
 
 static struct max8997_muic_irq muic_irqs[] = {
-	{ MAX8997_MUICIRQ_ADCError,	"muic-ADCERROR" },
-	{ MAX8997_MUICIRQ_ADCLow,	"muic-ADCLOW" },
-	{ MAX8997_MUICIRQ_ADC,		"muic-ADC" },
-	{ MAX8997_MUICIRQ_VBVolt,	"muic-VBVOLT" },
-	{ MAX8997_MUICIRQ_DBChg,	"muic-DBCHG" },
-	{ MAX8997_MUICIRQ_DCDTmr,	"muic-DCDTMR" },
-	{ MAX8997_MUICIRQ_ChgDetRun,	"muic-CHGDETRUN" },
-	{ MAX8997_MUICIRQ_ChgTyp,	"muic-CHGTYP" },
-	{ MAX8997_MUICIRQ_OVP,		"muic-OVP" },
+	{ MAX8997_MUICIRQ_ADCERROR,	"MUIC-ADCERROR" },
+	{ MAX8997_MUICIRQ_ADCLOW,	"MUIC-ADCLOW" },
+	{ MAX8997_MUICIRQ_ADC,		"MUIC-ADC" },
+	{ MAX8997_MUICIRQ_VBVOLT,	"MUIC-VBVOLT" },
+	{ MAX8997_MUICIRQ_DBCHG,	"MUIC-DBCHG" },
+	{ MAX8997_MUICIRQ_DCDTMR,	"MUIC-DCDTMR" },
+	{ MAX8997_MUICIRQ_CHGDETRUN,	"MUIC-CHGDETRUN" },
+	{ MAX8997_MUICIRQ_CHGTYP,	"MUIC-CHGTYP" },
+	{ MAX8997_MUICIRQ_OVP,		"MUIC-OVP" },
 };
 
 /* Define supported cable type */
@@ -553,17 +553,17 @@ static void max8997_muic_irq_work(struct work_struct *work)
 	}
 
 	switch (irq_type) {
-	case MAX8997_MUICIRQ_ADCError:
-	case MAX8997_MUICIRQ_ADCLow:
+	case MAX8997_MUICIRQ_ADCERROR:
+	case MAX8997_MUICIRQ_ADCLOW:
 	case MAX8997_MUICIRQ_ADC:
 		/* Handle all of cable except for charger cable */
 		ret = max8997_muic_adc_handler(info);
 		break;
-	case MAX8997_MUICIRQ_VBVolt:
-	case MAX8997_MUICIRQ_DBChg:
-	case MAX8997_MUICIRQ_DCDTmr:
-	case MAX8997_MUICIRQ_ChgDetRun:
-	case MAX8997_MUICIRQ_ChgTyp:
+	case MAX8997_MUICIRQ_VBVOLT:
+	case MAX8997_MUICIRQ_DBCHG:
+	case MAX8997_MUICIRQ_DCDTMR:
+	case MAX8997_MUICIRQ_CHGDETRUN:
+	case MAX8997_MUICIRQ_CHGTYP:
 		/* Handle charger cable */
 		ret = max8997_muic_chg_handler(info);
 		break;
diff --git a/include/linux/mfd/max8997-private.h b/include/linux/mfd/max8997-private.h
index f42ea22..2817fa6 100644
--- a/include/linux/mfd/max8997-private.h
+++ b/include/linux/mfd/max8997-private.h
@@ -411,14 +411,14 @@ enum max8997_irq {
 
 enum max8997_irq_muic {
 	MAX8997_MUICIRQ_ADC,
-	MAX8997_MUICIRQ_ADCLow,
-	MAX8997_MUICIRQ_ADCError,
-
-	MAX8997_MUICIRQ_ChgTyp,
-	MAX8997_MUICIRQ_ChgDetRun,
-	MAX8997_MUICIRQ_DCDTmr,
-	MAX8997_MUICIRQ_DBChg,
-	MAX8997_MUICIRQ_VBVolt,
+	MAX8997_MUICIRQ_ADCLOW,
+	MAX8997_MUICIRQ_ADCERROR,
+
+	MAX8997_MUICIRQ_CHGTYP,
+	MAX8997_MUICIRQ_CHGDETRUN,
+	MAX8997_MUICIRQ_DCDTMR,
+	MAX8997_MUICIRQ_DBCHG,
+	MAX8997_MUICIRQ_VBVOLT,
 
 	MAX8997_MUICIRQ_OVP,
 
-- 
1.9.1


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

* Re: [PATCH v5 1/3] mfd: max8997: use regmap to access registers
  2014-11-12  7:23 ` [PATCH v5 1/3] mfd: max8997: use regmap to access registers Robert Baldyga
@ 2014-11-12 17:01   ` Sebastian Reichel
  2015-01-29 18:01   ` Dmitry Torokhov
  1 sibling, 0 replies; 11+ messages in thread
From: Sebastian Reichel @ 2014-11-12 17:01 UTC (permalink / raw)
  To: Robert Baldyga
  Cc: lee.jones, sameo, myungjoo.ham, cw00.choi, dmitry.torokhov,
	cooloney, rpurdie, dbaryshkov, dwmw2, lgirdwood, broonie,
	a.zummo, paul.gortmaker, sachin.kamat, k.kozlowski, linux-kernel,
	linux-input, linux-leds, linux-pm, rtc-linux

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

Hi,

On Wed, Nov 12, 2014 at 08:23:14AM +0100, Robert Baldyga wrote:
> This patch modifies max8997 driver and each associated function driver,
> to use regmap instead of operating directly on i2c bus. It will allow to
> simplify IRQ handling using regmap-irq.
> 
> Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> 
> [For extcon part]
> Acked-by: Chanwoo Choi <cw00.choi@samsung.com>
> 
> [For leds part]
> Acked-by: Bryan Wu <cooloney@gmail.com>
> 
> [For the mfd part]
> Acked-by: Lee Jones <lee.jones@linaro.org>

[For the power supply part]
Acked-By: Sebastian Reichel <sre@kernel.org>

-- Sebastian

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

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

* Re: [PATCH v5 0/3] mfd: max8997: add regmap support
  2014-11-12  7:23 [PATCH v5 0/3] mfd: max8997: add regmap support Robert Baldyga
                   ` (2 preceding siblings ...)
  2014-11-12  7:23 ` [PATCH v5 3/3] mfd: max8997: change irq names to upper case Robert Baldyga
@ 2015-01-28 14:20 ` Robert Baldyga
  2015-01-29 18:03   ` Dmitry Torokhov
  3 siblings, 1 reply; 11+ messages in thread
From: Robert Baldyga @ 2015-01-28 14:20 UTC (permalink / raw)
  To: lee.jones, dmitry.torokhov, a.zummo
  Cc: sameo, myungjoo.ham, cw00.choi, cooloney, rpurdie, sre,
	dbaryshkov, dwmw2, lgirdwood, broonie, paul.gortmaker,
	sachin.kamat, k.kozlowski, linux-kernel, linux-input, linux-leds,
	linux-pm, rtc-linux

Hi,

The first version of this patchset was send to kernel list almost 9
months ago and still I don't have all needed Acks. The missing ones are
for changes in INPUT and RTC subsystems.

Dmitry, Alessandro, could you please have a look at this patches and
give your Acks?

Best regards,
Robert Baldyga

On 11/12/2014 08:23 AM, Robert Baldyga wrote:
> This patchset modifies max8997 driver and associated function drivers to use
> register maps instead of operating directly on i2c bus. This change allowed
> to simplify irq handling, and to move some initializations to individual
> function drivers. Hence now when some functions are not enabled, their i2c
> clients, regmaps and irqs are not registered.
> 
> Because patches are under review for very long time and I still don't have
> all needed Acks, I'm resending this series rebased to the latest next branch.
> 
> Best regards
> Robert Baldyga
> Samsung R&D Institute Poland
> 
> Changelog:
> 
> v5:
> - rebase patches to last next branch
> 
> v4:
> - remove patch moving regmap handling to function drivers
> 
> v3: https://lkml.org/lkml/2014/3/13/101
> - fix error handling
> - fix deinitializations order
> - move muic irq enum values renaming to separate patch
> 
> v2: https://lkml.org/lkml/2014/3/12/237
> - rebase patches on Lee Jones' MFD tree
> - add missing selects in Kconfig
> - add missing deinitializations
> - add interrupt disabling when suspend
> - few minor changes and typo fixes
> 
> v1: https://lkml.org/lkml/2014/3/11/291
> 
> Robert Baldyga (3):
>   mfd: max8997: use regmap to access registers
>   mfd: max8997: handle IRQs using regmap
>   mfd: max8997: change irq names to upper case
> 
>  drivers/extcon/extcon-max8997.c     |  66 +++---
>  drivers/input/misc/max8997_haptic.c |  34 ++--
>  drivers/leds/leds-max8997.c         |  13 +-
>  drivers/mfd/Kconfig                 |   3 +-
>  drivers/mfd/Makefile                |   2 +-
>  drivers/mfd/max8997-irq.c           | 387 ------------------------------------
>  drivers/mfd/max8997.c               | 245 +++++++++++++++--------
>  drivers/power/max8997_charger.c     |  33 +--
>  drivers/regulator/max8997.c         |  87 ++++----
>  drivers/rtc/rtc-max8997.c           |  58 +++---
>  include/linux/mfd/max8997-private.h |  82 ++++++--
>  11 files changed, 381 insertions(+), 629 deletions(-)
>  delete mode 100644 drivers/mfd/max8997-irq.c
> 


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

* Re: [PATCH v5 1/3] mfd: max8997: use regmap to access registers
  2014-11-12  7:23 ` [PATCH v5 1/3] mfd: max8997: use regmap to access registers Robert Baldyga
  2014-11-12 17:01   ` Sebastian Reichel
@ 2015-01-29 18:01   ` Dmitry Torokhov
  1 sibling, 0 replies; 11+ messages in thread
From: Dmitry Torokhov @ 2015-01-29 18:01 UTC (permalink / raw)
  To: Robert Baldyga
  Cc: lee.jones, sameo, myungjoo.ham, cw00.choi, cooloney, rpurdie,
	sre, dbaryshkov, dwmw2, lgirdwood, broonie, a.zummo,
	paul.gortmaker, sachin.kamat, k.kozlowski, linux-kernel,
	linux-input, linux-leds, linux-pm, rtc-linux

On Wed, Nov 12, 2014 at 08:23:14AM +0100, Robert Baldyga wrote:
> This patch modifies max8997 driver and each associated function driver,
> to use regmap instead of operating directly on i2c bus. It will allow to
> simplify IRQ handling using regmap-irq.
> 
> Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> 
> [For extcon part]
> Acked-by: Chanwoo Choi <cw00.choi@samsung.com>
> 
> [For leds part]
> Acked-by: Bryan Wu <cooloney@gmail.com>
> 
> [For the mfd part]
> Acked-by: Lee Jones <lee.jones@linaro.org>

For input part:

Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


Thanks.

> ---
>  drivers/extcon/extcon-max8997.c     |  31 ++++----
>  drivers/input/misc/max8997_haptic.c |  34 +++++----
>  drivers/leds/leds-max8997.c         |  13 ++--
>  drivers/mfd/Kconfig                 |   1 +
>  drivers/mfd/max8997-irq.c           |  64 +++++++---------
>  drivers/mfd/max8997.c               | 141 ++++++++++++++++--------------------
>  drivers/power/max8997_charger.c     |  33 +++++----
>  drivers/regulator/max8997.c         |  87 +++++++++++-----------
>  drivers/rtc/rtc-max8997.c           |  56 +++++++-------
>  include/linux/mfd/max8997-private.h |  17 ++---
>  10 files changed, 228 insertions(+), 249 deletions(-)
> 
> diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
> index 75e501c..2aafd5b 100644
> --- a/drivers/extcon/extcon-max8997.c
> +++ b/drivers/extcon/extcon-max8997.c
> @@ -27,6 +27,7 @@
>  #include <linux/mfd/max8997-private.h>
>  #include <linux/extcon.h>
>  #include <linux/irqdomain.h>
> +#include <linux/regmap.h>
>  
>  #define	DEV_NAME			"max8997-muic"
>  #define	DELAY_MS_DEFAULT		20000		/* unit: millisecond */
> @@ -116,7 +117,7 @@ enum max8997_muic_charger_type {
>  
>  struct max8997_muic_info {
>  	struct device *dev;
> -	struct i2c_client *muic;
> +	struct max8997_dev *max8997;
>  	struct extcon_dev *edev;
>  	int prev_cable_type;
>  	int prev_chg_type;
> @@ -190,10 +191,10 @@ static int max8997_muic_set_debounce_time(struct max8997_muic_info *info,
>  	case ADC_DEBOUNCE_TIME_10MS:
>  	case ADC_DEBOUNCE_TIME_25MS:
>  	case ADC_DEBOUNCE_TIME_38_62MS:
> -		ret = max8997_update_reg(info->muic,
> +		ret = regmap_update_bits(info->max8997->regmap_muic,
>  					  MAX8997_MUIC_REG_CONTROL3,
> -					  time << CONTROL3_ADCDBSET_SHIFT,
> -					  CONTROL3_ADCDBSET_MASK);
> +					  CONTROL3_ADCDBSET_MASK,
> +					  time << CONTROL3_ADCDBSET_SHIFT);
>  		if (ret) {
>  			dev_err(info->dev, "failed to set ADC debounce time\n");
>  			return ret;
> @@ -228,8 +229,8 @@ static int max8997_muic_set_path(struct max8997_muic_info *info,
>  	else
>  		ctrl1 = CONTROL1_SW_OPEN;
>  
> -	ret = max8997_update_reg(info->muic,
> -			MAX8997_MUIC_REG_CONTROL1, ctrl1, COMP_SW_MASK);
> +	ret = regmap_update_bits(info->max8997->regmap_muic,
> +			MAX8997_MUIC_REG_CONTROL1, COMP_SW_MASK, ctrl1);
>  	if (ret < 0) {
>  		dev_err(info->dev, "failed to update MUIC register\n");
>  		return ret;
> @@ -240,9 +241,9 @@ static int max8997_muic_set_path(struct max8997_muic_info *info,
>  	else
>  		ctrl2 |= CONTROL2_LOWPWR_MASK;	/* LowPwr=1, CPEn=0 */
>  
> -	ret = max8997_update_reg(info->muic,
> -			MAX8997_MUIC_REG_CONTROL2, ctrl2,
> -			CONTROL2_LOWPWR_MASK | CONTROL2_CPEN_MASK);
> +	ret = regmap_update_bits(info->max8997->regmap_muic,
> +			MAX8997_MUIC_REG_CONTROL2,
> +			CONTROL2_LOWPWR_MASK | CONTROL2_CPEN_MASK, ctrl2);
>  	if (ret < 0) {
>  		dev_err(info->dev, "failed to update MUIC register\n");
>  		return ret;
> @@ -543,8 +544,8 @@ static void max8997_muic_irq_work(struct work_struct *work)
>  		if (info->irq == muic_irqs[i].virq)
>  			irq_type = muic_irqs[i].irq;
>  
> -	ret = max8997_bulk_read(info->muic, MAX8997_MUIC_REG_STATUS1,
> -				2, info->status);
> +	ret = regmap_bulk_read(info->max8997->regmap_muic,
> +				MAX8997_MUIC_REG_STATUS1, info->status, 2);
>  	if (ret) {
>  		dev_err(info->dev, "failed to read muic register\n");
>  		mutex_unlock(&info->mutex);
> @@ -605,8 +606,8 @@ static int max8997_muic_detect_dev(struct max8997_muic_info *info)
>  	mutex_lock(&info->mutex);
>  
>  	/* Read STATUSx register to detect accessory */
> -	ret = max8997_bulk_read(info->muic,
> -			MAX8997_MUIC_REG_STATUS1, 2, info->status);
> +	ret = regmap_bulk_read(info->max8997->regmap_muic,
> +			MAX8997_MUIC_REG_STATUS1, info->status, 2);
>  	if (ret) {
>  		dev_err(info->dev, "failed to read MUIC register\n");
>  		mutex_unlock(&info->mutex);
> @@ -665,7 +666,7 @@ static int max8997_muic_probe(struct platform_device *pdev)
>  		return -ENOMEM;
>  
>  	info->dev = &pdev->dev;
> -	info->muic = max8997->muic;
> +	info->max8997 = max8997;
>  
>  	platform_set_drvdata(pdev, info);
>  	mutex_init(&info->mutex);
> @@ -717,7 +718,7 @@ static int max8997_muic_probe(struct platform_device *pdev)
>  
>  		/* Initialize registers according to platform data */
>  		for (i = 0; i < muic_pdata->num_init_data; i++) {
> -			max8997_write_reg(info->muic,
> +			regmap_write(info->max8997->regmap_muic,
>  					muic_pdata->init_data[i].addr,
>  					muic_pdata->init_data[i].data);
>  		}
> diff --git a/drivers/input/misc/max8997_haptic.c b/drivers/input/misc/max8997_haptic.c
> index a363ebb..53b32b5 100644
> --- a/drivers/input/misc/max8997_haptic.c
> +++ b/drivers/input/misc/max8997_haptic.c
> @@ -31,6 +31,7 @@
>  #include <linux/mfd/max8997-private.h>
>  #include <linux/mfd/max8997.h>
>  #include <linux/regulator/consumer.h>
> +#include <linux/regmap.h>
>  
>  /* Haptic configuration 2 register */
>  #define MAX8997_MOTOR_TYPE_SHIFT	7
> @@ -45,7 +46,7 @@
>  
>  struct max8997_haptic {
>  	struct device *dev;
> -	struct i2c_client *client;
> +	struct max8997_dev *max8997;
>  	struct input_dev *input_dev;
>  	struct regulator *regulator;
>  
> @@ -86,19 +87,19 @@ static int max8997_haptic_set_duty_cycle(struct max8997_haptic *chip)
>  		}
>  		switch (chip->internal_mode_pattern) {
>  		case 0:
> -			max8997_write_reg(chip->client,
> +			regmap_write(chip->max8997->regmap_haptic,
>  				MAX8997_HAPTIC_REG_SIGPWMDC1, duty_index);
>  			break;
>  		case 1:
> -			max8997_write_reg(chip->client,
> +			regmap_write(chip->max8997->regmap_haptic,
>  				MAX8997_HAPTIC_REG_SIGPWMDC2, duty_index);
>  			break;
>  		case 2:
> -			max8997_write_reg(chip->client,
> +			regmap_write(chip->max8997->regmap_haptic,
>  				MAX8997_HAPTIC_REG_SIGPWMDC3, duty_index);
>  			break;
>  		case 3:
> -			max8997_write_reg(chip->client,
> +			regmap_write(chip->max8997->regmap_haptic,
>  				MAX8997_HAPTIC_REG_SIGPWMDC4, duty_index);
>  			break;
>  		default:
> @@ -115,50 +116,51 @@ static void max8997_haptic_configure(struct max8997_haptic *chip)
>  	value = chip->type << MAX8997_MOTOR_TYPE_SHIFT |
>  		chip->enabled << MAX8997_ENABLE_SHIFT |
>  		chip->mode << MAX8997_MODE_SHIFT | chip->pwm_divisor;
> -	max8997_write_reg(chip->client, MAX8997_HAPTIC_REG_CONF2, value);
> +	regmap_write(chip->max8997->regmap_haptic,
> +		MAX8997_HAPTIC_REG_CONF2, value);
>  
>  	if (chip->mode == MAX8997_INTERNAL_MODE && chip->enabled) {
>  		value = chip->internal_mode_pattern << MAX8997_CYCLE_SHIFT |
>  			chip->internal_mode_pattern << MAX8997_SIG_PERIOD_SHIFT |
>  			chip->internal_mode_pattern << MAX8997_SIG_DUTY_SHIFT |
>  			chip->internal_mode_pattern << MAX8997_PWM_DUTY_SHIFT;
> -		max8997_write_reg(chip->client,
> +		regmap_write(chip->max8997->regmap_haptic,
>  			MAX8997_HAPTIC_REG_DRVCONF, value);
>  
>  		switch (chip->internal_mode_pattern) {
>  		case 0:
>  			value = chip->pattern_cycle << 4;
> -			max8997_write_reg(chip->client,
> +			regmap_write(chip->max8997->regmap_haptic,
>  				MAX8997_HAPTIC_REG_CYCLECONF1, value);
>  			value = chip->pattern_signal_period;
> -			max8997_write_reg(chip->client,
> +			regmap_write(chip->max8997->regmap_haptic,
>  				MAX8997_HAPTIC_REG_SIGCONF1, value);
>  			break;
>  
>  		case 1:
>  			value = chip->pattern_cycle;
> -			max8997_write_reg(chip->client,
> +			regmap_write(chip->max8997->regmap_haptic,
>  				MAX8997_HAPTIC_REG_CYCLECONF1, value);
>  			value = chip->pattern_signal_period;
> -			max8997_write_reg(chip->client,
> +			regmap_write(chip->max8997->regmap_haptic,
>  				MAX8997_HAPTIC_REG_SIGCONF2, value);
>  			break;
>  
>  		case 2:
>  			value = chip->pattern_cycle << 4;
> -			max8997_write_reg(chip->client,
> +			regmap_write(chip->max8997->regmap_haptic,
>  				MAX8997_HAPTIC_REG_CYCLECONF2, value);
>  			value = chip->pattern_signal_period;
> -			max8997_write_reg(chip->client,
> +			regmap_write(chip->max8997->regmap_haptic,
>  				MAX8997_HAPTIC_REG_SIGCONF3, value);
>  			break;
>  
>  		case 3:
>  			value = chip->pattern_cycle;
> -			max8997_write_reg(chip->client,
> +			regmap_write(chip->max8997->regmap_haptic,
>  				MAX8997_HAPTIC_REG_CYCLECONF2, value);
>  			value = chip->pattern_signal_period;
> -			max8997_write_reg(chip->client,
> +			regmap_write(chip->max8997->regmap_haptic,
>  				MAX8997_HAPTIC_REG_SIGCONF4, value);
>  			break;
>  
> @@ -277,7 +279,7 @@ static int max8997_haptic_probe(struct platform_device *pdev)
>  	INIT_WORK(&chip->work, max8997_haptic_play_effect_work);
>  	mutex_init(&chip->mutex);
>  
> -	chip->client = iodev->haptic;
> +	chip->max8997 = iodev;
>  	chip->dev = &pdev->dev;
>  	chip->input_dev = input_dev;
>  	chip->pwm_period = haptic_pdata->pwm_period;
> diff --git a/drivers/leds/leds-max8997.c b/drivers/leds/leds-max8997.c
> index 607bc27..49bb128 100644
> --- a/drivers/leds/leds-max8997.c
> +++ b/drivers/leds/leds-max8997.c
> @@ -18,6 +18,7 @@
>  #include <linux/mfd/max8997.h>
>  #include <linux/mfd/max8997-private.h>
>  #include <linux/platform_device.h>
> +#include <linux/regmap.h>
>  
>  #define MAX8997_LED_FLASH_SHIFT			3
>  #define MAX8997_LED_FLASH_CUR_MASK		0xf8
> @@ -53,7 +54,6 @@ static void max8997_led_set_mode(struct max8997_led *led,
>  			enum max8997_led_mode mode)
>  {
>  	int ret;
> -	struct i2c_client *client = led->iodev->i2c;
>  	u8 mask = 0, val;
>  
>  	switch (mode) {
> @@ -89,8 +89,8 @@ static void max8997_led_set_mode(struct max8997_led *led,
>  	}
>  
>  	if (mask) {
> -		ret = max8997_update_reg(client, MAX8997_REG_LEN_CNTL, val,
> -					 mask);
> +		ret = regmap_update_bits(led->iodev->regmap,
> +					MAX8997_REG_LEN_CNTL, mask, val);
>  		if (ret)
>  			dev_err(led->iodev->dev,
>  				"failed to update register(%d)\n", ret);
> @@ -102,7 +102,6 @@ static void max8997_led_set_mode(struct max8997_led *led,
>  static void max8997_led_enable(struct max8997_led *led, bool enable)
>  {
>  	int ret;
> -	struct i2c_client *client = led->iodev->i2c;
>  	u8 val = 0, mask = MAX8997_LED_BOOST_ENABLE_MASK;
>  
>  	if (led->enabled == enable)
> @@ -110,7 +109,8 @@ static void max8997_led_enable(struct max8997_led *led, bool enable)
>  
>  	val = enable ? MAX8997_LED_BOOST_ENABLE_MASK : 0;
>  
> -	ret = max8997_update_reg(client, MAX8997_REG_BOOST_CNTL, val, mask);
> +	ret = regmap_update_bits(led->iodev->regmap,
> +				MAX8997_REG_BOOST_CNTL, mask, val);
>  	if (ret)
>  		dev_err(led->iodev->dev,
>  			"failed to update register(%d)\n", ret);
> @@ -122,7 +122,6 @@ static void max8997_led_set_current(struct max8997_led *led,
>  				enum led_brightness value)
>  {
>  	int ret;
> -	struct i2c_client *client = led->iodev->i2c;
>  	u8 val = 0, mask = 0, reg = 0;
>  
>  	switch (led->led_mode) {
> @@ -143,7 +142,7 @@ static void max8997_led_set_current(struct max8997_led *led,
>  	}
>  
>  	if (mask) {
> -		ret = max8997_update_reg(client, reg, val, mask);
> +		ret = regmap_update_bits(led->iodev->regmap, reg, mask, val);
>  		if (ret)
>  			dev_err(led->iodev->dev,
>  				"failed to update register(%d)\n", ret);
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index 72d3808..ca57035 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -463,6 +463,7 @@ config MFD_MAX8997
>  	bool "Maxim Semiconductor MAX8997/8966 PMIC Support"
>  	depends on I2C=y
>  	select MFD_CORE
> +	select REGMAP_I2C
>  	select IRQ_DOMAIN
>  	help
>  	  Say yes here to add support for Maxim Semiconductor MAX8997/8966.
> diff --git a/drivers/mfd/max8997-irq.c b/drivers/mfd/max8997-irq.c
> index 43fa614..0e7ff39 100644
> --- a/drivers/mfd/max8997-irq.c
> +++ b/drivers/mfd/max8997-irq.c
> @@ -26,6 +26,7 @@
>  #include <linux/interrupt.h>
>  #include <linux/mfd/max8997.h>
>  #include <linux/mfd/max8997-private.h>
> +#include <linux/regmap.h>
>  
>  static const u8 max8997_mask_reg[] = {
>  	[PMIC_INT1] = MAX8997_REG_INT1MSK,
> @@ -41,25 +42,6 @@ static const u8 max8997_mask_reg[] = {
>  	[FLASH_STATUS] = MAX8997_REG_INVALID,
>  };
>  
> -static struct i2c_client *get_i2c(struct max8997_dev *max8997,
> -				enum max8997_irq_source src)
> -{
> -	switch (src) {
> -	case PMIC_INT1 ... PMIC_INT4:
> -		return max8997->i2c;
> -	case FUEL_GAUGE:
> -		return NULL;
> -	case MUIC_INT1 ... MUIC_INT3:
> -		return max8997->muic;
> -	case GPIO_LOW ... GPIO_HI:
> -		return max8997->i2c;
> -	case FLASH_STATUS:
> -		return max8997->i2c;
> -	default:
> -		return ERR_PTR(-EINVAL);
> -	}
> -}
> -
>  struct max8997_irq_data {
>  	int mask;
>  	enum max8997_irq_source group;
> @@ -124,15 +106,20 @@ static void max8997_irq_sync_unlock(struct irq_data *data)
>  	int i;
>  
>  	for (i = 0; i < MAX8997_IRQ_GROUP_NR; i++) {
> +		struct regmap *map;
>  		u8 mask_reg = max8997_mask_reg[i];
> -		struct i2c_client *i2c = get_i2c(max8997, i);
> +
> +		if (i >= MUIC_INT1 && i <= MUIC_INT3)
> +			map = max8997->regmap_muic;
> +		else
> +			map = max8997->regmap;
>  
>  		if (mask_reg == MAX8997_REG_INVALID ||
> -				IS_ERR_OR_NULL(i2c))
> +				IS_ERR_OR_NULL(map))
>  			continue;
>  		max8997->irq_masks_cache[i] = max8997->irq_masks_cur[i];
>  
> -		max8997_write_reg(i2c, max8997_mask_reg[i],
> +		regmap_write(map, max8997_mask_reg[i],
>  				max8997->irq_masks_cur[i]);
>  	}
>  
> @@ -181,11 +168,11 @@ static irqreturn_t max8997_irq_thread(int irq, void *data)
>  {
>  	struct max8997_dev *max8997 = data;
>  	u8 irq_reg[MAX8997_IRQ_GROUP_NR] = {};
> -	u8 irq_src;
> +	unsigned int irq_src;
>  	int ret;
>  	int i, cur_irq;
>  
> -	ret = max8997_read_reg(max8997->i2c, MAX8997_REG_INTSRC, &irq_src);
> +	ret = regmap_read(max8997->regmap, MAX8997_REG_INTSRC, &irq_src);
>  	if (ret < 0) {
>  		dev_err(max8997->dev, "Failed to read interrupt source: %d\n",
>  				ret);
> @@ -194,8 +181,8 @@ static irqreturn_t max8997_irq_thread(int irq, void *data)
>  
>  	if (irq_src & MAX8997_IRQSRC_PMIC) {
>  		/* PMIC INT1 ~ INT4 */
> -		max8997_bulk_read(max8997->i2c, MAX8997_REG_INT1, 4,
> -				&irq_reg[PMIC_INT1]);
> +		regmap_bulk_read(max8997->regmap, MAX8997_REG_INT1,
> +				&irq_reg[PMIC_INT1], 4);
>  	}
>  	if (irq_src & MAX8997_IRQSRC_FUELGAUGE) {
>  		/*
> @@ -215,8 +202,8 @@ static irqreturn_t max8997_irq_thread(int irq, void *data)
>  	}
>  	if (irq_src & MAX8997_IRQSRC_MUIC) {
>  		/* MUIC INT1 ~ INT3 */
> -		max8997_bulk_read(max8997->muic, MAX8997_MUIC_REG_INT1, 3,
> -				&irq_reg[MUIC_INT1]);
> +		regmap_bulk_read(max8997->regmap_muic, MAX8997_MUIC_REG_INT1,
> +				&irq_reg[MUIC_INT1], 3);
>  	}
>  	if (irq_src & MAX8997_IRQSRC_GPIO) {
>  		/* GPIO Interrupt */
> @@ -225,8 +212,8 @@ static irqreturn_t max8997_irq_thread(int irq, void *data)
>  		irq_reg[GPIO_LOW] = 0;
>  		irq_reg[GPIO_HI] = 0;
>  
> -		max8997_bulk_read(max8997->i2c, MAX8997_REG_GPIOCNTL1,
> -				MAX8997_NUM_GPIO, gpio_info);
> +		regmap_bulk_read(max8997->regmap, MAX8997_REG_GPIOCNTL1,
> +				gpio_info, MAX8997_NUM_GPIO);
>  		for (i = 0; i < MAX8997_NUM_GPIO; i++) {
>  			bool interrupt = false;
>  
> @@ -260,8 +247,10 @@ static irqreturn_t max8997_irq_thread(int irq, void *data)
>  	}
>  	if (irq_src & MAX8997_IRQSRC_FLASH) {
>  		/* Flash Status Interrupt */
> -		ret = max8997_read_reg(max8997->i2c, MAX8997_REG_FLASHSTATUS,
> -				&irq_reg[FLASH_STATUS]);
> +		unsigned int data;
> +		ret = regmap_read(max8997->regmap,
> +				MAX8997_REG_FLASHSTATUS, &data);
> +		irq_reg[FLASH_STATUS] = data;
>  	}
>  
>  	/* Apply masking */
> @@ -312,7 +301,7 @@ int max8997_irq_init(struct max8997_dev *max8997)
>  	struct irq_domain *domain;
>  	int i;
>  	int ret;
> -	u8 val;
> +	unsigned int val;
>  
>  	if (!max8997->irq) {
>  		dev_warn(max8997->dev, "No interrupt specified.\n");
> @@ -323,22 +312,19 @@ int max8997_irq_init(struct max8997_dev *max8997)
>  
>  	/* Mask individual interrupt sources */
>  	for (i = 0; i < MAX8997_IRQ_GROUP_NR; i++) {
> -		struct i2c_client *i2c;
> -
>  		max8997->irq_masks_cur[i] = 0xff;
>  		max8997->irq_masks_cache[i] = 0xff;
> -		i2c = get_i2c(max8997, i);
>  
> -		if (IS_ERR_OR_NULL(i2c))
> +		if (IS_ERR_OR_NULL(max8997->regmap))
>  			continue;
>  		if (max8997_mask_reg[i] == MAX8997_REG_INVALID)
>  			continue;
>  
> -		max8997_write_reg(i2c, max8997_mask_reg[i], 0xff);
> +		regmap_write(max8997->regmap, max8997_mask_reg[i], 0xff);
>  	}
>  
>  	for (i = 0; i < MAX8997_NUM_GPIO; i++) {
> -		max8997->gpio_status[i] = (max8997_read_reg(max8997->i2c,
> +		max8997->gpio_status[i] = (regmap_read(max8997->regmap,
>  						MAX8997_REG_GPIOCNTL1 + i,
>  						&val)
>  					& MAX8997_GPIO_DATA_MASK) ?
> diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c
> index 595364e..c4a1072 100644
> --- a/drivers/mfd/max8997.c
> +++ b/drivers/mfd/max8997.c
> @@ -33,6 +33,7 @@
>  #include <linux/mfd/core.h>
>  #include <linux/mfd/max8997.h>
>  #include <linux/mfd/max8997-private.h>
> +#include <linux/regmap.h>
>  
>  #define I2C_ADDR_PMIC	(0xCC >> 1)
>  #define I2C_ADDR_MUIC	(0x4A >> 1)
> @@ -57,81 +58,29 @@ static const struct of_device_id max8997_pmic_dt_match[] = {
>  };
>  #endif
>  
> -int max8997_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest)
> -{
> -	struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
> -	int ret;
> -
> -	mutex_lock(&max8997->iolock);
> -	ret = i2c_smbus_read_byte_data(i2c, reg);
> -	mutex_unlock(&max8997->iolock);
> -	if (ret < 0)
> -		return ret;
> -
> -	ret &= 0xff;
> -	*dest = ret;
> -	return 0;
> -}
> -EXPORT_SYMBOL_GPL(max8997_read_reg);
> -
> -int max8997_bulk_read(struct i2c_client *i2c, u8 reg, int count, u8 *buf)
> -{
> -	struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
> -	int ret;
> -
> -	mutex_lock(&max8997->iolock);
> -	ret = i2c_smbus_read_i2c_block_data(i2c, reg, count, buf);
> -	mutex_unlock(&max8997->iolock);
> -	if (ret < 0)
> -		return ret;
> -
> -	return 0;
> -}
> -EXPORT_SYMBOL_GPL(max8997_bulk_read);
> -
> -int max8997_write_reg(struct i2c_client *i2c, u8 reg, u8 value)
> -{
> -	struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
> -	int ret;
> -
> -	mutex_lock(&max8997->iolock);
> -	ret = i2c_smbus_write_byte_data(i2c, reg, value);
> -	mutex_unlock(&max8997->iolock);
> -	return ret;
> -}
> -EXPORT_SYMBOL_GPL(max8997_write_reg);
> -
> -int max8997_bulk_write(struct i2c_client *i2c, u8 reg, int count, u8 *buf)
> -{
> -	struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
> -	int ret;
> +static const struct regmap_config max8997_regmap_config = {
> +	.reg_bits = 8,
> +	.val_bits = 8,
> +	.max_register = MAX8997_REG_PMIC_END,
> +};
>  
> -	mutex_lock(&max8997->iolock);
> -	ret = i2c_smbus_write_i2c_block_data(i2c, reg, count, buf);
> -	mutex_unlock(&max8997->iolock);
> -	if (ret < 0)
> -		return ret;
> +static const struct regmap_config max8997_regmap_rtc_config = {
> +	.reg_bits = 8,
> +	.val_bits = 8,
> +	.max_register = MAX8997_RTC_REG_END,
> +};
>  
> -	return 0;
> -}
> -EXPORT_SYMBOL_GPL(max8997_bulk_write);
> +static const struct regmap_config max8997_regmap_haptic_config = {
> +	.reg_bits = 8,
> +	.val_bits = 8,
> +	.max_register = MAX8997_HAPTIC_REG_END,
> +};
>  
> -int max8997_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask)
> -{
> -	struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
> -	int ret;
> -
> -	mutex_lock(&max8997->iolock);
> -	ret = i2c_smbus_read_byte_data(i2c, reg);
> -	if (ret >= 0) {
> -		u8 old_val = ret & 0xff;
> -		u8 new_val = (val & mask) | (old_val & (~mask));
> -		ret = i2c_smbus_write_byte_data(i2c, reg, new_val);
> -	}
> -	mutex_unlock(&max8997->iolock);
> -	return ret;
> -}
> -EXPORT_SYMBOL_GPL(max8997_update_reg);
> +static const struct regmap_config max8997_regmap_muic_config = {
> +	.reg_bits = 8,
> +	.val_bits = 8,
> +	.max_register = MAX8997_MUIC_REG_END,
> +};
>  
>  /*
>   * Only the common platform data elements for max8997 are parsed here from the
> @@ -230,6 +179,41 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
>  	}
>  	i2c_set_clientdata(max8997->muic, max8997);
>  
> +	max8997->regmap = devm_regmap_init_i2c(i2c, &max8997_regmap_config);
> +	if (IS_ERR(max8997->regmap)) {
> +		ret = PTR_ERR(max8997->regmap);
> +		dev_err(max8997->dev,
> +				"failed to allocate register map: %d\n", ret);
> +		return ret;
> +	}
> +
> +	max8997->regmap_rtc = devm_regmap_init_i2c(max8997->rtc,
> +					&max8997_regmap_rtc_config);
> +	if (IS_ERR(max8997->regmap_rtc)) {
> +		ret = PTR_ERR(max8997->regmap_rtc);
> +		dev_err(max8997->dev,
> +				"failed to allocate register map: %d\n", ret);
> +		goto err_regmap;
> +	}
> +
> +	max8997->regmap_haptic = devm_regmap_init_i2c(max8997->haptic,
> +					&max8997_regmap_haptic_config);
> +	if (IS_ERR(max8997->regmap_haptic)) {
> +		ret = PTR_ERR(max8997->regmap_haptic);
> +		dev_err(max8997->dev,
> +				"failed to allocate register map: %d\n", ret);
> +		goto err_regmap;
> +	}
> +
> +	max8997->regmap_muic = devm_regmap_init_i2c(max8997->muic,
> +					&max8997_regmap_muic_config);
> +	if (IS_ERR(max8997->regmap_muic)) {
> +		ret = PTR_ERR(max8997->regmap_muic);
> +		dev_err(max8997->dev,
> +				"failed to allocate register map: %d\n", ret);
> +		goto err_regmap;
> +	}
> +
>  	pm_runtime_set_active(max8997->dev);
>  
>  	max8997_irq_init(max8997);
> @@ -254,6 +238,7 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
>  
>  err_mfd:
>  	mfd_remove_devices(max8997->dev);
> +err_regmap:
>  	i2c_unregister_device(max8997->muic);
>  err_i2c_muic:
>  	i2c_unregister_device(max8997->haptic);
> @@ -441,15 +426,15 @@ static int max8997_freeze(struct device *dev)
>  	int i;
>  
>  	for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_pmic); i++)
> -		max8997_read_reg(i2c, max8997_dumpaddr_pmic[i],
> +		regmap_read(max8997->regmap, max8997_dumpaddr_pmic[i],
>  				&max8997->reg_dump[i]);
>  
>  	for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_muic); i++)
> -		max8997_read_reg(i2c, max8997_dumpaddr_muic[i],
> +		regmap_read(max8997->regmap_muic, max8997_dumpaddr_muic[i],
>  				&max8997->reg_dump[i + MAX8997_REG_PMIC_END]);
>  
>  	for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_haptic); i++)
> -		max8997_read_reg(i2c, max8997_dumpaddr_haptic[i],
> +		regmap_read(max8997->regmap_haptic, max8997_dumpaddr_haptic[i],
>  				&max8997->reg_dump[i + MAX8997_REG_PMIC_END +
>  				MAX8997_MUIC_REG_END]);
>  
> @@ -463,15 +448,15 @@ static int max8997_restore(struct device *dev)
>  	int i;
>  
>  	for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_pmic); i++)
> -		max8997_write_reg(i2c, max8997_dumpaddr_pmic[i],
> +		regmap_write(max8997->regmap, max8997_dumpaddr_pmic[i],
>  				max8997->reg_dump[i]);
>  
>  	for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_muic); i++)
> -		max8997_write_reg(i2c, max8997_dumpaddr_muic[i],
> +		regmap_write(max8997->regmap_muic, max8997_dumpaddr_muic[i],
>  				max8997->reg_dump[i + MAX8997_REG_PMIC_END]);
>  
>  	for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_haptic); i++)
> -		max8997_write_reg(i2c, max8997_dumpaddr_haptic[i],
> +		regmap_write(max8997->regmap_haptic, max8997_dumpaddr_haptic[i],
>  				max8997->reg_dump[i + MAX8997_REG_PMIC_END +
>  				MAX8997_MUIC_REG_END]);
>  
> diff --git a/drivers/power/max8997_charger.c b/drivers/power/max8997_charger.c
> index 4bdedfe..43d8481 100644
> --- a/drivers/power/max8997_charger.c
> +++ b/drivers/power/max8997_charger.c
> @@ -26,6 +26,7 @@
>  #include <linux/power_supply.h>
>  #include <linux/mfd/max8997.h>
>  #include <linux/mfd/max8997-private.h>
> +#include <linux/regmap.h>
>  
>  struct charger_data {
>  	struct device *dev;
> @@ -46,14 +47,14 @@ static int max8997_battery_get_property(struct power_supply *psy,
>  {
>  	struct charger_data *charger = container_of(psy,
>  			struct charger_data, battery);
> -	struct i2c_client *i2c = charger->iodev->i2c;
>  	int ret;
> -	u8 reg;
> +	unsigned int reg;
>  
>  	switch (psp) {
>  	case POWER_SUPPLY_PROP_STATUS:
>  		val->intval = 0;
> -		ret = max8997_read_reg(i2c, MAX8997_REG_STATUS4, &reg);
> +		ret = regmap_read(charger->iodev->regmap,
> +				MAX8997_REG_STATUS4, &reg);
>  		if (ret)
>  			return ret;
>  		if ((reg & (1 << 0)) == 0x1)
> @@ -62,7 +63,8 @@ static int max8997_battery_get_property(struct power_supply *psy,
>  		break;
>  	case POWER_SUPPLY_PROP_PRESENT:
>  		val->intval = 0;
> -		ret = max8997_read_reg(i2c, MAX8997_REG_STATUS4, &reg);
> +		ret = regmap_read(charger->iodev->regmap,
> +				MAX8997_REG_STATUS4, &reg);
>  		if (ret)
>  			return ret;
>  		if ((reg & (1 << 2)) == 0x0)
> @@ -71,7 +73,8 @@ static int max8997_battery_get_property(struct power_supply *psy,
>  		break;
>  	case POWER_SUPPLY_PROP_ONLINE:
>  		val->intval = 0;
> -		ret = max8997_read_reg(i2c, MAX8997_REG_STATUS4, &reg);
> +		ret = regmap_read(charger->iodev->regmap,
> +				MAX8997_REG_STATUS4, &reg);
>  		if (ret)
>  			return ret;
>  		/* DCINOK */
> @@ -103,8 +106,8 @@ static int max8997_battery_probe(struct platform_device *pdev)
>  		if (val > 0xf)
>  			val = 0xf;
>  
> -		ret = max8997_update_reg(iodev->i2c,
> -				MAX8997_REG_MBCCTRL5, val, 0xf);
> +		ret = regmap_update_bits(iodev->regmap,
> +				MAX8997_REG_MBCCTRL5, 0xf, val);
>  		if (ret < 0) {
>  			dev_err(&pdev->dev, "Cannot use i2c bus.\n");
>  			return ret;
> @@ -113,20 +116,20 @@ static int max8997_battery_probe(struct platform_device *pdev)
>  
>  	switch (pdata->timeout) {
>  	case 5:
> -		ret = max8997_update_reg(iodev->i2c, MAX8997_REG_MBCCTRL1,
> -				0x2 << 4, 0x7 << 4);
> +		ret = regmap_update_bits(iodev->regmap,
> +				MAX8997_REG_MBCCTRL1, 0x7 << 4, 0x2 << 4);
>  		break;
>  	case 6:
> -		ret = max8997_update_reg(iodev->i2c, MAX8997_REG_MBCCTRL1,
> -				0x3 << 4, 0x7 << 4);
> +		ret = regmap_update_bits(iodev->regmap,
> +				MAX8997_REG_MBCCTRL1, 0x7 << 4, 0x3 << 4);
>  		break;
>  	case 7:
> -		ret = max8997_update_reg(iodev->i2c, MAX8997_REG_MBCCTRL1,
> -				0x4 << 4, 0x7 << 4);
> +		ret = regmap_update_bits(iodev->regmap,
> +				MAX8997_REG_MBCCTRL1, 0x7 << 4, 0x4 << 4);
>  		break;
>  	case 0:
> -		ret = max8997_update_reg(iodev->i2c, MAX8997_REG_MBCCTRL1,
> -				0x7 << 4, 0x7 << 4);
> +		ret = regmap_update_bits(iodev->regmap,
> +				MAX8997_REG_MBCCTRL1, 0x7 << 4, 0x7 << 4);
>  		break;
>  	default:
>  		dev_err(&pdev->dev, "incorrect timeout value (%d)\n",
> diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c
> index 9c31e21..faefd1c 100644
> --- a/drivers/regulator/max8997.c
> +++ b/drivers/regulator/max8997.c
> @@ -33,6 +33,7 @@
>  #include <linux/mfd/max8997.h>
>  #include <linux/mfd/max8997-private.h>
>  #include <linux/regulator/of_regulator.h>
> +#include <linux/regmap.h>
>  
>  struct max8997_data {
>  	struct device *dev;
> @@ -50,7 +51,7 @@ struct max8997_data {
>  	int buck125_gpioindex;
>  	bool ignore_gpiodvs_side_effect;
>  
> -	u8 saved_states[MAX8997_REG_MAX];
> +	unsigned int saved_states[MAX8997_REG_MAX];
>  };
>  
>  static const unsigned int safeoutvolt[] = {
> @@ -257,15 +258,14 @@ static int max8997_get_enable_register(struct regulator_dev *rdev,
>  static int max8997_reg_is_enabled(struct regulator_dev *rdev)
>  {
>  	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
> -	struct i2c_client *i2c = max8997->iodev->i2c;
>  	int ret, reg, mask, pattern;
> -	u8 val;
> +	unsigned int val;
>  
>  	ret = max8997_get_enable_register(rdev, &reg, &mask, &pattern);
>  	if (ret)
>  		return ret;
>  
> -	ret = max8997_read_reg(i2c, reg, &val);
> +	ret = regmap_read(max8997->iodev->regmap, reg, &val);
>  	if (ret)
>  		return ret;
>  
> @@ -275,27 +275,25 @@ static int max8997_reg_is_enabled(struct regulator_dev *rdev)
>  static int max8997_reg_enable(struct regulator_dev *rdev)
>  {
>  	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
> -	struct i2c_client *i2c = max8997->iodev->i2c;
>  	int ret, reg, mask, pattern;
>  
>  	ret = max8997_get_enable_register(rdev, &reg, &mask, &pattern);
>  	if (ret)
>  		return ret;
>  
> -	return max8997_update_reg(i2c, reg, pattern, mask);
> +	return regmap_update_bits(max8997->iodev->regmap, reg, mask, pattern);
>  }
>  
>  static int max8997_reg_disable(struct regulator_dev *rdev)
>  {
>  	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
> -	struct i2c_client *i2c = max8997->iodev->i2c;
>  	int ret, reg, mask, pattern;
>  
>  	ret = max8997_get_enable_register(rdev, &reg, &mask, &pattern);
>  	if (ret)
>  		return ret;
>  
> -	return max8997_update_reg(i2c, reg, ~pattern, mask);
> +	return regmap_update_bits(max8997->iodev->regmap, reg, mask, ~pattern);
>  }
>  
>  static int max8997_get_voltage_register(struct regulator_dev *rdev,
> @@ -367,15 +365,14 @@ static int max8997_get_voltage_register(struct regulator_dev *rdev,
>  static int max8997_get_voltage_sel(struct regulator_dev *rdev)
>  {
>  	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
> -	struct i2c_client *i2c = max8997->iodev->i2c;
>  	int reg, shift, mask, ret;
> -	u8 val;
> +	unsigned int val;
>  
>  	ret = max8997_get_voltage_register(rdev, &reg, &shift, &mask);
>  	if (ret)
>  		return ret;
>  
> -	ret = max8997_read_reg(i2c, reg, &val);
> +	ret = regmap_read(max8997->iodev->regmap, reg, &val);
>  	if (ret)
>  		return ret;
>  
> @@ -412,7 +409,6 @@ static int max8997_set_voltage_charger_cv(struct regulator_dev *rdev,
>  		int min_uV, int max_uV, unsigned *selector)
>  {
>  	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
> -	struct i2c_client *i2c = max8997->iodev->i2c;
>  	int rid = rdev_get_id(rdev);
>  	int lb, ub;
>  	int reg, shift = 0, mask, ret = 0;
> @@ -454,7 +450,8 @@ static int max8997_set_voltage_charger_cv(struct regulator_dev *rdev,
>  
>  	*selector = val;
>  
> -	ret = max8997_update_reg(i2c, reg, val << shift, mask);
> +	ret = regmap_update_bits(max8997->iodev->regmap,
> +				reg, mask, val << shift);
>  
>  	return ret;
>  }
> @@ -467,7 +464,6 @@ static int max8997_set_voltage_ldobuck(struct regulator_dev *rdev,
>  		int min_uV, int max_uV, unsigned *selector)
>  {
>  	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
> -	struct i2c_client *i2c = max8997->iodev->i2c;
>  	const struct voltage_map_desc *desc;
>  	int rid = rdev_get_id(rdev);
>  	int i, reg, shift, mask, ret;
> @@ -499,7 +495,8 @@ static int max8997_set_voltage_ldobuck(struct regulator_dev *rdev,
>  	if (ret)
>  		return ret;
>  
> -	ret = max8997_update_reg(i2c, reg, i << shift, mask << shift);
> +	ret = regmap_update_bits(max8997->iodev->regmap,
> +				reg, mask << shift, i << shift);
>  	*selector = i;
>  
>  	return ret;
> @@ -709,7 +706,6 @@ static int max8997_set_voltage_safeout_sel(struct regulator_dev *rdev,
>  					   unsigned selector)
>  {
>  	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
> -	struct i2c_client *i2c = max8997->iodev->i2c;
>  	int rid = rdev_get_id(rdev);
>  	int reg, shift = 0, mask, ret;
>  
> @@ -720,13 +716,13 @@ static int max8997_set_voltage_safeout_sel(struct regulator_dev *rdev,
>  	if (ret)
>  		return ret;
>  
> -	return max8997_update_reg(i2c, reg, selector << shift, mask << shift);
> +	return regmap_update_bits(max8997->iodev->regmap,
> +				reg, mask << shift, selector << shift);
>  }
>  
>  static int max8997_reg_disable_suspend(struct regulator_dev *rdev)
>  {
>  	struct max8997_data *max8997 = rdev_get_drvdata(rdev);
> -	struct i2c_client *i2c = max8997->iodev->i2c;
>  	int ret, reg, mask, pattern;
>  	int rid = rdev_get_id(rdev);
>  
> @@ -734,20 +730,22 @@ static int max8997_reg_disable_suspend(struct regulator_dev *rdev)
>  	if (ret)
>  		return ret;
>  
> -	max8997_read_reg(i2c, reg, &max8997->saved_states[rid]);
> +	regmap_read(max8997->iodev->regmap,
> +			reg, &max8997->saved_states[rid]);
>  
>  	if (rid == MAX8997_LDO1 ||
>  			rid == MAX8997_LDO10 ||
>  			rid == MAX8997_LDO21) {
>  		dev_dbg(&rdev->dev, "Conditional Power-Off for %s\n",
>  				rdev->desc->name);
> -		return max8997_update_reg(i2c, reg, 0x40, mask);
> +		return regmap_update_bits(max8997->iodev->regmap,
> +				reg, mask, 0x40);
>  	}
>  
>  	dev_dbg(&rdev->dev, "Full Power-Off for %s (%xh -> %xh)\n",
>  			rdev->desc->name, max8997->saved_states[rid] & mask,
>  			(~pattern) & mask);
> -	return max8997_update_reg(i2c, reg, ~pattern, mask);
> +	return regmap_update_bits(max8997->iodev->regmap, reg, mask, ~pattern);
>  }
>  
>  static struct regulator_ops max8997_ldo_ops = {
> @@ -1030,7 +1028,6 @@ static int max8997_pmic_probe(struct platform_device *pdev)
>  	struct regulator_config config = { };
>  	struct regulator_dev *rdev;
>  	struct max8997_data *max8997;
> -	struct i2c_client *i2c;
>  	int i, ret, nr_dvs;
>  	u8 max_buck1 = 0, max_buck2 = 0, max_buck5 = 0;
>  
> @@ -1054,7 +1051,6 @@ static int max8997_pmic_probe(struct platform_device *pdev)
>  	max8997->iodev = iodev;
>  	max8997->num_regulators = pdata->num_regulators;
>  	platform_set_drvdata(pdev, max8997);
> -	i2c = max8997->iodev->i2c;
>  
>  	max8997->buck125_gpioindex = pdata->buck125_default_idx;
>  	max8997->buck1_gpiodvs = pdata->buck1_gpiodvs;
> @@ -1104,25 +1100,25 @@ static int max8997_pmic_probe(struct platform_device *pdev)
>  
>  	/* For the safety, set max voltage before setting up */
>  	for (i = 0; i < 8; i++) {
> -		max8997_update_reg(i2c, MAX8997_REG_BUCK1DVS1 + i,
> -				max_buck1, 0x3f);
> -		max8997_update_reg(i2c, MAX8997_REG_BUCK2DVS1 + i,
> -				max_buck2, 0x3f);
> -		max8997_update_reg(i2c, MAX8997_REG_BUCK5DVS1 + i,
> -				max_buck5, 0x3f);
> +		regmap_update_bits(max8997->iodev->regmap,
> +				MAX8997_REG_BUCK1DVS1 + i, 0x3f, max_buck1);
> +		regmap_update_bits(max8997->iodev->regmap,
> +				MAX8997_REG_BUCK2DVS1 + i, 0x3f, max_buck2);
> +		regmap_update_bits(max8997->iodev->regmap,
> +				MAX8997_REG_BUCK5DVS1 + i, 0x3f, max_buck5);
>  	}
>  
>  	/* Initialize all the DVS related BUCK registers */
>  	for (i = 0; i < nr_dvs; i++) {
> -		max8997_update_reg(i2c, MAX8997_REG_BUCK1DVS1 + i,
> -				max8997->buck1_vol[i],
> -				0x3f);
> -		max8997_update_reg(i2c, MAX8997_REG_BUCK2DVS1 + i,
> -				max8997->buck2_vol[i],
> -				0x3f);
> -		max8997_update_reg(i2c, MAX8997_REG_BUCK5DVS1 + i,
> -				max8997->buck5_vol[i],
> -				0x3f);
> +		regmap_update_bits(max8997->iodev->regmap,
> +				MAX8997_REG_BUCK1DVS1 + i,
> +				0x3f, max8997->buck1_vol[i]);
> +		regmap_update_bits(max8997->iodev->regmap,
> +				MAX8997_REG_BUCK2DVS1 + i,
> +				0x3f, max8997->buck2_vol[i]);
> +		regmap_update_bits(max8997->iodev->regmap,
> +				MAX8997_REG_BUCK5DVS1 + i,
> +				0x3f, max8997->buck5_vol[i]);
>  	}
>  
>  	/*
> @@ -1166,16 +1162,17 @@ static int max8997_pmic_probe(struct platform_device *pdev)
>  	}
>  
>  	/* DVS-GPIO disabled */
> -	max8997_update_reg(i2c, MAX8997_REG_BUCK1CTRL, (pdata->buck1_gpiodvs) ?
> -			(1 << 1) : (0 << 1), 1 << 1);
> -	max8997_update_reg(i2c, MAX8997_REG_BUCK2CTRL, (pdata->buck2_gpiodvs) ?
> -			(1 << 1) : (0 << 1), 1 << 1);
> -	max8997_update_reg(i2c, MAX8997_REG_BUCK5CTRL, (pdata->buck5_gpiodvs) ?
> -			(1 << 1) : (0 << 1), 1 << 1);
> +	regmap_update_bits(max8997->iodev->regmap, MAX8997_REG_BUCK1CTRL,
> +			1 << 1, (pdata->buck1_gpiodvs) ? (1 << 1) : (0 << 1));
> +	regmap_update_bits(max8997->iodev->regmap, MAX8997_REG_BUCK2CTRL,
> +			1 << 1, (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1));
> +	regmap_update_bits(max8997->iodev->regmap, MAX8997_REG_BUCK5CTRL,
> +			1 << 1, (pdata->buck5_gpiodvs) ? (1 << 1) : (0 << 1));
>  
>  	/* Misc Settings */
>  	max8997->ramp_delay = 10; /* set 10mV/us, which is the default */
> -	max8997_write_reg(i2c, MAX8997_REG_BUCKRAMP, (0xf << 4) | 0x9);
> +	regmap_write(max8997->iodev->regmap,
> +			MAX8997_REG_BUCKRAMP, (0xf << 4) | 0x9);
>  
>  	for (i = 0; i < pdata->num_regulators; i++) {
>  		const struct voltage_map_desc *desc;
> diff --git a/drivers/rtc/rtc-max8997.c b/drivers/rtc/rtc-max8997.c
> index 0777c01..b866f7d5 100644
> --- a/drivers/rtc/rtc-max8997.c
> +++ b/drivers/rtc/rtc-max8997.c
> @@ -20,6 +20,7 @@
>  #include <linux/platform_device.h>
>  #include <linux/mfd/max8997-private.h>
>  #include <linux/irqdomain.h>
> +#include <linux/regmap.h>
>  
>  /* Module parameter for WTSR function control */
>  static int wtsr_en = 1;
> @@ -68,7 +69,6 @@ enum {
>  struct max8997_rtc_info {
>  	struct device		*dev;
>  	struct max8997_dev	*max8997;
> -	struct i2c_client	*rtc;
>  	struct rtc_device	*rtc_dev;
>  	struct mutex		lock;
>  	int virq;
> @@ -118,8 +118,8 @@ static inline int max8997_rtc_set_update_reg(struct max8997_rtc_info *info)
>  {
>  	int ret;
>  
> -	ret = max8997_write_reg(info->rtc, MAX8997_RTC_UPDATE1,
> -						RTC_UDR_MASK);
> +	ret = regmap_write(info->max8997->regmap_rtc,
> +				MAX8997_RTC_UPDATE1, RTC_UDR_MASK);
>  	if (ret < 0)
>  		dev_err(info->dev, "%s: fail to write update reg(%d)\n",
>  				__func__, ret);
> @@ -140,7 +140,8 @@ static int max8997_rtc_read_time(struct device *dev, struct rtc_time *tm)
>  	int ret;
>  
>  	mutex_lock(&info->lock);
> -	ret = max8997_bulk_read(info->rtc, MAX8997_RTC_SEC, RTC_NR_TIME, data);
> +	ret = regmap_bulk_read(info->max8997->regmap_rtc,
> +				MAX8997_RTC_SEC, data, RTC_NR_TIME);
>  	mutex_unlock(&info->lock);
>  
>  	if (ret < 0) {
> @@ -166,7 +167,8 @@ static int max8997_rtc_set_time(struct device *dev, struct rtc_time *tm)
>  
>  	mutex_lock(&info->lock);
>  
> -	ret = max8997_bulk_write(info->rtc, MAX8997_RTC_SEC, RTC_NR_TIME, data);
> +	ret = regmap_bulk_write(info->max8997->regmap_rtc,
> +				MAX8997_RTC_SEC, data, RTC_NR_TIME);
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
>  				ret);
> @@ -183,13 +185,13 @@ static int max8997_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  {
>  	struct max8997_rtc_info *info = dev_get_drvdata(dev);
>  	u8 data[RTC_NR_TIME];
> -	u8 val;
> +	unsigned int val;
>  	int i, ret;
>  
>  	mutex_lock(&info->lock);
>  
> -	ret = max8997_bulk_read(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
> -			data);
> +	ret = regmap_bulk_read(info->max8997->regmap_rtc,
> +				MAX8997_RTC_ALARM1_SEC, data, RTC_NR_TIME);
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
>  				__func__, __LINE__, ret);
> @@ -207,7 +209,8 @@ static int max8997_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  	}
>  
>  	alrm->pending = 0;
> -	ret = max8997_read_reg(info->max8997->i2c, MAX8997_REG_STATUS1, &val);
> +	ret = regmap_read(info->max8997->regmap_rtc,
> +			       MAX8997_REG_STATUS1, &val);
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s:%d fail to read status1 reg(%d)\n",
>  				__func__, __LINE__, ret);
> @@ -230,8 +233,8 @@ static int max8997_rtc_stop_alarm(struct max8997_rtc_info *info)
>  	if (!mutex_is_locked(&info->lock))
>  		dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
>  
> -	ret = max8997_bulk_read(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
> -				data);
> +	ret = regmap_bulk_read(info->max8997->regmap_rtc,
> +				MAX8997_RTC_ALARM1_SEC, data, RTC_NR_TIME);
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
>  				__func__, ret);
> @@ -241,8 +244,8 @@ static int max8997_rtc_stop_alarm(struct max8997_rtc_info *info)
>  	for (i = 0; i < RTC_NR_TIME; i++)
>  		data[i] &= ~ALARM_ENABLE_MASK;
>  
> -	ret = max8997_bulk_write(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
> -				 data);
> +	ret = regmap_bulk_write(info->max8997->regmap_rtc,
> +				 MAX8997_RTC_ALARM1_SEC, data, RTC_NR_TIME);
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
>  				__func__, ret);
> @@ -262,8 +265,8 @@ static int max8997_rtc_start_alarm(struct max8997_rtc_info *info)
>  	if (!mutex_is_locked(&info->lock))
>  		dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
>  
> -	ret = max8997_bulk_read(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
> -				data);
> +	ret = regmap_bulk_read(info->max8997->regmap_rtc,
> +				MAX8997_RTC_ALARM1_SEC, data, RTC_NR_TIME);
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
>  				__func__, ret);
> @@ -281,8 +284,8 @@ static int max8997_rtc_start_alarm(struct max8997_rtc_info *info)
>  	if (data[RTC_DATE] & 0x1f)
>  		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
>  
> -	ret = max8997_bulk_write(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
> -				 data);
> +	ret = regmap_bulk_write(info->max8997->regmap_rtc,
> +				 MAX8997_RTC_ALARM1_SEC, data, RTC_NR_TIME);
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
>  				__func__, ret);
> @@ -313,8 +316,8 @@ static int max8997_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  	if (ret < 0)
>  		goto out;
>  
> -	ret = max8997_bulk_write(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
> -				data);
> +	ret = regmap_bulk_write(info->max8997->regmap_rtc,
> +				 MAX8997_RTC_ALARM1_SEC, data, RTC_NR_TIME);
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
>  				__func__, ret);
> @@ -385,7 +388,8 @@ static void max8997_rtc_enable_wtsr(struct max8997_rtc_info *info, bool enable)
>  	dev_info(info->dev, "%s: %s WTSR\n", __func__,
>  			enable ? "enable" : "disable");
>  
> -	ret = max8997_update_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, val, mask);
> +	ret = regmap_update_bits(info->max8997->regmap_rtc,
> +				 MAX8997_RTC_WTSR_SMPL, mask, val);
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to update WTSR reg(%d)\n",
>  				__func__, ret);
> @@ -398,7 +402,7 @@ static void max8997_rtc_enable_wtsr(struct max8997_rtc_info *info, bool enable)
>  static void max8997_rtc_enable_smpl(struct max8997_rtc_info *info, bool enable)
>  {
>  	int ret;
> -	u8 val, mask;
> +	unsigned int val, mask;
>  
>  	if (!smpl_en)
>  		return;
> @@ -413,7 +417,8 @@ static void max8997_rtc_enable_smpl(struct max8997_rtc_info *info, bool enable)
>  	dev_info(info->dev, "%s: %s SMPL\n", __func__,
>  			enable ? "enable" : "disable");
>  
> -	ret = max8997_update_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, val, mask);
> +	ret = regmap_update_bits(info->max8997->regmap_rtc,
> +				 MAX8997_RTC_WTSR_SMPL, mask, val);
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to update SMPL reg(%d)\n",
>  				__func__, ret);
> @@ -423,7 +428,8 @@ static void max8997_rtc_enable_smpl(struct max8997_rtc_info *info, bool enable)
>  	max8997_rtc_set_update_reg(info);
>  
>  	val = 0;
> -	max8997_read_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, &val);
> +	regmap_read(info->max8997->regmap_rtc,
> +			 MAX8997_RTC_WTSR_SMPL, &val);
>  	pr_info("%s: WTSR_SMPL(0x%02x)\n", __func__, val);
>  }
>  
> @@ -438,7 +444,8 @@ static int max8997_rtc_init_reg(struct max8997_rtc_info *info)
>  
>  	info->rtc_24hr_mode = 1;
>  
> -	ret = max8997_bulk_write(info->rtc, MAX8997_RTC_CTRLMASK, 2, data);
> +	ret = regmap_bulk_write(info->max8997->regmap_rtc,
> +				 MAX8997_RTC_CTRLMASK, data, 2);
>  	if (ret < 0) {
>  		dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
>  				__func__, ret);
> @@ -463,7 +470,6 @@ static int max8997_rtc_probe(struct platform_device *pdev)
>  	mutex_init(&info->lock);
>  	info->dev = &pdev->dev;
>  	info->max8997 = max8997;
> -	info->rtc = max8997->rtc;
>  
>  	platform_set_drvdata(pdev, info);
>  
> diff --git a/include/linux/mfd/max8997-private.h b/include/linux/mfd/max8997-private.h
> index 78c76cd..ea80ef8 100644
> --- a/include/linux/mfd/max8997-private.h
> +++ b/include/linux/mfd/max8997-private.h
> @@ -309,6 +309,8 @@ enum max8997_rtc_reg {
>  	MAX8997_RTC_ALARM2_MONTH	= 0x22,
>  	MAX8997_RTC_ALARM2_YEAR		= 0x23,
>  	MAX8997_RTC_ALARM2_DAY_OF_MONTH	= 0x24,
> +
> +	MAX8997_RTC_REG_END		= 0x25,
>  };
>  
>  enum max8997_irq_source {
> @@ -390,6 +392,11 @@ struct max8997_dev {
>  	unsigned long type;
>  	struct platform_device *battery; /* battery control (not fuel gauge) */
>  
> +	struct regmap *regmap;
> +	struct regmap *regmap_rtc;
> +	struct regmap *regmap_haptic;
> +	struct regmap *regmap_muic;
> +
>  	int irq;
>  	int ono;
>  	struct irq_domain *irq_domain;
> @@ -398,7 +405,7 @@ struct max8997_dev {
>  	int irq_masks_cache[MAX8997_IRQ_GROUP_NR];
>  
>  	/* For hibernation */
> -	u8 reg_dump[MAX8997_REG_PMIC_END + MAX8997_MUIC_REG_END +
> +	unsigned int reg_dump[MAX8997_REG_PMIC_END + MAX8997_MUIC_REG_END +
>  		MAX8997_HAPTIC_REG_END];
>  
>  	bool gpio_status[MAX8997_NUM_GPIO];
> @@ -413,14 +420,6 @@ extern int max8997_irq_init(struct max8997_dev *max8997);
>  extern void max8997_irq_exit(struct max8997_dev *max8997);
>  extern int max8997_irq_resume(struct max8997_dev *max8997);
>  
> -extern int max8997_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest);
> -extern int max8997_bulk_read(struct i2c_client *i2c, u8 reg, int count,
> -				u8 *buf);
> -extern int max8997_write_reg(struct i2c_client *i2c, u8 reg, u8 value);
> -extern int max8997_bulk_write(struct i2c_client *i2c, u8 reg, int count,
> -				u8 *buf);
> -extern int max8997_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask);
> -
>  #define MAX8997_GPIO_INT_BOTH	(0x3 << 4)
>  #define MAX8997_GPIO_INT_RISE	(0x2 << 4)
>  #define MAX8997_GPIO_INT_FALL	(0x1 << 4)
> -- 
> 1.9.1
> 

-- 
Dmitry

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

* Re: [PATCH v5 0/3] mfd: max8997: add regmap support
  2015-01-28 14:20 ` [PATCH v5 0/3] mfd: max8997: add regmap support Robert Baldyga
@ 2015-01-29 18:03   ` Dmitry Torokhov
  2015-02-17  8:49     ` Robert Baldyga
  0 siblings, 1 reply; 11+ messages in thread
From: Dmitry Torokhov @ 2015-01-29 18:03 UTC (permalink / raw)
  To: Robert Baldyga
  Cc: lee.jones, a.zummo, sameo, myungjoo.ham, cw00.choi, cooloney,
	rpurdie, sre, dbaryshkov, dwmw2, lgirdwood, broonie,
	paul.gortmaker, sachin.kamat, k.kozlowski, linux-kernel,
	linux-input, linux-leds, linux-pm, rtc-linux

Hi Robert,

On Wed, Jan 28, 2015 at 03:20:11PM +0100, Robert Baldyga wrote:
> Hi,
> 
> The first version of this patchset was send to kernel list almost 9
> months ago and still I don't have all needed Acks. The missing ones are
> for changes in INPUT and RTC subsystems.
> 
> Dmitry, Alessandro, could you please have a look at this patches and
> give your Acks?

Sorry, there was nothing input-specific in the change (even though it
did touch one of the input drivers) so I did not realize you were
waiting for an ack.

Just for the record I am fine with the change.

Thanks.

-- 
Dmitry

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

* Re: [PATCH v5 3/3] mfd: max8997: change irq names to upper case
  2014-11-12  7:23 ` [PATCH v5 3/3] mfd: max8997: change irq names to upper case Robert Baldyga
@ 2015-01-30  1:00   ` Chanwoo Choi
  0 siblings, 0 replies; 11+ messages in thread
From: Chanwoo Choi @ 2015-01-30  1:00 UTC (permalink / raw)
  To: Robert Baldyga
  Cc: lee.jones, sameo, myungjoo.ham, dmitry.torokhov, cooloney,
	rpurdie, sre, dbaryshkov, dwmw2, lgirdwood, broonie, a.zummo,
	paul.gortmaker, sachin.kamat, k.kozlowski, linux-kernel,
	linux-input, linux-leds, linux-pm, rtc-linux

Hi Robert,

For extcon part,
Acked-by: Chanwoo Choi <cw00.choi@samsung.com>

Thanks,
Chanwoo Choi

On 11/12/2014 04:23 PM, Robert Baldyga wrote:
> This patch changes naming convention of MUIC interrupts form CamelCase
> to upper case. It makes names more readable and consistent with another
> interrupt names in max8997 driver.
> 
> Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> 
> [For the mfd part]
> Acked-by: Lee Jones <lee.jones@linaro.org>
> ---
>  drivers/extcon/extcon-max8997.c     | 32 ++++++++++++++++----------------
>  include/linux/mfd/max8997-private.h | 16 ++++++++--------
>  2 files changed, 24 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
> index 172dbd6..834b72f 100644
> --- a/drivers/extcon/extcon-max8997.c
> +++ b/drivers/extcon/extcon-max8997.c
> @@ -46,15 +46,15 @@ struct max8997_muic_irq {
>  };
>  
>  static struct max8997_muic_irq muic_irqs[] = {
> -	{ MAX8997_MUICIRQ_ADCError,	"muic-ADCERROR" },
> -	{ MAX8997_MUICIRQ_ADCLow,	"muic-ADCLOW" },
> -	{ MAX8997_MUICIRQ_ADC,		"muic-ADC" },
> -	{ MAX8997_MUICIRQ_VBVolt,	"muic-VBVOLT" },
> -	{ MAX8997_MUICIRQ_DBChg,	"muic-DBCHG" },
> -	{ MAX8997_MUICIRQ_DCDTmr,	"muic-DCDTMR" },
> -	{ MAX8997_MUICIRQ_ChgDetRun,	"muic-CHGDETRUN" },
> -	{ MAX8997_MUICIRQ_ChgTyp,	"muic-CHGTYP" },
> -	{ MAX8997_MUICIRQ_OVP,		"muic-OVP" },
> +	{ MAX8997_MUICIRQ_ADCERROR,	"MUIC-ADCERROR" },
> +	{ MAX8997_MUICIRQ_ADCLOW,	"MUIC-ADCLOW" },
> +	{ MAX8997_MUICIRQ_ADC,		"MUIC-ADC" },
> +	{ MAX8997_MUICIRQ_VBVOLT,	"MUIC-VBVOLT" },
> +	{ MAX8997_MUICIRQ_DBCHG,	"MUIC-DBCHG" },
> +	{ MAX8997_MUICIRQ_DCDTMR,	"MUIC-DCDTMR" },
> +	{ MAX8997_MUICIRQ_CHGDETRUN,	"MUIC-CHGDETRUN" },
> +	{ MAX8997_MUICIRQ_CHGTYP,	"MUIC-CHGTYP" },
> +	{ MAX8997_MUICIRQ_OVP,		"MUIC-OVP" },
>  };
>  
>  /* Define supported cable type */
> @@ -553,17 +553,17 @@ static void max8997_muic_irq_work(struct work_struct *work)
>  	}
>  
>  	switch (irq_type) {
> -	case MAX8997_MUICIRQ_ADCError:
> -	case MAX8997_MUICIRQ_ADCLow:
> +	case MAX8997_MUICIRQ_ADCERROR:
> +	case MAX8997_MUICIRQ_ADCLOW:
>  	case MAX8997_MUICIRQ_ADC:
>  		/* Handle all of cable except for charger cable */
>  		ret = max8997_muic_adc_handler(info);
>  		break;
> -	case MAX8997_MUICIRQ_VBVolt:
> -	case MAX8997_MUICIRQ_DBChg:
> -	case MAX8997_MUICIRQ_DCDTmr:
> -	case MAX8997_MUICIRQ_ChgDetRun:
> -	case MAX8997_MUICIRQ_ChgTyp:
> +	case MAX8997_MUICIRQ_VBVOLT:
> +	case MAX8997_MUICIRQ_DBCHG:
> +	case MAX8997_MUICIRQ_DCDTMR:
> +	case MAX8997_MUICIRQ_CHGDETRUN:
> +	case MAX8997_MUICIRQ_CHGTYP:
>  		/* Handle charger cable */
>  		ret = max8997_muic_chg_handler(info);
>  		break;
> diff --git a/include/linux/mfd/max8997-private.h b/include/linux/mfd/max8997-private.h
> index f42ea22..2817fa6 100644
> --- a/include/linux/mfd/max8997-private.h
> +++ b/include/linux/mfd/max8997-private.h
> @@ -411,14 +411,14 @@ enum max8997_irq {
>  
>  enum max8997_irq_muic {
>  	MAX8997_MUICIRQ_ADC,
> -	MAX8997_MUICIRQ_ADCLow,
> -	MAX8997_MUICIRQ_ADCError,
> -
> -	MAX8997_MUICIRQ_ChgTyp,
> -	MAX8997_MUICIRQ_ChgDetRun,
> -	MAX8997_MUICIRQ_DCDTmr,
> -	MAX8997_MUICIRQ_DBChg,
> -	MAX8997_MUICIRQ_VBVolt,
> +	MAX8997_MUICIRQ_ADCLOW,
> +	MAX8997_MUICIRQ_ADCERROR,
> +
> +	MAX8997_MUICIRQ_CHGTYP,
> +	MAX8997_MUICIRQ_CHGDETRUN,
> +	MAX8997_MUICIRQ_DCDTMR,
> +	MAX8997_MUICIRQ_DBCHG,
> +	MAX8997_MUICIRQ_VBVOLT,
>  
>  	MAX8997_MUICIRQ_OVP,
>  
> 


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

* Re: [PATCH v5 0/3] mfd: max8997: add regmap support
  2015-01-29 18:03   ` Dmitry Torokhov
@ 2015-02-17  8:49     ` Robert Baldyga
  2016-05-03 15:56       ` Alexandre Belloni
  0 siblings, 1 reply; 11+ messages in thread
From: Robert Baldyga @ 2015-02-17  8:49 UTC (permalink / raw)
  To: a.zummo; +Cc: lee.jones@linaro.org >> Lee Jones, linux-kernel, rtc-linux

Hi Alessandro,

It looks like only your Ack is missing. Could you please look at my
patches? There are very little changes in RTC subsystem but your Ack is
needed.

Thank you,
Robert Baldyga

On 01/29/2015 07:03 PM, Dmitry Torokhov wrote:
> Hi Robert,
> 
> On Wed, Jan 28, 2015 at 03:20:11PM +0100, Robert Baldyga wrote:
>> Hi,
>>
>> The first version of this patchset was send to kernel list almost 9
>> months ago and still I don't have all needed Acks. The missing ones are
>> for changes in INPUT and RTC subsystems.
>>
>> Dmitry, Alessandro, could you please have a look at this patches and
>> give your Acks?
> 
> Sorry, there was nothing input-specific in the change (even though it
> did touch one of the input drivers) so I did not realize you were
> waiting for an ack.
> 
> Just for the record I am fine with the change.
> 
> Thanks.
> 


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

* Re: [PATCH v5 0/3] mfd: max8997: add regmap support
  2015-02-17  8:49     ` Robert Baldyga
@ 2016-05-03 15:56       ` Alexandre Belloni
  0 siblings, 0 replies; 11+ messages in thread
From: Alexandre Belloni @ 2016-05-03 15:56 UTC (permalink / raw)
  To: Robert Baldyga
  Cc: a.zummo, lee.jones@linaro.org >> Lee Jones, linux-kernel,
	rtc-linux

Hi,

On 17/02/2015 at 09:49:24 +0100, Robert Baldyga wrote :
> Hi Alessandro,
> 
> It looks like only your Ack is missing. Could you please look at my
> patches? There are very little changes in RTC subsystem but your Ack is
> needed.
> 

I understand you are still waiting for acks from an RTC subsystem
maintainer...

For the whole series:
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

end of thread, other threads:[~2016-05-03 15:56 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-12  7:23 [PATCH v5 0/3] mfd: max8997: add regmap support Robert Baldyga
2014-11-12  7:23 ` [PATCH v5 1/3] mfd: max8997: use regmap to access registers Robert Baldyga
2014-11-12 17:01   ` Sebastian Reichel
2015-01-29 18:01   ` Dmitry Torokhov
2014-11-12  7:23 ` [PATCH v5 2/3] mfd: max8997: handle IRQs using regmap Robert Baldyga
2014-11-12  7:23 ` [PATCH v5 3/3] mfd: max8997: change irq names to upper case Robert Baldyga
2015-01-30  1:00   ` Chanwoo Choi
2015-01-28 14:20 ` [PATCH v5 0/3] mfd: max8997: add regmap support Robert Baldyga
2015-01-29 18:03   ` Dmitry Torokhov
2015-02-17  8:49     ` Robert Baldyga
2016-05-03 15:56       ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).