dp_display.c 95 KB

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