dp_display.c 94 KB

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