phy-mmp3-hsic.c 1.9 KB

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