phy-am335x.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include <linux/module.h>
  2. #include <linux/platform_device.h>
  3. #include <linux/dma-mapping.h>
  4. #include <linux/usb/otg.h>
  5. #include <linux/usb/usb_phy_gen_xceiv.h>
  6. #include <linux/slab.h>
  7. #include <linux/clk.h>
  8. #include <linux/regulator/consumer.h>
  9. #include <linux/of.h>
  10. #include <linux/of_address.h>
  11. #include "am35x-phy-control.h"
  12. #include "phy-generic.h"
  13. struct am335x_phy {
  14. struct usb_phy_gen_xceiv usb_phy_gen;
  15. struct phy_control *phy_ctrl;
  16. int id;
  17. };
  18. static int am335x_init(struct usb_phy *phy)
  19. {
  20. struct am335x_phy *am_phy = dev_get_drvdata(phy->dev);
  21. phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true);
  22. return 0;
  23. }
  24. static void am335x_shutdown(struct usb_phy *phy)
  25. {
  26. struct am335x_phy *am_phy = dev_get_drvdata(phy->dev);
  27. phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false);
  28. }
  29. static int am335x_phy_probe(struct platform_device *pdev)
  30. {
  31. struct am335x_phy *am_phy;
  32. struct device *dev = &pdev->dev;
  33. int ret;
  34. am_phy = devm_kzalloc(dev, sizeof(*am_phy), GFP_KERNEL);
  35. if (!am_phy)
  36. return -ENOMEM;
  37. am_phy->phy_ctrl = am335x_get_phy_control(dev);
  38. if (!am_phy->phy_ctrl)
  39. return -EPROBE_DEFER;
  40. am_phy->id = of_alias_get_id(pdev->dev.of_node, "phy");
  41. if (am_phy->id < 0) {
  42. dev_err(&pdev->dev, "Missing PHY id: %d\n", am_phy->id);
  43. return am_phy->id;
  44. }
  45. ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen,
  46. USB_PHY_TYPE_USB2, 0, false);
  47. if (ret)
  48. return ret;
  49. ret = usb_add_phy_dev(&am_phy->usb_phy_gen.phy);
  50. if (ret)
  51. return ret;
  52. am_phy->usb_phy_gen.phy.init = am335x_init;
  53. am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown;
  54. platform_set_drvdata(pdev, am_phy);
  55. return 0;
  56. return ret;
  57. }
  58. static int am335x_phy_remove(struct platform_device *pdev)
  59. {
  60. struct am335x_phy *am_phy = platform_get_drvdata(pdev);
  61. usb_remove_phy(&am_phy->usb_phy_gen.phy);
  62. return 0;
  63. }
  64. #ifdef CONFIG_PM_RUNTIME
  65. static int am335x_phy_runtime_suspend(struct device *dev)
  66. {
  67. struct platform_device *pdev = to_platform_device(dev);
  68. struct am335x_phy *am_phy = platform_get_drvdata(pdev);
  69. if (device_may_wakeup(dev))
  70. phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true);
  71. phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false);
  72. return 0;
  73. }
  74. static int am335x_phy_runtime_resume(struct device *dev)
  75. {
  76. struct platform_device *pdev = to_platform_device(dev);
  77. struct am335x_phy *am_phy = platform_get_drvdata(pdev);
  78. phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true);
  79. if (device_may_wakeup(dev))
  80. phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false);
  81. return 0;
  82. }
  83. static const struct dev_pm_ops am335x_pm_ops = {
  84. SET_RUNTIME_PM_OPS(am335x_phy_runtime_suspend,
  85. am335x_phy_runtime_resume, NULL)
  86. };
  87. #define DEV_PM_OPS (&am335x_pm_ops)
  88. #else
  89. #define DEV_PM_OPS NULL
  90. #endif
  91. static const struct of_device_id am335x_phy_ids[] = {
  92. { .compatible = "ti,am335x-usb-phy" },
  93. { }
  94. };
  95. MODULE_DEVICE_TABLE(of, am335x_phy_ids);
  96. static struct platform_driver am335x_phy_driver = {
  97. .probe = am335x_phy_probe,
  98. .remove = am335x_phy_remove,
  99. .driver = {
  100. .name = "am335x-phy-driver",
  101. .owner = THIS_MODULE,
  102. .pm = DEV_PM_OPS,
  103. .of_match_table = am335x_phy_ids,
  104. },
  105. };
  106. module_platform_driver(am335x_phy_driver);
  107. MODULE_LICENSE("GPL v2");