sde_hw_intf.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2022 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(
  374. struct sde_hw_intf *intf,
  375. u8 enable)
  376. {
  377. struct sde_hw_blk_reg_map *c = &intf->hw;
  378. /* Note: Display interface select is handled in top block hw layer */
  379. SDE_REG_WRITE(c, INTF_TIMING_ENGINE_EN, enable != 0);
  380. if (enable && (intf->cap->features & (BIT(SDE_INTF_PANEL_VSYNC_TS) | BIT(SDE_INTF_MDP_VSYNC_TS))))
  381. SDE_REG_WRITE(c, INTF_VSYNC_TIMESTAMP_CTRL, BIT(0));
  382. }
  383. static void sde_hw_intf_setup_prg_fetch(
  384. struct sde_hw_intf *intf,
  385. const struct intf_prog_fetch *fetch)
  386. {
  387. struct sde_hw_blk_reg_map *c = &intf->hw;
  388. int fetch_enable;
  389. /*
  390. * Fetch should always be outside the active lines. If the fetching
  391. * is programmed within active region, hardware behavior is unknown.
  392. */
  393. fetch_enable = SDE_REG_READ(c, INTF_CONFIG);
  394. if (fetch->enable) {
  395. fetch_enable |= BIT(31);
  396. SDE_REG_WRITE(c, INTF_PROG_FETCH_START,
  397. fetch->fetch_start);
  398. } else {
  399. fetch_enable &= ~BIT(31);
  400. }
  401. SDE_REG_WRITE(c, INTF_CONFIG, fetch_enable);
  402. }
  403. static void sde_hw_intf_configure_wd_timer_jitter(struct sde_hw_intf *intf,
  404. struct intf_wd_jitter_params *wd_jitter)
  405. {
  406. struct sde_hw_blk_reg_map *c;
  407. u32 reg, jitter_ctl = 0;
  408. c = &intf->hw;
  409. /*
  410. * Load Jitter values with jitter feature disabled.
  411. */
  412. SDE_REG_WRITE(c, INTF_WD_TIMER_0_JITTER_CTL, 0x1);
  413. if (wd_jitter->jitter)
  414. jitter_ctl |= ((wd_jitter->jitter & 0x3FF) << 16);
  415. if (wd_jitter->ltj_max) {
  416. SDE_REG_WRITE(c, INTF_WD_TIMER_0_LTJ_MAX, wd_jitter->ltj_max);
  417. SDE_REG_WRITE(c, INTF_WD_TIMER_0_LTJ_SLOPE, wd_jitter->ltj_slope);
  418. }
  419. reg = SDE_REG_READ(c, INTF_WD_TIMER_0_JITTER_CTL);
  420. reg |= jitter_ctl;
  421. SDE_REG_WRITE(c, INTF_WD_TIMER_0_JITTER_CTL, reg);
  422. if (wd_jitter->jitter)
  423. reg |= BIT(31);
  424. if (wd_jitter->ltj_max)
  425. reg |= BIT(30);
  426. SDE_REG_WRITE(c, INTF_WD_TIMER_0_JITTER_CTL, reg);
  427. if (intf->cap->features & BIT(SDE_INTF_WD_LTJ_CTL)) {
  428. if (wd_jitter->ltj_step_dir && wd_jitter->ltj_initial_val) {
  429. reg = ((wd_jitter->ltj_step_dir & 0x1) << 31) |
  430. (wd_jitter->ltj_initial_val & 0x1FFFFF);
  431. SDE_REG_WRITE(c, INTF_WD_TIMER_0_LTJ_CTL, reg);
  432. wd_jitter->ltj_step_dir = 0;
  433. wd_jitter->ltj_initial_val = 0;
  434. }
  435. if (wd_jitter->ltj_fractional_val) {
  436. SDE_REG_WRITE(c, INTF_WD_TIMER_0_LTJ_CTL1, wd_jitter->ltj_fractional_val);
  437. wd_jitter->ltj_fractional_val = 0;
  438. }
  439. }
  440. }
  441. static void sde_hw_intf_read_wd_ltj_ctl(struct sde_hw_intf *intf,
  442. struct intf_wd_jitter_params *wd_jitter)
  443. {
  444. struct sde_hw_blk_reg_map *c;
  445. u32 reg;
  446. c = &intf->hw;
  447. if (intf->cap->features & BIT(SDE_INTF_WD_LTJ_CTL)) {
  448. reg = SDE_REG_READ(c, INTF_WD_TIMER_0_LTJ_INT_STATUS);
  449. wd_jitter->ltj_step_dir = reg & BIT(31);
  450. wd_jitter->ltj_initial_val = (reg & 0x1FFFFF);
  451. reg = SDE_REG_READ(c, INTF_WD_TIMER_0_LTJ_FRAC_STATUS);
  452. wd_jitter->ltj_fractional_val = (reg & 0xFFFF);
  453. }
  454. }
  455. static void sde_hw_intf_setup_vsync_source(struct sde_hw_intf *intf, u32 frame_rate)
  456. {
  457. struct sde_hw_blk_reg_map *c;
  458. u32 reg = 0;
  459. if (!intf)
  460. return;
  461. c = &intf->hw;
  462. reg = CALCULATE_WD_LOAD_VALUE(frame_rate);
  463. SDE_REG_WRITE(c, INTF_WD_TIMER_0_LOAD_VALUE, reg);
  464. SDE_REG_WRITE(c, INTF_WD_TIMER_0_CTL, BIT(0)); /* clear timer */
  465. reg = BIT(8); /* enable heartbeat timer */
  466. reg |= BIT(0); /* enable WD timer */
  467. reg |= BIT(1); /* select default 16 clock ticks */
  468. SDE_REG_WRITE(c, INTF_WD_TIMER_0_CTL2, reg);
  469. /* make sure that timers are enabled/disabled for vsync state */
  470. wmb();
  471. }
  472. static void sde_hw_intf_bind_pingpong_blk(
  473. struct sde_hw_intf *intf,
  474. bool enable,
  475. const enum sde_pingpong pp)
  476. {
  477. struct sde_hw_blk_reg_map *c;
  478. u32 mux_cfg;
  479. if (!intf)
  480. return;
  481. c = &intf->hw;
  482. if (enable) {
  483. mux_cfg = SDE_REG_READ(c, INTF_MUX);
  484. mux_cfg &= ~0x0f;
  485. mux_cfg |= (pp - PINGPONG_0) & 0x7;
  486. /* Splitlink case, pp0->sublink0, pp1->sublink1 */
  487. if (intf->cfg.split_link_en)
  488. mux_cfg = 0x10000;
  489. } else {
  490. mux_cfg = 0xf000f;
  491. }
  492. SDE_REG_WRITE(c, INTF_MUX, mux_cfg);
  493. }
  494. static u32 sde_hw_intf_get_frame_count(struct sde_hw_intf *intf)
  495. {
  496. struct sde_hw_blk_reg_map *c = &intf->hw;
  497. bool en;
  498. /*
  499. * MDP VSync Frame Count is enabled with programmable fetch
  500. * or with auto-refresh enabled.
  501. */
  502. en = (SDE_REG_READ(c, INTF_TEAR_AUTOREFRESH_CONFIG) & BIT(31)) |
  503. (SDE_REG_READ(c, INTF_CONFIG) & BIT(31));
  504. if (en && (intf->cap->features & BIT(SDE_INTF_MDP_VSYNC_FC)))
  505. return SDE_REG_READ(c, INTF_MDP_FRAME_COUNT);
  506. else
  507. return SDE_REG_READ(c, INTF_FRAME_COUNT);
  508. }
  509. static void sde_hw_intf_get_status(
  510. struct sde_hw_intf *intf,
  511. struct intf_status *s)
  512. {
  513. struct sde_hw_blk_reg_map *c = &intf->hw;
  514. s->is_en = SDE_REG_READ(c, INTF_TIMING_ENGINE_EN);
  515. if (s->is_en) {
  516. s->frame_count = SDE_REG_READ(c, INTF_FRAME_COUNT);
  517. s->line_count = SDE_REG_READ(c, INTF_LINE_COUNT) & 0xffff;
  518. } else {
  519. s->line_count = 0;
  520. s->frame_count = 0;
  521. }
  522. }
  523. static void sde_hw_intf_v1_get_status(
  524. struct sde_hw_intf *intf,
  525. struct intf_status *s)
  526. {
  527. struct sde_hw_blk_reg_map *c = &intf->hw;
  528. s->is_en = SDE_REG_READ(c, INTF_STATUS) & BIT(0);
  529. s->is_prog_fetch_en = (SDE_REG_READ(c, INTF_CONFIG) & BIT(31));
  530. if (s->is_en) {
  531. s->frame_count = sde_hw_intf_get_frame_count(intf);
  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_setup_misr(struct sde_hw_intf *intf,
  539. bool enable, u32 frame_count)
  540. {
  541. struct sde_hw_blk_reg_map *c = &intf->hw;
  542. u32 config = 0;
  543. SDE_REG_WRITE(c, INTF_MISR_CTRL, MISR_CTRL_STATUS_CLEAR);
  544. /* clear misr data */
  545. wmb();
  546. if (enable)
  547. config = (frame_count & MISR_FRAME_COUNT_MASK) |
  548. MISR_CTRL_ENABLE |
  549. INTF_MISR_CTRL_FREE_RUN_MASK |
  550. INTF_MISR_CTRL_INPUT_SEL_DATA;
  551. SDE_REG_WRITE(c, INTF_MISR_CTRL, config);
  552. }
  553. static int sde_hw_intf_collect_misr(struct sde_hw_intf *intf, bool nonblock,
  554. u32 *misr_value)
  555. {
  556. struct sde_hw_blk_reg_map *c = &intf->hw;
  557. u32 ctrl = 0;
  558. int rc = 0;
  559. if (!misr_value)
  560. return -EINVAL;
  561. ctrl = SDE_REG_READ(c, INTF_MISR_CTRL);
  562. if (!nonblock) {
  563. if (ctrl & MISR_CTRL_ENABLE) {
  564. rc = read_poll_timeout(sde_reg_read, ctrl, (ctrl & MISR_CTRL_STATUS) > 0,
  565. 500, false, 84000, c, INTF_MISR_CTRL);
  566. if (rc)
  567. return rc;
  568. } else {
  569. return -EINVAL;
  570. }
  571. }
  572. *misr_value = SDE_REG_READ(c, INTF_MISR_SIGNATURE);
  573. return rc;
  574. }
  575. static u32 sde_hw_intf_get_line_count(struct sde_hw_intf *intf)
  576. {
  577. struct sde_hw_blk_reg_map *c;
  578. if (!intf)
  579. return 0;
  580. c = &intf->hw;
  581. return SDE_REG_READ(c, INTF_LINE_COUNT) & 0xffff;
  582. }
  583. static u32 sde_hw_intf_get_underrun_line_count(struct sde_hw_intf *intf)
  584. {
  585. struct sde_hw_blk_reg_map *c;
  586. u32 hsync_period;
  587. if (!intf)
  588. return 0;
  589. c = &intf->hw;
  590. hsync_period = SDE_REG_READ(c, INTF_HSYNC_CTL);
  591. hsync_period = ((hsync_period & 0xffff0000) >> 16);
  592. return hsync_period ?
  593. SDE_REG_READ(c, INTF_UNDERRUN_COUNT) / hsync_period :
  594. 0xebadebad;
  595. }
  596. static u32 sde_hw_intf_get_intr_status(struct sde_hw_intf *intf)
  597. {
  598. if (!intf)
  599. return -EINVAL;
  600. return SDE_REG_READ(&intf->hw, INTF_INTR_STATUS);
  601. }
  602. static int sde_hw_intf_setup_te_config(struct sde_hw_intf *intf,
  603. struct sde_hw_tear_check *te)
  604. {
  605. struct sde_hw_blk_reg_map *c;
  606. u32 cfg = 0, val;
  607. spinlock_t tearcheck_spinlock;
  608. if (!intf)
  609. return -EINVAL;
  610. spin_lock_init(&tearcheck_spinlock);
  611. c = &intf->hw;
  612. if (te->hw_vsync_mode)
  613. cfg |= BIT(20);
  614. cfg |= te->vsync_count;
  615. /*
  616. * Local spinlock is acquired here to avoid pre-emption
  617. * as below register programming should be completed in
  618. * less than 2^16 vsync clk cycles.
  619. */
  620. spin_lock(&tearcheck_spinlock);
  621. val = te->start_pos + te->sync_threshold_start + 1;
  622. if (intf->cap->features & BIT(SDE_INTF_TE_32BIT))
  623. SDE_REG_WRITE(c, INTF_TEAR_SYNC_WRCOUNT_EXT, (val >> 16));
  624. SDE_REG_WRITE(c, INTF_TEAR_SYNC_WRCOUNT, (val & 0xffff));
  625. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_VSYNC, cfg);
  626. wmb(); /* disable vsync counter before updating single buffer registers */
  627. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_HEIGHT, te->sync_cfg_height);
  628. SDE_REG_WRITE(c, INTF_TEAR_VSYNC_INIT_VAL, te->vsync_init_val);
  629. SDE_REG_WRITE(c, INTF_TEAR_RD_PTR_IRQ, te->rd_ptr_irq);
  630. SDE_REG_WRITE(c, INTF_TEAR_WR_PTR_IRQ, te->wr_ptr_irq);
  631. SDE_REG_WRITE(c, INTF_TEAR_START_POS, te->start_pos);
  632. if (intf->cap->features & BIT(SDE_INTF_TE_32BIT))
  633. SDE_REG_WRITE(c, INTF_TEAR_SYNC_THRESH_EXT,
  634. ((te->sync_threshold_continue & 0xffff0000) |
  635. (te->sync_threshold_start >> 16)));
  636. SDE_REG_WRITE(c, INTF_TEAR_SYNC_THRESH,
  637. ((te->sync_threshold_continue << 16) |
  638. (te->sync_threshold_start & 0xffff)));
  639. cfg |= BIT(19); /* VSYNC_COUNTER_EN */
  640. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_VSYNC, cfg);
  641. spin_unlock(&tearcheck_spinlock);
  642. return 0;
  643. }
  644. static int sde_hw_intf_setup_autorefresh_config(struct sde_hw_intf *intf,
  645. struct sde_hw_autorefresh *cfg)
  646. {
  647. struct sde_hw_blk_reg_map *c;
  648. u32 refresh_cfg;
  649. if (!intf || !cfg)
  650. return -EINVAL;
  651. c = &intf->hw;
  652. refresh_cfg = SDE_REG_READ(c, INTF_TEAR_AUTOREFRESH_CONFIG);
  653. if (cfg->enable)
  654. refresh_cfg = BIT(31) | cfg->frame_count;
  655. else
  656. refresh_cfg &= ~BIT(31);
  657. SDE_REG_WRITE(c, INTF_TEAR_AUTOREFRESH_CONFIG, refresh_cfg);
  658. return 0;
  659. }
  660. static int sde_hw_intf_get_autorefresh_config(struct sde_hw_intf *intf,
  661. struct sde_hw_autorefresh *cfg)
  662. {
  663. struct sde_hw_blk_reg_map *c;
  664. u32 val;
  665. if (!intf || !cfg)
  666. return -EINVAL;
  667. c = &intf->hw;
  668. val = SDE_REG_READ(c, INTF_TEAR_AUTOREFRESH_CONFIG);
  669. cfg->enable = (val & BIT(31)) >> 31;
  670. cfg->frame_count = val & 0xffff;
  671. return 0;
  672. }
  673. static int sde_hw_intf_poll_timeout_wr_ptr(struct sde_hw_intf *intf,
  674. u32 timeout_us)
  675. {
  676. struct sde_hw_blk_reg_map *c;
  677. u32 val, mask = 0;
  678. if (!intf)
  679. return -EINVAL;
  680. if (intf->cap->features & BIT(SDE_INTF_TE_32BIT))
  681. mask = 0xffffffff;
  682. else
  683. mask = 0xffff;
  684. c = &intf->hw;
  685. return read_poll_timeout(sde_reg_read, val, (val & mask) >= 1, 10, false, timeout_us,
  686. c, INTF_TEAR_LINE_COUNT);
  687. }
  688. static int sde_hw_intf_enable_te(struct sde_hw_intf *intf, bool enable)
  689. {
  690. struct sde_hw_blk_reg_map *c;
  691. uint32_t val = 0;
  692. if (!intf)
  693. return -EINVAL;
  694. c = &intf->hw;
  695. if (enable)
  696. val |= BIT(0);
  697. if (intf->cap->features & BIT(SDE_INTF_TE_SINGLE_UPDATE))
  698. val |= BIT(3);
  699. SDE_REG_WRITE(c, INTF_TEAR_TEAR_CHECK_EN, val);
  700. if (enable && (intf->cap->features & (BIT(SDE_INTF_PANEL_VSYNC_TS) | BIT(SDE_INTF_MDP_VSYNC_TS))))
  701. SDE_REG_WRITE(c, INTF_VSYNC_TIMESTAMP_CTRL, BIT(0));
  702. return 0;
  703. }
  704. static void sde_hw_intf_update_te(struct sde_hw_intf *intf,
  705. struct sde_hw_tear_check *te)
  706. {
  707. struct sde_hw_blk_reg_map *c;
  708. int cfg;
  709. if (!intf || !te)
  710. return;
  711. c = &intf->hw;
  712. cfg = SDE_REG_READ(c, INTF_TEAR_SYNC_THRESH);
  713. cfg &= ~0xFFFF;
  714. cfg |= te->sync_threshold_start;
  715. SDE_REG_WRITE(c, INTF_TEAR_SYNC_THRESH, cfg);
  716. }
  717. static int sde_hw_intf_connect_external_te(struct sde_hw_intf *intf,
  718. bool enable_external_te)
  719. {
  720. struct sde_hw_blk_reg_map *c = &intf->hw;
  721. u32 cfg;
  722. int orig;
  723. if (!intf)
  724. return -EINVAL;
  725. c = &intf->hw;
  726. cfg = SDE_REG_READ(c, INTF_TEAR_SYNC_CONFIG_VSYNC);
  727. orig = (bool)(cfg & BIT(20));
  728. if (enable_external_te)
  729. cfg |= BIT(20);
  730. else
  731. cfg &= ~BIT(20);
  732. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_VSYNC, cfg);
  733. return orig;
  734. }
  735. static int sde_hw_intf_get_vsync_info(struct sde_hw_intf *intf,
  736. struct sde_hw_pp_vsync_info *info)
  737. {
  738. struct sde_hw_blk_reg_map *c = &intf->hw;
  739. u32 val;
  740. if (!intf || !info)
  741. return -EINVAL;
  742. c = &intf->hw;
  743. val = SDE_REG_READ(c, INTF_TEAR_VSYNC_INIT_VAL);
  744. if (intf->cap->features & BIT(SDE_INTF_TE_32BIT))
  745. info->rd_ptr_init_val = val;
  746. else
  747. info->rd_ptr_init_val = val & 0xffff;
  748. val = SDE_REG_READ(c, INTF_TEAR_INT_COUNT_VAL);
  749. info->rd_ptr_frame_count = (val & 0xffff0000) >> 16;
  750. info->rd_ptr_line_count = val & 0xffff;
  751. if (intf->cap->features & BIT(SDE_INTF_TE_32BIT)) {
  752. val = SDE_REG_READ(c, INTF_TEAR_INT_COUNT_VAL_EXT);
  753. info->rd_ptr_line_count |= (val << 16);
  754. }
  755. val = SDE_REG_READ(c, INTF_TEAR_LINE_COUNT);
  756. info->wr_ptr_line_count = val;
  757. val = sde_hw_intf_get_frame_count(intf);
  758. info->intf_frame_count = val;
  759. return 0;
  760. }
  761. static int sde_hw_intf_v1_check_and_reset_tearcheck(struct sde_hw_intf *intf,
  762. struct intf_tear_status *status)
  763. {
  764. struct sde_hw_blk_reg_map *c = &intf->hw;
  765. u32 start_pos, val;
  766. if (!intf || !status)
  767. return -EINVAL;
  768. c = &intf->hw;
  769. status->read_line_count = SDE_REG_READ(c, INTF_TEAR_INT_COUNT_VAL);
  770. if (intf->cap->features & BIT(SDE_INTF_TE_32BIT))
  771. status->read_line_count |= (SDE_REG_READ(c, INTF_TEAR_INT_COUNT_VAL_EXT) << 16);
  772. start_pos = SDE_REG_READ(c, INTF_TEAR_START_POS);
  773. val = SDE_REG_READ(c, INTF_TEAR_SYNC_WRCOUNT);
  774. status->write_frame_count = val >> 16;
  775. status->write_line_count = start_pos;
  776. if (intf->cap->features & BIT(SDE_INTF_TE_32BIT)) {
  777. val = (status->write_line_count & 0xffff0000) >> 16;
  778. SDE_REG_WRITE(c, INTF_TEAR_SYNC_WRCOUNT_EXT, val);
  779. }
  780. val = (status->write_frame_count << 16) | (status->write_line_count & 0xffff);
  781. SDE_REG_WRITE(c, INTF_TEAR_SYNC_WRCOUNT, val);
  782. return 0;
  783. }
  784. static void sde_hw_intf_override_tear_rd_ptr_val(struct sde_hw_intf *intf,
  785. u32 adjusted_rd_ptr_val)
  786. {
  787. struct sde_hw_blk_reg_map *c;
  788. if (!intf || !adjusted_rd_ptr_val)
  789. return;
  790. c = &intf->hw;
  791. SDE_REG_WRITE(c, INTF_TEAR_SYNC_WRCOUNT, (adjusted_rd_ptr_val & 0xFFFF));
  792. /* ensure rd_ptr_val is written */
  793. wmb();
  794. }
  795. static void sde_hw_intf_vsync_sel(struct sde_hw_intf *intf,
  796. u32 vsync_source)
  797. {
  798. struct sde_hw_blk_reg_map *c;
  799. if (!intf)
  800. return;
  801. c = &intf->hw;
  802. SDE_REG_WRITE(c, INTF_TEAR_MDP_VSYNC_SEL, (vsync_source & 0xf));
  803. }
  804. static void sde_hw_intf_enable_compressed_input(struct sde_hw_intf *intf,
  805. bool compression_en, bool dsc_4hs_merge)
  806. {
  807. struct sde_hw_blk_reg_map *c;
  808. u32 intf_cfg2;
  809. if (!intf)
  810. return;
  811. /*
  812. * callers can either call this function to enable/disable the 64 bit
  813. * compressed input or this configuration can be applied along
  814. * with timing generation parameters
  815. */
  816. c = &intf->hw;
  817. intf_cfg2 = SDE_REG_READ(c, INTF_CONFIG2);
  818. _check_and_set_comp_bit(intf, dsc_4hs_merge, compression_en,
  819. &intf_cfg2);
  820. SDE_REG_WRITE(c, INTF_CONFIG2, intf_cfg2);
  821. }
  822. static void sde_hw_intf_enable_wide_bus(struct sde_hw_intf *intf,
  823. bool enable)
  824. {
  825. struct sde_hw_blk_reg_map *c;
  826. u32 intf_cfg2;
  827. if (!intf)
  828. return;
  829. c = &intf->hw;
  830. intf_cfg2 = SDE_REG_READ(c, INTF_CONFIG2);
  831. intf_cfg2 &= ~BIT(0);
  832. intf_cfg2 |= enable ? BIT(0) : 0;
  833. SDE_REG_WRITE(c, INTF_CONFIG2, intf_cfg2);
  834. }
  835. static void _setup_intf_ops(struct sde_hw_intf_ops *ops,
  836. unsigned long cap)
  837. {
  838. ops->setup_timing_gen = sde_hw_intf_setup_timing_engine;
  839. ops->setup_prg_fetch = sde_hw_intf_setup_prg_fetch;
  840. ops->enable_timing = sde_hw_intf_enable_timing_engine;
  841. ops->setup_misr = sde_hw_intf_setup_misr;
  842. ops->collect_misr = sde_hw_intf_collect_misr;
  843. ops->get_line_count = sde_hw_intf_get_line_count;
  844. ops->get_underrun_line_count = sde_hw_intf_get_underrun_line_count;
  845. ops->get_intr_status = sde_hw_intf_get_intr_status;
  846. ops->avr_setup = sde_hw_intf_avr_setup;
  847. ops->avr_trigger = sde_hw_intf_avr_trigger;
  848. ops->avr_ctrl = sde_hw_intf_avr_ctrl;
  849. ops->enable_compressed_input = sde_hw_intf_enable_compressed_input;
  850. ops->enable_wide_bus = sde_hw_intf_enable_wide_bus;
  851. if (cap & BIT(SDE_INTF_STATUS))
  852. ops->get_status = sde_hw_intf_v1_get_status;
  853. else
  854. ops->get_status = sde_hw_intf_get_status;
  855. if (cap & BIT(SDE_INTF_INPUT_CTRL))
  856. ops->bind_pingpong_blk = sde_hw_intf_bind_pingpong_blk;
  857. if (cap & BIT(SDE_INTF_WD_TIMER))
  858. ops->setup_vsync_source = sde_hw_intf_setup_vsync_source;
  859. if (cap & BIT(SDE_INTF_AVR_STATUS))
  860. ops->get_avr_status = sde_hw_intf_get_avr_status;
  861. if (cap & BIT(SDE_INTF_TE)) {
  862. ops->setup_tearcheck = sde_hw_intf_setup_te_config;
  863. ops->enable_tearcheck = sde_hw_intf_enable_te;
  864. ops->update_tearcheck = sde_hw_intf_update_te;
  865. ops->connect_external_te = sde_hw_intf_connect_external_te;
  866. ops->get_vsync_info = sde_hw_intf_get_vsync_info;
  867. ops->setup_autorefresh = sde_hw_intf_setup_autorefresh_config;
  868. ops->get_autorefresh = sde_hw_intf_get_autorefresh_config;
  869. ops->poll_timeout_wr_ptr = sde_hw_intf_poll_timeout_wr_ptr;
  870. ops->vsync_sel = sde_hw_intf_vsync_sel;
  871. ops->check_and_reset_tearcheck =
  872. sde_hw_intf_v1_check_and_reset_tearcheck;
  873. ops->override_tear_rd_ptr_val =
  874. sde_hw_intf_override_tear_rd_ptr_val;
  875. }
  876. if (cap & BIT(SDE_INTF_RESET_COUNTER))
  877. ops->reset_counter = sde_hw_intf_reset_counter;
  878. if (cap & (BIT(SDE_INTF_PANEL_VSYNC_TS) | BIT(SDE_INTF_MDP_VSYNC_TS)))
  879. ops->get_vsync_timestamp = sde_hw_intf_get_vsync_timestamp;
  880. if (cap & BIT(SDE_INTF_WD_JITTER))
  881. ops->configure_wd_jitter = sde_hw_intf_configure_wd_timer_jitter;
  882. if (cap & BIT(SDE_INTF_WD_LTJ_CTL))
  883. ops->get_wd_ltj_status = sde_hw_intf_read_wd_ltj_ctl;
  884. }
  885. struct sde_hw_blk_reg_map *sde_hw_intf_init(enum sde_intf idx,
  886. void __iomem *addr,
  887. struct sde_mdss_cfg *m)
  888. {
  889. struct sde_hw_intf *c;
  890. struct sde_intf_cfg *cfg;
  891. c = kzalloc(sizeof(*c), GFP_KERNEL);
  892. if (!c)
  893. return ERR_PTR(-ENOMEM);
  894. cfg = _intf_offset(idx, m, addr, &c->hw);
  895. if (IS_ERR_OR_NULL(cfg)) {
  896. kfree(c);
  897. pr_err("failed to create sde_hw_intf %d\n", idx);
  898. return ERR_PTR(-EINVAL);
  899. }
  900. /*
  901. * Assign ops
  902. */
  903. c->idx = idx;
  904. c->cap = cfg;
  905. c->mdss = m;
  906. _setup_intf_ops(&c->ops, c->cap->features);
  907. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
  908. c->hw.blk_off + c->hw.length, c->hw.xin_id);
  909. return &c->hw;
  910. }
  911. void sde_hw_intf_destroy(struct sde_hw_blk_reg_map *hw)
  912. {
  913. if (hw)
  914. kfree(to_sde_hw_intf(hw));
  915. }