exynos_dp.c 7.7 KB

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