sde_encoder_phys_cmd.c 61 KB

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