dsi_ctrl_hw_cmn.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950
  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);
  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. /*
  894. * Large read_cnt value can lead to negative repeated_bytes value
  895. * and array out of bounds access of read buffer.
  896. * Avoid this by resetting read_cnt to expected value when panel
  897. * sends more bytes than expected.
  898. */
  899. if (rx_byte == 4 && read_cnt > 4) {
  900. DSI_CTRL_HW_INFO(ctrl,
  901. "Expected %u bytes for short read but received %u bytes\n",
  902. rx_byte, read_cnt);
  903. read_cnt = rx_byte;
  904. } else if (rx_byte == 16 && read_cnt > (pkt_size + 6)) {
  905. DSI_CTRL_HW_INFO(ctrl,
  906. "Expected %u bytes for long read but received %u bytes\n",
  907. pkt_size + 6, read_cnt);
  908. read_cnt = pkt_size + 6;
  909. }
  910. if (read_cnt > 16) {
  911. int bytes_shifted, data_lost = 0, rem_header = 0;
  912. bytes_shifted = read_cnt - rx_byte;
  913. if (bytes_shifted >= 4)
  914. data_lost = bytes_shifted - 4; /* remove DCS header */
  915. else
  916. rem_header = 4 - bytes_shifted; /* remaining header */
  917. repeated_bytes = (read_offset - 4) - data_lost + rem_header;
  918. }
  919. off = DSI_RDBK_DATA0;
  920. off += ((cnt - 1) * 4);
  921. for (i = 0; i < cnt; i++) {
  922. data = DSI_R32(ctrl, off);
  923. if (!repeated_bytes)
  924. *lp++ = ntohl(data);
  925. else
  926. *temp++ = ntohl(data);
  927. off -= 4;
  928. }
  929. if (repeated_bytes) {
  930. for (i = repeated_bytes; i < 16; i++)
  931. rd_buf[j++] = reg[i];
  932. }
  933. *hw_read_cnt = read_cnt;
  934. DSI_CTRL_HW_DBG(ctrl, "Read %d bytes\n", rx_byte);
  935. return rx_byte;
  936. }
  937. /**
  938. * poll_dma_status() - API to poll DMA status
  939. * @ctrl: Pointer to the controller host hardware.
  940. *
  941. * Return: DMA status.
  942. */
  943. u32 dsi_ctrl_hw_cmn_poll_dma_status(struct dsi_ctrl_hw *ctrl)
  944. {
  945. int rc = 0;
  946. u32 status;
  947. u32 const delay_us = 10;
  948. u32 const timeout_us = 5000;
  949. rc = DSI_READ_POLL_TIMEOUT_ATOMIC(ctrl, DSI_INT_CTRL, status,
  950. ((status & DSI_CMD_MODE_DMA_DONE) > 0), delay_us, timeout_us);
  951. if (rc) {
  952. DSI_CTRL_HW_DBG(ctrl, "CMD_MODE_DMA_DONE failed\n");
  953. status = 0;
  954. }
  955. return status;
  956. }
  957. /**
  958. * get_interrupt_status() - returns the interrupt status
  959. * @ctrl: Pointer to the controller host hardware.
  960. *
  961. * Returns the ORed list of interrupts(enum dsi_status_int_type) that
  962. * are active. This list does not include any error interrupts. Caller
  963. * should call get_error_status for error interrupts.
  964. *
  965. * Return: List of active interrupts.
  966. */
  967. u32 dsi_ctrl_hw_cmn_get_interrupt_status(struct dsi_ctrl_hw *ctrl)
  968. {
  969. u32 reg = 0;
  970. u32 ints = 0;
  971. reg = DSI_R32(ctrl, DSI_INT_CTRL);
  972. if (reg & BIT(0))
  973. ints |= DSI_CMD_MODE_DMA_DONE;
  974. if (reg & BIT(8))
  975. ints |= DSI_CMD_FRAME_DONE;
  976. if (reg & BIT(10))
  977. ints |= DSI_CMD_STREAM0_FRAME_DONE;
  978. if (reg & BIT(12))
  979. ints |= DSI_CMD_STREAM1_FRAME_DONE;
  980. if (reg & BIT(14))
  981. ints |= DSI_CMD_STREAM2_FRAME_DONE;
  982. if (reg & BIT(16))
  983. ints |= DSI_VIDEO_MODE_FRAME_DONE;
  984. if (reg & BIT(20))
  985. ints |= DSI_BTA_DONE;
  986. if (reg & BIT(28))
  987. ints |= DSI_DYN_REFRESH_DONE;
  988. if (reg & BIT(30))
  989. ints |= DSI_DESKEW_DONE;
  990. if (reg & BIT(24))
  991. ints |= DSI_ERROR;
  992. DSI_CTRL_HW_DBG(ctrl, "Interrupt status = 0x%x, INT_CTRL=0x%x\n",
  993. ints, reg);
  994. return ints;
  995. }
  996. /**
  997. * clear_interrupt_status() - clears the specified interrupts
  998. * @ctrl: Pointer to the controller host hardware.
  999. * @ints: List of interrupts to be cleared.
  1000. */
  1001. void dsi_ctrl_hw_cmn_clear_interrupt_status(struct dsi_ctrl_hw *ctrl, u32 ints)
  1002. {
  1003. u32 reg = 0;
  1004. reg = DSI_R32(ctrl, DSI_INT_CTRL);
  1005. if (ints & DSI_CMD_MODE_DMA_DONE)
  1006. reg |= BIT(0);
  1007. if (ints & DSI_CMD_FRAME_DONE)
  1008. reg |= BIT(8);
  1009. if (ints & DSI_CMD_STREAM0_FRAME_DONE)
  1010. reg |= BIT(10);
  1011. if (ints & DSI_CMD_STREAM1_FRAME_DONE)
  1012. reg |= BIT(12);
  1013. if (ints & DSI_CMD_STREAM2_FRAME_DONE)
  1014. reg |= BIT(14);
  1015. if (ints & DSI_VIDEO_MODE_FRAME_DONE)
  1016. reg |= BIT(16);
  1017. if (ints & DSI_BTA_DONE)
  1018. reg |= BIT(20);
  1019. if (ints & DSI_DYN_REFRESH_DONE)
  1020. reg |= BIT(28);
  1021. if (ints & DSI_DESKEW_DONE)
  1022. reg |= BIT(30);
  1023. /*
  1024. * Do not clear error status.
  1025. * It will be cleared as part of
  1026. * error handler function.
  1027. */
  1028. reg &= ~BIT(24);
  1029. DSI_W32(ctrl, DSI_INT_CTRL, reg);
  1030. DSI_CTRL_HW_DBG(ctrl, "Clear interrupts, ints = 0x%x, INT_CTRL=0x%x\n",
  1031. ints, reg);
  1032. }
  1033. /**
  1034. * enable_status_interrupts() - enable the specified interrupts
  1035. * @ctrl: Pointer to the controller host hardware.
  1036. * @ints: List of interrupts to be enabled.
  1037. *
  1038. * Enables the specified interrupts. This list will override the
  1039. * previous interrupts enabled through this function. Caller has to
  1040. * maintain the state of the interrupts enabled. To disable all
  1041. * interrupts, set ints to 0.
  1042. */
  1043. void dsi_ctrl_hw_cmn_enable_status_interrupts(
  1044. struct dsi_ctrl_hw *ctrl, u32 ints)
  1045. {
  1046. u32 reg = 0;
  1047. /* Do not change value of DSI_ERROR_MASK bit */
  1048. reg |= (DSI_R32(ctrl, DSI_INT_CTRL) & BIT(25));
  1049. if (ints & DSI_CMD_MODE_DMA_DONE)
  1050. reg |= BIT(1);
  1051. if (ints & DSI_CMD_FRAME_DONE)
  1052. reg |= BIT(9);
  1053. if (ints & DSI_CMD_STREAM0_FRAME_DONE)
  1054. reg |= BIT(11);
  1055. if (ints & DSI_CMD_STREAM1_FRAME_DONE)
  1056. reg |= BIT(13);
  1057. if (ints & DSI_CMD_STREAM2_FRAME_DONE)
  1058. reg |= BIT(15);
  1059. if (ints & DSI_VIDEO_MODE_FRAME_DONE)
  1060. reg |= BIT(17);
  1061. if (ints & DSI_BTA_DONE)
  1062. reg |= BIT(21);
  1063. if (ints & DSI_DYN_REFRESH_DONE)
  1064. reg |= BIT(29);
  1065. if (ints & DSI_DESKEW_DONE)
  1066. reg |= BIT(31);
  1067. DSI_W32(ctrl, DSI_INT_CTRL, reg);
  1068. DSI_CTRL_HW_DBG(ctrl, "Enable interrupts 0x%x, INT_CTRL=0x%x\n", ints,
  1069. reg);
  1070. }
  1071. /**
  1072. * get_error_status() - returns the error status
  1073. * @ctrl: Pointer to the controller host hardware.
  1074. *
  1075. * Returns the ORed list of errors(enum dsi_error_int_type) that are
  1076. * active. This list does not include any status interrupts. Caller
  1077. * should call get_interrupt_status for status interrupts.
  1078. *
  1079. * Return: List of active error interrupts.
  1080. */
  1081. u64 dsi_ctrl_hw_cmn_get_error_status(struct dsi_ctrl_hw *ctrl)
  1082. {
  1083. u32 dln0_phy_err;
  1084. u32 fifo_status;
  1085. u32 ack_error;
  1086. u32 timeout_errors;
  1087. u32 clk_error;
  1088. u32 dsi_status;
  1089. u64 errors = 0, shift = 0x1;
  1090. dln0_phy_err = DSI_R32(ctrl, DSI_DLN0_PHY_ERR);
  1091. if (dln0_phy_err & BIT(0))
  1092. errors |= DSI_DLN0_ESC_ENTRY_ERR;
  1093. if (dln0_phy_err & BIT(4))
  1094. errors |= DSI_DLN0_ESC_SYNC_ERR;
  1095. if (dln0_phy_err & BIT(8))
  1096. errors |= DSI_DLN0_LP_CONTROL_ERR;
  1097. if (dln0_phy_err & BIT(12))
  1098. errors |= DSI_DLN0_LP0_CONTENTION;
  1099. if (dln0_phy_err & BIT(16))
  1100. errors |= DSI_DLN0_LP1_CONTENTION;
  1101. fifo_status = DSI_R32(ctrl, DSI_FIFO_STATUS);
  1102. if (fifo_status & BIT(7))
  1103. errors |= DSI_CMD_MDP_FIFO_UNDERFLOW;
  1104. if (fifo_status & BIT(10))
  1105. errors |= DSI_CMD_DMA_FIFO_UNDERFLOW;
  1106. if (fifo_status & BIT(18))
  1107. errors |= DSI_DLN0_HS_FIFO_OVERFLOW;
  1108. if (fifo_status & BIT(19))
  1109. errors |= DSI_DLN0_HS_FIFO_UNDERFLOW;
  1110. if (fifo_status & BIT(22))
  1111. errors |= DSI_DLN1_HS_FIFO_OVERFLOW;
  1112. if (fifo_status & BIT(23))
  1113. errors |= DSI_DLN1_HS_FIFO_UNDERFLOW;
  1114. if (fifo_status & BIT(26))
  1115. errors |= DSI_DLN2_HS_FIFO_OVERFLOW;
  1116. if (fifo_status & BIT(27))
  1117. errors |= DSI_DLN2_HS_FIFO_UNDERFLOW;
  1118. if (fifo_status & BIT(30))
  1119. errors |= DSI_DLN3_HS_FIFO_OVERFLOW;
  1120. if (fifo_status & BIT(31))
  1121. errors |= DSI_DLN3_HS_FIFO_UNDERFLOW;
  1122. ack_error = DSI_R32(ctrl, DSI_ACK_ERR_STATUS);
  1123. if (ack_error & BIT(16))
  1124. errors |= DSI_RDBK_SINGLE_ECC_ERR;
  1125. if (ack_error & BIT(17))
  1126. errors |= DSI_RDBK_MULTI_ECC_ERR;
  1127. if (ack_error & BIT(20))
  1128. errors |= DSI_RDBK_CRC_ERR;
  1129. if (ack_error & BIT(23))
  1130. errors |= DSI_RDBK_INCOMPLETE_PKT;
  1131. if (ack_error & BIT(24))
  1132. errors |= DSI_PERIPH_ERROR_PKT;
  1133. if (ack_error & BIT(15))
  1134. errors |= (shift << DSI_EINT_PANEL_SPECIFIC_ERR);
  1135. timeout_errors = DSI_R32(ctrl, DSI_TIMEOUT_STATUS);
  1136. if (timeout_errors & BIT(0))
  1137. errors |= DSI_HS_TX_TIMEOUT;
  1138. if (timeout_errors & BIT(4))
  1139. errors |= DSI_LP_RX_TIMEOUT;
  1140. if (timeout_errors & BIT(8))
  1141. errors |= DSI_BTA_TIMEOUT;
  1142. clk_error = DSI_R32(ctrl, DSI_CLK_STATUS);
  1143. if (clk_error & BIT(16))
  1144. errors |= DSI_PLL_UNLOCK;
  1145. dsi_status = DSI_R32(ctrl, DSI_STATUS);
  1146. if (dsi_status & BIT(31))
  1147. errors |= DSI_INTERLEAVE_OP_CONTENTION;
  1148. DSI_CTRL_HW_DBG(ctrl, "Error status = 0x%llx, phy=0x%x, fifo=0x%x\n",
  1149. errors, dln0_phy_err, fifo_status);
  1150. DSI_CTRL_HW_DBG(ctrl, "ack=0x%x, timeout=0x%x, clk=0x%x, dsi=0x%x\n",
  1151. ack_error, timeout_errors, clk_error, dsi_status);
  1152. return errors;
  1153. }
  1154. /**
  1155. * clear_error_status() - clears the specified errors
  1156. * @ctrl: Pointer to the controller host hardware.
  1157. * @errors: List of errors to be cleared.
  1158. */
  1159. void dsi_ctrl_hw_cmn_clear_error_status(struct dsi_ctrl_hw *ctrl, u64 errors)
  1160. {
  1161. u32 dln0_phy_err = 0;
  1162. u32 fifo_status = 0;
  1163. u32 ack_error = 0;
  1164. u32 timeout_error = 0;
  1165. u32 clk_error = 0;
  1166. u32 dsi_status = 0;
  1167. if (errors & DSI_RDBK_SINGLE_ECC_ERR)
  1168. ack_error |= BIT(16);
  1169. if (errors & DSI_RDBK_MULTI_ECC_ERR)
  1170. ack_error |= BIT(17);
  1171. if (errors & DSI_RDBK_CRC_ERR)
  1172. ack_error |= BIT(20);
  1173. if (errors & DSI_RDBK_INCOMPLETE_PKT)
  1174. ack_error |= BIT(23);
  1175. if (errors & DSI_PERIPH_ERROR_PKT)
  1176. ack_error |= BIT(24);
  1177. if (errors & DSI_PANEL_SPECIFIC_ERR)
  1178. ack_error |= BIT(15);
  1179. if (errors & DSI_LP_RX_TIMEOUT)
  1180. timeout_error |= BIT(4);
  1181. if (errors & DSI_HS_TX_TIMEOUT)
  1182. timeout_error |= BIT(0);
  1183. if (errors & DSI_BTA_TIMEOUT)
  1184. timeout_error |= BIT(8);
  1185. if (errors & DSI_PLL_UNLOCK)
  1186. clk_error |= BIT(16);
  1187. if (errors & DSI_DLN0_LP0_CONTENTION)
  1188. dln0_phy_err |= BIT(12);
  1189. if (errors & DSI_DLN0_LP1_CONTENTION)
  1190. dln0_phy_err |= BIT(16);
  1191. if (errors & DSI_DLN0_ESC_ENTRY_ERR)
  1192. dln0_phy_err |= BIT(0);
  1193. if (errors & DSI_DLN0_ESC_SYNC_ERR)
  1194. dln0_phy_err |= BIT(4);
  1195. if (errors & DSI_DLN0_LP_CONTROL_ERR)
  1196. dln0_phy_err |= BIT(8);
  1197. if (errors & DSI_CMD_DMA_FIFO_UNDERFLOW)
  1198. fifo_status |= BIT(10);
  1199. if (errors & DSI_CMD_MDP_FIFO_UNDERFLOW)
  1200. fifo_status |= BIT(7);
  1201. if (errors & DSI_DLN0_HS_FIFO_OVERFLOW)
  1202. fifo_status |= BIT(18);
  1203. if (errors & DSI_DLN1_HS_FIFO_OVERFLOW)
  1204. fifo_status |= BIT(22);
  1205. if (errors & DSI_DLN2_HS_FIFO_OVERFLOW)
  1206. fifo_status |= BIT(26);
  1207. if (errors & DSI_DLN3_HS_FIFO_OVERFLOW)
  1208. fifo_status |= BIT(30);
  1209. if (errors & DSI_DLN0_HS_FIFO_UNDERFLOW)
  1210. fifo_status |= BIT(19);
  1211. if (errors & DSI_DLN1_HS_FIFO_UNDERFLOW)
  1212. fifo_status |= BIT(23);
  1213. if (errors & DSI_DLN2_HS_FIFO_UNDERFLOW)
  1214. fifo_status |= BIT(27);
  1215. if (errors & DSI_DLN3_HS_FIFO_UNDERFLOW)
  1216. fifo_status |= BIT(31);
  1217. if (errors & DSI_INTERLEAVE_OP_CONTENTION)
  1218. dsi_status |= BIT(31);
  1219. DSI_W32(ctrl, DSI_DLN0_PHY_ERR, dln0_phy_err);
  1220. DSI_W32(ctrl, DSI_FIFO_STATUS, fifo_status);
  1221. /* Writing of an extra 0 is needed to clear ack error bits */
  1222. DSI_W32(ctrl, DSI_ACK_ERR_STATUS, ack_error);
  1223. wmb(); /* make sure register is committed */
  1224. DSI_W32(ctrl, DSI_ACK_ERR_STATUS, 0x0);
  1225. DSI_W32(ctrl, DSI_TIMEOUT_STATUS, timeout_error);
  1226. DSI_W32(ctrl, DSI_CLK_STATUS, clk_error);
  1227. DSI_W32(ctrl, DSI_STATUS, dsi_status);
  1228. DSI_CTRL_HW_DBG(ctrl, "clear errors = 0x%llx, phy=0x%x, fifo=0x%x\n",
  1229. errors, dln0_phy_err, fifo_status);
  1230. DSI_CTRL_HW_DBG(ctrl, "ack=0x%x, timeout=0x%x, clk=0x%x, dsi=0x%x\n",
  1231. ack_error, timeout_error, clk_error, dsi_status);
  1232. }
  1233. /**
  1234. * enable_error_interrupts() - enable the specified interrupts
  1235. * @ctrl: Pointer to the controller host hardware.
  1236. * @errors: List of errors to be enabled.
  1237. *
  1238. * Enables the specified interrupts. This list will override the
  1239. * previous interrupts enabled through this function. Caller has to
  1240. * maintain the state of the interrupts enabled. To disable all
  1241. * interrupts, set errors to 0.
  1242. */
  1243. void dsi_ctrl_hw_cmn_enable_error_interrupts(struct dsi_ctrl_hw *ctrl,
  1244. u64 errors)
  1245. {
  1246. u32 int_ctrl = 0;
  1247. u32 int_mask0 = 0x7FFF3BFF;
  1248. u32 dln0_phy_err = 0x11111;
  1249. u32 fifo_status = 0xCCCC0789;
  1250. u32 ack_error = 0x1193BFFF;
  1251. u32 timeout_status = 0x11111111;
  1252. u32 clk_status = 0x10000;
  1253. u32 dsi_status_error = 0x80000000;
  1254. u32 reg = 0;
  1255. DSI_W32(ctrl, DSI_DLN0_PHY_ERR, dln0_phy_err);
  1256. DSI_W32(ctrl, DSI_FIFO_STATUS, fifo_status);
  1257. DSI_W32(ctrl, DSI_TIMEOUT_STATUS, timeout_status);
  1258. DSI_W32(ctrl, DSI_ACK_ERR_STATUS, ack_error);
  1259. reg = DSI_R32(ctrl, DSI_CLK_STATUS);
  1260. DSI_W32(ctrl, DSI_CLK_STATUS, reg | clk_status);
  1261. reg = DSI_R32(ctrl, DSI_STATUS);
  1262. DSI_W32(ctrl, DSI_STATUS, reg | dsi_status_error);
  1263. int_ctrl = DSI_R32(ctrl, DSI_INT_CTRL);
  1264. if (errors)
  1265. int_ctrl |= BIT(25);
  1266. else
  1267. int_ctrl &= ~BIT(25);
  1268. if (ctrl->phy_pll_bypass) {
  1269. int_ctrl &= ~BIT(25);
  1270. goto dsi_write;
  1271. }
  1272. /* Do not clear interrupt status */
  1273. int_ctrl &= 0xAAEEAAFE;
  1274. if (errors & DSI_RDBK_SINGLE_ECC_ERR)
  1275. int_mask0 &= ~BIT(0);
  1276. if (errors & DSI_RDBK_MULTI_ECC_ERR)
  1277. int_mask0 &= ~BIT(1);
  1278. if (errors & DSI_RDBK_CRC_ERR)
  1279. int_mask0 &= ~BIT(2);
  1280. if (errors & DSI_RDBK_INCOMPLETE_PKT)
  1281. int_mask0 &= ~BIT(3);
  1282. if (errors & DSI_PERIPH_ERROR_PKT)
  1283. int_mask0 &= ~BIT(4);
  1284. if (errors & DSI_LP_RX_TIMEOUT)
  1285. int_mask0 &= ~BIT(5);
  1286. if (errors & DSI_HS_TX_TIMEOUT)
  1287. int_mask0 &= ~BIT(6);
  1288. if (errors & DSI_BTA_TIMEOUT)
  1289. int_mask0 &= ~BIT(7);
  1290. if (errors & DSI_PLL_UNLOCK)
  1291. int_mask0 &= ~BIT(28);
  1292. if (errors & DSI_DLN0_LP0_CONTENTION)
  1293. int_mask0 &= ~BIT(24);
  1294. if (errors & DSI_DLN0_LP1_CONTENTION)
  1295. int_mask0 &= ~BIT(25);
  1296. if (errors & DSI_DLN0_ESC_ENTRY_ERR)
  1297. int_mask0 &= ~BIT(21);
  1298. if (errors & DSI_DLN0_ESC_SYNC_ERR)
  1299. int_mask0 &= ~BIT(22);
  1300. if (errors & DSI_DLN0_LP_CONTROL_ERR)
  1301. int_mask0 &= ~BIT(23);
  1302. if (errors & DSI_CMD_DMA_FIFO_UNDERFLOW)
  1303. int_mask0 &= ~BIT(9);
  1304. if (errors & DSI_CMD_MDP_FIFO_UNDERFLOW)
  1305. int_mask0 &= ~BIT(11);
  1306. if (errors & DSI_DLN0_HS_FIFO_OVERFLOW)
  1307. int_mask0 &= ~BIT(16);
  1308. if (errors & DSI_DLN1_HS_FIFO_OVERFLOW)
  1309. int_mask0 &= ~BIT(17);
  1310. if (errors & DSI_DLN2_HS_FIFO_OVERFLOW)
  1311. int_mask0 &= ~BIT(18);
  1312. if (errors & DSI_DLN3_HS_FIFO_OVERFLOW)
  1313. int_mask0 &= ~BIT(19);
  1314. if (errors & DSI_DLN0_HS_FIFO_UNDERFLOW)
  1315. int_mask0 &= ~BIT(26);
  1316. if (errors & DSI_DLN1_HS_FIFO_UNDERFLOW)
  1317. int_mask0 &= ~BIT(27);
  1318. if (errors & DSI_DLN2_HS_FIFO_UNDERFLOW)
  1319. int_mask0 &= ~BIT(29);
  1320. if (errors & DSI_DLN3_HS_FIFO_UNDERFLOW)
  1321. int_mask0 &= ~BIT(30);
  1322. if (errors & DSI_INTERLEAVE_OP_CONTENTION)
  1323. int_mask0 &= ~BIT(8);
  1324. dsi_write:
  1325. DSI_W32(ctrl, DSI_INT_CTRL, int_ctrl);
  1326. DSI_W32(ctrl, DSI_ERR_INT_MASK0, int_mask0);
  1327. DSI_CTRL_HW_DBG(ctrl, "[DSI_%d] enable errors = 0x%llx, int_mask0=0x%x\n",
  1328. ctrl->index, errors, int_mask0);
  1329. }
  1330. /**
  1331. * video_test_pattern_setup() - setup test pattern engine for video mode
  1332. * @ctrl: Pointer to the controller host hardware.
  1333. * @type: Type of test pattern.
  1334. * @init_val: Initial value to use for generating test pattern.
  1335. */
  1336. void dsi_ctrl_hw_cmn_video_test_pattern_setup(struct dsi_ctrl_hw *ctrl,
  1337. enum dsi_test_pattern type,
  1338. u32 init_val)
  1339. {
  1340. u32 reg = 0, pattern_sel_shift = 4;
  1341. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_VIDEO_INIT_VAL, init_val);
  1342. switch (type) {
  1343. case DSI_TEST_PATTERN_FIXED:
  1344. reg |= (0x2 << pattern_sel_shift);
  1345. break;
  1346. case DSI_TEST_PATTERN_INC:
  1347. reg |= (0x1 << pattern_sel_shift);
  1348. break;
  1349. case DSI_TEST_PATTERN_POLY:
  1350. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_VIDEO_POLY, 0xF0F0F);
  1351. break;
  1352. case DSI_TEST_PATTERN_GENERAL:
  1353. reg |= (0x3 << pattern_sel_shift);
  1354. break;
  1355. default:
  1356. break;
  1357. }
  1358. DSI_W32(ctrl, DSI_TPG_MAIN_CONTROL, 0x100);
  1359. DSI_W32(ctrl, DSI_TPG_VIDEO_CONFIG, 0x5);
  1360. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  1361. DSI_CTRL_HW_DBG(ctrl, "Video test pattern setup done\n");
  1362. }
  1363. /**
  1364. * cmd_test_pattern_setup() - setup test patttern engine for cmd mode
  1365. * @ctrl: Pointer to the controller host hardware.
  1366. * @type: Type of test pattern.
  1367. * @init_val: Initial value to use for generating test pattern.
  1368. * @stream_id: Stream Id on which packets are generated.
  1369. */
  1370. void dsi_ctrl_hw_cmn_cmd_test_pattern_setup(struct dsi_ctrl_hw *ctrl,
  1371. enum dsi_test_pattern type,
  1372. u32 init_val,
  1373. u32 stream_id)
  1374. {
  1375. u32 reg = 0;
  1376. u32 init_offset;
  1377. u32 poly_offset;
  1378. u32 pattern_sel_shift;
  1379. switch (stream_id) {
  1380. case 0:
  1381. init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL0;
  1382. poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM0_POLY;
  1383. pattern_sel_shift = 8;
  1384. break;
  1385. case 1:
  1386. init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL1;
  1387. poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM1_POLY;
  1388. pattern_sel_shift = 12;
  1389. break;
  1390. case 2:
  1391. init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL2;
  1392. poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM2_POLY;
  1393. pattern_sel_shift = 20;
  1394. break;
  1395. default:
  1396. return;
  1397. }
  1398. DSI_W32(ctrl, init_offset, init_val);
  1399. switch (type) {
  1400. case DSI_TEST_PATTERN_FIXED:
  1401. reg |= (0x2 << pattern_sel_shift);
  1402. break;
  1403. case DSI_TEST_PATTERN_INC:
  1404. reg |= (0x1 << pattern_sel_shift);
  1405. break;
  1406. case DSI_TEST_PATTERN_POLY:
  1407. DSI_W32(ctrl, poly_offset, 0xF0F0F);
  1408. break;
  1409. case DSI_TEST_PATTERN_GENERAL:
  1410. reg |= (0x3 << pattern_sel_shift);
  1411. break;
  1412. default:
  1413. break;
  1414. }
  1415. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  1416. DSI_CTRL_HW_DBG(ctrl, "Cmd test pattern setup done\n");
  1417. }
  1418. /**
  1419. * test_pattern_enable() - enable test pattern engine
  1420. * @ctrl: Pointer to the controller host hardware.
  1421. * @enable: Enable/Disable test pattern engine.
  1422. * @pattern: Type of TPG pattern
  1423. * @panel_mode: DSI operation mode
  1424. */
  1425. void dsi_ctrl_hw_cmn_test_pattern_enable(struct dsi_ctrl_hw *ctrl,
  1426. bool enable, enum dsi_ctrl_tpg_pattern pattern,
  1427. enum dsi_op_mode panel_mode)
  1428. {
  1429. u32 reg = DSI_R32(ctrl, DSI_TEST_PATTERN_GEN_CTRL);
  1430. u32 reg_tpg_main_control = 0;
  1431. u32 reg_tpg_video_config = BIT(0);
  1432. reg_tpg_video_config |= BIT(2);
  1433. if (panel_mode == DSI_OP_CMD_MODE) {
  1434. reg_tpg_main_control = BIT(pattern);
  1435. DSI_W32(ctrl, DSI_TPG_MAIN_CONTROL2, reg_tpg_main_control);
  1436. } else {
  1437. reg_tpg_main_control = BIT(pattern + 1);
  1438. DSI_W32(ctrl, DSI_TPG_MAIN_CONTROL, reg_tpg_main_control);
  1439. }
  1440. DSI_W32(ctrl, DSI_TPG_VIDEO_CONFIG, reg_tpg_video_config);
  1441. if (enable)
  1442. reg |= BIT(0);
  1443. else
  1444. reg &= ~BIT(0);
  1445. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg);
  1446. DSI_CTRL_HW_DBG(ctrl, "Test pattern enable=%d\n", enable);
  1447. }
  1448. /**
  1449. * trigger_cmd_test_pattern() - trigger a command mode frame update with
  1450. * test pattern
  1451. * @ctrl: Pointer to the controller host hardware.
  1452. * @stream_id: Stream on which frame update is sent.
  1453. */
  1454. void dsi_ctrl_hw_cmn_trigger_cmd_test_pattern(struct dsi_ctrl_hw *ctrl,
  1455. u32 stream_id)
  1456. {
  1457. switch (stream_id) {
  1458. case 0:
  1459. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM0_TRIGGER, 0x1);
  1460. break;
  1461. case 1:
  1462. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM1_TRIGGER, 0x1);
  1463. break;
  1464. case 2:
  1465. DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM2_TRIGGER, 0x1);
  1466. break;
  1467. default:
  1468. break;
  1469. }
  1470. DSI_CTRL_HW_DBG(ctrl, "Cmd Test pattern trigger\n");
  1471. }
  1472. void dsi_ctrl_hw_dln0_phy_err(struct dsi_ctrl_hw *ctrl)
  1473. {
  1474. u32 status = 0;
  1475. /*
  1476. * Clear out any phy errors prior to exiting ULPS
  1477. * This fixes certain instances where phy does not exit
  1478. * ULPS cleanly. Also, do not print error during such cases.
  1479. */
  1480. status = DSI_R32(ctrl, DSI_DLN0_PHY_ERR);
  1481. if (status & 0x011111) {
  1482. DSI_W32(ctrl, DSI_DLN0_PHY_ERR, status);
  1483. DSI_CTRL_HW_ERR(ctrl, "phy_err_status = %x\n", status);
  1484. }
  1485. }
  1486. void dsi_ctrl_hw_cmn_phy_reset_config(struct dsi_ctrl_hw *ctrl,
  1487. bool enable)
  1488. {
  1489. u32 reg = 0;
  1490. reg = DSI_MMSS_MISC_R32(ctrl, MMSS_MISC_CLAMP_REG_OFF);
  1491. /* Mask/unmask disable PHY reset bit */
  1492. if (enable)
  1493. reg |= BIT(30);
  1494. else
  1495. reg &= ~BIT(30);
  1496. DSI_MMSS_MISC_W32(ctrl, MMSS_MISC_CLAMP_REG_OFF, reg);
  1497. }
  1498. int dsi_ctrl_hw_cmn_ctrl_reset(struct dsi_ctrl_hw *ctrl,
  1499. int mask)
  1500. {
  1501. int rc = 0;
  1502. u32 data;
  1503. DSI_CTRL_HW_DBG(ctrl, "DSI CTRL and PHY reset, mask=%d\n", mask);
  1504. data = DSI_R32(ctrl, 0x0004);
  1505. /* Disable DSI video mode */
  1506. DSI_W32(ctrl, 0x004, (data & ~BIT(1)));
  1507. wmb(); /* ensure register committed */
  1508. /* Disable DSI controller */
  1509. DSI_W32(ctrl, 0x004, (data & ~(BIT(0) | BIT(1))));
  1510. wmb(); /* ensure register committed */
  1511. /* "Force On" all dynamic clocks */
  1512. DSI_W32(ctrl, 0x11c, 0x100a00);
  1513. /* DSI_SW_RESET */
  1514. DSI_W32(ctrl, 0x118, 0x1);
  1515. wmb(); /* ensure register is committed */
  1516. DSI_W32(ctrl, 0x118, 0x0);
  1517. wmb(); /* ensure register is committed */
  1518. /* Remove "Force On" all dynamic clocks */
  1519. DSI_W32(ctrl, 0x11c, 0x00);
  1520. /* Enable DSI controller */
  1521. DSI_W32(ctrl, 0x004, (data & ~BIT(1)));
  1522. wmb(); /* ensure register committed */
  1523. return rc;
  1524. }
  1525. void dsi_ctrl_hw_cmn_mask_error_intr(struct dsi_ctrl_hw *ctrl, u32 idx, bool en)
  1526. {
  1527. u32 reg = 0;
  1528. u32 fifo_status = 0, timeout_status = 0;
  1529. u32 overflow_clear = BIT(10) | BIT(18) | BIT(22) | BIT(26) | BIT(30);
  1530. u32 underflow_clear = BIT(19) | BIT(23) | BIT(27) | BIT(31);
  1531. u32 lp_rx_clear = BIT(4);
  1532. reg = DSI_R32(ctrl, 0x10c);
  1533. /*
  1534. * Before unmasking we should clear the corresponding error status bits
  1535. * that might have been set while we masked these errors. Since these
  1536. * are sticky bits, these errors will trigger the moment we unmask
  1537. * the error bits.
  1538. */
  1539. if (idx & BIT(DSI_FIFO_OVERFLOW)) {
  1540. if (en) {
  1541. reg |= (0x1f << 16);
  1542. reg |= BIT(9);
  1543. } else {
  1544. reg &= ~(0x1f << 16);
  1545. reg &= ~BIT(9);
  1546. fifo_status = DSI_R32(ctrl, 0x00c);
  1547. DSI_W32(ctrl, 0x00c, fifo_status | overflow_clear);
  1548. }
  1549. }
  1550. if (idx & BIT(DSI_FIFO_UNDERFLOW)) {
  1551. if (en)
  1552. reg |= (0x1b << 26);
  1553. else {
  1554. reg &= ~(0x1b << 26);
  1555. fifo_status = DSI_R32(ctrl, 0x00c);
  1556. DSI_W32(ctrl, 0x00c, fifo_status | underflow_clear);
  1557. }
  1558. }
  1559. if (idx & BIT(DSI_LP_Rx_TIMEOUT)) {
  1560. if (en)
  1561. reg |= (0x7 << 23);
  1562. else {
  1563. reg &= ~(0x7 << 23);
  1564. timeout_status = DSI_R32(ctrl, 0x0c0);
  1565. DSI_W32(ctrl, 0x0c0, timeout_status | lp_rx_clear);
  1566. }
  1567. }
  1568. if (idx & BIT(DSI_PLL_UNLOCK_ERR)) {
  1569. if (en)
  1570. reg |= BIT(28);
  1571. else
  1572. reg &= ~BIT(28);
  1573. }
  1574. DSI_W32(ctrl, 0x10c, reg);
  1575. wmb(); /* ensure error is masked */
  1576. }
  1577. void dsi_ctrl_hw_cmn_error_intr_ctrl(struct dsi_ctrl_hw *ctrl, bool en)
  1578. {
  1579. u32 reg = 0;
  1580. u32 dsi_total_mask = 0x2222AA02;
  1581. reg = DSI_R32(ctrl, 0x110);
  1582. reg &= dsi_total_mask;
  1583. if (en)
  1584. reg |= (BIT(24) | BIT(25));
  1585. else
  1586. reg &= ~BIT(25);
  1587. DSI_W32(ctrl, 0x110, reg);
  1588. wmb(); /* ensure error is masked */
  1589. }
  1590. u32 dsi_ctrl_hw_cmn_get_error_mask(struct dsi_ctrl_hw *ctrl)
  1591. {
  1592. u32 reg = 0;
  1593. reg = DSI_R32(ctrl, 0x10c);
  1594. return reg;
  1595. }
  1596. u32 dsi_ctrl_hw_cmn_get_hw_version(struct dsi_ctrl_hw *ctrl)
  1597. {
  1598. u32 reg = 0;
  1599. reg = DSI_R32(ctrl, 0x0);
  1600. return reg;
  1601. }
  1602. int dsi_ctrl_hw_cmn_wait_for_cmd_mode_mdp_idle(struct dsi_ctrl_hw *ctrl)
  1603. {
  1604. int rc = 0, val = 0;
  1605. u32 cmd_mode_mdp_busy_mask = BIT(2);
  1606. u32 const sleep_us = 2 * 1000;
  1607. u32 const timeout_us = 200 * 1000;
  1608. rc = DSI_READ_POLL_TIMEOUT(ctrl, DSI_STATUS, val,
  1609. !(val & cmd_mode_mdp_busy_mask), sleep_us, timeout_us);
  1610. if (rc)
  1611. DSI_CTRL_HW_ERR(ctrl, "timed out waiting for idle\n");
  1612. return rc;
  1613. }
  1614. void dsi_ctrl_hw_cmn_hs_req_sel(struct dsi_ctrl_hw *ctrl, bool sel_phy)
  1615. {
  1616. u32 reg = 0;
  1617. reg = DSI_R32(ctrl, DSI_LANE_CTRL);
  1618. if (sel_phy)
  1619. reg &= ~BIT(24);
  1620. else
  1621. reg |= BIT(24);
  1622. DSI_W32(ctrl, DSI_LANE_CTRL, reg);
  1623. wmb(); /* make sure request is set */
  1624. }
  1625. void dsi_ctrl_hw_cmn_set_continuous_clk(struct dsi_ctrl_hw *ctrl, bool enable)
  1626. {
  1627. u32 reg = 0;
  1628. reg = DSI_R32(ctrl, DSI_LANE_CTRL);
  1629. if (enable)
  1630. reg |= BIT(28);
  1631. else
  1632. reg &= ~BIT(28);
  1633. DSI_W32(ctrl, DSI_LANE_CTRL, reg);
  1634. wmb(); /* make sure request is set */
  1635. }
  1636. int dsi_ctrl_hw_cmn_wait4dynamic_refresh_done(struct dsi_ctrl_hw *ctrl)
  1637. {
  1638. int rc;
  1639. u32 const sleep_us = 1000;
  1640. u32 const timeout_us = 84000; /* approximately 5 vsyncs */
  1641. u32 reg = 0, dyn_refresh_done = BIT(28);
  1642. rc = DSI_READ_POLL_TIMEOUT(ctrl, DSI_INT_CTRL, reg,
  1643. (reg & dyn_refresh_done), sleep_us, timeout_us);
  1644. if (rc) {
  1645. DSI_CTRL_HW_ERR(ctrl, "wait4dynamic refresh timedout %d\n", rc);
  1646. return rc;
  1647. }
  1648. /* ack dynamic refresh done status */
  1649. reg = DSI_R32(ctrl, DSI_INT_CTRL);
  1650. reg |= dyn_refresh_done;
  1651. DSI_W32(ctrl, DSI_INT_CTRL, reg);
  1652. return 0;
  1653. }
  1654. bool dsi_ctrl_hw_cmn_vid_engine_busy(struct dsi_ctrl_hw *ctrl)
  1655. {
  1656. u32 reg = 0, video_engine_busy = BIT(3);
  1657. int rc;
  1658. u32 const sleep_us = 1000;
  1659. u32 const timeout_us = 50000;
  1660. rc = DSI_READ_POLL_TIMEOUT(ctrl, DSI_STATUS, reg,
  1661. !(reg & video_engine_busy), sleep_us, timeout_us);
  1662. if (rc)
  1663. return true;
  1664. return false;
  1665. }
  1666. void dsi_ctrl_hw_cmn_init_cmddma_trig_ctrl(struct dsi_ctrl_hw *ctrl,
  1667. struct dsi_host_common_cfg *cfg)
  1668. {
  1669. u32 reg;
  1670. const u8 trigger_map[DSI_TRIGGER_MAX] = {
  1671. 0x0, 0x2, 0x1, 0x4, 0x5, 0x6 };
  1672. /* Initialize the default trigger used for Command Mode DMA path. */
  1673. reg = DSI_R32(ctrl, DSI_TRIG_CTRL);
  1674. reg &= ~BIT(16); /* Reset DMA_TRG_MUX */
  1675. reg &= ~(0xF); /* Reset DMA_TRIGGER_SEL */
  1676. reg |= (trigger_map[cfg->dma_cmd_trigger] & 0xF);
  1677. DSI_W32(ctrl, DSI_TRIG_CTRL, reg);
  1678. }