pvrusb2-main.c 4.0 KB

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