2 * uvc_debugfs.c -- USB Video Class driver - Debugging support
5 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
14 #include <linux/module.h>
15 #include <linux/debugfs.h>
16 #include <linux/slab.h>
17 #include <linux/usb.h>
21 /* -----------------------------------------------------------------------------
25 #define UVC_DEBUGFS_BUF_SIZE 1024
27 struct uvc_debugfs_buffer
{
29 char data
[UVC_DEBUGFS_BUF_SIZE
];
32 static int uvc_debugfs_stats_open(struct inode
*inode
, struct file
*file
)
34 struct uvc_streaming
*stream
= inode
->i_private
;
35 struct uvc_debugfs_buffer
*buf
;
37 buf
= kmalloc(sizeof(*buf
), GFP_KERNEL
);
41 buf
->count
= uvc_video_stats_dump(stream
, buf
->data
, sizeof(buf
->data
));
43 file
->private_data
= buf
;
47 static ssize_t
uvc_debugfs_stats_read(struct file
*file
, char __user
*user_buf
,
48 size_t nbytes
, loff_t
*ppos
)
50 struct uvc_debugfs_buffer
*buf
= file
->private_data
;
52 return simple_read_from_buffer(user_buf
, nbytes
, ppos
, buf
->data
,
56 static int uvc_debugfs_stats_release(struct inode
*inode
, struct file
*file
)
58 kfree(file
->private_data
);
59 file
->private_data
= NULL
;
64 static const struct file_operations uvc_debugfs_stats_fops
= {
66 .open
= uvc_debugfs_stats_open
,
68 .read
= uvc_debugfs_stats_read
,
69 .release
= uvc_debugfs_stats_release
,
72 /* -----------------------------------------------------------------------------
73 * Global and stream initialization/cleanup
76 static struct dentry
*uvc_debugfs_root_dir
;
78 void uvc_debugfs_init_stream(struct uvc_streaming
*stream
)
80 struct usb_device
*udev
= stream
->dev
->udev
;
84 if (uvc_debugfs_root_dir
== NULL
)
87 sprintf(dir_name
, "%u-%u", udev
->bus
->busnum
, udev
->devnum
);
89 dent
= debugfs_create_dir(dir_name
, uvc_debugfs_root_dir
);
90 if (IS_ERR_OR_NULL(dent
)) {
91 uvc_printk(KERN_INFO
, "Unable to create debugfs %s "
92 "directory.\n", dir_name
);
96 stream
->debugfs_dir
= dent
;
98 dent
= debugfs_create_file("stats", 0444, stream
->debugfs_dir
,
99 stream
, &uvc_debugfs_stats_fops
);
100 if (IS_ERR_OR_NULL(dent
)) {
101 uvc_printk(KERN_INFO
, "Unable to create debugfs stats file.\n");
102 uvc_debugfs_cleanup_stream(stream
);
107 void uvc_debugfs_cleanup_stream(struct uvc_streaming
*stream
)
109 if (stream
->debugfs_dir
== NULL
)
112 debugfs_remove_recursive(stream
->debugfs_dir
);
113 stream
->debugfs_dir
= NULL
;
116 void uvc_debugfs_init(void)
120 dir
= debugfs_create_dir("uvcvideo", usb_debug_root
);
121 if (IS_ERR_OR_NULL(dir
)) {
122 uvc_printk(KERN_INFO
, "Unable to create debugfs directory\n");
126 uvc_debugfs_root_dir
= dir
;
129 void uvc_debugfs_cleanup(void)
131 if (uvc_debugfs_root_dir
!= NULL
)
132 debugfs_remove_recursive(uvc_debugfs_root_dir
);