ehset.c 4.5 KB

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