dsi_ctrl_hw_cmn.c 45 KB

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