pmaports/device/archived/linux-xiaomi-wt88047-downstream/smb1360-dump-wt88047.patch

81 lines
2.4 KiB
Diff
Raw Normal View History

Dump all known registers of the SMB1360 battery/charging chip.
The same output can be generated with the mainline driver which allows verifying
if all the registers are set correctly.
(Note: Separate patch needed for wt88047 because it uses a slightly custom
smb1360-charger-fg driver...)
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 3f93c7636c8..24e48c337e4 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -1,6 +1,7 @@
ccflags-$(CONFIG_POWER_SUPPLY_DEBUG) := -DDEBUG
power_supply-y := power_supply_core.o
+power_supply-y += smb1360-dump.o
power_supply-$(CONFIG_SYSFS) += power_supply_sysfs.o
power_supply-$(CONFIG_LEDS_TRIGGERS) += power_supply_leds.o
diff --git a/drivers/power/smb1360-charger-fg-wt88047.c b/drivers/power/smb1360-charger-fg-wt88047.c
index fa03089b8b7..73ccd8d059e 100644
--- a/drivers/power/smb1360-charger-fg-wt88047.c
+++ b/drivers/power/smb1360-charger-fg-wt88047.c
@@ -3452,6 +3452,38 @@ static int smb1360_jeita_init(struct smb1360_chip *chip)
return rc;
}
+extern void smb1360_dump(struct i2c_client *client);
+extern void smb1360_dump_fg_scratch(struct i2c_client *fg_client);
+extern void smb1360_dump_fg(struct i2c_client *client);
+
+static void smb1360_dump_all(struct smb1360_chip *chip)
+{
+ int ret;
+
+ mutex_lock(&chip->read_write_lock);
+ smb1360_dump(chip->client);
+ mutex_unlock(&chip->read_write_lock);
+
+ ret = smb1360_enable_fg_access(chip);
+ if (ret)
+ return;
+
+ mutex_lock(&chip->read_write_lock);
+ smb1360_dump_fg_scratch(chip->client);
+
+ /* Do cool hacks to access FG I2C address instead */
+ chip->fg_access_type = FG_ACCESS_CFG;
+ smb1360_select_fg_i2c_address(chip);
+
+ chip->client->addr = chip->fg_i2c_addr;
+ smb1360_dump_fg(chip->client);
+ chip->client->addr = chip->default_i2c_addr;
+ mutex_unlock(&chip->read_write_lock);
+
+ smb1360_disable_fg_access(chip);
+ smb1360_check_cycle_stretch(chip);
+}
+
static int smb1360_hw_init(struct smb1360_chip *chip)
{
int rc;
@@ -3460,6 +3492,9 @@ static int smb1360_hw_init(struct smb1360_chip *chip)
smb1360_check_feature_support(chip);
+ /* Dump initial registers */
+ smb1360_dump_all(chip);
+
rc = smb1360_enable_volatile_writes(chip);
if (rc < 0) {
dev_err(chip->dev, "Couldn't configure for volatile rc = %d\n",
@@ -3787,6 +3822,8 @@ static int smb1360_hw_init(struct smb1360_chip *chip)
return rc;
}
+ /* Dump final registers */
+ smb1360_dump_all(chip);
return rc;
}