Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / media / usb / pvrusb2 / pvrusb2-main.c
blobce4d566e4e5a36ba69fe0661928bcc0dfb4215f0
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 #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| \
28 PVR2_TRACE_INFO| \
29 PVR2_TRACE_STD| \
30 PVR2_TRACE_TOLERANCE| \
31 PVR2_TRACE_TRAP| \
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 */
49 pvr2_dvb_create(pvr);
50 #endif
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);
63 if (!pvr) {
64 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
65 "Failed to create hdw handler");
66 return -ENOMEM;
69 pvr2_trace(PVR2_TRACE_INIT,"pvr_probe(pvr=%p)",pvr);
71 usb_set_intfdata(intf, pvr);
73 return 0;
77 * pvr_disconnect()
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 = {
94 .name = "pvrusb2",
95 .id_table = pvr2_device_table,
96 .probe = pvr_probe,
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)
108 int ret;
110 pvr2_trace(PVR2_TRACE_INIT,"pvr_init");
112 ret = pvr2_context_global_init();
113 if (ret != 0) {
114 pvr2_trace(PVR2_TRACE_INIT,"pvr_init failure code=%d",ret);
115 return 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);
124 if (ret == 0)
125 pr_info("pvrusb2: " DRIVER_VERSION ":"
126 DRIVER_DESC "\n");
127 if (pvrusb2_debug)
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");
133 return ret;
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");