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 | |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 120 | static const struct drm_mode_config_helper_funcs omap_mode_config_helper_funcs = { |
| 121 | .atomic_commit_tail = omap_atomic_commit_tail, |
| 122 | }; |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 123 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 124 | static const struct drm_mode_config_funcs omap_mode_config_funcs = { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 125 | .fb_create = omap_framebuffer_create, |
Noralf Trønnes | ef62d30 | 2017-12-05 19:25:01 +0100 | [diff] [blame] | 126 | .output_poll_changed = drm_fb_helper_output_poll_changed, |
Laurent Pinchart | cef77d4 | 2015-03-05 21:50:00 +0200 | [diff] [blame] | 127 | .atomic_check = drm_atomic_helper_check, |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 128 | .atomic_commit = drm_atomic_helper_commit, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 129 | }; |
| 130 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 131 | static void omap_disconnect_pipelines(struct drm_device *ddev) |
Archit Taneja | cc823bd | 2014-01-02 14:49:52 +0530 | [diff] [blame] | 132 | { |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 133 | struct omap_drm_private *priv = ddev->dev_private; |
| 134 | unsigned int i; |
Archit Taneja | cc823bd | 2014-01-02 14:49:52 +0530 | [diff] [blame] | 135 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 136 | for (i = 0; i < priv->num_pipes; i++) { |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 137 | struct omap_drm_pipeline *pipe = &priv->pipes[i]; |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 138 | |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 139 | omapdss_device_disconnect(NULL, pipe->output); |
| 140 | |
| 141 | omapdss_device_put(pipe->output); |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 142 | pipe->output = NULL; |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 143 | } |
| 144 | |
Laurent Pinchart | e48f9f1 | 2018-03-07 00:01:33 +0200 | [diff] [blame] | 145 | memset(&priv->channels, 0, sizeof(priv->channels)); |
| 146 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 147 | priv->num_pipes = 0; |
Archit Taneja | cc823bd | 2014-01-02 14:49:52 +0530 | [diff] [blame] | 148 | } |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 149 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 150 | static int omap_connect_pipelines(struct drm_device *ddev) |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 151 | { |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 152 | struct omap_drm_private *priv = ddev->dev_private; |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 153 | struct omap_dss_device *output = NULL; |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 154 | int r; |
Peter Ujfalusi | a09d2bc | 2016-05-03 22:08:01 +0300 | [diff] [blame] | 155 | |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 156 | for_each_dss_output(output) { |
| 157 | r = omapdss_device_connect(priv->dss, NULL, output); |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 158 | if (r == -EPROBE_DEFER) { |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 159 | omapdss_device_put(output); |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 160 | return r; |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 161 | } else if (r) { |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 162 | dev_warn(output->dev, "could not connect output %s\n", |
| 163 | output->name); |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 164 | } else { |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 165 | struct omap_drm_pipeline *pipe; |
| 166 | |
| 167 | pipe = &priv->pipes[priv->num_pipes++]; |
| 168 | pipe->output = omapdss_device_get(output); |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 169 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 170 | if (priv->num_pipes == ARRAY_SIZE(priv->pipes)) { |
Laurent Pinchart | 511afb4 | 2018-03-04 23:42:36 +0200 | [diff] [blame] | 171 | /* To balance the 'for_each_dss_output' loop */ |
| 172 | omapdss_device_put(output); |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 173 | break; |
| 174 | } |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 178 | return 0; |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 179 | } |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 180 | |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 181 | static int omap_compare_pipelines(const void *a, const void *b) |
| 182 | { |
| 183 | const struct omap_drm_pipeline *pipe1 = a; |
| 184 | const struct omap_drm_pipeline *pipe2 = b; |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 185 | |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 186 | if (pipe1->alias_id > pipe2->alias_id) |
| 187 | return 1; |
| 188 | else if (pipe1->alias_id < pipe2->alias_id) |
| 189 | return -1; |
| 190 | return 0; |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 191 | } |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 192 | |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 193 | static int omap_modeset_init_properties(struct drm_device *dev) |
| 194 | { |
| 195 | struct omap_drm_private *priv = dev->dev_private; |
Tomi Valkeinen | dac62bc | 2020-12-15 12:46:26 +0200 | [diff] [blame] | 196 | unsigned int num_planes = dispc_get_num_ovls(priv->dispc); |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 197 | |
Laurent Pinchart | dff6c24 | 2017-05-09 01:27:14 +0300 | [diff] [blame] | 198 | priv->zorder_prop = drm_property_create_range(dev, 0, "zorder", 0, |
| 199 | num_planes - 1); |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 200 | if (!priv->zorder_prop) |
| 201 | return -ENOMEM; |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 206 | static int omap_display_id(struct omap_dss_device *output) |
| 207 | { |
| 208 | struct device_node *node = NULL; |
| 209 | |
Sebastian Reichel | 4a55551 | 2020-12-15 12:46:16 +0200 | [diff] [blame] | 210 | if (output->bridge) { |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 211 | struct drm_bridge *bridge = output->bridge; |
| 212 | |
Boris Brezillon | fadf872 | 2019-12-03 15:15:06 +0100 | [diff] [blame] | 213 | while (drm_bridge_get_next_bridge(bridge)) |
| 214 | bridge = drm_bridge_get_next_bridge(bridge); |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 215 | |
| 216 | node = bridge->of_node; |
| 217 | } |
| 218 | |
| 219 | return node ? of_alias_get_id(node, "display") : -ENODEV; |
| 220 | } |
| 221 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 222 | static int omap_modeset_init(struct drm_device *dev) |
| 223 | { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 224 | struct omap_drm_private *priv = dev->dev_private; |
Tomi Valkeinen | dac62bc | 2020-12-15 12:46:26 +0200 | [diff] [blame] | 225 | int num_ovls = dispc_get_num_ovls(priv->dispc); |
| 226 | int num_mgrs = dispc_get_num_mgrs(priv->dispc); |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 227 | unsigned int i; |
Laurent Pinchart | fb9a35f | 2015-01-11 16:30:44 +0200 | [diff] [blame] | 228 | int ret; |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 229 | u32 plane_crtc_mask; |
Tomi Valkeinen | 04b1fc0 | 2013-05-14 10:55:19 +0300 | [diff] [blame] | 230 | |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 231 | if (!omapdss_stack_is_ready()) |
| 232 | return -EPROBE_DEFER; |
| 233 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 234 | drm_mode_config_init(dev); |
| 235 | |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 236 | ret = omap_modeset_init_properties(dev); |
| 237 | if (ret < 0) |
| 238 | return ret; |
| 239 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 240 | /* |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 241 | * This function creates exactly one connector, encoder, crtc, |
| 242 | * and primary plane per each connected dss-device. Each |
| 243 | * connector->encoder->crtc chain is expected to be separate |
| 244 | * and each crtc is connect to a single dss-channel. If the |
| 245 | * configuration does not match the expectations or exceeds |
| 246 | * the available resources, the configuration is rejected. |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 247 | */ |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 248 | ret = omap_connect_pipelines(dev); |
| 249 | if (ret < 0) |
| 250 | return ret; |
| 251 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 252 | if (priv->num_pipes > num_mgrs || priv->num_pipes > num_ovls) { |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 253 | dev_err(dev->dev, "%s(): Too many connected displays\n", |
| 254 | __func__); |
| 255 | return -EINVAL; |
| 256 | } |
| 257 | |
Laurent Pinchart | ac3b131 | 2018-03-05 19:11:30 +0200 | [diff] [blame] | 258 | /* Create all planes first. They can all be put to any CRTC. */ |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 259 | plane_crtc_mask = (1 << priv->num_pipes) - 1; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 260 | |
Laurent Pinchart | ac3b131 | 2018-03-05 19:11:30 +0200 | [diff] [blame] | 261 | for (i = 0; i < num_ovls; i++) { |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 262 | enum drm_plane_type type = i < priv->num_pipes |
Laurent Pinchart | ac3b131 | 2018-03-05 19:11:30 +0200 | [diff] [blame] | 263 | ? DRM_PLANE_TYPE_PRIMARY |
| 264 | : DRM_PLANE_TYPE_OVERLAY; |
| 265 | struct drm_plane *plane; |
| 266 | |
| 267 | if (WARN_ON(priv->num_planes >= ARRAY_SIZE(priv->planes))) |
| 268 | return -EINVAL; |
| 269 | |
| 270 | plane = omap_plane_init(dev, i, type, plane_crtc_mask); |
| 271 | if (IS_ERR(plane)) |
| 272 | return PTR_ERR(plane); |
| 273 | |
| 274 | priv->planes[priv->num_planes++] = plane; |
| 275 | } |
| 276 | |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 277 | /* |
| 278 | * Create the encoders, attach the bridges and get the pipeline alias |
| 279 | * IDs. |
| 280 | */ |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 281 | for (i = 0; i < priv->num_pipes; i++) { |
| 282 | struct omap_drm_pipeline *pipe = &priv->pipes[i]; |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 283 | int id; |
| 284 | |
| 285 | pipe->encoder = omap_encoder_init(dev, pipe->output); |
| 286 | if (!pipe->encoder) |
| 287 | return -ENOMEM; |
| 288 | |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 289 | if (pipe->output->bridge) { |
| 290 | ret = drm_bridge_attach(pipe->encoder, |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 291 | pipe->output->bridge, NULL, |
| 292 | DRM_BRIDGE_ATTACH_NO_CONNECTOR); |
Laurent Pinchart | fb8d617 | 2021-03-23 23:50:08 +0200 | [diff] [blame^] | 293 | if (ret < 0) |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | id = omap_display_id(pipe->output); |
Laurent Pinchart | a4e2652 | 2018-09-23 14:13:15 +0300 | [diff] [blame] | 298 | pipe->alias_id = id >= 0 ? id : i; |
| 299 | } |
| 300 | |
| 301 | /* Sort the pipelines by DT aliases. */ |
| 302 | sort(priv->pipes, priv->num_pipes, sizeof(priv->pipes[0]), |
| 303 | omap_compare_pipelines, NULL); |
| 304 | |
| 305 | /* |
| 306 | * Populate the pipeline lookup table by DISPC channel. Only one display |
| 307 | * is allowed per channel. |
| 308 | */ |
| 309 | for (i = 0; i < priv->num_pipes; ++i) { |
| 310 | struct omap_drm_pipeline *pipe = &priv->pipes[i]; |
| 311 | enum omap_channel channel = pipe->output->dispc_channel; |
| 312 | |
| 313 | if (WARN_ON(priv->channels[channel] != NULL)) |
| 314 | return -EINVAL; |
| 315 | |
| 316 | priv->channels[channel] = pipe; |
| 317 | } |
| 318 | |
| 319 | /* Create the connectors and CRTCs. */ |
| 320 | for (i = 0; i < priv->num_pipes; i++) { |
| 321 | struct omap_drm_pipeline *pipe = &priv->pipes[i]; |
| 322 | struct drm_encoder *encoder = pipe->encoder; |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 323 | struct drm_crtc *crtc; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 324 | |
Sebastian Reichel | fe5f6e5 | 2020-12-15 12:46:15 +0200 | [diff] [blame] | 325 | pipe->connector = drm_bridge_connector_init(dev, encoder); |
| 326 | if (IS_ERR(pipe->connector)) { |
| 327 | dev_err(priv->dev, |
| 328 | "unable to create bridge connector for %s\n", |
| 329 | pipe->output->name); |
| 330 | return PTR_ERR(pipe->connector); |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 331 | } |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 332 | |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 333 | drm_connector_attach_encoder(pipe->connector, encoder); |
| 334 | |
Laurent Pinchart | 00b30e7 | 2018-03-06 23:37:25 +0200 | [diff] [blame] | 335 | crtc = omap_crtc_init(dev, pipe, priv->planes[i]); |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 336 | if (IS_ERR(crtc)) |
| 337 | return PTR_ERR(crtc); |
| 338 | |
Laurent Pinchart | f969936 | 2018-03-05 14:47:47 +0200 | [diff] [blame] | 339 | encoder->possible_crtcs = 1 << i; |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 340 | pipe->crtc = crtc; |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 341 | } |
| 342 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 343 | DBG("registered %u planes, %u crtcs/encoders/connectors\n", |
| 344 | priv->num_planes, priv->num_pipes); |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 345 | |
Tomi Valkeinen | 1e90711 | 2016-08-23 12:35:39 +0300 | [diff] [blame] | 346 | dev->mode_config.min_width = 8; |
| 347 | dev->mode_config.min_height = 2; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 348 | |
Tomi Valkeinen | 1915d7f | 2018-01-10 11:31:18 +0200 | [diff] [blame] | 349 | /* |
| 350 | * Note: these values are used for multiple independent things: |
| 351 | * connector mode filtering, buffer sizes, crtc sizes... |
| 352 | * Use big enough values here to cover all use cases, and do more |
| 353 | * specific checking in the respective code paths. |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 354 | */ |
Tomi Valkeinen | 1915d7f | 2018-01-10 11:31:18 +0200 | [diff] [blame] | 355 | dev->mode_config.max_width = 8192; |
| 356 | dev->mode_config.max_height = 8192; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 357 | |
Peter Ujfalusi | 23936ba | 2018-03-21 12:20:29 +0200 | [diff] [blame] | 358 | /* We want the zpos to be normalized */ |
| 359 | dev->mode_config.normalize_zpos = true; |
| 360 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 361 | dev->mode_config.funcs = &omap_mode_config_funcs; |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 362 | dev->mode_config.helper_private = &omap_mode_config_helper_funcs; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 363 | |
Laurent Pinchart | 69a1226 | 2015-03-05 21:38:16 +0200 | [diff] [blame] | 364 | drm_mode_config_reset(dev); |
| 365 | |
Laurent Pinchart | 728ae8d | 2015-05-28 00:21:29 +0300 | [diff] [blame] | 366 | omap_drm_irq_install(dev); |
| 367 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 368 | return 0; |
| 369 | } |
| 370 | |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 371 | static void omap_modeset_fini(struct drm_device *ddev) |
| 372 | { |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 373 | omap_drm_irq_uninstall(ddev); |
| 374 | |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 375 | drm_mode_config_cleanup(ddev); |
| 376 | } |
| 377 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 378 | /* |
Peter Ujfalusi | 3c59680 | 2017-06-02 15:26:35 +0300 | [diff] [blame] | 379 | * Enable the HPD in external components if supported |
| 380 | */ |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 381 | static void omap_modeset_enable_external_hpd(struct drm_device *ddev) |
Peter Ujfalusi | 3c59680 | 2017-06-02 15:26:35 +0300 | [diff] [blame] | 382 | { |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 383 | struct omap_drm_private *priv = ddev->dev_private; |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 384 | unsigned int i; |
Peter Ujfalusi | 3c59680 | 2017-06-02 15:26:35 +0300 | [diff] [blame] | 385 | |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 386 | for (i = 0; i < priv->num_pipes; i++) { |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 387 | struct drm_connector *connector = priv->pipes[i].connector; |
| 388 | |
| 389 | if (!connector) |
| 390 | continue; |
| 391 | |
Laurent Pinchart | 75fb968 | 2020-02-26 13:25:00 +0200 | [diff] [blame] | 392 | if (priv->pipes[i].output->bridge) |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 393 | drm_bridge_connector_enable_hpd(connector); |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 394 | } |
Peter Ujfalusi | 3c59680 | 2017-06-02 15:26:35 +0300 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | /* |
| 398 | * Disable the HPD in external components if supported |
| 399 | */ |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 400 | static void omap_modeset_disable_external_hpd(struct drm_device *ddev) |
Peter Ujfalusi | 3c59680 | 2017-06-02 15:26:35 +0300 | [diff] [blame] | 401 | { |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 402 | struct omap_drm_private *priv = ddev->dev_private; |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 403 | unsigned int i; |
Peter Ujfalusi | 3c59680 | 2017-06-02 15:26:35 +0300 | [diff] [blame] | 404 | |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 405 | for (i = 0; i < priv->num_pipes; i++) { |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 406 | struct drm_connector *connector = priv->pipes[i].connector; |
| 407 | |
| 408 | if (!connector) |
| 409 | continue; |
| 410 | |
Laurent Pinchart | 75fb968 | 2020-02-26 13:25:00 +0200 | [diff] [blame] | 411 | if (priv->pipes[i].output->bridge) |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 412 | drm_bridge_connector_disable_hpd(connector); |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 413 | } |
Peter Ujfalusi | 3c59680 | 2017-06-02 15:26:35 +0300 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | /* |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 417 | * drm ioctl funcs |
| 418 | */ |
| 419 | |
| 420 | |
| 421 | static int ioctl_get_param(struct drm_device *dev, void *data, |
| 422 | struct drm_file *file_priv) |
| 423 | { |
Rob Clark | 5e3b087 | 2012-10-29 09:31:12 +0100 | [diff] [blame] | 424 | struct omap_drm_private *priv = dev->dev_private; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 425 | struct drm_omap_param *args = data; |
| 426 | |
| 427 | DBG("%p: param=%llu", dev, args->param); |
| 428 | |
| 429 | switch (args->param) { |
| 430 | case OMAP_PARAM_CHIPSET_ID: |
Rob Clark | 5e3b087 | 2012-10-29 09:31:12 +0100 | [diff] [blame] | 431 | args->value = priv->omaprev; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 432 | break; |
| 433 | default: |
| 434 | DBG("unknown parameter %lld", args->param); |
| 435 | return -EINVAL; |
| 436 | } |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
Laurent Pinchart | ef3f4e9 | 2015-12-14 22:39:36 +0200 | [diff] [blame] | 441 | #define OMAP_BO_USER_MASK 0x00ffffff /* flags settable by userspace */ |
| 442 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 443 | static int ioctl_gem_new(struct drm_device *dev, void *data, |
| 444 | struct drm_file *file_priv) |
| 445 | { |
| 446 | struct drm_omap_gem_new *args = data; |
Laurent Pinchart | ef3f4e9 | 2015-12-14 22:39:36 +0200 | [diff] [blame] | 447 | u32 flags = args->flags & OMAP_BO_USER_MASK; |
| 448 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 449 | VERB("%p:%p: size=0x%08x, flags=%08x", dev, file_priv, |
Laurent Pinchart | ef3f4e9 | 2015-12-14 22:39:36 +0200 | [diff] [blame] | 450 | args->size.bytes, flags); |
| 451 | |
| 452 | return omap_gem_new_handle(dev, file_priv, args->size, flags, |
| 453 | &args->handle); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 454 | } |
| 455 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 456 | static int ioctl_gem_info(struct drm_device *dev, void *data, |
| 457 | struct drm_file *file_priv) |
| 458 | { |
| 459 | struct drm_omap_gem_info *args = data; |
| 460 | struct drm_gem_object *obj; |
| 461 | int ret = 0; |
| 462 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 463 | VERB("%p:%p: handle=%d", dev, file_priv, args->handle); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 464 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 465 | obj = drm_gem_object_lookup(file_priv, args->handle); |
YAMANE Toshiaki | c7f904b | 2012-11-14 19:30:38 +0900 | [diff] [blame] | 466 | if (!obj) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 467 | return -ENOENT; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 468 | |
Rob Clark | f7f9f45 | 2011-12-05 19:19:22 -0600 | [diff] [blame] | 469 | args->size = omap_gem_mmap_size(obj); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 470 | args->offset = omap_gem_mmap_offset(obj); |
| 471 | |
Emil Velikov | d742cdd | 2020-05-15 10:51:06 +0100 | [diff] [blame] | 472 | drm_gem_object_put(obj); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 473 | |
| 474 | return ret; |
| 475 | } |
| 476 | |
Rob Clark | baa7094 | 2013-08-02 13:27:49 -0400 | [diff] [blame] | 477 | 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] | 478 | DRM_IOCTL_DEF_DRV(OMAP_GET_PARAM, ioctl_get_param, |
Emil Velikov | 7042a33 | 2019-05-27 09:17:37 +0100 | [diff] [blame] | 479 | DRM_RENDER_ALLOW), |
Emil Velikov | 9a671c2 | 2019-05-22 16:02:18 +0100 | [diff] [blame] | 480 | DRM_IOCTL_DEF_DRV(OMAP_SET_PARAM, drm_invalid_op, |
Hemant Hariyani | 5f6ab8c | 2016-06-07 13:23:19 -0500 | [diff] [blame] | 481 | DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY), |
| 482 | DRM_IOCTL_DEF_DRV(OMAP_GEM_NEW, ioctl_gem_new, |
Emil Velikov | 7042a33 | 2019-05-27 09:17:37 +0100 | [diff] [blame] | 483 | DRM_RENDER_ALLOW), |
Laurent Pinchart | d6f544f | 2017-05-09 01:27:11 +0300 | [diff] [blame] | 484 | /* Deprecated, to be removed. */ |
| 485 | DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_PREP, drm_noop, |
Emil Velikov | 7042a33 | 2019-05-27 09:17:37 +0100 | [diff] [blame] | 486 | DRM_RENDER_ALLOW), |
Laurent Pinchart | d6f544f | 2017-05-09 01:27:11 +0300 | [diff] [blame] | 487 | /* Deprecated, to be removed. */ |
| 488 | DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_FINI, drm_noop, |
Emil Velikov | 7042a33 | 2019-05-27 09:17:37 +0100 | [diff] [blame] | 489 | DRM_RENDER_ALLOW), |
Hemant Hariyani | 5f6ab8c | 2016-06-07 13:23:19 -0500 | [diff] [blame] | 490 | DRM_IOCTL_DEF_DRV(OMAP_GEM_INFO, ioctl_gem_info, |
Emil Velikov | 7042a33 | 2019-05-27 09:17:37 +0100 | [diff] [blame] | 491 | DRM_RENDER_ALLOW), |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 492 | }; |
| 493 | |
| 494 | /* |
| 495 | * drm driver funcs |
| 496 | */ |
| 497 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 498 | static int dev_open(struct drm_device *dev, struct drm_file *file) |
| 499 | { |
| 500 | file->driver_priv = NULL; |
| 501 | |
| 502 | DBG("open: dev=%p, file=%p", dev, file); |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
Rob Clark | ff4f387 | 2012-01-16 12:51:14 -0600 | [diff] [blame] | 507 | static const struct file_operations omapdriver_fops = { |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 508 | .owner = THIS_MODULE, |
| 509 | .open = drm_open, |
| 510 | .unlocked_ioctl = drm_ioctl, |
Tomi Valkeinen | 9d24159a | 2017-02-24 13:24:50 +0200 | [diff] [blame] | 511 | .compat_ioctl = drm_compat_ioctl, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 512 | .release = drm_release, |
| 513 | .mmap = omap_gem_mmap, |
| 514 | .poll = drm_poll, |
| 515 | .read = drm_read, |
| 516 | .llseek = noop_llseek, |
Rob Clark | ff4f387 | 2012-01-16 12:51:14 -0600 | [diff] [blame] | 517 | }; |
| 518 | |
Daniel Vetter | 70a59dd | 2020-11-04 11:04:24 +0100 | [diff] [blame] | 519 | static const struct drm_driver omap_drm_driver = { |
Daniel Vetter | 0424fda | 2019-06-17 17:39:24 +0200 | [diff] [blame] | 520 | .driver_features = DRIVER_MODESET | DRIVER_GEM | |
Hemant Hariyani | 5f6ab8c | 2016-06-07 13:23:19 -0500 | [diff] [blame] | 521 | DRIVER_ATOMIC | DRIVER_RENDER, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 522 | .open = dev_open, |
Noralf Trønnes | ef62d30 | 2017-12-05 19:25:01 +0100 | [diff] [blame] | 523 | .lastclose = drm_fb_helper_lastclose, |
Andy Gross | 6169a148 | 2011-12-15 21:05:17 -0600 | [diff] [blame] | 524 | #ifdef CONFIG_DEBUG_FS |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 525 | .debugfs_init = omap_debugfs_init, |
Andy Gross | 6169a148 | 2011-12-15 21:05:17 -0600 | [diff] [blame] | 526 | #endif |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 527 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 528 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 529 | .gem_prime_import = omap_gem_prime_import, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 530 | .dumb_create = omap_gem_dumb_create, |
| 531 | .dumb_map_offset = omap_gem_dumb_map_offset, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 532 | .ioctls = ioctls, |
| 533 | .num_ioctls = DRM_OMAP_NUM_IOCTLS, |
| 534 | .fops = &omapdriver_fops, |
| 535 | .name = DRIVER_NAME, |
| 536 | .desc = DRIVER_DESC, |
| 537 | .date = DRIVER_DATE, |
| 538 | .major = DRIVER_MAJOR, |
| 539 | .minor = DRIVER_MINOR, |
| 540 | .patchlevel = DRIVER_PATCHLEVEL, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 541 | }; |
| 542 | |
Laurent Pinchart | 6e471fa | 2017-05-06 02:57:12 +0300 | [diff] [blame] | 543 | static const struct soc_device_attribute omapdrm_soc_devices[] = { |
| 544 | { .family = "OMAP3", .data = (void *)0x3430 }, |
| 545 | { .family = "OMAP4", .data = (void *)0x4430 }, |
| 546 | { .family = "OMAP5", .data = (void *)0x5430 }, |
| 547 | { .family = "DRA7", .data = (void *)0x0752 }, |
| 548 | { /* sentinel */ } |
| 549 | }; |
| 550 | |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 551 | static int omapdrm_init(struct omap_drm_private *priv, struct device *dev) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 552 | { |
Laurent Pinchart | 6e471fa | 2017-05-06 02:57:12 +0300 | [diff] [blame] | 553 | const struct soc_device_attribute *soc; |
Sebastian Reichel | 8510148 | 2020-12-15 12:46:11 +0200 | [diff] [blame] | 554 | struct dss_pdata *pdata = dev->platform_data; |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 555 | struct drm_device *ddev; |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 556 | int ret; |
| 557 | |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 558 | DBG("%s", dev_name(dev)); |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 559 | |
Peter Ujfalusi | fb96b67 | 2018-02-12 11:44:36 +0200 | [diff] [blame] | 560 | /* Allocate and initialize the DRM device. */ |
| 561 | ddev = drm_dev_alloc(&omap_drm_driver, dev); |
| 562 | if (IS_ERR(ddev)) |
| 563 | return PTR_ERR(ddev); |
| 564 | |
| 565 | priv->ddev = ddev; |
| 566 | ddev->dev_private = priv; |
| 567 | |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 568 | priv->dev = dev; |
Sebastian Reichel | 8510148 | 2020-12-15 12:46:11 +0200 | [diff] [blame] | 569 | priv->dss = pdata->dss; |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 570 | priv->dispc = dispc_get_dispc(priv->dss); |
Laurent Pinchart | 510c74c | 2017-08-11 16:49:08 +0300 | [diff] [blame] | 571 | |
Tomi Valkeinen | 05ec612 | 2020-12-15 12:46:27 +0200 | [diff] [blame] | 572 | priv->dss->mgr_ops_priv = priv; |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 573 | |
Laurent Pinchart | 6e471fa | 2017-05-06 02:57:12 +0300 | [diff] [blame] | 574 | soc = soc_device_match(omapdrm_soc_devices); |
| 575 | priv->omaprev = soc ? (unsigned int)soc->data : 0; |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 576 | priv->wq = alloc_ordered_workqueue("omapdrm", 0); |
| 577 | |
Daniel Vetter | 5117bd8 | 2018-05-25 19:39:24 +0300 | [diff] [blame] | 578 | mutex_init(&priv->list_lock); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 579 | INIT_LIST_HEAD(&priv->obj_list); |
| 580 | |
Peter Ujfalusi | a7631c4 | 2017-11-30 14:12:37 +0200 | [diff] [blame] | 581 | /* Get memory bandwidth limits */ |
Tomi Valkeinen | dac62bc | 2020-12-15 12:46:26 +0200 | [diff] [blame] | 582 | priv->max_bandwidth = dispc_get_memory_bandwidth_limit(priv->dispc); |
Peter Ujfalusi | a7631c4 | 2017-11-30 14:12:37 +0200 | [diff] [blame] | 583 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 584 | omap_gem_init(ddev); |
| 585 | |
| 586 | ret = omap_modeset_init(ddev); |
| 587 | if (ret) { |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 588 | dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret); |
Peter Ujfalusi | fb96b67 | 2018-02-12 11:44:36 +0200 | [diff] [blame] | 589 | goto err_gem_deinit; |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | /* Initialize vblank handling, start with all CRTCs disabled. */ |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 593 | ret = drm_vblank_init(ddev, priv->num_pipes); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 594 | if (ret) { |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 595 | dev_err(priv->dev, "could not init vblank\n"); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 596 | goto err_cleanup_modeset; |
| 597 | } |
| 598 | |
Tomi Valkeinen | efd1f06 | 2018-02-09 09:36:23 +0200 | [diff] [blame] | 599 | omap_fbdev_init(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 600 | |
| 601 | drm_kms_helper_poll_init(ddev); |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 602 | omap_modeset_enable_external_hpd(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 603 | |
| 604 | /* |
| 605 | * Register the DRM device with the core and the connectors with |
| 606 | * sysfs. |
| 607 | */ |
| 608 | ret = drm_dev_register(ddev, 0); |
| 609 | if (ret) |
| 610 | goto err_cleanup_helpers; |
| 611 | |
| 612 | return 0; |
| 613 | |
| 614 | err_cleanup_helpers: |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 615 | omap_modeset_disable_external_hpd(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 616 | drm_kms_helper_poll_fini(ddev); |
Tomi Valkeinen | efd1f06 | 2018-02-09 09:36:23 +0200 | [diff] [blame] | 617 | |
| 618 | omap_fbdev_fini(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 619 | err_cleanup_modeset: |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 620 | omap_modeset_fini(ddev); |
Peter Ujfalusi | fb96b67 | 2018-02-12 11:44:36 +0200 | [diff] [blame] | 621 | err_gem_deinit: |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 622 | omap_gem_deinit(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 623 | destroy_workqueue(priv->wq); |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 624 | omap_disconnect_pipelines(ddev); |
Thomas Zimmermann | 08bafff | 2018-06-18 15:07:27 +0200 | [diff] [blame] | 625 | drm_dev_put(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 626 | return ret; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 627 | } |
| 628 | |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 629 | static void omapdrm_cleanup(struct omap_drm_private *priv) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 630 | { |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 631 | struct drm_device *ddev = priv->ddev; |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 632 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 633 | DBG(""); |
Andy Gross | 5c13779 | 2012-03-05 10:48:39 -0600 | [diff] [blame] | 634 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 635 | drm_dev_unregister(ddev); |
| 636 | |
Peter Ujfalusi | 52b9ef2 | 2018-02-12 11:44:37 +0200 | [diff] [blame] | 637 | omap_modeset_disable_external_hpd(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 638 | drm_kms_helper_poll_fini(ddev); |
| 639 | |
Tomi Valkeinen | efd1f06 | 2018-02-09 09:36:23 +0200 | [diff] [blame] | 640 | omap_fbdev_fini(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 641 | |
Tomi Valkeinen | 8a54aa9 | 2017-03-27 10:02:22 +0300 | [diff] [blame] | 642 | drm_atomic_helper_shutdown(ddev); |
| 643 | |
Laurent Pinchart | f40f4e4 | 2020-02-26 13:24:58 +0200 | [diff] [blame] | 644 | omap_modeset_fini(ddev); |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 645 | omap_gem_deinit(ddev); |
| 646 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 647 | destroy_workqueue(priv->wq); |
Tomi Valkeinen | 707cf58 | 2014-04-02 13:47:43 +0300 | [diff] [blame] | 648 | |
Laurent Pinchart | 2ee7679 | 2018-03-05 15:02:22 +0200 | [diff] [blame] | 649 | omap_disconnect_pipelines(ddev); |
Peter Ujfalusi | fb96b67 | 2018-02-12 11:44:36 +0200 | [diff] [blame] | 650 | |
Thomas Zimmermann | 08bafff | 2018-06-18 15:07:27 +0200 | [diff] [blame] | 651 | drm_dev_put(ddev); |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | static int pdev_probe(struct platform_device *pdev) |
| 655 | { |
| 656 | struct omap_drm_private *priv; |
| 657 | int ret; |
| 658 | |
Tomi Valkeinen | 63daf4e | 2019-08-09 13:00:38 +0300 | [diff] [blame] | 659 | ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 660 | if (ret) { |
| 661 | dev_err(&pdev->dev, "Failed to set the DMA mask\n"); |
| 662 | return ret; |
| 663 | } |
| 664 | |
| 665 | /* Allocate and initialize the driver private structure. */ |
| 666 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 667 | if (!priv) |
| 668 | return -ENOMEM; |
| 669 | |
| 670 | platform_set_drvdata(pdev, priv); |
| 671 | |
| 672 | ret = omapdrm_init(priv, &pdev->dev); |
| 673 | if (ret < 0) |
| 674 | kfree(priv); |
| 675 | |
| 676 | return ret; |
| 677 | } |
| 678 | |
| 679 | static int pdev_remove(struct platform_device *pdev) |
| 680 | { |
| 681 | struct omap_drm_private *priv = platform_get_drvdata(pdev); |
| 682 | |
| 683 | omapdrm_cleanup(priv); |
| 684 | kfree(priv); |
Daniel Vetter | fd3c025 | 2013-12-11 11:34:26 +0100 | [diff] [blame] | 685 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 686 | return 0; |
| 687 | } |
| 688 | |
Grygorii Strashko | 8450c8d | 2015-02-26 15:57:17 +0200 | [diff] [blame] | 689 | #ifdef CONFIG_PM_SLEEP |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 690 | static int omap_drm_suspend(struct device *dev) |
| 691 | { |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 692 | struct omap_drm_private *priv = dev_get_drvdata(dev); |
| 693 | struct drm_device *drm_dev = priv->ddev; |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 694 | |
Laurent Pinchart | d2c5316 | 2018-09-04 17:08:33 +0300 | [diff] [blame] | 695 | return drm_mode_config_helper_suspend(drm_dev); |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | static int omap_drm_resume(struct device *dev) |
| 699 | { |
Laurent Pinchart | a82f0347 | 2018-02-13 14:00:19 +0200 | [diff] [blame] | 700 | struct omap_drm_private *priv = dev_get_drvdata(dev); |
| 701 | struct drm_device *drm_dev = priv->ddev; |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 702 | |
Laurent Pinchart | d2c5316 | 2018-09-04 17:08:33 +0300 | [diff] [blame] | 703 | drm_mode_config_helper_resume(drm_dev); |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 704 | |
Laurent Pinchart | 7fb15c4 | 2017-10-13 17:58:58 +0300 | [diff] [blame] | 705 | return omap_gem_resume(drm_dev); |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 706 | } |
Andy Gross | e78edba | 2012-12-19 14:53:37 -0600 | [diff] [blame] | 707 | #endif |
| 708 | |
Grygorii Strashko | 8450c8d | 2015-02-26 15:57:17 +0200 | [diff] [blame] | 709 | static SIMPLE_DEV_PM_OPS(omapdrm_pm_ops, omap_drm_suspend, omap_drm_resume); |
| 710 | |
Tomi Valkeinen | 6717cd2 | 2013-04-10 10:44:00 +0300 | [diff] [blame] | 711 | static struct platform_driver pdev = { |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 712 | .driver = { |
Tomi Valkeinen | f64eafa | 2017-08-16 12:43:55 +0300 | [diff] [blame] | 713 | .name = "omapdrm", |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 714 | .pm = &omapdrm_pm_ops, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 715 | }, |
| 716 | .probe = pdev_probe, |
| 717 | .remove = pdev_remove, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 718 | }; |
| 719 | |
Thierry Reding | e1c49bd | 2015-12-02 17:23:31 +0100 | [diff] [blame] | 720 | static struct platform_driver * const drivers[] = { |
| 721 | &omap_dmm_driver, |
| 722 | &pdev, |
| 723 | }; |
| 724 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 725 | static int __init omap_drm_init(void) |
| 726 | { |
Tomi Valkeinen | 55b68fb | 2020-12-15 12:46:23 +0200 | [diff] [blame] | 727 | int r; |
| 728 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 729 | DBG("init"); |
Tomi Valkeinen | ea7e3a6 | 2014-04-02 14:31:50 +0300 | [diff] [blame] | 730 | |
Tomi Valkeinen | 55b68fb | 2020-12-15 12:46:23 +0200 | [diff] [blame] | 731 | r = omap_dss_init(); |
| 732 | if (r) |
| 733 | return r; |
| 734 | |
| 735 | r = platform_register_drivers(drivers, ARRAY_SIZE(drivers)); |
| 736 | if (r) { |
| 737 | omap_dss_exit(); |
| 738 | return r; |
| 739 | } |
| 740 | |
| 741 | return 0; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | static void __exit omap_drm_fini(void) |
| 745 | { |
| 746 | DBG("fini"); |
Tomi Valkeinen | ea7e3a6 | 2014-04-02 14:31:50 +0300 | [diff] [blame] | 747 | |
Thierry Reding | e1c49bd | 2015-12-02 17:23:31 +0100 | [diff] [blame] | 748 | platform_unregister_drivers(drivers, ARRAY_SIZE(drivers)); |
Tomi Valkeinen | 55b68fb | 2020-12-15 12:46:23 +0200 | [diff] [blame] | 749 | |
| 750 | omap_dss_exit(); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 751 | } |
| 752 | |
Tomi Valkeinen | 55b68fb | 2020-12-15 12:46:23 +0200 | [diff] [blame] | 753 | module_init(omap_drm_init); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 754 | module_exit(omap_drm_fini); |
| 755 | |
| 756 | MODULE_AUTHOR("Rob Clark <rob@ti.com>"); |
Tomi Valkeinen | 55b68fb | 2020-12-15 12:46:23 +0200 | [diff] [blame] | 757 | MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>"); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 758 | MODULE_DESCRIPTION("OMAP DRM Display Driver"); |
| 759 | MODULE_ALIAS("platform:" DRIVER_NAME); |
| 760 | MODULE_LICENSE("GPL v2"); |