dp_display.c 63 KB

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