Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / media / usb / pvrusb2 / pvrusb2-main.c
blob721dafd2c14b575f04e86d9c866e2a550488411e
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
6 */
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 #include "pvrusb2-sysfs.h"
21 #define DRIVER_AUTHOR "Mike Isely <isely@pobox.com>"
22 #define DRIVER_DESC "Hauppauge WinTV-PVR-USB2 MPEG2 Encoder/Tuner"
23 #define DRIVER_VERSION "V4L in-tree version"
25 #define DEFAULT_DEBUG_MASK (PVR2_TRACE_ERROR_LEGS| \
26 PVR2_TRACE_INFO| \
27 PVR2_TRACE_STD| \
28 PVR2_TRACE_TOLERANCE| \
29 PVR2_TRACE_TRAP| \
32 int pvrusb2_debug = DEFAULT_DEBUG_MASK;
34 module_param_named(debug,pvrusb2_debug,int,S_IRUGO|S_IWUSR);
35 MODULE_PARM_DESC(debug, "Debug trace mask");
37 static void pvr_setup_attach(struct pvr2_context *pvr)
39 /* Create association with v4l layer */
40 pvr2_v4l2_create(pvr);
41 #ifdef CONFIG_VIDEO_PVRUSB2_DVB
42 /* Create association with dvb layer */
43 pvr2_dvb_create(pvr);
44 #endif
45 pvr2_sysfs_create(pvr);
48 static int pvr_probe(struct usb_interface *intf,
49 const struct usb_device_id *devid)
51 struct pvr2_context *pvr;
53 /* Create underlying hardware interface */
54 pvr = pvr2_context_create(intf,devid,pvr_setup_attach);
55 if (!pvr) {
56 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
57 "Failed to create hdw handler");
58 return -ENOMEM;
61 pvr2_trace(PVR2_TRACE_INIT,"pvr_probe(pvr=%p)",pvr);
63 usb_set_intfdata(intf, pvr);
65 return 0;
69 * pvr_disconnect()
72 static void pvr_disconnect(struct usb_interface *intf)
74 struct pvr2_context *pvr = usb_get_intfdata(intf);
76 pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) BEGIN",pvr);
78 usb_set_intfdata (intf, NULL);
79 pvr2_context_disconnect(pvr);
81 pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) DONE",pvr);
85 static struct usb_driver pvr_driver = {
86 .name = "pvrusb2",
87 .id_table = pvr2_device_table,
88 .probe = pvr_probe,
89 .disconnect = pvr_disconnect
93 * pvr_init() / pvr_exit()
95 * This code is run to initialize/exit the driver.
98 static int __init pvr_init(void)
100 int ret;
102 pvr2_trace(PVR2_TRACE_INIT,"pvr_init");
104 ret = pvr2_context_global_init();
105 if (ret != 0) {
106 pvr2_trace(PVR2_TRACE_INIT,"pvr_init failure code=%d",ret);
107 return ret;
110 pvr2_sysfs_class_create();
112 ret = usb_register(&pvr_driver);
114 if (ret == 0)
115 pr_info("pvrusb2: " DRIVER_VERSION ":"
116 DRIVER_DESC "\n");
117 if (pvrusb2_debug)
118 pr_info("pvrusb2: Debug mask is %d (0x%x)\n",
119 pvrusb2_debug,pvrusb2_debug);
121 pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete");
123 return ret;
126 static void __exit pvr_exit(void)
128 pvr2_trace(PVR2_TRACE_INIT,"pvr_exit");
130 usb_deregister(&pvr_driver);
132 pvr2_context_global_done();
134 pvr2_sysfs_class_destroy();
136 pvr2_trace(PVR2_TRACE_INIT,"pvr_exit complete");
139 module_init(pvr_init);
140 module_exit(pvr_exit);
142 MODULE_AUTHOR(DRIVER_AUTHOR);
143 MODULE_DESCRIPTION(DRIVER_DESC);
144 MODULE_LICENSE("GPL");
145 MODULE_VERSION("0.9.1");