blob: 940f6cde8e8988089fc9dbd18854a79d3fb4d245 [file] [log] [blame]
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +01001/*
2 * multi.c -- Multifunction Composite driver
3 *
4 * Copyright (C) 2008 David Brownell
5 * Copyright (C) 2008 Nokia Corporation
6 * Copyright (C) 2009 Samsung Electronics
Michal Nazarewicz54b83602012-01-13 15:05:16 +01007 * Author: Michal Nazarewicz (mina86@mina86.com)
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +01008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +010013 */
14
15
16#include <linux/kernel.h>
Michal Nazarewicz279cc492010-06-21 13:57:03 +020017#include <linux/module.h>
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +020018#include <linux/netdevice.h>
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +010019
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +010020#include "u_serial.h"
Michal Nazarewicz396cda92009-11-30 10:55:40 +010021#if defined USB_ETH_RNDIS
22# undef USB_ETH_RNDIS
23#endif
Michal Nazarewiczdbe4a992010-01-22 15:18:21 +010024#ifdef CONFIG_USB_G_MULTI_RNDIS
Michal Nazarewicz396cda92009-11-30 10:55:40 +010025# define USB_ETH_RNDIS y
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +010026#endif
27
28
29#define DRIVER_DESC "Multifunction Composite Gadget"
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +010030
Michal Nazarewicz279cc492010-06-21 13:57:03 +020031MODULE_DESCRIPTION(DRIVER_DESC);
32MODULE_AUTHOR("Michal Nazarewicz");
33MODULE_LICENSE("GPL");
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +010034
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +010035
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +020036#include "f_mass_storage.h"
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +010037
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +020038#include "u_ecm.h"
Michal Nazarewicz396cda92009-11-30 10:55:40 +010039#ifdef USB_ETH_RNDIS
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +020040# include "u_rndis.h"
Andrzej Pietrasiewiczcbbd14a2013-05-24 10:23:02 +020041# include "rndis.h"
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +010042#endif
Andrzej Pietrasiewiczf1a18232013-05-23 09:22:03 +020043#include "u_ether.h"
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +010044
Sebastian Andrzej Siewior7d16e8d2012-09-10 15:01:53 +020045USB_GADGET_COMPOSITE_OPTIONS();
Michal Nazarewicz279cc492010-06-21 13:57:03 +020046
Andrzej Pietrasiewiczf1a18232013-05-23 09:22:03 +020047USB_ETHERNET_MODULE_PARAMETERS();
48
Michal Nazarewicz279cc492010-06-21 13:57:03 +020049/***************************** Device Descriptor ****************************/
50
Michal Nazarewicz1c6529e2010-08-12 17:43:44 +020051#define MULTI_VENDOR_NUM 0x1d6b /* Linux Foundation */
52#define MULTI_PRODUCT_NUM 0x0104 /* Multifunction Composite Gadget */
Michal Nazarewicz279cc492010-06-21 13:57:03 +020053
54
55enum {
56 __MULTI_NO_CONFIG,
57#ifdef CONFIG_USB_G_MULTI_RNDIS
58 MULTI_RNDIS_CONFIG_NUM,
59#endif
60#ifdef CONFIG_USB_G_MULTI_CDC
61 MULTI_CDC_CONFIG_NUM,
62#endif
63};
64
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +010065
66static struct usb_device_descriptor device_desc = {
67 .bLength = sizeof device_desc,
68 .bDescriptorType = USB_DT_DEVICE,
69
70 .bcdUSB = cpu_to_le16(0x0200),
71
Michal Nazarewicz279cc492010-06-21 13:57:03 +020072 .bDeviceClass = USB_CLASS_MISC /* 0xEF */,
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +010073 .bDeviceSubClass = 2,
74 .bDeviceProtocol = 1,
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +010075
76 /* Vendor and product id can be overridden by module parameters. */
77 .idVendor = cpu_to_le16(MULTI_VENDOR_NUM),
78 .idProduct = cpu_to_le16(MULTI_PRODUCT_NUM),
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +010079};
80
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +010081
82static const struct usb_descriptor_header *otg_desc[] = {
Michal Nazarewicz279cc492010-06-21 13:57:03 +020083 (struct usb_descriptor_header *) &(struct usb_otg_descriptor){
84 .bLength = sizeof(struct usb_otg_descriptor),
85 .bDescriptorType = USB_DT_OTG,
86
87 /*
88 * REVISIT SRP-only hardware is possible, although
89 * it would not be called "OTG" ...
90 */
91 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
92 },
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +010093 NULL,
94};
95
96
Michal Nazarewicz279cc492010-06-21 13:57:03 +020097enum {
Sebastian Andrzej Siewior276e2e42012-09-06 20:11:21 +020098 MULTI_STRING_RNDIS_CONFIG_IDX = USB_GADGET_FIRST_AVAIL_IDX,
Michal Nazarewicz279cc492010-06-21 13:57:03 +020099 MULTI_STRING_CDC_CONFIG_IDX,
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200100};
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100101
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100102static struct usb_string strings_dev[] = {
Sebastian Andrzej Siewior276e2e42012-09-06 20:11:21 +0200103 [USB_GADGET_MANUFACTURER_IDX].s = "",
Sebastian Andrzej Siewiord33f74f2012-09-10 15:01:57 +0200104 [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
Sebastian Andrzej Siewior276e2e42012-09-06 20:11:21 +0200105 [USB_GADGET_SERIAL_IDX].s = "",
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200106 [MULTI_STRING_RNDIS_CONFIG_IDX].s = "Multifunction with RNDIS",
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200107 [MULTI_STRING_CDC_CONFIG_IDX].s = "Multifunction with CDC ECM",
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100108 { } /* end of list */
109};
110
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100111static struct usb_gadget_strings *dev_strings[] = {
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200112 &(struct usb_gadget_strings){
113 .language = 0x0409, /* en-us */
114 .strings = strings_dev,
115 },
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100116 NULL,
117};
118
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100119
120
121
122/****************************** Configurations ******************************/
123
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200124static struct fsg_module_parameters fsg_mod_data = { .stall = 1 };
Andrzej Pietrasiewicz6fdc5dd2013-09-26 14:38:16 +0200125#ifdef CONFIG_USB_GADGET_DEBUG_FILES
126
127static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
128
129#else
130
131/*
132 * Number of buffers we will use.
133 * 2 is usually enough for good buffering pipeline
134 */
135#define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
136
Greg Kroah-Hartman0c8b1992013-12-19 15:43:10 -0800137#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
Andrzej Pietrasiewicz6fdc5dd2013-09-26 14:38:16 +0200138
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200139FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100140
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100141static struct usb_function_instance *fi_acm;
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200142static struct usb_function_instance *fi_msg;
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200143
144/********** RNDIS **********/
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100145
Michal Nazarewicz396cda92009-11-30 10:55:40 +0100146#ifdef USB_ETH_RNDIS
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200147static struct usb_function_instance *fi_rndis;
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100148static struct usb_function *f_acm_rndis;
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200149static struct usb_function *f_rndis;
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200150static struct usb_function *f_msg_rndis;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100151
Uwe Kleine-Königc9bfff92010-08-12 17:43:55 +0200152static __init int rndis_do_config(struct usb_configuration *c)
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100153{
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200154 struct fsg_opts *fsg_opts;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100155 int ret;
156
157 if (gadget_is_otg(c->cdev->gadget)) {
158 c->descriptors = otg_desc;
159 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
160 }
161
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200162 f_rndis = usb_get_function(fi_rndis);
163 if (IS_ERR(f_rndis))
164 return PTR_ERR(f_rndis);
165
166 ret = usb_add_function(c, f_rndis);
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100167 if (ret < 0)
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200168 goto err_func_rndis;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100169
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100170 f_acm_rndis = usb_get_function(fi_acm);
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200171 if (IS_ERR(f_acm_rndis)) {
172 ret = PTR_ERR(f_acm_rndis);
173 goto err_func_acm;
174 }
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100175
176 ret = usb_add_function(c, f_acm_rndis);
177 if (ret)
178 goto err_conf;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100179
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200180 f_msg_rndis = usb_get_function(fi_msg);
181 if (IS_ERR(f_msg_rndis)) {
182 ret = PTR_ERR(f_msg_rndis);
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100183 goto err_fsg;
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200184 }
185
186 fsg_opts = fsg_opts_from_func_inst(fi_msg);
187 ret = fsg_common_run_thread(fsg_opts->common);
188 if (ret)
189 goto err_run;
190
191 ret = usb_add_function(c, f_msg_rndis);
192 if (ret)
193 goto err_run;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100194
195 return 0;
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200196err_run:
197 usb_put_function(f_msg_rndis);
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100198err_fsg:
199 usb_remove_function(c, f_acm_rndis);
200err_conf:
201 usb_put_function(f_acm_rndis);
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200202err_func_acm:
203 usb_remove_function(c, f_rndis);
204err_func_rndis:
205 usb_put_function(f_rndis);
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100206 return ret;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100207}
208
Chen Gang780cc0f2013-09-02 18:14:42 +0800209static __ref int rndis_config_register(struct usb_composite_dev *cdev)
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200210{
211 static struct usb_configuration config = {
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200212 .bConfigurationValue = MULTI_RNDIS_CONFIG_NUM,
213 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
214 };
215
216 config.label = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].s;
217 config.iConfiguration = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].id;
218
Uwe Kleine-Königc9bfff92010-08-12 17:43:55 +0200219 return usb_add_config(cdev, &config, rndis_do_config);
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200220}
221
222#else
223
Chen Gang780cc0f2013-09-02 18:14:42 +0800224static __ref int rndis_config_register(struct usb_composite_dev *cdev)
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200225{
226 return 0;
227}
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100228
229#endif
230
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200231
232/********** CDC ECM **********/
233
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100234#ifdef CONFIG_USB_G_MULTI_CDC
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200235static struct usb_function_instance *fi_ecm;
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100236static struct usb_function *f_acm_multi;
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200237static struct usb_function *f_ecm;
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200238static struct usb_function *f_msg_multi;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100239
Uwe Kleine-Königc9bfff92010-08-12 17:43:55 +0200240static __init int cdc_do_config(struct usb_configuration *c)
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100241{
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200242 struct fsg_opts *fsg_opts;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100243 int ret;
244
245 if (gadget_is_otg(c->cdev->gadget)) {
246 c->descriptors = otg_desc;
247 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
248 }
249
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200250 f_ecm = usb_get_function(fi_ecm);
251 if (IS_ERR(f_ecm))
252 return PTR_ERR(f_ecm);
253
254 ret = usb_add_function(c, f_ecm);
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100255 if (ret < 0)
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200256 goto err_func_ecm;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100257
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100258 /* implicit port_num is zero */
259 f_acm_multi = usb_get_function(fi_acm);
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200260 if (IS_ERR(f_acm_multi)) {
261 ret = PTR_ERR(f_acm_multi);
262 goto err_func_acm;
263 }
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100264
265 ret = usb_add_function(c, f_acm_multi);
266 if (ret)
267 goto err_conf;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100268
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200269 f_msg_multi = usb_get_function(fi_msg);
270 if (IS_ERR(f_msg_multi)) {
271 ret = PTR_ERR(f_msg_multi);
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100272 goto err_fsg;
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200273 }
274
275 fsg_opts = fsg_opts_from_func_inst(fi_msg);
276 ret = fsg_common_run_thread(fsg_opts->common);
277 if (ret)
278 goto err_run;
279
280 ret = usb_add_function(c, f_msg_multi);
281 if (ret)
282 goto err_run;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100283
284 return 0;
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200285err_run:
286 usb_put_function(f_msg_multi);
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100287err_fsg:
288 usb_remove_function(c, f_acm_multi);
289err_conf:
290 usb_put_function(f_acm_multi);
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200291err_func_acm:
292 usb_remove_function(c, f_ecm);
293err_func_ecm:
294 usb_put_function(f_ecm);
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100295 return ret;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100296}
297
Chen Gang780cc0f2013-09-02 18:14:42 +0800298static __ref int cdc_config_register(struct usb_composite_dev *cdev)
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200299{
300 static struct usb_configuration config = {
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200301 .bConfigurationValue = MULTI_CDC_CONFIG_NUM,
302 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
303 };
304
305 config.label = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].s;
306 config.iConfiguration = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].id;
307
Uwe Kleine-Königc9bfff92010-08-12 17:43:55 +0200308 return usb_add_config(cdev, &config, cdc_do_config);
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200309}
310
311#else
312
Chen Gang780cc0f2013-09-02 18:14:42 +0800313static __ref int cdc_config_register(struct usb_composite_dev *cdev)
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200314{
315 return 0;
316}
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100317
318#endif
319
320
321
322/****************************** Gadget Bind ******************************/
323
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200324static int __ref multi_bind(struct usb_composite_dev *cdev)
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100325{
326 struct usb_gadget *gadget = cdev->gadget;
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200327#ifdef CONFIG_USB_G_MULTI_CDC
328 struct f_ecm_opts *ecm_opts;
329#endif
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200330#ifdef USB_ETH_RNDIS
331 struct f_rndis_opts *rndis_opts;
332#endif
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200333 struct fsg_opts *fsg_opts;
334 struct fsg_config config;
Sebastian Andrzej Siewiored9cbda2012-09-10 09:16:07 +0200335 int status;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100336
337 if (!can_support_ecm(cdev->gadget)) {
338 dev_err(&gadget->dev, "controller '%s' not usable\n",
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200339 gadget->name);
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100340 return -EINVAL;
341 }
342
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200343#ifdef CONFIG_USB_G_MULTI_CDC
344 fi_ecm = usb_get_function_instance("ecm");
345 if (IS_ERR(fi_ecm))
346 return PTR_ERR(fi_ecm);
347
348 ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst);
349
350 gether_set_qmult(ecm_opts->net, qmult);
351 if (!gether_set_host_addr(ecm_opts->net, host_addr))
352 pr_info("using host ethernet address: %s", host_addr);
353 if (!gether_set_dev_addr(ecm_opts->net, dev_addr))
354 pr_info("using self ethernet address: %s", dev_addr);
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200355#endif
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200356
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200357#ifdef USB_ETH_RNDIS
358 fi_rndis = usb_get_function_instance("rndis");
359 if (IS_ERR(fi_rndis)) {
360 status = PTR_ERR(fi_rndis);
361 goto fail;
362 }
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200363
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200364 rndis_opts = container_of(fi_rndis, struct f_rndis_opts, func_inst);
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200365
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200366 gether_set_qmult(rndis_opts->net, qmult);
367 if (!gether_set_host_addr(rndis_opts->net, host_addr))
368 pr_info("using host ethernet address: %s", host_addr);
369 if (!gether_set_dev_addr(rndis_opts->net, dev_addr))
370 pr_info("using self ethernet address: %s", dev_addr);
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200371#endif
372
373#if (defined CONFIG_USB_G_MULTI_CDC && defined USB_ETH_RNDIS)
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200374 /*
375 * If both ecm and rndis are selected then:
376 * 1) rndis borrows the net interface from ecm
377 * 2) since the interface is shared it must not be bound
378 * twice - in ecm's _and_ rndis' binds, so do it here.
379 */
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200380 gether_set_gadget(ecm_opts->net, cdev->gadget);
381 status = gether_register_netdev(ecm_opts->net);
382 if (status)
383 goto fail0;
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200384
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200385 rndis_borrow_net(fi_rndis, ecm_opts->net);
386 ecm_opts->bound = true;
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200387#endif
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100388
389 /* set up serial link layer */
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100390 fi_acm = usb_get_function_instance("acm");
391 if (IS_ERR(fi_acm)) {
392 status = PTR_ERR(fi_acm);
Sebastian Andrzej Siewiorc4ed4ac2012-12-23 21:10:18 +0100393 goto fail0;
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100394 }
395
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100396 /* set up mass storage function */
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200397 fi_msg = usb_get_function_instance("mass_storage");
398 if (IS_ERR(fi_msg)) {
399 status = PTR_ERR(fi_msg);
400 goto fail1;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100401 }
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200402 fsg_config_from_params(&config, &fsg_mod_data, fsg_num_buffers);
403 fsg_opts = fsg_opts_from_func_inst(fi_msg);
404
405 fsg_opts->no_configfs = true;
406 status = fsg_common_set_num_buffers(fsg_opts->common, fsg_num_buffers);
407 if (status)
408 goto fail2;
409
410 status = fsg_common_set_nluns(fsg_opts->common, config.nluns);
411 if (status)
412 goto fail_set_nluns;
413
414 status = fsg_common_set_cdev(fsg_opts->common, cdev, config.can_stall);
415 if (status)
416 goto fail_set_cdev;
417
418 fsg_common_set_sysfs(fsg_opts->common, true);
419 status = fsg_common_create_luns(fsg_opts->common, &config);
420 if (status)
421 goto fail_set_cdev;
422
423 fsg_common_set_inquiry_string(fsg_opts->common, config.vendor_name,
424 config.product_name);
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100425
Michal Nazarewicza99d8a42010-08-12 17:43:49 +0200426 /* allocate string IDs */
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200427 status = usb_string_ids_tab(cdev, strings_dev);
428 if (unlikely(status < 0))
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200429 goto fail_string_ids;
Sebastian Andrzej Siewiord33f74f2012-09-10 15:01:57 +0200430 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100431
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200432 /* register configurations */
433 status = rndis_config_register(cdev);
434 if (unlikely(status < 0))
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200435 goto fail_string_ids;
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100436
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200437 status = cdc_config_register(cdev);
438 if (unlikely(status < 0))
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200439 goto fail_string_ids;
Sebastian Andrzej Siewior7d16e8d2012-09-10 15:01:53 +0200440 usb_composite_overwrite_options(cdev, &coverwrite);
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100441
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200442 /* we're done */
443 dev_info(&gadget->dev, DRIVER_DESC "\n");
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100444 return 0;
445
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200446
447 /* error recovery */
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200448fail_string_ids:
449 fsg_common_remove_luns(fsg_opts->common);
450fail_set_cdev:
451 fsg_common_free_luns(fsg_opts->common);
452fail_set_nluns:
453 fsg_common_free_buffers(fsg_opts->common);
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100454fail2:
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200455 usb_put_function_instance(fi_msg);
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100456fail1:
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100457 usb_put_function_instance(fi_acm);
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100458fail0:
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200459#ifdef USB_ETH_RNDIS
460 usb_put_function_instance(fi_rndis);
461fail:
462#endif
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200463#ifdef CONFIG_USB_G_MULTI_CDC
464 usb_put_function_instance(fi_ecm);
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200465#endif
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100466 return status;
467}
468
469static int __exit multi_unbind(struct usb_composite_dev *cdev)
470{
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100471#ifdef CONFIG_USB_G_MULTI_CDC
Andrzej Pietrasiewicz1bcce932013-10-09 10:08:27 +0200472 usb_put_function(f_msg_multi);
473#endif
474#ifdef USB_ETH_RNDIS
475 usb_put_function(f_msg_rndis);
476#endif
477 usb_put_function_instance(fi_msg);
478#ifdef CONFIG_USB_G_MULTI_CDC
Sebastian Andrzej Siewior59835ad2012-12-23 21:10:10 +0100479 usb_put_function(f_acm_multi);
480#endif
481#ifdef USB_ETH_RNDIS
482 usb_put_function(f_acm_rndis);
483#endif
484 usb_put_function_instance(fi_acm);
Andrzej Pietrasiewicz4d1a8f62013-10-09 10:08:26 +0200485#ifdef USB_ETH_RNDIS
486 usb_put_function(f_rndis);
487 usb_put_function_instance(fi_rndis);
488#endif
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200489#ifdef CONFIG_USB_G_MULTI_CDC
490 usb_put_function(f_ecm);
491 usb_put_function_instance(fi_ecm);
Andrzej Pietrasiewicz73889012013-10-09 10:08:25 +0200492#endif
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100493 return 0;
494}
495
496
497/****************************** Some noise ******************************/
498
499
Sebastian Andrzej Siewiorc2ec75c2012-09-06 20:11:03 +0200500static __refdata struct usb_composite_driver multi_driver = {
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100501 .name = "g_multi",
502 .dev = &device_desc,
503 .strings = dev_strings,
Tatyana Brokhman35a0e0b2011-06-29 16:41:49 +0300504 .max_speed = USB_SPEED_HIGH,
Sebastian Andrzej Siewior03e42bd2012-09-06 20:11:04 +0200505 .bind = multi_bind,
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100506 .unbind = __exit_p(multi_unbind),
Michal Nazarewicza99d8a42010-08-12 17:43:49 +0200507 .needs_serial = 1,
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100508};
509
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100510
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200511static int __init multi_init(void)
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100512{
Sebastian Andrzej Siewior03e42bd2012-09-06 20:11:04 +0200513 return usb_composite_probe(&multi_driver);
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100514}
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200515module_init(multi_init);
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100516
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200517static void __exit multi_exit(void)
Michal Nazarewiczf176a5d2009-11-09 14:15:27 +0100518{
519 usb_composite_unregister(&multi_driver);
520}
Michal Nazarewicz279cc492010-06-21 13:57:03 +0200521module_exit(multi_exit);