sde_encoder_phys_cmd.c 59 KB

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