Lines Matching refs:twl

184 static int twl4030_i2c_write_u8_verify(struct twl4030_usb *twl,  in twl4030_i2c_write_u8_verify()  argument
193 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n", in twl4030_i2c_write_u8_verify()
201 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n", in twl4030_i2c_write_u8_verify()
208 #define twl4030_usb_write_verify(twl, address, data) \ argument
209 twl4030_i2c_write_u8_verify(twl, TWL_MODULE_USB, (data), (address))
211 static inline int twl4030_usb_write(struct twl4030_usb *twl, in twl4030_usb_write() argument
218 dev_dbg(twl->dev, in twl4030_usb_write()
223 static inline int twl4030_readb(struct twl4030_usb *twl, u8 module, u8 address) in twl4030_readb() argument
232 dev_dbg(twl->dev, in twl4030_readb()
239 static inline int twl4030_usb_read(struct twl4030_usb *twl, u8 address) in twl4030_usb_read() argument
241 return twl4030_readb(twl, TWL_MODULE_USB, address); in twl4030_usb_read()
247 twl4030_usb_set_bits(struct twl4030_usb *twl, u8 reg, u8 bits) in twl4030_usb_set_bits() argument
249 return twl4030_usb_write(twl, ULPI_SET(reg), bits); in twl4030_usb_set_bits()
253 twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits) in twl4030_usb_clear_bits() argument
255 return twl4030_usb_write(twl, ULPI_CLR(reg), bits); in twl4030_usb_clear_bits()
260 static bool twl4030_is_driving_vbus(struct twl4030_usb *twl) in twl4030_is_driving_vbus() argument
264 ret = twl4030_usb_read(twl, PHY_CLK_CTRL_STS); in twl4030_is_driving_vbus()
272 ret = twl4030_usb_read(twl, ULPI_OTG_CTRL); in twl4030_is_driving_vbus()
280 twl4030_usb_linkstat(struct twl4030_usb *twl) in twl4030_usb_linkstat() argument
285 twl->vbus_supplied = false; in twl4030_usb_linkstat()
297 status = twl4030_readb(twl, TWL_MODULE_PM_MASTER, STS_HW_CONDITIONS); in twl4030_usb_linkstat()
299 dev_err(twl->dev, "USB link status err %d\n", status); in twl4030_usb_linkstat()
302 if (twl4030_is_driving_vbus(twl)) in twl4030_usb_linkstat()
305 twl->vbus_supplied = true; in twl4030_usb_linkstat()
315 if (twl->linkstat != OMAP_MUSB_UNKNOWN) in twl4030_usb_linkstat()
319 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", in twl4030_usb_linkstat()
329 static void twl4030_usb_set_mode(struct twl4030_usb *twl, int mode) in twl4030_usb_set_mode() argument
331 twl->usb_mode = mode; in twl4030_usb_set_mode()
335 twl4030_usb_clear_bits(twl, ULPI_IFC_CTRL, in twl4030_usb_set_mode()
337 twl4030_usb_set_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB); in twl4030_usb_set_mode()
338 twl4030_usb_clear_bits(twl, ULPI_FUNC_CTRL, in twl4030_usb_set_mode()
346 dev_err(twl->dev, "unsupported T2 transceiver mode %d\n", in twl4030_usb_set_mode()
352 static void twl4030_i2c_access(struct twl4030_usb *twl, int on) in twl4030_i2c_access() argument
355 int val = twl4030_usb_read(twl, PHY_CLK_CTRL); in twl4030_i2c_access()
361 WARN_ON(twl4030_usb_write_verify(twl, PHY_CLK_CTRL, in twl4030_i2c_access()
365 while (!(twl4030_usb_read(twl, PHY_CLK_CTRL_STS) & in twl4030_i2c_access()
369 if (!(twl4030_usb_read(twl, PHY_CLK_CTRL_STS) & in twl4030_i2c_access()
371 dev_err(twl->dev, "Timeout setting T2 HSUSB " in twl4030_i2c_access()
376 WARN_ON(twl4030_usb_write_verify(twl, PHY_CLK_CTRL, in twl4030_i2c_access()
382 static void __twl4030_phy_power(struct twl4030_usb *twl, int on) in __twl4030_phy_power() argument
384 u8 pwr = twl4030_usb_read(twl, PHY_PWR_CTRL); in __twl4030_phy_power()
391 WARN_ON(twl4030_usb_write_verify(twl, PHY_PWR_CTRL, pwr) < 0); in __twl4030_phy_power()
396 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_runtime_suspend() local
398 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_usb_runtime_suspend()
400 __twl4030_phy_power(twl, 0); in twl4030_usb_runtime_suspend()
401 regulator_disable(twl->usb1v5); in twl4030_usb_runtime_suspend()
402 regulator_disable(twl->usb1v8); in twl4030_usb_runtime_suspend()
403 regulator_disable(twl->usb3v1); in twl4030_usb_runtime_suspend()
410 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_runtime_resume() local
413 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_usb_runtime_resume()
415 res = regulator_enable(twl->usb3v1); in twl4030_usb_runtime_resume()
417 dev_err(twl->dev, "Failed to enable usb3v1\n"); in twl4030_usb_runtime_resume()
419 res = regulator_enable(twl->usb1v8); in twl4030_usb_runtime_resume()
421 dev_err(twl->dev, "Failed to enable usb1v8\n"); in twl4030_usb_runtime_resume()
432 res = regulator_enable(twl->usb1v5); in twl4030_usb_runtime_resume()
434 dev_err(twl->dev, "Failed to enable usb1v5\n"); in twl4030_usb_runtime_resume()
436 __twl4030_phy_power(twl, 1); in twl4030_usb_runtime_resume()
437 twl4030_usb_write(twl, PHY_CLK_CTRL, in twl4030_usb_runtime_resume()
438 twl4030_usb_read(twl, PHY_CLK_CTRL) | in twl4030_usb_runtime_resume()
447 struct twl4030_usb *twl = phy_get_drvdata(phy); in twl4030_phy_power_off() local
449 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_phy_power_off()
450 pm_runtime_mark_last_busy(twl->dev); in twl4030_phy_power_off()
451 pm_runtime_put_autosuspend(twl->dev); in twl4030_phy_power_off()
458 struct twl4030_usb *twl = phy_get_drvdata(phy); in twl4030_phy_power_on() local
460 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_phy_power_on()
461 pm_runtime_get_sync(twl->dev); in twl4030_phy_power_on()
462 twl4030_i2c_access(twl, 1); in twl4030_phy_power_on()
463 twl4030_usb_set_mode(twl, twl->usb_mode); in twl4030_phy_power_on()
464 if (twl->usb_mode == T2_USB_MODE_ULPI) in twl4030_phy_power_on()
465 twl4030_i2c_access(twl, 0); in twl4030_phy_power_on()
466 schedule_delayed_work(&twl->id_workaround_work, 0); in twl4030_phy_power_on()
471 static int twl4030_usb_ldo_init(struct twl4030_usb *twl) in twl4030_usb_ldo_init() argument
489 twl->usb3v1 = devm_regulator_get(twl->dev, "usb3v1"); in twl4030_usb_ldo_init()
490 if (IS_ERR(twl->usb3v1)) in twl4030_usb_ldo_init()
498 twl->usb1v5 = devm_regulator_get(twl->dev, "usb1v5"); in twl4030_usb_ldo_init()
499 if (IS_ERR(twl->usb1v5)) in twl4030_usb_ldo_init()
507 twl->usb1v8 = devm_regulator_get(twl->dev, "usb1v8"); in twl4030_usb_ldo_init()
508 if (IS_ERR(twl->usb1v8)) in twl4030_usb_ldo_init()
523 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_vbus_show() local
526 mutex_lock(&twl->lock); in twl4030_usb_vbus_show()
528 twl->vbus_supplied ? "on" : "off"); in twl4030_usb_vbus_show()
529 mutex_unlock(&twl->lock); in twl4030_usb_vbus_show()
537 struct twl4030_usb *twl = _twl; in twl4030_usb_irq() local
541 status = twl4030_usb_linkstat(twl); in twl4030_usb_irq()
543 mutex_lock(&twl->lock); in twl4030_usb_irq()
544 if (status >= 0 && status != twl->linkstat) { in twl4030_usb_irq()
546 cable_present(twl->linkstat) != in twl4030_usb_irq()
548 twl->linkstat = status; in twl4030_usb_irq()
550 mutex_unlock(&twl->lock); in twl4030_usb_irq()
565 pm_runtime_get_sync(twl->dev); in twl4030_usb_irq()
567 pm_runtime_mark_last_busy(twl->dev); in twl4030_usb_irq()
568 pm_runtime_put_autosuspend(twl->dev); in twl4030_usb_irq()
574 if (status == OMAP_MUSB_ID_GROUND && pm_runtime_active(twl->dev)) { in twl4030_usb_irq()
575 cancel_delayed_work(&twl->id_workaround_work); in twl4030_usb_irq()
576 schedule_delayed_work(&twl->id_workaround_work, HZ); in twl4030_usb_irq()
580 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); in twl4030_usb_irq()
587 struct twl4030_usb *twl = container_of(work, struct twl4030_usb, in twl4030_id_workaround_work() local
590 twl4030_usb_irq(0, twl); in twl4030_id_workaround_work()
595 struct twl4030_usb *twl = phy_get_drvdata(phy); in twl4030_phy_init() local
597 pm_runtime_get_sync(twl->dev); in twl4030_phy_init()
598 schedule_delayed_work(&twl->id_workaround_work, 0); in twl4030_phy_init()
599 pm_runtime_mark_last_busy(twl->dev); in twl4030_phy_init()
600 pm_runtime_put_autosuspend(twl->dev); in twl4030_phy_init()
645 struct twl4030_usb *twl; in twl4030_usb_probe() local
652 twl = devm_kzalloc(&pdev->dev, sizeof(*twl), GFP_KERNEL); in twl4030_usb_probe()
653 if (!twl) in twl4030_usb_probe()
658 (enum twl4030_usb_mode *)&twl->usb_mode); in twl4030_usb_probe()
660 twl->usb_mode = pdata->usb_mode; in twl4030_usb_probe()
670 twl->dev = &pdev->dev; in twl4030_usb_probe()
671 twl->irq = platform_get_irq(pdev, 0); in twl4030_usb_probe()
672 twl->vbus_supplied = false; in twl4030_usb_probe()
673 twl->linkstat = OMAP_MUSB_UNKNOWN; in twl4030_usb_probe()
675 twl->phy.dev = twl->dev; in twl4030_usb_probe()
676 twl->phy.label = "twl4030"; in twl4030_usb_probe()
677 twl->phy.otg = otg; in twl4030_usb_probe()
678 twl->phy.type = USB_PHY_TYPE_USB2; in twl4030_usb_probe()
680 otg->usb_phy = &twl->phy; in twl4030_usb_probe()
684 phy = devm_phy_create(twl->dev, NULL, &ops); in twl4030_usb_probe()
690 phy_set_drvdata(phy, twl); in twl4030_usb_probe()
692 phy_provider = devm_of_phy_provider_register(twl->dev, in twl4030_usb_probe()
698 mutex_init(&twl->lock); in twl4030_usb_probe()
700 INIT_DELAYED_WORK(&twl->id_workaround_work, twl4030_id_workaround_work); in twl4030_usb_probe()
702 err = twl4030_usb_ldo_init(twl); in twl4030_usb_probe()
707 usb_add_phy_dev(&twl->phy); in twl4030_usb_probe()
709 platform_set_drvdata(pdev, twl); in twl4030_usb_probe()
713 ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier); in twl4030_usb_probe()
728 status = devm_request_threaded_irq(twl->dev, twl->irq, NULL, in twl4030_usb_probe()
730 IRQF_TRIGGER_RISING | IRQF_ONESHOT, "twl4030_usb", twl); in twl4030_usb_probe()
733 twl->irq, status); in twl4030_usb_probe()
743 pm_runtime_put_autosuspend(twl->dev); in twl4030_usb_probe()
751 struct twl4030_usb *twl = platform_get_drvdata(pdev); in twl4030_usb_remove() local
754 usb_remove_phy(&twl->phy); in twl4030_usb_remove()
755 pm_runtime_get_sync(twl->dev); in twl4030_usb_remove()
756 cancel_delayed_work(&twl->id_workaround_work); in twl4030_usb_remove()
757 device_remove_file(twl->dev, &dev_attr_vbus); in twl4030_usb_remove()
760 twl4030_usb_set_mode(twl, -1); in twl4030_usb_remove()
763 if (cable_present(twl->linkstat)) in twl4030_usb_remove()
764 pm_runtime_put_noidle(twl->dev); in twl4030_usb_remove()
765 pm_runtime_mark_last_busy(twl->dev); in twl4030_usb_remove()
766 pm_runtime_put_sync_suspend(twl->dev); in twl4030_usb_remove()
767 pm_runtime_disable(twl->dev); in twl4030_usb_remove()
773 val = twl4030_usb_read(twl, PHY_CLK_CTRL); in twl4030_usb_remove()
777 twl4030_usb_write(twl, PHY_CLK_CTRL, (u8)val); in twl4030_usb_remove()
781 twl4030_usb_clear_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB); in twl4030_usb_remove()