Thomas Gleixner | caab277 | 2019-06-03 07:44:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 2 | /* |
Alexander A. Klimov | 1b409fd | 2020-07-13 14:28:59 +0200 | [diff] [blame] | 3 | * Copyright (C) 2011 Texas Instruments Incorporated - https://www.ti.com/ |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 4 | * Author: Rob Clark <rob@ti.com> |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
Sam Ravnborg | 81f6156 | 2019-07-16 08:42:10 +0200 | [diff] [blame] | 7 | #include <linux/dma-mapping.h> |
| 8 | #include <linux/platform_device.h> |
Peter Ujfalusi | eb5bc1f | 2018-02-12 11:44:39 +0200 | [diff] [blame] | 9 | #include <linux/sort.h> |
Laurent Pinchart | 6e471fa | 2017-05-06 02:57:12 +0300 | [diff] [blame] | 10 | #include <linux/sys_soc.h> |
| 11 | |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 12 | #include <drm/drm_atomic.h> |
Laurent Pinchart | cef77d4 | 2015-03-05 21:50:00 +0200 | [diff] [blame] | 13 | #include <drm/drm_atomic_helper.h> |
Boris Brezillon | ee68c74 | 2019-08-26 17:26:29 +0200 | [diff] [blame] | 14 | #include <drm/drm_bridge.h> |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 15 | #include <drm/drm_bridge_connector.h> |
Sam Ravnborg | 81f6156 | 2019-07-16 08:42:10 +0200 | [diff] [blame] | 16 | #include <drm/drm_drv.h> |
Laurent Pinchart | 2d278f5 | 2015-03-05 21:31:37 +0200 | [diff] [blame] | 17 | #include <drm/drm_fb_helper.h> |
Sam Ravnborg | 81f6156 | 2019-07-16 08:42:10 +0200 | [diff] [blame] | 18 | #include <drm/drm_file.h> |
| 19 | #include <drm/drm_ioctl.h> |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 20 | #include <drm/drm_panel.h> |
Sam Ravnborg | 81f6156 | 2019-07-16 08:42:10 +0200 | [diff] [blame] | 21 | #include <drm/drm_prime.h> |
| 22 | #include <drm/drm_probe_helper.h> |
| 23 | #include <drm/drm_vblank.h> |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 24 | |
Andy Gross | 5c13779 | 2012-03-05 10:48:39 -0600 | [diff] [blame] | 25 | #include "omap_dmm_tiler.h" |
Laurent Pinchart | 2d278f5 | 2015-03-05 21:31:37 +0200 | [diff] [blame] | 26 | #include "omap_drv.h" |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 27 | |
| 28 | #define DRIVER_NAME MODULE_NAME |
| 29 | #define DRIVER_DESC "OMAP DRM" |
| 30 | #define DRIVER_DATE "20110917" |
| 31 | #define DRIVER_MAJOR 1 |
| 32 | #define DRIVER_MINOR 0 |
| 33 | #define DRIVER_PATCHLEVEL 0 |
| 34 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 35 | /* |
| 36 | * mode config funcs |
| 37 | */ |
| 38 | |
| 39 | /* Notes about mapping DSS and DRM entities: |
| 40 | * CRTC: overlay |
| 41 | * encoder: manager.. with some extension to allow one primary CRTC |
| 42 | * and zero or more video CRTC's to be mapped to one encoder? |
| 43 | * connector: dssdev.. manager can be attached/detached from different |
| 44 | * devices |
| 45 | */ |
| 46 | |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 47 | static void omap_atomic_wait_for_completion(struct drm_device *dev, |
| 48 | struct drm_atomic_state *old_state) |
| 49 | { |
Maarten Lankhorst | 34d8823 | 2017-07-19 16:39:17 +0200 | [diff] [blame] | 50 | struct drm_crtc_state *new_crtc_state; |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 51 | struct drm_crtc *crtc; |
| 52 | unsigned int i; |
| 53 | int ret; |
| 54 | |
Maarten Lankhorst | 34d8823 | 2017-07-19 16:39:17 +0200 | [diff] [blame] | 55 | for_each_new_crtc_in_state(old_state, crtc, new_crtc_state, i) { |
| 56 | if (!new_crtc_state->active) |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 57 | continue; |
| 58 | |
| 59 | ret = omap_crtc_wait_pending(crtc); |
| 60 | |
| 61 | if (!ret) |
| 62 | dev_warn(dev->dev, |
| 63 | "atomic complete timeout (pipe %u)!\n", i); |
| 64 | } |
| 65 | } |
| 66 | |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 67 | static void omap_atomic_commit_tail(struct drm_atomic_state *old_state) |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 68 | { |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 69 | struct drm_device *dev = old_state->dev; |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 70 | struct omap_drm_private *priv = dev->dev_private; |
Daniel Vetter | 250aa22 | 2021-01-21 16:29:56 +0100 | [diff] [blame] | 71 | bool fence_cookie = dma_fence_begin_signalling(); |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 72 | |
Tomi Valkeinen | dac62bc | 2020-12-15 12:46:26 +0200 | [diff] [blame] | 73 | dispc_runtime_get(priv->dispc); |
Laurent Pinchart | 69fb7c8 | 2015-05-28 02:09:56 +0300 | [diff] [blame] | 74 | |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 75 | /* Apply the atomic update. */ |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 76 | drm_atomic_helper_commit_modeset_disables(dev, old_state); |
Jyri Sarha | 897145d | 2017-01-27 12:04:55 +0200 | [diff] [blame] | 77 | |
Tomi Valkeinen | fc5cc967 | 2017-08-23 12:19:02 +0300 | [diff] [blame] | 78 | if (priv->omaprev != 0x3430) { |
| 79 | /* With the current dss dispc implementation we have to enable |
| 80 | * the new modeset before we can commit planes. The dispc ovl |
| 81 | * configuration relies on the video mode configuration been |
| 82 | * written into the HW when the ovl configuration is |
| 83 | * calculated. |
| 84 | * |
| 85 | * This approach is not ideal because after a mode change the |
| 86 | * plane update is executed only after the first vblank |
| 87 | * interrupt. The dispc implementation should be fixed so that |
| 88 | * it is able use uncommitted drm state information. |
| 89 | */ |
| 90 | drm_atomic_helper_commit_modeset_enables(dev, old_state); |
| 91 | omap_atomic_wait_for_completion(dev, old_state); |
Jyri Sarha | 897145d | 2017-01-27 12:04:55 +0200 | [diff] [blame] | 92 | |
Tomi Valkeinen | fc5cc967 | 2017-08-23 12:19:02 +0300 | [diff] [blame] | 93 | drm_atomic_helper_commit_planes(dev, old_state, 0); |
Tomi Valkeinen | fc5cc967 | 2017-08-23 12:19:02 +0300 | [diff] [blame] | 94 | } else { |
| 95 | /* |
| 96 | * OMAP3 DSS seems to have issues with the work-around above, |
| 97 | * resulting in endless sync losts if a crtc is enabled without |
| 98 | * a plane. For now, skip the WA for OMAP3. |
| 99 | */ |
| 100 | drm_atomic_helper_commit_planes(dev, old_state, 0); |
| 101 | |
| 102 | drm_atomic_helper_commit_modeset_enables(dev, old_state); |
Tomi Valkeinen | fc5cc967 | 2017-08-23 12:19:02 +0300 | [diff] [blame] | 103 | } |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 104 | |
Daniel Vetter | 250aa22 | 2021-01-21 16:29:56 +0100 | [diff] [blame] | 105 | drm_atomic_helper_commit_hw_done(old_state); |
| 106 | |
| 107 | dma_fence_end_signalling(fence_cookie); |
| 108 | |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 109 | /* |
| 110 | * Wait for completion of the page flips to ensure that old buffers |
| 111 | * can't be touched by the hardware anymore before cleaning up planes. |
| 112 | */ |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 113 | omap_atomic_wait_for_completion(dev, old_state); |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 114 | |
| 115 | drm_atomic_helper_cleanup_planes(dev, old_state); |
| 116 | |
Tomi Valkeinen | dac62bc | 2020-12-15 12:46:26 +0200 | [diff] [blame] | 117 | dispc_runtime_put(priv->dispc); |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 118 | } |
| 119 | |
Benoit Parrot | e02b5cc | 2021-11-17 15:19:28 +0100 | [diff] [blame] | 120 | static int drm_atomic_state_normalized_zpos_cmp(const void *a, const void *b) |
| 121 | { |
| 122 | const struct drm_plane_state *sa = *(struct drm_plane_state **)a; |
| 123 | const struct drm_plane_state *sb = *(struct drm_plane_state **)b; |
| 124 | |
| 125 | if (sa->normalized_zpos != sb->normalized_zpos) |
| 126 | return sa->normalized_zpos - sb->normalized_zpos; |
| 127 | else |
| 128 | return sa->plane->base.id - sb->plane->base.id; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * This replaces the drm_atomic_normalize_zpos to handle the dual overlay case. |
| 133 | * |
| 134 | * Since both halves need to be 'appear' side by side the zpos is |
| 135 | * recalculated when dealing with dual overlay cases so that the other |
| 136 | * planes zpos is consistent. |
| 137 | */ |
| 138 | static int omap_atomic_update_normalize_zpos(struct drm_device *dev, |
| 139 | struct drm_atomic_state *state) |
| 140 | { |
| 141 | struct drm_crtc *crtc; |
| 142 | struct drm_crtc_state *old_state, *new_state; |
| 143 | struct drm_plane *plane; |
| 144 | int c, i, n, inc; |
| 145 | int total_planes = dev->mode_config.num_total_plane; |
| 146 | struct drm_plane_state **states; |
| 147 | int ret = 0; |
| 148 | |
| 149 | states = kmalloc_array(total_planes, sizeof(*states), GFP_KERNEL); |
| 150 | if (!states) |
| 151 | return -ENOMEM; |
| 152 | |
| 153 | for_each_oldnew_crtc_in_state(state, crtc, old_state, new_state, c) { |
| 154 | if (old_state->plane_mask == new_state->plane_mask && |
| 155 | !new_state->zpos_changed) |
| 156 | continue; |
| 157 | |
| 158 | /* Reset plane increment and index value for every crtc */ |
| 159 | n = 0; |
| 160 | |
| 161 | /* |
| 162 | * Normalization process might create new states for planes |
| 163 | * which normalized_zpos has to be recalculated. |
| 164 | */ |
| 165 | drm_for_each_plane_mask(plane, dev, new_state->plane_mask) { |
| 166 | struct drm_plane_state *plane_state = |
| 167 | drm_atomic_get_plane_state(new_state->state, |
| 168 | plane); |
| 169 | if (IS_ERR(plane_state)) { |
| 170 | ret = PTR_ERR(plane_state); |
| 171 | goto done; |
| 172 | } |
| 173 | states[n++] = plane_state; |
| 174 | } |
| 175 | |
| 176 | sort(states, n, sizeof(*states), |
| 177 | drm_atomic_state_normalized_zpos_cmp, NULL); |
| 178 | |
| 179 | for (i = 0, inc = 0; i < n; i++) { |
| 180 | plane = states[i]->plane; |
| 181 | |
| 182 | states[i]->normalized_zpos = i + inc; |
| 183 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] updated normalized zpos value %d\n", |
| 184 | plane->base.id, plane->name, |
| 185 | states[i]->normalized_zpos); |
| 186 | |
| 187 | if (is_omap_plane_dual_overlay(states[i])) |
| 188 | inc++; |
| 189 | } |
| 190 | new_state->zpos_changed = true; |
| 191 | } |
| 192 | |
| 193 | done: |
| 194 | kfree(states); |
| 195 | return ret; |
| 196 | } |
| 197 | |
| 198 | static int omap_atomic_check(struct drm_device *dev, |
| 199 | struct drm_atomic_state *state) |
| 200 | { |
| 201 | int ret; |
| 202 | |
| 203 | ret = drm_atomic_helper_check(dev, state); |
| 204 | if (ret) |
| 205 | return ret; |
| 206 | |
| 207 | if (dev->mode_config.normalize_zpos) { |
| 208 | ret = omap_atomic_update_normalize_zpos(dev, state); |
| 209 | if (ret) |
| 210 | return ret; |
| 211 | } |
| 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 216 | static const struct drm_mode_config_helper_funcs omap_mode_config_helper_funcs = { |
| 217 | .atomic_commit_tail = omap_atomic_commit_tail, |
| 218 | }; |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 219 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 220 | static const struct drm_mode_config_funcs omap_mode_config_funcs = { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 221 | .fb_create = omap_framebuffer_create, |
Noralf Trønnes | ef62d30 | 2017-12-05 19:25:01 +0100 | [diff] [blame] | 222 | .output_poll_changed = drm_fb_helper_output_poll_changed, |
Benoit Parrot | e02b5cc | 2021-11-17 15:19:28 +0100 | [diff] [blame] | 223 | .atomic_check = omap_atomic_check, |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 224 | .atomic_commit = drm_atomic_helper_commit, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 225 | }; |
| 226 | |
Benoit Parrot | 6e42201 | 2021-11-17 15:19:25 +0100 | [diff] [blame] | 227 | /* Global/shared object state funcs */ |
| 228 | |
| 229 | /* |
| 230 | * This is a helper that returns the private state currently in operation. |
| 231 | * Note that this would return the "old_state" if called in the atomic check |
| 232 | * path, and the "new_state" after the atomic swap has been done. |
| 233 | */ |
| 234 | struct omap_global_state * |
| 235 | omap_get_existing_global_state(struct omap_drm_private *priv) |
| 236 | { |
| 237 | return to_omap_global_state(priv->glob_obj.state); |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | * This acquires the modeset lock set aside for global state, creates |
| 242 | * a new duplicated private object state. |
| 243 | */ |
| 244 | struct omap_global_state *__must_check |
| 245 | omap_get_global_state(struct drm_atomic_state *s) |
| 246 | { |
| 247 | struct omap_drm_private *priv = s->dev->dev_private; |
| 248 | struct drm_private_state *priv_state; |
| 249 | |
| 250 | priv_state = drm_atomic_get_private_obj_state(s, &priv->glob_obj); |
| 251 | if (IS_ERR(priv_state)) |
| 252 | return ERR_CAST(priv_state); |
| 253 | |
| 254 | return to_omap_global_state(priv_state); |
| 255 | } |
| 256 | |
| 257 | static struct drm_private_state * |
| 258 | omap_global_duplicate_state(struct drm_private_obj *obj) |
| 259 | { |
| 260 | struct omap_global_state *state; |
| 261 | |
| 262 | state = kmemdup(obj->state, sizeof(*state), GFP_KERNEL); |
| 263 | if (!state) |
| 264 | return NULL; |
| 265 | |
| 266 | __drm_atomic_helper_private_obj_duplicate_state(obj, &state->base); |
| 267 | |
| 268 | return &state->base; |
| 269 | } |
| 270 | |
| 271 | static void omap_global_destroy_state(struct drm_private_obj *obj, |
| 272 | struct drm_private_state *state) |
| 273 | { |
| 274 | struct omap_global_state *omap_state = to_omap_global_state(state); |
| 275 | |
| 276 | kfree(omap_state); |
| 277 | } |
| 278 | |
| 279 | static const struct drm_private_state_funcs omap_global_state_funcs = { |
| 280 | .atomic_duplicate_state = omap_global_duplicate_state, |
| 281 | .atomic_destroy_state = omap_global_destroy_state, |
| 282 | }; |
| 283 | |
| 284 | static int omap_global_obj_init(struct drm_device *dev) |
| 285 | { |
| 286 | struct omap_drm_private *priv = dev->dev_private; |
| 287 | struct omap_global_state *state; |
| 288 | |
| 289 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
| 290 | if (!state) |
| 291 | return -ENOMEM; |
| 292 | |
| 293 | drm_atomic_private_obj_init(dev, &priv->glob_obj, &state->base, |
| 294 | &omap_global_state_funcs); |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | static void omap_global_obj_fini(struct omap_drm_private *priv) |
| 299 | { |
| 300 | drm_atomic_private_obj_fini(&priv->glob_obj); |
| 301 | } |
| 302 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 303 | static void omap_disconnect_pipelines(struct drm_device *ddev) |
Archit Taneja | cc823bd | 2014-01-02 14:49:52 +0530 | [diff] [blame] | 304 | { |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 305 | struct omap_drm_private *priv = ddev->dev_private; |
| 306 | unsigned int i; |
Archit Taneja | cc823bd | 2014-01-02 14:49:52 +0530 | [diff] [blame] | 307 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 308 | for (i = 0; i < priv->num_pipes; i++) { |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 309 | struct omap_drm_pipeline *pipe = &priv->pipes[i]; |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 310 | |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 311 | omapdss_device_disconnect(NULL, pipe->output); |
| 312 | |
| 313 | omapdss_device_put(pipe->output); |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 314 | pipe->output = NULL; |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 315 | } |
| 316 | |
Laurent Pinchart | e48f9f1 | 2018-03-07 00:01:33 +0200 | [diff] [blame] | 317 | memset(&priv->channels, 0, sizeof(priv->channels)); |
| 318 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 319 | priv->num_pipes = 0; |
Archit Taneja | cc823bd | 2014-01-02 14:49:52 +0530 | [diff] [blame] | 320 | } |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 321 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 322 | static int omap_connect_pipelines(struct drm_device *ddev) |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 323 | { |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 324 | struct omap_drm_private *priv = ddev->dev_private; |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 325 | struct omap_dss_device *output = NULL; |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 326 | int r; |
Peter Ujfalusi | a09d2bc | 2016-05-03 22:08:01 +0300 | [diff] [blame] | 327 | |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 328 | for_each_dss_output(output) { |
| 329 | r = omapdss_device_connect(priv->dss, NULL, output); |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 330 | if (r == -EPROBE_DEFER) { |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 331 | omapdss_device_put(output); |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 332 | return r; |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 333 | } else if (r) { |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 334 | dev_warn(output->dev, "could not connect output %s\n", |
| 335 | output->name); |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 336 | } else { |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 337 | struct omap_drm_pipeline *pipe; |
| 338 | |
| 339 | pipe = &priv->pipes[priv->num_pipes++]; |
| 340 | pipe->output = omapdss_device_get(output); |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 341 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 342 | if (priv->num_pipes == ARRAY_SIZE(priv->pipes)) { |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 343 | /* To balance the 'for_each_dss_output' loop */ |
| 344 | omapdss_device_put(output); |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 345 | break; |
| 346 | } |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 350 | return 0; |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 351 | } |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 352 | |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 353 | static int omap_compare_pipelines(const void *a, const void *b) |
| 354 | { |
| 355 | const struct omap_drm_pipeline *pipe1 = a; |
| 356 | const struct omap_drm_pipeline *pipe2 = b; |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 357 | |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 358 | if (pipe1->alias_id > pipe2->alias_id) |
| 359 | return 1; |
| 360 | else if (pipe1->alias_id < pipe2->alias_id) |
| 361 | return -1; |
| 362 | return 0; |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 363 | } |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 364 | |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 365 | static int omap_modeset_init_properties(struct drm_device *dev) |
| 366 | { |
| 367 | struct omap_drm_private *priv = dev->dev_private; |
Tomi Valkeinen | dac62bc | 2020-12-15 12:46:26 +0200 | [diff] [blame] | 368 | unsigned int num_planes = dispc_get_num_ovls(priv->dispc); |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 369 | |
Laurent Pinchart | dff6c24 | 2017-05-09 01:27:14 +0300 | [diff] [blame] | 370 | priv->zorder_prop = drm_property_create_range(dev, 0, "zorder", 0, |
| 371 | num_planes - 1); |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 372 | if (!priv->zorder_prop) |
| 373 | return -ENOMEM; |
| 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 378 | static int omap_display_id(struct omap_dss_device *output) |
| 379 | { |
| 380 | struct device_node *node = NULL; |
| 381 | |
Sebastian Reichel | 4a55551 | 2020-12-15 12:46:16 +0200 | [diff] [blame] | 382 | if (output->bridge) { |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 383 | struct drm_bridge *bridge = output->bridge; |
| 384 | |
Boris Brezillon | fadf872 | 2019-12-03 15:15:06 +0100 | [diff] [blame] | 385 | while (drm_bridge_get_next_bridge(bridge)) |
| 386 | bridge = drm_bridge_get_next_bridge(bridge); |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 387 | |
| 388 | node = bridge->of_node; |
| 389 | } |
| 390 | |
| 391 | return node ? of_alias_get_id(node, "display") : -ENODEV; |
| 392 | } |
| 393 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 394 | static int omap_modeset_init(struct drm_device *dev) |
| 395 | { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 396 | struct omap_drm_private *priv = dev->dev_private; |
Tomi Valkeinen | dac62bc | 2020-12-15 12:46:26 +0200 | [diff] [blame] | 397 | int num_ovls = dispc_get_num_ovls(priv->dispc); |
| 398 | int num_mgrs = dispc_get_num_mgrs(priv->dispc); |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 399 | unsigned int i; |
Laurent Pinchart | fb9a35f | 2015-01-11 16:30:44 +0200 | [diff] [blame] | 400 | int ret; |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 401 | u32 plane_crtc_mask; |
Tomi Valkeinen | 04b1fc0 | 2013-05-14 10:55:19 +0300 | [diff] [blame] | 402 | |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 403 | if (!omapdss_stack_is_ready()) |
| 404 | return -EPROBE_DEFER; |
| 405 | |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 406 | ret = omap_modeset_init_properties(dev); |
| 407 | if (ret < 0) |
| 408 | return ret; |
| 409 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 410 | /* |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 411 | * This function creates exactly one connector, encoder, crtc, |
| 412 | * and primary plane per each connected dss-device. Each |
| 413 | * connector->encoder->crtc chain is expected to be separate |
| 414 | * and each crtc is connect to a single dss-channel. If the |
| 415 | * configuration does not match the expectations or exceeds |
| 416 | * the available resources, the configuration is rejected. |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 417 | */ |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 418 | ret = omap_connect_pipelines(dev); |
| 419 | if (ret < 0) |
| 420 | return ret; |
| 421 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 422 | if (priv->num_pipes > num_mgrs || priv->num_pipes > num_ovls) { |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 423 | dev_err(dev->dev, "%s(): Too many connected displays\n", |
| 424 | __func__); |
| 425 | return -EINVAL; |
| 426 | } |
| 427 | |
Laurent Pinchart | ac3b131 | 2018-03-05 19:11:30 +0200 | [diff] [blame] | 428 | /* Create all planes first. They can all be put to any CRTC. */ |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 429 | plane_crtc_mask = (1 << priv->num_pipes) - 1; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 430 | |
Laurent Pinchart | ac3b131 | 2018-03-05 19:11:30 +0200 | [diff] [blame] | 431 | for (i = 0; i < num_ovls; i++) { |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 432 | enum drm_plane_type type = i < priv->num_pipes |
Laurent Pinchart | ac3b131 | 2018-03-05 19:11:30 +0200 | [diff] [blame] | 433 | ? DRM_PLANE_TYPE_PRIMARY |
| 434 | : DRM_PLANE_TYPE_OVERLAY; |
| 435 | struct drm_plane *plane; |
| 436 | |
| 437 | if (WARN_ON(priv->num_planes >= ARRAY_SIZE(priv->planes))) |
| 438 | return -EINVAL; |
| 439 | |
| 440 | plane = omap_plane_init(dev, i, type, plane_crtc_mask); |
| 441 | if (IS_ERR(plane)) |
| 442 | return PTR_ERR(plane); |
| 443 | |
| 444 | priv->planes[priv->num_planes++] = plane; |
| 445 | } |
| 446 | |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 447 | /* |
| 448 | * Create the encoders, attach the bridges and get the pipeline alias |
| 449 | * IDs. |
| 450 | */ |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 451 | for (i = 0; i < priv->num_pipes; i++) { |
| 452 | struct omap_drm_pipeline *pipe = &priv->pipes[i]; |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 453 | int id; |
| 454 | |
| 455 | pipe->encoder = omap_encoder_init(dev, pipe->output); |
| 456 | if (!pipe->encoder) |
| 457 | return -ENOMEM; |
| 458 | |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 459 | if (pipe->output->bridge) { |
| 460 | ret = drm_bridge_attach(pipe->encoder, |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 461 | pipe->output->bridge, NULL, |
| 462 | DRM_BRIDGE_ATTACH_NO_CONNECTOR); |
Laurent Pinchart | fb8d617 | 2021-03-23 23:50:08 +0200 | [diff] [blame] | 463 | if (ret < 0) |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 464 | return ret; |
| 465 | } |
| 466 | |
| 467 | id = omap_display_id(pipe->output); |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 468 | pipe->alias_id = id >= 0 ? id : i; |
| 469 | } |
| 470 | |
| 471 | /* Sort the pipelines by DT aliases. */ |
| 472 | sort(priv->pipes, priv->num_pipes, sizeof(priv->pipes[0]), |
| 473 | omap_compare_pipelines, NULL); |
| 474 | |
| 475 | /* |
| 476 | * Populate the pipeline lookup table by DISPC channel. Only one display |
| 477 | * is allowed per channel. |
| 478 | */ |
| 479 | for (i = 0; i < priv->num_pipes; ++i) { |
| 480 | struct omap_drm_pipeline *pipe = &priv->pipes[i]; |
| 481 | enum omap_channel channel = pipe->output->dispc_channel; |
| 482 | |
| 483 | if (WARN_ON(priv->channels[channel] != NULL)) |
| 484 | return -EINVAL; |
| 485 | |
| 486 | priv->channels[channel] = pipe; |
| 487 | } |
| 488 | |
| 489 | /* Create the connectors and CRTCs. */ |
| 490 | for (i = 0; i < priv->num_pipes; i++) { |
| 491 | struct omap_drm_pipeline *pipe = &priv->pipes[i]; |
| 492 | struct drm_encoder *encoder = pipe->encoder; |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 493 | struct drm_crtc *crtc; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 494 | |
Sebastian Reichel | fe5f6e5 | 2020-12-15 12:46:15 +0200 | [diff] [blame] | 495 | pipe->connector = drm_bridge_connector_init(dev, encoder); |
| 496 | if (IS_ERR(pipe->connector)) { |
| 497 | dev_err(priv->dev, |
| 498 | "unable to create bridge connector for %s\n", |
| 499 | pipe->output->name); |
| 500 | return PTR_ERR(pipe->connector); |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 501 | } |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 502 | |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 503 | drm_connector_attach_encoder(pipe->connector, encoder); |
| 504 | |
Laurent Pinchart | 00b30e7 | 2018-03-06 23:37:25 +0200 | [diff] [blame] | 505 | crtc = omap_crtc_init(dev, pipe, priv->planes[i]); |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 506 | if (IS_ERR(crtc)) |
| 507 | return PTR_ERR(crtc); |
| 508 | |
Laurent Pinchart | f969936 | 2018-03-05 14:47:47 +0200 | [diff] [blame] | 509 | encoder->possible_crtcs = 1 << i; |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 510 | pipe->crtc = crtc; |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 511 | } |
| 512 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 513 | DBG("registered %u planes, %u crtcs/encoders/connectors\n", |
| 514 | priv->num_planes, priv->num_pipes); |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 515 | |
Tomi Valkeinen | 1e90711 | 2016-08-23 12:35:39 +0300 | [diff] [blame] | 516 | dev->mode_config.min_width = 8; |
| 517 | dev->mode_config.min_height = 2; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 518 | |
Tomi Valkeinen | 1915d7f | 2018-01-10 11:31:18 +0200 | [diff] [blame] | 519 | /* |
| 520 | * Note: these values are used for multiple independent things: |
| 521 | * connector mode filtering, buffer sizes, crtc sizes... |
| 522 | * Use big enough values here to cover all use cases, and do more |
| 523 | * specific checking in the respective code paths. |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 524 | */ |
Tomi Valkeinen | 1915d7f | 2018-01-10 11:31:18 +0200 | [diff] [blame] | 525 | dev->mode_config.max_width = 8192; |
| 526 | dev->mode_config.max_height = 8192; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 527 | |
Peter Ujfalusi | 23936ba | 2018-03-21 12:20:29 +0200 | [diff] [blame] | 528 | /* We want the zpos to be normalized */ |
| 529 | dev->mode_config.normalize_zpos = true; |
| 530 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 531 | dev->mode_config.funcs = &omap_mode_config_funcs; |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 532 | dev->mode_config.helper_private = &omap_mode_config_helper_funcs; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 533 | |
Laurent Pinchart | 69a1226 | 2015-03-05 21:38:16 +0200 | [diff] [blame] | 534 | drm_mode_config_reset(dev); |
| 535 | |
Laurent Pinchart | 728ae8d | 2015-05-28 00:21:29 +0300 | [diff] [blame] | 536 | omap_drm_irq_install(dev); |
| 537 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 538 | return 0; |
| 539 | } |
| 540 | |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 541 | static void omap_modeset_fini(struct drm_device *ddev) |
| 542 | { |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 543 | omap_drm_irq_uninstall(ddev); |
| 544 | |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 545 | drm_mode_config_cleanup(ddev); |
| 546 | } |
| 547 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 548 | /* |
Peter Ujfalusi | 3c59680 | 2017-06-02 15:26:35 +0300 | [diff] [blame] | 549 | * Enable the HPD in external components if supported |
| 550 | */ |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 551 | static void omap_modeset_enable_external_hpd(struct drm_device *ddev) |
Peter Ujfalusi | 3c59680 | 2017-06-02 15:26:35 +0300 | [diff] [blame] | 552 | { |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 553 | struct omap_drm_private *priv = ddev->dev_private; |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 554 | unsigned int i; |
Peter Ujfalusi | 3c59680 | 2017-06-02 15:26:35 +0300 | [diff] [blame] | 555 | |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 556 | for (i = 0; i < priv->num_pipes; i++) { |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 557 | struct drm_connector *connector = priv->pipes[i].connector; |
| 558 | |
| 559 | if (!connector) |
| 560 | continue; |
| 561 | |
Laurent Pinchart | 75fb968 | 2020-02-26 13:25:00 +0200 | [diff] [blame] | 562 | if (priv->pipes[i].output->bridge) |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 563 | drm_bridge_connector_enable_hpd(connector); |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 564 | } |
Peter Ujfalusi | 3c59680 | 2017-06-02 15:26:35 +0300 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | /* |
| 568 | * Disable the HPD in external components if supported |
| 569 | */ |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 570 | static void omap_modeset_disable_external_hpd(struct drm_device *ddev) |
Peter Ujfalusi | 3c59680 | 2017-06-02 15:26:35 +0300 | [diff] [blame] | 571 | { |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 572 | struct omap_drm_private *priv = ddev->dev_private; |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 573 | unsigned int i; |
Peter Ujfalusi | 3c59680 | 2017-06-02 15:26:35 +0300 | [diff] [blame] | 574 | |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 575 | for (i = 0; i < priv->num_pipes; i++) { |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 576 | struct drm_connector *connector = priv->pipes[i].connector; |
| 577 | |
| 578 | if (!connector) |
| 579 | continue; |
| 580 | |
Laurent Pinchart | 75fb968 | 2020-02-26 13:25:00 +0200 | [diff] [blame] | 581 | if (priv->pipes[i].output->bridge) |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 582 | drm_bridge_connector_disable_hpd(connector); |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 583 | } |
Peter Ujfalusi | 3c59680 | 2017-06-02 15:26:35 +0300 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /* |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 587 | * drm ioctl funcs |
| 588 | */ |
| 589 | |
| 590 | |
| 591 | static int ioctl_get_param(struct drm_device *dev, void *data, |
| 592 | struct drm_file *file_priv) |
| 593 | { |
Rob Clark | 5e3b087 | 2012-10-29 09:31:12 +0100 | [diff] [blame] | 594 | struct omap_drm_private *priv = dev->dev_private; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 595 | struct drm_omap_param *args = data; |
| 596 | |
| 597 | DBG("%p: param=%llu", dev, args->param); |
| 598 | |
| 599 | switch (args->param) { |
| 600 | case OMAP_PARAM_CHIPSET_ID: |
Rob Clark | 5e3b087 | 2012-10-29 09:31:12 +0100 | [diff] [blame] | 601 | args->value = priv->omaprev; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 602 | break; |
| 603 | default: |
| 604 | DBG("unknown parameter %lld", args->param); |
| 605 | return -EINVAL; |
| 606 | } |
| 607 | |
| 608 | return 0; |
| 609 | } |
| 610 | |
Laurent Pinchart | ef3f4e9 | 2015-12-14 22:39:36 +0200 | [diff] [blame] | 611 | #define OMAP_BO_USER_MASK 0x00ffffff /* flags settable by userspace */ |
| 612 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 613 | static int ioctl_gem_new(struct drm_device *dev, void *data, |
| 614 | struct drm_file *file_priv) |
| 615 | { |
| 616 | struct drm_omap_gem_new *args = data; |
Laurent Pinchart | ef3f4e9 | 2015-12-14 22:39:36 +0200 | [diff] [blame] | 617 | u32 flags = args->flags & OMAP_BO_USER_MASK; |
| 618 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 619 | VERB("%p:%p: size=0x%08x, flags=%08x", dev, file_priv, |
Laurent Pinchart | ef3f4e9 | 2015-12-14 22:39:36 +0200 | [diff] [blame] | 620 | args->size.bytes, flags); |
| 621 | |
| 622 | return omap_gem_new_handle(dev, file_priv, args->size, flags, |
| 623 | &args->handle); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 624 | } |
| 625 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 626 | static int ioctl_gem_info(struct drm_device *dev, void *data, |
| 627 | struct drm_file *file_priv) |
| 628 | { |
| 629 | struct drm_omap_gem_info *args = data; |
| 630 | struct drm_gem_object *obj; |
| 631 | int ret = 0; |
| 632 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 633 | VERB("%p:%p: handle=%d", dev, file_priv, args->handle); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 634 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 635 | obj = drm_gem_object_lookup(file_priv, args->handle); |
YAMANE Toshiaki | c7f904b | 2012-11-14 19:30:38 +0900 | [diff] [blame] | 636 | if (!obj) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 637 | return -ENOENT; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 638 | |
Rob Clark | f7f9f45 | 2011-12-05 19:19:22 -0600 | [diff] [blame] | 639 | args->size = omap_gem_mmap_size(obj); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 640 | args->offset = omap_gem_mmap_offset(obj); |
| 641 | |
Emil Velikov | d742cdd | 2020-05-15 10:51:06 +0100 | [diff] [blame] | 642 | drm_gem_object_put(obj); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 643 | |
| 644 | return ret; |
| 645 | } |
| 646 | |
Rob Clark | baa7094 | 2013-08-02 13:27:49 -0400 | [diff] [blame] | 647 | static const struct drm_ioctl_desc ioctls[DRM_COMMAND_END - DRM_COMMAND_BASE] = { |
Hemant Hariyani | 5f6ab8c | 2016-06-07 13:23:19 -0500 | [diff] [blame] | 648 | DRM_IOCTL_DEF_DRV(OMAP_GET_PARAM, ioctl_get_param, |
Emil Velikov | 7042a33 | 2019-05-27 09:17:37 +0100 | [diff] [blame] | 649 | DRM_RENDER_ALLOW), |
Emil Velikov | 9a671c2 | 2019-05-22 16:02:18 +0100 | [diff] [blame] | 650 | DRM_IOCTL_DEF_DRV(OMAP_SET_PARAM, drm_invalid_op, |
Hemant Hariyani | 5f6ab8c | 2016-06-07 13:23:19 -0500 | [diff] [blame] | 651 | DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY), |
| 652 | DRM_IOCTL_DEF_DRV(OMAP_GEM_NEW, ioctl_gem_new, |
Emil Velikov | 7042a33 | 2019-05-27 09:17:37 +0100 | [diff] [blame] | 653 | DRM_RENDER_ALLOW), |
Laurent Pinchart | d6f544f | 2017-05-09 01:27:11 +0300 | [diff] [blame] | 654 | /* Deprecated, to be removed. */ |
| 655 | DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_PREP, drm_noop, |
Emil Velikov | 7042a33 | 2019-05-27 09:17:37 +0100 | [diff] [blame] | 656 | DRM_RENDER_ALLOW), |
Laurent Pinchart | d6f544f | 2017-05-09 01:27:11 +0300 | [diff] [blame] | 657 | /* Deprecated, to be removed. */ |
| 658 | DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_FINI, drm_noop, |
Emil Velikov | 7042a33 | 2019-05-27 09:17:37 +0100 | [diff] [blame] | 659 | DRM_RENDER_ALLOW), |
Hemant Hariyani | 5f6ab8c | 2016-06-07 13:23:19 -0500 | [diff] [blame] | 660 | DRM_IOCTL_DEF_DRV(OMAP_GEM_INFO, ioctl_gem_info, |
Emil Velikov | 7042a33 | 2019-05-27 09:17:37 +0100 | [diff] [blame] | 661 | DRM_RENDER_ALLOW), |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 662 | }; |
| 663 | |
| 664 | /* |
| 665 | * drm driver funcs |
| 666 | */ |
| 667 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 668 | static int dev_open(struct drm_device *dev, struct drm_file *file) |
| 669 | { |
| 670 | file->driver_priv = NULL; |
| 671 | |
| 672 | DBG("open: dev=%p, file=%p", dev, file); |
| 673 | |
| 674 | return 0; |
| 675 | } |
| 676 | |
Rob Clark | ff4f387 | 2012-01-16 12:51:14 -0600 | [diff] [blame] | 677 | static const struct file_operations omapdriver_fops = { |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 678 | .owner = THIS_MODULE, |
| 679 | .open = drm_open, |
| 680 | .unlocked_ioctl = drm_ioctl, |
Tomi Valkeinen | 9d24159a | 2017-02-24 13:24:50 +0200 | [diff] [blame] | 681 | .compat_ioctl = drm_compat_ioctl, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 682 | .release = drm_release, |
| 683 | .mmap = omap_gem_mmap, |
| 684 | .poll = drm_poll, |
| 685 | .read = drm_read, |
| 686 | .llseek = noop_llseek, |
Rob Clark | ff4f387 | 2012-01-16 12:51:14 -0600 | [diff] [blame] | 687 | }; |
| 688 | |
Daniel Vetter | 70a59dd | 2020-11-04 11:04:24 +0100 | [diff] [blame] | 689 | static const struct drm_driver omap_drm_driver = { |
Daniel Vetter | 0424fda | 2019-06-17 17:39:24 +0200 | [diff] [blame] | 690 | .driver_features = DRIVER_MODESET | DRIVER_GEM | |
Hemant Hariyani | 5f6ab8c | 2016-06-07 13:23:19 -0500 | [diff] [blame] | 691 | DRIVER_ATOMIC | DRIVER_RENDER, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 692 | .open = dev_open, |
Noralf Trønnes | ef62d30 | 2017-12-05 19:25:01 +0100 | [diff] [blame] | 693 | .lastclose = drm_fb_helper_lastclose, |
Andy Gross | 6169a148 | 2011-12-15 21:05:17 -0600 | [diff] [blame] | 694 | #ifdef CONFIG_DEBUG_FS |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 695 | .debugfs_init = omap_debugfs_init, |
Andy Gross | 6169a148 | 2011-12-15 21:05:17 -0600 | [diff] [blame] | 696 | #endif |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 697 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 698 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 699 | .gem_prime_import = omap_gem_prime_import, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 700 | .dumb_create = omap_gem_dumb_create, |
| 701 | .dumb_map_offset = omap_gem_dumb_map_offset, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 702 | .ioctls = ioctls, |
| 703 | .num_ioctls = DRM_OMAP_NUM_IOCTLS, |
| 704 | .fops = &omapdriver_fops, |
| 705 | .name = DRIVER_NAME, |
| 706 | .desc = DRIVER_DESC, |
| 707 | .date = DRIVER_DATE, |
| 708 | .major = DRIVER_MAJOR, |
| 709 | .minor = DRIVER_MINOR, |
| 710 | .patchlevel = DRIVER_PATCHLEVEL, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 711 | }; |
| 712 | |
Laurent Pinchart | 6e471fa | 2017-05-06 02:57:12 +0300 | [diff] [blame] | 713 | static const struct soc_device_attribute omapdrm_soc_devices[] = { |
| 714 | { .family = "OMAP3", .data = (void *)0x3430 }, |
| 715 | { .family = "OMAP4", .data = (void *)0x4430 }, |
| 716 | { .family = "OMAP5", .data = (void *)0x5430 }, |
| 717 | { .family = "DRA7", .data = (void *)0x0752 }, |
| 718 | { /* sentinel */ } |
| 719 | }; |
| 720 | |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 721 | static int omapdrm_init(struct omap_drm_private *priv, struct device *dev) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 722 | { |
Laurent Pinchart | 6e471fa | 2017-05-06 02:57:12 +0300 | [diff] [blame] | 723 | const struct soc_device_attribute *soc; |
Sebastian Reichel | 8510148 | 2020-12-15 12:46:11 +0200 | [diff] [blame] | 724 | struct dss_pdata *pdata = dev->platform_data; |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 725 | struct drm_device *ddev; |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 726 | int ret; |
| 727 | |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 728 | DBG("%s", dev_name(dev)); |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 729 | |
Peter Ujfalusi | fb96b67 | 2018-02-12 11:44:36 +0200 | [diff] [blame] | 730 | /* Allocate and initialize the DRM device. */ |
| 731 | ddev = drm_dev_alloc(&omap_drm_driver, dev); |
| 732 | if (IS_ERR(ddev)) |
| 733 | return PTR_ERR(ddev); |
| 734 | |
| 735 | priv->ddev = ddev; |
| 736 | ddev->dev_private = priv; |
| 737 | |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 738 | priv->dev = dev; |
Sebastian Reichel | 8510148 | 2020-12-15 12:46:11 +0200 | [diff] [blame] | 739 | priv->dss = pdata->dss; |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 740 | priv->dispc = dispc_get_dispc(priv->dss); |
Laurent Pinchart | 510c74c | 2017-08-11 16:49:08 +0300 | [diff] [blame] | 741 | |
Tomi Valkeinen | 05ec612 | 2020-12-15 12:46:27 +0200 | [diff] [blame] | 742 | priv->dss->mgr_ops_priv = priv; |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 743 | |
Laurent Pinchart | 6e471fa | 2017-05-06 02:57:12 +0300 | [diff] [blame] | 744 | soc = soc_device_match(omapdrm_soc_devices); |
Laurent Pinchart | 95f22783 | 2021-07-28 18:19:34 +0300 | [diff] [blame] | 745 | priv->omaprev = soc ? (uintptr_t)soc->data : 0; |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 746 | priv->wq = alloc_ordered_workqueue("omapdrm", 0); |
| 747 | |
Daniel Vetter | 5117bd8 | 2018-05-25 19:39:24 +0300 | [diff] [blame] | 748 | mutex_init(&priv->list_lock); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 749 | INIT_LIST_HEAD(&priv->obj_list); |
| 750 | |
Peter Ujfalusi | a7631c4 | 2017-11-30 14:12:37 +0200 | [diff] [blame] | 751 | /* Get memory bandwidth limits */ |
Tomi Valkeinen | dac62bc | 2020-12-15 12:46:26 +0200 | [diff] [blame] | 752 | priv->max_bandwidth = dispc_get_memory_bandwidth_limit(priv->dispc); |
Peter Ujfalusi | a7631c4 | 2017-11-30 14:12:37 +0200 | [diff] [blame] | 753 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 754 | omap_gem_init(ddev); |
| 755 | |
Benoit Parrot | 6e42201 | 2021-11-17 15:19:25 +0100 | [diff] [blame] | 756 | drm_mode_config_init(ddev); |
| 757 | |
| 758 | ret = omap_global_obj_init(ddev); |
Benoit Parrot | c8fa1e7 | 2021-11-17 15:19:23 +0100 | [diff] [blame] | 759 | if (ret) |
| 760 | goto err_gem_deinit; |
| 761 | |
Benoit Parrot | 6e42201 | 2021-11-17 15:19:25 +0100 | [diff] [blame] | 762 | ret = omap_hwoverlays_init(priv); |
| 763 | if (ret) |
| 764 | goto err_free_priv_obj; |
| 765 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 766 | ret = omap_modeset_init(ddev); |
| 767 | if (ret) { |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 768 | dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret); |
Benoit Parrot | c8fa1e7 | 2021-11-17 15:19:23 +0100 | [diff] [blame] | 769 | goto err_free_overlays; |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /* Initialize vblank handling, start with all CRTCs disabled. */ |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 773 | ret = drm_vblank_init(ddev, priv->num_pipes); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 774 | if (ret) { |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 775 | dev_err(priv->dev, "could not init vblank\n"); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 776 | goto err_cleanup_modeset; |
| 777 | } |
| 778 | |
Tomi Valkeinen | efd1f06 | 2018-02-09 09:36:23 +0200 | [diff] [blame] | 779 | omap_fbdev_init(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 780 | |
| 781 | drm_kms_helper_poll_init(ddev); |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 782 | omap_modeset_enable_external_hpd(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 783 | |
| 784 | /* |
| 785 | * Register the DRM device with the core and the connectors with |
| 786 | * sysfs. |
| 787 | */ |
| 788 | ret = drm_dev_register(ddev, 0); |
| 789 | if (ret) |
| 790 | goto err_cleanup_helpers; |
| 791 | |
| 792 | return 0; |
| 793 | |
| 794 | err_cleanup_helpers: |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 795 | omap_modeset_disable_external_hpd(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 796 | drm_kms_helper_poll_fini(ddev); |
Tomi Valkeinen | efd1f06 | 2018-02-09 09:36:23 +0200 | [diff] [blame] | 797 | |
| 798 | omap_fbdev_fini(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 799 | err_cleanup_modeset: |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 800 | omap_modeset_fini(ddev); |
Benoit Parrot | c8fa1e7 | 2021-11-17 15:19:23 +0100 | [diff] [blame] | 801 | err_free_overlays: |
| 802 | omap_hwoverlays_destroy(priv); |
Benoit Parrot | 6e42201 | 2021-11-17 15:19:25 +0100 | [diff] [blame] | 803 | err_free_priv_obj: |
| 804 | omap_global_obj_fini(priv); |
Peter Ujfalusi | fb96b67 | 2018-02-12 11:44:36 +0200 | [diff] [blame] | 805 | err_gem_deinit: |
Benoit Parrot | 6e42201 | 2021-11-17 15:19:25 +0100 | [diff] [blame] | 806 | drm_mode_config_cleanup(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 807 | omap_gem_deinit(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 808 | destroy_workqueue(priv->wq); |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 809 | omap_disconnect_pipelines(ddev); |
Thomas Zimmermann | 08bafff | 2018-06-18 15:07:27 +0200 | [diff] [blame] | 810 | drm_dev_put(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 811 | return ret; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 812 | } |
| 813 | |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 814 | static void omapdrm_cleanup(struct omap_drm_private *priv) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 815 | { |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 816 | struct drm_device *ddev = priv->ddev; |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 817 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 818 | DBG(""); |
Andy Gross | 5c13779 | 2012-03-05 10:48:39 -0600 | [diff] [blame] | 819 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 820 | drm_dev_unregister(ddev); |
| 821 | |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 822 | omap_modeset_disable_external_hpd(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 823 | drm_kms_helper_poll_fini(ddev); |
| 824 | |
Tomi Valkeinen | efd1f06 | 2018-02-09 09:36:23 +0200 | [diff] [blame] | 825 | omap_fbdev_fini(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 826 | |
Tomi Valkeinen | 8a54aa9 | 2017-03-27 10:02:22 +0300 | [diff] [blame] | 827 | drm_atomic_helper_shutdown(ddev); |
| 828 | |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 829 | omap_modeset_fini(ddev); |
Benoit Parrot | c8fa1e7 | 2021-11-17 15:19:23 +0100 | [diff] [blame] | 830 | omap_hwoverlays_destroy(priv); |
Benoit Parrot | 6e42201 | 2021-11-17 15:19:25 +0100 | [diff] [blame] | 831 | omap_global_obj_fini(priv); |
| 832 | drm_mode_config_cleanup(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 833 | omap_gem_deinit(ddev); |
| 834 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 835 | destroy_workqueue(priv->wq); |
Tomi Valkeinen | 707cf58 | 2014-04-02 13:47:43 +0300 | [diff] [blame] | 836 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 837 | omap_disconnect_pipelines(ddev); |
Peter Ujfalusi | fb96b67 | 2018-02-12 11:44:36 +0200 | [diff] [blame] | 838 | |
Thomas Zimmermann | 08bafff | 2018-06-18 15:07:27 +0200 | [diff] [blame] | 839 | drm_dev_put(ddev); |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | static int pdev_probe(struct platform_device *pdev) |
| 843 | { |
| 844 | struct omap_drm_private *priv; |
| 845 | int ret; |
| 846 | |
Tomi Valkeinen | 63daf4e | 2019-08-09 13:00:38 +0300 | [diff] [blame] | 847 | ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 848 | if (ret) { |
| 849 | dev_err(&pdev->dev, "Failed to set the DMA mask\n"); |
| 850 | return ret; |
| 851 | } |
| 852 | |
| 853 | /* Allocate and initialize the driver private structure. */ |
| 854 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 855 | if (!priv) |
| 856 | return -ENOMEM; |
| 857 | |
| 858 | platform_set_drvdata(pdev, priv); |
| 859 | |
| 860 | ret = omapdrm_init(priv, &pdev->dev); |
| 861 | if (ret < 0) |
| 862 | kfree(priv); |
| 863 | |
| 864 | return ret; |
| 865 | } |
| 866 | |
| 867 | static int pdev_remove(struct platform_device *pdev) |
| 868 | { |
| 869 | struct omap_drm_private *priv = platform_get_drvdata(pdev); |
| 870 | |
| 871 | omapdrm_cleanup(priv); |
| 872 | kfree(priv); |
Daniel Vetter | fd3c025 | 2013-12-11 11:34:26 +0100 | [diff] [blame] | 873 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 874 | return 0; |
| 875 | } |
| 876 | |
Grygorii Strashko | 8450c8d | 2015-02-26 15:57:17 +0200 | [diff] [blame] | 877 | #ifdef CONFIG_PM_SLEEP |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 878 | static int omap_drm_suspend(struct device *dev) |
| 879 | { |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 880 | struct omap_drm_private *priv = dev_get_drvdata(dev); |
| 881 | struct drm_device *drm_dev = priv->ddev; |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 882 | |
Laurent Pinchart | d2c5316 | 2018-09-04 17:08:33 +0300 | [diff] [blame] | 883 | return drm_mode_config_helper_suspend(drm_dev); |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | static int omap_drm_resume(struct device *dev) |
| 887 | { |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 888 | struct omap_drm_private *priv = dev_get_drvdata(dev); |
| 889 | struct drm_device *drm_dev = priv->ddev; |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 890 | |
Laurent Pinchart | d2c5316 | 2018-09-04 17:08:33 +0300 | [diff] [blame] | 891 | drm_mode_config_helper_resume(drm_dev); |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 892 | |
Laurent Pinchart | 7fb15c4 | 2017-10-13 17:58:58 +0300 | [diff] [blame] | 893 | return omap_gem_resume(drm_dev); |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 894 | } |
Andy Gross | e78edba | 2012-12-19 14:53:37 -0600 | [diff] [blame] | 895 | #endif |
| 896 | |
Grygorii Strashko | 8450c8d | 2015-02-26 15:57:17 +0200 | [diff] [blame] | 897 | static SIMPLE_DEV_PM_OPS(omapdrm_pm_ops, omap_drm_suspend, omap_drm_resume); |
| 898 | |
Tomi Valkeinen | 6717cd2 | 2013-04-10 10:44:00 +0300 | [diff] [blame] | 899 | static struct platform_driver pdev = { |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 900 | .driver = { |
Tomi Valkeinen | f64eafa | 2017-08-16 12:43:55 +0300 | [diff] [blame] | 901 | .name = "omapdrm", |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 902 | .pm = &omapdrm_pm_ops, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 903 | }, |
| 904 | .probe = pdev_probe, |
| 905 | .remove = pdev_remove, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 906 | }; |
| 907 | |
Thierry Reding | e1c49bd | 2015-12-02 17:23:31 +0100 | [diff] [blame] | 908 | static struct platform_driver * const drivers[] = { |
| 909 | &omap_dmm_driver, |
| 910 | &pdev, |
| 911 | }; |
| 912 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 913 | static int __init omap_drm_init(void) |
| 914 | { |
Tomi Valkeinen | 55b68fb | 2020-12-15 12:46:23 +0200 | [diff] [blame] | 915 | int r; |
| 916 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 917 | DBG("init"); |
Tomi Valkeinen | ea7e3a6 | 2014-04-02 14:31:50 +0300 | [diff] [blame] | 918 | |
Tomi Valkeinen | 55b68fb | 2020-12-15 12:46:23 +0200 | [diff] [blame] | 919 | r = omap_dss_init(); |
| 920 | if (r) |
| 921 | return r; |
| 922 | |
| 923 | r = platform_register_drivers(drivers, ARRAY_SIZE(drivers)); |
| 924 | if (r) { |
| 925 | omap_dss_exit(); |
| 926 | return r; |
| 927 | } |
| 928 | |
| 929 | return 0; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | static void __exit omap_drm_fini(void) |
| 933 | { |
| 934 | DBG("fini"); |
Tomi Valkeinen | ea7e3a6 | 2014-04-02 14:31:50 +0300 | [diff] [blame] | 935 | |
Thierry Reding | e1c49bd | 2015-12-02 17:23:31 +0100 | [diff] [blame] | 936 | platform_unregister_drivers(drivers, ARRAY_SIZE(drivers)); |
Tomi Valkeinen | 55b68fb | 2020-12-15 12:46:23 +0200 | [diff] [blame] | 937 | |
| 938 | omap_dss_exit(); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 939 | } |
| 940 | |
Tomi Valkeinen | 55b68fb | 2020-12-15 12:46:23 +0200 | [diff] [blame] | 941 | module_init(omap_drm_init); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 942 | module_exit(omap_drm_fini); |
| 943 | |
| 944 | MODULE_AUTHOR("Rob Clark <rob@ti.com>"); |
Tomi Valkeinen | 55b68fb | 2020-12-15 12:46:23 +0200 | [diff] [blame] | 945 | MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>"); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 946 | MODULE_DESCRIPTION("OMAP DRM Display Driver"); |
| 947 | MODULE_ALIAS("platform:" DRIVER_NAME); |
| 948 | MODULE_LICENSE("GPL v2"); |