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 /* these callback points shoud be set by specific drivers. */
33 static struct exynos_hdmi_ops *hdmi_ops;
34 static struct exynos_mixer_ops *mixer_ops;
36 struct drm_hdmi_context {
37 struct exynos_drm_subdrv subdrv;
38 struct exynos_drm_hdmi_context *hdmi_ctx;
39 struct exynos_drm_hdmi_context *mixer_ctx;
42 void exynos_hdmi_ops_register(struct exynos_hdmi_ops *ops)
44 DRM_DEBUG_KMS("%s\n", __FILE__);
50 void exynos_mixer_ops_register(struct exynos_mixer_ops *ops)
52 DRM_DEBUG_KMS("%s\n", __FILE__);
58 static bool drm_hdmi_is_connected(struct device *dev)
60 struct drm_hdmi_context *ctx = to_context(dev);
62 DRM_DEBUG_KMS("%s\n", __FILE__);
64 if (hdmi_ops && hdmi_ops->is_connected)
65 return hdmi_ops->is_connected(ctx->hdmi_ctx->ctx);
70 static int drm_hdmi_get_edid(struct device *dev,
71 struct drm_connector *connector, u8 *edid, int len)
73 struct drm_hdmi_context *ctx = to_context(dev);
75 DRM_DEBUG_KMS("%s\n", __FILE__);
77 if (hdmi_ops && hdmi_ops->get_edid)
78 return hdmi_ops->get_edid(ctx->hdmi_ctx->ctx, connector, edid,
84 static int drm_hdmi_check_timing(struct device *dev, void *timing)
86 struct drm_hdmi_context *ctx = to_context(dev);
88 DRM_DEBUG_KMS("%s\n", __FILE__);
90 if (hdmi_ops && hdmi_ops->check_timing)
91 return hdmi_ops->check_timing(ctx->hdmi_ctx->ctx, timing);
96 static int drm_hdmi_power_on(struct device *dev, int mode)
98 struct drm_hdmi_context *ctx = to_context(dev);
100 DRM_DEBUG_KMS("%s\n", __FILE__);
102 if (hdmi_ops && hdmi_ops->power_on)
103 return hdmi_ops->power_on(ctx->hdmi_ctx->ctx, mode);
108 static struct exynos_drm_display_ops drm_hdmi_display_ops = {
109 .type = EXYNOS_DISPLAY_TYPE_HDMI,
110 .is_connected = drm_hdmi_is_connected,
111 .get_edid = drm_hdmi_get_edid,
112 .check_timing = drm_hdmi_check_timing,
113 .power_on = drm_hdmi_power_on,
116 static int drm_hdmi_enable_vblank(struct device *subdrv_dev)
118 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
119 struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
120 struct exynos_drm_manager *manager = subdrv->manager;
122 DRM_DEBUG_KMS("%s\n", __FILE__);
124 if (mixer_ops && mixer_ops->enable_vblank)
125 return mixer_ops->enable_vblank(ctx->mixer_ctx->ctx,
131 static void drm_hdmi_disable_vblank(struct device *subdrv_dev)
133 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
135 DRM_DEBUG_KMS("%s\n", __FILE__);
137 if (mixer_ops && mixer_ops->disable_vblank)
138 return mixer_ops->disable_vblank(ctx->mixer_ctx->ctx);
141 static void drm_hdmi_mode_fixup(struct device *subdrv_dev,
142 struct drm_connector *connector,
143 struct drm_display_mode *mode,
144 struct drm_display_mode *adjusted_mode)
146 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
148 DRM_DEBUG_KMS("%s\n", __FILE__);
150 if (hdmi_ops && hdmi_ops->mode_fixup)
151 hdmi_ops->mode_fixup(ctx->hdmi_ctx->ctx, connector, mode,
155 static void drm_hdmi_mode_set(struct device *subdrv_dev, void *mode)
157 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
159 DRM_DEBUG_KMS("%s\n", __FILE__);
161 if (hdmi_ops && hdmi_ops->mode_set)
162 hdmi_ops->mode_set(ctx->hdmi_ctx->ctx, mode);
165 static void drm_hdmi_get_max_resol(struct device *subdrv_dev,
166 unsigned int *width, unsigned int *height)
168 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
170 DRM_DEBUG_KMS("%s\n", __FILE__);
172 if (hdmi_ops && hdmi_ops->get_max_resol)
173 hdmi_ops->get_max_resol(ctx->hdmi_ctx->ctx, width, height);
176 static void drm_hdmi_commit(struct device *subdrv_dev)
178 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
180 DRM_DEBUG_KMS("%s\n", __FILE__);
182 if (hdmi_ops && hdmi_ops->commit)
183 hdmi_ops->commit(ctx->hdmi_ctx->ctx);
186 static void drm_hdmi_dpms(struct device *subdrv_dev, int mode)
188 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
190 DRM_DEBUG_KMS("%s\n", __FILE__);
193 case DRM_MODE_DPMS_ON:
195 case DRM_MODE_DPMS_STANDBY:
196 case DRM_MODE_DPMS_SUSPEND:
197 case DRM_MODE_DPMS_OFF:
198 if (hdmi_ops && hdmi_ops->disable)
199 hdmi_ops->disable(ctx->hdmi_ctx->ctx);
202 DRM_DEBUG_KMS("unkown dps mode: %d\n", mode);
207 static struct exynos_drm_manager_ops drm_hdmi_manager_ops = {
208 .dpms = drm_hdmi_dpms,
209 .enable_vblank = drm_hdmi_enable_vblank,
210 .disable_vblank = drm_hdmi_disable_vblank,
211 .mode_fixup = drm_hdmi_mode_fixup,
212 .mode_set = drm_hdmi_mode_set,
213 .get_max_resol = drm_hdmi_get_max_resol,
214 .commit = drm_hdmi_commit,
217 static void drm_mixer_mode_set(struct device *subdrv_dev,
218 struct exynos_drm_overlay *overlay)
220 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
222 DRM_DEBUG_KMS("%s\n", __FILE__);
224 if (mixer_ops && mixer_ops->win_mode_set)
225 mixer_ops->win_mode_set(ctx->mixer_ctx->ctx, overlay);
228 static void drm_mixer_commit(struct device *subdrv_dev, int zpos)
230 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
232 DRM_DEBUG_KMS("%s\n", __FILE__);
234 if (mixer_ops && mixer_ops->win_commit)
235 mixer_ops->win_commit(ctx->mixer_ctx->ctx, zpos);
238 static void drm_mixer_disable(struct device *subdrv_dev, int zpos)
240 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
242 DRM_DEBUG_KMS("%s\n", __FILE__);
244 if (mixer_ops && mixer_ops->win_disable)
245 mixer_ops->win_disable(ctx->mixer_ctx->ctx, zpos);
248 static struct exynos_drm_overlay_ops drm_hdmi_overlay_ops = {
249 .mode_set = drm_mixer_mode_set,
250 .commit = drm_mixer_commit,
251 .disable = drm_mixer_disable,
254 static struct exynos_drm_manager hdmi_manager = {
256 .ops = &drm_hdmi_manager_ops,
257 .overlay_ops = &drm_hdmi_overlay_ops,
258 .display_ops = &drm_hdmi_display_ops,
261 static int hdmi_subdrv_probe(struct drm_device *drm_dev,
264 struct exynos_drm_subdrv *subdrv = to_subdrv(dev);
265 struct drm_hdmi_context *ctx;
266 struct platform_device *pdev = to_platform_device(dev);
267 struct exynos_drm_common_hdmi_pd *pd;
269 DRM_DEBUG_KMS("%s\n", __FILE__);
271 pd = pdev->dev.platform_data;
274 DRM_DEBUG_KMS("platform data is null.\n");
279 DRM_DEBUG_KMS("hdmi device is null.\n");
283 if (!pd->mixer_dev) {
284 DRM_DEBUG_KMS("mixer device is null.\n");
288 ctx = get_ctx_from_subdrv(subdrv);
290 ctx->hdmi_ctx = (struct exynos_drm_hdmi_context *)
291 to_context(pd->hdmi_dev);
292 if (!ctx->hdmi_ctx) {
293 DRM_DEBUG_KMS("hdmi context is null.\n");
297 ctx->hdmi_ctx->drm_dev = drm_dev;
299 ctx->mixer_ctx = (struct exynos_drm_hdmi_context *)
300 to_context(pd->mixer_dev);
301 if (!ctx->mixer_ctx) {
302 DRM_DEBUG_KMS("mixer context is null.\n");
306 ctx->mixer_ctx->drm_dev = drm_dev;
311 static int __devinit exynos_drm_hdmi_probe(struct platform_device *pdev)
313 struct device *dev = &pdev->dev;
314 struct exynos_drm_subdrv *subdrv;
315 struct drm_hdmi_context *ctx;
317 DRM_DEBUG_KMS("%s\n", __FILE__);
319 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
321 DRM_LOG_KMS("failed to alloc common hdmi context.\n");
325 subdrv = &ctx->subdrv;
328 subdrv->manager = &hdmi_manager;
329 subdrv->probe = hdmi_subdrv_probe;
331 platform_set_drvdata(pdev, subdrv);
333 exynos_drm_subdrv_register(subdrv);
338 static int hdmi_runtime_suspend(struct device *dev)
340 DRM_DEBUG_KMS("%s\n", __FILE__);
345 static int hdmi_runtime_resume(struct device *dev)
347 DRM_DEBUG_KMS("%s\n", __FILE__);
352 static const struct dev_pm_ops hdmi_pm_ops = {
353 .runtime_suspend = hdmi_runtime_suspend,
354 .runtime_resume = hdmi_runtime_resume,
357 static int __devexit exynos_drm_hdmi_remove(struct platform_device *pdev)
359 struct drm_hdmi_context *ctx = platform_get_drvdata(pdev);
361 DRM_DEBUG_KMS("%s\n", __FILE__);
363 exynos_drm_subdrv_unregister(&ctx->subdrv);
369 struct platform_driver exynos_drm_common_hdmi_driver = {
370 .probe = exynos_drm_hdmi_probe,
371 .remove = __devexit_p(exynos_drm_hdmi_remove),
373 .name = "exynos-drm-hdmi",
374 .owner = THIS_MODULE,