Lines Matching refs:info
153 static inline int axp288_charger_set_cc(struct axp288_chrg_info *info, int cc) in axp288_charger_set_cc() argument
160 else if (cc > info->max_cc) in axp288_charger_set_cc()
161 cc = info->max_cc; in axp288_charger_set_cc()
167 ret = regmap_update_bits(info->regmap, in axp288_charger_set_cc()
171 info->cc = cc; in axp288_charger_set_cc()
176 static inline int axp288_charger_set_cv(struct axp288_chrg_info *info, int cv) in axp288_charger_set_cv() argument
197 ret = regmap_update_bits(info->regmap, in axp288_charger_set_cv()
202 info->cv = cv; in axp288_charger_set_cv()
207 static int axp288_charger_get_vbus_inlmt(struct axp288_chrg_info *info) in axp288_charger_get_vbus_inlmt() argument
211 val = info->backend_control; in axp288_charger_get_vbus_inlmt()
237 static inline int axp288_charger_set_vbus_inlmt(struct axp288_chrg_info *info, in axp288_charger_set_vbus_inlmt() argument
262 ret = regmap_update_bits(info->regmap, AXP20X_CHRG_BAK_CTRL, in axp288_charger_set_vbus_inlmt()
265 dev_err(&info->pdev->dev, "charger BAK control %d\n", ret); in axp288_charger_set_vbus_inlmt()
270 static int axp288_charger_vbus_path_select(struct axp288_chrg_info *info, in axp288_charger_vbus_path_select() argument
276 ret = regmap_update_bits(info->regmap, AXP20X_VBUS_IPSOUT_MGMT, in axp288_charger_vbus_path_select()
279 ret = regmap_update_bits(info->regmap, AXP20X_VBUS_IPSOUT_MGMT, in axp288_charger_vbus_path_select()
283 dev_err(&info->pdev->dev, "axp288 vbus path select %d\n", ret); in axp288_charger_vbus_path_select()
288 static int axp288_charger_enable_charger(struct axp288_chrg_info *info, in axp288_charger_enable_charger() argument
294 ret = regmap_update_bits(info->regmap, AXP20X_CHRG_CTRL1, in axp288_charger_enable_charger()
297 ret = regmap_update_bits(info->regmap, AXP20X_CHRG_CTRL1, in axp288_charger_enable_charger()
300 dev_err(&info->pdev->dev, "axp288 enable charger %d\n", ret); in axp288_charger_enable_charger()
305 static int axp288_get_charger_health(struct axp288_chrg_info *info) in axp288_get_charger_health() argument
307 if (!(info->input_status & PS_STAT_VBUS_PRESENT)) in axp288_get_charger_health()
310 if (!(info->input_status & PS_STAT_VBUS_VALID)) in axp288_get_charger_health()
312 else if (info->op_mode & CHRG_STAT_PMIC_OTP) in axp288_get_charger_health()
314 else if (info->op_mode & CHRG_STAT_BAT_SAFE_MODE) in axp288_get_charger_health()
324 struct axp288_chrg_info *info = power_supply_get_drvdata(psy); in axp288_charger_usb_set_property() local
328 mutex_lock(&info->lock); in axp288_charger_usb_set_property()
331 scaled_val = min(val->intval, info->max_cc); in axp288_charger_usb_set_property()
333 ret = axp288_charger_set_cc(info, scaled_val); in axp288_charger_usb_set_property()
335 dev_warn(&info->pdev->dev, "set charge current failed\n"); in axp288_charger_usb_set_property()
340 scaled_val = min(val->intval, info->max_cv); in axp288_charger_usb_set_property()
342 ret = axp288_charger_set_cv(info, scaled_val); in axp288_charger_usb_set_property()
344 dev_warn(&info->pdev->dev, "set charge voltage failed\n"); in axp288_charger_usb_set_property()
349 ret = axp288_charger_set_vbus_inlmt(info, val->intval); in axp288_charger_usb_set_property()
351 dev_warn(&info->pdev->dev, "set input current limit failed\n"); in axp288_charger_usb_set_property()
354 info->valid = false; in axp288_charger_usb_set_property()
361 mutex_unlock(&info->lock); in axp288_charger_usb_set_property()
365 static int axp288_charger_reg_readb(struct axp288_chrg_info *info, int reg, unsigned int *ret_val) in axp288_charger_reg_readb() argument
369 ret = regmap_read(info->regmap, reg, ret_val); in axp288_charger_reg_readb()
371 dev_err(&info->pdev->dev, "Error %d on reading value from register 0x%04x\n", in axp288_charger_reg_readb()
379 static int axp288_charger_usb_update_property(struct axp288_chrg_info *info) in axp288_charger_usb_update_property() argument
383 if (info->valid && time_before(jiffies, info->last_updated + AXP288_REG_UPDATE_INTERVAL)) in axp288_charger_usb_update_property()
386 dev_dbg(&info->pdev->dev, "Charger updating register values...\n"); in axp288_charger_usb_update_property()
392 ret = axp288_charger_reg_readb(info, AXP20X_PWR_INPUT_STATUS, &info->input_status); in axp288_charger_usb_update_property()
396 ret = axp288_charger_reg_readb(info, AXP20X_PWR_OP_MODE, &info->op_mode); in axp288_charger_usb_update_property()
400 ret = axp288_charger_reg_readb(info, AXP20X_CHRG_BAK_CTRL, &info->backend_control); in axp288_charger_usb_update_property()
404 info->last_updated = jiffies; in axp288_charger_usb_update_property()
405 info->valid = true; in axp288_charger_usb_update_property()
415 struct axp288_chrg_info *info = power_supply_get_drvdata(psy); in axp288_charger_usb_get_property() local
418 mutex_lock(&info->lock); in axp288_charger_usb_get_property()
419 ret = axp288_charger_usb_update_property(info); in axp288_charger_usb_get_property()
426 if (info->otg.id_short) { in axp288_charger_usb_get_property()
430 val->intval = (info->input_status & PS_STAT_VBUS_PRESENT) ? 1 : 0; in axp288_charger_usb_get_property()
434 if (info->otg.id_short) { in axp288_charger_usb_get_property()
438 val->intval = (info->input_status & PS_STAT_VBUS_VALID) ? 1 : 0; in axp288_charger_usb_get_property()
441 val->intval = axp288_get_charger_health(info); in axp288_charger_usb_get_property()
444 val->intval = info->cc * 1000; in axp288_charger_usb_get_property()
447 val->intval = info->max_cc * 1000; in axp288_charger_usb_get_property()
450 val->intval = info->cv * 1000; in axp288_charger_usb_get_property()
453 val->intval = info->max_cv * 1000; in axp288_charger_usb_get_property()
456 val->intval = axp288_charger_get_vbus_inlmt(info); in axp288_charger_usb_get_property()
463 mutex_unlock(&info->lock); in axp288_charger_usb_get_property()
509 struct axp288_chrg_info *info = dev; in axp288_charger_irq_thread_handler() local
513 if (info->irq[i] == irq) in axp288_charger_irq_thread_handler()
518 dev_warn(&info->pdev->dev, "spurious interrupt!!\n"); in axp288_charger_irq_thread_handler()
524 dev_dbg(&info->pdev->dev, "VBUS Over Voltage INTR\n"); in axp288_charger_irq_thread_handler()
527 dev_dbg(&info->pdev->dev, "Charging Done INTR\n"); in axp288_charger_irq_thread_handler()
530 dev_dbg(&info->pdev->dev, "Start Charging IRQ\n"); in axp288_charger_irq_thread_handler()
533 dev_dbg(&info->pdev->dev, in axp288_charger_irq_thread_handler()
537 dev_dbg(&info->pdev->dev, in axp288_charger_irq_thread_handler()
541 dev_dbg(&info->pdev->dev, in axp288_charger_irq_thread_handler()
545 dev_dbg(&info->pdev->dev, in axp288_charger_irq_thread_handler()
549 dev_dbg(&info->pdev->dev, in axp288_charger_irq_thread_handler()
553 dev_dbg(&info->pdev->dev, in axp288_charger_irq_thread_handler()
557 dev_warn(&info->pdev->dev, "Spurious Interrupt!!!\n"); in axp288_charger_irq_thread_handler()
560 mutex_lock(&info->lock); in axp288_charger_irq_thread_handler()
561 info->valid = false; in axp288_charger_irq_thread_handler()
562 mutex_unlock(&info->lock); in axp288_charger_irq_thread_handler()
563 power_supply_changed(info->psy_usb); in axp288_charger_irq_thread_handler()
619 struct axp288_chrg_info *info = in axp288_charger_extcon_evt_worker() local
622 struct extcon_dev *edev = info->cable.edev; in axp288_charger_extcon_evt_worker()
625 ret = regmap_read(info->regmap, AXP20X_PWR_INPUT_STATUS, &val); in axp288_charger_extcon_evt_worker()
627 dev_err(&info->pdev->dev, "Error reading status (%d)\n", ret); in axp288_charger_extcon_evt_worker()
633 dev_dbg(&info->pdev->dev, "USB charger disconnected\n"); in axp288_charger_extcon_evt_worker()
634 axp288_charger_enable_charger(info, false); in axp288_charger_extcon_evt_worker()
635 mutex_lock(&info->lock); in axp288_charger_extcon_evt_worker()
636 info->valid = false; in axp288_charger_extcon_evt_worker()
637 mutex_unlock(&info->lock); in axp288_charger_extcon_evt_worker()
638 power_supply_changed(info->psy_usb); in axp288_charger_extcon_evt_worker()
645 dev_dbg(&info->pdev->dev, "HP X2 with Type-C, setting inlmt to 3A\n"); in axp288_charger_extcon_evt_worker()
648 dev_dbg(&info->pdev->dev, "USB SDP charger is connected\n"); in axp288_charger_extcon_evt_worker()
651 dev_dbg(&info->pdev->dev, "USB CDP charger is connected\n"); in axp288_charger_extcon_evt_worker()
654 dev_dbg(&info->pdev->dev, "USB DCP charger is connected\n"); in axp288_charger_extcon_evt_worker()
662 ret = axp288_charger_set_vbus_inlmt(info, current_limit); in axp288_charger_extcon_evt_worker()
664 axp288_charger_enable_charger(info, true); in axp288_charger_extcon_evt_worker()
666 dev_err(&info->pdev->dev, in axp288_charger_extcon_evt_worker()
669 mutex_lock(&info->lock); in axp288_charger_extcon_evt_worker()
670 info->valid = false; in axp288_charger_extcon_evt_worker()
671 mutex_unlock(&info->lock); in axp288_charger_extcon_evt_worker()
672 power_supply_changed(info->psy_usb); in axp288_charger_extcon_evt_worker()
678 struct axp288_chrg_info *info = in axp288_charger_handle_cable_evt() local
680 schedule_work(&info->cable.work); in axp288_charger_handle_cable_evt()
686 struct axp288_chrg_info *info = in axp288_charger_otg_evt_worker() local
688 struct extcon_dev *edev = info->otg.cable; in axp288_charger_otg_evt_worker()
691 dev_dbg(&info->pdev->dev, "external connector USB-Host is %s\n", in axp288_charger_otg_evt_worker()
698 info->otg.id_short = usb_host; in axp288_charger_otg_evt_worker()
701 ret = axp288_charger_vbus_path_select(info, !info->otg.id_short); in axp288_charger_otg_evt_worker()
703 dev_warn(&info->pdev->dev, "vbus path disable failed\n"); in axp288_charger_otg_evt_worker()
709 struct axp288_chrg_info *info = in axp288_charger_handle_otg_evt() local
712 schedule_work(&info->otg.work); in axp288_charger_handle_otg_evt()
717 static int charger_init_hw_regs(struct axp288_chrg_info *info) in charger_init_hw_regs() argument
723 ret = regmap_write(info->regmap, AXP20X_V_LTF_CHRG, CHRG_VLTFC_0C); in charger_init_hw_regs()
725 dev_err(&info->pdev->dev, "register(%x) write error(%d)\n", in charger_init_hw_regs()
730 ret = regmap_write(info->regmap, AXP20X_V_HTF_CHRG, CHRG_VHTFC_45C); in charger_init_hw_regs()
732 dev_err(&info->pdev->dev, "register(%x) write error(%d)\n", in charger_init_hw_regs()
738 ret = regmap_update_bits(info->regmap, in charger_init_hw_regs()
742 dev_err(&info->pdev->dev, "register(%x) write error(%d)\n", in charger_init_hw_regs()
748 ret = regmap_update_bits(info->regmap, in charger_init_hw_regs()
752 dev_err(&info->pdev->dev, "register(%x) write error(%d)\n", in charger_init_hw_regs()
758 ret = regmap_update_bits(info->regmap, in charger_init_hw_regs()
762 dev_err(&info->pdev->dev, "register(%x) write error(%d)\n", in charger_init_hw_regs()
769 ret = axp288_charger_vbus_path_select(info, true); in charger_init_hw_regs()
775 ret = regmap_update_bits(info->regmap, AXP20X_VBUS_IPSOUT_MGMT, in charger_init_hw_regs()
778 dev_err(&info->pdev->dev, "register(%x) write error(%d)\n", in charger_init_hw_regs()
785 ret = regmap_read(info->regmap, AXP20X_CHRG_CTRL1, &val); in charger_init_hw_regs()
787 dev_err(&info->pdev->dev, "register(%x) read error(%d)\n", in charger_init_hw_regs()
796 info->cv = CV_4100MV; in charger_init_hw_regs()
799 info->cv = CV_4150MV; in charger_init_hw_regs()
802 info->cv = CV_4200MV; in charger_init_hw_regs()
805 info->cv = CV_4350MV; in charger_init_hw_regs()
812 info->cc = cc; in charger_init_hw_regs()
818 info->max_cv = info->cv; in charger_init_hw_regs()
819 info->max_cc = info->cc; in charger_init_hw_regs()
826 struct axp288_chrg_info *info = data; in axp288_charger_cancel_work() local
828 cancel_work_sync(&info->otg.work); in axp288_charger_cancel_work()
829 cancel_work_sync(&info->cable.work); in axp288_charger_cancel_work()
835 struct axp288_chrg_info *info; in axp288_charger_probe() local
858 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); in axp288_charger_probe()
859 if (!info) in axp288_charger_probe()
862 mutex_init(&info->lock); in axp288_charger_probe()
863 info->pdev = pdev; in axp288_charger_probe()
864 info->regmap = axp20x->regmap; in axp288_charger_probe()
865 info->regmap_irqc = axp20x->regmap_irqc; in axp288_charger_probe()
867 info->cable.edev = extcon_get_extcon_dev(AXP288_EXTCON_DEV_NAME); in axp288_charger_probe()
868 if (IS_ERR(info->cable.edev)) { in axp288_charger_probe()
869 dev_err_probe(dev, PTR_ERR(info->cable.edev), in axp288_charger_probe()
872 return PTR_ERR(info->cable.edev); in axp288_charger_probe()
876 info->otg.cable = extcon_get_extcon_dev(USB_HOST_EXTCON_NAME); in axp288_charger_probe()
877 if (IS_ERR(info->otg.cable)) { in axp288_charger_probe()
878 dev_err_probe(dev, PTR_ERR(info->otg.cable), in axp288_charger_probe()
881 return PTR_ERR(info->otg.cable); in axp288_charger_probe()
886 platform_set_drvdata(pdev, info); in axp288_charger_probe()
888 ret = charger_init_hw_regs(info); in axp288_charger_probe()
893 charger_cfg.drv_data = info; in axp288_charger_probe()
894 info->psy_usb = devm_power_supply_register(dev, &axp288_charger_desc, in axp288_charger_probe()
896 if (IS_ERR(info->psy_usb)) { in axp288_charger_probe()
897 ret = PTR_ERR(info->psy_usb); in axp288_charger_probe()
903 ret = devm_add_action(dev, axp288_charger_cancel_work, info); in axp288_charger_probe()
908 INIT_WORK(&info->cable.work, axp288_charger_extcon_evt_worker); in axp288_charger_probe()
909 info->cable.nb.notifier_call = axp288_charger_handle_cable_evt; in axp288_charger_probe()
910 ret = devm_extcon_register_notifier_all(dev, info->cable.edev, in axp288_charger_probe()
911 &info->cable.nb); in axp288_charger_probe()
916 schedule_work(&info->cable.work); in axp288_charger_probe()
919 INIT_WORK(&info->otg.work, axp288_charger_otg_evt_worker); in axp288_charger_probe()
920 info->otg.id_nb.notifier_call = axp288_charger_handle_otg_evt; in axp288_charger_probe()
921 if (info->otg.cable) { in axp288_charger_probe()
922 ret = devm_extcon_register_notifier(dev, info->otg.cable, in axp288_charger_probe()
923 EXTCON_USB_HOST, &info->otg.id_nb); in axp288_charger_probe()
928 schedule_work(&info->otg.work); in axp288_charger_probe()
933 pirq = platform_get_irq(info->pdev, i); in axp288_charger_probe()
937 info->irq[i] = regmap_irq_get_virq(info->regmap_irqc, pirq); in axp288_charger_probe()
938 if (info->irq[i] < 0) { in axp288_charger_probe()
939 dev_warn(&info->pdev->dev, in axp288_charger_probe()
941 return info->irq[i]; in axp288_charger_probe()
943 ret = devm_request_threaded_irq(&info->pdev->dev, info->irq[i], in axp288_charger_probe()
945 IRQF_ONESHOT, info->pdev->name, info); in axp288_charger_probe()
948 info->irq[i]); in axp288_charger_probe()