summaryrefslogtreecommitdiffstats
path: root/drivers/power/supply/bq25890_charger.c
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2022-02-01 14:06:50 +0100
committerSebastian Reichel <sebastian.reichel@collabora.com>2022-02-01 14:55:11 +0100
commit7b22a97464b4fd49b27a5eda72229854d0f454fa (patch)
tree40f34e591f980ec1cba51c662ef3e2efba870821 /drivers/power/supply/bq25890_charger.c
parentpower: supply: bq25890: Reduce reported CONSTANT_CHARGE_CURRENT_MAX for low t... (diff)
downloadlinux-7b22a97464b4fd49b27a5eda72229854d0f454fa.tar.xz
linux-7b22a97464b4fd49b27a5eda72229854d0f454fa.zip
power: supply: bq25890: Add a bq25890_rw_init_data() helper
On most x86/ACPI devices there is no devicetree to supply the necessary init-data. Instead the firmware already fully initializes the bq25890 charger at boot. Factor out the current code to write all the init_data from devicetree into a new bq25890_rw_init_data() helper which can both write the data to the charger (the current behavior) as well as read it back from the charger into the init_data struct. This is a preparation patch for adding support for x86/ACPI device's where the init_data must be read back from the bq25890 charger. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Diffstat (limited to 'drivers/power/supply/bq25890_charger.c')
-rw-r--r--drivers/power/supply/bq25890_charger.c62
1 files changed, 40 insertions, 22 deletions
diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
index 7a3269c06b38..eaf0400b632f 100644
--- a/drivers/power/supply/bq25890_charger.c
+++ b/drivers/power/supply/bq25890_charger.c
@@ -693,29 +693,52 @@ static int bq25890_chip_reset(struct bq25890_device *bq)
return 0;
}
-static int bq25890_hw_init(struct bq25890_device *bq)
+static int bq25890_rw_init_data(struct bq25890_device *bq)
{
+ bool write = true;
int ret;
int i;
const struct {
enum bq25890_fields id;
- u32 value;
+ u8 *value;
} init_data[] = {
- {F_ICHG, bq->init_data.ichg},
- {F_VREG, bq->init_data.vreg},
- {F_ITERM, bq->init_data.iterm},
- {F_IPRECHG, bq->init_data.iprechg},
- {F_SYSVMIN, bq->init_data.sysvmin},
- {F_BOOSTV, bq->init_data.boostv},
- {F_BOOSTI, bq->init_data.boosti},
- {F_BOOSTF, bq->init_data.boostf},
- {F_EN_ILIM, bq->init_data.ilim_en},
- {F_TREG, bq->init_data.treg},
- {F_BATCMP, bq->init_data.rbatcomp},
- {F_VCLAMP, bq->init_data.vclamp},
+ {F_ICHG, &bq->init_data.ichg},
+ {F_VREG, &bq->init_data.vreg},
+ {F_ITERM, &bq->init_data.iterm},
+ {F_IPRECHG, &bq->init_data.iprechg},
+ {F_SYSVMIN, &bq->init_data.sysvmin},
+ {F_BOOSTV, &bq->init_data.boostv},
+ {F_BOOSTI, &bq->init_data.boosti},
+ {F_BOOSTF, &bq->init_data.boostf},
+ {F_EN_ILIM, &bq->init_data.ilim_en},
+ {F_TREG, &bq->init_data.treg},
+ {F_BATCMP, &bq->init_data.rbatcomp},
+ {F_VCLAMP, &bq->init_data.vclamp},
};
+ for (i = 0; i < ARRAY_SIZE(init_data); i++) {
+ if (write) {
+ ret = bq25890_field_write(bq, init_data[i].id,
+ *init_data[i].value);
+ } else {
+ ret = bq25890_field_read(bq, init_data[i].id);
+ if (ret >= 0)
+ *init_data[i].value = ret;
+ }
+ if (ret < 0) {
+ dev_dbg(bq->dev, "Accessing init data failed %d\n", ret);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static int bq25890_hw_init(struct bq25890_device *bq)
+{
+ int ret;
+
ret = bq25890_chip_reset(bq);
if (ret < 0) {
dev_dbg(bq->dev, "Reset failed %d\n", ret);
@@ -730,14 +753,9 @@ static int bq25890_hw_init(struct bq25890_device *bq)
}
/* initialize currents/voltages and other parameters */
- for (i = 0; i < ARRAY_SIZE(init_data); i++) {
- ret = bq25890_field_write(bq, init_data[i].id,
- init_data[i].value);
- if (ret < 0) {
- dev_dbg(bq->dev, "Writing init data failed %d\n", ret);
- return ret;
- }
- }
+ ret = bq25890_rw_init_data(bq);
+ if (ret)
+ return ret;
ret = bq25890_get_chip_state(bq, &bq->state);
if (ret < 0) {