sde_encoder_phys_cmd.c 59 KB

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