From a641dc6e3942e686951b51cf271a58d827001950 Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 1 Oct 2024 12:21:00 +0000 Subject: [PATCH] rk818-charger: update rk8xx-{core,i2c}.c with patches from megi's kernel tree that add compat to rk818 --- pkgs/additional/rk818-charger/Makefile | 7 +- pkgs/additional/rk818-charger/rk818.h | 84 +++++++++++++++++++ pkgs/additional/rk818-charger/rk818_battery.c | 2 + pkgs/additional/rk818-charger/rk818_charger.c | 2 + pkgs/additional/rk818-charger/rk8xx-core.c | 5 ++ pkgs/additional/rk818-charger/rk8xx-i2c.c | 40 ++++++++- 6 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 pkgs/additional/rk818-charger/rk818.h diff --git a/pkgs/additional/rk818-charger/Makefile b/pkgs/additional/rk818-charger/Makefile index ea56e73b4..dfb83f380 100644 --- a/pkgs/additional/rk818-charger/Makefile +++ b/pkgs/additional/rk818-charger/Makefile @@ -1,4 +1,9 @@ -obj-m := rk8xx-core.o rk8xx-i2c.o rk818_charger.o rk818_battery.o +obj-m := rk8xx-core.o rk8xx-i2c.o rk818_battery.o rk818_charger.o all: $(MAKE) -C "$(KERNEL_DIR)" M="$(PWD)" modules +install: + install -D rk8xx-core.ko $(INSTALL_MOD_PATH)/mfd/rk8xx-core.ko + install -D rk8xx-i2c.ko $(INSTALL_MOD_PATH)/mfd/rk8xx-i2c.ko + install -D rk818_battery.ko $(INSTALL_MOD_PATH)/mfd/rk818_battery.ko + install -D rk818_charger.ko $(INSTALL_MOD_PATH)/mfd/rk818_charger.ko diff --git a/pkgs/additional/rk818-charger/rk818.h b/pkgs/additional/rk818-charger/rk818.h new file mode 100644 index 000000000..4bad961c1 --- /dev/null +++ b/pkgs/additional/rk818-charger/rk818.h @@ -0,0 +1,84 @@ +// things already #define'd in rk808.h are omitted here +#define RK818_VB_MON_REG 0x21 +#define RK818_THERMAL_REG 0x22 +#define RK818_OTP_VDD_EN_REG 0x51 +#define RK818_DCDC_ILMAX_REG 0x90 +#define RK818_CHRG_COMP_REG 0x9a +#define RK818_SUP_STS_REG 0xa0 +#define RK818_CHRG_CTRL_REG1 0xa3 +#define RK818_CHRG_CTRL_REG2 0xa4 +#define RK818_CHRG_CTRL_REG3 0xa5 +#define RK818_BAT_CTRL_REG 0xa6 +#define RK818_BAT_HTS_TS1_REG 0xa8 +#define RK818_BAT_LTS_TS1_REG 0xa9 +#define RK818_BAT_HTS_TS2_REG 0xaa +#define RK818_BAT_LTS_TS2_REG 0xab +#define RK818_TS_CTRL_REG 0xac +#define RK818_ADC_CTRL_REG 0xad +#define RK818_ON_SOURCE_REG 0xae +#define RK818_OFF_SOURCE_REG 0xaf +#define RK818_GGCON_REG 0xb0 +#define RK818_GGSTS_REG 0xb1 +#define RK818_FRAME_SMP_INTERV_REG 0xb2 +#define RK818_AUTO_SLP_CUR_THR_REG 0xb3 +#define RK818_GASCNT_CAL_REG3 0xb4 +#define RK818_GASCNT_CAL_REG2 0xb5 +#define RK818_GASCNT_CAL_REG1 0xb6 +#define RK818_GASCNT_CAL_REG0 0xb7 +#define RK818_GASCNT3_REG 0xb8 +#define RK818_GASCNT2_REG 0xb9 +#define RK818_GASCNT1_REG 0xba +#define RK818_GASCNT0_REG 0xbb +#define RK818_BAT_CUR_AVG_REGH 0xbc +#define RK818_BAT_CUR_AVG_REGL 0xbd +#define RK818_TS1_ADC_REGH 0xbe +#define RK818_TS1_ADC_REGL 0xbf +#define RK818_TS2_ADC_REGH 0xc0 +#define RK818_TS2_ADC_REGL 0xc1 +#define RK818_BAT_OCV_REGH 0xc2 +#define RK818_BAT_OCV_REGL 0xc3 +#define RK818_BAT_VOL_REGH 0xc4 +#define RK818_BAT_VOL_REGL 0xc5 +#define RK818_RELAX_ENTRY_THRES_REGH 0xc6 +#define RK818_RELAX_ENTRY_THRES_REGL 0xc7 +#define RK818_RELAX_EXIT_THRES_REGH 0xc8 +#define RK818_RELAX_EXIT_THRES_REGL 0xc9 +#define RK818_RELAX_VOL1_REGH 0xca +#define RK818_RELAX_VOL1_REGL 0xcb +#define RK818_RELAX_VOL2_REGH 0xcc +#define RK818_RELAX_VOL2_REGL 0xcd +#define RK818_BAT_CUR_R_CALC_REGH 0xce +#define RK818_BAT_CUR_R_CALC_REGL 0xcf +#define RK818_BAT_VOL_R_CALC_REGH 0xd0 +#define RK818_BAT_VOL_R_CALC_REGL 0xd1 +#define RK818_CAL_OFFSET_REGH 0xd2 +#define RK818_CAL_OFFSET_REGL 0xd3 +#define RK818_NON_ACT_TIMER_CNT_REG 0xd4 +#define RK818_VCALIB0_REGH 0xd5 +#define RK818_VCALIB0_REGL 0xd6 +#define RK818_VCALIB1_REGH 0xd7 +#define RK818_VCALIB1_REGL 0xd8 +#define RK818_IOFFSET_REGH 0xdd +#define RK818_IOFFSET_REGL 0xde +#define RK818_SOC_REG 0xe0 +#define RK818_REMAIN_CAP_REG3 0xe1 +#define RK818_REMAIN_CAP_REG2 0xe2 +#define RK818_REMAIN_CAP_REG1 0xe3 +#define RK818_REMAIN_CAP_REG0 0xe4 +#define RK818_UPDAT_LEVE_REG 0xe5 +#define RK818_NEW_FCC_REG3 0xe6 +#define RK818_NEW_FCC_REG2 0xe7 +#define RK818_NEW_FCC_REG1 0xe8 +#define RK818_NEW_FCC_REG0 0xe9 +#define RK818_NON_ACT_TIMER_CNT_SAVE_REG 0xea +#define RK818_OCV_VOL_VALID_REG 0xeb +#define RK818_REBOOT_CNT_REG 0xec +#define RK818_POFFSET_REG 0xed +#define RK818_MISC_MARK_REG 0xee +#define RK818_HALT_CNT_REG 0xef +#define RK818_CALC_REST_REGH 0xf0 +#define RK818_CALC_REST_REGL 0xf1 +#define RK818_SAVE_DATA19 0xf2 + +#define CLK32KOUT2_FUNC (0 << 1) +#define CLK32KOUT2_FUNC_MASK BIT(1) diff --git a/pkgs/additional/rk818-charger/rk818_battery.c b/pkgs/additional/rk818-charger/rk818_battery.c index b62d59a4b..5235c338b 100644 --- a/pkgs/additional/rk818-charger/rk818_battery.c +++ b/pkgs/additional/rk818-charger/rk818_battery.c @@ -39,6 +39,8 @@ #include #include "rk818_battery.h" +#include "rk818.h" + static int dbg_enable = 0; module_param_named(dbg_level, dbg_enable, int, 0644); diff --git a/pkgs/additional/rk818-charger/rk818_charger.c b/pkgs/additional/rk818-charger/rk818_charger.c index 1ec41b563..75978adeb 100644 --- a/pkgs/additional/rk818-charger/rk818_charger.c +++ b/pkgs/additional/rk818-charger/rk818_charger.c @@ -14,6 +14,8 @@ #include #include +#include "rk818.h" + #define RK818_CHG_STS_MASK (7u << 4) /* charger status */ #define RK818_CHG_STS_NONE (0u << 4) #define RK818_CHG_STS_WAKEUP_CUR (1u << 4) diff --git a/pkgs/additional/rk818-charger/rk8xx-core.c b/pkgs/additional/rk818-charger/rk8xx-core.c index 39ab114ea..ba9fabe5a 100644 --- a/pkgs/additional/rk818-charger/rk8xx-core.c +++ b/pkgs/additional/rk818-charger/rk8xx-core.c @@ -18,6 +18,8 @@ #include #include +#include "rk818.h" + struct rk808_reg_data { int addr; int mask; @@ -131,6 +133,8 @@ static const struct mfd_cell rk817s[] = { static const struct mfd_cell rk818s[] = { { .name = "rk808-clkout", }, { .name = "rk808-regulator", }, + { .name = "rk818-battery", .of_compatible = "rockchip,rk818-battery", }, + { .name = "rk818-charger", .of_compatible = "rockchip,rk818-charger", }, { .name = "rk808-rtc", .num_resources = ARRAY_SIZE(rtc_resources), @@ -281,6 +285,7 @@ static const struct rk808_reg_data rk818_pre_init_reg[] = { { RK818_H5V_EN_REG, BIT(0), RK818_H5V_EN }, { RK808_VB_MON_REG, MASK_ALL, VB_LO_ACT | VB_LO_SEL_3500MV }, + { RK808_CLK32OUT_REG, CLK32KOUT2_FUNC_MASK, CLK32KOUT2_FUNC }, }; static const struct regmap_irq rk805_irqs[] = { diff --git a/pkgs/additional/rk818-charger/rk8xx-i2c.c b/pkgs/additional/rk818-charger/rk8xx-i2c.c index 37287b06d..21af7e56d 100644 --- a/pkgs/additional/rk818-charger/rk8xx-i2c.c +++ b/pkgs/additional/rk818-charger/rk8xx-i2c.c @@ -16,6 +16,8 @@ #include #include +#include "rk818.h" + struct rk8xx_i2c_platform_data { const struct regmap_config *regmap_cfg; int variant; @@ -115,13 +117,47 @@ static bool rk817_is_volatile_reg(struct device *dev, unsigned int reg) return false; } +static bool rk818_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 RK808_SECONDS_REG ... RK808_WEEKS_REG: + case RK808_RTC_STATUS_REG: + case RK808_VB_MON_REG: + case RK808_THERMAL_REG: + case RK808_DCDC_EN_REG: + case RK808_LDO_EN_REG: + case RK808_DCDC_UV_STS_REG: + case RK808_LDO_UV_STS_REG: + case RK808_DCDC_PG_REG: + case RK808_LDO_PG_REG: + case RK808_DEVCTRL_REG: + case RK808_INT_STS_REG1: + case RK808_INT_STS_REG2: + case RK808_INT_STS_MSK_REG1: + case RK808_INT_STS_MSK_REG2: + case RK818_LDO8_ON_VSEL_REG: // TODO(ayufan):?? + case RK818_LDO8_SLP_VSEL_REG: // TODO(ayufan):?? + case RK818_SUP_STS_REG ... RK818_SAVE_DATA19: + return true; + } + + return false; +} static const struct regmap_config rk818_regmap_config = { .reg_bits = 8, .val_bits = 8, - .max_register = RK818_USB_CTRL_REG, + .max_register = RK818_SAVE_DATA19, .cache_type = REGCACHE_MAPLE, - .volatile_reg = rk808_is_volatile_reg, + .volatile_reg = rk818_is_volatile_reg, }; static const struct regmap_config rk805_regmap_config = {