2 * Copyright (C) 2011 Samsung Electronics Co.Ltd
4 * Inki Dae <inki.dae@samsung.com>
5 * Seung-Woo Kim <sw0312.kim@samsung.com>
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.
16 #include <linux/kernel.h>
17 #include <linux/wait.h>
18 #include <linux/module.h>
19 #include <linux/platform_device.h>
20 #include <linux/pm_runtime.h>
22 #include <drm/exynos_drm.h>
24 #include "exynos_drm_drv.h"
25 #include "exynos_drm_hdmi.h"
27 #define to_context(dev) platform_get_drvdata(to_platform_device(dev))
28 #define to_subdrv(dev) to_context(dev)
29 #define get_ctx_from_subdrv(subdrv) container_of(subdrv,\
30 struct drm_hdmi_context, subdrv);
32 /* platform device pointer for common drm hdmi device. */
33 static struct platform_device *exynos_drm_hdmi_pdev;
35 /* Common hdmi subdrv needs to access the hdmi and mixer though context.
36 * These should be initialied by the repective drivers */
37 static struct exynos_drm_hdmi_context *hdmi_ctx;
38 static struct exynos_drm_hdmi_context *mixer_ctx;
40 /* these callback points shoud be set by specific drivers. */
41 static struct exynos_hdmi_ops *hdmi_ops;
42 static struct exynos_mixer_ops *mixer_ops;
44 struct drm_hdmi_context {
45 struct exynos_drm_subdrv subdrv;
46 struct exynos_drm_hdmi_context *hdmi_ctx;
47 struct exynos_drm_hdmi_context *mixer_ctx;
49 bool enabled[MIXER_WIN_NR];
52 int exynos_platform_device_hdmi_register(void)
54 if (exynos_drm_hdmi_pdev)
57 exynos_drm_hdmi_pdev = platform_device_register_simple(
58 "exynos-drm-hdmi", -1, NULL, 0);
59 if (IS_ERR_OR_NULL(exynos_drm_hdmi_pdev))
60 return PTR_ERR(exynos_drm_hdmi_pdev);
65 void exynos_platform_device_hdmi_unregister(void)
67 if (exynos_drm_hdmi_pdev)
68 platform_device_unregister(exynos_drm_hdmi_pdev);
71 void exynos_hdmi_drv_attach(struct exynos_drm_hdmi_context *ctx)
77 void exynos_mixer_drv_attach(struct exynos_drm_hdmi_context *ctx)
83 void exynos_hdmi_ops_register(struct exynos_hdmi_ops *ops)
85 DRM_DEBUG_KMS("%s\n", __FILE__);
91 void exynos_mixer_ops_register(struct exynos_mixer_ops *ops)
93 DRM_DEBUG_KMS("%s\n", __FILE__);
99 static bool drm_hdmi_is_connected(struct device *dev)
101 struct drm_hdmi_context *ctx = to_context(dev);
103 DRM_DEBUG_KMS("%s\n", __FILE__);
105 if (hdmi_ops && hdmi_ops->is_connected)
106 return hdmi_ops->is_connected(ctx->hdmi_ctx->ctx);
111 static int drm_hdmi_get_edid(struct device *dev,
112 struct drm_connector *connector, u8 *edid, int len)
114 struct drm_hdmi_context *ctx = to_context(dev);
116 DRM_DEBUG_KMS("%s\n", __FILE__);
118 if (hdmi_ops && hdmi_ops->get_edid)
119 return hdmi_ops->get_edid(ctx->hdmi_ctx->ctx, connector, edid,
125 static int drm_hdmi_check_timing(struct device *dev, void *timing)
127 struct drm_hdmi_context *ctx = to_context(dev);
129 DRM_DEBUG_KMS("%s\n", __FILE__);
131 if (hdmi_ops && hdmi_ops->check_timing)
132 return hdmi_ops->check_timing(ctx->hdmi_ctx->ctx, timing);
137 static int drm_hdmi_power_on(struct device *dev, int mode)
139 struct drm_hdmi_context *ctx = to_context(dev);
141 DRM_DEBUG_KMS("%s\n", __FILE__);
143 if (hdmi_ops && hdmi_ops->power_on)
144 return hdmi_ops->power_on(ctx->hdmi_ctx->ctx, mode);
149 static struct exynos_drm_display_ops drm_hdmi_display_ops = {
150 .type = EXYNOS_DISPLAY_TYPE_HDMI,
151 .is_connected = drm_hdmi_is_connected,
152 .get_edid = drm_hdmi_get_edid,
153 .check_timing = drm_hdmi_check_timing,
154 .power_on = drm_hdmi_power_on,
157 static int drm_hdmi_enable_vblank(struct device *subdrv_dev)
159 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
160 struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
161 struct exynos_drm_manager *manager = subdrv->manager;
163 DRM_DEBUG_KMS("%s\n", __FILE__);
165 if (mixer_ops && mixer_ops->enable_vblank)
166 return mixer_ops->enable_vblank(ctx->mixer_ctx->ctx,
172 static void drm_hdmi_disable_vblank(struct device *subdrv_dev)
174 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
176 DRM_DEBUG_KMS("%s\n", __FILE__);
178 if (mixer_ops && mixer_ops->disable_vblank)
179 return mixer_ops->disable_vblank(ctx->mixer_ctx->ctx);
182 static void drm_hdmi_mode_fixup(struct device *subdrv_dev,
183 struct drm_connector *connector,
184 const struct drm_display_mode *mode,
185 struct drm_display_mode *adjusted_mode)
187 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
189 DRM_DEBUG_KMS("%s\n", __FILE__);
191 if (hdmi_ops && hdmi_ops->mode_fixup)
192 hdmi_ops->mode_fixup(ctx->hdmi_ctx->ctx, connector, mode,
196 static void drm_hdmi_mode_set(struct device *subdrv_dev, void *mode)
198 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
200 DRM_DEBUG_KMS("%s\n", __FILE__);
202 if (hdmi_ops && hdmi_ops->mode_set)
203 hdmi_ops->mode_set(ctx->hdmi_ctx->ctx, mode);
206 static void drm_hdmi_get_max_resol(struct device *subdrv_dev,
207 unsigned int *width, unsigned int *height)
209 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
211 DRM_DEBUG_KMS("%s\n", __FILE__);
213 if (hdmi_ops && hdmi_ops->get_max_resol)
214 hdmi_ops->get_max_resol(ctx->hdmi_ctx->ctx, width, height);
217 static void drm_hdmi_commit(struct device *subdrv_dev)
219 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
221 DRM_DEBUG_KMS("%s\n", __FILE__);
223 if (hdmi_ops && hdmi_ops->commit)
224 hdmi_ops->commit(ctx->hdmi_ctx->ctx);
227 static void drm_hdmi_dpms(struct device *subdrv_dev, int mode)
229 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
231 DRM_DEBUG_KMS("%s\n", __FILE__);
233 if (mixer_ops && mixer_ops->dpms)
234 mixer_ops->dpms(ctx->mixer_ctx->ctx, mode);
236 if (hdmi_ops && hdmi_ops->dpms)
237 hdmi_ops->dpms(ctx->hdmi_ctx->ctx, mode);
240 static void drm_hdmi_apply(struct device *subdrv_dev)
242 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
245 DRM_DEBUG_KMS("%s\n", __FILE__);
247 for (i = 0; i < MIXER_WIN_NR; i++) {
248 if (!ctx->enabled[i])
250 if (mixer_ops && mixer_ops->win_commit)
251 mixer_ops->win_commit(ctx->mixer_ctx->ctx, i);
254 if (hdmi_ops && hdmi_ops->commit)
255 hdmi_ops->commit(ctx->hdmi_ctx->ctx);
258 static struct exynos_drm_manager_ops drm_hdmi_manager_ops = {
259 .dpms = drm_hdmi_dpms,
260 .apply = drm_hdmi_apply,
261 .enable_vblank = drm_hdmi_enable_vblank,
262 .disable_vblank = drm_hdmi_disable_vblank,
263 .mode_fixup = drm_hdmi_mode_fixup,
264 .mode_set = drm_hdmi_mode_set,
265 .get_max_resol = drm_hdmi_get_max_resol,
266 .commit = drm_hdmi_commit,
269 static void drm_mixer_mode_set(struct device *subdrv_dev,
270 struct exynos_drm_overlay *overlay)
272 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
274 DRM_DEBUG_KMS("%s\n", __FILE__);
276 if (mixer_ops && mixer_ops->win_mode_set)
277 mixer_ops->win_mode_set(ctx->mixer_ctx->ctx, overlay);
280 static void drm_mixer_commit(struct device *subdrv_dev, int zpos)
282 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
283 int win = (zpos == DEFAULT_ZPOS) ? MIXER_DEFAULT_WIN : zpos;
285 DRM_DEBUG_KMS("%s\n", __FILE__);
287 if (win < 0 || win > MIXER_WIN_NR) {
288 DRM_ERROR("mixer window[%d] is wrong\n", win);
292 if (mixer_ops && mixer_ops->win_commit)
293 mixer_ops->win_commit(ctx->mixer_ctx->ctx, win);
295 ctx->enabled[win] = true;
298 static void drm_mixer_disable(struct device *subdrv_dev, int zpos)
300 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
301 int win = (zpos == DEFAULT_ZPOS) ? MIXER_DEFAULT_WIN : zpos;
303 DRM_DEBUG_KMS("%s\n", __FILE__);
305 if (win < 0 || win > MIXER_WIN_NR) {
306 DRM_ERROR("mixer window[%d] is wrong\n", win);
310 if (mixer_ops && mixer_ops->win_disable)
311 mixer_ops->win_disable(ctx->mixer_ctx->ctx, win);
313 ctx->enabled[win] = false;
316 static void drm_mixer_wait_for_vblank(struct device *subdrv_dev)
318 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
320 DRM_DEBUG_KMS("%s\n", __FILE__);
322 if (mixer_ops && mixer_ops->wait_for_vblank)
323 mixer_ops->wait_for_vblank(ctx->mixer_ctx->ctx);
326 static struct exynos_drm_overlay_ops drm_hdmi_overlay_ops = {
327 .mode_set = drm_mixer_mode_set,
328 .commit = drm_mixer_commit,
329 .disable = drm_mixer_disable,
330 .wait_for_vblank = drm_mixer_wait_for_vblank,
333 static struct exynos_drm_manager hdmi_manager = {
335 .ops = &drm_hdmi_manager_ops,
336 .overlay_ops = &drm_hdmi_overlay_ops,
337 .display_ops = &drm_hdmi_display_ops,
340 static int hdmi_subdrv_probe(struct drm_device *drm_dev,
343 struct exynos_drm_subdrv *subdrv = to_subdrv(dev);
344 struct drm_hdmi_context *ctx;
346 DRM_DEBUG_KMS("%s\n", __FILE__);
349 DRM_ERROR("hdmi context not initialized.\n");
354 DRM_ERROR("mixer context not initialized.\n");
358 ctx = get_ctx_from_subdrv(subdrv);
361 DRM_ERROR("no drm hdmi context.\n");
365 ctx->hdmi_ctx = hdmi_ctx;
366 ctx->mixer_ctx = mixer_ctx;
368 ctx->hdmi_ctx->drm_dev = drm_dev;
369 ctx->mixer_ctx->drm_dev = drm_dev;
371 if (mixer_ops->iommu_on)
372 mixer_ops->iommu_on(ctx->mixer_ctx->ctx, true);
377 static void hdmi_subdrv_remove(struct drm_device *drm_dev, struct device *dev)
379 struct drm_hdmi_context *ctx;
380 struct exynos_drm_subdrv *subdrv = to_subdrv(dev);
382 ctx = get_ctx_from_subdrv(subdrv);
384 if (mixer_ops->iommu_on)
385 mixer_ops->iommu_on(ctx->mixer_ctx->ctx, false);
388 static int __devinit exynos_drm_hdmi_probe(struct platform_device *pdev)
390 struct device *dev = &pdev->dev;
391 struct exynos_drm_subdrv *subdrv;
392 struct drm_hdmi_context *ctx;
394 DRM_DEBUG_KMS("%s\n", __FILE__);
396 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
398 DRM_LOG_KMS("failed to alloc common hdmi context.\n");
402 subdrv = &ctx->subdrv;
405 subdrv->manager = &hdmi_manager;
406 subdrv->probe = hdmi_subdrv_probe;
407 subdrv->remove = hdmi_subdrv_remove;
409 platform_set_drvdata(pdev, subdrv);
411 exynos_drm_subdrv_register(subdrv);
416 static int __devexit exynos_drm_hdmi_remove(struct platform_device *pdev)
418 struct drm_hdmi_context *ctx = platform_get_drvdata(pdev);
420 DRM_DEBUG_KMS("%s\n", __FILE__);
422 exynos_drm_subdrv_unregister(&ctx->subdrv);
427 struct platform_driver exynos_drm_common_hdmi_driver = {
428 .probe = exynos_drm_hdmi_probe,
429 .remove = __devexit_p(exynos_drm_hdmi_remove),
431 .name = "exynos-drm-hdmi",
432 .owner = THIS_MODULE,