sde_hw_intf.c 29 KB

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