dp_debug.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/debugfs.h>
  6. #include <linux/slab.h>
  7. #include <drm/drm_dp_mst_helper.h>
  8. #include <drm/drm_probe_helper.h>
  9. #include "dp_power.h"
  10. #include "dp_catalog.h"
  11. #include "dp_aux.h"
  12. #include "dp_debug.h"
  13. #include "drm/drm_connector.h"
  14. #include "sde_connector.h"
  15. #include "dp_display.h"
  16. #include "dp_pll.h"
  17. #include "dp_hpd.h"
  18. #include "dp_mst_sim.h"
  19. #include "dp_mst_drm.h"
  20. #define DEBUG_NAME "drm_dp"
  21. struct dp_debug_private {
  22. struct dentry *root;
  23. u32 dpcd_offset;
  24. u32 dpcd_size;
  25. u32 mst_con_id;
  26. u32 mst_edid_idx;
  27. bool hotplug;
  28. u32 sim_mode;
  29. char exe_mode[SZ_32];
  30. char reg_dump[SZ_32];
  31. struct dp_hpd *hpd;
  32. struct dp_link *link;
  33. struct dp_panel *panel;
  34. struct dp_aux *aux;
  35. struct dp_catalog *catalog;
  36. struct drm_connector **connector;
  37. struct device *dev;
  38. struct dp_debug dp_debug;
  39. struct dp_parser *parser;
  40. struct dp_ctrl *ctrl;
  41. struct dp_pll *pll;
  42. struct dp_display *display;
  43. struct mutex lock;
  44. struct dp_aux_bridge *sim_bridge;
  45. };
  46. static int dp_debug_sim_hpd_cb(void *arg, bool hpd, bool hpd_irq)
  47. {
  48. struct dp_debug_private *debug = arg;
  49. int vdo = 0;
  50. if (hpd_irq) {
  51. vdo |= BIT(7);
  52. if (hpd)
  53. vdo |= BIT(8);
  54. return debug->hpd->simulate_attention(debug->hpd, vdo);
  55. } else {
  56. return debug->hpd->simulate_connect(debug->hpd, hpd);
  57. }
  58. }
  59. static int dp_debug_attach_sim_bridge(struct dp_debug_private *debug)
  60. {
  61. int ret;
  62. if (debug->sim_bridge)
  63. return 0;
  64. ret = dp_sim_create_bridge(debug->dev, &debug->sim_bridge);
  65. if (ret)
  66. return ret;
  67. dp_sim_update_port_num(debug->sim_bridge, 1);
  68. if (debug->sim_bridge->register_hpd)
  69. debug->sim_bridge->register_hpd(debug->sim_bridge,
  70. dp_debug_sim_hpd_cb, debug);
  71. return 0;
  72. }
  73. static void dp_debug_enable_sim_mode(struct dp_debug_private *debug,
  74. u32 mode_mask)
  75. {
  76. /* return if mode is already enabled */
  77. if ((debug->sim_mode & mode_mask) == mode_mask)
  78. return;
  79. /* create bridge if not yet */
  80. if (dp_debug_attach_sim_bridge(debug))
  81. return;
  82. /* switch to bridge mode */
  83. if (!debug->sim_mode)
  84. debug->aux->set_sim_mode(debug->aux, debug->sim_bridge);
  85. /* update sim mode */
  86. debug->sim_mode |= mode_mask;
  87. dp_sim_set_sim_mode(debug->sim_bridge, debug->sim_mode);
  88. }
  89. static void dp_debug_disable_sim_mode(struct dp_debug_private *debug,
  90. u32 mode_mask)
  91. {
  92. /* return if mode is already disabled */
  93. if (!(debug->sim_mode & mode_mask))
  94. return;
  95. /* update sim mode */
  96. debug->sim_mode &= ~mode_mask;
  97. dp_sim_set_sim_mode(debug->sim_bridge, debug->sim_mode);
  98. /* switch to normal mode */
  99. if (!debug->sim_mode)
  100. debug->aux->set_sim_mode(debug->aux, NULL);
  101. }
  102. static ssize_t dp_debug_write_edid(struct file *file,
  103. const char __user *user_buff, size_t count, loff_t *ppos)
  104. {
  105. struct dp_debug_private *debug = file->private_data;
  106. u8 *buf = NULL, *buf_t = NULL, *edid = NULL;
  107. const int char_to_nib = 2;
  108. size_t edid_size = 0;
  109. size_t size = 0, edid_buf_index = 0;
  110. ssize_t rc = count;
  111. if (!debug)
  112. return -ENODEV;
  113. mutex_lock(&debug->lock);
  114. if (*ppos)
  115. goto bail;
  116. size = min_t(size_t, count, SZ_1K);
  117. buf = kzalloc(size, GFP_KERNEL);
  118. if (ZERO_OR_NULL_PTR(buf)) {
  119. rc = -ENOMEM;
  120. goto bail;
  121. }
  122. if (copy_from_user(buf, user_buff, size))
  123. goto bail;
  124. edid_size = size / char_to_nib;
  125. buf_t = buf;
  126. size = edid_size;
  127. edid = kzalloc(size, GFP_KERNEL);
  128. if (!edid)
  129. goto bail;
  130. while (size--) {
  131. char t[3];
  132. int d;
  133. memcpy(t, buf_t, sizeof(char) * char_to_nib);
  134. t[char_to_nib] = '\0';
  135. if (kstrtoint(t, 16, &d)) {
  136. DP_ERR("kstrtoint error\n");
  137. goto bail;
  138. }
  139. edid[edid_buf_index++] = d;
  140. buf_t += char_to_nib;
  141. }
  142. dp_debug_enable_sim_mode(debug, DP_SIM_MODE_EDID);
  143. dp_mst_clear_edid_cache(debug->display);
  144. dp_sim_update_port_edid(debug->sim_bridge, debug->mst_edid_idx,
  145. edid, edid_size);
  146. bail:
  147. kfree(buf);
  148. kfree(edid);
  149. mutex_unlock(&debug->lock);
  150. return rc;
  151. }
  152. static ssize_t dp_debug_write_dpcd(struct file *file,
  153. const char __user *user_buff, size_t count, loff_t *ppos)
  154. {
  155. struct dp_debug_private *debug = file->private_data;
  156. u8 *buf = NULL, *buf_t = NULL, *dpcd = NULL;
  157. const int char_to_nib = 2;
  158. size_t dpcd_size = 0;
  159. size_t size = 0, dpcd_buf_index = 0;
  160. ssize_t rc = count;
  161. char offset_ch[5];
  162. u32 offset, data_len;
  163. if (!debug)
  164. return -ENODEV;
  165. mutex_lock(&debug->lock);
  166. if (*ppos)
  167. goto bail;
  168. size = min_t(size_t, count, SZ_2K);
  169. if (size <= 4)
  170. goto bail;
  171. buf = kzalloc(size, GFP_KERNEL);
  172. if (ZERO_OR_NULL_PTR(buf)) {
  173. rc = -ENOMEM;
  174. goto bail;
  175. }
  176. if (copy_from_user(buf, user_buff, size))
  177. goto bail;
  178. memcpy(offset_ch, buf, 4);
  179. offset_ch[4] = '\0';
  180. if (kstrtoint(offset_ch, 16, &offset)) {
  181. DP_ERR("offset kstrtoint error\n");
  182. goto bail;
  183. }
  184. size -= 4;
  185. if (size == 0)
  186. goto bail;
  187. dpcd_size = size / char_to_nib;
  188. data_len = dpcd_size;
  189. buf_t = buf + 4;
  190. dpcd = kzalloc(dpcd_size, GFP_KERNEL);
  191. if (ZERO_OR_NULL_PTR(dpcd)) {
  192. rc = -ENOMEM;
  193. goto bail;
  194. }
  195. while (dpcd_size--) {
  196. char t[3];
  197. int d;
  198. memcpy(t, buf_t, sizeof(char) * char_to_nib);
  199. t[char_to_nib] = '\0';
  200. if (kstrtoint(t, 16, &d)) {
  201. DP_ERR("kstrtoint error\n");
  202. goto bail;
  203. }
  204. dpcd[dpcd_buf_index++] = d;
  205. buf_t += char_to_nib;
  206. }
  207. /*
  208. * if link training status registers are reprogramed,
  209. * read link training status from simulator, otherwise
  210. * read link training status from real aux channel.
  211. */
  212. if (offset <= DP_LANE0_1_STATUS &&
  213. offset + dpcd_buf_index > DP_LANE0_1_STATUS)
  214. dp_debug_enable_sim_mode(debug,
  215. DP_SIM_MODE_DPCD_READ | DP_SIM_MODE_LINK_TRAIN);
  216. else
  217. dp_debug_enable_sim_mode(debug, DP_SIM_MODE_DPCD_READ);
  218. dp_sim_write_dpcd_reg(debug->sim_bridge,
  219. dpcd, dpcd_buf_index, offset);
  220. debug->dpcd_offset = offset;
  221. debug->dpcd_size = dpcd_buf_index;
  222. bail:
  223. kfree(buf);
  224. kfree(dpcd);
  225. mutex_unlock(&debug->lock);
  226. return rc;
  227. }
  228. static ssize_t dp_debug_read_dpcd(struct file *file,
  229. char __user *user_buff, size_t count, loff_t *ppos)
  230. {
  231. struct dp_debug_private *debug = file->private_data;
  232. char *buf;
  233. int const buf_size = SZ_4K;
  234. u32 offset = 0;
  235. u32 len = 0;
  236. u8 *dpcd;
  237. if (!debug || !debug->aux)
  238. return -ENODEV;
  239. if (*ppos)
  240. return 0;
  241. buf = kzalloc(buf_size, GFP_KERNEL);
  242. if (!buf)
  243. return -ENOMEM;
  244. mutex_lock(&debug->lock);
  245. dpcd = kzalloc(buf_size, GFP_KERNEL);
  246. if (!dpcd)
  247. goto bail;
  248. /*
  249. * In simulation mode, this function returns the last written DPCD node.
  250. * For a real monitor plug in, it always dumps the first 16 DPCD registers.
  251. */
  252. if (debug->dp_debug.sim_mode) {
  253. dp_sim_read_dpcd_reg(debug->sim_bridge, dpcd, debug->dpcd_size, debug->dpcd_offset);
  254. } else {
  255. debug->dpcd_size = sizeof(debug->panel->dpcd);
  256. debug->dpcd_offset = 0;
  257. memcpy(dpcd, debug->panel->dpcd, debug->dpcd_size);
  258. }
  259. len += scnprintf(buf, buf_size, "%04x: ", debug->dpcd_offset);
  260. while (offset < debug->dpcd_size)
  261. len += scnprintf(buf + len, buf_size - len, "%02x ",
  262. dpcd[debug->dpcd_offset + offset++]);
  263. kfree(dpcd);
  264. len = min_t(size_t, count, len);
  265. if (!copy_to_user(user_buff, buf, len))
  266. *ppos += len;
  267. bail:
  268. mutex_unlock(&debug->lock);
  269. kfree(buf);
  270. return len;
  271. }
  272. static ssize_t dp_debug_write_hpd(struct file *file,
  273. const char __user *user_buff, size_t count, loff_t *ppos)
  274. {
  275. struct dp_debug_private *debug = file->private_data;
  276. char buf[SZ_8];
  277. size_t len = 0;
  278. int const hpd_data_mask = 0x7;
  279. int hpd = 0;
  280. if (!debug)
  281. return -ENODEV;
  282. if (*ppos)
  283. return 0;
  284. /* Leave room for termination char */
  285. len = min_t(size_t, count, SZ_8 - 1);
  286. if (copy_from_user(buf, user_buff, len))
  287. goto end;
  288. buf[len] = '\0';
  289. if (kstrtoint(buf, 10, &hpd) != 0)
  290. goto end;
  291. hpd &= hpd_data_mask;
  292. debug->hotplug = !!(hpd & BIT(0));
  293. debug->dp_debug.psm_enabled = !!(hpd & BIT(1));
  294. /*
  295. * print hotplug value as this code is executed
  296. * only while running in debug mode which is manually
  297. * triggered by a tester or a script.
  298. */
  299. DP_INFO("%s\n", debug->hotplug ? "[CONNECT]" : "[DISCONNECT]");
  300. debug->hpd->simulate_connect(debug->hpd, debug->hotplug);
  301. end:
  302. return len;
  303. }
  304. static ssize_t dp_debug_write_edid_modes(struct file *file,
  305. const char __user *user_buff, size_t count, loff_t *ppos)
  306. {
  307. struct dp_debug_private *debug = file->private_data;
  308. struct dp_panel *panel;
  309. char buf[SZ_32];
  310. size_t len = 0;
  311. int hdisplay = 0, vdisplay = 0, vrefresh = 0, aspect_ratio;
  312. if (!debug)
  313. return -ENODEV;
  314. if (*ppos)
  315. goto end;
  316. panel = debug->panel;
  317. /* Leave room for termination char */
  318. len = min_t(size_t, count, SZ_32 - 1);
  319. if (copy_from_user(buf, user_buff, len))
  320. goto clear;
  321. buf[len] = '\0';
  322. if (sscanf(buf, "%d %d %d %d", &hdisplay, &vdisplay, &vrefresh,
  323. &aspect_ratio) != 4)
  324. goto clear;
  325. if (!hdisplay || !vdisplay || !vrefresh)
  326. goto clear;
  327. panel->mode_override = true;
  328. panel->hdisplay = hdisplay;
  329. panel->vdisplay = vdisplay;
  330. panel->vrefresh = vrefresh;
  331. panel->aspect_ratio = aspect_ratio;
  332. goto end;
  333. clear:
  334. DP_DEBUG("clearing debug modes\n");
  335. panel->mode_override = false;
  336. end:
  337. return len;
  338. }
  339. static ssize_t dp_debug_write_edid_modes_mst(struct file *file,
  340. const char __user *user_buff, size_t count, loff_t *ppos)
  341. {
  342. struct dp_debug_private *debug = file->private_data;
  343. struct drm_connector *connector;
  344. struct sde_connector *sde_conn;
  345. struct dp_panel *panel = NULL;
  346. char buf[SZ_512];
  347. char *read_buf;
  348. size_t len = 0;
  349. int hdisplay = 0, vdisplay = 0, vrefresh = 0, aspect_ratio = 0;
  350. int con_id = 0, offset = 0, debug_en = 0;
  351. if (!debug)
  352. return -ENODEV;
  353. mutex_lock(&debug->lock);
  354. if (*ppos)
  355. goto end;
  356. len = min_t(size_t, count, SZ_512 - 1);
  357. if (copy_from_user(buf, user_buff, len))
  358. goto end;
  359. buf[len] = '\0';
  360. read_buf = buf;
  361. while (sscanf(read_buf, "%d %d %d %d %d %d%n", &debug_en, &con_id,
  362. &hdisplay, &vdisplay, &vrefresh, &aspect_ratio,
  363. &offset) == 6) {
  364. connector = drm_connector_lookup((*debug->connector)->dev,
  365. NULL, con_id);
  366. if (connector) {
  367. sde_conn = to_sde_connector(connector);
  368. panel = sde_conn->drv_panel;
  369. if (panel && sde_conn->mst_port) {
  370. panel->mode_override = debug_en;
  371. panel->hdisplay = hdisplay;
  372. panel->vdisplay = vdisplay;
  373. panel->vrefresh = vrefresh;
  374. panel->aspect_ratio = aspect_ratio;
  375. } else {
  376. DP_ERR("connector id %d is not mst\n", con_id);
  377. }
  378. drm_connector_put(connector);
  379. } else {
  380. DP_ERR("invalid connector id %d\n", con_id);
  381. }
  382. read_buf += offset;
  383. }
  384. end:
  385. mutex_unlock(&debug->lock);
  386. return len;
  387. }
  388. static ssize_t dp_debug_write_mst_con_id(struct file *file,
  389. const char __user *user_buff, size_t count, loff_t *ppos)
  390. {
  391. struct dp_debug_private *debug = file->private_data;
  392. struct drm_connector *connector;
  393. struct sde_connector *sde_conn;
  394. struct drm_dp_mst_port *mst_port;
  395. struct dp_panel *dp_panel;
  396. char buf[SZ_32];
  397. size_t len = 0;
  398. int con_id = 0, status;
  399. if (!debug)
  400. return -ENODEV;
  401. mutex_lock(&debug->lock);
  402. if (*ppos)
  403. goto end;
  404. /* Leave room for termination char */
  405. len = min_t(size_t, count, SZ_32 - 1);
  406. if (copy_from_user(buf, user_buff, len))
  407. goto clear;
  408. buf[len] = '\0';
  409. if (sscanf(buf, "%d %d", &con_id, &status) != 2)
  410. goto end;
  411. if (!con_id)
  412. goto clear;
  413. connector = drm_connector_lookup((*debug->connector)->dev,
  414. NULL, con_id);
  415. if (!connector) {
  416. DP_ERR("invalid connector id %u\n", con_id);
  417. goto end;
  418. }
  419. sde_conn = to_sde_connector(connector);
  420. if (!sde_conn->drv_panel || !sde_conn->mst_port) {
  421. DP_ERR("invalid connector state %d\n", con_id);
  422. goto out;
  423. }
  424. debug->mst_con_id = con_id;
  425. if (status == connector_status_unknown)
  426. goto out;
  427. mst_port = sde_conn->mst_port;
  428. dp_panel = sde_conn->drv_panel;
  429. if (debug->dp_debug.sim_mode) {
  430. dp_sim_update_port_status(debug->sim_bridge,
  431. mst_port->port_num, status);
  432. } else {
  433. dp_panel->mst_hide = (status == connector_status_disconnected);
  434. drm_kms_helper_hotplug_event(connector->dev);
  435. }
  436. out:
  437. drm_connector_put(connector);
  438. goto end;
  439. clear:
  440. DP_DEBUG("clearing mst_con_id\n");
  441. debug->mst_con_id = 0;
  442. end:
  443. mutex_unlock(&debug->lock);
  444. return len;
  445. }
  446. static ssize_t dp_debug_write_mst_con_add(struct file *file,
  447. const char __user *user_buff, size_t count, loff_t *ppos)
  448. {
  449. struct dp_debug_private *debug = file->private_data;
  450. char buf[SZ_32];
  451. size_t len = 0;
  452. const int dp_en = BIT(3), hpd_high = BIT(7), hpd_irq = BIT(8);
  453. int vdo = dp_en | hpd_high | hpd_irq;
  454. if (!debug)
  455. return -ENODEV;
  456. if (*ppos)
  457. return 0;
  458. /* Leave room for termination char */
  459. len = min_t(size_t, count, SZ_32 - 1);
  460. if (copy_from_user(buf, user_buff, len))
  461. goto end;
  462. debug->dp_debug.mst_sim_add_con = true;
  463. debug->hpd->simulate_attention(debug->hpd, vdo);
  464. end:
  465. return len;
  466. }
  467. static ssize_t dp_debug_write_mst_con_remove(struct file *file,
  468. const char __user *user_buff, size_t count, loff_t *ppos)
  469. {
  470. struct dp_debug_private *debug = file->private_data;
  471. struct drm_connector_list_iter conn_iter;
  472. struct drm_connector *connector;
  473. char buf[SZ_32];
  474. size_t len = 0;
  475. int con_id = 0;
  476. bool in_list = false;
  477. const int dp_en = BIT(3), hpd_high = BIT(7), hpd_irq = BIT(8);
  478. int vdo = dp_en | hpd_high | hpd_irq;
  479. if (!debug)
  480. return -ENODEV;
  481. if (*ppos)
  482. return 0;
  483. /* Leave room for termination char */
  484. len = min_t(size_t, count, SZ_32 - 1);
  485. if (copy_from_user(buf, user_buff, len))
  486. goto end;
  487. buf[len] = '\0';
  488. if (sscanf(buf, "%d", &con_id) != 1) {
  489. len = 0;
  490. goto end;
  491. }
  492. if (!con_id)
  493. goto end;
  494. drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
  495. drm_for_each_connector_iter(connector, &conn_iter) {
  496. if (connector->base.id == con_id) {
  497. in_list = true;
  498. break;
  499. }
  500. }
  501. drm_connector_list_iter_end(&conn_iter);
  502. if (!in_list) {
  503. DRM_ERROR("invalid connector id %u\n", con_id);
  504. goto end;
  505. }
  506. debug->dp_debug.mst_sim_remove_con = true;
  507. debug->dp_debug.mst_sim_remove_con_id = con_id;
  508. debug->hpd->simulate_attention(debug->hpd, vdo);
  509. end:
  510. return len;
  511. }
  512. static ssize_t dp_debug_mmrm_clk_cb_write(struct file *file,
  513. const char __user *user_buff, size_t count, loff_t *ppos)
  514. {
  515. struct dp_debug_private *debug = file->private_data;
  516. char buf[SZ_8];
  517. size_t len = 0;
  518. struct dss_clk_mmrm_cb mmrm_cb_data;
  519. struct mmrm_client_notifier_data notifier_data;
  520. struct dp_display *dp_display;
  521. int cb_type;
  522. if (!debug)
  523. return -ENODEV;
  524. if (*ppos)
  525. return 0;
  526. dp_display = debug->display;
  527. len = min_t(size_t, count, SZ_8 - 1);
  528. if (copy_from_user(buf, user_buff, len))
  529. return 0;
  530. buf[len] = '\0';
  531. if (kstrtoint(buf, 10, &cb_type) != 0)
  532. return 0;
  533. if (cb_type != MMRM_CLIENT_RESOURCE_VALUE_CHANGE)
  534. return 0;
  535. notifier_data.cb_type = MMRM_CLIENT_RESOURCE_VALUE_CHANGE;
  536. mmrm_cb_data.phandle = (void *)dp_display;
  537. notifier_data.pvt_data = (void *)&mmrm_cb_data;
  538. dp_display_mmrm_callback(&notifier_data);
  539. return len;
  540. }
  541. static ssize_t dp_debug_bw_code_write(struct file *file,
  542. const char __user *user_buff, size_t count, loff_t *ppos)
  543. {
  544. struct dp_debug_private *debug = file->private_data;
  545. char buf[SZ_8];
  546. size_t len = 0;
  547. u32 max_bw_code = 0;
  548. if (!debug)
  549. return -ENODEV;
  550. if (*ppos)
  551. return 0;
  552. /* Leave room for termination char */
  553. len = min_t(size_t, count, SZ_8 - 1);
  554. if (copy_from_user(buf, user_buff, len))
  555. return 0;
  556. buf[len] = '\0';
  557. if (kstrtoint(buf, 10, &max_bw_code) != 0)
  558. return 0;
  559. if (!is_link_rate_valid(max_bw_code)) {
  560. DP_ERR("Unsupported bw code %d\n", max_bw_code);
  561. return len;
  562. }
  563. debug->panel->max_bw_code = max_bw_code;
  564. DP_DEBUG("max_bw_code: %d\n", max_bw_code);
  565. return len;
  566. }
  567. static ssize_t dp_debug_mst_mode_read(struct file *file,
  568. char __user *user_buff, size_t count, loff_t *ppos)
  569. {
  570. struct dp_debug_private *debug = file->private_data;
  571. char buf[64];
  572. ssize_t len;
  573. len = scnprintf(buf, sizeof(buf),
  574. "mst_mode = %d, mst_state = %d\n",
  575. debug->parser->has_mst,
  576. debug->panel->mst_state);
  577. return simple_read_from_buffer(user_buff, count, ppos, buf, len);
  578. }
  579. static ssize_t dp_debug_mst_mode_write(struct file *file,
  580. const char __user *user_buff, size_t count, loff_t *ppos)
  581. {
  582. struct dp_debug_private *debug = file->private_data;
  583. char buf[SZ_8];
  584. size_t len = 0;
  585. u32 mst_mode = 0;
  586. if (!debug)
  587. return -ENODEV;
  588. if (*ppos)
  589. return 0;
  590. len = min_t(size_t, count, SZ_8 - 1);
  591. if (copy_from_user(buf, user_buff, len))
  592. return 0;
  593. buf[len] = '\0';
  594. if (kstrtoint(buf, 10, &mst_mode) != 0)
  595. return 0;
  596. debug->parser->has_mst = mst_mode ? true : false;
  597. DP_DEBUG("mst_enable: %d\n", mst_mode);
  598. return len;
  599. }
  600. static ssize_t dp_debug_max_pclk_khz_write(struct file *file,
  601. const char __user *user_buff, size_t count, loff_t *ppos)
  602. {
  603. struct dp_debug_private *debug = file->private_data;
  604. char buf[SZ_8];
  605. size_t len = 0;
  606. u32 max_pclk = 0;
  607. if (!debug)
  608. return -ENODEV;
  609. if (*ppos)
  610. return 0;
  611. len = min_t(size_t, count, SZ_8 - 1);
  612. if (copy_from_user(buf, user_buff, len))
  613. return 0;
  614. buf[len] = '\0';
  615. if (kstrtoint(buf, 10, &max_pclk) != 0)
  616. return 0;
  617. if (max_pclk > debug->parser->max_pclk_khz)
  618. DP_ERR("requested: %d, max_pclk_khz:%d\n", max_pclk,
  619. debug->parser->max_pclk_khz);
  620. else
  621. debug->dp_debug.max_pclk_khz = max_pclk;
  622. DP_DEBUG("max_pclk_khz: %d\n", max_pclk);
  623. return len;
  624. }
  625. static ssize_t dp_debug_max_pclk_khz_read(struct file *file,
  626. char __user *user_buff, size_t count, loff_t *ppos)
  627. {
  628. struct dp_debug_private *debug = file->private_data;
  629. char *buf;
  630. u32 len = 0;
  631. if (!debug)
  632. return -ENODEV;
  633. if (*ppos)
  634. return 0;
  635. buf = kzalloc(SZ_4K, GFP_KERNEL);
  636. if (ZERO_OR_NULL_PTR(buf))
  637. return -ENOMEM;
  638. len += snprintf(buf + len, (SZ_4K - len),
  639. "max_pclk_khz = %d, org: %d\n",
  640. debug->dp_debug.max_pclk_khz,
  641. debug->parser->max_pclk_khz);
  642. len = min_t(size_t, count, len);
  643. if (copy_to_user(user_buff, buf, len)) {
  644. kfree(buf);
  645. return -EFAULT;
  646. }
  647. *ppos += len;
  648. kfree(buf);
  649. return len;
  650. }
  651. static ssize_t dp_debug_mst_sideband_mode_write(struct file *file,
  652. const char __user *user_buff, size_t count, loff_t *ppos)
  653. {
  654. struct dp_debug_private *debug = file->private_data;
  655. char buf[SZ_8];
  656. size_t len = 0;
  657. int mst_sideband_mode = 0;
  658. u32 mst_port_cnt = 0;
  659. if (!debug)
  660. return -ENODEV;
  661. mutex_lock(&debug->lock);
  662. /* Leave room for termination char */
  663. len = min_t(size_t, count, SZ_8 - 1);
  664. if (copy_from_user(buf, user_buff, len))
  665. return -EFAULT;
  666. buf[len] = '\0';
  667. if (sscanf(buf, "%d %u", &mst_sideband_mode, &mst_port_cnt) != 2) {
  668. DP_ERR("invalid input\n");
  669. goto bail;
  670. }
  671. if (!mst_port_cnt)
  672. mst_port_cnt = 1;
  673. debug->mst_edid_idx = 0;
  674. if (mst_sideband_mode)
  675. dp_debug_disable_sim_mode(debug, DP_SIM_MODE_MST);
  676. else
  677. dp_debug_enable_sim_mode(debug, DP_SIM_MODE_MST);
  678. dp_sim_update_port_num(debug->sim_bridge, mst_port_cnt);
  679. buf[0] = !mst_sideband_mode;
  680. dp_sim_write_dpcd_reg(debug->sim_bridge, buf, 1, DP_MSTM_CAP);
  681. DP_DEBUG("mst_sideband_mode: %d port_cnt:%d\n",
  682. mst_sideband_mode, mst_port_cnt);
  683. bail:
  684. mutex_unlock(&debug->lock);
  685. return count;
  686. }
  687. static ssize_t dp_debug_tpg_write(struct file *file,
  688. const char __user *user_buff, size_t count, loff_t *ppos)
  689. {
  690. struct dp_debug_private *debug = file->private_data;
  691. char buf[SZ_8];
  692. size_t len = 0;
  693. u32 tpg_state = 0;
  694. if (!debug)
  695. return -ENODEV;
  696. if (*ppos)
  697. return 0;
  698. /* Leave room for termination char */
  699. len = min_t(size_t, count, SZ_8 - 1);
  700. if (copy_from_user(buf, user_buff, len))
  701. goto bail;
  702. buf[len] = '\0';
  703. if (kstrtoint(buf, 10, &tpg_state) != 0)
  704. goto bail;
  705. tpg_state &= 0x1;
  706. DP_DEBUG("tpg_state: %d\n", tpg_state);
  707. if (tpg_state == debug->dp_debug.tpg_state)
  708. goto bail;
  709. if (debug->panel)
  710. debug->panel->tpg_config(debug->panel, tpg_state);
  711. debug->dp_debug.tpg_state = tpg_state;
  712. bail:
  713. return len;
  714. }
  715. static ssize_t dp_debug_write_exe_mode(struct file *file,
  716. const char __user *user_buff, size_t count, loff_t *ppos)
  717. {
  718. struct dp_debug_private *debug = file->private_data;
  719. char buf[SZ_32];
  720. size_t len = 0;
  721. if (!debug)
  722. return -ENODEV;
  723. if (*ppos)
  724. return 0;
  725. len = min_t(size_t, count, SZ_32 - 1);
  726. if (copy_from_user(buf, user_buff, len))
  727. goto end;
  728. buf[len] = '\0';
  729. if (sscanf(buf, "%3s", debug->exe_mode) != 1)
  730. goto end;
  731. if (strcmp(debug->exe_mode, "hw") &&
  732. strcmp(debug->exe_mode, "sw") &&
  733. strcmp(debug->exe_mode, "all"))
  734. goto end;
  735. debug->catalog->set_exe_mode(debug->catalog, debug->exe_mode);
  736. end:
  737. return len;
  738. }
  739. static ssize_t dp_debug_read_connected(struct file *file,
  740. char __user *user_buff, size_t count, loff_t *ppos)
  741. {
  742. struct dp_debug_private *debug = file->private_data;
  743. char buf[SZ_8];
  744. u32 len = 0;
  745. if (!debug)
  746. return -ENODEV;
  747. if (*ppos)
  748. return 0;
  749. len += snprintf(buf, SZ_8, "%d\n", debug->hpd->hpd_high);
  750. len = min_t(size_t, count, len);
  751. if (copy_to_user(user_buff, buf, len))
  752. return -EFAULT;
  753. *ppos += len;
  754. return len;
  755. }
  756. static ssize_t dp_debug_write_hdcp(struct file *file,
  757. const char __user *user_buff, size_t count, loff_t *ppos)
  758. {
  759. struct dp_debug_private *debug = file->private_data;
  760. char buf[SZ_8];
  761. size_t len = 0;
  762. int hdcp = 0;
  763. if (!debug)
  764. return -ENODEV;
  765. if (*ppos)
  766. return 0;
  767. /* Leave room for termination char */
  768. len = min_t(size_t, count, SZ_8 - 1);
  769. if (copy_from_user(buf, user_buff, len))
  770. goto end;
  771. buf[len] = '\0';
  772. if (kstrtoint(buf, 10, &hdcp) != 0)
  773. goto end;
  774. debug->dp_debug.hdcp_disabled = !hdcp;
  775. end:
  776. return len;
  777. }
  778. static ssize_t dp_debug_read_hdcp(struct file *file,
  779. char __user *user_buff, size_t count, loff_t *ppos)
  780. {
  781. struct dp_debug_private *debug = file->private_data;
  782. u32 len = 0;
  783. if (!debug)
  784. return -ENODEV;
  785. if (*ppos)
  786. return 0;
  787. len = sizeof(debug->dp_debug.hdcp_status);
  788. len = min_t(size_t, count, len);
  789. if (copy_to_user(user_buff, debug->dp_debug.hdcp_status, len))
  790. return -EFAULT;
  791. *ppos += len;
  792. return len;
  793. }
  794. static int dp_debug_check_buffer_overflow(int rc, int *max_size, int *len)
  795. {
  796. if (rc >= *max_size) {
  797. DP_ERR("buffer overflow\n");
  798. return -EINVAL;
  799. }
  800. *len += rc;
  801. *max_size = SZ_4K - *len;
  802. return 0;
  803. }
  804. static ssize_t dp_debug_read_edid_modes(struct file *file,
  805. char __user *user_buff, size_t count, loff_t *ppos)
  806. {
  807. struct dp_debug_private *debug = file->private_data;
  808. char *buf;
  809. u32 len = 0, ret = 0, max_size = SZ_4K;
  810. int rc = 0;
  811. struct drm_connector *connector;
  812. struct drm_display_mode *mode;
  813. if (!debug) {
  814. DP_ERR("invalid data\n");
  815. rc = -ENODEV;
  816. goto error;
  817. }
  818. connector = *debug->connector;
  819. if (!connector) {
  820. DP_ERR("connector is NULL\n");
  821. rc = -EINVAL;
  822. goto error;
  823. }
  824. if (*ppos)
  825. goto error;
  826. buf = kzalloc(SZ_4K, GFP_KERNEL);
  827. if (ZERO_OR_NULL_PTR(buf)) {
  828. rc = -ENOMEM;
  829. goto error;
  830. }
  831. mutex_lock(&connector->dev->mode_config.mutex);
  832. list_for_each_entry(mode, &connector->modes, head) {
  833. ret = snprintf(buf + len, max_size,
  834. "%s %d %d %d %d %d 0x%x\n",
  835. mode->name, drm_mode_vrefresh(mode), mode->picture_aspect_ratio,
  836. mode->htotal, mode->vtotal, mode->clock, mode->flags);
  837. if (dp_debug_check_buffer_overflow(ret, &max_size, &len))
  838. break;
  839. }
  840. mutex_unlock(&connector->dev->mode_config.mutex);
  841. len = min_t(size_t, count, len);
  842. if (copy_to_user(user_buff, buf, len)) {
  843. kfree(buf);
  844. rc = -EFAULT;
  845. goto error;
  846. }
  847. *ppos += len;
  848. kfree(buf);
  849. return len;
  850. error:
  851. return rc;
  852. }
  853. static ssize_t dp_debug_read_edid_modes_mst(struct file *file,
  854. char __user *user_buff, size_t count, loff_t *ppos)
  855. {
  856. struct dp_debug_private *debug = file->private_data;
  857. char *buf;
  858. u32 len = 0, ret = 0, max_size = SZ_4K;
  859. struct drm_connector *connector;
  860. struct drm_display_mode *mode;
  861. if (!debug) {
  862. DP_ERR("invalid data\n");
  863. return -ENODEV;
  864. }
  865. if (*ppos)
  866. return 0;
  867. connector = drm_connector_lookup((*debug->connector)->dev,
  868. NULL, debug->mst_con_id);
  869. if (!connector) {
  870. DP_ERR("connector %u not in mst list\n", debug->mst_con_id);
  871. return 0;
  872. }
  873. buf = kzalloc(SZ_4K, GFP_KERNEL);
  874. if (!buf)
  875. goto clean;
  876. mutex_lock(&connector->dev->mode_config.mutex);
  877. list_for_each_entry(mode, &connector->modes, head) {
  878. ret = snprintf(buf + len, max_size,
  879. "%s %d %d %d %d %d 0x%x\n",
  880. mode->name, drm_mode_vrefresh(mode),
  881. mode->picture_aspect_ratio, mode->htotal,
  882. mode->vtotal, mode->clock, mode->flags);
  883. if (dp_debug_check_buffer_overflow(ret, &max_size, &len))
  884. break;
  885. }
  886. mutex_unlock(&connector->dev->mode_config.mutex);
  887. len = min_t(size_t, count, len);
  888. if (copy_to_user(user_buff, buf, len)) {
  889. len = -EFAULT;
  890. goto clean;
  891. }
  892. *ppos += len;
  893. clean:
  894. kfree(buf);
  895. drm_connector_put(connector);
  896. return len;
  897. }
  898. static ssize_t dp_debug_read_mst_con_id(struct file *file,
  899. char __user *user_buff, size_t count, loff_t *ppos)
  900. {
  901. struct dp_debug_private *debug = file->private_data;
  902. char *buf;
  903. u32 len = 0, ret = 0, max_size = SZ_4K;
  904. int rc = 0;
  905. if (!debug) {
  906. DP_ERR("invalid data\n");
  907. rc = -ENODEV;
  908. goto error;
  909. }
  910. if (*ppos)
  911. goto error;
  912. buf = kzalloc(SZ_4K, GFP_KERNEL);
  913. if (!buf) {
  914. rc = -ENOMEM;
  915. goto error;
  916. }
  917. ret = snprintf(buf, max_size, "%u\n", debug->mst_con_id);
  918. len += ret;
  919. len = min_t(size_t, count, len);
  920. if (copy_to_user(user_buff, buf, len)) {
  921. kfree(buf);
  922. rc = -EFAULT;
  923. goto error;
  924. }
  925. *ppos += len;
  926. kfree(buf);
  927. return len;
  928. error:
  929. return rc;
  930. }
  931. static ssize_t dp_debug_read_mst_conn_info(struct file *file,
  932. char __user *user_buff, size_t count, loff_t *ppos)
  933. {
  934. struct dp_debug_private *debug = file->private_data;
  935. struct drm_connector_list_iter conn_iter;
  936. struct drm_connector *connector;
  937. struct sde_connector *sde_conn;
  938. struct dp_display *display;
  939. char *buf;
  940. u32 len = 0, ret = 0, max_size = SZ_4K;
  941. int rc = 0;
  942. if (!debug) {
  943. DP_ERR("invalid data\n");
  944. rc = -ENODEV;
  945. goto error;
  946. }
  947. if (*ppos)
  948. goto error;
  949. buf = kzalloc(SZ_4K, GFP_KERNEL);
  950. if (!buf) {
  951. rc = -ENOMEM;
  952. goto error;
  953. }
  954. drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
  955. drm_for_each_connector_iter(connector, &conn_iter) {
  956. sde_conn = to_sde_connector(connector);
  957. display = sde_conn->display;
  958. if (!sde_conn->mst_port ||
  959. display->base_connector != (*debug->connector))
  960. continue;
  961. ret = scnprintf(buf + len, max_size,
  962. "conn name:%s, conn id:%d state:%d\n",
  963. connector->name, connector->base.id,
  964. connector->status);
  965. if (dp_debug_check_buffer_overflow(ret, &max_size, &len))
  966. break;
  967. }
  968. drm_connector_list_iter_end(&conn_iter);
  969. len = min_t(size_t, count, len);
  970. if (copy_to_user(user_buff, buf, len)) {
  971. kfree(buf);
  972. rc = -EFAULT;
  973. goto error;
  974. }
  975. *ppos += len;
  976. kfree(buf);
  977. return len;
  978. error:
  979. return rc;
  980. }
  981. static ssize_t dp_debug_read_info(struct file *file, char __user *user_buff,
  982. size_t count, loff_t *ppos)
  983. {
  984. struct dp_debug_private *debug = file->private_data;
  985. char *buf;
  986. u32 len = 0, rc = 0;
  987. u32 max_size = SZ_4K;
  988. if (!debug)
  989. return -ENODEV;
  990. if (*ppos)
  991. return 0;
  992. buf = kzalloc(SZ_4K, GFP_KERNEL);
  993. if (ZERO_OR_NULL_PTR(buf))
  994. return -ENOMEM;
  995. rc = snprintf(buf + len, max_size, "\tstate=0x%x\n", debug->aux->state);
  996. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  997. goto error;
  998. rc = snprintf(buf + len, max_size, "\tlink_rate=%u\n",
  999. debug->panel->link_info.rate);
  1000. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1001. goto error;
  1002. rc = snprintf(buf + len, max_size, "\tnum_lanes=%u\n",
  1003. debug->panel->link_info.num_lanes);
  1004. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1005. goto error;
  1006. rc = snprintf(buf + len, max_size, "\tresolution=%dx%d@%dHz\n",
  1007. debug->panel->pinfo.h_active,
  1008. debug->panel->pinfo.v_active,
  1009. debug->panel->pinfo.refresh_rate);
  1010. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1011. goto error;
  1012. rc = snprintf(buf + len, max_size, "\tpclock=%dKHz\n",
  1013. debug->panel->pinfo.pixel_clk_khz);
  1014. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1015. goto error;
  1016. rc = snprintf(buf + len, max_size, "\tbpp=%d\n",
  1017. debug->panel->pinfo.bpp);
  1018. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1019. goto error;
  1020. /* Link Information */
  1021. rc = snprintf(buf + len, max_size, "\ttest_req=%s\n",
  1022. dp_link_get_test_name(debug->link->sink_request));
  1023. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1024. goto error;
  1025. rc = snprintf(buf + len, max_size,
  1026. "\tlane_count=%d\n", debug->link->link_params.lane_count);
  1027. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1028. goto error;
  1029. rc = snprintf(buf + len, max_size,
  1030. "\tbw_code=%d\n", debug->link->link_params.bw_code);
  1031. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1032. goto error;
  1033. rc = snprintf(buf + len, max_size,
  1034. "\tv_level=%d\n", debug->link->phy_params.v_level);
  1035. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1036. goto error;
  1037. rc = snprintf(buf + len, max_size,
  1038. "\tp_level=%d\n", debug->link->phy_params.p_level);
  1039. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1040. goto error;
  1041. len = min_t(size_t, count, len);
  1042. if (copy_to_user(user_buff, buf, len))
  1043. goto error;
  1044. *ppos += len;
  1045. kfree(buf);
  1046. return len;
  1047. error:
  1048. kfree(buf);
  1049. return -EINVAL;
  1050. }
  1051. static ssize_t dp_debug_bw_code_read(struct file *file,
  1052. char __user *user_buff, size_t count, loff_t *ppos)
  1053. {
  1054. struct dp_debug_private *debug = file->private_data;
  1055. char *buf;
  1056. u32 len = 0;
  1057. if (!debug)
  1058. return -ENODEV;
  1059. if (*ppos)
  1060. return 0;
  1061. buf = kzalloc(SZ_4K, GFP_KERNEL);
  1062. if (ZERO_OR_NULL_PTR(buf))
  1063. return -ENOMEM;
  1064. len += snprintf(buf + len, (SZ_4K - len),
  1065. "max_bw_code = %d\n", debug->panel->max_bw_code);
  1066. len = min_t(size_t, count, len);
  1067. if (copy_to_user(user_buff, buf, len)) {
  1068. kfree(buf);
  1069. return -EFAULT;
  1070. }
  1071. *ppos += len;
  1072. kfree(buf);
  1073. return len;
  1074. }
  1075. static ssize_t dp_debug_tpg_read(struct file *file,
  1076. char __user *user_buff, size_t count, loff_t *ppos)
  1077. {
  1078. struct dp_debug_private *debug = file->private_data;
  1079. char buf[SZ_8];
  1080. u32 len = 0;
  1081. if (!debug)
  1082. return -ENODEV;
  1083. if (*ppos)
  1084. return 0;
  1085. len += snprintf(buf, SZ_8, "%d\n", debug->dp_debug.tpg_state);
  1086. len = min_t(size_t, count, len);
  1087. if (copy_to_user(user_buff, buf, len))
  1088. return -EFAULT;
  1089. *ppos += len;
  1090. return len;
  1091. }
  1092. static int dp_debug_print_hdr_params_to_buf(struct drm_connector *connector,
  1093. char *buf, u32 size)
  1094. {
  1095. int rc;
  1096. u32 i, len = 0, max_size = size;
  1097. struct sde_connector *c_conn;
  1098. struct sde_connector_state *c_state;
  1099. struct drm_msm_ext_hdr_metadata *hdr;
  1100. c_conn = to_sde_connector(connector);
  1101. c_state = to_sde_connector_state(connector->state);
  1102. hdr = &c_state->hdr_meta;
  1103. rc = snprintf(buf + len, max_size,
  1104. "============SINK HDR PARAMETERS===========\n");
  1105. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1106. goto error;
  1107. rc = snprintf(buf + len, max_size, "eotf = %d\n",
  1108. c_conn->hdr_eotf);
  1109. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1110. goto error;
  1111. rc = snprintf(buf + len, max_size, "type_one = %d\n",
  1112. c_conn->hdr_metadata_type_one);
  1113. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1114. goto error;
  1115. rc = snprintf(buf + len, max_size, "hdr_plus_app_ver = %d\n",
  1116. c_conn->hdr_plus_app_ver);
  1117. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1118. goto error;
  1119. rc = snprintf(buf + len, max_size, "max_luminance = %d\n",
  1120. c_conn->hdr_max_luminance);
  1121. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1122. goto error;
  1123. rc = snprintf(buf + len, max_size, "avg_luminance = %d\n",
  1124. c_conn->hdr_avg_luminance);
  1125. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1126. goto error;
  1127. rc = snprintf(buf + len, max_size, "min_luminance = %d\n",
  1128. c_conn->hdr_min_luminance);
  1129. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1130. goto error;
  1131. rc = snprintf(buf + len, max_size,
  1132. "============VIDEO HDR PARAMETERS===========\n");
  1133. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1134. goto error;
  1135. rc = snprintf(buf + len, max_size, "hdr_state = %d\n", hdr->hdr_state);
  1136. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1137. goto error;
  1138. rc = snprintf(buf + len, max_size, "hdr_supported = %d\n",
  1139. hdr->hdr_supported);
  1140. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1141. goto error;
  1142. rc = snprintf(buf + len, max_size, "eotf = %d\n", hdr->eotf);
  1143. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1144. goto error;
  1145. rc = snprintf(buf + len, max_size, "white_point_x = %d\n",
  1146. hdr->white_point_x);
  1147. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1148. goto error;
  1149. rc = snprintf(buf + len, max_size, "white_point_y = %d\n",
  1150. hdr->white_point_y);
  1151. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1152. goto error;
  1153. rc = snprintf(buf + len, max_size, "max_luminance = %d\n",
  1154. hdr->max_luminance);
  1155. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1156. goto error;
  1157. rc = snprintf(buf + len, max_size, "min_luminance = %d\n",
  1158. hdr->min_luminance);
  1159. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1160. goto error;
  1161. rc = snprintf(buf + len, max_size, "max_content_light_level = %d\n",
  1162. hdr->max_content_light_level);
  1163. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1164. goto error;
  1165. rc = snprintf(buf + len, max_size, "min_content_light_level = %d\n",
  1166. hdr->max_average_light_level);
  1167. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1168. goto error;
  1169. for (i = 0; i < HDR_PRIMARIES_COUNT; i++) {
  1170. rc = snprintf(buf + len, max_size, "primaries_x[%d] = %d\n",
  1171. i, hdr->display_primaries_x[i]);
  1172. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1173. goto error;
  1174. rc = snprintf(buf + len, max_size, "primaries_y[%d] = %d\n",
  1175. i, hdr->display_primaries_y[i]);
  1176. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1177. goto error;
  1178. }
  1179. if (hdr->hdr_plus_payload && hdr->hdr_plus_payload_size) {
  1180. u32 rowsize = 16, rem;
  1181. struct sde_connector_dyn_hdr_metadata *dhdr =
  1182. &c_state->dyn_hdr_meta;
  1183. /**
  1184. * Do not use user pointer from hdr->hdr_plus_payload directly,
  1185. * instead use kernel's cached copy of payload data.
  1186. */
  1187. for (i = 0; i < dhdr->dynamic_hdr_payload_size; i += rowsize) {
  1188. rc = snprintf(buf + len, max_size, "DHDR: ");
  1189. if (dp_debug_check_buffer_overflow(rc, &max_size,
  1190. &len))
  1191. goto error;
  1192. rem = dhdr->dynamic_hdr_payload_size - i;
  1193. rc = hex_dump_to_buffer(&dhdr->dynamic_hdr_payload[i],
  1194. min(rowsize, rem), rowsize, 1, buf + len,
  1195. max_size, false);
  1196. if (dp_debug_check_buffer_overflow(rc, &max_size,
  1197. &len))
  1198. goto error;
  1199. rc = snprintf(buf + len, max_size, "\n");
  1200. if (dp_debug_check_buffer_overflow(rc, &max_size,
  1201. &len))
  1202. goto error;
  1203. }
  1204. }
  1205. return len;
  1206. error:
  1207. return -EOVERFLOW;
  1208. }
  1209. static ssize_t dp_debug_read_hdr(struct file *file,
  1210. char __user *user_buff, size_t count, loff_t *ppos)
  1211. {
  1212. struct dp_debug_private *debug = file->private_data;
  1213. char *buf = NULL;
  1214. u32 len = 0;
  1215. u32 max_size = SZ_4K;
  1216. struct drm_connector *connector;
  1217. if (!debug) {
  1218. DP_ERR("invalid data\n");
  1219. return -ENODEV;
  1220. }
  1221. connector = *debug->connector;
  1222. if (!connector) {
  1223. DP_ERR("connector is NULL\n");
  1224. return -EINVAL;
  1225. }
  1226. if (*ppos)
  1227. return 0;
  1228. buf = kzalloc(max_size, GFP_KERNEL);
  1229. if (ZERO_OR_NULL_PTR(buf))
  1230. return -ENOMEM;
  1231. len = dp_debug_print_hdr_params_to_buf(connector, buf, max_size);
  1232. if (len == -EOVERFLOW) {
  1233. kfree(buf);
  1234. return len;
  1235. }
  1236. len = min_t(size_t, count, len);
  1237. if (copy_to_user(user_buff, buf, len)) {
  1238. kfree(buf);
  1239. return -EFAULT;
  1240. }
  1241. *ppos += len;
  1242. kfree(buf);
  1243. return len;
  1244. }
  1245. static ssize_t dp_debug_read_hdr_mst(struct file *file,
  1246. char __user *user_buff, size_t count, loff_t *ppos)
  1247. {
  1248. struct dp_debug_private *debug = file->private_data;
  1249. char *buf = NULL;
  1250. u32 len = 0, max_size = SZ_4K;
  1251. struct drm_connector_list_iter conn_iter;
  1252. struct drm_connector *connector;
  1253. bool in_list = false;
  1254. if (!debug) {
  1255. DP_ERR("invalid data\n");
  1256. return -ENODEV;
  1257. }
  1258. drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
  1259. drm_for_each_connector_iter(connector, &conn_iter) {
  1260. if (connector->base.id == debug->mst_con_id) {
  1261. in_list = true;
  1262. break;
  1263. }
  1264. }
  1265. drm_connector_list_iter_end(&conn_iter);
  1266. if (!in_list) {
  1267. DP_ERR("connector %u not in mst list\n", debug->mst_con_id);
  1268. return -EINVAL;
  1269. }
  1270. if (!connector) {
  1271. DP_ERR("connector is NULL\n");
  1272. return -EINVAL;
  1273. }
  1274. if (*ppos)
  1275. return 0;
  1276. buf = kzalloc(max_size, GFP_KERNEL);
  1277. if (ZERO_OR_NULL_PTR(buf))
  1278. return -ENOMEM;
  1279. len = dp_debug_print_hdr_params_to_buf(connector, buf, max_size);
  1280. if (len == -EOVERFLOW) {
  1281. kfree(buf);
  1282. return len;
  1283. }
  1284. len = min_t(size_t, count, len);
  1285. if (copy_to_user(user_buff, buf, len)) {
  1286. kfree(buf);
  1287. return -EFAULT;
  1288. }
  1289. *ppos += len;
  1290. kfree(buf);
  1291. return len;
  1292. }
  1293. static void dp_debug_set_sim_mode(struct dp_debug_private *debug, bool sim)
  1294. {
  1295. struct drm_connector_list_iter conn_iter;
  1296. struct drm_connector *connector;
  1297. struct sde_connector *sde_conn;
  1298. struct dp_display *display;
  1299. struct dp_panel *panel;
  1300. if (sim) {
  1301. debug->dp_debug.sim_mode = true;
  1302. dp_debug_enable_sim_mode(debug, DP_SIM_MODE_ALL);
  1303. } else {
  1304. if (debug->hotplug) {
  1305. DP_WARN("sim mode off before hotplug disconnect\n");
  1306. debug->hpd->simulate_connect(debug->hpd, false);
  1307. debug->hotplug = false;
  1308. }
  1309. debug->aux->abort(debug->aux, true);
  1310. debug->ctrl->abort(debug->ctrl, true);
  1311. debug->dp_debug.sim_mode = false;
  1312. debug->mst_edid_idx = 0;
  1313. dp_debug_disable_sim_mode(debug, DP_SIM_MODE_ALL);
  1314. }
  1315. /* clear override settings in panel */
  1316. drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
  1317. drm_for_each_connector_iter(connector, &conn_iter) {
  1318. sde_conn = to_sde_connector(connector);
  1319. display = sde_conn->display;
  1320. if (display->base_connector == (*debug->connector)) {
  1321. panel = sde_conn->drv_panel;
  1322. panel->mode_override = false;
  1323. panel->mst_hide = false;
  1324. }
  1325. }
  1326. drm_connector_list_iter_end(&conn_iter);
  1327. /*
  1328. * print simulation status as this code is executed
  1329. * only while running in debug mode which is manually
  1330. * triggered by a tester or a script.
  1331. */
  1332. DP_INFO("%s\n", sim ? "[ON]" : "[OFF]");
  1333. }
  1334. static ssize_t dp_debug_write_sim(struct file *file,
  1335. const char __user *user_buff, size_t count, loff_t *ppos)
  1336. {
  1337. struct dp_debug_private *debug = file->private_data;
  1338. char buf[SZ_8];
  1339. size_t len = 0;
  1340. int sim;
  1341. if (!debug)
  1342. return -ENODEV;
  1343. if (*ppos)
  1344. return 0;
  1345. mutex_lock(&debug->lock);
  1346. /* Leave room for termination char */
  1347. len = min_t(size_t, count, SZ_8 - 1);
  1348. if (copy_from_user(buf, user_buff, len))
  1349. goto end;
  1350. buf[len] = '\0';
  1351. if (kstrtoint(buf, 10, &sim) != 0)
  1352. goto end;
  1353. dp_debug_set_sim_mode(debug, sim);
  1354. end:
  1355. mutex_unlock(&debug->lock);
  1356. return len;
  1357. }
  1358. static ssize_t dp_debug_write_attention(struct file *file,
  1359. const char __user *user_buff, size_t count, loff_t *ppos)
  1360. {
  1361. struct dp_debug_private *debug = file->private_data;
  1362. char buf[SZ_8];
  1363. size_t len = 0;
  1364. int vdo;
  1365. if (!debug)
  1366. return -ENODEV;
  1367. if (*ppos)
  1368. return 0;
  1369. /* Leave room for termination char */
  1370. len = min_t(size_t, count, SZ_8 - 1);
  1371. if (copy_from_user(buf, user_buff, len))
  1372. goto end;
  1373. buf[len] = '\0';
  1374. if (kstrtoint(buf, 10, &vdo) != 0)
  1375. goto end;
  1376. debug->hpd->simulate_attention(debug->hpd, vdo);
  1377. end:
  1378. return len;
  1379. }
  1380. static ssize_t dp_debug_write_dump(struct file *file,
  1381. const char __user *user_buff, size_t count, loff_t *ppos)
  1382. {
  1383. struct dp_debug_private *debug = file->private_data;
  1384. char buf[SZ_32];
  1385. size_t len = 0;
  1386. if (!debug)
  1387. return -ENODEV;
  1388. if (*ppos)
  1389. return 0;
  1390. /* Leave room for termination char */
  1391. len = min_t(size_t, count, SZ_32 - 1);
  1392. if (copy_from_user(buf, user_buff, len))
  1393. goto end;
  1394. buf[len] = '\0';
  1395. if (sscanf(buf, "%31s", debug->reg_dump) != 1)
  1396. goto end;
  1397. /* qfprom register dump not supported */
  1398. if (!strcmp(debug->reg_dump, "qfprom_physical"))
  1399. strlcpy(debug->reg_dump, "clear", sizeof(debug->reg_dump));
  1400. end:
  1401. return len;
  1402. }
  1403. static ssize_t dp_debug_read_dump(struct file *file,
  1404. char __user *user_buff, size_t count, loff_t *ppos)
  1405. {
  1406. int rc = 0;
  1407. struct dp_debug_private *debug = file->private_data;
  1408. u8 *buf = NULL;
  1409. u32 len = 0;
  1410. char prefix[SZ_32];
  1411. if (!debug)
  1412. return -ENODEV;
  1413. if (*ppos)
  1414. return 0;
  1415. if (!debug->hpd->hpd_high || !strlen(debug->reg_dump))
  1416. goto end;
  1417. rc = debug->catalog->get_reg_dump(debug->catalog,
  1418. debug->reg_dump, &buf, &len);
  1419. if (rc)
  1420. goto end;
  1421. snprintf(prefix, sizeof(prefix), "%s: ", debug->reg_dump);
  1422. print_hex_dump_debug(prefix, DUMP_PREFIX_NONE,
  1423. 16, 4, buf, len, false);
  1424. len = min_t(size_t, count, len);
  1425. if (copy_to_user(user_buff, buf, len))
  1426. return -EFAULT;
  1427. *ppos += len;
  1428. end:
  1429. return len;
  1430. }
  1431. static const struct file_operations dp_debug_fops = {
  1432. .open = simple_open,
  1433. .read = dp_debug_read_info,
  1434. };
  1435. static const struct file_operations edid_modes_fops = {
  1436. .open = simple_open,
  1437. .read = dp_debug_read_edid_modes,
  1438. .write = dp_debug_write_edid_modes,
  1439. };
  1440. static const struct file_operations edid_modes_mst_fops = {
  1441. .open = simple_open,
  1442. .read = dp_debug_read_edid_modes_mst,
  1443. .write = dp_debug_write_edid_modes_mst,
  1444. };
  1445. static const struct file_operations mst_conn_info_fops = {
  1446. .open = simple_open,
  1447. .read = dp_debug_read_mst_conn_info,
  1448. };
  1449. static const struct file_operations mst_con_id_fops = {
  1450. .open = simple_open,
  1451. .read = dp_debug_read_mst_con_id,
  1452. .write = dp_debug_write_mst_con_id,
  1453. };
  1454. static const struct file_operations mst_con_add_fops = {
  1455. .open = simple_open,
  1456. .write = dp_debug_write_mst_con_add,
  1457. };
  1458. static const struct file_operations mst_con_remove_fops = {
  1459. .open = simple_open,
  1460. .write = dp_debug_write_mst_con_remove,
  1461. };
  1462. static const struct file_operations hpd_fops = {
  1463. .open = simple_open,
  1464. .write = dp_debug_write_hpd,
  1465. };
  1466. static const struct file_operations edid_fops = {
  1467. .open = simple_open,
  1468. .write = dp_debug_write_edid,
  1469. };
  1470. static const struct file_operations dpcd_fops = {
  1471. .open = simple_open,
  1472. .write = dp_debug_write_dpcd,
  1473. .read = dp_debug_read_dpcd,
  1474. };
  1475. static const struct file_operations connected_fops = {
  1476. .open = simple_open,
  1477. .read = dp_debug_read_connected,
  1478. };
  1479. static const struct file_operations bw_code_fops = {
  1480. .open = simple_open,
  1481. .read = dp_debug_bw_code_read,
  1482. .write = dp_debug_bw_code_write,
  1483. };
  1484. static const struct file_operations exe_mode_fops = {
  1485. .open = simple_open,
  1486. .write = dp_debug_write_exe_mode,
  1487. };
  1488. static const struct file_operations tpg_fops = {
  1489. .open = simple_open,
  1490. .read = dp_debug_tpg_read,
  1491. .write = dp_debug_tpg_write,
  1492. };
  1493. static const struct file_operations hdr_fops = {
  1494. .open = simple_open,
  1495. .read = dp_debug_read_hdr,
  1496. };
  1497. static const struct file_operations hdr_mst_fops = {
  1498. .open = simple_open,
  1499. .read = dp_debug_read_hdr_mst,
  1500. };
  1501. static const struct file_operations sim_fops = {
  1502. .open = simple_open,
  1503. .write = dp_debug_write_sim,
  1504. };
  1505. static const struct file_operations attention_fops = {
  1506. .open = simple_open,
  1507. .write = dp_debug_write_attention,
  1508. };
  1509. static const struct file_operations dump_fops = {
  1510. .open = simple_open,
  1511. .write = dp_debug_write_dump,
  1512. .read = dp_debug_read_dump,
  1513. };
  1514. static const struct file_operations mst_mode_fops = {
  1515. .open = simple_open,
  1516. .write = dp_debug_mst_mode_write,
  1517. .read = dp_debug_mst_mode_read,
  1518. };
  1519. static const struct file_operations mst_sideband_mode_fops = {
  1520. .open = simple_open,
  1521. .write = dp_debug_mst_sideband_mode_write,
  1522. };
  1523. static const struct file_operations max_pclk_khz_fops = {
  1524. .open = simple_open,
  1525. .write = dp_debug_max_pclk_khz_write,
  1526. .read = dp_debug_max_pclk_khz_read,
  1527. };
  1528. static const struct file_operations hdcp_fops = {
  1529. .open = simple_open,
  1530. .write = dp_debug_write_hdcp,
  1531. .read = dp_debug_read_hdcp,
  1532. };
  1533. static const struct file_operations mmrm_clk_cb_fops = {
  1534. .open = simple_open,
  1535. .write = dp_debug_mmrm_clk_cb_write,
  1536. };
  1537. static int dp_debug_init_mst(struct dp_debug_private *debug, struct dentry *dir)
  1538. {
  1539. int rc = 0;
  1540. struct dentry *file;
  1541. file = debugfs_create_file("mst_con_id", 0644, dir,
  1542. debug, &mst_con_id_fops);
  1543. if (IS_ERR_OR_NULL(file)) {
  1544. rc = PTR_ERR(file);
  1545. DP_ERR("[%s] debugfs create mst_con_id failed, rc=%d\n",
  1546. DEBUG_NAME, rc);
  1547. return rc;
  1548. }
  1549. file = debugfs_create_file("mst_con_info", 0644, dir,
  1550. debug, &mst_conn_info_fops);
  1551. if (IS_ERR_OR_NULL(file)) {
  1552. rc = PTR_ERR(file);
  1553. DP_ERR("[%s] debugfs create mst_conn_info failed, rc=%d\n",
  1554. DEBUG_NAME, rc);
  1555. return rc;
  1556. }
  1557. file = debugfs_create_file("mst_con_add", 0644, dir,
  1558. debug, &mst_con_add_fops);
  1559. if (IS_ERR_OR_NULL(file)) {
  1560. rc = PTR_ERR(file);
  1561. DRM_ERROR("[%s] debugfs create mst_con_add failed, rc=%d\n",
  1562. DEBUG_NAME, rc);
  1563. return rc;
  1564. }
  1565. file = debugfs_create_file("mst_con_remove", 0644, dir,
  1566. debug, &mst_con_remove_fops);
  1567. if (IS_ERR_OR_NULL(file)) {
  1568. rc = PTR_ERR(file);
  1569. DRM_ERROR("[%s] debugfs create mst_con_remove failed, rc=%d\n",
  1570. DEBUG_NAME, rc);
  1571. return rc;
  1572. }
  1573. file = debugfs_create_file("mst_mode", 0644, dir,
  1574. debug, &mst_mode_fops);
  1575. if (IS_ERR_OR_NULL(file)) {
  1576. rc = PTR_ERR(file);
  1577. DP_ERR("[%s] debugfs mst_mode failed, rc=%d\n",
  1578. DEBUG_NAME, rc);
  1579. return rc;
  1580. }
  1581. file = debugfs_create_file("mst_sideband_mode", 0644, dir,
  1582. debug, &mst_sideband_mode_fops);
  1583. if (IS_ERR_OR_NULL(file)) {
  1584. rc = PTR_ERR(file);
  1585. DP_ERR("[%s] debugfs mst_sideband_mode failed, rc=%d\n",
  1586. DEBUG_NAME, rc);
  1587. return rc;
  1588. }
  1589. debugfs_create_u32("mst_edid_idx", 0644, dir, &debug->mst_edid_idx);
  1590. return rc;
  1591. }
  1592. static int dp_debug_init_link(struct dp_debug_private *debug,
  1593. struct dentry *dir)
  1594. {
  1595. int rc = 0;
  1596. struct dentry *file;
  1597. file = debugfs_create_file("max_bw_code", 0644, dir,
  1598. debug, &bw_code_fops);
  1599. if (IS_ERR_OR_NULL(file)) {
  1600. rc = PTR_ERR(file);
  1601. DP_ERR("[%s] debugfs max_bw_code failed, rc=%d\n",
  1602. DEBUG_NAME, rc);
  1603. return rc;
  1604. }
  1605. file = debugfs_create_file("max_pclk_khz", 0644, dir,
  1606. debug, &max_pclk_khz_fops);
  1607. if (IS_ERR_OR_NULL(file)) {
  1608. rc = PTR_ERR(file);
  1609. DP_ERR("[%s] debugfs max_pclk_khz failed, rc=%d\n",
  1610. DEBUG_NAME, rc);
  1611. return rc;
  1612. }
  1613. debugfs_create_u32("max_lclk_khz", 0644, dir, &debug->parser->max_lclk_khz);
  1614. debugfs_create_u32("lane_count", 0644, dir, &debug->panel->lane_count);
  1615. debugfs_create_u32("link_bw_code", 0644, dir, &debug->panel->link_bw_code);
  1616. file = debugfs_create_file("mmrm_clk_cb", 0644, dir, debug, &mmrm_clk_cb_fops);
  1617. if (IS_ERR_OR_NULL(file)) {
  1618. rc = PTR_ERR(file);
  1619. DP_ERR("[%s] debugfs mmrm_clk_cb failed, rc=%d\n", DEBUG_NAME, rc);
  1620. return rc;
  1621. }
  1622. return rc;
  1623. }
  1624. static int dp_debug_init_hdcp(struct dp_debug_private *debug,
  1625. struct dentry *dir)
  1626. {
  1627. int rc = 0;
  1628. struct dentry *file;
  1629. file = debugfs_create_bool("hdcp_wait_sink_sync", 0644, dir,
  1630. &debug->dp_debug.hdcp_wait_sink_sync);
  1631. if (IS_ERR_OR_NULL(file)) {
  1632. rc = PTR_ERR(file);
  1633. DP_ERR("[%s] debugfs hdcp_wait_sink_sync failed, rc=%d\n",
  1634. DEBUG_NAME, rc);
  1635. return rc;
  1636. }
  1637. file = debugfs_create_bool("force_encryption", 0644, dir,
  1638. &debug->dp_debug.force_encryption);
  1639. if (IS_ERR_OR_NULL(file)) {
  1640. rc = PTR_ERR(file);
  1641. DP_ERR("[%s] debugfs force_encryption failed, rc=%d\n",
  1642. DEBUG_NAME, rc);
  1643. return rc;
  1644. }
  1645. return rc;
  1646. }
  1647. static int dp_debug_init_sink_caps(struct dp_debug_private *debug,
  1648. struct dentry *dir)
  1649. {
  1650. int rc = 0;
  1651. struct dentry *file;
  1652. file = debugfs_create_file("edid_modes", 0644, dir,
  1653. debug, &edid_modes_fops);
  1654. if (IS_ERR_OR_NULL(file)) {
  1655. rc = PTR_ERR(file);
  1656. DP_ERR("[%s] debugfs create edid_modes failed, rc=%d\n",
  1657. DEBUG_NAME, rc);
  1658. return rc;
  1659. }
  1660. file = debugfs_create_file("edid_modes_mst", 0644, dir,
  1661. debug, &edid_modes_mst_fops);
  1662. if (IS_ERR_OR_NULL(file)) {
  1663. rc = PTR_ERR(file);
  1664. DP_ERR("[%s] debugfs create edid_modes_mst failed, rc=%d\n",
  1665. DEBUG_NAME, rc);
  1666. return rc;
  1667. }
  1668. file = debugfs_create_file("edid", 0644, dir,
  1669. debug, &edid_fops);
  1670. if (IS_ERR_OR_NULL(file)) {
  1671. rc = PTR_ERR(file);
  1672. DP_ERR("[%s] debugfs edid failed, rc=%d\n",
  1673. DEBUG_NAME, rc);
  1674. return rc;
  1675. }
  1676. file = debugfs_create_file("dpcd", 0644, dir,
  1677. debug, &dpcd_fops);
  1678. if (IS_ERR_OR_NULL(file)) {
  1679. rc = PTR_ERR(file);
  1680. DP_ERR("[%s] debugfs dpcd failed, rc=%d\n",
  1681. DEBUG_NAME, rc);
  1682. return rc;
  1683. }
  1684. return rc;
  1685. }
  1686. static int dp_debug_init_status(struct dp_debug_private *debug,
  1687. struct dentry *dir)
  1688. {
  1689. int rc = 0;
  1690. struct dentry *file;
  1691. file = debugfs_create_file("dp_debug", 0444, dir,
  1692. debug, &dp_debug_fops);
  1693. if (IS_ERR_OR_NULL(file)) {
  1694. rc = PTR_ERR(file);
  1695. DP_ERR("[%s] debugfs create file failed, rc=%d\n",
  1696. DEBUG_NAME, rc);
  1697. return rc;
  1698. }
  1699. file = debugfs_create_file("connected", 0444, dir,
  1700. debug, &connected_fops);
  1701. if (IS_ERR_OR_NULL(file)) {
  1702. rc = PTR_ERR(file);
  1703. DP_ERR("[%s] debugfs connected failed, rc=%d\n",
  1704. DEBUG_NAME, rc);
  1705. return rc;
  1706. }
  1707. file = debugfs_create_file("hdr", 0400, dir, debug, &hdr_fops);
  1708. if (IS_ERR_OR_NULL(file)) {
  1709. rc = PTR_ERR(file);
  1710. DP_ERR("[%s] debugfs hdr failed, rc=%d\n",
  1711. DEBUG_NAME, rc);
  1712. return rc;
  1713. }
  1714. file = debugfs_create_file("hdr_mst", 0400, dir, debug, &hdr_mst_fops);
  1715. if (IS_ERR_OR_NULL(file)) {
  1716. rc = PTR_ERR(file);
  1717. DP_ERR("[%s] debugfs hdr_mst failed, rc=%d\n",
  1718. DEBUG_NAME, rc);
  1719. return rc;
  1720. }
  1721. file = debugfs_create_file("hdcp", 0644, dir, debug, &hdcp_fops);
  1722. if (IS_ERR_OR_NULL(file)) {
  1723. rc = PTR_ERR(file);
  1724. DP_ERR("[%s] debugfs hdcp failed, rc=%d\n",
  1725. DEBUG_NAME, rc);
  1726. return rc;
  1727. }
  1728. return rc;
  1729. }
  1730. static int dp_debug_init_sim(struct dp_debug_private *debug, struct dentry *dir)
  1731. {
  1732. int rc = 0;
  1733. struct dentry *file;
  1734. file = debugfs_create_file("hpd", 0644, dir, debug, &hpd_fops);
  1735. if (IS_ERR_OR_NULL(file)) {
  1736. rc = PTR_ERR(file);
  1737. DP_ERR("[%s] debugfs hpd failed, rc=%d\n",
  1738. DEBUG_NAME, rc);
  1739. return rc;
  1740. }
  1741. file = debugfs_create_file("sim", 0644, dir, debug, &sim_fops);
  1742. if (IS_ERR_OR_NULL(file)) {
  1743. rc = PTR_ERR(file);
  1744. DP_ERR("[%s] debugfs sim failed, rc=%d\n",
  1745. DEBUG_NAME, rc);
  1746. return rc;
  1747. }
  1748. file = debugfs_create_file("attention", 0644, dir,
  1749. debug, &attention_fops);
  1750. if (IS_ERR_OR_NULL(file)) {
  1751. rc = PTR_ERR(file);
  1752. DP_ERR("[%s] debugfs attention failed, rc=%d\n",
  1753. DEBUG_NAME, rc);
  1754. return rc;
  1755. }
  1756. file = debugfs_create_bool("skip_uevent", 0644, dir,
  1757. &debug->dp_debug.skip_uevent);
  1758. if (IS_ERR_OR_NULL(file)) {
  1759. rc = PTR_ERR(file);
  1760. DP_ERR("[%s] debugfs skip_uevent failed, rc=%d\n",
  1761. DEBUG_NAME, rc);
  1762. return rc;
  1763. }
  1764. file = debugfs_create_bool("force_multi_func", 0644, dir,
  1765. &debug->hpd->force_multi_func);
  1766. if (IS_ERR_OR_NULL(file)) {
  1767. rc = PTR_ERR(file);
  1768. DP_ERR("[%s] debugfs force_multi_func failed, rc=%d\n",
  1769. DEBUG_NAME, rc);
  1770. return rc;
  1771. }
  1772. return rc;
  1773. }
  1774. static int dp_debug_init_dsc_fec(struct dp_debug_private *debug,
  1775. struct dentry *dir)
  1776. {
  1777. int rc = 0;
  1778. struct dentry *file;
  1779. file = debugfs_create_bool("dsc_feature_enable", 0644, dir,
  1780. &debug->parser->dsc_feature_enable);
  1781. if (IS_ERR_OR_NULL(file)) {
  1782. rc = PTR_ERR(file);
  1783. DP_ERR("[%s] debugfs dsc_feature failed, rc=%d\n",
  1784. DEBUG_NAME, rc);
  1785. return rc;
  1786. }
  1787. file = debugfs_create_bool("fec_feature_enable", 0644, dir,
  1788. &debug->parser->fec_feature_enable);
  1789. if (IS_ERR_OR_NULL(file)) {
  1790. rc = PTR_ERR(file);
  1791. DP_ERR("[%s] debugfs fec_feature_enable failed, rc=%d\n",
  1792. DEBUG_NAME, rc);
  1793. return rc;
  1794. }
  1795. return rc;
  1796. }
  1797. static int dp_debug_init_tpg(struct dp_debug_private *debug, struct dentry *dir)
  1798. {
  1799. int rc = 0;
  1800. struct dentry *file;
  1801. file = debugfs_create_file("tpg_ctrl", 0644, dir,
  1802. debug, &tpg_fops);
  1803. if (IS_ERR_OR_NULL(file)) {
  1804. rc = PTR_ERR(file);
  1805. DP_ERR("[%s] debugfs tpg failed, rc=%d\n",
  1806. DEBUG_NAME, rc);
  1807. return rc;
  1808. }
  1809. return rc;
  1810. }
  1811. static int dp_debug_init_reg_dump(struct dp_debug_private *debug,
  1812. struct dentry *dir)
  1813. {
  1814. int rc = 0;
  1815. struct dentry *file;
  1816. file = debugfs_create_file("exe_mode", 0644, dir,
  1817. debug, &exe_mode_fops);
  1818. if (IS_ERR_OR_NULL(file)) {
  1819. rc = PTR_ERR(file);
  1820. DP_ERR("[%s] debugfs register failed, rc=%d\n",
  1821. DEBUG_NAME, rc);
  1822. return rc;
  1823. }
  1824. file = debugfs_create_file("dump", 0644, dir,
  1825. debug, &dump_fops);
  1826. if (IS_ERR_OR_NULL(file)) {
  1827. rc = PTR_ERR(file);
  1828. DP_ERR("[%s] debugfs dump failed, rc=%d\n",
  1829. DEBUG_NAME, rc);
  1830. return rc;
  1831. }
  1832. return rc;
  1833. }
  1834. static int dp_debug_init_feature_toggle(struct dp_debug_private *debug,
  1835. struct dentry *dir)
  1836. {
  1837. int rc = 0;
  1838. struct dentry *file;
  1839. file = debugfs_create_bool("ssc_enable", 0644, dir,
  1840. &debug->pll->ssc_en);
  1841. if (IS_ERR_OR_NULL(file)) {
  1842. rc = PTR_ERR(file);
  1843. DP_ERR("[%s] debugfs ssc_enable failed, rc=%d\n",
  1844. DEBUG_NAME, rc);
  1845. return rc;
  1846. }
  1847. file = debugfs_create_bool("widebus_mode", 0644, dir,
  1848. &debug->parser->has_widebus);
  1849. if (IS_ERR_OR_NULL(file)) {
  1850. rc = PTR_ERR(file);
  1851. DP_ERR("[%s] debugfs widebus_mode failed, rc=%d\n",
  1852. DEBUG_NAME, rc);
  1853. return rc;
  1854. }
  1855. return rc;
  1856. }
  1857. static int dp_debug_init_configs(struct dp_debug_private *debug,
  1858. struct dentry *dir)
  1859. {
  1860. int rc = 0;
  1861. struct dentry *file;
  1862. file = debugfs_create_ulong("connect_notification_delay_ms", 0644, dir,
  1863. &debug->dp_debug.connect_notification_delay_ms);
  1864. if (IS_ERR_OR_NULL(file)) {
  1865. rc = PTR_ERR(file);
  1866. DP_ERR("[%s] debugfs connect_notification_delay_ms failed, rc=%d\n",
  1867. DEBUG_NAME, rc);
  1868. return rc;
  1869. }
  1870. debug->dp_debug.connect_notification_delay_ms =
  1871. DEFAULT_CONNECT_NOTIFICATION_DELAY_MS;
  1872. debugfs_create_u32("disconnect_delay_ms", 0644, dir, &debug->dp_debug.disconnect_delay_ms);
  1873. debug->dp_debug.disconnect_delay_ms = DEFAULT_DISCONNECT_DELAY_MS;
  1874. return rc;
  1875. }
  1876. static int dp_debug_init(struct dp_debug *dp_debug)
  1877. {
  1878. int rc = 0;
  1879. struct dp_debug_private *debug = container_of(dp_debug,
  1880. struct dp_debug_private, dp_debug);
  1881. struct dentry *dir;
  1882. if (!IS_ENABLED(CONFIG_DEBUG_FS)) {
  1883. DP_WARN("Not creating debug root dir.");
  1884. debug->root = NULL;
  1885. return 0;
  1886. }
  1887. dir = debugfs_create_dir(DEBUG_NAME, NULL);
  1888. if (IS_ERR_OR_NULL(dir)) {
  1889. if (!dir)
  1890. rc = -EINVAL;
  1891. else
  1892. rc = PTR_ERR(dir);
  1893. DP_ERR("[%s] debugfs create dir failed, rc = %d\n",
  1894. DEBUG_NAME, rc);
  1895. goto error;
  1896. }
  1897. debug->root = dir;
  1898. rc = dp_debug_init_status(debug, dir);
  1899. if (rc)
  1900. goto error_remove_dir;
  1901. rc = dp_debug_init_sink_caps(debug, dir);
  1902. if (rc)
  1903. goto error_remove_dir;
  1904. rc = dp_debug_init_mst(debug, dir);
  1905. if (rc)
  1906. goto error_remove_dir;
  1907. rc = dp_debug_init_link(debug, dir);
  1908. if (rc)
  1909. goto error_remove_dir;
  1910. rc = dp_debug_init_hdcp(debug, dir);
  1911. if (rc)
  1912. goto error_remove_dir;
  1913. rc = dp_debug_init_sim(debug, dir);
  1914. if (rc)
  1915. goto error_remove_dir;
  1916. rc = dp_debug_init_dsc_fec(debug, dir);
  1917. if (rc)
  1918. goto error_remove_dir;
  1919. rc = dp_debug_init_tpg(debug, dir);
  1920. if (rc)
  1921. goto error_remove_dir;
  1922. rc = dp_debug_init_reg_dump(debug, dir);
  1923. if (rc)
  1924. goto error_remove_dir;
  1925. rc = dp_debug_init_feature_toggle(debug, dir);
  1926. if (rc)
  1927. goto error_remove_dir;
  1928. rc = dp_debug_init_configs(debug, dir);
  1929. if (rc)
  1930. goto error_remove_dir;
  1931. return 0;
  1932. error_remove_dir:
  1933. debugfs_remove_recursive(dir);
  1934. error:
  1935. return rc;
  1936. }
  1937. static void dp_debug_abort(struct dp_debug *dp_debug)
  1938. {
  1939. struct dp_debug_private *debug;
  1940. if (!dp_debug)
  1941. return;
  1942. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  1943. mutex_lock(&debug->lock);
  1944. dp_debug_set_sim_mode(debug, false);
  1945. mutex_unlock(&debug->lock);
  1946. }
  1947. static void dp_debug_set_mst_con(struct dp_debug *dp_debug, int con_id)
  1948. {
  1949. struct dp_debug_private *debug;
  1950. if (!dp_debug)
  1951. return;
  1952. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  1953. mutex_lock(&debug->lock);
  1954. debug->mst_con_id = con_id;
  1955. mutex_unlock(&debug->lock);
  1956. DP_INFO("Selecting mst connector %d\n", con_id);
  1957. }
  1958. struct dp_debug *dp_debug_get(struct dp_debug_in *in)
  1959. {
  1960. int rc = 0;
  1961. struct dp_debug_private *debug;
  1962. struct dp_debug *dp_debug;
  1963. if (!in->dev || !in->panel || !in->hpd || !in->link ||
  1964. !in->catalog || !in->ctrl || !in->pll) {
  1965. DP_ERR("invalid input\n");
  1966. rc = -EINVAL;
  1967. goto error;
  1968. }
  1969. debug = devm_kzalloc(in->dev, sizeof(*debug), GFP_KERNEL);
  1970. if (!debug) {
  1971. rc = -ENOMEM;
  1972. goto error;
  1973. }
  1974. debug->hpd = in->hpd;
  1975. debug->link = in->link;
  1976. debug->panel = in->panel;
  1977. debug->aux = in->aux;
  1978. debug->dev = in->dev;
  1979. debug->connector = in->connector;
  1980. debug->catalog = in->catalog;
  1981. debug->parser = in->parser;
  1982. debug->ctrl = in->ctrl;
  1983. debug->pll = in->pll;
  1984. debug->display = in->display;
  1985. dp_debug = &debug->dp_debug;
  1986. mutex_init(&debug->lock);
  1987. rc = dp_debug_init(dp_debug);
  1988. if (rc) {
  1989. devm_kfree(in->dev, debug);
  1990. goto error;
  1991. }
  1992. debug->aux->access_lock = &debug->lock;
  1993. dp_debug->abort = dp_debug_abort;
  1994. dp_debug->set_mst_con = dp_debug_set_mst_con;
  1995. dp_debug->max_pclk_khz = debug->parser->max_pclk_khz;
  1996. return dp_debug;
  1997. error:
  1998. return ERR_PTR(rc);
  1999. }
  2000. static int dp_debug_deinit(struct dp_debug *dp_debug)
  2001. {
  2002. struct dp_debug_private *debug;
  2003. if (!dp_debug)
  2004. return -EINVAL;
  2005. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  2006. debugfs_remove_recursive(debug->root);
  2007. if (debug->sim_bridge)
  2008. dp_sim_destroy_bridge(debug->sim_bridge);
  2009. return 0;
  2010. }
  2011. void dp_debug_put(struct dp_debug *dp_debug)
  2012. {
  2013. struct dp_debug_private *debug;
  2014. if (!dp_debug)
  2015. return;
  2016. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  2017. dp_debug_deinit(dp_debug);
  2018. mutex_destroy(&debug->lock);
  2019. devm_kfree(debug->dev, debug);
  2020. }