dp_display.c 101 KB

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