1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (c) 2015, The Linux Foundation. All rights reserved. 4 */ 5 6 #include "drm/drm_bridge_connector.h" 7 8 #include "msm_kms.h" 9 #include "dsi.h" 10 11 #define DSI_CLOCK_MASTER DSI_0 12 #define DSI_CLOCK_SLAVE DSI_1 13 14 #define DSI_LEFT DSI_0 15 #define DSI_RIGHT DSI_1 16 17 /* According to the current drm framework sequence, take the encoder of 18 * DSI_1 as master encoder 19 */ 20 #define DSI_ENCODER_MASTER DSI_1 21 #define DSI_ENCODER_SLAVE DSI_0 22 23 struct msm_dsi_manager { 24 struct msm_dsi *dsi[DSI_MAX]; 25 26 bool is_bonded_dsi; 27 bool is_sync_needed; 28 int master_dsi_link_id; 29 }; 30 31 static struct msm_dsi_manager msm_dsim_glb; 32 33 #define IS_BONDED_DSI() (msm_dsim_glb.is_bonded_dsi) 34 #define IS_SYNC_NEEDED() (msm_dsim_glb.is_sync_needed) 35 #define IS_MASTER_DSI_LINK(id) (msm_dsim_glb.master_dsi_link_id == id) 36 37 #ifdef CONFIG_OF 38 static bool dsi_mgr_power_on_early(struct drm_bridge *bridge) 39 { 40 struct drm_bridge *next_bridge = drm_bridge_get_next_bridge(bridge); 41 42 /* 43 * If the next bridge in the chain is the Parade ps8640 bridge chip 44 * then don't power on early since it seems to violate the expectations 45 * of the firmware that the bridge chip is running. 46 * 47 * NOTE: this is expected to be a temporary special case. It's expected 48 * that we'll eventually have a framework that allows the next level 49 * bridge to indicate whether it needs us to power on before it or 50 * after it. When that framework is in place then we'll use it and 51 * remove this special case. 52 */ 53 return !(next_bridge && next_bridge->of_node && 54 of_device_is_compatible(next_bridge->of_node, "parade,ps8640")); 55 } 56 #else 57 static inline bool dsi_mgr_power_on_early(struct drm_bridge *bridge) 58 { 59 return true; 60 } 61 #endif 62 63 static inline struct msm_dsi *dsi_mgr_get_dsi(int id) 64 { 65 return msm_dsim_glb.dsi[id]; 66 } 67 68 static inline struct msm_dsi *dsi_mgr_get_other_dsi(int id) 69 { 70 return msm_dsim_glb.dsi[(id + 1) % DSI_MAX]; 71 } 72 73 static int dsi_mgr_parse_of(struct device_node *np, int id) 74 { 75 struct msm_dsi_manager *msm_dsim = &msm_dsim_glb; 76 77 /* We assume 2 dsi nodes have the same information of bonded dsi and 78 * sync-mode, and only one node specifies master in case of bonded mode. 79 */ 80 if (!msm_dsim->is_bonded_dsi) 81 msm_dsim->is_bonded_dsi = of_property_read_bool(np, "qcom,dual-dsi-mode"); 82 83 if (msm_dsim->is_bonded_dsi) { 84 if (of_property_read_bool(np, "qcom,master-dsi")) 85 msm_dsim->master_dsi_link_id = id; 86 if (!msm_dsim->is_sync_needed) 87 msm_dsim->is_sync_needed = of_property_read_bool( 88 np, "qcom,sync-dual-dsi"); 89 } 90 91 return 0; 92 } 93 94 static int dsi_mgr_setup_components(int id) 95 { 96 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 97 struct msm_dsi *other_dsi = dsi_mgr_get_other_dsi(id); 98 struct msm_dsi *clk_master_dsi = dsi_mgr_get_dsi(DSI_CLOCK_MASTER); 99 struct msm_dsi *clk_slave_dsi = dsi_mgr_get_dsi(DSI_CLOCK_SLAVE); 100 int ret; 101 102 if (!IS_BONDED_DSI()) { 103 ret = msm_dsi_host_register(msm_dsi->host); 104 if (ret) 105 return ret; 106 107 msm_dsi_phy_set_usecase(msm_dsi->phy, MSM_DSI_PHY_STANDALONE); 108 msm_dsi_host_set_phy_mode(msm_dsi->host, msm_dsi->phy); 109 } else if (other_dsi) { 110 struct msm_dsi *master_link_dsi = IS_MASTER_DSI_LINK(id) ? 111 msm_dsi : other_dsi; 112 struct msm_dsi *slave_link_dsi = IS_MASTER_DSI_LINK(id) ? 113 other_dsi : msm_dsi; 114 /* Register slave host first, so that slave DSI device 115 * has a chance to probe, and do not block the master 116 * DSI device's probe. 117 * Also, do not check defer for the slave host, 118 * because only master DSI device adds the panel to global 119 * panel list. The panel's device is the master DSI device. 120 */ 121 ret = msm_dsi_host_register(slave_link_dsi->host); 122 if (ret) 123 return ret; 124 ret = msm_dsi_host_register(master_link_dsi->host); 125 if (ret) 126 return ret; 127 128 /* PLL0 is to drive both 2 DSI link clocks in bonded DSI mode. */ 129 msm_dsi_phy_set_usecase(clk_master_dsi->phy, 130 MSM_DSI_PHY_MASTER); 131 msm_dsi_phy_set_usecase(clk_slave_dsi->phy, 132 MSM_DSI_PHY_SLAVE); 133 msm_dsi_host_set_phy_mode(msm_dsi->host, msm_dsi->phy); 134 msm_dsi_host_set_phy_mode(other_dsi->host, other_dsi->phy); 135 } 136 137 return 0; 138 } 139 140 static int enable_phy(struct msm_dsi *msm_dsi, 141 struct msm_dsi_phy_shared_timings *shared_timings) 142 { 143 struct msm_dsi_phy_clk_request clk_req; 144 bool is_bonded_dsi = IS_BONDED_DSI(); 145 146 msm_dsi_host_get_phy_clk_req(msm_dsi->host, &clk_req, is_bonded_dsi); 147 148 return msm_dsi_phy_enable(msm_dsi->phy, &clk_req, shared_timings); 149 } 150 151 static int 152 dsi_mgr_phy_enable(int id, 153 struct msm_dsi_phy_shared_timings shared_timings[DSI_MAX]) 154 { 155 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 156 struct msm_dsi *mdsi = dsi_mgr_get_dsi(DSI_CLOCK_MASTER); 157 struct msm_dsi *sdsi = dsi_mgr_get_dsi(DSI_CLOCK_SLAVE); 158 int ret; 159 160 /* In case of bonded DSI, some registers in PHY1 have been programmed 161 * during PLL0 clock's set_rate. The PHY1 reset called by host1 here 162 * will silently reset those PHY1 registers. Therefore we need to reset 163 * and enable both PHYs before any PLL clock operation. 164 */ 165 if (IS_BONDED_DSI() && mdsi && sdsi) { 166 if (!mdsi->phy_enabled && !sdsi->phy_enabled) { 167 msm_dsi_host_reset_phy(mdsi->host); 168 msm_dsi_host_reset_phy(sdsi->host); 169 170 ret = enable_phy(mdsi, 171 &shared_timings[DSI_CLOCK_MASTER]); 172 if (ret) 173 return ret; 174 ret = enable_phy(sdsi, 175 &shared_timings[DSI_CLOCK_SLAVE]); 176 if (ret) { 177 msm_dsi_phy_disable(mdsi->phy); 178 return ret; 179 } 180 } 181 } else { 182 msm_dsi_host_reset_phy(msm_dsi->host); 183 ret = enable_phy(msm_dsi, &shared_timings[id]); 184 if (ret) 185 return ret; 186 } 187 188 msm_dsi->phy_enabled = true; 189 190 return 0; 191 } 192 193 static void dsi_mgr_phy_disable(int id) 194 { 195 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 196 struct msm_dsi *mdsi = dsi_mgr_get_dsi(DSI_CLOCK_MASTER); 197 struct msm_dsi *sdsi = dsi_mgr_get_dsi(DSI_CLOCK_SLAVE); 198 199 /* disable DSI phy 200 * In bonded dsi configuration, the phy should be disabled for the 201 * first controller only when the second controller is disabled. 202 */ 203 msm_dsi->phy_enabled = false; 204 if (IS_BONDED_DSI() && mdsi && sdsi) { 205 if (!mdsi->phy_enabled && !sdsi->phy_enabled) { 206 msm_dsi_phy_disable(sdsi->phy); 207 msm_dsi_phy_disable(mdsi->phy); 208 } 209 } else { 210 msm_dsi_phy_disable(msm_dsi->phy); 211 } 212 } 213 214 struct dsi_connector { 215 struct drm_connector base; 216 int id; 217 }; 218 219 struct dsi_bridge { 220 struct drm_bridge base; 221 int id; 222 }; 223 224 #define to_dsi_connector(x) container_of(x, struct dsi_connector, base) 225 #define to_dsi_bridge(x) container_of(x, struct dsi_bridge, base) 226 227 static inline int dsi_mgr_connector_get_id(struct drm_connector *connector) 228 { 229 struct dsi_connector *dsi_connector = to_dsi_connector(connector); 230 return dsi_connector->id; 231 } 232 233 static int dsi_mgr_bridge_get_id(struct drm_bridge *bridge) 234 { 235 struct dsi_bridge *dsi_bridge = to_dsi_bridge(bridge); 236 return dsi_bridge->id; 237 } 238 239 static int msm_dsi_manager_panel_init(struct drm_connector *conn, u8 id) 240 { 241 struct msm_drm_private *priv = conn->dev->dev_private; 242 struct msm_kms *kms = priv->kms; 243 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 244 struct msm_dsi *other_dsi = dsi_mgr_get_other_dsi(id); 245 struct msm_dsi *master_dsi, *slave_dsi; 246 struct drm_panel *panel; 247 248 if (IS_BONDED_DSI() && !IS_MASTER_DSI_LINK(id)) { 249 master_dsi = other_dsi; 250 slave_dsi = msm_dsi; 251 } else { 252 master_dsi = msm_dsi; 253 slave_dsi = other_dsi; 254 } 255 256 /* 257 * There is only 1 panel in the global panel list for bonded DSI mode. 258 * Therefore slave dsi should get the drm_panel instance from master 259 * dsi. 260 */ 261 panel = msm_dsi_host_get_panel(master_dsi->host); 262 if (IS_ERR(panel)) { 263 DRM_ERROR("Could not find panel for %u (%ld)\n", msm_dsi->id, 264 PTR_ERR(panel)); 265 return PTR_ERR(panel); 266 } 267 268 if (!panel || !IS_BONDED_DSI()) 269 goto out; 270 271 drm_object_attach_property(&conn->base, 272 conn->dev->mode_config.tile_property, 0); 273 274 /* 275 * Set split display info to kms once bonded DSI panel is connected to 276 * both hosts. 277 */ 278 if (other_dsi && other_dsi->panel && kms->funcs->set_split_display) { 279 kms->funcs->set_split_display(kms, master_dsi->encoder, 280 slave_dsi->encoder, 281 msm_dsi_is_cmd_mode(msm_dsi)); 282 } 283 284 out: 285 msm_dsi->panel = panel; 286 return 0; 287 } 288 289 static enum drm_connector_status dsi_mgr_connector_detect( 290 struct drm_connector *connector, bool force) 291 { 292 int id = dsi_mgr_connector_get_id(connector); 293 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 294 295 return msm_dsi->panel ? connector_status_connected : 296 connector_status_disconnected; 297 } 298 299 static void dsi_mgr_connector_destroy(struct drm_connector *connector) 300 { 301 struct dsi_connector *dsi_connector = to_dsi_connector(connector); 302 303 DBG(""); 304 305 drm_connector_cleanup(connector); 306 307 kfree(dsi_connector); 308 } 309 310 static int dsi_mgr_connector_get_modes(struct drm_connector *connector) 311 { 312 int id = dsi_mgr_connector_get_id(connector); 313 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 314 struct drm_panel *panel = msm_dsi->panel; 315 int num; 316 317 if (!panel) 318 return 0; 319 320 /* 321 * In bonded DSI mode, we have one connector that can be 322 * attached to the drm_panel. 323 */ 324 num = drm_panel_get_modes(panel, connector); 325 if (!num) 326 return 0; 327 328 return num; 329 } 330 331 static struct drm_encoder * 332 dsi_mgr_connector_best_encoder(struct drm_connector *connector) 333 { 334 int id = dsi_mgr_connector_get_id(connector); 335 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 336 337 DBG(""); 338 return msm_dsi_get_encoder(msm_dsi); 339 } 340 341 static void dsi_mgr_bridge_power_on(struct drm_bridge *bridge) 342 { 343 int id = dsi_mgr_bridge_get_id(bridge); 344 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 345 struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1); 346 struct mipi_dsi_host *host = msm_dsi->host; 347 struct msm_dsi_phy_shared_timings phy_shared_timings[DSI_MAX]; 348 bool is_bonded_dsi = IS_BONDED_DSI(); 349 int ret; 350 351 DBG("id=%d", id); 352 if (!msm_dsi_device_connected(msm_dsi)) 353 return; 354 355 /* Do nothing with the host if it is slave-DSI in case of bonded DSI */ 356 if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id)) 357 return; 358 359 ret = dsi_mgr_phy_enable(id, phy_shared_timings); 360 if (ret) 361 goto phy_en_fail; 362 363 ret = msm_dsi_host_power_on(host, &phy_shared_timings[id], is_bonded_dsi, msm_dsi->phy); 364 if (ret) { 365 pr_err("%s: power on host %d failed, %d\n", __func__, id, ret); 366 goto host_on_fail; 367 } 368 369 if (is_bonded_dsi && msm_dsi1) { 370 ret = msm_dsi_host_power_on(msm_dsi1->host, 371 &phy_shared_timings[DSI_1], is_bonded_dsi, msm_dsi1->phy); 372 if (ret) { 373 pr_err("%s: power on host1 failed, %d\n", 374 __func__, ret); 375 goto host1_on_fail; 376 } 377 } 378 379 /* 380 * Enable before preparing the panel, disable after unpreparing, so 381 * that the panel can communicate over the DSI link. 382 */ 383 msm_dsi_host_enable_irq(host); 384 if (is_bonded_dsi && msm_dsi1) 385 msm_dsi_host_enable_irq(msm_dsi1->host); 386 387 return; 388 389 host1_on_fail: 390 msm_dsi_host_power_off(host); 391 host_on_fail: 392 dsi_mgr_phy_disable(id); 393 phy_en_fail: 394 return; 395 } 396 397 static void dsi_mgr_bridge_pre_enable(struct drm_bridge *bridge) 398 { 399 int id = dsi_mgr_bridge_get_id(bridge); 400 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 401 struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1); 402 struct mipi_dsi_host *host = msm_dsi->host; 403 struct drm_panel *panel = msm_dsi->panel; 404 bool is_bonded_dsi = IS_BONDED_DSI(); 405 int ret; 406 407 DBG("id=%d", id); 408 if (!msm_dsi_device_connected(msm_dsi)) 409 return; 410 411 /* Do nothing with the host if it is slave-DSI in case of bonded DSI */ 412 if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id)) 413 return; 414 415 if (!dsi_mgr_power_on_early(bridge)) 416 dsi_mgr_bridge_power_on(bridge); 417 418 /* Always call panel functions once, because even for dual panels, 419 * there is only one drm_panel instance. 420 */ 421 if (panel) { 422 ret = drm_panel_prepare(panel); 423 if (ret) { 424 pr_err("%s: prepare panel %d failed, %d\n", __func__, 425 id, ret); 426 goto panel_prep_fail; 427 } 428 } 429 430 ret = msm_dsi_host_enable(host); 431 if (ret) { 432 pr_err("%s: enable host %d failed, %d\n", __func__, id, ret); 433 goto host_en_fail; 434 } 435 436 if (is_bonded_dsi && msm_dsi1) { 437 ret = msm_dsi_host_enable(msm_dsi1->host); 438 if (ret) { 439 pr_err("%s: enable host1 failed, %d\n", __func__, ret); 440 goto host1_en_fail; 441 } 442 } 443 444 return; 445 446 host1_en_fail: 447 msm_dsi_host_disable(host); 448 host_en_fail: 449 if (panel) 450 drm_panel_unprepare(panel); 451 panel_prep_fail: 452 453 return; 454 } 455 456 void msm_dsi_manager_tpg_enable(void) 457 { 458 struct msm_dsi *m_dsi = dsi_mgr_get_dsi(DSI_0); 459 struct msm_dsi *s_dsi = dsi_mgr_get_dsi(DSI_1); 460 461 /* if dual dsi, trigger tpg on master first then slave */ 462 if (m_dsi) { 463 msm_dsi_host_test_pattern_en(m_dsi->host); 464 if (IS_BONDED_DSI() && s_dsi) 465 msm_dsi_host_test_pattern_en(s_dsi->host); 466 } 467 } 468 469 static void dsi_mgr_bridge_enable(struct drm_bridge *bridge) 470 { 471 int id = dsi_mgr_bridge_get_id(bridge); 472 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 473 struct drm_panel *panel = msm_dsi->panel; 474 bool is_bonded_dsi = IS_BONDED_DSI(); 475 int ret; 476 477 DBG("id=%d", id); 478 if (!msm_dsi_device_connected(msm_dsi)) 479 return; 480 481 /* Do nothing with the host if it is slave-DSI in case of bonded DSI */ 482 if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id)) 483 return; 484 485 if (panel) { 486 ret = drm_panel_enable(panel); 487 if (ret) { 488 pr_err("%s: enable panel %d failed, %d\n", __func__, id, 489 ret); 490 } 491 } 492 } 493 494 static void dsi_mgr_bridge_disable(struct drm_bridge *bridge) 495 { 496 int id = dsi_mgr_bridge_get_id(bridge); 497 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 498 struct drm_panel *panel = msm_dsi->panel; 499 bool is_bonded_dsi = IS_BONDED_DSI(); 500 int ret; 501 502 DBG("id=%d", id); 503 if (!msm_dsi_device_connected(msm_dsi)) 504 return; 505 506 /* Do nothing with the host if it is slave-DSI in case of bonded DSI */ 507 if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id)) 508 return; 509 510 if (panel) { 511 ret = drm_panel_disable(panel); 512 if (ret) 513 pr_err("%s: Panel %d OFF failed, %d\n", __func__, id, 514 ret); 515 } 516 } 517 518 static void dsi_mgr_bridge_post_disable(struct drm_bridge *bridge) 519 { 520 int id = dsi_mgr_bridge_get_id(bridge); 521 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 522 struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1); 523 struct mipi_dsi_host *host = msm_dsi->host; 524 struct drm_panel *panel = msm_dsi->panel; 525 bool is_bonded_dsi = IS_BONDED_DSI(); 526 int ret; 527 528 DBG("id=%d", id); 529 530 if (!msm_dsi_device_connected(msm_dsi)) 531 return; 532 533 /* 534 * Do nothing with the host if it is slave-DSI in case of bonded DSI. 535 * It is safe to call dsi_mgr_phy_disable() here because a single PHY 536 * won't be diabled until both PHYs request disable. 537 */ 538 if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id)) 539 goto disable_phy; 540 541 ret = msm_dsi_host_disable(host); 542 if (ret) 543 pr_err("%s: host %d disable failed, %d\n", __func__, id, ret); 544 545 if (is_bonded_dsi && msm_dsi1) { 546 ret = msm_dsi_host_disable(msm_dsi1->host); 547 if (ret) 548 pr_err("%s: host1 disable failed, %d\n", __func__, ret); 549 } 550 551 if (panel) { 552 ret = drm_panel_unprepare(panel); 553 if (ret) 554 pr_err("%s: Panel %d unprepare failed,%d\n", __func__, 555 id, ret); 556 } 557 558 msm_dsi_host_disable_irq(host); 559 if (is_bonded_dsi && msm_dsi1) 560 msm_dsi_host_disable_irq(msm_dsi1->host); 561 562 /* Save PHY status if it is a clock source */ 563 msm_dsi_phy_pll_save_state(msm_dsi->phy); 564 565 ret = msm_dsi_host_power_off(host); 566 if (ret) 567 pr_err("%s: host %d power off failed,%d\n", __func__, id, ret); 568 569 if (is_bonded_dsi && msm_dsi1) { 570 ret = msm_dsi_host_power_off(msm_dsi1->host); 571 if (ret) 572 pr_err("%s: host1 power off failed, %d\n", 573 __func__, ret); 574 } 575 576 disable_phy: 577 dsi_mgr_phy_disable(id); 578 } 579 580 static void dsi_mgr_bridge_mode_set(struct drm_bridge *bridge, 581 const struct drm_display_mode *mode, 582 const struct drm_display_mode *adjusted_mode) 583 { 584 int id = dsi_mgr_bridge_get_id(bridge); 585 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 586 struct msm_dsi *other_dsi = dsi_mgr_get_other_dsi(id); 587 struct mipi_dsi_host *host = msm_dsi->host; 588 bool is_bonded_dsi = IS_BONDED_DSI(); 589 590 DBG("set mode: " DRM_MODE_FMT, DRM_MODE_ARG(mode)); 591 592 if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id)) 593 return; 594 595 msm_dsi_host_set_display_mode(host, adjusted_mode); 596 if (is_bonded_dsi && other_dsi) 597 msm_dsi_host_set_display_mode(other_dsi->host, adjusted_mode); 598 599 if (dsi_mgr_power_on_early(bridge)) 600 dsi_mgr_bridge_power_on(bridge); 601 } 602 603 static enum drm_mode_status dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge, 604 const struct drm_display_info *info, 605 const struct drm_display_mode *mode) 606 { 607 int id = dsi_mgr_bridge_get_id(bridge); 608 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 609 struct mipi_dsi_host *host = msm_dsi->host; 610 611 return msm_dsi_host_check_dsc(host, mode); 612 } 613 614 static const struct drm_connector_funcs dsi_mgr_connector_funcs = { 615 .detect = dsi_mgr_connector_detect, 616 .fill_modes = drm_helper_probe_single_connector_modes, 617 .destroy = dsi_mgr_connector_destroy, 618 .reset = drm_atomic_helper_connector_reset, 619 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 620 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 621 }; 622 623 static const struct drm_connector_helper_funcs dsi_mgr_conn_helper_funcs = { 624 .get_modes = dsi_mgr_connector_get_modes, 625 .best_encoder = dsi_mgr_connector_best_encoder, 626 }; 627 628 static const struct drm_bridge_funcs dsi_mgr_bridge_funcs = { 629 .pre_enable = dsi_mgr_bridge_pre_enable, 630 .enable = dsi_mgr_bridge_enable, 631 .disable = dsi_mgr_bridge_disable, 632 .post_disable = dsi_mgr_bridge_post_disable, 633 .mode_set = dsi_mgr_bridge_mode_set, 634 .mode_valid = dsi_mgr_bridge_mode_valid, 635 }; 636 637 /* initialize connector when we're connected to a drm_panel */ 638 struct drm_connector *msm_dsi_manager_connector_init(u8 id) 639 { 640 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 641 struct drm_connector *connector = NULL; 642 struct dsi_connector *dsi_connector; 643 int ret; 644 645 dsi_connector = kzalloc(sizeof(*dsi_connector), GFP_KERNEL); 646 if (!dsi_connector) 647 return ERR_PTR(-ENOMEM); 648 649 dsi_connector->id = id; 650 651 connector = &dsi_connector->base; 652 653 ret = drm_connector_init(msm_dsi->dev, connector, 654 &dsi_mgr_connector_funcs, DRM_MODE_CONNECTOR_DSI); 655 if (ret) 656 return ERR_PTR(ret); 657 658 drm_connector_helper_add(connector, &dsi_mgr_conn_helper_funcs); 659 660 /* Enable HPD to let hpd event is handled 661 * when panel is attached to the host. 662 */ 663 connector->polled = DRM_CONNECTOR_POLL_HPD; 664 665 /* Display driver doesn't support interlace now. */ 666 connector->interlace_allowed = 0; 667 connector->doublescan_allowed = 0; 668 669 drm_connector_attach_encoder(connector, msm_dsi->encoder); 670 671 ret = msm_dsi_manager_panel_init(connector, id); 672 if (ret) { 673 DRM_DEV_ERROR(msm_dsi->dev->dev, "init panel failed %d\n", ret); 674 goto fail; 675 } 676 677 return connector; 678 679 fail: 680 connector->funcs->destroy(connector); 681 return ERR_PTR(ret); 682 } 683 684 /* initialize bridge */ 685 struct drm_bridge *msm_dsi_manager_bridge_init(u8 id) 686 { 687 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 688 struct drm_bridge *bridge = NULL; 689 struct dsi_bridge *dsi_bridge; 690 struct drm_encoder *encoder; 691 int ret; 692 693 dsi_bridge = devm_kzalloc(msm_dsi->dev->dev, 694 sizeof(*dsi_bridge), GFP_KERNEL); 695 if (!dsi_bridge) { 696 ret = -ENOMEM; 697 goto fail; 698 } 699 700 dsi_bridge->id = id; 701 702 encoder = msm_dsi->encoder; 703 704 bridge = &dsi_bridge->base; 705 bridge->funcs = &dsi_mgr_bridge_funcs; 706 707 drm_bridge_add(bridge); 708 709 ret = drm_bridge_attach(encoder, bridge, NULL, 0); 710 if (ret) 711 goto fail; 712 713 return bridge; 714 715 fail: 716 if (bridge) 717 msm_dsi_manager_bridge_destroy(bridge); 718 719 return ERR_PTR(ret); 720 } 721 722 struct drm_connector *msm_dsi_manager_ext_bridge_init(u8 id) 723 { 724 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 725 struct drm_device *dev = msm_dsi->dev; 726 struct drm_connector *connector; 727 struct drm_encoder *encoder; 728 struct drm_bridge *int_bridge, *ext_bridge; 729 int ret; 730 731 int_bridge = msm_dsi->bridge; 732 ext_bridge = msm_dsi->external_bridge = 733 msm_dsi_host_get_bridge(msm_dsi->host); 734 735 encoder = msm_dsi->encoder; 736 737 /* 738 * Try first to create the bridge without it creating its own 739 * connector.. currently some bridges support this, and others 740 * do not (and some support both modes) 741 */ 742 ret = drm_bridge_attach(encoder, ext_bridge, int_bridge, 743 DRM_BRIDGE_ATTACH_NO_CONNECTOR); 744 if (ret == -EINVAL) { 745 struct drm_connector *connector; 746 struct list_head *connector_list; 747 748 /* link the internal dsi bridge to the external bridge */ 749 drm_bridge_attach(encoder, ext_bridge, int_bridge, 0); 750 751 /* 752 * we need the drm_connector created by the external bridge 753 * driver (or someone else) to feed it to our driver's 754 * priv->connector[] list, mainly for msm_fbdev_init() 755 */ 756 connector_list = &dev->mode_config.connector_list; 757 758 list_for_each_entry(connector, connector_list, head) { 759 if (drm_connector_has_possible_encoder(connector, encoder)) 760 return connector; 761 } 762 763 return ERR_PTR(-ENODEV); 764 } 765 766 connector = drm_bridge_connector_init(dev, encoder); 767 if (IS_ERR(connector)) { 768 DRM_ERROR("Unable to create bridge connector\n"); 769 return ERR_CAST(connector); 770 } 771 772 drm_connector_attach_encoder(connector, encoder); 773 774 return connector; 775 } 776 777 void msm_dsi_manager_bridge_destroy(struct drm_bridge *bridge) 778 { 779 drm_bridge_remove(bridge); 780 } 781 782 int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg) 783 { 784 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 785 struct msm_dsi *msm_dsi0 = dsi_mgr_get_dsi(DSI_0); 786 struct mipi_dsi_host *host = msm_dsi->host; 787 bool is_read = (msg->rx_buf && msg->rx_len); 788 bool need_sync = (IS_SYNC_NEEDED() && !is_read); 789 int ret; 790 791 if (!msg->tx_buf || !msg->tx_len) 792 return 0; 793 794 /* In bonded master case, panel requires the same commands sent to 795 * both DSI links. Host issues the command trigger to both links 796 * when DSI_1 calls the cmd transfer function, no matter it happens 797 * before or after DSI_0 cmd transfer. 798 */ 799 if (need_sync && (id == DSI_0)) 800 return is_read ? msg->rx_len : msg->tx_len; 801 802 if (need_sync && msm_dsi0) { 803 ret = msm_dsi_host_xfer_prepare(msm_dsi0->host, msg); 804 if (ret) { 805 pr_err("%s: failed to prepare non-trigger host, %d\n", 806 __func__, ret); 807 return ret; 808 } 809 } 810 ret = msm_dsi_host_xfer_prepare(host, msg); 811 if (ret) { 812 pr_err("%s: failed to prepare host, %d\n", __func__, ret); 813 goto restore_host0; 814 } 815 816 ret = is_read ? msm_dsi_host_cmd_rx(host, msg) : 817 msm_dsi_host_cmd_tx(host, msg); 818 819 msm_dsi_host_xfer_restore(host, msg); 820 821 restore_host0: 822 if (need_sync && msm_dsi0) 823 msm_dsi_host_xfer_restore(msm_dsi0->host, msg); 824 825 return ret; 826 } 827 828 bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len) 829 { 830 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 831 struct msm_dsi *msm_dsi0 = dsi_mgr_get_dsi(DSI_0); 832 struct mipi_dsi_host *host = msm_dsi->host; 833 834 if (IS_SYNC_NEEDED() && (id == DSI_0)) 835 return false; 836 837 if (IS_SYNC_NEEDED() && msm_dsi0) 838 msm_dsi_host_cmd_xfer_commit(msm_dsi0->host, dma_base, len); 839 840 msm_dsi_host_cmd_xfer_commit(host, dma_base, len); 841 842 return true; 843 } 844 845 int msm_dsi_manager_register(struct msm_dsi *msm_dsi) 846 { 847 struct msm_dsi_manager *msm_dsim = &msm_dsim_glb; 848 int id = msm_dsi->id; 849 int ret; 850 851 if (id >= DSI_MAX) { 852 pr_err("%s: invalid id %d\n", __func__, id); 853 return -EINVAL; 854 } 855 856 if (msm_dsim->dsi[id]) { 857 pr_err("%s: dsi%d already registered\n", __func__, id); 858 return -EBUSY; 859 } 860 861 msm_dsim->dsi[id] = msm_dsi; 862 863 ret = dsi_mgr_parse_of(msm_dsi->pdev->dev.of_node, id); 864 if (ret) { 865 pr_err("%s: failed to parse OF DSI info\n", __func__); 866 goto fail; 867 } 868 869 ret = dsi_mgr_setup_components(id); 870 if (ret) { 871 pr_err("%s: failed to register mipi dsi host for DSI %d: %d\n", 872 __func__, id, ret); 873 goto fail; 874 } 875 876 return 0; 877 878 fail: 879 msm_dsim->dsi[id] = NULL; 880 return ret; 881 } 882 883 void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi) 884 { 885 struct msm_dsi_manager *msm_dsim = &msm_dsim_glb; 886 887 if (msm_dsi->host) 888 msm_dsi_host_unregister(msm_dsi->host); 889 890 if (msm_dsi->id >= 0) 891 msm_dsim->dsi[msm_dsi->id] = NULL; 892 } 893 894 bool msm_dsi_is_bonded_dsi(struct msm_dsi *msm_dsi) 895 { 896 return IS_BONDED_DSI(); 897 } 898 899 bool msm_dsi_is_master_dsi(struct msm_dsi *msm_dsi) 900 { 901 return IS_MASTER_DSI_LINK(msm_dsi->id); 902 } 903