sde_hw_intf.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. #define AVR_CONTINUOUS_MODE 1
  80. #define AVR_ONE_SHOT_MODE 2
  81. static struct sde_intf_cfg *_intf_offset(enum sde_intf intf,
  82. struct sde_mdss_cfg *m,
  83. void __iomem *addr,
  84. struct sde_hw_blk_reg_map *b)
  85. {
  86. int i;
  87. for (i = 0; i < m->intf_count; i++) {
  88. if ((intf == m->intf[i].id) &&
  89. (m->intf[i].type != INTF_NONE)) {
  90. b->base_off = addr;
  91. b->blk_off = m->intf[i].base;
  92. b->length = m->intf[i].len;
  93. b->hwversion = m->hwversion;
  94. b->log_mask = SDE_DBG_MASK_INTF;
  95. return &m->intf[i];
  96. }
  97. }
  98. return ERR_PTR(-EINVAL);
  99. }
  100. static void sde_hw_intf_avr_trigger(struct sde_hw_intf *ctx)
  101. {
  102. struct sde_hw_blk_reg_map *c;
  103. if (!ctx)
  104. return;
  105. c = &ctx->hw;
  106. SDE_REG_WRITE(c, INTF_AVR_TRIGGER, 0x1);
  107. SDE_DEBUG("AVR Triggered\n");
  108. }
  109. static int sde_hw_intf_avr_setup(struct sde_hw_intf *ctx,
  110. const struct intf_timing_params *params,
  111. const struct intf_avr_params *avr_params)
  112. {
  113. struct sde_hw_blk_reg_map *c;
  114. u32 hsync_period, vsync_period;
  115. u32 min_fps, default_fps, diff_fps;
  116. u32 vsync_period_slow;
  117. u32 avr_vtotal;
  118. u32 add_porches;
  119. if (!ctx || !params || !avr_params) {
  120. SDE_ERROR("invalid input parameter(s)\n");
  121. return -EINVAL;
  122. }
  123. c = &ctx->hw;
  124. min_fps = avr_params->min_fps;
  125. default_fps = avr_params->default_fps;
  126. diff_fps = default_fps - min_fps;
  127. hsync_period = params->hsync_pulse_width +
  128. params->h_back_porch + params->width +
  129. params->h_front_porch;
  130. vsync_period = params->vsync_pulse_width +
  131. params->v_back_porch + params->height +
  132. params->v_front_porch;
  133. add_porches = mult_frac(vsync_period, diff_fps, min_fps);
  134. vsync_period_slow = vsync_period + add_porches;
  135. avr_vtotal = vsync_period_slow * hsync_period;
  136. SDE_REG_WRITE(c, INTF_AVR_VTOTAL, avr_vtotal);
  137. return 0;
  138. }
  139. static void sde_hw_intf_avr_ctrl(struct sde_hw_intf *ctx,
  140. const struct intf_avr_params *avr_params)
  141. {
  142. struct sde_hw_blk_reg_map *c;
  143. u32 avr_mode = 0;
  144. u32 avr_ctrl = 0;
  145. if (!ctx || !avr_params)
  146. return;
  147. c = &ctx->hw;
  148. if (avr_params->avr_mode) {
  149. avr_ctrl = BIT(0);
  150. avr_mode = (avr_params->avr_mode == AVR_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. else
  319. mux_cfg |= 0xf;
  320. if (intf->cfg.split_link_en)
  321. mux_cfg = 0x60000;
  322. SDE_REG_WRITE(c, INTF_MUX, mux_cfg);
  323. }
  324. static void sde_hw_intf_get_status(
  325. struct sde_hw_intf *intf,
  326. struct intf_status *s)
  327. {
  328. struct sde_hw_blk_reg_map *c = &intf->hw;
  329. s->is_en = SDE_REG_READ(c, INTF_TIMING_ENGINE_EN);
  330. if (s->is_en) {
  331. s->frame_count = SDE_REG_READ(c, INTF_FRAME_COUNT);
  332. s->line_count = SDE_REG_READ(c, INTF_LINE_COUNT);
  333. } else {
  334. s->line_count = 0;
  335. s->frame_count = 0;
  336. }
  337. }
  338. static void sde_hw_intf_v1_get_status(
  339. struct sde_hw_intf *intf,
  340. struct intf_status *s)
  341. {
  342. struct sde_hw_blk_reg_map *c = &intf->hw;
  343. s->is_en = SDE_REG_READ(c, INTF_STATUS) & BIT(0);
  344. if (s->is_en) {
  345. s->frame_count = SDE_REG_READ(c, INTF_FRAME_COUNT);
  346. s->line_count = SDE_REG_READ(c, INTF_LINE_COUNT);
  347. } else {
  348. s->line_count = 0;
  349. s->frame_count = 0;
  350. }
  351. }
  352. static void sde_hw_intf_setup_misr(struct sde_hw_intf *intf,
  353. bool enable, u32 frame_count)
  354. {
  355. struct sde_hw_blk_reg_map *c = &intf->hw;
  356. u32 config = 0;
  357. SDE_REG_WRITE(c, INTF_MISR_CTRL, MISR_CTRL_STATUS_CLEAR);
  358. /* clear misr data */
  359. wmb();
  360. if (enable)
  361. config = (frame_count & MISR_FRAME_COUNT_MASK) |
  362. MISR_CTRL_ENABLE |
  363. INTF_MISR_CTRL_FREE_RUN_MASK |
  364. INTF_MISR_CTRL_INPUT_SEL_DATA;
  365. SDE_REG_WRITE(c, INTF_MISR_CTRL, config);
  366. }
  367. static int sde_hw_intf_collect_misr(struct sde_hw_intf *intf, bool nonblock,
  368. u32 *misr_value)
  369. {
  370. struct sde_hw_blk_reg_map *c = &intf->hw;
  371. u32 ctrl = 0;
  372. if (!misr_value)
  373. return -EINVAL;
  374. ctrl = SDE_REG_READ(c, INTF_MISR_CTRL);
  375. if (!nonblock) {
  376. if (ctrl & MISR_CTRL_ENABLE) {
  377. int rc;
  378. rc = readl_poll_timeout(c->base_off + c->blk_off +
  379. INTF_MISR_CTRL, ctrl,
  380. (ctrl & MISR_CTRL_STATUS) > 0, 500,
  381. 84000);
  382. if (rc)
  383. return rc;
  384. } else {
  385. return -EINVAL;
  386. }
  387. }
  388. *misr_value = SDE_REG_READ(c, INTF_MISR_SIGNATURE);
  389. return 0;
  390. }
  391. static u32 sde_hw_intf_get_line_count(struct sde_hw_intf *intf)
  392. {
  393. struct sde_hw_blk_reg_map *c;
  394. if (!intf)
  395. return 0;
  396. c = &intf->hw;
  397. return SDE_REG_READ(c, INTF_LINE_COUNT);
  398. }
  399. static int sde_hw_intf_setup_te_config(struct sde_hw_intf *intf,
  400. struct sde_hw_tear_check *te)
  401. {
  402. struct sde_hw_blk_reg_map *c;
  403. int cfg;
  404. if (!intf)
  405. return -EINVAL;
  406. c = &intf->hw;
  407. cfg = BIT(19); /* VSYNC_COUNTER_EN */
  408. if (te->hw_vsync_mode)
  409. cfg |= BIT(20);
  410. cfg |= te->vsync_count;
  411. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_VSYNC, cfg);
  412. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_HEIGHT, te->sync_cfg_height);
  413. SDE_REG_WRITE(c, INTF_TEAR_VSYNC_INIT_VAL, te->vsync_init_val);
  414. SDE_REG_WRITE(c, INTF_TEAR_RD_PTR_IRQ, te->rd_ptr_irq);
  415. SDE_REG_WRITE(c, INTF_TEAR_WR_PTR_IRQ, te->wr_ptr_irq);
  416. SDE_REG_WRITE(c, INTF_TEAR_START_POS, te->start_pos);
  417. SDE_REG_WRITE(c, INTF_TEAR_SYNC_THRESH,
  418. ((te->sync_threshold_continue << 16) |
  419. te->sync_threshold_start));
  420. SDE_REG_WRITE(c, INTF_TEAR_SYNC_WRCOUNT,
  421. (te->start_pos + te->sync_threshold_start + 1));
  422. return 0;
  423. }
  424. static int sde_hw_intf_setup_autorefresh_config(struct sde_hw_intf *intf,
  425. struct sde_hw_autorefresh *cfg)
  426. {
  427. struct sde_hw_blk_reg_map *c;
  428. u32 refresh_cfg;
  429. if (!intf || !cfg)
  430. return -EINVAL;
  431. c = &intf->hw;
  432. if (cfg->enable)
  433. refresh_cfg = BIT(31) | cfg->frame_count;
  434. else
  435. refresh_cfg = 0;
  436. SDE_REG_WRITE(c, INTF_TEAR_AUTOREFRESH_CONFIG, refresh_cfg);
  437. return 0;
  438. }
  439. static int sde_hw_intf_get_autorefresh_config(struct sde_hw_intf *intf,
  440. struct sde_hw_autorefresh *cfg)
  441. {
  442. struct sde_hw_blk_reg_map *c;
  443. u32 val;
  444. if (!intf || !cfg)
  445. return -EINVAL;
  446. c = &intf->hw;
  447. val = SDE_REG_READ(c, INTF_TEAR_AUTOREFRESH_CONFIG);
  448. cfg->enable = (val & BIT(31)) >> 31;
  449. cfg->frame_count = val & 0xffff;
  450. return 0;
  451. }
  452. static int sde_hw_intf_poll_timeout_wr_ptr(struct sde_hw_intf *intf,
  453. u32 timeout_us)
  454. {
  455. struct sde_hw_blk_reg_map *c;
  456. u32 val;
  457. int rc;
  458. if (!intf)
  459. return -EINVAL;
  460. c = &intf->hw;
  461. rc = readl_poll_timeout(c->base_off + c->blk_off + INTF_TEAR_LINE_COUNT,
  462. val, (val & 0xffff) >= 1, 10, timeout_us);
  463. return rc;
  464. }
  465. static int sde_hw_intf_enable_te(struct sde_hw_intf *intf, bool enable)
  466. {
  467. struct sde_hw_blk_reg_map *c;
  468. if (!intf)
  469. return -EINVAL;
  470. c = &intf->hw;
  471. SDE_REG_WRITE(c, INTF_TEAR_TEAR_CHECK_EN, enable);
  472. return 0;
  473. }
  474. static void sde_hw_intf_update_te(struct sde_hw_intf *intf,
  475. struct sde_hw_tear_check *te)
  476. {
  477. struct sde_hw_blk_reg_map *c;
  478. int cfg;
  479. if (!intf || !te)
  480. return;
  481. c = &intf->hw;
  482. cfg = SDE_REG_READ(c, INTF_TEAR_SYNC_THRESH);
  483. cfg &= ~0xFFFF;
  484. cfg |= te->sync_threshold_start;
  485. SDE_REG_WRITE(c, INTF_TEAR_SYNC_THRESH, cfg);
  486. }
  487. static int sde_hw_intf_connect_external_te(struct sde_hw_intf *intf,
  488. bool enable_external_te)
  489. {
  490. struct sde_hw_blk_reg_map *c = &intf->hw;
  491. u32 cfg;
  492. int orig;
  493. if (!intf)
  494. return -EINVAL;
  495. c = &intf->hw;
  496. cfg = SDE_REG_READ(c, INTF_TEAR_SYNC_CONFIG_VSYNC);
  497. orig = (bool)(cfg & BIT(20));
  498. if (enable_external_te)
  499. cfg |= BIT(20);
  500. else
  501. cfg &= ~BIT(20);
  502. SDE_REG_WRITE(c, INTF_TEAR_SYNC_CONFIG_VSYNC, cfg);
  503. return orig;
  504. }
  505. static int sde_hw_intf_get_vsync_info(struct sde_hw_intf *intf,
  506. struct sde_hw_pp_vsync_info *info)
  507. {
  508. struct sde_hw_blk_reg_map *c = &intf->hw;
  509. u32 val;
  510. if (!intf || !info)
  511. return -EINVAL;
  512. c = &intf->hw;
  513. val = SDE_REG_READ(c, INTF_TEAR_VSYNC_INIT_VAL);
  514. info->rd_ptr_init_val = val & 0xffff;
  515. val = SDE_REG_READ(c, INTF_TEAR_INT_COUNT_VAL);
  516. info->rd_ptr_frame_count = (val & 0xffff0000) >> 16;
  517. info->rd_ptr_line_count = val & 0xffff;
  518. val = SDE_REG_READ(c, INTF_TEAR_LINE_COUNT);
  519. info->wr_ptr_line_count = val & 0xffff;
  520. return 0;
  521. }
  522. static void sde_hw_intf_vsync_sel(struct sde_hw_intf *intf,
  523. u32 vsync_source)
  524. {
  525. struct sde_hw_blk_reg_map *c;
  526. if (!intf)
  527. return;
  528. c = &intf->hw;
  529. SDE_REG_WRITE(c, INTF_TEAR_MDP_VSYNC_SEL, (vsync_source & 0xf));
  530. }
  531. static void _setup_intf_ops(struct sde_hw_intf_ops *ops,
  532. unsigned long cap)
  533. {
  534. ops->setup_timing_gen = sde_hw_intf_setup_timing_engine;
  535. ops->setup_prg_fetch = sde_hw_intf_setup_prg_fetch;
  536. ops->get_status = sde_hw_intf_get_status;
  537. ops->enable_timing = sde_hw_intf_enable_timing_engine;
  538. ops->setup_misr = sde_hw_intf_setup_misr;
  539. ops->collect_misr = sde_hw_intf_collect_misr;
  540. ops->get_line_count = sde_hw_intf_get_line_count;
  541. ops->avr_setup = sde_hw_intf_avr_setup;
  542. ops->avr_trigger = sde_hw_intf_avr_trigger;
  543. ops->avr_ctrl = sde_hw_intf_avr_ctrl;
  544. if (cap & BIT(SDE_INTF_INPUT_CTRL))
  545. ops->bind_pingpong_blk = sde_hw_intf_bind_pingpong_blk;
  546. if (cap & BIT(SDE_INTF_TE)) {
  547. ops->setup_tearcheck = sde_hw_intf_setup_te_config;
  548. ops->enable_tearcheck = sde_hw_intf_enable_te;
  549. ops->update_tearcheck = sde_hw_intf_update_te;
  550. ops->connect_external_te = sde_hw_intf_connect_external_te;
  551. ops->get_vsync_info = sde_hw_intf_get_vsync_info;
  552. ops->setup_autorefresh = sde_hw_intf_setup_autorefresh_config;
  553. ops->get_autorefresh = sde_hw_intf_get_autorefresh_config;
  554. ops->poll_timeout_wr_ptr = sde_hw_intf_poll_timeout_wr_ptr;
  555. ops->vsync_sel = sde_hw_intf_vsync_sel;
  556. ops->get_status = sde_hw_intf_v1_get_status;
  557. }
  558. }
  559. static struct sde_hw_blk_ops sde_hw_ops = {
  560. .start = NULL,
  561. .stop = NULL,
  562. };
  563. struct sde_hw_intf *sde_hw_intf_init(enum sde_intf idx,
  564. void __iomem *addr,
  565. struct sde_mdss_cfg *m)
  566. {
  567. struct sde_hw_intf *c;
  568. struct sde_intf_cfg *cfg;
  569. int rc;
  570. c = kzalloc(sizeof(*c), GFP_KERNEL);
  571. if (!c)
  572. return ERR_PTR(-ENOMEM);
  573. cfg = _intf_offset(idx, m, addr, &c->hw);
  574. if (IS_ERR_OR_NULL(cfg)) {
  575. kfree(c);
  576. pr_err("failed to create sde_hw_intf %d\n", idx);
  577. return ERR_PTR(-EINVAL);
  578. }
  579. /*
  580. * Assign ops
  581. */
  582. c->idx = idx;
  583. c->cap = cfg;
  584. c->mdss = m;
  585. _setup_intf_ops(&c->ops, c->cap->features);
  586. rc = sde_hw_blk_init(&c->base, SDE_HW_BLK_INTF, idx, &sde_hw_ops);
  587. if (rc) {
  588. SDE_ERROR("failed to init hw blk %d\n", rc);
  589. goto blk_init_error;
  590. }
  591. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
  592. c->hw.blk_off + c->hw.length, c->hw.xin_id);
  593. return c;
  594. blk_init_error:
  595. kzfree(c);
  596. return ERR_PTR(rc);
  597. }
  598. void sde_hw_intf_destroy(struct sde_hw_intf *intf)
  599. {
  600. if (intf)
  601. sde_hw_blk_destroy(&intf->base);
  602. kfree(intf);
  603. }