1/* 2 * 3 * $Id: pvrusb2-main.c,v 1.1.1.1 2007/08/03 18:52:41 Exp $ 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 23#include <linux/kernel.h> 24#include <linux/errno.h> 25#include <linux/slab.h> 26#include <linux/module.h> 27#include <linux/moduleparam.h> 28#include <linux/usb.h> 29#include <linux/videodev2.h> 30 31#include "pvrusb2-hdw.h" 32#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| \ 45 PVR2_TRACE_TOLERANCE| \ 46 PVR2_TRACE_TRAP| \ 47 0) 48 49int pvrusb2_debug = DEFAULT_DEBUG_MASK; 50 51module_param_named(debug,pvrusb2_debug,int,S_IRUGO|S_IWUSR); 52MODULE_PARM_DESC(debug, "Debug trace mask"); 53 54#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS 55static struct pvr2_sysfs_class *class_ptr = NULL; 56#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ 57 58static void pvr_setup_attach(struct pvr2_context *pvr) 59{ 60 /* Create association with v4l layer */ 61 pvr2_v4l2_create(pvr); 62#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS 63 pvr2_sysfs_create(pvr,class_ptr); 64#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ 65} 66 67static int pvr_probe(struct usb_interface *intf, 68 const struct usb_device_id *devid) 69{ 70 struct pvr2_context *pvr; 71 72 /* Create underlying hardware interface */ 73 pvr = pvr2_context_create(intf,devid,pvr_setup_attach); 74 if (!pvr) { 75 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 76 "Failed to create hdw handler"); 77 return -ENOMEM; 78 } 79 80 pvr2_trace(PVR2_TRACE_INIT,"pvr_probe(pvr=%p)",pvr); 81 82 usb_set_intfdata(intf, pvr); 83 84 return 0; 85} 86 87/* 88 * pvr_disconnect() 89 * 90 */ 91static void pvr_disconnect(struct usb_interface *intf) 92{ 93 struct pvr2_context *pvr = usb_get_intfdata(intf); 94 95 pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) BEGIN",pvr); 96 97 usb_set_intfdata (intf, NULL); 98 pvr2_context_disconnect(pvr); 99 100 pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) DONE",pvr); 101 102} 103 104static struct usb_driver pvr_driver = { 105 .name = "pvrusb2", 106 .id_table = pvr2_device_table, 107 .probe = pvr_probe, 108 .disconnect = pvr_disconnect 109}; 110 111/* 112 * pvr_init() / pvr_exit() 113 * 114 * This code is run to initialize/exit the driver. 115 * 116 */ 117static int __init pvr_init(void) 118{ 119 int ret; 120 121 pvr2_trace(PVR2_TRACE_INIT,"pvr_init"); 122 123#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS 124 class_ptr = pvr2_sysfs_class_create(); 125#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ 126 127 ret = usb_register(&pvr_driver); 128 129 if (ret == 0) 130 info(DRIVER_DESC " : " DRIVER_VERSION); 131 if (pvrusb2_debug) info("Debug mask is %d (0x%x)", 132 pvrusb2_debug,pvrusb2_debug); 133 134 return ret; 135} 136 137static void __exit pvr_exit(void) 138{ 139 140 pvr2_trace(PVR2_TRACE_INIT,"pvr_exit"); 141 142#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS 143 pvr2_sysfs_class_destroy(class_ptr); 144#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ 145 146 usb_deregister(&pvr_driver); 147} 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 */ 171