Skip to contentSkip to conversation

Add Xiaomi 12 Lite 5G (taoyao) battery support

PATCH Superseded Stanislav Zaikin 4 participants 9 messages Sep 15 – Sep 18

Subsystems (4)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add Xiaomi 12 Lite 5G (taoyao) battery support

Xiaomi 12 Lite 5G (taoyao) has an additional property with ID 12 that breaks the parsing in qcom_battmgr. Fix that by introducing separate maps for lookups properties in both directions.

The other approach that I tried is manual shifting properties:

+ if (battmgr->variant == QCOM_BATTMGR_TAOYAO && prop > BATT_CHG_CTRL_LIM_MAX)
+ prop++;
...
+ if (battmgr->variant == QCOM_BATTMGR_TAOYAO && property > BATT_CHG_CTRL_LIM_MAX + 1)
+ property--;

But I found that more obscure.

Will be happy to switch if the maintainers prefer this one.

Changes in v4:
- Added Konrad's r-b (patch #2)
- Dropped RFC tag

Changes in v3:
- Fix QCOM_BATTMGR_TAOYAO enum ordering (patch #2)
- Order in qcom_battmgr_of_variants[] is already right (no change)
- Revert the qcom,sm7325-pmic-glink SoC fallback (patch #1 and #3)
- Rephrased commit message (patch #3)
- Design question from v1/v2 still open: lookup tables vs. inline shift

Changes in v2:
- Keep the qcom,sm7325-pmic-glink SoC fallback in the compatible chain of the taoyao pmic-glink node (review feedback, patch #1 and #3)

Stanislav Zaikin (3):
dt-bindings: soc: qcom: add xiaomi,taoyao-pmic-glink compatible
power: supply: qcom_battmgr: add Xiaomi taoyao support
arm64: dts: qcom: sm7325-xiaomi-taoyao: switch to device-specific
pmic-glink compatible

 .../bindings/soc/qcom/qcom,pmic-glink.yaml    |  1 +
 .../boot/dts/qcom/sm7325-xiaomi-taoyao.dts    |  2 +-
 drivers/power/supply/qcom_battmgr.c           | 86 ++++++++++++++++++-
 3 files changed, 84 insertions(+), 5 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH v4 1/3 dt-bindings: soc: qcom: add xiaomi,taoyao-pmic-glink compatible

Add the compatible string used by Xiaomi 12 Lite 5G (taoyao) so its battery manager can be matched to a device-specific variant in qcom_battmgr.

---
 Documentation/devicetree/bindings/soc/qcom/qcom,pmic-glink.yaml | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/soc/qcom/qcom,pmic-glink.yaml +1 -0
index 16ad4f5698fc..8ca057c4e3e6 100644
@@ -41,6 +41,7 @@ properties:
       - items:
           - enum:
               - qcom,sm7325-pmic-glink
+              - xiaomi,taoyao-pmic-glink
           - const: qcom,qcm6490-pmic-glink
           - const: qcom,pmic-glink
       - items:
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH v4 1/3] dt-bindings: soc: qcom: add xiaomi,taoyao-pmic-glink compatible

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] dt-bindings: mutually exclusive board and SoC compatible strings --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] dt-bindings: mutually exclusive board and SoC compatible strings
--

commit c55f57a1517ca9ce82e67923ff8313d8fc20239f
Author: Stanislav Zaikin <[email protected]>

dt-bindings: soc: qcom: add xiaomi,taoyao-pmic-glink compatible

This commit adds the xiaomi,taoyao-pmic-glink compatible string for the Xiaomi 12 Lite 5G to the pmic-glink binding.

Documentation/devicetree/bindings/soc/qcom/qcom,pmic-glink.yaml properties: · line 46

Quoted 11 lines
Documentation/devicetree/bindings/soc/qcom/qcom,pmic-glink.yaml +1 -0
index 16ad4f5698fc3..8ca057c4e3e61 100644
@@ -41,6 +41,7 @@ properties:
       - items:
           - enum:
               - qcom,sm7325-pmic-glink
+              - xiaomi,taoyao-pmic-glink
           - const: qcom,qcm6490-pmic-glink
           - const: qcom,pmic-glink

[Severity: Low]
Does this force the compatible strings to be mutually exclusive and limit the fallback chain to exactly 3 items?

Standard Device Tree design dictates that compatible strings should be ordered from most-specific (board) to least-specific (SoC, generic). A board-specific compatible string for a subsystem should fall back to the SoC-specific string if they share the same underlying hardware.

By adding xiaomi,taoyao-pmic-glink to the same enum as qcom,sm7325-pmic-glink in a 3-item list, the schema forces the DT author to choose one or the other, preventing a complete fallback chain.

As a result, the DT is forced to drop the qcom,sm7325-pmic-glink fallback string to pass schema validation. This breaks the standard DT fallback chain.

Should the schema instead define a separate 4-item list under oneOf to enforce the board string, followed by the SoC string, followed by the base fallbacks?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH v4 1/3] dt-bindings: soc: qcom: add xiaomi,taoyao-pmic-glink compatible

