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