dsi_drm.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <drm/drm_atomic_helper.h>
  6. #include <drm/drm_atomic.h>
  7. #include "msm_kms.h"
  8. #include "sde_connector.h"
  9. #include "dsi_drm.h"
  10. #include "sde_trace.h"
  11. #include "sde_dbg.h"
  12. #include "msm_drv.h"
  13. #include "sde_encoder.h"
  14. #define to_dsi_bridge(x) container_of((x), struct dsi_bridge, base)
  15. #define to_dsi_state(x) container_of((x), struct dsi_connector_state, base)
  16. #define DEFAULT_PANEL_JITTER_NUMERATOR 2
  17. #define DEFAULT_PANEL_JITTER_DENOMINATOR 1
  18. #define DEFAULT_PANEL_JITTER_ARRAY_SIZE 2
  19. #define DEFAULT_PANEL_PREFILL_LINES 25
  20. static struct dsi_display_mode_priv_info default_priv_info = {
  21. .panel_jitter_numer = DEFAULT_PANEL_JITTER_NUMERATOR,
  22. .panel_jitter_denom = DEFAULT_PANEL_JITTER_DENOMINATOR,
  23. .panel_prefill_lines = DEFAULT_PANEL_PREFILL_LINES,
  24. .dsc_enabled = false,
  25. };
  26. static void convert_to_dsi_mode(const struct drm_display_mode *drm_mode,
  27. struct dsi_display_mode *dsi_mode)
  28. {
  29. memset(dsi_mode, 0, sizeof(*dsi_mode));
  30. dsi_mode->timing.h_active = drm_mode->hdisplay;
  31. dsi_mode->timing.h_back_porch = drm_mode->htotal - drm_mode->hsync_end;
  32. dsi_mode->timing.h_sync_width = drm_mode->htotal -
  33. (drm_mode->hsync_start + dsi_mode->timing.h_back_porch);
  34. dsi_mode->timing.h_front_porch = drm_mode->hsync_start -
  35. drm_mode->hdisplay;
  36. dsi_mode->timing.h_skew = drm_mode->hskew;
  37. dsi_mode->timing.v_active = drm_mode->vdisplay;
  38. dsi_mode->timing.v_back_porch = drm_mode->vtotal - drm_mode->vsync_end;
  39. dsi_mode->timing.v_sync_width = drm_mode->vtotal -
  40. (drm_mode->vsync_start + dsi_mode->timing.v_back_porch);
  41. dsi_mode->timing.v_front_porch = drm_mode->vsync_start -
  42. drm_mode->vdisplay;
  43. dsi_mode->timing.refresh_rate = drm_mode_vrefresh(drm_mode);
  44. dsi_mode->timing.h_sync_polarity =
  45. !!(drm_mode->flags & DRM_MODE_FLAG_PHSYNC);
  46. dsi_mode->timing.v_sync_polarity =
  47. !!(drm_mode->flags & DRM_MODE_FLAG_PVSYNC);
  48. }
  49. static void msm_parse_mode_priv_info(const struct msm_display_mode *msm_mode,
  50. struct dsi_display_mode *dsi_mode)
  51. {
  52. dsi_mode->priv_info =
  53. (struct dsi_display_mode_priv_info *)msm_mode->private;
  54. if (dsi_mode->priv_info) {
  55. dsi_mode->timing.dsc_enabled = dsi_mode->priv_info->dsc_enabled;
  56. dsi_mode->timing.dsc = &dsi_mode->priv_info->dsc;
  57. dsi_mode->timing.vdc_enabled = dsi_mode->priv_info->vdc_enabled;
  58. dsi_mode->timing.vdc = &dsi_mode->priv_info->vdc;
  59. dsi_mode->timing.pclk_scale = dsi_mode->priv_info->pclk_scale;
  60. }
  61. if (msm_is_mode_seamless(msm_mode))
  62. dsi_mode->dsi_mode_flags |= DSI_MODE_FLAG_SEAMLESS;
  63. if (msm_is_mode_dynamic_fps(msm_mode))
  64. dsi_mode->dsi_mode_flags |= DSI_MODE_FLAG_DFPS;
  65. if (msm_needs_vblank_pre_modeset(msm_mode))
  66. dsi_mode->dsi_mode_flags |= DSI_MODE_FLAG_VBLANK_PRE_MODESET;
  67. if (msm_is_mode_seamless_dms(msm_mode))
  68. dsi_mode->dsi_mode_flags |= DSI_MODE_FLAG_DMS;
  69. if (msm_is_mode_seamless_vrr(msm_mode))
  70. dsi_mode->dsi_mode_flags |= DSI_MODE_FLAG_VRR;
  71. if (msm_is_mode_seamless_poms_to_vid(msm_mode))
  72. dsi_mode->dsi_mode_flags |= DSI_MODE_FLAG_POMS_TO_VID;
  73. if (msm_is_mode_seamless_poms_to_cmd(msm_mode))
  74. dsi_mode->dsi_mode_flags |= DSI_MODE_FLAG_POMS_TO_CMD;
  75. if (msm_is_mode_seamless_dyn_clk(msm_mode))
  76. dsi_mode->dsi_mode_flags |= DSI_MODE_FLAG_DYN_CLK;
  77. }
  78. void dsi_convert_to_drm_mode(const struct dsi_display_mode *dsi_mode,
  79. struct drm_display_mode *drm_mode)
  80. {
  81. char *panel_caps = "vid";
  82. if ((dsi_mode->panel_mode_caps & DSI_OP_VIDEO_MODE) &&
  83. (dsi_mode->panel_mode_caps & DSI_OP_CMD_MODE))
  84. panel_caps = "vid_cmd";
  85. else if (dsi_mode->panel_mode_caps & DSI_OP_VIDEO_MODE)
  86. panel_caps = "vid";
  87. else if (dsi_mode->panel_mode_caps & DSI_OP_CMD_MODE)
  88. panel_caps = "cmd";
  89. memset(drm_mode, 0, sizeof(*drm_mode));
  90. drm_mode->hdisplay = dsi_mode->timing.h_active;
  91. drm_mode->hsync_start = drm_mode->hdisplay +
  92. dsi_mode->timing.h_front_porch;
  93. drm_mode->hsync_end = drm_mode->hsync_start +
  94. dsi_mode->timing.h_sync_width;
  95. drm_mode->htotal = drm_mode->hsync_end + dsi_mode->timing.h_back_porch;
  96. drm_mode->hskew = dsi_mode->timing.h_skew;
  97. drm_mode->vdisplay = dsi_mode->timing.v_active;
  98. drm_mode->vsync_start = drm_mode->vdisplay +
  99. dsi_mode->timing.v_front_porch;
  100. drm_mode->vsync_end = drm_mode->vsync_start +
  101. dsi_mode->timing.v_sync_width;
  102. drm_mode->vtotal = drm_mode->vsync_end + dsi_mode->timing.v_back_porch;
  103. drm_mode->clock = drm_mode->htotal * drm_mode->vtotal * dsi_mode->timing.refresh_rate;
  104. drm_mode->clock /= 1000;
  105. if (dsi_mode->timing.h_sync_polarity)
  106. drm_mode->flags |= DRM_MODE_FLAG_PHSYNC;
  107. if (dsi_mode->timing.v_sync_polarity)
  108. drm_mode->flags |= DRM_MODE_FLAG_PVSYNC;
  109. /* set mode name */
  110. snprintf(drm_mode->name, DRM_DISPLAY_MODE_LEN, "%dx%dx%d%s",
  111. drm_mode->hdisplay, drm_mode->vdisplay,
  112. drm_mode_vrefresh(drm_mode), panel_caps);
  113. }
  114. static void dsi_convert_to_msm_mode(const struct dsi_display_mode *dsi_mode,
  115. struct msm_display_mode *msm_mode)
  116. {
  117. msm_mode->private_flags = 0;
  118. msm_mode->private = (int *)dsi_mode->priv_info;
  119. if (dsi_mode->dsi_mode_flags & DSI_MODE_FLAG_SEAMLESS)
  120. msm_mode->private_flags |= DRM_MODE_FLAG_SEAMLESS;
  121. if (dsi_mode->dsi_mode_flags & DSI_MODE_FLAG_DFPS)
  122. msm_mode->private_flags |= MSM_MODE_FLAG_SEAMLESS_DYNAMIC_FPS;
  123. if (dsi_mode->dsi_mode_flags & DSI_MODE_FLAG_VBLANK_PRE_MODESET)
  124. msm_mode->private_flags |= MSM_MODE_FLAG_VBLANK_PRE_MODESET;
  125. if (dsi_mode->dsi_mode_flags & DSI_MODE_FLAG_DMS)
  126. msm_mode->private_flags |= MSM_MODE_FLAG_SEAMLESS_DMS;
  127. if (dsi_mode->dsi_mode_flags & DSI_MODE_FLAG_VRR)
  128. msm_mode->private_flags |= MSM_MODE_FLAG_SEAMLESS_VRR;
  129. if (dsi_mode->dsi_mode_flags & DSI_MODE_FLAG_POMS_TO_VID)
  130. msm_mode->private_flags |= MSM_MODE_FLAG_SEAMLESS_POMS_VID;
  131. if (dsi_mode->dsi_mode_flags & DSI_MODE_FLAG_POMS_TO_CMD)
  132. msm_mode->private_flags |= MSM_MODE_FLAG_SEAMLESS_POMS_CMD;
  133. if (dsi_mode->dsi_mode_flags & DSI_MODE_FLAG_DYN_CLK)
  134. msm_mode->private_flags |= MSM_MODE_FLAG_SEAMLESS_DYN_CLK;
  135. }
  136. static int dsi_bridge_attach(struct drm_bridge *bridge,
  137. enum drm_bridge_attach_flags flags)
  138. {
  139. struct dsi_bridge *c_bridge = to_dsi_bridge(bridge);
  140. if (!bridge) {
  141. DSI_ERR("Invalid params\n");
  142. return -EINVAL;
  143. }
  144. DSI_DEBUG("[%d] attached\n", c_bridge->id);
  145. return 0;
  146. }
  147. static void dsi_bridge_pre_enable(struct drm_bridge *bridge)
  148. {
  149. int rc = 0;
  150. struct dsi_bridge *c_bridge = to_dsi_bridge(bridge);
  151. if (!bridge) {
  152. DSI_ERR("Invalid params\n");
  153. return;
  154. }
  155. if (!c_bridge || !c_bridge->display || !c_bridge->display->panel) {
  156. DSI_ERR("Incorrect bridge details\n");
  157. return;
  158. }
  159. atomic_set(&c_bridge->display->panel->esd_recovery_pending, 0);
  160. /* By this point mode should have been validated through mode_fixup */
  161. rc = dsi_display_set_mode(c_bridge->display,
  162. &(c_bridge->dsi_mode), 0x0);
  163. if (rc) {
  164. DSI_ERR("[%d] failed to perform a mode set, rc=%d\n",
  165. c_bridge->id, rc);
  166. return;
  167. }
  168. if (c_bridge->dsi_mode.dsi_mode_flags &
  169. (DSI_MODE_FLAG_SEAMLESS | DSI_MODE_FLAG_VRR |
  170. DSI_MODE_FLAG_DYN_CLK)) {
  171. DSI_DEBUG("[%d] seamless pre-enable\n", c_bridge->id);
  172. return;
  173. }
  174. SDE_ATRACE_BEGIN("dsi_display_prepare");
  175. rc = dsi_display_prepare(c_bridge->display);
  176. if (rc) {
  177. DSI_ERR("[%d] DSI display prepare failed, rc=%d\n",
  178. c_bridge->id, rc);
  179. SDE_ATRACE_END("dsi_display_prepare");
  180. return;
  181. }
  182. SDE_ATRACE_END("dsi_display_prepare");
  183. SDE_ATRACE_BEGIN("dsi_display_enable");
  184. rc = dsi_display_enable(c_bridge->display);
  185. if (rc) {
  186. DSI_ERR("[%d] DSI display enable failed, rc=%d\n",
  187. c_bridge->id, rc);
  188. (void)dsi_display_unprepare(c_bridge->display);
  189. }
  190. SDE_ATRACE_END("dsi_display_enable");
  191. rc = dsi_display_splash_res_cleanup(c_bridge->display);
  192. if (rc)
  193. DSI_ERR("Continuous splash pipeline cleanup failed, rc=%d\n",
  194. rc);
  195. }
  196. static void dsi_bridge_enable(struct drm_bridge *bridge)
  197. {
  198. int rc = 0;
  199. struct dsi_bridge *c_bridge = to_dsi_bridge(bridge);
  200. struct dsi_display *display;
  201. if (!bridge) {
  202. DSI_ERR("Invalid params\n");
  203. return;
  204. }
  205. if (c_bridge->dsi_mode.dsi_mode_flags &
  206. (DSI_MODE_FLAG_SEAMLESS | DSI_MODE_FLAG_VRR |
  207. DSI_MODE_FLAG_DYN_CLK)) {
  208. DSI_DEBUG("[%d] seamless enable\n", c_bridge->id);
  209. return;
  210. }
  211. display = c_bridge->display;
  212. rc = dsi_display_post_enable(display);
  213. if (rc)
  214. DSI_ERR("[%d] DSI display post enabled failed, rc=%d\n",
  215. c_bridge->id, rc);
  216. if (display)
  217. display->enabled = true;
  218. if (display && display->drm_conn) {
  219. sde_connector_helper_bridge_enable(display->drm_conn);
  220. if (display->poms_pending) {
  221. display->poms_pending = false;
  222. sde_connector_schedule_status_work(display->drm_conn,
  223. true);
  224. }
  225. }
  226. }
  227. static void dsi_bridge_disable(struct drm_bridge *bridge)
  228. {
  229. int rc = 0;
  230. struct dsi_display *display;
  231. struct sde_connector_state *conn_state;
  232. struct dsi_bridge *c_bridge = to_dsi_bridge(bridge);
  233. if (!bridge) {
  234. DSI_ERR("Invalid params\n");
  235. return;
  236. }
  237. display = c_bridge->display;
  238. if (display)
  239. display->enabled = false;
  240. if (display && display->drm_conn) {
  241. conn_state = to_sde_connector_state(display->drm_conn->state);
  242. if (!conn_state) {
  243. DSI_ERR("invalid params\n");
  244. return;
  245. }
  246. display->poms_pending = msm_is_mode_seamless_poms(
  247. &conn_state->msm_mode);
  248. sde_connector_helper_bridge_disable(display->drm_conn);
  249. }
  250. rc = dsi_display_pre_disable(c_bridge->display);
  251. if (rc) {
  252. DSI_ERR("[%d] DSI display pre disable failed, rc=%d\n",
  253. c_bridge->id, rc);
  254. }
  255. }
  256. static void dsi_bridge_post_disable(struct drm_bridge *bridge)
  257. {
  258. int rc = 0;
  259. struct dsi_bridge *c_bridge = to_dsi_bridge(bridge);
  260. if (!bridge) {
  261. DSI_ERR("Invalid params\n");
  262. return;
  263. }
  264. SDE_ATRACE_BEGIN("dsi_bridge_post_disable");
  265. SDE_ATRACE_BEGIN("dsi_display_disable");
  266. rc = dsi_display_disable(c_bridge->display);
  267. if (rc) {
  268. DSI_ERR("[%d] DSI display disable failed, rc=%d\n",
  269. c_bridge->id, rc);
  270. SDE_ATRACE_END("dsi_display_disable");
  271. return;
  272. }
  273. SDE_ATRACE_END("dsi_display_disable");
  274. rc = dsi_display_unprepare(c_bridge->display);
  275. if (rc) {
  276. DSI_ERR("[%d] DSI display unprepare failed, rc=%d\n",
  277. c_bridge->id, rc);
  278. SDE_ATRACE_END("dsi_bridge_post_disable");
  279. return;
  280. }
  281. SDE_ATRACE_END("dsi_bridge_post_disable");
  282. }
  283. static void dsi_bridge_mode_set(struct drm_bridge *bridge,
  284. const struct drm_display_mode *mode,
  285. const struct drm_display_mode *adjusted_mode)
  286. {
  287. int rc = 0;
  288. struct dsi_bridge *c_bridge = NULL;
  289. struct dsi_display *display;
  290. struct drm_connector *conn;
  291. struct sde_connector_state *conn_state;
  292. if (!bridge || !mode || !adjusted_mode) {
  293. DSI_ERR("Invalid params\n");
  294. return;
  295. }
  296. c_bridge = to_dsi_bridge(bridge);
  297. if (!c_bridge) {
  298. DSI_ERR("invalid dsi bridge\n");
  299. return;
  300. }
  301. display = c_bridge->display;
  302. if (!display || !display->drm_conn || !display->drm_conn->state) {
  303. DSI_ERR("invalid display\n");
  304. return;
  305. }
  306. memset(&(c_bridge->dsi_mode), 0x0, sizeof(struct dsi_display_mode));
  307. convert_to_dsi_mode(adjusted_mode, &(c_bridge->dsi_mode));
  308. conn = sde_encoder_get_connector(bridge->dev, bridge->encoder);
  309. if (!conn)
  310. return;
  311. conn_state = to_sde_connector_state(conn->state);
  312. if (!conn_state) {
  313. DSI_ERR("invalid connector state\n");
  314. return;
  315. }
  316. msm_parse_mode_priv_info(&conn_state->msm_mode,
  317. &(c_bridge->dsi_mode));
  318. rc = dsi_display_restore_bit_clk(display, &c_bridge->dsi_mode);
  319. if (rc) {
  320. DSI_ERR("[%s] bit clk rate cannot be restored\n", display->name);
  321. return;
  322. }
  323. DSI_DEBUG("clk_rate: %llu\n", c_bridge->dsi_mode.timing.clk_rate_hz);
  324. }
  325. static bool dsi_bridge_mode_fixup(struct drm_bridge *bridge,
  326. const struct drm_display_mode *mode,
  327. struct drm_display_mode *adjusted_mode)
  328. {
  329. int rc = 0;
  330. struct dsi_bridge *c_bridge = to_dsi_bridge(bridge);
  331. struct dsi_display *display;
  332. struct dsi_display_mode dsi_mode, cur_dsi_mode, *panel_dsi_mode;
  333. struct drm_crtc_state *crtc_state;
  334. struct drm_connector_state *drm_conn_state;
  335. struct sde_connector_state *conn_state;
  336. crtc_state = container_of(mode, struct drm_crtc_state, mode);
  337. if (!bridge || !mode || !adjusted_mode) {
  338. DSI_ERR("invalid params\n");
  339. return false;
  340. }
  341. display = c_bridge->display;
  342. if (!display || !display->drm_conn || !display->drm_conn->state) {
  343. DSI_ERR("invalid params\n");
  344. return false;
  345. }
  346. drm_conn_state = drm_atomic_get_new_connector_state(crtc_state->state,
  347. display->drm_conn);
  348. conn_state = to_sde_connector_state(drm_conn_state);
  349. if (!conn_state) {
  350. DSI_ERR("invalid params\n");
  351. return false;
  352. }
  353. /*
  354. * if no timing defined in panel, it must be external mode
  355. * and we'll use empty priv info to populate the mode
  356. */
  357. if (display->panel && !display->panel->num_timing_nodes) {
  358. *adjusted_mode = *mode;
  359. conn_state->msm_mode.base = adjusted_mode;
  360. conn_state->msm_mode.private = (int *)&default_priv_info;
  361. conn_state->msm_mode.private_flags = 0;
  362. return true;
  363. }
  364. convert_to_dsi_mode(mode, &dsi_mode);
  365. msm_parse_mode_priv_info(&conn_state->msm_mode, &dsi_mode);
  366. /*
  367. * retrieve dsi mode from dsi driver's cache since not safe to take
  368. * the drm mode config mutex in all paths
  369. */
  370. rc = dsi_display_find_mode(display, &dsi_mode, &panel_dsi_mode);
  371. if (rc)
  372. return rc;
  373. /* propagate the private info to the adjusted_mode derived dsi mode */
  374. dsi_mode.priv_info = panel_dsi_mode->priv_info;
  375. dsi_mode.dsi_mode_flags = panel_dsi_mode->dsi_mode_flags;
  376. dsi_mode.panel_mode_caps = panel_dsi_mode->panel_mode_caps;
  377. dsi_mode.timing.dsc_enabled = dsi_mode.priv_info->dsc_enabled;
  378. dsi_mode.timing.dsc = &dsi_mode.priv_info->dsc;
  379. rc = dsi_display_restore_bit_clk(display, &dsi_mode);
  380. if (rc) {
  381. DSI_ERR("[%s] bit clk rate cannot be restored\n", display->name);
  382. return false;
  383. }
  384. rc = dsi_display_update_dyn_bit_clk(display, &dsi_mode);
  385. if (rc) {
  386. DSI_ERR("[%s] failed to update bit clock\n", display->name);
  387. return false;
  388. }
  389. rc = dsi_display_validate_mode(c_bridge->display, &dsi_mode,
  390. DSI_VALIDATE_FLAG_ALLOW_ADJUST);
  391. if (rc) {
  392. DSI_ERR("[%d] mode is not valid, rc=%d\n", c_bridge->id, rc);
  393. return false;
  394. }
  395. if (bridge->encoder && bridge->encoder->crtc &&
  396. crtc_state->crtc) {
  397. const struct drm_display_mode *cur_mode =
  398. &crtc_state->crtc->state->mode;
  399. convert_to_dsi_mode(cur_mode, &cur_dsi_mode);
  400. cur_dsi_mode.timing.dsc_enabled =
  401. dsi_mode.priv_info->dsc_enabled;
  402. cur_dsi_mode.timing.dsc = &dsi_mode.priv_info->dsc;
  403. rc = dsi_display_validate_mode_change(c_bridge->display,
  404. &cur_dsi_mode, &dsi_mode);
  405. if (rc) {
  406. DSI_ERR("[%s] seamless mode mismatch failure rc=%d\n",
  407. c_bridge->display->name, rc);
  408. return false;
  409. }
  410. /* No DMS/VRR when drm pipeline is changing */
  411. if (!drm_mode_equal(cur_mode, adjusted_mode) &&
  412. (!(dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_VRR)) &&
  413. (!(dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_DYN_CLK)) &&
  414. (!(dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_POMS_TO_VID)) &&
  415. (!(dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_POMS_TO_CMD)) &&
  416. (!crtc_state->active_changed ||
  417. display->is_cont_splash_enabled)) {
  418. dsi_mode.dsi_mode_flags |= DSI_MODE_FLAG_DMS;
  419. SDE_EVT32(SDE_EVTLOG_FUNC_CASE2,
  420. dsi_mode.timing.h_active,
  421. dsi_mode.timing.v_active,
  422. dsi_mode.timing.refresh_rate,
  423. dsi_mode.pixel_clk_khz,
  424. dsi_mode.panel_mode_caps);
  425. }
  426. }
  427. /* Reject seamless transition when active changed */
  428. if (crtc_state->active_changed &&
  429. ((dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_VRR) ||
  430. (dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_DYN_CLK) ||
  431. (dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_POMS_TO_VID) ||
  432. (dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_POMS_TO_CMD))) {
  433. DSI_INFO("seamless upon active changed 0x%x %d\n",
  434. dsi_mode.dsi_mode_flags, crtc_state->active_changed);
  435. return false;
  436. }
  437. /* convert back to drm mode, propagating the private info & flags */
  438. dsi_convert_to_drm_mode(&dsi_mode, adjusted_mode);
  439. dsi_convert_to_msm_mode(&dsi_mode, &conn_state->msm_mode);
  440. return true;
  441. }
  442. u32 dsi_drm_get_dfps_maxfps(void *display)
  443. {
  444. u32 dfps_maxfps = 0;
  445. struct dsi_display *dsi_display = display;
  446. /*
  447. * The time of SDE transmitting one frame active data
  448. * will not be changed, if frame rate is adjusted with
  449. * VFP method.
  450. * So only return max fps of DFPS for UIDLE update, if DFPS
  451. * is enabled with VFP.
  452. */
  453. if (dsi_display && dsi_display->panel &&
  454. dsi_display->panel->panel_mode == DSI_OP_VIDEO_MODE &&
  455. dsi_display->panel->dfps_caps.type ==
  456. DSI_DFPS_IMMEDIATE_VFP)
  457. dfps_maxfps =
  458. dsi_display->panel->dfps_caps.max_refresh_rate;
  459. return dfps_maxfps;
  460. }
  461. int dsi_conn_get_mode_info(struct drm_connector *connector,
  462. const struct drm_display_mode *drm_mode,
  463. struct msm_mode_info *mode_info,
  464. void *display, const struct msm_resource_caps_info *avail_res)
  465. {
  466. struct dsi_display_mode partial_dsi_mode, *dsi_mode = NULL;
  467. struct dsi_mode_info *timing;
  468. int src_bpp, tar_bpp, rc = 0;
  469. if (!drm_mode || !mode_info)
  470. return -EINVAL;
  471. convert_to_dsi_mode(drm_mode, &partial_dsi_mode);
  472. rc = dsi_display_find_mode(display, &partial_dsi_mode, &dsi_mode);
  473. if (rc || !dsi_mode->priv_info)
  474. return -EINVAL;
  475. memset(mode_info, 0, sizeof(*mode_info));
  476. timing = &dsi_mode->timing;
  477. mode_info->frame_rate = dsi_mode->timing.refresh_rate;
  478. mode_info->vtotal = DSI_V_TOTAL(timing);
  479. mode_info->prefill_lines = dsi_mode->priv_info->panel_prefill_lines;
  480. mode_info->jitter_numer = dsi_mode->priv_info->panel_jitter_numer;
  481. mode_info->jitter_denom = dsi_mode->priv_info->panel_jitter_denom;
  482. mode_info->dfps_maxfps = dsi_drm_get_dfps_maxfps(display);
  483. mode_info->clk_rate = dsi_mode->timing.clk_rate_hz;
  484. mode_info->panel_mode_caps = dsi_mode->panel_mode_caps;
  485. mode_info->mdp_transfer_time_us =
  486. dsi_mode->priv_info->mdp_transfer_time_us;
  487. memcpy(&mode_info->topology, &dsi_mode->priv_info->topology,
  488. sizeof(struct msm_display_topology));
  489. if (dsi_mode->priv_info->bit_clk_list.count) {
  490. mode_info->bit_clk_rates =
  491. dsi_mode->priv_info->bit_clk_list.rates;
  492. mode_info->bit_clk_count =
  493. dsi_mode->priv_info->bit_clk_list.count;
  494. }
  495. if (dsi_mode->priv_info->dsc_enabled) {
  496. mode_info->comp_info.comp_type = MSM_DISPLAY_COMPRESSION_DSC;
  497. mode_info->topology.comp_type = MSM_DISPLAY_COMPRESSION_DSC;
  498. memcpy(&mode_info->comp_info.dsc_info, &dsi_mode->priv_info->dsc,
  499. sizeof(dsi_mode->priv_info->dsc));
  500. } else if (dsi_mode->priv_info->vdc_enabled) {
  501. mode_info->comp_info.comp_type = MSM_DISPLAY_COMPRESSION_VDC;
  502. mode_info->topology.comp_type = MSM_DISPLAY_COMPRESSION_VDC;
  503. memcpy(&mode_info->comp_info.vdc_info, &dsi_mode->priv_info->vdc,
  504. sizeof(dsi_mode->priv_info->vdc));
  505. }
  506. if (mode_info->comp_info.comp_type) {
  507. tar_bpp = dsi_mode->priv_info->pclk_scale.numer;
  508. src_bpp = dsi_mode->priv_info->pclk_scale.denom;
  509. mode_info->comp_info.comp_ratio = mult_frac(1, src_bpp,
  510. tar_bpp);
  511. mode_info->wide_bus_en = dsi_mode->priv_info->widebus_support;
  512. }
  513. if (dsi_mode->priv_info->roi_caps.enabled) {
  514. memcpy(&mode_info->roi_caps, &dsi_mode->priv_info->roi_caps,
  515. sizeof(dsi_mode->priv_info->roi_caps));
  516. }
  517. mode_info->allowed_mode_switches =
  518. dsi_mode->priv_info->allowed_mode_switch;
  519. return 0;
  520. }
  521. static const struct drm_bridge_funcs dsi_bridge_ops = {
  522. .attach = dsi_bridge_attach,
  523. .mode_fixup = dsi_bridge_mode_fixup,
  524. .pre_enable = dsi_bridge_pre_enable,
  525. .enable = dsi_bridge_enable,
  526. .disable = dsi_bridge_disable,
  527. .post_disable = dsi_bridge_post_disable,
  528. .mode_set = dsi_bridge_mode_set,
  529. };
  530. int dsi_conn_set_avr_step_info(struct dsi_panel *panel, void *info)
  531. {
  532. u32 i;
  533. int idx = 0;
  534. size_t buff_sz = PAGE_SIZE;
  535. char *buff;
  536. buff = kzalloc(buff_sz, GFP_KERNEL);
  537. if (!buff)
  538. return -ENOMEM;
  539. for (i = 0; i < panel->avr_caps.avr_step_fps_list_len && (idx < (buff_sz - 1)); i++)
  540. idx += scnprintf(&buff[idx], buff_sz - idx, "%u@%u ",
  541. panel->avr_caps.avr_step_fps_list[i],
  542. panel->dfps_caps.dfps_list[i]);
  543. sde_kms_info_add_keystr(info, "avr step requirement", buff);
  544. kfree(buff);
  545. return 0;
  546. }
  547. int dsi_conn_set_info_blob(struct drm_connector *connector,
  548. void *info, void *display, struct msm_mode_info *mode_info)
  549. {
  550. struct dsi_display *dsi_display = display;
  551. struct dsi_panel *panel;
  552. enum dsi_pixel_format fmt;
  553. u32 bpp;
  554. if (!info || !dsi_display)
  555. return -EINVAL;
  556. dsi_display->drm_conn = connector;
  557. sde_kms_info_add_keystr(info,
  558. "display type", dsi_display->display_type);
  559. switch (dsi_display->type) {
  560. case DSI_DISPLAY_SINGLE:
  561. sde_kms_info_add_keystr(info, "display config",
  562. "single display");
  563. break;
  564. case DSI_DISPLAY_EXT_BRIDGE:
  565. sde_kms_info_add_keystr(info, "display config", "ext bridge");
  566. break;
  567. case DSI_DISPLAY_SPLIT:
  568. sde_kms_info_add_keystr(info, "display config",
  569. "split display");
  570. break;
  571. case DSI_DISPLAY_SPLIT_EXT_BRIDGE:
  572. sde_kms_info_add_keystr(info, "display config",
  573. "split ext bridge");
  574. break;
  575. default:
  576. DSI_DEBUG("invalid display type:%d\n", dsi_display->type);
  577. break;
  578. }
  579. if (!dsi_display->panel) {
  580. DSI_DEBUG("invalid panel data\n");
  581. goto end;
  582. }
  583. panel = dsi_display->panel;
  584. sde_kms_info_add_keystr(info, "panel name", panel->name);
  585. switch (panel->panel_mode) {
  586. case DSI_OP_VIDEO_MODE:
  587. sde_kms_info_add_keystr(info, "panel mode", "video");
  588. if (panel->avr_caps.avr_step_fps_list_len)
  589. dsi_conn_set_avr_step_info(panel, info);
  590. break;
  591. case DSI_OP_CMD_MODE:
  592. sde_kms_info_add_keystr(info, "panel mode", "command");
  593. sde_kms_info_add_keyint(info, "mdp_transfer_time_us",
  594. mode_info->mdp_transfer_time_us);
  595. break;
  596. default:
  597. DSI_DEBUG("invalid panel type:%d\n", panel->panel_mode);
  598. break;
  599. }
  600. sde_kms_info_add_keystr(info, "qsync support",
  601. panel->qsync_caps.qsync_min_fps ?
  602. "true" : "false");
  603. if (panel->qsync_caps.qsync_min_fps)
  604. sde_kms_info_add_keyint(info, "qsync_fps",
  605. panel->qsync_caps.qsync_min_fps);
  606. sde_kms_info_add_keystr(info, "dfps support",
  607. panel->dfps_caps.dfps_support ? "true" : "false");
  608. if (panel->dfps_caps.dfps_support) {
  609. sde_kms_info_add_keyint(info, "min_fps",
  610. panel->dfps_caps.min_refresh_rate);
  611. sde_kms_info_add_keyint(info, "max_fps",
  612. panel->dfps_caps.max_refresh_rate);
  613. }
  614. sde_kms_info_add_keystr(info, "dyn bitclk support",
  615. panel->dyn_clk_caps.dyn_clk_support ? "true" : "false");
  616. switch (panel->phy_props.rotation) {
  617. case DSI_PANEL_ROTATE_NONE:
  618. sde_kms_info_add_keystr(info, "panel orientation", "none");
  619. break;
  620. case DSI_PANEL_ROTATE_H_FLIP:
  621. sde_kms_info_add_keystr(info, "panel orientation", "horz flip");
  622. break;
  623. case DSI_PANEL_ROTATE_V_FLIP:
  624. sde_kms_info_add_keystr(info, "panel orientation", "vert flip");
  625. break;
  626. case DSI_PANEL_ROTATE_HV_FLIP:
  627. sde_kms_info_add_keystr(info, "panel orientation",
  628. "horz & vert flip");
  629. break;
  630. default:
  631. DSI_DEBUG("invalid panel rotation:%d\n",
  632. panel->phy_props.rotation);
  633. break;
  634. }
  635. switch (panel->bl_config.type) {
  636. case DSI_BACKLIGHT_PWM:
  637. sde_kms_info_add_keystr(info, "backlight type", "pwm");
  638. break;
  639. case DSI_BACKLIGHT_WLED:
  640. sde_kms_info_add_keystr(info, "backlight type", "wled");
  641. break;
  642. case DSI_BACKLIGHT_DCS:
  643. sde_kms_info_add_keystr(info, "backlight type", "dcs");
  644. break;
  645. default:
  646. DSI_DEBUG("invalid panel backlight type:%d\n",
  647. panel->bl_config.type);
  648. break;
  649. }
  650. if (panel->spr_info.enable)
  651. sde_kms_info_add_keystr(info, "spr_pack_type",
  652. msm_spr_pack_type_str[panel->spr_info.pack_type]);
  653. if (mode_info && mode_info->roi_caps.enabled) {
  654. sde_kms_info_add_keyint(info, "partial_update_num_roi",
  655. mode_info->roi_caps.num_roi);
  656. sde_kms_info_add_keyint(info, "partial_update_xstart",
  657. mode_info->roi_caps.align.xstart_pix_align);
  658. sde_kms_info_add_keyint(info, "partial_update_walign",
  659. mode_info->roi_caps.align.width_pix_align);
  660. sde_kms_info_add_keyint(info, "partial_update_wmin",
  661. mode_info->roi_caps.align.min_width);
  662. sde_kms_info_add_keyint(info, "partial_update_ystart",
  663. mode_info->roi_caps.align.ystart_pix_align);
  664. sde_kms_info_add_keyint(info, "partial_update_halign",
  665. mode_info->roi_caps.align.height_pix_align);
  666. sde_kms_info_add_keyint(info, "partial_update_hmin",
  667. mode_info->roi_caps.align.min_height);
  668. sde_kms_info_add_keyint(info, "partial_update_roimerge",
  669. mode_info->roi_caps.merge_rois);
  670. }
  671. fmt = dsi_display->config.common_config.dst_format;
  672. bpp = dsi_ctrl_pixel_format_to_bpp(fmt);
  673. sde_kms_info_add_keyint(info, "bit_depth", bpp);
  674. end:
  675. return 0;
  676. }
  677. enum drm_connector_status dsi_conn_detect(struct drm_connector *conn,
  678. bool force,
  679. void *display)
  680. {
  681. enum drm_connector_status status = connector_status_unknown;
  682. struct msm_display_info info;
  683. int rc;
  684. if (!conn || !display)
  685. return status;
  686. /* get display dsi_info */
  687. memset(&info, 0x0, sizeof(info));
  688. rc = dsi_display_get_info(conn, &info, display);
  689. if (rc) {
  690. DSI_ERR("failed to get display info, rc=%d\n", rc);
  691. return connector_status_disconnected;
  692. }
  693. if (info.capabilities & MSM_DISPLAY_CAP_HOT_PLUG)
  694. status = (info.is_connected ? connector_status_connected :
  695. connector_status_disconnected);
  696. else
  697. status = connector_status_connected;
  698. conn->display_info.width_mm = info.width_mm;
  699. conn->display_info.height_mm = info.height_mm;
  700. return status;
  701. }
  702. void dsi_connector_put_modes(struct drm_connector *connector,
  703. void *display)
  704. {
  705. struct drm_display_mode *drm_mode;
  706. struct dsi_display_mode dsi_mode, *full_dsi_mode = NULL;
  707. struct dsi_display *dsi_display;
  708. int rc = 0;
  709. if (!connector || !display)
  710. return;
  711. list_for_each_entry(drm_mode, &connector->modes, head) {
  712. convert_to_dsi_mode(drm_mode, &dsi_mode);
  713. rc = dsi_display_find_mode(display, &dsi_mode, &full_dsi_mode);
  714. if (rc)
  715. continue;
  716. dsi_display_put_mode(display, full_dsi_mode);
  717. }
  718. /* free the display structure modes also */
  719. dsi_display = display;
  720. kfree(dsi_display->modes);
  721. dsi_display->modes = NULL;
  722. }
  723. static int dsi_drm_update_edid_name(struct edid *edid, const char *name)
  724. {
  725. u8 *dtd = (u8 *)&edid->detailed_timings[3];
  726. u8 standard_header[] = {0x00, 0x00, 0x00, 0xFE, 0x00};
  727. u32 dtd_size = 18;
  728. u32 header_size = sizeof(standard_header);
  729. if (!name)
  730. return -EINVAL;
  731. /* Fill standard header */
  732. memcpy(dtd, standard_header, header_size);
  733. dtd_size -= header_size;
  734. dtd_size = min_t(u32, dtd_size, strlen(name));
  735. memcpy(dtd + header_size, name, dtd_size);
  736. return 0;
  737. }
  738. static void dsi_drm_update_dtd(struct edid *edid,
  739. struct dsi_display_mode *modes, u32 modes_count)
  740. {
  741. u32 i;
  742. u32 count = min_t(u32, modes_count, 3);
  743. for (i = 0; i < count; i++) {
  744. struct detailed_timing *dtd = &edid->detailed_timings[i];
  745. struct dsi_display_mode *mode = &modes[i];
  746. struct dsi_mode_info *timing = &mode->timing;
  747. struct detailed_pixel_timing *pd = &dtd->data.pixel_data;
  748. u32 h_blank = timing->h_front_porch + timing->h_sync_width +
  749. timing->h_back_porch;
  750. u32 v_blank = timing->v_front_porch + timing->v_sync_width +
  751. timing->v_back_porch;
  752. u32 h_img = 0, v_img = 0;
  753. dtd->pixel_clock = mode->pixel_clk_khz / 10;
  754. pd->hactive_lo = timing->h_active & 0xFF;
  755. pd->hblank_lo = h_blank & 0xFF;
  756. pd->hactive_hblank_hi = ((h_blank >> 8) & 0xF) |
  757. ((timing->h_active >> 8) & 0xF) << 4;
  758. pd->vactive_lo = timing->v_active & 0xFF;
  759. pd->vblank_lo = v_blank & 0xFF;
  760. pd->vactive_vblank_hi = ((v_blank >> 8) & 0xF) |
  761. ((timing->v_active >> 8) & 0xF) << 4;
  762. pd->hsync_offset_lo = timing->h_front_porch & 0xFF;
  763. pd->hsync_pulse_width_lo = timing->h_sync_width & 0xFF;
  764. pd->vsync_offset_pulse_width_lo =
  765. ((timing->v_front_porch & 0xF) << 4) |
  766. (timing->v_sync_width & 0xF);
  767. pd->hsync_vsync_offset_pulse_width_hi =
  768. (((timing->h_front_porch >> 8) & 0x3) << 6) |
  769. (((timing->h_sync_width >> 8) & 0x3) << 4) |
  770. (((timing->v_front_porch >> 4) & 0x3) << 2) |
  771. (((timing->v_sync_width >> 4) & 0x3) << 0);
  772. pd->width_mm_lo = h_img & 0xFF;
  773. pd->height_mm_lo = v_img & 0xFF;
  774. pd->width_height_mm_hi = (((h_img >> 8) & 0xF) << 4) |
  775. ((v_img >> 8) & 0xF);
  776. pd->hborder = 0;
  777. pd->vborder = 0;
  778. pd->misc = 0;
  779. }
  780. }
  781. static void dsi_drm_update_checksum(struct edid *edid)
  782. {
  783. u8 *data = (u8 *)edid;
  784. u32 i, sum = 0;
  785. for (i = 0; i < EDID_LENGTH - 1; i++)
  786. sum += data[i];
  787. edid->checksum = 0x100 - (sum & 0xFF);
  788. }
  789. int dsi_connector_get_modes(struct drm_connector *connector, void *data,
  790. const struct msm_resource_caps_info *avail_res)
  791. {
  792. int rc, i;
  793. u32 count = 0, edid_size;
  794. struct dsi_display_mode *modes = NULL;
  795. struct drm_display_mode drm_mode;
  796. struct dsi_display *display = data;
  797. struct edid edid;
  798. unsigned int width_mm = connector->display_info.width_mm;
  799. unsigned int height_mm = connector->display_info.height_mm;
  800. const u8 edid_buf[EDID_LENGTH] = {
  801. 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x44, 0x6D,
  802. 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1B, 0x10, 0x01, 0x03,
  803. 0x80, 0x00, 0x00, 0x78, 0x0A, 0x0D, 0xC9, 0xA0, 0x57, 0x47,
  804. 0x98, 0x27, 0x12, 0x48, 0x4C, 0x00, 0x00, 0x00, 0x01, 0x01,
  805. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  806. 0x01, 0x01, 0x01, 0x01,
  807. };
  808. edid_size = min_t(u32, sizeof(edid), EDID_LENGTH);
  809. memcpy(&edid, edid_buf, edid_size);
  810. rc = dsi_display_get_mode_count(display, &count);
  811. if (rc) {
  812. DSI_ERR("failed to get num of modes, rc=%d\n", rc);
  813. goto end;
  814. }
  815. rc = dsi_display_get_modes(display, &modes);
  816. if (rc) {
  817. DSI_ERR("failed to get modes, rc=%d\n", rc);
  818. count = 0;
  819. goto end;
  820. }
  821. for (i = 0; i < count; i++) {
  822. struct drm_display_mode *m;
  823. memset(&drm_mode, 0x0, sizeof(drm_mode));
  824. dsi_convert_to_drm_mode(&modes[i], &drm_mode);
  825. m = drm_mode_duplicate(connector->dev, &drm_mode);
  826. if (!m) {
  827. DSI_ERR("failed to add mode %ux%u\n",
  828. drm_mode.hdisplay,
  829. drm_mode.vdisplay);
  830. count = -ENOMEM;
  831. goto end;
  832. }
  833. m->width_mm = connector->display_info.width_mm;
  834. m->height_mm = connector->display_info.height_mm;
  835. if (display->cmdline_timing != NO_OVERRIDE) {
  836. /* get the preferred mode from dsi display mode */
  837. if (modes[i].is_preferred)
  838. m->type |= DRM_MODE_TYPE_PREFERRED;
  839. } else if (modes[i].mode_idx == 0) {
  840. /* set the first mode in device tree list as preferred */
  841. m->type |= DRM_MODE_TYPE_PREFERRED;
  842. }
  843. drm_mode_probed_add(connector, m);
  844. }
  845. rc = dsi_drm_update_edid_name(&edid, display->panel->name);
  846. if (rc) {
  847. count = 0;
  848. goto end;
  849. }
  850. edid.width_cm = (connector->display_info.width_mm) / 10;
  851. edid.height_cm = (connector->display_info.height_mm) / 10;
  852. dsi_drm_update_dtd(&edid, modes, count);
  853. dsi_drm_update_checksum(&edid);
  854. rc = drm_connector_update_edid_property(connector, &edid);
  855. if (rc)
  856. count = 0;
  857. /*
  858. * DRM EDID structure maintains panel physical dimensions in
  859. * centimeters, we will be losing the precision anything below cm.
  860. * Changing DRM framework will effect other clients at this
  861. * moment, overriding the values back to millimeter.
  862. */
  863. connector->display_info.width_mm = width_mm;
  864. connector->display_info.height_mm = height_mm;
  865. end:
  866. DSI_DEBUG("MODE COUNT =%d\n\n", count);
  867. return count;
  868. }
  869. enum drm_mode_status dsi_conn_mode_valid(struct drm_connector *connector,
  870. struct drm_display_mode *mode,
  871. void *display, const struct msm_resource_caps_info *avail_res)
  872. {
  873. struct dsi_display_mode dsi_mode;
  874. struct dsi_display_mode *full_dsi_mode = NULL;
  875. struct sde_connector_state *conn_state;
  876. int rc;
  877. if (!connector || !mode) {
  878. DSI_ERR("Invalid params\n");
  879. return MODE_ERROR;
  880. }
  881. convert_to_dsi_mode(mode, &dsi_mode);
  882. conn_state = to_sde_connector_state(connector->state);
  883. if (conn_state)
  884. msm_parse_mode_priv_info(&conn_state->msm_mode, &dsi_mode);
  885. rc = dsi_display_find_mode(display, &dsi_mode, &full_dsi_mode);
  886. if (rc) {
  887. DSI_ERR("could not find mode %s\n", mode->name);
  888. return MODE_ERROR;
  889. }
  890. rc = dsi_display_validate_mode(display, full_dsi_mode,
  891. DSI_VALIDATE_FLAG_ALLOW_ADJUST);
  892. if (rc) {
  893. DSI_ERR("mode not supported, rc=%d\n", rc);
  894. return MODE_BAD;
  895. }
  896. return MODE_OK;
  897. }
  898. int dsi_conn_pre_kickoff(struct drm_connector *connector,
  899. void *display,
  900. struct msm_display_kickoff_params *params)
  901. {
  902. if (!connector || !display || !params) {
  903. DSI_ERR("Invalid params\n");
  904. return -EINVAL;
  905. }
  906. return dsi_display_pre_kickoff(connector, display, params);
  907. }
  908. int dsi_conn_prepare_commit(void *display,
  909. struct msm_display_conn_params *params)
  910. {
  911. if (!display || !params) {
  912. pr_err("Invalid params\n");
  913. return -EINVAL;
  914. }
  915. return dsi_display_pre_commit(display, params);
  916. }
  917. void dsi_conn_enable_event(struct drm_connector *connector,
  918. uint32_t event_idx, bool enable, void *display)
  919. {
  920. struct dsi_event_cb_info event_info;
  921. memset(&event_info, 0, sizeof(event_info));
  922. event_info.event_cb = sde_connector_trigger_event;
  923. event_info.event_usr_ptr = connector;
  924. dsi_display_enable_event(connector, display,
  925. event_idx, &event_info, enable);
  926. }
  927. int dsi_conn_post_kickoff(struct drm_connector *connector,
  928. struct msm_display_conn_params *params)
  929. {
  930. struct drm_encoder *encoder;
  931. struct drm_bridge *bridge;
  932. struct dsi_bridge *c_bridge;
  933. struct dsi_display_mode adj_mode;
  934. struct dsi_display *display;
  935. struct dsi_display_ctrl *m_ctrl, *ctrl;
  936. int i, rc = 0, ctrl_version;
  937. bool enable;
  938. struct dsi_dyn_clk_caps *dyn_clk_caps;
  939. if (!connector || !connector->state) {
  940. DSI_ERR("invalid connector or connector state\n");
  941. return -EINVAL;
  942. }
  943. encoder = connector->state->best_encoder;
  944. if (!encoder) {
  945. DSI_DEBUG("best encoder is not available\n");
  946. return 0;
  947. }
  948. bridge = drm_bridge_chain_get_first_bridge(encoder);
  949. if (!bridge) {
  950. DSI_DEBUG("bridge is not available\n");
  951. return 0;
  952. }
  953. c_bridge = to_dsi_bridge(bridge);
  954. adj_mode = c_bridge->dsi_mode;
  955. display = c_bridge->display;
  956. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  957. if (adj_mode.dsi_mode_flags & DSI_MODE_FLAG_VRR) {
  958. m_ctrl = &display->ctrl[display->clk_master_idx];
  959. ctrl_version = m_ctrl->ctrl->version;
  960. rc = dsi_ctrl_timing_db_update(m_ctrl->ctrl, false);
  961. if (rc) {
  962. DSI_ERR("[%s] failed to dfps update rc=%d\n",
  963. display->name, rc);
  964. return -EINVAL;
  965. }
  966. /*
  967. * When both DFPS and dynamic clock switch with constant
  968. * fps features are enabled, wait for dynamic refresh done
  969. * only in case of clock switch.
  970. * In case where only fps changes, clock remains same.
  971. * So, wait for dynamic refresh done is not required.
  972. */
  973. if ((ctrl_version >= DSI_CTRL_VERSION_2_5) &&
  974. (dyn_clk_caps->maintain_const_fps) &&
  975. (adj_mode.dsi_mode_flags & DSI_MODE_FLAG_DYN_CLK)) {
  976. display_for_each_ctrl(i, display) {
  977. ctrl = &display->ctrl[i];
  978. rc = dsi_ctrl_wait4dynamic_refresh_done(
  979. ctrl->ctrl);
  980. if (rc)
  981. DSI_ERR("wait4dfps refresh failed\n");
  982. dsi_phy_dynamic_refresh_clear(ctrl->phy);
  983. dsi_clk_disable_unprepare(&display->clock_info.pll_clks);
  984. }
  985. }
  986. /* Update the rest of the controllers */
  987. display_for_each_ctrl(i, display) {
  988. ctrl = &display->ctrl[i];
  989. if (!ctrl->ctrl || (ctrl == m_ctrl))
  990. continue;
  991. rc = dsi_ctrl_timing_db_update(ctrl->ctrl, false);
  992. if (rc) {
  993. DSI_ERR("[%s] failed to dfps update rc=%d\n",
  994. display->name, rc);
  995. return -EINVAL;
  996. }
  997. }
  998. c_bridge->dsi_mode.dsi_mode_flags &= ~DSI_MODE_FLAG_VRR;
  999. }
  1000. /* ensure dynamic clk switch flag is reset */
  1001. c_bridge->dsi_mode.dsi_mode_flags &= ~DSI_MODE_FLAG_DYN_CLK;
  1002. if (params->qsync_update) {
  1003. enable = (params->qsync_mode > 0) ? true : false;
  1004. display_for_each_ctrl(i, display)
  1005. dsi_ctrl_setup_avr(display->ctrl[i].ctrl, enable);
  1006. }
  1007. return 0;
  1008. }
  1009. struct dsi_bridge *dsi_drm_bridge_init(struct dsi_display *display,
  1010. struct drm_device *dev,
  1011. struct drm_encoder *encoder)
  1012. {
  1013. int rc = 0;
  1014. struct dsi_bridge *bridge;
  1015. bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
  1016. if (!bridge) {
  1017. rc = -ENOMEM;
  1018. goto error;
  1019. }
  1020. bridge->display = display;
  1021. bridge->base.funcs = &dsi_bridge_ops;
  1022. bridge->base.encoder = encoder;
  1023. rc = drm_bridge_attach(encoder, &bridge->base, NULL, 0);
  1024. if (rc) {
  1025. DSI_ERR("failed to attach bridge, rc=%d\n", rc);
  1026. goto error_free_bridge;
  1027. }
  1028. return bridge;
  1029. error_free_bridge:
  1030. kfree(bridge);
  1031. error:
  1032. return ERR_PTR(rc);
  1033. }
  1034. void dsi_drm_bridge_cleanup(struct dsi_bridge *bridge)
  1035. {
  1036. kfree(bridge);
  1037. }
  1038. static bool is_valid_poms_switch(struct dsi_display_mode *mode_a,
  1039. struct dsi_display_mode *mode_b)
  1040. {
  1041. /*
  1042. * POMS cannot happen in conjunction with any other type of mode set.
  1043. * Check to ensure FPS remains same between the modes and also
  1044. * resolution.
  1045. */
  1046. return((mode_a->timing.refresh_rate == mode_b->timing.refresh_rate) &&
  1047. (mode_a->timing.v_active == mode_b->timing.v_active) &&
  1048. (mode_a->timing.h_active == mode_b->timing.h_active));
  1049. }
  1050. void dsi_conn_set_allowed_mode_switch(struct drm_connector *connector,
  1051. void *display)
  1052. {
  1053. u32 mode_idx = 0, cmp_mode_idx = 0;
  1054. u32 common_mode_caps = 0;
  1055. struct drm_display_mode *drm_mode, *cmp_drm_mode;
  1056. struct dsi_display_mode dsi_mode, *panel_dsi_mode, *cmp_panel_dsi_mode;
  1057. struct list_head *mode_list = &connector->modes;
  1058. struct dsi_display *disp = display;
  1059. struct dsi_panel *panel;
  1060. int mode_count = 0, rc = 0;
  1061. struct dsi_display_mode_priv_info *dsi_mode_info, *cmp_dsi_mode_info;
  1062. bool allow_switch = false;
  1063. if (!disp || !disp->panel) {
  1064. DSI_ERR("invalid parameters");
  1065. return;
  1066. }
  1067. panel = disp->panel;
  1068. list_for_each_entry(drm_mode, &connector->modes, head)
  1069. mode_count++;
  1070. list_for_each_entry(drm_mode, &connector->modes, head) {
  1071. convert_to_dsi_mode(drm_mode, &dsi_mode);
  1072. rc = dsi_display_find_mode(display, &dsi_mode, &panel_dsi_mode);
  1073. if (rc)
  1074. return;
  1075. dsi_mode_info = panel_dsi_mode->priv_info;
  1076. dsi_mode_info->allowed_mode_switch |= BIT(mode_idx);
  1077. if (mode_idx == mode_count - 1)
  1078. break;
  1079. mode_list = mode_list->next;
  1080. cmp_mode_idx = 1;
  1081. list_for_each_entry(cmp_drm_mode, mode_list, head) {
  1082. if (&cmp_drm_mode->head == &connector->modes)
  1083. continue;
  1084. convert_to_dsi_mode(cmp_drm_mode, &dsi_mode);
  1085. rc = dsi_display_find_mode(display, &dsi_mode,
  1086. &cmp_panel_dsi_mode);
  1087. if (rc)
  1088. return;
  1089. cmp_dsi_mode_info = cmp_panel_dsi_mode->priv_info;
  1090. allow_switch = false;
  1091. common_mode_caps = (panel_dsi_mode->panel_mode_caps &
  1092. cmp_panel_dsi_mode->panel_mode_caps);
  1093. /*
  1094. * FPS switch among video modes, is only supported
  1095. * if DFPS or dynamic clocks are specified.
  1096. * Reject any mode switches between video mode timing
  1097. * nodes if support for those features is not present.
  1098. */
  1099. if (common_mode_caps & DSI_OP_CMD_MODE) {
  1100. allow_switch = true;
  1101. } else if ((common_mode_caps & DSI_OP_VIDEO_MODE) &&
  1102. (panel->dfps_caps.dfps_support ||
  1103. panel->dyn_clk_caps.dyn_clk_support)) {
  1104. allow_switch = true;
  1105. } else {
  1106. if (is_valid_poms_switch(panel_dsi_mode,
  1107. cmp_panel_dsi_mode))
  1108. allow_switch = true;
  1109. }
  1110. if (allow_switch) {
  1111. dsi_mode_info->allowed_mode_switch |=
  1112. BIT(mode_idx + cmp_mode_idx);
  1113. cmp_dsi_mode_info->allowed_mode_switch |=
  1114. BIT(mode_idx);
  1115. }
  1116. if ((mode_idx + cmp_mode_idx) >= mode_count - 1)
  1117. break;
  1118. cmp_mode_idx++;
  1119. }
  1120. mode_idx++;
  1121. }
  1122. }
  1123. int dsi_conn_set_dyn_bit_clk(struct drm_connector *connector, uint64_t value)
  1124. {
  1125. struct sde_connector *c_conn = NULL;
  1126. struct dsi_display *display;
  1127. if (!connector) {
  1128. DSI_ERR("invalid connector\n");
  1129. return -EINVAL;
  1130. }
  1131. c_conn = to_sde_connector(connector);
  1132. display = (struct dsi_display *) c_conn->display;
  1133. display->dyn_bit_clk = value;
  1134. display->dyn_bit_clk_pending = true;
  1135. SDE_EVT32(display->dyn_bit_clk);
  1136. DSI_DEBUG("update dynamic bit clock rate to %llu\n", display->dyn_bit_clk);
  1137. return 0;
  1138. }