dp_display.c 95 KB

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