dp_display.c 96 KB

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