dsi_ctrl_hw_cmn.c 46 KB

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