exynos_dp.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. * Samsung SoC DP (Display Port) interface driver.
  3. *
  4. * Copyright (C) 2012 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 it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/err.h>
  15. #include <linux/clk.h>
  16. #include <linux/of_graph.h>
  17. #include <linux/component.h>
  18. #include <video/of_display_timing.h>
  19. #include <video/of_videomode.h>
  20. #include <video/videomode.h>
  21. #include <drm/drmP.h>
  22. #include <drm/drm_crtc.h>
  23. #include <drm/drm_crtc_helper.h>
  24. #include <drm/drm_of.h>
  25. #include <drm/drm_panel.h>
  26. #include <drm/bridge/analogix_dp.h>
  27. #include <drm/exynos_drm.h>
  28. #include "exynos_drm_crtc.h"
  29. #define to_dp(nm) container_of(nm, struct exynos_dp_device, nm)
  30. struct exynos_dp_device {
  31. struct drm_encoder encoder;
  32. struct drm_connector *connector;
  33. struct drm_bridge *ptn_bridge;
  34. struct drm_device *drm_dev;
  35. struct device *dev;
  36. struct videomode vm;
  37. struct analogix_dp_plat_data plat_data;
  38. };
  39. static int exynos_dp_crtc_clock_enable(struct analogix_dp_plat_data *plat_data,
  40. bool enable)
  41. {
  42. struct exynos_dp_device *dp = to_dp(plat_data);
  43. struct drm_encoder *encoder = &dp->encoder;
  44. if (!encoder->crtc)
  45. return -EPERM;
  46. exynos_drm_pipe_clk_enable(to_exynos_crtc(encoder->crtc), enable);
  47. return 0;
  48. }
  49. static int exynos_dp_poweron(struct analogix_dp_plat_data *plat_data)
  50. {
  51. return exynos_dp_crtc_clock_enable(plat_data, true);
  52. }
  53. static int exynos_dp_poweroff(struct analogix_dp_plat_data *plat_data)
  54. {
  55. return exynos_dp_crtc_clock_enable(plat_data, false);
  56. }
  57. static int exynos_dp_get_modes(struct analogix_dp_plat_data *plat_data,
  58. struct drm_connector *connector)
  59. {
  60. struct exynos_dp_device *dp = to_dp(plat_data);
  61. struct drm_display_mode *mode;
  62. int num_modes = 0;
  63. if (dp->plat_data.panel)
  64. return num_modes;
  65. mode = drm_mode_create(connector->dev);
  66. if (!mode) {
  67. DRM_ERROR("failed to create a new display mode.\n");
  68. return num_modes;
  69. }
  70. drm_display_mode_from_videomode(&dp->vm, mode);
  71. connector->display_info.width_mm = mode->width_mm;
  72. connector->display_info.height_mm = mode->height_mm;
  73. mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
  74. drm_mode_set_name(mode);
  75. drm_mode_probed_add(connector, mode);
  76. return num_modes + 1;
  77. }
  78. static int exynos_dp_bridge_attach(struct analogix_dp_plat_data *plat_data,
  79. struct drm_bridge *bridge,
  80. struct drm_connector *connector)
  81. {
  82. struct exynos_dp_device *dp = to_dp(plat_data);
  83. int ret;
  84. dp->connector = connector;
  85. /* Pre-empt DP connector creation if there's a bridge */
  86. if (dp->ptn_bridge) {
  87. ret = drm_bridge_attach(&dp->encoder, dp->ptn_bridge, bridge);
  88. if (ret) {
  89. DRM_ERROR("Failed to attach bridge to drm\n");
  90. bridge->next = NULL;
  91. return ret;
  92. }
  93. }
  94. return 0;
  95. }
  96. static void exynos_dp_mode_set(struct drm_encoder *encoder,
  97. struct drm_display_mode *mode,
  98. struct drm_display_mode *adjusted_mode)
  99. {
  100. }
  101. static void exynos_dp_nop(struct drm_encoder *encoder)
  102. {
  103. /* do nothing */
  104. }
  105. static const struct drm_encoder_helper_funcs exynos_dp_encoder_helper_funcs = {
  106. .mode_set = exynos_dp_mode_set,
  107. .enable = exynos_dp_nop,
  108. .disable = exynos_dp_nop,
  109. };
  110. static const struct drm_encoder_funcs exynos_dp_encoder_funcs = {
  111. .destroy = drm_encoder_cleanup,
  112. };
  113. static int exynos_dp_dt_parse_panel(struct exynos_dp_device *dp)
  114. {
  115. int ret;
  116. ret = of_get_videomode(dp->dev->of_node, &dp->vm, OF_USE_NATIVE_MODE);
  117. if (ret) {
  118. DRM_ERROR("failed: of_get_videomode() : %d\n", ret);
  119. return ret;
  120. }
  121. return 0;
  122. }
  123. static int exynos_dp_bind(struct device *dev, struct device *master, void *data)
  124. {
  125. struct exynos_dp_device *dp = dev_get_drvdata(dev);
  126. struct drm_encoder *encoder = &dp->encoder;
  127. struct drm_device *drm_dev = data;
  128. int ret;
  129. /*
  130. * Just like the probe function said, we don't need the
  131. * device drvrate anymore, we should leave the charge to
  132. * analogix dp driver, set the device drvdata to NULL.
  133. */
  134. dev_set_drvdata(dev, NULL);
  135. dp->dev = dev;
  136. dp->drm_dev = drm_dev;
  137. dp->plat_data.dev_type = EXYNOS_DP;
  138. dp->plat_data.power_on = exynos_dp_poweron;
  139. dp->plat_data.power_off = exynos_dp_poweroff;
  140. dp->plat_data.attach = exynos_dp_bridge_attach;
  141. dp->plat_data.get_modes = exynos_dp_get_modes;
  142. if (!dp->plat_data.panel && !dp->ptn_bridge) {
  143. ret = exynos_dp_dt_parse_panel(dp);
  144. if (ret)
  145. return ret;
  146. }
  147. drm_encoder_init(drm_dev, encoder, &exynos_dp_encoder_funcs,
  148. DRM_MODE_ENCODER_TMDS, NULL);
  149. drm_encoder_helper_add(encoder, &exynos_dp_encoder_helper_funcs);
  150. ret = exynos_drm_set_possible_crtcs(encoder, EXYNOS_DISPLAY_TYPE_LCD);
  151. if (ret < 0)
  152. return ret;
  153. dp->plat_data.encoder = encoder;
  154. return analogix_dp_bind(dev, dp->drm_dev, &dp->plat_data);
  155. }
  156. static void exynos_dp_unbind(struct device *dev, struct device *master,
  157. void *data)
  158. {
  159. return analogix_dp_unbind(dev, master, data);
  160. }
  161. static const struct component_ops exynos_dp_ops = {
  162. .bind = exynos_dp_bind,
  163. .unbind = exynos_dp_unbind,
  164. };
  165. static int exynos_dp_probe(struct platform_device *pdev)
  166. {
  167. struct device *dev = &pdev->dev;
  168. struct device_node *np;
  169. struct exynos_dp_device *dp;
  170. struct drm_panel *panel;
  171. struct drm_bridge *bridge;
  172. int ret;
  173. dp = devm_kzalloc(&pdev->dev, sizeof(struct exynos_dp_device),
  174. GFP_KERNEL);
  175. if (!dp)
  176. return -ENOMEM;
  177. /*
  178. * We just use the drvdata until driver run into component
  179. * add function, and then we would set drvdata to null, so
  180. * that analogix dp driver would take charge of the drvdata.
  181. */
  182. platform_set_drvdata(pdev, dp);
  183. /* This is for the backward compatibility. */
  184. np = of_parse_phandle(dev->of_node, "panel", 0);
  185. if (np) {
  186. dp->plat_data.panel = of_drm_find_panel(np);
  187. of_node_put(np);
  188. if (!dp->plat_data.panel)
  189. return -EPROBE_DEFER;
  190. goto out;
  191. }
  192. ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0, &panel, &bridge);
  193. if (ret)
  194. return ret;
  195. /* The remote port can be either a panel or a bridge */
  196. dp->plat_data.panel = panel;
  197. dp->ptn_bridge = bridge;
  198. out:
  199. return component_add(&pdev->dev, &exynos_dp_ops);
  200. }
  201. static int exynos_dp_remove(struct platform_device *pdev)
  202. {
  203. component_del(&pdev->dev, &exynos_dp_ops);
  204. return 0;
  205. }
  206. #ifdef CONFIG_PM
  207. static int exynos_dp_suspend(struct device *dev)
  208. {
  209. return analogix_dp_suspend(dev);
  210. }
  211. static int exynos_dp_resume(struct device *dev)
  212. {
  213. return analogix_dp_resume(dev);
  214. }
  215. #endif
  216. static const struct dev_pm_ops exynos_dp_pm_ops = {
  217. SET_RUNTIME_PM_OPS(exynos_dp_suspend, exynos_dp_resume, NULL)
  218. };
  219. static const struct of_device_id exynos_dp_match[] = {
  220. { .compatible = "samsung,exynos5-dp" },
  221. {},
  222. };
  223. MODULE_DEVICE_TABLE(of, exynos_dp_match);
  224. struct platform_driver dp_driver = {
  225. .probe = exynos_dp_probe,
  226. .remove = exynos_dp_remove,
  227. .driver = {
  228. .name = "exynos-dp",
  229. .owner = THIS_MODULE,
  230. .pm = &exynos_dp_pm_ops,
  231. .of_match_table = exynos_dp_match,
  232. },
  233. };
  234. MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");
  235. MODULE_DESCRIPTION("Samsung Specific Analogix-DP Driver Extension");
  236. MODULE_LICENSE("GPL v2");