sde_hw_intf.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/iopoll.h>
  6. #include "sde_hwio.h"
  7. #include "sde_hw_catalog.h"
  8. #include "sde_hw_intf.h"
  9. #include "sde_dbg.h"
  10. #define INTF_TIMING_ENGINE_EN 0x000
  11. #define INTF_CONFIG 0x004
  12. #define INTF_HSYNC_CTL 0x008
  13. #define INTF_VSYNC_PERIOD_F0 0x00C
  14. #define INTF_VSYNC_PERIOD_F1 0x010
  15. #define INTF_VSYNC_PULSE_WIDTH_F0 0x014
  16. #define INTF_VSYNC_PULSE_WIDTH_F1 0x018
  17. #define INTF_DISPLAY_V_START_F0 0x01C
  18. #define INTF_DISPLAY_V_START_F1 0x020
  19. #define INTF_DISPLAY_V_END_F0 0x024
  20. #define INTF_DISPLAY_V_END_F1 0x028
  21. #define INTF_ACTIVE_V_START_F0 0x02C
  22. #define INTF_ACTIVE_V_START_F1 0x030
  23. #define INTF_ACTIVE_V_END_F0 0x034
  24. #define INTF_ACTIVE_V_END_F1 0x038
  25. #define INTF_DISPLAY_HCTL 0x03C
  26. #define INTF_ACTIVE_HCTL 0x040
  27. #define INTF_BORDER_COLOR 0x044
  28. #define INTF_UNDERFLOW_COLOR 0x048
  29. #define INTF_HSYNC_SKEW 0x04C
  30. #define INTF_POLARITY_CTL 0x050
  31. #define INTF_TEST_CTL 0x054
  32. #define INTF_TP_COLOR0 0x058
  33. #define INTF_TP_COLOR1 0x05C
  34. #define INTF_CONFIG2 0x060
  35. #define INTF_DISPLAY_DATA_HCTL 0x064
  36. #define INTF_ACTIVE_DATA_HCTL 0x068
  37. #define INTF_FRAME_LINE_COUNT_EN 0x0A8
  38. #define INTF_FRAME_COUNT 0x0AC
  39. #define INTF_LINE_COUNT 0x0B0
  40. #define INTF_DEFLICKER_CONFIG 0x0F0
  41. #define INTF_DEFLICKER_STRNG_COEFF 0x0F4
  42. #define INTF_DEFLICKER_WEAK_COEFF 0x0F8
  43. #define INTF_REG_SPLIT_LINK 0x080
  44. #define INTF_DSI_CMD_MODE_TRIGGER_EN 0x084
  45. #define INTF_PANEL_FORMAT 0x090
  46. #define INTF_TPG_ENABLE 0x100
  47. #define INTF_TPG_MAIN_CONTROL 0x104
  48. #define INTF_TPG_VIDEO_CONFIG 0x108
  49. #define INTF_TPG_COMPONENT_LIMITS 0x10C
  50. #define INTF_TPG_RECTANGLE 0x110
  51. #define INTF_TPG_INITIAL_VALUE 0x114
  52. #define INTF_TPG_BLK_WHITE_PATTERN_FRAMES 0x118
  53. #define INTF_TPG_RGB_MAPPING 0x11C
  54. #define INTF_PROG_FETCH_START 0x170
  55. #define INTF_PROG_ROT_START 0x174
  56. #define INTF_MISR_CTRL 0x180
  57. #define INTF_MISR_SIGNATURE 0x184
  58. #define INTF_MUX 0x25C
  59. #define INTF_UNDERRUN_COUNT 0x268
  60. #define INTF_STATUS 0x26C
  61. #define INTF_AVR_CONTROL 0x270
  62. #define INTF_AVR_MODE 0x274
  63. #define INTF_AVR_TRIGGER 0x278
  64. #define INTF_AVR_VTOTAL 0x27C
  65. #define INTF_TEAR_MDP_VSYNC_SEL 0x280
  66. #define INTF_TEAR_TEAR_CHECK_EN 0x284
  67. #define INTF_TEAR_SYNC_CONFIG_VSYNC 0x288
  68. #define INTF_TEAR_SYNC_CONFIG_HEIGHT 0x28C
  69. #define INTF_TEAR_SYNC_WRCOUNT 0x290
  70. #define INTF_TEAR_VSYNC_INIT_VAL 0x294
  71. #define INTF_TEAR_INT_COUNT_VAL 0x298
  72. #define INTF_TEAR_SYNC_THRESH 0x29C
  73. #define INTF_TEAR_START_POS 0x2A0
  74. #define INTF_TEAR_RD_PTR_IRQ 0x2A4
  75. #define INTF_TEAR_WR_PTR_IRQ 0x2A8
  76. #define INTF_TEAR_OUT_LINE_COUNT 0x2AC
  77. #define INTF_TEAR_LINE_COUNT 0x2B0
  78. #define INTF_TEAR_AUTOREFRESH_CONFIG 0x2B4
  79. #define INTF_TEAR_TEAR_DETECT_CTRL 0x2B8
  80. static struct sde_intf_cfg *_intf_offset(enum sde_intf intf,
  81. struct sde_mdss_cfg *m,
  82. void __iomem *addr,
  83. struct sde_hw_blk_reg_map *b)
  84. {
  85. int i;
  86. for (i = 0; i < m->intf_count; i++) {
  87. if ((intf == m->intf[i].id) &&
  88. (m->intf[i].type != INTF_NONE)) {
  89. b->base_off = addr;
  90. b->blk_off = m->intf[i].base;
  91. b->length = m->intf[i].len;
  92. b->hwversion = m->hwversion;
  93. b->log_mask = SDE_DBG_MASK_INTF;
  94. return &m->intf[i];
  95. }
  96. }
  97. return ERR_PTR(-EINVAL);
  98. }
  99. static void sde_hw_intf_avr_trigger(struct sde_hw_intf *ctx)
  100. {
  101. struct sde_hw_blk_reg_map *c;
  102. if (!ctx)
  103. return;
  104. c = &ctx->hw;
  105. SDE_REG_WRITE(c, INTF_AVR_TRIGGER, 0x1);
  106. SDE_DEBUG("AVR Triggered\n");
  107. }
  108. static int sde_hw_intf_avr_setup(struct sde_hw_intf *ctx,
  109. const struct intf_timing_params *params,
  110. const struct intf_avr_params *avr_params)
  111. {
  112. struct sde_hw_blk_reg_map *c;
  113. u32 hsync_period, vsync_period;
  114. u32 min_fps, default_fps, diff_fps;
  115. u32 vsync_period_slow;
  116. u32 avr_vtotal;
  117. u32 add_porches = 0;
  118. if (!ctx || !params || !avr_params) {
  119. SDE_ERROR("invalid input parameter(s)\n");
  120. return -EINVAL;
  121. }
  122. c = &ctx->hw;
  123. min_fps = avr_params->min_fps;
  124. default_fps = avr_params->default_fps;
  125. diff_fps = default_fps - min_fps;
  126. hsync_period = params->hsync_pulse_width +
  127. params->h_back_porch + params->width +
  128. params->h_front_porch;
  129. vsync_period = params->vsync_pulse_width +
  130. params->v_back_porch + params->height +
  131. params->v_front_porch;
  132. if (diff_fps)
  133. add_porches = mult_frac(vsync_period, diff_fps, min_fps);
  134. vsync_period_slow = vsync_period + add_porches;
  135. avr_vtotal = vsync_period_slow * hsync_period;
  136. SDE_REG_WRITE(c, INTF_AVR_VTOTAL, avr_vtotal);
  137. return 0;
  138. }
  139. static void sde_hw_intf_avr_ctrl(struct sde_hw_intf *ctx,
  140. const struct intf_avr_params *avr_params)
  141. {
  142. struct sde_hw_blk_reg_map *c;
  143. u32 avr_mode = 0;
  144. u32 avr_ctrl = 0;
  145. if (!ctx || !avr_params)
  146. return;
  147. c = &ctx->hw;
  148. if (avr_params->avr_mode) {
  149. avr_ctrl = BIT(0);
  150. avr_mode =
  151. (avr_params->avr_mode == SDE_RM_QSYNC_ONE_SHOT_MODE) ?
  152. (BIT(0) | BIT(8)) : 0x0;
  153. }
  154. SDE_REG_WRITE(c, INTF_AVR_CONTROL, avr_ctrl);
  155. SDE_REG_WRITE(c, INTF_AVR_MODE, avr_mode);
  156. }
  157. static inline void _check_and_set_comp_bit(struct sde_hw_intf *ctx,
  158. bool dsc_4hs_merge, bool compression_en, u32 *intf_cfg2)
  159. {
  160. if (((SDE_HW_MAJOR(ctx->mdss->hwversion) >=
  161. SDE_HW_MAJOR(SDE_HW_VER_700)) &&
  162. compression_en) ||
  163. (IS_SDE_MAJOR_SAME(ctx->mdss->hwversion,
  164. SDE_HW_VER_600) && dsc_4hs_merge))
  165. (*intf_cfg2) |= BIT(12);
  166. }
  167. static void sde_hw_intf_setup_timing_engine(struct sde_hw_intf *ctx,
  168. const struct intf_timing_params *p,
  169. const struct sde_format *fmt)
  170. {
  171. struct sde_hw_blk_reg_map *c = &ctx->hw;
  172. u32 hsync_period, vsync_period;
  173. u32 display_v_start, display_v_end;
  174. u32 hsync_start_x, hsync_end_x;
  175. u32 hsync_data_start_x, hsync_data_end_x;
  176. u32 active_h_start, active_h_end;
  177. u32 active_v_start, active_v_end;
  178. u32 active_hctl, display_hctl, hsync_ctl;
  179. u32 polarity_ctl, den_polarity, hsync_polarity, vsync_polarity;
  180. u32 panel_format;
  181. u32 intf_cfg, intf_cfg2 = 0;
  182. u32 display_data_hctl = 0, active_data_hctl = 0;
  183. u32 data_width;
  184. bool dp_intf = false;
  185. /* read interface_cfg */
  186. intf_cfg = SDE_REG_READ(c, INTF_CONFIG);
  187. if (ctx->cap->type == INTF_EDP || ctx->cap->type == INTF_DP)
  188. dp_intf = true;
  189. hsync_period = p->hsync_pulse_width + p->h_back_porch + p->width +
  190. p->h_front_porch;
  191. vsync_period = p->vsync_pulse_width + p->v_back_porch + p->height +
  192. p->v_front_porch;
  193. display_v_start = ((p->vsync_pulse_width + p->v_back_porch) *
  194. hsync_period) + p->hsync_skew;
  195. display_v_end = ((vsync_period - p->v_front_porch) * hsync_period) +
  196. p->hsync_skew - 1;
  197. hsync_ctl = (hsync_period << 16) | p->hsync_pulse_width;
  198. hsync_start_x = p->h_back_porch + p->hsync_pulse_width;
  199. hsync_end_x = hsync_period - p->h_front_porch - 1;
  200. /*
  201. * DATA_HCTL_EN controls data timing which can be different from
  202. * video timing. It is recommended to enable it for all cases, except
  203. * if compression is enabled in 1 pixel per clock mode
  204. */
  205. if (!p->compression_en || p->wide_bus_en)
  206. intf_cfg2 |= BIT(4);
  207. if (p->wide_bus_en)
  208. intf_cfg2 |= BIT(0);
  209. /*
  210. * If widebus is disabled:
  211. * For uncompressed stream, the data is valid for the entire active
  212. * window period.
  213. * For compressed stream, data is valid for a shorter time period
  214. * inside the active window depending on the compression ratio.
  215. *
  216. * If widebus is enabled:
  217. * For uncompressed stream, data is valid for only half the active
  218. * window, since the data rate is doubled in this mode.
  219. * p->width holds the adjusted width for DP but unadjusted width for DSI
  220. * For compressed stream, data validity window needs to be adjusted for
  221. * compression ratio and then further halved.
  222. */
  223. data_width = p->width;
  224. if (p->compression_en) {
  225. data_width = DIV_ROUND_UP(p->dce_bytes_per_line, 3);
  226. if (p->wide_bus_en)
  227. data_width >>= 1;
  228. } else if (!dp_intf && p->wide_bus_en) {
  229. data_width = p->width >> 1;
  230. } else {
  231. data_width = p->width;
  232. }
  233. hsync_data_start_x = hsync_start_x;
  234. hsync_data_end_x = hsync_start_x + data_width - 1;
  235. display_hctl = (hsync_end_x << 16) | hsync_start_x;
  236. display_data_hctl = (hsync_data_end_x << 16) | hsync_data_start_x;
  237. if (dp_intf) {
  238. // DP timing adjustment
  239. display_v_start += p->hsync_pulse_width + p->h_back_porch;
  240. display_v_end -= p->h_front_porch;
  241. }
  242. intf_cfg |= BIT(29); /* ACTIVE_H_ENABLE */
  243. intf_cfg |= BIT(30); /* ACTIVE_V_ENABLE */
  244. active_h_start = hsync_start_x;
  245. active_h_end = active_h_start + p->xres - 1;
  246. active_v_start = display_v_start;
  247. active_v_end = active_v_start + (p->yres * hsync_period) - 1;
  248. active_hctl = (active_h_end << 16) | active_h_start;
  249. if (dp_intf) {
  250. display_hctl = active_hctl;
  251. if (p->compression_en) {
  252. active_data_hctl = (hsync_start_x +
  253. p->extra_dto_cycles) << 16;
  254. active_data_hctl += hsync_start_x;
  255. display_data_hctl = active_data_hctl;
  256. }
  257. }
  258. _check_and_set_comp_bit(ctx, p->dsc_4hs_merge, p->compression_en,
  259. &intf_cfg2);
  260. den_polarity = 0;
  261. if (ctx->cap->type == INTF_HDMI) {
  262. hsync_polarity = p->yres >= 720 ? 0 : 1;
  263. vsync_polarity = p->yres >= 720 ? 0 : 1;
  264. } else if (ctx->cap->type == INTF_DP) {
  265. hsync_polarity = p->hsync_polarity;
  266. vsync_polarity = p->vsync_polarity;
  267. } else {
  268. hsync_polarity = 0;
  269. vsync_polarity = 0;
  270. }
  271. polarity_ctl = (den_polarity << 2) | /* DEN Polarity */
  272. (vsync_polarity << 1) | /* VSYNC Polarity */
  273. (hsync_polarity << 0); /* HSYNC Polarity */
  274. if (!SDE_FORMAT_IS_YUV(fmt))
  275. panel_format = (fmt->bits[C0_G_Y] |
  276. (fmt->bits[C1_B_Cb] << 2) |
  277. (fmt->bits[C2_R_Cr] << 4) |
  278. (0x21 << 8));
  279. else
  280. /* Interface treats all the pixel data in RGB888 format */
  281. panel_format = (COLOR_8BIT |
  282. (COLOR_8BIT << 2) |
  283. (COLOR_8BIT << 4) |
  284. (0x21 << 8));
  285. if (p->wide_bus_en)
  286. intf_cfg2 |= BIT(0);
  287. /* Synchronize timing engine enable to TE */
  288. if ((ctx->cap->features & BIT(SDE_INTF_TE_ALIGN_VSYNC))
  289. && p->poms_align_vsync)
  290. intf_cfg2 |= BIT(16);
  291. if (ctx->cfg.split_link_en)
  292. SDE_REG_WRITE(c, INTF_REG_SPLIT_LINK, 0x3);
  293. SDE_REG_WRITE(c, INTF_HSYNC_CTL, hsync_ctl);
  294. SDE_REG_WRITE(c, INTF_VSYNC_PERIOD_F0, vsync_period * hsync_period);
  295. SDE_REG_WRITE(c, INTF_VSYNC_PULSE_WIDTH_F0,
  296. p->vsync_pulse_width * hsync_period);
  297. SDE_REG_WRITE(c, INTF_DISPLAY_HCTL, display_hctl);
  298. SDE_REG_WRITE(c, INTF_DISPLAY_V_START_F0, display_v_start);
  299. SDE_REG_WRITE(c, INTF_DISPLAY_V_END_F0, display_v_end);
  300. SDE_REG_WRITE(c, INTF_ACTIVE_HCTL, active_hctl);
  301. SDE_REG_WRITE(c, INTF_ACTIVE_V_START_F0, active_v_start);
  302. SDE_REG_WRITE(c, INTF_ACTIVE_V_END_F0, active_v_end);
  303. SDE_REG_WRITE(c, INTF_BORDER_COLOR, p->border_clr);
  304. SDE_REG_WRITE(c, INTF_UNDERFLOW_COLOR, p->underflow_clr);
  305. SDE_REG_WRITE(c, INTF_HSYNC_SKEW, p->hsync_skew);
  306. SDE_REG_WRITE(c, INTF_POLARITY_CTL, polarity_ctl);
  307. SDE_REG_WRITE(c, INTF_FRAME_LINE_COUNT_EN, 0x3);
  308. SDE_REG_WRITE(c, INTF_CONFIG, intf_cfg);
  309. SDE_REG_WRITE(c, INTF_PANEL_FORMAT, panel_format);
  310. SDE_REG_WRITE(c, INTF_CONFIG2, intf_cfg2);
  311. SDE_REG_WRITE(c, INTF_DISPLAY_DATA_HCTL, display_data_hctl);
  312. SDE_REG_WRITE(c, INTF_ACTIVE_DATA_HCTL, active_data_hctl);
  313. }
  314. static void sde_hw_intf_enable_timing_engine(
  315. struct sde_hw_intf *intf,
  316. u8 enable)
  317. {
  318. struct sde_hw_blk_reg_map *c = &intf->hw;
  319. /* Note: Display interface select is handled in top block hw layer */
  320. SDE_REG_WRITE(c, INTF_TIMING_ENGINE_EN, enable != 0);
  321. }
  322. static void sde_hw_intf_setup_prg_fetch(
  323. struct sde_hw_intf *intf,
  324. const struct intf_prog_fetch *fetch)
  325. {
  326. struct sde_hw_blk_reg_map *c = &intf->hw;
  327. int fetch_enable;
  328. /*
  329. * Fetch should always be outside the active lines. If the fetching
  330. * is programmed within active region, hardware behavior is unknown.
  331. */
  332. fetch_enable = SDE_REG_READ(c, INTF_CONFIG);
  333. if (fetch->enable) {
  334. fetch_enable |= BIT(31);
  335. SDE_REG_WRITE(c, INTF_PROG_FETCH_START,
  336. fetch->fetch_start);
  337. } else {
  338. fetch_enable &= ~BIT(31);
  339. }
  340. SDE_REG_WRITE(c, INTF_CONFIG, fetch_enable);
  341. }
  342. static void sde_hw_intf_bind_pingpong_blk(
  343. struct sde_hw_intf *intf,
  344. bool enable,
  345. const enum sde_pingpong pp)
  346. {
  347. struct sde_hw_blk_reg_map *c;
  348. u32 mux_cfg;
  349. if (!intf)
  350. return;
  351. c = &intf->hw;
  352. mux_cfg = SDE_REG_READ(c, INTF_MUX);
  353. mux_cfg &= ~0xf;
  354. if (enable) {
  355. mux_cfg |= (pp - PINGPONG_0) & 0x7;
  356. if (intf->cfg.split_link_en)
  357. mux_cfg = 0x60000;
  358. } else {
  359. mux_cfg = 0xf000f;
  360. }
  361. SDE_REG_WRITE(c, INTF_MUX, mux_cfg);
  362. }
  363. static void sde_hw_intf_get_status(
  364. struct sde_hw_intf *intf,
  365. struct intf_status *s)
  366. {
  367. struct sde_hw_blk_reg_map *c = &intf->hw;
  368. s->is_en = SDE_REG_READ(c, INTF_TIMING_ENGINE_EN);
  369. if (s->is_en) {
  370. s->frame_count = SDE_REG_READ(c, INTF_FRAME_COUNT);
  371. s->line_count = SDE_REG_READ(c, INTF_LINE_COUNT);
  372. } else {
  373. s->line_count = 0;
  374. s->frame_count = 0;
  375. }
  376. }
  377. static void sde_hw_intf_v1_get_status(
  378. struct sde_hw_intf *intf,
  379. struct intf_status *s)
  380. {
  381. struct sde_hw_blk_reg_map *c = &intf->hw;
  382. s->is_en = SDE_REG_READ(c, INTF_STATUS) & BIT(0);
  383. if (s->is_en) {
  384. s->frame_count = SDE_REG_READ(c, INTF_FRAME_COUNT);
  385. s->line_count = SDE_REG_READ(c, INTF_LINE_COUNT);
  386. } else {
  387. s->line_count = 0;
  388. s->frame_count = 0;
  389. }
  390. }
  391. static void sde_hw_intf_setup_misr(struct sde_hw_intf *intf,
  392. bool enable, u32 frame_count)
  393. {
  394. struct sde_hw_blk_reg_map *c = &intf->hw;
  395. u32 config = 0;
  396. SDE_REG_WRITE(c, INTF_MISR_CTRL, MISR_CTRL_STATUS_CLEAR);
  397. /* clear misr data */
  398. wmb();
  399. if (enable)
  400. config = (frame_count & MISR_FRAME_COUNT_MASK) |
  401. MISR_CTRL_ENABLE |
  402. INTF_MISR_CTRL_FREE_RUN_MASK |
  403. INTF_MISR_CTRL_INPUT_SEL_DATA;
  404. SDE_REG_WRITE(c, INTF_MISR_CTRL, config);
  405. }
  406. static int sde_hw_intf_collect_misr(struct sde_hw_intf *intf, bool nonblock,
  407. u32 *misr_value)
  408. {
  409. struct sde_hw_blk_reg_map *c = &intf->hw;
  410. u32 ctrl = 0;
  411. if (!misr_value)
  412. return -EINVAL;
  413. ctrl = SDE_REG_READ(c, INTF_MISR_CTRL);
  414. if (!nonblock) {
  415. if (ctrl & MISR_CTRL_ENABLE) {
  416. int rc;
  417. rc = readl_poll_timeout(c->base_off + c->blk_off +
  418. INTF_MISR_CTRL, ctrl,
  419. (ctrl & MISR_CTRL_STATUS) > 0, 500,
  420. 84000);
  421. if (rc)
  422. return rc;
  423. } else {
  424. return -EINVAL;
  425. }
  426. }
  427. *misr_value = SDE_REG_READ(c, INTF_MISR_SIGNATURE);
  428. return 0;
  429. }
  430. static u32 sde_hw_intf_get_line_count(struct sde_hw_intf *intf)
  431. {
  432. struct sde_hw_blk_reg_map *c;
  433. if (!intf)
  434. return 0;
  435. c = &intf->hw;
  436. return SDE_REG_READ(c, INTF_LINE_COUNT);
  437. }
  438. static u32 sde_hw_intf_get_underrun_line_count(struct sde_hw_intf *intf)
  439. {
  440. struct sde_hw_blk_reg_map *c;
  441. u32 hsync_period;
  442. if (!intf)
  443. return 0;
  444. c = &intf->hw;
  445. hsync_period = SDE_REG_READ(c, INTF_HSYNC_CTL);
  446. hsync_period = ((hsync_period & 0xffff0000) >> 16);
  447. return hsync_period ?
  448. SDE_REG_READ(c, INTF_UNDERRUN_COUNT) / hsync_period :
  449. 0xebadebad;
  450. }
  451. static int sde_hw_intf_setup_te_config(struct sde_hw_intf *intf,
  452. struct sde_hw_tear_check *te)
  453. {
  454. struct sde_hw_blk_reg_map *c;
  455. int cfg;
  456. if (!intf)
  457. return -EINVAL;
  458. c = &intf->hw;
  459. cfg = BIT(19); /* VSYNC_COUNTER_EN */
  460. if (te->hw_vsync_mode)
  461. cfg |= BIT(20);
  462. cfg |= te->vsync_count;
  463. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_VSYNC, cfg);
  464. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_HEIGHT, te->sync_cfg_height);
  465. SDE_REG_WRITE(c, INTF_TEAR_VSYNC_INIT_VAL, te->vsync_init_val);
  466. SDE_REG_WRITE(c, INTF_TEAR_RD_PTR_IRQ, te->rd_ptr_irq);
  467. SDE_REG_WRITE(c, INTF_TEAR_WR_PTR_IRQ, te->wr_ptr_irq);
  468. SDE_REG_WRITE(c, INTF_TEAR_START_POS, te->start_pos);
  469. SDE_REG_WRITE(c, INTF_TEAR_SYNC_THRESH,
  470. ((te->sync_threshold_continue << 16) |
  471. te->sync_threshold_start));
  472. SDE_REG_WRITE(c, INTF_TEAR_SYNC_WRCOUNT,
  473. (te->start_pos + te->sync_threshold_start + 1));
  474. return 0;
  475. }
  476. static int sde_hw_intf_setup_autorefresh_config(struct sde_hw_intf *intf,
  477. struct sde_hw_autorefresh *cfg)
  478. {
  479. struct sde_hw_blk_reg_map *c;
  480. u32 refresh_cfg;
  481. if (!intf || !cfg)
  482. return -EINVAL;
  483. c = &intf->hw;
  484. refresh_cfg = SDE_REG_READ(c, INTF_TEAR_AUTOREFRESH_CONFIG);
  485. if (cfg->enable)
  486. refresh_cfg = BIT(31) | cfg->frame_count;
  487. else
  488. refresh_cfg &= ~BIT(31);
  489. SDE_REG_WRITE(c, INTF_TEAR_AUTOREFRESH_CONFIG, refresh_cfg);
  490. return 0;
  491. }
  492. static int sde_hw_intf_get_autorefresh_config(struct sde_hw_intf *intf,
  493. struct sde_hw_autorefresh *cfg)
  494. {
  495. struct sde_hw_blk_reg_map *c;
  496. u32 val;
  497. if (!intf || !cfg)
  498. return -EINVAL;
  499. c = &intf->hw;
  500. val = SDE_REG_READ(c, INTF_TEAR_AUTOREFRESH_CONFIG);
  501. cfg->enable = (val & BIT(31)) >> 31;
  502. cfg->frame_count = val & 0xffff;
  503. return 0;
  504. }
  505. static int sde_hw_intf_poll_timeout_wr_ptr(struct sde_hw_intf *intf,
  506. u32 timeout_us)
  507. {
  508. struct sde_hw_blk_reg_map *c;
  509. u32 val;
  510. int rc;
  511. if (!intf)
  512. return -EINVAL;
  513. c = &intf->hw;
  514. rc = readl_poll_timeout(c->base_off + c->blk_off + INTF_TEAR_LINE_COUNT,
  515. val, (val & 0xffff) >= 1, 10, timeout_us);
  516. return rc;
  517. }
  518. static int sde_hw_intf_enable_te(struct sde_hw_intf *intf, bool enable)
  519. {
  520. struct sde_hw_blk_reg_map *c;
  521. if (!intf)
  522. return -EINVAL;
  523. c = &intf->hw;
  524. SDE_REG_WRITE(c, INTF_TEAR_TEAR_CHECK_EN, enable);
  525. return 0;
  526. }
  527. static void sde_hw_intf_update_te(struct sde_hw_intf *intf,
  528. struct sde_hw_tear_check *te)
  529. {
  530. struct sde_hw_blk_reg_map *c;
  531. int cfg;
  532. if (!intf || !te)
  533. return;
  534. c = &intf->hw;
  535. cfg = SDE_REG_READ(c, INTF_TEAR_SYNC_THRESH);
  536. cfg &= ~0xFFFF;
  537. cfg |= te->sync_threshold_start;
  538. SDE_REG_WRITE(c, INTF_TEAR_SYNC_THRESH, cfg);
  539. }
  540. static int sde_hw_intf_connect_external_te(struct sde_hw_intf *intf,
  541. bool enable_external_te)
  542. {
  543. struct sde_hw_blk_reg_map *c = &intf->hw;
  544. u32 cfg;
  545. int orig;
  546. if (!intf)
  547. return -EINVAL;
  548. c = &intf->hw;
  549. cfg = SDE_REG_READ(c, INTF_TEAR_SYNC_CONFIG_VSYNC);
  550. orig = (bool)(cfg & BIT(20));
  551. if (enable_external_te)
  552. cfg |= BIT(20);
  553. else
  554. cfg &= ~BIT(20);
  555. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_VSYNC, cfg);
  556. return orig;
  557. }
  558. static int sde_hw_intf_get_vsync_info(struct sde_hw_intf *intf,
  559. struct sde_hw_pp_vsync_info *info)
  560. {
  561. struct sde_hw_blk_reg_map *c = &intf->hw;
  562. u32 val;
  563. if (!intf || !info)
  564. return -EINVAL;
  565. c = &intf->hw;
  566. val = SDE_REG_READ(c, INTF_TEAR_VSYNC_INIT_VAL);
  567. info->rd_ptr_init_val = val & 0xffff;
  568. val = SDE_REG_READ(c, INTF_TEAR_INT_COUNT_VAL);
  569. info->rd_ptr_frame_count = (val & 0xffff0000) >> 16;
  570. info->rd_ptr_line_count = val & 0xffff;
  571. val = SDE_REG_READ(c, INTF_TEAR_LINE_COUNT);
  572. info->wr_ptr_line_count = val & 0xffff;
  573. val = SDE_REG_READ(c, INTF_FRAME_COUNT);
  574. info->intf_frame_count = val;
  575. return 0;
  576. }
  577. static int sde_hw_intf_v1_check_and_reset_tearcheck(struct sde_hw_intf *intf,
  578. struct intf_tear_status *status)
  579. {
  580. struct sde_hw_blk_reg_map *c = &intf->hw;
  581. u32 start_pos;
  582. if (!intf || !status)
  583. return -EINVAL;
  584. c = &intf->hw;
  585. status->read_count = SDE_REG_READ(c, INTF_TEAR_INT_COUNT_VAL);
  586. start_pos = SDE_REG_READ(c, INTF_TEAR_START_POS);
  587. status->write_count = SDE_REG_READ(c, INTF_TEAR_SYNC_WRCOUNT);
  588. status->write_count &= 0xffff0000;
  589. status->write_count |= start_pos;
  590. SDE_REG_WRITE(c, INTF_TEAR_SYNC_WRCOUNT, status->write_count);
  591. return 0;
  592. }
  593. static void sde_hw_intf_vsync_sel(struct sde_hw_intf *intf,
  594. u32 vsync_source)
  595. {
  596. struct sde_hw_blk_reg_map *c;
  597. if (!intf)
  598. return;
  599. c = &intf->hw;
  600. SDE_REG_WRITE(c, INTF_TEAR_MDP_VSYNC_SEL, (vsync_source & 0xf));
  601. }
  602. static void sde_hw_intf_enable_compressed_input(struct sde_hw_intf *intf,
  603. bool compression_en, bool dsc_4hs_merge)
  604. {
  605. struct sde_hw_blk_reg_map *c;
  606. u32 intf_cfg2;
  607. if (!intf)
  608. return;
  609. /*
  610. * callers can either call this function to enable/disable the 64 bit
  611. * compressed input or this configuration can be applied along
  612. * with timing generation parameters
  613. */
  614. c = &intf->hw;
  615. intf_cfg2 = SDE_REG_READ(c, INTF_CONFIG2);
  616. _check_and_set_comp_bit(intf, dsc_4hs_merge, compression_en,
  617. &intf_cfg2);
  618. SDE_REG_WRITE(c, INTF_CONFIG2, intf_cfg2);
  619. }
  620. static void sde_hw_intf_enable_wide_bus(struct sde_hw_intf *intf,
  621. bool enable)
  622. {
  623. struct sde_hw_blk_reg_map *c;
  624. u32 intf_cfg2;
  625. if (!intf)
  626. return;
  627. c = &intf->hw;
  628. intf_cfg2 = SDE_REG_READ(c, INTF_CONFIG2);
  629. intf_cfg2 &= ~BIT(0);
  630. intf_cfg2 |= enable ? BIT(0) : 0;
  631. SDE_REG_WRITE(c, INTF_CONFIG2, intf_cfg2);
  632. }
  633. static void _setup_intf_ops(struct sde_hw_intf_ops *ops,
  634. unsigned long cap)
  635. {
  636. ops->setup_timing_gen = sde_hw_intf_setup_timing_engine;
  637. ops->setup_prg_fetch = sde_hw_intf_setup_prg_fetch;
  638. ops->get_status = sde_hw_intf_get_status;
  639. ops->enable_timing = sde_hw_intf_enable_timing_engine;
  640. ops->setup_misr = sde_hw_intf_setup_misr;
  641. ops->collect_misr = sde_hw_intf_collect_misr;
  642. ops->get_line_count = sde_hw_intf_get_line_count;
  643. ops->get_underrun_line_count = sde_hw_intf_get_underrun_line_count;
  644. ops->avr_setup = sde_hw_intf_avr_setup;
  645. ops->avr_trigger = sde_hw_intf_avr_trigger;
  646. ops->avr_ctrl = sde_hw_intf_avr_ctrl;
  647. ops->enable_compressed_input = sde_hw_intf_enable_compressed_input;
  648. ops->enable_wide_bus = sde_hw_intf_enable_wide_bus;
  649. if (cap & BIT(SDE_INTF_INPUT_CTRL))
  650. ops->bind_pingpong_blk = sde_hw_intf_bind_pingpong_blk;
  651. if (cap & BIT(SDE_INTF_TE)) {
  652. ops->setup_tearcheck = sde_hw_intf_setup_te_config;
  653. ops->enable_tearcheck = sde_hw_intf_enable_te;
  654. ops->update_tearcheck = sde_hw_intf_update_te;
  655. ops->connect_external_te = sde_hw_intf_connect_external_te;
  656. ops->get_vsync_info = sde_hw_intf_get_vsync_info;
  657. ops->setup_autorefresh = sde_hw_intf_setup_autorefresh_config;
  658. ops->get_autorefresh = sde_hw_intf_get_autorefresh_config;
  659. ops->poll_timeout_wr_ptr = sde_hw_intf_poll_timeout_wr_ptr;
  660. ops->vsync_sel = sde_hw_intf_vsync_sel;
  661. ops->get_status = sde_hw_intf_v1_get_status;
  662. ops->check_and_reset_tearcheck =
  663. sde_hw_intf_v1_check_and_reset_tearcheck;
  664. }
  665. }
  666. static struct sde_hw_blk_ops sde_hw_ops = {
  667. .start = NULL,
  668. .stop = NULL,
  669. };
  670. struct sde_hw_intf *sde_hw_intf_init(enum sde_intf idx,
  671. void __iomem *addr,
  672. struct sde_mdss_cfg *m)
  673. {
  674. struct sde_hw_intf *c;
  675. struct sde_intf_cfg *cfg;
  676. int rc;
  677. c = kzalloc(sizeof(*c), GFP_KERNEL);
  678. if (!c)
  679. return ERR_PTR(-ENOMEM);
  680. cfg = _intf_offset(idx, m, addr, &c->hw);
  681. if (IS_ERR_OR_NULL(cfg)) {
  682. kfree(c);
  683. pr_err("failed to create sde_hw_intf %d\n", idx);
  684. return ERR_PTR(-EINVAL);
  685. }
  686. /*
  687. * Assign ops
  688. */
  689. c->idx = idx;
  690. c->cap = cfg;
  691. c->mdss = m;
  692. _setup_intf_ops(&c->ops, c->cap->features);
  693. rc = sde_hw_blk_init(&c->base, SDE_HW_BLK_INTF, idx, &sde_hw_ops);
  694. if (rc) {
  695. SDE_ERROR("failed to init hw blk %d\n", rc);
  696. goto blk_init_error;
  697. }
  698. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
  699. c->hw.blk_off + c->hw.length, c->hw.xin_id);
  700. return c;
  701. blk_init_error:
  702. kzfree(c);
  703. return ERR_PTR(rc);
  704. }
  705. void sde_hw_intf_destroy(struct sde_hw_intf *intf)
  706. {
  707. if (intf)
  708. sde_hw_blk_destroy(&intf->base);
  709. kfree(intf);
  710. }