Linux 4.19.133
[linux/fpc-iii.git] / drivers / media / usb / pvrusb2 / pvrusb2-main.c
blobcbe2c3a2245839005aa05f3bd56eedcc9a853270
1 /*
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
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
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
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>
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 /* CONFIG_VIDEO_PVRUSB2_SYSFS */
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"
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| \
44 int pvrusb2_debug = DEFAULT_DEBUG_MASK;
46 module_param_named(debug,pvrusb2_debug,int,S_IRUGO|S_IWUSR);
47 MODULE_PARM_DESC(debug, "Debug trace mask");
49 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
50 static struct pvr2_sysfs_class *class_ptr = NULL;
51 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
53 static void pvr_setup_attach(struct pvr2_context *pvr)
55 /* Create association with v4l layer */
56 pvr2_v4l2_create(pvr);
57 #ifdef CONFIG_VIDEO_PVRUSB2_DVB
58 /* Create association with dvb layer */
59 pvr2_dvb_create(pvr);
60 #endif
61 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
62 pvr2_sysfs_create(pvr,class_ptr);
63 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
66 static int pvr_probe(struct usb_interface *intf,
67 const struct usb_device_id *devid)
69 struct pvr2_context *pvr;
71 /* Create underlying hardware interface */
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;
79 pvr2_trace(PVR2_TRACE_INIT,"pvr_probe(pvr=%p)",pvr);
81 usb_set_intfdata(intf, pvr);
83 return 0;
87 * pvr_disconnect()
90 static void pvr_disconnect(struct usb_interface *intf)
92 struct pvr2_context *pvr = usb_get_intfdata(intf);
94 pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) BEGIN",pvr);
96 usb_set_intfdata (intf, NULL);
97 pvr2_context_disconnect(pvr);
99 pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) DONE",pvr);
103 static struct usb_driver pvr_driver = {
104 .name = "pvrusb2",
105 .id_table = pvr2_device_table,
106 .probe = pvr_probe,
107 .disconnect = pvr_disconnect
111 * pvr_init() / pvr_exit()
113 * This code is run to initialize/exit the driver.
116 static int __init pvr_init(void)
118 int ret;
120 pvr2_trace(PVR2_TRACE_INIT,"pvr_init");
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;
128 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
129 class_ptr = pvr2_sysfs_class_create();
130 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
132 ret = usb_register(&pvr_driver);
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);
141 pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete");
143 return ret;
146 static void __exit pvr_exit(void)
148 pvr2_trace(PVR2_TRACE_INIT,"pvr_exit");
150 usb_deregister(&pvr_driver);
152 pvr2_context_global_done();
154 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
155 pvr2_sysfs_class_destroy(class_ptr);
156 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
158 pvr2_trace(PVR2_TRACE_INIT,"pvr_exit complete");
161 module_init(pvr_init);
162 module_exit(pvr_exit);
164 MODULE_AUTHOR(DRIVER_AUTHOR);
165 MODULE_DESCRIPTION(DRIVER_DESC);
166 MODULE_LICENSE("GPL");
167 MODULE_VERSION("0.9.1");