sde_hw_intf.c 25 KB

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