pvrusb2-main.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. *
  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. #include <linux/kernel.h>
  22. #include <linux/errno.h>
  23. #include <linux/slab.h>
  24. #include <linux/module.h>
  25. #include <linux/usb.h>
  26. #include <linux/videodev2.h>
  27. #include "pvrusb2-hdw.h"
  28. #include "pvrusb2-devattr.h"
  29. #include "pvrusb2-context.h"
  30. #include "pvrusb2-debug.h"
  31. #include "pvrusb2-v4l2.h"
  32. #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  33. #include "pvrusb2-sysfs.h"
  34. #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  35. #define DRIVER_AUTHOR "Mike Isely <isely@pobox.com>"
  36. #define DRIVER_DESC "Hauppauge WinTV-PVR-USB2 MPEG2 Encoder/Tuner"
  37. #define DRIVER_VERSION "V4L in-tree version"
  38. #define DEFAULT_DEBUG_MASK (PVR2_TRACE_ERROR_LEGS| \
  39. PVR2_TRACE_INFO| \
  40. PVR2_TRACE_STD| \
  41. PVR2_TRACE_TOLERANCE| \
  42. PVR2_TRACE_TRAP| \
  43. 0)
  44. int pvrusb2_debug = DEFAULT_DEBUG_MASK;
  45. module_param_named(debug,pvrusb2_debug,int,S_IRUGO|S_IWUSR);
  46. MODULE_PARM_DESC(debug, "Debug trace mask");
  47. #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  48. static struct pvr2_sysfs_class *class_ptr = NULL;
  49. #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  50. static void pvr_setup_attach(struct pvr2_context *pvr)
  51. {
  52. /* Create association with v4l layer */
  53. pvr2_v4l2_create(pvr);
  54. #ifdef CONFIG_VIDEO_PVRUSB2_DVB
  55. /* Create association with dvb layer */
  56. pvr2_dvb_create(pvr);
  57. #endif
  58. #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  59. pvr2_sysfs_create(pvr,class_ptr);
  60. #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  61. }
  62. static int pvr_probe(struct usb_interface *intf,
  63. const struct usb_device_id *devid)
  64. {
  65. struct pvr2_context *pvr;
  66. /* Create underlying hardware interface */
  67. pvr = pvr2_context_create(intf,devid,pvr_setup_attach);
  68. if (!pvr) {
  69. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  70. "Failed to create hdw handler");
  71. return -ENOMEM;
  72. }
  73. pvr2_trace(PVR2_TRACE_INIT,"pvr_probe(pvr=%p)",pvr);
  74. usb_set_intfdata(intf, pvr);
  75. return 0;
  76. }
  77. /*
  78. * pvr_disconnect()
  79. *
  80. */
  81. static void pvr_disconnect(struct usb_interface *intf)
  82. {
  83. struct pvr2_context *pvr = usb_get_intfdata(intf);
  84. pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) BEGIN",pvr);
  85. usb_set_intfdata (intf, NULL);
  86. pvr2_context_disconnect(pvr);
  87. pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) DONE",pvr);
  88. }
  89. static struct usb_driver pvr_driver = {
  90. .name = "pvrusb2",
  91. .id_table = pvr2_device_table,
  92. .probe = pvr_probe,
  93. .disconnect = pvr_disconnect
  94. };
  95. /*
  96. * pvr_init() / pvr_exit()
  97. *
  98. * This code is run to initialize/exit the driver.
  99. *
  100. */
  101. static int __init pvr_init(void)
  102. {
  103. int ret;
  104. pvr2_trace(PVR2_TRACE_INIT,"pvr_init");
  105. ret = pvr2_context_global_init();
  106. if (ret != 0) {
  107. pvr2_trace(PVR2_TRACE_INIT,"pvr_init failure code=%d",ret);
  108. return ret;
  109. }
  110. #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  111. class_ptr = pvr2_sysfs_class_create();
  112. #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  113. ret = usb_register(&pvr_driver);
  114. if (ret == 0)
  115. printk(KERN_INFO "pvrusb2: " DRIVER_VERSION ":"
  116. DRIVER_DESC "\n");
  117. if (pvrusb2_debug)
  118. printk(KERN_INFO "pvrusb2: Debug mask is %d (0x%x)\n",
  119. pvrusb2_debug,pvrusb2_debug);
  120. pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete");
  121. return ret;
  122. }
  123. static void __exit pvr_exit(void)
  124. {
  125. pvr2_trace(PVR2_TRACE_INIT,"pvr_exit");
  126. usb_deregister(&pvr_driver);
  127. #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  128. pvr2_sysfs_class_destroy(class_ptr);
  129. #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  130. pvr2_context_global_done();
  131. pvr2_trace(PVR2_TRACE_INIT,"pvr_exit complete");
  132. }
  133. module_init(pvr_init);
  134. module_exit(pvr_exit);
  135. MODULE_AUTHOR(DRIVER_AUTHOR);
  136. MODULE_DESCRIPTION(DRIVER_DESC);
  137. MODULE_LICENSE("GPL");
  138. /*
  139. Stuff for Emacs to see, in order to encourage consistent editing style:
  140. *** Local Variables: ***
  141. *** mode: c ***
  142. *** fill-column: 70 ***
  143. *** tab-width: 8 ***
  144. *** c-basic-offset: 8 ***
  145. *** End: ***
  146. */