diff mbox series

[1/5] mfd: rk808: Add RK817 and RK809 support

Message ID 1532315945-1094-2-git-send-email-tony.xie@rock-chips.com (mailing list archive)
State New, archived
Headers show
Series support a new type of PMIC���including two chips(rk817 and rk809) | expand

Commit Message

Tony Xie July 23, 2018, 3:19 a.m. UTC
The rk809 and rk817 are a Power Management IC (PMIC) for multimedia
    and handheld devices. It contains the following components:

        - Regulators
        - RTC
        - Clocking

    Both RK809 and RK817 chips are using a similar register map,
    so we can reuse the RTC and Clocking and regulators functionality.

Signed-off-by: Tony Xie <tony.xie@rock-chips.com>
---
 drivers/mfd/Kconfig       |   6 +-
 drivers/mfd/rk808.c       | 216 +++++++++++++++++++++++++++++++++++++++++++++-
 include/linux/mfd/rk808.h | 172 ++++++++++++++++++++++++++++++++++++
 3 files changed, 389 insertions(+), 5 deletions(-)

Comments

kernel test robot July 23, 2018, 9:59 p.m. UTC | #1
Hi Tony,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on ljones-mfd/for-mfd-next]
[also build test WARNING on v4.18-rc6 next-20180723]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Tony-Xie/mfd-rk808-Add-RK817-and-RK809-support/20180724-040547
base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git for-mfd-next
config: xtensa-allyesconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 8.1.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=8.1.0 make.cross ARCH=xtensa 

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

   drivers//mfd/rk808.c: In function 'rk808_probe':
>> drivers//mfd/rk808.c:715:16: warning: 'pm_pwroff_fn' may be used uninitialized in this function [-Wmaybe-uninitialized]
      pm_power_off = pm_pwroff_fn;
      ~~~~~~~~~~~~~^~~~~~~~~~~~~~

vim +/pm_pwroff_fn +715 drivers//mfd/rk808.c

