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