blob: ee448465b7d973bbfe5fff6c64655e55912f4624 [file] [log] [blame]
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001/*
2 * Gadget Driver for Android
3 *
4 * Copyright (C) 2008 Google, Inc.
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05305 * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05006 * Author: Mike Lockwood <lockwood@android.com>
7 *
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19/* #define DEBUG */
20/* #define VERBOSE_DEBUG */
21
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/fs.h>
25
26#include <linux/delay.h>
27#include <linux/kernel.h>
28#include <linux/utsname.h>
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -050029#include <linux/platform_device.h>
30
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -050031#include <linux/usb/ch9.h>
32#include <linux/usb/composite.h>
33#include <linux/usb/gadget.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070034#include <linux/usb/android.h>
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -050035
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -050036#include "gadget_chips.h"
37
38/*
39 * Kbuild is not very cooperative with respect to linking separately
40 * compiled library objects into one module. So for now we won't use
41 * separate compilation ... ensuring init/exit sections work to shrink
42 * the runtime footprint, and giving us at least some parts of what
43 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
44 */
45#include "usbstring.c"
46#include "config.c"
47#include "epautoconf.c"
48#include "composite.c"
49
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050#include "f_diag.c"
Manu Gautam1c8ffd72011-09-02 16:00:49 +053051#include "f_rmnet_smd.c"
Manu Gautam8e0719b2011-09-26 14:47:55 +053052#include "f_rmnet_sdio.c"
53#include "f_rmnet_smd_sdio.c"
Manu Gautam2b0234a2011-09-07 16:47:52 +053054#include "f_rmnet.c"
Benoit Gobyaab96812011-04-19 20:37:33 -070055#include "f_mass_storage.c"
Manu Gautama4d993f2011-08-30 18:25:55 +053056#include "u_serial.c"
57#include "u_sdio.c"
58#include "u_smd.c"
59#include "u_bam.c"
Manu Gautam2b0234a2011-09-07 16:47:52 +053060#include "u_rmnet_ctrl_smd.c"
Jack Pham427f6922011-11-23 19:42:00 -080061#include "u_ctrl_hsic.c"
62#include "u_data_hsic.c"
Manu Gautama4d993f2011-08-30 18:25:55 +053063#include "f_serial.c"
Anji jonnala92be1b42011-12-19 09:44:41 +053064#include "f_acm.c"
Benoit Gobyaab96812011-04-19 20:37:33 -070065#include "f_adb.c"
Chiranjeevi Velempatie130fd02011-11-29 05:06:13 +053066#include "f_ccid.c"
Benoit Gobyaab96812011-04-19 20:37:33 -070067#include "f_mtp.c"
68#include "f_accessory.c"
69#define USB_ETH_RNDIS y
70#include "f_rndis.c"
71#include "rndis.c"
72#include "u_ether.c"
73
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -050074MODULE_AUTHOR("Mike Lockwood");
75MODULE_DESCRIPTION("Android Composite USB Driver");
76MODULE_LICENSE("GPL");
77MODULE_VERSION("1.0");
78
79static const char longname[] = "Gadget Android";
80
Benoit Gobyaab96812011-04-19 20:37:33 -070081/* Default vendor and product IDs, overridden by userspace */
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -050082#define VENDOR_ID 0x18D1
83#define PRODUCT_ID 0x0001
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -050084
Benoit Gobyaab96812011-04-19 20:37:33 -070085struct android_usb_function {
86 char *name;
87 void *config;
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -050088
Benoit Gobyaab96812011-04-19 20:37:33 -070089 struct device *dev;
90 char *dev_name;
91 struct device_attribute **attributes;
92
93 /* for android_dev.enabled_functions */
94 struct list_head enabled_list;
95
96 /* Optional: initialization during gadget bind */
97 int (*init)(struct android_usb_function *, struct usb_composite_dev *);
98 /* Optional: cleanup during gadget unbind */
99 void (*cleanup)(struct android_usb_function *);
100
101 int (*bind_config)(struct android_usb_function *, struct usb_configuration *);
102
103 /* Optional: called when the configuration is removed */
104 void (*unbind_config)(struct android_usb_function *, struct usb_configuration *);
Mike Lockwood686d33a2011-09-07 09:55:12 -0700105 /* Optional: handle ctrl requests before the device is configured */
Benoit Gobyaab96812011-04-19 20:37:33 -0700106 int (*ctrlrequest)(struct android_usb_function *,
107 struct usb_composite_dev *,
108 const struct usb_ctrlrequest *);
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -0500109};
110
Benoit Gobyaab96812011-04-19 20:37:33 -0700111struct android_dev {
112 struct android_usb_function **functions;
113 struct list_head enabled_functions;
114 struct usb_composite_dev *cdev;
115 struct device *dev;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700116 struct android_usb_platform_data *pdata;
Benoit Gobyaab96812011-04-19 20:37:33 -0700117
118 bool enabled;
Benoit Gobydc1b6342011-12-09 18:05:00 -0800119 struct mutex mutex;
Benoit Gobyaab96812011-04-19 20:37:33 -0700120 bool connected;
121 bool sw_connected;
122 struct work_struct work;
123};
124
125static struct class *android_class;
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -0500126static struct android_dev *_android_dev;
Benoit Gobyaab96812011-04-19 20:37:33 -0700127static int android_bind_config(struct usb_configuration *c);
128static void android_unbind_config(struct usb_configuration *c);
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -0500129
130/* string IDs are assigned dynamically */
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -0500131#define STRING_MANUFACTURER_IDX 0
132#define STRING_PRODUCT_IDX 1
133#define STRING_SERIAL_IDX 2
134
Benoit Gobyaab96812011-04-19 20:37:33 -0700135static char manufacturer_string[256];
136static char product_string[256];
137static char serial_string[256];
138
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -0500139/* String Table */
140static struct usb_string strings_dev[] = {
Benoit Gobyaab96812011-04-19 20:37:33 -0700141 [STRING_MANUFACTURER_IDX].s = manufacturer_string,
142 [STRING_PRODUCT_IDX].s = product_string,
143 [STRING_SERIAL_IDX].s = serial_string,
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -0500144 { } /* end of list */
145};
146
147static struct usb_gadget_strings stringtab_dev = {
148 .language = 0x0409, /* en-us */
149 .strings = strings_dev,
150};
151
152static struct usb_gadget_strings *dev_strings[] = {
153 &stringtab_dev,
154 NULL,
155};
156
157static struct usb_device_descriptor device_desc = {
158 .bLength = sizeof(device_desc),
159 .bDescriptorType = USB_DT_DEVICE,
160 .bcdUSB = __constant_cpu_to_le16(0x0200),
161 .bDeviceClass = USB_CLASS_PER_INTERFACE,
162 .idVendor = __constant_cpu_to_le16(VENDOR_ID),
163 .idProduct = __constant_cpu_to_le16(PRODUCT_ID),
164 .bcdDevice = __constant_cpu_to_le16(0xffff),
165 .bNumConfigurations = 1,
166};
167
Vijayavardhan Vennapusa56e60522012-02-16 15:40:16 +0530168static struct usb_otg_descriptor otg_descriptor = {
169 .bLength = sizeof otg_descriptor,
170 .bDescriptorType = USB_DT_OTG,
171 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
172 .bcdOTG = __constant_cpu_to_le16(0x0200),
173};
174
175static const struct usb_descriptor_header *otg_desc[] = {
176 (struct usb_descriptor_header *) &otg_descriptor,
177 NULL,
178};
179
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -0500180static struct usb_configuration android_config_driver = {
181 .label = "android",
Benoit Gobyaab96812011-04-19 20:37:33 -0700182 .unbind = android_unbind_config,
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -0500183 .bConfigurationValue = 1,
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -0500184};
185
Benoit Gobyaab96812011-04-19 20:37:33 -0700186static void android_work(struct work_struct *data)
187{
188 struct android_dev *dev = container_of(data, struct android_dev, work);
189 struct usb_composite_dev *cdev = dev->cdev;
190 char *disconnected[2] = { "USB_STATE=DISCONNECTED", NULL };
191 char *connected[2] = { "USB_STATE=CONNECTED", NULL };
192 char *configured[2] = { "USB_STATE=CONFIGURED", NULL };
Dima Zavinfc753492011-09-14 11:52:45 -0700193 char **uevent_envp = NULL;
Benoit Gobyaab96812011-04-19 20:37:33 -0700194 unsigned long flags;
195
196 spin_lock_irqsave(&cdev->lock, flags);
Dima Zavinf85cf4f2011-09-14 15:12:45 -0700197 if (cdev->config)
Dima Zavinfc753492011-09-14 11:52:45 -0700198 uevent_envp = configured;
Dima Zavinf85cf4f2011-09-14 15:12:45 -0700199 else if (dev->connected != dev->sw_connected)
200 uevent_envp = dev->connected ? connected : disconnected;
201 dev->sw_connected = dev->connected;
Dima Zavinfc753492011-09-14 11:52:45 -0700202 spin_unlock_irqrestore(&cdev->lock, flags);
203
204 if (uevent_envp) {
205 kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE, uevent_envp);
206 pr_info("%s: sent uevent %s\n", __func__, uevent_envp[0]);
Benoit Gobyaab96812011-04-19 20:37:33 -0700207 } else {
Dima Zavinfc753492011-09-14 11:52:45 -0700208 pr_info("%s: did not send uevent (%d %d %p)\n", __func__,
209 dev->connected, dev->sw_connected, cdev->config);
Benoit Gobyaab96812011-04-19 20:37:33 -0700210 }
211}
212
213
214/*-------------------------------------------------------------------------*/
215/* Supported functions initialization */
216
Manu Gautam8e0719b2011-09-26 14:47:55 +0530217/* RMNET_SMD */
Manu Gautam1c8ffd72011-09-02 16:00:49 +0530218static int rmnet_smd_function_bind_config(struct android_usb_function *f,
219 struct usb_configuration *c)
220{
221 return rmnet_smd_bind_config(c);
222}
223
224static struct android_usb_function rmnet_smd_function = {
225 .name = "rmnet_smd",
226 .bind_config = rmnet_smd_function_bind_config,
227};
228
Manu Gautam8e0719b2011-09-26 14:47:55 +0530229/* RMNET_SDIO */
230static int rmnet_sdio_function_bind_config(struct android_usb_function *f,
231 struct usb_configuration *c)
232{
233 return rmnet_sdio_function_add(c);
234}
235
236static struct android_usb_function rmnet_sdio_function = {
237 .name = "rmnet_sdio",
238 .bind_config = rmnet_sdio_function_bind_config,
239};
240
241/* RMNET_SMD_SDIO */
242static int rmnet_smd_sdio_function_init(struct android_usb_function *f,
243 struct usb_composite_dev *cdev)
244{
245 return rmnet_smd_sdio_init();
246}
247
248static void rmnet_smd_sdio_function_cleanup(struct android_usb_function *f)
249{
250 rmnet_smd_sdio_cleanup();
251}
252
253static int rmnet_smd_sdio_bind_config(struct android_usb_function *f,
254 struct usb_configuration *c)
255{
256 return rmnet_smd_sdio_function_add(c);
257}
258
259static struct device_attribute *rmnet_smd_sdio_attributes[] = {
260 &dev_attr_transport, NULL };
261
262static struct android_usb_function rmnet_smd_sdio_function = {
263 .name = "rmnet_smd_sdio",
264 .init = rmnet_smd_sdio_function_init,
265 .cleanup = rmnet_smd_sdio_function_cleanup,
266 .bind_config = rmnet_smd_sdio_bind_config,
267 .attributes = rmnet_smd_sdio_attributes,
268};
269
Hemant Kumar1b820d52011-11-03 15:08:28 -0700270/*rmnet transport string format(per port):"ctrl0,data0,ctrl1,data1..." */
271#define MAX_XPORT_STR_LEN 50
272static char rmnet_transports[MAX_XPORT_STR_LEN];
Manu Gautam1c8ffd72011-09-02 16:00:49 +0530273
Manu Gautame3e897c2011-09-12 17:18:46 +0530274static void rmnet_function_cleanup(struct android_usb_function *f)
275{
276 frmnet_cleanup();
277}
278
Manu Gautam2b0234a2011-09-07 16:47:52 +0530279static int rmnet_function_bind_config(struct android_usb_function *f,
280 struct usb_configuration *c)
281{
282 int i;
Hemant Kumar1b820d52011-11-03 15:08:28 -0700283 int err = 0;
284 char *ctrl_name;
285 char *data_name;
286 char buf[MAX_XPORT_STR_LEN], *b;
287 static int rmnet_initialized, ports;
Manu Gautam2b0234a2011-09-07 16:47:52 +0530288
Hemant Kumar1b820d52011-11-03 15:08:28 -0700289 if (!rmnet_initialized) {
290 rmnet_initialized = 1;
291 strlcpy(buf, rmnet_transports, sizeof(buf));
292 b = strim(buf);
293 while (b) {
294 ctrl_name = strsep(&b, ",");
295 data_name = strsep(&b, ",");
296 if (ctrl_name && data_name) {
297 err = frmnet_init_port(ctrl_name, data_name);
298 if (err) {
299 pr_err("rmnet: Cannot open ctrl port:"
300 "'%s' data port:'%s'\n",
301 ctrl_name, data_name);
302 goto out;
303 }
304 ports++;
305 }
306 }
307
308 err = rmnet_gport_setup();
309 if (err) {
310 pr_err("rmnet: Cannot setup transports");
311 goto out;
312 }
313 }
314
315 for (i = 0; i < ports; i++) {
316 err = frmnet_bind_config(c, i);
317 if (err) {
Manu Gautam2b0234a2011-09-07 16:47:52 +0530318 pr_err("Could not bind rmnet%u config\n", i);
319 break;
320 }
321 }
Hemant Kumar1b820d52011-11-03 15:08:28 -0700322out:
323 return err;
Manu Gautam2b0234a2011-09-07 16:47:52 +0530324}
325
Hemant Kumar1b820d52011-11-03 15:08:28 -0700326static ssize_t rmnet_transports_show(struct device *dev,
Manu Gautam2b0234a2011-09-07 16:47:52 +0530327 struct device_attribute *attr, char *buf)
328{
Hemant Kumar1b820d52011-11-03 15:08:28 -0700329 return snprintf(buf, PAGE_SIZE, "%s\n", rmnet_transports);
Manu Gautam2b0234a2011-09-07 16:47:52 +0530330}
331
Hemant Kumar1b820d52011-11-03 15:08:28 -0700332static ssize_t rmnet_transports_store(
333 struct device *device, struct device_attribute *attr,
334 const char *buff, size_t size)
Manu Gautam2b0234a2011-09-07 16:47:52 +0530335{
Hemant Kumar1b820d52011-11-03 15:08:28 -0700336 strlcpy(rmnet_transports, buff, sizeof(rmnet_transports));
Manu Gautam2b0234a2011-09-07 16:47:52 +0530337
Manu Gautam2b0234a2011-09-07 16:47:52 +0530338 return size;
339}
340
Hemant Kumar1b820d52011-11-03 15:08:28 -0700341static struct device_attribute dev_attr_rmnet_transports =
342 __ATTR(transports, S_IRUGO | S_IWUSR,
343 rmnet_transports_show,
344 rmnet_transports_store);
Manu Gautam2b0234a2011-09-07 16:47:52 +0530345static struct device_attribute *rmnet_function_attributes[] = {
Hemant Kumar1b820d52011-11-03 15:08:28 -0700346 &dev_attr_rmnet_transports,
347 NULL };
Manu Gautam2b0234a2011-09-07 16:47:52 +0530348
349static struct android_usb_function rmnet_function = {
350 .name = "rmnet",
Manu Gautame3e897c2011-09-12 17:18:46 +0530351 .cleanup = rmnet_function_cleanup,
Manu Gautam2b0234a2011-09-07 16:47:52 +0530352 .bind_config = rmnet_function_bind_config,
353 .attributes = rmnet_function_attributes,
354};
355
Manu Gautam8e0719b2011-09-26 14:47:55 +0530356/* DIAG */
Manu Gautam2b0234a2011-09-07 16:47:52 +0530357static char diag_clients[32]; /*enabled DIAG clients- "diag[,diag_mdm]" */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700358static ssize_t clients_store(
359 struct device *device, struct device_attribute *attr,
360 const char *buff, size_t size)
361{
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +0530362 strlcpy(diag_clients, buff, sizeof(diag_clients));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700363
364 return size;
365}
366
367static DEVICE_ATTR(clients, S_IWUSR, NULL, clients_store);
368static struct device_attribute *diag_function_attributes[] =
369 { &dev_attr_clients, NULL };
370
371static int diag_function_init(struct android_usb_function *f,
372 struct usb_composite_dev *cdev)
373{
374 return diag_setup();
375}
376
377static void diag_function_cleanup(struct android_usb_function *f)
378{
379 diag_cleanup();
380}
381
382static int diag_function_bind_config(struct android_usb_function *f,
383 struct usb_configuration *c)
384{
385 char *name;
386 char buf[32], *b;
Manu Gautamc5760302011-08-25 14:30:24 +0530387 int once = 0, err = -1;
Jack Phamb830a6c2011-12-12 22:35:27 -0800388 int (*notify)(uint32_t, const char *);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700389
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +0530390 strlcpy(buf, diag_clients, sizeof(buf));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700391 b = strim(buf);
392
393 while (b) {
Jack Phamb830a6c2011-12-12 22:35:27 -0800394 notify = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700395 name = strsep(&b, ",");
Manu Gautamc5760302011-08-25 14:30:24 +0530396 /* Allow only first diag channel to update pid and serial no */
Hemant Kumar1136c002011-10-18 22:04:06 -0700397 if (_android_dev->pdata && !once++)
Manu Gautamc5760302011-08-25 14:30:24 +0530398 notify = _android_dev->pdata->update_pid_and_serial_num;
Manu Gautamc5760302011-08-25 14:30:24 +0530399
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700400 if (name) {
Manu Gautamc5760302011-08-25 14:30:24 +0530401 err = diag_function_add(c, name, notify);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700402 if (err)
403 pr_err("diag: Cannot open channel '%s'", name);
404 }
405 }
406
407 return err;
408}
409
410static struct android_usb_function diag_function = {
411 .name = "diag",
412 .init = diag_function_init,
413 .cleanup = diag_function_cleanup,
414 .bind_config = diag_function_bind_config,
415 .attributes = diag_function_attributes,
416};
417
Manu Gautam8e0719b2011-09-26 14:47:55 +0530418/* SERIAL */
Manu Gautam2b0234a2011-09-07 16:47:52 +0530419static char serial_transports[32]; /*enabled FSERIAL ports - "tty[,sdio]"*/
Manu Gautama4d993f2011-08-30 18:25:55 +0530420static ssize_t serial_transports_store(
421 struct device *device, struct device_attribute *attr,
422 const char *buff, size_t size)
423{
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +0530424 strlcpy(serial_transports, buff, sizeof(serial_transports));
Manu Gautama4d993f2011-08-30 18:25:55 +0530425
426 return size;
427}
428
429static DEVICE_ATTR(transports, S_IWUSR, NULL, serial_transports_store);
430static struct device_attribute *serial_function_attributes[] =
431 { &dev_attr_transports, NULL };
432
433static void serial_function_cleanup(struct android_usb_function *f)
434{
435 gserial_cleanup();
436}
437
438static int serial_function_bind_config(struct android_usb_function *f,
439 struct usb_configuration *c)
440{
441 char *name;
442 char buf[32], *b;
443 int err = -1, i;
444 static int serial_initialized = 0, ports = 0;
445
446 if (serial_initialized)
447 goto bind_config;
448
449 serial_initialized = 1;
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +0530450 strlcpy(buf, serial_transports, sizeof(buf));
Manu Gautama4d993f2011-08-30 18:25:55 +0530451 b = strim(buf);
452
453 while (b) {
454 name = strsep(&b, ",");
455
456 if (name) {
457 err = gserial_init_port(ports, name);
458 if (err) {
459 pr_err("serial: Cannot open port '%s'", name);
460 goto out;
461 }
462 ports++;
463 }
464 }
465 err = gport_setup(c);
466 if (err) {
467 pr_err("serial: Cannot setup transports");
468 goto out;
469 }
470
471bind_config:
Lena Salmand092f2d2012-03-12 17:27:24 +0200472 for (i = 0; i < ports; i++) {
Manu Gautama4d993f2011-08-30 18:25:55 +0530473 err = gser_bind_config(c, i);
474 if (err) {
475 pr_err("serial: bind_config failed for port %d", i);
476 goto out;
477 }
478 }
479
480out:
481 return err;
482}
483
484static struct android_usb_function serial_function = {
485 .name = "serial",
486 .cleanup = serial_function_cleanup,
487 .bind_config = serial_function_bind_config,
488 .attributes = serial_function_attributes,
489};
490
Anji jonnala92be1b42011-12-19 09:44:41 +0530491/* ACM */
492static char acm_transports[32]; /*enabled ACM ports - "tty[,sdio]"*/
493static ssize_t acm_transports_store(
494 struct device *device, struct device_attribute *attr,
495 const char *buff, size_t size)
496{
497 strlcpy(acm_transports, buff, sizeof(acm_transports));
498
499 return size;
500}
501
502static DEVICE_ATTR(acm_transports, S_IWUSR, NULL, acm_transports_store);
503static struct device_attribute *acm_function_attributes[] = {
504 &dev_attr_acm_transports, NULL };
505
506static void acm_function_cleanup(struct android_usb_function *f)
507{
508 gserial_cleanup();
509}
510
511static int acm_function_bind_config(struct android_usb_function *f,
512 struct usb_configuration *c)
513{
514 char *name;
515 char buf[32], *b;
516 int err = -1, i;
517 static int acm_initialized, ports;
518
519 if (acm_initialized)
520 goto bind_config;
521
522 acm_initialized = 1;
523 strlcpy(buf, acm_transports, sizeof(buf));
524 b = strim(buf);
525
526 while (b) {
527 name = strsep(&b, ",");
528
529 if (name) {
530 err = acm_init_port(ports, name);
531 if (err) {
532 pr_err("acm: Cannot open port '%s'", name);
533 goto out;
534 }
535 ports++;
536 }
537 }
538 err = acm_port_setup(c);
539 if (err) {
540 pr_err("acm: Cannot setup transports");
541 goto out;
542 }
543
544bind_config:
545 for (i = 0; i < ports; i++) {
546 err = acm_bind_config(c, i);
547 if (err) {
548 pr_err("acm: bind_config failed for port %d", i);
549 goto out;
550 }
551 }
552
553out:
554 return err;
555}
556static struct android_usb_function acm_function = {
557 .name = "acm",
558 .cleanup = acm_function_cleanup,
559 .bind_config = acm_function_bind_config,
560 .attributes = acm_function_attributes,
561};
Manu Gautama4d993f2011-08-30 18:25:55 +0530562
Manu Gautam8e0719b2011-09-26 14:47:55 +0530563/* ADB */
Benoit Gobyaab96812011-04-19 20:37:33 -0700564static int adb_function_init(struct android_usb_function *f, struct usb_composite_dev *cdev)
565{
566 return adb_setup();
567}
568
569static void adb_function_cleanup(struct android_usb_function *f)
570{
571 adb_cleanup();
572}
573
574static int adb_function_bind_config(struct android_usb_function *f, struct usb_configuration *c)
575{
576 return adb_bind_config(c);
577}
578
579static struct android_usb_function adb_function = {
580 .name = "adb",
581 .init = adb_function_init,
582 .cleanup = adb_function_cleanup,
583 .bind_config = adb_function_bind_config,
584};
585
Chiranjeevi Velempatie130fd02011-11-29 05:06:13 +0530586/* CCID */
587static int ccid_function_init(struct android_usb_function *f,
588 struct usb_composite_dev *cdev)
589{
590 return ccid_setup();
591}
592
593static void ccid_function_cleanup(struct android_usb_function *f)
594{
595 ccid_cleanup();
596}
597
598static int ccid_function_bind_config(struct android_usb_function *f,
599 struct usb_configuration *c)
600{
601 return ccid_bind_config(c);
602}
603
604static struct android_usb_function ccid_function = {
605 .name = "ccid",
606 .init = ccid_function_init,
607 .cleanup = ccid_function_cleanup,
608 .bind_config = ccid_function_bind_config,
609};
610
Benoit Gobyaab96812011-04-19 20:37:33 -0700611static int mtp_function_init(struct android_usb_function *f, struct usb_composite_dev *cdev)
612{
613 return mtp_setup();
614}
615
616static void mtp_function_cleanup(struct android_usb_function *f)
617{
618 mtp_cleanup();
619}
620
621static int mtp_function_bind_config(struct android_usb_function *f, struct usb_configuration *c)
622{
Mike Lockwoodcf7addf2011-06-01 22:17:36 -0400623 return mtp_bind_config(c, false);
624}
625
626static int ptp_function_init(struct android_usb_function *f, struct usb_composite_dev *cdev)
627{
628 /* nothing to do - initialization is handled by mtp_function_init */
629 return 0;
630}
631
632static void ptp_function_cleanup(struct android_usb_function *f)
633{
634 /* nothing to do - cleanup is handled by mtp_function_cleanup */
635}
636
637static int ptp_function_bind_config(struct android_usb_function *f, struct usb_configuration *c)
638{
639 return mtp_bind_config(c, true);
Benoit Gobyaab96812011-04-19 20:37:33 -0700640}
641
642static int mtp_function_ctrlrequest(struct android_usb_function *f,
643 struct usb_composite_dev *cdev,
644 const struct usb_ctrlrequest *c)
645{
646 return mtp_ctrlrequest(cdev, c);
647}
648
649static struct android_usb_function mtp_function = {
650 .name = "mtp",
651 .init = mtp_function_init,
652 .cleanup = mtp_function_cleanup,
653 .bind_config = mtp_function_bind_config,
654 .ctrlrequest = mtp_function_ctrlrequest,
655};
656
Mike Lockwoodcf7addf2011-06-01 22:17:36 -0400657/* PTP function is same as MTP with slightly different interface descriptor */
658static struct android_usb_function ptp_function = {
659 .name = "ptp",
660 .init = ptp_function_init,
661 .cleanup = ptp_function_cleanup,
662 .bind_config = ptp_function_bind_config,
663};
664
Benoit Gobyaab96812011-04-19 20:37:33 -0700665
666struct rndis_function_config {
667 u8 ethaddr[ETH_ALEN];
668 u32 vendorID;
669 char manufacturer[256];
670 bool wceis;
671};
672
673static int rndis_function_init(struct android_usb_function *f, struct usb_composite_dev *cdev)
674{
675 f->config = kzalloc(sizeof(struct rndis_function_config), GFP_KERNEL);
676 if (!f->config)
677 return -ENOMEM;
678 return 0;
679}
680
681static void rndis_function_cleanup(struct android_usb_function *f)
682{
683 kfree(f->config);
684 f->config = NULL;
685}
686
687static int rndis_function_bind_config(struct android_usb_function *f,
688 struct usb_configuration *c)
689{
Manu Gautamf4741132011-11-25 09:08:53 +0530690 int ret;
Benoit Gobyaab96812011-04-19 20:37:33 -0700691 struct rndis_function_config *rndis = f->config;
692
693 if (!rndis) {
694 pr_err("%s: rndis_pdata\n", __func__);
695 return -1;
696 }
697
698 pr_info("%s MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", __func__,
699 rndis->ethaddr[0], rndis->ethaddr[1], rndis->ethaddr[2],
700 rndis->ethaddr[3], rndis->ethaddr[4], rndis->ethaddr[5]);
701
Manu Gautamf4741132011-11-25 09:08:53 +0530702 ret = gether_setup_name(c->cdev->gadget, rndis->ethaddr, "rndis");
703 if (ret) {
704 pr_err("%s: gether_setup failed\n", __func__);
705 return ret;
706 }
707
Benoit Gobyaab96812011-04-19 20:37:33 -0700708 if (rndis->wceis) {
709 /* "Wireless" RNDIS; auto-detected by Windows */
710 rndis_iad_descriptor.bFunctionClass =
711 USB_CLASS_WIRELESS_CONTROLLER;
712 rndis_iad_descriptor.bFunctionSubClass = 0x01;
713 rndis_iad_descriptor.bFunctionProtocol = 0x03;
714 rndis_control_intf.bInterfaceClass =
715 USB_CLASS_WIRELESS_CONTROLLER;
716 rndis_control_intf.bInterfaceSubClass = 0x01;
717 rndis_control_intf.bInterfaceProtocol = 0x03;
718 }
719
720 return rndis_bind_config(c, rndis->ethaddr, rndis->vendorID,
721 rndis->manufacturer);
722}
723
724static void rndis_function_unbind_config(struct android_usb_function *f,
725 struct usb_configuration *c)
726{
Manu Gautamf4741132011-11-25 09:08:53 +0530727 gether_cleanup();
Benoit Gobyaab96812011-04-19 20:37:33 -0700728}
729
730static ssize_t rndis_manufacturer_show(struct device *dev,
731 struct device_attribute *attr, char *buf)
732{
733 struct android_usb_function *f = dev_get_drvdata(dev);
734 struct rndis_function_config *config = f->config;
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +0530735 return snprintf(buf, PAGE_SIZE, "%s\n", config->manufacturer);
Benoit Gobyaab96812011-04-19 20:37:33 -0700736}
737
738static ssize_t rndis_manufacturer_store(struct device *dev,
739 struct device_attribute *attr, const char *buf, size_t size)
740{
741 struct android_usb_function *f = dev_get_drvdata(dev);
742 struct rndis_function_config *config = f->config;
743
744 if (size >= sizeof(config->manufacturer))
745 return -EINVAL;
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +0530746 if (sscanf(buf, "%255s", config->manufacturer) == 1)
Benoit Gobyaab96812011-04-19 20:37:33 -0700747 return size;
748 return -1;
749}
750
751static DEVICE_ATTR(manufacturer, S_IRUGO | S_IWUSR, rndis_manufacturer_show,
752 rndis_manufacturer_store);
753
754static ssize_t rndis_wceis_show(struct device *dev,
755 struct device_attribute *attr, char *buf)
756{
757 struct android_usb_function *f = dev_get_drvdata(dev);
758 struct rndis_function_config *config = f->config;
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +0530759 return snprintf(buf, PAGE_SIZE, "%d\n", config->wceis);
Benoit Gobyaab96812011-04-19 20:37:33 -0700760}
761
762static ssize_t rndis_wceis_store(struct device *dev,
763 struct device_attribute *attr, const char *buf, size_t size)
764{
765 struct android_usb_function *f = dev_get_drvdata(dev);
766 struct rndis_function_config *config = f->config;
767 int value;
768
769 if (sscanf(buf, "%d", &value) == 1) {
770 config->wceis = value;
771 return size;
772 }
773 return -EINVAL;
774}
775
776static DEVICE_ATTR(wceis, S_IRUGO | S_IWUSR, rndis_wceis_show,
777 rndis_wceis_store);
778
779static ssize_t rndis_ethaddr_show(struct device *dev,
780 struct device_attribute *attr, char *buf)
781{
782 struct android_usb_function *f = dev_get_drvdata(dev);
783 struct rndis_function_config *rndis = f->config;
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +0530784 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
Benoit Gobyaab96812011-04-19 20:37:33 -0700785 rndis->ethaddr[0], rndis->ethaddr[1], rndis->ethaddr[2],
786 rndis->ethaddr[3], rndis->ethaddr[4], rndis->ethaddr[5]);
787}
788
789static ssize_t rndis_ethaddr_store(struct device *dev,
790 struct device_attribute *attr, const char *buf, size_t size)
791{
792 struct android_usb_function *f = dev_get_drvdata(dev);
793 struct rndis_function_config *rndis = f->config;
794
795 if (sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
796 (int *)&rndis->ethaddr[0], (int *)&rndis->ethaddr[1],
797 (int *)&rndis->ethaddr[2], (int *)&rndis->ethaddr[3],
798 (int *)&rndis->ethaddr[4], (int *)&rndis->ethaddr[5]) == 6)
799 return size;
800 return -EINVAL;
801}
802
803static DEVICE_ATTR(ethaddr, S_IRUGO | S_IWUSR, rndis_ethaddr_show,
804 rndis_ethaddr_store);
805
806static ssize_t rndis_vendorID_show(struct device *dev,
807 struct device_attribute *attr, char *buf)
808{
809 struct android_usb_function *f = dev_get_drvdata(dev);
810 struct rndis_function_config *config = f->config;
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +0530811 return snprintf(buf, PAGE_SIZE, "%04x\n", config->vendorID);
Benoit Gobyaab96812011-04-19 20:37:33 -0700812}
813
814static ssize_t rndis_vendorID_store(struct device *dev,
815 struct device_attribute *attr, const char *buf, size_t size)
816{
817 struct android_usb_function *f = dev_get_drvdata(dev);
818 struct rndis_function_config *config = f->config;
819 int value;
820
821 if (sscanf(buf, "%04x", &value) == 1) {
822 config->vendorID = value;
823 return size;
824 }
825 return -EINVAL;
826}
827
828static DEVICE_ATTR(vendorID, S_IRUGO | S_IWUSR, rndis_vendorID_show,
829 rndis_vendorID_store);
830
831static struct device_attribute *rndis_function_attributes[] = {
832 &dev_attr_manufacturer,
833 &dev_attr_wceis,
834 &dev_attr_ethaddr,
835 &dev_attr_vendorID,
836 NULL
837};
838
839static struct android_usb_function rndis_function = {
840 .name = "rndis",
841 .init = rndis_function_init,
842 .cleanup = rndis_function_cleanup,
843 .bind_config = rndis_function_bind_config,
844 .unbind_config = rndis_function_unbind_config,
845 .attributes = rndis_function_attributes,
846};
847
848
849struct mass_storage_function_config {
850 struct fsg_config fsg;
851 struct fsg_common *common;
852};
853
854static int mass_storage_function_init(struct android_usb_function *f,
855 struct usb_composite_dev *cdev)
856{
857 struct mass_storage_function_config *config;
858 struct fsg_common *common;
859 int err;
860
861 config = kzalloc(sizeof(struct mass_storage_function_config),
862 GFP_KERNEL);
863 if (!config)
864 return -ENOMEM;
865
866 config->fsg.nluns = 1;
867 config->fsg.luns[0].removable = 1;
868
869 common = fsg_common_init(NULL, cdev, &config->fsg);
870 if (IS_ERR(common)) {
871 kfree(config);
872 return PTR_ERR(common);
873 }
874
875 err = sysfs_create_link(&f->dev->kobj,
876 &common->luns[0].dev.kobj,
877 "lun");
878 if (err) {
Rajkumar Raghupathy01f599c2011-10-25 15:32:43 +0530879 fsg_common_release(&common->ref);
Benoit Gobyaab96812011-04-19 20:37:33 -0700880 kfree(config);
881 return err;
882 }
883
884 config->common = common;
885 f->config = config;
886 return 0;
887}
888
889static void mass_storage_function_cleanup(struct android_usb_function *f)
890{
891 kfree(f->config);
892 f->config = NULL;
893}
894
895static int mass_storage_function_bind_config(struct android_usb_function *f,
896 struct usb_configuration *c)
897{
898 struct mass_storage_function_config *config = f->config;
899 return fsg_bind_config(c->cdev, c, config->common);
900}
901
902static ssize_t mass_storage_inquiry_show(struct device *dev,
903 struct device_attribute *attr, char *buf)
904{
905 struct android_usb_function *f = dev_get_drvdata(dev);
906 struct mass_storage_function_config *config = f->config;
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +0530907 return snprintf(buf, PAGE_SIZE, "%s\n", config->common->inquiry_string);
Benoit Gobyaab96812011-04-19 20:37:33 -0700908}
909
910static ssize_t mass_storage_inquiry_store(struct device *dev,
911 struct device_attribute *attr, const char *buf, size_t size)
912{
913 struct android_usb_function *f = dev_get_drvdata(dev);
914 struct mass_storage_function_config *config = f->config;
915 if (size >= sizeof(config->common->inquiry_string))
916 return -EINVAL;
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +0530917 if (sscanf(buf, "%28s", config->common->inquiry_string) != 1)
Benoit Gobyaab96812011-04-19 20:37:33 -0700918 return -EINVAL;
919 return size;
920}
921
922static DEVICE_ATTR(inquiry_string, S_IRUGO | S_IWUSR,
923 mass_storage_inquiry_show,
924 mass_storage_inquiry_store);
925
926static struct device_attribute *mass_storage_function_attributes[] = {
927 &dev_attr_inquiry_string,
928 NULL
929};
930
931static struct android_usb_function mass_storage_function = {
932 .name = "mass_storage",
933 .init = mass_storage_function_init,
934 .cleanup = mass_storage_function_cleanup,
935 .bind_config = mass_storage_function_bind_config,
936 .attributes = mass_storage_function_attributes,
937};
938
939
940static int accessory_function_init(struct android_usb_function *f,
941 struct usb_composite_dev *cdev)
942{
943 return acc_setup();
944}
945
946static void accessory_function_cleanup(struct android_usb_function *f)
947{
948 acc_cleanup();
949}
950
951static int accessory_function_bind_config(struct android_usb_function *f,
952 struct usb_configuration *c)
953{
954 return acc_bind_config(c);
955}
956
957static int accessory_function_ctrlrequest(struct android_usb_function *f,
958 struct usb_composite_dev *cdev,
959 const struct usb_ctrlrequest *c)
960{
961 return acc_ctrlrequest(cdev, c);
962}
963
964static struct android_usb_function accessory_function = {
965 .name = "accessory",
966 .init = accessory_function_init,
967 .cleanup = accessory_function_cleanup,
968 .bind_config = accessory_function_bind_config,
969 .ctrlrequest = accessory_function_ctrlrequest,
970};
971
972
973static struct android_usb_function *supported_functions[] = {
Manu Gautam1c8ffd72011-09-02 16:00:49 +0530974 &rmnet_smd_function,
Manu Gautam8e0719b2011-09-26 14:47:55 +0530975 &rmnet_sdio_function,
976 &rmnet_smd_sdio_function,
Manu Gautam2b0234a2011-09-07 16:47:52 +0530977 &rmnet_function,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700978 &diag_function,
Manu Gautama4d993f2011-08-30 18:25:55 +0530979 &serial_function,
Benoit Gobyaab96812011-04-19 20:37:33 -0700980 &adb_function,
Chiranjeevi Velempatie130fd02011-11-29 05:06:13 +0530981 &ccid_function,
Anji jonnala92be1b42011-12-19 09:44:41 +0530982 &acm_function,
Benoit Gobyaab96812011-04-19 20:37:33 -0700983 &mtp_function,
Mike Lockwoodcf7addf2011-06-01 22:17:36 -0400984 &ptp_function,
Benoit Gobyaab96812011-04-19 20:37:33 -0700985 &rndis_function,
986 &mass_storage_function,
987 &accessory_function,
988 NULL
989};
990
Lena Salmand092f2d2012-03-12 17:27:24 +0200991static void android_cleanup_functions(struct android_usb_function **functions)
992{
993 struct android_usb_function *f;
994 struct device_attribute **attrs;
995 struct device_attribute *attr;
996
997 while (*functions) {
998 f = *functions++;
999
1000 if (f->dev) {
1001 device_destroy(android_class, f->dev->devt);
1002 kfree(f->dev_name);
1003 } else
1004 continue;
1005
1006 if (f->cleanup)
1007 f->cleanup(f);
1008
1009 attrs = f->attributes;
1010 if (attrs) {
1011 while ((attr = *attrs++))
1012 device_remove_file(f->dev, attr);
1013 }
1014 }
1015}
Benoit Gobyaab96812011-04-19 20:37:33 -07001016
1017static int android_init_functions(struct android_usb_function **functions,
1018 struct usb_composite_dev *cdev)
1019{
1020 struct android_dev *dev = _android_dev;
1021 struct android_usb_function *f;
1022 struct device_attribute **attrs;
1023 struct device_attribute *attr;
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301024 int err = 0;
Lena Salmand092f2d2012-03-12 17:27:24 +02001025 int index = 1; /* index 0 is for android0 device */
Benoit Gobyaab96812011-04-19 20:37:33 -07001026
1027 for (; (f = *functions++); index++) {
1028 f->dev_name = kasprintf(GFP_KERNEL, "f_%s", f->name);
Lena Salmand092f2d2012-03-12 17:27:24 +02001029 if (!f->dev_name) {
1030 err = -ENOMEM;
1031 goto err_out;
1032 }
Benoit Gobyaab96812011-04-19 20:37:33 -07001033 f->dev = device_create(android_class, dev->dev,
1034 MKDEV(0, index), f, f->dev_name);
1035 if (IS_ERR(f->dev)) {
1036 pr_err("%s: Failed to create dev %s", __func__,
1037 f->dev_name);
1038 err = PTR_ERR(f->dev);
Lena Salmand092f2d2012-03-12 17:27:24 +02001039 f->dev = NULL;
Benoit Gobyaab96812011-04-19 20:37:33 -07001040 goto err_create;
1041 }
1042
1043 if (f->init) {
1044 err = f->init(f, cdev);
1045 if (err) {
1046 pr_err("%s: Failed to init %s", __func__,
1047 f->name);
Lena Salmand092f2d2012-03-12 17:27:24 +02001048 goto err_init;
Benoit Gobyaab96812011-04-19 20:37:33 -07001049 }
1050 }
1051
1052 attrs = f->attributes;
1053 if (attrs) {
1054 while ((attr = *attrs++) && !err)
1055 err = device_create_file(f->dev, attr);
1056 }
1057 if (err) {
1058 pr_err("%s: Failed to create function %s attributes",
1059 __func__, f->name);
Lena Salmand092f2d2012-03-12 17:27:24 +02001060 goto err_attrs;
Benoit Gobyaab96812011-04-19 20:37:33 -07001061 }
1062 }
1063 return 0;
1064
Lena Salmand092f2d2012-03-12 17:27:24 +02001065err_attrs:
1066 for (attr = *(attrs -= 2); attrs != f->attributes; attr = *(attrs--))
1067 device_remove_file(f->dev, attr);
1068 if (f->cleanup)
1069 f->cleanup(f);
1070err_init:
Benoit Gobyaab96812011-04-19 20:37:33 -07001071 device_destroy(android_class, f->dev->devt);
1072err_create:
Lena Salmand092f2d2012-03-12 17:27:24 +02001073 f->dev = NULL;
Benoit Gobyaab96812011-04-19 20:37:33 -07001074 kfree(f->dev_name);
Lena Salmand092f2d2012-03-12 17:27:24 +02001075err_out:
1076 android_cleanup_functions(dev->functions);
Benoit Gobyaab96812011-04-19 20:37:33 -07001077 return err;
1078}
1079
Benoit Gobyaab96812011-04-19 20:37:33 -07001080static int
1081android_bind_enabled_functions(struct android_dev *dev,
1082 struct usb_configuration *c)
1083{
1084 struct android_usb_function *f;
1085 int ret;
1086
1087 list_for_each_entry(f, &dev->enabled_functions, enabled_list) {
1088 ret = f->bind_config(f, c);
1089 if (ret) {
1090 pr_err("%s: %s failed", __func__, f->name);
1091 return ret;
1092 }
Krishna, Vamsi83814ea2009-02-11 21:07:20 +05301093 }
1094 return 0;
1095}
1096
Benoit Gobyaab96812011-04-19 20:37:33 -07001097static void
1098android_unbind_enabled_functions(struct android_dev *dev,
1099 struct usb_configuration *c)
Krishna, Vamsi83814ea2009-02-11 21:07:20 +05301100{
Benoit Gobyaab96812011-04-19 20:37:33 -07001101 struct android_usb_function *f;
1102
1103 list_for_each_entry(f, &dev->enabled_functions, enabled_list) {
1104 if (f->unbind_config)
1105 f->unbind_config(f, c);
1106 }
1107}
1108
1109static int android_enable_function(struct android_dev *dev, char *name)
1110{
1111 struct android_usb_function **functions = dev->functions;
1112 struct android_usb_function *f;
1113 while ((f = *functions++)) {
1114 if (!strcmp(name, f->name)) {
1115 list_add_tail(&f->enabled_list, &dev->enabled_functions);
Krishna, Vamsi83814ea2009-02-11 21:07:20 +05301116 return 0;
Mike Lockwoodaecca432011-02-09 09:38:26 -05001117 }
1118 }
Benoit Gobyaab96812011-04-19 20:37:33 -07001119 return -EINVAL;
Mike Lockwoodaecca432011-02-09 09:38:26 -05001120}
1121
Benoit Gobyaab96812011-04-19 20:37:33 -07001122/*-------------------------------------------------------------------------*/
1123/* /sys/class/android_usb/android%d/ interface */
Krishna, Vamsi83814ea2009-02-11 21:07:20 +05301124
Pavankumar Kondeti352396c2011-12-07 13:32:40 +05301125static ssize_t remote_wakeup_show(struct device *pdev,
1126 struct device_attribute *attr, char *buf)
1127{
1128 return snprintf(buf, PAGE_SIZE, "%d\n",
1129 !!(android_config_driver.bmAttributes &
1130 USB_CONFIG_ATT_WAKEUP));
1131}
1132
1133static ssize_t remote_wakeup_store(struct device *pdev,
1134 struct device_attribute *attr, const char *buff, size_t size)
1135{
1136 int enable = 0;
1137
1138 sscanf(buff, "%d", &enable);
1139
1140 pr_debug("android_usb: %s remote wakeup\n",
1141 enable ? "enabling" : "disabling");
1142
1143 if (enable)
1144 android_config_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1145 else
1146 android_config_driver.bmAttributes &= ~USB_CONFIG_ATT_WAKEUP;
1147
1148 return size;
1149}
1150
Benoit Gobyaab96812011-04-19 20:37:33 -07001151static ssize_t
1152functions_show(struct device *pdev, struct device_attribute *attr, char *buf)
1153{
1154 struct android_dev *dev = dev_get_drvdata(pdev);
1155 struct android_usb_function *f;
1156 char *buff = buf;
1157
Benoit Gobydc1b6342011-12-09 18:05:00 -08001158 mutex_lock(&dev->mutex);
1159
Benoit Gobyaab96812011-04-19 20:37:33 -07001160 list_for_each_entry(f, &dev->enabled_functions, enabled_list)
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301161 buff += snprintf(buff, PAGE_SIZE, "%s,", f->name);
Benoit Gobydc1b6342011-12-09 18:05:00 -08001162
1163 mutex_unlock(&dev->mutex);
1164
Benoit Gobyaab96812011-04-19 20:37:33 -07001165 if (buff != buf)
1166 *(buff-1) = '\n';
1167 return buff - buf;
1168}
1169
1170static ssize_t
1171functions_store(struct device *pdev, struct device_attribute *attr,
1172 const char *buff, size_t size)
1173{
1174 struct android_dev *dev = dev_get_drvdata(pdev);
1175 char *name;
1176 char buf[256], *b;
1177 int err;
1178
Benoit Gobydc1b6342011-12-09 18:05:00 -08001179 mutex_lock(&dev->mutex);
1180
1181 if (dev->enabled) {
1182 mutex_unlock(&dev->mutex);
1183 return -EBUSY;
1184 }
1185
Benoit Gobyaab96812011-04-19 20:37:33 -07001186 INIT_LIST_HEAD(&dev->enabled_functions);
1187
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301188 strlcpy(buf, buff, sizeof(buf));
Benoit Gobyaab96812011-04-19 20:37:33 -07001189 b = strim(buf);
1190
1191 while (b) {
1192 name = strsep(&b, ",");
1193 if (name) {
1194 err = android_enable_function(dev, name);
1195 if (err)
1196 pr_err("android_usb: Cannot enable '%s'", name);
Krishna, Vamsi83814ea2009-02-11 21:07:20 +05301197 }
1198 }
Benoit Gobyaab96812011-04-19 20:37:33 -07001199
Benoit Gobydc1b6342011-12-09 18:05:00 -08001200 mutex_unlock(&dev->mutex);
1201
Benoit Gobyaab96812011-04-19 20:37:33 -07001202 return size;
1203}
1204
1205static ssize_t enable_show(struct device *pdev, struct device_attribute *attr,
1206 char *buf)
1207{
1208 struct android_dev *dev = dev_get_drvdata(pdev);
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301209 return snprintf(buf, PAGE_SIZE, "%d\n", dev->enabled);
Benoit Gobyaab96812011-04-19 20:37:33 -07001210}
1211
1212static ssize_t enable_store(struct device *pdev, struct device_attribute *attr,
1213 const char *buff, size_t size)
1214{
1215 struct android_dev *dev = dev_get_drvdata(pdev);
1216 struct usb_composite_dev *cdev = dev->cdev;
1217 int enabled = 0;
1218
Benoit Gobydc1b6342011-12-09 18:05:00 -08001219 mutex_lock(&dev->mutex);
1220
Benoit Gobyaab96812011-04-19 20:37:33 -07001221 sscanf(buff, "%d", &enabled);
1222 if (enabled && !dev->enabled) {
1223 /* update values in composite driver's copy of device descriptor */
1224 cdev->desc.idVendor = device_desc.idVendor;
1225 cdev->desc.idProduct = device_desc.idProduct;
1226 cdev->desc.bcdDevice = device_desc.bcdDevice;
1227 cdev->desc.bDeviceClass = device_desc.bDeviceClass;
1228 cdev->desc.bDeviceSubClass = device_desc.bDeviceSubClass;
1229 cdev->desc.bDeviceProtocol = device_desc.bDeviceProtocol;
Manu Gautam05b9ca42011-10-14 17:12:40 +05301230 if (usb_add_config(cdev, &android_config_driver,
1231 android_bind_config))
1232 return size;
1233
Benoit Gobyaab96812011-04-19 20:37:33 -07001234 usb_gadget_connect(cdev->gadget);
1235 dev->enabled = true;
1236 } else if (!enabled && dev->enabled) {
1237 usb_gadget_disconnect(cdev->gadget);
Benoit Gobye0de0a52011-11-29 13:49:27 -08001238 /* Cancel pending control requests */
1239 usb_ep_dequeue(cdev->gadget->ep0, cdev->req);
Benoit Gobyaab96812011-04-19 20:37:33 -07001240 usb_remove_config(cdev, &android_config_driver);
1241 dev->enabled = false;
1242 } else {
1243 pr_err("android_usb: already %s\n",
1244 dev->enabled ? "enabled" : "disabled");
1245 }
Benoit Gobydc1b6342011-12-09 18:05:00 -08001246
1247 mutex_unlock(&dev->mutex);
Benoit Gobyaab96812011-04-19 20:37:33 -07001248 return size;
1249}
1250
1251static ssize_t state_show(struct device *pdev, struct device_attribute *attr,
1252 char *buf)
1253{
1254 struct android_dev *dev = dev_get_drvdata(pdev);
1255 struct usb_composite_dev *cdev = dev->cdev;
1256 char *state = "DISCONNECTED";
1257 unsigned long flags;
1258
1259 if (!cdev)
1260 goto out;
1261
1262 spin_lock_irqsave(&cdev->lock, flags);
1263 if (cdev->config)
1264 state = "CONFIGURED";
1265 else if (dev->connected)
1266 state = "CONNECTED";
1267 spin_unlock_irqrestore(&cdev->lock, flags);
1268out:
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301269 return snprintf(buf, PAGE_SIZE, "%s\n", state);
Benoit Gobyaab96812011-04-19 20:37:33 -07001270}
1271
1272#define DESCRIPTOR_ATTR(field, format_string) \
1273static ssize_t \
1274field ## _show(struct device *dev, struct device_attribute *attr, \
1275 char *buf) \
1276{ \
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301277 return snprintf(buf, PAGE_SIZE, \
1278 format_string, device_desc.field); \
Benoit Gobyaab96812011-04-19 20:37:33 -07001279} \
1280static ssize_t \
1281field ## _store(struct device *dev, struct device_attribute *attr, \
Benoit Gobydc1b6342011-12-09 18:05:00 -08001282 const char *buf, size_t size) \
Benoit Gobyaab96812011-04-19 20:37:33 -07001283{ \
Benoit Gobydc1b6342011-12-09 18:05:00 -08001284 int value; \
Benoit Gobyaab96812011-04-19 20:37:33 -07001285 if (sscanf(buf, format_string, &value) == 1) { \
1286 device_desc.field = value; \
1287 return size; \
1288 } \
1289 return -1; \
1290} \
1291static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, field ## _show, field ## _store);
1292
1293#define DESCRIPTOR_STRING_ATTR(field, buffer) \
1294static ssize_t \
1295field ## _show(struct device *dev, struct device_attribute *attr, \
1296 char *buf) \
1297{ \
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301298 return snprintf(buf, PAGE_SIZE, "%s", buffer); \
Benoit Gobyaab96812011-04-19 20:37:33 -07001299} \
1300static ssize_t \
1301field ## _store(struct device *dev, struct device_attribute *attr, \
Benoit Gobydc1b6342011-12-09 18:05:00 -08001302 const char *buf, size_t size) \
Benoit Gobyaab96812011-04-19 20:37:33 -07001303{ \
1304 if (size >= sizeof(buffer)) return -EINVAL; \
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301305 if (sscanf(buf, "%255s", buffer) == 1) { \
Benoit Gobyaab96812011-04-19 20:37:33 -07001306 return size; \
1307 } \
1308 return -1; \
1309} \
1310static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, field ## _show, field ## _store);
1311
1312
1313DESCRIPTOR_ATTR(idVendor, "%04x\n")
1314DESCRIPTOR_ATTR(idProduct, "%04x\n")
1315DESCRIPTOR_ATTR(bcdDevice, "%04x\n")
1316DESCRIPTOR_ATTR(bDeviceClass, "%d\n")
1317DESCRIPTOR_ATTR(bDeviceSubClass, "%d\n")
1318DESCRIPTOR_ATTR(bDeviceProtocol, "%d\n")
1319DESCRIPTOR_STRING_ATTR(iManufacturer, manufacturer_string)
1320DESCRIPTOR_STRING_ATTR(iProduct, product_string)
1321DESCRIPTOR_STRING_ATTR(iSerial, serial_string)
1322
1323static DEVICE_ATTR(functions, S_IRUGO | S_IWUSR, functions_show, functions_store);
1324static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, enable_show, enable_store);
1325static DEVICE_ATTR(state, S_IRUGO, state_show, NULL);
Pavankumar Kondeti352396c2011-12-07 13:32:40 +05301326static DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR,
1327 remote_wakeup_show, remote_wakeup_store);
Benoit Gobyaab96812011-04-19 20:37:33 -07001328
1329static struct device_attribute *android_usb_attributes[] = {
1330 &dev_attr_idVendor,
1331 &dev_attr_idProduct,
1332 &dev_attr_bcdDevice,
1333 &dev_attr_bDeviceClass,
1334 &dev_attr_bDeviceSubClass,
1335 &dev_attr_bDeviceProtocol,
1336 &dev_attr_iManufacturer,
1337 &dev_attr_iProduct,
1338 &dev_attr_iSerial,
1339 &dev_attr_functions,
1340 &dev_attr_enable,
1341 &dev_attr_state,
Pavankumar Kondeti352396c2011-12-07 13:32:40 +05301342 &dev_attr_remote_wakeup,
Benoit Gobyaab96812011-04-19 20:37:33 -07001343 NULL
1344};
1345
1346/*-------------------------------------------------------------------------*/
1347/* Composite driver */
1348
1349static int android_bind_config(struct usb_configuration *c)
1350{
1351 struct android_dev *dev = _android_dev;
1352 int ret = 0;
1353
1354 ret = android_bind_enabled_functions(dev, c);
1355 if (ret)
1356 return ret;
1357
1358 return 0;
1359}
1360
1361static void android_unbind_config(struct usb_configuration *c)
1362{
1363 struct android_dev *dev = _android_dev;
1364
1365 android_unbind_enabled_functions(dev, c);
Krishna, Vamsi83814ea2009-02-11 21:07:20 +05301366}
1367
Dmitry Shmidt577e37a2010-07-02 12:46:34 -07001368static int android_bind(struct usb_composite_dev *cdev)
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001369{
1370 struct android_dev *dev = _android_dev;
1371 struct usb_gadget *gadget = cdev->gadget;
Mike Lockwoodaecca432011-02-09 09:38:26 -05001372 int gcnum, id, ret;
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001373
Benoit Gobyaab96812011-04-19 20:37:33 -07001374 usb_gadget_disconnect(gadget);
1375
1376 ret = android_init_functions(dev->functions, cdev);
1377 if (ret)
1378 return ret;
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001379
1380 /* Allocate string descriptor numbers ... note that string
1381 * contents can be overridden by the composite_dev glue.
1382 */
1383 id = usb_string_id(cdev);
1384 if (id < 0)
1385 return id;
1386 strings_dev[STRING_MANUFACTURER_IDX].id = id;
1387 device_desc.iManufacturer = id;
1388
1389 id = usb_string_id(cdev);
1390 if (id < 0)
1391 return id;
1392 strings_dev[STRING_PRODUCT_IDX].id = id;
1393 device_desc.iProduct = id;
1394
Benoit Gobyaab96812011-04-19 20:37:33 -07001395 /* Default strings - should be updated by userspace */
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301396 strlcpy(manufacturer_string, "Android",
1397 sizeof(manufacturer_string) - 1);
1398 strlcpy(product_string, "Android", sizeof(product_string) - 1);
1399 strlcpy(serial_string, "0123456789ABCDEF", sizeof(serial_string) - 1);
Benoit Gobyaab96812011-04-19 20:37:33 -07001400
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001401 id = usb_string_id(cdev);
1402 if (id < 0)
1403 return id;
1404 strings_dev[STRING_SERIAL_IDX].id = id;
1405 device_desc.iSerialNumber = id;
1406
Vijayavardhan Vennapusa56e60522012-02-16 15:40:16 +05301407 if (gadget_is_otg(cdev->gadget))
1408 android_config_driver.descriptors = otg_desc;
1409
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001410 gcnum = usb_gadget_controller_number(gadget);
1411 if (gcnum >= 0)
1412 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
1413 else {
1414 /* gadget zero is so simple (for now, no altsettings) that
1415 * it SHOULD NOT have problems with bulk-capable hardware.
1416 * so just warn about unrcognized controllers -- don't panic.
1417 *
1418 * things like configuration and altsetting numbering
1419 * can need hardware-specific attention though.
1420 */
1421 pr_warning("%s: controller '%s' not recognized\n",
1422 longname, gadget->name);
1423 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999);
1424 }
1425
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001426 dev->cdev = cdev;
1427
1428 return 0;
1429}
1430
Benoit Gobyaab96812011-04-19 20:37:33 -07001431static int android_usb_unbind(struct usb_composite_dev *cdev)
1432{
1433 struct android_dev *dev = _android_dev;
1434
Lena Salmand092f2d2012-03-12 17:27:24 +02001435 manufacturer_string[0] = '\0';
1436 product_string[0] = '\0';
1437 serial_string[0] = '0';
Benoit Gobyaab96812011-04-19 20:37:33 -07001438 cancel_work_sync(&dev->work);
1439 android_cleanup_functions(dev->functions);
1440 return 0;
1441}
1442
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001443static struct usb_composite_driver android_usb_driver = {
1444 .name = "android_usb",
1445 .dev = &device_desc,
1446 .strings = dev_strings,
Benoit Gobyaab96812011-04-19 20:37:33 -07001447 .unbind = android_usb_unbind,
Tatyana Brokhman3ba28902011-06-29 16:41:49 +03001448 .max_speed = USB_SPEED_SUPER
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001449};
1450
Benoit Gobyaab96812011-04-19 20:37:33 -07001451static int
1452android_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *c)
1453{
1454 struct android_dev *dev = _android_dev;
1455 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1456 struct usb_request *req = cdev->req;
Benoit Gobyaab96812011-04-19 20:37:33 -07001457 struct android_usb_function *f;
1458 int value = -EOPNOTSUPP;
1459 unsigned long flags;
1460
1461 req->zero = 0;
1462 req->complete = composite_setup_complete;
1463 req->length = 0;
1464 gadget->ep0->driver_data = cdev;
1465
Mike Lockwood6c7dd4b2011-08-02 11:13:48 -04001466 list_for_each_entry(f, &dev->enabled_functions, enabled_list) {
Benoit Gobyaab96812011-04-19 20:37:33 -07001467 if (f->ctrlrequest) {
1468 value = f->ctrlrequest(f, cdev, c);
1469 if (value >= 0)
1470 break;
1471 }
1472 }
1473
Mike Lockwood686d33a2011-09-07 09:55:12 -07001474 /* Special case the accessory function.
1475 * It needs to handle control requests before it is enabled.
1476 */
1477 if (value < 0)
1478 value = acc_ctrlrequest(cdev, c);
1479
Benoit Gobyaab96812011-04-19 20:37:33 -07001480 if (value < 0)
1481 value = composite_setup(gadget, c);
1482
1483 spin_lock_irqsave(&cdev->lock, flags);
1484 if (!dev->connected) {
1485 dev->connected = 1;
1486 schedule_work(&dev->work);
1487 }
1488 else if (c->bRequest == USB_REQ_SET_CONFIGURATION && cdev->config) {
1489 schedule_work(&dev->work);
1490 }
1491 spin_unlock_irqrestore(&cdev->lock, flags);
1492
1493 return value;
1494}
1495
1496static void android_disconnect(struct usb_gadget *gadget)
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001497{
Krishna, Vamsi83814ea2009-02-11 21:07:20 +05301498 struct android_dev *dev = _android_dev;
Dima Zavin21bad752011-09-14 11:53:11 -07001499 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1500 unsigned long flags;
1501
1502 composite_disconnect(gadget);
1503
1504 spin_lock_irqsave(&cdev->lock, flags);
Benoit Gobyaab96812011-04-19 20:37:33 -07001505 dev->connected = 0;
1506 schedule_work(&dev->work);
Dima Zavin21bad752011-09-14 11:53:11 -07001507 spin_unlock_irqrestore(&cdev->lock, flags);
Krishna, Vamsi83814ea2009-02-11 21:07:20 +05301508}
1509
Benoit Gobyaab96812011-04-19 20:37:33 -07001510static int android_create_device(struct android_dev *dev)
John Michelaud5d2de62010-12-10 11:33:54 -06001511{
Benoit Gobyaab96812011-04-19 20:37:33 -07001512 struct device_attribute **attrs = android_usb_attributes;
1513 struct device_attribute *attr;
1514 int err;
John Michelaud5d2de62010-12-10 11:33:54 -06001515
Benoit Gobyaab96812011-04-19 20:37:33 -07001516 dev->dev = device_create(android_class, NULL,
1517 MKDEV(0, 0), NULL, "android0");
1518 if (IS_ERR(dev->dev))
1519 return PTR_ERR(dev->dev);
John Michelaud5d2de62010-12-10 11:33:54 -06001520
Benoit Gobyaab96812011-04-19 20:37:33 -07001521 dev_set_drvdata(dev->dev, dev);
1522
1523 while ((attr = *attrs++)) {
1524 err = device_create_file(dev->dev, attr);
1525 if (err) {
1526 device_destroy(android_class, dev->dev->devt);
1527 return err;
John Michelaud5d2de62010-12-10 11:33:54 -06001528 }
1529 }
Benoit Gobyaab96812011-04-19 20:37:33 -07001530 return 0;
John Michelaud5d2de62010-12-10 11:33:54 -06001531}
1532
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05301533static void android_destroy_device(struct android_dev *dev)
1534{
1535 struct device_attribute **attrs = android_usb_attributes;
1536 struct device_attribute *attr;
1537
1538 while ((attr = *attrs++))
1539 device_remove_file(dev->dev, attr);
1540 device_destroy(android_class, dev->dev->devt);
1541}
1542
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001543static int __devinit android_probe(struct platform_device *pdev)
1544{
1545 struct android_usb_platform_data *pdata = pdev->dev.platform_data;
1546 struct android_dev *dev = _android_dev;
Lena Salmand092f2d2012-03-12 17:27:24 +02001547 int ret = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001548
1549 dev->pdata = pdata;
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05301550
Lena Salmand092f2d2012-03-12 17:27:24 +02001551 ret = usb_composite_probe(&android_usb_driver, android_bind);
1552 if (ret) {
1553 pr_err("%s(): Failed to register android "
1554 "composite driver\n", __func__);
1555 }
1556
1557 return ret;
1558}
1559
1560static int android_remove(struct platform_device *pdev)
1561{
1562 usb_composite_unregister(&android_usb_driver);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001563 return 0;
1564}
1565
1566static struct platform_driver android_platform_driver = {
1567 .driver = { .name = "android_usb"},
Lena Salmand092f2d2012-03-12 17:27:24 +02001568 .probe = android_probe,
1569 .remove = android_remove,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001570};
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001571
1572static int __init init(void)
1573{
1574 struct android_dev *dev;
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05301575 int ret;
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001576
Benoit Gobyaab96812011-04-19 20:37:33 -07001577 android_class = class_create(THIS_MODULE, "android_usb");
1578 if (IS_ERR(android_class))
1579 return PTR_ERR(android_class);
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001580
1581 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05301582 if (!dev) {
1583 pr_err("%s(): Failed to alloc memory for android_dev\n",
1584 __func__);
1585 class_destroy(android_class);
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001586 return -ENOMEM;
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05301587 }
Benoit Gobyaab96812011-04-19 20:37:33 -07001588 dev->functions = supported_functions;
1589 INIT_LIST_HEAD(&dev->enabled_functions);
1590 INIT_WORK(&dev->work, android_work);
Benoit Gobydc1b6342011-12-09 18:05:00 -08001591 mutex_init(&dev->mutex);
Benoit Gobyaab96812011-04-19 20:37:33 -07001592
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05301593 ret = android_create_device(dev);
1594 if (ret) {
1595 pr_err("%s(): android_create_device failed\n", __func__);
1596 goto err_dev;
Benoit Gobyaab96812011-04-19 20:37:33 -07001597 }
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001598 _android_dev = dev;
1599
Benoit Gobyaab96812011-04-19 20:37:33 -07001600 /* Override composite driver functions */
1601 composite_driver.setup = android_setup;
1602 composite_driver.disconnect = android_disconnect;
1603
Pavankumar Kondeti044914d2012-01-31 12:56:13 +05301604 ret = platform_driver_register(&android_platform_driver);
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05301605 if (ret) {
1606 pr_err("%s(): Failed to register android"
1607 "platform driver\n", __func__);
1608 goto err_probe;
1609 }
Lena Salmand092f2d2012-03-12 17:27:24 +02001610
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05301611 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001612
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05301613err_probe:
1614 android_destroy_device(dev);
1615err_dev:
1616 kfree(dev);
1617 class_destroy(android_class);
1618 return ret;
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001619}
1620module_init(init);
1621
1622static void __exit cleanup(void)
1623{
Lena Salmand092f2d2012-03-12 17:27:24 +02001624 platform_driver_unregister(&android_platform_driver);
1625 android_destroy_device(_android_dev);
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001626 kfree(_android_dev);
Lena Salmand092f2d2012-03-12 17:27:24 +02001627 class_destroy(android_class);
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05001628 _android_dev = NULL;
1629}
1630module_exit(cleanup);