sde_hw_intf.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2020, 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_MUX 0x25C
  59. #define INTF_STATUS 0x26C
  60. #define INTF_AVR_CONTROL 0x270
  61. #define INTF_AVR_MODE 0x274
  62. #define INTF_AVR_TRIGGER 0x278
  63. #define INTF_AVR_VTOTAL 0x27C
  64. #define INTF_TEAR_MDP_VSYNC_SEL 0x280
  65. #define INTF_TEAR_TEAR_CHECK_EN 0x284
  66. #define INTF_TEAR_SYNC_CONFIG_VSYNC 0x288
  67. #define INTF_TEAR_SYNC_CONFIG_HEIGHT 0x28C
  68. #define INTF_TEAR_SYNC_WRCOUNT 0x290
  69. #define INTF_TEAR_VSYNC_INIT_VAL 0x294
  70. #define INTF_TEAR_INT_COUNT_VAL 0x298
  71. #define INTF_TEAR_SYNC_THRESH 0x29C
  72. #define INTF_TEAR_START_POS 0x2A0
  73. #define INTF_TEAR_RD_PTR_IRQ 0x2A4
  74. #define INTF_TEAR_WR_PTR_IRQ 0x2A8
  75. #define INTF_TEAR_OUT_LINE_COUNT 0x2AC
  76. #define INTF_TEAR_LINE_COUNT 0x2B0
  77. #define INTF_TEAR_AUTOREFRESH_CONFIG 0x2B4
  78. #define INTF_TEAR_TEAR_DETECT_CTRL 0x2B8
  79. static struct sde_intf_cfg *_intf_offset(enum sde_intf intf,
  80. struct sde_mdss_cfg *m,
  81. void __iomem *addr,
  82. struct sde_hw_blk_reg_map *b)
  83. {
  84. int i;
  85. for (i = 0; i < m->intf_count; i++) {
  86. if ((intf == m->intf[i].id) &&
  87. (m->intf[i].type != INTF_NONE)) {
  88. b->base_off = addr;
  89. b->blk_off = m->intf[i].base;
  90. b->length = m->intf[i].len;
  91. b->hwversion = m->hwversion;
  92. b->log_mask = SDE_DBG_MASK_INTF;
  93. return &m->intf[i];
  94. }
  95. }
  96. return ERR_PTR(-EINVAL);
  97. }
  98. static void sde_hw_intf_avr_trigger(struct sde_hw_intf *ctx)
  99. {
  100. struct sde_hw_blk_reg_map *c;
  101. if (!ctx)
  102. return;
  103. c = &ctx->hw;
  104. SDE_REG_WRITE(c, INTF_AVR_TRIGGER, 0x1);
  105. SDE_DEBUG("AVR Triggered\n");
  106. }
  107. static int sde_hw_intf_avr_setup(struct sde_hw_intf *ctx,
  108. const struct intf_timing_params *params,
  109. const struct intf_avr_params *avr_params)
  110. {
  111. struct sde_hw_blk_reg_map *c;
  112. u32 hsync_period, vsync_period;
  113. u32 min_fps, default_fps, diff_fps;
  114. u32 vsync_period_slow;
  115. u32 avr_vtotal;
  116. u32 add_porches = 0;
  117. if (!ctx || !params || !avr_params) {
  118. SDE_ERROR("invalid input parameter(s)\n");
  119. return -EINVAL;
  120. }
  121. c = &ctx->hw;
  122. min_fps = avr_params->min_fps;
  123. default_fps = avr_params->default_fps;
  124. diff_fps = default_fps - min_fps;
  125. hsync_period = params->hsync_pulse_width +
  126. params->h_back_porch + params->width +
  127. params->h_front_porch;
  128. vsync_period = params->vsync_pulse_width +
  129. params->v_back_porch + params->height +
  130. params->v_front_porch;
  131. if (diff_fps)
  132. add_porches = mult_frac(vsync_period, diff_fps, min_fps);
  133. vsync_period_slow = vsync_period + add_porches;
  134. avr_vtotal = vsync_period_slow * hsync_period;
  135. SDE_REG_WRITE(c, INTF_AVR_VTOTAL, avr_vtotal);
  136. return 0;
  137. }
  138. static void sde_hw_intf_avr_ctrl(struct sde_hw_intf *ctx,
  139. const struct intf_avr_params *avr_params)
  140. {
  141. struct sde_hw_blk_reg_map *c;
  142. u32 avr_mode = 0;
  143. u32 avr_ctrl = 0;
  144. if (!ctx || !avr_params)
  145. return;
  146. c = &ctx->hw;
  147. if (avr_params->avr_mode) {
  148. avr_ctrl = BIT(0);
  149. avr_mode =
  150. (avr_params->avr_mode == SDE_RM_QSYNC_ONE_SHOT_MODE) ?
  151. (BIT(0) | BIT(8)) : 0x0;
  152. }
  153. SDE_REG_WRITE(c, INTF_AVR_CONTROL, avr_ctrl);
  154. SDE_REG_WRITE(c, INTF_AVR_MODE, avr_mode);
  155. }
  156. static inline void _check_and_set_comp_bit(struct sde_hw_intf *ctx,
  157. bool dsc_4hs_merge, bool compression_en, u32 *intf_cfg2)
  158. {
  159. if (((SDE_HW_MAJOR(ctx->mdss->hwversion) >=
  160. SDE_HW_MAJOR(SDE_HW_VER_700)) &&
  161. compression_en) ||
  162. (IS_SDE_MAJOR_SAME(ctx->mdss->hwversion,
  163. SDE_HW_VER_600) && dsc_4hs_merge))
  164. (*intf_cfg2) |= BIT(12);
  165. }
  166. static void sde_hw_intf_setup_timing_engine(struct sde_hw_intf *ctx,
  167. const struct intf_timing_params *p,
  168. const struct sde_format *fmt)
  169. {
  170. struct sde_hw_blk_reg_map *c = &ctx->hw;
  171. u32 hsync_period, vsync_period;
  172. u32 display_v_start, display_v_end;
  173. u32 hsync_start_x, hsync_end_x;
  174. u32 active_h_start, active_h_end;
  175. u32 active_v_start, active_v_end;
  176. u32 active_hctl, display_hctl, hsync_ctl;
  177. u32 polarity_ctl, den_polarity, hsync_polarity, vsync_polarity;
  178. u32 panel_format;
  179. u32 intf_cfg, intf_cfg2;
  180. u32 display_data_hctl = 0, active_data_hctl = 0;
  181. bool dp_intf = false;
  182. /* read interface_cfg */
  183. intf_cfg = SDE_REG_READ(c, INTF_CONFIG);
  184. hsync_period = p->hsync_pulse_width + p->h_back_porch + p->width +
  185. p->h_front_porch;
  186. vsync_period = p->vsync_pulse_width + p->v_back_porch + p->height +
  187. p->v_front_porch;
  188. display_v_start = ((p->vsync_pulse_width + p->v_back_porch) *
  189. hsync_period) + p->hsync_skew;
  190. display_v_end = ((vsync_period - p->v_front_porch) * hsync_period) +
  191. p->hsync_skew - 1;
  192. hsync_start_x = p->h_back_porch + p->hsync_pulse_width;
  193. hsync_end_x = hsync_period - p->h_front_porch - 1;
  194. if (ctx->cap->type == INTF_EDP || ctx->cap->type == INTF_DP)
  195. dp_intf = true;
  196. if (p->width != p->xres) {
  197. active_h_start = hsync_start_x;
  198. active_h_end = active_h_start + p->xres - 1;
  199. } else {
  200. active_h_start = 0;
  201. active_h_end = 0;
  202. }
  203. if (p->height != p->yres) {
  204. active_v_start = display_v_start;
  205. active_v_end = active_v_start + (p->yres * hsync_period) - 1;
  206. } else {
  207. active_v_start = 0;
  208. active_v_end = 0;
  209. }
  210. if (active_h_end) {
  211. active_hctl = (active_h_end << 16) | active_h_start;
  212. intf_cfg |= BIT(29); /* ACTIVE_H_ENABLE */
  213. } else {
  214. active_hctl = 0;
  215. }
  216. if (active_v_end)
  217. intf_cfg |= BIT(30); /* ACTIVE_V_ENABLE */
  218. hsync_ctl = (hsync_period << 16) | p->hsync_pulse_width;
  219. display_hctl = (hsync_end_x << 16) | hsync_start_x;
  220. if (dp_intf) {
  221. active_h_start = hsync_start_x;
  222. active_h_end = active_h_start + p->xres - 1;
  223. active_v_start = display_v_start;
  224. active_v_end = active_v_start + (p->yres * hsync_period) - 1;
  225. display_v_start += p->hsync_pulse_width + p->h_back_porch;
  226. active_hctl = (active_h_end << 16) | active_h_start;
  227. display_hctl = active_hctl;
  228. }
  229. intf_cfg2 = 0;
  230. _check_and_set_comp_bit(ctx, p->dsc_4hs_merge, p->compression_en,
  231. &intf_cfg2);
  232. if (dp_intf && p->compression_en) {
  233. active_data_hctl = (hsync_start_x + p->extra_dto_cycles) << 16;
  234. active_data_hctl += hsync_start_x;
  235. display_data_hctl = active_data_hctl;
  236. intf_cfg2 |= BIT(4);
  237. }
  238. den_polarity = 0;
  239. if (ctx->cap->type == INTF_HDMI) {
  240. hsync_polarity = p->yres >= 720 ? 0 : 1;
  241. vsync_polarity = p->yres >= 720 ? 0 : 1;
  242. } else if (ctx->cap->type == INTF_DP) {
  243. hsync_polarity = p->hsync_polarity;
  244. vsync_polarity = p->vsync_polarity;
  245. } else {
  246. hsync_polarity = 0;
  247. vsync_polarity = 0;
  248. }
  249. polarity_ctl = (den_polarity << 2) | /* DEN Polarity */
  250. (vsync_polarity << 1) | /* VSYNC Polarity */
  251. (hsync_polarity << 0); /* HSYNC Polarity */
  252. if (!SDE_FORMAT_IS_YUV(fmt))
  253. panel_format = (fmt->bits[C0_G_Y] |
  254. (fmt->bits[C1_B_Cb] << 2) |
  255. (fmt->bits[C2_R_Cr] << 4) |
  256. (0x21 << 8));
  257. else
  258. /* Interface treats all the pixel data in RGB888 format */
  259. panel_format = (COLOR_8BIT |
  260. (COLOR_8BIT << 2) |
  261. (COLOR_8BIT << 4) |
  262. (0x21 << 8));
  263. if (p->wide_bus_en)
  264. intf_cfg2 |= BIT(0);
  265. if (ctx->cfg.split_link_en)
  266. SDE_REG_WRITE(c, INTF_REG_SPLIT_LINK, 0x3);
  267. SDE_REG_WRITE(c, INTF_HSYNC_CTL, hsync_ctl);
  268. SDE_REG_WRITE(c, INTF_VSYNC_PERIOD_F0, vsync_period * hsync_period);
  269. SDE_REG_WRITE(c, INTF_VSYNC_PULSE_WIDTH_F0,
  270. p->vsync_pulse_width * hsync_period);
  271. SDE_REG_WRITE(c, INTF_DISPLAY_HCTL, display_hctl);
  272. SDE_REG_WRITE(c, INTF_DISPLAY_V_START_F0, display_v_start);
  273. SDE_REG_WRITE(c, INTF_DISPLAY_V_END_F0, display_v_end);
  274. SDE_REG_WRITE(c, INTF_ACTIVE_HCTL, active_hctl);
  275. SDE_REG_WRITE(c, INTF_ACTIVE_V_START_F0, active_v_start);
  276. SDE_REG_WRITE(c, INTF_ACTIVE_V_END_F0, active_v_end);
  277. SDE_REG_WRITE(c, INTF_BORDER_COLOR, p->border_clr);
  278. SDE_REG_WRITE(c, INTF_UNDERFLOW_COLOR, p->underflow_clr);
  279. SDE_REG_WRITE(c, INTF_HSYNC_SKEW, p->hsync_skew);
  280. SDE_REG_WRITE(c, INTF_POLARITY_CTL, polarity_ctl);
  281. SDE_REG_WRITE(c, INTF_FRAME_LINE_COUNT_EN, 0x3);
  282. SDE_REG_WRITE(c, INTF_CONFIG, intf_cfg);
  283. SDE_REG_WRITE(c, INTF_PANEL_FORMAT, panel_format);
  284. SDE_REG_WRITE(c, INTF_CONFIG2, intf_cfg2);
  285. SDE_REG_WRITE(c, INTF_DISPLAY_DATA_HCTL, display_data_hctl);
  286. SDE_REG_WRITE(c, INTF_ACTIVE_DATA_HCTL, active_data_hctl);
  287. }
  288. static void sde_hw_intf_enable_timing_engine(
  289. struct sde_hw_intf *intf,
  290. u8 enable)
  291. {
  292. struct sde_hw_blk_reg_map *c = &intf->hw;
  293. /* Note: Display interface select is handled in top block hw layer */
  294. SDE_REG_WRITE(c, INTF_TIMING_ENGINE_EN, enable != 0);
  295. }
  296. static void sde_hw_intf_setup_prg_fetch(
  297. struct sde_hw_intf *intf,
  298. const struct intf_prog_fetch *fetch)
  299. {
  300. struct sde_hw_blk_reg_map *c = &intf->hw;
  301. int fetch_enable;
  302. /*
  303. * Fetch should always be outside the active lines. If the fetching
  304. * is programmed within active region, hardware behavior is unknown.
  305. */
  306. fetch_enable = SDE_REG_READ(c, INTF_CONFIG);
  307. if (fetch->enable) {
  308. fetch_enable |= BIT(31);
  309. SDE_REG_WRITE(c, INTF_PROG_FETCH_START,
  310. fetch->fetch_start);
  311. } else {
  312. fetch_enable &= ~BIT(31);
  313. }
  314. SDE_REG_WRITE(c, INTF_CONFIG, fetch_enable);
  315. }
  316. static void sde_hw_intf_bind_pingpong_blk(
  317. struct sde_hw_intf *intf,
  318. bool enable,
  319. const enum sde_pingpong pp)
  320. {
  321. struct sde_hw_blk_reg_map *c;
  322. u32 mux_cfg;
  323. if (!intf)
  324. return;
  325. c = &intf->hw;
  326. mux_cfg = SDE_REG_READ(c, INTF_MUX);
  327. mux_cfg &= ~0xf;
  328. if (enable) {
  329. mux_cfg |= (pp - PINGPONG_0) & 0x7;
  330. if (intf->cfg.split_link_en)
  331. mux_cfg = 0x60000;
  332. } else {
  333. mux_cfg = 0xf000f;
  334. }
  335. SDE_REG_WRITE(c, INTF_MUX, mux_cfg);
  336. }
  337. static void sde_hw_intf_get_status(
  338. struct sde_hw_intf *intf,
  339. struct intf_status *s)
  340. {
  341. struct sde_hw_blk_reg_map *c = &intf->hw;
  342. s->is_en = SDE_REG_READ(c, INTF_TIMING_ENGINE_EN);
  343. if (s->is_en) {
  344. s->frame_count = SDE_REG_READ(c, INTF_FRAME_COUNT);
  345. s->line_count = SDE_REG_READ(c, INTF_LINE_COUNT);
  346. } else {
  347. s->line_count = 0;
  348. s->frame_count = 0;
  349. }
  350. }
  351. static void sde_hw_intf_v1_get_status(
  352. struct sde_hw_intf *intf,
  353. struct intf_status *s)
  354. {
  355. struct sde_hw_blk_reg_map *c = &intf->hw;
  356. s->is_en = SDE_REG_READ(c, INTF_STATUS) & BIT(0);
  357. if (s->is_en) {
  358. s->frame_count = SDE_REG_READ(c, INTF_FRAME_COUNT);
  359. s->line_count = SDE_REG_READ(c, INTF_LINE_COUNT);
  360. } else {
  361. s->line_count = 0;
  362. s->frame_count = 0;
  363. }
  364. }
  365. static void sde_hw_intf_setup_misr(struct sde_hw_intf *intf,
  366. bool enable, u32 frame_count)
  367. {
  368. struct sde_hw_blk_reg_map *c = &intf->hw;
  369. u32 config = 0;
  370. SDE_REG_WRITE(c, INTF_MISR_CTRL, MISR_CTRL_STATUS_CLEAR);
  371. /* clear misr data */
  372. wmb();
  373. if (enable)
  374. config = (frame_count & MISR_FRAME_COUNT_MASK) |
  375. MISR_CTRL_ENABLE |
  376. INTF_MISR_CTRL_FREE_RUN_MASK |
  377. INTF_MISR_CTRL_INPUT_SEL_DATA;
  378. SDE_REG_WRITE(c, INTF_MISR_CTRL, config);
  379. }
  380. static int sde_hw_intf_collect_misr(struct sde_hw_intf *intf, bool nonblock,
  381. u32 *misr_value)
  382. {
  383. struct sde_hw_blk_reg_map *c = &intf->hw;
  384. u32 ctrl = 0;
  385. if (!misr_value)
  386. return -EINVAL;
  387. ctrl = SDE_REG_READ(c, INTF_MISR_CTRL);
  388. if (!nonblock) {
  389. if (ctrl & MISR_CTRL_ENABLE) {
  390. int rc;
  391. rc = readl_poll_timeout(c->base_off + c->blk_off +
  392. INTF_MISR_CTRL, ctrl,
  393. (ctrl & MISR_CTRL_STATUS) > 0, 500,
  394. 84000);
  395. if (rc)
  396. return rc;
  397. } else {
  398. return -EINVAL;
  399. }
  400. }
  401. *misr_value = SDE_REG_READ(c, INTF_MISR_SIGNATURE);
  402. return 0;
  403. }
  404. static u32 sde_hw_intf_get_line_count(struct sde_hw_intf *intf)
  405. {
  406. struct sde_hw_blk_reg_map *c;
  407. if (!intf)
  408. return 0;
  409. c = &intf->hw;
  410. return SDE_REG_READ(c, INTF_LINE_COUNT);
  411. }
  412. static int sde_hw_intf_setup_te_config(struct sde_hw_intf *intf,
  413. struct sde_hw_tear_check *te)
  414. {
  415. struct sde_hw_blk_reg_map *c;
  416. int cfg;
  417. if (!intf)
  418. return -EINVAL;
  419. c = &intf->hw;
  420. cfg = BIT(19); /* VSYNC_COUNTER_EN */
  421. if (te->hw_vsync_mode)
  422. cfg |= BIT(20);
  423. cfg |= te->vsync_count;
  424. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_VSYNC, cfg);
  425. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_HEIGHT, te->sync_cfg_height);
  426. SDE_REG_WRITE(c, INTF_TEAR_VSYNC_INIT_VAL, te->vsync_init_val);
  427. SDE_REG_WRITE(c, INTF_TEAR_RD_PTR_IRQ, te->rd_ptr_irq);
  428. SDE_REG_WRITE(c, INTF_TEAR_WR_PTR_IRQ, te->wr_ptr_irq);
  429. SDE_REG_WRITE(c, INTF_TEAR_START_POS, te->start_pos);
  430. SDE_REG_WRITE(c, INTF_TEAR_SYNC_THRESH,
  431. ((te->sync_threshold_continue << 16) |
  432. te->sync_threshold_start));
  433. SDE_REG_WRITE(c, INTF_TEAR_SYNC_WRCOUNT,
  434. (te->start_pos + te->sync_threshold_start + 1));
  435. return 0;
  436. }
  437. static int sde_hw_intf_setup_autorefresh_config(struct sde_hw_intf *intf,
  438. struct sde_hw_autorefresh *cfg)
  439. {
  440. struct sde_hw_blk_reg_map *c;
  441. u32 refresh_cfg;
  442. if (!intf || !cfg)
  443. return -EINVAL;
  444. c = &intf->hw;
  445. if (cfg->enable)
  446. refresh_cfg = BIT(31) | cfg->frame_count;
  447. else
  448. refresh_cfg = 0;
  449. SDE_REG_WRITE(c, INTF_TEAR_AUTOREFRESH_CONFIG, refresh_cfg);
  450. return 0;
  451. }
  452. static int sde_hw_intf_get_autorefresh_config(struct sde_hw_intf *intf,
  453. struct sde_hw_autorefresh *cfg)
  454. {
  455. struct sde_hw_blk_reg_map *c;
  456. u32 val;
  457. if (!intf || !cfg)
  458. return -EINVAL;
  459. c = &intf->hw;
  460. val = SDE_REG_READ(c, INTF_TEAR_AUTOREFRESH_CONFIG);
  461. cfg->enable = (val & BIT(31)) >> 31;
  462. cfg->frame_count = val & 0xffff;
  463. return 0;
  464. }
  465. static int sde_hw_intf_poll_timeout_wr_ptr(struct sde_hw_intf *intf,
  466. u32 timeout_us)
  467. {
  468. struct sde_hw_blk_reg_map *c;
  469. u32 val;
  470. int rc;
  471. if (!intf)
  472. return -EINVAL;
  473. c = &intf->hw;
  474. rc = readl_poll_timeout(c->base_off + c->blk_off + INTF_TEAR_LINE_COUNT,
  475. val, (val & 0xffff) >= 1, 10, timeout_us);
  476. return rc;
  477. }
  478. static int sde_hw_intf_enable_te(struct sde_hw_intf *intf, bool enable)
  479. {
  480. struct sde_hw_blk_reg_map *c;
  481. if (!intf)
  482. return -EINVAL;
  483. c = &intf->hw;
  484. SDE_REG_WRITE(c, INTF_TEAR_TEAR_CHECK_EN, enable);
  485. return 0;
  486. }
  487. static void sde_hw_intf_update_te(struct sde_hw_intf *intf,
  488. struct sde_hw_tear_check *te)
  489. {
  490. struct sde_hw_blk_reg_map *c;
  491. int cfg;
  492. if (!intf || !te)
  493. return;
  494. c = &intf->hw;
  495. cfg = SDE_REG_READ(c, INTF_TEAR_SYNC_THRESH);
  496. cfg &= ~0xFFFF;
  497. cfg |= te->sync_threshold_start;
  498. SDE_REG_WRITE(c, INTF_TEAR_SYNC_THRESH, cfg);
  499. }
  500. static int sde_hw_intf_connect_external_te(struct sde_hw_intf *intf,
  501. bool enable_external_te)
  502. {
  503. struct sde_hw_blk_reg_map *c = &intf->hw;
  504. u32 cfg;
  505. int orig;
  506. if (!intf)
  507. return -EINVAL;
  508. c = &intf->hw;
  509. cfg = SDE_REG_READ(c, INTF_TEAR_SYNC_CONFIG_VSYNC);
  510. orig = (bool)(cfg & BIT(20));
  511. if (enable_external_te)
  512. cfg |= BIT(20);
  513. else
  514. cfg &= ~BIT(20);
  515. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_VSYNC, cfg);
  516. return orig;
  517. }
  518. static int sde_hw_intf_get_vsync_info(struct sde_hw_intf *intf,
  519. struct sde_hw_pp_vsync_info *info)
  520. {
  521. struct sde_hw_blk_reg_map *c = &intf->hw;
  522. u32 val;
  523. if (!intf || !info)
  524. return -EINVAL;
  525. c = &intf->hw;
  526. val = SDE_REG_READ(c, INTF_TEAR_VSYNC_INIT_VAL);
  527. info->rd_ptr_init_val = val & 0xffff;
  528. val = SDE_REG_READ(c, INTF_TEAR_INT_COUNT_VAL);
  529. info->rd_ptr_frame_count = (val & 0xffff0000) >> 16;
  530. info->rd_ptr_line_count = val & 0xffff;
  531. val = SDE_REG_READ(c, INTF_TEAR_LINE_COUNT);
  532. info->wr_ptr_line_count = val & 0xffff;
  533. val = SDE_REG_READ(c, INTF_FRAME_COUNT);
  534. info->intf_frame_count = val;
  535. return 0;
  536. }
  537. static void sde_hw_intf_vsync_sel(struct sde_hw_intf *intf,
  538. u32 vsync_source)
  539. {
  540. struct sde_hw_blk_reg_map *c;
  541. if (!intf)
  542. return;
  543. c = &intf->hw;
  544. SDE_REG_WRITE(c, INTF_TEAR_MDP_VSYNC_SEL, (vsync_source & 0xf));
  545. }
  546. static void sde_hw_intf_enable_compressed_input(struct sde_hw_intf *intf,
  547. bool compression_en, bool dsc_4hs_merge)
  548. {
  549. struct sde_hw_blk_reg_map *c;
  550. u32 intf_cfg2;
  551. if (!intf)
  552. return;
  553. /*
  554. * callers can either call this function to enable/disable the 64 bit
  555. * compressed input or this configuration can be applied along
  556. * with timing generation parameters
  557. */
  558. c = &intf->hw;
  559. intf_cfg2 = SDE_REG_READ(c, INTF_CONFIG2);
  560. _check_and_set_comp_bit(intf, dsc_4hs_merge, compression_en,
  561. &intf_cfg2);
  562. SDE_REG_WRITE(c, INTF_CONFIG2, intf_cfg2);
  563. }
  564. static void _setup_intf_ops(struct sde_hw_intf_ops *ops,
  565. unsigned long cap)
  566. {
  567. ops->setup_timing_gen = sde_hw_intf_setup_timing_engine;
  568. ops->setup_prg_fetch = sde_hw_intf_setup_prg_fetch;
  569. ops->get_status = sde_hw_intf_get_status;
  570. ops->enable_timing = sde_hw_intf_enable_timing_engine;
  571. ops->setup_misr = sde_hw_intf_setup_misr;
  572. ops->collect_misr = sde_hw_intf_collect_misr;
  573. ops->get_line_count = sde_hw_intf_get_line_count;
  574. ops->avr_setup = sde_hw_intf_avr_setup;
  575. ops->avr_trigger = sde_hw_intf_avr_trigger;
  576. ops->avr_ctrl = sde_hw_intf_avr_ctrl;
  577. ops->enable_compressed_input = sde_hw_intf_enable_compressed_input;
  578. if (cap & BIT(SDE_INTF_INPUT_CTRL))
  579. ops->bind_pingpong_blk = sde_hw_intf_bind_pingpong_blk;
  580. if (cap & BIT(SDE_INTF_TE)) {
  581. ops->setup_tearcheck = sde_hw_intf_setup_te_config;
  582. ops->enable_tearcheck = sde_hw_intf_enable_te;
  583. ops->update_tearcheck = sde_hw_intf_update_te;
  584. ops->connect_external_te = sde_hw_intf_connect_external_te;
  585. ops->get_vsync_info = sde_hw_intf_get_vsync_info;
  586. ops->setup_autorefresh = sde_hw_intf_setup_autorefresh_config;
  587. ops->get_autorefresh = sde_hw_intf_get_autorefresh_config;
  588. ops->poll_timeout_wr_ptr = sde_hw_intf_poll_timeout_wr_ptr;
  589. ops->vsync_sel = sde_hw_intf_vsync_sel;
  590. ops->get_status = sde_hw_intf_v1_get_status;
  591. }
  592. }
  593. static struct sde_hw_blk_ops sde_hw_ops = {
  594. .start = NULL,
  595. .stop = NULL,
  596. };
  597. struct sde_hw_intf *sde_hw_intf_init(enum sde_intf idx,
  598. void __iomem *addr,
  599. struct sde_mdss_cfg *m)
  600. {
  601. struct sde_hw_intf *c;
  602. struct sde_intf_cfg *cfg;
  603. int rc;
  604. c = kzalloc(sizeof(*c), GFP_KERNEL);
  605. if (!c)
  606. return ERR_PTR(-ENOMEM);
  607. cfg = _intf_offset(idx, m, addr, &c->hw);
  608. if (IS_ERR_OR_NULL(cfg)) {
  609. kfree(c);
  610. pr_err("failed to create sde_hw_intf %d\n", idx);
  611. return ERR_PTR(-EINVAL);
  612. }
  613. /*
  614. * Assign ops
  615. */
  616. c->idx = idx;
  617. c->cap = cfg;
  618. c->mdss = m;
  619. _setup_intf_ops(&c->ops, c->cap->features);
  620. rc = sde_hw_blk_init(&c->base, SDE_HW_BLK_INTF, idx, &sde_hw_ops);
  621. if (rc) {
  622. SDE_ERROR("failed to init hw blk %d\n", rc);
  623. goto blk_init_error;
  624. }
  625. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
  626. c->hw.blk_off + c->hw.length, c->hw.xin_id);
  627. return c;
  628. blk_init_error:
  629. kzfree(c);
  630. return ERR_PTR(rc);
  631. }
  632. void sde_hw_intf_destroy(struct sde_hw_intf *intf)
  633. {
  634. if (intf)
  635. sde_hw_blk_destroy(&intf->base);
  636. kfree(intf);
  637. }