dsi_ctrl_hw_cmn.c 52 KB

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