Commit | Line | Data |
---|---|---|
d8408326 SWK |
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 | ||
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. */ | |
578b6065 JS |
33 | static struct exynos_hdmi_ops *hdmi_ops; |
34 | static struct exynos_mixer_ops *mixer_ops; | |
d8408326 SWK |
35 | |
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; | |
d8408326 SWK |
40 | }; |
41 | ||
578b6065 | 42 | void exynos_hdmi_ops_register(struct exynos_hdmi_ops *ops) |
d8408326 SWK |
43 | { |
44 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
45 | ||
578b6065 JS |
46 | if (ops) |
47 | hdmi_ops = ops; | |
d8408326 | 48 | } |
d8408326 | 49 | |
578b6065 | 50 | void exynos_mixer_ops_register(struct exynos_mixer_ops *ops) |
d8408326 SWK |
51 | { |
52 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
53 | ||
578b6065 JS |
54 | if (ops) |
55 | mixer_ops = ops; | |
d8408326 | 56 | } |
d8408326 SWK |
57 | |
58 | static 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 | ||
578b6065 JS |
64 | if (hdmi_ops && hdmi_ops->is_connected) |
65 | return hdmi_ops->is_connected(ctx->hdmi_ctx->ctx); | |
d8408326 SWK |
66 | |
67 | return false; | |
68 | } | |
69 | ||
70 | static 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 | ||
578b6065 JS |
77 | if (hdmi_ops && hdmi_ops->get_edid) |
78 | return hdmi_ops->get_edid(ctx->hdmi_ctx->ctx, connector, edid, | |
79 | len); | |
d8408326 SWK |
80 | |
81 | return 0; | |
82 | } | |
83 | ||
84 | static 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 | ||
578b6065 JS |
90 | if (hdmi_ops && hdmi_ops->check_timing) |
91 | return hdmi_ops->check_timing(ctx->hdmi_ctx->ctx, timing); | |
d8408326 SWK |
92 | |
93 | return 0; | |
94 | } | |
95 | ||
96 | static 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 | ||
578b6065 JS |
102 | if (hdmi_ops && hdmi_ops->power_on) |
103 | return hdmi_ops->power_on(ctx->hdmi_ctx->ctx, mode); | |
d8408326 SWK |
104 | |
105 | return 0; | |
106 | } | |
107 | ||
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, | |
114 | }; | |
115 | ||
116 | static 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; | |
120 | struct exynos_drm_manager *manager = &subdrv->manager; | |
121 | ||
122 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
123 | ||
578b6065 JS |
124 | if (mixer_ops && mixer_ops->enable_vblank) |
125 | return mixer_ops->enable_vblank(ctx->mixer_ctx->ctx, | |
126 | manager->pipe); | |
d8408326 SWK |
127 | |
128 | return 0; | |
129 | } | |
130 | ||
131 | static 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 | ||
578b6065 JS |
137 | if (mixer_ops && mixer_ops->disable_vblank) |
138 | return mixer_ops->disable_vblank(ctx->mixer_ctx->ctx); | |
d8408326 SWK |
139 | } |
140 | ||
1de425b0 ID |
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) | |
145 | { | |
146 | struct drm_hdmi_context *ctx = to_context(subdrv_dev); | |
147 | ||
148 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
149 | ||
578b6065 JS |
150 | if (hdmi_ops && hdmi_ops->mode_fixup) |
151 | hdmi_ops->mode_fixup(ctx->hdmi_ctx->ctx, connector, mode, | |
152 | adjusted_mode); | |
1de425b0 ID |
153 | } |
154 | ||
d8408326 SWK |
155 | static 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 | ||
578b6065 JS |
161 | if (hdmi_ops && hdmi_ops->mode_set) |
162 | hdmi_ops->mode_set(ctx->hdmi_ctx->ctx, mode); | |
d8408326 SWK |
163 | } |
164 | ||
1de425b0 ID |
165 | static 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 | ||
578b6065 JS |
172 | if (hdmi_ops && hdmi_ops->get_max_resol) |
173 | hdmi_ops->get_max_resol(ctx->hdmi_ctx->ctx, width, height); | |
1de425b0 ID |
174 | } |
175 | ||
d8408326 SWK |
176 | static 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 | ||
578b6065 JS |
182 | if (hdmi_ops && hdmi_ops->commit) |
183 | hdmi_ops->commit(ctx->hdmi_ctx->ctx); | |
d8408326 SWK |
184 | } |
185 | ||
186 | static 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: | |
578b6065 JS |
198 | if (hdmi_ops && hdmi_ops->disable) |
199 | hdmi_ops->disable(ctx->hdmi_ctx->ctx); | |
d8408326 SWK |
200 | break; |
201 | default: | |
202 | DRM_DEBUG_KMS("unkown dps mode: %d\n", mode); | |
203 | break; | |
204 | } | |
205 | } | |
206 | ||
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, | |
1de425b0 | 211 | .mode_fixup = drm_hdmi_mode_fixup, |
d8408326 | 212 | .mode_set = drm_hdmi_mode_set, |
1de425b0 | 213 | .get_max_resol = drm_hdmi_get_max_resol, |
d8408326 SWK |
214 | .commit = drm_hdmi_commit, |
215 | }; | |
216 | ||
217 | static 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 | ||
578b6065 JS |
224 | if (mixer_ops && mixer_ops->win_mode_set) |
225 | mixer_ops->win_mode_set(ctx->mixer_ctx->ctx, overlay); | |
d8408326 SWK |
226 | } |
227 | ||
228 | static 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 | ||
578b6065 JS |
234 | if (mixer_ops && mixer_ops->win_commit) |
235 | mixer_ops->win_commit(ctx->mixer_ctx->ctx, zpos); | |
d8408326 SWK |
236 | } |
237 | ||
238 | static 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 | ||
578b6065 JS |
244 | if (mixer_ops && mixer_ops->win_disable) |
245 | mixer_ops->win_disable(ctx->mixer_ctx->ctx, zpos); | |
d8408326 SWK |
246 | } |
247 | ||
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, | |
252 | }; | |
253 | ||
254 | ||
255 | static int hdmi_subdrv_probe(struct drm_device *drm_dev, | |
256 | struct device *dev) | |
257 | { | |
258 | struct exynos_drm_subdrv *subdrv = to_subdrv(dev); | |
259 | struct drm_hdmi_context *ctx; | |
260 | struct platform_device *pdev = to_platform_device(dev); | |
261 | struct exynos_drm_common_hdmi_pd *pd; | |
d8408326 SWK |
262 | |
263 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
264 | ||
265 | pd = pdev->dev.platform_data; | |
266 | ||
267 | if (!pd) { | |
268 | DRM_DEBUG_KMS("platform data is null.\n"); | |
269 | return -EFAULT; | |
270 | } | |
271 | ||
272 | if (!pd->hdmi_dev) { | |
273 | DRM_DEBUG_KMS("hdmi device is null.\n"); | |
274 | return -EFAULT; | |
275 | } | |
276 | ||
277 | if (!pd->mixer_dev) { | |
278 | DRM_DEBUG_KMS("mixer device is null.\n"); | |
279 | return -EFAULT; | |
280 | } | |
281 | ||
d8408326 SWK |
282 | ctx = get_ctx_from_subdrv(subdrv); |
283 | ||
284 | ctx->hdmi_ctx = (struct exynos_drm_hdmi_context *) | |
285 | to_context(pd->hdmi_dev); | |
286 | if (!ctx->hdmi_ctx) { | |
287 | DRM_DEBUG_KMS("hdmi context is null.\n"); | |
132a5b91 | 288 | return -EFAULT; |
d8408326 SWK |
289 | } |
290 | ||
291 | ctx->hdmi_ctx->drm_dev = drm_dev; | |
292 | ||
293 | ctx->mixer_ctx = (struct exynos_drm_hdmi_context *) | |
294 | to_context(pd->mixer_dev); | |
295 | if (!ctx->mixer_ctx) { | |
296 | DRM_DEBUG_KMS("mixer context is null.\n"); | |
132a5b91 | 297 | return -EFAULT; |
d8408326 SWK |
298 | } |
299 | ||
300 | ctx->mixer_ctx->drm_dev = drm_dev; | |
301 | ||
302 | return 0; | |
d8408326 SWK |
303 | } |
304 | ||
305 | static int __devinit exynos_drm_hdmi_probe(struct platform_device *pdev) | |
306 | { | |
307 | struct device *dev = &pdev->dev; | |
308 | struct exynos_drm_subdrv *subdrv; | |
309 | struct drm_hdmi_context *ctx; | |
310 | ||
311 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
312 | ||
313 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); | |
314 | if (!ctx) { | |
315 | DRM_LOG_KMS("failed to alloc common hdmi context.\n"); | |
316 | return -ENOMEM; | |
317 | } | |
318 | ||
319 | subdrv = &ctx->subdrv; | |
320 | ||
321 | subdrv->probe = hdmi_subdrv_probe; | |
d8408326 SWK |
322 | subdrv->manager.pipe = -1; |
323 | subdrv->manager.ops = &drm_hdmi_manager_ops; | |
324 | subdrv->manager.overlay_ops = &drm_hdmi_overlay_ops; | |
325 | subdrv->manager.display_ops = &drm_hdmi_display_ops; | |
326 | subdrv->manager.dev = dev; | |
327 | ||
328 | platform_set_drvdata(pdev, subdrv); | |
329 | ||
132a5b91 | 330 | exynos_drm_subdrv_register(subdrv); |
d8408326 SWK |
331 | |
332 | return 0; | |
333 | } | |
334 | ||
335 | static int hdmi_runtime_suspend(struct device *dev) | |
336 | { | |
337 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
338 | ||
339 | return 0; | |
340 | } | |
341 | ||
342 | static int hdmi_runtime_resume(struct device *dev) | |
343 | { | |
344 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
345 | ||
346 | return 0; | |
347 | } | |
348 | ||
349 | static const struct dev_pm_ops hdmi_pm_ops = { | |
350 | .runtime_suspend = hdmi_runtime_suspend, | |
351 | .runtime_resume = hdmi_runtime_resume, | |
352 | }; | |
353 | ||
354 | static int __devexit exynos_drm_hdmi_remove(struct platform_device *pdev) | |
355 | { | |
356 | struct drm_hdmi_context *ctx = platform_get_drvdata(pdev); | |
357 | ||
358 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
359 | ||
360 | exynos_drm_subdrv_unregister(&ctx->subdrv); | |
361 | kfree(ctx); | |
362 | ||
363 | return 0; | |
364 | } | |
365 | ||
132a5b91 | 366 | struct platform_driver exynos_drm_common_hdmi_driver = { |
d8408326 SWK |
367 | .probe = exynos_drm_hdmi_probe, |
368 | .remove = __devexit_p(exynos_drm_hdmi_remove), | |
369 | .driver = { | |
370 | .name = "exynos-drm-hdmi", | |
371 | .owner = THIS_MODULE, | |
372 | .pm = &hdmi_pm_ops, | |
373 | }, | |
374 | }; |