dp_display.c 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861
  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. if (!dp->debug->sim_mode && !dp->no_aux_switch && !dp->parser->gpio_aux_switch
  989. && dp->aux_switch_node) {
  990. rc = dp->aux->aux_switch(dp->aux, true, dp->hpd->orientation);
  991. if (rc) {
  992. mutex_unlock(&dp->session_lock);
  993. return rc;
  994. }
  995. }
  996. /*
  997. * If dp video session is not restored from a previous session teardown
  998. * by userspace, ensure the host_init is executed, in such a scenario,
  999. * so that all the required DP resources are enabled.
  1000. *
  1001. * Below is one of the sequences of events which describe the above
  1002. * scenario:
  1003. * a. Source initiated power down resulting in host_deinit.
  1004. * b. Sink issues hpd low attention without physical cable disconnect.
  1005. * c. Source initiated power up sequence returns early because hpd is
  1006. * not high.
  1007. * d. Sink issues a hpd high attention event.
  1008. */
  1009. if (dp_display_state_is(DP_STATE_SRC_PWRDN) &&
  1010. dp_display_state_is(DP_STATE_CONFIGURED)) {
  1011. rc = dp_display_host_init(dp);
  1012. if (rc) {
  1013. DP_WARN("Host init Failed");
  1014. if (!dp_display_state_is(DP_STATE_SUSPENDED)) {
  1015. /*
  1016. * If not suspended no point of going forward if
  1017. * resource is not enabled.
  1018. */
  1019. dp_display_state_remove(DP_STATE_CONNECTED);
  1020. }
  1021. goto end;
  1022. }
  1023. /*
  1024. * If device is suspended and host_init fails, there is
  1025. * one more chance for host init to happen in prepare which
  1026. * is why DP_STATE_SRC_PWRDN is removed only at success.
  1027. */
  1028. dp_display_state_remove(DP_STATE_SRC_PWRDN);
  1029. }
  1030. rc = dp_display_host_ready(dp);
  1031. if (rc) {
  1032. dp_display_state_show("[ready failed]");
  1033. goto end;
  1034. }
  1035. dp->link->psm_config(dp->link, &dp->panel->link_info, false);
  1036. dp->debug->psm_enabled = false;
  1037. if (!dp->dp_display.base_connector)
  1038. goto end;
  1039. rc = dp->panel->read_sink_caps(dp->panel,
  1040. dp->dp_display.base_connector, dp->hpd->multi_func);
  1041. /*
  1042. * ETIMEDOUT --> cable may have been removed
  1043. * ENOTCONN --> no downstream device connected
  1044. */
  1045. if (rc == -ETIMEDOUT || rc == -ENOTCONN) {
  1046. dp_display_state_remove(DP_STATE_CONNECTED);
  1047. goto end;
  1048. }
  1049. dp->link->process_request(dp->link);
  1050. dp->panel->handle_sink_request(dp->panel);
  1051. dp_display_mst_init(dp);
  1052. rc = dp->ctrl->on(dp->ctrl, dp->mst.mst_active,
  1053. dp->panel->fec_en, dp->panel->dsc_en, false);
  1054. if (rc) {
  1055. dp_display_state_remove(DP_STATE_CONNECTED);
  1056. goto end;
  1057. }
  1058. dp->process_hpd_connect = false;
  1059. dp_display_set_mst_mgr_state(dp, true);
  1060. end:
  1061. mutex_unlock(&dp->session_lock);
  1062. /*
  1063. * Delay the HPD connect notification to see if sink generates any
  1064. * IRQ HPDs immediately after the HPD high.
  1065. */
  1066. reinit_completion(&dp->attention_comp);
  1067. wait_timeout_ms = min_t(unsigned long,
  1068. dp->debug->connect_notification_delay_ms,
  1069. (unsigned long) MAX_CONNECT_NOTIFICATION_DELAY_MS);
  1070. t = wait_for_completion_timeout(&dp->attention_comp,
  1071. msecs_to_jiffies(wait_timeout_ms));
  1072. DP_DEBUG("wait_timeout=%lu ms, time_waited=%u ms\n", wait_timeout_ms,
  1073. jiffies_to_msecs(t));
  1074. /*
  1075. * If an IRQ HPD is pending, then do not send a connect notification.
  1076. * Once this work returns, the IRQ HPD would be processed and any
  1077. * required actions (such as link maintenance) would be done which
  1078. * will subsequently send the HPD notification. To keep things simple,
  1079. * do this only for SST use-cases. MST use cases require additional
  1080. * care in order to handle the side-band communications as well.
  1081. *
  1082. * One of the main motivations for this is DP LL 1.4 CTS use case
  1083. * where it is possible that we could get a test request right after
  1084. * a connection, and the strict timing requriements of the test can
  1085. * only be met if we do not wait for the e2e connection to be set up.
  1086. */
  1087. if (!dp->mst.mst_active &&
  1088. (work_busy(&dp->attention_work) == WORK_BUSY_PENDING)) {
  1089. SDE_EVT32_EXTERNAL(dp->state, 99, jiffies_to_msecs(t));
  1090. DP_DEBUG("Attention pending, skip HPD notification\n");
  1091. goto skip_notify;
  1092. }
  1093. if (!rc && !dp_display_state_is(DP_STATE_ABORTED))
  1094. dp_display_send_hpd_notification(dp, false);
  1095. skip_notify:
  1096. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state,
  1097. wait_timeout_ms, rc);
  1098. return rc;
  1099. }
  1100. static void dp_display_process_mst_hpd_low(struct dp_display_private *dp, bool skip_wait)
  1101. {
  1102. int rc = 0;
  1103. if (dp->mst.mst_active) {
  1104. DP_MST_DEBUG("mst_hpd_low work\n");
  1105. /*
  1106. * HPD unplug callflow:
  1107. * 1. send hpd unplug on base connector so usermode can disable
  1108. * all external displays.
  1109. * 2. unset mst state in the topology mgr so the branch device
  1110. * can be cleaned up.
  1111. */
  1112. if ((dp_display_state_is(DP_STATE_CONNECT_NOTIFIED) ||
  1113. dp_display_state_is(DP_STATE_ENABLED)))
  1114. rc = dp_display_send_hpd_notification(dp, skip_wait);
  1115. dp_display_set_mst_mgr_state(dp, false);
  1116. dp_display_update_mst_state(dp, false);
  1117. }
  1118. DP_MST_DEBUG("mst_hpd_low. mst_active:%d\n", dp->mst.mst_active);
  1119. }
  1120. static int dp_display_process_hpd_low(struct dp_display_private *dp, bool skip_wait)
  1121. {
  1122. int rc = 0;
  1123. dp_display_state_remove(DP_STATE_CONNECTED);
  1124. dp->process_hpd_connect = false;
  1125. dp_audio_enable(dp, false);
  1126. if (dp->mst.mst_active) {
  1127. dp_display_process_mst_hpd_low(dp, skip_wait);
  1128. } else {
  1129. if ((dp_display_state_is(DP_STATE_CONNECT_NOTIFIED) ||
  1130. dp_display_state_is(DP_STATE_ENABLED)))
  1131. rc = dp_display_send_hpd_notification(dp, skip_wait);
  1132. }
  1133. mutex_lock(&dp->session_lock);
  1134. if (!dp->active_stream_cnt)
  1135. dp->ctrl->off(dp->ctrl);
  1136. mutex_unlock(&dp->session_lock);
  1137. dp->panel->video_test = false;
  1138. return rc;
  1139. }
  1140. static int dp_display_fsa4480_callback(struct notifier_block *self,
  1141. unsigned long event, void *data)
  1142. {
  1143. return 0;
  1144. }
  1145. static int dp_display_init_aux_switch(struct dp_display_private *dp)
  1146. {
  1147. int rc = 0;
  1148. struct notifier_block nb;
  1149. const u32 max_retries = 50;
  1150. u32 retry;
  1151. if (dp->aux_switch_ready)
  1152. return rc;
  1153. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY);
  1154. nb.notifier_call = dp_display_fsa4480_callback;
  1155. nb.priority = 0;
  1156. /*
  1157. * Iteratively wait for reg notifier which confirms that fsa driver is probed.
  1158. * Bootup DP with cable connected usecase can hit this scenario.
  1159. */
  1160. for (retry = 0; retry < max_retries; retry++) {
  1161. rc = fsa4480_reg_notifier(&nb, dp->aux_switch_node);
  1162. if (rc == 0) {
  1163. DP_DEBUG("registered notifier successfully\n");
  1164. dp->aux_switch_ready = true;
  1165. break;
  1166. } else {
  1167. DP_DEBUG("failed to register notifier retry=%d rc=%d\n", retry, rc);
  1168. msleep(100);
  1169. }
  1170. }
  1171. if (retry == max_retries) {
  1172. DP_WARN("Failed to register fsa notifier\n");
  1173. dp->aux_switch_ready = false;
  1174. return rc;
  1175. }
  1176. fsa4480_unreg_notifier(&nb, dp->aux_switch_node);
  1177. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, rc);
  1178. return rc;
  1179. }
  1180. static int dp_display_usbpd_configure_cb(struct device *dev)
  1181. {
  1182. int rc = 0;
  1183. struct dp_display_private *dp;
  1184. if (!dev) {
  1185. DP_ERR("invalid dev\n");
  1186. return -EINVAL;
  1187. }
  1188. dp = dev_get_drvdata(dev);
  1189. if (!dp) {
  1190. DP_ERR("no driver data found\n");
  1191. return -ENODEV;
  1192. }
  1193. if (!dp->debug->sim_mode && !dp->no_aux_switch
  1194. && !dp->parser->gpio_aux_switch && dp->aux_switch_node) {
  1195. rc = dp_display_init_aux_switch(dp);
  1196. if (rc)
  1197. return rc;
  1198. rc = dp->aux->aux_switch(dp->aux, true, dp->hpd->orientation);
  1199. if (rc)
  1200. return rc;
  1201. }
  1202. mutex_lock(&dp->session_lock);
  1203. if (dp_display_state_is(DP_STATE_TUI_ACTIVE)) {
  1204. dp_display_state_log("[TUI is active]");
  1205. mutex_unlock(&dp->session_lock);
  1206. return 0;
  1207. }
  1208. dp_display_state_remove(DP_STATE_ABORTED);
  1209. dp_display_state_add(DP_STATE_CONFIGURED);
  1210. rc = dp_display_host_init(dp);
  1211. if (rc) {
  1212. DP_ERR("Host init Failed");
  1213. mutex_unlock(&dp->session_lock);
  1214. return rc;
  1215. }
  1216. /* check for hpd high */
  1217. if (dp->hpd->hpd_high)
  1218. queue_work(dp->wq, &dp->connect_work);
  1219. else
  1220. dp->process_hpd_connect = true;
  1221. mutex_unlock(&dp->session_lock);
  1222. return 0;
  1223. }
  1224. static void dp_display_clear_reservation(struct dp_display *dp, struct dp_panel *panel)
  1225. {
  1226. struct dp_display_private *dp_display;
  1227. if (!dp || !panel) {
  1228. DP_ERR("invalid params\n");
  1229. return;
  1230. }
  1231. dp_display = container_of(dp, struct dp_display_private, dp_display);
  1232. mutex_lock(&dp_display->accounting_lock);
  1233. dp_display->tot_lm_blks_in_use -= panel->max_lm;
  1234. panel->max_lm = 0;
  1235. mutex_unlock(&dp_display->accounting_lock);
  1236. }
  1237. static void dp_display_clear_dsc_resources(struct dp_display_private *dp,
  1238. struct dp_panel *panel)
  1239. {
  1240. dp->tot_dsc_blks_in_use -= panel->dsc_blks_in_use;
  1241. panel->dsc_blks_in_use = 0;
  1242. }
  1243. static int dp_display_stream_pre_disable(struct dp_display_private *dp,
  1244. struct dp_panel *dp_panel)
  1245. {
  1246. if (!dp->active_stream_cnt) {
  1247. DP_WARN("streams already disabled cnt=%d\n",
  1248. dp->active_stream_cnt);
  1249. return 0;
  1250. }
  1251. dp->ctrl->stream_pre_off(dp->ctrl, dp_panel);
  1252. return 0;
  1253. }
  1254. static void dp_display_stream_disable(struct dp_display_private *dp,
  1255. struct dp_panel *dp_panel)
  1256. {
  1257. if (!dp->active_stream_cnt) {
  1258. DP_WARN("streams already disabled cnt=%d\n",
  1259. dp->active_stream_cnt);
  1260. return;
  1261. }
  1262. if (dp_panel->stream_id == DP_STREAM_MAX ||
  1263. !dp->active_panels[dp_panel->stream_id]) {
  1264. DP_ERR("panel is already disabled\n");
  1265. return;
  1266. }
  1267. dp_display_clear_dsc_resources(dp, dp_panel);
  1268. DP_DEBUG("stream_id=%d, active_stream_cnt=%d, tot_dsc_blks_in_use=%d\n",
  1269. dp_panel->stream_id, dp->active_stream_cnt,
  1270. dp->tot_dsc_blks_in_use);
  1271. dp->ctrl->stream_off(dp->ctrl, dp_panel);
  1272. dp->active_panels[dp_panel->stream_id] = NULL;
  1273. dp->active_stream_cnt--;
  1274. }
  1275. static void dp_display_clean(struct dp_display_private *dp, bool skip_wait)
  1276. {
  1277. int idx;
  1278. struct dp_panel *dp_panel;
  1279. struct dp_link_hdcp_status *status = &dp->link->hdcp_status;
  1280. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1281. if (dp_display_state_is(DP_STATE_TUI_ACTIVE)) {
  1282. DP_WARN("TUI is active\n");
  1283. return;
  1284. }
  1285. if (dp_display_is_hdcp_enabled(dp) &&
  1286. status->hdcp_state != HDCP_STATE_INACTIVE) {
  1287. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  1288. if (dp->hdcp.ops->off)
  1289. dp->hdcp.ops->off(dp->hdcp.data);
  1290. dp_display_update_hdcp_status(dp, true);
  1291. }
  1292. for (idx = DP_STREAM_0; idx < DP_STREAM_MAX; idx++) {
  1293. if (!dp->active_panels[idx])
  1294. continue;
  1295. dp_panel = dp->active_panels[idx];
  1296. if (dp_panel->audio_supported)
  1297. dp_panel->audio->off(dp_panel->audio, skip_wait);
  1298. if (!skip_wait)
  1299. dp_display_stream_pre_disable(dp, dp_panel);
  1300. dp_display_stream_disable(dp, dp_panel);
  1301. dp_display_clear_reservation(&dp->dp_display, dp_panel);
  1302. dp_panel->deinit(dp_panel, 0);
  1303. }
  1304. dp_display_state_remove(DP_STATE_ENABLED | DP_STATE_CONNECTED);
  1305. dp->ctrl->off(dp->ctrl);
  1306. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1307. }
  1308. static int dp_display_handle_disconnect(struct dp_display_private *dp, bool skip_wait)
  1309. {
  1310. int rc;
  1311. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1312. rc = dp_display_process_hpd_low(dp, skip_wait);
  1313. if (rc) {
  1314. /* cancel any pending request */
  1315. dp->ctrl->abort(dp->ctrl, true);
  1316. dp->aux->abort(dp->aux, true);
  1317. }
  1318. mutex_lock(&dp->session_lock);
  1319. if (dp_display_state_is(DP_STATE_ENABLED))
  1320. dp_display_clean(dp, skip_wait);
  1321. dp_display_host_unready(dp);
  1322. dp->tot_lm_blks_in_use = 0;
  1323. mutex_unlock(&dp->session_lock);
  1324. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1325. return rc;
  1326. }
  1327. static void dp_display_disconnect_sync(struct dp_display_private *dp)
  1328. {
  1329. int disconnect_delay_ms;
  1330. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1331. /* cancel any pending request */
  1332. dp_display_state_add(DP_STATE_ABORTED);
  1333. dp->ctrl->abort(dp->ctrl, true);
  1334. dp->aux->abort(dp->aux, true);
  1335. /* wait for idle state */
  1336. cancel_work_sync(&dp->connect_work);
  1337. cancel_work_sync(&dp->attention_work);
  1338. flush_workqueue(dp->wq);
  1339. if (!dp->debug->sim_mode && !dp->no_aux_switch
  1340. && !dp->parser->gpio_aux_switch)
  1341. dp->aux->aux_switch(dp->aux, false, ORIENTATION_NONE);
  1342. /*
  1343. * Delay the teardown of the mainlink for better interop experience.
  1344. * It is possible that certain sinks can issue an HPD high immediately
  1345. * following an HPD low as soon as they detect the mainlink being
  1346. * turned off. This can sometimes result in the HPD low pulse getting
  1347. * lost with certain cable. This issue is commonly seen when running
  1348. * DP LL CTS test 4.2.1.3.
  1349. */
  1350. disconnect_delay_ms = min_t(u32, dp->debug->disconnect_delay_ms,
  1351. (u32) MAX_DISCONNECT_DELAY_MS);
  1352. DP_DEBUG("disconnect delay = %d ms\n", disconnect_delay_ms);
  1353. msleep(disconnect_delay_ms);
  1354. dp_display_handle_disconnect(dp, false);
  1355. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state,
  1356. disconnect_delay_ms);
  1357. }
  1358. static int dp_display_usbpd_disconnect_cb(struct device *dev)
  1359. {
  1360. int rc = 0;
  1361. struct dp_display_private *dp;
  1362. if (!dev) {
  1363. DP_ERR("invalid dev\n");
  1364. rc = -EINVAL;
  1365. goto end;
  1366. }
  1367. dp = dev_get_drvdata(dev);
  1368. if (!dp) {
  1369. DP_ERR("no driver data found\n");
  1370. rc = -ENODEV;
  1371. goto end;
  1372. }
  1373. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state,
  1374. dp->debug->psm_enabled);
  1375. /* skip if a disconnect is already in progress */
  1376. if (dp_display_state_is(DP_STATE_ABORTED) &&
  1377. dp_display_state_is(DP_STATE_READY)) {
  1378. DP_DEBUG("disconnect already in progress\n");
  1379. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_CASE1, dp->state);
  1380. return 0;
  1381. }
  1382. if (dp->debug->psm_enabled && dp_display_state_is(DP_STATE_READY))
  1383. dp->link->psm_config(dp->link, &dp->panel->link_info, true);
  1384. dp_display_disconnect_sync(dp);
  1385. mutex_lock(&dp->session_lock);
  1386. dp_display_host_deinit(dp);
  1387. dp_display_state_remove(DP_STATE_CONFIGURED);
  1388. mutex_unlock(&dp->session_lock);
  1389. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1390. end:
  1391. return rc;
  1392. }
  1393. static int dp_display_stream_enable(struct dp_display_private *dp,
  1394. struct dp_panel *dp_panel)
  1395. {
  1396. int rc = 0;
  1397. rc = dp->ctrl->stream_on(dp->ctrl, dp_panel);
  1398. if (dp->debug->tpg_pattern)
  1399. dp_panel->tpg_config(dp_panel, dp->debug->tpg_pattern);
  1400. if (!rc) {
  1401. dp->active_panels[dp_panel->stream_id] = dp_panel;
  1402. dp->active_stream_cnt++;
  1403. }
  1404. DP_DEBUG("dp active_stream_cnt:%d, tot_dsc_blks_in_use=%d\n",
  1405. dp->active_stream_cnt, dp->tot_dsc_blks_in_use);
  1406. return rc;
  1407. }
  1408. static void dp_display_mst_attention(struct dp_display_private *dp)
  1409. {
  1410. if (dp->mst.mst_active && dp->mst.cbs.hpd_irq)
  1411. dp->mst.cbs.hpd_irq(&dp->dp_display);
  1412. DP_MST_DEBUG("mst_attention_work. mst_active:%d\n", dp->mst.mst_active);
  1413. }
  1414. static void dp_display_attention_work(struct work_struct *work)
  1415. {
  1416. struct dp_display_private *dp = container_of(work,
  1417. struct dp_display_private, attention_work);
  1418. int rc = 0;
  1419. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1420. mutex_lock(&dp->session_lock);
  1421. SDE_EVT32_EXTERNAL(dp->state);
  1422. if (dp_display_state_is(DP_STATE_ABORTED)) {
  1423. DP_INFO("Hpd off, not handling any attention\n");
  1424. mutex_unlock(&dp->session_lock);
  1425. goto exit;
  1426. }
  1427. if (!dp_display_state_is(DP_STATE_READY)) {
  1428. mutex_unlock(&dp->session_lock);
  1429. goto mst_attention;
  1430. }
  1431. if (dp->link->process_request(dp->link)) {
  1432. mutex_unlock(&dp->session_lock);
  1433. goto cp_irq;
  1434. }
  1435. mutex_unlock(&dp->session_lock);
  1436. SDE_EVT32_EXTERNAL(dp->state, dp->link->sink_request);
  1437. if (dp->link->sink_request & DS_PORT_STATUS_CHANGED) {
  1438. SDE_EVT32_EXTERNAL(dp->state, DS_PORT_STATUS_CHANGED);
  1439. if (!dp->mst.mst_active) {
  1440. if (dp_display_is_sink_count_zero(dp)) {
  1441. dp_display_handle_disconnect(dp, false);
  1442. } else {
  1443. /*
  1444. * connect work should take care of sending
  1445. * the HPD notification.
  1446. */
  1447. queue_work(dp->wq, &dp->connect_work);
  1448. }
  1449. }
  1450. goto mst_attention;
  1451. }
  1452. if (dp->link->sink_request & DP_TEST_LINK_VIDEO_PATTERN) {
  1453. SDE_EVT32_EXTERNAL(dp->state, DP_TEST_LINK_VIDEO_PATTERN);
  1454. dp_display_handle_disconnect(dp, false);
  1455. dp->panel->video_test = true;
  1456. /*
  1457. * connect work should take care of sending
  1458. * the HPD notification.
  1459. */
  1460. queue_work(dp->wq, &dp->connect_work);
  1461. goto mst_attention;
  1462. }
  1463. if (dp->link->sink_request & (DP_TEST_LINK_PHY_TEST_PATTERN |
  1464. DP_TEST_LINK_TRAINING | DP_LINK_STATUS_UPDATED)) {
  1465. mutex_lock(&dp->session_lock);
  1466. dp_audio_enable(dp, false);
  1467. if (dp->link->sink_request & DP_TEST_LINK_PHY_TEST_PATTERN) {
  1468. SDE_EVT32_EXTERNAL(dp->state,
  1469. DP_TEST_LINK_PHY_TEST_PATTERN);
  1470. dp->ctrl->process_phy_test_request(dp->ctrl);
  1471. }
  1472. if (dp->link->sink_request & DP_TEST_LINK_TRAINING) {
  1473. SDE_EVT32_EXTERNAL(dp->state, DP_TEST_LINK_TRAINING);
  1474. dp->link->send_test_response(dp->link);
  1475. rc = dp->ctrl->link_maintenance(dp->ctrl);
  1476. }
  1477. if (dp->link->sink_request & DP_LINK_STATUS_UPDATED) {
  1478. SDE_EVT32_EXTERNAL(dp->state, DP_LINK_STATUS_UPDATED);
  1479. rc = dp->ctrl->link_maintenance(dp->ctrl);
  1480. }
  1481. if (!rc)
  1482. dp_audio_enable(dp, true);
  1483. mutex_unlock(&dp->session_lock);
  1484. if (rc)
  1485. goto exit;
  1486. if (dp->link->sink_request & (DP_TEST_LINK_PHY_TEST_PATTERN |
  1487. DP_TEST_LINK_TRAINING))
  1488. goto mst_attention;
  1489. }
  1490. cp_irq:
  1491. if (dp_display_is_hdcp_enabled(dp) && dp->hdcp.ops->cp_irq)
  1492. dp->hdcp.ops->cp_irq(dp->hdcp.data);
  1493. if (!dp->mst.mst_active) {
  1494. /*
  1495. * It is possible that the connect_work skipped sending
  1496. * the HPD notification if the attention message was
  1497. * already pending. Send the notification here to
  1498. * account for that. This is not needed if this
  1499. * attention work was handling a test request
  1500. */
  1501. dp_display_send_hpd_notification(dp, false);
  1502. }
  1503. mst_attention:
  1504. dp_display_mst_attention(dp);
  1505. exit:
  1506. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1507. }
  1508. static int dp_display_usbpd_attention_cb(struct device *dev)
  1509. {
  1510. struct dp_display_private *dp;
  1511. if (!dev) {
  1512. DP_ERR("invalid dev\n");
  1513. return -EINVAL;
  1514. }
  1515. dp = dev_get_drvdata(dev);
  1516. if (!dp) {
  1517. DP_ERR("no driver data found\n");
  1518. return -ENODEV;
  1519. }
  1520. DP_DEBUG("hpd_irq:%d, hpd_high:%d, power_on:%d, is_connected:%d\n",
  1521. dp->hpd->hpd_irq, dp->hpd->hpd_high,
  1522. !!dp_display_state_is(DP_STATE_ENABLED),
  1523. !!dp_display_state_is(DP_STATE_CONNECTED));
  1524. SDE_EVT32_EXTERNAL(dp->state, dp->hpd->hpd_irq, dp->hpd->hpd_high,
  1525. !!dp_display_state_is(DP_STATE_ENABLED),
  1526. !!dp_display_state_is(DP_STATE_CONNECTED));
  1527. if (!dp->hpd->hpd_high) {
  1528. dp_display_disconnect_sync(dp);
  1529. return 0;
  1530. }
  1531. /*
  1532. * Ignore all the attention messages except HPD LOW when TUI is
  1533. * active, so user mode can be notified of the disconnect event. This
  1534. * allows user mode to tear down the control path after the TUI
  1535. * session is over. Ideally this should never happen, but on the off
  1536. * chance that there is a race condition in which there is a IRQ HPD
  1537. * during tear down of DP at TUI start then this check might help avoid
  1538. * a potential issue accessing registers in attention processing.
  1539. */
  1540. if (dp_display_state_is(DP_STATE_TUI_ACTIVE)) {
  1541. DP_WARN("TUI is active\n");
  1542. return 0;
  1543. }
  1544. if (dp->hpd->hpd_irq && dp_display_state_is(DP_STATE_READY)) {
  1545. queue_work(dp->wq, &dp->attention_work);
  1546. complete_all(&dp->attention_comp);
  1547. } else if (dp->process_hpd_connect ||
  1548. !dp_display_state_is(DP_STATE_CONNECTED)) {
  1549. dp_display_state_remove(DP_STATE_ABORTED);
  1550. queue_work(dp->wq, &dp->connect_work);
  1551. } else {
  1552. DP_DEBUG("ignored\n");
  1553. }
  1554. return 0;
  1555. }
  1556. static void dp_display_connect_work(struct work_struct *work)
  1557. {
  1558. int rc = 0;
  1559. struct dp_display_private *dp = container_of(work,
  1560. struct dp_display_private, connect_work);
  1561. if (dp_display_state_is(DP_STATE_TUI_ACTIVE)) {
  1562. dp_display_state_log("[TUI is active]");
  1563. return;
  1564. }
  1565. if (dp_display_state_is(DP_STATE_ABORTED)) {
  1566. DP_WARN("HPD off requested\n");
  1567. return;
  1568. }
  1569. if (!dp->hpd->hpd_high) {
  1570. DP_WARN("Sink disconnected\n");
  1571. return;
  1572. }
  1573. rc = dp_display_process_hpd_high(dp);
  1574. if (!rc && dp->panel->video_test)
  1575. dp->link->send_test_response(dp->link);
  1576. }
  1577. static int dp_display_usb_notifier(struct notifier_block *nb,
  1578. unsigned long action, void *data)
  1579. {
  1580. struct dp_display_private *dp = container_of(nb,
  1581. struct dp_display_private, usb_nb);
  1582. SDE_EVT32_EXTERNAL(dp->state, dp->debug->sim_mode, action);
  1583. if (!action && dp->debug->sim_mode) {
  1584. DP_WARN("usb disconnected during simulation\n");
  1585. dp_display_state_add(DP_STATE_ABORTED);
  1586. dp->ctrl->abort(dp->ctrl, true);
  1587. dp->aux->abort(dp->aux, true);
  1588. dp_display_handle_disconnect(dp, true);
  1589. dp->debug->abort(dp->debug);
  1590. }
  1591. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, NOTIFY_DONE);
  1592. return NOTIFY_DONE;
  1593. }
  1594. static void dp_display_register_usb_notifier(struct dp_display_private *dp)
  1595. {
  1596. int rc = 0;
  1597. const char *phandle = "usb-phy";
  1598. struct usb_phy *usbphy;
  1599. usbphy = devm_usb_get_phy_by_phandle(&dp->pdev->dev, phandle, 0);
  1600. if (IS_ERR_OR_NULL(usbphy)) {
  1601. DP_DEBUG("unable to get usbphy\n");
  1602. return;
  1603. }
  1604. dp->usb_nb.notifier_call = dp_display_usb_notifier;
  1605. dp->usb_nb.priority = 2;
  1606. rc = usb_register_notifier(usbphy, &dp->usb_nb);
  1607. if (rc)
  1608. DP_DEBUG("failed to register for usb event: %d\n", rc);
  1609. }
  1610. int dp_display_mmrm_callback(struct mmrm_client_notifier_data *notifier_data)
  1611. {
  1612. struct dss_clk_mmrm_cb *mmrm_cb_data = (struct dss_clk_mmrm_cb *)notifier_data->pvt_data;
  1613. struct dp_display *dp_display = (struct dp_display *)mmrm_cb_data->phandle;
  1614. struct dp_display_private *dp =
  1615. container_of(dp_display, struct dp_display_private, dp_display);
  1616. int ret = 0;
  1617. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state, notifier_data->cb_type);
  1618. if (notifier_data->cb_type == MMRM_CLIENT_RESOURCE_VALUE_CHANGE
  1619. && dp_display_state_is(DP_STATE_ENABLED)
  1620. && !dp_display_state_is(DP_STATE_ABORTED)) {
  1621. ret = dp_display_handle_disconnect(dp, false);
  1622. if (ret)
  1623. DP_ERR("mmrm callback error reducing clk, ret:%d\n", ret);
  1624. }
  1625. DP_DEBUG("mmrm callback handled, state: 0x%x rc:%d\n", dp->state, ret);
  1626. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, notifier_data->cb_type);
  1627. return ret;
  1628. }
  1629. static void dp_display_deinit_sub_modules(struct dp_display_private *dp)
  1630. {
  1631. dp_debug_put(dp->debug);
  1632. dp_hpd_put(dp->hpd);
  1633. if (dp->panel)
  1634. dp_audio_put(dp->panel->audio);
  1635. dp_ctrl_put(dp->ctrl);
  1636. dp_panel_put(dp->panel);
  1637. dp_link_put(dp->link);
  1638. dp_power_put(dp->power);
  1639. dp_pll_put(dp->pll);
  1640. dp_aux_put(dp->aux);
  1641. dp_catalog_put(dp->catalog);
  1642. dp_parser_put(dp->parser);
  1643. mutex_destroy(&dp->session_lock);
  1644. }
  1645. static int dp_init_sub_modules(struct dp_display_private *dp)
  1646. {
  1647. int rc = 0;
  1648. u32 dp_core_revision = 0;
  1649. bool hdcp_disabled;
  1650. const char *phandle = "qcom,dp-aux-switch";
  1651. struct device *dev = &dp->pdev->dev;
  1652. struct dp_hpd_cb *cb = &dp->hpd_cb;
  1653. struct dp_ctrl_in ctrl_in = {
  1654. .dev = dev,
  1655. };
  1656. struct dp_panel_in panel_in = {
  1657. .dev = dev,
  1658. };
  1659. struct dp_debug_in debug_in = {
  1660. .dev = dev,
  1661. };
  1662. struct dp_pll_in pll_in = {
  1663. .pdev = dp->pdev,
  1664. };
  1665. mutex_init(&dp->session_lock);
  1666. mutex_init(&dp->accounting_lock);
  1667. dp->parser = dp_parser_get(dp->pdev);
  1668. if (IS_ERR(dp->parser)) {
  1669. rc = PTR_ERR(dp->parser);
  1670. DP_ERR("failed to initialize parser, rc = %d\n", rc);
  1671. dp->parser = NULL;
  1672. goto error;
  1673. }
  1674. rc = dp->parser->parse(dp->parser);
  1675. if (rc) {
  1676. DP_ERR("device tree parsing failed\n");
  1677. goto error_catalog;
  1678. }
  1679. g_dp_display->is_mst_supported = dp->parser->has_mst;
  1680. g_dp_display->dsc_cont_pps = dp->parser->dsc_continuous_pps;
  1681. dp->catalog = dp_catalog_get(dev, dp->parser);
  1682. if (IS_ERR(dp->catalog)) {
  1683. rc = PTR_ERR(dp->catalog);
  1684. DP_ERR("failed to initialize catalog, rc = %d\n", rc);
  1685. dp->catalog = NULL;
  1686. goto error_catalog;
  1687. }
  1688. dp_core_revision = dp_catalog_get_dp_core_version(dp->catalog);
  1689. dp->aux_switch_node = of_parse_phandle(dp->pdev->dev.of_node, phandle, 0);
  1690. if (!dp->aux_switch_node) {
  1691. DP_DEBUG("cannot parse %s handle\n", phandle);
  1692. dp->no_aux_switch = true;
  1693. }
  1694. dp->aux = dp_aux_get(dev, &dp->catalog->aux, dp->parser,
  1695. dp->aux_switch_node, dp->aux_bridge);
  1696. if (IS_ERR(dp->aux)) {
  1697. rc = PTR_ERR(dp->aux);
  1698. DP_ERR("failed to initialize aux, rc = %d\n", rc);
  1699. dp->aux = NULL;
  1700. goto error_aux;
  1701. }
  1702. rc = dp->aux->drm_aux_register(dp->aux, dp->dp_display.drm_dev);
  1703. if (rc) {
  1704. DP_ERR("DRM DP AUX register failed\n");
  1705. goto error_pll;
  1706. }
  1707. pll_in.aux = dp->aux;
  1708. pll_in.parser = dp->parser;
  1709. pll_in.dp_core_revision = dp_core_revision;
  1710. dp->pll = dp_pll_get(&pll_in);
  1711. if (IS_ERR(dp->pll)) {
  1712. rc = PTR_ERR(dp->pll);
  1713. DP_ERR("failed to initialize pll, rc = %d\n", rc);
  1714. dp->pll = NULL;
  1715. goto error_pll;
  1716. }
  1717. dp->power = dp_power_get(dp->parser, dp->pll);
  1718. if (IS_ERR(dp->power)) {
  1719. rc = PTR_ERR(dp->power);
  1720. DP_ERR("failed to initialize power, rc = %d\n", rc);
  1721. dp->power = NULL;
  1722. goto error_power;
  1723. }
  1724. rc = dp->power->power_client_init(dp->power, &dp->priv->phandle,
  1725. dp->dp_display.drm_dev);
  1726. if (rc) {
  1727. DP_ERR("Power client create failed\n");
  1728. goto error_link;
  1729. }
  1730. rc = dp->power->power_mmrm_init(dp->power, &dp->priv->phandle,
  1731. (void *)&dp->dp_display, dp_display_mmrm_callback);
  1732. if (rc) {
  1733. DP_ERR("failed to initialize mmrm, rc = %d\n", rc);
  1734. goto error_link;
  1735. }
  1736. dp->link = dp_link_get(dev, dp->aux, dp_core_revision);
  1737. if (IS_ERR(dp->link)) {
  1738. rc = PTR_ERR(dp->link);
  1739. DP_ERR("failed to initialize link, rc = %d\n", rc);
  1740. dp->link = NULL;
  1741. goto error_link;
  1742. }
  1743. panel_in.aux = dp->aux;
  1744. panel_in.catalog = &dp->catalog->panel;
  1745. panel_in.link = dp->link;
  1746. panel_in.connector = dp->dp_display.base_connector;
  1747. panel_in.base_panel = NULL;
  1748. panel_in.parser = dp->parser;
  1749. dp->panel = dp_panel_get(&panel_in);
  1750. if (IS_ERR(dp->panel)) {
  1751. rc = PTR_ERR(dp->panel);
  1752. DP_ERR("failed to initialize panel, rc = %d\n", rc);
  1753. dp->panel = NULL;
  1754. goto error_panel;
  1755. }
  1756. ctrl_in.link = dp->link;
  1757. ctrl_in.panel = dp->panel;
  1758. ctrl_in.aux = dp->aux;
  1759. ctrl_in.power = dp->power;
  1760. ctrl_in.catalog = &dp->catalog->ctrl;
  1761. ctrl_in.parser = dp->parser;
  1762. ctrl_in.pll = dp->pll;
  1763. dp->ctrl = dp_ctrl_get(&ctrl_in);
  1764. if (IS_ERR(dp->ctrl)) {
  1765. rc = PTR_ERR(dp->ctrl);
  1766. DP_ERR("failed to initialize ctrl, rc = %d\n", rc);
  1767. dp->ctrl = NULL;
  1768. goto error_ctrl;
  1769. }
  1770. dp->panel->audio = dp_audio_get(dp->pdev, dp->panel,
  1771. &dp->catalog->audio);
  1772. if (IS_ERR(dp->panel->audio)) {
  1773. rc = PTR_ERR(dp->panel->audio);
  1774. DP_ERR("failed to initialize audio, rc = %d\n", rc);
  1775. dp->panel->audio = NULL;
  1776. goto error_audio;
  1777. }
  1778. memset(&dp->mst, 0, sizeof(dp->mst));
  1779. dp->active_stream_cnt = 0;
  1780. cb->configure = dp_display_usbpd_configure_cb;
  1781. cb->disconnect = dp_display_usbpd_disconnect_cb;
  1782. cb->attention = dp_display_usbpd_attention_cb;
  1783. dp->hpd = dp_hpd_get(dev, dp->parser, &dp->catalog->hpd,
  1784. dp->aux_bridge, cb);
  1785. if (IS_ERR(dp->hpd)) {
  1786. rc = PTR_ERR(dp->hpd);
  1787. DP_ERR("failed to initialize hpd, rc = %d\n", rc);
  1788. dp->hpd = NULL;
  1789. goto error_hpd;
  1790. }
  1791. hdcp_disabled = !!dp_display_initialize_hdcp(dp);
  1792. debug_in.panel = dp->panel;
  1793. debug_in.hpd = dp->hpd;
  1794. debug_in.link = dp->link;
  1795. debug_in.aux = dp->aux;
  1796. debug_in.connector = &dp->dp_display.base_connector;
  1797. debug_in.catalog = dp->catalog;
  1798. debug_in.parser = dp->parser;
  1799. debug_in.ctrl = dp->ctrl;
  1800. debug_in.pll = dp->pll;
  1801. debug_in.display = &dp->dp_display;
  1802. dp->debug = dp_debug_get(&debug_in);
  1803. if (IS_ERR(dp->debug)) {
  1804. rc = PTR_ERR(dp->debug);
  1805. DP_ERR("failed to initialize debug, rc = %d\n", rc);
  1806. dp->debug = NULL;
  1807. goto error_debug;
  1808. }
  1809. dp->cached_connector_status = connector_status_disconnected;
  1810. dp->tot_dsc_blks_in_use = 0;
  1811. dp->tot_lm_blks_in_use = 0;
  1812. dp->debug->hdcp_disabled = hdcp_disabled;
  1813. dp_display_update_hdcp_status(dp, true);
  1814. dp_display_register_usb_notifier(dp);
  1815. if (dp->hpd->register_hpd) {
  1816. rc = dp->hpd->register_hpd(dp->hpd);
  1817. if (rc) {
  1818. DP_ERR("failed register hpd\n");
  1819. goto error_hpd_reg;
  1820. }
  1821. }
  1822. return rc;
  1823. error_hpd_reg:
  1824. dp_debug_put(dp->debug);
  1825. error_debug:
  1826. dp_hpd_put(dp->hpd);
  1827. error_hpd:
  1828. dp_audio_put(dp->panel->audio);
  1829. error_audio:
  1830. dp_ctrl_put(dp->ctrl);
  1831. error_ctrl:
  1832. dp_panel_put(dp->panel);
  1833. error_panel:
  1834. dp_link_put(dp->link);
  1835. error_link:
  1836. dp_power_put(dp->power);
  1837. error_power:
  1838. dp_pll_put(dp->pll);
  1839. error_pll:
  1840. dp_aux_put(dp->aux);
  1841. error_aux:
  1842. dp_catalog_put(dp->catalog);
  1843. error_catalog:
  1844. dp_parser_put(dp->parser);
  1845. error:
  1846. mutex_destroy(&dp->session_lock);
  1847. return rc;
  1848. }
  1849. static int dp_display_post_init(struct dp_display *dp_display)
  1850. {
  1851. int rc = 0;
  1852. struct dp_display_private *dp;
  1853. if (!dp_display) {
  1854. DP_ERR("invalid input\n");
  1855. rc = -EINVAL;
  1856. goto end;
  1857. }
  1858. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1859. if (IS_ERR_OR_NULL(dp)) {
  1860. DP_ERR("invalid params\n");
  1861. rc = -EINVAL;
  1862. goto end;
  1863. }
  1864. rc = dp_init_sub_modules(dp);
  1865. if (rc)
  1866. goto end;
  1867. dp_display->post_init = NULL;
  1868. end:
  1869. DP_DEBUG("%s\n", rc ? "failed" : "success");
  1870. return rc;
  1871. }
  1872. static int dp_display_set_mode(struct dp_display *dp_display, void *panel,
  1873. struct dp_display_mode *mode)
  1874. {
  1875. const u32 num_components = 3, default_bpp = 24;
  1876. struct dp_display_private *dp;
  1877. struct dp_panel *dp_panel;
  1878. bool dsc_en = (mode->capabilities & DP_PANEL_CAPS_DSC) ? true : false;
  1879. if (!dp_display || !panel) {
  1880. DP_ERR("invalid input\n");
  1881. return -EINVAL;
  1882. }
  1883. dp_panel = panel;
  1884. if (!dp_panel->connector) {
  1885. DP_ERR("invalid connector input\n");
  1886. return -EINVAL;
  1887. }
  1888. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1889. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state,
  1890. mode->timing.h_active, mode->timing.v_active,
  1891. mode->timing.refresh_rate);
  1892. mutex_lock(&dp->session_lock);
  1893. mode->timing.bpp =
  1894. dp_panel->connector->display_info.bpc * num_components;
  1895. if (!mode->timing.bpp)
  1896. mode->timing.bpp = default_bpp;
  1897. mode->timing.bpp = dp->panel->get_mode_bpp(dp->panel,
  1898. mode->timing.bpp, mode->timing.pixel_clk_khz, dsc_en);
  1899. dp_panel->pinfo = mode->timing;
  1900. mutex_unlock(&dp->session_lock);
  1901. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  1902. return 0;
  1903. }
  1904. static int dp_display_prepare(struct dp_display *dp_display, void *panel)
  1905. {
  1906. struct dp_display_private *dp;
  1907. struct dp_panel *dp_panel;
  1908. int rc = 0;
  1909. if (!dp_display || !panel) {
  1910. DP_ERR("invalid input\n");
  1911. return -EINVAL;
  1912. }
  1913. dp_panel = panel;
  1914. if (!dp_panel->connector) {
  1915. DP_ERR("invalid connector input\n");
  1916. return -EINVAL;
  1917. }
  1918. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1919. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  1920. mutex_lock(&dp->session_lock);
  1921. /*
  1922. * If DP video session is restored by the userspace after display
  1923. * disconnect notification from dongle i.e. typeC cable connected to
  1924. * source but disconnected at the display side, the DP controller is
  1925. * not restored to the desired configured state. So, ensure host_init
  1926. * is executed in such a scenario so that all the DP controller
  1927. * resources are enabled for the next connection event.
  1928. */
  1929. if (dp_display_state_is(DP_STATE_SRC_PWRDN) &&
  1930. dp_display_state_is(DP_STATE_CONFIGURED)) {
  1931. rc = dp_display_host_init(dp);
  1932. if (rc) {
  1933. /*
  1934. * Skip all the events that are similar to abort case, just that
  1935. * the stream clks should be enabled so that no commit failure can
  1936. * be seen.
  1937. */
  1938. DP_ERR("Host init failed.\n");
  1939. goto end;
  1940. }
  1941. /*
  1942. * Remove DP_STATE_SRC_PWRDN flag on successful host_init to
  1943. * prevent cases such as below.
  1944. * 1. MST stream 1 failed to do host init then stream 2 can retry again.
  1945. * 2. Resume path fails, now sink sends hpd_high=0 and hpd_high=1.
  1946. */
  1947. dp_display_state_remove(DP_STATE_SRC_PWRDN);
  1948. }
  1949. /*
  1950. * If the physical connection to the sink is already lost by the time
  1951. * we try to set up the connection, we can just skip all the steps
  1952. * here safely.
  1953. */
  1954. if (dp_display_state_is(DP_STATE_ABORTED)) {
  1955. dp_display_state_log("[aborted]");
  1956. goto end;
  1957. }
  1958. /*
  1959. * If DP_STATE_ENABLED, there is nothing left to do.
  1960. * This would happen during MST flow. So, log this.
  1961. */
  1962. if (dp_display_state_is(DP_STATE_ENABLED)) {
  1963. dp_display_state_warn("[already enabled]");
  1964. goto end;
  1965. }
  1966. if (!dp_display_is_ready(dp)) {
  1967. dp_display_state_show("[not ready]");
  1968. goto end;
  1969. }
  1970. /* For supporting DP_PANEL_SRC_INITIATED_POWER_DOWN case */
  1971. rc = dp_display_host_ready(dp);
  1972. if (rc) {
  1973. dp_display_state_show("[ready failed]");
  1974. goto end;
  1975. }
  1976. if (dp->debug->psm_enabled) {
  1977. dp->link->psm_config(dp->link, &dp->panel->link_info, false);
  1978. dp->debug->psm_enabled = false;
  1979. }
  1980. /*
  1981. * Execute the dp controller power on in shallow mode here.
  1982. * In normal cases, controller should have been powered on
  1983. * by now. In some cases like suspend/resume or framework
  1984. * reboot, we end up here without a powered on controller.
  1985. * Cable may have been removed in suspended state. In that
  1986. * case, link training is bound to fail on system resume.
  1987. * So, we execute in shallow mode here to do only minimal
  1988. * and required things.
  1989. */
  1990. rc = dp->ctrl->on(dp->ctrl, dp->mst.mst_active, dp_panel->fec_en,
  1991. dp_panel->dsc_en, true);
  1992. if (rc)
  1993. goto end;
  1994. end:
  1995. mutex_unlock(&dp->session_lock);
  1996. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, rc);
  1997. return rc;
  1998. }
  1999. static int dp_display_set_stream_info(struct dp_display *dp_display,
  2000. void *panel, u32 strm_id, u32 start_slot,
  2001. u32 num_slots, u32 pbn, int vcpi)
  2002. {
  2003. int rc = 0;
  2004. struct dp_panel *dp_panel;
  2005. struct dp_display_private *dp;
  2006. const int max_slots = 64;
  2007. if (!dp_display) {
  2008. DP_ERR("invalid input\n");
  2009. return -EINVAL;
  2010. }
  2011. if (strm_id >= DP_STREAM_MAX) {
  2012. DP_ERR("invalid stream id:%d\n", strm_id);
  2013. return -EINVAL;
  2014. }
  2015. if (start_slot + num_slots > max_slots) {
  2016. DP_ERR("invalid channel info received. start:%d, slots:%d\n",
  2017. start_slot, num_slots);
  2018. return -EINVAL;
  2019. }
  2020. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2021. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state, strm_id,
  2022. start_slot, num_slots);
  2023. mutex_lock(&dp->session_lock);
  2024. dp->ctrl->set_mst_channel_info(dp->ctrl, strm_id,
  2025. start_slot, num_slots);
  2026. if (panel) {
  2027. dp_panel = panel;
  2028. dp_panel->set_stream_info(dp_panel, strm_id, start_slot,
  2029. num_slots, pbn, vcpi);
  2030. }
  2031. mutex_unlock(&dp->session_lock);
  2032. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, rc);
  2033. return rc;
  2034. }
  2035. static int dp_display_enable(struct dp_display *dp_display, void *panel)
  2036. {
  2037. int rc = 0;
  2038. struct dp_display_private *dp;
  2039. if (!dp_display || !panel) {
  2040. DP_ERR("invalid input\n");
  2041. return -EINVAL;
  2042. }
  2043. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2044. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2045. mutex_lock(&dp->session_lock);
  2046. /*
  2047. * If DP_STATE_READY is not set, we should not do any HW
  2048. * programming.
  2049. */
  2050. if (!dp_display_state_is(DP_STATE_READY)) {
  2051. dp_display_state_show("[host not ready]");
  2052. goto end;
  2053. }
  2054. /*
  2055. * It is possible that by the time we get call back to establish
  2056. * the DP pipeline e2e, the physical DP connection to the sink is
  2057. * already lost. In such cases, the DP_STATE_ABORTED would be set.
  2058. * However, it is necessary to NOT abort the display setup here so as
  2059. * to ensure that the rest of the system is in a stable state prior to
  2060. * handling the disconnect notification.
  2061. */
  2062. if (dp_display_state_is(DP_STATE_ABORTED))
  2063. dp_display_state_log("[aborted, but continue on]");
  2064. rc = dp_display_stream_enable(dp, panel);
  2065. if (rc)
  2066. goto end;
  2067. dp_display_state_add(DP_STATE_ENABLED);
  2068. end:
  2069. mutex_unlock(&dp->session_lock);
  2070. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, rc);
  2071. return rc;
  2072. }
  2073. static void dp_display_stream_post_enable(struct dp_display_private *dp,
  2074. struct dp_panel *dp_panel)
  2075. {
  2076. dp_panel->spd_config(dp_panel);
  2077. dp_panel->setup_hdr(dp_panel, NULL, false, 0, true);
  2078. }
  2079. static int dp_display_post_enable(struct dp_display *dp_display, void *panel)
  2080. {
  2081. struct dp_display_private *dp;
  2082. struct dp_panel *dp_panel;
  2083. if (!dp_display || !panel) {
  2084. DP_ERR("invalid input\n");
  2085. return -EINVAL;
  2086. }
  2087. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2088. dp_panel = panel;
  2089. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2090. mutex_lock(&dp->session_lock);
  2091. /*
  2092. * If DP_STATE_READY is not set, we should not do any HW
  2093. * programming.
  2094. */
  2095. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  2096. dp_display_state_show("[not enabled]");
  2097. goto end;
  2098. }
  2099. /*
  2100. * If the physical connection to the sink is already lost by the time
  2101. * we try to set up the connection, we can just skip all the steps
  2102. * here safely.
  2103. */
  2104. if (dp_display_state_is(DP_STATE_ABORTED)) {
  2105. dp_display_state_log("[aborted]");
  2106. goto end;
  2107. }
  2108. if (!dp_display_is_ready(dp) || !dp_display_state_is(DP_STATE_READY)) {
  2109. dp_display_state_show("[not ready]");
  2110. goto end;
  2111. }
  2112. dp_display_stream_post_enable(dp, dp_panel);
  2113. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  2114. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ);
  2115. if (dp_panel->audio_supported) {
  2116. dp_panel->audio->bw_code = dp->link->link_params.bw_code;
  2117. dp_panel->audio->lane_count = dp->link->link_params.lane_count;
  2118. dp_panel->audio->on(dp_panel->audio);
  2119. }
  2120. dp->aux->state &= ~DP_STATE_CTRL_POWERED_OFF;
  2121. dp->aux->state |= DP_STATE_CTRL_POWERED_ON;
  2122. complete_all(&dp->notification_comp);
  2123. DP_DEBUG("display post enable complete. state: 0x%x\n", dp->state);
  2124. end:
  2125. mutex_unlock(&dp->session_lock);
  2126. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  2127. return 0;
  2128. }
  2129. static void dp_display_clear_colorspaces(struct dp_display *dp_display)
  2130. {
  2131. struct drm_connector *connector;
  2132. struct sde_connector *sde_conn;
  2133. connector = dp_display->base_connector;
  2134. sde_conn = to_sde_connector(connector);
  2135. sde_conn->color_enc_fmt = 0;
  2136. }
  2137. static int dp_display_pre_disable(struct dp_display *dp_display, void *panel)
  2138. {
  2139. struct dp_display_private *dp;
  2140. struct dp_panel *dp_panel = panel;
  2141. struct dp_link_hdcp_status *status;
  2142. int rc = 0;
  2143. size_t i;
  2144. if (!dp_display || !panel) {
  2145. DP_ERR("invalid input\n");
  2146. return -EINVAL;
  2147. }
  2148. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2149. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2150. mutex_lock(&dp->session_lock);
  2151. status = &dp->link->hdcp_status;
  2152. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  2153. dp_display_state_show("[not enabled]");
  2154. goto end;
  2155. }
  2156. dp_display_state_add(DP_STATE_HDCP_ABORTED);
  2157. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  2158. if (dp_display_is_hdcp_enabled(dp) &&
  2159. status->hdcp_state != HDCP_STATE_INACTIVE) {
  2160. bool off = true;
  2161. if (dp_display_state_is(DP_STATE_SUSPENDED)) {
  2162. DP_DEBUG("Can't perform HDCP cleanup while suspended. Defer\n");
  2163. dp->hdcp_delayed_off = true;
  2164. goto clean;
  2165. }
  2166. flush_delayed_work(&dp->hdcp_cb_work);
  2167. if (dp->mst.mst_active) {
  2168. dp_display_hdcp_deregister_stream(dp,
  2169. dp_panel->stream_id);
  2170. for (i = DP_STREAM_0; i < DP_STREAM_MAX; i++) {
  2171. if (i != dp_panel->stream_id &&
  2172. dp->active_panels[i]) {
  2173. DP_DEBUG("Streams are still active. Skip disabling HDCP\n");
  2174. off = false;
  2175. }
  2176. }
  2177. }
  2178. if (off) {
  2179. if (dp->hdcp.ops->off)
  2180. dp->hdcp.ops->off(dp->hdcp.data);
  2181. dp_display_update_hdcp_status(dp, true);
  2182. }
  2183. }
  2184. dp_display_clear_colorspaces(dp_display);
  2185. clean:
  2186. if (dp_panel->audio_supported)
  2187. dp_panel->audio->off(dp_panel->audio, false);
  2188. rc = dp_display_stream_pre_disable(dp, dp_panel);
  2189. end:
  2190. mutex_unlock(&dp->session_lock);
  2191. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  2192. return 0;
  2193. }
  2194. static int dp_display_disable(struct dp_display *dp_display, void *panel)
  2195. {
  2196. int i;
  2197. struct dp_display_private *dp = NULL;
  2198. struct dp_panel *dp_panel = NULL;
  2199. struct dp_link_hdcp_status *status;
  2200. if (!dp_display || !panel) {
  2201. DP_ERR("invalid input\n");
  2202. return -EINVAL;
  2203. }
  2204. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2205. dp_panel = panel;
  2206. status = &dp->link->hdcp_status;
  2207. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2208. mutex_lock(&dp->session_lock);
  2209. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  2210. dp_display_state_show("[not enabled]");
  2211. goto end;
  2212. }
  2213. if (!dp_display_state_is(DP_STATE_READY)) {
  2214. dp_display_state_show("[not ready]");
  2215. goto end;
  2216. }
  2217. dp_display_stream_disable(dp, dp_panel);
  2218. dp_display_state_remove(DP_STATE_HDCP_ABORTED);
  2219. for (i = DP_STREAM_0; i < DP_STREAM_MAX; i++) {
  2220. if (dp->active_panels[i]) {
  2221. if (status->hdcp_state != HDCP_STATE_AUTHENTICATED)
  2222. queue_delayed_work(dp->wq, &dp->hdcp_cb_work,
  2223. HZ/4);
  2224. break;
  2225. }
  2226. }
  2227. end:
  2228. mutex_unlock(&dp->session_lock);
  2229. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  2230. return 0;
  2231. }
  2232. static int dp_request_irq(struct dp_display *dp_display)
  2233. {
  2234. int rc = 0;
  2235. struct dp_display_private *dp;
  2236. if (!dp_display) {
  2237. DP_ERR("invalid input\n");
  2238. return -EINVAL;
  2239. }
  2240. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2241. dp->irq = irq_of_parse_and_map(dp->pdev->dev.of_node, 0);
  2242. if (dp->irq < 0) {
  2243. rc = dp->irq;
  2244. DP_ERR("failed to get irq: %d\n", rc);
  2245. return rc;
  2246. }
  2247. rc = devm_request_irq(&dp->pdev->dev, dp->irq, dp_display_irq,
  2248. IRQF_TRIGGER_HIGH, "dp_display_isr", dp);
  2249. if (rc < 0) {
  2250. DP_ERR("failed to request IRQ%u: %d\n",
  2251. dp->irq, rc);
  2252. return rc;
  2253. }
  2254. disable_irq(dp->irq);
  2255. return 0;
  2256. }
  2257. static struct dp_debug *dp_get_debug(struct dp_display *dp_display)
  2258. {
  2259. struct dp_display_private *dp;
  2260. if (!dp_display) {
  2261. DP_ERR("invalid input\n");
  2262. return ERR_PTR(-EINVAL);
  2263. }
  2264. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2265. return dp->debug;
  2266. }
  2267. static int dp_display_unprepare(struct dp_display *dp_display, void *panel)
  2268. {
  2269. struct dp_display_private *dp;
  2270. struct dp_panel *dp_panel = panel;
  2271. u32 flags = 0;
  2272. if (!dp_display || !panel) {
  2273. DP_ERR("invalid input\n");
  2274. return -EINVAL;
  2275. }
  2276. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2277. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2278. mutex_lock(&dp->session_lock);
  2279. /*
  2280. * Check if the power off sequence was triggered
  2281. * by a source initialated action like framework
  2282. * reboot or suspend-resume but not from normal
  2283. * hot plug. If connector is in MST mode, skip
  2284. * powering down host as aux needs to be kept
  2285. * alive to handle hot-plug sideband message.
  2286. */
  2287. if (dp_display_is_ready(dp) &&
  2288. (dp_display_state_is(DP_STATE_SUSPENDED) ||
  2289. !dp->mst.mst_active))
  2290. flags |= DP_PANEL_SRC_INITIATED_POWER_DOWN;
  2291. if (dp->active_stream_cnt)
  2292. goto end;
  2293. if (flags & DP_PANEL_SRC_INITIATED_POWER_DOWN) {
  2294. dp->link->psm_config(dp->link, &dp->panel->link_info, true);
  2295. dp->debug->psm_enabled = true;
  2296. dp->ctrl->off(dp->ctrl);
  2297. dp_display_host_unready(dp);
  2298. dp_display_host_deinit(dp);
  2299. dp_display_state_add(DP_STATE_SRC_PWRDN);
  2300. }
  2301. dp_display_state_remove(DP_STATE_ENABLED);
  2302. dp->aux->state &= ~DP_STATE_CTRL_POWERED_ON;
  2303. dp->aux->state |= DP_STATE_CTRL_POWERED_OFF;
  2304. complete_all(&dp->notification_comp);
  2305. /* log this as it results from user action of cable dis-connection */
  2306. DP_INFO("[OK]\n");
  2307. end:
  2308. dp->tot_lm_blks_in_use -= dp_panel->max_lm;
  2309. dp_panel->max_lm = 0;
  2310. dp_panel->deinit(dp_panel, flags);
  2311. mutex_unlock(&dp->session_lock);
  2312. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  2313. return 0;
  2314. }
  2315. static int dp_display_validate_link_clock(struct dp_display_private *dp,
  2316. struct drm_display_mode *mode, struct dp_display_mode dp_mode)
  2317. {
  2318. u32 mode_rate_khz = 0, supported_rate_khz = 0, mode_bpp = 0;
  2319. bool dsc_en;
  2320. int rate;
  2321. dsc_en = dp_mode.timing.comp_info.enabled;
  2322. mode_bpp = dsc_en ?
  2323. DSC_BPP(dp_mode.timing.comp_info.dsc_info.config)
  2324. : dp_mode.timing.bpp;
  2325. mode_rate_khz = mode->clock * mode_bpp;
  2326. rate = drm_dp_bw_code_to_link_rate(dp->link->link_params.bw_code);
  2327. supported_rate_khz = dp->link->link_params.lane_count * rate * 8;
  2328. if (mode_rate_khz > supported_rate_khz) {
  2329. DP_DEBUG("mode_rate: %d kHz, supported_rate: %d kHz\n",
  2330. mode_rate_khz, supported_rate_khz);
  2331. return -EPERM;
  2332. }
  2333. return 0;
  2334. }
  2335. static int dp_display_validate_pixel_clock(struct dp_display_mode dp_mode,
  2336. u32 max_pclk_khz)
  2337. {
  2338. u32 pclk_khz = dp_mode.timing.widebus_en ?
  2339. (dp_mode.timing.pixel_clk_khz >> 1) :
  2340. dp_mode.timing.pixel_clk_khz;
  2341. if (pclk_khz > max_pclk_khz) {
  2342. DP_DEBUG("clk: %d kHz, max: %d kHz\n", pclk_khz, max_pclk_khz);
  2343. return -EPERM;
  2344. }
  2345. return 0;
  2346. }
  2347. static int dp_display_validate_topology(struct dp_display_private *dp,
  2348. struct dp_panel *dp_panel, struct drm_display_mode *mode,
  2349. struct dp_display_mode *dp_mode,
  2350. const struct msm_resource_caps_info *avail_res)
  2351. {
  2352. int rc;
  2353. struct msm_drm_private *priv = dp->priv;
  2354. const u32 dual = 2, quad = 4;
  2355. u32 num_lm = 0, num_dsc = 0, num_3dmux = 0;
  2356. bool dsc_capable = dp_mode->capabilities & DP_PANEL_CAPS_DSC;
  2357. u32 fps = dp_mode->timing.refresh_rate;
  2358. int avail_lm = 0;
  2359. mutex_lock(&dp->accounting_lock);
  2360. rc = msm_get_mixer_count(priv, mode, avail_res, &num_lm);
  2361. if (rc) {
  2362. DP_ERR("error getting mixer count. rc:%d\n", rc);
  2363. goto end;
  2364. }
  2365. /* Merge using DSC, if enabled */
  2366. if (dp_panel->dsc_en && dsc_capable) {
  2367. rc = msm_get_dsc_count(priv, mode->hdisplay, &num_dsc);
  2368. if (rc) {
  2369. DP_ERR("error getting dsc count. rc:%d\n", rc);
  2370. goto end;
  2371. }
  2372. num_dsc = max(num_lm, num_dsc);
  2373. if ((num_dsc > avail_res->num_lm) || (num_dsc > avail_res->num_dsc)) {
  2374. DP_DEBUG("mode %sx%d: not enough resources for dsc %d dsc_a:%d lm_a:%d\n",
  2375. mode->name, fps, num_dsc, avail_res->num_dsc,
  2376. avail_res->num_lm);
  2377. /* Clear DSC caps and retry */
  2378. dp_mode->capabilities &= ~DP_PANEL_CAPS_DSC;
  2379. rc = -EAGAIN;
  2380. goto end;
  2381. } else {
  2382. /* Only DSCMERGE is supported on DP */
  2383. num_lm = num_dsc;
  2384. }
  2385. }
  2386. if (!num_dsc && (num_lm == 2) && avail_res->num_3dmux) {
  2387. num_3dmux = 1;
  2388. }
  2389. avail_lm = avail_res->num_lm + avail_res->num_lm_in_use - dp->tot_lm_blks_in_use;
  2390. if ((num_lm > dp_panel->max_lm) && (num_lm > avail_lm)) {
  2391. DP_DEBUG("mode %sx%d is invalid, not enough lm %d %d\n",
  2392. mode->name, fps, num_lm, avail_res->num_lm);
  2393. rc = -EPERM;
  2394. goto end;
  2395. } else if (!num_dsc && (num_lm == dual && !num_3dmux)) {
  2396. DP_DEBUG("mode %sx%d is invalid, not enough 3dmux %d %d\n",
  2397. mode->name, fps, num_3dmux, avail_res->num_3dmux);
  2398. rc = -EPERM;
  2399. goto end;
  2400. } else if (num_lm == quad && num_dsc != quad) {
  2401. DP_DEBUG("mode %sx%d is invalid, unsupported DP topology lm:%d dsc:%d\n",
  2402. mode->name, fps, num_lm, num_dsc);
  2403. rc = -EPERM;
  2404. goto end;
  2405. }
  2406. DP_DEBUG_V("mode %sx%d is valid, supported DP topology lm:%d dsc:%d 3dmux:%d\n",
  2407. mode->name, fps, num_lm, num_dsc, num_3dmux);
  2408. dp->tot_lm_blks_in_use -= dp_panel->max_lm;
  2409. dp_panel->max_lm = num_lm > avail_res->num_lm_in_use ? max(dp_panel->max_lm, num_lm) : 0;
  2410. dp->tot_lm_blks_in_use += dp_panel->max_lm;
  2411. rc = 0;
  2412. end:
  2413. mutex_unlock(&dp->accounting_lock);
  2414. return rc;
  2415. }
  2416. static enum drm_mode_status dp_display_validate_mode(
  2417. struct dp_display *dp_display,
  2418. void *panel, struct drm_display_mode *mode,
  2419. const struct msm_resource_caps_info *avail_res)
  2420. {
  2421. struct dp_display_private *dp;
  2422. struct dp_panel *dp_panel;
  2423. struct dp_debug *debug;
  2424. enum drm_mode_status mode_status = MODE_BAD;
  2425. struct dp_display_mode dp_mode;
  2426. int rc = 0;
  2427. if (!dp_display || !mode || !panel ||
  2428. !avail_res || !avail_res->max_mixer_width) {
  2429. DP_ERR("invalid params\n");
  2430. return mode_status;
  2431. }
  2432. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2433. mutex_lock(&dp->session_lock);
  2434. dp_panel = panel;
  2435. if (!dp_panel->connector) {
  2436. DP_ERR("invalid connector\n");
  2437. goto end;
  2438. }
  2439. debug = dp->debug;
  2440. if (!debug)
  2441. goto end;
  2442. dp_display->convert_to_dp_mode(dp_display, panel, mode, &dp_mode);
  2443. rc = dp_display_validate_topology(dp, dp_panel, mode, &dp_mode, avail_res);
  2444. if (rc == -EAGAIN) {
  2445. dp_panel->convert_to_dp_mode(dp_panel, mode, &dp_mode);
  2446. rc = dp_display_validate_topology(dp, dp_panel, mode, &dp_mode, avail_res);
  2447. }
  2448. if (rc)
  2449. goto end;
  2450. rc = dp_display_validate_link_clock(dp, mode, dp_mode);
  2451. if (rc)
  2452. goto end;
  2453. rc = dp_display_validate_pixel_clock(dp_mode, dp_display->max_pclk_khz);
  2454. if (rc)
  2455. goto end;
  2456. mode_status = MODE_OK;
  2457. end:
  2458. if (mode_status != MODE_OK)
  2459. dp_display_clear_reservation(dp_display, dp_panel);
  2460. mutex_unlock(&dp->session_lock);
  2461. DP_DEBUG_V("[%s] mode is %s\n", mode->name,
  2462. (mode_status == MODE_OK) ? "valid" : "invalid");
  2463. return mode_status;
  2464. }
  2465. static int dp_display_get_available_dp_resources(struct dp_display *dp_display,
  2466. const struct msm_resource_caps_info *avail_res,
  2467. struct msm_resource_caps_info *max_dp_avail_res)
  2468. {
  2469. if (!dp_display || !avail_res || !max_dp_avail_res) {
  2470. DP_ERR("invalid arguments\n");
  2471. return -EINVAL;
  2472. }
  2473. memcpy(max_dp_avail_res, avail_res,
  2474. sizeof(struct msm_resource_caps_info));
  2475. max_dp_avail_res->num_lm = min(avail_res->num_lm,
  2476. dp_display->max_mixer_count);
  2477. max_dp_avail_res->num_dsc = min(avail_res->num_dsc,
  2478. dp_display->max_dsc_count);
  2479. DP_DEBUG_V("max_lm:%d, avail_lm:%d, dp_avail_lm:%d\n",
  2480. dp_display->max_mixer_count, avail_res->num_lm,
  2481. max_dp_avail_res->num_lm);
  2482. DP_DEBUG_V("max_dsc:%d, avail_dsc:%d, dp_avail_dsc:%d\n",
  2483. dp_display->max_dsc_count, avail_res->num_dsc,
  2484. max_dp_avail_res->num_dsc);
  2485. return 0;
  2486. }
  2487. static int dp_display_get_modes(struct dp_display *dp, void *panel,
  2488. struct dp_display_mode *dp_mode)
  2489. {
  2490. struct dp_display_private *dp_display;
  2491. struct dp_panel *dp_panel;
  2492. int ret = 0;
  2493. if (!dp || !panel) {
  2494. DP_ERR("invalid params\n");
  2495. return 0;
  2496. }
  2497. dp_panel = panel;
  2498. if (!dp_panel->connector) {
  2499. DP_ERR("invalid connector\n");
  2500. return 0;
  2501. }
  2502. dp_display = container_of(dp, struct dp_display_private, dp_display);
  2503. ret = dp_panel->get_modes(dp_panel, dp_panel->connector, dp_mode);
  2504. if (dp_mode->timing.pixel_clk_khz)
  2505. dp->max_pclk_khz = dp_mode->timing.pixel_clk_khz;
  2506. return ret;
  2507. }
  2508. static void dp_display_convert_to_dp_mode(struct dp_display *dp_display,
  2509. void *panel,
  2510. const struct drm_display_mode *drm_mode,
  2511. struct dp_display_mode *dp_mode)
  2512. {
  2513. int rc;
  2514. struct dp_display_private *dp;
  2515. struct dp_panel *dp_panel;
  2516. u32 free_dsc_blks = 0, required_dsc_blks = 0, curr_dsc = 0, new_dsc = 0;
  2517. if (!dp_display || !drm_mode || !dp_mode || !panel) {
  2518. DP_ERR("invalid input\n");
  2519. return;
  2520. }
  2521. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2522. dp_panel = panel;
  2523. memset(dp_mode, 0, sizeof(*dp_mode));
  2524. if (dp_panel->dsc_en) {
  2525. free_dsc_blks = dp_display->max_dsc_count -
  2526. dp->tot_dsc_blks_in_use +
  2527. dp_panel->dsc_blks_in_use;
  2528. DP_DEBUG_V("Before: in_use:%d, max:%d, free:%d\n",
  2529. dp->tot_dsc_blks_in_use,
  2530. dp_display->max_dsc_count, free_dsc_blks);
  2531. rc = msm_get_dsc_count(dp->priv, drm_mode->hdisplay,
  2532. &required_dsc_blks);
  2533. if (rc) {
  2534. DP_ERR("error getting dsc count. rc:%d\n", rc);
  2535. return;
  2536. }
  2537. curr_dsc = dp_panel->dsc_blks_in_use;
  2538. dp->tot_dsc_blks_in_use -= dp_panel->dsc_blks_in_use;
  2539. dp_panel->dsc_blks_in_use = 0;
  2540. if (free_dsc_blks >= required_dsc_blks) {
  2541. dp_mode->capabilities |= DP_PANEL_CAPS_DSC;
  2542. new_dsc = max(curr_dsc, required_dsc_blks);
  2543. dp_panel->dsc_blks_in_use = new_dsc;
  2544. dp->tot_dsc_blks_in_use += new_dsc;
  2545. }
  2546. DP_DEBUG_V("After: in_use:%d, max:%d, free:%d, req:%d, caps:0x%x\n",
  2547. dp->tot_dsc_blks_in_use,
  2548. dp_display->max_dsc_count,
  2549. free_dsc_blks, required_dsc_blks,
  2550. dp_mode->capabilities);
  2551. }
  2552. dp_panel->convert_to_dp_mode(dp_panel, drm_mode, dp_mode);
  2553. }
  2554. static int dp_display_config_hdr(struct dp_display *dp_display, void *panel,
  2555. struct drm_msm_ext_hdr_metadata *hdr, bool dhdr_update)
  2556. {
  2557. struct dp_panel *dp_panel;
  2558. struct sde_connector *sde_conn;
  2559. struct dp_display_private *dp;
  2560. u64 core_clk_rate;
  2561. bool flush_hdr;
  2562. if (!dp_display || !panel) {
  2563. DP_ERR("invalid input\n");
  2564. return -EINVAL;
  2565. }
  2566. dp_panel = panel;
  2567. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2568. sde_conn = to_sde_connector(dp_panel->connector);
  2569. core_clk_rate = dp->power->clk_get_rate(dp->power, "core_clk");
  2570. if (!core_clk_rate) {
  2571. DP_ERR("invalid rate for core_clk\n");
  2572. return -EINVAL;
  2573. }
  2574. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  2575. dp_display_state_show("[not enabled]");
  2576. return 0;
  2577. }
  2578. /*
  2579. * In rare cases where HDR metadata is updated independently
  2580. * flush the HDR metadata immediately instead of relying on
  2581. * the colorspace
  2582. */
  2583. flush_hdr = !sde_conn->colorspace_updated;
  2584. if (flush_hdr)
  2585. DP_DEBUG("flushing the HDR metadata\n");
  2586. else
  2587. DP_DEBUG("piggy-backing with colorspace\n");
  2588. return dp_panel->setup_hdr(dp_panel, hdr, dhdr_update,
  2589. core_clk_rate, flush_hdr);
  2590. }
  2591. static int dp_display_setup_colospace(struct dp_display *dp_display,
  2592. void *panel,
  2593. u32 colorspace)
  2594. {
  2595. struct dp_panel *dp_panel;
  2596. struct dp_display_private *dp;
  2597. if (!dp_display || !panel) {
  2598. pr_err("invalid input\n");
  2599. return -EINVAL;
  2600. }
  2601. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2602. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  2603. dp_display_state_show("[not enabled]");
  2604. return 0;
  2605. }
  2606. dp_panel = panel;
  2607. return dp_panel->set_colorspace(dp_panel, colorspace);
  2608. }
  2609. static int dp_display_create_workqueue(struct dp_display_private *dp)
  2610. {
  2611. dp->wq = create_singlethread_workqueue("drm_dp");
  2612. if (IS_ERR_OR_NULL(dp->wq)) {
  2613. DP_ERR("Error creating wq\n");
  2614. return -EPERM;
  2615. }
  2616. INIT_DELAYED_WORK(&dp->hdcp_cb_work, dp_display_hdcp_cb_work);
  2617. INIT_WORK(&dp->connect_work, dp_display_connect_work);
  2618. INIT_WORK(&dp->attention_work, dp_display_attention_work);
  2619. return 0;
  2620. }
  2621. static int dp_display_bridge_internal_hpd(void *dev, bool hpd, bool hpd_irq)
  2622. {
  2623. struct dp_display_private *dp = dev;
  2624. struct drm_device *drm_dev = dp->dp_display.drm_dev;
  2625. if (!drm_dev || !drm_dev->mode_config.poll_enabled)
  2626. return -EBUSY;
  2627. if (hpd_irq)
  2628. dp_display_mst_attention(dp);
  2629. else
  2630. dp->hpd->simulate_connect(dp->hpd, hpd);
  2631. return 0;
  2632. }
  2633. static int dp_display_init_aux_bridge(struct dp_display_private *dp)
  2634. {
  2635. int rc = 0;
  2636. const char *phandle = "qcom,dp-aux-bridge";
  2637. struct device_node *bridge_node;
  2638. if (!dp->pdev->dev.of_node) {
  2639. pr_err("cannot find dev.of_node\n");
  2640. rc = -ENODEV;
  2641. goto end;
  2642. }
  2643. bridge_node = of_parse_phandle(dp->pdev->dev.of_node,
  2644. phandle, 0);
  2645. if (!bridge_node)
  2646. goto end;
  2647. dp->aux_bridge = of_dp_aux_find_bridge(bridge_node);
  2648. if (!dp->aux_bridge) {
  2649. pr_err("failed to find dp aux bridge\n");
  2650. rc = -EPROBE_DEFER;
  2651. goto end;
  2652. }
  2653. if (dp->aux_bridge->register_hpd &&
  2654. !(dp->aux_bridge->flag & DP_AUX_BRIDGE_HPD))
  2655. dp->aux_bridge->register_hpd(dp->aux_bridge,
  2656. dp_display_bridge_internal_hpd, dp);
  2657. end:
  2658. return rc;
  2659. }
  2660. static int dp_display_mst_install(struct dp_display *dp_display,
  2661. struct dp_mst_drm_install_info *mst_install_info)
  2662. {
  2663. struct dp_display_private *dp;
  2664. if (!dp_display || !mst_install_info) {
  2665. DP_ERR("invalid input\n");
  2666. return -EINVAL;
  2667. }
  2668. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2669. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2670. if (!mst_install_info->cbs->hpd || !mst_install_info->cbs->hpd_irq) {
  2671. DP_ERR("invalid mst cbs\n");
  2672. return -EINVAL;
  2673. }
  2674. dp_display->dp_mst_prv_info = mst_install_info->dp_mst_prv_info;
  2675. if (!dp->parser->has_mst) {
  2676. DP_DEBUG("mst not enabled\n");
  2677. return -EPERM;
  2678. }
  2679. memcpy(&dp->mst.cbs, mst_install_info->cbs, sizeof(dp->mst.cbs));
  2680. dp->mst.drm_registered = true;
  2681. DP_MST_DEBUG("dp mst drm installed\n");
  2682. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  2683. return 0;
  2684. }
  2685. static int dp_display_mst_uninstall(struct dp_display *dp_display)
  2686. {
  2687. struct dp_display_private *dp;
  2688. if (!dp_display) {
  2689. DP_ERR("invalid input\n");
  2690. return -EINVAL;
  2691. }
  2692. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2693. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2694. if (!dp->mst.drm_registered) {
  2695. DP_DEBUG("drm mst not registered\n");
  2696. return -EPERM;
  2697. }
  2698. dp = container_of(dp_display, struct dp_display_private,
  2699. dp_display);
  2700. memset(&dp->mst.cbs, 0, sizeof(dp->mst.cbs));
  2701. dp->mst.drm_registered = false;
  2702. DP_MST_DEBUG("dp mst drm uninstalled\n");
  2703. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  2704. return 0;
  2705. }
  2706. static int dp_display_mst_connector_install(struct dp_display *dp_display,
  2707. struct drm_connector *connector)
  2708. {
  2709. int rc = 0;
  2710. struct dp_panel_in panel_in;
  2711. struct dp_panel *dp_panel;
  2712. struct dp_display_private *dp;
  2713. if (!dp_display || !connector) {
  2714. DP_ERR("invalid input\n");
  2715. return -EINVAL;
  2716. }
  2717. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2718. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2719. mutex_lock(&dp->session_lock);
  2720. if (!dp->mst.drm_registered) {
  2721. DP_DEBUG("drm mst not registered\n");
  2722. rc = -EPERM;
  2723. goto end;
  2724. }
  2725. panel_in.dev = &dp->pdev->dev;
  2726. panel_in.aux = dp->aux;
  2727. panel_in.catalog = &dp->catalog->panel;
  2728. panel_in.link = dp->link;
  2729. panel_in.connector = connector;
  2730. panel_in.base_panel = dp->panel;
  2731. panel_in.parser = dp->parser;
  2732. dp_panel = dp_panel_get(&panel_in);
  2733. if (IS_ERR(dp_panel)) {
  2734. rc = PTR_ERR(dp_panel);
  2735. DP_ERR("failed to initialize panel, rc = %d\n", rc);
  2736. goto end;
  2737. }
  2738. dp_panel->audio = dp_audio_get(dp->pdev, dp_panel, &dp->catalog->audio);
  2739. if (IS_ERR(dp_panel->audio)) {
  2740. rc = PTR_ERR(dp_panel->audio);
  2741. DP_ERR("[mst] failed to initialize audio, rc = %d\n", rc);
  2742. dp_panel->audio = NULL;
  2743. goto end;
  2744. }
  2745. DP_MST_DEBUG("dp mst connector installed. conn:%d\n",
  2746. connector->base.id);
  2747. end:
  2748. mutex_unlock(&dp->session_lock);
  2749. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state, rc);
  2750. return rc;
  2751. }
  2752. static int dp_display_mst_connector_uninstall(struct dp_display *dp_display,
  2753. struct drm_connector *connector)
  2754. {
  2755. int rc = 0;
  2756. struct sde_connector *sde_conn;
  2757. struct dp_panel *dp_panel;
  2758. struct dp_display_private *dp;
  2759. struct dp_audio *audio = NULL;
  2760. if (!dp_display || !connector) {
  2761. DP_ERR("invalid input\n");
  2762. return -EINVAL;
  2763. }
  2764. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2765. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY, dp->state);
  2766. mutex_lock(&dp->session_lock);
  2767. if (!dp->mst.drm_registered) {
  2768. DP_DEBUG("drm mst not registered\n");
  2769. mutex_unlock(&dp->session_lock);
  2770. return -EPERM;
  2771. }
  2772. sde_conn = to_sde_connector(connector);
  2773. if (!sde_conn->drv_panel) {
  2774. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2775. mutex_unlock(&dp->session_lock);
  2776. return -EINVAL;
  2777. }
  2778. dp_panel = sde_conn->drv_panel;
  2779. /* Make a copy of audio structure to call into dp_audio_put later */
  2780. audio = dp_panel->audio;
  2781. dp_panel_put(dp_panel);
  2782. DP_MST_DEBUG("dp mst connector uninstalled. conn:%d\n",
  2783. connector->base.id);
  2784. mutex_unlock(&dp->session_lock);
  2785. dp_audio_put(audio);
  2786. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  2787. return rc;
  2788. }
  2789. static int dp_display_mst_connector_update_edid(struct dp_display *dp_display,
  2790. struct drm_connector *connector,
  2791. struct edid *edid)
  2792. {
  2793. int rc = 0;
  2794. struct sde_connector *sde_conn;
  2795. struct dp_panel *dp_panel;
  2796. struct dp_display_private *dp;
  2797. if (!dp_display || !connector || !edid) {
  2798. DP_ERR("invalid input\n");
  2799. return -EINVAL;
  2800. }
  2801. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2802. if (!dp->mst.drm_registered) {
  2803. DP_DEBUG("drm mst not registered\n");
  2804. return -EPERM;
  2805. }
  2806. sde_conn = to_sde_connector(connector);
  2807. if (!sde_conn->drv_panel) {
  2808. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2809. return -EINVAL;
  2810. }
  2811. dp_panel = sde_conn->drv_panel;
  2812. rc = dp_panel->update_edid(dp_panel, edid);
  2813. DP_MST_DEBUG("dp mst connector:%d edid updated. mode_cnt:%d\n",
  2814. connector->base.id, rc);
  2815. return rc;
  2816. }
  2817. static int dp_display_update_pps(struct dp_display *dp_display,
  2818. struct drm_connector *connector, char *pps_cmd)
  2819. {
  2820. struct sde_connector *sde_conn;
  2821. struct dp_panel *dp_panel;
  2822. struct dp_display_private *dp;
  2823. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2824. sde_conn = to_sde_connector(connector);
  2825. if (!sde_conn->drv_panel) {
  2826. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2827. return -EINVAL;
  2828. }
  2829. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  2830. dp_display_state_show("[not enabled]");
  2831. return 0;
  2832. }
  2833. dp_panel = sde_conn->drv_panel;
  2834. dp_panel->update_pps(dp_panel, pps_cmd);
  2835. return 0;
  2836. }
  2837. static int dp_display_mst_connector_update_link_info(
  2838. struct dp_display *dp_display,
  2839. struct drm_connector *connector)
  2840. {
  2841. int rc = 0;
  2842. struct sde_connector *sde_conn;
  2843. struct dp_panel *dp_panel;
  2844. struct dp_display_private *dp;
  2845. if (!dp_display || !connector) {
  2846. DP_ERR("invalid input\n");
  2847. return -EINVAL;
  2848. }
  2849. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2850. if (!dp->mst.drm_registered) {
  2851. DP_DEBUG("drm mst not registered\n");
  2852. return -EPERM;
  2853. }
  2854. sde_conn = to_sde_connector(connector);
  2855. if (!sde_conn->drv_panel) {
  2856. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2857. return -EINVAL;
  2858. }
  2859. dp_panel = sde_conn->drv_panel;
  2860. memcpy(dp_panel->dpcd, dp->panel->dpcd,
  2861. DP_RECEIVER_CAP_SIZE + 1);
  2862. memcpy(dp_panel->dsc_dpcd, dp->panel->dsc_dpcd,
  2863. DP_RECEIVER_DSC_CAP_SIZE + 1);
  2864. memcpy(&dp_panel->link_info, &dp->panel->link_info,
  2865. sizeof(dp_panel->link_info));
  2866. DP_MST_DEBUG("dp mst connector:%d link info updated\n",
  2867. connector->base.id);
  2868. return rc;
  2869. }
  2870. static int dp_display_mst_get_fixed_topology_port(
  2871. struct dp_display *dp_display,
  2872. u32 strm_id, u32 *port_num)
  2873. {
  2874. struct dp_display_private *dp;
  2875. u32 port;
  2876. if (!dp_display) {
  2877. DP_ERR("invalid input\n");
  2878. return -EINVAL;
  2879. }
  2880. if (strm_id >= DP_STREAM_MAX) {
  2881. DP_ERR("invalid stream id:%d\n", strm_id);
  2882. return -EINVAL;
  2883. }
  2884. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2885. port = dp->parser->mst_fixed_port[strm_id];
  2886. if (!port || port > 255)
  2887. return -ENOENT;
  2888. if (port_num)
  2889. *port_num = port;
  2890. return 0;
  2891. }
  2892. static int dp_display_get_mst_caps(struct dp_display *dp_display,
  2893. struct dp_mst_caps *mst_caps)
  2894. {
  2895. int rc = 0;
  2896. struct dp_display_private *dp;
  2897. if (!dp_display || !mst_caps) {
  2898. DP_ERR("invalid input\n");
  2899. return -EINVAL;
  2900. }
  2901. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2902. mst_caps->has_mst = dp->parser->has_mst;
  2903. mst_caps->max_streams_supported = (mst_caps->has_mst) ? 2 : 0;
  2904. mst_caps->max_dpcd_transaction_bytes = (mst_caps->has_mst) ? 16 : 0;
  2905. mst_caps->drm_aux = dp->aux->drm_aux;
  2906. return rc;
  2907. }
  2908. static void dp_display_wakeup_phy_layer(struct dp_display *dp_display,
  2909. bool wakeup)
  2910. {
  2911. struct dp_display_private *dp;
  2912. struct dp_hpd *hpd;
  2913. if (!dp_display) {
  2914. DP_ERR("invalid input\n");
  2915. return;
  2916. }
  2917. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2918. if (!dp->mst.drm_registered) {
  2919. DP_DEBUG("drm mst not registered\n");
  2920. return;
  2921. }
  2922. hpd = dp->hpd;
  2923. if (hpd && hpd->wakeup_phy)
  2924. hpd->wakeup_phy(hpd, wakeup);
  2925. }
  2926. static int dp_display_probe(struct platform_device *pdev)
  2927. {
  2928. int rc = 0;
  2929. struct dp_display_private *dp;
  2930. if (!pdev || !pdev->dev.of_node) {
  2931. DP_ERR("pdev not found\n");
  2932. rc = -ENODEV;
  2933. goto bail;
  2934. }
  2935. dp = devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL);
  2936. if (!dp) {
  2937. rc = -ENOMEM;
  2938. goto bail;
  2939. }
  2940. init_completion(&dp->notification_comp);
  2941. init_completion(&dp->attention_comp);
  2942. dp->pdev = pdev;
  2943. dp->name = "drm_dp";
  2944. memset(&dp->mst, 0, sizeof(dp->mst));
  2945. rc = dp_display_init_aux_bridge(dp);
  2946. if (rc)
  2947. goto error;
  2948. rc = dp_display_create_workqueue(dp);
  2949. if (rc) {
  2950. DP_ERR("Failed to create workqueue\n");
  2951. goto error;
  2952. }
  2953. platform_set_drvdata(pdev, dp);
  2954. g_dp_display = &dp->dp_display;
  2955. g_dp_display->dp_ipc_log = ipc_log_context_create(DRM_DP_IPC_NUM_PAGES, "drm_dp", 0);
  2956. if (!g_dp_display->dp_ipc_log)
  2957. DP_WARN("Error in creating ipc_log_context\n");
  2958. g_dp_display->enable = dp_display_enable;
  2959. g_dp_display->post_enable = dp_display_post_enable;
  2960. g_dp_display->pre_disable = dp_display_pre_disable;
  2961. g_dp_display->disable = dp_display_disable;
  2962. g_dp_display->set_mode = dp_display_set_mode;
  2963. g_dp_display->validate_mode = dp_display_validate_mode;
  2964. g_dp_display->get_modes = dp_display_get_modes;
  2965. g_dp_display->prepare = dp_display_prepare;
  2966. g_dp_display->unprepare = dp_display_unprepare;
  2967. g_dp_display->request_irq = dp_request_irq;
  2968. g_dp_display->get_debug = dp_get_debug;
  2969. g_dp_display->post_open = NULL;
  2970. g_dp_display->post_init = dp_display_post_init;
  2971. g_dp_display->config_hdr = dp_display_config_hdr;
  2972. g_dp_display->mst_install = dp_display_mst_install;
  2973. g_dp_display->mst_uninstall = dp_display_mst_uninstall;
  2974. g_dp_display->mst_connector_install = dp_display_mst_connector_install;
  2975. g_dp_display->mst_connector_uninstall =
  2976. dp_display_mst_connector_uninstall;
  2977. g_dp_display->mst_connector_update_edid =
  2978. dp_display_mst_connector_update_edid;
  2979. g_dp_display->mst_connector_update_link_info =
  2980. dp_display_mst_connector_update_link_info;
  2981. g_dp_display->get_mst_caps = dp_display_get_mst_caps;
  2982. g_dp_display->set_stream_info = dp_display_set_stream_info;
  2983. g_dp_display->update_pps = dp_display_update_pps;
  2984. g_dp_display->convert_to_dp_mode = dp_display_convert_to_dp_mode;
  2985. g_dp_display->mst_get_fixed_topology_port =
  2986. dp_display_mst_get_fixed_topology_port;
  2987. g_dp_display->wakeup_phy_layer =
  2988. dp_display_wakeup_phy_layer;
  2989. g_dp_display->set_colorspace = dp_display_setup_colospace;
  2990. g_dp_display->get_available_dp_resources =
  2991. dp_display_get_available_dp_resources;
  2992. g_dp_display->clear_reservation = dp_display_clear_reservation;
  2993. rc = component_add(&pdev->dev, &dp_display_comp_ops);
  2994. if (rc) {
  2995. DP_ERR("component add failed, rc=%d\n", rc);
  2996. goto error;
  2997. }
  2998. return 0;
  2999. error:
  3000. devm_kfree(&pdev->dev, dp);
  3001. bail:
  3002. return rc;
  3003. }
  3004. int dp_display_get_displays(void **displays, int count)
  3005. {
  3006. if (!displays) {
  3007. DP_ERR("invalid data\n");
  3008. return -EINVAL;
  3009. }
  3010. if (count != 1) {
  3011. DP_ERR("invalid number of displays\n");
  3012. return -EINVAL;
  3013. }
  3014. displays[0] = g_dp_display;
  3015. return count;
  3016. }
  3017. int dp_display_get_num_of_displays(void)
  3018. {
  3019. if (!g_dp_display)
  3020. return 0;
  3021. return 1;
  3022. }
  3023. int dp_display_get_num_of_streams(void)
  3024. {
  3025. return DP_STREAM_MAX;
  3026. }
  3027. static void dp_display_set_mst_state(void *dp_display,
  3028. enum dp_drv_state mst_state)
  3029. {
  3030. struct dp_display_private *dp;
  3031. if (!g_dp_display) {
  3032. DP_DEBUG("dp display not initialized\n");
  3033. return;
  3034. }
  3035. dp = container_of(g_dp_display, struct dp_display_private, dp_display);
  3036. SDE_EVT32_EXTERNAL(mst_state, dp->mst.mst_active);
  3037. if (dp->mst.mst_active && dp->mst.cbs.set_drv_state)
  3038. dp->mst.cbs.set_drv_state(g_dp_display, mst_state);
  3039. }
  3040. static int dp_display_remove(struct platform_device *pdev)
  3041. {
  3042. struct dp_display_private *dp;
  3043. if (!pdev)
  3044. return -EINVAL;
  3045. dp = platform_get_drvdata(pdev);
  3046. dp_display_deinit_sub_modules(dp);
  3047. if (dp->wq)
  3048. destroy_workqueue(dp->wq);
  3049. platform_set_drvdata(pdev, NULL);
  3050. devm_kfree(&pdev->dev, dp);
  3051. if (g_dp_display->dp_ipc_log) {
  3052. ipc_log_context_destroy(g_dp_display->dp_ipc_log);
  3053. g_dp_display->dp_ipc_log = NULL;
  3054. }
  3055. return 0;
  3056. }
  3057. static int dp_pm_prepare(struct device *dev)
  3058. {
  3059. struct dp_display_private *dp = container_of(g_dp_display,
  3060. struct dp_display_private, dp_display);
  3061. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY);
  3062. mutex_lock(&dp->session_lock);
  3063. dp_display_set_mst_state(g_dp_display, PM_SUSPEND);
  3064. /*
  3065. * There are a few instances where the DP is hotplugged when the device
  3066. * is in PM suspend state. After hotplug, it is observed the device
  3067. * enters and exits the PM suspend multiple times while aux transactions
  3068. * are taking place. This may sometimes cause an unclocked register
  3069. * access error. So, abort aux transactions when such a situation
  3070. * arises i.e. when DP is connected but display not enabled yet.
  3071. */
  3072. if (dp_display_state_is(DP_STATE_CONNECTED) &&
  3073. !dp_display_state_is(DP_STATE_ENABLED)) {
  3074. dp->aux->abort(dp->aux, true);
  3075. dp->ctrl->abort(dp->ctrl, true);
  3076. }
  3077. dp_display_state_add(DP_STATE_SUSPENDED);
  3078. mutex_unlock(&dp->session_lock);
  3079. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  3080. return 0;
  3081. }
  3082. static void dp_pm_complete(struct device *dev)
  3083. {
  3084. struct dp_display_private *dp = container_of(g_dp_display,
  3085. struct dp_display_private, dp_display);
  3086. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_ENTRY);
  3087. mutex_lock(&dp->session_lock);
  3088. dp_display_set_mst_state(g_dp_display, PM_DEFAULT);
  3089. /*
  3090. * There are multiple PM suspend entry and exits observed before
  3091. * the connect uevent is issued to userspace. The aux transactions are
  3092. * aborted during PM suspend entry in dp_pm_prepare to prevent unclocked
  3093. * register access. On PM suspend exit, there will be no host_init call
  3094. * to reset the abort flags for ctrl and aux incase DP is connected
  3095. * but display not enabled. So, resetting abort flags for aux and ctrl.
  3096. */
  3097. if (dp_display_state_is(DP_STATE_CONNECTED) &&
  3098. !dp_display_state_is(DP_STATE_ENABLED)) {
  3099. dp->aux->abort(dp->aux, false);
  3100. dp->ctrl->abort(dp->ctrl, false);
  3101. }
  3102. dp_display_state_remove(DP_STATE_SUSPENDED);
  3103. mutex_unlock(&dp->session_lock);
  3104. SDE_EVT32_EXTERNAL(SDE_EVTLOG_FUNC_EXIT, dp->state);
  3105. }
  3106. void *get_ipc_log_context(void)
  3107. {
  3108. if (g_dp_display && g_dp_display->dp_ipc_log)
  3109. return g_dp_display->dp_ipc_log;
  3110. return NULL;
  3111. }
  3112. static const struct dev_pm_ops dp_pm_ops = {
  3113. .prepare = dp_pm_prepare,
  3114. .complete = dp_pm_complete,
  3115. };
  3116. static struct platform_driver dp_display_driver = {
  3117. .probe = dp_display_probe,
  3118. .remove = dp_display_remove,
  3119. .driver = {
  3120. .name = "msm-dp-display",
  3121. .of_match_table = dp_dt_match,
  3122. .suppress_bind_attrs = true,
  3123. .pm = &dp_pm_ops,
  3124. },
  3125. };
  3126. void __init dp_display_register(void)
  3127. {
  3128. platform_driver_register(&dp_display_driver);
  3129. }
  3130. void __exit dp_display_unregister(void)
  3131. {
  3132. platform_driver_unregister(&dp_display_driver);
  3133. }