Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1 | /* |
| 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 Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 26 | #include <linux/pm_qos.h> |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 27 | |
| 28 | #include <linux/usb/ch9.h> |
| 29 | #include <linux/usb/composite.h> |
| 30 | #include <linux/usb/gadget.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 31 | #include <linux/usb/android.h> |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 32 | |
| 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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 47 | #include "f_diag.c" |
Manu Gautam | 1c8ffd7 | 2011-09-02 16:00:49 +0530 | [diff] [blame] | 48 | #include "f_rmnet_smd.c" |
Manu Gautam | 8e0719b | 2011-09-26 14:47:55 +0530 | [diff] [blame] | 49 | #include "f_rmnet_sdio.c" |
| 50 | #include "f_rmnet_smd_sdio.c" |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 51 | #include "f_rmnet.c" |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 52 | #include "f_mass_storage.c" |
| 53 | #include "u_serial.c" |
Manu Gautam | a4d993f | 2011-08-30 18:25:55 +0530 | [diff] [blame] | 54 | #include "u_sdio.c" |
| 55 | #include "u_smd.c" |
| 56 | #include "u_bam.c" |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 57 | #include "u_rmnet_ctrl_smd.c" |
Jack Pham | 427f692 | 2011-11-23 19:42:00 -0800 | [diff] [blame] | 58 | #include "u_ctrl_hsic.c" |
| 59 | #include "u_data_hsic.c" |
Vijayavardhan Vennapusa | eb8d239 | 2012-04-03 18:58:49 +0530 | [diff] [blame] | 60 | #include "u_ctrl_hsuart.c" |
| 61 | #include "u_data_hsuart.c" |
Manu Gautam | a4d993f | 2011-08-30 18:25:55 +0530 | [diff] [blame] | 62 | #include "f_serial.c" |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 63 | #include "f_acm.c" |
Benoit Goby | 2b6862d | 2011-12-19 14:38:41 -0800 | [diff] [blame] | 64 | #include "f_adb.c" |
Chiranjeevi Velempati | e130fd0 | 2011-11-29 05:06:13 +0530 | [diff] [blame] | 65 | #include "f_ccid.c" |
Benoit Goby | f0fbc48 | 2011-12-19 14:37:50 -0800 | [diff] [blame] | 66 | #include "f_mtp.c" |
Benoit Goby | cf3fc06 | 2011-12-19 14:39:37 -0800 | [diff] [blame] | 67 | #include "f_accessory.c" |
Devin Kim | 0c5b9ce | 2012-06-19 21:34:44 -0700 | [diff] [blame^] | 68 | #ifdef CONFIG_USB_ANDROID_CDC_ECM |
| 69 | #include "f_ecm.c" |
| 70 | #else |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 71 | #define USB_ETH_RNDIS y |
| 72 | #include "f_rndis.c" |
| 73 | #include "rndis.c" |
Devin Kim | 0c5b9ce | 2012-06-19 21:34:44 -0700 | [diff] [blame^] | 74 | #endif |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 75 | #include "u_ether.c" |
Anna Perel | a8c991d | 2012-04-09 16:44:46 +0300 | [diff] [blame] | 76 | #include "u_bam_data.c" |
| 77 | #include "f_mbim.c" |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 78 | |
| 79 | MODULE_AUTHOR("Mike Lockwood"); |
| 80 | MODULE_DESCRIPTION("Android Composite USB Driver"); |
| 81 | MODULE_LICENSE("GPL"); |
| 82 | MODULE_VERSION("1.0"); |
| 83 | |
| 84 | static const char longname[] = "Gadget Android"; |
| 85 | |
| 86 | /* Default vendor and product IDs, overridden by userspace */ |
| 87 | #define VENDOR_ID 0x18D1 |
| 88 | #define PRODUCT_ID 0x0001 |
| 89 | |
| 90 | struct android_usb_function { |
| 91 | char *name; |
| 92 | void *config; |
| 93 | |
| 94 | struct device *dev; |
| 95 | char *dev_name; |
| 96 | struct device_attribute **attributes; |
| 97 | |
| 98 | /* for android_dev.enabled_functions */ |
| 99 | struct list_head enabled_list; |
| 100 | |
| 101 | /* Optional: initialization during gadget bind */ |
| 102 | int (*init)(struct android_usb_function *, struct usb_composite_dev *); |
| 103 | /* Optional: cleanup during gadget unbind */ |
| 104 | void (*cleanup)(struct android_usb_function *); |
Benoit Goby | 80ba14d | 2012-03-19 18:56:52 -0700 | [diff] [blame] | 105 | /* Optional: called when the function is added the list of |
| 106 | * enabled functions */ |
| 107 | void (*enable)(struct android_usb_function *); |
| 108 | /* Optional: called when it is removed */ |
| 109 | void (*disable)(struct android_usb_function *); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 110 | |
| 111 | int (*bind_config)(struct android_usb_function *, |
| 112 | struct usb_configuration *); |
| 113 | |
| 114 | /* Optional: called when the configuration is removed */ |
| 115 | void (*unbind_config)(struct android_usb_function *, |
| 116 | struct usb_configuration *); |
| 117 | /* Optional: handle ctrl requests before the device is configured */ |
| 118 | int (*ctrlrequest)(struct android_usb_function *, |
| 119 | struct usb_composite_dev *, |
| 120 | const struct usb_ctrlrequest *); |
| 121 | }; |
| 122 | |
| 123 | struct android_dev { |
| 124 | struct android_usb_function **functions; |
| 125 | struct list_head enabled_functions; |
| 126 | struct usb_composite_dev *cdev; |
| 127 | struct device *dev; |
| 128 | |
| 129 | bool enabled; |
Benoit Goby | 80ba14d | 2012-03-19 18:56:52 -0700 | [diff] [blame] | 130 | int disable_depth; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 131 | struct mutex mutex; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 132 | struct android_usb_platform_data *pdata; |
| 133 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 134 | bool connected; |
| 135 | bool sw_connected; |
Ofir Cohen | 94213a7 | 2012-05-03 14:26:32 +0300 | [diff] [blame] | 136 | char pm_qos[5]; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 137 | struct pm_qos_request pm_qos_req_dma; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 138 | struct work_struct work; |
| 139 | }; |
| 140 | |
| 141 | static struct class *android_class; |
| 142 | static struct android_dev *_android_dev; |
| 143 | static int android_bind_config(struct usb_configuration *c); |
| 144 | static void android_unbind_config(struct usb_configuration *c); |
| 145 | |
| 146 | /* string IDs are assigned dynamically */ |
| 147 | #define STRING_MANUFACTURER_IDX 0 |
| 148 | #define STRING_PRODUCT_IDX 1 |
| 149 | #define STRING_SERIAL_IDX 2 |
| 150 | |
| 151 | static char manufacturer_string[256]; |
| 152 | static char product_string[256]; |
| 153 | static char serial_string[256]; |
| 154 | |
| 155 | /* String Table */ |
| 156 | static struct usb_string strings_dev[] = { |
| 157 | [STRING_MANUFACTURER_IDX].s = manufacturer_string, |
| 158 | [STRING_PRODUCT_IDX].s = product_string, |
| 159 | [STRING_SERIAL_IDX].s = serial_string, |
| 160 | { } /* end of list */ |
| 161 | }; |
| 162 | |
| 163 | static struct usb_gadget_strings stringtab_dev = { |
| 164 | .language = 0x0409, /* en-us */ |
| 165 | .strings = strings_dev, |
| 166 | }; |
| 167 | |
| 168 | static struct usb_gadget_strings *dev_strings[] = { |
| 169 | &stringtab_dev, |
| 170 | NULL, |
| 171 | }; |
| 172 | |
| 173 | static struct usb_device_descriptor device_desc = { |
| 174 | .bLength = sizeof(device_desc), |
| 175 | .bDescriptorType = USB_DT_DEVICE, |
| 176 | .bcdUSB = __constant_cpu_to_le16(0x0200), |
| 177 | .bDeviceClass = USB_CLASS_PER_INTERFACE, |
| 178 | .idVendor = __constant_cpu_to_le16(VENDOR_ID), |
| 179 | .idProduct = __constant_cpu_to_le16(PRODUCT_ID), |
| 180 | .bcdDevice = __constant_cpu_to_le16(0xffff), |
| 181 | .bNumConfigurations = 1, |
| 182 | }; |
| 183 | |
Vijayavardhan Vennapusa | 56e6052 | 2012-02-16 15:40:16 +0530 | [diff] [blame] | 184 | static struct usb_otg_descriptor otg_descriptor = { |
| 185 | .bLength = sizeof otg_descriptor, |
| 186 | .bDescriptorType = USB_DT_OTG, |
| 187 | .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, |
| 188 | .bcdOTG = __constant_cpu_to_le16(0x0200), |
| 189 | }; |
| 190 | |
| 191 | static const struct usb_descriptor_header *otg_desc[] = { |
| 192 | (struct usb_descriptor_header *) &otg_descriptor, |
| 193 | NULL, |
| 194 | }; |
| 195 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 196 | static struct usb_configuration android_config_driver = { |
| 197 | .label = "android", |
| 198 | .unbind = android_unbind_config, |
| 199 | .bConfigurationValue = 1, |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 200 | }; |
| 201 | |
Manu Gautam | a2b5414 | 2012-04-03 14:34:32 +0530 | [diff] [blame] | 202 | enum android_device_state { |
| 203 | USB_DISCONNECTED, |
| 204 | USB_CONNECTED, |
| 205 | USB_CONFIGURED, |
| 206 | }; |
| 207 | |
Ofir Cohen | 94213a7 | 2012-05-03 14:26:32 +0300 | [diff] [blame] | 208 | static void android_pm_qos_update_latency(struct android_dev *dev, int vote) |
| 209 | { |
| 210 | struct android_usb_platform_data *pdata = dev->pdata; |
| 211 | u32 swfi_latency = 0; |
| 212 | static int last_vote = -1; |
| 213 | |
Ofir Cohen | 56eb707 | 2012-05-20 11:41:39 +0300 | [diff] [blame] | 214 | if (!pdata || vote == last_vote |
| 215 | || !pdata->swfi_latency) |
Ofir Cohen | 94213a7 | 2012-05-03 14:26:32 +0300 | [diff] [blame] | 216 | return; |
| 217 | |
| 218 | swfi_latency = pdata->swfi_latency + 1; |
| 219 | if (vote) |
| 220 | pm_qos_update_request(&dev->pm_qos_req_dma, |
| 221 | swfi_latency); |
| 222 | else |
| 223 | pm_qos_update_request(&dev->pm_qos_req_dma, |
| 224 | PM_QOS_DEFAULT_VALUE); |
| 225 | last_vote = vote; |
| 226 | } |
| 227 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 228 | static void android_work(struct work_struct *data) |
| 229 | { |
| 230 | struct android_dev *dev = container_of(data, struct android_dev, work); |
| 231 | struct usb_composite_dev *cdev = dev->cdev; |
| 232 | char *disconnected[2] = { "USB_STATE=DISCONNECTED", NULL }; |
| 233 | char *connected[2] = { "USB_STATE=CONNECTED", NULL }; |
| 234 | char *configured[2] = { "USB_STATE=CONFIGURED", NULL }; |
| 235 | char **uevent_envp = NULL; |
Manu Gautam | a2b5414 | 2012-04-03 14:34:32 +0530 | [diff] [blame] | 236 | static enum android_device_state last_uevent, next_state; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 237 | unsigned long flags; |
Ofir Cohen | bcbb1a7 | 2012-05-20 16:28:15 +0300 | [diff] [blame] | 238 | int pm_qos_vote = -1; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 239 | |
| 240 | spin_lock_irqsave(&cdev->lock, flags); |
Manu Gautam | a2b5414 | 2012-04-03 14:34:32 +0530 | [diff] [blame] | 241 | if (cdev->config) { |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 242 | uevent_envp = configured; |
Manu Gautam | a2b5414 | 2012-04-03 14:34:32 +0530 | [diff] [blame] | 243 | next_state = USB_CONFIGURED; |
| 244 | } else if (dev->connected != dev->sw_connected) { |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 245 | uevent_envp = dev->connected ? connected : disconnected; |
Manu Gautam | a2b5414 | 2012-04-03 14:34:32 +0530 | [diff] [blame] | 246 | next_state = dev->connected ? USB_CONNECTED : USB_DISCONNECTED; |
Ofir Cohen | 94213a7 | 2012-05-03 14:26:32 +0300 | [diff] [blame] | 247 | if (dev->connected && strncmp(dev->pm_qos, "low", 3)) |
Ofir Cohen | bcbb1a7 | 2012-05-20 16:28:15 +0300 | [diff] [blame] | 248 | pm_qos_vote = 1; |
Ofir Cohen | 94213a7 | 2012-05-03 14:26:32 +0300 | [diff] [blame] | 249 | else if (!dev->connected || !strncmp(dev->pm_qos, "low", 3)) |
Ofir Cohen | bcbb1a7 | 2012-05-20 16:28:15 +0300 | [diff] [blame] | 250 | pm_qos_vote = 0; |
Manu Gautam | a2b5414 | 2012-04-03 14:34:32 +0530 | [diff] [blame] | 251 | } |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 252 | dev->sw_connected = dev->connected; |
| 253 | spin_unlock_irqrestore(&cdev->lock, flags); |
| 254 | |
Ofir Cohen | bcbb1a7 | 2012-05-20 16:28:15 +0300 | [diff] [blame] | 255 | if (pm_qos_vote != -1) |
| 256 | android_pm_qos_update_latency(dev, pm_qos_vote); |
| 257 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 258 | if (uevent_envp) { |
Manu Gautam | a2b5414 | 2012-04-03 14:34:32 +0530 | [diff] [blame] | 259 | /* |
| 260 | * Some userspace modules, e.g. MTP, work correctly only if |
| 261 | * CONFIGURED uevent is preceded by DISCONNECT uevent. |
| 262 | * Check if we missed sending out a DISCONNECT uevent. This can |
| 263 | * happen if host PC resets and configures device really quick. |
| 264 | */ |
| 265 | if (((uevent_envp == connected) && |
| 266 | (last_uevent != USB_DISCONNECTED)) || |
| 267 | ((uevent_envp == configured) && |
| 268 | (last_uevent == USB_CONFIGURED))) { |
| 269 | pr_info("%s: sent missed DISCONNECT event\n", __func__); |
| 270 | kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE, |
| 271 | disconnected); |
| 272 | msleep(20); |
| 273 | } |
| 274 | /* |
| 275 | * Before sending out CONFIGURED uevent give function drivers |
| 276 | * a chance to wakeup userspace threads and notify disconnect |
| 277 | */ |
| 278 | if (uevent_envp == configured) |
| 279 | msleep(50); |
| 280 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 281 | kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE, uevent_envp); |
Manu Gautam | a2b5414 | 2012-04-03 14:34:32 +0530 | [diff] [blame] | 282 | last_uevent = next_state; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 283 | pr_info("%s: sent uevent %s\n", __func__, uevent_envp[0]); |
| 284 | } else { |
| 285 | pr_info("%s: did not send uevent (%d %d %p)\n", __func__, |
| 286 | dev->connected, dev->sw_connected, cdev->config); |
| 287 | } |
| 288 | } |
| 289 | |
Benoit Goby | 80ba14d | 2012-03-19 18:56:52 -0700 | [diff] [blame] | 290 | static void android_enable(struct android_dev *dev) |
| 291 | { |
| 292 | struct usb_composite_dev *cdev = dev->cdev; |
| 293 | |
| 294 | if (WARN_ON(!dev->disable_depth)) |
| 295 | return; |
| 296 | |
| 297 | if (--dev->disable_depth == 0) { |
| 298 | usb_add_config(cdev, &android_config_driver, |
| 299 | android_bind_config); |
| 300 | usb_gadget_connect(cdev->gadget); |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | static void android_disable(struct android_dev *dev) |
| 305 | { |
| 306 | struct usb_composite_dev *cdev = dev->cdev; |
| 307 | |
| 308 | if (dev->disable_depth++ == 0) { |
| 309 | usb_gadget_disconnect(cdev->gadget); |
| 310 | /* Cancel pending control requests */ |
| 311 | usb_ep_dequeue(cdev->gadget->ep0, cdev->req); |
| 312 | usb_remove_config(cdev, &android_config_driver); |
| 313 | } |
| 314 | } |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 315 | |
| 316 | /*-------------------------------------------------------------------------*/ |
| 317 | /* Supported functions initialization */ |
| 318 | |
Benoit Goby | 80ba14d | 2012-03-19 18:56:52 -0700 | [diff] [blame] | 319 | struct adb_data { |
| 320 | bool opened; |
| 321 | bool enabled; |
| 322 | }; |
| 323 | |
Benoit Goby | 2b6862d | 2011-12-19 14:38:41 -0800 | [diff] [blame] | 324 | static int |
| 325 | adb_function_init(struct android_usb_function *f, |
| 326 | struct usb_composite_dev *cdev) |
| 327 | { |
Benoit Goby | 80ba14d | 2012-03-19 18:56:52 -0700 | [diff] [blame] | 328 | f->config = kzalloc(sizeof(struct adb_data), GFP_KERNEL); |
| 329 | if (!f->config) |
| 330 | return -ENOMEM; |
| 331 | |
Benoit Goby | 2b6862d | 2011-12-19 14:38:41 -0800 | [diff] [blame] | 332 | return adb_setup(); |
| 333 | } |
| 334 | |
| 335 | static void adb_function_cleanup(struct android_usb_function *f) |
| 336 | { |
| 337 | adb_cleanup(); |
Benoit Goby | 80ba14d | 2012-03-19 18:56:52 -0700 | [diff] [blame] | 338 | kfree(f->config); |
Benoit Goby | 2b6862d | 2011-12-19 14:38:41 -0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | static int |
| 342 | adb_function_bind_config(struct android_usb_function *f, |
| 343 | struct usb_configuration *c) |
| 344 | { |
| 345 | return adb_bind_config(c); |
| 346 | } |
| 347 | |
Benoit Goby | 80ba14d | 2012-03-19 18:56:52 -0700 | [diff] [blame] | 348 | static void adb_android_function_enable(struct android_usb_function *f) |
| 349 | { |
| 350 | struct android_dev *dev = _android_dev; |
| 351 | struct adb_data *data = f->config; |
| 352 | |
| 353 | data->enabled = true; |
| 354 | |
| 355 | /* Disable the gadget until adbd is ready */ |
| 356 | if (!data->opened) |
| 357 | android_disable(dev); |
| 358 | } |
| 359 | |
| 360 | static void adb_android_function_disable(struct android_usb_function *f) |
| 361 | { |
| 362 | struct android_dev *dev = _android_dev; |
| 363 | struct adb_data *data = f->config; |
| 364 | |
| 365 | data->enabled = false; |
| 366 | |
| 367 | /* Balance the disable that was called in closed_callback */ |
| 368 | if (!data->opened) |
| 369 | android_enable(dev); |
| 370 | } |
| 371 | |
Benoit Goby | 2b6862d | 2011-12-19 14:38:41 -0800 | [diff] [blame] | 372 | static struct android_usb_function adb_function = { |
| 373 | .name = "adb", |
Benoit Goby | 80ba14d | 2012-03-19 18:56:52 -0700 | [diff] [blame] | 374 | .enable = adb_android_function_enable, |
| 375 | .disable = adb_android_function_disable, |
Benoit Goby | 2b6862d | 2011-12-19 14:38:41 -0800 | [diff] [blame] | 376 | .init = adb_function_init, |
| 377 | .cleanup = adb_function_cleanup, |
| 378 | .bind_config = adb_function_bind_config, |
| 379 | }; |
| 380 | |
Benoit Goby | 80ba14d | 2012-03-19 18:56:52 -0700 | [diff] [blame] | 381 | static void adb_ready_callback(void) |
| 382 | { |
| 383 | struct android_dev *dev = _android_dev; |
| 384 | struct adb_data *data = adb_function.config; |
| 385 | |
| 386 | mutex_lock(&dev->mutex); |
| 387 | |
| 388 | data->opened = true; |
| 389 | |
| 390 | if (data->enabled) |
| 391 | android_enable(dev); |
| 392 | |
| 393 | mutex_unlock(&dev->mutex); |
| 394 | } |
| 395 | |
| 396 | static void adb_closed_callback(void) |
| 397 | { |
| 398 | struct android_dev *dev = _android_dev; |
| 399 | struct adb_data *data = adb_function.config; |
| 400 | |
| 401 | mutex_lock(&dev->mutex); |
| 402 | |
| 403 | data->opened = false; |
| 404 | |
| 405 | if (data->enabled) |
| 406 | android_disable(dev); |
| 407 | |
| 408 | mutex_unlock(&dev->mutex); |
| 409 | } |
| 410 | |
Benoit Goby | 2b6862d | 2011-12-19 14:38:41 -0800 | [diff] [blame] | 411 | |
Benoit Goby | aab9681 | 2011-04-19 20:37:33 -0700 | [diff] [blame] | 412 | /*-------------------------------------------------------------------------*/ |
| 413 | /* Supported functions initialization */ |
| 414 | |
Manu Gautam | 8e0719b | 2011-09-26 14:47:55 +0530 | [diff] [blame] | 415 | /* RMNET_SMD */ |
Manu Gautam | 1c8ffd7 | 2011-09-02 16:00:49 +0530 | [diff] [blame] | 416 | static int rmnet_smd_function_bind_config(struct android_usb_function *f, |
| 417 | struct usb_configuration *c) |
| 418 | { |
| 419 | return rmnet_smd_bind_config(c); |
| 420 | } |
| 421 | |
| 422 | static struct android_usb_function rmnet_smd_function = { |
| 423 | .name = "rmnet_smd", |
| 424 | .bind_config = rmnet_smd_function_bind_config, |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 425 | }; |
| 426 | |
Manu Gautam | 8e0719b | 2011-09-26 14:47:55 +0530 | [diff] [blame] | 427 | /* RMNET_SDIO */ |
| 428 | static int rmnet_sdio_function_bind_config(struct android_usb_function *f, |
| 429 | struct usb_configuration *c) |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 430 | { |
Manu Gautam | 8e0719b | 2011-09-26 14:47:55 +0530 | [diff] [blame] | 431 | return rmnet_sdio_function_add(c); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Manu Gautam | 8e0719b | 2011-09-26 14:47:55 +0530 | [diff] [blame] | 434 | static struct android_usb_function rmnet_sdio_function = { |
| 435 | .name = "rmnet_sdio", |
| 436 | .bind_config = rmnet_sdio_function_bind_config, |
| 437 | }; |
| 438 | |
| 439 | /* RMNET_SMD_SDIO */ |
| 440 | static int rmnet_smd_sdio_function_init(struct android_usb_function *f, |
| 441 | struct usb_composite_dev *cdev) |
| 442 | { |
| 443 | return rmnet_smd_sdio_init(); |
| 444 | } |
| 445 | |
| 446 | static void rmnet_smd_sdio_function_cleanup(struct android_usb_function *f) |
| 447 | { |
| 448 | rmnet_smd_sdio_cleanup(); |
| 449 | } |
| 450 | |
| 451 | static int rmnet_smd_sdio_bind_config(struct android_usb_function *f, |
| 452 | struct usb_configuration *c) |
| 453 | { |
| 454 | return rmnet_smd_sdio_function_add(c); |
| 455 | } |
| 456 | |
| 457 | static struct device_attribute *rmnet_smd_sdio_attributes[] = { |
| 458 | &dev_attr_transport, NULL }; |
| 459 | |
| 460 | static struct android_usb_function rmnet_smd_sdio_function = { |
| 461 | .name = "rmnet_smd_sdio", |
| 462 | .init = rmnet_smd_sdio_function_init, |
| 463 | .cleanup = rmnet_smd_sdio_function_cleanup, |
| 464 | .bind_config = rmnet_smd_sdio_bind_config, |
| 465 | .attributes = rmnet_smd_sdio_attributes, |
| 466 | }; |
| 467 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 468 | /*rmnet transport string format(per port):"ctrl0,data0,ctrl1,data1..." */ |
| 469 | #define MAX_XPORT_STR_LEN 50 |
| 470 | static char rmnet_transports[MAX_XPORT_STR_LEN]; |
Manu Gautam | 1c8ffd7 | 2011-09-02 16:00:49 +0530 | [diff] [blame] | 471 | |
Manu Gautam | e3e897c | 2011-09-12 17:18:46 +0530 | [diff] [blame] | 472 | static void rmnet_function_cleanup(struct android_usb_function *f) |
| 473 | { |
| 474 | frmnet_cleanup(); |
| 475 | } |
| 476 | |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 477 | static int rmnet_function_bind_config(struct android_usb_function *f, |
| 478 | struct usb_configuration *c) |
| 479 | { |
| 480 | int i; |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 481 | int err = 0; |
| 482 | char *ctrl_name; |
| 483 | char *data_name; |
| 484 | char buf[MAX_XPORT_STR_LEN], *b; |
| 485 | static int rmnet_initialized, ports; |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 486 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 487 | if (!rmnet_initialized) { |
| 488 | rmnet_initialized = 1; |
| 489 | strlcpy(buf, rmnet_transports, sizeof(buf)); |
| 490 | b = strim(buf); |
| 491 | while (b) { |
| 492 | ctrl_name = strsep(&b, ","); |
| 493 | data_name = strsep(&b, ","); |
| 494 | if (ctrl_name && data_name) { |
| 495 | err = frmnet_init_port(ctrl_name, data_name); |
| 496 | if (err) { |
| 497 | pr_err("rmnet: Cannot open ctrl port:" |
| 498 | "'%s' data port:'%s'\n", |
| 499 | ctrl_name, data_name); |
| 500 | goto out; |
| 501 | } |
| 502 | ports++; |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | err = rmnet_gport_setup(); |
| 507 | if (err) { |
| 508 | pr_err("rmnet: Cannot setup transports"); |
| 509 | goto out; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | for (i = 0; i < ports; i++) { |
| 514 | err = frmnet_bind_config(c, i); |
| 515 | if (err) { |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 516 | pr_err("Could not bind rmnet%u config\n", i); |
| 517 | break; |
| 518 | } |
| 519 | } |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 520 | out: |
| 521 | return err; |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 522 | } |
| 523 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 524 | static ssize_t rmnet_transports_show(struct device *dev, |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 525 | struct device_attribute *attr, char *buf) |
| 526 | { |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 527 | return snprintf(buf, PAGE_SIZE, "%s\n", rmnet_transports); |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 528 | } |
| 529 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 530 | static ssize_t rmnet_transports_store( |
| 531 | struct device *device, struct device_attribute *attr, |
| 532 | const char *buff, size_t size) |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 533 | { |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 534 | strlcpy(rmnet_transports, buff, sizeof(rmnet_transports)); |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 535 | |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 536 | return size; |
| 537 | } |
| 538 | |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 539 | static struct device_attribute dev_attr_rmnet_transports = |
| 540 | __ATTR(transports, S_IRUGO | S_IWUSR, |
| 541 | rmnet_transports_show, |
| 542 | rmnet_transports_store); |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 543 | static struct device_attribute *rmnet_function_attributes[] = { |
Hemant Kumar | 1b820d5 | 2011-11-03 15:08:28 -0700 | [diff] [blame] | 544 | &dev_attr_rmnet_transports, |
| 545 | NULL }; |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 546 | |
| 547 | static struct android_usb_function rmnet_function = { |
| 548 | .name = "rmnet", |
Manu Gautam | e3e897c | 2011-09-12 17:18:46 +0530 | [diff] [blame] | 549 | .cleanup = rmnet_function_cleanup, |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 550 | .bind_config = rmnet_function_bind_config, |
| 551 | .attributes = rmnet_function_attributes, |
| 552 | }; |
| 553 | |
Anna Perel | a8c991d | 2012-04-09 16:44:46 +0300 | [diff] [blame] | 554 | |
| 555 | /* MBIM - used with BAM */ |
| 556 | #define MAX_MBIM_INSTANCES 1 |
| 557 | |
| 558 | static int mbim_function_init(struct android_usb_function *f, |
| 559 | struct usb_composite_dev *cdev) |
| 560 | { |
| 561 | return mbim_init(MAX_MBIM_INSTANCES); |
| 562 | } |
| 563 | |
| 564 | static void mbim_function_cleanup(struct android_usb_function *f) |
| 565 | { |
| 566 | fmbim_cleanup(); |
| 567 | } |
| 568 | |
| 569 | static int mbim_function_bind_config(struct android_usb_function *f, |
| 570 | struct usb_configuration *c) |
| 571 | { |
| 572 | return mbim_bind_config(c, 0); |
| 573 | } |
| 574 | |
| 575 | static struct android_usb_function mbim_function = { |
| 576 | .name = "usb_mbim", |
| 577 | .cleanup = mbim_function_cleanup, |
| 578 | .bind_config = mbim_function_bind_config, |
| 579 | .init = mbim_function_init, |
| 580 | }; |
| 581 | |
| 582 | |
Manu Gautam | 8e0719b | 2011-09-26 14:47:55 +0530 | [diff] [blame] | 583 | /* DIAG */ |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 584 | static char diag_clients[32]; /*enabled DIAG clients- "diag[,diag_mdm]" */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 585 | static ssize_t clients_store( |
| 586 | struct device *device, struct device_attribute *attr, |
| 587 | const char *buff, size_t size) |
| 588 | { |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 589 | strlcpy(diag_clients, buff, sizeof(diag_clients)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 590 | |
| 591 | return size; |
| 592 | } |
| 593 | |
| 594 | static DEVICE_ATTR(clients, S_IWUSR, NULL, clients_store); |
| 595 | static struct device_attribute *diag_function_attributes[] = |
| 596 | { &dev_attr_clients, NULL }; |
| 597 | |
| 598 | static int diag_function_init(struct android_usb_function *f, |
| 599 | struct usb_composite_dev *cdev) |
| 600 | { |
| 601 | return diag_setup(); |
| 602 | } |
| 603 | |
| 604 | static void diag_function_cleanup(struct android_usb_function *f) |
| 605 | { |
| 606 | diag_cleanup(); |
| 607 | } |
| 608 | |
| 609 | static int diag_function_bind_config(struct android_usb_function *f, |
| 610 | struct usb_configuration *c) |
| 611 | { |
| 612 | char *name; |
| 613 | char buf[32], *b; |
Manu Gautam | c576030 | 2011-08-25 14:30:24 +0530 | [diff] [blame] | 614 | int once = 0, err = -1; |
Jack Pham | b830a6c | 2011-12-12 22:35:27 -0800 | [diff] [blame] | 615 | int (*notify)(uint32_t, const char *); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 616 | |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 617 | strlcpy(buf, diag_clients, sizeof(buf)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 618 | b = strim(buf); |
| 619 | |
| 620 | while (b) { |
Jack Pham | b830a6c | 2011-12-12 22:35:27 -0800 | [diff] [blame] | 621 | notify = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 622 | name = strsep(&b, ","); |
Manu Gautam | c576030 | 2011-08-25 14:30:24 +0530 | [diff] [blame] | 623 | /* Allow only first diag channel to update pid and serial no */ |
Hemant Kumar | 1136c00 | 2011-10-18 22:04:06 -0700 | [diff] [blame] | 624 | if (_android_dev->pdata && !once++) |
Manu Gautam | c576030 | 2011-08-25 14:30:24 +0530 | [diff] [blame] | 625 | notify = _android_dev->pdata->update_pid_and_serial_num; |
Manu Gautam | c576030 | 2011-08-25 14:30:24 +0530 | [diff] [blame] | 626 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 627 | if (name) { |
Manu Gautam | c576030 | 2011-08-25 14:30:24 +0530 | [diff] [blame] | 628 | err = diag_function_add(c, name, notify); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 629 | if (err) |
| 630 | pr_err("diag: Cannot open channel '%s'", name); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | return err; |
| 635 | } |
| 636 | |
| 637 | static struct android_usb_function diag_function = { |
| 638 | .name = "diag", |
| 639 | .init = diag_function_init, |
| 640 | .cleanup = diag_function_cleanup, |
| 641 | .bind_config = diag_function_bind_config, |
| 642 | .attributes = diag_function_attributes, |
| 643 | }; |
| 644 | |
Manu Gautam | 8e0719b | 2011-09-26 14:47:55 +0530 | [diff] [blame] | 645 | /* SERIAL */ |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 646 | static char serial_transports[32]; /*enabled FSERIAL ports - "tty[,sdio]"*/ |
Manu Gautam | a4d993f | 2011-08-30 18:25:55 +0530 | [diff] [blame] | 647 | static ssize_t serial_transports_store( |
| 648 | struct device *device, struct device_attribute *attr, |
| 649 | const char *buff, size_t size) |
| 650 | { |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 651 | strlcpy(serial_transports, buff, sizeof(serial_transports)); |
Manu Gautam | a4d993f | 2011-08-30 18:25:55 +0530 | [diff] [blame] | 652 | |
| 653 | return size; |
| 654 | } |
| 655 | |
| 656 | static DEVICE_ATTR(transports, S_IWUSR, NULL, serial_transports_store); |
| 657 | static struct device_attribute *serial_function_attributes[] = |
| 658 | { &dev_attr_transports, NULL }; |
| 659 | |
| 660 | static void serial_function_cleanup(struct android_usb_function *f) |
| 661 | { |
| 662 | gserial_cleanup(); |
| 663 | } |
| 664 | |
| 665 | static int serial_function_bind_config(struct android_usb_function *f, |
| 666 | struct usb_configuration *c) |
| 667 | { |
| 668 | char *name; |
| 669 | char buf[32], *b; |
| 670 | int err = -1, i; |
| 671 | static int serial_initialized = 0, ports = 0; |
| 672 | |
| 673 | if (serial_initialized) |
| 674 | goto bind_config; |
| 675 | |
| 676 | serial_initialized = 1; |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 677 | strlcpy(buf, serial_transports, sizeof(buf)); |
Manu Gautam | a4d993f | 2011-08-30 18:25:55 +0530 | [diff] [blame] | 678 | b = strim(buf); |
| 679 | |
| 680 | while (b) { |
| 681 | name = strsep(&b, ","); |
| 682 | |
| 683 | if (name) { |
| 684 | err = gserial_init_port(ports, name); |
| 685 | if (err) { |
| 686 | pr_err("serial: Cannot open port '%s'", name); |
| 687 | goto out; |
| 688 | } |
| 689 | ports++; |
| 690 | } |
| 691 | } |
| 692 | err = gport_setup(c); |
| 693 | if (err) { |
| 694 | pr_err("serial: Cannot setup transports"); |
| 695 | goto out; |
| 696 | } |
| 697 | |
| 698 | bind_config: |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 699 | for (i = 0; i < ports; i++) { |
Manu Gautam | a4d993f | 2011-08-30 18:25:55 +0530 | [diff] [blame] | 700 | err = gser_bind_config(c, i); |
| 701 | if (err) { |
| 702 | pr_err("serial: bind_config failed for port %d", i); |
| 703 | goto out; |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | out: |
| 708 | return err; |
| 709 | } |
| 710 | |
| 711 | static struct android_usb_function serial_function = { |
| 712 | .name = "serial", |
| 713 | .cleanup = serial_function_cleanup, |
| 714 | .bind_config = serial_function_bind_config, |
| 715 | .attributes = serial_function_attributes, |
| 716 | }; |
| 717 | |
Anji jonnala | 92be1b4 | 2011-12-19 09:44:41 +0530 | [diff] [blame] | 718 | /* ACM */ |
| 719 | static char acm_transports[32]; /*enabled ACM ports - "tty[,sdio]"*/ |
| 720 | static ssize_t acm_transports_store( |
| 721 | struct device *device, struct device_attribute *attr, |
| 722 | const char *buff, size_t size) |
| 723 | { |
| 724 | strlcpy(acm_transports, buff, sizeof(acm_transports)); |
| 725 | |
| 726 | return size; |
| 727 | } |
| 728 | |
| 729 | static DEVICE_ATTR(acm_transports, S_IWUSR, NULL, acm_transports_store); |
| 730 | static struct device_attribute *acm_function_attributes[] = { |
| 731 | &dev_attr_acm_transports, NULL }; |
| 732 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 733 | static void acm_function_cleanup(struct android_usb_function *f) |
| 734 | { |
| 735 | gserial_cleanup(); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 736 | } |
| 737 | |
Anji jonnala | 92be1b4 | 2011-12-19 09:44:41 +0530 | [diff] [blame] | 738 | static int acm_function_bind_config(struct android_usb_function *f, |
| 739 | struct usb_configuration *c) |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 740 | { |
Anji jonnala | 92be1b4 | 2011-12-19 09:44:41 +0530 | [diff] [blame] | 741 | char *name; |
| 742 | char buf[32], *b; |
| 743 | int err = -1, i; |
| 744 | static int acm_initialized, ports; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 745 | |
Anji jonnala | 92be1b4 | 2011-12-19 09:44:41 +0530 | [diff] [blame] | 746 | if (acm_initialized) |
| 747 | goto bind_config; |
| 748 | |
| 749 | acm_initialized = 1; |
| 750 | strlcpy(buf, acm_transports, sizeof(buf)); |
| 751 | b = strim(buf); |
| 752 | |
| 753 | while (b) { |
| 754 | name = strsep(&b, ","); |
| 755 | |
| 756 | if (name) { |
| 757 | err = acm_init_port(ports, name); |
| 758 | if (err) { |
| 759 | pr_err("acm: Cannot open port '%s'", name); |
| 760 | goto out; |
| 761 | } |
| 762 | ports++; |
| 763 | } |
| 764 | } |
| 765 | err = acm_port_setup(c); |
| 766 | if (err) { |
| 767 | pr_err("acm: Cannot setup transports"); |
| 768 | goto out; |
| 769 | } |
| 770 | |
| 771 | bind_config: |
| 772 | for (i = 0; i < ports; i++) { |
| 773 | err = acm_bind_config(c, i); |
| 774 | if (err) { |
| 775 | pr_err("acm: bind_config failed for port %d", i); |
| 776 | goto out; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | |
Anji jonnala | 92be1b4 | 2011-12-19 09:44:41 +0530 | [diff] [blame] | 780 | out: |
| 781 | return err; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 782 | } |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 783 | static struct android_usb_function acm_function = { |
| 784 | .name = "acm", |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 785 | .cleanup = acm_function_cleanup, |
| 786 | .bind_config = acm_function_bind_config, |
| 787 | .attributes = acm_function_attributes, |
| 788 | }; |
| 789 | |
Chiranjeevi Velempati | e130fd0 | 2011-11-29 05:06:13 +0530 | [diff] [blame] | 790 | /* CCID */ |
| 791 | static int ccid_function_init(struct android_usb_function *f, |
| 792 | struct usb_composite_dev *cdev) |
| 793 | { |
| 794 | return ccid_setup(); |
| 795 | } |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 796 | |
Chiranjeevi Velempati | e130fd0 | 2011-11-29 05:06:13 +0530 | [diff] [blame] | 797 | static void ccid_function_cleanup(struct android_usb_function *f) |
| 798 | { |
| 799 | ccid_cleanup(); |
| 800 | } |
| 801 | |
| 802 | static int ccid_function_bind_config(struct android_usb_function *f, |
| 803 | struct usb_configuration *c) |
| 804 | { |
| 805 | return ccid_bind_config(c); |
| 806 | } |
| 807 | |
| 808 | static struct android_usb_function ccid_function = { |
| 809 | .name = "ccid", |
| 810 | .init = ccid_function_init, |
| 811 | .cleanup = ccid_function_cleanup, |
| 812 | .bind_config = ccid_function_bind_config, |
| 813 | }; |
| 814 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 815 | static int mtp_function_init(struct android_usb_function *f, |
Benoit Goby | f0fbc48 | 2011-12-19 14:37:50 -0800 | [diff] [blame] | 816 | struct usb_composite_dev *cdev) |
| 817 | { |
| 818 | return mtp_setup(); |
| 819 | } |
| 820 | |
| 821 | static void mtp_function_cleanup(struct android_usb_function *f) |
| 822 | { |
| 823 | mtp_cleanup(); |
| 824 | } |
| 825 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 826 | static int mtp_function_bind_config(struct android_usb_function *f, |
Benoit Goby | f0fbc48 | 2011-12-19 14:37:50 -0800 | [diff] [blame] | 827 | struct usb_configuration *c) |
| 828 | { |
| 829 | return mtp_bind_config(c, false); |
| 830 | } |
| 831 | |
Mike Lockwood | cf7addf | 2011-06-01 22:17:36 -0400 | [diff] [blame] | 832 | static int ptp_function_init(struct android_usb_function *f, struct usb_composite_dev *cdev) |
Benoit Goby | f0fbc48 | 2011-12-19 14:37:50 -0800 | [diff] [blame] | 833 | { |
| 834 | /* nothing to do - initialization is handled by mtp_function_init */ |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | static void ptp_function_cleanup(struct android_usb_function *f) |
| 839 | { |
| 840 | /* nothing to do - cleanup is handled by mtp_function_cleanup */ |
| 841 | } |
| 842 | |
Mike Lockwood | cf7addf | 2011-06-01 22:17:36 -0400 | [diff] [blame] | 843 | static int ptp_function_bind_config(struct android_usb_function *f, struct usb_configuration *c) |
Benoit Goby | f0fbc48 | 2011-12-19 14:37:50 -0800 | [diff] [blame] | 844 | { |
| 845 | return mtp_bind_config(c, true); |
| 846 | } |
| 847 | |
| 848 | static int mtp_function_ctrlrequest(struct android_usb_function *f, |
| 849 | struct usb_composite_dev *cdev, |
| 850 | const struct usb_ctrlrequest *c) |
| 851 | { |
| 852 | return mtp_ctrlrequest(cdev, c); |
| 853 | } |
| 854 | |
| 855 | static struct android_usb_function mtp_function = { |
| 856 | .name = "mtp", |
| 857 | .init = mtp_function_init, |
| 858 | .cleanup = mtp_function_cleanup, |
| 859 | .bind_config = mtp_function_bind_config, |
| 860 | .ctrlrequest = mtp_function_ctrlrequest, |
| 861 | }; |
| 862 | |
| 863 | /* PTP function is same as MTP with slightly different interface descriptor */ |
| 864 | static struct android_usb_function ptp_function = { |
| 865 | .name = "ptp", |
| 866 | .init = ptp_function_init, |
| 867 | .cleanup = ptp_function_cleanup, |
| 868 | .bind_config = ptp_function_bind_config, |
| 869 | }; |
| 870 | |
Devin Kim | 0c5b9ce | 2012-06-19 21:34:44 -0700 | [diff] [blame^] | 871 | #ifdef CONFIG_USB_ANDROID_CDC_ECM |
| 872 | struct ecm_function_config { |
| 873 | u8 ethaddr[ETH_ALEN]; |
| 874 | u32 vendorID; |
| 875 | char manufacturer[256]; |
| 876 | }; |
| 877 | |
| 878 | static int ecm_function_init(struct android_usb_function *f, |
| 879 | struct usb_composite_dev *cdev) |
| 880 | { |
| 881 | f->config = kzalloc(sizeof(struct ecm_function_config), GFP_KERNEL); |
| 882 | if (!f->config) |
| 883 | return -ENOMEM; |
| 884 | return 0; |
| 885 | } |
| 886 | |
| 887 | static void ecm_function_cleanup(struct android_usb_function *f) |
| 888 | { |
| 889 | kfree(f->config); |
| 890 | f->config = NULL; |
| 891 | } |
| 892 | |
| 893 | static int ecm_function_bind_config(struct android_usb_function *f, |
| 894 | struct usb_configuration *c) |
| 895 | { |
| 896 | int ret; |
| 897 | struct ecm_function_config *ecm = f->config; |
| 898 | |
| 899 | if (!ecm) { |
| 900 | pr_err("%s: ecm_function_config\n", __func__); |
| 901 | return -1; |
| 902 | } |
| 903 | |
| 904 | pr_info("%s MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", __func__, |
| 905 | ecm->ethaddr[0], ecm->ethaddr[1], ecm->ethaddr[2], |
| 906 | ecm->ethaddr[3], ecm->ethaddr[4], ecm->ethaddr[5]); |
| 907 | |
| 908 | ret = gether_setup_name(c->cdev->gadget, ecm->ethaddr, "usb"); |
| 909 | if (ret) { |
| 910 | pr_err("%s: gether_setup failed\n", __func__); |
| 911 | return ret; |
| 912 | } |
| 913 | |
| 914 | return ecm_bind_config(c, ecm->ethaddr); |
| 915 | } |
| 916 | |
| 917 | static void ecm_function_unbind_config(struct android_usb_function *f, |
| 918 | struct usb_configuration *c) |
| 919 | { |
| 920 | gether_cleanup(); |
| 921 | } |
| 922 | |
| 923 | static ssize_t ecm_manufacturer_show(struct device *dev, |
| 924 | struct device_attribute *attr, char *buf) |
| 925 | { |
| 926 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 927 | struct ecm_function_config *config = f->config; |
| 928 | |
| 929 | return snprintf(buf, PAGE_SIZE, "%s\n", config->manufacturer); |
| 930 | } |
| 931 | |
| 932 | static ssize_t ecm_manufacturer_store(struct device *dev, |
| 933 | struct device_attribute *attr, const char *buf, size_t size) |
| 934 | { |
| 935 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 936 | struct ecm_function_config *config = f->config; |
| 937 | |
| 938 | if (size >= sizeof(config->manufacturer)) |
| 939 | return -EINVAL; |
| 940 | |
| 941 | if (sscanf(buf, "%255s", config->manufacturer) == 1) |
| 942 | return size; |
| 943 | return -1; |
| 944 | } |
| 945 | |
| 946 | static DEVICE_ATTR(manufacturer, S_IRUGO | S_IWUSR, ecm_manufacturer_show, |
| 947 | ecm_manufacturer_store); |
| 948 | |
| 949 | static ssize_t ecm_ethaddr_show(struct device *dev, |
| 950 | struct device_attribute *attr, char *buf) |
| 951 | { |
| 952 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 953 | struct ecm_function_config *ecm = f->config; |
| 954 | return sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n", |
| 955 | ecm->ethaddr[0], ecm->ethaddr[1], ecm->ethaddr[2], |
| 956 | ecm->ethaddr[3], ecm->ethaddr[4], ecm->ethaddr[5]); |
| 957 | } |
| 958 | |
| 959 | static ssize_t ecm_ethaddr_store(struct device *dev, |
| 960 | struct device_attribute *attr, const char *buf, size_t size) |
| 961 | { |
| 962 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 963 | struct ecm_function_config *ecm = f->config; |
| 964 | |
| 965 | if (sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n", |
| 966 | (int *)&ecm->ethaddr[0], (int *)&ecm->ethaddr[1], |
| 967 | (int *)&ecm->ethaddr[2], (int *)&ecm->ethaddr[3], |
| 968 | (int *)&ecm->ethaddr[4], (int *)&ecm->ethaddr[5]) == 6) |
| 969 | return size; |
| 970 | return -EINVAL; |
| 971 | } |
| 972 | |
| 973 | static DEVICE_ATTR(ethaddr, S_IRUGO | S_IWUSR, ecm_ethaddr_show, |
| 974 | ecm_ethaddr_store); |
| 975 | |
| 976 | static ssize_t ecm_vendorID_show(struct device *dev, |
| 977 | struct device_attribute *attr, char *buf) |
| 978 | { |
| 979 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 980 | struct ecm_function_config *config = f->config; |
| 981 | |
| 982 | return snprintf(buf, PAGE_SIZE, "%04x\n", config->vendorID); |
| 983 | } |
| 984 | |
| 985 | static ssize_t ecm_vendorID_store(struct device *dev, |
| 986 | struct device_attribute *attr, const char *buf, size_t size) |
| 987 | { |
| 988 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 989 | struct ecm_function_config *config = f->config; |
| 990 | int value; |
| 991 | |
| 992 | if (sscanf(buf, "%04x", &value) == 1) { |
| 993 | config->vendorID = value; |
| 994 | return size; |
| 995 | } |
| 996 | return -EINVAL; |
| 997 | } |
| 998 | |
| 999 | static DEVICE_ATTR(vendorID, S_IRUGO | S_IWUSR, ecm_vendorID_show, |
| 1000 | ecm_vendorID_store); |
| 1001 | |
| 1002 | static struct device_attribute *ecm_function_attributes[] = { |
| 1003 | &dev_attr_manufacturer, |
| 1004 | &dev_attr_ethaddr, |
| 1005 | &dev_attr_vendorID, |
| 1006 | NULL |
| 1007 | }; |
| 1008 | |
| 1009 | static struct android_usb_function ecm_function = { |
| 1010 | .name = "ecm", |
| 1011 | .init = ecm_function_init, |
| 1012 | .cleanup = ecm_function_cleanup, |
| 1013 | .bind_config = ecm_function_bind_config, |
| 1014 | .unbind_config = ecm_function_unbind_config, |
| 1015 | .attributes = ecm_function_attributes, |
| 1016 | }; |
| 1017 | |
| 1018 | #else |
Benoit Goby | f0fbc48 | 2011-12-19 14:37:50 -0800 | [diff] [blame] | 1019 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1020 | struct rndis_function_config { |
| 1021 | u8 ethaddr[ETH_ALEN]; |
| 1022 | u32 vendorID; |
| 1023 | char manufacturer[256]; |
| 1024 | /* "Wireless" RNDIS; auto-detected by Windows */ |
| 1025 | bool wceis; |
| 1026 | }; |
| 1027 | |
| 1028 | static int |
| 1029 | rndis_function_init(struct android_usb_function *f, |
| 1030 | struct usb_composite_dev *cdev) |
| 1031 | { |
| 1032 | f->config = kzalloc(sizeof(struct rndis_function_config), GFP_KERNEL); |
| 1033 | if (!f->config) |
| 1034 | return -ENOMEM; |
| 1035 | return 0; |
| 1036 | } |
| 1037 | |
| 1038 | static void rndis_function_cleanup(struct android_usb_function *f) |
| 1039 | { |
| 1040 | kfree(f->config); |
| 1041 | f->config = NULL; |
| 1042 | } |
| 1043 | |
| 1044 | static int |
| 1045 | rndis_function_bind_config(struct android_usb_function *f, |
| 1046 | struct usb_configuration *c) |
| 1047 | { |
| 1048 | int ret; |
| 1049 | struct rndis_function_config *rndis = f->config; |
| 1050 | |
| 1051 | if (!rndis) { |
| 1052 | pr_err("%s: rndis_pdata\n", __func__); |
| 1053 | return -1; |
| 1054 | } |
| 1055 | |
| 1056 | pr_info("%s MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", __func__, |
| 1057 | rndis->ethaddr[0], rndis->ethaddr[1], rndis->ethaddr[2], |
| 1058 | rndis->ethaddr[3], rndis->ethaddr[4], rndis->ethaddr[5]); |
| 1059 | |
| 1060 | ret = gether_setup_name(c->cdev->gadget, rndis->ethaddr, "rndis"); |
| 1061 | if (ret) { |
| 1062 | pr_err("%s: gether_setup failed\n", __func__); |
| 1063 | return ret; |
| 1064 | } |
| 1065 | |
| 1066 | if (rndis->wceis) { |
| 1067 | /* "Wireless" RNDIS; auto-detected by Windows */ |
| 1068 | rndis_iad_descriptor.bFunctionClass = |
| 1069 | USB_CLASS_WIRELESS_CONTROLLER; |
| 1070 | rndis_iad_descriptor.bFunctionSubClass = 0x01; |
| 1071 | rndis_iad_descriptor.bFunctionProtocol = 0x03; |
| 1072 | rndis_control_intf.bInterfaceClass = |
| 1073 | USB_CLASS_WIRELESS_CONTROLLER; |
| 1074 | rndis_control_intf.bInterfaceSubClass = 0x01; |
| 1075 | rndis_control_intf.bInterfaceProtocol = 0x03; |
| 1076 | } |
| 1077 | |
| 1078 | return rndis_bind_config_vendor(c, rndis->ethaddr, rndis->vendorID, |
| 1079 | rndis->manufacturer); |
| 1080 | } |
| 1081 | |
| 1082 | static void rndis_function_unbind_config(struct android_usb_function *f, |
| 1083 | struct usb_configuration *c) |
| 1084 | { |
| 1085 | gether_cleanup(); |
| 1086 | } |
| 1087 | |
| 1088 | static ssize_t rndis_manufacturer_show(struct device *dev, |
| 1089 | struct device_attribute *attr, char *buf) |
| 1090 | { |
| 1091 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 1092 | struct rndis_function_config *config = f->config; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1093 | |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1094 | return snprintf(buf, PAGE_SIZE, "%s\n", config->manufacturer); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | static ssize_t rndis_manufacturer_store(struct device *dev, |
| 1098 | struct device_attribute *attr, const char *buf, size_t size) |
| 1099 | { |
| 1100 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 1101 | struct rndis_function_config *config = f->config; |
| 1102 | |
| 1103 | if (size >= sizeof(config->manufacturer)) |
| 1104 | return -EINVAL; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1105 | |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1106 | if (sscanf(buf, "%255s", config->manufacturer) == 1) |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1107 | return size; |
| 1108 | return -1; |
| 1109 | } |
| 1110 | |
| 1111 | static DEVICE_ATTR(manufacturer, S_IRUGO | S_IWUSR, rndis_manufacturer_show, |
| 1112 | rndis_manufacturer_store); |
| 1113 | |
| 1114 | static ssize_t rndis_wceis_show(struct device *dev, |
| 1115 | struct device_attribute *attr, char *buf) |
| 1116 | { |
| 1117 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 1118 | struct rndis_function_config *config = f->config; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1119 | |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1120 | return snprintf(buf, PAGE_SIZE, "%d\n", config->wceis); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | static ssize_t rndis_wceis_store(struct device *dev, |
| 1124 | struct device_attribute *attr, const char *buf, size_t size) |
| 1125 | { |
| 1126 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 1127 | struct rndis_function_config *config = f->config; |
| 1128 | int value; |
| 1129 | |
| 1130 | if (sscanf(buf, "%d", &value) == 1) { |
| 1131 | config->wceis = value; |
| 1132 | return size; |
| 1133 | } |
| 1134 | return -EINVAL; |
| 1135 | } |
| 1136 | |
| 1137 | static DEVICE_ATTR(wceis, S_IRUGO | S_IWUSR, rndis_wceis_show, |
| 1138 | rndis_wceis_store); |
| 1139 | |
| 1140 | static ssize_t rndis_ethaddr_show(struct device *dev, |
| 1141 | struct device_attribute *attr, char *buf) |
| 1142 | { |
| 1143 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 1144 | struct rndis_function_config *rndis = f->config; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1145 | |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1146 | return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n", |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1147 | rndis->ethaddr[0], rndis->ethaddr[1], rndis->ethaddr[2], |
| 1148 | rndis->ethaddr[3], rndis->ethaddr[4], rndis->ethaddr[5]); |
| 1149 | } |
| 1150 | |
| 1151 | static ssize_t rndis_ethaddr_store(struct device *dev, |
| 1152 | struct device_attribute *attr, const char *buf, size_t size) |
| 1153 | { |
| 1154 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 1155 | struct rndis_function_config *rndis = f->config; |
| 1156 | |
| 1157 | if (sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n", |
| 1158 | (int *)&rndis->ethaddr[0], (int *)&rndis->ethaddr[1], |
| 1159 | (int *)&rndis->ethaddr[2], (int *)&rndis->ethaddr[3], |
| 1160 | (int *)&rndis->ethaddr[4], (int *)&rndis->ethaddr[5]) == 6) |
| 1161 | return size; |
| 1162 | return -EINVAL; |
| 1163 | } |
| 1164 | |
| 1165 | static DEVICE_ATTR(ethaddr, S_IRUGO | S_IWUSR, rndis_ethaddr_show, |
| 1166 | rndis_ethaddr_store); |
| 1167 | |
| 1168 | static ssize_t rndis_vendorID_show(struct device *dev, |
| 1169 | struct device_attribute *attr, char *buf) |
| 1170 | { |
| 1171 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 1172 | struct rndis_function_config *config = f->config; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1173 | |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1174 | return snprintf(buf, PAGE_SIZE, "%04x\n", config->vendorID); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | static ssize_t rndis_vendorID_store(struct device *dev, |
| 1178 | struct device_attribute *attr, const char *buf, size_t size) |
| 1179 | { |
| 1180 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 1181 | struct rndis_function_config *config = f->config; |
| 1182 | int value; |
| 1183 | |
| 1184 | if (sscanf(buf, "%04x", &value) == 1) { |
| 1185 | config->vendorID = value; |
| 1186 | return size; |
| 1187 | } |
| 1188 | return -EINVAL; |
| 1189 | } |
| 1190 | |
| 1191 | static DEVICE_ATTR(vendorID, S_IRUGO | S_IWUSR, rndis_vendorID_show, |
| 1192 | rndis_vendorID_store); |
| 1193 | |
| 1194 | static struct device_attribute *rndis_function_attributes[] = { |
| 1195 | &dev_attr_manufacturer, |
| 1196 | &dev_attr_wceis, |
| 1197 | &dev_attr_ethaddr, |
| 1198 | &dev_attr_vendorID, |
| 1199 | NULL |
| 1200 | }; |
| 1201 | |
| 1202 | static struct android_usb_function rndis_function = { |
| 1203 | .name = "rndis", |
| 1204 | .init = rndis_function_init, |
| 1205 | .cleanup = rndis_function_cleanup, |
| 1206 | .bind_config = rndis_function_bind_config, |
| 1207 | .unbind_config = rndis_function_unbind_config, |
| 1208 | .attributes = rndis_function_attributes, |
| 1209 | }; |
Devin Kim | 0c5b9ce | 2012-06-19 21:34:44 -0700 | [diff] [blame^] | 1210 | #endif /* CONFIG_USB_ANDROID_CDC_ECM */ |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1211 | |
| 1212 | struct mass_storage_function_config { |
| 1213 | struct fsg_config fsg; |
| 1214 | struct fsg_common *common; |
| 1215 | }; |
| 1216 | |
| 1217 | static int mass_storage_function_init(struct android_usb_function *f, |
| 1218 | struct usb_composite_dev *cdev) |
| 1219 | { |
| 1220 | struct mass_storage_function_config *config; |
| 1221 | struct fsg_common *common; |
| 1222 | int err; |
| 1223 | |
| 1224 | config = kzalloc(sizeof(struct mass_storage_function_config), |
| 1225 | GFP_KERNEL); |
| 1226 | if (!config) |
| 1227 | return -ENOMEM; |
| 1228 | |
| 1229 | config->fsg.nluns = 1; |
| 1230 | config->fsg.luns[0].removable = 1; |
| 1231 | |
| 1232 | common = fsg_common_init(NULL, cdev, &config->fsg); |
| 1233 | if (IS_ERR(common)) { |
| 1234 | kfree(config); |
| 1235 | return PTR_ERR(common); |
| 1236 | } |
| 1237 | |
| 1238 | err = sysfs_create_link(&f->dev->kobj, |
| 1239 | &common->luns[0].dev.kobj, |
| 1240 | "lun"); |
| 1241 | if (err) { |
Rajkumar Raghupathy | 01f599c | 2011-10-25 15:32:43 +0530 | [diff] [blame] | 1242 | fsg_common_release(&common->ref); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1243 | kfree(config); |
| 1244 | return err; |
| 1245 | } |
| 1246 | |
| 1247 | config->common = common; |
| 1248 | f->config = config; |
| 1249 | return 0; |
| 1250 | } |
| 1251 | |
| 1252 | static void mass_storage_function_cleanup(struct android_usb_function *f) |
| 1253 | { |
| 1254 | kfree(f->config); |
| 1255 | f->config = NULL; |
| 1256 | } |
| 1257 | |
| 1258 | static int mass_storage_function_bind_config(struct android_usb_function *f, |
| 1259 | struct usb_configuration *c) |
| 1260 | { |
| 1261 | struct mass_storage_function_config *config = f->config; |
| 1262 | return fsg_bind_config(c->cdev, c, config->common); |
| 1263 | } |
| 1264 | |
| 1265 | static ssize_t mass_storage_inquiry_show(struct device *dev, |
| 1266 | struct device_attribute *attr, char *buf) |
| 1267 | { |
| 1268 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 1269 | struct mass_storage_function_config *config = f->config; |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1270 | return snprintf(buf, PAGE_SIZE, "%s\n", config->common->inquiry_string); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | static ssize_t mass_storage_inquiry_store(struct device *dev, |
| 1274 | struct device_attribute *attr, const char *buf, size_t size) |
| 1275 | { |
| 1276 | struct android_usb_function *f = dev_get_drvdata(dev); |
| 1277 | struct mass_storage_function_config *config = f->config; |
| 1278 | if (size >= sizeof(config->common->inquiry_string)) |
| 1279 | return -EINVAL; |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1280 | if (sscanf(buf, "%28s", config->common->inquiry_string) != 1) |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1281 | return -EINVAL; |
| 1282 | return size; |
| 1283 | } |
| 1284 | |
| 1285 | static DEVICE_ATTR(inquiry_string, S_IRUGO | S_IWUSR, |
| 1286 | mass_storage_inquiry_show, |
| 1287 | mass_storage_inquiry_store); |
| 1288 | |
| 1289 | static struct device_attribute *mass_storage_function_attributes[] = { |
| 1290 | &dev_attr_inquiry_string, |
| 1291 | NULL |
| 1292 | }; |
| 1293 | |
| 1294 | static struct android_usb_function mass_storage_function = { |
| 1295 | .name = "mass_storage", |
| 1296 | .init = mass_storage_function_init, |
| 1297 | .cleanup = mass_storage_function_cleanup, |
| 1298 | .bind_config = mass_storage_function_bind_config, |
| 1299 | .attributes = mass_storage_function_attributes, |
| 1300 | }; |
| 1301 | |
| 1302 | |
Benoit Goby | cf3fc06 | 2011-12-19 14:39:37 -0800 | [diff] [blame] | 1303 | static int accessory_function_init(struct android_usb_function *f, |
| 1304 | struct usb_composite_dev *cdev) |
| 1305 | { |
| 1306 | return acc_setup(); |
| 1307 | } |
| 1308 | |
| 1309 | static void accessory_function_cleanup(struct android_usb_function *f) |
| 1310 | { |
| 1311 | acc_cleanup(); |
| 1312 | } |
| 1313 | |
| 1314 | static int accessory_function_bind_config(struct android_usb_function *f, |
| 1315 | struct usb_configuration *c) |
| 1316 | { |
| 1317 | return acc_bind_config(c); |
| 1318 | } |
| 1319 | |
| 1320 | static int accessory_function_ctrlrequest(struct android_usb_function *f, |
| 1321 | struct usb_composite_dev *cdev, |
| 1322 | const struct usb_ctrlrequest *c) |
| 1323 | { |
| 1324 | return acc_ctrlrequest(cdev, c); |
| 1325 | } |
| 1326 | |
| 1327 | static struct android_usb_function accessory_function = { |
| 1328 | .name = "accessory", |
| 1329 | .init = accessory_function_init, |
| 1330 | .cleanup = accessory_function_cleanup, |
| 1331 | .bind_config = accessory_function_bind_config, |
| 1332 | .ctrlrequest = accessory_function_ctrlrequest, |
| 1333 | }; |
| 1334 | |
| 1335 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1336 | static struct android_usb_function *supported_functions[] = { |
Anna Perel | a8c991d | 2012-04-09 16:44:46 +0300 | [diff] [blame] | 1337 | &mbim_function, |
Manu Gautam | 1c8ffd7 | 2011-09-02 16:00:49 +0530 | [diff] [blame] | 1338 | &rmnet_smd_function, |
Manu Gautam | 8e0719b | 2011-09-26 14:47:55 +0530 | [diff] [blame] | 1339 | &rmnet_sdio_function, |
| 1340 | &rmnet_smd_sdio_function, |
Manu Gautam | 2b0234a | 2011-09-07 16:47:52 +0530 | [diff] [blame] | 1341 | &rmnet_function, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1342 | &diag_function, |
Manu Gautam | a4d993f | 2011-08-30 18:25:55 +0530 | [diff] [blame] | 1343 | &serial_function, |
Benoit Goby | 2b6862d | 2011-12-19 14:38:41 -0800 | [diff] [blame] | 1344 | &adb_function, |
Chiranjeevi Velempati | e130fd0 | 2011-11-29 05:06:13 +0530 | [diff] [blame] | 1345 | &ccid_function, |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1346 | &acm_function, |
Benoit Goby | f0fbc48 | 2011-12-19 14:37:50 -0800 | [diff] [blame] | 1347 | &mtp_function, |
| 1348 | &ptp_function, |
Devin Kim | 0c5b9ce | 2012-06-19 21:34:44 -0700 | [diff] [blame^] | 1349 | #ifdef CONFIG_USB_ANDROID_CDC_ECM |
| 1350 | &ecm_function, |
| 1351 | #else |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1352 | &rndis_function, |
Devin Kim | 0c5b9ce | 2012-06-19 21:34:44 -0700 | [diff] [blame^] | 1353 | #endif |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1354 | &mass_storage_function, |
Benoit Goby | cf3fc06 | 2011-12-19 14:39:37 -0800 | [diff] [blame] | 1355 | &accessory_function, |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1356 | NULL |
| 1357 | }; |
| 1358 | |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1359 | static void android_cleanup_functions(struct android_usb_function **functions) |
| 1360 | { |
| 1361 | struct android_usb_function *f; |
| 1362 | struct device_attribute **attrs; |
| 1363 | struct device_attribute *attr; |
| 1364 | |
| 1365 | while (*functions) { |
| 1366 | f = *functions++; |
| 1367 | |
| 1368 | if (f->dev) { |
| 1369 | device_destroy(android_class, f->dev->devt); |
| 1370 | kfree(f->dev_name); |
| 1371 | } else |
| 1372 | continue; |
| 1373 | |
| 1374 | if (f->cleanup) |
| 1375 | f->cleanup(f); |
| 1376 | |
| 1377 | attrs = f->attributes; |
| 1378 | if (attrs) { |
| 1379 | while ((attr = *attrs++)) |
| 1380 | device_remove_file(f->dev, attr); |
| 1381 | } |
| 1382 | } |
| 1383 | } |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1384 | |
| 1385 | static int android_init_functions(struct android_usb_function **functions, |
| 1386 | struct usb_composite_dev *cdev) |
| 1387 | { |
| 1388 | struct android_dev *dev = _android_dev; |
| 1389 | struct android_usb_function *f; |
| 1390 | struct device_attribute **attrs; |
| 1391 | struct device_attribute *attr; |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1392 | int err = 0; |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1393 | int index = 1; /* index 0 is for android0 device */ |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1394 | |
| 1395 | for (; (f = *functions++); index++) { |
| 1396 | f->dev_name = kasprintf(GFP_KERNEL, "f_%s", f->name); |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1397 | if (!f->dev_name) { |
| 1398 | err = -ENOMEM; |
| 1399 | goto err_out; |
| 1400 | } |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1401 | f->dev = device_create(android_class, dev->dev, |
| 1402 | MKDEV(0, index), f, f->dev_name); |
| 1403 | if (IS_ERR(f->dev)) { |
| 1404 | pr_err("%s: Failed to create dev %s", __func__, |
| 1405 | f->dev_name); |
| 1406 | err = PTR_ERR(f->dev); |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1407 | f->dev = NULL; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1408 | goto err_create; |
| 1409 | } |
| 1410 | |
| 1411 | if (f->init) { |
| 1412 | err = f->init(f, cdev); |
| 1413 | if (err) { |
| 1414 | pr_err("%s: Failed to init %s", __func__, |
| 1415 | f->name); |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1416 | goto err_init; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | attrs = f->attributes; |
| 1421 | if (attrs) { |
| 1422 | while ((attr = *attrs++) && !err) |
| 1423 | err = device_create_file(f->dev, attr); |
| 1424 | } |
| 1425 | if (err) { |
| 1426 | pr_err("%s: Failed to create function %s attributes", |
| 1427 | __func__, f->name); |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1428 | goto err_attrs; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1429 | } |
| 1430 | } |
| 1431 | return 0; |
| 1432 | |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1433 | err_attrs: |
| 1434 | for (attr = *(attrs -= 2); attrs != f->attributes; attr = *(attrs--)) |
| 1435 | device_remove_file(f->dev, attr); |
| 1436 | if (f->cleanup) |
| 1437 | f->cleanup(f); |
| 1438 | err_init: |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1439 | device_destroy(android_class, f->dev->devt); |
| 1440 | err_create: |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1441 | f->dev = NULL; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1442 | kfree(f->dev_name); |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1443 | err_out: |
| 1444 | android_cleanup_functions(dev->functions); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1445 | return err; |
| 1446 | } |
| 1447 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1448 | static int |
| 1449 | android_bind_enabled_functions(struct android_dev *dev, |
| 1450 | struct usb_configuration *c) |
| 1451 | { |
| 1452 | struct android_usb_function *f; |
| 1453 | int ret; |
| 1454 | |
| 1455 | list_for_each_entry(f, &dev->enabled_functions, enabled_list) { |
| 1456 | ret = f->bind_config(f, c); |
| 1457 | if (ret) { |
| 1458 | pr_err("%s: %s failed", __func__, f->name); |
| 1459 | return ret; |
| 1460 | } |
| 1461 | } |
| 1462 | return 0; |
| 1463 | } |
| 1464 | |
| 1465 | static void |
| 1466 | android_unbind_enabled_functions(struct android_dev *dev, |
| 1467 | struct usb_configuration *c) |
| 1468 | { |
| 1469 | struct android_usb_function *f; |
| 1470 | |
| 1471 | list_for_each_entry(f, &dev->enabled_functions, enabled_list) { |
| 1472 | if (f->unbind_config) |
| 1473 | f->unbind_config(f, c); |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | static int android_enable_function(struct android_dev *dev, char *name) |
| 1478 | { |
| 1479 | struct android_usb_function **functions = dev->functions; |
| 1480 | struct android_usb_function *f; |
| 1481 | while ((f = *functions++)) { |
| 1482 | if (!strcmp(name, f->name)) { |
| 1483 | list_add_tail(&f->enabled_list, |
| 1484 | &dev->enabled_functions); |
| 1485 | return 0; |
| 1486 | } |
| 1487 | } |
| 1488 | return -EINVAL; |
| 1489 | } |
| 1490 | |
| 1491 | /*-------------------------------------------------------------------------*/ |
| 1492 | /* /sys/class/android_usb/android%d/ interface */ |
| 1493 | |
Pavankumar Kondeti | 352396c | 2011-12-07 13:32:40 +0530 | [diff] [blame] | 1494 | static ssize_t remote_wakeup_show(struct device *pdev, |
| 1495 | struct device_attribute *attr, char *buf) |
| 1496 | { |
| 1497 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 1498 | !!(android_config_driver.bmAttributes & |
| 1499 | USB_CONFIG_ATT_WAKEUP)); |
| 1500 | } |
| 1501 | |
| 1502 | static ssize_t remote_wakeup_store(struct device *pdev, |
| 1503 | struct device_attribute *attr, const char *buff, size_t size) |
| 1504 | { |
| 1505 | int enable = 0; |
| 1506 | |
| 1507 | sscanf(buff, "%d", &enable); |
| 1508 | |
| 1509 | pr_debug("android_usb: %s remote wakeup\n", |
| 1510 | enable ? "enabling" : "disabling"); |
| 1511 | |
| 1512 | if (enable) |
| 1513 | android_config_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
| 1514 | else |
| 1515 | android_config_driver.bmAttributes &= ~USB_CONFIG_ATT_WAKEUP; |
| 1516 | |
| 1517 | return size; |
| 1518 | } |
| 1519 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1520 | static ssize_t |
| 1521 | functions_show(struct device *pdev, struct device_attribute *attr, char *buf) |
| 1522 | { |
| 1523 | struct android_dev *dev = dev_get_drvdata(pdev); |
| 1524 | struct android_usb_function *f; |
| 1525 | char *buff = buf; |
| 1526 | |
| 1527 | mutex_lock(&dev->mutex); |
| 1528 | |
| 1529 | list_for_each_entry(f, &dev->enabled_functions, enabled_list) |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1530 | buff += snprintf(buff, PAGE_SIZE, "%s,", f->name); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1531 | |
| 1532 | mutex_unlock(&dev->mutex); |
| 1533 | |
| 1534 | if (buff != buf) |
| 1535 | *(buff-1) = '\n'; |
| 1536 | return buff - buf; |
| 1537 | } |
| 1538 | |
| 1539 | static ssize_t |
| 1540 | functions_store(struct device *pdev, struct device_attribute *attr, |
| 1541 | const char *buff, size_t size) |
| 1542 | { |
| 1543 | struct android_dev *dev = dev_get_drvdata(pdev); |
| 1544 | char *name; |
| 1545 | char buf[256], *b; |
| 1546 | int err; |
| 1547 | |
| 1548 | mutex_lock(&dev->mutex); |
| 1549 | |
| 1550 | if (dev->enabled) { |
| 1551 | mutex_unlock(&dev->mutex); |
| 1552 | return -EBUSY; |
| 1553 | } |
| 1554 | |
| 1555 | INIT_LIST_HEAD(&dev->enabled_functions); |
| 1556 | |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1557 | strlcpy(buf, buff, sizeof(buf)); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1558 | b = strim(buf); |
| 1559 | |
| 1560 | while (b) { |
| 1561 | name = strsep(&b, ","); |
| 1562 | if (name) { |
| 1563 | err = android_enable_function(dev, name); |
| 1564 | if (err) |
| 1565 | pr_err("android_usb: Cannot enable '%s'", name); |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | mutex_unlock(&dev->mutex); |
| 1570 | |
| 1571 | return size; |
| 1572 | } |
| 1573 | |
| 1574 | static ssize_t enable_show(struct device *pdev, struct device_attribute *attr, |
| 1575 | char *buf) |
| 1576 | { |
| 1577 | struct android_dev *dev = dev_get_drvdata(pdev); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1578 | |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1579 | return snprintf(buf, PAGE_SIZE, "%d\n", dev->enabled); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | static ssize_t enable_store(struct device *pdev, struct device_attribute *attr, |
| 1583 | const char *buff, size_t size) |
| 1584 | { |
| 1585 | struct android_dev *dev = dev_get_drvdata(pdev); |
| 1586 | struct usb_composite_dev *cdev = dev->cdev; |
Benoit Goby | 80ba14d | 2012-03-19 18:56:52 -0700 | [diff] [blame] | 1587 | struct android_usb_function *f; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1588 | int enabled = 0; |
| 1589 | |
Benoit Goby | cf3fc06 | 2011-12-19 14:39:37 -0800 | [diff] [blame] | 1590 | if (!cdev) |
| 1591 | return -ENODEV; |
| 1592 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1593 | mutex_lock(&dev->mutex); |
| 1594 | |
| 1595 | sscanf(buff, "%d", &enabled); |
| 1596 | if (enabled && !dev->enabled) { |
| 1597 | cdev->next_string_id = 0; |
| 1598 | /* |
| 1599 | * Update values in composite driver's copy of |
| 1600 | * device descriptor. |
| 1601 | */ |
| 1602 | cdev->desc.idVendor = device_desc.idVendor; |
| 1603 | cdev->desc.idProduct = device_desc.idProduct; |
| 1604 | cdev->desc.bcdDevice = device_desc.bcdDevice; |
| 1605 | cdev->desc.bDeviceClass = device_desc.bDeviceClass; |
| 1606 | cdev->desc.bDeviceSubClass = device_desc.bDeviceSubClass; |
| 1607 | cdev->desc.bDeviceProtocol = device_desc.bDeviceProtocol; |
Benoit Goby | 80ba14d | 2012-03-19 18:56:52 -0700 | [diff] [blame] | 1608 | list_for_each_entry(f, &dev->enabled_functions, enabled_list) { |
| 1609 | if (f->enable) |
| 1610 | f->enable(f); |
| 1611 | } |
| 1612 | android_enable(dev); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1613 | dev->enabled = true; |
| 1614 | } else if (!enabled && dev->enabled) { |
Benoit Goby | 80ba14d | 2012-03-19 18:56:52 -0700 | [diff] [blame] | 1615 | android_disable(dev); |
| 1616 | list_for_each_entry(f, &dev->enabled_functions, enabled_list) { |
| 1617 | if (f->disable) |
| 1618 | f->disable(f); |
| 1619 | } |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1620 | dev->enabled = false; |
| 1621 | } else { |
| 1622 | pr_err("android_usb: already %s\n", |
| 1623 | dev->enabled ? "enabled" : "disabled"); |
| 1624 | } |
| 1625 | |
| 1626 | mutex_unlock(&dev->mutex); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1627 | |
Benoit Goby | aab9681 | 2011-04-19 20:37:33 -0700 | [diff] [blame] | 1628 | return size; |
| 1629 | } |
| 1630 | |
Ofir Cohen | 94213a7 | 2012-05-03 14:26:32 +0300 | [diff] [blame] | 1631 | static ssize_t pm_qos_show(struct device *pdev, |
| 1632 | struct device_attribute *attr, char *buf) |
| 1633 | { |
| 1634 | struct android_dev *dev = dev_get_drvdata(pdev); |
| 1635 | |
| 1636 | return snprintf(buf, PAGE_SIZE, "%s\n", dev->pm_qos); |
| 1637 | } |
| 1638 | |
| 1639 | static ssize_t pm_qos_store(struct device *pdev, |
| 1640 | struct device_attribute *attr, |
| 1641 | const char *buff, size_t size) |
| 1642 | { |
| 1643 | struct android_dev *dev = dev_get_drvdata(pdev); |
| 1644 | |
| 1645 | strlcpy(dev->pm_qos, buff, sizeof(dev->pm_qos)); |
| 1646 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1647 | return size; |
| 1648 | } |
| 1649 | |
| 1650 | static ssize_t state_show(struct device *pdev, struct device_attribute *attr, |
| 1651 | char *buf) |
| 1652 | { |
| 1653 | struct android_dev *dev = dev_get_drvdata(pdev); |
| 1654 | struct usb_composite_dev *cdev = dev->cdev; |
| 1655 | char *state = "DISCONNECTED"; |
| 1656 | unsigned long flags; |
| 1657 | |
| 1658 | if (!cdev) |
| 1659 | goto out; |
| 1660 | |
| 1661 | spin_lock_irqsave(&cdev->lock, flags); |
| 1662 | if (cdev->config) |
| 1663 | state = "CONFIGURED"; |
| 1664 | else if (dev->connected) |
| 1665 | state = "CONNECTED"; |
| 1666 | spin_unlock_irqrestore(&cdev->lock, flags); |
| 1667 | out: |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1668 | return snprintf(buf, PAGE_SIZE, "%s\n", state); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | #define DESCRIPTOR_ATTR(field, format_string) \ |
| 1672 | static ssize_t \ |
| 1673 | field ## _show(struct device *dev, struct device_attribute *attr, \ |
| 1674 | char *buf) \ |
| 1675 | { \ |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1676 | return snprintf(buf, PAGE_SIZE, \ |
| 1677 | format_string, device_desc.field); \ |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1678 | } \ |
| 1679 | static ssize_t \ |
| 1680 | field ## _store(struct device *dev, struct device_attribute *attr, \ |
| 1681 | const char *buf, size_t size) \ |
| 1682 | { \ |
| 1683 | int value; \ |
| 1684 | if (sscanf(buf, format_string, &value) == 1) { \ |
| 1685 | device_desc.field = value; \ |
| 1686 | return size; \ |
| 1687 | } \ |
| 1688 | return -1; \ |
| 1689 | } \ |
| 1690 | static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, field ## _show, field ## _store); |
| 1691 | |
| 1692 | #define DESCRIPTOR_STRING_ATTR(field, buffer) \ |
| 1693 | static ssize_t \ |
| 1694 | field ## _show(struct device *dev, struct device_attribute *attr, \ |
| 1695 | char *buf) \ |
| 1696 | { \ |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1697 | return snprintf(buf, PAGE_SIZE, "%s", buffer); \ |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1698 | } \ |
| 1699 | static ssize_t \ |
| 1700 | field ## _store(struct device *dev, struct device_attribute *attr, \ |
| 1701 | const char *buf, size_t size) \ |
| 1702 | { \ |
| 1703 | if (size >= sizeof(buffer)) \ |
| 1704 | return -EINVAL; \ |
Benoit Goby | dcefb2e | 2012-05-29 13:57:27 -0700 | [diff] [blame] | 1705 | return strlcpy(buffer, buf, sizeof(buffer)); \ |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1706 | } \ |
| 1707 | static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, field ## _show, field ## _store); |
| 1708 | |
| 1709 | |
| 1710 | DESCRIPTOR_ATTR(idVendor, "%04x\n") |
| 1711 | DESCRIPTOR_ATTR(idProduct, "%04x\n") |
| 1712 | DESCRIPTOR_ATTR(bcdDevice, "%04x\n") |
| 1713 | DESCRIPTOR_ATTR(bDeviceClass, "%d\n") |
| 1714 | DESCRIPTOR_ATTR(bDeviceSubClass, "%d\n") |
| 1715 | DESCRIPTOR_ATTR(bDeviceProtocol, "%d\n") |
| 1716 | DESCRIPTOR_STRING_ATTR(iManufacturer, manufacturer_string) |
| 1717 | DESCRIPTOR_STRING_ATTR(iProduct, product_string) |
| 1718 | DESCRIPTOR_STRING_ATTR(iSerial, serial_string) |
| 1719 | |
| 1720 | static DEVICE_ATTR(functions, S_IRUGO | S_IWUSR, functions_show, |
| 1721 | functions_store); |
| 1722 | static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, enable_show, enable_store); |
Ofir Cohen | 94213a7 | 2012-05-03 14:26:32 +0300 | [diff] [blame] | 1723 | static DEVICE_ATTR(pm_qos, S_IRUGO | S_IWUSR, |
| 1724 | pm_qos_show, pm_qos_store); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1725 | static DEVICE_ATTR(state, S_IRUGO, state_show, NULL); |
Pavankumar Kondeti | 352396c | 2011-12-07 13:32:40 +0530 | [diff] [blame] | 1726 | static DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, |
| 1727 | remote_wakeup_show, remote_wakeup_store); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1728 | |
| 1729 | static struct device_attribute *android_usb_attributes[] = { |
| 1730 | &dev_attr_idVendor, |
| 1731 | &dev_attr_idProduct, |
| 1732 | &dev_attr_bcdDevice, |
| 1733 | &dev_attr_bDeviceClass, |
| 1734 | &dev_attr_bDeviceSubClass, |
| 1735 | &dev_attr_bDeviceProtocol, |
| 1736 | &dev_attr_iManufacturer, |
| 1737 | &dev_attr_iProduct, |
| 1738 | &dev_attr_iSerial, |
| 1739 | &dev_attr_functions, |
| 1740 | &dev_attr_enable, |
Ofir Cohen | 94213a7 | 2012-05-03 14:26:32 +0300 | [diff] [blame] | 1741 | &dev_attr_pm_qos, |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1742 | &dev_attr_state, |
Pavankumar Kondeti | 352396c | 2011-12-07 13:32:40 +0530 | [diff] [blame] | 1743 | &dev_attr_remote_wakeup, |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1744 | NULL |
| 1745 | }; |
| 1746 | |
| 1747 | /*-------------------------------------------------------------------------*/ |
| 1748 | /* Composite driver */ |
| 1749 | |
| 1750 | static int android_bind_config(struct usb_configuration *c) |
| 1751 | { |
| 1752 | struct android_dev *dev = _android_dev; |
| 1753 | int ret = 0; |
| 1754 | |
| 1755 | ret = android_bind_enabled_functions(dev, c); |
| 1756 | if (ret) |
| 1757 | return ret; |
| 1758 | |
| 1759 | return 0; |
| 1760 | } |
| 1761 | |
| 1762 | static void android_unbind_config(struct usb_configuration *c) |
| 1763 | { |
| 1764 | struct android_dev *dev = _android_dev; |
| 1765 | |
| 1766 | android_unbind_enabled_functions(dev, c); |
| 1767 | } |
| 1768 | |
| 1769 | static int android_bind(struct usb_composite_dev *cdev) |
| 1770 | { |
| 1771 | struct android_dev *dev = _android_dev; |
| 1772 | struct usb_gadget *gadget = cdev->gadget; |
| 1773 | int gcnum, id, ret; |
| 1774 | |
| 1775 | /* |
| 1776 | * Start disconnected. Userspace will connect the gadget once |
| 1777 | * it is done configuring the functions. |
| 1778 | */ |
| 1779 | usb_gadget_disconnect(gadget); |
| 1780 | |
| 1781 | ret = android_init_functions(dev->functions, cdev); |
| 1782 | if (ret) |
| 1783 | return ret; |
| 1784 | |
| 1785 | /* Allocate string descriptor numbers ... note that string |
| 1786 | * contents can be overridden by the composite_dev glue. |
| 1787 | */ |
| 1788 | id = usb_string_id(cdev); |
| 1789 | if (id < 0) |
| 1790 | return id; |
| 1791 | strings_dev[STRING_MANUFACTURER_IDX].id = id; |
| 1792 | device_desc.iManufacturer = id; |
| 1793 | |
| 1794 | id = usb_string_id(cdev); |
| 1795 | if (id < 0) |
| 1796 | return id; |
| 1797 | strings_dev[STRING_PRODUCT_IDX].id = id; |
| 1798 | device_desc.iProduct = id; |
| 1799 | |
| 1800 | /* Default strings - should be updated by userspace */ |
Rajkumar Raghupathy | 42ec8da | 2011-10-21 18:58:53 +0530 | [diff] [blame] | 1801 | strlcpy(manufacturer_string, "Android", |
| 1802 | sizeof(manufacturer_string) - 1); |
| 1803 | strlcpy(product_string, "Android", sizeof(product_string) - 1); |
| 1804 | strlcpy(serial_string, "0123456789ABCDEF", sizeof(serial_string) - 1); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1805 | |
| 1806 | id = usb_string_id(cdev); |
| 1807 | if (id < 0) |
| 1808 | return id; |
| 1809 | strings_dev[STRING_SERIAL_IDX].id = id; |
| 1810 | device_desc.iSerialNumber = id; |
| 1811 | |
Vijayavardhan Vennapusa | 56e6052 | 2012-02-16 15:40:16 +0530 | [diff] [blame] | 1812 | if (gadget_is_otg(cdev->gadget)) |
| 1813 | android_config_driver.descriptors = otg_desc; |
| 1814 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1815 | gcnum = usb_gadget_controller_number(gadget); |
| 1816 | if (gcnum >= 0) |
| 1817 | device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum); |
| 1818 | else { |
| 1819 | pr_warning("%s: controller '%s' not recognized\n", |
| 1820 | longname, gadget->name); |
| 1821 | device_desc.bcdDevice = __constant_cpu_to_le16(0x9999); |
| 1822 | } |
| 1823 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1824 | dev->cdev = cdev; |
| 1825 | |
| 1826 | return 0; |
| 1827 | } |
| 1828 | |
| 1829 | static int android_usb_unbind(struct usb_composite_dev *cdev) |
| 1830 | { |
| 1831 | struct android_dev *dev = _android_dev; |
| 1832 | |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1833 | manufacturer_string[0] = '\0'; |
| 1834 | product_string[0] = '\0'; |
| 1835 | serial_string[0] = '0'; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1836 | cancel_work_sync(&dev->work); |
| 1837 | android_cleanup_functions(dev->functions); |
| 1838 | return 0; |
| 1839 | } |
| 1840 | |
| 1841 | static struct usb_composite_driver android_usb_driver = { |
| 1842 | .name = "android_usb", |
| 1843 | .dev = &device_desc, |
| 1844 | .strings = dev_strings, |
| 1845 | .unbind = android_usb_unbind, |
Tatyana Brokhman | 3ba2890 | 2011-06-29 16:41:49 +0300 | [diff] [blame] | 1846 | .max_speed = USB_SPEED_SUPER |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1847 | }; |
| 1848 | |
| 1849 | static int |
| 1850 | android_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *c) |
| 1851 | { |
| 1852 | struct android_dev *dev = _android_dev; |
| 1853 | struct usb_composite_dev *cdev = get_gadget_data(gadget); |
| 1854 | struct usb_request *req = cdev->req; |
| 1855 | struct android_usb_function *f; |
| 1856 | int value = -EOPNOTSUPP; |
| 1857 | unsigned long flags; |
| 1858 | |
| 1859 | req->zero = 0; |
| 1860 | req->complete = composite_setup_complete; |
| 1861 | req->length = 0; |
| 1862 | gadget->ep0->driver_data = cdev; |
| 1863 | |
| 1864 | list_for_each_entry(f, &dev->enabled_functions, enabled_list) { |
| 1865 | if (f->ctrlrequest) { |
| 1866 | value = f->ctrlrequest(f, cdev, c); |
| 1867 | if (value >= 0) |
| 1868 | break; |
| 1869 | } |
| 1870 | } |
| 1871 | |
Benoit Goby | cf3fc06 | 2011-12-19 14:39:37 -0800 | [diff] [blame] | 1872 | /* Special case the accessory function. |
| 1873 | * It needs to handle control requests before it is enabled. |
| 1874 | */ |
| 1875 | if (value < 0) |
| 1876 | value = acc_ctrlrequest(cdev, c); |
| 1877 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1878 | if (value < 0) |
| 1879 | value = composite_setup(gadget, c); |
| 1880 | |
| 1881 | spin_lock_irqsave(&cdev->lock, flags); |
| 1882 | if (!dev->connected) { |
| 1883 | dev->connected = 1; |
| 1884 | schedule_work(&dev->work); |
| 1885 | } else if (c->bRequest == USB_REQ_SET_CONFIGURATION && |
| 1886 | cdev->config) { |
| 1887 | schedule_work(&dev->work); |
| 1888 | } |
| 1889 | spin_unlock_irqrestore(&cdev->lock, flags); |
| 1890 | |
| 1891 | return value; |
| 1892 | } |
| 1893 | |
| 1894 | static void android_disconnect(struct usb_gadget *gadget) |
| 1895 | { |
| 1896 | struct android_dev *dev = _android_dev; |
| 1897 | struct usb_composite_dev *cdev = get_gadget_data(gadget); |
| 1898 | unsigned long flags; |
| 1899 | |
| 1900 | composite_disconnect(gadget); |
| 1901 | |
| 1902 | spin_lock_irqsave(&cdev->lock, flags); |
| 1903 | dev->connected = 0; |
| 1904 | schedule_work(&dev->work); |
| 1905 | spin_unlock_irqrestore(&cdev->lock, flags); |
| 1906 | } |
| 1907 | |
| 1908 | static int android_create_device(struct android_dev *dev) |
| 1909 | { |
| 1910 | struct device_attribute **attrs = android_usb_attributes; |
| 1911 | struct device_attribute *attr; |
| 1912 | int err; |
| 1913 | |
| 1914 | dev->dev = device_create(android_class, NULL, |
| 1915 | MKDEV(0, 0), NULL, "android0"); |
| 1916 | if (IS_ERR(dev->dev)) |
| 1917 | return PTR_ERR(dev->dev); |
| 1918 | |
| 1919 | dev_set_drvdata(dev->dev, dev); |
| 1920 | |
| 1921 | while ((attr = *attrs++)) { |
| 1922 | err = device_create_file(dev->dev, attr); |
| 1923 | if (err) { |
| 1924 | device_destroy(android_class, dev->dev->devt); |
| 1925 | return err; |
| 1926 | } |
| 1927 | } |
| 1928 | return 0; |
| 1929 | } |
| 1930 | |
Rajkumar Raghupathy | a1df77e | 2012-01-19 17:45:55 +0530 | [diff] [blame] | 1931 | static void android_destroy_device(struct android_dev *dev) |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1932 | { |
Rajkumar Raghupathy | a1df77e | 2012-01-19 17:45:55 +0530 | [diff] [blame] | 1933 | struct device_attribute **attrs = android_usb_attributes; |
| 1934 | struct device_attribute *attr; |
| 1935 | |
| 1936 | while ((attr = *attrs++)) |
| 1937 | device_remove_file(dev->dev, attr); |
| 1938 | device_destroy(android_class, dev->dev->devt); |
| 1939 | } |
| 1940 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1941 | static int __devinit android_probe(struct platform_device *pdev) |
| 1942 | { |
| 1943 | struct android_usb_platform_data *pdata = pdev->dev.platform_data; |
| 1944 | struct android_dev *dev = _android_dev; |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1945 | int ret = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1946 | |
| 1947 | dev->pdata = pdata; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 1948 | |
| 1949 | android_class = class_create(THIS_MODULE, "android_usb"); |
| 1950 | if (IS_ERR(android_class)) |
| 1951 | return PTR_ERR(android_class); |
| 1952 | |
Rajkumar Raghupathy | 5d3fc39 | 2012-04-11 16:53:19 +0530 | [diff] [blame] | 1953 | ret = android_create_device(dev); |
| 1954 | if (ret) { |
| 1955 | pr_err("%s(): android_create_device failed\n", __func__); |
| 1956 | goto err_dev; |
| 1957 | } |
| 1958 | |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1959 | ret = usb_composite_probe(&android_usb_driver, android_bind); |
| 1960 | if (ret) { |
| 1961 | pr_err("%s(): Failed to register android " |
| 1962 | "composite driver\n", __func__); |
Rajkumar Raghupathy | 5d3fc39 | 2012-04-11 16:53:19 +0530 | [diff] [blame] | 1963 | goto err_probe; |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1964 | } |
| 1965 | |
Ofir Cohen | 94213a7 | 2012-05-03 14:26:32 +0300 | [diff] [blame] | 1966 | /* pm qos request to prevent apps idle power collapse */ |
Manu Gautam | 94dc614 | 2012-05-08 14:35:24 +0530 | [diff] [blame] | 1967 | if (pdata && pdata->swfi_latency) |
Ofir Cohen | 94213a7 | 2012-05-03 14:26:32 +0300 | [diff] [blame] | 1968 | pm_qos_add_request(&dev->pm_qos_req_dma, |
| 1969 | PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE); |
| 1970 | strlcpy(dev->pm_qos, "high", sizeof(dev->pm_qos)); |
| 1971 | |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1972 | return ret; |
Rajkumar Raghupathy | 5d3fc39 | 2012-04-11 16:53:19 +0530 | [diff] [blame] | 1973 | err_probe: |
| 1974 | android_destroy_device(dev); |
| 1975 | err_dev: |
| 1976 | class_destroy(android_class); |
| 1977 | return ret; |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | static int android_remove(struct platform_device *pdev) |
| 1981 | { |
Rajkumar Raghupathy | 5d3fc39 | 2012-04-11 16:53:19 +0530 | [diff] [blame] | 1982 | struct android_dev *dev = _android_dev; |
Ofir Cohen | 94213a7 | 2012-05-03 14:26:32 +0300 | [diff] [blame] | 1983 | struct android_usb_platform_data *pdata = pdev->dev.platform_data; |
Rajkumar Raghupathy | 5d3fc39 | 2012-04-11 16:53:19 +0530 | [diff] [blame] | 1984 | |
| 1985 | android_destroy_device(dev); |
| 1986 | class_destroy(android_class); |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1987 | usb_composite_unregister(&android_usb_driver); |
Manu Gautam | 94dc614 | 2012-05-08 14:35:24 +0530 | [diff] [blame] | 1988 | if (pdata && pdata->swfi_latency) |
Ofir Cohen | 94213a7 | 2012-05-03 14:26:32 +0300 | [diff] [blame] | 1989 | pm_qos_remove_request(&dev->pm_qos_req_dma); |
| 1990 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1991 | return 0; |
| 1992 | } |
| 1993 | |
| 1994 | static struct platform_driver android_platform_driver = { |
| 1995 | .driver = { .name = "android_usb"}, |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 1996 | .probe = android_probe, |
| 1997 | .remove = android_remove, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1998 | }; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 1999 | |
| 2000 | static int __init init(void) |
| 2001 | { |
| 2002 | struct android_dev *dev; |
Rajkumar Raghupathy | a1df77e | 2012-01-19 17:45:55 +0530 | [diff] [blame] | 2003 | int ret; |
Mike Lockwood | 7f0d7bd | 2008-12-02 22:01:33 -0500 | [diff] [blame] | 2004 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 2005 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
Rajkumar Raghupathy | a1df77e | 2012-01-19 17:45:55 +0530 | [diff] [blame] | 2006 | if (!dev) { |
| 2007 | pr_err("%s(): Failed to alloc memory for android_dev\n", |
| 2008 | __func__); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 2009 | return -ENOMEM; |
Rajkumar Raghupathy | a1df77e | 2012-01-19 17:45:55 +0530 | [diff] [blame] | 2010 | } |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 2011 | |
Benoit Goby | 80ba14d | 2012-03-19 18:56:52 -0700 | [diff] [blame] | 2012 | dev->disable_depth = 1; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 2013 | dev->functions = supported_functions; |
| 2014 | INIT_LIST_HEAD(&dev->enabled_functions); |
| 2015 | INIT_WORK(&dev->work, android_work); |
| 2016 | mutex_init(&dev->mutex); |
| 2017 | |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 2018 | _android_dev = dev; |
| 2019 | |
| 2020 | /* Override composite driver functions */ |
| 2021 | composite_driver.setup = android_setup; |
| 2022 | composite_driver.disconnect = android_disconnect; |
| 2023 | |
Pavankumar Kondeti | 044914d | 2012-01-31 12:56:13 +0530 | [diff] [blame] | 2024 | ret = platform_driver_register(&android_platform_driver); |
Rajkumar Raghupathy | a1df77e | 2012-01-19 17:45:55 +0530 | [diff] [blame] | 2025 | if (ret) { |
| 2026 | pr_err("%s(): Failed to register android" |
| 2027 | "platform driver\n", __func__); |
Rajkumar Raghupathy | 5d3fc39 | 2012-04-11 16:53:19 +0530 | [diff] [blame] | 2028 | kfree(dev); |
Rajkumar Raghupathy | a1df77e | 2012-01-19 17:45:55 +0530 | [diff] [blame] | 2029 | } |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 2030 | |
Rajkumar Raghupathy | a1df77e | 2012-01-19 17:45:55 +0530 | [diff] [blame] | 2031 | return ret; |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 2032 | } |
| 2033 | module_init(init); |
| 2034 | |
| 2035 | static void __exit cleanup(void) |
| 2036 | { |
Lena Salman | d092f2d | 2012-03-12 17:27:24 +0200 | [diff] [blame] | 2037 | platform_driver_unregister(&android_platform_driver); |
Benoit Goby | 1e8ce15 | 2011-12-12 13:01:23 -0800 | [diff] [blame] | 2038 | kfree(_android_dev); |
| 2039 | _android_dev = NULL; |
| 2040 | } |
| 2041 | module_exit(cleanup); |