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