blob: ebaf5678b1e4e3b0b2a27461ef11fc4271b0a911 [file] [log] [blame]
Duy Truong790f06d2013-02-13 16:38:12 -08001/* Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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
14
15#include <linux/kernel.h>
16#include <linux/errno.h>
17#include <linux/module.h>
18#include <linux/usb.h>
19#include <linux/slab.h>
20#include <linux/usb/ch11.h>
21#include <linux/usb/hcd.h>
22
23#define TEST_SE0_NAK_PID 0x0101
24#define TEST_J_PID 0x0102
25#define TEST_K_PID 0x0103
26#define TEST_PACKET_PID 0x0104
27#define TEST_HS_HOST_PORT_SUSPEND_RESUME 0x0106
28#define TEST_SINGLE_STEP_GET_DEV_DESC 0x0107
29#define TEST_SINGLE_STEP_SET_FEATURE 0x0108
30
31static int ehset_probe(struct usb_interface *intf,
32 const struct usb_device_id *id)
33{
34 int status = -1;
35 struct usb_device *dev = interface_to_usbdev(intf);
36 struct usb_device *rh_udev = dev->bus->root_hub;
37 struct usb_device *hub_udev = dev->parent;
38 int port1 = dev->portnum;
39 int test_mode = le16_to_cpu(dev->descriptor.idProduct);
40
41 switch (test_mode) {
42 case TEST_SE0_NAK_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 (3 << 8) | port1, NULL, 0, 1000);
46 break;
47 case TEST_J_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 (1 << 8) | port1, NULL, 0, 1000);
51 break;
52 case TEST_K_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 (2 << 8) | port1, NULL, 0, 1000);
56 break;
57 case TEST_PACKET_PID:
58 status = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
59 USB_REQ_SET_FEATURE, USB_RT_PORT, USB_PORT_FEAT_TEST,
60 (4 << 8) | port1, NULL, 0, 1000);
61 break;
62 case TEST_HS_HOST_PORT_SUSPEND_RESUME:
63 /* Test: wait for 15secs -> suspend -> 15secs delay -> resume */
64 msleep(15 * 1000);
65 status = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
66 USB_REQ_SET_FEATURE, USB_RT_PORT,
67 USB_PORT_FEAT_SUSPEND, port1, NULL, 0, 1000);
68 if (status < 0)
69 break;
70 msleep(15 * 1000);
71 status = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
72 USB_REQ_CLEAR_FEATURE, USB_RT_PORT,
73 USB_PORT_FEAT_SUSPEND, port1, NULL, 0, 1000);
74 break;
75 case TEST_SINGLE_STEP_GET_DEV_DESC:
76 /* Test: wait for 15secs -> GetDescriptor request */
77 msleep(15 * 1000);
78 {
79 struct usb_device_descriptor *buf;
80 buf = kmalloc(USB_DT_DEVICE_SIZE, GFP_KERNEL);
81 if (!buf)
82 return -ENOMEM;
83
84 status = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
85 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
86 USB_DT_DEVICE << 8, 0,
87 buf, USB_DT_DEVICE_SIZE,
88 USB_CTRL_GET_TIMEOUT);
89 kfree(buf);
90 }
91 break;
92 case TEST_SINGLE_STEP_SET_FEATURE:
93 /* GetDescriptor's SETUP request -> 15secs delay -> IN & STATUS
94 * Issue request to ehci root hub driver with portnum = 1
95 */
96 status = usb_control_msg(rh_udev, usb_sndctrlpipe(rh_udev, 0),
97 USB_REQ_SET_FEATURE, USB_RT_PORT, USB_PORT_FEAT_TEST,
98 (6 << 8) | 1, NULL, 0, 60 * 1000);
99
100 break;
101 default:
102 pr_err("%s: undefined test mode ( %X )\n", __func__, test_mode);
103 return -EINVAL;
104 }
105
106 return (status < 0) ? status : 0;
107}
108
109static void ehset_disconnect(struct usb_interface *intf)
110{
111}
112
113static struct usb_device_id ehset_id_table[] = {
114 { USB_DEVICE(0x1a0a, TEST_SE0_NAK_PID) },
115 { USB_DEVICE(0x1a0a, TEST_J_PID) },
116 { USB_DEVICE(0x1a0a, TEST_K_PID) },
117 { USB_DEVICE(0x1a0a, TEST_PACKET_PID) },
118 { USB_DEVICE(0x1a0a, TEST_HS_HOST_PORT_SUSPEND_RESUME) },
119 { USB_DEVICE(0x1a0a, TEST_SINGLE_STEP_GET_DEV_DESC) },
120 { USB_DEVICE(0x1a0a, TEST_SINGLE_STEP_SET_FEATURE) },
121 { } /* Terminating entry */
122};
123
124MODULE_DEVICE_TABLE(usb, ehset_id_table);
125
126static struct usb_driver ehset_driver = {
127 .name = "usb_ehset_test",
128 .probe = ehset_probe,
129 .disconnect = ehset_disconnect,
130 .id_table = ehset_id_table,
131};
132
133static int __init ehset_init(void)
134{
135 return usb_register(&ehset_driver);
136}
137
138static void __exit ehset_exit(void)
139{
140 usb_deregister(&ehset_driver);
141}
142
143module_init(ehset_init);
144module_exit(ehset_exit);
145
146MODULE_DESCRIPTION("USB Driver for EHSET Test Fixture");
147MODULE_LICENSE("GPL v2");