dp_debug.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580
  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. 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. debugfs_create_u32("max_bpp", 0644, dir, &debug->panel->max_supported_bpp);
  1703. file = debugfs_create_file("mmrm_clk_cb", 0644, dir, debug, &mmrm_clk_cb_fops);
  1704. if (IS_ERR_OR_NULL(file)) {
  1705. rc = PTR_ERR(file);
  1706. DP_ERR("[%s] debugfs mmrm_clk_cb failed, rc=%d\n", DEBUG_NAME, rc);
  1707. return rc;
  1708. }
  1709. return rc;
  1710. }
  1711. static int dp_debug_init_hdcp(struct dp_debug_private *debug,
  1712. struct dentry *dir)
  1713. {
  1714. int rc = 0;
  1715. debugfs_create_bool("hdcp_wait_sink_sync", 0644, dir, &debug->dp_debug.hdcp_wait_sink_sync);
  1716. debugfs_create_bool("force_encryption", 0644, dir, &debug->dp_debug.force_encryption);
  1717. return rc;
  1718. }
  1719. static int dp_debug_init_sink_caps(struct dp_debug_private *debug,
  1720. struct dentry *dir)
  1721. {
  1722. int rc = 0;
  1723. struct dentry *file;
  1724. file = debugfs_create_file("edid_modes", 0644, dir,
  1725. debug, &edid_modes_fops);
  1726. if (IS_ERR_OR_NULL(file)) {
  1727. rc = PTR_ERR(file);
  1728. DP_ERR("[%s] debugfs create edid_modes failed, rc=%d\n",
  1729. DEBUG_NAME, rc);
  1730. return rc;
  1731. }
  1732. file = debugfs_create_file("edid_modes_mst", 0644, dir,
  1733. debug, &edid_modes_mst_fops);
  1734. if (IS_ERR_OR_NULL(file)) {
  1735. rc = PTR_ERR(file);
  1736. DP_ERR("[%s] debugfs create edid_modes_mst failed, rc=%d\n",
  1737. DEBUG_NAME, rc);
  1738. return rc;
  1739. }
  1740. file = debugfs_create_file("edid", 0644, dir,
  1741. debug, &edid_fops);
  1742. if (IS_ERR_OR_NULL(file)) {
  1743. rc = PTR_ERR(file);
  1744. DP_ERR("[%s] debugfs edid failed, rc=%d\n",
  1745. DEBUG_NAME, rc);
  1746. return rc;
  1747. }
  1748. file = debugfs_create_file("dpcd", 0644, dir,
  1749. debug, &dpcd_fops);
  1750. if (IS_ERR_OR_NULL(file)) {
  1751. rc = PTR_ERR(file);
  1752. DP_ERR("[%s] debugfs dpcd failed, rc=%d\n",
  1753. DEBUG_NAME, rc);
  1754. return rc;
  1755. }
  1756. file = debugfs_create_file("crc", 0644, dir, debug, &crc_fops);
  1757. if (IS_ERR_OR_NULL(file)) {
  1758. rc = PTR_ERR(file);
  1759. DP_ERR("[%s] debugfs crc failed, rc=%d\n", DEBUG_NAME, rc);
  1760. return rc;
  1761. }
  1762. return rc;
  1763. }
  1764. static int dp_debug_init_status(struct dp_debug_private *debug,
  1765. struct dentry *dir)
  1766. {
  1767. int rc = 0;
  1768. struct dentry *file;
  1769. file = debugfs_create_file("dp_debug", 0444, dir,
  1770. debug, &dp_debug_fops);
  1771. if (IS_ERR_OR_NULL(file)) {
  1772. rc = PTR_ERR(file);
  1773. DP_ERR("[%s] debugfs create file failed, rc=%d\n",
  1774. DEBUG_NAME, rc);
  1775. return rc;
  1776. }
  1777. file = debugfs_create_file("connected", 0444, dir,
  1778. debug, &connected_fops);
  1779. if (IS_ERR_OR_NULL(file)) {
  1780. rc = PTR_ERR(file);
  1781. DP_ERR("[%s] debugfs connected failed, rc=%d\n",
  1782. DEBUG_NAME, rc);
  1783. return rc;
  1784. }
  1785. file = debugfs_create_file("hdr", 0400, dir, debug, &hdr_fops);
  1786. if (IS_ERR_OR_NULL(file)) {
  1787. rc = PTR_ERR(file);
  1788. DP_ERR("[%s] debugfs hdr failed, rc=%d\n",
  1789. DEBUG_NAME, rc);
  1790. return rc;
  1791. }
  1792. file = debugfs_create_file("hdr_mst", 0400, dir, debug, &hdr_mst_fops);
  1793. if (IS_ERR_OR_NULL(file)) {
  1794. rc = PTR_ERR(file);
  1795. DP_ERR("[%s] debugfs hdr_mst failed, rc=%d\n",
  1796. DEBUG_NAME, rc);
  1797. return rc;
  1798. }
  1799. file = debugfs_create_file("hdcp", 0644, dir, debug, &hdcp_fops);
  1800. if (IS_ERR_OR_NULL(file)) {
  1801. rc = PTR_ERR(file);
  1802. DP_ERR("[%s] debugfs hdcp failed, rc=%d\n",
  1803. DEBUG_NAME, rc);
  1804. return rc;
  1805. }
  1806. return rc;
  1807. }
  1808. static int dp_debug_init_sim(struct dp_debug_private *debug, struct dentry *dir)
  1809. {
  1810. int rc = 0;
  1811. struct dentry *file;
  1812. file = debugfs_create_file("hpd", 0644, dir, debug, &hpd_fops);
  1813. if (IS_ERR_OR_NULL(file)) {
  1814. rc = PTR_ERR(file);
  1815. DP_ERR("[%s] debugfs hpd failed, rc=%d\n",
  1816. DEBUG_NAME, rc);
  1817. return rc;
  1818. }
  1819. file = debugfs_create_file("sim", 0644, dir, debug, &sim_fops);
  1820. if (IS_ERR_OR_NULL(file)) {
  1821. rc = PTR_ERR(file);
  1822. DP_ERR("[%s] debugfs sim failed, rc=%d\n",
  1823. DEBUG_NAME, rc);
  1824. return rc;
  1825. }
  1826. file = debugfs_create_file("attention", 0644, dir,
  1827. debug, &attention_fops);
  1828. if (IS_ERR_OR_NULL(file)) {
  1829. rc = PTR_ERR(file);
  1830. DP_ERR("[%s] debugfs attention failed, rc=%d\n",
  1831. DEBUG_NAME, rc);
  1832. return rc;
  1833. }
  1834. debugfs_create_bool("skip_uevent", 0644, dir, &debug->dp_debug.skip_uevent);
  1835. debugfs_create_bool("force_multi_func", 0644, dir, &debug->hpd->force_multi_func);
  1836. return rc;
  1837. }
  1838. static int dp_debug_init_dsc_fec(struct dp_debug_private *debug,
  1839. struct dentry *dir)
  1840. {
  1841. int rc = 0;
  1842. debugfs_create_bool("dsc_feature_enable", 0644, dir, &debug->parser->dsc_feature_enable);
  1843. debugfs_create_bool("fec_feature_enable", 0644, dir, &debug->parser->fec_feature_enable);
  1844. return rc;
  1845. }
  1846. static int dp_debug_init_tpg(struct dp_debug_private *debug, struct dentry *dir)
  1847. {
  1848. int rc = 0;
  1849. struct dentry *file;
  1850. file = debugfs_create_file("tpg_ctrl", 0644, dir,
  1851. debug, &tpg_fops);
  1852. if (IS_ERR_OR_NULL(file)) {
  1853. rc = PTR_ERR(file);
  1854. DP_ERR("[%s] debugfs tpg failed, rc=%d\n",
  1855. DEBUG_NAME, rc);
  1856. return rc;
  1857. }
  1858. return rc;
  1859. }
  1860. static int dp_debug_init_reg_dump(struct dp_debug_private *debug,
  1861. struct dentry *dir)
  1862. {
  1863. int rc = 0;
  1864. struct dentry *file;
  1865. file = debugfs_create_file("exe_mode", 0644, dir,
  1866. debug, &exe_mode_fops);
  1867. if (IS_ERR_OR_NULL(file)) {
  1868. rc = PTR_ERR(file);
  1869. DP_ERR("[%s] debugfs register failed, rc=%d\n",
  1870. DEBUG_NAME, rc);
  1871. return rc;
  1872. }
  1873. file = debugfs_create_file("dump", 0644, dir,
  1874. debug, &dump_fops);
  1875. if (IS_ERR_OR_NULL(file)) {
  1876. rc = PTR_ERR(file);
  1877. DP_ERR("[%s] debugfs dump failed, rc=%d\n",
  1878. DEBUG_NAME, rc);
  1879. return rc;
  1880. }
  1881. return rc;
  1882. }
  1883. static int dp_debug_init_feature_toggle(struct dp_debug_private *debug,
  1884. struct dentry *dir)
  1885. {
  1886. int rc = 0;
  1887. debugfs_create_bool("ssc_enable", 0644, dir, &debug->pll->ssc_en);
  1888. debugfs_create_bool("widebus_mode", 0644, dir, &debug->parser->has_widebus);
  1889. return rc;
  1890. }
  1891. static int dp_debug_init_configs(struct dp_debug_private *debug,
  1892. struct dentry *dir)
  1893. {
  1894. int rc = 0;
  1895. debugfs_create_ulong("connect_notification_delay_ms", 0644, dir,
  1896. &debug->dp_debug.connect_notification_delay_ms);
  1897. debug->dp_debug.connect_notification_delay_ms =
  1898. DEFAULT_CONNECT_NOTIFICATION_DELAY_MS;
  1899. debugfs_create_u32("disconnect_delay_ms", 0644, dir, &debug->dp_debug.disconnect_delay_ms);
  1900. debug->dp_debug.disconnect_delay_ms = DEFAULT_DISCONNECT_DELAY_MS;
  1901. return rc;
  1902. }
  1903. static int dp_debug_init(struct dp_debug *dp_debug)
  1904. {
  1905. int rc = 0;
  1906. struct dp_debug_private *debug = container_of(dp_debug,
  1907. struct dp_debug_private, dp_debug);
  1908. struct dentry *dir;
  1909. if (!IS_ENABLED(CONFIG_DEBUG_FS)) {
  1910. DP_WARN("Not creating debug root dir.");
  1911. debug->root = NULL;
  1912. return 0;
  1913. }
  1914. dir = debugfs_create_dir(DEBUG_NAME, NULL);
  1915. if (IS_ERR_OR_NULL(dir)) {
  1916. if (!dir)
  1917. rc = -EINVAL;
  1918. else
  1919. rc = PTR_ERR(dir);
  1920. DP_ERR("[%s] debugfs create dir failed, rc = %d\n",
  1921. DEBUG_NAME, rc);
  1922. goto error;
  1923. }
  1924. debug->root = dir;
  1925. rc = dp_debug_init_status(debug, dir);
  1926. if (rc)
  1927. goto error_remove_dir;
  1928. rc = dp_debug_init_sink_caps(debug, dir);
  1929. if (rc)
  1930. goto error_remove_dir;
  1931. rc = dp_debug_init_mst(debug, dir);
  1932. if (rc)
  1933. goto error_remove_dir;
  1934. rc = dp_debug_init_link(debug, dir);
  1935. if (rc)
  1936. goto error_remove_dir;
  1937. rc = dp_debug_init_hdcp(debug, dir);
  1938. if (rc)
  1939. goto error_remove_dir;
  1940. rc = dp_debug_init_sim(debug, dir);
  1941. if (rc)
  1942. goto error_remove_dir;
  1943. rc = dp_debug_init_dsc_fec(debug, dir);
  1944. if (rc)
  1945. goto error_remove_dir;
  1946. rc = dp_debug_init_tpg(debug, dir);
  1947. if (rc)
  1948. goto error_remove_dir;
  1949. rc = dp_debug_init_reg_dump(debug, dir);
  1950. if (rc)
  1951. goto error_remove_dir;
  1952. rc = dp_debug_init_feature_toggle(debug, dir);
  1953. if (rc)
  1954. goto error_remove_dir;
  1955. rc = dp_debug_init_configs(debug, dir);
  1956. if (rc)
  1957. goto error_remove_dir;
  1958. return 0;
  1959. error_remove_dir:
  1960. debugfs_remove_recursive(dir);
  1961. error:
  1962. return rc;
  1963. }
  1964. static void dp_debug_abort(struct dp_debug *dp_debug)
  1965. {
  1966. struct dp_debug_private *debug;
  1967. if (!dp_debug)
  1968. return;
  1969. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  1970. mutex_lock(&debug->lock);
  1971. // disconnect has already been handled. so clear hotplug
  1972. debug->hotplug = false;
  1973. dp_debug_set_sim_mode(debug, false);
  1974. mutex_unlock(&debug->lock);
  1975. }
  1976. static void dp_debug_set_mst_con(struct dp_debug *dp_debug, int con_id)
  1977. {
  1978. struct dp_debug_private *debug;
  1979. if (!dp_debug)
  1980. return;
  1981. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  1982. mutex_lock(&debug->lock);
  1983. debug->mst_con_id = con_id;
  1984. mutex_unlock(&debug->lock);
  1985. DP_INFO("Selecting mst connector %d\n", con_id);
  1986. }
  1987. struct dp_debug *dp_debug_get(struct dp_debug_in *in)
  1988. {
  1989. int rc = 0;
  1990. struct dp_debug_private *debug;
  1991. struct dp_debug *dp_debug;
  1992. if (!in->dev || !in->panel || !in->hpd || !in->link ||
  1993. !in->catalog || !in->ctrl || !in->pll) {
  1994. DP_ERR("invalid input\n");
  1995. rc = -EINVAL;
  1996. goto error;
  1997. }
  1998. debug = devm_kzalloc(in->dev, sizeof(*debug), GFP_KERNEL);
  1999. if (!debug) {
  2000. rc = -ENOMEM;
  2001. goto error;
  2002. }
  2003. debug->hpd = in->hpd;
  2004. debug->link = in->link;
  2005. debug->panel = in->panel;
  2006. debug->aux = in->aux;
  2007. debug->dev = in->dev;
  2008. debug->connector = in->connector;
  2009. debug->catalog = in->catalog;
  2010. debug->parser = in->parser;
  2011. debug->ctrl = in->ctrl;
  2012. debug->pll = in->pll;
  2013. debug->display = in->display;
  2014. dp_debug = &debug->dp_debug;
  2015. mutex_init(&debug->lock);
  2016. rc = dp_debug_init(dp_debug);
  2017. if (rc) {
  2018. devm_kfree(in->dev, debug);
  2019. goto error;
  2020. }
  2021. debug->aux->access_lock = &debug->lock;
  2022. dp_debug->abort = dp_debug_abort;
  2023. dp_debug->set_mst_con = dp_debug_set_mst_con;
  2024. dp_debug->max_pclk_khz = debug->parser->max_pclk_khz;
  2025. return dp_debug;
  2026. error:
  2027. return ERR_PTR(rc);
  2028. }
  2029. static int dp_debug_deinit(struct dp_debug *dp_debug)
  2030. {
  2031. struct dp_debug_private *debug;
  2032. if (!dp_debug)
  2033. return -EINVAL;
  2034. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  2035. debugfs_remove_recursive(debug->root);
  2036. if (debug->sim_bridge)
  2037. dp_sim_destroy_bridge(debug->sim_bridge);
  2038. return 0;
  2039. }
  2040. void dp_debug_put(struct dp_debug *dp_debug)
  2041. {
  2042. struct dp_debug_private *debug;
  2043. if (!dp_debug)
  2044. return;
  2045. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  2046. dp_debug_deinit(dp_debug);
  2047. mutex_destroy(&debug->lock);
  2048. devm_kfree(debug->dev, debug);
  2049. }