exynos_drm_hdmi.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics Co.Ltd
  3. * Authors:
  4. * Inki Dae <inki.dae@samsung.com>
  5. * Seung-Woo Kim <sw0312.kim@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. */
  13. #include "drmP.h"
  14. #include <linux/kernel.h>
  15. #include <linux/wait.h>
  16. #include <linux/module.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/pm_runtime.h>
  19. #include <drm/exynos_drm.h>
  20. #include "exynos_drm_drv.h"
  21. #include "exynos_drm_hdmi.h"
  22. #define to_context(dev) platform_get_drvdata(to_platform_device(dev))
  23. #define to_subdrv(dev) to_context(dev)
  24. #define get_ctx_from_subdrv(subdrv) container_of(subdrv,\
  25. struct drm_hdmi_context, subdrv);
  26. /* these callback points shoud be set by specific drivers. */
  27. static struct exynos_hdmi_display_ops *hdmi_display_ops;
  28. static struct exynos_hdmi_manager_ops *hdmi_manager_ops;
  29. static struct exynos_hdmi_overlay_ops *hdmi_overlay_ops;
  30. struct drm_hdmi_context {
  31. struct exynos_drm_subdrv subdrv;
  32. struct exynos_drm_hdmi_context *hdmi_ctx;
  33. struct exynos_drm_hdmi_context *mixer_ctx;
  34. };
  35. void exynos_drm_display_ops_register(struct exynos_hdmi_display_ops
  36. *display_ops)
  37. {
  38. DRM_DEBUG_KMS("%s\n", __FILE__);
  39. if (display_ops)
  40. hdmi_display_ops = display_ops;
  41. }
  42. void exynos_drm_manager_ops_register(struct exynos_hdmi_manager_ops
  43. *manager_ops)
  44. {
  45. DRM_DEBUG_KMS("%s\n", __FILE__);
  46. if (manager_ops)
  47. hdmi_manager_ops = manager_ops;
  48. }
  49. void exynos_drm_overlay_ops_register(struct exynos_hdmi_overlay_ops
  50. *overlay_ops)
  51. {
  52. DRM_DEBUG_KMS("%s\n", __FILE__);
  53. if (overlay_ops)
  54. hdmi_overlay_ops = overlay_ops;
  55. }
  56. static bool drm_hdmi_is_connected(struct device *dev)
  57. {
  58. struct drm_hdmi_context *ctx = to_context(dev);
  59. DRM_DEBUG_KMS("%s\n", __FILE__);
  60. if (hdmi_display_ops && hdmi_display_ops->is_connected)
  61. return hdmi_display_ops->is_connected(ctx->hdmi_ctx->ctx);
  62. return false;
  63. }
  64. static int drm_hdmi_get_edid(struct device *dev,
  65. struct drm_connector *connector, u8 *edid, int len)
  66. {
  67. struct drm_hdmi_context *ctx = to_context(dev);
  68. DRM_DEBUG_KMS("%s\n", __FILE__);
  69. if (hdmi_display_ops && hdmi_display_ops->get_edid)
  70. return hdmi_display_ops->get_edid(ctx->hdmi_ctx->ctx,
  71. connector, edid, len);
  72. return 0;
  73. }
  74. static int drm_hdmi_check_timing(struct device *dev, void *timing)
  75. {
  76. struct drm_hdmi_context *ctx = to_context(dev);
  77. DRM_DEBUG_KMS("%s\n", __FILE__);
  78. if (hdmi_display_ops && hdmi_display_ops->check_timing)
  79. return hdmi_display_ops->check_timing(ctx->hdmi_ctx->ctx,
  80. timing);
  81. return 0;
  82. }
  83. static int drm_hdmi_power_on(struct device *dev, int mode)
  84. {
  85. struct drm_hdmi_context *ctx = to_context(dev);
  86. DRM_DEBUG_KMS("%s\n", __FILE__);
  87. if (hdmi_display_ops && hdmi_display_ops->power_on)
  88. return hdmi_display_ops->power_on(ctx->hdmi_ctx->ctx, mode);
  89. return 0;
  90. }
  91. static struct exynos_drm_display_ops drm_hdmi_display_ops = {
  92. .type = EXYNOS_DISPLAY_TYPE_HDMI,
  93. .is_connected = drm_hdmi_is_connected,
  94. .get_edid = drm_hdmi_get_edid,
  95. .check_timing = drm_hdmi_check_timing,
  96. .power_on = drm_hdmi_power_on,
  97. };
  98. static int drm_hdmi_enable_vblank(struct device *subdrv_dev)
  99. {
  100. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  101. struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
  102. struct exynos_drm_manager *manager = &subdrv->manager;
  103. DRM_DEBUG_KMS("%s\n", __FILE__);
  104. if (hdmi_overlay_ops && hdmi_overlay_ops->enable_vblank)
  105. return hdmi_overlay_ops->enable_vblank(ctx->mixer_ctx->ctx,
  106. manager->pipe);
  107. return 0;
  108. }
  109. static void drm_hdmi_disable_vblank(struct device *subdrv_dev)
  110. {
  111. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  112. DRM_DEBUG_KMS("%s\n", __FILE__);
  113. if (hdmi_overlay_ops && hdmi_overlay_ops->disable_vblank)
  114. return hdmi_overlay_ops->disable_vblank(ctx->mixer_ctx->ctx);
  115. }
  116. static void drm_hdmi_mode_fixup(struct device *subdrv_dev,
  117. struct drm_connector *connector,
  118. struct drm_display_mode *mode,
  119. struct drm_display_mode *adjusted_mode)
  120. {
  121. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  122. DRM_DEBUG_KMS("%s\n", __FILE__);
  123. if (hdmi_manager_ops && hdmi_manager_ops->mode_fixup)
  124. hdmi_manager_ops->mode_fixup(ctx->hdmi_ctx->ctx, connector,
  125. mode, adjusted_mode);
  126. }
  127. static void drm_hdmi_mode_set(struct device *subdrv_dev, void *mode)
  128. {
  129. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  130. DRM_DEBUG_KMS("%s\n", __FILE__);
  131. if (hdmi_manager_ops && hdmi_manager_ops->mode_set)
  132. hdmi_manager_ops->mode_set(ctx->hdmi_ctx->ctx, mode);
  133. }
  134. static void drm_hdmi_get_max_resol(struct device *subdrv_dev,
  135. unsigned int *width, unsigned int *height)
  136. {
  137. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  138. DRM_DEBUG_KMS("%s\n", __FILE__);
  139. if (hdmi_manager_ops && hdmi_manager_ops->get_max_resol)
  140. hdmi_manager_ops->get_max_resol(ctx->hdmi_ctx->ctx, width,
  141. height);
  142. }
  143. static void drm_hdmi_commit(struct device *subdrv_dev)
  144. {
  145. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  146. DRM_DEBUG_KMS("%s\n", __FILE__);
  147. if (hdmi_manager_ops && hdmi_manager_ops->commit)
  148. hdmi_manager_ops->commit(ctx->hdmi_ctx->ctx);
  149. }
  150. static void drm_hdmi_dpms(struct device *subdrv_dev, int mode)
  151. {
  152. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  153. DRM_DEBUG_KMS("%s\n", __FILE__);
  154. switch (mode) {
  155. case DRM_MODE_DPMS_ON:
  156. break;
  157. case DRM_MODE_DPMS_STANDBY:
  158. case DRM_MODE_DPMS_SUSPEND:
  159. case DRM_MODE_DPMS_OFF:
  160. if (hdmi_manager_ops && hdmi_manager_ops->disable)
  161. hdmi_manager_ops->disable(ctx->hdmi_ctx->ctx);
  162. break;
  163. default:
  164. DRM_DEBUG_KMS("unkown dps mode: %d\n", mode);
  165. break;
  166. }
  167. }
  168. static struct exynos_drm_manager_ops drm_hdmi_manager_ops = {
  169. .dpms = drm_hdmi_dpms,
  170. .enable_vblank = drm_hdmi_enable_vblank,
  171. .disable_vblank = drm_hdmi_disable_vblank,
  172. .mode_fixup = drm_hdmi_mode_fixup,
  173. .mode_set = drm_hdmi_mode_set,
  174. .get_max_resol = drm_hdmi_get_max_resol,
  175. .commit = drm_hdmi_commit,
  176. };
  177. static void drm_mixer_mode_set(struct device *subdrv_dev,
  178. struct exynos_drm_overlay *overlay)
  179. {
  180. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  181. DRM_DEBUG_KMS("%s\n", __FILE__);
  182. if (hdmi_overlay_ops && hdmi_overlay_ops->win_mode_set)
  183. hdmi_overlay_ops->win_mode_set(ctx->mixer_ctx->ctx, overlay);
  184. }
  185. static void drm_mixer_commit(struct device *subdrv_dev, int zpos)
  186. {
  187. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  188. DRM_DEBUG_KMS("%s\n", __FILE__);
  189. if (hdmi_overlay_ops && hdmi_overlay_ops->win_commit)
  190. hdmi_overlay_ops->win_commit(ctx->mixer_ctx->ctx, zpos);
  191. }
  192. static void drm_mixer_disable(struct device *subdrv_dev, int zpos)
  193. {
  194. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  195. DRM_DEBUG_KMS("%s\n", __FILE__);
  196. if (hdmi_overlay_ops && hdmi_overlay_ops->win_disable)
  197. hdmi_overlay_ops->win_disable(ctx->mixer_ctx->ctx, zpos);
  198. }
  199. static struct exynos_drm_overlay_ops drm_hdmi_overlay_ops = {
  200. .mode_set = drm_mixer_mode_set,
  201. .commit = drm_mixer_commit,
  202. .disable = drm_mixer_disable,
  203. };
  204. static int hdmi_subdrv_probe(struct drm_device *drm_dev,
  205. struct device *dev)
  206. {
  207. struct exynos_drm_subdrv *subdrv = to_subdrv(dev);
  208. struct drm_hdmi_context *ctx;
  209. struct platform_device *pdev = to_platform_device(dev);
  210. struct exynos_drm_common_hdmi_pd *pd;
  211. DRM_DEBUG_KMS("%s\n", __FILE__);
  212. pd = pdev->dev.platform_data;
  213. if (!pd) {
  214. DRM_DEBUG_KMS("platform data is null.\n");
  215. return -EFAULT;
  216. }
  217. if (!pd->hdmi_dev) {
  218. DRM_DEBUG_KMS("hdmi device is null.\n");
  219. return -EFAULT;
  220. }
  221. if (!pd->mixer_dev) {
  222. DRM_DEBUG_KMS("mixer device is null.\n");
  223. return -EFAULT;
  224. }
  225. ctx = get_ctx_from_subdrv(subdrv);
  226. ctx->hdmi_ctx = (struct exynos_drm_hdmi_context *)
  227. to_context(pd->hdmi_dev);
  228. if (!ctx->hdmi_ctx) {
  229. DRM_DEBUG_KMS("hdmi context is null.\n");
  230. return -EFAULT;
  231. }
  232. ctx->hdmi_ctx->drm_dev = drm_dev;
  233. ctx->mixer_ctx = (struct exynos_drm_hdmi_context *)
  234. to_context(pd->mixer_dev);
  235. if (!ctx->mixer_ctx) {
  236. DRM_DEBUG_KMS("mixer context is null.\n");
  237. return -EFAULT;
  238. }
  239. ctx->mixer_ctx->drm_dev = drm_dev;
  240. return 0;
  241. }
  242. static int __devinit exynos_drm_hdmi_probe(struct platform_device *pdev)
  243. {
  244. struct device *dev = &pdev->dev;
  245. struct exynos_drm_subdrv *subdrv;
  246. struct drm_hdmi_context *ctx;
  247. DRM_DEBUG_KMS("%s\n", __FILE__);
  248. ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
  249. if (!ctx) {
  250. DRM_LOG_KMS("failed to alloc common hdmi context.\n");
  251. return -ENOMEM;
  252. }
  253. subdrv = &ctx->subdrv;
  254. subdrv->probe = hdmi_subdrv_probe;
  255. subdrv->manager.pipe = -1;
  256. subdrv->manager.ops = &drm_hdmi_manager_ops;
  257. subdrv->manager.overlay_ops = &drm_hdmi_overlay_ops;
  258. subdrv->manager.display_ops = &drm_hdmi_display_ops;
  259. subdrv->manager.dev = dev;
  260. platform_set_drvdata(pdev, subdrv);
  261. exynos_drm_subdrv_register(subdrv);
  262. return 0;
  263. }
  264. static int hdmi_runtime_suspend(struct device *dev)
  265. {
  266. DRM_DEBUG_KMS("%s\n", __FILE__);
  267. return 0;
  268. }
  269. static int hdmi_runtime_resume(struct device *dev)
  270. {
  271. DRM_DEBUG_KMS("%s\n", __FILE__);
  272. return 0;
  273. }
  274. static const struct dev_pm_ops hdmi_pm_ops = {
  275. .runtime_suspend = hdmi_runtime_suspend,
  276. .runtime_resume = hdmi_runtime_resume,
  277. };
  278. static int __devexit exynos_drm_hdmi_remove(struct platform_device *pdev)
  279. {
  280. struct drm_hdmi_context *ctx = platform_get_drvdata(pdev);
  281. DRM_DEBUG_KMS("%s\n", __FILE__);
  282. exynos_drm_subdrv_unregister(&ctx->subdrv);
  283. kfree(ctx);
  284. return 0;
  285. }
  286. struct platform_driver exynos_drm_common_hdmi_driver = {
  287. .probe = exynos_drm_hdmi_probe,
  288. .remove = __devexit_p(exynos_drm_hdmi_remove),
  289. .driver = {
  290. .name = "exynos-drm-hdmi",
  291. .owner = THIS_MODULE,
  292. .pm = &hdmi_pm_ops,
  293. },
  294. };