sde_hw_intf.c 26 KB

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