blob: 3424463676e0997d4f653b11a400c7cf1f8aefd9 [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
14#include "drmP.h"
15
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>
21
22#include <drm/exynos_drm.h>
23
24#include "exynos_drm_drv.h"
25#include "exynos_drm_hdmi.h"
26
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);
31
32/* these callback points shoud be set by specific drivers. */
Joonyoung Shim578b6062012-04-05 20:49:26 +090033static struct exynos_hdmi_ops *hdmi_ops;
34static struct exynos_mixer_ops *mixer_ops;
Seung-Woo Kimd8408322011-12-21 17:39:39 +090035
36struct 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;
Seung-Woo Kimd8408322011-12-21 17:39:39 +090040};
41
Joonyoung Shim578b6062012-04-05 20:49:26 +090042void exynos_hdmi_ops_register(struct exynos_hdmi_ops *ops)
Seung-Woo Kimd8408322011-12-21 17:39:39 +090043{
44 DRM_DEBUG_KMS("%s\n", __FILE__);
45
Joonyoung Shim578b6062012-04-05 20:49:26 +090046 if (ops)
47 hdmi_ops = ops;
Seung-Woo Kimd8408322011-12-21 17:39:39 +090048}
Seung-Woo Kimd8408322011-12-21 17:39:39 +090049
Joonyoung Shim578b6062012-04-05 20:49:26 +090050void exynos_mixer_ops_register(struct exynos_mixer_ops *ops)
Seung-Woo Kimd8408322011-12-21 17:39:39 +090051{
52 DRM_DEBUG_KMS("%s\n", __FILE__);
53
Joonyoung Shim578b6062012-04-05 20:49:26 +090054 if (ops)
55 mixer_ops = ops;
Seung-Woo Kimd8408322011-12-21 17:39:39 +090056}
Seung-Woo Kimd8408322011-12-21 17:39:39 +090057
58static bool drm_hdmi_is_connected(struct device *dev)
59{
60 struct drm_hdmi_context *ctx = to_context(dev);
61
62 DRM_DEBUG_KMS("%s\n", __FILE__);
63
Joonyoung Shim578b6062012-04-05 20:49:26 +090064 if (hdmi_ops && hdmi_ops->is_connected)
65 return hdmi_ops->is_connected(ctx->hdmi_ctx->ctx);
Seung-Woo Kimd8408322011-12-21 17:39:39 +090066
67 return false;
68}
69
70static int drm_hdmi_get_edid(struct device *dev,
71 struct drm_connector *connector, u8 *edid, int len)
72{
73 struct drm_hdmi_context *ctx = to_context(dev);
74
75 DRM_DEBUG_KMS("%s\n", __FILE__);
76
Joonyoung Shim578b6062012-04-05 20:49:26 +090077 if (hdmi_ops && hdmi_ops->get_edid)
78 return hdmi_ops->get_edid(ctx->hdmi_ctx->ctx, connector, edid,
79 len);
Seung-Woo Kimd8408322011-12-21 17:39:39 +090080
81 return 0;
82}
83
84static int drm_hdmi_check_timing(struct device *dev, void *timing)
85{
86 struct drm_hdmi_context *ctx = to_context(dev);
87
88 DRM_DEBUG_KMS("%s\n", __FILE__);
89
Joonyoung Shim578b6062012-04-05 20:49:26 +090090 if (hdmi_ops && hdmi_ops->check_timing)
91 return hdmi_ops->check_timing(ctx->hdmi_ctx->ctx, timing);
Seung-Woo Kimd8408322011-12-21 17:39:39 +090092
93 return 0;
94}
95
96static int drm_hdmi_power_on(struct device *dev, int mode)
97{
98 struct drm_hdmi_context *ctx = to_context(dev);
99
100 DRM_DEBUG_KMS("%s\n", __FILE__);
101
Joonyoung Shim578b6062012-04-05 20:49:26 +0900102 if (hdmi_ops && hdmi_ops->power_on)
103 return hdmi_ops->power_on(ctx->hdmi_ctx->ctx, mode);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900104
105 return 0;
106}
107
108static 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,
114};
115
116static int drm_hdmi_enable_vblank(struct device *subdrv_dev)
117{
118 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
119 struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900120 struct exynos_drm_manager *manager = subdrv->manager;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900121
122 DRM_DEBUG_KMS("%s\n", __FILE__);
123
Joonyoung Shim578b6062012-04-05 20:49:26 +0900124 if (mixer_ops && mixer_ops->enable_vblank)
125 return mixer_ops->enable_vblank(ctx->mixer_ctx->ctx,
126 manager->pipe);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900127
128 return 0;
129}
130
131static void drm_hdmi_disable_vblank(struct device *subdrv_dev)
132{
133 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
134
135 DRM_DEBUG_KMS("%s\n", __FILE__);
136
Joonyoung Shim578b6062012-04-05 20:49:26 +0900137 if (mixer_ops && mixer_ops->disable_vblank)
138 return mixer_ops->disable_vblank(ctx->mixer_ctx->ctx);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900139}
140
Inki Dae1de425b2012-03-16 18:47:04 +0900141static 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)
145{
146 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
147
148 DRM_DEBUG_KMS("%s\n", __FILE__);
149
Joonyoung Shim578b6062012-04-05 20:49:26 +0900150 if (hdmi_ops && hdmi_ops->mode_fixup)
151 hdmi_ops->mode_fixup(ctx->hdmi_ctx->ctx, connector, mode,
152 adjusted_mode);
Inki Dae1de425b2012-03-16 18:47:04 +0900153}
154
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900155static void drm_hdmi_mode_set(struct device *subdrv_dev, void *mode)
156{
157 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
158
159 DRM_DEBUG_KMS("%s\n", __FILE__);
160
Joonyoung Shim578b6062012-04-05 20:49:26 +0900161 if (hdmi_ops && hdmi_ops->mode_set)
162 hdmi_ops->mode_set(ctx->hdmi_ctx->ctx, mode);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900163}
164
Inki Dae1de425b2012-03-16 18:47:04 +0900165static void drm_hdmi_get_max_resol(struct device *subdrv_dev,
166 unsigned int *width, unsigned int *height)
167{
168 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
169
170 DRM_DEBUG_KMS("%s\n", __FILE__);
171
Joonyoung Shim578b6062012-04-05 20:49:26 +0900172 if (hdmi_ops && hdmi_ops->get_max_resol)
173 hdmi_ops->get_max_resol(ctx->hdmi_ctx->ctx, width, height);
Inki Dae1de425b2012-03-16 18:47:04 +0900174}
175
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900176static void drm_hdmi_commit(struct device *subdrv_dev)
177{
178 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
179
180 DRM_DEBUG_KMS("%s\n", __FILE__);
181
Joonyoung Shim578b6062012-04-05 20:49:26 +0900182 if (hdmi_ops && hdmi_ops->commit)
183 hdmi_ops->commit(ctx->hdmi_ctx->ctx);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900184}
185
186static void drm_hdmi_dpms(struct device *subdrv_dev, int mode)
187{
188 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
189
190 DRM_DEBUG_KMS("%s\n", __FILE__);
191
192 switch (mode) {
193 case DRM_MODE_DPMS_ON:
194 break;
195 case DRM_MODE_DPMS_STANDBY:
196 case DRM_MODE_DPMS_SUSPEND:
197 case DRM_MODE_DPMS_OFF:
Joonyoung Shim578b6062012-04-05 20:49:26 +0900198 if (hdmi_ops && hdmi_ops->disable)
199 hdmi_ops->disable(ctx->hdmi_ctx->ctx);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900200 break;
201 default:
202 DRM_DEBUG_KMS("unkown dps mode: %d\n", mode);
203 break;
204 }
205}
206
207static 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,
Inki Dae1de425b2012-03-16 18:47:04 +0900211 .mode_fixup = drm_hdmi_mode_fixup,
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900212 .mode_set = drm_hdmi_mode_set,
Inki Dae1de425b2012-03-16 18:47:04 +0900213 .get_max_resol = drm_hdmi_get_max_resol,
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900214 .commit = drm_hdmi_commit,
215};
216
217static void drm_mixer_mode_set(struct device *subdrv_dev,
218 struct exynos_drm_overlay *overlay)
219{
220 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
221
222 DRM_DEBUG_KMS("%s\n", __FILE__);
223
Joonyoung Shim578b6062012-04-05 20:49:26 +0900224 if (mixer_ops && mixer_ops->win_mode_set)
225 mixer_ops->win_mode_set(ctx->mixer_ctx->ctx, overlay);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900226}
227
228static void drm_mixer_commit(struct device *subdrv_dev, int zpos)
229{
230 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
231
232 DRM_DEBUG_KMS("%s\n", __FILE__);
233
Joonyoung Shim578b6062012-04-05 20:49:26 +0900234 if (mixer_ops && mixer_ops->win_commit)
235 mixer_ops->win_commit(ctx->mixer_ctx->ctx, zpos);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900236}
237
238static void drm_mixer_disable(struct device *subdrv_dev, int zpos)
239{
240 struct drm_hdmi_context *ctx = to_context(subdrv_dev);
241
242 DRM_DEBUG_KMS("%s\n", __FILE__);
243
Joonyoung Shim578b6062012-04-05 20:49:26 +0900244 if (mixer_ops && mixer_ops->win_disable)
245 mixer_ops->win_disable(ctx->mixer_ctx->ctx, zpos);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900246}
247
248static 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,
252};
253
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900254static struct exynos_drm_manager hdmi_manager = {
255 .pipe = -1,
256 .ops = &drm_hdmi_manager_ops,
257 .overlay_ops = &drm_hdmi_overlay_ops,
258 .display_ops = &drm_hdmi_display_ops,
259};
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900260
261static int hdmi_subdrv_probe(struct drm_device *drm_dev,
262 struct device *dev)
263{
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;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900268
269 DRM_DEBUG_KMS("%s\n", __FILE__);
270
271 pd = pdev->dev.platform_data;
272
273 if (!pd) {
274 DRM_DEBUG_KMS("platform data is null.\n");
275 return -EFAULT;
276 }
277
278 if (!pd->hdmi_dev) {
279 DRM_DEBUG_KMS("hdmi device is null.\n");
280 return -EFAULT;
281 }
282
283 if (!pd->mixer_dev) {
284 DRM_DEBUG_KMS("mixer device is null.\n");
285 return -EFAULT;
286 }
287
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900288 ctx = get_ctx_from_subdrv(subdrv);
289
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");
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900294 return -EFAULT;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900295 }
296
297 ctx->hdmi_ctx->drm_dev = drm_dev;
298
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");
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900303 return -EFAULT;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900304 }
305
306 ctx->mixer_ctx->drm_dev = drm_dev;
307
308 return 0;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900309}
310
311static int __devinit exynos_drm_hdmi_probe(struct platform_device *pdev)
312{
313 struct device *dev = &pdev->dev;
314 struct exynos_drm_subdrv *subdrv;
315 struct drm_hdmi_context *ctx;
316
317 DRM_DEBUG_KMS("%s\n", __FILE__);
318
319 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
320 if (!ctx) {
321 DRM_LOG_KMS("failed to alloc common hdmi context.\n");
322 return -ENOMEM;
323 }
324
325 subdrv = &ctx->subdrv;
326
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900327 subdrv->dev = dev;
328 subdrv->manager = &hdmi_manager;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900329 subdrv->probe = hdmi_subdrv_probe;
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900330
331 platform_set_drvdata(pdev, subdrv);
332
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900333 exynos_drm_subdrv_register(subdrv);
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900334
335 return 0;
336}
337
338static int hdmi_runtime_suspend(struct device *dev)
339{
340 DRM_DEBUG_KMS("%s\n", __FILE__);
341
342 return 0;
343}
344
345static int hdmi_runtime_resume(struct device *dev)
346{
347 DRM_DEBUG_KMS("%s\n", __FILE__);
348
349 return 0;
350}
351
352static const struct dev_pm_ops hdmi_pm_ops = {
353 .runtime_suspend = hdmi_runtime_suspend,
354 .runtime_resume = hdmi_runtime_resume,
355};
356
357static int __devexit exynos_drm_hdmi_remove(struct platform_device *pdev)
358{
359 struct drm_hdmi_context *ctx = platform_get_drvdata(pdev);
360
361 DRM_DEBUG_KMS("%s\n", __FILE__);
362
363 exynos_drm_subdrv_unregister(&ctx->subdrv);
364 kfree(ctx);
365
366 return 0;
367}
368
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900369struct platform_driver exynos_drm_common_hdmi_driver = {
Seung-Woo Kimd8408322011-12-21 17:39:39 +0900370 .probe = exynos_drm_hdmi_probe,
371 .remove = __devexit_p(exynos_drm_hdmi_remove),
372 .driver = {
373 .name = "exynos-drm-hdmi",
374 .owner = THIS_MODULE,
375 .pm = &hdmi_pm_ops,
376 },
377};