dp_display.c 78 KB

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