git: 43301ad2b63c - main - pmic: rockchip: Add dedicated file for rk808

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Sun, 14 Nov 2021 12:34:21 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=43301ad2b63c19532b13f3a85c9c46f9a8b11516

commit 43301ad2b63c19532b13f3a85c9c46f9a8b11516
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2021-11-11 18:18:57 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2021-11-14 11:31:12 +0000

    pmic: rockchip: Add dedicated file for rk808
    
    While here rename registers for rk805 and rk808 based on the names
    on the datasheet.
    
    No functional changes intended.
---
 sys/dev/iicbus/pmic/rockchip/rk805.c    |  47 ++++++------
 sys/dev/iicbus/pmic/rockchip/rk805reg.h |  90 +++++++++-------------
 sys/dev/iicbus/pmic/rockchip/rk808reg.h | 127 ++++++++++++++++++++++++++++++++
 3 files changed, 185 insertions(+), 79 deletions(-)

diff --git a/sys/dev/iicbus/pmic/rockchip/rk805.c b/sys/dev/iicbus/pmic/rockchip/rk805.c
index 27e9e3a5287e..14996a792739 100644
--- a/sys/dev/iicbus/pmic/rockchip/rk805.c
+++ b/sys/dev/iicbus/pmic/rockchip/rk805.c
@@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
 #include <dev/extres/regulator/regulator.h>
 
 #include <dev/iicbus/pmic/rockchip/rk805reg.h>
+#include <dev/iicbus/pmic/rockchip/rk808reg.h>
 
 #include "clock_if.h"
 #include "regdev_if.h"
