sde_encoder_phys_cmd.c 58 KB

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