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
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>
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"
47 #include "epautoconf.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 */,
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,
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[] = {
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)
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);
142 status = fsg_bind_config(c->cdev, c, &fsg_common);
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)
161 struct usb_gadget *gadget = cdev->gadget;
165 /* set up serial link layer */
166 status = gserial_setup(cdev->gadget, 1);
170 /* set up mass storage function */
171 retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data);
173 status = PTR_ERR(retp);
178 gcnum = usb_gadget_controller_number(gadget);
180 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
182 WARNING(cdev, "controller '%s' not recognized; trying %s\n",
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,
198 status = usb_string_id(cdev);
201 strings_dev[STRING_MANUFACTURER_IDX].id = status;
202 device_desc.iManufacturer = status;
204 status = usb_string_id(cdev);
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);
215 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
217 fsg_common_put(&fsg_common);
222 fsg_common_put(&fsg_common);
228 static int __exit acm_ms_unbind(struct usb_composite_dev *cdev)
235 static struct usb_composite_driver acm_ms_driver = {
238 .strings = dev_strings,
239 .unbind = __exit_p(acm_ms_unbind),
242 MODULE_DESCRIPTION(DRIVER_DESC);
244 MODULE_LICENSE("GPL v2");
246 static int __init init(void)
248 return usb_composite_probe(&acm_ms_driver, acm_ms_bind);
252 static void __exit cleanup(void)
254 usb_composite_unregister(&acm_ms_driver);
256 module_exit(cleanup);