dsi_drm.c 34 KB

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