Skip to content

Commit 6adaa9a

Browse files
jwrdegoedesre
authored andcommitted
power: supply: bq25890: Add new linux,iinlim-percentage property
Some devices, such as the Lenovo Yoga Tab 3 Pro (YT3-X90F) have multiple batteries with a separate bq25890 charger for each battery. This requires the maximum current the external power-supply can deliver to be divided over the chargers. The Android vendor kernel shipped on the YT3-X90F divides this current with a 40/60 percent split so that batteries are done charging at approx. the same time if both were fully empty at the start. Add support for a new "linux,iinlim-percentage" percentage property which can be set to indicate that a bq25890 charger should only use that percentage of the external power-supply's maximum current. So far this new property is only used on x86/ACPI (non devicetree) devs, IOW it is not used in actual devicetree files. The devicetree-bindings maintainers have requested properties like these to not be added to the devicetree-bindings, so the new property is deliberately not added to the existing devicetree-bindings. Signed-off-by: Hans de Goede <[email protected]> Reviewed-by: Marek Vasut <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
1 parent d54bf87 commit 6adaa9a

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

drivers/power/supply/bq25890_charger.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct bq25890_device {
126126
bool read_back_init_data;
127127
bool force_hiz;
128128
u32 pump_express_vbus_max;
129+
u32 iinlim_percentage;
129130
enum bq25890_chip_version chip_version;
130131
struct bq25890_init_data init_data;
131132
struct bq25890_state state;
@@ -727,6 +728,18 @@ static int bq25890_power_supply_property_is_writeable(struct power_supply *psy,
727728
}
728729
}
729730

731+
/*
732+
* If there are multiple chargers the maximum current the external power-supply
733+
* can deliver needs to be divided over the chargers. This is done according
734+
* to the bq->iinlim_percentage setting.
735+
*/
736+
static int bq25890_charger_get_scaled_iinlim_regval(struct bq25890_device *bq,
737+
int iinlim_ua)
738+
{
739+
iinlim_ua = iinlim_ua * bq->iinlim_percentage / 100;
740+
return bq25890_find_idx(iinlim_ua, TBL_IINLIM);
741+
}
742+
730743
/* On the BQ25892 try to get charger-type info from our supplier */
731744
static void bq25890_charger_external_power_changed(struct power_supply *psy)
732745
{
@@ -745,7 +758,7 @@ static void bq25890_charger_external_power_changed(struct power_supply *psy)
745758

746759
switch (val.intval) {
747760
case POWER_SUPPLY_USB_TYPE_DCP:
748-
input_current_limit = bq25890_find_idx(2000000, TBL_IINLIM);
761+
input_current_limit = bq25890_charger_get_scaled_iinlim_regval(bq, 2000000);
749762
if (bq->pump_express_vbus_max) {
750763
queue_delayed_work(system_power_efficient_wq,
751764
&bq->pump_express_work,
@@ -754,11 +767,11 @@ static void bq25890_charger_external_power_changed(struct power_supply *psy)
754767
break;
755768
case POWER_SUPPLY_USB_TYPE_CDP:
756769
case POWER_SUPPLY_USB_TYPE_ACA:
757-
input_current_limit = bq25890_find_idx(1500000, TBL_IINLIM);
770+
input_current_limit = bq25890_charger_get_scaled_iinlim_regval(bq, 1500000);
758771
break;
759772
case POWER_SUPPLY_USB_TYPE_SDP:
760773
default:
761-
input_current_limit = bq25890_find_idx(500000, TBL_IINLIM);
774+
input_current_limit = bq25890_charger_get_scaled_iinlim_regval(bq, 500000);
762775
}
763776

764777
bq25890_field_write(bq, F_IINLIM, input_current_limit);
@@ -1378,6 +1391,7 @@ static int bq25890_fw_probe(struct bq25890_device *bq)
13781391
int ret;
13791392
struct bq25890_init_data *init = &bq->init_data;
13801393
const char *str;
1394+
u32 val;
13811395

13821396
ret = device_property_read_string(bq->dev, "linux,secondary-charger-name", &str);
13831397
if (ret == 0) {
@@ -1390,6 +1404,17 @@ static int bq25890_fw_probe(struct bq25890_device *bq)
13901404
device_property_read_u32(bq->dev, "linux,pump-express-vbus-max",
13911405
&bq->pump_express_vbus_max);
13921406

1407+
ret = device_property_read_u32(bq->dev, "linux,iinlim-percentage", &val);
1408+
if (ret == 0) {
1409+
if (val > 100) {
1410+
dev_err(bq->dev, "Error linux,iinlim-percentage %u > 100\n", val);
1411+
return -EINVAL;
1412+
}
1413+
bq->iinlim_percentage = val;
1414+
} else {
1415+
bq->iinlim_percentage = 100;
1416+
}
1417+
13931418
bq->skip_reset = device_property_read_bool(bq->dev, "linux,skip-reset");
13941419
bq->read_back_init_data = device_property_read_bool(bq->dev,
13951420
"linux,read-back-settings");

0 commit comments

Comments
 (0)