Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * zero.c -- Gadget Zero, for USB development |
| 3 | * |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 4 | * Copyright (C) 2003-2008 David Brownell |
| 5 | * Copyright (C) 2008 by Nokia Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
David Brownell | ca2bdf4 | 2007-08-02 12:20:05 -0700 | [diff] [blame] | 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | |
| 14 | /* |
| 15 | * Gadget Zero only needs two bulk endpoints, and is an example of how you |
| 16 | * can write a hardware-agnostic gadget driver running inside a USB device. |
David Brownell | 7472f38 | 2008-04-18 18:47:54 -0700 | [diff] [blame] | 17 | * Some hardware details are visible, but don't affect most of the driver. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * |
| 19 | * Use it with the Linux host/master side "usbtest" driver to get a basic |
| 20 | * functional test of your device-side usb stack, or with "usb-skeleton". |
| 21 | * |
| 22 | * It supports two similar configurations. One sinks whatever the usb host |
| 23 | * writes, and in return sources zeroes. The other loops whatever the host |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 24 | * writes back, so the host can read it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | * |
| 26 | * Many drivers will only have one configuration, letting them be much |
| 27 | * simpler if they also don't support high speed operation (like this |
| 28 | * driver does). |
David Brownell | ca2bdf4 | 2007-08-02 12:20:05 -0700 | [diff] [blame] | 29 | * |
| 30 | * Why is *this* driver using two configurations, rather than setting up |
| 31 | * two interfaces with different functions? To help verify that multiple |
| 32 | * configuration infrastucture is working correctly; also, so that it can |
| 33 | * work with low capability USB controllers without four bulk endpoints. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | */ |
| 35 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 36 | /* |
| 37 | * driver assumes self-powered hardware, and |
| 38 | * has no way for users to trigger remote wakeup. |
| 39 | */ |
| 40 | |
David Brownell | ca2bdf4 | 2007-08-02 12:20:05 -0700 | [diff] [blame] | 41 | /* #define VERBOSE_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/utsname.h> |
| 46 | #include <linux/device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 48 | #include "g_zero.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include "gadget_chips.h" |
| 50 | |
| 51 | |
| 52 | /*-------------------------------------------------------------------------*/ |
| 53 | |
David Brownell | 7e75bc0 | 2008-08-18 17:41:31 -0700 | [diff] [blame] | 54 | /* |
| 55 | * Kbuild is not very cooperative with respect to linking separately |
| 56 | * compiled library objects into one module. So for now we won't use |
| 57 | * separate compilation ... ensuring init/exit sections work to shrink |
| 58 | * the runtime footprint, and giving us at least some parts of what |
| 59 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. |
| 60 | */ |
| 61 | #include "composite.c" |
David Brownell | 7e75bc0 | 2008-08-18 17:41:31 -0700 | [diff] [blame] | 62 | |
| 63 | #include "f_sourcesink.c" |
| 64 | #include "f_loopback.c" |
| 65 | |
| 66 | /*-------------------------------------------------------------------------*/ |
Sebastian Andrzej Siewior | 7d16e8d | 2012-09-10 15:01:53 +0200 | [diff] [blame^] | 67 | USB_GADGET_COMPOSITE_OPTIONS(); |
David Brownell | 7e75bc0 | 2008-08-18 17:41:31 -0700 | [diff] [blame] | 68 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 69 | #define DRIVER_VERSION "Cinco de Mayo 2008" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
David Brownell | 7472f38 | 2008-04-18 18:47:54 -0700 | [diff] [blame] | 71 | static const char longname[] = "Gadget Zero"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Paul Zimmerman | b4036cc | 2012-04-16 14:19:06 -0700 | [diff] [blame] | 73 | unsigned buflen = 4096; /* only used for bulk endpoints */ |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 74 | module_param(buflen, uint, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * Normally the "loopback" configuration is second (index 1) so |
| 78 | * it's not the default. Here's where to change that order, to |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 79 | * work better with hosts where config changes are problematic or |
| 80 | * controllers (like original superh) that only support one config. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 82 | static bool loopdefault = 0; |
David Brownell | 7472f38 | 2008-04-18 18:47:54 -0700 | [diff] [blame] | 83 | module_param(loopdefault, bool, S_IRUGO|S_IWUSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | /*-------------------------------------------------------------------------*/ |
| 86 | |
| 87 | /* Thanks to NetChip Technologies for donating this product ID. |
| 88 | * |
| 89 | * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! |
| 90 | * Instead: allocate your own, using normal USB-IF procedures. |
| 91 | */ |
| 92 | #ifndef CONFIG_USB_ZERO_HNPTEST |
| 93 | #define DRIVER_VENDOR_NUM 0x0525 /* NetChip */ |
| 94 | #define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */ |
David Brownell | ab943a2 | 2009-03-19 14:16:09 -0700 | [diff] [blame] | 95 | #define DEFAULT_AUTORESUME 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | #else |
| 97 | #define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */ |
| 98 | #define DRIVER_PRODUCT_NUM 0xbadd |
David Brownell | ab943a2 | 2009-03-19 14:16:09 -0700 | [diff] [blame] | 99 | #define DEFAULT_AUTORESUME 5 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | #endif |
| 101 | |
David Brownell | ab943a2 | 2009-03-19 14:16:09 -0700 | [diff] [blame] | 102 | /* If the optional "autoresume" mode is enabled, it provides good |
| 103 | * functional coverage for the "USBCV" test harness from USB-IF. |
| 104 | * It's always set if OTG mode is enabled. |
| 105 | */ |
| 106 | unsigned autoresume = DEFAULT_AUTORESUME; |
| 107 | module_param(autoresume, uint, S_IRUGO); |
| 108 | MODULE_PARM_DESC(autoresume, "zero, or seconds before remote wakeup"); |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | /*-------------------------------------------------------------------------*/ |
| 111 | |
David Brownell | 7472f38 | 2008-04-18 18:47:54 -0700 | [diff] [blame] | 112 | static struct usb_device_descriptor device_desc = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | .bLength = sizeof device_desc, |
| 114 | .bDescriptorType = USB_DT_DEVICE, |
| 115 | |
Harvey Harrison | 551509d | 2009-02-11 14:11:36 -0800 | [diff] [blame] | 116 | .bcdUSB = cpu_to_le16(0x0200), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | .bDeviceClass = USB_CLASS_VENDOR_SPEC, |
| 118 | |
Harvey Harrison | 551509d | 2009-02-11 14:11:36 -0800 | [diff] [blame] | 119 | .idVendor = cpu_to_le16(DRIVER_VENDOR_NUM), |
| 120 | .idProduct = cpu_to_le16(DRIVER_PRODUCT_NUM), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | .bNumConfigurations = 2, |
| 122 | }; |
| 123 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 124 | #ifdef CONFIG_USB_OTG |
David Brownell | 7472f38 | 2008-04-18 18:47:54 -0700 | [diff] [blame] | 125 | static struct usb_otg_descriptor otg_descriptor = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | .bLength = sizeof otg_descriptor, |
| 127 | .bDescriptorType = USB_DT_OTG, |
| 128 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 129 | /* REVISIT SRP-only hardware is possible, although |
| 130 | * it would not be called "OTG" ... |
| 131 | */ |
| 132 | .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 135 | const struct usb_descriptor_header *otg_desc[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | (struct usb_descriptor_header *) &otg_descriptor, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | NULL, |
| 138 | }; |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 139 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 141 | /* string IDs are assigned dynamically */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 143 | #define STRING_MANUFACTURER_IDX 0 |
| 144 | #define STRING_PRODUCT_IDX 1 |
| 145 | #define STRING_SERIAL_IDX 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
David Brownell | ca2bdf4 | 2007-08-02 12:20:05 -0700 | [diff] [blame] | 147 | static char manufacturer[50]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
David Brownell | ca2bdf4 | 2007-08-02 12:20:05 -0700 | [diff] [blame] | 149 | /* default serial number takes at least two packets */ |
| 150 | static char serial[] = "0123456789.0123456789.0123456789"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 152 | static struct usb_string strings_dev[] = { |
| 153 | [STRING_MANUFACTURER_IDX].s = manufacturer, |
| 154 | [STRING_PRODUCT_IDX].s = longname, |
| 155 | [STRING_SERIAL_IDX].s = serial, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { } /* end of list */ |
| 157 | }; |
| 158 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 159 | static struct usb_gadget_strings stringtab_dev = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | .language = 0x0409, /* en-us */ |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 161 | .strings = strings_dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 164 | static struct usb_gadget_strings *dev_strings[] = { |
| 165 | &stringtab_dev, |
| 166 | NULL, |
| 167 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
| 169 | /*-------------------------------------------------------------------------*/ |
| 170 | |
Paul Zimmerman | b4036cc | 2012-04-16 14:19:06 -0700 | [diff] [blame] | 171 | struct usb_request *alloc_ep_req(struct usb_ep *ep, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | { |
| 173 | struct usb_request *req; |
| 174 | |
David Brownell | 7472f38 | 2008-04-18 18:47:54 -0700 | [diff] [blame] | 175 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | if (req) { |
Paul Zimmerman | b4036cc | 2012-04-16 14:19:06 -0700 | [diff] [blame] | 177 | if (len) |
| 178 | req->length = len; |
| 179 | else |
| 180 | req->length = buflen; |
| 181 | req->buf = kmalloc(req->length, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | if (!req->buf) { |
David Brownell | 7472f38 | 2008-04-18 18:47:54 -0700 | [diff] [blame] | 183 | usb_ep_free_request(ep, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | req = NULL; |
| 185 | } |
| 186 | } |
| 187 | return req; |
| 188 | } |
| 189 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 190 | void free_ep_req(struct usb_ep *ep, struct usb_request *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
David Brownell | 9d8bab5 | 2007-07-01 11:04:54 -0700 | [diff] [blame] | 192 | kfree(req->buf); |
David Brownell | 7472f38 | 2008-04-18 18:47:54 -0700 | [diff] [blame] | 193 | usb_ep_free_request(ep, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 196 | static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 198 | int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 200 | if (ep->driver_data) { |
| 201 | value = usb_ep_disable(ep); |
| 202 | if (value < 0) |
| 203 | DBG(cdev, "disable %s --> %d\n", |
| 204 | ep->name, value); |
| 205 | ep->driver_data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 209 | void disable_endpoints(struct usb_composite_dev *cdev, |
Paul Zimmerman | b4036cc | 2012-04-16 14:19:06 -0700 | [diff] [blame] | 210 | struct usb_ep *in, struct usb_ep *out, |
| 211 | struct usb_ep *iso_in, struct usb_ep *iso_out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | { |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 213 | disable_ep(cdev, in); |
| 214 | disable_ep(cdev, out); |
Paul Zimmerman | b4036cc | 2012-04-16 14:19:06 -0700 | [diff] [blame] | 215 | if (iso_in) |
| 216 | disable_ep(cdev, iso_in); |
| 217 | if (iso_out) |
| 218 | disable_ep(cdev, iso_out); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /*-------------------------------------------------------------------------*/ |
| 222 | |
David Brownell | ab943a2 | 2009-03-19 14:16:09 -0700 | [diff] [blame] | 223 | static struct timer_list autoresume_timer; |
| 224 | |
| 225 | static void zero_autoresume(unsigned long _c) |
| 226 | { |
| 227 | struct usb_composite_dev *cdev = (void *)_c; |
| 228 | struct usb_gadget *g = cdev->gadget; |
| 229 | |
| 230 | /* unconfigured devices can't issue wakeups */ |
| 231 | if (!cdev->config) |
| 232 | return; |
| 233 | |
| 234 | /* Normally the host would be woken up for something |
| 235 | * more significant than just a timer firing; likely |
| 236 | * because of some direct user request. |
| 237 | */ |
| 238 | if (g->speed != USB_SPEED_UNKNOWN) { |
| 239 | int status = usb_gadget_wakeup(g); |
| 240 | INFO(cdev, "%s --> %d\n", __func__, status); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | static void zero_suspend(struct usb_composite_dev *cdev) |
| 245 | { |
| 246 | if (cdev->gadget->speed == USB_SPEED_UNKNOWN) |
| 247 | return; |
| 248 | |
| 249 | if (autoresume) { |
| 250 | mod_timer(&autoresume_timer, jiffies + (HZ * autoresume)); |
| 251 | DBG(cdev, "suspend, wakeup in %d seconds\n", autoresume); |
| 252 | } else |
| 253 | DBG(cdev, "%s\n", __func__); |
| 254 | } |
| 255 | |
| 256 | static void zero_resume(struct usb_composite_dev *cdev) |
| 257 | { |
| 258 | DBG(cdev, "%s\n", __func__); |
| 259 | del_timer(&autoresume_timer); |
| 260 | } |
| 261 | |
| 262 | /*-------------------------------------------------------------------------*/ |
| 263 | |
Michal Nazarewicz | e12995e | 2010-08-12 17:43:52 +0200 | [diff] [blame] | 264 | static int __init zero_bind(struct usb_composite_dev *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
David Brownell | 91e79c9 | 2005-07-13 15:18:30 -0700 | [diff] [blame] | 266 | int gcnum; |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 267 | struct usb_gadget *gadget = cdev->gadget; |
Sebastian Andrzej Siewior | e1f15cc | 2012-09-06 20:11:16 +0200 | [diff] [blame] | 268 | int status; |
David Brownell | 91e79c9 | 2005-07-13 15:18:30 -0700 | [diff] [blame] | 269 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 270 | /* Allocate string descriptor numbers ... note that string |
| 271 | * contents can be overridden by the composite_dev glue. |
David Brownell | 91e79c9 | 2005-07-13 15:18:30 -0700 | [diff] [blame] | 272 | */ |
Sebastian Andrzej Siewior | e1f15cc | 2012-09-06 20:11:16 +0200 | [diff] [blame] | 273 | status = usb_string_ids_tab(cdev, strings_dev); |
| 274 | if (status < 0) |
| 275 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Sebastian Andrzej Siewior | e1f15cc | 2012-09-06 20:11:16 +0200 | [diff] [blame] | 277 | device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id; |
| 278 | device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id; |
| 279 | device_desc.iSerialNumber = strings_dev[STRING_SERIAL_IDX].id; |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 280 | |
David Brownell | ab943a2 | 2009-03-19 14:16:09 -0700 | [diff] [blame] | 281 | setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev); |
| 282 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 283 | /* Register primary, then secondary configuration. Note that |
| 284 | * SH3 only allows one config... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | */ |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 286 | if (loopdefault) { |
David Brownell | ab943a2 | 2009-03-19 14:16:09 -0700 | [diff] [blame] | 287 | loopback_add(cdev, autoresume != 0); |
Christoph Egger | 90f7976 | 2010-02-05 13:24:12 +0100 | [diff] [blame] | 288 | sourcesink_add(cdev, autoresume != 0); |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 289 | } else { |
David Brownell | ab943a2 | 2009-03-19 14:16:09 -0700 | [diff] [blame] | 290 | sourcesink_add(cdev, autoresume != 0); |
Christoph Egger | 90f7976 | 2010-02-05 13:24:12 +0100 | [diff] [blame] | 291 | loopback_add(cdev, autoresume != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
David Brownell | 7472f38 | 2008-04-18 18:47:54 -0700 | [diff] [blame] | 294 | gcnum = usb_gadget_controller_number(gadget); |
David Brownell | 91e79c9 | 2005-07-13 15:18:30 -0700 | [diff] [blame] | 295 | if (gcnum >= 0) |
David Brownell | 7472f38 | 2008-04-18 18:47:54 -0700 | [diff] [blame] | 296 | device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum); |
David Brownell | 91e79c9 | 2005-07-13 15:18:30 -0700 | [diff] [blame] | 297 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | /* gadget zero is so simple (for now, no altsettings) that |
| 299 | * it SHOULD NOT have problems with bulk-capable hardware. |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 300 | * so just warn about unrcognized controllers -- don't panic. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | * |
| 302 | * things like configuration and altsetting numbering |
| 303 | * can need hardware-specific attention though. |
| 304 | */ |
David Brownell | 0027492 | 2007-11-19 12:58:36 -0800 | [diff] [blame] | 305 | pr_warning("%s: controller '%s' not recognized\n", |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 306 | longname, gadget->name); |
Harvey Harrison | 551509d | 2009-02-11 14:11:36 -0800 | [diff] [blame] | 307 | device_desc.bcdDevice = cpu_to_le16(0x9999); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |
Sebastian Andrzej Siewior | 7d16e8d | 2012-09-10 15:01:53 +0200 | [diff] [blame^] | 309 | usb_composite_overwrite_options(cdev, &coverwrite); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 311 | INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
David Brownell | 7472f38 | 2008-04-18 18:47:54 -0700 | [diff] [blame] | 313 | snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", |
Serge E. Hallyn | 96b644b | 2006-10-02 02:18:13 -0700 | [diff] [blame] | 314 | init_utsname()->sysname, init_utsname()->release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | gadget->name); |
| 316 | |
| 317 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | |
David Brownell | ab943a2 | 2009-03-19 14:16:09 -0700 | [diff] [blame] | 320 | static int zero_unbind(struct usb_composite_dev *cdev) |
| 321 | { |
| 322 | del_timer_sync(&autoresume_timer); |
| 323 | return 0; |
| 324 | } |
| 325 | |
Sebastian Andrzej Siewior | c2ec75c | 2012-09-06 20:11:03 +0200 | [diff] [blame] | 326 | static __refdata struct usb_composite_driver zero_driver = { |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 327 | .name = "zero", |
| 328 | .dev = &device_desc, |
| 329 | .strings = dev_strings, |
Amit Blay | 57c97c0 | 2011-07-03 17:29:31 +0300 | [diff] [blame] | 330 | .max_speed = USB_SPEED_SUPER, |
Sebastian Andrzej Siewior | 03e42bd | 2012-09-06 20:11:04 +0200 | [diff] [blame] | 331 | .bind = zero_bind, |
David Brownell | ab943a2 | 2009-03-19 14:16:09 -0700 | [diff] [blame] | 332 | .unbind = zero_unbind, |
| 333 | .suspend = zero_suspend, |
| 334 | .resume = zero_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | }; |
| 336 | |
David Brownell | ca2bdf4 | 2007-08-02 12:20:05 -0700 | [diff] [blame] | 337 | MODULE_AUTHOR("David Brownell"); |
| 338 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
David Brownell | 7472f38 | 2008-04-18 18:47:54 -0700 | [diff] [blame] | 340 | static int __init init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | { |
Sebastian Andrzej Siewior | 03e42bd | 2012-09-06 20:11:04 +0200 | [diff] [blame] | 342 | return usb_composite_probe(&zero_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
David Brownell | 7472f38 | 2008-04-18 18:47:54 -0700 | [diff] [blame] | 344 | module_init(init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
David Brownell | 7472f38 | 2008-04-18 18:47:54 -0700 | [diff] [blame] | 346 | static void __exit cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
David Brownell | 097db1d | 2008-06-19 18:18:27 -0700 | [diff] [blame] | 348 | usb_composite_unregister(&zero_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
David Brownell | 7472f38 | 2008-04-18 18:47:54 -0700 | [diff] [blame] | 350 | module_exit(cleanup); |