110-add-platform-driver-support-for-ulpi-phys.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. --- a/drivers/usb/phy/Kconfig
  2. +++ b/drivers/usb/phy/Kconfig
  3. @@ -202,6 +202,7 @@ config USB_RCAR_PHY
  4. config USB_ULPI
  5. bool "Generic ULPI Transceiver Driver"
  6. depends on ARM || ARM64
  7. + depends on USB_PHY
  8. select USB_ULPI_VIEWPORT
  9. help
  10. Enable this to support ULPI connected USB OTG transceivers which
  11. --- a/drivers/usb/phy/phy-ulpi.c
  12. +++ b/drivers/usb/phy/phy-ulpi.c
  13. @@ -26,9 +26,16 @@
  14. #include <linux/kernel.h>
  15. #include <linux/slab.h>
  16. #include <linux/export.h>
  17. +#include <linux/module.h>
  18. +#include <linux/of.h>
  19. +#include <linux/io.h>
  20. +#include <linux/of_address.h>
  21. +#include <linux/of_device.h>
  22. +#include <linux/platform_device.h>
  23. #include <linux/usb.h>
  24. #include <linux/usb/otg.h>
  25. #include <linux/usb/ulpi.h>
  26. +#include <linux/usb/phy.h>
  27. struct ulpi_info {
  28. @@ -52,6 +59,13 @@ static struct ulpi_info ulpi_ids[] = {
  29. ULPI_INFO(ULPI_ID(0x0451, 0x1507), "TI TUSB1210"),
  30. };
  31. +struct ulpi_phy {
  32. + struct usb_phy *usb_phy;
  33. + void __iomem *regs;
  34. + unsigned int vp_offset;
  35. + unsigned int flags;
  36. +};
  37. +
  38. static int ulpi_set_otg_flags(struct usb_phy *phy)
  39. {
  40. unsigned int flags = ULPI_OTG_CTRL_DP_PULLDOWN |
  41. @@ -253,6 +267,23 @@ static int ulpi_set_vbus(struct usb_otg
  42. return usb_phy_io_write(phy, flags, ULPI_OTG_CTRL);
  43. }
  44. +static int usbphy_set_vbus(struct usb_phy *phy, int on)
  45. +{
  46. + unsigned int flags = usb_phy_io_read(phy, ULPI_OTG_CTRL);
  47. +
  48. + flags &= ~(ULPI_OTG_CTRL_DRVVBUS | ULPI_OTG_CTRL_DRVVBUS_EXT);
  49. +
  50. + if (on) {
  51. + if (phy->flags & ULPI_OTG_DRVVBUS)
  52. + flags |= ULPI_OTG_CTRL_DRVVBUS;
  53. +
  54. + if (phy->flags & ULPI_OTG_DRVVBUS_EXT)
  55. + flags |= ULPI_OTG_CTRL_DRVVBUS_EXT;
  56. + }
  57. +
  58. + return usb_phy_io_write(phy, flags, ULPI_OTG_CTRL);
  59. +}
  60. +
  61. struct usb_phy *
  62. otg_ulpi_create(struct usb_phy_io_ops *ops,
  63. unsigned int flags)
  64. @@ -275,6 +306,7 @@ otg_ulpi_create(struct usb_phy_io_ops *o
  65. phy->io_ops = ops;
  66. phy->otg = otg;
  67. phy->init = ulpi_init;
  68. + phy->set_vbus = usbphy_set_vbus;
  69. otg->usb_phy = phy;
  70. otg->set_host = ulpi_set_host;
  71. @@ -284,3 +316,70 @@ otg_ulpi_create(struct usb_phy_io_ops *o
  72. }
  73. EXPORT_SYMBOL_GPL(otg_ulpi_create);
  74. +static int ulpi_phy_probe(struct platform_device *pdev)
  75. +{
  76. + struct device_node *np = pdev->dev.of_node;
  77. + struct resource *res;
  78. + struct ulpi_phy *uphy;
  79. + bool flag;
  80. + int ret;
  81. +
  82. + uphy = devm_kzalloc(&pdev->dev, sizeof(*uphy), GFP_KERNEL);
  83. + if (!uphy)
  84. + return -ENOMEM;
  85. +
  86. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  87. + uphy->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res));
  88. + if (IS_ERR(uphy->regs))
  89. + return PTR_ERR(uphy->regs);
  90. +
  91. + ret = of_property_read_u32(np, "view-port", &uphy->vp_offset);
  92. + if (IS_ERR(uphy->regs)) {
  93. + dev_err(&pdev->dev, "view-port register not specified\n");
  94. + return PTR_ERR(uphy->regs);
  95. + }
  96. +
  97. + flag = of_property_read_bool(np, "drv-vbus");
  98. + if (flag)
  99. + uphy->flags |= ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT;
  100. +
  101. + uphy->usb_phy = otg_ulpi_create(&ulpi_viewport_access_ops, uphy->flags);
  102. +
  103. + uphy->usb_phy->dev = &pdev->dev;
  104. +
  105. + uphy->usb_phy->io_priv = uphy->regs + uphy->vp_offset;
  106. +
  107. + ret = usb_add_phy_dev(uphy->usb_phy);
  108. + if (ret < 0)
  109. + return ret;
  110. +
  111. + return 0;
  112. +}
  113. +
  114. +static int ulpi_phy_remove(struct platform_device *pdev)
  115. +{
  116. + struct ulpi_phy *uphy = platform_get_drvdata(pdev);
  117. +
  118. + usb_remove_phy(uphy->usb_phy);
  119. +
  120. + return 0;
  121. +}
  122. +
  123. +static const struct of_device_id ulpi_phy_table[] = {
  124. + { .compatible = "ulpi-phy" },
  125. + { },
  126. +};
  127. +MODULE_DEVICE_TABLE(of, ulpi_phy_table);
  128. +
  129. +static struct platform_driver ulpi_phy_driver = {
  130. + .probe = ulpi_phy_probe,
  131. + .remove = ulpi_phy_remove,
  132. + .driver = {
  133. + .name = "ulpi-phy",
  134. + .of_match_table = ulpi_phy_table,
  135. + },
  136. +};
  137. +module_platform_driver(ulpi_phy_driver);
  138. +
  139. +MODULE_DESCRIPTION("ULPI PHY driver");
  140. +MODULE_LICENSE("GPL v2");