2eedcbfc0 Wadim Egorov    2016-08-29  581  
f69a7cf74 Chris Zhong     2014-09-03  582  static int rk808_probe(struct i2c_client *client,
f69a7cf74 Chris Zhong     2014-09-03  583  		       const struct i2c_device_id *id)
f69a7cf74 Chris Zhong     2014-09-03  584  {
f69a7cf74 Chris Zhong     2014-09-03  585  	struct device_node *np = client->dev.of_node;
f69a7cf74 Chris Zhong     2014-09-03  586  	struct rk808 *rk808;
2eedcbfc0 Wadim Egorov    2016-08-29  587  	const struct rk808_reg_data *pre_init_reg;
2eedcbfc0 Wadim Egorov    2016-08-29  588  	const struct mfd_cell *cells;
b2e2c8509 Jianhong Chen   2016-10-17  589  	void (*pm_pwroff_fn)(void);
2eedcbfc0 Wadim Egorov    2016-08-29  590  	int nr_pre_init_regs;
2eedcbfc0 Wadim Egorov    2016-08-29  591  	int nr_cells;
9d6105e19 Elaine Zhang    2017-08-21  592  	int pm_off = 0, msb, lsb;
1e99c2e53 Tony Xie        2018-07-23  593  	unsigned char pmic_id_msb = RK808_ID_MSB, pmic_id_lsb = RK808_ID_LSB;
f69a7cf74 Chris Zhong     2014-09-03  594  	int ret;
f69a7cf74 Chris Zhong     2014-09-03  595  	int i;
f69a7cf74 Chris Zhong     2014-09-03  596  
f69a7cf74 Chris Zhong     2014-09-03  597  	rk808 = devm_kzalloc(&client->dev, sizeof(*rk808), GFP_KERNEL);
f69a7cf74 Chris Zhong     2014-09-03  598  	if (!rk808)
f69a7cf74 Chris Zhong     2014-09-03  599  		return -ENOMEM;
f69a7cf74 Chris Zhong     2014-09-03  600  
1e99c2e53 Tony Xie        2018-07-23  601  	if (of_device_is_compatible(np, "rockchip,rk817") ||
1e99c2e53 Tony Xie        2018-07-23  602  	    of_device_is_compatible(np, "rockchip,rk809")) {
1e99c2e53 Tony Xie        2018-07-23  603  		pmic_id_msb = RK817_ID_MSB;
1e99c2e53 Tony Xie        2018-07-23  604  		pmic_id_lsb = RK817_ID_LSB;
1e99c2e53 Tony Xie        2018-07-23  605  	}
9d6105e19 Elaine Zhang    2017-08-21  606  	/* Read chip variant */
1e99c2e53 Tony Xie        2018-07-23  607  	msb = i2c_smbus_read_byte_data(client, pmic_id_msb);
9d6105e19 Elaine Zhang    2017-08-21  608  	if (msb < 0) {
9d6105e19 Elaine Zhang    2017-08-21  609  		dev_err(&client->dev, "failed to read the chip id at 0x%x\n",
2eedcbfc0 Wadim Egorov    2016-08-29  610  			RK808_ID_MSB);
9d6105e19 Elaine Zhang    2017-08-21  611  		return msb;
2eedcbfc0 Wadim Egorov    2016-08-29  612  	}
2eedcbfc0 Wadim Egorov    2016-08-29  613  
1e99c2e53 Tony Xie        2018-07-23  614  	lsb = i2c_smbus_read_byte_data(client, pmic_id_lsb);
9d6105e19 Elaine Zhang    2017-08-21  615  	if (lsb < 0) {
9d6105e19 Elaine Zhang    2017-08-21  616  		dev_err(&client->dev, "failed to read the chip id at 0x%x\n",
9d6105e19 Elaine Zhang    2017-08-21  617  			RK808_ID_LSB);
9d6105e19 Elaine Zhang    2017-08-21  618  		return lsb;
9d6105e19 Elaine Zhang    2017-08-21  619  	}
9d6105e19 Elaine Zhang    2017-08-21  620  
9d6105e19 Elaine Zhang    2017-08-21  621  	rk808->variant = ((msb << 8) | lsb) & RK8XX_ID_MSK;
9d6105e19 Elaine Zhang    2017-08-21  622  	dev_info(&client->dev, "chip id: 0x%x\n", (unsigned int)rk808->variant);
2eedcbfc0 Wadim Egorov    2016-08-29  623  
2eedcbfc0 Wadim Egorov    2016-08-29  624  	switch (rk808->variant) {
990f05f6a Elaine Zhang    2017-08-21  625  	case RK805_ID:
990f05f6a Elaine Zhang    2017-08-21  626  		rk808->regmap_cfg = &rk805_regmap_config;
990f05f6a Elaine Zhang    2017-08-21  627  		rk808->regmap_irq_chip = &rk805_irq_chip;
990f05f6a Elaine Zhang    2017-08-21  628  		pre_init_reg = rk805_pre_init_reg;
990f05f6a Elaine Zhang    2017-08-21  629  		nr_pre_init_regs = ARRAY_SIZE(rk805_pre_init_reg);
990f05f6a Elaine Zhang    2017-08-21  630  		cells = rk805s;
990f05f6a Elaine Zhang    2017-08-21  631  		nr_cells = ARRAY_SIZE(rk805s);
990f05f6a Elaine Zhang    2017-08-21  632  		pm_pwroff_fn = rk805_device_shutdown;
990f05f6a Elaine Zhang    2017-08-21  633  		break;
2eedcbfc0 Wadim Egorov    2016-08-29  634  	case RK808_ID:
2eedcbfc0 Wadim Egorov    2016-08-29  635  		rk808->regmap_cfg = &rk808_regmap_config;
2eedcbfc0 Wadim Egorov    2016-08-29  636  		rk808->regmap_irq_chip = &rk808_irq_chip;
2eedcbfc0 Wadim Egorov    2016-08-29  637  		pre_init_reg = rk808_pre_init_reg;
2eedcbfc0 Wadim Egorov    2016-08-29  638  		nr_pre_init_regs = ARRAY_SIZE(rk808_pre_init_reg);
2eedcbfc0 Wadim Egorov    2016-08-29  639  		cells = rk808s;
2eedcbfc0 Wadim Egorov    2016-08-29  640  		nr_cells = ARRAY_SIZE(rk808s);
b2e2c8509 Jianhong Chen   2016-10-17  641  		pm_pwroff_fn = rk808_device_shutdown;
2eedcbfc0 Wadim Egorov    2016-08-29  642  		break;
2eedcbfc0 Wadim Egorov    2016-08-29  643  	case RK818_ID:
2eedcbfc0 Wadim Egorov    2016-08-29  644  		rk808->regmap_cfg = &rk818_regmap_config;
2eedcbfc0 Wadim Egorov    2016-08-29  645  		rk808->regmap_irq_chip = &rk818_irq_chip;
2eedcbfc0 Wadim Egorov    2016-08-29  646  		pre_init_reg = rk818_pre_init_reg;
2eedcbfc0 Wadim Egorov    2016-08-29  647  		nr_pre_init_regs = ARRAY_SIZE(rk818_pre_init_reg);
2eedcbfc0 Wadim Egorov    2016-08-29  648  		cells = rk818s;
2eedcbfc0 Wadim Egorov    2016-08-29  649  		nr_cells = ARRAY_SIZE(rk818s);
b2e2c8509 Jianhong Chen   2016-10-17  650  		pm_pwroff_fn = rk818_device_shutdown;
2eedcbfc0 Wadim Egorov    2016-08-29  651  		break;
1e99c2e53 Tony Xie        2018-07-23  652  	case RK809_ID:
1e99c2e53 Tony Xie        2018-07-23  653  	case RK817_ID:
1e99c2e53 Tony Xie        2018-07-23  654  		rk808->regmap_cfg = &rk817_regmap_config;
1e99c2e53 Tony Xie        2018-07-23  655  		rk808->regmap_irq_chip = &rk817_irq_chip;
1e99c2e53 Tony Xie        2018-07-23  656  		pre_init_reg = rk817_pre_init_reg;
1e99c2e53 Tony Xie        2018-07-23  657  		nr_pre_init_regs = ARRAY_SIZE(rk817_pre_init_reg);
1e99c2e53 Tony Xie        2018-07-23  658  		cells = rk817s;
1e99c2e53 Tony Xie        2018-07-23  659  		nr_cells = ARRAY_SIZE(rk817s);
1e99c2e53 Tony Xie        2018-07-23  660  		pm_power_off_prepare = rk8xx_device_shutdown_prepare;
1e99c2e53 Tony Xie        2018-07-23  661  		break;
2eedcbfc0 Wadim Egorov    2016-08-29  662  	default:
2eedcbfc0 Wadim Egorov    2016-08-29  663  		dev_err(&client->dev, "Unsupported RK8XX ID %lu\n",
2eedcbfc0 Wadim Egorov    2016-08-29  664  			rk808->variant);
2eedcbfc0 Wadim Egorov    2016-08-29  665  		return -EINVAL;
2eedcbfc0 Wadim Egorov    2016-08-29  666  	}
2eedcbfc0 Wadim Egorov    2016-08-29  667  
2eedcbfc0 Wadim Egorov    2016-08-29  668  	rk808->i2c = client;
2eedcbfc0 Wadim Egorov    2016-08-29  669  	i2c_set_clientdata(client, rk808);
2eedcbfc0 Wadim Egorov    2016-08-29  670  
2eedcbfc0 Wadim Egorov    2016-08-29  671  	rk808->regmap = devm_regmap_init_i2c(client, rk808->regmap_cfg);
f69a7cf74 Chris Zhong     2014-09-03  672  	if (IS_ERR(rk808->regmap)) {
f69a7cf74 Chris Zhong     2014-09-03  673  		dev_err(&client->dev, "regmap initialization failed\n");
f69a7cf74 Chris Zhong     2014-09-03  674  		return PTR_ERR(rk808->regmap);
f69a7cf74 Chris Zhong     2014-09-03  675  	}
f69a7cf74 Chris Zhong     2014-09-03  676  
2eedcbfc0 Wadim Egorov    2016-08-29  677  	if (!client->irq) {
2eedcbfc0 Wadim Egorov    2016-08-29  678  		dev_err(&client->dev, "No interrupt support, no core IRQ\n");
2eedcbfc0 Wadim Egorov    2016-08-29  679  		return -EINVAL;
f69a7cf74 Chris Zhong     2014-09-03  680  	}
f69a7cf74 Chris Zhong     2014-09-03  681  
f69a7cf74 Chris Zhong     2014-09-03  682  	ret = regmap_add_irq_chip(rk808->regmap, client->irq,
f69a7cf74 Chris Zhong     2014-09-03  683  				  IRQF_ONESHOT, -1,
2eedcbfc0 Wadim Egorov    2016-08-29  684  				  rk808->regmap_irq_chip, &rk808->irq_data);
f69a7cf74 Chris Zhong     2014-09-03  685  	if (ret) {
f69a7cf74 Chris Zhong     2014-09-03  686  		dev_err(&client->dev, "Failed to add irq_chip %d\n", ret);
f69a7cf74 Chris Zhong     2014-09-03  687  		return ret;
f69a7cf74 Chris Zhong     2014-09-03  688  	}
f69a7cf74 Chris Zhong     2014-09-03  689  
2eedcbfc0 Wadim Egorov    2016-08-29  690  	for (i = 0; i < nr_pre_init_regs; i++) {
2eedcbfc0 Wadim Egorov    2016-08-29  691  		ret = regmap_update_bits(rk808->regmap,
2eedcbfc0 Wadim Egorov    2016-08-29  692  					pre_init_reg[i].addr,
2eedcbfc0 Wadim Egorov    2016-08-29  693  					pre_init_reg[i].mask,
2eedcbfc0 Wadim Egorov    2016-08-29  694  					pre_init_reg[i].value);
2eedcbfc0 Wadim Egorov    2016-08-29  695  		if (ret) {
2eedcbfc0 Wadim Egorov    2016-08-29  696  			dev_err(&client->dev,
2eedcbfc0 Wadim Egorov    2016-08-29  697  				"0x%x write err\n",
2eedcbfc0 Wadim Egorov    2016-08-29  698  				pre_init_reg[i].addr);
2eedcbfc0 Wadim Egorov    2016-08-29  699  			return ret;
2eedcbfc0 Wadim Egorov    2016-08-29  700  		}
2eedcbfc0 Wadim Egorov    2016-08-29  701  	}
f69a7cf74 Chris Zhong     2014-09-03  702  
2eedcbfc0 Wadim Egorov    2016-08-29  703  	ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
2eedcbfc0 Wadim Egorov    2016-08-29  704  			      cells, nr_cells, NULL, 0,
d5623161a Laxman Dewangan 2016-04-08  705  			      regmap_irq_get_domain(rk808->irq_data));
f69a7cf74 Chris Zhong     2014-09-03  706  	if (ret) {
f69a7cf74 Chris Zhong     2014-09-03  707  		dev_err(&client->dev, "failed to add MFD devices %d\n", ret);
f69a7cf74 Chris Zhong     2014-09-03  708  		goto err_irq;
f69a7cf74 Chris Zhong     2014-09-03  709  	}
f69a7cf74 Chris Zhong     2014-09-03  710  
f69a7cf74 Chris Zhong     2014-09-03  711  	pm_off = of_property_read_bool(np,
f69a7cf74 Chris Zhong     2014-09-03  712  				"rockchip,system-power-controller");
f69a7cf74 Chris Zhong     2014-09-03  713  	if (pm_off && !pm_power_off) {
f69a7cf74 Chris Zhong     2014-09-03  714  		rk808_i2c_client = client;
b2e2c8509 Jianhong Chen   2016-10-17 @715  		pm_power_off = pm_pwroff_fn;
f69a7cf74 Chris Zhong     2014-09-03  716  	}
f69a7cf74 Chris Zhong     2014-09-03  717  
f69a7cf74 Chris Zhong     2014-09-03  718  	return 0;
f69a7cf74 Chris Zhong     2014-09-03  719  
f69a7cf74 Chris Zhong     2014-09-03  720  err_irq:
f69a7cf74 Chris Zhong     2014-09-03  721  	regmap_del_irq_chip(client->irq, rk808->irq_data);
f69a7cf74 Chris Zhong     2014-09-03  722  	return ret;
f69a7cf74 Chris Zhong     2014-09-03  723  }
f69a7cf74 Chris Zhong     2014-09-03  724  

