exynos_dp.c 7.7 KB

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