dp_display.c 88 KB

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