Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Gadget Driver for Android |
| 3 | * |
| 4 | * Copyright (C) 2008 Google, Inc. |
| 5 | * Author: Mike Lockwood <lockwood@android.com> |
| 6 | * |
| 7 | * This software is licensed under the terms of the GNU General Public |
| 8 | * License version 2, as published by the Free Software Foundation, and |
| 9 | * may be copied, distributed, and modified under those terms. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | /* #define DEBUG */ |
| 19 | /* #define VERBOSE_DEBUG */ |
| 20 | |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/fs.h> |
| 24 | |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/utsname.h> |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 28 | #include <linux/platform_device.h> |
| 29 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 30 | #include <linux/usb/android_composite.h> |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 31 | #include <linux/usb/ch9.h> |
| 32 | #include <linux/usb/composite.h> |
| 33 | #include <linux/usb/gadget.h> |
| 34 | |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 35 | #include "gadget_chips.h" |
| 36 | |
| 37 | /* |
| 38 | * Kbuild is not very cooperative with respect to linking separately |
| 39 | * compiled library objects into one module. So for now we won't use |
| 40 | * separate compilation ... ensuring init/exit sections work to shrink |
| 41 | * the runtime footprint, and giving us at least some parts of what |
| 42 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. |
| 43 | */ |
| 44 | #include "usbstring.c" |
| 45 | #include "config.c" |
| 46 | #include "epautoconf.c" |
| 47 | #include "composite.c" |
| 48 | |
| 49 | MODULE_AUTHOR("Mike Lockwood"); |
| 50 | MODULE_DESCRIPTION("Android Composite USB Driver"); |
| 51 | MODULE_LICENSE("GPL"); |
| 52 | MODULE_VERSION("1.0"); |
| 53 | |
| 54 | static const char longname[] = "Gadget Android"; |
| 55 | |
| 56 | /* Default vendor and product IDs, overridden by platform data */ |
| 57 | #define VENDOR_ID 0x18D1 |
| 58 | #define PRODUCT_ID 0x0001 |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 59 | |
| 60 | struct android_dev { |
| 61 | struct usb_composite_dev *cdev; |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 62 | struct usb_configuration *config; |
| 63 | int num_products; |
| 64 | struct android_usb_product *products; |
| 65 | int num_functions; |
| 66 | char **functions; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 67 | |
Mike Lockwood | aecca43 | 2011-02-09 09:38:26 -0500 | [diff] [blame] | 68 | int vendor_id; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 69 | int product_id; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 70 | int version; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 71 | }; |
| 72 | |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 73 | static struct android_dev *_android_dev; |
| 74 | |
| 75 | /* string IDs are assigned dynamically */ |
| 76 | |
| 77 | #define STRING_MANUFACTURER_IDX 0 |
| 78 | #define STRING_PRODUCT_IDX 1 |
| 79 | #define STRING_SERIAL_IDX 2 |
| 80 | |
| 81 | /* String Table */ |
| 82 | static struct usb_string strings_dev[] = { |
| 83 | /* These dummy values should be overridden by platform data */ |
| 84 | [STRING_MANUFACTURER_IDX].s = "Android", |
| 85 | [STRING_PRODUCT_IDX].s = "Android", |
| 86 | [STRING_SERIAL_IDX].s = "0123456789ABCDEF", |
| 87 | { } /* end of list */ |
| 88 | }; |
| 89 | |
| 90 | static struct usb_gadget_strings stringtab_dev = { |
| 91 | .language = 0x0409, /* en-us */ |
| 92 | .strings = strings_dev, |
| 93 | }; |
| 94 | |
| 95 | static struct usb_gadget_strings *dev_strings[] = { |
| 96 | &stringtab_dev, |
| 97 | NULL, |
| 98 | }; |
| 99 | |
| 100 | static struct usb_device_descriptor device_desc = { |
| 101 | .bLength = sizeof(device_desc), |
| 102 | .bDescriptorType = USB_DT_DEVICE, |
| 103 | .bcdUSB = __constant_cpu_to_le16(0x0200), |
| 104 | .bDeviceClass = USB_CLASS_PER_INTERFACE, |
| 105 | .idVendor = __constant_cpu_to_le16(VENDOR_ID), |
| 106 | .idProduct = __constant_cpu_to_le16(PRODUCT_ID), |
| 107 | .bcdDevice = __constant_cpu_to_le16(0xffff), |
| 108 | .bNumConfigurations = 1, |
| 109 | }; |
| 110 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 111 | static struct list_head _functions = LIST_HEAD_INIT(_functions); |
John Michelau | 51d5755 | 2010-11-30 15:36:29 -0600 | [diff] [blame] | 112 | static bool _are_functions_bound; |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 113 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 114 | static struct android_usb_function *get_function(const char *name) |
| 115 | { |
| 116 | struct android_usb_function *f; |
| 117 | list_for_each_entry(f, &_functions, list) { |
| 118 | if (!strcmp(name, f->name)) |
| 119 | return f; |
| 120 | } |
| 121 | return 0; |
| 122 | } |
| 123 | |
John Michelau | 51d5755 | 2010-11-30 15:36:29 -0600 | [diff] [blame] | 124 | static bool are_functions_registered(struct android_dev *dev) |
| 125 | { |
| 126 | char **functions = dev->functions; |
| 127 | int i; |
| 128 | |
| 129 | /* Look only for functions required by the board config */ |
| 130 | for (i = 0; i < dev->num_functions; i++) { |
| 131 | char *name = *functions++; |
| 132 | bool is_match = false; |
| 133 | /* Could reuse get_function() here, but a reverse search |
| 134 | * should yield less comparisons overall */ |
| 135 | struct android_usb_function *f; |
| 136 | list_for_each_entry_reverse(f, &_functions, list) { |
| 137 | if (!strcmp(name, f->name)) { |
| 138 | is_match = true; |
| 139 | break; |
| 140 | } |
| 141 | } |
| 142 | if (is_match) |
| 143 | continue; |
| 144 | else |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | return true; |
| 149 | } |
| 150 | |
| 151 | static bool should_bind_functions(struct android_dev *dev) |
| 152 | { |
| 153 | /* Don't waste time if the main driver hasn't bound */ |
| 154 | if (!dev->config) |
| 155 | return false; |
| 156 | |
| 157 | /* Don't waste time if we've already bound the functions */ |
| 158 | if (_are_functions_bound) |
| 159 | return false; |
| 160 | |
| 161 | /* This call is the most costly, so call it last */ |
| 162 | if (!are_functions_registered(dev)) |
| 163 | return false; |
| 164 | |
| 165 | return true; |
| 166 | } |
| 167 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 168 | static void bind_functions(struct android_dev *dev) |
| 169 | { |
| 170 | struct android_usb_function *f; |
| 171 | char **functions = dev->functions; |
| 172 | int i; |
| 173 | |
| 174 | for (i = 0; i < dev->num_functions; i++) { |
| 175 | char *name = *functions++; |
| 176 | f = get_function(name); |
| 177 | if (f) |
| 178 | f->bind_config(dev->config); |
| 179 | else |
| 180 | printk(KERN_ERR "function %s not found in bind_functions\n", name); |
| 181 | } |
John Michelau | 51d5755 | 2010-11-30 15:36:29 -0600 | [diff] [blame] | 182 | |
| 183 | _are_functions_bound = true; |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 184 | } |
| 185 | |
Dmitry Shmidt | 577e37a | 2010-07-02 12:46:34 -0700 | [diff] [blame] | 186 | static int android_bind_config(struct usb_configuration *c) |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 187 | { |
| 188 | struct android_dev *dev = _android_dev; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 189 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 190 | printk(KERN_DEBUG "android_bind_config\n"); |
| 191 | dev->config = c; |
| 192 | |
John Michelau | 51d5755 | 2010-11-30 15:36:29 -0600 | [diff] [blame] | 193 | if (should_bind_functions(dev)) |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 194 | bind_functions(dev); |
| 195 | |
| 196 | return 0; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 197 | } |
| 198 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 199 | static int android_setup_config(struct usb_configuration *c, |
| 200 | const struct usb_ctrlrequest *ctrl); |
| 201 | |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 202 | static struct usb_configuration android_config_driver = { |
| 203 | .label = "android", |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 204 | .setup = android_setup_config, |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 205 | .bConfigurationValue = 1, |
| 206 | .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, |
| 207 | .bMaxPower = 0xFA, /* 500ma */ |
| 208 | }; |
| 209 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 210 | static int android_setup_config(struct usb_configuration *c, |
| 211 | const struct usb_ctrlrequest *ctrl) |
| 212 | { |
| 213 | int i; |
| 214 | int ret = -EOPNOTSUPP; |
| 215 | |
| 216 | for (i = 0; i < android_config_driver.next_interface_id; i++) { |
| 217 | if (android_config_driver.interface[i]->setup) { |
| 218 | ret = android_config_driver.interface[i]->setup( |
| 219 | android_config_driver.interface[i], ctrl); |
| 220 | if (ret >= 0) |
| 221 | return ret; |
| 222 | } |
| 223 | } |
| 224 | return ret; |
| 225 | } |
| 226 | |
| 227 | static int product_has_function(struct android_usb_product *p, |
| 228 | struct usb_function *f) |
| 229 | { |
| 230 | char **functions = p->functions; |
| 231 | int count = p->num_functions; |
| 232 | const char *name = f->name; |
| 233 | int i; |
| 234 | |
| 235 | for (i = 0; i < count; i++) { |
John Michelau | 51d5755 | 2010-11-30 15:36:29 -0600 | [diff] [blame] | 236 | /* For functions with multiple instances, usb_function.name |
| 237 | * will have an index appended to the core name (ex: acm0), |
| 238 | * while android_usb_product.functions[i] will only have the |
| 239 | * core name (ex: acm). So, only compare up to the length of |
| 240 | * android_usb_product.functions[i]. |
| 241 | */ |
| 242 | if (!strncmp(name, functions[i], strlen(functions[i]))) |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 243 | return 1; |
| 244 | } |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | static int product_matches_functions(struct android_usb_product *p) |
| 249 | { |
| 250 | struct usb_function *f; |
| 251 | list_for_each_entry(f, &android_config_driver.functions, list) { |
Mike Lockwood | e2dc503 | 2010-06-23 08:20:59 -0400 | [diff] [blame] | 252 | if (product_has_function(p, f) == !!f->disabled) |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 253 | return 0; |
| 254 | } |
| 255 | return 1; |
| 256 | } |
| 257 | |
Mike Lockwood | aecca43 | 2011-02-09 09:38:26 -0500 | [diff] [blame] | 258 | static int get_vendor_id(struct android_dev *dev) |
| 259 | { |
| 260 | struct android_usb_product *p = dev->products; |
| 261 | int count = dev->num_products; |
| 262 | int i; |
| 263 | |
| 264 | if (p) { |
| 265 | for (i = 0; i < count; i++, p++) { |
| 266 | if (p->vendor_id && product_matches_functions(p)) |
| 267 | return p->vendor_id; |
| 268 | } |
| 269 | } |
| 270 | /* use default vendor ID */ |
| 271 | return dev->vendor_id; |
| 272 | } |
| 273 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 274 | static int get_product_id(struct android_dev *dev) |
| 275 | { |
| 276 | struct android_usb_product *p = dev->products; |
| 277 | int count = dev->num_products; |
| 278 | int i; |
| 279 | |
| 280 | if (p) { |
| 281 | for (i = 0; i < count; i++, p++) { |
| 282 | if (product_matches_functions(p)) |
| 283 | return p->product_id; |
| 284 | } |
| 285 | } |
| 286 | /* use default product ID */ |
| 287 | return dev->product_id; |
| 288 | } |
| 289 | |
Dmitry Shmidt | 577e37a | 2010-07-02 12:46:34 -0700 | [diff] [blame] | 290 | static int android_bind(struct usb_composite_dev *cdev) |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 291 | { |
| 292 | struct android_dev *dev = _android_dev; |
| 293 | struct usb_gadget *gadget = cdev->gadget; |
Mike Lockwood | aecca43 | 2011-02-09 09:38:26 -0500 | [diff] [blame] | 294 | int gcnum, id, ret; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 295 | |
| 296 | printk(KERN_INFO "android_bind\n"); |
| 297 | |
| 298 | /* Allocate string descriptor numbers ... note that string |
| 299 | * contents can be overridden by the composite_dev glue. |
| 300 | */ |
| 301 | id = usb_string_id(cdev); |
| 302 | if (id < 0) |
| 303 | return id; |
| 304 | strings_dev[STRING_MANUFACTURER_IDX].id = id; |
| 305 | device_desc.iManufacturer = id; |
| 306 | |
| 307 | id = usb_string_id(cdev); |
| 308 | if (id < 0) |
| 309 | return id; |
| 310 | strings_dev[STRING_PRODUCT_IDX].id = id; |
| 311 | device_desc.iProduct = id; |
| 312 | |
| 313 | id = usb_string_id(cdev); |
| 314 | if (id < 0) |
| 315 | return id; |
| 316 | strings_dev[STRING_SERIAL_IDX].id = id; |
| 317 | device_desc.iSerialNumber = id; |
| 318 | |
| 319 | /* register our configuration */ |
Dima Zavin | 8da0417 | 2011-01-05 16:13:41 -0800 | [diff] [blame] | 320 | ret = usb_add_config(cdev, &android_config_driver, android_bind_config); |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 321 | if (ret) { |
| 322 | printk(KERN_ERR "usb_add_config failed\n"); |
| 323 | return ret; |
| 324 | } |
| 325 | |
| 326 | gcnum = usb_gadget_controller_number(gadget); |
| 327 | if (gcnum >= 0) |
| 328 | device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum); |
| 329 | else { |
| 330 | /* gadget zero is so simple (for now, no altsettings) that |
| 331 | * it SHOULD NOT have problems with bulk-capable hardware. |
| 332 | * so just warn about unrcognized controllers -- don't panic. |
| 333 | * |
| 334 | * things like configuration and altsetting numbering |
| 335 | * can need hardware-specific attention though. |
| 336 | */ |
| 337 | pr_warning("%s: controller '%s' not recognized\n", |
| 338 | longname, gadget->name); |
| 339 | device_desc.bcdDevice = __constant_cpu_to_le16(0x9999); |
| 340 | } |
| 341 | |
| 342 | usb_gadget_set_selfpowered(gadget); |
| 343 | dev->cdev = cdev; |
Mike Lockwood | aecca43 | 2011-02-09 09:38:26 -0500 | [diff] [blame] | 344 | device_desc.idVendor = __constant_cpu_to_le16(get_vendor_id(dev)); |
| 345 | device_desc.idProduct = __constant_cpu_to_le16(get_product_id(dev)); |
Mike Lockwood | 1adbbfb | 2011-02-14 13:32:05 -0500 | [diff] [blame] | 346 | cdev->desc.idVendor = device_desc.idVendor; |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 347 | cdev->desc.idProduct = device_desc.idProduct; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 348 | |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | static struct usb_composite_driver android_usb_driver = { |
| 353 | .name = "android_usb", |
| 354 | .dev = &device_desc, |
| 355 | .strings = dev_strings, |
Mike Lockwood | 0532973 | 2010-02-06 21:54:31 -0500 | [diff] [blame] | 356 | .enable_function = android_enable_function, |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 357 | }; |
| 358 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 359 | void android_register_function(struct android_usb_function *f) |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 360 | { |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 361 | struct android_dev *dev = _android_dev; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 362 | |
Mike Lockwood | 789ef23 | 2010-01-12 10:33:59 -0800 | [diff] [blame] | 363 | printk(KERN_INFO "android_register_function %s\n", f->name); |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 364 | list_add_tail(&f->list, &_functions); |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 365 | |
John Michelau | 51d5755 | 2010-11-30 15:36:29 -0600 | [diff] [blame] | 366 | if (dev && should_bind_functions(dev)) |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 367 | bind_functions(dev); |
| 368 | } |
| 369 | |
John Michelau | d5d2de6 | 2010-12-10 11:33:54 -0600 | [diff] [blame] | 370 | void update_dev_desc(struct android_dev *dev) |
| 371 | { |
| 372 | struct usb_function *f; |
| 373 | struct usb_function *last_enabled_f = NULL; |
| 374 | int num_enabled = 0; |
| 375 | int has_iad = 0; |
| 376 | |
| 377 | dev->cdev->desc.bDeviceClass = USB_CLASS_PER_INTERFACE; |
| 378 | dev->cdev->desc.bDeviceSubClass = 0x00; |
| 379 | dev->cdev->desc.bDeviceProtocol = 0x00; |
| 380 | |
| 381 | list_for_each_entry(f, &android_config_driver.functions, list) { |
| 382 | if (!f->disabled) { |
| 383 | num_enabled++; |
| 384 | last_enabled_f = f; |
| 385 | if (f->descriptors[0]->bDescriptorType == |
| 386 | USB_DT_INTERFACE_ASSOCIATION) |
| 387 | has_iad = 1; |
| 388 | } |
| 389 | if (num_enabled > 1 && has_iad) { |
| 390 | dev->cdev->desc.bDeviceClass = USB_CLASS_MISC; |
| 391 | dev->cdev->desc.bDeviceSubClass = 0x02; |
| 392 | dev->cdev->desc.bDeviceProtocol = 0x01; |
| 393 | break; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | if (num_enabled == 1) { |
| 398 | #ifdef CONFIG_USB_ANDROID_RNDIS |
| 399 | if (!strcmp(last_enabled_f->name, "rndis")) { |
| 400 | #ifdef CONFIG_USB_ANDROID_RNDIS_WCEIS |
| 401 | dev->cdev->desc.bDeviceClass = |
| 402 | USB_CLASS_WIRELESS_CONTROLLER; |
| 403 | #else |
| 404 | dev->cdev->desc.bDeviceClass = USB_CLASS_COMM; |
| 405 | #endif |
| 406 | } |
| 407 | #endif |
| 408 | } |
| 409 | } |
| 410 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 411 | void android_enable_function(struct usb_function *f, int enable) |
| 412 | { |
| 413 | struct android_dev *dev = _android_dev; |
| 414 | int disable = !enable; |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 415 | |
Mike Lockwood | e2dc503 | 2010-06-23 08:20:59 -0400 | [diff] [blame] | 416 | if (!!f->disabled != disable) { |
| 417 | usb_function_set_enabled(f, !disable); |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 418 | |
Mike Lockwood | da574e2 | 2010-02-13 16:37:16 -0500 | [diff] [blame] | 419 | #ifdef CONFIG_USB_ANDROID_RNDIS |
Mike Lockwood | da574e2 | 2010-02-13 16:37:16 -0500 | [diff] [blame] | 420 | if (!strcmp(f->name, "rndis")) { |
Mike Lockwood | 3522086 | 2010-02-24 10:20:59 -0500 | [diff] [blame] | 421 | struct usb_function *func; |
Mike Lockwood | 3522086 | 2010-02-24 10:20:59 -0500 | [diff] [blame] | 422 | /* Windows does not support other interfaces when RNDIS is enabled, |
Mike Lockwood | d6b1d73 | 2010-08-23 08:17:21 -0400 | [diff] [blame] | 423 | * so we disable UMS and MTP when RNDIS is on. |
Mike Lockwood | 3522086 | 2010-02-24 10:20:59 -0500 | [diff] [blame] | 424 | */ |
| 425 | list_for_each_entry(func, &android_config_driver.functions, list) { |
Mike Lockwood | d6b1d73 | 2010-08-23 08:17:21 -0400 | [diff] [blame] | 426 | if (!strcmp(func->name, "usb_mass_storage") |
| 427 | || !strcmp(func->name, "mtp")) { |
Mike Lockwood | 28acc1a | 2010-06-28 16:19:32 -0400 | [diff] [blame] | 428 | usb_function_set_enabled(func, !enable); |
Mike Lockwood | 3522086 | 2010-02-24 10:20:59 -0500 | [diff] [blame] | 429 | } |
| 430 | } |
Mike Lockwood | da574e2 | 2010-02-13 16:37:16 -0500 | [diff] [blame] | 431 | } |
| 432 | #endif |
Mike Lockwood | 9902e0b | 2011-02-02 11:52:56 -0500 | [diff] [blame] | 433 | #ifdef CONFIG_USB_ANDROID_ACCESSORY |
| 434 | if (!strcmp(f->name, "accessory") && enable) { |
| 435 | struct usb_function *func; |
| 436 | |
| 437 | /* disable everything else (and keep adb for now) */ |
| 438 | list_for_each_entry(func, &android_config_driver.functions, list) { |
| 439 | if (strcmp(func->name, "accessory") |
| 440 | && strcmp(func->name, "adb")) { |
| 441 | usb_function_set_enabled(func, 0); |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | #endif |
Mike Lockwood | da574e2 | 2010-02-13 16:37:16 -0500 | [diff] [blame] | 446 | |
John Michelau | d5d2de6 | 2010-12-10 11:33:54 -0600 | [diff] [blame] | 447 | update_dev_desc(dev); |
| 448 | |
Mike Lockwood | aecca43 | 2011-02-09 09:38:26 -0500 | [diff] [blame] | 449 | device_desc.idVendor = __constant_cpu_to_le16(get_vendor_id(dev)); |
| 450 | device_desc.idProduct = __constant_cpu_to_le16(get_product_id(dev)); |
Mike Lockwood | 1adbbfb | 2011-02-14 13:32:05 -0500 | [diff] [blame] | 451 | if (dev->cdev) { |
| 452 | dev->cdev->desc.idVendor = device_desc.idVendor; |
Mike Lockwood | 3522086 | 2010-02-24 10:20:59 -0500 | [diff] [blame] | 453 | dev->cdev->desc.idProduct = device_desc.idProduct; |
Mike Lockwood | 1adbbfb | 2011-02-14 13:32:05 -0500 | [diff] [blame] | 454 | } |
Mike Lockwood | 28acc1a | 2010-06-28 16:19:32 -0400 | [diff] [blame] | 455 | usb_composite_force_reset(dev->cdev); |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 456 | } |
| 457 | } |
| 458 | |
Dmitry Shmidt | 577e37a | 2010-07-02 12:46:34 -0700 | [diff] [blame] | 459 | static int android_probe(struct platform_device *pdev) |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 460 | { |
| 461 | struct android_usb_platform_data *pdata = pdev->dev.platform_data; |
| 462 | struct android_dev *dev = _android_dev; |
| 463 | |
| 464 | printk(KERN_INFO "android_probe pdata: %p\n", pdata); |
| 465 | |
| 466 | if (pdata) { |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 467 | dev->products = pdata->products; |
| 468 | dev->num_products = pdata->num_products; |
| 469 | dev->functions = pdata->functions; |
| 470 | dev->num_functions = pdata->num_functions; |
Mike Lockwood | aecca43 | 2011-02-09 09:38:26 -0500 | [diff] [blame] | 471 | if (pdata->vendor_id) { |
| 472 | dev->vendor_id = pdata->vendor_id; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 473 | device_desc.idVendor = |
| 474 | __constant_cpu_to_le16(pdata->vendor_id); |
Mike Lockwood | aecca43 | 2011-02-09 09:38:26 -0500 | [diff] [blame] | 475 | } |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 476 | if (pdata->product_id) { |
| 477 | dev->product_id = pdata->product_id; |
| 478 | device_desc.idProduct = |
| 479 | __constant_cpu_to_le16(pdata->product_id); |
| 480 | } |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 481 | if (pdata->version) |
| 482 | dev->version = pdata->version; |
| 483 | |
| 484 | if (pdata->product_name) |
| 485 | strings_dev[STRING_PRODUCT_IDX].s = pdata->product_name; |
| 486 | if (pdata->manufacturer_name) |
| 487 | strings_dev[STRING_MANUFACTURER_IDX].s = |
| 488 | pdata->manufacturer_name; |
| 489 | if (pdata->serial_number) |
| 490 | strings_dev[STRING_SERIAL_IDX].s = pdata->serial_number; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 491 | } |
| 492 | |
Dima Zavin | 8da0417 | 2011-01-05 16:13:41 -0800 | [diff] [blame] | 493 | return usb_composite_probe(&android_usb_driver, android_bind); |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | static struct platform_driver android_platform_driver = { |
| 497 | .driver = { .name = "android_usb", }, |
| 498 | .probe = android_probe, |
| 499 | }; |
| 500 | |
| 501 | static int __init init(void) |
| 502 | { |
| 503 | struct android_dev *dev; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 504 | |
| 505 | printk(KERN_INFO "android init\n"); |
| 506 | |
| 507 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 508 | if (!dev) |
| 509 | return -ENOMEM; |
| 510 | |
| 511 | /* set default values, which should be overridden by platform data */ |
| 512 | dev->product_id = PRODUCT_ID; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 513 | _android_dev = dev; |
| 514 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 515 | return platform_driver_register(&android_platform_driver); |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 516 | } |
| 517 | module_init(init); |
| 518 | |
| 519 | static void __exit cleanup(void) |
| 520 | { |
| 521 | usb_composite_unregister(&android_usb_driver); |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 522 | platform_driver_unregister(&android_platform_driver); |
| 523 | kfree(_android_dev); |
| 524 | _android_dev = NULL; |
| 525 | } |
| 526 | module_exit(cleanup); |