exynos_drm_hdmi.c 8.7 KB

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