sde_hw_intf.c 24 KB

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