linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/5] support a new type of PMIC,including two chips(rk817 and rk809)
@ 2018-08-24  3:30 Tony Xie
  2018-08-24  3:30 ` [PATCH v3 1/5] mfd: rk808: Add RK817 and RK809 support Tony Xie
                   ` (5 more replies)
  0 siblings, 6 replies; 16+ messages in thread
From: Tony Xie @ 2018-08-24  3:30 UTC (permalink / raw)
  To: heiko
  Cc: broonie, lee.jones, robh+dt, mark.rutland, a.zummo,
	alexandre.belloni, sboyd, linux-clk, linux-rtc, linux-arm-kernel,
	linux-rockchip, devicetree, linux-kernel, chenjh, xsf, zhangqing,
	huangtao, tony.xie

Most of functions and registers of the rk817 and rk808 are the same,
so they can share allmost all codes.

Their specifications are as follows:
  1) The RK809 and RK809 consist of 5 DCDCs, 9 LDOs and have the same registers
     for these components except dcdc5.
  2) The dcdc5 is a boost dcdc for RK817 and is a buck for RK809.
  3) The RK817 has one switch but The Rk809 has two.

Changes in V2:
1. initialize the pm_pwroff_fn to NULL. 
2. use EXPORT_SYMBOL_GPL to export pm_power_off_prepare.
3. change patch 2/3/4/5 subjects. 

Changes in V3:
1. change patch 4 subjects
2. replace pr_ with dev_ for printing in patch 2
3. modify switch1 and switch2 configs in patch 2
4. explain gpio information for rk809 and rk817 in patch 4

Tony Xie (5):
  mfd: rk808: Add RK817 and RK809 support
  regulator: rk808: add RK809 and RK817 support.
  dt-bindings: mfd: rk808: Add binding information for RK809 and RK817.
  rtc: rk808: add RK809 and RK817 support.
  clk: RK808: add RK809 and RK817 support.

 Documentation/devicetree/bindings/mfd/rk808.txt |  56 +++
 drivers/clk/Kconfig                             |   9 +-
 drivers/clk/clk-rk808.c                         |  62 ++-
 drivers/mfd/Kconfig                             |   6 +-
 drivers/mfd/rk808.c                             | 218 +++++++-
 drivers/regulator/Kconfig                       |   4 +-
 drivers/regulator/rk808-regulator.c             | 639 +++++++++++++++++++++++-
 drivers/rtc/Kconfig                             |   4 +-
 drivers/rtc/rtc-rk808.c                         |  68 ++-
 include/linux/mfd/rk808.h                       | 175 +++++++
 kernel/reboot.c                                 |   1 +
 11 files changed, 1209 insertions(+), 33 deletions(-)

-- 
1.9.1



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

* [PATCH v3 1/5] mfd: rk808: Add RK817 and RK809 support
  2018-08-24  3:30 [PATCH v3 0/5] support a new type of PMIC,including two chips(rk817 and rk809) Tony Xie
@ 2018-08-24  3:30 ` Tony Xie
  2018-09-11 11:47   ` Lee Jones
  2018-08-24  3:30 ` [PATCH v3 2/5] regulator: rk808: add RK809 and RK817 support Tony Xie
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 16+ messages in thread
From: Tony Xie @ 2018-08-24  3:30 UTC (permalink / raw)
  To: heiko
  Cc: broonie, lee.jones, robh+dt, mark.rutland, a.zummo,
	alexandre.belloni, sboyd, linux-clk, linux-rtc, linux-arm-kernel,
	linux-rockchip, devicetree, linux-kernel, chenjh, xsf, zhangqing,
	huangtao, tony.xie

    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       | 218 +++++++++++++++++++++++++++++++++++++++++++++-
 include/linux/mfd/rk808.h | 172 ++++++++++++++++++++++++++++++++++++
 kernel/reboot.c           |   1 +
 4 files changed, 391 insertions(+), 6 deletions(-)

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..62e2fe1 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" },
 	{ },
 };
@@ -438,10 +586,11 @@ static int rk808_probe(struct i2c_client *client,
 	struct rk808 *rk808;
 	const struct rk808_reg_data *pre_init_reg;
 	const struct mfd_cell *cells;
-	void (*pm_pwroff_fn)(void);
+	void (*pm_pwroff_fn)(void) = NULL;
 	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,
 };
 
diff --git a/kernel/reboot.c b/kernel/reboot.c
index e4ced88..83810d7 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -49,6 +49,7 @@
  */
 
 void (*pm_power_off_prepare)(void);
+EXPORT_SYMBOL_GPL(pm_power_off_prepare);
 
 /**
  *	emergency_restart - reboot the system
-- 
1.9.1



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

* [PATCH v3 2/5] regulator: rk808: add RK809 and RK817 support.
  2018-08-24  3:30 [PATCH v3 0/5] support a new type of PMIC,including two chips(rk817 and rk809) Tony Xie
  2018-08-24  3:30 ` [PATCH v3 1/5] mfd: rk808: Add RK817 and RK809 support Tony Xie
