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 | |
| 68 | int product_id; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 69 | int version; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 70 | }; |
| 71 | |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 72 | static struct android_dev *_android_dev; |
| 73 | |
| 74 | /* string IDs are assigned dynamically */ |
| 75 | |
| 76 | #define STRING_MANUFACTURER_IDX 0 |
| 77 | #define STRING_PRODUCT_IDX 1 |
| 78 | #define STRING_SERIAL_IDX 2 |
| 79 | |
| 80 | /* String Table */ |
| 81 | static struct usb_string strings_dev[] = { |
| 82 | /* These dummy values should be overridden by platform data */ |
| 83 | [STRING_MANUFACTURER_IDX].s = "Android", |
| 84 | [STRING_PRODUCT_IDX].s = "Android", |
| 85 | [STRING_SERIAL_IDX].s = "0123456789ABCDEF", |
| 86 | { } /* end of list */ |
| 87 | }; |
| 88 | |
| 89 | static struct usb_gadget_strings stringtab_dev = { |
| 90 | .language = 0x0409, /* en-us */ |
| 91 | .strings = strings_dev, |
| 92 | }; |
| 93 | |
| 94 | static struct usb_gadget_strings *dev_strings[] = { |
| 95 | &stringtab_dev, |
| 96 | NULL, |
| 97 | }; |
| 98 | |
| 99 | static struct usb_device_descriptor device_desc = { |
| 100 | .bLength = sizeof(device_desc), |
| 101 | .bDescriptorType = USB_DT_DEVICE, |
| 102 | .bcdUSB = __constant_cpu_to_le16(0x0200), |
| 103 | .bDeviceClass = USB_CLASS_PER_INTERFACE, |
| 104 | .idVendor = __constant_cpu_to_le16(VENDOR_ID), |
| 105 | .idProduct = __constant_cpu_to_le16(PRODUCT_ID), |
| 106 | .bcdDevice = __constant_cpu_to_le16(0xffff), |
| 107 | .bNumConfigurations = 1, |
| 108 | }; |
| 109 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 110 | static struct list_head _functions = LIST_HEAD_INIT(_functions); |
John Michelau | 51d5755 | 2010-11-30 15:36:29 -0600 | [diff] [blame^] | 111 | static bool _are_functions_bound; |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 112 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 113 | static struct android_usb_function *get_function(const char *name) |
| 114 | { |
| 115 | struct android_usb_function *f; |
| 116 | list_for_each_entry(f, &_functions, list) { |
| 117 | if (!strcmp(name, f->name)) |
| 118 | return f; |
| 119 | } |
| 120 | return 0; |
| 121 | } |
| 122 | |
John Michelau | 51d5755 | 2010-11-30 15:36:29 -0600 | [diff] [blame^] | 123 | static bool are_functions_registered(struct android_dev *dev) |
| 124 | { |
| 125 | char **functions = dev->functions; |
| 126 | int i; |
| 127 | |
| 128 | /* Look only for functions required by the board config */ |
| 129 | for (i = 0; i < dev->num_functions; i++) { |
| 130 | char *name = *functions++; |
| 131 | bool is_match = false; |
| 132 | /* Could reuse get_function() here, but a reverse search |
| 133 | * should yield less comparisons overall */ |
| 134 | struct android_usb_function *f; |
| 135 | list_for_each_entry_reverse(f, &_functions, list) { |
| 136 | if (!strcmp(name, f->name)) { |
| 137 | is_match = true; |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | if (is_match) |
| 142 | continue; |
| 143 | else |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | return true; |
| 148 | } |
| 149 | |
| 150 | static bool should_bind_functions(struct android_dev *dev) |
| 151 | { |
| 152 | /* Don't waste time if the main driver hasn't bound */ |
| 153 | if (!dev->config) |
| 154 | return false; |
| 155 | |
| 156 | /* Don't waste time if we've already bound the functions */ |
| 157 | if (_are_functions_bound) |
| 158 | return false; |
| 159 | |
| 160 | /* This call is the most costly, so call it last */ |
| 161 | if (!are_functions_registered(dev)) |
| 162 | return false; |
| 163 | |
| 164 | return true; |
| 165 | } |
| 166 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 167 | static void bind_functions(struct android_dev *dev) |
| 168 | { |
| 169 | struct android_usb_function *f; |
| 170 | char **functions = dev->functions; |
| 171 | int i; |
| 172 | |
| 173 | for (i = 0; i < dev->num_functions; i++) { |
| 174 | char *name = *functions++; |
| 175 | f = get_function(name); |
| 176 | if (f) |
| 177 | f->bind_config(dev->config); |
| 178 | else |
| 179 | printk(KERN_ERR "function %s not found in bind_functions\n", name); |
| 180 | } |
John Michelau | 51d5755 | 2010-11-30 15:36:29 -0600 | [diff] [blame^] | 181 | |
| 182 | _are_functions_bound = true; |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 183 | } |
| 184 | |
Dmitry Shmidt | 577e37a | 2010-07-02 12:46:34 -0700 | [diff] [blame] | 185 | static int android_bind_config(struct usb_configuration *c) |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 186 | { |
| 187 | struct android_dev *dev = _android_dev; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 188 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 189 | printk(KERN_DEBUG "android_bind_config\n"); |
| 190 | dev->config = c; |
| 191 | |
John Michelau | 51d5755 | 2010-11-30 15:36:29 -0600 | [diff] [blame^] | 192 | if (should_bind_functions(dev)) |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 193 | bind_functions(dev); |
| 194 | |
| 195 | return 0; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 196 | } |
| 197 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 198 | static int android_setup_config(struct usb_configuration *c, |
| 199 | const struct usb_ctrlrequest *ctrl); |
| 200 | |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 201 | static struct usb_configuration android_config_driver = { |
| 202 | .label = "android", |
| 203 | .bind = android_bind_config, |
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 | |
| 258 | static int get_product_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 (product_matches_functions(p)) |
| 267 | return p->product_id; |
| 268 | } |
| 269 | } |
| 270 | /* use default product ID */ |
| 271 | return dev->product_id; |
| 272 | } |
| 273 | |
Dmitry Shmidt | 577e37a | 2010-07-02 12:46:34 -0700 | [diff] [blame] | 274 | static int android_bind(struct usb_composite_dev *cdev) |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 275 | { |
| 276 | struct android_dev *dev = _android_dev; |
| 277 | struct usb_gadget *gadget = cdev->gadget; |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 278 | int gcnum, id, product_id, ret; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 279 | |
| 280 | printk(KERN_INFO "android_bind\n"); |
| 281 | |
| 282 | /* Allocate string descriptor numbers ... note that string |
| 283 | * contents can be overridden by the composite_dev glue. |
| 284 | */ |
| 285 | id = usb_string_id(cdev); |
| 286 | if (id < 0) |
| 287 | return id; |
| 288 | strings_dev[STRING_MANUFACTURER_IDX].id = id; |
| 289 | device_desc.iManufacturer = id; |
| 290 | |
| 291 | id = usb_string_id(cdev); |
| 292 | if (id < 0) |
| 293 | return id; |
| 294 | strings_dev[STRING_PRODUCT_IDX].id = id; |
| 295 | device_desc.iProduct = id; |
| 296 | |
| 297 | id = usb_string_id(cdev); |
| 298 | if (id < 0) |
| 299 | return id; |
| 300 | strings_dev[STRING_SERIAL_IDX].id = id; |
| 301 | device_desc.iSerialNumber = id; |
| 302 | |
| 303 | /* register our configuration */ |
| 304 | ret = usb_add_config(cdev, &android_config_driver); |
| 305 | if (ret) { |
| 306 | printk(KERN_ERR "usb_add_config failed\n"); |
| 307 | return ret; |
| 308 | } |
| 309 | |
| 310 | gcnum = usb_gadget_controller_number(gadget); |
| 311 | if (gcnum >= 0) |
| 312 | device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum); |
| 313 | else { |
| 314 | /* gadget zero is so simple (for now, no altsettings) that |
| 315 | * it SHOULD NOT have problems with bulk-capable hardware. |
| 316 | * so just warn about unrcognized controllers -- don't panic. |
| 317 | * |
| 318 | * things like configuration and altsetting numbering |
| 319 | * can need hardware-specific attention though. |
| 320 | */ |
| 321 | pr_warning("%s: controller '%s' not recognized\n", |
| 322 | longname, gadget->name); |
| 323 | device_desc.bcdDevice = __constant_cpu_to_le16(0x9999); |
| 324 | } |
| 325 | |
| 326 | usb_gadget_set_selfpowered(gadget); |
| 327 | dev->cdev = cdev; |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 328 | product_id = get_product_id(dev); |
| 329 | device_desc.idProduct = __constant_cpu_to_le16(product_id); |
| 330 | cdev->desc.idProduct = device_desc.idProduct; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | static struct usb_composite_driver android_usb_driver = { |
| 336 | .name = "android_usb", |
| 337 | .dev = &device_desc, |
| 338 | .strings = dev_strings, |
| 339 | .bind = android_bind, |
Mike Lockwood | 0532973 | 2010-02-06 21:54:31 -0500 | [diff] [blame] | 340 | .enable_function = android_enable_function, |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 341 | }; |
| 342 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 343 | void android_register_function(struct android_usb_function *f) |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 344 | { |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 345 | struct android_dev *dev = _android_dev; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 346 | |
Mike Lockwood | 789ef23 | 2010-01-12 10:33:59 -0800 | [diff] [blame] | 347 | printk(KERN_INFO "android_register_function %s\n", f->name); |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 348 | list_add_tail(&f->list, &_functions); |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 349 | |
John Michelau | 51d5755 | 2010-11-30 15:36:29 -0600 | [diff] [blame^] | 350 | if (dev && should_bind_functions(dev)) |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 351 | bind_functions(dev); |
| 352 | } |
| 353 | |
| 354 | void android_enable_function(struct usb_function *f, int enable) |
| 355 | { |
| 356 | struct android_dev *dev = _android_dev; |
| 357 | int disable = !enable; |
| 358 | int product_id; |
| 359 | |
Mike Lockwood | e2dc503 | 2010-06-23 08:20:59 -0400 | [diff] [blame] | 360 | if (!!f->disabled != disable) { |
| 361 | usb_function_set_enabled(f, !disable); |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 362 | |
Mike Lockwood | da574e2 | 2010-02-13 16:37:16 -0500 | [diff] [blame] | 363 | #ifdef CONFIG_USB_ANDROID_RNDIS |
Mike Lockwood | da574e2 | 2010-02-13 16:37:16 -0500 | [diff] [blame] | 364 | if (!strcmp(f->name, "rndis")) { |
Mike Lockwood | 3522086 | 2010-02-24 10:20:59 -0500 | [diff] [blame] | 365 | struct usb_function *func; |
| 366 | |
| 367 | /* We need to specify the COMM class in the device descriptor |
| 368 | * if we are using RNDIS. |
| 369 | */ |
Mike Lockwood | da574e2 | 2010-02-13 16:37:16 -0500 | [diff] [blame] | 370 | if (enable) |
Steve Kondik | 8f5f391 | 2010-02-17 12:59:29 -0500 | [diff] [blame] | 371 | #ifdef CONFIG_USB_ANDROID_RNDIS_WCEIS |
| 372 | dev->cdev->desc.bDeviceClass = USB_CLASS_WIRELESS_CONTROLLER; |
| 373 | #else |
Mike Lockwood | da574e2 | 2010-02-13 16:37:16 -0500 | [diff] [blame] | 374 | dev->cdev->desc.bDeviceClass = USB_CLASS_COMM; |
Steve Kondik | 8f5f391 | 2010-02-17 12:59:29 -0500 | [diff] [blame] | 375 | #endif |
Mike Lockwood | da574e2 | 2010-02-13 16:37:16 -0500 | [diff] [blame] | 376 | else |
| 377 | dev->cdev->desc.bDeviceClass = USB_CLASS_PER_INTERFACE; |
Mike Lockwood | 3522086 | 2010-02-24 10:20:59 -0500 | [diff] [blame] | 378 | |
| 379 | /* Windows does not support other interfaces when RNDIS is enabled, |
Mike Lockwood | d6b1d73 | 2010-08-23 08:17:21 -0400 | [diff] [blame] | 380 | * so we disable UMS and MTP when RNDIS is on. |
Mike Lockwood | 3522086 | 2010-02-24 10:20:59 -0500 | [diff] [blame] | 381 | */ |
| 382 | list_for_each_entry(func, &android_config_driver.functions, list) { |
Mike Lockwood | d6b1d73 | 2010-08-23 08:17:21 -0400 | [diff] [blame] | 383 | if (!strcmp(func->name, "usb_mass_storage") |
| 384 | || !strcmp(func->name, "mtp")) { |
Mike Lockwood | 28acc1a | 2010-06-28 16:19:32 -0400 | [diff] [blame] | 385 | usb_function_set_enabled(func, !enable); |
Mike Lockwood | 3522086 | 2010-02-24 10:20:59 -0500 | [diff] [blame] | 386 | } |
| 387 | } |
Mike Lockwood | da574e2 | 2010-02-13 16:37:16 -0500 | [diff] [blame] | 388 | } |
| 389 | #endif |
| 390 | |
Mike Lockwood | 3522086 | 2010-02-24 10:20:59 -0500 | [diff] [blame] | 391 | product_id = get_product_id(dev); |
| 392 | device_desc.idProduct = __constant_cpu_to_le16(product_id); |
| 393 | if (dev->cdev) |
| 394 | dev->cdev->desc.idProduct = device_desc.idProduct; |
Mike Lockwood | 28acc1a | 2010-06-28 16:19:32 -0400 | [diff] [blame] | 395 | usb_composite_force_reset(dev->cdev); |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
Dmitry Shmidt | 577e37a | 2010-07-02 12:46:34 -0700 | [diff] [blame] | 399 | static int android_probe(struct platform_device *pdev) |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 400 | { |
| 401 | struct android_usb_platform_data *pdata = pdev->dev.platform_data; |
| 402 | struct android_dev *dev = _android_dev; |
| 403 | |
| 404 | printk(KERN_INFO "android_probe pdata: %p\n", pdata); |
| 405 | |
| 406 | if (pdata) { |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 407 | dev->products = pdata->products; |
| 408 | dev->num_products = pdata->num_products; |
| 409 | dev->functions = pdata->functions; |
| 410 | dev->num_functions = pdata->num_functions; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 411 | if (pdata->vendor_id) |
| 412 | device_desc.idVendor = |
| 413 | __constant_cpu_to_le16(pdata->vendor_id); |
| 414 | if (pdata->product_id) { |
| 415 | dev->product_id = pdata->product_id; |
| 416 | device_desc.idProduct = |
| 417 | __constant_cpu_to_le16(pdata->product_id); |
| 418 | } |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 419 | if (pdata->version) |
| 420 | dev->version = pdata->version; |
| 421 | |
| 422 | if (pdata->product_name) |
| 423 | strings_dev[STRING_PRODUCT_IDX].s = pdata->product_name; |
| 424 | if (pdata->manufacturer_name) |
| 425 | strings_dev[STRING_MANUFACTURER_IDX].s = |
| 426 | pdata->manufacturer_name; |
| 427 | if (pdata->serial_number) |
| 428 | strings_dev[STRING_SERIAL_IDX].s = pdata->serial_number; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 429 | } |
| 430 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 431 | return usb_composite_register(&android_usb_driver); |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | static struct platform_driver android_platform_driver = { |
| 435 | .driver = { .name = "android_usb", }, |
| 436 | .probe = android_probe, |
| 437 | }; |
| 438 | |
| 439 | static int __init init(void) |
| 440 | { |
| 441 | struct android_dev *dev; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 442 | |
| 443 | printk(KERN_INFO "android init\n"); |
| 444 | |
| 445 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 446 | if (!dev) |
| 447 | return -ENOMEM; |
| 448 | |
| 449 | /* set default values, which should be overridden by platform data */ |
| 450 | dev->product_id = PRODUCT_ID; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 451 | _android_dev = dev; |
| 452 | |
Krishna, Vamsi | 83814ea | 2009-02-11 21:07:20 +0530 | [diff] [blame] | 453 | return platform_driver_register(&android_platform_driver); |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 454 | } |
| 455 | module_init(init); |
| 456 | |
| 457 | static void __exit cleanup(void) |
| 458 | { |
| 459 | usb_composite_unregister(&android_usb_driver); |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 460 | platform_driver_unregister(&android_platform_driver); |
| 461 | kfree(_android_dev); |
| 462 | _android_dev = NULL; |
| 463 | } |
| 464 | module_exit(cleanup); |