dsi_ctrl_hw_cmn.c 44 KB

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