@ 2018-08-24  3:30 ` Tony Xie
  2018-08-24 12:23   ` Wadim Egorov
  2018-08-24  3:30 ` [PATCH v3 3/5] dt-bindings: mfd: rk808: Add binding information for RK809 and RK817 Tony Xie
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 16+ messages in thread
From: Tony Xie @ 2018-08-24  3:30 UTC (permalink / raw)
  To: heiko
  Cc: broonie, lee.jones, robh+dt, mark.rutland, a.zummo,
	alexandre.belloni, sboyd, linux-clk, linux-rtc, linux-arm-kernel,
	linux-rockchip, devicetree, linux-kernel, chenjh, xsf, zhangqing,
	huangtao, tony.xie

    Add support for the rk809 and rk817 regulator driver.
    Their specifications are as follows:
    1、The RK809 and RK809 consist of 5 DCDCs, 9 LDOs
       and have the same registers for these components except dcdc5.
    2、The dcdc5 is a boost dcdc for RK817 and is a buck for RK809.
    3、The RK817 has one switch but The Rk809 has two.

    The output voltages are configurable and are meant to supply power
    to the main processor and other components.

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

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 5dbccf5..27ff89f 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -716,11 +716,11 @@ config REGULATOR_RC5T583
 	  outputs which can be controlled by i2c communication.
 
 config REGULATOR_RK808
-	tristate "Rockchip RK805/RK808/RK818 Power regulators"
+	tristate "Rockchip RK805/RK808/RK809/RK817/RK818 Power regulators"
 	depends on MFD_RK808
 	help
 	  Select this option to enable the power regulator of ROCKCHIP
-	  PMIC RK805,RK808 and RK818.
+	  PMIC RK805,RK809&RK817,RK808 and RK818.
 	  This driver supports the control of different power rails of device
 	  through regulator interface. The device supports multiple DCDC/LDO
 	  outputs which can be controlled by i2c communication.
diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-regulator.c
index 213b687..4aa2df6 100644
--- a/drivers/regulator/rk808-regulator.c
+++ b/drivers/regulator/rk808-regulator.c
@@ -36,6 +36,12 @@
 #define RK808_BUCK4_VSEL_MASK	0xf
 #define RK808_LDO_VSEL_MASK	0x1f
 
+#define RK809_BUCK5_VSEL_MASK		0x7
+
+#define RK817_LDO_VSEL_MASK		0x7f
+#define RK817_BOOST_VSEL_MASK		0x7
+#define RK817_BUCK_VSEL_MASK		0x7f
+
 #define RK818_BUCK_VSEL_MASK		0x3f
 #define RK818_BUCK4_VSEL_MASK		0x1f
 #define RK818_LDO_VSEL_MASK		0x1f
@@ -65,6 +71,9 @@
 /* max steps for increase voltage of Buck1/2, equal 100mv*/
 #define MAX_STEPS_ONE_TIME 8
 
+#define ENABLE_MASK(id)			(BIT(id) | BIT(4 + (id)))
+#define DISABLE_VAL(id)			(BIT(4 + (id)))
+
 #define RK805_DESC(_id, _match, _supply, _min, _max, _step, _vreg,      \
 	_vmask, _ereg, _emask, _etime)                                  \
 	[_id] = {                                                       \
@@ -86,6 +95,70 @@
 		.ops            = &rk805_reg_ops,                       \
 	}
 
+#define RK817_DESC(_id, _match, _supply, _min, _max, _step, _vreg,	\
+	_vmask, _ereg, _emask, _enval, _disval, _etime)		\
+	{							\
+		.name		= (_match),				\
+		.supply_name	= (_supply),				\
+		.of_match	= of_match_ptr(_match),			\
+		.regulators_node = of_match_ptr("regulators"),		\
+		.type		= REGULATOR_VOLTAGE,			\
+		.id		= (_id),				\
+		.n_voltages	= (((_max) - (_min)) / (_step) + 1),	\
+		.owner		= THIS_MODULE,				\
+		.min_uV		= (_min) * 1000,			\
+		.uV_step	= (_step) * 1000,			\
+		.vsel_reg	= (_vreg),				\
+		.vsel_mask	= (_vmask),				\
+		.enable_reg	= (_ereg),				\
+		.enable_mask	= (_emask),				\
+		.enable_val     = (_enval),				\
+		.disable_val     = (_disval),				\
+		.enable_time	= (_etime),				\
+		.ops		= &rk817_reg_ops,			\
+	}
+
+#define RK817_BOOST_DESC(_id, _match, _supply, _min, _max, _step, _vreg,\
+	_vmask, _ereg, _emask, _enval, _disval, _etime, m_drop)		\
+	{							\
+		.name		= (_match),				\
+		.supply_name	= (_supply),				\
+		.of_match	= of_match_ptr(_match),			\
+		.regulators_node = of_match_ptr("regulators"),		\
+		.type		= REGULATOR_VOLTAGE,			\
+		.id		= (_id),				\
+		.n_voltages	= (((_max) - (_min)) / (_step) + 1),	\
+		.owner		= THIS_MODULE,				\
+		.min_uV		= (_min) * 1000,			\
+		.uV_step	= (_step) * 1000,			\
+		.vsel_reg	= (_vreg),				\
+		.vsel_mask	= (_vmask),				\
+		.enable_reg	= (_ereg),				\
+		.enable_mask	= (_emask),				\
+		.enable_val     = (_enval),				\
+		.disable_val     = (_disval),				\
+		.enable_time	= (_etime),				\
+		.min_dropout_uV = (m_drop) * 1000,			\
+		.ops		= &rk817_boost_ops,			\
+	}
+
+#define RK817_DESC_SWITCH(_id, _match, _supply, _ereg, _emask,\
+	_enval, _disval)		\
+	{							\
+		.name		= (_match),				\
+		.supply_name	= (_supply),				\
+		.of_match	= of_match_ptr(_match),			\
+		.regulators_node = of_match_ptr("regulators"),		\
+		.type		= REGULATOR_VOLTAGE,			\
+		.id		= (_id),				\
+		.enable_reg	= (_ereg),				\
+		.enable_mask	= (_emask),				\
+		.enable_val     = (_enval),				\
+		.disable_val     = (_disval),				\
+		.owner		= THIS_MODULE,				\
+		.ops		= &rk817_switch_ops			\
+	}
+
 #define RK8XX_DESC(_id, _match, _supply, _min, _max, _step, _vreg,	\
 	_vmask, _ereg, _emask, _etime)					\
 	[_id] = {							\
@@ -121,7 +194,6 @@
 		.ops		= &rk808_switch_ops			\
 	}
 
-
 struct rk808_regulator_data {
 	struct gpio_desc *dvs_gpio[2];
 };
@@ -138,6 +210,51 @@ struct rk808_regulator_data {
 	REGULATOR_LINEAR_RANGE(2500000, 15, 15, 0),
 };
 
+#define RK809_BUCK5_SEL_CNT		(8)
+
+static const struct regulator_linear_range rk809_buck5_voltage_ranges[] = {
+	REGULATOR_LINEAR_RANGE(1500000, 0, 0, 0),
+	REGULATOR_LINEAR_RANGE(1800000, 1, 3, 200000),
+	REGULATOR_LINEAR_RANGE(2800000, 4, 5, 200000),
+	REGULATOR_LINEAR_RANGE(3300000, 6, 7, 300000),
+};
+
+#define RK817_BUCK1_MIN0 500000
+#define RK817_BUCK1_MAX0 1500000
+
+#define RK817_BUCK1_MIN1 1600000
+#define RK817_BUCK1_MAX1 2400000
+
+#define RK817_BUCK3_MAX1 3400000
+
+#define RK817_BUCK1_STP0 12500
+#define RK817_BUCK1_STP1 100000
+
+#define RK817_BUCK1_SEL0 ((RK817_BUCK1_MAX0 - RK817_BUCK1_MIN0) /\
+						  RK817_BUCK1_STP0)
+#define RK817_BUCK1_SEL1 ((RK817_BUCK1_MAX1 - RK817_BUCK1_MIN1) /\
+						  RK817_BUCK1_STP1)
+
+#define RK817_BUCK3_SEL1 ((RK817_BUCK3_MAX1 - RK817_BUCK1_MIN1) /\
+						  RK817_BUCK1_STP1)
+
+#define RK817_BUCK1_SEL_CNT (RK817_BUCK1_SEL0 + RK817_BUCK1_SEL1 + 1)
+#define RK817_BUCK3_SEL_CNT (RK817_BUCK1_SEL0 + RK817_BUCK3_SEL1 + 1)
+
+static const struct regulator_linear_range rk817_buck1_voltage_ranges[] = {
+	REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN0, 0,
+			       RK817_BUCK1_SEL0, RK817_BUCK1_STP0),
+	REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN1, RK817_BUCK1_SEL0 + 1,
+			       RK817_BUCK1_SEL_CNT, RK817_BUCK1_STP1),
+};
+
+static const struct regulator_linear_range rk817_buck3_voltage_ranges[] = {
+	REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN0, 0,
+			       RK817_BUCK1_SEL0, RK817_BUCK1_STP0),
+	REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN1, RK817_BUCK1_SEL0 + 1,
+			       RK817_BUCK3_SEL_CNT, RK817_BUCK1_STP1),
+};
+
 static int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev *rdev)
 {
 	struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev);
@@ -281,14 +398,45 @@ static int rk808_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
 	case 6001 ... 10000:
 		break;
 	default:
-		pr_warn("%s ramp_delay: %d not supported, setting 10000\n",
-			rdev->desc->name, ramp_delay);
+		dev_warn(&rdev->dev,
+			 "%s ramp_delay: %d not supported, setting 10000\n",
+			 rdev->desc->name, ramp_delay);
 	}
 
 	return regmap_update_bits(rdev->regmap, reg,
 				  RK808_RAMP_RATE_MASK, ramp_value);
 }
 
+/*
+ * RK817 RK809
+ */
+static int rk817_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
+{
+	unsigned int ramp_value = RK817_RAMP_RATE_25MV_PER_US;
+	unsigned int reg = RK817_BUCK_CONFIG_REG(rdev_get_id(rdev));
+
+	switch (ramp_delay) {
+	case 0 ... 3000:
+		ramp_value = RK817_RAMP_RATE_3MV_PER_US;
+		break;
+	case 3001 ... 6300:
+		ramp_value = RK817_RAMP_RATE_6_3MV_PER_US;
+		break;
+	case 6301 ... 12500:
+		ramp_value = RK817_RAMP_RATE_12_5MV_PER_US;
+		break;
+	case 12501 ... 25000:
+		break;
+	default:
+		dev_warn(&rdev->dev,
+			 "%s ramp_delay: %d not supported, setting 10000\n",
+			 rdev->desc->name, ramp_delay);
+	}
+
+	return regmap_update_bits(rdev->regmap, reg,
+				  RK817_RAMP_RATE_MASK, ramp_value);
+}
+
 static int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv)
 {
 	unsigned int reg;
@@ -304,6 +452,29 @@ static int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv)
 				  sel);
 }
 
+static int rk817_check_suspend_voltage(int id)
+{
+	if (id >= RK817_ID_DCDC1 && id <= RK817_ID_LDO9)
+		return 0;
+	return -1;
+}
+
+static int rk817_set_suspend_voltage(struct regulator_dev *rdev, int uv)
+{
+	unsigned int reg;
+	int id = rdev_get_id(rdev);
+	int sel = regulator_map_voltage_linear(rdev, uv, uv);
+	/* only ldo1~ldo9 */
+	if (sel < 0 || rk817_check_suspend_voltage(id))
+		return -EINVAL;
+
+	reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
+
+	return regmap_update_bits(rdev->regmap, reg,
+				  rdev->desc->vsel_mask,
+				  sel);
+}
+
 static int rk808_set_suspend_voltage_range(struct regulator_dev *rdev, int uv)
 {
 	unsigned int reg;
@@ -363,6 +534,129 @@ static int rk808_set_suspend_disable(struct regulator_dev *rdev)
 				  rdev->desc->enable_mask);
 }
 
+static int rk817_set_suspend_enable_ctrl(struct regulator_dev *rdev,
+					 unsigned int en)
+{
+	unsigned int reg;
+	int id = rdev_get_id(rdev);
+	unsigned int id_slp, msk, val;
+
+	if (id >= RK817_ID_DCDC1 && id <= RK817_ID_DCDC4)
+		id_slp = id;
+	else if (id >= RK817_ID_LDO1 && id <= RK817_ID_LDO8)
+		id_slp = 8 + (id - RK817_ID_LDO1);
+	else if (id >= RK817_ID_LDO9 && id <= RK809_ID_SW2)
+		id_slp = 4 + (id - RK817_ID_LDO9);
+	else
+		return -EINVAL;
+
+	reg = RK817_POWER_SLP_EN_REG(id_slp / 8);
+
+	msk = BIT(id_slp % 8);
+	if (en)
+		val = msk;
+	else
+		val = 0;
+
+	return regmap_update_bits(rdev->regmap, reg, msk, val);
+}
+
+static int rk817_set_suspend_enable(struct regulator_dev *rdev)
+{
+	return rk817_set_suspend_enable_ctrl(rdev, 1);
+}
+
+static int rk817_set_suspend_disable(struct regulator_dev *rdev)
+{
+	return rk817_set_suspend_enable_ctrl(rdev, 0);
+}
+
+static int rk8xx_set_suspend_mode(struct regulator_dev *rdev, unsigned int mode)
+{
+	unsigned int reg;
+
+	reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
+
+	switch (mode) {
+	case REGULATOR_MODE_FAST:
+		return regmap_update_bits(rdev->regmap, reg,
+					  PWM_MODE_MSK, FPWM_MODE);
+	case REGULATOR_MODE_NORMAL:
+		return regmap_update_bits(rdev->regmap, reg,
+					  PWM_MODE_MSK, AUTO_PWM_MODE);
+	default:
+		dev_err(&rdev->dev, "do not support this mode\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int rk8xx_set_mode(struct regulator_dev *rdev, unsigned int mode)
+{
+	switch (mode) {
+	case REGULATOR_MODE_FAST:
+		return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
+					  PWM_MODE_MSK, FPWM_MODE);
+	case REGULATOR_MODE_NORMAL:
+		return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
+					  PWM_MODE_MSK, AUTO_PWM_MODE);
+	default:
+		dev_err(&rdev->dev, "do not support this mode\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static unsigned int rk8xx_get_mode(struct regulator_dev *rdev)
+{
+	unsigned int val;
+	int err;
+
+	err = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
+	if (err)
+		return err;
+
+	if (val & FPWM_MODE)
+		return REGULATOR_MODE_FAST;
+	else
+		return REGULATOR_MODE_NORMAL;
+}
+
+static int rk8xx_is_enabled_wmsk_regmap(struct regulator_dev *rdev)
+{
+	unsigned int val;
+	int ret;
+
+	ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
+	if (ret != 0)
+		return ret;
+
+	/* add write mask bit */
+	val |= (rdev->desc->enable_mask & 0xf0);
+	val &= rdev->desc->enable_mask;
+
+	if (rdev->desc->enable_is_inverted) {
+		if (rdev->desc->enable_val)
+			return val != rdev->desc->enable_val;
+		return (val == 0);
+	}
+	if (rdev->desc->enable_val)
+		return val == rdev->desc->enable_val;
+	return val != 0;
+}
+
+static unsigned int rk8xx_regulator_of_map_mode(unsigned int mode)
+{
+	if (mode == 1)
+		return REGULATOR_MODE_FAST;
+	if (mode == 2)
+		return REGULATOR_MODE_NORMAL;
+
+	return -EINVAL;
+}
+
 static struct regulator_ops rk805_reg_ops = {
 		.list_voltage           = regulator_list_voltage_linear,
 		.map_voltage            = regulator_map_voltage_linear,
@@ -433,6 +727,71 @@ static int rk808_set_suspend_disable(struct regulator_dev *rdev)
 	.set_suspend_disable	= rk808_set_suspend_disable,
 };
 
+static struct regulator_ops rk809_buck5_ops_range = {
+	.list_voltage		= regulator_list_voltage_linear_range,
+	.map_voltage		= regulator_map_voltage_linear_range,
+	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
+	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
+	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
+	.enable			= regulator_enable_regmap,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= rk8xx_is_enabled_wmsk_regmap,
+	.set_suspend_voltage	= rk808_set_suspend_voltage_range,
+	.set_suspend_enable	= rk817_set_suspend_enable,
+	.set_suspend_disable	= rk817_set_suspend_disable,
+};
+
+static struct regulator_ops rk817_reg_ops = {
+	.list_voltage		= regulator_list_voltage_linear,
+	.map_voltage		= regulator_map_voltage_linear,
+	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
+	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
+	.enable			= regulator_enable_regmap,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= rk8xx_is_enabled_wmsk_regmap,
+	.set_suspend_voltage	= rk817_set_suspend_voltage,
+	.set_suspend_enable	= rk817_set_suspend_enable,
+	.set_suspend_disable	= rk817_set_suspend_disable,
+};
+
+static struct regulator_ops rk817_boost_ops = {
+	.list_voltage		= regulator_list_voltage_linear,
+	.map_voltage		= regulator_map_voltage_linear,
+	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
+	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
+	.enable			= regulator_enable_regmap,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= rk8xx_is_enabled_wmsk_regmap,
+	.set_suspend_enable	= rk817_set_suspend_enable,
+	.set_suspend_disable	= rk817_set_suspend_disable,
+};
+
+static struct regulator_ops rk817_buck_ops_range = {
+	.list_voltage		= regulator_list_voltage_linear_range,
+	.map_voltage		= regulator_map_voltage_linear_range,
+	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
+	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
+	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
+	.enable			= regulator_enable_regmap,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= rk8xx_is_enabled_wmsk_regmap,
+	.set_mode		= rk8xx_set_mode,
+	.get_mode		= rk8xx_get_mode,
+	.set_suspend_mode	= rk8xx_set_suspend_mode,
+	.set_ramp_delay		= rk817_set_ramp_delay,
+	.set_suspend_voltage	= rk808_set_suspend_voltage_range,
+	.set_suspend_enable	= rk817_set_suspend_enable,
+	.set_suspend_disable	= rk817_set_suspend_disable,
+};
+
+static struct regulator_ops rk817_switch_ops = {
+	.enable			= regulator_enable_regmap,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.set_suspend_enable	= rk817_set_suspend_enable,
+	.set_suspend_disable	= rk817_set_suspend_disable,
+};
+
 static const struct regulator_desc rk805_reg[] = {
 	{
 		.name = "DCDC_REG1",
@@ -589,6 +948,271 @@ static int rk808_set_suspend_disable(struct regulator_dev *rdev)
 		RK808_DCDC_EN_REG, BIT(6)),
 };
 
+static const struct regulator_desc rk809_reg[] = {
+	{
+		.name = "DCDC_REG1",
+		.supply_name = "vcc1",
+		.of_match = of_match_ptr("DCDC_REG1"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = RK817_ID_DCDC1,
+		.ops = &rk817_buck_ops_range,
+		.type = REGULATOR_VOLTAGE,
+		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
+		.linear_ranges = rk817_buck1_voltage_ranges,
+		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
+		.vsel_reg = RK817_BUCK1_ON_VSEL_REG,
+		.vsel_mask = RK817_BUCK_VSEL_MASK,
+		.enable_reg = RK817_POWER_EN_REG(0),
+		.enable_mask = ENABLE_MASK(RK817_ID_DCDC1),
+		.enable_val = ENABLE_MASK(RK817_ID_DCDC1),
+		.disable_val = DISABLE_VAL(RK817_ID_DCDC1),
+		.of_map_mode = rk8xx_regulator_of_map_mode,
+		.owner = THIS_MODULE,
+	}, {
+		.name = "DCDC_REG2",
+		.supply_name = "vcc2",
+		.of_match = of_match_ptr("DCDC_REG2"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = RK817_ID_DCDC2,
+		.ops = &rk817_buck_ops_range,
+		.type = REGULATOR_VOLTAGE,
+		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
+		.linear_ranges = rk817_buck1_voltage_ranges,
+		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
+		.vsel_reg = RK817_BUCK2_ON_VSEL_REG,
+		.vsel_mask = RK817_BUCK_VSEL_MASK,
+		.enable_reg = RK817_POWER_EN_REG(0),
+		.enable_mask = ENABLE_MASK(RK817_ID_DCDC2),
+		.enable_val = ENABLE_MASK(RK817_ID_DCDC2),
+		.disable_val = DISABLE_VAL(RK817_ID_DCDC2),
+		.of_map_mode = rk8xx_regulator_of_map_mode,
+		.owner = THIS_MODULE,
+	}, {
+		.name = "DCDC_REG3",
+		.supply_name = "vcc3",
+		.of_match = of_match_ptr("DCDC_REG3"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = RK817_ID_DCDC3,
+		.ops = &rk817_buck_ops_range,
+		.type = REGULATOR_VOLTAGE,
+		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
+		.linear_ranges = rk817_buck1_voltage_ranges,
+		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
+		.vsel_reg = RK817_BUCK3_ON_VSEL_REG,
+		.vsel_mask = RK817_BUCK_VSEL_MASK,
+		.enable_reg = RK817_POWER_EN_REG(0),
+		.enable_mask = ENABLE_MASK(RK817_ID_DCDC3),
+		.enable_val = ENABLE_MASK(RK817_ID_DCDC3),
+		.disable_val = DISABLE_VAL(RK817_ID_DCDC3),
+		.of_map_mode = rk8xx_regulator_of_map_mode,
+		.owner = THIS_MODULE,
+	}, {
+		.name = "DCDC_REG4",
+		.supply_name = "vcc4",
+		.of_match = of_match_ptr("DCDC_REG4"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = RK817_ID_DCDC4,
+		.ops = &rk817_buck_ops_range,
+		.type = REGULATOR_VOLTAGE,
+		.n_voltages = RK817_BUCK3_SEL_CNT + 1,
+		.linear_ranges = rk817_buck3_voltage_ranges,
+		.n_linear_ranges = ARRAY_SIZE(rk817_buck3_voltage_ranges),
+		.vsel_reg = RK817_BUCK4_ON_VSEL_REG,
+		.vsel_mask = RK817_BUCK_VSEL_MASK,
+		.enable_reg = RK817_POWER_EN_REG(0),
+		.enable_mask = ENABLE_MASK(RK817_ID_DCDC4),
+		.enable_val = ENABLE_MASK(RK817_ID_DCDC4),
+		.disable_val = DISABLE_VAL(RK817_ID_DCDC4),
+		.of_map_mode = rk8xx_regulator_of_map_mode,
+		.owner = THIS_MODULE,
+	},
+	{
+		.name = "DCDC_REG5",
+		.supply_name = "vcc9",
+		.of_match = of_match_ptr("DCDC_REG5"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = RK809_ID_DCDC5,
+		.ops = &rk809_buck5_ops_range,
+		.type = REGULATOR_VOLTAGE,
+		.n_voltages = RK809_BUCK5_SEL_CNT,
+		.linear_ranges = rk809_buck5_voltage_ranges,
+		.n_linear_ranges = ARRAY_SIZE(rk809_buck5_voltage_ranges),
+		.vsel_reg = RK809_BUCK5_CONFIG(0),
+		.vsel_mask = RK809_BUCK5_VSEL_MASK,
+		.enable_reg = RK817_POWER_EN_REG(3),
+		.enable_mask = ENABLE_MASK(1),
+		.enable_val = ENABLE_MASK(1),
+		.disable_val = DISABLE_VAL(1),
+		.of_map_mode = rk8xx_regulator_of_map_mode,
+		.owner = THIS_MODULE,
+	},
+	RK817_DESC(RK817_ID_LDO1, "LDO_REG1", "vcc5", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(0), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(1), ENABLE_MASK(0), ENABLE_MASK(0),
+		   DISABLE_VAL(0), 400),
+	RK817_DESC(RK817_ID_LDO2, "LDO_REG2", "vcc5", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(1), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(1), ENABLE_MASK(1), ENABLE_MASK(1),
+		   DISABLE_VAL(1), 400),
+	RK817_DESC(RK817_ID_LDO3, "LDO_REG3", "vcc5", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(2), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(1), ENABLE_MASK(2), ENABLE_MASK(2),
+		   DISABLE_VAL(2), 400),
+	RK817_DESC(RK817_ID_LDO4, "LDO_REG4", "vcc6", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(3), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(1), ENABLE_MASK(3), ENABLE_MASK(3),
+		   DISABLE_VAL(3), 400),
+	RK817_DESC(RK817_ID_LDO5, "LDO_REG5", "vcc6", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(4), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(2), ENABLE_MASK(0), ENABLE_MASK(0),
+		   DISABLE_VAL(0), 400),
+	RK817_DESC(RK817_ID_LDO6, "LDO_REG6", "vcc6", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(5), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(2), ENABLE_MASK(1), ENABLE_MASK(1),
+		   DISABLE_VAL(1), 400),
+	RK817_DESC(RK817_ID_LDO7, "LDO_REG7", "vcc7", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(6), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(2), ENABLE_MASK(2), ENABLE_MASK(2),
+		   DISABLE_VAL(2), 400),
+	RK817_DESC(RK817_ID_LDO8, "LDO_REG8", "vcc7", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(7), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(2), ENABLE_MASK(3), ENABLE_MASK(3),
+		   DISABLE_VAL(3), 400),
+	RK817_DESC(RK817_ID_LDO9, "LDO_REG9", "vcc7", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(8), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(3), ENABLE_MASK(0), ENABLE_MASK(0),
+		   DISABLE_VAL(0), 400),
+	RK817_DESC_SWITCH(RK809_ID_SW1, "SWITCH_REG1", "vcc9",
+			  RK817_POWER_EN_REG(3), ENABLE_MASK(2),
+			  ENABLE_MASK(2), DISABLE_VAL(2)),
+	RK817_DESC_SWITCH(RK809_ID_SW2, "SWITCH_REG2", "vcc8",
+			  RK817_POWER_EN_REG(3), ENABLE_MASK(3),
+			  ENABLE_MASK(3), DISABLE_VAL(3)),
+};
+
+static const struct regulator_desc rk817_reg[] = {
+	{
+		.name = "DCDC_REG1",
+		.supply_name = "vcc1",
+		.of_match = of_match_ptr("DCDC_REG1"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = RK817_ID_DCDC1,
+		.ops = &rk817_buck_ops_range,
+		.type = REGULATOR_VOLTAGE,
+		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
+		.linear_ranges = rk817_buck1_voltage_ranges,
+		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
+		.vsel_reg = RK817_BUCK1_ON_VSEL_REG,
+		.vsel_mask = RK817_BUCK_VSEL_MASK,
+		.enable_reg = RK817_POWER_EN_REG(0),
+		.enable_mask = ENABLE_MASK(RK817_ID_DCDC1),
+		.enable_val = ENABLE_MASK(RK817_ID_DCDC1),
+		.disable_val = DISABLE_VAL(RK817_ID_DCDC1),
+		.of_map_mode = rk8xx_regulator_of_map_mode,
+		.owner = THIS_MODULE,
+	}, {
+		.name = "DCDC_REG2",
+		.supply_name = "vcc2",
+		.of_match = of_match_ptr("DCDC_REG2"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = RK817_ID_DCDC2,
+		.ops = &rk817_buck_ops_range,
+		.type = REGULATOR_VOLTAGE,
+		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
+		.linear_ranges = rk817_buck1_voltage_ranges,
+		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
+		.vsel_reg = RK817_BUCK2_ON_VSEL_REG,
+		.vsel_mask = RK817_BUCK_VSEL_MASK,
+		.enable_reg = RK817_POWER_EN_REG(0),
+		.enable_mask = ENABLE_MASK(RK817_ID_DCDC2),
+		.enable_val = ENABLE_MASK(RK817_ID_DCDC2),
+		.disable_val = DISABLE_VAL(RK817_ID_DCDC2),
+		.of_map_mode = rk8xx_regulator_of_map_mode,
+		.owner = THIS_MODULE,
+	}, {
+		.name = "DCDC_REG3",
+		.supply_name = "vcc3",
+		.of_match = of_match_ptr("DCDC_REG3"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = RK817_ID_DCDC3,
+		.ops = &rk817_buck_ops_range,
+		.type = REGULATOR_VOLTAGE,
+		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
+		.linear_ranges = rk817_buck1_voltage_ranges,
+		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
+		.vsel_reg = RK817_BUCK3_ON_VSEL_REG,
+		.vsel_mask = RK817_BUCK_VSEL_MASK,
+		.enable_reg = RK817_POWER_EN_REG(0),
+		.enable_mask = ENABLE_MASK(RK817_ID_DCDC3),
+		.enable_val = ENABLE_MASK(RK817_ID_DCDC3),
+		.disable_val = DISABLE_VAL(RK817_ID_DCDC3),
+		.of_map_mode = rk8xx_regulator_of_map_mode,
+		.owner = THIS_MODULE,
+	}, {
+		.name = "DCDC_REG4",
+		.supply_name = "vcc4",
+		.of_match = of_match_ptr("DCDC_REG4"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = RK817_ID_DCDC4,
+		.ops = &rk817_buck_ops_range,
+		.type = REGULATOR_VOLTAGE,
+		.n_voltages = RK817_BUCK3_SEL_CNT + 1,
+		.linear_ranges = rk817_buck3_voltage_ranges,
+		.n_linear_ranges = ARRAY_SIZE(rk817_buck3_voltage_ranges),
+		.vsel_reg = RK817_BUCK4_ON_VSEL_REG,
+		.vsel_mask = RK817_BUCK_VSEL_MASK,
+		.enable_reg = RK817_POWER_EN_REG(0),
+		.enable_mask = ENABLE_MASK(RK817_ID_DCDC4),
+		.enable_val = ENABLE_MASK(RK817_ID_DCDC4),
+		.disable_val = DISABLE_VAL(RK817_ID_DCDC4),
+		.of_map_mode = rk8xx_regulator_of_map_mode,
+		.owner = THIS_MODULE,
+	},
+	RK817_DESC(RK817_ID_LDO1, "LDO_REG1", "vcc5", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(0), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(1), ENABLE_MASK(0), ENABLE_MASK(0),
+		   DISABLE_VAL(0), 400),
+	RK817_DESC(RK817_ID_LDO2, "LDO_REG2", "vcc5", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(1), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(1), ENABLE_MASK(1), ENABLE_MASK(1),
+		   DISABLE_VAL(1), 400),
+	RK817_DESC(RK817_ID_LDO3, "LDO_REG3", "vcc5", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(2), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(1), ENABLE_MASK(2), ENABLE_MASK(2),
+		   DISABLE_VAL(2), 400),
+	RK817_DESC(RK817_ID_LDO4, "LDO_REG4", "vcc6", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(3), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(1), ENABLE_MASK(3), ENABLE_MASK(3),
+		   DISABLE_VAL(3), 400),
+	RK817_DESC(RK817_ID_LDO5, "LDO_REG5", "vcc6", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(4), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(2), ENABLE_MASK(0), ENABLE_MASK(0),
+		   DISABLE_VAL(0), 400),
+	RK817_DESC(RK817_ID_LDO6, "LDO_REG6", "vcc6", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(5), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(2), ENABLE_MASK(1), ENABLE_MASK(1),
+		   DISABLE_VAL(1), 400),
+	RK817_DESC(RK817_ID_LDO7, "LDO_REG7", "vcc7", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(6), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(2), ENABLE_MASK(2), ENABLE_MASK(2),
+		   DISABLE_VAL(2), 400),
+	RK817_DESC(RK817_ID_LDO8, "LDO_REG8", "vcc7", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(7), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(2), ENABLE_MASK(3), ENABLE_MASK(3),
+		   DISABLE_VAL(3), 400),
+	RK817_DESC(RK817_ID_LDO9, "LDO_REG9", "vcc7", 600, 3400, 25,
+		   RK817_LDO_ON_VSEL_REG(8), RK817_LDO_VSEL_MASK,
+		   RK817_POWER_EN_REG(3), ENABLE_MASK(0), ENABLE_MASK(0),
+		   DISABLE_VAL(0), 400),
+	RK817_BOOST_DESC(RK817_ID_BOOST, "BOOST", "vcc8", 4700, 5400, 100,
+			 RK817_BOOST_OTG_CFG, RK817_BOOST_VSEL_MASK,
+			 RK817_POWER_EN_REG(3), ENABLE_MASK(1), ENABLE_MASK(1),
+		   DISABLE_VAL(1), 400, 3500 - 5400),
+	RK817_DESC_SWITCH(RK817_ID_BOOST_OTG_SW, "OTG_SWITCH", "vcc9",
+			  RK817_POWER_EN_REG(3), ENABLE_MASK(2),
+			  ENABLE_MASK(2), DISABLE_VAL(2)),
+};
+
 static const struct regulator_desc rk818_reg[] = {
 	{
 		.name = "DCDC_REG1",
@@ -759,6 +1383,14 @@ static int rk808_regulator_probe(struct platform_device *pdev)
 		regulators = rk808_reg;
 		nregulators = RK808_NUM_REGULATORS;
 		break;
+	case RK809_ID:
+		regulators = rk809_reg;
+		nregulators = RK809_NUM_REGULATORS;
+		break;
+	case RK817_ID:
+		regulators = rk817_reg;
+		nregulators = RK817_NUM_REGULATORS;
+		break;
 	case RK818_ID:
 		regulators = rk818_reg;
 		nregulators = RK818_NUM_REGULATORS;
@@ -797,6 +1429,7 @@ static int rk808_regulator_probe(struct platform_device *pdev)
 module_platform_driver(rk808_regulator_driver);
 
 MODULE_DESCRIPTION("regulator driver for the RK808/RK818 series PMICs");
+MODULE_AUTHOR("Tony xie <tony.xie@rock-chips.com>");
 MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
 MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>");
 MODULE_AUTHOR("Wadim Egorov <w.egorov@phytec.de>");
diff --git a/include/linux/mfd/rk808.h b/include/linux/mfd/rk808.h
index b973b0a..b4ce2373 100644
--- a/include/linux/mfd/rk808.h
+++ b/include/linux/mfd/rk808.h
@@ -396,7 +396,10 @@ enum rk805_reg {
 #define SHUTDOWN_FUN			(0x2 << 2)
 #define SLEEP_FUN			(0x1 << 2)
 #define RK8XX_ID_MSK			0xfff0
+#define PWM_MODE_MSK			BIT(7)
 #define FPWM_MODE			BIT(7)
+#define AUTO_PWM_MODE			0
+
 enum rk817_reg_id {
 	RK817_ID_DCDC1 = 0,
 	RK817_ID_DCDC2,
-- 
1.9.1



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

* [PATCH v3 3/5] dt-bindings: mfd: rk808: Add binding information for RK809 and RK817.
  2018-08-24  3:30 [PATCH v3 0/5] support a new type of PMIC,including two chips(rk817 and rk809) Tony Xie
  2018-08-24  3:30 ` [PATCH v3 1/5] mfd: rk808: Add RK817 and RK809 support Tony Xie
  2018-08-24  3:30 ` [PATCH v3 2/5] regulator: rk808: add RK809 and RK817 support Tony Xie
@ 2018-08-24  3:30 ` Tony Xie
  2018-08-28 22:40   ` Rob Herring
  2018-09-11 12:37   ` Lee Jones
  2018-08-24  3:30 ` [PATCH v3 4/5] rtc: rk808: add RK809 and RK817 support Tony Xie
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 16+ messages in thread
From: Tony Xie @ 2018-08-24  3:30 UTC (permalink / raw)
  To: heiko
  Cc: broonie, lee.jones, robh+dt, mark.rutland, a.zummo,
	alexandre.belloni, sboyd, linux-clk, linux-rtc, linux-arm-kernel,
	linux-rockchip, devicetree, linux-kernel, chenjh, xsf, zhangqing,
	huangtao, tony.xie

Add device tree bindings documentation for Rockchip's RK809 & RK817 PMIC.

Signed-off-by: Tony Xie <tony.xie@rock-chips.com>
---
 Documentation/devicetree/bindings/mfd/rk808.txt | 56 +++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/rk808.txt b/Documentation/devicetree/bindings/mfd/rk808.txt
index 91b6522..c025a99 100644
--- a/Documentation/devicetree/bindings/mfd/rk808.txt
+++ b/Documentation/devicetree/bindings/mfd/rk808.txt
@@ -3,11 +3,15 @@ RK8XX Power Management Integrated Circuit
 The rk8xx family current members:
 rk805
 rk808
+rk809
+rk817
 rk818
 
 Required properties:
 - compatible: "rockchip,rk805"
 - compatible: "rockchip,rk808"
+- compatible: "rockchip,rk809"
+- compatible: "rockchip,rk817"
 - compatible: "rockchip,rk818"
 - reg: I2C slave address
 - interrupt-parent: The parent interrupt controller.
@@ -46,6 +50,28 @@ Optional RK808 properties:
   the gpio controller. If DVS GPIOs aren't present, voltage changes will happen
   very quickly with no slow ramp time.
 
+Optional RK809 properties:
+- vcc1-supply:  The input supply for DCDC_REG1
+- vcc2-supply:  The input supply for DCDC_REG2
+- vcc3-supply:  The input supply for DCDC_REG3
+- vcc4-supply:  The input supply for DCDC_REG4
+- vcc5-supply:  The input supply for LDO_REG1, LDO_REG2, LDO_REG3
+- vcc6-supply:  The input supply for LDO_REG4, LDO_REG5, LDO_REG6
+- vcc7-supply:  The input supply for LDO_REG7, LDO_REG8, LDO_REG9
+- vcc8-supply:  The input supply for SWITCH_REG1
+- vcc9-supply:  The input supply for DCDC_REG5, SWITCH_REG2
+
+Optional RK817 properties:
+- vcc1-supply:  The input supply for DCDC_REG1
+- vcc2-supply:  The input supply for DCDC_REG2
+- vcc3-supply:  The input supply for DCDC_REG3
+- vcc4-supply:  The input supply for DCDC_REG4
+- vcc5-supply:  The input supply for LDO_REG1, LDO_REG2, LDO_REG3
+- vcc6-supply:  The input supply for LDO_REG4, LDO_REG5, LDO_REG6
+- vcc7-supply:  The input supply for LDO_REG7, LDO_REG8, LDO_REG9
+- vcc8-supply:  The input supply for BOOST
+- vcc9-supply:  The input supply for OTG_SWITCH
+
 Optional RK818 properties:
 - vcc1-supply:  The input supply for DCDC_REG1
 - vcc2-supply:  The input supply for DCDC_REG2
@@ -87,6 +113,28 @@ number as described in RK808 datasheet.
 	- SWITCH_REGn
 		- valid values for n are 1 to 2
 
+Following regulators of the RK809 PMIC block are supported. Note that
+the 'n' in regulator name, as in DCDC_REGn or LDOn, represents the DCDC or LDO
+number as described in RK808 datasheet.
+
+	- DCDC_REGn
+		- valid values for n are 1 to 5.
+	- LDO_REGn
+		- valid values for n are 1 to 9.
+	- SWITCH_REGn
+		- valid values for n are 1 to 2.
+
+Following regulators of the RK817 PMIC block are supported. Note that
+the 'n' in regulator name, as in DCDC_REGn or LDOn, represents the DCDC or LDO
+number as described in RK818 datasheet.
+
+	- DCDC_REGn
+		- valid values for n are 1 to 4.
+	- LDO_REGn
+		- valid values for n are 1 to 9.
+	- BOOST
+	- OTG_SWITCH
+
 Following regulators of the RK818 PMIC block are supported. Note that
 the 'n' in regulator name, as in DCDC_REGn or LDOn, represents the DCDC or LDO
 number as described in RK818 datasheet.
@@ -99,6 +147,14 @@ number as described in RK818 datasheet.
 	- HDMI_SWITCH
 	- OTG_SWITCH
 
+There are three pins needed to config for each of RK809 and RK817,
+named "gpio_ts" "gpio_gt" "gpio_slp".
+	The gpio_gt and gpio_ts pins support the gpio function.
+	The gpio_slp pin is for controlling the pmic states, as below:
+		- reset
+		- power down
+		- sleep
+
 Standard regulator bindings are used inside regulator subnodes. Check
   Documentation/devicetree/bindings/regulator/regulator.txt
 for more details
-- 
1.9.1



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

* [PATCH v3 4/5] rtc: rk808: add RK809 and RK817 support.
  2018-08-24  3:30 [PATCH v3 0/5] support a new type of PMIC,including two chips(rk817 and rk809) Tony Xie
                   ` (2 preceding siblings ...)
  2018-08-24  3:30 ` [PATCH v3 3/5] dt-bindings: mfd: rk808: Add binding information for RK809 and RK817 Tony Xie
@ 2018-08-24  3:30 ` Tony Xie
  2018-08-27 21:14   ` Alexandre Belloni
  2018-08-24  3:35 ` Tony Xie
  2018-08-24  3:36 ` [PATCH v3 5/5] clk: RK808: " Tony Xie
  5 siblings, 1 reply; 16+ messages in thread
From: Tony Xie @ 2018-08-24  3:30 UTC (permalink / raw)
  To: heiko
  Cc: broonie, lee.jones, robh+dt, mark.rutland, a.zummo,
	alexandre.belloni, sboyd, linux-clk, linux-rtc, linux-arm-kernel,
	linux-rockchip, devicetree, linux-kernel, chenjh, xsf, zhangqing,
	huangtao, tony.xie

RK809 and RK817 are power management IC chips for multimedia products.
Most of their functions and registers are same, including the rtc.

Signed-off-by: Tony Xie <tony.xie@rock-chips.com>
---
 drivers/rtc/Kconfig     |  4 +--
 drivers/rtc/rtc-rk808.c | 68 +++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 56 insertions(+), 16 deletions(-)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index a2ba5db..1aaf935 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -371,11 +371,11 @@ config RTC_DRV_MAX77686
 	  will be called rtc-max77686.
 
 config RTC_DRV_RK808
-	tristate "Rockchip RK805/RK808/RK818 RTC"
+	tristate "Rockchip RK805/RK808/RK809/RK817/RK818 RTC"
 	depends on MFD_RK808
 	help
 	  If you say yes here you will get support for the
-	  RTC of RK805, RK808 and RK818 PMIC.
+	  RTC of RK805, RK809 and RK817, RK808 and RK818 PMIC.
 
 	  This driver can also be built as a module. If so, the module
 	  will be called rk808-rtc.
diff --git a/drivers/rtc/rtc-rk808.c b/drivers/rtc/rtc-rk808.c
index 739c0d4..5bacdaf 100644
--- a/drivers/rtc/rtc-rk808.c
+++ b/drivers/rtc/rtc-rk808.c
@@ -50,9 +50,18 @@
 #define NUM_TIME_REGS	(RK808_WEEKS_REG - RK808_SECONDS_REG + 1)
 #define NUM_ALARM_REGS	(RK808_ALARM_YEARS_REG - RK808_ALARM_SECONDS_REG + 1)
 
+struct rk_rtc_compat_reg {
+	unsigned int ctrl_reg;
+	unsigned int status_reg;
+	unsigned int alarm_seconds_reg;
+	unsigned int int_reg;
+	unsigned int seconds_reg;
+};
+
 struct rk808_rtc {
 	struct rk808 *rk808;
 	struct rtc_device *rtc;
+	struct rk_rtc_compat_reg *creg;
 	int irq;
 };
 
@@ -101,7 +110,7 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
 	int ret;
 
 	/* Force an update of the shadowed registers right now */
-	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->ctrl_reg,
 				 BIT_RTC_CTRL_REG_RTC_GET_TIME,
 				 BIT_RTC_CTRL_REG_RTC_GET_TIME);
 	if (ret) {
@@ -115,7 +124,7 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
 	 * 32khz. If we clear the GET_TIME bit here, the time of i2c transfer
 	 * certainly more than 31.25us: 16 * 2.5us at 400kHz bus frequency.
 	 */
-	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->ctrl_reg,
 				 BIT_RTC_CTRL_REG_RTC_GET_TIME,
 				 0);
 	if (ret) {
@@ -123,7 +132,7 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
 		return ret;
 	}
 
-	ret = regmap_bulk_read(rk808->regmap, RK808_SECONDS_REG,
+	ret = regmap_bulk_read(rk808->regmap, rk808_rtc->creg->seconds_reg,
 			       rtc_data, NUM_TIME_REGS);
 	if (ret) {
 		dev_err(dev, "Failed to bulk read rtc_data: %d\n", ret);
@@ -166,7 +175,7 @@ static int rk808_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	rtc_data[6] = bin2bcd(tm->tm_wday);
 
 	/* Stop RTC while updating the RTC registers */
-	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->ctrl_reg,
 				 BIT_RTC_CTRL_REG_STOP_RTC_M,
 				 BIT_RTC_CTRL_REG_STOP_RTC_M);
 	if (ret) {
@@ -174,14 +183,14 @@ static int rk808_rtc_set_time(struct device *dev, struct rtc_time *tm)
 		return ret;
 	}
 
-	ret = regmap_bulk_write(rk808->regmap, RK808_SECONDS_REG,
+	ret = regmap_bulk_write(rk808->regmap, rk808_rtc->creg->seconds_reg,
 				rtc_data, NUM_TIME_REGS);
 	if (ret) {
 		dev_err(dev, "Failed to bull write rtc_data: %d\n", ret);
 		return ret;
 	}
 	/* Start RTC again */
-	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->ctrl_reg,
 				 BIT_RTC_CTRL_REG_STOP_RTC_M, 0);
 	if (ret) {
 		dev_err(dev, "Failed to update RTC control: %d\n", ret);
@@ -199,8 +208,13 @@ static int rk808_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
 	uint32_t int_reg;
 	int ret;
 
-	ret = regmap_bulk_read(rk808->regmap, RK808_ALARM_SECONDS_REG,
+	ret = regmap_bulk_read(rk808->regmap,
+			       rk808_rtc->creg->alarm_seconds_reg,
 			       alrm_data, NUM_ALARM_REGS);
+	if (ret) {
+		dev_err(dev, "Failed to read RTC alarm date REG: %d\n", ret);
+		return ret;
+	}
 
 	alrm->time.tm_sec = bcd2bin(alrm_data[0] & SECONDS_REG_MSK);
 	alrm->time.tm_min = bcd2bin(alrm_data[1] & MINUTES_REG_MAK);
@@ -210,7 +224,7 @@ static int rk808_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
 	alrm->time.tm_year = (bcd2bin(alrm_data[5] & YEARS_REG_MSK)) + 100;
 	rockchip_to_gregorian(&alrm->time);
 
-	ret = regmap_read(rk808->regmap, RK808_RTC_INT_REG, &int_reg);
+	ret = regmap_read(rk808->regmap, rk808_rtc->creg->int_reg, &int_reg);
 	if (ret) {
 		dev_err(dev, "Failed to read RTC INT REG: %d\n", ret);
 		return ret;
@@ -231,7 +245,7 @@ static int rk808_rtc_stop_alarm(struct rk808_rtc *rk808_rtc)
 	struct rk808 *rk808 = rk808_rtc->rk808;
 	int ret;
 
-	ret = regmap_update_bits(rk808->regmap, RK808_RTC_INT_REG,
+	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->int_reg,
 				 BIT_RTC_INTERRUPTS_REG_IT_ALARM_M, 0);
 
 	return ret;
@@ -242,7 +256,7 @@ static int rk808_rtc_start_alarm(struct rk808_rtc *rk808_rtc)
 	struct rk808 *rk808 = rk808_rtc->rk808;
 	int ret;
 
-	ret = regmap_update_bits(rk808->regmap, RK808_RTC_INT_REG,
+	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->int_reg,
 				 BIT_RTC_INTERRUPTS_REG_IT_ALARM_M,
 				 BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
 
@@ -274,7 +288,8 @@ static int rk808_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
 	alrm_data[4] = bin2bcd(alrm->time.tm_mon + 1);
 	alrm_data[5] = bin2bcd(alrm->time.tm_year - 100);
 
-	ret = regmap_bulk_write(rk808->regmap, RK808_ALARM_SECONDS_REG,
+	ret = regmap_bulk_write(rk808->regmap,
+				rk808_rtc->creg->alarm_seconds_reg,
 				alrm_data, NUM_ALARM_REGS);
 	if (ret) {
 		dev_err(dev, "Failed to bulk write: %d\n", ret);
@@ -318,7 +333,7 @@ static irqreturn_t rk808_alarm_irq(int irq, void *data)
 	struct i2c_client *client = rk808->i2c;
 	int ret;
 
-	ret = regmap_write(rk808->regmap, RK808_RTC_STATUS_REG,
+	ret = regmap_write(rk808->regmap, rk808_rtc->creg->status_reg,
 			   RTC_STATUS_MASK);
 	if (ret) {
 		dev_err(&client->dev,
@@ -371,6 +386,22 @@ static int rk808_rtc_resume(struct device *dev)
 static SIMPLE_DEV_PM_OPS(rk808_rtc_pm_ops,
 	rk808_rtc_suspend, rk808_rtc_resume);
 
+static struct rk_rtc_compat_reg rk808_creg = {
+	.ctrl_reg = RK808_RTC_CTRL_REG,
+	.status_reg = RK808_RTC_STATUS_REG,
+	.alarm_seconds_reg = RK808_ALARM_SECONDS_REG,
+	.int_reg = RK808_RTC_INT_REG,
+	.seconds_reg = RK808_SECONDS_REG,
+};
+
+static struct rk_rtc_compat_reg rk817_creg = {
+	.ctrl_reg = RK817_RTC_CTRL_REG,
+	.status_reg = RK817_RTC_STATUS_REG,
+	.alarm_seconds_reg = RK817_ALARM_SECONDS_REG,
+	.int_reg = RK817_RTC_INT_REG,
+	.seconds_reg = RK817_SECONDS_REG,
+};
+
 static int rk808_rtc_probe(struct platform_device *pdev)
 {
 	struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
@@ -381,11 +412,20 @@ static int rk808_rtc_probe(struct platform_device *pdev)
 	if (rk808_rtc == NULL)
 		return -ENOMEM;
 
+	switch (rk808->variant) {
+	case RK809_ID:
+	case RK817_ID:
+		rk808_rtc->creg = &rk817_creg;
+		break;
+	default:
+		rk808_rtc->creg = &rk808_creg;
+		break;
+	}
 	platform_set_drvdata(pdev, rk808_rtc);
 	rk808_rtc->rk808 = rk808;
 
 	/* start rtc running by default, and use shadowed timer. */
-	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->ctrl_reg,
 				 BIT_RTC_CTRL_REG_STOP_RTC_M |
 				 BIT_RTC_CTRL_REG_RTC_READSEL_M,
 				 BIT_RTC_CTRL_REG_RTC_READSEL_M);
@@ -395,7 +435,7 @@ static int rk808_rtc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	ret = regmap_write(rk808->regmap, RK808_RTC_STATUS_REG,
+	ret = regmap_write(rk808->regmap, rk808_rtc->creg->status_reg,
 			   RTC_STATUS_MASK);
 	if (ret) {
 		dev_err(&pdev->dev,
-- 
1.9.1



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

* [PATCH v3 4/5] rtc: rk808: add RK809 and RK817 support.
  2018-08-24  3:30 [PATCH v3 0/5] support a new type of PMIC,including two chips(rk817 and rk809) Tony Xie
                   ` (3 preceding siblings ...)
  2018-08-24  3:30 ` [PATCH v3 4/5] rtc: rk808: add RK809 and RK817 support Tony Xie
@ 2018-08-24  3:35 ` Tony Xie
  2018-08-24  3:36 ` [PATCH v3 5/5] clk: RK808: " Tony Xie
  5 siblings, 0 replies; 16+ messages in thread
From: Tony Xie @ 2018-08-24  3:35 UTC (permalink / raw)
  To: heiko
  Cc: broonie, lee.jones, robh+dt, mark.rutland, a.zummo,
	alexandre.belloni, sboyd, linux-clk, linux-rtc, linux-arm-kernel,
	linux-rockchip, devicetree, linux-kernel, chenjh, xsf, zhangqing,
	huangtao, tony.xie

RK809 and RK817 are power management IC chips for multimedia products.
Most of their functions and registers are same, including the rtc.

Signed-off-by: Tony Xie <tony.xie@rock-chips.com>
---
 drivers/rtc/Kconfig     |  4 +--
 drivers/rtc/rtc-rk808.c | 68 +++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 56 insertions(+), 16 deletions(-)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index a2ba5db..1aaf935 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -371,11 +371,11 @@ config RTC_DRV_MAX77686
 	  will be called rtc-max77686.
 
 config RTC_DRV_RK808
-	tristate "Rockchip RK805/RK808/RK818 RTC"
+	tristate "Rockchip RK805/RK808/RK809/RK817/RK818 RTC"
 	depends on MFD_RK808
 	help
 	  If you say yes here you will get support for the
-	  RTC of RK805, RK808 and RK818 PMIC.
+	  RTC of RK805, RK809 and RK817, RK808 and RK818 PMIC.
 
 	  This driver can also be built as a module. If so, the module
 	  will be called rk808-rtc.
diff --git a/drivers/rtc/rtc-rk808.c b/drivers/rtc/rtc-rk808.c
index 739c0d4..5bacdaf 100644
--- a/drivers/rtc/rtc-rk808.c
+++ b/drivers/rtc/rtc-rk808.c
@@ -50,9 +50,18 @@
 #define NUM_TIME_REGS	(RK808_WEEKS_REG - RK808_SECONDS_REG + 1)
 #define NUM_ALARM_REGS	(RK808_ALARM_YEARS_REG - RK808_ALARM_SECONDS_REG + 1)
 
+struct rk_rtc_compat_reg {
+	unsigned int ctrl_reg;
+	unsigned int status_reg;
+	unsigned int alarm_seconds_reg;
+	unsigned int int_reg;
+	unsigned int seconds_reg;
+};
+
 struct rk808_rtc {
 	struct rk808 *rk808;
 	struct rtc_device *rtc;
+	struct rk_rtc_compat_reg *creg;
 	int irq;
 };
 
@@ -101,7 +110,7 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
 	int ret;
 
 	/* Force an update of the shadowed registers right now */
-	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->ctrl_reg,
 				 BIT_RTC_CTRL_REG_RTC_GET_TIME,
 				 BIT_RTC_CTRL_REG_RTC_GET_TIME);
 	if (ret) {
@@ -115,7 +124,7 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
 	 * 32khz. If we clear the GET_TIME bit here, the time of i2c transfer
 	 * certainly more than 31.25us: 16 * 2.5us at 400kHz bus frequency.
 	 */
-	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->ctrl_reg,
 				 BIT_RTC_CTRL_REG_RTC_GET_TIME,
 				 0);
 	if (ret) {
@@ -123,7 +132,7 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
 		return ret;
 	}
 
-	ret = regmap_bulk_read(rk808->regmap, RK808_SECONDS_REG,
+	ret = regmap_bulk_read(rk808->regmap, rk808_rtc->creg->seconds_reg,
 			       rtc_data, NUM_TIME_REGS);
 	if (ret) {
 		dev_err(dev, "Failed to bulk read rtc_data: %d\n", ret);
@@ -166,7 +175,7 @@ static int rk808_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	rtc_data[6] = bin2bcd(tm->tm_wday);
 
 	/* Stop RTC while updating the RTC registers */
-	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->ctrl_reg,
 				 BIT_RTC_CTRL_REG_STOP_RTC_M,
 				 BIT_RTC_CTRL_REG_STOP_RTC_M);
 	if (ret) {
@@ -174,14 +183,14 @@ static int rk808_rtc_set_time(struct device *dev, struct rtc_time *tm)
 		return ret;
 	}
 
-	ret = regmap_bulk_write(rk808->regmap, RK808_SECONDS_REG,
+	ret = regmap_bulk_write(rk808->regmap, rk808_rtc->creg->seconds_reg,
 				rtc_data, NUM_TIME_REGS);
 	if (ret) {
 		dev_err(dev, "Failed to bull write rtc_data: %d\n", ret);
 		return ret;
 	}
 	/* Start RTC again */
-	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->ctrl_reg,
 				 BIT_RTC_CTRL_REG_STOP_RTC_M, 0);
 	if (ret) {
 		dev_err(dev, "Failed to update RTC control: %d\n", ret);
@@ -199,8 +208,13 @@ static int rk808_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
 	uint32_t int_reg;
 	int ret;
 
-	ret = regmap_bulk_read(rk808->regmap, RK808_ALARM_SECONDS_REG,
+	ret = regmap_bulk_read(rk808->regmap,
+			       rk808_rtc->creg->alarm_seconds_reg,
 			       alrm_data, NUM_ALARM_REGS);
+	if (ret) {
+		dev_err(dev, "Failed to read RTC alarm date REG: %d\n", ret);
+		return ret;
+	}
 
 	alrm->time.tm_sec = bcd2bin(alrm_data[0] & SECONDS_REG_MSK);
 	alrm->time.tm_min = bcd2bin(alrm_data[1] & MINUTES_REG_MAK);
@@ -210,7 +224,7 @@ static int rk808_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
 	alrm->time.tm_year = (bcd2bin(alrm_data[5] & YEARS_REG_MSK)) + 100;
 	rockchip_to_gregorian(&alrm->time);
 
-	ret = regmap_read(rk808->regmap, RK808_RTC_INT_REG, &int_reg);
+	ret = regmap_read(rk808->regmap, rk808_rtc->creg->int_reg, &int_reg);
 	if (ret) {
 		dev_err(dev, "Failed to read RTC INT REG: %d\n", ret);
 		return ret;
@@ -231,7 +245,7 @@ static int rk808_rtc_stop_alarm(struct rk808_rtc *rk808_rtc)
 	struct rk808 *rk808 = rk808_rtc->rk808;
 	int ret;
 
-	ret = regmap_update_bits(rk808->regmap, RK808_RTC_INT_REG,
+	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->int_reg,
 				 BIT_RTC_INTERRUPTS_REG_IT_ALARM_M, 0);
 
 	return ret;
@@ -242,7 +256,7 @@ static int rk808_rtc_start_alarm(struct rk808_rtc *rk808_rtc)
 	struct rk808 *rk808 = rk808_rtc->rk808;
 	int ret;
 
-	ret = regmap_update_bits(rk808->regmap, RK808_RTC_INT_REG,
+	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->int_reg,
 				 BIT_RTC_INTERRUPTS_REG_IT_ALARM_M,
 				 BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
 
@@ -274,7 +288,8 @@ static int rk808_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
 	alrm_data[4] = bin2bcd(alrm->time.tm_mon + 1);
 	alrm_data[5] = bin2bcd(alrm->time.tm_year - 100);
 
-	ret = regmap_bulk_write(rk808->regmap, RK808_ALARM_SECONDS_REG,
+	ret = regmap_bulk_write(rk808->regmap,
+				rk808_rtc->creg->alarm_seconds_reg,
 				alrm_data, NUM_ALARM_REGS);
 	if (ret) {
 		dev_err(dev, "Failed to bulk write: %d\n", ret);
@@ -318,7 +333,7 @@ static irqreturn_t rk808_alarm_irq(int irq, void *data)
 	struct i2c_client *client = rk808->i2c;
 	int ret;
 
-	ret = regmap_write(rk808->regmap, RK808_RTC_STATUS_REG,
+	ret = regmap_write(rk808->regmap, rk808_rtc->creg->status_reg,
 			   RTC_STATUS_MASK);
 	if (ret) {
 		dev_err(&client->dev,
@@ -371,6 +386,22 @@ static int rk808_rtc_resume(struct device *dev)
 static SIMPLE_DEV_PM_OPS(rk808_rtc_pm_ops,
 	rk808_rtc_suspend, rk808_rtc_resume);
 
+static struct rk_rtc_compat_reg rk808_creg = {
+	.ctrl_reg = RK808_RTC_CTRL_REG,
+	.status_reg = RK808_RTC_STATUS_REG,
+	.alarm_seconds_reg = RK808_ALARM_SECONDS_REG,
+	.int_reg = RK808_RTC_INT_REG,
+	.seconds_reg = RK808_SECONDS_REG,
+};
+
+static struct rk_rtc_compat_reg rk817_creg = {
+	.ctrl_reg = RK817_RTC_CTRL_REG,
+	.status_reg = RK817_RTC_STATUS_REG,
+	.alarm_seconds_reg = RK817_ALARM_SECONDS_REG,
+	.int_reg = RK817_RTC_INT_REG,
+	.seconds_reg = RK817_SECONDS_REG,
+};
+
 static int rk808_rtc_probe(struct platform_device *pdev)
 {
 	struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
@@ -381,11 +412,20 @@ static int rk808_rtc_probe(struct platform_device *pdev)
 	if (rk808_rtc == NULL)
 		return -ENOMEM;
 
+	switch (rk808->variant) {
+	case RK809_ID:
+	case RK817_ID:
+		rk808_rtc->creg = &rk817_creg;
+		break;
+	default:
+		rk808_rtc->creg = &rk808_creg;
+		break;
+	}
 	platform_set_drvdata(pdev, rk808_rtc);
 	rk808_rtc->rk808 = rk808;
 
 	/* start rtc running by default, and use shadowed timer. */
-	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
+	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->ctrl_reg,
 				 BIT_RTC_CTRL_REG_STOP_RTC_M |
 				 BIT_RTC_CTRL_REG_RTC_READSEL_M,
 				 BIT_RTC_CTRL_REG_RTC_READSEL_M);
@@ -395,7 +435,7 @@ static int rk808_rtc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	ret = regmap_write(rk808->regmap, RK808_RTC_STATUS_REG,
+	ret = regmap_write(rk808->regmap, rk808_rtc->creg->status_reg,
 			   RTC_STATUS_MASK);
 	if (ret) {
 		dev_err(&pdev->dev,
-- 
1.9.1



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

* [PATCH v3 5/5] clk: RK808: add RK809 and RK817 support.
  2018-08-24  3:30 [PATCH v3 0/5] support a new type of PMIC,including two chips(rk817 and rk809) Tony Xie
                   ` (4 preceding siblings ...)
  2018-08-24  3:35 ` Tony Xie
@ 2018-08-24  3:36 ` Tony Xie
  2018-08-31 17:34   ` Stephen Boyd
  5 siblings, 1 reply; 16+ messages in thread
From: Tony Xie @ 2018-08-24  3:36 UTC (permalink / raw)
  To: heiko
  Cc: broonie, lee.jones, robh+dt, mark.rutland, a.zummo,
	alexandre.belloni, sboyd, linux-clk, linux-rtc, linux-arm-kernel,
	linux-rockchip, devicetree, linux-kernel, chenjh, xsf, zhangqing,
	huangtao, tony.xie

RK809 and RK817 are power management IC chips for multimedia products.
most of their functions and registers are same, including the clkout
funciton.

Signed-off-by: Tony Xie <tony.xie@rock-chips.com>
---
 drivers/clk/Kconfig     |  9 ++++---
 drivers/clk/clk-rk808.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 721572a..92cf5ad 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -46,13 +46,12 @@ config COMMON_CLK_MAX77686
 	  clock.
 
 config COMMON_CLK_RK808
-	tristate "Clock driver for RK805/RK808/RK818"
+	tristate "Clock driver for RK805/RK808/RK809/RK817/RK818"
 	depends on MFD_RK808
 	---help---
-	  This driver supports RK805, RK808 and RK818 crystal oscillator clock. These
-	  multi-function devices have two fixed-rate oscillators,
-	  clocked at 32KHz each. Clkout1 is always on, Clkout2 can off
-	  by control register.
+	  This driver supports RK805, RK809 and RK817, RK808 and RK818 crystal oscillator clock.
+	  These multi-function devices have two fixed-rate oscillators, clocked at 32KHz each.
+	  Clkout1 is always on, Clkout2 can off by control register.
 
 config COMMON_CLK_HI655X
 	tristate "Clock driver for Hi655x" if EXPERT
diff --git a/drivers/clk/clk-rk808.c b/drivers/clk/clk-rk808.c
index 6461f28..c5d3492 100644
--- a/drivers/clk/clk-rk808.c
+++ b/drivers/clk/clk-rk808.c
@@ -96,6 +96,66 @@ static int rk808_clkout2_is_prepared(struct clk_hw *hw)
 	return idx ? &rk808_clkout->clkout2_hw : &rk808_clkout->clkout1_hw;
 }
 
+static int rk817_clkout2_enable(struct clk_hw *hw, bool enable)
+{
+	struct rk808_clkout *rk808_clkout = container_of(hw,
+							 struct rk808_clkout,
+							 clkout2_hw);
+	struct rk808 *rk808 = rk808_clkout->rk808;
+
+	return regmap_update_bits(rk808->regmap, RK817_SYS_CFG(1),
+				  RK817_CLK32KOUT2_EN,
+				  enable ? RK817_CLK32KOUT2_EN : 0);
+}
+
+static int rk817_clkout2_prepare(struct clk_hw *hw)
+{
+	return rk817_clkout2_enable(hw, true);
+}
+
+static void rk817_clkout2_unprepare(struct clk_hw *hw)
+{
+	rk817_clkout2_enable(hw, false);
+}
+
+static int rk817_clkout2_is_prepared(struct clk_hw *hw)
+{
+	struct rk808_clkout *rk808_clkout = container_of(hw,
+							 struct rk808_clkout,
+							 clkout2_hw);
+	struct rk808 *rk808 = rk808_clkout->rk808;
+	unsigned int val;
+
+	int ret = regmap_read(rk808->regmap, RK817_SYS_CFG(1), &val);
+
+	if (ret < 0)
+		return ret;
+
+	return (val & RK817_CLK32KOUT2_EN) ? 1 : 0;
+}
+
+static const struct clk_ops rk817_clkout2_ops = {
+	.prepare = rk817_clkout2_prepare,
+	.unprepare = rk817_clkout2_unprepare,
+	.is_prepared = rk817_clkout2_is_prepared,
+	.recalc_rate = rk808_clkout_recalc_rate,
+};
+
+static const struct clk_ops *rkpmic_get_ops(long variant)
+{
+	switch (variant) {
+	case RK809_ID:
+	case RK817_ID:
+		return &rk817_clkout2_ops;
+	case RK805_ID:
+	case RK808_ID:
+	case RK818_ID:
+		return &rk808_clkout2_ops;
+	}
+
+	return &rk808_clkout2_ops;
+}
+
 static int rk808_clkout_probe(struct platform_device *pdev)
 {
 	struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
@@ -127,7 +187,7 @@ static int rk808_clkout_probe(struct platform_device *pdev)
 		return ret;
 
 	init.name = "rk808-clkout2";
-	init.ops = &rk808_clkout2_ops;
+	init.ops = rkpmic_get_ops(rk808->variant);
 	rk808_clkout->clkout2_hw.init = &init;
 
 	/* optional override of the clockname */
-- 
1.9.1



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

* Re: [PATCH v3 2/5] regulator: rk808: add RK809 and RK817 support.
  2018-08-24  3:30 ` [PATCH v3 2/5] regulator: rk808: add RK809 and RK817 support Tony Xie
