dsi_ctrl_hw_cmn.c 52 KB

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