exynos_drm_hdmi.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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 <drm/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. /* Common hdmi subdrv needs to access the hdmi and mixer though context.
  27. * These should be initialied by the repective drivers */
  28. static struct exynos_drm_hdmi_context *hdmi_ctx;
  29. static struct exynos_drm_hdmi_context *mixer_ctx;
  30. /* these callback points shoud be set by specific drivers. */
  31. static struct exynos_hdmi_ops *hdmi_ops;
  32. static struct exynos_mixer_ops *mixer_ops;
  33. struct drm_hdmi_context {
  34. struct exynos_drm_subdrv subdrv;
  35. struct exynos_drm_hdmi_context *hdmi_ctx;
  36. struct exynos_drm_hdmi_context *mixer_ctx;
  37. bool enabled[MIXER_WIN_NR];
  38. };
  39. void exynos_hdmi_drv_attach(struct exynos_drm_hdmi_context *ctx)
  40. {
  41. if (ctx)
  42. hdmi_ctx = ctx;
  43. }
  44. void exynos_mixer_drv_attach(struct exynos_drm_hdmi_context *ctx)
  45. {
  46. if (ctx)
  47. mixer_ctx = ctx;
  48. }
  49. void exynos_hdmi_ops_register(struct exynos_hdmi_ops *ops)
  50. {
  51. DRM_DEBUG_KMS("%s\n", __FILE__);
  52. if (ops)
  53. hdmi_ops = ops;
  54. }
  55. void exynos_mixer_ops_register(struct exynos_mixer_ops *ops)
  56. {
  57. DRM_DEBUG_KMS("%s\n", __FILE__);
  58. if (ops)
  59. mixer_ops = ops;
  60. }
  61. static bool drm_hdmi_is_connected(struct device *dev)
  62. {
  63. struct drm_hdmi_context *ctx = to_context(dev);
  64. DRM_DEBUG_KMS("%s\n", __FILE__);
  65. if (hdmi_ops && hdmi_ops->is_connected)
  66. return hdmi_ops->is_connected(ctx->hdmi_ctx->ctx);
  67. return false;
  68. }
  69. static int drm_hdmi_get_edid(struct device *dev,
  70. struct drm_connector *connector, u8 *edid, int len)
  71. {
  72. struct drm_hdmi_context *ctx = to_context(dev);
  73. DRM_DEBUG_KMS("%s\n", __FILE__);
  74. if (hdmi_ops && hdmi_ops->get_edid)
  75. return hdmi_ops->get_edid(ctx->hdmi_ctx->ctx, connector, edid,
  76. len);
  77. return 0;
  78. }
  79. static int drm_hdmi_check_timing(struct device *dev, void *timing)
  80. {
  81. struct drm_hdmi_context *ctx = to_context(dev);
  82. DRM_DEBUG_KMS("%s\n", __FILE__);
  83. if (hdmi_ops && hdmi_ops->check_timing)
  84. return hdmi_ops->check_timing(ctx->hdmi_ctx->ctx, timing);
  85. return 0;
  86. }
  87. static int drm_hdmi_power_on(struct device *dev, int mode)
  88. {
  89. struct drm_hdmi_context *ctx = to_context(dev);
  90. DRM_DEBUG_KMS("%s\n", __FILE__);
  91. if (hdmi_ops && hdmi_ops->power_on)
  92. return hdmi_ops->power_on(ctx->hdmi_ctx->ctx, mode);
  93. return 0;
  94. }
  95. static struct exynos_drm_display_ops drm_hdmi_display_ops = {
  96. .type = EXYNOS_DISPLAY_TYPE_HDMI,
  97. .is_connected = drm_hdmi_is_connected,
  98. .get_edid = drm_hdmi_get_edid,
  99. .check_timing = drm_hdmi_check_timing,
  100. .power_on = drm_hdmi_power_on,
  101. };
  102. static int drm_hdmi_enable_vblank(struct device *subdrv_dev)
  103. {
  104. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  105. struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
  106. struct exynos_drm_manager *manager = subdrv->manager;
  107. DRM_DEBUG_KMS("%s\n", __FILE__);
  108. if (mixer_ops && mixer_ops->enable_vblank)
  109. return mixer_ops->enable_vblank(ctx->mixer_ctx->ctx,
  110. manager->pipe);
  111. return 0;
  112. }
  113. static void drm_hdmi_disable_vblank(struct device *subdrv_dev)
  114. {
  115. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  116. DRM_DEBUG_KMS("%s\n", __FILE__);
  117. if (mixer_ops && mixer_ops->disable_vblank)
  118. return mixer_ops->disable_vblank(ctx->mixer_ctx->ctx);
  119. }
  120. static void drm_hdmi_mode_fixup(struct device *subdrv_dev,
  121. struct drm_connector *connector,
  122. const struct drm_display_mode *mode,
  123. struct drm_display_mode *adjusted_mode)
  124. {
  125. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  126. DRM_DEBUG_KMS("%s\n", __FILE__);
  127. if (hdmi_ops && hdmi_ops->mode_fixup)
  128. hdmi_ops->mode_fixup(ctx->hdmi_ctx->ctx, connector, mode,
  129. adjusted_mode);
  130. }
  131. static void drm_hdmi_mode_set(struct device *subdrv_dev, void *mode)
  132. {
  133. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  134. DRM_DEBUG_KMS("%s\n", __FILE__);
  135. if (hdmi_ops && hdmi_ops->mode_set)
  136. hdmi_ops->mode_set(ctx->hdmi_ctx->ctx, mode);
  137. }
  138. static void drm_hdmi_get_max_resol(struct device *subdrv_dev,
  139. unsigned int *width, unsigned int *height)
  140. {
  141. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  142. DRM_DEBUG_KMS("%s\n", __FILE__);
  143. if (hdmi_ops && hdmi_ops->get_max_resol)
  144. hdmi_ops->get_max_resol(ctx->hdmi_ctx->ctx, width, height);
  145. }
  146. static void drm_hdmi_commit(struct device *subdrv_dev)
  147. {
  148. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  149. DRM_DEBUG_KMS("%s\n", __FILE__);
  150. if (hdmi_ops && hdmi_ops->commit)
  151. hdmi_ops->commit(ctx->hdmi_ctx->ctx);
  152. }
  153. static void drm_hdmi_dpms(struct device *subdrv_dev, int mode)
  154. {
  155. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  156. DRM_DEBUG_KMS("%s\n", __FILE__);
  157. if (mixer_ops && mixer_ops->dpms)
  158. mixer_ops->dpms(ctx->mixer_ctx->ctx, mode);
  159. if (hdmi_ops && hdmi_ops->dpms)
  160. hdmi_ops->dpms(ctx->hdmi_ctx->ctx, mode);
  161. }
  162. static void drm_hdmi_apply(struct device *subdrv_dev)
  163. {
  164. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  165. int i;
  166. DRM_DEBUG_KMS("%s\n", __FILE__);
  167. for (i = 0; i < MIXER_WIN_NR; i++) {
  168. if (!ctx->enabled[i])
  169. continue;
  170. if (mixer_ops && mixer_ops->win_commit)
  171. mixer_ops->win_commit(ctx->mixer_ctx->ctx, i);
  172. }
  173. if (hdmi_ops && hdmi_ops->commit)
  174. hdmi_ops->commit(ctx->hdmi_ctx->ctx);
  175. }
  176. static struct exynos_drm_manager_ops drm_hdmi_manager_ops = {
  177. .dpms = drm_hdmi_dpms,
  178. .apply = drm_hdmi_apply,
  179. .enable_vblank = drm_hdmi_enable_vblank,
  180. .disable_vblank = drm_hdmi_disable_vblank,
  181. .mode_fixup = drm_hdmi_mode_fixup,
  182. .mode_set = drm_hdmi_mode_set,
  183. .get_max_resol = drm_hdmi_get_max_resol,
  184. .commit = drm_hdmi_commit,
  185. };
  186. static void drm_mixer_mode_set(struct device *subdrv_dev,
  187. struct exynos_drm_overlay *overlay)
  188. {
  189. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  190. DRM_DEBUG_KMS("%s\n", __FILE__);
  191. if (mixer_ops && mixer_ops->win_mode_set)
  192. mixer_ops->win_mode_set(ctx->mixer_ctx->ctx, overlay);
  193. }
  194. static void drm_mixer_commit(struct device *subdrv_dev, int zpos)
  195. {
  196. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  197. int win = (zpos == DEFAULT_ZPOS) ? MIXER_DEFAULT_WIN : zpos;
  198. DRM_DEBUG_KMS("%s\n", __FILE__);
  199. if (win < 0 || win > MIXER_WIN_NR) {
  200. DRM_ERROR("mixer window[%d] is wrong\n", win);
  201. return;
  202. }
  203. if (mixer_ops && mixer_ops->win_commit)
  204. mixer_ops->win_commit(ctx->mixer_ctx->ctx, win);
  205. ctx->enabled[win] = true;
  206. }
  207. static void drm_mixer_disable(struct device *subdrv_dev, int zpos)
  208. {
  209. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  210. int win = (zpos == DEFAULT_ZPOS) ? MIXER_DEFAULT_WIN : zpos;
  211. DRM_DEBUG_KMS("%s\n", __FILE__);
  212. if (win < 0 || win > MIXER_WIN_NR) {
  213. DRM_ERROR("mixer window[%d] is wrong\n", win);
  214. return;
  215. }
  216. if (mixer_ops && mixer_ops->win_disable)
  217. mixer_ops->win_disable(ctx->mixer_ctx->ctx, win);
  218. ctx->enabled[win] = false;
  219. }
  220. static void drm_mixer_wait_for_vblank(struct device *subdrv_dev)
  221. {
  222. struct drm_hdmi_context *ctx = to_context(subdrv_dev);
  223. DRM_DEBUG_KMS("%s\n", __FILE__);
  224. if (mixer_ops && mixer_ops->wait_for_vblank)
  225. mixer_ops->wait_for_vblank(ctx->mixer_ctx->ctx);
  226. }
  227. static struct exynos_drm_overlay_ops drm_hdmi_overlay_ops = {
  228. .mode_set = drm_mixer_mode_set,
  229. .commit = drm_mixer_commit,
  230. .disable = drm_mixer_disable,
  231. .wait_for_vblank = drm_mixer_wait_for_vblank,
  232. };
  233. static struct exynos_drm_manager hdmi_manager = {
  234. .pipe = -1,
  235. .ops = &drm_hdmi_manager_ops,
  236. .overlay_ops = &drm_hdmi_overlay_ops,
  237. .display_ops = &drm_hdmi_display_ops,
  238. };
  239. static int hdmi_subdrv_probe(struct drm_device *drm_dev,
  240. struct device *dev)
  241. {
  242. struct exynos_drm_subdrv *subdrv = to_subdrv(dev);
  243. struct drm_hdmi_context *ctx;
  244. DRM_DEBUG_KMS("%s\n", __FILE__);
  245. if (!hdmi_ctx) {
  246. DRM_ERROR("hdmi context not initialized.\n");
  247. return -EFAULT;
  248. }
  249. if (!mixer_ctx) {
  250. DRM_ERROR("mixer context not initialized.\n");
  251. return -EFAULT;
  252. }
  253. ctx = get_ctx_from_subdrv(subdrv);
  254. if (!ctx) {
  255. DRM_ERROR("no drm hdmi context.\n");
  256. return -EFAULT;
  257. }
  258. ctx->hdmi_ctx = hdmi_ctx;
  259. ctx->mixer_ctx = mixer_ctx;
  260. ctx->hdmi_ctx->drm_dev = drm_dev;
  261. ctx->mixer_ctx->drm_dev = drm_dev;
  262. return 0;
  263. }
  264. static int __devinit exynos_drm_hdmi_probe(struct platform_device *pdev)
  265. {
  266. struct device *dev = &pdev->dev;
  267. struct exynos_drm_subdrv *subdrv;
  268. struct drm_hdmi_context *ctx;
  269. DRM_DEBUG_KMS("%s\n", __FILE__);
  270. ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
  271. if (!ctx) {
  272. DRM_LOG_KMS("failed to alloc common hdmi context.\n");
  273. return -ENOMEM;
  274. }
  275. subdrv = &ctx->subdrv;
  276. subdrv->dev = dev;
  277. subdrv->manager = &hdmi_manager;
  278. subdrv->probe = hdmi_subdrv_probe;
  279. platform_set_drvdata(pdev, subdrv);
  280. exynos_drm_subdrv_register(subdrv);
  281. return 0;
  282. }
  283. static int __devexit exynos_drm_hdmi_remove(struct platform_device *pdev)
  284. {
  285. struct drm_hdmi_context *ctx = platform_get_drvdata(pdev);
  286. DRM_DEBUG_KMS("%s\n", __FILE__);
  287. exynos_drm_subdrv_unregister(&ctx->subdrv);
  288. return 0;
  289. }
  290. struct platform_driver exynos_drm_common_hdmi_driver = {
  291. .probe = exynos_drm_hdmi_probe,
  292. .remove = __devexit_p(exynos_drm_hdmi_remove),
  293. .driver = {
  294. .name = "exynos-drm-hdmi",
  295. .owner = THIS_MODULE,
  296. },
  297. };