dp_display.c 96 KB

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