@ 2018-08-24 12:23   ` Wadim Egorov
  0 siblings, 0 replies; 16+ messages in thread
From: Wadim Egorov @ 2018-08-24 12:23 UTC (permalink / raw)
  To: Tony Xie, heiko
  Cc: mark.rutland, a.zummo, alexandre.belloni, huangtao, devicetree,
	sboyd, zhangqing, linux-kernel, robh+dt, xsf, linux-rockchip,
	broonie, chenjh, lee.jones, linux-clk, linux-arm-kernel,
	linux-rtc

Hi Tony,

I have a few points regarding the various Rockchip PMIC variants and
it's handling in this driver.

Am 24.08.18 um 05:30 schrieb Tony Xie:
>     Add support for the rk809 and rk817 regulator driver.
>     Their specifications are as follows:
>     1、The RK809 and RK809 consist of 5 DCDCs, 9 LDOs
>        and have the same registers for these components except dcdc5.
>     2、The dcdc5 is a boost dcdc for RK817 and is a buck for RK809.
>     3、The RK817 has one switch but The Rk809 has two.
>
>     The output voltages are configurable and are meant to supply power
>     to the main processor and other components.
>
> Signed-off-by: Tony Xie <tony.xie@rock-chips.com>
> ---
>  drivers/regulator/Kconfig           |   4 +-
>  drivers/regulator/rk808-regulator.c | 639 +++++++++++++++++++++++++++++++++++-
>  include/linux/mfd/rk808.h           |   3 +
>  3 files changed, 641 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
> index 5dbccf5..27ff89f 100644
> --- a/drivers/regulator/Kconfig
> +++ b/drivers/regulator/Kconfig
> @@ -716,11 +716,11 @@ config REGULATOR_RC5T583
>  	  outputs which can be controlled by i2c communication.
>  
>  config REGULATOR_RK808
> -	tristate "Rockchip RK805/RK808/RK818 Power regulators"
> +	tristate "Rockchip RK805/RK808/RK809/RK817/RK818 Power regulators"
>  	depends on MFD_RK808
>  	help
>  	  Select this option to enable the power regulator of ROCKCHIP
> -	  PMIC RK805,RK808 and RK818.
> +	  PMIC RK805,RK809&RK817,RK808 and RK818.
>  	  This driver supports the control of different power rails of device
>  	  through regulator interface. The device supports multiple DCDC/LDO
>  	  outputs which can be controlled by i2c communication.
> diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-regulator.c
> index 213b687..4aa2df6 100644
> --- a/drivers/regulator/rk808-regulator.c
> +++ b/drivers/regulator/rk808-regulator.c
> @@ -36,6 +36,12 @@
>  #define RK808_BUCK4_VSEL_MASK	0xf
>  #define RK808_LDO_VSEL_MASK	0x1f
>  
> +#define RK809_BUCK5_VSEL_MASK		0x7
> +
> +#define RK817_LDO_VSEL_MASK		0x7f
> +#define RK817_BOOST_VSEL_MASK		0x7
> +#define RK817_BUCK_VSEL_MASK		0x7f
> +
>  #define RK818_BUCK_VSEL_MASK		0x3f
>  #define RK818_BUCK4_VSEL_MASK		0x1f
>  #define RK818_LDO_VSEL_MASK		0x1f
> @@ -65,6 +71,9 @@
>  /* max steps for increase voltage of Buck1/2, equal 100mv*/
>  #define MAX_STEPS_ONE_TIME 8
>  
> +#define ENABLE_MASK(id)			(BIT(id) | BIT(4 + (id)))
> +#define DISABLE_VAL(id)			(BIT(4 + (id)))
> +
>  #define RK805_DESC(_id, _match, _supply, _min, _max, _step, _vreg,      \
>  	_vmask, _ereg, _emask, _etime)                                  \
>  	[_id] = {                                                       \
> @@ -86,6 +95,70 @@
>  		.ops            = &rk805_reg_ops,                       \
>  	}
>  
> +#define RK817_DESC(_id, _match, _supply, _min, _max, _step, _vreg,	\
> +	_vmask, _ereg, _emask, _enval, _disval, _etime)		\
> +	{							\
> +		.name		= (_match),				\
> +		.supply_name	= (_supply),				\
> +		.of_match	= of_match_ptr(_match),			\
> +		.regulators_node = of_match_ptr("regulators"),		\
> +		.type		= REGULATOR_VOLTAGE,			\
> +		.id		= (_id),				\
> +		.n_voltages	= (((_max) - (_min)) / (_step) + 1),	\
> +		.owner		= THIS_MODULE,				\
> +		.min_uV		= (_min) * 1000,			\
> +		.uV_step	= (_step) * 1000,			\
> +		.vsel_reg	= (_vreg),				\
> +		.vsel_mask	= (_vmask),				\
> +		.enable_reg	= (_ereg),				\
> +		.enable_mask	= (_emask),				\
> +		.enable_val     = (_enval),				\
> +		.disable_val     = (_disval),				\
> +		.enable_time	= (_etime),				\
> +		.ops		= &rk817_reg_ops,			\
> +	}

There is already a RK805_DESC and RK8XX_DESC which looking very similar.
So instead of creating a new RK817_DESC, you can also reuse the
RK8XX_DESC by extending it with a an ops parameter. I think you can
refactor the RK8XX_DESC in a way it will be usable for most of your PMICs.
It also looks like you can remove the _enval and _disval parameters
since _enval and _emask is always the same.


> +
> +#define RK817_BOOST_DESC(_id, _match, _supply, _min, _max, _step, _vreg,\
> +	_vmask, _ereg, _emask, _enval, _disval, _etime, m_drop)		\
> +	{							\
> +		.name		= (_match),				\
> +		.supply_name	= (_supply),				\
> +		.of_match	= of_match_ptr(_match),			\
> +		.regulators_node = of_match_ptr("regulators"),		\
> +		.type		= REGULATOR_VOLTAGE,			\
> +		.id		= (_id),				\
> +		.n_voltages	= (((_max) - (_min)) / (_step) + 1),	\
> +		.owner		= THIS_MODULE,				\
> +		.min_uV		= (_min) * 1000,			\
> +		.uV_step	= (_step) * 1000,			\
> +		.vsel_reg	= (_vreg),				\
> +		.vsel_mask	= (_vmask),				\
> +		.enable_reg	= (_ereg),				\
> +		.enable_mask	= (_emask),				\
> +		.enable_val     = (_enval),				\
> +		.disable_val     = (_disval),				\
> +		.enable_time	= (_etime),				\
> +		.min_dropout_uV = (m_drop) * 1000,			\
> +		.ops		= &rk817_boost_ops,			\
> +	}
> +
> +#define RK817_DESC_SWITCH(_id, _match, _supply, _ereg, _emask,\
> +	_enval, _disval)		\
> +	{							\
> +		.name		= (_match),				\
> +		.supply_name	= (_supply),				\
> +		.of_match	= of_match_ptr(_match),			\
> +		.regulators_node = of_match_ptr("regulators"),		\
> +		.type		= REGULATOR_VOLTAGE,			\
> +		.id		= (_id),				\
> +		.enable_reg	= (_ereg),				\
> +		.enable_mask	= (_emask),				\
> +		.enable_val     = (_enval),				\
> +		.disable_val     = (_disval),				\
> +		.owner		= THIS_MODULE,				\
> +		.ops		= &rk817_switch_ops			\
> +	}

Same thing applies to the RK817_DESC_SWITCH.

Regards,
Wadim


> +
>  #define RK8XX_DESC(_id, _match, _supply, _min, _max, _step, _vreg,	\
>  	_vmask, _ereg, _emask, _etime)					\
>  	[_id] = {							\
> @@ -121,7 +194,6 @@
>  		.ops		= &rk808_switch_ops			\
>  	}
>  
> -
>  struct rk808_regulator_data {
>  	struct gpio_desc *dvs_gpio[2];
>  };
> @@ -138,6 +210,51 @@ struct rk808_regulator_data {
>  	REGULATOR_LINEAR_RANGE(2500000, 15, 15, 0),
>  };
>  
> +#define RK809_BUCK5_SEL_CNT		(8)
> +
> +static const struct regulator_linear_range rk809_buck5_voltage_ranges[] = {
> +	REGULATOR_LINEAR_RANGE(1500000, 0, 0, 0),
> +	REGULATOR_LINEAR_RANGE(1800000, 1, 3, 200000),
> +	REGULATOR_LINEAR_RANGE(2800000, 4, 5, 200000),
> +	REGULATOR_LINEAR_RANGE(3300000, 6, 7, 300000),
> +};
> +
> +#define RK817_BUCK1_MIN0 500000
> +#define RK817_BUCK1_MAX0 1500000
> +
> +#define RK817_BUCK1_MIN1 1600000
> +#define RK817_BUCK1_MAX1 2400000
> +
> +#define RK817_BUCK3_MAX1 3400000
> +
> +#define RK817_BUCK1_STP0 12500
> +#define RK817_BUCK1_STP1 100000
> +
> +#define RK817_BUCK1_SEL0 ((RK817_BUCK1_MAX0 - RK817_BUCK1_MIN0) /\
> +						  RK817_BUCK1_STP0)
> +#define RK817_BUCK1_SEL1 ((RK817_BUCK1_MAX1 - RK817_BUCK1_MIN1) /\
> +						  RK817_BUCK1_STP1)
> +
> +#define RK817_BUCK3_SEL1 ((RK817_BUCK3_MAX1 - RK817_BUCK1_MIN1) /\
> +						  RK817_BUCK1_STP1)
> +
> +#define RK817_BUCK1_SEL_CNT (RK817_BUCK1_SEL0 + RK817_BUCK1_SEL1 + 1)
> +#define RK817_BUCK3_SEL_CNT (RK817_BUCK1_SEL0 + RK817_BUCK3_SEL1 + 1)
> +
> +static const struct regulator_linear_range rk817_buck1_voltage_ranges[] = {
> +	REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN0, 0,
> +			       RK817_BUCK1_SEL0, RK817_BUCK1_STP0),
> +	REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN1, RK817_BUCK1_SEL0 + 1,
> +			       RK817_BUCK1_SEL_CNT, RK817_BUCK1_STP1),
> +};
> +
> +static const struct regulator_linear_range rk817_buck3_voltage_ranges[] = {
> +	REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN0, 0,
> +			       RK817_BUCK1_SEL0, RK817_BUCK1_STP0),
> +	REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN1, RK817_BUCK1_SEL0 + 1,
> +			       RK817_BUCK3_SEL_CNT, RK817_BUCK1_STP1),
> +};
> +
>  static int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev *rdev)
>  {
>  	struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev);
> @@ -281,14 +398,45 @@ static int rk808_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
>  	case 6001 ... 10000:
>  		break;
>  	default:
> -		pr_warn("%s ramp_delay: %d not supported, setting 10000\n",
> -			rdev->desc->name, ramp_delay);
> +		dev_warn(&rdev->dev,
> +			 "%s ramp_delay: %d not supported, setting 10000\n",
> +			 rdev->desc->name, ramp_delay);
>  	}
>  
>  	return regmap_update_bits(rdev->regmap, reg,
>  				  RK808_RAMP_RATE_MASK, ramp_value);
>  }
>  
> +/*
> + * RK817 RK809
> + */
> +static int rk817_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
> +{
> +	unsigned int ramp_value = RK817_RAMP_RATE_25MV_PER_US;
> +	unsigned int reg = RK817_BUCK_CONFIG_REG(rdev_get_id(rdev));
> +
> +	switch (ramp_delay) {
> +	case 0 ... 3000:
> +		ramp_value = RK817_RAMP_RATE_3MV_PER_US;
> +		break;
> +	case 3001 ... 6300:
> +		ramp_value = RK817_RAMP_RATE_6_3MV_PER_US;
> +		break;
> +	case 6301 ... 12500:
> +		ramp_value = RK817_RAMP_RATE_12_5MV_PER_US;
> +		break;
> +	case 12501 ... 25000:
> +		break;
> +	default:
> +		dev_warn(&rdev->dev,
> +			 "%s ramp_delay: %d not supported, setting 10000\n",
> +			 rdev->desc->name, ramp_delay);
> +	}
> +
> +	return regmap_update_bits(rdev->regmap, reg,
> +				  RK817_RAMP_RATE_MASK, ramp_value);
> +}
> +
>  static int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv)
>  {
>  	unsigned int reg;
> @@ -304,6 +452,29 @@ static int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv)
>  				  sel);
>  }
>  
> +static int rk817_check_suspend_voltage(int id)
> +{
> +	if (id >= RK817_ID_DCDC1 && id <= RK817_ID_LDO9)
> +		return 0;
> +	return -1;
> +}
> +
> +static int rk817_set_suspend_voltage(struct regulator_dev *rdev, int uv)
> +{
> +	unsigned int reg;
> +	int id = rdev_get_id(rdev);
> +	int sel = regulator_map_voltage_linear(rdev, uv, uv);
> +	/* only ldo1~ldo9 */
> +	if (sel < 0 || rk817_check_suspend_voltage(id))
> +		return -EINVAL;
> +
> +	reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
> +
> +	return regmap_update_bits(rdev->regmap, reg,
> +				  rdev->desc->vsel_mask,
> +				  sel);
> +}
> +
>  static int rk808_set_suspend_voltage_range(struct regulator_dev *rdev, int uv)
>  {
>  	unsigned int reg;
> @@ -363,6 +534,129 @@ static int rk808_set_suspend_disable(struct regulator_dev *rdev)
>  				  rdev->desc->enable_mask);
>  }
>  
> +static int rk817_set_suspend_enable_ctrl(struct regulator_dev *rdev,
> +					 unsigned int en)
> +{
> +	unsigned int reg;
> +	int id = rdev_get_id(rdev);
> +	unsigned int id_slp, msk, val;
> +
> +	if (id >= RK817_ID_DCDC1 && id <= RK817_ID_DCDC4)
> +		id_slp = id;
> +	else if (id >= RK817_ID_LDO1 && id <= RK817_ID_LDO8)
> +		id_slp = 8 + (id - RK817_ID_LDO1);
> +	else if (id >= RK817_ID_LDO9 && id <= RK809_ID_SW2)
> +		id_slp = 4 + (id - RK817_ID_LDO9);
> +	else
> +		return -EINVAL;
> +
> +	reg = RK817_POWER_SLP_EN_REG(id_slp / 8);
> +
> +	msk = BIT(id_slp % 8);
> +	if (en)
> +		val = msk;
> +	else
> +		val = 0;
> +
> +	return regmap_update_bits(rdev->regmap, reg, msk, val);
> +}
> +
> +static int rk817_set_suspend_enable(struct regulator_dev *rdev)
> +{
> +	return rk817_set_suspend_enable_ctrl(rdev, 1);
> +}
> +
> +static int rk817_set_suspend_disable(struct regulator_dev *rdev)
> +{
> +	return rk817_set_suspend_enable_ctrl(rdev, 0);
> +}
> +
> +static int rk8xx_set_suspend_mode(struct regulator_dev *rdev, unsigned int mode)
> +{
> +	unsigned int reg;
> +
> +	reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
> +
> +	switch (mode) {
> +	case REGULATOR_MODE_FAST:
> +		return regmap_update_bits(rdev->regmap, reg,
> +					  PWM_MODE_MSK, FPWM_MODE);
> +	case REGULATOR_MODE_NORMAL:
> +		return regmap_update_bits(rdev->regmap, reg,
> +					  PWM_MODE_MSK, AUTO_PWM_MODE);
> +	default:
> +		dev_err(&rdev->dev, "do not support this mode\n");
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +static int rk8xx_set_mode(struct regulator_dev *rdev, unsigned int mode)
> +{
> +	switch (mode) {
> +	case REGULATOR_MODE_FAST:
> +		return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
> +					  PWM_MODE_MSK, FPWM_MODE);
> +	case REGULATOR_MODE_NORMAL:
> +		return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
> +					  PWM_MODE_MSK, AUTO_PWM_MODE);
> +	default:
> +		dev_err(&rdev->dev, "do not support this mode\n");
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +static unsigned int rk8xx_get_mode(struct regulator_dev *rdev)
> +{
> +	unsigned int val;
> +	int err;
> +
> +	err = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
> +	if (err)
> +		return err;
> +
> +	if (val & FPWM_MODE)
> +		return REGULATOR_MODE_FAST;
> +	else
> +		return REGULATOR_MODE_NORMAL;
> +}
> +
> +static int rk8xx_is_enabled_wmsk_regmap(struct regulator_dev *rdev)
> +{
> +	unsigned int val;
> +	int ret;
> +
> +	ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
> +	if (ret != 0)
> +		return ret;
> +
> +	/* add write mask bit */
> +	val |= (rdev->desc->enable_mask & 0xf0);
> +	val &= rdev->desc->enable_mask;
> +
> +	if (rdev->desc->enable_is_inverted) {
> +		if (rdev->desc->enable_val)
> +			return val != rdev->desc->enable_val;
> +		return (val == 0);
> +	}
> +	if (rdev->desc->enable_val)
> +		return val == rdev->desc->enable_val;
> +	return val != 0;
> +}
> +
> +static unsigned int rk8xx_regulator_of_map_mode(unsigned int mode)
> +{
> +	if (mode == 1)
> +		return REGULATOR_MODE_FAST;
> +	if (mode == 2)
> +		return REGULATOR_MODE_NORMAL;
> +
> +	return -EINVAL;
> +}
> +
>  static struct regulator_ops rk805_reg_ops = {
>  		.list_voltage           = regulator_list_voltage_linear,
>  		.map_voltage            = regulator_map_voltage_linear,
> @@ -433,6 +727,71 @@ static int rk808_set_suspend_disable(struct regulator_dev *rdev)
>  	.set_suspend_disable	= rk808_set_suspend_disable,
>  };
>  
> +static struct regulator_ops rk809_buck5_ops_range = {
> +	.list_voltage		= regulator_list_voltage_linear_range,
> +	.map_voltage		= regulator_map_voltage_linear_range,
> +	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
> +	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
> +	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
> +	.enable			= regulator_enable_regmap,
> +	.disable		= regulator_disable_regmap,
> +	.is_enabled		= rk8xx_is_enabled_wmsk_regmap,
> +	.set_suspend_voltage	= rk808_set_suspend_voltage_range,
> +	.set_suspend_enable	= rk817_set_suspend_enable,
> +	.set_suspend_disable	= rk817_set_suspend_disable,
> +};
> +
> +static struct regulator_ops rk817_reg_ops = {
> +	.list_voltage		= regulator_list_voltage_linear,
> +	.map_voltage		= regulator_map_voltage_linear,
> +	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
> +	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
> +	.enable			= regulator_enable_regmap,
> +	.disable		= regulator_disable_regmap,
> +	.is_enabled		= rk8xx_is_enabled_wmsk_regmap,
> +	.set_suspend_voltage	= rk817_set_suspend_voltage,
> +	.set_suspend_enable	= rk817_set_suspend_enable,
> +	.set_suspend_disable	= rk817_set_suspend_disable,
> +};
> +
> +static struct regulator_ops rk817_boost_ops = {
> +	.list_voltage		= regulator_list_voltage_linear,
> +	.map_voltage		= regulator_map_voltage_linear,
> +	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
> +	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
> +	.enable			= regulator_enable_regmap,
> +	.disable		= regulator_disable_regmap,
> +	.is_enabled		= rk8xx_is_enabled_wmsk_regmap,
> +	.set_suspend_enable	= rk817_set_suspend_enable,
> +	.set_suspend_disable	= rk817_set_suspend_disable,
> +};
> +
> +static struct regulator_ops rk817_buck_ops_range = {
> +	.list_voltage		= regulator_list_voltage_linear_range,
> +	.map_voltage		= regulator_map_voltage_linear_range,
> +	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
> +	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
> +	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
> +	.enable			= regulator_enable_regmap,
> +	.disable		= regulator_disable_regmap,
> +	.is_enabled		= rk8xx_is_enabled_wmsk_regmap,
> +	.set_mode		= rk8xx_set_mode,
> +	.get_mode		= rk8xx_get_mode,
> +	.set_suspend_mode	= rk8xx_set_suspend_mode,
> +	.set_ramp_delay		= rk817_set_ramp_delay,
> +	.set_suspend_voltage	= rk808_set_suspend_voltage_range,
> +	.set_suspend_enable	= rk817_set_suspend_enable,
> +	.set_suspend_disable	= rk817_set_suspend_disable,
> +};
> +
> +static struct regulator_ops rk817_switch_ops = {
> +	.enable			= regulator_enable_regmap,
> +	.disable		= regulator_disable_regmap,
> +	.is_enabled		= regulator_is_enabled_regmap,
> +	.set_suspend_enable	= rk817_set_suspend_enable,
> +	.set_suspend_disable	= rk817_set_suspend_disable,
> +};
> +
>  static const struct regulator_desc rk805_reg[] = {
>  	{
>  		.name = "DCDC_REG1",
> @@ -589,6 +948,271 @@ static int rk808_set_suspend_disable(struct regulator_dev *rdev)
>  		RK808_DCDC_EN_REG, BIT(6)),
>  };
>  
> +static const struct regulator_desc rk809_reg[] = {
> +	{
> +		.name = "DCDC_REG1",
> +		.supply_name = "vcc1",
> +		.of_match = of_match_ptr("DCDC_REG1"),
> +		.regulators_node = of_match_ptr("regulators"),
> +		.id = RK817_ID_DCDC1,
> +		.ops = &rk817_buck_ops_range,
> +		.type = REGULATOR_VOLTAGE,
> +		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
> +		.linear_ranges = rk817_buck1_voltage_ranges,
> +		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
> +		.vsel_reg = RK817_BUCK1_ON_VSEL_REG,
> +		.vsel_mask = RK817_BUCK_VSEL_MASK,
> +		.enable_reg = RK817_POWER_EN_REG(0),
> +		.enable_mask = ENABLE_MASK(RK817_ID_DCDC1),
> +		.enable_val = ENABLE_MASK(RK817_ID_DCDC1),
> +		.disable_val = DISABLE_VAL(RK817_ID_DCDC1),
> +		.of_map_mode = rk8xx_regulator_of_map_mode,
> +		.owner = THIS_MODULE,
> +	}, {
> +		.name = "DCDC_REG2",
> +		.supply_name = "vcc2",
> +		.of_match = of_match_ptr("DCDC_REG2"),
> +		.regulators_node = of_match_ptr("regulators"),
> +		.id = RK817_ID_DCDC2,
> +		.ops = &rk817_buck_ops_range,
> +		.type = REGULATOR_VOLTAGE,
> +		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
> +		.linear_ranges = rk817_buck1_voltage_ranges,
> +		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
> +		.vsel_reg = RK817_BUCK2_ON_VSEL_REG,
> +		.vsel_mask = RK817_BUCK_VSEL_MASK,
> +		.enable_reg = RK817_POWER_EN_REG(0),
> +		.enable_mask = ENABLE_MASK(RK817_ID_DCDC2),
> +		.enable_val = ENABLE_MASK(RK817_ID_DCDC2),
> +		.disable_val = DISABLE_VAL(RK817_ID_DCDC2),
> +		.of_map_mode = rk8xx_regulator_of_map_mode,
> +		.owner = THIS_MODULE,
> +	}, {
> +		.name = "DCDC_REG3",
> +		.supply_name = "vcc3",
> +		.of_match = of_match_ptr("DCDC_REG3"),
> +		.regulators_node = of_match_ptr("regulators"),
> +		.id = RK817_ID_DCDC3,
> +		.ops = &rk817_buck_ops_range,
> +		.type = REGULATOR_VOLTAGE,
> +		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
> +		.linear_ranges = rk817_buck1_voltage_ranges,
> +		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
> +		.vsel_reg = RK817_BUCK3_ON_VSEL_REG,
> +		.vsel_mask = RK817_BUCK_VSEL_MASK,
> +		.enable_reg = RK817_POWER_EN_REG(0),
> +		.enable_mask = ENABLE_MASK(RK817_ID_DCDC3),
> +		.enable_val = ENABLE_MASK(RK817_ID_DCDC3),
> +		.disable_val = DISABLE_VAL(RK817_ID_DCDC3),
> +		.of_map_mode = rk8xx_regulator_of_map_mode,
> +		.owner = THIS_MODULE,
> +	}, {
> +		.name = "DCDC_REG4",
> +		.supply_name = "vcc4",
> +		.of_match = of_match_ptr("DCDC_REG4"),
> +		.regulators_node = of_match_ptr("regulators"),
> +		.id = RK817_ID_DCDC4,
> +		.ops = &rk817_buck_ops_range,
> +		.type = REGULATOR_VOLTAGE,
> +		.n_voltages = RK817_BUCK3_SEL_CNT + 1,
> +		.linear_ranges = rk817_buck3_voltage_ranges,
> +		.n_linear_ranges = ARRAY_SIZE(rk817_buck3_voltage_ranges),
> +		.vsel_reg = RK817_BUCK4_ON_VSEL_REG,
> +		.vsel_mask = RK817_BUCK_VSEL_MASK,
> +		.enable_reg = RK817_POWER_EN_REG(0),
> +		.enable_mask = ENABLE_MASK(RK817_ID_DCDC4),
> +		.enable_val = ENABLE_MASK(RK817_ID_DCDC4),
> +		.disable_val = DISABLE_VAL(RK817_ID_DCDC4),
> +		.of_map_mode = rk8xx_regulator_of_map_mode,
> +		.owner = THIS_MODULE,
> +	},
> +	{
> +		.name = "DCDC_REG5",
> +		.supply_name = "vcc9",
> +		.of_match = of_match_ptr("DCDC_REG5"),
> +		.regulators_node = of_match_ptr("regulators"),
> +		.id = RK809_ID_DCDC5,
> +		.ops = &rk809_buck5_ops_range,
> +		.type = REGULATOR_VOLTAGE,
> +		.n_voltages = RK809_BUCK5_SEL_CNT,
> +		.linear_ranges = rk809_buck5_voltage_ranges,
> +		.n_linear_ranges = ARRAY_SIZE(rk809_buck5_voltage_ranges),
> +		.vsel_reg = RK809_BUCK5_CONFIG(0),
> +		.vsel_mask = RK809_BUCK5_VSEL_MASK,
> +		.enable_reg = RK817_POWER_EN_REG(3),
> +		.enable_mask = ENABLE_MASK(1),
> +		.enable_val = ENABLE_MASK(1),
> +		.disable_val = DISABLE_VAL(1),
> +		.of_map_mode = rk8xx_regulator_of_map_mode,
> +		.owner = THIS_MODULE,
> +	},
> +	RK817_DESC(RK817_ID_LDO1, "LDO_REG1", "vcc5", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(0), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(1), ENABLE_MASK(0), ENABLE_MASK(0),
> +		   DISABLE_VAL(0), 400),
> +	RK817_DESC(RK817_ID_LDO2, "LDO_REG2", "vcc5", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(1), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(1), ENABLE_MASK(1), ENABLE_MASK(1),
> +		   DISABLE_VAL(1), 400),
> +	RK817_DESC(RK817_ID_LDO3, "LDO_REG3", "vcc5", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(2), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(1), ENABLE_MASK(2), ENABLE_MASK(2),
> +		   DISABLE_VAL(2), 400),
> +	RK817_DESC(RK817_ID_LDO4, "LDO_REG4", "vcc6", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(3), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(1), ENABLE_MASK(3), ENABLE_MASK(3),
> +		   DISABLE_VAL(3), 400),
> +	RK817_DESC(RK817_ID_LDO5, "LDO_REG5", "vcc6", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(4), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(2), ENABLE_MASK(0), ENABLE_MASK(0),
> +		   DISABLE_VAL(0), 400),
> +	RK817_DESC(RK817_ID_LDO6, "LDO_REG6", "vcc6", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(5), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(2), ENABLE_MASK(1), ENABLE_MASK(1),
> +		   DISABLE_VAL(1), 400),
> +	RK817_DESC(RK817_ID_LDO7, "LDO_REG7", "vcc7", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(6), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(2), ENABLE_MASK(2), ENABLE_MASK(2),
> +		   DISABLE_VAL(2), 400),
> +	RK817_DESC(RK817_ID_LDO8, "LDO_REG8", "vcc7", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(7), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(2), ENABLE_MASK(3), ENABLE_MASK(3),
> +		   DISABLE_VAL(3), 400),
> +	RK817_DESC(RK817_ID_LDO9, "LDO_REG9", "vcc7", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(8), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(3), ENABLE_MASK(0), ENABLE_MASK(0),
> +		   DISABLE_VAL(0), 400),
> +	RK817_DESC_SWITCH(RK809_ID_SW1, "SWITCH_REG1", "vcc9",
> +			  RK817_POWER_EN_REG(3), ENABLE_MASK(2),
> +			  ENABLE_MASK(2), DISABLE_VAL(2)),
> +	RK817_DESC_SWITCH(RK809_ID_SW2, "SWITCH_REG2", "vcc8",
> +			  RK817_POWER_EN_REG(3), ENABLE_MASK(3),
> +			  ENABLE_MASK(3), DISABLE_VAL(3)),
> +};
> +
> +static const struct regulator_desc rk817_reg[] = {
> +	{
> +		.name = "DCDC_REG1",
> +		.supply_name = "vcc1",
> +		.of_match = of_match_ptr("DCDC_REG1"),
> +		.regulators_node = of_match_ptr("regulators"),
> +		.id = RK817_ID_DCDC1,
> +		.ops = &rk817_buck_ops_range,
> +		.type = REGULATOR_VOLTAGE,
> +		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
> +		.linear_ranges = rk817_buck1_voltage_ranges,
> +		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
> +		.vsel_reg = RK817_BUCK1_ON_VSEL_REG,
> +		.vsel_mask = RK817_BUCK_VSEL_MASK,
> +		.enable_reg = RK817_POWER_EN_REG(0),
> +		.enable_mask = ENABLE_MASK(RK817_ID_DCDC1),
> +		.enable_val = ENABLE_MASK(RK817_ID_DCDC1),
> +		.disable_val = DISABLE_VAL(RK817_ID_DCDC1),
> +		.of_map_mode = rk8xx_regulator_of_map_mode,
> +		.owner = THIS_MODULE,
> +	}, {
> +		.name = "DCDC_REG2",
> +		.supply_name = "vcc2",
> +		.of_match = of_match_ptr("DCDC_REG2"),
> +		.regulators_node = of_match_ptr("regulators"),
> +		.id = RK817_ID_DCDC2,
> +		.ops = &rk817_buck_ops_range,
> +		.type = REGULATOR_VOLTAGE,
> +		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
> +		.linear_ranges = rk817_buck1_voltage_ranges,
> +		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
> +		.vsel_reg = RK817_BUCK2_ON_VSEL_REG,
> +		.vsel_mask = RK817_BUCK_VSEL_MASK,
> +		.enable_reg = RK817_POWER_EN_REG(0),
> +		.enable_mask = ENABLE_MASK(RK817_ID_DCDC2),
> +		.enable_val = ENABLE_MASK(RK817_ID_DCDC2),
> +		.disable_val = DISABLE_VAL(RK817_ID_DCDC2),
> +		.of_map_mode = rk8xx_regulator_of_map_mode,
> +		.owner = THIS_MODULE,
> +	}, {
> +		.name = "DCDC_REG3",
> +		.supply_name = "vcc3",
> +		.of_match = of_match_ptr("DCDC_REG3"),
> +		.regulators_node = of_match_ptr("regulators"),
> +		.id = RK817_ID_DCDC3,
> +		.ops = &rk817_buck_ops_range,
> +		.type = REGULATOR_VOLTAGE,
> +		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
> +		.linear_ranges = rk817_buck1_voltage_ranges,
> +		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
> +		.vsel_reg = RK817_BUCK3_ON_VSEL_REG,
> +		.vsel_mask = RK817_BUCK_VSEL_MASK,
> +		.enable_reg = RK817_POWER_EN_REG(0),
> +		.enable_mask = ENABLE_MASK(RK817_ID_DCDC3),
> +		.enable_val = ENABLE_MASK(RK817_ID_DCDC3),
> +		.disable_val = DISABLE_VAL(RK817_ID_DCDC3),
> +		.of_map_mode = rk8xx_regulator_of_map_mode,
> +		.owner = THIS_MODULE,
> +	}, {
> +		.name = "DCDC_REG4",
> +		.supply_name = "vcc4",
> +		.of_match = of_match_ptr("DCDC_REG4"),
> +		.regulators_node = of_match_ptr("regulators"),
> +		.id = RK817_ID_DCDC4,
> +		.ops = &rk817_buck_ops_range,
> +		.type = REGULATOR_VOLTAGE,
> +		.n_voltages = RK817_BUCK3_SEL_CNT + 1,
> +		.linear_ranges = rk817_buck3_voltage_ranges,
> +		.n_linear_ranges = ARRAY_SIZE(rk817_buck3_voltage_ranges),
> +		.vsel_reg = RK817_BUCK4_ON_VSEL_REG,
> +		.vsel_mask = RK817_BUCK_VSEL_MASK,
> +		.enable_reg = RK817_POWER_EN_REG(0),
> +		.enable_mask = ENABLE_MASK(RK817_ID_DCDC4),
> +		.enable_val = ENABLE_MASK(RK817_ID_DCDC4),
> +		.disable_val = DISABLE_VAL(RK817_ID_DCDC4),
> +		.of_map_mode = rk8xx_regulator_of_map_mode,
> +		.owner = THIS_MODULE,
> +	},
> +	RK817_DESC(RK817_ID_LDO1, "LDO_REG1", "vcc5", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(0), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(1), ENABLE_MASK(0), ENABLE_MASK(0),
> +		   DISABLE_VAL(0), 400),
> +	RK817_DESC(RK817_ID_LDO2, "LDO_REG2", "vcc5", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(1), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(1), ENABLE_MASK(1), ENABLE_MASK(1),
> +		   DISABLE_VAL(1), 400),
> +	RK817_DESC(RK817_ID_LDO3, "LDO_REG3", "vcc5", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(2), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(1), ENABLE_MASK(2), ENABLE_MASK(2),
> +		   DISABLE_VAL(2), 400),
> +	RK817_DESC(RK817_ID_LDO4, "LDO_REG4", "vcc6", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(3), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(1), ENABLE_MASK(3), ENABLE_MASK(3),
> +		   DISABLE_VAL(3), 400),
> +	RK817_DESC(RK817_ID_LDO5, "LDO_REG5", "vcc6", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(4), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(2), ENABLE_MASK(0), ENABLE_MASK(0),
> +		   DISABLE_VAL(0), 400),
> +	RK817_DESC(RK817_ID_LDO6, "LDO_REG6", "vcc6", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(5), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(2), ENABLE_MASK(1), ENABLE_MASK(1),
> +		   DISABLE_VAL(1), 400),
> +	RK817_DESC(RK817_ID_LDO7, "LDO_REG7", "vcc7", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(6), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(2), ENABLE_MASK(2), ENABLE_MASK(2),
> +		   DISABLE_VAL(2), 400),
> +	RK817_DESC(RK817_ID_LDO8, "LDO_REG8", "vcc7", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(7), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(2), ENABLE_MASK(3), ENABLE_MASK(3),
> +		   DISABLE_VAL(3), 400),
> +	RK817_DESC(RK817_ID_LDO9, "LDO_REG9", "vcc7", 600, 3400, 25,
> +		   RK817_LDO_ON_VSEL_REG(8), RK817_LDO_VSEL_MASK,
> +		   RK817_POWER_EN_REG(3), ENABLE_MASK(0), ENABLE_MASK(0),
> +		   DISABLE_VAL(0), 400),
> +	RK817_BOOST_DESC(RK817_ID_BOOST, "BOOST", "vcc8", 4700, 5400, 100,
> +			 RK817_BOOST_OTG_CFG, RK817_BOOST_VSEL_MASK,
> +			 RK817_POWER_EN_REG(3), ENABLE_MASK(1), ENABLE_MASK(1),
> +		   DISABLE_VAL(1), 400, 3500 - 5400),
> +	RK817_DESC_SWITCH(RK817_ID_BOOST_OTG_SW, "OTG_SWITCH", "vcc9",
> +			  RK817_POWER_EN_REG(3), ENABLE_MASK(2),
> +			  ENABLE_MASK(2), DISABLE_VAL(2)),
> +};
> +
>  static const struct regulator_desc rk818_reg[] = {
>  	{
>  		.name = "DCDC_REG1",
> @@ -759,6 +1383,14 @@ static int rk808_regulator_probe(struct platform_device *pdev)
>  		regulators = rk808_reg;
>  		nregulators = RK808_NUM_REGULATORS;
>  		break;
> +	case RK809_ID:
> +		regulators = rk809_reg;
> +		nregulators = RK809_NUM_REGULATORS;
> +		break;
> +	case RK817_ID:
> +		regulators = rk817_reg;
> +		nregulators = RK817_NUM_REGULATORS;
> +		break;
>  	case RK818_ID:
>  		regulators = rk818_reg;
>  		nregulators = RK818_NUM_REGULATORS;
> @@ -797,6 +1429,7 @@ static int rk808_regulator_probe(struct platform_device *pdev)
>  module_platform_driver(rk808_regulator_driver);
>  
>  MODULE_DESCRIPTION("regulator driver for the RK808/RK818 series PMICs");
> +MODULE_AUTHOR("Tony xie <tony.xie@rock-chips.com>");
>  MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
>  MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>");
>  MODULE_AUTHOR("Wadim Egorov <w.egorov@phytec.de>");
> diff --git a/include/linux/mfd/rk808.h b/include/linux/mfd/rk808.h
> index b973b0a..b4ce2373 100644
> --- a/include/linux/mfd/rk808.h
> +++ b/include/linux/mfd/rk808.h
> @@ -396,7 +396,10 @@ enum rk805_reg {
>  #define SHUTDOWN_FUN			(0x2 << 2)
>  #define SLEEP_FUN			(0x1 << 2)
>  #define RK8XX_ID_MSK			0xfff0
> +#define PWM_MODE_MSK			BIT(7)
>  #define FPWM_MODE			BIT(7)
> +#define AUTO_PWM_MODE			0
> +
>  enum rk817_reg_id {
>  	RK817_ID_DCDC1 = 0,
>  	RK817_ID_DCDC2,

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

* Re: [PATCH v3 4/5] rtc: rk808: add RK809 and RK817 support.
  2018-08-24  3:30 ` [PATCH v3 4/5] rtc: rk808: add RK809 and RK817 support Tony Xie
