dsi_ctrl_hw_cmn.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #define pr_fmt(fmt) "dsi-hw:" fmt
  6. #include <linux/delay.h>
  7. #include <linux/iopoll.h>
  8. #include "dsi_catalog.h"
  9. #include "dsi_ctrl_hw.h"
  10. #include "dsi_ctrl_reg.h"
  11. #include "dsi_hw.h"
  12. #include "dsi_panel.h"
  13. #include "dsi_catalog.h"
  14. #include "sde_dbg.h"
  15. #define MMSS_MISC_CLAMP_REG_OFF 0x0014
  16. #define DSI_CTRL_DYNAMIC_FORCE_ON (0x23F|BIT(8)|BIT(9)|BIT(11)|BIT(21))
  17. #define DSI_CTRL_CMD_MISR_ENABLE BIT(28)
  18. #define DSI_CTRL_VIDEO_MISR_ENABLE BIT(16)
  19. /* Unsupported formats default to RGB888 */
  20. static const u8 cmd_mode_format_map[DSI_PIXEL_FORMAT_MAX] = {
  21. 0x6, 0x7, 0x8, 0x8, 0x0, 0x3, 0x4 };
  22. static const u8 video_mode_format_map[DSI_PIXEL_FORMAT_MAX] = {
  23. 0x0, 0x1, 0x2, 0x3, 0x3, 0x3, 0x3 };
  24. /**
  25. * dsi_setup_trigger_controls() - setup dsi trigger configurations
  26. * @ctrl: Pointer to the controller host hardware.
  27. * @cfg: DSI host configuration that is common to both video and
  28. * command modes.
  29. */
  30. static void dsi_setup_trigger_controls(struct dsi_ctrl_hw *ctrl,
  31. struct dsi_host_common_cfg *cfg)
  32. {
  33. u32 reg = 0;
  34. const u8 trigger_map[DSI_TRIGGER_MAX] = {
  35. 0x0, 0x2, 0x1, 0x4, 0x5, 0x6 };
  36. reg |= (cfg->te_mode == DSI_TE_ON_EXT_PIN) ? BIT(31) : 0;
  37. reg |= (trigger_map[cfg->dma_cmd_trigger] & 0x7);
  38. reg |= (trigger_map[cfg->mdp_cmd_trigger] & 0x7) << 4;
  39. DSI_W32(ctrl, DSI_TRIG_CTRL, reg);
  40. }
  41. /**
  42. * dsi_ctrl_hw_cmn_host_setup() - setup dsi host configuration
  43. * @ctrl: Pointer to the controller host hardware.
  44. * @cfg: DSI host configuration that is common to both video and
  45. * command modes.
  46. */
  47. void dsi_ctrl_hw_cmn_host_setup(struct dsi_ctrl_hw *ctrl,
  48. struct dsi_host_common_cfg *cfg)
  49. {
  50. u32 reg_value = 0;
  51. dsi_setup_trigger_controls(ctrl, cfg);
  52. /* Setup clocking timing controls */
  53. reg_value = ((cfg->t_clk_post & 0x3F) << 8);
  54. reg_value |= (cfg->t_clk_pre & 0x3F);
  55. DSI_W32(ctrl, DSI_CLKOUT_TIMING_CTRL, reg_value);
  56. /* EOT packet control */
  57. reg_value = cfg->append_tx_eot ? 1 : 0;
  58. reg_value |= (cfg->ignore_rx_eot ? (1 << 4) : 0);
  59. DSI_W32(ctrl, DSI_EOT_PACKET_CTRL, reg_value);
  60. /* Turn on dsi clocks */
  61. DSI_W32(ctrl, DSI_CLK_CTRL, 0x23F);
  62. /* Setup DSI control register */
  63. reg_value = DSI_R32(ctrl, DSI_CTRL);
  64. reg_value |= (cfg->en_crc_check ? BIT(24) : 0);
  65. reg_value |= (cfg->en_ecc_check ? BIT(20) : 0);
  66. reg_value |= BIT(8); /* Clock lane */
  67. reg_value |= ((cfg->data_lanes & DSI_DATA_LANE_3) ? BIT(7) : 0);
  68. reg_value |= ((cfg->data_lanes & DSI_DATA_LANE_2) ? BIT(6) : 0);
  69. reg_value |= ((cfg->data_lanes & DSI_DATA_LANE_1) ? BIT(5) : 0);
  70. reg_value |= ((cfg->data_lanes & DSI_DATA_LANE_0) ? BIT(4) : 0);
  71. DSI_W32(ctrl, DSI_CTRL, reg_value);
  72. if (ctrl->phy_isolation_enabled)
  73. DSI_W32(ctrl, DSI_DEBUG_CTRL, BIT(28));
  74. pr_debug("[DSI_%d]Host configuration complete\n", ctrl->index);
  75. }
  76. /**
  77. * phy_sw_reset() - perform a soft reset on the PHY.
  78. * @ctrl: Pointer to the controller host hardware.
  79. */
  80. void dsi_ctrl_hw_cmn_phy_sw_reset(struct dsi_ctrl_hw *ctrl)
  81. {
  82. DSI_W32(ctrl, DSI_PHY_SW_RESET, BIT(24)|BIT(0));
  83. wmb(); /* make sure reset is asserted */
  84. udelay(1000);
  85. DSI_W32(ctrl, DSI_PHY_SW_RESET, 0x0);
  86. wmb(); /* ensure reset is cleared before waiting */
  87. udelay(100);
  88. pr_debug("[DSI_%d] phy sw reset done\n", ctrl->index);
  89. }
  90. /**
  91. * soft_reset() - perform a soft reset on DSI controller
  92. * @ctrl: Pointer to the controller host hardware.
  93. *
  94. * The video, command and controller engines will be disabled before the
  95. * reset is triggered and re-enabled after the reset is complete.
  96. *
  97. * If the reset is done while MDP timing engine is turned on, the video
  98. * enigne should be re-enabled only during the vertical blanking time.
  99. */
  100. void dsi_ctrl_hw_cmn_soft_reset(struct dsi_ctrl_hw *ctrl)
  101. {
  102. u32 reg = 0;
  103. u32 reg_ctrl = 0;
  104. /* Clear DSI_EN, VIDEO_MODE_EN, CMD_MODE_EN */
  105. reg_ctrl = DSI_R32(ctrl, DSI_CTRL);
  106. DSI_W32(ctrl, DSI_CTRL, reg_ctrl & ~0x7);
  107. wmb(); /* wait controller to be disabled before reset */
  108. /* Force enable PCLK, BYTECLK, AHBM_HCLK */
  109. reg = DSI_R32(ctrl, DSI_CLK_CTRL);
  110. DSI_W32(ctrl, DSI_CLK_CTRL, reg | DSI_CTRL_DYNAMIC_FORCE_ON);
  111. wmb(); /* wait for clocks to be enabled */
  112. /* Trigger soft reset */
  113. DSI_W32(ctrl, DSI_SOFT_RESET, 0x1);
  114. wmb(); /* wait for reset to assert before waiting */
  115. udelay(1);
  116. DSI_W32(ctrl, DSI_SOFT_RESET, 0x0);
  117. wmb(); /* ensure reset is cleared */
  118. /* Disable force clock on */
  119. DSI_W32(ctrl, DSI_CLK_CTRL, reg);
  120. wmb(); /* make sure clocks are restored */
  121. /* Re-enable DSI controller */
  122. DSI_W32(ctrl, DSI_CTRL, reg_ctrl);
  123. wmb(); /* make sure DSI controller is enabled again */
  124. pr_debug("[DSI_%d] ctrl soft reset done\n", ctrl->index);
  125. }
  126. /**
  127. * setup_misr() - Setup frame MISR
  128. * @ctrl: Pointer to the controller host hardware.
  129. * @panel_mode: CMD or VIDEO mode indicator
  130. * @enable: Enable/disable MISR.
  131. * @frame_count: Number of frames to accumulate MISR.
  132. */
  133. void dsi_ctrl_hw_cmn_setup_misr(struct dsi_ctrl_hw *ctrl,
  134. enum dsi_op_mode panel_mode,
  135. bool enable,
  136. u32 frame_count)
  137. {
  138. u32 addr;
  139. u32 config = 0;
  140. if (panel_mode == DSI_OP_CMD_MODE) {
  141. addr = DSI_MISR_CMD_CTRL;
  142. if (enable)
  143. config = DSI_CTRL_CMD_MISR_ENABLE;
  144. } else {
  145. addr = DSI_MISR_VIDEO_CTRL;
  146. if (enable)
  147. config = DSI_CTRL_VIDEO_MISR_ENABLE;
  148. if (frame_count > 255)
  149. frame_count = 255;
  150. config |= frame_count << 8;
  151. }
  152. pr_debug("[DSI_%d] MISR ctrl: 0x%x\n", ctrl->index,
  153. config);
  154. DSI_W32(ctrl, addr, config);
  155. wmb(); /* make sure MISR is configured */
  156. }
  157. /**
  158. * collect_misr() - Read frame MISR
  159. * @ctrl: Pointer to the controller host hardware.
  160. * @panel_mode: CMD or VIDEO mode indicator
  161. */
  162. u32 dsi_ctrl_hw_cmn_collect_misr(struct dsi_ctrl_hw *ctrl,
  163. enum dsi_op_mode panel_mode)
  164. {
  165. u32 addr;
  166. u32 enabled;
  167. u32 misr = 0;
  168. if (panel_mode == DSI_OP_CMD_MODE) {
  169. addr = DSI_MISR_CMD_MDP0_32BIT;
  170. enabled = DSI_R32(ctrl, DSI_MISR_CMD_CTRL) &
  171. DSI_CTRL_CMD_MISR_ENABLE;
  172. } else {
  173. addr = DSI_MISR_VIDEO_32BIT;
  174. enabled = DSI_R32(ctrl, DSI_MISR_VIDEO_CTRL) &
  175. DSI_CTRL_VIDEO_MISR_ENABLE;
  176. }
  177. if (enabled)
  178. misr = DSI_R32(ctrl, addr);
  179. pr_debug("[DSI_%d] MISR enabled %x value: 0x%x\n", ctrl->index,
  180. enabled, misr);
  181. return misr;
  182. }
  183. /**
  184. * set_timing_db() - enable/disable Timing DB register
  185. * @ctrl: Pointer to controller host hardware.
  186. * @enable: Enable/Disable flag.
  187. *
  188. * Enable or Disabe the Timing DB register.
  189. */
  190. void dsi_ctrl_hw_cmn_set_timing_db(struct dsi_ctrl_hw *ctrl,
  191. bool enable)
  192. {
  193. if (enable)
  194. DSI_W32(ctrl, DSI_DSI_TIMING_DB_MODE, 0x1);
  195. else
  196. DSI_W32(ctrl, DSI_DSI_TIMING_DB_MODE, 0x0);
  197. wmb(); /* make sure timing db registers are set */
  198. pr_debug("[DSI_%d] ctrl timing DB set:%d\n", ctrl->index,
  199. enable);
  200. SDE_EVT32(ctrl->index, enable);
  201. }
  202. /**
  203. * set_video_timing() - set up the timing for video frame
  204. * @ctrl: Pointer to controller host hardware.
  205. * @mode: Video mode information.
  206. *
  207. * Set up the video timing parameters for the DSI video mode operation.
  208. */
  209. void dsi_ctrl_hw_cmn_set_video_timing(struct dsi_ctrl_hw *ctrl,
  210. struct dsi_mode_info *mode)
  211. {
  212. u32 reg = 0;
  213. u32 hs_start = 0;
  214. u32 hs_end, active_h_start, active_h_end, h_total, width = 0;
  215. u32 vs_start = 0, vs_end = 0;
  216. u32 vpos_start = 0, vpos_end, active_v_start, active_v_end, v_total;
  217. if (mode->dsc_enabled && mode->dsc) {
  218. width = mode->dsc->pclk_per_line;
  219. reg = mode->dsc->bytes_per_pkt << 16;
  220. reg |= (0x0b << 8); /* dtype of compressed image */
  221. /*
  222. * pkt_per_line:
  223. * 0 == 1 pkt
  224. * 1 == 2 pkt
  225. * 2 == 4 pkt
  226. * 3 pkt is not support
  227. */
  228. if (mode->dsc->pkt_per_line == 4)
  229. reg |= (mode->dsc->pkt_per_line - 2) << 6;
  230. else
  231. reg |= (mode->dsc->pkt_per_line - 1) << 6;
  232. reg |= mode->dsc->eol_byte_num << 4;
  233. reg |= 1;
  234. DSI_W32(ctrl, DSI_VIDEO_COMPRESSION_MODE_CTRL, reg);
  235. } else {
  236. width = mode->h_active;
  237. }
  238. hs_end = mode->h_sync_width;
  239. active_h_start = mode->h_sync_width + mode->h_back_porch;
  240. active_h_end = active_h_start + width;
  241. h_total = (mode->h_sync_width + mode->h_back_porch + width +
  242. mode->h_front_porch) - 1;
  243. vpos_end = mode->v_sync_width;
  244. active_v_start = mode->v_sync_width + mode->v_back_porch;
  245. active_v_end = active_v_start + mode->v_active;
  246. v_total = (mode->v_sync_width + mode->v_back_porch + mode->v_active +
  247. mode->v_front_porch) - 1;
  248. reg = ((active_h_end & 0xFFFF) << 16) | (active_h_start & 0xFFFF);
  249. DSI_W32(ctrl, DSI_VIDEO_MODE_ACTIVE_H, reg);
  250. reg = ((active_v_end & 0xFFFF) << 16) | (active_v_start & 0xFFFF);
  251. DSI_W32(ctrl, DSI_VIDEO_MODE_ACTIVE_V, reg);
  252. reg = ((v_total & 0xFFFF) << 16) | (h_total & 0xFFFF);
  253. DSI_W32(ctrl, DSI_VIDEO_MODE_TOTAL, reg);
  254. reg = ((hs_end & 0xFFFF) << 16) | (hs_start & 0xFFFF);
  255. DSI_W32(ctrl, DSI_VIDEO_MODE_HSYNC, reg);
  256. reg = ((vs_end & 0xFFFF) << 16) | (vs_start & 0xFFFF);
  257. DSI_W32(ctrl, DSI_VIDEO_MODE_VSYNC, reg);
  258. reg = ((vpos_end & 0xFFFF) << 16) | (vpos_start & 0xFFFF);
  259. DSI_W32(ctrl, DSI_VIDEO_MODE_VSYNC_VPOS, reg);
  260. /* TODO: HS TIMER value? */
  261. DSI_W32(ctrl, DSI_HS_TIMER_CTRL, 0x3FD08);
  262. DSI_W32(ctrl, DSI_MISR_VIDEO_CTRL, 0x10100);
  263. DSI_W32(ctrl, DSI_DSI_TIMING_FLUSH, 0x1);
  264. pr_debug("[DSI_%d] ctrl video parameters updated\n", ctrl->index);
  265. SDE_EVT32(v_total, h_total);
  266. }
  267. /**
  268. * setup_cmd_stream() - set up parameters for command pixel streams
  269. * @ctrl: Pointer to controller host hardware.
  270. * @mode: Pointer to mode information.
  271. * @h_stride: Horizontal stride in bytes.
  272. * @vc_id: stream_id
  273. *
  274. * Setup parameters for command mode pixel stream size.
  275. */
  276. void dsi_ctrl_hw_cmn_setup_cmd_stream(struct dsi_ctrl_hw *ctrl,
  277. struct dsi_mode_info *mode,
  278. u32 h_stride,
  279. u32 vc_id,
  280. struct dsi_rect *roi)
  281. {
  282. u32 width_final, stride_final;
  283. u32 height_final;
  284. u32 stream_total = 0, stream_ctrl = 0;
  285. u32 reg_ctrl = 0, reg_ctrl2 = 0, data = 0;
  286. if (roi && (!roi->w || !roi->h))
  287. return;
  288. if (mode->dsc_enabled && mode->dsc) {
  289. u32 reg = 0;
  290. u32 offset = 0;
  291. int pic_width, this_frame_slices, intf_ip_w;
  292. struct msm_display_dsc_info dsc;
  293. memcpy(&dsc, mode->dsc, sizeof(dsc));
  294. pic_width = roi ? roi->w : mode->h_active;
  295. this_frame_slices = pic_width / dsc.slice_width;
  296. intf_ip_w = this_frame_slices * dsc.slice_width;
  297. dsi_dsc_pclk_param_calc(&dsc, intf_ip_w);
  298. if (vc_id != 0)
  299. offset = 16;
  300. reg_ctrl = DSI_R32(ctrl, DSI_COMMAND_COMPRESSION_MODE_CTRL);
  301. reg_ctrl2 = DSI_R32(ctrl, DSI_COMMAND_COMPRESSION_MODE_CTRL2);
  302. width_final = dsc.pclk_per_line;
  303. stride_final = dsc.bytes_per_pkt;
  304. height_final = roi ? roi->h : mode->v_active;
  305. reg = 0x39 << 8;
  306. /*
  307. * pkt_per_line:
  308. * 0 == 1 pkt
  309. * 1 == 2 pkt
  310. * 2 == 4 pkt
  311. * 3 pkt is not support
  312. */
  313. if (dsc.pkt_per_line == 4)
  314. reg |= (dsc.pkt_per_line - 2) << 6;
  315. else
  316. reg |= (dsc.pkt_per_line - 1) << 6;
  317. reg |= dsc.eol_byte_num << 4;
  318. reg |= 1;
  319. reg_ctrl &= ~(0xFFFF << offset);
  320. reg_ctrl |= (reg << offset);
  321. reg_ctrl2 &= ~(0xFFFF << offset);
  322. reg_ctrl2 |= (dsc.bytes_in_slice << offset);
  323. pr_debug("ctrl %d reg_ctrl 0x%x reg_ctrl2 0x%x\n", ctrl->index,
  324. reg_ctrl, reg_ctrl2);
  325. } else if (roi) {
  326. width_final = roi->w;
  327. stride_final = roi->w * 3;
  328. height_final = roi->h;
  329. } else {
  330. width_final = mode->h_active;
  331. stride_final = h_stride;
  332. height_final = mode->v_active;
  333. }
  334. /* HS Timer value */
  335. DSI_W32(ctrl, DSI_HS_TIMER_CTRL, 0x3FD08);
  336. stream_ctrl = (stride_final + 1) << 16;
  337. stream_ctrl |= (vc_id & 0x3) << 8;
  338. stream_ctrl |= 0x39; /* packet data type */
  339. DSI_W32(ctrl, DSI_COMMAND_COMPRESSION_MODE_CTRL, reg_ctrl);
  340. DSI_W32(ctrl, DSI_COMMAND_COMPRESSION_MODE_CTRL2, reg_ctrl2);
  341. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_STREAM0_CTRL, stream_ctrl);
  342. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_STREAM1_CTRL, stream_ctrl);
  343. stream_total = (height_final << 16) | width_final;
  344. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_STREAM0_TOTAL, stream_total);
  345. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_STREAM1_TOTAL, stream_total);
  346. if (ctrl->null_insertion_enabled) {
  347. /* enable null packet insertion */
  348. data = (vc_id << 1);
  349. data |= 0 << 16;
  350. data |= 0x1;
  351. DSI_W32(ctrl, DSI_COMMAND_MODE_NULL_INSERTION_CTRL, data);
  352. }
  353. pr_debug("ctrl %d stream_ctrl 0x%x stream_total 0x%x\n", ctrl->index,
  354. stream_ctrl, stream_total);
  355. }
  356. /**
  357. * setup_avr() - set the AVR_SUPPORT_ENABLE bit in DSI_VIDEO_MODE_CTRL
  358. * @ctrl: Pointer to controller host hardware.
  359. * @enable: Controls whether this bit is set or cleared
  360. *
  361. * Set or clear the AVR_SUPPORT_ENABLE bit in DSI_VIDEO_MODE_CTRL.
  362. */
  363. void dsi_ctrl_hw_cmn_setup_avr(struct dsi_ctrl_hw *ctrl, bool enable)
  364. {
  365. u32 reg = DSI_R32(ctrl, DSI_VIDEO_MODE_CTRL);
  366. if (enable)
  367. reg |= BIT(29);
  368. else
  369. reg &= ~BIT(29);
  370. DSI_W32(ctrl, DSI_VIDEO_MODE_CTRL, reg);
  371. pr_debug("ctrl %d AVR %s\n", ctrl->index,
  372. enable ? "enabled" : "disabled");
  373. }
  374. /**
  375. * video_engine_setup() - Setup dsi host controller for video mode
  376. * @ctrl: Pointer to controller host hardware.
  377. * @common_cfg: Common configuration parameters.
  378. * @cfg: Video mode configuration.
  379. *
  380. * Set up DSI video engine with a specific configuration. Controller and
  381. * video engine are not enabled as part of this function.
  382. */
  383. void dsi_ctrl_hw_cmn_video_engine_setup(struct dsi_ctrl_hw *ctrl,
  384. struct dsi_host_common_cfg *common_cfg,
  385. struct dsi_video_engine_cfg *cfg)
  386. {
  387. u32 reg = 0;
  388. reg |= (cfg->last_line_interleave_en ? BIT(31) : 0);
  389. reg |= (cfg->pulse_mode_hsa_he ? BIT(28) : 0);
  390. reg |= (cfg->hfp_lp11_en ? BIT(24) : 0);
  391. reg |= (cfg->hbp_lp11_en ? BIT(20) : 0);
  392. reg |= (cfg->hsa_lp11_en ? BIT(16) : 0);
  393. reg |= (cfg->eof_bllp_lp11_en ? BIT(15) : 0);
  394. reg |= (cfg->bllp_lp11_en ? BIT(12) : 0);
  395. reg |= (cfg->traffic_mode & 0x3) << 8;
  396. reg |= (cfg->vc_id & 0x3);
  397. reg |= (video_mode_format_map[common_cfg->dst_format] & 0x3) << 4;
  398. DSI_W32(ctrl, DSI_VIDEO_MODE_CTRL, reg);
  399. reg = (common_cfg->swap_mode & 0x7) << 12;
  400. reg |= (common_cfg->bit_swap_red ? BIT(0) : 0);
  401. reg |= (common_cfg->bit_swap_green ? BIT(4) : 0);
  402. reg |= (common_cfg->bit_swap_blue ? BIT(8) : 0);
  403. DSI_W32(ctrl, DSI_VIDEO_MODE_DATA_CTRL, reg);
  404. /* Disable Timing double buffering */
  405. DSI_W32(ctrl, DSI_DSI_TIMING_DB_MODE, 0x0);
  406. pr_debug("[DSI_%d] Video engine setup done\n", ctrl->index);
  407. }
  408. void dsi_ctrl_hw_cmn_debug_bus(struct dsi_ctrl_hw *ctrl, u32 *entries, u32 size)
  409. {
  410. u32 reg = 0, i = 0;
  411. for (i = 0; i < size; i++) {
  412. DSI_W32(ctrl, DSI_DEBUG_BUS_CTL, entries[i]);
  413. /* make sure that debug test point is enabled */
  414. wmb();
  415. reg = DSI_R32(ctrl, DSI_DEBUG_BUS_STATUS);
  416. pr_err("[DSI_%d] debug bus ctrl: 0x%x status:0x%x\n",
  417. ctrl->index, entries[i], reg);
  418. }
  419. }
  420. /**
  421. * cmd_engine_setup() - setup dsi host controller for command mode
  422. * @ctrl: Pointer to the controller host hardware.
  423. * @common_cfg: Common configuration parameters.
  424. * @cfg: Command mode configuration.
  425. *
  426. * Setup DSI CMD engine with a specific configuration. Controller and
  427. * command engine are not enabled as part of this function.
  428. */
  429. void dsi_ctrl_hw_cmn_cmd_engine_setup(struct dsi_ctrl_hw *ctrl,
  430. struct dsi_host_common_cfg *common_cfg,
  431. struct dsi_cmd_engine_cfg *cfg)
  432. {
  433. u32 reg = 0;
  434. reg = (cfg->max_cmd_packets_interleave & 0xF) << 20;
  435. reg |= (common_cfg->bit_swap_red ? BIT(4) : 0);
  436. reg |= (common_cfg->bit_swap_green ? BIT(8) : 0);
  437. reg |= (common_cfg->bit_swap_blue ? BIT(12) : 0);
  438. reg |= cmd_mode_format_map[common_cfg->dst_format];
  439. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_CTRL, reg);
  440. reg = DSI_R32(ctrl, DSI_COMMAND_MODE_MDP_CTRL2);
  441. reg |= BIT(16);
  442. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_CTRL2, reg);
  443. reg = cfg->wr_mem_start & 0xFF;
  444. reg |= (cfg->wr_mem_continue & 0xFF) << 8;
  445. reg |= (cfg->insert_dcs_command ? BIT(16) : 0);
  446. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_DCS_CMD_CTRL, reg);
  447. pr_debug("[DSI_%d] Cmd engine setup done\n", ctrl->index);
  448. }
  449. /**
  450. * video_engine_en() - enable DSI video engine
  451. * @ctrl: Pointer to controller host hardware.
  452. * @on: Enable/disabel video engine.
  453. */
  454. void dsi_ctrl_hw_cmn_video_engine_en(struct dsi_ctrl_hw *ctrl, bool on)
  455. {
  456. u32 reg = 0;
  457. /* Set/Clear VIDEO_MODE_EN bit */
  458. reg = DSI_R32(ctrl, DSI_CTRL);
  459. if (on)
  460. reg |= BIT(1);
  461. else
  462. reg &= ~BIT(1);
  463. DSI_W32(ctrl, DSI_CTRL, reg);
  464. pr_debug("[DSI_%d] Video engine = %d\n", ctrl->index, on);
  465. }
  466. /**
  467. * ctrl_en() - enable DSI controller engine
  468. * @ctrl: Pointer to the controller host hardware.
  469. * @on: turn on/off the DSI controller engine.
  470. */
  471. void dsi_ctrl_hw_cmn_ctrl_en(struct dsi_ctrl_hw *ctrl, bool on)
  472. {
  473. u32 reg = 0;
  474. u32 clk_ctrl;
  475. clk_ctrl = DSI_R32(ctrl, DSI_CLK_CTRL);
  476. DSI_W32(ctrl, DSI_CLK_CTRL, clk_ctrl | DSI_CTRL_DYNAMIC_FORCE_ON);
  477. wmb(); /* wait for clocks to enable */
  478. /* Set/Clear DSI_EN bit */
  479. reg = DSI_R32(ctrl, DSI_CTRL);
  480. if (on)
  481. reg |= BIT(0);
  482. else
  483. reg &= ~BIT(0);
  484. DSI_W32(ctrl, DSI_CTRL, reg);
  485. wmb(); /* wait for DSI_EN update before disabling clocks */
  486. DSI_W32(ctrl, DSI_CLK_CTRL, clk_ctrl);
  487. wmb(); /* make sure clocks are restored */
  488. pr_debug("[DSI_%d] Controller engine = %d\n", ctrl->index, on);
  489. }
  490. /**
  491. * cmd_engine_en() - enable DSI controller command engine
  492. * @ctrl: Pointer to the controller host hardware.
  493. * @on: Turn on/off the DSI command engine.
  494. */
  495. void dsi_ctrl_hw_cmn_cmd_engine_en(struct dsi_ctrl_hw *ctrl, bool on)
  496. {
  497. u32 reg = 0;
  498. /* Set/Clear CMD_MODE_EN bit */
  499. reg = DSI_R32(ctrl, DSI_CTRL);
  500. if (on)
  501. reg |= BIT(2);
  502. else
  503. reg &= ~BIT(2);
  504. DSI_W32(ctrl, DSI_CTRL, reg);
  505. pr_debug("[DSI_%d] command engine = %d\n", ctrl->index, on);
  506. }
  507. /**
  508. * kickoff_command() - transmits commands stored in memory
  509. * @ctrl: Pointer to the controller host hardware.
  510. * @cmd: Command information.
  511. * @flags: Modifiers for command transmission.
  512. *
  513. * The controller hardware is programmed with address and size of the
  514. * command buffer. The transmission is kicked off if
  515. * DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER flag is not set. If this flag is
  516. * set, caller should make a separate call to trigger_command_dma() to
  517. * transmit the command.
  518. */
  519. void dsi_ctrl_hw_cmn_kickoff_command(struct dsi_ctrl_hw *ctrl,
  520. struct dsi_ctrl_cmd_dma_info *cmd,
  521. u32 flags)
  522. {
  523. u32 reg = 0;
  524. /*Set BROADCAST_EN and EMBEDDED_MODE */
  525. reg = DSI_R32(ctrl, DSI_COMMAND_MODE_DMA_CTRL);
  526. if (cmd->en_broadcast)
  527. reg |= BIT(31);
  528. else
  529. reg &= ~BIT(31);
  530. if (cmd->is_master)
  531. reg |= BIT(30);
  532. else
  533. reg &= ~BIT(30);
  534. if (cmd->use_lpm)
  535. reg |= BIT(26);
  536. else
  537. reg &= ~BIT(26);
  538. reg |= BIT(28);/* Select embedded mode */
  539. reg &= ~BIT(24);/* packet type */
  540. reg &= ~BIT(29);/* WC_SEL to 0 */
  541. DSI_W32(ctrl, DSI_COMMAND_MODE_DMA_CTRL, reg);
  542. reg = DSI_R32(ctrl, DSI_DMA_FIFO_CTRL);
  543. reg |= BIT(20);/* Disable write watermark*/
  544. reg |= BIT(16);/* Disable read watermark */
  545. DSI_W32(ctrl, DSI_DMA_FIFO_CTRL, reg);
  546. DSI_W32(ctrl, DSI_DMA_CMD_OFFSET, cmd->offset);
  547. DSI_W32(ctrl, DSI_DMA_CMD_LENGTH, (cmd->length & 0xFFFFFF));
  548. /* wait for writes to complete before kick off */
  549. wmb();
  550. if (!(flags & DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER))
  551. DSI_W32(ctrl, DSI_CMD_MODE_DMA_SW_TRIGGER, 0x1);
  552. }
  553. /**
  554. * kickoff_fifo_command() - transmits a command using FIFO in dsi
  555. * hardware.
  556. * @ctrl: Pointer to the controller host hardware.
  557. * @cmd: Command information.
  558. * @flags: Modifiers for command transmission.
  559. *
  560. * The controller hardware FIFO is programmed with command header and
  561. * payload. The transmission is kicked off if
  562. * DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER flag is not set. If this flag is
  563. * set, caller should make a separate call to trigger_command_dma() to
  564. * transmit the command.
  565. */
  566. void dsi_ctrl_hw_cmn_kickoff_fifo_command(struct dsi_ctrl_hw *ctrl,
  567. struct dsi_ctrl_cmd_dma_fifo_info *cmd,
  568. u32 flags)
  569. {
  570. u32 reg = 0, i = 0;
  571. u32 *ptr = cmd->command;
  572. /*
  573. * Set CMD_DMA_TPG_EN, TPG_DMA_FIFO_MODE and
  574. * CMD_DMA_PATTERN_SEL = custom pattern stored in TPG DMA FIFO
  575. */
  576. reg = (BIT(1) | BIT(2) | (0x3 << 16));
  577. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  578. /*
  579. * Program the FIFO with command buffer. Hardware requires an extra
  580. * DWORD (set to zero) if the length of command buffer is odd DWORDS.
  581. */
  582. for (i = 0; i < cmd->size; i += 4) {
  583. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_DMA_INIT_VAL, *ptr);
  584. ptr++;
  585. }
  586. if ((cmd->size / 4) & 0x1)
  587. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_DMA_INIT_VAL, 0);
  588. /*Set BROADCAST_EN and EMBEDDED_MODE */
  589. reg = DSI_R32(ctrl, DSI_COMMAND_MODE_DMA_CTRL);
  590. if (cmd->en_broadcast)
  591. reg |= BIT(31);
  592. else
  593. reg &= ~BIT(31);
  594. if (cmd->is_master)
  595. reg |= BIT(30);
  596. else
  597. reg &= ~BIT(30);
  598. if (cmd->use_lpm)
  599. reg |= BIT(26);
  600. else
  601. reg &= ~BIT(26);
  602. reg |= BIT(28);
  603. DSI_W32(ctrl, DSI_COMMAND_MODE_DMA_CTRL, reg);
  604. DSI_W32(ctrl, DSI_DMA_CMD_LENGTH, (cmd->size & 0xFFFFFFFF));
  605. /* Finish writes before command trigger */
  606. wmb();
  607. if (!(flags & DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER))
  608. DSI_W32(ctrl, DSI_CMD_MODE_DMA_SW_TRIGGER, 0x1);
  609. pr_debug("[DSI_%d]size=%d, trigger = %d\n",
  610. ctrl->index, cmd->size,
  611. (flags & DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER) ? false : true);
  612. }
  613. void dsi_ctrl_hw_cmn_reset_cmd_fifo(struct dsi_ctrl_hw *ctrl)
  614. {
  615. /* disable cmd dma tpg */
  616. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, 0x0);
  617. DSI_W32(ctrl, DSI_TPG_DMA_FIFO_RESET, 0x1);
  618. udelay(1);
  619. DSI_W32(ctrl, DSI_TPG_DMA_FIFO_RESET, 0x0);
  620. }
  621. /**
  622. * trigger_command_dma() - trigger transmission of command buffer.
  623. * @ctrl: Pointer to the controller host hardware.
  624. *
  625. * This trigger can be only used if there was a prior call to
  626. * kickoff_command() of kickoff_fifo_command() with
  627. * DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER flag.
  628. */
  629. void dsi_ctrl_hw_cmn_trigger_command_dma(struct dsi_ctrl_hw *ctrl)
  630. {
  631. DSI_W32(ctrl, DSI_CMD_MODE_DMA_SW_TRIGGER, 0x1);
  632. pr_debug("[DSI_%d] CMD DMA triggered\n", ctrl->index);
  633. }
  634. /**
  635. * clear_rdbk_reg() - clear previously read panel data.
  636. * @ctrl: Pointer to the controller host hardware.
  637. *
  638. * This function is called before sending DSI Rx command to
  639. * panel in order to clear if any stale data remaining from
  640. * previous read operation.
  641. */
  642. void dsi_ctrl_hw_cmn_clear_rdbk_reg(struct dsi_ctrl_hw *ctrl)
  643. {
  644. DSI_W32(ctrl, DSI_RDBK_DATA_CTRL, 0x1);
  645. wmb(); /* ensure read back register is reset */
  646. DSI_W32(ctrl, DSI_RDBK_DATA_CTRL, 0x0);
  647. wmb(); /* ensure read back register is cleared */
  648. }
  649. /**
  650. * get_cmd_read_data() - get data read from the peripheral
  651. * @ctrl: Pointer to the controller host hardware.
  652. * @rd_buf: Buffer where data will be read into.
  653. * @total_read_len: Number of bytes to read.
  654. *
  655. * return: number of bytes read.
  656. */
  657. u32 dsi_ctrl_hw_cmn_get_cmd_read_data(struct dsi_ctrl_hw *ctrl,
  658. u8 *rd_buf,
  659. u32 read_offset,
  660. u32 rx_byte,
  661. u32 pkt_size,
  662. u32 *hw_read_cnt)
  663. {
  664. u32 *lp, *temp, data;
  665. int i, j = 0, cnt, off;
  666. u32 read_cnt;
  667. u32 repeated_bytes = 0;
  668. u8 reg[16] = {0};
  669. bool ack_err = false;
  670. lp = (u32 *)rd_buf;
  671. temp = (u32 *)reg;
  672. cnt = (rx_byte + 3) >> 2;
  673. if (cnt > 4)
  674. cnt = 4;
  675. read_cnt = (DSI_R32(ctrl, DSI_RDBK_DATA_CTRL) >> 16);
  676. ack_err = (rx_byte == 4) ? (read_cnt == 8) :
  677. ((read_cnt - 4) == (pkt_size + 6));
  678. if (ack_err)
  679. read_cnt -= 4;
  680. if (!read_cnt) {
  681. pr_err("Panel detected error, no data read\n");
  682. return 0;
  683. }
  684. if (read_cnt > 16) {
  685. int bytes_shifted, data_lost = 0, rem_header = 0;
  686. bytes_shifted = read_cnt - rx_byte;
  687. if (bytes_shifted >= 4)
  688. data_lost = bytes_shifted - 4; /* remove DCS header */
  689. else
  690. rem_header = 4 - bytes_shifted; /* remaining header */
  691. repeated_bytes = (read_offset - 4) - data_lost + rem_header;
  692. }
  693. off = DSI_RDBK_DATA0;
  694. off += ((cnt - 1) * 4);
  695. for (i = 0; i < cnt; i++) {
  696. data = DSI_R32(ctrl, off);
  697. if (!repeated_bytes)
  698. *lp++ = ntohl(data);
  699. else
  700. *temp++ = ntohl(data);
  701. off -= 4;
  702. }
  703. if (repeated_bytes) {
  704. for (i = repeated_bytes; i < 16; i++)
  705. rd_buf[j++] = reg[i];
  706. }
  707. *hw_read_cnt = read_cnt;
  708. pr_debug("[DSI_%d] Read %d bytes\n", ctrl->index, rx_byte);
  709. return rx_byte;
  710. }
  711. /**
  712. * get_interrupt_status() - returns the interrupt status
  713. * @ctrl: Pointer to the controller host hardware.
  714. *
  715. * Returns the ORed list of interrupts(enum dsi_status_int_type) that
  716. * are active. This list does not include any error interrupts. Caller
  717. * should call get_error_status for error interrupts.
  718. *
  719. * Return: List of active interrupts.
  720. */
  721. u32 dsi_ctrl_hw_cmn_get_interrupt_status(struct dsi_ctrl_hw *ctrl)
  722. {
  723. u32 reg = 0;
  724. u32 ints = 0;
  725. reg = DSI_R32(ctrl, DSI_INT_CTRL);
  726. if (reg & BIT(0))
  727. ints |= DSI_CMD_MODE_DMA_DONE;
  728. if (reg & BIT(8))
  729. ints |= DSI_CMD_FRAME_DONE;
  730. if (reg & BIT(10))
  731. ints |= DSI_CMD_STREAM0_FRAME_DONE;
  732. if (reg & BIT(12))
  733. ints |= DSI_CMD_STREAM1_FRAME_DONE;
  734. if (reg & BIT(14))
  735. ints |= DSI_CMD_STREAM2_FRAME_DONE;
  736. if (reg & BIT(16))
  737. ints |= DSI_VIDEO_MODE_FRAME_DONE;
  738. if (reg & BIT(20))
  739. ints |= DSI_BTA_DONE;
  740. if (reg & BIT(28))
  741. ints |= DSI_DYN_REFRESH_DONE;
  742. if (reg & BIT(30))
  743. ints |= DSI_DESKEW_DONE;
  744. if (reg & BIT(24))
  745. ints |= DSI_ERROR;
  746. pr_debug("[DSI_%d] Interrupt status = 0x%x, INT_CTRL=0x%x\n",
  747. ctrl->index, ints, reg);
  748. return ints;
  749. }
  750. /**
  751. * clear_interrupt_status() - clears the specified interrupts
  752. * @ctrl: Pointer to the controller host hardware.
  753. * @ints: List of interrupts to be cleared.
  754. */
  755. void dsi_ctrl_hw_cmn_clear_interrupt_status(struct dsi_ctrl_hw *ctrl, u32 ints)
  756. {
  757. u32 reg = 0;
  758. reg = DSI_R32(ctrl, DSI_INT_CTRL);
  759. if (ints & DSI_CMD_MODE_DMA_DONE)
  760. reg |= BIT(0);
  761. if (ints & DSI_CMD_FRAME_DONE)
  762. reg |= BIT(8);
  763. if (ints & DSI_CMD_STREAM0_FRAME_DONE)
  764. reg |= BIT(10);
  765. if (ints & DSI_CMD_STREAM1_FRAME_DONE)
  766. reg |= BIT(12);
  767. if (ints & DSI_CMD_STREAM2_FRAME_DONE)
  768. reg |= BIT(14);
  769. if (ints & DSI_VIDEO_MODE_FRAME_DONE)
  770. reg |= BIT(16);
  771. if (ints & DSI_BTA_DONE)
  772. reg |= BIT(20);
  773. if (ints & DSI_DYN_REFRESH_DONE)
  774. reg |= BIT(28);
  775. if (ints & DSI_DESKEW_DONE)
  776. reg |= BIT(30);
  777. /*
  778. * Do not clear error status.
  779. * It will be cleared as part of
  780. * error handler function.
  781. */
  782. reg &= ~BIT(24);
  783. DSI_W32(ctrl, DSI_INT_CTRL, reg);
  784. pr_debug("[DSI_%d] Clear interrupts, ints = 0x%x, INT_CTRL=0x%x\n",
  785. ctrl->index, ints, reg);
  786. }
  787. /**
  788. * enable_status_interrupts() - enable the specified interrupts
  789. * @ctrl: Pointer to the controller host hardware.
  790. * @ints: List of interrupts to be enabled.
  791. *
  792. * Enables the specified interrupts. This list will override the
  793. * previous interrupts enabled through this function. Caller has to
  794. * maintain the state of the interrupts enabled. To disable all
  795. * interrupts, set ints to 0.
  796. */
  797. void dsi_ctrl_hw_cmn_enable_status_interrupts(
  798. struct dsi_ctrl_hw *ctrl, u32 ints)
  799. {
  800. u32 reg = 0;
  801. /* Do not change value of DSI_ERROR_MASK bit */
  802. reg |= (DSI_R32(ctrl, DSI_INT_CTRL) & BIT(25));
  803. if (ints & DSI_CMD_MODE_DMA_DONE)
  804. reg |= BIT(1);
  805. if (ints & DSI_CMD_FRAME_DONE)
  806. reg |= BIT(9);
  807. if (ints & DSI_CMD_STREAM0_FRAME_DONE)
  808. reg |= BIT(11);
  809. if (ints & DSI_CMD_STREAM1_FRAME_DONE)
  810. reg |= BIT(13);
  811. if (ints & DSI_CMD_STREAM2_FRAME_DONE)
  812. reg |= BIT(15);
  813. if (ints & DSI_VIDEO_MODE_FRAME_DONE)
  814. reg |= BIT(17);
  815. if (ints & DSI_BTA_DONE)
  816. reg |= BIT(21);
  817. if (ints & DSI_DYN_REFRESH_DONE)
  818. reg |= BIT(29);
  819. if (ints & DSI_DESKEW_DONE)
  820. reg |= BIT(31);
  821. DSI_W32(ctrl, DSI_INT_CTRL, reg);
  822. pr_debug("[DSI_%d] Enable interrupts 0x%x, INT_CTRL=0x%x\n",
  823. ctrl->index, ints, reg);
  824. }
  825. /**
  826. * get_error_status() - returns the error status
  827. * @ctrl: Pointer to the controller host hardware.
  828. *
  829. * Returns the ORed list of errors(enum dsi_error_int_type) that are
  830. * active. This list does not include any status interrupts. Caller
  831. * should call get_interrupt_status for status interrupts.
  832. *
  833. * Return: List of active error interrupts.
  834. */
  835. u64 dsi_ctrl_hw_cmn_get_error_status(struct dsi_ctrl_hw *ctrl)
  836. {
  837. u32 dln0_phy_err;
  838. u32 fifo_status;
  839. u32 ack_error;
  840. u32 timeout_errors;
  841. u32 clk_error;
  842. u32 dsi_status;
  843. u64 errors = 0, shift = 0x1;
  844. dln0_phy_err = DSI_R32(ctrl, DSI_DLN0_PHY_ERR);
  845. if (dln0_phy_err & BIT(0))
  846. errors |= DSI_DLN0_ESC_ENTRY_ERR;
  847. if (dln0_phy_err & BIT(4))
  848. errors |= DSI_DLN0_ESC_SYNC_ERR;
  849. if (dln0_phy_err & BIT(8))
  850. errors |= DSI_DLN0_LP_CONTROL_ERR;
  851. if (dln0_phy_err & BIT(12))
  852. errors |= DSI_DLN0_LP0_CONTENTION;
  853. if (dln0_phy_err & BIT(16))
  854. errors |= DSI_DLN0_LP1_CONTENTION;
  855. fifo_status = DSI_R32(ctrl, DSI_FIFO_STATUS);
  856. if (fifo_status & BIT(7))
  857. errors |= DSI_CMD_MDP_FIFO_UNDERFLOW;
  858. if (fifo_status & BIT(10))
  859. errors |= DSI_CMD_DMA_FIFO_UNDERFLOW;
  860. if (fifo_status & BIT(18))
  861. errors |= DSI_DLN0_HS_FIFO_OVERFLOW;
  862. if (fifo_status & BIT(19))
  863. errors |= DSI_DLN0_HS_FIFO_UNDERFLOW;
  864. if (fifo_status & BIT(22))
  865. errors |= DSI_DLN1_HS_FIFO_OVERFLOW;
  866. if (fifo_status & BIT(23))
  867. errors |= DSI_DLN1_HS_FIFO_UNDERFLOW;
  868. if (fifo_status & BIT(26))
  869. errors |= DSI_DLN2_HS_FIFO_OVERFLOW;
  870. if (fifo_status & BIT(27))
  871. errors |= DSI_DLN2_HS_FIFO_UNDERFLOW;
  872. if (fifo_status & BIT(30))
  873. errors |= DSI_DLN3_HS_FIFO_OVERFLOW;
  874. if (fifo_status & BIT(31))
  875. errors |= DSI_DLN3_HS_FIFO_UNDERFLOW;
  876. ack_error = DSI_R32(ctrl, DSI_ACK_ERR_STATUS);
  877. if (ack_error & BIT(16))
  878. errors |= DSI_RDBK_SINGLE_ECC_ERR;
  879. if (ack_error & BIT(17))
  880. errors |= DSI_RDBK_MULTI_ECC_ERR;
  881. if (ack_error & BIT(20))
  882. errors |= DSI_RDBK_CRC_ERR;
  883. if (ack_error & BIT(23))
  884. errors |= DSI_RDBK_INCOMPLETE_PKT;
  885. if (ack_error & BIT(24))
  886. errors |= DSI_PERIPH_ERROR_PKT;
  887. if (ack_error & BIT(15))
  888. errors |= (shift << DSI_EINT_PANEL_SPECIFIC_ERR);
  889. timeout_errors = DSI_R32(ctrl, DSI_TIMEOUT_STATUS);
  890. if (timeout_errors & BIT(0))
  891. errors |= DSI_HS_TX_TIMEOUT;
  892. if (timeout_errors & BIT(4))
  893. errors |= DSI_LP_RX_TIMEOUT;
  894. if (timeout_errors & BIT(8))
  895. errors |= DSI_BTA_TIMEOUT;
  896. clk_error = DSI_R32(ctrl, DSI_CLK_STATUS);
  897. if (clk_error & BIT(16))
  898. errors |= DSI_PLL_UNLOCK;
  899. dsi_status = DSI_R32(ctrl, DSI_STATUS);
  900. if (dsi_status & BIT(31))
  901. errors |= DSI_INTERLEAVE_OP_CONTENTION;
  902. pr_debug("[DSI_%d] Error status = 0x%llx, phy=0x%x, fifo=0x%x\n",
  903. ctrl->index, errors, dln0_phy_err, fifo_status);
  904. pr_debug("[DSI_%d] ack=0x%x, timeout=0x%x, clk=0x%x, dsi=0x%x\n",
  905. ctrl->index, ack_error, timeout_errors, clk_error, dsi_status);
  906. return errors;
  907. }
  908. /**
  909. * clear_error_status() - clears the specified errors
  910. * @ctrl: Pointer to the controller host hardware.
  911. * @errors: List of errors to be cleared.
  912. */
  913. void dsi_ctrl_hw_cmn_clear_error_status(struct dsi_ctrl_hw *ctrl, u64 errors)
  914. {
  915. u32 dln0_phy_err = 0;
  916. u32 fifo_status = 0;
  917. u32 ack_error = 0;
  918. u32 timeout_error = 0;
  919. u32 clk_error = 0;
  920. u32 dsi_status = 0;
  921. if (errors & DSI_RDBK_SINGLE_ECC_ERR)
  922. ack_error |= BIT(16);
  923. if (errors & DSI_RDBK_MULTI_ECC_ERR)
  924. ack_error |= BIT(17);
  925. if (errors & DSI_RDBK_CRC_ERR)
  926. ack_error |= BIT(20);
  927. if (errors & DSI_RDBK_INCOMPLETE_PKT)
  928. ack_error |= BIT(23);
  929. if (errors & DSI_PERIPH_ERROR_PKT)
  930. ack_error |= BIT(24);
  931. if (errors & DSI_PANEL_SPECIFIC_ERR)
  932. ack_error |= BIT(15);
  933. if (errors & DSI_LP_RX_TIMEOUT)
  934. timeout_error |= BIT(4);
  935. if (errors & DSI_HS_TX_TIMEOUT)
  936. timeout_error |= BIT(0);
  937. if (errors & DSI_BTA_TIMEOUT)
  938. timeout_error |= BIT(8);
  939. if (errors & DSI_PLL_UNLOCK)
  940. clk_error |= BIT(16);
  941. if (errors & DSI_DLN0_LP0_CONTENTION)
  942. dln0_phy_err |= BIT(12);
  943. if (errors & DSI_DLN0_LP1_CONTENTION)
  944. dln0_phy_err |= BIT(16);
  945. if (errors & DSI_DLN0_ESC_ENTRY_ERR)
  946. dln0_phy_err |= BIT(0);
  947. if (errors & DSI_DLN0_ESC_SYNC_ERR)
  948. dln0_phy_err |= BIT(4);
  949. if (errors & DSI_DLN0_LP_CONTROL_ERR)
  950. dln0_phy_err |= BIT(8);
  951. if (errors & DSI_CMD_DMA_FIFO_UNDERFLOW)
  952. fifo_status |= BIT(10);
  953. if (errors & DSI_CMD_MDP_FIFO_UNDERFLOW)
  954. fifo_status |= BIT(7);
  955. if (errors & DSI_DLN0_HS_FIFO_OVERFLOW)
  956. fifo_status |= BIT(18);
  957. if (errors & DSI_DLN1_HS_FIFO_OVERFLOW)
  958. fifo_status |= BIT(22);
  959. if (errors & DSI_DLN2_HS_FIFO_OVERFLOW)
  960. fifo_status |= BIT(26);
  961. if (errors & DSI_DLN3_HS_FIFO_OVERFLOW)
  962. fifo_status |= BIT(30);
  963. if (errors & DSI_DLN0_HS_FIFO_UNDERFLOW)
  964. fifo_status |= BIT(19);
  965. if (errors & DSI_DLN1_HS_FIFO_UNDERFLOW)
  966. fifo_status |= BIT(23);
  967. if (errors & DSI_DLN2_HS_FIFO_UNDERFLOW)
  968. fifo_status |= BIT(27);
  969. if (errors & DSI_DLN3_HS_FIFO_UNDERFLOW)
  970. fifo_status |= BIT(31);
  971. if (errors & DSI_INTERLEAVE_OP_CONTENTION)
  972. dsi_status |= BIT(31);
  973. DSI_W32(ctrl, DSI_DLN0_PHY_ERR, dln0_phy_err);
  974. DSI_W32(ctrl, DSI_FIFO_STATUS, fifo_status);
  975. /* Writing of an extra 0 is needed to clear ack error bits */
  976. DSI_W32(ctrl, DSI_ACK_ERR_STATUS, ack_error);
  977. wmb(); /* make sure register is committed */
  978. DSI_W32(ctrl, DSI_ACK_ERR_STATUS, 0x0);
  979. DSI_W32(ctrl, DSI_TIMEOUT_STATUS, timeout_error);
  980. DSI_W32(ctrl, DSI_CLK_STATUS, clk_error);
  981. DSI_W32(ctrl, DSI_STATUS, dsi_status);
  982. pr_debug("[DSI_%d] clear errors = 0x%llx, phy=0x%x, fifo=0x%x\n",
  983. ctrl->index, errors, dln0_phy_err, fifo_status);
  984. pr_debug("[DSI_%d] ack=0x%x, timeout=0x%x, clk=0x%x, dsi=0x%x\n",
  985. ctrl->index, ack_error, timeout_error, clk_error, dsi_status);
  986. }
  987. /**
  988. * enable_error_interrupts() - enable the specified interrupts
  989. * @ctrl: Pointer to the controller host hardware.
  990. * @errors: List of errors to be enabled.
  991. *
  992. * Enables the specified interrupts. This list will override the
  993. * previous interrupts enabled through this function. Caller has to
  994. * maintain the state of the interrupts enabled. To disable all
  995. * interrupts, set errors to 0.
  996. */
  997. void dsi_ctrl_hw_cmn_enable_error_interrupts(struct dsi_ctrl_hw *ctrl,
  998. u64 errors)
  999. {
  1000. u32 int_ctrl = 0;
  1001. u32 int_mask0 = 0x7FFF3BFF;
  1002. int_ctrl = DSI_R32(ctrl, DSI_INT_CTRL);
  1003. if (errors)
  1004. int_ctrl |= BIT(25);
  1005. else
  1006. int_ctrl &= ~BIT(25);
  1007. if (errors & DSI_RDBK_SINGLE_ECC_ERR)
  1008. int_mask0 &= ~BIT(0);
  1009. if (errors & DSI_RDBK_MULTI_ECC_ERR)
  1010. int_mask0 &= ~BIT(1);
  1011. if (errors & DSI_RDBK_CRC_ERR)
  1012. int_mask0 &= ~BIT(2);
  1013. if (errors & DSI_RDBK_INCOMPLETE_PKT)
  1014. int_mask0 &= ~BIT(3);
  1015. if (errors & DSI_PERIPH_ERROR_PKT)
  1016. int_mask0 &= ~BIT(4);
  1017. if (errors & DSI_LP_RX_TIMEOUT)
  1018. int_mask0 &= ~BIT(5);
  1019. if (errors & DSI_HS_TX_TIMEOUT)
  1020. int_mask0 &= ~BIT(6);
  1021. if (errors & DSI_BTA_TIMEOUT)
  1022. int_mask0 &= ~BIT(7);
  1023. if (errors & DSI_PLL_UNLOCK)
  1024. int_mask0 &= ~BIT(28);
  1025. if (errors & DSI_DLN0_LP0_CONTENTION)
  1026. int_mask0 &= ~BIT(24);
  1027. if (errors & DSI_DLN0_LP1_CONTENTION)
  1028. int_mask0 &= ~BIT(25);
  1029. if (errors & DSI_DLN0_ESC_ENTRY_ERR)
  1030. int_mask0 &= ~BIT(21);
  1031. if (errors & DSI_DLN0_ESC_SYNC_ERR)
  1032. int_mask0 &= ~BIT(22);
  1033. if (errors & DSI_DLN0_LP_CONTROL_ERR)
  1034. int_mask0 &= ~BIT(23);
  1035. if (errors & DSI_CMD_DMA_FIFO_UNDERFLOW)
  1036. int_mask0 &= ~BIT(9);
  1037. if (errors & DSI_CMD_MDP_FIFO_UNDERFLOW)
  1038. int_mask0 &= ~BIT(11);
  1039. if (errors & DSI_DLN0_HS_FIFO_OVERFLOW)
  1040. int_mask0 &= ~BIT(16);
  1041. if (errors & DSI_DLN1_HS_FIFO_OVERFLOW)
  1042. int_mask0 &= ~BIT(17);
  1043. if (errors & DSI_DLN2_HS_FIFO_OVERFLOW)
  1044. int_mask0 &= ~BIT(18);
  1045. if (errors & DSI_DLN3_HS_FIFO_OVERFLOW)
  1046. int_mask0 &= ~BIT(19);
  1047. if (errors & DSI_DLN0_HS_FIFO_UNDERFLOW)
  1048. int_mask0 &= ~BIT(26);
  1049. if (errors & DSI_DLN1_HS_FIFO_UNDERFLOW)
  1050. int_mask0 &= ~BIT(27);
  1051. if (errors & DSI_DLN2_HS_FIFO_UNDERFLOW)
  1052. int_mask0 &= ~BIT(29);
  1053. if (errors & DSI_DLN3_HS_FIFO_UNDERFLOW)
  1054. int_mask0 &= ~BIT(30);
  1055. if (errors & DSI_INTERLEAVE_OP_CONTENTION)
  1056. int_mask0 &= ~BIT(8);
  1057. DSI_W32(ctrl, DSI_INT_CTRL, int_ctrl);
  1058. DSI_W32(ctrl, DSI_ERR_INT_MASK0, int_mask0);
  1059. pr_debug("[DSI_%d] enable errors = 0x%llx, int_mask0=0x%x\n",
  1060. ctrl->index, errors, int_mask0);
  1061. }
  1062. /**
  1063. * video_test_pattern_setup() - setup test pattern engine for video mode
  1064. * @ctrl: Pointer to the controller host hardware.
  1065. * @type: Type of test pattern.
  1066. * @init_val: Initial value to use for generating test pattern.
  1067. */
  1068. void dsi_ctrl_hw_cmn_video_test_pattern_setup(struct dsi_ctrl_hw *ctrl,
  1069. enum dsi_test_pattern type,
  1070. u32 init_val)
  1071. {
  1072. u32 reg = 0;
  1073. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_VIDEO_INIT_VAL, init_val);
  1074. switch (type) {
  1075. case DSI_TEST_PATTERN_FIXED:
  1076. reg |= (0x2 << 4);
  1077. break;
  1078. case DSI_TEST_PATTERN_INC:
  1079. reg |= (0x1 << 4);
  1080. break;
  1081. case DSI_TEST_PATTERN_POLY:
  1082. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_VIDEO_POLY, 0xF0F0F);
  1083. break;
  1084. default:
  1085. break;
  1086. }
  1087. DSI_W32(ctrl, DSI_TPG_MAIN_CONTROL, 0x100);
  1088. DSI_W32(ctrl, DSI_TPG_VIDEO_CONFIG, 0x5);
  1089. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  1090. pr_debug("[DSI_%d] Video test pattern setup done\n", ctrl->index);
  1091. }
  1092. /**
  1093. * cmd_test_pattern_setup() - setup test patttern engine for cmd mode
  1094. * @ctrl: Pointer to the controller host hardware.
  1095. * @type: Type of test pattern.
  1096. * @init_val: Initial value to use for generating test pattern.
  1097. * @stream_id: Stream Id on which packets are generated.
  1098. */
  1099. void dsi_ctrl_hw_cmn_cmd_test_pattern_setup(struct dsi_ctrl_hw *ctrl,
  1100. enum dsi_test_pattern type,
  1101. u32 init_val,
  1102. u32 stream_id)
  1103. {
  1104. u32 reg = 0;
  1105. u32 init_offset;
  1106. u32 poly_offset;
  1107. u32 pattern_sel_shift;
  1108. switch (stream_id) {
  1109. case 0:
  1110. init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL0;
  1111. poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM0_POLY;
  1112. pattern_sel_shift = 8;
  1113. break;
  1114. case 1:
  1115. init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL1;
  1116. poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM1_POLY;
  1117. pattern_sel_shift = 12;
  1118. break;
  1119. case 2:
  1120. init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL2;
  1121. poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM2_POLY;
  1122. pattern_sel_shift = 20;
  1123. break;
  1124. default:
  1125. return;
  1126. }
  1127. DSI_W32(ctrl, init_offset, init_val);
  1128. switch (type) {
  1129. case DSI_TEST_PATTERN_FIXED:
  1130. reg |= (0x2 << pattern_sel_shift);
  1131. break;
  1132. case DSI_TEST_PATTERN_INC:
  1133. reg |= (0x1 << pattern_sel_shift);
  1134. break;
  1135. case DSI_TEST_PATTERN_POLY:
  1136. DSI_W32(ctrl, poly_offset, 0xF0F0F);
  1137. break;
  1138. default:
  1139. break;
  1140. }
  1141. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  1142. pr_debug("[DSI_%d] Cmd test pattern setup done\n", ctrl->index);
  1143. }
  1144. /**
  1145. * test_pattern_enable() - enable test pattern engine
  1146. * @ctrl: Pointer to the controller host hardware.
  1147. * @enable: Enable/Disable test pattern engine.
  1148. */
  1149. void dsi_ctrl_hw_cmn_test_pattern_enable(struct dsi_ctrl_hw *ctrl,
  1150. bool enable)
  1151. {
  1152. u32 reg = DSI_R32(ctrl, DSI_TEST_PATTERN_GEN_CTRL);
  1153. if (enable)
  1154. reg |= BIT(0);
  1155. else
  1156. reg &= ~BIT(0);
  1157. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  1158. pr_debug("[DSI_%d] Test pattern enable=%d\n", ctrl->index, enable);
  1159. }
  1160. /**
  1161. * trigger_cmd_test_pattern() - trigger a command mode frame update with
  1162. * test pattern
  1163. * @ctrl: Pointer to the controller host hardware.
  1164. * @stream_id: Stream on which frame update is sent.
  1165. */
  1166. void dsi_ctrl_hw_cmn_trigger_cmd_test_pattern(struct dsi_ctrl_hw *ctrl,
  1167. u32 stream_id)
  1168. {
  1169. switch (stream_id) {
  1170. case 0:
  1171. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM0_TRIGGER, 0x1);
  1172. break;
  1173. case 1:
  1174. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM1_TRIGGER, 0x1);
  1175. break;
  1176. case 2:
  1177. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM2_TRIGGER, 0x1);
  1178. break;
  1179. default:
  1180. break;
  1181. }
  1182. pr_debug("[DSI_%d] Cmd Test pattern trigger\n", ctrl->index);
  1183. }
  1184. void dsi_ctrl_hw_dln0_phy_err(struct dsi_ctrl_hw *ctrl)
  1185. {
  1186. u32 status = 0;
  1187. /*
  1188. * Clear out any phy errors prior to exiting ULPS
  1189. * This fixes certain instances where phy does not exit
  1190. * ULPS cleanly. Also, do not print error during such cases.
  1191. */
  1192. status = DSI_R32(ctrl, DSI_DLN0_PHY_ERR);
  1193. if (status & 0x011111) {
  1194. DSI_W32(ctrl, DSI_DLN0_PHY_ERR, status);
  1195. pr_err("%s: phy_err_status = %x\n", __func__, status);
  1196. }
  1197. }
  1198. void dsi_ctrl_hw_cmn_phy_reset_config(struct dsi_ctrl_hw *ctrl,
  1199. bool enable)
  1200. {
  1201. u32 reg = 0;
  1202. reg = DSI_MMSS_MISC_R32(ctrl, MMSS_MISC_CLAMP_REG_OFF);
  1203. /* Mask/unmask disable PHY reset bit */
  1204. if (enable)
  1205. reg |= BIT(30);
  1206. else
  1207. reg &= ~BIT(30);
  1208. DSI_MMSS_MISC_W32(ctrl, MMSS_MISC_CLAMP_REG_OFF, reg);
  1209. }
  1210. int dsi_ctrl_hw_cmn_ctrl_reset(struct dsi_ctrl_hw *ctrl,
  1211. int mask)
  1212. {
  1213. int rc = 0;
  1214. u32 data;
  1215. pr_debug("DSI CTRL and PHY reset. ctrl-num = %d %d\n",
  1216. ctrl->index, mask);
  1217. data = DSI_R32(ctrl, 0x0004);
  1218. /* Disable DSI video mode */
  1219. DSI_W32(ctrl, 0x004, (data & ~BIT(1)));
  1220. wmb(); /* ensure register committed */
  1221. /* Disable DSI controller */
  1222. DSI_W32(ctrl, 0x004, (data & ~(BIT(0) | BIT(1))));
  1223. wmb(); /* ensure register committed */
  1224. /* "Force On" all dynamic clocks */
  1225. DSI_W32(ctrl, 0x11c, 0x100a00);
  1226. /* DSI_SW_RESET */
  1227. DSI_W32(ctrl, 0x118, 0x1);
  1228. wmb(); /* ensure register is committed */
  1229. DSI_W32(ctrl, 0x118, 0x0);
  1230. wmb(); /* ensure register is committed */
  1231. /* Remove "Force On" all dynamic clocks */
  1232. DSI_W32(ctrl, 0x11c, 0x00);
  1233. /* Enable DSI controller */
  1234. DSI_W32(ctrl, 0x004, (data & ~BIT(1)));
  1235. wmb(); /* ensure register committed */
  1236. return rc;
  1237. }
  1238. void dsi_ctrl_hw_cmn_mask_error_intr(struct dsi_ctrl_hw *ctrl, u32 idx, bool en)
  1239. {
  1240. u32 reg = 0;
  1241. u32 fifo_status = 0, timeout_status = 0;
  1242. u32 overflow_clear = BIT(10) | BIT(18) | BIT(22) | BIT(26) | BIT(30);
  1243. u32 underflow_clear = BIT(19) | BIT(23) | BIT(27) | BIT(31);
  1244. u32 lp_rx_clear = BIT(4);
  1245. reg = DSI_R32(ctrl, 0x10c);
  1246. /*
  1247. * Before unmasking we should clear the corresponding error status bits
  1248. * that might have been set while we masked these errors. Since these
  1249. * are sticky bits, these errors will trigger the moment we unmask
  1250. * the error bits.
  1251. */
  1252. if (idx & BIT(DSI_FIFO_OVERFLOW)) {
  1253. if (en) {
  1254. reg |= (0x1f << 16);
  1255. reg |= BIT(9);
  1256. } else {
  1257. reg &= ~(0x1f << 16);
  1258. reg &= ~BIT(9);
  1259. fifo_status = DSI_R32(ctrl, 0x00c);
  1260. DSI_W32(ctrl, 0x00c, fifo_status | overflow_clear);
  1261. }
  1262. }
  1263. if (idx & BIT(DSI_FIFO_UNDERFLOW)) {
  1264. if (en)
  1265. reg |= (0x1b << 26);
  1266. else {
  1267. reg &= ~(0x1b << 26);
  1268. fifo_status = DSI_R32(ctrl, 0x00c);
  1269. DSI_W32(ctrl, 0x00c, fifo_status | underflow_clear);
  1270. }
  1271. }
  1272. if (idx & BIT(DSI_LP_Rx_TIMEOUT)) {
  1273. if (en)
  1274. reg |= (0x7 << 23);
  1275. else {
  1276. reg &= ~(0x7 << 23);
  1277. timeout_status = DSI_R32(ctrl, 0x0c0);
  1278. DSI_W32(ctrl, 0x0c0, timeout_status | lp_rx_clear);
  1279. }
  1280. }
  1281. DSI_W32(ctrl, 0x10c, reg);
  1282. wmb(); /* ensure error is masked */
  1283. }
  1284. void dsi_ctrl_hw_cmn_error_intr_ctrl(struct dsi_ctrl_hw *ctrl, bool en)
  1285. {
  1286. u32 reg = 0;
  1287. u32 dsi_total_mask = 0x2222AA02;
  1288. reg = DSI_R32(ctrl, 0x110);
  1289. reg &= dsi_total_mask;
  1290. if (en)
  1291. reg |= (BIT(24) | BIT(25));
  1292. else
  1293. reg &= ~BIT(25);
  1294. DSI_W32(ctrl, 0x110, reg);
  1295. wmb(); /* ensure error is masked */
  1296. }
  1297. u32 dsi_ctrl_hw_cmn_get_error_mask(struct dsi_ctrl_hw *ctrl)
  1298. {
  1299. u32 reg = 0;
  1300. reg = DSI_R32(ctrl, 0x10c);
  1301. return reg;
  1302. }
  1303. u32 dsi_ctrl_hw_cmn_get_hw_version(struct dsi_ctrl_hw *ctrl)
  1304. {
  1305. u32 reg = 0;
  1306. reg = DSI_R32(ctrl, 0x0);
  1307. return reg;
  1308. }
  1309. int dsi_ctrl_hw_cmn_wait_for_cmd_mode_mdp_idle(struct dsi_ctrl_hw *ctrl)
  1310. {
  1311. int rc = 0, val = 0;
  1312. u32 cmd_mode_mdp_busy_mask = BIT(2);
  1313. u32 const sleep_us = 2 * 1000;
  1314. u32 const timeout_us = 200 * 1000;
  1315. rc = readl_poll_timeout(ctrl->base + DSI_STATUS, val,
  1316. !(val & cmd_mode_mdp_busy_mask), sleep_us, timeout_us);
  1317. if (rc)
  1318. pr_err("%s: timed out waiting for idle\n", __func__);
  1319. return rc;
  1320. }
  1321. void dsi_ctrl_hw_cmn_set_continuous_clk(struct dsi_ctrl_hw *ctrl, bool enable)
  1322. {
  1323. u32 reg = 0;
  1324. reg = DSI_R32(ctrl, DSI_LANE_CTRL);
  1325. if (enable)
  1326. reg |= BIT(28);
  1327. else
  1328. reg &= ~BIT(28);
  1329. DSI_W32(ctrl, DSI_LANE_CTRL, reg);
  1330. wmb(); /* make sure request is set */
  1331. }