sde_encoder_phys_cmd.c 48 KB

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