sde_encoder_phys_cmd.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021 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 "sde_encoder_phys.h"
  8. #include "sde_hw_interrupts.h"
  9. #include "sde_core_irq.h"
  10. #include "sde_formats.h"
  11. #include "sde_trace.h"
  12. #define SDE_DEBUG_CMDENC(e, fmt, ...) SDE_DEBUG("enc%d intf%d " fmt, \
  13. (e) && (e)->base.parent ? \
  14. (e)->base.parent->base.id : -1, \
  15. (e) ? (e)->base.intf_idx - INTF_0 : -1, ##__VA_ARGS__)
  16. #define SDE_ERROR_CMDENC(e, fmt, ...) SDE_ERROR("enc%d intf%d " fmt, \
  17. (e) && (e)->base.parent ? \
  18. (e)->base.parent->base.id : -1, \
  19. (e) ? (e)->base.intf_idx - INTF_0 : -1, ##__VA_ARGS__)
  20. #define to_sde_encoder_phys_cmd(x) \
  21. container_of(x, struct sde_encoder_phys_cmd, base)
  22. /*
  23. * Tearcheck sync start and continue thresholds are empirically found
  24. * based on common panels In the future, may want to allow panels to override
  25. * these default values
  26. */
  27. #define DEFAULT_TEARCHECK_SYNC_THRESH_START 4
  28. #define DEFAULT_TEARCHECK_SYNC_THRESH_CONTINUE 4
  29. #define SDE_ENC_WR_PTR_START_TIMEOUT_US 20000
  30. #define AUTOREFRESH_SEQ1_POLL_TIME 2000
  31. #define AUTOREFRESH_SEQ2_POLL_TIME 25000
  32. #define AUTOREFRESH_SEQ2_POLL_TIMEOUT 1000000
  33. static inline int _sde_encoder_phys_cmd_get_idle_timeout(
  34. struct sde_encoder_phys *phys_enc)
  35. {
  36. u32 timeout = phys_enc->kickoff_timeout_ms;
  37. struct sde_encoder_phys_cmd *cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  38. return cmd_enc->autorefresh.cfg.frame_count ?
  39. cmd_enc->autorefresh.cfg.frame_count * timeout : timeout;
  40. }
  41. static inline bool sde_encoder_phys_cmd_is_master(
  42. struct sde_encoder_phys *phys_enc)
  43. {
  44. return (phys_enc->split_role != ENC_ROLE_SLAVE) ? true : false;
  45. }
  46. static bool sde_encoder_phys_cmd_mode_fixup(
  47. struct sde_encoder_phys *phys_enc,
  48. const struct drm_display_mode *mode,
  49. struct drm_display_mode *adj_mode)
  50. {
  51. if (phys_enc)
  52. SDE_DEBUG_CMDENC(to_sde_encoder_phys_cmd(phys_enc), "\n");
  53. return true;
  54. }
  55. static uint64_t _sde_encoder_phys_cmd_get_autorefresh_property(
  56. struct sde_encoder_phys *phys_enc)
  57. {
  58. struct drm_connector *conn = phys_enc->connector;
  59. if (!conn || !conn->state)
  60. return 0;
  61. return sde_connector_get_property(conn->state,
  62. CONNECTOR_PROP_AUTOREFRESH);
  63. }
  64. static void _sde_encoder_phys_cmd_config_autorefresh(
  65. struct sde_encoder_phys *phys_enc,
  66. u32 new_frame_count)
  67. {
  68. struct sde_encoder_phys_cmd *cmd_enc =
  69. to_sde_encoder_phys_cmd(phys_enc);
  70. struct sde_hw_pingpong *hw_pp = phys_enc->hw_pp;
  71. struct sde_hw_intf *hw_intf = phys_enc->hw_intf;
  72. struct drm_connector *conn = phys_enc->connector;
  73. struct sde_hw_autorefresh *cfg_cur, cfg_nxt;
  74. if (!conn || !conn->state || !hw_pp || !hw_intf)
  75. return;
  76. cfg_cur = &cmd_enc->autorefresh.cfg;
  77. /* autorefresh property value should be validated already */
  78. memset(&cfg_nxt, 0, sizeof(cfg_nxt));
  79. cfg_nxt.frame_count = new_frame_count;
  80. cfg_nxt.enable = (cfg_nxt.frame_count != 0);
  81. SDE_DEBUG_CMDENC(cmd_enc, "autorefresh state %d->%d framecount %d\n",
  82. cfg_cur->enable, cfg_nxt.enable, cfg_nxt.frame_count);
  83. SDE_EVT32(DRMID(phys_enc->parent), hw_pp->idx, hw_intf->idx,
  84. cfg_cur->enable, cfg_nxt.enable, cfg_nxt.frame_count);
  85. /* only proceed on state changes */
  86. if (cfg_nxt.enable == cfg_cur->enable)
  87. return;
  88. memcpy(cfg_cur, &cfg_nxt, sizeof(*cfg_cur));
  89. if (phys_enc->has_intf_te && hw_intf->ops.setup_autorefresh)
  90. hw_intf->ops.setup_autorefresh(hw_intf, cfg_cur);
  91. else if (hw_pp->ops.setup_autorefresh)
  92. hw_pp->ops.setup_autorefresh(hw_pp, cfg_cur);
  93. }
  94. static void _sde_encoder_phys_cmd_update_flush_mask(
  95. struct sde_encoder_phys *phys_enc)
  96. {
  97. struct sde_encoder_phys_cmd *cmd_enc;
  98. struct sde_hw_ctl *ctl;
  99. if (!phys_enc || !phys_enc->hw_intf || !phys_enc->hw_pp)
  100. return;
  101. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  102. ctl = phys_enc->hw_ctl;
  103. if (!ctl)
  104. return;
  105. if (!ctl->ops.update_bitmask) {
  106. SDE_ERROR("invalid hw_ctl ops %d\n", ctl->idx);
  107. return;
  108. }
  109. ctl->ops.update_bitmask(ctl, SDE_HW_FLUSH_INTF, phys_enc->intf_idx, 1);
  110. if (phys_enc->hw_pp->merge_3d)
  111. ctl->ops.update_bitmask(ctl, SDE_HW_FLUSH_MERGE_3D,
  112. phys_enc->hw_pp->merge_3d->idx, 1);
  113. SDE_DEBUG_CMDENC(cmd_enc, "update pending flush ctl %d intf_idx %x\n",
  114. ctl->idx - CTL_0, phys_enc->intf_idx);
  115. }
  116. static void _sde_encoder_phys_cmd_update_intf_cfg(
  117. struct sde_encoder_phys *phys_enc)
  118. {
  119. struct sde_encoder_phys_cmd *cmd_enc =
  120. to_sde_encoder_phys_cmd(phys_enc);
  121. struct sde_hw_ctl *ctl;
  122. if (!phys_enc)
  123. return;
  124. ctl = phys_enc->hw_ctl;
  125. if (!ctl)
  126. return;
  127. if (ctl->ops.setup_intf_cfg) {
  128. struct sde_hw_intf_cfg intf_cfg = { 0 };
  129. intf_cfg.intf = phys_enc->intf_idx;
  130. intf_cfg.intf_mode_sel = SDE_CTL_MODE_SEL_CMD;
  131. intf_cfg.stream_sel = cmd_enc->stream_sel;
  132. intf_cfg.mode_3d =
  133. sde_encoder_helper_get_3d_blend_mode(phys_enc);
  134. ctl->ops.setup_intf_cfg(ctl, &intf_cfg);
  135. } else if (test_bit(SDE_CTL_ACTIVE_CFG, &ctl->caps->features)) {
  136. sde_encoder_helper_update_intf_cfg(phys_enc);
  137. }
  138. }
  139. static void sde_encoder_phys_cmd_pp_tx_done_irq(void *arg, int irq_idx)
  140. {
  141. struct sde_encoder_phys *phys_enc = arg;
  142. struct sde_encoder_phys_cmd *cmd_enc;
  143. struct sde_hw_ctl *ctl;
  144. u32 scheduler_status = INVALID_CTL_STATUS, event = 0;
  145. if (!phys_enc || !phys_enc->hw_pp)
  146. return;
  147. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  148. ctl = phys_enc->hw_ctl;
  149. SDE_ATRACE_BEGIN("pp_done_irq");
  150. /* notify all synchronous clients first, then asynchronous clients */
  151. if (phys_enc->parent_ops.handle_frame_done &&
  152. atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0)) {
  153. event = SDE_ENCODER_FRAME_EVENT_DONE |
  154. SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE;
  155. spin_lock(phys_enc->enc_spinlock);
  156. phys_enc->parent_ops.handle_frame_done(phys_enc->parent,
  157. phys_enc, event);
  158. if (cmd_enc->pp_timeout_report_cnt)
  159. phys_enc->recovered = true;
  160. spin_unlock(phys_enc->enc_spinlock);
  161. }
  162. if (ctl && ctl->ops.get_scheduler_status)
  163. scheduler_status = ctl->ops.get_scheduler_status(ctl);
  164. SDE_EVT32_IRQ(DRMID(phys_enc->parent),
  165. phys_enc->hw_pp->idx - PINGPONG_0, event, scheduler_status);
  166. /* Signal any waiting atomic commit thread */
  167. wake_up_all(&phys_enc->pending_kickoff_wq);
  168. SDE_ATRACE_END("pp_done_irq");
  169. }
  170. static void sde_encoder_phys_cmd_autorefresh_done_irq(void *arg, int irq_idx)
  171. {
  172. struct sde_encoder_phys *phys_enc = arg;
  173. struct sde_encoder_phys_cmd *cmd_enc =
  174. to_sde_encoder_phys_cmd(phys_enc);
  175. unsigned long lock_flags;
  176. int new_cnt;
  177. if (!cmd_enc)
  178. return;
  179. phys_enc = &cmd_enc->base;
  180. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  181. new_cnt = atomic_add_unless(&cmd_enc->autorefresh.kickoff_cnt, -1, 0);
  182. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  183. SDE_EVT32_IRQ(DRMID(phys_enc->parent),
  184. phys_enc->hw_pp->idx - PINGPONG_0,
  185. phys_enc->hw_intf->idx - INTF_0,
  186. new_cnt);
  187. /* Signal any waiting atomic commit thread */
  188. wake_up_all(&cmd_enc->autorefresh.kickoff_wq);
  189. }
  190. static void sde_encoder_phys_cmd_te_rd_ptr_irq(void *arg, int irq_idx)
  191. {
  192. struct sde_encoder_phys *phys_enc = arg;
  193. struct sde_encoder_phys_cmd *cmd_enc;
  194. u32 scheduler_status = INVALID_CTL_STATUS;
  195. struct sde_hw_ctl *ctl;
  196. struct sde_hw_pp_vsync_info info[MAX_CHANNELS_PER_ENC] = {{0}};
  197. struct sde_encoder_phys_cmd_te_timestamp *te_timestamp;
  198. unsigned long lock_flags;
  199. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  200. return;
  201. SDE_ATRACE_BEGIN("rd_ptr_irq");
  202. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  203. ctl = phys_enc->hw_ctl;
  204. if (ctl && ctl->ops.get_scheduler_status)
  205. scheduler_status = ctl->ops.get_scheduler_status(ctl);
  206. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  207. te_timestamp = list_first_entry_or_null(&cmd_enc->te_timestamp_list,
  208. struct sde_encoder_phys_cmd_te_timestamp, list);
  209. if (te_timestamp) {
  210. list_del_init(&te_timestamp->list);
  211. te_timestamp->timestamp = ktime_get();
  212. list_add_tail(&te_timestamp->list, &cmd_enc->te_timestamp_list);
  213. }
  214. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  215. sde_encoder_helper_get_pp_line_count(phys_enc->parent, info);
  216. SDE_EVT32_IRQ(DRMID(phys_enc->parent),
  217. info[0].pp_idx, info[0].intf_idx,
  218. info[0].wr_ptr_line_count, info[0].intf_frame_count,
  219. info[1].pp_idx, info[1].intf_idx,
  220. info[1].wr_ptr_line_count, info[1].intf_frame_count,
  221. scheduler_status);
  222. if (phys_enc->parent_ops.handle_vblank_virt)
  223. phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent,
  224. phys_enc);
  225. atomic_add_unless(&cmd_enc->pending_vblank_cnt, -1, 0);
  226. wake_up_all(&cmd_enc->pending_vblank_wq);
  227. SDE_ATRACE_END("rd_ptr_irq");
  228. }
  229. static void sde_encoder_phys_cmd_wr_ptr_irq(void *arg, int irq_idx)
  230. {
  231. struct sde_encoder_phys *phys_enc = arg;
  232. struct sde_hw_ctl *ctl;
  233. u32 event = 0;
  234. struct sde_hw_pp_vsync_info info[MAX_CHANNELS_PER_ENC] = {{0}};
  235. if (!phys_enc || !phys_enc->hw_ctl)
  236. return;
  237. SDE_ATRACE_BEGIN("wr_ptr_irq");
  238. ctl = phys_enc->hw_ctl;
  239. if (atomic_add_unless(&phys_enc->pending_retire_fence_cnt, -1, 0)) {
  240. event = SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE;
  241. if (phys_enc->parent_ops.handle_frame_done) {
  242. spin_lock(phys_enc->enc_spinlock);
  243. phys_enc->parent_ops.handle_frame_done(
  244. phys_enc->parent, phys_enc, event);
  245. spin_unlock(phys_enc->enc_spinlock);
  246. }
  247. }
  248. sde_encoder_helper_get_pp_line_count(phys_enc->parent, info);
  249. SDE_EVT32_IRQ(DRMID(phys_enc->parent),
  250. ctl->idx - CTL_0, event,
  251. info[0].pp_idx, info[0].intf_idx, info[0].wr_ptr_line_count,
  252. info[1].pp_idx, info[1].intf_idx, info[1].wr_ptr_line_count);
  253. /* Signal any waiting wr_ptr start interrupt */
  254. wake_up_all(&phys_enc->pending_kickoff_wq);
  255. SDE_ATRACE_END("wr_ptr_irq");
  256. }
  257. static void _sde_encoder_phys_cmd_setup_irq_hw_idx(
  258. struct sde_encoder_phys *phys_enc)
  259. {
  260. struct sde_encoder_irq *irq;
  261. struct sde_kms *sde_kms;
  262. if (!phys_enc->sde_kms || !phys_enc->hw_pp || !phys_enc->hw_ctl) {
  263. SDE_ERROR("invalid args %d %d %d\n", !phys_enc->sde_kms,
  264. !phys_enc->hw_pp, !phys_enc->hw_ctl);
  265. return;
  266. }
  267. if (phys_enc->has_intf_te && !phys_enc->hw_intf) {
  268. SDE_ERROR("invalid intf configuration\n");
  269. return;
  270. }
  271. sde_kms = phys_enc->sde_kms;
  272. irq = &phys_enc->irq[INTR_IDX_CTL_START];
  273. irq->hw_idx = phys_enc->hw_ctl->idx;
  274. irq = &phys_enc->irq[INTR_IDX_PINGPONG];
  275. irq->hw_idx = phys_enc->hw_pp->idx;
  276. irq = &phys_enc->irq[INTR_IDX_RDPTR];
  277. if (phys_enc->has_intf_te)
  278. irq->hw_idx = phys_enc->hw_intf->idx;
  279. else
  280. irq->hw_idx = phys_enc->hw_pp->idx;
  281. irq = &phys_enc->irq[INTR_IDX_AUTOREFRESH_DONE];
  282. if (phys_enc->has_intf_te)
  283. irq->hw_idx = phys_enc->hw_intf->idx;
  284. else
  285. irq->hw_idx = phys_enc->hw_pp->idx;
  286. irq = &phys_enc->irq[INTR_IDX_WRPTR];
  287. if (phys_enc->has_intf_te)
  288. irq->hw_idx = phys_enc->hw_intf->idx;
  289. else
  290. irq->hw_idx = phys_enc->hw_pp->idx;
  291. }
  292. static void sde_encoder_phys_cmd_cont_splash_mode_set(
  293. struct sde_encoder_phys *phys_enc,
  294. struct drm_display_mode *adj_mode)
  295. {
  296. struct sde_hw_intf *hw_intf;
  297. struct sde_hw_pingpong *hw_pp;
  298. struct sde_encoder_phys_cmd *cmd_enc;
  299. if (!phys_enc || !adj_mode) {
  300. SDE_ERROR("invalid args\n");
  301. return;
  302. }
  303. phys_enc->cached_mode = *adj_mode;
  304. phys_enc->enable_state = SDE_ENC_ENABLED;
  305. if (!phys_enc->hw_ctl || !phys_enc->hw_pp) {
  306. SDE_DEBUG("invalid ctl:%d pp:%d\n",
  307. (phys_enc->hw_ctl == NULL),
  308. (phys_enc->hw_pp == NULL));
  309. return;
  310. }
  311. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  312. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  313. hw_pp = phys_enc->hw_pp;
  314. hw_intf = phys_enc->hw_intf;
  315. if (phys_enc->has_intf_te && hw_intf &&
  316. hw_intf->ops.get_autorefresh) {
  317. hw_intf->ops.get_autorefresh(hw_intf,
  318. &cmd_enc->autorefresh.cfg);
  319. } else if (hw_pp && hw_pp->ops.get_autorefresh) {
  320. hw_pp->ops.get_autorefresh(hw_pp,
  321. &cmd_enc->autorefresh.cfg);
  322. }
  323. if (hw_intf && hw_intf->ops.reset_counter)
  324. hw_intf->ops.reset_counter(hw_intf);
  325. }
  326. _sde_encoder_phys_cmd_setup_irq_hw_idx(phys_enc);
  327. }
  328. static void sde_encoder_phys_cmd_mode_set(
  329. struct sde_encoder_phys *phys_enc,
  330. struct drm_display_mode *mode,
  331. struct drm_display_mode *adj_mode, bool *reinit_mixers)
  332. {
  333. struct sde_encoder_phys_cmd *cmd_enc =
  334. to_sde_encoder_phys_cmd(phys_enc);
  335. struct sde_rm *rm = &phys_enc->sde_kms->rm;
  336. struct sde_rm_hw_iter iter;
  337. int i, instance;
  338. if (!phys_enc || !mode || !adj_mode) {
  339. SDE_ERROR("invalid args\n");
  340. return;
  341. }
  342. phys_enc->cached_mode = *adj_mode;
  343. SDE_DEBUG_CMDENC(cmd_enc, "caching mode:\n");
  344. drm_mode_debug_printmodeline(adj_mode);
  345. instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0;
  346. /* Retrieve previously allocated HW Resources. Shouldn't fail */
  347. sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CTL);
  348. for (i = 0; i <= instance; i++) {
  349. if (sde_rm_get_hw(rm, &iter)) {
  350. if (phys_enc->hw_ctl && phys_enc->hw_ctl != iter.hw) {
  351. *reinit_mixers = true;
  352. SDE_EVT32(phys_enc->hw_ctl->idx,
  353. ((struct sde_hw_ctl *)iter.hw)->idx);
  354. }
  355. phys_enc->hw_ctl = (struct sde_hw_ctl *)iter.hw;
  356. }
  357. }
  358. if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
  359. SDE_ERROR_CMDENC(cmd_enc, "failed to init ctl: %ld\n",
  360. PTR_ERR(phys_enc->hw_ctl));
  361. phys_enc->hw_ctl = NULL;
  362. return;
  363. }
  364. sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_INTF);
  365. for (i = 0; i <= instance; i++) {
  366. if (sde_rm_get_hw(rm, &iter))
  367. phys_enc->hw_intf = (struct sde_hw_intf *)iter.hw;
  368. }
  369. if (IS_ERR_OR_NULL(phys_enc->hw_intf)) {
  370. SDE_ERROR_CMDENC(cmd_enc, "failed to init intf: %ld\n",
  371. PTR_ERR(phys_enc->hw_intf));
  372. phys_enc->hw_intf = NULL;
  373. return;
  374. }
  375. _sde_encoder_phys_cmd_setup_irq_hw_idx(phys_enc);
  376. phys_enc->kickoff_timeout_ms =
  377. sde_encoder_helper_get_kickoff_timeout_ms(phys_enc->parent);
  378. }
  379. static int _sde_encoder_phys_cmd_handle_ppdone_timeout(
  380. struct sde_encoder_phys *phys_enc)
  381. {
  382. struct sde_encoder_phys_cmd *cmd_enc =
  383. to_sde_encoder_phys_cmd(phys_enc);
  384. bool recovery_events = sde_encoder_recovery_events_enabled(
  385. phys_enc->parent);
  386. u32 frame_event = SDE_ENCODER_FRAME_EVENT_ERROR
  387. | SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE;
  388. struct drm_connector *conn;
  389. u32 pending_kickoff_cnt;
  390. unsigned long lock_flags;
  391. if (!phys_enc->hw_pp || !phys_enc->hw_ctl)
  392. return -EINVAL;
  393. conn = phys_enc->connector;
  394. /* decrement the kickoff_cnt before checking for ESD status */
  395. if (!atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0))
  396. return 0;
  397. cmd_enc->pp_timeout_report_cnt++;
  398. pending_kickoff_cnt = atomic_read(&phys_enc->pending_kickoff_cnt) + 1;
  399. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  400. cmd_enc->pp_timeout_report_cnt,
  401. pending_kickoff_cnt,
  402. frame_event);
  403. /* check if panel is still sending TE signal or not */
  404. if (sde_connector_esd_status(phys_enc->connector))
  405. goto exit;
  406. /* to avoid flooding, only log first time, and "dead" time */
  407. if (cmd_enc->pp_timeout_report_cnt == 1) {
  408. SDE_ERROR_CMDENC(cmd_enc,
  409. "pp:%d kickoff timed out ctl %d koff_cnt %d\n",
  410. phys_enc->hw_pp->idx - PINGPONG_0,
  411. phys_enc->hw_ctl->idx - CTL_0,
  412. pending_kickoff_cnt);
  413. SDE_EVT32(DRMID(phys_enc->parent), SDE_EVTLOG_FATAL);
  414. mutex_lock(phys_enc->vblank_ctl_lock);
  415. sde_encoder_helper_unregister_irq(phys_enc, INTR_IDX_RDPTR);
  416. if (sde_kms_is_secure_session_inprogress(phys_enc->sde_kms))
  417. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL, "secure");
  418. else
  419. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL);
  420. sde_encoder_helper_register_irq(phys_enc, INTR_IDX_RDPTR);
  421. mutex_unlock(phys_enc->vblank_ctl_lock);
  422. }
  423. /*
  424. * if the recovery event is registered by user, don't panic
  425. * trigger panic on first timeout if no listener registered
  426. */
  427. if (recovery_events)
  428. sde_connector_event_notify(conn, DRM_EVENT_SDE_HW_RECOVERY,
  429. sizeof(uint8_t), SDE_RECOVERY_CAPTURE);
  430. else if (cmd_enc->pp_timeout_report_cnt)
  431. SDE_DBG_DUMP(0x0, "panic");
  432. /* request a ctl reset before the next kickoff */
  433. phys_enc->enable_state = SDE_ENC_ERR_NEEDS_HW_RESET;
  434. exit:
  435. if (phys_enc->parent_ops.handle_frame_done) {
  436. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  437. phys_enc->parent_ops.handle_frame_done(
  438. phys_enc->parent, phys_enc, frame_event);
  439. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  440. }
  441. return -ETIMEDOUT;
  442. }
  443. static bool _sde_encoder_phys_is_ppsplit_slave(
  444. struct sde_encoder_phys *phys_enc)
  445. {
  446. if (!phys_enc)
  447. return false;
  448. return _sde_encoder_phys_is_ppsplit(phys_enc) &&
  449. phys_enc->split_role == ENC_ROLE_SLAVE;
  450. }
  451. static bool _sde_encoder_phys_is_disabling_ppsplit_slave(
  452. struct sde_encoder_phys *phys_enc)
  453. {
  454. enum sde_rm_topology_name old_top;
  455. if (!phys_enc || !phys_enc->connector ||
  456. phys_enc->split_role != ENC_ROLE_SLAVE)
  457. return false;
  458. old_top = sde_connector_get_old_topology_name(
  459. phys_enc->connector->state);
  460. return old_top == SDE_RM_TOPOLOGY_PPSPLIT;
  461. }
  462. static int _sde_encoder_phys_cmd_poll_write_pointer_started(
  463. struct sde_encoder_phys *phys_enc)
  464. {
  465. struct sde_encoder_phys_cmd *cmd_enc =
  466. to_sde_encoder_phys_cmd(phys_enc);
  467. struct sde_hw_pingpong *hw_pp = phys_enc->hw_pp;
  468. struct sde_hw_intf *hw_intf = phys_enc->hw_intf;
  469. struct sde_hw_pp_vsync_info info;
  470. u32 timeout_us = SDE_ENC_WR_PTR_START_TIMEOUT_US;
  471. int ret = 0;
  472. if (!hw_pp || !hw_intf)
  473. return 0;
  474. if (phys_enc->has_intf_te) {
  475. if (!hw_intf->ops.get_vsync_info ||
  476. !hw_intf->ops.poll_timeout_wr_ptr)
  477. goto end;
  478. } else {
  479. if (!hw_pp->ops.get_vsync_info ||
  480. !hw_pp->ops.poll_timeout_wr_ptr)
  481. goto end;
  482. }
  483. if (phys_enc->has_intf_te)
  484. ret = hw_intf->ops.get_vsync_info(hw_intf, &info);
  485. else
  486. ret = hw_pp->ops.get_vsync_info(hw_pp, &info);
  487. if (ret)
  488. return ret;
  489. SDE_DEBUG_CMDENC(cmd_enc,
  490. "pp:%d intf:%d rd_ptr %d wr_ptr %d\n",
  491. phys_enc->hw_pp->idx - PINGPONG_0,
  492. phys_enc->hw_intf->idx - INTF_0,
  493. info.rd_ptr_line_count,
  494. info.wr_ptr_line_count);
  495. SDE_EVT32_VERBOSE(DRMID(phys_enc->parent),
  496. phys_enc->hw_pp->idx - PINGPONG_0,
  497. phys_enc->hw_intf->idx - INTF_0,
  498. info.wr_ptr_line_count);
  499. if (phys_enc->has_intf_te)
  500. ret = hw_intf->ops.poll_timeout_wr_ptr(hw_intf, timeout_us);
  501. else
  502. ret = hw_pp->ops.poll_timeout_wr_ptr(hw_pp, timeout_us);
  503. if (ret) {
  504. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  505. phys_enc->hw_intf->idx - INTF_0, timeout_us, ret);
  506. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL, "panic");
  507. }
  508. end:
  509. return ret;
  510. }
  511. static bool _sde_encoder_phys_cmd_is_ongoing_pptx(
  512. struct sde_encoder_phys *phys_enc)
  513. {
  514. struct sde_hw_pingpong *hw_pp;
  515. struct sde_hw_pp_vsync_info info;
  516. struct sde_hw_intf *hw_intf;
  517. if (!phys_enc)
  518. return false;
  519. if (phys_enc->has_intf_te) {
  520. hw_intf = phys_enc->hw_intf;
  521. if (!hw_intf || !hw_intf->ops.get_vsync_info)
  522. return false;
  523. hw_intf->ops.get_vsync_info(hw_intf, &info);
  524. } else {
  525. hw_pp = phys_enc->hw_pp;
  526. if (!hw_pp || !hw_pp->ops.get_vsync_info)
  527. return false;
  528. hw_pp->ops.get_vsync_info(hw_pp, &info);
  529. }
  530. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  531. phys_enc->hw_intf->idx - INTF_0, atomic_read(&phys_enc->pending_kickoff_cnt),
  532. info.wr_ptr_line_count, info.intf_frame_count, phys_enc->cached_mode.vdisplay);
  533. if (info.wr_ptr_line_count > 0 && info.wr_ptr_line_count <
  534. phys_enc->cached_mode.vdisplay)
  535. return true;
  536. return false;
  537. }
  538. static bool _sde_encoder_phys_cmd_is_scheduler_idle(
  539. struct sde_encoder_phys *phys_enc)
  540. {
  541. bool wr_ptr_wait_success = true;
  542. unsigned long lock_flags;
  543. bool ret = false;
  544. struct sde_encoder_phys_cmd *cmd_enc =
  545. to_sde_encoder_phys_cmd(phys_enc);
  546. struct sde_hw_ctl *ctl = phys_enc->hw_ctl;
  547. enum frame_trigger_mode_type frame_trigger_mode =
  548. phys_enc->frame_trigger_mode;
  549. if (sde_encoder_phys_cmd_is_master(phys_enc))
  550. wr_ptr_wait_success = cmd_enc->wr_ptr_wait_success;
  551. /*
  552. * Handle cases where a pp-done interrupt is missed
  553. * due to irq latency with POSTED start
  554. */
  555. if (wr_ptr_wait_success &&
  556. (frame_trigger_mode == FRAME_DONE_WAIT_POSTED_START) &&
  557. ctl->ops.get_scheduler_status &&
  558. phys_enc->parent_ops.handle_frame_done &&
  559. atomic_read(&phys_enc->pending_kickoff_cnt) > 0 &&
  560. (ctl->ops.get_scheduler_status(ctl) & BIT(0)) &&
  561. atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0)) {
  562. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  563. phys_enc->parent_ops.handle_frame_done(
  564. phys_enc->parent, phys_enc,
  565. SDE_ENCODER_FRAME_EVENT_DONE |
  566. SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE);
  567. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  568. SDE_EVT32(DRMID(phys_enc->parent),
  569. phys_enc->hw_pp->idx - PINGPONG_0,
  570. phys_enc->hw_intf->idx - INTF_0,
  571. atomic_read(&phys_enc->pending_kickoff_cnt));
  572. ret = true;
  573. }
  574. return ret;
  575. }
  576. static int _sde_encoder_phys_cmd_wait_for_idle(
  577. struct sde_encoder_phys *phys_enc)
  578. {
  579. struct sde_encoder_wait_info wait_info = {0};
  580. int ret;
  581. if (!phys_enc) {
  582. SDE_ERROR("invalid encoder\n");
  583. return -EINVAL;
  584. }
  585. if (atomic_read(&phys_enc->pending_kickoff_cnt) > 1)
  586. wait_info.count_check = 1;
  587. wait_info.wq = &phys_enc->pending_kickoff_wq;
  588. wait_info.atomic_cnt = &phys_enc->pending_kickoff_cnt;
  589. wait_info.timeout_ms = phys_enc->kickoff_timeout_ms;
  590. /* slave encoder doesn't enable for ppsplit */
  591. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  592. return 0;
  593. if (_sde_encoder_phys_cmd_is_scheduler_idle(phys_enc))
  594. return 0;
  595. ret = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_PINGPONG,
  596. &wait_info);
  597. if (ret == -ETIMEDOUT) {
  598. if (_sde_encoder_phys_cmd_is_scheduler_idle(phys_enc))
  599. return 0;
  600. _sde_encoder_phys_cmd_handle_ppdone_timeout(phys_enc);
  601. }
  602. return ret;
  603. }
  604. static int _sde_encoder_phys_cmd_wait_for_autorefresh_done(
  605. struct sde_encoder_phys *phys_enc)
  606. {
  607. struct sde_encoder_phys_cmd *cmd_enc =
  608. to_sde_encoder_phys_cmd(phys_enc);
  609. struct sde_encoder_wait_info wait_info = {0};
  610. int ret = 0;
  611. if (!phys_enc) {
  612. SDE_ERROR("invalid encoder\n");
  613. return -EINVAL;
  614. }
  615. /* only master deals with autorefresh */
  616. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  617. return 0;
  618. wait_info.wq = &cmd_enc->autorefresh.kickoff_wq;
  619. wait_info.atomic_cnt = &cmd_enc->autorefresh.kickoff_cnt;
  620. wait_info.timeout_ms = _sde_encoder_phys_cmd_get_idle_timeout(phys_enc);
  621. /* wait for autorefresh kickoff to start */
  622. ret = sde_encoder_helper_wait_for_irq(phys_enc,
  623. INTR_IDX_AUTOREFRESH_DONE, &wait_info);
  624. /* double check that kickoff has started by reading write ptr reg */
  625. if (!ret)
  626. ret = _sde_encoder_phys_cmd_poll_write_pointer_started(
  627. phys_enc);
  628. else
  629. sde_encoder_helper_report_irq_timeout(phys_enc,
  630. INTR_IDX_AUTOREFRESH_DONE);
  631. return ret;
  632. }
  633. static int sde_encoder_phys_cmd_control_vblank_irq(
  634. struct sde_encoder_phys *phys_enc,
  635. bool enable)
  636. {
  637. struct sde_encoder_phys_cmd *cmd_enc =
  638. to_sde_encoder_phys_cmd(phys_enc);
  639. int ret = 0;
  640. u32 refcount;
  641. struct sde_kms *sde_kms;
  642. if (!phys_enc || !phys_enc->hw_pp) {
  643. SDE_ERROR("invalid encoder\n");
  644. return -EINVAL;
  645. }
  646. sde_kms = phys_enc->sde_kms;
  647. mutex_lock(phys_enc->vblank_ctl_lock);
  648. /* Slave encoders don't report vblank */
  649. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  650. goto end;
  651. refcount = atomic_read(&phys_enc->vblank_refcount);
  652. /* protect against negative */
  653. if (!enable && refcount == 0) {
  654. ret = -EINVAL;
  655. goto end;
  656. }
  657. SDE_DEBUG_CMDENC(cmd_enc, "[%pS] enable=%d/%d\n",
  658. __builtin_return_address(0), enable, refcount);
  659. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  660. enable, refcount);
  661. if (enable && atomic_inc_return(&phys_enc->vblank_refcount) == 1) {
  662. ret = sde_encoder_helper_register_irq(phys_enc, INTR_IDX_RDPTR);
  663. if (ret)
  664. atomic_dec_return(&phys_enc->vblank_refcount);
  665. } else if (!enable &&
  666. atomic_dec_return(&phys_enc->vblank_refcount) == 0) {
  667. ret = sde_encoder_helper_unregister_irq(phys_enc,
  668. INTR_IDX_RDPTR);
  669. if (ret)
  670. atomic_inc_return(&phys_enc->vblank_refcount);
  671. }
  672. end:
  673. mutex_unlock(phys_enc->vblank_ctl_lock);
  674. if (ret) {
  675. SDE_ERROR_CMDENC(cmd_enc,
  676. "control vblank irq error %d, enable %d, refcount %d\n",
  677. ret, enable, refcount);
  678. SDE_EVT32(DRMID(phys_enc->parent),
  679. phys_enc->hw_pp->idx - PINGPONG_0,
  680. enable, refcount, SDE_EVTLOG_ERROR);
  681. }
  682. return ret;
  683. }
  684. void sde_encoder_phys_cmd_irq_control(struct sde_encoder_phys *phys_enc,
  685. bool enable)
  686. {
  687. struct sde_encoder_phys_cmd *cmd_enc;
  688. if (!phys_enc)
  689. return;
  690. /**
  691. * pingpong split slaves do not register for IRQs
  692. * check old and new topologies
  693. */
  694. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc) ||
  695. _sde_encoder_phys_is_disabling_ppsplit_slave(phys_enc))
  696. return;
  697. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  698. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  699. enable, atomic_read(&phys_enc->vblank_refcount));
  700. if (enable) {
  701. sde_encoder_helper_register_irq(phys_enc, INTR_IDX_PINGPONG);
  702. sde_encoder_phys_cmd_control_vblank_irq(phys_enc, true);
  703. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  704. sde_encoder_helper_register_irq(phys_enc,
  705. INTR_IDX_WRPTR);
  706. sde_encoder_helper_register_irq(phys_enc,
  707. INTR_IDX_AUTOREFRESH_DONE);
  708. }
  709. } else {
  710. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  711. sde_encoder_helper_unregister_irq(phys_enc,
  712. INTR_IDX_WRPTR);
  713. sde_encoder_helper_unregister_irq(phys_enc,
  714. INTR_IDX_AUTOREFRESH_DONE);
  715. }
  716. sde_encoder_phys_cmd_control_vblank_irq(phys_enc, false);
  717. sde_encoder_helper_unregister_irq(phys_enc, INTR_IDX_PINGPONG);
  718. }
  719. }
  720. static int _get_tearcheck_threshold(struct sde_encoder_phys *phys_enc)
  721. {
  722. struct drm_connector *conn = phys_enc->connector;
  723. u32 qsync_mode;
  724. struct drm_display_mode *mode;
  725. u32 threshold_lines = DEFAULT_TEARCHECK_SYNC_THRESH_START;
  726. struct sde_encoder_phys_cmd *cmd_enc =
  727. to_sde_encoder_phys_cmd(phys_enc);
  728. if (!conn || !conn->state)
  729. return 0;
  730. mode = &phys_enc->cached_mode;
  731. qsync_mode = sde_connector_get_qsync_mode(conn);
  732. if (mode && (qsync_mode == SDE_RM_QSYNC_CONTINUOUS_MODE)) {
  733. u32 qsync_min_fps = 0;
  734. u32 default_fps = drm_mode_vrefresh(mode);
  735. u32 yres = mode->vtotal;
  736. u32 slow_time_ns;
  737. u32 default_time_ns;
  738. u32 extra_time_ns;
  739. u32 default_line_time_ns;
  740. if (phys_enc->parent_ops.get_qsync_fps)
  741. phys_enc->parent_ops.get_qsync_fps(
  742. phys_enc->parent, &qsync_min_fps, conn->state);
  743. if (!qsync_min_fps || !default_fps || !yres) {
  744. SDE_ERROR_CMDENC(cmd_enc,
  745. "wrong qsync params %d %d %d\n",
  746. qsync_min_fps, default_fps, yres);
  747. goto exit;
  748. }
  749. if (qsync_min_fps >= default_fps) {
  750. SDE_ERROR_CMDENC(cmd_enc,
  751. "qsync fps:%d must be less than default:%d\n",
  752. qsync_min_fps, default_fps);
  753. goto exit;
  754. }
  755. /* Calculate the number of extra lines*/
  756. slow_time_ns = DIV_ROUND_UP(1000000000, qsync_min_fps);
  757. default_time_ns = DIV_ROUND_UP(1000000000, default_fps);
  758. extra_time_ns = slow_time_ns - default_time_ns;
  759. default_line_time_ns = DIV_ROUND_UP(default_time_ns, yres);
  760. threshold_lines = extra_time_ns / default_line_time_ns;
  761. /* some DDICs express the timeout value in lines/4, round down to compensate */
  762. threshold_lines = round_down(threshold_lines, 4);
  763. /* remove 2 lines to cover for latency */
  764. if (threshold_lines - 2 > DEFAULT_TEARCHECK_SYNC_THRESH_START)
  765. threshold_lines -= 2;
  766. SDE_DEBUG_CMDENC(cmd_enc, "slow:%d default:%d extra:%d(ns)\n",
  767. slow_time_ns, default_time_ns, extra_time_ns);
  768. SDE_DEBUG_CMDENC(cmd_enc, "min_fps:%d fps:%d yres:%d lines:%d\n",
  769. qsync_min_fps, default_fps, yres, threshold_lines);
  770. SDE_EVT32(qsync_mode, qsync_min_fps, extra_time_ns, default_fps,
  771. yres, threshold_lines);
  772. }
  773. exit:
  774. return threshold_lines;
  775. }
  776. static void sde_encoder_phys_cmd_tearcheck_config(
  777. struct sde_encoder_phys *phys_enc)
  778. {
  779. struct sde_encoder_phys_cmd *cmd_enc =
  780. to_sde_encoder_phys_cmd(phys_enc);
  781. struct sde_hw_tear_check tc_cfg = { 0 };
  782. struct drm_display_mode *mode;
  783. bool tc_enable = true;
  784. u32 vsync_hz;
  785. int vrefresh;
  786. struct msm_drm_private *priv;
  787. struct sde_kms *sde_kms;
  788. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf) {
  789. SDE_ERROR("invalid encoder\n");
  790. return;
  791. }
  792. mode = &phys_enc->cached_mode;
  793. SDE_DEBUG_CMDENC(cmd_enc, "pp %d, intf %d\n",
  794. phys_enc->hw_pp->idx - PINGPONG_0,
  795. phys_enc->hw_intf->idx - INTF_0);
  796. if (phys_enc->has_intf_te) {
  797. if (!phys_enc->hw_intf->ops.setup_tearcheck ||
  798. !phys_enc->hw_intf->ops.enable_tearcheck) {
  799. SDE_DEBUG_CMDENC(cmd_enc, "tearcheck not supported\n");
  800. return;
  801. }
  802. } else {
  803. if (!phys_enc->hw_pp->ops.setup_tearcheck ||
  804. !phys_enc->hw_pp->ops.enable_tearcheck) {
  805. SDE_DEBUG_CMDENC(cmd_enc, "tearcheck not supported\n");
  806. return;
  807. }
  808. }
  809. sde_kms = phys_enc->sde_kms;
  810. if (!sde_kms || !sde_kms->dev || !sde_kms->dev->dev_private) {
  811. SDE_ERROR("invalid device\n");
  812. return;
  813. }
  814. priv = sde_kms->dev->dev_private;
  815. vrefresh = drm_mode_vrefresh(mode);
  816. /*
  817. * TE default: dsi byte clock calculated base on 70 fps;
  818. * around 14 ms to complete a kickoff cycle if te disabled;
  819. * vclk_line base on 60 fps; write is faster than read;
  820. * init == start == rdptr;
  821. *
  822. * vsync_count is ratio of MDP VSYNC clock frequency to LCD panel
  823. * frequency divided by the no. of rows (lines) in the LCDpanel.
  824. */
  825. vsync_hz = sde_power_clk_get_rate(&priv->phandle, "vsync_clk");
  826. if (!vsync_hz || !mode->vtotal || !vrefresh) {
  827. SDE_DEBUG_CMDENC(cmd_enc,
  828. "invalid params - vsync_hz %u vtot %u vrefresh %u\n",
  829. vsync_hz, mode->vtotal, vrefresh);
  830. return;
  831. }
  832. tc_cfg.vsync_count = vsync_hz / (mode->vtotal * vrefresh);
  833. /* enable external TE after kickoff to avoid premature autorefresh */
  834. tc_cfg.hw_vsync_mode = 0;
  835. /*
  836. * By setting sync_cfg_height to near max register value, we essentially
  837. * disable sde hw generated TE signal, since hw TE will arrive first.
  838. * Only caveat is if due to error, we hit wrap-around.
  839. */
  840. tc_cfg.sync_cfg_height = 0xFFF0;
  841. tc_cfg.vsync_init_val = mode->vdisplay;
  842. tc_cfg.sync_threshold_start = _get_tearcheck_threshold(phys_enc);
  843. tc_cfg.sync_threshold_continue = DEFAULT_TEARCHECK_SYNC_THRESH_CONTINUE;
  844. tc_cfg.start_pos = mode->vdisplay;
  845. tc_cfg.rd_ptr_irq = mode->vdisplay + 1;
  846. tc_cfg.wr_ptr_irq = 1;
  847. SDE_DEBUG_CMDENC(cmd_enc,
  848. "tc %d intf %d vsync_clk_speed_hz %u vtotal %u vrefresh %u\n",
  849. phys_enc->hw_pp->idx - PINGPONG_0,
  850. phys_enc->hw_intf->idx - INTF_0,
  851. vsync_hz, mode->vtotal, vrefresh);
  852. SDE_DEBUG_CMDENC(cmd_enc,
  853. "tc %d intf %d enable %u start_pos %u rd_ptr_irq %u wr_ptr_irq %u\n",
  854. phys_enc->hw_pp->idx - PINGPONG_0,
  855. phys_enc->hw_intf->idx - INTF_0,
  856. tc_enable, tc_cfg.start_pos, tc_cfg.rd_ptr_irq,
  857. tc_cfg.wr_ptr_irq);
  858. SDE_DEBUG_CMDENC(cmd_enc,
  859. "tc %d intf %d hw_vsync_mode %u vsync_count %u vsync_init_val %u\n",
  860. phys_enc->hw_pp->idx - PINGPONG_0,
  861. phys_enc->hw_intf->idx - INTF_0,
  862. tc_cfg.hw_vsync_mode, tc_cfg.vsync_count,
  863. tc_cfg.vsync_init_val);
  864. SDE_DEBUG_CMDENC(cmd_enc,
  865. "tc %d intf %d cfgheight %u thresh_start %u thresh_cont %u\n",
  866. phys_enc->hw_pp->idx - PINGPONG_0,
  867. phys_enc->hw_intf->idx - INTF_0,
  868. tc_cfg.sync_cfg_height,
  869. tc_cfg.sync_threshold_start, tc_cfg.sync_threshold_continue);
  870. if (phys_enc->has_intf_te) {
  871. phys_enc->hw_intf->ops.setup_tearcheck(phys_enc->hw_intf,
  872. &tc_cfg);
  873. phys_enc->hw_intf->ops.enable_tearcheck(phys_enc->hw_intf,
  874. tc_enable);
  875. } else {
  876. phys_enc->hw_pp->ops.setup_tearcheck(phys_enc->hw_pp, &tc_cfg);
  877. phys_enc->hw_pp->ops.enable_tearcheck(phys_enc->hw_pp,
  878. tc_enable);
  879. }
  880. }
  881. static void _sde_encoder_phys_cmd_pingpong_config(
  882. struct sde_encoder_phys *phys_enc)
  883. {
  884. struct sde_encoder_phys_cmd *cmd_enc =
  885. to_sde_encoder_phys_cmd(phys_enc);
  886. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->hw_pp) {
  887. SDE_ERROR("invalid arg(s), enc %d\n", !phys_enc);
  888. return;
  889. }
  890. SDE_DEBUG_CMDENC(cmd_enc, "pp %d, enabling mode:\n",
  891. phys_enc->hw_pp->idx - PINGPONG_0);
  892. drm_mode_debug_printmodeline(&phys_enc->cached_mode);
  893. if (!_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  894. _sde_encoder_phys_cmd_update_intf_cfg(phys_enc);
  895. sde_encoder_phys_cmd_tearcheck_config(phys_enc);
  896. }
  897. static void sde_encoder_phys_cmd_enable_helper(
  898. struct sde_encoder_phys *phys_enc)
  899. {
  900. struct sde_hw_intf *hw_intf;
  901. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->hw_pp ||
  902. !phys_enc->hw_intf) {
  903. SDE_ERROR("invalid arg(s), encoder %d\n", !phys_enc);
  904. return;
  905. }
  906. sde_encoder_helper_split_config(phys_enc, phys_enc->intf_idx);
  907. _sde_encoder_phys_cmd_pingpong_config(phys_enc);
  908. hw_intf = phys_enc->hw_intf;
  909. if (hw_intf->ops.enable_compressed_input)
  910. hw_intf->ops.enable_compressed_input(phys_enc->hw_intf,
  911. (phys_enc->comp_type !=
  912. MSM_DISPLAY_COMPRESSION_NONE), false);
  913. if (hw_intf->ops.enable_wide_bus)
  914. hw_intf->ops.enable_wide_bus(hw_intf,
  915. sde_encoder_is_widebus_enabled(phys_enc->parent));
  916. /*
  917. * For pp-split, skip setting the flush bit for the slave intf, since
  918. * both intfs use same ctl and HW will only flush the master.
  919. */
  920. if (_sde_encoder_phys_is_ppsplit(phys_enc) &&
  921. !sde_encoder_phys_cmd_is_master(phys_enc))
  922. goto skip_flush;
  923. _sde_encoder_phys_cmd_update_flush_mask(phys_enc);
  924. skip_flush:
  925. return;
  926. }
  927. static void sde_encoder_phys_cmd_enable(struct sde_encoder_phys *phys_enc)
  928. {
  929. struct sde_encoder_phys_cmd *cmd_enc =
  930. to_sde_encoder_phys_cmd(phys_enc);
  931. if (!phys_enc || !phys_enc->hw_pp) {
  932. SDE_ERROR("invalid phys encoder\n");
  933. return;
  934. }
  935. SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", phys_enc->hw_pp->idx - PINGPONG_0);
  936. if (phys_enc->enable_state == SDE_ENC_ENABLED) {
  937. if (!phys_enc->cont_splash_enabled)
  938. SDE_ERROR("already enabled\n");
  939. return;
  940. }
  941. sde_encoder_phys_cmd_enable_helper(phys_enc);
  942. phys_enc->enable_state = SDE_ENC_ENABLED;
  943. }
  944. static bool sde_encoder_phys_cmd_is_autorefresh_enabled(
  945. struct sde_encoder_phys *phys_enc)
  946. {
  947. struct sde_hw_pingpong *hw_pp;
  948. struct sde_hw_intf *hw_intf;
  949. struct sde_hw_autorefresh cfg;
  950. int ret;
  951. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  952. return false;
  953. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  954. return false;
  955. if (phys_enc->has_intf_te) {
  956. hw_intf = phys_enc->hw_intf;
  957. if (!hw_intf->ops.get_autorefresh)
  958. return false;
  959. ret = hw_intf->ops.get_autorefresh(hw_intf, &cfg);
  960. } else {
  961. hw_pp = phys_enc->hw_pp;
  962. if (!hw_pp->ops.get_autorefresh)
  963. return false;
  964. ret = hw_pp->ops.get_autorefresh(hw_pp, &cfg);
  965. }
  966. return ret ? false : cfg.enable;
  967. }
  968. static void sde_encoder_phys_cmd_connect_te(
  969. struct sde_encoder_phys *phys_enc, bool enable)
  970. {
  971. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  972. return;
  973. if (phys_enc->has_intf_te &&
  974. phys_enc->hw_intf->ops.connect_external_te)
  975. phys_enc->hw_intf->ops.connect_external_te(phys_enc->hw_intf,
  976. enable);
  977. else if (phys_enc->hw_pp->ops.connect_external_te)
  978. phys_enc->hw_pp->ops.connect_external_te(phys_enc->hw_pp,
  979. enable);
  980. else
  981. return;
  982. SDE_EVT32(DRMID(phys_enc->parent), enable);
  983. }
  984. static int sde_encoder_phys_cmd_te_get_line_count(
  985. struct sde_encoder_phys *phys_enc)
  986. {
  987. struct sde_hw_pingpong *hw_pp;
  988. struct sde_hw_intf *hw_intf;
  989. u32 line_count;
  990. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  991. return -EINVAL;
  992. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  993. return -EINVAL;
  994. if (phys_enc->has_intf_te) {
  995. hw_intf = phys_enc->hw_intf;
  996. if (!hw_intf->ops.get_line_count)
  997. return -EINVAL;
  998. line_count = hw_intf->ops.get_line_count(hw_intf);
  999. } else {
  1000. hw_pp = phys_enc->hw_pp;
  1001. if (!hw_pp->ops.get_line_count)
  1002. return -EINVAL;
  1003. line_count = hw_pp->ops.get_line_count(hw_pp);
  1004. }
  1005. return line_count;
  1006. }
  1007. static void sde_encoder_phys_cmd_disable(struct sde_encoder_phys *phys_enc)
  1008. {
  1009. struct sde_encoder_phys_cmd *cmd_enc =
  1010. to_sde_encoder_phys_cmd(phys_enc);
  1011. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf) {
  1012. SDE_ERROR("invalid encoder\n");
  1013. return;
  1014. }
  1015. SDE_DEBUG_CMDENC(cmd_enc, "pp %d intf %d state %d\n",
  1016. phys_enc->hw_pp->idx - PINGPONG_0,
  1017. phys_enc->hw_intf->idx - INTF_0,
  1018. phys_enc->enable_state);
  1019. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  1020. phys_enc->hw_intf->idx - INTF_0,
  1021. phys_enc->enable_state);
  1022. if (phys_enc->enable_state == SDE_ENC_DISABLED) {
  1023. SDE_ERROR_CMDENC(cmd_enc, "already disabled\n");
  1024. return;
  1025. }
  1026. if (!sde_in_trusted_vm(phys_enc->sde_kms)) {
  1027. if (phys_enc->has_intf_te &&
  1028. phys_enc->hw_intf->ops.enable_tearcheck)
  1029. phys_enc->hw_intf->ops.enable_tearcheck(
  1030. phys_enc->hw_intf,
  1031. false);
  1032. else if (phys_enc->hw_pp->ops.enable_tearcheck)
  1033. phys_enc->hw_pp->ops.enable_tearcheck(phys_enc->hw_pp,
  1034. false);
  1035. if (sde_encoder_phys_cmd_is_master(phys_enc))
  1036. sde_encoder_helper_phys_disable(phys_enc, NULL);
  1037. if (phys_enc->hw_intf->ops.reset_counter)
  1038. phys_enc->hw_intf->ops.reset_counter(phys_enc->hw_intf);
  1039. }
  1040. memset(&cmd_enc->autorefresh.cfg, 0, sizeof(struct sde_hw_autorefresh));
  1041. phys_enc->enable_state = SDE_ENC_DISABLED;
  1042. }
  1043. static void sde_encoder_phys_cmd_destroy(struct sde_encoder_phys *phys_enc)
  1044. {
  1045. struct sde_encoder_phys_cmd *cmd_enc =
  1046. to_sde_encoder_phys_cmd(phys_enc);
  1047. if (!phys_enc) {
  1048. SDE_ERROR("invalid encoder\n");
  1049. return;
  1050. }
  1051. kfree(cmd_enc);
  1052. }
  1053. static void sde_encoder_phys_cmd_get_hw_resources(
  1054. struct sde_encoder_phys *phys_enc,
  1055. struct sde_encoder_hw_resources *hw_res,
  1056. struct drm_connector_state *conn_state)
  1057. {
  1058. struct sde_encoder_phys_cmd *cmd_enc =
  1059. to_sde_encoder_phys_cmd(phys_enc);
  1060. if (!phys_enc) {
  1061. SDE_ERROR("invalid encoder\n");
  1062. return;
  1063. }
  1064. if ((phys_enc->intf_idx - INTF_0) >= INTF_MAX) {
  1065. SDE_ERROR("invalid intf idx:%d\n", phys_enc->intf_idx);
  1066. return;
  1067. }
  1068. SDE_DEBUG_CMDENC(cmd_enc, "\n");
  1069. hw_res->intfs[phys_enc->intf_idx - INTF_0] = INTF_MODE_CMD;
  1070. }
  1071. static int sde_encoder_phys_cmd_prepare_for_kickoff(
  1072. struct sde_encoder_phys *phys_enc,
  1073. struct sde_encoder_kickoff_params *params)
  1074. {
  1075. struct sde_hw_tear_check tc_cfg = {0};
  1076. struct sde_encoder_phys_cmd *cmd_enc =
  1077. to_sde_encoder_phys_cmd(phys_enc);
  1078. int ret = 0;
  1079. bool recovery_events;
  1080. if (!phys_enc || !phys_enc->hw_pp) {
  1081. SDE_ERROR("invalid encoder\n");
  1082. return -EINVAL;
  1083. }
  1084. SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", phys_enc->hw_pp->idx - PINGPONG_0);
  1085. phys_enc->frame_trigger_mode = params->frame_trigger_mode;
  1086. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  1087. atomic_read(&phys_enc->pending_kickoff_cnt),
  1088. atomic_read(&cmd_enc->autorefresh.kickoff_cnt),
  1089. phys_enc->frame_trigger_mode);
  1090. if (phys_enc->frame_trigger_mode == FRAME_DONE_WAIT_DEFAULT) {
  1091. /*
  1092. * Mark kickoff request as outstanding. If there are more
  1093. * than one outstanding frame, then we have to wait for the
  1094. * previous frame to complete
  1095. */
  1096. ret = _sde_encoder_phys_cmd_wait_for_idle(phys_enc);
  1097. if (ret) {
  1098. atomic_set(&phys_enc->pending_kickoff_cnt, 0);
  1099. SDE_EVT32(DRMID(phys_enc->parent),
  1100. phys_enc->hw_pp->idx - PINGPONG_0);
  1101. SDE_ERROR("failed wait_for_idle: %d\n", ret);
  1102. }
  1103. }
  1104. if (phys_enc->recovered) {
  1105. recovery_events = sde_encoder_recovery_events_enabled(
  1106. phys_enc->parent);
  1107. if (cmd_enc->pp_timeout_report_cnt && recovery_events)
  1108. sde_connector_event_notify(phys_enc->connector,
  1109. DRM_EVENT_SDE_HW_RECOVERY,
  1110. sizeof(uint8_t),
  1111. SDE_RECOVERY_SUCCESS);
  1112. cmd_enc->pp_timeout_report_cnt = 0;
  1113. phys_enc->recovered = false;
  1114. }
  1115. if (sde_connector_is_qsync_updated(phys_enc->connector)) {
  1116. tc_cfg.sync_threshold_start = _get_tearcheck_threshold(
  1117. phys_enc);
  1118. if (phys_enc->has_intf_te &&
  1119. phys_enc->hw_intf->ops.update_tearcheck)
  1120. phys_enc->hw_intf->ops.update_tearcheck(
  1121. phys_enc->hw_intf, &tc_cfg);
  1122. else if (phys_enc->hw_pp->ops.update_tearcheck)
  1123. phys_enc->hw_pp->ops.update_tearcheck(
  1124. phys_enc->hw_pp, &tc_cfg);
  1125. SDE_EVT32(DRMID(phys_enc->parent), tc_cfg.sync_threshold_start);
  1126. }
  1127. SDE_DEBUG_CMDENC(cmd_enc, "pp:%d pending_cnt %d\n",
  1128. phys_enc->hw_pp->idx - PINGPONG_0,
  1129. atomic_read(&phys_enc->pending_kickoff_cnt));
  1130. return ret;
  1131. }
  1132. static bool _sde_encoder_phys_cmd_needs_vsync_change(
  1133. struct sde_encoder_phys *phys_enc, ktime_t profile_timestamp)
  1134. {
  1135. struct sde_encoder_phys_cmd *cmd_enc;
  1136. struct sde_encoder_phys_cmd_te_timestamp *cur;
  1137. struct sde_encoder_phys_cmd_te_timestamp *prev = NULL;
  1138. ktime_t time_diff;
  1139. u64 l_bound = 0, u_bound = 0;
  1140. bool ret = false;
  1141. unsigned long lock_flags;
  1142. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1143. sde_encoder_helper_get_jitter_bounds_ns(phys_enc->parent,
  1144. &l_bound, &u_bound);
  1145. if (!l_bound || !u_bound) {
  1146. SDE_ERROR_CMDENC(cmd_enc, "invalid vsync jitter bounds\n");
  1147. return false;
  1148. }
  1149. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  1150. list_for_each_entry_reverse(cur, &cmd_enc->te_timestamp_list, list) {
  1151. if (prev && ktime_after(cur->timestamp, profile_timestamp)) {
  1152. time_diff = ktime_sub(prev->timestamp, cur->timestamp);
  1153. if ((time_diff < l_bound) || (time_diff > u_bound)) {
  1154. ret = true;
  1155. break;
  1156. }
  1157. }
  1158. prev = cur;
  1159. }
  1160. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  1161. if (ret) {
  1162. SDE_DEBUG_CMDENC(cmd_enc,
  1163. "time_diff:%llu, prev:%llu, cur:%llu, jitter:%llu/%llu\n",
  1164. time_diff, prev->timestamp, cur->timestamp,
  1165. l_bound, u_bound);
  1166. time_diff = div_s64(time_diff, 1000);
  1167. SDE_EVT32(DRMID(phys_enc->parent),
  1168. (u32) (do_div(l_bound, 1000)),
  1169. (u32) (do_div(u_bound, 1000)),
  1170. (u32) (time_diff), SDE_EVTLOG_ERROR);
  1171. }
  1172. return ret;
  1173. }
  1174. static int _sde_encoder_phys_cmd_wait_for_wr_ptr(
  1175. struct sde_encoder_phys *phys_enc)
  1176. {
  1177. struct sde_encoder_phys_cmd *cmd_enc =
  1178. to_sde_encoder_phys_cmd(phys_enc);
  1179. struct sde_encoder_wait_info wait_info = {0};
  1180. struct sde_connector *c_conn;
  1181. bool frame_pending = true;
  1182. struct sde_hw_ctl *ctl;
  1183. unsigned long lock_flags;
  1184. int ret, timeout_ms;
  1185. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->connector) {
  1186. SDE_ERROR("invalid argument(s)\n");
  1187. return -EINVAL;
  1188. }
  1189. ctl = phys_enc->hw_ctl;
  1190. c_conn = to_sde_connector(phys_enc->connector);
  1191. timeout_ms = phys_enc->kickoff_timeout_ms;
  1192. if (c_conn->lp_mode == SDE_MODE_DPMS_LP1 ||
  1193. c_conn->lp_mode == SDE_MODE_DPMS_LP2)
  1194. timeout_ms = timeout_ms * 2;
  1195. wait_info.wq = &phys_enc->pending_kickoff_wq;
  1196. wait_info.atomic_cnt = &phys_enc->pending_retire_fence_cnt;
  1197. wait_info.timeout_ms = timeout_ms;
  1198. /* slave encoder doesn't enable for ppsplit */
  1199. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  1200. return 0;
  1201. ret = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_WRPTR,
  1202. &wait_info);
  1203. if (ret == -ETIMEDOUT) {
  1204. struct sde_hw_ctl *ctl = phys_enc->hw_ctl;
  1205. if (ctl && ctl->ops.get_start_state)
  1206. frame_pending = ctl->ops.get_start_state(ctl);
  1207. ret = (frame_pending || sde_connector_esd_status(phys_enc->connector)) ? ret : 0;
  1208. /*
  1209. * There can be few cases of ESD where CTL_START is cleared but
  1210. * wr_ptr irq doesn't come. Signaling retire fence in these
  1211. * cases to avoid freeze and dangling pending_retire_fence_cnt
  1212. */
  1213. if (!ret) {
  1214. SDE_EVT32(DRMID(phys_enc->parent),
  1215. SDE_EVTLOG_FUNC_CASE1);
  1216. if (sde_encoder_phys_cmd_is_master(phys_enc) &&
  1217. atomic_add_unless(
  1218. &phys_enc->pending_retire_fence_cnt, -1, 0)) {
  1219. spin_lock_irqsave(phys_enc->enc_spinlock,
  1220. lock_flags);
  1221. phys_enc->parent_ops.handle_frame_done(
  1222. phys_enc->parent, phys_enc,
  1223. SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE);
  1224. spin_unlock_irqrestore(phys_enc->enc_spinlock,
  1225. lock_flags);
  1226. }
  1227. }
  1228. }
  1229. cmd_enc->wr_ptr_wait_success = (ret == 0) ? true : false;
  1230. return ret;
  1231. }
  1232. static int sde_encoder_phys_cmd_wait_for_tx_complete(
  1233. struct sde_encoder_phys *phys_enc)
  1234. {
  1235. int rc;
  1236. struct sde_encoder_phys_cmd *cmd_enc;
  1237. if (!phys_enc)
  1238. return -EINVAL;
  1239. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1240. if (!atomic_read(&phys_enc->pending_kickoff_cnt)) {
  1241. SDE_EVT32(DRMID(phys_enc->parent),
  1242. phys_enc->intf_idx - INTF_0,
  1243. phys_enc->enable_state);
  1244. return 0;
  1245. }
  1246. rc = _sde_encoder_phys_cmd_wait_for_idle(phys_enc);
  1247. if (rc) {
  1248. SDE_EVT32(DRMID(phys_enc->parent),
  1249. phys_enc->intf_idx - INTF_0);
  1250. SDE_ERROR("failed wait_for_idle: %d\n", rc);
  1251. }
  1252. return rc;
  1253. }
  1254. static int _sde_encoder_phys_cmd_handle_wr_ptr_timeout(
  1255. struct sde_encoder_phys *phys_enc,
  1256. ktime_t profile_timestamp)
  1257. {
  1258. struct sde_encoder_phys_cmd *cmd_enc =
  1259. to_sde_encoder_phys_cmd(phys_enc);
  1260. bool switch_te;
  1261. int ret = -ETIMEDOUT;
  1262. unsigned long lock_flags;
  1263. switch_te = _sde_encoder_phys_cmd_needs_vsync_change(
  1264. phys_enc, profile_timestamp);
  1265. SDE_EVT32(DRMID(phys_enc->parent), switch_te, SDE_EVTLOG_FUNC_ENTRY);
  1266. if (sde_connector_panel_dead(phys_enc->connector)) {
  1267. ret = _sde_encoder_phys_cmd_wait_for_wr_ptr(phys_enc);
  1268. } else if (switch_te) {
  1269. SDE_DEBUG_CMDENC(cmd_enc,
  1270. "wr_ptr_irq wait failed, retry with WD TE\n");
  1271. /* switch to watchdog TE and wait again */
  1272. sde_encoder_helper_switch_vsync(phys_enc->parent, true);
  1273. ret = _sde_encoder_phys_cmd_wait_for_wr_ptr(phys_enc);
  1274. /* switch back to default TE */
  1275. sde_encoder_helper_switch_vsync(phys_enc->parent, false);
  1276. }
  1277. /*
  1278. * Signaling the retire fence at wr_ptr timeout
  1279. * to allow the next commit and avoid device freeze.
  1280. */
  1281. if (ret == -ETIMEDOUT) {
  1282. SDE_ERROR_CMDENC(cmd_enc,
  1283. "wr_ptr_irq wait failed, switch_te:%d\n", switch_te);
  1284. SDE_EVT32(DRMID(phys_enc->parent), switch_te, SDE_EVTLOG_ERROR);
  1285. if (sde_encoder_phys_cmd_is_master(phys_enc) &&
  1286. atomic_add_unless(
  1287. &phys_enc->pending_retire_fence_cnt, -1, 0)) {
  1288. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  1289. phys_enc->parent_ops.handle_frame_done(
  1290. phys_enc->parent, phys_enc,
  1291. SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE);
  1292. spin_unlock_irqrestore(phys_enc->enc_spinlock,
  1293. lock_flags);
  1294. }
  1295. }
  1296. cmd_enc->wr_ptr_wait_success = (ret == 0) ? true : false;
  1297. return ret;
  1298. }
  1299. static int sde_encoder_phys_cmd_wait_for_commit_done(
  1300. struct sde_encoder_phys *phys_enc)
  1301. {
  1302. int rc = 0, i, pending_cnt;
  1303. struct sde_encoder_phys_cmd *cmd_enc;
  1304. ktime_t profile_timestamp = ktime_get();
  1305. u32 scheduler_status = INVALID_CTL_STATUS;
  1306. struct sde_hw_ctl *ctl;
  1307. if (!phys_enc)
  1308. return -EINVAL;
  1309. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1310. /* only required for master controller */
  1311. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  1312. rc = _sde_encoder_phys_cmd_wait_for_wr_ptr(phys_enc);
  1313. if (rc == -ETIMEDOUT) {
  1314. /*
  1315. * Profile all the TE received after profile_timestamp
  1316. * and if the jitter is more, switch to watchdog TE
  1317. * and wait for wr_ptr again. Finally move back to
  1318. * default TE.
  1319. */
  1320. rc = _sde_encoder_phys_cmd_handle_wr_ptr_timeout(
  1321. phys_enc, profile_timestamp);
  1322. if (rc == -ETIMEDOUT)
  1323. goto wait_for_idle;
  1324. }
  1325. if (cmd_enc->autorefresh.cfg.enable)
  1326. rc = _sde_encoder_phys_cmd_wait_for_autorefresh_done(
  1327. phys_enc);
  1328. ctl = phys_enc->hw_ctl;
  1329. if (ctl && ctl->ops.get_scheduler_status)
  1330. scheduler_status = ctl->ops.get_scheduler_status(ctl);
  1331. }
  1332. /* wait for posted start or serialize trigger */
  1333. pending_cnt = atomic_read(&phys_enc->pending_kickoff_cnt);
  1334. if ((pending_cnt > 1) ||
  1335. (pending_cnt && (scheduler_status & BIT(0))) ||
  1336. (!rc && phys_enc->frame_trigger_mode == FRAME_DONE_WAIT_SERIALIZE))
  1337. goto wait_for_idle;
  1338. return rc;
  1339. wait_for_idle:
  1340. pending_cnt = atomic_read(&phys_enc->pending_kickoff_cnt);
  1341. for (i = 0; i < pending_cnt; i++)
  1342. rc |= sde_encoder_wait_for_event(phys_enc->parent,
  1343. MSM_ENC_TX_COMPLETE);
  1344. if (rc) {
  1345. SDE_EVT32(DRMID(phys_enc->parent),
  1346. phys_enc->hw_pp->idx - PINGPONG_0,
  1347. phys_enc->frame_trigger_mode,
  1348. atomic_read(&phys_enc->pending_kickoff_cnt),
  1349. phys_enc->enable_state,
  1350. cmd_enc->wr_ptr_wait_success, scheduler_status, rc);
  1351. SDE_ERROR("pp:%d failed wait_for_idle: %d\n",
  1352. phys_enc->hw_pp->idx - PINGPONG_0, rc);
  1353. if (phys_enc->enable_state == SDE_ENC_ERR_NEEDS_HW_RESET)
  1354. sde_encoder_needs_hw_reset(phys_enc->parent);
  1355. }
  1356. return rc;
  1357. }
  1358. static int sde_encoder_phys_cmd_wait_for_vblank(
  1359. struct sde_encoder_phys *phys_enc)
  1360. {
  1361. int rc = 0;
  1362. struct sde_encoder_phys_cmd *cmd_enc;
  1363. struct sde_encoder_wait_info wait_info = {0};
  1364. if (!phys_enc)
  1365. return -EINVAL;
  1366. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1367. /* only required for master controller */
  1368. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  1369. return rc;
  1370. wait_info.wq = &cmd_enc->pending_vblank_wq;
  1371. wait_info.atomic_cnt = &cmd_enc->pending_vblank_cnt;
  1372. wait_info.timeout_ms = _sde_encoder_phys_cmd_get_idle_timeout(phys_enc);
  1373. atomic_inc(&cmd_enc->pending_vblank_cnt);
  1374. rc = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_RDPTR,
  1375. &wait_info);
  1376. return rc;
  1377. }
  1378. static void sde_encoder_phys_cmd_update_split_role(
  1379. struct sde_encoder_phys *phys_enc,
  1380. enum sde_enc_split_role role)
  1381. {
  1382. struct sde_encoder_phys_cmd *cmd_enc;
  1383. enum sde_enc_split_role old_role;
  1384. bool is_ppsplit;
  1385. if (!phys_enc)
  1386. return;
  1387. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1388. old_role = phys_enc->split_role;
  1389. is_ppsplit = _sde_encoder_phys_is_ppsplit(phys_enc);
  1390. phys_enc->split_role = role;
  1391. SDE_DEBUG_CMDENC(cmd_enc, "old role %d new role %d\n",
  1392. old_role, role);
  1393. /*
  1394. * ppsplit solo needs to reprogram because intf may have swapped without
  1395. * role changing on left-only, right-only back-to-back commits
  1396. */
  1397. if (!(is_ppsplit && role == ENC_ROLE_SOLO) &&
  1398. (role == old_role || role == ENC_ROLE_SKIP))
  1399. return;
  1400. sde_encoder_helper_split_config(phys_enc, phys_enc->intf_idx);
  1401. _sde_encoder_phys_cmd_pingpong_config(phys_enc);
  1402. _sde_encoder_phys_cmd_update_flush_mask(phys_enc);
  1403. }
  1404. static void _sde_encoder_autorefresh_disable_seq1(
  1405. struct sde_encoder_phys *phys_enc)
  1406. {
  1407. int trial = 0;
  1408. u32 timeout_ms = phys_enc->kickoff_timeout_ms;
  1409. struct sde_encoder_phys_cmd *cmd_enc =
  1410. to_sde_encoder_phys_cmd(phys_enc);
  1411. /*
  1412. * If autorefresh is enabled, disable it and make sure it is safe to
  1413. * proceed with current frame commit/push. Sequence fallowed is,
  1414. * 1. Disable TE - caller will take care of it
  1415. * 2. Disable autorefresh config
  1416. * 4. Poll for frame transfer ongoing to be false
  1417. * 5. Enable TE back - caller will take care of it
  1418. */
  1419. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, 0);
  1420. do {
  1421. udelay(AUTOREFRESH_SEQ1_POLL_TIME);
  1422. if ((trial * AUTOREFRESH_SEQ1_POLL_TIME)
  1423. > (timeout_ms * USEC_PER_MSEC)) {
  1424. SDE_ERROR_CMDENC(cmd_enc,
  1425. "disable autorefresh failed\n");
  1426. phys_enc->enable_state = SDE_ENC_ERR_NEEDS_HW_RESET;
  1427. break;
  1428. }
  1429. trial++;
  1430. } while (_sde_encoder_phys_cmd_is_ongoing_pptx(phys_enc));
  1431. }
  1432. static void _sde_encoder_autorefresh_disable_seq2(
  1433. struct sde_encoder_phys *phys_enc)
  1434. {
  1435. int trial = 0;
  1436. struct sde_hw_mdp *hw_mdp = phys_enc->hw_mdptop;
  1437. u32 autorefresh_status = 0;
  1438. struct sde_encoder_phys_cmd *cmd_enc =
  1439. to_sde_encoder_phys_cmd(phys_enc);
  1440. struct intf_tear_status tear_status;
  1441. struct sde_hw_intf *hw_intf = phys_enc->hw_intf;
  1442. if (!hw_mdp->ops.get_autorefresh_status ||
  1443. !hw_intf->ops.check_and_reset_tearcheck) {
  1444. SDE_DEBUG_CMDENC(cmd_enc,
  1445. "autofresh disable seq2 not supported\n");
  1446. return;
  1447. }
  1448. /*
  1449. * If autorefresh is still enabled after sequence-1, proceed with
  1450. * below sequence-2.
  1451. * 1. Disable autorefresh config
  1452. * 2. Run in loop:
  1453. * 2.1 Poll for autorefresh to be disabled
  1454. * 2.2 Log read and write count status
  1455. * 2.3 Replace te write count with start_pos to meet trigger window
  1456. */
  1457. autorefresh_status = hw_mdp->ops.get_autorefresh_status(hw_mdp,
  1458. phys_enc->intf_idx);
  1459. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1460. autorefresh_status, SDE_EVTLOG_FUNC_CASE1);
  1461. if (!(autorefresh_status & BIT(7))) {
  1462. usleep_range(AUTOREFRESH_SEQ2_POLL_TIME,
  1463. AUTOREFRESH_SEQ2_POLL_TIME + 1);
  1464. autorefresh_status = hw_mdp->ops.get_autorefresh_status(hw_mdp,
  1465. phys_enc->intf_idx);
  1466. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1467. autorefresh_status, SDE_EVTLOG_FUNC_CASE2);
  1468. }
  1469. while (autorefresh_status & BIT(7)) {
  1470. if (!trial) {
  1471. pr_err("enc:%d autofresh status:0x%x intf:%d\n", DRMID(phys_enc->parent),
  1472. autorefresh_status, phys_enc->intf_idx - INTF_0);
  1473. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, 0);
  1474. }
  1475. usleep_range(AUTOREFRESH_SEQ2_POLL_TIME,
  1476. AUTOREFRESH_SEQ2_POLL_TIME + 1);
  1477. if ((trial * AUTOREFRESH_SEQ2_POLL_TIME)
  1478. > AUTOREFRESH_SEQ2_POLL_TIMEOUT) {
  1479. SDE_ERROR_CMDENC(cmd_enc,
  1480. "disable autorefresh failed\n");
  1481. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL, "panic");
  1482. break;
  1483. }
  1484. trial++;
  1485. autorefresh_status = hw_mdp->ops.get_autorefresh_status(hw_mdp,
  1486. phys_enc->intf_idx);
  1487. hw_intf->ops.check_and_reset_tearcheck(hw_intf, &tear_status);
  1488. pr_err("enc:%d autofresh status:0x%x intf:%d tear_read:0x%x tear_write:0x%x\n",
  1489. DRMID(phys_enc->parent), autorefresh_status, phys_enc->intf_idx - INTF_0,
  1490. tear_status.read_count, tear_status.write_count);
  1491. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1492. autorefresh_status, tear_status.read_count,
  1493. tear_status.write_count);
  1494. }
  1495. }
  1496. static void sde_encoder_phys_cmd_prepare_commit(
  1497. struct sde_encoder_phys *phys_enc)
  1498. {
  1499. struct sde_encoder_phys_cmd *cmd_enc =
  1500. to_sde_encoder_phys_cmd(phys_enc);
  1501. if (!phys_enc)
  1502. return;
  1503. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  1504. return;
  1505. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1506. cmd_enc->autorefresh.cfg.enable);
  1507. if (!sde_encoder_phys_cmd_is_autorefresh_enabled(phys_enc))
  1508. return;
  1509. sde_encoder_phys_cmd_connect_te(phys_enc, false);
  1510. _sde_encoder_autorefresh_disable_seq1(phys_enc);
  1511. _sde_encoder_autorefresh_disable_seq2(phys_enc);
  1512. sde_encoder_phys_cmd_connect_te(phys_enc, true);
  1513. SDE_DEBUG_CMDENC(cmd_enc, "autorefresh disabled successfully\n");
  1514. }
  1515. static void sde_encoder_phys_cmd_trigger_start(
  1516. struct sde_encoder_phys *phys_enc)
  1517. {
  1518. struct sde_encoder_phys_cmd *cmd_enc =
  1519. to_sde_encoder_phys_cmd(phys_enc);
  1520. u32 frame_cnt;
  1521. if (!phys_enc)
  1522. return;
  1523. /* we don't issue CTL_START when using autorefresh */
  1524. frame_cnt = _sde_encoder_phys_cmd_get_autorefresh_property(phys_enc);
  1525. if (frame_cnt) {
  1526. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, frame_cnt);
  1527. atomic_inc(&cmd_enc->autorefresh.kickoff_cnt);
  1528. } else {
  1529. sde_encoder_helper_trigger_start(phys_enc);
  1530. }
  1531. /* wr_ptr_wait_success is set true when wr_ptr arrives */
  1532. cmd_enc->wr_ptr_wait_success = false;
  1533. }
  1534. static void sde_encoder_phys_cmd_setup_vsync_source(struct sde_encoder_phys *phys_enc,
  1535. u32 vsync_source, struct msm_display_info *disp_info)
  1536. {
  1537. struct sde_encoder_virt *sde_enc;
  1538. struct sde_connector *sde_conn;
  1539. if (!phys_enc || !phys_enc->hw_intf)
  1540. return;
  1541. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  1542. if (!sde_enc)
  1543. return;
  1544. sde_conn = to_sde_connector(phys_enc->connector);
  1545. if ((disp_info->is_te_using_watchdog_timer || sde_conn->panel_dead) &&
  1546. phys_enc->hw_intf->ops.setup_vsync_source) {
  1547. vsync_source = SDE_VSYNC_SOURCE_WD_TIMER_0;
  1548. phys_enc->hw_intf->ops.setup_vsync_source(phys_enc->hw_intf,
  1549. sde_enc->mode_info.frame_rate);
  1550. } else {
  1551. sde_encoder_helper_vsync_config(phys_enc, vsync_source);
  1552. }
  1553. if (phys_enc->has_intf_te && phys_enc->hw_intf->ops.vsync_sel)
  1554. phys_enc->hw_intf->ops.vsync_sel(phys_enc->hw_intf,
  1555. vsync_source);
  1556. }
  1557. void sde_encoder_phys_cmd_add_enc_to_minidump(struct sde_encoder_phys *phys_enc)
  1558. {
  1559. struct sde_encoder_phys_cmd *cmd_enc;
  1560. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1561. sde_mini_dump_add_va_region("sde_enc_phys_cmd", sizeof(*cmd_enc), cmd_enc);
  1562. }
  1563. static void sde_encoder_phys_cmd_init_ops(struct sde_encoder_phys_ops *ops)
  1564. {
  1565. ops->prepare_commit = sde_encoder_phys_cmd_prepare_commit;
  1566. ops->is_master = sde_encoder_phys_cmd_is_master;
  1567. ops->mode_set = sde_encoder_phys_cmd_mode_set;
  1568. ops->cont_splash_mode_set = sde_encoder_phys_cmd_cont_splash_mode_set;
  1569. ops->mode_fixup = sde_encoder_phys_cmd_mode_fixup;
  1570. ops->enable = sde_encoder_phys_cmd_enable;
  1571. ops->disable = sde_encoder_phys_cmd_disable;
  1572. ops->destroy = sde_encoder_phys_cmd_destroy;
  1573. ops->get_hw_resources = sde_encoder_phys_cmd_get_hw_resources;
  1574. ops->control_vblank_irq = sde_encoder_phys_cmd_control_vblank_irq;
  1575. ops->wait_for_commit_done = sde_encoder_phys_cmd_wait_for_commit_done;
  1576. ops->prepare_for_kickoff = sde_encoder_phys_cmd_prepare_for_kickoff;
  1577. ops->wait_for_tx_complete = sde_encoder_phys_cmd_wait_for_tx_complete;
  1578. ops->wait_for_vblank = sde_encoder_phys_cmd_wait_for_vblank;
  1579. ops->trigger_flush = sde_encoder_helper_trigger_flush;
  1580. ops->trigger_start = sde_encoder_phys_cmd_trigger_start;
  1581. ops->needs_single_flush = sde_encoder_phys_needs_single_flush;
  1582. ops->hw_reset = sde_encoder_helper_hw_reset;
  1583. ops->irq_control = sde_encoder_phys_cmd_irq_control;
  1584. ops->update_split_role = sde_encoder_phys_cmd_update_split_role;
  1585. ops->restore = sde_encoder_phys_cmd_enable_helper;
  1586. ops->control_te = sde_encoder_phys_cmd_connect_te;
  1587. ops->is_autorefresh_enabled =
  1588. sde_encoder_phys_cmd_is_autorefresh_enabled;
  1589. ops->get_line_count = sde_encoder_phys_cmd_te_get_line_count;
  1590. ops->wait_for_active = NULL;
  1591. ops->setup_vsync_source = sde_encoder_phys_cmd_setup_vsync_source;
  1592. ops->setup_misr = sde_encoder_helper_setup_misr;
  1593. ops->collect_misr = sde_encoder_helper_collect_misr;
  1594. ops->add_to_minidump = sde_encoder_phys_cmd_add_enc_to_minidump;
  1595. }
  1596. static inline bool sde_encoder_phys_cmd_intf_te_supported(
  1597. const struct sde_mdss_cfg *sde_cfg, enum sde_intf idx)
  1598. {
  1599. if (sde_cfg && ((idx - INTF_0) < sde_cfg->intf_count))
  1600. return test_bit(SDE_INTF_TE,
  1601. &(sde_cfg->intf[idx - INTF_0].features));
  1602. return false;
  1603. }
  1604. struct sde_encoder_phys *sde_encoder_phys_cmd_init(
  1605. struct sde_enc_phys_init_params *p)
  1606. {
  1607. struct sde_encoder_phys *phys_enc = NULL;
  1608. struct sde_encoder_phys_cmd *cmd_enc = NULL;
  1609. struct sde_hw_mdp *hw_mdp;
  1610. struct sde_encoder_irq *irq;
  1611. int i, ret = 0;
  1612. SDE_DEBUG("intf %d\n", p->intf_idx - INTF_0);
  1613. cmd_enc = kzalloc(sizeof(*cmd_enc), GFP_KERNEL);
  1614. if (!cmd_enc) {
  1615. ret = -ENOMEM;
  1616. SDE_ERROR("failed to allocate\n");
  1617. goto fail;
  1618. }
  1619. phys_enc = &cmd_enc->base;
  1620. hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm);
  1621. if (IS_ERR_OR_NULL(hw_mdp)) {
  1622. ret = PTR_ERR(hw_mdp);
  1623. SDE_ERROR("failed to get mdptop\n");
  1624. goto fail_mdp_init;
  1625. }
  1626. phys_enc->hw_mdptop = hw_mdp;
  1627. phys_enc->intf_idx = p->intf_idx;
  1628. phys_enc->parent = p->parent;
  1629. phys_enc->parent_ops = p->parent_ops;
  1630. phys_enc->sde_kms = p->sde_kms;
  1631. phys_enc->split_role = p->split_role;
  1632. phys_enc->intf_mode = INTF_MODE_CMD;
  1633. phys_enc->enc_spinlock = p->enc_spinlock;
  1634. phys_enc->vblank_ctl_lock = p->vblank_ctl_lock;
  1635. cmd_enc->stream_sel = 0;
  1636. phys_enc->enable_state = SDE_ENC_DISABLED;
  1637. phys_enc->kickoff_timeout_ms = DEFAULT_KICKOFF_TIMEOUT_MS;
  1638. sde_encoder_phys_cmd_init_ops(&phys_enc->ops);
  1639. phys_enc->comp_type = p->comp_type;
  1640. phys_enc->has_intf_te = sde_encoder_phys_cmd_intf_te_supported(
  1641. phys_enc->sde_kms->catalog, phys_enc->intf_idx);
  1642. for (i = 0; i < INTR_IDX_MAX; i++) {
  1643. irq = &phys_enc->irq[i];
  1644. INIT_LIST_HEAD(&irq->cb.list);
  1645. irq->irq_idx = -EINVAL;
  1646. irq->hw_idx = -EINVAL;
  1647. irq->cb.arg = phys_enc;
  1648. }
  1649. irq = &phys_enc->irq[INTR_IDX_CTL_START];
  1650. irq->name = "ctl_start";
  1651. irq->intr_type = SDE_IRQ_TYPE_CTL_START;
  1652. irq->intr_idx = INTR_IDX_CTL_START;
  1653. irq->cb.func = NULL;
  1654. irq = &phys_enc->irq[INTR_IDX_PINGPONG];
  1655. irq->name = "pp_done";
  1656. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_COMP;
  1657. irq->intr_idx = INTR_IDX_PINGPONG;
  1658. irq->cb.func = sde_encoder_phys_cmd_pp_tx_done_irq;
  1659. irq = &phys_enc->irq[INTR_IDX_RDPTR];
  1660. irq->intr_idx = INTR_IDX_RDPTR;
  1661. irq->name = "te_rd_ptr";
  1662. if (phys_enc->has_intf_te)
  1663. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_RD_PTR;
  1664. else
  1665. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_RD_PTR;
  1666. irq->cb.func = sde_encoder_phys_cmd_te_rd_ptr_irq;
  1667. irq = &phys_enc->irq[INTR_IDX_AUTOREFRESH_DONE];
  1668. irq->name = "autorefresh_done";
  1669. if (phys_enc->has_intf_te)
  1670. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_AUTO_REF;
  1671. else
  1672. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_AUTO_REF;
  1673. irq->intr_idx = INTR_IDX_AUTOREFRESH_DONE;
  1674. irq->cb.func = sde_encoder_phys_cmd_autorefresh_done_irq;
  1675. irq = &phys_enc->irq[INTR_IDX_WRPTR];
  1676. irq->intr_idx = INTR_IDX_WRPTR;
  1677. irq->name = "wr_ptr";
  1678. if (phys_enc->has_intf_te)
  1679. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_WR_PTR;
  1680. else
  1681. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_WR_PTR;
  1682. irq->cb.func = sde_encoder_phys_cmd_wr_ptr_irq;
  1683. atomic_set(&phys_enc->vblank_refcount, 0);
  1684. atomic_set(&phys_enc->pending_kickoff_cnt, 0);
  1685. atomic_set(&phys_enc->pending_retire_fence_cnt, 0);
  1686. atomic_set(&cmd_enc->pending_vblank_cnt, 0);
  1687. init_waitqueue_head(&phys_enc->pending_kickoff_wq);
  1688. init_waitqueue_head(&cmd_enc->pending_vblank_wq);
  1689. atomic_set(&cmd_enc->autorefresh.kickoff_cnt, 0);
  1690. init_waitqueue_head(&cmd_enc->autorefresh.kickoff_wq);
  1691. INIT_LIST_HEAD(&cmd_enc->te_timestamp_list);
  1692. for (i = 0; i < MAX_TE_PROFILE_COUNT; i++)
  1693. list_add(&cmd_enc->te_timestamp[i].list,
  1694. &cmd_enc->te_timestamp_list);
  1695. SDE_DEBUG_CMDENC(cmd_enc, "created\n");
  1696. return phys_enc;
  1697. fail_mdp_init:
  1698. kfree(cmd_enc);
  1699. fail:
  1700. return ERR_PTR(ret);
  1701. }