dsi_ctrl_hw_cmn.c 47 KB

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