sde_hw_intf.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2019, 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 void sde_hw_intf_setup_timing_engine(struct sde_hw_intf *ctx,
  157. const struct intf_timing_params *p,
  158. const struct sde_format *fmt)
  159. {
  160. struct sde_hw_blk_reg_map *c = &ctx->hw;
  161. u32 hsync_period, vsync_period;
  162. u32 display_v_start, display_v_end;
  163. u32 hsync_start_x, hsync_end_x;
  164. u32 active_h_start, active_h_end;
  165. u32 active_v_start, active_v_end;
  166. u32 active_hctl, display_hctl, hsync_ctl;
  167. u32 polarity_ctl, den_polarity, hsync_polarity, vsync_polarity;
  168. u32 panel_format;
  169. u32 intf_cfg, intf_cfg2;
  170. u32 display_data_hctl = 0, active_data_hctl = 0;
  171. bool dp_intf = false;
  172. /* read interface_cfg */
  173. intf_cfg = SDE_REG_READ(c, INTF_CONFIG);
  174. hsync_period = p->hsync_pulse_width + p->h_back_porch + p->width +
  175. p->h_front_porch;
  176. vsync_period = p->vsync_pulse_width + p->v_back_porch + p->height +
  177. p->v_front_porch;
  178. display_v_start = ((p->vsync_pulse_width + p->v_back_porch) *
  179. hsync_period) + p->hsync_skew;
  180. display_v_end = ((vsync_period - p->v_front_porch) * hsync_period) +
  181. p->hsync_skew - 1;
  182. hsync_start_x = p->h_back_porch + p->hsync_pulse_width;
  183. hsync_end_x = hsync_period - p->h_front_porch - 1;
  184. if (ctx->cap->type == INTF_EDP || ctx->cap->type == INTF_DP)
  185. dp_intf = true;
  186. if (p->width != p->xres) {
  187. active_h_start = hsync_start_x;
  188. active_h_end = active_h_start + p->xres - 1;
  189. } else {
  190. active_h_start = 0;
  191. active_h_end = 0;
  192. }
  193. if (p->height != p->yres) {
  194. active_v_start = display_v_start;
  195. active_v_end = active_v_start + (p->yres * hsync_period) - 1;
  196. } else {
  197. active_v_start = 0;
  198. active_v_end = 0;
  199. }
  200. if (active_h_end) {
  201. active_hctl = (active_h_end << 16) | active_h_start;
  202. intf_cfg |= BIT(29); /* ACTIVE_H_ENABLE */
  203. } else {
  204. active_hctl = 0;
  205. }
  206. if (active_v_end)
  207. intf_cfg |= BIT(30); /* ACTIVE_V_ENABLE */
  208. hsync_ctl = (hsync_period << 16) | p->hsync_pulse_width;
  209. display_hctl = (hsync_end_x << 16) | hsync_start_x;
  210. if (dp_intf) {
  211. active_h_start = hsync_start_x;
  212. active_h_end = active_h_start + p->xres - 1;
  213. active_v_start = display_v_start;
  214. active_v_end = active_v_start + (p->yres * hsync_period) - 1;
  215. display_v_start += p->hsync_pulse_width + p->h_back_porch;
  216. active_hctl = (active_h_end << 16) | active_h_start;
  217. display_hctl = active_hctl;
  218. }
  219. intf_cfg2 = 0;
  220. if (dp_intf && p->compression_en) {
  221. active_data_hctl = (hsync_start_x + p->extra_dto_cycles) << 16;
  222. active_data_hctl += hsync_start_x;
  223. display_data_hctl = active_data_hctl;
  224. intf_cfg2 |= BIT(4);
  225. }
  226. den_polarity = 0;
  227. if (ctx->cap->type == INTF_HDMI) {
  228. hsync_polarity = p->yres >= 720 ? 0 : 1;
  229. vsync_polarity = p->yres >= 720 ? 0 : 1;
  230. } else if (ctx->cap->type == INTF_DP) {
  231. hsync_polarity = p->hsync_polarity;
  232. vsync_polarity = p->vsync_polarity;
  233. } else {
  234. hsync_polarity = 0;
  235. vsync_polarity = 0;
  236. }
  237. polarity_ctl = (den_polarity << 2) | /* DEN Polarity */
  238. (vsync_polarity << 1) | /* VSYNC Polarity */
  239. (hsync_polarity << 0); /* HSYNC Polarity */
  240. if (!SDE_FORMAT_IS_YUV(fmt))
  241. panel_format = (fmt->bits[C0_G_Y] |
  242. (fmt->bits[C1_B_Cb] << 2) |
  243. (fmt->bits[C2_R_Cr] << 4) |
  244. (0x21 << 8));
  245. else
  246. /* Interface treats all the pixel data in RGB888 format */
  247. panel_format = (COLOR_8BIT |
  248. (COLOR_8BIT << 2) |
  249. (COLOR_8BIT << 4) |
  250. (0x21 << 8));
  251. if (p->wide_bus_en)
  252. intf_cfg2 |= BIT(0);
  253. if (ctx->cfg.split_link_en)
  254. SDE_REG_WRITE(c, INTF_REG_SPLIT_LINK, 0x3);
  255. SDE_REG_WRITE(c, INTF_HSYNC_CTL, hsync_ctl);
  256. SDE_REG_WRITE(c, INTF_VSYNC_PERIOD_F0, vsync_period * hsync_period);
  257. SDE_REG_WRITE(c, INTF_VSYNC_PULSE_WIDTH_F0,
  258. p->vsync_pulse_width * hsync_period);
  259. SDE_REG_WRITE(c, INTF_DISPLAY_HCTL, display_hctl);
  260. SDE_REG_WRITE(c, INTF_DISPLAY_V_START_F0, display_v_start);
  261. SDE_REG_WRITE(c, INTF_DISPLAY_V_END_F0, display_v_end);
  262. SDE_REG_WRITE(c, INTF_ACTIVE_HCTL, active_hctl);
  263. SDE_REG_WRITE(c, INTF_ACTIVE_V_START_F0, active_v_start);
  264. SDE_REG_WRITE(c, INTF_ACTIVE_V_END_F0, active_v_end);
  265. SDE_REG_WRITE(c, INTF_BORDER_COLOR, p->border_clr);
  266. SDE_REG_WRITE(c, INTF_UNDERFLOW_COLOR, p->underflow_clr);
  267. SDE_REG_WRITE(c, INTF_HSYNC_SKEW, p->hsync_skew);
  268. SDE_REG_WRITE(c, INTF_POLARITY_CTL, polarity_ctl);
  269. SDE_REG_WRITE(c, INTF_FRAME_LINE_COUNT_EN, 0x3);
  270. SDE_REG_WRITE(c, INTF_CONFIG, intf_cfg);
  271. SDE_REG_WRITE(c, INTF_PANEL_FORMAT, panel_format);
  272. SDE_REG_WRITE(c, INTF_CONFIG2, intf_cfg2);
  273. SDE_REG_WRITE(c, INTF_DISPLAY_DATA_HCTL, display_data_hctl);
  274. SDE_REG_WRITE(c, INTF_ACTIVE_DATA_HCTL, active_data_hctl);
  275. }
  276. static void sde_hw_intf_enable_timing_engine(
  277. struct sde_hw_intf *intf,
  278. u8 enable)
  279. {
  280. struct sde_hw_blk_reg_map *c = &intf->hw;
  281. /* Note: Display interface select is handled in top block hw layer */
  282. SDE_REG_WRITE(c, INTF_TIMING_ENGINE_EN, enable != 0);
  283. }
  284. static void sde_hw_intf_setup_prg_fetch(
  285. struct sde_hw_intf *intf,
  286. const struct intf_prog_fetch *fetch)
  287. {
  288. struct sde_hw_blk_reg_map *c = &intf->hw;
  289. int fetch_enable;
  290. /*
  291. * Fetch should always be outside the active lines. If the fetching
  292. * is programmed within active region, hardware behavior is unknown.
  293. */
  294. fetch_enable = SDE_REG_READ(c, INTF_CONFIG);
  295. if (fetch->enable) {
  296. fetch_enable |= BIT(31);
  297. SDE_REG_WRITE(c, INTF_PROG_FETCH_START,
  298. fetch->fetch_start);
  299. } else {
  300. fetch_enable &= ~BIT(31);
  301. }
  302. SDE_REG_WRITE(c, INTF_CONFIG, fetch_enable);
  303. }
  304. static void sde_hw_intf_bind_pingpong_blk(
  305. struct sde_hw_intf *intf,
  306. bool enable,
  307. const enum sde_pingpong pp)
  308. {
  309. struct sde_hw_blk_reg_map *c;
  310. u32 mux_cfg;
  311. if (!intf)
  312. return;
  313. c = &intf->hw;
  314. mux_cfg = SDE_REG_READ(c, INTF_MUX);
  315. mux_cfg &= ~0xf;
  316. if (enable) {
  317. mux_cfg |= (pp - PINGPONG_0) & 0x7;
  318. if (intf->cfg.split_link_en)
  319. mux_cfg = 0x60000;
  320. } else {
  321. mux_cfg = 0xf000f;
  322. }
  323. SDE_REG_WRITE(c, INTF_MUX, mux_cfg);
  324. }
  325. static void sde_hw_intf_get_status(
  326. struct sde_hw_intf *intf,
  327. struct intf_status *s)
  328. {
  329. struct sde_hw_blk_reg_map *c = &intf->hw;
  330. s->is_en = SDE_REG_READ(c, INTF_TIMING_ENGINE_EN);
  331. if (s->is_en) {
  332. s->frame_count = SDE_REG_READ(c, INTF_FRAME_COUNT);
  333. s->line_count = SDE_REG_READ(c, INTF_LINE_COUNT);
  334. } else {
  335. s->line_count = 0;
  336. s->frame_count = 0;
  337. }
  338. }
  339. static void sde_hw_intf_v1_get_status(
  340. struct sde_hw_intf *intf,
  341. struct intf_status *s)
  342. {
  343. struct sde_hw_blk_reg_map *c = &intf->hw;
  344. s->is_en = SDE_REG_READ(c, INTF_STATUS) & BIT(0);
  345. if (s->is_en) {
  346. s->frame_count = SDE_REG_READ(c, INTF_FRAME_COUNT);
  347. s->line_count = SDE_REG_READ(c, INTF_LINE_COUNT);
  348. } else {
  349. s->line_count = 0;
  350. s->frame_count = 0;
  351. }
  352. }
  353. static void sde_hw_intf_setup_misr(struct sde_hw_intf *intf,
  354. bool enable, u32 frame_count)
  355. {
  356. struct sde_hw_blk_reg_map *c = &intf->hw;
  357. u32 config = 0;
  358. SDE_REG_WRITE(c, INTF_MISR_CTRL, MISR_CTRL_STATUS_CLEAR);
  359. /* clear misr data */
  360. wmb();
  361. if (enable)
  362. config = (frame_count & MISR_FRAME_COUNT_MASK) |
  363. MISR_CTRL_ENABLE |
  364. INTF_MISR_CTRL_FREE_RUN_MASK |
  365. INTF_MISR_CTRL_INPUT_SEL_DATA;
  366. SDE_REG_WRITE(c, INTF_MISR_CTRL, config);
  367. }
  368. static int sde_hw_intf_collect_misr(struct sde_hw_intf *intf, bool nonblock,
  369. u32 *misr_value)
  370. {
  371. struct sde_hw_blk_reg_map *c = &intf->hw;
  372. u32 ctrl = 0;
  373. if (!misr_value)
  374. return -EINVAL;
  375. ctrl = SDE_REG_READ(c, INTF_MISR_CTRL);
  376. if (!nonblock) {
  377. if (ctrl & MISR_CTRL_ENABLE) {
  378. int rc;
  379. rc = readl_poll_timeout(c->base_off + c->blk_off +
  380. INTF_MISR_CTRL, ctrl,
  381. (ctrl & MISR_CTRL_STATUS) > 0, 500,
  382. 84000);
  383. if (rc)
  384. return rc;
  385. } else {
  386. return -EINVAL;
  387. }
  388. }
  389. *misr_value = SDE_REG_READ(c, INTF_MISR_SIGNATURE);
  390. return 0;
  391. }
  392. static u32 sde_hw_intf_get_line_count(struct sde_hw_intf *intf)
  393. {
  394. struct sde_hw_blk_reg_map *c;
  395. if (!intf)
  396. return 0;
  397. c = &intf->hw;
  398. return SDE_REG_READ(c, INTF_LINE_COUNT);
  399. }
  400. static int sde_hw_intf_setup_te_config(struct sde_hw_intf *intf,
  401. struct sde_hw_tear_check *te)
  402. {
  403. struct sde_hw_blk_reg_map *c;
  404. int cfg;
  405. if (!intf)
  406. return -EINVAL;
  407. c = &intf->hw;
  408. cfg = BIT(19); /* VSYNC_COUNTER_EN */
  409. if (te->hw_vsync_mode)
  410. cfg |= BIT(20);
  411. cfg |= te->vsync_count;
  412. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_VSYNC, cfg);
  413. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_HEIGHT, te->sync_cfg_height);
  414. SDE_REG_WRITE(c, INTF_TEAR_VSYNC_INIT_VAL, te->vsync_init_val);
  415. SDE_REG_WRITE(c, INTF_TEAR_RD_PTR_IRQ, te->rd_ptr_irq);
  416. SDE_REG_WRITE(c, INTF_TEAR_WR_PTR_IRQ, te->wr_ptr_irq);
  417. SDE_REG_WRITE(c, INTF_TEAR_START_POS, te->start_pos);
  418. SDE_REG_WRITE(c, INTF_TEAR_SYNC_THRESH,
  419. ((te->sync_threshold_continue << 16) |
  420. te->sync_threshold_start));
  421. SDE_REG_WRITE(c, INTF_TEAR_SYNC_WRCOUNT,
  422. (te->start_pos + te->sync_threshold_start + 1));
  423. return 0;
  424. }
  425. static int sde_hw_intf_setup_autorefresh_config(struct sde_hw_intf *intf,
  426. struct sde_hw_autorefresh *cfg)
  427. {
  428. struct sde_hw_blk_reg_map *c;
  429. u32 refresh_cfg;
  430. if (!intf || !cfg)
  431. return -EINVAL;
  432. c = &intf->hw;
  433. if (cfg->enable)
  434. refresh_cfg = BIT(31) | cfg->frame_count;
  435. else
  436. refresh_cfg = 0;
  437. SDE_REG_WRITE(c, INTF_TEAR_AUTOREFRESH_CONFIG, refresh_cfg);
  438. return 0;
  439. }
  440. static int sde_hw_intf_get_autorefresh_config(struct sde_hw_intf *intf,
  441. struct sde_hw_autorefresh *cfg)
  442. {
  443. struct sde_hw_blk_reg_map *c;
  444. u32 val;
  445. if (!intf || !cfg)
  446. return -EINVAL;
  447. c = &intf->hw;
  448. val = SDE_REG_READ(c, INTF_TEAR_AUTOREFRESH_CONFIG);
  449. cfg->enable = (val & BIT(31)) >> 31;
  450. cfg->frame_count = val & 0xffff;
  451. return 0;
  452. }
  453. static int sde_hw_intf_poll_timeout_wr_ptr(struct sde_hw_intf *intf,
  454. u32 timeout_us)
  455. {
  456. struct sde_hw_blk_reg_map *c;
  457. u32 val;
  458. int rc;
  459. if (!intf)
  460. return -EINVAL;
  461. c = &intf->hw;
  462. rc = readl_poll_timeout(c->base_off + c->blk_off + INTF_TEAR_LINE_COUNT,
  463. val, (val & 0xffff) >= 1, 10, timeout_us);
  464. return rc;
  465. }
  466. static int sde_hw_intf_enable_te(struct sde_hw_intf *intf, bool enable)
  467. {
  468. struct sde_hw_blk_reg_map *c;
  469. if (!intf)
  470. return -EINVAL;
  471. c = &intf->hw;
  472. SDE_REG_WRITE(c, INTF_TEAR_TEAR_CHECK_EN, enable);
  473. return 0;
  474. }
  475. static void sde_hw_intf_update_te(struct sde_hw_intf *intf,
  476. struct sde_hw_tear_check *te)
  477. {
  478. struct sde_hw_blk_reg_map *c;
  479. int cfg;
  480. if (!intf || !te)
  481. return;
  482. c = &intf->hw;
  483. cfg = SDE_REG_READ(c, INTF_TEAR_SYNC_THRESH);
  484. cfg &= ~0xFFFF;
  485. cfg |= te->sync_threshold_start;
  486. SDE_REG_WRITE(c, INTF_TEAR_SYNC_THRESH, cfg);
  487. }
  488. static int sde_hw_intf_connect_external_te(struct sde_hw_intf *intf,
  489. bool enable_external_te)
  490. {
  491. struct sde_hw_blk_reg_map *c = &intf->hw;
  492. u32 cfg;
  493. int orig;
  494. if (!intf)
  495. return -EINVAL;
  496. c = &intf->hw;
  497. cfg = SDE_REG_READ(c, INTF_TEAR_SYNC_CONFIG_VSYNC);
  498. orig = (bool)(cfg & BIT(20));
  499. if (enable_external_te)
  500. cfg |= BIT(20);
  501. else
  502. cfg &= ~BIT(20);
  503. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_VSYNC, cfg);
  504. return orig;
  505. }
  506. static int sde_hw_intf_get_vsync_info(struct sde_hw_intf *intf,
  507. struct sde_hw_pp_vsync_info *info)
  508. {
  509. struct sde_hw_blk_reg_map *c = &intf->hw;
  510. u32 val;
  511. if (!intf || !info)
  512. return -EINVAL;
  513. c = &intf->hw;
  514. val = SDE_REG_READ(c, INTF_TEAR_VSYNC_INIT_VAL);
  515. info->rd_ptr_init_val = val & 0xffff;
  516. val = SDE_REG_READ(c, INTF_TEAR_INT_COUNT_VAL);
  517. info->rd_ptr_frame_count = (val & 0xffff0000) >> 16;
  518. info->rd_ptr_line_count = val & 0xffff;
  519. val = SDE_REG_READ(c, INTF_TEAR_LINE_COUNT);
  520. info->wr_ptr_line_count = val & 0xffff;
  521. val = SDE_REG_READ(c, INTF_FRAME_COUNT);
  522. info->intf_frame_count = val;
  523. return 0;
  524. }
  525. static void sde_hw_intf_vsync_sel(struct sde_hw_intf *intf,
  526. u32 vsync_source)
  527. {
  528. struct sde_hw_blk_reg_map *c;
  529. if (!intf)
  530. return;
  531. c = &intf->hw;
  532. SDE_REG_WRITE(c, INTF_TEAR_MDP_VSYNC_SEL, (vsync_source & 0xf));
  533. }
  534. static void _setup_intf_ops(struct sde_hw_intf_ops *ops,
  535. unsigned long cap)
  536. {
  537. ops->setup_timing_gen = sde_hw_intf_setup_timing_engine;
  538. ops->setup_prg_fetch = sde_hw_intf_setup_prg_fetch;
  539. ops->get_status = sde_hw_intf_get_status;
  540. ops->enable_timing = sde_hw_intf_enable_timing_engine;
  541. ops->setup_misr = sde_hw_intf_setup_misr;
  542. ops->collect_misr = sde_hw_intf_collect_misr;
  543. ops->get_line_count = sde_hw_intf_get_line_count;
  544. ops->avr_setup = sde_hw_intf_avr_setup;
  545. ops->avr_trigger = sde_hw_intf_avr_trigger;
  546. ops->avr_ctrl = sde_hw_intf_avr_ctrl;
  547. if (cap & BIT(SDE_INTF_INPUT_CTRL))
  548. ops->bind_pingpong_blk = sde_hw_intf_bind_pingpong_blk;
  549. if (cap & BIT(SDE_INTF_TE)) {
  550. ops->setup_tearcheck = sde_hw_intf_setup_te_config;
  551. ops->enable_tearcheck = sde_hw_intf_enable_te;
  552. ops->update_tearcheck = sde_hw_intf_update_te;
  553. ops->connect_external_te = sde_hw_intf_connect_external_te;
  554. ops->get_vsync_info = sde_hw_intf_get_vsync_info;
  555. ops->setup_autorefresh = sde_hw_intf_setup_autorefresh_config;
  556. ops->get_autorefresh = sde_hw_intf_get_autorefresh_config;
  557. ops->poll_timeout_wr_ptr = sde_hw_intf_poll_timeout_wr_ptr;
  558. ops->vsync_sel = sde_hw_intf_vsync_sel;
  559. ops->get_status = sde_hw_intf_v1_get_status;
  560. }
  561. }
  562. static struct sde_hw_blk_ops sde_hw_ops = {
  563. .start = NULL,
  564. .stop = NULL,
  565. };
  566. struct sde_hw_intf *sde_hw_intf_init(enum sde_intf idx,
  567. void __iomem *addr,
  568. struct sde_mdss_cfg *m)
  569. {
  570. struct sde_hw_intf *c;
  571. struct sde_intf_cfg *cfg;
  572. int rc;
  573. c = kzalloc(sizeof(*c), GFP_KERNEL);
  574. if (!c)
  575. return ERR_PTR(-ENOMEM);
  576. cfg = _intf_offset(idx, m, addr, &c->hw);
  577. if (IS_ERR_OR_NULL(cfg)) {
  578. kfree(c);
  579. pr_err("failed to create sde_hw_intf %d\n", idx);
  580. return ERR_PTR(-EINVAL);
  581. }
  582. /*
  583. * Assign ops
  584. */
  585. c->idx = idx;
  586. c->cap = cfg;
  587. c->mdss = m;
  588. _setup_intf_ops(&c->ops, c->cap->features);
  589. rc = sde_hw_blk_init(&c->base, SDE_HW_BLK_INTF, idx, &sde_hw_ops);
  590. if (rc) {
  591. SDE_ERROR("failed to init hw blk %d\n", rc);
  592. goto blk_init_error;
  593. }
  594. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
  595. c->hw.blk_off + c->hw.length, c->hw.xin_id);
  596. return c;
  597. blk_init_error:
  598. kzfree(c);
  599. return ERR_PTR(rc);
  600. }
  601. void sde_hw_intf_destroy(struct sde_hw_intf *intf)
  602. {
  603. if (intf)
  604. sde_hw_blk_destroy(&intf->base);
  605. kfree(intf);
  606. }