12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474 |
- // SPDX-License-Identifier: GPL-2.0-only
- /*
- * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
- * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
- */
- #include <linux/debugfs.h>
- #include <linux/slab.h>
- #include <drm/drm_dp_mst_helper.h>
- #include <drm/drm_probe_helper.h>
- #include "dp_power.h"
- #include "dp_catalog.h"
- #include "dp_aux.h"
- #include "dp_debug.h"
- #include "drm/drm_connector.h"
- #include "sde_connector.h"
- #include "dp_display.h"
- #include "dp_pll.h"
- #include "dp_hpd.h"
- #include "dp_mst_sim.h"
- #include "dp_mst_drm.h"
- #define DEBUG_NAME "drm_dp"
- struct dp_debug_private {
- struct dentry *root;
- u32 dpcd_offset;
- u32 dpcd_size;
- u32 mst_con_id;
- u32 mst_edid_idx;
- bool hotplug;
- u32 sim_mode;
- char exe_mode[SZ_32];
- char reg_dump[SZ_32];
- struct dp_hpd *hpd;
- struct dp_link *link;
- struct dp_panel *panel;
- struct dp_aux *aux;
- struct dp_catalog *catalog;
- struct drm_connector **connector;
- struct device *dev;
- struct dp_debug dp_debug;
- struct dp_parser *parser;
- struct dp_ctrl *ctrl;
- struct dp_pll *pll;
- struct dp_display *display;
- struct mutex lock;
- struct dp_aux_bridge *sim_bridge;
- };
- static int dp_debug_sim_hpd_cb(void *arg, bool hpd, bool hpd_irq)
- {
- struct dp_debug_private *debug = arg;
- int vdo = 0;
- if (hpd_irq) {
- vdo |= BIT(7);
- if (hpd)
- vdo |= BIT(8);
- return debug->hpd->simulate_attention(debug->hpd, vdo);
- } else {
- return debug->hpd->simulate_connect(debug->hpd, hpd);
- }
- }
- static int dp_debug_attach_sim_bridge(struct dp_debug_private *debug)
- {
- int ret;
- if (debug->sim_bridge)
- return 0;
- ret = dp_sim_create_bridge(debug->dev, &debug->sim_bridge);
- if (ret)
- return ret;
- dp_sim_update_port_num(debug->sim_bridge, 1);
- if (debug->sim_bridge->register_hpd)
- debug->sim_bridge->register_hpd(debug->sim_bridge,
- dp_debug_sim_hpd_cb, debug);
- return 0;
- }
- static void dp_debug_enable_sim_mode(struct dp_debug_private *debug,
- u32 mode_mask)
- {
- /* return if mode is already enabled */
- if ((debug->sim_mode & mode_mask) == mode_mask)
- return;
- /* create bridge if not yet */
- if (dp_debug_attach_sim_bridge(debug))
- return;
- /* switch to bridge mode */
- if (!debug->sim_mode)
- debug->aux->set_sim_mode(debug->aux, debug->sim_bridge);
- /* update sim mode */
- debug->sim_mode |= mode_mask;
- dp_sim_set_sim_mode(debug->sim_bridge, debug->sim_mode);
- }
- static void dp_debug_disable_sim_mode(struct dp_debug_private *debug,
- u32 mode_mask)
- {
- /* return if mode is already disabled */
- if (!(debug->sim_mode & mode_mask))
- return;
- /* update sim mode */
- debug->sim_mode &= ~mode_mask;
- dp_sim_set_sim_mode(debug->sim_bridge, debug->sim_mode);
- /* switch to normal mode */
- if (!debug->sim_mode)
- debug->aux->set_sim_mode(debug->aux, NULL);
- }
- static ssize_t dp_debug_write_edid(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- u8 *buf = NULL, *buf_t = NULL, *edid = NULL;
- const int char_to_nib = 2;
- size_t edid_size = 0;
- size_t size = 0, edid_buf_index = 0;
- ssize_t rc = count;
- if (!debug)
- return -ENODEV;
- mutex_lock(&debug->lock);
- if (*ppos)
- goto bail;
- size = min_t(size_t, count, SZ_1K);
- buf = kzalloc(size, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf)) {
- rc = -ENOMEM;
- goto bail;
- }
- if (copy_from_user(buf, user_buff, size))
- goto bail;
- edid_size = size / char_to_nib;
- buf_t = buf;
- size = edid_size;
- edid = kzalloc(size, GFP_KERNEL);
- if (!edid)
- goto bail;
- while (size--) {
- char t[3];
- int d;
- memcpy(t, buf_t, sizeof(char) * char_to_nib);
- t[char_to_nib] = '\0';
- if (kstrtoint(t, 16, &d)) {
- DP_ERR("kstrtoint error\n");
- goto bail;
- }
- edid[edid_buf_index++] = d;
- buf_t += char_to_nib;
- }
- dp_debug_enable_sim_mode(debug, DP_SIM_MODE_EDID);
- dp_mst_clear_edid_cache(debug->display);
- dp_sim_update_port_edid(debug->sim_bridge, debug->mst_edid_idx,
- edid, edid_size);
- bail:
- kfree(buf);
- kfree(edid);
- mutex_unlock(&debug->lock);
- return rc;
- }
- static ssize_t dp_debug_write_dpcd(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- u8 *buf = NULL, *buf_t = NULL, *dpcd = NULL;
- const int char_to_nib = 2;
- size_t dpcd_size = 0;
- size_t size = 0, dpcd_buf_index = 0;
- ssize_t rc = count;
- char offset_ch[5];
- u32 offset, data_len;
- if (!debug)
- return -ENODEV;
- mutex_lock(&debug->lock);
- if (*ppos)
- goto bail;
- size = min_t(size_t, count, SZ_2K);
- if (size < 4)
- goto bail;
- buf = kzalloc(size, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf)) {
- rc = -ENOMEM;
- goto bail;
- }
- if (copy_from_user(buf, user_buff, size))
- goto bail;
- memcpy(offset_ch, buf, 4);
- offset_ch[4] = '\0';
- if (kstrtoint(offset_ch, 16, &offset)) {
- DP_ERR("offset kstrtoint error\n");
- goto bail;
- }
- debug->dpcd_offset = offset;
- size -= 4;
- if (size < char_to_nib)
- goto bail;
- dpcd_size = size / char_to_nib;
- data_len = dpcd_size;
- buf_t = buf + 4;
- dpcd = kzalloc(dpcd_size, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(dpcd)) {
- rc = -ENOMEM;
- goto bail;
- }
- while (dpcd_size--) {
- char t[3];
- int d;
- memcpy(t, buf_t, sizeof(char) * char_to_nib);
- t[char_to_nib] = '\0';
- if (kstrtoint(t, 16, &d)) {
- DP_ERR("kstrtoint error\n");
- goto bail;
- }
- dpcd[dpcd_buf_index++] = d;
- buf_t += char_to_nib;
- }
- /*
- * if link training status registers are reprogramed,
- * read link training status from simulator, otherwise
- * read link training status from real aux channel.
- */
- if (offset <= DP_LANE0_1_STATUS &&
- offset + dpcd_buf_index > DP_LANE0_1_STATUS)
- dp_debug_enable_sim_mode(debug,
- DP_SIM_MODE_DPCD_READ | DP_SIM_MODE_LINK_TRAIN);
- else
- dp_debug_enable_sim_mode(debug, DP_SIM_MODE_DPCD_READ);
- dp_sim_write_dpcd_reg(debug->sim_bridge,
- dpcd, dpcd_buf_index, offset);
- debug->dpcd_size = dpcd_buf_index;
- bail:
- kfree(buf);
- kfree(dpcd);
- mutex_unlock(&debug->lock);
- return rc;
- }
- static ssize_t dp_debug_read_dpcd(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf;
- int const buf_size = SZ_4K;
- u32 offset = 0;
- u32 len = 0;
- u8 *dpcd;
- if (!debug || !debug->aux)
- return -ENODEV;
- if (*ppos)
- return 0;
- buf = kzalloc(buf_size, GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
- mutex_lock(&debug->lock);
- dpcd = kzalloc(buf_size, GFP_KERNEL);
- if (!dpcd)
- goto bail;
- /*
- * In simulation mode, this function returns the last written DPCD node.
- * For a real monitor plug in, it dumps the first byte at the last written DPCD address
- * unless the address is 0, in which case the first 20 bytes are dumped
- */
- if (debug->dp_debug.sim_mode) {
- dp_sim_read_dpcd_reg(debug->sim_bridge, dpcd, debug->dpcd_size, debug->dpcd_offset);
- } else {
- if (debug->dpcd_offset) {
- debug->dpcd_size = 1;
- if (drm_dp_dpcd_read(debug->aux->drm_aux, debug->dpcd_offset, dpcd,
- debug->dpcd_size) != 1)
- goto bail;
- } else {
- debug->dpcd_size = sizeof(debug->panel->dpcd);
- memcpy(dpcd, debug->panel->dpcd, debug->dpcd_size);
- }
- }
- len += scnprintf(buf + len , buf_size - len, "%04x: ", debug->dpcd_offset);
- while (offset < debug->dpcd_size)
- len += scnprintf(buf + len, buf_size - len, "%02x ", dpcd[offset++]);
- kfree(dpcd);
- len = min_t(size_t, count, len);
- if (!copy_to_user(user_buff, buf, len))
- *ppos += len;
- bail:
- mutex_unlock(&debug->lock);
- kfree(buf);
- return len;
- }
- static ssize_t dp_debug_write_hpd(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- int const hpd_data_mask = 0x7;
- int hpd = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &hpd) != 0)
- goto end;
- hpd &= hpd_data_mask;
- debug->hotplug = !!(hpd & BIT(0));
- debug->dp_debug.psm_enabled = !!(hpd & BIT(1));
- /*
- * print hotplug value as this code is executed
- * only while running in debug mode which is manually
- * triggered by a tester or a script.
- */
- DP_INFO("%s\n", debug->hotplug ? "[CONNECT]" : "[DISCONNECT]");
- debug->hpd->simulate_connect(debug->hpd, debug->hotplug);
- end:
- return len;
- }
- static ssize_t dp_debug_write_edid_modes(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- struct dp_panel *panel;
- char buf[SZ_32];
- size_t len = 0;
- int hdisplay = 0, vdisplay = 0, vrefresh = 0, aspect_ratio;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- goto end;
- panel = debug->panel;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_32 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto clear;
- buf[len] = '\0';
- if (sscanf(buf, "%d %d %d %d", &hdisplay, &vdisplay, &vrefresh,
- &aspect_ratio) != 4)
- goto clear;
- if (!hdisplay || !vdisplay || !vrefresh)
- goto clear;
- panel->mode_override = true;
- panel->hdisplay = hdisplay;
- panel->vdisplay = vdisplay;
- panel->vrefresh = vrefresh;
- panel->aspect_ratio = aspect_ratio;
- goto end;
- clear:
- DP_DEBUG("clearing debug modes\n");
- panel->mode_override = false;
- end:
- return len;
- }
- static ssize_t dp_debug_write_edid_modes_mst(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- struct drm_connector *connector;
- struct sde_connector *sde_conn;
- struct dp_panel *panel = NULL;
- char buf[SZ_512];
- char *read_buf;
- size_t len = 0;
- int hdisplay = 0, vdisplay = 0, vrefresh = 0, aspect_ratio = 0;
- int con_id = 0, offset = 0, debug_en = 0;
- if (!debug)
- return -ENODEV;
- mutex_lock(&debug->lock);
- if (*ppos)
- goto end;
- len = min_t(size_t, count, SZ_512 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- read_buf = buf;
- while (sscanf(read_buf, "%d %d %d %d %d %d%n", &debug_en, &con_id,
- &hdisplay, &vdisplay, &vrefresh, &aspect_ratio,
- &offset) == 6) {
- connector = drm_connector_lookup((*debug->connector)->dev,
- NULL, con_id);
- if (connector) {
- sde_conn = to_sde_connector(connector);
- panel = sde_conn->drv_panel;
- if (panel && sde_conn->mst_port) {
- panel->mode_override = debug_en;
- panel->hdisplay = hdisplay;
- panel->vdisplay = vdisplay;
- panel->vrefresh = vrefresh;
- panel->aspect_ratio = aspect_ratio;
- } else {
- DP_ERR("connector id %d is not mst\n", con_id);
- }
- drm_connector_put(connector);
- } else {
- DP_ERR("invalid connector id %d\n", con_id);
- }
- read_buf += offset;
- }
- end:
- mutex_unlock(&debug->lock);
- return len;
- }
- static ssize_t dp_debug_write_mst_con_id(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- struct drm_connector *connector;
- struct sde_connector *sde_conn;
- struct drm_dp_mst_port *mst_port;
- struct dp_panel *dp_panel;
- char buf[SZ_32];
- size_t len = 0;
- int con_id = 0, status;
- if (!debug)
- return -ENODEV;
- mutex_lock(&debug->lock);
- if (*ppos)
- goto end;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_32 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto clear;
- buf[len] = '\0';
- if (sscanf(buf, "%d %d", &con_id, &status) != 2)
- goto end;
- if (!con_id)
- goto clear;
- connector = drm_connector_lookup((*debug->connector)->dev,
- NULL, con_id);
- if (!connector) {
- DP_ERR("invalid connector id %u\n", con_id);
- goto end;
- }
- sde_conn = to_sde_connector(connector);
- if (!sde_conn->drv_panel || !sde_conn->mst_port) {
- DP_ERR("invalid connector state %d\n", con_id);
- goto out;
- }
- debug->mst_con_id = con_id;
- if (status == connector_status_connected)
- DP_INFO("plug mst connector %d\n", con_id);
- else
- DP_INFO("unplug mst connector %d\n", con_id);
- if (status == connector_status_unknown)
- goto out;
- mst_port = sde_conn->mst_port;
- dp_panel = sde_conn->drv_panel;
- if (debug->dp_debug.sim_mode) {
- dp_sim_update_port_status(debug->sim_bridge,
- mst_port->port_num, status);
- } else {
- dp_panel->mst_hide = (status == connector_status_disconnected);
- drm_kms_helper_hotplug_event(connector->dev);
- }
- out:
- drm_connector_put(connector);
- goto end;
- clear:
- DP_DEBUG("clearing mst_con_id\n");
- debug->mst_con_id = 0;
- end:
- mutex_unlock(&debug->lock);
- return len;
- }
- static ssize_t dp_debug_write_mst_con_add(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_32];
- size_t len = 0;
- const int dp_en = BIT(3), hpd_high = BIT(7), hpd_irq = BIT(8);
- int vdo = dp_en | hpd_high | hpd_irq;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_32 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- debug->dp_debug.mst_sim_add_con = true;
- debug->hpd->simulate_attention(debug->hpd, vdo);
- end:
- return len;
- }
- static ssize_t dp_debug_write_mst_con_remove(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- struct drm_connector_list_iter conn_iter;
- struct drm_connector *connector;
- char buf[SZ_32];
- size_t len = 0;
- int con_id = 0;
- bool in_list = false;
- const int dp_en = BIT(3), hpd_high = BIT(7), hpd_irq = BIT(8);
- int vdo = dp_en | hpd_high | hpd_irq;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_32 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- if (sscanf(buf, "%d", &con_id) != 1) {
- len = 0;
- goto end;
- }
- if (!con_id)
- goto end;
- drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
- drm_for_each_connector_iter(connector, &conn_iter) {
- if (connector->base.id == con_id) {
- in_list = true;
- break;
- }
- }
- drm_connector_list_iter_end(&conn_iter);
- if (!in_list) {
- DRM_ERROR("invalid connector id %u\n", con_id);
- goto end;
- }
- debug->dp_debug.mst_sim_remove_con = true;
- debug->dp_debug.mst_sim_remove_con_id = con_id;
- debug->hpd->simulate_attention(debug->hpd, vdo);
- end:
- return len;
- }
- static ssize_t dp_debug_mmrm_clk_cb_write(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- struct dss_clk_mmrm_cb mmrm_cb_data;
- struct mmrm_client_notifier_data notifier_data;
- struct dp_display *dp_display;
- int cb_type;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- dp_display = debug->display;
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- return 0;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &cb_type) != 0)
- return 0;
- if (cb_type != MMRM_CLIENT_RESOURCE_VALUE_CHANGE)
- return 0;
- notifier_data.cb_type = MMRM_CLIENT_RESOURCE_VALUE_CHANGE;
- mmrm_cb_data.phandle = (void *)dp_display;
- notifier_data.pvt_data = (void *)&mmrm_cb_data;
- dp_display_mmrm_callback(¬ifier_data);
- return len;
- }
- static ssize_t dp_debug_bw_code_write(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- u32 max_bw_code = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- return 0;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &max_bw_code) != 0)
- return 0;
- if (!is_link_rate_valid(max_bw_code)) {
- DP_ERR("Unsupported bw code %d\n", max_bw_code);
- return len;
- }
- debug->panel->max_bw_code = max_bw_code;
- DP_DEBUG("max_bw_code: %d\n", max_bw_code);
- return len;
- }
- static ssize_t dp_debug_mst_mode_read(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[64];
- ssize_t len;
- len = scnprintf(buf, sizeof(buf),
- "mst_mode = %d, mst_state = %d\n",
- debug->parser->has_mst,
- debug->panel->mst_state);
- return simple_read_from_buffer(user_buff, count, ppos, buf, len);
- }
- static ssize_t dp_debug_mst_mode_write(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- u32 mst_mode = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- return 0;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &mst_mode) != 0)
- return 0;
- debug->parser->has_mst = mst_mode ? true : false;
- DP_DEBUG("mst_enable: %d\n", mst_mode);
- return len;
- }
- static ssize_t dp_debug_max_pclk_khz_write(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- u32 max_pclk = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- return 0;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &max_pclk) != 0)
- return 0;
- if (max_pclk > debug->parser->max_pclk_khz)
- DP_ERR("requested: %d, max_pclk_khz:%d\n", max_pclk,
- debug->parser->max_pclk_khz);
- else
- debug->dp_debug.max_pclk_khz = max_pclk;
- DP_DEBUG("max_pclk_khz: %d\n", max_pclk);
- return len;
- }
- static ssize_t dp_debug_max_pclk_khz_read(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf;
- u32 len = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- buf = kzalloc(SZ_4K, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf))
- return -ENOMEM;
- len += snprintf(buf + len, (SZ_4K - len),
- "max_pclk_khz = %d, org: %d\n",
- debug->dp_debug.max_pclk_khz,
- debug->parser->max_pclk_khz);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- kfree(buf);
- return -EFAULT;
- }
- *ppos += len;
- kfree(buf);
- return len;
- }
- static ssize_t dp_debug_mst_sideband_mode_write(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- int mst_sideband_mode = 0;
- u32 mst_port_cnt = 0;
- if (!debug)
- return -ENODEV;
- mutex_lock(&debug->lock);
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- return -EFAULT;
- buf[len] = '\0';
- if (sscanf(buf, "%d %u", &mst_sideband_mode, &mst_port_cnt) != 2) {
- DP_ERR("invalid input\n");
- goto bail;
- }
- if (!mst_port_cnt)
- mst_port_cnt = 1;
- debug->mst_edid_idx = 0;
- if (mst_sideband_mode)
- dp_debug_disable_sim_mode(debug, DP_SIM_MODE_MST);
- else
- dp_debug_enable_sim_mode(debug, DP_SIM_MODE_MST);
- dp_sim_update_port_num(debug->sim_bridge, mst_port_cnt);
- buf[0] = !mst_sideband_mode;
- dp_sim_write_dpcd_reg(debug->sim_bridge, buf, 1, DP_MSTM_CAP);
- DP_DEBUG("mst_sideband_mode: %d port_cnt:%d\n",
- mst_sideband_mode, mst_port_cnt);
- bail:
- mutex_unlock(&debug->lock);
- return count;
- }
- static ssize_t dp_debug_tpg_write(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- u32 tpg_pattern = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto bail;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &tpg_pattern) != 0)
- goto bail;
- DP_DEBUG("tpg_pattern: %d\n", tpg_pattern);
- if (tpg_pattern == debug->dp_debug.tpg_pattern)
- goto bail;
- if (debug->panel)
- debug->panel->tpg_config(debug->panel, tpg_pattern);
- debug->dp_debug.tpg_pattern = tpg_pattern;
- bail:
- return len;
- }
- static ssize_t dp_debug_write_exe_mode(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_32];
- size_t len = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- len = min_t(size_t, count, SZ_32 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- if (sscanf(buf, "%3s", debug->exe_mode) != 1)
- goto end;
- if (strcmp(debug->exe_mode, "hw") &&
- strcmp(debug->exe_mode, "sw") &&
- strcmp(debug->exe_mode, "all"))
- goto end;
- debug->catalog->set_exe_mode(debug->catalog, debug->exe_mode);
- end:
- return len;
- }
- static ssize_t dp_debug_read_connected(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- u32 len = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- len += snprintf(buf, SZ_8, "%d\n", debug->hpd->hpd_high);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len))
- return -EFAULT;
- *ppos += len;
- return len;
- }
- static ssize_t dp_debug_write_hdcp(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- int hdcp = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &hdcp) != 0)
- goto end;
- debug->dp_debug.hdcp_disabled = !hdcp;
- end:
- return len;
- }
- static ssize_t dp_debug_read_hdcp(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- u32 len = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- len = sizeof(debug->dp_debug.hdcp_status);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, debug->dp_debug.hdcp_status, len))
- return -EFAULT;
- *ppos += len;
- return len;
- }
- static int dp_debug_check_buffer_overflow(int rc, int *max_size, int *len)
- {
- if (rc >= *max_size) {
- DP_ERR("buffer overflow\n");
- return -EINVAL;
- }
- *len += rc;
- *max_size = SZ_4K - *len;
- return 0;
- }
- static ssize_t dp_debug_read_edid_modes(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf;
- u32 len = 0, ret = 0, max_size = SZ_4K;
- int rc = 0;
- struct drm_connector *connector;
- struct drm_display_mode *mode;
- if (!debug) {
- DP_ERR("invalid data\n");
- rc = -ENODEV;
- goto error;
- }
- connector = *debug->connector;
- if (!connector) {
- DP_ERR("connector is NULL\n");
- rc = -EINVAL;
- goto error;
- }
- if (*ppos)
- goto error;
- buf = kzalloc(SZ_4K, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf)) {
- rc = -ENOMEM;
- goto error;
- }
- mutex_lock(&connector->dev->mode_config.mutex);
- list_for_each_entry(mode, &connector->modes, head) {
- ret = snprintf(buf + len, max_size,
- "%s %d %d %d %d %d 0x%x\n",
- mode->name, drm_mode_vrefresh(mode), mode->picture_aspect_ratio,
- mode->htotal, mode->vtotal, mode->clock, mode->flags);
- if (dp_debug_check_buffer_overflow(ret, &max_size, &len))
- break;
- }
- mutex_unlock(&connector->dev->mode_config.mutex);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- kfree(buf);
- rc = -EFAULT;
- goto error;
- }
- *ppos += len;
- kfree(buf);
- return len;
- error:
- return rc;
- }
- static ssize_t dp_debug_read_edid_modes_mst(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf;
- u32 len = 0, ret = 0, max_size = SZ_4K;
- struct drm_connector *connector;
- struct drm_display_mode *mode;
- if (!debug) {
- DP_ERR("invalid data\n");
- return -ENODEV;
- }
- if (*ppos)
- return 0;
- connector = drm_connector_lookup((*debug->connector)->dev,
- NULL, debug->mst_con_id);
- if (!connector) {
- DP_ERR("connector %u not in mst list\n", debug->mst_con_id);
- return 0;
- }
- buf = kzalloc(SZ_4K, GFP_KERNEL);
- if (!buf)
- goto clean;
- mutex_lock(&connector->dev->mode_config.mutex);
- list_for_each_entry(mode, &connector->modes, head) {
- ret = snprintf(buf + len, max_size,
- "%s %d %d %d %d %d 0x%x\n",
- mode->name, drm_mode_vrefresh(mode),
- mode->picture_aspect_ratio, mode->htotal,
- mode->vtotal, mode->clock, mode->flags);
- if (dp_debug_check_buffer_overflow(ret, &max_size, &len))
- break;
- }
- mutex_unlock(&connector->dev->mode_config.mutex);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- len = -EFAULT;
- goto clean;
- }
- *ppos += len;
- clean:
- kfree(buf);
- drm_connector_put(connector);
- return len;
- }
- static ssize_t dp_debug_read_mst_con_id(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf;
- u32 len = 0, ret = 0, max_size = SZ_4K;
- int rc = 0;
- if (!debug) {
- DP_ERR("invalid data\n");
- rc = -ENODEV;
- goto error;
- }
- if (*ppos)
- goto error;
- buf = kzalloc(SZ_4K, GFP_KERNEL);
- if (!buf) {
- rc = -ENOMEM;
- goto error;
- }
- ret = snprintf(buf, max_size, "%u\n", debug->mst_con_id);
- len += ret;
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- kfree(buf);
- rc = -EFAULT;
- goto error;
- }
- *ppos += len;
- kfree(buf);
- return len;
- error:
- return rc;
- }
- static ssize_t dp_debug_read_mst_conn_info(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- struct drm_connector_list_iter conn_iter;
- struct drm_connector *connector;
- struct sde_connector *sde_conn;
- struct dp_display *display;
- char *buf;
- u32 len = 0, ret = 0, max_size = SZ_4K;
- int rc = 0;
- if (!debug) {
- DP_ERR("invalid data\n");
- rc = -ENODEV;
- goto error;
- }
- if (*ppos)
- goto error;
- buf = kzalloc(SZ_4K, GFP_KERNEL);
- if (!buf) {
- rc = -ENOMEM;
- goto error;
- }
- drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
- drm_for_each_connector_iter(connector, &conn_iter) {
- sde_conn = to_sde_connector(connector);
- display = sde_conn->display;
- if (!sde_conn->mst_port ||
- display->base_connector != (*debug->connector))
- continue;
- ret = scnprintf(buf + len, max_size,
- "conn name:%s, conn id:%d state:%d\n",
- connector->name, connector->base.id,
- connector->status);
- if (dp_debug_check_buffer_overflow(ret, &max_size, &len))
- break;
- }
- drm_connector_list_iter_end(&conn_iter);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- kfree(buf);
- rc = -EFAULT;
- goto error;
- }
- *ppos += len;
- kfree(buf);
- return len;
- error:
- return rc;
- }
- static ssize_t dp_debug_read_info(struct file *file, char __user *user_buff,
- size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf;
- u32 len = 0, rc = 0;
- u32 max_size = SZ_4K;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- buf = kzalloc(SZ_4K, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf))
- return -ENOMEM;
- rc = snprintf(buf + len, max_size, "\tstate=0x%x\n", debug->aux->state);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "\tlink_rate=%u\n",
- debug->panel->link_info.rate);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "\tnum_lanes=%u\n",
- debug->panel->link_info.num_lanes);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "\tresolution=%dx%d@%dHz\n",
- debug->panel->pinfo.h_active,
- debug->panel->pinfo.v_active,
- debug->panel->pinfo.refresh_rate);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "\tpclock=%dKHz\n",
- debug->panel->pinfo.pixel_clk_khz);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "\tbpp=%d\n",
- debug->panel->pinfo.bpp);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- /* Link Information */
- rc = snprintf(buf + len, max_size, "\ttest_req=%s\n",
- dp_link_get_test_name(debug->link->sink_request));
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size,
- "\tlane_count=%d\n", debug->link->link_params.lane_count);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size,
- "\tbw_code=%d\n", debug->link->link_params.bw_code);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size,
- "\tv_level=%d\n", debug->link->phy_params.v_level);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size,
- "\tp_level=%d\n", debug->link->phy_params.p_level);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len))
- goto error;
- *ppos += len;
- kfree(buf);
- return len;
- error:
- kfree(buf);
- return -EINVAL;
- }
- static ssize_t dp_debug_bw_code_read(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf;
- u32 len = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- buf = kzalloc(SZ_4K, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf))
- return -ENOMEM;
- len += snprintf(buf + len, (SZ_4K - len),
- "max_bw_code = %d\n", debug->panel->max_bw_code);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- kfree(buf);
- return -EFAULT;
- }
- *ppos += len;
- kfree(buf);
- return len;
- }
- static ssize_t dp_debug_tpg_read(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- u32 len = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- len += scnprintf(buf, SZ_8, "%d\n", debug->dp_debug.tpg_pattern);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len))
- return -EFAULT;
- *ppos += len;
- return len;
- }
- static int dp_debug_print_hdr_params_to_buf(struct drm_connector *connector,
- char *buf, u32 size)
- {
- int rc;
- u32 i, len = 0, max_size = size;
- struct sde_connector *c_conn;
- struct sde_connector_state *c_state;
- struct drm_msm_ext_hdr_metadata *hdr;
- c_conn = to_sde_connector(connector);
- c_state = to_sde_connector_state(connector->state);
- hdr = &c_state->hdr_meta;
- rc = snprintf(buf + len, max_size,
- "============SINK HDR PARAMETERS===========\n");
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "eotf = %d\n",
- c_conn->hdr_eotf);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "type_one = %d\n",
- c_conn->hdr_metadata_type_one);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "hdr_plus_app_ver = %d\n",
- c_conn->hdr_plus_app_ver);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "max_luminance = %d\n",
- c_conn->hdr_max_luminance);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "avg_luminance = %d\n",
- c_conn->hdr_avg_luminance);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "min_luminance = %d\n",
- c_conn->hdr_min_luminance);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size,
- "============VIDEO HDR PARAMETERS===========\n");
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "hdr_state = %d\n", hdr->hdr_state);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "hdr_supported = %d\n",
- hdr->hdr_supported);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "eotf = %d\n", hdr->eotf);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "white_point_x = %d\n",
- hdr->white_point_x);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "white_point_y = %d\n",
- hdr->white_point_y);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "max_luminance = %d\n",
- hdr->max_luminance);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "min_luminance = %d\n",
- hdr->min_luminance);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "max_content_light_level = %d\n",
- hdr->max_content_light_level);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "min_content_light_level = %d\n",
- hdr->max_average_light_level);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- for (i = 0; i < HDR_PRIMARIES_COUNT; i++) {
- rc = snprintf(buf + len, max_size, "primaries_x[%d] = %d\n",
- i, hdr->display_primaries_x[i]);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- rc = snprintf(buf + len, max_size, "primaries_y[%d] = %d\n",
- i, hdr->display_primaries_y[i]);
- if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
- goto error;
- }
- if (hdr->hdr_plus_payload && hdr->hdr_plus_payload_size) {
- u32 rowsize = 16, rem;
- struct sde_connector_dyn_hdr_metadata *dhdr =
- &c_state->dyn_hdr_meta;
- /**
- * Do not use user pointer from hdr->hdr_plus_payload directly,
- * instead use kernel's cached copy of payload data.
- */
- for (i = 0; i < dhdr->dynamic_hdr_payload_size; i += rowsize) {
- rc = snprintf(buf + len, max_size, "DHDR: ");
- if (dp_debug_check_buffer_overflow(rc, &max_size,
- &len))
- goto error;
- rem = dhdr->dynamic_hdr_payload_size - i;
- rc = hex_dump_to_buffer(&dhdr->dynamic_hdr_payload[i],
- min(rowsize, rem), rowsize, 1, buf + len,
- max_size, false);
- if (dp_debug_check_buffer_overflow(rc, &max_size,
- &len))
- goto error;
- rc = snprintf(buf + len, max_size, "\n");
- if (dp_debug_check_buffer_overflow(rc, &max_size,
- &len))
- goto error;
- }
- }
- return len;
- error:
- return -EOVERFLOW;
- }
- static ssize_t dp_debug_read_hdr(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf = NULL;
- u32 len = 0;
- u32 max_size = SZ_4K;
- struct drm_connector *connector;
- if (!debug) {
- DP_ERR("invalid data\n");
- return -ENODEV;
- }
- connector = *debug->connector;
- if (!connector) {
- DP_ERR("connector is NULL\n");
- return -EINVAL;
- }
- if (*ppos)
- return 0;
- buf = kzalloc(max_size, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf))
- return -ENOMEM;
- len = dp_debug_print_hdr_params_to_buf(connector, buf, max_size);
- if (len == -EOVERFLOW) {
- kfree(buf);
- return len;
- }
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- kfree(buf);
- return -EFAULT;
- }
- *ppos += len;
- kfree(buf);
- return len;
- }
- static ssize_t dp_debug_read_hdr_mst(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char *buf = NULL;
- u32 len = 0, max_size = SZ_4K;
- struct drm_connector_list_iter conn_iter;
- struct drm_connector *connector;
- bool in_list = false;
- if (!debug) {
- DP_ERR("invalid data\n");
- return -ENODEV;
- }
- drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
- drm_for_each_connector_iter(connector, &conn_iter) {
- if (connector->base.id == debug->mst_con_id) {
- in_list = true;
- break;
- }
- }
- drm_connector_list_iter_end(&conn_iter);
- if (!in_list) {
- DP_ERR("connector %u not in mst list\n", debug->mst_con_id);
- return -EINVAL;
- }
- if (!connector) {
- DP_ERR("connector is NULL\n");
- return -EINVAL;
- }
- if (*ppos)
- return 0;
- buf = kzalloc(max_size, GFP_KERNEL);
- if (ZERO_OR_NULL_PTR(buf))
- return -ENOMEM;
- len = dp_debug_print_hdr_params_to_buf(connector, buf, max_size);
- if (len == -EOVERFLOW) {
- kfree(buf);
- return len;
- }
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len)) {
- kfree(buf);
- return -EFAULT;
- }
- *ppos += len;
- kfree(buf);
- return len;
- }
- static void dp_debug_set_sim_mode(struct dp_debug_private *debug, bool sim)
- {
- struct drm_connector_list_iter conn_iter;
- struct drm_connector *connector;
- struct sde_connector *sde_conn;
- struct dp_display *display;
- struct dp_panel *panel;
- if (sim) {
- debug->dp_debug.sim_mode = true;
- dp_debug_enable_sim_mode(debug, DP_SIM_MODE_ALL);
- } else {
- if (debug->hotplug) {
- DP_WARN("sim mode off before hotplug disconnect\n");
- debug->hpd->simulate_connect(debug->hpd, false);
- debug->hotplug = false;
- }
- debug->aux->abort(debug->aux, true);
- debug->ctrl->abort(debug->ctrl, true);
- debug->dp_debug.sim_mode = false;
- debug->mst_edid_idx = 0;
- dp_debug_disable_sim_mode(debug, DP_SIM_MODE_ALL);
- }
- /* clear override settings in panel */
- drm_connector_list_iter_begin((*debug->connector)->dev, &conn_iter);
- drm_for_each_connector_iter(connector, &conn_iter) {
- sde_conn = to_sde_connector(connector);
- display = sde_conn->display;
- if (display->base_connector == (*debug->connector)) {
- panel = sde_conn->drv_panel;
- panel->mode_override = false;
- panel->mst_hide = false;
- }
- }
- drm_connector_list_iter_end(&conn_iter);
- /*
- * print simulation status as this code is executed
- * only while running in debug mode which is manually
- * triggered by a tester or a script.
- */
- DP_INFO("%s\n", sim ? "[ON]" : "[OFF]");
- }
- static ssize_t dp_debug_write_sim(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- int sim;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- mutex_lock(&debug->lock);
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &sim) != 0)
- goto end;
- dp_debug_set_sim_mode(debug, sim);
- end:
- mutex_unlock(&debug->lock);
- return len;
- }
- static ssize_t dp_debug_write_attention(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_8];
- size_t len = 0;
- int vdo;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_8 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- if (kstrtoint(buf, 10, &vdo) != 0)
- goto end;
- debug->hpd->simulate_attention(debug->hpd, vdo);
- end:
- return len;
- }
- static ssize_t dp_debug_write_dump(struct file *file,
- const char __user *user_buff, size_t count, loff_t *ppos)
- {
- struct dp_debug_private *debug = file->private_data;
- char buf[SZ_32];
- size_t len = 0;
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- /* Leave room for termination char */
- len = min_t(size_t, count, SZ_32 - 1);
- if (copy_from_user(buf, user_buff, len))
- goto end;
- buf[len] = '\0';
- if (sscanf(buf, "%31s", debug->reg_dump) != 1)
- goto end;
- /* qfprom register dump not supported */
- if (!strcmp(debug->reg_dump, "qfprom_physical"))
- strlcpy(debug->reg_dump, "clear", sizeof(debug->reg_dump));
- end:
- return len;
- }
- static ssize_t dp_debug_read_dump(struct file *file,
- char __user *user_buff, size_t count, loff_t *ppos)
- {
- int rc = 0;
- struct dp_debug_private *debug = file->private_data;
- u8 *buf = NULL;
- u32 len = 0;
- char prefix[SZ_32];
- if (!debug)
- return -ENODEV;
- if (*ppos)
- return 0;
- if (!debug->hpd->hpd_high || !strlen(debug->reg_dump))
- goto end;
- rc = debug->catalog->get_reg_dump(debug->catalog,
- debug->reg_dump, &buf, &len);
- if (rc)
- goto end;
- snprintf(prefix, sizeof(prefix), "%s: ", debug->reg_dump);
- print_hex_dump_debug(prefix, DUMP_PREFIX_NONE,
- 16, 4, buf, len, false);
- len = min_t(size_t, count, len);
- if (copy_to_user(user_buff, buf, len))
- return -EFAULT;
- *ppos += len;
- end:
- return len;
- }
- static const struct file_operations dp_debug_fops = {
- .open = simple_open,
- .read = dp_debug_read_info,
- };
- static const struct file_operations edid_modes_fops = {
- .open = simple_open,
- .read = dp_debug_read_edid_modes,
- .write = dp_debug_write_edid_modes,
- };
- static const struct file_operations edid_modes_mst_fops = {
- .open = simple_open,
- .read = dp_debug_read_edid_modes_mst,
- .write = dp_debug_write_edid_modes_mst,
- };
- static const struct file_operations mst_conn_info_fops = {
- .open = simple_open,
- .read = dp_debug_read_mst_conn_info,
- };
- static const struct file_operations mst_con_id_fops = {
- .open = simple_open,
- .read = dp_debug_read_mst_con_id,
- .write = dp_debug_write_mst_con_id,
- };
- static const struct file_operations mst_con_add_fops = {
- .open = simple_open,
- .write = dp_debug_write_mst_con_add,
- };
- static const struct file_operations mst_con_remove_fops = {
- .open = simple_open,
- .write = dp_debug_write_mst_con_remove,
- };
- static const struct file_operations hpd_fops = {
- .open = simple_open,
- .write = dp_debug_write_hpd,
- };
- static const struct file_operations edid_fops = {
- .open = simple_open,
- .write = dp_debug_write_edid,
- };
- static const struct file_operations dpcd_fops = {
- .open = simple_open,
- .write = dp_debug_write_dpcd,
- .read = dp_debug_read_dpcd,
- };
- static const struct file_operations connected_fops = {
- .open = simple_open,
- .read = dp_debug_read_connected,
- };
- static const struct file_operations bw_code_fops = {
- .open = simple_open,
- .read = dp_debug_bw_code_read,
- .write = dp_debug_bw_code_write,
- };
- static const struct file_operations exe_mode_fops = {
- .open = simple_open,
- .write = dp_debug_write_exe_mode,
- };
- static const struct file_operations tpg_fops = {
- .open = simple_open,
- .read = dp_debug_tpg_read,
- .write = dp_debug_tpg_write,
- };
- static const struct file_operations hdr_fops = {
- .open = simple_open,
- .read = dp_debug_read_hdr,
- };
- static const struct file_operations hdr_mst_fops = {
- .open = simple_open,
- .read = dp_debug_read_hdr_mst,
- };
- static const struct file_operations sim_fops = {
- .open = simple_open,
- .write = dp_debug_write_sim,
- };
- static const struct file_operations attention_fops = {
- .open = simple_open,
- .write = dp_debug_write_attention,
- };
- static const struct file_operations dump_fops = {
- .open = simple_open,
- .write = dp_debug_write_dump,
- .read = dp_debug_read_dump,
- };
- static const struct file_operations mst_mode_fops = {
- .open = simple_open,
- .write = dp_debug_mst_mode_write,
- .read = dp_debug_mst_mode_read,
- };
- static const struct file_operations mst_sideband_mode_fops = {
- .open = simple_open,
- .write = dp_debug_mst_sideband_mode_write,
- };
- static const struct file_operations max_pclk_khz_fops = {
- .open = simple_open,
- .write = dp_debug_max_pclk_khz_write,
- .read = dp_debug_max_pclk_khz_read,
- };
- static const struct file_operations hdcp_fops = {
- .open = simple_open,
- .write = dp_debug_write_hdcp,
- .read = dp_debug_read_hdcp,
- };
- static const struct file_operations mmrm_clk_cb_fops = {
- .open = simple_open,
- .write = dp_debug_mmrm_clk_cb_write,
- };
- static int dp_debug_init_mst(struct dp_debug_private *debug, struct dentry *dir)
- {
- int rc = 0;
- struct dentry *file;
- file = debugfs_create_file("mst_con_id", 0644, dir,
- debug, &mst_con_id_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs create mst_con_id failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("mst_con_info", 0644, dir,
- debug, &mst_conn_info_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs create mst_conn_info failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("mst_con_add", 0644, dir,
- debug, &mst_con_add_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DRM_ERROR("[%s] debugfs create mst_con_add failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("mst_con_remove", 0644, dir,
- debug, &mst_con_remove_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DRM_ERROR("[%s] debugfs create mst_con_remove failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("mst_mode", 0644, dir,
- debug, &mst_mode_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs mst_mode failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("mst_sideband_mode", 0644, dir,
- debug, &mst_sideband_mode_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs mst_sideband_mode failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- debugfs_create_u32("mst_edid_idx", 0644, dir, &debug->mst_edid_idx);
- return rc;
- }
- static int dp_debug_init_link(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- struct dentry *file;
- file = debugfs_create_file("max_bw_code", 0644, dir,
- debug, &bw_code_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs max_bw_code failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("max_pclk_khz", 0644, dir,
- debug, &max_pclk_khz_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs max_pclk_khz failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- debugfs_create_u32("max_lclk_khz", 0644, dir, &debug->parser->max_lclk_khz);
- debugfs_create_u32("lane_count", 0644, dir, &debug->panel->lane_count);
- debugfs_create_u32("link_bw_code", 0644, dir, &debug->panel->link_bw_code);
- file = debugfs_create_file("mmrm_clk_cb", 0644, dir, debug, &mmrm_clk_cb_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs mmrm_clk_cb failed, rc=%d\n", DEBUG_NAME, rc);
- return rc;
- }
- return rc;
- }
- static int dp_debug_init_hdcp(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- debugfs_create_bool("hdcp_wait_sink_sync", 0644, dir, &debug->dp_debug.hdcp_wait_sink_sync);
- debugfs_create_bool("force_encryption", 0644, dir, &debug->dp_debug.force_encryption);
- return rc;
- }
- static int dp_debug_init_sink_caps(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- struct dentry *file;
- file = debugfs_create_file("edid_modes", 0644, dir,
- debug, &edid_modes_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs create edid_modes failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("edid_modes_mst", 0644, dir,
- debug, &edid_modes_mst_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs create edid_modes_mst failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("edid", 0644, dir,
- debug, &edid_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs edid failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("dpcd", 0644, dir,
- debug, &dpcd_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs dpcd failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- return rc;
- }
- static int dp_debug_init_status(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- struct dentry *file;
- file = debugfs_create_file("dp_debug", 0444, dir,
- debug, &dp_debug_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs create file failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("connected", 0444, dir,
- debug, &connected_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs connected failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("hdr", 0400, dir, debug, &hdr_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs hdr failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("hdr_mst", 0400, dir, debug, &hdr_mst_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs hdr_mst failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("hdcp", 0644, dir, debug, &hdcp_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs hdcp failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- return rc;
- }
- static int dp_debug_init_sim(struct dp_debug_private *debug, struct dentry *dir)
- {
- int rc = 0;
- struct dentry *file;
- file = debugfs_create_file("hpd", 0644, dir, debug, &hpd_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs hpd failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("sim", 0644, dir, debug, &sim_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs sim failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("attention", 0644, dir,
- debug, &attention_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs attention failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- debugfs_create_bool("skip_uevent", 0644, dir, &debug->dp_debug.skip_uevent);
- debugfs_create_bool("force_multi_func", 0644, dir, &debug->hpd->force_multi_func);
- return rc;
- }
- static int dp_debug_init_dsc_fec(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- debugfs_create_bool("dsc_feature_enable", 0644, dir, &debug->parser->dsc_feature_enable);
- debugfs_create_bool("fec_feature_enable", 0644, dir, &debug->parser->fec_feature_enable);
- return rc;
- }
- static int dp_debug_init_tpg(struct dp_debug_private *debug, struct dentry *dir)
- {
- int rc = 0;
- struct dentry *file;
- file = debugfs_create_file("tpg_ctrl", 0644, dir,
- debug, &tpg_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs tpg failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- return rc;
- }
- static int dp_debug_init_reg_dump(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- struct dentry *file;
- file = debugfs_create_file("exe_mode", 0644, dir,
- debug, &exe_mode_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs register failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- file = debugfs_create_file("dump", 0644, dir,
- debug, &dump_fops);
- if (IS_ERR_OR_NULL(file)) {
- rc = PTR_ERR(file);
- DP_ERR("[%s] debugfs dump failed, rc=%d\n",
- DEBUG_NAME, rc);
- return rc;
- }
- return rc;
- }
- static int dp_debug_init_feature_toggle(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- debugfs_create_bool("ssc_enable", 0644, dir, &debug->pll->ssc_en);
- debugfs_create_bool("widebus_mode", 0644, dir, &debug->parser->has_widebus);
- return rc;
- }
- static int dp_debug_init_configs(struct dp_debug_private *debug,
- struct dentry *dir)
- {
- int rc = 0;
- debugfs_create_ulong("connect_notification_delay_ms", 0644, dir,
- &debug->dp_debug.connect_notification_delay_ms);
- debug->dp_debug.connect_notification_delay_ms =
- DEFAULT_CONNECT_NOTIFICATION_DELAY_MS;
- debugfs_create_u32("disconnect_delay_ms", 0644, dir, &debug->dp_debug.disconnect_delay_ms);
- debug->dp_debug.disconnect_delay_ms = DEFAULT_DISCONNECT_DELAY_MS;
- return rc;
- }
- static int dp_debug_init(struct dp_debug *dp_debug)
- {
- int rc = 0;
- struct dp_debug_private *debug = container_of(dp_debug,
- struct dp_debug_private, dp_debug);
- struct dentry *dir;
- if (!IS_ENABLED(CONFIG_DEBUG_FS)) {
- DP_WARN("Not creating debug root dir.");
- debug->root = NULL;
- return 0;
- }
- dir = debugfs_create_dir(DEBUG_NAME, NULL);
- if (IS_ERR_OR_NULL(dir)) {
- if (!dir)
- rc = -EINVAL;
- else
- rc = PTR_ERR(dir);
- DP_ERR("[%s] debugfs create dir failed, rc = %d\n",
- DEBUG_NAME, rc);
- goto error;
- }
- debug->root = dir;
- rc = dp_debug_init_status(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_sink_caps(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_mst(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_link(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_hdcp(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_sim(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_dsc_fec(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_tpg(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_reg_dump(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_feature_toggle(debug, dir);
- if (rc)
- goto error_remove_dir;
- rc = dp_debug_init_configs(debug, dir);
- if (rc)
- goto error_remove_dir;
- return 0;
- error_remove_dir:
- debugfs_remove_recursive(dir);
- error:
- return rc;
- }
- static void dp_debug_abort(struct dp_debug *dp_debug)
- {
- struct dp_debug_private *debug;
- if (!dp_debug)
- return;
- debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
- mutex_lock(&debug->lock);
- dp_debug_set_sim_mode(debug, false);
- mutex_unlock(&debug->lock);
- }
- static void dp_debug_set_mst_con(struct dp_debug *dp_debug, int con_id)
- {
- struct dp_debug_private *debug;
- if (!dp_debug)
- return;
- debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
- mutex_lock(&debug->lock);
- debug->mst_con_id = con_id;
- mutex_unlock(&debug->lock);
- DP_INFO("Selecting mst connector %d\n", con_id);
- }
- struct dp_debug *dp_debug_get(struct dp_debug_in *in)
- {
- int rc = 0;
- struct dp_debug_private *debug;
- struct dp_debug *dp_debug;
- if (!in->dev || !in->panel || !in->hpd || !in->link ||
- !in->catalog || !in->ctrl || !in->pll) {
- DP_ERR("invalid input\n");
- rc = -EINVAL;
- goto error;
- }
- debug = devm_kzalloc(in->dev, sizeof(*debug), GFP_KERNEL);
- if (!debug) {
- rc = -ENOMEM;
- goto error;
- }
- debug->hpd = in->hpd;
- debug->link = in->link;
- debug->panel = in->panel;
- debug->aux = in->aux;
- debug->dev = in->dev;
- debug->connector = in->connector;
- debug->catalog = in->catalog;
- debug->parser = in->parser;
- debug->ctrl = in->ctrl;
- debug->pll = in->pll;
- debug->display = in->display;
- dp_debug = &debug->dp_debug;
- mutex_init(&debug->lock);
- rc = dp_debug_init(dp_debug);
- if (rc) {
- devm_kfree(in->dev, debug);
- goto error;
- }
- debug->aux->access_lock = &debug->lock;
- dp_debug->abort = dp_debug_abort;
- dp_debug->set_mst_con = dp_debug_set_mst_con;
- dp_debug->max_pclk_khz = debug->parser->max_pclk_khz;
- return dp_debug;
- error:
- return ERR_PTR(rc);
- }
- static int dp_debug_deinit(struct dp_debug *dp_debug)
- {
- struct dp_debug_private *debug;
- if (!dp_debug)
- return -EINVAL;
- debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
- debugfs_remove_recursive(debug->root);
- if (debug->sim_bridge)
- dp_sim_destroy_bridge(debug->sim_bridge);
- return 0;
- }
- void dp_debug_put(struct dp_debug *dp_debug)
- {
- struct dp_debug_private *debug;
- if (!dp_debug)
- return;
- debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
- dp_debug_deinit(dp_debug);
- mutex_destroy(&debug->lock);
- devm_kfree(debug->dev, debug);
- }
|