sde_encoder_phys_cmd.c 48 KB

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