sde_hw_intf.c 27 KB

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