sde_encoder_phys_cmd.c 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2023 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_override_tearcheck_rd_ptr(struct sde_encoder_phys *phys_enc)
  140. {
  141. struct sde_hw_intf *hw_intf;
  142. struct drm_display_mode *mode;
  143. struct sde_encoder_phys_cmd *cmd_enc;
  144. struct sde_hw_pp_vsync_info info[MAX_CHANNELS_PER_ENC] = {{0}};
  145. u32 adjusted_tear_rd_ptr_line_cnt;
  146. if (!phys_enc || !phys_enc->hw_intf)
  147. return;
  148. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  149. hw_intf = phys_enc->hw_intf;
  150. mode = &phys_enc->cached_mode;
  151. /* Configure TE rd_ptr_val to the end of qsync Start Window.
  152. * This ensures next frame trigger_start does not get latched in the current
  153. * vsync window.
  154. */
  155. adjusted_tear_rd_ptr_line_cnt = mode->vdisplay + cmd_enc->qsync_threshold_lines + 1;
  156. if (hw_intf && hw_intf->ops.override_tear_rd_ptr_val)
  157. hw_intf->ops.override_tear_rd_ptr_val(hw_intf, adjusted_tear_rd_ptr_line_cnt);
  158. sde_encoder_helper_get_pp_line_count(phys_enc->parent, info);
  159. SDE_EVT32_VERBOSE(phys_enc->hw_intf->idx - INTF_0, mode->vdisplay,
  160. cmd_enc->qsync_threshold_lines, adjusted_tear_rd_ptr_line_cnt,
  161. info[0].rd_ptr_line_count, info[0].rd_ptr_frame_count, info[0].wr_ptr_line_count,
  162. info[1].rd_ptr_line_count, info[1].rd_ptr_frame_count, info[1].wr_ptr_line_count);
  163. }
  164. void sde_encoder_restore_tearcheck_rd_ptr(struct sde_encoder_phys *phys_enc)
  165. {
  166. struct sde_hw_intf *hw_intf;
  167. struct sde_hw_pp_vsync_info info[MAX_CHANNELS_PER_ENC] = {{0}};
  168. struct drm_display_mode *mode;
  169. struct sde_encoder_phys_cmd *cmd_enc;
  170. struct sde_encoder_virt *sde_enc;
  171. struct sde_connector *c_conn;
  172. ktime_t nominal_period_ns, nominal_line_time_ns, panel_scan_line_ts_ns = 0;
  173. ktime_t qsync_period_ns, time_into_frame_ns;
  174. u32 qsync_timeout_lines, latency_margin_lines = 0, restored_rd_ptr_lines;
  175. u16 panel_scan_line;
  176. int rc;
  177. if (!phys_enc || !phys_enc->connector) {
  178. SDE_ERROR("invalid arguments\n");
  179. return;
  180. }
  181. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  182. mode = &phys_enc->cached_mode;
  183. hw_intf = phys_enc->hw_intf;
  184. c_conn = to_sde_connector(phys_enc->connector);
  185. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  186. nominal_period_ns = mult_frac(1000000000, 1, drm_mode_vrefresh(mode));
  187. qsync_period_ns = mult_frac(1000000000, 1, sde_enc->mode_info.qsync_min_fps);
  188. nominal_line_time_ns = mult_frac(1, nominal_period_ns, mode->vtotal);
  189. qsync_timeout_lines = mode->vtotal + cmd_enc->qsync_threshold_lines + 1;
  190. /*
  191. * First read panel scan line value using a DCS command.
  192. * If the functionality is not supported or there is an error, defer trigger to
  193. * next TE by setting panel_scan_line to qsync_timeout_lines.
  194. */
  195. if (c_conn->ops.get_panel_scan_line) {
  196. rc = c_conn->ops.get_panel_scan_line(c_conn->display, &panel_scan_line,
  197. &panel_scan_line_ts_ns);
  198. if (rc || panel_scan_line >= qsync_timeout_lines) {
  199. SDE_DEBUG_CMDENC(cmd_enc, "failed to get panel scan line, rc=%d\n", rc);
  200. panel_scan_line = qsync_timeout_lines;
  201. }
  202. } else {
  203. panel_scan_line = qsync_timeout_lines;
  204. }
  205. /* Compensate the latency from DCS scan line response*/
  206. spin_lock(phys_enc->enc_spinlock);
  207. sde_encoder_helper_get_pp_line_count(phys_enc->parent, info);
  208. time_into_frame_ns = ktime_sub(ktime_get(), phys_enc->last_vsync_timestamp);
  209. if (panel_scan_line_ts_ns)
  210. latency_margin_lines = mult_frac(1, ktime_sub(ktime_get(), panel_scan_line_ts_ns),
  211. nominal_line_time_ns);
  212. restored_rd_ptr_lines = panel_scan_line + latency_margin_lines;
  213. if (restored_rd_ptr_lines >= qsync_timeout_lines)
  214. restored_rd_ptr_lines = qsync_timeout_lines;
  215. if (hw_intf && hw_intf->ops.override_tear_rd_ptr_val)
  216. hw_intf->ops.override_tear_rd_ptr_val(hw_intf, restored_rd_ptr_lines);
  217. spin_unlock(phys_enc->enc_spinlock);
  218. SDE_EVT32(DRMID(phys_enc->parent), drm_mode_vrefresh(mode),
  219. sde_enc->mode_info.qsync_min_fps,
  220. mode->vtotal, panel_scan_line, qsync_timeout_lines, latency_margin_lines,
  221. restored_rd_ptr_lines, info[0].rd_ptr_line_count - mode->vdisplay,
  222. ktime_to_us(time_into_frame_ns));
  223. SDE_DEBUG_CMDENC(cmd_enc, "scan_line:%u rest_rd_ptr:%u rd_ptr:%u frame_ns:%u\n",
  224. panel_scan_line, restored_rd_ptr_lines,
  225. info[0].rd_ptr_line_count - mode->vdisplay,
  226. ktime_to_us(time_into_frame_ns));
  227. }
  228. static void _sde_encoder_phys_signal_frame_done(struct sde_encoder_phys *phys_enc)
  229. {
  230. struct sde_encoder_phys_cmd *cmd_enc;
  231. struct sde_hw_ctl *ctl;
  232. u32 scheduler_status = INVALID_CTL_STATUS, event = 0;
  233. struct sde_hw_pp_vsync_info info[MAX_CHANNELS_PER_ENC] = {{0}};
  234. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  235. ctl = phys_enc->hw_ctl;
  236. if (!ctl)
  237. return;
  238. /* notify all synchronous clients first, then asynchronous clients */
  239. if (phys_enc->parent_ops.handle_frame_done &&
  240. atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0)) {
  241. event = SDE_ENCODER_FRAME_EVENT_DONE |
  242. SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE;
  243. spin_lock(phys_enc->enc_spinlock);
  244. phys_enc->parent_ops.handle_frame_done(phys_enc->parent,
  245. phys_enc, event);
  246. if (cmd_enc->frame_tx_timeout_report_cnt)
  247. phys_enc->recovered = true;
  248. spin_unlock(phys_enc->enc_spinlock);
  249. }
  250. if (ctl->ops.get_scheduler_status)
  251. scheduler_status = ctl->ops.get_scheduler_status(ctl);
  252. sde_encoder_helper_get_pp_line_count(phys_enc->parent, info);
  253. SDE_EVT32_IRQ(DRMID(phys_enc->parent), ctl->idx - CTL_0, phys_enc->hw_pp->idx - PINGPONG_0,
  254. event, scheduler_status, phys_enc->autorefresh_disable_trans, info[0].pp_idx,
  255. info[0].intf_idx, info[0].intf_frame_count, info[0].wr_ptr_line_count,
  256. info[0].rd_ptr_line_count, info[1].pp_idx, info[1].intf_idx,
  257. info[1].intf_frame_count, info[1].wr_ptr_line_count, info[1].rd_ptr_line_count);
  258. /*
  259. * For hw-fences, in the last frame during the autorefresh disable transition
  260. * hw won't trigger the output-fence signal once the frame is done, therefore
  261. * sw must trigger the override to force the signal here
  262. */
  263. if (phys_enc->autorefresh_disable_trans) {
  264. if (ctl->ops.trigger_output_fence_override)
  265. ctl->ops.trigger_output_fence_override(ctl);
  266. phys_enc->autorefresh_disable_trans = false;
  267. }
  268. /* Signal any waiting atomic commit thread */
  269. wake_up_all(&phys_enc->pending_kickoff_wq);
  270. }
  271. static void sde_encoder_phys_cmd_ctl_done_irq(void *arg, int irq_idx)
  272. {
  273. struct sde_encoder_phys *phys_enc = arg;
  274. if (!phys_enc)
  275. return;
  276. SDE_ATRACE_BEGIN("ctl_done_irq");
  277. _sde_encoder_phys_signal_frame_done(phys_enc);
  278. SDE_ATRACE_END("ctl_done_irq");
  279. }
  280. static void sde_encoder_phys_cmd_pp_tx_done_irq(void *arg, int irq_idx)
  281. {
  282. struct sde_encoder_phys *phys_enc = arg;
  283. if (!phys_enc || !phys_enc->hw_pp)
  284. return;
  285. SDE_ATRACE_BEGIN("pp_done_irq");
  286. _sde_encoder_phys_signal_frame_done(phys_enc);
  287. SDE_ATRACE_END("pp_done_irq");
  288. }
  289. static void sde_encoder_phys_cmd_autorefresh_done_irq(void *arg, int irq_idx)
  290. {
  291. struct sde_encoder_phys *phys_enc = arg;
  292. struct sde_encoder_phys_cmd *cmd_enc =
  293. to_sde_encoder_phys_cmd(phys_enc);
  294. unsigned long lock_flags;
  295. int new_cnt;
  296. if (!cmd_enc)
  297. return;
  298. phys_enc = &cmd_enc->base;
  299. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  300. new_cnt = atomic_add_unless(&cmd_enc->autorefresh.kickoff_cnt, -1, 0);
  301. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  302. SDE_EVT32_IRQ(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  303. phys_enc->hw_intf->idx - INTF_0, new_cnt);
  304. if (new_cnt)
  305. _sde_encoder_phys_signal_frame_done(phys_enc);
  306. /* Signal any waiting atomic commit thread */
  307. wake_up_all(&cmd_enc->autorefresh.kickoff_wq);
  308. }
  309. static void sde_encoder_phys_cmd_te_rd_ptr_irq(void *arg, int irq_idx)
  310. {
  311. struct sde_encoder_phys *phys_enc = arg;
  312. struct sde_encoder_phys_cmd *cmd_enc;
  313. u32 scheduler_status = INVALID_CTL_STATUS;
  314. struct sde_hw_ctl *ctl;
  315. struct sde_hw_pp_vsync_info info[MAX_CHANNELS_PER_ENC] = {{0}};
  316. struct sde_encoder_phys_cmd_te_timestamp *te_timestamp;
  317. unsigned long lock_flags;
  318. u32 fence_ready = 0;
  319. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf || !phys_enc->hw_ctl)
  320. return;
  321. SDE_ATRACE_BEGIN("rd_ptr_irq");
  322. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  323. ctl = phys_enc->hw_ctl;
  324. if (ctl->ops.get_scheduler_status)
  325. scheduler_status = ctl->ops.get_scheduler_status(ctl);
  326. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  327. te_timestamp = list_first_entry_or_null(&cmd_enc->te_timestamp_list,
  328. struct sde_encoder_phys_cmd_te_timestamp, list);
  329. if (te_timestamp) {
  330. list_del_init(&te_timestamp->list);
  331. te_timestamp->timestamp = ktime_get();
  332. list_add_tail(&te_timestamp->list, &cmd_enc->te_timestamp_list);
  333. }
  334. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  335. if ((scheduler_status != 0x1) && ctl->ops.get_hw_fence_status)
  336. fence_ready = ctl->ops.get_hw_fence_status(ctl);
  337. sde_encoder_helper_get_pp_line_count(phys_enc->parent, info);
  338. SDE_EVT32_IRQ(DRMID(phys_enc->parent), scheduler_status, fence_ready, info[0].pp_idx,
  339. info[0].intf_idx, info[0].intf_frame_count, info[0].wr_ptr_line_count,
  340. info[0].rd_ptr_line_count, info[1].pp_idx, info[1].intf_idx,
  341. info[1].intf_frame_count, info[1].wr_ptr_line_count, info[1].rd_ptr_line_count);
  342. if (phys_enc->parent_ops.handle_vblank_virt)
  343. phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent,
  344. phys_enc);
  345. atomic_add_unless(&cmd_enc->pending_vblank_cnt, -1, 0);
  346. wake_up_all(&cmd_enc->pending_vblank_wq);
  347. SDE_ATRACE_END("rd_ptr_irq");
  348. }
  349. static void sde_encoder_phys_cmd_wr_ptr_irq(void *arg, int irq_idx)
  350. {
  351. struct sde_encoder_phys *phys_enc = arg;
  352. struct sde_hw_ctl *ctl;
  353. u32 event = 0, qsync_mode = 0;
  354. struct sde_hw_pp_vsync_info info[MAX_CHANNELS_PER_ENC] = {{0}};
  355. if (!phys_enc || !phys_enc->hw_ctl)
  356. return;
  357. SDE_ATRACE_BEGIN("wr_ptr_irq");
  358. ctl = phys_enc->hw_ctl;
  359. qsync_mode = sde_connector_get_qsync_mode(phys_enc->connector);
  360. if (atomic_add_unless(&phys_enc->pending_retire_fence_cnt, -1, 0)) {
  361. event = SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE;
  362. if (phys_enc->parent_ops.handle_frame_done) {
  363. spin_lock(phys_enc->enc_spinlock);
  364. phys_enc->parent_ops.handle_frame_done(
  365. phys_enc->parent, phys_enc, event);
  366. spin_unlock(phys_enc->enc_spinlock);
  367. }
  368. }
  369. sde_encoder_helper_get_pp_line_count(phys_enc->parent, info);
  370. SDE_EVT32_IRQ(DRMID(phys_enc->parent), ctl->idx - CTL_0, event, qsync_mode,
  371. info[0].pp_idx, info[0].intf_idx, info[0].intf_frame_count,
  372. info[0].wr_ptr_line_count, info[0].rd_ptr_line_count, info[1].pp_idx,
  373. info[1].intf_idx, info[1].intf_frame_count, info[1].wr_ptr_line_count,
  374. info[1].rd_ptr_line_count);
  375. if (qsync_mode &&
  376. !test_bit(SDE_INTF_TE_SINGLE_UPDATE, &phys_enc->hw_intf->cap->features))
  377. sde_encoder_override_tearcheck_rd_ptr(phys_enc);
  378. /* Signal any waiting wr_ptr start interrupt */
  379. wake_up_all(&phys_enc->pending_kickoff_wq);
  380. SDE_ATRACE_END("wr_ptr_irq");
  381. }
  382. static void sde_encoder_phys_cmd_tear_detect_irq(void *arg, int irq_idx)
  383. {
  384. struct sde_encoder_phys *phys_enc = arg;
  385. struct sde_encoder_phys_cmd *cmd_enc;
  386. if (!phys_enc)
  387. return;
  388. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  389. if (!cmd_enc)
  390. return;
  391. SDE_ATRACE_BEGIN("tear_detect_irq");
  392. SDE_EVT32_IRQ(DRMID(phys_enc->parent));
  393. SDE_ATRACE_END("tear_detect_irq");
  394. }
  395. static void sde_encoder_phys_cmd_te_assert_irq(void *arg, int irq_idx)
  396. {
  397. struct sde_encoder_phys *phys_enc = arg;
  398. struct sde_encoder_phys_cmd *cmd_enc;
  399. if (!phys_enc)
  400. return;
  401. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  402. if (!cmd_enc)
  403. return;
  404. SDE_ATRACE_BEGIN("te_assert_irq");
  405. SDE_EVT32_IRQ(DRMID(phys_enc->parent));
  406. SDE_ATRACE_END("te_assert_irq");
  407. }
  408. static void sde_encoder_phys_cmd_te_deassert_irq(void *arg, int irq_idx)
  409. {
  410. struct sde_encoder_phys *phys_enc = arg;
  411. struct sde_encoder_phys_cmd *cmd_enc;
  412. if (!phys_enc)
  413. return;
  414. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  415. if (!cmd_enc)
  416. return;
  417. SDE_ATRACE_BEGIN("te_deassert_irq");
  418. SDE_EVT32_IRQ(DRMID(phys_enc->parent));
  419. SDE_ATRACE_END("te_deassert_irq");
  420. }
  421. static void _sde_encoder_phys_cmd_setup_irq_hw_idx(
  422. struct sde_encoder_phys *phys_enc)
  423. {
  424. struct sde_encoder_irq *irq;
  425. struct sde_kms *sde_kms;
  426. if (!phys_enc->sde_kms || !phys_enc->hw_pp || !phys_enc->hw_ctl) {
  427. SDE_ERROR("invalid args %d %d %d\n", !phys_enc->sde_kms,
  428. !phys_enc->hw_pp, !phys_enc->hw_ctl);
  429. return;
  430. }
  431. if (phys_enc->has_intf_te && !phys_enc->hw_intf) {
  432. SDE_ERROR("invalid intf configuration\n");
  433. return;
  434. }
  435. sde_kms = phys_enc->sde_kms;
  436. irq = &phys_enc->irq[INTR_IDX_CTL_START];
  437. irq->hw_idx = phys_enc->hw_ctl->idx;
  438. irq = &phys_enc->irq[INTR_IDX_CTL_DONE];
  439. irq->hw_idx = phys_enc->hw_ctl->idx;
  440. irq = &phys_enc->irq[INTR_IDX_PINGPONG];
  441. irq->hw_idx = phys_enc->hw_pp->idx;
  442. irq = &phys_enc->irq[INTR_IDX_RDPTR];
  443. if (phys_enc->has_intf_te)
  444. irq->hw_idx = phys_enc->hw_intf->idx;
  445. else
  446. irq->hw_idx = phys_enc->hw_pp->idx;
  447. irq = &phys_enc->irq[INTR_IDX_AUTOREFRESH_DONE];
  448. if (phys_enc->has_intf_te)
  449. irq->hw_idx = phys_enc->hw_intf->idx;
  450. else
  451. irq->hw_idx = phys_enc->hw_pp->idx;
  452. irq = &phys_enc->irq[INTR_IDX_WRPTR];
  453. if (phys_enc->has_intf_te)
  454. irq->hw_idx = phys_enc->hw_intf->idx;
  455. else
  456. irq->hw_idx = phys_enc->hw_pp->idx;
  457. irq = &phys_enc->irq[INTF_IDX_TEAR_DETECT];
  458. if (phys_enc->has_intf_te)
  459. irq->hw_idx = phys_enc->hw_intf->idx;
  460. else
  461. irq->hw_idx = phys_enc->hw_pp->idx;
  462. if (phys_enc->has_intf_te) {
  463. irq = &phys_enc->irq[INTR_IDX_TE_ASSERT];
  464. irq->hw_idx = phys_enc->hw_intf->idx;
  465. if (test_bit(SDE_INTF_TE_DEASSERT_DETECT, &phys_enc->hw_intf->cap->features)) {
  466. irq = &phys_enc->irq[INTR_IDX_TE_DEASSERT];
  467. irq->hw_idx = phys_enc->hw_intf->idx;
  468. }
  469. }
  470. }
  471. static void sde_encoder_phys_cmd_cont_splash_mode_set(
  472. struct sde_encoder_phys *phys_enc,
  473. struct drm_display_mode *adj_mode)
  474. {
  475. struct sde_hw_intf *hw_intf;
  476. struct sde_hw_pingpong *hw_pp;
  477. struct sde_encoder_phys_cmd *cmd_enc;
  478. if (!phys_enc || !adj_mode) {
  479. SDE_ERROR("invalid args\n");
  480. return;
  481. }
  482. phys_enc->cached_mode = *adj_mode;
  483. phys_enc->enable_state = SDE_ENC_ENABLED;
  484. if (!phys_enc->hw_ctl || !phys_enc->hw_pp) {
  485. SDE_DEBUG("invalid ctl:%d pp:%d\n",
  486. (phys_enc->hw_ctl == NULL),
  487. (phys_enc->hw_pp == NULL));
  488. return;
  489. }
  490. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  491. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  492. hw_pp = phys_enc->hw_pp;
  493. hw_intf = phys_enc->hw_intf;
  494. if (phys_enc->has_intf_te && hw_intf &&
  495. hw_intf->ops.get_autorefresh) {
  496. hw_intf->ops.get_autorefresh(hw_intf,
  497. &cmd_enc->autorefresh.cfg);
  498. } else if (hw_pp && hw_pp->ops.get_autorefresh) {
  499. hw_pp->ops.get_autorefresh(hw_pp,
  500. &cmd_enc->autorefresh.cfg);
  501. }
  502. if (hw_intf && hw_intf->ops.reset_counter)
  503. hw_intf->ops.reset_counter(hw_intf);
  504. }
  505. _sde_encoder_phys_cmd_setup_irq_hw_idx(phys_enc);
  506. }
  507. static void sde_encoder_phys_cmd_mode_set(
  508. struct sde_encoder_phys *phys_enc,
  509. struct drm_display_mode *mode,
  510. struct drm_display_mode *adj_mode, bool *reinit_mixers)
  511. {
  512. struct sde_encoder_phys_cmd *cmd_enc =
  513. to_sde_encoder_phys_cmd(phys_enc);
  514. struct sde_rm *rm = &phys_enc->sde_kms->rm;
  515. struct sde_rm_hw_iter iter;
  516. int i, instance;
  517. if (!phys_enc || !mode || !adj_mode) {
  518. SDE_ERROR("invalid args\n");
  519. return;
  520. }
  521. phys_enc->cached_mode = *adj_mode;
  522. SDE_DEBUG_CMDENC(cmd_enc, "caching mode:\n");
  523. drm_mode_debug_printmodeline(adj_mode);
  524. instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0;
  525. /* Retrieve previously allocated HW Resources. Shouldn't fail */
  526. sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CTL);
  527. for (i = 0; i <= instance; i++) {
  528. if (sde_rm_get_hw(rm, &iter)) {
  529. if (phys_enc->hw_ctl && phys_enc->hw_ctl != to_sde_hw_ctl(iter.hw)) {
  530. *reinit_mixers = true;
  531. SDE_EVT32(phys_enc->hw_ctl->idx,
  532. to_sde_hw_ctl(iter.hw)->idx);
  533. }
  534. phys_enc->hw_ctl = to_sde_hw_ctl(iter.hw);
  535. }
  536. }
  537. if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
  538. SDE_ERROR_CMDENC(cmd_enc, "failed to init ctl: %ld\n",
  539. PTR_ERR(phys_enc->hw_ctl));
  540. phys_enc->hw_ctl = NULL;
  541. return;
  542. }
  543. sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_INTF);
  544. for (i = 0; i <= instance; i++) {
  545. if (sde_rm_get_hw(rm, &iter))
  546. phys_enc->hw_intf = to_sde_hw_intf(iter.hw);
  547. }
  548. if (IS_ERR_OR_NULL(phys_enc->hw_intf)) {
  549. SDE_ERROR_CMDENC(cmd_enc, "failed to init intf: %ld\n",
  550. PTR_ERR(phys_enc->hw_intf));
  551. phys_enc->hw_intf = NULL;
  552. return;
  553. }
  554. _sde_encoder_phys_cmd_setup_irq_hw_idx(phys_enc);
  555. phys_enc->kickoff_timeout_ms =
  556. sde_encoder_helper_get_kickoff_timeout_ms(phys_enc->parent);
  557. }
  558. static int _sde_encoder_phys_cmd_handle_framedone_timeout(
  559. struct sde_encoder_phys *phys_enc)
  560. {
  561. struct sde_encoder_phys_cmd *cmd_enc =
  562. to_sde_encoder_phys_cmd(phys_enc);
  563. bool recovery_events = sde_encoder_recovery_events_enabled(
  564. phys_enc->parent);
  565. u32 frame_event = SDE_ENCODER_FRAME_EVENT_ERROR
  566. | SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE;
  567. struct drm_connector *conn;
  568. u32 pending_kickoff_cnt;
  569. unsigned long lock_flags;
  570. if (!phys_enc->hw_pp || !phys_enc->hw_ctl)
  571. return -EINVAL;
  572. conn = phys_enc->connector;
  573. /* decrement the kickoff_cnt before checking for ESD status */
  574. if (!atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0))
  575. return 0;
  576. cmd_enc->frame_tx_timeout_report_cnt++;
  577. pending_kickoff_cnt = atomic_read(&phys_enc->pending_kickoff_cnt) + 1;
  578. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  579. cmd_enc->frame_tx_timeout_report_cnt,
  580. pending_kickoff_cnt,
  581. frame_event);
  582. /* check if panel is still sending TE signal or not */
  583. if (sde_connector_esd_status(phys_enc->connector))
  584. goto exit;
  585. /* to avoid flooding, only log first time, and "dead" time */
  586. if (cmd_enc->frame_tx_timeout_report_cnt == 1) {
  587. SDE_ERROR_CMDENC(cmd_enc,
  588. "pp:%d kickoff timed out ctl %d koff_cnt %d\n",
  589. phys_enc->hw_pp->idx - PINGPONG_0,
  590. phys_enc->hw_ctl->idx - CTL_0,
  591. pending_kickoff_cnt);
  592. SDE_EVT32(DRMID(phys_enc->parent), SDE_EVTLOG_FATAL);
  593. mutex_lock(phys_enc->vblank_ctl_lock);
  594. sde_encoder_helper_unregister_irq(phys_enc, INTR_IDX_RDPTR);
  595. if (sde_kms_is_secure_session_inprogress(phys_enc->sde_kms))
  596. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL, "secure");
  597. else
  598. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL);
  599. sde_encoder_helper_register_irq(phys_enc, INTR_IDX_RDPTR);
  600. mutex_unlock(phys_enc->vblank_ctl_lock);
  601. }
  602. /*
  603. * if the recovery event is registered by user, don't panic
  604. * trigger panic on first timeout if no listener registered
  605. */
  606. if (recovery_events)
  607. sde_connector_event_notify(conn, DRM_EVENT_SDE_HW_RECOVERY,
  608. sizeof(uint8_t), SDE_RECOVERY_CAPTURE);
  609. else if (cmd_enc->frame_tx_timeout_report_cnt)
  610. SDE_DBG_DUMP(0x0, "panic");
  611. /* request a ctl reset before the next kickoff */
  612. phys_enc->enable_state = SDE_ENC_ERR_NEEDS_HW_RESET;
  613. exit:
  614. if (phys_enc->parent_ops.handle_frame_done) {
  615. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  616. phys_enc->parent_ops.handle_frame_done(
  617. phys_enc->parent, phys_enc, frame_event);
  618. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  619. }
  620. return -ETIMEDOUT;
  621. }
  622. static bool _sde_encoder_phys_is_ppsplit_slave(
  623. struct sde_encoder_phys *phys_enc)
  624. {
  625. if (!phys_enc)
  626. return false;
  627. return _sde_encoder_phys_is_ppsplit(phys_enc) &&
  628. phys_enc->split_role == ENC_ROLE_SLAVE;
  629. }
  630. static bool _sde_encoder_phys_is_disabling_ppsplit_slave(
  631. struct sde_encoder_phys *phys_enc)
  632. {
  633. enum sde_rm_topology_name old_top;
  634. if (!phys_enc || !phys_enc->connector ||
  635. phys_enc->split_role != ENC_ROLE_SLAVE)
  636. return false;
  637. old_top = sde_connector_get_old_topology_name(
  638. phys_enc->connector->state);
  639. return old_top == SDE_RM_TOPOLOGY_PPSPLIT;
  640. }
  641. static int _sde_encoder_phys_cmd_poll_write_pointer_started(
  642. struct sde_encoder_phys *phys_enc)
  643. {
  644. struct sde_encoder_phys_cmd *cmd_enc =
  645. to_sde_encoder_phys_cmd(phys_enc);
  646. struct sde_hw_pingpong *hw_pp = phys_enc->hw_pp;
  647. struct sde_hw_intf *hw_intf = phys_enc->hw_intf;
  648. struct sde_hw_pp_vsync_info info;
  649. u32 timeout_us = SDE_ENC_WR_PTR_START_TIMEOUT_US;
  650. int ret = 0;
  651. if (!hw_pp || !hw_intf)
  652. return 0;
  653. if (phys_enc->has_intf_te) {
  654. if (!hw_intf->ops.get_vsync_info ||
  655. !hw_intf->ops.poll_timeout_wr_ptr)
  656. goto end;
  657. } else {
  658. if (!hw_pp->ops.get_vsync_info ||
  659. !hw_pp->ops.poll_timeout_wr_ptr)
  660. goto end;
  661. }
  662. if (phys_enc->has_intf_te)
  663. ret = hw_intf->ops.get_vsync_info(hw_intf, &info);
  664. else
  665. ret = hw_pp->ops.get_vsync_info(hw_pp, &info);
  666. if (ret)
  667. return ret;
  668. SDE_DEBUG_CMDENC(cmd_enc,
  669. "pp:%d intf:%d rd_ptr %d wr_ptr %d\n",
  670. phys_enc->hw_pp->idx - PINGPONG_0,
  671. phys_enc->hw_intf->idx - INTF_0,
  672. info.rd_ptr_line_count,
  673. info.wr_ptr_line_count);
  674. SDE_EVT32_VERBOSE(DRMID(phys_enc->parent),
  675. phys_enc->hw_pp->idx - PINGPONG_0,
  676. phys_enc->hw_intf->idx - INTF_0,
  677. info.wr_ptr_line_count);
  678. if (phys_enc->has_intf_te)
  679. ret = hw_intf->ops.poll_timeout_wr_ptr(hw_intf, timeout_us);
  680. else
  681. ret = hw_pp->ops.poll_timeout_wr_ptr(hw_pp, timeout_us);
  682. if (ret) {
  683. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  684. phys_enc->hw_intf->idx - INTF_0, timeout_us, ret);
  685. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL, "panic");
  686. }
  687. end:
  688. return ret;
  689. }
  690. static bool _sde_encoder_phys_cmd_is_ongoing_pptx(
  691. struct sde_encoder_phys *phys_enc)
  692. {
  693. struct sde_hw_pingpong *hw_pp;
  694. struct sde_hw_pp_vsync_info info;
  695. struct sde_hw_intf *hw_intf;
  696. if (!phys_enc)
  697. return false;
  698. if (phys_enc->has_intf_te) {
  699. hw_intf = phys_enc->hw_intf;
  700. if (!hw_intf || !hw_intf->ops.get_vsync_info)
  701. return false;
  702. hw_intf->ops.get_vsync_info(hw_intf, &info);
  703. } else {
  704. hw_pp = phys_enc->hw_pp;
  705. if (!hw_pp || !hw_pp->ops.get_vsync_info)
  706. return false;
  707. hw_pp->ops.get_vsync_info(hw_pp, &info);
  708. }
  709. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  710. phys_enc->hw_intf->idx - INTF_0, atomic_read(&phys_enc->pending_kickoff_cnt),
  711. info.wr_ptr_line_count, info.intf_frame_count, phys_enc->cached_mode.vdisplay);
  712. if (info.wr_ptr_line_count > 0 && info.wr_ptr_line_count <
  713. phys_enc->cached_mode.vdisplay)
  714. return true;
  715. return false;
  716. }
  717. static bool _sde_encoder_phys_cmd_is_scheduler_idle(
  718. struct sde_encoder_phys *phys_enc)
  719. {
  720. bool wr_ptr_wait_success = true;
  721. unsigned long lock_flags;
  722. bool ret = false;
  723. struct sde_encoder_phys_cmd *cmd_enc =
  724. to_sde_encoder_phys_cmd(phys_enc);
  725. struct sde_hw_ctl *ctl = phys_enc->hw_ctl;
  726. enum frame_trigger_mode_type frame_trigger_mode =
  727. phys_enc->frame_trigger_mode;
  728. if (sde_encoder_phys_cmd_is_master(phys_enc))
  729. wr_ptr_wait_success = cmd_enc->wr_ptr_wait_success;
  730. /*
  731. * Handle cases where a pp-done interrupt is missed
  732. * due to irq latency with POSTED start
  733. */
  734. if (wr_ptr_wait_success &&
  735. (frame_trigger_mode == FRAME_DONE_WAIT_POSTED_START) &&
  736. ctl->ops.get_scheduler_status &&
  737. phys_enc->parent_ops.handle_frame_done &&
  738. atomic_read(&phys_enc->pending_kickoff_cnt) > 0 &&
  739. (ctl->ops.get_scheduler_status(ctl) & BIT(0)) &&
  740. atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0)) {
  741. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  742. phys_enc->parent_ops.handle_frame_done(
  743. phys_enc->parent, phys_enc,
  744. SDE_ENCODER_FRAME_EVENT_DONE |
  745. SDE_ENCODER_FRAME_EVENT_SIGNAL_RELEASE_FENCE);
  746. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  747. SDE_EVT32(DRMID(phys_enc->parent),
  748. phys_enc->hw_pp->idx - PINGPONG_0,
  749. phys_enc->hw_intf->idx - INTF_0,
  750. atomic_read(&phys_enc->pending_kickoff_cnt));
  751. ret = true;
  752. }
  753. return ret;
  754. }
  755. static int _sde_encoder_phys_cmd_wait_for_idle(
  756. struct sde_encoder_phys *phys_enc)
  757. {
  758. struct sde_encoder_wait_info wait_info = {0};
  759. enum sde_intr_idx intr_idx;
  760. int ret;
  761. if (!phys_enc) {
  762. SDE_ERROR("invalid encoder\n");
  763. return -EINVAL;
  764. }
  765. if (sde_encoder_check_ctl_done_support(phys_enc->parent)
  766. && !sde_encoder_phys_cmd_is_master(phys_enc))
  767. return 0;
  768. if (atomic_read(&phys_enc->pending_kickoff_cnt) > 1)
  769. wait_info.count_check = 1;
  770. wait_info.wq = &phys_enc->pending_kickoff_wq;
  771. wait_info.atomic_cnt = &phys_enc->pending_kickoff_cnt;
  772. wait_info.timeout_ms = phys_enc->kickoff_timeout_ms;
  773. /* slave encoder doesn't enable for ppsplit */
  774. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  775. return 0;
  776. if (_sde_encoder_phys_cmd_is_scheduler_idle(phys_enc))
  777. return 0;
  778. intr_idx = sde_encoder_check_ctl_done_support(phys_enc->parent) ?
  779. INTR_IDX_CTL_DONE : INTR_IDX_PINGPONG;
  780. ret = sde_encoder_helper_wait_for_irq(phys_enc, intr_idx, &wait_info);
  781. if (ret == -ETIMEDOUT) {
  782. if (_sde_encoder_phys_cmd_is_scheduler_idle(phys_enc))
  783. return 0;
  784. _sde_encoder_phys_cmd_handle_framedone_timeout(phys_enc);
  785. }
  786. return ret;
  787. }
  788. static int _sde_encoder_phys_cmd_wait_for_autorefresh_done(
  789. struct sde_encoder_phys *phys_enc)
  790. {
  791. struct sde_encoder_phys_cmd *cmd_enc =
  792. to_sde_encoder_phys_cmd(phys_enc);
  793. struct sde_encoder_wait_info wait_info = {0};
  794. int ret = 0;
  795. if (!phys_enc) {
  796. SDE_ERROR("invalid encoder\n");
  797. return -EINVAL;
  798. }
  799. /* only master deals with autorefresh */
  800. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  801. return 0;
  802. wait_info.wq = &cmd_enc->autorefresh.kickoff_wq;
  803. wait_info.atomic_cnt = &cmd_enc->autorefresh.kickoff_cnt;
  804. wait_info.timeout_ms = _sde_encoder_phys_cmd_get_idle_timeout(phys_enc);
  805. /* wait for autorefresh kickoff to start */
  806. ret = sde_encoder_helper_wait_for_irq(phys_enc,
  807. INTR_IDX_AUTOREFRESH_DONE, &wait_info);
  808. /* double check that kickoff has started by reading write ptr reg */
  809. if (!ret)
  810. ret = _sde_encoder_phys_cmd_poll_write_pointer_started(
  811. phys_enc);
  812. else
  813. sde_encoder_helper_report_irq_timeout(phys_enc,
  814. INTR_IDX_AUTOREFRESH_DONE);
  815. return ret;
  816. }
  817. static int sde_encoder_phys_cmd_control_vblank_irq(
  818. struct sde_encoder_phys *phys_enc,
  819. bool enable)
  820. {
  821. struct sde_encoder_phys_cmd *cmd_enc =
  822. to_sde_encoder_phys_cmd(phys_enc);
  823. int ret = 0;
  824. u32 refcount;
  825. struct sde_kms *sde_kms;
  826. if (!phys_enc || !phys_enc->hw_pp) {
  827. SDE_ERROR("invalid encoder\n");
  828. return -EINVAL;
  829. }
  830. sde_kms = phys_enc->sde_kms;
  831. mutex_lock(phys_enc->vblank_ctl_lock);
  832. /* Slave encoders don't report vblank */
  833. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  834. goto end;
  835. refcount = atomic_read(&phys_enc->vblank_refcount);
  836. /* protect against negative */
  837. if (!enable && refcount == 0) {
  838. ret = -EINVAL;
  839. goto end;
  840. }
  841. SDE_DEBUG_CMDENC(cmd_enc, "[%pS] enable=%d/%d\n",
  842. __builtin_return_address(0), enable, refcount);
  843. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  844. enable, refcount);
  845. if (enable && atomic_inc_return(&phys_enc->vblank_refcount) == 1) {
  846. ret = sde_encoder_helper_register_irq(phys_enc, INTR_IDX_RDPTR);
  847. if (ret)
  848. atomic_dec_return(&phys_enc->vblank_refcount);
  849. } else if (!enable &&
  850. atomic_dec_return(&phys_enc->vblank_refcount) == 0) {
  851. ret = sde_encoder_helper_unregister_irq(phys_enc,
  852. INTR_IDX_RDPTR);
  853. if (ret)
  854. atomic_inc_return(&phys_enc->vblank_refcount);
  855. }
  856. end:
  857. mutex_unlock(phys_enc->vblank_ctl_lock);
  858. if (ret) {
  859. SDE_ERROR_CMDENC(cmd_enc,
  860. "control vblank irq error %d, enable %d, refcount %d\n",
  861. ret, enable, refcount);
  862. SDE_EVT32(DRMID(phys_enc->parent),
  863. phys_enc->hw_pp->idx - PINGPONG_0,
  864. enable, refcount, SDE_EVTLOG_ERROR);
  865. }
  866. return ret;
  867. }
  868. void sde_encoder_phys_cmd_dynamic_irq_control(struct sde_encoder_phys *phys_enc, bool enable)
  869. {
  870. struct sde_encoder_virt *sde_enc;
  871. if (!phys_enc)
  872. return;
  873. /**
  874. * pingpong split slaves do not register for IRQs
  875. * check old and new topologies
  876. */
  877. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc) ||
  878. _sde_encoder_phys_is_disabling_ppsplit_slave(phys_enc))
  879. return;
  880. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  881. if (enable) {
  882. if (test_bit(SDE_ENC_CMD_TEAR_DETECT, &sde_enc->dynamic_irqs_config))
  883. sde_encoder_helper_register_irq(phys_enc, INTF_IDX_TEAR_DETECT);
  884. if (test_bit(SDE_ENC_CMD_TE_ASSERT, &sde_enc->dynamic_irqs_config) &&
  885. phys_enc->has_intf_te)
  886. sde_encoder_helper_register_irq(phys_enc, INTR_IDX_TE_ASSERT);
  887. if (test_bit(SDE_ENC_CMD_TE_DEASSERT, &sde_enc->dynamic_irqs_config) &&
  888. test_bit(SDE_INTF_TE_DEASSERT_DETECT,
  889. &phys_enc->hw_intf->cap->features) &&
  890. phys_enc->has_intf_te)
  891. sde_encoder_helper_register_irq(phys_enc, INTR_IDX_TE_DEASSERT);
  892. } else {
  893. if (SDE_ENC_IRQ_REGISTERED(phys_enc, INTF_IDX_TEAR_DETECT))
  894. sde_encoder_helper_unregister_irq(phys_enc, INTF_IDX_TEAR_DETECT);
  895. if (SDE_ENC_IRQ_REGISTERED(phys_enc, INTR_IDX_TE_ASSERT))
  896. sde_encoder_helper_unregister_irq(phys_enc, INTR_IDX_TE_ASSERT);
  897. if (test_bit(SDE_INTF_TE_DEASSERT_DETECT, &phys_enc->hw_intf->cap->features) &&
  898. SDE_ENC_IRQ_REGISTERED(phys_enc, INTR_IDX_TE_DEASSERT))
  899. sde_encoder_helper_unregister_irq(phys_enc, INTR_IDX_TE_DEASSERT);
  900. }
  901. }
  902. void sde_encoder_phys_cmd_irq_control(struct sde_encoder_phys *phys_enc,
  903. bool enable)
  904. {
  905. struct sde_encoder_phys_cmd *cmd_enc;
  906. bool ctl_done_supported = false;
  907. if (!phys_enc)
  908. return;
  909. /**
  910. * pingpong split slaves do not register for IRQs
  911. * check old and new topologies
  912. */
  913. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc) ||
  914. _sde_encoder_phys_is_disabling_ppsplit_slave(phys_enc))
  915. return;
  916. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  917. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  918. enable, atomic_read(&phys_enc->vblank_refcount));
  919. ctl_done_supported = sde_encoder_check_ctl_done_support(phys_enc->parent);
  920. if (enable) {
  921. if (!ctl_done_supported)
  922. sde_encoder_helper_register_irq(phys_enc, INTR_IDX_PINGPONG);
  923. sde_encoder_phys_cmd_control_vblank_irq(phys_enc, true);
  924. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  925. sde_encoder_helper_register_irq(phys_enc,
  926. INTR_IDX_WRPTR);
  927. sde_encoder_helper_register_irq(phys_enc,
  928. INTR_IDX_AUTOREFRESH_DONE);
  929. if (ctl_done_supported)
  930. sde_encoder_helper_register_irq(phys_enc, INTR_IDX_CTL_DONE);
  931. }
  932. } else {
  933. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  934. sde_encoder_helper_unregister_irq(phys_enc,
  935. INTR_IDX_WRPTR);
  936. sde_encoder_helper_unregister_irq(phys_enc,
  937. INTR_IDX_AUTOREFRESH_DONE);
  938. if (ctl_done_supported)
  939. sde_encoder_helper_unregister_irq(phys_enc, INTR_IDX_CTL_DONE);
  940. }
  941. sde_encoder_phys_cmd_control_vblank_irq(phys_enc, false);
  942. if (!ctl_done_supported)
  943. sde_encoder_helper_unregister_irq(phys_enc, INTR_IDX_PINGPONG);
  944. }
  945. }
  946. static int _get_tearcheck_threshold(struct sde_encoder_phys *phys_enc)
  947. {
  948. struct drm_connector *conn = phys_enc->connector;
  949. u32 qsync_mode;
  950. struct drm_display_mode *mode;
  951. u32 threshold_lines, adjusted_threshold_lines;
  952. struct sde_encoder_phys_cmd *cmd_enc =
  953. to_sde_encoder_phys_cmd(phys_enc);
  954. struct sde_encoder_virt *sde_enc;
  955. struct msm_mode_info *info;
  956. if (!conn || !conn->state)
  957. return 0;
  958. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  959. info = &sde_enc->mode_info;
  960. mode = &phys_enc->cached_mode;
  961. qsync_mode = sde_connector_get_qsync_mode(conn);
  962. threshold_lines = adjusted_threshold_lines = DEFAULT_TEARCHECK_SYNC_THRESH_START;
  963. if (mode && (qsync_mode == SDE_RM_QSYNC_CONTINUOUS_MODE)) {
  964. u32 qsync_min_fps = 0;
  965. ktime_t qsync_time_ns;
  966. ktime_t qsync_l_bound_ns, qsync_u_bound_ns;
  967. u32 default_fps = drm_mode_vrefresh(mode);
  968. ktime_t default_time_ns;
  969. ktime_t default_line_time_ns;
  970. ktime_t extra_time_ns;
  971. u32 yres = mode->vtotal;
  972. if (phys_enc->parent_ops.get_qsync_fps)
  973. phys_enc->parent_ops.get_qsync_fps(phys_enc->parent, &qsync_min_fps,
  974. conn->state);
  975. if (!qsync_min_fps || !default_fps || !yres) {
  976. SDE_ERROR_CMDENC(cmd_enc,
  977. "wrong qsync params %d %d %d\n",
  978. qsync_min_fps, default_fps, yres);
  979. goto exit;
  980. }
  981. if (qsync_min_fps >= default_fps) {
  982. SDE_ERROR_CMDENC(cmd_enc,
  983. "qsync fps:%d must be less than default:%d\n",
  984. qsync_min_fps, default_fps);
  985. goto exit;
  986. }
  987. /*
  988. * Calculate safe qsync trigger window by compensating
  989. * the qsync timeout period by panel jitter value.
  990. *
  991. * qsync_safe_window_period = qsync_timeout_period * (1 - jitter) - nominal_period
  992. * nominal_line_time = nominal_period / vtotal
  993. * qsync_safe_window_lines = qsync_safe_window_period / nominal_line_time
  994. */
  995. qsync_time_ns = mult_frac(1000000000, 1, qsync_min_fps);
  996. default_time_ns = mult_frac(1000000000, 1, default_fps);
  997. sde_encoder_helper_get_jitter_bounds_ns(qsync_min_fps, info->jitter_numer,
  998. info->jitter_denom, &qsync_l_bound_ns, &qsync_u_bound_ns);
  999. if (!qsync_l_bound_ns || !qsync_u_bound_ns)
  1000. qsync_l_bound_ns = qsync_u_bound_ns = qsync_time_ns;
  1001. extra_time_ns = qsync_l_bound_ns - default_time_ns;
  1002. default_line_time_ns = mult_frac(1, default_time_ns, yres);
  1003. threshold_lines = mult_frac(1, extra_time_ns, default_line_time_ns);
  1004. /* some DDICs express the timeout value in lines/4, round down to compensate */
  1005. adjusted_threshold_lines = round_down(threshold_lines, 4);
  1006. /* remove 2 lines to cover for latency */
  1007. if (adjusted_threshold_lines - 2 > DEFAULT_TEARCHECK_SYNC_THRESH_START)
  1008. adjusted_threshold_lines -= 2;
  1009. SDE_DEBUG_CMDENC(cmd_enc,
  1010. "qsync mode:%u min_fps:%u time:%lld low:%lld up:%lld jitter:%u/%u\n",
  1011. qsync_mode, qsync_min_fps, qsync_time_ns, qsync_l_bound_ns,
  1012. qsync_u_bound_ns, info->jitter_numer, info->jitter_denom);
  1013. SDE_DEBUG_CMDENC(cmd_enc,
  1014. "default fps:%u time:%lld yres:%u line_time:%lld\n",
  1015. default_fps, default_time_ns, yres, default_line_time_ns);
  1016. SDE_DEBUG_CMDENC(cmd_enc,
  1017. "extra_time:%lld threshold_lines:%u adjusted_threshold_lines:%u\n",
  1018. extra_time_ns, threshold_lines, adjusted_threshold_lines);
  1019. SDE_EVT32(qsync_mode, qsync_min_fps, default_fps, info->jitter_numer,
  1020. info->jitter_denom, yres, extra_time_ns, default_line_time_ns,
  1021. adjusted_threshold_lines);
  1022. }
  1023. exit:
  1024. return adjusted_threshold_lines;
  1025. }
  1026. static void sde_encoder_phys_cmd_tearcheck_config(
  1027. struct sde_encoder_phys *phys_enc)
  1028. {
  1029. struct sde_encoder_phys_cmd *cmd_enc =
  1030. to_sde_encoder_phys_cmd(phys_enc);
  1031. struct sde_hw_tear_check tc_cfg = { 0 };
  1032. struct drm_display_mode *mode;
  1033. bool tc_enable = true;
  1034. u32 vsync_hz;
  1035. int vrefresh;
  1036. struct msm_drm_private *priv;
  1037. struct sde_kms *sde_kms;
  1038. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf) {
  1039. SDE_ERROR("invalid encoder\n");
  1040. return;
  1041. }
  1042. mode = &phys_enc->cached_mode;
  1043. SDE_DEBUG_CMDENC(cmd_enc, "pp %d, intf %d\n",
  1044. phys_enc->hw_pp->idx - PINGPONG_0,
  1045. phys_enc->hw_intf->idx - INTF_0);
  1046. if (phys_enc->has_intf_te) {
  1047. if (!phys_enc->hw_intf->ops.setup_tearcheck ||
  1048. !phys_enc->hw_intf->ops.enable_tearcheck) {
  1049. SDE_DEBUG_CMDENC(cmd_enc, "tearcheck not supported\n");
  1050. return;
  1051. }
  1052. } else {
  1053. if (!phys_enc->hw_pp->ops.setup_tearcheck ||
  1054. !phys_enc->hw_pp->ops.enable_tearcheck) {
  1055. SDE_DEBUG_CMDENC(cmd_enc, "tearcheck not supported\n");
  1056. return;
  1057. }
  1058. }
  1059. sde_kms = phys_enc->sde_kms;
  1060. if (!sde_kms || !sde_kms->dev || !sde_kms->dev->dev_private) {
  1061. SDE_ERROR("invalid device\n");
  1062. return;
  1063. }
  1064. priv = sde_kms->dev->dev_private;
  1065. vrefresh = drm_mode_vrefresh(mode);
  1066. /*
  1067. * TE default: dsi byte clock calculated base on 70 fps;
  1068. * around 14 ms to complete a kickoff cycle if te disabled;
  1069. * vclk_line base on 60 fps; write is faster than read;
  1070. * init == start == rdptr;
  1071. *
  1072. * vsync_count is ratio of MDP VSYNC clock frequency to LCD panel
  1073. * frequency divided by the no. of rows (lines) in the LCDpanel.
  1074. */
  1075. vsync_hz = sde_power_clk_get_rate(&priv->phandle, "vsync_clk");
  1076. if (!vsync_hz || !mode->vtotal || !vrefresh) {
  1077. SDE_DEBUG_CMDENC(cmd_enc,
  1078. "invalid params - vsync_hz %u vtot %u vrefresh %u\n",
  1079. vsync_hz, mode->vtotal, vrefresh);
  1080. return;
  1081. }
  1082. tc_cfg.vsync_count = vsync_hz / (mode->vtotal * vrefresh);
  1083. /* enable external TE after kickoff to avoid premature autorefresh */
  1084. tc_cfg.hw_vsync_mode = 0;
  1085. /*
  1086. * By setting sync_cfg_height to near max register value, we essentially
  1087. * disable sde hw generated TE signal, since hw TE will arrive first.
  1088. * Only caveat is if due to error, we hit wrap-around.
  1089. */
  1090. if (phys_enc->hw_intf->ops.is_te_32bit_supported
  1091. && phys_enc->hw_intf->ops.is_te_32bit_supported(phys_enc->hw_intf))
  1092. tc_cfg.sync_cfg_height = 0xFFFFFFF0;
  1093. else
  1094. tc_cfg.sync_cfg_height = 0xFFF0;
  1095. tc_cfg.vsync_init_val = mode->vdisplay;
  1096. tc_cfg.sync_threshold_start = _get_tearcheck_threshold(phys_enc);
  1097. tc_cfg.sync_threshold_continue = DEFAULT_TEARCHECK_SYNC_THRESH_CONTINUE;
  1098. tc_cfg.start_pos = mode->vdisplay;
  1099. tc_cfg.rd_ptr_irq = mode->vdisplay + 1;
  1100. tc_cfg.wr_ptr_irq = 1;
  1101. cmd_enc->qsync_threshold_lines = tc_cfg.sync_threshold_start;
  1102. SDE_DEBUG_CMDENC(cmd_enc,
  1103. "tc %d intf %d vsync_clk_speed_hz %u vtotal %u vrefresh %u\n",
  1104. phys_enc->hw_pp->idx - PINGPONG_0,
  1105. phys_enc->hw_intf->idx - INTF_0,
  1106. vsync_hz, mode->vtotal, vrefresh);
  1107. SDE_DEBUG_CMDENC(cmd_enc,
  1108. "tc %d intf %d enable %u start_pos %u rd_ptr_irq %u wr_ptr_irq %u\n",
  1109. phys_enc->hw_pp->idx - PINGPONG_0,
  1110. phys_enc->hw_intf->idx - INTF_0,
  1111. tc_enable, tc_cfg.start_pos, tc_cfg.rd_ptr_irq,
  1112. tc_cfg.wr_ptr_irq);
  1113. SDE_DEBUG_CMDENC(cmd_enc,
  1114. "tc %d intf %d hw_vsync_mode %u vsync_count %u vsync_init_val %u\n",
  1115. phys_enc->hw_pp->idx - PINGPONG_0,
  1116. phys_enc->hw_intf->idx - INTF_0,
  1117. tc_cfg.hw_vsync_mode, tc_cfg.vsync_count,
  1118. tc_cfg.vsync_init_val);
  1119. SDE_DEBUG_CMDENC(cmd_enc,
  1120. "tc %d intf %d cfgheight %u thresh_start %u thresh_cont %u\n",
  1121. phys_enc->hw_pp->idx - PINGPONG_0,
  1122. phys_enc->hw_intf->idx - INTF_0,
  1123. tc_cfg.sync_cfg_height,
  1124. tc_cfg.sync_threshold_start, tc_cfg.sync_threshold_continue);
  1125. SDE_EVT32(phys_enc->hw_pp->idx - PINGPONG_0, phys_enc->hw_intf->idx - INTF_0,
  1126. vsync_hz, mode->vtotal, vrefresh);
  1127. SDE_EVT32(tc_enable, tc_cfg.start_pos, tc_cfg.rd_ptr_irq, tc_cfg.wr_ptr_irq,
  1128. tc_cfg.hw_vsync_mode, tc_cfg.vsync_count, tc_cfg.vsync_init_val,
  1129. tc_cfg.sync_cfg_height, tc_cfg.sync_threshold_start,
  1130. tc_cfg.sync_threshold_continue);
  1131. if (phys_enc->has_intf_te) {
  1132. phys_enc->hw_intf->ops.setup_tearcheck(phys_enc->hw_intf,
  1133. &tc_cfg);
  1134. phys_enc->hw_intf->ops.enable_tearcheck(phys_enc->hw_intf,
  1135. tc_enable);
  1136. } else {
  1137. phys_enc->hw_pp->ops.setup_tearcheck(phys_enc->hw_pp, &tc_cfg);
  1138. phys_enc->hw_pp->ops.enable_tearcheck(phys_enc->hw_pp,
  1139. tc_enable);
  1140. }
  1141. }
  1142. static void _sde_encoder_phys_cmd_pingpong_config(
  1143. struct sde_encoder_phys *phys_enc)
  1144. {
  1145. struct sde_encoder_phys_cmd *cmd_enc =
  1146. to_sde_encoder_phys_cmd(phys_enc);
  1147. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->hw_pp) {
  1148. SDE_ERROR("invalid arg(s), enc %d\n", !phys_enc);
  1149. return;
  1150. }
  1151. SDE_DEBUG_CMDENC(cmd_enc, "pp %d, enabling mode:\n",
  1152. phys_enc->hw_pp->idx - PINGPONG_0);
  1153. drm_mode_debug_printmodeline(&phys_enc->cached_mode);
  1154. if (!_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  1155. _sde_encoder_phys_cmd_update_intf_cfg(phys_enc);
  1156. sde_encoder_phys_cmd_tearcheck_config(phys_enc);
  1157. }
  1158. static void sde_encoder_phys_cmd_enable_helper(
  1159. struct sde_encoder_phys *phys_enc)
  1160. {
  1161. struct sde_encoder_virt *sde_enc;
  1162. struct sde_hw_intf *hw_intf;
  1163. u32 qsync_mode;
  1164. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->hw_pp ||
  1165. !phys_enc->hw_intf) {
  1166. SDE_ERROR("invalid arg(s), encoder %d\n", !phys_enc);
  1167. return;
  1168. }
  1169. sde_encoder_helper_split_config(phys_enc, phys_enc->intf_idx);
  1170. _sde_encoder_phys_cmd_pingpong_config(phys_enc);
  1171. hw_intf = phys_enc->hw_intf;
  1172. if (hw_intf->ops.enable_compressed_input)
  1173. hw_intf->ops.enable_compressed_input(phys_enc->hw_intf,
  1174. (phys_enc->comp_type !=
  1175. MSM_DISPLAY_COMPRESSION_NONE), false);
  1176. if (hw_intf->ops.enable_wide_bus)
  1177. hw_intf->ops.enable_wide_bus(hw_intf,
  1178. sde_encoder_is_widebus_enabled(phys_enc->parent));
  1179. /*
  1180. * Override internal rd_ptr value when coming out of IPC.
  1181. * This is required on QSYNC panel with low refresh rate to
  1182. * avoid out of sync frame trigger as panel rd_ptr was still
  1183. * incrementing while MDP was power collapsed.
  1184. */
  1185. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  1186. if (sde_enc->idle_pc_restore) {
  1187. qsync_mode = sde_connector_get_qsync_mode(phys_enc->connector);
  1188. if (qsync_mode)
  1189. sde_enc->restore_te_rd_ptr = true;
  1190. }
  1191. /*
  1192. * For pp-split, skip setting the flush bit for the slave intf, since
  1193. * both intfs use same ctl and HW will only flush the master.
  1194. */
  1195. if (_sde_encoder_phys_is_ppsplit(phys_enc) &&
  1196. !sde_encoder_phys_cmd_is_master(phys_enc))
  1197. goto skip_flush;
  1198. _sde_encoder_phys_cmd_update_flush_mask(phys_enc);
  1199. skip_flush:
  1200. return;
  1201. }
  1202. static void sde_encoder_phys_cmd_enable(struct sde_encoder_phys *phys_enc)
  1203. {
  1204. struct sde_encoder_phys_cmd *cmd_enc =
  1205. to_sde_encoder_phys_cmd(phys_enc);
  1206. if (!phys_enc || !phys_enc->hw_pp) {
  1207. SDE_ERROR("invalid phys encoder\n");
  1208. return;
  1209. }
  1210. SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", phys_enc->hw_pp->idx - PINGPONG_0);
  1211. if (phys_enc->enable_state == SDE_ENC_ENABLED) {
  1212. if (!phys_enc->cont_splash_enabled)
  1213. SDE_ERROR("already enabled\n");
  1214. return;
  1215. }
  1216. sde_encoder_phys_cmd_enable_helper(phys_enc);
  1217. phys_enc->enable_state = SDE_ENC_ENABLED;
  1218. }
  1219. static bool sde_encoder_phys_cmd_is_autorefresh_enabled(
  1220. struct sde_encoder_phys *phys_enc)
  1221. {
  1222. struct sde_hw_pingpong *hw_pp;
  1223. struct sde_hw_intf *hw_intf;
  1224. struct sde_hw_autorefresh cfg;
  1225. int ret;
  1226. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  1227. return false;
  1228. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  1229. return false;
  1230. if (phys_enc->has_intf_te) {
  1231. hw_intf = phys_enc->hw_intf;
  1232. if (!hw_intf->ops.get_autorefresh)
  1233. return false;
  1234. ret = hw_intf->ops.get_autorefresh(hw_intf, &cfg);
  1235. } else {
  1236. hw_pp = phys_enc->hw_pp;
  1237. if (!hw_pp->ops.get_autorefresh)
  1238. return false;
  1239. ret = hw_pp->ops.get_autorefresh(hw_pp, &cfg);
  1240. }
  1241. return ret ? false : cfg.enable;
  1242. }
  1243. static void sde_encoder_phys_cmd_connect_te(
  1244. struct sde_encoder_phys *phys_enc, bool enable)
  1245. {
  1246. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  1247. return;
  1248. if (phys_enc->has_intf_te &&
  1249. phys_enc->hw_intf->ops.connect_external_te)
  1250. phys_enc->hw_intf->ops.connect_external_te(phys_enc->hw_intf,
  1251. enable);
  1252. else if (phys_enc->hw_pp->ops.connect_external_te)
  1253. phys_enc->hw_pp->ops.connect_external_te(phys_enc->hw_pp,
  1254. enable);
  1255. else
  1256. return;
  1257. SDE_EVT32(DRMID(phys_enc->parent), enable);
  1258. }
  1259. static int sde_encoder_phys_cmd_te_get_line_count(
  1260. struct sde_encoder_phys *phys_enc)
  1261. {
  1262. struct sde_hw_pingpong *hw_pp;
  1263. struct sde_hw_intf *hw_intf;
  1264. u32 line_count;
  1265. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  1266. return -EINVAL;
  1267. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  1268. return -EINVAL;
  1269. if (phys_enc->has_intf_te) {
  1270. hw_intf = phys_enc->hw_intf;
  1271. if (!hw_intf->ops.get_line_count)
  1272. return -EINVAL;
  1273. line_count = hw_intf->ops.get_line_count(hw_intf);
  1274. } else {
  1275. hw_pp = phys_enc->hw_pp;
  1276. if (!hw_pp->ops.get_line_count)
  1277. return -EINVAL;
  1278. line_count = hw_pp->ops.get_line_count(hw_pp);
  1279. }
  1280. return line_count;
  1281. }
  1282. static void sde_encoder_phys_cmd_disable(struct sde_encoder_phys *phys_enc)
  1283. {
  1284. struct sde_encoder_phys_cmd *cmd_enc =
  1285. to_sde_encoder_phys_cmd(phys_enc);
  1286. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf) {
  1287. SDE_ERROR("invalid encoder\n");
  1288. return;
  1289. }
  1290. SDE_DEBUG_CMDENC(cmd_enc, "pp %d intf %d state %d\n",
  1291. phys_enc->hw_pp->idx - PINGPONG_0,
  1292. phys_enc->hw_intf->idx - INTF_0,
  1293. phys_enc->enable_state);
  1294. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  1295. phys_enc->hw_intf->idx - INTF_0,
  1296. phys_enc->enable_state);
  1297. if (phys_enc->enable_state == SDE_ENC_DISABLED) {
  1298. SDE_ERROR_CMDENC(cmd_enc, "already disabled\n");
  1299. return;
  1300. }
  1301. if (!sde_in_trusted_vm(phys_enc->sde_kms)) {
  1302. if (phys_enc->has_intf_te &&
  1303. phys_enc->hw_intf->ops.enable_tearcheck)
  1304. phys_enc->hw_intf->ops.enable_tearcheck(
  1305. phys_enc->hw_intf,
  1306. false);
  1307. else if (phys_enc->hw_pp->ops.enable_tearcheck)
  1308. phys_enc->hw_pp->ops.enable_tearcheck(phys_enc->hw_pp,
  1309. false);
  1310. if (sde_encoder_phys_cmd_is_master(phys_enc))
  1311. sde_encoder_helper_phys_disable(phys_enc, NULL);
  1312. if (phys_enc->hw_intf->ops.reset_counter)
  1313. phys_enc->hw_intf->ops.reset_counter(phys_enc->hw_intf);
  1314. }
  1315. memset(&cmd_enc->autorefresh.cfg, 0, sizeof(struct sde_hw_autorefresh));
  1316. phys_enc->enable_state = SDE_ENC_DISABLED;
  1317. }
  1318. static void sde_encoder_phys_cmd_destroy(struct sde_encoder_phys *phys_enc)
  1319. {
  1320. struct sde_encoder_phys_cmd *cmd_enc =
  1321. to_sde_encoder_phys_cmd(phys_enc);
  1322. if (!phys_enc) {
  1323. SDE_ERROR("invalid encoder\n");
  1324. return;
  1325. }
  1326. kfree(cmd_enc);
  1327. }
  1328. static void sde_encoder_phys_cmd_get_hw_resources(
  1329. struct sde_encoder_phys *phys_enc,
  1330. struct sde_encoder_hw_resources *hw_res,
  1331. struct drm_connector_state *conn_state)
  1332. {
  1333. struct sde_encoder_phys_cmd *cmd_enc =
  1334. to_sde_encoder_phys_cmd(phys_enc);
  1335. if (!phys_enc) {
  1336. SDE_ERROR("invalid encoder\n");
  1337. return;
  1338. }
  1339. if ((phys_enc->intf_idx - INTF_0) >= INTF_MAX) {
  1340. SDE_ERROR("invalid intf idx:%d\n", phys_enc->intf_idx);
  1341. return;
  1342. }
  1343. SDE_DEBUG_CMDENC(cmd_enc, "\n");
  1344. hw_res->intfs[phys_enc->intf_idx - INTF_0] = INTF_MODE_CMD;
  1345. }
  1346. static int sde_encoder_phys_cmd_prepare_for_kickoff(
  1347. struct sde_encoder_phys *phys_enc,
  1348. struct sde_encoder_kickoff_params *params)
  1349. {
  1350. struct sde_hw_tear_check tc_cfg = {0};
  1351. struct sde_encoder_phys_cmd *cmd_enc =
  1352. to_sde_encoder_phys_cmd(phys_enc);
  1353. struct sde_encoder_virt *sde_enc;
  1354. int ret = 0;
  1355. bool recovery_events;
  1356. if (!phys_enc || !phys_enc->hw_pp) {
  1357. SDE_ERROR("invalid encoder\n");
  1358. return -EINVAL;
  1359. }
  1360. SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", phys_enc->hw_pp->idx - PINGPONG_0);
  1361. phys_enc->frame_trigger_mode = params->frame_trigger_mode;
  1362. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  1363. atomic_read(&phys_enc->pending_kickoff_cnt),
  1364. atomic_read(&cmd_enc->autorefresh.kickoff_cnt),
  1365. phys_enc->frame_trigger_mode);
  1366. if (phys_enc->frame_trigger_mode == FRAME_DONE_WAIT_DEFAULT) {
  1367. /*
  1368. * Mark kickoff request as outstanding. If there are more
  1369. * than one outstanding frame, then we have to wait for the
  1370. * previous frame to complete
  1371. */
  1372. ret = _sde_encoder_phys_cmd_wait_for_idle(phys_enc);
  1373. if (ret) {
  1374. atomic_set(&phys_enc->pending_kickoff_cnt, 0);
  1375. SDE_EVT32(DRMID(phys_enc->parent),
  1376. phys_enc->hw_pp->idx - PINGPONG_0);
  1377. SDE_ERROR("failed wait_for_idle: %d\n", ret);
  1378. }
  1379. }
  1380. if (phys_enc->recovered) {
  1381. recovery_events = sde_encoder_recovery_events_enabled(
  1382. phys_enc->parent);
  1383. if (cmd_enc->frame_tx_timeout_report_cnt && recovery_events)
  1384. sde_connector_event_notify(phys_enc->connector,
  1385. DRM_EVENT_SDE_HW_RECOVERY,
  1386. sizeof(uint8_t),
  1387. SDE_RECOVERY_SUCCESS);
  1388. cmd_enc->frame_tx_timeout_report_cnt = 0;
  1389. phys_enc->recovered = false;
  1390. }
  1391. if (sde_connector_is_qsync_updated(phys_enc->connector)) {
  1392. tc_cfg.sync_threshold_start = _get_tearcheck_threshold(
  1393. phys_enc);
  1394. cmd_enc->qsync_threshold_lines = tc_cfg.sync_threshold_start;
  1395. if (phys_enc->has_intf_te &&
  1396. phys_enc->hw_intf->ops.update_tearcheck)
  1397. phys_enc->hw_intf->ops.update_tearcheck(
  1398. phys_enc->hw_intf, &tc_cfg);
  1399. else if (phys_enc->hw_pp->ops.update_tearcheck)
  1400. phys_enc->hw_pp->ops.update_tearcheck(
  1401. phys_enc->hw_pp, &tc_cfg);
  1402. SDE_EVT32(DRMID(phys_enc->parent), tc_cfg.sync_threshold_start);
  1403. }
  1404. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  1405. if (sde_enc->restore_te_rd_ptr) {
  1406. sde_encoder_restore_tearcheck_rd_ptr(phys_enc);
  1407. sde_enc->restore_te_rd_ptr = false;
  1408. }
  1409. SDE_DEBUG_CMDENC(cmd_enc, "pp:%d pending_cnt %d\n",
  1410. phys_enc->hw_pp->idx - PINGPONG_0,
  1411. atomic_read(&phys_enc->pending_kickoff_cnt));
  1412. return ret;
  1413. }
  1414. static bool _sde_encoder_phys_cmd_needs_vsync_change(
  1415. struct sde_encoder_phys *phys_enc, ktime_t profile_timestamp)
  1416. {
  1417. struct sde_encoder_virt *sde_enc;
  1418. struct sde_encoder_phys_cmd *cmd_enc;
  1419. struct sde_encoder_phys_cmd_te_timestamp *cur;
  1420. struct sde_encoder_phys_cmd_te_timestamp *prev = NULL;
  1421. ktime_t time_diff;
  1422. struct msm_mode_info *info;
  1423. ktime_t l_bound = 0, u_bound = 0;
  1424. bool ret = false;
  1425. unsigned long lock_flags;
  1426. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1427. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  1428. info = &sde_enc->mode_info;
  1429. sde_encoder_helper_get_jitter_bounds_ns(info->frame_rate, info->jitter_numer,
  1430. info->jitter_denom, &l_bound, &u_bound);
  1431. if (!l_bound || !u_bound) {
  1432. SDE_ERROR_CMDENC(cmd_enc, "invalid vsync jitter bounds\n");
  1433. return false;
  1434. }
  1435. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  1436. list_for_each_entry_reverse(cur, &cmd_enc->te_timestamp_list, list) {
  1437. if (prev && ktime_after(cur->timestamp, profile_timestamp)) {
  1438. time_diff = ktime_sub(prev->timestamp, cur->timestamp);
  1439. if ((time_diff < l_bound) || (time_diff > u_bound)) {
  1440. ret = true;
  1441. break;
  1442. }
  1443. }
  1444. prev = cur;
  1445. }
  1446. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  1447. if (ret) {
  1448. SDE_DEBUG_CMDENC(cmd_enc,
  1449. "time_diff:%llu, prev:%llu, cur:%llu, jitter:%llu/%llu\n",
  1450. time_diff, prev->timestamp, cur->timestamp,
  1451. l_bound, u_bound);
  1452. time_diff = div_s64(time_diff, 1000);
  1453. SDE_EVT32(DRMID(phys_enc->parent),
  1454. (u32) (do_div(l_bound, 1000)),
  1455. (u32) (do_div(u_bound, 1000)),
  1456. (u32) (time_diff), SDE_EVTLOG_ERROR);
  1457. }
  1458. return ret;
  1459. }
  1460. static int _sde_encoder_phys_cmd_wait_for_wr_ptr(
  1461. struct sde_encoder_phys *phys_enc)
  1462. {
  1463. struct sde_encoder_phys_cmd *cmd_enc =
  1464. to_sde_encoder_phys_cmd(phys_enc);
  1465. struct sde_encoder_wait_info wait_info = {0};
  1466. struct sde_connector *c_conn;
  1467. bool frame_pending = true;
  1468. struct sde_hw_ctl *ctl;
  1469. unsigned long lock_flags;
  1470. int ret, timeout_ms;
  1471. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->connector) {
  1472. SDE_ERROR("invalid argument(s)\n");
  1473. return -EINVAL;
  1474. }
  1475. ctl = phys_enc->hw_ctl;
  1476. c_conn = to_sde_connector(phys_enc->connector);
  1477. timeout_ms = phys_enc->kickoff_timeout_ms;
  1478. if (c_conn->lp_mode == SDE_MODE_DPMS_LP1 ||
  1479. c_conn->lp_mode == SDE_MODE_DPMS_LP2)
  1480. timeout_ms = timeout_ms * 2;
  1481. wait_info.wq = &phys_enc->pending_kickoff_wq;
  1482. wait_info.atomic_cnt = &phys_enc->pending_retire_fence_cnt;
  1483. wait_info.timeout_ms = timeout_ms;
  1484. /* slave encoder doesn't enable for ppsplit */
  1485. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  1486. return 0;
  1487. ret = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_WRPTR,
  1488. &wait_info);
  1489. /*
  1490. * if hwfencing enabled, try again to wait for up to the extended timeout time in
  1491. * increments as long as fence has not been signaled.
  1492. */
  1493. if (ret == -ETIMEDOUT && phys_enc->sde_kms->catalog->hw_fence_rev)
  1494. ret = sde_encoder_helper_hw_fence_extended_wait(phys_enc, ctl, &wait_info,
  1495. INTR_IDX_WRPTR);
  1496. if (ret == -ETIMEDOUT) {
  1497. struct sde_hw_ctl *ctl = phys_enc->hw_ctl;
  1498. if (ctl && ctl->ops.get_start_state)
  1499. frame_pending = ctl->ops.get_start_state(ctl);
  1500. ret = (frame_pending || sde_connector_esd_status(phys_enc->connector)) ? ret : 0;
  1501. /*
  1502. * There can be few cases of ESD where CTL_START is cleared but
  1503. * wr_ptr irq doesn't come. Signaling retire fence in these
  1504. * cases to avoid freeze and dangling pending_retire_fence_cnt
  1505. */
  1506. if (!ret) {
  1507. SDE_EVT32(DRMID(phys_enc->parent),
  1508. SDE_EVTLOG_FUNC_CASE1);
  1509. if (sde_encoder_phys_cmd_is_master(phys_enc) &&
  1510. atomic_add_unless(
  1511. &phys_enc->pending_retire_fence_cnt, -1, 0)) {
  1512. spin_lock_irqsave(phys_enc->enc_spinlock,
  1513. lock_flags);
  1514. phys_enc->parent_ops.handle_frame_done(
  1515. phys_enc->parent, phys_enc,
  1516. SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE);
  1517. spin_unlock_irqrestore(phys_enc->enc_spinlock,
  1518. lock_flags);
  1519. }
  1520. }
  1521. /* if we timeout after the extended wait, reset mixers and do sw override */
  1522. if (ret && phys_enc->sde_kms->catalog->hw_fence_rev)
  1523. sde_encoder_helper_hw_fence_sw_override(phys_enc, ctl);
  1524. }
  1525. cmd_enc->wr_ptr_wait_success = (ret == 0) ? true : false;
  1526. return ret;
  1527. }
  1528. static int sde_encoder_phys_cmd_wait_for_tx_complete(
  1529. struct sde_encoder_phys *phys_enc)
  1530. {
  1531. int rc;
  1532. struct sde_encoder_phys_cmd *cmd_enc;
  1533. if (!phys_enc)
  1534. return -EINVAL;
  1535. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1536. if (sde_encoder_check_ctl_done_support(phys_enc->parent)
  1537. && !sde_encoder_phys_cmd_is_master(phys_enc))
  1538. return 0;
  1539. if (!atomic_read(&phys_enc->pending_kickoff_cnt)) {
  1540. SDE_EVT32(DRMID(phys_enc->parent),
  1541. phys_enc->intf_idx - INTF_0,
  1542. phys_enc->enable_state);
  1543. return 0;
  1544. }
  1545. rc = _sde_encoder_phys_cmd_wait_for_idle(phys_enc);
  1546. if (rc) {
  1547. SDE_EVT32(DRMID(phys_enc->parent),
  1548. phys_enc->intf_idx - INTF_0);
  1549. SDE_ERROR("failed wait_for_idle: %d\n", rc);
  1550. }
  1551. return rc;
  1552. }
  1553. static int _sde_encoder_phys_cmd_handle_wr_ptr_timeout(
  1554. struct sde_encoder_phys *phys_enc,
  1555. ktime_t profile_timestamp)
  1556. {
  1557. struct sde_encoder_phys_cmd *cmd_enc =
  1558. to_sde_encoder_phys_cmd(phys_enc);
  1559. bool switch_te;
  1560. int ret = -ETIMEDOUT;
  1561. unsigned long lock_flags;
  1562. switch_te = _sde_encoder_phys_cmd_needs_vsync_change(
  1563. phys_enc, profile_timestamp);
  1564. SDE_EVT32(DRMID(phys_enc->parent), switch_te, SDE_EVTLOG_FUNC_ENTRY);
  1565. if (sde_connector_panel_dead(phys_enc->connector)) {
  1566. ret = _sde_encoder_phys_cmd_wait_for_wr_ptr(phys_enc);
  1567. } else if (switch_te) {
  1568. SDE_DEBUG_CMDENC(cmd_enc,
  1569. "wr_ptr_irq wait failed, retry with WD TE\n");
  1570. /* switch to watchdog TE and wait again */
  1571. sde_encoder_helper_switch_vsync(phys_enc->parent, true);
  1572. ret = _sde_encoder_phys_cmd_wait_for_wr_ptr(phys_enc);
  1573. /* switch back to default TE */
  1574. sde_encoder_helper_switch_vsync(phys_enc->parent, false);
  1575. }
  1576. /*
  1577. * Signaling the retire fence at wr_ptr timeout
  1578. * to allow the next commit and avoid device freeze.
  1579. */
  1580. if (ret == -ETIMEDOUT) {
  1581. SDE_ERROR_CMDENC(cmd_enc,
  1582. "wr_ptr_irq wait failed, switch_te:%d\n", switch_te);
  1583. SDE_EVT32(DRMID(phys_enc->parent), switch_te, SDE_EVTLOG_ERROR);
  1584. if (sde_encoder_phys_cmd_is_master(phys_enc) &&
  1585. atomic_add_unless(
  1586. &phys_enc->pending_retire_fence_cnt, -1, 0)) {
  1587. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  1588. phys_enc->parent_ops.handle_frame_done(
  1589. phys_enc->parent, phys_enc,
  1590. SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE);
  1591. spin_unlock_irqrestore(phys_enc->enc_spinlock,
  1592. lock_flags);
  1593. }
  1594. }
  1595. cmd_enc->wr_ptr_wait_success = (ret == 0) ? true : false;
  1596. return ret;
  1597. }
  1598. static int sde_encoder_phys_cmd_wait_for_commit_done(
  1599. struct sde_encoder_phys *phys_enc)
  1600. {
  1601. int rc = 0, i, pending_cnt;
  1602. struct sde_encoder_phys_cmd *cmd_enc;
  1603. ktime_t profile_timestamp = ktime_get();
  1604. u32 scheduler_status = INVALID_CTL_STATUS;
  1605. struct sde_hw_ctl *ctl;
  1606. if (!phys_enc)
  1607. return -EINVAL;
  1608. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1609. if (sde_encoder_check_ctl_done_support(phys_enc->parent)
  1610. && !sde_encoder_phys_cmd_is_master(phys_enc))
  1611. return 0;
  1612. /* only required for master controller */
  1613. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  1614. rc = _sde_encoder_phys_cmd_wait_for_wr_ptr(phys_enc);
  1615. if (rc == -ETIMEDOUT) {
  1616. /*
  1617. * Profile all the TE received after profile_timestamp
  1618. * and if the jitter is more, switch to watchdog TE
  1619. * and wait for wr_ptr again. Finally move back to
  1620. * default TE.
  1621. */
  1622. rc = _sde_encoder_phys_cmd_handle_wr_ptr_timeout(
  1623. phys_enc, profile_timestamp);
  1624. if (rc == -ETIMEDOUT)
  1625. goto wait_for_idle;
  1626. }
  1627. if (cmd_enc->autorefresh.cfg.enable)
  1628. rc = _sde_encoder_phys_cmd_wait_for_autorefresh_done(
  1629. phys_enc);
  1630. ctl = phys_enc->hw_ctl;
  1631. if (ctl && ctl->ops.get_scheduler_status)
  1632. scheduler_status = ctl->ops.get_scheduler_status(ctl);
  1633. }
  1634. /* wait for posted start or serialize trigger */
  1635. pending_cnt = atomic_read(&phys_enc->pending_kickoff_cnt);
  1636. if ((pending_cnt > 1) ||
  1637. (pending_cnt && (scheduler_status & BIT(0))) ||
  1638. (!rc && phys_enc->frame_trigger_mode == FRAME_DONE_WAIT_SERIALIZE))
  1639. goto wait_for_idle;
  1640. return rc;
  1641. wait_for_idle:
  1642. pending_cnt = atomic_read(&phys_enc->pending_kickoff_cnt);
  1643. for (i = 0; i < pending_cnt; i++)
  1644. rc |= sde_encoder_wait_for_event(phys_enc->parent,
  1645. MSM_ENC_TX_COMPLETE);
  1646. if (rc) {
  1647. SDE_EVT32(DRMID(phys_enc->parent),
  1648. phys_enc->hw_pp->idx - PINGPONG_0,
  1649. phys_enc->frame_trigger_mode,
  1650. atomic_read(&phys_enc->pending_kickoff_cnt),
  1651. phys_enc->enable_state,
  1652. cmd_enc->wr_ptr_wait_success, scheduler_status, rc);
  1653. SDE_ERROR("pp:%d failed wait_for_idle: %d\n",
  1654. phys_enc->hw_pp->idx - PINGPONG_0, rc);
  1655. if (phys_enc->enable_state == SDE_ENC_ERR_NEEDS_HW_RESET)
  1656. sde_encoder_needs_hw_reset(phys_enc->parent);
  1657. }
  1658. return rc;
  1659. }
  1660. static int sde_encoder_phys_cmd_wait_for_vblank(
  1661. struct sde_encoder_phys *phys_enc)
  1662. {
  1663. int rc = 0;
  1664. struct sde_encoder_phys_cmd *cmd_enc;
  1665. struct sde_encoder_wait_info wait_info = {0};
  1666. if (!phys_enc)
  1667. return -EINVAL;
  1668. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1669. /* only required for master controller */
  1670. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  1671. return rc;
  1672. wait_info.wq = &cmd_enc->pending_vblank_wq;
  1673. wait_info.atomic_cnt = &cmd_enc->pending_vblank_cnt;
  1674. wait_info.timeout_ms = _sde_encoder_phys_cmd_get_idle_timeout(phys_enc);
  1675. atomic_inc(&cmd_enc->pending_vblank_cnt);
  1676. rc = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_RDPTR,
  1677. &wait_info);
  1678. return rc;
  1679. }
  1680. static void sde_encoder_phys_cmd_update_split_role(
  1681. struct sde_encoder_phys *phys_enc,
  1682. enum sde_enc_split_role role)
  1683. {
  1684. struct sde_encoder_phys_cmd *cmd_enc;
  1685. enum sde_enc_split_role old_role;
  1686. bool is_ppsplit;
  1687. if (!phys_enc)
  1688. return;
  1689. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1690. old_role = phys_enc->split_role;
  1691. is_ppsplit = _sde_encoder_phys_is_ppsplit(phys_enc);
  1692. phys_enc->split_role = role;
  1693. SDE_DEBUG_CMDENC(cmd_enc, "old role %d new role %d\n",
  1694. old_role, role);
  1695. /*
  1696. * ppsplit solo needs to reprogram because intf may have swapped without
  1697. * role changing on left-only, right-only back-to-back commits
  1698. */
  1699. if (!(is_ppsplit && role == ENC_ROLE_SOLO) &&
  1700. (role == old_role || role == ENC_ROLE_SKIP))
  1701. return;
  1702. sde_encoder_helper_split_config(phys_enc, phys_enc->intf_idx);
  1703. _sde_encoder_phys_cmd_pingpong_config(phys_enc);
  1704. _sde_encoder_phys_cmd_update_flush_mask(phys_enc);
  1705. }
  1706. static void _sde_encoder_autorefresh_disable_seq1(
  1707. struct sde_encoder_phys *phys_enc)
  1708. {
  1709. int trial = 0;
  1710. u32 timeout_ms = phys_enc->kickoff_timeout_ms;
  1711. struct sde_encoder_phys_cmd *cmd_enc =
  1712. to_sde_encoder_phys_cmd(phys_enc);
  1713. /*
  1714. * If autorefresh is enabled, disable it and make sure it is safe to
  1715. * proceed with current frame commit/push. Sequence fallowed is,
  1716. * 1. Disable TE & autorefresh - caller will take care of it
  1717. * 2. Poll for frame transfer ongoing to be false
  1718. * 3. Enable TE back - caller will take care of it
  1719. */
  1720. do {
  1721. udelay(AUTOREFRESH_SEQ1_POLL_TIME);
  1722. if ((trial * AUTOREFRESH_SEQ1_POLL_TIME)
  1723. > (timeout_ms * USEC_PER_MSEC)) {
  1724. SDE_ERROR_CMDENC(cmd_enc,
  1725. "disable autorefresh failed\n");
  1726. phys_enc->enable_state = SDE_ENC_ERR_NEEDS_HW_RESET;
  1727. break;
  1728. }
  1729. trial++;
  1730. } while (_sde_encoder_phys_cmd_is_ongoing_pptx(phys_enc));
  1731. }
  1732. static void _sde_encoder_autorefresh_disable_seq2(
  1733. struct sde_encoder_phys *phys_enc)
  1734. {
  1735. int trial = 0;
  1736. struct sde_hw_mdp *hw_mdp = phys_enc->hw_mdptop;
  1737. u32 autorefresh_status = 0;
  1738. struct sde_encoder_phys_cmd *cmd_enc =
  1739. to_sde_encoder_phys_cmd(phys_enc);
  1740. struct intf_tear_status tear_status;
  1741. struct sde_hw_intf *hw_intf = phys_enc->hw_intf;
  1742. if (!hw_mdp->ops.get_autorefresh_status ||
  1743. !hw_intf->ops.check_and_reset_tearcheck) {
  1744. SDE_DEBUG_CMDENC(cmd_enc,
  1745. "autofresh disable seq2 not supported\n");
  1746. return;
  1747. }
  1748. /*
  1749. * If autorefresh is still enabled after sequence-1, proceed with
  1750. * below sequence-2.
  1751. * 1. Disable autorefresh config
  1752. * 2. Run in loop:
  1753. * 2.1 Poll for autorefresh to be disabled
  1754. * 2.2 Log read and write count status
  1755. * 2.3 Replace te write count with start_pos to meet trigger window
  1756. */
  1757. autorefresh_status = hw_mdp->ops.get_autorefresh_status(hw_mdp,
  1758. phys_enc->intf_idx);
  1759. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1760. autorefresh_status, SDE_EVTLOG_FUNC_CASE1);
  1761. if (!(autorefresh_status & BIT(7))) {
  1762. usleep_range(AUTOREFRESH_SEQ2_POLL_TIME,
  1763. AUTOREFRESH_SEQ2_POLL_TIME + 1);
  1764. autorefresh_status = hw_mdp->ops.get_autorefresh_status(hw_mdp,
  1765. phys_enc->intf_idx);
  1766. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1767. autorefresh_status, SDE_EVTLOG_FUNC_CASE2);
  1768. }
  1769. while (autorefresh_status & BIT(7)) {
  1770. if (!trial) {
  1771. pr_err("enc:%d autofresh status:0x%x intf:%d\n", DRMID(phys_enc->parent),
  1772. autorefresh_status, phys_enc->intf_idx - INTF_0);
  1773. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, 0);
  1774. }
  1775. usleep_range(AUTOREFRESH_SEQ2_POLL_TIME,
  1776. AUTOREFRESH_SEQ2_POLL_TIME + 1);
  1777. if ((trial * AUTOREFRESH_SEQ2_POLL_TIME)
  1778. > AUTOREFRESH_SEQ2_POLL_TIMEOUT) {
  1779. SDE_ERROR_CMDENC(cmd_enc,
  1780. "disable autorefresh failed\n");
  1781. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL, "panic");
  1782. break;
  1783. }
  1784. trial++;
  1785. autorefresh_status = hw_mdp->ops.get_autorefresh_status(hw_mdp,
  1786. phys_enc->intf_idx);
  1787. hw_intf->ops.check_and_reset_tearcheck(hw_intf, &tear_status);
  1788. pr_err("enc:%d autofresh status:0x%x intf:%d\n",
  1789. DRMID(phys_enc->parent), autorefresh_status,
  1790. phys_enc->intf_idx - INTF_0);
  1791. pr_err("tear_read_frame_count:%d tear_read_line_count:%d\n",
  1792. tear_status.read_frame_count, tear_status.read_line_count);
  1793. pr_err("tear_write_frame_count:%d tear_write_line_count:%d\n",
  1794. tear_status.write_frame_count, tear_status.write_line_count);
  1795. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0, autorefresh_status,
  1796. tear_status.read_frame_count, tear_status.read_line_count,
  1797. tear_status.write_frame_count, tear_status.write_line_count);
  1798. }
  1799. }
  1800. static void _sde_encoder_phys_disable_autorefresh(struct sde_encoder_phys *phys_enc)
  1801. {
  1802. struct sde_encoder_phys_cmd *cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1803. struct sde_kms *sde_kms;
  1804. if (!phys_enc || !sde_encoder_phys_cmd_is_master(phys_enc))
  1805. return;
  1806. if (!sde_encoder_phys_cmd_is_autorefresh_enabled(phys_enc))
  1807. return;
  1808. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1809. cmd_enc->autorefresh.cfg.enable);
  1810. sde_kms = phys_enc->sde_kms;
  1811. sde_encoder_phys_cmd_connect_te(phys_enc, false);
  1812. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, 0);
  1813. phys_enc->autorefresh_disable_trans = true;
  1814. if (sde_kms && sde_kms->catalog &&
  1815. (sde_kms->catalog->autorefresh_disable_seq == AUTOREFRESH_DISABLE_SEQ1)) {
  1816. _sde_encoder_autorefresh_disable_seq1(phys_enc);
  1817. _sde_encoder_autorefresh_disable_seq2(phys_enc);
  1818. }
  1819. sde_encoder_phys_cmd_connect_te(phys_enc, true);
  1820. SDE_DEBUG_CMDENC(cmd_enc, "autorefresh disabled successfully\n");
  1821. }
  1822. static void sde_encoder_phys_cmd_prepare_commit(struct sde_encoder_phys *phys_enc)
  1823. {
  1824. return _sde_encoder_phys_disable_autorefresh(phys_enc);
  1825. }
  1826. static void sde_encoder_phys_cmd_trigger_start(
  1827. struct sde_encoder_phys *phys_enc)
  1828. {
  1829. struct sde_encoder_phys_cmd *cmd_enc =
  1830. to_sde_encoder_phys_cmd(phys_enc);
  1831. u32 frame_cnt;
  1832. struct sde_hw_pp_vsync_info info[MAX_CHANNELS_PER_ENC] = {{0}};
  1833. if (!phys_enc)
  1834. return;
  1835. /* we don't issue CTL_START when using autorefresh */
  1836. frame_cnt = _sde_encoder_phys_cmd_get_autorefresh_property(phys_enc);
  1837. if (frame_cnt) {
  1838. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, frame_cnt);
  1839. atomic_inc(&cmd_enc->autorefresh.kickoff_cnt);
  1840. } else {
  1841. sde_encoder_helper_trigger_start(phys_enc);
  1842. }
  1843. sde_encoder_helper_get_pp_line_count(phys_enc->parent, info);
  1844. SDE_EVT32(DRMID(phys_enc->parent), frame_cnt, info[0].pp_idx, info[0].intf_idx,
  1845. info[0].intf_frame_count, info[0].wr_ptr_line_count, info[0].rd_ptr_line_count,
  1846. info[1].pp_idx, info[1].intf_idx, info[1].intf_frame_count,
  1847. info[1].wr_ptr_line_count, info[1].rd_ptr_line_count);
  1848. /* wr_ptr_wait_success is set true when wr_ptr arrives */
  1849. cmd_enc->wr_ptr_wait_success = false;
  1850. }
  1851. static void _sde_encoder_phys_cmd_calculate_wd_params(struct sde_encoder_phys *phys_enc)
  1852. {
  1853. u32 nominal_te_value;
  1854. struct sde_encoder_virt *sde_enc;
  1855. struct msm_mode_info *mode_info;
  1856. const u32 multiplier = 1 << 10;
  1857. struct intf_wd_jitter_params wd_jtr;
  1858. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  1859. mode_info = &sde_enc->mode_info;
  1860. if (mode_info->wd_jitter.jitter_type & MSM_DISPLAY_WD_INSTANTANEOUS_JITTER) {
  1861. wd_jtr.jitter = mult_frac(multiplier,
  1862. mode_info->wd_jitter.inst_jitter_numer,
  1863. (mode_info->wd_jitter.inst_jitter_denom * 100));
  1864. phys_enc->wd_jitter.jitter = wd_jtr.jitter;
  1865. }
  1866. if (mode_info->wd_jitter.jitter_type & MSM_DISPLAY_WD_LTJ_JITTER) {
  1867. nominal_te_value = CALCULATE_WD_LOAD_VALUE(mode_info->frame_rate) * MDP_TICK_COUNT;
  1868. wd_jtr.ltj_max = mult_frac(nominal_te_value,
  1869. mode_info->wd_jitter.ltj_max_numer,
  1870. (mode_info->wd_jitter.ltj_max_denom) * 100);
  1871. wd_jtr.ltj_slope = mult_frac((1 << 16), wd_jtr.ltj_max,
  1872. (mode_info->wd_jitter.ltj_time_sec * mode_info->frame_rate));
  1873. phys_enc->wd_jitter.ltj_max = wd_jtr.ltj_max;
  1874. phys_enc->wd_jitter.ltj_slope = wd_jtr.ltj_slope;
  1875. }
  1876. phys_enc->hw_intf->ops.configure_wd_jitter(phys_enc->hw_intf, &phys_enc->wd_jitter);
  1877. }
  1878. static void sde_encoder_phys_cmd_store_ltj_values(struct sde_encoder_phys *phys_enc)
  1879. {
  1880. if (phys_enc && phys_enc->hw_intf->ops.get_wd_ltj_status)
  1881. phys_enc->hw_intf->ops.get_wd_ltj_status(phys_enc->hw_intf, &phys_enc->wd_jitter);
  1882. }
  1883. static void sde_encoder_phys_cmd_setup_vsync_source(struct sde_encoder_phys *phys_enc,
  1884. u32 vsync_source, struct msm_display_info *disp_info)
  1885. {
  1886. struct sde_encoder_virt *sde_enc;
  1887. struct sde_connector *sde_conn;
  1888. if (!phys_enc || !phys_enc->hw_intf)
  1889. return;
  1890. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  1891. if (!sde_enc)
  1892. return;
  1893. sde_conn = to_sde_connector(phys_enc->connector);
  1894. if ((disp_info->is_te_using_watchdog_timer || sde_conn->panel_dead) &&
  1895. phys_enc->hw_intf->ops.setup_vsync_source) {
  1896. vsync_source = SDE_VSYNC_SOURCE_WD_TIMER_0;
  1897. if (phys_enc->hw_intf->ops.configure_wd_jitter)
  1898. _sde_encoder_phys_cmd_calculate_wd_params(phys_enc);
  1899. phys_enc->hw_intf->ops.setup_vsync_source(phys_enc->hw_intf,
  1900. sde_enc->mode_info.frame_rate);
  1901. } else {
  1902. sde_encoder_helper_vsync_config(phys_enc, vsync_source);
  1903. }
  1904. if (phys_enc->has_intf_te && phys_enc->hw_intf->ops.vsync_sel)
  1905. phys_enc->hw_intf->ops.vsync_sel(phys_enc->hw_intf,
  1906. vsync_source);
  1907. }
  1908. void sde_encoder_phys_cmd_add_enc_to_minidump(struct sde_encoder_phys *phys_enc)
  1909. {
  1910. struct sde_encoder_phys_cmd *cmd_enc;
  1911. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1912. sde_mini_dump_add_va_region("sde_enc_phys_cmd", sizeof(*cmd_enc), cmd_enc);
  1913. }
  1914. static void sde_encoder_phys_cmd_init_ops(struct sde_encoder_phys_ops *ops)
  1915. {
  1916. ops->prepare_commit = sde_encoder_phys_cmd_prepare_commit;
  1917. ops->is_master = sde_encoder_phys_cmd_is_master;
  1918. ops->mode_set = sde_encoder_phys_cmd_mode_set;
  1919. ops->cont_splash_mode_set = sde_encoder_phys_cmd_cont_splash_mode_set;
  1920. ops->mode_fixup = sde_encoder_phys_cmd_mode_fixup;
  1921. ops->enable = sde_encoder_phys_cmd_enable;
  1922. ops->disable = sde_encoder_phys_cmd_disable;
  1923. ops->destroy = sde_encoder_phys_cmd_destroy;
  1924. ops->get_hw_resources = sde_encoder_phys_cmd_get_hw_resources;
  1925. ops->control_vblank_irq = sde_encoder_phys_cmd_control_vblank_irq;
  1926. ops->wait_for_commit_done = sde_encoder_phys_cmd_wait_for_commit_done;
  1927. ops->prepare_for_kickoff = sde_encoder_phys_cmd_prepare_for_kickoff;
  1928. ops->wait_for_tx_complete = sde_encoder_phys_cmd_wait_for_tx_complete;
  1929. ops->wait_for_vblank = sde_encoder_phys_cmd_wait_for_vblank;
  1930. ops->trigger_flush = sde_encoder_helper_trigger_flush;
  1931. ops->trigger_start = sde_encoder_phys_cmd_trigger_start;
  1932. ops->needs_single_flush = sde_encoder_phys_needs_single_flush;
  1933. ops->hw_reset = sde_encoder_helper_hw_reset;
  1934. ops->irq_control = sde_encoder_phys_cmd_irq_control;
  1935. ops->dynamic_irq_control = sde_encoder_phys_cmd_dynamic_irq_control;
  1936. ops->update_split_role = sde_encoder_phys_cmd_update_split_role;
  1937. ops->restore = sde_encoder_phys_cmd_enable_helper;
  1938. ops->control_te = sde_encoder_phys_cmd_connect_te;
  1939. ops->is_autorefresh_enabled =
  1940. sde_encoder_phys_cmd_is_autorefresh_enabled;
  1941. ops->get_line_count = sde_encoder_phys_cmd_te_get_line_count;
  1942. ops->wait_for_active = NULL;
  1943. ops->setup_vsync_source = sde_encoder_phys_cmd_setup_vsync_source;
  1944. ops->setup_misr = sde_encoder_helper_setup_misr;
  1945. ops->collect_misr = sde_encoder_helper_collect_misr;
  1946. ops->add_to_minidump = sde_encoder_phys_cmd_add_enc_to_minidump;
  1947. ops->disable_autorefresh = _sde_encoder_phys_disable_autorefresh;
  1948. ops->idle_pc_cache_display_status = sde_encoder_phys_cmd_store_ltj_values;
  1949. }
  1950. static inline bool sde_encoder_phys_cmd_intf_te_supported(
  1951. const struct sde_mdss_cfg *sde_cfg, enum sde_intf idx)
  1952. {
  1953. if (sde_cfg && ((idx - INTF_0) < sde_cfg->intf_count))
  1954. return test_bit(SDE_INTF_TE,
  1955. &(sde_cfg->intf[idx - INTF_0].features));
  1956. return false;
  1957. }
  1958. static void _sde_encoder_phys_cmd_init_irqs(struct sde_encoder_phys *phys_enc)
  1959. {
  1960. struct sde_encoder_irq *irq;
  1961. int i;
  1962. for (i = 0; i < INTR_IDX_MAX; i++) {
  1963. irq = &phys_enc->irq[i];
  1964. INIT_LIST_HEAD(&irq->cb.list);
  1965. irq->irq_idx = -EINVAL;
  1966. irq->hw_idx = -EINVAL;
  1967. irq->cb.arg = phys_enc;
  1968. }
  1969. irq = &phys_enc->irq[INTR_IDX_CTL_START];
  1970. irq->name = "ctl_start";
  1971. irq->intr_type = SDE_IRQ_TYPE_CTL_START;
  1972. irq->intr_idx = INTR_IDX_CTL_START;
  1973. irq->cb.func = NULL;
  1974. irq = &phys_enc->irq[INTR_IDX_CTL_DONE];
  1975. irq->name = "ctl_done";
  1976. irq->intr_type = SDE_IRQ_TYPE_CTL_DONE;
  1977. irq->intr_idx = INTR_IDX_CTL_DONE;
  1978. irq->cb.func = sde_encoder_phys_cmd_ctl_done_irq;
  1979. irq = &phys_enc->irq[INTR_IDX_PINGPONG];
  1980. irq->name = "pp_done";
  1981. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_COMP;
  1982. irq->intr_idx = INTR_IDX_PINGPONG;
  1983. irq->cb.func = sde_encoder_phys_cmd_pp_tx_done_irq;
  1984. irq = &phys_enc->irq[INTR_IDX_RDPTR];
  1985. irq->intr_idx = INTR_IDX_RDPTR;
  1986. irq->name = "te_rd_ptr";
  1987. if (phys_enc->has_intf_te)
  1988. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_RD_PTR;
  1989. else
  1990. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_RD_PTR;
  1991. irq->cb.func = sde_encoder_phys_cmd_te_rd_ptr_irq;
  1992. irq = &phys_enc->irq[INTR_IDX_AUTOREFRESH_DONE];
  1993. irq->name = "autorefresh_done";
  1994. if (phys_enc->has_intf_te)
  1995. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_AUTO_REF;
  1996. else
  1997. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_AUTO_REF;
  1998. irq->intr_idx = INTR_IDX_AUTOREFRESH_DONE;
  1999. irq->cb.func = sde_encoder_phys_cmd_autorefresh_done_irq;
  2000. irq = &phys_enc->irq[INTR_IDX_WRPTR];
  2001. irq->intr_idx = INTR_IDX_WRPTR;
  2002. irq->name = "wr_ptr";
  2003. if (phys_enc->has_intf_te)
  2004. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_WR_PTR;
  2005. else
  2006. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_WR_PTR;
  2007. irq->cb.func = sde_encoder_phys_cmd_wr_ptr_irq;
  2008. irq = &phys_enc->irq[INTF_IDX_TEAR_DETECT];
  2009. irq->intr_idx = INTF_IDX_TEAR_DETECT;
  2010. irq->name = "te_tear_detect";
  2011. if (phys_enc->has_intf_te)
  2012. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_TEAR_DETECT;
  2013. else
  2014. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_TEAR_CHECK;
  2015. irq->cb.func = sde_encoder_phys_cmd_tear_detect_irq;
  2016. if (phys_enc->has_intf_te) {
  2017. irq = &phys_enc->irq[INTR_IDX_TE_ASSERT];
  2018. irq->intr_idx = INTR_IDX_TE_ASSERT;
  2019. irq->name = "te_assert";
  2020. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_TE_ASSERT;
  2021. irq->cb.func = sde_encoder_phys_cmd_te_assert_irq;
  2022. irq = &phys_enc->irq[INTR_IDX_TE_DEASSERT];
  2023. irq->intr_idx = INTR_IDX_TE_DEASSERT;
  2024. irq->name = "te_deassert";
  2025. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_TE_DEASSERT;
  2026. irq->cb.func = sde_encoder_phys_cmd_te_deassert_irq;
  2027. }
  2028. }
  2029. struct sde_encoder_phys *sde_encoder_phys_cmd_init(
  2030. struct sde_enc_phys_init_params *p)
  2031. {
  2032. struct sde_encoder_phys *phys_enc = NULL;
  2033. struct sde_encoder_phys_cmd *cmd_enc = NULL;
  2034. struct sde_hw_mdp *hw_mdp;
  2035. int i, ret = 0;
  2036. SDE_DEBUG("intf %d\n", p->intf_idx - INTF_0);
  2037. cmd_enc = kzalloc(sizeof(*cmd_enc), GFP_KERNEL);
  2038. if (!cmd_enc) {
  2039. ret = -ENOMEM;
  2040. SDE_ERROR("failed to allocate\n");
  2041. goto fail;
  2042. }
  2043. phys_enc = &cmd_enc->base;
  2044. hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm);
  2045. if (IS_ERR_OR_NULL(hw_mdp)) {
  2046. ret = PTR_ERR(hw_mdp);
  2047. SDE_ERROR("failed to get mdptop\n");
  2048. goto fail_mdp_init;
  2049. }
  2050. phys_enc->hw_mdptop = hw_mdp;
  2051. phys_enc->intf_idx = p->intf_idx;
  2052. phys_enc->parent = p->parent;
  2053. phys_enc->parent_ops = p->parent_ops;
  2054. phys_enc->sde_kms = p->sde_kms;
  2055. phys_enc->split_role = p->split_role;
  2056. phys_enc->intf_mode = INTF_MODE_CMD;
  2057. phys_enc->enc_spinlock = p->enc_spinlock;
  2058. phys_enc->vblank_ctl_lock = p->vblank_ctl_lock;
  2059. cmd_enc->stream_sel = 0;
  2060. phys_enc->enable_state = SDE_ENC_DISABLED;
  2061. phys_enc->kickoff_timeout_ms = DEFAULT_KICKOFF_TIMEOUT_MS;
  2062. sde_encoder_phys_cmd_init_ops(&phys_enc->ops);
  2063. phys_enc->comp_type = p->comp_type;
  2064. phys_enc->has_intf_te = sde_encoder_phys_cmd_intf_te_supported(
  2065. phys_enc->sde_kms->catalog, phys_enc->intf_idx);
  2066. _sde_encoder_phys_cmd_init_irqs(phys_enc);
  2067. atomic_set(&phys_enc->vblank_refcount, 0);
  2068. atomic_set(&phys_enc->pending_kickoff_cnt, 0);
  2069. atomic_set(&phys_enc->pending_retire_fence_cnt, 0);
  2070. atomic_set(&cmd_enc->pending_vblank_cnt, 0);
  2071. init_waitqueue_head(&phys_enc->pending_kickoff_wq);
  2072. init_waitqueue_head(&cmd_enc->pending_vblank_wq);
  2073. atomic_set(&cmd_enc->autorefresh.kickoff_cnt, 0);
  2074. init_waitqueue_head(&cmd_enc->autorefresh.kickoff_wq);
  2075. INIT_LIST_HEAD(&cmd_enc->te_timestamp_list);
  2076. for (i = 0; i < MAX_TE_PROFILE_COUNT; i++)
  2077. list_add(&cmd_enc->te_timestamp[i].list,
  2078. &cmd_enc->te_timestamp_list);
  2079. SDE_DEBUG_CMDENC(cmd_enc, "created\n");
  2080. return phys_enc;
  2081. fail_mdp_init:
  2082. kfree(cmd_enc);
  2083. fail:
  2084. return ERR_PTR(ret);
  2085. }