pvrusb2-main.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. *
  3. * $Id$
  4. *
  5. * Copyright (C) 2005 Mike Isely <isely@pobox.com>
  6. * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #include <linux/config.h>
  23. #include <linux/kernel.h>
  24. #include <linux/errno.h>
  25. #include <linux/slab.h>
  26. #include <linux/module.h>
  27. #include <linux/moduleparam.h>
  28. #include <linux/smp_lock.h>
  29. #include <linux/usb.h>
  30. #include <linux/videodev2.h>
  31. #include "pvrusb2-hdw.h"
  32. #include "pvrusb2-context.h"
  33. #include "pvrusb2-debug.h"
  34. #include "pvrusb2-v4l2.h"
  35. #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  36. #include "pvrusb2-sysfs.h"
  37. #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  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. #define DEFAULT_DEBUG_MASK (PVR2_TRACE_ERROR_LEGS| \
  42. PVR2_TRACE_INFO| \
  43. PVR2_TRACE_TOLERANCE| \
  44. PVR2_TRACE_TRAP| \
  45. 0)
  46. int pvrusb2_debug = DEFAULT_DEBUG_MASK;
  47. module_param_named(debug,pvrusb2_debug,int,S_IRUGO|S_IWUSR);
  48. MODULE_PARM_DESC(debug, "Debug trace mask");
  49. #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  50. static struct pvr2_sysfs_class *class_ptr = NULL;
  51. #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  52. static void pvr_setup_attach(struct pvr2_context *pvr)
  53. {
  54. /* Create association with v4l layer */
  55. pvr2_v4l2_create(pvr);
  56. #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  57. pvr2_sysfs_create(pvr,class_ptr);
  58. #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  59. }
  60. static int pvr_probe(struct usb_interface *intf,
  61. const struct usb_device_id *devid)
  62. {
  63. struct pvr2_context *pvr;
  64. /* Create underlying hardware interface */
  65. pvr = pvr2_context_create(intf,devid,pvr_setup_attach);
  66. if (!pvr) {
  67. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  68. "Failed to create hdw handler");
  69. return -ENOMEM;
  70. }
  71. pvr2_trace(PVR2_TRACE_INIT,"pvr_probe(pvr=%p)",pvr);
  72. usb_set_intfdata(intf, pvr);
  73. return 0;
  74. }
  75. /*
  76. * pvr_disconnect()
  77. *
  78. */
  79. static void pvr_disconnect(struct usb_interface *intf)
  80. {
  81. struct pvr2_context *pvr = usb_get_intfdata(intf);
  82. pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) BEGIN",pvr);
  83. usb_set_intfdata (intf, NULL);
  84. pvr2_context_disconnect(pvr);
  85. pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) DONE",pvr);
  86. }
  87. static struct usb_driver pvr_driver = {
  88. .name = "pvrusb2",
  89. .id_table = pvr2_device_table,
  90. .probe = pvr_probe,
  91. .disconnect = pvr_disconnect
  92. };
  93. /*
  94. * pvr_init() / pvr_exit()
  95. *
  96. * This code is run to initialize/exit the driver.
  97. *
  98. */
  99. static int __init pvr_init(void)
  100. {
  101. int ret;
  102. pvr2_trace(PVR2_TRACE_INIT,"pvr_init");
  103. #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  104. class_ptr = pvr2_sysfs_class_create();
  105. #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  106. ret = usb_register(&pvr_driver);
  107. if (ret == 0)
  108. info(DRIVER_DESC " : " DRIVER_VERSION);
  109. if (pvrusb2_debug) info("Debug mask is %d (0x%x)",
  110. pvrusb2_debug,pvrusb2_debug);
  111. return ret;
  112. }
  113. static void __exit pvr_exit(void)
  114. {
  115. pvr2_trace(PVR2_TRACE_INIT,"pvr_exit");
  116. #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  117. pvr2_sysfs_class_destroy(class_ptr);
  118. #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  119. usb_deregister(&pvr_driver);
  120. }
  121. module_init(pvr_init);
  122. module_exit(pvr_exit);
  123. /* Mike Isely <mcisely@pobox.com> 11-Mar-2006: See pvrusb2-hdw.c for
  124. MODULE_DEVICE_TABLE(). We have to declare that attribute there
  125. because that's where the device table actually is now and it seems
  126. that certain gcc configurations get angry if MODULE_DEVICE_TABLE()
  127. is used on what ends up being an external symbol. */
  128. MODULE_AUTHOR(DRIVER_AUTHOR);
  129. MODULE_DESCRIPTION(DRIVER_DESC);
  130. MODULE_LICENSE("GPL");
  131. /*
  132. Stuff for Emacs to see, in order to encourage consistent editing style:
  133. *** Local Variables: ***
  134. *** mode: c ***
  135. *** fill-column: 70 ***
  136. *** tab-width: 8 ***
  137. *** c-basic-offset: 8 ***
  138. *** End: ***
  139. */