sde_hw_intf.c 26 KB

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