sde_hw_intf.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
  7. #include <linux/iopoll.h>
  8. #include "sde_hwio.h"
  9. #include "sde_hw_catalog.h"
  10. #include "sde_hw_intf.h"
  11. #include "sde_dbg.h"
  12. #define INTF_TIMING_ENGINE_EN 0x000
  13. #define INTF_CONFIG 0x004
  14. #define INTF_HSYNC_CTL 0x008
  15. #define INTF_VSYNC_PERIOD_F0 0x00C
  16. #define INTF_VSYNC_PERIOD_F1 0x010
  17. #define INTF_VSYNC_PULSE_WIDTH_F0 0x014
  18. #define INTF_VSYNC_PULSE_WIDTH_F1 0x018
  19. #define INTF_DISPLAY_V_START_F0 0x01C
  20. #define INTF_DISPLAY_V_START_F1 0x020
  21. #define INTF_DISPLAY_V_END_F0 0x024
  22. #define INTF_DISPLAY_V_END_F1 0x028
  23. #define INTF_ACTIVE_V_START_F0 0x02C
  24. #define INTF_ACTIVE_V_START_F1 0x030
  25. #define INTF_ACTIVE_V_END_F0 0x034
  26. #define INTF_ACTIVE_V_END_F1 0x038
  27. #define INTF_DISPLAY_HCTL 0x03C
  28. #define INTF_ACTIVE_HCTL 0x040
  29. #define INTF_BORDER_COLOR 0x044
  30. #define INTF_UNDERFLOW_COLOR 0x048
  31. #define INTF_HSYNC_SKEW 0x04C
  32. #define INTF_POLARITY_CTL 0x050
  33. #define INTF_TEST_CTL 0x054
  34. #define INTF_TP_COLOR0 0x058
  35. #define INTF_TP_COLOR1 0x05C
  36. #define INTF_CONFIG2 0x060
  37. #define INTF_DISPLAY_DATA_HCTL 0x064
  38. #define INTF_ACTIVE_DATA_HCTL 0x068
  39. #define INTF_FRAME_LINE_COUNT_EN 0x0A8
  40. #define INTF_MDP_FRAME_COUNT 0x0A4
  41. #define INTF_FRAME_COUNT 0x0AC
  42. #define INTF_LINE_COUNT 0x0B0
  43. #define INTF_DEFLICKER_CONFIG 0x0F0
  44. #define INTF_DEFLICKER_STRNG_COEFF 0x0F4
  45. #define INTF_DEFLICKER_WEAK_COEFF 0x0F8
  46. #define INTF_REG_SPLIT_LINK 0x080
  47. #define INTF_DSI_CMD_MODE_TRIGGER_EN 0x084
  48. #define INTF_PANEL_FORMAT 0x090
  49. #define INTF_TPG_ENABLE 0x100
  50. #define INTF_TPG_MAIN_CONTROL 0x104
  51. #define INTF_TPG_VIDEO_CONFIG 0x108
  52. #define INTF_TPG_COMPONENT_LIMITS 0x10C
  53. #define INTF_TPG_RECTANGLE 0x110
  54. #define INTF_TPG_INITIAL_VALUE 0x114
  55. #define INTF_TPG_BLK_WHITE_PATTERN_FRAMES 0x118
  56. #define INTF_TPG_RGB_MAPPING 0x11C
  57. #define INTF_PROG_FETCH_START 0x170
  58. #define INTF_PROG_ROT_START 0x174
  59. #define INTF_MISR_CTRL 0x180
  60. #define INTF_MISR_SIGNATURE 0x184
  61. #define INTF_WD_TIMER_0_LTJ_CTL 0x200
  62. #define INTF_WD_TIMER_0_LTJ_CTL1 0x204
  63. #define INTF_VSYNC_TIMESTAMP_CTRL 0x210
  64. #define INTF_VSYNC_TIMESTAMP0 0x214
  65. #define INTF_VSYNC_TIMESTAMP1 0x218
  66. #define INTF_MDP_VSYNC_TIMESTAMP0 0x21C
  67. #define INTF_MDP_VSYNC_TIMESTAMP1 0x220
  68. #define INTF_WD_TIMER_0_JITTER_CTL 0x224
  69. #define INTF_WD_TIMER_0_LTJ_SLOPE 0x228
  70. #define INTF_WD_TIMER_0_LTJ_MAX 0x22C
  71. #define INTF_WD_TIMER_0_CTL 0x230
  72. #define INTF_WD_TIMER_0_CTL2 0x234
  73. #define INTF_WD_TIMER_0_LOAD_VALUE 0x238
  74. #define INTF_WD_TIMER_0_LTJ_INT_STATUS 0x240
  75. #define INTF_WD_TIMER_0_LTJ_FRAC_STATUS 0x244
  76. #define INTF_MUX 0x25C
  77. #define INTF_UNDERRUN_COUNT 0x268
  78. #define INTF_STATUS 0x26C
  79. #define INTF_AVR_CONTROL 0x270
  80. #define INTF_AVR_MODE 0x274
  81. #define INTF_AVR_TRIGGER 0x278
  82. #define INTF_AVR_VTOTAL 0x27C
  83. #define INTF_TEAR_MDP_VSYNC_SEL 0x280
  84. #define INTF_TEAR_TEAR_CHECK_EN 0x284
  85. #define INTF_TEAR_SYNC_CONFIG_VSYNC 0x288
  86. #define INTF_TEAR_SYNC_CONFIG_HEIGHT 0x28C
  87. #define INTF_TEAR_SYNC_WRCOUNT 0x290
  88. #define INTF_TEAR_VSYNC_INIT_VAL 0x294
  89. #define INTF_TEAR_INT_COUNT_VAL 0x298
  90. #define INTF_TEAR_SYNC_THRESH 0x29C
  91. #define INTF_TEAR_START_POS 0x2A0
  92. #define INTF_TEAR_RD_PTR_IRQ 0x2A4
  93. #define INTF_TEAR_WR_PTR_IRQ 0x2A8
  94. #define INTF_TEAR_OUT_LINE_COUNT 0x2AC
  95. #define INTF_TEAR_LINE_COUNT 0x2B0
  96. #define INTF_TEAR_AUTOREFRESH_CONFIG 0x2B4
  97. #define INTF_TEAR_TEAR_DETECT_CTRL 0x2B8
  98. #define INTF_TEAR_PROG_FETCH_START 0x2C4
  99. #define INTF_TEAR_DSI_DMA_SCHD_CTRL0 0x2C8
  100. #define INTF_TEAR_DSI_DMA_SCHD_CTRL1 0x2CC
  101. #define INTF_TEAR_INT_COUNT_VAL_EXT 0x2DC
  102. #define INTF_TEAR_SYNC_THRESH_EXT 0x2E0
  103. #define INTF_TEAR_SYNC_WRCOUNT_EXT 0x2E4
  104. static struct sde_intf_cfg *_intf_offset(enum sde_intf intf,
  105. struct sde_mdss_cfg *m,
  106. void __iomem *addr,
  107. struct sde_hw_blk_reg_map *b)
  108. {
  109. int i;
  110. for (i = 0; i < m->intf_count; i++) {
  111. if ((intf == m->intf[i].id) &&
  112. (m->intf[i].type != INTF_NONE)) {
  113. b->base_off = addr;
  114. b->blk_off = m->intf[i].base;
  115. b->length = m->intf[i].len;
  116. b->hw_rev = m->hw_rev;
  117. b->log_mask = SDE_DBG_MASK_INTF;
  118. return &m->intf[i];
  119. }
  120. }
  121. return ERR_PTR(-EINVAL);
  122. }
  123. static void sde_hw_intf_avr_trigger(struct sde_hw_intf *ctx)
  124. {
  125. struct sde_hw_blk_reg_map *c;
  126. if (!ctx)
  127. return;
  128. c = &ctx->hw;
  129. SDE_REG_WRITE(c, INTF_AVR_TRIGGER, 0x1);
  130. SDE_DEBUG("AVR Triggered\n");
  131. }
  132. static int sde_hw_intf_avr_setup(struct sde_hw_intf *ctx,
  133. const struct intf_timing_params *params,
  134. const struct intf_avr_params *avr_params)
  135. {
  136. struct sde_hw_blk_reg_map *c;
  137. u32 hsync_period, vsync_period;
  138. u32 min_fps, default_fps, diff_fps;
  139. u32 vsync_period_slow;
  140. u32 avr_vtotal;
  141. u32 add_porches = 0;
  142. if (!ctx || !params || !avr_params) {
  143. SDE_ERROR("invalid input parameter(s)\n");
  144. return -EINVAL;
  145. }
  146. c = &ctx->hw;
  147. min_fps = avr_params->min_fps;
  148. default_fps = avr_params->default_fps;
  149. diff_fps = default_fps - min_fps;
  150. hsync_period = params->hsync_pulse_width +
  151. params->h_back_porch + params->width +
  152. params->h_front_porch;
  153. vsync_period = params->vsync_pulse_width +
  154. params->v_back_porch + params->height +
  155. params->v_front_porch;
  156. if (diff_fps)
  157. add_porches = mult_frac(vsync_period, diff_fps, min_fps);
  158. vsync_period_slow = vsync_period + add_porches;
  159. avr_vtotal = vsync_period_slow * hsync_period;
  160. SDE_REG_WRITE(c, INTF_AVR_VTOTAL, avr_vtotal);
  161. return 0;
  162. }
  163. static void sde_hw_intf_avr_ctrl(struct sde_hw_intf *ctx,
  164. const struct intf_avr_params *avr_params)
  165. {
  166. struct sde_hw_blk_reg_map *c;
  167. u32 avr_mode = 0;
  168. u32 avr_ctrl = 0;
  169. if (!ctx || !avr_params)
  170. return;
  171. c = &ctx->hw;
  172. if (avr_params->avr_mode) {
  173. avr_ctrl = BIT(0);
  174. avr_mode = (avr_params->avr_mode == SDE_RM_QSYNC_ONE_SHOT_MODE) ?
  175. (BIT(0) | BIT(8)) : 0x0;
  176. if (avr_params->avr_step_lines)
  177. avr_mode |= avr_params->avr_step_lines << 16;
  178. }
  179. SDE_REG_WRITE(c, INTF_AVR_CONTROL, avr_ctrl);
  180. SDE_REG_WRITE(c, INTF_AVR_MODE, avr_mode);
  181. }
  182. static u32 sde_hw_intf_get_avr_status(struct sde_hw_intf *ctx)
  183. {
  184. struct sde_hw_blk_reg_map *c;
  185. u32 avr_ctrl;
  186. if (!ctx)
  187. return false;
  188. c = &ctx->hw;
  189. avr_ctrl = SDE_REG_READ(c, INTF_AVR_CONTROL);
  190. return avr_ctrl >> 31;
  191. }
  192. static inline void _check_and_set_comp_bit(struct sde_hw_intf *ctx,
  193. bool dsc_4hs_merge, bool compression_en, u32 *intf_cfg2)
  194. {
  195. if (((SDE_HW_MAJOR(ctx->mdss->hw_rev) >= SDE_HW_MAJOR(SDE_HW_VER_700)) && compression_en)
  196. || (IS_SDE_MAJOR_SAME(ctx->mdss->hw_rev, SDE_HW_VER_600) && dsc_4hs_merge))
  197. (*intf_cfg2) |= BIT(12);
  198. else if (!compression_en)
  199. (*intf_cfg2) &= ~BIT(12);
  200. }
  201. static void sde_hw_intf_reset_counter(struct sde_hw_intf *ctx)
  202. {
  203. struct sde_hw_blk_reg_map *c = &ctx->hw;
  204. SDE_REG_WRITE(c, INTF_LINE_COUNT, BIT(31));
  205. }
  206. static u64 sde_hw_intf_get_vsync_timestamp(struct sde_hw_intf *ctx, bool is_vid)
  207. {
  208. struct sde_hw_blk_reg_map *c = &ctx->hw;
  209. u32 timestamp_lo, timestamp_hi;
  210. u64 timestamp = 0;
  211. u32 reg_ts_0, reg_ts_1;
  212. if (ctx->cap->features & BIT(SDE_INTF_MDP_VSYNC_TS) && is_vid) {
  213. reg_ts_0 = INTF_MDP_VSYNC_TIMESTAMP0;
  214. reg_ts_1 = INTF_MDP_VSYNC_TIMESTAMP1;
  215. } else {
  216. reg_ts_0 = INTF_VSYNC_TIMESTAMP0;
  217. reg_ts_1 = INTF_VSYNC_TIMESTAMP1;
  218. }
  219. timestamp_hi = SDE_REG_READ(c, reg_ts_1);
  220. timestamp_lo = SDE_REG_READ(c, reg_ts_0);
  221. timestamp = timestamp_hi;
  222. timestamp = (timestamp << 32) | timestamp_lo;
  223. return timestamp;
  224. }
  225. static void sde_hw_intf_setup_timing_engine(struct sde_hw_intf *ctx,
  226. const struct intf_timing_params *p,
  227. const struct sde_format *fmt)
  228. {
  229. struct sde_hw_blk_reg_map *c = &ctx->hw;
  230. u32 hsync_period, vsync_period;
  231. u32 display_v_start, display_v_end;
  232. u32 hsync_start_x, hsync_end_x;
  233. u32 hsync_data_start_x, hsync_data_end_x;
  234. u32 active_h_start, active_h_end;
  235. u32 active_v_start, active_v_end;
  236. u32 active_hctl, display_hctl, hsync_ctl;
  237. u32 polarity_ctl, den_polarity, hsync_polarity, vsync_polarity;
  238. u32 panel_format;
  239. u32 intf_cfg, intf_cfg2 = 0;
  240. u32 display_data_hctl = 0, active_data_hctl = 0;
  241. u32 data_width;
  242. bool dp_intf = false;
  243. /* read interface_cfg */
  244. intf_cfg = SDE_REG_READ(c, INTF_CONFIG);
  245. if (ctx->cap->type == INTF_EDP || ctx->cap->type == INTF_DP)
  246. dp_intf = true;
  247. hsync_period = p->hsync_pulse_width + p->h_back_porch + p->width +
  248. p->h_front_porch;
  249. vsync_period = p->vsync_pulse_width + p->v_back_porch + p->height +
  250. p->v_front_porch;
  251. display_v_start = ((p->vsync_pulse_width + p->v_back_porch) *
  252. hsync_period) + p->hsync_skew;
  253. display_v_end = ((vsync_period - p->v_front_porch) * hsync_period) +
  254. p->hsync_skew - 1;
  255. hsync_ctl = (hsync_period << 16) | p->hsync_pulse_width;
  256. hsync_start_x = p->h_back_porch + p->hsync_pulse_width;
  257. hsync_end_x = hsync_period - p->h_front_porch - 1;
  258. /*
  259. * DATA_HCTL_EN controls data timing which can be different from
  260. * video timing. It is recommended to enable it for all cases, except
  261. * if compression is enabled in 1 pixel per clock mode
  262. */
  263. if (!p->compression_en || p->wide_bus_en)
  264. intf_cfg2 |= BIT(4);
  265. if (p->wide_bus_en)
  266. intf_cfg2 |= BIT(0);
  267. /*
  268. * If widebus is disabled:
  269. * For uncompressed stream, the data is valid for the entire active
  270. * window period.
  271. * For compressed stream, data is valid for a shorter time period
  272. * inside the active window depending on the compression ratio.
  273. *
  274. * If widebus is enabled:
  275. * For uncompressed stream, data is valid for only half the active
  276. * window, since the data rate is doubled in this mode.
  277. * p->width holds the adjusted width for DP but unadjusted width for DSI
  278. * For compressed stream, data validity window needs to be adjusted for
  279. * compression ratio and then further halved.
  280. */
  281. data_width = p->width;
  282. if (p->compression_en) {
  283. if (p->wide_bus_en)
  284. data_width = DIV_ROUND_UP(p->dce_bytes_per_line, 6);
  285. else
  286. data_width = DIV_ROUND_UP(p->dce_bytes_per_line, 3);
  287. } else if (!dp_intf && p->wide_bus_en) {
  288. data_width = p->width >> 1;
  289. } else {
  290. data_width = p->width;
  291. }
  292. hsync_data_start_x = hsync_start_x;
  293. hsync_data_end_x = hsync_start_x + data_width - 1;
  294. display_hctl = (hsync_end_x << 16) | hsync_start_x;
  295. display_data_hctl = (hsync_data_end_x << 16) | hsync_data_start_x;
  296. if (dp_intf) {
  297. // DP timing adjustment
  298. display_v_start += p->hsync_pulse_width + p->h_back_porch;
  299. display_v_end -= p->h_front_porch;
  300. }
  301. intf_cfg |= BIT(29); /* ACTIVE_H_ENABLE */
  302. intf_cfg |= BIT(30); /* ACTIVE_V_ENABLE */
  303. active_h_start = hsync_start_x;
  304. active_h_end = active_h_start + p->xres - 1;
  305. active_v_start = display_v_start;
  306. active_v_end = active_v_start + (p->yres * hsync_period) - 1;
  307. active_hctl = (active_h_end << 16) | active_h_start;
  308. if (dp_intf) {
  309. display_hctl = active_hctl;
  310. if (p->compression_en) {
  311. active_data_hctl = (hsync_start_x +
  312. p->extra_dto_cycles) << 16;
  313. active_data_hctl += hsync_start_x;
  314. display_data_hctl = active_data_hctl;
  315. }
  316. }
  317. _check_and_set_comp_bit(ctx, p->dsc_4hs_merge, p->compression_en,
  318. &intf_cfg2);
  319. den_polarity = 0;
  320. if (ctx->cap->type == INTF_HDMI) {
  321. hsync_polarity = p->yres >= 720 ? 0 : 1;
  322. vsync_polarity = p->yres >= 720 ? 0 : 1;
  323. } else if (ctx->cap->type == INTF_DP) {
  324. hsync_polarity = p->hsync_polarity;
  325. vsync_polarity = p->vsync_polarity;
  326. } else {
  327. hsync_polarity = 0;
  328. vsync_polarity = 0;
  329. }
  330. polarity_ctl = (den_polarity << 2) | /* DEN Polarity */
  331. (vsync_polarity << 1) | /* VSYNC Polarity */
  332. (hsync_polarity << 0); /* HSYNC Polarity */
  333. if (!SDE_FORMAT_IS_YUV(fmt))
  334. panel_format = (fmt->bits[C0_G_Y] |
  335. (fmt->bits[C1_B_Cb] << 2) |
  336. (fmt->bits[C2_R_Cr] << 4) |
  337. (0x21 << 8));
  338. else
  339. /* Interface treats all the pixel data in RGB888 format */
  340. panel_format = (COLOR_8BIT |
  341. (COLOR_8BIT << 2) |
  342. (COLOR_8BIT << 4) |
  343. (0x21 << 8));
  344. if (p->wide_bus_en)
  345. intf_cfg2 |= BIT(0);
  346. /* Synchronize timing engine enable to TE */
  347. if ((ctx->cap->features & BIT(SDE_INTF_TE_ALIGN_VSYNC))
  348. && p->poms_align_vsync)
  349. intf_cfg2 |= BIT(16);
  350. if (ctx->cfg.split_link_en)
  351. SDE_REG_WRITE(c, INTF_REG_SPLIT_LINK, 0x3);
  352. SDE_REG_WRITE(c, INTF_HSYNC_CTL, hsync_ctl);
  353. SDE_REG_WRITE(c, INTF_VSYNC_PERIOD_F0, vsync_period * hsync_period);
  354. SDE_REG_WRITE(c, INTF_VSYNC_PULSE_WIDTH_F0,
  355. p->vsync_pulse_width * hsync_period);
  356. SDE_REG_WRITE(c, INTF_DISPLAY_HCTL, display_hctl);
  357. SDE_REG_WRITE(c, INTF_DISPLAY_V_START_F0, display_v_start);
  358. SDE_REG_WRITE(c, INTF_DISPLAY_V_END_F0, display_v_end);
  359. SDE_REG_WRITE(c, INTF_ACTIVE_HCTL, active_hctl);
  360. SDE_REG_WRITE(c, INTF_ACTIVE_V_START_F0, active_v_start);
  361. SDE_REG_WRITE(c, INTF_ACTIVE_V_END_F0, active_v_end);
  362. SDE_REG_WRITE(c, INTF_BORDER_COLOR, p->border_clr);
  363. SDE_REG_WRITE(c, INTF_UNDERFLOW_COLOR, p->underflow_clr);
  364. SDE_REG_WRITE(c, INTF_HSYNC_SKEW, p->hsync_skew);
  365. SDE_REG_WRITE(c, INTF_POLARITY_CTL, polarity_ctl);
  366. SDE_REG_WRITE(c, INTF_FRAME_LINE_COUNT_EN, 0x3);
  367. SDE_REG_WRITE(c, INTF_CONFIG, intf_cfg);
  368. SDE_REG_WRITE(c, INTF_PANEL_FORMAT, panel_format);
  369. SDE_REG_WRITE(c, INTF_CONFIG2, intf_cfg2);
  370. SDE_REG_WRITE(c, INTF_DISPLAY_DATA_HCTL, display_data_hctl);
  371. SDE_REG_WRITE(c, INTF_ACTIVE_DATA_HCTL, active_data_hctl);
  372. }
  373. static void sde_hw_intf_enable_timing_engine(struct sde_hw_intf *intf, u8 enable)
  374. {
  375. struct sde_hw_blk_reg_map *c = &intf->hw;
  376. u32 val;
  377. /* Note: Display interface select is handled in top block hw layer */
  378. SDE_REG_WRITE(c, INTF_TIMING_ENGINE_EN, enable != 0);
  379. if (enable && (intf->cap->features
  380. & (BIT(SDE_INTF_PANEL_VSYNC_TS) | BIT(SDE_INTF_MDP_VSYNC_TS)))) {
  381. val = BIT(0);
  382. if (intf->cap->features & SDE_INTF_VSYNC_TS_SRC_EN)
  383. val |= BIT(4);
  384. SDE_REG_WRITE(c, INTF_VSYNC_TIMESTAMP_CTRL, val);
  385. }
  386. }
  387. static void sde_hw_intf_enable_te_level_trigger(struct sde_hw_intf *intf, bool enable)
  388. {
  389. struct sde_hw_blk_reg_map *c = &intf->hw;
  390. u32 intf_cfg = 0;
  391. intf_cfg = SDE_REG_READ(c, INTF_CONFIG);
  392. if (enable)
  393. intf_cfg |= BIT(22);
  394. else
  395. intf_cfg &= ~BIT(22);
  396. SDE_REG_WRITE(c, INTF_CONFIG, intf_cfg);
  397. }
  398. static void sde_hw_intf_setup_prg_fetch(
  399. struct sde_hw_intf *intf,
  400. const struct intf_prog_fetch *fetch)
  401. {
  402. struct sde_hw_blk_reg_map *c = &intf->hw;
  403. int fetch_enable;
  404. /*
  405. * Fetch should always be outside the active lines. If the fetching
  406. * is programmed within active region, hardware behavior is unknown.
  407. */
  408. fetch_enable = SDE_REG_READ(c, INTF_CONFIG);
  409. if (fetch->enable) {
  410. fetch_enable |= BIT(31);
  411. SDE_REG_WRITE(c, INTF_PROG_FETCH_START,
  412. fetch->fetch_start);
  413. } else {
  414. fetch_enable &= ~BIT(31);
  415. }
  416. SDE_REG_WRITE(c, INTF_CONFIG, fetch_enable);
  417. }
  418. static void sde_hw_intf_configure_wd_timer_jitter(struct sde_hw_intf *intf,
  419. struct intf_wd_jitter_params *wd_jitter)
  420. {
  421. struct sde_hw_blk_reg_map *c;
  422. u32 reg, jitter_ctl = 0;
  423. c = &intf->hw;
  424. /*
  425. * Load Jitter values with jitter feature disabled.
  426. */
  427. SDE_REG_WRITE(c, INTF_WD_TIMER_0_JITTER_CTL, 0x1);
  428. if (wd_jitter->jitter)
  429. jitter_ctl |= ((wd_jitter->jitter & 0x3FF) << 16);
  430. if (wd_jitter->ltj_max) {
  431. SDE_REG_WRITE(c, INTF_WD_TIMER_0_LTJ_MAX, wd_jitter->ltj_max);
  432. SDE_REG_WRITE(c, INTF_WD_TIMER_0_LTJ_SLOPE, wd_jitter->ltj_slope);
  433. }
  434. reg = SDE_REG_READ(c, INTF_WD_TIMER_0_JITTER_CTL);
  435. reg |= jitter_ctl;
  436. SDE_REG_WRITE(c, INTF_WD_TIMER_0_JITTER_CTL, reg);
  437. if (wd_jitter->jitter)
  438. reg |= BIT(31);
  439. if (wd_jitter->ltj_max)
  440. reg |= BIT(30);
  441. SDE_REG_WRITE(c, INTF_WD_TIMER_0_JITTER_CTL, reg);
  442. if (intf->cap->features & BIT(SDE_INTF_WD_LTJ_CTL)) {
  443. if (wd_jitter->ltj_step_dir && wd_jitter->ltj_initial_val) {
  444. reg = ((wd_jitter->ltj_step_dir & 0x1) << 31) |
  445. (wd_jitter->ltj_initial_val & 0x1FFFFF);
  446. SDE_REG_WRITE(c, INTF_WD_TIMER_0_LTJ_CTL, reg);
  447. wd_jitter->ltj_step_dir = 0;
  448. wd_jitter->ltj_initial_val = 0;
  449. }
  450. if (wd_jitter->ltj_fractional_val) {
  451. SDE_REG_WRITE(c, INTF_WD_TIMER_0_LTJ_CTL1, wd_jitter->ltj_fractional_val);
  452. wd_jitter->ltj_fractional_val = 0;
  453. }
  454. }
  455. }
  456. static void sde_hw_intf_read_wd_ltj_ctl(struct sde_hw_intf *intf,
  457. struct intf_wd_jitter_params *wd_jitter)
  458. {
  459. struct sde_hw_blk_reg_map *c;
  460. u32 reg;
  461. c = &intf->hw;
  462. if (intf->cap->features & BIT(SDE_INTF_WD_LTJ_CTL)) {
  463. reg = SDE_REG_READ(c, INTF_WD_TIMER_0_LTJ_INT_STATUS);
  464. wd_jitter->ltj_step_dir = reg & BIT(31);
  465. wd_jitter->ltj_initial_val = (reg & 0x1FFFFF);
  466. reg = SDE_REG_READ(c, INTF_WD_TIMER_0_LTJ_FRAC_STATUS);
  467. wd_jitter->ltj_fractional_val = (reg & 0xFFFF);
  468. }
  469. }
  470. static void sde_hw_intf_setup_vsync_source(struct sde_hw_intf *intf, u32 frame_rate)
  471. {
  472. struct sde_hw_blk_reg_map *c;
  473. u32 reg = 0;
  474. if (!intf)
  475. return;
  476. c = &intf->hw;
  477. reg = CALCULATE_WD_LOAD_VALUE(frame_rate);
  478. SDE_REG_WRITE(c, INTF_WD_TIMER_0_LOAD_VALUE, reg);
  479. SDE_REG_WRITE(c, INTF_WD_TIMER_0_CTL, BIT(0)); /* clear timer */
  480. reg = BIT(8); /* enable heartbeat timer */
  481. reg |= BIT(0); /* enable WD timer */
  482. reg |= BIT(1); /* select default 16 clock ticks */
  483. SDE_REG_WRITE(c, INTF_WD_TIMER_0_CTL2, reg);
  484. /* make sure that timers are enabled/disabled for vsync state */
  485. wmb();
  486. }
  487. static void sde_hw_intf_bind_pingpong_blk(
  488. struct sde_hw_intf *intf,
  489. bool enable,
  490. const enum sde_pingpong pp)
  491. {
  492. struct sde_hw_blk_reg_map *c;
  493. u32 mux_cfg;
  494. if (!intf)
  495. return;
  496. c = &intf->hw;
  497. if (enable) {
  498. mux_cfg = SDE_REG_READ(c, INTF_MUX);
  499. mux_cfg &= ~0x0f;
  500. mux_cfg |= (pp - PINGPONG_0) & 0x7;
  501. /* Splitlink case, pp0->sublink0, pp1->sublink1 */
  502. if (intf->cfg.split_link_en)
  503. mux_cfg = 0x10000;
  504. } else {
  505. mux_cfg = 0xf000f;
  506. }
  507. SDE_REG_WRITE(c, INTF_MUX, mux_cfg);
  508. }
  509. static u32 sde_hw_intf_get_frame_count(struct sde_hw_intf *intf)
  510. {
  511. struct sde_hw_blk_reg_map *c = &intf->hw;
  512. bool en;
  513. /*
  514. * MDP VSync Frame Count is enabled with programmable fetch
  515. * or with auto-refresh enabled.
  516. */
  517. en = (SDE_REG_READ(c, INTF_TEAR_AUTOREFRESH_CONFIG) & BIT(31)) |
  518. (SDE_REG_READ(c, INTF_CONFIG) & BIT(31));
  519. if (en && (intf->cap->features & BIT(SDE_INTF_MDP_VSYNC_FC)))
  520. return SDE_REG_READ(c, INTF_MDP_FRAME_COUNT);
  521. else
  522. return SDE_REG_READ(c, INTF_FRAME_COUNT);
  523. }
  524. static void sde_hw_intf_get_status(
  525. struct sde_hw_intf *intf,
  526. struct intf_status *s)
  527. {
  528. struct sde_hw_blk_reg_map *c = &intf->hw;
  529. s->is_en = SDE_REG_READ(c, INTF_TIMING_ENGINE_EN);
  530. if (s->is_en) {
  531. s->frame_count = SDE_REG_READ(c, INTF_FRAME_COUNT);
  532. s->line_count = SDE_REG_READ(c, INTF_LINE_COUNT) & 0xffff;
  533. } else {
  534. s->line_count = 0;
  535. s->frame_count = 0;
  536. }
  537. }
  538. static void sde_hw_intf_v1_get_status(
  539. struct sde_hw_intf *intf,
  540. struct intf_status *s)
  541. {
  542. struct sde_hw_blk_reg_map *c = &intf->hw;
  543. s->is_en = SDE_REG_READ(c, INTF_STATUS) & BIT(0);
  544. s->is_prog_fetch_en = (SDE_REG_READ(c, INTF_CONFIG) & BIT(31));
  545. if (s->is_en) {
  546. s->frame_count = sde_hw_intf_get_frame_count(intf);
  547. s->line_count = SDE_REG_READ(c, INTF_LINE_COUNT) & 0xffff;
  548. } else {
  549. s->line_count = 0;
  550. s->frame_count = 0;
  551. }
  552. }
  553. static void sde_hw_intf_setup_misr(struct sde_hw_intf *intf,
  554. bool enable, u32 frame_count)
  555. {
  556. struct sde_hw_blk_reg_map *c = &intf->hw;
  557. u32 config = 0;
  558. SDE_REG_WRITE(c, INTF_MISR_CTRL, MISR_CTRL_STATUS_CLEAR);
  559. /* clear misr data */
  560. wmb();
  561. if (enable)
  562. config = (frame_count & MISR_FRAME_COUNT_MASK) |
  563. MISR_CTRL_ENABLE |
  564. INTF_MISR_CTRL_FREE_RUN_MASK |
  565. INTF_MISR_CTRL_INPUT_SEL_DATA;
  566. SDE_REG_WRITE(c, INTF_MISR_CTRL, config);
  567. }
  568. static int sde_hw_intf_collect_misr(struct sde_hw_intf *intf, bool nonblock,
  569. u32 *misr_value)
  570. {
  571. struct sde_hw_blk_reg_map *c = &intf->hw;
  572. u32 ctrl = 0;
  573. int rc = 0;
  574. if (!misr_value)
  575. return -EINVAL;
  576. ctrl = SDE_REG_READ(c, INTF_MISR_CTRL);
  577. if (!nonblock) {
  578. if (ctrl & MISR_CTRL_ENABLE) {
  579. rc = read_poll_timeout(sde_reg_read, ctrl, (ctrl & MISR_CTRL_STATUS) > 0,
  580. 500, false, 84000, c, INTF_MISR_CTRL);
  581. if (rc)
  582. return rc;
  583. } else {
  584. return -EINVAL;
  585. }
  586. }
  587. *misr_value = SDE_REG_READ(c, INTF_MISR_SIGNATURE);
  588. return rc;
  589. }
  590. static u32 sde_hw_intf_get_line_count(struct sde_hw_intf *intf)
  591. {
  592. struct sde_hw_blk_reg_map *c;
  593. if (!intf)
  594. return 0;
  595. c = &intf->hw;
  596. return SDE_REG_READ(c, INTF_LINE_COUNT) & 0xffff;
  597. }
  598. static u32 sde_hw_intf_get_underrun_line_count(struct sde_hw_intf *intf)
  599. {
  600. struct sde_hw_blk_reg_map *c;
  601. u32 hsync_period;
  602. if (!intf)
  603. return 0;
  604. c = &intf->hw;
  605. hsync_period = SDE_REG_READ(c, INTF_HSYNC_CTL);
  606. hsync_period = ((hsync_period & 0xffff0000) >> 16);
  607. return hsync_period ?
  608. SDE_REG_READ(c, INTF_UNDERRUN_COUNT) / hsync_period :
  609. 0xebadebad;
  610. }
  611. static u32 sde_hw_intf_get_intr_status(struct sde_hw_intf *intf)
  612. {
  613. if (!intf)
  614. return -EINVAL;
  615. return SDE_REG_READ(&intf->hw, INTF_INTR_STATUS);
  616. }
  617. static int sde_hw_intf_setup_te_config(struct sde_hw_intf *intf,
  618. struct sde_hw_tear_check *te)
  619. {
  620. struct sde_hw_blk_reg_map *c;
  621. u32 cfg = 0, val;
  622. spinlock_t tearcheck_spinlock;
  623. if (!intf)
  624. return -EINVAL;
  625. spin_lock_init(&tearcheck_spinlock);
  626. c = &intf->hw;
  627. if (te->hw_vsync_mode)
  628. cfg |= BIT(20);
  629. cfg |= te->vsync_count;
  630. /*
  631. * Local spinlock is acquired here to avoid pre-emption
  632. * as below register programming should be completed in
  633. * less than 2^16 vsync clk cycles.
  634. */
  635. spin_lock(&tearcheck_spinlock);
  636. val = te->start_pos + te->sync_threshold_start + 1;
  637. if (intf->cap->features & BIT(SDE_INTF_TE_32BIT))
  638. SDE_REG_WRITE(c, INTF_TEAR_SYNC_WRCOUNT_EXT, (val >> 16));
  639. SDE_REG_WRITE(c, INTF_TEAR_SYNC_WRCOUNT, (val & 0xffff));
  640. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_VSYNC, cfg);
  641. wmb(); /* disable vsync counter before updating single buffer registers */
  642. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_HEIGHT, te->sync_cfg_height);
  643. SDE_REG_WRITE(c, INTF_TEAR_VSYNC_INIT_VAL, te->vsync_init_val);
  644. SDE_REG_WRITE(c, INTF_TEAR_RD_PTR_IRQ, te->rd_ptr_irq);
  645. SDE_REG_WRITE(c, INTF_TEAR_WR_PTR_IRQ, te->wr_ptr_irq);
  646. SDE_REG_WRITE(c, INTF_TEAR_START_POS, te->start_pos);
  647. SDE_REG_WRITE(c, INTF_TEAR_TEAR_DETECT_CTRL, te->detect_ctrl);
  648. if (intf->cap->features & BIT(SDE_INTF_TE_32BIT))
  649. SDE_REG_WRITE(c, INTF_TEAR_SYNC_THRESH_EXT,
  650. ((te->sync_threshold_continue & 0xffff0000) |
  651. (te->sync_threshold_start >> 16)));
  652. SDE_REG_WRITE(c, INTF_TEAR_SYNC_THRESH,
  653. ((te->sync_threshold_continue << 16) |
  654. (te->sync_threshold_start & 0xffff)));
  655. cfg |= BIT(19); /* VSYNC_COUNTER_EN */
  656. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_VSYNC, cfg);
  657. spin_unlock(&tearcheck_spinlock);
  658. return 0;
  659. }
  660. static int sde_hw_intf_setup_autorefresh_config(struct sde_hw_intf *intf,
  661. struct sde_hw_autorefresh *cfg)
  662. {
  663. struct sde_hw_blk_reg_map *c;
  664. u32 refresh_cfg;
  665. if (!intf || !cfg)
  666. return -EINVAL;
  667. c = &intf->hw;
  668. refresh_cfg = SDE_REG_READ(c, INTF_TEAR_AUTOREFRESH_CONFIG);
  669. if (cfg->enable)
  670. refresh_cfg = BIT(31) | cfg->frame_count;
  671. else
  672. refresh_cfg &= ~BIT(31);
  673. SDE_REG_WRITE(c, INTF_TEAR_AUTOREFRESH_CONFIG, refresh_cfg);
  674. return 0;
  675. }
  676. static int sde_hw_intf_get_autorefresh_config(struct sde_hw_intf *intf,
  677. struct sde_hw_autorefresh *cfg)
  678. {
  679. struct sde_hw_blk_reg_map *c;
  680. u32 val;
  681. if (!intf || !cfg)
  682. return -EINVAL;
  683. c = &intf->hw;
  684. val = SDE_REG_READ(c, INTF_TEAR_AUTOREFRESH_CONFIG);
  685. cfg->enable = (val & BIT(31)) >> 31;
  686. cfg->frame_count = val & 0xffff;
  687. return 0;
  688. }
  689. static int sde_hw_intf_poll_timeout_wr_ptr(struct sde_hw_intf *intf,
  690. u32 timeout_us)
  691. {
  692. struct sde_hw_blk_reg_map *c;
  693. u32 val, mask = 0;
  694. if (!intf)
  695. return -EINVAL;
  696. if (intf->cap->features & BIT(SDE_INTF_TE_32BIT))
  697. mask = 0xffffffff;
  698. else
  699. mask = 0xffff;
  700. c = &intf->hw;
  701. return read_poll_timeout(sde_reg_read, val, (val & mask) >= 1, 10, false, timeout_us,
  702. c, INTF_TEAR_LINE_COUNT);
  703. }
  704. static int sde_hw_intf_enable_te(struct sde_hw_intf *intf, bool enable)
  705. {
  706. struct sde_hw_blk_reg_map *c;
  707. uint32_t val = 0;
  708. if (!intf)
  709. return -EINVAL;
  710. c = &intf->hw;
  711. if (enable)
  712. val |= BIT(0);
  713. if (intf->cap->features & BIT(SDE_INTF_TE_SINGLE_UPDATE))
  714. val |= BIT(3);
  715. SDE_REG_WRITE(c, INTF_TEAR_TEAR_CHECK_EN, val);
  716. if (enable && (intf->cap->features &
  717. (BIT(SDE_INTF_PANEL_VSYNC_TS) | BIT(SDE_INTF_MDP_VSYNC_TS)))) {
  718. val = BIT(0);
  719. if (intf->cap->features & SDE_INTF_VSYNC_TS_SRC_EN)
  720. val |= BIT(5);
  721. SDE_REG_WRITE(c, INTF_VSYNC_TIMESTAMP_CTRL, val);
  722. }
  723. return 0;
  724. }
  725. static void sde_hw_intf_update_te(struct sde_hw_intf *intf,
  726. struct sde_hw_tear_check *te)
  727. {
  728. struct sde_hw_blk_reg_map *c;
  729. int cfg;
  730. if (!intf || !te)
  731. return;
  732. c = &intf->hw;
  733. cfg = SDE_REG_READ(c, INTF_TEAR_SYNC_THRESH);
  734. cfg &= ~0xFFFF;
  735. cfg |= te->sync_threshold_start;
  736. SDE_REG_WRITE(c, INTF_TEAR_SYNC_THRESH, cfg);
  737. SDE_REG_WRITE(c, INTF_TEAR_START_POS, te->start_pos);
  738. }
  739. static int sde_hw_intf_connect_external_te(struct sde_hw_intf *intf,
  740. bool enable_external_te)
  741. {
  742. struct sde_hw_blk_reg_map *c = &intf->hw;
  743. u32 cfg;
  744. int orig;
  745. if (!intf)
  746. return -EINVAL;
  747. c = &intf->hw;
  748. cfg = SDE_REG_READ(c, INTF_TEAR_SYNC_CONFIG_VSYNC);
  749. orig = (bool)(cfg & BIT(20));
  750. if (enable_external_te)
  751. cfg |= BIT(20);
  752. else
  753. cfg &= ~BIT(20);
  754. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_VSYNC, cfg);
  755. return orig;
  756. }
  757. static int sde_hw_intf_get_vsync_info(struct sde_hw_intf *intf,
  758. struct sde_hw_pp_vsync_info *info)
  759. {
  760. struct sde_hw_blk_reg_map *c = &intf->hw;
  761. u32 val;
  762. if (!intf || !info)
  763. return -EINVAL;
  764. c = &intf->hw;
  765. val = SDE_REG_READ(c, INTF_TEAR_VSYNC_INIT_VAL);
  766. if (intf->cap->features & BIT(SDE_INTF_TE_32BIT))
  767. info->rd_ptr_init_val = val;
  768. else
  769. info->rd_ptr_init_val = val & 0xffff;
  770. val = SDE_REG_READ(c, INTF_TEAR_INT_COUNT_VAL);
  771. info->rd_ptr_frame_count = (val & 0xffff0000) >> 16;
  772. info->rd_ptr_line_count = val & 0xffff;
  773. if (intf->cap->features & BIT(SDE_INTF_TE_32BIT)) {
  774. val = SDE_REG_READ(c, INTF_TEAR_INT_COUNT_VAL_EXT);
  775. info->rd_ptr_line_count |= (val << 16);
  776. }
  777. val = SDE_REG_READ(c, INTF_TEAR_LINE_COUNT);
  778. info->wr_ptr_line_count = val;
  779. val = sde_hw_intf_get_frame_count(intf);
  780. info->intf_frame_count = val;
  781. return 0;
  782. }
  783. static int sde_hw_intf_v1_check_and_reset_tearcheck(struct sde_hw_intf *intf,
  784. struct intf_tear_status *status)
  785. {
  786. struct sde_hw_blk_reg_map *c = &intf->hw;
  787. u32 start_pos, val;
  788. if (!intf || !status)
  789. return -EINVAL;
  790. c = &intf->hw;
  791. status->read_line_count = SDE_REG_READ(c, INTF_TEAR_INT_COUNT_VAL);
  792. if (intf->cap->features & BIT(SDE_INTF_TE_32BIT))
  793. status->read_line_count |= (SDE_REG_READ(c, INTF_TEAR_INT_COUNT_VAL_EXT) << 16);
  794. start_pos = SDE_REG_READ(c, INTF_TEAR_START_POS);
  795. val = SDE_REG_READ(c, INTF_TEAR_SYNC_WRCOUNT);
  796. status->write_frame_count = val >> 16;
  797. status->write_line_count = start_pos;
  798. if (intf->cap->features & BIT(SDE_INTF_TE_32BIT)) {
  799. val = (status->write_line_count & 0xffff0000) >> 16;
  800. SDE_REG_WRITE(c, INTF_TEAR_SYNC_WRCOUNT_EXT, val);
  801. }
  802. val = (status->write_frame_count << 16) | (status->write_line_count & 0xffff);
  803. SDE_REG_WRITE(c, INTF_TEAR_SYNC_WRCOUNT, val);
  804. return 0;
  805. }
  806. static void sde_hw_intf_override_tear_rd_ptr_val(struct sde_hw_intf *intf,
  807. u32 adjusted_rd_ptr_val)
  808. {
  809. struct sde_hw_blk_reg_map *c;
  810. if (!intf || !adjusted_rd_ptr_val)
  811. return;
  812. c = &intf->hw;
  813. SDE_REG_WRITE(c, INTF_TEAR_SYNC_WRCOUNT, (adjusted_rd_ptr_val & 0xFFFF));
  814. /* ensure rd_ptr_val is written */
  815. wmb();
  816. }
  817. static void sde_hw_intf_vsync_sel(struct sde_hw_intf *intf,
  818. u32 vsync_source)
  819. {
  820. struct sde_hw_blk_reg_map *c;
  821. if (!intf)
  822. return;
  823. c = &intf->hw;
  824. SDE_REG_WRITE(c, INTF_TEAR_MDP_VSYNC_SEL, (vsync_source & 0xf));
  825. }
  826. static void sde_hw_intf_enable_compressed_input(struct sde_hw_intf *intf,
  827. bool compression_en, bool dsc_4hs_merge)
  828. {
  829. struct sde_hw_blk_reg_map *c;
  830. u32 intf_cfg2;
  831. if (!intf)
  832. return;
  833. /*
  834. * callers can either call this function to enable/disable the 64 bit
  835. * compressed input or this configuration can be applied along
  836. * with timing generation parameters
  837. */
  838. c = &intf->hw;
  839. intf_cfg2 = SDE_REG_READ(c, INTF_CONFIG2);
  840. _check_and_set_comp_bit(intf, dsc_4hs_merge, compression_en,
  841. &intf_cfg2);
  842. SDE_REG_WRITE(c, INTF_CONFIG2, intf_cfg2);
  843. }
  844. static void sde_hw_intf_enable_wide_bus(struct sde_hw_intf *intf,
  845. bool enable)
  846. {
  847. struct sde_hw_blk_reg_map *c;
  848. u32 intf_cfg2;
  849. if (!intf)
  850. return;
  851. c = &intf->hw;
  852. intf_cfg2 = SDE_REG_READ(c, INTF_CONFIG2);
  853. intf_cfg2 &= ~BIT(0);
  854. intf_cfg2 |= enable ? BIT(0) : 0;
  855. SDE_REG_WRITE(c, INTF_CONFIG2, intf_cfg2);
  856. }
  857. static bool sde_hw_intf_is_te_32bit_supported(struct sde_hw_intf *intf)
  858. {
  859. return (intf->cap->features & BIT(SDE_INTF_TE_32BIT));
  860. }
  861. static void _setup_intf_ops(struct sde_hw_intf_ops *ops,
  862. unsigned long cap)
  863. {
  864. ops->setup_timing_gen = sde_hw_intf_setup_timing_engine;
  865. ops->setup_prg_fetch = sde_hw_intf_setup_prg_fetch;
  866. ops->enable_timing = sde_hw_intf_enable_timing_engine;
  867. ops->setup_misr = sde_hw_intf_setup_misr;
  868. ops->collect_misr = sde_hw_intf_collect_misr;
  869. ops->get_line_count = sde_hw_intf_get_line_count;
  870. ops->get_underrun_line_count = sde_hw_intf_get_underrun_line_count;
  871. ops->get_intr_status = sde_hw_intf_get_intr_status;
  872. ops->avr_setup = sde_hw_intf_avr_setup;
  873. ops->avr_trigger = sde_hw_intf_avr_trigger;
  874. ops->avr_ctrl = sde_hw_intf_avr_ctrl;
  875. ops->enable_compressed_input = sde_hw_intf_enable_compressed_input;
  876. ops->enable_wide_bus = sde_hw_intf_enable_wide_bus;
  877. ops->is_te_32bit_supported = sde_hw_intf_is_te_32bit_supported;
  878. if (cap & BIT(SDE_INTF_STATUS))
  879. ops->get_status = sde_hw_intf_v1_get_status;
  880. else
  881. ops->get_status = sde_hw_intf_get_status;
  882. if (cap & BIT(SDE_INTF_INPUT_CTRL))
  883. ops->bind_pingpong_blk = sde_hw_intf_bind_pingpong_blk;
  884. if (cap & BIT(SDE_INTF_WD_TIMER))
  885. ops->setup_vsync_source = sde_hw_intf_setup_vsync_source;
  886. if (cap & BIT(SDE_INTF_AVR_STATUS))
  887. ops->get_avr_status = sde_hw_intf_get_avr_status;
  888. if (cap & BIT(SDE_INTF_TE)) {
  889. ops->setup_tearcheck = sde_hw_intf_setup_te_config;
  890. ops->enable_tearcheck = sde_hw_intf_enable_te;
  891. ops->update_tearcheck = sde_hw_intf_update_te;
  892. ops->connect_external_te = sde_hw_intf_connect_external_te;
  893. ops->get_vsync_info = sde_hw_intf_get_vsync_info;
  894. ops->setup_autorefresh = sde_hw_intf_setup_autorefresh_config;
  895. ops->get_autorefresh = sde_hw_intf_get_autorefresh_config;
  896. ops->poll_timeout_wr_ptr = sde_hw_intf_poll_timeout_wr_ptr;
  897. ops->vsync_sel = sde_hw_intf_vsync_sel;
  898. ops->check_and_reset_tearcheck = sde_hw_intf_v1_check_and_reset_tearcheck;
  899. ops->override_tear_rd_ptr_val = sde_hw_intf_override_tear_rd_ptr_val;
  900. if (cap & BIT(SDE_INTF_TE_LEVEL_TRIGGER))
  901. ops->enable_te_level_trigger = sde_hw_intf_enable_te_level_trigger;
  902. }
  903. if (cap & BIT(SDE_INTF_RESET_COUNTER))
  904. ops->reset_counter = sde_hw_intf_reset_counter;
  905. if (cap & (BIT(SDE_INTF_PANEL_VSYNC_TS) | BIT(SDE_INTF_MDP_VSYNC_TS)))
  906. ops->get_vsync_timestamp = sde_hw_intf_get_vsync_timestamp;
  907. if (cap & BIT(SDE_INTF_WD_JITTER))
  908. ops->configure_wd_jitter = sde_hw_intf_configure_wd_timer_jitter;
  909. if (cap & BIT(SDE_INTF_WD_LTJ_CTL))
  910. ops->get_wd_ltj_status = sde_hw_intf_read_wd_ltj_ctl;
  911. }
  912. struct sde_hw_blk_reg_map *sde_hw_intf_init(enum sde_intf idx,
  913. void __iomem *addr,
  914. struct sde_mdss_cfg *m)
  915. {
  916. struct sde_hw_intf *c;
  917. struct sde_intf_cfg *cfg;
  918. c = kzalloc(sizeof(*c), GFP_KERNEL);
  919. if (!c)
  920. return ERR_PTR(-ENOMEM);
  921. cfg = _intf_offset(idx, m, addr, &c->hw);
  922. if (IS_ERR_OR_NULL(cfg)) {
  923. kfree(c);
  924. pr_err("failed to create sde_hw_intf %d\n", idx);
  925. return ERR_PTR(-EINVAL);
  926. }
  927. /*
  928. * Assign ops
  929. */
  930. c->idx = idx;
  931. c->cap = cfg;
  932. c->mdss = m;
  933. _setup_intf_ops(&c->ops, c->cap->features);
  934. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
  935. c->hw.blk_off + c->hw.length, c->hw.xin_id);
  936. return &c->hw;
  937. }
  938. void sde_hw_intf_destroy(struct sde_hw_blk_reg_map *hw)
  939. {
  940. if (hw)
  941. kfree(to_sde_hw_intf(hw));
  942. }