dsi_ctrl_hw_cmn.c 44 KB

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