dp_display.c 68 KB

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