:::::: The code at line 715 was first introduced by commit
:::::: b2e2c85091710159b305735d557f4ef4695f5dff mfd: rk808: RK818 uses DEV_OFF to power off supplies

:::::: TO: Jianhong Chen <chenjh@rock-chips.com>
:::::: CC: Lee Jones <lee.jones@linaro.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
kernel test robot July 23, 2018, 11:13 p.m. UTC | #2
Hi Tony,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on ljones-mfd/for-mfd-next]
[also build test ERROR on v4.18-rc6 next-20180723]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Tony-Xie/mfd-rk808-Add-RK817-and-RK809-support/20180724-040547
base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git for-mfd-next
config: i386-randconfig-a0-201829 (attached as .config)
compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

>> ERROR: "pm_power_off_prepare" [drivers/mfd/rk808.ko] undefined!

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox series

Patch

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index b860eb5..84f2f22 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -967,14 +967,14 @@  config MFD_RC5T583
 	  different functionality of the device.
 
 config MFD_RK808
-	tristate "Rockchip RK805/RK808/RK818 Power Management Chip"
+	tristate "Rockchip RK805/RK808/RK809/RK817/RK818 Power Management Chip"
 	depends on I2C && OF
 	select MFD_CORE
 	select REGMAP_I2C
 	select REGMAP_IRQ
 	help
