Lines Matching refs:twl

177 static int twl4030_i2c_write_u8_verify(struct twl4030_usb *twl,  in twl4030_i2c_write_u8_verify()  argument
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()
201 #define twl4030_usb_write_verify(twl, address, data) \ argument
202 twl4030_i2c_write_u8_verify(twl, TWL_MODULE_USB, (data), (address))
204 static inline int twl4030_usb_write(struct twl4030_usb *twl, in twl4030_usb_write() argument
211 dev_dbg(twl->dev, in twl4030_usb_write()
216 static inline int twl4030_readb(struct twl4030_usb *twl, u8 module, u8 address) in twl4030_readb() argument
225 dev_dbg(twl->dev, in twl4030_readb()
232 static inline int twl4030_usb_read(struct twl4030_usb *twl, u8 address) in twl4030_usb_read() argument
234 return twl4030_readb(twl, TWL_MODULE_USB, address); in twl4030_usb_read()
240 twl4030_usb_set_bits(struct twl4030_usb *twl, u8 reg, u8 bits) in twl4030_usb_set_bits() argument
242 return twl4030_usb_write(twl, ULPI_SET(reg), bits); in twl4030_usb_set_bits()
246 twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits) in twl4030_usb_clear_bits() argument
248 return twl4030_usb_write(twl, ULPI_CLR(reg), bits); in twl4030_usb_clear_bits()
253 static bool twl4030_is_driving_vbus(struct twl4030_usb *twl) in twl4030_is_driving_vbus() argument
257 ret = twl4030_usb_read(twl, PHY_CLK_CTRL_STS); in twl4030_is_driving_vbus()
265 ret = twl4030_usb_read(twl, ULPI_OTG_CTRL); in twl4030_is_driving_vbus()
273 twl4030_usb_linkstat(struct twl4030_usb *twl) in twl4030_usb_linkstat() argument
278 twl->vbus_supplied = false; in twl4030_usb_linkstat()
290 status = twl4030_readb(twl, TWL_MODULE_PM_MASTER, STS_HW_CONDITIONS); in twl4030_usb_linkstat()
292 dev_err(twl->dev, "USB link status err %d\n", status); in twl4030_usb_linkstat()
295 if (twl4030_is_driving_vbus(twl)) 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()
325 static void twl4030_usb_set_mode(struct twl4030_usb *twl, int mode) in twl4030_usb_set_mode() argument
327 twl->usb_mode = mode; in twl4030_usb_set_mode()
331 twl4030_usb_clear_bits(twl, ULPI_IFC_CTRL, in twl4030_usb_set_mode()
333 twl4030_usb_set_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB); in twl4030_usb_set_mode()
334 twl4030_usb_clear_bits(twl, ULPI_FUNC_CTRL, in twl4030_usb_set_mode()
342 dev_err(twl->dev, "unsupported T2 transceiver mode %d\n", in twl4030_usb_set_mode()
348 static void twl4030_i2c_access(struct twl4030_usb *twl, int on) in twl4030_i2c_access() argument
351 int val = twl4030_usb_read(twl, PHY_CLK_CTRL); in twl4030_i2c_access()
357 WARN_ON(twl4030_usb_write_verify(twl, PHY_CLK_CTRL, in twl4030_i2c_access()
361 while (!(twl4030_usb_read(twl, PHY_CLK_CTRL_STS) & in twl4030_i2c_access()
365 if (!(twl4030_usb_read(twl, PHY_CLK_CTRL_STS) & in twl4030_i2c_access()
367 dev_err(twl->dev, "Timeout setting T2 HSUSB " in twl4030_i2c_access()
372 WARN_ON(twl4030_usb_write_verify(twl, PHY_CLK_CTRL, in twl4030_i2c_access()
378 static void __twl4030_phy_power(struct twl4030_usb *twl, int on) in __twl4030_phy_power() argument
380 u8 pwr = twl4030_usb_read(twl, PHY_PWR_CTRL); in __twl4030_phy_power()
387 WARN_ON(twl4030_usb_write_verify(twl, PHY_PWR_CTRL, pwr) < 0); in __twl4030_phy_power()
395 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_suspend() local
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()
414 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_resume() local
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()
421 twl4030_usb_irq(0, twl); in twl4030_usb_resume()
423 twl->runtime_suspended = 0; in twl4030_usb_resume()
430 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_runtime_suspend() local
432 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_usb_runtime_suspend()
434 __twl4030_phy_power(twl, 0); 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()
446 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_runtime_resume() local
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()
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()
472 __twl4030_phy_power(twl, 1); in twl4030_usb_runtime_resume()
473 twl4030_usb_write(twl, PHY_CLK_CTRL, in twl4030_usb_runtime_resume()
474 twl4030_usb_read(twl, PHY_CLK_CTRL) | in twl4030_usb_runtime_resume()
478 twl4030_i2c_access(twl, 1); 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()
481 twl4030_i2c_access(twl, 0); in twl4030_usb_runtime_resume()
494 struct twl4030_usb *twl = phy_get_drvdata(phy); in twl4030_phy_power_off() local
496 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_phy_power_off()
503 struct twl4030_usb *twl = phy_get_drvdata(phy); in twl4030_phy_power_on() local
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()
514 static int twl4030_usb_ldo_init(struct twl4030_usb *twl) in twl4030_usb_ldo_init() argument
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()
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()
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()
566 struct twl4030_usb *twl = dev_get_drvdata(dev); in vbus_show() local
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()
580 struct twl4030_usb *twl = _twl; in twl4030_usb_irq() local
584 status = twl4030_usb_linkstat(twl); in twl4030_usb_irq()
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()
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()
626 struct twl4030_usb *twl = container_of(work, struct twl4030_usb, in twl4030_id_workaround_work() local
629 twl4030_usb_irq(0, twl); in twl4030_id_workaround_work()
634 struct twl4030_usb *twl = phy_get_drvdata(phy); in twl4030_phy_init() local
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()
686 struct twl4030_usb *twl; in twl4030_usb_probe() local
693 twl = devm_kzalloc(&pdev->dev, sizeof(*twl), GFP_KERNEL); in twl4030_usb_probe()
694 if (!twl) 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()
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()
726 phy = devm_phy_create(twl->dev, NULL, &ops); in twl4030_usb_probe()
732 phy_set_drvdata(phy, twl); 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()
744 err = twl4030_usb_ldo_init(twl); in twl4030_usb_probe()
749 usb_add_phy_dev(&twl->phy); in twl4030_usb_probe()
751 platform_set_drvdata(pdev, twl); in twl4030_usb_probe()
755 ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier); in twl4030_usb_probe()
770 status = devm_request_threaded_irq(twl->dev, twl->irq, NULL, in twl4030_usb_probe()
772 IRQF_TRIGGER_RISING | IRQF_ONESHOT, "twl4030_usb", twl); in twl4030_usb_probe()
775 twl->irq, status); in twl4030_usb_probe()
785 pm_runtime_put_autosuspend(twl->dev); in twl4030_usb_probe()
793 struct twl4030_usb *twl = platform_get_drvdata(pdev); in twl4030_usb_remove() local
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()
809 pm_runtime_put_sync(twl->dev); in twl4030_usb_remove()
810 pm_runtime_disable(twl->dev); in twl4030_usb_remove()
816 val = twl4030_usb_read(twl, PHY_CLK_CTRL); in twl4030_usb_remove()
820 twl4030_usb_write(twl, PHY_CLK_CTRL, (u8)val); in twl4030_usb_remove()
824 twl4030_usb_clear_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB); in twl4030_usb_remove()