sde_encoder_phys_cmd.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526
  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. tc_cfg.sync_cfg_height = 0xFFF0;
  1091. tc_cfg.vsync_init_val = mode->vdisplay;
  1092. tc_cfg.sync_threshold_start = _get_tearcheck_threshold(phys_enc);
  1093. tc_cfg.sync_threshold_continue = DEFAULT_TEARCHECK_SYNC_THRESH_CONTINUE;
  1094. tc_cfg.start_pos = mode->vdisplay;
  1095. tc_cfg.rd_ptr_irq = mode->vdisplay + 1;
  1096. tc_cfg.wr_ptr_irq = 1;
  1097. cmd_enc->qsync_threshold_lines = tc_cfg.sync_threshold_start;
  1098. SDE_DEBUG_CMDENC(cmd_enc,
  1099. "tc %d intf %d vsync_clk_speed_hz %u vtotal %u vrefresh %u\n",
  1100. phys_enc->hw_pp->idx - PINGPONG_0,
  1101. phys_enc->hw_intf->idx - INTF_0,
  1102. vsync_hz, mode->vtotal, vrefresh);
  1103. SDE_DEBUG_CMDENC(cmd_enc,
  1104. "tc %d intf %d enable %u start_pos %u rd_ptr_irq %u wr_ptr_irq %u\n",
  1105. phys_enc->hw_pp->idx - PINGPONG_0,
  1106. phys_enc->hw_intf->idx - INTF_0,
  1107. tc_enable, tc_cfg.start_pos, tc_cfg.rd_ptr_irq,
  1108. tc_cfg.wr_ptr_irq);
  1109. SDE_DEBUG_CMDENC(cmd_enc,
  1110. "tc %d intf %d hw_vsync_mode %u vsync_count %u vsync_init_val %u\n",
  1111. phys_enc->hw_pp->idx - PINGPONG_0,
  1112. phys_enc->hw_intf->idx - INTF_0,
  1113. tc_cfg.hw_vsync_mode, tc_cfg.vsync_count,
  1114. tc_cfg.vsync_init_val);
  1115. SDE_DEBUG_CMDENC(cmd_enc,
  1116. "tc %d intf %d cfgheight %u thresh_start %u thresh_cont %u\n",
  1117. phys_enc->hw_pp->idx - PINGPONG_0,
  1118. phys_enc->hw_intf->idx - INTF_0,
  1119. tc_cfg.sync_cfg_height,
  1120. tc_cfg.sync_threshold_start, tc_cfg.sync_threshold_continue);
  1121. SDE_EVT32(phys_enc->hw_pp->idx - PINGPONG_0, phys_enc->hw_intf->idx - INTF_0,
  1122. vsync_hz, mode->vtotal, vrefresh);
  1123. SDE_EVT32(tc_enable, tc_cfg.start_pos, tc_cfg.rd_ptr_irq, tc_cfg.wr_ptr_irq,
  1124. tc_cfg.hw_vsync_mode, tc_cfg.vsync_count, tc_cfg.vsync_init_val,
  1125. tc_cfg.sync_cfg_height, tc_cfg.sync_threshold_start,
  1126. tc_cfg.sync_threshold_continue);
  1127. if (phys_enc->has_intf_te) {
  1128. phys_enc->hw_intf->ops.setup_tearcheck(phys_enc->hw_intf,
  1129. &tc_cfg);
  1130. phys_enc->hw_intf->ops.enable_tearcheck(phys_enc->hw_intf,
  1131. tc_enable);
  1132. } else {
  1133. phys_enc->hw_pp->ops.setup_tearcheck(phys_enc->hw_pp, &tc_cfg);
  1134. phys_enc->hw_pp->ops.enable_tearcheck(phys_enc->hw_pp,
  1135. tc_enable);
  1136. }
  1137. }
  1138. static void _sde_encoder_phys_cmd_pingpong_config(
  1139. struct sde_encoder_phys *phys_enc)
  1140. {
  1141. struct sde_encoder_phys_cmd *cmd_enc =
  1142. to_sde_encoder_phys_cmd(phys_enc);
  1143. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->hw_pp) {
  1144. SDE_ERROR("invalid arg(s), enc %d\n", !phys_enc);
  1145. return;
  1146. }
  1147. SDE_DEBUG_CMDENC(cmd_enc, "pp %d, enabling mode:\n",
  1148. phys_enc->hw_pp->idx - PINGPONG_0);
  1149. drm_mode_debug_printmodeline(&phys_enc->cached_mode);
  1150. if (!_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  1151. _sde_encoder_phys_cmd_update_intf_cfg(phys_enc);
  1152. sde_encoder_phys_cmd_tearcheck_config(phys_enc);
  1153. }
  1154. static void sde_encoder_phys_cmd_enable_helper(
  1155. struct sde_encoder_phys *phys_enc)
  1156. {
  1157. struct sde_encoder_virt *sde_enc;
  1158. struct sde_hw_intf *hw_intf;
  1159. u32 qsync_mode;
  1160. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->hw_pp ||
  1161. !phys_enc->hw_intf) {
  1162. SDE_ERROR("invalid arg(s), encoder %d\n", !phys_enc);
  1163. return;
  1164. }
  1165. sde_encoder_helper_split_config(phys_enc, phys_enc->intf_idx);
  1166. _sde_encoder_phys_cmd_pingpong_config(phys_enc);
  1167. hw_intf = phys_enc->hw_intf;
  1168. if (hw_intf->ops.enable_compressed_input)
  1169. hw_intf->ops.enable_compressed_input(phys_enc->hw_intf,
  1170. (phys_enc->comp_type !=
  1171. MSM_DISPLAY_COMPRESSION_NONE), false);
  1172. if (hw_intf->ops.enable_wide_bus)
  1173. hw_intf->ops.enable_wide_bus(hw_intf,
  1174. sde_encoder_is_widebus_enabled(phys_enc->parent));
  1175. /*
  1176. * Override internal rd_ptr value when coming out of IPC.
  1177. * This is required on QSYNC panel with low refresh rate to
  1178. * avoid out of sync frame trigger as panel rd_ptr was still
  1179. * incrementing while MDP was power collapsed.
  1180. */
  1181. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  1182. if (sde_enc->idle_pc_restore) {
  1183. qsync_mode = sde_connector_get_qsync_mode(phys_enc->connector);
  1184. if (qsync_mode)
  1185. sde_enc->restore_te_rd_ptr = true;
  1186. }
  1187. /*
  1188. * For pp-split, skip setting the flush bit for the slave intf, since
  1189. * both intfs use same ctl and HW will only flush the master.
  1190. */
  1191. if (_sde_encoder_phys_is_ppsplit(phys_enc) &&
  1192. !sde_encoder_phys_cmd_is_master(phys_enc))
  1193. goto skip_flush;
  1194. _sde_encoder_phys_cmd_update_flush_mask(phys_enc);
  1195. skip_flush:
  1196. return;
  1197. }
  1198. static void sde_encoder_phys_cmd_enable(struct sde_encoder_phys *phys_enc)
  1199. {
  1200. struct sde_encoder_phys_cmd *cmd_enc =
  1201. to_sde_encoder_phys_cmd(phys_enc);
  1202. if (!phys_enc || !phys_enc->hw_pp) {
  1203. SDE_ERROR("invalid phys encoder\n");
  1204. return;
  1205. }
  1206. SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", phys_enc->hw_pp->idx - PINGPONG_0);
  1207. if (phys_enc->enable_state == SDE_ENC_ENABLED) {
  1208. if (!phys_enc->cont_splash_enabled)
  1209. SDE_ERROR("already enabled\n");
  1210. return;
  1211. }
  1212. sde_encoder_phys_cmd_enable_helper(phys_enc);
  1213. phys_enc->enable_state = SDE_ENC_ENABLED;
  1214. }
  1215. static bool sde_encoder_phys_cmd_is_autorefresh_enabled(
  1216. struct sde_encoder_phys *phys_enc)
  1217. {
  1218. struct sde_hw_pingpong *hw_pp;
  1219. struct sde_hw_intf *hw_intf;
  1220. struct sde_hw_autorefresh cfg;
  1221. int ret;
  1222. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  1223. return false;
  1224. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  1225. return false;
  1226. if (phys_enc->has_intf_te) {
  1227. hw_intf = phys_enc->hw_intf;
  1228. if (!hw_intf->ops.get_autorefresh)
  1229. return false;
  1230. ret = hw_intf->ops.get_autorefresh(hw_intf, &cfg);
  1231. } else {
  1232. hw_pp = phys_enc->hw_pp;
  1233. if (!hw_pp->ops.get_autorefresh)
  1234. return false;
  1235. ret = hw_pp->ops.get_autorefresh(hw_pp, &cfg);
  1236. }
  1237. return ret ? false : cfg.enable;
  1238. }
  1239. static void sde_encoder_phys_cmd_connect_te(
  1240. struct sde_encoder_phys *phys_enc, bool enable)
  1241. {
  1242. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  1243. return;
  1244. if (phys_enc->has_intf_te &&
  1245. phys_enc->hw_intf->ops.connect_external_te)
  1246. phys_enc->hw_intf->ops.connect_external_te(phys_enc->hw_intf,
  1247. enable);
  1248. else if (phys_enc->hw_pp->ops.connect_external_te)
  1249. phys_enc->hw_pp->ops.connect_external_te(phys_enc->hw_pp,
  1250. enable);
  1251. else
  1252. return;
  1253. SDE_EVT32(DRMID(phys_enc->parent), enable);
  1254. }
  1255. static int sde_encoder_phys_cmd_te_get_line_count(
  1256. struct sde_encoder_phys *phys_enc)
  1257. {
  1258. struct sde_hw_pingpong *hw_pp;
  1259. struct sde_hw_intf *hw_intf;
  1260. u32 line_count;
  1261. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf)
  1262. return -EINVAL;
  1263. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  1264. return -EINVAL;
  1265. if (phys_enc->has_intf_te) {
  1266. hw_intf = phys_enc->hw_intf;
  1267. if (!hw_intf->ops.get_line_count)
  1268. return -EINVAL;
  1269. line_count = hw_intf->ops.get_line_count(hw_intf);
  1270. } else {
  1271. hw_pp = phys_enc->hw_pp;
  1272. if (!hw_pp->ops.get_line_count)
  1273. return -EINVAL;
  1274. line_count = hw_pp->ops.get_line_count(hw_pp);
  1275. }
  1276. return line_count;
  1277. }
  1278. static void sde_encoder_phys_cmd_disable(struct sde_encoder_phys *phys_enc)
  1279. {
  1280. struct sde_encoder_phys_cmd *cmd_enc =
  1281. to_sde_encoder_phys_cmd(phys_enc);
  1282. if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_intf) {
  1283. SDE_ERROR("invalid encoder\n");
  1284. return;
  1285. }
  1286. SDE_DEBUG_CMDENC(cmd_enc, "pp %d intf %d state %d\n",
  1287. phys_enc->hw_pp->idx - PINGPONG_0,
  1288. phys_enc->hw_intf->idx - INTF_0,
  1289. phys_enc->enable_state);
  1290. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  1291. phys_enc->hw_intf->idx - INTF_0,
  1292. phys_enc->enable_state);
  1293. if (phys_enc->enable_state == SDE_ENC_DISABLED) {
  1294. SDE_ERROR_CMDENC(cmd_enc, "already disabled\n");
  1295. return;
  1296. }
  1297. if (!sde_in_trusted_vm(phys_enc->sde_kms)) {
  1298. if (phys_enc->has_intf_te &&
  1299. phys_enc->hw_intf->ops.enable_tearcheck)
  1300. phys_enc->hw_intf->ops.enable_tearcheck(
  1301. phys_enc->hw_intf,
  1302. false);
  1303. else if (phys_enc->hw_pp->ops.enable_tearcheck)
  1304. phys_enc->hw_pp->ops.enable_tearcheck(phys_enc->hw_pp,
  1305. false);
  1306. if (sde_encoder_phys_cmd_is_master(phys_enc))
  1307. sde_encoder_helper_phys_disable(phys_enc, NULL);
  1308. if (phys_enc->hw_intf->ops.reset_counter)
  1309. phys_enc->hw_intf->ops.reset_counter(phys_enc->hw_intf);
  1310. }
  1311. memset(&cmd_enc->autorefresh.cfg, 0, sizeof(struct sde_hw_autorefresh));
  1312. phys_enc->enable_state = SDE_ENC_DISABLED;
  1313. }
  1314. static void sde_encoder_phys_cmd_destroy(struct sde_encoder_phys *phys_enc)
  1315. {
  1316. struct sde_encoder_phys_cmd *cmd_enc =
  1317. to_sde_encoder_phys_cmd(phys_enc);
  1318. if (!phys_enc) {
  1319. SDE_ERROR("invalid encoder\n");
  1320. return;
  1321. }
  1322. kfree(cmd_enc);
  1323. }
  1324. static void sde_encoder_phys_cmd_get_hw_resources(
  1325. struct sde_encoder_phys *phys_enc,
  1326. struct sde_encoder_hw_resources *hw_res,
  1327. struct drm_connector_state *conn_state)
  1328. {
  1329. struct sde_encoder_phys_cmd *cmd_enc =
  1330. to_sde_encoder_phys_cmd(phys_enc);
  1331. if (!phys_enc) {
  1332. SDE_ERROR("invalid encoder\n");
  1333. return;
  1334. }
  1335. if ((phys_enc->intf_idx - INTF_0) >= INTF_MAX) {
  1336. SDE_ERROR("invalid intf idx:%d\n", phys_enc->intf_idx);
  1337. return;
  1338. }
  1339. SDE_DEBUG_CMDENC(cmd_enc, "\n");
  1340. hw_res->intfs[phys_enc->intf_idx - INTF_0] = INTF_MODE_CMD;
  1341. }
  1342. static int sde_encoder_phys_cmd_prepare_for_kickoff(
  1343. struct sde_encoder_phys *phys_enc,
  1344. struct sde_encoder_kickoff_params *params)
  1345. {
  1346. struct sde_hw_tear_check tc_cfg = {0};
  1347. struct sde_encoder_phys_cmd *cmd_enc =
  1348. to_sde_encoder_phys_cmd(phys_enc);
  1349. struct sde_encoder_virt *sde_enc;
  1350. int ret = 0;
  1351. bool recovery_events;
  1352. if (!phys_enc || !phys_enc->hw_pp) {
  1353. SDE_ERROR("invalid encoder\n");
  1354. return -EINVAL;
  1355. }
  1356. SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", phys_enc->hw_pp->idx - PINGPONG_0);
  1357. phys_enc->frame_trigger_mode = params->frame_trigger_mode;
  1358. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->hw_pp->idx - PINGPONG_0,
  1359. atomic_read(&phys_enc->pending_kickoff_cnt),
  1360. atomic_read(&cmd_enc->autorefresh.kickoff_cnt),
  1361. phys_enc->frame_trigger_mode);
  1362. if (phys_enc->frame_trigger_mode == FRAME_DONE_WAIT_DEFAULT) {
  1363. /*
  1364. * Mark kickoff request as outstanding. If there are more
  1365. * than one outstanding frame, then we have to wait for the
  1366. * previous frame to complete
  1367. */
  1368. ret = _sde_encoder_phys_cmd_wait_for_idle(phys_enc);
  1369. if (ret) {
  1370. atomic_set(&phys_enc->pending_kickoff_cnt, 0);
  1371. SDE_EVT32(DRMID(phys_enc->parent),
  1372. phys_enc->hw_pp->idx - PINGPONG_0);
  1373. SDE_ERROR("failed wait_for_idle: %d\n", ret);
  1374. }
  1375. }
  1376. if (phys_enc->recovered) {
  1377. recovery_events = sde_encoder_recovery_events_enabled(
  1378. phys_enc->parent);
  1379. if (cmd_enc->frame_tx_timeout_report_cnt && recovery_events)
  1380. sde_connector_event_notify(phys_enc->connector,
  1381. DRM_EVENT_SDE_HW_RECOVERY,
  1382. sizeof(uint8_t),
  1383. SDE_RECOVERY_SUCCESS);
  1384. cmd_enc->frame_tx_timeout_report_cnt = 0;
  1385. phys_enc->recovered = false;
  1386. }
  1387. if (sde_connector_is_qsync_updated(phys_enc->connector)) {
  1388. tc_cfg.sync_threshold_start = _get_tearcheck_threshold(
  1389. phys_enc);
  1390. cmd_enc->qsync_threshold_lines = tc_cfg.sync_threshold_start;
  1391. if (phys_enc->has_intf_te &&
  1392. phys_enc->hw_intf->ops.update_tearcheck)
  1393. phys_enc->hw_intf->ops.update_tearcheck(
  1394. phys_enc->hw_intf, &tc_cfg);
  1395. else if (phys_enc->hw_pp->ops.update_tearcheck)
  1396. phys_enc->hw_pp->ops.update_tearcheck(
  1397. phys_enc->hw_pp, &tc_cfg);
  1398. SDE_EVT32(DRMID(phys_enc->parent), tc_cfg.sync_threshold_start);
  1399. }
  1400. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  1401. if (sde_enc->restore_te_rd_ptr) {
  1402. sde_encoder_restore_tearcheck_rd_ptr(phys_enc);
  1403. sde_enc->restore_te_rd_ptr = false;
  1404. }
  1405. SDE_DEBUG_CMDENC(cmd_enc, "pp:%d pending_cnt %d\n",
  1406. phys_enc->hw_pp->idx - PINGPONG_0,
  1407. atomic_read(&phys_enc->pending_kickoff_cnt));
  1408. return ret;
  1409. }
  1410. static bool _sde_encoder_phys_cmd_needs_vsync_change(
  1411. struct sde_encoder_phys *phys_enc, ktime_t profile_timestamp)
  1412. {
  1413. struct sde_encoder_virt *sde_enc;
  1414. struct sde_encoder_phys_cmd *cmd_enc;
  1415. struct sde_encoder_phys_cmd_te_timestamp *cur;
  1416. struct sde_encoder_phys_cmd_te_timestamp *prev = NULL;
  1417. ktime_t time_diff;
  1418. struct msm_mode_info *info;
  1419. ktime_t l_bound = 0, u_bound = 0;
  1420. bool ret = false;
  1421. unsigned long lock_flags;
  1422. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1423. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  1424. info = &sde_enc->mode_info;
  1425. sde_encoder_helper_get_jitter_bounds_ns(info->frame_rate, info->jitter_numer,
  1426. info->jitter_denom, &l_bound, &u_bound);
  1427. if (!l_bound || !u_bound) {
  1428. SDE_ERROR_CMDENC(cmd_enc, "invalid vsync jitter bounds\n");
  1429. return false;
  1430. }
  1431. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  1432. list_for_each_entry_reverse(cur, &cmd_enc->te_timestamp_list, list) {
  1433. if (prev && ktime_after(cur->timestamp, profile_timestamp)) {
  1434. time_diff = ktime_sub(prev->timestamp, cur->timestamp);
  1435. if ((time_diff < l_bound) || (time_diff > u_bound)) {
  1436. ret = true;
  1437. break;
  1438. }
  1439. }
  1440. prev = cur;
  1441. }
  1442. spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
  1443. if (ret) {
  1444. SDE_DEBUG_CMDENC(cmd_enc,
  1445. "time_diff:%llu, prev:%llu, cur:%llu, jitter:%llu/%llu\n",
  1446. time_diff, prev->timestamp, cur->timestamp,
  1447. l_bound, u_bound);
  1448. time_diff = div_s64(time_diff, 1000);
  1449. SDE_EVT32(DRMID(phys_enc->parent),
  1450. (u32) (do_div(l_bound, 1000)),
  1451. (u32) (do_div(u_bound, 1000)),
  1452. (u32) (time_diff), SDE_EVTLOG_ERROR);
  1453. }
  1454. return ret;
  1455. }
  1456. static int _sde_encoder_phys_cmd_wait_for_wr_ptr(
  1457. struct sde_encoder_phys *phys_enc)
  1458. {
  1459. struct sde_encoder_phys_cmd *cmd_enc =
  1460. to_sde_encoder_phys_cmd(phys_enc);
  1461. struct sde_encoder_wait_info wait_info = {0};
  1462. struct sde_connector *c_conn;
  1463. bool frame_pending = true;
  1464. struct sde_hw_ctl *ctl;
  1465. unsigned long lock_flags;
  1466. int ret, timeout_ms;
  1467. if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->connector) {
  1468. SDE_ERROR("invalid argument(s)\n");
  1469. return -EINVAL;
  1470. }
  1471. ctl = phys_enc->hw_ctl;
  1472. c_conn = to_sde_connector(phys_enc->connector);
  1473. timeout_ms = phys_enc->kickoff_timeout_ms;
  1474. if (c_conn->lp_mode == SDE_MODE_DPMS_LP1 ||
  1475. c_conn->lp_mode == SDE_MODE_DPMS_LP2)
  1476. timeout_ms = timeout_ms * 2;
  1477. wait_info.wq = &phys_enc->pending_kickoff_wq;
  1478. wait_info.atomic_cnt = &phys_enc->pending_retire_fence_cnt;
  1479. wait_info.timeout_ms = timeout_ms;
  1480. /* slave encoder doesn't enable for ppsplit */
  1481. if (_sde_encoder_phys_is_ppsplit_slave(phys_enc))
  1482. return 0;
  1483. ret = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_WRPTR,
  1484. &wait_info);
  1485. /*
  1486. * if hwfencing enabled, try again to wait for up to the extended timeout time in
  1487. * increments as long as fence has not been signaled.
  1488. */
  1489. if (ret == -ETIMEDOUT && phys_enc->sde_kms->catalog->hw_fence_rev)
  1490. ret = sde_encoder_helper_hw_fence_extended_wait(phys_enc, ctl, &wait_info,
  1491. INTR_IDX_WRPTR);
  1492. if (ret == -ETIMEDOUT) {
  1493. struct sde_hw_ctl *ctl = phys_enc->hw_ctl;
  1494. if (ctl && ctl->ops.get_start_state)
  1495. frame_pending = ctl->ops.get_start_state(ctl);
  1496. ret = (frame_pending || sde_connector_esd_status(phys_enc->connector)) ? ret : 0;
  1497. /*
  1498. * There can be few cases of ESD where CTL_START is cleared but
  1499. * wr_ptr irq doesn't come. Signaling retire fence in these
  1500. * cases to avoid freeze and dangling pending_retire_fence_cnt
  1501. */
  1502. if (!ret) {
  1503. SDE_EVT32(DRMID(phys_enc->parent),
  1504. SDE_EVTLOG_FUNC_CASE1);
  1505. if (sde_encoder_phys_cmd_is_master(phys_enc) &&
  1506. atomic_add_unless(
  1507. &phys_enc->pending_retire_fence_cnt, -1, 0)) {
  1508. spin_lock_irqsave(phys_enc->enc_spinlock,
  1509. lock_flags);
  1510. phys_enc->parent_ops.handle_frame_done(
  1511. phys_enc->parent, phys_enc,
  1512. SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE);
  1513. spin_unlock_irqrestore(phys_enc->enc_spinlock,
  1514. lock_flags);
  1515. }
  1516. }
  1517. /* if we timeout after the extended wait, reset mixers and do sw override */
  1518. if (ret && phys_enc->sde_kms->catalog->hw_fence_rev)
  1519. sde_encoder_helper_hw_fence_sw_override(phys_enc, ctl);
  1520. }
  1521. cmd_enc->wr_ptr_wait_success = (ret == 0) ? true : false;
  1522. return ret;
  1523. }
  1524. static int sde_encoder_phys_cmd_wait_for_tx_complete(
  1525. struct sde_encoder_phys *phys_enc)
  1526. {
  1527. int rc;
  1528. struct sde_encoder_phys_cmd *cmd_enc;
  1529. if (!phys_enc)
  1530. return -EINVAL;
  1531. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1532. if (sde_encoder_check_ctl_done_support(phys_enc->parent)
  1533. && !sde_encoder_phys_cmd_is_master(phys_enc))
  1534. return 0;
  1535. if (!atomic_read(&phys_enc->pending_kickoff_cnt)) {
  1536. SDE_EVT32(DRMID(phys_enc->parent),
  1537. phys_enc->intf_idx - INTF_0,
  1538. phys_enc->enable_state);
  1539. return 0;
  1540. }
  1541. rc = _sde_encoder_phys_cmd_wait_for_idle(phys_enc);
  1542. if (rc) {
  1543. SDE_EVT32(DRMID(phys_enc->parent),
  1544. phys_enc->intf_idx - INTF_0);
  1545. SDE_ERROR("failed wait_for_idle: %d\n", rc);
  1546. }
  1547. return rc;
  1548. }
  1549. static int _sde_encoder_phys_cmd_handle_wr_ptr_timeout(
  1550. struct sde_encoder_phys *phys_enc,
  1551. ktime_t profile_timestamp)
  1552. {
  1553. struct sde_encoder_phys_cmd *cmd_enc =
  1554. to_sde_encoder_phys_cmd(phys_enc);
  1555. bool switch_te;
  1556. int ret = -ETIMEDOUT;
  1557. unsigned long lock_flags;
  1558. switch_te = _sde_encoder_phys_cmd_needs_vsync_change(
  1559. phys_enc, profile_timestamp);
  1560. SDE_EVT32(DRMID(phys_enc->parent), switch_te, SDE_EVTLOG_FUNC_ENTRY);
  1561. if (sde_connector_panel_dead(phys_enc->connector)) {
  1562. ret = _sde_encoder_phys_cmd_wait_for_wr_ptr(phys_enc);
  1563. } else if (switch_te) {
  1564. SDE_DEBUG_CMDENC(cmd_enc,
  1565. "wr_ptr_irq wait failed, retry with WD TE\n");
  1566. /* switch to watchdog TE and wait again */
  1567. sde_encoder_helper_switch_vsync(phys_enc->parent, true);
  1568. ret = _sde_encoder_phys_cmd_wait_for_wr_ptr(phys_enc);
  1569. /* switch back to default TE */
  1570. sde_encoder_helper_switch_vsync(phys_enc->parent, false);
  1571. }
  1572. /*
  1573. * Signaling the retire fence at wr_ptr timeout
  1574. * to allow the next commit and avoid device freeze.
  1575. */
  1576. if (ret == -ETIMEDOUT) {
  1577. SDE_ERROR_CMDENC(cmd_enc,
  1578. "wr_ptr_irq wait failed, switch_te:%d\n", switch_te);
  1579. SDE_EVT32(DRMID(phys_enc->parent), switch_te, SDE_EVTLOG_ERROR);
  1580. if (sde_encoder_phys_cmd_is_master(phys_enc) &&
  1581. atomic_add_unless(
  1582. &phys_enc->pending_retire_fence_cnt, -1, 0)) {
  1583. spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags);
  1584. phys_enc->parent_ops.handle_frame_done(
  1585. phys_enc->parent, phys_enc,
  1586. SDE_ENCODER_FRAME_EVENT_SIGNAL_RETIRE_FENCE);
  1587. spin_unlock_irqrestore(phys_enc->enc_spinlock,
  1588. lock_flags);
  1589. }
  1590. }
  1591. cmd_enc->wr_ptr_wait_success = (ret == 0) ? true : false;
  1592. return ret;
  1593. }
  1594. static int sde_encoder_phys_cmd_wait_for_commit_done(
  1595. struct sde_encoder_phys *phys_enc)
  1596. {
  1597. int rc = 0, i, pending_cnt;
  1598. struct sde_encoder_phys_cmd *cmd_enc;
  1599. ktime_t profile_timestamp = ktime_get();
  1600. u32 scheduler_status = INVALID_CTL_STATUS;
  1601. struct sde_hw_ctl *ctl;
  1602. if (!phys_enc)
  1603. return -EINVAL;
  1604. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1605. if (sde_encoder_check_ctl_done_support(phys_enc->parent)
  1606. && !sde_encoder_phys_cmd_is_master(phys_enc))
  1607. return 0;
  1608. /* only required for master controller */
  1609. if (sde_encoder_phys_cmd_is_master(phys_enc)) {
  1610. rc = _sde_encoder_phys_cmd_wait_for_wr_ptr(phys_enc);
  1611. if (rc == -ETIMEDOUT) {
  1612. /*
  1613. * Profile all the TE received after profile_timestamp
  1614. * and if the jitter is more, switch to watchdog TE
  1615. * and wait for wr_ptr again. Finally move back to
  1616. * default TE.
  1617. */
  1618. rc = _sde_encoder_phys_cmd_handle_wr_ptr_timeout(
  1619. phys_enc, profile_timestamp);
  1620. if (rc == -ETIMEDOUT)
  1621. goto wait_for_idle;
  1622. }
  1623. if (cmd_enc->autorefresh.cfg.enable)
  1624. rc = _sde_encoder_phys_cmd_wait_for_autorefresh_done(
  1625. phys_enc);
  1626. ctl = phys_enc->hw_ctl;
  1627. if (ctl && ctl->ops.get_scheduler_status)
  1628. scheduler_status = ctl->ops.get_scheduler_status(ctl);
  1629. }
  1630. /* wait for posted start or serialize trigger */
  1631. pending_cnt = atomic_read(&phys_enc->pending_kickoff_cnt);
  1632. if ((pending_cnt > 1) ||
  1633. (pending_cnt && (scheduler_status & BIT(0))) ||
  1634. (!rc && phys_enc->frame_trigger_mode == FRAME_DONE_WAIT_SERIALIZE))
  1635. goto wait_for_idle;
  1636. return rc;
  1637. wait_for_idle:
  1638. pending_cnt = atomic_read(&phys_enc->pending_kickoff_cnt);
  1639. for (i = 0; i < pending_cnt; i++)
  1640. rc |= sde_encoder_wait_for_event(phys_enc->parent,
  1641. MSM_ENC_TX_COMPLETE);
  1642. if (rc) {
  1643. SDE_EVT32(DRMID(phys_enc->parent),
  1644. phys_enc->hw_pp->idx - PINGPONG_0,
  1645. phys_enc->frame_trigger_mode,
  1646. atomic_read(&phys_enc->pending_kickoff_cnt),
  1647. phys_enc->enable_state,
  1648. cmd_enc->wr_ptr_wait_success, scheduler_status, rc);
  1649. SDE_ERROR("pp:%d failed wait_for_idle: %d\n",
  1650. phys_enc->hw_pp->idx - PINGPONG_0, rc);
  1651. if (phys_enc->enable_state == SDE_ENC_ERR_NEEDS_HW_RESET)
  1652. sde_encoder_needs_hw_reset(phys_enc->parent);
  1653. }
  1654. return rc;
  1655. }
  1656. static int sde_encoder_phys_cmd_wait_for_vblank(
  1657. struct sde_encoder_phys *phys_enc)
  1658. {
  1659. int rc = 0;
  1660. struct sde_encoder_phys_cmd *cmd_enc;
  1661. struct sde_encoder_wait_info wait_info = {0};
  1662. if (!phys_enc)
  1663. return -EINVAL;
  1664. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1665. /* only required for master controller */
  1666. if (!sde_encoder_phys_cmd_is_master(phys_enc))
  1667. return rc;
  1668. wait_info.wq = &cmd_enc->pending_vblank_wq;
  1669. wait_info.atomic_cnt = &cmd_enc->pending_vblank_cnt;
  1670. wait_info.timeout_ms = _sde_encoder_phys_cmd_get_idle_timeout(phys_enc);
  1671. atomic_inc(&cmd_enc->pending_vblank_cnt);
  1672. rc = sde_encoder_helper_wait_for_irq(phys_enc, INTR_IDX_RDPTR,
  1673. &wait_info);
  1674. return rc;
  1675. }
  1676. static void sde_encoder_phys_cmd_update_split_role(
  1677. struct sde_encoder_phys *phys_enc,
  1678. enum sde_enc_split_role role)
  1679. {
  1680. struct sde_encoder_phys_cmd *cmd_enc;
  1681. enum sde_enc_split_role old_role;
  1682. bool is_ppsplit;
  1683. if (!phys_enc)
  1684. return;
  1685. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1686. old_role = phys_enc->split_role;
  1687. is_ppsplit = _sde_encoder_phys_is_ppsplit(phys_enc);
  1688. phys_enc->split_role = role;
  1689. SDE_DEBUG_CMDENC(cmd_enc, "old role %d new role %d\n",
  1690. old_role, role);
  1691. /*
  1692. * ppsplit solo needs to reprogram because intf may have swapped without
  1693. * role changing on left-only, right-only back-to-back commits
  1694. */
  1695. if (!(is_ppsplit && role == ENC_ROLE_SOLO) &&
  1696. (role == old_role || role == ENC_ROLE_SKIP))
  1697. return;
  1698. sde_encoder_helper_split_config(phys_enc, phys_enc->intf_idx);
  1699. _sde_encoder_phys_cmd_pingpong_config(phys_enc);
  1700. _sde_encoder_phys_cmd_update_flush_mask(phys_enc);
  1701. }
  1702. static void _sde_encoder_autorefresh_disable_seq1(
  1703. struct sde_encoder_phys *phys_enc)
  1704. {
  1705. int trial = 0;
  1706. u32 timeout_ms = phys_enc->kickoff_timeout_ms;
  1707. struct sde_encoder_phys_cmd *cmd_enc =
  1708. to_sde_encoder_phys_cmd(phys_enc);
  1709. /*
  1710. * If autorefresh is enabled, disable it and make sure it is safe to
  1711. * proceed with current frame commit/push. Sequence fallowed is,
  1712. * 1. Disable TE & autorefresh - caller will take care of it
  1713. * 2. Poll for frame transfer ongoing to be false
  1714. * 3. Enable TE back - caller will take care of it
  1715. */
  1716. do {
  1717. udelay(AUTOREFRESH_SEQ1_POLL_TIME);
  1718. if ((trial * AUTOREFRESH_SEQ1_POLL_TIME)
  1719. > (timeout_ms * USEC_PER_MSEC)) {
  1720. SDE_ERROR_CMDENC(cmd_enc,
  1721. "disable autorefresh failed\n");
  1722. phys_enc->enable_state = SDE_ENC_ERR_NEEDS_HW_RESET;
  1723. break;
  1724. }
  1725. trial++;
  1726. } while (_sde_encoder_phys_cmd_is_ongoing_pptx(phys_enc));
  1727. }
  1728. static void _sde_encoder_autorefresh_disable_seq2(
  1729. struct sde_encoder_phys *phys_enc)
  1730. {
  1731. int trial = 0;
  1732. struct sde_hw_mdp *hw_mdp = phys_enc->hw_mdptop;
  1733. u32 autorefresh_status = 0;
  1734. struct sde_encoder_phys_cmd *cmd_enc =
  1735. to_sde_encoder_phys_cmd(phys_enc);
  1736. struct intf_tear_status tear_status;
  1737. struct sde_hw_intf *hw_intf = phys_enc->hw_intf;
  1738. if (!hw_mdp->ops.get_autorefresh_status ||
  1739. !hw_intf->ops.check_and_reset_tearcheck) {
  1740. SDE_DEBUG_CMDENC(cmd_enc,
  1741. "autofresh disable seq2 not supported\n");
  1742. return;
  1743. }
  1744. /*
  1745. * If autorefresh is still enabled after sequence-1, proceed with
  1746. * below sequence-2.
  1747. * 1. Disable autorefresh config
  1748. * 2. Run in loop:
  1749. * 2.1 Poll for autorefresh to be disabled
  1750. * 2.2 Log read and write count status
  1751. * 2.3 Replace te write count with start_pos to meet trigger window
  1752. */
  1753. autorefresh_status = hw_mdp->ops.get_autorefresh_status(hw_mdp,
  1754. phys_enc->intf_idx);
  1755. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1756. autorefresh_status, SDE_EVTLOG_FUNC_CASE1);
  1757. if (!(autorefresh_status & BIT(7))) {
  1758. usleep_range(AUTOREFRESH_SEQ2_POLL_TIME,
  1759. AUTOREFRESH_SEQ2_POLL_TIME + 1);
  1760. autorefresh_status = hw_mdp->ops.get_autorefresh_status(hw_mdp,
  1761. phys_enc->intf_idx);
  1762. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1763. autorefresh_status, SDE_EVTLOG_FUNC_CASE2);
  1764. }
  1765. while (autorefresh_status & BIT(7)) {
  1766. if (!trial) {
  1767. pr_err("enc:%d autofresh status:0x%x intf:%d\n", DRMID(phys_enc->parent),
  1768. autorefresh_status, phys_enc->intf_idx - INTF_0);
  1769. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, 0);
  1770. }
  1771. usleep_range(AUTOREFRESH_SEQ2_POLL_TIME,
  1772. AUTOREFRESH_SEQ2_POLL_TIME + 1);
  1773. if ((trial * AUTOREFRESH_SEQ2_POLL_TIME)
  1774. > AUTOREFRESH_SEQ2_POLL_TIMEOUT) {
  1775. SDE_ERROR_CMDENC(cmd_enc,
  1776. "disable autorefresh failed\n");
  1777. SDE_DBG_DUMP(SDE_DBG_BUILT_IN_ALL, "panic");
  1778. break;
  1779. }
  1780. trial++;
  1781. autorefresh_status = hw_mdp->ops.get_autorefresh_status(hw_mdp,
  1782. phys_enc->intf_idx);
  1783. hw_intf->ops.check_and_reset_tearcheck(hw_intf, &tear_status);
  1784. pr_err("enc:%d autofresh status:0x%x intf:%d\n",
  1785. DRMID(phys_enc->parent), autorefresh_status,
  1786. phys_enc->intf_idx - INTF_0);
  1787. pr_err("tear_read_frame_count:%d tear_read_line_count:%d\n",
  1788. tear_status.read_frame_count, tear_status.read_line_count);
  1789. pr_err("tear_write_frame_count:%d tear_write_line_count:%d\n",
  1790. tear_status.write_frame_count, tear_status.write_line_count);
  1791. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0, autorefresh_status,
  1792. tear_status.read_frame_count, tear_status.read_line_count,
  1793. tear_status.write_frame_count, tear_status.write_line_count);
  1794. }
  1795. }
  1796. static void _sde_encoder_phys_disable_autorefresh(struct sde_encoder_phys *phys_enc)
  1797. {
  1798. struct sde_encoder_phys_cmd *cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1799. struct sde_kms *sde_kms;
  1800. if (!phys_enc || !sde_encoder_phys_cmd_is_master(phys_enc))
  1801. return;
  1802. if (!sde_encoder_phys_cmd_is_autorefresh_enabled(phys_enc))
  1803. return;
  1804. SDE_EVT32(DRMID(phys_enc->parent), phys_enc->intf_idx - INTF_0,
  1805. cmd_enc->autorefresh.cfg.enable);
  1806. sde_kms = phys_enc->sde_kms;
  1807. sde_encoder_phys_cmd_connect_te(phys_enc, false);
  1808. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, 0);
  1809. phys_enc->autorefresh_disable_trans = true;
  1810. if (sde_kms && sde_kms->catalog &&
  1811. (sde_kms->catalog->autorefresh_disable_seq == AUTOREFRESH_DISABLE_SEQ1)) {
  1812. _sde_encoder_autorefresh_disable_seq1(phys_enc);
  1813. _sde_encoder_autorefresh_disable_seq2(phys_enc);
  1814. }
  1815. sde_encoder_phys_cmd_connect_te(phys_enc, true);
  1816. SDE_DEBUG_CMDENC(cmd_enc, "autorefresh disabled successfully\n");
  1817. }
  1818. static void sde_encoder_phys_cmd_prepare_commit(struct sde_encoder_phys *phys_enc)
  1819. {
  1820. return _sde_encoder_phys_disable_autorefresh(phys_enc);
  1821. }
  1822. static void sde_encoder_phys_cmd_trigger_start(
  1823. struct sde_encoder_phys *phys_enc)
  1824. {
  1825. struct sde_encoder_phys_cmd *cmd_enc =
  1826. to_sde_encoder_phys_cmd(phys_enc);
  1827. u32 frame_cnt;
  1828. struct sde_hw_pp_vsync_info info[MAX_CHANNELS_PER_ENC] = {{0}};
  1829. if (!phys_enc)
  1830. return;
  1831. /* we don't issue CTL_START when using autorefresh */
  1832. frame_cnt = _sde_encoder_phys_cmd_get_autorefresh_property(phys_enc);
  1833. if (frame_cnt) {
  1834. _sde_encoder_phys_cmd_config_autorefresh(phys_enc, frame_cnt);
  1835. atomic_inc(&cmd_enc->autorefresh.kickoff_cnt);
  1836. } else {
  1837. sde_encoder_helper_trigger_start(phys_enc);
  1838. }
  1839. sde_encoder_helper_get_pp_line_count(phys_enc->parent, info);
  1840. SDE_EVT32(DRMID(phys_enc->parent), frame_cnt, info[0].pp_idx, info[0].intf_idx,
  1841. info[0].intf_frame_count, info[0].wr_ptr_line_count, info[0].rd_ptr_line_count,
  1842. info[1].pp_idx, info[1].intf_idx, info[1].intf_frame_count,
  1843. info[1].wr_ptr_line_count, info[1].rd_ptr_line_count);
  1844. /* wr_ptr_wait_success is set true when wr_ptr arrives */
  1845. cmd_enc->wr_ptr_wait_success = false;
  1846. }
  1847. static void _sde_encoder_phys_cmd_calculate_wd_params(struct sde_encoder_phys *phys_enc)
  1848. {
  1849. u32 nominal_te_value;
  1850. struct sde_encoder_virt *sde_enc;
  1851. struct msm_mode_info *mode_info;
  1852. const u32 multiplier = 1 << 10;
  1853. struct intf_wd_jitter_params wd_jtr;
  1854. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  1855. mode_info = &sde_enc->mode_info;
  1856. if (mode_info->wd_jitter.jitter_type & MSM_DISPLAY_WD_INSTANTANEOUS_JITTER) {
  1857. wd_jtr.jitter = mult_frac(multiplier,
  1858. mode_info->wd_jitter.inst_jitter_numer,
  1859. (mode_info->wd_jitter.inst_jitter_denom * 100));
  1860. phys_enc->wd_jitter.jitter = wd_jtr.jitter;
  1861. }
  1862. if (mode_info->wd_jitter.jitter_type & MSM_DISPLAY_WD_LTJ_JITTER) {
  1863. nominal_te_value = CALCULATE_WD_LOAD_VALUE(mode_info->frame_rate) * MDP_TICK_COUNT;
  1864. wd_jtr.ltj_max = mult_frac(nominal_te_value,
  1865. mode_info->wd_jitter.ltj_max_numer,
  1866. (mode_info->wd_jitter.ltj_max_denom) * 100);
  1867. wd_jtr.ltj_slope = mult_frac((1 << 16), wd_jtr.ltj_max,
  1868. (mode_info->wd_jitter.ltj_time_sec * mode_info->frame_rate));
  1869. phys_enc->wd_jitter.ltj_max = wd_jtr.ltj_max;
  1870. phys_enc->wd_jitter.ltj_slope = wd_jtr.ltj_slope;
  1871. }
  1872. phys_enc->hw_intf->ops.configure_wd_jitter(phys_enc->hw_intf, &phys_enc->wd_jitter);
  1873. }
  1874. static void sde_encoder_phys_cmd_store_ltj_values(struct sde_encoder_phys *phys_enc)
  1875. {
  1876. if (phys_enc && phys_enc->hw_intf->ops.get_wd_ltj_status)
  1877. phys_enc->hw_intf->ops.get_wd_ltj_status(phys_enc->hw_intf, &phys_enc->wd_jitter);
  1878. }
  1879. static void sde_encoder_phys_cmd_setup_vsync_source(struct sde_encoder_phys *phys_enc,
  1880. u32 vsync_source, struct msm_display_info *disp_info)
  1881. {
  1882. struct sde_encoder_virt *sde_enc;
  1883. struct sde_connector *sde_conn;
  1884. if (!phys_enc || !phys_enc->hw_intf)
  1885. return;
  1886. sde_enc = to_sde_encoder_virt(phys_enc->parent);
  1887. if (!sde_enc)
  1888. return;
  1889. sde_conn = to_sde_connector(phys_enc->connector);
  1890. if ((disp_info->is_te_using_watchdog_timer || sde_conn->panel_dead) &&
  1891. phys_enc->hw_intf->ops.setup_vsync_source) {
  1892. vsync_source = SDE_VSYNC_SOURCE_WD_TIMER_0;
  1893. if (phys_enc->hw_intf->ops.configure_wd_jitter)
  1894. _sde_encoder_phys_cmd_calculate_wd_params(phys_enc);
  1895. phys_enc->hw_intf->ops.setup_vsync_source(phys_enc->hw_intf,
  1896. sde_enc->mode_info.frame_rate);
  1897. } else {
  1898. sde_encoder_helper_vsync_config(phys_enc, vsync_source);
  1899. }
  1900. if (phys_enc->has_intf_te && phys_enc->hw_intf->ops.vsync_sel)
  1901. phys_enc->hw_intf->ops.vsync_sel(phys_enc->hw_intf,
  1902. vsync_source);
  1903. }
  1904. void sde_encoder_phys_cmd_add_enc_to_minidump(struct sde_encoder_phys *phys_enc)
  1905. {
  1906. struct sde_encoder_phys_cmd *cmd_enc;
  1907. cmd_enc = to_sde_encoder_phys_cmd(phys_enc);
  1908. sde_mini_dump_add_va_region("sde_enc_phys_cmd", sizeof(*cmd_enc), cmd_enc);
  1909. }
  1910. static void sde_encoder_phys_cmd_init_ops(struct sde_encoder_phys_ops *ops)
  1911. {
  1912. ops->prepare_commit = sde_encoder_phys_cmd_prepare_commit;
  1913. ops->is_master = sde_encoder_phys_cmd_is_master;
  1914. ops->mode_set = sde_encoder_phys_cmd_mode_set;
  1915. ops->cont_splash_mode_set = sde_encoder_phys_cmd_cont_splash_mode_set;
  1916. ops->mode_fixup = sde_encoder_phys_cmd_mode_fixup;
  1917. ops->enable = sde_encoder_phys_cmd_enable;
  1918. ops->disable = sde_encoder_phys_cmd_disable;
  1919. ops->destroy = sde_encoder_phys_cmd_destroy;
  1920. ops->get_hw_resources = sde_encoder_phys_cmd_get_hw_resources;
  1921. ops->control_vblank_irq = sde_encoder_phys_cmd_control_vblank_irq;
  1922. ops->wait_for_commit_done = sde_encoder_phys_cmd_wait_for_commit_done;
  1923. ops->prepare_for_kickoff = sde_encoder_phys_cmd_prepare_for_kickoff;
  1924. ops->wait_for_tx_complete = sde_encoder_phys_cmd_wait_for_tx_complete;
  1925. ops->wait_for_vblank = sde_encoder_phys_cmd_wait_for_vblank;
  1926. ops->trigger_flush = sde_encoder_helper_trigger_flush;
  1927. ops->trigger_start = sde_encoder_phys_cmd_trigger_start;
  1928. ops->needs_single_flush = sde_encoder_phys_needs_single_flush;
  1929. ops->hw_reset = sde_encoder_helper_hw_reset;
  1930. ops->irq_control = sde_encoder_phys_cmd_irq_control;
  1931. ops->dynamic_irq_control = sde_encoder_phys_cmd_dynamic_irq_control;
  1932. ops->update_split_role = sde_encoder_phys_cmd_update_split_role;
  1933. ops->restore = sde_encoder_phys_cmd_enable_helper;
  1934. ops->control_te = sde_encoder_phys_cmd_connect_te;
  1935. ops->is_autorefresh_enabled =
  1936. sde_encoder_phys_cmd_is_autorefresh_enabled;
  1937. ops->get_line_count = sde_encoder_phys_cmd_te_get_line_count;
  1938. ops->wait_for_active = NULL;
  1939. ops->setup_vsync_source = sde_encoder_phys_cmd_setup_vsync_source;
  1940. ops->setup_misr = sde_encoder_helper_setup_misr;
  1941. ops->collect_misr = sde_encoder_helper_collect_misr;
  1942. ops->add_to_minidump = sde_encoder_phys_cmd_add_enc_to_minidump;
  1943. ops->disable_autorefresh = _sde_encoder_phys_disable_autorefresh;
  1944. ops->idle_pc_cache_display_status = sde_encoder_phys_cmd_store_ltj_values;
  1945. }
  1946. static inline bool sde_encoder_phys_cmd_intf_te_supported(
  1947. const struct sde_mdss_cfg *sde_cfg, enum sde_intf idx)
  1948. {
  1949. if (sde_cfg && ((idx - INTF_0) < sde_cfg->intf_count))
  1950. return test_bit(SDE_INTF_TE,
  1951. &(sde_cfg->intf[idx - INTF_0].features));
  1952. return false;
  1953. }
  1954. static void _sde_encoder_phys_cmd_init_irqs(struct sde_encoder_phys *phys_enc)
  1955. {
  1956. struct sde_encoder_irq *irq;
  1957. int i;
  1958. for (i = 0; i < INTR_IDX_MAX; i++) {
  1959. irq = &phys_enc->irq[i];
  1960. INIT_LIST_HEAD(&irq->cb.list);
  1961. irq->irq_idx = -EINVAL;
  1962. irq->hw_idx = -EINVAL;
  1963. irq->cb.arg = phys_enc;
  1964. }
  1965. irq = &phys_enc->irq[INTR_IDX_CTL_START];
  1966. irq->name = "ctl_start";
  1967. irq->intr_type = SDE_IRQ_TYPE_CTL_START;
  1968. irq->intr_idx = INTR_IDX_CTL_START;
  1969. irq->cb.func = NULL;
  1970. irq = &phys_enc->irq[INTR_IDX_CTL_DONE];
  1971. irq->name = "ctl_done";
  1972. irq->intr_type = SDE_IRQ_TYPE_CTL_DONE;
  1973. irq->intr_idx = INTR_IDX_CTL_DONE;
  1974. irq->cb.func = sde_encoder_phys_cmd_ctl_done_irq;
  1975. irq = &phys_enc->irq[INTR_IDX_PINGPONG];
  1976. irq->name = "pp_done";
  1977. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_COMP;
  1978. irq->intr_idx = INTR_IDX_PINGPONG;
  1979. irq->cb.func = sde_encoder_phys_cmd_pp_tx_done_irq;
  1980. irq = &phys_enc->irq[INTR_IDX_RDPTR];
  1981. irq->intr_idx = INTR_IDX_RDPTR;
  1982. irq->name = "te_rd_ptr";
  1983. if (phys_enc->has_intf_te)
  1984. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_RD_PTR;
  1985. else
  1986. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_RD_PTR;
  1987. irq->cb.func = sde_encoder_phys_cmd_te_rd_ptr_irq;
  1988. irq = &phys_enc->irq[INTR_IDX_AUTOREFRESH_DONE];
  1989. irq->name = "autorefresh_done";
  1990. if (phys_enc->has_intf_te)
  1991. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_AUTO_REF;
  1992. else
  1993. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_AUTO_REF;
  1994. irq->intr_idx = INTR_IDX_AUTOREFRESH_DONE;
  1995. irq->cb.func = sde_encoder_phys_cmd_autorefresh_done_irq;
  1996. irq = &phys_enc->irq[INTR_IDX_WRPTR];
  1997. irq->intr_idx = INTR_IDX_WRPTR;
  1998. irq->name = "wr_ptr";
  1999. if (phys_enc->has_intf_te)
  2000. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_WR_PTR;
  2001. else
  2002. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_WR_PTR;
  2003. irq->cb.func = sde_encoder_phys_cmd_wr_ptr_irq;
  2004. irq = &phys_enc->irq[INTF_IDX_TEAR_DETECT];
  2005. irq->intr_idx = INTF_IDX_TEAR_DETECT;
  2006. irq->name = "te_tear_detect";
  2007. if (phys_enc->has_intf_te)
  2008. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_TEAR_DETECT;
  2009. else
  2010. irq->intr_type = SDE_IRQ_TYPE_PING_PONG_TEAR_CHECK;
  2011. irq->cb.func = sde_encoder_phys_cmd_tear_detect_irq;
  2012. if (phys_enc->has_intf_te) {
  2013. irq = &phys_enc->irq[INTR_IDX_TE_ASSERT];
  2014. irq->intr_idx = INTR_IDX_TE_ASSERT;
  2015. irq->name = "te_assert";
  2016. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_TE_ASSERT;
  2017. irq->cb.func = sde_encoder_phys_cmd_te_assert_irq;
  2018. irq = &phys_enc->irq[INTR_IDX_TE_DEASSERT];
  2019. irq->intr_idx = INTR_IDX_TE_DEASSERT;
  2020. irq->name = "te_deassert";
  2021. irq->intr_type = SDE_IRQ_TYPE_INTF_TEAR_TE_DEASSERT;
  2022. irq->cb.func = sde_encoder_phys_cmd_te_deassert_irq;
  2023. }
  2024. }
  2025. struct sde_encoder_phys *sde_encoder_phys_cmd_init(
  2026. struct sde_enc_phys_init_params *p)
  2027. {
  2028. struct sde_encoder_phys *phys_enc = NULL;
  2029. struct sde_encoder_phys_cmd *cmd_enc = NULL;
  2030. struct sde_hw_mdp *hw_mdp;
  2031. int i, ret = 0;
  2032. SDE_DEBUG("intf %d\n", p->intf_idx - INTF_0);
  2033. cmd_enc = kzalloc(sizeof(*cmd_enc), GFP_KERNEL);
  2034. if (!cmd_enc) {
  2035. ret = -ENOMEM;
  2036. SDE_ERROR("failed to allocate\n");
  2037. goto fail;
  2038. }
  2039. phys_enc = &cmd_enc->base;
  2040. hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm);
  2041. if (IS_ERR_OR_NULL(hw_mdp)) {
  2042. ret = PTR_ERR(hw_mdp);
  2043. SDE_ERROR("failed to get mdptop\n");
  2044. goto fail_mdp_init;
  2045. }
  2046. phys_enc->hw_mdptop = hw_mdp;
  2047. phys_enc->intf_idx = p->intf_idx;
  2048. phys_enc->parent = p->parent;
  2049. phys_enc->parent_ops = p->parent_ops;
  2050. phys_enc->sde_kms = p->sde_kms;
  2051. phys_enc->split_role = p->split_role;
  2052. phys_enc->intf_mode = INTF_MODE_CMD;
  2053. phys_enc->enc_spinlock = p->enc_spinlock;
  2054. phys_enc->vblank_ctl_lock = p->vblank_ctl_lock;
  2055. cmd_enc->stream_sel = 0;
  2056. phys_enc->enable_state = SDE_ENC_DISABLED;
  2057. phys_enc->kickoff_timeout_ms = DEFAULT_KICKOFF_TIMEOUT_MS;
  2058. sde_encoder_phys_cmd_init_ops(&phys_enc->ops);
  2059. phys_enc->comp_type = p->comp_type;
  2060. phys_enc->has_intf_te = sde_encoder_phys_cmd_intf_te_supported(
  2061. phys_enc->sde_kms->catalog, phys_enc->intf_idx);
  2062. _sde_encoder_phys_cmd_init_irqs(phys_enc);
  2063. atomic_set(&phys_enc->vblank_refcount, 0);
  2064. atomic_set(&phys_enc->pending_kickoff_cnt, 0);
  2065. atomic_set(&phys_enc->pending_retire_fence_cnt, 0);
  2066. atomic_set(&cmd_enc->pending_vblank_cnt, 0);
  2067. init_waitqueue_head(&phys_enc->pending_kickoff_wq);
  2068. init_waitqueue_head(&cmd_enc->pending_vblank_wq);
  2069. atomic_set(&cmd_enc->autorefresh.kickoff_cnt, 0);
  2070. init_waitqueue_head(&cmd_enc->autorefresh.kickoff_wq);
  2071. INIT_LIST_HEAD(&cmd_enc->te_timestamp_list);
  2072. for (i = 0; i < MAX_TE_PROFILE_COUNT; i++)
  2073. list_add(&cmd_enc->te_timestamp[i].list,
  2074. &cmd_enc->te_timestamp_list);
  2075. SDE_DEBUG_CMDENC(cmd_enc, "created\n");
  2076. return phys_enc;
  2077. fail_mdp_init:
  2078. kfree(cmd_enc);
  2079. fail:
  2080. return ERR_PTR(ret);
  2081. }