Lines Matching +full:battery +full:- +full:sensing

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * twl4030_usb - TWL4030 USB transceiver, talking to OMAP OTG controller
5 * Copyright (C) 2004-2007 Texas Instruments
10 * - HS USB ULPI mode works.
11 * - 3-pin mode support may be added in future.
138 * cable is present and we need to be runtime-enabled
175 /*-------------------------------------------------------------------------*/
186 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n", in twl4030_i2c_write_u8_verify()
194 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n", in twl4030_i2c_write_u8_verify()
198 return -EBUSY; in twl4030_i2c_write_u8_verify()
211 dev_dbg(twl->dev, in twl4030_usb_write()
225 dev_dbg(twl->dev, in twl4030_readb()
237 /*-------------------------------------------------------------------------*/
251 /*-------------------------------------------------------------------------*/
278 twl->vbus_supplied = false; in twl4030_usb_linkstat()
281 * For ID/VBUS sensing, see manual section 15.4.8 ... in twl4030_usb_linkstat()
282 * except when using only battery backup power, two in twl4030_usb_linkstat()
292 dev_err(twl->dev, "USB link status err %d\n", status); in twl4030_usb_linkstat()
298 twl->vbus_supplied = true; in twl4030_usb_linkstat()
308 if (twl->linkstat != MUSB_UNKNOWN) in twl4030_usb_linkstat()
312 kobject_uevent(&twl->dev->kobj, linkstat == MUSB_VBUS_VALID in twl4030_usb_linkstat()
315 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", in twl4030_usb_linkstat()
327 twl->usb_mode = mode; in twl4030_usb_set_mode()
338 case -1: in twl4030_usb_set_mode()
342 dev_err(twl->dev, "unsupported T2 transceiver mode %d\n", in twl4030_usb_set_mode()
367 dev_err(twl->dev, "Timeout setting T2 HSUSB " in twl4030_i2c_access()
402 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_usb_suspend()
403 disable_irq(twl->irq); in twl4030_usb_suspend()
404 if (!twl->runtime_suspended && !atomic_read(&twl->connected)) { in twl4030_usb_suspend()
406 twl->needs_resume = 1; in twl4030_usb_suspend()
416 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_usb_resume()
417 enable_irq(twl->irq); in twl4030_usb_resume()
418 if (twl->needs_resume) in twl4030_usb_resume()
423 twl->runtime_suspended = 0; in twl4030_usb_resume()
432 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_usb_runtime_suspend()
435 regulator_disable(twl->usb1v5); in twl4030_usb_runtime_suspend()
436 regulator_disable(twl->usb1v8); in twl4030_usb_runtime_suspend()
437 regulator_disable(twl->usb3v1); in twl4030_usb_runtime_suspend()
439 twl->runtime_suspended = 1; in twl4030_usb_runtime_suspend()
449 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_usb_runtime_resume()
451 res = regulator_enable(twl->usb3v1); in twl4030_usb_runtime_resume()
453 dev_err(twl->dev, "Failed to enable usb3v1\n"); in twl4030_usb_runtime_resume()
455 res = regulator_enable(twl->usb1v8); in twl4030_usb_runtime_resume()
457 dev_err(twl->dev, "Failed to enable usb1v8\n"); in twl4030_usb_runtime_resume()
464 * is re-activated. This ensures that VUSB3V1 is really active. in twl4030_usb_runtime_resume()
468 res = regulator_enable(twl->usb1v5); in twl4030_usb_runtime_resume()
470 dev_err(twl->dev, "Failed to enable usb1v5\n"); in twl4030_usb_runtime_resume()
479 twl4030_usb_set_mode(twl, twl->usb_mode); in twl4030_usb_runtime_resume()
480 if (twl->usb_mode == T2_USB_MODE_ULPI) in twl4030_usb_runtime_resume()
496 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_phy_power_off()
505 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_phy_power_on()
506 pm_runtime_get_sync(twl->dev); in twl4030_phy_power_on()
507 schedule_delayed_work(&twl->id_workaround_work, HZ); in twl4030_phy_power_on()
508 pm_runtime_mark_last_busy(twl->dev); in twl4030_phy_power_on()
509 pm_runtime_put_autosuspend(twl->dev); in twl4030_phy_power_on()
532 twl->usb3v1 = devm_regulator_get(twl->dev, "usb3v1"); in twl4030_usb_ldo_init()
533 if (IS_ERR(twl->usb3v1)) in twl4030_usb_ldo_init()
534 return -ENODEV; in twl4030_usb_ldo_init()
541 twl->usb1v5 = devm_regulator_get(twl->dev, "usb1v5"); in twl4030_usb_ldo_init()
542 if (IS_ERR(twl->usb1v5)) in twl4030_usb_ldo_init()
543 return -ENODEV; in twl4030_usb_ldo_init()
550 twl->usb1v8 = devm_regulator_get(twl->dev, "usb1v8"); in twl4030_usb_ldo_init()
551 if (IS_ERR(twl->usb1v8)) in twl4030_usb_ldo_init()
552 return -ENODEV; in twl4030_usb_ldo_init()
567 int ret = -EINVAL; in vbus_show()
569 mutex_lock(&twl->lock); in vbus_show()
571 twl->vbus_supplied ? "on" : "off"); in vbus_show()
572 mutex_unlock(&twl->lock); in vbus_show()
586 mutex_lock(&twl->lock); in twl4030_usb_irq()
587 twl->linkstat = status; in twl4030_usb_irq()
588 mutex_unlock(&twl->lock); in twl4030_usb_irq()
591 if (atomic_add_unless(&twl->connected, 1, 1)) { in twl4030_usb_irq()
592 dev_dbg(twl->dev, "%s: cable connected %i\n", in twl4030_usb_irq()
594 pm_runtime_get_sync(twl->dev); in twl4030_usb_irq()
595 twl->musb_mailbox_pending = true; in twl4030_usb_irq()
598 if (atomic_add_unless(&twl->connected, -1, 0)) { in twl4030_usb_irq()
599 dev_dbg(twl->dev, "%s: cable disconnected %i\n", in twl4030_usb_irq()
601 pm_runtime_mark_last_busy(twl->dev); in twl4030_usb_irq()
602 pm_runtime_put_autosuspend(twl->dev); in twl4030_usb_irq()
603 twl->musb_mailbox_pending = true; in twl4030_usb_irq()
606 if (twl->musb_mailbox_pending) { in twl4030_usb_irq()
609 twl->musb_mailbox_pending = false; in twl4030_usb_irq()
612 /* don't schedule during sleep - irq works right then */ in twl4030_usb_irq()
613 if (status == MUSB_ID_GROUND && pm_runtime_active(twl->dev)) { in twl4030_usb_irq()
614 cancel_delayed_work(&twl->id_workaround_work); in twl4030_usb_irq()
615 schedule_delayed_work(&twl->id_workaround_work, HZ); in twl4030_usb_irq()
619 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); in twl4030_usb_irq()
636 pm_runtime_get_sync(twl->dev); in twl4030_phy_init()
637 twl->linkstat = MUSB_UNKNOWN; in twl4030_phy_init()
638 schedule_delayed_work(&twl->id_workaround_work, HZ); in twl4030_phy_init()
639 pm_runtime_mark_last_busy(twl->dev); in twl4030_phy_init()
640 pm_runtime_put_autosuspend(twl->dev); in twl4030_phy_init()
649 return -ENODEV; in twl4030_set_peripheral()
651 otg->gadget = gadget; in twl4030_set_peripheral()
653 otg->state = OTG_STATE_UNDEFINED; in twl4030_set_peripheral()
661 return -ENODEV; in twl4030_set_host()
663 otg->host = host; in twl4030_set_host()
665 otg->state = OTG_STATE_UNDEFINED; in twl4030_set_host()
685 struct twl4030_usb_data *pdata = dev_get_platdata(&pdev->dev); in twl4030_usb_probe()
690 struct device_node *np = pdev->dev.of_node; in twl4030_usb_probe()
693 twl = devm_kzalloc(&pdev->dev, sizeof(*twl), GFP_KERNEL); in twl4030_usb_probe()
695 return -ENOMEM; in twl4030_usb_probe()
699 (enum twl4030_usb_mode *)&twl->usb_mode); in twl4030_usb_probe()
701 twl->usb_mode = pdata->usb_mode; in twl4030_usb_probe()
703 dev_err(&pdev->dev, "twl4030 initialized without pdata\n"); in twl4030_usb_probe()
704 return -EINVAL; in twl4030_usb_probe()
707 otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); in twl4030_usb_probe()
709 return -ENOMEM; in twl4030_usb_probe()
711 twl->dev = &pdev->dev; in twl4030_usb_probe()
712 twl->irq = platform_get_irq(pdev, 0); in twl4030_usb_probe()
713 twl->vbus_supplied = false; in twl4030_usb_probe()
714 twl->linkstat = MUSB_UNKNOWN; in twl4030_usb_probe()
715 twl->musb_mailbox_pending = false; in twl4030_usb_probe()
717 twl->phy.dev = twl->dev; in twl4030_usb_probe()
718 twl->phy.label = "twl4030"; in twl4030_usb_probe()
719 twl->phy.otg = otg; in twl4030_usb_probe()
720 twl->phy.type = USB_PHY_TYPE_USB2; in twl4030_usb_probe()
722 otg->usb_phy = &twl->phy; in twl4030_usb_probe()
723 otg->set_host = twl4030_set_host; in twl4030_usb_probe()
724 otg->set_peripheral = twl4030_set_peripheral; in twl4030_usb_probe()
726 phy = devm_phy_create(twl->dev, NULL, &ops); in twl4030_usb_probe()
728 dev_dbg(&pdev->dev, "Failed to create PHY\n"); in twl4030_usb_probe()
734 phy_provider = devm_of_phy_provider_register(twl->dev, in twl4030_usb_probe()
740 mutex_init(&twl->lock); in twl4030_usb_probe()
742 INIT_DELAYED_WORK(&twl->id_workaround_work, twl4030_id_workaround_work); in twl4030_usb_probe()
746 dev_err(&pdev->dev, "ldo init failed\n"); in twl4030_usb_probe()
749 usb_add_phy_dev(&twl->phy); in twl4030_usb_probe()
752 if (device_create_file(&pdev->dev, &dev_attr_vbus)) in twl4030_usb_probe()
753 dev_warn(&pdev->dev, "could not create sysfs file\n"); in twl4030_usb_probe()
755 ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier); in twl4030_usb_probe()
757 pm_runtime_use_autosuspend(&pdev->dev); in twl4030_usb_probe()
758 pm_runtime_set_autosuspend_delay(&pdev->dev, 2000); in twl4030_usb_probe()
759 pm_runtime_enable(&pdev->dev); in twl4030_usb_probe()
760 pm_runtime_get_sync(&pdev->dev); in twl4030_usb_probe()
770 status = devm_request_threaded_irq(twl->dev, twl->irq, NULL, in twl4030_usb_probe()
774 dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n", in twl4030_usb_probe()
775 twl->irq, status); in twl4030_usb_probe()
780 err = phy_create_lookup(phy, "usb", "musb-hdrc.0"); in twl4030_usb_probe()
784 pm_runtime_mark_last_busy(&pdev->dev); in twl4030_usb_probe()
785 pm_runtime_put_autosuspend(twl->dev); in twl4030_usb_probe()
787 dev_info(&pdev->dev, "Initialized TWL4030 USB module\n"); in twl4030_usb_probe()
796 usb_remove_phy(&twl->phy); in twl4030_usb_remove()
797 pm_runtime_get_sync(twl->dev); in twl4030_usb_remove()
798 cancel_delayed_work_sync(&twl->id_workaround_work); in twl4030_usb_remove()
799 device_remove_file(twl->dev, &dev_attr_vbus); in twl4030_usb_remove()
802 twl4030_usb_set_mode(twl, -1); in twl4030_usb_remove()
805 if (cable_present(twl->linkstat)) in twl4030_usb_remove()
806 pm_runtime_put_noidle(twl->dev); in twl4030_usb_remove()
807 pm_runtime_mark_last_busy(twl->dev); in twl4030_usb_remove()
808 pm_runtime_dont_use_autosuspend(&pdev->dev); in twl4030_usb_remove()
809 pm_runtime_put_sync(twl->dev); in twl4030_usb_remove()
810 pm_runtime_disable(twl->dev); in twl4030_usb_remove()
829 { .compatible = "ti,twl4030-usb" },