dp_display.c 65 KB

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