dp_display.c 97 KB

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