linux/drivers/usb/misc/ehset.c
<<
lue=14lue=14>>lulue=lue=14 ">lue=14lue=14Searchlue=14Prefs. 14lulu ">le=14 4.
4 41/*4 42 * Copyright (c) 2010-2013, The Linux Founda v. All rights reserved.4 43 *4 44 * This program is free software; you cav redistribute it and/or modify4 45 * it under the terms of the GNU General Public License verstion2 and4 46 * only verstion2 as published by the Free Software Founda v.4 47 *4 48 * This program is distributed in the hope that it will be useful,4 49 * but WITHOUT ANY WARRANTY; without even the implied warranty of4 2 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the4 11 * GNU General Public License for more details.4 12 */4 13.4 14#include <linux/kernel.h>.4 15#include <linux/errno.h>.4 16#include <linux/module.h>.4 17#include <linux/slab.h>.4 18#include <linux/usb.h>.4 19#include <linux/usb/ch11.h>.4 20.4 21#define4TEST_SE0_NAK_PID 0x0101.4 22#define4TEST_J_PID 0x0102.4 23#define4TEST_K_PID 0x0103.4 24#define4TEST_PACKET_PID 0x0104.4 25#define4TEST_HS_HOST_PORT_SUSPEND_RESUME 0x0106.4 26#define4TEST_SINGLE_STEP_GET_DEV_DESC 0x0107.4 27#define4TEST_SINGLE_STEP_SET_FEATURE 0x0108.4 28.4 29static int4ehset_probe(struct4usb_interface *intf,.4 30 const struct4usb_device_id *id).4 31{.4 32 int4ret = -EINVAL;.4 33 struct4usb_device *dev = interface_to_usbdev(intf);.4 34 struct4usb_device *hub_udev = dev->parent;.4 35 struct4usb_device_descriptor *buf;.4 36 u8 portnum = dev->portnum;.4 37 u16 test_pid = le16_to_cpu(dev->descriptor.idProduct);.4 38.4 39 switch (test_pid) {.4 40 case4TEST_SE0_NAK_PID:.4 41 ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),.4 42 USB_REQ_SET_FEATURE, USB_RT_PORT,.4 43 USB_PORT_FEAT_TEST,.4 44 (TEST_SE0_NAK << 8) | portnum,.4 45 NULL, 0, 1000);.4 46 break;.4 47 case4TEST_J_PID:.4 48 ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),.4 49 USB_REQ_SET_FEATURE, USB_RT_PORT,.4 50 USB_PORT_FEAT_TEST,.4 51 (TEST_J << 8) | portnum,.4 52 NULL, 0, 1000);.4 53 break;.4 54 case4TEST_K_PID:.4 55 ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),.4 56 USB_REQ_SET_FEATURE, USB_RT_PORT,.4 57 USB_PORT_FEAT_TEST,.4 58 (TEST_K << 8) | portnum,.4 59 NULL, 0, 1000);.4 60 break;.4 61 case4TEST_PACKET_PID:.4 62 ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),.4 63 USB_REQ_SET_FEATURE, USB_RT_PORT,.4 64 USB_PORT_FEAT_TEST,.4 65 (TEST_PACKET << 8) | portnum,.4 66 NULL, 0, 1000);.4 67 break;.4 68 case4TEST_HS_HOST_PORT_SUSPEND_RESUME:.4 69 /* Test: wait for 15secs -> suspend -> 15secs delay -> resume */4 70 msleep(15 * 1000);.4 71 ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),.4 72 USB_REQ_SET_FEATURE, USB_RT_PORT,.4 73 USB_PORT_FEAT_SUSPEND, portnum,.4 74 NULL, 0, 1000);.4 75 if (ret < 0).4 76 break;.4 77.4 78 msleep(15 * 1000);.4 79 ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),.4 80 USB_REQ_CLEAR_FEATURE, USB_RT_PORT,.4 81 USB_PORT_FEAT_SUSPEND, portnum,.4 82 NULL, 0, 1000);.4 83 break;.4 84 case4TEST_SINGLE_STEP_GET_DEV_DESC:.4 85 /* Test: wait for 15secs -> GetDescriptor request */4 86 msleep(15 * 1000);.4 87 buf = kmalloc(USB_DT_DEVICE_SIZE, GFP_KERNEL);.4 88 if (!buf).4 89 return -ENOMEM;.4 90.4 91 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),.4 92 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,.4 93 USB_DT_DEVICE << 8, 0,.4 94 buf, USB_DT_DEVICE_SIZE,.4 95 USB_CTRL_GET_TIMEOUT);.4 96 kfree(buf);.4 97 break;.4 98 case4TEST_SINGLE_STEP_SET_FEATURE:.4 99 /*4100 * GetDescriptor SETUP request -> 15secs delay -> IN & STATUS4101 *4102 * Note, this test is only supported on root hubs since the4103 * SetPortFeature handling cav only be done inside the HCD's4104 * hub_control callback func v.4105 */4106 if (hub_udev != dev->bus->root_hub) {.4107 dev_err(&intf->dev, "SINGLE_STEP_SET_FEATURE test only supported on root hub\n"4108 break;.4109 }.4110.4111 ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),.4112 USB_REQ_SET_FEATURE, USB_RT_PORT,.4113 USB_PORT_FEAT_TEST,.4114 (6 << 8) | portnum,.4115 NULL, 0, 60 * 1000);.4116.4117 break;.4118 default:.4119 dev_err(&intf->dev, "%s: unsupported PID: 0x%x\n"4120 __func__, test_pid);.4121 }.4122.4123 return (ret < 0) ? ret : 0;.4124}.4125.4126static void4ehset_disconnect(struct4usb_interface *intf).4127{.4128}.4129.4130static const struct4usb_device_id ehset_id_table[] = {.4131 { USB_DEVICE(0x1a0a, TEST_SE0_NAK_PID) },.4132 { USB_DEVICE(0x1a0a, TEST_J_PID) },.4133 { USB_DEVICE(0x1a0a, TEST_K_PID) },.4134 { USB_DEVICE(0x1a0a, TEST_PACKET_PID) },.4135 { USB_DEVICE(0x1a0a, TEST_HS_HOST_PORT_SUSPEND_RESUME) },.4136 { USB_DEVICE(0x1a0a, TEST_SINGLE_STEP_GET_DEV_DESC) },.4137 { USB_DEVICE(0x1a0a, TEST_SINGLE_STEP_SET_FEATURE) },.4138 { } /* Terminating entry */4139};.4140MODULE_DEVICE_TABLE(usb, ehset_id_table);.4141.4142static struct4usb_driver ehset_driver = {.4143 .nam = "usb_ehset_test"4144 .probe = ehset_probe,.4145 .disconnect = ehset_disconnect,.4146 .id_table = ehset_id_table,.4147};.4148.4149module_usb_driver(ehset_driver);.4150.4151MODULE_DESCRIPTION("USB Driver for EHSET Test Fixture"4152MODULE_LICENSE("GPL v2"4153 The original LXR software by the LXR community, this experimental verstionby lxr@linux.no. lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and opera vs services since 1995.