Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Hans de Goede and committed by
Sebastian Reichel
7b22a974 c562a43a

+40 -22
+40 -22
drivers/power/supply/bq25890_charger.c
··· 693 693 return 0; 694 694 } 695 695 696 - static int bq25890_hw_init(struct bq25890_device *bq) 696 + static int bq25890_rw_init_data(struct bq25890_device *bq) 697 697 { 698 + bool write = true; 698 699 int ret; 699 700 int i; 700 701 701 702 const struct { 702 703 enum bq25890_fields id; 703 - u32 value; 704 + u8 *value; 704 705 } init_data[] = { 705 - {F_ICHG, bq->init_data.ichg}, 706 - {F_VREG, bq->init_data.vreg}, 707 - {F_ITERM, bq->init_data.iterm}, 708 - {F_IPRECHG, bq->init_data.iprechg}, 709 - {F_SYSVMIN, bq->init_data.sysvmin}, 710 - {F_BOOSTV, bq->init_data.boostv}, 711 - {F_BOOSTI, bq->init_data.boosti}, 712 - {F_BOOSTF, bq->init_data.boostf}, 713 - {F_EN_ILIM, bq->init_data.ilim_en}, 714 - {F_TREG, bq->init_data.treg}, 715 - {F_BATCMP, bq->init_data.rbatcomp}, 716 - {F_VCLAMP, bq->init_data.vclamp}, 706 + {F_ICHG, &bq->init_data.ichg}, 707 + {F_VREG, &bq->init_data.vreg}, 708 + {F_ITERM, &bq->init_data.iterm}, 709 + {F_IPRECHG, &bq->init_data.iprechg}, 710 + {F_SYSVMIN, &bq->init_data.sysvmin}, 711 + {F_BOOSTV, &bq->init_data.boostv}, 712 + {F_BOOSTI, &bq->init_data.boosti}, 713 + {F_BOOSTF, &bq->init_data.boostf}, 714 + {F_EN_ILIM, &bq->init_data.ilim_en}, 715 + {F_TREG, &bq->init_data.treg}, 716 + {F_BATCMP, &bq->init_data.rbatcomp}, 717 + {F_VCLAMP, &bq->init_data.vclamp}, 717 718 }; 719 + 720 + for (i = 0; i < ARRAY_SIZE(init_data); i++) { 721 + if (write) { 722 + ret = bq25890_field_write(bq, init_data[i].id, 723 + *init_data[i].value); 724 + } else { 725 + ret = bq25890_field_read(bq, init_data[i].id); 726 + if (ret >= 0) 727 + *init_data[i].value = ret; 728 + } 729 + if (ret < 0) { 730 + dev_dbg(bq->dev, "Accessing init data failed %d\n", ret); 731 + return ret; 732 + } 733 + } 734 + 735 + return 0; 736 + } 737 + 738 + static int bq25890_hw_init(struct bq25890_device *bq) 739 + { 740 + int ret; 718 741 719 742 ret = bq25890_chip_reset(bq); 720 743 if (ret < 0) { ··· 753 730 } 754 731 755 732 /* initialize currents/voltages and other parameters */ 756 - for (i = 0; i < ARRAY_SIZE(init_data); i++) { 757 - ret = bq25890_field_write(bq, init_data[i].id, 758 - init_data[i].value); 759 - if (ret < 0) { 760 - dev_dbg(bq->dev, "Writing init data failed %d\n", ret); 761 - return ret; 762 - } 763 - } 733 + ret = bq25890_rw_init_data(bq); 734 + if (ret) 735 + return ret; 764 736 765 737 ret = bq25890_get_chip_state(bq, &bq->state); 766 738 if (ret < 0) {