sde_encoder_phys_cmd.c 58 KB

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