dp_debug.c 57 KB

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