Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1 | /* |
| 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 Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 23 | #include <linux/kernel.h> |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/module.h> |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 27 | #include <linux/usb.h> |
| 28 | #include <linux/videodev2.h> |
| 29 | |
| 30 | #include "pvrusb2-hdw.h" |
Mike Isely | 989eb15 | 2007-11-26 01:53:12 -0300 | [diff] [blame] | 31 | #include "pvrusb2-devattr.h" |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 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| \ |
Mike Isely | 5658538 | 2007-09-08 22:32:12 -0300 | [diff] [blame] | 45 | PVR2_TRACE_STD| \ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 46 | PVR2_TRACE_TOLERANCE| \ |
| 47 | PVR2_TRACE_TRAP| \ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 48 | 0) |
| 49 | |
| 50 | int pvrusb2_debug = DEFAULT_DEBUG_MASK; |
| 51 | |
| 52 | module_param_named(debug,pvrusb2_debug,int,S_IRUGO|S_IWUSR); |
| 53 | MODULE_PARM_DESC(debug, "Debug trace mask"); |
| 54 | |
| 55 | #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 56 | static struct pvr2_sysfs_class *class_ptr = NULL; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 57 | #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ |
| 58 | |
| 59 | static void pvr_setup_attach(struct pvr2_context *pvr) |
| 60 | { |
| 61 | /* Create association with v4l layer */ |
| 62 | pvr2_v4l2_create(pvr); |
Michael Krufky | 04910bd | 2008-02-03 23:46:16 -0300 | [diff] [blame^] | 63 | #ifdef CONFIG_VIDEO_PVRUSB2_DVB |
| 64 | /* Create association with dvb layer */ |
| 65 | pvr2_dvb_init(pvr); |
| 66 | #endif |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 67 | #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS |
| 68 | pvr2_sysfs_create(pvr,class_ptr); |
| 69 | #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ |
| 70 | } |
| 71 | |
| 72 | static int pvr_probe(struct usb_interface *intf, |
| 73 | const struct usb_device_id *devid) |
| 74 | { |
| 75 | struct pvr2_context *pvr; |
| 76 | |
| 77 | /* Create underlying hardware interface */ |
| 78 | pvr = pvr2_context_create(intf,devid,pvr_setup_attach); |
| 79 | if (!pvr) { |
| 80 | pvr2_trace(PVR2_TRACE_ERROR_LEGS, |
| 81 | "Failed to create hdw handler"); |
| 82 | return -ENOMEM; |
| 83 | } |
| 84 | |
| 85 | pvr2_trace(PVR2_TRACE_INIT,"pvr_probe(pvr=%p)",pvr); |
| 86 | |
| 87 | usb_set_intfdata(intf, pvr); |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | /* |
| 93 | * pvr_disconnect() |
| 94 | * |
| 95 | */ |
| 96 | static void pvr_disconnect(struct usb_interface *intf) |
| 97 | { |
| 98 | struct pvr2_context *pvr = usb_get_intfdata(intf); |
| 99 | |
| 100 | pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) BEGIN",pvr); |
| 101 | |
Michael Krufky | 04910bd | 2008-02-03 23:46:16 -0300 | [diff] [blame^] | 102 | #ifdef CONFIG_VIDEO_PVRUSB2_DVB |
| 103 | pvr2_dvb_exit(pvr); |
| 104 | #endif |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 105 | usb_set_intfdata (intf, NULL); |
| 106 | pvr2_context_disconnect(pvr); |
| 107 | |
| 108 | pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) DONE",pvr); |
| 109 | |
| 110 | } |
| 111 | |
| 112 | static struct usb_driver pvr_driver = { |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 113 | .name = "pvrusb2", |
| 114 | .id_table = pvr2_device_table, |
| 115 | .probe = pvr_probe, |
| 116 | .disconnect = pvr_disconnect |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | /* |
| 120 | * pvr_init() / pvr_exit() |
| 121 | * |
| 122 | * This code is run to initialize/exit the driver. |
| 123 | * |
| 124 | */ |
| 125 | static int __init pvr_init(void) |
| 126 | { |
| 127 | int ret; |
| 128 | |
| 129 | pvr2_trace(PVR2_TRACE_INIT,"pvr_init"); |
| 130 | |
| 131 | #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS |
| 132 | class_ptr = pvr2_sysfs_class_create(); |
| 133 | #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ |
| 134 | |
| 135 | ret = usb_register(&pvr_driver); |
| 136 | |
| 137 | if (ret == 0) |
| 138 | info(DRIVER_DESC " : " DRIVER_VERSION); |
| 139 | if (pvrusb2_debug) info("Debug mask is %d (0x%x)", |
| 140 | pvrusb2_debug,pvrusb2_debug); |
| 141 | |
| 142 | return ret; |
| 143 | } |
| 144 | |
| 145 | static void __exit pvr_exit(void) |
| 146 | { |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 147 | pvr2_trace(PVR2_TRACE_INIT,"pvr_exit"); |
| 148 | |
Mike Isely | 4f663bd | 2007-11-03 00:06:42 -0300 | [diff] [blame] | 149 | usb_deregister(&pvr_driver); |
| 150 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 151 | #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS |
| 152 | pvr2_sysfs_class_destroy(class_ptr); |
| 153 | #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | module_init(pvr_init); |
| 157 | module_exit(pvr_exit); |
| 158 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 159 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 160 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 161 | MODULE_LICENSE("GPL"); |
| 162 | |
| 163 | |
| 164 | /* |
| 165 | Stuff for Emacs to see, in order to encourage consistent editing style: |
| 166 | *** Local Variables: *** |
| 167 | *** mode: c *** |
| 168 | *** fill-column: 70 *** |
| 169 | *** tab-width: 8 *** |
| 170 | *** c-basic-offset: 8 *** |
| 171 | *** End: *** |
| 172 | */ |