Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1 | /* |
| 2 | * |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 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 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * |
| 20 | */ |
| 21 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 22 | #include <linux/kernel.h> |
| 23 | #include <linux/errno.h> |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 24 | #include <linux/module.h> |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 25 | #include <linux/usb.h> |
| 26 | #include <linux/videodev2.h> |
| 27 | |
| 28 | #include "pvrusb2-hdw.h" |
Mike Isely | 989eb15 | 2007-11-26 01:53:12 -0300 | [diff] [blame] | 29 | #include "pvrusb2-devattr.h" |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 30 | #include "pvrusb2-context.h" |
| 31 | #include "pvrusb2-debug.h" |
| 32 | #include "pvrusb2-v4l2.h" |
| 33 | #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS |
| 34 | #include "pvrusb2-sysfs.h" |
| 35 | #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ |
| 36 | |
| 37 | #define DRIVER_AUTHOR "Mike Isely <isely@pobox.com>" |
| 38 | #define DRIVER_DESC "Hauppauge WinTV-PVR-USB2 MPEG2 Encoder/Tuner" |
| 39 | #define DRIVER_VERSION "V4L in-tree version" |
| 40 | |
| 41 | #define DEFAULT_DEBUG_MASK (PVR2_TRACE_ERROR_LEGS| \ |
| 42 | PVR2_TRACE_INFO| \ |
Mike Isely | 5658538 | 2007-09-08 22:32:12 -0300 | [diff] [blame] | 43 | PVR2_TRACE_STD| \ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 44 | PVR2_TRACE_TOLERANCE| \ |
| 45 | PVR2_TRACE_TRAP| \ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 46 | 0) |
| 47 | |
| 48 | int pvrusb2_debug = DEFAULT_DEBUG_MASK; |
| 49 | |
| 50 | module_param_named(debug,pvrusb2_debug,int,S_IRUGO|S_IWUSR); |
| 51 | MODULE_PARM_DESC(debug, "Debug trace mask"); |
| 52 | |
| 53 | #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 54 | static struct pvr2_sysfs_class *class_ptr = NULL; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 55 | #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ |
| 56 | |
| 57 | static void pvr_setup_attach(struct pvr2_context *pvr) |
| 58 | { |
| 59 | /* Create association with v4l layer */ |
| 60 | pvr2_v4l2_create(pvr); |
Michael Krufky | 04910bd | 2008-02-03 23:46:16 -0300 | [diff] [blame] | 61 | #ifdef CONFIG_VIDEO_PVRUSB2_DVB |
| 62 | /* Create association with dvb layer */ |
Mike Isely | c5317b1 | 2008-02-09 19:47:07 -0300 | [diff] [blame] | 63 | pvr2_dvb_create(pvr); |
Michael Krufky | 04910bd | 2008-02-03 23:46:16 -0300 | [diff] [blame] | 64 | #endif |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 65 | #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS |
| 66 | pvr2_sysfs_create(pvr,class_ptr); |
| 67 | #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ |
| 68 | } |
| 69 | |
| 70 | static int pvr_probe(struct usb_interface *intf, |
| 71 | const struct usb_device_id *devid) |
| 72 | { |
| 73 | struct pvr2_context *pvr; |
| 74 | |
| 75 | /* Create underlying hardware interface */ |
| 76 | pvr = pvr2_context_create(intf,devid,pvr_setup_attach); |
| 77 | if (!pvr) { |
| 78 | pvr2_trace(PVR2_TRACE_ERROR_LEGS, |
| 79 | "Failed to create hdw handler"); |
| 80 | return -ENOMEM; |
| 81 | } |
| 82 | |
| 83 | pvr2_trace(PVR2_TRACE_INIT,"pvr_probe(pvr=%p)",pvr); |
| 84 | |
| 85 | usb_set_intfdata(intf, pvr); |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | /* |
| 91 | * pvr_disconnect() |
| 92 | * |
| 93 | */ |
| 94 | static void pvr_disconnect(struct usb_interface *intf) |
| 95 | { |
| 96 | struct pvr2_context *pvr = usb_get_intfdata(intf); |
| 97 | |
| 98 | pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) BEGIN",pvr); |
| 99 | |
| 100 | usb_set_intfdata (intf, NULL); |
| 101 | pvr2_context_disconnect(pvr); |
| 102 | |
| 103 | pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) DONE",pvr); |
| 104 | |
| 105 | } |
| 106 | |
| 107 | static struct usb_driver pvr_driver = { |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 108 | .name = "pvrusb2", |
| 109 | .id_table = pvr2_device_table, |
| 110 | .probe = pvr_probe, |
| 111 | .disconnect = pvr_disconnect |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | /* |
| 115 | * pvr_init() / pvr_exit() |
| 116 | * |
| 117 | * This code is run to initialize/exit the driver. |
| 118 | * |
| 119 | */ |
| 120 | static int __init pvr_init(void) |
| 121 | { |
| 122 | int ret; |
| 123 | |
| 124 | pvr2_trace(PVR2_TRACE_INIT,"pvr_init"); |
| 125 | |
Mike Isely | e5be15c | 2008-04-07 02:22:04 -0300 | [diff] [blame] | 126 | ret = pvr2_context_global_init(); |
| 127 | if (ret != 0) { |
| 128 | pvr2_trace(PVR2_TRACE_INIT,"pvr_init failure code=%d",ret); |
| 129 | return ret; |
| 130 | } |
| 131 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 132 | #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS |
| 133 | class_ptr = pvr2_sysfs_class_create(); |
| 134 | #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ |
| 135 | |
| 136 | ret = usb_register(&pvr_driver); |
| 137 | |
| 138 | if (ret == 0) |
Mike Isely | 94b5ff9 | 2009-01-16 03:09:34 -0300 | [diff] [blame] | 139 | printk(KERN_INFO "pvrusb2: " DRIVER_VERSION ":" |
Greg Kroah-Hartman | a482f32 | 2008-10-10 05:08:23 -0300 | [diff] [blame] | 140 | DRIVER_DESC "\n"); |
| 141 | if (pvrusb2_debug) |
Mike Isely | 94b5ff9 | 2009-01-16 03:09:34 -0300 | [diff] [blame] | 142 | printk(KERN_INFO "pvrusb2: Debug mask is %d (0x%x)\n", |
Greg Kroah-Hartman | a482f32 | 2008-10-10 05:08:23 -0300 | [diff] [blame] | 143 | pvrusb2_debug,pvrusb2_debug); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 144 | |
Mike Isely | e5be15c | 2008-04-07 02:22:04 -0300 | [diff] [blame] | 145 | pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete"); |
| 146 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 147 | return ret; |
| 148 | } |
| 149 | |
| 150 | static void __exit pvr_exit(void) |
| 151 | { |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 152 | pvr2_trace(PVR2_TRACE_INIT,"pvr_exit"); |
| 153 | |
Mike Isely | 4f663bd | 2007-11-03 00:06:42 -0300 | [diff] [blame] | 154 | usb_deregister(&pvr_driver); |
| 155 | |
Mike Isely | e3a5ee7 | 2010-05-15 00:30:29 -0300 | [diff] [blame] | 156 | pvr2_context_global_done(); |
| 157 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 158 | #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS |
| 159 | pvr2_sysfs_class_destroy(class_ptr); |
| 160 | #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ |
Mike Isely | e5be15c | 2008-04-07 02:22:04 -0300 | [diff] [blame] | 161 | |
Mike Isely | e5be15c | 2008-04-07 02:22:04 -0300 | [diff] [blame] | 162 | pvr2_trace(PVR2_TRACE_INIT,"pvr_exit complete"); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | module_init(pvr_init); |
| 166 | module_exit(pvr_exit); |
| 167 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 168 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 169 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 170 | MODULE_LICENSE("GPL"); |
| 171 | |
| 172 | |
| 173 | /* |
| 174 | Stuff for Emacs to see, in order to encourage consistent editing style: |
| 175 | *** Local Variables: *** |
| 176 | *** mode: c *** |
| 177 | *** fill-column: 70 *** |
| 178 | *** tab-width: 8 *** |
| 179 | *** c-basic-offset: 8 *** |
| 180 | *** End: *** |
| 181 | */ |