exynos_dp.c 7.7 KB

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