phy-exynos-dp-video.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Samsung EXYNOS SoC series Display Port PHY driver
  3. *
  4. * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  5. * Author: Jingoo Han <jg1.han@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/err.h>
  12. #include <linux/io.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/of.h>
  16. #include <linux/of_address.h>
  17. #include <linux/phy/phy.h>
  18. #include <linux/platform_device.h>
  19. /* DPTX_PHY_CONTROL register */
  20. #define EXYNOS_DPTX_PHY_ENABLE (1 << 0)
  21. struct exynos_dp_video_phy {
  22. void __iomem *regs;
  23. };
  24. static int __set_phy_state(struct exynos_dp_video_phy *state, unsigned int on)
  25. {
  26. u32 reg;
  27. reg = readl(state->regs);
  28. if (on)
  29. reg |= EXYNOS_DPTX_PHY_ENABLE;
  30. else
  31. reg &= ~EXYNOS_DPTX_PHY_ENABLE;
  32. writel(reg, state->regs);
  33. return 0;
  34. }
  35. static int exynos_dp_video_phy_power_on(struct phy *phy)
  36. {
  37. struct exynos_dp_video_phy *state = phy_get_drvdata(phy);
  38. return __set_phy_state(state, 1);
  39. }
  40. static int exynos_dp_video_phy_power_off(struct phy *phy)
  41. {
  42. struct exynos_dp_video_phy *state = phy_get_drvdata(phy);
  43. return __set_phy_state(state, 0);
  44. }
  45. static struct phy_ops exynos_dp_video_phy_ops = {
  46. .power_on = exynos_dp_video_phy_power_on,
  47. .power_off = exynos_dp_video_phy_power_off,
  48. .owner = THIS_MODULE,
  49. };
  50. static int exynos_dp_video_phy_probe(struct platform_device *pdev)
  51. {
  52. struct exynos_dp_video_phy *state;
  53. struct device *dev = &pdev->dev;
  54. struct resource *res;
  55. struct phy_provider *phy_provider;
  56. struct phy *phy;
  57. state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL);
  58. if (!state)
  59. return -ENOMEM;
  60. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  61. state->regs = devm_ioremap_resource(dev, res);
  62. if (IS_ERR(state->regs))
  63. return PTR_ERR(state->regs);
  64. phy = devm_phy_create(dev, NULL, &exynos_dp_video_phy_ops, NULL);
  65. if (IS_ERR(phy)) {
  66. dev_err(dev, "failed to create Display Port PHY\n");
  67. return PTR_ERR(phy);
  68. }
  69. phy_set_drvdata(phy, state);
  70. phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
  71. return PTR_ERR_OR_ZERO(phy_provider);
  72. }
  73. static const struct of_device_id exynos_dp_video_phy_of_match[] = {
  74. { .compatible = "samsung,exynos5250-dp-video-phy" },
  75. { },
  76. };
  77. MODULE_DEVICE_TABLE(of, exynos_dp_video_phy_of_match);
  78. static struct platform_driver exynos_dp_video_phy_driver = {
  79. .probe = exynos_dp_video_phy_probe,
  80. .driver = {
  81. .name = "exynos-dp-video-phy",
  82. .owner = THIS_MODULE,
  83. .of_match_table = exynos_dp_video_phy_of_match,
  84. }
  85. };
  86. module_platform_driver(exynos_dp_video_phy_driver);
  87. MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");
  88. MODULE_DESCRIPTION("Samsung EXYNOS SoC DP PHY driver");
  89. MODULE_LICENSE("GPL v2");