Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v3.7-rc3 226 lines 5.9 kB view raw
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> 18#include <linux/module.h> 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 */ 43 44#include "u_serial.c" 45#include "f_acm.c" 46#include "f_mass_storage.c" 47 48/*-------------------------------------------------------------------------*/ 49USB_GADGET_COMPOSITE_OPTIONS(); 50 51static struct usb_device_descriptor device_desc = { 52 .bLength = sizeof device_desc, 53 .bDescriptorType = USB_DT_DEVICE, 54 55 .bcdUSB = cpu_to_le16(0x0200), 56 57 .bDeviceClass = USB_CLASS_MISC /* 0xEF */, 58 .bDeviceSubClass = 2, 59 .bDeviceProtocol = 1, 60 61 /* .bMaxPacketSize0 = f(hardware) */ 62 63 /* Vendor and product id can be overridden by module parameters. */ 64 .idVendor = cpu_to_le16(ACM_MS_VENDOR_NUM), 65 .idProduct = cpu_to_le16(ACM_MS_PRODUCT_NUM), 66 /* .bcdDevice = f(hardware) */ 67 /* .iManufacturer = DYNAMIC */ 68 /* .iProduct = DYNAMIC */ 69 /* NO SERIAL NUMBER */ 70 /*.bNumConfigurations = DYNAMIC*/ 71}; 72 73static struct usb_otg_descriptor otg_descriptor = { 74 .bLength = sizeof otg_descriptor, 75 .bDescriptorType = USB_DT_OTG, 76 77 /* 78 * REVISIT SRP-only hardware is possible, although 79 * it would not be called "OTG" ... 80 */ 81 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, 82}; 83 84static const struct usb_descriptor_header *otg_desc[] = { 85 (struct usb_descriptor_header *) &otg_descriptor, 86 NULL, 87}; 88 89/* string IDs are assigned dynamically */ 90static struct usb_string strings_dev[] = { 91 [USB_GADGET_MANUFACTURER_IDX].s = "", 92 [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC, 93 [USB_GADGET_SERIAL_IDX].s = "", 94 { } /* end of list */ 95}; 96 97static struct usb_gadget_strings stringtab_dev = { 98 .language = 0x0409, /* en-us */ 99 .strings = strings_dev, 100}; 101 102static struct usb_gadget_strings *dev_strings[] = { 103 &stringtab_dev, 104 NULL, 105}; 106 107/****************************** Configurations ******************************/ 108 109static struct fsg_module_parameters fsg_mod_data = { .stall = 1 }; 110FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); 111 112static struct fsg_common fsg_common; 113 114/*-------------------------------------------------------------------------*/ 115 116/* 117 * We _always_ have both ACM and mass storage functions. 118 */ 119static int __init acm_ms_do_config(struct usb_configuration *c) 120{ 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 128 129 status = acm_bind_config(c, 0); 130 if (status < 0) 131 return status; 132 133 status = fsg_bind_config(c->cdev, c, &fsg_common); 134 if (status < 0) 135 return status; 136 137 return 0; 138} 139 140static struct usb_configuration acm_ms_config_driver = { 141 .label = DRIVER_DESC, 142 .bConfigurationValue = 1, 143 /* .iConfiguration = DYNAMIC */ 144 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 145}; 146 147/*-------------------------------------------------------------------------*/ 148 149static int __init acm_ms_bind(struct usb_composite_dev *cdev) 150{ 151 struct usb_gadget *gadget = cdev->gadget; 152 int status; 153 void *retp; 154 155 /* set up serial link layer */ 156 status = gserial_setup(cdev->gadget, 1); 157 if (status < 0) 158 return status; 159 160 /* set up mass storage function */ 161 retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); 162 if (IS_ERR(retp)) { 163 status = PTR_ERR(retp); 164 goto fail0; 165 } 166 167 /* 168 * Allocate string descriptor numbers ... note that string 169 * contents can be overridden by the composite_dev glue. 170 */ 171 status = usb_string_ids_tab(cdev, strings_dev); 172 if (status < 0) 173 goto fail1; 174 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; 175 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; 176 177 /* register our configuration */ 178 status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config); 179 if (status < 0) 180 goto fail1; 181 182 usb_composite_overwrite_options(cdev, &coverwrite); 183 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", 184 DRIVER_DESC); 185 fsg_common_put(&fsg_common); 186 return 0; 187 188 /* error recovery */ 189fail1: 190 fsg_common_put(&fsg_common); 191fail0: 192 gserial_cleanup(); 193 return status; 194} 195 196static int __exit acm_ms_unbind(struct usb_composite_dev *cdev) 197{ 198 gserial_cleanup(); 199 200 return 0; 201} 202 203static __refdata struct usb_composite_driver acm_ms_driver = { 204 .name = "g_acm_ms", 205 .dev = &device_desc, 206 .max_speed = USB_SPEED_SUPER, 207 .strings = dev_strings, 208 .bind = acm_ms_bind, 209 .unbind = __exit_p(acm_ms_unbind), 210}; 211 212MODULE_DESCRIPTION(DRIVER_DESC); 213MODULE_AUTHOR("Klaus Schwarzkopf <schwarzkopf@sensortherm.de>"); 214MODULE_LICENSE("GPL v2"); 215 216static int __init init(void) 217{ 218 return usb_composite_probe(&acm_ms_driver); 219} 220module_init(init); 221 222static void __exit cleanup(void) 223{ 224 usb_composite_unregister(&acm_ms_driver); 225} 226module_exit(cleanup);