0001
0002
0003
0004
0005
0006 #include "drm/drm_bridge_connector.h"
0007
0008 #include "msm_kms.h"
0009 #include "dsi.h"
0010
0011 #define DSI_CLOCK_MASTER DSI_0
0012 #define DSI_CLOCK_SLAVE DSI_1
0013
0014 #define DSI_LEFT DSI_0
0015 #define DSI_RIGHT DSI_1
0016
0017
0018
0019
0020 #define DSI_ENCODER_MASTER DSI_1
0021 #define DSI_ENCODER_SLAVE DSI_0
0022
0023 struct msm_dsi_manager {
0024 struct msm_dsi *dsi[DSI_MAX];
0025
0026 bool is_bonded_dsi;
0027 bool is_sync_needed;
0028 int master_dsi_link_id;
0029 };
0030
0031 static struct msm_dsi_manager msm_dsim_glb;
0032
0033 #define IS_BONDED_DSI() (msm_dsim_glb.is_bonded_dsi)
0034 #define IS_SYNC_NEEDED() (msm_dsim_glb.is_sync_needed)
0035 #define IS_MASTER_DSI_LINK(id) (msm_dsim_glb.master_dsi_link_id == id)
0036
0037 #ifdef CONFIG_OF
0038 static bool dsi_mgr_power_on_early(struct drm_bridge *bridge)
0039 {
0040 struct drm_bridge *next_bridge = drm_bridge_get_next_bridge(bridge);
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 return !(next_bridge && next_bridge->of_node &&
0054 of_device_is_compatible(next_bridge->of_node, "parade,ps8640"));
0055 }
0056 #else
0057 static inline bool dsi_mgr_power_on_early(struct drm_bridge *bridge)
0058 {
0059 return true;
0060 }
0061 #endif
0062
0063 static inline struct msm_dsi *dsi_mgr_get_dsi(int id)
0064 {
0065 return msm_dsim_glb.dsi[id];
0066 }
0067
0068 static inline struct msm_dsi *dsi_mgr_get_other_dsi(int id)
0069 {
0070 return msm_dsim_glb.dsi[(id + 1) % DSI_MAX];
0071 }
0072
0073 static int dsi_mgr_parse_of(struct device_node *np, int id)
0074 {
0075 struct msm_dsi_manager *msm_dsim = &msm_dsim_glb;
0076
0077
0078
0079
0080 if (!msm_dsim->is_bonded_dsi)
0081 msm_dsim->is_bonded_dsi = of_property_read_bool(np, "qcom,dual-dsi-mode");
0082
0083 if (msm_dsim->is_bonded_dsi) {
0084 if (of_property_read_bool(np, "qcom,master-dsi"))
0085 msm_dsim->master_dsi_link_id = id;
0086 if (!msm_dsim->is_sync_needed)
0087 msm_dsim->is_sync_needed = of_property_read_bool(
0088 np, "qcom,sync-dual-dsi");
0089 }
0090
0091 return 0;
0092 }
0093
0094 static int dsi_mgr_setup_components(int id)
0095 {
0096 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0097 struct msm_dsi *other_dsi = dsi_mgr_get_other_dsi(id);
0098 struct msm_dsi *clk_master_dsi = dsi_mgr_get_dsi(DSI_CLOCK_MASTER);
0099 struct msm_dsi *clk_slave_dsi = dsi_mgr_get_dsi(DSI_CLOCK_SLAVE);
0100 int ret;
0101
0102 if (!IS_BONDED_DSI()) {
0103 ret = msm_dsi_host_register(msm_dsi->host);
0104 if (ret)
0105 return ret;
0106
0107 msm_dsi_phy_set_usecase(msm_dsi->phy, MSM_DSI_PHY_STANDALONE);
0108 msm_dsi_host_set_phy_mode(msm_dsi->host, msm_dsi->phy);
0109 } else if (other_dsi) {
0110 struct msm_dsi *master_link_dsi = IS_MASTER_DSI_LINK(id) ?
0111 msm_dsi : other_dsi;
0112 struct msm_dsi *slave_link_dsi = IS_MASTER_DSI_LINK(id) ?
0113 other_dsi : msm_dsi;
0114
0115
0116
0117
0118
0119
0120
0121 ret = msm_dsi_host_register(slave_link_dsi->host);
0122 if (ret)
0123 return ret;
0124 ret = msm_dsi_host_register(master_link_dsi->host);
0125 if (ret)
0126 return ret;
0127
0128
0129 msm_dsi_phy_set_usecase(clk_master_dsi->phy,
0130 MSM_DSI_PHY_MASTER);
0131 msm_dsi_phy_set_usecase(clk_slave_dsi->phy,
0132 MSM_DSI_PHY_SLAVE);
0133 msm_dsi_host_set_phy_mode(msm_dsi->host, msm_dsi->phy);
0134 msm_dsi_host_set_phy_mode(other_dsi->host, other_dsi->phy);
0135 }
0136
0137 return 0;
0138 }
0139
0140 static int enable_phy(struct msm_dsi *msm_dsi,
0141 struct msm_dsi_phy_shared_timings *shared_timings)
0142 {
0143 struct msm_dsi_phy_clk_request clk_req;
0144 int ret;
0145 bool is_bonded_dsi = IS_BONDED_DSI();
0146
0147 msm_dsi_host_get_phy_clk_req(msm_dsi->host, &clk_req, is_bonded_dsi);
0148
0149 ret = msm_dsi_phy_enable(msm_dsi->phy, &clk_req, shared_timings);
0150
0151 return ret;
0152 }
0153
0154 static int
0155 dsi_mgr_phy_enable(int id,
0156 struct msm_dsi_phy_shared_timings shared_timings[DSI_MAX])
0157 {
0158 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0159 struct msm_dsi *mdsi = dsi_mgr_get_dsi(DSI_CLOCK_MASTER);
0160 struct msm_dsi *sdsi = dsi_mgr_get_dsi(DSI_CLOCK_SLAVE);
0161 int ret;
0162
0163
0164
0165
0166
0167
0168 if (IS_BONDED_DSI() && mdsi && sdsi) {
0169 if (!mdsi->phy_enabled && !sdsi->phy_enabled) {
0170 msm_dsi_host_reset_phy(mdsi->host);
0171 msm_dsi_host_reset_phy(sdsi->host);
0172
0173 ret = enable_phy(mdsi,
0174 &shared_timings[DSI_CLOCK_MASTER]);
0175 if (ret)
0176 return ret;
0177 ret = enable_phy(sdsi,
0178 &shared_timings[DSI_CLOCK_SLAVE]);
0179 if (ret) {
0180 msm_dsi_phy_disable(mdsi->phy);
0181 return ret;
0182 }
0183 }
0184 } else {
0185 msm_dsi_host_reset_phy(msm_dsi->host);
0186 ret = enable_phy(msm_dsi, &shared_timings[id]);
0187 if (ret)
0188 return ret;
0189 }
0190
0191 msm_dsi->phy_enabled = true;
0192
0193 return 0;
0194 }
0195
0196 static void dsi_mgr_phy_disable(int id)
0197 {
0198 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0199 struct msm_dsi *mdsi = dsi_mgr_get_dsi(DSI_CLOCK_MASTER);
0200 struct msm_dsi *sdsi = dsi_mgr_get_dsi(DSI_CLOCK_SLAVE);
0201
0202
0203
0204
0205
0206 msm_dsi->phy_enabled = false;
0207 if (IS_BONDED_DSI() && mdsi && sdsi) {
0208 if (!mdsi->phy_enabled && !sdsi->phy_enabled) {
0209 msm_dsi_phy_disable(sdsi->phy);
0210 msm_dsi_phy_disable(mdsi->phy);
0211 }
0212 } else {
0213 msm_dsi_phy_disable(msm_dsi->phy);
0214 }
0215 }
0216
0217 struct dsi_connector {
0218 struct drm_connector base;
0219 int id;
0220 };
0221
0222 struct dsi_bridge {
0223 struct drm_bridge base;
0224 int id;
0225 };
0226
0227 #define to_dsi_connector(x) container_of(x, struct dsi_connector, base)
0228 #define to_dsi_bridge(x) container_of(x, struct dsi_bridge, base)
0229
0230 static inline int dsi_mgr_connector_get_id(struct drm_connector *connector)
0231 {
0232 struct dsi_connector *dsi_connector = to_dsi_connector(connector);
0233 return dsi_connector->id;
0234 }
0235
0236 static int dsi_mgr_bridge_get_id(struct drm_bridge *bridge)
0237 {
0238 struct dsi_bridge *dsi_bridge = to_dsi_bridge(bridge);
0239 return dsi_bridge->id;
0240 }
0241
0242 static int msm_dsi_manager_panel_init(struct drm_connector *conn, u8 id)
0243 {
0244 struct msm_drm_private *priv = conn->dev->dev_private;
0245 struct msm_kms *kms = priv->kms;
0246 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0247 struct msm_dsi *other_dsi = dsi_mgr_get_other_dsi(id);
0248 struct msm_dsi *master_dsi, *slave_dsi;
0249 struct drm_panel *panel;
0250
0251 if (IS_BONDED_DSI() && !IS_MASTER_DSI_LINK(id)) {
0252 master_dsi = other_dsi;
0253 slave_dsi = msm_dsi;
0254 } else {
0255 master_dsi = msm_dsi;
0256 slave_dsi = other_dsi;
0257 }
0258
0259
0260
0261
0262
0263
0264 panel = msm_dsi_host_get_panel(master_dsi->host);
0265 if (IS_ERR(panel)) {
0266 DRM_ERROR("Could not find panel for %u (%ld)\n", msm_dsi->id,
0267 PTR_ERR(panel));
0268 return PTR_ERR(panel);
0269 }
0270
0271 if (!panel || !IS_BONDED_DSI())
0272 goto out;
0273
0274 drm_object_attach_property(&conn->base,
0275 conn->dev->mode_config.tile_property, 0);
0276
0277
0278
0279
0280
0281 if (other_dsi && other_dsi->panel && kms->funcs->set_split_display) {
0282 kms->funcs->set_split_display(kms, master_dsi->encoder,
0283 slave_dsi->encoder,
0284 msm_dsi_is_cmd_mode(msm_dsi));
0285 }
0286
0287 out:
0288 msm_dsi->panel = panel;
0289 return 0;
0290 }
0291
0292 static enum drm_connector_status dsi_mgr_connector_detect(
0293 struct drm_connector *connector, bool force)
0294 {
0295 int id = dsi_mgr_connector_get_id(connector);
0296 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0297
0298 return msm_dsi->panel ? connector_status_connected :
0299 connector_status_disconnected;
0300 }
0301
0302 static void dsi_mgr_connector_destroy(struct drm_connector *connector)
0303 {
0304 struct dsi_connector *dsi_connector = to_dsi_connector(connector);
0305
0306 DBG("");
0307
0308 drm_connector_cleanup(connector);
0309
0310 kfree(dsi_connector);
0311 }
0312
0313 static int dsi_mgr_connector_get_modes(struct drm_connector *connector)
0314 {
0315 int id = dsi_mgr_connector_get_id(connector);
0316 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0317 struct drm_panel *panel = msm_dsi->panel;
0318 int num;
0319
0320 if (!panel)
0321 return 0;
0322
0323
0324
0325
0326
0327 num = drm_panel_get_modes(panel, connector);
0328 if (!num)
0329 return 0;
0330
0331 return num;
0332 }
0333
0334 static struct drm_encoder *
0335 dsi_mgr_connector_best_encoder(struct drm_connector *connector)
0336 {
0337 int id = dsi_mgr_connector_get_id(connector);
0338 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0339
0340 DBG("");
0341 return msm_dsi_get_encoder(msm_dsi);
0342 }
0343
0344 static void dsi_mgr_bridge_power_on(struct drm_bridge *bridge)
0345 {
0346 int id = dsi_mgr_bridge_get_id(bridge);
0347 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0348 struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1);
0349 struct mipi_dsi_host *host = msm_dsi->host;
0350 struct msm_dsi_phy_shared_timings phy_shared_timings[DSI_MAX];
0351 bool is_bonded_dsi = IS_BONDED_DSI();
0352 int ret;
0353
0354 DBG("id=%d", id);
0355 if (!msm_dsi_device_connected(msm_dsi))
0356 return;
0357
0358
0359 if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id))
0360 return;
0361
0362 ret = dsi_mgr_phy_enable(id, phy_shared_timings);
0363 if (ret)
0364 goto phy_en_fail;
0365
0366 ret = msm_dsi_host_power_on(host, &phy_shared_timings[id], is_bonded_dsi, msm_dsi->phy);
0367 if (ret) {
0368 pr_err("%s: power on host %d failed, %d\n", __func__, id, ret);
0369 goto host_on_fail;
0370 }
0371
0372 if (is_bonded_dsi && msm_dsi1) {
0373 ret = msm_dsi_host_power_on(msm_dsi1->host,
0374 &phy_shared_timings[DSI_1], is_bonded_dsi, msm_dsi1->phy);
0375 if (ret) {
0376 pr_err("%s: power on host1 failed, %d\n",
0377 __func__, ret);
0378 goto host1_on_fail;
0379 }
0380 }
0381
0382
0383
0384
0385
0386 msm_dsi_host_enable_irq(host);
0387 if (is_bonded_dsi && msm_dsi1)
0388 msm_dsi_host_enable_irq(msm_dsi1->host);
0389
0390 return;
0391
0392 host1_on_fail:
0393 msm_dsi_host_power_off(host);
0394 host_on_fail:
0395 dsi_mgr_phy_disable(id);
0396 phy_en_fail:
0397 return;
0398 }
0399
0400 static void dsi_mgr_bridge_pre_enable(struct drm_bridge *bridge)
0401 {
0402 int id = dsi_mgr_bridge_get_id(bridge);
0403 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0404 struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1);
0405 struct mipi_dsi_host *host = msm_dsi->host;
0406 struct drm_panel *panel = msm_dsi->panel;
0407 bool is_bonded_dsi = IS_BONDED_DSI();
0408 int ret;
0409
0410 DBG("id=%d", id);
0411 if (!msm_dsi_device_connected(msm_dsi))
0412 return;
0413
0414
0415 if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id))
0416 return;
0417
0418 if (!dsi_mgr_power_on_early(bridge))
0419 dsi_mgr_bridge_power_on(bridge);
0420
0421
0422
0423
0424 if (panel) {
0425 ret = drm_panel_prepare(panel);
0426 if (ret) {
0427 pr_err("%s: prepare panel %d failed, %d\n", __func__,
0428 id, ret);
0429 goto panel_prep_fail;
0430 }
0431 }
0432
0433 ret = msm_dsi_host_enable(host);
0434 if (ret) {
0435 pr_err("%s: enable host %d failed, %d\n", __func__, id, ret);
0436 goto host_en_fail;
0437 }
0438
0439 if (is_bonded_dsi && msm_dsi1) {
0440 ret = msm_dsi_host_enable(msm_dsi1->host);
0441 if (ret) {
0442 pr_err("%s: enable host1 failed, %d\n", __func__, ret);
0443 goto host1_en_fail;
0444 }
0445 }
0446
0447 return;
0448
0449 host1_en_fail:
0450 msm_dsi_host_disable(host);
0451 host_en_fail:
0452 if (panel)
0453 drm_panel_unprepare(panel);
0454 panel_prep_fail:
0455
0456 return;
0457 }
0458
0459 void msm_dsi_manager_tpg_enable(void)
0460 {
0461 struct msm_dsi *m_dsi = dsi_mgr_get_dsi(DSI_0);
0462 struct msm_dsi *s_dsi = dsi_mgr_get_dsi(DSI_1);
0463
0464
0465 if (m_dsi) {
0466 msm_dsi_host_test_pattern_en(m_dsi->host);
0467 if (IS_BONDED_DSI() && s_dsi)
0468 msm_dsi_host_test_pattern_en(s_dsi->host);
0469 }
0470 }
0471
0472 static void dsi_mgr_bridge_enable(struct drm_bridge *bridge)
0473 {
0474 int id = dsi_mgr_bridge_get_id(bridge);
0475 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0476 struct drm_panel *panel = msm_dsi->panel;
0477 bool is_bonded_dsi = IS_BONDED_DSI();
0478 int ret;
0479
0480 DBG("id=%d", id);
0481 if (!msm_dsi_device_connected(msm_dsi))
0482 return;
0483
0484
0485 if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id))
0486 return;
0487
0488 if (panel) {
0489 ret = drm_panel_enable(panel);
0490 if (ret) {
0491 pr_err("%s: enable panel %d failed, %d\n", __func__, id,
0492 ret);
0493 }
0494 }
0495 }
0496
0497 static void dsi_mgr_bridge_disable(struct drm_bridge *bridge)
0498 {
0499 int id = dsi_mgr_bridge_get_id(bridge);
0500 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0501 struct drm_panel *panel = msm_dsi->panel;
0502 bool is_bonded_dsi = IS_BONDED_DSI();
0503 int ret;
0504
0505 DBG("id=%d", id);
0506 if (!msm_dsi_device_connected(msm_dsi))
0507 return;
0508
0509
0510 if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id))
0511 return;
0512
0513 if (panel) {
0514 ret = drm_panel_disable(panel);
0515 if (ret)
0516 pr_err("%s: Panel %d OFF failed, %d\n", __func__, id,
0517 ret);
0518 }
0519 }
0520
0521 static void dsi_mgr_bridge_post_disable(struct drm_bridge *bridge)
0522 {
0523 int id = dsi_mgr_bridge_get_id(bridge);
0524 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0525 struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1);
0526 struct mipi_dsi_host *host = msm_dsi->host;
0527 struct drm_panel *panel = msm_dsi->panel;
0528 bool is_bonded_dsi = IS_BONDED_DSI();
0529 int ret;
0530
0531 DBG("id=%d", id);
0532
0533 if (!msm_dsi_device_connected(msm_dsi))
0534 return;
0535
0536
0537
0538
0539
0540
0541 if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id))
0542 goto disable_phy;
0543
0544 ret = msm_dsi_host_disable(host);
0545 if (ret)
0546 pr_err("%s: host %d disable failed, %d\n", __func__, id, ret);
0547
0548 if (is_bonded_dsi && msm_dsi1) {
0549 ret = msm_dsi_host_disable(msm_dsi1->host);
0550 if (ret)
0551 pr_err("%s: host1 disable failed, %d\n", __func__, ret);
0552 }
0553
0554 if (panel) {
0555 ret = drm_panel_unprepare(panel);
0556 if (ret)
0557 pr_err("%s: Panel %d unprepare failed,%d\n", __func__,
0558 id, ret);
0559 }
0560
0561 msm_dsi_host_disable_irq(host);
0562 if (is_bonded_dsi && msm_dsi1)
0563 msm_dsi_host_disable_irq(msm_dsi1->host);
0564
0565
0566 msm_dsi_phy_pll_save_state(msm_dsi->phy);
0567
0568 ret = msm_dsi_host_power_off(host);
0569 if (ret)
0570 pr_err("%s: host %d power off failed,%d\n", __func__, id, ret);
0571
0572 if (is_bonded_dsi && msm_dsi1) {
0573 ret = msm_dsi_host_power_off(msm_dsi1->host);
0574 if (ret)
0575 pr_err("%s: host1 power off failed, %d\n",
0576 __func__, ret);
0577 }
0578
0579 disable_phy:
0580 dsi_mgr_phy_disable(id);
0581 }
0582
0583 static void dsi_mgr_bridge_mode_set(struct drm_bridge *bridge,
0584 const struct drm_display_mode *mode,
0585 const struct drm_display_mode *adjusted_mode)
0586 {
0587 int id = dsi_mgr_bridge_get_id(bridge);
0588 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0589 struct msm_dsi *other_dsi = dsi_mgr_get_other_dsi(id);
0590 struct mipi_dsi_host *host = msm_dsi->host;
0591 bool is_bonded_dsi = IS_BONDED_DSI();
0592
0593 DBG("set mode: " DRM_MODE_FMT, DRM_MODE_ARG(mode));
0594
0595 if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id))
0596 return;
0597
0598 msm_dsi_host_set_display_mode(host, adjusted_mode);
0599 if (is_bonded_dsi && other_dsi)
0600 msm_dsi_host_set_display_mode(other_dsi->host, adjusted_mode);
0601
0602 if (dsi_mgr_power_on_early(bridge))
0603 dsi_mgr_bridge_power_on(bridge);
0604 }
0605
0606 static enum drm_mode_status dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge,
0607 const struct drm_display_info *info,
0608 const struct drm_display_mode *mode)
0609 {
0610 int id = dsi_mgr_bridge_get_id(bridge);
0611 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0612 struct mipi_dsi_host *host = msm_dsi->host;
0613
0614 return msm_dsi_host_check_dsc(host, mode);
0615 }
0616
0617 static const struct drm_connector_funcs dsi_mgr_connector_funcs = {
0618 .detect = dsi_mgr_connector_detect,
0619 .fill_modes = drm_helper_probe_single_connector_modes,
0620 .destroy = dsi_mgr_connector_destroy,
0621 .reset = drm_atomic_helper_connector_reset,
0622 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
0623 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
0624 };
0625
0626 static const struct drm_connector_helper_funcs dsi_mgr_conn_helper_funcs = {
0627 .get_modes = dsi_mgr_connector_get_modes,
0628 .best_encoder = dsi_mgr_connector_best_encoder,
0629 };
0630
0631 static const struct drm_bridge_funcs dsi_mgr_bridge_funcs = {
0632 .pre_enable = dsi_mgr_bridge_pre_enable,
0633 .enable = dsi_mgr_bridge_enable,
0634 .disable = dsi_mgr_bridge_disable,
0635 .post_disable = dsi_mgr_bridge_post_disable,
0636 .mode_set = dsi_mgr_bridge_mode_set,
0637 .mode_valid = dsi_mgr_bridge_mode_valid,
0638 };
0639
0640
0641 struct drm_connector *msm_dsi_manager_connector_init(u8 id)
0642 {
0643 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0644 struct drm_connector *connector = NULL;
0645 struct dsi_connector *dsi_connector;
0646 int ret;
0647
0648 dsi_connector = kzalloc(sizeof(*dsi_connector), GFP_KERNEL);
0649 if (!dsi_connector)
0650 return ERR_PTR(-ENOMEM);
0651
0652 dsi_connector->id = id;
0653
0654 connector = &dsi_connector->base;
0655
0656 ret = drm_connector_init(msm_dsi->dev, connector,
0657 &dsi_mgr_connector_funcs, DRM_MODE_CONNECTOR_DSI);
0658 if (ret)
0659 return ERR_PTR(ret);
0660
0661 drm_connector_helper_add(connector, &dsi_mgr_conn_helper_funcs);
0662
0663
0664
0665
0666 connector->polled = DRM_CONNECTOR_POLL_HPD;
0667
0668
0669 connector->interlace_allowed = 0;
0670 connector->doublescan_allowed = 0;
0671
0672 drm_connector_attach_encoder(connector, msm_dsi->encoder);
0673
0674 ret = msm_dsi_manager_panel_init(connector, id);
0675 if (ret) {
0676 DRM_DEV_ERROR(msm_dsi->dev->dev, "init panel failed %d\n", ret);
0677 goto fail;
0678 }
0679
0680 return connector;
0681
0682 fail:
0683 connector->funcs->destroy(connector);
0684 return ERR_PTR(ret);
0685 }
0686
0687
0688 struct drm_bridge *msm_dsi_manager_bridge_init(u8 id)
0689 {
0690 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0691 struct drm_bridge *bridge = NULL;
0692 struct dsi_bridge *dsi_bridge;
0693 struct drm_encoder *encoder;
0694 int ret;
0695
0696 dsi_bridge = devm_kzalloc(msm_dsi->dev->dev,
0697 sizeof(*dsi_bridge), GFP_KERNEL);
0698 if (!dsi_bridge) {
0699 ret = -ENOMEM;
0700 goto fail;
0701 }
0702
0703 dsi_bridge->id = id;
0704
0705 encoder = msm_dsi->encoder;
0706
0707 bridge = &dsi_bridge->base;
0708 bridge->funcs = &dsi_mgr_bridge_funcs;
0709
0710 drm_bridge_add(bridge);
0711
0712 ret = drm_bridge_attach(encoder, bridge, NULL, 0);
0713 if (ret)
0714 goto fail;
0715
0716 return bridge;
0717
0718 fail:
0719 if (bridge)
0720 msm_dsi_manager_bridge_destroy(bridge);
0721
0722 return ERR_PTR(ret);
0723 }
0724
0725 struct drm_connector *msm_dsi_manager_ext_bridge_init(u8 id)
0726 {
0727 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0728 struct drm_device *dev = msm_dsi->dev;
0729 struct drm_connector *connector;
0730 struct drm_encoder *encoder;
0731 struct drm_bridge *int_bridge, *ext_bridge;
0732 int ret;
0733
0734 int_bridge = msm_dsi->bridge;
0735 ext_bridge = msm_dsi->external_bridge =
0736 msm_dsi_host_get_bridge(msm_dsi->host);
0737
0738 encoder = msm_dsi->encoder;
0739
0740
0741
0742
0743
0744
0745 ret = drm_bridge_attach(encoder, ext_bridge, int_bridge,
0746 DRM_BRIDGE_ATTACH_NO_CONNECTOR);
0747 if (ret == -EINVAL) {
0748 struct drm_connector *connector;
0749 struct list_head *connector_list;
0750
0751
0752 drm_bridge_attach(encoder, ext_bridge, int_bridge, 0);
0753
0754
0755
0756
0757
0758
0759 connector_list = &dev->mode_config.connector_list;
0760
0761 list_for_each_entry(connector, connector_list, head) {
0762 if (drm_connector_has_possible_encoder(connector, encoder))
0763 return connector;
0764 }
0765
0766 return ERR_PTR(-ENODEV);
0767 }
0768
0769 connector = drm_bridge_connector_init(dev, encoder);
0770 if (IS_ERR(connector)) {
0771 DRM_ERROR("Unable to create bridge connector\n");
0772 return ERR_CAST(connector);
0773 }
0774
0775 drm_connector_attach_encoder(connector, encoder);
0776
0777 return connector;
0778 }
0779
0780 void msm_dsi_manager_bridge_destroy(struct drm_bridge *bridge)
0781 {
0782 drm_bridge_remove(bridge);
0783 }
0784
0785 int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg)
0786 {
0787 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0788 struct msm_dsi *msm_dsi0 = dsi_mgr_get_dsi(DSI_0);
0789 struct mipi_dsi_host *host = msm_dsi->host;
0790 bool is_read = (msg->rx_buf && msg->rx_len);
0791 bool need_sync = (IS_SYNC_NEEDED() && !is_read);
0792 int ret;
0793
0794 if (!msg->tx_buf || !msg->tx_len)
0795 return 0;
0796
0797
0798
0799
0800
0801
0802 if (need_sync && (id == DSI_0))
0803 return is_read ? msg->rx_len : msg->tx_len;
0804
0805 if (need_sync && msm_dsi0) {
0806 ret = msm_dsi_host_xfer_prepare(msm_dsi0->host, msg);
0807 if (ret) {
0808 pr_err("%s: failed to prepare non-trigger host, %d\n",
0809 __func__, ret);
0810 return ret;
0811 }
0812 }
0813 ret = msm_dsi_host_xfer_prepare(host, msg);
0814 if (ret) {
0815 pr_err("%s: failed to prepare host, %d\n", __func__, ret);
0816 goto restore_host0;
0817 }
0818
0819 ret = is_read ? msm_dsi_host_cmd_rx(host, msg) :
0820 msm_dsi_host_cmd_tx(host, msg);
0821
0822 msm_dsi_host_xfer_restore(host, msg);
0823
0824 restore_host0:
0825 if (need_sync && msm_dsi0)
0826 msm_dsi_host_xfer_restore(msm_dsi0->host, msg);
0827
0828 return ret;
0829 }
0830
0831 bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len)
0832 {
0833 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
0834 struct msm_dsi *msm_dsi0 = dsi_mgr_get_dsi(DSI_0);
0835 struct mipi_dsi_host *host = msm_dsi->host;
0836
0837 if (IS_SYNC_NEEDED() && (id == DSI_0))
0838 return false;
0839
0840 if (IS_SYNC_NEEDED() && msm_dsi0)
0841 msm_dsi_host_cmd_xfer_commit(msm_dsi0->host, dma_base, len);
0842
0843 msm_dsi_host_cmd_xfer_commit(host, dma_base, len);
0844
0845 return true;
0846 }
0847
0848 int msm_dsi_manager_register(struct msm_dsi *msm_dsi)
0849 {
0850 struct msm_dsi_manager *msm_dsim = &msm_dsim_glb;
0851 int id = msm_dsi->id;
0852 int ret;
0853
0854 if (id >= DSI_MAX) {
0855 pr_err("%s: invalid id %d\n", __func__, id);
0856 return -EINVAL;
0857 }
0858
0859 if (msm_dsim->dsi[id]) {
0860 pr_err("%s: dsi%d already registered\n", __func__, id);
0861 return -EBUSY;
0862 }
0863
0864 msm_dsim->dsi[id] = msm_dsi;
0865
0866 ret = dsi_mgr_parse_of(msm_dsi->pdev->dev.of_node, id);
0867 if (ret) {
0868 pr_err("%s: failed to parse OF DSI info\n", __func__);
0869 goto fail;
0870 }
0871
0872 ret = dsi_mgr_setup_components(id);
0873 if (ret) {
0874 pr_err("%s: failed to register mipi dsi host for DSI %d: %d\n",
0875 __func__, id, ret);
0876 goto fail;
0877 }
0878
0879 return 0;
0880
0881 fail:
0882 msm_dsim->dsi[id] = NULL;
0883 return ret;
0884 }
0885
0886 void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi)
0887 {
0888 struct msm_dsi_manager *msm_dsim = &msm_dsim_glb;
0889
0890 if (msm_dsi->host)
0891 msm_dsi_host_unregister(msm_dsi->host);
0892
0893 if (msm_dsi->id >= 0)
0894 msm_dsim->dsi[msm_dsi->id] = NULL;
0895 }
0896
0897 bool msm_dsi_is_bonded_dsi(struct msm_dsi *msm_dsi)
0898 {
0899 return IS_BONDED_DSI();
0900 }
0901
0902 bool msm_dsi_is_master_dsi(struct msm_dsi *msm_dsi)
0903 {
0904 return IS_MASTER_DSI_LINK(msm_dsi->id);
0905 }