sde_encoder_phys_cmd.c 58 KB

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