1 /* 2 * 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 * 16 */ 17 18 #include <linux/kernel.h> 19 #include <linux/errno.h> 20 #include <linux/module.h> 21 #include <linux/usb.h> 22 #include <linux/videodev2.h> 23 24 #include "pvrusb2-hdw.h" 25 #include "pvrusb2-devattr.h" 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| \ 39 PVR2_TRACE_STD| \ 40 PVR2_TRACE_TOLERANCE| \ 41 PVR2_TRACE_TRAP| \ 42 0) 43 44 int pvrusb2_debug = DEFAULT_DEBUG_MASK; 45 46 module_param_named(debug,pvrusb2_debug,int,S_IRUGO|S_IWUSR); 47 MODULE_PARM_DESC(debug, "Debug trace mask"); 48 49 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS 50 static struct pvr2_sysfs_class *class_ptr = NULL; 51 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ 52 53 static void pvr_setup_attach(struct pvr2_context *pvr) 54 { 55 /* Create association with v4l layer */ 56 pvr2_v4l2_create(pvr); 57 #ifdef CONFIG_VIDEO_PVRUSB2_DVB 58 /* Create association with dvb layer */ 59 pvr2_dvb_create(pvr); 60 #endif 61 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS 62 pvr2_sysfs_create(pvr,class_ptr); 63 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ 64 } 65 66 static 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 */ 90 static 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 103 static struct usb_driver pvr_driver = { 104 .name = "pvrusb2", 105 .id_table = pvr2_device_table, 106 .probe = pvr_probe, 107 .disconnect = pvr_disconnect 108 }; 109 110 /* 111 * pvr_init() / pvr_exit() 112 * 113 * This code is run to initialize/exit the driver. 114 * 115 */ 116 static int __init pvr_init(void) 117 { 118 int ret; 119 120 pvr2_trace(PVR2_TRACE_INIT,"pvr_init"); 121 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 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) 135 printk(KERN_INFO "pvrusb2: " DRIVER_VERSION ":" 136 DRIVER_DESC "\n"); 137 if (pvrusb2_debug) 138 printk(KERN_INFO "pvrusb2: Debug mask is %d (0x%x)\n", 139 pvrusb2_debug,pvrusb2_debug); 140 141 pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete"); 142 143 return ret; 144 } 145 146 static void __exit pvr_exit(void) 147 { 148 pvr2_trace(PVR2_TRACE_INIT,"pvr_exit"); 149 150 usb_deregister(&pvr_driver); 151 152 pvr2_context_global_done(); 153 154 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS 155 pvr2_sysfs_class_destroy(class_ptr); 156 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ 157 158 pvr2_trace(PVR2_TRACE_INIT,"pvr_exit complete"); 159 } 160 161 module_init(pvr_init); 162 module_exit(pvr_exit); 163 164 MODULE_AUTHOR(DRIVER_AUTHOR); 165 MODULE_DESCRIPTION(DRIVER_DESC); 166 MODULE_LICENSE("GPL"); 167 MODULE_VERSION("0.9.1"); 168