259af8ecbca6da05f5e7e07d129980588ea489b2
[openwrt/staging/ynezz.git] /
1 From 93cd22091be5d549fb5b0ec78955c2ec272a52e5 Mon Sep 17 00:00:00 2001
2 From: Peter Chen <peter.chen@freescale.com>
3 Date: Fri, 8 Aug 2014 09:12:52 +0800
4 Subject: [PATCH] MLK-11340-40 usb: whitelist: update otg & eh's TPL for fsl
5 i.mx
6
7 The default TPL is for USB OTG & EH compliance test, the supported
8 class is: mass storage, hub, and hid.
9
10 Besides, we add one match criterion that matching targeted device
11 through class at interface descriptor.
12
13 Tested-by: Li Jun <b47624@freescale.com>
14 Signed-off-by: Peter Chen <peter.chen@freescale.com>
15 (cherry picked from commit 483c071d989ceb36cacf76e1e3e779c67e5b8280)
16 (cherry picked from commit defcf3883f60f8ea913481f16411752cb0132a74)
17 ---
18 drivers/usb/core/otg_whitelist.h | 73 ++++++++++++++++++++++++++++------------
19 1 file changed, 52 insertions(+), 21 deletions(-)
20
21 --- a/drivers/usb/core/otg_whitelist.h
22 +++ b/drivers/usb/core/otg_whitelist.h
23 @@ -13,35 +13,62 @@
24 */
25
26 static struct usb_device_id whitelist_table[] = {
27 -
28 -/* hubs are optional in OTG, but very handy ... */
29 -{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
30 -{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
31 -
32 -#ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
33 -/* FIXME actually, printers are NOT supposed to use device classes;
34 - * they're supposed to use interface classes...
35 - */
36 -{ USB_DEVICE_INFO(7, 1, 1) },
37 -{ USB_DEVICE_INFO(7, 1, 2) },
38 -{ USB_DEVICE_INFO(7, 1, 3) },
39 +/* Add FSL i.mx whitelist, the default list is for USB Compliance Test */
40 +#if defined(CONFIG_USB_EHSET_TEST_FIXTURE) \
41 + || defined(CONFIG_USB_EHSET_TEST_FIXTURE_MODULE)
42 +#define TEST_SE0_NAK_PID 0x0101
43 +#define TEST_J_PID 0x0102
44 +#define TEST_K_PID 0x0103
45 +#define TEST_PACKET_PID 0x0104
46 +#define TEST_HS_HOST_PORT_SUSPEND_RESUME 0x0106
47 +#define TEST_SINGLE_STEP_GET_DEV_DESC 0x0107
48 +#define TEST_SINGLE_STEP_SET_FEATURE 0x0108
49 +{ USB_DEVICE(0x1a0a, TEST_SE0_NAK_PID) },
50 +{ USB_DEVICE(0x1a0a, TEST_J_PID) },
51 +{ USB_DEVICE(0x1a0a, TEST_K_PID) },
52 +{ USB_DEVICE(0x1a0a, TEST_PACKET_PID) },
53 +{ USB_DEVICE(0x1a0a, TEST_HS_HOST_PORT_SUSPEND_RESUME) },
54 +{ USB_DEVICE(0x1a0a, TEST_SINGLE_STEP_GET_DEV_DESC) },
55 +{ USB_DEVICE(0x1a0a, TEST_SINGLE_STEP_SET_FEATURE) },
56 #endif
57
58 -#ifdef CONFIG_USB_NET_CDCETHER
59 -/* Linux-USB CDC Ethernet gadget */
60 -{ USB_DEVICE(0x0525, 0xa4a1), },
61 -/* Linux-USB CDC Ethernet + RNDIS gadget */
62 -{ USB_DEVICE(0x0525, 0xa4a2), },
63 +#define USB_INTERFACE_CLASS_INFO(cl) \
64 + .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS, \
65 + .bInterfaceClass = (cl)
66 +
67 +{USB_INTERFACE_CLASS_INFO(USB_CLASS_HUB) },
68 +#if defined(CONFIG_USB_STORAGE) || defined(CONFIG_USB_STORAGE_MODULE)
69 +{USB_INTERFACE_CLASS_INFO(USB_CLASS_MASS_STORAGE) },
70 #endif
71 -
72 -#if IS_ENABLED(CONFIG_USB_TEST)
73 -/* gadget zero, for testing */
74 -{ USB_DEVICE(0x0525, 0xa4a0), },
75 +#if defined(CONFIG_USB_HID) || defined(CONFIG_USB_HID_MODULE)
76 +{USB_INTERFACE_CLASS_INFO(USB_CLASS_HID) },
77 #endif
78
79 { } /* Terminating entry */
80 };
81
82 +static bool match_int_class(struct usb_device_id *id, struct usb_device *udev)
83 +{
84 + struct usb_host_config *c;
85 + int num_configs, i;
86 +
87 + /* Copy the code from generic.c */
88 + c = udev->config;
89 + num_configs = udev->descriptor.bNumConfigurations;
90 + for (i = 0; i < num_configs; (i++, c++)) {
91 + struct usb_interface_descriptor *desc = NULL;
92 +
93 + /* It's possible that a config has no interfaces! */
94 + if (c->desc.bNumInterfaces > 0)
95 + desc = &c->intf_cache[0]->altsetting->desc;
96 +
97 + if (desc && (desc->bInterfaceClass == id->bInterfaceClass))
98 + return true;
99 + }
100 +
101 + return false;
102 +}
103 +
104 static int is_targeted(struct usb_device *dev)
105 {
106 struct usb_device_id *id = whitelist_table;
107 @@ -90,6 +117,10 @@ static int is_targeted(struct usb_device
108 (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
109 continue;
110
111 + if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_CLASS) &&
112 + (!match_int_class(id, dev)))
113 + continue;
114 +
115 return 1;
116 }
117