sde_hw_intf.c 25 KB

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