1d11a9369SAbhinav Kumar // SPDX-License-Identifier: GPL-2.0-only 2d11a9369SAbhinav Kumar /* 3d11a9369SAbhinav Kumar * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. 4d11a9369SAbhinav Kumar */ 5d11a9369SAbhinav Kumar 6d11a9369SAbhinav Kumar #define pr_fmt(fmt)"[drm-dp] %s: " fmt, __func__ 7d11a9369SAbhinav Kumar 8d11a9369SAbhinav Kumar #include <linux/debugfs.h> 9d11a9369SAbhinav Kumar #include <drm/drm_connector.h> 10f913454aSAbhinav Kumar #include <drm/drm_file.h> 11d11a9369SAbhinav Kumar 12d11a9369SAbhinav Kumar #include "dp_parser.h" 13d11a9369SAbhinav Kumar #include "dp_catalog.h" 14d11a9369SAbhinav Kumar #include "dp_aux.h" 15d11a9369SAbhinav Kumar #include "dp_ctrl.h" 16d11a9369SAbhinav Kumar #include "dp_debug.h" 17d11a9369SAbhinav Kumar #include "dp_display.h" 18d11a9369SAbhinav Kumar 19f913454aSAbhinav Kumar #define DEBUG_NAME "msm_dp" 20d11a9369SAbhinav Kumar 21d11a9369SAbhinav Kumar struct dp_debug_private { 22d11a9369SAbhinav Kumar struct dentry *root; 23d11a9369SAbhinav Kumar 24d11a9369SAbhinav Kumar struct dp_usbpd *usbpd; 25d11a9369SAbhinav Kumar struct dp_link *link; 26d11a9369SAbhinav Kumar struct dp_panel *panel; 27*899b2608SBjorn Andersson struct drm_connector *connector; 28d11a9369SAbhinav Kumar struct device *dev; 29f913454aSAbhinav Kumar struct drm_device *drm_dev; 30d11a9369SAbhinav Kumar 31d11a9369SAbhinav Kumar struct dp_debug dp_debug; 32d11a9369SAbhinav Kumar }; 33d11a9369SAbhinav Kumar 34d11a9369SAbhinav Kumar static int dp_debug_check_buffer_overflow(int rc, int *max_size, int *len) 35d11a9369SAbhinav Kumar { 36d11a9369SAbhinav Kumar if (rc >= *max_size) { 37d11a9369SAbhinav Kumar DRM_ERROR("buffer overflow\n"); 38d11a9369SAbhinav Kumar return -EINVAL; 39d11a9369SAbhinav Kumar } 40d11a9369SAbhinav Kumar *len += rc; 41d11a9369SAbhinav Kumar *max_size = SZ_4K - *len; 42d11a9369SAbhinav Kumar 43d11a9369SAbhinav Kumar return 0; 44d11a9369SAbhinav Kumar } 45d11a9369SAbhinav Kumar 46d11a9369SAbhinav Kumar static ssize_t dp_debug_read_info(struct file *file, char __user *user_buff, 47d11a9369SAbhinav Kumar size_t count, loff_t *ppos) 48d11a9369SAbhinav Kumar { 49d11a9369SAbhinav Kumar struct dp_debug_private *debug = file->private_data; 50d11a9369SAbhinav Kumar char *buf; 51d11a9369SAbhinav Kumar u32 len = 0, rc = 0; 52d11a9369SAbhinav Kumar u64 lclk = 0; 53d11a9369SAbhinav Kumar u32 max_size = SZ_4K; 54d11a9369SAbhinav Kumar u32 link_params_rate; 55d11a9369SAbhinav Kumar struct drm_display_mode *drm_mode; 56d11a9369SAbhinav Kumar 57d11a9369SAbhinav Kumar if (!debug) 58d11a9369SAbhinav Kumar return -ENODEV; 59d11a9369SAbhinav Kumar 60d11a9369SAbhinav Kumar if (*ppos) 61d11a9369SAbhinav Kumar return 0; 62d11a9369SAbhinav Kumar 63d11a9369SAbhinav Kumar buf = kzalloc(SZ_4K, GFP_KERNEL); 64d11a9369SAbhinav Kumar if (!buf) 65d11a9369SAbhinav Kumar return -ENOMEM; 66d11a9369SAbhinav Kumar 67d11a9369SAbhinav Kumar drm_mode = &debug->panel->dp_mode.drm_mode; 68d11a9369SAbhinav Kumar 69d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, "\tname = %s\n", DEBUG_NAME); 70d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 71d11a9369SAbhinav Kumar goto error; 72d11a9369SAbhinav Kumar 73d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 74d11a9369SAbhinav Kumar "\tdp_panel\n\t\tmax_pclk_khz = %d\n", 75d11a9369SAbhinav Kumar debug->panel->max_pclk_khz); 76d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 77d11a9369SAbhinav Kumar goto error; 78d11a9369SAbhinav Kumar 79d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 80d11a9369SAbhinav Kumar "\tdrm_dp_link\n\t\trate = %u\n", 81d11a9369SAbhinav Kumar debug->panel->link_info.rate); 82d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 83d11a9369SAbhinav Kumar goto error; 84d11a9369SAbhinav Kumar 85d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 86d11a9369SAbhinav Kumar "\t\tnum_lanes = %u\n", 87d11a9369SAbhinav Kumar debug->panel->link_info.num_lanes); 88d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 89d11a9369SAbhinav Kumar goto error; 90d11a9369SAbhinav Kumar 91d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 92d11a9369SAbhinav Kumar "\t\tcapabilities = %lu\n", 93d11a9369SAbhinav Kumar debug->panel->link_info.capabilities); 94d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 95d11a9369SAbhinav Kumar goto error; 96d11a9369SAbhinav Kumar 97d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 98d11a9369SAbhinav Kumar "\tdp_panel_info:\n\t\tactive = %dx%d\n", 99d11a9369SAbhinav Kumar drm_mode->hdisplay, 100d11a9369SAbhinav Kumar drm_mode->vdisplay); 101d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 102d11a9369SAbhinav Kumar goto error; 103d11a9369SAbhinav Kumar 104d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 105d11a9369SAbhinav Kumar "\t\tback_porch = %dx%d\n", 106d11a9369SAbhinav Kumar drm_mode->htotal - drm_mode->hsync_end, 107d11a9369SAbhinav Kumar drm_mode->vtotal - drm_mode->vsync_end); 108d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 109d11a9369SAbhinav Kumar goto error; 110d11a9369SAbhinav Kumar 111d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 112d11a9369SAbhinav Kumar "\t\tfront_porch = %dx%d\n", 113d11a9369SAbhinav Kumar drm_mode->hsync_start - drm_mode->hdisplay, 114d11a9369SAbhinav Kumar drm_mode->vsync_start - drm_mode->vdisplay); 115d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 116d11a9369SAbhinav Kumar goto error; 117d11a9369SAbhinav Kumar 118d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 119d11a9369SAbhinav Kumar "\t\tsync_width = %dx%d\n", 120d11a9369SAbhinav Kumar drm_mode->hsync_end - drm_mode->hsync_start, 121d11a9369SAbhinav Kumar drm_mode->vsync_end - drm_mode->vsync_start); 122d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 123d11a9369SAbhinav Kumar goto error; 124d11a9369SAbhinav Kumar 125d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 126d11a9369SAbhinav Kumar "\t\tactive_low = %dx%d\n", 127d11a9369SAbhinav Kumar debug->panel->dp_mode.h_active_low, 128d11a9369SAbhinav Kumar debug->panel->dp_mode.v_active_low); 129d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 130d11a9369SAbhinav Kumar goto error; 131d11a9369SAbhinav Kumar 132d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 133d11a9369SAbhinav Kumar "\t\th_skew = %d\n", 134d11a9369SAbhinav Kumar drm_mode->hskew); 135d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 136d11a9369SAbhinav Kumar goto error; 137d11a9369SAbhinav Kumar 138d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 139d11a9369SAbhinav Kumar "\t\trefresh rate = %d\n", 140d11a9369SAbhinav Kumar drm_mode_vrefresh(drm_mode)); 141d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 142d11a9369SAbhinav Kumar goto error; 143d11a9369SAbhinav Kumar 144d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 145d11a9369SAbhinav Kumar "\t\tpixel clock khz = %d\n", 146d11a9369SAbhinav Kumar drm_mode->clock); 147d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 148d11a9369SAbhinav Kumar goto error; 149d11a9369SAbhinav Kumar 150d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 151d11a9369SAbhinav Kumar "\t\tbpp = %d\n", 152d11a9369SAbhinav Kumar debug->panel->dp_mode.bpp); 153d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 154d11a9369SAbhinav Kumar goto error; 155d11a9369SAbhinav Kumar 156d11a9369SAbhinav Kumar /* Link Information */ 157d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 158d11a9369SAbhinav Kumar "\tdp_link:\n\t\ttest_requested = %d\n", 159d11a9369SAbhinav Kumar debug->link->sink_request); 160d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 161d11a9369SAbhinav Kumar goto error; 162d11a9369SAbhinav Kumar 163d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 164d11a9369SAbhinav Kumar "\t\tnum_lanes = %d\n", 165d11a9369SAbhinav Kumar debug->link->link_params.num_lanes); 166d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 167d11a9369SAbhinav Kumar goto error; 168d11a9369SAbhinav Kumar 169d11a9369SAbhinav Kumar link_params_rate = debug->link->link_params.rate; 170d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 171d11a9369SAbhinav Kumar "\t\tbw_code = %d\n", 172d11a9369SAbhinav Kumar drm_dp_link_rate_to_bw_code(link_params_rate)); 173d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 174d11a9369SAbhinav Kumar goto error; 175d11a9369SAbhinav Kumar 176d11a9369SAbhinav Kumar lclk = debug->link->link_params.rate * 1000; 177d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 178d11a9369SAbhinav Kumar "\t\tlclk = %lld\n", lclk); 179d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 180d11a9369SAbhinav Kumar goto error; 181d11a9369SAbhinav Kumar 182d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 183d11a9369SAbhinav Kumar "\t\tv_level = %d\n", 184d11a9369SAbhinav Kumar debug->link->phy_params.v_level); 185d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 186d11a9369SAbhinav Kumar goto error; 187d11a9369SAbhinav Kumar 188d11a9369SAbhinav Kumar rc = snprintf(buf + len, max_size, 189d11a9369SAbhinav Kumar "\t\tp_level = %d\n", 190d11a9369SAbhinav Kumar debug->link->phy_params.p_level); 191d11a9369SAbhinav Kumar if (dp_debug_check_buffer_overflow(rc, &max_size, &len)) 192d11a9369SAbhinav Kumar goto error; 193d11a9369SAbhinav Kumar 194d11a9369SAbhinav Kumar if (copy_to_user(user_buff, buf, len)) 195d11a9369SAbhinav Kumar goto error; 196d11a9369SAbhinav Kumar 197d11a9369SAbhinav Kumar *ppos += len; 198d11a9369SAbhinav Kumar 199d11a9369SAbhinav Kumar kfree(buf); 200d11a9369SAbhinav Kumar return len; 201d11a9369SAbhinav Kumar error: 202d11a9369SAbhinav Kumar kfree(buf); 203d11a9369SAbhinav Kumar return -EINVAL; 204d11a9369SAbhinav Kumar } 205d11a9369SAbhinav Kumar 206de3ee254SAbhinav Kumar static int dp_test_data_show(struct seq_file *m, void *data) 207de3ee254SAbhinav Kumar { 208*899b2608SBjorn Andersson const struct dp_debug_private *debug = m->private; 209*899b2608SBjorn Andersson const struct drm_connector *connector = debug->connector; 210de3ee254SAbhinav Kumar u32 bpc; 211de3ee254SAbhinav Kumar 212de3ee254SAbhinav Kumar if (connector->status == connector_status_connected) { 213de3ee254SAbhinav Kumar bpc = debug->link->test_video.test_bit_depth; 214de3ee254SAbhinav Kumar seq_printf(m, "hdisplay: %d\n", 215de3ee254SAbhinav Kumar debug->link->test_video.test_h_width); 216de3ee254SAbhinav Kumar seq_printf(m, "vdisplay: %d\n", 217de3ee254SAbhinav Kumar debug->link->test_video.test_v_height); 218de3ee254SAbhinav Kumar seq_printf(m, "bpc: %u\n", 219de3ee254SAbhinav Kumar dp_link_bit_depth_to_bpc(bpc)); 220*899b2608SBjorn Andersson } else { 221de3ee254SAbhinav Kumar seq_puts(m, "0"); 222de3ee254SAbhinav Kumar } 223de3ee254SAbhinav Kumar 224de3ee254SAbhinav Kumar return 0; 225de3ee254SAbhinav Kumar } 226de3ee254SAbhinav Kumar DEFINE_SHOW_ATTRIBUTE(dp_test_data); 227de3ee254SAbhinav Kumar 228de3ee254SAbhinav Kumar static int dp_test_type_show(struct seq_file *m, void *data) 229de3ee254SAbhinav Kumar { 230*899b2608SBjorn Andersson const struct dp_debug_private *debug = m->private; 231*899b2608SBjorn Andersson const struct drm_connector *connector = debug->connector; 232de3ee254SAbhinav Kumar 233de3ee254SAbhinav Kumar if (connector->status == connector_status_connected) 234de3ee254SAbhinav Kumar seq_printf(m, "%02x", DP_TEST_LINK_VIDEO_PATTERN); 235de3ee254SAbhinav Kumar else 236de3ee254SAbhinav Kumar seq_puts(m, "0"); 237de3ee254SAbhinav Kumar 238de3ee254SAbhinav Kumar return 0; 239de3ee254SAbhinav Kumar } 240de3ee254SAbhinav Kumar DEFINE_SHOW_ATTRIBUTE(dp_test_type); 241de3ee254SAbhinav Kumar 242de3ee254SAbhinav Kumar static ssize_t dp_test_active_write(struct file *file, 243de3ee254SAbhinav Kumar const char __user *ubuf, 244de3ee254SAbhinav Kumar size_t len, loff_t *offp) 245de3ee254SAbhinav Kumar { 246de3ee254SAbhinav Kumar char *input_buffer; 247de3ee254SAbhinav Kumar int status = 0; 248*899b2608SBjorn Andersson const struct dp_debug_private *debug; 249*899b2608SBjorn Andersson const struct drm_connector *connector; 250de3ee254SAbhinav Kumar int val = 0; 251de3ee254SAbhinav Kumar 252de3ee254SAbhinav Kumar debug = ((struct seq_file *)file->private_data)->private; 253*899b2608SBjorn Andersson connector = debug->connector; 254de3ee254SAbhinav Kumar 255de3ee254SAbhinav Kumar if (len == 0) 256de3ee254SAbhinav Kumar return 0; 257de3ee254SAbhinav Kumar 258de3ee254SAbhinav Kumar input_buffer = memdup_user_nul(ubuf, len); 259de3ee254SAbhinav Kumar if (IS_ERR(input_buffer)) 260de3ee254SAbhinav Kumar return PTR_ERR(input_buffer); 261de3ee254SAbhinav Kumar 262de3ee254SAbhinav Kumar DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len); 263de3ee254SAbhinav Kumar 264de3ee254SAbhinav Kumar if (connector->status == connector_status_connected) { 265de3ee254SAbhinav Kumar status = kstrtoint(input_buffer, 10, &val); 266*899b2608SBjorn Andersson if (status < 0) { 267*899b2608SBjorn Andersson kfree(input_buffer); 268*899b2608SBjorn Andersson return status; 269*899b2608SBjorn Andersson } 270de3ee254SAbhinav Kumar DRM_DEBUG_DRIVER("Got %d for test active\n", val); 271de3ee254SAbhinav Kumar /* To prevent erroneous activation of the compliance 272de3ee254SAbhinav Kumar * testing code, only accept an actual value of 1 here 273de3ee254SAbhinav Kumar */ 274de3ee254SAbhinav Kumar if (val == 1) 275de3ee254SAbhinav Kumar debug->panel->video_test = true; 276de3ee254SAbhinav Kumar else 277de3ee254SAbhinav Kumar debug->panel->video_test = false; 278de3ee254SAbhinav Kumar } 279de3ee254SAbhinav Kumar kfree(input_buffer); 280de3ee254SAbhinav Kumar 281de3ee254SAbhinav Kumar *offp += len; 282de3ee254SAbhinav Kumar return len; 283de3ee254SAbhinav Kumar } 284de3ee254SAbhinav Kumar 285de3ee254SAbhinav Kumar static int dp_test_active_show(struct seq_file *m, void *data) 286de3ee254SAbhinav Kumar { 287de3ee254SAbhinav Kumar struct dp_debug_private *debug = m->private; 288*899b2608SBjorn Andersson struct drm_connector *connector = debug->connector; 289de3ee254SAbhinav Kumar 290de3ee254SAbhinav Kumar if (connector->status == connector_status_connected) { 291de3ee254SAbhinav Kumar if (debug->panel->video_test) 292de3ee254SAbhinav Kumar seq_puts(m, "1"); 293de3ee254SAbhinav Kumar else 294de3ee254SAbhinav Kumar seq_puts(m, "0"); 295*899b2608SBjorn Andersson } else { 296de3ee254SAbhinav Kumar seq_puts(m, "0"); 297de3ee254SAbhinav Kumar } 298de3ee254SAbhinav Kumar 299de3ee254SAbhinav Kumar return 0; 300de3ee254SAbhinav Kumar } 301de3ee254SAbhinav Kumar 302de3ee254SAbhinav Kumar static int dp_test_active_open(struct inode *inode, 303de3ee254SAbhinav Kumar struct file *file) 304de3ee254SAbhinav Kumar { 305de3ee254SAbhinav Kumar return single_open(file, dp_test_active_show, 306de3ee254SAbhinav Kumar inode->i_private); 307de3ee254SAbhinav Kumar } 308de3ee254SAbhinav Kumar 309d11a9369SAbhinav Kumar static const struct file_operations dp_debug_fops = { 310d11a9369SAbhinav Kumar .open = simple_open, 311d11a9369SAbhinav Kumar .read = dp_debug_read_info, 312d11a9369SAbhinav Kumar }; 313d11a9369SAbhinav Kumar 314de3ee254SAbhinav Kumar static const struct file_operations test_active_fops = { 315de3ee254SAbhinav Kumar .owner = THIS_MODULE, 316de3ee254SAbhinav Kumar .open = dp_test_active_open, 317de3ee254SAbhinav Kumar .read = seq_read, 318de3ee254SAbhinav Kumar .llseek = seq_lseek, 319de3ee254SAbhinav Kumar .release = single_release, 320de3ee254SAbhinav Kumar .write = dp_test_active_write 321de3ee254SAbhinav Kumar }; 322de3ee254SAbhinav Kumar 323f913454aSAbhinav Kumar static int dp_debug_init(struct dp_debug *dp_debug, struct drm_minor *minor) 324d11a9369SAbhinav Kumar { 325d11a9369SAbhinav Kumar int rc = 0; 326d11a9369SAbhinav Kumar struct dp_debug_private *debug = container_of(dp_debug, 327d11a9369SAbhinav Kumar struct dp_debug_private, dp_debug); 328d11a9369SAbhinav Kumar 329cb3fd74aSAbhinav Kumar debugfs_create_file("dp_debug", 0444, minor->debugfs_root, 330d11a9369SAbhinav Kumar debug, &dp_debug_fops); 331d11a9369SAbhinav Kumar 332cb3fd74aSAbhinav Kumar debugfs_create_file("msm_dp_test_active", 0444, 333de3ee254SAbhinav Kumar minor->debugfs_root, 334de3ee254SAbhinav Kumar debug, &test_active_fops); 335de3ee254SAbhinav Kumar 336cb3fd74aSAbhinav Kumar debugfs_create_file("msm_dp_test_data", 0444, 337de3ee254SAbhinav Kumar minor->debugfs_root, 338de3ee254SAbhinav Kumar debug, &dp_test_data_fops); 339de3ee254SAbhinav Kumar 340cb3fd74aSAbhinav Kumar debugfs_create_file("msm_dp_test_type", 0444, 341de3ee254SAbhinav Kumar minor->debugfs_root, 342de3ee254SAbhinav Kumar debug, &dp_test_type_fops); 343de3ee254SAbhinav Kumar 344f913454aSAbhinav Kumar debug->root = minor->debugfs_root; 345f913454aSAbhinav Kumar 346d11a9369SAbhinav Kumar return rc; 347d11a9369SAbhinav Kumar } 348d11a9369SAbhinav Kumar 349d11a9369SAbhinav Kumar struct dp_debug *dp_debug_get(struct device *dev, struct dp_panel *panel, 350d11a9369SAbhinav Kumar struct dp_usbpd *usbpd, struct dp_link *link, 351*899b2608SBjorn Andersson struct drm_connector *connector, struct drm_minor *minor) 352d11a9369SAbhinav Kumar { 353d11a9369SAbhinav Kumar int rc = 0; 354d11a9369SAbhinav Kumar struct dp_debug_private *debug; 355d11a9369SAbhinav Kumar struct dp_debug *dp_debug; 356d11a9369SAbhinav Kumar 357d11a9369SAbhinav Kumar if (!dev || !panel || !usbpd || !link) { 358d11a9369SAbhinav Kumar DRM_ERROR("invalid input\n"); 359d11a9369SAbhinav Kumar rc = -EINVAL; 360d11a9369SAbhinav Kumar goto error; 361d11a9369SAbhinav Kumar } 362d11a9369SAbhinav Kumar 363d11a9369SAbhinav Kumar debug = devm_kzalloc(dev, sizeof(*debug), GFP_KERNEL); 364d11a9369SAbhinav Kumar if (!debug) { 365d11a9369SAbhinav Kumar rc = -ENOMEM; 366d11a9369SAbhinav Kumar goto error; 367d11a9369SAbhinav Kumar } 368d11a9369SAbhinav Kumar 369d11a9369SAbhinav Kumar debug->dp_debug.debug_en = false; 370d11a9369SAbhinav Kumar debug->usbpd = usbpd; 371d11a9369SAbhinav Kumar debug->link = link; 372d11a9369SAbhinav Kumar debug->panel = panel; 373d11a9369SAbhinav Kumar debug->dev = dev; 374f913454aSAbhinav Kumar debug->drm_dev = minor->dev; 375d11a9369SAbhinav Kumar debug->connector = connector; 376d11a9369SAbhinav Kumar 377d11a9369SAbhinav Kumar dp_debug = &debug->dp_debug; 378d11a9369SAbhinav Kumar dp_debug->vdisplay = 0; 379d11a9369SAbhinav Kumar dp_debug->hdisplay = 0; 380d11a9369SAbhinav Kumar dp_debug->vrefresh = 0; 381d11a9369SAbhinav Kumar 382f913454aSAbhinav Kumar rc = dp_debug_init(dp_debug, minor); 383d11a9369SAbhinav Kumar if (rc) { 384d11a9369SAbhinav Kumar devm_kfree(dev, debug); 385d11a9369SAbhinav Kumar goto error; 386d11a9369SAbhinav Kumar } 387d11a9369SAbhinav Kumar 388d11a9369SAbhinav Kumar return dp_debug; 389d11a9369SAbhinav Kumar error: 390d11a9369SAbhinav Kumar return ERR_PTR(rc); 391d11a9369SAbhinav Kumar } 392d11a9369SAbhinav Kumar 393d11a9369SAbhinav Kumar static int dp_debug_deinit(struct dp_debug *dp_debug) 394d11a9369SAbhinav Kumar { 395d11a9369SAbhinav Kumar struct dp_debug_private *debug; 396d11a9369SAbhinav Kumar 397d11a9369SAbhinav Kumar if (!dp_debug) 398d11a9369SAbhinav Kumar return -EINVAL; 399d11a9369SAbhinav Kumar 400d11a9369SAbhinav Kumar debug = container_of(dp_debug, struct dp_debug_private, dp_debug); 401d11a9369SAbhinav Kumar 402d11a9369SAbhinav Kumar debugfs_remove_recursive(debug->root); 403d11a9369SAbhinav Kumar 404d11a9369SAbhinav Kumar return 0; 405d11a9369SAbhinav Kumar } 406d11a9369SAbhinav Kumar 407d11a9369SAbhinav Kumar void dp_debug_put(struct dp_debug *dp_debug) 408d11a9369SAbhinav Kumar { 409d11a9369SAbhinav Kumar struct dp_debug_private *debug; 410d11a9369SAbhinav Kumar 411d11a9369SAbhinav Kumar if (!dp_debug) 412d11a9369SAbhinav Kumar return; 413d11a9369SAbhinav Kumar 414d11a9369SAbhinav Kumar debug = container_of(dp_debug, struct dp_debug_private, dp_debug); 415d11a9369SAbhinav Kumar 416d11a9369SAbhinav Kumar dp_debug_deinit(dp_debug); 417d11a9369SAbhinav Kumar 418d11a9369SAbhinav Kumar devm_kfree(debug->dev, debug); 419d11a9369SAbhinav Kumar } 420