dp_debug.c 57 KB

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