sde_encoder_phys_cmd.c 59 KB

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