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