@ 2018-08-27 21:14   ` Alexandre Belloni
  0 siblings, 0 replies; 16+ messages in thread
From: Alexandre Belloni @ 2018-08-27 21:14 UTC (permalink / raw)
  To: Tony Xie
  Cc: heiko, broonie, lee.jones, robh+dt, mark.rutland, a.zummo, sboyd,
	linux-clk, linux-rtc, linux-arm-kernel, linux-rockchip,
	devicetree, linux-kernel, chenjh, xsf, zhangqing, huangtao

On 24/08/2018 11:30:40+0800, Tony Xie wrote:
> RK809 and RK817 are power management IC chips for multimedia products.
> Most of their functions and registers are same, including the rtc.
> 
> Signed-off-by: Tony Xie <tony.xie@rock-chips.com>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

> ---
>  drivers/rtc/Kconfig     |  4 +--
>  drivers/rtc/rtc-rk808.c | 68 +++++++++++++++++++++++++++++++++++++++----------
>  2 files changed, 56 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index a2ba5db..1aaf935 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -371,11 +371,11 @@ config RTC_DRV_MAX77686
>  	  will be called rtc-max77686.
>  
>  config RTC_DRV_RK808
> -	tristate "Rockchip RK805/RK808/RK818 RTC"
> +	tristate "Rockchip RK805/RK808/RK809/RK817/RK818 RTC"
>  	depends on MFD_RK808
>  	help
>  	  If you say yes here you will get support for the
> -	  RTC of RK805, RK808 and RK818 PMIC.
> +	  RTC of RK805, RK809 and RK817, RK808 and RK818 PMIC.
>  
>  	  This driver can also be built as a module. If so, the module
>  	  will be called rk808-rtc.
> diff --git a/drivers/rtc/rtc-rk808.c b/drivers/rtc/rtc-rk808.c
> index 739c0d4..5bacdaf 100644
> --- a/drivers/rtc/rtc-rk808.c
> +++ b/drivers/rtc/rtc-rk808.c
> @@ -50,9 +50,18 @@
>  #define NUM_TIME_REGS	(RK808_WEEKS_REG - RK808_SECONDS_REG + 1)
>  #define NUM_ALARM_REGS	(RK808_ALARM_YEARS_REG - RK808_ALARM_SECONDS_REG + 1)
>  
> +struct rk_rtc_compat_reg {
> +	unsigned int ctrl_reg;
> +	unsigned int status_reg;
> +	unsigned int alarm_seconds_reg;
> +	unsigned int int_reg;
> +	unsigned int seconds_reg;
> +};
> +
>  struct rk808_rtc {
>  	struct rk808 *rk808;
>  	struct rtc_device *rtc;
> +	struct rk_rtc_compat_reg *creg;
>  	int irq;
>  };
>  
> @@ -101,7 +110,7 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
>  	int ret;
>  
>  	/* Force an update of the shadowed registers right now */
> -	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
> +	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->ctrl_reg,
>  				 BIT_RTC_CTRL_REG_RTC_GET_TIME,
>  				 BIT_RTC_CTRL_REG_RTC_GET_TIME);
>  	if (ret) {
> @@ -115,7 +124,7 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
>  	 * 32khz. If we clear the GET_TIME bit here, the time of i2c transfer
>  	 * certainly more than 31.25us: 16 * 2.5us at 400kHz bus frequency.
>  	 */
> -	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
> +	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->ctrl_reg,
>  				 BIT_RTC_CTRL_REG_RTC_GET_TIME,
>  				 0);
>  	if (ret) {
> @@ -123,7 +132,7 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
>  		return ret;
>  	}
>  
> -	ret = regmap_bulk_read(rk808->regmap, RK808_SECONDS_REG,
> +	ret = regmap_bulk_read(rk808->regmap, rk808_rtc->creg->seconds_reg,
>  			       rtc_data, NUM_TIME_REGS);
>  	if (ret) {
>  		dev_err(dev, "Failed to bulk read rtc_data: %d\n", ret);
> @@ -166,7 +175,7 @@ static int rk808_rtc_set_time(struct device *dev, struct rtc_time *tm)
>  	rtc_data[6] = bin2bcd(tm->tm_wday);
>  
>  	/* Stop RTC while updating the RTC registers */
> -	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
> +	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->ctrl_reg,
>  				 BIT_RTC_CTRL_REG_STOP_RTC_M,
>  				 BIT_RTC_CTRL_REG_STOP_RTC_M);
>  	if (ret) {
> @@ -174,14 +183,14 @@ static int rk808_rtc_set_time(struct device *dev, struct rtc_time *tm)
>  		return ret;
>  	}
>  
> -	ret = regmap_bulk_write(rk808->regmap, RK808_SECONDS_REG,
> +	ret = regmap_bulk_write(rk808->regmap, rk808_rtc->creg->seconds_reg,
>  				rtc_data, NUM_TIME_REGS);
>  	if (ret) {
>  		dev_err(dev, "Failed to bull write rtc_data: %d\n", ret);
>  		return ret;
>  	}
>  	/* Start RTC again */
> -	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
> +	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->ctrl_reg,
>  				 BIT_RTC_CTRL_REG_STOP_RTC_M, 0);
>  	if (ret) {
>  		dev_err(dev, "Failed to update RTC control: %d\n", ret);
> @@ -199,8 +208,13 @@ static int rk808_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
>  	uint32_t int_reg;
>  	int ret;
>  
> -	ret = regmap_bulk_read(rk808->regmap, RK808_ALARM_SECONDS_REG,
> +	ret = regmap_bulk_read(rk808->regmap,
> +			       rk808_rtc->creg->alarm_seconds_reg,
>  			       alrm_data, NUM_ALARM_REGS);
> +	if (ret) {
> +		dev_err(dev, "Failed to read RTC alarm date REG: %d\n", ret);
> +		return ret;
> +	}
>  
>  	alrm->time.tm_sec = bcd2bin(alrm_data[0] & SECONDS_REG_MSK);
>  	alrm->time.tm_min = bcd2bin(alrm_data[1] & MINUTES_REG_MAK);
> @@ -210,7 +224,7 @@ static int rk808_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
>  	alrm->time.tm_year = (bcd2bin(alrm_data[5] & YEARS_REG_MSK)) + 100;
>  	rockchip_to_gregorian(&alrm->time);
>  
> -	ret = regmap_read(rk808->regmap, RK808_RTC_INT_REG, &int_reg);
> +	ret = regmap_read(rk808->regmap, rk808_rtc->creg->int_reg, &int_reg);
>  	if (ret) {
>  		dev_err(dev, "Failed to read RTC INT REG: %d\n", ret);
>  		return ret;
> @@ -231,7 +245,7 @@ static int rk808_rtc_stop_alarm(struct rk808_rtc *rk808_rtc)
>  	struct rk808 *rk808 = rk808_rtc->rk808;
>  	int ret;
>  
> -	ret = regmap_update_bits(rk808->regmap, RK808_RTC_INT_REG,
> +	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->int_reg,
>  				 BIT_RTC_INTERRUPTS_REG_IT_ALARM_M, 0);
>  
>  	return ret;
> @@ -242,7 +256,7 @@ static int rk808_rtc_start_alarm(struct rk808_rtc *rk808_rtc)
>  	struct rk808 *rk808 = rk808_rtc->rk808;
>  	int ret;
>  
> -	ret = regmap_update_bits(rk808->regmap, RK808_RTC_INT_REG,
> +	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->int_reg,
>  				 BIT_RTC_INTERRUPTS_REG_IT_ALARM_M,
>  				 BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
>  
> @@ -274,7 +288,8 @@ static int rk808_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
>  	alrm_data[4] = bin2bcd(alrm->time.tm_mon + 1);
>  	alrm_data[5] = bin2bcd(alrm->time.tm_year - 100);
>  
> -	ret = regmap_bulk_write(rk808->regmap, RK808_ALARM_SECONDS_REG,
> +	ret = regmap_bulk_write(rk808->regmap,
> +				rk808_rtc->creg->alarm_seconds_reg,
>  				alrm_data, NUM_ALARM_REGS);
>  	if (ret) {
>  		dev_err(dev, "Failed to bulk write: %d\n", ret);
> @@ -318,7 +333,7 @@ static irqreturn_t rk808_alarm_irq(int irq, void *data)
>  	struct i2c_client *client = rk808->i2c;
>  	int ret;
>  
> -	ret = regmap_write(rk808->regmap, RK808_RTC_STATUS_REG,
> +	ret = regmap_write(rk808->regmap, rk808_rtc->creg->status_reg,
>  			   RTC_STATUS_MASK);
>  	if (ret) {
>  		dev_err(&client->dev,
> @@ -371,6 +386,22 @@ static int rk808_rtc_resume(struct device *dev)
>  static SIMPLE_DEV_PM_OPS(rk808_rtc_pm_ops,
>  	rk808_rtc_suspend, rk808_rtc_resume);
>  
> +static struct rk_rtc_compat_reg rk808_creg = {
> +	.ctrl_reg = RK808_RTC_CTRL_REG,
> +	.status_reg = RK808_RTC_STATUS_REG,
> +	.alarm_seconds_reg = RK808_ALARM_SECONDS_REG,
> +	.int_reg = RK808_RTC_INT_REG,
> +	.seconds_reg = RK808_SECONDS_REG,
> +};
> +
> +static struct rk_rtc_compat_reg rk817_creg = {
> +	.ctrl_reg = RK817_RTC_CTRL_REG,
> +	.status_reg = RK817_RTC_STATUS_REG,
> +	.alarm_seconds_reg = RK817_ALARM_SECONDS_REG,
> +	.int_reg = RK817_RTC_INT_REG,
> +	.seconds_reg = RK817_SECONDS_REG,
> +};
> +
>  static int rk808_rtc_probe(struct platform_device *pdev)
>  {
>  	struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
> @@ -381,11 +412,20 @@ static int rk808_rtc_probe(struct platform_device *pdev)
>  	if (rk808_rtc == NULL)
>  		return -ENOMEM;
>  
> +	switch (rk808->variant) {
> +	case RK809_ID:
> +	case RK817_ID:
> +		rk808_rtc->creg = &rk817_creg;
> +		break;
> +	default:
> +		rk808_rtc->creg = &rk808_creg;
> +		break;
> +	}
>  	platform_set_drvdata(pdev, rk808_rtc);
>  	rk808_rtc->rk808 = rk808;
>  
>  	/* start rtc running by default, and use shadowed timer. */
> -	ret = regmap_update_bits(rk808->regmap, RK808_RTC_CTRL_REG,
> +	ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->ctrl_reg,
>  				 BIT_RTC_CTRL_REG_STOP_RTC_M |
>  				 BIT_RTC_CTRL_REG_RTC_READSEL_M,
>  				 BIT_RTC_CTRL_REG_RTC_READSEL_M);
> @@ -395,7 +435,7 @@ static int rk808_rtc_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> -	ret = regmap_write(rk808->regmap, RK808_RTC_STATUS_REG,
> +	ret = regmap_write(rk808->regmap, rk808_rtc->creg->status_reg,
>  			   RTC_STATUS_MASK);
>  	if (ret) {
>  		dev_err(&pdev->dev,
> -- 
> 1.9.1
> 
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* Re: [PATCH v3 3/5] dt-bindings: mfd: rk808: Add binding information for RK809 and RK817.
  2018-08-24  3:30 ` [PATCH v3 3/5] dt-bindings: mfd: rk808: Add binding information for RK809 and RK817 Tony Xie
