Lines Matching full:twl

26 #include <linux/mfd/twl.h>
174 static int twl4030_i2c_write_u8_verify(struct twl4030_usb *twl, in twl4030_i2c_write_u8_verify() argument
183 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n", in twl4030_i2c_write_u8_verify()
191 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n", in twl4030_i2c_write_u8_verify()
198 #define twl4030_usb_write_verify(twl, address, data) \ argument
199 twl4030_i2c_write_u8_verify(twl, TWL_MODULE_USB, (data), (address))
201 static inline int twl4030_usb_write(struct twl4030_usb *twl, in twl4030_usb_write() argument
208 dev_dbg(twl->dev, in twl4030_usb_write()
213 static inline int twl4030_readb(struct twl4030_usb *twl, u8 module, u8 address) in twl4030_readb() argument
222 dev_dbg(twl->dev, in twl4030_readb()
229 static inline int twl4030_usb_read(struct twl4030_usb *twl, u8 address) in twl4030_usb_read() argument
231 return twl4030_readb(twl, TWL_MODULE_USB, address); in twl4030_usb_read()
237 twl4030_usb_set_bits(struct twl4030_usb *twl, u8 reg, u8 bits) in twl4030_usb_set_bits() argument
239 return twl4030_usb_write(twl, ULPI_SET(reg), bits); in twl4030_usb_set_bits()
243 twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits) in twl4030_usb_clear_bits() argument
245 return twl4030_usb_write(twl, ULPI_CLR(reg), bits); in twl4030_usb_clear_bits()
250 static bool twl4030_is_driving_vbus(struct twl4030_usb *twl) in twl4030_is_driving_vbus() argument
254 ret = twl4030_usb_read(twl, PHY_CLK_CTRL_STS); in twl4030_is_driving_vbus()
262 ret = twl4030_usb_read(twl, ULPI_OTG_CTRL); in twl4030_is_driving_vbus()
270 twl4030_usb_linkstat(struct twl4030_usb *twl) in twl4030_usb_linkstat() argument
275 twl->vbus_supplied = false; in twl4030_usb_linkstat()
287 status = twl4030_readb(twl, TWL_MODULE_PM_MASTER, STS_HW_CONDITIONS); in twl4030_usb_linkstat()
289 dev_err(twl->dev, "USB link status err %d\n", status); in twl4030_usb_linkstat()
292 if (twl4030_is_driving_vbus(twl)) in twl4030_usb_linkstat()
295 twl->vbus_supplied = true; in twl4030_usb_linkstat()
305 if (twl->linkstat != MUSB_UNKNOWN) in twl4030_usb_linkstat()
309 kobject_uevent(&twl->dev->kobj, linkstat == MUSB_VBUS_VALID in twl4030_usb_linkstat()
312 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", in twl4030_usb_linkstat()
322 static void twl4030_usb_set_mode(struct twl4030_usb *twl, int mode) in twl4030_usb_set_mode() argument
324 twl->usb_mode = mode; in twl4030_usb_set_mode()
328 twl4030_usb_clear_bits(twl, ULPI_IFC_CTRL, in twl4030_usb_set_mode()
330 twl4030_usb_set_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB); in twl4030_usb_set_mode()
331 twl4030_usb_clear_bits(twl, ULPI_FUNC_CTRL, in twl4030_usb_set_mode()
339 dev_err(twl->dev, "unsupported T2 transceiver mode %d\n", in twl4030_usb_set_mode()
345 static void twl4030_i2c_access(struct twl4030_usb *twl, int on) in twl4030_i2c_access() argument
348 int val = twl4030_usb_read(twl, PHY_CLK_CTRL); in twl4030_i2c_access()
354 WARN_ON(twl4030_usb_write_verify(twl, PHY_CLK_CTRL, in twl4030_i2c_access()
358 while (!(twl4030_usb_read(twl, PHY_CLK_CTRL_STS) & in twl4030_i2c_access()
362 if (!(twl4030_usb_read(twl, PHY_CLK_CTRL_STS) & in twl4030_i2c_access()
364 dev_err(twl->dev, "Timeout setting T2 HSUSB " in twl4030_i2c_access()
369 WARN_ON(twl4030_usb_write_verify(twl, PHY_CLK_CTRL, in twl4030_i2c_access()
375 static void __twl4030_phy_power(struct twl4030_usb *twl, int on) in __twl4030_phy_power() argument
377 u8 pwr = twl4030_usb_read(twl, PHY_PWR_CTRL); in __twl4030_phy_power()
384 WARN_ON(twl4030_usb_write_verify(twl, PHY_PWR_CTRL, pwr) < 0); in __twl4030_phy_power()
389 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_suspend() local
396 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_usb_suspend()
397 disable_irq(twl->irq); in twl4030_usb_suspend()
404 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_resume() local
406 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_usb_resume()
407 enable_irq(twl->irq); in twl4030_usb_resume()
409 twl4030_usb_irq(0, twl); in twl4030_usb_resume()
416 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_runtime_suspend() local
418 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_usb_runtime_suspend()
420 __twl4030_phy_power(twl, 0); in twl4030_usb_runtime_suspend()
421 regulator_disable(twl->usb1v5); in twl4030_usb_runtime_suspend()
422 regulator_disable(twl->usb1v8); in twl4030_usb_runtime_suspend()
423 regulator_disable(twl->usb3v1); in twl4030_usb_runtime_suspend()
430 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_runtime_resume() local
433 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_usb_runtime_resume()
435 res = regulator_enable(twl->usb3v1); in twl4030_usb_runtime_resume()
437 dev_err(twl->dev, "Failed to enable usb3v1\n"); in twl4030_usb_runtime_resume()
439 res = regulator_enable(twl->usb1v8); in twl4030_usb_runtime_resume()
441 dev_err(twl->dev, "Failed to enable usb1v8\n"); in twl4030_usb_runtime_resume()
452 res = regulator_enable(twl->usb1v5); in twl4030_usb_runtime_resume()
454 dev_err(twl->dev, "Failed to enable usb1v5\n"); in twl4030_usb_runtime_resume()
456 __twl4030_phy_power(twl, 1); in twl4030_usb_runtime_resume()
457 twl4030_usb_write(twl, PHY_CLK_CTRL, in twl4030_usb_runtime_resume()
458 twl4030_usb_read(twl, PHY_CLK_CTRL) | in twl4030_usb_runtime_resume()
462 twl4030_i2c_access(twl, 1); in twl4030_usb_runtime_resume()
463 twl4030_usb_set_mode(twl, twl->usb_mode); in twl4030_usb_runtime_resume()
464 if (twl->usb_mode == T2_USB_MODE_ULPI) in twl4030_usb_runtime_resume()
465 twl4030_i2c_access(twl, 0); in twl4030_usb_runtime_resume()
478 struct twl4030_usb *twl = phy_get_drvdata(phy); in twl4030_phy_power_off() local
480 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_phy_power_off()
487 struct twl4030_usb *twl = phy_get_drvdata(phy); in twl4030_phy_power_on() local
489 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_phy_power_on()
490 pm_runtime_get_sync(twl->dev); in twl4030_phy_power_on()
491 schedule_delayed_work(&twl->id_workaround_work, HZ); in twl4030_phy_power_on()
492 pm_runtime_mark_last_busy(twl->dev); in twl4030_phy_power_on()
493 pm_runtime_put_autosuspend(twl->dev); in twl4030_phy_power_on()
498 static int twl4030_usb_ldo_init(struct twl4030_usb *twl) in twl4030_usb_ldo_init() argument
516 twl->usb3v1 = devm_regulator_get(twl->dev, "usb3v1"); in twl4030_usb_ldo_init()
517 if (IS_ERR(twl->usb3v1)) in twl4030_usb_ldo_init()
525 twl->usb1v5 = devm_regulator_get(twl->dev, "usb1v5"); in twl4030_usb_ldo_init()
526 if (IS_ERR(twl->usb1v5)) in twl4030_usb_ldo_init()
534 twl->usb1v8 = devm_regulator_get(twl->dev, "usb1v8"); in twl4030_usb_ldo_init()
535 if (IS_ERR(twl->usb1v8)) in twl4030_usb_ldo_init()
550 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_vbus_show() local
553 mutex_lock(&twl->lock); in twl4030_usb_vbus_show()
555 twl->vbus_supplied ? "on" : "off"); in twl4030_usb_vbus_show()
556 mutex_unlock(&twl->lock); in twl4030_usb_vbus_show()
564 struct twl4030_usb *twl = _twl; in twl4030_usb_irq() local
568 status = twl4030_usb_linkstat(twl); in twl4030_usb_irq()
570 mutex_lock(&twl->lock); in twl4030_usb_irq()
571 twl->linkstat = status; in twl4030_usb_irq()
572 mutex_unlock(&twl->lock); in twl4030_usb_irq()
575 if (atomic_add_unless(&twl->connected, 1, 1)) { in twl4030_usb_irq()
576 dev_dbg(twl->dev, "%s: cable connected %i\n", in twl4030_usb_irq()
578 pm_runtime_get_sync(twl->dev); in twl4030_usb_irq()
579 twl->musb_mailbox_pending = true; in twl4030_usb_irq()
582 if (atomic_add_unless(&twl->connected, -1, 0)) { in twl4030_usb_irq()
583 dev_dbg(twl->dev, "%s: cable disconnected %i\n", in twl4030_usb_irq()
585 pm_runtime_mark_last_busy(twl->dev); in twl4030_usb_irq()
586 pm_runtime_put_autosuspend(twl->dev); in twl4030_usb_irq()
587 twl->musb_mailbox_pending = true; in twl4030_usb_irq()
590 if (twl->musb_mailbox_pending) { in twl4030_usb_irq()
593 twl->musb_mailbox_pending = false; in twl4030_usb_irq()
597 if (status == MUSB_ID_GROUND && pm_runtime_active(twl->dev)) { in twl4030_usb_irq()
598 cancel_delayed_work(&twl->id_workaround_work); in twl4030_usb_irq()
599 schedule_delayed_work(&twl->id_workaround_work, HZ); in twl4030_usb_irq()
603 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); in twl4030_usb_irq()
610 struct twl4030_usb *twl = container_of(work, struct twl4030_usb, in twl4030_id_workaround_work() local
613 twl4030_usb_irq(0, twl); in twl4030_id_workaround_work()
618 struct twl4030_usb *twl = phy_get_drvdata(phy); in twl4030_phy_init() local
620 pm_runtime_get_sync(twl->dev); in twl4030_phy_init()
621 twl->linkstat = MUSB_UNKNOWN; in twl4030_phy_init()
622 schedule_delayed_work(&twl->id_workaround_work, HZ); in twl4030_phy_init()
623 pm_runtime_mark_last_busy(twl->dev); in twl4030_phy_init()
624 pm_runtime_put_autosuspend(twl->dev); in twl4030_phy_init()
670 struct twl4030_usb *twl; in twl4030_usb_probe() local
677 twl = devm_kzalloc(&pdev->dev, sizeof(*twl), GFP_KERNEL); in twl4030_usb_probe()
678 if (!twl) in twl4030_usb_probe()
683 (enum twl4030_usb_mode *)&twl->usb_mode); in twl4030_usb_probe()
685 twl->usb_mode = pdata->usb_mode; in twl4030_usb_probe()
695 twl->dev = &pdev->dev; in twl4030_usb_probe()
696 twl->irq = platform_get_irq(pdev, 0); in twl4030_usb_probe()
697 twl->vbus_supplied = false; in twl4030_usb_probe()
698 twl->linkstat = MUSB_UNKNOWN; in twl4030_usb_probe()
699 twl->musb_mailbox_pending = false; in twl4030_usb_probe()
701 twl->phy.dev = twl->dev; in twl4030_usb_probe()
702 twl->phy.label = "twl4030"; in twl4030_usb_probe()
703 twl->phy.otg = otg; in twl4030_usb_probe()
704 twl->phy.type = USB_PHY_TYPE_USB2; in twl4030_usb_probe()
706 otg->usb_phy = &twl->phy; in twl4030_usb_probe()
710 phy = devm_phy_create(twl->dev, NULL, &ops); in twl4030_usb_probe()
716 phy_set_drvdata(phy, twl); in twl4030_usb_probe()
718 phy_provider = devm_of_phy_provider_register(twl->dev, in twl4030_usb_probe()
724 mutex_init(&twl->lock); in twl4030_usb_probe()
726 INIT_DELAYED_WORK(&twl->id_workaround_work, twl4030_id_workaround_work); in twl4030_usb_probe()
728 err = twl4030_usb_ldo_init(twl); in twl4030_usb_probe()
733 usb_add_phy_dev(&twl->phy); in twl4030_usb_probe()
735 platform_set_drvdata(pdev, twl); in twl4030_usb_probe()
739 ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier); in twl4030_usb_probe()
754 status = devm_request_threaded_irq(twl->dev, twl->irq, NULL, in twl4030_usb_probe()
756 IRQF_TRIGGER_RISING | IRQF_ONESHOT, "twl4030_usb", twl); in twl4030_usb_probe()
759 twl->irq, status); in twl4030_usb_probe()
769 pm_runtime_put_autosuspend(twl->dev); in twl4030_usb_probe()
777 struct twl4030_usb *twl = platform_get_drvdata(pdev); in twl4030_usb_remove() local
780 usb_remove_phy(&twl->phy); in twl4030_usb_remove()
781 pm_runtime_get_sync(twl->dev); in twl4030_usb_remove()
782 cancel_delayed_work_sync(&twl->id_workaround_work); in twl4030_usb_remove()
783 device_remove_file(twl->dev, &dev_attr_vbus); in twl4030_usb_remove()
786 twl4030_usb_set_mode(twl, -1); in twl4030_usb_remove()
789 if (cable_present(twl->linkstat)) in twl4030_usb_remove()
790 pm_runtime_put_noidle(twl->dev); in twl4030_usb_remove()
791 pm_runtime_mark_last_busy(twl->dev); in twl4030_usb_remove()
793 pm_runtime_put_sync(twl->dev); in twl4030_usb_remove()
794 pm_runtime_disable(twl->dev); in twl4030_usb_remove()
800 val = twl4030_usb_read(twl, PHY_CLK_CTRL); in twl4030_usb_remove()
804 twl4030_usb_write(twl, PHY_CLK_CTRL, (u8)val); in twl4030_usb_remove()
808 twl4030_usb_clear_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB); in twl4030_usb_remove()