-	  If you say yes here you get support for the RK805, RK808 and RK818
-	  Power Management chips.
+	  If you say yes here you get support for the RK805, RK809 and RK817,
+	  RK808 and RK818 Power Management chips.
 	  This driver provides common support for accessing the device
 	  through I2C interface. The device supports multiple sub-devices
 	  including interrupts, RTC, LDO & DCDC regulators, and onkey.
diff --git a/drivers/mfd/rk808.c b/drivers/mfd/rk808.c
index 216fbf6..bfb5668 100644
--- a/drivers/mfd/rk808.c
+++ b/drivers/mfd/rk808.c
@@ -62,6 +62,29 @@  static bool rk808_is_volatile_reg(struct device *dev, unsigned int reg)
 	return false;
 }
 
+static bool rk817_is_volatile_reg(struct device *dev, unsigned int reg)
+{
+	/*
+	 * Notes:
+	 * - Technically the ROUND_30s bit makes RTC_CTRL_REG volatile, but
+	 *   we don't use that feature.  It's better to cache.
+	 * - It's unlikely we care that RK808_DEVCTRL_REG is volatile since
+	 *   bits are cleared in case when we shutoff anyway, but better safe.
+	 */
+
+	switch (reg) {
+	case RK817_SECONDS_REG ... RK817_WEEKS_REG:
+	case RK817_RTC_STATUS_REG:
+	case RK817_INT_STS_REG0:
+	case RK817_INT_STS_REG1:
+	case RK817_INT_STS_REG2:
+	case RK817_SYS_STS:
+		return true;
+	}
+
+	return true;
+}
+
 static const struct regmap_config rk818_regmap_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
@@ -86,6 +109,14 @@  static bool rk808_is_volatile_reg(struct device *dev, unsigned int reg)
 	.volatile_reg = rk808_is_volatile_reg,
 };
 
+static const struct regmap_config rk817_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = RK817_GPIO_INT_CFG,
+	.cache_type = REGCACHE_NONE,
+	.volatile_reg = rk817_is_volatile_reg,
+};
+
 static struct resource rtc_resources[] = {
 	{
 		.start  = RK808_IRQ_RTC_ALARM,
@@ -94,6 +125,13 @@  static bool rk808_is_volatile_reg(struct device *dev, unsigned int reg)
 	}
 };
 
