dp_display.c 83 KB

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