blob: ca0a87f2cd7f3f9e3b98b6c134c58c6897a3a772 [file] [log] [blame]
Seung-Woo Kimd8408322011-12-21 17:39:39 +09001/*
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
David Howells760285e2012-10-02 18:01:07 +010014#include <drm/drmP.h>
Seung-Woo Kimd8408322011-12-21 17:39:39 +090015
16#include <linux/kernel.h>
17#include <linux/wait.h>
Seung-Woo Kimd8408322011-12-21 17:39:39 +090018#include <linux/platform_device.h>
19#include <linux/pm_runtime.h>
20
21#include <drm/exynos_drm.h>
22
23#include "exynos_drm_drv.h"
24#include "exynos_drm_hdmi.h"
25
26#define to_context(dev) platform_get_drvdata(to_platform_device(dev))
27#define to_subdrv(dev) to_context(dev)
28#define get_ctx_from_subdrv(subdrv) container_of(subdrv,\
29 struct drm_hdmi_context, subdrv);
30
Rahul Sharmaae9dace2012-10-16 05:50:13 +053031/* platform device pointer for common drm hdmi device. */
32static struct platform_device *exynos_drm_hdmi_pdev;
33
Rahul Sharma768c3052012-10-04 20:48:56 +053034/* Common hdmi subdrv needs to access the hdmi and mixer though context.
35* These should be initialied by the repective drivers */
36static struct exynos_drm_hdmi_context *hdmi_ctx;
37static struct exynos_drm_hdmi_context *mixer_ctx;
38
Seung-Woo Kimd8408322011-12-21 17:39:39 +090039/* these callback points shoud be set by specific drivers. */
Joonyoung Shim578b6062012-04-05 20:49:26 +090040static struct exynos_hdmi_ops *hdmi_ops;
41static struct exynos_mixer_ops *mixer_ops;
Seung-Woo Kimd8408322011-12-21 17:39:39 +090042
43struct drm_hdmi_context {
44 struct exynos_drm_subdrv subdrv;
45 struct exynos_drm_hdmi_context *hdmi_ctx;
46 struct exynos_drm_hdmi_context *mixer_ctx;
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +090047
48 bool enabled[MIXER_WIN_NR];
Seung-Woo Kimd8408322011-12-21 17:39:39 +090049};
50
Rahul Sharmaae9dace2012-10-16 05:50:13 +053051int exynos_platform_device_hdmi_register(void)
52{
Seung-Woo Kim0f6f9592013-04-22 18:40:34 +090053 struct platform_device *pdev;
54
Rahul Sharmaae9dace2012-10-16 05:50:13 +053055 if (exynos_drm_hdmi_pdev)
56 return -EEXIST;
57
Seung-Woo Kim0f6f9592013-04-22 18:40:34 +090058 pdev = platform_device_register_simple(
Rahul Sharmaae9dace2012-10-16 05:50:13 +053059 "exynos-drm-hdmi", -1, NULL, 0);
Seung-Woo Kim0f6f9592013-04-22 18:40:34 +090060 if (IS_ERR(pdev))
61 return PTR_ERR(pdev);
62
63 exynos_drm_hdmi_pdev = pdev;
Rahul Sharmaae9dace2012-10-16 05:50:13 +053064
65 return 0;
66}
67
68void exynos_platform_device_hdmi_unregister(void)
69{
Seung-Woo Kim0f6f9592013-04-22 18:40:34 +090070 if (exynos_drm_hdmi_pdev) {
Rahul Sharmaae9dace2012-10-16 05:50:13 +053071 platform_device_unregister(exynos_drm_hdmi_pdev);
Seung-Woo Kim0f6f9592013-04-22 18:40:34 +090072 exynos_drm_hdmi_pdev = NULL;
73 }
Rahul Sharmaae9dace2012-10-16 05:50:13 +053074}
75
Rahul Sharma768c3052012-10-04 20:48:56 +053076void exynos_hdmi_drv_attach(struct exynos_drm_hdmi_context *ctx)
77{
78 if (ctx)
79 hdmi_ctx = ctx;
80}
81
82void exynos_mixer_drv_attach(struct exynos_drm_hdmi_context *ctx)
83{
84 if (ctx)
85 mixer_ctx = ctx;
86}
87
Joonyoung Shim578b6062012-04-05 20:49:26 +090088void exynos_hdmi_ops_register(struct exynos_hdmi_ops *ops)
Seung-Woo Kimd8408322011-12-21 17:39:39 +090089{
Joonyoung Shim578b6062012-04-05 20:49:26 +090090 if (ops)
91 hdmi_ops = ops;
Seung-Woo Kimd8408322011-12-21 17:39:39 +090092}
Seung-Woo Kimd8408322011-12-21 17:39:39 +090093
Joonyoung Shim578b6062012-04-05 20:49:26 +090094void exynos_mixer_ops_register(struct exynos_mixer_ops *ops)
Seung-Woo Kimd8408322011-12-21 17:39:39 +090095{
Joonyoung Shim578b6062012-04-05 20:49:26 +090096 if (ops)
97 mixer_ops = ops;
Seung-Woo Kimd8408322011-12-21 17:39:39 +090098}
Seung-Woo Kimd8408322011-12-21 17:39:39 +090099
Sean Paul45517892014-01-30 16:19:05 -0500100static int drm_hdmi_display_initialize(struct device *dev,
101 struct drm_device *drm_dev)
102{
103 struct drm_hdmi_context *ctx = to_context(dev);
104
105 if (hdmi_ops && hdmi_ops->initialize)
106 return hdmi_ops->initialize(ctx->hdmi_ctx->ctx, drm_dev);
107
108 return 0;
109}
110
111
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900112static bool drm_hdmi_is_connected(struct device *dev)
113{
114 struct drm_hdmi_context *ctx = to_context(dev);
115
Joonyoung Shim578b6062012-04-05 20:49:26 +0900116 if (hdmi_ops && hdmi_ops->is_connected)
117 return hdmi_ops->is_connected(ctx->hdmi_ctx->ctx);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900118
119 return false;
120}
121
Sachin Kamat428982e2013-01-21 15:26:57 +0530122static struct edid *drm_hdmi_get_edid(struct device *dev,
Rahul Sharma9c08e4b2013-01-04 07:59:11 -0500123 struct drm_connector *connector)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900124{
125 struct drm_hdmi_context *ctx = to_context(dev);
126
Joonyoung Shim578b6062012-04-05 20:49:26 +0900127 if (hdmi_ops && hdmi_ops->get_edid)
Rahul Sharma9c08e4b2013-01-04 07:59:11 -0500128 return hdmi_ops->get_edid(ctx->hdmi_ctx->ctx, connector);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900129
Rahul Sharma9c08e4b2013-01-04 07:59:11 -0500130 return NULL;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900131}
Sean Paulbb7704d2014-01-30 16:19:06 -0500132static int drm_hdmi_check_mode_ctx(struct drm_hdmi_context *ctx,
Rahul Sharma16844fb2013-06-10 14:50:00 +0530133 struct drm_display_mode *mode)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900134{
Rahul Sharma438c0f82013-01-15 08:11:05 -0500135 int ret = 0;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900136
Rahul Sharma438c0f82013-01-15 08:11:05 -0500137 /*
138 * Both, mixer and hdmi should be able to handle the requested mode.
139 * If any of the two fails, return mode as BAD.
140 */
141
Rahul Sharma16844fb2013-06-10 14:50:00 +0530142 if (mixer_ops && mixer_ops->check_mode)
143 ret = mixer_ops->check_mode(ctx->mixer_ctx->ctx, mode);
Rahul Sharma438c0f82013-01-15 08:11:05 -0500144
145 if (ret)
146 return ret;
147
Rahul Sharma16844fb2013-06-10 14:50:00 +0530148 if (hdmi_ops && hdmi_ops->check_mode)
149 return hdmi_ops->check_mode(ctx->hdmi_ctx->ctx, mode);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900150
151 return 0;
152}
153
Sean Paulbb7704d2014-01-30 16:19:06 -0500154static int drm_hdmi_check_mode(struct device *dev,
155 struct drm_display_mode *mode)
156{
157 struct drm_hdmi_context *ctx = to_context(dev);
158
159 return drm_hdmi_check_mode_ctx(ctx, mode);
160}
161
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900162static int drm_hdmi_power_on(struct device *dev, int mode)
163{
164 struct drm_hdmi_context *ctx = to_context(dev);
165
Joonyoung Shim578b6062012-04-05 20:49:26 +0900166 if (hdmi_ops && hdmi_ops->power_on)
167 return hdmi_ops->power_on(ctx->hdmi_ctx->ctx, mode);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900168
169 return 0;
170}
171
172static struct exynos_drm_display_ops drm_hdmi_display_ops = {
173 .type = EXYNOS_DISPLAY_TYPE_HDMI,
Sean Paul45517892014-01-30 16:19:05 -0500174 .initialize = drm_hdmi_display_initialize,
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900175 .is_connected = drm_hdmi_is_connected,
176 .get_edid = drm_hdmi_get_edid,
Rahul Sharma16844fb2013-06-10 14:50:00 +0530177 .check_mode = drm_hdmi_check_mode,
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900178 .power_on = drm_hdmi_power_on,
179};
180
Sean Paulbb7704d2014-01-30 16:19:06 -0500181static int drm_hdmi_enable_vblank(struct exynos_drm_manager *mgr)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900182{
Sean Paulbb7704d2014-01-30 16:19:06 -0500183 struct drm_hdmi_context *ctx = mgr->ctx;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900184 struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900185 struct exynos_drm_manager *manager = subdrv->manager;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900186
Joonyoung Shim578b6062012-04-05 20:49:26 +0900187 if (mixer_ops && mixer_ops->enable_vblank)
188 return mixer_ops->enable_vblank(ctx->mixer_ctx->ctx,
189 manager->pipe);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900190
191 return 0;
192}
193
Sean Paulbb7704d2014-01-30 16:19:06 -0500194static void drm_hdmi_disable_vblank(struct exynos_drm_manager *mgr)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900195{
Sean Paulbb7704d2014-01-30 16:19:06 -0500196 struct drm_hdmi_context *ctx = mgr->ctx;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900197
Joonyoung Shim578b6062012-04-05 20:49:26 +0900198 if (mixer_ops && mixer_ops->disable_vblank)
199 return mixer_ops->disable_vblank(ctx->mixer_ctx->ctx);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900200}
201
Sean Paulbb7704d2014-01-30 16:19:06 -0500202static void drm_hdmi_wait_for_vblank(struct exynos_drm_manager *mgr)
Prathyush K8137a2e2012-12-06 20:16:01 +0530203{
Sean Paulbb7704d2014-01-30 16:19:06 -0500204 struct drm_hdmi_context *ctx = mgr->ctx;
Prathyush K8137a2e2012-12-06 20:16:01 +0530205
Prathyush K8137a2e2012-12-06 20:16:01 +0530206 if (mixer_ops && mixer_ops->wait_for_vblank)
207 mixer_ops->wait_for_vblank(ctx->mixer_ctx->ctx);
208}
209
Sean Paulbb7704d2014-01-30 16:19:06 -0500210static void drm_hdmi_mode_fixup(struct exynos_drm_manager *mgr,
Inki Dae1de425b2012-03-16 18:47:04 +0900211 struct drm_connector *connector,
Laurent Pincharte811f5a2012-07-17 17:56:50 +0200212 const struct drm_display_mode *mode,
Inki Dae1de425b2012-03-16 18:47:04 +0900213 struct drm_display_mode *adjusted_mode)
214{
Sean Paulbb7704d2014-01-30 16:19:06 -0500215 struct drm_hdmi_context *ctx = mgr->ctx;
Rahul Sharma7ddcc732013-03-06 17:28:16 +0900216 struct drm_display_mode *m;
217 int mode_ok;
Inki Dae1de425b2012-03-16 18:47:04 +0900218
Rahul Sharma7ddcc732013-03-06 17:28:16 +0900219 drm_mode_set_crtcinfo(adjusted_mode, 0);
220
Sean Paulbb7704d2014-01-30 16:19:06 -0500221 mode_ok = drm_hdmi_check_mode_ctx(ctx, adjusted_mode);
Rahul Sharma7ddcc732013-03-06 17:28:16 +0900222
223 /* just return if user desired mode exists. */
224 if (mode_ok == 0)
225 return;
226
227 /*
228 * otherwise, find the most suitable mode among modes and change it
229 * to adjusted_mode.
230 */
231 list_for_each_entry(m, &connector->modes, head) {
Sean Paulbb7704d2014-01-30 16:19:06 -0500232 mode_ok = drm_hdmi_check_mode_ctx(ctx, m);
Rahul Sharma7ddcc732013-03-06 17:28:16 +0900233
234 if (mode_ok == 0) {
235 struct drm_mode_object base;
236 struct list_head head;
237
238 DRM_INFO("desired mode doesn't exist so\n");
239 DRM_INFO("use the most suitable mode among modes.\n");
240
241 DRM_DEBUG_KMS("Adjusted Mode: [%d]x[%d] [%d]Hz\n",
242 m->hdisplay, m->vdisplay, m->vrefresh);
243
244 /* preserve display mode header while copying. */
245 head = adjusted_mode->head;
246 base = adjusted_mode->base;
247 memcpy(adjusted_mode, m, sizeof(*m));
248 adjusted_mode->head = head;
249 adjusted_mode->base = base;
250 break;
251 }
252 }
Inki Dae1de425b2012-03-16 18:47:04 +0900253}
254
Sean Paulbb7704d2014-01-30 16:19:06 -0500255static void drm_hdmi_mode_set(struct exynos_drm_manager *mgr, void *mode)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900256{
Sean Paulbb7704d2014-01-30 16:19:06 -0500257 struct drm_hdmi_context *ctx = mgr->ctx;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900258
Joonyoung Shim578b6062012-04-05 20:49:26 +0900259 if (hdmi_ops && hdmi_ops->mode_set)
260 hdmi_ops->mode_set(ctx->hdmi_ctx->ctx, mode);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900261}
262
Sean Paulbb7704d2014-01-30 16:19:06 -0500263static void drm_hdmi_get_max_resol(struct exynos_drm_manager *mgr,
Inki Dae1de425b2012-03-16 18:47:04 +0900264 unsigned int *width, unsigned int *height)
265{
Sean Paulbb7704d2014-01-30 16:19:06 -0500266 struct drm_hdmi_context *ctx = mgr->ctx;
Inki Dae1de425b2012-03-16 18:47:04 +0900267
Joonyoung Shim578b6062012-04-05 20:49:26 +0900268 if (hdmi_ops && hdmi_ops->get_max_resol)
269 hdmi_ops->get_max_resol(ctx->hdmi_ctx->ctx, width, height);
Inki Dae1de425b2012-03-16 18:47:04 +0900270}
271
Sean Paulbb7704d2014-01-30 16:19:06 -0500272static void drm_hdmi_commit(struct exynos_drm_manager *mgr)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900273{
Sean Paulbb7704d2014-01-30 16:19:06 -0500274 struct drm_hdmi_context *ctx = mgr->ctx;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900275
Joonyoung Shim578b6062012-04-05 20:49:26 +0900276 if (hdmi_ops && hdmi_ops->commit)
277 hdmi_ops->commit(ctx->hdmi_ctx->ctx);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900278}
279
Sean Paulbb7704d2014-01-30 16:19:06 -0500280static int drm_hdmi_mgr_initialize(struct exynos_drm_manager *mgr, struct drm_device *drm_dev)
Sean Paul45517892014-01-30 16:19:05 -0500281{
Sean Paulbb7704d2014-01-30 16:19:06 -0500282 struct drm_hdmi_context *ctx = mgr->ctx;
Sean Paul45517892014-01-30 16:19:05 -0500283 int ret = 0;
284
285 if (mixer_ops && mixer_ops->initialize)
286 ret = mixer_ops->initialize(ctx->mixer_ctx->ctx, drm_dev);
287
288 if (mixer_ops->iommu_on)
289 mixer_ops->iommu_on(ctx->mixer_ctx->ctx, true);
290
291 return ret;
292}
293
Sean Paulbb7704d2014-01-30 16:19:06 -0500294static void drm_hdmi_dpms(struct exynos_drm_manager *mgr, int mode)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900295{
Sean Paulbb7704d2014-01-30 16:19:06 -0500296 struct drm_hdmi_context *ctx = mgr->ctx;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900297
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900298 if (mixer_ops && mixer_ops->dpms)
299 mixer_ops->dpms(ctx->mixer_ctx->ctx, mode);
300
301 if (hdmi_ops && hdmi_ops->dpms)
302 hdmi_ops->dpms(ctx->hdmi_ctx->ctx, mode);
303}
304
Sean Paulbb7704d2014-01-30 16:19:06 -0500305static void drm_hdmi_apply(struct exynos_drm_manager *mgr)
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900306{
Sean Paulbb7704d2014-01-30 16:19:06 -0500307 struct drm_hdmi_context *ctx = mgr->ctx;
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900308 int i;
309
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900310 for (i = 0; i < MIXER_WIN_NR; i++) {
311 if (!ctx->enabled[i])
312 continue;
313 if (mixer_ops && mixer_ops->win_commit)
314 mixer_ops->win_commit(ctx->mixer_ctx->ctx, i);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900315 }
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900316
317 if (hdmi_ops && hdmi_ops->commit)
318 hdmi_ops->commit(ctx->hdmi_ctx->ctx);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900319}
320
Sean Paulbb7704d2014-01-30 16:19:06 -0500321static void drm_mixer_win_mode_set(struct exynos_drm_manager *mgr,
322 struct exynos_drm_overlay *overlay)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900323{
Sean Paulbb7704d2014-01-30 16:19:06 -0500324 struct drm_hdmi_context *ctx = mgr->ctx;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900325
Joonyoung Shim578b6062012-04-05 20:49:26 +0900326 if (mixer_ops && mixer_ops->win_mode_set)
327 mixer_ops->win_mode_set(ctx->mixer_ctx->ctx, overlay);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900328}
329
Sean Paulbb7704d2014-01-30 16:19:06 -0500330static void drm_mixer_win_commit(struct exynos_drm_manager *mgr, int zpos)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900331{
Sean Paulbb7704d2014-01-30 16:19:06 -0500332 struct drm_hdmi_context *ctx = mgr->ctx;
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900333 int win = (zpos == DEFAULT_ZPOS) ? MIXER_DEFAULT_WIN : zpos;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900334
Krzysztof Kozlowski1586d802013-05-27 15:00:43 +0900335 if (win < 0 || win >= MIXER_WIN_NR) {
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900336 DRM_ERROR("mixer window[%d] is wrong\n", win);
337 return;
338 }
339
Joonyoung Shim578b6062012-04-05 20:49:26 +0900340 if (mixer_ops && mixer_ops->win_commit)
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900341 mixer_ops->win_commit(ctx->mixer_ctx->ctx, win);
342
343 ctx->enabled[win] = true;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900344}
345
Sean Paulbb7704d2014-01-30 16:19:06 -0500346static void drm_mixer_win_disable(struct exynos_drm_manager *mgr, int zpos)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900347{
Sean Paulbb7704d2014-01-30 16:19:06 -0500348 struct drm_hdmi_context *ctx = mgr->ctx;
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900349 int win = (zpos == DEFAULT_ZPOS) ? MIXER_DEFAULT_WIN : zpos;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900350
Krzysztof Kozlowski1586d802013-05-27 15:00:43 +0900351 if (win < 0 || win >= MIXER_WIN_NR) {
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900352 DRM_ERROR("mixer window[%d] is wrong\n", win);
353 return;
354 }
355
Joonyoung Shim578b6062012-04-05 20:49:26 +0900356 if (mixer_ops && mixer_ops->win_disable)
Joonyoung Shimcf8fc4f2012-04-23 19:35:50 +0900357 mixer_ops->win_disable(ctx->mixer_ctx->ctx, win);
358
359 ctx->enabled[win] = false;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900360}
361
Sean Paul1c6244c2014-01-30 16:19:02 -0500362static struct exynos_drm_manager_ops drm_hdmi_manager_ops = {
Sean Paul45517892014-01-30 16:19:05 -0500363 .initialize = drm_hdmi_mgr_initialize,
Sean Paul1c6244c2014-01-30 16:19:02 -0500364 .dpms = drm_hdmi_dpms,
365 .apply = drm_hdmi_apply,
366 .enable_vblank = drm_hdmi_enable_vblank,
367 .disable_vblank = drm_hdmi_disable_vblank,
368 .wait_for_vblank = drm_hdmi_wait_for_vblank,
369 .mode_fixup = drm_hdmi_mode_fixup,
370 .mode_set = drm_hdmi_mode_set,
371 .get_max_resol = drm_hdmi_get_max_resol,
372 .commit = drm_hdmi_commit,
373 .win_mode_set = drm_mixer_win_mode_set,
374 .win_commit = drm_mixer_win_commit,
375 .win_disable = drm_mixer_win_disable,
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900376};
377
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900378static struct exynos_drm_manager hdmi_manager = {
379 .pipe = -1,
380 .ops = &drm_hdmi_manager_ops,
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900381 .display_ops = &drm_hdmi_display_ops,
382};
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900383
384static int hdmi_subdrv_probe(struct drm_device *drm_dev,
385 struct device *dev)
386{
387 struct exynos_drm_subdrv *subdrv = to_subdrv(dev);
388 struct drm_hdmi_context *ctx;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900389
Rahul Sharma768c3052012-10-04 20:48:56 +0530390 if (!hdmi_ctx) {
391 DRM_ERROR("hdmi context not initialized.\n");
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900392 return -EFAULT;
393 }
394
Rahul Sharma768c3052012-10-04 20:48:56 +0530395 if (!mixer_ctx) {
396 DRM_ERROR("mixer context not initialized.\n");
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900397 return -EFAULT;
398 }
399
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900400 ctx = get_ctx_from_subdrv(subdrv);
401
Rahul Sharma768c3052012-10-04 20:48:56 +0530402 if (!ctx) {
403 DRM_ERROR("no drm hdmi context.\n");
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900404 return -EFAULT;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900405 }
406
Rahul Sharma768c3052012-10-04 20:48:56 +0530407 ctx->hdmi_ctx = hdmi_ctx;
408 ctx->mixer_ctx = mixer_ctx;
409
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900410 return 0;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900411}
412
Inki Dae1055b392012-10-19 17:37:35 +0900413static void hdmi_subdrv_remove(struct drm_device *drm_dev, struct device *dev)
414{
415 struct drm_hdmi_context *ctx;
416 struct exynos_drm_subdrv *subdrv = to_subdrv(dev);
417
418 ctx = get_ctx_from_subdrv(subdrv);
419
420 if (mixer_ops->iommu_on)
421 mixer_ops->iommu_on(ctx->mixer_ctx->ctx, false);
422}
423
Greg Kroah-Hartman56550d92012-12-21 15:09:25 -0800424static int exynos_drm_hdmi_probe(struct platform_device *pdev)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900425{
426 struct device *dev = &pdev->dev;
427 struct exynos_drm_subdrv *subdrv;
428 struct drm_hdmi_context *ctx;
429
Seung-Woo Kimd873ab92013-05-22 21:14:14 +0900430 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
Sachin Kamat38bb5252013-08-19 19:04:55 +0900431 if (!ctx)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900432 return -ENOMEM;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900433
Sean Paulbb7704d2014-01-30 16:19:06 -0500434 hdmi_manager.ctx = ctx;
435
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900436 subdrv = &ctx->subdrv;
437
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900438 subdrv->dev = dev;
439 subdrv->manager = &hdmi_manager;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900440 subdrv->probe = hdmi_subdrv_probe;
Inki Dae1055b392012-10-19 17:37:35 +0900441 subdrv->remove = hdmi_subdrv_remove;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900442
443 platform_set_drvdata(pdev, subdrv);
444
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900445 exynos_drm_subdrv_register(subdrv);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900446
447 return 0;
448}
449
Greg Kroah-Hartman56550d92012-12-21 15:09:25 -0800450static int exynos_drm_hdmi_remove(struct platform_device *pdev)
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900451{
452 struct drm_hdmi_context *ctx = platform_get_drvdata(pdev);
453
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900454 exynos_drm_subdrv_unregister(&ctx->subdrv);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900455
456 return 0;
457}
458
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900459struct platform_driver exynos_drm_common_hdmi_driver = {
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900460 .probe = exynos_drm_hdmi_probe,
Greg Kroah-Hartman56550d92012-12-21 15:09:25 -0800461 .remove = exynos_drm_hdmi_remove,
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900462 .driver = {
463 .name = "exynos-drm-hdmi",
464 .owner = THIS_MODULE,
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900465 },
466};