Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 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 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 14 | #include <drm/drmP.h> |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/wait.h> |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 18 | #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 Sharma | ae9dace | 2012-10-16 05:50:13 +0530 | [diff] [blame] | 31 | /* platform device pointer for common drm hdmi device. */ |
| 32 | static struct platform_device *exynos_drm_hdmi_pdev; |
| 33 | |
Rahul Sharma | 768c305 | 2012-10-04 20:48:56 +0530 | [diff] [blame] | 34 | /* Common hdmi subdrv needs to access the hdmi and mixer though context. |
| 35 | * These should be initialied by the repective drivers */ |
| 36 | static struct exynos_drm_hdmi_context *hdmi_ctx; |
| 37 | static struct exynos_drm_hdmi_context *mixer_ctx; |
| 38 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 39 | /* these callback points shoud be set by specific drivers. */ |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 40 | static struct exynos_hdmi_ops *hdmi_ops; |
| 41 | static struct exynos_mixer_ops *mixer_ops; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 42 | |
| 43 | struct 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 Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 47 | |
| 48 | bool enabled[MIXER_WIN_NR]; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 49 | }; |
| 50 | |
Rahul Sharma | ae9dace | 2012-10-16 05:50:13 +0530 | [diff] [blame] | 51 | int exynos_platform_device_hdmi_register(void) |
| 52 | { |
Seung-Woo Kim | 0f6f959 | 2013-04-22 18:40:34 +0900 | [diff] [blame] | 53 | struct platform_device *pdev; |
| 54 | |
Rahul Sharma | ae9dace | 2012-10-16 05:50:13 +0530 | [diff] [blame] | 55 | if (exynos_drm_hdmi_pdev) |
| 56 | return -EEXIST; |
| 57 | |
Seung-Woo Kim | 0f6f959 | 2013-04-22 18:40:34 +0900 | [diff] [blame] | 58 | pdev = platform_device_register_simple( |
Rahul Sharma | ae9dace | 2012-10-16 05:50:13 +0530 | [diff] [blame] | 59 | "exynos-drm-hdmi", -1, NULL, 0); |
Seung-Woo Kim | 0f6f959 | 2013-04-22 18:40:34 +0900 | [diff] [blame] | 60 | if (IS_ERR(pdev)) |
| 61 | return PTR_ERR(pdev); |
| 62 | |
| 63 | exynos_drm_hdmi_pdev = pdev; |
Rahul Sharma | ae9dace | 2012-10-16 05:50:13 +0530 | [diff] [blame] | 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | void exynos_platform_device_hdmi_unregister(void) |
| 69 | { |
Seung-Woo Kim | 0f6f959 | 2013-04-22 18:40:34 +0900 | [diff] [blame] | 70 | if (exynos_drm_hdmi_pdev) { |
Rahul Sharma | ae9dace | 2012-10-16 05:50:13 +0530 | [diff] [blame] | 71 | platform_device_unregister(exynos_drm_hdmi_pdev); |
Seung-Woo Kim | 0f6f959 | 2013-04-22 18:40:34 +0900 | [diff] [blame] | 72 | exynos_drm_hdmi_pdev = NULL; |
| 73 | } |
Rahul Sharma | ae9dace | 2012-10-16 05:50:13 +0530 | [diff] [blame] | 74 | } |
| 75 | |
Rahul Sharma | 768c305 | 2012-10-04 20:48:56 +0530 | [diff] [blame] | 76 | void exynos_hdmi_drv_attach(struct exynos_drm_hdmi_context *ctx) |
| 77 | { |
| 78 | if (ctx) |
| 79 | hdmi_ctx = ctx; |
| 80 | } |
| 81 | |
| 82 | void exynos_mixer_drv_attach(struct exynos_drm_hdmi_context *ctx) |
| 83 | { |
| 84 | if (ctx) |
| 85 | mixer_ctx = ctx; |
| 86 | } |
| 87 | |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 88 | void exynos_hdmi_ops_register(struct exynos_hdmi_ops *ops) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 89 | { |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 90 | if (ops) |
| 91 | hdmi_ops = ops; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 92 | } |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 93 | |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 94 | void exynos_mixer_ops_register(struct exynos_mixer_ops *ops) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 95 | { |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 96 | if (ops) |
| 97 | mixer_ops = ops; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 98 | } |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 99 | |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 100 | static 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 Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 112 | static bool drm_hdmi_is_connected(struct device *dev) |
| 113 | { |
| 114 | struct drm_hdmi_context *ctx = to_context(dev); |
| 115 | |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 116 | if (hdmi_ops && hdmi_ops->is_connected) |
| 117 | return hdmi_ops->is_connected(ctx->hdmi_ctx->ctx); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 118 | |
| 119 | return false; |
| 120 | } |
| 121 | |
Sachin Kamat | 428982e | 2013-01-21 15:26:57 +0530 | [diff] [blame] | 122 | static struct edid *drm_hdmi_get_edid(struct device *dev, |
Rahul Sharma | 9c08e4b | 2013-01-04 07:59:11 -0500 | [diff] [blame] | 123 | struct drm_connector *connector) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 124 | { |
| 125 | struct drm_hdmi_context *ctx = to_context(dev); |
| 126 | |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 127 | if (hdmi_ops && hdmi_ops->get_edid) |
Rahul Sharma | 9c08e4b | 2013-01-04 07:59:11 -0500 | [diff] [blame] | 128 | return hdmi_ops->get_edid(ctx->hdmi_ctx->ctx, connector); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 129 | |
Rahul Sharma | 9c08e4b | 2013-01-04 07:59:11 -0500 | [diff] [blame] | 130 | return NULL; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 131 | } |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 132 | static int drm_hdmi_check_mode_ctx(struct drm_hdmi_context *ctx, |
Rahul Sharma | 16844fb | 2013-06-10 14:50:00 +0530 | [diff] [blame] | 133 | struct drm_display_mode *mode) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 134 | { |
Rahul Sharma | 438c0f8 | 2013-01-15 08:11:05 -0500 | [diff] [blame] | 135 | int ret = 0; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 136 | |
Rahul Sharma | 438c0f8 | 2013-01-15 08:11:05 -0500 | [diff] [blame] | 137 | /* |
| 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 Sharma | 16844fb | 2013-06-10 14:50:00 +0530 | [diff] [blame] | 142 | if (mixer_ops && mixer_ops->check_mode) |
| 143 | ret = mixer_ops->check_mode(ctx->mixer_ctx->ctx, mode); |
Rahul Sharma | 438c0f8 | 2013-01-15 08:11:05 -0500 | [diff] [blame] | 144 | |
| 145 | if (ret) |
| 146 | return ret; |
| 147 | |
Rahul Sharma | 16844fb | 2013-06-10 14:50:00 +0530 | [diff] [blame] | 148 | if (hdmi_ops && hdmi_ops->check_mode) |
| 149 | return hdmi_ops->check_mode(ctx->hdmi_ctx->ctx, mode); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 154 | static 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 Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 162 | static int drm_hdmi_power_on(struct device *dev, int mode) |
| 163 | { |
| 164 | struct drm_hdmi_context *ctx = to_context(dev); |
| 165 | |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 166 | if (hdmi_ops && hdmi_ops->power_on) |
| 167 | return hdmi_ops->power_on(ctx->hdmi_ctx->ctx, mode); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | static struct exynos_drm_display_ops drm_hdmi_display_ops = { |
| 173 | .type = EXYNOS_DISPLAY_TYPE_HDMI, |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 174 | .initialize = drm_hdmi_display_initialize, |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 175 | .is_connected = drm_hdmi_is_connected, |
| 176 | .get_edid = drm_hdmi_get_edid, |
Rahul Sharma | 16844fb | 2013-06-10 14:50:00 +0530 | [diff] [blame] | 177 | .check_mode = drm_hdmi_check_mode, |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 178 | .power_on = drm_hdmi_power_on, |
| 179 | }; |
| 180 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 181 | static int drm_hdmi_enable_vblank(struct exynos_drm_manager *mgr) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 182 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 183 | struct drm_hdmi_context *ctx = mgr->ctx; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 184 | struct exynos_drm_subdrv *subdrv = &ctx->subdrv; |
Joonyoung Shim | 677e84c | 2012-04-05 20:49:27 +0900 | [diff] [blame] | 185 | struct exynos_drm_manager *manager = subdrv->manager; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 186 | |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 187 | if (mixer_ops && mixer_ops->enable_vblank) |
| 188 | return mixer_ops->enable_vblank(ctx->mixer_ctx->ctx, |
| 189 | manager->pipe); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 194 | static void drm_hdmi_disable_vblank(struct exynos_drm_manager *mgr) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 195 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 196 | struct drm_hdmi_context *ctx = mgr->ctx; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 197 | |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 198 | if (mixer_ops && mixer_ops->disable_vblank) |
| 199 | return mixer_ops->disable_vblank(ctx->mixer_ctx->ctx); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 200 | } |
| 201 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 202 | static void drm_hdmi_wait_for_vblank(struct exynos_drm_manager *mgr) |
Prathyush K | 8137a2e | 2012-12-06 20:16:01 +0530 | [diff] [blame] | 203 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 204 | struct drm_hdmi_context *ctx = mgr->ctx; |
Prathyush K | 8137a2e | 2012-12-06 20:16:01 +0530 | [diff] [blame] | 205 | |
Prathyush K | 8137a2e | 2012-12-06 20:16:01 +0530 | [diff] [blame] | 206 | if (mixer_ops && mixer_ops->wait_for_vblank) |
| 207 | mixer_ops->wait_for_vblank(ctx->mixer_ctx->ctx); |
| 208 | } |
| 209 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 210 | static void drm_hdmi_mode_fixup(struct exynos_drm_manager *mgr, |
Inki Dae | 1de425b | 2012-03-16 18:47:04 +0900 | [diff] [blame] | 211 | struct drm_connector *connector, |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 212 | const struct drm_display_mode *mode, |
Inki Dae | 1de425b | 2012-03-16 18:47:04 +0900 | [diff] [blame] | 213 | struct drm_display_mode *adjusted_mode) |
| 214 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 215 | struct drm_hdmi_context *ctx = mgr->ctx; |
Rahul Sharma | 7ddcc73 | 2013-03-06 17:28:16 +0900 | [diff] [blame] | 216 | struct drm_display_mode *m; |
| 217 | int mode_ok; |
Inki Dae | 1de425b | 2012-03-16 18:47:04 +0900 | [diff] [blame] | 218 | |
Rahul Sharma | 7ddcc73 | 2013-03-06 17:28:16 +0900 | [diff] [blame] | 219 | drm_mode_set_crtcinfo(adjusted_mode, 0); |
| 220 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 221 | mode_ok = drm_hdmi_check_mode_ctx(ctx, adjusted_mode); |
Rahul Sharma | 7ddcc73 | 2013-03-06 17:28:16 +0900 | [diff] [blame] | 222 | |
| 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 Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 232 | mode_ok = drm_hdmi_check_mode_ctx(ctx, m); |
Rahul Sharma | 7ddcc73 | 2013-03-06 17:28:16 +0900 | [diff] [blame] | 233 | |
| 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 Dae | 1de425b | 2012-03-16 18:47:04 +0900 | [diff] [blame] | 253 | } |
| 254 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 255 | static void drm_hdmi_mode_set(struct exynos_drm_manager *mgr, void *mode) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 256 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 257 | struct drm_hdmi_context *ctx = mgr->ctx; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 258 | |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 259 | if (hdmi_ops && hdmi_ops->mode_set) |
| 260 | hdmi_ops->mode_set(ctx->hdmi_ctx->ctx, mode); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 261 | } |
| 262 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 263 | static void drm_hdmi_get_max_resol(struct exynos_drm_manager *mgr, |
Inki Dae | 1de425b | 2012-03-16 18:47:04 +0900 | [diff] [blame] | 264 | unsigned int *width, unsigned int *height) |
| 265 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 266 | struct drm_hdmi_context *ctx = mgr->ctx; |
Inki Dae | 1de425b | 2012-03-16 18:47:04 +0900 | [diff] [blame] | 267 | |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 268 | if (hdmi_ops && hdmi_ops->get_max_resol) |
| 269 | hdmi_ops->get_max_resol(ctx->hdmi_ctx->ctx, width, height); |
Inki Dae | 1de425b | 2012-03-16 18:47:04 +0900 | [diff] [blame] | 270 | } |
| 271 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 272 | static void drm_hdmi_commit(struct exynos_drm_manager *mgr) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 273 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 274 | struct drm_hdmi_context *ctx = mgr->ctx; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 275 | |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 276 | if (hdmi_ops && hdmi_ops->commit) |
| 277 | hdmi_ops->commit(ctx->hdmi_ctx->ctx); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 278 | } |
| 279 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 280 | static int drm_hdmi_mgr_initialize(struct exynos_drm_manager *mgr, struct drm_device *drm_dev) |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 281 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 282 | struct drm_hdmi_context *ctx = mgr->ctx; |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 283 | 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 Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 294 | static void drm_hdmi_dpms(struct exynos_drm_manager *mgr, int mode) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 295 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 296 | struct drm_hdmi_context *ctx = mgr->ctx; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 297 | |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 298 | 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 Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 305 | static void drm_hdmi_apply(struct exynos_drm_manager *mgr) |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 306 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 307 | struct drm_hdmi_context *ctx = mgr->ctx; |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 308 | int i; |
| 309 | |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 310 | 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 Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 315 | } |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 316 | |
| 317 | if (hdmi_ops && hdmi_ops->commit) |
| 318 | hdmi_ops->commit(ctx->hdmi_ctx->ctx); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 319 | } |
| 320 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 321 | static void drm_mixer_win_mode_set(struct exynos_drm_manager *mgr, |
| 322 | struct exynos_drm_overlay *overlay) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 323 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 324 | struct drm_hdmi_context *ctx = mgr->ctx; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 325 | |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 326 | if (mixer_ops && mixer_ops->win_mode_set) |
| 327 | mixer_ops->win_mode_set(ctx->mixer_ctx->ctx, overlay); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 328 | } |
| 329 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 330 | static void drm_mixer_win_commit(struct exynos_drm_manager *mgr, int zpos) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 331 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 332 | struct drm_hdmi_context *ctx = mgr->ctx; |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 333 | int win = (zpos == DEFAULT_ZPOS) ? MIXER_DEFAULT_WIN : zpos; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 334 | |
Krzysztof Kozlowski | 1586d80 | 2013-05-27 15:00:43 +0900 | [diff] [blame] | 335 | if (win < 0 || win >= MIXER_WIN_NR) { |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 336 | DRM_ERROR("mixer window[%d] is wrong\n", win); |
| 337 | return; |
| 338 | } |
| 339 | |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 340 | if (mixer_ops && mixer_ops->win_commit) |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 341 | mixer_ops->win_commit(ctx->mixer_ctx->ctx, win); |
| 342 | |
| 343 | ctx->enabled[win] = true; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 344 | } |
| 345 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 346 | static void drm_mixer_win_disable(struct exynos_drm_manager *mgr, int zpos) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 347 | { |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 348 | struct drm_hdmi_context *ctx = mgr->ctx; |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 349 | int win = (zpos == DEFAULT_ZPOS) ? MIXER_DEFAULT_WIN : zpos; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 350 | |
Krzysztof Kozlowski | 1586d80 | 2013-05-27 15:00:43 +0900 | [diff] [blame] | 351 | if (win < 0 || win >= MIXER_WIN_NR) { |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 352 | DRM_ERROR("mixer window[%d] is wrong\n", win); |
| 353 | return; |
| 354 | } |
| 355 | |
Joonyoung Shim | 578b606 | 2012-04-05 20:49:26 +0900 | [diff] [blame] | 356 | if (mixer_ops && mixer_ops->win_disable) |
Joonyoung Shim | cf8fc4f | 2012-04-23 19:35:50 +0900 | [diff] [blame] | 357 | mixer_ops->win_disable(ctx->mixer_ctx->ctx, win); |
| 358 | |
| 359 | ctx->enabled[win] = false; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 360 | } |
| 361 | |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 362 | static struct exynos_drm_manager_ops drm_hdmi_manager_ops = { |
Sean Paul | 4551789 | 2014-01-30 16:19:05 -0500 | [diff] [blame] | 363 | .initialize = drm_hdmi_mgr_initialize, |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 364 | .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 Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 376 | }; |
| 377 | |
Joonyoung Shim | 677e84c | 2012-04-05 20:49:27 +0900 | [diff] [blame] | 378 | static struct exynos_drm_manager hdmi_manager = { |
| 379 | .pipe = -1, |
| 380 | .ops = &drm_hdmi_manager_ops, |
Joonyoung Shim | 677e84c | 2012-04-05 20:49:27 +0900 | [diff] [blame] | 381 | .display_ops = &drm_hdmi_display_ops, |
| 382 | }; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 383 | |
| 384 | static 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 Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 389 | |
Rahul Sharma | 768c305 | 2012-10-04 20:48:56 +0530 | [diff] [blame] | 390 | if (!hdmi_ctx) { |
| 391 | DRM_ERROR("hdmi context not initialized.\n"); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 392 | return -EFAULT; |
| 393 | } |
| 394 | |
Rahul Sharma | 768c305 | 2012-10-04 20:48:56 +0530 | [diff] [blame] | 395 | if (!mixer_ctx) { |
| 396 | DRM_ERROR("mixer context not initialized.\n"); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 397 | return -EFAULT; |
| 398 | } |
| 399 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 400 | ctx = get_ctx_from_subdrv(subdrv); |
| 401 | |
Rahul Sharma | 768c305 | 2012-10-04 20:48:56 +0530 | [diff] [blame] | 402 | if (!ctx) { |
| 403 | DRM_ERROR("no drm hdmi context.\n"); |
Joonyoung Shim | 132a5b9 | 2012-03-16 18:47:08 +0900 | [diff] [blame] | 404 | return -EFAULT; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 405 | } |
| 406 | |
Rahul Sharma | 768c305 | 2012-10-04 20:48:56 +0530 | [diff] [blame] | 407 | ctx->hdmi_ctx = hdmi_ctx; |
| 408 | ctx->mixer_ctx = mixer_ctx; |
| 409 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 410 | return 0; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 411 | } |
| 412 | |
Inki Dae | 1055b39 | 2012-10-19 17:37:35 +0900 | [diff] [blame] | 413 | static 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-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 424 | static int exynos_drm_hdmi_probe(struct platform_device *pdev) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 425 | { |
| 426 | struct device *dev = &pdev->dev; |
| 427 | struct exynos_drm_subdrv *subdrv; |
| 428 | struct drm_hdmi_context *ctx; |
| 429 | |
Seung-Woo Kim | d873ab9 | 2013-05-22 21:14:14 +0900 | [diff] [blame] | 430 | ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
Sachin Kamat | 38bb525 | 2013-08-19 19:04:55 +0900 | [diff] [blame] | 431 | if (!ctx) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 432 | return -ENOMEM; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 433 | |
Sean Paul | bb7704d | 2014-01-30 16:19:06 -0500 | [diff] [blame^] | 434 | hdmi_manager.ctx = ctx; |
| 435 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 436 | subdrv = &ctx->subdrv; |
| 437 | |
Joonyoung Shim | 677e84c | 2012-04-05 20:49:27 +0900 | [diff] [blame] | 438 | subdrv->dev = dev; |
| 439 | subdrv->manager = &hdmi_manager; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 440 | subdrv->probe = hdmi_subdrv_probe; |
Inki Dae | 1055b39 | 2012-10-19 17:37:35 +0900 | [diff] [blame] | 441 | subdrv->remove = hdmi_subdrv_remove; |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 442 | |
| 443 | platform_set_drvdata(pdev, subdrv); |
| 444 | |
Joonyoung Shim | 132a5b9 | 2012-03-16 18:47:08 +0900 | [diff] [blame] | 445 | exynos_drm_subdrv_register(subdrv); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 446 | |
| 447 | return 0; |
| 448 | } |
| 449 | |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 450 | static int exynos_drm_hdmi_remove(struct platform_device *pdev) |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 451 | { |
| 452 | struct drm_hdmi_context *ctx = platform_get_drvdata(pdev); |
| 453 | |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 454 | exynos_drm_subdrv_unregister(&ctx->subdrv); |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 455 | |
| 456 | return 0; |
| 457 | } |
| 458 | |
Joonyoung Shim | 132a5b9 | 2012-03-16 18:47:08 +0900 | [diff] [blame] | 459 | struct platform_driver exynos_drm_common_hdmi_driver = { |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 460 | .probe = exynos_drm_hdmi_probe, |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 461 | .remove = exynos_drm_hdmi_remove, |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 462 | .driver = { |
| 463 | .name = "exynos-drm-hdmi", |
| 464 | .owner = THIS_MODULE, |
Seung-Woo Kim | d840832 | 2011-12-21 17:39:39 +0900 | [diff] [blame] | 465 | }, |
| 466 | }; |