sde_encoder_phys_cmd.c 59 KB

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