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
dsi_mgr_get_dsi(int id)37 static inline struct msm_dsi *dsi_mgr_get_dsi(int id)
38 {
39 return msm_dsim_glb.dsi[id];
40 }
41
dsi_mgr_get_other_dsi(int id)42 static inline struct msm_dsi *dsi_mgr_get_other_dsi(int id)
43 {
44 return msm_dsim_glb.dsi[(id + 1) % DSI_MAX];
45 }
46
dsi_mgr_parse_of(struct device_node * np,int id)47 static int dsi_mgr_parse_of(struct device_node *np, int id)
48 {
49 struct msm_dsi_manager *msm_dsim = &msm_dsim_glb;
50
51 /* We assume 2 dsi nodes have the same information of bonded dsi and
52 * sync-mode, and only one node specifies master in case of bonded mode.
53 */
54 if (!msm_dsim->is_bonded_dsi)
55 msm_dsim->is_bonded_dsi = of_property_read_bool(np, "qcom,dual-dsi-mode");
56
57 if (msm_dsim->is_bonded_dsi) {
58 if (of_property_read_bool(np, "qcom,master-dsi"))
59 msm_dsim->master_dsi_link_id = id;
60 if (!msm_dsim->is_sync_needed)
61 msm_dsim->is_sync_needed = of_property_read_bool(
62 np, "qcom,sync-dual-dsi");
63 }
64
65 return 0;
66 }
67
dsi_mgr_setup_components(int id)68 static int dsi_mgr_setup_components(int id)
69 {
70 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
71 struct msm_dsi *other_dsi = dsi_mgr_get_other_dsi(id);
72 struct msm_dsi *clk_master_dsi = dsi_mgr_get_dsi(DSI_CLOCK_MASTER);
73 struct msm_dsi *clk_slave_dsi = dsi_mgr_get_dsi(DSI_CLOCK_SLAVE);
74 int ret;
75
76 if (!IS_BONDED_DSI()) {
77 /*
78 * Set the usecase before calling msm_dsi_host_register(), which would
79 * already program the PLL source mux based on a default usecase.
80 */
81 msm_dsi_phy_set_usecase(msm_dsi->phy, MSM_DSI_PHY_STANDALONE);
82 msm_dsi_host_set_phy_mode(msm_dsi->host, msm_dsi->phy);
83
84 ret = msm_dsi_host_register(msm_dsi->host);
85 if (ret)
86 return ret;
87 } else if (other_dsi) {
88 struct msm_dsi *master_link_dsi = IS_MASTER_DSI_LINK(id) ?
89 msm_dsi : other_dsi;
90 struct msm_dsi *slave_link_dsi = IS_MASTER_DSI_LINK(id) ?
91 other_dsi : msm_dsi;
92
93 /*
94 * PLL0 is to drive both DSI link clocks in bonded DSI mode.
95 *
96 * Set the usecase before calling msm_dsi_host_register(), which would
97 * already program the PLL source mux based on a default usecase.
98 */
99 msm_dsi_phy_set_usecase(clk_master_dsi->phy,
100 MSM_DSI_PHY_MASTER);
101 msm_dsi_phy_set_usecase(clk_slave_dsi->phy,
102 MSM_DSI_PHY_SLAVE);
103 msm_dsi_host_set_phy_mode(msm_dsi->host, msm_dsi->phy);
104 msm_dsi_host_set_phy_mode(other_dsi->host, other_dsi->phy);
105
106 /* Register slave host first, so that slave DSI device
107 * has a chance to probe, and do not block the master
108 * DSI device's probe.
109 * Also, do not check defer for the slave host,
110 * because only master DSI device adds the panel to global
111 * panel list. The panel's device is the master DSI device.
112 */
113 ret = msm_dsi_host_register(slave_link_dsi->host);
114 if (ret)
115 return ret;
116 ret = msm_dsi_host_register(master_link_dsi->host);
117 if (ret)
118 return ret;
119 }
120
121 return 0;
122 }
123
enable_phy(struct msm_dsi * msm_dsi,struct msm_dsi_phy_shared_timings * shared_timings)124 static int enable_phy(struct msm_dsi *msm_dsi,
125 struct msm_dsi_phy_shared_timings *shared_timings)
126 {
127 struct msm_dsi_phy_clk_request clk_req;
128 bool is_bonded_dsi = IS_BONDED_DSI();
129
130 msm_dsi_host_get_phy_clk_req(msm_dsi->host, &clk_req, is_bonded_dsi);
131
132 return msm_dsi_phy_enable(msm_dsi->phy, &clk_req, shared_timings);
133 }
134
135 static int
dsi_mgr_phy_enable(int id,struct msm_dsi_phy_shared_timings shared_timings[DSI_MAX])136 dsi_mgr_phy_enable(int id,
137 struct msm_dsi_phy_shared_timings shared_timings[DSI_MAX])
138 {
139 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
140 struct msm_dsi *mdsi = dsi_mgr_get_dsi(DSI_CLOCK_MASTER);
141 struct msm_dsi *sdsi = dsi_mgr_get_dsi(DSI_CLOCK_SLAVE);
142 int ret;
143
144 /* In case of bonded DSI, some registers in PHY1 have been programmed
145 * during PLL0 clock's set_rate. The PHY1 reset called by host1 here
146 * will silently reset those PHY1 registers. Therefore we need to reset
147 * and enable both PHYs before any PLL clock operation.
148 */
149 if (IS_BONDED_DSI() && mdsi && sdsi) {
150 if (!mdsi->phy_enabled && !sdsi->phy_enabled) {
151 msm_dsi_host_reset_phy(mdsi->host);
152 msm_dsi_host_reset_phy(sdsi->host);
153
154 ret = enable_phy(mdsi,
155 &shared_timings[DSI_CLOCK_MASTER]);
156 if (ret)
157 return ret;
158 ret = enable_phy(sdsi,
159 &shared_timings[DSI_CLOCK_SLAVE]);
160 if (ret) {
161 msm_dsi_phy_disable(mdsi->phy);
162 return ret;
163 }
164 }
165 } else {
166 msm_dsi_host_reset_phy(msm_dsi->host);
167 ret = enable_phy(msm_dsi, &shared_timings[id]);
168 if (ret)
169 return ret;
170 }
171
172 msm_dsi->phy_enabled = true;
173
174 return 0;
175 }
176
dsi_mgr_phy_disable(int id)177 static void dsi_mgr_phy_disable(int id)
178 {
179 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
180 struct msm_dsi *mdsi = dsi_mgr_get_dsi(DSI_CLOCK_MASTER);
181 struct msm_dsi *sdsi = dsi_mgr_get_dsi(DSI_CLOCK_SLAVE);
182
183 /* disable DSI phy
184 * In bonded dsi configuration, the phy should be disabled for the
185 * first controller only when the second controller is disabled.
186 */
187 msm_dsi->phy_enabled = false;
188 if (IS_BONDED_DSI() && mdsi && sdsi) {
189 if (!mdsi->phy_enabled && !sdsi->phy_enabled) {
190 msm_dsi_phy_disable(sdsi->phy);
191 msm_dsi_phy_disable(mdsi->phy);
192 }
193 } else {
194 msm_dsi_phy_disable(msm_dsi->phy);
195 }
196 }
197
198 struct dsi_bridge {
199 struct drm_bridge base;
200 int id;
201 };
202
203 #define to_dsi_bridge(x) container_of(x, struct dsi_bridge, base)
204
dsi_mgr_bridge_get_id(struct drm_bridge * bridge)205 static int dsi_mgr_bridge_get_id(struct drm_bridge *bridge)
206 {
207 struct dsi_bridge *dsi_bridge = to_dsi_bridge(bridge);
208 return dsi_bridge->id;
209 }
210
msm_dsi_manager_set_split_display(u8 id)211 static void msm_dsi_manager_set_split_display(u8 id)
212 {
213 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
214 struct msm_dsi *other_dsi = dsi_mgr_get_other_dsi(id);
215 struct msm_drm_private *priv = msm_dsi->dev->dev_private;
216 struct msm_kms *kms = priv->kms;
217 struct msm_dsi *master_dsi, *slave_dsi;
218
219 if (IS_BONDED_DSI() && !IS_MASTER_DSI_LINK(id)) {
220 master_dsi = other_dsi;
221 slave_dsi = msm_dsi;
222 } else {
223 master_dsi = msm_dsi;
224 slave_dsi = other_dsi;
225 }
226
227 if (!msm_dsi->external_bridge || !IS_BONDED_DSI())
228 return;
229
230 /*
231 * Set split display info to kms once bonded DSI panel is connected to
232 * both hosts.
233 */
234 if (other_dsi && other_dsi->external_bridge && kms->funcs->set_split_display) {
235 kms->funcs->set_split_display(kms, master_dsi->encoder,
236 slave_dsi->encoder,
237 msm_dsi_is_cmd_mode(msm_dsi));
238 }
239 }
240
dsi_mgr_bridge_power_on(struct drm_bridge * bridge)241 static int dsi_mgr_bridge_power_on(struct drm_bridge *bridge)
242 {
243 int id = dsi_mgr_bridge_get_id(bridge);
244 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
245 struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1);
246 struct mipi_dsi_host *host = msm_dsi->host;
247 struct msm_dsi_phy_shared_timings phy_shared_timings[DSI_MAX];
248 bool is_bonded_dsi = IS_BONDED_DSI();
249 int ret;
250
251 DBG("id=%d", id);
252
253 ret = dsi_mgr_phy_enable(id, phy_shared_timings);
254 if (ret)
255 goto phy_en_fail;
256
257 ret = msm_dsi_host_power_on(host, &phy_shared_timings[id], is_bonded_dsi, msm_dsi->phy);
258 if (ret) {
259 pr_err("%s: power on host %d failed, %d\n", __func__, id, ret);
260 goto host_on_fail;
261 }
262
263 if (is_bonded_dsi && msm_dsi1) {
264 ret = msm_dsi_host_power_on(msm_dsi1->host,
265 &phy_shared_timings[DSI_1], is_bonded_dsi, msm_dsi1->phy);
266 if (ret) {
267 pr_err("%s: power on host1 failed, %d\n",
268 __func__, ret);
269 goto host1_on_fail;
270 }
271 }
272
273 /*
274 * Enable before preparing the panel, disable after unpreparing, so
275 * that the panel can communicate over the DSI link.
276 */
277 msm_dsi_host_enable_irq(host);
278 if (is_bonded_dsi && msm_dsi1)
279 msm_dsi_host_enable_irq(msm_dsi1->host);
280
281 return 0;
282
283 host1_on_fail:
284 msm_dsi_host_power_off(host);
285 host_on_fail:
286 dsi_mgr_phy_disable(id);
287 phy_en_fail:
288 return ret;
289 }
290
dsi_mgr_bridge_power_off(struct drm_bridge * bridge)291 static void dsi_mgr_bridge_power_off(struct drm_bridge *bridge)
292 {
293 int id = dsi_mgr_bridge_get_id(bridge);
294 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
295 struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1);
296 struct mipi_dsi_host *host = msm_dsi->host;
297 bool is_bonded_dsi = IS_BONDED_DSI();
298
299 msm_dsi_host_disable_irq(host);
300 if (is_bonded_dsi && msm_dsi1) {
301 msm_dsi_host_disable_irq(msm_dsi1->host);
302 msm_dsi_host_power_off(msm_dsi1->host);
303 }
304 msm_dsi_host_power_off(host);
305 dsi_mgr_phy_disable(id);
306 }
307
dsi_mgr_bridge_pre_enable(struct drm_bridge * bridge)308 static void dsi_mgr_bridge_pre_enable(struct drm_bridge *bridge)
309 {
310 int id = dsi_mgr_bridge_get_id(bridge);
311 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
312 struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1);
313 struct mipi_dsi_host *host = msm_dsi->host;
314 bool is_bonded_dsi = IS_BONDED_DSI();
315 int ret;
316
317 DBG("id=%d", id);
318 if (!msm_dsi_device_connected(msm_dsi))
319 return;
320
321 /* Do nothing with the host if it is slave-DSI in case of bonded DSI */
322 if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id))
323 return;
324
325 ret = dsi_mgr_bridge_power_on(bridge);
326 if (ret) {
327 dev_err(&msm_dsi->pdev->dev, "Power on failed: %d\n", ret);
328 return;
329 }
330
331 ret = msm_dsi_host_enable(host);
332 if (ret) {
333 pr_err("%s: enable host %d failed, %d\n", __func__, id, ret);
334 goto host_en_fail;
335 }
336
337 if (is_bonded_dsi && msm_dsi1) {
338 ret = msm_dsi_host_enable(msm_dsi1->host);
339 if (ret) {
340 pr_err("%s: enable host1 failed, %d\n", __func__, ret);
341 goto host1_en_fail;
342 }
343 }
344
345 return;
346
347 host1_en_fail:
348 msm_dsi_host_disable(host);
349 host_en_fail:
350 dsi_mgr_bridge_power_off(bridge);
351 }
352
msm_dsi_manager_tpg_enable(void)353 void msm_dsi_manager_tpg_enable(void)
354 {
355 struct msm_dsi *m_dsi = dsi_mgr_get_dsi(DSI_0);
356 struct msm_dsi *s_dsi = dsi_mgr_get_dsi(DSI_1);
357
358 /* if dual dsi, trigger tpg on master first then slave */
359 if (m_dsi) {
360 msm_dsi_host_test_pattern_en(m_dsi->host);
361 if (IS_BONDED_DSI() && s_dsi)
362 msm_dsi_host_test_pattern_en(s_dsi->host);
363 }
364 }
365
dsi_mgr_bridge_post_disable(struct drm_bridge * bridge)366 static void dsi_mgr_bridge_post_disable(struct drm_bridge *bridge)
367 {
368 int id = dsi_mgr_bridge_get_id(bridge);
369 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
370 struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1);
371 struct mipi_dsi_host *host = msm_dsi->host;
372 bool is_bonded_dsi = IS_BONDED_DSI();
373 int ret;
374
375 DBG("id=%d", id);
376
377 if (!msm_dsi_device_connected(msm_dsi))
378 return;
379
380 /*
381 * Do nothing with the host if it is slave-DSI in case of bonded DSI.
382 * It is safe to call dsi_mgr_phy_disable() here because a single PHY
383 * won't be diabled until both PHYs request disable.
384 */
385 if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id))
386 goto disable_phy;
387
388 ret = msm_dsi_host_disable(host);
389 if (ret)
390 pr_err("%s: host %d disable failed, %d\n", __func__, id, ret);
391
392 if (is_bonded_dsi && msm_dsi1) {
393 ret = msm_dsi_host_disable(msm_dsi1->host);
394 if (ret)
395 pr_err("%s: host1 disable failed, %d\n", __func__, ret);
396 }
397
398 msm_dsi_host_disable_irq(host);
399 if (is_bonded_dsi && msm_dsi1)
400 msm_dsi_host_disable_irq(msm_dsi1->host);
401
402 /* Save PHY status if it is a clock source */
403 msm_dsi_phy_pll_save_state(msm_dsi->phy);
404
405 ret = msm_dsi_host_power_off(host);
406 if (ret)
407 pr_err("%s: host %d power off failed,%d\n", __func__, id, ret);
408
409 if (is_bonded_dsi && msm_dsi1) {
410 ret = msm_dsi_host_power_off(msm_dsi1->host);
411 if (ret)
412 pr_err("%s: host1 power off failed, %d\n",
413 __func__, ret);
414 }
415
416 disable_phy:
417 dsi_mgr_phy_disable(id);
418 }
419
dsi_mgr_bridge_mode_set(struct drm_bridge * bridge,const struct drm_display_mode * mode,const struct drm_display_mode * adjusted_mode)420 static void dsi_mgr_bridge_mode_set(struct drm_bridge *bridge,
421 const struct drm_display_mode *mode,
422 const struct drm_display_mode *adjusted_mode)
423 {
424 int id = dsi_mgr_bridge_get_id(bridge);
425 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
426 struct msm_dsi *other_dsi = dsi_mgr_get_other_dsi(id);
427 struct mipi_dsi_host *host = msm_dsi->host;
428 bool is_bonded_dsi = IS_BONDED_DSI();
429
430 DBG("set mode: " DRM_MODE_FMT, DRM_MODE_ARG(mode));
431
432 if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id))
433 return;
434
435 msm_dsi_host_set_display_mode(host, adjusted_mode);
436 if (is_bonded_dsi && other_dsi)
437 msm_dsi_host_set_display_mode(other_dsi->host, adjusted_mode);
438 }
439
dsi_mgr_bridge_mode_valid(struct drm_bridge * bridge,const struct drm_display_info * info,const struct drm_display_mode * mode)440 static enum drm_mode_status dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge,
441 const struct drm_display_info *info,
442 const struct drm_display_mode *mode)
443 {
444 int id = dsi_mgr_bridge_get_id(bridge);
445 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
446 struct mipi_dsi_host *host = msm_dsi->host;
447 struct platform_device *pdev = msm_dsi->pdev;
448 struct dev_pm_opp *opp;
449 unsigned long byte_clk_rate;
450
451 byte_clk_rate = dsi_byte_clk_get_rate(host, IS_BONDED_DSI(), mode);
452
453 opp = dev_pm_opp_find_freq_ceil(&pdev->dev, &byte_clk_rate);
454 if (!IS_ERR(opp)) {
455 dev_pm_opp_put(opp);
456 } else if (PTR_ERR(opp) == -ERANGE) {
457 /*
458 * An empty table is created by devm_pm_opp_set_clkname() even
459 * if there is none. Thus find_freq_ceil will still return
460 * -ERANGE in such case.
461 */
462 if (dev_pm_opp_get_opp_count(&pdev->dev) != 0)
463 return MODE_CLOCK_RANGE;
464 } else {
465 return MODE_ERROR;
466 }
467
468 return msm_dsi_host_check_dsc(host, mode);
469 }
470
471 static const struct drm_bridge_funcs dsi_mgr_bridge_funcs = {
472 .pre_enable = dsi_mgr_bridge_pre_enable,
473 .post_disable = dsi_mgr_bridge_post_disable,
474 .mode_set = dsi_mgr_bridge_mode_set,
475 .mode_valid = dsi_mgr_bridge_mode_valid,
476 };
477
478 /* initialize bridge */
msm_dsi_manager_bridge_init(u8 id)479 struct drm_bridge *msm_dsi_manager_bridge_init(u8 id)
480 {
481 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
482 struct drm_bridge *bridge = NULL;
483 struct dsi_bridge *dsi_bridge;
484 struct drm_encoder *encoder;
485 int ret;
486
487 dsi_bridge = devm_kzalloc(msm_dsi->dev->dev,
488 sizeof(*dsi_bridge), GFP_KERNEL);
489 if (!dsi_bridge) {
490 ret = -ENOMEM;
491 goto fail;
492 }
493
494 dsi_bridge->id = id;
495
496 encoder = msm_dsi->encoder;
497
498 bridge = &dsi_bridge->base;
499 bridge->funcs = &dsi_mgr_bridge_funcs;
500
501 drm_bridge_add(bridge);
502
503 ret = drm_bridge_attach(encoder, bridge, NULL, 0);
504 if (ret)
505 goto fail;
506
507 return bridge;
508
509 fail:
510 if (bridge)
511 msm_dsi_manager_bridge_destroy(bridge);
512
513 return ERR_PTR(ret);
514 }
515
msm_dsi_manager_ext_bridge_init(u8 id)516 int msm_dsi_manager_ext_bridge_init(u8 id)
517 {
518 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
519 struct drm_device *dev = msm_dsi->dev;
520 struct drm_encoder *encoder;
521 struct drm_bridge *int_bridge, *ext_bridge;
522 int ret;
523
524 int_bridge = msm_dsi->bridge;
525 ext_bridge = devm_drm_of_get_bridge(&msm_dsi->pdev->dev,
526 msm_dsi->pdev->dev.of_node, 1, 0);
527 if (IS_ERR(ext_bridge))
528 return PTR_ERR(ext_bridge);
529
530 msm_dsi->external_bridge = ext_bridge;
531
532 encoder = msm_dsi->encoder;
533
534 /*
535 * Try first to create the bridge without it creating its own
536 * connector.. currently some bridges support this, and others
537 * do not (and some support both modes)
538 */
539 ret = drm_bridge_attach(encoder, ext_bridge, int_bridge,
540 DRM_BRIDGE_ATTACH_NO_CONNECTOR);
541 if (ret == -EINVAL) {
542 /*
543 * link the internal dsi bridge to the external bridge,
544 * connector is created by the next bridge.
545 */
546 ret = drm_bridge_attach(encoder, ext_bridge, int_bridge, 0);
547 if (ret < 0)
548 return ret;
549 } else {
550 struct drm_connector *connector;
551
552 /* We are in charge of the connector, create one now. */
553 connector = drm_bridge_connector_init(dev, encoder);
554 if (IS_ERR(connector)) {
555 DRM_ERROR("Unable to create bridge connector\n");
556 return PTR_ERR(connector);
557 }
558
559 ret = drm_connector_attach_encoder(connector, encoder);
560 if (ret < 0)
561 return ret;
562 }
563
564 /* The pipeline is ready, ping encoders if necessary */
565 msm_dsi_manager_set_split_display(id);
566
567 return 0;
568 }
569
msm_dsi_manager_bridge_destroy(struct drm_bridge * bridge)570 void msm_dsi_manager_bridge_destroy(struct drm_bridge *bridge)
571 {
572 drm_bridge_remove(bridge);
573 }
574
msm_dsi_manager_cmd_xfer(int id,const struct mipi_dsi_msg * msg)575 int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg)
576 {
577 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
578 struct msm_dsi *msm_dsi0 = dsi_mgr_get_dsi(DSI_0);
579 struct mipi_dsi_host *host = msm_dsi->host;
580 bool is_read = (msg->rx_buf && msg->rx_len);
581 bool need_sync = (IS_SYNC_NEEDED() && !is_read);
582 int ret;
583
584 if (!msg->tx_buf || !msg->tx_len)
585 return 0;
586
587 /* In bonded master case, panel requires the same commands sent to
588 * both DSI links. Host issues the command trigger to both links
589 * when DSI_1 calls the cmd transfer function, no matter it happens
590 * before or after DSI_0 cmd transfer.
591 */
592 if (need_sync && (id == DSI_0))
593 return is_read ? msg->rx_len : msg->tx_len;
594
595 if (need_sync && msm_dsi0) {
596 ret = msm_dsi_host_xfer_prepare(msm_dsi0->host, msg);
597 if (ret) {
598 pr_err("%s: failed to prepare non-trigger host, %d\n",
599 __func__, ret);
600 return ret;
601 }
602 }
603 ret = msm_dsi_host_xfer_prepare(host, msg);
604 if (ret) {
605 pr_err("%s: failed to prepare host, %d\n", __func__, ret);
606 goto restore_host0;
607 }
608
609 ret = is_read ? msm_dsi_host_cmd_rx(host, msg) :
610 msm_dsi_host_cmd_tx(host, msg);
611
612 msm_dsi_host_xfer_restore(host, msg);
613
614 restore_host0:
615 if (need_sync && msm_dsi0)
616 msm_dsi_host_xfer_restore(msm_dsi0->host, msg);
617
618 return ret;
619 }
620
msm_dsi_manager_cmd_xfer_trigger(int id,u32 dma_base,u32 len)621 bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len)
622 {
623 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
624 struct msm_dsi *msm_dsi0 = dsi_mgr_get_dsi(DSI_0);
625 struct mipi_dsi_host *host = msm_dsi->host;
626
627 if (IS_SYNC_NEEDED() && (id == DSI_0))
628 return false;
629
630 if (IS_SYNC_NEEDED() && msm_dsi0)
631 msm_dsi_host_cmd_xfer_commit(msm_dsi0->host, dma_base, len);
632
633 msm_dsi_host_cmd_xfer_commit(host, dma_base, len);
634
635 return true;
636 }
637
msm_dsi_manager_register(struct msm_dsi * msm_dsi)638 int msm_dsi_manager_register(struct msm_dsi *msm_dsi)
639 {
640 struct msm_dsi_manager *msm_dsim = &msm_dsim_glb;
641 int id = msm_dsi->id;
642 int ret;
643
644 if (id >= DSI_MAX) {
645 pr_err("%s: invalid id %d\n", __func__, id);
646 return -EINVAL;
647 }
648
649 if (msm_dsim->dsi[id]) {
650 pr_err("%s: dsi%d already registered\n", __func__, id);
651 return -EBUSY;
652 }
653
654 msm_dsim->dsi[id] = msm_dsi;
655
656 ret = dsi_mgr_parse_of(msm_dsi->pdev->dev.of_node, id);
657 if (ret) {
658 pr_err("%s: failed to parse OF DSI info\n", __func__);
659 goto fail;
660 }
661
662 ret = dsi_mgr_setup_components(id);
663 if (ret) {
664 pr_err("%s: failed to register mipi dsi host for DSI %d: %d\n",
665 __func__, id, ret);
666 goto fail;
667 }
668
669 return 0;
670
671 fail:
672 msm_dsim->dsi[id] = NULL;
673 return ret;
674 }
675
msm_dsi_manager_unregister(struct msm_dsi * msm_dsi)676 void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi)
677 {
678 struct msm_dsi_manager *msm_dsim = &msm_dsim_glb;
679
680 if (msm_dsi->host)
681 msm_dsi_host_unregister(msm_dsi->host);
682
683 if (msm_dsi->id >= 0)
684 msm_dsim->dsi[msm_dsi->id] = NULL;
685 }
686
msm_dsi_is_bonded_dsi(struct msm_dsi * msm_dsi)687 bool msm_dsi_is_bonded_dsi(struct msm_dsi *msm_dsi)
688 {
689 return IS_BONDED_DSI();
690 }
691
msm_dsi_is_master_dsi(struct msm_dsi * msm_dsi)692 bool msm_dsi_is_master_dsi(struct msm_dsi *msm_dsi)
693 {
694 return IS_MASTER_DSI_LINK(msm_dsi->id);
695 }
696