dsi_ctrl_hw_cmn.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872
  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. u32 dln0_phy_err = 0x11111;
  1224. u32 fifo_status = 0xCCCC0789;
  1225. u32 ack_error = 0x1193BFFF;
  1226. u32 timeout_status = 0x11111111;
  1227. u32 clk_status = 0x10000;
  1228. u32 dsi_status_error = 0x80000000;
  1229. u32 reg = 0;
  1230. DSI_W32(ctrl, DSI_DLN0_PHY_ERR, dln0_phy_err);
  1231. DSI_W32(ctrl, DSI_FIFO_STATUS, fifo_status);
  1232. DSI_W32(ctrl, DSI_TIMEOUT_STATUS, timeout_status);
  1233. DSI_W32(ctrl, DSI_ACK_ERR_STATUS, ack_error);
  1234. reg = DSI_R32(ctrl, DSI_CLK_STATUS);
  1235. DSI_W32(ctrl, DSI_CLK_STATUS, reg | clk_status);
  1236. reg = DSI_R32(ctrl, DSI_STATUS);
  1237. DSI_W32(ctrl, DSI_STATUS, reg | dsi_status_error);
  1238. int_ctrl = DSI_R32(ctrl, DSI_INT_CTRL);
  1239. if (errors)
  1240. int_ctrl |= BIT(25);
  1241. else
  1242. int_ctrl &= ~BIT(25);
  1243. if (errors & DSI_RDBK_SINGLE_ECC_ERR)
  1244. int_mask0 &= ~BIT(0);
  1245. if (errors & DSI_RDBK_MULTI_ECC_ERR)
  1246. int_mask0 &= ~BIT(1);
  1247. if (errors & DSI_RDBK_CRC_ERR)
  1248. int_mask0 &= ~BIT(2);
  1249. if (errors & DSI_RDBK_INCOMPLETE_PKT)
  1250. int_mask0 &= ~BIT(3);
  1251. if (errors & DSI_PERIPH_ERROR_PKT)
  1252. int_mask0 &= ~BIT(4);
  1253. if (errors & DSI_LP_RX_TIMEOUT)
  1254. int_mask0 &= ~BIT(5);
  1255. if (errors & DSI_HS_TX_TIMEOUT)
  1256. int_mask0 &= ~BIT(6);
  1257. if (errors & DSI_BTA_TIMEOUT)
  1258. int_mask0 &= ~BIT(7);
  1259. if (errors & DSI_PLL_UNLOCK)
  1260. int_mask0 &= ~BIT(28);
  1261. if (errors & DSI_DLN0_LP0_CONTENTION)
  1262. int_mask0 &= ~BIT(24);
  1263. if (errors & DSI_DLN0_LP1_CONTENTION)
  1264. int_mask0 &= ~BIT(25);
  1265. if (errors & DSI_DLN0_ESC_ENTRY_ERR)
  1266. int_mask0 &= ~BIT(21);
  1267. if (errors & DSI_DLN0_ESC_SYNC_ERR)
  1268. int_mask0 &= ~BIT(22);
  1269. if (errors & DSI_DLN0_LP_CONTROL_ERR)
  1270. int_mask0 &= ~BIT(23);
  1271. if (errors & DSI_CMD_DMA_FIFO_UNDERFLOW)
  1272. int_mask0 &= ~BIT(9);
  1273. if (errors & DSI_CMD_MDP_FIFO_UNDERFLOW)
  1274. int_mask0 &= ~BIT(11);
  1275. if (errors & DSI_DLN0_HS_FIFO_OVERFLOW)
  1276. int_mask0 &= ~BIT(16);
  1277. if (errors & DSI_DLN1_HS_FIFO_OVERFLOW)
  1278. int_mask0 &= ~BIT(17);
  1279. if (errors & DSI_DLN2_HS_FIFO_OVERFLOW)
  1280. int_mask0 &= ~BIT(18);
  1281. if (errors & DSI_DLN3_HS_FIFO_OVERFLOW)
  1282. int_mask0 &= ~BIT(19);
  1283. if (errors & DSI_DLN0_HS_FIFO_UNDERFLOW)
  1284. int_mask0 &= ~BIT(26);
  1285. if (errors & DSI_DLN1_HS_FIFO_UNDERFLOW)
  1286. int_mask0 &= ~BIT(27);
  1287. if (errors & DSI_DLN2_HS_FIFO_UNDERFLOW)
  1288. int_mask0 &= ~BIT(29);
  1289. if (errors & DSI_DLN3_HS_FIFO_UNDERFLOW)
  1290. int_mask0 &= ~BIT(30);
  1291. if (errors & DSI_INTERLEAVE_OP_CONTENTION)
  1292. int_mask0 &= ~BIT(8);
  1293. DSI_W32(ctrl, DSI_INT_CTRL, int_ctrl);
  1294. DSI_W32(ctrl, DSI_ERR_INT_MASK0, int_mask0);
  1295. DSI_CTRL_HW_DBG(ctrl, "[DSI_%d] enable errors = 0x%llx, int_mask0=0x%x\n",
  1296. ctrl->index, errors, int_mask0);
  1297. }
  1298. /**
  1299. * video_test_pattern_setup() - setup test pattern engine for video mode
  1300. * @ctrl: Pointer to the controller host hardware.
  1301. * @type: Type of test pattern.
  1302. * @init_val: Initial value to use for generating test pattern.
  1303. */
  1304. void dsi_ctrl_hw_cmn_video_test_pattern_setup(struct dsi_ctrl_hw *ctrl,
  1305. enum dsi_test_pattern type,
  1306. u32 init_val)
  1307. {
  1308. u32 reg = 0;
  1309. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_VIDEO_INIT_VAL, init_val);
  1310. switch (type) {
  1311. case DSI_TEST_PATTERN_FIXED:
  1312. reg |= (0x2 << 4);
  1313. break;
  1314. case DSI_TEST_PATTERN_INC:
  1315. reg |= (0x1 << 4);
  1316. break;
  1317. case DSI_TEST_PATTERN_POLY:
  1318. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_VIDEO_POLY, 0xF0F0F);
  1319. break;
  1320. default:
  1321. break;
  1322. }
  1323. DSI_W32(ctrl, DSI_TPG_MAIN_CONTROL, 0x100);
  1324. DSI_W32(ctrl, DSI_TPG_VIDEO_CONFIG, 0x5);
  1325. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  1326. DSI_CTRL_HW_DBG(ctrl, "Video test pattern setup done\n");
  1327. }
  1328. /**
  1329. * cmd_test_pattern_setup() - setup test patttern engine for cmd mode
  1330. * @ctrl: Pointer to the controller host hardware.
  1331. * @type: Type of test pattern.
  1332. * @init_val: Initial value to use for generating test pattern.
  1333. * @stream_id: Stream Id on which packets are generated.
  1334. */
  1335. void dsi_ctrl_hw_cmn_cmd_test_pattern_setup(struct dsi_ctrl_hw *ctrl,
  1336. enum dsi_test_pattern type,
  1337. u32 init_val,
  1338. u32 stream_id)
  1339. {
  1340. u32 reg = 0;
  1341. u32 init_offset;
  1342. u32 poly_offset;
  1343. u32 pattern_sel_shift;
  1344. switch (stream_id) {
  1345. case 0:
  1346. init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL0;
  1347. poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM0_POLY;
  1348. pattern_sel_shift = 8;
  1349. break;
  1350. case 1:
  1351. init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL1;
  1352. poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM1_POLY;
  1353. pattern_sel_shift = 12;
  1354. break;
  1355. case 2:
  1356. init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL2;
  1357. poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM2_POLY;
  1358. pattern_sel_shift = 20;
  1359. break;
  1360. default:
  1361. return;
  1362. }
  1363. DSI_W32(ctrl, init_offset, init_val);
  1364. switch (type) {
  1365. case DSI_TEST_PATTERN_FIXED:
  1366. reg |= (0x2 << pattern_sel_shift);
  1367. break;
  1368. case DSI_TEST_PATTERN_INC:
  1369. reg |= (0x1 << pattern_sel_shift);
  1370. break;
  1371. case DSI_TEST_PATTERN_POLY:
  1372. DSI_W32(ctrl, poly_offset, 0xF0F0F);
  1373. break;
  1374. default:
  1375. break;
  1376. }
  1377. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  1378. DSI_CTRL_HW_DBG(ctrl, "Cmd test pattern setup done\n");
  1379. }
  1380. /**
  1381. * test_pattern_enable() - enable test pattern engine
  1382. * @ctrl: Pointer to the controller host hardware.
  1383. * @enable: Enable/Disable test pattern engine.
  1384. */
  1385. void dsi_ctrl_hw_cmn_test_pattern_enable(struct dsi_ctrl_hw *ctrl,
  1386. bool enable)
  1387. {
  1388. u32 reg = DSI_R32(ctrl, DSI_TEST_PATTERN_GEN_CTRL);
  1389. if (enable)
  1390. reg |= BIT(0);
  1391. else
  1392. reg &= ~BIT(0);
  1393. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  1394. DSI_CTRL_HW_DBG(ctrl, "Test pattern enable=%d\n", enable);
  1395. }
  1396. /**
  1397. * trigger_cmd_test_pattern() - trigger a command mode frame update with
  1398. * test pattern
  1399. * @ctrl: Pointer to the controller host hardware.
  1400. * @stream_id: Stream on which frame update is sent.
  1401. */
  1402. void dsi_ctrl_hw_cmn_trigger_cmd_test_pattern(struct dsi_ctrl_hw *ctrl,
  1403. u32 stream_id)
  1404. {
  1405. switch (stream_id) {
  1406. case 0:
  1407. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM0_TRIGGER, 0x1);
  1408. break;
  1409. case 1:
  1410. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM1_TRIGGER, 0x1);
  1411. break;
  1412. case 2:
  1413. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM2_TRIGGER, 0x1);
  1414. break;
  1415. default:
  1416. break;
  1417. }
  1418. DSI_CTRL_HW_DBG(ctrl, "Cmd Test pattern trigger\n");
  1419. }
  1420. void dsi_ctrl_hw_dln0_phy_err(struct dsi_ctrl_hw *ctrl)
  1421. {
  1422. u32 status = 0;
  1423. /*
  1424. * Clear out any phy errors prior to exiting ULPS
  1425. * This fixes certain instances where phy does not exit
  1426. * ULPS cleanly. Also, do not print error during such cases.
  1427. */
  1428. status = DSI_R32(ctrl, DSI_DLN0_PHY_ERR);
  1429. if (status & 0x011111) {
  1430. DSI_W32(ctrl, DSI_DLN0_PHY_ERR, status);
  1431. DSI_CTRL_HW_ERR(ctrl, "phy_err_status = %x\n", status);
  1432. }
  1433. }
  1434. void dsi_ctrl_hw_cmn_phy_reset_config(struct dsi_ctrl_hw *ctrl,
  1435. bool enable)
  1436. {
  1437. u32 reg = 0;
  1438. reg = DSI_MMSS_MISC_R32(ctrl, MMSS_MISC_CLAMP_REG_OFF);
  1439. /* Mask/unmask disable PHY reset bit */
  1440. if (enable)
  1441. reg |= BIT(30);
  1442. else
  1443. reg &= ~BIT(30);
  1444. DSI_MMSS_MISC_W32(ctrl, MMSS_MISC_CLAMP_REG_OFF, reg);
  1445. }
  1446. int dsi_ctrl_hw_cmn_ctrl_reset(struct dsi_ctrl_hw *ctrl,
  1447. int mask)
  1448. {
  1449. int rc = 0;
  1450. u32 data;
  1451. DSI_CTRL_HW_DBG(ctrl, "DSI CTRL and PHY reset, mask=%d\n", mask);
  1452. data = DSI_R32(ctrl, 0x0004);
  1453. /* Disable DSI video mode */
  1454. DSI_W32(ctrl, 0x004, (data & ~BIT(1)));
  1455. wmb(); /* ensure register committed */
  1456. /* Disable DSI controller */
  1457. DSI_W32(ctrl, 0x004, (data & ~(BIT(0) | BIT(1))));
  1458. wmb(); /* ensure register committed */
  1459. /* "Force On" all dynamic clocks */
  1460. DSI_W32(ctrl, 0x11c, 0x100a00);
  1461. /* DSI_SW_RESET */
  1462. DSI_W32(ctrl, 0x118, 0x1);
  1463. wmb(); /* ensure register is committed */
  1464. DSI_W32(ctrl, 0x118, 0x0);
  1465. wmb(); /* ensure register is committed */
  1466. /* Remove "Force On" all dynamic clocks */
  1467. DSI_W32(ctrl, 0x11c, 0x00);
  1468. /* Enable DSI controller */
  1469. DSI_W32(ctrl, 0x004, (data & ~BIT(1)));
  1470. wmb(); /* ensure register committed */
  1471. return rc;
  1472. }
  1473. void dsi_ctrl_hw_cmn_mask_error_intr(struct dsi_ctrl_hw *ctrl, u32 idx, bool en)
  1474. {
  1475. u32 reg = 0;
  1476. u32 fifo_status = 0, timeout_status = 0;
  1477. u32 overflow_clear = BIT(10) | BIT(18) | BIT(22) | BIT(26) | BIT(30);
  1478. u32 underflow_clear = BIT(19) | BIT(23) | BIT(27) | BIT(31);
  1479. u32 lp_rx_clear = BIT(4);
  1480. reg = DSI_R32(ctrl, 0x10c);
  1481. /*
  1482. * Before unmasking we should clear the corresponding error status bits
  1483. * that might have been set while we masked these errors. Since these
  1484. * are sticky bits, these errors will trigger the moment we unmask
  1485. * the error bits.
  1486. */
  1487. if (idx & BIT(DSI_FIFO_OVERFLOW)) {
  1488. if (en) {
  1489. reg |= (0x1f << 16);
  1490. reg |= BIT(9);
  1491. } else {
  1492. reg &= ~(0x1f << 16);
  1493. reg &= ~BIT(9);
  1494. fifo_status = DSI_R32(ctrl, 0x00c);
  1495. DSI_W32(ctrl, 0x00c, fifo_status | overflow_clear);
  1496. }
  1497. }
  1498. if (idx & BIT(DSI_FIFO_UNDERFLOW)) {
  1499. if (en)
  1500. reg |= (0x1b << 26);
  1501. else {
  1502. reg &= ~(0x1b << 26);
  1503. fifo_status = DSI_R32(ctrl, 0x00c);
  1504. DSI_W32(ctrl, 0x00c, fifo_status | underflow_clear);
  1505. }
  1506. }
  1507. if (idx & BIT(DSI_LP_Rx_TIMEOUT)) {
  1508. if (en)
  1509. reg |= (0x7 << 23);
  1510. else {
  1511. reg &= ~(0x7 << 23);
  1512. timeout_status = DSI_R32(ctrl, 0x0c0);
  1513. DSI_W32(ctrl, 0x0c0, timeout_status | lp_rx_clear);
  1514. }
  1515. }
  1516. if (idx & BIT(DSI_PLL_UNLOCK_ERR)) {
  1517. if (en)
  1518. reg |= BIT(28);
  1519. else
  1520. reg &= ~BIT(28);
  1521. }
  1522. DSI_W32(ctrl, 0x10c, reg);
  1523. wmb(); /* ensure error is masked */
  1524. }
  1525. void dsi_ctrl_hw_cmn_error_intr_ctrl(struct dsi_ctrl_hw *ctrl, bool en)
  1526. {
  1527. u32 reg = 0;
  1528. u32 dsi_total_mask = 0x2222AA02;
  1529. reg = DSI_R32(ctrl, 0x110);
  1530. reg &= dsi_total_mask;
  1531. if (en)
  1532. reg |= (BIT(24) | BIT(25));
  1533. else
  1534. reg &= ~BIT(25);
  1535. DSI_W32(ctrl, 0x110, reg);
  1536. wmb(); /* ensure error is masked */
  1537. }
  1538. u32 dsi_ctrl_hw_cmn_get_error_mask(struct dsi_ctrl_hw *ctrl)
  1539. {
  1540. u32 reg = 0;
  1541. reg = DSI_R32(ctrl, 0x10c);
  1542. return reg;
  1543. }
  1544. u32 dsi_ctrl_hw_cmn_get_hw_version(struct dsi_ctrl_hw *ctrl)
  1545. {
  1546. u32 reg = 0;
  1547. reg = DSI_R32(ctrl, 0x0);
  1548. return reg;
  1549. }
  1550. int dsi_ctrl_hw_cmn_wait_for_cmd_mode_mdp_idle(struct dsi_ctrl_hw *ctrl)
  1551. {
  1552. int rc = 0, val = 0;
  1553. u32 cmd_mode_mdp_busy_mask = BIT(2);
  1554. u32 const sleep_us = 2 * 1000;
  1555. u32 const timeout_us = 200 * 1000;
  1556. rc = DSI_READ_POLL_TIMEOUT(ctrl, DSI_STATUS, val,
  1557. !(val & cmd_mode_mdp_busy_mask), sleep_us, timeout_us);
  1558. if (rc)
  1559. DSI_CTRL_HW_ERR(ctrl, "timed out waiting for idle\n");
  1560. return rc;
  1561. }
  1562. void dsi_ctrl_hw_cmn_hs_req_sel(struct dsi_ctrl_hw *ctrl, bool sel_phy)
  1563. {
  1564. u32 reg = 0;
  1565. reg = DSI_R32(ctrl, DSI_LANE_CTRL);
  1566. if (sel_phy)
  1567. reg &= ~BIT(24);
  1568. else
  1569. reg |= BIT(24);
  1570. DSI_W32(ctrl, DSI_LANE_CTRL, reg);
  1571. wmb(); /* make sure request is set */
  1572. }
  1573. void dsi_ctrl_hw_cmn_set_continuous_clk(struct dsi_ctrl_hw *ctrl, bool enable)
  1574. {
  1575. u32 reg = 0;
  1576. reg = DSI_R32(ctrl, DSI_LANE_CTRL);
  1577. if (enable)
  1578. reg |= BIT(28);
  1579. else
  1580. reg &= ~BIT(28);
  1581. DSI_W32(ctrl, DSI_LANE_CTRL, reg);
  1582. wmb(); /* make sure request is set */
  1583. }
  1584. int dsi_ctrl_hw_cmn_wait4dynamic_refresh_done(struct dsi_ctrl_hw *ctrl)
  1585. {
  1586. int rc;
  1587. u32 const sleep_us = 1000;
  1588. u32 const timeout_us = 84000; /* approximately 5 vsyncs */
  1589. u32 reg = 0, dyn_refresh_done = BIT(28);
  1590. rc = DSI_READ_POLL_TIMEOUT(ctrl, DSI_INT_CTRL, reg,
  1591. (reg & dyn_refresh_done), sleep_us, timeout_us);
  1592. if (rc) {
  1593. DSI_CTRL_HW_ERR(ctrl, "wait4dynamic refresh timedout %d\n", rc);
  1594. return rc;
  1595. }
  1596. /* ack dynamic refresh done status */
  1597. reg = DSI_R32(ctrl, DSI_INT_CTRL);
  1598. reg |= dyn_refresh_done;
  1599. DSI_W32(ctrl, DSI_INT_CTRL, reg);
  1600. return 0;
  1601. }
  1602. bool dsi_ctrl_hw_cmn_vid_engine_busy(struct dsi_ctrl_hw *ctrl)
  1603. {
  1604. u32 reg = 0, video_engine_busy = BIT(3);
  1605. int rc;
  1606. u32 const sleep_us = 1000;
  1607. u32 const timeout_us = 50000;
  1608. rc = DSI_READ_POLL_TIMEOUT(ctrl, DSI_STATUS, reg,
  1609. !(reg & video_engine_busy), sleep_us, timeout_us);
  1610. if (rc)
  1611. return true;
  1612. return false;
  1613. }