dsi_manager.c 24 KB

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