dsi_ctrl_hw_cmn.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569
  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. if (idx & BIT(DSI_PLL_UNLOCK_ERR)) {
  1282. if (en)
  1283. reg |= BIT(28);
  1284. else
  1285. reg &= ~BIT(28);
  1286. }
  1287. DSI_W32(ctrl, 0x10c, reg);
  1288. wmb(); /* ensure error is masked */
  1289. }
  1290. void dsi_ctrl_hw_cmn_error_intr_ctrl(struct dsi_ctrl_hw *ctrl, bool en)
  1291. {
  1292. u32 reg = 0;
  1293. u32 dsi_total_mask = 0x2222AA02;
  1294. reg = DSI_R32(ctrl, 0x110);
  1295. reg &= dsi_total_mask;
  1296. if (en)
  1297. reg |= (BIT(24) | BIT(25));
  1298. else
  1299. reg &= ~BIT(25);
  1300. DSI_W32(ctrl, 0x110, reg);
  1301. wmb(); /* ensure error is masked */
  1302. }
  1303. u32 dsi_ctrl_hw_cmn_get_error_mask(struct dsi_ctrl_hw *ctrl)
  1304. {
  1305. u32 reg = 0;
  1306. reg = DSI_R32(ctrl, 0x10c);
  1307. return reg;
  1308. }
  1309. u32 dsi_ctrl_hw_cmn_get_hw_version(struct dsi_ctrl_hw *ctrl)
  1310. {
  1311. u32 reg = 0;
  1312. reg = DSI_R32(ctrl, 0x0);
  1313. return reg;
  1314. }
  1315. int dsi_ctrl_hw_cmn_wait_for_cmd_mode_mdp_idle(struct dsi_ctrl_hw *ctrl)
  1316. {
  1317. int rc = 0, val = 0;
  1318. u32 cmd_mode_mdp_busy_mask = BIT(2);
  1319. u32 const sleep_us = 2 * 1000;
  1320. u32 const timeout_us = 200 * 1000;
  1321. rc = readl_poll_timeout(ctrl->base + DSI_STATUS, val,
  1322. !(val & cmd_mode_mdp_busy_mask), sleep_us, timeout_us);
  1323. if (rc)
  1324. pr_err("%s: timed out waiting for idle\n", __func__);
  1325. return rc;
  1326. }
  1327. void dsi_ctrl_hw_cmn_set_continuous_clk(struct dsi_ctrl_hw *ctrl, bool enable)
  1328. {
  1329. u32 reg = 0;
  1330. reg = DSI_R32(ctrl, DSI_LANE_CTRL);
  1331. if (enable)
  1332. reg |= BIT(28);
  1333. else
  1334. reg &= ~BIT(28);
  1335. DSI_W32(ctrl, DSI_LANE_CTRL, reg);
  1336. wmb(); /* make sure request is set */
  1337. }
  1338. int dsi_ctrl_hw_cmn_wait4dynamic_refresh_done(struct dsi_ctrl_hw *ctrl)
  1339. {
  1340. int rc;
  1341. u32 const sleep_us = 1000;
  1342. u32 const timeout_us = 84000; /* approximately 5 vsyncs */
  1343. u32 reg = 0, dyn_refresh_done = BIT(28);
  1344. rc = readl_poll_timeout(ctrl->base + DSI_INT_CTRL, reg,
  1345. (reg & dyn_refresh_done), sleep_us, timeout_us);
  1346. if (rc) {
  1347. pr_err("wait4dynamic refresh timedout %d\n", rc);
  1348. return rc;
  1349. }
  1350. /* ack dynamic refresh done status */
  1351. reg = DSI_R32(ctrl, DSI_INT_CTRL);
  1352. reg |= dyn_refresh_done;
  1353. DSI_W32(ctrl, DSI_INT_CTRL, reg);
  1354. return 0;
  1355. }