WIP FPC-III support
[linux/fpc-iii.git] / drivers / media / usb / uvc / uvc_debugfs.c
blob1a1258d4ffcadf8a932b783013c3ec45ebd40f8e
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * uvc_debugfs.c -- USB Video Class driver - Debugging support
5 * Copyright (C) 2011
6 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
7 */
9 #include <linux/module.h>
10 #include <linux/debugfs.h>
11 #include <linux/slab.h>
12 #include <linux/usb.h>
14 #include "uvcvideo.h"
16 /* -----------------------------------------------------------------------------
17 * Statistics
20 #define UVC_DEBUGFS_BUF_SIZE 1024
22 struct uvc_debugfs_buffer {
23 size_t count;
24 char data[UVC_DEBUGFS_BUF_SIZE];
27 static int uvc_debugfs_stats_open(struct inode *inode, struct file *file)
29 struct uvc_streaming *stream = inode->i_private;
30 struct uvc_debugfs_buffer *buf;
32 buf = kmalloc(sizeof(*buf), GFP_KERNEL);
33 if (buf == NULL)
34 return -ENOMEM;
36 buf->count = uvc_video_stats_dump(stream, buf->data, sizeof(buf->data));
38 file->private_data = buf;
39 return 0;
42 static ssize_t uvc_debugfs_stats_read(struct file *file, char __user *user_buf,
43 size_t nbytes, loff_t *ppos)
45 struct uvc_debugfs_buffer *buf = file->private_data;
47 return simple_read_from_buffer(user_buf, nbytes, ppos, buf->data,
48 buf->count);
51 static int uvc_debugfs_stats_release(struct inode *inode, struct file *file)
53 kfree(file->private_data);
54 file->private_data = NULL;
56 return 0;
59 static const struct file_operations uvc_debugfs_stats_fops = {
60 .owner = THIS_MODULE,
61 .open = uvc_debugfs_stats_open,
62 .llseek = no_llseek,
63 .read = uvc_debugfs_stats_read,
64 .release = uvc_debugfs_stats_release,
67 /* -----------------------------------------------------------------------------
68 * Global and stream initialization/cleanup
71 static struct dentry *uvc_debugfs_root_dir;
73 void uvc_debugfs_init_stream(struct uvc_streaming *stream)
75 struct usb_device *udev = stream->dev->udev;
76 char dir_name[33];
78 if (uvc_debugfs_root_dir == NULL)
79 return;
81 snprintf(dir_name, sizeof(dir_name), "%u-%u-%u", udev->bus->busnum,
82 udev->devnum, stream->intfnum);
84 stream->debugfs_dir = debugfs_create_dir(dir_name,
85 uvc_debugfs_root_dir);
87 debugfs_create_file("stats", 0444, stream->debugfs_dir, stream,
88 &uvc_debugfs_stats_fops);
91 void uvc_debugfs_cleanup_stream(struct uvc_streaming *stream)
93 debugfs_remove_recursive(stream->debugfs_dir);
94 stream->debugfs_dir = NULL;
97 void uvc_debugfs_init(void)
99 uvc_debugfs_root_dir = debugfs_create_dir("uvcvideo", usb_debug_root);
102 void uvc_debugfs_cleanup(void)
104 debugfs_remove_recursive(uvc_debugfs_root_dir);