Lines Matching refs:twl

176 static int twl4030_i2c_write_u8_verify(struct twl4030_usb *twl,  in twl4030_i2c_write_u8_verify()  argument
185 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n", in twl4030_i2c_write_u8_verify()
193 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n", in twl4030_i2c_write_u8_verify()
200 #define twl4030_usb_write_verify(twl, address, data) \ argument
201 twl4030_i2c_write_u8_verify(twl, TWL_MODULE_USB, (data), (address))
203 static inline int twl4030_usb_write(struct twl4030_usb *twl, in twl4030_usb_write() argument
210 dev_dbg(twl->dev, in twl4030_usb_write()
215 static inline int twl4030_readb(struct twl4030_usb *twl, u8 module, u8 address) in twl4030_readb() argument
224 dev_dbg(twl->dev, in twl4030_readb()
231 static inline int twl4030_usb_read(struct twl4030_usb *twl, u8 address) in twl4030_usb_read() argument
233 return twl4030_readb(twl, TWL_MODULE_USB, address); in twl4030_usb_read()
239 twl4030_usb_set_bits(struct twl4030_usb *twl, u8 reg, u8 bits) in twl4030_usb_set_bits() argument
241 return twl4030_usb_write(twl, ULPI_SET(reg), bits); in twl4030_usb_set_bits()
245 twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits) in twl4030_usb_clear_bits() argument
247 return twl4030_usb_write(twl, ULPI_CLR(reg), bits); in twl4030_usb_clear_bits()
252 static bool twl4030_is_driving_vbus(struct twl4030_usb *twl) in twl4030_is_driving_vbus() argument
256 ret = twl4030_usb_read(twl, PHY_CLK_CTRL_STS); in twl4030_is_driving_vbus()
264 ret = twl4030_usb_read(twl, ULPI_OTG_CTRL); in twl4030_is_driving_vbus()
272 twl4030_usb_linkstat(struct twl4030_usb *twl) in twl4030_usb_linkstat() argument
277 twl->vbus_supplied = false; in twl4030_usb_linkstat()
289 status = twl4030_readb(twl, TWL_MODULE_PM_MASTER, STS_HW_CONDITIONS); in twl4030_usb_linkstat()
291 dev_err(twl->dev, "USB link status err %d\n", status); in twl4030_usb_linkstat()
294 if (twl4030_is_driving_vbus(twl)) in twl4030_usb_linkstat()
297 twl->vbus_supplied = true; in twl4030_usb_linkstat()
307 if (twl->linkstat != MUSB_UNKNOWN) in twl4030_usb_linkstat()
311 kobject_uevent(&twl->dev->kobj, linkstat == MUSB_VBUS_VALID in twl4030_usb_linkstat()
314 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", in twl4030_usb_linkstat()
324 static void twl4030_usb_set_mode(struct twl4030_usb *twl, int mode) in twl4030_usb_set_mode() argument
326 twl->usb_mode = mode; in twl4030_usb_set_mode()
330 twl4030_usb_clear_bits(twl, ULPI_IFC_CTRL, in twl4030_usb_set_mode()
332 twl4030_usb_set_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB); in twl4030_usb_set_mode()
333 twl4030_usb_clear_bits(twl, ULPI_FUNC_CTRL, in twl4030_usb_set_mode()
341 dev_err(twl->dev, "unsupported T2 transceiver mode %d\n", in twl4030_usb_set_mode()
347 static void twl4030_i2c_access(struct twl4030_usb *twl, int on) in twl4030_i2c_access() argument
350 int val = twl4030_usb_read(twl, PHY_CLK_CTRL); in twl4030_i2c_access()
356 WARN_ON(twl4030_usb_write_verify(twl, PHY_CLK_CTRL, in twl4030_i2c_access()
360 while (!(twl4030_usb_read(twl, PHY_CLK_CTRL_STS) & in twl4030_i2c_access()
364 if (!(twl4030_usb_read(twl, PHY_CLK_CTRL_STS) & in twl4030_i2c_access()
366 dev_err(twl->dev, "Timeout setting T2 HSUSB " in twl4030_i2c_access()
371 WARN_ON(twl4030_usb_write_verify(twl, PHY_CLK_CTRL, in twl4030_i2c_access()
377 static void __twl4030_phy_power(struct twl4030_usb *twl, int on) in __twl4030_phy_power() argument
379 u8 pwr = twl4030_usb_read(twl, PHY_PWR_CTRL); in __twl4030_phy_power()
386 WARN_ON(twl4030_usb_write_verify(twl, PHY_PWR_CTRL, pwr) < 0); in __twl4030_phy_power()
394 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_suspend() local
401 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_usb_suspend()
402 disable_irq(twl->irq); in twl4030_usb_suspend()
403 if (!twl->runtime_suspended && !atomic_read(&twl->connected)) { in twl4030_usb_suspend()
405 twl->needs_resume = 1; in twl4030_usb_suspend()
413 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_resume() local
415 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_usb_resume()
416 enable_irq(twl->irq); in twl4030_usb_resume()
417 if (twl->needs_resume) in twl4030_usb_resume()
420 twl4030_usb_irq(0, twl); in twl4030_usb_resume()
422 twl->runtime_suspended = 0; in twl4030_usb_resume()
429 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_runtime_suspend() local
431 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_usb_runtime_suspend()
433 __twl4030_phy_power(twl, 0); in twl4030_usb_runtime_suspend()
434 regulator_disable(twl->usb1v5); in twl4030_usb_runtime_suspend()
435 regulator_disable(twl->usb1v8); in twl4030_usb_runtime_suspend()
436 regulator_disable(twl->usb3v1); in twl4030_usb_runtime_suspend()
438 twl->runtime_suspended = 1; in twl4030_usb_runtime_suspend()
445 struct twl4030_usb *twl = dev_get_drvdata(dev); in twl4030_usb_runtime_resume() local
448 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_usb_runtime_resume()
450 res = regulator_enable(twl->usb3v1); in twl4030_usb_runtime_resume()
452 dev_err(twl->dev, "Failed to enable usb3v1\n"); in twl4030_usb_runtime_resume()
454 res = regulator_enable(twl->usb1v8); in twl4030_usb_runtime_resume()
456 dev_err(twl->dev, "Failed to enable usb1v8\n"); in twl4030_usb_runtime_resume()
467 res = regulator_enable(twl->usb1v5); in twl4030_usb_runtime_resume()
469 dev_err(twl->dev, "Failed to enable usb1v5\n"); in twl4030_usb_runtime_resume()
471 __twl4030_phy_power(twl, 1); in twl4030_usb_runtime_resume()
472 twl4030_usb_write(twl, PHY_CLK_CTRL, in twl4030_usb_runtime_resume()
473 twl4030_usb_read(twl, PHY_CLK_CTRL) | in twl4030_usb_runtime_resume()
477 twl4030_i2c_access(twl, 1); in twl4030_usb_runtime_resume()
478 twl4030_usb_set_mode(twl, twl->usb_mode); in twl4030_usb_runtime_resume()
479 if (twl->usb_mode == T2_USB_MODE_ULPI) in twl4030_usb_runtime_resume()
480 twl4030_i2c_access(twl, 0); in twl4030_usb_runtime_resume()
493 struct twl4030_usb *twl = phy_get_drvdata(phy); in twl4030_phy_power_off() local
495 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_phy_power_off()
502 struct twl4030_usb *twl = phy_get_drvdata(phy); in twl4030_phy_power_on() local
504 dev_dbg(twl->dev, "%s\n", __func__); in twl4030_phy_power_on()
505 pm_runtime_get_sync(twl->dev); in twl4030_phy_power_on()
506 schedule_delayed_work(&twl->id_workaround_work, HZ); in twl4030_phy_power_on()
507 pm_runtime_mark_last_busy(twl->dev); in twl4030_phy_power_on()
508 pm_runtime_put_autosuspend(twl->dev); in twl4030_phy_power_on()
513 static int twl4030_usb_ldo_init(struct twl4030_usb *twl) in twl4030_usb_ldo_init() argument
531 twl->usb3v1 = devm_regulator_get(twl->dev, "usb3v1"); in twl4030_usb_ldo_init()
532 if (IS_ERR(twl->usb3v1)) in twl4030_usb_ldo_init()
540 twl->usb1v5 = devm_regulator_get(twl->dev, "usb1v5"); in twl4030_usb_ldo_init()
541 if (IS_ERR(twl->usb1v5)) in twl4030_usb_ldo_init()
549 twl->usb1v8 = devm_regulator_get(twl->dev, "usb1v8"); in twl4030_usb_ldo_init()
550 if (IS_ERR(twl->usb1v8)) in twl4030_usb_ldo_init()
565 struct twl4030_usb *twl = dev_get_drvdata(dev); in vbus_show() local
568 mutex_lock(&twl->lock); in vbus_show()
570 twl->vbus_supplied ? "on" : "off"); in vbus_show()
571 mutex_unlock(&twl->lock); in vbus_show()
579 struct twl4030_usb *twl = _twl; in twl4030_usb_irq() local
583 status = twl4030_usb_linkstat(twl); in twl4030_usb_irq()
585 mutex_lock(&twl->lock); in twl4030_usb_irq()
586 twl->linkstat = status; in twl4030_usb_irq()
587 mutex_unlock(&twl->lock); in twl4030_usb_irq()
590 if (atomic_add_unless(&twl->connected, 1, 1)) { in twl4030_usb_irq()
591 dev_dbg(twl->dev, "%s: cable connected %i\n", in twl4030_usb_irq()
593 pm_runtime_get_sync(twl->dev); in twl4030_usb_irq()
594 twl->musb_mailbox_pending = true; in twl4030_usb_irq()
597 if (atomic_add_unless(&twl->connected, -1, 0)) { in twl4030_usb_irq()
598 dev_dbg(twl->dev, "%s: cable disconnected %i\n", in twl4030_usb_irq()
600 pm_runtime_mark_last_busy(twl->dev); in twl4030_usb_irq()
601 pm_runtime_put_autosuspend(twl->dev); in twl4030_usb_irq()
602 twl->musb_mailbox_pending = true; in twl4030_usb_irq()
605 if (twl->musb_mailbox_pending) { in twl4030_usb_irq()
608 twl->musb_mailbox_pending = false; in twl4030_usb_irq()
612 if (status == MUSB_ID_GROUND && pm_runtime_active(twl->dev)) { in twl4030_usb_irq()
613 cancel_delayed_work(&twl->id_workaround_work); in twl4030_usb_irq()
614 schedule_delayed_work(&twl->id_workaround_work, HZ); in twl4030_usb_irq()
618 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); in twl4030_usb_irq()
625 struct twl4030_usb *twl = container_of(work, struct twl4030_usb, in twl4030_id_workaround_work() local
628 twl4030_usb_irq(0, twl); in twl4030_id_workaround_work()
633 struct twl4030_usb *twl = phy_get_drvdata(phy); in twl4030_phy_init() local
635 pm_runtime_get_sync(twl->dev); in twl4030_phy_init()
636 twl->linkstat = MUSB_UNKNOWN; in twl4030_phy_init()
637 schedule_delayed_work(&twl->id_workaround_work, HZ); in twl4030_phy_init()
638 pm_runtime_mark_last_busy(twl->dev); in twl4030_phy_init()
639 pm_runtime_put_autosuspend(twl->dev); in twl4030_phy_init()
685 struct twl4030_usb *twl; in twl4030_usb_probe() local
692 twl = devm_kzalloc(&pdev->dev, sizeof(*twl), GFP_KERNEL); in twl4030_usb_probe()
693 if (!twl) in twl4030_usb_probe()
698 (enum twl4030_usb_mode *)&twl->usb_mode); in twl4030_usb_probe()
700 twl->usb_mode = pdata->usb_mode; in twl4030_usb_probe()
710 twl->dev = &pdev->dev; in twl4030_usb_probe()
711 twl->irq = platform_get_irq(pdev, 0); in twl4030_usb_probe()
712 twl->vbus_supplied = false; in twl4030_usb_probe()
713 twl->linkstat = MUSB_UNKNOWN; in twl4030_usb_probe()
714 twl->musb_mailbox_pending = false; in twl4030_usb_probe()
716 twl->phy.dev = twl->dev; in twl4030_usb_probe()
717 twl->phy.label = "twl4030"; in twl4030_usb_probe()
718 twl->phy.otg = otg; in twl4030_usb_probe()
719 twl->phy.type = USB_PHY_TYPE_USB2; in twl4030_usb_probe()
721 otg->usb_phy = &twl->phy; in twl4030_usb_probe()
725 phy = devm_phy_create(twl->dev, NULL, &ops); in twl4030_usb_probe()
731 phy_set_drvdata(phy, twl); in twl4030_usb_probe()
733 phy_provider = devm_of_phy_provider_register(twl->dev, in twl4030_usb_probe()
739 mutex_init(&twl->lock); in twl4030_usb_probe()
741 INIT_DELAYED_WORK(&twl->id_workaround_work, twl4030_id_workaround_work); in twl4030_usb_probe()
743 err = twl4030_usb_ldo_init(twl); in twl4030_usb_probe()
748 usb_add_phy_dev(&twl->phy); in twl4030_usb_probe()
750 platform_set_drvdata(pdev, twl); in twl4030_usb_probe()
754 ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier); in twl4030_usb_probe()
769 status = devm_request_threaded_irq(twl->dev, twl->irq, NULL, in twl4030_usb_probe()
771 IRQF_TRIGGER_RISING | IRQF_ONESHOT, "twl4030_usb", twl); in twl4030_usb_probe()
774 twl->irq, status); in twl4030_usb_probe()
784 pm_runtime_put_autosuspend(twl->dev); in twl4030_usb_probe()
792 struct twl4030_usb *twl = platform_get_drvdata(pdev); in twl4030_usb_remove() local
795 usb_remove_phy(&twl->phy); in twl4030_usb_remove()
796 pm_runtime_get_sync(twl->dev); in twl4030_usb_remove()
797 cancel_delayed_work_sync(&twl->id_workaround_work); in twl4030_usb_remove()
798 device_remove_file(twl->dev, &dev_attr_vbus); in twl4030_usb_remove()
801 twl4030_usb_set_mode(twl, -1); in twl4030_usb_remove()
804 if (cable_present(twl->linkstat)) in twl4030_usb_remove()
805 pm_runtime_put_noidle(twl->dev); in twl4030_usb_remove()
806 pm_runtime_mark_last_busy(twl->dev); in twl4030_usb_remove()
808 pm_runtime_put_sync(twl->dev); in twl4030_usb_remove()
809 pm_runtime_disable(twl->dev); in twl4030_usb_remove()
815 val = twl4030_usb_read(twl, PHY_CLK_CTRL); in twl4030_usb_remove()
819 twl4030_usb_write(twl, PHY_CLK_CTRL, (u8)val); in twl4030_usb_remove()
823 twl4030_usb_clear_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB); in twl4030_usb_remove()