dp_display.c 70 KB

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