sde_encoder_phys_cmd.c 59 KB

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