dsi_ctrl_hw_cmn.c 54 KB

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