@@ -114,11 +115,11 @@ static int rk805_regnode_get_voltage(struct regnode *regnode, int *uvolt);
 
 static struct rk805_regdef rk805_regdefs[] = {
 	{
-		.id = RK805_DCDC1,
+		.id = RK805_BUCK1,
 		.name = "DCDC_REG1",
 		.enable_reg = RK805_DCDC_EN,
 		.enable_mask = 0x11,
-		.voltage_reg = RK805_DCDC1_ON_VSEL,
+		.voltage_reg = RK805_BUCK1_ON_VSEL,
 		.voltage_mask = 0x3F,
 		.voltage_min = 712500,
 		.voltage_max = 1450000,
@@ -126,11 +127,11 @@ static struct rk805_regdef rk805_regdefs[] = {
 		.voltage_nstep = 64,
 	},
 	{
-		.id = RK805_DCDC2,
+		.id = RK805_BUCK2,
 		.name = "DCDC_REG2",
 		.enable_reg = RK805_DCDC_EN,
 		.enable_mask = 0x22,
-		.voltage_reg = RK805_DCDC2_ON_VSEL,
+		.voltage_reg = RK805_BUCK2_ON_VSEL,
 		.voltage_mask = 0x3F,
 		.voltage_min = 712500,
 		.voltage_max = 1450000,
@@ -138,17 +139,17 @@ static struct rk805_regdef rk805_regdefs[] = {
 		.voltage_nstep = 64,
 	},
 	{
-		.id = RK805_DCDC3,
+		.id = RK805_BUCK3,
 		.name = "DCDC_REG3",
 		.enable_reg = RK805_DCDC_EN,
 		.enable_mask = 0x44,
 	},
 	{
-		.id = RK805_DCDC4,
+		.id = RK805_BUCK4,
 		.name = "DCDC_REG4",
 		.enable_reg = RK805_DCDC_EN,
 		.enable_mask = 0x88,
-		.voltage_reg = RK805_DCDC4_ON_VSEL,
+		.voltage_reg = RK805_BUCK4_ON_VSEL,
 		.voltage_mask = 0x3F,
 		.voltage_min = 800000,
 		.voltage_max = 3500000,
@@ -195,11 +196,11 @@ static struct rk805_regdef rk805_regdefs[] = {
 
 static struct rk805_regdef rk808_regdefs[] = {
 	{
-		.id = RK805_DCDC1,
+		.id = RK808_BUCK1,
 		.name = "DCDC_REG1",
-		.enable_reg = RK805_DCDC_EN,
+		.enable_reg = RK808_DCDC_EN,
 		.enable_mask = 0x1,
-		.voltage_reg = RK805_DCDC1_ON_VSEL,
+		.voltage_reg = RK808_BUCK1_ON_VSEL,
 		.voltage_mask = 0x3F,
 		.voltage_min = 712500,
 		.voltage_max = 1500000,
@@ -207,11 +208,11 @@ static struct rk805_regdef rk808_regdefs[] = {
 		.voltage_nstep = 64,
 	},
 	{
-		.id = RK805_DCDC2,
+		.id = RK808_BUCK2,
 		.name = "DCDC_REG2",
-		.enable_reg = RK805_DCDC_EN,
+		.enable_reg = RK808_DCDC_EN,
 		.enable_mask = 0x2,
-		.voltage_reg = RK805_DCDC2_ON_VSEL,
+		.voltage_reg = RK808_BUCK2_ON_VSEL,
 		.voltage_mask = 0x3F,
 		.voltage_min = 712500,
 		.voltage_max = 1500000,
@@ -220,17 +221,17 @@ static struct rk805_regdef rk808_regdefs[] = {
 	},
 	{
 		/* BUCK3 voltage is calculated based on external resistor */
-		.id = RK805_DCDC3,
+		.id = RK808_BUCK3,
 		.name = "DCDC_REG3",
-		.enable_reg = RK805_DCDC_EN,
+		.enable_reg = RK808_DCDC_EN,
 		.enable_mask = 0x4,
 	},
 	{
-		.id = RK805_DCDC4,
+		.id = RK808_BUCK4,
 		.name = "DCDC_REG4",
-		.enable_reg = RK805_DCDC_EN,
+		.enable_reg = RK808_DCDC_EN,
 		.enable_mask = 0x8,
-		.voltage_reg = RK805_DCDC4_ON_VSEL,
+		.voltage_reg = RK808_BUCK4_ON_VSEL,
 		.voltage_mask = 0xF,
 		.voltage_min = 1800000,
 		.voltage_max = 3300000,
@@ -242,7 +243,7 @@ static struct rk805_regdef rk808_regdefs[] = {
 		.name = "LDO_REG1",
 		.enable_reg = RK808_LDO_EN,
 		.enable_mask = 0x1,
-		.voltage_reg = RK805_LDO1_ON_VSEL,
+		.voltage_reg = RK808_LDO1_ON_VSEL,
 		.voltage_mask = 0x1F,
 		.voltage_min = 1800000,
 		.voltage_max = 3400000,
@@ -254,7 +255,7 @@ static struct rk805_regdef rk808_regdefs[] = {
 		.name = "LDO_REG2",
 		.enable_reg = RK808_LDO_EN,
 		.enable_mask = 0x2,
-		.voltage_reg = RK805_LDO2_ON_VSEL,
+		.voltage_reg = RK808_LDO2_ON_VSEL,
 		.voltage_mask = 0x1F,
 		.voltage_min = 1800000,
 		.voltage_max = 3400000,
@@ -266,7 +267,7 @@ static struct rk805_regdef rk808_regdefs[] = {
 		.name = "LDO_REG3",
 		.enable_reg = RK808_LDO_EN,
 		.enable_mask = 0x4,
-		.voltage_reg = RK805_LDO3_ON_VSEL,
+		.voltage_reg = RK808_LDO3_ON_VSEL,
 		.voltage_mask = 0xF,
 		.voltage_min = 800000,
 		.voltage_max = 2500000,
@@ -336,7 +337,7 @@ static struct rk805_regdef rk808_regdefs[] = {
 	{
 		.id = RK808_SWITCH1,
 		.name = "SWITCH_REG1",
-		.enable_reg = RK805_DCDC_EN,
+		.enable_reg = RK808_DCDC_EN,
 		.enable_mask = 0x20,
 		.voltage_min = 3000000,
 		.voltage_max = 3000000,
@@ -344,7 +345,7 @@ static struct rk805_regdef rk808_regdefs[] = {
 	{
 		.id = RK808_SWITCH2,
 		.name = "SWITCH_REG2",
-		.enable_reg = RK805_DCDC_EN,
+		.enable_reg = RK808_DCDC_EN,
 		.enable_mask = 0x40,
 		.voltage_min = 3000000,
 		.voltage_max = 3000000,
diff --git a/sys/dev/iicbus/pmic/rockchip/rk805reg.h b/sys/dev/iicbus/pmic/rockchip/rk805reg.h
index 61c6f49abd2c..449ac9bdab7a 100644
--- a/sys/dev/iicbus/pmic/rockchip/rk805reg.h
+++ b/sys/dev/iicbus/pmic/rockchip/rk805reg.h
@@ -30,98 +30,76 @@
 #ifndef _RK805REG_H_
 #define	 _RK805REG_H_
 
-/*
- * The RTC registers are the same in both RK805 and RK808.
- * Note that the code assumes that RK805_RTC_SECS is 0
- */
+/* RTC registers */
 #define	RK805_RTC_SECS		0x00
-#define	RK805_RTC_SECS_MASK	0x7f
+#define	 RK805_RTC_SECS_MASK	0x7f
 #define	RK805_RTC_MINUTES	0x01
-#define	RK805_RTC_MINUTES_MASK	0x7f
+#define	 RK805_RTC_MINUTES_MASK	0x7f
 #define	RK805_RTC_HOURS		0x02
-#define	RK805_RTC_HOURS_MASK	0x3f
+#define	 RK805_RTC_HOURS_MASK	0x3f
 #define	RK805_RTC_HOURS_PM	0x80
 #define	RK805_RTC_DAYS		0x03
-#define	RK805_RTC_DAYS_MASK	0x3f
+#define	 RK805_RTC_DAYS_MASK	0x3f
 #define	RK805_RTC_MONTHS	0x04
-#define	RK805_RTC_MONTHS_MASK	0x1f
+#define	 RK805_RTC_MONTHS_MASK	0x1f
 #define	RK805_RTC_YEARS		0x05
 #define	RK805_RTC_WEEKS		0x06 /* day of week */
-#define	RK805_RTC_WEEKS_MASK	0x07
-
+#define	 RK805_RTC_WEEKS_MASK	0x07
+#define	RK805_ALARM_SECONDS	0x8
+#define	RK805_ALARM_MINUTES	0x9
+#define	RK805_ALARM_HOURS	0xA
+#define	RK805_ALARM_DAYS	0xB
+#define	RK805_ALARM_MONTHS	0xC
+#define	RK805_ALARM_YEARS	0xD
 #define	RK805_RTC_CTRL		0x10
 #define	 RK805_RTC_CTRL_STOP	(1 << 0)
 #define	 RK805_RTC_AMPM_MODE	(1 << 3)
 #define	 RK805_RTC_GET_TIME	(1 << 6)
 #define	 RK805_RTC_READSEL	(1 << 7)
+#define	RK805_CLK32KOUT		0x20
 
+/* Version registers */
 #define	RK805_CHIP_NAME		0x17
 #define	RK805_CHIP_VER		0x18
 #define	RK805_OTP_VER		0x19
 
+/* Power channel enable registers */
 #define	RK805_DCDC_EN		0x23
-#define	RK808_LDO_EN		0x24
-#define	RK805_SLEEP_DCDC_EN	0x25
-#define	RK805_SLEEP_LDO_EN	0x26
+#define	RK805_SLP_DCDC_EN	0x25
+#define	RK805_SLP_LDO_EN	0x26
 #define	RK805_LDO_EN		0x27
-#define	RK805_SLEEP_LDO_LP_EN	0x2A
+#define	RK805_BUCK_LDO_SLP_LP	0x2A
 
-#define	RK805_DCDC1_CONFIG	0x2E
-#define	RK805_DCDC1_ON_VSEL	0x2F
-#define	RK805_DCDC1_SLEEP_VSEL	0x30
-#define	RK805_DCDC2_CONFIG	0x32
-#define	RK805_DCDC2_ON_VSEL	0x33
-#define	RK805_DCDC2_SLEEP_VSEL	0x34
-#define	RK805_DCDC3_CONFIG	0x36
-#define	RK805_DCDC4_CONFIG	0x37
-#define	RK805_DCDC4_ON_VSEL	0x38
-#define	RK805_DCDC4_SLEEP_VSEL	0x39
+/* Buck and LDO configuration registers */
+#define	RK805_BUCK1_CONFIG	0x2E
+#define	RK805_BUCK1_ON_VSEL	0x2F
+#define	RK805_BUCK1_SLEEP_VSEL	0x30
+#define	RK805_BUCK2_CONFIG	0x32
+#define	RK805_BUCK2_ON_VSEL	0x33
+#define	RK805_BUCK2_SLEEP_VSEL	0x34
+#define	RK805_BUCK3_CONFIG	0x36
+#define	RK805_BUCK4_CONFIG	0x37
+#define	RK805_BUCK4_ON_VSEL	0x38
+#define	RK805_BUCK4_SLEEP_VSEL	0x39
 #define	RK805_LDO1_ON_VSEL	0x3B
 #define	RK805_LDO1_SLEEP_VSEL	0x3C
 #define	RK805_LDO2_ON_VSEL	0x3D
 #define	RK805_LDO2_SLEEP_VSEL	0x3E
 #define	RK805_LDO3_ON_VSEL	0x3F
 #define	RK805_LDO3_SLEEP_VSEL	0x40
-#define	RK808_LDO4_ON_VSEL	0x41
-#define	RK808_LDO4_SLEEP_VSEL	0x42
-#define	RK808_LDO5_ON_VSEL	0x43
-#define	RK808_LDO5_SLEEP_VSEL	0x44
-#define	RK808_LDO6_ON_VSEL	0x45
-#define	RK808_LDO6_SLEEP_VSEL	0x46
-#define	RK808_LDO7_ON_VSEL	0x47
-#define	RK808_LDO7_SLEEP_VSEL	0x48
-#define	RK808_LDO8_ON_VSEL	0x49
-#define	RK808_LDO8_SLEEP_VSEL	0x4A
 
 #define	RK805_DEV_CTRL		0x4B
 #define	 RK805_DEV_CTRL_OFF	(1 << 0)
 #define	 RK805_DEV_CTRL_SLP	(1 << 1)
 
 enum rk805_regulator {
-	RK805_DCDC1 = 0,
-	RK805_DCDC2,
-	RK805_DCDC3,
-	RK805_DCDC4,
+	RK805_BUCK1 = 0,
+	RK805_BUCK2,
+	RK805_BUCK3,
+	RK805_BUCK4,
 	RK805_LDO1,
 	RK805_LDO2,
 	RK805_LDO3,
 };
 
-enum rk808_regulator {
-	RK808_DCDC1 = 0,
-	RK808_DCDC2,
-	RK808_DCDC3,
-	RK808_DCDC4,
-	RK808_LDO1,
-	RK808_LDO2,
-	RK808_LDO3,
-	RK808_LDO4,
-	RK808_LDO5,
-	RK808_LDO6,
-	RK808_LDO7,
-	RK808_LDO8,
-	RK808_SWITCH1,
-	RK808_SWITCH2,
-};
-
 #endif /* _RK805REG_H_ */
diff --git a/sys/dev/iicbus/pmic/rockchip/rk808reg.h b/sys/dev/iicbus/pmic/rockchip/rk808reg.h
new file mode 100644
index 000000000000..054cac45f1d6
--- /dev/null
+++ b/sys/dev/iicbus/pmic/rockchip/rk808reg.h
@@ -0,0 +1,127 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2018-2021 Emmanuel Vadot <manu@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _RK808REG_H_
+#define	 _RK808REG_H_
+
+/* RTC registers */
+#define	RK808_RTC_SECS		0x00
+#define	 RK808_RTC_SECS_MASK	0x7f
+#define	RK808_RTC_MINUTES	0x01
+#define	 RK808_RTC_MINUTES_MASK	0x7f
+#define	RK808_RTC_HOURS		0x02
+#define	 RK808_RTC_HOURS_MASK	0x3f
+#define	RK808_RTC_DAYS		0x03
+#define	 RK808_RTC_DAYS_MASK	0x3f
+#define	RK808_RTC_MONTHS	0x04
+#define	 RK808_RTC_MONTHS_MASK	0x1f
+#define	RK808_RTC_YEARS		0x05
+#define	RK808_RTC_WEEKS		0x06 /* day of week */
+#define	 RK808_RTC_WEEKS_MASK	0x07
+#define	RK808_ALARM_SECONDS	0x8
+#define	RK808_ALARM_MINUTES	0x9
+#define	RK808_ALARM_HOURS	0xA
+#define	RK808_ALARM_DAYS	0xB
+#define	RK808_ALARM_MONTHS	0xC
+#define	RK808_ALARM_YEARS	0xD
+#define	RK808_RTC_CTRL		0x10
+#define	 RK808_RTC_CTRL_STOP	(1 << 0)
+#define	 RK808_RTC_AMPM_MODE	(1 << 3)
+#define	 RK808_RTC_GET_TIME	(1 << 6)
+#define	 RK808_RTC_READSEL	(1 << 7)
+#define	RK808_RTC_STATUS	0x11
+#define	RK808_RTC_INT		0x12
+#define	RK808_RTC_COMP_LSB	0x13
+#define	RK808_RTC_COMP_MSB	0x14
+
+/* Misc registers*/
+#define	RK808_CLK32KOUT		0x20
+#define	RK808_VB_MON		0x21
+#define	RK808_THERMAL		0x22
+
+/* Power channel control and monitoring registers */
+#define	RK808_DCDC_EN		0x23
+#define	RK808_LDO_EN		0x24
+#define	RK808_SLEEP_SET_OFF_1	0x25
+#define	RK808_SLEEP_SET_OFF_2	0x26
+#define	RK808_DCDC_UV_STS	0x27
+#define	RK808_DCDC_UV_ACT	0x28
+#define	RK808_LDO_UV_STS	0x29
+#define	RK808_LDO_UV_ACT	0x2A
+#define	RK808_DCDC_PG		0x2B
+#define	RK808_LDO_PG		0x2C
+#define	RK808_VOUT_MON_TDB	0x2D
+
+/* Power channel configuration registers */
+#define	RK808_BUCK1_CONFIG	0x2E
+#define	RK808_BUCK1_ON_VSEL	0x2F
+#define	RK808_BUCK1_SLP_VSEL	0x30
+#define	RK808_BUCK2_CONFIG	0x32
+#define	RK808_BUCK2_ON_VSEL	0x33
+#define	RK808_BUCK2_SLEEP_VSEL	0x34
+#define	RK808_BUCK3_CONFIG	0x36
+#define	RK808_BUCK4_CONFIG	0x37
+#define	RK808_BUCK4_ON_VSEL	0x38
+#define	RK808_BUCK4_SLEEP_VSEL	0x39
+#define	RK808_DCDC_ILMAX_REG	0x90
+#define	RK808_LDO1_ON_VSEL	0x3B
+#define	RK808_LDO1_SLEEP_VSEL	0x3C
+#define	RK808_LDO2_ON_VSEL	0x3D
+#define	RK808_LDO2_SLEEP_VSEL	0x3E
+#define	RK808_LDO3_ON_VSEL	0x3F
+#define	RK808_LDO3_SLEEP_VSEL	0x40
+#define	RK808_LDO4_ON_VSEL	0x41
+#define	RK808_LDO4_SLEEP_VSEL	0x42
+#define	RK808_LDO5_ON_VSEL	0x43
+#define	RK808_LDO5_SLEEP_VSEL	0x44
+#define	RK808_LDO6_ON_VSEL	0x45
+#define	RK808_LDO6_SLEEP_VSEL	0x46
+#define	RK808_LDO7_ON_VSEL	0x47
+#define	RK808_LDO7_SLEEP_VSEL	0x48
+#define	RK808_LDO8_ON_VSEL	0x49
+#define	RK808_LDO8_SLEEP_VSEL	0x4A
+
+enum rk808_regulator {
+	RK808_BUCK1 = 0,
+	RK808_BUCK2,
+	RK808_BUCK3,
+	RK808_BUCK4,
+	RK808_LDO1,
+	RK808_LDO2,
+	RK808_LDO3,
+	RK808_LDO4,
+	RK808_LDO5,
+	RK808_LDO6,
+	RK808_LDO7,
+	RK808_LDO8,
+	RK808_SWITCH1,
+	RK808_SWITCH2,
+};
+
+#endif /* _RK808REG_H_ */