root/drivers/media/usb/pvrusb2/pvrusb2-main.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. pvr_setup_attach
  2. pvr_probe
  3. pvr_disconnect
  4. pvr_init
  5. pvr_exit

   1 // SPDX-License-Identifier: GPL-2.0-only
   2 /*
   3  *
   4  *  Copyright (C) 2005 Mike Isely <isely@pobox.com>
   5  *  Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
   6  */
   7 
   8 #include <linux/kernel.h>
   9 #include <linux/errno.h>
  10 #include <linux/module.h>
  11 #include <linux/usb.h>
  12 #include <linux/videodev2.h>
  13 
  14 #include "pvrusb2-hdw.h"
  15 #include "pvrusb2-devattr.h"
  16 #include "pvrusb2-context.h"
  17 #include "pvrusb2-debug.h"
  18 #include "pvrusb2-v4l2.h"
  19 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  20 #include "pvrusb2-sysfs.h"
  21 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  22 
  23 #define DRIVER_AUTHOR "Mike Isely <isely@pobox.com>"
  24 #define DRIVER_DESC "Hauppauge WinTV-PVR-USB2 MPEG2 Encoder/Tuner"
  25 #define DRIVER_VERSION "V4L in-tree version"
  26 
  27 #define DEFAULT_DEBUG_MASK (PVR2_TRACE_ERROR_LEGS| \
  28                             PVR2_TRACE_INFO| \
  29                             PVR2_TRACE_STD| \
  30                             PVR2_TRACE_TOLERANCE| \
  31                             PVR2_TRACE_TRAP| \
  32                             0)
  33 
  34 int pvrusb2_debug = DEFAULT_DEBUG_MASK;
  35 
  36 module_param_named(debug,pvrusb2_debug,int,S_IRUGO|S_IWUSR);
  37 MODULE_PARM_DESC(debug, "Debug trace mask");
  38 
  39 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  40 static struct pvr2_sysfs_class *class_ptr = NULL;
  41 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  42 
  43 static void pvr_setup_attach(struct pvr2_context *pvr)
  44 {
  45         /* Create association with v4l layer */
  46         pvr2_v4l2_create(pvr);
  47 #ifdef CONFIG_VIDEO_PVRUSB2_DVB
  48         /* Create association with dvb layer */
  49         pvr2_dvb_create(pvr);
  50 #endif
  51 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  52         pvr2_sysfs_create(pvr,class_ptr);
  53 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  54 }
  55 
  56 static int pvr_probe(struct usb_interface *intf,
  57                      const struct usb_device_id *devid)
  58 {
  59         struct pvr2_context *pvr;
  60 
  61         /* Create underlying hardware interface */
  62         pvr = pvr2_context_create(intf,devid,pvr_setup_attach);
  63         if (!pvr) {
  64                 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  65                            "Failed to create hdw handler");
  66                 return -ENOMEM;
  67         }
  68 
  69         pvr2_trace(PVR2_TRACE_INIT,"pvr_probe(pvr=%p)",pvr);
  70 
  71         usb_set_intfdata(intf, pvr);
  72 
  73         return 0;
  74 }
  75 
  76 /*
  77  * pvr_disconnect()
  78  *
  79  */
  80 static void pvr_disconnect(struct usb_interface *intf)
  81 {
  82         struct pvr2_context *pvr = usb_get_intfdata(intf);
  83 
  84         pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) BEGIN",pvr);
  85 
  86         usb_set_intfdata (intf, NULL);
  87         pvr2_context_disconnect(pvr);
  88 
  89         pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) DONE",pvr);
  90 
  91 }
  92 
  93 static struct usb_driver pvr_driver = {
  94         .name =         "pvrusb2",
  95         .id_table =     pvr2_device_table,
  96         .probe =        pvr_probe,
  97         .disconnect =   pvr_disconnect
  98 };
  99 
 100 /*
 101  * pvr_init() / pvr_exit()
 102  *
 103  * This code is run to initialize/exit the driver.
 104  *
 105  */
 106 static int __init pvr_init(void)
 107 {
 108         int ret;
 109 
 110         pvr2_trace(PVR2_TRACE_INIT,"pvr_init");
 111 
 112         ret = pvr2_context_global_init();
 113         if (ret != 0) {
 114                 pvr2_trace(PVR2_TRACE_INIT,"pvr_init failure code=%d",ret);
 115                 return ret;
 116         }
 117 
 118 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
 119         class_ptr = pvr2_sysfs_class_create();
 120 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
 121 
 122         ret = usb_register(&pvr_driver);
 123 
 124         if (ret == 0)
 125                 pr_info("pvrusb2: " DRIVER_VERSION ":"
 126                        DRIVER_DESC "\n");
 127         if (pvrusb2_debug)
 128                 pr_info("pvrusb2: Debug mask is %d (0x%x)\n",
 129                        pvrusb2_debug,pvrusb2_debug);
 130 
 131         pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete");
 132 
 133         return ret;
 134 }
 135 
 136 static void __exit pvr_exit(void)
 137 {
 138         pvr2_trace(PVR2_TRACE_INIT,"pvr_exit");
 139 
 140         usb_deregister(&pvr_driver);
 141 
 142         pvr2_context_global_done();
 143 
 144 #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
 145         pvr2_sysfs_class_destroy(class_ptr);
 146 #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
 147 
 148         pvr2_trace(PVR2_TRACE_INIT,"pvr_exit complete");
 149 }
 150 
 151 module_init(pvr_init);
 152 module_exit(pvr_exit);
 153 
 154 MODULE_AUTHOR(DRIVER_AUTHOR);
 155 MODULE_DESCRIPTION(DRIVER_DESC);
 156 MODULE_LICENSE("GPL");
 157 MODULE_VERSION("0.9.1");

/* [<][>][^][v][top][bottom][index][help] */