dsi_ctrl_hw_cmn.c 46 KB

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