dp_display.c 65 KB

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