dp_debug.c 54 KB

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