sde_encoder_phys_cmd.c 62 KB

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