Merge tag 'iommu-updates-v3.9' of git://git.kernel.org/pub/scm/linux/kernel/git/joro...
[deliverable/linux.git] / drivers / usb / gadget / acm_ms.c
CommitLineData
fa3ae0c1
KS
1/*
2 * acm_ms.c -- Composite driver, with ACM and mass storage support
3 *
4 * Copyright (C) 2008 David Brownell
5 * Copyright (C) 2008 Nokia Corporation
6 * Author: David Brownell
7 * Modified: Klaus Schwarzkopf <schwarzkopf@sensortherm.de>
8 *
9 * Heavily based on multi.c and cdc2.c
10 *
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.
15 */
16
17#include <linux/kernel.h>
721e2e91 18#include <linux/module.h>
fa3ae0c1
KS
19
20#include "u_serial.h"
21
22#define DRIVER_DESC "Composite Gadget (ACM + MS)"
23#define DRIVER_VERSION "2011/10/10"
24
25/*-------------------------------------------------------------------------*/
26
27/*
28 * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
29 * Instead: allocate your own, using normal USB-IF procedures.
30 */
31#define ACM_MS_VENDOR_NUM 0x1d6b /* Linux Foundation */
32#define ACM_MS_PRODUCT_NUM 0x0106 /* Composite Gadget: ACM + MS*/
33
34/*-------------------------------------------------------------------------*/
35
36/*
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.
42 */
fa3ae0c1
KS
43#include "f_mass_storage.c"
44
45/*-------------------------------------------------------------------------*/
7d16e8d3 46USB_GADGET_COMPOSITE_OPTIONS();
fa3ae0c1
KS
47
48static struct usb_device_descriptor device_desc = {
49 .bLength = sizeof device_desc,
50 .bDescriptorType = USB_DT_DEVICE,
51
52 .bcdUSB = cpu_to_le16(0x0200),
53
54 .bDeviceClass = USB_CLASS_MISC /* 0xEF */,
55 .bDeviceSubClass = 2,
56 .bDeviceProtocol = 1,
57
58 /* .bMaxPacketSize0 = f(hardware) */
59
60 /* Vendor and product id can be overridden by module parameters. */
61 .idVendor = cpu_to_le16(ACM_MS_VENDOR_NUM),
62 .idProduct = cpu_to_le16(ACM_MS_PRODUCT_NUM),
63 /* .bcdDevice = f(hardware) */
64 /* .iManufacturer = DYNAMIC */
65 /* .iProduct = DYNAMIC */
66 /* NO SERIAL NUMBER */
67 /*.bNumConfigurations = DYNAMIC*/
68};
69
70static struct usb_otg_descriptor otg_descriptor = {
71 .bLength = sizeof otg_descriptor,
72 .bDescriptorType = USB_DT_OTG,
73
74 /*
75 * REVISIT SRP-only hardware is possible, although
76 * it would not be called "OTG" ...
77 */
78 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
79};
80
81static const struct usb_descriptor_header *otg_desc[] = {
82 (struct usb_descriptor_header *) &otg_descriptor,
83 NULL,
84};
85
fa3ae0c1 86/* string IDs are assigned dynamically */
fa3ae0c1 87static struct usb_string strings_dev[] = {
cc2683c3 88 [USB_GADGET_MANUFACTURER_IDX].s = "",
276e2e4f
SAS
89 [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
90 [USB_GADGET_SERIAL_IDX].s = "",
fa3ae0c1
KS
91 { } /* end of list */
92};
93
94static struct usb_gadget_strings stringtab_dev = {
95 .language = 0x0409, /* en-us */
96 .strings = strings_dev,
97};
98
99static struct usb_gadget_strings *dev_strings[] = {
100 &stringtab_dev,
101 NULL,
102};
103
104/****************************** Configurations ******************************/
105
106static struct fsg_module_parameters fsg_mod_data = { .stall = 1 };
107FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
108
109static struct fsg_common fsg_common;
110
111/*-------------------------------------------------------------------------*/
19b10a88 112static unsigned char tty_line;
5f72bbfd
SAS
113static struct usb_function *f_acm;
114static struct usb_function_instance *f_acm_inst;
fa3ae0c1
KS
115/*
116 * We _always_ have both ACM and mass storage functions.
117 */
118static int __init acm_ms_do_config(struct usb_configuration *c)
119{
5f72bbfd 120 struct f_serial_opts *opts;
fa3ae0c1
KS
121 int status;
122
123 if (gadget_is_otg(c->cdev->gadget)) {
124 c->descriptors = otg_desc;
125 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
126 }
127
5f72bbfd
SAS
128 f_acm_inst = usb_get_function_instance("acm");
129 if (IS_ERR(f_acm_inst))
130 return PTR_ERR(f_acm_inst);
131
132 opts = container_of(f_acm_inst, struct f_serial_opts, func_inst);
133 opts->port_num = tty_line;
134
135 f_acm = usb_get_function(f_acm_inst);
136 if (IS_ERR(f_acm)) {
137 status = PTR_ERR(f_acm);
138 goto err_func;
139 }
fa3ae0c1 140
5f72bbfd 141 status = usb_add_function(c, f_acm);
fa3ae0c1 142 if (status < 0)
5f72bbfd 143 goto err_conf;
fa3ae0c1
KS
144
145 status = fsg_bind_config(c->cdev, c, &fsg_common);
146 if (status < 0)
5f72bbfd 147 goto err_fsg;
fa3ae0c1
KS
148
149 return 0;
5f72bbfd
SAS
150err_fsg:
151 usb_remove_function(c, f_acm);
152err_conf:
153 usb_put_function(f_acm);
154err_func:
155 usb_put_function_instance(f_acm_inst);
156 return status;
fa3ae0c1
KS
157}
158
159static struct usb_configuration acm_ms_config_driver = {
160 .label = DRIVER_DESC,
161 .bConfigurationValue = 1,
162 /* .iConfiguration = DYNAMIC */
163 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
164};
165
166/*-------------------------------------------------------------------------*/
167
168static int __init acm_ms_bind(struct usb_composite_dev *cdev)
169{
fa3ae0c1
KS
170 struct usb_gadget *gadget = cdev->gadget;
171 int status;
172 void *retp;
173
174 /* set up serial link layer */
19b10a88 175 status = gserial_alloc_line(&tty_line);
fa3ae0c1
KS
176 if (status < 0)
177 return status;
178
179 /* set up mass storage function */
180 retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data);
181 if (IS_ERR(retp)) {
182 status = PTR_ERR(retp);
183 goto fail0;
184 }
185
fa3ae0c1
KS
186 /*
187 * Allocate string descriptor numbers ... note that string
188 * contents can be overridden by the composite_dev glue.
189 */
e1f15ccb 190 status = usb_string_ids_tab(cdev, strings_dev);
fa3ae0c1
KS
191 if (status < 0)
192 goto fail1;
276e2e4f
SAS
193 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
194 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
fa3ae0c1
KS
195
196 /* register our configuration */
197 status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config);
198 if (status < 0)
199 goto fail1;
200
7d16e8d3 201 usb_composite_overwrite_options(cdev, &coverwrite);
fa3ae0c1
KS
202 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
203 DRIVER_DESC);
204 fsg_common_put(&fsg_common);
205 return 0;
206
207 /* error recovery */
208fail1:
209 fsg_common_put(&fsg_common);
210fail0:
19b10a88 211 gserial_free_line(tty_line);
fa3ae0c1
KS
212 return status;
213}
214
215static int __exit acm_ms_unbind(struct usb_composite_dev *cdev)
216{
5f72bbfd
SAS
217 usb_put_function(f_acm);
218 usb_put_function_instance(f_acm_inst);
19b10a88 219 gserial_free_line(tty_line);
fa3ae0c1
KS
220 return 0;
221}
222
c2ec75c2 223static __refdata struct usb_composite_driver acm_ms_driver = {
fa3ae0c1
KS
224 .name = "g_acm_ms",
225 .dev = &device_desc,
6f47209b 226 .max_speed = USB_SPEED_SUPER,
fa3ae0c1 227 .strings = dev_strings,
03e42bd5 228 .bind = acm_ms_bind,
fa3ae0c1
KS
229 .unbind = __exit_p(acm_ms_unbind),
230};
231
232MODULE_DESCRIPTION(DRIVER_DESC);
233MODULE_AUTHOR("Klaus Schwarzkopf <schwarzkopf@sensortherm.de>");
234MODULE_LICENSE("GPL v2");
235
236static int __init init(void)
237{
03e42bd5 238 return usb_composite_probe(&acm_ms_driver);
fa3ae0c1
KS
239}
240module_init(init);
241
242static void __exit cleanup(void)
243{
244 usb_composite_unregister(&acm_ms_driver);
245}
246module_exit(cleanup);
This page took 0.195165 seconds and 5 git commands to generate.