+static struct resource rk817_rtc_resources[] = {
+	{
+		.start  = RK817_IRQ_RTC_ALARM,
+		.end    = RK817_IRQ_RTC_ALARM,
+		.flags  = IORESOURCE_IRQ,
+	}
+};
 static struct resource rk805_key_resources[] = {
 	{
 		.start  = RK805_IRQ_PWRON_FALL,
@@ -107,6 +145,19 @@  static bool rk808_is_volatile_reg(struct device *dev, unsigned int reg)
 	}
 };
 
+static struct resource rk817_pwrkey_resources[] = {
+	{
+		.start  = RK817_IRQ_PWRON_RISE,
+		.end    = RK817_IRQ_PWRON_RISE,
+		.flags  = IORESOURCE_IRQ,
+	},
+	{
+		.start  = RK817_IRQ_PWRON_FALL,
+		.end    = RK817_IRQ_PWRON_FALL,
+		.flags  = IORESOURCE_IRQ,
+	},
+};
+
 static const struct mfd_cell rk805s[] = {
 	{ .name = "rk808-clkout", },
 	{ .name = "rk808-regulator", },
@@ -132,6 +183,21 @@  static bool rk808_is_volatile_reg(struct device *dev, unsigned int reg)
 	},
 };
 
+static const struct mfd_cell rk817s[] = {
+	{ .name = "rk808-clkout",},
+	{ .name = "rk808-regulator",},
+	{
+		.name = "rk8xx-pwrkey",
+		.num_resources = ARRAY_SIZE(rk817_pwrkey_resources),
+		.resources = &rk817_pwrkey_resources[0],
+	},
+	{
+		.name = "rk808-rtc",
+		.num_resources = ARRAY_SIZE(rk817_rtc_resources),
+		.resources = &rk817_rtc_resources[0],
+	},
+};
+
 static const struct mfd_cell rk818s[] = {
 	{ .name = "rk808-clkout", },
 	{ .name = "rk808-regulator", },
@@ -167,6 +233,13 @@  static bool rk808_is_volatile_reg(struct device *dev, unsigned int reg)
 						    VB_LO_SEL_3500MV },
 };
 
+static const struct rk808_reg_data rk817_pre_init_reg[] = {
+	{RK817_RTC_CTRL_REG, RTC_STOP, RTC_STOP},
+	{RK817_GPIO_INT_CFG, RK817_INT_POL_MSK, RK817_INT_POL_H},
+	{RK817_SYS_CFG(1), RK817_HOTDIE_TEMP_MSK | RK817_TSD_TEMP_MSK,
+					   RK817_HOTDIE_105 | RK817_TSD_140},
+};
+
 static const struct rk808_reg_data rk818_pre_init_reg[] = {
 	/* improve efficiency */
 	{ RK818_BUCK2_CONFIG_REG, BUCK2_RATE_MASK,  BUCK_ILMIN_250MA },
@@ -332,6 +405,39 @@  static bool rk808_is_volatile_reg(struct device *dev, unsigned int reg)
 	},
 };
 
+#define REGMAP_IRQ_M(_id) \
+	[_id] = {				\
+		.mask = BIT(((_id) % 8)),	\
+		.reg_offset = ((_id) / 8),	\
+	}
+
+static const struct regmap_irq rk817_irqs[RK817_IRQ_END] = {
+	REGMAP_IRQ_M(0),
+	REGMAP_IRQ_M(1),
+	REGMAP_IRQ_M(2),
+	REGMAP_IRQ_M(3),
+	REGMAP_IRQ_M(4),
+	REGMAP_IRQ_M(5),
+	REGMAP_IRQ_M(6),
+	REGMAP_IRQ_M(7),
+	REGMAP_IRQ_M(8),
+	REGMAP_IRQ_M(9),
+	REGMAP_IRQ_M(10),
+	REGMAP_IRQ_M(11),
+	REGMAP_IRQ_M(12),
+	REGMAP_IRQ_M(13),
+	REGMAP_IRQ_M(14),
+	REGMAP_IRQ_M(15),
+	REGMAP_IRQ_M(16),
+	REGMAP_IRQ_M(17),
+	REGMAP_IRQ_M(18),
+	REGMAP_IRQ_M(19),
+	REGMAP_IRQ_M(20),
+	REGMAP_IRQ_M(21),
+	REGMAP_IRQ_M(22),
+	REGMAP_IRQ_M(23)
+};
+
 static struct regmap_irq_chip rk805_irq_chip = {
 	.name = "rk805",
 	.irqs = rk805_irqs,
@@ -355,6 +461,18 @@  static bool rk808_is_volatile_reg(struct device *dev, unsigned int reg)
 	.init_ack_masked = true,
 };
 
+static struct regmap_irq_chip rk817_irq_chip = {
+	.name = "rk817",
+	.irqs = rk817_irqs,
+	.num_irqs = ARRAY_SIZE(rk817_irqs),
+	.num_regs = 3,
+	.irq_reg_stride = 2,
+	.status_base = RK817_INT_STS_REG0,
+	.mask_base = RK817_INT_STS_MSK_REG0,
+	.ack_base = RK817_INT_STS_REG0,
+	.init_ack_masked = true,
+};
+
 static const struct regmap_irq_chip rk818_irq_chip = {
 	.name = "rk818",
 	.irqs = rk818_irqs,
@@ -423,9 +541,39 @@  static void rk818_device_shutdown(void)
 		dev_err(&rk808_i2c_client->dev, "power off error!\n");
 }
 
