ehset.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/module.h>
  16. #include <linux/usb.h>
  17. #include <linux/slab.h>
  18. #include <linux/usb/ch11.h>
  19. #include <linux/usb/hcd.h>
  20. #define TEST_SE0_NAK_PID 0x0101
  21. #define TEST_J_PID 0x0102
  22. #define TEST_K_PID 0x0103
  23. #define TEST_PACKET_PID 0x0104
  24. #define TEST_HS_HOST_PORT_SUSPEND_RESUME 0x0106
  25. #define TEST_SINGLE_STEP_GET_DEV_DESC 0x0107
  26. #define TEST_SINGLE_STEP_SET_FEATURE 0x0108
  27. static int ehset_probe(struct usb_interface *intf,
  28. const struct usb_device_id *id)
  29. {
  30. int status = -1;
  31. struct usb_device *dev = interface_to_usbdev(intf);
  32. struct usb_device *rh_udev = dev->bus->root_hub;
  33. struct usb_device *hub_udev = dev->parent;
  34. int port1 = dev->portnum;
  35. int test_mode = le16_to_cpu(dev->descriptor.idProduct);
  36. switch (test_mode) {
  37. case TEST_SE0_NAK_PID:
  38. status = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
  39. USB_REQ_SET_FEATURE, USB_RT_PORT, USB_PORT_FEAT_TEST,
  40. (3 << 8) | port1, NULL, 0, 1000);
  41. break;
  42. case TEST_J_PID:
  43. status = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
  44. USB_REQ_SET_FEATURE, USB_RT_PORT, USB_PORT_FEAT_TEST,
  45. (1 << 8) | port1, NULL, 0, 1000);
  46. break;
  47. case TEST_K_PID:
  48. status = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
  49. USB_REQ_SET_FEATURE, USB_RT_PORT, USB_PORT_FEAT_TEST,
  50. (2 << 8) | port1, NULL, 0, 1000);
  51. break;
  52. case TEST_PACKET_PID:
  53. status = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
  54. USB_REQ_SET_FEATURE, USB_RT_PORT, USB_PORT_FEAT_TEST,
  55. (4 << 8) | port1, NULL, 0, 1000);
  56. break;
  57. case TEST_HS_HOST_PORT_SUSPEND_RESUME:
  58. /* Test: wait for 15secs -> suspend -> 15secs delay -> resume */
  59. msleep(15 * 1000);
  60. status = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
  61. USB_REQ_SET_FEATURE, USB_RT_PORT,
  62. USB_PORT_FEAT_SUSPEND, port1, NULL, 0, 1000);
  63. if (status < 0)
  64. break;
  65. msleep(15 * 1000);
  66. status = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
  67. USB_REQ_CLEAR_FEATURE, USB_RT_PORT,
  68. USB_PORT_FEAT_SUSPEND, port1, NULL, 0, 1000);
  69. break;
  70. case TEST_SINGLE_STEP_GET_DEV_DESC:
  71. /* Test: wait for 15secs -> GetDescriptor request */
  72. msleep(15 * 1000);
  73. {
  74. struct usb_device_descriptor *buf;
  75. buf = kmalloc(USB_DT_DEVICE_SIZE, GFP_KERNEL);
  76. if (!buf)
  77. return -ENOMEM;
  78. status = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
  79. USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
  80. USB_DT_DEVICE << 8, 0,
  81. buf, USB_DT_DEVICE_SIZE,
  82. USB_CTRL_GET_TIMEOUT);
  83. kfree(buf);
  84. }
  85. break;
  86. case TEST_SINGLE_STEP_SET_FEATURE:
  87. /* GetDescriptor's SETUP request -> 15secs delay -> IN & STATUS
  88. * Issue request to ehci root hub driver with portnum = 1
  89. */
  90. status = usb_control_msg(rh_udev, usb_sndctrlpipe(rh_udev, 0),
  91. USB_REQ_SET_FEATURE, USB_RT_PORT, USB_PORT_FEAT_TEST,
  92. (6 << 8) | 1, NULL, 0, 60 * 1000);
  93. break;
  94. default:
  95. pr_err("%s: undefined test mode ( %X )\n", __func__, test_mode);
  96. return -EINVAL;
  97. }
  98. return (status < 0) ? status : 0;
  99. }
  100. static void ehset_disconnect(struct usb_interface *intf)
  101. {
  102. }
  103. static struct usb_device_id ehset_id_table[] = {
  104. { USB_DEVICE(0x1a0a, TEST_SE0_NAK_PID) },
  105. { USB_DEVICE(0x1a0a, TEST_J_PID) },
  106. { USB_DEVICE(0x1a0a, TEST_K_PID) },
  107. { USB_DEVICE(0x1a0a, TEST_PACKET_PID) },
  108. { USB_DEVICE(0x1a0a, TEST_HS_HOST_PORT_SUSPEND_RESUME) },
  109. { USB_DEVICE(0x1a0a, TEST_SINGLE_STEP_GET_DEV_DESC) },
  110. { USB_DEVICE(0x1a0a, TEST_SINGLE_STEP_SET_FEATURE) },
  111. { } /* Terminating entry */
  112. };
  113. MODULE_DEVICE_TABLE(usb, ehset_id_table);
  114. static struct usb_driver ehset_driver = {
  115. .name = "usb_ehset_test",
  116. .probe = ehset_probe,
  117. .disconnect = ehset_disconnect,
  118. .id_table = ehset_id_table,
  119. };
  120. static int __init ehset_init(void)
  121. {
  122. return usb_register(&ehset_driver);
  123. }
  124. static void __exit ehset_exit(void)
  125. {
  126. usb_deregister(&ehset_driver);
  127. }
  128. module_init(ehset_init);
  129. module_exit(ehset_exit);
  130. MODULE_DESCRIPTION("USB Driver for EHSET Test Fixture");
  131. MODULE_LICENSE("GPL v2");