| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ |
|---|
| 3 | 4 | * 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 | 5 | */ |
|---|
| 17 | 6 | |
|---|
| 7 | +#include <linux/dma-mapping.h> |
|---|
| 8 | +#include <linux/platform_device.h> |
|---|
| 9 | +#include <linux/sort.h> |
|---|
| 18 | 10 | #include <linux/sys_soc.h> |
|---|
| 19 | 11 | |
|---|
| 20 | 12 | #include <drm/drm_atomic.h> |
|---|
| 21 | 13 | #include <drm/drm_atomic_helper.h> |
|---|
| 22 | | -#include <drm/drm_crtc_helper.h> |
|---|
| 14 | +#include <drm/drm_bridge.h> |
|---|
| 15 | +#include <drm/drm_bridge_connector.h> |
|---|
| 16 | +#include <drm/drm_drv.h> |
|---|
| 23 | 17 | #include <drm/drm_fb_helper.h> |
|---|
| 18 | +#include <drm/drm_file.h> |
|---|
| 19 | +#include <drm/drm_ioctl.h> |
|---|
| 20 | +#include <drm/drm_panel.h> |
|---|
| 21 | +#include <drm/drm_prime.h> |
|---|
| 22 | +#include <drm/drm_probe_helper.h> |
|---|
| 23 | +#include <drm/drm_vblank.h> |
|---|
| 24 | 24 | |
|---|
| 25 | 25 | #include "omap_dmm_tiler.h" |
|---|
| 26 | 26 | #include "omap_drv.h" |
|---|
| .. | .. |
|---|
| 127 | 127 | .atomic_commit = drm_atomic_helper_commit, |
|---|
| 128 | 128 | }; |
|---|
| 129 | 129 | |
|---|
| 130 | | -static int get_connector_type(struct omap_dss_device *dssdev) |
|---|
| 130 | +static void omap_disconnect_pipelines(struct drm_device *ddev) |
|---|
| 131 | 131 | { |
|---|
| 132 | | - switch (dssdev->type) { |
|---|
| 133 | | - case OMAP_DISPLAY_TYPE_HDMI: |
|---|
| 134 | | - return DRM_MODE_CONNECTOR_HDMIA; |
|---|
| 135 | | - case OMAP_DISPLAY_TYPE_DVI: |
|---|
| 136 | | - return DRM_MODE_CONNECTOR_DVID; |
|---|
| 137 | | - case OMAP_DISPLAY_TYPE_DSI: |
|---|
| 138 | | - return DRM_MODE_CONNECTOR_DSI; |
|---|
| 139 | | - case OMAP_DISPLAY_TYPE_DPI: |
|---|
| 140 | | - case OMAP_DISPLAY_TYPE_DBI: |
|---|
| 141 | | - return DRM_MODE_CONNECTOR_DPI; |
|---|
| 142 | | - case OMAP_DISPLAY_TYPE_VENC: |
|---|
| 143 | | - /* TODO: This could also be composite */ |
|---|
| 144 | | - return DRM_MODE_CONNECTOR_SVIDEO; |
|---|
| 145 | | - case OMAP_DISPLAY_TYPE_SDI: |
|---|
| 146 | | - return DRM_MODE_CONNECTOR_LVDS; |
|---|
| 147 | | - default: |
|---|
| 148 | | - return DRM_MODE_CONNECTOR_Unknown; |
|---|
| 132 | + struct omap_drm_private *priv = ddev->dev_private; |
|---|
| 133 | + unsigned int i; |
|---|
| 134 | + |
|---|
| 135 | + for (i = 0; i < priv->num_pipes; i++) { |
|---|
| 136 | + struct omap_drm_pipeline *pipe = &priv->pipes[i]; |
|---|
| 137 | + |
|---|
| 138 | + omapdss_device_disconnect(NULL, pipe->output); |
|---|
| 139 | + |
|---|
| 140 | + omapdss_device_put(pipe->output); |
|---|
| 141 | + pipe->output = NULL; |
|---|
| 149 | 142 | } |
|---|
| 143 | + |
|---|
| 144 | + memset(&priv->channels, 0, sizeof(priv->channels)); |
|---|
| 145 | + |
|---|
| 146 | + priv->num_pipes = 0; |
|---|
| 150 | 147 | } |
|---|
| 151 | 148 | |
|---|
| 152 | | -static void omap_disconnect_dssdevs(void) |
|---|
| 149 | +static int omap_connect_pipelines(struct drm_device *ddev) |
|---|
| 153 | 150 | { |
|---|
| 154 | | - struct omap_dss_device *dssdev = NULL; |
|---|
| 155 | | - |
|---|
| 156 | | - for_each_dss_dev(dssdev) |
|---|
| 157 | | - dssdev->driver->disconnect(dssdev); |
|---|
| 158 | | -} |
|---|
| 159 | | - |
|---|
| 160 | | -static int omap_connect_dssdevs(void) |
|---|
| 161 | | -{ |
|---|
| 151 | + struct omap_drm_private *priv = ddev->dev_private; |
|---|
| 152 | + struct omap_dss_device *output = NULL; |
|---|
| 162 | 153 | int r; |
|---|
| 163 | | - struct omap_dss_device *dssdev = NULL; |
|---|
| 164 | 154 | |
|---|
| 165 | | - if (!omapdss_stack_is_ready()) |
|---|
| 166 | | - return -EPROBE_DEFER; |
|---|
| 167 | | - |
|---|
| 168 | | - for_each_dss_dev(dssdev) { |
|---|
| 169 | | - r = dssdev->driver->connect(dssdev); |
|---|
| 155 | + for_each_dss_output(output) { |
|---|
| 156 | + r = omapdss_device_connect(priv->dss, NULL, output); |
|---|
| 170 | 157 | if (r == -EPROBE_DEFER) { |
|---|
| 171 | | - omap_dss_put_device(dssdev); |
|---|
| 172 | | - goto cleanup; |
|---|
| 158 | + omapdss_device_put(output); |
|---|
| 159 | + return r; |
|---|
| 173 | 160 | } else if (r) { |
|---|
| 174 | | - dev_warn(dssdev->dev, "could not connect display: %s\n", |
|---|
| 175 | | - dssdev->name); |
|---|
| 161 | + dev_warn(output->dev, "could not connect output %s\n", |
|---|
| 162 | + output->name); |
|---|
| 163 | + } else { |
|---|
| 164 | + struct omap_drm_pipeline *pipe; |
|---|
| 165 | + |
|---|
| 166 | + pipe = &priv->pipes[priv->num_pipes++]; |
|---|
| 167 | + pipe->output = omapdss_device_get(output); |
|---|
| 168 | + |
|---|
| 169 | + if (priv->num_pipes == ARRAY_SIZE(priv->pipes)) { |
|---|
| 170 | + /* To balance the 'for_each_dss_output' loop */ |
|---|
| 171 | + omapdss_device_put(output); |
|---|
| 172 | + break; |
|---|
| 173 | + } |
|---|
| 176 | 174 | } |
|---|
| 177 | 175 | } |
|---|
| 178 | 176 | |
|---|
| 179 | 177 | return 0; |
|---|
| 178 | +} |
|---|
| 180 | 179 | |
|---|
| 181 | | -cleanup: |
|---|
| 182 | | - /* |
|---|
| 183 | | - * if we are deferring probe, we disconnect the devices we previously |
|---|
| 184 | | - * connected |
|---|
| 185 | | - */ |
|---|
| 186 | | - omap_disconnect_dssdevs(); |
|---|
| 180 | +static int omap_compare_pipelines(const void *a, const void *b) |
|---|
| 181 | +{ |
|---|
| 182 | + const struct omap_drm_pipeline *pipe1 = a; |
|---|
| 183 | + const struct omap_drm_pipeline *pipe2 = b; |
|---|
| 187 | 184 | |
|---|
| 188 | | - return r; |
|---|
| 185 | + if (pipe1->alias_id > pipe2->alias_id) |
|---|
| 186 | + return 1; |
|---|
| 187 | + else if (pipe1->alias_id < pipe2->alias_id) |
|---|
| 188 | + return -1; |
|---|
| 189 | + return 0; |
|---|
| 189 | 190 | } |
|---|
| 190 | 191 | |
|---|
| 191 | 192 | static int omap_modeset_init_properties(struct drm_device *dev) |
|---|
| .. | .. |
|---|
| 201 | 202 | return 0; |
|---|
| 202 | 203 | } |
|---|
| 203 | 204 | |
|---|
| 205 | +static int omap_display_id(struct omap_dss_device *output) |
|---|
| 206 | +{ |
|---|
| 207 | + struct device_node *node = NULL; |
|---|
| 208 | + |
|---|
| 209 | + if (output->next) { |
|---|
| 210 | + struct omap_dss_device *display = output; |
|---|
| 211 | + |
|---|
| 212 | + while (display->next) |
|---|
| 213 | + display = display->next; |
|---|
| 214 | + |
|---|
| 215 | + node = display->dev->of_node; |
|---|
| 216 | + } else if (output->bridge) { |
|---|
| 217 | + struct drm_bridge *bridge = output->bridge; |
|---|
| 218 | + |
|---|
| 219 | + while (drm_bridge_get_next_bridge(bridge)) |
|---|
| 220 | + bridge = drm_bridge_get_next_bridge(bridge); |
|---|
| 221 | + |
|---|
| 222 | + node = bridge->of_node; |
|---|
| 223 | + } |
|---|
| 224 | + |
|---|
| 225 | + return node ? of_alias_get_id(node, "display") : -ENODEV; |
|---|
| 226 | +} |
|---|
| 227 | + |
|---|
| 204 | 228 | static int omap_modeset_init(struct drm_device *dev) |
|---|
| 205 | 229 | { |
|---|
| 206 | 230 | struct omap_drm_private *priv = dev->dev_private; |
|---|
| 207 | | - struct omap_dss_device *dssdev = NULL; |
|---|
| 208 | 231 | int num_ovls = priv->dispc_ops->get_num_ovls(priv->dispc); |
|---|
| 209 | 232 | int num_mgrs = priv->dispc_ops->get_num_mgrs(priv->dispc); |
|---|
| 210 | | - int num_crtcs, crtc_idx, plane_idx; |
|---|
| 233 | + unsigned int i; |
|---|
| 211 | 234 | int ret; |
|---|
| 212 | 235 | u32 plane_crtc_mask; |
|---|
| 236 | + |
|---|
| 237 | + if (!omapdss_stack_is_ready()) |
|---|
| 238 | + return -EPROBE_DEFER; |
|---|
| 213 | 239 | |
|---|
| 214 | 240 | drm_mode_config_init(dev); |
|---|
| 215 | 241 | |
|---|
| .. | .. |
|---|
| 225 | 251 | * configuration does not match the expectations or exceeds |
|---|
| 226 | 252 | * the available resources, the configuration is rejected. |
|---|
| 227 | 253 | */ |
|---|
| 228 | | - num_crtcs = 0; |
|---|
| 229 | | - for_each_dss_dev(dssdev) |
|---|
| 230 | | - if (omapdss_device_is_connected(dssdev)) |
|---|
| 231 | | - num_crtcs++; |
|---|
| 254 | + ret = omap_connect_pipelines(dev); |
|---|
| 255 | + if (ret < 0) |
|---|
| 256 | + return ret; |
|---|
| 232 | 257 | |
|---|
| 233 | | - if (num_crtcs > num_mgrs || num_crtcs > num_ovls || |
|---|
| 234 | | - num_crtcs > ARRAY_SIZE(priv->crtcs) || |
|---|
| 235 | | - num_crtcs > ARRAY_SIZE(priv->planes) || |
|---|
| 236 | | - num_crtcs > ARRAY_SIZE(priv->encoders) || |
|---|
| 237 | | - num_crtcs > ARRAY_SIZE(priv->connectors)) { |
|---|
| 258 | + if (priv->num_pipes > num_mgrs || priv->num_pipes > num_ovls) { |
|---|
| 238 | 259 | dev_err(dev->dev, "%s(): Too many connected displays\n", |
|---|
| 239 | 260 | __func__); |
|---|
| 240 | 261 | return -EINVAL; |
|---|
| 241 | 262 | } |
|---|
| 242 | 263 | |
|---|
| 243 | | - /* All planes can be put to any CRTC */ |
|---|
| 244 | | - plane_crtc_mask = (1 << num_crtcs) - 1; |
|---|
| 264 | + /* Create all planes first. They can all be put to any CRTC. */ |
|---|
| 265 | + plane_crtc_mask = (1 << priv->num_pipes) - 1; |
|---|
| 245 | 266 | |
|---|
| 246 | | - dssdev = NULL; |
|---|
| 247 | | - |
|---|
| 248 | | - crtc_idx = 0; |
|---|
| 249 | | - plane_idx = 0; |
|---|
| 250 | | - for_each_dss_dev(dssdev) { |
|---|
| 251 | | - struct drm_connector *connector; |
|---|
| 252 | | - struct drm_encoder *encoder; |
|---|
| 253 | | - struct drm_plane *plane; |
|---|
| 254 | | - struct drm_crtc *crtc; |
|---|
| 255 | | - |
|---|
| 256 | | - if (!omapdss_device_is_connected(dssdev)) |
|---|
| 257 | | - continue; |
|---|
| 258 | | - |
|---|
| 259 | | - encoder = omap_encoder_init(dev, dssdev); |
|---|
| 260 | | - if (!encoder) |
|---|
| 261 | | - return -ENOMEM; |
|---|
| 262 | | - |
|---|
| 263 | | - connector = omap_connector_init(dev, |
|---|
| 264 | | - get_connector_type(dssdev), dssdev, encoder); |
|---|
| 265 | | - if (!connector) |
|---|
| 266 | | - return -ENOMEM; |
|---|
| 267 | | - |
|---|
| 268 | | - plane = omap_plane_init(dev, plane_idx, DRM_PLANE_TYPE_PRIMARY, |
|---|
| 269 | | - plane_crtc_mask); |
|---|
| 270 | | - if (IS_ERR(plane)) |
|---|
| 271 | | - return PTR_ERR(plane); |
|---|
| 272 | | - |
|---|
| 273 | | - crtc = omap_crtc_init(dev, plane, dssdev); |
|---|
| 274 | | - if (IS_ERR(crtc)) |
|---|
| 275 | | - return PTR_ERR(crtc); |
|---|
| 276 | | - |
|---|
| 277 | | - drm_connector_attach_encoder(connector, encoder); |
|---|
| 278 | | - encoder->possible_crtcs = (1 << crtc_idx); |
|---|
| 279 | | - |
|---|
| 280 | | - priv->crtcs[priv->num_crtcs++] = crtc; |
|---|
| 281 | | - priv->planes[priv->num_planes++] = plane; |
|---|
| 282 | | - priv->encoders[priv->num_encoders++] = encoder; |
|---|
| 283 | | - priv->connectors[priv->num_connectors++] = connector; |
|---|
| 284 | | - |
|---|
| 285 | | - plane_idx++; |
|---|
| 286 | | - crtc_idx++; |
|---|
| 287 | | - } |
|---|
| 288 | | - |
|---|
| 289 | | - /* |
|---|
| 290 | | - * Create normal planes for the remaining overlays: |
|---|
| 291 | | - */ |
|---|
| 292 | | - for (; plane_idx < num_ovls; plane_idx++) { |
|---|
| 267 | + for (i = 0; i < num_ovls; i++) { |
|---|
| 268 | + enum drm_plane_type type = i < priv->num_pipes |
|---|
| 269 | + ? DRM_PLANE_TYPE_PRIMARY |
|---|
| 270 | + : DRM_PLANE_TYPE_OVERLAY; |
|---|
| 293 | 271 | struct drm_plane *plane; |
|---|
| 294 | 272 | |
|---|
| 295 | 273 | if (WARN_ON(priv->num_planes >= ARRAY_SIZE(priv->planes))) |
|---|
| 296 | 274 | return -EINVAL; |
|---|
| 297 | 275 | |
|---|
| 298 | | - plane = omap_plane_init(dev, plane_idx, DRM_PLANE_TYPE_OVERLAY, |
|---|
| 299 | | - plane_crtc_mask); |
|---|
| 276 | + plane = omap_plane_init(dev, i, type, plane_crtc_mask); |
|---|
| 300 | 277 | if (IS_ERR(plane)) |
|---|
| 301 | 278 | return PTR_ERR(plane); |
|---|
| 302 | 279 | |
|---|
| 303 | 280 | priv->planes[priv->num_planes++] = plane; |
|---|
| 304 | 281 | } |
|---|
| 305 | 282 | |
|---|
| 306 | | - DBG("registered %d planes, %d crtcs, %d encoders and %d connectors\n", |
|---|
| 307 | | - priv->num_planes, priv->num_crtcs, priv->num_encoders, |
|---|
| 308 | | - priv->num_connectors); |
|---|
| 283 | + /* |
|---|
| 284 | + * Create the encoders, attach the bridges and get the pipeline alias |
|---|
| 285 | + * IDs. |
|---|
| 286 | + */ |
|---|
| 287 | + for (i = 0; i < priv->num_pipes; i++) { |
|---|
| 288 | + struct omap_drm_pipeline *pipe = &priv->pipes[i]; |
|---|
| 289 | + int id; |
|---|
| 290 | + |
|---|
| 291 | + pipe->encoder = omap_encoder_init(dev, pipe->output); |
|---|
| 292 | + if (!pipe->encoder) |
|---|
| 293 | + return -ENOMEM; |
|---|
| 294 | + |
|---|
| 295 | + if (pipe->output->bridge) { |
|---|
| 296 | + ret = drm_bridge_attach(pipe->encoder, |
|---|
| 297 | + pipe->output->bridge, NULL, |
|---|
| 298 | + DRM_BRIDGE_ATTACH_NO_CONNECTOR); |
|---|
| 299 | + if (ret < 0) { |
|---|
| 300 | + dev_err(priv->dev, |
|---|
| 301 | + "unable to attach bridge %pOF\n", |
|---|
| 302 | + pipe->output->bridge->of_node); |
|---|
| 303 | + return ret; |
|---|
| 304 | + } |
|---|
| 305 | + } |
|---|
| 306 | + |
|---|
| 307 | + id = omap_display_id(pipe->output); |
|---|
| 308 | + pipe->alias_id = id >= 0 ? id : i; |
|---|
| 309 | + } |
|---|
| 310 | + |
|---|
| 311 | + /* Sort the pipelines by DT aliases. */ |
|---|
| 312 | + sort(priv->pipes, priv->num_pipes, sizeof(priv->pipes[0]), |
|---|
| 313 | + omap_compare_pipelines, NULL); |
|---|
| 314 | + |
|---|
| 315 | + /* |
|---|
| 316 | + * Populate the pipeline lookup table by DISPC channel. Only one display |
|---|
| 317 | + * is allowed per channel. |
|---|
| 318 | + */ |
|---|
| 319 | + for (i = 0; i < priv->num_pipes; ++i) { |
|---|
| 320 | + struct omap_drm_pipeline *pipe = &priv->pipes[i]; |
|---|
| 321 | + enum omap_channel channel = pipe->output->dispc_channel; |
|---|
| 322 | + |
|---|
| 323 | + if (WARN_ON(priv->channels[channel] != NULL)) |
|---|
| 324 | + return -EINVAL; |
|---|
| 325 | + |
|---|
| 326 | + priv->channels[channel] = pipe; |
|---|
| 327 | + } |
|---|
| 328 | + |
|---|
| 329 | + /* Create the connectors and CRTCs. */ |
|---|
| 330 | + for (i = 0; i < priv->num_pipes; i++) { |
|---|
| 331 | + struct omap_drm_pipeline *pipe = &priv->pipes[i]; |
|---|
| 332 | + struct drm_encoder *encoder = pipe->encoder; |
|---|
| 333 | + struct drm_crtc *crtc; |
|---|
| 334 | + |
|---|
| 335 | + if (pipe->output->next) { |
|---|
| 336 | + pipe->connector = omap_connector_init(dev, pipe->output, |
|---|
| 337 | + encoder); |
|---|
| 338 | + if (!pipe->connector) |
|---|
| 339 | + return -ENOMEM; |
|---|
| 340 | + } else { |
|---|
| 341 | + pipe->connector = drm_bridge_connector_init(dev, encoder); |
|---|
| 342 | + if (IS_ERR(pipe->connector)) { |
|---|
| 343 | + dev_err(priv->dev, |
|---|
| 344 | + "unable to create bridge connector for %s\n", |
|---|
| 345 | + pipe->output->name); |
|---|
| 346 | + return PTR_ERR(pipe->connector); |
|---|
| 347 | + } |
|---|
| 348 | + } |
|---|
| 349 | + |
|---|
| 350 | + drm_connector_attach_encoder(pipe->connector, encoder); |
|---|
| 351 | + |
|---|
| 352 | + crtc = omap_crtc_init(dev, pipe, priv->planes[i]); |
|---|
| 353 | + if (IS_ERR(crtc)) |
|---|
| 354 | + return PTR_ERR(crtc); |
|---|
| 355 | + |
|---|
| 356 | + encoder->possible_crtcs = 1 << i; |
|---|
| 357 | + pipe->crtc = crtc; |
|---|
| 358 | + } |
|---|
| 359 | + |
|---|
| 360 | + DBG("registered %u planes, %u crtcs/encoders/connectors\n", |
|---|
| 361 | + priv->num_planes, priv->num_pipes); |
|---|
| 309 | 362 | |
|---|
| 310 | 363 | dev->mode_config.min_width = 8; |
|---|
| 311 | 364 | dev->mode_config.min_height = 2; |
|---|
| .. | .. |
|---|
| 332 | 385 | return 0; |
|---|
| 333 | 386 | } |
|---|
| 334 | 387 | |
|---|
| 388 | +static void omap_modeset_fini(struct drm_device *ddev) |
|---|
| 389 | +{ |
|---|
| 390 | + omap_drm_irq_uninstall(ddev); |
|---|
| 391 | + |
|---|
| 392 | + drm_mode_config_cleanup(ddev); |
|---|
| 393 | +} |
|---|
| 394 | + |
|---|
| 335 | 395 | /* |
|---|
| 336 | 396 | * Enable the HPD in external components if supported |
|---|
| 337 | 397 | */ |
|---|
| 338 | | -static void omap_modeset_enable_external_hpd(void) |
|---|
| 398 | +static void omap_modeset_enable_external_hpd(struct drm_device *ddev) |
|---|
| 339 | 399 | { |
|---|
| 340 | | - struct omap_dss_device *dssdev = NULL; |
|---|
| 400 | + struct omap_drm_private *priv = ddev->dev_private; |
|---|
| 401 | + unsigned int i; |
|---|
| 341 | 402 | |
|---|
| 342 | | - for_each_dss_dev(dssdev) { |
|---|
| 343 | | - if (dssdev->driver->enable_hpd) |
|---|
| 344 | | - dssdev->driver->enable_hpd(dssdev); |
|---|
| 403 | + for (i = 0; i < priv->num_pipes; i++) { |
|---|
| 404 | + struct drm_connector *connector = priv->pipes[i].connector; |
|---|
| 405 | + |
|---|
| 406 | + if (!connector) |
|---|
| 407 | + continue; |
|---|
| 408 | + |
|---|
| 409 | + if (priv->pipes[i].output->bridge) |
|---|
| 410 | + drm_bridge_connector_enable_hpd(connector); |
|---|
| 345 | 411 | } |
|---|
| 346 | 412 | } |
|---|
| 347 | 413 | |
|---|
| 348 | 414 | /* |
|---|
| 349 | 415 | * Disable the HPD in external components if supported |
|---|
| 350 | 416 | */ |
|---|
| 351 | | -static void omap_modeset_disable_external_hpd(void) |
|---|
| 417 | +static void omap_modeset_disable_external_hpd(struct drm_device *ddev) |
|---|
| 352 | 418 | { |
|---|
| 353 | | - struct omap_dss_device *dssdev = NULL; |
|---|
| 419 | + struct omap_drm_private *priv = ddev->dev_private; |
|---|
| 420 | + unsigned int i; |
|---|
| 354 | 421 | |
|---|
| 355 | | - for_each_dss_dev(dssdev) { |
|---|
| 356 | | - if (dssdev->driver->disable_hpd) |
|---|
| 357 | | - dssdev->driver->disable_hpd(dssdev); |
|---|
| 422 | + for (i = 0; i < priv->num_pipes; i++) { |
|---|
| 423 | + struct drm_connector *connector = priv->pipes[i].connector; |
|---|
| 424 | + |
|---|
| 425 | + if (!connector) |
|---|
| 426 | + continue; |
|---|
| 427 | + |
|---|
| 428 | + if (priv->pipes[i].output->bridge) |
|---|
| 429 | + drm_bridge_connector_disable_hpd(connector); |
|---|
| 358 | 430 | } |
|---|
| 359 | 431 | } |
|---|
| 360 | 432 | |
|---|
| .. | .. |
|---|
| 375 | 447 | case OMAP_PARAM_CHIPSET_ID: |
|---|
| 376 | 448 | args->value = priv->omaprev; |
|---|
| 377 | 449 | break; |
|---|
| 378 | | - default: |
|---|
| 379 | | - DBG("unknown parameter %lld", args->param); |
|---|
| 380 | | - return -EINVAL; |
|---|
| 381 | | - } |
|---|
| 382 | | - |
|---|
| 383 | | - return 0; |
|---|
| 384 | | -} |
|---|
| 385 | | - |
|---|
| 386 | | -static int ioctl_set_param(struct drm_device *dev, void *data, |
|---|
| 387 | | - struct drm_file *file_priv) |
|---|
| 388 | | -{ |
|---|
| 389 | | - struct drm_omap_param *args = data; |
|---|
| 390 | | - |
|---|
| 391 | | - switch (args->param) { |
|---|
| 392 | 450 | default: |
|---|
| 393 | 451 | DBG("unknown parameter %lld", args->param); |
|---|
| 394 | 452 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 428 | 486 | args->size = omap_gem_mmap_size(obj); |
|---|
| 429 | 487 | args->offset = omap_gem_mmap_offset(obj); |
|---|
| 430 | 488 | |
|---|
| 431 | | - drm_gem_object_unreference_unlocked(obj); |
|---|
| 489 | + drm_gem_object_put(obj); |
|---|
| 432 | 490 | |
|---|
| 433 | 491 | return ret; |
|---|
| 434 | 492 | } |
|---|
| 435 | 493 | |
|---|
| 436 | 494 | static const struct drm_ioctl_desc ioctls[DRM_COMMAND_END - DRM_COMMAND_BASE] = { |
|---|
| 437 | 495 | DRM_IOCTL_DEF_DRV(OMAP_GET_PARAM, ioctl_get_param, |
|---|
| 438 | | - DRM_AUTH | DRM_RENDER_ALLOW), |
|---|
| 439 | | - DRM_IOCTL_DEF_DRV(OMAP_SET_PARAM, ioctl_set_param, |
|---|
| 496 | + DRM_RENDER_ALLOW), |
|---|
| 497 | + DRM_IOCTL_DEF_DRV(OMAP_SET_PARAM, drm_invalid_op, |
|---|
| 440 | 498 | DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY), |
|---|
| 441 | 499 | DRM_IOCTL_DEF_DRV(OMAP_GEM_NEW, ioctl_gem_new, |
|---|
| 442 | | - DRM_AUTH | DRM_RENDER_ALLOW), |
|---|
| 500 | + DRM_RENDER_ALLOW), |
|---|
| 443 | 501 | /* Deprecated, to be removed. */ |
|---|
| 444 | 502 | DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_PREP, drm_noop, |
|---|
| 445 | | - DRM_AUTH | DRM_RENDER_ALLOW), |
|---|
| 503 | + DRM_RENDER_ALLOW), |
|---|
| 446 | 504 | /* Deprecated, to be removed. */ |
|---|
| 447 | 505 | DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_FINI, drm_noop, |
|---|
| 448 | | - DRM_AUTH | DRM_RENDER_ALLOW), |
|---|
| 506 | + DRM_RENDER_ALLOW), |
|---|
| 449 | 507 | DRM_IOCTL_DEF_DRV(OMAP_GEM_INFO, ioctl_gem_info, |
|---|
| 450 | | - DRM_AUTH | DRM_RENDER_ALLOW), |
|---|
| 508 | + DRM_RENDER_ALLOW), |
|---|
| 451 | 509 | }; |
|---|
| 452 | 510 | |
|---|
| 453 | 511 | /* |
|---|
| .. | .. |
|---|
| 482 | 540 | }; |
|---|
| 483 | 541 | |
|---|
| 484 | 542 | static struct drm_driver omap_drm_driver = { |
|---|
| 485 | | - .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME | |
|---|
| 543 | + .driver_features = DRIVER_MODESET | DRIVER_GEM | |
|---|
| 486 | 544 | DRIVER_ATOMIC | DRIVER_RENDER, |
|---|
| 487 | 545 | .open = dev_open, |
|---|
| 488 | 546 | .lastclose = drm_fb_helper_lastclose, |
|---|
| .. | .. |
|---|
| 520 | 578 | { |
|---|
| 521 | 579 | const struct soc_device_attribute *soc; |
|---|
| 522 | 580 | struct drm_device *ddev; |
|---|
| 523 | | - unsigned int i; |
|---|
| 524 | 581 | int ret; |
|---|
| 525 | 582 | |
|---|
| 526 | 583 | DBG("%s", dev_name(dev)); |
|---|
| 584 | + |
|---|
| 585 | + /* Allocate and initialize the DRM device. */ |
|---|
| 586 | + ddev = drm_dev_alloc(&omap_drm_driver, dev); |
|---|
| 587 | + if (IS_ERR(ddev)) |
|---|
| 588 | + return PTR_ERR(ddev); |
|---|
| 589 | + |
|---|
| 590 | + priv->ddev = ddev; |
|---|
| 591 | + ddev->dev_private = priv; |
|---|
| 527 | 592 | |
|---|
| 528 | 593 | priv->dev = dev; |
|---|
| 529 | 594 | priv->dss = omapdss_get_dss(); |
|---|
| .. | .. |
|---|
| 532 | 597 | |
|---|
| 533 | 598 | omap_crtc_pre_init(priv); |
|---|
| 534 | 599 | |
|---|
| 535 | | - ret = omap_connect_dssdevs(); |
|---|
| 536 | | - if (ret) |
|---|
| 537 | | - goto err_crtc_uninit; |
|---|
| 538 | | - |
|---|
| 539 | 600 | soc = soc_device_match(omapdrm_soc_devices); |
|---|
| 540 | 601 | priv->omaprev = soc ? (unsigned int)soc->data : 0; |
|---|
| 541 | 602 | priv->wq = alloc_ordered_workqueue("omapdrm", 0); |
|---|
| 542 | 603 | |
|---|
| 543 | 604 | mutex_init(&priv->list_lock); |
|---|
| 544 | 605 | INIT_LIST_HEAD(&priv->obj_list); |
|---|
| 545 | | - |
|---|
| 546 | | - /* Allocate and initialize the DRM device. */ |
|---|
| 547 | | - ddev = drm_dev_alloc(&omap_drm_driver, priv->dev); |
|---|
| 548 | | - if (IS_ERR(ddev)) { |
|---|
| 549 | | - ret = PTR_ERR(ddev); |
|---|
| 550 | | - goto err_destroy_wq; |
|---|
| 551 | | - } |
|---|
| 552 | | - |
|---|
| 553 | | - priv->ddev = ddev; |
|---|
| 554 | | - ddev->dev_private = priv; |
|---|
| 555 | 606 | |
|---|
| 556 | 607 | /* Get memory bandwidth limits */ |
|---|
| 557 | 608 | if (priv->dispc_ops->get_memory_bandwidth_limit) |
|---|
| .. | .. |
|---|
| 563 | 614 | ret = omap_modeset_init(ddev); |
|---|
| 564 | 615 | if (ret) { |
|---|
| 565 | 616 | dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret); |
|---|
| 566 | | - goto err_free_drm_dev; |
|---|
| 617 | + goto err_gem_deinit; |
|---|
| 567 | 618 | } |
|---|
| 568 | 619 | |
|---|
| 569 | 620 | /* Initialize vblank handling, start with all CRTCs disabled. */ |
|---|
| 570 | | - ret = drm_vblank_init(ddev, priv->num_crtcs); |
|---|
| 621 | + ret = drm_vblank_init(ddev, priv->num_pipes); |
|---|
| 571 | 622 | if (ret) { |
|---|
| 572 | 623 | dev_err(priv->dev, "could not init vblank\n"); |
|---|
| 573 | 624 | goto err_cleanup_modeset; |
|---|
| 574 | 625 | } |
|---|
| 575 | 626 | |
|---|
| 576 | | - for (i = 0; i < priv->num_crtcs; i++) |
|---|
| 577 | | - drm_crtc_vblank_off(priv->crtcs[i]); |
|---|
| 578 | | - |
|---|
| 579 | 627 | omap_fbdev_init(ddev); |
|---|
| 580 | 628 | |
|---|
| 581 | 629 | drm_kms_helper_poll_init(ddev); |
|---|
| 582 | | - omap_modeset_enable_external_hpd(); |
|---|
| 630 | + omap_modeset_enable_external_hpd(ddev); |
|---|
| 583 | 631 | |
|---|
| 584 | 632 | /* |
|---|
| 585 | 633 | * Register the DRM device with the core and the connectors with |
|---|
| .. | .. |
|---|
| 592 | 640 | return 0; |
|---|
| 593 | 641 | |
|---|
| 594 | 642 | err_cleanup_helpers: |
|---|
| 595 | | - omap_modeset_disable_external_hpd(); |
|---|
| 643 | + omap_modeset_disable_external_hpd(ddev); |
|---|
| 596 | 644 | drm_kms_helper_poll_fini(ddev); |
|---|
| 597 | 645 | |
|---|
| 598 | 646 | omap_fbdev_fini(ddev); |
|---|
| 599 | 647 | err_cleanup_modeset: |
|---|
| 600 | | - drm_mode_config_cleanup(ddev); |
|---|
| 601 | | - omap_drm_irq_uninstall(ddev); |
|---|
| 602 | | -err_free_drm_dev: |
|---|
| 648 | + omap_modeset_fini(ddev); |
|---|
| 649 | +err_gem_deinit: |
|---|
| 603 | 650 | omap_gem_deinit(ddev); |
|---|
| 604 | | - drm_dev_unref(ddev); |
|---|
| 605 | | -err_destroy_wq: |
|---|
| 606 | 651 | destroy_workqueue(priv->wq); |
|---|
| 607 | | - omap_disconnect_dssdevs(); |
|---|
| 608 | | -err_crtc_uninit: |
|---|
| 609 | | - omap_crtc_pre_uninit(); |
|---|
| 652 | + omap_disconnect_pipelines(ddev); |
|---|
| 653 | + omap_crtc_pre_uninit(priv); |
|---|
| 654 | + drm_dev_put(ddev); |
|---|
| 610 | 655 | return ret; |
|---|
| 611 | 656 | } |
|---|
| 612 | 657 | |
|---|
| .. | .. |
|---|
| 618 | 663 | |
|---|
| 619 | 664 | drm_dev_unregister(ddev); |
|---|
| 620 | 665 | |
|---|
| 621 | | - omap_modeset_disable_external_hpd(); |
|---|
| 666 | + omap_modeset_disable_external_hpd(ddev); |
|---|
| 622 | 667 | drm_kms_helper_poll_fini(ddev); |
|---|
| 623 | 668 | |
|---|
| 624 | 669 | omap_fbdev_fini(ddev); |
|---|
| 625 | 670 | |
|---|
| 626 | 671 | drm_atomic_helper_shutdown(ddev); |
|---|
| 627 | 672 | |
|---|
| 628 | | - drm_mode_config_cleanup(ddev); |
|---|
| 629 | | - |
|---|
| 630 | | - omap_drm_irq_uninstall(ddev); |
|---|
| 673 | + omap_modeset_fini(ddev); |
|---|
| 631 | 674 | omap_gem_deinit(ddev); |
|---|
| 632 | | - |
|---|
| 633 | | - drm_dev_unref(ddev); |
|---|
| 634 | 675 | |
|---|
| 635 | 676 | destroy_workqueue(priv->wq); |
|---|
| 636 | 677 | |
|---|
| 637 | | - omap_disconnect_dssdevs(); |
|---|
| 638 | | - omap_crtc_pre_uninit(); |
|---|
| 678 | + omap_disconnect_pipelines(ddev); |
|---|
| 679 | + omap_crtc_pre_uninit(priv); |
|---|
| 680 | + |
|---|
| 681 | + drm_dev_put(ddev); |
|---|
| 639 | 682 | } |
|---|
| 640 | 683 | |
|---|
| 641 | 684 | static int pdev_probe(struct platform_device *pdev) |
|---|
| .. | .. |
|---|
| 646 | 689 | if (omapdss_is_initialized() == false) |
|---|
| 647 | 690 | return -EPROBE_DEFER; |
|---|
| 648 | 691 | |
|---|
| 649 | | - ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); |
|---|
| 692 | + ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
|---|
| 650 | 693 | if (ret) { |
|---|
| 651 | 694 | dev_err(&pdev->dev, "Failed to set the DMA mask\n"); |
|---|
| 652 | 695 | return ret; |
|---|
| .. | .. |
|---|
| 677 | 720 | } |
|---|
| 678 | 721 | |
|---|
| 679 | 722 | #ifdef CONFIG_PM_SLEEP |
|---|
| 680 | | -static int omap_drm_suspend_all_displays(void) |
|---|
| 681 | | -{ |
|---|
| 682 | | - struct omap_dss_device *dssdev = NULL; |
|---|
| 683 | | - |
|---|
| 684 | | - for_each_dss_dev(dssdev) { |
|---|
| 685 | | - if (!dssdev->driver) |
|---|
| 686 | | - continue; |
|---|
| 687 | | - |
|---|
| 688 | | - if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) { |
|---|
| 689 | | - dssdev->driver->disable(dssdev); |
|---|
| 690 | | - dssdev->activate_after_resume = true; |
|---|
| 691 | | - } else { |
|---|
| 692 | | - dssdev->activate_after_resume = false; |
|---|
| 693 | | - } |
|---|
| 694 | | - } |
|---|
| 695 | | - |
|---|
| 696 | | - return 0; |
|---|
| 697 | | -} |
|---|
| 698 | | - |
|---|
| 699 | | -static int omap_drm_resume_all_displays(void) |
|---|
| 700 | | -{ |
|---|
| 701 | | - struct omap_dss_device *dssdev = NULL; |
|---|
| 702 | | - |
|---|
| 703 | | - for_each_dss_dev(dssdev) { |
|---|
| 704 | | - if (!dssdev->driver) |
|---|
| 705 | | - continue; |
|---|
| 706 | | - |
|---|
| 707 | | - if (dssdev->activate_after_resume) { |
|---|
| 708 | | - dssdev->driver->enable(dssdev); |
|---|
| 709 | | - dssdev->activate_after_resume = false; |
|---|
| 710 | | - } |
|---|
| 711 | | - } |
|---|
| 712 | | - |
|---|
| 713 | | - return 0; |
|---|
| 714 | | -} |
|---|
| 715 | | - |
|---|
| 716 | 723 | static int omap_drm_suspend(struct device *dev) |
|---|
| 717 | 724 | { |
|---|
| 718 | 725 | struct omap_drm_private *priv = dev_get_drvdata(dev); |
|---|
| 719 | 726 | struct drm_device *drm_dev = priv->ddev; |
|---|
| 720 | 727 | |
|---|
| 721 | | - drm_kms_helper_poll_disable(drm_dev); |
|---|
| 722 | | - |
|---|
| 723 | | - drm_modeset_lock_all(drm_dev); |
|---|
| 724 | | - omap_drm_suspend_all_displays(); |
|---|
| 725 | | - drm_modeset_unlock_all(drm_dev); |
|---|
| 726 | | - |
|---|
| 727 | | - return 0; |
|---|
| 728 | + return drm_mode_config_helper_suspend(drm_dev); |
|---|
| 728 | 729 | } |
|---|
| 729 | 730 | |
|---|
| 730 | 731 | static int omap_drm_resume(struct device *dev) |
|---|
| .. | .. |
|---|
| 732 | 733 | struct omap_drm_private *priv = dev_get_drvdata(dev); |
|---|
| 733 | 734 | struct drm_device *drm_dev = priv->ddev; |
|---|
| 734 | 735 | |
|---|
| 735 | | - drm_modeset_lock_all(drm_dev); |
|---|
| 736 | | - omap_drm_resume_all_displays(); |
|---|
| 737 | | - drm_modeset_unlock_all(drm_dev); |
|---|
| 738 | | - |
|---|
| 739 | | - drm_kms_helper_poll_enable(drm_dev); |
|---|
| 736 | + drm_mode_config_helper_resume(drm_dev); |
|---|
| 740 | 737 | |
|---|
| 741 | 738 | return omap_gem_resume(drm_dev); |
|---|
| 742 | 739 | } |
|---|