dsi_manager.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  4. */
  5. #include "drm/drm_bridge_connector.h"
  6. #include "msm_kms.h"
  7. #include "dsi.h"
  8. #define DSI_CLOCK_MASTER DSI_0
  9. #define DSI_CLOCK_SLAVE DSI_1
  10. #define DSI_LEFT DSI_0
  11. #define DSI_RIGHT DSI_1
  12. /* According to the current drm framework sequence, take the encoder of
  13. * DSI_1 as master encoder
  14. */
  15. #define DSI_ENCODER_MASTER DSI_1
  16. #define DSI_ENCODER_SLAVE DSI_0
  17. struct msm_dsi_manager {
  18. struct msm_dsi *dsi[DSI_MAX];
  19. bool is_bonded_dsi;
  20. bool is_sync_needed;
  21. int master_dsi_link_id;
  22. };
  23. static struct msm_dsi_manager msm_dsim_glb;
  24. #define IS_BONDED_DSI() (msm_dsim_glb.is_bonded_dsi)
  25. #define IS_SYNC_NEEDED() (msm_dsim_glb.is_sync_needed)
  26. #define IS_MASTER_DSI_LINK(id) (msm_dsim_glb.master_dsi_link_id == id)
  27. static inline struct msm_dsi *dsi_mgr_get_dsi(int id)
  28. {
  29. return msm_dsim_glb.dsi[id];
  30. }
  31. static inline struct msm_dsi *dsi_mgr_get_other_dsi(int id)
  32. {
  33. return msm_dsim_glb.dsi[(id + 1) % DSI_MAX];
  34. }
  35. static int dsi_mgr_parse_of(struct device_node *np, int id)
  36. {
  37. struct msm_dsi_manager *msm_dsim = &msm_dsim_glb;
  38. /* We assume 2 dsi nodes have the same information of bonded dsi and
  39. * sync-mode, and only one node specifies master in case of bonded mode.
  40. */
  41. if (!msm_dsim->is_bonded_dsi)
  42. msm_dsim->is_bonded_dsi = of_property_read_bool(np, "qcom,dual-dsi-mode");
  43. if (msm_dsim->is_bonded_dsi) {
  44. if (of_property_read_bool(np, "qcom,master-dsi"))
  45. msm_dsim->master_dsi_link_id = id;
  46. if (!msm_dsim->is_sync_needed)
  47. msm_dsim->is_sync_needed = of_property_read_bool(
  48. np, "qcom,sync-dual-dsi");
  49. }
  50. return 0;
  51. }
  52. static int dsi_mgr_setup_components(int id)
  53. {
  54. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  55. struct msm_dsi *other_dsi = dsi_mgr_get_other_dsi(id);
  56. struct msm_dsi *clk_master_dsi = dsi_mgr_get_dsi(DSI_CLOCK_MASTER);
  57. struct msm_dsi *clk_slave_dsi = dsi_mgr_get_dsi(DSI_CLOCK_SLAVE);
  58. int ret;
  59. if (!IS_BONDED_DSI()) {
  60. /*
  61. * Set the usecase before calling msm_dsi_host_register(), which would
  62. * already program the PLL source mux based on a default usecase.
  63. */
  64. msm_dsi_phy_set_usecase(msm_dsi->phy, MSM_DSI_PHY_STANDALONE);
  65. msm_dsi_host_set_phy_mode(msm_dsi->host, msm_dsi->phy);
  66. ret = msm_dsi_host_register(msm_dsi->host);
  67. if (ret)
  68. return ret;
  69. } else if (other_dsi) {
  70. struct msm_dsi *master_link_dsi = IS_MASTER_DSI_LINK(id) ?
  71. msm_dsi : other_dsi;
  72. struct msm_dsi *slave_link_dsi = IS_MASTER_DSI_LINK(id) ?
  73. other_dsi : msm_dsi;
  74. /*
  75. * PLL0 is to drive both DSI link clocks in bonded DSI mode.
  76. *
  77. * Set the usecase before calling msm_dsi_host_register(), which would
  78. * already program the PLL source mux based on a default usecase.
  79. */
  80. msm_dsi_phy_set_usecase(clk_master_dsi->phy,
  81. MSM_DSI_PHY_MASTER);
  82. msm_dsi_phy_set_usecase(clk_slave_dsi->phy,
  83. MSM_DSI_PHY_SLAVE);
  84. msm_dsi_host_set_phy_mode(msm_dsi->host, msm_dsi->phy);
  85. msm_dsi_host_set_phy_mode(other_dsi->host, other_dsi->phy);
  86. /* Register slave host first, so that slave DSI device
  87. * has a chance to probe, and do not block the master
  88. * DSI device's probe.
  89. * Also, do not check defer for the slave host,
  90. * because only master DSI device adds the panel to global
  91. * panel list. The panel's device is the master DSI device.
  92. */
  93. ret = msm_dsi_host_register(slave_link_dsi->host);
  94. if (ret)
  95. return ret;
  96. ret = msm_dsi_host_register(master_link_dsi->host);
  97. if (ret)
  98. return ret;
  99. }
  100. return 0;
  101. }
  102. static int enable_phy(struct msm_dsi *msm_dsi,
  103. struct msm_dsi_phy_shared_timings *shared_timings)
  104. {
  105. struct msm_dsi_phy_clk_request clk_req;
  106. bool is_bonded_dsi = IS_BONDED_DSI();
  107. msm_dsi_host_get_phy_clk_req(msm_dsi->host, &clk_req, is_bonded_dsi);
  108. return msm_dsi_phy_enable(msm_dsi->phy, &clk_req, shared_timings);
  109. }
  110. static int
  111. dsi_mgr_phy_enable(int id,
  112. struct msm_dsi_phy_shared_timings shared_timings[DSI_MAX])
  113. {
  114. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  115. struct msm_dsi *mdsi = dsi_mgr_get_dsi(DSI_CLOCK_MASTER);
  116. struct msm_dsi *sdsi = dsi_mgr_get_dsi(DSI_CLOCK_SLAVE);
  117. int ret;
  118. /* In case of bonded DSI, some registers in PHY1 have been programmed
  119. * during PLL0 clock's set_rate. The PHY1 reset called by host1 here
  120. * will silently reset those PHY1 registers. Therefore we need to reset
  121. * and enable both PHYs before any PLL clock operation.
  122. */
  123. if (IS_BONDED_DSI() && mdsi && sdsi) {
  124. if (!mdsi->phy_enabled && !sdsi->phy_enabled) {
  125. msm_dsi_host_reset_phy(mdsi->host);
  126. msm_dsi_host_reset_phy(sdsi->host);
  127. ret = enable_phy(mdsi,
  128. &shared_timings[DSI_CLOCK_MASTER]);
  129. if (ret)
  130. return ret;
  131. ret = enable_phy(sdsi,
  132. &shared_timings[DSI_CLOCK_SLAVE]);
  133. if (ret) {
  134. msm_dsi_phy_disable(mdsi->phy);
  135. return ret;
  136. }
  137. }
  138. } else {
  139. msm_dsi_host_reset_phy(msm_dsi->host);
  140. ret = enable_phy(msm_dsi, &shared_timings[id]);
  141. if (ret)
  142. return ret;
  143. }
  144. msm_dsi->phy_enabled = true;
  145. return 0;
  146. }
  147. static void dsi_mgr_phy_disable(int id)
  148. {
  149. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  150. struct msm_dsi *mdsi = dsi_mgr_get_dsi(DSI_CLOCK_MASTER);
  151. struct msm_dsi *sdsi = dsi_mgr_get_dsi(DSI_CLOCK_SLAVE);
  152. /* disable DSI phy
  153. * In bonded dsi configuration, the phy should be disabled for the
  154. * first controller only when the second controller is disabled.
  155. */
  156. msm_dsi->phy_enabled = false;
  157. if (IS_BONDED_DSI() && mdsi && sdsi) {
  158. if (!mdsi->phy_enabled && !sdsi->phy_enabled) {
  159. msm_dsi_phy_disable(sdsi->phy);
  160. msm_dsi_phy_disable(mdsi->phy);
  161. }
  162. } else {
  163. msm_dsi_phy_disable(msm_dsi->phy);
  164. }
  165. }
  166. struct dsi_bridge {
  167. struct drm_bridge base;
  168. int id;
  169. };
  170. #define to_dsi_bridge(x) container_of(x, struct dsi_bridge, base)
  171. static int dsi_mgr_bridge_get_id(struct drm_bridge *bridge)
  172. {
  173. struct dsi_bridge *dsi_bridge = to_dsi_bridge(bridge);
  174. return dsi_bridge->id;
  175. }
  176. static int dsi_mgr_bridge_power_on(struct drm_bridge *bridge)
  177. {
  178. int id = dsi_mgr_bridge_get_id(bridge);
  179. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  180. struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1);
  181. struct mipi_dsi_host *host = msm_dsi->host;
  182. struct msm_dsi_phy_shared_timings phy_shared_timings[DSI_MAX];
  183. bool is_bonded_dsi = IS_BONDED_DSI();
  184. int ret;
  185. DBG("id=%d", id);
  186. ret = dsi_mgr_phy_enable(id, phy_shared_timings);
  187. if (ret)
  188. goto phy_en_fail;
  189. ret = msm_dsi_host_power_on(host, &phy_shared_timings[id], is_bonded_dsi, msm_dsi->phy);
  190. if (ret) {
  191. pr_err("%s: power on host %d failed, %d\n", __func__, id, ret);
  192. goto host_on_fail;
  193. }
  194. if (is_bonded_dsi && msm_dsi1) {
  195. ret = msm_dsi_host_power_on(msm_dsi1->host,
  196. &phy_shared_timings[DSI_1], is_bonded_dsi, msm_dsi1->phy);
  197. if (ret) {
  198. pr_err("%s: power on host1 failed, %d\n",
  199. __func__, ret);
  200. goto host1_on_fail;
  201. }
  202. }
  203. /*
  204. * Enable before preparing the panel, disable after unpreparing, so
  205. * that the panel can communicate over the DSI link.
  206. */
  207. msm_dsi_host_enable_irq(host);
  208. if (is_bonded_dsi && msm_dsi1)
  209. msm_dsi_host_enable_irq(msm_dsi1->host);
  210. return 0;
  211. host1_on_fail:
  212. msm_dsi_host_power_off(host);
  213. host_on_fail:
  214. dsi_mgr_phy_disable(id);
  215. phy_en_fail:
  216. return ret;
  217. }
  218. static void dsi_mgr_bridge_power_off(struct drm_bridge *bridge)
  219. {
  220. int id = dsi_mgr_bridge_get_id(bridge);
  221. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  222. struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1);
  223. struct mipi_dsi_host *host = msm_dsi->host;
  224. bool is_bonded_dsi = IS_BONDED_DSI();
  225. msm_dsi_host_disable_irq(host);
  226. if (is_bonded_dsi && msm_dsi1) {
  227. msm_dsi_host_disable_irq(msm_dsi1->host);
  228. msm_dsi_host_power_off(msm_dsi1->host);
  229. }
  230. msm_dsi_host_power_off(host);
  231. dsi_mgr_phy_disable(id);
  232. }
  233. static void dsi_mgr_bridge_pre_enable(struct drm_bridge *bridge)
  234. {
  235. int id = dsi_mgr_bridge_get_id(bridge);
  236. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  237. struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1);
  238. struct mipi_dsi_host *host = msm_dsi->host;
  239. bool is_bonded_dsi = IS_BONDED_DSI();
  240. int ret;
  241. DBG("id=%d", id);
  242. /* Do nothing with the host if it is slave-DSI in case of bonded DSI */
  243. if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id))
  244. return;
  245. ret = dsi_mgr_bridge_power_on(bridge);
  246. if (ret) {
  247. dev_err(&msm_dsi->pdev->dev, "Power on failed: %d\n", ret);
  248. return;
  249. }
  250. ret = msm_dsi_host_enable(host);
  251. if (ret) {
  252. pr_err("%s: enable host %d failed, %d\n", __func__, id, ret);
  253. goto host_en_fail;
  254. }
  255. if (is_bonded_dsi && msm_dsi1) {
  256. ret = msm_dsi_host_enable(msm_dsi1->host);
  257. if (ret) {
  258. pr_err("%s: enable host1 failed, %d\n", __func__, ret);
  259. goto host1_en_fail;
  260. }
  261. }
  262. return;
  263. host1_en_fail:
  264. msm_dsi_host_disable(host);
  265. host_en_fail:
  266. dsi_mgr_bridge_power_off(bridge);
  267. }
  268. void msm_dsi_manager_tpg_enable(void)
  269. {
  270. struct msm_dsi *m_dsi = dsi_mgr_get_dsi(DSI_0);
  271. struct msm_dsi *s_dsi = dsi_mgr_get_dsi(DSI_1);
  272. /* if dual dsi, trigger tpg on master first then slave */
  273. if (m_dsi) {
  274. msm_dsi_host_test_pattern_en(m_dsi->host);
  275. if (IS_BONDED_DSI() && s_dsi)
  276. msm_dsi_host_test_pattern_en(s_dsi->host);
  277. }
  278. }
  279. static void dsi_mgr_bridge_post_disable(struct drm_bridge *bridge)
  280. {
  281. int id = dsi_mgr_bridge_get_id(bridge);
  282. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  283. struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1);
  284. struct mipi_dsi_host *host = msm_dsi->host;
  285. bool is_bonded_dsi = IS_BONDED_DSI();
  286. int ret;
  287. DBG("id=%d", id);
  288. /*
  289. * Do nothing with the host if it is slave-DSI in case of bonded DSI.
  290. * It is safe to call dsi_mgr_phy_disable() here because a single PHY
  291. * won't be diabled until both PHYs request disable.
  292. */
  293. if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id))
  294. goto disable_phy;
  295. ret = msm_dsi_host_disable(host);
  296. if (ret)
  297. pr_err("%s: host %d disable failed, %d\n", __func__, id, ret);
  298. if (is_bonded_dsi && msm_dsi1) {
  299. ret = msm_dsi_host_disable(msm_dsi1->host);
  300. if (ret)
  301. pr_err("%s: host1 disable failed, %d\n", __func__, ret);
  302. }
  303. msm_dsi_host_disable_irq(host);
  304. if (is_bonded_dsi && msm_dsi1)
  305. msm_dsi_host_disable_irq(msm_dsi1->host);
  306. /* Save PHY status if it is a clock source */
  307. msm_dsi_phy_pll_save_state(msm_dsi->phy);
  308. ret = msm_dsi_host_power_off(host);
  309. if (ret)
  310. pr_err("%s: host %d power off failed,%d\n", __func__, id, ret);
  311. if (is_bonded_dsi && msm_dsi1) {
  312. ret = msm_dsi_host_power_off(msm_dsi1->host);
  313. if (ret)
  314. pr_err("%s: host1 power off failed, %d\n",
  315. __func__, ret);
  316. }
  317. disable_phy:
  318. dsi_mgr_phy_disable(id);
  319. }
  320. static void dsi_mgr_bridge_mode_set(struct drm_bridge *bridge,
  321. const struct drm_display_mode *mode,
  322. const struct drm_display_mode *adjusted_mode)
  323. {
  324. int id = dsi_mgr_bridge_get_id(bridge);
  325. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  326. struct msm_dsi *other_dsi = dsi_mgr_get_other_dsi(id);
  327. struct mipi_dsi_host *host = msm_dsi->host;
  328. bool is_bonded_dsi = IS_BONDED_DSI();
  329. DBG("set mode: " DRM_MODE_FMT, DRM_MODE_ARG(mode));
  330. if (is_bonded_dsi && !IS_MASTER_DSI_LINK(id))
  331. return;
  332. msm_dsi_host_set_display_mode(host, adjusted_mode);
  333. if (is_bonded_dsi && other_dsi)
  334. msm_dsi_host_set_display_mode(other_dsi->host, adjusted_mode);
  335. }
  336. static enum drm_mode_status dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge,
  337. const struct drm_display_info *info,
  338. const struct drm_display_mode *mode)
  339. {
  340. int id = dsi_mgr_bridge_get_id(bridge);
  341. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  342. struct mipi_dsi_host *host = msm_dsi->host;
  343. struct platform_device *pdev = msm_dsi->pdev;
  344. struct dev_pm_opp *opp;
  345. unsigned long byte_clk_rate;
  346. byte_clk_rate = dsi_byte_clk_get_rate(host, IS_BONDED_DSI(), mode);
  347. opp = dev_pm_opp_find_freq_ceil(&pdev->dev, &byte_clk_rate);
  348. if (!IS_ERR(opp)) {
  349. dev_pm_opp_put(opp);
  350. } else if (PTR_ERR(opp) == -ERANGE) {
  351. /*
  352. * An empty table is created by devm_pm_opp_set_clkname() even
  353. * if there is none. Thus find_freq_ceil will still return
  354. * -ERANGE in such case.
  355. */
  356. if (dev_pm_opp_get_opp_count(&pdev->dev) != 0)
  357. return MODE_CLOCK_RANGE;
  358. } else {
  359. return MODE_ERROR;
  360. }
  361. return msm_dsi_host_check_dsc(host, mode);
  362. }
  363. static int dsi_mgr_bridge_attach(struct drm_bridge *bridge,
  364. enum drm_bridge_attach_flags flags)
  365. {
  366. int id = dsi_mgr_bridge_get_id(bridge);
  367. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  368. return drm_bridge_attach(bridge->encoder, msm_dsi->next_bridge,
  369. bridge, flags);
  370. }
  371. static const struct drm_bridge_funcs dsi_mgr_bridge_funcs = {
  372. .attach = dsi_mgr_bridge_attach,
  373. .pre_enable = dsi_mgr_bridge_pre_enable,
  374. .post_disable = dsi_mgr_bridge_post_disable,
  375. .mode_set = dsi_mgr_bridge_mode_set,
  376. .mode_valid = dsi_mgr_bridge_mode_valid,
  377. };
  378. /* initialize bridge */
  379. int msm_dsi_manager_connector_init(struct msm_dsi *msm_dsi,
  380. struct drm_encoder *encoder)
  381. {
  382. struct drm_device *dev = msm_dsi->dev;
  383. struct drm_bridge *bridge;
  384. struct dsi_bridge *dsi_bridge;
  385. struct drm_connector *connector;
  386. int ret;
  387. dsi_bridge = devm_kzalloc(msm_dsi->dev->dev,
  388. sizeof(*dsi_bridge), GFP_KERNEL);
  389. if (!dsi_bridge)
  390. return -ENOMEM;
  391. dsi_bridge->id = msm_dsi->id;
  392. bridge = &dsi_bridge->base;
  393. bridge->funcs = &dsi_mgr_bridge_funcs;
  394. ret = devm_drm_bridge_add(msm_dsi->dev->dev, bridge);
  395. if (ret)
  396. return ret;
  397. ret = drm_bridge_attach(encoder, bridge, NULL, DRM_BRIDGE_ATTACH_NO_CONNECTOR);
  398. if (ret)
  399. return ret;
  400. connector = drm_bridge_connector_init(dev, encoder);
  401. if (IS_ERR(connector)) {
  402. DRM_ERROR("Unable to create bridge connector\n");
  403. return PTR_ERR(connector);
  404. }
  405. ret = drm_connector_attach_encoder(connector, encoder);
  406. if (ret < 0)
  407. return ret;
  408. return 0;
  409. }
  410. int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg)
  411. {
  412. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  413. struct msm_dsi *msm_dsi0 = dsi_mgr_get_dsi(DSI_0);
  414. struct mipi_dsi_host *host = msm_dsi->host;
  415. bool is_read = (msg->rx_buf && msg->rx_len);
  416. bool need_sync = (IS_SYNC_NEEDED() && !is_read);
  417. int ret;
  418. if (!msg->tx_buf || !msg->tx_len)
  419. return 0;
  420. /* In bonded master case, panel requires the same commands sent to
  421. * both DSI links. Host issues the command trigger to both links
  422. * when DSI_1 calls the cmd transfer function, no matter it happens
  423. * before or after DSI_0 cmd transfer.
  424. */
  425. if (need_sync && (id == DSI_0))
  426. return is_read ? msg->rx_len : msg->tx_len;
  427. if (need_sync && msm_dsi0) {
  428. ret = msm_dsi_host_xfer_prepare(msm_dsi0->host, msg);
  429. if (ret) {
  430. pr_err("%s: failed to prepare non-trigger host, %d\n",
  431. __func__, ret);
  432. return ret;
  433. }
  434. }
  435. ret = msm_dsi_host_xfer_prepare(host, msg);
  436. if (ret) {
  437. pr_err("%s: failed to prepare host, %d\n", __func__, ret);
  438. goto restore_host0;
  439. }
  440. ret = is_read ? msm_dsi_host_cmd_rx(host, msg) :
  441. msm_dsi_host_cmd_tx(host, msg);
  442. msm_dsi_host_xfer_restore(host, msg);
  443. restore_host0:
  444. if (need_sync && msm_dsi0)
  445. msm_dsi_host_xfer_restore(msm_dsi0->host, msg);
  446. return ret;
  447. }
  448. bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len)
  449. {
  450. struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  451. struct msm_dsi *msm_dsi0 = dsi_mgr_get_dsi(DSI_0);
  452. struct mipi_dsi_host *host = msm_dsi->host;
  453. if (IS_SYNC_NEEDED() && (id == DSI_0))
  454. return false;
  455. if (IS_SYNC_NEEDED() && msm_dsi0)
  456. msm_dsi_host_cmd_xfer_commit(msm_dsi0->host, dma_base, len);
  457. msm_dsi_host_cmd_xfer_commit(host, dma_base, len);
  458. return true;
  459. }
  460. int msm_dsi_manager_register(struct msm_dsi *msm_dsi)
  461. {
  462. struct msm_dsi_manager *msm_dsim = &msm_dsim_glb;
  463. int id = msm_dsi->id;
  464. int ret;
  465. if (id >= DSI_MAX) {
  466. pr_err("%s: invalid id %d\n", __func__, id);
  467. return -EINVAL;
  468. }
  469. if (msm_dsim->dsi[id]) {
  470. pr_err("%s: dsi%d already registered\n", __func__, id);
  471. return -EBUSY;
  472. }
  473. msm_dsim->dsi[id] = msm_dsi;
  474. ret = dsi_mgr_parse_of(msm_dsi->pdev->dev.of_node, id);
  475. if (ret) {
  476. pr_err("%s: failed to parse OF DSI info\n", __func__);
  477. goto fail;
  478. }
  479. ret = dsi_mgr_setup_components(id);
  480. if (ret) {
  481. pr_err("%s: failed to register mipi dsi host for DSI %d: %d\n",
  482. __func__, id, ret);
  483. goto fail;
  484. }
  485. return 0;
  486. fail:
  487. msm_dsim->dsi[id] = NULL;
  488. return ret;
  489. }
  490. void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi)
  491. {
  492. struct msm_dsi_manager *msm_dsim = &msm_dsim_glb;
  493. if (msm_dsi->host)
  494. msm_dsi_host_unregister(msm_dsi->host);
  495. if (msm_dsi->id >= 0)
  496. msm_dsim->dsi[msm_dsi->id] = NULL;
  497. }
  498. bool msm_dsi_is_bonded_dsi(struct msm_dsi *msm_dsi)
  499. {
  500. return IS_BONDED_DSI();
  501. }
  502. bool msm_dsi_is_master_dsi(struct msm_dsi *msm_dsi)
  503. {
  504. return IS_MASTER_DSI_LINK(msm_dsi->id);
  505. }
  506. const char *msm_dsi_get_te_source(struct msm_dsi *msm_dsi)
  507. {
  508. return msm_dsi->te_source;
  509. }