Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *
0004  *  Copyright (C) 2005 Mike Isely <isely@pobox.com>
0005  *  Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
0006  */
0007 
0008 #include <linux/kernel.h>
0009 #include <linux/errno.h>
0010 #include <linux/module.h>
0011 #include <linux/usb.h>
0012 #include <linux/videodev2.h>
0013 
0014 #include "pvrusb2-hdw.h"
0015 #include "pvrusb2-devattr.h"
0016 #include "pvrusb2-context.h"
0017 #include "pvrusb2-debug.h"
0018 #include "pvrusb2-v4l2.h"
0019 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
0020 #include "pvrusb2-sysfs.h"
0021 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
0022 
0023 #define DRIVER_AUTHOR "Mike Isely <isely@pobox.com>"
0024 #define DRIVER_DESC "Hauppauge WinTV-PVR-USB2 MPEG2 Encoder/Tuner"
0025 #define DRIVER_VERSION "V4L in-tree version"
0026 
0027 #define DEFAULT_DEBUG_MASK (PVR2_TRACE_ERROR_LEGS| \
0028                 PVR2_TRACE_INFO| \
0029                 PVR2_TRACE_STD| \
0030                 PVR2_TRACE_TOLERANCE| \
0031                 PVR2_TRACE_TRAP| \
0032                 0)
0033 
0034 int pvrusb2_debug = DEFAULT_DEBUG_MASK;
0035 
0036 module_param_named(debug,pvrusb2_debug,int,S_IRUGO|S_IWUSR);
0037 MODULE_PARM_DESC(debug, "Debug trace mask");
0038 
0039 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
0040 static struct pvr2_sysfs_class *class_ptr = NULL;
0041 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
0042 
0043 static void pvr_setup_attach(struct pvr2_context *pvr)
0044 {
0045     /* Create association with v4l layer */
0046     pvr2_v4l2_create(pvr);
0047 #ifdef CONFIG_VIDEO_PVRUSB2_DVB
0048     /* Create association with dvb layer */
0049     pvr2_dvb_create(pvr);
0050 #endif
0051 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
0052     pvr2_sysfs_create(pvr,class_ptr);
0053 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
0054 }
0055 
0056 static int pvr_probe(struct usb_interface *intf,
0057              const struct usb_device_id *devid)
0058 {
0059     struct pvr2_context *pvr;
0060 
0061     /* Create underlying hardware interface */
0062     pvr = pvr2_context_create(intf,devid,pvr_setup_attach);
0063     if (!pvr) {
0064         pvr2_trace(PVR2_TRACE_ERROR_LEGS,
0065                "Failed to create hdw handler");
0066         return -ENOMEM;
0067     }
0068 
0069     pvr2_trace(PVR2_TRACE_INIT,"pvr_probe(pvr=%p)",pvr);
0070 
0071     usb_set_intfdata(intf, pvr);
0072 
0073     return 0;
0074 }
0075 
0076 /*
0077  * pvr_disconnect()
0078  *
0079  */
0080 static void pvr_disconnect(struct usb_interface *intf)
0081 {
0082     struct pvr2_context *pvr = usb_get_intfdata(intf);
0083 
0084     pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) BEGIN",pvr);
0085 
0086     usb_set_intfdata (intf, NULL);
0087     pvr2_context_disconnect(pvr);
0088 
0089     pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) DONE",pvr);
0090 
0091 }
0092 
0093 static struct usb_driver pvr_driver = {
0094     .name =         "pvrusb2",
0095     .id_table =     pvr2_device_table,
0096     .probe =        pvr_probe,
0097     .disconnect =   pvr_disconnect
0098 };
0099 
0100 /*
0101  * pvr_init() / pvr_exit()
0102  *
0103  * This code is run to initialize/exit the driver.
0104  *
0105  */
0106 static int __init pvr_init(void)
0107 {
0108     int ret;
0109 
0110     pvr2_trace(PVR2_TRACE_INIT,"pvr_init");
0111 
0112     ret = pvr2_context_global_init();
0113     if (ret != 0) {
0114         pvr2_trace(PVR2_TRACE_INIT,"pvr_init failure code=%d",ret);
0115         return ret;
0116     }
0117 
0118 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
0119     class_ptr = pvr2_sysfs_class_create();
0120 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
0121 
0122     ret = usb_register(&pvr_driver);
0123 
0124     if (ret == 0)
0125         pr_info("pvrusb2: " DRIVER_VERSION ":"
0126                DRIVER_DESC "\n");
0127     if (pvrusb2_debug)
0128         pr_info("pvrusb2: Debug mask is %d (0x%x)\n",
0129                pvrusb2_debug,pvrusb2_debug);
0130 
0131     pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete");
0132 
0133     return ret;
0134 }
0135 
0136 static void __exit pvr_exit(void)
0137 {
0138     pvr2_trace(PVR2_TRACE_INIT,"pvr_exit");
0139 
0140     usb_deregister(&pvr_driver);
0141 
0142     pvr2_context_global_done();
0143 
0144 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
0145     pvr2_sysfs_class_destroy(class_ptr);
0146 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
0147 
0148     pvr2_trace(PVR2_TRACE_INIT,"pvr_exit complete");
0149 }
0150 
0151 module_init(pvr_init);
0152 module_exit(pvr_exit);
0153 
0154 MODULE_AUTHOR(DRIVER_AUTHOR);
0155 MODULE_DESCRIPTION(DRIVER_DESC);
0156 MODULE_LICENSE("GPL");
0157 MODULE_VERSION("0.9.1");