From f291a5cfa796f4b2695ce09da16e0cbb977b3d16 Mon Sep 17 00:00:00 2001
From: CTCaer <ctcaer@gmail.com>
Date: Fri, 28 Jul 2023 03:34:11 +0300
Subject: [PATCH] bdk: max17050: add reg dumping

---
 bdk/power/max17050.c | 23 +++++++++++++++++++++++
 bdk/power/max17050.h |  7 ++++---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/bdk/power/max17050.c b/bdk/power/max17050.c
index c718d2b..8c4f658 100644
--- a/bdk/power/max17050.c
+++ b/bdk/power/max17050.c
@@ -279,3 +279,26 @@ int max17050_fix_configuration()
 
 	return 0;
 }
+
+void max17050_dump_regs(void *buf)
+{
+	u16 *buff = (u16 *)buf;
+
+	// Unlock model table.
+	u16 unlock = 0x59;
+	i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, MAX17050_MODELEnable1, (u8 *)&unlock, 2);
+	unlock = 0xC4;
+	i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, MAX17050_MODELEnable2, (u8 *)&unlock, 2);
+
+	// Dump all battery fuel gauge registers.
+	for (u32 i = 0; i < 0x100; i++)
+	{
+		buff[i] = max17050_get_reg(i);
+		msleep(1);
+	}
+
+	// Lock model table.
+	unlock = 0;
+	i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, MAX17050_MODELEnable1, (u8 *)&unlock, 2);
+	i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, MAX17050_MODELEnable2, (u8 *)&unlock, 2);
+}
diff --git a/bdk/power/max17050.h b/bdk/power/max17050.h
index a9b3d37..438f55a 100644
--- a/bdk/power/max17050.h
+++ b/bdk/power/max17050.h
@@ -130,8 +130,9 @@ enum MAX17050_reg {
 	MAX17050_VFSOC			= 0xFF,
 };
 
-int max17050_get_property(enum MAX17050_reg reg, int *value);
-int max17050_fix_configuration();
-u32 max17050_get_cached_batt_volt();
+int  max17050_get_property(enum MAX17050_reg reg, int *value);
+int  max17050_fix_configuration();
+void max17050_dump_regs(void *buf);
+u32  max17050_get_cached_batt_volt();
 
 #endif /* __MAX17050_H_ */