@ 2018-08-28 22:40   ` Rob Herring
  2018-09-11 12:37   ` Lee Jones
  1 sibling, 0 replies; 16+ messages in thread
From: Rob Herring @ 2018-08-28 22:40 UTC (permalink / raw)
  To: Tony Xie
  Cc: heiko, broonie, lee.jones, robh+dt, mark.rutland, a.zummo,
	alexandre.belloni, sboyd, linux-clk, linux-rtc, linux-arm-kernel,
	linux-rockchip, devicetree, linux-kernel, chenjh, xsf, zhangqing,
	huangtao, tony.xie

On Fri, 24 Aug 2018 11:30:39 +0800, Tony Xie wrote:
> Add device tree bindings documentation for Rockchip's RK809 & RK817 PMIC.
> 
> Signed-off-by: Tony Xie <tony.xie@rock-chips.com>
> ---
>  Documentation/devicetree/bindings/mfd/rk808.txt | 56 +++++++++++++++++++++++++
>  1 file changed, 56 insertions(+)
> 

Reviewed-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH v3 5/5] clk: RK808: add RK809 and RK817 support.
  2018-08-24  3:36 ` [PATCH v3 5/5] clk: RK808: " Tony Xie
@ 2018-08-31 17:34   ` Stephen Boyd
  0 siblings, 0 replies; 16+ messages in thread
