dp_display.c 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2019, 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/extcon.h>
  12. #include <linux/soc/qcom/fsa4480-i2c.h>
  13. #include <linux/usb/usbpd.h>
  14. #include "sde_connector.h"
  15. #include "msm_drv.h"
  16. #include "dp_hpd.h"
  17. #include "dp_parser.h"
  18. #include "dp_power.h"
  19. #include "dp_catalog.h"
  20. #include "dp_aux.h"
  21. #include "dp_link.h"
  22. #include "dp_panel.h"
  23. #include "dp_ctrl.h"
  24. #include "dp_audio.h"
  25. #include "dp_display.h"
  26. #include "sde_hdcp.h"
  27. #include "dp_debug.h"
  28. #define DP_MST_DEBUG(fmt, ...) DP_DEBUG(fmt, ##__VA_ARGS__)
  29. #define dp_display_state_show(x) { \
  30. DP_ERR("%s: state (0x%x): %s\n", x, dp->state, \
  31. dp_display_state_name(dp->state)); }
  32. #define dp_display_state_is(x) (dp->state & (x))
  33. #define dp_display_state_add(x) (dp->state |= (x))
  34. #define dp_display_state_remove(x) (dp->state &= ~(x))
  35. enum dp_display_states {
  36. DP_STATE_DISCONNECTED = 0,
  37. DP_STATE_CONFIGURED = BIT(0),
  38. DP_STATE_INITIALIZED = BIT(1),
  39. DP_STATE_READY = BIT(2),
  40. DP_STATE_CONNECTED = BIT(3),
  41. DP_STATE_CONNECT_NOTIFIED = BIT(4),
  42. DP_STATE_DISCONNECT_NOTIFIED = BIT(5),
  43. DP_STATE_ENABLED = BIT(6),
  44. DP_STATE_SUSPENDED = BIT(7),
  45. DP_STATE_ABORTED = BIT(8),
  46. DP_STATE_HDCP_ABORTED = BIT(9),
  47. };
  48. static char *dp_display_state_name(enum dp_display_states state)
  49. {
  50. static char buf[SZ_1K];
  51. u32 len = 0;
  52. memset(buf, 0, SZ_1K);
  53. if (state & DP_STATE_CONFIGURED)
  54. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  55. "CONFIGURED");
  56. if (state & DP_STATE_INITIALIZED)
  57. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  58. "INITIALIZED");
  59. if (state & DP_STATE_READY)
  60. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  61. "READY");
  62. if (state & DP_STATE_CONNECTED)
  63. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  64. "CONNECTED");
  65. if (state & DP_STATE_CONNECT_NOTIFIED)
  66. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  67. "CONNECT_NOTIFIED");
  68. if (state & DP_STATE_DISCONNECT_NOTIFIED)
  69. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  70. "DISCONNECT_NOTIFIED");
  71. if (state & DP_STATE_ENABLED)
  72. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  73. "ENABLED");
  74. if (state & DP_STATE_SUSPENDED)
  75. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  76. "SUSPENDED");
  77. if (state & DP_STATE_ABORTED)
  78. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  79. "ABORTED");
  80. if (state & DP_STATE_HDCP_ABORTED)
  81. len += scnprintf(buf + len, sizeof(buf) - len, "|%s|",
  82. "HDCP_ABORTED");
  83. if (!strlen(buf))
  84. return "DISCONNECTED";
  85. return buf;
  86. }
  87. static struct dp_display *g_dp_display;
  88. #define HPD_STRING_SIZE 30
  89. struct dp_hdcp_dev {
  90. void *fd;
  91. struct sde_hdcp_ops *ops;
  92. enum sde_hdcp_version ver;
  93. };
  94. struct dp_hdcp {
  95. void *data;
  96. struct sde_hdcp_ops *ops;
  97. u32 source_cap;
  98. struct dp_hdcp_dev dev[HDCP_VERSION_MAX];
  99. };
  100. struct dp_mst {
  101. bool mst_active;
  102. bool drm_registered;
  103. struct dp_mst_drm_cbs cbs;
  104. };
  105. struct dp_display_private {
  106. char *name;
  107. int irq;
  108. enum drm_connector_status cached_connector_status;
  109. enum dp_display_states state;
  110. struct platform_device *pdev;
  111. struct device_node *aux_switch_node;
  112. struct dentry *root;
  113. struct completion notification_comp;
  114. struct dp_hpd *hpd;
  115. struct dp_parser *parser;
  116. struct dp_power *power;
  117. struct dp_catalog *catalog;
  118. struct dp_aux *aux;
  119. struct dp_link *link;
  120. struct dp_panel *panel;
  121. struct dp_ctrl *ctrl;
  122. struct dp_debug *debug;
  123. struct dp_panel *active_panels[DP_STREAM_MAX];
  124. struct dp_hdcp hdcp;
  125. struct dp_hpd_cb hpd_cb;
  126. struct dp_display_mode mode;
  127. struct dp_display dp_display;
  128. struct msm_drm_private *priv;
  129. struct workqueue_struct *wq;
  130. struct delayed_work hdcp_cb_work;
  131. struct work_struct connect_work;
  132. struct work_struct attention_work;
  133. struct mutex session_lock;
  134. bool hdcp_delayed_off;
  135. u32 active_stream_cnt;
  136. struct dp_mst mst;
  137. u32 tot_dsc_blks_in_use;
  138. bool process_hpd_connect;
  139. struct notifier_block usb_nb;
  140. };
  141. static const struct of_device_id dp_dt_match[] = {
  142. {.compatible = "qcom,dp-display"},
  143. {}
  144. };
  145. static inline bool dp_display_is_hdcp_enabled(struct dp_display_private *dp)
  146. {
  147. return dp->link->hdcp_status.hdcp_version && dp->hdcp.ops;
  148. }
  149. static irqreturn_t dp_display_irq(int irq, void *dev_id)
  150. {
  151. struct dp_display_private *dp = dev_id;
  152. if (!dp) {
  153. DP_ERR("invalid data\n");
  154. return IRQ_NONE;
  155. }
  156. /* DP HPD isr */
  157. if (dp->hpd->type == DP_HPD_LPHW)
  158. dp->hpd->isr(dp->hpd);
  159. /* DP controller isr */
  160. dp->ctrl->isr(dp->ctrl);
  161. /* DP aux isr */
  162. dp->aux->isr(dp->aux);
  163. /* HDCP isr */
  164. if (dp_display_is_hdcp_enabled(dp) && dp->hdcp.ops->isr) {
  165. if (dp->hdcp.ops->isr(dp->hdcp.data))
  166. DP_ERR("dp_hdcp_isr failed\n");
  167. }
  168. return IRQ_HANDLED;
  169. }
  170. static bool dp_display_is_ds_bridge(struct dp_panel *panel)
  171. {
  172. return (panel->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
  173. DP_DWN_STRM_PORT_PRESENT);
  174. }
  175. static bool dp_display_is_sink_count_zero(struct dp_display_private *dp)
  176. {
  177. return dp_display_is_ds_bridge(dp->panel) &&
  178. (dp->link->sink_count.count == 0);
  179. }
  180. static bool dp_display_is_ready(struct dp_display_private *dp)
  181. {
  182. return dp->hpd->hpd_high && dp_display_state_is(DP_STATE_CONNECTED) &&
  183. !dp_display_is_sink_count_zero(dp) &&
  184. dp->hpd->alt_mode_cfg_done;
  185. }
  186. static void dp_display_update_hdcp_status(struct dp_display_private *dp,
  187. bool reset)
  188. {
  189. if (reset) {
  190. dp->link->hdcp_status.hdcp_state = HDCP_STATE_INACTIVE;
  191. dp->link->hdcp_status.hdcp_version = HDCP_VERSION_NONE;
  192. }
  193. memset(dp->debug->hdcp_status, 0, sizeof(dp->debug->hdcp_status));
  194. snprintf(dp->debug->hdcp_status, sizeof(dp->debug->hdcp_status),
  195. "%s: %s\ncaps: %d\n",
  196. sde_hdcp_version(dp->link->hdcp_status.hdcp_version),
  197. sde_hdcp_state_name(dp->link->hdcp_status.hdcp_state),
  198. dp->hdcp.source_cap);
  199. }
  200. static void dp_display_update_hdcp_info(struct dp_display_private *dp)
  201. {
  202. void *fd = NULL;
  203. struct dp_hdcp_dev *dev = NULL;
  204. struct sde_hdcp_ops *ops = NULL;
  205. int i = HDCP_VERSION_2P2;
  206. dp_display_update_hdcp_status(dp, true);
  207. dp->hdcp.data = NULL;
  208. dp->hdcp.ops = NULL;
  209. if (dp->debug->hdcp_disabled || dp->debug->sim_mode)
  210. return;
  211. while (i) {
  212. dev = &dp->hdcp.dev[i];
  213. ops = dev->ops;
  214. fd = dev->fd;
  215. i >>= 1;
  216. if (!(dp->hdcp.source_cap & dev->ver))
  217. continue;
  218. if (ops->sink_support(fd)) {
  219. dp->hdcp.data = fd;
  220. dp->hdcp.ops = ops;
  221. dp->link->hdcp_status.hdcp_version = dev->ver;
  222. break;
  223. }
  224. }
  225. DP_DEBUG("HDCP version supported: %s\n",
  226. sde_hdcp_version(dp->link->hdcp_status.hdcp_version));
  227. }
  228. static void dp_display_check_source_hdcp_caps(struct dp_display_private *dp)
  229. {
  230. int i;
  231. struct dp_hdcp_dev *hdcp_dev = dp->hdcp.dev;
  232. if (dp->debug->hdcp_disabled) {
  233. DP_DEBUG("hdcp disabled\n");
  234. return;
  235. }
  236. for (i = 0; i < HDCP_VERSION_MAX; i++) {
  237. struct dp_hdcp_dev *dev = &hdcp_dev[i];
  238. struct sde_hdcp_ops *ops = dev->ops;
  239. void *fd = dev->fd;
  240. if (!fd || !ops)
  241. continue;
  242. if (ops->set_mode && ops->set_mode(fd, dp->mst.mst_active))
  243. continue;
  244. if (!(dp->hdcp.source_cap & dev->ver) &&
  245. ops->feature_supported &&
  246. ops->feature_supported(fd))
  247. dp->hdcp.source_cap |= dev->ver;
  248. }
  249. dp_display_update_hdcp_status(dp, false);
  250. }
  251. static void dp_display_hdcp_register_streams(struct dp_display_private *dp)
  252. {
  253. int rc;
  254. size_t i;
  255. struct sde_hdcp_ops *ops = dp->hdcp.ops;
  256. void *data = dp->hdcp.data;
  257. if (dp_display_is_ready(dp) && dp->mst.mst_active && ops &&
  258. ops->register_streams){
  259. struct stream_info streams[DP_STREAM_MAX];
  260. int index = 0;
  261. DP_DEBUG("Registering all active panel streams with HDCP\n");
  262. for (i = DP_STREAM_0; i < DP_STREAM_MAX; i++) {
  263. if (!dp->active_panels[i])
  264. continue;
  265. streams[index].stream_id = i;
  266. streams[index].virtual_channel =
  267. dp->active_panels[i]->vcpi;
  268. index++;
  269. }
  270. if (index > 0) {
  271. rc = ops->register_streams(data, index, streams);
  272. if (rc)
  273. DP_ERR("failed to register streams. rc = %d\n",
  274. rc);
  275. }
  276. }
  277. }
  278. static void dp_display_hdcp_deregister_stream(struct dp_display_private *dp,
  279. enum dp_stream_id stream_id)
  280. {
  281. if (dp->hdcp.ops->deregister_streams) {
  282. struct stream_info stream = {stream_id,
  283. dp->active_panels[stream_id]->vcpi};
  284. DP_DEBUG("Deregistering stream within HDCP library\n");
  285. dp->hdcp.ops->deregister_streams(dp->hdcp.data, 1, &stream);
  286. }
  287. }
  288. static void dp_display_hdcp_cb_work(struct work_struct *work)
  289. {
  290. struct dp_display_private *dp;
  291. struct delayed_work *dw = to_delayed_work(work);
  292. struct sde_hdcp_ops *ops;
  293. struct dp_link_hdcp_status *status;
  294. void *data;
  295. int rc = 0;
  296. u32 hdcp_auth_state;
  297. u8 sink_status = 0;
  298. dp = container_of(dw, struct dp_display_private, hdcp_cb_work);
  299. if (!dp_display_state_is(DP_STATE_ENABLED | DP_STATE_CONNECTED) ||
  300. dp_display_state_is(DP_STATE_ABORTED | DP_STATE_HDCP_ABORTED))
  301. return;
  302. if (dp_display_state_is(DP_STATE_SUSPENDED)) {
  303. DP_DEBUG("System suspending. Delay HDCP operations\n");
  304. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ);
  305. return;
  306. }
  307. if (dp->hdcp_delayed_off) {
  308. if (dp->hdcp.ops && dp->hdcp.ops->off)
  309. dp->hdcp.ops->off(dp->hdcp.data);
  310. dp_display_update_hdcp_status(dp, true);
  311. dp->hdcp_delayed_off = false;
  312. }
  313. if (dp->debug->hdcp_wait_sink_sync) {
  314. drm_dp_dpcd_readb(dp->aux->drm_aux, DP_SINK_STATUS,
  315. &sink_status);
  316. sink_status &= (DP_RECEIVE_PORT_0_STATUS |
  317. DP_RECEIVE_PORT_1_STATUS);
  318. if (sink_status < 1) {
  319. DP_DEBUG("Sink not synchronized. Queuing again then exiting\n");
  320. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ);
  321. return;
  322. }
  323. }
  324. status = &dp->link->hdcp_status;
  325. if (status->hdcp_state == HDCP_STATE_INACTIVE) {
  326. dp_display_check_source_hdcp_caps(dp);
  327. dp_display_update_hdcp_info(dp);
  328. if (dp_display_is_hdcp_enabled(dp)) {
  329. if (dp->hdcp.ops && dp->hdcp.ops->on &&
  330. dp->hdcp.ops->on(dp->hdcp.data)) {
  331. dp_display_update_hdcp_status(dp, true);
  332. return;
  333. }
  334. } else {
  335. dp_display_update_hdcp_status(dp, true);
  336. return;
  337. }
  338. }
  339. rc = dp->catalog->ctrl.read_hdcp_status(&dp->catalog->ctrl);
  340. if (rc >= 0) {
  341. hdcp_auth_state = (rc >> 20) & 0x3;
  342. DP_DEBUG("hdcp auth state %d\n", hdcp_auth_state);
  343. }
  344. ops = dp->hdcp.ops;
  345. data = dp->hdcp.data;
  346. DP_DEBUG("%s: %s\n", sde_hdcp_version(status->hdcp_version),
  347. sde_hdcp_state_name(status->hdcp_state));
  348. dp_display_update_hdcp_status(dp, false);
  349. if (status->hdcp_state != HDCP_STATE_AUTHENTICATED &&
  350. dp->debug->force_encryption && ops && ops->force_encryption)
  351. ops->force_encryption(data, dp->debug->force_encryption);
  352. switch (status->hdcp_state) {
  353. case HDCP_STATE_INACTIVE:
  354. dp_display_hdcp_register_streams(dp);
  355. if (dp->hdcp.ops && dp->hdcp.ops->authenticate)
  356. rc = dp->hdcp.ops->authenticate(data);
  357. if (!rc)
  358. status->hdcp_state = HDCP_STATE_AUTHENTICATING;
  359. break;
  360. case HDCP_STATE_AUTH_FAIL:
  361. if (dp_display_is_ready(dp) &&
  362. dp_display_state_is(DP_STATE_ENABLED)) {
  363. if (ops && ops->on && ops->on(data)) {
  364. dp_display_update_hdcp_status(dp, true);
  365. return;
  366. }
  367. dp_display_hdcp_register_streams(dp);
  368. if (ops && ops->reauthenticate) {
  369. rc = ops->reauthenticate(data);
  370. if (rc)
  371. DP_ERR("failed rc=%d\n", rc);
  372. }
  373. status->hdcp_state = HDCP_STATE_AUTHENTICATING;
  374. } else {
  375. DP_DEBUG("not reauthenticating, cable disconnected\n");
  376. }
  377. break;
  378. default:
  379. dp_display_hdcp_register_streams(dp);
  380. break;
  381. }
  382. }
  383. static void dp_display_notify_hdcp_status_cb(void *ptr,
  384. enum sde_hdcp_state state)
  385. {
  386. struct dp_display_private *dp = ptr;
  387. if (!dp) {
  388. DP_ERR("invalid input\n");
  389. return;
  390. }
  391. dp->link->hdcp_status.hdcp_state = state;
  392. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ/4);
  393. }
  394. static void dp_display_deinitialize_hdcp(struct dp_display_private *dp)
  395. {
  396. if (!dp) {
  397. DP_ERR("invalid input\n");
  398. return;
  399. }
  400. sde_dp_hdcp2p2_deinit(dp->hdcp.data);
  401. }
  402. static int dp_display_initialize_hdcp(struct dp_display_private *dp)
  403. {
  404. struct sde_hdcp_init_data hdcp_init_data;
  405. struct dp_parser *parser;
  406. void *fd;
  407. int rc = 0;
  408. if (!dp) {
  409. DP_ERR("invalid input\n");
  410. return -EINVAL;
  411. }
  412. parser = dp->parser;
  413. hdcp_init_data.client_id = HDCP_CLIENT_DP;
  414. hdcp_init_data.drm_aux = dp->aux->drm_aux;
  415. hdcp_init_data.cb_data = (void *)dp;
  416. hdcp_init_data.workq = dp->wq;
  417. hdcp_init_data.sec_access = true;
  418. hdcp_init_data.notify_status = dp_display_notify_hdcp_status_cb;
  419. hdcp_init_data.dp_ahb = &parser->get_io(parser, "dp_ahb")->io;
  420. hdcp_init_data.dp_aux = &parser->get_io(parser, "dp_aux")->io;
  421. hdcp_init_data.dp_link = &parser->get_io(parser, "dp_link")->io;
  422. hdcp_init_data.dp_p0 = &parser->get_io(parser, "dp_p0")->io;
  423. hdcp_init_data.hdcp_io = &parser->get_io(parser,
  424. "hdcp_physical")->io;
  425. hdcp_init_data.revision = &dp->panel->link_info.revision;
  426. hdcp_init_data.msm_hdcp_dev = dp->parser->msm_hdcp_dev;
  427. fd = sde_hdcp_1x_init(&hdcp_init_data);
  428. if (IS_ERR_OR_NULL(fd)) {
  429. DP_ERR("Error initializing HDCP 1.x\n");
  430. rc = -EINVAL;
  431. goto error;
  432. }
  433. dp->hdcp.dev[HDCP_VERSION_1X].fd = fd;
  434. dp->hdcp.dev[HDCP_VERSION_1X].ops = sde_hdcp_1x_get(fd);
  435. dp->hdcp.dev[HDCP_VERSION_1X].ver = HDCP_VERSION_1X;
  436. DP_DEBUG("HDCP 1.3 initialized\n");
  437. fd = sde_dp_hdcp2p2_init(&hdcp_init_data);
  438. if (IS_ERR_OR_NULL(fd)) {
  439. DP_ERR("Error initializing HDCP 2.x\n");
  440. rc = -EINVAL;
  441. goto error;
  442. }
  443. dp->hdcp.dev[HDCP_VERSION_2P2].fd = fd;
  444. dp->hdcp.dev[HDCP_VERSION_2P2].ops = sde_dp_hdcp2p2_get(fd);
  445. dp->hdcp.dev[HDCP_VERSION_2P2].ver = HDCP_VERSION_2P2;
  446. DP_DEBUG("HDCP 2.2 initialized\n");
  447. return 0;
  448. error:
  449. dp_display_deinitialize_hdcp(dp);
  450. return rc;
  451. }
  452. static int dp_display_bind(struct device *dev, struct device *master,
  453. void *data)
  454. {
  455. int rc = 0;
  456. struct dp_display_private *dp;
  457. struct drm_device *drm;
  458. struct platform_device *pdev = to_platform_device(dev);
  459. if (!dev || !pdev || !master) {
  460. DP_ERR("invalid param(s), dev %pK, pdev %pK, master %pK\n",
  461. dev, pdev, master);
  462. rc = -EINVAL;
  463. goto end;
  464. }
  465. drm = dev_get_drvdata(master);
  466. dp = platform_get_drvdata(pdev);
  467. if (!drm || !dp) {
  468. DP_ERR("invalid param(s), drm %pK, dp %pK\n",
  469. drm, dp);
  470. rc = -EINVAL;
  471. goto end;
  472. }
  473. dp->dp_display.drm_dev = drm;
  474. dp->priv = drm->dev_private;
  475. end:
  476. return rc;
  477. }
  478. static void dp_display_unbind(struct device *dev, struct device *master,
  479. void *data)
  480. {
  481. struct dp_display_private *dp;
  482. struct platform_device *pdev = to_platform_device(dev);
  483. if (!dev || !pdev) {
  484. DP_ERR("invalid param(s)\n");
  485. return;
  486. }
  487. dp = platform_get_drvdata(pdev);
  488. if (!dp) {
  489. DP_ERR("Invalid params\n");
  490. return;
  491. }
  492. if (dp->power)
  493. (void)dp->power->power_client_deinit(dp->power);
  494. if (dp->aux)
  495. (void)dp->aux->drm_aux_deregister(dp->aux);
  496. dp_display_deinitialize_hdcp(dp);
  497. }
  498. static const struct component_ops dp_display_comp_ops = {
  499. .bind = dp_display_bind,
  500. .unbind = dp_display_unbind,
  501. };
  502. static void dp_display_send_hpd_event(struct dp_display_private *dp)
  503. {
  504. struct drm_device *dev = NULL;
  505. struct drm_connector *connector;
  506. char name[HPD_STRING_SIZE], status[HPD_STRING_SIZE],
  507. bpp[HPD_STRING_SIZE], pattern[HPD_STRING_SIZE];
  508. char *envp[5];
  509. if (dp->mst.mst_active) {
  510. DP_DEBUG("skip notification for mst mode\n");
  511. return;
  512. }
  513. connector = dp->dp_display.base_connector;
  514. if (!connector) {
  515. DP_ERR("connector not set\n");
  516. return;
  517. }
  518. connector->status = connector->funcs->detect(connector, false);
  519. if (dp->cached_connector_status == connector->status) {
  520. DP_DEBUG("connector status (%d) unchanged, skipping uevent\n",
  521. dp->cached_connector_status);
  522. return;
  523. }
  524. dp->cached_connector_status = connector->status;
  525. dev = connector->dev;
  526. snprintf(name, HPD_STRING_SIZE, "name=%s", connector->name);
  527. snprintf(status, HPD_STRING_SIZE, "status=%s",
  528. drm_get_connector_status_name(connector->status));
  529. snprintf(bpp, HPD_STRING_SIZE, "bpp=%d",
  530. dp_link_bit_depth_to_bpp(
  531. dp->link->test_video.test_bit_depth));
  532. snprintf(pattern, HPD_STRING_SIZE, "pattern=%d",
  533. dp->link->test_video.test_video_pattern);
  534. DP_DEBUG("[%s]:[%s] [%s] [%s]\n", name, status, bpp, pattern);
  535. envp[0] = name;
  536. envp[1] = status;
  537. envp[2] = bpp;
  538. envp[3] = pattern;
  539. envp[4] = NULL;
  540. kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
  541. envp);
  542. if (connector->status == connector_status_connected) {
  543. dp_display_state_add(DP_STATE_CONNECT_NOTIFIED);
  544. dp_display_state_remove(DP_STATE_DISCONNECT_NOTIFIED);
  545. } else {
  546. dp_display_state_add(DP_STATE_DISCONNECT_NOTIFIED);
  547. dp_display_state_remove(DP_STATE_CONNECT_NOTIFIED);
  548. }
  549. }
  550. static int dp_display_send_hpd_notification(struct dp_display_private *dp)
  551. {
  552. int ret = 0;
  553. bool hpd = !!dp_display_state_is(DP_STATE_CONNECTED);
  554. dp->aux->state |= DP_STATE_NOTIFICATION_SENT;
  555. if (!dp->mst.mst_active)
  556. dp->dp_display.is_sst_connected = hpd;
  557. else
  558. dp->dp_display.is_sst_connected = false;
  559. reinit_completion(&dp->notification_comp);
  560. dp_display_send_hpd_event(dp);
  561. if (hpd && dp->mst.mst_active)
  562. goto skip_wait;
  563. if (!dp->mst.mst_active &&
  564. (!!dp_display_state_is(DP_STATE_ENABLED) == hpd))
  565. goto skip_wait;
  566. if (!wait_for_completion_timeout(&dp->notification_comp,
  567. HZ * 5)) {
  568. DP_WARN("%s timeout\n", hpd ? "connect" : "disconnect");
  569. ret = -EINVAL;
  570. }
  571. return ret;
  572. skip_wait:
  573. return 0;
  574. }
  575. static void dp_display_update_mst_state(struct dp_display_private *dp,
  576. bool state)
  577. {
  578. dp->mst.mst_active = state;
  579. dp->panel->mst_state = state;
  580. }
  581. static void dp_display_process_mst_hpd_high(struct dp_display_private *dp,
  582. bool mst_probe)
  583. {
  584. bool is_mst_receiver;
  585. struct dp_mst_hpd_info info;
  586. const unsigned long clear_mstm_ctrl_timeout_us = 100000;
  587. u8 old_mstm_ctrl;
  588. int ret;
  589. if (!dp->parser->has_mst || !dp->mst.drm_registered) {
  590. DP_MST_DEBUG("mst not enabled. has_mst:%d, registered:%d\n",
  591. dp->parser->has_mst, dp->mst.drm_registered);
  592. return;
  593. }
  594. DP_MST_DEBUG("mst_hpd_high work. mst_probe:%d\n", mst_probe);
  595. if (!dp->mst.mst_active) {
  596. is_mst_receiver = dp->panel->read_mst_cap(dp->panel);
  597. if (!is_mst_receiver) {
  598. DP_MST_DEBUG("sink doesn't support mst\n");
  599. return;
  600. }
  601. /* clear sink mst state */
  602. drm_dp_dpcd_readb(dp->aux->drm_aux, DP_MSTM_CTRL,
  603. &old_mstm_ctrl);
  604. drm_dp_dpcd_writeb(dp->aux->drm_aux, DP_MSTM_CTRL, 0);
  605. /* add extra delay if MST state is not cleared */
  606. if (old_mstm_ctrl) {
  607. DP_MST_DEBUG("MSTM_CTRL is not cleared, wait %dus\n",
  608. clear_mstm_ctrl_timeout_us);
  609. usleep_range(clear_mstm_ctrl_timeout_us,
  610. clear_mstm_ctrl_timeout_us + 1000);
  611. }
  612. ret = drm_dp_dpcd_writeb(dp->aux->drm_aux, DP_MSTM_CTRL,
  613. DP_MST_EN | DP_UP_REQ_EN | DP_UPSTREAM_IS_SRC);
  614. if (ret < 0) {
  615. DP_ERR("sink mst enablement failed\n");
  616. return;
  617. }
  618. dp_display_update_mst_state(dp, true);
  619. } else if (dp->mst.mst_active && mst_probe) {
  620. info.mst_protocol = dp->parser->has_mst_sideband;
  621. info.mst_port_cnt = dp->debug->mst_port_cnt;
  622. info.edid = dp->debug->get_edid(dp->debug);
  623. if (dp->mst.cbs.hpd)
  624. dp->mst.cbs.hpd(&dp->dp_display, true, &info);
  625. }
  626. DP_MST_DEBUG("mst_hpd_high. mst_active:%d\n", dp->mst.mst_active);
  627. }
  628. static void dp_display_host_init(struct dp_display_private *dp)
  629. {
  630. bool flip = false;
  631. bool reset;
  632. if (dp_display_state_is(DP_STATE_INITIALIZED))
  633. return;
  634. if (dp->hpd->orientation == ORIENTATION_CC2)
  635. flip = true;
  636. reset = dp->debug->sim_mode ? false : !dp->hpd->multi_func;
  637. dp->power->init(dp->power, flip);
  638. dp->hpd->host_init(dp->hpd, &dp->catalog->hpd);
  639. dp->ctrl->init(dp->ctrl, flip, reset);
  640. enable_irq(dp->irq);
  641. dp_display_state_add(DP_STATE_INITIALIZED);
  642. /* log this as it results from user action of cable connection */
  643. DP_INFO("[OK]\n");
  644. }
  645. static void dp_display_host_ready(struct dp_display_private *dp)
  646. {
  647. if (!dp_display_state_is(DP_STATE_INITIALIZED))
  648. return;
  649. if (dp_display_state_is(DP_STATE_READY))
  650. return;
  651. dp->aux->init(dp->aux, dp->parser->aux_cfg);
  652. dp->panel->init(dp->panel);
  653. dp_display_state_add(DP_STATE_READY);
  654. }
  655. static void dp_display_host_unready(struct dp_display_private *dp)
  656. {
  657. if (!dp_display_state_is(DP_STATE_INITIALIZED))
  658. return;
  659. if (!dp_display_state_is(DP_STATE_READY))
  660. return;
  661. dp_display_state_remove(DP_STATE_READY);
  662. dp->aux->deinit(dp->aux);
  663. }
  664. static void dp_display_host_deinit(struct dp_display_private *dp)
  665. {
  666. if (dp->active_stream_cnt) {
  667. DP_DEBUG("active stream present\n");
  668. return;
  669. }
  670. if (!dp_display_state_is(DP_STATE_INITIALIZED))
  671. return;
  672. dp->ctrl->deinit(dp->ctrl);
  673. dp->hpd->host_deinit(dp->hpd, &dp->catalog->hpd);
  674. dp->power->deinit(dp->power);
  675. disable_irq(dp->irq);
  676. dp->aux->state = 0;
  677. dp_display_state_remove(DP_STATE_INITIALIZED);
  678. /* log this as it results from user action of cable dis-connection */
  679. DP_INFO("[OK]\n");
  680. }
  681. static int dp_display_process_hpd_high(struct dp_display_private *dp)
  682. {
  683. int rc = -EINVAL;
  684. mutex_lock(&dp->session_lock);
  685. if (dp_display_state_is(DP_STATE_CONNECTED)) {
  686. DP_DEBUG("dp already connected, skipping hpd high\n");
  687. mutex_unlock(&dp->session_lock);
  688. return -EISCONN;
  689. }
  690. dp_display_state_add(DP_STATE_CONNECTED);
  691. dp->dp_display.max_pclk_khz = min(dp->parser->max_pclk_khz,
  692. dp->debug->max_pclk_khz);
  693. dp_display_host_ready(dp);
  694. dp->link->psm_config(dp->link, &dp->panel->link_info, false);
  695. dp->debug->psm_enabled = false;
  696. if (!dp->dp_display.base_connector)
  697. goto end;
  698. rc = dp->panel->read_sink_caps(dp->panel,
  699. dp->dp_display.base_connector, dp->hpd->multi_func);
  700. /*
  701. * ETIMEDOUT --> cable may have been removed
  702. * ENOTCONN --> no downstream device connected
  703. */
  704. if (rc == -ETIMEDOUT || rc == -ENOTCONN) {
  705. dp_display_state_remove(DP_STATE_CONNECTED);
  706. goto end;
  707. }
  708. dp->link->process_request(dp->link);
  709. dp->panel->handle_sink_request(dp->panel);
  710. dp_display_process_mst_hpd_high(dp, false);
  711. rc = dp->ctrl->on(dp->ctrl, dp->mst.mst_active,
  712. dp->panel->fec_en, false);
  713. if (rc) {
  714. dp_display_state_remove(DP_STATE_CONNECTED);
  715. goto end;
  716. }
  717. dp->process_hpd_connect = false;
  718. dp_display_process_mst_hpd_high(dp, true);
  719. end:
  720. mutex_unlock(&dp->session_lock);
  721. if (!rc && !dp_display_state_is(DP_STATE_ABORTED))
  722. dp_display_send_hpd_notification(dp);
  723. return rc;
  724. }
  725. static void dp_display_process_mst_hpd_low(struct dp_display_private *dp)
  726. {
  727. struct dp_mst_hpd_info info = {0};
  728. if (dp->mst.mst_active) {
  729. DP_MST_DEBUG("mst_hpd_low work\n");
  730. if (dp->mst.cbs.hpd) {
  731. info.mst_protocol = dp->parser->has_mst_sideband;
  732. dp->mst.cbs.hpd(&dp->dp_display, false, &info);
  733. }
  734. dp_display_update_mst_state(dp, false);
  735. }
  736. DP_MST_DEBUG("mst_hpd_low. mst_active:%d\n", dp->mst.mst_active);
  737. }
  738. static int dp_display_process_hpd_low(struct dp_display_private *dp)
  739. {
  740. int rc = 0;
  741. dp_display_state_remove(DP_STATE_CONNECTED);
  742. dp->process_hpd_connect = false;
  743. dp_display_process_mst_hpd_low(dp);
  744. if ((dp_display_state_is(DP_STATE_CONNECT_NOTIFIED) ||
  745. dp_display_state_is(DP_STATE_ENABLED)) &&
  746. !dp->mst.mst_active)
  747. rc = dp_display_send_hpd_notification(dp);
  748. mutex_lock(&dp->session_lock);
  749. if (!dp->active_stream_cnt)
  750. dp->ctrl->off(dp->ctrl);
  751. mutex_unlock(&dp->session_lock);
  752. dp->panel->video_test = false;
  753. return rc;
  754. }
  755. static int dp_display_usbpd_configure_cb(struct device *dev)
  756. {
  757. int rc = 0;
  758. struct dp_display_private *dp;
  759. if (!dev) {
  760. DP_ERR("invalid dev\n");
  761. rc = -EINVAL;
  762. goto end;
  763. }
  764. dp = dev_get_drvdata(dev);
  765. if (!dp) {
  766. DP_ERR("no driver data found\n");
  767. rc = -ENODEV;
  768. goto end;
  769. }
  770. if (!dp->debug->sim_mode && !dp->parser->no_aux_switch
  771. && !dp->parser->gpio_aux_switch) {
  772. rc = dp->aux->aux_switch(dp->aux, true, dp->hpd->orientation);
  773. if (rc)
  774. goto end;
  775. }
  776. mutex_lock(&dp->session_lock);
  777. dp_display_state_remove(DP_STATE_ABORTED);
  778. dp_display_state_add(DP_STATE_CONFIGURED);
  779. dp_display_host_init(dp);
  780. /* check for hpd high */
  781. if (dp->hpd->hpd_high)
  782. queue_work(dp->wq, &dp->connect_work);
  783. else
  784. dp->process_hpd_connect = true;
  785. mutex_unlock(&dp->session_lock);
  786. end:
  787. return rc;
  788. }
  789. static int dp_display_stream_pre_disable(struct dp_display_private *dp,
  790. struct dp_panel *dp_panel)
  791. {
  792. dp->ctrl->stream_pre_off(dp->ctrl, dp_panel);
  793. return 0;
  794. }
  795. static void dp_display_stream_disable(struct dp_display_private *dp,
  796. struct dp_panel *dp_panel)
  797. {
  798. if (!dp->active_stream_cnt) {
  799. DP_ERR("invalid active_stream_cnt (%d)\n",
  800. dp->active_stream_cnt);
  801. return;
  802. }
  803. DP_DEBUG("stream_id=%d, active_stream_cnt=%d\n",
  804. dp_panel->stream_id, dp->active_stream_cnt);
  805. dp->ctrl->stream_off(dp->ctrl, dp_panel);
  806. dp->active_panels[dp_panel->stream_id] = NULL;
  807. dp->active_stream_cnt--;
  808. }
  809. static void dp_audio_enable(struct dp_display_private *dp, bool enable)
  810. {
  811. struct dp_panel *dp_panel;
  812. int idx;
  813. for (idx = DP_STREAM_0; idx < DP_STREAM_MAX; idx++) {
  814. if (!dp->active_panels[idx])
  815. continue;
  816. dp_panel = dp->active_panels[idx];
  817. if (dp_panel->audio_supported) {
  818. if (enable) {
  819. dp_panel->audio->bw_code =
  820. dp->link->link_params.bw_code;
  821. dp_panel->audio->lane_count =
  822. dp->link->link_params.lane_count;
  823. dp_panel->audio->on(dp->panel->audio);
  824. } else {
  825. dp_panel->audio->off(dp_panel->audio);
  826. }
  827. }
  828. }
  829. }
  830. static void dp_display_clean(struct dp_display_private *dp)
  831. {
  832. int idx;
  833. struct dp_panel *dp_panel;
  834. struct dp_link_hdcp_status *status = &dp->link->hdcp_status;
  835. if (dp_display_is_hdcp_enabled(dp) &&
  836. status->hdcp_state != HDCP_STATE_INACTIVE) {
  837. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  838. if (dp->hdcp.ops->off)
  839. dp->hdcp.ops->off(dp->hdcp.data);
  840. dp_display_update_hdcp_status(dp, true);
  841. }
  842. for (idx = DP_STREAM_0; idx < DP_STREAM_MAX; idx++) {
  843. if (!dp->active_panels[idx])
  844. continue;
  845. dp_panel = dp->active_panels[idx];
  846. if (dp_panel->audio_supported)
  847. dp_panel->audio->off(dp_panel->audio);
  848. dp_display_stream_pre_disable(dp, dp_panel);
  849. dp_display_stream_disable(dp, dp_panel);
  850. dp_panel->deinit(dp_panel, 0);
  851. }
  852. dp_display_state_remove(DP_STATE_ENABLED | DP_STATE_CONNECTED);
  853. dp->ctrl->off(dp->ctrl);
  854. }
  855. static int dp_display_handle_disconnect(struct dp_display_private *dp)
  856. {
  857. int rc;
  858. rc = dp_display_process_hpd_low(dp);
  859. if (rc) {
  860. /* cancel any pending request */
  861. dp->ctrl->abort(dp->ctrl);
  862. dp->aux->abort(dp->aux);
  863. }
  864. mutex_lock(&dp->session_lock);
  865. if (rc && dp_display_state_is(DP_STATE_ENABLED))
  866. dp_display_clean(dp);
  867. dp_display_host_unready(dp);
  868. mutex_unlock(&dp->session_lock);
  869. return rc;
  870. }
  871. static void dp_display_disconnect_sync(struct dp_display_private *dp)
  872. {
  873. /* cancel any pending request */
  874. dp_display_state_add(DP_STATE_ABORTED);
  875. dp->ctrl->abort(dp->ctrl);
  876. dp->aux->abort(dp->aux);
  877. /* wait for idle state */
  878. cancel_work_sync(&dp->connect_work);
  879. cancel_work_sync(&dp->attention_work);
  880. flush_workqueue(dp->wq);
  881. dp_display_handle_disconnect(dp);
  882. }
  883. static int dp_display_usbpd_disconnect_cb(struct device *dev)
  884. {
  885. int rc = 0;
  886. struct dp_display_private *dp;
  887. if (!dev) {
  888. DP_ERR("invalid dev\n");
  889. rc = -EINVAL;
  890. goto end;
  891. }
  892. dp = dev_get_drvdata(dev);
  893. if (!dp) {
  894. DP_ERR("no driver data found\n");
  895. rc = -ENODEV;
  896. goto end;
  897. }
  898. dp_display_state_remove(DP_STATE_CONFIGURED);
  899. mutex_lock(&dp->session_lock);
  900. if (dp->debug->psm_enabled && dp_display_state_is(DP_STATE_READY))
  901. dp->link->psm_config(dp->link, &dp->panel->link_info, true);
  902. mutex_unlock(&dp->session_lock);
  903. dp_display_disconnect_sync(dp);
  904. mutex_lock(&dp->session_lock);
  905. dp_display_host_deinit(dp);
  906. mutex_unlock(&dp->session_lock);
  907. if (!dp->debug->sim_mode && !dp->parser->no_aux_switch
  908. && !dp->parser->gpio_aux_switch)
  909. dp->aux->aux_switch(dp->aux, false, ORIENTATION_NONE);
  910. end:
  911. return rc;
  912. }
  913. static int dp_display_stream_enable(struct dp_display_private *dp,
  914. struct dp_panel *dp_panel)
  915. {
  916. int rc = 0;
  917. rc = dp->ctrl->stream_on(dp->ctrl, dp_panel);
  918. if (dp->debug->tpg_state)
  919. dp_panel->tpg_config(dp_panel, true);
  920. if (!rc) {
  921. dp->active_panels[dp_panel->stream_id] = dp_panel;
  922. dp->active_stream_cnt++;
  923. }
  924. DP_DEBUG("dp active_stream_cnt:%d\n", dp->active_stream_cnt);
  925. return rc;
  926. }
  927. static void dp_display_mst_attention(struct dp_display_private *dp)
  928. {
  929. struct dp_mst_hpd_info hpd_irq = {0};
  930. if (dp->mst.mst_active && dp->mst.cbs.hpd_irq) {
  931. hpd_irq.mst_hpd_sim = dp->debug->mst_hpd_sim;
  932. hpd_irq.mst_sim_add_con = dp->debug->mst_sim_add_con;
  933. hpd_irq.mst_sim_remove_con = dp->debug->mst_sim_remove_con;
  934. hpd_irq.mst_sim_remove_con_id = dp->debug->mst_sim_remove_con_id;
  935. hpd_irq.edid = dp->debug->get_edid(dp->debug);
  936. dp->mst.cbs.hpd_irq(&dp->dp_display, &hpd_irq);
  937. dp->debug->mst_hpd_sim = false;
  938. dp->debug->mst_sim_add_con = false;
  939. dp->debug->mst_sim_remove_con = false;
  940. }
  941. DP_MST_DEBUG("mst_attention_work. mst_active:%d\n", dp->mst.mst_active);
  942. }
  943. static void dp_display_attention_work(struct work_struct *work)
  944. {
  945. struct dp_display_private *dp = container_of(work,
  946. struct dp_display_private, attention_work);
  947. mutex_lock(&dp->session_lock);
  948. if (dp->debug->mst_hpd_sim || !dp_display_state_is(DP_STATE_READY)) {
  949. mutex_unlock(&dp->session_lock);
  950. goto mst_attention;
  951. }
  952. if (dp->link->process_request(dp->link)) {
  953. mutex_unlock(&dp->session_lock);
  954. goto cp_irq;
  955. }
  956. mutex_unlock(&dp->session_lock);
  957. if (dp->link->sink_request & DS_PORT_STATUS_CHANGED) {
  958. if (dp_display_is_sink_count_zero(dp)) {
  959. dp_display_handle_disconnect(dp);
  960. } else {
  961. if (!dp->mst.mst_active)
  962. queue_work(dp->wq, &dp->connect_work);
  963. }
  964. goto mst_attention;
  965. }
  966. if (dp->link->sink_request & DP_TEST_LINK_VIDEO_PATTERN) {
  967. dp_display_handle_disconnect(dp);
  968. dp->panel->video_test = true;
  969. queue_work(dp->wq, &dp->connect_work);
  970. goto mst_attention;
  971. }
  972. if (dp->link->sink_request & (DP_TEST_LINK_PHY_TEST_PATTERN |
  973. DP_TEST_LINK_TRAINING | DP_LINK_STATUS_UPDATED)) {
  974. mutex_lock(&dp->session_lock);
  975. dp_audio_enable(dp, false);
  976. mutex_unlock(&dp->session_lock);
  977. if (dp->link->sink_request & DP_TEST_LINK_PHY_TEST_PATTERN)
  978. dp->ctrl->process_phy_test_request(dp->ctrl);
  979. if (dp->link->sink_request & DP_TEST_LINK_TRAINING) {
  980. dp->link->send_test_response(dp->link);
  981. dp->ctrl->link_maintenance(dp->ctrl);
  982. }
  983. if (dp->link->sink_request & DP_LINK_STATUS_UPDATED)
  984. dp->ctrl->link_maintenance(dp->ctrl);
  985. mutex_lock(&dp->session_lock);
  986. dp_audio_enable(dp, true);
  987. mutex_unlock(&dp->session_lock);
  988. if (dp->link->sink_request & (DP_TEST_LINK_PHY_TEST_PATTERN |
  989. DP_TEST_LINK_TRAINING))
  990. goto mst_attention;
  991. }
  992. cp_irq:
  993. if (dp_display_is_hdcp_enabled(dp) && dp->hdcp.ops->cp_irq)
  994. dp->hdcp.ops->cp_irq(dp->hdcp.data);
  995. mst_attention:
  996. dp_display_mst_attention(dp);
  997. }
  998. static int dp_display_usbpd_attention_cb(struct device *dev)
  999. {
  1000. struct dp_display_private *dp;
  1001. if (!dev) {
  1002. DP_ERR("invalid dev\n");
  1003. return -EINVAL;
  1004. }
  1005. dp = dev_get_drvdata(dev);
  1006. if (!dp) {
  1007. DP_ERR("no driver data found\n");
  1008. return -ENODEV;
  1009. }
  1010. DP_DEBUG("hpd_irq:%d, hpd_high:%d, power_on:%d, is_connected:%d\n",
  1011. dp->hpd->hpd_irq, dp->hpd->hpd_high,
  1012. !!dp_display_state_is(DP_STATE_ENABLED),
  1013. !!dp_display_state_is(DP_STATE_CONNECTED));
  1014. if (!dp->hpd->hpd_high) {
  1015. dp_display_disconnect_sync(dp);
  1016. } else if ((dp->hpd->hpd_irq && dp_display_state_is(DP_STATE_READY)) ||
  1017. dp->debug->mst_hpd_sim) {
  1018. queue_work(dp->wq, &dp->attention_work);
  1019. } else if (dp->process_hpd_connect ||
  1020. !dp_display_state_is(DP_STATE_CONNECTED)) {
  1021. dp_display_state_remove(DP_STATE_ABORTED);
  1022. queue_work(dp->wq, &dp->connect_work);
  1023. } else {
  1024. DP_DEBUG("ignored\n");
  1025. }
  1026. return 0;
  1027. }
  1028. static void dp_display_connect_work(struct work_struct *work)
  1029. {
  1030. int rc = 0;
  1031. struct dp_display_private *dp = container_of(work,
  1032. struct dp_display_private, connect_work);
  1033. if (dp_display_state_is(DP_STATE_ABORTED)) {
  1034. DP_WARN("HPD off requested\n");
  1035. return;
  1036. }
  1037. if (!dp->hpd->hpd_high) {
  1038. DP_WARN("Sink disconnected\n");
  1039. return;
  1040. }
  1041. rc = dp_display_process_hpd_high(dp);
  1042. if (!rc && dp->panel->video_test)
  1043. dp->link->send_test_response(dp->link);
  1044. }
  1045. static int dp_display_usb_notifier(struct notifier_block *nb,
  1046. unsigned long event, void *ptr)
  1047. {
  1048. struct extcon_dev *edev = ptr;
  1049. struct dp_display_private *dp = container_of(nb,
  1050. struct dp_display_private, usb_nb);
  1051. if (!edev)
  1052. goto end;
  1053. if (!event && dp->debug->sim_mode) {
  1054. dp_display_disconnect_sync(dp);
  1055. dp->debug->abort(dp->debug);
  1056. }
  1057. end:
  1058. return NOTIFY_DONE;
  1059. }
  1060. static int dp_display_get_usb_extcon(struct dp_display_private *dp)
  1061. {
  1062. struct extcon_dev *edev;
  1063. int rc;
  1064. edev = extcon_get_edev_by_phandle(&dp->pdev->dev, 0);
  1065. if (IS_ERR(edev))
  1066. return PTR_ERR(edev);
  1067. dp->usb_nb.notifier_call = dp_display_usb_notifier;
  1068. dp->usb_nb.priority = 2;
  1069. rc = extcon_register_notifier(edev, EXTCON_USB, &dp->usb_nb);
  1070. if (rc)
  1071. DP_ERR("failed to register for usb event: %d\n", rc);
  1072. return rc;
  1073. }
  1074. static void dp_display_deinit_sub_modules(struct dp_display_private *dp)
  1075. {
  1076. dp_audio_put(dp->panel->audio);
  1077. dp_ctrl_put(dp->ctrl);
  1078. dp_link_put(dp->link);
  1079. dp_panel_put(dp->panel);
  1080. dp_aux_put(dp->aux);
  1081. dp_power_put(dp->power);
  1082. dp_catalog_put(dp->catalog);
  1083. dp_parser_put(dp->parser);
  1084. dp_hpd_put(dp->hpd);
  1085. mutex_destroy(&dp->session_lock);
  1086. dp_debug_put(dp->debug);
  1087. }
  1088. static int dp_init_sub_modules(struct dp_display_private *dp)
  1089. {
  1090. int rc = 0;
  1091. bool hdcp_disabled;
  1092. struct device *dev = &dp->pdev->dev;
  1093. struct dp_hpd_cb *cb = &dp->hpd_cb;
  1094. struct dp_ctrl_in ctrl_in = {
  1095. .dev = dev,
  1096. };
  1097. struct dp_panel_in panel_in = {
  1098. .dev = dev,
  1099. };
  1100. struct dp_debug_in debug_in = {
  1101. .dev = dev,
  1102. };
  1103. mutex_init(&dp->session_lock);
  1104. dp->parser = dp_parser_get(dp->pdev);
  1105. if (IS_ERR(dp->parser)) {
  1106. rc = PTR_ERR(dp->parser);
  1107. DP_ERR("failed to initialize parser, rc = %d\n", rc);
  1108. dp->parser = NULL;
  1109. goto error;
  1110. }
  1111. rc = dp->parser->parse(dp->parser);
  1112. if (rc) {
  1113. DP_ERR("device tree parsing failed\n");
  1114. goto error_catalog;
  1115. }
  1116. g_dp_display->is_mst_supported = dp->parser->has_mst;
  1117. dp->catalog = dp_catalog_get(dev, dp->parser);
  1118. if (IS_ERR(dp->catalog)) {
  1119. rc = PTR_ERR(dp->catalog);
  1120. DP_ERR("failed to initialize catalog, rc = %d\n", rc);
  1121. dp->catalog = NULL;
  1122. goto error_catalog;
  1123. }
  1124. dp->power = dp_power_get(dp->parser);
  1125. if (IS_ERR(dp->power)) {
  1126. rc = PTR_ERR(dp->power);
  1127. DP_ERR("failed to initialize power, rc = %d\n", rc);
  1128. dp->power = NULL;
  1129. goto error_power;
  1130. }
  1131. rc = dp->power->power_client_init(dp->power, &dp->priv->phandle,
  1132. dp->dp_display.drm_dev);
  1133. if (rc) {
  1134. DP_ERR("Power client create failed\n");
  1135. goto error_aux;
  1136. }
  1137. dp->aux = dp_aux_get(dev, &dp->catalog->aux, dp->parser,
  1138. dp->aux_switch_node);
  1139. if (IS_ERR(dp->aux)) {
  1140. rc = PTR_ERR(dp->aux);
  1141. DP_ERR("failed to initialize aux, rc = %d\n", rc);
  1142. dp->aux = NULL;
  1143. goto error_aux;
  1144. }
  1145. rc = dp->aux->drm_aux_register(dp->aux);
  1146. if (rc) {
  1147. DP_ERR("DRM DP AUX register failed\n");
  1148. goto error_link;
  1149. }
  1150. dp->link = dp_link_get(dev, dp->aux);
  1151. if (IS_ERR(dp->link)) {
  1152. rc = PTR_ERR(dp->link);
  1153. DP_ERR("failed to initialize link, rc = %d\n", rc);
  1154. dp->link = NULL;
  1155. goto error_link;
  1156. }
  1157. panel_in.aux = dp->aux;
  1158. panel_in.catalog = &dp->catalog->panel;
  1159. panel_in.link = dp->link;
  1160. panel_in.connector = dp->dp_display.base_connector;
  1161. panel_in.base_panel = NULL;
  1162. panel_in.parser = dp->parser;
  1163. dp->panel = dp_panel_get(&panel_in);
  1164. if (IS_ERR(dp->panel)) {
  1165. rc = PTR_ERR(dp->panel);
  1166. DP_ERR("failed to initialize panel, rc = %d\n", rc);
  1167. dp->panel = NULL;
  1168. goto error_panel;
  1169. }
  1170. ctrl_in.link = dp->link;
  1171. ctrl_in.panel = dp->panel;
  1172. ctrl_in.aux = dp->aux;
  1173. ctrl_in.power = dp->power;
  1174. ctrl_in.catalog = &dp->catalog->ctrl;
  1175. ctrl_in.parser = dp->parser;
  1176. dp->ctrl = dp_ctrl_get(&ctrl_in);
  1177. if (IS_ERR(dp->ctrl)) {
  1178. rc = PTR_ERR(dp->ctrl);
  1179. DP_ERR("failed to initialize ctrl, rc = %d\n", rc);
  1180. dp->ctrl = NULL;
  1181. goto error_ctrl;
  1182. }
  1183. dp->panel->audio = dp_audio_get(dp->pdev, dp->panel,
  1184. &dp->catalog->audio);
  1185. if (IS_ERR(dp->panel->audio)) {
  1186. rc = PTR_ERR(dp->panel->audio);
  1187. DP_ERR("failed to initialize audio, rc = %d\n", rc);
  1188. dp->panel->audio = NULL;
  1189. goto error_audio;
  1190. }
  1191. memset(&dp->mst, 0, sizeof(dp->mst));
  1192. dp->active_stream_cnt = 0;
  1193. cb->configure = dp_display_usbpd_configure_cb;
  1194. cb->disconnect = dp_display_usbpd_disconnect_cb;
  1195. cb->attention = dp_display_usbpd_attention_cb;
  1196. dp->hpd = dp_hpd_get(dev, dp->parser, &dp->catalog->hpd, cb);
  1197. if (IS_ERR(dp->hpd)) {
  1198. rc = PTR_ERR(dp->hpd);
  1199. DP_ERR("failed to initialize hpd, rc = %d\n", rc);
  1200. dp->hpd = NULL;
  1201. goto error_hpd;
  1202. }
  1203. hdcp_disabled = !!dp_display_initialize_hdcp(dp);
  1204. debug_in.panel = dp->panel;
  1205. debug_in.hpd = dp->hpd;
  1206. debug_in.link = dp->link;
  1207. debug_in.aux = dp->aux;
  1208. debug_in.connector = &dp->dp_display.base_connector;
  1209. debug_in.catalog = dp->catalog;
  1210. debug_in.parser = dp->parser;
  1211. debug_in.ctrl = dp->ctrl;
  1212. dp->debug = dp_debug_get(&debug_in);
  1213. if (IS_ERR(dp->debug)) {
  1214. rc = PTR_ERR(dp->debug);
  1215. DP_ERR("failed to initialize debug, rc = %d\n", rc);
  1216. dp->debug = NULL;
  1217. goto error_debug;
  1218. }
  1219. dp->cached_connector_status = connector_status_disconnected;
  1220. dp->tot_dsc_blks_in_use = 0;
  1221. dp->debug->hdcp_disabled = hdcp_disabled;
  1222. dp_display_update_hdcp_status(dp, true);
  1223. dp_display_get_usb_extcon(dp);
  1224. rc = dp->hpd->register_hpd(dp->hpd);
  1225. if (rc) {
  1226. DP_ERR("failed register hpd\n");
  1227. goto error_hpd_reg;
  1228. }
  1229. return rc;
  1230. error_hpd_reg:
  1231. dp_debug_put(dp->debug);
  1232. error_debug:
  1233. dp_hpd_put(dp->hpd);
  1234. error_hpd:
  1235. dp_audio_put(dp->panel->audio);
  1236. error_audio:
  1237. dp_ctrl_put(dp->ctrl);
  1238. error_ctrl:
  1239. dp_panel_put(dp->panel);
  1240. error_panel:
  1241. dp_link_put(dp->link);
  1242. error_link:
  1243. dp_aux_put(dp->aux);
  1244. error_aux:
  1245. dp_power_put(dp->power);
  1246. error_power:
  1247. dp_catalog_put(dp->catalog);
  1248. error_catalog:
  1249. dp_parser_put(dp->parser);
  1250. error:
  1251. mutex_destroy(&dp->session_lock);
  1252. return rc;
  1253. }
  1254. static int dp_display_post_init(struct dp_display *dp_display)
  1255. {
  1256. int rc = 0;
  1257. struct dp_display_private *dp;
  1258. if (!dp_display) {
  1259. DP_ERR("invalid input\n");
  1260. rc = -EINVAL;
  1261. goto end;
  1262. }
  1263. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1264. if (IS_ERR_OR_NULL(dp)) {
  1265. DP_ERR("invalid params\n");
  1266. rc = -EINVAL;
  1267. goto end;
  1268. }
  1269. rc = dp_init_sub_modules(dp);
  1270. if (rc)
  1271. goto end;
  1272. dp_display->post_init = NULL;
  1273. end:
  1274. DP_DEBUG("%s\n", rc ? "failed" : "success");
  1275. return rc;
  1276. }
  1277. static int dp_display_set_mode(struct dp_display *dp_display, void *panel,
  1278. struct dp_display_mode *mode)
  1279. {
  1280. const u32 num_components = 3, default_bpp = 24;
  1281. struct dp_display_private *dp;
  1282. struct dp_panel *dp_panel;
  1283. if (!dp_display || !panel) {
  1284. DP_ERR("invalid input\n");
  1285. return -EINVAL;
  1286. }
  1287. dp_panel = panel;
  1288. if (!dp_panel->connector) {
  1289. DP_ERR("invalid connector input\n");
  1290. return -EINVAL;
  1291. }
  1292. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1293. mutex_lock(&dp->session_lock);
  1294. mode->timing.bpp =
  1295. dp_panel->connector->display_info.bpc * num_components;
  1296. if (!mode->timing.bpp)
  1297. mode->timing.bpp = default_bpp;
  1298. mode->timing.bpp = dp->panel->get_mode_bpp(dp->panel,
  1299. mode->timing.bpp, mode->timing.pixel_clk_khz);
  1300. dp_panel->pinfo = mode->timing;
  1301. mutex_unlock(&dp->session_lock);
  1302. return 0;
  1303. }
  1304. static int dp_display_prepare(struct dp_display *dp_display, void *panel)
  1305. {
  1306. struct dp_display_private *dp;
  1307. struct dp_panel *dp_panel;
  1308. int rc = 0;
  1309. if (!dp_display || !panel) {
  1310. DP_ERR("invalid input\n");
  1311. return -EINVAL;
  1312. }
  1313. dp_panel = panel;
  1314. if (!dp_panel->connector) {
  1315. DP_ERR("invalid connector input\n");
  1316. return -EINVAL;
  1317. }
  1318. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1319. mutex_lock(&dp->session_lock);
  1320. if (dp_display_state_is(DP_STATE_ABORTED | DP_STATE_ENABLED))
  1321. goto end;
  1322. if (!dp_display_is_ready(dp))
  1323. goto end;
  1324. /* For supporting DP_PANEL_SRC_INITIATED_POWER_DOWN case */
  1325. dp_display_host_init(dp);
  1326. dp_display_host_ready(dp);
  1327. if (dp->debug->psm_enabled) {
  1328. dp->link->psm_config(dp->link, &dp->panel->link_info, false);
  1329. dp->debug->psm_enabled = false;
  1330. }
  1331. /*
  1332. * Execute the dp controller power on in shallow mode here.
  1333. * In normal cases, controller should have been powered on
  1334. * by now. In some cases like suspend/resume or framework
  1335. * reboot, we end up here without a powered on controller.
  1336. * Cable may have been removed in suspended state. In that
  1337. * case, link training is bound to fail on system resume.
  1338. * So, we execute in shallow mode here to do only minimal
  1339. * and required things.
  1340. */
  1341. rc = dp->ctrl->on(dp->ctrl, dp->mst.mst_active, dp_panel->fec_en, true);
  1342. if (rc)
  1343. goto end;
  1344. end:
  1345. mutex_unlock(&dp->session_lock);
  1346. return 0;
  1347. }
  1348. static int dp_display_set_stream_info(struct dp_display *dp_display,
  1349. void *panel, u32 strm_id, u32 start_slot,
  1350. u32 num_slots, u32 pbn, int vcpi)
  1351. {
  1352. int rc = 0;
  1353. struct dp_panel *dp_panel;
  1354. struct dp_display_private *dp;
  1355. const int max_slots = 64;
  1356. if (!dp_display) {
  1357. DP_ERR("invalid input\n");
  1358. return -EINVAL;
  1359. }
  1360. if (strm_id >= DP_STREAM_MAX) {
  1361. DP_ERR("invalid stream id:%d\n", strm_id);
  1362. return -EINVAL;
  1363. }
  1364. if (start_slot + num_slots > max_slots) {
  1365. DP_ERR("invalid channel info received. start:%d, slots:%d\n",
  1366. start_slot, num_slots);
  1367. return -EINVAL;
  1368. }
  1369. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1370. mutex_lock(&dp->session_lock);
  1371. dp->ctrl->set_mst_channel_info(dp->ctrl, strm_id,
  1372. start_slot, num_slots);
  1373. if (panel) {
  1374. dp_panel = panel;
  1375. dp_panel->set_stream_info(dp_panel, strm_id, start_slot,
  1376. num_slots, pbn, vcpi);
  1377. }
  1378. mutex_unlock(&dp->session_lock);
  1379. return rc;
  1380. }
  1381. static void dp_display_update_dsc_resources(struct dp_display_private *dp,
  1382. struct dp_panel *panel, bool enable)
  1383. {
  1384. u32 dsc_blk_cnt = 0;
  1385. if (panel->pinfo.comp_info.comp_type == MSM_DISPLAY_COMPRESSION_DSC &&
  1386. panel->pinfo.comp_info.comp_ratio) {
  1387. dsc_blk_cnt = panel->pinfo.h_active /
  1388. dp->parser->max_dp_dsc_input_width_pixs;
  1389. if (panel->pinfo.h_active %
  1390. dp->parser->max_dp_dsc_input_width_pixs)
  1391. dsc_blk_cnt++;
  1392. }
  1393. if (enable) {
  1394. dp->tot_dsc_blks_in_use += dsc_blk_cnt;
  1395. panel->tot_dsc_blks_in_use += dsc_blk_cnt;
  1396. } else {
  1397. dp->tot_dsc_blks_in_use -= dsc_blk_cnt;
  1398. panel->tot_dsc_blks_in_use -= dsc_blk_cnt;
  1399. }
  1400. }
  1401. static int dp_display_enable(struct dp_display *dp_display, void *panel)
  1402. {
  1403. int rc = 0;
  1404. struct dp_display_private *dp;
  1405. if (!dp_display || !panel) {
  1406. DP_ERR("invalid input\n");
  1407. return -EINVAL;
  1408. }
  1409. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1410. mutex_lock(&dp->session_lock);
  1411. if (!dp_display_state_is(DP_STATE_READY)) {
  1412. dp_display_state_show("[host not ready]");
  1413. goto end;
  1414. }
  1415. if (dp_display_state_is(DP_STATE_ABORTED))
  1416. goto end;
  1417. rc = dp_display_stream_enable(dp, panel);
  1418. if (rc)
  1419. goto end;
  1420. dp_display_update_dsc_resources(dp, panel, true);
  1421. dp_display_state_add(DP_STATE_ENABLED);
  1422. end:
  1423. mutex_unlock(&dp->session_lock);
  1424. return rc;
  1425. }
  1426. static void dp_display_stream_post_enable(struct dp_display_private *dp,
  1427. struct dp_panel *dp_panel)
  1428. {
  1429. dp_panel->spd_config(dp_panel);
  1430. dp_panel->setup_hdr(dp_panel, NULL, false, 0, true);
  1431. }
  1432. static int dp_display_post_enable(struct dp_display *dp_display, void *panel)
  1433. {
  1434. struct dp_display_private *dp;
  1435. struct dp_panel *dp_panel;
  1436. if (!dp_display || !panel) {
  1437. DP_ERR("invalid input\n");
  1438. return -EINVAL;
  1439. }
  1440. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1441. dp_panel = panel;
  1442. mutex_lock(&dp->session_lock);
  1443. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  1444. dp_display_state_show("[not enabled]");
  1445. goto end;
  1446. }
  1447. if (dp_display_state_is(DP_STATE_ABORTED))
  1448. goto end;
  1449. if (!dp_display_is_ready(dp) || !dp_display_state_is(DP_STATE_READY)) {
  1450. dp_display_state_show("[not ready]");
  1451. goto end;
  1452. }
  1453. dp_display_stream_post_enable(dp, dp_panel);
  1454. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  1455. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ);
  1456. if (dp_panel->audio_supported) {
  1457. dp_panel->audio->bw_code = dp->link->link_params.bw_code;
  1458. dp_panel->audio->lane_count = dp->link->link_params.lane_count;
  1459. dp_panel->audio->on(dp_panel->audio);
  1460. }
  1461. end:
  1462. dp->aux->state |= DP_STATE_CTRL_POWERED_ON;
  1463. complete_all(&dp->notification_comp);
  1464. mutex_unlock(&dp->session_lock);
  1465. return 0;
  1466. }
  1467. static void dp_display_clear_colorspaces(struct dp_display *dp_display)
  1468. {
  1469. struct drm_connector *connector;
  1470. connector = dp_display->base_connector;
  1471. connector->color_enc_fmt = 0;
  1472. }
  1473. static int dp_display_pre_disable(struct dp_display *dp_display, void *panel)
  1474. {
  1475. struct dp_display_private *dp;
  1476. struct dp_panel *dp_panel = panel;
  1477. struct dp_link_hdcp_status *status;
  1478. int rc = 0;
  1479. size_t i;
  1480. if (!dp_display || !panel) {
  1481. DP_ERR("invalid input\n");
  1482. return -EINVAL;
  1483. }
  1484. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1485. mutex_lock(&dp->session_lock);
  1486. status = &dp->link->hdcp_status;
  1487. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  1488. dp_display_state_show("[not enabled]");
  1489. goto end;
  1490. }
  1491. dp_display_state_add(DP_STATE_HDCP_ABORTED);
  1492. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  1493. if (dp_display_is_hdcp_enabled(dp) &&
  1494. status->hdcp_state != HDCP_STATE_INACTIVE) {
  1495. bool off = true;
  1496. if (dp_display_state_is(DP_STATE_SUSPENDED)) {
  1497. DP_DEBUG("Can't perform HDCP cleanup while suspended. Defer\n");
  1498. dp->hdcp_delayed_off = true;
  1499. goto clean;
  1500. }
  1501. flush_delayed_work(&dp->hdcp_cb_work);
  1502. if (dp->mst.mst_active) {
  1503. dp_display_hdcp_deregister_stream(dp,
  1504. dp_panel->stream_id);
  1505. for (i = DP_STREAM_0; i < DP_STREAM_MAX; i++) {
  1506. if (i != dp_panel->stream_id &&
  1507. dp->active_panels[i]) {
  1508. DP_DEBUG("Streams are still active. Skip disabling HDCP\n");
  1509. off = false;
  1510. }
  1511. }
  1512. }
  1513. if (off) {
  1514. if (dp->hdcp.ops->off)
  1515. dp->hdcp.ops->off(dp->hdcp.data);
  1516. dp_display_update_hdcp_status(dp, true);
  1517. }
  1518. }
  1519. dp_display_clear_colorspaces(dp_display);
  1520. clean:
  1521. if (dp_panel->audio_supported)
  1522. dp_panel->audio->off(dp_panel->audio);
  1523. rc = dp_display_stream_pre_disable(dp, dp_panel);
  1524. end:
  1525. mutex_unlock(&dp->session_lock);
  1526. return 0;
  1527. }
  1528. static int dp_display_disable(struct dp_display *dp_display, void *panel)
  1529. {
  1530. int i;
  1531. struct dp_display_private *dp = NULL;
  1532. struct dp_panel *dp_panel = NULL;
  1533. struct dp_link_hdcp_status *status;
  1534. if (!dp_display || !panel) {
  1535. DP_ERR("invalid input\n");
  1536. return -EINVAL;
  1537. }
  1538. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1539. dp_panel = panel;
  1540. status = &dp->link->hdcp_status;
  1541. mutex_lock(&dp->session_lock);
  1542. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  1543. dp_display_state_show("[not enabled]");
  1544. goto end;
  1545. }
  1546. if (!dp_display_state_is(DP_STATE_READY)) {
  1547. dp_display_state_show("[not ready]");
  1548. goto end;
  1549. }
  1550. dp_display_stream_disable(dp, dp_panel);
  1551. dp_display_update_dsc_resources(dp, dp_panel, false);
  1552. dp_display_state_remove(DP_STATE_HDCP_ABORTED);
  1553. for (i = DP_STREAM_0; i < DP_STREAM_MAX; i++) {
  1554. if (dp->active_panels[i]) {
  1555. if (status->hdcp_state != HDCP_STATE_AUTHENTICATED)
  1556. queue_delayed_work(dp->wq, &dp->hdcp_cb_work,
  1557. HZ/4);
  1558. break;
  1559. }
  1560. }
  1561. end:
  1562. mutex_unlock(&dp->session_lock);
  1563. return 0;
  1564. }
  1565. static int dp_request_irq(struct dp_display *dp_display)
  1566. {
  1567. int rc = 0;
  1568. struct dp_display_private *dp;
  1569. if (!dp_display) {
  1570. DP_ERR("invalid input\n");
  1571. return -EINVAL;
  1572. }
  1573. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1574. dp->irq = irq_of_parse_and_map(dp->pdev->dev.of_node, 0);
  1575. if (dp->irq < 0) {
  1576. rc = dp->irq;
  1577. DP_ERR("failed to get irq: %d\n", rc);
  1578. return rc;
  1579. }
  1580. rc = devm_request_irq(&dp->pdev->dev, dp->irq, dp_display_irq,
  1581. IRQF_TRIGGER_HIGH, "dp_display_isr", dp);
  1582. if (rc < 0) {
  1583. DP_ERR("failed to request IRQ%u: %d\n",
  1584. dp->irq, rc);
  1585. return rc;
  1586. }
  1587. disable_irq(dp->irq);
  1588. return 0;
  1589. }
  1590. static struct dp_debug *dp_get_debug(struct dp_display *dp_display)
  1591. {
  1592. struct dp_display_private *dp;
  1593. if (!dp_display) {
  1594. DP_ERR("invalid input\n");
  1595. return ERR_PTR(-EINVAL);
  1596. }
  1597. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1598. return dp->debug;
  1599. }
  1600. static int dp_display_unprepare(struct dp_display *dp_display, void *panel)
  1601. {
  1602. struct dp_display_private *dp;
  1603. struct dp_panel *dp_panel = panel;
  1604. u32 flags = 0;
  1605. if (!dp_display || !panel) {
  1606. DP_ERR("invalid input\n");
  1607. return -EINVAL;
  1608. }
  1609. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1610. mutex_lock(&dp->session_lock);
  1611. /*
  1612. * Check if the power off sequence was triggered
  1613. * by a source initialated action like framework
  1614. * reboot or suspend-resume but not from normal
  1615. * hot plug.
  1616. */
  1617. if (dp_display_is_ready(dp))
  1618. flags |= DP_PANEL_SRC_INITIATED_POWER_DOWN;
  1619. if (dp->active_stream_cnt)
  1620. goto end;
  1621. if (flags & DP_PANEL_SRC_INITIATED_POWER_DOWN) {
  1622. dp->link->psm_config(dp->link, &dp->panel->link_info, true);
  1623. dp->debug->psm_enabled = true;
  1624. dp->ctrl->off(dp->ctrl);
  1625. dp_display_host_unready(dp);
  1626. dp_display_host_deinit(dp);
  1627. }
  1628. dp_display_state_remove(DP_STATE_ENABLED);
  1629. dp->aux->state = DP_STATE_CTRL_POWERED_OFF;
  1630. complete_all(&dp->notification_comp);
  1631. /* log this as it results from user action of cable dis-connection */
  1632. DP_INFO("[OK]\n");
  1633. end:
  1634. dp_panel->deinit(dp_panel, flags);
  1635. mutex_unlock(&dp->session_lock);
  1636. return 0;
  1637. }
  1638. static enum drm_mode_status dp_display_validate_mode(
  1639. struct dp_display *dp_display,
  1640. void *panel, struct drm_display_mode *mode,
  1641. const struct msm_resource_caps_info *avail_res)
  1642. {
  1643. struct dp_display_private *dp;
  1644. struct drm_dp_link *link_info;
  1645. u32 mode_rate_khz = 0, supported_rate_khz = 0, mode_bpp = 0;
  1646. struct dp_panel *dp_panel;
  1647. struct dp_debug *debug;
  1648. enum drm_mode_status mode_status = MODE_BAD;
  1649. bool in_list = false;
  1650. struct dp_mst_connector *mst_connector;
  1651. int hdis, vdis, vref, ar, _hdis, _vdis, _vref, _ar, rate;
  1652. struct dp_display_mode dp_mode;
  1653. bool dsc_en;
  1654. u32 num_lm = 0;
  1655. if (!dp_display || !mode || !panel ||
  1656. !avail_res || !avail_res->max_mixer_width) {
  1657. DP_ERR("invalid params\n");
  1658. return mode_status;
  1659. }
  1660. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1661. mutex_lock(&dp->session_lock);
  1662. dp_panel = panel;
  1663. if (!dp_panel->connector) {
  1664. DP_ERR("invalid connector\n");
  1665. goto end;
  1666. }
  1667. link_info = &dp->panel->link_info;
  1668. debug = dp->debug;
  1669. if (!debug)
  1670. goto end;
  1671. dp_display->convert_to_dp_mode(dp_display, panel, mode, &dp_mode);
  1672. dsc_en = dp_mode.timing.comp_info.comp_ratio ? true : false;
  1673. mode_bpp = dsc_en ? dp_mode.timing.comp_info.dsc_info.bpp :
  1674. dp_mode.timing.bpp;
  1675. mode_rate_khz = mode->clock * mode_bpp;
  1676. rate = drm_dp_bw_code_to_link_rate(dp->link->link_params.bw_code);
  1677. supported_rate_khz = link_info->num_lanes * rate * 8;
  1678. if (mode_rate_khz > supported_rate_khz) {
  1679. DP_MST_DEBUG("pclk:%d, supported_rate:%d\n",
  1680. mode->clock, supported_rate_khz);
  1681. goto end;
  1682. }
  1683. if (mode->clock > dp_display->max_pclk_khz) {
  1684. DP_MST_DEBUG("clk:%d, max:%d\n", mode->clock,
  1685. dp_display->max_pclk_khz);
  1686. goto end;
  1687. }
  1688. num_lm = (avail_res->max_mixer_width <= mode->hdisplay) ?
  1689. 2 : 1;
  1690. if (num_lm > avail_res->num_lm ||
  1691. (num_lm == 2 && !avail_res->num_3dmux)) {
  1692. DP_MST_DEBUG("num_lm:%d, req lm:%d 3dmux:%d\n", num_lm,
  1693. avail_res->num_lm, avail_res->num_3dmux);
  1694. goto end;
  1695. }
  1696. /*
  1697. * If the connector exists in the mst connector list and if debug is
  1698. * enabled for that connector, use the mst connector settings from the
  1699. * list for validation. Otherwise, use non-mst default settings.
  1700. */
  1701. mutex_lock(&debug->dp_mst_connector_list.lock);
  1702. if (list_empty(&debug->dp_mst_connector_list.list)) {
  1703. mutex_unlock(&debug->dp_mst_connector_list.lock);
  1704. goto verify_default;
  1705. }
  1706. list_for_each_entry(mst_connector, &debug->dp_mst_connector_list.list,
  1707. list) {
  1708. if (mst_connector->con_id == dp_panel->connector->base.id) {
  1709. in_list = true;
  1710. if (!mst_connector->debug_en) {
  1711. mode_status = MODE_OK;
  1712. mutex_unlock(
  1713. &debug->dp_mst_connector_list.lock);
  1714. goto end;
  1715. }
  1716. hdis = mst_connector->hdisplay;
  1717. vdis = mst_connector->vdisplay;
  1718. vref = mst_connector->vrefresh;
  1719. ar = mst_connector->aspect_ratio;
  1720. _hdis = mode->hdisplay;
  1721. _vdis = mode->vdisplay;
  1722. _vref = mode->vrefresh;
  1723. _ar = mode->picture_aspect_ratio;
  1724. if (hdis == _hdis && vdis == _vdis && vref == _vref &&
  1725. ar == _ar) {
  1726. mode_status = MODE_OK;
  1727. mutex_unlock(
  1728. &debug->dp_mst_connector_list.lock);
  1729. goto end;
  1730. }
  1731. break;
  1732. }
  1733. }
  1734. mutex_unlock(&debug->dp_mst_connector_list.lock);
  1735. if (in_list)
  1736. goto end;
  1737. verify_default:
  1738. if (debug->debug_en && (mode->hdisplay != debug->hdisplay ||
  1739. mode->vdisplay != debug->vdisplay ||
  1740. mode->vrefresh != debug->vrefresh ||
  1741. mode->picture_aspect_ratio != debug->aspect_ratio))
  1742. goto end;
  1743. mode_status = MODE_OK;
  1744. end:
  1745. mutex_unlock(&dp->session_lock);
  1746. return mode_status;
  1747. }
  1748. static int dp_display_get_modes(struct dp_display *dp, void *panel,
  1749. struct dp_display_mode *dp_mode)
  1750. {
  1751. struct dp_display_private *dp_display;
  1752. struct dp_panel *dp_panel;
  1753. int ret = 0;
  1754. if (!dp || !panel) {
  1755. DP_ERR("invalid params\n");
  1756. return 0;
  1757. }
  1758. dp_panel = panel;
  1759. if (!dp_panel->connector) {
  1760. DP_ERR("invalid connector\n");
  1761. return 0;
  1762. }
  1763. dp_display = container_of(dp, struct dp_display_private, dp_display);
  1764. ret = dp_panel->get_modes(dp_panel, dp_panel->connector, dp_mode);
  1765. if (dp_mode->timing.pixel_clk_khz)
  1766. dp->max_pclk_khz = dp_mode->timing.pixel_clk_khz;
  1767. return ret;
  1768. }
  1769. static void dp_display_convert_to_dp_mode(struct dp_display *dp_display,
  1770. void *panel,
  1771. const struct drm_display_mode *drm_mode,
  1772. struct dp_display_mode *dp_mode)
  1773. {
  1774. struct dp_display_private *dp;
  1775. struct dp_panel *dp_panel;
  1776. u32 free_dsc_blks = 0, required_dsc_blks = 0;
  1777. if (!dp_display || !drm_mode || !dp_mode || !panel) {
  1778. DP_ERR("invalid input\n");
  1779. return;
  1780. }
  1781. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1782. dp_panel = panel;
  1783. memset(dp_mode, 0, sizeof(*dp_mode));
  1784. free_dsc_blks = dp->parser->max_dp_dsc_blks -
  1785. dp->tot_dsc_blks_in_use +
  1786. dp_panel->tot_dsc_blks_in_use;
  1787. required_dsc_blks = drm_mode->hdisplay /
  1788. dp->parser->max_dp_dsc_input_width_pixs;
  1789. if (drm_mode->hdisplay % dp->parser->max_dp_dsc_input_width_pixs)
  1790. required_dsc_blks++;
  1791. if (free_dsc_blks >= required_dsc_blks)
  1792. dp_mode->capabilities |= DP_PANEL_CAPS_DSC;
  1793. if (dp_mode->capabilities & DP_PANEL_CAPS_DSC)
  1794. DP_DEBUG("in_use:%d, max:%d, free:%d, req:%d, caps:0x%x, width:%d\n",
  1795. dp->tot_dsc_blks_in_use, dp->parser->max_dp_dsc_blks,
  1796. free_dsc_blks, required_dsc_blks, dp_mode->capabilities,
  1797. dp->parser->max_dp_dsc_input_width_pixs);
  1798. dp_panel->convert_to_dp_mode(dp_panel, drm_mode, dp_mode);
  1799. }
  1800. static int dp_display_config_hdr(struct dp_display *dp_display, void *panel,
  1801. struct drm_msm_ext_hdr_metadata *hdr, bool dhdr_update)
  1802. {
  1803. struct dp_panel *dp_panel;
  1804. struct sde_connector *sde_conn;
  1805. struct dp_display_private *dp;
  1806. u64 core_clk_rate;
  1807. bool flush_hdr;
  1808. if (!dp_display || !panel) {
  1809. DP_ERR("invalid input\n");
  1810. return -EINVAL;
  1811. }
  1812. dp_panel = panel;
  1813. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1814. sde_conn = to_sde_connector(dp_panel->connector);
  1815. core_clk_rate = dp->power->clk_get_rate(dp->power, "core_clk");
  1816. if (!core_clk_rate) {
  1817. DP_ERR("invalid rate for core_clk\n");
  1818. return -EINVAL;
  1819. }
  1820. /*
  1821. * In rare cases where HDR metadata is updated independently
  1822. * flush the HDR metadata immediately instead of relying on
  1823. * the colorspace
  1824. */
  1825. flush_hdr = !sde_conn->colorspace_updated;
  1826. if (flush_hdr)
  1827. DP_DEBUG("flushing the HDR metadata\n");
  1828. else
  1829. DP_DEBUG("piggy-backing with colorspace\n");
  1830. return dp_panel->setup_hdr(dp_panel, hdr, dhdr_update,
  1831. core_clk_rate, flush_hdr);
  1832. }
  1833. static int dp_display_setup_colospace(struct dp_display *dp_display,
  1834. void *panel,
  1835. u32 colorspace)
  1836. {
  1837. struct dp_panel *dp_panel;
  1838. if (!dp_display || !panel) {
  1839. pr_err("invalid input\n");
  1840. return -EINVAL;
  1841. }
  1842. dp_panel = panel;
  1843. return dp_panel->set_colorspace(dp_panel, colorspace);
  1844. }
  1845. static int dp_display_create_workqueue(struct dp_display_private *dp)
  1846. {
  1847. dp->wq = create_singlethread_workqueue("drm_dp");
  1848. if (IS_ERR_OR_NULL(dp->wq)) {
  1849. DP_ERR("Error creating wq\n");
  1850. return -EPERM;
  1851. }
  1852. INIT_DELAYED_WORK(&dp->hdcp_cb_work, dp_display_hdcp_cb_work);
  1853. INIT_WORK(&dp->connect_work, dp_display_connect_work);
  1854. INIT_WORK(&dp->attention_work, dp_display_attention_work);
  1855. return 0;
  1856. }
  1857. static int dp_display_fsa4480_callback(struct notifier_block *self,
  1858. unsigned long event, void *data)
  1859. {
  1860. return 0;
  1861. }
  1862. static int dp_display_init_aux_switch(struct dp_display_private *dp)
  1863. {
  1864. int rc = 0;
  1865. const char *phandle = "qcom,dp-aux-switch";
  1866. struct notifier_block nb;
  1867. if (!dp->pdev->dev.of_node) {
  1868. DP_ERR("cannot find dev.of_node\n");
  1869. rc = -ENODEV;
  1870. goto end;
  1871. }
  1872. dp->aux_switch_node = of_parse_phandle(dp->pdev->dev.of_node,
  1873. phandle, 0);
  1874. if (!dp->aux_switch_node) {
  1875. DP_WARN("cannot parse %s handle\n", phandle);
  1876. rc = -ENODEV;
  1877. goto end;
  1878. }
  1879. nb.notifier_call = dp_display_fsa4480_callback;
  1880. nb.priority = 0;
  1881. rc = fsa4480_reg_notifier(&nb, dp->aux_switch_node);
  1882. if (rc) {
  1883. DP_ERR("failed to register notifier (%d)\n", rc);
  1884. goto end;
  1885. }
  1886. fsa4480_unreg_notifier(&nb, dp->aux_switch_node);
  1887. end:
  1888. return rc;
  1889. }
  1890. static int dp_display_mst_install(struct dp_display *dp_display,
  1891. struct dp_mst_drm_install_info *mst_install_info)
  1892. {
  1893. struct dp_display_private *dp;
  1894. if (!dp_display || !mst_install_info) {
  1895. DP_ERR("invalid input\n");
  1896. return -EINVAL;
  1897. }
  1898. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1899. if (!mst_install_info->cbs->hpd || !mst_install_info->cbs->hpd_irq) {
  1900. DP_ERR("invalid mst cbs\n");
  1901. return -EINVAL;
  1902. }
  1903. dp_display->dp_mst_prv_info = mst_install_info->dp_mst_prv_info;
  1904. if (!dp->parser->has_mst) {
  1905. DP_DEBUG("mst not enabled\n");
  1906. return -EPERM;
  1907. }
  1908. memcpy(&dp->mst.cbs, mst_install_info->cbs, sizeof(dp->mst.cbs));
  1909. dp->mst.drm_registered = true;
  1910. DP_MST_DEBUG("dp mst drm installed\n");
  1911. return 0;
  1912. }
  1913. static int dp_display_mst_uninstall(struct dp_display *dp_display)
  1914. {
  1915. struct dp_display_private *dp;
  1916. if (!dp_display) {
  1917. DP_ERR("invalid input\n");
  1918. return -EINVAL;
  1919. }
  1920. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1921. if (!dp->mst.drm_registered) {
  1922. DP_DEBUG("drm mst not registered\n");
  1923. return -EPERM;
  1924. }
  1925. dp = container_of(dp_display, struct dp_display_private,
  1926. dp_display);
  1927. memset(&dp->mst.cbs, 0, sizeof(dp->mst.cbs));
  1928. dp->mst.drm_registered = false;
  1929. DP_MST_DEBUG("dp mst drm uninstalled\n");
  1930. return 0;
  1931. }
  1932. static int dp_display_mst_connector_install(struct dp_display *dp_display,
  1933. struct drm_connector *connector)
  1934. {
  1935. int rc = 0;
  1936. struct dp_panel_in panel_in;
  1937. struct dp_panel *dp_panel;
  1938. struct dp_display_private *dp;
  1939. struct dp_mst_connector *mst_connector;
  1940. if (!dp_display || !connector) {
  1941. DP_ERR("invalid input\n");
  1942. return -EINVAL;
  1943. }
  1944. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1945. mutex_lock(&dp->session_lock);
  1946. if (!dp->mst.drm_registered) {
  1947. DP_DEBUG("drm mst not registered\n");
  1948. mutex_unlock(&dp->session_lock);
  1949. return -EPERM;
  1950. }
  1951. panel_in.dev = &dp->pdev->dev;
  1952. panel_in.aux = dp->aux;
  1953. panel_in.catalog = &dp->catalog->panel;
  1954. panel_in.link = dp->link;
  1955. panel_in.connector = connector;
  1956. panel_in.base_panel = dp->panel;
  1957. panel_in.parser = dp->parser;
  1958. dp_panel = dp_panel_get(&panel_in);
  1959. if (IS_ERR(dp_panel)) {
  1960. rc = PTR_ERR(dp_panel);
  1961. DP_ERR("failed to initialize panel, rc = %d\n", rc);
  1962. mutex_unlock(&dp->session_lock);
  1963. return rc;
  1964. }
  1965. dp_panel->audio = dp_audio_get(dp->pdev, dp_panel, &dp->catalog->audio);
  1966. if (IS_ERR(dp_panel->audio)) {
  1967. rc = PTR_ERR(dp_panel->audio);
  1968. DP_ERR("[mst] failed to initialize audio, rc = %d\n", rc);
  1969. dp_panel->audio = NULL;
  1970. mutex_unlock(&dp->session_lock);
  1971. return rc;
  1972. }
  1973. DP_MST_DEBUG("dp mst connector installed. conn:%d\n",
  1974. connector->base.id);
  1975. mutex_lock(&dp->debug->dp_mst_connector_list.lock);
  1976. mst_connector = kmalloc(sizeof(struct dp_mst_connector),
  1977. GFP_KERNEL);
  1978. if (!mst_connector) {
  1979. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  1980. mutex_unlock(&dp->session_lock);
  1981. return -ENOMEM;
  1982. }
  1983. mst_connector->debug_en = false;
  1984. mst_connector->conn = connector;
  1985. mst_connector->con_id = connector->base.id;
  1986. mst_connector->state = connector_status_unknown;
  1987. INIT_LIST_HEAD(&mst_connector->list);
  1988. list_add(&mst_connector->list,
  1989. &dp->debug->dp_mst_connector_list.list);
  1990. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  1991. mutex_unlock(&dp->session_lock);
  1992. return 0;
  1993. }
  1994. static int dp_display_mst_connector_uninstall(struct dp_display *dp_display,
  1995. struct drm_connector *connector)
  1996. {
  1997. int rc = 0;
  1998. struct sde_connector *sde_conn;
  1999. struct dp_panel *dp_panel;
  2000. struct dp_display_private *dp;
  2001. struct dp_mst_connector *con_to_remove, *temp_con;
  2002. if (!dp_display || !connector) {
  2003. DP_ERR("invalid input\n");
  2004. return -EINVAL;
  2005. }
  2006. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2007. mutex_lock(&dp->session_lock);
  2008. if (!dp->mst.drm_registered) {
  2009. DP_DEBUG("drm mst not registered\n");
  2010. mutex_unlock(&dp->session_lock);
  2011. return -EPERM;
  2012. }
  2013. sde_conn = to_sde_connector(connector);
  2014. if (!sde_conn->drv_panel) {
  2015. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2016. mutex_unlock(&dp->session_lock);
  2017. return -EINVAL;
  2018. }
  2019. dp_panel = sde_conn->drv_panel;
  2020. dp_audio_put(dp_panel->audio);
  2021. dp_panel_put(dp_panel);
  2022. DP_MST_DEBUG("dp mst connector uninstalled. conn:%d\n",
  2023. connector->base.id);
  2024. mutex_lock(&dp->debug->dp_mst_connector_list.lock);
  2025. list_for_each_entry_safe(con_to_remove, temp_con,
  2026. &dp->debug->dp_mst_connector_list.list, list) {
  2027. if (con_to_remove->conn == connector) {
  2028. list_del(&con_to_remove->list);
  2029. kfree(con_to_remove);
  2030. }
  2031. }
  2032. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  2033. mutex_unlock(&dp->session_lock);
  2034. return rc;
  2035. }
  2036. static int dp_display_mst_get_connector_info(struct dp_display *dp_display,
  2037. struct drm_connector *connector,
  2038. struct dp_mst_connector *mst_conn)
  2039. {
  2040. struct dp_display_private *dp;
  2041. struct dp_mst_connector *conn, *temp_conn;
  2042. if (!connector || !mst_conn) {
  2043. DP_ERR("invalid input\n");
  2044. return -EINVAL;
  2045. }
  2046. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2047. mutex_lock(&dp->session_lock);
  2048. if (!dp->mst.drm_registered) {
  2049. DP_DEBUG("drm mst not registered\n");
  2050. mutex_unlock(&dp->session_lock);
  2051. return -EPERM;
  2052. }
  2053. mutex_lock(&dp->debug->dp_mst_connector_list.lock);
  2054. list_for_each_entry_safe(conn, temp_conn,
  2055. &dp->debug->dp_mst_connector_list.list, list) {
  2056. if (conn->con_id == connector->base.id)
  2057. memcpy(mst_conn, conn, sizeof(*mst_conn));
  2058. }
  2059. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  2060. mutex_unlock(&dp->session_lock);
  2061. return 0;
  2062. }
  2063. static int dp_display_mst_connector_update_edid(struct dp_display *dp_display,
  2064. struct drm_connector *connector,
  2065. struct edid *edid)
  2066. {
  2067. int rc = 0;
  2068. struct sde_connector *sde_conn;
  2069. struct dp_panel *dp_panel;
  2070. struct dp_display_private *dp;
  2071. if (!dp_display || !connector || !edid) {
  2072. DP_ERR("invalid input\n");
  2073. return -EINVAL;
  2074. }
  2075. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2076. if (!dp->mst.drm_registered) {
  2077. DP_DEBUG("drm mst not registered\n");
  2078. return -EPERM;
  2079. }
  2080. sde_conn = to_sde_connector(connector);
  2081. if (!sde_conn->drv_panel) {
  2082. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2083. return -EINVAL;
  2084. }
  2085. dp_panel = sde_conn->drv_panel;
  2086. rc = dp_panel->update_edid(dp_panel, edid);
  2087. DP_MST_DEBUG("dp mst connector:%d edid updated. mode_cnt:%d\n",
  2088. connector->base.id, rc);
  2089. return rc;
  2090. }
  2091. static int dp_display_update_pps(struct dp_display *dp_display,
  2092. struct drm_connector *connector, char *pps_cmd)
  2093. {
  2094. struct sde_connector *sde_conn;
  2095. struct dp_panel *dp_panel;
  2096. struct dp_display_private *dp;
  2097. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2098. sde_conn = to_sde_connector(connector);
  2099. if (!sde_conn->drv_panel) {
  2100. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2101. return -EINVAL;
  2102. }
  2103. dp_panel = sde_conn->drv_panel;
  2104. dp_panel->update_pps(dp_panel, pps_cmd);
  2105. return 0;
  2106. }
  2107. static int dp_display_mst_connector_update_link_info(
  2108. struct dp_display *dp_display,
  2109. struct drm_connector *connector)
  2110. {
  2111. int rc = 0;
  2112. struct sde_connector *sde_conn;
  2113. struct dp_panel *dp_panel;
  2114. struct dp_display_private *dp;
  2115. if (!dp_display || !connector) {
  2116. DP_ERR("invalid input\n");
  2117. return -EINVAL;
  2118. }
  2119. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2120. if (!dp->mst.drm_registered) {
  2121. DP_DEBUG("drm mst not registered\n");
  2122. return -EPERM;
  2123. }
  2124. sde_conn = to_sde_connector(connector);
  2125. if (!sde_conn->drv_panel) {
  2126. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2127. return -EINVAL;
  2128. }
  2129. dp_panel = sde_conn->drv_panel;
  2130. memcpy(dp_panel->dpcd, dp->panel->dpcd,
  2131. DP_RECEIVER_CAP_SIZE + 1);
  2132. memcpy(dp_panel->dsc_dpcd, dp->panel->dsc_dpcd,
  2133. DP_RECEIVER_DSC_CAP_SIZE + 1);
  2134. memcpy(&dp_panel->link_info, &dp->panel->link_info,
  2135. sizeof(dp_panel->link_info));
  2136. DP_MST_DEBUG("dp mst connector:%d link info updated\n",
  2137. connector->base.id);
  2138. return rc;
  2139. }
  2140. static int dp_display_mst_get_fixed_topology_port(
  2141. struct dp_display *dp_display,
  2142. u32 strm_id, u32 *port_num)
  2143. {
  2144. struct dp_display_private *dp;
  2145. u32 port;
  2146. if (!dp_display) {
  2147. DP_ERR("invalid input\n");
  2148. return -EINVAL;
  2149. }
  2150. if (strm_id >= DP_STREAM_MAX) {
  2151. DP_ERR("invalid stream id:%d\n", strm_id);
  2152. return -EINVAL;
  2153. }
  2154. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2155. port = dp->parser->mst_fixed_port[strm_id];
  2156. if (!port || port > 255)
  2157. return -ENOENT;
  2158. if (port_num)
  2159. *port_num = port;
  2160. return 0;
  2161. }
  2162. static int dp_display_get_mst_caps(struct dp_display *dp_display,
  2163. struct dp_mst_caps *mst_caps)
  2164. {
  2165. int rc = 0;
  2166. struct dp_display_private *dp;
  2167. if (!dp_display || !mst_caps) {
  2168. DP_ERR("invalid input\n");
  2169. return -EINVAL;
  2170. }
  2171. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2172. mst_caps->has_mst = dp->parser->has_mst;
  2173. mst_caps->max_streams_supported = (mst_caps->has_mst) ? 2 : 0;
  2174. mst_caps->max_dpcd_transaction_bytes = (mst_caps->has_mst) ? 16 : 0;
  2175. mst_caps->drm_aux = dp->aux->drm_aux;
  2176. return rc;
  2177. }
  2178. static void dp_display_wakeup_phy_layer(struct dp_display *dp_display,
  2179. bool wakeup)
  2180. {
  2181. struct dp_display_private *dp;
  2182. struct dp_hpd *hpd;
  2183. if (!dp_display) {
  2184. DP_ERR("invalid input\n");
  2185. return;
  2186. }
  2187. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2188. if (!dp->mst.drm_registered) {
  2189. DP_DEBUG("drm mst not registered\n");
  2190. return;
  2191. }
  2192. hpd = dp->hpd;
  2193. if (hpd && hpd->wakeup_phy)
  2194. hpd->wakeup_phy(hpd, wakeup);
  2195. }
  2196. static int dp_display_probe(struct platform_device *pdev)
  2197. {
  2198. int rc = 0;
  2199. struct dp_display_private *dp;
  2200. if (!pdev || !pdev->dev.of_node) {
  2201. DP_ERR("pdev not found\n");
  2202. rc = -ENODEV;
  2203. goto bail;
  2204. }
  2205. dp = devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL);
  2206. if (!dp) {
  2207. rc = -ENOMEM;
  2208. goto bail;
  2209. }
  2210. init_completion(&dp->notification_comp);
  2211. dp->pdev = pdev;
  2212. dp->name = "drm_dp";
  2213. memset(&dp->mst, 0, sizeof(dp->mst));
  2214. rc = dp_display_init_aux_switch(dp);
  2215. if (rc) {
  2216. rc = -EPROBE_DEFER;
  2217. goto error;
  2218. }
  2219. rc = dp_display_create_workqueue(dp);
  2220. if (rc) {
  2221. DP_ERR("Failed to create workqueue\n");
  2222. goto error;
  2223. }
  2224. platform_set_drvdata(pdev, dp);
  2225. g_dp_display = &dp->dp_display;
  2226. g_dp_display->enable = dp_display_enable;
  2227. g_dp_display->post_enable = dp_display_post_enable;
  2228. g_dp_display->pre_disable = dp_display_pre_disable;
  2229. g_dp_display->disable = dp_display_disable;
  2230. g_dp_display->set_mode = dp_display_set_mode;
  2231. g_dp_display->validate_mode = dp_display_validate_mode;
  2232. g_dp_display->get_modes = dp_display_get_modes;
  2233. g_dp_display->prepare = dp_display_prepare;
  2234. g_dp_display->unprepare = dp_display_unprepare;
  2235. g_dp_display->request_irq = dp_request_irq;
  2236. g_dp_display->get_debug = dp_get_debug;
  2237. g_dp_display->post_open = NULL;
  2238. g_dp_display->post_init = dp_display_post_init;
  2239. g_dp_display->config_hdr = dp_display_config_hdr;
  2240. g_dp_display->mst_install = dp_display_mst_install;
  2241. g_dp_display->mst_uninstall = dp_display_mst_uninstall;
  2242. g_dp_display->mst_connector_install = dp_display_mst_connector_install;
  2243. g_dp_display->mst_connector_uninstall =
  2244. dp_display_mst_connector_uninstall;
  2245. g_dp_display->mst_connector_update_edid =
  2246. dp_display_mst_connector_update_edid;
  2247. g_dp_display->mst_connector_update_link_info =
  2248. dp_display_mst_connector_update_link_info;
  2249. g_dp_display->get_mst_caps = dp_display_get_mst_caps;
  2250. g_dp_display->set_stream_info = dp_display_set_stream_info;
  2251. g_dp_display->update_pps = dp_display_update_pps;
  2252. g_dp_display->convert_to_dp_mode = dp_display_convert_to_dp_mode;
  2253. g_dp_display->mst_get_connector_info =
  2254. dp_display_mst_get_connector_info;
  2255. g_dp_display->mst_get_fixed_topology_port =
  2256. dp_display_mst_get_fixed_topology_port;
  2257. g_dp_display->wakeup_phy_layer =
  2258. dp_display_wakeup_phy_layer;
  2259. g_dp_display->set_colorspace = dp_display_setup_colospace;
  2260. rc = component_add(&pdev->dev, &dp_display_comp_ops);
  2261. if (rc) {
  2262. DP_ERR("component add failed, rc=%d\n", rc);
  2263. goto error;
  2264. }
  2265. return 0;
  2266. error:
  2267. devm_kfree(&pdev->dev, dp);
  2268. bail:
  2269. return rc;
  2270. }
  2271. int dp_display_get_displays(void **displays, int count)
  2272. {
  2273. if (!displays) {
  2274. DP_ERR("invalid data\n");
  2275. return -EINVAL;
  2276. }
  2277. if (count != 1) {
  2278. DP_ERR("invalid number of displays\n");
  2279. return -EINVAL;
  2280. }
  2281. displays[0] = g_dp_display;
  2282. return count;
  2283. }
  2284. int dp_display_get_num_of_displays(void)
  2285. {
  2286. if (!g_dp_display)
  2287. return 0;
  2288. return 1;
  2289. }
  2290. int dp_display_get_num_of_streams(void)
  2291. {
  2292. return DP_STREAM_MAX;
  2293. }
  2294. static void dp_display_set_mst_state(void *dp_display,
  2295. enum dp_drv_state mst_state)
  2296. {
  2297. struct dp_display_private *dp;
  2298. if (!g_dp_display) {
  2299. DP_DEBUG("dp display not initialized\n");
  2300. return;
  2301. }
  2302. dp = container_of(g_dp_display, struct dp_display_private, dp_display);
  2303. if (dp->mst.mst_active && dp->mst.cbs.set_drv_state)
  2304. dp->mst.cbs.set_drv_state(g_dp_display, mst_state);
  2305. }
  2306. static int dp_display_remove(struct platform_device *pdev)
  2307. {
  2308. struct dp_display_private *dp;
  2309. if (!pdev)
  2310. return -EINVAL;
  2311. dp = platform_get_drvdata(pdev);
  2312. dp_display_deinit_sub_modules(dp);
  2313. if (dp->wq)
  2314. destroy_workqueue(dp->wq);
  2315. platform_set_drvdata(pdev, NULL);
  2316. devm_kfree(&pdev->dev, dp);
  2317. return 0;
  2318. }
  2319. static int dp_pm_prepare(struct device *dev)
  2320. {
  2321. struct dp_display_private *dp = container_of(g_dp_display,
  2322. struct dp_display_private, dp_display);
  2323. dp_display_set_mst_state(g_dp_display, PM_SUSPEND);
  2324. dp_display_state_add(DP_STATE_SUSPENDED);
  2325. return 0;
  2326. }
  2327. static void dp_pm_complete(struct device *dev)
  2328. {
  2329. struct dp_display_private *dp = container_of(g_dp_display,
  2330. struct dp_display_private, dp_display);
  2331. dp_display_set_mst_state(g_dp_display, PM_DEFAULT);
  2332. dp_display_state_remove(DP_STATE_SUSPENDED);
  2333. }
  2334. static const struct dev_pm_ops dp_pm_ops = {
  2335. .prepare = dp_pm_prepare,
  2336. .complete = dp_pm_complete,
  2337. };
  2338. static struct platform_driver dp_display_driver = {
  2339. .probe = dp_display_probe,
  2340. .remove = dp_display_remove,
  2341. .driver = {
  2342. .name = "msm-dp-display",
  2343. .of_match_table = dp_dt_match,
  2344. .suppress_bind_attrs = true,
  2345. .pm = &dp_pm_ops,
  2346. },
  2347. };
  2348. static int __init dp_display_init(void)
  2349. {
  2350. int ret;
  2351. ret = platform_driver_register(&dp_display_driver);
  2352. if (ret) {
  2353. DP_ERR("driver register failed\n");
  2354. return ret;
  2355. }
  2356. return ret;
  2357. }
  2358. late_initcall(dp_display_init);
  2359. static void __exit dp_display_cleanup(void)
  2360. {
  2361. platform_driver_unregister(&dp_display_driver);
  2362. }
  2363. module_exit(dp_display_cleanup);