1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (C) 2013 Red Hat 4 * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved. 5 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. 6 * 7 * Author: Rob Clark <robdclark@gmail.com> 8 */ 9 10 #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__ 11 12 #include <linux/debugfs.h> 13 #include <linux/dma-buf.h> 14 #include <linux/of_irq.h> 15 #include <linux/pm_opp.h> 16 17 #include <drm/drm_crtc.h> 18 #include <drm/drm_file.h> 19 #include <drm/drm_framebuffer.h> 20 #include <drm/drm_vblank.h> 21 #include <drm/drm_writeback.h> 22 23 #include "msm_drv.h" 24 #include "msm_mmu.h" 25 #include "msm_mdss.h" 26 #include "msm_gem.h" 27 #include "disp/msm_disp_snapshot.h" 28 29 #include "dpu_core_irq.h" 30 #include "dpu_crtc.h" 31 #include "dpu_encoder.h" 32 #include "dpu_formats.h" 33 #include "dpu_hw_vbif.h" 34 #include "dpu_kms.h" 35 #include "dpu_plane.h" 36 #include "dpu_vbif.h" 37 #include "dpu_writeback.h" 38 39 #define CREATE_TRACE_POINTS 40 #include "dpu_trace.h" 41 42 /* 43 * To enable overall DRM driver logging 44 * # echo 0x2 > /sys/module/drm/parameters/debug 45 * 46 * To enable DRM driver h/w logging 47 * # echo <mask> > /sys/kernel/debug/dri/0/debug/hw_log_mask 48 * 49 * See dpu_hw_mdss.h for h/w logging mask definitions (search for DPU_DBG_MASK_) 50 */ 51 #define DPU_DEBUGFS_DIR "msm_dpu" 52 #define DPU_DEBUGFS_HWMASKNAME "hw_log_mask" 53 54 static int dpu_kms_hw_init(struct msm_kms *kms); 55 static void _dpu_kms_mmu_destroy(struct dpu_kms *dpu_kms); 56 57 #ifdef CONFIG_DEBUG_FS 58 static int _dpu_danger_signal_status(struct seq_file *s, 59 bool danger_status) 60 { 61 struct dpu_danger_safe_status status; 62 struct dpu_kms *kms = s->private; 63 int i; 64 65 if (!kms->hw_mdp) { 66 DPU_ERROR("invalid arg(s)\n"); 67 return 0; 68 } 69 70 memset(&status, 0, sizeof(struct dpu_danger_safe_status)); 71 72 pm_runtime_get_sync(&kms->pdev->dev); 73 if (danger_status) { 74 seq_puts(s, "\nDanger signal status:\n"); 75 if (kms->hw_mdp->ops.get_danger_status) 76 kms->hw_mdp->ops.get_danger_status(kms->hw_mdp, 77 &status); 78 } else { 79 seq_puts(s, "\nSafe signal status:\n"); 80 if (kms->hw_mdp->ops.get_safe_status) 81 kms->hw_mdp->ops.get_safe_status(kms->hw_mdp, 82 &status); 83 } 84 pm_runtime_put_sync(&kms->pdev->dev); 85 86 seq_printf(s, "MDP : 0x%x\n", status.mdp); 87 88 for (i = SSPP_VIG0; i < SSPP_MAX; i++) 89 seq_printf(s, "SSPP%d : 0x%x \n", i - SSPP_VIG0, 90 status.sspp[i]); 91 seq_puts(s, "\n"); 92 93 return 0; 94 } 95 96 static int dpu_debugfs_danger_stats_show(struct seq_file *s, void *v) 97 { 98 return _dpu_danger_signal_status(s, true); 99 } 100 DEFINE_SHOW_ATTRIBUTE(dpu_debugfs_danger_stats); 101 102 static int dpu_debugfs_safe_stats_show(struct seq_file *s, void *v) 103 { 104 return _dpu_danger_signal_status(s, false); 105 } 106 DEFINE_SHOW_ATTRIBUTE(dpu_debugfs_safe_stats); 107 108 static ssize_t _dpu_plane_danger_read(struct file *file, 109 char __user *buff, size_t count, loff_t *ppos) 110 { 111 struct dpu_kms *kms = file->private_data; 112 int len; 113 char buf[40]; 114 115 len = scnprintf(buf, sizeof(buf), "%d\n", !kms->has_danger_ctrl); 116 117 return simple_read_from_buffer(buff, count, ppos, buf, len); 118 } 119 120 static void _dpu_plane_set_danger_state(struct dpu_kms *kms, bool enable) 121 { 122 struct drm_plane *plane; 123 124 drm_for_each_plane(plane, kms->dev) { 125 if (plane->fb && plane->state) { 126 dpu_plane_danger_signal_ctrl(plane, enable); 127 DPU_DEBUG("plane:%d img:%dx%d ", 128 plane->base.id, plane->fb->width, 129 plane->fb->height); 130 DPU_DEBUG("src[%d,%d,%d,%d] dst[%d,%d,%d,%d]\n", 131 plane->state->src_x >> 16, 132 plane->state->src_y >> 16, 133 plane->state->src_w >> 16, 134 plane->state->src_h >> 16, 135 plane->state->crtc_x, plane->state->crtc_y, 136 plane->state->crtc_w, plane->state->crtc_h); 137 } else { 138 DPU_DEBUG("Inactive plane:%d\n", plane->base.id); 139 } 140 } 141 } 142 143 static ssize_t _dpu_plane_danger_write(struct file *file, 144 const char __user *user_buf, size_t count, loff_t *ppos) 145 { 146 struct dpu_kms *kms = file->private_data; 147 int disable_panic; 148 int ret; 149 150 ret = kstrtouint_from_user(user_buf, count, 0, &disable_panic); 151 if (ret) 152 return ret; 153 154 if (disable_panic) { 155 /* Disable panic signal for all active pipes */ 156 DPU_DEBUG("Disabling danger:\n"); 157 _dpu_plane_set_danger_state(kms, false); 158 kms->has_danger_ctrl = false; 159 } else { 160 /* Enable panic signal for all active pipes */ 161 DPU_DEBUG("Enabling danger:\n"); 162 kms->has_danger_ctrl = true; 163 _dpu_plane_set_danger_state(kms, true); 164 } 165 166 return count; 167 } 168 169 static const struct file_operations dpu_plane_danger_enable = { 170 .open = simple_open, 171 .read = _dpu_plane_danger_read, 172 .write = _dpu_plane_danger_write, 173 }; 174 175 static void dpu_debugfs_danger_init(struct dpu_kms *dpu_kms, 176 struct dentry *parent) 177 { 178 struct dentry *entry = debugfs_create_dir("danger", parent); 179 180 debugfs_create_file("danger_status", 0600, entry, 181 dpu_kms, &dpu_debugfs_danger_stats_fops); 182 debugfs_create_file("safe_status", 0600, entry, 183 dpu_kms, &dpu_debugfs_safe_stats_fops); 184 debugfs_create_file("disable_danger", 0600, entry, 185 dpu_kms, &dpu_plane_danger_enable); 186 187 } 188 189 /* 190 * Companion structure for dpu_debugfs_create_regset32. 191 */ 192 struct dpu_debugfs_regset32 { 193 uint32_t offset; 194 uint32_t blk_len; 195 struct dpu_kms *dpu_kms; 196 }; 197 198 static int dpu_regset32_show(struct seq_file *s, void *data) 199 { 200 struct dpu_debugfs_regset32 *regset = s->private; 201 struct dpu_kms *dpu_kms = regset->dpu_kms; 202 void __iomem *base; 203 uint32_t i, addr; 204 205 if (!dpu_kms->mmio) 206 return 0; 207 208 base = dpu_kms->mmio + regset->offset; 209 210 /* insert padding spaces, if needed */ 211 if (regset->offset & 0xF) { 212 seq_printf(s, "[%x]", regset->offset & ~0xF); 213 for (i = 0; i < (regset->offset & 0xF); i += 4) 214 seq_puts(s, " "); 215 } 216 217 pm_runtime_get_sync(&dpu_kms->pdev->dev); 218 219 /* main register output */ 220 for (i = 0; i < regset->blk_len; i += 4) { 221 addr = regset->offset + i; 222 if ((addr & 0xF) == 0x0) 223 seq_printf(s, i ? "\n[%x]" : "[%x]", addr); 224 seq_printf(s, " %08x", readl_relaxed(base + i)); 225 } 226 seq_puts(s, "\n"); 227 pm_runtime_put_sync(&dpu_kms->pdev->dev); 228 229 return 0; 230 } 231 DEFINE_SHOW_ATTRIBUTE(dpu_regset32); 232 233 void dpu_debugfs_create_regset32(const char *name, umode_t mode, 234 void *parent, 235 uint32_t offset, uint32_t length, struct dpu_kms *dpu_kms) 236 { 237 struct dpu_debugfs_regset32 *regset; 238 239 if (WARN_ON(!name || !dpu_kms || !length)) 240 return; 241 242 regset = devm_kzalloc(&dpu_kms->pdev->dev, sizeof(*regset), GFP_KERNEL); 243 if (!regset) 244 return; 245 246 /* make sure offset is a multiple of 4 */ 247 regset->offset = round_down(offset, 4); 248 regset->blk_len = length; 249 regset->dpu_kms = dpu_kms; 250 251 debugfs_create_file(name, mode, parent, regset, &dpu_regset32_fops); 252 } 253 254 static void dpu_debugfs_sspp_init(struct dpu_kms *dpu_kms, struct dentry *debugfs_root) 255 { 256 struct dentry *entry = debugfs_create_dir("sspp", debugfs_root); 257 int i; 258 259 if (IS_ERR(entry)) 260 return; 261 262 for (i = SSPP_NONE; i < SSPP_MAX; i++) { 263 struct dpu_hw_sspp *hw = dpu_rm_get_sspp(&dpu_kms->rm, i); 264 265 if (!hw) 266 continue; 267 268 _dpu_hw_sspp_init_debugfs(hw, dpu_kms, entry); 269 } 270 } 271 272 static int dpu_kms_debugfs_init(struct msm_kms *kms, struct drm_minor *minor) 273 { 274 struct dpu_kms *dpu_kms = to_dpu_kms(kms); 275 void *p = dpu_hw_util_get_log_mask_ptr(); 276 struct dentry *entry; 277 278 if (!p) 279 return -EINVAL; 280 281 /* Only create a set of debugfs for the primary node, ignore render nodes */ 282 if (minor->type != DRM_MINOR_PRIMARY) 283 return 0; 284 285 entry = debugfs_create_dir("debug", minor->debugfs_root); 286 287 debugfs_create_x32(DPU_DEBUGFS_HWMASKNAME, 0600, entry, p); 288 289 dpu_debugfs_danger_init(dpu_kms, entry); 290 dpu_debugfs_vbif_init(dpu_kms, entry); 291 dpu_debugfs_core_irq_init(dpu_kms, entry); 292 dpu_debugfs_sspp_init(dpu_kms, entry); 293 294 return dpu_core_perf_debugfs_init(dpu_kms, entry); 295 } 296 #endif 297 298 /* Global/shared object state funcs */ 299 300 /* 301 * This is a helper that returns the private state currently in operation. 302 * Note that this would return the "old_state" if called in the atomic check 303 * path, and the "new_state" after the atomic swap has been done. 304 */ 305 struct dpu_global_state * 306 dpu_kms_get_existing_global_state(struct dpu_kms *dpu_kms) 307 { 308 return to_dpu_global_state(dpu_kms->global_state.state); 309 } 310 311 /* 312 * This acquires the modeset lock set aside for global state, creates 313 * a new duplicated private object state. 314 */ 315 struct dpu_global_state *dpu_kms_get_global_state(struct drm_atomic_state *s) 316 { 317 struct msm_drm_private *priv = s->dev->dev_private; 318 struct dpu_kms *dpu_kms = to_dpu_kms(priv->kms); 319 struct drm_private_state *priv_state; 320 321 priv_state = drm_atomic_get_private_obj_state(s, 322 &dpu_kms->global_state); 323 if (IS_ERR(priv_state)) 324 return ERR_CAST(priv_state); 325 326 return to_dpu_global_state(priv_state); 327 } 328 329 static struct drm_private_state * 330 dpu_kms_global_duplicate_state(struct drm_private_obj *obj) 331 { 332 struct dpu_global_state *state; 333 334 state = kmemdup(obj->state, sizeof(*state), GFP_KERNEL); 335 if (!state) 336 return NULL; 337 338 __drm_atomic_helper_private_obj_duplicate_state(obj, &state->base); 339 340 return &state->base; 341 } 342 343 static void dpu_kms_global_destroy_state(struct drm_private_obj *obj, 344 struct drm_private_state *state) 345 { 346 struct dpu_global_state *dpu_state = to_dpu_global_state(state); 347 348 kfree(dpu_state); 349 } 350 351 static const struct drm_private_state_funcs dpu_kms_global_state_funcs = { 352 .atomic_duplicate_state = dpu_kms_global_duplicate_state, 353 .atomic_destroy_state = dpu_kms_global_destroy_state, 354 }; 355 356 static int dpu_kms_global_obj_init(struct dpu_kms *dpu_kms) 357 { 358 struct dpu_global_state *state; 359 360 state = kzalloc(sizeof(*state), GFP_KERNEL); 361 if (!state) 362 return -ENOMEM; 363 364 drm_atomic_private_obj_init(dpu_kms->dev, &dpu_kms->global_state, 365 &state->base, 366 &dpu_kms_global_state_funcs); 367 return 0; 368 } 369 370 static void dpu_kms_global_obj_fini(struct dpu_kms *dpu_kms) 371 { 372 drm_atomic_private_obj_fini(&dpu_kms->global_state); 373 } 374 375 static int dpu_kms_parse_data_bus_icc_path(struct dpu_kms *dpu_kms) 376 { 377 struct icc_path *path0; 378 struct icc_path *path1; 379 struct device *dpu_dev = &dpu_kms->pdev->dev; 380 381 path0 = msm_icc_get(dpu_dev, "mdp0-mem"); 382 path1 = msm_icc_get(dpu_dev, "mdp1-mem"); 383 384 if (IS_ERR_OR_NULL(path0)) 385 return PTR_ERR_OR_ZERO(path0); 386 387 dpu_kms->path[0] = path0; 388 dpu_kms->num_paths = 1; 389 390 if (!IS_ERR_OR_NULL(path1)) { 391 dpu_kms->path[1] = path1; 392 dpu_kms->num_paths++; 393 } 394 return 0; 395 } 396 397 static int dpu_kms_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc) 398 { 399 return dpu_crtc_vblank(crtc, true); 400 } 401 402 static void dpu_kms_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc) 403 { 404 dpu_crtc_vblank(crtc, false); 405 } 406 407 static void dpu_kms_enable_commit(struct msm_kms *kms) 408 { 409 struct dpu_kms *dpu_kms = to_dpu_kms(kms); 410 pm_runtime_get_sync(&dpu_kms->pdev->dev); 411 } 412 413 static void dpu_kms_disable_commit(struct msm_kms *kms) 414 { 415 struct dpu_kms *dpu_kms = to_dpu_kms(kms); 416 pm_runtime_put_sync(&dpu_kms->pdev->dev); 417 } 418 419 static void dpu_kms_flush_commit(struct msm_kms *kms, unsigned crtc_mask) 420 { 421 struct dpu_kms *dpu_kms = to_dpu_kms(kms); 422 struct drm_crtc *crtc; 423 424 for_each_crtc_mask(dpu_kms->dev, crtc, crtc_mask) { 425 if (!crtc->state->active) 426 continue; 427 428 trace_dpu_kms_commit(DRMID(crtc)); 429 dpu_crtc_commit_kickoff(crtc); 430 } 431 } 432 433 static void dpu_kms_complete_commit(struct msm_kms *kms, unsigned crtc_mask) 434 { 435 struct dpu_kms *dpu_kms = to_dpu_kms(kms); 436 struct drm_crtc *crtc; 437 438 DPU_ATRACE_BEGIN("kms_complete_commit"); 439 440 for_each_crtc_mask(dpu_kms->dev, crtc, crtc_mask) 441 dpu_crtc_complete_commit(crtc); 442 443 DPU_ATRACE_END("kms_complete_commit"); 444 } 445 446 static void dpu_kms_wait_for_commit_done(struct msm_kms *kms, 447 struct drm_crtc *crtc) 448 { 449 struct drm_encoder *encoder; 450 struct drm_device *dev; 451 int ret; 452 453 if (!kms || !crtc || !crtc->state) { 454 DPU_ERROR("invalid params\n"); 455 return; 456 } 457 458 dev = crtc->dev; 459 460 if (!crtc->state->enable) { 461 DPU_DEBUG("[crtc:%d] not enable\n", crtc->base.id); 462 return; 463 } 464 465 if (!drm_atomic_crtc_effectively_active(crtc->state)) { 466 DPU_DEBUG("[crtc:%d] not active\n", crtc->base.id); 467 return; 468 } 469 470 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 471 if (encoder->crtc != crtc) 472 continue; 473 /* 474 * Wait for post-flush if necessary to delay before 475 * plane_cleanup. For example, wait for vsync in case of video 476 * mode panels. This may be a no-op for command mode panels. 477 */ 478 trace_dpu_kms_wait_for_commit_done(DRMID(crtc)); 479 ret = dpu_encoder_wait_for_commit_done(encoder); 480 if (ret && ret != -EWOULDBLOCK) { 481 DPU_ERROR("wait for commit done returned %d\n", ret); 482 break; 483 } 484 } 485 } 486 487 static void dpu_kms_wait_flush(struct msm_kms *kms, unsigned crtc_mask) 488 { 489 struct dpu_kms *dpu_kms = to_dpu_kms(kms); 490 struct drm_crtc *crtc; 491 492 for_each_crtc_mask(dpu_kms->dev, crtc, crtc_mask) 493 dpu_kms_wait_for_commit_done(kms, crtc); 494 } 495 496 static int _dpu_kms_initialize_dsi(struct drm_device *dev, 497 struct msm_drm_private *priv, 498 struct dpu_kms *dpu_kms) 499 { 500 struct drm_encoder *encoder = NULL; 501 struct msm_display_info info; 502 int i, rc = 0; 503 504 if (!(priv->dsi[0] || priv->dsi[1])) 505 return rc; 506 507 /* 508 * We support following confiurations: 509 * - Single DSI host (dsi0 or dsi1) 510 * - Two independent DSI hosts 511 * - Bonded DSI0 and DSI1 hosts 512 * 513 * TODO: Support swapping DSI0 and DSI1 in the bonded setup. 514 */ 515 for (i = 0; i < ARRAY_SIZE(priv->dsi); i++) { 516 int other = (i + 1) % 2; 517 518 if (!priv->dsi[i]) 519 continue; 520 521 if (msm_dsi_is_bonded_dsi(priv->dsi[i]) && 522 !msm_dsi_is_master_dsi(priv->dsi[i])) 523 continue; 524 525 memset(&info, 0, sizeof(info)); 526 info.intf_type = INTF_DSI; 527 528 info.h_tile_instance[info.num_of_h_tiles++] = i; 529 if (msm_dsi_is_bonded_dsi(priv->dsi[i])) 530 info.h_tile_instance[info.num_of_h_tiles++] = other; 531 532 info.is_cmd_mode = msm_dsi_is_cmd_mode(priv->dsi[i]); 533 534 encoder = dpu_encoder_init(dev, DRM_MODE_ENCODER_DSI, &info); 535 if (IS_ERR(encoder)) { 536 DPU_ERROR("encoder init failed for dsi display\n"); 537 return PTR_ERR(encoder); 538 } 539 540 rc = msm_dsi_modeset_init(priv->dsi[i], dev, encoder); 541 if (rc) { 542 DPU_ERROR("modeset_init failed for dsi[%d], rc = %d\n", 543 i, rc); 544 break; 545 } 546 547 if (msm_dsi_is_bonded_dsi(priv->dsi[i]) && priv->dsi[other]) { 548 rc = msm_dsi_modeset_init(priv->dsi[other], dev, encoder); 549 if (rc) { 550 DPU_ERROR("modeset_init failed for dsi[%d], rc = %d\n", 551 other, rc); 552 break; 553 } 554 } 555 } 556 557 return rc; 558 } 559 560 static int _dpu_kms_initialize_displayport(struct drm_device *dev, 561 struct msm_drm_private *priv, 562 struct dpu_kms *dpu_kms) 563 { 564 struct drm_encoder *encoder = NULL; 565 struct msm_display_info info; 566 bool yuv_supported; 567 int rc; 568 int i; 569 570 for (i = 0; i < ARRAY_SIZE(priv->dp); i++) { 571 if (!priv->dp[i]) 572 continue; 573 574 memset(&info, 0, sizeof(info)); 575 info.num_of_h_tiles = 1; 576 info.h_tile_instance[0] = i; 577 info.intf_type = INTF_DP; 578 579 encoder = dpu_encoder_init(dev, DRM_MODE_ENCODER_TMDS, &info); 580 if (IS_ERR(encoder)) { 581 DPU_ERROR("encoder init failed for dsi display\n"); 582 return PTR_ERR(encoder); 583 } 584 585 yuv_supported = !!dpu_kms->catalog->cdm; 586 rc = msm_dp_modeset_init(priv->dp[i], dev, encoder, yuv_supported); 587 if (rc) { 588 DPU_ERROR("modeset_init failed for DP, rc = %d\n", rc); 589 return rc; 590 } 591 } 592 593 return 0; 594 } 595 596 static int _dpu_kms_initialize_hdmi(struct drm_device *dev, 597 struct msm_drm_private *priv, 598 struct dpu_kms *dpu_kms) 599 { 600 struct drm_encoder *encoder = NULL; 601 struct msm_display_info info; 602 int rc; 603 604 if (!priv->hdmi) 605 return 0; 606 607 memset(&info, 0, sizeof(info)); 608 info.num_of_h_tiles = 1; 609 info.h_tile_instance[0] = 0; 610 info.intf_type = INTF_HDMI; 611 612 encoder = dpu_encoder_init(dev, DRM_MODE_ENCODER_TMDS, &info); 613 if (IS_ERR(encoder)) { 614 DPU_ERROR("encoder init failed for HDMI display\n"); 615 return PTR_ERR(encoder); 616 } 617 618 rc = msm_hdmi_modeset_init(priv->hdmi, dev, encoder); 619 if (rc) { 620 DPU_ERROR("modeset_init failed for DP, rc = %d\n", rc); 621 return rc; 622 } 623 624 return 0; 625 } 626 627 static int _dpu_kms_initialize_writeback(struct drm_device *dev, 628 struct msm_drm_private *priv, struct dpu_kms *dpu_kms, 629 const u32 *wb_formats, int n_formats) 630 { 631 struct drm_encoder *encoder = NULL; 632 struct msm_display_info info; 633 const enum dpu_wb wb_idx = WB_2; 634 u32 maxlinewidth; 635 int rc; 636 637 memset(&info, 0, sizeof(info)); 638 639 info.num_of_h_tiles = 1; 640 /* use only WB idx 2 instance for DPU */ 641 info.h_tile_instance[0] = wb_idx; 642 info.intf_type = INTF_WB; 643 644 maxlinewidth = dpu_rm_get_wb(&dpu_kms->rm, info.h_tile_instance[0])->caps->maxlinewidth; 645 646 encoder = dpu_encoder_init(dev, DRM_MODE_ENCODER_VIRTUAL, &info); 647 if (IS_ERR(encoder)) { 648 DPU_ERROR("encoder init failed for dsi display\n"); 649 return PTR_ERR(encoder); 650 } 651 652 rc = dpu_writeback_init(dev, encoder, wb_formats, n_formats, maxlinewidth); 653 if (rc) { 654 DPU_ERROR("dpu_writeback_init, rc = %d\n", rc); 655 return rc; 656 } 657 658 return 0; 659 } 660 661 /** 662 * _dpu_kms_setup_displays - create encoders, bridges and connectors 663 * for underlying displays 664 * @dev: Pointer to drm device structure 665 * @priv: Pointer to private drm device data 666 * @dpu_kms: Pointer to dpu kms structure 667 * Returns: Zero on success 668 */ 669 static int _dpu_kms_setup_displays(struct drm_device *dev, 670 struct msm_drm_private *priv, 671 struct dpu_kms *dpu_kms) 672 { 673 int rc = 0; 674 int i; 675 676 rc = _dpu_kms_initialize_dsi(dev, priv, dpu_kms); 677 if (rc) { 678 DPU_ERROR("initialize_dsi failed, rc = %d\n", rc); 679 return rc; 680 } 681 682 rc = _dpu_kms_initialize_displayport(dev, priv, dpu_kms); 683 if (rc) { 684 DPU_ERROR("initialize_DP failed, rc = %d\n", rc); 685 return rc; 686 } 687 688 rc = _dpu_kms_initialize_hdmi(dev, priv, dpu_kms); 689 if (rc) { 690 DPU_ERROR("initialize HDMI failed, rc = %d\n", rc); 691 return rc; 692 } 693 694 /* Since WB isn't a driver check the catalog before initializing */ 695 if (dpu_kms->catalog->wb_count) { 696 for (i = 0; i < dpu_kms->catalog->wb_count; i++) { 697 if (dpu_kms->catalog->wb[i].id == WB_2) { 698 rc = _dpu_kms_initialize_writeback(dev, priv, dpu_kms, 699 dpu_kms->catalog->wb[i].format_list, 700 dpu_kms->catalog->wb[i].num_formats); 701 if (rc) { 702 DPU_ERROR("initialize_WB failed, rc = %d\n", rc); 703 return rc; 704 } 705 } 706 } 707 } 708 709 return rc; 710 } 711 712 #define MAX_PLANES 20 713 static int _dpu_kms_drm_obj_init(struct dpu_kms *dpu_kms) 714 { 715 struct drm_device *dev; 716 struct drm_plane *primary_planes[MAX_PLANES], *plane; 717 struct drm_plane *cursor_planes[MAX_PLANES] = { NULL }; 718 struct drm_crtc *crtc; 719 struct drm_encoder *encoder; 720 unsigned int num_encoders; 721 722 struct msm_drm_private *priv; 723 const struct dpu_mdss_cfg *catalog; 724 725 int primary_planes_idx = 0, cursor_planes_idx = 0, i, ret; 726 int max_crtc_count; 727 dev = dpu_kms->dev; 728 priv = dev->dev_private; 729 catalog = dpu_kms->catalog; 730 731 /* 732 * Create encoder and query display drivers to create 733 * bridges and connectors 734 */ 735 ret = _dpu_kms_setup_displays(dev, priv, dpu_kms); 736 if (ret) 737 return ret; 738 739 num_encoders = 0; 740 drm_for_each_encoder(encoder, dev) 741 num_encoders++; 742 743 max_crtc_count = min(catalog->mixer_count, num_encoders); 744 745 /* Create the planes, keeping track of one primary/cursor per crtc */ 746 for (i = 0; i < catalog->sspp_count; i++) { 747 enum drm_plane_type type; 748 749 if ((catalog->sspp[i].features & BIT(DPU_SSPP_CURSOR)) 750 && cursor_planes_idx < max_crtc_count) 751 type = DRM_PLANE_TYPE_CURSOR; 752 else if (primary_planes_idx < max_crtc_count) 753 type = DRM_PLANE_TYPE_PRIMARY; 754 else 755 type = DRM_PLANE_TYPE_OVERLAY; 756 757 DPU_DEBUG("Create plane type %d with features %lx (cur %lx)\n", 758 type, catalog->sspp[i].features, 759 catalog->sspp[i].features & BIT(DPU_SSPP_CURSOR)); 760 761 plane = dpu_plane_init(dev, catalog->sspp[i].id, type, 762 (1UL << max_crtc_count) - 1); 763 if (IS_ERR(plane)) { 764 DPU_ERROR("dpu_plane_init failed\n"); 765 ret = PTR_ERR(plane); 766 return ret; 767 } 768 769 if (type == DRM_PLANE_TYPE_CURSOR) 770 cursor_planes[cursor_planes_idx++] = plane; 771 else if (type == DRM_PLANE_TYPE_PRIMARY) 772 primary_planes[primary_planes_idx++] = plane; 773 } 774 775 max_crtc_count = min(max_crtc_count, primary_planes_idx); 776 777 /* Create one CRTC per encoder */ 778 for (i = 0; i < max_crtc_count; i++) { 779 crtc = dpu_crtc_init(dev, primary_planes[i], cursor_planes[i]); 780 if (IS_ERR(crtc)) { 781 ret = PTR_ERR(crtc); 782 return ret; 783 } 784 priv->num_crtcs++; 785 } 786 787 /* All CRTCs are compatible with all encoders */ 788 drm_for_each_encoder(encoder, dev) 789 encoder->possible_crtcs = (1 << priv->num_crtcs) - 1; 790 791 return 0; 792 } 793 794 static void _dpu_kms_hw_destroy(struct dpu_kms *dpu_kms) 795 { 796 int i; 797 798 dpu_kms->hw_intr = NULL; 799 800 /* safe to call these more than once during shutdown */ 801 _dpu_kms_mmu_destroy(dpu_kms); 802 803 for (i = 0; i < ARRAY_SIZE(dpu_kms->hw_vbif); i++) { 804 dpu_kms->hw_vbif[i] = NULL; 805 } 806 807 dpu_kms_global_obj_fini(dpu_kms); 808 809 dpu_kms->catalog = NULL; 810 811 dpu_kms->hw_mdp = NULL; 812 } 813 814 static void dpu_kms_destroy(struct msm_kms *kms) 815 { 816 struct dpu_kms *dpu_kms; 817 818 if (!kms) { 819 DPU_ERROR("invalid kms\n"); 820 return; 821 } 822 823 dpu_kms = to_dpu_kms(kms); 824 825 _dpu_kms_hw_destroy(dpu_kms); 826 827 msm_kms_destroy(&dpu_kms->base); 828 829 if (dpu_kms->rpm_enabled) 830 pm_runtime_disable(&dpu_kms->pdev->dev); 831 } 832 833 static int dpu_irq_postinstall(struct msm_kms *kms) 834 { 835 struct msm_drm_private *priv; 836 struct dpu_kms *dpu_kms = to_dpu_kms(kms); 837 838 if (!dpu_kms || !dpu_kms->dev) 839 return -EINVAL; 840 841 priv = dpu_kms->dev->dev_private; 842 if (!priv) 843 return -EINVAL; 844 845 return 0; 846 } 847 848 static void dpu_kms_mdp_snapshot(struct msm_disp_state *disp_state, struct msm_kms *kms) 849 { 850 int i; 851 struct dpu_kms *dpu_kms; 852 const struct dpu_mdss_cfg *cat; 853 void __iomem *base; 854 855 dpu_kms = to_dpu_kms(kms); 856 857 cat = dpu_kms->catalog; 858 859 pm_runtime_get_sync(&dpu_kms->pdev->dev); 860 861 /* dump CTL sub-blocks HW regs info */ 862 for (i = 0; i < cat->ctl_count; i++) 863 msm_disp_snapshot_add_block(disp_state, cat->ctl[i].len, 864 dpu_kms->mmio + cat->ctl[i].base, cat->ctl[i].name); 865 866 /* dump DSPP sub-blocks HW regs info */ 867 for (i = 0; i < cat->dspp_count; i++) { 868 base = dpu_kms->mmio + cat->dspp[i].base; 869 msm_disp_snapshot_add_block(disp_state, cat->dspp[i].len, base, cat->dspp[i].name); 870 871 if (cat->dspp[i].sblk && cat->dspp[i].sblk->pcc.len > 0) 872 msm_disp_snapshot_add_block(disp_state, cat->dspp[i].sblk->pcc.len, 873 base + cat->dspp[i].sblk->pcc.base, "%s_%s", 874 cat->dspp[i].name, 875 cat->dspp[i].sblk->pcc.name); 876 } 877 878 /* dump INTF sub-blocks HW regs info */ 879 for (i = 0; i < cat->intf_count; i++) 880 msm_disp_snapshot_add_block(disp_state, cat->intf[i].len, 881 dpu_kms->mmio + cat->intf[i].base, cat->intf[i].name); 882 883 /* dump PP sub-blocks HW regs info */ 884 for (i = 0; i < cat->pingpong_count; i++) { 885 base = dpu_kms->mmio + cat->pingpong[i].base; 886 msm_disp_snapshot_add_block(disp_state, cat->pingpong[i].len, base, 887 cat->pingpong[i].name); 888 889 /* TE2 sub-block has length of 0, so will not print it */ 890 891 if (cat->pingpong[i].sblk && cat->pingpong[i].sblk->dither.len > 0) 892 msm_disp_snapshot_add_block(disp_state, cat->pingpong[i].sblk->dither.len, 893 base + cat->pingpong[i].sblk->dither.base, 894 "%s_%s", cat->pingpong[i].name, 895 cat->pingpong[i].sblk->dither.name); 896 } 897 898 /* dump SSPP sub-blocks HW regs info */ 899 for (i = 0; i < cat->sspp_count; i++) { 900 base = dpu_kms->mmio + cat->sspp[i].base; 901 msm_disp_snapshot_add_block(disp_state, cat->sspp[i].len, base, cat->sspp[i].name); 902 903 if (cat->sspp[i].sblk && cat->sspp[i].sblk->scaler_blk.len > 0) 904 msm_disp_snapshot_add_block(disp_state, cat->sspp[i].sblk->scaler_blk.len, 905 base + cat->sspp[i].sblk->scaler_blk.base, 906 "%s_%s", cat->sspp[i].name, 907 cat->sspp[i].sblk->scaler_blk.name); 908 909 if (cat->sspp[i].sblk && cat->sspp[i].sblk->csc_blk.len > 0) 910 msm_disp_snapshot_add_block(disp_state, cat->sspp[i].sblk->csc_blk.len, 911 base + cat->sspp[i].sblk->csc_blk.base, 912 "%s_%s", cat->sspp[i].name, 913 cat->sspp[i].sblk->csc_blk.name); 914 } 915 916 /* dump LM sub-blocks HW regs info */ 917 for (i = 0; i < cat->mixer_count; i++) 918 msm_disp_snapshot_add_block(disp_state, cat->mixer[i].len, 919 dpu_kms->mmio + cat->mixer[i].base, cat->mixer[i].name); 920 921 /* dump WB sub-blocks HW regs info */ 922 for (i = 0; i < cat->wb_count; i++) 923 msm_disp_snapshot_add_block(disp_state, cat->wb[i].len, 924 dpu_kms->mmio + cat->wb[i].base, cat->wb[i].name); 925 926 if (cat->mdp[0].features & BIT(DPU_MDP_PERIPH_0_REMOVED)) { 927 msm_disp_snapshot_add_block(disp_state, MDP_PERIPH_TOP0, 928 dpu_kms->mmio + cat->mdp[0].base, "top"); 929 msm_disp_snapshot_add_block(disp_state, cat->mdp[0].len - MDP_PERIPH_TOP0_END, 930 dpu_kms->mmio + cat->mdp[0].base + MDP_PERIPH_TOP0_END, "top_2"); 931 } else { 932 msm_disp_snapshot_add_block(disp_state, cat->mdp[0].len, 933 dpu_kms->mmio + cat->mdp[0].base, "top"); 934 } 935 936 /* dump DSC sub-blocks HW regs info */ 937 for (i = 0; i < cat->dsc_count; i++) { 938 base = dpu_kms->mmio + cat->dsc[i].base; 939 msm_disp_snapshot_add_block(disp_state, cat->dsc[i].len, base, cat->dsc[i].name); 940 941 if (cat->dsc[i].features & BIT(DPU_DSC_HW_REV_1_2)) { 942 struct dpu_dsc_blk enc = cat->dsc[i].sblk->enc; 943 struct dpu_dsc_blk ctl = cat->dsc[i].sblk->ctl; 944 945 msm_disp_snapshot_add_block(disp_state, enc.len, base + enc.base, "%s_%s", 946 cat->dsc[i].name, enc.name); 947 msm_disp_snapshot_add_block(disp_state, ctl.len, base + ctl.base, "%s_%s", 948 cat->dsc[i].name, ctl.name); 949 } 950 } 951 952 if (cat->cdm) 953 msm_disp_snapshot_add_block(disp_state, cat->cdm->len, 954 dpu_kms->mmio + cat->cdm->base, cat->cdm->name); 955 956 pm_runtime_put_sync(&dpu_kms->pdev->dev); 957 } 958 959 static const struct msm_kms_funcs kms_funcs = { 960 .hw_init = dpu_kms_hw_init, 961 .irq_preinstall = dpu_core_irq_preinstall, 962 .irq_postinstall = dpu_irq_postinstall, 963 .irq_uninstall = dpu_core_irq_uninstall, 964 .irq = dpu_core_irq, 965 .enable_commit = dpu_kms_enable_commit, 966 .disable_commit = dpu_kms_disable_commit, 967 .flush_commit = dpu_kms_flush_commit, 968 .wait_flush = dpu_kms_wait_flush, 969 .complete_commit = dpu_kms_complete_commit, 970 .enable_vblank = dpu_kms_enable_vblank, 971 .disable_vblank = dpu_kms_disable_vblank, 972 .check_modified_format = dpu_format_check_modified_format, 973 .get_format = dpu_get_msm_format, 974 .destroy = dpu_kms_destroy, 975 .snapshot = dpu_kms_mdp_snapshot, 976 #ifdef CONFIG_DEBUG_FS 977 .debugfs_init = dpu_kms_debugfs_init, 978 #endif 979 }; 980 981 static void _dpu_kms_mmu_destroy(struct dpu_kms *dpu_kms) 982 { 983 struct msm_mmu *mmu; 984 985 if (!dpu_kms->base.aspace) 986 return; 987 988 mmu = dpu_kms->base.aspace->mmu; 989 990 mmu->funcs->detach(mmu); 991 msm_gem_address_space_put(dpu_kms->base.aspace); 992 993 dpu_kms->base.aspace = NULL; 994 } 995 996 static int _dpu_kms_mmu_init(struct dpu_kms *dpu_kms) 997 { 998 struct msm_gem_address_space *aspace; 999 1000 aspace = msm_kms_init_aspace(dpu_kms->dev); 1001 if (IS_ERR(aspace)) 1002 return PTR_ERR(aspace); 1003 1004 dpu_kms->base.aspace = aspace; 1005 1006 return 0; 1007 } 1008 1009 unsigned long dpu_kms_get_clk_rate(struct dpu_kms *dpu_kms, char *clock_name) 1010 { 1011 struct clk *clk; 1012 1013 clk = msm_clk_bulk_get_clock(dpu_kms->clocks, dpu_kms->num_clocks, clock_name); 1014 if (!clk) 1015 return 0; 1016 1017 return clk_get_rate(clk); 1018 } 1019 1020 #define DPU_PERF_DEFAULT_MAX_CORE_CLK_RATE 412500000 1021 1022 static int dpu_kms_hw_init(struct msm_kms *kms) 1023 { 1024 struct dpu_kms *dpu_kms; 1025 struct drm_device *dev; 1026 int i, rc = -EINVAL; 1027 unsigned long max_core_clk_rate; 1028 u32 core_rev; 1029 1030 if (!kms) { 1031 DPU_ERROR("invalid kms\n"); 1032 return rc; 1033 } 1034 1035 dpu_kms = to_dpu_kms(kms); 1036 dev = dpu_kms->dev; 1037 1038 dev->mode_config.cursor_width = 512; 1039 dev->mode_config.cursor_height = 512; 1040 1041 rc = dpu_kms_global_obj_init(dpu_kms); 1042 if (rc) 1043 return rc; 1044 1045 atomic_set(&dpu_kms->bandwidth_ref, 0); 1046 1047 rc = pm_runtime_resume_and_get(&dpu_kms->pdev->dev); 1048 if (rc < 0) 1049 goto error; 1050 1051 core_rev = readl_relaxed(dpu_kms->mmio + 0x0); 1052 1053 pr_info("dpu hardware revision:0x%x\n", core_rev); 1054 1055 dpu_kms->catalog = of_device_get_match_data(dev->dev); 1056 if (!dpu_kms->catalog) { 1057 DPU_ERROR("device config not known!\n"); 1058 rc = -EINVAL; 1059 goto err_pm_put; 1060 } 1061 1062 /* 1063 * Now we need to read the HW catalog and initialize resources such as 1064 * clocks, regulators, GDSC/MMAGIC, ioremap the register ranges etc 1065 */ 1066 rc = _dpu_kms_mmu_init(dpu_kms); 1067 if (rc) { 1068 DPU_ERROR("dpu_kms_mmu_init failed: %d\n", rc); 1069 goto err_pm_put; 1070 } 1071 1072 dpu_kms->mdss = msm_mdss_get_mdss_data(dpu_kms->pdev->dev.parent); 1073 if (IS_ERR(dpu_kms->mdss)) { 1074 rc = PTR_ERR(dpu_kms->mdss); 1075 DPU_ERROR("failed to get MDSS data: %d\n", rc); 1076 goto err_pm_put; 1077 } 1078 1079 if (!dpu_kms->mdss) { 1080 rc = -EINVAL; 1081 DPU_ERROR("NULL MDSS data\n"); 1082 goto err_pm_put; 1083 } 1084 1085 rc = dpu_rm_init(dev, &dpu_kms->rm, dpu_kms->catalog, dpu_kms->mdss, dpu_kms->mmio); 1086 if (rc) { 1087 DPU_ERROR("rm init failed: %d\n", rc); 1088 goto err_pm_put; 1089 } 1090 1091 dpu_kms->hw_mdp = dpu_hw_mdptop_init(dev, 1092 dpu_kms->catalog->mdp, 1093 dpu_kms->mmio, 1094 dpu_kms->catalog); 1095 if (IS_ERR(dpu_kms->hw_mdp)) { 1096 rc = PTR_ERR(dpu_kms->hw_mdp); 1097 DPU_ERROR("failed to get hw_mdp: %d\n", rc); 1098 dpu_kms->hw_mdp = NULL; 1099 goto err_pm_put; 1100 } 1101 1102 for (i = 0; i < dpu_kms->catalog->vbif_count; i++) { 1103 struct dpu_hw_vbif *hw; 1104 const struct dpu_vbif_cfg *vbif = &dpu_kms->catalog->vbif[i]; 1105 1106 hw = dpu_hw_vbif_init(dev, vbif, dpu_kms->vbif[vbif->id]); 1107 if (IS_ERR(hw)) { 1108 rc = PTR_ERR(hw); 1109 DPU_ERROR("failed to init vbif %d: %d\n", vbif->id, rc); 1110 goto err_pm_put; 1111 } 1112 1113 dpu_kms->hw_vbif[vbif->id] = hw; 1114 } 1115 1116 /* TODO: use the same max_freq as in dpu_kms_hw_init */ 1117 max_core_clk_rate = dpu_kms_get_clk_rate(dpu_kms, "core"); 1118 if (!max_core_clk_rate) { 1119 DPU_DEBUG("max core clk rate not determined, using default\n"); 1120 max_core_clk_rate = DPU_PERF_DEFAULT_MAX_CORE_CLK_RATE; 1121 } 1122 1123 rc = dpu_core_perf_init(&dpu_kms->perf, dpu_kms->catalog->perf, max_core_clk_rate); 1124 if (rc) { 1125 DPU_ERROR("failed to init perf %d\n", rc); 1126 goto err_pm_put; 1127 } 1128 1129 dpu_kms->hw_intr = dpu_hw_intr_init(dev, dpu_kms->mmio, dpu_kms->catalog); 1130 if (IS_ERR(dpu_kms->hw_intr)) { 1131 rc = PTR_ERR(dpu_kms->hw_intr); 1132 DPU_ERROR("hw_intr init failed: %d\n", rc); 1133 dpu_kms->hw_intr = NULL; 1134 goto err_pm_put; 1135 } 1136 1137 dev->mode_config.min_width = 0; 1138 dev->mode_config.min_height = 0; 1139 1140 /* 1141 * max crtc width is equal to the max mixer width * 2 and max height is 1142 * is 4K 1143 */ 1144 dev->mode_config.max_width = 1145 dpu_kms->catalog->caps->max_mixer_width * 2; 1146 dev->mode_config.max_height = 4096; 1147 1148 dev->max_vblank_count = 0xffffffff; 1149 /* Disable vblank irqs aggressively for power-saving */ 1150 dev->vblank_disable_immediate = true; 1151 1152 /* 1153 * _dpu_kms_drm_obj_init should create the DRM related objects 1154 * i.e. CRTCs, planes, encoders, connectors and so forth 1155 */ 1156 rc = _dpu_kms_drm_obj_init(dpu_kms); 1157 if (rc) { 1158 DPU_ERROR("modeset init failed: %d\n", rc); 1159 goto err_pm_put; 1160 } 1161 1162 dpu_vbif_init_memtypes(dpu_kms); 1163 1164 pm_runtime_put_sync(&dpu_kms->pdev->dev); 1165 1166 return 0; 1167 1168 err_pm_put: 1169 pm_runtime_put_sync(&dpu_kms->pdev->dev); 1170 error: 1171 _dpu_kms_hw_destroy(dpu_kms); 1172 1173 return rc; 1174 } 1175 1176 static int dpu_kms_init(struct drm_device *ddev) 1177 { 1178 struct msm_drm_private *priv = ddev->dev_private; 1179 struct device *dev = ddev->dev; 1180 struct platform_device *pdev = to_platform_device(dev); 1181 struct dpu_kms *dpu_kms = to_dpu_kms(priv->kms); 1182 struct dev_pm_opp *opp; 1183 int ret = 0; 1184 unsigned long max_freq = ULONG_MAX; 1185 1186 opp = dev_pm_opp_find_freq_floor(dev, &max_freq); 1187 if (!IS_ERR(opp)) 1188 dev_pm_opp_put(opp); 1189 1190 dev_pm_opp_set_rate(dev, max_freq); 1191 1192 ret = msm_kms_init(&dpu_kms->base, &kms_funcs); 1193 if (ret) { 1194 DPU_ERROR("failed to init kms, ret=%d\n", ret); 1195 return ret; 1196 } 1197 dpu_kms->dev = ddev; 1198 1199 pm_runtime_enable(&pdev->dev); 1200 dpu_kms->rpm_enabled = true; 1201 1202 return 0; 1203 } 1204 1205 static int dpu_kms_mmap_mdp5(struct dpu_kms *dpu_kms) 1206 { 1207 struct platform_device *pdev = dpu_kms->pdev; 1208 struct platform_device *mdss_dev; 1209 int ret; 1210 1211 if (!dev_is_platform(dpu_kms->pdev->dev.parent)) 1212 return -EINVAL; 1213 1214 mdss_dev = to_platform_device(dpu_kms->pdev->dev.parent); 1215 1216 dpu_kms->mmio = msm_ioremap(pdev, "mdp_phys"); 1217 if (IS_ERR(dpu_kms->mmio)) { 1218 ret = PTR_ERR(dpu_kms->mmio); 1219 DPU_ERROR("mdp register memory map failed: %d\n", ret); 1220 dpu_kms->mmio = NULL; 1221 return ret; 1222 } 1223 DRM_DEBUG("mapped dpu address space @%pK\n", dpu_kms->mmio); 1224 1225 dpu_kms->vbif[VBIF_RT] = msm_ioremap_mdss(mdss_dev, 1226 dpu_kms->pdev, 1227 "vbif_phys"); 1228 if (IS_ERR(dpu_kms->vbif[VBIF_RT])) { 1229 ret = PTR_ERR(dpu_kms->vbif[VBIF_RT]); 1230 DPU_ERROR("vbif register memory map failed: %d\n", ret); 1231 dpu_kms->vbif[VBIF_RT] = NULL; 1232 return ret; 1233 } 1234 1235 dpu_kms->vbif[VBIF_NRT] = msm_ioremap_mdss(mdss_dev, 1236 dpu_kms->pdev, 1237 "vbif_nrt_phys"); 1238 if (IS_ERR(dpu_kms->vbif[VBIF_NRT])) { 1239 dpu_kms->vbif[VBIF_NRT] = NULL; 1240 DPU_DEBUG("VBIF NRT is not defined"); 1241 } 1242 1243 return 0; 1244 } 1245 1246 static int dpu_kms_mmap_dpu(struct dpu_kms *dpu_kms) 1247 { 1248 struct platform_device *pdev = dpu_kms->pdev; 1249 int ret; 1250 1251 dpu_kms->mmio = msm_ioremap(pdev, "mdp"); 1252 if (IS_ERR(dpu_kms->mmio)) { 1253 ret = PTR_ERR(dpu_kms->mmio); 1254 DPU_ERROR("mdp register memory map failed: %d\n", ret); 1255 dpu_kms->mmio = NULL; 1256 return ret; 1257 } 1258 DRM_DEBUG("mapped dpu address space @%pK\n", dpu_kms->mmio); 1259 1260 dpu_kms->vbif[VBIF_RT] = msm_ioremap(pdev, "vbif"); 1261 if (IS_ERR(dpu_kms->vbif[VBIF_RT])) { 1262 ret = PTR_ERR(dpu_kms->vbif[VBIF_RT]); 1263 DPU_ERROR("vbif register memory map failed: %d\n", ret); 1264 dpu_kms->vbif[VBIF_RT] = NULL; 1265 return ret; 1266 } 1267 1268 dpu_kms->vbif[VBIF_NRT] = msm_ioremap_quiet(pdev, "vbif_nrt"); 1269 if (IS_ERR(dpu_kms->vbif[VBIF_NRT])) { 1270 dpu_kms->vbif[VBIF_NRT] = NULL; 1271 DPU_DEBUG("VBIF NRT is not defined"); 1272 } 1273 1274 return 0; 1275 } 1276 1277 static int dpu_dev_probe(struct platform_device *pdev) 1278 { 1279 struct device *dev = &pdev->dev; 1280 struct dpu_kms *dpu_kms; 1281 int irq; 1282 int ret = 0; 1283 1284 if (!msm_disp_drv_should_bind(&pdev->dev, true)) 1285 return -ENODEV; 1286 1287 dpu_kms = devm_kzalloc(dev, sizeof(*dpu_kms), GFP_KERNEL); 1288 if (!dpu_kms) 1289 return -ENOMEM; 1290 1291 dpu_kms->pdev = pdev; 1292 1293 ret = devm_pm_opp_set_clkname(dev, "core"); 1294 if (ret) 1295 return ret; 1296 /* OPP table is optional */ 1297 ret = devm_pm_opp_of_add_table(dev); 1298 if (ret && ret != -ENODEV) 1299 return dev_err_probe(dev, ret, "invalid OPP table in device tree\n"); 1300 1301 ret = devm_clk_bulk_get_all(&pdev->dev, &dpu_kms->clocks); 1302 if (ret < 0) 1303 return dev_err_probe(dev, ret, "failed to parse clocks\n"); 1304 1305 dpu_kms->num_clocks = ret; 1306 1307 irq = platform_get_irq(pdev, 0); 1308 if (irq < 0) 1309 return dev_err_probe(dev, irq, "failed to get irq\n"); 1310 1311 dpu_kms->base.irq = irq; 1312 1313 if (of_device_is_compatible(dpu_kms->pdev->dev.of_node, "qcom,mdp5")) 1314 ret = dpu_kms_mmap_mdp5(dpu_kms); 1315 else 1316 ret = dpu_kms_mmap_dpu(dpu_kms); 1317 if (ret) 1318 return ret; 1319 1320 ret = dpu_kms_parse_data_bus_icc_path(dpu_kms); 1321 if (ret) 1322 return ret; 1323 1324 return msm_drv_probe(&pdev->dev, dpu_kms_init, &dpu_kms->base); 1325 } 1326 1327 static void dpu_dev_remove(struct platform_device *pdev) 1328 { 1329 component_master_del(&pdev->dev, &msm_drm_ops); 1330 } 1331 1332 static int __maybe_unused dpu_runtime_suspend(struct device *dev) 1333 { 1334 int i; 1335 struct platform_device *pdev = to_platform_device(dev); 1336 struct msm_drm_private *priv = platform_get_drvdata(pdev); 1337 struct dpu_kms *dpu_kms = to_dpu_kms(priv->kms); 1338 1339 /* Drop the performance state vote */ 1340 dev_pm_opp_set_rate(dev, 0); 1341 clk_bulk_disable_unprepare(dpu_kms->num_clocks, dpu_kms->clocks); 1342 1343 for (i = 0; i < dpu_kms->num_paths; i++) 1344 icc_set_bw(dpu_kms->path[i], 0, 0); 1345 1346 return 0; 1347 } 1348 1349 static int __maybe_unused dpu_runtime_resume(struct device *dev) 1350 { 1351 int rc = -1; 1352 struct platform_device *pdev = to_platform_device(dev); 1353 struct msm_drm_private *priv = platform_get_drvdata(pdev); 1354 struct dpu_kms *dpu_kms = to_dpu_kms(priv->kms); 1355 struct drm_encoder *encoder; 1356 struct drm_device *ddev; 1357 1358 ddev = dpu_kms->dev; 1359 1360 rc = clk_bulk_prepare_enable(dpu_kms->num_clocks, dpu_kms->clocks); 1361 if (rc) { 1362 DPU_ERROR("clock enable failed rc:%d\n", rc); 1363 return rc; 1364 } 1365 1366 dpu_vbif_init_memtypes(dpu_kms); 1367 1368 drm_for_each_encoder(encoder, ddev) 1369 dpu_encoder_virt_runtime_resume(encoder); 1370 1371 return rc; 1372 } 1373 1374 static const struct dev_pm_ops dpu_pm_ops = { 1375 SET_RUNTIME_PM_OPS(dpu_runtime_suspend, dpu_runtime_resume, NULL) 1376 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 1377 pm_runtime_force_resume) 1378 .prepare = msm_kms_pm_prepare, 1379 .complete = msm_kms_pm_complete, 1380 }; 1381 1382 static const struct of_device_id dpu_dt_match[] = { 1383 { .compatible = "qcom,msm8998-dpu", .data = &dpu_msm8998_cfg, }, 1384 { .compatible = "qcom,qcm2290-dpu", .data = &dpu_qcm2290_cfg, }, 1385 { .compatible = "qcom,sdm630-mdp5", .data = &dpu_sdm630_cfg, }, 1386 { .compatible = "qcom,sdm660-mdp5", .data = &dpu_sdm660_cfg, }, 1387 { .compatible = "qcom,sdm670-dpu", .data = &dpu_sdm670_cfg, }, 1388 { .compatible = "qcom,sdm845-dpu", .data = &dpu_sdm845_cfg, }, 1389 { .compatible = "qcom,sc7180-dpu", .data = &dpu_sc7180_cfg, }, 1390 { .compatible = "qcom,sc7280-dpu", .data = &dpu_sc7280_cfg, }, 1391 { .compatible = "qcom,sc8180x-dpu", .data = &dpu_sc8180x_cfg, }, 1392 { .compatible = "qcom,sc8280xp-dpu", .data = &dpu_sc8280xp_cfg, }, 1393 { .compatible = "qcom,sm6115-dpu", .data = &dpu_sm6115_cfg, }, 1394 { .compatible = "qcom,sm6125-dpu", .data = &dpu_sm6125_cfg, }, 1395 { .compatible = "qcom,sm6350-dpu", .data = &dpu_sm6350_cfg, }, 1396 { .compatible = "qcom,sm6375-dpu", .data = &dpu_sm6375_cfg, }, 1397 { .compatible = "qcom,sm8150-dpu", .data = &dpu_sm8150_cfg, }, 1398 { .compatible = "qcom,sm8250-dpu", .data = &dpu_sm8250_cfg, }, 1399 { .compatible = "qcom,sm8350-dpu", .data = &dpu_sm8350_cfg, }, 1400 { .compatible = "qcom,sm8450-dpu", .data = &dpu_sm8450_cfg, }, 1401 { .compatible = "qcom,sm8550-dpu", .data = &dpu_sm8550_cfg, }, 1402 { .compatible = "qcom,sm8650-dpu", .data = &dpu_sm8650_cfg, }, 1403 { .compatible = "qcom,x1e80100-dpu", .data = &dpu_x1e80100_cfg, }, 1404 {} 1405 }; 1406 MODULE_DEVICE_TABLE(of, dpu_dt_match); 1407 1408 static struct platform_driver dpu_driver = { 1409 .probe = dpu_dev_probe, 1410 .remove_new = dpu_dev_remove, 1411 .shutdown = msm_kms_shutdown, 1412 .driver = { 1413 .name = "msm_dpu", 1414 .of_match_table = dpu_dt_match, 1415 .pm = &dpu_pm_ops, 1416 }, 1417 }; 1418 1419 void __init msm_dpu_register(void) 1420 { 1421 platform_driver_register(&dpu_driver); 1422 } 1423 1424 void __exit msm_dpu_unregister(void) 1425 { 1426 platform_driver_unregister(&dpu_driver); 1427 } 1428