dsi_ctrl_hw_cmn.c 46 KB

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