Lines Matching refs:twl
27 #include <linux/mfd/twl.h>
177 static int twl4030_i2c_write_u8_verify(struct twl4030_usb *twl,
186 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n",
194 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n",
201 #define twl4030_usb_write_verify(twl, address, data) \
202 twl4030_i2c_write_u8_verify(twl, TWL_MODULE_USB, (data), (address))
204 static inline int twl4030_usb_write(struct twl4030_usb *twl,
211 dev_dbg(twl->dev,
216 static inline int twl4030_readb(struct twl4030_usb *twl, u8 module, u8 address)
225 dev_dbg(twl->dev,
232 static inline int twl4030_usb_read(struct twl4030_usb *twl, u8 address)
234 return twl4030_readb(twl, TWL_MODULE_USB, address);
240 twl4030_usb_set_bits(struct twl4030_usb *twl, u8 reg, u8 bits)
242 return twl4030_usb_write(twl, ULPI_SET(reg), bits);
246 twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits)
248 return twl4030_usb_write(twl, ULPI_CLR(reg), bits);
253 static bool twl4030_is_driving_vbus(struct twl4030_usb *twl)
257 ret = twl4030_usb_read(twl, PHY_CLK_CTRL_STS);
265 ret = twl4030_usb_read(twl, ULPI_OTG_CTRL);
273 twl4030_usb_linkstat(struct twl4030_usb *twl)
278 twl->vbus_supplied = false;
290 status = twl4030_readb(twl, TWL_MODULE_PM_MASTER, STS_HW_CONDITIONS);
292 dev_err(twl->dev, "USB link status err %d\n", status);
295 if (twl4030_is_driving_vbus(twl))
298 twl->vbus_supplied = true;
308 if (twl->linkstat != MUSB_UNKNOWN)
312 kobject_uevent(&twl->dev->kobj, linkstat == MUSB_VBUS_VALID
315 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n",
325 static void twl4030_usb_set_mode(struct twl4030_usb *twl, int mode)
327 twl->usb_mode = mode;
331 twl4030_usb_clear_bits(twl, ULPI_IFC_CTRL,
333 twl4030_usb_set_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB);
334 twl4030_usb_clear_bits(twl, ULPI_FUNC_CTRL,
342 dev_err(twl->dev, "unsupported T2 transceiver mode %d\n",
348 static void twl4030_i2c_access(struct twl4030_usb *twl, int on)
351 int val = twl4030_usb_read(twl, PHY_CLK_CTRL);
357 WARN_ON(twl4030_usb_write_verify(twl, PHY_CLK_CTRL,
361 while (!(twl4030_usb_read(twl, PHY_CLK_CTRL_STS) &
365 if (!(twl4030_usb_read(twl, PHY_CLK_CTRL_STS) &
367 dev_err(twl->dev, "Timeout setting T2 HSUSB "
372 WARN_ON(twl4030_usb_write_verify(twl, PHY_CLK_CTRL,
378 static void __twl4030_phy_power(struct twl4030_usb *twl, int on)
380 u8 pwr = twl4030_usb_read(twl, PHY_PWR_CTRL);
387 WARN_ON(twl4030_usb_write_verify(twl, PHY_PWR_CTRL, pwr) < 0);
395 struct twl4030_usb *twl = dev_get_drvdata(dev);
402 dev_dbg(twl->dev, "%s\n", __func__);
403 disable_irq(twl->irq);
404 if (!twl->runtime_suspended && !atomic_read(&twl->connected)) {
406 twl->needs_resume = 1;
414 struct twl4030_usb *twl = dev_get_drvdata(dev);
416 dev_dbg(twl->dev, "%s\n", __func__);
417 enable_irq(twl->irq);
418 if (twl->needs_resume)
421 twl4030_usb_irq(0, twl);
423 twl->runtime_suspended = 0;
430 struct twl4030_usb *twl = dev_get_drvdata(dev);
432 dev_dbg(twl->dev, "%s\n", __func__);
434 __twl4030_phy_power(twl, 0);
435 regulator_disable(twl->usb1v5);
436 regulator_disable(twl->usb1v8);
437 regulator_disable(twl->usb3v1);
439 twl->runtime_suspended = 1;
446 struct twl4030_usb *twl = dev_get_drvdata(dev);
449 dev_dbg(twl->dev, "%s\n", __func__);
451 res = regulator_enable(twl->usb3v1);
453 dev_err(twl->dev, "Failed to enable usb3v1\n");
455 res = regulator_enable(twl->usb1v8);
457 dev_err(twl->dev, "Failed to enable usb1v8\n");
468 res = regulator_enable(twl->usb1v5);
470 dev_err(twl->dev, "Failed to enable usb1v5\n");
472 __twl4030_phy_power(twl, 1);
473 twl4030_usb_write(twl, PHY_CLK_CTRL,
474 twl4030_usb_read(twl, PHY_CLK_CTRL) |
478 twl4030_i2c_access(twl, 1);
479 twl4030_usb_set_mode(twl, twl->usb_mode);
480 if (twl->usb_mode == T2_USB_MODE_ULPI)
481 twl4030_i2c_access(twl, 0);
494 struct twl4030_usb *twl = phy_get_drvdata(phy);
496 dev_dbg(twl->dev, "%s\n", __func__);
503 struct twl4030_usb *twl = phy_get_drvdata(phy);
505 dev_dbg(twl->dev, "%s\n", __func__);
506 pm_runtime_get_sync(twl->dev);
507 schedule_delayed_work(&twl->id_workaround_work, HZ);
508 pm_runtime_mark_last_busy(twl->dev);
509 pm_runtime_put_autosuspend(twl->dev);
514 static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
532 twl->usb3v1 = devm_regulator_get(twl->dev, "usb3v1");
533 if (IS_ERR(twl->usb3v1))
541 twl->usb1v5 = devm_regulator_get(twl->dev, "usb1v5");
542 if (IS_ERR(twl->usb1v5))
550 twl->usb1v8 = devm_regulator_get(twl->dev, "usb1v8");
551 if (IS_ERR(twl->usb1v8))
566 struct twl4030_usb *twl = dev_get_drvdata(dev);
569 mutex_lock(&twl->lock);
571 twl->vbus_supplied ? "on" : "off");
572 mutex_unlock(&twl->lock);
580 struct twl4030_usb *twl = _twl;
584 status = twl4030_usb_linkstat(twl);
586 mutex_lock(&twl->lock);
587 twl->linkstat = status;
588 mutex_unlock(&twl->lock);
591 if (atomic_add_unless(&twl->connected, 1, 1)) {
592 dev_dbg(twl->dev, "%s: cable connected %i\n",
594 pm_runtime_get_sync(twl->dev);
595 twl->musb_mailbox_pending = true;
598 if (atomic_add_unless(&twl->connected, -1, 0)) {
599 dev_dbg(twl->dev, "%s: cable disconnected %i\n",
601 pm_runtime_mark_last_busy(twl->dev);
602 pm_runtime_put_autosuspend(twl->dev);
603 twl->musb_mailbox_pending = true;
606 if (twl->musb_mailbox_pending) {
609 twl->musb_mailbox_pending = false;
613 if (status == MUSB_ID_GROUND && pm_runtime_active(twl->dev)) {
614 cancel_delayed_work(&twl->id_workaround_work);
615 schedule_delayed_work(&twl->id_workaround_work, HZ);
619 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
626 struct twl4030_usb *twl = container_of(work, struct twl4030_usb,
629 twl4030_usb_irq(0, twl);
634 struct twl4030_usb *twl = phy_get_drvdata(phy);
636 pm_runtime_get_sync(twl->dev);
637 twl->linkstat = MUSB_UNKNOWN;
638 schedule_delayed_work(&twl->id_workaround_work, HZ);
639 pm_runtime_mark_last_busy(twl->dev);
640 pm_runtime_put_autosuspend(twl->dev);
686 struct twl4030_usb *twl;
693 twl = devm_kzalloc(&pdev->dev, sizeof(*twl), GFP_KERNEL);
694 if (!twl)
699 (enum twl4030_usb_mode *)&twl->usb_mode);
701 twl->usb_mode = pdata->usb_mode;
711 twl->dev = &pdev->dev;
712 twl->irq = platform_get_irq(pdev, 0);
713 twl->vbus_supplied = false;
714 twl->linkstat = MUSB_UNKNOWN;
715 twl->musb_mailbox_pending = false;
717 twl->phy.dev = twl->dev;
718 twl->phy.label = "twl4030";
719 twl->phy.otg = otg;
720 twl->phy.type = USB_PHY_TYPE_USB2;
722 otg->usb_phy = &twl->phy;
726 phy = devm_phy_create(twl->dev, NULL, &ops);
732 phy_set_drvdata(phy, twl);
734 phy_provider = devm_of_phy_provider_register(twl->dev,
740 mutex_init(&twl->lock);
742 INIT_DELAYED_WORK(&twl->id_workaround_work, twl4030_id_workaround_work);
744 err = twl4030_usb_ldo_init(twl);
749 usb_add_phy_dev(&twl->phy);
751 platform_set_drvdata(pdev, twl);
755 ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier);
770 status = devm_request_threaded_irq(twl->dev, twl->irq, NULL,
772 IRQF_TRIGGER_RISING | IRQF_ONESHOT, "twl4030_usb", twl);
775 twl->irq, status);
785 pm_runtime_put_autosuspend(twl->dev);
793 struct twl4030_usb *twl = platform_get_drvdata(pdev);
796 usb_remove_phy(&twl->phy);
797 pm_runtime_get_sync(twl->dev);
798 cancel_delayed_work_sync(&twl->id_workaround_work);
799 device_remove_file(twl->dev, &dev_attr_vbus);
802 twl4030_usb_set_mode(twl, -1);
805 if (cable_present(twl->linkstat))
806 pm_runtime_put_noidle(twl->dev);
807 pm_runtime_mark_last_busy(twl->dev);
809 pm_runtime_put_sync(twl->dev);
810 pm_runtime_disable(twl->dev);
816 val = twl4030_usb_read(twl, PHY_CLK_CTRL);
820 twl4030_usb_write(twl, PHY_CLK_CTRL, (u8)val);
824 twl4030_usb_clear_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB);