dp_display.c 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919
  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->mst.mst_active)
  746. rc = dp_display_send_hpd_notification(dp);
  747. mutex_lock(&dp->session_lock);
  748. if (!dp->active_stream_cnt)
  749. dp->ctrl->off(dp->ctrl);
  750. mutex_unlock(&dp->session_lock);
  751. dp->panel->video_test = false;
  752. return rc;
  753. }
  754. static int dp_display_usbpd_configure_cb(struct device *dev)
  755. {
  756. int rc = 0;
  757. struct dp_display_private *dp;
  758. if (!dev) {
  759. DP_ERR("invalid dev\n");
  760. rc = -EINVAL;
  761. goto end;
  762. }
  763. dp = dev_get_drvdata(dev);
  764. if (!dp) {
  765. DP_ERR("no driver data found\n");
  766. rc = -ENODEV;
  767. goto end;
  768. }
  769. if (!dp->debug->sim_mode && !dp->parser->no_aux_switch
  770. && !dp->parser->gpio_aux_switch) {
  771. rc = dp->aux->aux_switch(dp->aux, true, dp->hpd->orientation);
  772. if (rc)
  773. goto end;
  774. }
  775. mutex_lock(&dp->session_lock);
  776. dp_display_state_remove(DP_STATE_ABORTED);
  777. dp_display_state_add(DP_STATE_CONFIGURED);
  778. dp_display_host_init(dp);
  779. /* check for hpd high */
  780. if (dp->hpd->hpd_high)
  781. queue_work(dp->wq, &dp->connect_work);
  782. else
  783. dp->process_hpd_connect = true;
  784. mutex_unlock(&dp->session_lock);
  785. end:
  786. return rc;
  787. }
  788. static int dp_display_stream_pre_disable(struct dp_display_private *dp,
  789. struct dp_panel *dp_panel)
  790. {
  791. dp->ctrl->stream_pre_off(dp->ctrl, dp_panel);
  792. return 0;
  793. }
  794. static void dp_display_stream_disable(struct dp_display_private *dp,
  795. struct dp_panel *dp_panel)
  796. {
  797. if (!dp->active_stream_cnt) {
  798. DP_ERR("invalid active_stream_cnt (%d)\n",
  799. dp->active_stream_cnt);
  800. return;
  801. }
  802. DP_DEBUG("stream_id=%d, active_stream_cnt=%d\n",
  803. dp_panel->stream_id, dp->active_stream_cnt);
  804. dp->ctrl->stream_off(dp->ctrl, dp_panel);
  805. dp->active_panels[dp_panel->stream_id] = NULL;
  806. dp->active_stream_cnt--;
  807. }
  808. static void dp_display_clean(struct dp_display_private *dp)
  809. {
  810. int idx;
  811. struct dp_panel *dp_panel;
  812. struct dp_link_hdcp_status *status = &dp->link->hdcp_status;
  813. if (dp_display_is_hdcp_enabled(dp) &&
  814. status->hdcp_state != HDCP_STATE_INACTIVE) {
  815. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  816. if (dp->hdcp.ops->off)
  817. dp->hdcp.ops->off(dp->hdcp.data);
  818. dp_display_update_hdcp_status(dp, true);
  819. }
  820. for (idx = DP_STREAM_0; idx < DP_STREAM_MAX; idx++) {
  821. if (!dp->active_panels[idx])
  822. continue;
  823. dp_panel = dp->active_panels[idx];
  824. if (dp_panel->audio_supported)
  825. dp_panel->audio->off(dp_panel->audio);
  826. dp_display_stream_pre_disable(dp, dp_panel);
  827. dp_display_stream_disable(dp, dp_panel);
  828. dp_panel->deinit(dp_panel, 0);
  829. }
  830. dp_display_state_remove(DP_STATE_ENABLED | DP_STATE_CONNECTED);
  831. dp->ctrl->off(dp->ctrl);
  832. }
  833. static int dp_display_handle_disconnect(struct dp_display_private *dp)
  834. {
  835. int rc;
  836. rc = dp_display_process_hpd_low(dp);
  837. if (rc) {
  838. /* cancel any pending request */
  839. dp->ctrl->abort(dp->ctrl);
  840. dp->aux->abort(dp->aux);
  841. }
  842. mutex_lock(&dp->session_lock);
  843. if (rc && dp_display_state_is(DP_STATE_ENABLED))
  844. dp_display_clean(dp);
  845. dp_display_host_unready(dp);
  846. mutex_unlock(&dp->session_lock);
  847. return rc;
  848. }
  849. static void dp_display_disconnect_sync(struct dp_display_private *dp)
  850. {
  851. /* cancel any pending request */
  852. dp_display_state_add(DP_STATE_ABORTED);
  853. dp->ctrl->abort(dp->ctrl);
  854. dp->aux->abort(dp->aux);
  855. /* wait for idle state */
  856. cancel_work_sync(&dp->connect_work);
  857. cancel_work_sync(&dp->attention_work);
  858. flush_workqueue(dp->wq);
  859. dp_display_handle_disconnect(dp);
  860. }
  861. static int dp_display_usbpd_disconnect_cb(struct device *dev)
  862. {
  863. int rc = 0;
  864. struct dp_display_private *dp;
  865. if (!dev) {
  866. DP_ERR("invalid dev\n");
  867. rc = -EINVAL;
  868. goto end;
  869. }
  870. dp = dev_get_drvdata(dev);
  871. if (!dp) {
  872. DP_ERR("no driver data found\n");
  873. rc = -ENODEV;
  874. goto end;
  875. }
  876. dp_display_state_remove(DP_STATE_CONFIGURED);
  877. mutex_lock(&dp->session_lock);
  878. if (dp->debug->psm_enabled && dp_display_state_is(DP_STATE_READY))
  879. dp->link->psm_config(dp->link, &dp->panel->link_info, true);
  880. mutex_unlock(&dp->session_lock);
  881. dp_display_disconnect_sync(dp);
  882. mutex_lock(&dp->session_lock);
  883. dp_display_host_deinit(dp);
  884. mutex_unlock(&dp->session_lock);
  885. if (!dp->debug->sim_mode && !dp->parser->no_aux_switch
  886. && !dp->parser->gpio_aux_switch)
  887. dp->aux->aux_switch(dp->aux, false, ORIENTATION_NONE);
  888. end:
  889. return rc;
  890. }
  891. static int dp_display_stream_enable(struct dp_display_private *dp,
  892. struct dp_panel *dp_panel)
  893. {
  894. int rc = 0;
  895. rc = dp->ctrl->stream_on(dp->ctrl, dp_panel);
  896. if (dp->debug->tpg_state)
  897. dp_panel->tpg_config(dp_panel, true);
  898. if (!rc) {
  899. dp->active_panels[dp_panel->stream_id] = dp_panel;
  900. dp->active_stream_cnt++;
  901. }
  902. DP_DEBUG("dp active_stream_cnt:%d\n", dp->active_stream_cnt);
  903. return rc;
  904. }
  905. static void dp_display_mst_attention(struct dp_display_private *dp)
  906. {
  907. struct dp_mst_hpd_info hpd_irq = {0};
  908. if (dp->mst.mst_active && dp->mst.cbs.hpd_irq) {
  909. hpd_irq.mst_hpd_sim = dp->debug->mst_hpd_sim;
  910. hpd_irq.mst_sim_add_con = dp->debug->mst_sim_add_con;
  911. hpd_irq.mst_sim_remove_con = dp->debug->mst_sim_remove_con;
  912. hpd_irq.mst_sim_remove_con_id = dp->debug->mst_sim_remove_con_id;
  913. hpd_irq.edid = dp->debug->get_edid(dp->debug);
  914. dp->mst.cbs.hpd_irq(&dp->dp_display, &hpd_irq);
  915. dp->debug->mst_hpd_sim = false;
  916. dp->debug->mst_sim_add_con = false;
  917. dp->debug->mst_sim_remove_con = false;
  918. }
  919. DP_MST_DEBUG("mst_attention_work. mst_active:%d\n", dp->mst.mst_active);
  920. }
  921. static void dp_display_attention_work(struct work_struct *work)
  922. {
  923. struct dp_display_private *dp = container_of(work,
  924. struct dp_display_private, attention_work);
  925. mutex_lock(&dp->session_lock);
  926. if (dp->debug->mst_hpd_sim || !dp_display_state_is(DP_STATE_READY)) {
  927. mutex_unlock(&dp->session_lock);
  928. goto mst_attention;
  929. }
  930. if (dp->link->process_request(dp->link)) {
  931. mutex_unlock(&dp->session_lock);
  932. goto cp_irq;
  933. }
  934. mutex_unlock(&dp->session_lock);
  935. if (dp->link->sink_request & DS_PORT_STATUS_CHANGED) {
  936. if (dp_display_is_sink_count_zero(dp)) {
  937. dp_display_handle_disconnect(dp);
  938. } else {
  939. if (!dp->mst.mst_active)
  940. queue_work(dp->wq, &dp->connect_work);
  941. }
  942. goto mst_attention;
  943. }
  944. if (dp->link->sink_request & DP_TEST_LINK_VIDEO_PATTERN) {
  945. dp_display_handle_disconnect(dp);
  946. dp->panel->video_test = true;
  947. queue_work(dp->wq, &dp->connect_work);
  948. goto mst_attention;
  949. }
  950. if (dp->link->sink_request & DP_TEST_LINK_PHY_TEST_PATTERN) {
  951. dp->ctrl->process_phy_test_request(dp->ctrl);
  952. goto mst_attention;
  953. }
  954. if (dp->link->sink_request & DP_TEST_LINK_TRAINING) {
  955. dp->link->send_test_response(dp->link);
  956. dp->ctrl->link_maintenance(dp->ctrl);
  957. goto mst_attention;
  958. }
  959. if (dp->link->sink_request & DP_LINK_STATUS_UPDATED)
  960. dp->ctrl->link_maintenance(dp->ctrl);
  961. cp_irq:
  962. if (dp_display_is_hdcp_enabled(dp) && dp->hdcp.ops->cp_irq)
  963. dp->hdcp.ops->cp_irq(dp->hdcp.data);
  964. mst_attention:
  965. dp_display_mst_attention(dp);
  966. }
  967. static int dp_display_usbpd_attention_cb(struct device *dev)
  968. {
  969. struct dp_display_private *dp;
  970. if (!dev) {
  971. DP_ERR("invalid dev\n");
  972. return -EINVAL;
  973. }
  974. dp = dev_get_drvdata(dev);
  975. if (!dp) {
  976. DP_ERR("no driver data found\n");
  977. return -ENODEV;
  978. }
  979. DP_DEBUG("hpd_irq:%d, hpd_high:%d, power_on:%d, is_connected:%d\n",
  980. dp->hpd->hpd_irq, dp->hpd->hpd_high,
  981. !!dp_display_state_is(DP_STATE_ENABLED),
  982. !!dp_display_state_is(DP_STATE_CONNECTED));
  983. if (!dp->hpd->hpd_high) {
  984. dp_display_disconnect_sync(dp);
  985. } else if ((dp->hpd->hpd_irq && dp_display_state_is(DP_STATE_READY)) ||
  986. dp->debug->mst_hpd_sim) {
  987. queue_work(dp->wq, &dp->attention_work);
  988. } else if (dp->process_hpd_connect ||
  989. !dp_display_state_is(DP_STATE_CONNECTED)) {
  990. dp_display_state_remove(DP_STATE_ABORTED);
  991. queue_work(dp->wq, &dp->connect_work);
  992. } else {
  993. DP_DEBUG("ignored\n");
  994. }
  995. return 0;
  996. }
  997. static void dp_display_connect_work(struct work_struct *work)
  998. {
  999. int rc = 0;
  1000. struct dp_display_private *dp = container_of(work,
  1001. struct dp_display_private, connect_work);
  1002. if (dp_display_state_is(DP_STATE_ABORTED)) {
  1003. DP_WARN("HPD off requested\n");
  1004. return;
  1005. }
  1006. if (!dp->hpd->hpd_high) {
  1007. DP_WARN("Sink disconnected\n");
  1008. return;
  1009. }
  1010. rc = dp_display_process_hpd_high(dp);
  1011. if (!rc && dp->panel->video_test)
  1012. dp->link->send_test_response(dp->link);
  1013. }
  1014. static int dp_display_usb_notifier(struct notifier_block *nb,
  1015. unsigned long event, void *ptr)
  1016. {
  1017. struct extcon_dev *edev = ptr;
  1018. struct dp_display_private *dp = container_of(nb,
  1019. struct dp_display_private, usb_nb);
  1020. if (!edev)
  1021. goto end;
  1022. if (!event && dp->debug->sim_mode) {
  1023. dp_display_disconnect_sync(dp);
  1024. dp->debug->abort(dp->debug);
  1025. }
  1026. end:
  1027. return NOTIFY_DONE;
  1028. }
  1029. static int dp_display_get_usb_extcon(struct dp_display_private *dp)
  1030. {
  1031. struct extcon_dev *edev;
  1032. int rc;
  1033. edev = extcon_get_edev_by_phandle(&dp->pdev->dev, 0);
  1034. if (IS_ERR(edev))
  1035. return PTR_ERR(edev);
  1036. dp->usb_nb.notifier_call = dp_display_usb_notifier;
  1037. dp->usb_nb.priority = 2;
  1038. rc = extcon_register_notifier(edev, EXTCON_USB, &dp->usb_nb);
  1039. if (rc)
  1040. DP_ERR("failed to register for usb event: %d\n", rc);
  1041. return rc;
  1042. }
  1043. static void dp_display_deinit_sub_modules(struct dp_display_private *dp)
  1044. {
  1045. dp_audio_put(dp->panel->audio);
  1046. dp_ctrl_put(dp->ctrl);
  1047. dp_link_put(dp->link);
  1048. dp_panel_put(dp->panel);
  1049. dp_aux_put(dp->aux);
  1050. dp_power_put(dp->power);
  1051. dp_catalog_put(dp->catalog);
  1052. dp_parser_put(dp->parser);
  1053. dp_hpd_put(dp->hpd);
  1054. mutex_destroy(&dp->session_lock);
  1055. dp_debug_put(dp->debug);
  1056. }
  1057. static int dp_init_sub_modules(struct dp_display_private *dp)
  1058. {
  1059. int rc = 0;
  1060. bool hdcp_disabled;
  1061. struct device *dev = &dp->pdev->dev;
  1062. struct dp_hpd_cb *cb = &dp->hpd_cb;
  1063. struct dp_ctrl_in ctrl_in = {
  1064. .dev = dev,
  1065. };
  1066. struct dp_panel_in panel_in = {
  1067. .dev = dev,
  1068. };
  1069. struct dp_debug_in debug_in = {
  1070. .dev = dev,
  1071. };
  1072. mutex_init(&dp->session_lock);
  1073. dp->parser = dp_parser_get(dp->pdev);
  1074. if (IS_ERR(dp->parser)) {
  1075. rc = PTR_ERR(dp->parser);
  1076. DP_ERR("failed to initialize parser, rc = %d\n", rc);
  1077. dp->parser = NULL;
  1078. goto error;
  1079. }
  1080. rc = dp->parser->parse(dp->parser);
  1081. if (rc) {
  1082. DP_ERR("device tree parsing failed\n");
  1083. goto error_catalog;
  1084. }
  1085. g_dp_display->is_mst_supported = dp->parser->has_mst;
  1086. dp->catalog = dp_catalog_get(dev, dp->parser);
  1087. if (IS_ERR(dp->catalog)) {
  1088. rc = PTR_ERR(dp->catalog);
  1089. DP_ERR("failed to initialize catalog, rc = %d\n", rc);
  1090. dp->catalog = NULL;
  1091. goto error_catalog;
  1092. }
  1093. dp->power = dp_power_get(dp->parser);
  1094. if (IS_ERR(dp->power)) {
  1095. rc = PTR_ERR(dp->power);
  1096. DP_ERR("failed to initialize power, rc = %d\n", rc);
  1097. dp->power = NULL;
  1098. goto error_power;
  1099. }
  1100. rc = dp->power->power_client_init(dp->power, &dp->priv->phandle,
  1101. dp->dp_display.drm_dev);
  1102. if (rc) {
  1103. DP_ERR("Power client create failed\n");
  1104. goto error_aux;
  1105. }
  1106. dp->aux = dp_aux_get(dev, &dp->catalog->aux, dp->parser,
  1107. dp->aux_switch_node);
  1108. if (IS_ERR(dp->aux)) {
  1109. rc = PTR_ERR(dp->aux);
  1110. DP_ERR("failed to initialize aux, rc = %d\n", rc);
  1111. dp->aux = NULL;
  1112. goto error_aux;
  1113. }
  1114. rc = dp->aux->drm_aux_register(dp->aux);
  1115. if (rc) {
  1116. DP_ERR("DRM DP AUX register failed\n");
  1117. goto error_link;
  1118. }
  1119. dp->link = dp_link_get(dev, dp->aux);
  1120. if (IS_ERR(dp->link)) {
  1121. rc = PTR_ERR(dp->link);
  1122. DP_ERR("failed to initialize link, rc = %d\n", rc);
  1123. dp->link = NULL;
  1124. goto error_link;
  1125. }
  1126. panel_in.aux = dp->aux;
  1127. panel_in.catalog = &dp->catalog->panel;
  1128. panel_in.link = dp->link;
  1129. panel_in.connector = dp->dp_display.base_connector;
  1130. panel_in.base_panel = NULL;
  1131. panel_in.parser = dp->parser;
  1132. dp->panel = dp_panel_get(&panel_in);
  1133. if (IS_ERR(dp->panel)) {
  1134. rc = PTR_ERR(dp->panel);
  1135. DP_ERR("failed to initialize panel, rc = %d\n", rc);
  1136. dp->panel = NULL;
  1137. goto error_panel;
  1138. }
  1139. ctrl_in.link = dp->link;
  1140. ctrl_in.panel = dp->panel;
  1141. ctrl_in.aux = dp->aux;
  1142. ctrl_in.power = dp->power;
  1143. ctrl_in.catalog = &dp->catalog->ctrl;
  1144. ctrl_in.parser = dp->parser;
  1145. dp->ctrl = dp_ctrl_get(&ctrl_in);
  1146. if (IS_ERR(dp->ctrl)) {
  1147. rc = PTR_ERR(dp->ctrl);
  1148. DP_ERR("failed to initialize ctrl, rc = %d\n", rc);
  1149. dp->ctrl = NULL;
  1150. goto error_ctrl;
  1151. }
  1152. dp->panel->audio = dp_audio_get(dp->pdev, dp->panel,
  1153. &dp->catalog->audio);
  1154. if (IS_ERR(dp->panel->audio)) {
  1155. rc = PTR_ERR(dp->panel->audio);
  1156. DP_ERR("failed to initialize audio, rc = %d\n", rc);
  1157. dp->panel->audio = NULL;
  1158. goto error_audio;
  1159. }
  1160. memset(&dp->mst, 0, sizeof(dp->mst));
  1161. dp->active_stream_cnt = 0;
  1162. cb->configure = dp_display_usbpd_configure_cb;
  1163. cb->disconnect = dp_display_usbpd_disconnect_cb;
  1164. cb->attention = dp_display_usbpd_attention_cb;
  1165. dp->hpd = dp_hpd_get(dev, dp->parser, &dp->catalog->hpd, cb);
  1166. if (IS_ERR(dp->hpd)) {
  1167. rc = PTR_ERR(dp->hpd);
  1168. DP_ERR("failed to initialize hpd, rc = %d\n", rc);
  1169. dp->hpd = NULL;
  1170. goto error_hpd;
  1171. }
  1172. hdcp_disabled = !!dp_display_initialize_hdcp(dp);
  1173. debug_in.panel = dp->panel;
  1174. debug_in.hpd = dp->hpd;
  1175. debug_in.link = dp->link;
  1176. debug_in.aux = dp->aux;
  1177. debug_in.connector = &dp->dp_display.base_connector;
  1178. debug_in.catalog = dp->catalog;
  1179. debug_in.parser = dp->parser;
  1180. debug_in.ctrl = dp->ctrl;
  1181. dp->debug = dp_debug_get(&debug_in);
  1182. if (IS_ERR(dp->debug)) {
  1183. rc = PTR_ERR(dp->debug);
  1184. DP_ERR("failed to initialize debug, rc = %d\n", rc);
  1185. dp->debug = NULL;
  1186. goto error_debug;
  1187. }
  1188. dp->cached_connector_status = connector_status_disconnected;
  1189. dp->tot_dsc_blks_in_use = 0;
  1190. dp->debug->hdcp_disabled = hdcp_disabled;
  1191. dp_display_update_hdcp_status(dp, true);
  1192. dp_display_get_usb_extcon(dp);
  1193. rc = dp->hpd->register_hpd(dp->hpd);
  1194. if (rc) {
  1195. DP_ERR("failed register hpd\n");
  1196. goto error_hpd_reg;
  1197. }
  1198. return rc;
  1199. error_hpd_reg:
  1200. dp_debug_put(dp->debug);
  1201. error_debug:
  1202. dp_hpd_put(dp->hpd);
  1203. error_hpd:
  1204. dp_audio_put(dp->panel->audio);
  1205. error_audio:
  1206. dp_ctrl_put(dp->ctrl);
  1207. error_ctrl:
  1208. dp_panel_put(dp->panel);
  1209. error_panel:
  1210. dp_link_put(dp->link);
  1211. error_link:
  1212. dp_aux_put(dp->aux);
  1213. error_aux:
  1214. dp_power_put(dp->power);
  1215. error_power:
  1216. dp_catalog_put(dp->catalog);
  1217. error_catalog:
  1218. dp_parser_put(dp->parser);
  1219. error:
  1220. mutex_destroy(&dp->session_lock);
  1221. return rc;
  1222. }
  1223. static int dp_display_post_init(struct dp_display *dp_display)
  1224. {
  1225. int rc = 0;
  1226. struct dp_display_private *dp;
  1227. if (!dp_display) {
  1228. DP_ERR("invalid input\n");
  1229. rc = -EINVAL;
  1230. goto end;
  1231. }
  1232. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1233. if (IS_ERR_OR_NULL(dp)) {
  1234. DP_ERR("invalid params\n");
  1235. rc = -EINVAL;
  1236. goto end;
  1237. }
  1238. rc = dp_init_sub_modules(dp);
  1239. if (rc)
  1240. goto end;
  1241. dp_display->post_init = NULL;
  1242. end:
  1243. DP_DEBUG("%s\n", rc ? "failed" : "success");
  1244. return rc;
  1245. }
  1246. static int dp_display_set_mode(struct dp_display *dp_display, void *panel,
  1247. struct dp_display_mode *mode)
  1248. {
  1249. const u32 num_components = 3, default_bpp = 24;
  1250. struct dp_display_private *dp;
  1251. struct dp_panel *dp_panel;
  1252. if (!dp_display || !panel) {
  1253. DP_ERR("invalid input\n");
  1254. return -EINVAL;
  1255. }
  1256. dp_panel = panel;
  1257. if (!dp_panel->connector) {
  1258. DP_ERR("invalid connector input\n");
  1259. return -EINVAL;
  1260. }
  1261. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1262. mutex_lock(&dp->session_lock);
  1263. mode->timing.bpp =
  1264. dp_panel->connector->display_info.bpc * num_components;
  1265. if (!mode->timing.bpp)
  1266. mode->timing.bpp = default_bpp;
  1267. mode->timing.bpp = dp->panel->get_mode_bpp(dp->panel,
  1268. mode->timing.bpp, mode->timing.pixel_clk_khz);
  1269. dp_panel->pinfo = mode->timing;
  1270. mutex_unlock(&dp->session_lock);
  1271. return 0;
  1272. }
  1273. static int dp_display_prepare(struct dp_display *dp_display, void *panel)
  1274. {
  1275. struct dp_display_private *dp;
  1276. struct dp_panel *dp_panel;
  1277. int rc = 0;
  1278. if (!dp_display || !panel) {
  1279. DP_ERR("invalid input\n");
  1280. return -EINVAL;
  1281. }
  1282. dp_panel = panel;
  1283. if (!dp_panel->connector) {
  1284. DP_ERR("invalid connector input\n");
  1285. return -EINVAL;
  1286. }
  1287. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1288. mutex_lock(&dp->session_lock);
  1289. if (dp_display_state_is(DP_STATE_ABORTED | DP_STATE_ENABLED))
  1290. goto end;
  1291. if (!dp_display_is_ready(dp))
  1292. goto end;
  1293. /* For supporting DP_PANEL_SRC_INITIATED_POWER_DOWN case */
  1294. dp_display_host_init(dp);
  1295. dp_display_host_ready(dp);
  1296. if (dp->debug->psm_enabled) {
  1297. dp->link->psm_config(dp->link, &dp->panel->link_info, false);
  1298. dp->debug->psm_enabled = false;
  1299. }
  1300. /*
  1301. * Execute the dp controller power on in shallow mode here.
  1302. * In normal cases, controller should have been powered on
  1303. * by now. In some cases like suspend/resume or framework
  1304. * reboot, we end up here without a powered on controller.
  1305. * Cable may have been removed in suspended state. In that
  1306. * case, link training is bound to fail on system resume.
  1307. * So, we execute in shallow mode here to do only minimal
  1308. * and required things.
  1309. */
  1310. rc = dp->ctrl->on(dp->ctrl, dp->mst.mst_active, dp_panel->fec_en, true);
  1311. if (rc)
  1312. goto end;
  1313. end:
  1314. mutex_unlock(&dp->session_lock);
  1315. return 0;
  1316. }
  1317. static int dp_display_set_stream_info(struct dp_display *dp_display,
  1318. void *panel, u32 strm_id, u32 start_slot,
  1319. u32 num_slots, u32 pbn, int vcpi)
  1320. {
  1321. int rc = 0;
  1322. struct dp_panel *dp_panel;
  1323. struct dp_display_private *dp;
  1324. const int max_slots = 64;
  1325. if (!dp_display) {
  1326. DP_ERR("invalid input\n");
  1327. return -EINVAL;
  1328. }
  1329. if (strm_id >= DP_STREAM_MAX) {
  1330. DP_ERR("invalid stream id:%d\n", strm_id);
  1331. return -EINVAL;
  1332. }
  1333. if (start_slot + num_slots > max_slots) {
  1334. DP_ERR("invalid channel info received. start:%d, slots:%d\n",
  1335. start_slot, num_slots);
  1336. return -EINVAL;
  1337. }
  1338. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1339. mutex_lock(&dp->session_lock);
  1340. dp->ctrl->set_mst_channel_info(dp->ctrl, strm_id,
  1341. start_slot, num_slots);
  1342. if (panel) {
  1343. dp_panel = panel;
  1344. dp_panel->set_stream_info(dp_panel, strm_id, start_slot,
  1345. num_slots, pbn, vcpi);
  1346. }
  1347. mutex_unlock(&dp->session_lock);
  1348. return rc;
  1349. }
  1350. static void dp_display_update_dsc_resources(struct dp_display_private *dp,
  1351. struct dp_panel *panel, bool enable)
  1352. {
  1353. u32 dsc_blk_cnt = 0;
  1354. if (panel->pinfo.comp_info.comp_type == MSM_DISPLAY_COMPRESSION_DSC &&
  1355. panel->pinfo.comp_info.comp_ratio) {
  1356. dsc_blk_cnt = panel->pinfo.h_active /
  1357. dp->parser->max_dp_dsc_input_width_pixs;
  1358. if (panel->pinfo.h_active %
  1359. dp->parser->max_dp_dsc_input_width_pixs)
  1360. dsc_blk_cnt++;
  1361. }
  1362. if (enable) {
  1363. dp->tot_dsc_blks_in_use += dsc_blk_cnt;
  1364. panel->tot_dsc_blks_in_use += dsc_blk_cnt;
  1365. } else {
  1366. dp->tot_dsc_blks_in_use -= dsc_blk_cnt;
  1367. panel->tot_dsc_blks_in_use -= dsc_blk_cnt;
  1368. }
  1369. }
  1370. static int dp_display_enable(struct dp_display *dp_display, void *panel)
  1371. {
  1372. int rc = 0;
  1373. struct dp_display_private *dp;
  1374. if (!dp_display || !panel) {
  1375. DP_ERR("invalid input\n");
  1376. return -EINVAL;
  1377. }
  1378. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1379. mutex_lock(&dp->session_lock);
  1380. if (!dp_display_state_is(DP_STATE_READY)) {
  1381. dp_display_state_show("[host not ready]");
  1382. goto end;
  1383. }
  1384. if (dp_display_state_is(DP_STATE_ABORTED))
  1385. goto end;
  1386. rc = dp_display_stream_enable(dp, panel);
  1387. if (rc)
  1388. goto end;
  1389. dp_display_update_dsc_resources(dp, panel, true);
  1390. dp_display_state_add(DP_STATE_ENABLED);
  1391. end:
  1392. mutex_unlock(&dp->session_lock);
  1393. return rc;
  1394. }
  1395. static void dp_display_stream_post_enable(struct dp_display_private *dp,
  1396. struct dp_panel *dp_panel)
  1397. {
  1398. dp_panel->spd_config(dp_panel);
  1399. dp_panel->setup_hdr(dp_panel, NULL, false, 0, true);
  1400. }
  1401. static int dp_display_post_enable(struct dp_display *dp_display, void *panel)
  1402. {
  1403. struct dp_display_private *dp;
  1404. struct dp_panel *dp_panel;
  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. dp_panel = panel;
  1411. mutex_lock(&dp->session_lock);
  1412. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  1413. dp_display_state_show("[not enabled]");
  1414. goto end;
  1415. }
  1416. if (dp_display_state_is(DP_STATE_ABORTED))
  1417. goto end;
  1418. if (!dp_display_is_ready(dp) || !dp_display_state_is(DP_STATE_READY)) {
  1419. dp_display_state_show("[not ready]");
  1420. goto end;
  1421. }
  1422. dp_display_stream_post_enable(dp, dp_panel);
  1423. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  1424. queue_delayed_work(dp->wq, &dp->hdcp_cb_work, HZ);
  1425. if (dp_panel->audio_supported) {
  1426. dp_panel->audio->bw_code = dp->link->link_params.bw_code;
  1427. dp_panel->audio->lane_count = dp->link->link_params.lane_count;
  1428. dp_panel->audio->on(dp_panel->audio);
  1429. }
  1430. end:
  1431. dp->aux->state |= DP_STATE_CTRL_POWERED_ON;
  1432. complete_all(&dp->notification_comp);
  1433. mutex_unlock(&dp->session_lock);
  1434. return 0;
  1435. }
  1436. static void dp_display_clear_colorspaces(struct dp_display *dp_display)
  1437. {
  1438. struct drm_connector *connector;
  1439. connector = dp_display->base_connector;
  1440. connector->color_enc_fmt = 0;
  1441. }
  1442. static int dp_display_pre_disable(struct dp_display *dp_display, void *panel)
  1443. {
  1444. struct dp_display_private *dp;
  1445. struct dp_panel *dp_panel = panel;
  1446. struct dp_link_hdcp_status *status;
  1447. int rc = 0;
  1448. size_t i;
  1449. if (!dp_display || !panel) {
  1450. DP_ERR("invalid input\n");
  1451. return -EINVAL;
  1452. }
  1453. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1454. mutex_lock(&dp->session_lock);
  1455. status = &dp->link->hdcp_status;
  1456. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  1457. dp_display_state_show("[not enabled]");
  1458. goto end;
  1459. }
  1460. dp_display_state_add(DP_STATE_HDCP_ABORTED);
  1461. cancel_delayed_work_sync(&dp->hdcp_cb_work);
  1462. if (dp_display_is_hdcp_enabled(dp) &&
  1463. status->hdcp_state != HDCP_STATE_INACTIVE) {
  1464. bool off = true;
  1465. if (dp_display_state_is(DP_STATE_SUSPENDED)) {
  1466. DP_DEBUG("Can't perform HDCP cleanup while suspended. Defer\n");
  1467. dp->hdcp_delayed_off = true;
  1468. goto clean;
  1469. }
  1470. flush_delayed_work(&dp->hdcp_cb_work);
  1471. if (dp->mst.mst_active) {
  1472. dp_display_hdcp_deregister_stream(dp,
  1473. dp_panel->stream_id);
  1474. for (i = DP_STREAM_0; i < DP_STREAM_MAX; i++) {
  1475. if (i != dp_panel->stream_id &&
  1476. dp->active_panels[i]) {
  1477. DP_DEBUG("Streams are still active. Skip disabling HDCP\n");
  1478. off = false;
  1479. }
  1480. }
  1481. }
  1482. if (off) {
  1483. if (dp->hdcp.ops->off)
  1484. dp->hdcp.ops->off(dp->hdcp.data);
  1485. dp_display_update_hdcp_status(dp, true);
  1486. }
  1487. }
  1488. dp_display_clear_colorspaces(dp_display);
  1489. clean:
  1490. if (dp_panel->audio_supported)
  1491. dp_panel->audio->off(dp_panel->audio);
  1492. rc = dp_display_stream_pre_disable(dp, dp_panel);
  1493. end:
  1494. mutex_unlock(&dp->session_lock);
  1495. return 0;
  1496. }
  1497. static int dp_display_disable(struct dp_display *dp_display, void *panel)
  1498. {
  1499. int i;
  1500. struct dp_display_private *dp = NULL;
  1501. struct dp_panel *dp_panel = NULL;
  1502. struct dp_link_hdcp_status *status;
  1503. if (!dp_display || !panel) {
  1504. DP_ERR("invalid input\n");
  1505. return -EINVAL;
  1506. }
  1507. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1508. dp_panel = panel;
  1509. status = &dp->link->hdcp_status;
  1510. mutex_lock(&dp->session_lock);
  1511. if (!dp_display_state_is(DP_STATE_ENABLED)) {
  1512. dp_display_state_show("[not enabled]");
  1513. goto end;
  1514. }
  1515. if (!dp_display_state_is(DP_STATE_READY)) {
  1516. dp_display_state_show("[not ready]");
  1517. goto end;
  1518. }
  1519. dp_display_stream_disable(dp, dp_panel);
  1520. dp_display_update_dsc_resources(dp, dp_panel, false);
  1521. dp_display_state_remove(DP_STATE_HDCP_ABORTED);
  1522. for (i = DP_STREAM_0; i < DP_STREAM_MAX; i++) {
  1523. if (dp->active_panels[i]) {
  1524. if (status->hdcp_state != HDCP_STATE_AUTHENTICATED)
  1525. queue_delayed_work(dp->wq, &dp->hdcp_cb_work,
  1526. HZ/4);
  1527. break;
  1528. }
  1529. }
  1530. end:
  1531. mutex_unlock(&dp->session_lock);
  1532. return 0;
  1533. }
  1534. static int dp_request_irq(struct dp_display *dp_display)
  1535. {
  1536. int rc = 0;
  1537. struct dp_display_private *dp;
  1538. if (!dp_display) {
  1539. DP_ERR("invalid input\n");
  1540. return -EINVAL;
  1541. }
  1542. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1543. dp->irq = irq_of_parse_and_map(dp->pdev->dev.of_node, 0);
  1544. if (dp->irq < 0) {
  1545. rc = dp->irq;
  1546. DP_ERR("failed to get irq: %d\n", rc);
  1547. return rc;
  1548. }
  1549. rc = devm_request_irq(&dp->pdev->dev, dp->irq, dp_display_irq,
  1550. IRQF_TRIGGER_HIGH, "dp_display_isr", dp);
  1551. if (rc < 0) {
  1552. DP_ERR("failed to request IRQ%u: %d\n",
  1553. dp->irq, rc);
  1554. return rc;
  1555. }
  1556. disable_irq(dp->irq);
  1557. return 0;
  1558. }
  1559. static struct dp_debug *dp_get_debug(struct dp_display *dp_display)
  1560. {
  1561. struct dp_display_private *dp;
  1562. if (!dp_display) {
  1563. DP_ERR("invalid input\n");
  1564. return ERR_PTR(-EINVAL);
  1565. }
  1566. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1567. return dp->debug;
  1568. }
  1569. static int dp_display_unprepare(struct dp_display *dp_display, void *panel)
  1570. {
  1571. struct dp_display_private *dp;
  1572. struct dp_panel *dp_panel = panel;
  1573. u32 flags = 0;
  1574. if (!dp_display || !panel) {
  1575. DP_ERR("invalid input\n");
  1576. return -EINVAL;
  1577. }
  1578. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1579. mutex_lock(&dp->session_lock);
  1580. /*
  1581. * Check if the power off sequence was triggered
  1582. * by a source initialated action like framework
  1583. * reboot or suspend-resume but not from normal
  1584. * hot plug.
  1585. */
  1586. if (dp_display_is_ready(dp))
  1587. flags |= DP_PANEL_SRC_INITIATED_POWER_DOWN;
  1588. if (dp->active_stream_cnt)
  1589. goto end;
  1590. if (flags & DP_PANEL_SRC_INITIATED_POWER_DOWN) {
  1591. dp->link->psm_config(dp->link, &dp->panel->link_info, true);
  1592. dp->debug->psm_enabled = true;
  1593. dp->ctrl->off(dp->ctrl);
  1594. dp_display_host_unready(dp);
  1595. dp_display_host_deinit(dp);
  1596. }
  1597. dp_display_state_remove(DP_STATE_ENABLED);
  1598. dp->aux->state = DP_STATE_CTRL_POWERED_OFF;
  1599. complete_all(&dp->notification_comp);
  1600. /* log this as it results from user action of cable dis-connection */
  1601. DP_INFO("[OK]\n");
  1602. end:
  1603. dp_panel->deinit(dp_panel, flags);
  1604. mutex_unlock(&dp->session_lock);
  1605. return 0;
  1606. }
  1607. static enum drm_mode_status dp_display_validate_mode(
  1608. struct dp_display *dp_display,
  1609. void *panel, struct drm_display_mode *mode,
  1610. const struct msm_resource_caps_info *avail_res)
  1611. {
  1612. struct dp_display_private *dp;
  1613. struct drm_dp_link *link_info;
  1614. u32 mode_rate_khz = 0, supported_rate_khz = 0, mode_bpp = 0;
  1615. struct dp_panel *dp_panel;
  1616. struct dp_debug *debug;
  1617. enum drm_mode_status mode_status = MODE_BAD;
  1618. bool in_list = false;
  1619. struct dp_mst_connector *mst_connector;
  1620. int hdis, vdis, vref, ar, _hdis, _vdis, _vref, _ar, rate;
  1621. struct dp_display_mode dp_mode;
  1622. bool dsc_en;
  1623. u32 num_lm = 0;
  1624. if (!dp_display || !mode || !panel ||
  1625. !avail_res || !avail_res->max_mixer_width) {
  1626. DP_ERR("invalid params\n");
  1627. return mode_status;
  1628. }
  1629. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1630. mutex_lock(&dp->session_lock);
  1631. dp_panel = panel;
  1632. if (!dp_panel->connector) {
  1633. DP_ERR("invalid connector\n");
  1634. goto end;
  1635. }
  1636. link_info = &dp->panel->link_info;
  1637. debug = dp->debug;
  1638. if (!debug)
  1639. goto end;
  1640. dp_display->convert_to_dp_mode(dp_display, panel, mode, &dp_mode);
  1641. dsc_en = dp_mode.timing.comp_info.comp_ratio ? true : false;
  1642. mode_bpp = dsc_en ? dp_mode.timing.comp_info.dsc_info.bpp :
  1643. dp_mode.timing.bpp;
  1644. mode_rate_khz = mode->clock * mode_bpp;
  1645. rate = drm_dp_bw_code_to_link_rate(dp->link->link_params.bw_code);
  1646. supported_rate_khz = link_info->num_lanes * rate * 8;
  1647. if (mode_rate_khz > supported_rate_khz) {
  1648. DP_MST_DEBUG("pclk:%d, supported_rate:%d\n",
  1649. mode->clock, supported_rate_khz);
  1650. goto end;
  1651. }
  1652. if (mode->clock > dp_display->max_pclk_khz) {
  1653. DP_MST_DEBUG("clk:%d, max:%d\n", mode->clock,
  1654. dp_display->max_pclk_khz);
  1655. goto end;
  1656. }
  1657. num_lm = (avail_res->max_mixer_width <= mode->hdisplay) ?
  1658. 2 : 1;
  1659. if (num_lm > avail_res->num_lm ||
  1660. (num_lm == 2 && !avail_res->num_3dmux)) {
  1661. DP_MST_DEBUG("num_lm:%d, req lm:%d 3dmux:%d\n", num_lm,
  1662. avail_res->num_lm, avail_res->num_3dmux);
  1663. goto end;
  1664. }
  1665. /*
  1666. * If the connector exists in the mst connector list and if debug is
  1667. * enabled for that connector, use the mst connector settings from the
  1668. * list for validation. Otherwise, use non-mst default settings.
  1669. */
  1670. mutex_lock(&debug->dp_mst_connector_list.lock);
  1671. if (list_empty(&debug->dp_mst_connector_list.list)) {
  1672. mutex_unlock(&debug->dp_mst_connector_list.lock);
  1673. goto verify_default;
  1674. }
  1675. list_for_each_entry(mst_connector, &debug->dp_mst_connector_list.list,
  1676. list) {
  1677. if (mst_connector->con_id == dp_panel->connector->base.id) {
  1678. in_list = true;
  1679. if (!mst_connector->debug_en) {
  1680. mode_status = MODE_OK;
  1681. mutex_unlock(
  1682. &debug->dp_mst_connector_list.lock);
  1683. goto end;
  1684. }
  1685. hdis = mst_connector->hdisplay;
  1686. vdis = mst_connector->vdisplay;
  1687. vref = mst_connector->vrefresh;
  1688. ar = mst_connector->aspect_ratio;
  1689. _hdis = mode->hdisplay;
  1690. _vdis = mode->vdisplay;
  1691. _vref = mode->vrefresh;
  1692. _ar = mode->picture_aspect_ratio;
  1693. if (hdis == _hdis && vdis == _vdis && vref == _vref &&
  1694. ar == _ar) {
  1695. mode_status = MODE_OK;
  1696. mutex_unlock(
  1697. &debug->dp_mst_connector_list.lock);
  1698. goto end;
  1699. }
  1700. break;
  1701. }
  1702. }
  1703. mutex_unlock(&debug->dp_mst_connector_list.lock);
  1704. if (in_list)
  1705. goto end;
  1706. verify_default:
  1707. if (debug->debug_en && (mode->hdisplay != debug->hdisplay ||
  1708. mode->vdisplay != debug->vdisplay ||
  1709. mode->vrefresh != debug->vrefresh ||
  1710. mode->picture_aspect_ratio != debug->aspect_ratio))
  1711. goto end;
  1712. mode_status = MODE_OK;
  1713. end:
  1714. mutex_unlock(&dp->session_lock);
  1715. return mode_status;
  1716. }
  1717. static int dp_display_get_modes(struct dp_display *dp, void *panel,
  1718. struct dp_display_mode *dp_mode)
  1719. {
  1720. struct dp_display_private *dp_display;
  1721. struct dp_panel *dp_panel;
  1722. int ret = 0;
  1723. if (!dp || !panel) {
  1724. DP_ERR("invalid params\n");
  1725. return 0;
  1726. }
  1727. dp_panel = panel;
  1728. if (!dp_panel->connector) {
  1729. DP_ERR("invalid connector\n");
  1730. return 0;
  1731. }
  1732. dp_display = container_of(dp, struct dp_display_private, dp_display);
  1733. ret = dp_panel->get_modes(dp_panel, dp_panel->connector, dp_mode);
  1734. if (dp_mode->timing.pixel_clk_khz)
  1735. dp->max_pclk_khz = dp_mode->timing.pixel_clk_khz;
  1736. return ret;
  1737. }
  1738. static void dp_display_convert_to_dp_mode(struct dp_display *dp_display,
  1739. void *panel,
  1740. const struct drm_display_mode *drm_mode,
  1741. struct dp_display_mode *dp_mode)
  1742. {
  1743. struct dp_display_private *dp;
  1744. struct dp_panel *dp_panel;
  1745. u32 free_dsc_blks = 0, required_dsc_blks = 0;
  1746. if (!dp_display || !drm_mode || !dp_mode || !panel) {
  1747. DP_ERR("invalid input\n");
  1748. return;
  1749. }
  1750. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1751. dp_panel = panel;
  1752. memset(dp_mode, 0, sizeof(*dp_mode));
  1753. free_dsc_blks = dp->parser->max_dp_dsc_blks -
  1754. dp->tot_dsc_blks_in_use +
  1755. dp_panel->tot_dsc_blks_in_use;
  1756. required_dsc_blks = drm_mode->hdisplay /
  1757. dp->parser->max_dp_dsc_input_width_pixs;
  1758. if (drm_mode->hdisplay % dp->parser->max_dp_dsc_input_width_pixs)
  1759. required_dsc_blks++;
  1760. if (free_dsc_blks >= required_dsc_blks)
  1761. dp_mode->capabilities |= DP_PANEL_CAPS_DSC;
  1762. if (dp_mode->capabilities & DP_PANEL_CAPS_DSC)
  1763. DP_DEBUG("in_use:%d, max:%d, free:%d, req:%d, caps:0x%x, width:%d\n",
  1764. dp->tot_dsc_blks_in_use, dp->parser->max_dp_dsc_blks,
  1765. free_dsc_blks, required_dsc_blks, dp_mode->capabilities,
  1766. dp->parser->max_dp_dsc_input_width_pixs);
  1767. dp_panel->convert_to_dp_mode(dp_panel, drm_mode, dp_mode);
  1768. }
  1769. static int dp_display_config_hdr(struct dp_display *dp_display, void *panel,
  1770. struct drm_msm_ext_hdr_metadata *hdr, bool dhdr_update)
  1771. {
  1772. struct dp_panel *dp_panel;
  1773. struct sde_connector *sde_conn;
  1774. struct dp_display_private *dp;
  1775. u64 core_clk_rate;
  1776. bool flush_hdr;
  1777. if (!dp_display || !panel) {
  1778. DP_ERR("invalid input\n");
  1779. return -EINVAL;
  1780. }
  1781. dp_panel = panel;
  1782. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1783. sde_conn = to_sde_connector(dp_panel->connector);
  1784. core_clk_rate = dp->power->clk_get_rate(dp->power, "core_clk");
  1785. if (!core_clk_rate) {
  1786. DP_ERR("invalid rate for core_clk\n");
  1787. return -EINVAL;
  1788. }
  1789. /*
  1790. * In rare cases where HDR metadata is updated independently
  1791. * flush the HDR metadata immediately instead of relying on
  1792. * the colorspace
  1793. */
  1794. flush_hdr = !sde_conn->colorspace_updated;
  1795. if (flush_hdr)
  1796. DP_DEBUG("flushing the HDR metadata\n");
  1797. else
  1798. DP_DEBUG("piggy-backing with colorspace\n");
  1799. return dp_panel->setup_hdr(dp_panel, hdr, dhdr_update,
  1800. core_clk_rate, flush_hdr);
  1801. }
  1802. static int dp_display_setup_colospace(struct dp_display *dp_display,
  1803. void *panel,
  1804. u32 colorspace)
  1805. {
  1806. struct dp_panel *dp_panel;
  1807. if (!dp_display || !panel) {
  1808. pr_err("invalid input\n");
  1809. return -EINVAL;
  1810. }
  1811. dp_panel = panel;
  1812. return dp_panel->set_colorspace(dp_panel, colorspace);
  1813. }
  1814. static int dp_display_create_workqueue(struct dp_display_private *dp)
  1815. {
  1816. dp->wq = create_singlethread_workqueue("drm_dp");
  1817. if (IS_ERR_OR_NULL(dp->wq)) {
  1818. DP_ERR("Error creating wq\n");
  1819. return -EPERM;
  1820. }
  1821. INIT_DELAYED_WORK(&dp->hdcp_cb_work, dp_display_hdcp_cb_work);
  1822. INIT_WORK(&dp->connect_work, dp_display_connect_work);
  1823. INIT_WORK(&dp->attention_work, dp_display_attention_work);
  1824. return 0;
  1825. }
  1826. static int dp_display_fsa4480_callback(struct notifier_block *self,
  1827. unsigned long event, void *data)
  1828. {
  1829. return 0;
  1830. }
  1831. static int dp_display_init_aux_switch(struct dp_display_private *dp)
  1832. {
  1833. int rc = 0;
  1834. const char *phandle = "qcom,dp-aux-switch";
  1835. struct notifier_block nb;
  1836. if (!dp->pdev->dev.of_node) {
  1837. DP_ERR("cannot find dev.of_node\n");
  1838. rc = -ENODEV;
  1839. goto end;
  1840. }
  1841. dp->aux_switch_node = of_parse_phandle(dp->pdev->dev.of_node,
  1842. phandle, 0);
  1843. if (!dp->aux_switch_node) {
  1844. DP_WARN("cannot parse %s handle\n", phandle);
  1845. rc = -ENODEV;
  1846. goto end;
  1847. }
  1848. nb.notifier_call = dp_display_fsa4480_callback;
  1849. nb.priority = 0;
  1850. rc = fsa4480_reg_notifier(&nb, dp->aux_switch_node);
  1851. if (rc) {
  1852. DP_ERR("failed to register notifier (%d)\n", rc);
  1853. goto end;
  1854. }
  1855. fsa4480_unreg_notifier(&nb, dp->aux_switch_node);
  1856. end:
  1857. return rc;
  1858. }
  1859. static int dp_display_mst_install(struct dp_display *dp_display,
  1860. struct dp_mst_drm_install_info *mst_install_info)
  1861. {
  1862. struct dp_display_private *dp;
  1863. if (!dp_display || !mst_install_info) {
  1864. DP_ERR("invalid input\n");
  1865. return -EINVAL;
  1866. }
  1867. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1868. if (!mst_install_info->cbs->hpd || !mst_install_info->cbs->hpd_irq) {
  1869. DP_ERR("invalid mst cbs\n");
  1870. return -EINVAL;
  1871. }
  1872. dp_display->dp_mst_prv_info = mst_install_info->dp_mst_prv_info;
  1873. if (!dp->parser->has_mst) {
  1874. DP_DEBUG("mst not enabled\n");
  1875. return -EPERM;
  1876. }
  1877. memcpy(&dp->mst.cbs, mst_install_info->cbs, sizeof(dp->mst.cbs));
  1878. dp->mst.drm_registered = true;
  1879. DP_MST_DEBUG("dp mst drm installed\n");
  1880. return 0;
  1881. }
  1882. static int dp_display_mst_uninstall(struct dp_display *dp_display)
  1883. {
  1884. struct dp_display_private *dp;
  1885. if (!dp_display) {
  1886. DP_ERR("invalid input\n");
  1887. return -EINVAL;
  1888. }
  1889. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1890. if (!dp->mst.drm_registered) {
  1891. DP_DEBUG("drm mst not registered\n");
  1892. return -EPERM;
  1893. }
  1894. dp = container_of(dp_display, struct dp_display_private,
  1895. dp_display);
  1896. memset(&dp->mst.cbs, 0, sizeof(dp->mst.cbs));
  1897. dp->mst.drm_registered = false;
  1898. DP_MST_DEBUG("dp mst drm uninstalled\n");
  1899. return 0;
  1900. }
  1901. static int dp_display_mst_connector_install(struct dp_display *dp_display,
  1902. struct drm_connector *connector)
  1903. {
  1904. int rc = 0;
  1905. struct dp_panel_in panel_in;
  1906. struct dp_panel *dp_panel;
  1907. struct dp_display_private *dp;
  1908. struct dp_mst_connector *mst_connector;
  1909. if (!dp_display || !connector) {
  1910. DP_ERR("invalid input\n");
  1911. return -EINVAL;
  1912. }
  1913. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1914. mutex_lock(&dp->session_lock);
  1915. if (!dp->mst.drm_registered) {
  1916. DP_DEBUG("drm mst not registered\n");
  1917. mutex_unlock(&dp->session_lock);
  1918. return -EPERM;
  1919. }
  1920. panel_in.dev = &dp->pdev->dev;
  1921. panel_in.aux = dp->aux;
  1922. panel_in.catalog = &dp->catalog->panel;
  1923. panel_in.link = dp->link;
  1924. panel_in.connector = connector;
  1925. panel_in.base_panel = dp->panel;
  1926. panel_in.parser = dp->parser;
  1927. dp_panel = dp_panel_get(&panel_in);
  1928. if (IS_ERR(dp_panel)) {
  1929. rc = PTR_ERR(dp_panel);
  1930. DP_ERR("failed to initialize panel, rc = %d\n", rc);
  1931. mutex_unlock(&dp->session_lock);
  1932. return rc;
  1933. }
  1934. dp_panel->audio = dp_audio_get(dp->pdev, dp_panel, &dp->catalog->audio);
  1935. if (IS_ERR(dp_panel->audio)) {
  1936. rc = PTR_ERR(dp_panel->audio);
  1937. DP_ERR("[mst] failed to initialize audio, rc = %d\n", rc);
  1938. dp_panel->audio = NULL;
  1939. mutex_unlock(&dp->session_lock);
  1940. return rc;
  1941. }
  1942. DP_MST_DEBUG("dp mst connector installed. conn:%d\n",
  1943. connector->base.id);
  1944. mutex_lock(&dp->debug->dp_mst_connector_list.lock);
  1945. mst_connector = kmalloc(sizeof(struct dp_mst_connector),
  1946. GFP_KERNEL);
  1947. if (!mst_connector) {
  1948. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  1949. mutex_unlock(&dp->session_lock);
  1950. return -ENOMEM;
  1951. }
  1952. mst_connector->debug_en = false;
  1953. mst_connector->conn = connector;
  1954. mst_connector->con_id = connector->base.id;
  1955. mst_connector->state = connector_status_unknown;
  1956. INIT_LIST_HEAD(&mst_connector->list);
  1957. list_add(&mst_connector->list,
  1958. &dp->debug->dp_mst_connector_list.list);
  1959. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  1960. mutex_unlock(&dp->session_lock);
  1961. return 0;
  1962. }
  1963. static int dp_display_mst_connector_uninstall(struct dp_display *dp_display,
  1964. struct drm_connector *connector)
  1965. {
  1966. int rc = 0;
  1967. struct sde_connector *sde_conn;
  1968. struct dp_panel *dp_panel;
  1969. struct dp_display_private *dp;
  1970. struct dp_mst_connector *con_to_remove, *temp_con;
  1971. if (!dp_display || !connector) {
  1972. DP_ERR("invalid input\n");
  1973. return -EINVAL;
  1974. }
  1975. dp = container_of(dp_display, struct dp_display_private, dp_display);
  1976. mutex_lock(&dp->session_lock);
  1977. if (!dp->mst.drm_registered) {
  1978. DP_DEBUG("drm mst not registered\n");
  1979. mutex_unlock(&dp->session_lock);
  1980. return -EPERM;
  1981. }
  1982. sde_conn = to_sde_connector(connector);
  1983. if (!sde_conn->drv_panel) {
  1984. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  1985. mutex_unlock(&dp->session_lock);
  1986. return -EINVAL;
  1987. }
  1988. dp_panel = sde_conn->drv_panel;
  1989. dp_audio_put(dp_panel->audio);
  1990. dp_panel_put(dp_panel);
  1991. DP_MST_DEBUG("dp mst connector uninstalled. conn:%d\n",
  1992. connector->base.id);
  1993. mutex_lock(&dp->debug->dp_mst_connector_list.lock);
  1994. list_for_each_entry_safe(con_to_remove, temp_con,
  1995. &dp->debug->dp_mst_connector_list.list, list) {
  1996. if (con_to_remove->conn == connector) {
  1997. list_del(&con_to_remove->list);
  1998. kfree(con_to_remove);
  1999. }
  2000. }
  2001. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  2002. mutex_unlock(&dp->session_lock);
  2003. return rc;
  2004. }
  2005. static int dp_display_mst_get_connector_info(struct dp_display *dp_display,
  2006. struct drm_connector *connector,
  2007. struct dp_mst_connector *mst_conn)
  2008. {
  2009. struct dp_display_private *dp;
  2010. struct dp_mst_connector *conn, *temp_conn;
  2011. if (!connector || !mst_conn) {
  2012. DP_ERR("invalid input\n");
  2013. return -EINVAL;
  2014. }
  2015. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2016. mutex_lock(&dp->session_lock);
  2017. if (!dp->mst.drm_registered) {
  2018. DP_DEBUG("drm mst not registered\n");
  2019. mutex_unlock(&dp->session_lock);
  2020. return -EPERM;
  2021. }
  2022. mutex_lock(&dp->debug->dp_mst_connector_list.lock);
  2023. list_for_each_entry_safe(conn, temp_conn,
  2024. &dp->debug->dp_mst_connector_list.list, list) {
  2025. if (conn->con_id == connector->base.id)
  2026. memcpy(mst_conn, conn, sizeof(*mst_conn));
  2027. }
  2028. mutex_unlock(&dp->debug->dp_mst_connector_list.lock);
  2029. mutex_unlock(&dp->session_lock);
  2030. return 0;
  2031. }
  2032. static int dp_display_mst_connector_update_edid(struct dp_display *dp_display,
  2033. struct drm_connector *connector,
  2034. struct edid *edid)
  2035. {
  2036. int rc = 0;
  2037. struct sde_connector *sde_conn;
  2038. struct dp_panel *dp_panel;
  2039. struct dp_display_private *dp;
  2040. if (!dp_display || !connector || !edid) {
  2041. DP_ERR("invalid input\n");
  2042. return -EINVAL;
  2043. }
  2044. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2045. if (!dp->mst.drm_registered) {
  2046. DP_DEBUG("drm mst not registered\n");
  2047. return -EPERM;
  2048. }
  2049. sde_conn = to_sde_connector(connector);
  2050. if (!sde_conn->drv_panel) {
  2051. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2052. return -EINVAL;
  2053. }
  2054. dp_panel = sde_conn->drv_panel;
  2055. rc = dp_panel->update_edid(dp_panel, edid);
  2056. DP_MST_DEBUG("dp mst connector:%d edid updated. mode_cnt:%d\n",
  2057. connector->base.id, rc);
  2058. return rc;
  2059. }
  2060. static int dp_display_update_pps(struct dp_display *dp_display,
  2061. struct drm_connector *connector, char *pps_cmd)
  2062. {
  2063. struct sde_connector *sde_conn;
  2064. struct dp_panel *dp_panel;
  2065. struct dp_display_private *dp;
  2066. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2067. sde_conn = to_sde_connector(connector);
  2068. if (!sde_conn->drv_panel) {
  2069. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2070. return -EINVAL;
  2071. }
  2072. dp_panel = sde_conn->drv_panel;
  2073. dp_panel->update_pps(dp_panel, pps_cmd);
  2074. return 0;
  2075. }
  2076. static int dp_display_mst_connector_update_link_info(
  2077. struct dp_display *dp_display,
  2078. struct drm_connector *connector)
  2079. {
  2080. int rc = 0;
  2081. struct sde_connector *sde_conn;
  2082. struct dp_panel *dp_panel;
  2083. struct dp_display_private *dp;
  2084. if (!dp_display || !connector) {
  2085. DP_ERR("invalid input\n");
  2086. return -EINVAL;
  2087. }
  2088. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2089. if (!dp->mst.drm_registered) {
  2090. DP_DEBUG("drm mst not registered\n");
  2091. return -EPERM;
  2092. }
  2093. sde_conn = to_sde_connector(connector);
  2094. if (!sde_conn->drv_panel) {
  2095. DP_ERR("invalid panel for connector:%d\n", connector->base.id);
  2096. return -EINVAL;
  2097. }
  2098. dp_panel = sde_conn->drv_panel;
  2099. memcpy(dp_panel->dpcd, dp->panel->dpcd,
  2100. DP_RECEIVER_CAP_SIZE + 1);
  2101. memcpy(dp_panel->dsc_dpcd, dp->panel->dsc_dpcd,
  2102. DP_RECEIVER_DSC_CAP_SIZE + 1);
  2103. memcpy(&dp_panel->link_info, &dp->panel->link_info,
  2104. sizeof(dp_panel->link_info));
  2105. DP_MST_DEBUG("dp mst connector:%d link info updated\n",
  2106. connector->base.id);
  2107. return rc;
  2108. }
  2109. static int dp_display_mst_get_fixed_topology_port(
  2110. struct dp_display *dp_display,
  2111. u32 strm_id, u32 *port_num)
  2112. {
  2113. struct dp_display_private *dp;
  2114. u32 port;
  2115. if (!dp_display) {
  2116. DP_ERR("invalid input\n");
  2117. return -EINVAL;
  2118. }
  2119. if (strm_id >= DP_STREAM_MAX) {
  2120. DP_ERR("invalid stream id:%d\n", strm_id);
  2121. return -EINVAL;
  2122. }
  2123. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2124. port = dp->parser->mst_fixed_port[strm_id];
  2125. if (!port || port > 255)
  2126. return -ENOENT;
  2127. if (port_num)
  2128. *port_num = port;
  2129. return 0;
  2130. }
  2131. static int dp_display_get_mst_caps(struct dp_display *dp_display,
  2132. struct dp_mst_caps *mst_caps)
  2133. {
  2134. int rc = 0;
  2135. struct dp_display_private *dp;
  2136. if (!dp_display || !mst_caps) {
  2137. DP_ERR("invalid input\n");
  2138. return -EINVAL;
  2139. }
  2140. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2141. mst_caps->has_mst = dp->parser->has_mst;
  2142. mst_caps->max_streams_supported = (mst_caps->has_mst) ? 2 : 0;
  2143. mst_caps->max_dpcd_transaction_bytes = (mst_caps->has_mst) ? 16 : 0;
  2144. mst_caps->drm_aux = dp->aux->drm_aux;
  2145. return rc;
  2146. }
  2147. static void dp_display_wakeup_phy_layer(struct dp_display *dp_display,
  2148. bool wakeup)
  2149. {
  2150. struct dp_display_private *dp;
  2151. struct dp_hpd *hpd;
  2152. if (!dp_display) {
  2153. DP_ERR("invalid input\n");
  2154. return;
  2155. }
  2156. dp = container_of(dp_display, struct dp_display_private, dp_display);
  2157. if (!dp->mst.drm_registered) {
  2158. DP_DEBUG("drm mst not registered\n");
  2159. return;
  2160. }
  2161. hpd = dp->hpd;
  2162. if (hpd && hpd->wakeup_phy)
  2163. hpd->wakeup_phy(hpd, wakeup);
  2164. }
  2165. static int dp_display_probe(struct platform_device *pdev)
  2166. {
  2167. int rc = 0;
  2168. struct dp_display_private *dp;
  2169. if (!pdev || !pdev->dev.of_node) {
  2170. DP_ERR("pdev not found\n");
  2171. rc = -ENODEV;
  2172. goto bail;
  2173. }
  2174. dp = devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL);
  2175. if (!dp) {
  2176. rc = -ENOMEM;
  2177. goto bail;
  2178. }
  2179. init_completion(&dp->notification_comp);
  2180. dp->pdev = pdev;
  2181. dp->name = "drm_dp";
  2182. memset(&dp->mst, 0, sizeof(dp->mst));
  2183. rc = dp_display_init_aux_switch(dp);
  2184. if (rc) {
  2185. rc = -EPROBE_DEFER;
  2186. goto error;
  2187. }
  2188. rc = dp_display_create_workqueue(dp);
  2189. if (rc) {
  2190. DP_ERR("Failed to create workqueue\n");
  2191. goto error;
  2192. }
  2193. platform_set_drvdata(pdev, dp);
  2194. g_dp_display = &dp->dp_display;
  2195. g_dp_display->enable = dp_display_enable;
  2196. g_dp_display->post_enable = dp_display_post_enable;
  2197. g_dp_display->pre_disable = dp_display_pre_disable;
  2198. g_dp_display->disable = dp_display_disable;
  2199. g_dp_display->set_mode = dp_display_set_mode;
  2200. g_dp_display->validate_mode = dp_display_validate_mode;
  2201. g_dp_display->get_modes = dp_display_get_modes;
  2202. g_dp_display->prepare = dp_display_prepare;
  2203. g_dp_display->unprepare = dp_display_unprepare;
  2204. g_dp_display->request_irq = dp_request_irq;
  2205. g_dp_display->get_debug = dp_get_debug;
  2206. g_dp_display->post_open = NULL;
  2207. g_dp_display->post_init = dp_display_post_init;
  2208. g_dp_display->config_hdr = dp_display_config_hdr;
  2209. g_dp_display->mst_install = dp_display_mst_install;
  2210. g_dp_display->mst_uninstall = dp_display_mst_uninstall;
  2211. g_dp_display->mst_connector_install = dp_display_mst_connector_install;
  2212. g_dp_display->mst_connector_uninstall =
  2213. dp_display_mst_connector_uninstall;
  2214. g_dp_display->mst_connector_update_edid =
  2215. dp_display_mst_connector_update_edid;
  2216. g_dp_display->mst_connector_update_link_info =
  2217. dp_display_mst_connector_update_link_info;
  2218. g_dp_display->get_mst_caps = dp_display_get_mst_caps;
  2219. g_dp_display->set_stream_info = dp_display_set_stream_info;
  2220. g_dp_display->update_pps = dp_display_update_pps;
  2221. g_dp_display->convert_to_dp_mode = dp_display_convert_to_dp_mode;
  2222. g_dp_display->mst_get_connector_info =
  2223. dp_display_mst_get_connector_info;
  2224. g_dp_display->mst_get_fixed_topology_port =
  2225. dp_display_mst_get_fixed_topology_port;
  2226. g_dp_display->wakeup_phy_layer =
  2227. dp_display_wakeup_phy_layer;
  2228. g_dp_display->set_colorspace = dp_display_setup_colospace;
  2229. rc = component_add(&pdev->dev, &dp_display_comp_ops);
  2230. if (rc) {
  2231. DP_ERR("component add failed, rc=%d\n", rc);
  2232. goto error;
  2233. }
  2234. return 0;
  2235. error:
  2236. devm_kfree(&pdev->dev, dp);
  2237. bail:
  2238. return rc;
  2239. }
  2240. int dp_display_get_displays(void **displays, int count)
  2241. {
  2242. if (!displays) {
  2243. DP_ERR("invalid data\n");
  2244. return -EINVAL;
  2245. }
  2246. if (count != 1) {
  2247. DP_ERR("invalid number of displays\n");
  2248. return -EINVAL;
  2249. }
  2250. displays[0] = g_dp_display;
  2251. return count;
  2252. }
  2253. int dp_display_get_num_of_displays(void)
  2254. {
  2255. if (!g_dp_display)
  2256. return 0;
  2257. return 1;
  2258. }
  2259. int dp_display_get_num_of_streams(void)
  2260. {
  2261. return DP_STREAM_MAX;
  2262. }
  2263. static void dp_display_set_mst_state(void *dp_display,
  2264. enum dp_drv_state mst_state)
  2265. {
  2266. struct dp_display_private *dp;
  2267. if (!g_dp_display) {
  2268. DP_DEBUG("dp display not initialized\n");
  2269. return;
  2270. }
  2271. dp = container_of(g_dp_display, struct dp_display_private, dp_display);
  2272. if (dp->mst.mst_active && dp->mst.cbs.set_drv_state)
  2273. dp->mst.cbs.set_drv_state(g_dp_display, mst_state);
  2274. }
  2275. static int dp_display_remove(struct platform_device *pdev)
  2276. {
  2277. struct dp_display_private *dp;
  2278. if (!pdev)
  2279. return -EINVAL;
  2280. dp = platform_get_drvdata(pdev);
  2281. dp_display_deinit_sub_modules(dp);
  2282. if (dp->wq)
  2283. destroy_workqueue(dp->wq);
  2284. platform_set_drvdata(pdev, NULL);
  2285. devm_kfree(&pdev->dev, dp);
  2286. return 0;
  2287. }
  2288. static int dp_pm_prepare(struct device *dev)
  2289. {
  2290. struct dp_display_private *dp = container_of(g_dp_display,
  2291. struct dp_display_private, dp_display);
  2292. dp_display_set_mst_state(g_dp_display, PM_SUSPEND);
  2293. dp_display_state_add(DP_STATE_SUSPENDED);
  2294. return 0;
  2295. }
  2296. static void dp_pm_complete(struct device *dev)
  2297. {
  2298. struct dp_display_private *dp = container_of(g_dp_display,
  2299. struct dp_display_private, dp_display);
  2300. dp_display_set_mst_state(g_dp_display, PM_DEFAULT);
  2301. dp_display_state_remove(DP_STATE_SUSPENDED);
  2302. }
  2303. static const struct dev_pm_ops dp_pm_ops = {
  2304. .prepare = dp_pm_prepare,
  2305. .complete = dp_pm_complete,
  2306. };
  2307. static struct platform_driver dp_display_driver = {
  2308. .probe = dp_display_probe,
  2309. .remove = dp_display_remove,
  2310. .driver = {
  2311. .name = "msm-dp-display",
  2312. .of_match_table = dp_dt_match,
  2313. .suppress_bind_attrs = true,
  2314. .pm = &dp_pm_ops,
  2315. },
  2316. };
  2317. static int __init dp_display_init(void)
  2318. {
  2319. int ret;
  2320. ret = platform_driver_register(&dp_display_driver);
  2321. if (ret) {
  2322. DP_ERR("driver register failed\n");
  2323. return ret;
  2324. }
  2325. return ret;
  2326. }
  2327. late_initcall(dp_display_init);
  2328. static void __exit dp_display_cleanup(void)
  2329. {
  2330. platform_driver_unregister(&dp_display_driver);
  2331. }
  2332. module_exit(dp_display_cleanup);