+static void rk8xx_device_shutdown_prepare(void)
+{
+	int ret;
+	struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
+
+	if (!rk808) {
+		dev_warn(&rk808_i2c_client->dev,
+			 "have no rk808, so do nothing here\n");
+		return;
+	}
+
+	switch (rk808->variant) {
+	case RK809_ID:
+	case RK817_ID:
+		ret = regmap_update_bits(rk808->regmap,
+					 RK817_SYS_CFG(3),
+					 RK817_SLPPIN_FUNC_MSK,
+					 SLPPIN_DN_FUN);
+		if (ret) {
+			dev_warn(&rk808_i2c_client->dev,
+				 "switch pin func to power down error!\n");
+		}
+		break;
+	default:
+		break;
+	}
+}
+
 static const struct of_device_id rk808_of_match[] = {
 	{ .compatible = "rockchip,rk805" },
 	{ .compatible = "rockchip,rk808" },
+	{ .compatible = "rockchip,rk809" },
+	{ .compatible = "rockchip,rk817" },
 	{ .compatible = "rockchip,rk818" },
 	{ },
 };
@@ -442,6 +590,7 @@  static int rk808_probe(struct i2c_client *client,
 	int nr_pre_init_regs;
 	int nr_cells;
 	int pm_off = 0, msb, lsb;
+	unsigned char pmic_id_msb = RK808_ID_MSB, pmic_id_lsb = RK808_ID_LSB;
 	int ret;
 	int i;
 
@@ -449,15 +598,20 @@  static int rk808_probe(struct i2c_client *client,
 	if (!rk808)
 		return -ENOMEM;
 
+	if (of_device_is_compatible(np, "rockchip,rk817") ||
+	    of_device_is_compatible(np, "rockchip,rk809")) {
+		pmic_id_msb = RK817_ID_MSB;
+		pmic_id_lsb = RK817_ID_LSB;
+	}
 	/* Read chip variant */
-	msb = i2c_smbus_read_byte_data(client, RK808_ID_MSB);
+	msb = i2c_smbus_read_byte_data(client, pmic_id_msb);
 	if (msb < 0) {
 		dev_err(&client->dev, "failed to read the chip id at 0x%x\n",
 			RK808_ID_MSB);
 		return msb;
 	}
 
-	lsb = i2c_smbus_read_byte_data(client, RK808_ID_LSB);
+	lsb = i2c_smbus_read_byte_data(client, pmic_id_lsb);
 	if (lsb < 0) {
 		dev_err(&client->dev, "failed to read the chip id at 0x%x\n",
 			RK808_ID_LSB);
@@ -495,6 +649,16 @@  static int rk808_probe(struct i2c_client *client,
 		nr_cells = ARRAY_SIZE(rk818s);
 		pm_pwroff_fn = rk818_device_shutdown;
 		break;
+	case RK809_ID:
+	case RK817_ID:
+		rk808->regmap_cfg = &rk817_regmap_config;
+		rk808->regmap_irq_chip = &rk817_irq_chip;
+		pre_init_reg = rk817_pre_init_reg;
+		nr_pre_init_regs = ARRAY_SIZE(rk817_pre_init_reg);
+		cells = rk817s;
+		nr_cells = ARRAY_SIZE(rk817s);
+		pm_power_off_prepare = rk8xx_device_shutdown_prepare;
+		break;
 	default:
 		dev_err(&client->dev, "Unsupported RK8XX ID %lu\n",
 			rk808->variant);
@@ -568,9 +732,56 @@  static int rk808_remove(struct i2c_client *client)
 	return 0;
 }
 
+static int rk8xx_suspend(struct device *dev)
+{
+	int ret = 0;
+	struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
+
+	switch (rk808->variant) {
+	case RK809_ID:
+	case RK817_ID:
+		ret = regmap_update_bits(rk808->regmap,
+					 RK817_SYS_CFG(3),
+					 RK817_SLPPIN_FUNC_MSK,
+					 SLPPIN_SLP_FUN);
+		break;
+	default:
+		break;
+	}
+
+	return ret;
+}
+
+static int rk8xx_resume(struct device *dev)
+{
+	int ret = 0;
+	struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
+
+	switch (rk808->variant) {
+	case RK809_ID:
+	case RK817_ID:
+		ret = regmap_update_bits(rk808->regmap,
+					 RK817_SYS_CFG(3),
+					 RK817_SLPPIN_FUNC_MSK,
+					 SLPPIN_NULL_FUN);
+		break;
+	default:
+		break;
+	}
+
+	return ret;
+}
+
+static const struct dev_pm_ops rk8xx_pm_ops = {
+	.suspend = rk8xx_suspend,
+	.resume =  rk8xx_resume,
+};
+
 static const struct i2c_device_id rk808_ids[] = {
 	{ "rk805" },
 	{ "rk808" },
+	{ "rk809" },
+	{ "rk817" },
 	{ "rk818" },
 	{ },
 };
@@ -580,6 +791,7 @@  static int rk808_remove(struct i2c_client *client)
 	.driver = {
 		.name = "rk808",
 		.of_match_table = rk808_of_match,
+		.pm = &rk8xx_pm_ops,
 	},
 	.probe    = rk808_probe,
 	.remove   = rk808_remove,
diff --git a/include/linux/mfd/rk808.h b/include/linux/mfd/rk808.h
index d315659..b973b0a 100644
--- a/include/linux/mfd/rk808.h
+++ b/include/linux/mfd/rk808.h
@@ -382,6 +382,7 @@  enum rk805_reg {
 #define SWITCH1_EN	BIT(5)
 #define DEV_OFF_RST	BIT(3)
 #define DEV_OFF		BIT(0)
+#define RTC_STOP	BIT(0)
 
 #define VB_LO_ACT		BIT(4)
 #define VB_LO_SEL_3500MV	(7 << 0)
@@ -396,6 +397,175 @@  enum rk805_reg {
 #define SLEEP_FUN			(0x1 << 2)
 #define RK8XX_ID_MSK			0xfff0
 #define FPWM_MODE			BIT(7)
+enum rk817_reg_id {
+	RK817_ID_DCDC1 = 0,
+	RK817_ID_DCDC2,
+	RK817_ID_DCDC3,
+	RK817_ID_DCDC4,
+	RK817_ID_LDO1,
+	RK817_ID_LDO2,
+	RK817_ID_LDO3,
+	RK817_ID_LDO4,
+	RK817_ID_LDO5,
+	RK817_ID_LDO6,
+	RK817_ID_LDO7,
+	RK817_ID_LDO8,
+	RK817_ID_LDO9,
+	RK817_ID_BOOST,
+	RK817_ID_BOOST_OTG_SW,
+	RK817_NUM_REGULATORS
+};
+
+enum rk809_reg_id {
+	RK809_ID_DCDC5 = RK817_ID_BOOST,
+	RK809_ID_SW1,
+	RK809_ID_SW2,
+	RK809_NUM_REGULATORS
+};
+
+#define RK817_SECONDS_REG		0x00
+#define RK817_MINUTES_REG		0x01
+#define RK817_HOURS_REG			0x02
+#define RK817_DAYS_REG			0x03
+#define RK817_MONTHS_REG		0x04
+#define RK817_YEARS_REG			0x05
+#define RK817_WEEKS_REG			0x06
+#define RK817_ALARM_SECONDS_REG		0x07
+#define RK817_ALARM_MINUTES_REG		0x08
+#define RK817_ALARM_HOURS_REG		0x09
+#define RK817_ALARM_DAYS_REG		0x0a
+#define RK817_ALARM_MONTHS_REG		0x0b
+#define RK817_ALARM_YEARS_REG		0x0c
+#define RK817_RTC_CTRL_REG		0xd
+#define RK817_RTC_STATUS_REG		0xe
+#define RK817_RTC_INT_REG		0xf
+#define RK817_RTC_COMP_LSB_REG		0x10
+#define RK817_RTC_COMP_MSB_REG		0x11
+
+#define RK817_POWER_EN_REG(i)		(0xb1 + (i))
+#define RK817_POWER_SLP_EN_REG(i)	(0xb5 + (i))
+
+#define RK817_POWER_CONFIG		(0xb9)
+
+#define RK817_BUCK_CONFIG_REG(i)	(0xba + (i) * 3)
+
+#define RK817_BUCK1_ON_VSEL_REG		0xBB
+#define RK817_BUCK1_SLP_VSEL_REG	0xBC
+
+#define RK817_BUCK2_CONFIG_REG		0xBD
+#define RK817_BUCK2_ON_VSEL_REG		0xBE
+#define RK817_BUCK2_SLP_VSEL_REG	0xBF
+
+#define RK817_BUCK3_CONFIG_REG		0xC0
+#define RK817_BUCK3_ON_VSEL_REG		0xC1
+#define RK817_BUCK3_SLP_VSEL_REG	0xC2
+
+#define RK817_BUCK4_CONFIG_REG		0xC3
+#define RK817_BUCK4_ON_VSEL_REG		0xC4
+#define RK817_BUCK4_SLP_VSEL_REG	0xC5
+
+#define RK817_LDO_ON_VSEL_REG(idx)	(0xcc + (idx) * 2)
+#define RK817_BOOST_OTG_CFG		(0xde)
+
+#define RK817_ID_MSB			0xed
+#define RK817_ID_LSB			0xee
+
+#define RK817_SYS_STS			0xf0
+#define RK817_SYS_CFG(i)		(0xf1 + (i))
+
+#define RK817_ON_SOURCE_REG		0xf5
+#define RK817_OFF_SOURCE_REG		0xf6
+
+/* INTERRUPT REGISTER */
+#define RK817_INT_STS_REG0		0xf8
+#define RK817_INT_STS_MSK_REG0		0xf9
+#define RK817_INT_STS_REG1		0xfa
+#define RK817_INT_STS_MSK_REG1		0xfb
+#define RK817_INT_STS_REG2		0xfc
+#define RK817_INT_STS_MSK_REG2		0xfd
+#define RK817_GPIO_INT_CFG		0xfe
+
+/* IRQ Definitions */
+#define RK817_IRQ_PWRON_FALL		0
+#define RK817_IRQ_PWRON_RISE		1
+#define RK817_IRQ_PWRON			2
+#define RK817_IRQ_PWMON_LP		3
+#define RK817_IRQ_HOTDIE		4
+#define RK817_IRQ_RTC_ALARM		5
+#define RK817_IRQ_RTC_PERIOD		6
+#define RK817_IRQ_VB_LO			7
+#define RK817_IRQ_PLUG_IN		(8 + 0)
+#define RK817_IRQ_PLUG_OUT		(8 + 1)
+#define RK817_IRQ_CHRG_TERM		(8 + 2)
+#define RK817_IRQ_CHRG_TIME		(8 + 3)
+#define RK817_IRQ_CHRG_TS		(8 + 4)
+#define RK817_IRQ_USB_OV		(8 + 5)
+#define RK817_IRQ_CHRG_IN_CLMP		(8 + 6)
+#define RK817_IRQ_BAT_DIS_ILIM		(8 + 7)
+#define RK817_IRQ_GATE_GPIO		(16 + 0)
+#define RK817_IRQ_TS_GPIO		(16 + 1)
+#define RK817_IRQ_CODEC_PD		(16 + 2)
+#define RK817_IRQ_CODEC_PO		(16 + 3)
+#define RK817_IRQ_CLASSD_MUTE_DONE	(16 + 4)
+#define RK817_IRQ_CLASSD_OCP		(16 + 5)
+#define RK817_IRQ_BAT_OVP		(16 + 6)
+#define RK817_IRQ_CHRG_BAT_HI		(16 + 7)
+#define RK817_IRQ_END			(RK817_IRQ_CHRG_BAT_HI + 1)
+
+/*
+ * rtc_ctrl 0xd
+ * same as 808, except bit4
+ */
+#define RK817_RTC_CTRL_RSV4		BIT(4)
+
+/* power config 0xb9 */
+#define RK817_BUCK3_FB_RES_MSK		BIT(6)
+#define RK817_BUCK3_FB_RES_INTER	BIT(6)
+#define RK817_BUCK3_FB_RES_EXT		0
+
+/* buck config 0xba */
+#define RK817_RAMP_RATE_OFFSET		6
+#define RK817_RAMP_RATE_MASK		(0x3 << RK817_RAMP_RATE_OFFSET)
+#define RK817_RAMP_RATE_3MV_PER_US	(0x0 << RK817_RAMP_RATE_OFFSET)
+#define RK817_RAMP_RATE_6_3MV_PER_US	(0x1 << RK817_RAMP_RATE_OFFSET)
+#define RK817_RAMP_RATE_12_5MV_PER_US	(0x2 << RK817_RAMP_RATE_OFFSET)
+#define RK817_RAMP_RATE_25MV_PER_US	(0x3 << RK817_RAMP_RATE_OFFSET)
+
+/* sys_cfg1 0xf2 */
+#define RK817_HOTDIE_TEMP_MSK		(0x3 << 4)
+#define RK817_HOTDIE_85			(0x0 << 4)
+#define RK817_HOTDIE_95			(0x1 << 4)
+#define RK817_HOTDIE_105		(0x2 << 4)
+#define RK817_HOTDIE_115		(0x3 << 4)
+
+#define RK817_TSD_TEMP_MSK		BIT(6)
+#define RK817_TSD_140			0
+#define RK817_TSD_160			BIT(6)
+
+#define RK817_CLK32KOUT2_EN		BIT(7)
+
+/* sys_cfg3 0xf4 */
+#define RK817_SLPPIN_FUNC_MSK		(0x3 << 3)
+#define SLPPIN_NULL_FUN			(0x0 << 3)
+#define SLPPIN_SLP_FUN			(0x1 << 3)
+#define SLPPIN_DN_FUN			(0x2 << 3)
+#define SLPPIN_RST_FUN			(0x3 << 3)
+
+#define RK817_RST_FUNC_MSK		(0x3 << 6)
+#define RK817_RST_FUNC_SFT		(6)
+#define RK817_RST_FUNC_CNT		(3)
+#define RK817_RST_FUNC_DEV		(0) /* reset the dev */
+#define RK817_RST_FUNC_REG		(0x1 << 6) /* reset the reg only */
+
+#define RK817_SLPPOL_MSK		BIT(5)
+#define RK817_SLPPOL_H			BIT(5)
+#define RK817_SLPPOL_L			(0)
+
+/* gpio&int 0xfe */
+#define RK817_INT_POL_MSK		BIT(1)
+#define RK817_INT_POL_H			BIT(1)
+#define RK817_INT_POL_L			0
+#define RK809_BUCK5_CONFIG(i)		(RK817_BOOST_OTG_CFG + (i) * 1)
 
 enum {
 	BUCK_ILMIN_50MA,
@@ -443,6 +613,8 @@  enum {
 enum {
 	RK805_ID = 0x8050,
 	RK808_ID = 0x0000,
+	RK809_ID = 0x8090,
+	RK817_ID = 0x8170,
 	RK818_ID = 0x8181,
 };