dsi_ctrl_hw_cmn.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877
  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, 0x9 };
  38. static const u8 video_mode_format_map[DSI_PIXEL_FORMAT_MAX] = {
  39. 0x0, 0x1, 0x2, 0x3, 0x3, 0x3, 0x3, 0x4 };
  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. u32 bpp;
  476. if (roi && (!roi->w || !roi->h))
  477. return;
  478. bpp = dsi_pixel_format_to_bpp(cfg->dst_format);
  479. if (dsi_dsc_compression_enabled(mode)) {
  480. struct msm_display_dsc_info dsc;
  481. pic_width = roi ? roi->w : mode->h_active;
  482. memcpy(&dsc, mode->dsc, sizeof(dsc));
  483. this_frame_slices = pic_width / dsc.config.slice_width;
  484. intf_ip_w = this_frame_slices * dsc.config.slice_width;
  485. sde_dsc_populate_dsc_private_params(&dsc, intf_ip_w);
  486. width_final = dsc.bytes_per_pkt * dsc.pkt_per_line;
  487. stride_final = dsc.bytes_per_pkt;
  488. pkt_per_line = dsc.pkt_per_line;
  489. eol_byte_num = dsc.eol_byte_num;
  490. bytes_in_slice = dsc.bytes_in_slice;
  491. } else if (dsi_vdc_compression_enabled(mode)) {
  492. struct msm_display_vdc_info vdc;
  493. pic_width = roi ? roi->w : mode->h_active;
  494. memcpy(&vdc, mode->vdc, sizeof(vdc));
  495. this_frame_slices = pic_width / vdc.slice_width;
  496. intf_ip_w = this_frame_slices * vdc.slice_width;
  497. sde_vdc_intf_prog_params(&vdc, intf_ip_w);
  498. width_final = vdc.bytes_per_pkt * vdc.pkt_per_line;
  499. stride_final = vdc.bytes_per_pkt;
  500. pkt_per_line = vdc.pkt_per_line;
  501. eol_byte_num = vdc.eol_byte_num;
  502. bytes_in_slice = vdc.bytes_in_slice;
  503. } else if (roi) {
  504. width_final = roi->w;
  505. stride_final = DIV_ROUND_UP(roi->w * bpp, 8);
  506. height_final = roi->h;
  507. } else {
  508. width_final = mode->h_active;
  509. stride_final = DIV_ROUND_UP(mode->h_active * bpp, 8);
  510. height_final = mode->v_active;
  511. }
  512. if (dsi_compression_enabled(mode)) {
  513. pic_width = roi ? roi->w : mode->h_active;
  514. height_final = roi ? roi->h : mode->v_active;
  515. if (ctrl->widebus_support) {
  516. width_final = DIV_ROUND_UP(width_final, 6);
  517. reg = DSI_R32(ctrl, DSI_COMMAND_MODE_MDP_CTRL2);
  518. reg |= BIT(20);
  519. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_CTRL2, reg);
  520. } else {
  521. width_final = DIV_ROUND_UP(width_final, 3);
  522. }
  523. reg_ctrl = DSI_R32(ctrl, DSI_COMMAND_COMPRESSION_MODE_CTRL);
  524. reg_ctrl2 = DSI_R32(ctrl, DSI_COMMAND_COMPRESSION_MODE_CTRL2);
  525. if (vc_id != 0)
  526. offset = 16;
  527. reg = 0x39 << 8;
  528. /*
  529. * pkt_per_line:
  530. * 0 == 1 pkt
  531. * 1 == 2 pkt
  532. * 2 == 4 pkt
  533. * 3 pkt is not supported
  534. */
  535. reg |= (pkt_per_line >> 1) << 6;
  536. reg |= eol_byte_num << 4;
  537. reg |= 1;
  538. reg_ctrl &= ~(0xFFFF << offset);
  539. reg_ctrl |= (reg << offset);
  540. reg_ctrl2 &= ~(0xFFFF << offset);
  541. reg_ctrl2 |= (bytes_in_slice << offset);
  542. DSI_CTRL_HW_DBG(ctrl, "reg_ctrl 0x%x reg_ctrl2 0x%x\n",
  543. reg_ctrl, reg_ctrl2);
  544. }
  545. /* HS Timer value */
  546. DSI_W32(ctrl, DSI_HS_TIMER_CTRL, 0x3FD08);
  547. stream_ctrl = (stride_final + 1) << 16;
  548. stream_ctrl |= (vc_id & 0x3) << 8;
  549. stream_ctrl |= 0x39; /* packet data type */
  550. DSI_W32(ctrl, DSI_COMMAND_COMPRESSION_MODE_CTRL, reg_ctrl);
  551. DSI_W32(ctrl, DSI_COMMAND_COMPRESSION_MODE_CTRL2, reg_ctrl2);
  552. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_STREAM0_CTRL, stream_ctrl);
  553. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_STREAM1_CTRL, stream_ctrl);
  554. stream_total = (height_final << 16) | width_final;
  555. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_STREAM0_TOTAL, stream_total);
  556. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_STREAM1_TOTAL, stream_total);
  557. if (ctrl->null_insertion_enabled) {
  558. /* enable null packet insertion */
  559. data = (vc_id << 1);
  560. data |= 0 << 16;
  561. data |= 0x1;
  562. DSI_W32(ctrl, DSI_COMMAND_MODE_NULL_INSERTION_CTRL, data);
  563. }
  564. DSI_CTRL_HW_DBG(ctrl, "stream_ctrl 0x%x stream_total 0x%x\n",
  565. stream_ctrl, stream_total);
  566. }
  567. /**
  568. * setup_avr() - set the AVR_SUPPORT_ENABLE bit in DSI_VIDEO_MODE_CTRL
  569. * @ctrl: Pointer to controller host hardware.
  570. * @enable: Controls whether this bit is set or cleared
  571. *
  572. * Set or clear the AVR_SUPPORT_ENABLE bit in DSI_VIDEO_MODE_CTRL.
  573. */
  574. void dsi_ctrl_hw_cmn_setup_avr(struct dsi_ctrl_hw *ctrl, bool enable)
  575. {
  576. u32 reg = DSI_R32(ctrl, DSI_VIDEO_MODE_CTRL);
  577. if (enable)
  578. reg |= BIT(29);
  579. else
  580. reg &= ~BIT(29);
  581. DSI_W32(ctrl, DSI_VIDEO_MODE_CTRL, reg);
  582. DSI_CTRL_HW_DBG(ctrl, "AVR %s\n", enable ? "enabled" : "disabled");
  583. }
  584. /**
  585. * video_engine_setup() - Setup dsi host controller for video mode
  586. * @ctrl: Pointer to controller host hardware.
  587. * @common_cfg: Common configuration parameters.
  588. * @cfg: Video mode configuration.
  589. *
  590. * Set up DSI video engine with a specific configuration. Controller and
  591. * video engine are not enabled as part of this function.
  592. */
  593. void dsi_ctrl_hw_cmn_video_engine_setup(struct dsi_ctrl_hw *ctrl,
  594. struct dsi_host_common_cfg *common_cfg,
  595. struct dsi_video_engine_cfg *cfg)
  596. {
  597. u32 reg = 0;
  598. reg |= (cfg->last_line_interleave_en ? BIT(31) : 0);
  599. reg |= (cfg->pulse_mode_hsa_he ? BIT(28) : 0);
  600. reg |= (cfg->hfp_lp11_en ? BIT(24) : 0);
  601. reg |= (cfg->hbp_lp11_en ? BIT(20) : 0);
  602. reg |= (cfg->hsa_lp11_en ? BIT(16) : 0);
  603. reg |= (cfg->eof_bllp_lp11_en ? BIT(15) : 0);
  604. reg |= (cfg->bllp_lp11_en ? BIT(12) : 0);
  605. reg |= (cfg->traffic_mode & 0x3) << 8;
  606. reg |= (cfg->vc_id & 0x3);
  607. reg |= (video_mode_format_map[common_cfg->dst_format] & 0x7) << 4;
  608. DSI_W32(ctrl, DSI_VIDEO_MODE_CTRL, reg);
  609. reg = (common_cfg->swap_mode & 0x7) << 12;
  610. reg |= (common_cfg->bit_swap_red ? BIT(0) : 0);
  611. reg |= (common_cfg->bit_swap_green ? BIT(4) : 0);
  612. reg |= (common_cfg->bit_swap_blue ? BIT(8) : 0);
  613. DSI_W32(ctrl, DSI_VIDEO_MODE_DATA_CTRL, reg);
  614. /* Disable Timing double buffering */
  615. DSI_W32(ctrl, DSI_DSI_TIMING_DB_MODE, 0x0);
  616. DSI_CTRL_HW_DBG(ctrl, "Video engine setup done\n");
  617. }
  618. /**
  619. * cmd_engine_setup() - setup dsi host controller for command mode
  620. * @ctrl: Pointer to the controller host hardware.
  621. * @common_cfg: Common configuration parameters.
  622. * @cfg: Command mode configuration.
  623. *
  624. * Setup DSI CMD engine with a specific configuration. Controller and
  625. * command engine are not enabled as part of this function.
  626. */
  627. void dsi_ctrl_hw_cmn_cmd_engine_setup(struct dsi_ctrl_hw *ctrl,
  628. struct dsi_host_common_cfg *common_cfg,
  629. struct dsi_cmd_engine_cfg *cfg)
  630. {
  631. u32 reg = 0;
  632. reg = (cfg->max_cmd_packets_interleave & 0xF) << 20;
  633. reg |= (common_cfg->bit_swap_red ? BIT(4) : 0);
  634. reg |= (common_cfg->bit_swap_green ? BIT(8) : 0);
  635. reg |= (common_cfg->bit_swap_blue ? BIT(12) : 0);
  636. reg |= cmd_mode_format_map[common_cfg->dst_format];
  637. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_CTRL, reg);
  638. if (!cfg->mdp_idle_ctrl_en) {
  639. reg = DSI_R32(ctrl, DSI_COMMAND_MODE_MDP_CTRL2);
  640. reg |= BIT(16);
  641. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_CTRL2, reg);
  642. }
  643. reg = cfg->wr_mem_start & 0xFF;
  644. reg |= (cfg->wr_mem_continue & 0xFF) << 8;
  645. reg |= (cfg->insert_dcs_command ? BIT(16) : 0);
  646. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_DCS_CMD_CTRL, reg);
  647. if (cfg->mdp_idle_ctrl_en) {
  648. reg = cfg->mdp_idle_ctrl_len & 0x3FF;
  649. reg |= BIT(12);
  650. DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_IDLE_CTRL, reg);
  651. }
  652. DSI_CTRL_HW_DBG(ctrl, "Cmd engine setup done\n");
  653. }
  654. /**
  655. * video_engine_en() - enable DSI video engine
  656. * @ctrl: Pointer to controller host hardware.
  657. * @on: Enable/disabel video engine.
  658. */
  659. void dsi_ctrl_hw_cmn_video_engine_en(struct dsi_ctrl_hw *ctrl, bool on)
  660. {
  661. u32 reg = 0;
  662. /* Set/Clear VIDEO_MODE_EN bit */
  663. reg = DSI_R32(ctrl, DSI_CTRL);
  664. if (on)
  665. reg |= BIT(1);
  666. else
  667. reg &= ~BIT(1);
  668. DSI_W32(ctrl, DSI_CTRL, reg);
  669. DSI_CTRL_HW_DBG(ctrl, "Video engine = %d\n", on);
  670. }
  671. /**
  672. * ctrl_en() - enable DSI controller engine
  673. * @ctrl: Pointer to the controller host hardware.
  674. * @on: turn on/off the DSI controller engine.
  675. */
  676. void dsi_ctrl_hw_cmn_ctrl_en(struct dsi_ctrl_hw *ctrl, bool on)
  677. {
  678. u32 reg = 0;
  679. u32 clk_ctrl;
  680. clk_ctrl = DSI_R32(ctrl, DSI_CLK_CTRL);
  681. DSI_W32(ctrl, DSI_CLK_CTRL, clk_ctrl | DSI_CTRL_DYNAMIC_FORCE_ON);
  682. wmb(); /* wait for clocks to enable */
  683. /* Set/Clear DSI_EN bit */
  684. reg = DSI_R32(ctrl, DSI_CTRL);
  685. if (on)
  686. reg |= BIT(0);
  687. else
  688. reg &= ~BIT(0);
  689. DSI_W32(ctrl, DSI_CTRL, reg);
  690. wmb(); /* wait for DSI_EN update before disabling clocks */
  691. DSI_W32(ctrl, DSI_CLK_CTRL, clk_ctrl);
  692. wmb(); /* make sure clocks are restored */
  693. DSI_CTRL_HW_DBG(ctrl, "Controller engine = %d\n", on);
  694. }
  695. /**
  696. * cmd_engine_en() - enable DSI controller command engine
  697. * @ctrl: Pointer to the controller host hardware.
  698. * @on: Turn on/off the DSI command engine.
  699. */
  700. void dsi_ctrl_hw_cmn_cmd_engine_en(struct dsi_ctrl_hw *ctrl, bool on)
  701. {
  702. u32 reg = 0;
  703. /* Set/Clear CMD_MODE_EN bit */
  704. reg = DSI_R32(ctrl, DSI_CTRL);
  705. if (on)
  706. reg |= BIT(2);
  707. else
  708. reg &= ~BIT(2);
  709. DSI_W32(ctrl, DSI_CTRL, reg);
  710. DSI_CTRL_HW_DBG(ctrl, "command engine = %d\n", on);
  711. }
  712. /**
  713. * kickoff_command() - transmits commands stored in memory
  714. * @ctrl: Pointer to the controller host hardware.
  715. * @cmd: Command information.
  716. * @flags: Modifiers for command transmission.
  717. *
  718. * The controller hardware is programmed with address and size of the
  719. * command buffer. The transmission is kicked off if
  720. * DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER flag is not set. If this flag is
  721. * set, caller should make a separate call to trigger_command_dma() to
  722. * transmit the command.
  723. */
  724. void dsi_ctrl_hw_cmn_kickoff_command(struct dsi_ctrl_hw *ctrl,
  725. struct dsi_ctrl_cmd_dma_info *cmd,
  726. u32 flags)
  727. {
  728. u32 reg = 0;
  729. /*Set BROADCAST_EN and EMBEDDED_MODE */
  730. reg = DSI_R32(ctrl, DSI_COMMAND_MODE_DMA_CTRL);
  731. if (cmd->en_broadcast)
  732. reg |= BIT(31);
  733. else
  734. reg &= ~BIT(31);
  735. if (cmd->is_master)
  736. reg |= BIT(30);
  737. else
  738. reg &= ~BIT(30);
  739. if (cmd->use_lpm)
  740. reg |= BIT(26);
  741. else
  742. reg &= ~BIT(26);
  743. reg |= BIT(28);/* Select embedded mode */
  744. reg &= ~BIT(24);/* packet type */
  745. reg &= ~BIT(29);/* WC_SEL to 0 */
  746. DSI_W32(ctrl, DSI_COMMAND_MODE_DMA_CTRL, reg);
  747. reg = DSI_R32(ctrl, DSI_DMA_FIFO_CTRL);
  748. reg |= BIT(20);/* Disable write watermark*/
  749. reg |= BIT(16);/* Disable read watermark */
  750. DSI_W32(ctrl, DSI_DMA_FIFO_CTRL, reg);
  751. DSI_W32(ctrl, DSI_DMA_CMD_OFFSET, cmd->offset);
  752. DSI_W32(ctrl, DSI_DMA_CMD_LENGTH, (cmd->length & 0xFFFFFF));
  753. /* wait for writes to complete before kick off */
  754. wmb();
  755. if (!(flags & DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER))
  756. DSI_W32(ctrl, DSI_CMD_MODE_DMA_SW_TRIGGER, 0x1);
  757. SDE_EVT32(ctrl->index, cmd->length, flags);
  758. }
  759. /**
  760. * kickoff_fifo_command() - transmits a command using FIFO in dsi
  761. * hardware.
  762. * @ctrl: Pointer to the controller host hardware.
  763. * @cmd: Command information.
  764. * @flags: Modifiers for command transmission.
  765. *
  766. * The controller hardware FIFO is programmed with command header and
  767. * payload. The transmission is kicked off if
  768. * DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER flag is not set. If this flag is
  769. * set, caller should make a separate call to trigger_command_dma() to
  770. * transmit the command.
  771. */
  772. void dsi_ctrl_hw_cmn_kickoff_fifo_command(struct dsi_ctrl_hw *ctrl,
  773. struct dsi_ctrl_cmd_dma_fifo_info *cmd,
  774. u32 flags)
  775. {
  776. u32 reg = 0, i = 0;
  777. u32 *ptr = cmd->command;
  778. /*
  779. * Set CMD_DMA_TPG_EN, TPG_DMA_FIFO_MODE and
  780. * CMD_DMA_PATTERN_SEL = custom pattern stored in TPG DMA FIFO
  781. */
  782. reg = (BIT(1) | BIT(2) | (0x3 << 16));
  783. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  784. /*
  785. * Program the FIFO with command buffer. Hardware requires an extra
  786. * DWORD (set to zero) if the length of command buffer is odd DWORDS.
  787. */
  788. for (i = 0; i < cmd->size; i += 4) {
  789. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_DMA_INIT_VAL, *ptr);
  790. ptr++;
  791. }
  792. if ((cmd->size / 4) & 0x1)
  793. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_DMA_INIT_VAL, 0);
  794. /*Set BROADCAST_EN and EMBEDDED_MODE */
  795. reg = DSI_R32(ctrl, DSI_COMMAND_MODE_DMA_CTRL);
  796. if (cmd->en_broadcast)
  797. reg |= BIT(31);
  798. else
  799. reg &= ~BIT(31);
  800. if (cmd->is_master)
  801. reg |= BIT(30);
  802. else
  803. reg &= ~BIT(30);
  804. if (cmd->use_lpm)
  805. reg |= BIT(26);
  806. else
  807. reg &= ~BIT(26);
  808. reg |= BIT(28);
  809. DSI_W32(ctrl, DSI_COMMAND_MODE_DMA_CTRL, reg);
  810. DSI_W32(ctrl, DSI_DMA_CMD_LENGTH, (cmd->size & 0xFFFFFFFF));
  811. /* Finish writes before command trigger */
  812. wmb();
  813. if (!(flags & DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER))
  814. DSI_W32(ctrl, DSI_CMD_MODE_DMA_SW_TRIGGER, 0x1);
  815. DSI_CTRL_HW_DBG(ctrl, "size=%d, trigger = %d\n", cmd->size,
  816. (flags & DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER) ? false : true);
  817. }
  818. void dsi_ctrl_hw_cmn_reset_cmd_fifo(struct dsi_ctrl_hw *ctrl)
  819. {
  820. /* disable cmd dma tpg */
  821. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, 0x0);
  822. DSI_W32(ctrl, DSI_TPG_DMA_FIFO_RESET, 0x1);
  823. udelay(1);
  824. DSI_W32(ctrl, DSI_TPG_DMA_FIFO_RESET, 0x0);
  825. }
  826. /**
  827. * trigger_command_dma() - trigger transmission of command buffer.
  828. * @ctrl: Pointer to the controller host hardware.
  829. *
  830. * This trigger can be only used if there was a prior call to
  831. * kickoff_command() of kickoff_fifo_command() with
  832. * DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER flag.
  833. */
  834. void dsi_ctrl_hw_cmn_trigger_command_dma(struct dsi_ctrl_hw *ctrl)
  835. {
  836. DSI_W32(ctrl, DSI_CMD_MODE_DMA_SW_TRIGGER, 0x1);
  837. }
  838. /**
  839. * clear_rdbk_reg() - clear previously read panel data.
  840. * @ctrl: Pointer to the controller host hardware.
  841. *
  842. * This function is called before sending DSI Rx command to
  843. * panel in order to clear if any stale data remaining from
  844. * previous read operation.
  845. */
  846. void dsi_ctrl_hw_cmn_clear_rdbk_reg(struct dsi_ctrl_hw *ctrl)
  847. {
  848. DSI_W32(ctrl, DSI_RDBK_DATA_CTRL, 0x1);
  849. wmb(); /* ensure read back register is reset */
  850. DSI_W32(ctrl, DSI_RDBK_DATA_CTRL, 0x0);
  851. wmb(); /* ensure read back register is cleared */
  852. }
  853. /**
  854. * get_cmd_read_data() - get data read from the peripheral
  855. * @ctrl: Pointer to the controller host hardware.
  856. * @rd_buf: Buffer where data will be read into.
  857. * @total_read_len: Number of bytes to read.
  858. *
  859. * return: number of bytes read.
  860. */
  861. u32 dsi_ctrl_hw_cmn_get_cmd_read_data(struct dsi_ctrl_hw *ctrl,
  862. u8 *rd_buf,
  863. u32 read_offset,
  864. u32 rx_byte,
  865. u32 pkt_size,
  866. u32 *hw_read_cnt)
  867. {
  868. u32 *lp, *temp, data;
  869. int i, j = 0, cnt, off;
  870. u32 read_cnt;
  871. u32 repeated_bytes = 0;
  872. u8 reg[16] = {0};
  873. bool ack_err = false;
  874. lp = (u32 *)rd_buf;
  875. temp = (u32 *)reg;
  876. cnt = (rx_byte + 3) >> 2;
  877. if (cnt > 4)
  878. cnt = 4;
  879. read_cnt = (DSI_R32(ctrl, DSI_RDBK_DATA_CTRL) >> 16);
  880. ack_err = (rx_byte == 4) ? (read_cnt == 8) :
  881. ((read_cnt - 4) == (pkt_size + 6));
  882. if (ack_err)
  883. read_cnt -= 4;
  884. if (!read_cnt) {
  885. DSI_CTRL_HW_ERR(ctrl, "Panel detected error, no data read\n");
  886. return 0;
  887. }
  888. if (read_cnt > 16) {
  889. int bytes_shifted, data_lost = 0, rem_header = 0;
  890. bytes_shifted = read_cnt - rx_byte;
  891. if (bytes_shifted >= 4)
  892. data_lost = bytes_shifted - 4; /* remove DCS header */
  893. else
  894. rem_header = 4 - bytes_shifted; /* remaining header */
  895. repeated_bytes = (read_offset - 4) - data_lost + rem_header;
  896. }
  897. off = DSI_RDBK_DATA0;
  898. off += ((cnt - 1) * 4);
  899. for (i = 0; i < cnt; i++) {
  900. data = DSI_R32(ctrl, off);
  901. if (!repeated_bytes)
  902. *lp++ = ntohl(data);
  903. else
  904. *temp++ = ntohl(data);
  905. off -= 4;
  906. }
  907. if (repeated_bytes) {
  908. for (i = repeated_bytes; i < 16; i++)
  909. rd_buf[j++] = reg[i];
  910. }
  911. *hw_read_cnt = read_cnt;
  912. DSI_CTRL_HW_DBG(ctrl, "Read %d bytes\n", rx_byte);
  913. return rx_byte;
  914. }
  915. /**
  916. * poll_dma_status() - API to poll DMA status
  917. * @ctrl: Pointer to the controller host hardware.
  918. *
  919. * Return: DMA status.
  920. */
  921. u32 dsi_ctrl_hw_cmn_poll_dma_status(struct dsi_ctrl_hw *ctrl)
  922. {
  923. int rc = 0;
  924. u32 status;
  925. u32 const delay_us = 10;
  926. u32 const timeout_us = 5000;
  927. rc = DSI_READ_POLL_TIMEOUT_ATOMIC(ctrl, DSI_INT_CTRL, status,
  928. ((status & DSI_CMD_MODE_DMA_DONE) > 0), delay_us, timeout_us);
  929. if (rc) {
  930. DSI_CTRL_HW_DBG(ctrl, "CMD_MODE_DMA_DONE failed\n");
  931. status = 0;
  932. }
  933. return status;
  934. }
  935. /**
  936. * get_interrupt_status() - returns the interrupt status
  937. * @ctrl: Pointer to the controller host hardware.
  938. *
  939. * Returns the ORed list of interrupts(enum dsi_status_int_type) that
  940. * are active. This list does not include any error interrupts. Caller
  941. * should call get_error_status for error interrupts.
  942. *
  943. * Return: List of active interrupts.
  944. */
  945. u32 dsi_ctrl_hw_cmn_get_interrupt_status(struct dsi_ctrl_hw *ctrl)
  946. {
  947. u32 reg = 0;
  948. u32 ints = 0;
  949. reg = DSI_R32(ctrl, DSI_INT_CTRL);
  950. if (reg & BIT(0))
  951. ints |= DSI_CMD_MODE_DMA_DONE;
  952. if (reg & BIT(8))
  953. ints |= DSI_CMD_FRAME_DONE;
  954. if (reg & BIT(10))
  955. ints |= DSI_CMD_STREAM0_FRAME_DONE;
  956. if (reg & BIT(12))
  957. ints |= DSI_CMD_STREAM1_FRAME_DONE;
  958. if (reg & BIT(14))
  959. ints |= DSI_CMD_STREAM2_FRAME_DONE;
  960. if (reg & BIT(16))
  961. ints |= DSI_VIDEO_MODE_FRAME_DONE;
  962. if (reg & BIT(20))
  963. ints |= DSI_BTA_DONE;
  964. if (reg & BIT(28))
  965. ints |= DSI_DYN_REFRESH_DONE;
  966. if (reg & BIT(30))
  967. ints |= DSI_DESKEW_DONE;
  968. if (reg & BIT(24))
  969. ints |= DSI_ERROR;
  970. DSI_CTRL_HW_DBG(ctrl, "Interrupt status = 0x%x, INT_CTRL=0x%x\n",
  971. ints, reg);
  972. return ints;
  973. }
  974. /**
  975. * clear_interrupt_status() - clears the specified interrupts
  976. * @ctrl: Pointer to the controller host hardware.
  977. * @ints: List of interrupts to be cleared.
  978. */
  979. void dsi_ctrl_hw_cmn_clear_interrupt_status(struct dsi_ctrl_hw *ctrl, u32 ints)
  980. {
  981. u32 reg = 0;
  982. reg = DSI_R32(ctrl, DSI_INT_CTRL);
  983. if (ints & DSI_CMD_MODE_DMA_DONE)
  984. reg |= BIT(0);
  985. if (ints & DSI_CMD_FRAME_DONE)
  986. reg |= BIT(8);
  987. if (ints & DSI_CMD_STREAM0_FRAME_DONE)
  988. reg |= BIT(10);
  989. if (ints & DSI_CMD_STREAM1_FRAME_DONE)
  990. reg |= BIT(12);
  991. if (ints & DSI_CMD_STREAM2_FRAME_DONE)
  992. reg |= BIT(14);
  993. if (ints & DSI_VIDEO_MODE_FRAME_DONE)
  994. reg |= BIT(16);
  995. if (ints & DSI_BTA_DONE)
  996. reg |= BIT(20);
  997. if (ints & DSI_DYN_REFRESH_DONE)
  998. reg |= BIT(28);
  999. if (ints & DSI_DESKEW_DONE)
  1000. reg |= BIT(30);
  1001. /*
  1002. * Do not clear error status.
  1003. * It will be cleared as part of
  1004. * error handler function.
  1005. */
  1006. reg &= ~BIT(24);
  1007. DSI_W32(ctrl, DSI_INT_CTRL, reg);
  1008. DSI_CTRL_HW_DBG(ctrl, "Clear interrupts, ints = 0x%x, INT_CTRL=0x%x\n",
  1009. ints, reg);
  1010. }
  1011. /**
  1012. * enable_status_interrupts() - enable the specified interrupts
  1013. * @ctrl: Pointer to the controller host hardware.
  1014. * @ints: List of interrupts to be enabled.
  1015. *
  1016. * Enables the specified interrupts. This list will override the
  1017. * previous interrupts enabled through this function. Caller has to
  1018. * maintain the state of the interrupts enabled. To disable all
  1019. * interrupts, set ints to 0.
  1020. */
  1021. void dsi_ctrl_hw_cmn_enable_status_interrupts(
  1022. struct dsi_ctrl_hw *ctrl, u32 ints)
  1023. {
  1024. u32 reg = 0;
  1025. /* Do not change value of DSI_ERROR_MASK bit */
  1026. reg |= (DSI_R32(ctrl, DSI_INT_CTRL) & BIT(25));
  1027. if (ints & DSI_CMD_MODE_DMA_DONE)
  1028. reg |= BIT(1);
  1029. if (ints & DSI_CMD_FRAME_DONE)
  1030. reg |= BIT(9);
  1031. if (ints & DSI_CMD_STREAM0_FRAME_DONE)
  1032. reg |= BIT(11);
  1033. if (ints & DSI_CMD_STREAM1_FRAME_DONE)
  1034. reg |= BIT(13);
  1035. if (ints & DSI_CMD_STREAM2_FRAME_DONE)
  1036. reg |= BIT(15);
  1037. if (ints & DSI_VIDEO_MODE_FRAME_DONE)
  1038. reg |= BIT(17);
  1039. if (ints & DSI_BTA_DONE)
  1040. reg |= BIT(21);
  1041. if (ints & DSI_DYN_REFRESH_DONE)
  1042. reg |= BIT(29);
  1043. if (ints & DSI_DESKEW_DONE)
  1044. reg |= BIT(31);
  1045. DSI_W32(ctrl, DSI_INT_CTRL, reg);
  1046. DSI_CTRL_HW_DBG(ctrl, "Enable interrupts 0x%x, INT_CTRL=0x%x\n", ints,
  1047. reg);
  1048. }
  1049. /**
  1050. * get_error_status() - returns the error status
  1051. * @ctrl: Pointer to the controller host hardware.
  1052. *
  1053. * Returns the ORed list of errors(enum dsi_error_int_type) that are
  1054. * active. This list does not include any status interrupts. Caller
  1055. * should call get_interrupt_status for status interrupts.
  1056. *
  1057. * Return: List of active error interrupts.
  1058. */
  1059. u64 dsi_ctrl_hw_cmn_get_error_status(struct dsi_ctrl_hw *ctrl)
  1060. {
  1061. u32 dln0_phy_err;
  1062. u32 fifo_status;
  1063. u32 ack_error;
  1064. u32 timeout_errors;
  1065. u32 clk_error;
  1066. u32 dsi_status;
  1067. u64 errors = 0, shift = 0x1;
  1068. dln0_phy_err = DSI_R32(ctrl, DSI_DLN0_PHY_ERR);
  1069. if (dln0_phy_err & BIT(0))
  1070. errors |= DSI_DLN0_ESC_ENTRY_ERR;
  1071. if (dln0_phy_err & BIT(4))
  1072. errors |= DSI_DLN0_ESC_SYNC_ERR;
  1073. if (dln0_phy_err & BIT(8))
  1074. errors |= DSI_DLN0_LP_CONTROL_ERR;
  1075. if (dln0_phy_err & BIT(12))
  1076. errors |= DSI_DLN0_LP0_CONTENTION;
  1077. if (dln0_phy_err & BIT(16))
  1078. errors |= DSI_DLN0_LP1_CONTENTION;
  1079. fifo_status = DSI_R32(ctrl, DSI_FIFO_STATUS);
  1080. if (fifo_status & BIT(7))
  1081. errors |= DSI_CMD_MDP_FIFO_UNDERFLOW;
  1082. if (fifo_status & BIT(10))
  1083. errors |= DSI_CMD_DMA_FIFO_UNDERFLOW;
  1084. if (fifo_status & BIT(18))
  1085. errors |= DSI_DLN0_HS_FIFO_OVERFLOW;
  1086. if (fifo_status & BIT(19))
  1087. errors |= DSI_DLN0_HS_FIFO_UNDERFLOW;
  1088. if (fifo_status & BIT(22))
  1089. errors |= DSI_DLN1_HS_FIFO_OVERFLOW;
  1090. if (fifo_status & BIT(23))
  1091. errors |= DSI_DLN1_HS_FIFO_UNDERFLOW;
  1092. if (fifo_status & BIT(26))
  1093. errors |= DSI_DLN2_HS_FIFO_OVERFLOW;
  1094. if (fifo_status & BIT(27))
  1095. errors |= DSI_DLN2_HS_FIFO_UNDERFLOW;
  1096. if (fifo_status & BIT(30))
  1097. errors |= DSI_DLN3_HS_FIFO_OVERFLOW;
  1098. if (fifo_status & BIT(31))
  1099. errors |= DSI_DLN3_HS_FIFO_UNDERFLOW;
  1100. ack_error = DSI_R32(ctrl, DSI_ACK_ERR_STATUS);
  1101. if (ack_error & BIT(16))
  1102. errors |= DSI_RDBK_SINGLE_ECC_ERR;
  1103. if (ack_error & BIT(17))
  1104. errors |= DSI_RDBK_MULTI_ECC_ERR;
  1105. if (ack_error & BIT(20))
  1106. errors |= DSI_RDBK_CRC_ERR;
  1107. if (ack_error & BIT(23))
  1108. errors |= DSI_RDBK_INCOMPLETE_PKT;
  1109. if (ack_error & BIT(24))
  1110. errors |= DSI_PERIPH_ERROR_PKT;
  1111. if (ack_error & BIT(15))
  1112. errors |= (shift << DSI_EINT_PANEL_SPECIFIC_ERR);
  1113. timeout_errors = DSI_R32(ctrl, DSI_TIMEOUT_STATUS);
  1114. if (timeout_errors & BIT(0))
  1115. errors |= DSI_HS_TX_TIMEOUT;
  1116. if (timeout_errors & BIT(4))
  1117. errors |= DSI_LP_RX_TIMEOUT;
  1118. if (timeout_errors & BIT(8))
  1119. errors |= DSI_BTA_TIMEOUT;
  1120. clk_error = DSI_R32(ctrl, DSI_CLK_STATUS);
  1121. if (clk_error & BIT(16))
  1122. errors |= DSI_PLL_UNLOCK;
  1123. dsi_status = DSI_R32(ctrl, DSI_STATUS);
  1124. if (dsi_status & BIT(31))
  1125. errors |= DSI_INTERLEAVE_OP_CONTENTION;
  1126. DSI_CTRL_HW_DBG(ctrl, "Error status = 0x%llx, phy=0x%x, fifo=0x%x\n",
  1127. errors, dln0_phy_err, fifo_status);
  1128. DSI_CTRL_HW_DBG(ctrl, "ack=0x%x, timeout=0x%x, clk=0x%x, dsi=0x%x\n",
  1129. ack_error, timeout_errors, clk_error, dsi_status);
  1130. return errors;
  1131. }
  1132. /**
  1133. * clear_error_status() - clears the specified errors
  1134. * @ctrl: Pointer to the controller host hardware.
  1135. * @errors: List of errors to be cleared.
  1136. */
  1137. void dsi_ctrl_hw_cmn_clear_error_status(struct dsi_ctrl_hw *ctrl, u64 errors)
  1138. {
  1139. u32 dln0_phy_err = 0;
  1140. u32 fifo_status = 0;
  1141. u32 ack_error = 0;
  1142. u32 timeout_error = 0;
  1143. u32 clk_error = 0;
  1144. u32 dsi_status = 0;
  1145. if (errors & DSI_RDBK_SINGLE_ECC_ERR)
  1146. ack_error |= BIT(16);
  1147. if (errors & DSI_RDBK_MULTI_ECC_ERR)
  1148. ack_error |= BIT(17);
  1149. if (errors & DSI_RDBK_CRC_ERR)
  1150. ack_error |= BIT(20);
  1151. if (errors & DSI_RDBK_INCOMPLETE_PKT)
  1152. ack_error |= BIT(23);
  1153. if (errors & DSI_PERIPH_ERROR_PKT)
  1154. ack_error |= BIT(24);
  1155. if (errors & DSI_PANEL_SPECIFIC_ERR)
  1156. ack_error |= BIT(15);
  1157. if (errors & DSI_LP_RX_TIMEOUT)
  1158. timeout_error |= BIT(4);
  1159. if (errors & DSI_HS_TX_TIMEOUT)
  1160. timeout_error |= BIT(0);
  1161. if (errors & DSI_BTA_TIMEOUT)
  1162. timeout_error |= BIT(8);
  1163. if (errors & DSI_PLL_UNLOCK)
  1164. clk_error |= BIT(16);
  1165. if (errors & DSI_DLN0_LP0_CONTENTION)
  1166. dln0_phy_err |= BIT(12);
  1167. if (errors & DSI_DLN0_LP1_CONTENTION)
  1168. dln0_phy_err |= BIT(16);
  1169. if (errors & DSI_DLN0_ESC_ENTRY_ERR)
  1170. dln0_phy_err |= BIT(0);
  1171. if (errors & DSI_DLN0_ESC_SYNC_ERR)
  1172. dln0_phy_err |= BIT(4);
  1173. if (errors & DSI_DLN0_LP_CONTROL_ERR)
  1174. dln0_phy_err |= BIT(8);
  1175. if (errors & DSI_CMD_DMA_FIFO_UNDERFLOW)
  1176. fifo_status |= BIT(10);
  1177. if (errors & DSI_CMD_MDP_FIFO_UNDERFLOW)
  1178. fifo_status |= BIT(7);
  1179. if (errors & DSI_DLN0_HS_FIFO_OVERFLOW)
  1180. fifo_status |= BIT(18);
  1181. if (errors & DSI_DLN1_HS_FIFO_OVERFLOW)
  1182. fifo_status |= BIT(22);
  1183. if (errors & DSI_DLN2_HS_FIFO_OVERFLOW)
  1184. fifo_status |= BIT(26);
  1185. if (errors & DSI_DLN3_HS_FIFO_OVERFLOW)
  1186. fifo_status |= BIT(30);
  1187. if (errors & DSI_DLN0_HS_FIFO_UNDERFLOW)
  1188. fifo_status |= BIT(19);
  1189. if (errors & DSI_DLN1_HS_FIFO_UNDERFLOW)
  1190. fifo_status |= BIT(23);
  1191. if (errors & DSI_DLN2_HS_FIFO_UNDERFLOW)
  1192. fifo_status |= BIT(27);
  1193. if (errors & DSI_DLN3_HS_FIFO_UNDERFLOW)
  1194. fifo_status |= BIT(31);
  1195. if (errors & DSI_INTERLEAVE_OP_CONTENTION)
  1196. dsi_status |= BIT(31);
  1197. DSI_W32(ctrl, DSI_DLN0_PHY_ERR, dln0_phy_err);
  1198. DSI_W32(ctrl, DSI_FIFO_STATUS, fifo_status);
  1199. /* Writing of an extra 0 is needed to clear ack error bits */
  1200. DSI_W32(ctrl, DSI_ACK_ERR_STATUS, ack_error);
  1201. wmb(); /* make sure register is committed */
  1202. DSI_W32(ctrl, DSI_ACK_ERR_STATUS, 0x0);
  1203. DSI_W32(ctrl, DSI_TIMEOUT_STATUS, timeout_error);
  1204. DSI_W32(ctrl, DSI_CLK_STATUS, clk_error);
  1205. DSI_W32(ctrl, DSI_STATUS, dsi_status);
  1206. DSI_CTRL_HW_DBG(ctrl, "clear errors = 0x%llx, phy=0x%x, fifo=0x%x\n",
  1207. errors, dln0_phy_err, fifo_status);
  1208. DSI_CTRL_HW_DBG(ctrl, "ack=0x%x, timeout=0x%x, clk=0x%x, dsi=0x%x\n",
  1209. ack_error, timeout_error, clk_error, dsi_status);
  1210. }
  1211. /**
  1212. * enable_error_interrupts() - enable the specified interrupts
  1213. * @ctrl: Pointer to the controller host hardware.
  1214. * @errors: List of errors to be enabled.
  1215. *
  1216. * Enables the specified interrupts. This list will override the
  1217. * previous interrupts enabled through this function. Caller has to
  1218. * maintain the state of the interrupts enabled. To disable all
  1219. * interrupts, set errors to 0.
  1220. */
  1221. void dsi_ctrl_hw_cmn_enable_error_interrupts(struct dsi_ctrl_hw *ctrl,
  1222. u64 errors)
  1223. {
  1224. u32 int_ctrl = 0;
  1225. u32 int_mask0 = 0x7FFF3BFF;
  1226. u32 dln0_phy_err = 0x11111;
  1227. u32 fifo_status = 0xCCCC0789;
  1228. u32 ack_error = 0x1193BFFF;
  1229. u32 timeout_status = 0x11111111;
  1230. u32 clk_status = 0x10000;
  1231. u32 dsi_status_error = 0x80000000;
  1232. u32 reg = 0;
  1233. DSI_W32(ctrl, DSI_DLN0_PHY_ERR, dln0_phy_err);
  1234. DSI_W32(ctrl, DSI_FIFO_STATUS, fifo_status);
  1235. DSI_W32(ctrl, DSI_TIMEOUT_STATUS, timeout_status);
  1236. DSI_W32(ctrl, DSI_ACK_ERR_STATUS, ack_error);
  1237. reg = DSI_R32(ctrl, DSI_CLK_STATUS);
  1238. DSI_W32(ctrl, DSI_CLK_STATUS, reg | clk_status);
  1239. reg = DSI_R32(ctrl, DSI_STATUS);
  1240. DSI_W32(ctrl, DSI_STATUS, reg | dsi_status_error);
  1241. int_ctrl = DSI_R32(ctrl, DSI_INT_CTRL);
  1242. if (errors)
  1243. int_ctrl |= BIT(25);
  1244. else
  1245. int_ctrl &= ~BIT(25);
  1246. if (errors & DSI_RDBK_SINGLE_ECC_ERR)
  1247. int_mask0 &= ~BIT(0);
  1248. if (errors & DSI_RDBK_MULTI_ECC_ERR)
  1249. int_mask0 &= ~BIT(1);
  1250. if (errors & DSI_RDBK_CRC_ERR)
  1251. int_mask0 &= ~BIT(2);
  1252. if (errors & DSI_RDBK_INCOMPLETE_PKT)
  1253. int_mask0 &= ~BIT(3);
  1254. if (errors & DSI_PERIPH_ERROR_PKT)
  1255. int_mask0 &= ~BIT(4);
  1256. if (errors & DSI_LP_RX_TIMEOUT)
  1257. int_mask0 &= ~BIT(5);
  1258. if (errors & DSI_HS_TX_TIMEOUT)
  1259. int_mask0 &= ~BIT(6);
  1260. if (errors & DSI_BTA_TIMEOUT)
  1261. int_mask0 &= ~BIT(7);
  1262. if (errors & DSI_PLL_UNLOCK)
  1263. int_mask0 &= ~BIT(28);
  1264. if (errors & DSI_DLN0_LP0_CONTENTION)
  1265. int_mask0 &= ~BIT(24);
  1266. if (errors & DSI_DLN0_LP1_CONTENTION)
  1267. int_mask0 &= ~BIT(25);
  1268. if (errors & DSI_DLN0_ESC_ENTRY_ERR)
  1269. int_mask0 &= ~BIT(21);
  1270. if (errors & DSI_DLN0_ESC_SYNC_ERR)
  1271. int_mask0 &= ~BIT(22);
  1272. if (errors & DSI_DLN0_LP_CONTROL_ERR)
  1273. int_mask0 &= ~BIT(23);
  1274. if (errors & DSI_CMD_DMA_FIFO_UNDERFLOW)
  1275. int_mask0 &= ~BIT(9);
  1276. if (errors & DSI_CMD_MDP_FIFO_UNDERFLOW)
  1277. int_mask0 &= ~BIT(11);
  1278. if (errors & DSI_DLN0_HS_FIFO_OVERFLOW)
  1279. int_mask0 &= ~BIT(16);
  1280. if (errors & DSI_DLN1_HS_FIFO_OVERFLOW)
  1281. int_mask0 &= ~BIT(17);
  1282. if (errors & DSI_DLN2_HS_FIFO_OVERFLOW)
  1283. int_mask0 &= ~BIT(18);
  1284. if (errors & DSI_DLN3_HS_FIFO_OVERFLOW)
  1285. int_mask0 &= ~BIT(19);
  1286. if (errors & DSI_DLN0_HS_FIFO_UNDERFLOW)
  1287. int_mask0 &= ~BIT(26);
  1288. if (errors & DSI_DLN1_HS_FIFO_UNDERFLOW)
  1289. int_mask0 &= ~BIT(27);
  1290. if (errors & DSI_DLN2_HS_FIFO_UNDERFLOW)
  1291. int_mask0 &= ~BIT(29);
  1292. if (errors & DSI_DLN3_HS_FIFO_UNDERFLOW)
  1293. int_mask0 &= ~BIT(30);
  1294. if (errors & DSI_INTERLEAVE_OP_CONTENTION)
  1295. int_mask0 &= ~BIT(8);
  1296. DSI_W32(ctrl, DSI_INT_CTRL, int_ctrl);
  1297. DSI_W32(ctrl, DSI_ERR_INT_MASK0, int_mask0);
  1298. DSI_CTRL_HW_DBG(ctrl, "[DSI_%d] enable errors = 0x%llx, int_mask0=0x%x\n",
  1299. ctrl->index, errors, int_mask0);
  1300. }
  1301. /**
  1302. * video_test_pattern_setup() - setup test pattern engine for video mode
  1303. * @ctrl: Pointer to the controller host hardware.
  1304. * @type: Type of test pattern.
  1305. * @init_val: Initial value to use for generating test pattern.
  1306. */
  1307. void dsi_ctrl_hw_cmn_video_test_pattern_setup(struct dsi_ctrl_hw *ctrl,
  1308. enum dsi_test_pattern type,
  1309. u32 init_val)
  1310. {
  1311. u32 reg = 0;
  1312. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_VIDEO_INIT_VAL, init_val);
  1313. switch (type) {
  1314. case DSI_TEST_PATTERN_FIXED:
  1315. reg |= (0x2 << 4);
  1316. break;
  1317. case DSI_TEST_PATTERN_INC:
  1318. reg |= (0x1 << 4);
  1319. break;
  1320. case DSI_TEST_PATTERN_POLY:
  1321. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_VIDEO_POLY, 0xF0F0F);
  1322. break;
  1323. default:
  1324. break;
  1325. }
  1326. DSI_W32(ctrl, DSI_TPG_MAIN_CONTROL, 0x100);
  1327. DSI_W32(ctrl, DSI_TPG_VIDEO_CONFIG, 0x5);
  1328. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  1329. DSI_CTRL_HW_DBG(ctrl, "Video test pattern setup done\n");
  1330. }
  1331. /**
  1332. * cmd_test_pattern_setup() - setup test patttern engine for cmd mode
  1333. * @ctrl: Pointer to the controller host hardware.
  1334. * @type: Type of test pattern.
  1335. * @init_val: Initial value to use for generating test pattern.
  1336. * @stream_id: Stream Id on which packets are generated.
  1337. */
  1338. void dsi_ctrl_hw_cmn_cmd_test_pattern_setup(struct dsi_ctrl_hw *ctrl,
  1339. enum dsi_test_pattern type,
  1340. u32 init_val,
  1341. u32 stream_id)
  1342. {
  1343. u32 reg = 0;
  1344. u32 init_offset;
  1345. u32 poly_offset;
  1346. u32 pattern_sel_shift;
  1347. switch (stream_id) {
  1348. case 0:
  1349. init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL0;
  1350. poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM0_POLY;
  1351. pattern_sel_shift = 8;
  1352. break;
  1353. case 1:
  1354. init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL1;
  1355. poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM1_POLY;
  1356. pattern_sel_shift = 12;
  1357. break;
  1358. case 2:
  1359. init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL2;
  1360. poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM2_POLY;
  1361. pattern_sel_shift = 20;
  1362. break;
  1363. default:
  1364. return;
  1365. }
  1366. DSI_W32(ctrl, init_offset, init_val);
  1367. switch (type) {
  1368. case DSI_TEST_PATTERN_FIXED:
  1369. reg |= (0x2 << pattern_sel_shift);
  1370. break;
  1371. case DSI_TEST_PATTERN_INC:
  1372. reg |= (0x1 << pattern_sel_shift);
  1373. break;
  1374. case DSI_TEST_PATTERN_POLY:
  1375. DSI_W32(ctrl, poly_offset, 0xF0F0F);
  1376. break;
  1377. default:
  1378. break;
  1379. }
  1380. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  1381. DSI_CTRL_HW_DBG(ctrl, "Cmd test pattern setup done\n");
  1382. }
  1383. /**
  1384. * test_pattern_enable() - enable test pattern engine
  1385. * @ctrl: Pointer to the controller host hardware.
  1386. * @enable: Enable/Disable test pattern engine.
  1387. */
  1388. void dsi_ctrl_hw_cmn_test_pattern_enable(struct dsi_ctrl_hw *ctrl,
  1389. bool enable)
  1390. {
  1391. u32 reg = DSI_R32(ctrl, DSI_TEST_PATTERN_GEN_CTRL);
  1392. if (enable)
  1393. reg |= BIT(0);
  1394. else
  1395. reg &= ~BIT(0);
  1396. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  1397. DSI_CTRL_HW_DBG(ctrl, "Test pattern enable=%d\n", enable);
  1398. }
  1399. /**
  1400. * trigger_cmd_test_pattern() - trigger a command mode frame update with
  1401. * test pattern
  1402. * @ctrl: Pointer to the controller host hardware.
  1403. * @stream_id: Stream on which frame update is sent.
  1404. */
  1405. void dsi_ctrl_hw_cmn_trigger_cmd_test_pattern(struct dsi_ctrl_hw *ctrl,
  1406. u32 stream_id)
  1407. {
  1408. switch (stream_id) {
  1409. case 0:
  1410. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM0_TRIGGER, 0x1);
  1411. break;
  1412. case 1:
  1413. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM1_TRIGGER, 0x1);
  1414. break;
  1415. case 2:
  1416. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM2_TRIGGER, 0x1);
  1417. break;
  1418. default:
  1419. break;
  1420. }
  1421. DSI_CTRL_HW_DBG(ctrl, "Cmd Test pattern trigger\n");
  1422. }
  1423. void dsi_ctrl_hw_dln0_phy_err(struct dsi_ctrl_hw *ctrl)
  1424. {
  1425. u32 status = 0;
  1426. /*
  1427. * Clear out any phy errors prior to exiting ULPS
  1428. * This fixes certain instances where phy does not exit
  1429. * ULPS cleanly. Also, do not print error during such cases.
  1430. */
  1431. status = DSI_R32(ctrl, DSI_DLN0_PHY_ERR);
  1432. if (status & 0x011111) {
  1433. DSI_W32(ctrl, DSI_DLN0_PHY_ERR, status);
  1434. DSI_CTRL_HW_ERR(ctrl, "phy_err_status = %x\n", status);
  1435. }
  1436. }
  1437. void dsi_ctrl_hw_cmn_phy_reset_config(struct dsi_ctrl_hw *ctrl,
  1438. bool enable)
  1439. {
  1440. u32 reg = 0;
  1441. reg = DSI_MMSS_MISC_R32(ctrl, MMSS_MISC_CLAMP_REG_OFF);
  1442. /* Mask/unmask disable PHY reset bit */
  1443. if (enable)
  1444. reg |= BIT(30);
  1445. else
  1446. reg &= ~BIT(30);
  1447. DSI_MMSS_MISC_W32(ctrl, MMSS_MISC_CLAMP_REG_OFF, reg);
  1448. }
  1449. int dsi_ctrl_hw_cmn_ctrl_reset(struct dsi_ctrl_hw *ctrl,
  1450. int mask)
  1451. {
  1452. int rc = 0;
  1453. u32 data;
  1454. DSI_CTRL_HW_DBG(ctrl, "DSI CTRL and PHY reset, mask=%d\n", mask);
  1455. data = DSI_R32(ctrl, 0x0004);
  1456. /* Disable DSI video mode */
  1457. DSI_W32(ctrl, 0x004, (data & ~BIT(1)));
  1458. wmb(); /* ensure register committed */
  1459. /* Disable DSI controller */
  1460. DSI_W32(ctrl, 0x004, (data & ~(BIT(0) | BIT(1))));
  1461. wmb(); /* ensure register committed */
  1462. /* "Force On" all dynamic clocks */
  1463. DSI_W32(ctrl, 0x11c, 0x100a00);
  1464. /* DSI_SW_RESET */
  1465. DSI_W32(ctrl, 0x118, 0x1);
  1466. wmb(); /* ensure register is committed */
  1467. DSI_W32(ctrl, 0x118, 0x0);
  1468. wmb(); /* ensure register is committed */
  1469. /* Remove "Force On" all dynamic clocks */
  1470. DSI_W32(ctrl, 0x11c, 0x00);
  1471. /* Enable DSI controller */
  1472. DSI_W32(ctrl, 0x004, (data & ~BIT(1)));
  1473. wmb(); /* ensure register committed */
  1474. return rc;
  1475. }
  1476. void dsi_ctrl_hw_cmn_mask_error_intr(struct dsi_ctrl_hw *ctrl, u32 idx, bool en)
  1477. {
  1478. u32 reg = 0;
  1479. u32 fifo_status = 0, timeout_status = 0;
  1480. u32 overflow_clear = BIT(10) | BIT(18) | BIT(22) | BIT(26) | BIT(30);
  1481. u32 underflow_clear = BIT(19) | BIT(23) | BIT(27) | BIT(31);
  1482. u32 lp_rx_clear = BIT(4);
  1483. reg = DSI_R32(ctrl, 0x10c);
  1484. /*
  1485. * Before unmasking we should clear the corresponding error status bits
  1486. * that might have been set while we masked these errors. Since these
  1487. * are sticky bits, these errors will trigger the moment we unmask
  1488. * the error bits.
  1489. */
  1490. if (idx & BIT(DSI_FIFO_OVERFLOW)) {
  1491. if (en) {
  1492. reg |= (0x1f << 16);
  1493. reg |= BIT(9);
  1494. } else {
  1495. reg &= ~(0x1f << 16);
  1496. reg &= ~BIT(9);
  1497. fifo_status = DSI_R32(ctrl, 0x00c);
  1498. DSI_W32(ctrl, 0x00c, fifo_status | overflow_clear);
  1499. }
  1500. }
  1501. if (idx & BIT(DSI_FIFO_UNDERFLOW)) {
  1502. if (en)
  1503. reg |= (0x1b << 26);
  1504. else {
  1505. reg &= ~(0x1b << 26);
  1506. fifo_status = DSI_R32(ctrl, 0x00c);
  1507. DSI_W32(ctrl, 0x00c, fifo_status | underflow_clear);
  1508. }
  1509. }
  1510. if (idx & BIT(DSI_LP_Rx_TIMEOUT)) {
  1511. if (en)
  1512. reg |= (0x7 << 23);
  1513. else {
  1514. reg &= ~(0x7 << 23);
  1515. timeout_status = DSI_R32(ctrl, 0x0c0);
  1516. DSI_W32(ctrl, 0x0c0, timeout_status | lp_rx_clear);
  1517. }
  1518. }
  1519. if (idx & BIT(DSI_PLL_UNLOCK_ERR)) {
  1520. if (en)
  1521. reg |= BIT(28);
  1522. else
  1523. reg &= ~BIT(28);
  1524. }
  1525. DSI_W32(ctrl, 0x10c, reg);
  1526. wmb(); /* ensure error is masked */
  1527. }
  1528. void dsi_ctrl_hw_cmn_error_intr_ctrl(struct dsi_ctrl_hw *ctrl, bool en)
  1529. {
  1530. u32 reg = 0;
  1531. u32 dsi_total_mask = 0x2222AA02;
  1532. reg = DSI_R32(ctrl, 0x110);
  1533. reg &= dsi_total_mask;
  1534. if (en)
  1535. reg |= (BIT(24) | BIT(25));
  1536. else
  1537. reg &= ~BIT(25);
  1538. DSI_W32(ctrl, 0x110, reg);
  1539. wmb(); /* ensure error is masked */
  1540. }
  1541. u32 dsi_ctrl_hw_cmn_get_error_mask(struct dsi_ctrl_hw *ctrl)
  1542. {
  1543. u32 reg = 0;
  1544. reg = DSI_R32(ctrl, 0x10c);
  1545. return reg;
  1546. }
  1547. u32 dsi_ctrl_hw_cmn_get_hw_version(struct dsi_ctrl_hw *ctrl)
  1548. {
  1549. u32 reg = 0;
  1550. reg = DSI_R32(ctrl, 0x0);
  1551. return reg;
  1552. }
  1553. int dsi_ctrl_hw_cmn_wait_for_cmd_mode_mdp_idle(struct dsi_ctrl_hw *ctrl)
  1554. {
  1555. int rc = 0, val = 0;
  1556. u32 cmd_mode_mdp_busy_mask = BIT(2);
  1557. u32 const sleep_us = 2 * 1000;
  1558. u32 const timeout_us = 200 * 1000;
  1559. rc = DSI_READ_POLL_TIMEOUT(ctrl, DSI_STATUS, val,
  1560. !(val & cmd_mode_mdp_busy_mask), sleep_us, timeout_us);
  1561. if (rc)
  1562. DSI_CTRL_HW_ERR(ctrl, "timed out waiting for idle\n");
  1563. return rc;
  1564. }
  1565. void dsi_ctrl_hw_cmn_hs_req_sel(struct dsi_ctrl_hw *ctrl, bool sel_phy)
  1566. {
  1567. u32 reg = 0;
  1568. reg = DSI_R32(ctrl, DSI_LANE_CTRL);
  1569. if (sel_phy)
  1570. reg &= ~BIT(24);
  1571. else
  1572. reg |= BIT(24);
  1573. DSI_W32(ctrl, DSI_LANE_CTRL, reg);
  1574. wmb(); /* make sure request is set */
  1575. }
  1576. void dsi_ctrl_hw_cmn_set_continuous_clk(struct dsi_ctrl_hw *ctrl, bool enable)
  1577. {
  1578. u32 reg = 0;
  1579. reg = DSI_R32(ctrl, DSI_LANE_CTRL);
  1580. if (enable)
  1581. reg |= BIT(28);
  1582. else
  1583. reg &= ~BIT(28);
  1584. DSI_W32(ctrl, DSI_LANE_CTRL, reg);
  1585. wmb(); /* make sure request is set */
  1586. }
  1587. int dsi_ctrl_hw_cmn_wait4dynamic_refresh_done(struct dsi_ctrl_hw *ctrl)
  1588. {
  1589. int rc;
  1590. u32 const sleep_us = 1000;
  1591. u32 const timeout_us = 84000; /* approximately 5 vsyncs */
  1592. u32 reg = 0, dyn_refresh_done = BIT(28);
  1593. rc = DSI_READ_POLL_TIMEOUT(ctrl, DSI_INT_CTRL, reg,
  1594. (reg & dyn_refresh_done), sleep_us, timeout_us);
  1595. if (rc) {
  1596. DSI_CTRL_HW_ERR(ctrl, "wait4dynamic refresh timedout %d\n", rc);
  1597. return rc;
  1598. }
  1599. /* ack dynamic refresh done status */
  1600. reg = DSI_R32(ctrl, DSI_INT_CTRL);
  1601. reg |= dyn_refresh_done;
  1602. DSI_W32(ctrl, DSI_INT_CTRL, reg);
  1603. return 0;
  1604. }
  1605. bool dsi_ctrl_hw_cmn_vid_engine_busy(struct dsi_ctrl_hw *ctrl)
  1606. {
  1607. u32 reg = 0, video_engine_busy = BIT(3);
  1608. int rc;
  1609. u32 const sleep_us = 1000;
  1610. u32 const timeout_us = 50000;
  1611. rc = DSI_READ_POLL_TIMEOUT(ctrl, DSI_STATUS, reg,
  1612. !(reg & video_engine_busy), sleep_us, timeout_us);
  1613. if (rc)
  1614. return true;
  1615. return false;
  1616. }