blob: a8370737b503db97ef7b6ae753dcf93cbe778883 [file] [log] [blame]
Mike Iselyd8554972006-06-26 20:58:46 -03001/*
2 *
3 * $Id$
4 *
5 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
6 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
Mike Iselyd8554972006-06-26 20:58:46 -030023#include <linux/kernel.h>
24#include <linux/errno.h>
25#include <linux/slab.h>
26#include <linux/module.h>
Mike Iselyd8554972006-06-26 20:58:46 -030027#include <linux/usb.h>
28#include <linux/videodev2.h>
29
30#include "pvrusb2-hdw.h"
Mike Isely989eb152007-11-26 01:53:12 -030031#include "pvrusb2-devattr.h"
Mike Iselyd8554972006-06-26 20:58:46 -030032#include "pvrusb2-context.h"
33#include "pvrusb2-debug.h"
34#include "pvrusb2-v4l2.h"
35#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
36#include "pvrusb2-sysfs.h"
37#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
38
39#define DRIVER_AUTHOR "Mike Isely <isely@pobox.com>"
40#define DRIVER_DESC "Hauppauge WinTV-PVR-USB2 MPEG2 Encoder/Tuner"
41#define DRIVER_VERSION "V4L in-tree version"
42
43#define DEFAULT_DEBUG_MASK (PVR2_TRACE_ERROR_LEGS| \
44 PVR2_TRACE_INFO| \
Mike Isely56585382007-09-08 22:32:12 -030045 PVR2_TRACE_STD| \
Mike Iselyd8554972006-06-26 20:58:46 -030046 PVR2_TRACE_TOLERANCE| \
47 PVR2_TRACE_TRAP| \
Mike Iselyd8554972006-06-26 20:58:46 -030048 0)
49
50int pvrusb2_debug = DEFAULT_DEBUG_MASK;
51
52module_param_named(debug,pvrusb2_debug,int,S_IRUGO|S_IWUSR);
53MODULE_PARM_DESC(debug, "Debug trace mask");
54
55#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
Mike Iselya0fd1cb2006-06-30 11:35:28 -030056static struct pvr2_sysfs_class *class_ptr = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -030057#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
58
59static void pvr_setup_attach(struct pvr2_context *pvr)
60{
61 /* Create association with v4l layer */
62 pvr2_v4l2_create(pvr);
63#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
64 pvr2_sysfs_create(pvr,class_ptr);
65#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
66}
67
68static int pvr_probe(struct usb_interface *intf,
69 const struct usb_device_id *devid)
70{
71 struct pvr2_context *pvr;
72
73 /* Create underlying hardware interface */
74 pvr = pvr2_context_create(intf,devid,pvr_setup_attach);
75 if (!pvr) {
76 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
77 "Failed to create hdw handler");
78 return -ENOMEM;
79 }
80
81 pvr2_trace(PVR2_TRACE_INIT,"pvr_probe(pvr=%p)",pvr);
82
83 usb_set_intfdata(intf, pvr);
84
85 return 0;
86}
87
88/*
89 * pvr_disconnect()
90 *
91 */
92static void pvr_disconnect(struct usb_interface *intf)
93{
94 struct pvr2_context *pvr = usb_get_intfdata(intf);
95
96 pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) BEGIN",pvr);
97
98 usb_set_intfdata (intf, NULL);
99 pvr2_context_disconnect(pvr);
100
101 pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) DONE",pvr);
102
103}
104
105static struct usb_driver pvr_driver = {
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300106 .name = "pvrusb2",
107 .id_table = pvr2_device_table,
108 .probe = pvr_probe,
109 .disconnect = pvr_disconnect
Mike Iselyd8554972006-06-26 20:58:46 -0300110};
111
112/*
113 * pvr_init() / pvr_exit()
114 *
115 * This code is run to initialize/exit the driver.
116 *
117 */
118static int __init pvr_init(void)
119{
120 int ret;
121
122 pvr2_trace(PVR2_TRACE_INIT,"pvr_init");
123
124#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
125 class_ptr = pvr2_sysfs_class_create();
126#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
127
128 ret = usb_register(&pvr_driver);
129
130 if (ret == 0)
131 info(DRIVER_DESC " : " DRIVER_VERSION);
132 if (pvrusb2_debug) info("Debug mask is %d (0x%x)",
133 pvrusb2_debug,pvrusb2_debug);
134
135 return ret;
136}
137
138static void __exit pvr_exit(void)
139{
Mike Iselyd8554972006-06-26 20:58:46 -0300140 pvr2_trace(PVR2_TRACE_INIT,"pvr_exit");
141
Mike Isely4f663bd2007-11-03 00:06:42 -0300142 usb_deregister(&pvr_driver);
143
Mike Iselyd8554972006-06-26 20:58:46 -0300144#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
145 pvr2_sysfs_class_destroy(class_ptr);
146#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
Mike Iselyd8554972006-06-26 20:58:46 -0300147}
148
149module_init(pvr_init);
150module_exit(pvr_exit);
151
152/* Mike Isely <mcisely@pobox.com> 11-Mar-2006: See pvrusb2-hdw.c for
153 MODULE_DEVICE_TABLE(). We have to declare that attribute there
154 because that's where the device table actually is now and it seems
155 that certain gcc configurations get angry if MODULE_DEVICE_TABLE()
156 is used on what ends up being an external symbol. */
157MODULE_AUTHOR(DRIVER_AUTHOR);
158MODULE_DESCRIPTION(DRIVER_DESC);
159MODULE_LICENSE("GPL");
160
161
162/*
163 Stuff for Emacs to see, in order to encourage consistent editing style:
164 *** Local Variables: ***
165 *** mode: c ***
166 *** fill-column: 70 ***
167 *** tab-width: 8 ***
168 *** c-basic-offset: 8 ***
169 *** End: ***
170 */