sde_encoder_phys_cmd.c 60 KB

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