dp_display.c 95 KB

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