In reply to Stanislav Zaikin
Quoted 3 lines · Stanislav Zaikin

Add the compatible string used by Xiaomi 12 Lite 5G (taoyao) so its battery manager can be matched to a device-specific variant in qcom_battmgr.

Previously you were asked if the device is compatible with qcm6490. You responded about something completely else - that you need qcm6490. That was not the question if you need it or not. The question was are they compatible and you have entire commit msg to explain that.

Instead, describing standard Linux device driver matching in commit msg is redundant.

Best regards,
Krzysztof

#4 lore raw

Re: [PATCH v4 1/3] dt-bindings: soc: qcom: add xiaomi,taoyao-pmic-glink compatible

Quoted 10 lines · Krzysztof Kozlowski
Quoted 3 lines · Stanislav Zaikin

Add the compatible string used by Xiaomi 12 Lite 5G (taoyao) so its battery manager can be matched to a device-specific variant in qcom_battmgr.

Previously you were asked if the device is compatible with qcm6490. You responded about something completely else - that you need qcm6490. That was not the question if you need it or not. The question was are they compatible and you have entire commit msg to explain that.

Quoted 6 lines

Instead, describing standard Linux device driver matching in commit msg is redundant.

Best regards,
Krzysztof

Yes, apart from battmgr, the pmic-glink implementation on this device is compatible with the QCM6490 platform (base communication & UCSI implementation), and therefore should keep qcom,qcm6490-pmic-glink and qcom,pmic-glink in the compatibles.

I will adjust the commit message in the v5 to:

dt-bindings: soc: qcom: qcom,pmic-glink: Document Xiaomi taoyao compatible

The taoyao is the device compatible with the QCM6490 platform (apart from battmgr). The device also requires both UCSI_NO_PARTNER_PDOS & UCSI_DELAY_DEVICE_PDOS quirks.

Document the PMIC GLINK firmware interface on the taoyao by using the QCM6490 bindings as fallback.

Signature · 2 lines
Best regards,
Stanislav
#5 lore raw

PATCH v4 2/3 power: supply: qcom_battmgr: add Xiaomi taoyao support

In reply to Stanislav Zaikin

The Xiaomi taoyao firmware defines an additional BATT_CONSTANT_CURRENT property (ID 12) between BATT_CHG_CTRL_LIM_MAX and BATT_TEMP, shifting all higher battery property IDs by one.

---
 drivers/power/supply/qcom_battmgr.c | 86 +++++++++++++++++++++++++++--
 1 file changed, 82 insertions(+), 4 deletions(-)
drivers/power/supply/qcom_battmgr.c +82 -4
index 490137a23d00..1ff079750807 100644
@@ -23,6 +23,7 @@ enum qcom_battmgr_variant {
 	QCOM_BATTMGR_SC8280XP,
 	QCOM_BATTMGR_SM8350,
 	QCOM_BATTMGR_SM8550,
+	QCOM_BATTMGR_TAOYAO,
 	QCOM_BATTMGR_X1E80100,
 };
 
