sde_hw_intf.c 32 KB

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