dsi_ctrl_hw_cmn.c 46 KB

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