1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/kernel.h>
19#include <linux/errno.h>
20#include <linux/module.h>
21#include <linux/usb.h>
22#include <linux/videodev2.h>
23
24#include "pvrusb2-hdw.h"
25#include "pvrusb2-devattr.h"
26#include "pvrusb2-context.h"
27#include "pvrusb2-debug.h"
28#include "pvrusb2-v4l2.h"
29#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
30#include "pvrusb2-sysfs.h"
31#endif
32
33#define DRIVER_AUTHOR "Mike Isely <isely@pobox.com>"
34#define DRIVER_DESC "Hauppauge WinTV-PVR-USB2 MPEG2 Encoder/Tuner"
35#define DRIVER_VERSION "V4L in-tree version"
36
37#define DEFAULT_DEBUG_MASK (PVR2_TRACE_ERROR_LEGS| \
38 PVR2_TRACE_INFO| \
39 PVR2_TRACE_STD| \
40 PVR2_TRACE_TOLERANCE| \
41 PVR2_TRACE_TRAP| \
42 0)
43
44int pvrusb2_debug = DEFAULT_DEBUG_MASK;
45
46module_param_named(debug,pvrusb2_debug,int,S_IRUGO|S_IWUSR);
47MODULE_PARM_DESC(debug, "Debug trace mask");
48
49#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
50static struct pvr2_sysfs_class *class_ptr = NULL;
51#endif
52
53static void pvr_setup_attach(struct pvr2_context *pvr)
54{
55
56 pvr2_v4l2_create(pvr);
57#ifdef CONFIG_VIDEO_PVRUSB2_DVB
58
59 pvr2_dvb_create(pvr);
60#endif
61#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
62 pvr2_sysfs_create(pvr,class_ptr);
63#endif
64}
65
66static int pvr_probe(struct usb_interface *intf,
67 const struct usb_device_id *devid)
68{
69 struct pvr2_context *pvr;
70
71
72 pvr = pvr2_context_create(intf,devid,pvr_setup_attach);
73 if (!pvr) {
74 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
75 "Failed to create hdw handler");
76 return -ENOMEM;
77 }
78
79 pvr2_trace(PVR2_TRACE_INIT,"pvr_probe(pvr=%p)",pvr);
80
81 usb_set_intfdata(intf, pvr);
82
83 return 0;
84}
85
86
87
88
89
90static void pvr_disconnect(struct usb_interface *intf)
91{
92 struct pvr2_context *pvr = usb_get_intfdata(intf);
93
94 pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) BEGIN",pvr);
95
96 usb_set_intfdata (intf, NULL);
97 pvr2_context_disconnect(pvr);
98
99 pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) DONE",pvr);
100
101}
102
103static struct usb_driver pvr_driver = {
104 .name = "pvrusb2",
105 .id_table = pvr2_device_table,
106 .probe = pvr_probe,
107 .disconnect = pvr_disconnect
108};
109
110
111
112
113
114
115
116static int __init pvr_init(void)
117{
118 int ret;
119
120 pvr2_trace(PVR2_TRACE_INIT,"pvr_init");
121
122 ret = pvr2_context_global_init();
123 if (ret != 0) {
124 pvr2_trace(PVR2_TRACE_INIT,"pvr_init failure code=%d",ret);
125 return ret;
126 }
127
128#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
129 class_ptr = pvr2_sysfs_class_create();
130#endif
131
132 ret = usb_register(&pvr_driver);
133
134 if (ret == 0)
135 printk(KERN_INFO "pvrusb2: " DRIVER_VERSION ":"
136 DRIVER_DESC "\n");
137 if (pvrusb2_debug)
138 printk(KERN_INFO "pvrusb2: Debug mask is %d (0x%x)\n",
139 pvrusb2_debug,pvrusb2_debug);
140
141 pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete");
142
143 return ret;
144}
145
146static void __exit pvr_exit(void)
147{
148 pvr2_trace(PVR2_TRACE_INIT,"pvr_exit");
149
150 usb_deregister(&pvr_driver);
151
152 pvr2_context_global_done();
153
154#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
155 pvr2_sysfs_class_destroy(class_ptr);
156#endif
157
158 pvr2_trace(PVR2_TRACE_INIT,"pvr_exit complete");
159}
160
161module_init(pvr_init);
162module_exit(pvr_exit);
163
164MODULE_AUTHOR(DRIVER_AUTHOR);
165MODULE_DESCRIPTION(DRIVER_DESC);
166MODULE_LICENSE("GPL");
167MODULE_VERSION("0.9.1");
168