From: Stephen Boyd @ 2018-08-31 17:34 UTC (permalink / raw)
  To: Tony Xie, heiko
  Cc: broonie, lee.jones, robh+dt, mark.rutland, a.zummo,
	alexandre.belloni, linux-clk, linux-rtc, linux-arm-kernel,
	linux-rockchip, devicetree, linux-kernel, chenjh, xsf, zhangqing,
	huangtao, tony.xie

Quoting Tony Xie (2018-08-23 20:36:02)
> diff --git a/drivers/clk/clk-rk808.c b/drivers/clk/clk-rk808.c
> index 6461f28..c5d3492 100644
> --- a/drivers/clk/clk-rk808.c
> +++ b/drivers/clk/clk-rk808.c
> @@ -96,6 +96,66 @@ static int rk808_clkout2_is_prepared(struct clk_hw *hw)
> +
> +static int rk817_clkout2_is_prepared(struct clk_hw *hw)
> +{
> +       struct rk808_clkout *rk808_clkout = container_of(hw,
> +                                                        struct rk808_clkout,
> +                                                        clkout2_hw);
> +       struct rk808 *rk808 = rk808_clkout->rk808;
> +       unsigned int val;
> +
> +       int ret = regmap_read(rk808->regmap, RK817_SYS_CFG(1), &val);
> +
> +       if (ret < 0)
> +               return ret;

The clk core handles the return value here as true or false. Probably
should return 0 here.

> +
> +       return (val & RK817_CLK32KOUT2_EN) ? 1 : 0;
> +}
> +
> +static const struct clk_ops rk817_clkout2_ops = {
> +       .prepare = rk817_clkout2_prepare,
> +       .unprepare = rk817_clkout2_unprepare,
> +       .is_prepared = rk817_clkout2_is_prepared,
> +       .recalc_rate = rk808_clkout_recalc_rate,
> +};
> +
> +static const struct clk_ops *rkpmic_get_ops(long variant)

