dsi_drm.c 35 KB

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