* [PATCH 0/4] Add pm8916 VM-BMS and LBC
@ 2023-07-28 17:19 Nikita Travkin
2023-07-28 17:19 ` [PATCH 1/4] dt-bindings: power: supply: Add pm8916 VM-BMS Nikita Travkin
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Nikita Travkin @ 2023-07-28 17:19 UTC (permalink / raw)
To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-pm, devicetree, linux-kernel, linux-arm-msm, Nikita Travkin
This series adds charger and "fuel-gauge" found in Qualcomm pm8916 PMIC.
The LBC - Linear Battery Charger is a simple CC/CV charger, that works
autonomously after the current and voltage limits are set.
The VM-BMS - Voltage Mode BMS is a simple hardware block that provides
average voltage on the battery terminals.
These two hardware blocks are used as the battery charging and
management solution in some old Qualcomm devices.
Signed-off-by: Nikita Travkin <nikita@trvn.ru>
---
Nikita Travkin (4):
dt-bindings: power: supply: Add pm8916 VM-BMS
dt-bindings: power: supply: Add pm8916 LBC
power: supply: Add pm8916 VM-BMS support
power: supply: Add driver for pm8916 lbc
.../bindings/power/supply/qcom,pm8916-bms-vm.yaml | 64 ++++
.../bindings/power/supply/qcom,pm8916-lbc.yaml | 93 +++++
drivers/power/supply/Kconfig | 22 ++
drivers/power/supply/Makefile | 2 +
drivers/power/supply/pm8916_bms_vm.c | 296 ++++++++++++++++
drivers/power/supply/pm8916_lbc.c | 385 +++++++++++++++++++++
6 files changed, 862 insertions(+)
---
base-commit: d7b3af5a77e8d8da28f435f313e069aea5bcf172
change-id: 20230727-pm8916-bms-lbc-3f80305326a2
Best regards,
--
Nikita Travkin <nikita@trvn.ru>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/4] dt-bindings: power: supply: Add pm8916 VM-BMS
2023-07-28 17:19 [PATCH 0/4] Add pm8916 VM-BMS and LBC Nikita Travkin
@ 2023-07-28 17:19 ` Nikita Travkin
2023-07-29 10:03 ` Conor Dooley
2023-07-28 17:19 ` [PATCH 2/4] dt-bindings: power: supply: Add pm8916 LBC Nikita Travkin
` (2 subsequent siblings)
3 siblings, 1 reply; 11+ messages in thread
From: Nikita Travkin @ 2023-07-28 17:19 UTC (permalink / raw)
To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-pm, devicetree, linux-kernel, linux-arm-msm, Nikita Travkin
Qualcomm Voltage Mode BMS is a battery monitoring block in PM8916 PMIC.
Document it's DT binding.
Signed-off-by: Nikita Travkin <nikita@trvn.ru>
---
.../bindings/power/supply/qcom,pm8916-bms-vm.yaml | 64 ++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/Documentation/devicetree/bindings/power/supply/qcom,pm8916-bms-vm.yaml b/Documentation/devicetree/bindings/power/supply/qcom,pm8916-bms-vm.yaml
new file mode 100644
index 000000000000..455973d46862
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/supply/qcom,pm8916-bms-vm.yaml
@@ -0,0 +1,64 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/power/supply/qcom,pm8916-bms-vm.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Voltage Mode BMS
+
+maintainers:
+ - Nikita Travkin <nikita@trvn.ru>
+
+description:
+ Voltage Mode BMS is a hardware block found in some Qualcomm PMICs
+ such as pm8916. This block performs battery voltage monitoring.
+
+allOf:
+ - $ref: power-supply.yaml#
+
+properties:
+ compatible:
+ const: qcom,pm8916-bms-vm
+
+ reg:
+ maxItems: 1
+
+ interrupts:
+ items:
+ - description: FIFO update done
+
+ interrupt-names:
+ items:
+ - const: fifo
+
+ monitored-battery: true
+
+ power-supplies: true
+
+
+required:
+ - compatible
+ - reg
+ - interrupts
+ - interrupt-names
+ - monitored-battery
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/irq.h>
+ pmic {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ battery@4000 {
+ compatible = "qcom,pm8916-bms-vm";
+ reg = <0x4000>;
+ interrupts = <0x0 0x40 4 IRQ_TYPE_EDGE_RISING>;
+ interrupt-names = "fifo";
+
+ monitored-battery = <&battery>;
+ power-supplies = <&pm8916_charger>;
+ };
+ };
--
2.41.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/4] dt-bindings: power: supply: Add pm8916 LBC
2023-07-28 17:19 [PATCH 0/4] Add pm8916 VM-BMS and LBC Nikita Travkin
2023-07-28 17:19 ` [PATCH 1/4] dt-bindings: power: supply: Add pm8916 VM-BMS Nikita Travkin
@ 2023-07-28 17:19 ` Nikita Travkin
2023-07-28 17:19 ` [PATCH 3/4] power: supply: Add pm8916 VM-BMS support Nikita Travkin
2023-07-28 17:19 ` [PATCH 4/4] power: supply: Add driver for pm8916 lbc Nikita Travkin
3 siblings, 0 replies; 11+ messages in thread
From: Nikita Travkin @ 2023-07-28 17:19 UTC (permalink / raw)
To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-pm, devicetree, linux-kernel, linux-arm-msm, Nikita Travkin
Qualcomm Linear Battery Charger is a CC/CV charger block in PM8916 PMIC.
Document it's DT binding.
Signed-off-by: Nikita Travkin <nikita@trvn.ru>
---
.../bindings/power/supply/qcom,pm8916-lbc.yaml | 93 ++++++++++++++++++++++
1 file changed, 93 insertions(+)
diff --git a/Documentation/devicetree/bindings/power/supply/qcom,pm8916-lbc.yaml b/Documentation/devicetree/bindings/power/supply/qcom,pm8916-lbc.yaml
new file mode 100644
index 000000000000..baf232b61e02
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/supply/qcom,pm8916-lbc.yaml
@@ -0,0 +1,93 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/power/supply/qcom,pm8916-lbc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Linear Battery Charger
+
+maintainers:
+ - Nikita Travkin <nikita@trvn.ru>
+
+description:
+ Linear Battery Charger hardware block, found in some Qualcomm PMICs
+ such as pm8916. Implements a simple, autonomous CC/CV charger.
+
+allOf:
+ - $ref: power-supply.yaml#
+
+properties:
+ compatible:
+ const: qcom,pm8916-lbc
+
+ reg:
+ items:
+ - description: Charger
+ - description: Battery
+ - description: USB
+ - description: MISC
+
+ reg-names:
+ items:
+ - const: chgr
+ - const: bat_if
+ - const: usb
+ - const: misc
+
+ interrupts:
+ items:
+ - description: USB IN valid
+
+ interrupt-names:
+ items:
+ - const: usb_vbus
+
+ qcom,fast-charge-safe-voltage:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ minimum: 4000000
+ maximum: 4775000
+ description:
+ Maximum safe battery voltage in uV; May be pre-set by bootloader,
+ in which case, setting this will harmlessly fail.
+
+ qcom,fast-charge-safe-current:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ minimum: 90000
+ maximum: 1440000
+ description:
+ Maximum safe battery charge current in uA; May be pre-set by
+ bootloader, in which case setting this will harmlessly fail.
+
+ monitored-battery: true
+
+required:
+ - compatible
+ - reg
+ - interrupts
+ - interrupt-names
+ - qcom,fast-charge-safe-voltage
+ - qcom,fast-charge-safe-current
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/irq.h>
+ pmic {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ charger@1000 {
+ compatible = "qcom,pm8916-lbc";
+ reg = <0x1000>, <0x1200>, <0x1300>, <0x1600>;
+ reg-names = "chgr", "bat_if", "usb", "misc";
+
+ interrupts = <0x0 0x13 1 IRQ_TYPE_EDGE_BOTH>;
+ interrupt-names = "usb_vbus";
+
+ monitored-battery = <&battery>;
+
+ qcom,fast-charge-safe-current = <900000>;
+ qcom,fast-charge-safe-voltage = <4300000>;
+ };
+ };
--
2.41.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/4] power: supply: Add pm8916 VM-BMS support
2023-07-28 17:19 [PATCH 0/4] Add pm8916 VM-BMS and LBC Nikita Travkin
2023-07-28 17:19 ` [PATCH 1/4] dt-bindings: power: supply: Add pm8916 VM-BMS Nikita Travkin
2023-07-28 17:19 ` [PATCH 2/4] dt-bindings: power: supply: Add pm8916 LBC Nikita Travkin
@ 2023-07-28 17:19 ` Nikita Travkin
2023-07-28 17:19 ` [PATCH 4/4] power: supply: Add driver for pm8916 lbc Nikita Travkin
3 siblings, 0 replies; 11+ messages in thread
From: Nikita Travkin @ 2023-07-28 17:19 UTC (permalink / raw)
To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-pm, devicetree, linux-kernel, linux-arm-msm, Nikita Travkin
This driver adds basic support for VM-BMS found in pm8916.
VM-BMS is a very basic fuel-gauge hardware block that is, sadly,
incapable of any gauging. The hardware supports measuring OCV in
sleep mode, where the battery is not in use, or measuring average
voltage over time when the device is active.
This driver implements basic value readout from this block.
Signed-off-by: Nikita Travkin <nikita@trvn.ru>
---
drivers/power/supply/Kconfig | 11 ++
drivers/power/supply/Makefile | 1 +
drivers/power/supply/pm8916_bms_vm.c | 296 +++++++++++++++++++++++++++++++++++
3 files changed, 308 insertions(+)
diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index 663a1c423806..e93a5a4d03e2 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -629,6 +629,17 @@ config CHARGER_QCOM_SMBB
documentation for more detail. The base name for this driver is
'pm8941_charger'.
+config BATTERY_PM8916_BMS_VM
+ tristate "Qualcomm PM8916 BMS-VM support"
+ depends on MFD_SPMI_PMIC || COMPILE_TEST
+ help
+ Say Y to add support for Voltage Mode BMS block found in some
+ Qualcomm PMICs such as PM8916. This hardware block provides
+ battery voltage monitoring for the system.
+
+ To compile this driver as module, choose M here: the
+ module will be called pm8916_bms_vm.
+
config CHARGER_BQ2415X
tristate "TI BQ2415x battery charger driver"
depends on I2C
diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile
index a8a9fa6de1e9..fdf7916f80ed 100644
--- a/drivers/power/supply/Makefile
+++ b/drivers/power/supply/Makefile
@@ -84,6 +84,7 @@ obj-$(CONFIG_CHARGER_MP2629) += mp2629_charger.o
obj-$(CONFIG_CHARGER_MT6360) += mt6360_charger.o
obj-$(CONFIG_CHARGER_MT6370) += mt6370-charger.o
obj-$(CONFIG_CHARGER_QCOM_SMBB) += qcom_smbb.o
+obj-$(CONFIG_BATTERY_PM8916_BMS_VM) += pm8916_bms_vm.o
obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o
obj-$(CONFIG_CHARGER_BQ24190) += bq24190_charger.o
obj-$(CONFIG_CHARGER_BQ24257) += bq24257_charger.o
diff --git a/drivers/power/supply/pm8916_bms_vm.c b/drivers/power/supply/pm8916_bms_vm.c
new file mode 100644
index 000000000000..e4652749f711
--- /dev/null
+++ b/drivers/power/supply/pm8916_bms_vm.c
@@ -0,0 +1,296 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2023, Nikita Travkin <nikita@trvn.ru>
+ */
+
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/power_supply.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+
+#define PM8916_PERPH_TYPE 0x04
+#define PM8916_BMS_VM_TYPE 0x020D
+
+#define PM8916_SEC_ACCESS 0xD0
+#define PM8916_SEC_MAGIC 0xA5
+
+#define PM8916_BMS_VM_STATUS1 0x08
+#define PM8916_BMS_VM_FSM_STATE(x) (((x) & 0b00111000) >> 3)
+#define PM8916_BMS_VM_FSM_STATE_S2 0x2
+
+#define PM8916_BMS_VM_MODE_CTL 0x40
+#define PM8916_BMS_VM_MODE_FORCE_S3 (BIT(0) | BIT(1))
+#define PM8916_BMS_VM_MODE_NORMAL (BIT(1) | BIT(3))
+
+#define PM8916_BMS_VM_EN_CTL 0x46
+#define PM8916_BMS_ENABLED BIT(7)
+
+#define PM8916_BMS_VM_FIFO_LENGTH_CTL 0x47
+#define PM8916_BMS_VM_S1_SAMPLE_INTERVAL_CTL 0x55
+#define PM8916_BMS_VM_S2_SAMPLE_INTERVAL_CTL 0x56
+#define PM8916_BMS_VM_S3_S7_OCV_DATA0 0x6A
+#define PM8916_BMS_VM_BMS_FIFO_REG_0_LSB 0xC0
+
+/* Using only 1 fifo is broken in hardware */
+#define PM8916_BMS_VM_FIFO_COUNT 2 /* 2 .. 8 */
+
+#define PM8916_BMS_VM_S1_SAMPLE_INTERVAL 10
+#define PM8916_BMS_VM_S2_SAMPLE_INTERVAL 10
+
+struct pm8916_bms_vm_battery {
+ struct device *dev;
+ struct power_supply *battery;
+ struct power_supply_battery_info *info;
+ struct regmap *regmap;
+ unsigned int reg;
+ unsigned int last_ocv;
+ unsigned int vbat_now;
+};
+
+static int pm8916_bms_vm_battery_get_property(struct power_supply *psy,
+ enum power_supply_property psp,
+ union power_supply_propval *val)
+{
+ struct pm8916_bms_vm_battery *bat = power_supply_get_drvdata(psy);
+ struct power_supply_battery_info *info = bat->info;
+ int supplied;
+
+ switch (psp) {
+ case POWER_SUPPLY_PROP_STATUS:
+ supplied = power_supply_am_i_supplied(psy);
+
+ if (supplied < 0 && supplied != -ENODEV)
+ return supplied;
+ else if (supplied && supplied != -ENODEV)
+ val->intval = POWER_SUPPLY_STATUS_CHARGING;
+ else
+ val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
+ return 0;
+
+ case POWER_SUPPLY_PROP_HEALTH:
+ if (bat->vbat_now < info->voltage_min_design_uv)
+ val->intval = POWER_SUPPLY_HEALTH_DEAD;
+ else if (bat->vbat_now > info->voltage_max_design_uv)
+ val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
+ else
+ val->intval = POWER_SUPPLY_HEALTH_GOOD;
+ return 0;
+
+ case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+ val->intval = bat->vbat_now;
+ return 0;
+
+ case POWER_SUPPLY_PROP_VOLTAGE_BOOT:
+ /* Returning last known ocv value here - it changes after suspend. */
+ val->intval = bat->last_ocv;
+ return 0;
+
+ default:
+ return -EINVAL;
+ }
+}
+
+static enum power_supply_property pm8916_bms_vm_battery_properties[] = {
+ POWER_SUPPLY_PROP_STATUS,
+ POWER_SUPPLY_PROP_VOLTAGE_NOW,
+ POWER_SUPPLY_PROP_VOLTAGE_BOOT,
+ POWER_SUPPLY_PROP_HEALTH,
+};
+
+static irqreturn_t pm8916_bms_vm_fifo_update_done_irq(int irq, void *data)
+{
+ struct pm8916_bms_vm_battery *bat = data;
+ u16 vbat_data[PM8916_BMS_VM_FIFO_COUNT];
+ int ret;
+
+ ret = regmap_bulk_read(bat->regmap, bat->reg + PM8916_BMS_VM_BMS_FIFO_REG_0_LSB,
+ &vbat_data, PM8916_BMS_VM_FIFO_COUNT * 2);
+ if (ret)
+ return IRQ_HANDLED;
+
+ /*
+ * The VM-BMS hardware only collects voltage data and the software
+ * has to process it to calculate the OCV and SoC. Hardware provides
+ * up to 8 averaged measurements for software to take in account.
+ *
+ * Just use the last measured value for now to report the current
+ * battery voltage.
+ */
+ bat->vbat_now = vbat_data[PM8916_BMS_VM_FIFO_COUNT - 1] * 300;
+
+ power_supply_changed(bat->battery);
+
+ return IRQ_HANDLED;
+}
+
+static const struct power_supply_desc pm8916_bms_vm_battery_psy_desc = {
+ .name = "pm8916-bms-vm",
+ .type = POWER_SUPPLY_TYPE_BATTERY,
+ .properties = pm8916_bms_vm_battery_properties,
+ .num_properties = ARRAY_SIZE(pm8916_bms_vm_battery_properties),
+ .get_property = pm8916_bms_vm_battery_get_property,
+};
+
+static int pm8916_bms_vm_battery_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct pm8916_bms_vm_battery *bat;
+ struct power_supply_config psy_cfg = {};
+ int ret, irq;
+ unsigned int tmp;
+
+ bat = devm_kzalloc(dev, sizeof(*bat), GFP_KERNEL);
+ if (!bat)
+ return -ENOMEM;
+
+ bat->dev = dev;
+
+ bat->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+ if (!bat->regmap)
+ return -ENODEV;
+
+ of_property_read_u32(dev->of_node, "reg", &bat->reg);
+ if (bat->reg < 0)
+ return -EINVAL;
+
+ irq = platform_get_irq(pdev, 0);
+ if (irq < 0)
+ return irq;
+
+ ret = devm_request_threaded_irq(dev, irq, NULL, pm8916_bms_vm_fifo_update_done_irq,
+ IRQF_ONESHOT, "pm8916_vm_bms", bat);
+ if (ret)
+ return ret;
+
+ ret = regmap_bulk_read(bat->regmap, bat->reg + PM8916_PERPH_TYPE, &tmp, 2);
+ if (ret)
+ goto comm_error;
+
+ if (tmp != PM8916_BMS_VM_TYPE)
+ return dev_err_probe(dev, -ENODEV, "Device reported wrong type: 0x%X\n", tmp);
+
+ ret = regmap_write(bat->regmap, bat->reg + PM8916_BMS_VM_S1_SAMPLE_INTERVAL_CTL,
+ PM8916_BMS_VM_S1_SAMPLE_INTERVAL);
+ if (ret)
+ goto comm_error;
+ ret = regmap_write(bat->regmap, bat->reg + PM8916_BMS_VM_S2_SAMPLE_INTERVAL_CTL,
+ PM8916_BMS_VM_S2_SAMPLE_INTERVAL);
+ if (ret)
+ goto comm_error;
+ ret = regmap_write(bat->regmap, bat->reg + PM8916_BMS_VM_FIFO_LENGTH_CTL,
+ PM8916_BMS_VM_FIFO_COUNT << 4 | PM8916_BMS_VM_FIFO_COUNT);
+ if (ret)
+ goto comm_error;
+ ret = regmap_write(bat->regmap,
+ bat->reg + PM8916_BMS_VM_EN_CTL, PM8916_BMS_ENABLED);
+ if (ret)
+ goto comm_error;
+
+ ret = regmap_bulk_read(bat->regmap,
+ bat->reg + PM8916_BMS_VM_S3_S7_OCV_DATA0, &tmp, 2);
+ if (ret)
+ goto comm_error;
+
+ bat->last_ocv = tmp * 300;
+ bat->vbat_now = bat->last_ocv;
+
+ psy_cfg.drv_data = bat;
+ psy_cfg.of_node = dev->of_node;
+
+ bat->battery = devm_power_supply_register(dev, &pm8916_bms_vm_battery_psy_desc, &psy_cfg);
+ if (IS_ERR(bat->battery))
+ return dev_err_probe(dev, PTR_ERR(bat->battery), "Unable to register battery\n");
+
+ ret = power_supply_get_battery_info(bat->battery, &bat->info);
+ if (ret)
+ return dev_err_probe(dev, ret, "Unable to get battery info\n");
+
+ platform_set_drvdata(pdev, bat);
+
+ return 0;
+
+comm_error:
+ return dev_err_probe(dev, ret, "Unable to communicate with device\n");
+}
+
+static int pm8916_bms_vm_battery_suspend(struct platform_device *pdev, pm_message_t state)
+{
+ struct pm8916_bms_vm_battery *bat = platform_get_drvdata(pdev);
+ int ret;
+
+ /*
+ * Due to a hardware quirk the FSM doesn't switch states normally.
+ * Instead we unlock the debug registers and force S3 (Measure OCV/Sleep)
+ * mode every time we suspend.
+ */
+
+ ret = regmap_write(bat->regmap,
+ bat->reg + PM8916_SEC_ACCESS, PM8916_SEC_MAGIC);
+ if (ret)
+ goto error;
+ ret = regmap_write(bat->regmap,
+ bat->reg + PM8916_BMS_VM_MODE_CTL, PM8916_BMS_VM_MODE_FORCE_S3);
+ if (ret)
+ goto error;
+
+ return 0;
+
+error:
+ dev_err(bat->dev, "Failed to force S3 mode: %pe\n", ERR_PTR(ret));
+ return ret;
+}
+
+static int pm8916_bms_vm_battery_resume(struct platform_device *pdev)
+{
+ struct pm8916_bms_vm_battery *bat = platform_get_drvdata(pdev);
+ int ret;
+ unsigned int tmp;
+
+ ret = regmap_bulk_read(bat->regmap,
+ bat->reg + PM8916_BMS_VM_S3_S7_OCV_DATA0, &tmp, 2);
+
+ bat->last_ocv = tmp * 300;
+
+ ret = regmap_write(bat->regmap,
+ bat->reg + PM8916_SEC_ACCESS, PM8916_SEC_MAGIC);
+ if (ret)
+ goto error;
+ ret = regmap_write(bat->regmap,
+ bat->reg + PM8916_BMS_VM_MODE_CTL, PM8916_BMS_VM_MODE_NORMAL);
+ if (ret)
+ goto error;
+
+ return 0;
+
+error:
+ dev_err(bat->dev, "Failed to return normal mode: %pe\n", ERR_PTR(ret));
+ return ret;
+}
+
+static const struct of_device_id pm8916_bms_vm_battery_of_match[] = {
+ { .compatible = "qcom,pm8916-bms-vm", },
+ { },
+};
+MODULE_DEVICE_TABLE(of, pm8916_bms_vm_battery_of_match);
+
+static struct platform_driver pm8916_bms_vm_battery_driver = {
+ .driver = {
+ .name = "pm8916-bms-vm",
+ .of_match_table = of_match_ptr(pm8916_bms_vm_battery_of_match),
+ },
+ .probe = pm8916_bms_vm_battery_probe,
+ .suspend = pm8916_bms_vm_battery_suspend,
+ .resume = pm8916_bms_vm_battery_resume,
+};
+module_platform_driver(pm8916_bms_vm_battery_driver);
+
+MODULE_DESCRIPTION("pm8916 BMS-VM driver");
+MODULE_AUTHOR("Nikita Travkin <nikita@trvn.ru>");
+MODULE_LICENSE("GPL");
--
2.41.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 4/4] power: supply: Add driver for pm8916 lbc
2023-07-28 17:19 [PATCH 0/4] Add pm8916 VM-BMS and LBC Nikita Travkin
` (2 preceding siblings ...)
2023-07-28 17:19 ` [PATCH 3/4] power: supply: Add pm8916 VM-BMS support Nikita Travkin
@ 2023-07-28 17:19 ` Nikita Travkin
2023-07-29 5:28 ` kernel test robot
3 siblings, 1 reply; 11+ messages in thread
From: Nikita Travkin @ 2023-07-28 17:19 UTC (permalink / raw)
To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-pm, devicetree, linux-kernel, linux-arm-msm, Nikita Travkin
pm8916 LBC is a Linear Battery Charger hardware block in pm8916 PMIC.
This block implements simple CC/CV charging for Li-Po batteries.
The hardware has internal state machine to switch between modes and
works mostly autonomously, only needing the limits and targets to be
set to operate.
This driver allows setting limits and enabling the LBC block, monitoring
it's state.
Signed-off-by: Nikita Travkin <nikita@trvn.ru>
---
drivers/power/supply/Kconfig | 11 ++
drivers/power/supply/Makefile | 1 +
drivers/power/supply/pm8916_lbc.c | 385 ++++++++++++++++++++++++++++++++++++++
3 files changed, 397 insertions(+)
diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index e93a5a4d03e2..a2ea249a57c6 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -640,6 +640,17 @@ config BATTERY_PM8916_BMS_VM
To compile this driver as module, choose M here: the
module will be called pm8916_bms_vm.
+config CHARGER_PM8916_LBC
+ tristate "Qualcomm PM8916 Linear Battery Charger support"
+ depends on MFD_SPMI_PMIC || COMPILE_TEST
+ help
+ Say Y here to add support for Linear Battery Charger block
+ found in some Qualcomm PMICs such as PM8916. This hardware
+ blokc provides simple CC/CV battery charger.
+
+ To compile this driver as module, choose M here: the
+ module will be called pm8916_lbc.
+
config CHARGER_BQ2415X
tristate "TI BQ2415x battery charger driver"
depends on I2C
diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile
index fdf7916f80ed..e4bd9eb1261b 100644
--- a/drivers/power/supply/Makefile
+++ b/drivers/power/supply/Makefile
@@ -85,6 +85,7 @@ obj-$(CONFIG_CHARGER_MT6360) += mt6360_charger.o
obj-$(CONFIG_CHARGER_MT6370) += mt6370-charger.o
obj-$(CONFIG_CHARGER_QCOM_SMBB) += qcom_smbb.o
obj-$(CONFIG_BATTERY_PM8916_BMS_VM) += pm8916_bms_vm.o
+obj-$(CONFIG_CHARGER_PM8916_LBC) += pm8916_lbc.o
obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o
obj-$(CONFIG_CHARGER_BQ24190) += bq24190_charger.o
obj-$(CONFIG_CHARGER_BQ24257) += bq24257_charger.o
diff --git a/drivers/power/supply/pm8916_lbc.c b/drivers/power/supply/pm8916_lbc.c
new file mode 100644
index 000000000000..800ca3ff6d60
--- /dev/null
+++ b/drivers/power/supply/pm8916_lbc.c
@@ -0,0 +1,385 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2023, Nikita Travkin <nikita@trvn.ru>
+ */
+
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/power_supply.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/extcon-provider.h>
+
+/* Two bytes: type + subtype */
+#define PM8916_PERPH_TYPE 0x04
+#define PM8916_LBC_CHGR_TYPE 0x1502
+#define PM8916_LBC_BAT_IF_TYPE 0x1602
+#define PM8916_LBC_USB_TYPE 0x1702
+#define PM8916_LBC_MISC_TYPE 0x1802
+
+#define PM8916_LBC_CHGR_CHG_OPTION 0x08
+#define PM8916_LBC_CHGR_PMIC_CHARGER BIT(7)
+
+#define PM8916_LBC_CHGR_CHG_STATUS 0x09
+
+#define PM8916_INT_RT_STS 0x10
+
+#define PM8916_LBC_USB_USBIN_VALID BIT(1)
+
+#define PM8916_LBC_CHGR_VDD_MAX 0x40
+#define PM8916_LBC_CHGR_VDD_SAFE 0x41
+#define PM8916_LBC_CHGR_IBAT_MAX 0x44
+#define PM8916_LBC_CHGR_IBAT_SAFE 0x45
+
+#define PM8916_LBC_CHGR_TCHG_MAX_EN 0x60
+#define PM8916_LBC_CHGR_TCHG_MAX_ENABLED BIT(7)
+#define PM8916_LBC_CHGR_TCHG_MAX 0x61
+
+#define PM8916_LBC_CHGR_CHG_CTRL 0x49
+#define PM8916_LBC_CHGR_CHG_EN BIT(7)
+#define PM8916_LBC_CHGR_PSTG_EN BIT(5)
+
+#define PM8916_LBC_CHGR_MIN_CURRENT 90000
+#define PM8916_LBC_CHGR_MAX_CURRENT 1440000
+
+#define PM8916_LBC_CHGR_MIN_VOLTAGE 4000000
+#define PM8916_LBC_CHGR_MAX_VOLTAGE 4775000
+#define PM8916_LBC_CHGR_VOLTAGE_STEP 25000
+
+#define PM8916_LBC_CHGR_MIN_TIME 4
+#define PM8916_LBC_CHGR_MAX_TIME 256
+
+struct pm8916_lbc_charger {
+ struct device *dev;
+ struct extcon_dev *edev;
+ struct power_supply *charger;
+ struct power_supply_battery_info *info;
+ struct regmap *regmap;
+ unsigned int reg[4];
+ bool online;
+ unsigned int charge_voltage_max;
+ unsigned int charge_voltage_safe;
+ unsigned int charge_current_max;
+ unsigned int charge_current_safe;
+};
+
+static const unsigned int pm8916_lbc_charger_cable[] = {
+ EXTCON_USB,
+ EXTCON_NONE,
+};
+
+enum {
+ LBC_CHGR = 0,
+ LBC_BAT_IF,
+ LBC_USB,
+ LBC_MISC,
+};
+
+static int pm8916_lbc_charger_configure(struct pm8916_lbc_charger *chg)
+{
+ int ret = 0;
+ unsigned int tmp;
+
+ chg->charge_voltage_max = clamp_t(u32, chg->charge_voltage_max,
+ PM8916_LBC_CHGR_MIN_VOLTAGE, chg->charge_voltage_safe);
+
+ tmp = chg->charge_voltage_max - PM8916_LBC_CHGR_MIN_VOLTAGE;
+ tmp /= PM8916_LBC_CHGR_VOLTAGE_STEP;
+ chg->charge_voltage_max = PM8916_LBC_CHGR_MIN_VOLTAGE + tmp * PM8916_LBC_CHGR_VOLTAGE_STEP;
+
+ ret = regmap_write(chg->regmap, chg->reg[LBC_CHGR] + PM8916_LBC_CHGR_VDD_MAX, tmp);
+ if (ret)
+ goto error;
+
+ chg->charge_current_max = min(chg->charge_current_max, chg->charge_current_safe);
+
+ tmp = clamp_t(u32, chg->charge_current_max,
+ PM8916_LBC_CHGR_MIN_CURRENT, PM8916_LBC_CHGR_MAX_CURRENT);
+
+ tmp = chg->charge_current_max / PM8916_LBC_CHGR_MIN_CURRENT - 1;
+ chg->charge_current_max = (tmp + 1) * PM8916_LBC_CHGR_MIN_CURRENT;
+
+ ret = regmap_write(chg->regmap, chg->reg[LBC_CHGR] + PM8916_LBC_CHGR_IBAT_MAX, tmp);
+ if (ret)
+ goto error;
+
+ ret = regmap_write(chg->regmap, chg->reg[LBC_CHGR] + PM8916_LBC_CHGR_CHG_CTRL,
+ PM8916_LBC_CHGR_CHG_EN | PM8916_LBC_CHGR_PSTG_EN);
+ if (ret)
+ goto error;
+
+ return ret;
+
+error:
+ dev_err(chg->dev, "Failed to configure charging: %pe\n", ERR_PTR(ret));
+ return ret;
+}
+
+static int pm8916_lbc_charger_get_property(struct power_supply *psy,
+ enum power_supply_property psp,
+ union power_supply_propval *val)
+{
+ struct pm8916_lbc_charger *chg = power_supply_get_drvdata(psy);
+ int ret = 0;
+ unsigned int tmp;
+
+ switch (psp) {
+ case POWER_SUPPLY_PROP_ONLINE:
+ val->intval = chg->online;
+ return 0;
+
+ case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
+ val->intval = chg->charge_voltage_max;
+ return 0;
+
+ case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+ val->intval = chg->charge_current_max;
+ return 0;
+
+ default:
+ return -EINVAL;
+ };
+}
+
+static int pm8916_lbc_charger_set_property(struct power_supply *psy,
+ enum power_supply_property prop,
+ const union power_supply_propval *val)
+{
+ struct pm8916_lbc_charger *chg = power_supply_get_drvdata(psy);
+
+ switch (prop) {
+ case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+ chg->charge_current_max = val->intval;
+ return pm8916_lbc_charger_configure(chg);
+ default:
+ return -EINVAL;
+ }
+}
+
+static int pm8916_lbc_charger_property_is_writeable(struct power_supply *psy,
+ enum power_supply_property psp)
+{
+ switch (psp) {
+ case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static enum power_supply_property pm8916_lbc_charger_properties[] = {
+ POWER_SUPPLY_PROP_ONLINE,
+ POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
+ POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
+};
+
+static irqreturn_t pm8916_lbc_charger_state_changed_irq(int irq, void *data)
+{
+ struct pm8916_lbc_charger *chg = data;
+ unsigned int tmp;
+ int ret;
+
+ ret = regmap_read(chg->regmap, chg->reg[LBC_USB] + PM8916_INT_RT_STS, &tmp);
+ if (ret)
+ return IRQ_HANDLED;
+
+ chg->online = !!(tmp & PM8916_LBC_USB_USBIN_VALID);
+ extcon_set_state_sync(chg->edev, EXTCON_USB, chg->online);
+
+ power_supply_changed(chg->charger);
+
+ return IRQ_HANDLED;
+}
+
+static int pm8916_lbc_charger_probe_dt(struct pm8916_lbc_charger *chg)
+{
+ struct device *dev = chg->dev;
+ struct device_node *np = dev->of_node;
+ int ret = 0;
+ unsigned int tmp;
+
+ ret = of_property_read_u32(np, "qcom,fast-charge-safe-voltage", &chg->charge_voltage_safe);
+ if (ret)
+ return ret;
+ if (chg->charge_voltage_safe < PM8916_LBC_CHGR_MIN_VOLTAGE)
+ return -EINVAL;
+
+ chg->charge_voltage_safe = clamp_t(u32, chg->charge_voltage_safe,
+ PM8916_LBC_CHGR_MIN_VOLTAGE, PM8916_LBC_CHGR_MAX_VOLTAGE);
+
+ tmp = chg->charge_voltage_safe - PM8916_LBC_CHGR_MIN_VOLTAGE;
+ tmp /= PM8916_LBC_CHGR_VOLTAGE_STEP;
+ ret = regmap_write(chg->regmap, chg->reg[LBC_CHGR] + PM8916_LBC_CHGR_VDD_SAFE, tmp);
+ if (ret)
+ return ret;
+
+ ret = of_property_read_u32(np, "qcom,fast-charge-safe-current", &chg->charge_current_safe);
+ if (ret)
+ return ret;
+ if (chg->charge_current_safe < PM8916_LBC_CHGR_MIN_CURRENT)
+ return -EINVAL;
+
+ chg->charge_current_safe = clamp_t(u32, chg->charge_current_safe,
+ PM8916_LBC_CHGR_MIN_CURRENT, PM8916_LBC_CHGR_MAX_CURRENT);
+
+ chg->charge_current_max = chg->charge_current_safe;
+
+ tmp = chg->charge_current_safe / PM8916_LBC_CHGR_MIN_CURRENT - 1;
+ ret = regmap_write(chg->regmap, chg->reg[LBC_CHGR] + PM8916_LBC_CHGR_IBAT_SAFE, tmp);
+ if (ret)
+ return ret;
+
+ /* Disable charger timeout. */
+ ret = regmap_write(chg->regmap, chg->reg[LBC_CHGR] + PM8916_LBC_CHGR_TCHG_MAX_EN, 0x00);
+ if (ret)
+ return ret;
+
+ return ret;
+}
+
+static const struct power_supply_desc pm8916_lbc_charger_psy_desc = {
+ .name = "pm8916-lbc-chgr",
+ .type = POWER_SUPPLY_TYPE_USB,
+ .properties = pm8916_lbc_charger_properties,
+ .num_properties = ARRAY_SIZE(pm8916_lbc_charger_properties),
+ .get_property = pm8916_lbc_charger_get_property,
+ .set_property = pm8916_lbc_charger_set_property,
+ .property_is_writeable = pm8916_lbc_charger_property_is_writeable,
+};
+
+static int pm8916_lbc_charger_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct pm8916_lbc_charger *chg;
+ struct power_supply_config psy_cfg = {};
+ int ret, len, irq;
+ unsigned int tmp;
+
+ chg = devm_kzalloc(dev, sizeof(*chg), GFP_KERNEL);
+ if (!chg)
+ return -ENOMEM;
+
+ chg->dev = dev;
+
+ chg->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+ if (!chg->regmap)
+ return -ENODEV;
+
+ len = of_property_count_u32_elems(dev->of_node, "reg");
+ if (len < 0)
+ return len;
+ if (len != 4)
+ return dev_err_probe(dev, -EINVAL,
+ "Wrong amount of reg values: %d (4 expected)\n", len);
+
+ irq = platform_get_irq(pdev, 0);
+ if (irq < 0)
+ return irq;
+
+ ret = devm_request_threaded_irq(dev, irq, NULL, pm8916_lbc_charger_state_changed_irq,
+ IRQF_ONESHOT, "pm8916_lbc", chg);
+ if (ret)
+ return ret;
+
+ ret = of_property_read_u32_array(dev->of_node, "reg", chg->reg, len);
+ if (ret)
+ return ret;
+
+ ret = regmap_bulk_read(chg->regmap, chg->reg[LBC_CHGR] + PM8916_PERPH_TYPE, &tmp, 2);
+ if (ret)
+ goto comm_error;
+ if (tmp != PM8916_LBC_CHGR_TYPE)
+ goto type_error;
+
+ ret = regmap_bulk_read(chg->regmap, chg->reg[LBC_BAT_IF] + PM8916_PERPH_TYPE, &tmp, 2);
+ if (ret)
+ goto comm_error;
+ if (tmp != PM8916_LBC_BAT_IF_TYPE)
+ goto type_error;
+
+ ret = regmap_bulk_read(chg->regmap, chg->reg[LBC_USB] + PM8916_PERPH_TYPE, &tmp, 2);
+ if (ret)
+ goto comm_error;
+ if (tmp != PM8916_LBC_USB_TYPE)
+ goto type_error;
+
+ ret = regmap_bulk_read(chg->regmap, chg->reg[LBC_MISC] + PM8916_PERPH_TYPE, &tmp, 2);
+ if (ret)
+ goto comm_error;
+ if (tmp != PM8916_LBC_MISC_TYPE)
+ goto type_error;
+
+ ret = regmap_read(chg->regmap, chg->reg[LBC_CHGR] + PM8916_LBC_CHGR_CHG_OPTION, &tmp);
+ if (ret)
+ goto comm_error;
+ if (tmp != PM8916_LBC_CHGR_PMIC_CHARGER)
+ dev_err_probe(dev, -ENODEV, "The system is using an external charger\n");
+
+ ret = pm8916_lbc_charger_probe_dt(chg);
+ if (ret)
+ dev_err_probe(dev, ret, "Error while parsing device tree\n");
+
+ psy_cfg.drv_data = chg;
+ psy_cfg.of_node = dev->of_node;
+
+ chg->charger = devm_power_supply_register(dev, &pm8916_lbc_charger_psy_desc, &psy_cfg);
+ if (IS_ERR(chg->charger))
+ return dev_err_probe(dev, PTR_ERR(chg->charger), "Unable to register charger\n");
+
+ ret = power_supply_get_battery_info(chg->charger, &chg->info);
+ if (ret)
+ return dev_err_probe(dev, ret, "Unable to get battery info\n");
+
+ chg->edev = devm_extcon_dev_allocate(dev, pm8916_lbc_charger_cable);
+ if (IS_ERR(chg->edev))
+ return PTR_ERR(chg->edev);
+
+ ret = devm_extcon_dev_register(dev, chg->edev);
+ if (ret < 0)
+ return dev_err_probe(dev, ret, "failed to register extcon device\n");
+
+ ret = regmap_read(chg->regmap, chg->reg[LBC_USB] + PM8916_INT_RT_STS, &tmp);
+ if (ret)
+ goto comm_error;
+
+ chg->online = !!(tmp & PM8916_LBC_USB_USBIN_VALID);
+ extcon_set_state_sync(chg->edev, EXTCON_USB, chg->online);
+
+ chg->charge_voltage_max = chg->info->voltage_max_design_uv;
+ ret = pm8916_lbc_charger_configure(chg);
+ if (ret)
+ return ret;
+
+ return 0;
+
+comm_error:
+ return dev_err_probe(dev, ret, "Unable to communicate with device\n");
+
+type_error:
+ return dev_err_probe(dev, -ENODEV, "Device reported wrong type: 0x%X\n", tmp);
+}
+
+static const struct of_device_id pm8916_lbc_charger_of_match[] = {
+ { .compatible = "qcom,pm8916-lbc", },
+ { },
+};
+MODULE_DEVICE_TABLE(of, pm8916_lbc_charger_of_match);
+
+static struct platform_driver pm8916_lbc_charger_driver = {
+ .driver = {
+ .name = "pm8916-lbc",
+ .of_match_table = of_match_ptr(pm8916_lbc_charger_of_match),
+ },
+ .probe = pm8916_lbc_charger_probe,
+};
+module_platform_driver(pm8916_lbc_charger_driver);
+
+MODULE_DESCRIPTION("pm8916 LBC driver");
+MODULE_AUTHOR("Nikita Travkin <nikita@trvn.ru>");
+MODULE_LICENSE("GPL");
--
2.41.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 4/4] power: supply: Add driver for pm8916 lbc
2023-07-28 17:19 ` [PATCH 4/4] power: supply: Add driver for pm8916 lbc Nikita Travkin
@ 2023-07-29 5:28 ` kernel test robot
0 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2023-07-29 5:28 UTC (permalink / raw)
To: Nikita Travkin, Sebastian Reichel, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: oe-kbuild-all, linux-pm, devicetree, linux-kernel, linux-arm-msm,
Nikita Travkin
Hi Nikita,
kernel test robot noticed the following build warnings:
[auto build test WARNING on d7b3af5a77e8d8da28f435f313e069aea5bcf172]
url: https://github.com/intel-lab-lkp/linux/commits/Nikita-Travkin/dt-bindings-power-supply-Add-pm8916-VM-BMS/20230729-013044
base: d7b3af5a77e8d8da28f435f313e069aea5bcf172
patch link: https://lore.kernel.org/r/20230728-pm8916-bms-lbc-v1-4-56da32467487%40trvn.ru
patch subject: [PATCH 4/4] power: supply: Add driver for pm8916 lbc
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20230729/202307291336.Zxmj8R1g-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230729/202307291336.Zxmj8R1g-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202307291336.Zxmj8R1g-lkp@intel.com/
All warnings (new ones prefixed by >>):
drivers/power/supply/pm8916_lbc.c: In function 'pm8916_lbc_charger_get_property':
>> drivers/power/supply/pm8916_lbc.c:130:22: warning: unused variable 'tmp' [-Wunused-variable]
130 | unsigned int tmp;
| ^~~
>> drivers/power/supply/pm8916_lbc.c:129:13: warning: unused variable 'ret' [-Wunused-variable]
129 | int ret = 0;
| ^~~
vim +/tmp +130 drivers/power/supply/pm8916_lbc.c
123
124 static int pm8916_lbc_charger_get_property(struct power_supply *psy,
125 enum power_supply_property psp,
126 union power_supply_propval *val)
127 {
128 struct pm8916_lbc_charger *chg = power_supply_get_drvdata(psy);
> 129 int ret = 0;
> 130 unsigned int tmp;
131
132 switch (psp) {
133 case POWER_SUPPLY_PROP_ONLINE:
134 val->intval = chg->online;
135 return 0;
136
137 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
138 val->intval = chg->charge_voltage_max;
139 return 0;
140
141 case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
142 val->intval = chg->charge_current_max;
143 return 0;
144
145 default:
146 return -EINVAL;
147 };
148 }
149
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/4] dt-bindings: power: supply: Add pm8916 VM-BMS
2023-07-28 17:19 ` [PATCH 1/4] dt-bindings: power: supply: Add pm8916 VM-BMS Nikita Travkin
@ 2023-07-29 10:03 ` Conor Dooley
2023-07-29 12:06 ` Nikita Travkin
0 siblings, 1 reply; 11+ messages in thread
From: Conor Dooley @ 2023-07-29 10:03 UTC (permalink / raw)
To: Nikita Travkin
Cc: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-pm, devicetree, linux-kernel, linux-arm-msm
[-- Attachment #1: Type: text/plain, Size: 2394 bytes --]
On Fri, Jul 28, 2023 at 10:19:30PM +0500, Nikita Travkin wrote:
> Qualcomm Voltage Mode BMS is a battery monitoring block in PM8916 PMIC.
> Document it's DT binding.
>
> Signed-off-by: Nikita Travkin <nikita@trvn.ru>
> ---
> .../bindings/power/supply/qcom,pm8916-bms-vm.yaml | 64 ++++++++++++++++++++++
> 1 file changed, 64 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/power/supply/qcom,pm8916-bms-vm.yaml b/Documentation/devicetree/bindings/power/supply/qcom,pm8916-bms-vm.yaml
> new file mode 100644
> index 000000000000..455973d46862
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/power/supply/qcom,pm8916-bms-vm.yaml
> @@ -0,0 +1,64 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/power/supply/qcom,pm8916-bms-vm.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Qualcomm Voltage Mode BMS
> +
> +maintainers:
> + - Nikita Travkin <nikita@trvn.ru>
> +
> +description:
> + Voltage Mode BMS is a hardware block found in some Qualcomm PMICs
> + such as pm8916. This block performs battery voltage monitoring.
> +
> +allOf:
> + - $ref: power-supply.yaml#
> +
> +properties:
> + compatible:
> + const: qcom,pm8916-bms-vm
> +
> + reg:
> + maxItems: 1
> +
> + interrupts:
> + items:
> + - description: FIFO update done
You don't need items: here since you only have one - const: will do.
> + interrupt-names:
> + items:
> + - const: fifo
Same here, but do you really need a name, when you have only one
interrupt?
Thanks,
Conor.
> +
> + monitored-battery: true
> +
> + power-supplies: true
> +
> +
> +required:
> + - compatible
> + - reg
> + - interrupts
> + - interrupt-names
> + - monitored-battery
> +
> +additionalProperties: false
> +
> +examples:
> + - |
> + #include <dt-bindings/interrupt-controller/irq.h>
> + pmic {
> + #address-cells = <1>;
> + #size-cells = <0>;
> +
> + battery@4000 {
> + compatible = "qcom,pm8916-bms-vm";
> + reg = <0x4000>;
> + interrupts = <0x0 0x40 4 IRQ_TYPE_EDGE_RISING>;
> + interrupt-names = "fifo";
> +
> + monitored-battery = <&battery>;
> + power-supplies = <&pm8916_charger>;
> + };
> + };
>
> --
> 2.41.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/4] dt-bindings: power: supply: Add pm8916 VM-BMS
2023-07-29 10:03 ` Conor Dooley
@ 2023-07-29 12:06 ` Nikita Travkin
2023-07-29 12:10 ` Conor Dooley
0 siblings, 1 reply; 11+ messages in thread
From: Nikita Travkin @ 2023-07-29 12:06 UTC (permalink / raw)
To: Conor Dooley
Cc: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-pm, devicetree, linux-kernel, linux-arm-msm
Conor Dooley писал(а) 29.07.2023 15:03:
> On Fri, Jul 28, 2023 at 10:19:30PM +0500, Nikita Travkin wrote:
>> Qualcomm Voltage Mode BMS is a battery monitoring block in PM8916 PMIC.
>> Document it's DT binding.
>>
>> Signed-off-by: Nikita Travkin <nikita@trvn.ru>
>> ---
>> .../bindings/power/supply/qcom,pm8916-bms-vm.yaml | 64 ++++++++++++++++++++++
>> 1 file changed, 64 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/power/supply/qcom,pm8916-bms-vm.yaml b/Documentation/devicetree/bindings/power/supply/qcom,pm8916-bms-vm.yaml
>> new file mode 100644
>> index 000000000000..455973d46862
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/power/supply/qcom,pm8916-bms-vm.yaml
>> @@ -0,0 +1,64 @@
>> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
>> +%YAML 1.2
>> +---
>> +$id: http://devicetree.org/schemas/power/supply/qcom,pm8916-bms-vm.yaml#
>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>> +
>> +title: Qualcomm Voltage Mode BMS
>> +
>> +maintainers:
>> + - Nikita Travkin <nikita@trvn.ru>
>> +
>> +description:
>> + Voltage Mode BMS is a hardware block found in some Qualcomm PMICs
>> + such as pm8916. This block performs battery voltage monitoring.
>> +
>> +allOf:
>> + - $ref: power-supply.yaml#
>> +
>> +properties:
>> + compatible:
>> + const: qcom,pm8916-bms-vm
>> +
>> + reg:
>> + maxItems: 1
>> +
>> + interrupts:
>> + items:
>> + - description: FIFO update done
>
> You don't need items: here since you only have one - const: will do.
>
Ack.
>> + interrupt-names:
>> + items:
>> + - const: fifo
>
> Same here, but do you really need a name, when you have only one
> interrupt?
>
Hm, thinking of this more, the hardware actually has more than one
interrupt, even though this one seems to be the only really useful
one. Would a better way forward be to list all of them (and fix
the driver to get the value by it's name) or it would be
acceptable to leave the names here and extend the list at a later
date when (if ever) other interrupts are needed?
Thanks for the review!
Nikita
> Thanks,
> Conor.
>
>> +
>> + monitored-battery: true
>> +
>> + power-supplies: true
>> +
>> +
>> +required:
>> + - compatible
>> + - reg
>> + - interrupts
>> + - interrupt-names
>> + - monitored-battery
>> +
>> +additionalProperties: false
>> +
>> +examples:
>> + - |
>> + #include <dt-bindings/interrupt-controller/irq.h>
>> + pmic {
>> + #address-cells = <1>;
>> + #size-cells = <0>;
>> +
>> + battery@4000 {
>> + compatible = "qcom,pm8916-bms-vm";
>> + reg = <0x4000>;
>> + interrupts = <0x0 0x40 4 IRQ_TYPE_EDGE_RISING>;
>> + interrupt-names = "fifo";
>> +
>> + monitored-battery = <&battery>;
>> + power-supplies = <&pm8916_charger>;
>> + };
>> + };
>>
>> --
>> 2.41.0
>>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/4] dt-bindings: power: supply: Add pm8916 VM-BMS
2023-07-29 12:06 ` Nikita Travkin
@ 2023-07-29 12:10 ` Conor Dooley
2023-07-29 12:15 ` Nikita Travkin
0 siblings, 1 reply; 11+ messages in thread
From: Conor Dooley @ 2023-07-29 12:10 UTC (permalink / raw)
To: Nikita Travkin
Cc: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-pm, devicetree, linux-kernel, linux-arm-msm
[-- Attachment #1: Type: text/plain, Size: 1038 bytes --]
On Sat, Jul 29, 2023 at 05:06:14PM +0500, Nikita Travkin wrote:
> Conor Dooley писал(а) 29.07.2023 15:03:
> > On Fri, Jul 28, 2023 at 10:19:30PM +0500, Nikita Travkin wrote:
> >> + interrupt-names:
> >> + items:
> >> + - const: fifo
> >
> > Same here, but do you really need a name, when you have only one
> > interrupt?
> >
>
> Hm, thinking of this more, the hardware actually has more than one
> interrupt, even though this one seems to be the only really useful
> one. Would a better way forward be to list all of them
Yes.
> (and fix
> the driver to get the value by it's name)
It's not a fix to do that, the order of the interrupts is not variable,
so there's nothing wrong with using the indices. You can do it if you
like.
> or it would be
> acceptable to leave the names here and extend the list at a later
> date when (if ever) other interrupts are needed?
If you know what they are, please describe them now, even if the driver
does not use them (yet).
Thanks,
Conor.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/4] dt-bindings: power: supply: Add pm8916 VM-BMS
2023-07-29 12:10 ` Conor Dooley
@ 2023-07-29 12:15 ` Nikita Travkin
2023-07-30 10:05 ` Conor Dooley
0 siblings, 1 reply; 11+ messages in thread
From: Nikita Travkin @ 2023-07-29 12:15 UTC (permalink / raw)
To: Conor Dooley
Cc: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-pm, devicetree, linux-kernel, linux-arm-msm
Conor Dooley писал(а) 29.07.2023 17:10:
> On Sat, Jul 29, 2023 at 05:06:14PM +0500, Nikita Travkin wrote:
>> Conor Dooley писал(а) 29.07.2023 15:03:
>> > On Fri, Jul 28, 2023 at 10:19:30PM +0500, Nikita Travkin wrote:
>
>> >> + interrupt-names:
>> >> + items:
>> >> + - const: fifo
>> >
>> > Same here, but do you really need a name, when you have only one
>> > interrupt?
>> >
>>
>> Hm, thinking of this more, the hardware actually has more than one
>> interrupt, even though this one seems to be the only really useful
>> one. Would a better way forward be to list all of them
>
> Yes.
>
>> (and fix
>> the driver to get the value by it's name)
>
> It's not a fix to do that, the order of the interrupts is not variable,
> so there's nothing wrong with using the indices. You can do it if you
> like.
>
>> or it would be
>> acceptable to leave the names here and extend the list at a later
>> date when (if ever) other interrupts are needed?
>
> If you know what they are, please describe them now, even if the driver
> does not use them (yet).
>
Thanks for the clarification! Will make sure both drivers have all
interrupts described in v2
Nikita
> Thanks,
> Conor.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/4] dt-bindings: power: supply: Add pm8916 VM-BMS
2023-07-29 12:15 ` Nikita Travkin
@ 2023-07-30 10:05 ` Conor Dooley
0 siblings, 0 replies; 11+ messages in thread
From: Conor Dooley @ 2023-07-30 10:05 UTC (permalink / raw)
To: Nikita Travkin
Cc: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-pm, devicetree, linux-kernel, linux-arm-msm
[-- Attachment #1: Type: text/plain, Size: 1586 bytes --]
On Sat, Jul 29, 2023 at 05:15:06PM +0500, Nikita Travkin wrote:
> Conor Dooley писал(а) 29.07.2023 17:10:
> > On Sat, Jul 29, 2023 at 05:06:14PM +0500, Nikita Travkin wrote:
> >> Conor Dooley писал(а) 29.07.2023 15:03:
> >> > On Fri, Jul 28, 2023 at 10:19:30PM +0500, Nikita Travkin wrote:
> >
> >> >> + interrupt-names:
> >> >> + items:
> >> >> + - const: fifo
> >> >
> >> > Same here, but do you really need a name, when you have only one
> >> > interrupt?
> >> >
> >>
> >> Hm, thinking of this more, the hardware actually has more than one
> >> interrupt, even though this one seems to be the only really useful
> >> one. Would a better way forward be to list all of them
> >
> > Yes.
> >
> >> (and fix
> >> the driver to get the value by it's name)
> >
> > It's not a fix to do that, the order of the interrupts is not variable,
> > so there's nothing wrong with using the indices. You can do it if you
> > like.
> >
> >> or it would be
> >> acceptable to leave the names here and extend the list at a later
> >> date when (if ever) other interrupts are needed?
> >
> > If you know what they are, please describe them now, even if the driver
> > does not use them (yet).
> >
>
> Thanks for the clarification! Will make sure both drivers have all
> interrupts described in v2
Note that bindings describe hardware, not the driver. The driver need
not touch the other interrupts if it does not use them, but make the
hardware description (IOW the dt-binding) accurate & as complete as you
can.
Thanks,
Conor.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2023-07-30 10:05 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-28 17:19 [PATCH 0/4] Add pm8916 VM-BMS and LBC Nikita Travkin
2023-07-28 17:19 ` [PATCH 1/4] dt-bindings: power: supply: Add pm8916 VM-BMS Nikita Travkin
2023-07-29 10:03 ` Conor Dooley
2023-07-29 12:06 ` Nikita Travkin
2023-07-29 12:10 ` Conor Dooley
2023-07-29 12:15 ` Nikita Travkin
2023-07-30 10:05 ` Conor Dooley
2023-07-28 17:19 ` [PATCH 2/4] dt-bindings: power: supply: Add pm8916 LBC Nikita Travkin
2023-07-28 17:19 ` [PATCH 3/4] power: supply: Add pm8916 VM-BMS support Nikita Travkin
2023-07-28 17:19 ` [PATCH 4/4] power: supply: Add driver for pm8916 lbc Nikita Travkin
2023-07-29 5:28 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox