sde_encoder_phys_cmd.c 58 KB

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