dsi_manager.c 19 KB

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