sde_encoder_phys_cmd.c 59 KB

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