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