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