dp_debug.c 53 KB

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