phy-exynos-dp-video.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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/io.h>
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/of.h>
  15. #include <linux/of_address.h>
  16. #include <linux/phy/phy.h>
  17. #include <linux/platform_device.h>
  18. /* DPTX_PHY_CONTROL register */
  19. #define EXYNOS_DPTX_PHY_ENABLE (1 << 0)
  20. struct exynos_dp_video_phy {
  21. void __iomem *regs;
  22. };
  23. static int __set_phy_state(struct exynos_dp_video_phy *state, unsigned int on)
  24. {
  25. u32 reg;
  26. reg = readl(state->regs);
  27. if (on)
  28. reg |= EXYNOS_DPTX_PHY_ENABLE;
  29. else
  30. reg &= ~EXYNOS_DPTX_PHY_ENABLE;
  31. writel(reg, state->regs);
  32. return 0;
  33. }
  34. static int exynos_dp_video_phy_power_on(struct phy *phy)
  35. {
  36. struct exynos_dp_video_phy *state = phy_get_drvdata(phy);
  37. return __set_phy_state(state, 1);
  38. }
  39. static int exynos_dp_video_phy_power_off(struct phy *phy)
  40. {
  41. struct exynos_dp_video_phy *state = phy_get_drvdata(phy);
  42. return __set_phy_state(state, 0);
  43. }
  44. static struct phy_ops exynos_dp_video_phy_ops = {
  45. .power_on = exynos_dp_video_phy_power_on,
  46. .power_off = exynos_dp_video_phy_power_off,
  47. .owner = THIS_MODULE,
  48. };
  49. static int exynos_dp_video_phy_probe(struct platform_device *pdev)
  50. {
  51. struct exynos_dp_video_phy *state;
  52. struct device *dev = &pdev->dev;
  53. struct resource *res;
  54. struct phy_provider *phy_provider;
  55. struct phy *phy;
  56. state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL);
  57. if (!state)
  58. return -ENOMEM;
  59. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  60. state->regs = devm_ioremap_resource(dev, res);
  61. if (IS_ERR(state->regs))
  62. return PTR_ERR(state->regs);
  63. phy = devm_phy_create(dev, &exynos_dp_video_phy_ops, NULL);
  64. if (IS_ERR(phy)) {
  65. dev_err(dev, "failed to create Display Port PHY\n");
  66. return PTR_ERR(phy);
  67. }
  68. phy_set_drvdata(phy, state);
  69. phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
  70. if (IS_ERR(phy_provider))
  71. return PTR_ERR(phy_provider);
  72. return 0;
  73. }
  74. static const struct of_device_id exynos_dp_video_phy_of_match[] = {
  75. { .compatible = "samsung,exynos5250-dp-video-phy" },
  76. { },
  77. };
  78. MODULE_DEVICE_TABLE(of, exynos_dp_video_phy_of_match);
  79. static struct platform_driver exynos_dp_video_phy_driver = {
  80. .probe = exynos_dp_video_phy_probe,
  81. .driver = {
  82. .name = "exynos-dp-video-phy",
  83. .owner = THIS_MODULE,
  84. .of_match_table = exynos_dp_video_phy_of_match,
  85. }
  86. };
  87. module_platform_driver(exynos_dp_video_phy_driver);
  88. MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");
  89. MODULE_DESCRIPTION("Samsung EXYNOS SoC DP PHY driver");
  90. MODULE_LICENSE("GPL v2");