Lines Matching +full:usb +full:- +full:sdp
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2016-2019 The Linux Foundation. All rights reserved.
7 * This driver is for the switch-mode battery charger and boost
12 #include <linux/devm-helpers.h>
26 /* clang-format off */
352 /* clang-format on */
372 * struct smb2_chip - smb2 chip structure
379 * @cable_irq: USB plugin IRQ
419 rc = regmap_read(chip->regmap, chip->base + POWER_PATH_STATUS, &stat); in smb2_get_prop_usb_online()
421 dev_err(chip->dev, "Couldn't read power path status: %d\n", rc); in smb2_get_prop_usb_online()
446 rc = regmap_read(chip->regmap, chip->base + APSD_STATUS, &apsd_stat); in smb2_apsd_get_charger_type()
448 dev_err(chip->dev, "Failed to read apsd status, rc = %d", rc); in smb2_apsd_get_charger_type()
452 dev_dbg(chip->dev, "Apsd not ready"); in smb2_apsd_get_charger_type()
453 return -EAGAIN; in smb2_apsd_get_charger_type()
456 rc = regmap_read(chip->regmap, chip->base + APSD_RESULT_STATUS, &stat); in smb2_apsd_get_charger_type()
458 dev_err(chip->dev, "Failed to read apsd result, rc = %d", rc); in smb2_apsd_get_charger_type()
486 rc = regmap_bulk_read(chip->regmap, in smb2_get_prop_status()
487 chip->base + BATTERY_CHARGER_STATUS_1, &stat, 2); in smb2_get_prop_status()
489 dev_err(chip->dev, "Failed to read charging status ret=%d\n", in smb2_get_prop_status()
525 int rc = regmap_read(chip->regmap, chip->base + ICL_STATUS, val); in smb2_get_current_limit()
537 dev_err(chip->dev, in smb2_set_current_limit()
539 return -EINVAL; in smb2_set_current_limit()
543 return regmap_write(chip->regmap, chip->base + USBIN_CURRENT_LIMIT_CFG, in smb2_set_current_limit()
561 dev_dbg(chip->dev, "get charger type retry %d\n", count); in smb2_status_change_work()
563 if (rc != -EAGAIN) in smb2_status_change_work()
568 if (rc < 0 && rc != -EAGAIN) { in smb2_status_change_work()
569 dev_err(chip->dev, "get charger type failed: %d\n", rc); in smb2_status_change_work()
574 rc = regmap_update_bits(chip->regmap, chip->base + CMD_APSD, in smb2_status_change_work()
576 schedule_delayed_work(&chip->status_change_work, in smb2_status_change_work()
578 dev_dbg(chip->dev, "get charger type failed, rerun apsd\n"); in smb2_status_change_work()
596 power_supply_changed(chip->chg_psy); in smb2_status_change_work()
605 rc = power_supply_get_property(chip->chg_psy, POWER_SUPPLY_PROP_STATUS, in smb2_get_iio_chan()
613 dev_err(chip->dev, "Failed to chan, err = %li", PTR_ERR(chan)); in smb2_get_iio_chan()
625 rc = regmap_read(chip->regmap, chip->base + BATTERY_CHARGER_STATUS_2, in smb2_get_prop_health()
628 dev_err(chip->dev, "Couldn't read charger status rc=%d\n", rc); in smb2_get_prop_health()
662 val->strval = "Qualcomm"; in smb2_get_property()
665 val->strval = chip->name; in smb2_get_property()
668 return smb2_get_current_limit(chip, &val->intval); in smb2_get_property()
670 return smb2_get_iio_chan(chip, chip->usb_in_i_chan, in smb2_get_property()
671 &val->intval); in smb2_get_property()
673 return smb2_get_iio_chan(chip, chip->usb_in_v_chan, in smb2_get_property()
674 &val->intval); in smb2_get_property()
676 return smb2_get_prop_usb_online(chip, &val->intval); in smb2_get_property()
678 return smb2_get_prop_status(chip, &val->intval); in smb2_get_property()
680 return smb2_get_prop_health(chip, &val->intval); in smb2_get_property()
682 return smb2_apsd_get_charger_type(chip, &val->intval); in smb2_get_property()
684 dev_err(chip->dev, "invalid property: %d\n", psp); in smb2_get_property()
685 return -EINVAL; in smb2_get_property()
697 return smb2_set_current_limit(chip, val->intval); in smb2_set_property()
699 dev_err(chip->dev, "No setter for property: %d\n", psp); in smb2_set_property()
700 return -EINVAL; in smb2_set_property()
720 regmap_read(chip->regmap, chip->base + BATTERY_CHARGER_STATUS_2, in smb2_handle_batt_overvoltage()
725 dev_err(chip->dev, "battery overvoltage detected\n"); in smb2_handle_batt_overvoltage()
726 power_supply_changed(chip->chg_psy); in smb2_handle_batt_overvoltage()
736 power_supply_changed(chip->chg_psy); in smb2_handle_usb_plugin()
738 schedule_delayed_work(&chip->status_change_work, in smb2_handle_usb_plugin()
748 power_supply_changed(chip->chg_psy); in smb2_handle_usb_icl_change()
758 power_supply_changed(chip->chg_psy); in smb2_handle_wdog_bark()
760 rc = regmap_write(chip->regmap, BARK_BITE_WDOG_PET, in smb2_handle_wdog_bark()
763 dev_err(chip->dev, "Couldn't pet the dog rc=%d\n", rc); in smb2_handle_wdog_bark()
787 * FIXME: This will be handled by the type-c driver
794 * Disable Type-C factory mode and stay in Attached.SRC state when VCONN
795 * over-current happens
817 * CHG_EN_SRC_BIT - charger enable is controlled by software
818 * CHG_EN_POLARITY_BIT - polarity of charge enable pin when in HW control
820 * PRETOFAST_TRANSITION_CFG_BIT -
821 * BAT_OV_ECC_BIT -
822 * I_TERM_BIT - Current termination ?? 0 = enabled
823 * AUTO_RECHG_BIT - Enable automatic recharge when battery is full
826 * CHARGER_INHIBIT_BIT - Inhibit charging based on battery voltage
839 /* Set the default SDP charger type to a 500ma USB 2.0 port */
890 dev_dbg(chip->dev, "%d: Writing 0x%02x to 0x%02x\n", i, in smb2_init_hw()
892 rc = regmap_update_bits(chip->regmap, in smb2_init_hw()
893 chip->base + smb2_init_seq[i].addr, in smb2_init_hw()
897 return dev_err_probe(chip->dev, rc, in smb2_init_hw()
911 irqnum = platform_get_irq_byname(to_platform_device(chip->dev), name); in smb2_init_irq()
915 rc = devm_request_threaded_irq(chip->dev, irqnum, NULL, handler, in smb2_init_irq()
918 return dev_err_probe(chip->dev, rc, "Couldn't request irq %s\n", in smb2_init_irq()
934 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); in smb2_probe()
936 return -ENOMEM; in smb2_probe()
938 chip->dev = &pdev->dev; in smb2_probe()
939 chip->name = pdev->name; in smb2_probe()
941 chip->regmap = dev_get_regmap(pdev->dev.parent, NULL); in smb2_probe()
942 if (!chip->regmap) in smb2_probe()
943 return dev_err_probe(chip->dev, -ENODEV, in smb2_probe()
946 rc = device_property_read_u32(chip->dev, "reg", &chip->base); in smb2_probe()
948 return dev_err_probe(chip->dev, rc, in smb2_probe()
951 chip->usb_in_v_chan = devm_iio_channel_get(chip->dev, "usbin_v"); in smb2_probe()
952 if (IS_ERR(chip->usb_in_v_chan)) in smb2_probe()
953 return dev_err_probe(chip->dev, PTR_ERR(chip->usb_in_v_chan), in smb2_probe()
956 chip->usb_in_i_chan = devm_iio_channel_get(chip->dev, "usbin_i"); in smb2_probe()
957 if (IS_ERR(chip->usb_in_i_chan)) { in smb2_probe()
958 return dev_err_probe(chip->dev, PTR_ERR(chip->usb_in_i_chan), in smb2_probe()
967 supply_config.of_node = pdev->dev.of_node; in smb2_probe()
969 desc = devm_kzalloc(chip->dev, sizeof(smb2_psy_desc), GFP_KERNEL); in smb2_probe()
971 return -ENOMEM; in smb2_probe()
973 desc->name = in smb2_probe()
974 devm_kasprintf(chip->dev, GFP_KERNEL, "%s-charger", in smb2_probe()
975 (const char *)device_get_match_data(chip->dev)); in smb2_probe()
976 if (!desc->name) in smb2_probe()
977 return -ENOMEM; in smb2_probe()
979 chip->chg_psy = in smb2_probe()
980 devm_power_supply_register(chip->dev, desc, &supply_config); in smb2_probe()
981 if (IS_ERR(chip->chg_psy)) in smb2_probe()
982 return dev_err_probe(chip->dev, PTR_ERR(chip->chg_psy), in smb2_probe()
985 rc = power_supply_get_battery_info(chip->chg_psy, &chip->batt_info); in smb2_probe()
987 return dev_err_probe(chip->dev, rc, in smb2_probe()
990 rc = devm_delayed_work_autocancel(chip->dev, &chip->status_change_work, in smb2_probe()
993 return dev_err_probe(chip->dev, rc, in smb2_probe()
996 rc = (chip->batt_info->voltage_max_design_uv - 3487500) / 7500 + 1; in smb2_probe()
997 rc = regmap_update_bits(chip->regmap, chip->base + FLOAT_VOLTAGE_CFG, in smb2_probe()
1000 return dev_err_probe(chip->dev, rc, "Couldn't set vbat max\n"); in smb2_probe()
1002 rc = smb2_init_irq(chip, &irq, "bat-ov", smb2_handle_batt_overvoltage); in smb2_probe()
1006 rc = smb2_init_irq(chip, &chip->cable_irq, "usb-plugin", in smb2_probe()
1011 rc = smb2_init_irq(chip, &irq, "usbin-icl-change", in smb2_probe()
1015 rc = smb2_init_irq(chip, &irq, "wdog-bark", smb2_handle_wdog_bark); in smb2_probe()
1019 rc = dev_pm_set_wake_irq(chip->dev, chip->cable_irq); in smb2_probe()
1021 return dev_err_probe(chip->dev, rc, "Couldn't set wake irq\n"); in smb2_probe()
1026 schedule_delayed_work(&chip->status_change_work, 0); in smb2_probe()
1032 { .compatible = "qcom,pmi8998-charger", .data = "pmi8998" },
1033 { .compatible = "qcom,pm660-charger", .data = "pm660" },
1041 .name = "qcom-pmi8998/pm660-charger",