dsi_ctrl_hw_cmn.c 51 KB

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