i2c-eg20t: change timeout value 50msec to 1000msec
[zen-stable.git] / drivers / usb / gadget / acm_ms.c
blobfdb7aec3bd0c9685262db2a303444ef69a62222c
1 /*
2 * acm_ms.c -- Composite driver, with ACM and mass storage support
4 * Copyright (C) 2008 David Brownell
5 * Copyright (C) 2008 Nokia Corporation
6 * Author: David Brownell
7 * Modified: Klaus Schwarzkopf <schwarzkopf@sensortherm.de>
9 * Heavily based on multi.c and cdc2.c
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
17 #include <linux/kernel.h>
18 #include <linux/utsname.h>
20 #include "u_serial.h"
22 #define DRIVER_DESC "Composite Gadget (ACM + MS)"
23 #define DRIVER_VERSION "2011/10/10"
25 /*-------------------------------------------------------------------------*/
28 * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
29 * Instead: allocate your own, using normal USB-IF procedures.
31 #define ACM_MS_VENDOR_NUM 0x1d6b /* Linux Foundation */
32 #define ACM_MS_PRODUCT_NUM 0x0106 /* Composite Gadget: ACM + MS*/
34 /*-------------------------------------------------------------------------*/
37 * Kbuild is not very cooperative with respect to linking separately
38 * compiled library objects into one module. So for now we won't use
39 * separate compilation ... ensuring init/exit sections work to shrink
40 * the runtime footprint, and giving us at least some parts of what
41 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
44 #include "composite.c"
45 #include "usbstring.c"
46 #include "config.c"
47 #include "epautoconf.c"
48 #include "u_serial.c"
49 #include "f_acm.c"
50 #include "f_mass_storage.c"
52 /*-------------------------------------------------------------------------*/
54 static struct usb_device_descriptor device_desc = {
55 .bLength = sizeof device_desc,
56 .bDescriptorType = USB_DT_DEVICE,
58 .bcdUSB = cpu_to_le16(0x0200),
60 .bDeviceClass = USB_CLASS_MISC /* 0xEF */,
61 .bDeviceSubClass = 2,
62 .bDeviceProtocol = 1,
64 /* .bMaxPacketSize0 = f(hardware) */
66 /* Vendor and product id can be overridden by module parameters. */
67 .idVendor = cpu_to_le16(ACM_MS_VENDOR_NUM),
68 .idProduct = cpu_to_le16(ACM_MS_PRODUCT_NUM),
69 /* .bcdDevice = f(hardware) */
70 /* .iManufacturer = DYNAMIC */
71 /* .iProduct = DYNAMIC */
72 /* NO SERIAL NUMBER */
73 /*.bNumConfigurations = DYNAMIC*/
76 static struct usb_otg_descriptor otg_descriptor = {
77 .bLength = sizeof otg_descriptor,
78 .bDescriptorType = USB_DT_OTG,
81 * REVISIT SRP-only hardware is possible, although
82 * it would not be called "OTG" ...
84 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
87 static const struct usb_descriptor_header *otg_desc[] = {
88 (struct usb_descriptor_header *) &otg_descriptor,
89 NULL,
93 /* string IDs are assigned dynamically */
95 #define STRING_MANUFACTURER_IDX 0
96 #define STRING_PRODUCT_IDX 1
98 static char manufacturer[50];
100 static struct usb_string strings_dev[] = {
101 [STRING_MANUFACTURER_IDX].s = manufacturer,
102 [STRING_PRODUCT_IDX].s = DRIVER_DESC,
103 { } /* end of list */
106 static struct usb_gadget_strings stringtab_dev = {
107 .language = 0x0409, /* en-us */
108 .strings = strings_dev,
111 static struct usb_gadget_strings *dev_strings[] = {
112 &stringtab_dev,
113 NULL,
116 /****************************** Configurations ******************************/
118 static struct fsg_module_parameters fsg_mod_data = { .stall = 1 };
119 FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
121 static struct fsg_common fsg_common;
123 /*-------------------------------------------------------------------------*/
126 * We _always_ have both ACM and mass storage functions.
128 static int __init acm_ms_do_config(struct usb_configuration *c)
130 int status;
132 if (gadget_is_otg(c->cdev->gadget)) {
133 c->descriptors = otg_desc;
134 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
138 status = acm_bind_config(c, 0);
139 if (status < 0)
140 return status;
142 status = fsg_bind_config(c->cdev, c, &fsg_common);
143 if (status < 0)
144 return status;
146 return 0;
149 static struct usb_configuration acm_ms_config_driver = {
150 .label = DRIVER_DESC,
151 .bConfigurationValue = 1,
152 /* .iConfiguration = DYNAMIC */
153 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
156 /*-------------------------------------------------------------------------*/
158 static int __init acm_ms_bind(struct usb_composite_dev *cdev)
160 int gcnum;
161 struct usb_gadget *gadget = cdev->gadget;
162 int status;
163 void *retp;
165 /* set up serial link layer */
166 status = gserial_setup(cdev->gadget, 1);
167 if (status < 0)
168 return status;
170 /* set up mass storage function */
171 retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data);
172 if (IS_ERR(retp)) {
173 status = PTR_ERR(retp);
174 goto fail0;
177 /* set bcdDevice */
178 gcnum = usb_gadget_controller_number(gadget);
179 if (gcnum >= 0) {
180 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
181 } else {
182 WARNING(cdev, "controller '%s' not recognized; trying %s\n",
183 gadget->name,
184 acm_ms_config_driver.label);
185 device_desc.bcdDevice =
186 cpu_to_le16(0x0300 | 0x0099);
190 * Allocate string descriptor numbers ... note that string
191 * contents can be overridden by the composite_dev glue.
194 /* device descriptor strings: manufacturer, product */
195 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
196 init_utsname()->sysname, init_utsname()->release,
197 gadget->name);
198 status = usb_string_id(cdev);
199 if (status < 0)
200 goto fail1;
201 strings_dev[STRING_MANUFACTURER_IDX].id = status;
202 device_desc.iManufacturer = status;
204 status = usb_string_id(cdev);
205 if (status < 0)
206 goto fail1;
207 strings_dev[STRING_PRODUCT_IDX].id = status;
208 device_desc.iProduct = status;
210 /* register our configuration */
211 status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config);
212 if (status < 0)
213 goto fail1;
215 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
216 DRIVER_DESC);
217 fsg_common_put(&fsg_common);
218 return 0;
220 /* error recovery */
221 fail1:
222 fsg_common_put(&fsg_common);
223 fail0:
224 gserial_cleanup();
225 return status;
228 static int __exit acm_ms_unbind(struct usb_composite_dev *cdev)
230 gserial_cleanup();
232 return 0;
235 static struct usb_composite_driver acm_ms_driver = {
236 .name = "g_acm_ms",
237 .dev = &device_desc,
238 .strings = dev_strings,
239 .unbind = __exit_p(acm_ms_unbind),
242 MODULE_DESCRIPTION(DRIVER_DESC);
243 MODULE_AUTHOR("Klaus Schwarzkopf <schwarzkopf@sensortherm.de>");
244 MODULE_LICENSE("GPL v2");
246 static int __init init(void)
248 return usb_composite_probe(&acm_ms_driver, acm_ms_bind);
250 module_init(init);
252 static void __exit cleanup(void)
254 usb_composite_unregister(&acm_ms_driver);
256 module_exit(cleanup);