Lines Matching +full:boost +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2011-2013 Pali Rohár <pali@kernel.org>
166 enum bq2415x_mode reported_mode;/* mode reported by hook function */
167 enum bq2415x_mode mode; /* currently configured mode */ member
172 int autotimer; /* 1 - if driver automatically reset timer, 0 - not */
173 int automode; /* 1 - enabled, 0 - disabled; -1 - not supported */
189 struct i2c_client *client = to_i2c_client(bq->dev); in bq2415x_i2c_read()
194 if (!client->adapter) in bq2415x_i2c_read()
195 return -ENODEV; in bq2415x_i2c_read()
197 msg[0].addr = client->addr; in bq2415x_i2c_read()
201 msg[1].addr = client->addr; in bq2415x_i2c_read()
207 ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); in bq2415x_i2c_read()
223 return -EINVAL; in bq2415x_i2c_read_mask()
235 return -EINVAL; in bq2415x_i2c_read_bit()
244 struct i2c_client *client = to_i2c_client(bq->dev); in bq2415x_i2c_write()
252 msg[0].addr = client->addr; in bq2415x_i2c_write()
258 ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); in bq2415x_i2c_write()
265 return -EIO; in bq2415x_i2c_write()
277 return -EINVAL; in bq2415x_i2c_write_mask()
294 return -EINVAL; in bq2415x_i2c_write_bit()
401 return -EINVAL; in bq2415x_exec_command()
407 struct i2c_client *client = to_i2c_client(bq->dev); in bq2415x_detect_chip()
413 switch (client->addr) { in bq2415x_detect_chip()
417 if (bq->chip == BQ24151A) in bq2415x_detect_chip()
418 return bq->chip; in bq2415x_detect_chip()
421 if (bq->chip == BQ24150A || in bq2415x_detect_chip()
422 bq->chip == BQ24152 || in bq2415x_detect_chip()
423 bq->chip == BQ24155) in bq2415x_detect_chip()
424 return bq->chip; in bq2415x_detect_chip()
427 if (bq->chip == BQ24153A) in bq2415x_detect_chip()
428 return bq->chip; in bq2415x_detect_chip()
438 if (bq->chip == BQ24156A) in bq2415x_detect_chip()
439 return bq->chip; in bq2415x_detect_chip()
442 if (bq->chip == BQ24157S) in bq2415x_detect_chip()
443 return bq->chip; in bq2415x_detect_chip()
461 return -1; in bq2415x_detect_revision()
471 return -1; in bq2415x_detect_revision()
482 return -1; in bq2415x_detect_revision()
486 return -1; in bq2415x_detect_revision()
488 return -1; in bq2415x_detect_revision()
491 return -1; in bq2415x_detect_revision()
516 bq->timer_error = NULL; in bq2415x_reset_chip()
556 return -EINVAL; in bq2415x_get_current_limit()
594 int val = (mV/10 - 350) / 2; in bq2415x_set_battery_regulation_voltage()
603 return -EINVAL; in bq2415x_set_battery_regulation_voltage()
625 if (bq->init_data.resistor_sense <= 0) in bq2415x_set_charge_current()
626 return -EINVAL; in bq2415x_set_charge_current()
628 val = (mA * bq->init_data.resistor_sense - 37400) / 6800; in bq2415x_set_charge_current()
644 if (bq->init_data.resistor_sense <= 0) in bq2415x_get_charge_current()
645 return -EINVAL; in bq2415x_get_charge_current()
651 return (37400 + 6800*ret) / bq->init_data.resistor_sense; in bq2415x_get_charge_current()
659 if (bq->init_data.resistor_sense <= 0) in bq2415x_set_termination_current()
660 return -EINVAL; in bq2415x_set_termination_current()
662 val = (mA * bq->init_data.resistor_sense - 3400) / 3400; in bq2415x_set_termination_current()
678 if (bq->init_data.resistor_sense <= 0) in bq2415x_get_termination_current()
679 return -EINVAL; in bq2415x_get_termination_current()
685 return (3400 + 3400*ret) / bq->init_data.resistor_sense; in bq2415x_get_termination_current()
692 if (bq->init_data.prop != -1) \
693 ret = bq2415x_set_##prop(bq, bq->init_data.prop); \
709 if (bq->init_data.resistor_sense > 0) { in bq2415x_set_defaults()
719 /**** charger mode functions ****/
721 /* set charger mode */
722 static int bq2415x_set_mode(struct bq2415x_device *bq, enum bq2415x_mode mode) in bq2415x_set_mode() argument
726 int boost = 0; in bq2415x_set_mode() local
728 if (mode == BQ2415X_MODE_BOOST) in bq2415x_set_mode()
729 boost = 1; in bq2415x_set_mode()
730 else if (mode != BQ2415X_MODE_OFF) in bq2415x_set_mode()
736 if (!boost) in bq2415x_set_mode()
742 switch (mode) { in bq2415x_set_mode()
744 dev_dbg(bq->dev, "changing mode to: Offline\n"); in bq2415x_set_mode()
748 dev_dbg(bq->dev, "changing mode to: N/A\n"); in bq2415x_set_mode()
752 dev_dbg(bq->dev, "changing mode to: Host/HUB charger\n"); in bq2415x_set_mode()
756 dev_dbg(bq->dev, "changing mode to: Dedicated charger\n"); in bq2415x_set_mode()
759 case BQ2415X_MODE_BOOST: /* Boost mode */ in bq2415x_set_mode()
760 dev_dbg(bq->dev, "changing mode to: Boost\n"); in bq2415x_set_mode()
770 else if (boost) in bq2415x_set_mode()
779 bq->mode = mode; in bq2415x_set_mode()
780 sysfs_notify(&bq->charger->dev.kobj, NULL, "mode"); in bq2415x_set_mode()
788 enum bq2415x_mode mode; in bq2415x_update_reported_mode() local
791 mode = BQ2415X_MODE_OFF; in bq2415x_update_reported_mode()
793 mode = BQ2415X_MODE_NONE; in bq2415x_update_reported_mode()
795 mode = BQ2415X_MODE_HOST_CHARGER; in bq2415x_update_reported_mode()
797 mode = BQ2415X_MODE_DEDICATED_CHARGER; in bq2415x_update_reported_mode()
799 if (bq->reported_mode == mode) in bq2415x_update_reported_mode()
802 bq->reported_mode = mode; in bq2415x_update_reported_mode()
819 if (bq->notify_node) { in bq2415x_notifier_call()
820 if (!psy->dev.parent || in bq2415x_notifier_call()
821 psy->dev.parent->of_node != bq->notify_node) in bq2415x_notifier_call()
823 } else if (bq->init_data.notify_device) { in bq2415x_notifier_call()
824 if (strcmp(psy->desc->name, bq->init_data.notify_device) != 0) in bq2415x_notifier_call()
828 dev_dbg(bq->dev, "notifier call was called\n"); in bq2415x_notifier_call()
839 if (bq->automode < 1) in bq2415x_notifier_call()
842 schedule_delayed_work(&bq->work, 0); in bq2415x_notifier_call()
854 if (bq->autotimer == state) { in bq2415x_set_autotimer()
859 bq->autotimer = state; in bq2415x_set_autotimer()
862 schedule_delayed_work(&bq->work, BQ2415X_TIMER_TIMEOUT * HZ); in bq2415x_set_autotimer()
864 bq->timer_error = NULL; in bq2415x_set_autotimer()
866 cancel_delayed_work_sync(&bq->work); in bq2415x_set_autotimer()
875 bq->timer_error = msg; in bq2415x_timer_error()
876 sysfs_notify(&bq->charger->dev.kobj, NULL, "timer"); in bq2415x_timer_error()
877 dev_err(bq->dev, "%s\n", msg); in bq2415x_timer_error()
878 if (bq->automode > 0) in bq2415x_timer_error()
879 bq->automode = 0; in bq2415x_timer_error()
891 int boost; in bq2415x_timer_work() local
893 if (bq->automode > 0 && (bq->reported_mode != bq->mode)) { in bq2415x_timer_work()
894 sysfs_notify(&bq->charger->dev.kobj, NULL, "reported_mode"); in bq2415x_timer_work()
895 bq2415x_set_mode(bq, bq->reported_mode); in bq2415x_timer_work()
898 if (!bq->autotimer) in bq2415x_timer_work()
907 boost = bq2415x_exec_command(bq, BQ2415X_BOOST_MODE_STATUS); in bq2415x_timer_work()
908 if (boost < 0) { in bq2415x_timer_work()
919 if (boost) { in bq2415x_timer_work()
925 dev_err(bq->dev, "Timer expired\n"); in bq2415x_timer_work()
928 dev_err(bq->dev, "Battery voltage to low\n"); in bq2415x_timer_work()
956 case 2: /* Sleep mode */ in bq2415x_timer_work()
957 dev_err(bq->dev, "Sleep mode\n"); in bq2415x_timer_work()
960 dev_err(bq->dev, "Poor input source\n"); in bq2415x_timer_work()
963 dev_err(bq->dev, "Timer expired\n"); in bq2415x_timer_work()
966 dev_err(bq->dev, "No battery\n"); in bq2415x_timer_work()
985 schedule_delayed_work(&bq->work, BQ2415X_TIMER_TIMEOUT * HZ); in bq2415x_timer_work()
1010 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in bq2415x_power_supply_get_property()
1012 val->intval = POWER_SUPPLY_STATUS_CHARGING; in bq2415x_power_supply_get_property()
1014 val->intval = POWER_SUPPLY_STATUS_FULL; in bq2415x_power_supply_get_property()
1016 val->intval = POWER_SUPPLY_STATUS_UNKNOWN; in bq2415x_power_supply_get_property()
1019 val->strval = bq->model; in bq2415x_power_supply_get_property()
1028 val->intval = ret > 0; in bq2415x_power_supply_get_property()
1031 return -EINVAL; in bq2415x_power_supply_get_property()
1038 bq->autotimer = 0; in bq2415x_power_supply_exit()
1039 if (bq->automode > 0) in bq2415x_power_supply_exit()
1040 bq->automode = 0; in bq2415x_power_supply_exit()
1041 cancel_delayed_work_sync(&bq->work); in bq2415x_power_supply_exit()
1042 power_supply_unregister(bq->charger); in bq2415x_power_supply_exit()
1043 kfree(bq->model); in bq2415x_power_supply_exit()
1058 if (strcmp(attr->attr.name, "otg_status") == 0) in bq2415x_sysfs_show_status()
1060 else if (strcmp(attr->attr.name, "charge_status") == 0) in bq2415x_sysfs_show_status()
1062 else if (strcmp(attr->attr.name, "boost_status") == 0) in bq2415x_sysfs_show_status()
1064 else if (strcmp(attr->attr.name, "fault_status") == 0) in bq2415x_sysfs_show_status()
1067 return -EINVAL; in bq2415x_sysfs_show_status()
1077 * auto - enable auto mode
1078 * off - disable auto mode
1079 * (other values) - reset chip timer
1110 if (bq->timer_error) in bq2415x_sysfs_show_timer()
1111 return sysfs_emit(buf, "%s\n", bq->timer_error); in bq2415x_sysfs_show_timer()
1113 if (bq->autotimer) in bq2415x_sysfs_show_timer()
1119 * set mode entry:
1120 * auto - if automode is supported, enable it and set mode to reported
1121 * none - disable charger and boost mode
1122 * host - charging mode for host/hub chargers (current limit 500mA)
1123 * dedicated - charging mode for dedicated chargers (unlimited current limit)
1124 * boost - disable charger and enable boost mode
1133 enum bq2415x_mode mode; in bq2415x_sysfs_set_mode() local
1137 if (bq->automode < 0) in bq2415x_sysfs_set_mode()
1138 return -EINVAL; in bq2415x_sysfs_set_mode()
1139 bq->automode = 1; in bq2415x_sysfs_set_mode()
1140 mode = bq->reported_mode; in bq2415x_sysfs_set_mode()
1142 if (bq->automode > 0) in bq2415x_sysfs_set_mode()
1143 bq->automode = 0; in bq2415x_sysfs_set_mode()
1144 mode = BQ2415X_MODE_OFF; in bq2415x_sysfs_set_mode()
1146 if (bq->automode > 0) in bq2415x_sysfs_set_mode()
1147 bq->automode = 0; in bq2415x_sysfs_set_mode()
1148 mode = BQ2415X_MODE_NONE; in bq2415x_sysfs_set_mode()
1150 if (bq->automode > 0) in bq2415x_sysfs_set_mode()
1151 bq->automode = 0; in bq2415x_sysfs_set_mode()
1152 mode = BQ2415X_MODE_HOST_CHARGER; in bq2415x_sysfs_set_mode()
1154 if (bq->automode > 0) in bq2415x_sysfs_set_mode()
1155 bq->automode = 0; in bq2415x_sysfs_set_mode()
1156 mode = BQ2415X_MODE_DEDICATED_CHARGER; in bq2415x_sysfs_set_mode()
1157 } else if (strncmp(buf, "boost", 5) == 0) { in bq2415x_sysfs_set_mode()
1158 if (bq->automode > 0) in bq2415x_sysfs_set_mode()
1159 bq->automode = 0; in bq2415x_sysfs_set_mode()
1160 mode = BQ2415X_MODE_BOOST; in bq2415x_sysfs_set_mode()
1164 if (bq->automode <= 0) in bq2415x_sysfs_set_mode()
1166 bq->automode = 1; in bq2415x_sysfs_set_mode()
1167 mode = bq->reported_mode; in bq2415x_sysfs_set_mode()
1169 return -EINVAL; in bq2415x_sysfs_set_mode()
1172 ret = bq2415x_set_mode(bq, mode); in bq2415x_sysfs_set_mode()
1178 /* show mode entry (auto, none, host, dedicated or boost) */
1187 if (bq->automode > 0) in bq2415x_sysfs_show_mode()
1190 switch (bq->mode) { in bq2415x_sysfs_show_mode()
1204 ret += sysfs_emit_at(buf, ret, "boost"); in bq2415x_sysfs_show_mode()
1208 if (bq->automode > 0) in bq2415x_sysfs_show_mode()
1215 /* show reported_mode entry (none, host, dedicated or boost) */
1223 if (bq->automode < 0) in bq2415x_sysfs_show_reported_mode()
1224 return -EINVAL; in bq2415x_sysfs_show_reported_mode()
1226 switch (bq->reported_mode) { in bq2415x_sysfs_show_reported_mode()
1236 return sysfs_emit(buf, "boost\n"); in bq2415x_sysfs_show_reported_mode()
1239 return -EINVAL; in bq2415x_sysfs_show_reported_mode()
1255 return -EINVAL; in bq2415x_sysfs_set_registers()
1258 return -EINVAL; in bq2415x_sysfs_set_registers()
1307 return -EINVAL; in bq2415x_sysfs_set_limit()
1309 if (strcmp(attr->attr.name, "current_limit") == 0) in bq2415x_sysfs_set_limit()
1311 else if (strcmp(attr->attr.name, "weak_battery_voltage") == 0) in bq2415x_sysfs_set_limit()
1313 else if (strcmp(attr->attr.name, "battery_regulation_voltage") == 0) in bq2415x_sysfs_set_limit()
1315 else if (strcmp(attr->attr.name, "charge_current") == 0) in bq2415x_sysfs_set_limit()
1317 else if (strcmp(attr->attr.name, "termination_current") == 0) in bq2415x_sysfs_set_limit()
1320 return -EINVAL; in bq2415x_sysfs_set_limit()
1336 if (strcmp(attr->attr.name, "current_limit") == 0) in bq2415x_sysfs_show_limit()
1338 else if (strcmp(attr->attr.name, "weak_battery_voltage") == 0) in bq2415x_sysfs_show_limit()
1340 else if (strcmp(attr->attr.name, "battery_regulation_voltage") == 0) in bq2415x_sysfs_show_limit()
1342 else if (strcmp(attr->attr.name, "charge_current") == 0) in bq2415x_sysfs_show_limit()
1344 else if (strcmp(attr->attr.name, "termination_current") == 0) in bq2415x_sysfs_show_limit()
1347 return -EINVAL; in bq2415x_sysfs_show_limit()
1367 return -EINVAL; in bq2415x_sysfs_set_enable()
1369 if (strcmp(attr->attr.name, "charge_termination_enable") == 0) in bq2415x_sysfs_set_enable()
1372 else if (strcmp(attr->attr.name, "high_impedance_enable") == 0) in bq2415x_sysfs_set_enable()
1375 else if (strcmp(attr->attr.name, "otg_pin_enable") == 0) in bq2415x_sysfs_set_enable()
1378 else if (strcmp(attr->attr.name, "stat_pin_enable") == 0) in bq2415x_sysfs_set_enable()
1382 return -EINVAL; in bq2415x_sysfs_set_enable()
1400 if (strcmp(attr->attr.name, "charge_termination_enable") == 0) in bq2415x_sysfs_show_enable()
1402 else if (strcmp(attr->attr.name, "high_impedance_enable") == 0) in bq2415x_sysfs_show_enable()
1404 else if (strcmp(attr->attr.name, "otg_pin_enable") == 0) in bq2415x_sysfs_show_enable()
1406 else if (strcmp(attr->attr.name, "stat_pin_enable") == 0) in bq2415x_sysfs_show_enable()
1409 return -EINVAL; in bq2415x_sysfs_show_enable()
1439 static DEVICE_ATTR(mode, S_IWUSR | S_IRUGO,
1490 .of_node = bq->dev->of_node, in bq2415x_power_supply_init()
1494 bq->charger_desc.name = bq->name; in bq2415x_power_supply_init()
1495 bq->charger_desc.type = POWER_SUPPLY_TYPE_USB; in bq2415x_power_supply_init()
1496 bq->charger_desc.properties = bq2415x_power_supply_props; in bq2415x_power_supply_init()
1497 bq->charger_desc.num_properties = in bq2415x_power_supply_init()
1499 bq->charger_desc.get_property = bq2415x_power_supply_get_property; in bq2415x_power_supply_init()
1513 bq->model = kasprintf(GFP_KERNEL, in bq2415x_power_supply_init()
1517 if (!bq->model) { in bq2415x_power_supply_init()
1518 dev_err(bq->dev, "failed to allocate model name\n"); in bq2415x_power_supply_init()
1519 return -ENOMEM; in bq2415x_power_supply_init()
1522 bq->charger = power_supply_register(bq->dev, &bq->charger_desc, in bq2415x_power_supply_init()
1524 if (IS_ERR(bq->charger)) { in bq2415x_power_supply_init()
1525 kfree(bq->model); in bq2415x_power_supply_init()
1526 return PTR_ERR(bq->charger); in bq2415x_power_supply_init()
1540 struct device_node *np = client->dev.of_node; in bq2415x_probe()
1541 struct bq2415x_platform_data *pdata = client->dev.platform_data; in bq2415x_probe()
1546 if (!np && !pdata && !ACPI_HANDLE(&client->dev)) { in bq2415x_probe()
1547 dev_err(&client->dev, "Neither devicetree, nor platform data, nor ACPI support\n"); in bq2415x_probe()
1548 return -ENODEV; in bq2415x_probe()
1559 name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num); in bq2415x_probe()
1560 } else if (ACPI_HANDLE(&client->dev)) { in bq2415x_probe()
1562 acpi_match_device(client->dev.driver->acpi_match_table, in bq2415x_probe()
1563 &client->dev); in bq2415x_probe()
1565 dev_err(&client->dev, "failed to match device name\n"); in bq2415x_probe()
1566 ret = -ENODEV; in bq2415x_probe()
1569 name = kasprintf(GFP_KERNEL, "%s-%d", acpi_id->id, num); in bq2415x_probe()
1572 dev_err(&client->dev, "failed to allocate device name\n"); in bq2415x_probe()
1573 ret = -ENOMEM; in bq2415x_probe()
1577 bq = devm_kzalloc(&client->dev, sizeof(*bq), GFP_KERNEL); in bq2415x_probe()
1579 ret = -ENOMEM; in bq2415x_probe()
1585 bq->id = num; in bq2415x_probe()
1586 bq->dev = &client->dev; in bq2415x_probe()
1588 bq->chip = id->driver_data; in bq2415x_probe()
1589 else if (ACPI_HANDLE(bq->dev)) in bq2415x_probe()
1590 bq->chip = acpi_id->driver_data; in bq2415x_probe()
1591 bq->name = name; in bq2415x_probe()
1592 bq->mode = BQ2415X_MODE_OFF; in bq2415x_probe()
1593 bq->reported_mode = BQ2415X_MODE_OFF; in bq2415x_probe()
1594 bq->autotimer = 0; in bq2415x_probe()
1595 bq->automode = 0; in bq2415x_probe()
1597 if (np || ACPI_HANDLE(bq->dev)) { in bq2415x_probe()
1598 ret = device_property_read_u32(bq->dev, in bq2415x_probe()
1599 "ti,current-limit", in bq2415x_probe()
1600 &bq->init_data.current_limit); in bq2415x_probe()
1603 ret = device_property_read_u32(bq->dev, in bq2415x_probe()
1604 "ti,weak-battery-voltage", in bq2415x_probe()
1605 &bq->init_data.weak_battery_voltage); in bq2415x_probe()
1608 ret = device_property_read_u32(bq->dev, in bq2415x_probe()
1609 "ti,battery-regulation-voltage", in bq2415x_probe()
1610 &bq->init_data.battery_regulation_voltage); in bq2415x_probe()
1613 ret = device_property_read_u32(bq->dev, in bq2415x_probe()
1614 "ti,charge-current", in bq2415x_probe()
1615 &bq->init_data.charge_current); in bq2415x_probe()
1618 ret = device_property_read_u32(bq->dev, in bq2415x_probe()
1619 "ti,termination-current", in bq2415x_probe()
1620 &bq->init_data.termination_current); in bq2415x_probe()
1623 ret = device_property_read_u32(bq->dev, in bq2415x_probe()
1624 "ti,resistor-sense", in bq2415x_probe()
1625 &bq->init_data.resistor_sense); in bq2415x_probe()
1629 bq->notify_node = of_parse_phandle(np, in bq2415x_probe()
1630 "ti,usb-charger-detection", 0); in bq2415x_probe()
1632 memcpy(&bq->init_data, pdata, sizeof(bq->init_data)); in bq2415x_probe()
1639 dev_err(bq->dev, "failed to register power supply: %d\n", ret); in bq2415x_probe()
1645 dev_err(bq->dev, "failed to set default values: %d\n", ret); in bq2415x_probe()
1649 if (bq->notify_node || bq->init_data.notify_device) { in bq2415x_probe()
1650 bq->nb.notifier_call = bq2415x_notifier_call; in bq2415x_probe()
1651 ret = power_supply_reg_notifier(&bq->nb); in bq2415x_probe()
1653 dev_err(bq->dev, "failed to reg notifier: %d\n", ret); in bq2415x_probe()
1657 bq->automode = 1; in bq2415x_probe()
1658 dev_info(bq->dev, "automode supported, waiting for events\n"); in bq2415x_probe()
1660 bq->automode = -1; in bq2415x_probe()
1661 dev_info(bq->dev, "automode not supported\n"); in bq2415x_probe()
1665 if (bq->nb.notifier_call) { in bq2415x_probe()
1668 "ti,usb-charger-detection"); in bq2415x_probe()
1671 } else if (bq->init_data.notify_device) { in bq2415x_probe()
1673 bq->init_data.notify_device); in bq2415x_probe()
1683 bq2415x_set_mode(bq, bq->reported_mode); in bq2415x_probe()
1687 INIT_DELAYED_WORK(&bq->work, bq2415x_timer_work); in bq2415x_probe()
1690 dev_info(bq->dev, "driver registered\n"); in bq2415x_probe()
1697 of_node_put(bq->notify_node); in bq2415x_probe()
1713 if (bq->nb.notifier_call) in bq2415x_remove()
1714 power_supply_unreg_notifier(&bq->nb); in bq2415x_remove()
1716 of_node_put(bq->notify_node); in bq2415x_remove()
1722 idr_remove(&bq2415x_id, bq->id); in bq2415x_remove()
1725 dev_info(bq->dev, "driver unregistered\n"); in bq2415x_remove()
1727 kfree(bq->name); in bq2415x_remove()
1789 .name = "bq2415x-charger",