dp_debug.c 55 KB

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