phy-keystone.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * phy-keystone - USB PHY, talking to dwc3 controller in Keystone.
  3. *
  4. * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Author: WingMan Kwok <w-kwok2@ti.com>
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. */
  18. #include <linux/module.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/usb/usb_phy_generic.h>
  21. #include <linux/io.h>
  22. #include <linux/of.h>
  23. #include "phy-generic.h"
  24. /* USB PHY control register offsets */
  25. #define USB_PHY_CTL_UTMI 0x0000
  26. #define USB_PHY_CTL_PIPE 0x0004
  27. #define USB_PHY_CTL_PARAM_1 0x0008
  28. #define USB_PHY_CTL_PARAM_2 0x000c
  29. #define USB_PHY_CTL_CLOCK 0x0010
  30. #define USB_PHY_CTL_PLL 0x0014
  31. #define PHY_REF_SSP_EN BIT(29)
  32. struct keystone_usbphy {
  33. struct usb_phy_generic usb_phy_gen;
  34. void __iomem *phy_ctrl;
  35. };
  36. static inline u32 keystone_usbphy_readl(void __iomem *base, u32 offset)
  37. {
  38. return readl(base + offset);
  39. }
  40. static inline void keystone_usbphy_writel(void __iomem *base,
  41. u32 offset, u32 value)
  42. {
  43. writel(value, base + offset);
  44. }
  45. static int keystone_usbphy_init(struct usb_phy *phy)
  46. {
  47. struct keystone_usbphy *k_phy = dev_get_drvdata(phy->dev);
  48. u32 val;
  49. val = keystone_usbphy_readl(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK);
  50. keystone_usbphy_writel(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK,
  51. val | PHY_REF_SSP_EN);
  52. return 0;
  53. }
  54. static void keystone_usbphy_shutdown(struct usb_phy *phy)
  55. {
  56. struct keystone_usbphy *k_phy = dev_get_drvdata(phy->dev);
  57. u32 val;
  58. val = keystone_usbphy_readl(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK);
  59. keystone_usbphy_writel(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK,
  60. val &= ~PHY_REF_SSP_EN);
  61. }
  62. static int keystone_usbphy_probe(struct platform_device *pdev)
  63. {
  64. struct device *dev = &pdev->dev;
  65. struct keystone_usbphy *k_phy;
  66. struct resource *res;
  67. int ret;
  68. k_phy = devm_kzalloc(dev, sizeof(*k_phy), GFP_KERNEL);
  69. if (!k_phy)
  70. return -ENOMEM;
  71. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  72. k_phy->phy_ctrl = devm_ioremap_resource(dev, res);
  73. if (IS_ERR(k_phy->phy_ctrl))
  74. return PTR_ERR(k_phy->phy_ctrl);
  75. ret = usb_phy_gen_create_phy(dev, &k_phy->usb_phy_gen, NULL);
  76. if (ret)
  77. return ret;
  78. k_phy->usb_phy_gen.phy.init = keystone_usbphy_init;
  79. k_phy->usb_phy_gen.phy.shutdown = keystone_usbphy_shutdown;
  80. platform_set_drvdata(pdev, k_phy);
  81. return usb_add_phy_dev(&k_phy->usb_phy_gen.phy);
  82. }
  83. static int keystone_usbphy_remove(struct platform_device *pdev)
  84. {
  85. struct keystone_usbphy *k_phy = platform_get_drvdata(pdev);
  86. usb_remove_phy(&k_phy->usb_phy_gen.phy);
  87. return 0;
  88. }
  89. static const struct of_device_id keystone_usbphy_ids[] = {
  90. { .compatible = "ti,keystone-usbphy" },
  91. { }
  92. };
  93. MODULE_DEVICE_TABLE(of, keystone_usbphy_ids);
  94. static struct platform_driver keystone_usbphy_driver = {
  95. .probe = keystone_usbphy_probe,
  96. .remove = keystone_usbphy_remove,
  97. .driver = {
  98. .name = "keystone-usbphy",
  99. .of_match_table = keystone_usbphy_ids,
  100. },
  101. };
  102. module_platform_driver(keystone_usbphy_driver);
  103. MODULE_ALIAS("platform:keystone-usbphy");
  104. MODULE_AUTHOR("Texas Instruments Inc.");
  105. MODULE_DESCRIPTION("Keystone USB phy driver");
  106. MODULE_LICENSE("GPL v2");