phy-mmp3-hsic.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2020 Lubomir Rintel <lkundrak@v3.sk>
  4. */
  5. #include <linux/delay.h>
  6. #include <linux/io.h>
  7. #include <linux/mod_devicetable.h>
  8. #include <linux/module.h>
  9. #include <linux/phy/phy.h>
  10. #include <linux/platform_device.h>
  11. #define HSIC_CTRL 0x08
  12. #define HSIC_ENABLE BIT(7)
  13. #define PLL_BYPASS BIT(4)
  14. static int mmp3_hsic_phy_init(struct phy *phy)
  15. {
  16. void __iomem *base = (void __iomem *)phy_get_drvdata(phy);
  17. u32 hsic_ctrl;
  18. hsic_ctrl = readl_relaxed(base + HSIC_CTRL);
  19. hsic_ctrl |= HSIC_ENABLE;
  20. hsic_ctrl |= PLL_BYPASS;
  21. writel_relaxed(hsic_ctrl, base + HSIC_CTRL);
  22. return 0;
  23. }
  24. static const struct phy_ops mmp3_hsic_phy_ops = {
  25. .init = mmp3_hsic_phy_init,
  26. .owner = THIS_MODULE,
  27. };
  28. static const struct of_device_id mmp3_hsic_phy_of_match[] = {
  29. { .compatible = "marvell,mmp3-hsic-phy", },
  30. { },
  31. };
  32. MODULE_DEVICE_TABLE(of, mmp3_hsic_phy_of_match);
  33. static int mmp3_hsic_phy_probe(struct platform_device *pdev)
  34. {
  35. struct device *dev = &pdev->dev;
  36. struct phy_provider *provider;
  37. void __iomem *base;
  38. struct phy *phy;
  39. base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
  40. if (IS_ERR(base))
  41. return PTR_ERR(base);
  42. phy = devm_phy_create(dev, NULL, &mmp3_hsic_phy_ops);
  43. if (IS_ERR(phy)) {
  44. dev_err(dev, "failed to create PHY\n");
  45. return PTR_ERR(phy);
  46. }
  47. phy_set_drvdata(phy, (void *)base);
  48. provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
  49. if (IS_ERR(provider)) {
  50. dev_err(dev, "failed to register PHY provider\n");
  51. return PTR_ERR(provider);
  52. }
  53. return 0;
  54. }
  55. static struct platform_driver mmp3_hsic_phy_driver = {
  56. .probe = mmp3_hsic_phy_probe,
  57. .driver = {
  58. .name = "mmp3-hsic-phy",
  59. .of_match_table = mmp3_hsic_phy_of_match,
  60. },
  61. };
  62. module_platform_driver(mmp3_hsic_phy_driver);
  63. MODULE_AUTHOR("Lubomir Rintel <lkundrak@v3.sk>");
  64. MODULE_DESCRIPTION("Marvell MMP3 USB HSIC PHY Driver");
  65. MODULE_LICENSE("GPL");