exynos_drm_hdmi.c 9.1 KB

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