Add Xiaomi 12 Lite 5G (taoyao) battery support
v2 cover Add Xiaomi 12 Lite 5G (taoyao) battery support
From: Stanislav Zaikin <[email protected]>
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 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 | 5 ++ .../boot/dts/qcom/sm7325-xiaomi-taoyao.dts | 3 +- drivers/power/supply/qcom_battmgr.c | 86 ++++++++++++++++++- 3 files changed, 89 insertions(+), 5 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/3 dt-bindings: soc: qcom: add xiaomi,taoyao-pmic-glink compatible
From: Stanislav Zaikin <[email protected]>
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.
--- .../devicetree/bindings/soc/qcom/qcom,pmic-glink.yaml | 5 +++++ 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/soc/qcom/qcom,pmic-glink.yaml +5 -0
@@ -43,6 +43,11 @@ properties: - qcom,sm7325-pmic-glink - const: qcom,qcm6490-pmic-glink - const: qcom,pmic-glink + - items: + - const: xiaomi,taoyao-pmic-glink + - const: qcom,sm7325-pmic-glink + - const: qcom,qcm6490-pmic-glink + - const: qcom,pmic-glink - items: - enum: - qcom,eliza-pmic-glink
Signature · 1 line
2.53.0
PATCH v2 2/3 power: supply: qcom_battmgr: add Xiaomi taoyao support
In reply to user.emailFrom: Stanislav Zaikin <[email protected]>
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
@@ -24,6 +24,7 @@ enum qcom_battmgr_variant {QCOM_BATTMGR_SM8350 ,QCOM_BATTMGR_SM8550 ,QCOM_BATTMGR_X1E80100 , + QCOM_BATTMGR_TAOYAO, };#define BATTMGR_BAT_STATUS 0x1
@@ -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
[email protected]
AI reviewRe: [PATCH v2 2/3] power: supply: qcom_battmgr: add Xiaomi taoyao support
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Missing exposure of charge control thresholds for the Taoyao variant. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing exposure of charge control thresholds for the Taoyao variant. --
--- Patch [2]: [PATCH v2 2/3] power: supply: qcom_battmgr: add Xiaomi taoyao support --- commit 7dca11719c74cb544dcbbafa2547e26c0a56fd43
Author: Stanislav Zaikin <[email protected]>
power: supply: qcom_battmgr: add Xiaomi taoyao support
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.
Quoted 14 lines
drivers/power/supply/qcom_battmgr.c +6
-0@@ -452,16 +453,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[] = {
[ ... ]
drivers/power/supply/qcom_battmgr.c static const u8 sm8350_bat_prop_map[] = { · line 484
Quoted 4 lines
drivers/power/supply/qcom_battmgr.c +4
-0+ [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, +};
[Severity: Medium]
While you've explicitly mapped the charge control thresholds here for the Taoyao variant, does qcom_battmgr_probe() actually assign a power supply descriptor that exposes these properties?
Looking at qcom_battmgr_probe(), QCOM_BATTMGR_TAOYAO will fall through to using sm8350_bat_psy_desc:
} else {
if (battmgr->variant == QCOM_BATTMGR_SM8550)
psy_desc = &sm8550_bat_psy_desc;
else
psy_desc = &sm8350_bat_psy_desc;Since sm8350_bat_psy_desc lacks POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD and POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD, will these properties be silently unavailable for Taoyao devices?
If they should be supported, does this require a dedicated power supply descriptor or using sm8550_bat_psy_desc instead?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v2 2/3] power: supply: qcom_battmgr: add Xiaomi taoyao support
In reply to user.emailQuoted 16 lines · user.email
From: Stanislav Zaikin <[email protected]>
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]>--- drivers/power/supply/qcom_battmgr.c | 86 +++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 4 deletions(-)drivers/power/supply/qcom_battmgr.c +0
-0
drivers/power/supply/qcom_battmgr.c enum qcom_battmgr_variant { · line 27
Quoted 4 lines
drivers/power/supply/qcom_battmgr.c +1
-0@@ -24,6 +24,7 @@ enum qcom_battmgr_variant {QCOM_BATTMGR_SM8350 ,QCOM_BATTMGR_SM8550 ,QCOM_BATTMGR_X1E80100 , + QCOM_BATTMGR_TAOYAO,
T < X, do not introduce entries in random order
Quoted 96 lines
drivers/power/supply/qcom_battmgr.c +75
-4};#define BATTMGR_BAT_STATUS 0x1@@ -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 );
drivers/power/supply/qcom_battmgr.c static void qcom_battmgr_sm8350_callback(struct qcom_battmgr *battmgr, · line 1459
Quoted 7 lines
drivers/power/supply/qcom_battmgr.c +4
-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];
So device is or is not compatible with sm7325? Above code suggests that it is not. How does it work when bound by sm7325 compatible?
drivers/power/supply/qcom_battmgr.c static const struct of_device_id qcom_battmgr_of_variants[] = { · line 1697
Quoted 9 lines
drivers/power/supply/qcom_battmgr.c +2
-0+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 },
And here as well wrong order
Quoted 6 lines
drivers/power/supply/qcom_battmgr.c +0
-0/* Unmatched devices falls back to QCOM_BATTMGR_SM8350 */ {} };Signature · 1 line
2.53.0
Re: [PATCH v2 2/3] power: supply: qcom_battmgr: add Xiaomi taoyao support
Quoted 12 lines · Krzysztof Kozlowski
Quoted 11 lines · user.email
From: Stanislav Zaikin <[email protected]>
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]>--- drivers/power/supply/qcom_battmgr.c | 86 +++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 4 deletions(-)
Quoted 11 lines
drivers/power/supply/qcom_battmgr.c enum qcom_battmgr_variant { · line 27
Quoted 9 lines
drivers/power/supply/qcom_battmgr.c +1
-0@@ -24,6 +24,7 @@ enum qcom_battmgr_variant {QCOM_BATTMGR_SM8350 ,QCOM_BATTMGR_SM8550 ,QCOM_BATTMGR_X1E80100 , + QCOM_BATTMGR_TAOYAO,T < X, do not introduce entries in random order
Hello Krzysztof,
Thank you for the review.
Will fix in v3.
Quoted 11 lines
drivers/power/supply/qcom_battmgr.c static void qcom_battmgr_sm8350_callback(struct qcom_battmgr *battmgr, · line 1459
Quoted 8 lines
drivers/power/supply/qcom_battmgr.c +4
-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];So device is or is not compatible with sm7325? Above code suggests that it is not. How does it work when bound by sm7325 compatible?
The device is sm7325-based and when bound to sm7325-pmic-glink it falls back to QCOM_BATTMGR_SM8350 property map. However, due to shifted property IDs baked into taoyao's firmware the parsing of roughly the 2nd half of properties is broken.
And any userspace process that reads the battery properties via sysfs suffers from 1s timeouts and it basically hangs my DE.
Since this is an RFC: do you think this approach is better than what I described in cover letter? (manually shifting property IDs)
Quoted 7 lines
drivers/power/supply/qcom_battmgr.c static const struct of_device_id qcom_battmgr_of_variants[] = { · line 1697
Quoted 5 lines
drivers/power/supply/qcom_battmgr.c +1
-0@@ -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 },And here as well wrong order
Will fix in v3.
--
Best regards,
Stanislav
Re: [PATCH v2 2/3] power: supply: qcom_battmgr: add Xiaomi taoyao support
Quoted 42 lines · Stanislav Zaikin
Quoted 12 lines · Krzysztof Kozlowski
Quoted 11 lines · user.email
From: Stanislav Zaikin <[email protected]>
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]>---
drivers/power/supply/qcom_battmgr.c| 86 +++++++++++++++++++++++++++--1 file changed, 82 insertions(+), 4 deletions(-)Quoted 11 lines
drivers/power/supply/qcom_battmgr.c enum qcom_battmgr_variant { · line 27
Quoted 9 lines
drivers/power/supply/qcom_battmgr.c +1
-0@@ -24,6 +24,7 @@ enum qcom_battmgr_variant { QCOM_BATTMGR_SM8350, QCOM_BATTMGR_SM8550, QCOM_BATTMGR_X1E80100, + QCOM_BATTMGR_TAOYAO,T < X, do not introduce entries in random order
Hello Krzysztof,
Thank you for the review.Will fix in v3.
Quoted 11 lines
Quoted 8 lines
drivers/power/supply/qcom_battmgr.c +0
-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];So device is or is not compatible with sm7325? Above code suggests that it is not. How does it work when bound by sm7325 compatible?
Quoted 5 lines
The device is sm7325-based and when bound to sm7325-pmic-glink it falls back to
QCOM_BATTMGR_SM8350property map. However, due to shifted property IDs baked into taoyao's firmware the parsing of roughly the 2nd half of properties is broken.And any userspace process that reads the battery properties via sysfs suffers from 1s timeouts and it basically hangs my DE.
Since this is an RFC: do you think this approach is better than what I described in cover letter? (manually shifting property IDs)
Krzysztof is trying to say that even though the device is based on the 7325 SoC, what the kernel today knows as "pmic glink on sm7325" is not compatible with the customized firmware on your device, so the fallback compatible should be dropped, as it suggests that is the case
Konrad
Re: [PATCH v2 2/3] power: supply: qcom_battmgr: add Xiaomi taoyao support
In reply to Stanislav ZaikinQuoted 42 lines · Stanislav Zaikin
Quoted 12 lines · Krzysztof Kozlowski
Quoted 11 lines · user.email
From: Stanislav Zaikin <[email protected]>
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]>--- drivers/power/supply/qcom_battmgr.c | 86 +++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 4 deletions(-)Quoted 11 lines
drivers/power/supply/qcom_battmgr.c enum qcom_battmgr_variant { · line 27
Quoted 9 lines
drivers/power/supply/qcom_battmgr.c +1
-0@@ -24,6 +24,7 @@ enum qcom_battmgr_variant {QCOM_BATTMGR_SM8350 ,QCOM_BATTMGR_SM8550 ,QCOM_BATTMGR_X1E80100 , + QCOM_BATTMGR_TAOYAO,T < X, do not introduce entries in random order
Hello Krzysztof,
Thank you for the review.Will fix in v3.
Quoted 11 lines
drivers/power/supply/qcom_battmgr.c static void qcom_battmgr_sm8350_callback(struct qcom_battmgr *battmgr, · line 1459
Quoted 8 lines
drivers/power/supply/qcom_battmgr.c +4
-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];So device is or is not compatible with sm7325? Above code suggests that it is not. How does it work when bound by sm7325 compatible?
Quoted 7 lines
The device is sm7325-based and when bound to sm7325-pmic-glink it falls back to
QCOM_BATTMGR_SM8350property map. However, due to shifted property IDs baked into taoyao's firmware the parsing of roughly the 2nd half of properties is broken.And any userspace process that reads the battery properties via sysfs suffers from 1s timeouts and it basically hangs my DE.
So basically it is not compatible with sm7325-pmic-glink and it should be expressed/fixed. I wonder though how was the DTS even tested in this matter.
Quoted 3 lines
Since this is an RFC: do you think this approach is better than what I described in cover letter? (manually shifting property IDs)
Every patch is RFC... or are you saying this is a RFC in a meaning it is
not ready for review?
Quoted 9 lines
Quoted 8 lines
drivers/power/supply/qcom_battmgr.c static const struct of_device_id qcom_battmgr_of_variants[] = { · line 1697
Quoted 6 lines
drivers/power/supply/qcom_battmgr.c +1
-0@@ -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 },And here as well wrong order
Quoted 6 lines
Will fix in v3.
--
Best regards,
Stanislav
Best regards,
Krzysztof
PATCH v2 3/3 arm64: dts: qcom: sm7325-xiaomi-taoyao: switch to device-specific pmic-glink compatible
In reply to user.emailFrom: Stanislav Zaikin <[email protected]>
Switch taoyao to its own compatible so qcom_battmgr can select the taoyao-specific property mapping added in the previous patch.
--- arch/arm64/boot/dts/qcom/sm7325-xiaomi-taoyao.dts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/sm7325-xiaomi-taoyao.dts +2 -1
@@ -72,7 +72,8 @@ key-volume-up { }; pmic-glink { - compatible = "qcom,sm7325-pmic-glink", + compatible = "xiaomi,taoyao-pmic-glink", + "qcom,sm7325-pmic-glink", "qcom,qcm6490-pmic-glink", "qcom,pmic-glink";
Signature · 1 line
2.53.0
Re: [PATCH v2 3/3] arm64: dts: qcom: sm7325-xiaomi-taoyao: switch to device-specific pmic-glink compatible
Quoted 4 lines · user.email
From: Stanislav Zaikin <[email protected]>
Switch taoyao to its own compatible so
qcom_battmgrcan select the taoyao-specific property mapping added in the previous patch.
How is it going to be a "previous patch"? Previous patch is a different DTS commit - look at the DTS branch of qcom soc or any other soc tree.
Best regards,
Krzysztof