dsi_ctrl_hw_cmn.c 47 KB

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