]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/media/usb/pvrusb2/pvrusb2-main.c
Merge branches 'for-4.11/upstream-fixes', 'for-4.12/accutouch', 'for-4.12/cp2112...
[mirror_ubuntu-artful-kernel.git] / drivers / media / usb / pvrusb2 / pvrusb2-main.c
CommitLineData
d855497e
MI
1/*
2 *
d855497e
MI
3 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
6 *
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
10 *
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.
15 *
d855497e
MI
16 */
17
d855497e
MI
18#include <linux/kernel.h>
19#include <linux/errno.h>
d855497e 20#include <linux/module.h>
d855497e
MI
21#include <linux/usb.h>
22#include <linux/videodev2.h>
23
24#include "pvrusb2-hdw.h"
989eb154 25#include "pvrusb2-devattr.h"
d855497e
MI
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 */
32
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"
36
37#define DEFAULT_DEBUG_MASK (PVR2_TRACE_ERROR_LEGS| \
38 PVR2_TRACE_INFO| \
56585386 39 PVR2_TRACE_STD| \
d855497e
MI
40 PVR2_TRACE_TOLERANCE| \
41 PVR2_TRACE_TRAP| \
d855497e
MI
42 0)
43
44int pvrusb2_debug = DEFAULT_DEBUG_MASK;
45
46module_param_named(debug,pvrusb2_debug,int,S_IRUGO|S_IWUSR);
47MODULE_PARM_DESC(debug, "Debug trace mask");
48
49#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
a0fd1cb1 50static struct pvr2_sysfs_class *class_ptr = NULL;
d855497e
MI
51#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
52
53static void pvr_setup_attach(struct pvr2_context *pvr)
54{
55 /* Create association with v4l layer */
56 pvr2_v4l2_create(pvr);
04910bdc
MK
57#ifdef CONFIG_VIDEO_PVRUSB2_DVB
58 /* Create association with dvb layer */
c5317b17 59 pvr2_dvb_create(pvr);
04910bdc 60#endif
d855497e
MI
61#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
62 pvr2_sysfs_create(pvr,class_ptr);
63#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
64}
65
66static int pvr_probe(struct usb_interface *intf,
67 const struct usb_device_id *devid)
68{
69 struct pvr2_context *pvr;
70
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;
77 }
78
79 pvr2_trace(PVR2_TRACE_INIT,"pvr_probe(pvr=%p)",pvr);
80
81 usb_set_intfdata(intf, pvr);
82
83 return 0;
84}
85
86/*
87 * pvr_disconnect()
88 *
89 */
90static void pvr_disconnect(struct usb_interface *intf)
91{
92 struct pvr2_context *pvr = usb_get_intfdata(intf);
93
94 pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) BEGIN",pvr);
95
96 usb_set_intfdata (intf, NULL);
97 pvr2_context_disconnect(pvr);
98
99 pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) DONE",pvr);
100
101}
102
103static struct usb_driver pvr_driver = {
a0fd1cb1
MI
104 .name = "pvrusb2",
105 .id_table = pvr2_device_table,
106 .probe = pvr_probe,
107 .disconnect = pvr_disconnect
d855497e
MI
108};
109
110/*
111 * pvr_init() / pvr_exit()
112 *
113 * This code is run to initialize/exit the driver.
114 *
115 */
116static int __init pvr_init(void)
117{
118 int ret;
119
120 pvr2_trace(PVR2_TRACE_INIT,"pvr_init");
121
e5be15c6
MI
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;
126 }
127
d855497e
MI
128#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
129 class_ptr = pvr2_sysfs_class_create();
130#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
131
132 ret = usb_register(&pvr_driver);
133
134 if (ret == 0)
94b5ff9c 135 printk(KERN_INFO "pvrusb2: " DRIVER_VERSION ":"
a482f327
GKH
136 DRIVER_DESC "\n");
137 if (pvrusb2_debug)
94b5ff9c 138 printk(KERN_INFO "pvrusb2: Debug mask is %d (0x%x)\n",
a482f327 139 pvrusb2_debug,pvrusb2_debug);
d855497e 140
e5be15c6
MI
141 pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete");
142
d855497e
MI
143 return ret;
144}
145
146static void __exit pvr_exit(void)
147{
d855497e
MI
148 pvr2_trace(PVR2_TRACE_INIT,"pvr_exit");
149
4f663bdc
MI
150 usb_deregister(&pvr_driver);
151
e3a5ee73
MI
152 pvr2_context_global_done();
153
d855497e
MI
154#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
155 pvr2_sysfs_class_destroy(class_ptr);
156#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
e5be15c6 157
e5be15c6 158 pvr2_trace(PVR2_TRACE_INIT,"pvr_exit complete");
d855497e
MI
159}
160
161module_init(pvr_init);
162module_exit(pvr_exit);
163
d855497e
MI
164MODULE_AUTHOR(DRIVER_AUTHOR);
165MODULE_DESCRIPTION(DRIVER_DESC);
166MODULE_LICENSE("GPL");
083774d8 167MODULE_VERSION("0.9.1");