1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Copyright (C) 2004 Texas Instruments */
3
4 /*
5 * This OTG and Embedded Host list is "Targeted Peripheral List".
6 * It should mostly use of USB_DEVICE() or USB_DEVICE_VER() entries..
7 *
8 * YOU _SHOULD_ CHANGE THIS LIST TO MATCH YOUR PRODUCT AND ITS TESTING!
9 */
10
11 static struct usb_device_id productlist_table[] = {
12
13 /* hubs are optional in OTG, but very handy ... */
14 { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
15 { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
16
17 #ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
18 /* FIXME actually, printers are NOT supposed to use device classes;
19 * they're supposed to use interface classes...
20 */
21 { USB_DEVICE_INFO(7, 1, 1) },
22 { USB_DEVICE_INFO(7, 1, 2) },
23 { USB_DEVICE_INFO(7, 1, 3) },
24 #endif
25
26 #ifdef CONFIG_USB_NET_CDCETHER
27 /* Linux-USB CDC Ethernet gadget */
28 { USB_DEVICE(0x0525, 0xa4a1), },
29 /* Linux-USB CDC Ethernet + RNDIS gadget */
30 { USB_DEVICE(0x0525, 0xa4a2), },
31 #endif
32
33 #if IS_ENABLED(CONFIG_USB_TEST)
34 /* gadget zero, for testing */
35 { USB_DEVICE(0x0525, 0xa4a0), },
36 #endif
37
38 { } /* Terminating entry */
39 };
40
is_targeted(struct usb_device * dev)41 static int is_targeted(struct usb_device *dev)
42 {
43 struct usb_device_id *id = productlist_table;
44
45 /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
46 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
47 le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
48 return 0;
49
50 /* OTG PET device is always targeted (see OTG 2.0 ECN 6.4.2) */
51 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
52 le16_to_cpu(dev->descriptor.idProduct) == 0x0200))
53 return 1;
54
55 /* NOTE: can't use usb_match_id() since interface caches
56 * aren't set up yet. this is cut/paste from that code.
57 */
58 for (id = productlist_table; id->match_flags; id++) {
59 if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
60 id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
61 continue;
62
63 if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
64 id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
65 continue;
66
67 /* No need to test id->bcdDevice_lo != 0, since 0 is never
68 greater than any unsigned number. */
69 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
70 (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
71 continue;
72
73 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
74 (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
75 continue;
76
77 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
78 (id->bDeviceClass != dev->descriptor.bDeviceClass))
79 continue;
80
81 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
82 (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
83 continue;
84
85 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
86 (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
87 continue;
88
89 return 1;
90 }
91
92 /* add other match criteria here ... */
93
94
95 /* OTG MESSAGE: report errors here, customize to match your product */
96 dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
97 le16_to_cpu(dev->descriptor.idVendor),
98 le16_to_cpu(dev->descriptor.idProduct));
99
100 return 0;
101 }
102
103