Use the enum here for 'variant'? Then the case statement here will
complain loudly for unhandled cases.

> +{
> +       switch (variant) {
> +       case RK809_ID:
> +       case RK817_ID:
> +               return &rk817_clkout2_ops;
> +       case RK805_ID:
> +       case RK808_ID:
> +       case RK818_ID:
> +               return &rk808_clkout2_ops;
> +       }
> +
> +       return &rk808_clkout2_ops;
> +}
> +
>  static int rk808_clkout_probe(struct platform_device *pdev)
>  {
>         struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
> @@ -127,7 +187,7 @@ static int rk808_clkout_probe(struct platform_device *pdev)
>                 return ret;
>  
>         init.name = "rk808-clkout2";
> -       init.ops = &rk808_clkout2_ops;
> +       init.ops = rkpmic_get_ops(rk808->variant);
>         rk808_clkout->clkout2_hw.init = &init;
>  
>         /* optional override of the clockname */
> -- 
> 1.9.1
> 
> 

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

* Re: [PATCH v3 1/5] mfd: rk808: Add RK817 and RK809 support
  2018-08-24  3:30 ` [PATCH v3 1/5] mfd: rk808: Add RK817 and RK809 support Tony Xie
@ 2018-09-11 11:47   ` Lee Jones
  2018-10-23  3:12     ` tony
  0 siblings, 1 reply; 16+ messages in thread
From: Lee Jones @ 2018-09-11 11:47 UTC (permalink / raw)
  To: Tony Xie
  Cc: heiko, broonie, robh+dt, mark.rutland, a.zummo,
	alexandre.belloni, sboyd, linux-clk, linux-rtc, linux-arm-kernel,
	linux-rockchip, devicetree, linux-kernel, chenjh, xsf, zhangqing,
	huangtao

On Fri, 24 Aug 2018, Tony Xie wrote:

>     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       | 218 +++++++++++++++++++++++++++++++++++++++++++++-
>  include/linux/mfd/rk808.h | 172 ++++++++++++++++++++++++++++++++++++
>  kernel/reboot.c           |   1 +
>  4 files changed, 391 insertions(+), 6 deletions(-)
> 
> 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.

Any reason why you've taken these out of order?

>  	  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..62e2fe1 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),	\
> +	}

If this is helpful for you, it will be helpful for others.

Please submit this to the Regmap subsystem.

See: include/linux/regmap.h

> +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");

This isn't a good warning to an end user.

Where is "here"?

Please provide something a little more forthcoming/descriptive.

> +		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");

Again, what does this mean to an end user?  Probably very little.

> +		}
> +		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" },
>  	{ },
>  };
> @@ -438,10 +586,11 @@ static int rk808_probe(struct i2c_client *client,
>  	struct rk808 *rk808;
>  	const struct rk808_reg_data *pre_init_reg;
>  	const struct mfd_cell *cells;
> -	void (*pm_pwroff_fn)(void);
> +	void (*pm_pwroff_fn)(void) = NULL;
>  	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;

Please place these on separate lines.

>  	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;
> +	}

Rather than pre-assign default values at declaration, I think it would
be cleaner to have an else here.

>  	/* 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,
> +};

Looks like you want SIMPLE_DEV_PM_OPS() here.

>  static const struct i2c_device_id rk808_ids[] = {
>  	{ "rk805" },
>  	{ "rk808" },
> +	{ "rk809" },
> +	{ "rk817" },
>  	{ "rk818" },
>  	{ },
>  };

I don't think this table is required anymore.

Try removing it.

> @@ -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,
>  };
>  
> diff --git a/kernel/reboot.c b/kernel/reboot.c
> index e4ced88..83810d7 100644
> --- a/kernel/reboot.c
> +++ b/kernel/reboot.c
> @@ -49,6 +49,7 @@
>   */
>  
>  void (*pm_power_off_prepare)(void);
> +EXPORT_SYMBOL_GPL(pm_power_off_prepare);

Why do you need this where no other driver in the kernel does?

>  /**
>   *	emergency_restart - reboot the system

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH v3 3/5] dt-bindings: mfd: rk808: Add binding information for RK809 and RK817.
  2018-08-24  3:30 ` [PATCH v3 3/5] dt-bindings: mfd: rk808: Add binding information for RK809 and RK817 Tony Xie
  2018-08-28 22:40   ` Rob Herring
@ 2018-09-11 12:37   ` Lee Jones
  1 sibling, 0 replies; 16+ messages in thread
From: Lee Jones @ 2018-09-11 12:37 UTC (permalink / raw)
  To: Tony Xie
  Cc: heiko, broonie, robh+dt, mark.rutland, a.zummo,
	alexandre.belloni, sboyd, linux-clk, linux-rtc, linux-arm-kernel,
	linux-rockchip, devicetree, linux-kernel, chenjh, xsf, zhangqing,
	huangtao

On Fri, 24 Aug 2018, Tony Xie wrote:

> Add device tree bindings documentation for Rockchip's RK809 & RK817 PMIC.
> 
> Signed-off-by: Tony Xie <tony.xie@rock-chips.com>
> ---
>  Documentation/devicetree/bindings/mfd/rk808.txt | 56 +++++++++++++++++++++++++
>  1 file changed, 56 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/mfd/rk808.txt b/Documentation/devicetree/bindings/mfd/rk808.txt
> index 91b6522..c025a99 100644
> --- a/Documentation/devicetree/bindings/mfd/rk808.txt
> +++ b/Documentation/devicetree/bindings/mfd/rk808.txt
> @@ -3,11 +3,15 @@ RK8XX Power Management Integrated Circuit
>  The rk8xx family current members:
>  rk805
>  rk808
> +rk809
> +rk817
>  rk818
>  
>  Required properties:
>  - compatible: "rockchip,rk805"
>  - compatible: "rockchip,rk808"
> +- compatible: "rockchip,rk809"
> +- compatible: "rockchip,rk817"
>  - compatible: "rockchip,rk818"
>  - reg: I2C slave address
>  - interrupt-parent: The parent interrupt controller.
> @@ -46,6 +50,28 @@ Optional RK808 properties:
>    the gpio controller. If DVS GPIOs aren't present, voltage changes will happen
>    very quickly with no slow ramp time.
>  
> +Optional RK809 properties:
> +- vcc1-supply:  The input supply for DCDC_REG1
> +- vcc2-supply:  The input supply for DCDC_REG2
> +- vcc3-supply:  The input supply for DCDC_REG3
> +- vcc4-supply:  The input supply for DCDC_REG4
> +- vcc5-supply:  The input supply for LDO_REG1, LDO_REG2, LDO_REG3
> +- vcc6-supply:  The input supply for LDO_REG4, LDO_REG5, LDO_REG6
> +- vcc7-supply:  The input supply for LDO_REG7, LDO_REG8, LDO_REG9
> +- vcc8-supply:  The input supply for SWITCH_REG1
> +- vcc9-supply:  The input supply for DCDC_REG5, SWITCH_REG2
> +
> +Optional RK817 properties:
> +- vcc1-supply:  The input supply for DCDC_REG1
> +- vcc2-supply:  The input supply for DCDC_REG2
> +- vcc3-supply:  The input supply for DCDC_REG3
> +- vcc4-supply:  The input supply for DCDC_REG4
> +- vcc5-supply:  The input supply for LDO_REG1, LDO_REG2, LDO_REG3
> +- vcc6-supply:  The input supply for LDO_REG4, LDO_REG5, LDO_REG6
> +- vcc7-supply:  The input supply for LDO_REG7, LDO_REG8, LDO_REG9
> +- vcc8-supply:  The input supply for BOOST
> +- vcc9-supply:  The input supply for OTG_SWITCH

I think I'd like to see these squashed down a bit.

Something like:

> +Optional shared RK809 and RK817 properties:
> +- vcc1-supply:  The input supply for DCDC_REG1
> +- vcc2-supply:  The input supply for DCDC_REG2
> +- vcc3-supply:  The input supply for DCDC_REG3
> +- vcc4-supply:  The input supply for DCDC_REG4
> +- vcc5-supply:  The input supply for LDO_REG1, LDO_REG2, LDO_REG3
> +- vcc6-supply:  The input supply for LDO_REG4, LDO_REG5, LDO_REG6
> +- vcc7-supply:  The input supply for LDO_REG7, LDO_REG8, LDO_REG9
> +
> +Optional RK809 properties:
> +- vcc8-supply:  The input supply for SWITCH_REG1
> +- vcc9-supply:  The input supply for DCDC_REG5, SWITCH_REG2
> +
> +Optional RK817 properties:
> +- vcc8-supply:  The input supply for BOOST
> +- vcc9-supply:  The input supply for OTG_SWITCH

That's if 1-7 are as identical as they look at first glance.

>  Optional RK818 properties:
>  - vcc1-supply:  The input supply for DCDC_REG1
>  - vcc2-supply:  The input supply for DCDC_REG2
> @@ -87,6 +113,28 @@ number as described in RK808 datasheet.
>  	- SWITCH_REGn
>  		- valid values for n are 1 to 2
>  
> +Following regulators of the RK809 PMIC block are supported. Note that
> +the 'n' in regulator name, as in DCDC_REGn or LDOn, represents the DCDC or LDO
> +number as described in RK808 datasheet.
> +
> +	- DCDC_REGn
> +		- valid values for n are 1 to 5.
> +	- LDO_REGn
> +		- valid values for n are 1 to 9.
> +	- SWITCH_REGn
> +		- valid values for n are 1 to 2.
> +
> +Following regulators of the RK817 PMIC block are supported. Note that
> +the 'n' in regulator name, as in DCDC_REGn or LDOn, represents the DCDC or LDO
> +number as described in RK818 datasheet.

Is there any need to keep saying the same thing over and over?

Especially for something fairly obvious.

> +	- DCDC_REGn
> +		- valid values for n are 1 to 4.
> +	- LDO_REGn
> +		- valid values for n are 1 to 9.
> +	- BOOST
> +	- OTG_SWITCH
> +
>  Following regulators of the RK818 PMIC block are supported. Note that
>  the 'n' in regulator name, as in DCDC_REGn or LDOn, represents the DCDC or LDO
>  number as described in RK818 datasheet.
> @@ -99,6 +147,14 @@ number as described in RK818 datasheet.
>  	- HDMI_SWITCH
>  	- OTG_SWITCH
>  
> +There are three pins needed to config for each of RK809 and RK817,
> +named "gpio_ts" "gpio_gt" "gpio_slp".
> +	The gpio_gt and gpio_ts pins support the gpio function.
> +	The gpio_slp pin is for controlling the pmic states, as below:
> +		- reset
> +		- power down
> +		- sleep
> +
>  Standard regulator bindings are used inside regulator subnodes. Check
>    Documentation/devicetree/bindings/regulator/regulator.txt
>  for more details

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH v3 1/5] mfd: rk808: Add RK817 and RK809 support
  2018-09-11 11:47   ` Lee Jones
@ 2018-10-23  3:12     ` tony
  2018-10-23  6:26       ` Lee Jones
  0 siblings, 1 reply; 16+ messages in thread
From: tony @ 2018-10-23  3:12 UTC (permalink / raw)
  To: Lee Jones
  Cc: heiko, broonie, robh+dt, mark.rutland, a.zummo,
	alexandre.belloni, sboyd, linux-clk, linux-rtc, linux-arm-kernel,
	linux-rockchip, devicetree, linux-kernel, chenjh, xsf, zhangqing,
	huangtao


> On Fri, 24 Aug 2018, Tony Xie wrote:
>
>>      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       | 218 +++++++++++++++++++++++++++++++++++++++++++++-
>>   include/linux/mfd/rk808.h | 172 ++++++++++++++++++++++++++++++++++++
>>   kernel/reboot.c           |   1 +
>>   4 files changed, 391 insertions(+), 6 deletions(-)
>>
>> 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.
> Any reason why you've taken these out of order?
>
>>   	  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..62e2fe1 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),	\
>> +	}
> If this is helpful for you, it will be helpful for others.
>
> Please submit this to the Regmap subsystem.
>
> See: include/linux/regmap.h
>
>> +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");
> This isn't a good warning to an end user.
>
> Where is "here"?
>
> Please provide something a little more forthcoming/descriptive.
>
>> +		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");
> Again, what does this mean to an end user?  Probably very little.
>
>> +		}
>> +		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" },
>>   	{ },
>>   };
>> @@ -438,10 +586,11 @@ static int rk808_probe(struct i2c_client *client,
>>   	struct rk808 *rk808;
>>   	const struct rk808_reg_data *pre_init_reg;
>>   	const struct mfd_cell *cells;
>> -	void (*pm_pwroff_fn)(void);
>> +	void (*pm_pwroff_fn)(void) = NULL;
>>   	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;
> Please place these on separate lines.
>
>>   	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;
>> +	}
> Rather than pre-assign default values at declaration, I think it would
> be cleaner to have an else here.
>
>>   	/* 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,
>> +};
> Looks like you want SIMPLE_DEV_PM_OPS() here.
>
>>   static const struct i2c_device_id rk808_ids[] = {
>>   	{ "rk805" },
>>   	{ "rk808" },
>> +	{ "rk809" },
>> +	{ "rk817" },
>>   	{ "rk818" },
>>   	{ },
>>   };
> I don't think this table is required anymore.
>
> Try removing it.
>
>> @@ -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,
>>   };
>>   
>> diff --git a/kernel/reboot.c b/kernel/reboot.c
>> index e4ced88..83810d7 100644
>> --- a/kernel/reboot.c
>> +++ b/kernel/reboot.c
>> @@ -49,6 +49,7 @@
>>    */
>>   
>>   void (*pm_power_off_prepare)(void);
>> +EXPORT_SYMBOL_GPL(pm_power_off_prepare);
> Why do you need this where no other driver in the kernel does?
     There is a gpio_slp pin for RK809 and RK817,this pin has 
reset、power down and sleep functions,so
     when system is going to power down, this pin is needed to switch to 
power down function,and then we just only control
     this pin to high to power down the system in atf at last。
>
>>   /**
>>    *	emergency_restart - reboot the system



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

* Re: [PATCH v3 1/5] mfd: rk808: Add RK817 and RK809 support
  2018-10-23  3:12     ` tony
