pvrusb2-main.c 4.2 KB

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