@@ -451,16 +452,87 @@ static const u8 sm8350_bat_prop_map[] = {
 	[POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD] = BATT_CHG_CTRL_END_THR,
 };
 
+/*
+ * Xiaomi Taoyao firmware has BATT_CONSTANT_CURRENT (ID 12) inserted
+ * between BATT_CHG_CTRL_LIM_MAX and BATT_TEMP, shifting all subsequent
+ * IDs by one.
+ */
+static const u8 taoyao_bat_prop_map[] = {
+	[POWER_SUPPLY_PROP_STATUS] = BATT_STATUS,
+	[POWER_SUPPLY_PROP_HEALTH] = BATT_HEALTH,
+	[POWER_SUPPLY_PROP_PRESENT] = BATT_PRESENT,
+	[POWER_SUPPLY_PROP_CHARGE_TYPE] = BATT_CHG_TYPE,
+	[POWER_SUPPLY_PROP_CAPACITY] = BATT_CAPACITY,
+	[POWER_SUPPLY_PROP_VOLTAGE_OCV] = BATT_VOLT_OCV,
+	[POWER_SUPPLY_PROP_VOLTAGE_NOW] = BATT_VOLT_NOW,
+	[POWER_SUPPLY_PROP_VOLTAGE_MAX] = BATT_VOLT_MAX,
+	[POWER_SUPPLY_PROP_CURRENT_NOW] = BATT_CURR_NOW,
+	[POWER_SUPPLY_PROP_TEMP] = BATT_TEMP + 1,
+	[POWER_SUPPLY_PROP_TECHNOLOGY] = BATT_TECHNOLOGY + 1,
+	[POWER_SUPPLY_PROP_CHARGE_COUNTER] = BATT_CHG_COUNTER + 1,
+	[POWER_SUPPLY_PROP_CYCLE_COUNT] = BATT_CYCLE_COUNT + 1,
+	[POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN] = BATT_CHG_FULL_DESIGN + 1,
+	[POWER_SUPPLY_PROP_CHARGE_FULL] = BATT_CHG_FULL + 1,
+	[POWER_SUPPLY_PROP_MODEL_NAME] = BATT_MODEL_NAME + 1,
+	[POWER_SUPPLY_PROP_TIME_TO_FULL_AVG] = BATT_TTF_AVG + 1,
+	[POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG] = BATT_TTE_AVG + 1,
+	[POWER_SUPPLY_PROP_INTERNAL_RESISTANCE] = BATT_RESISTANCE + 1,
+	[POWER_SUPPLY_PROP_STATE_OF_HEALTH] = BATT_SOH,
+	[POWER_SUPPLY_PROP_POWER_NOW] = BATT_POWER_NOW + 1,
+	[POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD] = BATT_CHG_CTRL_START_THR + 1,
+	[POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD] = BATT_CHG_CTRL_END_THR + 1,
+};
+
+/*
+ * Reverse mapping from Xiaomi Taoyao firmware property IDs to canonical
+ * kernel property IDs.
+ */
+static const u8 taoyao_to_canonical[] = {
+	[BATT_STATUS] = BATT_STATUS,
+	[BATT_HEALTH] = BATT_HEALTH,
+	[BATT_PRESENT] = BATT_PRESENT,
+	[BATT_CHG_TYPE] = BATT_CHG_TYPE,
+	[BATT_CAPACITY] = BATT_CAPACITY,
+	[BATT_SOH] = BATT_SOH,
+	[BATT_VOLT_OCV] = BATT_VOLT_OCV,
+	[BATT_VOLT_NOW] = BATT_VOLT_NOW,
+	[BATT_VOLT_MAX] = BATT_VOLT_MAX,
+	[BATT_CURR_NOW] = BATT_CURR_NOW,
+	[BATT_CHG_CTRL_LIM] = BATT_CHG_CTRL_LIM,
+	[BATT_CHG_CTRL_LIM_MAX] = BATT_CHG_CTRL_LIM_MAX,
+	[BATT_CHG_CTRL_LIM_MAX + 1] = 0xff,	/* BATT_CONSTANT_CURRENT - never requested */
+	[BATT_TEMP + 1] = BATT_TEMP,
+	[BATT_TECHNOLOGY + 1] = BATT_TECHNOLOGY,
+	[BATT_CHG_COUNTER + 1] = BATT_CHG_COUNTER,
+	[BATT_CYCLE_COUNT + 1] = BATT_CYCLE_COUNT,
+	[BATT_CHG_FULL_DESIGN + 1] = BATT_CHG_FULL_DESIGN,
+	[BATT_CHG_FULL + 1] = BATT_CHG_FULL,
+	[BATT_MODEL_NAME + 1] = BATT_MODEL_NAME,
+	[BATT_TTF_AVG + 1] = BATT_TTF_AVG,
+	[BATT_TTE_AVG + 1] = BATT_TTE_AVG,
+	[BATT_RESISTANCE + 1] = BATT_RESISTANCE,
+	[BATT_POWER_NOW + 1] = BATT_POWER_NOW,
+	[BATT_POWER_AVG + 1] = BATT_POWER_AVG,
+	[BATT_CHG_CTRL_EN + 1] = BATT_CHG_CTRL_EN,
+	[BATT_CHG_CTRL_START_THR + 1] = BATT_CHG_CTRL_START_THR,
+	[BATT_CHG_CTRL_END_THR + 1] = BATT_CHG_CTRL_END_THR,
+};
+
 static int qcom_battmgr_bat_sm8350_update(struct qcom_battmgr *battmgr,
 					  enum power_supply_property psp)
 {
 	unsigned int prop;
 	int ret;
 
-	if (psp >= ARRAY_SIZE(sm8350_bat_prop_map))
-		return -EINVAL;
-
-	prop = sm8350_bat_prop_map[psp];
+	if (battmgr->variant == QCOM_BATTMGR_TAOYAO) {
+		if (psp >= ARRAY_SIZE(taoyao_bat_prop_map))
+			return -EINVAL;
+		prop = taoyao_bat_prop_map[psp];
+	} else {
+		if (psp >= ARRAY_SIZE(sm8350_bat_prop_map))
+			return -EINVAL;
+		prop = sm8350_bat_prop_map[psp];
+	}
 
 	mutex_lock(&battmgr->lock);
 	ret = qcom_battmgr_request_property(battmgr, BATTMGR_BAT_PROPERTY_GET, prop, 0);
@@ -1381,6 +1453,11 @@ static void qcom_battmgr_sm8350_callback(struct qcom_battmgr *battmgr,
 	switch (opcode) {
 	case BATTMGR_BAT_PROPERTY_GET:
 		property = le32_to_cpu(resp->intval.property);
+
+		if (battmgr->variant == QCOM_BATTMGR_TAOYAO &&
+		    property < ARRAY_SIZE(taoyao_to_canonical))
+			property = taoyao_to_canonical[property];
+
 		if (property == BATT_MODEL_NAME) {
 			if (payload_len != sizeof(resp->strval)) {
 				dev_warn(battmgr->dev,
@@ -1617,6 +1694,7 @@ static const struct of_device_id qcom_battmgr_of_variants[] = {
 	{ .compatible = "qcom,sc8280xp-pmic-glink", .data = (void *)QCOM_BATTMGR_SC8280XP },
 	{ .compatible = "qcom,sm8550-pmic-glink", .data = (void *)QCOM_BATTMGR_SM8550 },
 	{ .compatible = "qcom,x1e80100-pmic-glink", .data = (void *)QCOM_BATTMGR_X1E80100 },
+	{ .compatible = "xiaomi,taoyao-pmic-glink", .data = (void *)QCOM_BATTMGR_TAOYAO },
 	/* Unmatched devices falls back to QCOM_BATTMGR_SM8350 */
 	{}
 };
Signature · 1 line
2.53.0
#6 lore raw

PATCH v4 3/3 arm64: dts: qcom: sm7325-xiaomi-taoyao: switch to device-specific pmic-glink compatible

In reply to Stanislav Zaikin

Switch taoyao to "xiaomi,taoyao-pmic-glink" compatible so qcom_battmgr can identify the device and apply its taoyao-specific battery property mapping, required because its firmware shifts battery property IDs relative to the generic sm7325-pmic-glink firmware.

---
 arch/arm64/boot/dts/qcom/sm7325-xiaomi-taoyao.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/sm7325-xiaomi-taoyao.dts +1 -1
index 6f8bc65bb99b..bc4dfa49ef38 100644
@@ -72,7 +72,7 @@ key-volume-up {
 	};
 
 	pmic-glink {
-		compatible = "qcom,sm7325-pmic-glink",
+		compatible = "xiaomi,taoyao-pmic-glink",
 			     "qcom,qcm6490-pmic-glink",
 			     "qcom,pmic-glink";
 
Signature · 1 line
2.53.0
#7 lore raw

Re: [PATCH v4 3/3] arm64: dts: qcom: sm7325-xiaomi-taoyao: switch to device-specific pmic-glink compatible

Quoted 16 lines · Stanislav Zaikin

Switch taoyao to "xiaomi,taoyao-pmic-glink" compatible so qcom_battmgr can identify the device and apply its taoyao-specific battery property mapping, required because its firmware shifts battery property IDs relative to the generic sm7325-pmic-glink firmware.

---
 arch/arm64/boot/dts/qcom/sm7325-xiaomi-taoyao.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/sm7325-xiaomi-taoyao.dts +0 -0
index 6f8bc65bb99b..bc4dfa49ef38 100644

arch/arm64/boot/dts/qcom/sm7325-xiaomi-taoyao.dts key-volume-up { · line 77

Quoted 7 lines
arch/arm64/boot/dts/qcom/sm7325-xiaomi-taoyao.dts +1 -1
@@ -72,7 +72,7 @@ key-volume-up {
 	};
 
 	pmic-glink {
-		compatible = "qcom,sm7325-pmic-glink",
+		compatible = "xiaomi,taoyao-pmic-glink",
 			     "qcom,qcm6490-pmic-glink",
 			     "qcom,pmic-glink";

As krzk points out, this should be a standalone single compatible, because it's neither going to work with qcm6490-pmic-glink nor with qcom,pmic-glink

Konrad

#8 lore raw

Re: [PATCH v4 3/3] arm64: dts: qcom: sm7325-xiaomi-taoyao: switch to device-specific pmic-glink compatible

Quoted 29 lines · Konrad Dybcio
Quoted 16 lines · Stanislav Zaikin

Switch taoyao to "xiaomi,taoyao-pmic-glink" compatible so qcom_battmgr can identify the device and apply its taoyao-specific battery property mapping, required because its firmware shifts battery property IDs relative to the generic sm7325-pmic-glink firmware.

---
  arch/arm64/boot/dts/qcom/sm7325-xiaomi-taoyao.dts | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/sm7325-xiaomi-taoyao.dts +0 -0
index 6f8bc65bb99b..bc4dfa49ef38 100644

arch/arm64/boot/dts/qcom/sm7325-xiaomi-taoyao.dts key-volume-up { · line 77

Quoted 7 lines
arch/arm64/boot/dts/qcom/sm7325-xiaomi-taoyao.dts +1 -1
@@ -72,7 +72,7 @@ key-volume-up {
  	};
 
  	pmic-glink {
-		compatible = "qcom,sm7325-pmic-glink",
+		compatible = "xiaomi,taoyao-pmic-glink",
  			     "qcom,qcm6490-pmic-glink",
  			     "qcom,pmic-glink";

As krzk points out, this should be a standalone single compatible, because it's neither going to work with qcm6490-pmic-glink nor with qcom,pmic-glink

Quoted 1 line

Konrad

Only the battmgr implementation differs but the rest is compatible with qcm6490 (UCSI implementation) and generic pmic-glink (basic communication). So, we should keep all 3 compatibles.

Signature · 2 lines
Best regards,
Stanislav