dp_display.c 93 KB

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