blob: 0dd07ae1555ddf066312e0ff4e8182a02f27a3d6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * zero.c -- Gadget Zero, for USB development
3 *
David Brownell097db1d2008-06-19 18:18:27 -07004 * Copyright (C) 2003-2008 David Brownell
5 * Copyright (C) 2008 by Nokia Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
David Brownellca2bdf42007-08-02 12:20:05 -07007 * 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 Torvalds1da177e2005-04-16 15:20:36 -070011 */
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013/*
14 * Gadget Zero only needs two bulk endpoints, and is an example of how you
15 * can write a hardware-agnostic gadget driver running inside a USB device.
David Brownell7472f382008-04-18 18:47:54 -070016 * Some hardware details are visible, but don't affect most of the driver.
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 *
18 * Use it with the Linux host/master side "usbtest" driver to get a basic
19 * functional test of your device-side usb stack, or with "usb-skeleton".
20 *
21 * It supports two similar configurations. One sinks whatever the usb host
22 * writes, and in return sources zeroes. The other loops whatever the host
David Brownell097db1d2008-06-19 18:18:27 -070023 * writes back, so the host can read it.
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 *
25 * Many drivers will only have one configuration, letting them be much
26 * simpler if they also don't support high speed operation (like this
27 * driver does).
David Brownellca2bdf42007-08-02 12:20:05 -070028 *
29 * Why is *this* driver using two configurations, rather than setting up
30 * two interfaces with different functions? To help verify that multiple
31 * configuration infrastucture is working correctly; also, so that it can
32 * work with low capability USB controllers without four bulk endpoints.
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 */
34
David Brownell097db1d2008-06-19 18:18:27 -070035/*
36 * driver assumes self-powered hardware, and
37 * has no way for users to trigger remote wakeup.
38 */
39
David Brownellca2bdf42007-08-02 12:20:05 -070040/* #define VERBOSE_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090043#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/device.h>
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +010045#include <linux/module.h>
46#include <linux/err.h>
47#include <linux/usb/composite.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
David Brownell097db1d2008-06-19 18:18:27 -070049#include "g_zero.h"
David Brownell7e75bc02008-08-18 17:41:31 -070050/*-------------------------------------------------------------------------*/
Sebastian Andrzej Siewior7d16e8d2012-09-10 15:01:53 +020051USB_GADGET_COMPOSITE_OPTIONS();
David Brownell7e75bc02008-08-18 17:41:31 -070052
David Brownell097db1d2008-06-19 18:18:27 -070053#define DRIVER_VERSION "Cinco de Mayo 2008"
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
David Brownell7472f382008-04-18 18:47:54 -070055static const char longname[] = "Gadget Zero";
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/*
58 * Normally the "loopback" configuration is second (index 1) so
59 * it's not the default. Here's where to change that order, to
David Brownell097db1d2008-06-19 18:18:27 -070060 * work better with hosts where config changes are problematic or
61 * controllers (like original superh) that only support one config.
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 */
Rusty Russell90ab5ee2012-01-13 09:32:20 +103063static bool loopdefault = 0;
David Brownell7472f382008-04-18 18:47:54 -070064module_param(loopdefault, bool, S_IRUGO|S_IWUSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Felipe Balbi38b3ad52013-01-18 13:18:44 +020066static struct usb_zero_options gzero_options = {
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +010067 .isoc_interval = 4,
68 .isoc_maxpacket = 1024,
69 .bulk_buflen = 4096,
70 .qlen = 32,
71};
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/*-------------------------------------------------------------------------*/
74
75/* Thanks to NetChip Technologies for donating this product ID.
76 *
77 * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
78 * Instead: allocate your own, using normal USB-IF procedures.
79 */
80#ifndef CONFIG_USB_ZERO_HNPTEST
81#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
82#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
David Brownellab943a22009-03-19 14:16:09 -070083#define DEFAULT_AUTORESUME 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#else
85#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
86#define DRIVER_PRODUCT_NUM 0xbadd
David Brownellab943a22009-03-19 14:16:09 -070087#define DEFAULT_AUTORESUME 5
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#endif
89
David Brownellab943a22009-03-19 14:16:09 -070090/* If the optional "autoresume" mode is enabled, it provides good
91 * functional coverage for the "USBCV" test harness from USB-IF.
92 * It's always set if OTG mode is enabled.
93 */
94unsigned autoresume = DEFAULT_AUTORESUME;
95module_param(autoresume, uint, S_IRUGO);
96MODULE_PARM_DESC(autoresume, "zero, or seconds before remote wakeup");
97
Peter Chen36ed03f2013-09-09 16:48:29 +080098/* Maximum Autoresume time */
99unsigned max_autoresume;
100module_param(max_autoresume, uint, S_IRUGO);
101MODULE_PARM_DESC(max_autoresume, "maximum seconds before remote wakeup");
102
103/* Interval between two remote wakeups */
104unsigned autoresume_interval_ms;
105module_param(autoresume_interval_ms, uint, S_IRUGO);
106MODULE_PARM_DESC(autoresume_interval_ms,
107 "milliseconds to increase successive wakeup delays");
108
109static unsigned autoresume_step_ms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110/*-------------------------------------------------------------------------*/
111
David Brownell7472f382008-04-18 18:47:54 -0700112static struct usb_device_descriptor device_desc = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 .bLength = sizeof device_desc,
114 .bDescriptorType = USB_DT_DEVICE,
115
Harvey Harrison551509d2009-02-11 14:11:36 -0800116 .bcdUSB = cpu_to_le16(0x0200),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
118
Harvey Harrison551509d2009-02-11 14:11:36 -0800119 .idVendor = cpu_to_le16(DRIVER_VENDOR_NUM),
120 .idProduct = cpu_to_le16(DRIVER_PRODUCT_NUM),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 .bNumConfigurations = 2,
122};
123
David Brownell097db1d2008-06-19 18:18:27 -0700124#ifdef CONFIG_USB_OTG
David Brownell7472f382008-04-18 18:47:54 -0700125static struct usb_otg_descriptor otg_descriptor = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 .bLength = sizeof otg_descriptor,
127 .bDescriptorType = USB_DT_OTG,
128
David Brownell097db1d2008-06-19 18:18:27 -0700129 /* REVISIT SRP-only hardware is possible, although
130 * it would not be called "OTG" ...
131 */
132 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133};
134
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100135static const struct usb_descriptor_header *otg_desc[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 (struct usb_descriptor_header *) &otg_descriptor,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 NULL,
138};
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100139#else
140#define otg_desc NULL
David Brownell097db1d2008-06-19 18:18:27 -0700141#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
David Brownell097db1d2008-06-19 18:18:27 -0700143/* string IDs are assigned dynamically */
David Brownellca2bdf42007-08-02 12:20:05 -0700144/* default serial number takes at least two packets */
145static char serial[] = "0123456789.0123456789.0123456789";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Sebastian Andrzej Siewioreeae5402012-12-23 21:09:58 +0100147#define USB_GZERO_SS_DESC (USB_GADGET_FIRST_AVAIL_IDX + 0)
Sebastian Andrzej Siewior78f46f02012-12-23 21:09:59 +0100148#define USB_GZERO_LB_DESC (USB_GADGET_FIRST_AVAIL_IDX + 1)
Sebastian Andrzej Siewioreeae5402012-12-23 21:09:58 +0100149
David Brownell097db1d2008-06-19 18:18:27 -0700150static struct usb_string strings_dev[] = {
Sebastian Andrzej Siewiorcc2683c2012-09-10 15:01:58 +0200151 [USB_GADGET_MANUFACTURER_IDX].s = "",
Sebastian Andrzej Siewior276e2e42012-09-06 20:11:21 +0200152 [USB_GADGET_PRODUCT_IDX].s = longname,
153 [USB_GADGET_SERIAL_IDX].s = serial,
Sebastian Andrzej Siewioreeae5402012-12-23 21:09:58 +0100154 [USB_GZERO_SS_DESC].s = "source and sink data",
Sebastian Andrzej Siewior78f46f02012-12-23 21:09:59 +0100155 [USB_GZERO_LB_DESC].s = "loop input to output",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 { } /* end of list */
157};
158
David Brownell097db1d2008-06-19 18:18:27 -0700159static struct usb_gadget_strings stringtab_dev = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 .language = 0x0409, /* en-us */
David Brownell097db1d2008-06-19 18:18:27 -0700161 .strings = strings_dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162};
163
David Brownell097db1d2008-06-19 18:18:27 -0700164static struct usb_gadget_strings *dev_strings[] = {
165 &stringtab_dev,
166 NULL,
167};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169/*-------------------------------------------------------------------------*/
170
David Brownellab943a22009-03-19 14:16:09 -0700171static struct timer_list autoresume_timer;
172
173static void zero_autoresume(unsigned long _c)
174{
175 struct usb_composite_dev *cdev = (void *)_c;
176 struct usb_gadget *g = cdev->gadget;
177
178 /* unconfigured devices can't issue wakeups */
179 if (!cdev->config)
180 return;
181
182 /* Normally the host would be woken up for something
183 * more significant than just a timer firing; likely
184 * because of some direct user request.
185 */
186 if (g->speed != USB_SPEED_UNKNOWN) {
187 int status = usb_gadget_wakeup(g);
188 INFO(cdev, "%s --> %d\n", __func__, status);
189 }
190}
191
192static void zero_suspend(struct usb_composite_dev *cdev)
193{
194 if (cdev->gadget->speed == USB_SPEED_UNKNOWN)
195 return;
196
197 if (autoresume) {
Peter Chen36ed03f2013-09-09 16:48:29 +0800198 if (max_autoresume &&
199 (autoresume_step_ms > max_autoresume * 1000))
200 autoresume_step_ms = autoresume * 1000;
201
202 mod_timer(&autoresume_timer, jiffies +
203 msecs_to_jiffies(autoresume_step_ms));
204 DBG(cdev, "suspend, wakeup in %d milliseconds\n",
205 autoresume_step_ms);
206
207 autoresume_step_ms += autoresume_interval_ms;
David Brownellab943a22009-03-19 14:16:09 -0700208 } else
209 DBG(cdev, "%s\n", __func__);
210}
211
212static void zero_resume(struct usb_composite_dev *cdev)
213{
214 DBG(cdev, "%s\n", __func__);
215 del_timer(&autoresume_timer);
216}
217
218/*-------------------------------------------------------------------------*/
219
Sebastian Andrzej Siewior78f46f02012-12-23 21:09:59 +0100220static struct usb_configuration loopback_driver = {
221 .label = "loopback",
Sebastian Andrzej Siewior78f46f02012-12-23 21:09:59 +0100222 .bConfigurationValue = 2,
223 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
224 /* .iConfiguration = DYNAMIC */
225};
226
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100227static struct usb_function *func_ss;
228static struct usb_function_instance *func_inst_ss;
229
230static int ss_config_setup(struct usb_configuration *c,
231 const struct usb_ctrlrequest *ctrl)
232{
233 switch (ctrl->bRequest) {
234 case 0x5b:
235 case 0x5c:
236 return func_ss->setup(func_ss, ctrl);
237 default:
238 return -EOPNOTSUPP;
239 }
240}
241
Sebastian Andrzej Siewioreeae5402012-12-23 21:09:58 +0100242static struct usb_configuration sourcesink_driver = {
243 .label = "source/sink",
Sebastian Andrzej Siewioreeae5402012-12-23 21:09:58 +0100244 .setup = ss_config_setup,
245 .bConfigurationValue = 3,
246 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
247 /* .iConfiguration = DYNAMIC */
248};
249
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100250module_param_named(buflen, gzero_options.bulk_buflen, uint, 0);
251module_param_named(pattern, gzero_options.pattern, uint, S_IRUGO|S_IWUSR);
252MODULE_PARM_DESC(pattern, "0 = all zeroes, 1 = mod63, 2 = none");
253
254module_param_named(isoc_interval, gzero_options.isoc_interval, uint,
255 S_IRUGO|S_IWUSR);
256MODULE_PARM_DESC(isoc_interval, "1 - 16");
257
258module_param_named(isoc_maxpacket, gzero_options.isoc_maxpacket, uint,
259 S_IRUGO|S_IWUSR);
260MODULE_PARM_DESC(isoc_maxpacket, "0 - 1023 (fs), 0 - 1024 (hs/ss)");
261
262module_param_named(isoc_mult, gzero_options.isoc_mult, uint, S_IRUGO|S_IWUSR);
263MODULE_PARM_DESC(isoc_mult, "0 - 2 (hs/ss only)");
264
265module_param_named(isoc_maxburst, gzero_options.isoc_maxburst, uint,
266 S_IRUGO|S_IWUSR);
267MODULE_PARM_DESC(isoc_maxburst, "0 - 15 (ss only)");
268
269static struct usb_function *func_lb;
270static struct usb_function_instance *func_inst_lb;
271
272module_param_named(qlen, gzero_options.qlen, uint, S_IRUGO|S_IWUSR);
273MODULE_PARM_DESC(qlen, "depth of loopback queue");
274
Michal Nazarewicze12995e2010-08-12 17:43:52 +0200275static int __init zero_bind(struct usb_composite_dev *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100277 struct f_ss_opts *ss_opts;
278 struct f_lb_opts *lb_opts;
Sebastian Andrzej Siewiore1f15cc2012-09-06 20:11:16 +0200279 int status;
David Brownell91e79c92005-07-13 15:18:30 -0700280
David Brownell097db1d2008-06-19 18:18:27 -0700281 /* Allocate string descriptor numbers ... note that string
282 * contents can be overridden by the composite_dev glue.
David Brownell91e79c92005-07-13 15:18:30 -0700283 */
Sebastian Andrzej Siewiore1f15cc2012-09-06 20:11:16 +0200284 status = usb_string_ids_tab(cdev, strings_dev);
285 if (status < 0)
286 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Sebastian Andrzej Siewior276e2e42012-09-06 20:11:21 +0200288 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
289 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
290 device_desc.iSerialNumber = strings_dev[USB_GADGET_SERIAL_IDX].id;
David Brownell097db1d2008-06-19 18:18:27 -0700291
David Brownellab943a22009-03-19 14:16:09 -0700292 setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev);
293
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100294 func_inst_ss = usb_get_function_instance("SourceSink");
295 if (IS_ERR(func_inst_ss))
296 return PTR_ERR(func_inst_ss);
297
298 ss_opts = container_of(func_inst_ss, struct f_ss_opts, func_inst);
299 ss_opts->pattern = gzero_options.pattern;
300 ss_opts->isoc_interval = gzero_options.isoc_interval;
301 ss_opts->isoc_maxpacket = gzero_options.isoc_maxpacket;
302 ss_opts->isoc_mult = gzero_options.isoc_mult;
303 ss_opts->isoc_maxburst = gzero_options.isoc_maxpacket;
304 ss_opts->bulk_buflen = gzero_options.bulk_buflen;
305
306 func_ss = usb_get_function(func_inst_ss);
Wei Yongjunc8c18882013-04-25 17:29:05 +0800307 if (IS_ERR(func_ss)) {
308 status = PTR_ERR(func_ss);
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100309 goto err_put_func_inst_ss;
Wei Yongjunc8c18882013-04-25 17:29:05 +0800310 }
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100311
312 func_inst_lb = usb_get_function_instance("Loopback");
Wei Yongjunc8c18882013-04-25 17:29:05 +0800313 if (IS_ERR(func_inst_lb)) {
314 status = PTR_ERR(func_inst_lb);
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100315 goto err_put_func_ss;
Wei Yongjunc8c18882013-04-25 17:29:05 +0800316 }
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100317
318 lb_opts = container_of(func_inst_lb, struct f_lb_opts, func_inst);
319 lb_opts->bulk_buflen = gzero_options.bulk_buflen;
320 lb_opts->qlen = gzero_options.qlen;
321
322 func_lb = usb_get_function(func_inst_lb);
323 if (IS_ERR(func_lb)) {
324 status = PTR_ERR(func_lb);
325 goto err_put_func_inst_lb;
326 }
327
Sebastian Andrzej Siewioreeae5402012-12-23 21:09:58 +0100328 sourcesink_driver.iConfiguration = strings_dev[USB_GZERO_SS_DESC].id;
Sebastian Andrzej Siewior78f46f02012-12-23 21:09:59 +0100329 loopback_driver.iConfiguration = strings_dev[USB_GZERO_LB_DESC].id;
330
Sebastian Andrzej Siewioreeae5402012-12-23 21:09:58 +0100331 /* support autoresume for remote wakeup testing */
332 sourcesink_driver.bmAttributes &= ~USB_CONFIG_ATT_WAKEUP;
Sebastian Andrzej Siewior78f46f02012-12-23 21:09:59 +0100333 loopback_driver.bmAttributes &= ~USB_CONFIG_ATT_WAKEUP;
Sebastian Andrzej Siewioreeae5402012-12-23 21:09:58 +0100334 sourcesink_driver.descriptors = NULL;
Sebastian Andrzej Siewior78f46f02012-12-23 21:09:59 +0100335 loopback_driver.descriptors = NULL;
336 if (autoresume) {
Sebastian Andrzej Siewioreeae5402012-12-23 21:09:58 +0100337 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
Sebastian Andrzej Siewior78f46f02012-12-23 21:09:59 +0100338 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
Peter Chen36ed03f2013-09-09 16:48:29 +0800339 autoresume_step_ms = autoresume * 1000;
Sebastian Andrzej Siewior78f46f02012-12-23 21:09:59 +0100340 }
Sebastian Andrzej Siewioreeae5402012-12-23 21:09:58 +0100341
342 /* support OTG systems */
343 if (gadget_is_otg(cdev->gadget)) {
344 sourcesink_driver.descriptors = otg_desc;
345 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
Sebastian Andrzej Siewior78f46f02012-12-23 21:09:59 +0100346 loopback_driver.descriptors = otg_desc;
347 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
Sebastian Andrzej Siewioreeae5402012-12-23 21:09:58 +0100348 }
349
David Brownell097db1d2008-06-19 18:18:27 -0700350 /* Register primary, then secondary configuration. Note that
351 * SH3 only allows one config...
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 */
David Brownell097db1d2008-06-19 18:18:27 -0700353 if (loopdefault) {
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100354 usb_add_config_only(cdev, &loopback_driver);
355 usb_add_config_only(cdev, &sourcesink_driver);
David Brownell097db1d2008-06-19 18:18:27 -0700356 } else {
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100357 usb_add_config_only(cdev, &sourcesink_driver);
358 usb_add_config_only(cdev, &loopback_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 }
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100360 status = usb_add_function(&sourcesink_driver, func_ss);
361 if (status)
362 goto err_conf_flb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100364 usb_ep_autoconfig_reset(cdev->gadget);
365 status = usb_add_function(&loopback_driver, func_lb);
366 if (status)
367 goto err_conf_flb;
368
369 usb_ep_autoconfig_reset(cdev->gadget);
Sebastian Andrzej Siewior7d16e8d2012-09-10 15:01:53 +0200370 usb_composite_overwrite_options(cdev, &coverwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
David Brownell097db1d2008-06-19 18:18:27 -0700372 INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 return 0;
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100375
376err_conf_flb:
377 usb_put_function(func_lb);
378 func_lb = NULL;
379err_put_func_inst_lb:
380 usb_put_function_instance(func_inst_lb);
381 func_inst_lb = NULL;
382err_put_func_ss:
383 usb_put_function(func_ss);
384 func_ss = NULL;
385err_put_func_inst_ss:
386 usb_put_function_instance(func_inst_ss);
387 func_inst_ss = NULL;
388 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
390
David Brownellab943a22009-03-19 14:16:09 -0700391static int zero_unbind(struct usb_composite_dev *cdev)
392{
393 del_timer_sync(&autoresume_timer);
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100394 if (!IS_ERR_OR_NULL(func_ss))
395 usb_put_function(func_ss);
Andrzej Pietrasiewiczabe7a402013-04-18 14:43:26 +0200396 usb_put_function_instance(func_inst_ss);
Sebastian Andrzej Siewiorcf9a08a2012-12-23 21:10:01 +0100397 if (!IS_ERR_OR_NULL(func_lb))
398 usb_put_function(func_lb);
Andrzej Pietrasiewiczabe7a402013-04-18 14:43:26 +0200399 usb_put_function_instance(func_inst_lb);
David Brownellab943a22009-03-19 14:16:09 -0700400 return 0;
401}
402
Sebastian Andrzej Siewiorc2ec75c2012-09-06 20:11:03 +0200403static __refdata struct usb_composite_driver zero_driver = {
David Brownell097db1d2008-06-19 18:18:27 -0700404 .name = "zero",
405 .dev = &device_desc,
406 .strings = dev_strings,
Amit Blay57c97c02011-07-03 17:29:31 +0300407 .max_speed = USB_SPEED_SUPER,
Sebastian Andrzej Siewior03e42bd2012-09-06 20:11:04 +0200408 .bind = zero_bind,
David Brownellab943a22009-03-19 14:16:09 -0700409 .unbind = zero_unbind,
410 .suspend = zero_suspend,
411 .resume = zero_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412};
413
David Brownellca2bdf42007-08-02 12:20:05 -0700414MODULE_AUTHOR("David Brownell");
415MODULE_LICENSE("GPL");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
David Brownell7472f382008-04-18 18:47:54 -0700417static int __init init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
Sebastian Andrzej Siewior03e42bd2012-09-06 20:11:04 +0200419 return usb_composite_probe(&zero_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
David Brownell7472f382008-04-18 18:47:54 -0700421module_init(init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
David Brownell7472f382008-04-18 18:47:54 -0700423static void __exit cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
David Brownell097db1d2008-06-19 18:18:27 -0700425 usb_composite_unregister(&zero_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426}
David Brownell7472f382008-04-18 18:47:54 -0700427module_exit(cleanup);