2 * otg.c -- USB OTG utility code
4 * Copyright (C) 2004 Texas Instruments
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
12 #include <linux/kernel.h>
13 #include <linux/device.h>
14 #include <linux/mod_devicetable.h>
15 #include <linux/byteorder/generic.h>
16 #include <linux/gfp.h>
17 #include <linux/usb.h>
18 #include <linux/usb/otg.h>
20 #include "../core/otg_whitelist.h"
22 static struct otg_transceiver *xceiv;
25 * otg_get_transceiver - find the (single) OTG transceiver
27 * Returns the transceiver driver, after getting a refcount to it; or
28 * null if there is no such transceiver. The caller is responsible for
29 * calling otg_put_transceiver() to release that count.
31 * For use by USB host and peripheral drivers.
33 struct otg_transceiver *otg_get_transceiver(void)
36 get_device(xceiv->dev);
39 EXPORT_SYMBOL(otg_get_transceiver);
42 * otg_put_transceiver - release the (single) OTG transceiver
43 * @x: the transceiver returned by otg_get_transceiver()
45 * Releases a refcount the caller received from otg_get_transceiver().
47 * For use by USB host and peripheral drivers.
49 void otg_put_transceiver(struct otg_transceiver *x)
53 EXPORT_SYMBOL(otg_put_transceiver);
56 * otg_set_transceiver - declare the (single) OTG transceiver
57 * @x: the USB OTG transceiver to be used; or NULL
59 * This call is exclusively for use by transceiver drivers, which
60 * coordinate the activities of drivers for host and peripheral
61 * controllers, and in some cases for VBUS current regulation.
63 int otg_set_transceiver(struct otg_transceiver *x)
70 EXPORT_SYMBOL(otg_set_transceiver);
72 #ifdef CONFIG_USB_OTG_WHITELIST
75 * This OTG Whitelist is the OTG "Targeted Peripheral List". It should
76 * mostly use of USB_DEVICE() or USB_DEVICE_VER() entries..
78 * YOU _SHOULD_ CHANGE THIS LIST TO MATCH YOUR PRODUCT AND ITS TESTING!
81 static struct usb_device_id whitelist_table[] = {
83 /* hubs are optional in OTG, but very handy ... */
84 { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
85 { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
87 #ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
88 /* FIXME actually, printers are NOT supposed to use device classes;
89 * they're supposed to use interface classes...
91 { USB_DEVICE_INFO(7, 1, 1) },
92 { USB_DEVICE_INFO(7, 1, 2) },
93 { USB_DEVICE_INFO(7, 1, 3) },
96 #ifdef CONFIG_USB_NET_CDCETHER
97 /* Linux-USB CDC Ethernet gadget */
98 { USB_DEVICE(0x0525, 0xa4a1), },
99 /* Linux-USB CDC Ethernet + RNDIS gadget */
100 { USB_DEVICE(0x0525, 0xa4a2), },
103 #if defined(CONFIG_USB_TEST) || defined(CONFIG_USB_TEST_MODULE)
104 /* gadget zero, for testing */
105 { USB_DEVICE(0x0525, 0xa4a0), },
108 { } /* Terminating entry */
111 int is_targeted(struct usb_device *dev)
113 struct usb_device_id *id = whitelist_table;
115 /* possible in developer configs only! */
116 if (!dev->bus->otg_port)
119 /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
120 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
121 le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
124 /* NOTE: can't use usb_match_id() since interface caches
125 * aren't set up yet. this is cut/paste from that code.
127 for (id = whitelist_table; id->match_flags; id++) {
128 if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
129 id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
132 if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
133 id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
136 /* No need to test id->bcdDevice_lo != 0, since 0 is never
137 greater than any unsigned number. */
138 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
139 (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
142 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
143 (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
146 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
147 (id->bDeviceClass != dev->descriptor.bDeviceClass))
150 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
151 (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
154 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
155 (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
161 /* add other match criteria here ... */
165 /* OTG MESSAGE: report errors here, customize to match your product */
166 dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
167 le16_to_cpu(dev->descriptor.idVendor),
168 le16_to_cpu(dev->descriptor.idProduct));
173 #endif /* CONFIG_USB_OTG_WHITELIST */