dp_display.c 62 KB

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