Add Xiaomi 12 Lite 5G (taoyao) battery support
v3 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 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
RFC PATCH v3 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
@@ -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
Re: [RFC PATCH v3 1/3] dt-bindings: soc: qcom: add xiaomi,taoyao-pmic-glink compatible
Hi,
Quoted 14 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.Signed-off-by Stanislav Zaikin <[email protected]>--- Documentation/devicetree/bindings/soc/qcom/qcom,pmic-glink.yaml | 1 + 1 file changed, 1 insertion(+)Documentation/devicetree/bindings/soc/qcom/qcom,pmic-glink.yaml +0
-0
Documentation/devicetree/bindings/soc/qcom/qcom,pmic-glink.yaml properties: · line 46
Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,pmic-glink.yaml +1
-0@@ -41,6 +41,7 @@ properties: - items: - enum: - qcom,sm7325-pmic-glink + - xiaomi,taoyao-pmic-glink - const: qcom,qcm6490-pmic-glink - const: qcom,pmic-glink
Is the implementation compatible with qcom,qcm6490-pmic-glink? The driver does not bind that compatible, so I can't tell. Maybe some Qualcomm people can answer this question. Please send new version without the RFC tag, so that DT binding maintainers review this patch series.
Greetings,
-- Sebastian
Re: [RFC PATCH v3 1/3] dt-bindings: soc: qcom: add xiaomi,taoyao-pmic-glink compatible
Quoted 30 lines · Sebastian Reichel
Hi,
Quoted 14 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.Signed-off-by Stanislav Zaikin <[email protected]>--- Documentation/devicetree/bindings/soc/qcom/qcom,pmic-glink.yaml | 1 + 1 file changed, 1 insertion(+)Documentation/devicetree/bindings/soc/qcom/qcom,pmic-glink.yaml +0
-0Documentation/devicetree/bindings/soc/qcom/qcom,pmic-glink.yaml properties: · line 46
Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,pmic-glink.yaml +1
-0@@ -41,6 +41,7 @@ properties: - items: - enum: - qcom,sm7325-pmic-glink + - xiaomi,taoyao-pmic-glink - const: qcom,qcm6490-pmic-glink - const: qcom,pmic-glinkIs the implementation compatible with qcom,qcm6490-pmic-glink? The driver does not bind that compatible, so I can't tell. Maybe some Qualcomm people can answer this question. Please send new version without the RFC tag, so that DT binding maintainers review this patch series.
Quoted 3 lines
Greetings,
-- Sebastian
Hi,
Thank you for the review.
Yes, we still need qcom,qcm6490-pmic-glink for usci_glink driver (there's a quirk that all sm7325-based handset uses: spacewar, dubai).
Will send a new version without RFC tag.
Signature · 2 lines
Best regards, Stanislav
RFC PATCH v3 2/3 power: supply: qcom_battmgr: add Xiaomi taoyao support
In reply to Stanislav ZaikinThe 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
@@ -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
Re: [RFC PATCH v3 2/3] power: supply: qcom_battmgr: add Xiaomi taoyao support
Quoted 6 lines · Stanislav Zaikin
The Xiaomi taoyao firmware defines an additional
BATT_CONSTANT_CURRENTproperty (ID 12) betweenBATT_CHG_CTRL_LIM_MAXandBATT_TEMP, shifting all higher battery property IDs by one.Signed-off-by Stanislav Zaikin <[email protected]>---
With a certain amount of pain,
Konrad
RFC PATCH v3 3/3 arm64: dts: qcom: sm7325-xiaomi-taoyao: switch to device-specific pmic-glink compatible
In reply to Stanislav ZaikinSwitch 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
@@ -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