dsi_manager.c 22 KB

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