@ 2018-10-23  6:26       ` Lee Jones
  2018-10-23  7:21         ` tony
  0 siblings, 1 reply; 16+ messages in thread
From: Lee Jones @ 2018-10-23  6:26 UTC (permalink / raw)
  To: tony
  Cc: heiko, broonie, robh+dt, mark.rutland, a.zummo,
	alexandre.belloni, sboyd, linux-clk, linux-rtc, linux-arm-kernel,
	linux-rockchip, devicetree, linux-kernel, chenjh, xsf, zhangqing,
	huangtao

> > >      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       | 218 +++++++++++++++++++++++++++++++++++++++++++++-
> > >   include/linux/mfd/rk808.h | 172 ++++++++++++++++++++++++++++++++++++
> > >   kernel/reboot.c           |   1 +
> > >   4 files changed, 391 insertions(+), 6 deletions(-)

[...]

> > > diff --git a/kernel/reboot.c b/kernel/reboot.c
> > > index e4ced88..83810d7 100644
> > > --- a/kernel/reboot.c
> > > +++ b/kernel/reboot.c
> > > @@ -49,6 +49,7 @@
> > >    */
> > >   void (*pm_power_off_prepare)(void);
> > > +EXPORT_SYMBOL_GPL(pm_power_off_prepare);
> > Why do you need this where no other driver in the kernel does?
>     There is a gpio_slp pin for RK809 and RK817,this pin has reset、power
> down and sleep functions,so
>     when system is going to power down, this pin is needed to switch to
> power down function,and then we just only control
>     this pin to high to power down the system in atf at last。

There are other PM call-backs that you can use for this.  There
shouldn't be any requirement to export and call functions at this
level directly.

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH v3 1/5] mfd: rk808: Add RK817 and RK809 support
  2018-10-23  6:26       ` Lee Jones
@ 2018-10-23  7:21         ` tony
  0 siblings, 0 replies; 16+ messages in thread
From: tony @ 2018-10-23  7:21 UTC (permalink / raw)
  To: Lee Jones
  Cc: heiko, broonie, robh+dt, mark.rutland, a.zummo,
	alexandre.belloni, sboyd, linux-clk, linux-rtc, linux-arm-kernel,
	linux-rockchip, devicetree, linux-kernel, chenjh, xsf, zhangqing,
	huangtao



在 2018/10/23 14:26, Lee Jones 写道:
>>>>       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       | 218 +++++++++++++++++++++++++++++++++++++++++++++-
>>>>    include/linux/mfd/rk808.h | 172 ++++++++++++++++++++++++++++++++++++
>>>>    kernel/reboot.c           |   1 +
>>>>    4 files changed, 391 insertions(+), 6 deletions(-)
> [...]
>
>>>> diff --git a/kernel/reboot.c b/kernel/reboot.c
>>>> index e4ced88..83810d7 100644
>>>> --- a/kernel/reboot.c
>>>> +++ b/kernel/reboot.c
>>>> @@ -49,6 +49,7 @@
>>>>     */
>>>>    void (*pm_power_off_prepare)(void);
>>>> +EXPORT_SYMBOL_GPL(pm_power_off_prepare);
>>> Why do you need this where no other driver in the kernel does?
>>      There is a gpio_slp pin for RK809 and RK817,this pin has reset、power
>> down and sleep functions,so
>>      when system is going to power down, this pin is needed to switch to
>> power down function,and then we just only control
>>      this pin to high to power down the system in atf at last。
> There are other PM call-backs that you can use for this.  There
> shouldn't be any requirement to export and call functions at this
> level directly.
     I will use a shutdown call-backs from syscore to implement it.
>



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

end of thread, other threads:[~2018-10-23  7:22 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-24  3:30 [PATCH v3 0/5] support a new type of PMIC,including two chips(rk817 and rk809) Tony Xie
2018-08-24  3:30 ` [PATCH v3 1/5] mfd: rk808: Add RK817 and RK809 support Tony Xie
2018-09-11 11:47   ` Lee Jones
2018-10-23  3:12     ` tony
2018-10-23  6:26       ` Lee Jones
2018-10-23  7:21         ` tony
2018-08-24  3:30 ` [PATCH v3 2/5] regulator: rk808: add RK809 and RK817 support Tony Xie
2018-08-24 12:23   ` Wadim Egorov
2018-08-24  3:30 ` [PATCH v3 3/5] dt-bindings: mfd: rk808: Add binding information for RK809 and RK817 Tony Xie
2018-08-28 22:40   ` Rob Herring
2018-09-11 12:37   ` Lee Jones
2018-08-24  3:30 ` [PATCH v3 4/5] rtc: rk808: add RK809 and RK817 support Tony Xie
2018-08-27 21:14   ` Alexandre Belloni
2018-08-24  3:35 ` Tony Xie
2018-08-24  3:36 ` [PATCH v3 5/5] clk: RK808: " Tony Xie
2018-08-31 17:34   ` Stephen Boyd

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).