sde_encoder_phys_cmd.c 58 KB

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