pvrusb2-main.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. *
  4. * Copyright (C) 2005 Mike Isely <[email protected]>
  5. * Copyright (C) 2004 Aurelien Alleaume <[email protected]>
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/errno.h>
  9. #include <linux/module.h>
  10. #include <linux/usb.h>
  11. #include <linux/videodev2.h>
  12. #include "pvrusb2-hdw.h"
  13. #include "pvrusb2-devattr.h"
  14. #include "pvrusb2-context.h"
  15. #include "pvrusb2-debug.h"
  16. #include "pvrusb2-v4l2.h"
  17. #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  18. #include "pvrusb2-sysfs.h"
  19. #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  20. #define DRIVER_AUTHOR "Mike Isely <[email protected]>"
  21. #define DRIVER_DESC "Hauppauge WinTV-PVR-USB2 MPEG2 Encoder/Tuner"
  22. #define DRIVER_VERSION "V4L in-tree version"
  23. #define DEFAULT_DEBUG_MASK (PVR2_TRACE_ERROR_LEGS| \
  24. PVR2_TRACE_INFO| \
  25. PVR2_TRACE_STD| \
  26. PVR2_TRACE_TOLERANCE| \
  27. PVR2_TRACE_TRAP| \
  28. 0)
  29. int pvrusb2_debug = DEFAULT_DEBUG_MASK;
  30. module_param_named(debug,pvrusb2_debug,int,S_IRUGO|S_IWUSR);
  31. MODULE_PARM_DESC(debug, "Debug trace mask");
  32. #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  33. static struct pvr2_sysfs_class *class_ptr = NULL;
  34. #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  35. static void pvr_setup_attach(struct pvr2_context *pvr)
  36. {
  37. /* Create association with v4l layer */
  38. pvr2_v4l2_create(pvr);
  39. #ifdef CONFIG_VIDEO_PVRUSB2_DVB
  40. /* Create association with dvb layer */
  41. pvr2_dvb_create(pvr);
  42. #endif
  43. #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  44. pvr2_sysfs_create(pvr,class_ptr);
  45. #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  46. }
  47. static int pvr_probe(struct usb_interface *intf,
  48. const struct usb_device_id *devid)
  49. {
  50. struct pvr2_context *pvr;
  51. /* Create underlying hardware interface */
  52. pvr = pvr2_context_create(intf,devid,pvr_setup_attach);
  53. if (!pvr) {
  54. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  55. "Failed to create hdw handler");
  56. return -ENOMEM;
  57. }
  58. pvr2_trace(PVR2_TRACE_INIT,"pvr_probe(pvr=%p)",pvr);
  59. usb_set_intfdata(intf, pvr);
  60. return 0;
  61. }
  62. /*
  63. * pvr_disconnect()
  64. *
  65. */
  66. static void pvr_disconnect(struct usb_interface *intf)
  67. {
  68. struct pvr2_context *pvr = usb_get_intfdata(intf);
  69. pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) BEGIN",pvr);
  70. usb_set_intfdata (intf, NULL);
  71. pvr2_context_disconnect(pvr);
  72. pvr2_trace(PVR2_TRACE_INIT,"pvr_disconnect(pvr=%p) DONE",pvr);
  73. }
  74. static struct usb_driver pvr_driver = {
  75. .name = "pvrusb2",
  76. .id_table = pvr2_device_table,
  77. .probe = pvr_probe,
  78. .disconnect = pvr_disconnect
  79. };
  80. /*
  81. * pvr_init() / pvr_exit()
  82. *
  83. * This code is run to initialize/exit the driver.
  84. *
  85. */
  86. static int __init pvr_init(void)
  87. {
  88. int ret;
  89. pvr2_trace(PVR2_TRACE_INIT,"pvr_init");
  90. ret = pvr2_context_global_init();
  91. if (ret != 0) {
  92. pvr2_trace(PVR2_TRACE_INIT,"pvr_init failure code=%d",ret);
  93. return ret;
  94. }
  95. #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  96. class_ptr = pvr2_sysfs_class_create();
  97. #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  98. ret = usb_register(&pvr_driver);
  99. if (ret == 0)
  100. pr_info("pvrusb2: " DRIVER_VERSION ":"
  101. DRIVER_DESC "\n");
  102. if (pvrusb2_debug)
  103. pr_info("pvrusb2: Debug mask is %d (0x%x)\n",
  104. pvrusb2_debug,pvrusb2_debug);
  105. pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete");
  106. return ret;
  107. }
  108. static void __exit pvr_exit(void)
  109. {
  110. pvr2_trace(PVR2_TRACE_INIT,"pvr_exit");
  111. usb_deregister(&pvr_driver);
  112. pvr2_context_global_done();
  113. #ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
  114. pvr2_sysfs_class_destroy(class_ptr);
  115. #endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
  116. pvr2_trace(PVR2_TRACE_INIT,"pvr_exit complete");
  117. }
  118. module_init(pvr_init);
  119. module_exit(pvr_exit);
  120. MODULE_AUTHOR(DRIVER_AUTHOR);
  121. MODULE_DESCRIPTION(DRIVER_DESC);
  122. MODULE_LICENSE("GPL");
  123. MODULE_VERSION("0.9.1");