Lines Matching +full:li +full:- +full:polymer

1 // SPDX-License-Identifier: GPL-2.0-only
19 #include <linux/extcon-provider.h>
32 #define BQ24190_REG_POC 0x01 /* Power-On Configuration */
57 #define BQ24190_REG_PCTCC 0x03 /* Pre-charge/Termination Current Cntl */
190 * The tables below provide a 2-way mapping for the value that goes in
191 * the register field and the real-world value that it represents.
193 * number at that index in the array is the real-world value that it
233 * 'val'. The index range returned is 0 to 'tbl_size' - 1. Assumes that
245 return i - 1; in bq24190_find_idx()
254 ret = i2c_smbus_read_byte_data(bdi->client, reg); in bq24190_read()
264 return i2c_smbus_write_byte_data(bdi->client, reg, data); in bq24190_write()
312 v = (v >= tbl_size) ? (tbl_size - 1) : v; in bq24190_get_field_val()
366 /* On i386 ptrace-abi.h defines SS that breaks the macro calls below. */
454 info = bq24190_sysfs_field_lookup(attr->attr.name); in bq24190_sysfs_show()
456 return -EINVAL; in bq24190_sysfs_show()
458 ret = pm_runtime_resume_and_get(bdi->dev); in bq24190_sysfs_show()
462 ret = bq24190_read_mask(bdi, info->reg, info->mask, info->shift, &v); in bq24190_sysfs_show()
468 pm_runtime_mark_last_busy(bdi->dev); in bq24190_sysfs_show()
469 pm_runtime_put_autosuspend(bdi->dev); in bq24190_sysfs_show()
483 info = bq24190_sysfs_field_lookup(attr->attr.name); in bq24190_sysfs_store()
485 return -EINVAL; in bq24190_sysfs_store()
491 ret = pm_runtime_resume_and_get(bdi->dev); in bq24190_sysfs_store()
495 ret = bq24190_write_mask(bdi, info->reg, info->mask, info->shift, v); in bq24190_sysfs_store()
499 pm_runtime_mark_last_busy(bdi->dev); in bq24190_sysfs_store()
500 pm_runtime_put_autosuspend(bdi->dev); in bq24190_sysfs_store()
508 union power_supply_propval val = { .intval = bdi->charge_type }; in bq24190_set_otg_vbus()
511 ret = pm_runtime_resume_and_get(bdi->dev); in bq24190_set_otg_vbus()
513 dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret); in bq24190_set_otg_vbus()
517 bdi->otg_vbus_enabled = enable; in bq24190_set_otg_vbus()
526 pm_runtime_mark_last_busy(bdi->dev); in bq24190_set_otg_vbus()
527 pm_runtime_put_autosuspend(bdi->dev); in bq24190_set_otg_vbus()
549 ret = pm_runtime_resume_and_get(bdi->dev); in bq24190_vbus_is_enabled()
551 dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret); in bq24190_vbus_is_enabled()
559 pm_runtime_mark_last_busy(bdi->dev); in bq24190_vbus_is_enabled()
560 pm_runtime_put_autosuspend(bdi->dev); in bq24190_vbus_is_enabled()
565 bdi->otg_vbus_enabled = (val == BQ24190_REG_POC_CHG_CONFIG_OTG || in bq24190_vbus_is_enabled()
567 return bdi->otg_vbus_enabled; in bq24190_vbus_is_enabled()
578 .of_match = "usb-otg-vbus",
594 struct bq24190_platform_data *pdata = bdi->dev->platform_data; in bq24190_register_vbus_regulator()
599 cfg.dev = bdi->dev; in bq24190_register_vbus_regulator()
600 if (pdata && pdata->regulator_init_data) in bq24190_register_vbus_regulator()
601 cfg.init_data = pdata->regulator_init_data; in bq24190_register_vbus_regulator()
605 reg = devm_regulator_register(bdi->dev, &bq24190_vbus_desc, &cfg); in bq24190_register_vbus_regulator()
608 dev_err(bdi->dev, "Can't register regulator: %d\n", ret); in bq24190_register_vbus_regulator()
629 bdi->watchdog = ((v & BQ24190_REG_CTTC_WATCHDOG_MASK) >> in bq24190_set_config()
646 if (bdi->sys_min) { in bq24190_set_config()
647 v = bdi->sys_min / 100 - 30; // manual section 9.5.1.2, table 9 in bq24190_set_config()
656 if (bdi->iprechg) { in bq24190_set_config()
657 v = bdi->iprechg / 128 - 1; // manual section 9.5.1.4, table 11 in bq24190_set_config()
666 if (bdi->iterm) { in bq24190_set_config()
667 v = bdi->iterm / 128 - 1; // manual section 9.5.1.4, table 11 in bq24190_set_config()
676 if (bdi->ichg) { in bq24190_set_config()
682 bdi->ichg); in bq24190_set_config()
687 if (bdi->vreg) { in bq24190_set_config()
693 bdi->vreg); in bq24190_set_config()
709 * { PROPERTY_ENTRY_BOOL("disable-reset"), ... }; in bq24190_register_reset()
716 if (device_property_read_bool(bdi->dev, "disable-reset")) in bq24190_register_reset()
740 } while (--limit); in bq24190_register_reset()
742 return -EIO; in bq24190_register_reset()
775 val->intval = type; in bq24190_charger_get_charge_type()
796 switch (val->intval) { in bq24190_charger_set_charge_type()
811 return -EINVAL; in bq24190_charger_set_charge_type()
814 bdi->charge_type = val->intval; in bq24190_charger_set_charge_type()
817 * the charge-type until its gets disabled. in bq24190_charger_set_charge_type()
819 if (bdi->otg_vbus_enabled) in bq24190_charger_set_charge_type()
849 mutex_lock(&bdi->f_reg_lock); in bq24190_charger_get_health()
850 v = bdi->f_reg; in bq24190_charger_get_health()
851 mutex_unlock(&bdi->f_reg_lock); in bq24190_charger_get_health()
874 * This could be over-voltage or under-voltage in bq24190_charger_get_health()
877 * when its really under-voltage, just return in bq24190_charger_get_health()
889 health = -1; in bq24190_charger_get_health()
893 * This could be over-current or over-voltage but there's in bq24190_charger_get_health()
896 * even if it was over-current. in bq24190_charger_get_health()
903 val->intval = health; in bq24190_charger_get_health()
926 val->intval = pg_stat && !batfet_disable; in bq24190_charger_get_online()
988 val->intval = curr; in bq24190_charger_get_precharge()
1005 val->intval = ++v * 128 * 1000; in bq24190_charger_get_charge_term()
1032 val->intval = curr; in bq24190_charger_get_current()
1040 int ret, curr = val->intval; in bq24190_charger_set_current()
1052 if (curr > bdi->ichg_max) in bq24190_charger_set_current()
1053 return -EINVAL; in bq24190_charger_set_current()
1062 bdi->ichg = curr; in bq24190_charger_set_current()
1079 val->intval = voltage; in bq24190_charger_get_voltage()
1088 if (val->intval > bdi->vreg_max) in bq24190_charger_set_voltage()
1089 return -EINVAL; in bq24190_charger_set_voltage()
1094 ARRAY_SIZE(bq24190_cvc_vreg_values), val->intval); in bq24190_charger_set_voltage()
1098 bdi->vreg = val->intval; in bq24190_charger_set_voltage()
1116 val->intval = iinlimit; in bq24190_charger_get_iinlimit()
1127 ARRAY_SIZE(bq24190_isc_iinlim_values), val->intval); in bq24190_charger_set_iinlimit()
1136 dev_dbg(bdi->dev, "prop: %d\n", psp); in bq24190_charger_get_property()
1138 ret = pm_runtime_resume_and_get(bdi->dev); in bq24190_charger_get_property()
1168 val->intval = bdi->ichg_max; in bq24190_charger_get_property()
1175 val->intval = bdi->vreg_max; in bq24190_charger_get_property()
1182 val->intval = POWER_SUPPLY_SCOPE_SYSTEM; in bq24190_charger_get_property()
1186 val->strval = bdi->model_name; in bq24190_charger_get_property()
1190 val->strval = BQ24190_MANUFACTURER; in bq24190_charger_get_property()
1194 ret = -ENODATA; in bq24190_charger_get_property()
1197 pm_runtime_mark_last_busy(bdi->dev); in bq24190_charger_get_property()
1198 pm_runtime_put_autosuspend(bdi->dev); in bq24190_charger_get_property()
1210 dev_dbg(bdi->dev, "prop: %d\n", psp); in bq24190_charger_set_property()
1212 ret = pm_runtime_resume_and_get(bdi->dev); in bq24190_charger_set_property()
1236 ret = -EINVAL; in bq24190_charger_set_property()
1239 pm_runtime_mark_last_busy(bdi->dev); in bq24190_charger_set_property()
1240 pm_runtime_put_autosuspend(bdi->dev); in bq24190_charger_set_property()
1269 ret = power_supply_get_property_from_supplier(bdi->charger, in bq24190_input_current_limit_work()
1275 bq24190_charger_set_property(bdi->charger, in bq24190_input_current_limit_work()
1278 power_supply_changed(bdi->charger); in bq24190_input_current_limit_work()
1281 /* Sync the input-current-limit with our parent supply (if we have one) */
1287 * The Power-Good detection may take up to 220ms, sometimes in bq24190_charger_external_power_changed()
1291 * too low default 500mA iinlim. Delay setting the input-current-limit in bq24190_charger_external_power_changed()
1294 queue_delayed_work(system_wq, &bdi->input_current_limit_work, in bq24190_charger_external_power_changed()
1317 "main-battery",
1321 .name = "bq24190-charger",
1339 mutex_lock(&bdi->f_reg_lock); in bq24190_battery_get_status()
1340 chrg_fault = bdi->f_reg; in bq24190_battery_get_status()
1341 mutex_unlock(&bdi->f_reg_lock); in bq24190_battery_get_status()
1352 * - there is no good power source; in bq24190_battery_get_status()
1353 * - there is a charge fault. in bq24190_battery_get_status()
1367 case 0x1: /* Pre-charge */ in bq24190_battery_get_status()
1375 ret = -EIO; in bq24190_battery_get_status()
1380 val->intval = status; in bq24190_battery_get_status()
1391 mutex_lock(&bdi->f_reg_lock); in bq24190_battery_get_health()
1392 v = bdi->f_reg; in bq24190_battery_get_health()
1393 mutex_unlock(&bdi->f_reg_lock); in bq24190_battery_get_health()
1420 val->intval = health; in bq24190_battery_get_health()
1436 val->intval = !batfet_disable; in bq24190_battery_get_online()
1445 BQ24190_REG_MOC_BATFET_DISABLE_SHIFT, !val->intval); in bq24190_battery_set_online()
1461 val->intval = temp; in bq24190_battery_get_temp_alert_max()
1472 ARRAY_SIZE(bq24190_ictrc_treg_values), val->intval); in bq24190_battery_set_temp_alert_max()
1481 dev_warn(bdi->dev, "warning: /sys/class/power_supply/bq24190-battery is deprecated\n"); in bq24190_battery_get_property()
1482 dev_dbg(bdi->dev, "prop: %d\n", psp); in bq24190_battery_get_property()
1484 ret = pm_runtime_resume_and_get(bdi->dev); in bq24190_battery_get_property()
1499 /* Could be Li-on or Li-polymer but no way to tell which */ in bq24190_battery_get_property()
1500 val->intval = POWER_SUPPLY_TECHNOLOGY_UNKNOWN; in bq24190_battery_get_property()
1507 val->intval = POWER_SUPPLY_SCOPE_SYSTEM; in bq24190_battery_get_property()
1511 ret = -ENODATA; in bq24190_battery_get_property()
1514 pm_runtime_mark_last_busy(bdi->dev); in bq24190_battery_get_property()
1515 pm_runtime_put_autosuspend(bdi->dev); in bq24190_battery_get_property()
1527 dev_warn(bdi->dev, "warning: /sys/class/power_supply/bq24190-battery is deprecated\n"); in bq24190_battery_set_property()
1528 dev_dbg(bdi->dev, "prop: %d\n", psp); in bq24190_battery_set_property()
1530 ret = pm_runtime_resume_and_get(bdi->dev); in bq24190_battery_set_property()
1542 ret = -EINVAL; in bq24190_battery_set_property()
1545 pm_runtime_mark_last_busy(bdi->dev); in bq24190_battery_set_property()
1546 pm_runtime_put_autosuspend(bdi->dev); in bq24190_battery_set_property()
1578 .name = "bq24190-battery",
1593 ret = extcon_set_state_sync(bdi->edev, EXTCON_USB, otg_enabled); in bq24190_configure_usb_otg()
1595 dev_err(bdi->dev, "Can't set extcon state to %d: %d\n", in bq24190_configure_usb_otg()
1612 dev_err(bdi->dev, "Can't read SS reg: %d\n", ret); in bq24190_check_status()
1620 dev_err(bdi->dev, "Can't read F reg: %d\n", ret); in bq24190_check_status()
1630 if (f_reg != bdi->f_reg) { in bq24190_check_status()
1631 dev_warn(bdi->dev, in bq24190_check_status()
1638 mutex_lock(&bdi->f_reg_lock); in bq24190_check_status()
1639 if ((bdi->f_reg & battery_mask_f) != (f_reg & battery_mask_f)) in bq24190_check_status()
1641 if ((bdi->f_reg & ~battery_mask_f) != (f_reg & ~battery_mask_f)) in bq24190_check_status()
1643 bdi->f_reg = f_reg; in bq24190_check_status()
1644 mutex_unlock(&bdi->f_reg_lock); in bq24190_check_status()
1647 if (ss_reg != bdi->ss_reg) { in bq24190_check_status()
1649 * The device is in host mode so when PG_STAT goes from 1->0 in bq24190_check_status()
1652 if ((bdi->ss_reg & BQ24190_REG_SS_PG_STAT_MASK) && in bq24190_check_status()
1659 dev_err(bdi->dev, "Can't access ISC reg: %d\n", in bq24190_check_status()
1663 if ((bdi->ss_reg & battery_mask_ss) != (ss_reg & battery_mask_ss)) in bq24190_check_status()
1665 if ((bdi->ss_reg & ~battery_mask_ss) != (ss_reg & ~battery_mask_ss)) in bq24190_check_status()
1667 bdi->ss_reg = ss_reg; in bq24190_check_status()
1671 power_supply_changed(bdi->charger); in bq24190_check_status()
1674 if (alert_battery && bdi->battery) in bq24190_check_status()
1675 power_supply_changed(bdi->battery); in bq24190_check_status()
1677 dev_dbg(bdi->dev, "ss_reg: 0x%02x, f_reg: 0x%02x\n", ss_reg, f_reg); in bq24190_check_status()
1685 bdi->irq_event = true; in bq24190_irq_handler_thread()
1686 error = pm_runtime_resume_and_get(bdi->dev); in bq24190_irq_handler_thread()
1688 dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error); in bq24190_irq_handler_thread()
1692 pm_runtime_mark_last_busy(bdi->dev); in bq24190_irq_handler_thread()
1693 pm_runtime_put_autosuspend(bdi->dev); in bq24190_irq_handler_thread()
1694 bdi->irq_event = false; in bq24190_irq_handler_thread()
1718 dev_err(bdi->dev, "Error unknown model: 0x%02x\n", v); in bq24190_hw_init()
1719 return -ENODEV; in bq24190_hw_init()
1730 return bq24190_read(bdi, BQ24190_REG_SS, &bdi->ss_reg); in bq24190_hw_init()
1735 const char * const s = "ti,system-minimum-microvolt"; in bq24190_get_config()
1739 idx = ARRAY_SIZE(bq24190_ccc_ichg_values) - 1; in bq24190_get_config()
1740 bdi->ichg_max = bq24190_ccc_ichg_values[idx]; in bq24190_get_config()
1742 idx = ARRAY_SIZE(bq24190_cvc_vreg_values) - 1; in bq24190_get_config()
1743 bdi->vreg_max = bq24190_cvc_vreg_values[idx]; in bq24190_get_config()
1745 if (device_property_read_u32(bdi->dev, s, &v) == 0) { in bq24190_get_config()
1749 bdi->sys_min = v; in bq24190_get_config()
1751 dev_warn(bdi->dev, "invalid value for %s: %u\n", s, v); in bq24190_get_config()
1754 if (!power_supply_get_battery_info(bdi->charger, &info)) { in bq24190_get_config()
1755 v = info->precharge_current_ua / 1000; in bq24190_get_config()
1758 bdi->iprechg = v; in bq24190_get_config()
1760 dev_warn(bdi->dev, "invalid value for battery:precharge-current-microamp: %d\n", in bq24190_get_config()
1763 v = info->charge_term_current_ua / 1000; in bq24190_get_config()
1766 bdi->iterm = v; in bq24190_get_config()
1768 dev_warn(bdi->dev, "invalid value for battery:charge-term-current-microamp: %d\n", in bq24190_get_config()
1772 v = info->constant_charge_current_max_ua; in bq24190_get_config()
1773 if (v >= bq24190_ccc_ichg_values[0] && v <= bdi->ichg_max) in bq24190_get_config()
1774 bdi->ichg = bdi->ichg_max = v; in bq24190_get_config()
1776 v = info->constant_charge_voltage_max_uv; in bq24190_get_config()
1777 if (v >= bq24190_cvc_vreg_values[0] && v <= bdi->vreg_max) in bq24190_get_config()
1778 bdi->vreg = bdi->vreg_max = v; in bq24190_get_config()
1787 struct i2c_adapter *adapter = client->adapter; in bq24190_probe()
1788 struct device *dev = &client->dev; in bq24190_probe()
1795 return -ENODEV; in bq24190_probe()
1801 return -ENOMEM; in bq24190_probe()
1804 bdi->client = client; in bq24190_probe()
1805 bdi->dev = dev; in bq24190_probe()
1806 strncpy(bdi->model_name, id->name, I2C_NAME_SIZE); in bq24190_probe()
1807 mutex_init(&bdi->f_reg_lock); in bq24190_probe()
1808 bdi->charge_type = POWER_SUPPLY_CHARGE_TYPE_FAST; in bq24190_probe()
1809 bdi->f_reg = 0; in bq24190_probe()
1810 bdi->ss_reg = BQ24190_REG_SS_VBUS_STAT_MASK; /* impossible state */ in bq24190_probe()
1811 INIT_DELAYED_WORK(&bdi->input_current_limit_work, in bq24190_probe()
1816 if (client->irq <= 0) { in bq24190_probe()
1818 return -EINVAL; in bq24190_probe()
1821 bdi->edev = devm_extcon_dev_allocate(dev, bq24190_usb_extcon_cable); in bq24190_probe()
1822 if (IS_ERR(bdi->edev)) in bq24190_probe()
1823 return PTR_ERR(bdi->edev); in bq24190_probe()
1825 ret = devm_extcon_dev_register(dev, bdi->edev); in bq24190_probe()
1844 charger_cfg.of_node = dev->of_node; in bq24190_probe()
1847 bdi->charger = power_supply_register(dev, &bq24190_charger_desc, in bq24190_probe()
1849 if (IS_ERR(bdi->charger)) { in bq24190_probe()
1851 ret = PTR_ERR(bdi->charger); in bq24190_probe()
1857 if (!device_property_read_bool(dev, "omit-battery-class")) { in bq24190_probe()
1859 bdi->battery = power_supply_register(dev, &bq24190_battery_desc, in bq24190_probe()
1861 if (IS_ERR(bdi->battery)) { in bq24190_probe()
1863 ret = PTR_ERR(bdi->battery); in bq24190_probe()
1880 ret = bq24190_configure_usb_otg(bdi, bdi->ss_reg); in bq24190_probe()
1884 bdi->initialized = true; in bq24190_probe()
1886 ret = devm_request_threaded_irq(dev, client->irq, NULL, in bq24190_probe()
1889 "bq24190-charger", bdi); in bq24190_probe()
1899 enable_irq_wake(client->irq); in bq24190_probe()
1907 if (!IS_ERR_OR_NULL(bdi->battery)) in bq24190_probe()
1908 power_supply_unregister(bdi->battery); in bq24190_probe()
1909 power_supply_unregister(bdi->charger); in bq24190_probe()
1923 cancel_delayed_work_sync(&bdi->input_current_limit_work); in bq24190_remove()
1924 error = pm_runtime_resume_and_get(bdi->dev); in bq24190_remove()
1926 dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error); in bq24190_remove()
1929 if (bdi->battery) in bq24190_remove()
1930 power_supply_unregister(bdi->battery); in bq24190_remove()
1931 power_supply_unregister(bdi->charger); in bq24190_remove()
1933 pm_runtime_put_sync(bdi->dev); in bq24190_remove()
1934 pm_runtime_dont_use_autosuspend(bdi->dev); in bq24190_remove()
1935 pm_runtime_disable(bdi->dev); in bq24190_remove()
1951 if (!bdi->initialized) in bq24190_runtime_suspend()
1954 dev_dbg(bdi->dev, "%s\n", __func__); in bq24190_runtime_suspend()
1964 if (!bdi->initialized) in bq24190_runtime_resume()
1967 if (!bdi->irq_event) { in bq24190_runtime_resume()
1968 dev_dbg(bdi->dev, "checking events on possible wakeirq\n"); in bq24190_runtime_resume()
1981 error = pm_runtime_resume_and_get(bdi->dev); in bq24190_pm_suspend()
1983 dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error); in bq24190_pm_suspend()
1988 pm_runtime_mark_last_busy(bdi->dev); in bq24190_pm_suspend()
1989 pm_runtime_put_autosuspend(bdi->dev); in bq24190_pm_suspend()
2001 bdi->f_reg = 0; in bq24190_pm_resume()
2002 bdi->ss_reg = BQ24190_REG_SS_VBUS_STAT_MASK; /* impossible state */ in bq24190_pm_resume()
2004 error = pm_runtime_resume_and_get(bdi->dev); in bq24190_pm_resume()
2006 dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error); in bq24190_pm_resume()
2010 bq24190_read(bdi, BQ24190_REG_SS, &bdi->ss_reg); in bq24190_pm_resume()
2013 pm_runtime_mark_last_busy(bdi->dev); in bq24190_pm_resume()
2014 pm_runtime_put_autosuspend(bdi->dev); in bq24190_pm_resume()
2018 power_supply_changed(bdi->charger); in bq24190_pm_resume()
2019 if (bdi->battery) in bq24190_pm_resume()
2020 power_supply_changed(bdi->battery); in bq24190_pm_resume()
2055 .name = "bq24190-charger",