dsi_ctrl_hw_cmn.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856
  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. }
  756. /**
  757. * kickoff_fifo_command() - transmits a command using FIFO in dsi
  758. * hardware.
  759. * @ctrl: Pointer to the controller host hardware.
  760. * @cmd: Command information.
  761. * @flags: Modifiers for command transmission.
  762. *
  763. * The controller hardware FIFO is programmed with command header and
  764. * payload. The transmission is kicked off if
  765. * DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER flag is not set. If this flag is
  766. * set, caller should make a separate call to trigger_command_dma() to
  767. * transmit the command.
  768. */
  769. void dsi_ctrl_hw_cmn_kickoff_fifo_command(struct dsi_ctrl_hw *ctrl,
  770. struct dsi_ctrl_cmd_dma_fifo_info *cmd,
  771. u32 flags)
  772. {
  773. u32 reg = 0, i = 0;
  774. u32 *ptr = cmd->command;
  775. /*
  776. * Set CMD_DMA_TPG_EN, TPG_DMA_FIFO_MODE and
  777. * CMD_DMA_PATTERN_SEL = custom pattern stored in TPG DMA FIFO
  778. */
  779. reg = (BIT(1) | BIT(2) | (0x3 << 16));
  780. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  781. /*
  782. * Program the FIFO with command buffer. Hardware requires an extra
  783. * DWORD (set to zero) if the length of command buffer is odd DWORDS.
  784. */
  785. for (i = 0; i < cmd->size; i += 4) {
  786. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_DMA_INIT_VAL, *ptr);
  787. ptr++;
  788. }
  789. if ((cmd->size / 4) & 0x1)
  790. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_DMA_INIT_VAL, 0);
  791. /*Set BROADCAST_EN and EMBEDDED_MODE */
  792. reg = DSI_R32(ctrl, DSI_COMMAND_MODE_DMA_CTRL);
  793. if (cmd->en_broadcast)
  794. reg |= BIT(31);
  795. else
  796. reg &= ~BIT(31);
  797. if (cmd->is_master)
  798. reg |= BIT(30);
  799. else
  800. reg &= ~BIT(30);
  801. if (cmd->use_lpm)
  802. reg |= BIT(26);
  803. else
  804. reg &= ~BIT(26);
  805. reg |= BIT(28);
  806. DSI_W32(ctrl, DSI_COMMAND_MODE_DMA_CTRL, reg);
  807. DSI_W32(ctrl, DSI_DMA_CMD_LENGTH, (cmd->size & 0xFFFFFFFF));
  808. /* Finish writes before command trigger */
  809. wmb();
  810. if (!(flags & DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER))
  811. DSI_W32(ctrl, DSI_CMD_MODE_DMA_SW_TRIGGER, 0x1);
  812. DSI_CTRL_HW_DBG(ctrl, "size=%d, trigger = %d\n", cmd->size,
  813. (flags & DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER) ? false : true);
  814. }
  815. void dsi_ctrl_hw_cmn_reset_cmd_fifo(struct dsi_ctrl_hw *ctrl)
  816. {
  817. /* disable cmd dma tpg */
  818. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, 0x0);
  819. DSI_W32(ctrl, DSI_TPG_DMA_FIFO_RESET, 0x1);
  820. udelay(1);
  821. DSI_W32(ctrl, DSI_TPG_DMA_FIFO_RESET, 0x0);
  822. }
  823. /**
  824. * trigger_command_dma() - trigger transmission of command buffer.
  825. * @ctrl: Pointer to the controller host hardware.
  826. *
  827. * This trigger can be only used if there was a prior call to
  828. * kickoff_command() of kickoff_fifo_command() with
  829. * DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER flag.
  830. */
  831. void dsi_ctrl_hw_cmn_trigger_command_dma(struct dsi_ctrl_hw *ctrl)
  832. {
  833. DSI_W32(ctrl, DSI_CMD_MODE_DMA_SW_TRIGGER, 0x1);
  834. }
  835. /**
  836. * clear_rdbk_reg() - clear previously read panel data.
  837. * @ctrl: Pointer to the controller host hardware.
  838. *
  839. * This function is called before sending DSI Rx command to
  840. * panel in order to clear if any stale data remaining from
  841. * previous read operation.
  842. */
  843. void dsi_ctrl_hw_cmn_clear_rdbk_reg(struct dsi_ctrl_hw *ctrl)
  844. {
  845. DSI_W32(ctrl, DSI_RDBK_DATA_CTRL, 0x1);
  846. wmb(); /* ensure read back register is reset */
  847. DSI_W32(ctrl, DSI_RDBK_DATA_CTRL, 0x0);
  848. wmb(); /* ensure read back register is cleared */
  849. }
  850. /**
  851. * get_cmd_read_data() - get data read from the peripheral
  852. * @ctrl: Pointer to the controller host hardware.
  853. * @rd_buf: Buffer where data will be read into.
  854. * @total_read_len: Number of bytes to read.
  855. *
  856. * return: number of bytes read.
  857. */
  858. u32 dsi_ctrl_hw_cmn_get_cmd_read_data(struct dsi_ctrl_hw *ctrl,
  859. u8 *rd_buf,
  860. u32 read_offset,
  861. u32 rx_byte,
  862. u32 pkt_size,
  863. u32 *hw_read_cnt)
  864. {
  865. u32 *lp, *temp, data;
  866. int i, j = 0, cnt, off;
  867. u32 read_cnt;
  868. u32 repeated_bytes = 0;
  869. u8 reg[16] = {0};
  870. bool ack_err = false;
  871. lp = (u32 *)rd_buf;
  872. temp = (u32 *)reg;
  873. cnt = (rx_byte + 3) >> 2;
  874. if (cnt > 4)
  875. cnt = 4;
  876. read_cnt = (DSI_R32(ctrl, DSI_RDBK_DATA_CTRL) >> 16);
  877. ack_err = (rx_byte == 4) ? (read_cnt == 8) :
  878. ((read_cnt - 4) == (pkt_size + 6));
  879. if (ack_err)
  880. read_cnt -= 4;
  881. if (!read_cnt) {
  882. DSI_CTRL_HW_ERR(ctrl, "Panel detected error, no data read\n");
  883. return 0;
  884. }
  885. if (read_cnt > 16) {
  886. int bytes_shifted, data_lost = 0, rem_header = 0;
  887. bytes_shifted = read_cnt - rx_byte;
  888. if (bytes_shifted >= 4)
  889. data_lost = bytes_shifted - 4; /* remove DCS header */
  890. else
  891. rem_header = 4 - bytes_shifted; /* remaining header */
  892. repeated_bytes = (read_offset - 4) - data_lost + rem_header;
  893. }
  894. off = DSI_RDBK_DATA0;
  895. off += ((cnt - 1) * 4);
  896. for (i = 0; i < cnt; i++) {
  897. data = DSI_R32(ctrl, off);
  898. if (!repeated_bytes)
  899. *lp++ = ntohl(data);
  900. else
  901. *temp++ = ntohl(data);
  902. off -= 4;
  903. }
  904. if (repeated_bytes) {
  905. for (i = repeated_bytes; i < 16; i++)
  906. rd_buf[j++] = reg[i];
  907. }
  908. *hw_read_cnt = read_cnt;
  909. DSI_CTRL_HW_DBG(ctrl, "Read %d bytes\n", rx_byte);
  910. return rx_byte;
  911. }
  912. /**
  913. * poll_dma_status() - API to poll DMA status
  914. * @ctrl: Pointer to the controller host hardware.
  915. *
  916. * Return: DMA status.
  917. */
  918. u32 dsi_ctrl_hw_cmn_poll_dma_status(struct dsi_ctrl_hw *ctrl)
  919. {
  920. int rc = 0;
  921. u32 status;
  922. u32 const delay_us = 10;
  923. u32 const timeout_us = 5000;
  924. rc = DSI_READ_POLL_TIMEOUT_ATOMIC(ctrl, DSI_INT_CTRL, status,
  925. ((status & DSI_CMD_MODE_DMA_DONE) > 0), delay_us, timeout_us);
  926. if (rc) {
  927. DSI_CTRL_HW_DBG(ctrl, "CMD_MODE_DMA_DONE failed\n");
  928. status = 0;
  929. }
  930. return status;
  931. }
  932. /**
  933. * get_interrupt_status() - returns the interrupt status
  934. * @ctrl: Pointer to the controller host hardware.
  935. *
  936. * Returns the ORed list of interrupts(enum dsi_status_int_type) that
  937. * are active. This list does not include any error interrupts. Caller
  938. * should call get_error_status for error interrupts.
  939. *
  940. * Return: List of active interrupts.
  941. */
  942. u32 dsi_ctrl_hw_cmn_get_interrupt_status(struct dsi_ctrl_hw *ctrl)
  943. {
  944. u32 reg = 0;
  945. u32 ints = 0;
  946. reg = DSI_R32(ctrl, DSI_INT_CTRL);
  947. if (reg & BIT(0))
  948. ints |= DSI_CMD_MODE_DMA_DONE;
  949. if (reg & BIT(8))
  950. ints |= DSI_CMD_FRAME_DONE;
  951. if (reg & BIT(10))
  952. ints |= DSI_CMD_STREAM0_FRAME_DONE;
  953. if (reg & BIT(12))
  954. ints |= DSI_CMD_STREAM1_FRAME_DONE;
  955. if (reg & BIT(14))
  956. ints |= DSI_CMD_STREAM2_FRAME_DONE;
  957. if (reg & BIT(16))
  958. ints |= DSI_VIDEO_MODE_FRAME_DONE;
  959. if (reg & BIT(20))
  960. ints |= DSI_BTA_DONE;
  961. if (reg & BIT(28))
  962. ints |= DSI_DYN_REFRESH_DONE;
  963. if (reg & BIT(30))
  964. ints |= DSI_DESKEW_DONE;
  965. if (reg & BIT(24))
  966. ints |= DSI_ERROR;
  967. DSI_CTRL_HW_DBG(ctrl, "Interrupt status = 0x%x, INT_CTRL=0x%x\n",
  968. ints, reg);
  969. return ints;
  970. }
  971. /**
  972. * clear_interrupt_status() - clears the specified interrupts
  973. * @ctrl: Pointer to the controller host hardware.
  974. * @ints: List of interrupts to be cleared.
  975. */
  976. void dsi_ctrl_hw_cmn_clear_interrupt_status(struct dsi_ctrl_hw *ctrl, u32 ints)
  977. {
  978. u32 reg = 0;
  979. reg = DSI_R32(ctrl, DSI_INT_CTRL);
  980. if (ints & DSI_CMD_MODE_DMA_DONE)
  981. reg |= BIT(0);
  982. if (ints & DSI_CMD_FRAME_DONE)
  983. reg |= BIT(8);
  984. if (ints & DSI_CMD_STREAM0_FRAME_DONE)
  985. reg |= BIT(10);
  986. if (ints & DSI_CMD_STREAM1_FRAME_DONE)
  987. reg |= BIT(12);
  988. if (ints & DSI_CMD_STREAM2_FRAME_DONE)
  989. reg |= BIT(14);
  990. if (ints & DSI_VIDEO_MODE_FRAME_DONE)
  991. reg |= BIT(16);
  992. if (ints & DSI_BTA_DONE)
  993. reg |= BIT(20);
  994. if (ints & DSI_DYN_REFRESH_DONE)
  995. reg |= BIT(28);
  996. if (ints & DSI_DESKEW_DONE)
  997. reg |= BIT(30);
  998. /*
  999. * Do not clear error status.
  1000. * It will be cleared as part of
  1001. * error handler function.
  1002. */
  1003. reg &= ~BIT(24);
  1004. DSI_W32(ctrl, DSI_INT_CTRL, reg);
  1005. DSI_CTRL_HW_DBG(ctrl, "Clear interrupts, ints = 0x%x, INT_CTRL=0x%x\n",
  1006. ints, reg);
  1007. }
  1008. /**
  1009. * enable_status_interrupts() - enable the specified interrupts
  1010. * @ctrl: Pointer to the controller host hardware.
  1011. * @ints: List of interrupts to be enabled.
  1012. *
  1013. * Enables the specified interrupts. This list will override the
  1014. * previous interrupts enabled through this function. Caller has to
  1015. * maintain the state of the interrupts enabled. To disable all
  1016. * interrupts, set ints to 0.
  1017. */
  1018. void dsi_ctrl_hw_cmn_enable_status_interrupts(
  1019. struct dsi_ctrl_hw *ctrl, u32 ints)
  1020. {
  1021. u32 reg = 0;
  1022. /* Do not change value of DSI_ERROR_MASK bit */
  1023. reg |= (DSI_R32(ctrl, DSI_INT_CTRL) & BIT(25));
  1024. if (ints & DSI_CMD_MODE_DMA_DONE)
  1025. reg |= BIT(1);
  1026. if (ints & DSI_CMD_FRAME_DONE)
  1027. reg |= BIT(9);
  1028. if (ints & DSI_CMD_STREAM0_FRAME_DONE)
  1029. reg |= BIT(11);
  1030. if (ints & DSI_CMD_STREAM1_FRAME_DONE)
  1031. reg |= BIT(13);
  1032. if (ints & DSI_CMD_STREAM2_FRAME_DONE)
  1033. reg |= BIT(15);
  1034. if (ints & DSI_VIDEO_MODE_FRAME_DONE)
  1035. reg |= BIT(17);
  1036. if (ints & DSI_BTA_DONE)
  1037. reg |= BIT(21);
  1038. if (ints & DSI_DYN_REFRESH_DONE)
  1039. reg |= BIT(29);
  1040. if (ints & DSI_DESKEW_DONE)
  1041. reg |= BIT(31);
  1042. DSI_W32(ctrl, DSI_INT_CTRL, reg);
  1043. DSI_CTRL_HW_DBG(ctrl, "Enable interrupts 0x%x, INT_CTRL=0x%x\n", ints,
  1044. reg);
  1045. }
  1046. /**
  1047. * get_error_status() - returns the error status
  1048. * @ctrl: Pointer to the controller host hardware.
  1049. *
  1050. * Returns the ORed list of errors(enum dsi_error_int_type) that are
  1051. * active. This list does not include any status interrupts. Caller
  1052. * should call get_interrupt_status for status interrupts.
  1053. *
  1054. * Return: List of active error interrupts.
  1055. */
  1056. u64 dsi_ctrl_hw_cmn_get_error_status(struct dsi_ctrl_hw *ctrl)
  1057. {
  1058. u32 dln0_phy_err;
  1059. u32 fifo_status;
  1060. u32 ack_error;
  1061. u32 timeout_errors;
  1062. u32 clk_error;
  1063. u32 dsi_status;
  1064. u64 errors = 0, shift = 0x1;
  1065. dln0_phy_err = DSI_R32(ctrl, DSI_DLN0_PHY_ERR);
  1066. if (dln0_phy_err & BIT(0))
  1067. errors |= DSI_DLN0_ESC_ENTRY_ERR;
  1068. if (dln0_phy_err & BIT(4))
  1069. errors |= DSI_DLN0_ESC_SYNC_ERR;
  1070. if (dln0_phy_err & BIT(8))
  1071. errors |= DSI_DLN0_LP_CONTROL_ERR;
  1072. if (dln0_phy_err & BIT(12))
  1073. errors |= DSI_DLN0_LP0_CONTENTION;
  1074. if (dln0_phy_err & BIT(16))
  1075. errors |= DSI_DLN0_LP1_CONTENTION;
  1076. fifo_status = DSI_R32(ctrl, DSI_FIFO_STATUS);
  1077. if (fifo_status & BIT(7))
  1078. errors |= DSI_CMD_MDP_FIFO_UNDERFLOW;
  1079. if (fifo_status & BIT(10))
  1080. errors |= DSI_CMD_DMA_FIFO_UNDERFLOW;
  1081. if (fifo_status & BIT(18))
  1082. errors |= DSI_DLN0_HS_FIFO_OVERFLOW;
  1083. if (fifo_status & BIT(19))
  1084. errors |= DSI_DLN0_HS_FIFO_UNDERFLOW;
  1085. if (fifo_status & BIT(22))
  1086. errors |= DSI_DLN1_HS_FIFO_OVERFLOW;
  1087. if (fifo_status & BIT(23))
  1088. errors |= DSI_DLN1_HS_FIFO_UNDERFLOW;
  1089. if (fifo_status & BIT(26))
  1090. errors |= DSI_DLN2_HS_FIFO_OVERFLOW;
  1091. if (fifo_status & BIT(27))
  1092. errors |= DSI_DLN2_HS_FIFO_UNDERFLOW;
  1093. if (fifo_status & BIT(30))
  1094. errors |= DSI_DLN3_HS_FIFO_OVERFLOW;
  1095. if (fifo_status & BIT(31))
  1096. errors |= DSI_DLN3_HS_FIFO_UNDERFLOW;
  1097. ack_error = DSI_R32(ctrl, DSI_ACK_ERR_STATUS);
  1098. if (ack_error & BIT(16))
  1099. errors |= DSI_RDBK_SINGLE_ECC_ERR;
  1100. if (ack_error & BIT(17))
  1101. errors |= DSI_RDBK_MULTI_ECC_ERR;
  1102. if (ack_error & BIT(20))
  1103. errors |= DSI_RDBK_CRC_ERR;
  1104. if (ack_error & BIT(23))
  1105. errors |= DSI_RDBK_INCOMPLETE_PKT;
  1106. if (ack_error & BIT(24))
  1107. errors |= DSI_PERIPH_ERROR_PKT;
  1108. if (ack_error & BIT(15))
  1109. errors |= (shift << DSI_EINT_PANEL_SPECIFIC_ERR);
  1110. timeout_errors = DSI_R32(ctrl, DSI_TIMEOUT_STATUS);
  1111. if (timeout_errors & BIT(0))
  1112. errors |= DSI_HS_TX_TIMEOUT;
  1113. if (timeout_errors & BIT(4))
  1114. errors |= DSI_LP_RX_TIMEOUT;
  1115. if (timeout_errors & BIT(8))
  1116. errors |= DSI_BTA_TIMEOUT;
  1117. clk_error = DSI_R32(ctrl, DSI_CLK_STATUS);
  1118. if (clk_error & BIT(16))
  1119. errors |= DSI_PLL_UNLOCK;
  1120. dsi_status = DSI_R32(ctrl, DSI_STATUS);
  1121. if (dsi_status & BIT(31))
  1122. errors |= DSI_INTERLEAVE_OP_CONTENTION;
  1123. DSI_CTRL_HW_DBG(ctrl, "Error status = 0x%llx, phy=0x%x, fifo=0x%x\n",
  1124. errors, dln0_phy_err, fifo_status);
  1125. DSI_CTRL_HW_DBG(ctrl, "ack=0x%x, timeout=0x%x, clk=0x%x, dsi=0x%x\n",
  1126. ack_error, timeout_errors, clk_error, dsi_status);
  1127. return errors;
  1128. }
  1129. /**
  1130. * clear_error_status() - clears the specified errors
  1131. * @ctrl: Pointer to the controller host hardware.
  1132. * @errors: List of errors to be cleared.
  1133. */
  1134. void dsi_ctrl_hw_cmn_clear_error_status(struct dsi_ctrl_hw *ctrl, u64 errors)
  1135. {
  1136. u32 dln0_phy_err = 0;
  1137. u32 fifo_status = 0;
  1138. u32 ack_error = 0;
  1139. u32 timeout_error = 0;
  1140. u32 clk_error = 0;
  1141. u32 dsi_status = 0;
  1142. if (errors & DSI_RDBK_SINGLE_ECC_ERR)
  1143. ack_error |= BIT(16);
  1144. if (errors & DSI_RDBK_MULTI_ECC_ERR)
  1145. ack_error |= BIT(17);
  1146. if (errors & DSI_RDBK_CRC_ERR)
  1147. ack_error |= BIT(20);
  1148. if (errors & DSI_RDBK_INCOMPLETE_PKT)
  1149. ack_error |= BIT(23);
  1150. if (errors & DSI_PERIPH_ERROR_PKT)
  1151. ack_error |= BIT(24);
  1152. if (errors & DSI_PANEL_SPECIFIC_ERR)
  1153. ack_error |= BIT(15);
  1154. if (errors & DSI_LP_RX_TIMEOUT)
  1155. timeout_error |= BIT(4);
  1156. if (errors & DSI_HS_TX_TIMEOUT)
  1157. timeout_error |= BIT(0);
  1158. if (errors & DSI_BTA_TIMEOUT)
  1159. timeout_error |= BIT(8);
  1160. if (errors & DSI_PLL_UNLOCK)
  1161. clk_error |= BIT(16);
  1162. if (errors & DSI_DLN0_LP0_CONTENTION)
  1163. dln0_phy_err |= BIT(12);
  1164. if (errors & DSI_DLN0_LP1_CONTENTION)
  1165. dln0_phy_err |= BIT(16);
  1166. if (errors & DSI_DLN0_ESC_ENTRY_ERR)
  1167. dln0_phy_err |= BIT(0);
  1168. if (errors & DSI_DLN0_ESC_SYNC_ERR)
  1169. dln0_phy_err |= BIT(4);
  1170. if (errors & DSI_DLN0_LP_CONTROL_ERR)
  1171. dln0_phy_err |= BIT(8);
  1172. if (errors & DSI_CMD_DMA_FIFO_UNDERFLOW)
  1173. fifo_status |= BIT(10);
  1174. if (errors & DSI_CMD_MDP_FIFO_UNDERFLOW)
  1175. fifo_status |= BIT(7);
  1176. if (errors & DSI_DLN0_HS_FIFO_OVERFLOW)
  1177. fifo_status |= BIT(18);
  1178. if (errors & DSI_DLN1_HS_FIFO_OVERFLOW)
  1179. fifo_status |= BIT(22);
  1180. if (errors & DSI_DLN2_HS_FIFO_OVERFLOW)
  1181. fifo_status |= BIT(26);
  1182. if (errors & DSI_DLN3_HS_FIFO_OVERFLOW)
  1183. fifo_status |= BIT(30);
  1184. if (errors & DSI_DLN0_HS_FIFO_UNDERFLOW)
  1185. fifo_status |= BIT(19);
  1186. if (errors & DSI_DLN1_HS_FIFO_UNDERFLOW)
  1187. fifo_status |= BIT(23);
  1188. if (errors & DSI_DLN2_HS_FIFO_UNDERFLOW)
  1189. fifo_status |= BIT(27);
  1190. if (errors & DSI_DLN3_HS_FIFO_UNDERFLOW)
  1191. fifo_status |= BIT(31);
  1192. if (errors & DSI_INTERLEAVE_OP_CONTENTION)
  1193. dsi_status |= BIT(31);
  1194. DSI_W32(ctrl, DSI_DLN0_PHY_ERR, dln0_phy_err);
  1195. DSI_W32(ctrl, DSI_FIFO_STATUS, fifo_status);
  1196. /* Writing of an extra 0 is needed to clear ack error bits */
  1197. DSI_W32(ctrl, DSI_ACK_ERR_STATUS, ack_error);
  1198. wmb(); /* make sure register is committed */
  1199. DSI_W32(ctrl, DSI_ACK_ERR_STATUS, 0x0);
  1200. DSI_W32(ctrl, DSI_TIMEOUT_STATUS, timeout_error);
  1201. DSI_W32(ctrl, DSI_CLK_STATUS, clk_error);
  1202. DSI_W32(ctrl, DSI_STATUS, dsi_status);
  1203. DSI_CTRL_HW_DBG(ctrl, "clear errors = 0x%llx, phy=0x%x, fifo=0x%x\n",
  1204. errors, dln0_phy_err, fifo_status);
  1205. DSI_CTRL_HW_DBG(ctrl, "ack=0x%x, timeout=0x%x, clk=0x%x, dsi=0x%x\n",
  1206. ack_error, timeout_error, clk_error, dsi_status);
  1207. }
  1208. /**
  1209. * enable_error_interrupts() - enable the specified interrupts
  1210. * @ctrl: Pointer to the controller host hardware.
  1211. * @errors: List of errors to be enabled.
  1212. *
  1213. * Enables the specified interrupts. This list will override the
  1214. * previous interrupts enabled through this function. Caller has to
  1215. * maintain the state of the interrupts enabled. To disable all
  1216. * interrupts, set errors to 0.
  1217. */
  1218. void dsi_ctrl_hw_cmn_enable_error_interrupts(struct dsi_ctrl_hw *ctrl,
  1219. u64 errors)
  1220. {
  1221. u32 int_ctrl = 0;
  1222. u32 int_mask0 = 0x7FFF3BFF;
  1223. int_ctrl = DSI_R32(ctrl, DSI_INT_CTRL);
  1224. if (errors)
  1225. int_ctrl |= BIT(25);
  1226. else
  1227. int_ctrl &= ~BIT(25);
  1228. if (errors & DSI_RDBK_SINGLE_ECC_ERR)
  1229. int_mask0 &= ~BIT(0);
  1230. if (errors & DSI_RDBK_MULTI_ECC_ERR)
  1231. int_mask0 &= ~BIT(1);
  1232. if (errors & DSI_RDBK_CRC_ERR)
  1233. int_mask0 &= ~BIT(2);
  1234. if (errors & DSI_RDBK_INCOMPLETE_PKT)
  1235. int_mask0 &= ~BIT(3);
  1236. if (errors & DSI_PERIPH_ERROR_PKT)
  1237. int_mask0 &= ~BIT(4);
  1238. if (errors & DSI_LP_RX_TIMEOUT)
  1239. int_mask0 &= ~BIT(5);
  1240. if (errors & DSI_HS_TX_TIMEOUT)
  1241. int_mask0 &= ~BIT(6);
  1242. if (errors & DSI_BTA_TIMEOUT)
  1243. int_mask0 &= ~BIT(7);
  1244. if (errors & DSI_PLL_UNLOCK)
  1245. int_mask0 &= ~BIT(28);
  1246. if (errors & DSI_DLN0_LP0_CONTENTION)
  1247. int_mask0 &= ~BIT(24);
  1248. if (errors & DSI_DLN0_LP1_CONTENTION)
  1249. int_mask0 &= ~BIT(25);
  1250. if (errors & DSI_DLN0_ESC_ENTRY_ERR)
  1251. int_mask0 &= ~BIT(21);
  1252. if (errors & DSI_DLN0_ESC_SYNC_ERR)
  1253. int_mask0 &= ~BIT(22);
  1254. if (errors & DSI_DLN0_LP_CONTROL_ERR)
  1255. int_mask0 &= ~BIT(23);
  1256. if (errors & DSI_CMD_DMA_FIFO_UNDERFLOW)
  1257. int_mask0 &= ~BIT(9);
  1258. if (errors & DSI_CMD_MDP_FIFO_UNDERFLOW)
  1259. int_mask0 &= ~BIT(11);
  1260. if (errors & DSI_DLN0_HS_FIFO_OVERFLOW)
  1261. int_mask0 &= ~BIT(16);
  1262. if (errors & DSI_DLN1_HS_FIFO_OVERFLOW)
  1263. int_mask0 &= ~BIT(17);
  1264. if (errors & DSI_DLN2_HS_FIFO_OVERFLOW)
  1265. int_mask0 &= ~BIT(18);
  1266. if (errors & DSI_DLN3_HS_FIFO_OVERFLOW)
  1267. int_mask0 &= ~BIT(19);
  1268. if (errors & DSI_DLN0_HS_FIFO_UNDERFLOW)
  1269. int_mask0 &= ~BIT(26);
  1270. if (errors & DSI_DLN1_HS_FIFO_UNDERFLOW)
  1271. int_mask0 &= ~BIT(27);
  1272. if (errors & DSI_DLN2_HS_FIFO_UNDERFLOW)
  1273. int_mask0 &= ~BIT(29);
  1274. if (errors & DSI_DLN3_HS_FIFO_UNDERFLOW)
  1275. int_mask0 &= ~BIT(30);
  1276. if (errors & DSI_INTERLEAVE_OP_CONTENTION)
  1277. int_mask0 &= ~BIT(8);
  1278. DSI_W32(ctrl, DSI_INT_CTRL, int_ctrl);
  1279. DSI_W32(ctrl, DSI_ERR_INT_MASK0, int_mask0);
  1280. DSI_CTRL_HW_DBG(ctrl, "[DSI_%d] enable errors = 0x%llx, int_mask0=0x%x\n",
  1281. ctrl->index, errors, int_mask0);
  1282. }
  1283. /**
  1284. * video_test_pattern_setup() - setup test pattern engine for video mode
  1285. * @ctrl: Pointer to the controller host hardware.
  1286. * @type: Type of test pattern.
  1287. * @init_val: Initial value to use for generating test pattern.
  1288. */
  1289. void dsi_ctrl_hw_cmn_video_test_pattern_setup(struct dsi_ctrl_hw *ctrl,
  1290. enum dsi_test_pattern type,
  1291. u32 init_val)
  1292. {
  1293. u32 reg = 0;
  1294. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_VIDEO_INIT_VAL, init_val);
  1295. switch (type) {
  1296. case DSI_TEST_PATTERN_FIXED:
  1297. reg |= (0x2 << 4);
  1298. break;
  1299. case DSI_TEST_PATTERN_INC:
  1300. reg |= (0x1 << 4);
  1301. break;
  1302. case DSI_TEST_PATTERN_POLY:
  1303. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_VIDEO_POLY, 0xF0F0F);
  1304. break;
  1305. default:
  1306. break;
  1307. }
  1308. DSI_W32(ctrl, DSI_TPG_MAIN_CONTROL, 0x100);
  1309. DSI_W32(ctrl, DSI_TPG_VIDEO_CONFIG, 0x5);
  1310. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  1311. DSI_CTRL_HW_DBG(ctrl, "Video test pattern setup done\n");
  1312. }
  1313. /**
  1314. * cmd_test_pattern_setup() - setup test patttern engine for cmd mode
  1315. * @ctrl: Pointer to the controller host hardware.
  1316. * @type: Type of test pattern.
  1317. * @init_val: Initial value to use for generating test pattern.
  1318. * @stream_id: Stream Id on which packets are generated.
  1319. */
  1320. void dsi_ctrl_hw_cmn_cmd_test_pattern_setup(struct dsi_ctrl_hw *ctrl,
  1321. enum dsi_test_pattern type,
  1322. u32 init_val,
  1323. u32 stream_id)
  1324. {
  1325. u32 reg = 0;
  1326. u32 init_offset;
  1327. u32 poly_offset;
  1328. u32 pattern_sel_shift;
  1329. switch (stream_id) {
  1330. case 0:
  1331. init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL0;
  1332. poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM0_POLY;
  1333. pattern_sel_shift = 8;
  1334. break;
  1335. case 1:
  1336. init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL1;
  1337. poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM1_POLY;
  1338. pattern_sel_shift = 12;
  1339. break;
  1340. case 2:
  1341. init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL2;
  1342. poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM2_POLY;
  1343. pattern_sel_shift = 20;
  1344. break;
  1345. default:
  1346. return;
  1347. }
  1348. DSI_W32(ctrl, init_offset, init_val);
  1349. switch (type) {
  1350. case DSI_TEST_PATTERN_FIXED:
  1351. reg |= (0x2 << pattern_sel_shift);
  1352. break;
  1353. case DSI_TEST_PATTERN_INC:
  1354. reg |= (0x1 << pattern_sel_shift);
  1355. break;
  1356. case DSI_TEST_PATTERN_POLY:
  1357. DSI_W32(ctrl, poly_offset, 0xF0F0F);
  1358. break;
  1359. default:
  1360. break;
  1361. }
  1362. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  1363. DSI_CTRL_HW_DBG(ctrl, "Cmd test pattern setup done\n");
  1364. }
  1365. /**
  1366. * test_pattern_enable() - enable test pattern engine
  1367. * @ctrl: Pointer to the controller host hardware.
  1368. * @enable: Enable/Disable test pattern engine.
  1369. */
  1370. void dsi_ctrl_hw_cmn_test_pattern_enable(struct dsi_ctrl_hw *ctrl,
  1371. bool enable)
  1372. {
  1373. u32 reg = DSI_R32(ctrl, DSI_TEST_PATTERN_GEN_CTRL);
  1374. if (enable)
  1375. reg |= BIT(0);
  1376. else
  1377. reg &= ~BIT(0);
  1378. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  1379. DSI_CTRL_HW_DBG(ctrl, "Test pattern enable=%d\n", enable);
  1380. }
  1381. /**
  1382. * trigger_cmd_test_pattern() - trigger a command mode frame update with
  1383. * test pattern
  1384. * @ctrl: Pointer to the controller host hardware.
  1385. * @stream_id: Stream on which frame update is sent.
  1386. */
  1387. void dsi_ctrl_hw_cmn_trigger_cmd_test_pattern(struct dsi_ctrl_hw *ctrl,
  1388. u32 stream_id)
  1389. {
  1390. switch (stream_id) {
  1391. case 0:
  1392. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM0_TRIGGER, 0x1);
  1393. break;
  1394. case 1:
  1395. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM1_TRIGGER, 0x1);
  1396. break;
  1397. case 2:
  1398. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM2_TRIGGER, 0x1);
  1399. break;
  1400. default:
  1401. break;
  1402. }
  1403. DSI_CTRL_HW_DBG(ctrl, "Cmd Test pattern trigger\n");
  1404. }
  1405. void dsi_ctrl_hw_dln0_phy_err(struct dsi_ctrl_hw *ctrl)
  1406. {
  1407. u32 status = 0;
  1408. /*
  1409. * Clear out any phy errors prior to exiting ULPS
  1410. * This fixes certain instances where phy does not exit
  1411. * ULPS cleanly. Also, do not print error during such cases.
  1412. */
  1413. status = DSI_R32(ctrl, DSI_DLN0_PHY_ERR);
  1414. if (status & 0x011111) {
  1415. DSI_W32(ctrl, DSI_DLN0_PHY_ERR, status);
  1416. DSI_CTRL_HW_ERR(ctrl, "phy_err_status = %x\n", status);
  1417. }
  1418. }
  1419. void dsi_ctrl_hw_cmn_phy_reset_config(struct dsi_ctrl_hw *ctrl,
  1420. bool enable)
  1421. {
  1422. u32 reg = 0;
  1423. reg = DSI_MMSS_MISC_R32(ctrl, MMSS_MISC_CLAMP_REG_OFF);
  1424. /* Mask/unmask disable PHY reset bit */
  1425. if (enable)
  1426. reg |= BIT(30);
  1427. else
  1428. reg &= ~BIT(30);
  1429. DSI_MMSS_MISC_W32(ctrl, MMSS_MISC_CLAMP_REG_OFF, reg);
  1430. }
  1431. int dsi_ctrl_hw_cmn_ctrl_reset(struct dsi_ctrl_hw *ctrl,
  1432. int mask)
  1433. {
  1434. int rc = 0;
  1435. u32 data;
  1436. DSI_CTRL_HW_DBG(ctrl, "DSI CTRL and PHY reset, mask=%d\n", mask);
  1437. data = DSI_R32(ctrl, 0x0004);
  1438. /* Disable DSI video mode */
  1439. DSI_W32(ctrl, 0x004, (data & ~BIT(1)));
  1440. wmb(); /* ensure register committed */
  1441. /* Disable DSI controller */
  1442. DSI_W32(ctrl, 0x004, (data & ~(BIT(0) | BIT(1))));
  1443. wmb(); /* ensure register committed */
  1444. /* "Force On" all dynamic clocks */
  1445. DSI_W32(ctrl, 0x11c, 0x100a00);
  1446. /* DSI_SW_RESET */
  1447. DSI_W32(ctrl, 0x118, 0x1);
  1448. wmb(); /* ensure register is committed */
  1449. DSI_W32(ctrl, 0x118, 0x0);
  1450. wmb(); /* ensure register is committed */
  1451. /* Remove "Force On" all dynamic clocks */
  1452. DSI_W32(ctrl, 0x11c, 0x00);
  1453. /* Enable DSI controller */
  1454. DSI_W32(ctrl, 0x004, (data & ~BIT(1)));
  1455. wmb(); /* ensure register committed */
  1456. return rc;
  1457. }
  1458. void dsi_ctrl_hw_cmn_mask_error_intr(struct dsi_ctrl_hw *ctrl, u32 idx, bool en)
  1459. {
  1460. u32 reg = 0;
  1461. u32 fifo_status = 0, timeout_status = 0;
  1462. u32 overflow_clear = BIT(10) | BIT(18) | BIT(22) | BIT(26) | BIT(30);
  1463. u32 underflow_clear = BIT(19) | BIT(23) | BIT(27) | BIT(31);
  1464. u32 lp_rx_clear = BIT(4);
  1465. reg = DSI_R32(ctrl, 0x10c);
  1466. /*
  1467. * Before unmasking we should clear the corresponding error status bits
  1468. * that might have been set while we masked these errors. Since these
  1469. * are sticky bits, these errors will trigger the moment we unmask
  1470. * the error bits.
  1471. */
  1472. if (idx & BIT(DSI_FIFO_OVERFLOW)) {
  1473. if (en) {
  1474. reg |= (0x1f << 16);
  1475. reg |= BIT(9);
  1476. } else {
  1477. reg &= ~(0x1f << 16);
  1478. reg &= ~BIT(9);
  1479. fifo_status = DSI_R32(ctrl, 0x00c);
  1480. DSI_W32(ctrl, 0x00c, fifo_status | overflow_clear);
  1481. }
  1482. }
  1483. if (idx & BIT(DSI_FIFO_UNDERFLOW)) {
  1484. if (en)
  1485. reg |= (0x1b << 26);
  1486. else {
  1487. reg &= ~(0x1b << 26);
  1488. fifo_status = DSI_R32(ctrl, 0x00c);
  1489. DSI_W32(ctrl, 0x00c, fifo_status | underflow_clear);
  1490. }
  1491. }
  1492. if (idx & BIT(DSI_LP_Rx_TIMEOUT)) {
  1493. if (en)
  1494. reg |= (0x7 << 23);
  1495. else {
  1496. reg &= ~(0x7 << 23);
  1497. timeout_status = DSI_R32(ctrl, 0x0c0);
  1498. DSI_W32(ctrl, 0x0c0, timeout_status | lp_rx_clear);
  1499. }
  1500. }
  1501. if (idx & BIT(DSI_PLL_UNLOCK_ERR)) {
  1502. if (en)
  1503. reg |= BIT(28);
  1504. else
  1505. reg &= ~BIT(28);
  1506. }
  1507. DSI_W32(ctrl, 0x10c, reg);
  1508. wmb(); /* ensure error is masked */
  1509. }
  1510. void dsi_ctrl_hw_cmn_error_intr_ctrl(struct dsi_ctrl_hw *ctrl, bool en)
  1511. {
  1512. u32 reg = 0;
  1513. u32 dsi_total_mask = 0x2222AA02;
  1514. reg = DSI_R32(ctrl, 0x110);
  1515. reg &= dsi_total_mask;
  1516. if (en)
  1517. reg |= (BIT(24) | BIT(25));
  1518. else
  1519. reg &= ~BIT(25);
  1520. DSI_W32(ctrl, 0x110, reg);
  1521. wmb(); /* ensure error is masked */
  1522. }
  1523. u32 dsi_ctrl_hw_cmn_get_error_mask(struct dsi_ctrl_hw *ctrl)
  1524. {
  1525. u32 reg = 0;
  1526. reg = DSI_R32(ctrl, 0x10c);
  1527. return reg;
  1528. }
  1529. u32 dsi_ctrl_hw_cmn_get_hw_version(struct dsi_ctrl_hw *ctrl)
  1530. {
  1531. u32 reg = 0;
  1532. reg = DSI_R32(ctrl, 0x0);
  1533. return reg;
  1534. }
  1535. int dsi_ctrl_hw_cmn_wait_for_cmd_mode_mdp_idle(struct dsi_ctrl_hw *ctrl)
  1536. {
  1537. int rc = 0, val = 0;
  1538. u32 cmd_mode_mdp_busy_mask = BIT(2);
  1539. u32 const sleep_us = 2 * 1000;
  1540. u32 const timeout_us = 200 * 1000;
  1541. rc = DSI_READ_POLL_TIMEOUT(ctrl, DSI_STATUS, val,
  1542. !(val & cmd_mode_mdp_busy_mask), sleep_us, timeout_us);
  1543. if (rc)
  1544. DSI_CTRL_HW_ERR(ctrl, "timed out waiting for idle\n");
  1545. return rc;
  1546. }
  1547. void dsi_ctrl_hw_cmn_hs_req_sel(struct dsi_ctrl_hw *ctrl, bool sel_phy)
  1548. {
  1549. u32 reg = 0;
  1550. reg = DSI_R32(ctrl, DSI_LANE_CTRL);
  1551. if (sel_phy)
  1552. reg &= ~BIT(24);
  1553. else
  1554. reg |= BIT(24);
  1555. DSI_W32(ctrl, DSI_LANE_CTRL, reg);
  1556. wmb(); /* make sure request is set */
  1557. }
  1558. void dsi_ctrl_hw_cmn_set_continuous_clk(struct dsi_ctrl_hw *ctrl, bool enable)
  1559. {
  1560. u32 reg = 0;
  1561. reg = DSI_R32(ctrl, DSI_LANE_CTRL);
  1562. if (enable)
  1563. reg |= BIT(28);
  1564. else
  1565. reg &= ~BIT(28);
  1566. DSI_W32(ctrl, DSI_LANE_CTRL, reg);
  1567. wmb(); /* make sure request is set */
  1568. }
  1569. int dsi_ctrl_hw_cmn_wait4dynamic_refresh_done(struct dsi_ctrl_hw *ctrl)
  1570. {
  1571. int rc;
  1572. u32 const sleep_us = 1000;
  1573. u32 const timeout_us = 84000; /* approximately 5 vsyncs */
  1574. u32 reg = 0, dyn_refresh_done = BIT(28);
  1575. rc = DSI_READ_POLL_TIMEOUT(ctrl, DSI_INT_CTRL, reg,
  1576. (reg & dyn_refresh_done), sleep_us, timeout_us);
  1577. if (rc) {
  1578. DSI_CTRL_HW_ERR(ctrl, "wait4dynamic refresh timedout %d\n", rc);
  1579. return rc;
  1580. }
  1581. /* ack dynamic refresh done status */
  1582. reg = DSI_R32(ctrl, DSI_INT_CTRL);
  1583. reg |= dyn_refresh_done;
  1584. DSI_W32(ctrl, DSI_INT_CTRL, reg);
  1585. return 0;
  1586. }
  1587. bool dsi_ctrl_hw_cmn_vid_engine_busy(struct dsi_ctrl_hw *ctrl)
  1588. {
  1589. u32 reg = 0, video_engine_busy = BIT(3);
  1590. int rc;
  1591. u32 const sleep_us = 1000;
  1592. u32 const timeout_us = 50000;
  1593. rc = DSI_READ_POLL_TIMEOUT(ctrl, DSI_STATUS, reg,
  1594. !(reg & video_engine_busy), sleep_us, timeout_us);
  1595. if (rc)
  1596. return true;
  1597. return false;
  1598. }