sde_encoder_phys_cmd.c 72 KB

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