Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 1 | /* exynos_drm_vidi.c |
| 2 | * |
| 3 | * Copyright (C) 2012 Samsung Electronics Co.Ltd |
| 4 | * Authors: |
| 5 | * Inki Dae <inki.dae@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 | */ |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 13 | #include <drm/drmP.h> |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 14 | |
| 15 | #include <linux/kernel.h> |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 16 | #include <linux/platform_device.h> |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 17 | #include <linux/component.h> |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 18 | |
| 19 | #include <drm/exynos_drm.h> |
| 20 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 21 | #include <drm/drm_edid.h> |
| 22 | #include <drm/drm_crtc_helper.h> |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 23 | |
| 24 | #include "exynos_drm_drv.h" |
| 25 | #include "exynos_drm_crtc.h" |
| 26 | #include "exynos_drm_encoder.h" |
Mark Brown | e30655d | 2013-08-13 00:46:40 +0100 | [diff] [blame] | 27 | #include "exynos_drm_vidi.h" |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 28 | |
| 29 | /* vidi has totally three virtual windows. */ |
| 30 | #define WINDOWS_NR 3 |
| 31 | |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 32 | #define ctx_from_connector(c) container_of(c, struct vidi_context, \ |
| 33 | connector) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 34 | |
| 35 | struct vidi_win_data { |
| 36 | unsigned int offset_x; |
| 37 | unsigned int offset_y; |
| 38 | unsigned int ovl_width; |
| 39 | unsigned int ovl_height; |
| 40 | unsigned int fb_width; |
| 41 | unsigned int fb_height; |
| 42 | unsigned int bpp; |
| 43 | dma_addr_t dma_addr; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 44 | unsigned int buf_offsize; |
| 45 | unsigned int line_size; /* bytes */ |
| 46 | bool enabled; |
| 47 | }; |
| 48 | |
| 49 | struct vidi_context { |
Andrzej Hajda | 7340426 | 2014-11-17 09:54:22 +0100 | [diff] [blame] | 50 | struct exynos_drm_display display; |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 51 | struct platform_device *pdev; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 52 | struct drm_device *drm_dev; |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 53 | struct exynos_drm_crtc *crtc; |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 54 | struct drm_encoder *encoder; |
| 55 | struct drm_connector connector; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 56 | struct vidi_win_data win_data[WINDOWS_NR]; |
| 57 | struct edid *raw_edid; |
| 58 | unsigned int clkdiv; |
| 59 | unsigned int default_win; |
| 60 | unsigned long irq_flags; |
| 61 | unsigned int connected; |
| 62 | bool vblank_on; |
| 63 | bool suspended; |
Inki Dae | 291257c | 2012-09-19 11:02:43 +0900 | [diff] [blame] | 64 | bool direct_vblank; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 65 | struct work_struct work; |
| 66 | struct mutex lock; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 67 | int pipe; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 68 | }; |
| 69 | |
Andrzej Hajda | 2f26bd7 | 2014-11-17 09:54:23 +0100 | [diff] [blame] | 70 | static inline struct vidi_context *display_to_vidi(struct exynos_drm_display *d) |
| 71 | { |
| 72 | return container_of(d, struct vidi_context, display); |
| 73 | } |
| 74 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 75 | static const char fake_edid_info[] = { |
| 76 | 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x4c, 0x2d, 0x05, 0x05, |
| 77 | 0x00, 0x00, 0x00, 0x00, 0x30, 0x12, 0x01, 0x03, 0x80, 0x10, 0x09, 0x78, |
| 78 | 0x0a, 0xee, 0x91, 0xa3, 0x54, 0x4c, 0x99, 0x26, 0x0f, 0x50, 0x54, 0xbd, |
| 79 | 0xee, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, |
| 80 | 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x66, 0x21, 0x50, 0xb0, 0x51, 0x00, |
| 81 | 0x1b, 0x30, 0x40, 0x70, 0x36, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e, |
| 82 | 0x01, 0x1d, 0x00, 0x72, 0x51, 0xd0, 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00, |
| 83 | 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x18, |
| 84 | 0x4b, 0x1a, 0x44, 0x17, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 85 | 0x00, 0x00, 0x00, 0xfc, 0x00, 0x53, 0x41, 0x4d, 0x53, 0x55, 0x4e, 0x47, |
| 86 | 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0xbc, 0x02, 0x03, 0x1e, 0xf1, |
| 87 | 0x46, 0x84, 0x05, 0x03, 0x10, 0x20, 0x22, 0x23, 0x09, 0x07, 0x07, 0x83, |
| 88 | 0x01, 0x00, 0x00, 0xe2, 0x00, 0x0f, 0x67, 0x03, 0x0c, 0x00, 0x10, 0x00, |
| 89 | 0xb8, 0x2d, 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, 0x58, 0x2c, |
| 90 | 0x25, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x9e, 0x8c, 0x0a, 0xd0, 0x8a, |
| 91 | 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00, 0xa0, 0x5a, 0x00, 0x00, |
| 92 | 0x00, 0x18, 0x02, 0x3a, 0x80, 0x18, 0x71, 0x38, 0x2d, 0x40, 0x58, 0x2c, |
| 93 | 0x45, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, |
| 94 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 95 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 96 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 97 | 0x00, 0x00, 0x00, 0x06 |
| 98 | }; |
| 99 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 100 | static void vidi_apply(struct exynos_drm_crtc *crtc) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 101 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 102 | struct vidi_context *ctx = crtc->ctx; |
| 103 | struct exynos_drm_crtc_ops *crtc_ops = crtc->ops; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 104 | struct vidi_win_data *win_data; |
| 105 | int i; |
| 106 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 107 | for (i = 0; i < WINDOWS_NR; i++) { |
| 108 | win_data = &ctx->win_data[i]; |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 109 | if (win_data->enabled && (crtc_ops && crtc_ops->win_commit)) |
| 110 | crtc_ops->win_commit(crtc, i); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 111 | } |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 112 | } |
| 113 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 114 | static int vidi_enable_vblank(struct exynos_drm_crtc *crtc) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 115 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 116 | struct vidi_context *ctx = crtc->ctx; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 117 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 118 | if (ctx->suspended) |
| 119 | return -EPERM; |
| 120 | |
| 121 | if (!test_and_set_bit(0, &ctx->irq_flags)) |
| 122 | ctx->vblank_on = true; |
| 123 | |
Inki Dae | 291257c | 2012-09-19 11:02:43 +0900 | [diff] [blame] | 124 | ctx->direct_vblank = true; |
| 125 | |
| 126 | /* |
| 127 | * in case of page flip request, vidi_finish_pageflip function |
| 128 | * will not be called because direct_vblank is true and then |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 129 | * that function will be called by crtc_ops->win_commit callback |
Inki Dae | 291257c | 2012-09-19 11:02:43 +0900 | [diff] [blame] | 130 | */ |
| 131 | schedule_work(&ctx->work); |
| 132 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 133 | return 0; |
| 134 | } |
| 135 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 136 | static void vidi_disable_vblank(struct exynos_drm_crtc *crtc) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 137 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 138 | struct vidi_context *ctx = crtc->ctx; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 139 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 140 | if (ctx->suspended) |
| 141 | return; |
| 142 | |
| 143 | if (test_and_clear_bit(0, &ctx->irq_flags)) |
| 144 | ctx->vblank_on = false; |
| 145 | } |
| 146 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 147 | static void vidi_win_mode_set(struct exynos_drm_crtc *crtc, |
Gustavo Padovan | 8837dee | 2014-11-03 18:13:27 -0200 | [diff] [blame] | 148 | struct exynos_drm_plane *plane) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 149 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 150 | struct vidi_context *ctx = crtc->ctx; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 151 | struct vidi_win_data *win_data; |
| 152 | int win; |
| 153 | unsigned long offset; |
| 154 | |
Gustavo Padovan | 8837dee | 2014-11-03 18:13:27 -0200 | [diff] [blame] | 155 | if (!plane) { |
| 156 | DRM_ERROR("plane is NULL\n"); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 157 | return; |
| 158 | } |
| 159 | |
Gustavo Padovan | 8837dee | 2014-11-03 18:13:27 -0200 | [diff] [blame] | 160 | win = plane->zpos; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 161 | if (win == DEFAULT_ZPOS) |
| 162 | win = ctx->default_win; |
| 163 | |
Inki Dae | a7f98d6 | 2013-05-28 16:01:21 +0900 | [diff] [blame] | 164 | if (win < 0 || win >= WINDOWS_NR) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 165 | return; |
| 166 | |
Gustavo Padovan | 8837dee | 2014-11-03 18:13:27 -0200 | [diff] [blame] | 167 | offset = plane->fb_x * (plane->bpp >> 3); |
| 168 | offset += plane->fb_y * plane->pitch; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 169 | |
Gustavo Padovan | 8837dee | 2014-11-03 18:13:27 -0200 | [diff] [blame] | 170 | DRM_DEBUG_KMS("offset = 0x%lx, pitch = %x\n", offset, plane->pitch); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 171 | |
| 172 | win_data = &ctx->win_data[win]; |
| 173 | |
Gustavo Padovan | 8837dee | 2014-11-03 18:13:27 -0200 | [diff] [blame] | 174 | win_data->offset_x = plane->crtc_x; |
| 175 | win_data->offset_y = plane->crtc_y; |
| 176 | win_data->ovl_width = plane->crtc_width; |
| 177 | win_data->ovl_height = plane->crtc_height; |
| 178 | win_data->fb_width = plane->fb_width; |
| 179 | win_data->fb_height = plane->fb_height; |
| 180 | win_data->dma_addr = plane->dma_addr[0] + offset; |
| 181 | win_data->bpp = plane->bpp; |
| 182 | win_data->buf_offsize = (plane->fb_width - plane->crtc_width) * |
| 183 | (plane->bpp >> 3); |
| 184 | win_data->line_size = plane->crtc_width * (plane->bpp >> 3); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 185 | |
| 186 | /* |
| 187 | * some parts of win_data should be transferred to user side |
| 188 | * through specific ioctl. |
| 189 | */ |
| 190 | |
| 191 | DRM_DEBUG_KMS("offset_x = %d, offset_y = %d\n", |
| 192 | win_data->offset_x, win_data->offset_y); |
| 193 | DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n", |
| 194 | win_data->ovl_width, win_data->ovl_height); |
YoungJun Cho | ddd8e95 | 2012-12-10 15:44:58 +0900 | [diff] [blame] | 195 | DRM_DEBUG_KMS("paddr = 0x%lx\n", (unsigned long)win_data->dma_addr); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 196 | DRM_DEBUG_KMS("fb_width = %d, crtc_width = %d\n", |
Gustavo Padovan | 8837dee | 2014-11-03 18:13:27 -0200 | [diff] [blame] | 197 | plane->fb_width, plane->crtc_width); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 198 | } |
| 199 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 200 | static void vidi_win_commit(struct exynos_drm_crtc *crtc, int zpos) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 201 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 202 | struct vidi_context *ctx = crtc->ctx; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 203 | struct vidi_win_data *win_data; |
| 204 | int win = zpos; |
| 205 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 206 | if (ctx->suspended) |
| 207 | return; |
| 208 | |
| 209 | if (win == DEFAULT_ZPOS) |
| 210 | win = ctx->default_win; |
| 211 | |
Inki Dae | a7f98d6 | 2013-05-28 16:01:21 +0900 | [diff] [blame] | 212 | if (win < 0 || win >= WINDOWS_NR) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 213 | return; |
| 214 | |
| 215 | win_data = &ctx->win_data[win]; |
| 216 | |
| 217 | win_data->enabled = true; |
| 218 | |
Jingoo Han | b8eade2 | 2014-04-22 14:45:32 +0900 | [diff] [blame] | 219 | DRM_DEBUG_KMS("dma_addr = %pad\n", &win_data->dma_addr); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 220 | |
| 221 | if (ctx->vblank_on) |
| 222 | schedule_work(&ctx->work); |
| 223 | } |
| 224 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 225 | static void vidi_win_disable(struct exynos_drm_crtc *crtc, int zpos) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 226 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 227 | struct vidi_context *ctx = crtc->ctx; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 228 | struct vidi_win_data *win_data; |
| 229 | int win = zpos; |
| 230 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 231 | if (win == DEFAULT_ZPOS) |
| 232 | win = ctx->default_win; |
| 233 | |
Inki Dae | a7f98d6 | 2013-05-28 16:01:21 +0900 | [diff] [blame] | 234 | if (win < 0 || win >= WINDOWS_NR) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 235 | return; |
| 236 | |
| 237 | win_data = &ctx->win_data[win]; |
| 238 | win_data->enabled = false; |
| 239 | |
| 240 | /* TODO. */ |
| 241 | } |
| 242 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 243 | static int vidi_power_on(struct exynos_drm_crtc *crtc, bool enable) |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 244 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 245 | struct vidi_context *ctx = crtc->ctx; |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 246 | |
| 247 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 248 | |
| 249 | if (enable != false && enable != true) |
| 250 | return -EINVAL; |
| 251 | |
| 252 | if (enable) { |
| 253 | ctx->suspended = false; |
| 254 | |
| 255 | /* if vblank was enabled status, enable it again. */ |
| 256 | if (test_and_clear_bit(0, &ctx->irq_flags)) |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 257 | vidi_enable_vblank(crtc); |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 258 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 259 | vidi_apply(crtc); |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 260 | } else { |
| 261 | ctx->suspended = true; |
| 262 | } |
| 263 | |
| 264 | return 0; |
| 265 | } |
| 266 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 267 | static void vidi_dpms(struct exynos_drm_crtc *crtc, int mode) |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 268 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 269 | struct vidi_context *ctx = crtc->ctx; |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 270 | |
| 271 | DRM_DEBUG_KMS("%d\n", mode); |
| 272 | |
| 273 | mutex_lock(&ctx->lock); |
| 274 | |
| 275 | switch (mode) { |
| 276 | case DRM_MODE_DPMS_ON: |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 277 | vidi_power_on(crtc, true); |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 278 | break; |
| 279 | case DRM_MODE_DPMS_STANDBY: |
| 280 | case DRM_MODE_DPMS_SUSPEND: |
| 281 | case DRM_MODE_DPMS_OFF: |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 282 | vidi_power_on(crtc, false); |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 283 | break; |
| 284 | default: |
| 285 | DRM_DEBUG_KMS("unspecified mode %d\n", mode); |
| 286 | break; |
| 287 | } |
| 288 | |
| 289 | mutex_unlock(&ctx->lock); |
| 290 | } |
| 291 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 292 | static int vidi_ctx_initialize(struct vidi_context *ctx, |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 293 | struct drm_device *drm_dev) |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 294 | { |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 295 | struct exynos_drm_private *priv = drm_dev->dev_private; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 296 | |
Gustavo Padovan | eb88e42 | 2014-11-26 16:43:27 -0200 | [diff] [blame] | 297 | ctx->drm_dev = drm_dev; |
Gustavo Padovan | 8a326ed | 2014-11-04 18:44:47 -0200 | [diff] [blame] | 298 | ctx->pipe = priv->pipe++; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 299 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 300 | return 0; |
| 301 | } |
| 302 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 303 | static struct exynos_drm_crtc_ops vidi_crtc_ops = { |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 304 | .dpms = vidi_dpms, |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 305 | .enable_vblank = vidi_enable_vblank, |
| 306 | .disable_vblank = vidi_disable_vblank, |
| 307 | .win_mode_set = vidi_win_mode_set, |
| 308 | .win_commit = vidi_win_commit, |
| 309 | .win_disable = vidi_win_disable, |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 310 | }; |
| 311 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 312 | static void vidi_fake_vblank_handler(struct work_struct *work) |
| 313 | { |
| 314 | struct vidi_context *ctx = container_of(work, struct vidi_context, |
| 315 | work); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 316 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 317 | if (ctx->pipe < 0) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 318 | return; |
| 319 | |
| 320 | /* refresh rate is about 50Hz. */ |
| 321 | usleep_range(16000, 20000); |
| 322 | |
Inki Dae | 291257c | 2012-09-19 11:02:43 +0900 | [diff] [blame] | 323 | mutex_lock(&ctx->lock); |
| 324 | |
| 325 | if (ctx->direct_vblank) { |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 326 | drm_handle_vblank(ctx->drm_dev, ctx->pipe); |
Inki Dae | 291257c | 2012-09-19 11:02:43 +0900 | [diff] [blame] | 327 | ctx->direct_vblank = false; |
| 328 | mutex_unlock(&ctx->lock); |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | mutex_unlock(&ctx->lock); |
| 333 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 334 | exynos_drm_crtc_finish_pageflip(ctx->drm_dev, ctx->pipe); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 335 | } |
| 336 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 337 | static int vidi_show_connection(struct device *dev, |
| 338 | struct device_attribute *attr, char *buf) |
| 339 | { |
Andrzej Hajda | f01833c | 2014-11-17 09:54:16 +0100 | [diff] [blame] | 340 | struct vidi_context *ctx = dev_get_drvdata(dev); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 341 | int rc; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 342 | |
| 343 | mutex_lock(&ctx->lock); |
| 344 | |
| 345 | rc = sprintf(buf, "%d\n", ctx->connected); |
| 346 | |
| 347 | mutex_unlock(&ctx->lock); |
| 348 | |
| 349 | return rc; |
| 350 | } |
| 351 | |
| 352 | static int vidi_store_connection(struct device *dev, |
| 353 | struct device_attribute *attr, |
| 354 | const char *buf, size_t len) |
| 355 | { |
Andrzej Hajda | f01833c | 2014-11-17 09:54:16 +0100 | [diff] [blame] | 356 | struct vidi_context *ctx = dev_get_drvdata(dev); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 357 | int ret; |
| 358 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 359 | ret = kstrtoint(buf, 0, &ctx->connected); |
| 360 | if (ret) |
| 361 | return ret; |
| 362 | |
| 363 | if (ctx->connected > 1) |
| 364 | return -EINVAL; |
| 365 | |
Inki Dae | d07d39d | 2012-06-27 16:00:56 +0900 | [diff] [blame] | 366 | /* use fake edid data for test. */ |
| 367 | if (!ctx->raw_edid) |
| 368 | ctx->raw_edid = (struct edid *)fake_edid_info; |
| 369 | |
Inki Dae | d7b8478 | 2012-06-27 16:16:26 +0900 | [diff] [blame] | 370 | /* if raw_edid isn't same as fake data then it can't be tested. */ |
| 371 | if (ctx->raw_edid != (struct edid *)fake_edid_info) { |
| 372 | DRM_DEBUG_KMS("edid data is not fake data.\n"); |
| 373 | return -EINVAL; |
| 374 | } |
| 375 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 376 | DRM_DEBUG_KMS("requested connection.\n"); |
| 377 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 378 | drm_helper_hpd_irq_event(ctx->drm_dev); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 379 | |
| 380 | return len; |
| 381 | } |
| 382 | |
| 383 | static DEVICE_ATTR(connection, 0644, vidi_show_connection, |
| 384 | vidi_store_connection); |
| 385 | |
| 386 | int vidi_connection_ioctl(struct drm_device *drm_dev, void *data, |
| 387 | struct drm_file *file_priv) |
| 388 | { |
| 389 | struct vidi_context *ctx = NULL; |
| 390 | struct drm_encoder *encoder; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 391 | struct exynos_drm_display *display; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 392 | struct drm_exynos_vidi_connection *vidi = data; |
| 393 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 394 | if (!vidi) { |
| 395 | DRM_DEBUG_KMS("user data for vidi is null.\n"); |
| 396 | return -EINVAL; |
| 397 | } |
| 398 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 399 | if (vidi->connection > 1) { |
| 400 | DRM_DEBUG_KMS("connection should be 0 or 1.\n"); |
| 401 | return -EINVAL; |
| 402 | } |
| 403 | |
| 404 | list_for_each_entry(encoder, &drm_dev->mode_config.encoder_list, |
| 405 | head) { |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 406 | display = exynos_drm_get_display(encoder); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 407 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 408 | if (display->type == EXYNOS_DISPLAY_TYPE_VIDI) { |
Andrzej Hajda | 2f26bd7 | 2014-11-17 09:54:23 +0100 | [diff] [blame] | 409 | ctx = display_to_vidi(display); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 410 | break; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | if (!ctx) { |
| 415 | DRM_DEBUG_KMS("not found virtual device type encoder.\n"); |
| 416 | return -EINVAL; |
| 417 | } |
| 418 | |
| 419 | if (ctx->connected == vidi->connection) { |
| 420 | DRM_DEBUG_KMS("same connection request.\n"); |
| 421 | return -EINVAL; |
| 422 | } |
| 423 | |
Inki Dae | d3b62db | 2012-06-27 16:36:12 +0900 | [diff] [blame] | 424 | if (vidi->connection) { |
Seung-Woo Kim | e7808df | 2013-01-10 19:35:06 +0900 | [diff] [blame] | 425 | struct edid *raw_edid = (struct edid *)(uint32_t)vidi->edid; |
| 426 | if (!drm_edid_is_valid(raw_edid)) { |
| 427 | DRM_DEBUG_KMS("edid data is invalid.\n"); |
Inki Dae | d3b62db | 2012-06-27 16:36:12 +0900 | [diff] [blame] | 428 | return -EINVAL; |
| 429 | } |
Jani Nikula | 4ddc773 | 2013-09-27 15:08:29 +0300 | [diff] [blame] | 430 | ctx->raw_edid = drm_edid_duplicate(raw_edid); |
Inki Dae | d3b62db | 2012-06-27 16:36:12 +0900 | [diff] [blame] | 431 | if (!ctx->raw_edid) { |
| 432 | DRM_DEBUG_KMS("failed to allocate raw_edid.\n"); |
| 433 | return -ENOMEM; |
| 434 | } |
Inki Dae | d3b62db | 2012-06-27 16:36:12 +0900 | [diff] [blame] | 435 | } else { |
| 436 | /* |
| 437 | * with connection = 0, free raw_edid |
| 438 | * only if raw edid data isn't same as fake data. |
| 439 | */ |
| 440 | if (ctx->raw_edid && ctx->raw_edid != |
| 441 | (struct edid *)fake_edid_info) { |
| 442 | kfree(ctx->raw_edid); |
| 443 | ctx->raw_edid = NULL; |
| 444 | } |
| 445 | } |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 446 | |
| 447 | ctx->connected = vidi->connection; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 448 | drm_helper_hpd_irq_event(ctx->drm_dev); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 449 | |
| 450 | return 0; |
| 451 | } |
| 452 | |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 453 | static enum drm_connector_status vidi_detect(struct drm_connector *connector, |
| 454 | bool force) |
| 455 | { |
| 456 | struct vidi_context *ctx = ctx_from_connector(connector); |
| 457 | |
| 458 | /* |
| 459 | * connection request would come from user side |
| 460 | * to do hotplug through specific ioctl. |
| 461 | */ |
| 462 | return ctx->connected ? connector_status_connected : |
| 463 | connector_status_disconnected; |
| 464 | } |
| 465 | |
| 466 | static void vidi_connector_destroy(struct drm_connector *connector) |
| 467 | { |
| 468 | } |
| 469 | |
| 470 | static struct drm_connector_funcs vidi_connector_funcs = { |
| 471 | .dpms = drm_helper_connector_dpms, |
| 472 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 473 | .detect = vidi_detect, |
| 474 | .destroy = vidi_connector_destroy, |
| 475 | }; |
| 476 | |
| 477 | static int vidi_get_modes(struct drm_connector *connector) |
| 478 | { |
| 479 | struct vidi_context *ctx = ctx_from_connector(connector); |
| 480 | struct edid *edid; |
| 481 | int edid_len; |
| 482 | |
| 483 | /* |
| 484 | * the edid data comes from user side and it would be set |
| 485 | * to ctx->raw_edid through specific ioctl. |
| 486 | */ |
| 487 | if (!ctx->raw_edid) { |
| 488 | DRM_DEBUG_KMS("raw_edid is null.\n"); |
| 489 | return -EFAULT; |
| 490 | } |
| 491 | |
| 492 | edid_len = (1 + ctx->raw_edid->extensions) * EDID_LENGTH; |
| 493 | edid = kmemdup(ctx->raw_edid, edid_len, GFP_KERNEL); |
| 494 | if (!edid) { |
| 495 | DRM_DEBUG_KMS("failed to allocate edid\n"); |
| 496 | return -ENOMEM; |
| 497 | } |
| 498 | |
| 499 | drm_mode_connector_update_edid_property(connector, edid); |
| 500 | |
| 501 | return drm_add_edid_modes(connector, edid); |
| 502 | } |
| 503 | |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 504 | static struct drm_encoder *vidi_best_encoder(struct drm_connector *connector) |
| 505 | { |
| 506 | struct vidi_context *ctx = ctx_from_connector(connector); |
| 507 | |
| 508 | return ctx->encoder; |
| 509 | } |
| 510 | |
| 511 | static struct drm_connector_helper_funcs vidi_connector_helper_funcs = { |
| 512 | .get_modes = vidi_get_modes, |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 513 | .best_encoder = vidi_best_encoder, |
| 514 | }; |
| 515 | |
| 516 | static int vidi_create_connector(struct exynos_drm_display *display, |
| 517 | struct drm_encoder *encoder) |
| 518 | { |
Andrzej Hajda | 2f26bd7 | 2014-11-17 09:54:23 +0100 | [diff] [blame] | 519 | struct vidi_context *ctx = display_to_vidi(display); |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 520 | struct drm_connector *connector = &ctx->connector; |
| 521 | int ret; |
| 522 | |
| 523 | ctx->encoder = encoder; |
| 524 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
| 525 | |
| 526 | ret = drm_connector_init(ctx->drm_dev, connector, |
| 527 | &vidi_connector_funcs, DRM_MODE_CONNECTOR_VIRTUAL); |
| 528 | if (ret) { |
| 529 | DRM_ERROR("Failed to initialize connector with drm\n"); |
| 530 | return ret; |
| 531 | } |
| 532 | |
| 533 | drm_connector_helper_add(connector, &vidi_connector_helper_funcs); |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 534 | drm_connector_register(connector); |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 535 | drm_mode_connector_attach_encoder(connector, encoder); |
| 536 | |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | |
| 541 | static struct exynos_drm_display_ops vidi_display_ops = { |
| 542 | .create_connector = vidi_create_connector, |
| 543 | }; |
| 544 | |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 545 | static int vidi_bind(struct device *dev, struct device *master, void *data) |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 546 | { |
Andrzej Hajda | f01833c | 2014-11-17 09:54:16 +0100 | [diff] [blame] | 547 | struct vidi_context *ctx = dev_get_drvdata(dev); |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 548 | struct drm_device *drm_dev = data; |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 549 | int ret; |
| 550 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 551 | ctx->crtc = exynos_drm_crtc_create(drm_dev, ctx->pipe, |
| 552 | EXYNOS_DISPLAY_TYPE_VIDI, |
| 553 | &vidi_crtc_ops, ctx); |
| 554 | if (IS_ERR(ctx->crtc)) { |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 555 | DRM_ERROR("failed to create crtc.\n"); |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 556 | return PTR_ERR(ctx->crtc); |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 557 | } |
| 558 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 559 | vidi_ctx_initialize(ctx, drm_dev); |
| 560 | |
Andrzej Hajda | 7340426 | 2014-11-17 09:54:22 +0100 | [diff] [blame] | 561 | ret = exynos_drm_create_enc_conn(drm_dev, &ctx->display); |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 562 | if (ret) { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame^] | 563 | ctx->crtc->base.funcs->destroy(&ctx->crtc->base); |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 564 | return ret; |
| 565 | } |
| 566 | |
| 567 | return 0; |
| 568 | } |
| 569 | |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 570 | |
| 571 | static void vidi_unbind(struct device *dev, struct device *master, void *data) |
| 572 | { |
| 573 | } |
| 574 | |
| 575 | static const struct component_ops vidi_component_ops = { |
| 576 | .bind = vidi_bind, |
| 577 | .unbind = vidi_unbind, |
| 578 | }; |
| 579 | |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 580 | static int vidi_probe(struct platform_device *pdev) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 581 | { |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 582 | struct vidi_context *ctx; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 583 | int ret; |
| 584 | |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 585 | ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 586 | if (!ctx) |
| 587 | return -ENOMEM; |
| 588 | |
Andrzej Hajda | 7340426 | 2014-11-17 09:54:22 +0100 | [diff] [blame] | 589 | ctx->display.type = EXYNOS_DISPLAY_TYPE_VIDI; |
| 590 | ctx->display.ops = &vidi_display_ops; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 591 | ctx->default_win = 0; |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 592 | ctx->pdev = pdev; |
| 593 | |
| 594 | ret = exynos_drm_component_add(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC, |
Gustavo Padovan | 5d1741a | 2014-11-05 19:51:35 -0200 | [diff] [blame] | 595 | EXYNOS_DISPLAY_TYPE_VIDI); |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 596 | if (ret) |
| 597 | return ret; |
| 598 | |
| 599 | ret = exynos_drm_component_add(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR, |
| 600 | ctx->display.type); |
| 601 | if (ret) |
| 602 | goto err_del_crtc_component; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 603 | |
| 604 | INIT_WORK(&ctx->work, vidi_fake_vblank_handler); |
| 605 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 606 | mutex_init(&ctx->lock); |
| 607 | |
Andrzej Hajda | f01833c | 2014-11-17 09:54:16 +0100 | [diff] [blame] | 608 | platform_set_drvdata(pdev, ctx); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 609 | |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 610 | ret = device_create_file(&pdev->dev, &dev_attr_connection); |
| 611 | if (ret < 0) { |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 612 | DRM_ERROR("failed to create connection sysfs.\n"); |
| 613 | goto err_del_conn_component; |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 614 | } |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 615 | |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 616 | ret = component_add(&pdev->dev, &vidi_component_ops); |
| 617 | if (ret) |
| 618 | goto err_remove_file; |
| 619 | |
| 620 | return ret; |
| 621 | |
| 622 | err_remove_file: |
| 623 | device_remove_file(&pdev->dev, &dev_attr_connection); |
| 624 | err_del_conn_component: |
| 625 | exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR); |
| 626 | err_del_crtc_component: |
| 627 | exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC); |
| 628 | |
| 629 | return ret; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 630 | } |
| 631 | |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 632 | static int vidi_remove(struct platform_device *pdev) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 633 | { |
Andrzej Hajda | f01833c | 2014-11-17 09:54:16 +0100 | [diff] [blame] | 634 | struct vidi_context *ctx = platform_get_drvdata(pdev); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 635 | |
Inki Dae | d3b62db | 2012-06-27 16:36:12 +0900 | [diff] [blame] | 636 | if (ctx->raw_edid != (struct edid *)fake_edid_info) { |
| 637 | kfree(ctx->raw_edid); |
| 638 | ctx->raw_edid = NULL; |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 639 | |
| 640 | return -EINVAL; |
Inki Dae | d3b62db | 2012-06-27 16:36:12 +0900 | [diff] [blame] | 641 | } |
| 642 | |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 643 | component_del(&pdev->dev, &vidi_component_ops); |
| 644 | exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR); |
| 645 | exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CRTC); |
| 646 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 647 | return 0; |
| 648 | } |
| 649 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 650 | struct platform_driver vidi_driver = { |
| 651 | .probe = vidi_probe, |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 652 | .remove = vidi_remove, |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 653 | .driver = { |
| 654 | .name = "exynos-drm-vidi", |
| 655 | .owner = THIS_MODULE, |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 656 | }, |
| 657 | }; |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 658 | |
| 659 | int exynos_drm_probe_vidi(void) |
| 660 | { |
| 661 | struct platform_device *pdev; |
| 662 | int ret; |
| 663 | |
| 664 | pdev = platform_device_register_simple("exynos-drm-vidi", -1, NULL, 0); |
| 665 | if (IS_ERR(pdev)) |
| 666 | return PTR_ERR(pdev); |
| 667 | |
| 668 | ret = platform_driver_register(&vidi_driver); |
| 669 | if (ret) { |
| 670 | platform_device_unregister(pdev); |
| 671 | return ret; |
| 672 | } |
| 673 | |
| 674 | return ret; |
| 675 | } |
| 676 | |
Andrzej Hajda | f01833c | 2014-11-17 09:54:16 +0100 | [diff] [blame] | 677 | static int exynos_drm_remove_vidi_device(struct device *dev, void *data) |
| 678 | { |
| 679 | platform_device_unregister(to_platform_device(dev)); |
| 680 | |
| 681 | return 0; |
| 682 | } |
| 683 | |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 684 | void exynos_drm_remove_vidi(void) |
| 685 | { |
Andrzej Hajda | f01833c | 2014-11-17 09:54:16 +0100 | [diff] [blame] | 686 | int ret = driver_for_each_device(&vidi_driver.driver, NULL, NULL, |
| 687 | exynos_drm_remove_vidi_device); |
| 688 | /* silence compiler warning */ |
| 689 | (void)ret; |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 690 | |
| 691 | platform_driver_unregister(&vidi_driver); |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 692 | } |