sde_hw_intf.c 27 KB

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