exynos_dp.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. int ret;
  83. drm_connector_register(connector);
  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 pipe, 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. pipe = exynos_drm_crtc_get_pipe_from_type(drm_dev,
  148. EXYNOS_DISPLAY_TYPE_LCD);
  149. if (pipe < 0)
  150. return pipe;
  151. encoder->possible_crtcs = 1 << pipe;
  152. DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
  153. drm_encoder_init(drm_dev, encoder, &exynos_dp_encoder_funcs,
  154. DRM_MODE_ENCODER_TMDS, NULL);
  155. drm_encoder_helper_add(encoder, &exynos_dp_encoder_helper_funcs);
  156. dp->plat_data.encoder = encoder;
  157. return analogix_dp_bind(dev, dp->drm_dev, &dp->plat_data);
  158. }
  159. static void exynos_dp_unbind(struct device *dev, struct device *master,
  160. void *data)
  161. {
  162. return analogix_dp_unbind(dev, master, data);
  163. }
  164. static const struct component_ops exynos_dp_ops = {
  165. .bind = exynos_dp_bind,
  166. .unbind = exynos_dp_unbind,
  167. };
  168. static int exynos_dp_probe(struct platform_device *pdev)
  169. {
  170. struct device *dev = &pdev->dev;
  171. struct device_node *np = NULL, *endpoint = NULL;
  172. struct exynos_dp_device *dp;
  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. endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
  193. if (endpoint) {
  194. np = of_graph_get_remote_port_parent(endpoint);
  195. if (np) {
  196. /* The remote port can be either a panel or a bridge */
  197. dp->plat_data.panel = of_drm_find_panel(np);
  198. if (!dp->plat_data.panel) {
  199. dp->ptn_bridge = of_drm_find_bridge(np);
  200. if (!dp->ptn_bridge) {
  201. of_node_put(np);
  202. return -EPROBE_DEFER;
  203. }
  204. }
  205. of_node_put(np);
  206. } else {
  207. DRM_ERROR("no remote endpoint device node found.\n");
  208. return -EINVAL;
  209. }
  210. } else {
  211. DRM_ERROR("no port endpoint subnode found.\n");
  212. return -EINVAL;
  213. }
  214. out:
  215. return component_add(&pdev->dev, &exynos_dp_ops);
  216. }
  217. static int exynos_dp_remove(struct platform_device *pdev)
  218. {
  219. component_del(&pdev->dev, &exynos_dp_ops);
  220. return 0;
  221. }
  222. #ifdef CONFIG_PM
  223. static int exynos_dp_suspend(struct device *dev)
  224. {
  225. return analogix_dp_suspend(dev);
  226. }
  227. static int exynos_dp_resume(struct device *dev)
  228. {
  229. return analogix_dp_resume(dev);
  230. }
  231. #endif
  232. static const struct dev_pm_ops exynos_dp_pm_ops = {
  233. SET_RUNTIME_PM_OPS(exynos_dp_suspend, exynos_dp_resume, NULL)
  234. };
  235. static const struct of_device_id exynos_dp_match[] = {
  236. { .compatible = "samsung,exynos5-dp" },
  237. {},
  238. };
  239. MODULE_DEVICE_TABLE(of, exynos_dp_match);
  240. struct platform_driver dp_driver = {
  241. .probe = exynos_dp_probe,
  242. .remove = exynos_dp_remove,
  243. .driver = {
  244. .name = "exynos-dp",
  245. .owner = THIS_MODULE,
  246. .pm = &exynos_dp_pm_ops,
  247. .of_match_table = exynos_dp_match,
  248. },
  249. };
  250. MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");
  251. MODULE_DESCRIPTION("Samsung Specific Analogix-DP Driver Extension");
  252. MODULE_LICENSE("GPL v2");