dp_display.c 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2022, Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #include <linux/module.h>
  7. #include <linux/slab.h>
  8. #include <linux/uaccess.h>
  9. #include <linux/debugfs.h>
  10. #include <linux/component.h>
  11. #include <linux/of_irq.h>
  12. #include <linux/delay.h>
  13. #include <linux/soc/qcom/fsa4480-i2c.h>
  14. #include <linux/usb/phy.h>
  15. #include <linux/jiffies.h>
  16. #include <linux/pm_qos.h>
  17. #include <linux/ipc_logging.h>
  18. #include "sde_connector.h"
  19. #include "msm_drv.h"
  20. #include "dp_hpd.h"
  21. #include "dp_parser.h"
  22. #include "dp_power.h"
  23. #include "dp_catalog.h"
  24. #include "dp_aux.h"
  25. #include "dp_link.h"
  26. #include "dp_panel.h"
  27. #include "dp_ctrl.h"
  28. #include "dp_audio.h"
  29. #include "dp_display.h"
  30. #include "sde_hdcp.h"
  31. #include "dp_debug.h"
  32. #include "dp_pll.h"
  33. #include "sde_dbg.h"
  34. #define DRM_DP_IPC_NUM_PAGES 10
  35. #define DP_MST_DEBUG(fmt, ...) DP_DEBUG(fmt, ##__VA_ARGS__)
  36. #define dp_display_state_show(x) { \
  37. DP_ERR("%s: state (0x%x): %s\n", x, dp->state, \
  38. dp_display_state_name(dp->state)); \
  39. SDE_EVT32_EXTERNAL(dp->state); }
  40. #define dp_display_state_warn(x) { \
  41. DP_WARN("%s: state (0x%x): %s\n", x, dp->state, \
  42. dp_display_state_name(dp->state)); \
  43. SDE_EVT32_EXTERNAL(dp->state); }
  44. #define dp_display_state_log(x) { \
  45. DP_DEBUG("%s: state (0x%x): %s\n", x, dp->state, \
  46. dp_display_state_name(dp->state)); \
  47. SDE_EVT32_EXTERNAL(dp->state); }
  48. #define dp_display_state_is(x) (dp->state & (x))
  49. #define dp_display_state_add(x) { \
  50. (dp->state |= (x)); \
  51. dp_display_state_log("add "#x); }
  52. #define dp_display_state_remove(x) { \
  53. (dp->state &= ~(x)); \
  54. dp_display_state_log("remove "#x); }
  55. enum dp_display_states {
  56. DP_STATE_DISCONNECTED = 0,
  57. DP_STATE_CONFIGURED = BIT(0),
  58. DP_STATE_INITIALIZED = BIT(1),
  59. DP_STATE_READY = BIT(2),
  60. DP_STATE_CONNECTED = BIT(3),
  61. DP_STATE_CONNECT_NOTIFIED = BIT(4),
  62. DP_STATE_DISCONNECT_NOTIFIED = BIT(5),
  63. DP_STATE_ENABLED = BIT(6),
  64. DP_STATE_SUSPENDED = BIT(7),
  65. DP_STATE_ABORTED = BIT(8),
  66. DP_STATE_HDCP_ABORTED = BIT(9),
  67. DP_STATE_SRC_PWRDN = BIT(10),
  68. DP_STATE_TUI_ACTIVE = BIT(11),
  69. };
  70. static char *dp_display_state_name(enum dp_display_states state)
  71. {
  72. static char buf[SZ_1K];
  73. u32 len = 0;
  74. memset(buf, 0, SZ_1K);
  75. if (state & DP_STATE_CONFIGURED)
  76. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  77. "CONFIGURED");
  78. if (state & DP_STATE_INITIALIZED)
  79. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  80. "INITIALIZED");
  81. if (state & DP_STATE_READY)
  82. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  83. "READY");
  84. if (state & DP_STATE_CONNECTED)
  85. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  86. "CONNECTED");
  87. if (state & DP_STATE_CONNECT_NOTIFIED)
  88. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  89. "CONNECT_NOTIFIED");
  90. if (state & DP_STATE_DISCONNECT_NOTIFIED)
  91. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  92. "DISCONNECT_NOTIFIED");
  93. if (state & DP_STATE_ENABLED)
  94. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  95. "ENABLED");
  96. if (state & DP_STATE_SUSPENDED)
  97. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  98. "SUSPENDED");
  99. if (state & DP_STATE_ABORTED)
  100. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  101. "ABORTED");
  102. if (state & DP_STATE_HDCP_ABORTED)
  103. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  104. "HDCP_ABORTED");
  105. if (state & DP_STATE_SRC_PWRDN)
  106. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  107. "SRC_PWRDN");
  108. if (state & DP_STATE_TUI_ACTIVE)
  109. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  110. "TUI_ACTIVE");
  111. if (!strlen(buf))
  112. return "DISCONNECTED";
  113. return buf;
  114. }
  115. static struct dp_display *g_dp_display;
  116. #define HPD_STRING_SIZE 30
  117. struct dp_hdcp_dev {
  118. void *fd;
  119. struct sde_hdcp_ops *ops;
  120. enum sde_hdcp_version ver;
  121. };
  122. struct dp_hdcp {
  123. void *data;
  124. struct sde_hdcp_ops *ops;
  125. u32 source_cap;
  126. struct dp_hdcp_dev dev[HDCP_VERSION_MAX];
  127. };
  128. struct dp_mst {
  129. bool mst_active;
  130. bool drm_registered;
  131. struct dp_mst_drm_cbs cbs;
  132. };
  133. struct dp_display_private {
  134. char *name;
  135. int irq;
  136. enum drm_connector_status cached_connector_status;
  137. enum dp_display_states state;
  138. struct platform_device *pdev;
  139. struct device_node *aux_switch_node;
  140. bool aux_switch_ready;
  141. struct dp_aux_bridge *aux_bridge;
  142. struct dentry *root;
  143. struct completion notification_comp;
  144. struct completion attention_comp;
  145. struct dp_hpd *hpd;
  146. struct dp_parser *parser;
  147. struct dp_power *power;
  148. struct dp_catalog *catalog;
  149. struct dp_aux *aux;
  150. struct dp_link *link;
  151. struct dp_panel *panel;
  152. struct dp_ctrl *ctrl;
  153. struct dp_debug *debug;
  154. struct dp_pll *pll;
  155. struct dp_panel *active_panels[DP_STREAM_MAX];
  156. struct dp_hdcp hdcp;
  157. struct dp_hpd_cb hpd_cb;
  158. struct dp_display_mode mode;
  159. struct dp_display dp_display;
  160. struct msm_drm_private *priv;
  161. struct workqueue_struct *wq;
  162. struct delayed_work hdcp_cb_work;
  163. struct work_struct connect_work;
  164. struct work_struct attention_work;
  165. struct mutex session_lock;
  166. struct mutex accounting_lock;
  167. bool hdcp_delayed_off;
  168. bool no_aux_switch;
  169. u32 active_stream_cnt;
  170. struct dp_mst mst;
  171. u32 tot_dsc_blks_in_use;
  172. u32 tot_lm_blks_in_use;
  173. bool process_hpd_connect;
  174. struct dev_pm_qos_request pm_qos_req[NR_CPUS];
  175. bool pm_qos_requested;
  176. struct notifier_block usb_nb;
  177. };
  178. static const struct of_device_id dp_dt_match[] = {
  179. {.compatible = "qcom,dp-display"},
  180. {}
  181. };
  182. static inline bool dp_display_is_hdcp_enabled(struct dp_display_private *dp)
  183. {
  184. return dp->link->hdcp_status.hdcp_version && dp->hdcp.ops;
  185. }
  186. static irqreturn_t dp_display_irq(int irq, void *dev_id)
  187. {
  188. struct dp_display_private *dp = dev_id;
  189. if (!dp) {
  190. DP_ERR("invalid data\n");
  191. return IRQ_NONE;
  192. }
  193. /* DP HPD isr */
  194. if (dp->hpd->type == DP_HPD_LPHW)
  195. dp->hpd->isr(dp->hpd);
  196. /* DP controller isr */
  197. dp->ctrl->isr(dp->ctrl);
  198. /* DP aux isr */
  199. dp->aux->isr(dp->aux);
  200. /* HDCP isr */
  201. if (dp_display_is_hdcp_enabled(dp) && dp->hdcp.ops->isr) {
  202. if (dp->hdcp.ops->isr(dp->hdcp.data))
  203. DP_ERR("dp_hdcp_isr failed\n");
  204. }
  205. return IRQ_HANDLED;
  206. }
  207. static bool dp_display_is_ds_bridge(struct dp_panel *panel)
  208. {
  209. return (panel->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
  210. DP_DWN_STRM_PORT_PRESENT);
  211. }
  212. static bool dp_display_is_sink_count_zero(struct dp_display_private *dp)
  213. {
  214. return dp_display_is_ds_bridge(dp->panel) &&
  215. (dp->link->sink_count.count == 0);
  216. }
  217. static bool dp_display_is_ready(struct dp_display_private *dp)
  218. {
  219. return dp->hpd->hpd_high && dp_display_state_is(DP_STATE_CONNECTED) &&
  220. !dp_display_is_sink_count_zero(dp) &&
  221. dp->hpd->alt_mode_cfg_done;
  222. }
  223. static void dp_audio_enable(struct dp_display_private *dp, bool enable)
  224. {
  225. struct dp_panel *dp_panel;
  226. int idx;
  227. for (idx = DP_STREAM_0; idx < DP_STREAM_MAX; idx++) {
  228. if (!dp->active_panels[idx])
  229. continue;
  230. dp_panel = dp->active_panels[idx];
  231. if (dp_panel->audio_supported) {
  232. if (enable) {
  233. dp_panel->audio->bw_code =
  234. dp->link->link_params.bw_code;
  235. dp_panel->audio->lane_count =
  236. dp->link->link_params.lane_count;
  237. dp_panel->audio->on(dp_panel->audio);
  238. } else {
  239. dp_panel->audio->off(dp_panel->audio);
  240. }
  241. }
  242. }
  243. }
  244. static void dp_display_qos_request(struct dp_display_private *dp, bool add_vote)
  245. {
  246. struct device *cpu_dev;
  247. int cpu = 0;
  248. struct cpumask *cpu_mask;
  249. u32 latency = dp->parser->qos_cpu_latency;
  250. unsigned long mask = dp->parser->qos_cpu_mask;
  251. if (!dp->parser->qos_cpu_mask || (dp->pm_qos_requested == add_vote))
  252. return;
  253. cpu_mask = to_cpumask(&mask);
  254. for_each_cpu(cpu, cpu_mask) {
  255. cpu_dev = get_cpu_device(cpu);
  256. if (!cpu_dev) {
  257. SDE_DEBUG("%s: failed to get cpu%d device\n", __func__, cpu);
  258. continue;
  259. }
  260. if (add_vote)
  261. dev_pm_qos_add_request(cpu_dev, &dp->pm_qos_req[cpu],
  262. DEV_PM_QOS_RESUME_LATENCY, latency);
  263. else
  264. dev_pm_qos_remove_request(&dp->pm_qos_req[cpu]);
  265. }
  266. SDE_EVT32_EXTERNAL(add_vote, mask, latency);
  267. dp->pm_qos_requested = add_vote;
  268. }
  269. static void dp_display_update_hdcp_status(struct dp_display_private *dp,
  270. bool reset)
  271. {
  272. if (reset) {
  273. dp->link->hdcp_status.hdcp_state = HDCP_STATE_INACTIVE;
  274. dp->link->hdcp_status.hdcp_version = HDCP_VERSION_NONE;
  275. }
  276. memset(dp->debug->hdcp_status, 0, sizeof(dp->debug->hdcp_status));
  277. snprintf(dp->debug->hdcp_status, sizeof(dp->debug->hdcp_status),
  278. "%s: %s\ncaps: %d\n",
  279. sde_hdcp_version(dp->link->hdcp_status.hdcp_version),
  280. sde_hdcp_state_name(dp->link->hdcp_status.hdcp_state),
  281. dp->hdcp.source_cap);
  282. }
  283. static void dp_display_update_hdcp_info(struct dp_display_private *dp)
  284. {
  285. void *fd = NULL;
  286. struct dp_hdcp_dev *dev = NULL;
  287. struct sde_hdcp_ops *ops = NULL;
  288. int i = HDCP_VERSION_2P2;
  289. dp_display_update_hdcp_status(dp, true);
  290. dp->hdcp.data = NULL;
  291. dp->hdcp.ops = NULL;
  292. if (dp->debug->hdcp_disabled || dp->debug->sim_mode)
  293. return;
  294. while (i) {
  295. dev = &dp->hdcp.dev[i];
  296. ops = dev->ops;
  297. fd = dev->fd;
  298. i >>= 1;
  299. if (!(dp->hdcp.source_cap & dev->ver))
  300. continue;
  301. if (ops->sink_support(fd)) {
  302. dp->hdcp.data = fd;
  303. dp->hdcp.ops = ops;
  304. dp->link->hdcp_status.hdcp_version = dev->ver;
  305. break;
  306. }
  307. }
  308. DP_DEBUG("HDCP version supported: %s\n",
  309. sde_hdcp_version(dp->link->hdcp_status.hdcp_version));
  310. }
  311. static void dp_display_check_source_hdcp_caps(struct dp_display_private *dp)
  312. {
  313. int i;
  314. struct dp_hdcp_dev *hdcp_dev = dp->hdcp.dev;
  315. if (dp->debug->hdcp_disabled) {
  316. DP_DEBUG("hdcp disabled\n");
  317. return;
  318. }
  319. for (i = 0; i < HDCP_VERSION_MAX; i++) {
  320. struct dp_hdcp_dev *dev = &hdcp_dev[i];
  321. struct sde_hdcp_ops *ops = dev->ops;
  322. void *fd = dev->fd;
  323. if (!fd || !ops)
  324. continue;
  325. if (ops->set_mode && ops->set_mode(fd, dp->mst.mst_active))
  326. continue;
  327. if (!(dp->hdcp.source_cap & dev->ver) &&
  328. ops->feature_supported &&
  329. ops->feature_supported(fd))
  330. dp->hdcp.source_cap |= dev->ver;
  331. }
  332. dp_display_update_hdcp_status(dp, false);
  333. }
  334. static void dp_display_hdcp_register_streams(struct dp_display_private *dp)
  335. {
  336. int rc;
  337. size_t i;
  338. struct sde_hdcp_ops *ops = dp->hdcp.ops;
  339. void *data = dp->hdcp.data;
  340. if (dp_display_is_ready(dp) && dp->mst.mst_active && ops &&
  341. ops->register_streams){
  342. struct stream_info streams[DP_STREAM_MAX];
  343. int index = 0;
  344. DP_DEBUG("Registering all active panel streams with HDCP\n");
  345. for (i = DP_STREAM_0; i < DP_STREAM_MAX; i++) {
  346. if (!dp->active_panels[i])
  347. continue;
  348. streams[index].stream_id = i;
  349. streams[index].virtual_channel =
  350. dp->active_panels[i]->vcpi;
  351. index++;
  352. }
  353. if (index > 0) {
  354. rc = ops->register_streams(data, index, streams);
  355. if (rc)
  356. DP_ERR("failed to register streams. rc = %d\n",
  357. rc);
  358. }
  359. }
  360. }
  361. static void dp_display_hdcp_deregister_stream(struct dp_display_private *dp,
  362. enum dp_stream_id stream_id)
  363. {
  364. if (dp->hdcp.ops->deregister_streams && dp->active_panels[stream_id]) {
  365. struct stream_info stream = {stream_id,
  366. dp->active_panels[stream_id]->vcpi};
  367. DP_DEBUG("Deregistering stream within HDCP library\n");
  368. dp->hdcp.ops->deregister_streams(dp->hdcp.data, 1, &stream);
  369. }
  370. }
  371. static void dp_display_hdcp_process_delayed_off(struct dp_display_private *dp)
  372. {
  373. if (dp->hdcp_delayed_off) {
  374. if (dp->hdcp.ops && dp->hdcp.ops->off)
  375. dp->hdcp.ops->off(dp->hdcp.data);
  376. dp_display_update_hdcp_status(dp, true);
  377. dp->hdcp_delayed_off = false;
  378. }
  379. }
  380. static int dp_display_hdcp_process_sink_sync(struct dp_display_private *dp)
  381. {
  382. u8 sink_status = 0;
  383. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY);
  384. if (dp->debug->hdcp_wait_sink_sync) {
  385. drm_dp_dpcd_readb(dp->aux->drm_aux, DP_SINK_STATUS,
  386. &sink_status);
  387. sink_status &= (DP_RECEIVE_PORT_0_STATUS |
  388. DP_RECEIVE_PORT_1_STATUS);
  389. if (sink_status < 1) {
  390. DP_DEBUG("Sink not synchronized. Queuing again then exiting\n");
  391. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ);
  392. return -EAGAIN;
  393. }
  394. /*
  395. * Some sinks need more time to stabilize after synchronization
  396. * and before it can handle an HDCP authentication request.
  397. * Adding the delay for better interoperability.
  398. */
  399. msleep(6000);
  400. }
  401. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT);
  402. return 0;
  403. }
  404. static int dp_display_hdcp_start(struct dp_display_private *dp)
  405. {
  406. if (dp->link->hdcp_status.hdcp_state != HDCP_STATE_INACTIVE)
  407. return -EINVAL;
  408. dp_display_check_source_hdcp_caps(dp);
  409. dp_display_update_hdcp_info(dp);
  410. if (dp_display_is_hdcp_enabled(dp)) {
  411. if (dp->hdcp.ops && dp->hdcp.ops->on &&
  412. dp->hdcp.ops->on(dp->hdcp.data)) {
  413. dp_display_update_hdcp_status(dp, true);
  414. return 0;
  415. }
  416. } else {
  417. dp_display_update_hdcp_status(dp, true);
  418. return 0;
  419. }
  420. return -EINVAL;
  421. }
  422. static void dp_display_hdcp_print_auth_state(struct dp_display_private *dp)
  423. {
  424. u32 hdcp_auth_state;
  425. int rc;
  426. rc = dp->catalog->ctrl.read_hdcp_status(&dp->catalog->ctrl);
  427. if (rc >= 0) {
  428. hdcp_auth_state = (rc >> 20) & 0x3;
  429. DP_DEBUG("hdcp auth state %d\n", hdcp_auth_state);
  430. }
  431. }
  432. static void dp_display_hdcp_process_state(struct dp_display_private *dp)
  433. {
  434. struct dp_link_hdcp_status *status;
  435. struct sde_hdcp_ops *ops;
  436. void *data;
  437. int rc = 0;
  438. status = &dp->link->hdcp_status;
  439. ops = dp->hdcp.ops;
  440. data = dp->hdcp.data;
  441. if (status->hdcp_state != HDCP_STATE_AUTHENTICATED &&
  442. dp->debug->force_encryption && ops && ops->force_encryption)
  443. ops->force_encryption(data, dp->debug->force_encryption);
  444. if (status->hdcp_state == HDCP_STATE_AUTHENTICATED)
  445. dp_display_qos_request(dp, false);
  446. else
  447. dp_display_qos_request(dp, true);
  448. switch (status->hdcp_state) {
  449. case HDCP_STATE_INACTIVE:
  450. dp_display_hdcp_register_streams(dp);
  451. if (dp->hdcp.ops && dp->hdcp.ops->authenticate)
  452. rc = dp->hdcp.ops->authenticate(data);
  453. if (!rc)
  454. status->hdcp_state = HDCP_STATE_AUTHENTICATING;
  455. break;
  456. case HDCP_STATE_AUTH_FAIL:
  457. if (dp_display_is_ready(dp) &&
  458. dp_display_state_is(DP_STATE_ENABLED)) {
  459. if (ops && ops->on && ops->on(data)) {
  460. dp_display_update_hdcp_status(dp, true);
  461. return;
  462. }
  463. dp_display_hdcp_register_streams(dp);
  464. if (ops && ops->reauthenticate) {
  465. rc = ops->reauthenticate(data);
  466. if (rc)
  467. DP_ERR("failed rc=%d\n", rc);
  468. }
  469. status->hdcp_state = HDCP_STATE_AUTHENTICATING;
  470. } else {
  471. DP_DEBUG("not reauthenticating, cable disconnected\n");
  472. }
  473. break;
  474. default:
  475. dp_display_hdcp_register_streams(dp);
  476. break;
  477. }
  478. }
  479. static void dp_display_abort_hdcp(struct dp_display_private *dp,
  480. bool abort)
  481. {
  482. u8 i = HDCP_VERSION_2P2;
  483. struct dp_hdcp_dev *dev = NULL;
  484. while (i) {
  485. dev = &dp->hdcp.dev[i];
  486. i >>= 1;
  487. if (!(dp->hdcp.source_cap & dev->ver))
  488. continue;
  489. dev->ops->abort(dev->fd, abort);
  490. }
  491. }
  492. static void dp_display_hdcp_cb_work(struct work_struct *work)
  493. {
  494. struct dp_display_private *dp;
  495. struct delayed_work *dw = to_delayed_work(work);
  496. struct dp_link_hdcp_status *status;
  497. int rc = 0;
  498. dp = container_of(dw, struct dp_display_private, hdcp_cb_work);
  499. if (!dp_display_state_is(DP_STATE_ENABLED | DP_STATE_CONNECTED) ||
  500. dp_display_state_is(DP_STATE_ABORTED | DP_STATE_HDCP_ABORTED))
  501. return;
  502. if (dp_display_state_is(DP_STATE_SUSPENDED)) {
  503. DP_DEBUG("System suspending. Delay HDCP operations\n");
  504. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ);
  505. return;
  506. }
  507. dp_display_hdcp_process_delayed_off(dp);
  508. rc = dp_display_hdcp_process_sink_sync(dp);
  509. if (rc)
  510. return;
  511. rc = dp_display_hdcp_start(dp);
  512. if (!rc)
  513. return;
  514. dp_display_hdcp_print_auth_state(dp);
  515. status = &dp->link->hdcp_status;
  516. DP_DEBUG("%s: %s\n", sde_hdcp_version(status->hdcp_version),
  517. sde_hdcp_state_name(status->hdcp_state));
  518. dp_display_update_hdcp_status(dp, false);
  519. dp_display_hdcp_process_state(dp);
  520. }
  521. static void dp_display_notify_hdcp_status_cb(void *ptr,
  522. enum sde_hdcp_state state)
  523. {
  524. struct dp_display_private *dp = ptr;
  525. if (!dp) {
  526. DP_ERR("invalid input\n");
  527. return;
  528. }
  529. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY,
  530. dp->link->hdcp_status.hdcp_state);
  531. dp->link->hdcp_status.hdcp_state = state;
  532. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ/4);
  533. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT,
  534. dp->link->hdcp_status.hdcp_state);
  535. }
  536. static void dp_display_deinitialize_hdcp(struct dp_display_private *dp)
  537. {
  538. if (!dp) {
  539. DP_ERR("invalid input\n");
  540. return;
  541. }
  542. sde_hdcp_1x_deinit(dp->hdcp.dev[HDCP_VERSION_1X].fd);
  543. sde_dp_hdcp2p2_deinit(dp->hdcp.dev[HDCP_VERSION_2P2].fd);
  544. }
  545. static int dp_display_initialize_hdcp(struct dp_display_private *dp)
  546. {
  547. struct sde_hdcp_init_data hdcp_init_data;
  548. struct dp_parser *parser;
  549. void *fd;
  550. int rc = 0;
  551. if (!dp) {
  552. DP_ERR("invalid input\n");
  553. return -EINVAL;
  554. }
  555. parser = dp->parser;
  556. hdcp_init_data.client_id = HDCP_CLIENT_DP;
  557. hdcp_init_data.drm_aux = dp->aux->drm_aux;
  558. hdcp_init_data.cb_data = (void *)dp;
  559. hdcp_init_data.workq = dp->wq;
  560. hdcp_init_data.sec_access = true;
  561. hdcp_init_data.notify_status = dp_display_notify_hdcp_status_cb;
  562. hdcp_init_data.dp_ahb = &parser->get_io(parser, "dp_ahb")->io;
  563. hdcp_init_data.dp_aux = &parser->get_io(parser, "dp_aux")->io;
  564. hdcp_init_data.dp_link = &parser->get_io(parser, "dp_link")->io;
  565. hdcp_init_data.dp_p0 = &parser->get_io(parser, "dp_p0")->io;
  566. hdcp_init_data.hdcp_io = &parser->get_io(parser,
  567. "hdcp_physical")->io;
  568. hdcp_init_data.revision = &dp->panel->link_info.revision;
  569. hdcp_init_data.msm_hdcp_dev = dp->parser->msm_hdcp_dev;
  570. fd = sde_hdcp_1x_init(&hdcp_init_data);
  571. if (IS_ERR_OR_NULL(fd)) {
  572. DP_DEBUG("Error initializing HDCP 1.x\n");
  573. return -EINVAL;
  574. }
  575. dp->hdcp.dev[HDCP_VERSION_1X].fd = fd;
  576. dp->hdcp.dev[HDCP_VERSION_1X].ops = sde_hdcp_1x_get(fd);
  577. dp->hdcp.dev[HDCP_VERSION_1X].ver = HDCP_VERSION_1X;
  578. DP_INFO("HDCP 1.3 initialized\n");
  579. fd = sde_dp_hdcp2p2_init(&hdcp_init_data);
  580. if (IS_ERR_OR_NULL(fd)) {
  581. DP_DEBUG("Error initializing HDCP 2.x\n");
  582. rc = -EINVAL;
  583. goto error;
  584. }
  585. dp->hdcp.dev[HDCP_VERSION_2P2].fd = fd;
  586. dp->hdcp.dev[HDCP_VERSION_2P2].ops = sde_dp_hdcp2p2_get(fd);
  587. dp->hdcp.dev[HDCP_VERSION_2P2].ver = HDCP_VERSION_2P2;
  588. DP_INFO("HDCP 2.2 initialized\n");
  589. return 0;
  590. error:
  591. sde_hdcp_1x_deinit(dp->hdcp.dev[HDCP_VERSION_1X].fd);
  592. return rc;
  593. }
  594. static void dp_display_pause_audio(struct dp_display_private *dp, bool pause)
  595. {
  596. struct dp_panel *dp_panel;
  597. int idx;
  598. for (idx = DP_STREAM_0; idx < DP_STREAM_MAX; idx++) {
  599. if (!dp->active_panels[idx])
  600. continue;
  601. dp_panel = dp->active_panels[idx];
  602. if (dp_panel->audio_supported)
  603. dp_panel->audio->tui_active = pause;
  604. }
  605. }
  606. static int dp_display_pre_hw_release(void *data)
  607. {
  608. struct dp_display_private *dp;
  609. struct dp_display *dp_display = data;
  610. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY);
  611. if (!dp_display)
  612. return -EINVAL;
  613. dp = container_of(dp_display, struct dp_display_private, dp_display);
  614. mutex_lock(&dp->session_lock);
  615. dp_display_state_add(DP_STATE_TUI_ACTIVE);
  616. cancel_work_sync(&dp->connect_work);
  617. cancel_work_sync(&dp->attention_work);
  618. flush_workqueue(dp->wq);
  619. dp_display_pause_audio(dp, true);
  620. disable_irq(dp->irq);
  621. mutex_unlock(&dp->session_lock);
  622. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT);
  623. return 0;
  624. }
  625. static int dp_display_post_hw_acquire(void *data)
  626. {
  627. struct dp_display_private *dp;
  628. struct dp_display *dp_display = data;
  629. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY);
  630. if (!dp_display)
  631. return -EINVAL;
  632. dp = container_of(dp_display, struct dp_display_private, dp_display);
  633. mutex_lock(&dp->session_lock);
  634. dp_display_state_remove(DP_STATE_TUI_ACTIVE);
  635. dp_display_pause_audio(dp, false);
  636. enable_irq(dp->irq);
  637. mutex_unlock(&dp->session_lock);
  638. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT);
  639. return 0;
  640. }
  641. static int dp_display_bind(struct device *dev, struct device *master,
  642. void *data)
  643. {
  644. int rc = 0;
  645. struct dp_display_private *dp;
  646. struct drm_device *drm;
  647. struct platform_device *pdev = to_platform_device(dev);
  648. struct msm_vm_ops vm_event_ops = {
  649. .vm_pre_hw_release = dp_display_pre_hw_release,
  650. .vm_post_hw_acquire = dp_display_post_hw_acquire,
  651. };
  652. if (!dev || !pdev || !master) {
  653. DP_ERR("invalid param(s), dev %pK, pdev %pK, master %pK\n",
  654. dev, pdev, master);
  655. rc = -EINVAL;
  656. goto end;
  657. }
  658. drm = dev_get_drvdata(master);
  659. dp = platform_get_drvdata(pdev);
  660. if (!drm || !dp) {
  661. DP_ERR("invalid param(s), drm %pK, dp %pK\n",
  662. drm, dp);
  663. rc = -EINVAL;
  664. goto end;
  665. }
  666. dp->dp_display.drm_dev = drm;
  667. dp->priv = drm->dev_private;
  668. msm_register_vm_event(master, dev, &vm_event_ops,
  669. (void *)&dp->dp_display);
  670. end:
  671. return rc;
  672. }
  673. static void dp_display_unbind(struct device *dev, struct device *master,
  674. void *data)
  675. {
  676. struct dp_display_private *dp;
  677. struct platform_device *pdev = to_platform_device(dev);
  678. if (!dev || !pdev) {
  679. DP_ERR("invalid param(s)\n");
  680. return;
  681. }
  682. dp = platform_get_drvdata(pdev);
  683. if (!dp) {
  684. DP_ERR("Invalid params\n");
  685. return;
  686. }
  687. if (dp->power)
  688. (void)dp->power->power_client_deinit(dp->power);
  689. if (dp->aux)
  690. (void)dp->aux->drm_aux_deregister(dp->aux);
  691. dp_display_deinitialize_hdcp(dp);
  692. }
  693. static const struct component_ops dp_display_comp_ops = {
  694. .bind = dp_display_bind,
  695. .unbind = dp_display_unbind,
  696. };
  697. static bool dp_display_send_hpd_event(struct dp_display_private *dp)
  698. {
  699. struct drm_device *dev = NULL;
  700. struct drm_connector *connector;
  701. char name[HPD_STRING_SIZE], status[HPD_STRING_SIZE],
  702. bpp[HPD_STRING_SIZE], pattern[HPD_STRING_SIZE];
  703. char *envp[5];
  704. struct dp_display *display;
  705. int rc = 0;
  706. connector = dp->dp_display.base_connector;
  707. display = &dp->dp_display;
  708. if (!connector) {
  709. DP_ERR("connector not set\n");
  710. return false;
  711. }
  712. connector->status = display->is_sst_connected ? connector_status_connected :
  713. connector_status_disconnected;
  714. if (dp->cached_connector_status == connector->status) {
  715. DP_DEBUG("connector status (%d) unchanged, skipping uevent\n",
  716. dp->cached_connector_status);
  717. return false;
  718. }
  719. dp->cached_connector_status = connector->status;
  720. dev = connector->dev;
  721. if (dp->debug->skip_uevent) {
  722. DP_INFO("skipping uevent\n");
  723. return false;
  724. }
  725. snprintf(name, HPD_STRING_SIZE, "name=%s", connector->name);
  726. snprintf(status, HPD_STRING_SIZE, "status=%s",
  727. drm_get_connector_status_name(connector->status));
  728. snprintf(bpp, HPD_STRING_SIZE, "bpp=%d",
  729. dp_link_bit_depth_to_bpp(
  730. dp->link->test_video.test_bit_depth));
  731. snprintf(pattern, HPD_STRING_SIZE, "pattern=%d",
  732. dp->link->test_video.test_video_pattern);
  733. DP_INFO("[%s]:[%s] [%s] [%s]\n", name, status, bpp, pattern);
  734. envp[0] = name;
  735. envp[1] = status;
  736. envp[2] = bpp;
  737. envp[3] = pattern;
  738. envp[4] = NULL;
  739. rc = kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, envp);
  740. DP_INFO("uevent %s: %d\n", rc ? "failure" : "success", rc);
  741. return true;
  742. }
  743. static int dp_display_send_hpd_notification(struct dp_display_private *dp)
  744. {
  745. int ret = 0;
  746. bool hpd = !!dp_display_state_is(DP_STATE_CONNECTED);
  747. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state, hpd);
  748. /*
  749. * Send the notification only if there is any change. This check is
  750. * necessary since it is possible that the connect_work may or may not
  751. * skip sending the notification in order to respond to a pending
  752. * attention message. Attention work thread will always attempt to
  753. * send the notification after successfully handling the attention
  754. * message. This check here will avoid any unintended duplicate
  755. * notifications.
  756. */
  757. if (dp_display_state_is(DP_STATE_CONNECT_NOTIFIED) && hpd) {
  758. DP_DEBUG("connection notified already, skip notification\n");
  759. goto skip_wait;
  760. } else if (dp_display_state_is(DP_STATE_DISCONNECT_NOTIFIED) && !hpd) {
  761. DP_DEBUG("disonnect notified already, skip notification\n");
  762. goto skip_wait;
  763. }
  764. dp->aux->state |= DP_STATE_NOTIFICATION_SENT;
  765. reinit_completion(&dp->notification_comp);
  766. if (!dp->mst.mst_active) {
  767. dp->dp_display.is_sst_connected = hpd;
  768. if (!dp_display_send_hpd_event(dp))
  769. goto skip_wait;
  770. } else {
  771. dp->dp_display.is_sst_connected = false;
  772. if (!dp->mst.cbs.hpd)
  773. goto skip_wait;
  774. dp->mst.cbs.hpd(&dp->dp_display, hpd);
  775. }
  776. if (hpd) {
  777. dp_display_state_add(DP_STATE_CONNECT_NOTIFIED);
  778. dp_display_state_remove(DP_STATE_DISCONNECT_NOTIFIED);
  779. } else {
  780. dp_display_state_add(DP_STATE_DISCONNECT_NOTIFIED);
  781. dp_display_state_remove(DP_STATE_CONNECT_NOTIFIED);
  782. }
  783. /*
  784. * Skip the wait if TUI is active considering that the user mode will
  785. * not act on the notification until after the TUI session is over.
  786. */
  787. if (dp_display_state_is(DP_STATE_TUI_ACTIVE)) {
  788. dp_display_state_log("[TUI is active, skipping wait]");
  789. goto skip_wait;
  790. }
  791. if (hpd && dp->mst.mst_active)
  792. goto skip_wait;
  793. if (!dp->mst.mst_active &&
  794. (!!dp_display_state_is(DP_STATE_ENABLED) == hpd))
  795. goto skip_wait;
  796. if (!wait_for_completion_timeout(&dp->notification_comp,
  797. HZ * 5)) {
  798. DP_WARN("%s timeout\n", hpd ? "connect" : "disconnect");
  799. ret = -EINVAL;
  800. }
  801. skip_wait:
  802. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, hpd, ret);
  803. return ret;
  804. }
  805. static void dp_display_update_mst_state(struct dp_display_private *dp,
  806. bool state)
  807. {
  808. dp->mst.mst_active = state;
  809. dp->panel->mst_state = state;
  810. }
  811. static void dp_display_mst_init(struct dp_display_private *dp)
  812. {
  813. bool is_mst_receiver;
  814. const unsigned long clear_mstm_ctrl_timeout_us = 100000;
  815. u8 old_mstm_ctrl;
  816. int ret;
  817. if (!dp->parser->has_mst || !dp->mst.drm_registered) {
  818. DP_MST_DEBUG("mst not enabled. has_mst:%d, registered:%d\n",
  819. dp->parser->has_mst, dp->mst.drm_registered);
  820. return;
  821. }
  822. is_mst_receiver = dp->panel->read_mst_cap(dp->panel);
  823. if (!is_mst_receiver) {
  824. DP_MST_DEBUG("sink doesn't support mst\n");
  825. return;
  826. }
  827. /* clear sink mst state */
  828. drm_dp_dpcd_readb(dp->aux->drm_aux, DP_MSTM_CTRL, &old_mstm_ctrl);
  829. drm_dp_dpcd_writeb(dp->aux->drm_aux, DP_MSTM_CTRL, 0);
  830. /* add extra delay if MST state is not cleared */
  831. if (old_mstm_ctrl) {
  832. DP_MST_DEBUG("MSTM_CTRL is not cleared, wait %luus\n",
  833. clear_mstm_ctrl_timeout_us);
  834. usleep_range(clear_mstm_ctrl_timeout_us,
  835. clear_mstm_ctrl_timeout_us + 1000);
  836. }
  837. ret = drm_dp_dpcd_writeb(dp->aux->drm_aux, DP_MSTM_CTRL,
  838. DP_MST_EN | DP_UP_REQ_EN | DP_UPSTREAM_IS_SRC);
  839. if (ret < 0) {
  840. DP_ERR("sink mst enablement failed\n");
  841. return;
  842. }
  843. dp_display_update_mst_state(dp, true);
  844. }
  845. static void dp_display_set_mst_mgr_state(struct dp_display_private *dp,
  846. bool state)
  847. {
  848. if (!dp->mst.mst_active)
  849. return;
  850. if (dp->mst.cbs.set_mgr_state)
  851. dp->mst.cbs.set_mgr_state(&dp->dp_display, state);
  852. DP_MST_DEBUG("mst_mgr_state: %d\n", state);
  853. }
  854. static int dp_display_host_init(struct dp_display_private *dp)
  855. {
  856. bool flip = false;
  857. bool reset;
  858. int rc = 0;
  859. if (dp_display_state_is(DP_STATE_INITIALIZED)) {
  860. dp_display_state_log("[already initialized]");
  861. return rc;
  862. }
  863. if (dp->hpd->orientation == ORIENTATION_CC2)
  864. flip = true;
  865. reset = dp->debug->sim_mode ? false : !dp->hpd->multi_func;
  866. rc = dp->power->init(dp->power, flip);
  867. if (rc) {
  868. DP_WARN("Power init failed.\n");
  869. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_CASE1, dp->state);
  870. return rc;
  871. }
  872. dp->hpd->host_init(dp->hpd, &dp->catalog->hpd);
  873. rc = dp->ctrl->init(dp->ctrl, flip, reset);
  874. if (rc) {
  875. DP_WARN("Ctrl init Failed.\n");
  876. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_CASE2, dp->state);
  877. goto error_ctrl;
  878. }
  879. enable_irq(dp->irq);
  880. dp_display_abort_hdcp(dp, false);
  881. dp_display_state_add(DP_STATE_INITIALIZED);
  882. /* log this as it results from user action of cable connection */
  883. DP_INFO("[OK]\n");
  884. return rc;
  885. error_ctrl:
  886. dp->hpd->host_deinit(dp->hpd, &dp->catalog->hpd);
  887. dp->power->deinit(dp->power);
  888. return rc;
  889. }
  890. static int dp_display_host_ready(struct dp_display_private *dp)
  891. {
  892. int rc = 0;
  893. if (!dp_display_state_is(DP_STATE_INITIALIZED)) {
  894. rc = dp_display_host_init(dp);
  895. if (rc) {
  896. dp_display_state_show("[not initialized]");
  897. return rc;
  898. }
  899. }
  900. if (dp_display_state_is(DP_STATE_READY)) {
  901. dp_display_state_log("[already ready]");
  902. return rc;
  903. }
  904. /*
  905. * Reset the aborted state for AUX and CTRL modules. This will
  906. * allow these modules to execute normally in response to the
  907. * cable connection event.
  908. *
  909. * One corner case still exists. While the execution flow ensures
  910. * that cable disconnection flushes all pending work items on the DP
  911. * workqueue, and waits for the user module to clean up the DP
  912. * connection session, it is possible that the system delays can
  913. * lead to timeouts in the connect path. As a result, the actual
  914. * connection callback from user modules can come in late and can
  915. * race against a subsequent connection event here which would have
  916. * reset the aborted flags. There is no clear solution for this since
  917. * the connect/disconnect notifications do not currently have any
  918. * sessions IDs.
  919. */
  920. dp->aux->abort(dp->aux, false);
  921. dp->ctrl->abort(dp->ctrl, false);
  922. dp->aux->init(dp->aux, dp->parser->aux_cfg);
  923. dp->panel->init(dp->panel);
  924. dp_display_state_add(DP_STATE_READY);
  925. /* log this as it results from user action of cable connection */
  926. DP_INFO("[OK]\n");
  927. return rc;
  928. }
  929. static void dp_display_host_unready(struct dp_display_private *dp)
  930. {
  931. if (!dp_display_state_is(DP_STATE_INITIALIZED)) {
  932. dp_display_state_warn("[not initialized]");
  933. return;
  934. }
  935. if (!dp_display_state_is(DP_STATE_READY)) {
  936. dp_display_state_show("[not ready]");
  937. return;
  938. }
  939. dp_display_state_remove(DP_STATE_READY);
  940. dp->aux->deinit(dp->aux);
  941. /* log this as it results from user action of cable disconnection */
  942. DP_INFO("[OK]\n");
  943. }
  944. static void dp_display_host_deinit(struct dp_display_private *dp)
  945. {
  946. if (dp->active_stream_cnt) {
  947. SDE_EVT32_EXTERNAL(dp->state, dp->active_stream_cnt);
  948. DP_DEBUG("active stream present\n");
  949. return;
  950. }
  951. if (!dp_display_state_is(DP_STATE_INITIALIZED)) {
  952. dp_display_state_show("[not initialized]");
  953. return;
  954. }
  955. dp_display_abort_hdcp(dp, true);
  956. dp->ctrl->deinit(dp->ctrl);
  957. dp->hpd->host_deinit(dp->hpd, &dp->catalog->hpd);
  958. dp->power->deinit(dp->power);
  959. disable_irq(dp->irq);
  960. dp->aux->state = 0;
  961. dp_display_state_remove(DP_STATE_INITIALIZED);
  962. /* log this as it results from user action of cable dis-connection */
  963. DP_INFO("[OK]\n");
  964. }
  965. static int dp_display_process_hpd_high(struct dp_display_private *dp)
  966. {
  967. int rc = -EINVAL;
  968. unsigned long wait_timeout_ms;
  969. unsigned long t;
  970. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  971. mutex_lock(&dp->session_lock);
  972. if (dp_display_state_is(DP_STATE_CONNECTED)) {
  973. DP_DEBUG("dp already connected, skipping hpd high\n");
  974. mutex_unlock(&dp->session_lock);
  975. return -EISCONN;
  976. }
  977. dp_display_state_add(DP_STATE_CONNECTED);
  978. dp->dp_display.max_pclk_khz = min(dp->parser->max_pclk_khz,
  979. dp->debug->max_pclk_khz);
  980. /*
  981. * If dp video session is not restored from a previous session teardown
  982. * by userspace, ensure the host_init is executed, in such a scenario,
  983. * so that all the required DP resources are enabled.
  984. *
  985. * Below is one of the sequences of events which describe the above
  986. * scenario:
  987. * a. Source initiated power down resulting in host_deinit.
  988. * b. Sink issues hpd low attention without physical cable disconnect.
  989. * c. Source initiated power up sequence returns early because hpd is
  990. * not high.
  991. * d. Sink issues a hpd high attention event.
  992. */
  993. if (dp_display_state_is(DP_STATE_SRC_PWRDN) &&
  994. dp_display_state_is(DP_STATE_CONFIGURED)) {
  995. rc = dp_display_host_init(dp);
  996. if (rc) {
  997. DP_WARN("Host init Failed");
  998. if (!dp_display_state_is(DP_STATE_SUSPENDED)) {
  999. /*
  1000. * If not suspended no point of going forward if
  1001. * resource is not enabled.
  1002. */
  1003. dp_display_state_remove(DP_STATE_CONNECTED);
  1004. }
  1005. goto end;
  1006. }
  1007. /*
  1008. * If device is suspended and host_init fails, there is
  1009. * one more chance for host init to happen in prepare which
  1010. * is why DP_STATE_SRC_PWRDN is removed only at success.
  1011. */
  1012. dp_display_state_remove(DP_STATE_SRC_PWRDN);
  1013. }
  1014. rc = dp_display_host_ready(dp);
  1015. if (rc) {
  1016. dp_display_state_show("[ready failed]");
  1017. goto end;
  1018. }
  1019. dp->link->psm_config(dp->link, &dp->panel->link_info, false);
  1020. dp->debug->psm_enabled = false;
  1021. if (!dp->dp_display.base_connector)
  1022. goto end;
  1023. rc = dp->panel->read_sink_caps(dp->panel,
  1024. dp->dp_display.base_connector, dp->hpd->multi_func);
  1025. /*
  1026. * ETIMEDOUT --> cable may have been removed
  1027. * ENOTCONN --> no downstream device connected
  1028. */
  1029. if (rc == -ETIMEDOUT || rc == -ENOTCONN) {
  1030. dp_display_state_remove(DP_STATE_CONNECTED);
  1031. goto end;
  1032. }
  1033. dp->link->process_request(dp->link);
  1034. dp->panel->handle_sink_request(dp->panel);
  1035. dp_display_mst_init(dp);
  1036. rc = dp->ctrl->on(dp->ctrl, dp->mst.mst_active,
  1037. dp->panel->fec_en, dp->panel->dsc_en, false);
  1038. if (rc) {
  1039. dp_display_state_remove(DP_STATE_CONNECTED);
  1040. goto end;
  1041. }
  1042. dp->process_hpd_connect = false;
  1043. dp_display_set_mst_mgr_state(dp, true);
  1044. end:
  1045. mutex_unlock(&dp->session_lock);
  1046. /*
  1047. * Delay the HPD connect notification to see if sink generates any
  1048. * IRQ HPDs immediately after the HPD high.
  1049. */
  1050. reinit_completion(&dp->attention_comp);
  1051. wait_timeout_ms = min_t(unsigned long,
  1052. dp->debug->connect_notification_delay_ms,
  1053. (unsigned long) MAX_CONNECT_NOTIFICATION_DELAY_MS);
  1054. t = wait_for_completion_timeout(&dp->attention_comp,
  1055. msecs_to_jiffies(wait_timeout_ms));
  1056. DP_DEBUG("wait_timeout=%lu ms, time_waited=%u ms\n", wait_timeout_ms,
  1057. jiffies_to_msecs(t));
  1058. /*
  1059. * If an IRQ HPD is pending, then do not send a connect notification.
  1060. * Once this work returns, the IRQ HPD would be processed and any
  1061. * required actions (such as link maintenance) would be done which
  1062. * will subsequently send the HPD notification. To keep things simple,
  1063. * do this only for SST use-cases. MST use cases require additional
  1064. * care in order to handle the side-band communications as well.
  1065. *
  1066. * One of the main motivations for this is DP LL 1.4 CTS use case
  1067. * where it is possible that we could get a test request right after
  1068. * a connection, and the strict timing requriements of the test can
  1069. * only be met if we do not wait for the e2e connection to be set up.
  1070. */
  1071. if (!dp->mst.mst_active &&
  1072. (work_busy(&dp->attention_work) == WORK_BUSY_PENDING)) {
  1073. SDE_EVT32_EXTERNAL(dp->state, 99, jiffies_to_msecs(t));
  1074. DP_DEBUG("Attention pending, skip HPD notification\n");
  1075. goto skip_notify;
  1076. }
  1077. if (!rc && !dp_display_state_is(DP_STATE_ABORTED))
  1078. dp_display_send_hpd_notification(dp);
  1079. skip_notify:
  1080. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state,
  1081. wait_timeout_ms, rc);
  1082. return rc;
  1083. }
  1084. static void dp_display_process_mst_hpd_low(struct dp_display_private *dp)
  1085. {
  1086. int rc = 0;
  1087. if (dp->mst.mst_active) {
  1088. DP_MST_DEBUG("mst_hpd_low work\n");
  1089. /*
  1090. * HPD unplug callflow:
  1091. * 1. send hpd unplug on base connector so usermode can disable
  1092. * all external displays.
  1093. * 2. unset mst state in the topology mgr so the branch device
  1094. * can be cleaned up.
  1095. */
  1096. if ((dp_display_state_is(DP_STATE_CONNECT_NOTIFIED) ||
  1097. dp_display_state_is(DP_STATE_ENABLED)))
  1098. rc = dp_display_send_hpd_notification(dp);
  1099. dp_display_set_mst_mgr_state(dp, false);
  1100. dp_display_update_mst_state(dp, false);
  1101. }
  1102. DP_MST_DEBUG("mst_hpd_low. mst_active:%d\n", dp->mst.mst_active);
  1103. }
  1104. static int dp_display_process_hpd_low(struct dp_display_private *dp)
  1105. {
  1106. int rc = 0;
  1107. dp_display_state_remove(DP_STATE_CONNECTED);
  1108. dp->process_hpd_connect = false;
  1109. dp_audio_enable(dp, false);
  1110. if (dp->mst.mst_active) {
  1111. dp_display_process_mst_hpd_low(dp);
  1112. } else {
  1113. if ((dp_display_state_is(DP_STATE_CONNECT_NOTIFIED) ||
  1114. dp_display_state_is(DP_STATE_ENABLED)))
  1115. rc = dp_display_send_hpd_notification(dp);
  1116. }
  1117. mutex_lock(&dp->session_lock);
  1118. if (!dp->active_stream_cnt)
  1119. dp->ctrl->off(dp->ctrl);
  1120. mutex_unlock(&dp->session_lock);
  1121. dp->panel->video_test = false;
  1122. return rc;
  1123. }
  1124. static int dp_display_fsa4480_callback(struct notifier_block *self,
  1125. unsigned long event, void *data)
  1126. {
  1127. return 0;
  1128. }
  1129. static int dp_display_init_aux_switch(struct dp_display_private *dp)
  1130. {
  1131. int rc = 0;
  1132. struct notifier_block nb;
  1133. const u32 max_retries = 50;
  1134. u32 retry;
  1135. if (dp->aux_switch_ready)
  1136. return rc;
  1137. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY);
  1138. nb.notifier_call = dp_display_fsa4480_callback;
  1139. nb.priority = 0;
  1140. /*
  1141. * Iteratively wait for reg notifier which confirms that fsa driver is probed.
  1142. * Bootup DP with cable connected usecase can hit this scenario.
  1143. */
  1144. for (retry = 0; retry < max_retries; retry++) {
  1145. rc = fsa4480_reg_notifier(&nb, dp->aux_switch_node);
  1146. if (rc == 0) {
  1147. DP_DEBUG("registered notifier successfully\n");
  1148. dp->aux_switch_ready = true;
  1149. break;
  1150. } else {
  1151. DP_DEBUG("failed to register notifier retry=%d rc=%d\n", retry, rc);
  1152. msleep(100);
  1153. }
  1154. }
  1155. if (retry == max_retries) {
  1156. DP_WARN("Failed to register fsa notifier\n");
  1157. dp->aux_switch_ready = false;
  1158. return rc;
  1159. }
  1160. fsa4480_unreg_notifier(&nb, dp->aux_switch_node);
  1161. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, rc);
  1162. return rc;
  1163. }
  1164. static int dp_display_usbpd_configure_cb(struct device *dev)
  1165. {
  1166. int rc = 0;
  1167. struct dp_display_private *dp;
  1168. if (!dev) {
  1169. DP_ERR("invalid dev\n");
  1170. return -EINVAL;
  1171. }
  1172. dp = dev_get_drvdata(dev);
  1173. if (!dp) {
  1174. DP_ERR("no driver data found\n");
  1175. return -ENODEV;
  1176. }
  1177. if (!dp->debug->sim_mode && !dp->no_aux_switch
  1178. && !dp->parser->gpio_aux_switch && dp->aux_switch_node) {
  1179. rc = dp_display_init_aux_switch(dp);
  1180. if (rc)
  1181. return rc;
  1182. rc = dp->aux->aux_switch(dp->aux, true, dp->hpd->orientation);
  1183. if (rc)
  1184. return rc;
  1185. }
  1186. mutex_lock(&dp->session_lock);
  1187. if (dp_display_state_is(DP_STATE_TUI_ACTIVE)) {
  1188. dp_display_state_log("[TUI is active]");
  1189. mutex_unlock(&dp->session_lock);
  1190. return 0;
  1191. }
  1192. dp_display_state_remove(DP_STATE_ABORTED);
  1193. dp_display_state_add(DP_STATE_CONFIGURED);
  1194. rc = dp_display_host_init(dp);
  1195. if (rc) {
  1196. DP_ERR("Host init Failed");
  1197. mutex_unlock(&dp->session_lock);
  1198. return rc;
  1199. }
  1200. /* check for hpd high */
  1201. if (dp->hpd->hpd_high)
  1202. queue_work(dp->wq, &dp->connect_work);
  1203. else
  1204. dp->process_hpd_connect = true;
  1205. mutex_unlock(&dp->session_lock);
  1206. return 0;
  1207. }
  1208. static void dp_display_clear_reservation(struct dp_display *dp, struct dp_panel *panel)
  1209. {
  1210. struct dp_display_private *dp_display;
  1211. if (!dp || !panel) {
  1212. DP_ERR("invalid params\n");
  1213. return;
  1214. }
  1215. dp_display = container_of(dp, struct dp_display_private, dp_display);
  1216. mutex_lock(&dp_display->accounting_lock);
  1217. dp_display->tot_lm_blks_in_use -= panel->max_lm;
  1218. panel->max_lm = 0;
  1219. mutex_unlock(&dp_display->accounting_lock);
  1220. }
  1221. static void dp_display_clear_dsc_resources(struct dp_display_private *dp,
  1222. struct dp_panel *panel)
  1223. {
  1224. dp->tot_dsc_blks_in_use -= panel->dsc_blks_in_use;
  1225. panel->dsc_blks_in_use = 0;
  1226. }
  1227. static int dp_display_stream_pre_disable(struct dp_display_private *dp,
  1228. struct dp_panel *dp_panel)
  1229. {
  1230. if (!dp->active_stream_cnt) {
  1231. DP_WARN("streams already disabled cnt=%d\n",
  1232. dp->active_stream_cnt);
  1233. return 0;
  1234. }
  1235. dp->ctrl->stream_pre_off(dp->ctrl, dp_panel);
  1236. return 0;
  1237. }
  1238. static void dp_display_stream_disable(struct dp_display_private *dp,
  1239. struct dp_panel *dp_panel)
  1240. {
  1241. if (!dp->active_stream_cnt) {
  1242. DP_WARN("streams already disabled cnt=%d\n",
  1243. dp->active_stream_cnt);
  1244. return;
  1245. }
  1246. if (dp_panel->stream_id == DP_STREAM_MAX ||
  1247. !dp->active_panels[dp_panel->stream_id]) {
  1248. DP_ERR("panel is already disabled\n");
  1249. return;
  1250. }
  1251. dp_display_clear_dsc_resources(dp, dp_panel);
  1252. DP_DEBUG("stream_id=%d, active_stream_cnt=%d, tot_dsc_blks_in_use=%d\n",
  1253. dp_panel->stream_id, dp->active_stream_cnt,
  1254. dp->tot_dsc_blks_in_use);
  1255. dp->ctrl->stream_off(dp->ctrl, dp_panel);
  1256. dp->active_panels[dp_panel->stream_id] = NULL;
  1257. dp->active_stream_cnt--;
  1258. }
  1259. static void dp_display_clean(struct dp_display_private *dp)
  1260. {
  1261. int idx;
  1262. struct dp_panel *dp_panel;
  1263. struct dp_link_hdcp_status *status = &dp->link->hdcp_status;
  1264. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1265. if (dp_display_state_is(DP_STATE_TUI_ACTIVE)) {
  1266. DP_WARN("TUI is active\n");
  1267. return;
  1268. }
  1269. if (dp_display_is_hdcp_enabled(dp) &&
  1270. status->hdcp_state != HDCP_STATE_INACTIVE) {
  1271. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  1272. if (dp->hdcp.ops->off)
  1273. dp->hdcp.ops->off(dp->hdcp.data);
  1274. dp_display_update_hdcp_status(dp, true);
  1275. }
  1276. for (idx = DP_STREAM_0; idx < DP_STREAM_MAX; idx++) {
  1277. if (!dp->active_panels[idx])
  1278. continue;
  1279. dp_panel = dp->active_panels[idx];
  1280. if (dp_panel->audio_supported)
  1281. dp_panel->audio->off(dp_panel->audio);
  1282. dp_display_stream_pre_disable(dp, dp_panel);
  1283. dp_display_stream_disable(dp, dp_panel);
  1284. dp_display_clear_reservation(&dp->dp_display, dp_panel);
  1285. dp_panel->deinit(dp_panel, 0);
  1286. }
  1287. dp_display_state_remove(DP_STATE_ENABLED | DP_STATE_CONNECTED);
  1288. dp->ctrl->off(dp->ctrl);
  1289. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1290. }
  1291. static int dp_display_handle_disconnect(struct dp_display_private *dp)
  1292. {
  1293. int rc;
  1294. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1295. rc = dp_display_process_hpd_low(dp);
  1296. if (rc) {
  1297. /* cancel any pending request */
  1298. dp->ctrl->abort(dp->ctrl, true);
  1299. dp->aux->abort(dp->aux, true);
  1300. }
  1301. mutex_lock(&dp->session_lock);
  1302. if (dp_display_state_is(DP_STATE_ENABLED))
  1303. dp_display_clean(dp);
  1304. dp_display_host_unready(dp);
  1305. dp->tot_lm_blks_in_use = 0;
  1306. mutex_unlock(&dp->session_lock);
  1307. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1308. return rc;
  1309. }
  1310. static void dp_display_disconnect_sync(struct dp_display_private *dp)
  1311. {
  1312. int disconnect_delay_ms;
  1313. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1314. /* cancel any pending request */
  1315. dp_display_state_add(DP_STATE_ABORTED);
  1316. dp->ctrl->abort(dp->ctrl, true);
  1317. dp->aux->abort(dp->aux, true);
  1318. /* wait for idle state */
  1319. cancel_work_sync(&dp->connect_work);
  1320. cancel_work_sync(&dp->attention_work);
  1321. flush_workqueue(dp->wq);
  1322. /*
  1323. * Delay the teardown of the mainlink for better interop experience.
  1324. * It is possible that certain sinks can issue an HPD high immediately
  1325. * following an HPD low as soon as they detect the mainlink being
  1326. * turned off. This can sometimes result in the HPD low pulse getting
  1327. * lost with certain cable. This issue is commonly seen when running
  1328. * DP LL CTS test 4.2.1.3.
  1329. */
  1330. disconnect_delay_ms = min_t(u32, dp->debug->disconnect_delay_ms,
  1331. (u32) MAX_DISCONNECT_DELAY_MS);
  1332. DP_DEBUG("disconnect delay = %d ms\n", disconnect_delay_ms);
  1333. msleep(disconnect_delay_ms);
  1334. dp_display_handle_disconnect(dp);
  1335. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state,
  1336. disconnect_delay_ms);
  1337. }
  1338. static int dp_display_usbpd_disconnect_cb(struct device *dev)
  1339. {
  1340. int rc = 0;
  1341. struct dp_display_private *dp;
  1342. if (!dev) {
  1343. DP_ERR("invalid dev\n");
  1344. rc = -EINVAL;
  1345. goto end;
  1346. }
  1347. dp = dev_get_drvdata(dev);
  1348. if (!dp) {
  1349. DP_ERR("no driver data found\n");
  1350. rc = -ENODEV;
  1351. goto end;
  1352. }
  1353. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state,
  1354. dp->debug->psm_enabled);
  1355. /* skip if a disconnect is already in progress */
  1356. if (dp_display_state_is(DP_STATE_ABORTED) &&
  1357. dp_display_state_is(DP_STATE_READY)) {
  1358. DP_DEBUG("disconnect already in progress\n");
  1359. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_CASE1, dp->state);
  1360. return 0;
  1361. }
  1362. if (dp->debug->psm_enabled && dp_display_state_is(DP_STATE_READY))
  1363. dp->link->psm_config(dp->link, &dp->panel->link_info, true);
  1364. dp_display_disconnect_sync(dp);
  1365. mutex_lock(&dp->session_lock);
  1366. dp_display_host_deinit(dp);
  1367. dp_display_state_remove(DP_STATE_CONFIGURED);
  1368. mutex_unlock(&dp->session_lock);
  1369. if (!dp->debug->sim_mode && !dp->no_aux_switch
  1370. && !dp->parser->gpio_aux_switch)
  1371. dp->aux->aux_switch(dp->aux, false, ORIENTATION_NONE);
  1372. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1373. end:
  1374. return rc;
  1375. }
  1376. static int dp_display_stream_enable(struct dp_display_private *dp,
  1377. struct dp_panel *dp_panel)
  1378. {
  1379. int rc = 0;
  1380. rc = dp->ctrl->stream_on(dp->ctrl, dp_panel);
  1381. if (dp->debug->tpg_pattern)
  1382. dp_panel->tpg_config(dp_panel, dp->debug->tpg_pattern);
  1383. if (!rc) {
  1384. dp->active_panels[dp_panel->stream_id] = dp_panel;
  1385. dp->active_stream_cnt++;
  1386. }
  1387. DP_DEBUG("dp active_stream_cnt:%d, tot_dsc_blks_in_use=%d\n",
  1388. dp->active_stream_cnt, dp->tot_dsc_blks_in_use);
  1389. return rc;
  1390. }
  1391. static void dp_display_mst_attention(struct dp_display_private *dp)
  1392. {
  1393. if (dp->mst.mst_active && dp->mst.cbs.hpd_irq)
  1394. dp->mst.cbs.hpd_irq(&dp->dp_display);
  1395. DP_MST_DEBUG("mst_attention_work. mst_active:%d\n", dp->mst.mst_active);
  1396. }
  1397. static void dp_display_attention_work(struct work_struct *work)
  1398. {
  1399. struct dp_display_private *dp = container_of(work,
  1400. struct dp_display_private, attention_work);
  1401. int rc = 0;
  1402. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1403. mutex_lock(&dp->session_lock);
  1404. SDE_EVT32_EXTERNAL(dp->state);
  1405. if (dp_display_state_is(DP_STATE_ABORTED)) {
  1406. DP_INFO("Hpd off, not handling any attention\n");
  1407. mutex_unlock(&dp->session_lock);
  1408. goto exit;
  1409. }
  1410. if (!dp_display_state_is(DP_STATE_READY)) {
  1411. mutex_unlock(&dp->session_lock);
  1412. goto mst_attention;
  1413. }
  1414. if (dp->link->process_request(dp->link)) {
  1415. mutex_unlock(&dp->session_lock);
  1416. goto cp_irq;
  1417. }
  1418. mutex_unlock(&dp->session_lock);
  1419. SDE_EVT32_EXTERNAL(dp->state, dp->link->sink_request);
  1420. if (dp->link->sink_request & DS_PORT_STATUS_CHANGED) {
  1421. SDE_EVT32_EXTERNAL(dp->state, DS_PORT_STATUS_CHANGED);
  1422. if (!dp->mst.mst_active) {
  1423. if (dp_display_is_sink_count_zero(dp)) {
  1424. dp_display_handle_disconnect(dp);
  1425. } else {
  1426. /*
  1427. * connect work should take care of sending
  1428. * the HPD notification.
  1429. */
  1430. queue_work(dp->wq, &dp->connect_work);
  1431. }
  1432. }
  1433. goto mst_attention;
  1434. }
  1435. if (dp->link->sink_request & DP_TEST_LINK_VIDEO_PATTERN) {
  1436. SDE_EVT32_EXTERNAL(dp->state, DP_TEST_LINK_VIDEO_PATTERN);
  1437. dp_display_handle_disconnect(dp);
  1438. dp->panel->video_test = true;
  1439. /*
  1440. * connect work should take care of sending
  1441. * the HPD notification.
  1442. */
  1443. queue_work(dp->wq, &dp->connect_work);
  1444. goto mst_attention;
  1445. }
  1446. if (dp->link->sink_request & (DP_TEST_LINK_PHY_TEST_PATTERN |
  1447. DP_TEST_LINK_TRAINING | DP_LINK_STATUS_UPDATED)) {
  1448. mutex_lock(&dp->session_lock);
  1449. dp_audio_enable(dp, false);
  1450. if (dp->link->sink_request & DP_TEST_LINK_PHY_TEST_PATTERN) {
  1451. SDE_EVT32_EXTERNAL(dp->state,
  1452. DP_TEST_LINK_PHY_TEST_PATTERN);
  1453. dp->ctrl->process_phy_test_request(dp->ctrl);
  1454. }
  1455. if (dp->link->sink_request & DP_TEST_LINK_TRAINING) {
  1456. SDE_EVT32_EXTERNAL(dp->state, DP_TEST_LINK_TRAINING);
  1457. dp->link->send_test_response(dp->link);
  1458. rc = dp->ctrl->link_maintenance(dp->ctrl);
  1459. }
  1460. if (dp->link->sink_request & DP_LINK_STATUS_UPDATED) {
  1461. SDE_EVT32_EXTERNAL(dp->state, DP_LINK_STATUS_UPDATED);
  1462. rc = dp->ctrl->link_maintenance(dp->ctrl);
  1463. }
  1464. if (!rc)
  1465. dp_audio_enable(dp, true);
  1466. mutex_unlock(&dp->session_lock);
  1467. if (rc)
  1468. goto exit;
  1469. if (dp->link->sink_request & (DP_TEST_LINK_PHY_TEST_PATTERN |
  1470. DP_TEST_LINK_TRAINING))
  1471. goto mst_attention;
  1472. }
  1473. cp_irq:
  1474. if (dp_display_is_hdcp_enabled(dp) && dp->hdcp.ops->cp_irq)
  1475. dp->hdcp.ops->cp_irq(dp->hdcp.data);
  1476. if (!dp->mst.mst_active) {
  1477. /*
  1478. * It is possible that the connect_work skipped sending
  1479. * the HPD notification if the attention message was
  1480. * already pending. Send the notification here to
  1481. * account for that. This is not needed if this
  1482. * attention work was handling a test request
  1483. */
  1484. dp_display_send_hpd_notification(dp);
  1485. }
  1486. mst_attention:
  1487. dp_display_mst_attention(dp);
  1488. exit:
  1489. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1490. }
  1491. static int dp_display_usbpd_attention_cb(struct device *dev)
  1492. {
  1493. struct dp_display_private *dp;
  1494. if (!dev) {
  1495. DP_ERR("invalid dev\n");
  1496. return -EINVAL;
  1497. }
  1498. dp = dev_get_drvdata(dev);
  1499. if (!dp) {
  1500. DP_ERR("no driver data found\n");
  1501. return -ENODEV;
  1502. }
  1503. DP_DEBUG("hpd_irq:%d, hpd_high:%d, power_on:%d, is_connected:%d\n",
  1504. dp->hpd->hpd_irq, dp->hpd->hpd_high,
  1505. !!dp_display_state_is(DP_STATE_ENABLED),
  1506. !!dp_display_state_is(DP_STATE_CONNECTED));
  1507. SDE_EVT32_EXTERNAL(dp->state, dp->hpd->hpd_irq, dp->hpd->hpd_high,
  1508. !!dp_display_state_is(DP_STATE_ENABLED),
  1509. !!dp_display_state_is(DP_STATE_CONNECTED));
  1510. if (!dp->hpd->hpd_high) {
  1511. dp_display_disconnect_sync(dp);
  1512. return 0;
  1513. }
  1514. /*
  1515. * Ignore all the attention messages except HPD LOW when TUI is
  1516. * active, so user mode can be notified of the disconnect event. This
  1517. * allows user mode to tear down the control path after the TUI
  1518. * session is over. Ideally this should never happen, but on the off
  1519. * chance that there is a race condition in which there is a IRQ HPD
  1520. * during tear down of DP at TUI start then this check might help avoid
  1521. * a potential issue accessing registers in attention processing.
  1522. */
  1523. if (dp_display_state_is(DP_STATE_TUI_ACTIVE)) {
  1524. DP_WARN("TUI is active\n");
  1525. return 0;
  1526. }
  1527. if (dp->hpd->hpd_irq && dp_display_state_is(DP_STATE_READY)) {
  1528. queue_work(dp->wq, &dp->attention_work);
  1529. complete_all(&dp->attention_comp);
  1530. } else if (dp->process_hpd_connect ||
  1531. !dp_display_state_is(DP_STATE_CONNECTED)) {
  1532. dp_display_state_remove(DP_STATE_ABORTED);
  1533. queue_work(dp->wq, &dp->connect_work);
  1534. } else {
  1535. DP_DEBUG("ignored\n");
  1536. }
  1537. return 0;
  1538. }
  1539. static void dp_display_connect_work(struct work_struct *work)
  1540. {
  1541. int rc = 0;
  1542. struct dp_display_private *dp = container_of(work,
  1543. struct dp_display_private, connect_work);
  1544. if (dp_display_state_is(DP_STATE_TUI_ACTIVE)) {
  1545. dp_display_state_log("[TUI is active]");
  1546. return;
  1547. }
  1548. if (dp_display_state_is(DP_STATE_ABORTED)) {
  1549. DP_WARN("HPD off requested\n");
  1550. return;
  1551. }
  1552. if (!dp->hpd->hpd_high) {
  1553. DP_WARN("Sink disconnected\n");
  1554. return;
  1555. }
  1556. rc = dp_display_process_hpd_high(dp);
  1557. if (!rc && dp->panel->video_test)
  1558. dp->link->send_test_response(dp->link);
  1559. }
  1560. static int dp_display_usb_notifier(struct notifier_block *nb,
  1561. unsigned long action, void *data)
  1562. {
  1563. struct dp_display_private *dp = container_of(nb,
  1564. struct dp_display_private, usb_nb);
  1565. SDE_EVT32_EXTERNAL(dp->state, dp->debug->sim_mode, action);
  1566. if (!action && dp->debug->sim_mode) {
  1567. DP_WARN("usb disconnected during simulation\n");
  1568. dp_display_disconnect_sync(dp);
  1569. dp->debug->abort(dp->debug);
  1570. }
  1571. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, NOTIFY_DONE);
  1572. return NOTIFY_DONE;
  1573. }
  1574. static void dp_display_register_usb_notifier(struct dp_display_private *dp)
  1575. {
  1576. int rc = 0;
  1577. const char *phandle = "usb-phy";
  1578. struct usb_phy *usbphy;
  1579. usbphy = devm_usb_get_phy_by_phandle(&dp->pdev->dev, phandle, 0);
  1580. if (IS_ERR_OR_NULL(usbphy)) {
  1581. DP_DEBUG("unable to get usbphy\n");
  1582. return;
  1583. }
  1584. dp->usb_nb.notifier_call = dp_display_usb_notifier;
  1585. dp->usb_nb.priority = 2;
  1586. rc = usb_register_notifier(usbphy, &dp->usb_nb);
  1587. if (rc)
  1588. DP_DEBUG("failed to register for usb event: %d\n", rc);
  1589. }
  1590. int dp_display_mmrm_callback(struct mmrm_client_notifier_data *notifier_data)
  1591. {
  1592. struct dss_clk_mmrm_cb *mmrm_cb_data = (struct dss_clk_mmrm_cb *)notifier_data->pvt_data;
  1593. struct dp_display *dp_display = (struct dp_display *)mmrm_cb_data->phandle;
  1594. struct dp_display_private *dp =
  1595. container_of(dp_display, struct dp_display_private, dp_display);
  1596. int ret = 0;
  1597. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state, notifier_data->cb_type);
  1598. if (notifier_data->cb_type == MMRM_CLIENT_RESOURCE_VALUE_CHANGE
  1599. && dp_display_state_is(DP_STATE_ENABLED)
  1600. && !dp_display_state_is(DP_STATE_ABORTED)) {
  1601. ret = dp_display_handle_disconnect(dp);
  1602. if (ret)
  1603. DP_ERR("mmrm callback error reducing clk, ret:%d\n", ret);
  1604. }
  1605. DP_DEBUG("mmrm callback handled, state: 0x%x rc:%d\n", dp->state, ret);
  1606. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, notifier_data->cb_type);
  1607. return ret;
  1608. }
  1609. static void dp_display_deinit_sub_modules(struct dp_display_private *dp)
  1610. {
  1611. dp_debug_put(dp->debug);
  1612. dp_hpd_put(dp->hpd);
  1613. if (dp->panel)
  1614. dp_audio_put(dp->panel->audio);
  1615. dp_ctrl_put(dp->ctrl);
  1616. dp_panel_put(dp->panel);
  1617. dp_link_put(dp->link);
  1618. dp_power_put(dp->power);
  1619. dp_pll_put(dp->pll);
  1620. dp_aux_put(dp->aux);
  1621. dp_catalog_put(dp->catalog);
  1622. dp_parser_put(dp->parser);
  1623. mutex_destroy(&dp->session_lock);
  1624. }
  1625. static int dp_init_sub_modules(struct dp_display_private *dp)
  1626. {
  1627. int rc = 0;
  1628. u32 dp_core_revision = 0;
  1629. bool hdcp_disabled;
  1630. const char *phandle = "qcom,dp-aux-switch";
  1631. struct device *dev = &dp->pdev->dev;
  1632. struct dp_hpd_cb *cb = &dp->hpd_cb;
  1633. struct dp_ctrl_in ctrl_in = {
  1634. .dev = dev,
  1635. };
  1636. struct dp_panel_in panel_in = {
  1637. .dev = dev,
  1638. };
  1639. struct dp_debug_in debug_in = {
  1640. .dev = dev,
  1641. };
  1642. struct dp_pll_in pll_in = {
  1643. .pdev = dp->pdev,
  1644. };
  1645. mutex_init(&dp->session_lock);
  1646. mutex_init(&dp->accounting_lock);
  1647. dp->parser = dp_parser_get(dp->pdev);
  1648. if (IS_ERR(dp->parser)) {
  1649. rc = PTR_ERR(dp->parser);
  1650. DP_ERR("failed to initialize parser, rc = %d\n", rc);
  1651. dp->parser = NULL;
  1652. goto error;
  1653. }
  1654. rc = dp->parser->parse(dp->parser);
  1655. if (rc) {
  1656. DP_ERR("device tree parsing failed\n");
  1657. goto error_catalog;
  1658. }
  1659. g_dp_display->is_mst_supported = dp->parser->has_mst;
  1660. g_dp_display->dsc_cont_pps = dp->parser->dsc_continuous_pps;
  1661. dp->catalog = dp_catalog_get(dev, dp->parser);
  1662. if (IS_ERR(dp->catalog)) {
  1663. rc = PTR_ERR(dp->catalog);
  1664. DP_ERR("failed to initialize catalog, rc = %d\n", rc);
  1665. dp->catalog = NULL;
  1666. goto error_catalog;
  1667. }
  1668. dp_core_revision = dp_catalog_get_dp_core_version(dp->catalog);
  1669. dp->aux_switch_node = of_parse_phandle(dp->pdev->dev.of_node, phandle, 0);
  1670. if (!dp->aux_switch_node) {
  1671. DP_DEBUG("cannot parse %s handle\n", phandle);
  1672. dp->no_aux_switch = true;
  1673. }
  1674. dp->aux = dp_aux_get(dev, &dp->catalog->aux, dp->parser,
  1675. dp->aux_switch_node, dp->aux_bridge);
  1676. if (IS_ERR(dp->aux)) {
  1677. rc = PTR_ERR(dp->aux);
  1678. DP_ERR("failed to initialize aux, rc = %d\n", rc);
  1679. dp->aux = NULL;
  1680. goto error_aux;
  1681. }
  1682. rc = dp->aux->drm_aux_register(dp->aux, dp->dp_display.drm_dev);
  1683. if (rc) {
  1684. DP_ERR("DRM DP AUX register failed\n");
  1685. goto error_pll;
  1686. }
  1687. pll_in.aux = dp->aux;
  1688. pll_in.parser = dp->parser;
  1689. pll_in.dp_core_revision = dp_core_revision;
  1690. dp->pll = dp_pll_get(&pll_in);
  1691. if (IS_ERR(dp->pll)) {
  1692. rc = PTR_ERR(dp->pll);
  1693. DP_ERR("failed to initialize pll, rc = %d\n", rc);
  1694. dp->pll = NULL;
  1695. goto error_pll;
  1696. }
  1697. dp->power = dp_power_get(dp->parser, dp->pll);
  1698. if (IS_ERR(dp->power)) {
  1699. rc = PTR_ERR(dp->power);
  1700. DP_ERR("failed to initialize power, rc = %d\n", rc);
  1701. dp->power = NULL;
  1702. goto error_power;
  1703. }
  1704. rc = dp->power->power_client_init(dp->power, &dp->priv->phandle,
  1705. dp->dp_display.drm_dev);
  1706. if (rc) {
  1707. DP_ERR("Power client create failed\n");
  1708. goto error_link;
  1709. }
  1710. rc = dp->power->power_mmrm_init(dp->power, &dp->priv->phandle,
  1711. (void *)&dp->dp_display, dp_display_mmrm_callback);
  1712. if (rc) {
  1713. DP_ERR("failed to initialize mmrm, rc = %d\n", rc);
  1714. goto error_link;
  1715. }
  1716. dp->link = dp_link_get(dev, dp->aux, dp_core_revision);
  1717. if (IS_ERR(dp->link)) {
  1718. rc = PTR_ERR(dp->link);
  1719. DP_ERR("failed to initialize link, rc = %d\n", rc);
  1720. dp->link = NULL;
  1721. goto error_link;
  1722. }
  1723. panel_in.aux = dp->aux;
  1724. panel_in.catalog = &dp->catalog->panel;
  1725. panel_in.link = dp->link;
  1726. panel_in.connector = dp->dp_display.base_connector;
  1727. panel_in.base_panel = NULL;
  1728. panel_in.parser = dp->parser;
  1729. dp->panel = dp_panel_get(&panel_in);
  1730. if (IS_ERR(dp->panel)) {
  1731. rc = PTR_ERR(dp->panel);
  1732. DP_ERR("failed to initialize panel, rc = %d\n", rc);
  1733. dp->panel = NULL;
  1734. goto error_panel;
  1735. }
  1736. ctrl_in.link = dp->link;
  1737. ctrl_in.panel = dp->panel;
  1738. ctrl_in.aux = dp->aux;
  1739. ctrl_in.power = dp->power;
  1740. ctrl_in.catalog = &dp->catalog->ctrl;
  1741. ctrl_in.parser = dp->parser;
  1742. ctrl_in.pll = dp->pll;
  1743. dp->ctrl = dp_ctrl_get(&ctrl_in);
  1744. if (IS_ERR(dp->ctrl)) {
  1745. rc = PTR_ERR(dp->ctrl);
  1746. DP_ERR("failed to initialize ctrl, rc = %d\n", rc);
  1747. dp->ctrl = NULL;
  1748. goto error_ctrl;
  1749. }
  1750. dp->panel->audio = dp_audio_get(dp->pdev, dp->panel,
  1751. &dp->catalog->audio);
  1752. if (IS_ERR(dp->panel->audio)) {
  1753. rc = PTR_ERR(dp->panel->audio);
  1754. DP_ERR("failed to initialize audio, rc = %d\n", rc);
  1755. dp->panel->audio = NULL;
  1756. goto error_audio;
  1757. }
  1758. memset(&dp->mst, 0, sizeof(dp->mst));
  1759. dp->active_stream_cnt = 0;
  1760. cb->configure = dp_display_usbpd_configure_cb;
  1761. cb->disconnect = dp_display_usbpd_disconnect_cb;
  1762. cb->attention = dp_display_usbpd_attention_cb;
  1763. dp->hpd = dp_hpd_get(dev, dp->parser, &dp->catalog->hpd,
  1764. dp->aux_bridge, cb);
  1765. if (IS_ERR(dp->hpd)) {
  1766. rc = PTR_ERR(dp->hpd);
  1767. DP_ERR("failed to initialize hpd, rc = %d\n", rc);
  1768. dp->hpd = NULL;
  1769. goto error_hpd;
  1770. }
  1771. hdcp_disabled = !!dp_display_initialize_hdcp(dp);
  1772. debug_in.panel = dp->panel;
  1773. debug_in.hpd = dp->hpd;
  1774. debug_in.link = dp->link;
  1775. debug_in.aux = dp->aux;
  1776. debug_in.connector = &dp->dp_display.base_connector;
  1777. debug_in.catalog = dp->catalog;
  1778. debug_in.parser = dp->parser;
  1779. debug_in.ctrl = dp->ctrl;
  1780. debug_in.pll = dp->pll;
  1781. debug_in.display = &dp->dp_display;
  1782. dp->debug = dp_debug_get(&debug_in);
  1783. if (IS_ERR(dp->debug)) {
  1784. rc = PTR_ERR(dp->debug);
  1785. DP_ERR("failed to initialize debug, rc = %d\n", rc);
  1786. dp->debug = NULL;
  1787. goto error_debug;
  1788. }
  1789. dp->cached_connector_status = connector_status_disconnected;
  1790. dp->tot_dsc_blks_in_use = 0;
  1791. dp->tot_lm_blks_in_use = 0;
  1792. dp->debug->hdcp_disabled = hdcp_disabled;
  1793. dp_display_update_hdcp_status(dp, true);
  1794. dp_display_register_usb_notifier(dp);
  1795. if (dp->hpd->register_hpd) {
  1796. rc = dp->hpd->register_hpd(dp->hpd);
  1797. if (rc) {
  1798. DP_ERR("failed register hpd\n");
  1799. goto error_hpd_reg;
  1800. }
  1801. }
  1802. return rc;
  1803. error_hpd_reg:
  1804. dp_debug_put(dp->debug);
  1805. error_debug:
  1806. dp_hpd_put(dp->hpd);
  1807. error_hpd:
  1808. dp_audio_put(dp->panel->audio);
  1809. error_audio:
  1810. dp_ctrl_put(dp->ctrl);
  1811. error_ctrl:
  1812. dp_panel_put(dp->panel);
  1813. error_panel:
  1814. dp_link_put(dp->link);
  1815. error_link:
  1816. dp_power_put(dp->power);
  1817. error_power:
  1818. dp_pll_put(dp->pll);
  1819. error_pll:
  1820. dp_aux_put(dp->aux);
  1821. error_aux:
  1822. dp_catalog_put(dp->catalog);
  1823. error_catalog:
  1824. dp_parser_put(dp->parser);
  1825. error:
  1826. mutex_destroy(&dp->session_lock);
  1827. return rc;
  1828. }
  1829. static int dp_display_post_init(struct dp_display *dp_display)
  1830. {
  1831. int rc = 0;
  1832. struct dp_display_private *dp;
  1833. if (!dp_display) {
  1834. DP_ERR("invalid input\n");
  1835. rc = -EINVAL;
  1836. goto end;
  1837. }
  1838. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1839. if (IS_ERR_OR_NULL(dp)) {
  1840. DP_ERR("invalid params\n");
  1841. rc = -EINVAL;
  1842. goto end;
  1843. }
  1844. rc = dp_init_sub_modules(dp);
  1845. if (rc)
  1846. goto end;
  1847. dp_display->post_init = NULL;
  1848. end:
  1849. DP_DEBUG("%s\n", rc ? "failed" : "success");
  1850. return rc;
  1851. }
  1852. static int dp_display_set_mode(struct dp_display *dp_display, void *panel,
  1853. struct dp_display_mode *mode)
  1854. {
  1855. const u32 num_components = 3, default_bpp = 24;
  1856. struct dp_display_private *dp;
  1857. struct dp_panel *dp_panel;
  1858. bool dsc_en = (mode->capabilities & DP_PANEL_CAPS_DSC) ? true : false;
  1859. if (!dp_display || !panel) {
  1860. DP_ERR("invalid input\n");
  1861. return -EINVAL;
  1862. }
  1863. dp_panel = panel;
  1864. if (!dp_panel->connector) {
  1865. DP_ERR("invalid connector input\n");
  1866. return -EINVAL;
  1867. }
  1868. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1869. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state,
  1870. mode->timing.h_active, mode->timing.v_active,
  1871. mode->timing.refresh_rate);
  1872. mutex_lock(&dp->session_lock);
  1873. mode->timing.bpp =
  1874. dp_panel->connector->display_info.bpc * num_components;
  1875. if (!mode->timing.bpp)
  1876. mode->timing.bpp = default_bpp;
  1877. mode->timing.bpp = dp->panel->get_mode_bpp(dp->panel,
  1878. mode->timing.bpp, mode->timing.pixel_clk_khz, dsc_en);
  1879. dp_panel->pinfo = mode->timing;
  1880. mutex_unlock(&dp->session_lock);
  1881. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1882. return 0;
  1883. }
  1884. static int dp_display_prepare(struct dp_display *dp_display, void *panel)
  1885. {
  1886. struct dp_display_private *dp;
  1887. struct dp_panel *dp_panel;
  1888. int rc = 0;
  1889. if (!dp_display || !panel) {
  1890. DP_ERR("invalid input\n");
  1891. return -EINVAL;
  1892. }
  1893. dp_panel = panel;
  1894. if (!dp_panel->connector) {
  1895. DP_ERR("invalid connector input\n");
  1896. return -EINVAL;
  1897. }
  1898. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1899. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1900. mutex_lock(&dp->session_lock);
  1901. /*
  1902. * If DP video session is restored by the userspace after display
  1903. * disconnect notification from dongle i.e. typeC cable connected to
  1904. * source but disconnected at the display side, the DP controller is
  1905. * not restored to the desired configured state. So, ensure host_init
  1906. * is executed in such a scenario so that all the DP controller
  1907. * resources are enabled for the next connection event.
  1908. */
  1909. if (dp_display_state_is(DP_STATE_SRC_PWRDN) &&
  1910. dp_display_state_is(DP_STATE_CONFIGURED)) {
  1911. rc = dp_display_host_init(dp);
  1912. if (rc) {
  1913. /*
  1914. * Skip all the events that are similar to abort case, just that
  1915. * the stream clks should be enabled so that no commit failure can
  1916. * be seen.
  1917. */
  1918. DP_ERR("Host init failed.\n");
  1919. goto end;
  1920. }
  1921. /*
  1922. * Remove DP_STATE_SRC_PWRDN flag on successful host_init to
  1923. * prevent cases such as below.
  1924. * 1. MST stream 1 failed to do host init then stream 2 can retry again.
  1925. * 2. Resume path fails, now sink sends hpd_high=0 and hpd_high=1.
  1926. */
  1927. dp_display_state_remove(DP_STATE_SRC_PWRDN);
  1928. }
  1929. /*
  1930. * If the physical connection to the sink is already lost by the time
  1931. * we try to set up the connection, we can just skip all the steps
  1932. * here safely.
  1933. */
  1934. if (dp_display_state_is(DP_STATE_ABORTED)) {
  1935. dp_display_state_log("[aborted]");
  1936. goto end;
  1937. }
  1938. /*
  1939. * If DP_STATE_ENABLED, there is nothing left to do.
  1940. * This would happen during MST flow. So, log this.
  1941. */
  1942. if (dp_display_state_is(DP_STATE_ENABLED)) {
  1943. dp_display_state_warn("[already enabled]");
  1944. goto end;
  1945. }
  1946. if (!dp_display_is_ready(dp)) {
  1947. dp_display_state_show("[not ready]");
  1948. goto end;
  1949. }
  1950. /* For supporting DP_PANEL_SRC_INITIATED_POWER_DOWN case */
  1951. rc = dp_display_host_ready(dp);
  1952. if (rc) {
  1953. dp_display_state_show("[ready failed]");
  1954. goto end;
  1955. }
  1956. if (dp->debug->psm_enabled) {
  1957. dp->link->psm_config(dp->link, &dp->panel->link_info, false);
  1958. dp->debug->psm_enabled = false;
  1959. }
  1960. /*
  1961. * Execute the dp controller power on in shallow mode here.
  1962. * In normal cases, controller should have been powered on
  1963. * by now. In some cases like suspend/resume or framework
  1964. * reboot, we end up here without a powered on controller.
  1965. * Cable may have been removed in suspended state. In that
  1966. * case, link training is bound to fail on system resume.
  1967. * So, we execute in shallow mode here to do only minimal
  1968. * and required things.
  1969. */
  1970. rc = dp->ctrl->on(dp->ctrl, dp->mst.mst_active, dp_panel->fec_en,
  1971. dp_panel->dsc_en, true);
  1972. if (rc)
  1973. goto end;
  1974. end:
  1975. mutex_unlock(&dp->session_lock);
  1976. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, rc);
  1977. return rc;
  1978. }
  1979. static int dp_display_set_stream_info(struct dp_display *dp_display,
  1980. void *panel, u32 strm_id, u32 start_slot,
  1981. u32 num_slots, u32 pbn, int vcpi)
  1982. {
  1983. int rc = 0;
  1984. struct dp_panel *dp_panel;
  1985. struct dp_display_private *dp;
  1986. const int max_slots = 64;
  1987. if (!dp_display) {
  1988. DP_ERR("invalid input\n");
  1989. return -EINVAL;
  1990. }
  1991. if (strm_id >= DP_STREAM_MAX) {
  1992. DP_ERR("invalid stream id:%d\n", strm_id);
  1993. return -EINVAL;
  1994. }
  1995. if (start_slot + num_slots > max_slots) {
  1996. DP_ERR("invalid channel info received. start:%d, slots:%d\n",
  1997. start_slot, num_slots);
  1998. return -EINVAL;
  1999. }
  2000. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2001. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state, strm_id,
  2002. start_slot, num_slots);
  2003. mutex_lock(&dp->session_lock);
  2004. dp->ctrl->set_mst_channel_info(dp->ctrl, strm_id,
  2005. start_slot, num_slots);
  2006. if (panel) {
  2007. dp_panel = panel;
  2008. dp_panel->set_stream_info(dp_panel, strm_id, start_slot,
  2009. num_slots, pbn, vcpi);
  2010. }
  2011. mutex_unlock(&dp->session_lock);
  2012. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, rc);
  2013. return rc;
  2014. }
  2015. static int dp_display_enable(struct dp_display *dp_display, void *panel)
  2016. {
  2017. int rc = 0;
  2018. struct dp_display_private *dp;
  2019. if (!dp_display || !panel) {
  2020. DP_ERR("invalid input\n");
  2021. return -EINVAL;
  2022. }
  2023. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2024. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2025. mutex_lock(&dp->session_lock);
  2026. /*
  2027. * If DP_STATE_READY is not set, we should not do any HW
  2028. * programming.
  2029. */
  2030. if (!dp_display_state_is(DP_STATE_READY)) {
  2031. dp_display_state_show("[host not ready]");
  2032. goto end;
  2033. }
  2034. /*
  2035. * It is possible that by the time we get call back to establish
  2036. * the DP pipeline e2e, the physical DP connection to the sink is
  2037. * already lost. In such cases, the DP_STATE_ABORTED would be set.
  2038. * However, it is necessary to NOT abort the display setup here so as
  2039. * to ensure that the rest of the system is in a stable state prior to
  2040. * handling the disconnect notification.
  2041. */
  2042. if (dp_display_state_is(DP_STATE_ABORTED))
  2043. dp_display_state_log("[aborted, but continue on]");
  2044. rc = dp_display_stream_enable(dp, panel);
  2045. if (rc)
  2046. goto end;
  2047. dp_display_state_add(DP_STATE_ENABLED);
  2048. end:
  2049. mutex_unlock(&dp->session_lock);
  2050. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, rc);
  2051. return rc;
  2052. }
  2053. static void dp_display_stream_post_enable(struct dp_display_private *dp,
  2054. struct dp_panel *dp_panel)
  2055. {
  2056. dp_panel->spd_config(dp_panel);
  2057. dp_panel->setup_hdr(dp_panel, NULL, false, 0, true);
  2058. }
  2059. static int dp_display_post_enable(struct dp_display *dp_display, void *panel)
  2060. {
  2061. struct dp_display_private *dp;
  2062. struct dp_panel *dp_panel;
  2063. if (!dp_display || !panel) {
  2064. DP_ERR("invalid input\n");
  2065. return -EINVAL;
  2066. }
  2067. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2068. dp_panel = panel;
  2069. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2070. mutex_lock(&dp->session_lock);
  2071. /*
  2072. * If DP_STATE_READY is not set, we should not do any HW
  2073. * programming.
  2074. */
  2075. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  2076. dp_display_state_show("[not enabled]");
  2077. goto end;
  2078. }
  2079. /*
  2080. * If the physical connection to the sink is already lost by the time
  2081. * we try to set up the connection, we can just skip all the steps
  2082. * here safely.
  2083. */
  2084. if (dp_display_state_is(DP_STATE_ABORTED)) {
  2085. dp_display_state_log("[aborted]");
  2086. goto end;
  2087. }
  2088. if (!dp_display_is_ready(dp) || !dp_display_state_is(DP_STATE_READY)) {
  2089. dp_display_state_show("[not ready]");
  2090. goto end;
  2091. }
  2092. dp_display_stream_post_enable(dp, dp_panel);
  2093. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  2094. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ);
  2095. if (dp_panel->audio_supported) {
  2096. dp_panel->audio->bw_code = dp->link->link_params.bw_code;
  2097. dp_panel->audio->lane_count = dp->link->link_params.lane_count;
  2098. dp_panel->audio->on(dp_panel->audio);
  2099. }
  2100. dp->aux->state &= ~DP_STATE_CTRL_POWERED_OFF;
  2101. dp->aux->state |= DP_STATE_CTRL_POWERED_ON;
  2102. complete_all(&dp->notification_comp);
  2103. DP_DEBUG("display post enable complete. state: 0x%x\n", dp->state);
  2104. end:
  2105. mutex_unlock(&dp->session_lock);
  2106. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  2107. return 0;
  2108. }
  2109. static void dp_display_clear_colorspaces(struct dp_display *dp_display)
  2110. {
  2111. struct drm_connector *connector;
  2112. struct sde_connector *sde_conn;
  2113. connector = dp_display->base_connector;
  2114. sde_conn = to_sde_connector(connector);
  2115. sde_conn->color_enc_fmt = 0;
  2116. }
  2117. static int dp_display_pre_disable(struct dp_display *dp_display, void *panel)
  2118. {
  2119. struct dp_display_private *dp;
  2120. struct dp_panel *dp_panel = panel;
  2121. struct dp_link_hdcp_status *status;
  2122. int rc = 0;
  2123. size_t i;
  2124. if (!dp_display || !panel) {
  2125. DP_ERR("invalid input\n");
  2126. return -EINVAL;
  2127. }
  2128. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2129. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2130. mutex_lock(&dp->session_lock);
  2131. status = &dp->link->hdcp_status;
  2132. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  2133. dp_display_state_show("[not enabled]");
  2134. goto end;
  2135. }
  2136. dp_display_state_add(DP_STATE_HDCP_ABORTED);
  2137. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  2138. if (dp_display_is_hdcp_enabled(dp) &&
  2139. status->hdcp_state != HDCP_STATE_INACTIVE) {
  2140. bool off = true;
  2141. if (dp_display_state_is(DP_STATE_SUSPENDED)) {
  2142. DP_DEBUG("Can't perform HDCP cleanup while suspended. Defer\n");
  2143. dp->hdcp_delayed_off = true;
  2144. goto clean;
  2145. }
  2146. flush_delayed_work(&dp->hdcp_cb_work);
  2147. if (dp->mst.mst_active) {
  2148. dp_display_hdcp_deregister_stream(dp,
  2149. dp_panel->stream_id);
  2150. for (i = DP_STREAM_0; i < DP_STREAM_MAX; i++) {
  2151. if (i != dp_panel->stream_id &&
  2152. dp->active_panels[i]) {
  2153. DP_DEBUG("Streams are still active. Skip disabling HDCP\n");
  2154. off = false;
  2155. }
  2156. }
  2157. }
  2158. if (off) {
  2159. if (dp->hdcp.ops->off)
  2160. dp->hdcp.ops->off(dp->hdcp.data);
  2161. dp_display_update_hdcp_status(dp, true);
  2162. }
  2163. }
  2164. dp_display_clear_colorspaces(dp_display);
  2165. clean:
  2166. if (dp_panel->audio_supported)
  2167. dp_panel->audio->off(dp_panel->audio);
  2168. rc = dp_display_stream_pre_disable(dp, dp_panel);
  2169. end:
  2170. mutex_unlock(&dp->session_lock);
  2171. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  2172. return 0;
  2173. }
  2174. static int dp_display_disable(struct dp_display *dp_display, void *panel)
  2175. {
  2176. int i;
  2177. struct dp_display_private *dp = NULL;
  2178. struct dp_panel *dp_panel = NULL;
  2179. struct dp_link_hdcp_status *status;
  2180. if (!dp_display || !panel) {
  2181. DP_ERR("invalid input\n");
  2182. return -EINVAL;
  2183. }
  2184. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2185. dp_panel = panel;
  2186. status = &dp->link->hdcp_status;
  2187. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2188. mutex_lock(&dp->session_lock);
  2189. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  2190. dp_display_state_show("[not enabled]");
  2191. goto end;
  2192. }
  2193. if (!dp_display_state_is(DP_STATE_READY)) {
  2194. dp_display_state_show("[not ready]");
  2195. goto end;
  2196. }
  2197. dp_display_stream_disable(dp, dp_panel);
  2198. dp_display_state_remove(DP_STATE_HDCP_ABORTED);
  2199. for (i = DP_STREAM_0; i < DP_STREAM_MAX; i++) {
  2200. if (dp->active_panels[i]) {
  2201. if (status->hdcp_state != HDCP_STATE_AUTHENTICATED)
  2202. queue_delayed_work(dp->wq, &dp->hdcp_cb_work,
  2203. HZ/4);
  2204. break;
  2205. }
  2206. }
  2207. end:
  2208. mutex_unlock(&dp->session_lock);
  2209. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  2210. return 0;
  2211. }
  2212. static int dp_request_irq(struct dp_display *dp_display)
  2213. {
  2214. int rc = 0;
  2215. struct dp_display_private *dp;
  2216. if (!dp_display) {
  2217. DP_ERR("invalid input\n");
  2218. return -EINVAL;
  2219. }
  2220. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2221. dp->irq = irq_of_parse_and_map(dp->pdev->dev.of_node, 0);
  2222. if (dp->irq < 0) {
  2223. rc = dp->irq;
  2224. DP_ERR("failed to get irq: %d\n", rc);
  2225. return rc;
  2226. }
  2227. rc = devm_request_irq(&dp->pdev->dev, dp->irq, dp_display_irq,
  2228. IRQF_TRIGGER_HIGH, "dp_display_isr", dp);
  2229. if (rc < 0) {
  2230. DP_ERR("failed to request IRQ%u: %d\n",
  2231. dp->irq, rc);
  2232. return rc;
  2233. }
  2234. disable_irq(dp->irq);
  2235. return 0;
  2236. }
  2237. static struct dp_debug *dp_get_debug(struct dp_display *dp_display)
  2238. {
  2239. struct dp_display_private *dp;
  2240. if (!dp_display) {
  2241. DP_ERR("invalid input\n");
  2242. return ERR_PTR(-EINVAL);
  2243. }
  2244. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2245. return dp->debug;
  2246. }
  2247. static int dp_display_unprepare(struct dp_display *dp_display, void *panel)
  2248. {
  2249. struct dp_display_private *dp;
  2250. struct dp_panel *dp_panel = panel;
  2251. u32 flags = 0;
  2252. if (!dp_display || !panel) {
  2253. DP_ERR("invalid input\n");
  2254. return -EINVAL;
  2255. }
  2256. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2257. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2258. mutex_lock(&dp->session_lock);
  2259. /*
  2260. * Check if the power off sequence was triggered
  2261. * by a source initialated action like framework
  2262. * reboot or suspend-resume but not from normal
  2263. * hot plug. If connector is in MST mode, skip
  2264. * powering down host as aux needs to be kept
  2265. * alive to handle hot-plug sideband message.
  2266. */
  2267. if (dp_display_is_ready(dp) &&
  2268. (dp_display_state_is(DP_STATE_SUSPENDED) ||
  2269. !dp->mst.mst_active))
  2270. flags |= DP_PANEL_SRC_INITIATED_POWER_DOWN;
  2271. if (dp->active_stream_cnt)
  2272. goto end;
  2273. if (flags & DP_PANEL_SRC_INITIATED_POWER_DOWN) {
  2274. dp->link->psm_config(dp->link, &dp->panel->link_info, true);
  2275. dp->debug->psm_enabled = true;
  2276. dp->ctrl->off(dp->ctrl);
  2277. dp_display_host_unready(dp);
  2278. dp_display_host_deinit(dp);
  2279. dp_display_state_add(DP_STATE_SRC_PWRDN);
  2280. }
  2281. dp_display_state_remove(DP_STATE_ENABLED);
  2282. dp->aux->state &= ~DP_STATE_CTRL_POWERED_ON;
  2283. dp->aux->state |= DP_STATE_CTRL_POWERED_OFF;
  2284. complete_all(&dp->notification_comp);
  2285. /* log this as it results from user action of cable dis-connection */
  2286. DP_INFO("[OK]\n");
  2287. end:
  2288. dp->tot_lm_blks_in_use -= dp_panel->max_lm;
  2289. dp_panel->max_lm = 0;
  2290. dp_panel->deinit(dp_panel, flags);
  2291. mutex_unlock(&dp->session_lock);
  2292. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  2293. return 0;
  2294. }
  2295. static int dp_display_validate_link_clock(struct dp_display_private *dp,
  2296. struct drm_display_mode *mode, struct dp_display_mode dp_mode)
  2297. {
  2298. u32 mode_rate_khz = 0, supported_rate_khz = 0, mode_bpp = 0;
  2299. bool dsc_en;
  2300. int rate;
  2301. dsc_en = dp_mode.timing.comp_info.enabled;
  2302. mode_bpp = dsc_en ?
  2303. DSC_BPP(dp_mode.timing.comp_info.dsc_info.config)
  2304. : dp_mode.timing.bpp;
  2305. mode_rate_khz = mode->clock * mode_bpp;
  2306. rate = drm_dp_bw_code_to_link_rate(dp->link->link_params.bw_code);
  2307. supported_rate_khz = dp->link->link_params.lane_count * rate * 8;
  2308. if (mode_rate_khz > supported_rate_khz) {
  2309. DP_DEBUG("mode_rate: %d kHz, supported_rate: %d kHz\n",
  2310. mode_rate_khz, supported_rate_khz);
  2311. return -EPERM;
  2312. }
  2313. return 0;
  2314. }
  2315. static int dp_display_validate_pixel_clock(struct dp_display_mode dp_mode,
  2316. u32 max_pclk_khz)
  2317. {
  2318. u32 pclk_khz = dp_mode.timing.widebus_en ?
  2319. (dp_mode.timing.pixel_clk_khz >> 1) :
  2320. dp_mode.timing.pixel_clk_khz;
  2321. if (pclk_khz > max_pclk_khz) {
  2322. DP_DEBUG("clk: %d kHz, max: %d kHz\n", pclk_khz, max_pclk_khz);
  2323. return -EPERM;
  2324. }
  2325. return 0;
  2326. }
  2327. static int dp_display_validate_topology(struct dp_display_private *dp,
  2328. struct dp_panel *dp_panel, struct drm_display_mode *mode,
  2329. struct dp_display_mode *dp_mode,
  2330. const struct msm_resource_caps_info *avail_res)
  2331. {
  2332. int rc;
  2333. struct msm_drm_private *priv = dp->priv;
  2334. const u32 dual = 2, quad = 4;
  2335. u32 num_lm = 0, num_dsc = 0, num_3dmux = 0;
  2336. bool dsc_capable = dp_mode->capabilities & DP_PANEL_CAPS_DSC;
  2337. u32 fps = dp_mode->timing.refresh_rate;
  2338. int avail_lm = 0;
  2339. mutex_lock(&dp->accounting_lock);
  2340. rc = msm_get_mixer_count(priv, mode, avail_res, &num_lm);
  2341. if (rc) {
  2342. DP_ERR("error getting mixer count. rc:%d\n", rc);
  2343. goto end;
  2344. }
  2345. /* Merge using DSC, if enabled */
  2346. if (dp_panel->dsc_en && dsc_capable) {
  2347. rc = msm_get_dsc_count(priv, mode->hdisplay, &num_dsc);
  2348. if (rc) {
  2349. DP_ERR("error getting dsc count. rc:%d\n", rc);
  2350. goto end;
  2351. }
  2352. num_dsc = max(num_lm, num_dsc);
  2353. if ((num_dsc > avail_res->num_lm) || (num_dsc > avail_res->num_dsc)) {
  2354. DP_DEBUG("mode %sx%d: not enough resources for dsc %d dsc_a:%d lm_a:%d\n",
  2355. mode->name, fps, num_dsc, avail_res->num_dsc,
  2356. avail_res->num_lm);
  2357. /* Clear DSC caps and retry */
  2358. dp_mode->capabilities &= ~DP_PANEL_CAPS_DSC;
  2359. rc = -EAGAIN;
  2360. goto end;
  2361. } else {
  2362. /* Only DSCMERGE is supported on DP */
  2363. num_lm = num_dsc;
  2364. }
  2365. }
  2366. if (!num_dsc && (num_lm == 2) && avail_res->num_3dmux) {
  2367. num_3dmux = 1;
  2368. }
  2369. avail_lm = avail_res->num_lm + avail_res->num_lm_in_use - dp->tot_lm_blks_in_use;
  2370. if ((num_lm > dp_panel->max_lm) && (num_lm > avail_lm)) {
  2371. DP_DEBUG("mode %sx%d is invalid, not enough lm %d %d\n",
  2372. mode->name, fps, num_lm, avail_res->num_lm);
  2373. rc = -EPERM;
  2374. goto end;
  2375. } else if (!num_dsc && (num_lm == dual && !num_3dmux)) {
  2376. DP_DEBUG("mode %sx%d is invalid, not enough 3dmux %d %d\n",
  2377. mode->name, fps, num_3dmux, avail_res->num_3dmux);
  2378. rc = -EPERM;
  2379. goto end;
  2380. } else if (num_lm == quad && num_dsc != quad) {
  2381. DP_DEBUG("mode %sx%d is invalid, unsupported DP topology lm:%d dsc:%d\n",
  2382. mode->name, fps, num_lm, num_dsc);
  2383. rc = -EPERM;
  2384. goto end;
  2385. }
  2386. DP_DEBUG_V("mode %sx%d is valid, supported DP topology lm:%d dsc:%d 3dmux:%d\n",
  2387. mode->name, fps, num_lm, num_dsc, num_3dmux);
  2388. dp->tot_lm_blks_in_use -= dp_panel->max_lm;
  2389. dp_panel->max_lm = num_lm > avail_res->num_lm_in_use ? max(dp_panel->max_lm, num_lm) : 0;
  2390. dp->tot_lm_blks_in_use += dp_panel->max_lm;
  2391. rc = 0;
  2392. end:
  2393. mutex_unlock(&dp->accounting_lock);
  2394. return rc;
  2395. }
  2396. static enum drm_mode_status dp_display_validate_mode(
  2397. struct dp_display *dp_display,
  2398. void *panel, struct drm_display_mode *mode,
  2399. const struct msm_resource_caps_info *avail_res)
  2400. {
  2401. struct dp_display_private *dp;
  2402. struct dp_panel *dp_panel;
  2403. struct dp_debug *debug;
  2404. enum drm_mode_status mode_status = MODE_BAD;
  2405. struct dp_display_mode dp_mode;
  2406. int rc = 0;
  2407. if (!dp_display || !mode || !panel ||
  2408. !avail_res || !avail_res->max_mixer_width) {
  2409. DP_ERR("invalid params\n");
  2410. return mode_status;
  2411. }
  2412. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2413. mutex_lock(&dp->session_lock);
  2414. dp_panel = panel;
  2415. if (!dp_panel->connector) {
  2416. DP_ERR("invalid connector\n");
  2417. goto end;
  2418. }
  2419. debug = dp->debug;
  2420. if (!debug)
  2421. goto end;
  2422. dp_display->convert_to_dp_mode(dp_display, panel, mode, &dp_mode);
  2423. rc = dp_display_validate_topology(dp, dp_panel, mode, &dp_mode, avail_res);
  2424. if (rc == -EAGAIN) {
  2425. dp_panel->convert_to_dp_mode(dp_panel, mode, &dp_mode);
  2426. rc = dp_display_validate_topology(dp, dp_panel, mode, &dp_mode, avail_res);
  2427. }
  2428. if (rc)
  2429. goto end;
  2430. rc = dp_display_validate_link_clock(dp, mode, dp_mode);
  2431. if (rc)
  2432. goto end;
  2433. rc = dp_display_validate_pixel_clock(dp_mode, dp_display->max_pclk_khz);
  2434. if (rc)
  2435. goto end;
  2436. mode_status = MODE_OK;
  2437. end:
  2438. if (mode_status != MODE_OK)
  2439. dp_display_clear_reservation(dp_display, dp_panel);
  2440. mutex_unlock(&dp->session_lock);
  2441. DP_DEBUG_V("[%s] mode is %s\n", mode->name,
  2442. (mode_status == MODE_OK) ? "valid" : "invalid");
  2443. return mode_status;
  2444. }
  2445. static int dp_display_get_available_dp_resources(struct dp_display *dp_display,
  2446. const struct msm_resource_caps_info *avail_res,
  2447. struct msm_resource_caps_info *max_dp_avail_res)
  2448. {
  2449. if (!dp_display || !avail_res || !max_dp_avail_res) {
  2450. DP_ERR("invalid arguments\n");
  2451. return -EINVAL;
  2452. }
  2453. memcpy(max_dp_avail_res, avail_res,
  2454. sizeof(struct msm_resource_caps_info));
  2455. max_dp_avail_res->num_lm = min(avail_res->num_lm,
  2456. dp_display->max_mixer_count);
  2457. max_dp_avail_res->num_dsc = min(avail_res->num_dsc,
  2458. dp_display->max_dsc_count);
  2459. DP_DEBUG_V("max_lm:%d, avail_lm:%d, dp_avail_lm:%d\n",
  2460. dp_display->max_mixer_count, avail_res->num_lm,
  2461. max_dp_avail_res->num_lm);
  2462. DP_DEBUG_V("max_dsc:%d, avail_dsc:%d, dp_avail_dsc:%d\n",
  2463. dp_display->max_dsc_count, avail_res->num_dsc,
  2464. max_dp_avail_res->num_dsc);
  2465. return 0;
  2466. }
  2467. static int dp_display_get_modes(struct dp_display *dp, void *panel,
  2468. struct dp_display_mode *dp_mode)
  2469. {
  2470. struct dp_display_private *dp_display;
  2471. struct dp_panel *dp_panel;
  2472. int ret = 0;
  2473. if (!dp || !panel) {
  2474. DP_ERR("invalid params\n");
  2475. return 0;
  2476. }
  2477. dp_panel = panel;
  2478. if (!dp_panel->connector) {
  2479. DP_ERR("invalid connector\n");
  2480. return 0;
  2481. }
  2482. dp_display = container_of(dp, struct dp_display_private, dp_display);
  2483. ret = dp_panel->get_modes(dp_panel, dp_panel->connector, dp_mode);
  2484. if (dp_mode->timing.pixel_clk_khz)
  2485. dp->max_pclk_khz = dp_mode->timing.pixel_clk_khz;
  2486. return ret;
  2487. }
  2488. static void dp_display_convert_to_dp_mode(struct dp_display *dp_display,
  2489. void *panel,
  2490. const struct drm_display_mode *drm_mode,
  2491. struct dp_display_mode *dp_mode)
  2492. {
  2493. int rc;
  2494. struct dp_display_private *dp;
  2495. struct dp_panel *dp_panel;
  2496. u32 free_dsc_blks = 0, required_dsc_blks = 0, curr_dsc = 0, new_dsc = 0;
  2497. if (!dp_display || !drm_mode || !dp_mode || !panel) {
  2498. DP_ERR("invalid input\n");
  2499. return;
  2500. }
  2501. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2502. dp_panel = panel;
  2503. memset(dp_mode, 0, sizeof(*dp_mode));
  2504. if (dp_panel->dsc_en) {
  2505. free_dsc_blks = dp_display->max_dsc_count -
  2506. dp->tot_dsc_blks_in_use +
  2507. dp_panel->dsc_blks_in_use;
  2508. DP_DEBUG_V("Before: in_use:%d, max:%d, free:%d\n",
  2509. dp->tot_dsc_blks_in_use,
  2510. dp_display->max_dsc_count, free_dsc_blks);
  2511. rc = msm_get_dsc_count(dp->priv, drm_mode->hdisplay,
  2512. &required_dsc_blks);
  2513. if (rc) {
  2514. DP_ERR("error getting dsc count. rc:%d\n", rc);
  2515. return;
  2516. }
  2517. curr_dsc = dp_panel->dsc_blks_in_use;
  2518. dp->tot_dsc_blks_in_use -= dp_panel->dsc_blks_in_use;
  2519. dp_panel->dsc_blks_in_use = 0;
  2520. if (free_dsc_blks >= required_dsc_blks) {
  2521. dp_mode->capabilities |= DP_PANEL_CAPS_DSC;
  2522. new_dsc = max(curr_dsc, required_dsc_blks);
  2523. dp_panel->dsc_blks_in_use = new_dsc;
  2524. dp->tot_dsc_blks_in_use += new_dsc;
  2525. }
  2526. DP_DEBUG_V("After: in_use:%d, max:%d, free:%d, req:%d, caps:0x%x\n",
  2527. dp->tot_dsc_blks_in_use,
  2528. dp_display->max_dsc_count,
  2529. free_dsc_blks, required_dsc_blks,
  2530. dp_mode->capabilities);
  2531. }
  2532. dp_panel->convert_to_dp_mode(dp_panel, drm_mode, dp_mode);
  2533. }
  2534. static int dp_display_config_hdr(struct dp_display *dp_display, void *panel,
  2535. struct drm_msm_ext_hdr_metadata *hdr, bool dhdr_update)
  2536. {
  2537. struct dp_panel *dp_panel;
  2538. struct sde_connector *sde_conn;
  2539. struct dp_display_private *dp;
  2540. u64 core_clk_rate;
  2541. bool flush_hdr;
  2542. if (!dp_display || !panel) {
  2543. DP_ERR("invalid input\n");
  2544. return -EINVAL;
  2545. }
  2546. dp_panel = panel;
  2547. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2548. sde_conn = to_sde_connector(dp_panel->connector);
  2549. core_clk_rate = dp->power->clk_get_rate(dp->power, "core_clk");
  2550. if (!core_clk_rate) {
  2551. DP_ERR("invalid rate for core_clk\n");
  2552. return -EINVAL;
  2553. }
  2554. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  2555. dp_display_state_show("[not enabled]");
  2556. return 0;
  2557. }
  2558. /*
  2559. * In rare cases where HDR metadata is updated independently
  2560. * flush the HDR metadata immediately instead of relying on
  2561. * the colorspace
  2562. */
  2563. flush_hdr = !sde_conn->colorspace_updated;
  2564. if (flush_hdr)
  2565. DP_DEBUG("flushing the HDR metadata\n");
  2566. else
  2567. DP_DEBUG("piggy-backing with colorspace\n");
  2568. return dp_panel->setup_hdr(dp_panel, hdr, dhdr_update,
  2569. core_clk_rate, flush_hdr);
  2570. }
  2571. static int dp_display_setup_colospace(struct dp_display *dp_display,
  2572. void *panel,
  2573. u32 colorspace)
  2574. {
  2575. struct dp_panel *dp_panel;
  2576. struct dp_display_private *dp;
  2577. if (!dp_display || !panel) {
  2578. pr_err("invalid input\n");
  2579. return -EINVAL;
  2580. }
  2581. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2582. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  2583. dp_display_state_show("[not enabled]");
  2584. return 0;
  2585. }
  2586. dp_panel = panel;
  2587. return dp_panel->set_colorspace(dp_panel, colorspace);
  2588. }
  2589. static int dp_display_create_workqueue(struct dp_display_private *dp)
  2590. {
  2591. dp->wq = create_singlethread_workqueue("drm_dp");
  2592. if (IS_ERR_OR_NULL(dp->wq)) {
  2593. DP_ERR("Error creating wq\n");
  2594. return -EPERM;
  2595. }
  2596. INIT_DELAYED_WORK(&dp->hdcp_cb_work, dp_display_hdcp_cb_work);
  2597. INIT_WORK(&dp->connect_work, dp_display_connect_work);
  2598. INIT_WORK(&dp->attention_work, dp_display_attention_work);
  2599. return 0;
  2600. }
  2601. static int dp_display_bridge_internal_hpd(void *dev, bool hpd, bool hpd_irq)
  2602. {
  2603. struct dp_display_private *dp = dev;
  2604. struct drm_device *drm_dev = dp->dp_display.drm_dev;
  2605. if (!drm_dev || !drm_dev->mode_config.poll_enabled)
  2606. return -EBUSY;
  2607. if (hpd_irq)
  2608. dp_display_mst_attention(dp);
  2609. else
  2610. dp->hpd->simulate_connect(dp->hpd, hpd);
  2611. return 0;
  2612. }
  2613. static int dp_display_init_aux_bridge(struct dp_display_private *dp)
  2614. {
  2615. int rc = 0;
  2616. const char *phandle = "qcom,dp-aux-bridge";
  2617. struct device_node *bridge_node;
  2618. if (!dp->pdev->dev.of_node) {
  2619. pr_err("cannot find dev.of_node\n");
  2620. rc = -ENODEV;
  2621. goto end;
  2622. }
  2623. bridge_node = of_parse_phandle(dp->pdev->dev.of_node,
  2624. phandle, 0);
  2625. if (!bridge_node)
  2626. goto end;
  2627. dp->aux_bridge = of_dp_aux_find_bridge(bridge_node);
  2628. if (!dp->aux_bridge) {
  2629. pr_err("failed to find dp aux bridge\n");
  2630. rc = -EPROBE_DEFER;
  2631. goto end;
  2632. }
  2633. if (dp->aux_bridge->register_hpd &&
  2634. !(dp->aux_bridge->flag & DP_AUX_BRIDGE_HPD))
  2635. dp->aux_bridge->register_hpd(dp->aux_bridge,
  2636. dp_display_bridge_internal_hpd, dp);
  2637. end:
  2638. return rc;
  2639. }
  2640. static int dp_display_mst_install(struct dp_display *dp_display,
  2641. struct dp_mst_drm_install_info *mst_install_info)
  2642. {
  2643. struct dp_display_private *dp;
  2644. if (!dp_display || !mst_install_info) {
  2645. DP_ERR("invalid input\n");
  2646. return -EINVAL;
  2647. }
  2648. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2649. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2650. if (!mst_install_info->cbs->hpd || !mst_install_info->cbs->hpd_irq) {
  2651. DP_ERR("invalid mst cbs\n");
  2652. return -EINVAL;
  2653. }
  2654. dp_display->dp_mst_prv_info = mst_install_info->dp_mst_prv_info;
  2655. if (!dp->parser->has_mst) {
  2656. DP_DEBUG("mst not enabled\n");
  2657. return -EPERM;
  2658. }
  2659. memcpy(&dp->mst.cbs, mst_install_info->cbs, sizeof(dp->mst.cbs));
  2660. dp->mst.drm_registered = true;
  2661. DP_MST_DEBUG("dp mst drm installed\n");
  2662. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  2663. return 0;
  2664. }
  2665. static int dp_display_mst_uninstall(struct dp_display *dp_display)
  2666. {
  2667. struct dp_display_private *dp;
  2668. if (!dp_display) {
  2669. DP_ERR("invalid input\n");
  2670. return -EINVAL;
  2671. }
  2672. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2673. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2674. if (!dp->mst.drm_registered) {
  2675. DP_DEBUG("drm mst not registered\n");
  2676. return -EPERM;
  2677. }
  2678. dp = container_of(dp_display, struct dp_display_private,
  2679. dp_display);
  2680. memset(&dp->mst.cbs, 0, sizeof(dp->mst.cbs));
  2681. dp->mst.drm_registered = false;
  2682. DP_MST_DEBUG("dp mst drm uninstalled\n");
  2683. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  2684. return 0;
  2685. }
  2686. static int dp_display_mst_connector_install(struct dp_display *dp_display,
  2687. struct drm_connector *connector)
  2688. {
  2689. int rc = 0;
  2690. struct dp_panel_in panel_in;
  2691. struct dp_panel *dp_panel;
  2692. struct dp_display_private *dp;
  2693. if (!dp_display || !connector) {
  2694. DP_ERR("invalid input\n");
  2695. return -EINVAL;
  2696. }
  2697. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2698. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2699. mutex_lock(&dp->session_lock);
  2700. if (!dp->mst.drm_registered) {
  2701. DP_DEBUG("drm mst not registered\n");
  2702. rc = -EPERM;
  2703. goto end;
  2704. }
  2705. panel_in.dev = &dp->pdev->dev;
  2706. panel_in.aux = dp->aux;
  2707. panel_in.catalog = &dp->catalog->panel;
  2708. panel_in.link = dp->link;
  2709. panel_in.connector = connector;
  2710. panel_in.base_panel = dp->panel;
  2711. panel_in.parser = dp->parser;
  2712. dp_panel = dp_panel_get(&panel_in);
  2713. if (IS_ERR(dp_panel)) {
  2714. rc = PTR_ERR(dp_panel);
  2715. DP_ERR("failed to initialize panel, rc = %d\n", rc);
  2716. goto end;
  2717. }
  2718. dp_panel->audio = dp_audio_get(dp->pdev, dp_panel, &dp->catalog->audio);
  2719. if (IS_ERR(dp_panel->audio)) {
  2720. rc = PTR_ERR(dp_panel->audio);
  2721. DP_ERR("[mst] failed to initialize audio, rc = %d\n", rc);
  2722. dp_panel->audio = NULL;
  2723. goto end;
  2724. }
  2725. DP_MST_DEBUG("dp mst connector installed. conn:%d\n",
  2726. connector->base.id);
  2727. end:
  2728. mutex_unlock(&dp->session_lock);
  2729. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, rc);
  2730. return rc;
  2731. }
  2732. static int dp_display_mst_connector_uninstall(struct dp_display *dp_display,
  2733. struct drm_connector *connector)
  2734. {
  2735. int rc = 0;
  2736. struct sde_connector *sde_conn;
  2737. struct dp_panel *dp_panel;
  2738. struct dp_display_private *dp;
  2739. struct dp_audio *audio = NULL;
  2740. if (!dp_display || !connector) {
  2741. DP_ERR("invalid input\n");
  2742. return -EINVAL;
  2743. }
  2744. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2745. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2746. mutex_lock(&dp->session_lock);
  2747. if (!dp->mst.drm_registered) {
  2748. DP_DEBUG("drm mst not registered\n");
  2749. mutex_unlock(&dp->session_lock);
  2750. return -EPERM;
  2751. }
  2752. sde_conn = to_sde_connector(connector);
  2753. if (!sde_conn->drv_panel) {
  2754. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2755. mutex_unlock(&dp->session_lock);
  2756. return -EINVAL;
  2757. }
  2758. dp_panel = sde_conn->drv_panel;
  2759. /* Make a copy of audio structure to call into dp_audio_put later */
  2760. audio = dp_panel->audio;
  2761. dp_panel_put(dp_panel);
  2762. DP_MST_DEBUG("dp mst connector uninstalled. conn:%d\n",
  2763. connector->base.id);
  2764. mutex_unlock(&dp->session_lock);
  2765. dp_audio_put(audio);
  2766. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  2767. return rc;
  2768. }
  2769. static int dp_display_mst_connector_update_edid(struct dp_display *dp_display,
  2770. struct drm_connector *connector,
  2771. struct edid *edid)
  2772. {
  2773. int rc = 0;
  2774. struct sde_connector *sde_conn;
  2775. struct dp_panel *dp_panel;
  2776. struct dp_display_private *dp;
  2777. if (!dp_display || !connector || !edid) {
  2778. DP_ERR("invalid input\n");
  2779. return -EINVAL;
  2780. }
  2781. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2782. if (!dp->mst.drm_registered) {
  2783. DP_DEBUG("drm mst not registered\n");
  2784. return -EPERM;
  2785. }
  2786. sde_conn = to_sde_connector(connector);
  2787. if (!sde_conn->drv_panel) {
  2788. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2789. return -EINVAL;
  2790. }
  2791. dp_panel = sde_conn->drv_panel;
  2792. rc = dp_panel->update_edid(dp_panel, edid);
  2793. DP_MST_DEBUG("dp mst connector:%d edid updated. mode_cnt:%d\n",
  2794. connector->base.id, rc);
  2795. return rc;
  2796. }
  2797. static int dp_display_update_pps(struct dp_display *dp_display,
  2798. struct drm_connector *connector, char *pps_cmd)
  2799. {
  2800. struct sde_connector *sde_conn;
  2801. struct dp_panel *dp_panel;
  2802. struct dp_display_private *dp;
  2803. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2804. sde_conn = to_sde_connector(connector);
  2805. if (!sde_conn->drv_panel) {
  2806. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2807. return -EINVAL;
  2808. }
  2809. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  2810. dp_display_state_show("[not enabled]");
  2811. return 0;
  2812. }
  2813. dp_panel = sde_conn->drv_panel;
  2814. dp_panel->update_pps(dp_panel, pps_cmd);
  2815. return 0;
  2816. }
  2817. static int dp_display_mst_connector_update_link_info(
  2818. struct dp_display *dp_display,
  2819. struct drm_connector *connector)
  2820. {
  2821. int rc = 0;
  2822. struct sde_connector *sde_conn;
  2823. struct dp_panel *dp_panel;
  2824. struct dp_display_private *dp;
  2825. if (!dp_display || !connector) {
  2826. DP_ERR("invalid input\n");
  2827. return -EINVAL;
  2828. }
  2829. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2830. if (!dp->mst.drm_registered) {
  2831. DP_DEBUG("drm mst not registered\n");
  2832. return -EPERM;
  2833. }
  2834. sde_conn = to_sde_connector(connector);
  2835. if (!sde_conn->drv_panel) {
  2836. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2837. return -EINVAL;
  2838. }
  2839. dp_panel = sde_conn->drv_panel;
  2840. memcpy(dp_panel->dpcd, dp->panel->dpcd,
  2841. DP_RECEIVER_CAP_SIZE + 1);
  2842. memcpy(dp_panel->dsc_dpcd, dp->panel->dsc_dpcd,
  2843. DP_RECEIVER_DSC_CAP_SIZE + 1);
  2844. memcpy(&dp_panel->link_info, &dp->panel->link_info,
  2845. sizeof(dp_panel->link_info));
  2846. DP_MST_DEBUG("dp mst connector:%d link info updated\n",
  2847. connector->base.id);
  2848. return rc;
  2849. }
  2850. static int dp_display_mst_get_fixed_topology_port(
  2851. struct dp_display *dp_display,
  2852. u32 strm_id, u32 *port_num)
  2853. {
  2854. struct dp_display_private *dp;
  2855. u32 port;
  2856. if (!dp_display) {
  2857. DP_ERR("invalid input\n");
  2858. return -EINVAL;
  2859. }
  2860. if (strm_id >= DP_STREAM_MAX) {
  2861. DP_ERR("invalid stream id:%d\n", strm_id);
  2862. return -EINVAL;
  2863. }
  2864. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2865. port = dp->parser->mst_fixed_port[strm_id];
  2866. if (!port || port > 255)
  2867. return -ENOENT;
  2868. if (port_num)
  2869. *port_num = port;
  2870. return 0;
  2871. }
  2872. static int dp_display_get_mst_caps(struct dp_display *dp_display,
  2873. struct dp_mst_caps *mst_caps)
  2874. {
  2875. int rc = 0;
  2876. struct dp_display_private *dp;
  2877. if (!dp_display || !mst_caps) {
  2878. DP_ERR("invalid input\n");
  2879. return -EINVAL;
  2880. }
  2881. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2882. mst_caps->has_mst = dp->parser->has_mst;
  2883. mst_caps->max_streams_supported = (mst_caps->has_mst) ? 2 : 0;
  2884. mst_caps->max_dpcd_transaction_bytes = (mst_caps->has_mst) ? 16 : 0;
  2885. mst_caps->drm_aux = dp->aux->drm_aux;
  2886. return rc;
  2887. }
  2888. static void dp_display_wakeup_phy_layer(struct dp_display *dp_display,
  2889. bool wakeup)
  2890. {
  2891. struct dp_display_private *dp;
  2892. struct dp_hpd *hpd;
  2893. if (!dp_display) {
  2894. DP_ERR("invalid input\n");
  2895. return;
  2896. }
  2897. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2898. if (!dp->mst.drm_registered) {
  2899. DP_DEBUG("drm mst not registered\n");
  2900. return;
  2901. }
  2902. hpd = dp->hpd;
  2903. if (hpd && hpd->wakeup_phy)
  2904. hpd->wakeup_phy(hpd, wakeup);
  2905. }
  2906. static int dp_display_probe(struct platform_device *pdev)
  2907. {
  2908. int rc = 0;
  2909. struct dp_display_private *dp;
  2910. if (!pdev || !pdev->dev.of_node) {
  2911. DP_ERR("pdev not found\n");
  2912. rc = -ENODEV;
  2913. goto bail;
  2914. }
  2915. dp = devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL);
  2916. if (!dp) {
  2917. rc = -ENOMEM;
  2918. goto bail;
  2919. }
  2920. init_completion(&dp->notification_comp);
  2921. init_completion(&dp->attention_comp);
  2922. dp->pdev = pdev;
  2923. dp->name = "drm_dp";
  2924. memset(&dp->mst, 0, sizeof(dp->mst));
  2925. rc = dp_display_init_aux_bridge(dp);
  2926. if (rc)
  2927. goto error;
  2928. rc = dp_display_create_workqueue(dp);
  2929. if (rc) {
  2930. DP_ERR("Failed to create workqueue\n");
  2931. goto error;
  2932. }
  2933. platform_set_drvdata(pdev, dp);
  2934. g_dp_display = &dp->dp_display;
  2935. g_dp_display->dp_ipc_log = ipc_log_context_create(DRM_DP_IPC_NUM_PAGES, "drm_dp", 0);
  2936. if (!g_dp_display->dp_ipc_log)
  2937. DP_WARN("Error in creating ipc_log_context\n");
  2938. g_dp_display->enable = dp_display_enable;
  2939. g_dp_display->post_enable = dp_display_post_enable;
  2940. g_dp_display->pre_disable = dp_display_pre_disable;
  2941. g_dp_display->disable = dp_display_disable;
  2942. g_dp_display->set_mode = dp_display_set_mode;
  2943. g_dp_display->validate_mode = dp_display_validate_mode;
  2944. g_dp_display->get_modes = dp_display_get_modes;
  2945. g_dp_display->prepare = dp_display_prepare;
  2946. g_dp_display->unprepare = dp_display_unprepare;
  2947. g_dp_display->request_irq = dp_request_irq;
  2948. g_dp_display->get_debug = dp_get_debug;
  2949. g_dp_display->post_open = NULL;
  2950. g_dp_display->post_init = dp_display_post_init;
  2951. g_dp_display->config_hdr = dp_display_config_hdr;
  2952. g_dp_display->mst_install = dp_display_mst_install;
  2953. g_dp_display->mst_uninstall = dp_display_mst_uninstall;
  2954. g_dp_display->mst_connector_install = dp_display_mst_connector_install;
  2955. g_dp_display->mst_connector_uninstall =
  2956. dp_display_mst_connector_uninstall;
  2957. g_dp_display->mst_connector_update_edid =
  2958. dp_display_mst_connector_update_edid;
  2959. g_dp_display->mst_connector_update_link_info =
  2960. dp_display_mst_connector_update_link_info;
  2961. g_dp_display->get_mst_caps = dp_display_get_mst_caps;
  2962. g_dp_display->set_stream_info = dp_display_set_stream_info;
  2963. g_dp_display->update_pps = dp_display_update_pps;
  2964. g_dp_display->convert_to_dp_mode = dp_display_convert_to_dp_mode;
  2965. g_dp_display->mst_get_fixed_topology_port =
  2966. dp_display_mst_get_fixed_topology_port;
  2967. g_dp_display->wakeup_phy_layer =
  2968. dp_display_wakeup_phy_layer;
  2969. g_dp_display->set_colorspace = dp_display_setup_colospace;
  2970. g_dp_display->get_available_dp_resources =
  2971. dp_display_get_available_dp_resources;
  2972. g_dp_display->clear_reservation = dp_display_clear_reservation;
  2973. rc = component_add(&pdev->dev, &dp_display_comp_ops);
  2974. if (rc) {
  2975. DP_ERR("component add failed, rc=%d\n", rc);
  2976. goto error;
  2977. }
  2978. return 0;
  2979. error:
  2980. devm_kfree(&pdev->dev, dp);
  2981. bail:
  2982. return rc;
  2983. }
  2984. int dp_display_get_displays(void **displays, int count)
  2985. {
  2986. if (!displays) {
  2987. DP_ERR("invalid data\n");
  2988. return -EINVAL;
  2989. }
  2990. if (count != 1) {
  2991. DP_ERR("invalid number of displays\n");
  2992. return -EINVAL;
  2993. }
  2994. displays[0] = g_dp_display;
  2995. return count;
  2996. }
  2997. int dp_display_get_num_of_displays(void)
  2998. {
  2999. if (!g_dp_display)
  3000. return 0;
  3001. return 1;
  3002. }
  3003. int dp_display_get_num_of_streams(void)
  3004. {
  3005. return DP_STREAM_MAX;
  3006. }
  3007. static void dp_display_set_mst_state(void *dp_display,
  3008. enum dp_drv_state mst_state)
  3009. {
  3010. struct dp_display_private *dp;
  3011. if (!g_dp_display) {
  3012. DP_DEBUG("dp display not initialized\n");
  3013. return;
  3014. }
  3015. dp = container_of(g_dp_display, struct dp_display_private, dp_display);
  3016. SDE_EVT32_EXTERNAL(mst_state, dp->mst.mst_active);
  3017. if (dp->mst.mst_active && dp->mst.cbs.set_drv_state)
  3018. dp->mst.cbs.set_drv_state(g_dp_display, mst_state);
  3019. }
  3020. static int dp_display_remove(struct platform_device *pdev)
  3021. {
  3022. struct dp_display_private *dp;
  3023. if (!pdev)
  3024. return -EINVAL;
  3025. dp = platform_get_drvdata(pdev);
  3026. dp_display_deinit_sub_modules(dp);
  3027. if (dp->wq)
  3028. destroy_workqueue(dp->wq);
  3029. platform_set_drvdata(pdev, NULL);
  3030. devm_kfree(&pdev->dev, dp);
  3031. if (g_dp_display->dp_ipc_log) {
  3032. ipc_log_context_destroy(g_dp_display->dp_ipc_log);
  3033. g_dp_display->dp_ipc_log = NULL;
  3034. }
  3035. return 0;
  3036. }
  3037. static int dp_pm_prepare(struct device *dev)
  3038. {
  3039. struct dp_display_private *dp = container_of(g_dp_display,
  3040. struct dp_display_private, dp_display);
  3041. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY);
  3042. mutex_lock(&dp->session_lock);
  3043. dp_display_set_mst_state(g_dp_display, PM_SUSPEND);
  3044. /*
  3045. * There are a few instances where the DP is hotplugged when the device
  3046. * is in PM suspend state. After hotplug, it is observed the device
  3047. * enters and exits the PM suspend multiple times while aux transactions
  3048. * are taking place. This may sometimes cause an unclocked register
  3049. * access error. So, abort aux transactions when such a situation
  3050. * arises i.e. when DP is connected but display not enabled yet.
  3051. */
  3052. if (dp_display_state_is(DP_STATE_CONNECTED) &&
  3053. !dp_display_state_is(DP_STATE_ENABLED)) {
  3054. dp->aux->abort(dp->aux, true);
  3055. dp->ctrl->abort(dp->ctrl, true);
  3056. }
  3057. dp_display_state_add(DP_STATE_SUSPENDED);
  3058. mutex_unlock(&dp->session_lock);
  3059. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  3060. return 0;
  3061. }
  3062. static void dp_pm_complete(struct device *dev)
  3063. {
  3064. struct dp_display_private *dp = container_of(g_dp_display,
  3065. struct dp_display_private, dp_display);
  3066. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY);
  3067. mutex_lock(&dp->session_lock);
  3068. dp_display_set_mst_state(g_dp_display, PM_DEFAULT);
  3069. /*
  3070. * There are multiple PM suspend entry and exits observed before
  3071. * the connect uevent is issued to userspace. The aux transactions are
  3072. * aborted during PM suspend entry in dp_pm_prepare to prevent unclocked
  3073. * register access. On PM suspend exit, there will be no host_init call
  3074. * to reset the abort flags for ctrl and aux incase DP is connected
  3075. * but display not enabled. So, resetting abort flags for aux and ctrl.
  3076. */
  3077. if (dp_display_state_is(DP_STATE_CONNECTED) &&
  3078. !dp_display_state_is(DP_STATE_ENABLED)) {
  3079. dp->aux->abort(dp->aux, false);
  3080. dp->ctrl->abort(dp->ctrl, false);
  3081. }
  3082. dp_display_state_remove(DP_STATE_SUSPENDED);
  3083. mutex_unlock(&dp->session_lock);
  3084. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  3085. }
  3086. void *get_ipc_log_context(void)
  3087. {
  3088. if (g_dp_display && g_dp_display->dp_ipc_log)
  3089. return g_dp_display->dp_ipc_log;
  3090. return NULL;
  3091. }
  3092. static const struct dev_pm_ops dp_pm_ops = {
  3093. .prepare = dp_pm_prepare,
  3094. .complete = dp_pm_complete,
  3095. };
  3096. static struct platform_driver dp_display_driver = {
  3097. .probe = dp_display_probe,
  3098. .remove = dp_display_remove,
  3099. .driver = {
  3100. .name = "msm-dp-display",
  3101. .of_match_table = dp_dt_match,
  3102. .suppress_bind_attrs = true,
  3103. .pm = &dp_pm_ops,
  3104. },
  3105. };
  3106. void __init dp_display_register(void)
  3107. {
  3108. platform_driver_register(&dp_display_driver);
  3109. }
  3110. void __exit dp_display_unregister(void)
  3111. {
  3112. platform_driver_unregister(&dp_display_driver);
  3113. }