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> |
Andrzej Hajda | 8574e92 | 2016-09-23 10:15:23 +0200 | [diff] [blame] | 18 | #include <linux/timer.h> |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 19 | |
| 20 | #include <drm/exynos_drm.h> |
| 21 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 22 | #include <drm/drm_edid.h> |
| 23 | #include <drm/drm_crtc_helper.h> |
Gustavo Padovan | 4ea9526 | 2015-06-01 12:04:44 -0300 | [diff] [blame] | 24 | #include <drm/drm_atomic_helper.h> |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 25 | |
| 26 | #include "exynos_drm_drv.h" |
| 27 | #include "exynos_drm_crtc.h" |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 28 | #include "exynos_drm_fb.h" |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 29 | #include "exynos_drm_plane.h" |
Mark Brown | e30655d | 2013-08-13 00:46:40 +0100 | [diff] [blame] | 30 | #include "exynos_drm_vidi.h" |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 31 | |
Andrzej Hajda | 8574e92 | 2016-09-23 10:15:23 +0200 | [diff] [blame] | 32 | /* VIDI uses fixed refresh rate of 50Hz */ |
| 33 | #define VIDI_REFRESH_TIME (1000 / 50) |
| 34 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 35 | /* vidi has totally three virtual windows. */ |
| 36 | #define WINDOWS_NR 3 |
| 37 | |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 38 | #define ctx_from_connector(c) container_of(c, struct vidi_context, \ |
| 39 | connector) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 40 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 41 | struct vidi_context { |
Gustavo Padovan | 2b8376c | 2015-08-15 12:14:08 -0300 | [diff] [blame] | 42 | struct drm_encoder encoder; |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 43 | struct platform_device *pdev; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 44 | struct drm_device *drm_dev; |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 45 | struct exynos_drm_crtc *crtc; |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 46 | struct drm_connector connector; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 47 | struct exynos_drm_plane planes[WINDOWS_NR]; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 48 | struct edid *raw_edid; |
| 49 | unsigned int clkdiv; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 50 | unsigned int connected; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 51 | bool suspended; |
Andrzej Hajda | 8574e92 | 2016-09-23 10:15:23 +0200 | [diff] [blame] | 52 | struct timer_list timer; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 53 | struct mutex lock; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 54 | int pipe; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 55 | }; |
| 56 | |
Gustavo Padovan | 2b8376c | 2015-08-15 12:14:08 -0300 | [diff] [blame] | 57 | static inline struct vidi_context *encoder_to_vidi(struct drm_encoder *e) |
Andrzej Hajda | 2f26bd7 | 2014-11-17 09:54:23 +0100 | [diff] [blame] | 58 | { |
Gustavo Padovan | cf67cc9 | 2015-08-11 17:38:06 +0900 | [diff] [blame] | 59 | return container_of(e, struct vidi_context, encoder); |
Andrzej Hajda | 2f26bd7 | 2014-11-17 09:54:23 +0100 | [diff] [blame] | 60 | } |
| 61 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 62 | static const char fake_edid_info[] = { |
| 63 | 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x4c, 0x2d, 0x05, 0x05, |
| 64 | 0x00, 0x00, 0x00, 0x00, 0x30, 0x12, 0x01, 0x03, 0x80, 0x10, 0x09, 0x78, |
| 65 | 0x0a, 0xee, 0x91, 0xa3, 0x54, 0x4c, 0x99, 0x26, 0x0f, 0x50, 0x54, 0xbd, |
| 66 | 0xee, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, |
| 67 | 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x66, 0x21, 0x50, 0xb0, 0x51, 0x00, |
| 68 | 0x1b, 0x30, 0x40, 0x70, 0x36, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e, |
| 69 | 0x01, 0x1d, 0x00, 0x72, 0x51, 0xd0, 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00, |
| 70 | 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x18, |
| 71 | 0x4b, 0x1a, 0x44, 0x17, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 72 | 0x00, 0x00, 0x00, 0xfc, 0x00, 0x53, 0x41, 0x4d, 0x53, 0x55, 0x4e, 0x47, |
| 73 | 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0xbc, 0x02, 0x03, 0x1e, 0xf1, |
| 74 | 0x46, 0x84, 0x05, 0x03, 0x10, 0x20, 0x22, 0x23, 0x09, 0x07, 0x07, 0x83, |
| 75 | 0x01, 0x00, 0x00, 0xe2, 0x00, 0x0f, 0x67, 0x03, 0x0c, 0x00, 0x10, 0x00, |
| 76 | 0xb8, 0x2d, 0x01, 0x1d, 0x80, 0x18, 0x71, 0x1c, 0x16, 0x20, 0x58, 0x2c, |
| 77 | 0x25, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x9e, 0x8c, 0x0a, 0xd0, 0x8a, |
| 78 | 0x20, 0xe0, 0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00, 0xa0, 0x5a, 0x00, 0x00, |
| 79 | 0x00, 0x18, 0x02, 0x3a, 0x80, 0x18, 0x71, 0x38, 0x2d, 0x40, 0x58, 0x2c, |
| 80 | 0x45, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, |
| 81 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 82 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 83 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 84 | 0x00, 0x00, 0x00, 0x06 |
| 85 | }; |
| 86 | |
Marek Szyprowski | fbbb1e1 | 2015-08-31 00:53:57 +0900 | [diff] [blame] | 87 | static const uint32_t formats[] = { |
| 88 | DRM_FORMAT_XRGB8888, |
| 89 | DRM_FORMAT_ARGB8888, |
| 90 | DRM_FORMAT_NV12, |
| 91 | }; |
| 92 | |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 93 | static const enum drm_plane_type vidi_win_types[WINDOWS_NR] = { |
| 94 | DRM_PLANE_TYPE_PRIMARY, |
| 95 | DRM_PLANE_TYPE_OVERLAY, |
| 96 | DRM_PLANE_TYPE_CURSOR, |
| 97 | }; |
| 98 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 99 | static int vidi_enable_vblank(struct exynos_drm_crtc *crtc) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 100 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 101 | struct vidi_context *ctx = crtc->ctx; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 102 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 103 | if (ctx->suspended) |
| 104 | return -EPERM; |
| 105 | |
Andrzej Hajda | 8574e92 | 2016-09-23 10:15:23 +0200 | [diff] [blame] | 106 | mod_timer(&ctx->timer, |
| 107 | jiffies + msecs_to_jiffies(VIDI_REFRESH_TIME) - 1); |
Inki Dae | 291257c | 2012-09-19 11:02:43 +0900 | [diff] [blame] | 108 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 109 | return 0; |
| 110 | } |
| 111 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 112 | static void vidi_disable_vblank(struct exynos_drm_crtc *crtc) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 113 | { |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 114 | } |
| 115 | |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 116 | static void vidi_update_plane(struct exynos_drm_crtc *crtc, |
| 117 | struct exynos_drm_plane *plane) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 118 | { |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 119 | struct drm_plane_state *state = plane->base.state; |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 120 | struct vidi_context *ctx = crtc->ctx; |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 121 | dma_addr_t addr; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 122 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 123 | if (ctx->suspended) |
| 124 | return; |
| 125 | |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 126 | addr = exynos_drm_fb_dma_addr(state->fb, 0); |
| 127 | DRM_DEBUG_KMS("dma_addr = %pad\n", &addr); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 128 | } |
| 129 | |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 130 | static void vidi_enable(struct exynos_drm_crtc *crtc) |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 131 | { |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 132 | struct vidi_context *ctx = crtc->ctx; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 133 | |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 134 | mutex_lock(&ctx->lock); |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 135 | |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 136 | ctx->suspended = false; |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 137 | |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 138 | mutex_unlock(&ctx->lock); |
Andrzej Hajda | 8574e92 | 2016-09-23 10:15:23 +0200 | [diff] [blame] | 139 | |
| 140 | drm_crtc_vblank_on(&crtc->base); |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 141 | } |
| 142 | |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 143 | static void vidi_disable(struct exynos_drm_crtc *crtc) |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 144 | { |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 145 | struct vidi_context *ctx = crtc->ctx; |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 146 | |
Andrzej Hajda | 8574e92 | 2016-09-23 10:15:23 +0200 | [diff] [blame] | 147 | drm_crtc_vblank_off(&crtc->base); |
| 148 | |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 149 | mutex_lock(&ctx->lock); |
| 150 | |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 151 | ctx->suspended = true; |
Sean Paul | af65c80 | 2014-01-30 16:19:27 -0500 | [diff] [blame] | 152 | |
| 153 | mutex_unlock(&ctx->lock); |
| 154 | } |
| 155 | |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 156 | static int vidi_ctx_initialize(struct vidi_context *ctx, |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 157 | struct drm_device *drm_dev) |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 158 | { |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 159 | struct exynos_drm_private *priv = drm_dev->dev_private; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 160 | |
Gustavo Padovan | eb88e42 | 2014-11-26 16:43:27 -0200 | [diff] [blame] | 161 | ctx->drm_dev = drm_dev; |
Gustavo Padovan | 8a326ed | 2014-11-04 18:44:47 -0200 | [diff] [blame] | 162 | ctx->pipe = priv->pipe++; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 163 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 164 | return 0; |
| 165 | } |
| 166 | |
Krzysztof Kozlowski | f3aaf76 | 2015-05-07 09:04:45 +0900 | [diff] [blame] | 167 | static const struct exynos_drm_crtc_ops vidi_crtc_ops = { |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 168 | .enable = vidi_enable, |
| 169 | .disable = vidi_disable, |
Sean Paul | 1c6244c | 2014-01-30 16:19:02 -0500 | [diff] [blame] | 170 | .enable_vblank = vidi_enable_vblank, |
| 171 | .disable_vblank = vidi_disable_vblank, |
Gustavo Padovan | 9cc7610 | 2015-08-03 14:38:05 +0900 | [diff] [blame] | 172 | .update_plane = vidi_update_plane, |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 173 | }; |
| 174 | |
Andrzej Hajda | 8574e92 | 2016-09-23 10:15:23 +0200 | [diff] [blame] | 175 | static void vidi_fake_vblank_timer(unsigned long arg) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 176 | { |
Andrzej Hajda | 8574e92 | 2016-09-23 10:15:23 +0200 | [diff] [blame] | 177 | struct vidi_context *ctx = (void *)arg; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 178 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 179 | if (ctx->pipe < 0) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 180 | return; |
| 181 | |
Andrzej Hajda | 8574e92 | 2016-09-23 10:15:23 +0200 | [diff] [blame] | 182 | if (drm_crtc_handle_vblank(&ctx->crtc->base)) |
| 183 | mod_timer(&ctx->timer, |
| 184 | jiffies + msecs_to_jiffies(VIDI_REFRESH_TIME) - 1); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 185 | } |
| 186 | |
Marek Szyprowski | c5f2f0c | 2016-02-03 13:42:47 +0100 | [diff] [blame] | 187 | static ssize_t vidi_show_connection(struct device *dev, |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 188 | struct device_attribute *attr, char *buf) |
| 189 | { |
Andrzej Hajda | f01833c | 2014-11-17 09:54:16 +0100 | [diff] [blame] | 190 | struct vidi_context *ctx = dev_get_drvdata(dev); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 191 | int rc; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 192 | |
| 193 | mutex_lock(&ctx->lock); |
| 194 | |
| 195 | rc = sprintf(buf, "%d\n", ctx->connected); |
| 196 | |
| 197 | mutex_unlock(&ctx->lock); |
| 198 | |
| 199 | return rc; |
| 200 | } |
| 201 | |
Marek Szyprowski | c5f2f0c | 2016-02-03 13:42:47 +0100 | [diff] [blame] | 202 | static ssize_t vidi_store_connection(struct device *dev, |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 203 | struct device_attribute *attr, |
| 204 | const char *buf, size_t len) |
| 205 | { |
Andrzej Hajda | f01833c | 2014-11-17 09:54:16 +0100 | [diff] [blame] | 206 | struct vidi_context *ctx = dev_get_drvdata(dev); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 207 | int ret; |
| 208 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 209 | ret = kstrtoint(buf, 0, &ctx->connected); |
| 210 | if (ret) |
| 211 | return ret; |
| 212 | |
| 213 | if (ctx->connected > 1) |
| 214 | return -EINVAL; |
| 215 | |
Inki Dae | d07d39d | 2012-06-27 16:00:56 +0900 | [diff] [blame] | 216 | /* use fake edid data for test. */ |
| 217 | if (!ctx->raw_edid) |
| 218 | ctx->raw_edid = (struct edid *)fake_edid_info; |
| 219 | |
Inki Dae | d7b8478 | 2012-06-27 16:16:26 +0900 | [diff] [blame] | 220 | /* if raw_edid isn't same as fake data then it can't be tested. */ |
| 221 | if (ctx->raw_edid != (struct edid *)fake_edid_info) { |
| 222 | DRM_DEBUG_KMS("edid data is not fake data.\n"); |
| 223 | return -EINVAL; |
| 224 | } |
| 225 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 226 | DRM_DEBUG_KMS("requested connection.\n"); |
| 227 | |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 228 | drm_helper_hpd_irq_event(ctx->drm_dev); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 229 | |
| 230 | return len; |
| 231 | } |
| 232 | |
| 233 | static DEVICE_ATTR(connection, 0644, vidi_show_connection, |
| 234 | vidi_store_connection); |
| 235 | |
| 236 | int vidi_connection_ioctl(struct drm_device *drm_dev, void *data, |
| 237 | struct drm_file *file_priv) |
| 238 | { |
Gustavo Padovan | cf67cc9 | 2015-08-11 17:38:06 +0900 | [diff] [blame] | 239 | struct vidi_context *ctx = dev_get_drvdata(drm_dev->dev); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 240 | struct drm_exynos_vidi_connection *vidi = data; |
| 241 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 242 | if (!vidi) { |
| 243 | DRM_DEBUG_KMS("user data for vidi is null.\n"); |
| 244 | return -EINVAL; |
| 245 | } |
| 246 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 247 | if (vidi->connection > 1) { |
| 248 | DRM_DEBUG_KMS("connection should be 0 or 1.\n"); |
| 249 | return -EINVAL; |
| 250 | } |
| 251 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 252 | if (ctx->connected == vidi->connection) { |
| 253 | DRM_DEBUG_KMS("same connection request.\n"); |
| 254 | return -EINVAL; |
| 255 | } |
| 256 | |
Inki Dae | d3b62db | 2012-06-27 16:36:12 +0900 | [diff] [blame] | 257 | if (vidi->connection) { |
Marek Szyprowski | c5f2f0c | 2016-02-03 13:42:47 +0100 | [diff] [blame] | 258 | struct edid *raw_edid; |
| 259 | |
| 260 | raw_edid = (struct edid *)(unsigned long)vidi->edid; |
Seung-Woo Kim | e7808df | 2013-01-10 19:35:06 +0900 | [diff] [blame] | 261 | if (!drm_edid_is_valid(raw_edid)) { |
| 262 | DRM_DEBUG_KMS("edid data is invalid.\n"); |
Inki Dae | d3b62db | 2012-06-27 16:36:12 +0900 | [diff] [blame] | 263 | return -EINVAL; |
| 264 | } |
Jani Nikula | 4ddc773 | 2013-09-27 15:08:29 +0300 | [diff] [blame] | 265 | ctx->raw_edid = drm_edid_duplicate(raw_edid); |
Inki Dae | d3b62db | 2012-06-27 16:36:12 +0900 | [diff] [blame] | 266 | if (!ctx->raw_edid) { |
| 267 | DRM_DEBUG_KMS("failed to allocate raw_edid.\n"); |
| 268 | return -ENOMEM; |
| 269 | } |
Inki Dae | d3b62db | 2012-06-27 16:36:12 +0900 | [diff] [blame] | 270 | } else { |
| 271 | /* |
| 272 | * with connection = 0, free raw_edid |
| 273 | * only if raw edid data isn't same as fake data. |
| 274 | */ |
| 275 | if (ctx->raw_edid && ctx->raw_edid != |
| 276 | (struct edid *)fake_edid_info) { |
| 277 | kfree(ctx->raw_edid); |
| 278 | ctx->raw_edid = NULL; |
| 279 | } |
| 280 | } |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 281 | |
| 282 | ctx->connected = vidi->connection; |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 283 | drm_helper_hpd_irq_event(ctx->drm_dev); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 288 | static enum drm_connector_status vidi_detect(struct drm_connector *connector, |
| 289 | bool force) |
| 290 | { |
| 291 | struct vidi_context *ctx = ctx_from_connector(connector); |
| 292 | |
| 293 | /* |
| 294 | * connection request would come from user side |
| 295 | * to do hotplug through specific ioctl. |
| 296 | */ |
| 297 | return ctx->connected ? connector_status_connected : |
| 298 | connector_status_disconnected; |
| 299 | } |
| 300 | |
| 301 | static void vidi_connector_destroy(struct drm_connector *connector) |
| 302 | { |
| 303 | } |
| 304 | |
Ville Syrjälä | 800ba2b | 2015-12-15 12:21:06 +0100 | [diff] [blame] | 305 | static const struct drm_connector_funcs vidi_connector_funcs = { |
Gustavo Padovan | 63498e3 | 2015-06-01 12:04:53 -0300 | [diff] [blame] | 306 | .dpms = drm_atomic_helper_connector_dpms, |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 307 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 308 | .detect = vidi_detect, |
| 309 | .destroy = vidi_connector_destroy, |
Gustavo Padovan | 4ea9526 | 2015-06-01 12:04:44 -0300 | [diff] [blame] | 310 | .reset = drm_atomic_helper_connector_reset, |
| 311 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
| 312 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 313 | }; |
| 314 | |
| 315 | static int vidi_get_modes(struct drm_connector *connector) |
| 316 | { |
| 317 | struct vidi_context *ctx = ctx_from_connector(connector); |
| 318 | struct edid *edid; |
| 319 | int edid_len; |
| 320 | |
| 321 | /* |
| 322 | * the edid data comes from user side and it would be set |
| 323 | * to ctx->raw_edid through specific ioctl. |
| 324 | */ |
| 325 | if (!ctx->raw_edid) { |
| 326 | DRM_DEBUG_KMS("raw_edid is null.\n"); |
| 327 | return -EFAULT; |
| 328 | } |
| 329 | |
| 330 | edid_len = (1 + ctx->raw_edid->extensions) * EDID_LENGTH; |
| 331 | edid = kmemdup(ctx->raw_edid, edid_len, GFP_KERNEL); |
| 332 | if (!edid) { |
| 333 | DRM_DEBUG_KMS("failed to allocate edid\n"); |
| 334 | return -ENOMEM; |
| 335 | } |
| 336 | |
| 337 | drm_mode_connector_update_edid_property(connector, edid); |
| 338 | |
| 339 | return drm_add_edid_modes(connector, edid); |
| 340 | } |
| 341 | |
Ville Syrjälä | 800ba2b | 2015-12-15 12:21:06 +0100 | [diff] [blame] | 342 | static const struct drm_connector_helper_funcs vidi_connector_helper_funcs = { |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 343 | .get_modes = vidi_get_modes, |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 344 | }; |
| 345 | |
Gustavo Padovan | 2b8376c | 2015-08-15 12:14:08 -0300 | [diff] [blame] | 346 | static int vidi_create_connector(struct drm_encoder *encoder) |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 347 | { |
Gustavo Padovan | 2b8376c | 2015-08-15 12:14:08 -0300 | [diff] [blame] | 348 | struct vidi_context *ctx = encoder_to_vidi(encoder); |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 349 | struct drm_connector *connector = &ctx->connector; |
| 350 | int ret; |
| 351 | |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 352 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
| 353 | |
| 354 | ret = drm_connector_init(ctx->drm_dev, connector, |
| 355 | &vidi_connector_funcs, DRM_MODE_CONNECTOR_VIRTUAL); |
| 356 | if (ret) { |
| 357 | DRM_ERROR("Failed to initialize connector with drm\n"); |
| 358 | return ret; |
| 359 | } |
| 360 | |
| 361 | drm_connector_helper_add(connector, &vidi_connector_helper_funcs); |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 362 | drm_connector_register(connector); |
Sean Paul | ce6cb55 | 2014-01-30 16:38:07 -0500 | [diff] [blame] | 363 | drm_mode_connector_attach_encoder(connector, encoder); |
| 364 | |
| 365 | return 0; |
| 366 | } |
| 367 | |
Gustavo Padovan | 2b8376c | 2015-08-15 12:14:08 -0300 | [diff] [blame] | 368 | static void exynos_vidi_mode_set(struct drm_encoder *encoder, |
| 369 | struct drm_display_mode *mode, |
| 370 | struct drm_display_mode *adjusted_mode) |
| 371 | { |
| 372 | } |
| 373 | |
| 374 | static void exynos_vidi_enable(struct drm_encoder *encoder) |
| 375 | { |
| 376 | } |
| 377 | |
| 378 | static void exynos_vidi_disable(struct drm_encoder *encoder) |
| 379 | { |
| 380 | } |
| 381 | |
Ville Syrjälä | 800ba2b | 2015-12-15 12:21:06 +0100 | [diff] [blame] | 382 | static const struct drm_encoder_helper_funcs exynos_vidi_encoder_helper_funcs = { |
Gustavo Padovan | 2b8376c | 2015-08-15 12:14:08 -0300 | [diff] [blame] | 383 | .mode_set = exynos_vidi_mode_set, |
| 384 | .enable = exynos_vidi_enable, |
| 385 | .disable = exynos_vidi_disable, |
| 386 | }; |
| 387 | |
Ville Syrjälä | 800ba2b | 2015-12-15 12:21:06 +0100 | [diff] [blame] | 388 | static const struct drm_encoder_funcs exynos_vidi_encoder_funcs = { |
Gustavo Padovan | 2b8376c | 2015-08-15 12:14:08 -0300 | [diff] [blame] | 389 | .destroy = drm_encoder_cleanup, |
| 390 | }; |
| 391 | |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 392 | static int vidi_bind(struct device *dev, struct device *master, void *data) |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 393 | { |
Andrzej Hajda | f01833c | 2014-11-17 09:54:16 +0100 | [diff] [blame] | 394 | struct vidi_context *ctx = dev_get_drvdata(dev); |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 395 | struct drm_device *drm_dev = data; |
Gustavo Padovan | 2b8376c | 2015-08-15 12:14:08 -0300 | [diff] [blame] | 396 | struct drm_encoder *encoder = &ctx->encoder; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 397 | struct exynos_drm_plane *exynos_plane; |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 398 | struct exynos_drm_plane_config plane_config = { 0 }; |
| 399 | unsigned int i; |
Gustavo Padovan | 2b8376c | 2015-08-15 12:14:08 -0300 | [diff] [blame] | 400 | int pipe, ret; |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 401 | |
Joonyoung Shim | 0f04cf8 | 2015-01-30 16:43:01 +0900 | [diff] [blame] | 402 | vidi_ctx_initialize(ctx, drm_dev); |
| 403 | |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 404 | plane_config.pixel_formats = formats; |
| 405 | plane_config.num_pixel_formats = ARRAY_SIZE(formats); |
| 406 | |
| 407 | for (i = 0; i < WINDOWS_NR; i++) { |
| 408 | plane_config.zpos = i; |
| 409 | plane_config.type = vidi_win_types[i]; |
| 410 | |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 411 | ret = exynos_plane_init(drm_dev, &ctx->planes[i], i, |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 412 | 1 << ctx->pipe, &plane_config); |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 413 | if (ret) |
| 414 | return ret; |
| 415 | } |
| 416 | |
Gustavo Padovan | 5d3d099 | 2015-10-12 22:07:48 +0900 | [diff] [blame] | 417 | exynos_plane = &ctx->planes[DEFAULT_WIN]; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 418 | ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base, |
| 419 | ctx->pipe, EXYNOS_DISPLAY_TYPE_VIDI, |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 420 | &vidi_crtc_ops, ctx); |
| 421 | if (IS_ERR(ctx->crtc)) { |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 422 | DRM_ERROR("failed to create crtc.\n"); |
Gustavo Padovan | 93bca24 | 2015-01-18 18:16:23 +0900 | [diff] [blame] | 423 | return PTR_ERR(ctx->crtc); |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 424 | } |
| 425 | |
Gustavo Padovan | 2b8376c | 2015-08-15 12:14:08 -0300 | [diff] [blame] | 426 | pipe = exynos_drm_crtc_get_pipe_from_type(drm_dev, |
| 427 | EXYNOS_DISPLAY_TYPE_VIDI); |
| 428 | if (pipe < 0) |
| 429 | return pipe; |
Gustavo Padovan | a2986e8 | 2015-08-05 20:24:20 -0300 | [diff] [blame] | 430 | |
Gustavo Padovan | 2b8376c | 2015-08-15 12:14:08 -0300 | [diff] [blame] | 431 | encoder->possible_crtcs = 1 << pipe; |
| 432 | |
| 433 | DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs); |
| 434 | |
| 435 | drm_encoder_init(drm_dev, encoder, &exynos_vidi_encoder_funcs, |
Ville Syrjälä | 13a3d91 | 2015-12-09 16:20:18 +0200 | [diff] [blame] | 436 | DRM_MODE_ENCODER_TMDS, NULL); |
Gustavo Padovan | 2b8376c | 2015-08-15 12:14:08 -0300 | [diff] [blame] | 437 | |
| 438 | drm_encoder_helper_add(encoder, &exynos_vidi_encoder_helper_funcs); |
| 439 | |
| 440 | ret = vidi_create_connector(encoder); |
Gustavo Padovan | a2986e8 | 2015-08-05 20:24:20 -0300 | [diff] [blame] | 441 | if (ret) { |
| 442 | DRM_ERROR("failed to create connector ret = %d\n", ret); |
Gustavo Padovan | 2b8376c | 2015-08-15 12:14:08 -0300 | [diff] [blame] | 443 | drm_encoder_cleanup(encoder); |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 444 | return ret; |
| 445 | } |
| 446 | |
| 447 | return 0; |
| 448 | } |
| 449 | |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 450 | |
| 451 | static void vidi_unbind(struct device *dev, struct device *master, void *data) |
| 452 | { |
Andrzej Hajda | 8574e92 | 2016-09-23 10:15:23 +0200 | [diff] [blame] | 453 | struct vidi_context *ctx = dev_get_drvdata(dev); |
| 454 | |
| 455 | del_timer_sync(&ctx->timer); |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | static const struct component_ops vidi_component_ops = { |
| 459 | .bind = vidi_bind, |
| 460 | .unbind = vidi_unbind, |
| 461 | }; |
| 462 | |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 463 | static int vidi_probe(struct platform_device *pdev) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 464 | { |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 465 | struct vidi_context *ctx; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 466 | int ret; |
| 467 | |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 468 | ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 469 | if (!ctx) |
| 470 | return -ENOMEM; |
| 471 | |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 472 | ctx->pdev = pdev; |
| 473 | |
Andrzej Hajda | 8574e92 | 2016-09-23 10:15:23 +0200 | [diff] [blame] | 474 | setup_timer(&ctx->timer, vidi_fake_vblank_timer, (unsigned long)ctx); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 475 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 476 | mutex_init(&ctx->lock); |
| 477 | |
Andrzej Hajda | f01833c | 2014-11-17 09:54:16 +0100 | [diff] [blame] | 478 | platform_set_drvdata(pdev, ctx); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 479 | |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 480 | ret = device_create_file(&pdev->dev, &dev_attr_connection); |
| 481 | if (ret < 0) { |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 482 | DRM_ERROR("failed to create connection sysfs.\n"); |
Andrzej Hajda | 8665040 | 2015-06-11 23:23:37 +0900 | [diff] [blame] | 483 | return ret; |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 484 | } |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 485 | |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 486 | ret = component_add(&pdev->dev, &vidi_component_ops); |
| 487 | if (ret) |
| 488 | goto err_remove_file; |
| 489 | |
| 490 | return ret; |
| 491 | |
| 492 | err_remove_file: |
| 493 | device_remove_file(&pdev->dev, &dev_attr_connection); |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 494 | |
| 495 | return ret; |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 496 | } |
| 497 | |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 498 | static int vidi_remove(struct platform_device *pdev) |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 499 | { |
Andrzej Hajda | f01833c | 2014-11-17 09:54:16 +0100 | [diff] [blame] | 500 | struct vidi_context *ctx = platform_get_drvdata(pdev); |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 501 | |
Inki Dae | d3b62db | 2012-06-27 16:36:12 +0900 | [diff] [blame] | 502 | if (ctx->raw_edid != (struct edid *)fake_edid_info) { |
| 503 | kfree(ctx->raw_edid); |
| 504 | ctx->raw_edid = NULL; |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 505 | |
| 506 | return -EINVAL; |
Inki Dae | d3b62db | 2012-06-27 16:36:12 +0900 | [diff] [blame] | 507 | } |
| 508 | |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 509 | component_del(&pdev->dev, &vidi_component_ops); |
Inki Dae | 1d50aa9 | 2014-11-24 14:55:41 +0900 | [diff] [blame] | 510 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 511 | return 0; |
| 512 | } |
| 513 | |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 514 | struct platform_driver vidi_driver = { |
| 515 | .probe = vidi_probe, |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 516 | .remove = vidi_remove, |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 517 | .driver = { |
| 518 | .name = "exynos-drm-vidi", |
| 519 | .owner = THIS_MODULE, |
Inki Dae | b73d123 | 2012-03-21 10:55:26 +0900 | [diff] [blame] | 520 | }, |
| 521 | }; |