dsi_manager.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. /*
  2. * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include "msm_kms.h"
  14. #include "dsi.h"
  15. struct msm_dsi_manager {
  16. struct msm_dsi *dsi[DSI_MAX];
  17. bool is_dual_panel;
  18. bool is_sync_needed;
  19. int master_panel_id;
  20. };
  21. static struct msm_dsi_manager msm_dsim_glb;
  22. #define IS_DUAL_PANEL() (msm_dsim_glb.is_dual_panel)
  23. #define IS_SYNC_NEEDED() (msm_dsim_glb.is_sync_needed)
  24. #define IS_MASTER_PANEL(id) (msm_dsim_glb.master_panel_id == id)
  25. static inline struct msm_dsi *dsi_mgr_get_dsi(int id)
  26. {
  27. return msm_dsim_glb.dsi[id];
  28. }
  29. static inline struct msm_dsi *dsi_mgr_get_other_dsi(int id)
  30. {
  31. return msm_dsim_glb.dsi[(id + 1) % DSI_MAX];
  32. }
  33. static int dsi_mgr_parse_dual_panel(struct device_node *np, int id)
  34. {
  35. struct msm_dsi_manager *msm_dsim = &msm_dsim_glb;
  36. /* We assume 2 dsi nodes have the same information of dual-panel and
  37. * sync-mode, and only one node specifies master in case of dual mode.
  38. */
  39. if (!msm_dsim->is_dual_panel)
  40. msm_dsim->is_dual_panel = of_property_read_bool(
  41. np, "qcom,dual-panel-mode");
  42. if (msm_dsim->is_dual_panel) {
  43. if (of_property_read_bool(np, "qcom,master-panel"))
  44. msm_dsim->master_panel_id = id;
  45. if (!msm_dsim->is_sync_needed)
  46. msm_dsim->is_sync_needed = of_property_read_bool(
  47. np, "qcom,sync-dual-panel");
  48. }
  49. return 0;
  50. }
  51. struct dsi_connector {
  52. struct drm_connector base;
  53. int id;
  54. };
  55. struct dsi_bridge {
  56. struct drm_bridge base;
  57. int id;
  58. };
  59. #define to_dsi_connector(x) container_of(x, struct dsi_connector, base)
  60. #define to_dsi_bridge(x) container_of(x, struct dsi_bridge, base)
  61. static inline int dsi_mgr_connector_get_id(struct drm_connector *connector)
  62. {
  63. struct dsi_connector *dsi_connector = to_dsi_connector(connector);
  64. return dsi_connector->id;
  65. }
  66. static int dsi_mgr_bridge_get_id(struct drm_bridge *bridge)
  67. {
  68. struct dsi_bridge *dsi_bridge = to_dsi_bridge(bridge);
  69. return dsi_bridge->id;
  70. }
  71. static enum drm_connector_status dsi_mgr_connector_detect(
  72. struct drm_connector *connector, bool force)
  73. {
  74. int id = dsi_mgr_connector_get_id(connector);
  75. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  76. struct msm_dsi *other_dsi = dsi_mgr_get_other_dsi(id);
  77. struct msm_drm_private *priv = connector->dev->dev_private;
  78. struct msm_kms *kms = priv->kms;
  79. DBG("id=%d", id);
  80. if (!msm_dsi->panel) {
  81. msm_dsi->panel = msm_dsi_host_get_panel(msm_dsi->host,
  82. &msm_dsi->panel_flags);
  83. /* There is only 1 panel in the global panel list
  84. * for dual panel mode. Therefore slave dsi should get
  85. * the drm_panel instance from master dsi, and
  86. * keep using the panel flags got from the current DSI link.
  87. */
  88. if (!msm_dsi->panel && IS_DUAL_PANEL() &&
  89. !IS_MASTER_PANEL(id) && other_dsi)
  90. msm_dsi->panel = msm_dsi_host_get_panel(
  91. other_dsi->host, NULL);
  92. if (msm_dsi->panel && IS_DUAL_PANEL())
  93. drm_object_attach_property(&connector->base,
  94. connector->dev->mode_config.tile_property, 0);
  95. /* Set split display info to kms once dual panel is connected
  96. * to both hosts
  97. */
  98. if (msm_dsi->panel && IS_DUAL_PANEL() &&
  99. other_dsi && other_dsi->panel) {
  100. bool cmd_mode = !(msm_dsi->panel_flags &
  101. MIPI_DSI_MODE_VIDEO);
  102. struct drm_encoder *encoder = msm_dsi_get_encoder(
  103. dsi_mgr_get_dsi(DSI_ENCODER_MASTER));
  104. struct drm_encoder *slave_enc = msm_dsi_get_encoder(
  105. dsi_mgr_get_dsi(DSI_ENCODER_SLAVE));
  106. if (kms->funcs->set_split_display)
  107. kms->funcs->set_split_display(kms, encoder,
  108. slave_enc, cmd_mode);
  109. else
  110. pr_err("mdp does not support dual panel\n");
  111. }
  112. }
  113. return msm_dsi->panel ? connector_status_connected :
  114. connector_status_disconnected;
  115. }
  116. static void dsi_mgr_connector_destroy(struct drm_connector *connector)
  117. {
  118. DBG("");
  119. drm_connector_unregister(connector);
  120. drm_connector_cleanup(connector);
  121. }
  122. static void dsi_dual_connector_fix_modes(struct drm_connector *connector)
  123. {
  124. struct drm_display_mode *mode, *m;
  125. /* Only support left-right mode */
  126. list_for_each_entry_safe(mode, m, &connector->probed_modes, head) {
  127. mode->clock >>= 1;
  128. mode->hdisplay >>= 1;
  129. mode->hsync_start >>= 1;
  130. mode->hsync_end >>= 1;
  131. mode->htotal >>= 1;
  132. drm_mode_set_name(mode);
  133. }
  134. }
  135. static int dsi_dual_connector_tile_init(
  136. struct drm_connector *connector, int id)
  137. {
  138. struct drm_display_mode *mode;
  139. /* Fake topology id */
  140. char topo_id[8] = {'M', 'S', 'M', 'D', 'U', 'D', 'S', 'I'};
  141. if (connector->tile_group) {
  142. DBG("Tile property has been initialized");
  143. return 0;
  144. }
  145. /* Use the first mode only for now */
  146. mode = list_first_entry(&connector->probed_modes,
  147. struct drm_display_mode,
  148. head);
  149. if (!mode)
  150. return -EINVAL;
  151. connector->tile_group = drm_mode_get_tile_group(
  152. connector->dev, topo_id);
  153. if (!connector->tile_group)
  154. connector->tile_group = drm_mode_create_tile_group(
  155. connector->dev, topo_id);
  156. if (!connector->tile_group) {
  157. pr_err("%s: failed to create tile group\n", __func__);
  158. return -ENOMEM;
  159. }
  160. connector->has_tile = true;
  161. connector->tile_is_single_monitor = true;
  162. /* mode has been fixed */
  163. connector->tile_h_size = mode->hdisplay;
  164. connector->tile_v_size = mode->vdisplay;
  165. /* Only support left-right mode */
  166. connector->num_h_tile = 2;
  167. connector->num_v_tile = 1;
  168. connector->tile_v_loc = 0;
  169. connector->tile_h_loc = (id == DSI_RIGHT) ? 1 : 0;
  170. return 0;
  171. }
  172. static int dsi_mgr_connector_get_modes(struct drm_connector *connector)
  173. {
  174. int id = dsi_mgr_connector_get_id(connector);
  175. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  176. struct drm_panel *panel = msm_dsi->panel;
  177. int ret, num;
  178. if (!panel)
  179. return 0;
  180. /* Since we have 2 connectors, but only 1 drm_panel in dual DSI mode,
  181. * panel should not attach to any connector.
  182. * Only temporarily attach panel to the current connector here,
  183. * to let panel set mode to this connector.
  184. */
  185. drm_panel_attach(panel, connector);
  186. num = drm_panel_get_modes(panel);
  187. drm_panel_detach(panel);
  188. if (!num)
  189. return 0;
  190. if (IS_DUAL_PANEL()) {
  191. /* report half resolution to user */
  192. dsi_dual_connector_fix_modes(connector);
  193. ret = dsi_dual_connector_tile_init(connector, id);
  194. if (ret)
  195. return ret;
  196. ret = drm_mode_connector_set_tile_property(connector);
  197. if (ret) {
  198. pr_err("%s: set tile property failed, %d\n",
  199. __func__, ret);
  200. return ret;
  201. }
  202. }
  203. return num;
  204. }
  205. static int dsi_mgr_connector_mode_valid(struct drm_connector *connector,
  206. struct drm_display_mode *mode)
  207. {
  208. int id = dsi_mgr_connector_get_id(connector);
  209. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  210. struct drm_encoder *encoder = msm_dsi_get_encoder(msm_dsi);
  211. struct msm_drm_private *priv = connector->dev->dev_private;
  212. struct msm_kms *kms = priv->kms;
  213. long actual, requested;
  214. DBG("");
  215. requested = 1000 * mode->clock;
  216. actual = kms->funcs->round_pixclk(kms, requested, encoder);
  217. DBG("requested=%ld, actual=%ld", requested, actual);
  218. if (actual != requested)
  219. return MODE_CLOCK_RANGE;
  220. return MODE_OK;
  221. }
  222. static struct drm_encoder *
  223. dsi_mgr_connector_best_encoder(struct drm_connector *connector)
  224. {
  225. int id = dsi_mgr_connector_get_id(connector);
  226. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  227. DBG("");
  228. return msm_dsi_get_encoder(msm_dsi);
  229. }
  230. static void dsi_mgr_bridge_pre_enable(struct drm_bridge *bridge)
  231. {
  232. int id = dsi_mgr_bridge_get_id(bridge);
  233. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  234. struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1);
  235. struct mipi_dsi_host *host = msm_dsi->host;
  236. struct drm_panel *panel = msm_dsi->panel;
  237. bool is_dual_panel = IS_DUAL_PANEL();
  238. int ret;
  239. DBG("id=%d", id);
  240. if (!panel || (is_dual_panel && (DSI_1 == id)))
  241. return;
  242. ret = msm_dsi_host_power_on(host);
  243. if (ret) {
  244. pr_err("%s: power on host %d failed, %d\n", __func__, id, ret);
  245. goto host_on_fail;
  246. }
  247. if (is_dual_panel && msm_dsi1) {
  248. ret = msm_dsi_host_power_on(msm_dsi1->host);
  249. if (ret) {
  250. pr_err("%s: power on host1 failed, %d\n",
  251. __func__, ret);
  252. goto host1_on_fail;
  253. }
  254. }
  255. /* Always call panel functions once, because even for dual panels,
  256. * there is only one drm_panel instance.
  257. */
  258. ret = drm_panel_prepare(panel);
  259. if (ret) {
  260. pr_err("%s: prepare panel %d failed, %d\n", __func__, id, ret);
  261. goto panel_prep_fail;
  262. }
  263. ret = msm_dsi_host_enable(host);
  264. if (ret) {
  265. pr_err("%s: enable host %d failed, %d\n", __func__, id, ret);
  266. goto host_en_fail;
  267. }
  268. if (is_dual_panel && msm_dsi1) {
  269. ret = msm_dsi_host_enable(msm_dsi1->host);
  270. if (ret) {
  271. pr_err("%s: enable host1 failed, %d\n", __func__, ret);
  272. goto host1_en_fail;
  273. }
  274. }
  275. ret = drm_panel_enable(panel);
  276. if (ret) {
  277. pr_err("%s: enable panel %d failed, %d\n", __func__, id, ret);
  278. goto panel_en_fail;
  279. }
  280. return;
  281. panel_en_fail:
  282. if (is_dual_panel && msm_dsi1)
  283. msm_dsi_host_disable(msm_dsi1->host);
  284. host1_en_fail:
  285. msm_dsi_host_disable(host);
  286. host_en_fail:
  287. drm_panel_unprepare(panel);
  288. panel_prep_fail:
  289. if (is_dual_panel && msm_dsi1)
  290. msm_dsi_host_power_off(msm_dsi1->host);
  291. host1_on_fail:
  292. msm_dsi_host_power_off(host);
  293. host_on_fail:
  294. return;
  295. }
  296. static void dsi_mgr_bridge_enable(struct drm_bridge *bridge)
  297. {
  298. DBG("");
  299. }
  300. static void dsi_mgr_bridge_disable(struct drm_bridge *bridge)
  301. {
  302. DBG("");
  303. }
  304. static void dsi_mgr_bridge_post_disable(struct drm_bridge *bridge)
  305. {
  306. int id = dsi_mgr_bridge_get_id(bridge);
  307. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  308. struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1);
  309. struct mipi_dsi_host *host = msm_dsi->host;
  310. struct drm_panel *panel = msm_dsi->panel;
  311. bool is_dual_panel = IS_DUAL_PANEL();
  312. int ret;
  313. DBG("id=%d", id);
  314. if (!panel || (is_dual_panel && (DSI_1 == id)))
  315. return;
  316. ret = drm_panel_disable(panel);
  317. if (ret)
  318. pr_err("%s: Panel %d OFF failed, %d\n", __func__, id, ret);
  319. ret = msm_dsi_host_disable(host);
  320. if (ret)
  321. pr_err("%s: host %d disable failed, %d\n", __func__, id, ret);
  322. if (is_dual_panel && msm_dsi1) {
  323. ret = msm_dsi_host_disable(msm_dsi1->host);
  324. if (ret)
  325. pr_err("%s: host1 disable failed, %d\n", __func__, ret);
  326. }
  327. ret = drm_panel_unprepare(panel);
  328. if (ret)
  329. pr_err("%s: Panel %d unprepare failed,%d\n", __func__, id, ret);
  330. ret = msm_dsi_host_power_off(host);
  331. if (ret)
  332. pr_err("%s: host %d power off failed,%d\n", __func__, id, ret);
  333. if (is_dual_panel && msm_dsi1) {
  334. ret = msm_dsi_host_power_off(msm_dsi1->host);
  335. if (ret)
  336. pr_err("%s: host1 power off failed, %d\n",
  337. __func__, ret);
  338. }
  339. }
  340. static void dsi_mgr_bridge_mode_set(struct drm_bridge *bridge,
  341. struct drm_display_mode *mode,
  342. struct drm_display_mode *adjusted_mode)
  343. {
  344. int id = dsi_mgr_bridge_get_id(bridge);
  345. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  346. struct msm_dsi *other_dsi = dsi_mgr_get_other_dsi(id);
  347. struct mipi_dsi_host *host = msm_dsi->host;
  348. bool is_dual_panel = IS_DUAL_PANEL();
  349. DBG("set mode: %d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x",
  350. mode->base.id, mode->name,
  351. mode->vrefresh, mode->clock,
  352. mode->hdisplay, mode->hsync_start,
  353. mode->hsync_end, mode->htotal,
  354. mode->vdisplay, mode->vsync_start,
  355. mode->vsync_end, mode->vtotal,
  356. mode->type, mode->flags);
  357. if (is_dual_panel && (DSI_1 == id))
  358. return;
  359. msm_dsi_host_set_display_mode(host, adjusted_mode);
  360. if (is_dual_panel && other_dsi)
  361. msm_dsi_host_set_display_mode(other_dsi->host, adjusted_mode);
  362. }
  363. static const struct drm_connector_funcs dsi_mgr_connector_funcs = {
  364. .dpms = drm_atomic_helper_connector_dpms,
  365. .detect = dsi_mgr_connector_detect,
  366. .fill_modes = drm_helper_probe_single_connector_modes,
  367. .destroy = dsi_mgr_connector_destroy,
  368. .reset = drm_atomic_helper_connector_reset,
  369. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  370. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  371. };
  372. static const struct drm_connector_helper_funcs dsi_mgr_conn_helper_funcs = {
  373. .get_modes = dsi_mgr_connector_get_modes,
  374. .mode_valid = dsi_mgr_connector_mode_valid,
  375. .best_encoder = dsi_mgr_connector_best_encoder,
  376. };
  377. static const struct drm_bridge_funcs dsi_mgr_bridge_funcs = {
  378. .pre_enable = dsi_mgr_bridge_pre_enable,
  379. .enable = dsi_mgr_bridge_enable,
  380. .disable = dsi_mgr_bridge_disable,
  381. .post_disable = dsi_mgr_bridge_post_disable,
  382. .mode_set = dsi_mgr_bridge_mode_set,
  383. };
  384. /* initialize connector */
  385. struct drm_connector *msm_dsi_manager_connector_init(u8 id)
  386. {
  387. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  388. struct drm_connector *connector = NULL;
  389. struct dsi_connector *dsi_connector;
  390. int ret, i;
  391. dsi_connector = devm_kzalloc(msm_dsi->dev->dev,
  392. sizeof(*dsi_connector), GFP_KERNEL);
  393. if (!dsi_connector) {
  394. ret = -ENOMEM;
  395. goto fail;
  396. }
  397. dsi_connector->id = id;
  398. connector = &dsi_connector->base;
  399. ret = drm_connector_init(msm_dsi->dev, connector,
  400. &dsi_mgr_connector_funcs, DRM_MODE_CONNECTOR_DSI);
  401. if (ret)
  402. goto fail;
  403. drm_connector_helper_add(connector, &dsi_mgr_conn_helper_funcs);
  404. /* Enable HPD to let hpd event is handled
  405. * when panel is attached to the host.
  406. */
  407. connector->polled = DRM_CONNECTOR_POLL_HPD;
  408. /* Display driver doesn't support interlace now. */
  409. connector->interlace_allowed = 0;
  410. connector->doublescan_allowed = 0;
  411. ret = drm_connector_register(connector);
  412. if (ret)
  413. goto fail;
  414. for (i = 0; i < MSM_DSI_ENCODER_NUM; i++)
  415. drm_mode_connector_attach_encoder(connector,
  416. msm_dsi->encoders[i]);
  417. return connector;
  418. fail:
  419. if (connector)
  420. dsi_mgr_connector_destroy(connector);
  421. return ERR_PTR(ret);
  422. }
  423. /* initialize bridge */
  424. struct drm_bridge *msm_dsi_manager_bridge_init(u8 id)
  425. {
  426. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  427. struct drm_bridge *bridge = NULL;
  428. struct dsi_bridge *dsi_bridge;
  429. int ret;
  430. dsi_bridge = devm_kzalloc(msm_dsi->dev->dev,
  431. sizeof(*dsi_bridge), GFP_KERNEL);
  432. if (!dsi_bridge) {
  433. ret = -ENOMEM;
  434. goto fail;
  435. }
  436. dsi_bridge->id = id;
  437. bridge = &dsi_bridge->base;
  438. bridge->funcs = &dsi_mgr_bridge_funcs;
  439. ret = drm_bridge_attach(msm_dsi->dev, bridge);
  440. if (ret)
  441. goto fail;
  442. return bridge;
  443. fail:
  444. if (bridge)
  445. msm_dsi_manager_bridge_destroy(bridge);
  446. return ERR_PTR(ret);
  447. }
  448. void msm_dsi_manager_bridge_destroy(struct drm_bridge *bridge)
  449. {
  450. }
  451. int msm_dsi_manager_phy_enable(int id,
  452. const unsigned long bit_rate, const unsigned long esc_rate,
  453. u32 *clk_pre, u32 *clk_post)
  454. {
  455. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  456. struct msm_dsi_phy *phy = msm_dsi->phy;
  457. int ret;
  458. ret = msm_dsi_phy_enable(phy, IS_DUAL_PANEL(), bit_rate, esc_rate);
  459. if (ret)
  460. return ret;
  461. msm_dsi->phy_enabled = true;
  462. msm_dsi_phy_get_clk_pre_post(phy, clk_pre, clk_post);
  463. return 0;
  464. }
  465. void msm_dsi_manager_phy_disable(int id)
  466. {
  467. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  468. struct msm_dsi *mdsi = dsi_mgr_get_dsi(DSI_CLOCK_MASTER);
  469. struct msm_dsi *sdsi = dsi_mgr_get_dsi(DSI_CLOCK_SLAVE);
  470. struct msm_dsi_phy *phy = msm_dsi->phy;
  471. /* disable DSI phy
  472. * In dual-dsi configuration, the phy should be disabled for the
  473. * first controller only when the second controller is disabled.
  474. */
  475. msm_dsi->phy_enabled = false;
  476. if (IS_DUAL_PANEL() && mdsi && sdsi) {
  477. if (!mdsi->phy_enabled && !sdsi->phy_enabled) {
  478. msm_dsi_phy_disable(sdsi->phy);
  479. msm_dsi_phy_disable(mdsi->phy);
  480. }
  481. } else {
  482. msm_dsi_phy_disable(phy);
  483. }
  484. }
  485. int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg)
  486. {
  487. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  488. struct msm_dsi *msm_dsi0 = dsi_mgr_get_dsi(DSI_0);
  489. struct mipi_dsi_host *host = msm_dsi->host;
  490. bool is_read = (msg->rx_buf && msg->rx_len);
  491. bool need_sync = (IS_SYNC_NEEDED() && !is_read);
  492. int ret;
  493. if (!msg->tx_buf || !msg->tx_len)
  494. return 0;
  495. /* In dual master case, panel requires the same commands sent to
  496. * both DSI links. Host issues the command trigger to both links
  497. * when DSI_1 calls the cmd transfer function, no matter it happens
  498. * before or after DSI_0 cmd transfer.
  499. */
  500. if (need_sync && (id == DSI_0))
  501. return is_read ? msg->rx_len : msg->tx_len;
  502. if (need_sync && msm_dsi0) {
  503. ret = msm_dsi_host_xfer_prepare(msm_dsi0->host, msg);
  504. if (ret) {
  505. pr_err("%s: failed to prepare non-trigger host, %d\n",
  506. __func__, ret);
  507. return ret;
  508. }
  509. }
  510. ret = msm_dsi_host_xfer_prepare(host, msg);
  511. if (ret) {
  512. pr_err("%s: failed to prepare host, %d\n", __func__, ret);
  513. goto restore_host0;
  514. }
  515. ret = is_read ? msm_dsi_host_cmd_rx(host, msg) :
  516. msm_dsi_host_cmd_tx(host, msg);
  517. msm_dsi_host_xfer_restore(host, msg);
  518. restore_host0:
  519. if (need_sync && msm_dsi0)
  520. msm_dsi_host_xfer_restore(msm_dsi0->host, msg);
  521. return ret;
  522. }
  523. bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 iova, u32 len)
  524. {
  525. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  526. struct msm_dsi *msm_dsi0 = dsi_mgr_get_dsi(DSI_0);
  527. struct mipi_dsi_host *host = msm_dsi->host;
  528. if (IS_SYNC_NEEDED() && (id == DSI_0))
  529. return false;
  530. if (IS_SYNC_NEEDED() && msm_dsi0)
  531. msm_dsi_host_cmd_xfer_commit(msm_dsi0->host, iova, len);
  532. msm_dsi_host_cmd_xfer_commit(host, iova, len);
  533. return true;
  534. }
  535. int msm_dsi_manager_register(struct msm_dsi *msm_dsi)
  536. {
  537. struct msm_dsi_manager *msm_dsim = &msm_dsim_glb;
  538. int id = msm_dsi->id;
  539. struct msm_dsi *other_dsi = dsi_mgr_get_other_dsi(id);
  540. int ret;
  541. if (id > DSI_MAX) {
  542. pr_err("%s: invalid id %d\n", __func__, id);
  543. return -EINVAL;
  544. }
  545. if (msm_dsim->dsi[id]) {
  546. pr_err("%s: dsi%d already registered\n", __func__, id);
  547. return -EBUSY;
  548. }
  549. msm_dsim->dsi[id] = msm_dsi;
  550. ret = dsi_mgr_parse_dual_panel(msm_dsi->pdev->dev.of_node, id);
  551. if (ret) {
  552. pr_err("%s: failed to parse dual panel info\n", __func__);
  553. return ret;
  554. }
  555. if (!IS_DUAL_PANEL()) {
  556. ret = msm_dsi_host_register(msm_dsi->host, true);
  557. } else if (!other_dsi) {
  558. return 0;
  559. } else {
  560. struct msm_dsi *mdsi = IS_MASTER_PANEL(id) ?
  561. msm_dsi : other_dsi;
  562. struct msm_dsi *sdsi = IS_MASTER_PANEL(id) ?
  563. other_dsi : msm_dsi;
  564. /* Register slave host first, so that slave DSI device
  565. * has a chance to probe, and do not block the master
  566. * DSI device's probe.
  567. * Also, do not check defer for the slave host,
  568. * because only master DSI device adds the panel to global
  569. * panel list. The panel's device is the master DSI device.
  570. */
  571. ret = msm_dsi_host_register(sdsi->host, false);
  572. if (ret)
  573. return ret;
  574. ret = msm_dsi_host_register(mdsi->host, true);
  575. }
  576. return ret;
  577. }
  578. void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi)
  579. {
  580. struct msm_dsi_manager *msm_dsim = &msm_dsim_glb;
  581. if (msm_dsi->host)
  582. msm_dsi_host_unregister(msm_dsi->host);
  583. msm_dsim->dsi[msm_dsi->id] = NULL;
  584. }