Lines Matching refs:bci
239 static int twl4030_charger_update_current(struct twl4030_bci *bci) in twl4030_charger_update_current() argument
252 if (ac_available(bci->channel_vac)) { in twl4030_charger_update_current()
253 cur = bci->ac_cur; in twl4030_charger_update_current()
254 bci->ac_is_active = true; in twl4030_charger_update_current()
256 cur = bci->usb_cur; in twl4030_charger_update_current()
257 bci->ac_is_active = false; in twl4030_charger_update_current()
258 if (cur > bci->usb_cur_target) { in twl4030_charger_update_current()
259 cur = bci->usb_cur_target; in twl4030_charger_update_current()
260 bci->usb_cur = cur; in twl4030_charger_update_current()
262 if (cur < bci->usb_cur_target) in twl4030_charger_update_current()
263 schedule_delayed_work(&bci->current_worker, USB_CUR_DELAY); in twl4030_charger_update_current()
267 if (bci->ichg_eoc >= 200000) in twl4030_charger_update_current()
269 if (bci->ichg_lo >= 400000) in twl4030_charger_update_current()
271 if (bci->ichg_hi >= 820000) in twl4030_charger_update_current()
296 reg = ua2regval(bci->ichg_eoc, cgain); in twl4030_charger_update_current()
308 reg = ua2regval(bci->ichg_lo, cgain); in twl4030_charger_update_current()
330 reg = ua2regval(bci->ichg_hi, cgain); in twl4030_charger_update_current()
404 struct twl4030_bci *bci = container_of(data, struct twl4030_bci, in twl4030_current_worker() local
415 dev_dbg(bci->dev, "v=%d cur=%d limit=%d target=%d\n", v, curr, in twl4030_current_worker()
416 bci->usb_cur, bci->usb_cur_target); in twl4030_current_worker()
420 if (bci->usb_cur >= USB_CUR_STEP) in twl4030_current_worker()
421 bci->usb_cur -= USB_CUR_STEP; in twl4030_current_worker()
422 bci->usb_cur_target = bci->usb_cur; in twl4030_current_worker()
423 } else if (bci->usb_cur >= bci->usb_cur_target || in twl4030_current_worker()
424 bci->usb_cur + USB_CUR_STEP > USB_MAX_CURRENT) { in twl4030_current_worker()
428 bci->usb_cur += USB_CUR_STEP; in twl4030_current_worker()
429 schedule_delayed_work(&bci->current_worker, USB_CUR_DELAY); in twl4030_current_worker()
431 twl4030_charger_update_current(bci); in twl4030_current_worker()
437 static int twl4030_charger_enable_usb(struct twl4030_bci *bci, bool enable) in twl4030_charger_enable_usb() argument
442 if (bci->usb_mode == CHARGE_OFF) in twl4030_charger_enable_usb()
444 if (enable && !IS_ERR_OR_NULL(bci->transceiver)) { in twl4030_charger_enable_usb()
446 twl4030_charger_update_current(bci); in twl4030_charger_enable_usb()
449 if (!bci->usb_enabled) { in twl4030_charger_enable_usb()
450 pm_runtime_get_sync(bci->transceiver->dev); in twl4030_charger_enable_usb()
451 bci->usb_enabled = 1; in twl4030_charger_enable_usb()
454 if (bci->usb_mode == CHARGE_AUTO) { in twl4030_charger_enable_usb()
462 dev_err(bci->dev, in twl4030_charger_enable_usb()
474 if (bci->usb_mode == CHARGE_LINEAR) { in twl4030_charger_enable_usb()
481 dev_err(bci->dev, in twl4030_charger_enable_usb()
514 if (bci->usb_enabled) { in twl4030_charger_enable_usb()
515 pm_runtime_mark_last_busy(bci->transceiver->dev); in twl4030_charger_enable_usb()
516 pm_runtime_put_autosuspend(bci->transceiver->dev); in twl4030_charger_enable_usb()
517 bci->usb_enabled = 0; in twl4030_charger_enable_usb()
519 bci->usb_cur = 0; in twl4030_charger_enable_usb()
528 static int twl4030_charger_enable_ac(struct twl4030_bci *bci, bool enable) in twl4030_charger_enable_ac() argument
532 if (bci->ac_mode == CHARGE_OFF) in twl4030_charger_enable_ac()
591 struct twl4030_bci *bci = arg; in twl4030_charger_interrupt() local
593 dev_dbg(bci->dev, "CHG_PRES irq\n"); in twl4030_charger_interrupt()
595 bci->ac_cur = 500000; in twl4030_charger_interrupt()
596 twl4030_charger_update_current(bci); in twl4030_charger_interrupt()
597 power_supply_changed(bci->ac); in twl4030_charger_interrupt()
598 power_supply_changed(bci->usb); in twl4030_charger_interrupt()
608 struct twl4030_bci *bci = arg; in twl4030_bci_interrupt() local
622 dev_dbg(bci->dev, "BCI irq %02x %02x\n", irqs2, irqs1); in twl4030_bci_interrupt()
626 power_supply_changed(bci->ac); in twl4030_bci_interrupt()
627 power_supply_changed(bci->usb); in twl4030_bci_interrupt()
629 twl4030_charger_update_current(bci); in twl4030_bci_interrupt()
633 dev_warn(bci->dev, "battery temperature out of range\n"); in twl4030_bci_interrupt()
636 dev_crit(bci->dev, "battery disconnected\n"); in twl4030_bci_interrupt()
639 dev_crit(bci->dev, "VBAT overvoltage\n"); in twl4030_bci_interrupt()
642 dev_crit(bci->dev, "VBUS overvoltage\n"); in twl4030_bci_interrupt()
645 dev_crit(bci->dev, "Ac charger overvoltage\n"); in twl4030_bci_interrupt()
652 struct twl4030_bci *bci = container_of(data, struct twl4030_bci, work); in twl4030_bci_usb_work() local
654 switch (bci->event) { in twl4030_bci_usb_work()
657 twl4030_charger_enable_usb(bci, true); in twl4030_bci_usb_work()
660 twl4030_charger_enable_usb(bci, false); in twl4030_bci_usb_work()
668 struct twl4030_bci *bci = container_of(nb, struct twl4030_bci, usb_nb); in twl4030_bci_usb_ncb() local
670 dev_dbg(bci->dev, "OTG notify %lu\n", val); in twl4030_bci_usb_ncb()
674 bci->usb_cur_target = 500000; in twl4030_bci_usb_ncb()
676 bci->usb_cur_target = 100000; in twl4030_bci_usb_ncb()
678 bci->event = val; in twl4030_bci_usb_ncb()
679 schedule_work(&bci->work); in twl4030_bci_usb_ncb()
691 struct twl4030_bci *bci = dev_get_drvdata(dev->parent); in twl4030_bci_mode_store() local
699 if (dev == &bci->ac->dev) { in twl4030_bci_mode_store()
702 twl4030_charger_enable_ac(bci, false); in twl4030_bci_mode_store()
703 bci->ac_mode = mode; in twl4030_bci_mode_store()
704 status = twl4030_charger_enable_ac(bci, true); in twl4030_bci_mode_store()
706 twl4030_charger_enable_usb(bci, false); in twl4030_bci_mode_store()
707 bci->usb_mode = mode; in twl4030_bci_mode_store()
708 status = twl4030_charger_enable_usb(bci, true); in twl4030_bci_mode_store()
720 struct twl4030_bci *bci = dev_get_drvdata(dev->parent); in twl4030_bci_mode_show() local
723 int mode = bci->usb_mode; in twl4030_bci_mode_show()
725 if (dev == &bci->ac->dev) in twl4030_bci_mode_show()
726 mode = bci->ac_mode; in twl4030_bci_mode_show()
760 static int twl4030bci_state(struct twl4030_bci *bci) in twl4030bci_state() argument
767 dev_err(bci->dev, "error reading BCIMSTATEC\n"); in twl4030bci_state()
771 dev_dbg(bci->dev, "state: %02x\n", state); in twl4030bci_state()
792 struct twl4030_bci *bci = dev_get_drvdata(psy->dev.parent); in twl4030_bci_get_property() local
797 state = twl4030bci_state(bci); in twl4030_bci_get_property()
861 if (!bci->ac_is_active) in twl4030_bci_get_property()
862 val->intval = bci->ac_cur; in twl4030_bci_get_property()
864 if (bci->ac_is_active) in twl4030_bci_get_property()
865 val->intval = bci->usb_cur_target; in twl4030_bci_get_property()
891 struct twl4030_bci *bci = dev_get_drvdata(psy->dev.parent); in twl4030_bci_set_property() local
896 bci->usb_cur_target = val->intval; in twl4030_bci_set_property()
898 bci->ac_cur = val->intval; in twl4030_bci_set_property()
899 twl4030_charger_update_current(bci); in twl4030_bci_set_property()
977 struct twl4030_bci *bci; in twl4030_bci_probe() local
982 bci = devm_kzalloc(&pdev->dev, sizeof(*bci), GFP_KERNEL); in twl4030_bci_probe()
983 if (bci == NULL) in twl4030_bci_probe()
989 bci->ichg_eoc = 80100; /* Stop charging when current drops to here */ in twl4030_bci_probe()
990 bci->ichg_lo = 241000; /* Low threshold */ in twl4030_bci_probe()
991 bci->ichg_hi = 500000; /* High threshold */ in twl4030_bci_probe()
992 bci->ac_cur = 500000; /* 500mA */ in twl4030_bci_probe()
994 bci->usb_cur_target = 500000; /* 500mA */ in twl4030_bci_probe()
996 bci->usb_cur_target = 100000; /* 100mA */ in twl4030_bci_probe()
997 bci->usb_mode = CHARGE_AUTO; in twl4030_bci_probe()
998 bci->ac_mode = CHARGE_AUTO; in twl4030_bci_probe()
1000 bci->dev = &pdev->dev; in twl4030_bci_probe()
1001 bci->irq_chg = platform_get_irq(pdev, 0); in twl4030_bci_probe()
1002 bci->irq_bci = platform_get_irq(pdev, 1); in twl4030_bci_probe()
1004 platform_set_drvdata(pdev, bci); in twl4030_bci_probe()
1006 INIT_WORK(&bci->work, twl4030_bci_usb_work); in twl4030_bci_probe()
1007 INIT_DELAYED_WORK(&bci->current_worker, twl4030_current_worker); in twl4030_bci_probe()
1009 bci->channel_vac = devm_iio_channel_get(&pdev->dev, "vac"); in twl4030_bci_probe()
1010 if (IS_ERR(bci->channel_vac)) { in twl4030_bci_probe()
1011 ret = PTR_ERR(bci->channel_vac); in twl4030_bci_probe()
1016 bci->channel_vac = NULL; in twl4030_bci_probe()
1019 if (bci->dev->of_node) { in twl4030_bci_probe()
1022 phynode = of_get_compatible_child(bci->dev->of_node->parent, in twl4030_bci_probe()
1025 bci->usb_nb.notifier_call = twl4030_bci_usb_ncb; in twl4030_bci_probe()
1026 bci->transceiver = devm_usb_get_phy_by_node( in twl4030_bci_probe()
1027 bci->dev, phynode, &bci->usb_nb); in twl4030_bci_probe()
1029 if (IS_ERR(bci->transceiver)) { in twl4030_bci_probe()
1030 ret = PTR_ERR(bci->transceiver); in twl4030_bci_probe()
1035 bci->transceiver = NULL; in twl4030_bci_probe()
1040 bci->ac = devm_power_supply_register(&pdev->dev, &twl4030_bci_ac_desc, in twl4030_bci_probe()
1042 if (IS_ERR(bci->ac)) { in twl4030_bci_probe()
1043 ret = PTR_ERR(bci->ac); in twl4030_bci_probe()
1048 bci->usb = devm_power_supply_register(&pdev->dev, &twl4030_bci_usb_desc, in twl4030_bci_probe()
1050 if (IS_ERR(bci->usb)) { in twl4030_bci_probe()
1051 ret = PTR_ERR(bci->usb); in twl4030_bci_probe()
1056 ret = devm_request_threaded_irq(&pdev->dev, bci->irq_chg, NULL, in twl4030_bci_probe()
1058 bci); in twl4030_bci_probe()
1061 bci->irq_chg, ret); in twl4030_bci_probe()
1065 ret = devm_request_threaded_irq(&pdev->dev, bci->irq_bci, NULL, in twl4030_bci_probe()
1066 twl4030_bci_interrupt, IRQF_ONESHOT, pdev->name, bci); in twl4030_bci_probe()
1069 bci->irq_bci, ret); in twl4030_bci_probe()
1089 twl4030_charger_update_current(bci); in twl4030_bci_probe()
1090 if (device_create_file(&bci->usb->dev, &dev_attr_mode)) in twl4030_bci_probe()
1092 if (device_create_file(&bci->ac->dev, &dev_attr_mode)) in twl4030_bci_probe()
1095 twl4030_charger_enable_ac(bci, true); in twl4030_bci_probe()
1096 if (!IS_ERR_OR_NULL(bci->transceiver)) in twl4030_bci_probe()
1097 twl4030_bci_usb_ncb(&bci->usb_nb, in twl4030_bci_probe()
1098 bci->transceiver->last_event, in twl4030_bci_probe()
1101 twl4030_charger_enable_usb(bci, false); in twl4030_bci_probe()
1113 struct twl4030_bci *bci = platform_get_drvdata(pdev); in twl4030_bci_remove() local
1115 twl4030_charger_enable_ac(bci, false); in twl4030_bci_remove()
1116 twl4030_charger_enable_usb(bci, false); in twl4030_bci_remove()
1119 device_remove_file(&bci->usb->dev, &dev_attr_mode); in twl4030_bci_remove()
1120 device_remove_file(&bci->ac->dev, &dev_attr_mode); in twl4030_bci_remove()