blob: 54c486e709e72823b7754d770536c06afc4eb23c [file] [log] [blame]
Benoit Goby1e8ce152011-12-12 13:01:23 -08001/*
2 * Gadget Driver for Android
3 *
4 * Copyright (C) 2008 Google, Inc.
5 * Author: Mike Lockwood <lockwood@android.com>
6 * Benoit Goby <benoit@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#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/fs.h>
22#include <linux/delay.h>
23#include <linux/kernel.h>
24#include <linux/utsname.h>
25#include <linux/platform_device.h>
Steve Mucklef132c6c2012-06-06 18:30:57 -070026#include <linux/pm_qos.h>
Benoit Goby1e8ce152011-12-12 13:01:23 -080027
28#include <linux/usb/ch9.h>
29#include <linux/usb/composite.h>
30#include <linux/usb/gadget.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070031#include <linux/usb/android.h>
Benoit Goby1e8ce152011-12-12 13:01:23 -080032
33#include "gadget_chips.h"
34
35/*
36 * Kbuild is not very cooperative with respect to linking separately
37 * compiled library objects into one module. So for now we won't use
38 * separate compilation ... ensuring init/exit sections work to shrink
39 * the runtime footprint, and giving us at least some parts of what
40 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
41 */
42#include "usbstring.c"
43#include "config.c"
44#include "epautoconf.c"
45#include "composite.c"
46
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070047#include "f_diag.c"
Manu Gautam1c8ffd72011-09-02 16:00:49 +053048#include "f_rmnet_smd.c"
Manu Gautam8e0719b2011-09-26 14:47:55 +053049#include "f_rmnet_sdio.c"
50#include "f_rmnet_smd_sdio.c"
Manu Gautam2b0234a2011-09-07 16:47:52 +053051#include "f_rmnet.c"
Benoit Goby1e8ce152011-12-12 13:01:23 -080052#include "f_mass_storage.c"
53#include "u_serial.c"
Manu Gautama4d993f2011-08-30 18:25:55 +053054#include "u_sdio.c"
55#include "u_smd.c"
56#include "u_bam.c"
Manu Gautam2b0234a2011-09-07 16:47:52 +053057#include "u_rmnet_ctrl_smd.c"
Jack Pham427f6922011-11-23 19:42:00 -080058#include "u_ctrl_hsic.c"
59#include "u_data_hsic.c"
Vijayavardhan Vennapusaeb8d2392012-04-03 18:58:49 +053060#include "u_ctrl_hsuart.c"
61#include "u_data_hsuart.c"
Manu Gautama4d993f2011-08-30 18:25:55 +053062#include "f_serial.c"
Benoit Goby1e8ce152011-12-12 13:01:23 -080063#include "f_acm.c"
Benoit Goby2b6862d2011-12-19 14:38:41 -080064#include "f_adb.c"
Chiranjeevi Velempatie130fd02011-11-29 05:06:13 +053065#include "f_ccid.c"
Benoit Gobyf0fbc482011-12-19 14:37:50 -080066#include "f_mtp.c"
Benoit Gobycf3fc062011-12-19 14:39:37 -080067#include "f_accessory.c"
Benoit Goby1e8ce152011-12-12 13:01:23 -080068#define USB_ETH_RNDIS y
69#include "f_rndis.c"
70#include "rndis.c"
71#include "u_ether.c"
Anna Perela8c991d2012-04-09 16:44:46 +030072#include "u_bam_data.c"
73#include "f_mbim.c"
Ofir Cohen7b155422012-07-31 13:02:49 +030074#include "f_qc_ecm.c"
75#include "u_qc_ether.c"
Pavankumar Kondeti8f6ca4f2012-06-26 09:44:36 +053076#ifdef CONFIG_TARGET_CORE
77#include "f_tcm.c"
78#endif
Benoit Goby1e8ce152011-12-12 13:01:23 -080079
80MODULE_AUTHOR("Mike Lockwood");
81MODULE_DESCRIPTION("Android Composite USB Driver");
82MODULE_LICENSE("GPL");
83MODULE_VERSION("1.0");
84
85static const char longname[] = "Gadget Android";
86
87/* Default vendor and product IDs, overridden by userspace */
88#define VENDOR_ID 0x18D1
89#define PRODUCT_ID 0x0001
90
Ido Shayevitz23dc77c2012-07-18 16:16:06 +030091#define ANDROID_DEVICE_NODE_NAME_LENGTH 11
92
Benoit Goby1e8ce152011-12-12 13:01:23 -080093struct android_usb_function {
94 char *name;
95 void *config;
96
97 struct device *dev;
98 char *dev_name;
99 struct device_attribute **attributes;
100
101 /* for android_dev.enabled_functions */
102 struct list_head enabled_list;
103
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300104 struct android_dev *android_dev;
105
Benoit Goby1e8ce152011-12-12 13:01:23 -0800106 /* Optional: initialization during gadget bind */
107 int (*init)(struct android_usb_function *, struct usb_composite_dev *);
108 /* Optional: cleanup during gadget unbind */
109 void (*cleanup)(struct android_usb_function *);
Benoit Goby80ba14d2012-03-19 18:56:52 -0700110 /* Optional: called when the function is added the list of
111 * enabled functions */
112 void (*enable)(struct android_usb_function *);
113 /* Optional: called when it is removed */
114 void (*disable)(struct android_usb_function *);
Benoit Goby1e8ce152011-12-12 13:01:23 -0800115
116 int (*bind_config)(struct android_usb_function *,
117 struct usb_configuration *);
118
119 /* Optional: called when the configuration is removed */
120 void (*unbind_config)(struct android_usb_function *,
121 struct usb_configuration *);
122 /* Optional: handle ctrl requests before the device is configured */
123 int (*ctrlrequest)(struct android_usb_function *,
124 struct usb_composite_dev *,
125 const struct usb_ctrlrequest *);
126};
127
128struct android_dev {
129 struct android_usb_function **functions;
130 struct list_head enabled_functions;
131 struct usb_composite_dev *cdev;
132 struct device *dev;
133
134 bool enabled;
Benoit Goby80ba14d2012-03-19 18:56:52 -0700135 int disable_depth;
Benoit Goby1e8ce152011-12-12 13:01:23 -0800136 struct mutex mutex;
Steve Mucklef132c6c2012-06-06 18:30:57 -0700137 struct android_usb_platform_data *pdata;
138
Benoit Goby1e8ce152011-12-12 13:01:23 -0800139 bool connected;
140 bool sw_connected;
Ofir Cohen94213a72012-05-03 14:26:32 +0300141 char pm_qos[5];
Steve Mucklef132c6c2012-06-06 18:30:57 -0700142 struct pm_qos_request pm_qos_req_dma;
Benoit Goby1e8ce152011-12-12 13:01:23 -0800143 struct work_struct work;
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300144
145 struct list_head list_item;
146
147 struct usb_configuration config;
Benoit Goby1e8ce152011-12-12 13:01:23 -0800148};
149
150static struct class *android_class;
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300151static struct list_head android_dev_list;
152static int android_dev_count;
Benoit Goby1e8ce152011-12-12 13:01:23 -0800153static int android_bind_config(struct usb_configuration *c);
154static void android_unbind_config(struct usb_configuration *c);
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300155static struct android_dev *cdev_to_android_dev(struct usb_composite_dev *cdev);
Benoit Goby1e8ce152011-12-12 13:01:23 -0800156
157/* string IDs are assigned dynamically */
158#define STRING_MANUFACTURER_IDX 0
159#define STRING_PRODUCT_IDX 1
160#define STRING_SERIAL_IDX 2
161
162static char manufacturer_string[256];
163static char product_string[256];
164static char serial_string[256];
165
166/* String Table */
167static struct usb_string strings_dev[] = {
168 [STRING_MANUFACTURER_IDX].s = manufacturer_string,
169 [STRING_PRODUCT_IDX].s = product_string,
170 [STRING_SERIAL_IDX].s = serial_string,
171 { } /* end of list */
172};
173
174static struct usb_gadget_strings stringtab_dev = {
175 .language = 0x0409, /* en-us */
176 .strings = strings_dev,
177};
178
179static struct usb_gadget_strings *dev_strings[] = {
180 &stringtab_dev,
181 NULL,
182};
183
184static struct usb_device_descriptor device_desc = {
185 .bLength = sizeof(device_desc),
186 .bDescriptorType = USB_DT_DEVICE,
187 .bcdUSB = __constant_cpu_to_le16(0x0200),
188 .bDeviceClass = USB_CLASS_PER_INTERFACE,
189 .idVendor = __constant_cpu_to_le16(VENDOR_ID),
190 .idProduct = __constant_cpu_to_le16(PRODUCT_ID),
191 .bcdDevice = __constant_cpu_to_le16(0xffff),
192 .bNumConfigurations = 1,
193};
194
Vijayavardhan Vennapusa56e60522012-02-16 15:40:16 +0530195static struct usb_otg_descriptor otg_descriptor = {
196 .bLength = sizeof otg_descriptor,
197 .bDescriptorType = USB_DT_OTG,
198 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
199 .bcdOTG = __constant_cpu_to_le16(0x0200),
200};
201
202static const struct usb_descriptor_header *otg_desc[] = {
203 (struct usb_descriptor_header *) &otg_descriptor,
204 NULL,
205};
206
Manu Gautama2b54142012-04-03 14:34:32 +0530207enum android_device_state {
208 USB_DISCONNECTED,
209 USB_CONNECTED,
210 USB_CONFIGURED,
211};
212
Ofir Cohen94213a72012-05-03 14:26:32 +0300213static void android_pm_qos_update_latency(struct android_dev *dev, int vote)
214{
215 struct android_usb_platform_data *pdata = dev->pdata;
216 u32 swfi_latency = 0;
217 static int last_vote = -1;
218
Ofir Cohen56eb7072012-05-20 11:41:39 +0300219 if (!pdata || vote == last_vote
220 || !pdata->swfi_latency)
Ofir Cohen94213a72012-05-03 14:26:32 +0300221 return;
222
223 swfi_latency = pdata->swfi_latency + 1;
224 if (vote)
225 pm_qos_update_request(&dev->pm_qos_req_dma,
226 swfi_latency);
227 else
228 pm_qos_update_request(&dev->pm_qos_req_dma,
229 PM_QOS_DEFAULT_VALUE);
230 last_vote = vote;
231}
232
Benoit Goby1e8ce152011-12-12 13:01:23 -0800233static void android_work(struct work_struct *data)
234{
235 struct android_dev *dev = container_of(data, struct android_dev, work);
236 struct usb_composite_dev *cdev = dev->cdev;
237 char *disconnected[2] = { "USB_STATE=DISCONNECTED", NULL };
238 char *connected[2] = { "USB_STATE=CONNECTED", NULL };
239 char *configured[2] = { "USB_STATE=CONFIGURED", NULL };
240 char **uevent_envp = NULL;
Manu Gautama2b54142012-04-03 14:34:32 +0530241 static enum android_device_state last_uevent, next_state;
Benoit Goby1e8ce152011-12-12 13:01:23 -0800242 unsigned long flags;
Ofir Cohenbcbb1a72012-05-20 16:28:15 +0300243 int pm_qos_vote = -1;
Benoit Goby1e8ce152011-12-12 13:01:23 -0800244
245 spin_lock_irqsave(&cdev->lock, flags);
Manu Gautama2b54142012-04-03 14:34:32 +0530246 if (cdev->config) {
Benoit Goby1e8ce152011-12-12 13:01:23 -0800247 uevent_envp = configured;
Manu Gautama2b54142012-04-03 14:34:32 +0530248 next_state = USB_CONFIGURED;
249 } else if (dev->connected != dev->sw_connected) {
Benoit Goby1e8ce152011-12-12 13:01:23 -0800250 uevent_envp = dev->connected ? connected : disconnected;
Manu Gautama2b54142012-04-03 14:34:32 +0530251 next_state = dev->connected ? USB_CONNECTED : USB_DISCONNECTED;
Ofir Cohen94213a72012-05-03 14:26:32 +0300252 if (dev->connected && strncmp(dev->pm_qos, "low", 3))
Ofir Cohenbcbb1a72012-05-20 16:28:15 +0300253 pm_qos_vote = 1;
Ofir Cohen94213a72012-05-03 14:26:32 +0300254 else if (!dev->connected || !strncmp(dev->pm_qos, "low", 3))
Ofir Cohenbcbb1a72012-05-20 16:28:15 +0300255 pm_qos_vote = 0;
Manu Gautama2b54142012-04-03 14:34:32 +0530256 }
Benoit Goby1e8ce152011-12-12 13:01:23 -0800257 dev->sw_connected = dev->connected;
258 spin_unlock_irqrestore(&cdev->lock, flags);
259
Ofir Cohenbcbb1a72012-05-20 16:28:15 +0300260 if (pm_qos_vote != -1)
261 android_pm_qos_update_latency(dev, pm_qos_vote);
262
Benoit Goby1e8ce152011-12-12 13:01:23 -0800263 if (uevent_envp) {
Manu Gautama2b54142012-04-03 14:34:32 +0530264 /*
265 * Some userspace modules, e.g. MTP, work correctly only if
266 * CONFIGURED uevent is preceded by DISCONNECT uevent.
267 * Check if we missed sending out a DISCONNECT uevent. This can
268 * happen if host PC resets and configures device really quick.
269 */
270 if (((uevent_envp == connected) &&
271 (last_uevent != USB_DISCONNECTED)) ||
272 ((uevent_envp == configured) &&
273 (last_uevent == USB_CONFIGURED))) {
274 pr_info("%s: sent missed DISCONNECT event\n", __func__);
275 kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE,
276 disconnected);
277 msleep(20);
278 }
279 /*
280 * Before sending out CONFIGURED uevent give function drivers
281 * a chance to wakeup userspace threads and notify disconnect
282 */
283 if (uevent_envp == configured)
284 msleep(50);
285
Benoit Goby1e8ce152011-12-12 13:01:23 -0800286 kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE, uevent_envp);
Manu Gautama2b54142012-04-03 14:34:32 +0530287 last_uevent = next_state;
Benoit Goby1e8ce152011-12-12 13:01:23 -0800288 pr_info("%s: sent uevent %s\n", __func__, uevent_envp[0]);
289 } else {
290 pr_info("%s: did not send uevent (%d %d %p)\n", __func__,
291 dev->connected, dev->sw_connected, cdev->config);
292 }
293}
294
Benoit Goby80ba14d2012-03-19 18:56:52 -0700295static void android_enable(struct android_dev *dev)
296{
297 struct usb_composite_dev *cdev = dev->cdev;
298
299 if (WARN_ON(!dev->disable_depth))
300 return;
301
302 if (--dev->disable_depth == 0) {
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300303 usb_add_config(cdev, &dev->config,
Benoit Goby80ba14d2012-03-19 18:56:52 -0700304 android_bind_config);
305 usb_gadget_connect(cdev->gadget);
306 }
307}
308
309static void android_disable(struct android_dev *dev)
310{
311 struct usb_composite_dev *cdev = dev->cdev;
312
313 if (dev->disable_depth++ == 0) {
314 usb_gadget_disconnect(cdev->gadget);
315 /* Cancel pending control requests */
316 usb_ep_dequeue(cdev->gadget->ep0, cdev->req);
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300317 usb_remove_config(cdev, &dev->config);
Benoit Goby80ba14d2012-03-19 18:56:52 -0700318 }
319}
Benoit Goby1e8ce152011-12-12 13:01:23 -0800320
321/*-------------------------------------------------------------------------*/
322/* Supported functions initialization */
323
Benoit Goby80ba14d2012-03-19 18:56:52 -0700324struct adb_data {
325 bool opened;
326 bool enabled;
327};
328
Benoit Goby2b6862d2011-12-19 14:38:41 -0800329static int
330adb_function_init(struct android_usb_function *f,
331 struct usb_composite_dev *cdev)
332{
Benoit Goby80ba14d2012-03-19 18:56:52 -0700333 f->config = kzalloc(sizeof(struct adb_data), GFP_KERNEL);
334 if (!f->config)
335 return -ENOMEM;
336
Benoit Goby2b6862d2011-12-19 14:38:41 -0800337 return adb_setup();
338}
339
340static void adb_function_cleanup(struct android_usb_function *f)
341{
342 adb_cleanup();
Benoit Goby80ba14d2012-03-19 18:56:52 -0700343 kfree(f->config);
Benoit Goby2b6862d2011-12-19 14:38:41 -0800344}
345
346static int
347adb_function_bind_config(struct android_usb_function *f,
348 struct usb_configuration *c)
349{
350 return adb_bind_config(c);
351}
352
Benoit Goby80ba14d2012-03-19 18:56:52 -0700353static void adb_android_function_enable(struct android_usb_function *f)
354{
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300355 struct android_dev *dev = f->android_dev;
Benoit Goby80ba14d2012-03-19 18:56:52 -0700356 struct adb_data *data = f->config;
357
358 data->enabled = true;
359
360 /* Disable the gadget until adbd is ready */
361 if (!data->opened)
362 android_disable(dev);
363}
364
365static void adb_android_function_disable(struct android_usb_function *f)
366{
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300367 struct android_dev *dev = f->android_dev;
Benoit Goby80ba14d2012-03-19 18:56:52 -0700368 struct adb_data *data = f->config;
369
370 data->enabled = false;
371
372 /* Balance the disable that was called in closed_callback */
373 if (!data->opened)
374 android_enable(dev);
375}
376
Benoit Goby2b6862d2011-12-19 14:38:41 -0800377static struct android_usb_function adb_function = {
378 .name = "adb",
Benoit Goby80ba14d2012-03-19 18:56:52 -0700379 .enable = adb_android_function_enable,
380 .disable = adb_android_function_disable,
Benoit Goby2b6862d2011-12-19 14:38:41 -0800381 .init = adb_function_init,
382 .cleanup = adb_function_cleanup,
383 .bind_config = adb_function_bind_config,
384};
385
Benoit Goby80ba14d2012-03-19 18:56:52 -0700386static void adb_ready_callback(void)
387{
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300388 struct android_dev *dev = adb_function.android_dev;
Benoit Goby80ba14d2012-03-19 18:56:52 -0700389 struct adb_data *data = adb_function.config;
390
Benoit Goby80ba14d2012-03-19 18:56:52 -0700391 data->opened = true;
392
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300393 if (data->enabled && dev) {
394 mutex_lock(&dev->mutex);
Benoit Goby80ba14d2012-03-19 18:56:52 -0700395 android_enable(dev);
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300396 mutex_unlock(&dev->mutex);
397 }
Benoit Goby80ba14d2012-03-19 18:56:52 -0700398}
399
400static void adb_closed_callback(void)
401{
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300402 struct android_dev *dev = adb_function.android_dev;
Benoit Goby80ba14d2012-03-19 18:56:52 -0700403 struct adb_data *data = adb_function.config;
404
Benoit Goby80ba14d2012-03-19 18:56:52 -0700405 data->opened = false;
406
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300407 if (data->enabled) {
408 mutex_lock(&dev->mutex);
Benoit Goby80ba14d2012-03-19 18:56:52 -0700409 android_disable(dev);
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300410 mutex_unlock(&dev->mutex);
411 }
Benoit Goby80ba14d2012-03-19 18:56:52 -0700412}
413
Benoit Goby2b6862d2011-12-19 14:38:41 -0800414
Benoit Gobyaab96812011-04-19 20:37:33 -0700415/*-------------------------------------------------------------------------*/
416/* Supported functions initialization */
417
Manu Gautam8e0719b2011-09-26 14:47:55 +0530418/* RMNET_SMD */
Manu Gautam1c8ffd72011-09-02 16:00:49 +0530419static int rmnet_smd_function_bind_config(struct android_usb_function *f,
420 struct usb_configuration *c)
421{
422 return rmnet_smd_bind_config(c);
423}
424
425static struct android_usb_function rmnet_smd_function = {
426 .name = "rmnet_smd",
427 .bind_config = rmnet_smd_function_bind_config,
Benoit Goby1e8ce152011-12-12 13:01:23 -0800428};
429
Manu Gautam8e0719b2011-09-26 14:47:55 +0530430/* RMNET_SDIO */
431static int rmnet_sdio_function_bind_config(struct android_usb_function *f,
432 struct usb_configuration *c)
Benoit Goby1e8ce152011-12-12 13:01:23 -0800433{
Manu Gautam8e0719b2011-09-26 14:47:55 +0530434 return rmnet_sdio_function_add(c);
Benoit Goby1e8ce152011-12-12 13:01:23 -0800435}
436
Manu Gautam8e0719b2011-09-26 14:47:55 +0530437static struct android_usb_function rmnet_sdio_function = {
438 .name = "rmnet_sdio",
439 .bind_config = rmnet_sdio_function_bind_config,
440};
441
442/* RMNET_SMD_SDIO */
443static int rmnet_smd_sdio_function_init(struct android_usb_function *f,
444 struct usb_composite_dev *cdev)
445{
446 return rmnet_smd_sdio_init();
447}
448
449static void rmnet_smd_sdio_function_cleanup(struct android_usb_function *f)
450{
451 rmnet_smd_sdio_cleanup();
452}
453
454static int rmnet_smd_sdio_bind_config(struct android_usb_function *f,
455 struct usb_configuration *c)
456{
457 return rmnet_smd_sdio_function_add(c);
458}
459
460static struct device_attribute *rmnet_smd_sdio_attributes[] = {
461 &dev_attr_transport, NULL };
462
463static struct android_usb_function rmnet_smd_sdio_function = {
464 .name = "rmnet_smd_sdio",
465 .init = rmnet_smd_sdio_function_init,
466 .cleanup = rmnet_smd_sdio_function_cleanup,
467 .bind_config = rmnet_smd_sdio_bind_config,
468 .attributes = rmnet_smd_sdio_attributes,
469};
470
Hemant Kumar1b820d52011-11-03 15:08:28 -0700471/*rmnet transport string format(per port):"ctrl0,data0,ctrl1,data1..." */
472#define MAX_XPORT_STR_LEN 50
473static char rmnet_transports[MAX_XPORT_STR_LEN];
Manu Gautam1c8ffd72011-09-02 16:00:49 +0530474
Manu Gautame3e897c2011-09-12 17:18:46 +0530475static void rmnet_function_cleanup(struct android_usb_function *f)
476{
477 frmnet_cleanup();
478}
479
Manu Gautam2b0234a2011-09-07 16:47:52 +0530480static int rmnet_function_bind_config(struct android_usb_function *f,
481 struct usb_configuration *c)
482{
483 int i;
Hemant Kumar1b820d52011-11-03 15:08:28 -0700484 int err = 0;
485 char *ctrl_name;
486 char *data_name;
487 char buf[MAX_XPORT_STR_LEN], *b;
488 static int rmnet_initialized, ports;
Manu Gautam2b0234a2011-09-07 16:47:52 +0530489
Hemant Kumar1b820d52011-11-03 15:08:28 -0700490 if (!rmnet_initialized) {
491 rmnet_initialized = 1;
492 strlcpy(buf, rmnet_transports, sizeof(buf));
493 b = strim(buf);
494 while (b) {
495 ctrl_name = strsep(&b, ",");
496 data_name = strsep(&b, ",");
497 if (ctrl_name && data_name) {
498 err = frmnet_init_port(ctrl_name, data_name);
499 if (err) {
500 pr_err("rmnet: Cannot open ctrl port:"
501 "'%s' data port:'%s'\n",
502 ctrl_name, data_name);
503 goto out;
504 }
505 ports++;
506 }
507 }
508
509 err = rmnet_gport_setup();
510 if (err) {
511 pr_err("rmnet: Cannot setup transports");
512 goto out;
513 }
514 }
515
516 for (i = 0; i < ports; i++) {
517 err = frmnet_bind_config(c, i);
518 if (err) {
Manu Gautam2b0234a2011-09-07 16:47:52 +0530519 pr_err("Could not bind rmnet%u config\n", i);
520 break;
521 }
522 }
Hemant Kumar1b820d52011-11-03 15:08:28 -0700523out:
524 return err;
Manu Gautam2b0234a2011-09-07 16:47:52 +0530525}
526
Hemant Kumar1b820d52011-11-03 15:08:28 -0700527static ssize_t rmnet_transports_show(struct device *dev,
Manu Gautam2b0234a2011-09-07 16:47:52 +0530528 struct device_attribute *attr, char *buf)
529{
Hemant Kumar1b820d52011-11-03 15:08:28 -0700530 return snprintf(buf, PAGE_SIZE, "%s\n", rmnet_transports);
Manu Gautam2b0234a2011-09-07 16:47:52 +0530531}
532
Hemant Kumar1b820d52011-11-03 15:08:28 -0700533static ssize_t rmnet_transports_store(
534 struct device *device, struct device_attribute *attr,
535 const char *buff, size_t size)
Manu Gautam2b0234a2011-09-07 16:47:52 +0530536{
Hemant Kumar1b820d52011-11-03 15:08:28 -0700537 strlcpy(rmnet_transports, buff, sizeof(rmnet_transports));
Manu Gautam2b0234a2011-09-07 16:47:52 +0530538
Manu Gautam2b0234a2011-09-07 16:47:52 +0530539 return size;
540}
541
Hemant Kumar1b820d52011-11-03 15:08:28 -0700542static struct device_attribute dev_attr_rmnet_transports =
543 __ATTR(transports, S_IRUGO | S_IWUSR,
544 rmnet_transports_show,
545 rmnet_transports_store);
Manu Gautam2b0234a2011-09-07 16:47:52 +0530546static struct device_attribute *rmnet_function_attributes[] = {
Hemant Kumar1b820d52011-11-03 15:08:28 -0700547 &dev_attr_rmnet_transports,
548 NULL };
Manu Gautam2b0234a2011-09-07 16:47:52 +0530549
550static struct android_usb_function rmnet_function = {
551 .name = "rmnet",
Manu Gautame3e897c2011-09-12 17:18:46 +0530552 .cleanup = rmnet_function_cleanup,
Manu Gautam2b0234a2011-09-07 16:47:52 +0530553 .bind_config = rmnet_function_bind_config,
554 .attributes = rmnet_function_attributes,
555};
556
Ofir Cohen7b155422012-07-31 13:02:49 +0300557struct ecm_function_config {
558 u8 ethaddr[ETH_ALEN];
559};
560
561static int ecm_function_init(struct android_usb_function *f,
562 struct usb_composite_dev *cdev)
563{
564 f->config = kzalloc(sizeof(struct ecm_function_config), GFP_KERNEL);
565 if (!f->config)
566 return -ENOMEM;
567 return 0;
568}
569
570static void ecm_function_cleanup(struct android_usb_function *f)
571{
572 kfree(f->config);
573 f->config = NULL;
574}
575
576static int ecm_qc_function_bind_config(struct android_usb_function *f,
577 struct usb_configuration *c)
578{
579 int ret;
580 struct ecm_function_config *ecm = f->config;
581
582 if (!ecm) {
583 pr_err("%s: ecm_pdata\n", __func__);
584 return -EINVAL;
585 }
586
587 pr_info("%s MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", __func__,
588 ecm->ethaddr[0], ecm->ethaddr[1], ecm->ethaddr[2],
589 ecm->ethaddr[3], ecm->ethaddr[4], ecm->ethaddr[5]);
590
591 ret = gether_qc_setup_name(c->cdev->gadget, ecm->ethaddr, "ecm");
592 if (ret) {
593 pr_err("%s: gether_setup failed\n", __func__);
594 return ret;
595 }
596
597 return ecm_qc_bind_config(c, ecm->ethaddr);
598}
599
600static void ecm_qc_function_unbind_config(struct android_usb_function *f,
601 struct usb_configuration *c)
602{
603 gether_qc_cleanup();
604}
605
606static ssize_t ecm_ethaddr_show(struct device *dev,
607 struct device_attribute *attr, char *buf)
608{
609 struct android_usb_function *f = dev_get_drvdata(dev);
610 struct ecm_function_config *ecm = f->config;
611 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
612 ecm->ethaddr[0], ecm->ethaddr[1], ecm->ethaddr[2],
613 ecm->ethaddr[3], ecm->ethaddr[4], ecm->ethaddr[5]);
614}
615
616static ssize_t ecm_ethaddr_store(struct device *dev,
617 struct device_attribute *attr, const char *buf, size_t size)
618{
619 struct android_usb_function *f = dev_get_drvdata(dev);
620 struct ecm_function_config *ecm = f->config;
621
622 if (sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
623 (int *)&ecm->ethaddr[0], (int *)&ecm->ethaddr[1],
624 (int *)&ecm->ethaddr[2], (int *)&ecm->ethaddr[3],
625 (int *)&ecm->ethaddr[4], (int *)&ecm->ethaddr[5]) == 6)
626 return size;
627 return -EINVAL;
628}
629
630static DEVICE_ATTR(ecm_ethaddr, S_IRUGO | S_IWUSR, ecm_ethaddr_show,
631 ecm_ethaddr_store);
632
633static struct device_attribute *ecm_function_attributes[] = {
634 &dev_attr_ecm_ethaddr,
635 NULL
636};
637
638static struct android_usb_function ecm_qc_function = {
639 .name = "ecm_qc",
640 .init = ecm_function_init,
641 .cleanup = ecm_function_cleanup,
642 .bind_config = ecm_qc_function_bind_config,
643 .unbind_config = ecm_qc_function_unbind_config,
644 .attributes = ecm_function_attributes,
645};
Anna Perela8c991d2012-04-09 16:44:46 +0300646
647/* MBIM - used with BAM */
648#define MAX_MBIM_INSTANCES 1
649
650static int mbim_function_init(struct android_usb_function *f,
651 struct usb_composite_dev *cdev)
652{
653 return mbim_init(MAX_MBIM_INSTANCES);
654}
655
656static void mbim_function_cleanup(struct android_usb_function *f)
657{
658 fmbim_cleanup();
659}
660
661static int mbim_function_bind_config(struct android_usb_function *f,
662 struct usb_configuration *c)
663{
664 return mbim_bind_config(c, 0);
665}
666
667static struct android_usb_function mbim_function = {
668 .name = "usb_mbim",
669 .cleanup = mbim_function_cleanup,
670 .bind_config = mbim_function_bind_config,
671 .init = mbim_function_init,
672};
673
674
Manu Gautam8e0719b2011-09-26 14:47:55 +0530675/* DIAG */
Manu Gautam2b0234a2011-09-07 16:47:52 +0530676static char diag_clients[32]; /*enabled DIAG clients- "diag[,diag_mdm]" */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700677static ssize_t clients_store(
678 struct device *device, struct device_attribute *attr,
679 const char *buff, size_t size)
680{
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +0530681 strlcpy(diag_clients, buff, sizeof(diag_clients));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700682
683 return size;
684}
685
686static DEVICE_ATTR(clients, S_IWUSR, NULL, clients_store);
687static struct device_attribute *diag_function_attributes[] =
688 { &dev_attr_clients, NULL };
689
690static int diag_function_init(struct android_usb_function *f,
691 struct usb_composite_dev *cdev)
692{
693 return diag_setup();
694}
695
696static void diag_function_cleanup(struct android_usb_function *f)
697{
698 diag_cleanup();
699}
700
701static int diag_function_bind_config(struct android_usb_function *f,
702 struct usb_configuration *c)
703{
704 char *name;
705 char buf[32], *b;
Manu Gautamc5760302011-08-25 14:30:24 +0530706 int once = 0, err = -1;
Jack Phamb830a6c2011-12-12 22:35:27 -0800707 int (*notify)(uint32_t, const char *);
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300708 struct android_dev *dev = cdev_to_android_dev(c->cdev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700709
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +0530710 strlcpy(buf, diag_clients, sizeof(buf));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700711 b = strim(buf);
712
713 while (b) {
Jack Phamb830a6c2011-12-12 22:35:27 -0800714 notify = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700715 name = strsep(&b, ",");
Manu Gautamc5760302011-08-25 14:30:24 +0530716 /* Allow only first diag channel to update pid and serial no */
Ido Shayevitz23dc77c2012-07-18 16:16:06 +0300717 if (dev->pdata && !once++)
718 notify = dev->pdata->update_pid_and_serial_num;
Manu Gautamc5760302011-08-25 14:30:24 +0530719
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700720 if (name) {
Manu Gautamc5760302011-08-25 14:30:24 +0530721 err = diag_function_add(c, name, notify);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700722 if (err)
723 pr_err("diag: Cannot open channel '%s'", name);
724 }
725 }
726
727 return err;
728}
729
730static struct android_usb_function diag_function = {
731 .name = "diag",
732 .init = diag_function_init,
733 .cleanup = diag_function_cleanup,
734 .bind_config = diag_function_bind_config,
735 .attributes = diag_function_attributes,
736};
737
Manu Gautam8e0719b2011-09-26 14:47:55 +0530738/* SERIAL */
Manu Gautam2b0234a2011-09-07 16:47:52 +0530739static char serial_transports[32]; /*enabled FSERIAL ports - "tty[,sdio]"*/
Manu Gautama4d993f2011-08-30 18:25:55 +0530740static ssize_t serial_transports_store(
741 struct device *device, struct device_attribute *attr,
742 const char *buff, size_t size)
743{
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +0530744 strlcpy(serial_transports, buff, sizeof(serial_transports));
Manu Gautama4d993f2011-08-30 18:25:55 +0530745
746 return size;
747}
748
749static DEVICE_ATTR(transports, S_IWUSR, NULL, serial_transports_store);
750static struct device_attribute *serial_function_attributes[] =
751 { &dev_attr_transports, NULL };
752
753static void serial_function_cleanup(struct android_usb_function *f)
754{
755 gserial_cleanup();
756}
757
758static int serial_function_bind_config(struct android_usb_function *f,
759 struct usb_configuration *c)
760{
761 char *name;
762 char buf[32], *b;
763 int err = -1, i;
764 static int serial_initialized = 0, ports = 0;
765
766 if (serial_initialized)
767 goto bind_config;
768
769 serial_initialized = 1;
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +0530770 strlcpy(buf, serial_transports, sizeof(buf));
Manu Gautama4d993f2011-08-30 18:25:55 +0530771 b = strim(buf);
772
773 while (b) {
774 name = strsep(&b, ",");
775
776 if (name) {
777 err = gserial_init_port(ports, name);
778 if (err) {
779 pr_err("serial: Cannot open port '%s'", name);
780 goto out;
781 }
782 ports++;
783 }
784 }
785 err = gport_setup(c);
786 if (err) {
787 pr_err("serial: Cannot setup transports");
788 goto out;
789 }
790
791bind_config:
Lena Salmand092f2d2012-03-12 17:27:24 +0200792 for (i = 0; i < ports; i++) {
Manu Gautama4d993f2011-08-30 18:25:55 +0530793 err = gser_bind_config(c, i);
794 if (err) {
795 pr_err("serial: bind_config failed for port %d", i);
796 goto out;
797 }
798 }
799
800out:
801 return err;
802}
803
804static struct android_usb_function serial_function = {
805 .name = "serial",
806 .cleanup = serial_function_cleanup,
807 .bind_config = serial_function_bind_config,
808 .attributes = serial_function_attributes,
809};
810
Anji jonnala92be1b42011-12-19 09:44:41 +0530811/* ACM */
812static char acm_transports[32]; /*enabled ACM ports - "tty[,sdio]"*/
813static ssize_t acm_transports_store(
814 struct device *device, struct device_attribute *attr,
815 const char *buff, size_t size)
816{
817 strlcpy(acm_transports, buff, sizeof(acm_transports));
818
819 return size;
820}
821
822static DEVICE_ATTR(acm_transports, S_IWUSR, NULL, acm_transports_store);
823static struct device_attribute *acm_function_attributes[] = {
824 &dev_attr_acm_transports, NULL };
825
Benoit Goby1e8ce152011-12-12 13:01:23 -0800826static void acm_function_cleanup(struct android_usb_function *f)
827{
828 gserial_cleanup();
Benoit Goby1e8ce152011-12-12 13:01:23 -0800829}
830
Anji jonnala92be1b42011-12-19 09:44:41 +0530831static int acm_function_bind_config(struct android_usb_function *f,
832 struct usb_configuration *c)
Benoit Goby1e8ce152011-12-12 13:01:23 -0800833{
Anji jonnala92be1b42011-12-19 09:44:41 +0530834 char *name;
835 char buf[32], *b;
836 int err = -1, i;
837 static int acm_initialized, ports;
Benoit Goby1e8ce152011-12-12 13:01:23 -0800838
Anji jonnala92be1b42011-12-19 09:44:41 +0530839 if (acm_initialized)
840 goto bind_config;
841
842 acm_initialized = 1;
843 strlcpy(buf, acm_transports, sizeof(buf));
844 b = strim(buf);
845
846 while (b) {
847 name = strsep(&b, ",");
848
849 if (name) {
850 err = acm_init_port(ports, name);
851 if (err) {
852 pr_err("acm: Cannot open port '%s'", name);
853 goto out;
854 }
855 ports++;
856 }
857 }
858 err = acm_port_setup(c);
859 if (err) {
860 pr_err("acm: Cannot setup transports");
861 goto out;
862 }
863
864bind_config:
865 for (i = 0; i < ports; i++) {
866 err = acm_bind_config(c, i);
867 if (err) {
868 pr_err("acm: bind_config failed for port %d", i);
869 goto out;
Benoit Goby1e8ce152011-12-12 13:01:23 -0800870 }
871 }
872
Anji jonnala92be1b42011-12-19 09:44:41 +0530873out:
874 return err;
Benoit Goby1e8ce152011-12-12 13:01:23 -0800875}
Benoit Goby1e8ce152011-12-12 13:01:23 -0800876static struct android_usb_function acm_function = {
877 .name = "acm",
Benoit Goby1e8ce152011-12-12 13:01:23 -0800878 .cleanup = acm_function_cleanup,
879 .bind_config = acm_function_bind_config,
880 .attributes = acm_function_attributes,
881};
882
Chiranjeevi Velempatie130fd02011-11-29 05:06:13 +0530883/* CCID */
884static int ccid_function_init(struct android_usb_function *f,
885 struct usb_composite_dev *cdev)
886{
887 return ccid_setup();
888}
Benoit Goby1e8ce152011-12-12 13:01:23 -0800889
Chiranjeevi Velempatie130fd02011-11-29 05:06:13 +0530890static void ccid_function_cleanup(struct android_usb_function *f)
891{
892 ccid_cleanup();
893}
894
895static int ccid_function_bind_config(struct android_usb_function *f,
896 struct usb_configuration *c)
897{
898 return ccid_bind_config(c);
899}
900
901static struct android_usb_function ccid_function = {
902 .name = "ccid",
903 .init = ccid_function_init,
904 .cleanup = ccid_function_cleanup,
905 .bind_config = ccid_function_bind_config,
906};
907
Steve Mucklef132c6c2012-06-06 18:30:57 -0700908static int mtp_function_init(struct android_usb_function *f,
Benoit Gobyf0fbc482011-12-19 14:37:50 -0800909 struct usb_composite_dev *cdev)
910{
911 return mtp_setup();
912}
913
914static void mtp_function_cleanup(struct android_usb_function *f)
915{
916 mtp_cleanup();
917}
918
Steve Mucklef132c6c2012-06-06 18:30:57 -0700919static int mtp_function_bind_config(struct android_usb_function *f,
Benoit Gobyf0fbc482011-12-19 14:37:50 -0800920 struct usb_configuration *c)
921{
922 return mtp_bind_config(c, false);
923}
924
Mike Lockwoodcf7addf2011-06-01 22:17:36 -0400925static int ptp_function_init(struct android_usb_function *f, struct usb_composite_dev *cdev)
Benoit Gobyf0fbc482011-12-19 14:37:50 -0800926{
927 /* nothing to do - initialization is handled by mtp_function_init */
928 return 0;
929}
930
931static void ptp_function_cleanup(struct android_usb_function *f)
932{
933 /* nothing to do - cleanup is handled by mtp_function_cleanup */
934}
935
Mike Lockwoodcf7addf2011-06-01 22:17:36 -0400936static int ptp_function_bind_config(struct android_usb_function *f, struct usb_configuration *c)
Benoit Gobyf0fbc482011-12-19 14:37:50 -0800937{
938 return mtp_bind_config(c, true);
939}
940
941static int mtp_function_ctrlrequest(struct android_usb_function *f,
942 struct usb_composite_dev *cdev,
943 const struct usb_ctrlrequest *c)
944{
945 return mtp_ctrlrequest(cdev, c);
946}
947
948static struct android_usb_function mtp_function = {
949 .name = "mtp",
950 .init = mtp_function_init,
951 .cleanup = mtp_function_cleanup,
952 .bind_config = mtp_function_bind_config,
953 .ctrlrequest = mtp_function_ctrlrequest,
954};
955
956/* PTP function is same as MTP with slightly different interface descriptor */
957static struct android_usb_function ptp_function = {
958 .name = "ptp",
959 .init = ptp_function_init,
960 .cleanup = ptp_function_cleanup,
961 .bind_config = ptp_function_bind_config,
962};
963
964
Benoit Goby1e8ce152011-12-12 13:01:23 -0800965struct rndis_function_config {
966 u8 ethaddr[ETH_ALEN];
967 u32 vendorID;
968 char manufacturer[256];
969 /* "Wireless" RNDIS; auto-detected by Windows */
970 bool wceis;
971};
972
973static int
974rndis_function_init(struct android_usb_function *f,
975 struct usb_composite_dev *cdev)
976{
977 f->config = kzalloc(sizeof(struct rndis_function_config), GFP_KERNEL);
978 if (!f->config)
979 return -ENOMEM;
980 return 0;
981}
982
983static void rndis_function_cleanup(struct android_usb_function *f)
984{
985 kfree(f->config);
986 f->config = NULL;
987}
988
989static int
990rndis_function_bind_config(struct android_usb_function *f,
991 struct usb_configuration *c)
992{
993 int ret;
994 struct rndis_function_config *rndis = f->config;
995
996 if (!rndis) {
997 pr_err("%s: rndis_pdata\n", __func__);
998 return -1;
999 }
1000
1001 pr_info("%s MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", __func__,
1002 rndis->ethaddr[0], rndis->ethaddr[1], rndis->ethaddr[2],
1003 rndis->ethaddr[3], rndis->ethaddr[4], rndis->ethaddr[5]);
1004
1005 ret = gether_setup_name(c->cdev->gadget, rndis->ethaddr, "rndis");
1006 if (ret) {
1007 pr_err("%s: gether_setup failed\n", __func__);
1008 return ret;
1009 }
1010
1011 if (rndis->wceis) {
1012 /* "Wireless" RNDIS; auto-detected by Windows */
1013 rndis_iad_descriptor.bFunctionClass =
1014 USB_CLASS_WIRELESS_CONTROLLER;
1015 rndis_iad_descriptor.bFunctionSubClass = 0x01;
1016 rndis_iad_descriptor.bFunctionProtocol = 0x03;
1017 rndis_control_intf.bInterfaceClass =
1018 USB_CLASS_WIRELESS_CONTROLLER;
1019 rndis_control_intf.bInterfaceSubClass = 0x01;
1020 rndis_control_intf.bInterfaceProtocol = 0x03;
1021 }
1022
1023 return rndis_bind_config_vendor(c, rndis->ethaddr, rndis->vendorID,
1024 rndis->manufacturer);
1025}
1026
1027static void rndis_function_unbind_config(struct android_usb_function *f,
1028 struct usb_configuration *c)
1029{
1030 gether_cleanup();
1031}
1032
1033static ssize_t rndis_manufacturer_show(struct device *dev,
1034 struct device_attribute *attr, char *buf)
1035{
1036 struct android_usb_function *f = dev_get_drvdata(dev);
1037 struct rndis_function_config *config = f->config;
Steve Mucklef132c6c2012-06-06 18:30:57 -07001038
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301039 return snprintf(buf, PAGE_SIZE, "%s\n", config->manufacturer);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001040}
1041
1042static ssize_t rndis_manufacturer_store(struct device *dev,
1043 struct device_attribute *attr, const char *buf, size_t size)
1044{
1045 struct android_usb_function *f = dev_get_drvdata(dev);
1046 struct rndis_function_config *config = f->config;
1047
1048 if (size >= sizeof(config->manufacturer))
1049 return -EINVAL;
Steve Mucklef132c6c2012-06-06 18:30:57 -07001050
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301051 if (sscanf(buf, "%255s", config->manufacturer) == 1)
Benoit Goby1e8ce152011-12-12 13:01:23 -08001052 return size;
1053 return -1;
1054}
1055
1056static DEVICE_ATTR(manufacturer, S_IRUGO | S_IWUSR, rndis_manufacturer_show,
1057 rndis_manufacturer_store);
1058
1059static ssize_t rndis_wceis_show(struct device *dev,
1060 struct device_attribute *attr, char *buf)
1061{
1062 struct android_usb_function *f = dev_get_drvdata(dev);
1063 struct rndis_function_config *config = f->config;
Steve Mucklef132c6c2012-06-06 18:30:57 -07001064
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301065 return snprintf(buf, PAGE_SIZE, "%d\n", config->wceis);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001066}
1067
1068static ssize_t rndis_wceis_store(struct device *dev,
1069 struct device_attribute *attr, const char *buf, size_t size)
1070{
1071 struct android_usb_function *f = dev_get_drvdata(dev);
1072 struct rndis_function_config *config = f->config;
1073 int value;
1074
1075 if (sscanf(buf, "%d", &value) == 1) {
1076 config->wceis = value;
1077 return size;
1078 }
1079 return -EINVAL;
1080}
1081
1082static DEVICE_ATTR(wceis, S_IRUGO | S_IWUSR, rndis_wceis_show,
1083 rndis_wceis_store);
1084
1085static ssize_t rndis_ethaddr_show(struct device *dev,
1086 struct device_attribute *attr, char *buf)
1087{
1088 struct android_usb_function *f = dev_get_drvdata(dev);
1089 struct rndis_function_config *rndis = f->config;
Steve Mucklef132c6c2012-06-06 18:30:57 -07001090
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301091 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
Benoit Goby1e8ce152011-12-12 13:01:23 -08001092 rndis->ethaddr[0], rndis->ethaddr[1], rndis->ethaddr[2],
1093 rndis->ethaddr[3], rndis->ethaddr[4], rndis->ethaddr[5]);
1094}
1095
1096static ssize_t rndis_ethaddr_store(struct device *dev,
1097 struct device_attribute *attr, const char *buf, size_t size)
1098{
1099 struct android_usb_function *f = dev_get_drvdata(dev);
1100 struct rndis_function_config *rndis = f->config;
1101
1102 if (sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1103 (int *)&rndis->ethaddr[0], (int *)&rndis->ethaddr[1],
1104 (int *)&rndis->ethaddr[2], (int *)&rndis->ethaddr[3],
1105 (int *)&rndis->ethaddr[4], (int *)&rndis->ethaddr[5]) == 6)
1106 return size;
1107 return -EINVAL;
1108}
1109
1110static DEVICE_ATTR(ethaddr, S_IRUGO | S_IWUSR, rndis_ethaddr_show,
1111 rndis_ethaddr_store);
1112
1113static ssize_t rndis_vendorID_show(struct device *dev,
1114 struct device_attribute *attr, char *buf)
1115{
1116 struct android_usb_function *f = dev_get_drvdata(dev);
1117 struct rndis_function_config *config = f->config;
Steve Mucklef132c6c2012-06-06 18:30:57 -07001118
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301119 return snprintf(buf, PAGE_SIZE, "%04x\n", config->vendorID);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001120}
1121
1122static ssize_t rndis_vendorID_store(struct device *dev,
1123 struct device_attribute *attr, const char *buf, size_t size)
1124{
1125 struct android_usb_function *f = dev_get_drvdata(dev);
1126 struct rndis_function_config *config = f->config;
1127 int value;
1128
1129 if (sscanf(buf, "%04x", &value) == 1) {
1130 config->vendorID = value;
1131 return size;
1132 }
1133 return -EINVAL;
1134}
1135
1136static DEVICE_ATTR(vendorID, S_IRUGO | S_IWUSR, rndis_vendorID_show,
1137 rndis_vendorID_store);
1138
1139static struct device_attribute *rndis_function_attributes[] = {
1140 &dev_attr_manufacturer,
1141 &dev_attr_wceis,
1142 &dev_attr_ethaddr,
1143 &dev_attr_vendorID,
1144 NULL
1145};
1146
1147static struct android_usb_function rndis_function = {
1148 .name = "rndis",
1149 .init = rndis_function_init,
1150 .cleanup = rndis_function_cleanup,
1151 .bind_config = rndis_function_bind_config,
1152 .unbind_config = rndis_function_unbind_config,
1153 .attributes = rndis_function_attributes,
1154};
1155
1156
1157struct mass_storage_function_config {
1158 struct fsg_config fsg;
1159 struct fsg_common *common;
1160};
1161
1162static int mass_storage_function_init(struct android_usb_function *f,
1163 struct usb_composite_dev *cdev)
1164{
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001165 struct android_dev *dev = cdev_to_android_dev(cdev);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001166 struct mass_storage_function_config *config;
1167 struct fsg_common *common;
1168 int err;
Rajkumar Raghupathyc9cb2052012-04-26 13:14:10 +05301169 int i;
1170 const char *name[2];
Benoit Goby1e8ce152011-12-12 13:01:23 -08001171
1172 config = kzalloc(sizeof(struct mass_storage_function_config),
1173 GFP_KERNEL);
1174 if (!config)
1175 return -ENOMEM;
1176
1177 config->fsg.nluns = 1;
Rajkumar Raghupathyc9cb2052012-04-26 13:14:10 +05301178 name[0] = "lun";
Pavankumar Kondeti2043e302012-07-19 08:54:04 +05301179 if (dev->pdata && dev->pdata->cdrom) {
Rajkumar Raghupathyc9cb2052012-04-26 13:14:10 +05301180 config->fsg.nluns = 2;
1181 config->fsg.luns[1].cdrom = 1;
1182 config->fsg.luns[1].ro = 1;
1183 config->fsg.luns[1].removable = 1;
1184 name[1] = "lun0";
1185 }
1186
Benoit Goby1e8ce152011-12-12 13:01:23 -08001187 config->fsg.luns[0].removable = 1;
1188
1189 common = fsg_common_init(NULL, cdev, &config->fsg);
1190 if (IS_ERR(common)) {
1191 kfree(config);
1192 return PTR_ERR(common);
1193 }
1194
Rajkumar Raghupathyc9cb2052012-04-26 13:14:10 +05301195 for (i = 0; i < config->fsg.nluns; i++) {
1196 err = sysfs_create_link(&f->dev->kobj,
1197 &common->luns[i].dev.kobj,
1198 name[i]);
1199 if (err)
1200 goto error;
Benoit Goby1e8ce152011-12-12 13:01:23 -08001201 }
1202
1203 config->common = common;
1204 f->config = config;
1205 return 0;
Rajkumar Raghupathyc9cb2052012-04-26 13:14:10 +05301206error:
1207 for (; i > 0 ; i--)
1208 sysfs_remove_link(&f->dev->kobj, name[i-1]);
1209
1210 fsg_common_release(&common->ref);
1211 kfree(config);
1212 return err;
Benoit Goby1e8ce152011-12-12 13:01:23 -08001213}
1214
1215static void mass_storage_function_cleanup(struct android_usb_function *f)
1216{
1217 kfree(f->config);
1218 f->config = NULL;
1219}
1220
1221static int mass_storage_function_bind_config(struct android_usb_function *f,
1222 struct usb_configuration *c)
1223{
1224 struct mass_storage_function_config *config = f->config;
1225 return fsg_bind_config(c->cdev, c, config->common);
1226}
1227
1228static ssize_t mass_storage_inquiry_show(struct device *dev,
1229 struct device_attribute *attr, char *buf)
1230{
1231 struct android_usb_function *f = dev_get_drvdata(dev);
1232 struct mass_storage_function_config *config = f->config;
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301233 return snprintf(buf, PAGE_SIZE, "%s\n", config->common->inquiry_string);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001234}
1235
1236static ssize_t mass_storage_inquiry_store(struct device *dev,
1237 struct device_attribute *attr, const char *buf, size_t size)
1238{
1239 struct android_usb_function *f = dev_get_drvdata(dev);
1240 struct mass_storage_function_config *config = f->config;
1241 if (size >= sizeof(config->common->inquiry_string))
1242 return -EINVAL;
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301243 if (sscanf(buf, "%28s", config->common->inquiry_string) != 1)
Benoit Goby1e8ce152011-12-12 13:01:23 -08001244 return -EINVAL;
1245 return size;
1246}
1247
1248static DEVICE_ATTR(inquiry_string, S_IRUGO | S_IWUSR,
1249 mass_storage_inquiry_show,
1250 mass_storage_inquiry_store);
1251
1252static struct device_attribute *mass_storage_function_attributes[] = {
1253 &dev_attr_inquiry_string,
1254 NULL
1255};
1256
1257static struct android_usb_function mass_storage_function = {
1258 .name = "mass_storage",
1259 .init = mass_storage_function_init,
1260 .cleanup = mass_storage_function_cleanup,
1261 .bind_config = mass_storage_function_bind_config,
1262 .attributes = mass_storage_function_attributes,
1263};
1264
1265
Benoit Gobycf3fc062011-12-19 14:39:37 -08001266static int accessory_function_init(struct android_usb_function *f,
1267 struct usb_composite_dev *cdev)
1268{
1269 return acc_setup();
1270}
1271
1272static void accessory_function_cleanup(struct android_usb_function *f)
1273{
1274 acc_cleanup();
1275}
1276
1277static int accessory_function_bind_config(struct android_usb_function *f,
1278 struct usb_configuration *c)
1279{
1280 return acc_bind_config(c);
1281}
1282
1283static int accessory_function_ctrlrequest(struct android_usb_function *f,
1284 struct usb_composite_dev *cdev,
1285 const struct usb_ctrlrequest *c)
1286{
1287 return acc_ctrlrequest(cdev, c);
1288}
1289
1290static struct android_usb_function accessory_function = {
1291 .name = "accessory",
1292 .init = accessory_function_init,
1293 .cleanup = accessory_function_cleanup,
1294 .bind_config = accessory_function_bind_config,
1295 .ctrlrequest = accessory_function_ctrlrequest,
1296};
1297
Pavankumar Kondeti8f6ca4f2012-06-26 09:44:36 +05301298static int android_uasp_connect_cb(bool connect)
1299{
1300 /*
1301 * TODO
1302 * We may have to disable gadget till UASP configfs nodes
1303 * are configured which includes mapping LUN with the
1304 * backing file. It is a fundamental difference between
1305 * f_mass_storage and f_tcp. That means UASP can not be
1306 * in default composition.
1307 *
1308 * For now, assume that UASP configfs nodes are configured
1309 * before enabling android gadget. Or cable should be
1310 * reconnected after mapping the LUN.
1311 *
1312 * Also consider making UASP to respond to Host requests when
1313 * Lun is not mapped.
1314 */
1315 pr_debug("UASP %s\n", connect ? "connect" : "disconnect");
1316
1317 return 0;
1318}
1319
1320static int uasp_function_init(struct android_usb_function *f,
1321 struct usb_composite_dev *cdev)
1322{
1323 return f_tcm_init(&android_uasp_connect_cb);
1324}
1325
1326static void uasp_function_cleanup(struct android_usb_function *f)
1327{
1328 f_tcm_exit();
1329}
1330
1331static int uasp_function_bind_config(struct android_usb_function *f,
1332 struct usb_configuration *c)
1333{
1334 return tcm_bind_config(c);
1335}
1336
1337static struct android_usb_function uasp_function = {
1338 .name = "uasp",
1339 .init = uasp_function_init,
1340 .cleanup = uasp_function_cleanup,
1341 .bind_config = uasp_function_bind_config,
1342};
Benoit Gobycf3fc062011-12-19 14:39:37 -08001343
Benoit Goby1e8ce152011-12-12 13:01:23 -08001344static struct android_usb_function *supported_functions[] = {
Anna Perela8c991d2012-04-09 16:44:46 +03001345 &mbim_function,
Ofir Cohen7b155422012-07-31 13:02:49 +03001346 &ecm_qc_function,
Manu Gautam1c8ffd72011-09-02 16:00:49 +05301347 &rmnet_smd_function,
Manu Gautam8e0719b2011-09-26 14:47:55 +05301348 &rmnet_sdio_function,
1349 &rmnet_smd_sdio_function,
Manu Gautam2b0234a2011-09-07 16:47:52 +05301350 &rmnet_function,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001351 &diag_function,
Manu Gautama4d993f2011-08-30 18:25:55 +05301352 &serial_function,
Benoit Goby2b6862d2011-12-19 14:38:41 -08001353 &adb_function,
Chiranjeevi Velempatie130fd02011-11-29 05:06:13 +05301354 &ccid_function,
Benoit Goby1e8ce152011-12-12 13:01:23 -08001355 &acm_function,
Benoit Gobyf0fbc482011-12-19 14:37:50 -08001356 &mtp_function,
1357 &ptp_function,
Benoit Goby1e8ce152011-12-12 13:01:23 -08001358 &rndis_function,
1359 &mass_storage_function,
Benoit Gobycf3fc062011-12-19 14:39:37 -08001360 &accessory_function,
Pavankumar Kondeti8f6ca4f2012-06-26 09:44:36 +05301361 &uasp_function,
Benoit Goby1e8ce152011-12-12 13:01:23 -08001362 NULL
1363};
1364
Lena Salmand092f2d2012-03-12 17:27:24 +02001365static void android_cleanup_functions(struct android_usb_function **functions)
1366{
1367 struct android_usb_function *f;
1368 struct device_attribute **attrs;
1369 struct device_attribute *attr;
1370
1371 while (*functions) {
1372 f = *functions++;
1373
1374 if (f->dev) {
1375 device_destroy(android_class, f->dev->devt);
1376 kfree(f->dev_name);
1377 } else
1378 continue;
1379
1380 if (f->cleanup)
1381 f->cleanup(f);
1382
1383 attrs = f->attributes;
1384 if (attrs) {
1385 while ((attr = *attrs++))
1386 device_remove_file(f->dev, attr);
1387 }
1388 }
1389}
Benoit Goby1e8ce152011-12-12 13:01:23 -08001390
1391static int android_init_functions(struct android_usb_function **functions,
1392 struct usb_composite_dev *cdev)
1393{
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001394 struct android_dev *dev = cdev_to_android_dev(cdev);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001395 struct android_usb_function *f;
1396 struct device_attribute **attrs;
1397 struct device_attribute *attr;
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301398 int err = 0;
Lena Salmand092f2d2012-03-12 17:27:24 +02001399 int index = 1; /* index 0 is for android0 device */
Benoit Goby1e8ce152011-12-12 13:01:23 -08001400
1401 for (; (f = *functions++); index++) {
1402 f->dev_name = kasprintf(GFP_KERNEL, "f_%s", f->name);
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001403 f->android_dev = NULL;
Lena Salmand092f2d2012-03-12 17:27:24 +02001404 if (!f->dev_name) {
1405 err = -ENOMEM;
1406 goto err_out;
1407 }
Benoit Goby1e8ce152011-12-12 13:01:23 -08001408 f->dev = device_create(android_class, dev->dev,
1409 MKDEV(0, index), f, f->dev_name);
1410 if (IS_ERR(f->dev)) {
1411 pr_err("%s: Failed to create dev %s", __func__,
1412 f->dev_name);
1413 err = PTR_ERR(f->dev);
Lena Salmand092f2d2012-03-12 17:27:24 +02001414 f->dev = NULL;
Benoit Goby1e8ce152011-12-12 13:01:23 -08001415 goto err_create;
1416 }
1417
1418 if (f->init) {
1419 err = f->init(f, cdev);
1420 if (err) {
1421 pr_err("%s: Failed to init %s", __func__,
1422 f->name);
Lena Salmand092f2d2012-03-12 17:27:24 +02001423 goto err_init;
Benoit Goby1e8ce152011-12-12 13:01:23 -08001424 }
1425 }
1426
1427 attrs = f->attributes;
1428 if (attrs) {
1429 while ((attr = *attrs++) && !err)
1430 err = device_create_file(f->dev, attr);
1431 }
1432 if (err) {
1433 pr_err("%s: Failed to create function %s attributes",
1434 __func__, f->name);
Lena Salmand092f2d2012-03-12 17:27:24 +02001435 goto err_attrs;
Benoit Goby1e8ce152011-12-12 13:01:23 -08001436 }
1437 }
1438 return 0;
1439
Lena Salmand092f2d2012-03-12 17:27:24 +02001440err_attrs:
1441 for (attr = *(attrs -= 2); attrs != f->attributes; attr = *(attrs--))
1442 device_remove_file(f->dev, attr);
1443 if (f->cleanup)
1444 f->cleanup(f);
1445err_init:
Benoit Goby1e8ce152011-12-12 13:01:23 -08001446 device_destroy(android_class, f->dev->devt);
1447err_create:
Lena Salmand092f2d2012-03-12 17:27:24 +02001448 f->dev = NULL;
Benoit Goby1e8ce152011-12-12 13:01:23 -08001449 kfree(f->dev_name);
Lena Salmand092f2d2012-03-12 17:27:24 +02001450err_out:
1451 android_cleanup_functions(dev->functions);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001452 return err;
1453}
1454
Benoit Goby1e8ce152011-12-12 13:01:23 -08001455static int
1456android_bind_enabled_functions(struct android_dev *dev,
1457 struct usb_configuration *c)
1458{
1459 struct android_usb_function *f;
1460 int ret;
1461
1462 list_for_each_entry(f, &dev->enabled_functions, enabled_list) {
1463 ret = f->bind_config(f, c);
1464 if (ret) {
1465 pr_err("%s: %s failed", __func__, f->name);
1466 return ret;
1467 }
1468 }
1469 return 0;
1470}
1471
1472static void
1473android_unbind_enabled_functions(struct android_dev *dev,
1474 struct usb_configuration *c)
1475{
1476 struct android_usb_function *f;
1477
1478 list_for_each_entry(f, &dev->enabled_functions, enabled_list) {
1479 if (f->unbind_config)
1480 f->unbind_config(f, c);
1481 }
1482}
1483
1484static int android_enable_function(struct android_dev *dev, char *name)
1485{
1486 struct android_usb_function **functions = dev->functions;
1487 struct android_usb_function *f;
1488 while ((f = *functions++)) {
1489 if (!strcmp(name, f->name)) {
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001490 if (f->android_dev)
1491 pr_err("%s cannot be enabled on two devices\n",
1492 f->name);
1493 else {
1494 list_add_tail(&f->enabled_list,
1495 &dev->enabled_functions);
1496 f->android_dev = dev;
1497 return 0;
1498 }
Benoit Goby1e8ce152011-12-12 13:01:23 -08001499 }
1500 }
1501 return -EINVAL;
1502}
1503
1504/*-------------------------------------------------------------------------*/
1505/* /sys/class/android_usb/android%d/ interface */
1506
Pavankumar Kondeti352396c2011-12-07 13:32:40 +05301507static ssize_t remote_wakeup_show(struct device *pdev,
1508 struct device_attribute *attr, char *buf)
1509{
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001510 struct android_dev *dev = dev_get_drvdata(pdev);
1511
Pavankumar Kondeti352396c2011-12-07 13:32:40 +05301512 return snprintf(buf, PAGE_SIZE, "%d\n",
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001513 !!(dev->config.bmAttributes &
Pavankumar Kondeti352396c2011-12-07 13:32:40 +05301514 USB_CONFIG_ATT_WAKEUP));
1515}
1516
1517static ssize_t remote_wakeup_store(struct device *pdev,
1518 struct device_attribute *attr, const char *buff, size_t size)
1519{
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001520 struct android_dev *dev = dev_get_drvdata(pdev);
Pavankumar Kondeti352396c2011-12-07 13:32:40 +05301521 int enable = 0;
1522
1523 sscanf(buff, "%d", &enable);
1524
1525 pr_debug("android_usb: %s remote wakeup\n",
1526 enable ? "enabling" : "disabling");
1527
1528 if (enable)
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001529 dev->config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
Pavankumar Kondeti352396c2011-12-07 13:32:40 +05301530 else
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001531 dev->config.bmAttributes &= ~USB_CONFIG_ATT_WAKEUP;
Pavankumar Kondeti352396c2011-12-07 13:32:40 +05301532
1533 return size;
1534}
1535
Benoit Goby1e8ce152011-12-12 13:01:23 -08001536static ssize_t
1537functions_show(struct device *pdev, struct device_attribute *attr, char *buf)
1538{
1539 struct android_dev *dev = dev_get_drvdata(pdev);
1540 struct android_usb_function *f;
1541 char *buff = buf;
1542
1543 mutex_lock(&dev->mutex);
1544
1545 list_for_each_entry(f, &dev->enabled_functions, enabled_list)
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301546 buff += snprintf(buff, PAGE_SIZE, "%s,", f->name);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001547
1548 mutex_unlock(&dev->mutex);
1549
1550 if (buff != buf)
1551 *(buff-1) = '\n';
1552 return buff - buf;
1553}
1554
1555static ssize_t
1556functions_store(struct device *pdev, struct device_attribute *attr,
1557 const char *buff, size_t size)
1558{
1559 struct android_dev *dev = dev_get_drvdata(pdev);
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001560 struct android_usb_function *f;
Benoit Goby1e8ce152011-12-12 13:01:23 -08001561 char *name;
1562 char buf[256], *b;
1563 int err;
1564
1565 mutex_lock(&dev->mutex);
1566
1567 if (dev->enabled) {
1568 mutex_unlock(&dev->mutex);
1569 return -EBUSY;
1570 }
1571
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001572 /* Clear previous enabled list */
1573 list_for_each_entry(f, &dev->enabled_functions, enabled_list) {
1574 f->android_dev = NULL;
1575 }
Benoit Goby1e8ce152011-12-12 13:01:23 -08001576 INIT_LIST_HEAD(&dev->enabled_functions);
1577
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301578 strlcpy(buf, buff, sizeof(buf));
Benoit Goby1e8ce152011-12-12 13:01:23 -08001579 b = strim(buf);
1580
1581 while (b) {
1582 name = strsep(&b, ",");
1583 if (name) {
1584 err = android_enable_function(dev, name);
1585 if (err)
1586 pr_err("android_usb: Cannot enable '%s'", name);
1587 }
1588 }
1589
1590 mutex_unlock(&dev->mutex);
1591
1592 return size;
1593}
1594
1595static ssize_t enable_show(struct device *pdev, struct device_attribute *attr,
1596 char *buf)
1597{
1598 struct android_dev *dev = dev_get_drvdata(pdev);
Steve Mucklef132c6c2012-06-06 18:30:57 -07001599
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301600 return snprintf(buf, PAGE_SIZE, "%d\n", dev->enabled);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001601}
1602
1603static ssize_t enable_store(struct device *pdev, struct device_attribute *attr,
1604 const char *buff, size_t size)
1605{
1606 struct android_dev *dev = dev_get_drvdata(pdev);
1607 struct usb_composite_dev *cdev = dev->cdev;
Benoit Goby80ba14d2012-03-19 18:56:52 -07001608 struct android_usb_function *f;
Benoit Goby1e8ce152011-12-12 13:01:23 -08001609 int enabled = 0;
1610
Benoit Gobycf3fc062011-12-19 14:39:37 -08001611 if (!cdev)
1612 return -ENODEV;
1613
Benoit Goby1e8ce152011-12-12 13:01:23 -08001614 mutex_lock(&dev->mutex);
1615
1616 sscanf(buff, "%d", &enabled);
1617 if (enabled && !dev->enabled) {
Benoit Goby1e8ce152011-12-12 13:01:23 -08001618 /*
1619 * Update values in composite driver's copy of
1620 * device descriptor.
1621 */
1622 cdev->desc.idVendor = device_desc.idVendor;
1623 cdev->desc.idProduct = device_desc.idProduct;
1624 cdev->desc.bcdDevice = device_desc.bcdDevice;
1625 cdev->desc.bDeviceClass = device_desc.bDeviceClass;
1626 cdev->desc.bDeviceSubClass = device_desc.bDeviceSubClass;
1627 cdev->desc.bDeviceProtocol = device_desc.bDeviceProtocol;
Benoit Goby80ba14d2012-03-19 18:56:52 -07001628 list_for_each_entry(f, &dev->enabled_functions, enabled_list) {
1629 if (f->enable)
1630 f->enable(f);
1631 }
1632 android_enable(dev);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001633 dev->enabled = true;
1634 } else if (!enabled && dev->enabled) {
Benoit Goby80ba14d2012-03-19 18:56:52 -07001635 android_disable(dev);
1636 list_for_each_entry(f, &dev->enabled_functions, enabled_list) {
1637 if (f->disable)
1638 f->disable(f);
1639 }
Benoit Goby1e8ce152011-12-12 13:01:23 -08001640 dev->enabled = false;
1641 } else {
1642 pr_err("android_usb: already %s\n",
1643 dev->enabled ? "enabled" : "disabled");
1644 }
1645
1646 mutex_unlock(&dev->mutex);
Steve Mucklef132c6c2012-06-06 18:30:57 -07001647
Benoit Gobyaab96812011-04-19 20:37:33 -07001648 return size;
1649}
1650
Ofir Cohen94213a72012-05-03 14:26:32 +03001651static ssize_t pm_qos_show(struct device *pdev,
1652 struct device_attribute *attr, char *buf)
1653{
1654 struct android_dev *dev = dev_get_drvdata(pdev);
1655
1656 return snprintf(buf, PAGE_SIZE, "%s\n", dev->pm_qos);
1657}
1658
1659static ssize_t pm_qos_store(struct device *pdev,
1660 struct device_attribute *attr,
1661 const char *buff, size_t size)
1662{
1663 struct android_dev *dev = dev_get_drvdata(pdev);
1664
1665 strlcpy(dev->pm_qos, buff, sizeof(dev->pm_qos));
1666
Benoit Goby1e8ce152011-12-12 13:01:23 -08001667 return size;
1668}
1669
1670static ssize_t state_show(struct device *pdev, struct device_attribute *attr,
1671 char *buf)
1672{
1673 struct android_dev *dev = dev_get_drvdata(pdev);
1674 struct usb_composite_dev *cdev = dev->cdev;
1675 char *state = "DISCONNECTED";
1676 unsigned long flags;
1677
1678 if (!cdev)
1679 goto out;
1680
1681 spin_lock_irqsave(&cdev->lock, flags);
1682 if (cdev->config)
1683 state = "CONFIGURED";
1684 else if (dev->connected)
1685 state = "CONNECTED";
1686 spin_unlock_irqrestore(&cdev->lock, flags);
1687out:
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301688 return snprintf(buf, PAGE_SIZE, "%s\n", state);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001689}
1690
1691#define DESCRIPTOR_ATTR(field, format_string) \
1692static ssize_t \
1693field ## _show(struct device *dev, struct device_attribute *attr, \
1694 char *buf) \
1695{ \
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301696 return snprintf(buf, PAGE_SIZE, \
1697 format_string, device_desc.field); \
Benoit Goby1e8ce152011-12-12 13:01:23 -08001698} \
1699static ssize_t \
1700field ## _store(struct device *dev, struct device_attribute *attr, \
1701 const char *buf, size_t size) \
1702{ \
1703 int value; \
1704 if (sscanf(buf, format_string, &value) == 1) { \
1705 device_desc.field = value; \
1706 return size; \
1707 } \
1708 return -1; \
1709} \
1710static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, field ## _show, field ## _store);
1711
1712#define DESCRIPTOR_STRING_ATTR(field, buffer) \
1713static ssize_t \
1714field ## _show(struct device *dev, struct device_attribute *attr, \
1715 char *buf) \
1716{ \
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301717 return snprintf(buf, PAGE_SIZE, "%s", buffer); \
Benoit Goby1e8ce152011-12-12 13:01:23 -08001718} \
1719static ssize_t \
1720field ## _store(struct device *dev, struct device_attribute *attr, \
1721 const char *buf, size_t size) \
1722{ \
1723 if (size >= sizeof(buffer)) \
1724 return -EINVAL; \
Pavankumar Kondetie02a51a2012-06-20 08:52:37 +05301725 strlcpy(buffer, buf, sizeof(buffer)); \
1726 strim(buffer); \
Pavankumar Kondeti4c22c102012-06-15 10:59:05 +05301727 return size; \
Benoit Goby1e8ce152011-12-12 13:01:23 -08001728} \
1729static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, field ## _show, field ## _store);
1730
1731
1732DESCRIPTOR_ATTR(idVendor, "%04x\n")
1733DESCRIPTOR_ATTR(idProduct, "%04x\n")
1734DESCRIPTOR_ATTR(bcdDevice, "%04x\n")
1735DESCRIPTOR_ATTR(bDeviceClass, "%d\n")
1736DESCRIPTOR_ATTR(bDeviceSubClass, "%d\n")
1737DESCRIPTOR_ATTR(bDeviceProtocol, "%d\n")
1738DESCRIPTOR_STRING_ATTR(iManufacturer, manufacturer_string)
1739DESCRIPTOR_STRING_ATTR(iProduct, product_string)
1740DESCRIPTOR_STRING_ATTR(iSerial, serial_string)
1741
1742static DEVICE_ATTR(functions, S_IRUGO | S_IWUSR, functions_show,
1743 functions_store);
1744static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, enable_show, enable_store);
Ofir Cohen94213a72012-05-03 14:26:32 +03001745static DEVICE_ATTR(pm_qos, S_IRUGO | S_IWUSR,
1746 pm_qos_show, pm_qos_store);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001747static DEVICE_ATTR(state, S_IRUGO, state_show, NULL);
Pavankumar Kondeti352396c2011-12-07 13:32:40 +05301748static DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR,
1749 remote_wakeup_show, remote_wakeup_store);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001750
1751static struct device_attribute *android_usb_attributes[] = {
1752 &dev_attr_idVendor,
1753 &dev_attr_idProduct,
1754 &dev_attr_bcdDevice,
1755 &dev_attr_bDeviceClass,
1756 &dev_attr_bDeviceSubClass,
1757 &dev_attr_bDeviceProtocol,
1758 &dev_attr_iManufacturer,
1759 &dev_attr_iProduct,
1760 &dev_attr_iSerial,
1761 &dev_attr_functions,
1762 &dev_attr_enable,
Ofir Cohen94213a72012-05-03 14:26:32 +03001763 &dev_attr_pm_qos,
Benoit Goby1e8ce152011-12-12 13:01:23 -08001764 &dev_attr_state,
Pavankumar Kondeti352396c2011-12-07 13:32:40 +05301765 &dev_attr_remote_wakeup,
Benoit Goby1e8ce152011-12-12 13:01:23 -08001766 NULL
1767};
1768
1769/*-------------------------------------------------------------------------*/
1770/* Composite driver */
1771
1772static int android_bind_config(struct usb_configuration *c)
1773{
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001774 struct android_dev *dev = cdev_to_android_dev(c->cdev);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001775 int ret = 0;
1776
1777 ret = android_bind_enabled_functions(dev, c);
1778 if (ret)
1779 return ret;
1780
1781 return 0;
1782}
1783
1784static void android_unbind_config(struct usb_configuration *c)
1785{
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001786 struct android_dev *dev = cdev_to_android_dev(c->cdev);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001787
1788 android_unbind_enabled_functions(dev, c);
1789}
1790
1791static int android_bind(struct usb_composite_dev *cdev)
1792{
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001793 struct android_dev *dev;
Benoit Goby1e8ce152011-12-12 13:01:23 -08001794 struct usb_gadget *gadget = cdev->gadget;
1795 int gcnum, id, ret;
1796
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001797 /* Bind to the last android_dev that was probed */
1798 dev = list_entry(android_dev_list.prev, struct android_dev, list_item);
1799
1800 dev->cdev = cdev;
1801
Benoit Goby1e8ce152011-12-12 13:01:23 -08001802 /*
1803 * Start disconnected. Userspace will connect the gadget once
1804 * it is done configuring the functions.
1805 */
1806 usb_gadget_disconnect(gadget);
1807
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001808 /* Init the supported functions only once, on the first android_dev */
1809 if (android_dev_count == 1) {
1810 ret = android_init_functions(dev->functions, cdev);
1811 if (ret)
1812 return ret;
1813 }
Benoit Goby1e8ce152011-12-12 13:01:23 -08001814
1815 /* Allocate string descriptor numbers ... note that string
1816 * contents can be overridden by the composite_dev glue.
1817 */
1818 id = usb_string_id(cdev);
1819 if (id < 0)
1820 return id;
1821 strings_dev[STRING_MANUFACTURER_IDX].id = id;
1822 device_desc.iManufacturer = id;
1823
1824 id = usb_string_id(cdev);
1825 if (id < 0)
1826 return id;
1827 strings_dev[STRING_PRODUCT_IDX].id = id;
1828 device_desc.iProduct = id;
1829
1830 /* Default strings - should be updated by userspace */
Rajkumar Raghupathy42ec8da2011-10-21 18:58:53 +05301831 strlcpy(manufacturer_string, "Android",
1832 sizeof(manufacturer_string) - 1);
1833 strlcpy(product_string, "Android", sizeof(product_string) - 1);
1834 strlcpy(serial_string, "0123456789ABCDEF", sizeof(serial_string) - 1);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001835
1836 id = usb_string_id(cdev);
1837 if (id < 0)
1838 return id;
1839 strings_dev[STRING_SERIAL_IDX].id = id;
1840 device_desc.iSerialNumber = id;
1841
Vijayavardhan Vennapusa56e60522012-02-16 15:40:16 +05301842 if (gadget_is_otg(cdev->gadget))
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001843 dev->config.descriptors = otg_desc;
Vijayavardhan Vennapusa56e60522012-02-16 15:40:16 +05301844
Benoit Goby1e8ce152011-12-12 13:01:23 -08001845 gcnum = usb_gadget_controller_number(gadget);
1846 if (gcnum >= 0)
1847 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
1848 else {
1849 pr_warning("%s: controller '%s' not recognized\n",
1850 longname, gadget->name);
1851 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999);
1852 }
1853
Benoit Goby1e8ce152011-12-12 13:01:23 -08001854 return 0;
1855}
1856
1857static int android_usb_unbind(struct usb_composite_dev *cdev)
1858{
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001859 struct android_dev *dev = cdev_to_android_dev(cdev);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001860
Lena Salmand092f2d2012-03-12 17:27:24 +02001861 manufacturer_string[0] = '\0';
1862 product_string[0] = '\0';
1863 serial_string[0] = '0';
Benoit Goby1e8ce152011-12-12 13:01:23 -08001864 cancel_work_sync(&dev->work);
1865 android_cleanup_functions(dev->functions);
1866 return 0;
1867}
1868
1869static struct usb_composite_driver android_usb_driver = {
1870 .name = "android_usb",
1871 .dev = &device_desc,
1872 .strings = dev_strings,
1873 .unbind = android_usb_unbind,
Tatyana Brokhman3ba28902011-06-29 16:41:49 +03001874 .max_speed = USB_SPEED_SUPER
Benoit Goby1e8ce152011-12-12 13:01:23 -08001875};
1876
1877static int
1878android_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *c)
1879{
Benoit Goby1e8ce152011-12-12 13:01:23 -08001880 struct usb_composite_dev *cdev = get_gadget_data(gadget);
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001881 struct android_dev *dev = cdev_to_android_dev(cdev);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001882 struct usb_request *req = cdev->req;
1883 struct android_usb_function *f;
1884 int value = -EOPNOTSUPP;
1885 unsigned long flags;
1886
1887 req->zero = 0;
1888 req->complete = composite_setup_complete;
1889 req->length = 0;
1890 gadget->ep0->driver_data = cdev;
1891
1892 list_for_each_entry(f, &dev->enabled_functions, enabled_list) {
1893 if (f->ctrlrequest) {
1894 value = f->ctrlrequest(f, cdev, c);
1895 if (value >= 0)
1896 break;
1897 }
1898 }
1899
Benoit Gobycf3fc062011-12-19 14:39:37 -08001900 /* Special case the accessory function.
1901 * It needs to handle control requests before it is enabled.
1902 */
1903 if (value < 0)
1904 value = acc_ctrlrequest(cdev, c);
1905
Benoit Goby1e8ce152011-12-12 13:01:23 -08001906 if (value < 0)
1907 value = composite_setup(gadget, c);
1908
1909 spin_lock_irqsave(&cdev->lock, flags);
1910 if (!dev->connected) {
1911 dev->connected = 1;
1912 schedule_work(&dev->work);
1913 } else if (c->bRequest == USB_REQ_SET_CONFIGURATION &&
1914 cdev->config) {
1915 schedule_work(&dev->work);
1916 }
1917 spin_unlock_irqrestore(&cdev->lock, flags);
1918
1919 return value;
1920}
1921
1922static void android_disconnect(struct usb_gadget *gadget)
1923{
Benoit Goby1e8ce152011-12-12 13:01:23 -08001924 struct usb_composite_dev *cdev = get_gadget_data(gadget);
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001925 struct android_dev *dev = cdev_to_android_dev(cdev);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001926 unsigned long flags;
1927
1928 composite_disconnect(gadget);
1929
1930 spin_lock_irqsave(&cdev->lock, flags);
1931 dev->connected = 0;
1932 schedule_work(&dev->work);
1933 spin_unlock_irqrestore(&cdev->lock, flags);
1934}
1935
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001936static int android_create_device(struct android_dev *dev, u8 usb_core_id)
Benoit Goby1e8ce152011-12-12 13:01:23 -08001937{
1938 struct device_attribute **attrs = android_usb_attributes;
1939 struct device_attribute *attr;
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001940 char device_node_name[ANDROID_DEVICE_NODE_NAME_LENGTH];
Benoit Goby1e8ce152011-12-12 13:01:23 -08001941 int err;
1942
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001943 /*
1944 * The primary usb core should always have usb_core_id=0, since
1945 * Android user space is currently interested in android0 events.
1946 */
1947 snprintf(device_node_name, ANDROID_DEVICE_NODE_NAME_LENGTH,
1948 "android%d", usb_core_id);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001949 dev->dev = device_create(android_class, NULL,
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001950 MKDEV(0, 0), NULL, device_node_name);
Benoit Goby1e8ce152011-12-12 13:01:23 -08001951 if (IS_ERR(dev->dev))
1952 return PTR_ERR(dev->dev);
1953
1954 dev_set_drvdata(dev->dev, dev);
1955
1956 while ((attr = *attrs++)) {
1957 err = device_create_file(dev->dev, attr);
1958 if (err) {
1959 device_destroy(android_class, dev->dev->devt);
1960 return err;
1961 }
1962 }
1963 return 0;
1964}
1965
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05301966static void android_destroy_device(struct android_dev *dev)
Benoit Goby1e8ce152011-12-12 13:01:23 -08001967{
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05301968 struct device_attribute **attrs = android_usb_attributes;
1969 struct device_attribute *attr;
1970
1971 while ((attr = *attrs++))
1972 device_remove_file(dev->dev, attr);
1973 device_destroy(android_class, dev->dev->devt);
1974}
1975
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001976static struct android_dev *cdev_to_android_dev(struct usb_composite_dev *cdev)
1977{
1978 struct android_dev *dev = NULL;
1979
1980 /* Find the android dev from the list */
1981 list_for_each_entry(dev, &android_dev_list, list_item) {
1982 if (dev->cdev == cdev)
1983 break;
1984 }
1985
1986 return dev;
1987}
1988
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001989static int __devinit android_probe(struct platform_device *pdev)
1990{
1991 struct android_usb_platform_data *pdata = pdev->dev.platform_data;
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001992 struct android_dev *android_dev;
Lena Salmand092f2d2012-03-12 17:27:24 +02001993 int ret = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001994
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03001995 if (!android_class) {
1996 android_class = class_create(THIS_MODULE, "android_usb");
1997 if (IS_ERR(android_class))
1998 return PTR_ERR(android_class);
1999 }
Benoit Goby1e8ce152011-12-12 13:01:23 -08002000
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03002001 android_dev = kzalloc(sizeof(*android_dev), GFP_KERNEL);
2002 if (!android_dev) {
2003 pr_err("%s(): Failed to alloc memory for android_dev\n",
2004 __func__);
2005 ret = -ENOMEM;
2006 goto err_alloc;
2007 }
Benoit Goby1e8ce152011-12-12 13:01:23 -08002008
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03002009 android_dev->config.label = pdev->name;
2010 android_dev->config.unbind = android_unbind_config;
2011 android_dev->config.bConfigurationValue = 1;
2012 android_dev->disable_depth = 1;
2013 android_dev->functions = supported_functions;
2014 INIT_LIST_HEAD(&android_dev->enabled_functions);
2015 INIT_WORK(&android_dev->work, android_work);
2016 mutex_init(&android_dev->mutex);
2017
2018 android_dev->pdata = pdata;
2019
2020 list_add_tail(&android_dev->list_item, &android_dev_list);
2021 android_dev_count++;
2022
2023 if (pdata)
2024 composite_driver.usb_core_id = pdata->usb_core_id;
2025 else
2026 composite_driver.usb_core_id = 0; /*To backward compatibility*/
2027
2028 ret = android_create_device(android_dev, composite_driver.usb_core_id);
Rajkumar Raghupathy5d3fc392012-04-11 16:53:19 +05302029 if (ret) {
2030 pr_err("%s(): android_create_device failed\n", __func__);
2031 goto err_dev;
2032 }
2033
Lena Salmand092f2d2012-03-12 17:27:24 +02002034 ret = usb_composite_probe(&android_usb_driver, android_bind);
2035 if (ret) {
2036 pr_err("%s(): Failed to register android "
2037 "composite driver\n", __func__);
Rajkumar Raghupathy5d3fc392012-04-11 16:53:19 +05302038 goto err_probe;
Lena Salmand092f2d2012-03-12 17:27:24 +02002039 }
2040
Ofir Cohen94213a72012-05-03 14:26:32 +03002041 /* pm qos request to prevent apps idle power collapse */
Manu Gautam94dc6142012-05-08 14:35:24 +05302042 if (pdata && pdata->swfi_latency)
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03002043 pm_qos_add_request(&android_dev->pm_qos_req_dma,
Ofir Cohen94213a72012-05-03 14:26:32 +03002044 PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03002045 strlcpy(android_dev->pm_qos, "high", sizeof(android_dev->pm_qos));
Ofir Cohen94213a72012-05-03 14:26:32 +03002046
Lena Salmand092f2d2012-03-12 17:27:24 +02002047 return ret;
Rajkumar Raghupathy5d3fc392012-04-11 16:53:19 +05302048err_probe:
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03002049 android_destroy_device(android_dev);
Rajkumar Raghupathy5d3fc392012-04-11 16:53:19 +05302050err_dev:
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03002051 list_del(&android_dev->list_item);
2052 android_dev_count--;
2053 kfree(android_dev);
2054err_alloc:
2055 if (list_empty(&android_dev_list)) {
2056 class_destroy(android_class);
2057 android_class = NULL;
2058 }
Rajkumar Raghupathy5d3fc392012-04-11 16:53:19 +05302059 return ret;
Lena Salmand092f2d2012-03-12 17:27:24 +02002060}
2061
2062static int android_remove(struct platform_device *pdev)
2063{
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03002064 struct android_dev *dev = NULL;
Ofir Cohen94213a72012-05-03 14:26:32 +03002065 struct android_usb_platform_data *pdata = pdev->dev.platform_data;
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03002066 int usb_core_id = 0;
Rajkumar Raghupathy5d3fc392012-04-11 16:53:19 +05302067
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03002068 if (pdata)
2069 usb_core_id = pdata->usb_core_id;
2070
2071 /* Find the android dev from the list */
2072 list_for_each_entry(dev, &android_dev_list, list_item) {
2073 if (!dev->pdata)
2074 break; /*To backward compatibility*/
2075 if (dev->pdata->usb_core_id == usb_core_id)
2076 break;
2077 }
2078
2079 if (dev) {
2080 android_destroy_device(dev);
2081 if (pdata && pdata->swfi_latency)
2082 pm_qos_remove_request(&dev->pm_qos_req_dma);
2083 list_del(&dev->list_item);
2084 android_dev_count--;
2085 kfree(dev);
2086 }
2087
2088 if (list_empty(&android_dev_list)) {
2089 class_destroy(android_class);
2090 android_class = NULL;
2091 usb_composite_unregister(&android_usb_driver);
2092 }
Ofir Cohen94213a72012-05-03 14:26:32 +03002093
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002094 return 0;
2095}
2096
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03002097static const struct platform_device_id android_id_table[] __devinitconst = {
2098 {
2099 .name = "android_usb",
2100 },
2101 {
2102 .name = "android_usb_hsic",
2103 },
2104};
2105
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002106static struct platform_driver android_platform_driver = {
2107 .driver = { .name = "android_usb"},
Lena Salmand092f2d2012-03-12 17:27:24 +02002108 .probe = android_probe,
2109 .remove = android_remove,
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03002110 .id_table = android_id_table,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002111};
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05002112
2113static int __init init(void)
2114{
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05302115 int ret;
Mike Lockwood7f0d7bd2008-12-02 22:01:33 -05002116
Benoit Goby1e8ce152011-12-12 13:01:23 -08002117 /* Override composite driver functions */
2118 composite_driver.setup = android_setup;
2119 composite_driver.disconnect = android_disconnect;
2120
Ido Shayevitz23dc77c2012-07-18 16:16:06 +03002121 INIT_LIST_HEAD(&android_dev_list);
2122 android_dev_count = 0;
2123
Pavankumar Kondeti044914d2012-01-31 12:56:13 +05302124 ret = platform_driver_register(&android_platform_driver);
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05302125 if (ret) {
2126 pr_err("%s(): Failed to register android"
2127 "platform driver\n", __func__);
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05302128 }
Lena Salmand092f2d2012-03-12 17:27:24 +02002129
Rajkumar Raghupathya1df77e2012-01-19 17:45:55 +05302130 return ret;
Benoit Goby1e8ce152011-12-12 13:01:23 -08002131}
2132module_init(init);
2133
2134static void __exit cleanup(void)
2135{
Lena Salmand092f2d2012-03-12 17:27:24 +02002136 platform_driver_unregister(&android_platform_driver);
Benoit Goby1e8ce152011-12-12 13:01:23 -08002137}
2138module_exit(cleanup);