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