1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
8 #include <linux/kernel.h>
9 #include <linux/errno.h>
10 #include <linux/module.h>
11 #include <linux/usb.h>
12 #include <linux/videodev2.h>
14 #include "pvrusb2-hdw.h"
15 #include "pvrusb2-devattr.h"
16 #include "pvrusb2-context.h"
17 #include "pvrusb2-debug.h"
18 #include "pvrusb2-v4l2.h"
19 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
20 #include "pvrusb2-sysfs.h"
21 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
23 #define DRIVER_AUTHOR "Mike Isely <isely@pobox.com>"
24 #define DRIVER_DESC "Hauppauge WinTV-PVR-USB2 MPEG2 Encoder/Tuner"
25 #define DRIVER_VERSION "V4L in-tree version"
27 #define DEFAULT_DEBUG_MASK (PVR2_TRACE_ERROR_LEGS| \
30 PVR2_TRACE_TOLERANCE| \
34 int pvrusb2_debug
= DEFAULT_DEBUG_MASK
;
36 module_param_named(debug
,pvrusb2_debug
,int,S_IRUGO
|S_IWUSR
);
37 MODULE_PARM_DESC(debug
, "Debug trace mask");
39 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
40 static struct pvr2_sysfs_class
*class_ptr
= NULL
;
41 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
43 static void pvr_setup_attach(struct pvr2_context
*pvr
)
45 /* Create association with v4l layer */
46 pvr2_v4l2_create(pvr
);
47 #ifdef CONFIG_VIDEO_PVRUSB2_DVB
48 /* Create association with dvb layer */
51 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
52 pvr2_sysfs_create(pvr
,class_ptr
);
53 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
56 static int pvr_probe(struct usb_interface
*intf
,
57 const struct usb_device_id
*devid
)
59 struct pvr2_context
*pvr
;
61 /* Create underlying hardware interface */
62 pvr
= pvr2_context_create(intf
,devid
,pvr_setup_attach
);
64 pvr2_trace(PVR2_TRACE_ERROR_LEGS
,
65 "Failed to create hdw handler");
69 pvr2_trace(PVR2_TRACE_INIT
,"pvr_probe(pvr=%p)",pvr
);
71 usb_set_intfdata(intf
, pvr
);
80 static void pvr_disconnect(struct usb_interface
*intf
)
82 struct pvr2_context
*pvr
= usb_get_intfdata(intf
);
84 pvr2_trace(PVR2_TRACE_INIT
,"pvr_disconnect(pvr=%p) BEGIN",pvr
);
86 usb_set_intfdata (intf
, NULL
);
87 pvr2_context_disconnect(pvr
);
89 pvr2_trace(PVR2_TRACE_INIT
,"pvr_disconnect(pvr=%p) DONE",pvr
);
93 static struct usb_driver pvr_driver
= {
95 .id_table
= pvr2_device_table
,
97 .disconnect
= pvr_disconnect
101 * pvr_init() / pvr_exit()
103 * This code is run to initialize/exit the driver.
106 static int __init
pvr_init(void)
110 pvr2_trace(PVR2_TRACE_INIT
,"pvr_init");
112 ret
= pvr2_context_global_init();
114 pvr2_trace(PVR2_TRACE_INIT
,"pvr_init failure code=%d",ret
);
118 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
119 class_ptr
= pvr2_sysfs_class_create();
120 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
122 ret
= usb_register(&pvr_driver
);
125 pr_info("pvrusb2: " DRIVER_VERSION
":"
128 pr_info("pvrusb2: Debug mask is %d (0x%x)\n",
129 pvrusb2_debug
,pvrusb2_debug
);
131 pvr2_trace(PVR2_TRACE_INIT
,"pvr_init complete");
136 static void __exit
pvr_exit(void)
138 pvr2_trace(PVR2_TRACE_INIT
,"pvr_exit");
140 usb_deregister(&pvr_driver
);
142 pvr2_context_global_done();
144 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
145 pvr2_sysfs_class_destroy(class_ptr
);
146 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
148 pvr2_trace(PVR2_TRACE_INIT
,"pvr_exit complete");
151 module_init(pvr_init
);
152 module_exit(pvr_exit
);
154 MODULE_AUTHOR(DRIVER_AUTHOR
);
155 MODULE_DESCRIPTION(DRIVER_DESC
);
156 MODULE_LICENSE("GPL");
157 MODULE_VERSION("0.9.1");