1 | // SPDX-License-Identifier: GPL-2.0-only |
2 | /* |
3 | * |
4 | * Copyright (C) 2005 Mike Isely <isely@pobox.com> |
5 | * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr> |
6 | */ |
7 | |
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> |
13 | |
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" |
20 | |
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" |
24 | |
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| \ |
30 | 0) |
31 | |
32 | int pvrusb2_debug = DEFAULT_DEBUG_MASK; |
33 | |
34 | module_param_named(debug,pvrusb2_debug,int,S_IRUGO|S_IWUSR); |
35 | MODULE_PARM_DESC(debug, "Debug trace mask" ); |
36 | |
37 | static void pvr_setup_attach(struct pvr2_context *pvr) |
38 | { |
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(mp: pvr); |
46 | } |
47 | |
48 | static int pvr_probe(struct usb_interface *intf, |
49 | const struct usb_device_id *devid) |
50 | { |
51 | struct pvr2_context *pvr; |
52 | |
53 | /* Create underlying hardware interface */ |
54 | pvr = pvr2_context_create(intf,devid,setup_func: pvr_setup_attach); |
55 | if (!pvr) { |
56 | pvr2_trace(PVR2_TRACE_ERROR_LEGS, |
57 | "Failed to create hdw handler" ); |
58 | return -ENOMEM; |
59 | } |
60 | |
61 | pvr2_trace(PVR2_TRACE_INIT,"pvr_probe(pvr=%p)" ,pvr); |
62 | |
63 | usb_set_intfdata(intf, data: pvr); |
64 | |
65 | return 0; |
66 | } |
67 | |
68 | /* |
69 | * pvr_disconnect() |
70 | * |
71 | */ |
72 | static void pvr_disconnect(struct usb_interface *intf) |
73 | { |
74 | struct pvr2_context *pvr = usb_get_intfdata(intf); |
75 | |
76 | pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) BEGIN" ,pvr); |
77 | |
78 | usb_set_intfdata (intf, NULL); |
79 | pvr2_context_disconnect(pvr); |
80 | |
81 | pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) DONE" ,pvr); |
82 | |
83 | } |
84 | |
85 | static struct usb_driver pvr_driver = { |
86 | .name = "pvrusb2" , |
87 | .id_table = pvr2_device_table, |
88 | .probe = pvr_probe, |
89 | .disconnect = pvr_disconnect |
90 | }; |
91 | |
92 | /* |
93 | * pvr_init() / pvr_exit() |
94 | * |
95 | * This code is run to initialize/exit the driver. |
96 | * |
97 | */ |
98 | static int __init pvr_init(void) |
99 | { |
100 | int ret; |
101 | |
102 | pvr2_trace(PVR2_TRACE_INIT,"pvr_init" ); |
103 | |
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; |
108 | } |
109 | |
110 | pvr2_sysfs_class_create(); |
111 | |
112 | ret = usb_register(&pvr_driver); |
113 | |
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); |
120 | |
121 | pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete" ); |
122 | |
123 | return ret; |
124 | } |
125 | |
126 | static void __exit pvr_exit(void) |
127 | { |
128 | pvr2_trace(PVR2_TRACE_INIT,"pvr_exit" ); |
129 | |
130 | usb_deregister(&pvr_driver); |
131 | |
132 | pvr2_context_global_done(); |
133 | |
134 | pvr2_sysfs_class_destroy(); |
135 | |
136 | pvr2_trace(PVR2_TRACE_INIT,"pvr_exit complete" ); |
137 | } |
138 | |
139 | module_init(pvr_init); |
140 | module_exit(pvr_exit); |
141 | |
142 | MODULE_AUTHOR(DRIVER_AUTHOR); |
143 | MODULE_DESCRIPTION(DRIVER_DESC); |
144 | MODULE_LICENSE("GPL" ); |
145 | MODULE_VERSION("0.9.1" ); |
146 | |