diff options
author | Benoit Goby | 2012-11-05 20:47:08 -0600 |
---|---|---|
committer | Arve Hjønnevåg | 2013-02-22 17:27:52 -0600 |
commit | 2b9b0b6a95cb7adbdd4fa03bff2c7dec86852aa0 (patch) | |
tree | d34ca3151eb131f5698a5b46b6ac5fd61c4e8d10 | |
parent | 9b95e130377747fb2d2edd71e9f641696b73e23a (diff) | |
download | kernel-common-2b9b0b6a95cb7adbdd4fa03bff2c7dec86852aa0.tar.gz kernel-common-2b9b0b6a95cb7adbdd4fa03bff2c7dec86852aa0.tar.xz kernel-common-2b9b0b6a95cb7adbdd4fa03bff2c7dec86852aa0.zip |
usb: gadget: Fix android gadget driver build
Removed obsolete f_adb function
Change-Id: Idfb4110429bc0ea63f493c68ad667f49ca471987
Signed-off-by: Benoit Goby <benoit@android.com>
-rw-r--r-- | drivers/usb/gadget/Kconfig | 7 | ||||
-rw-r--r-- | drivers/usb/gadget/android.c | 165 | ||||
-rw-r--r-- | drivers/usb/gadget/f_adb.c | 619 | ||||
-rw-r--r-- | drivers/usb/gadget/u_serial.c | 3 |
4 files changed, 43 insertions, 751 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index f74fc7f418e..ad882dbe5e5 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -801,6 +801,7 @@ config USB_G_PRINTER | |||
801 | 801 | ||
802 | config USB_G_ANDROID | 802 | config USB_G_ANDROID |
803 | boolean "Android Composite Gadget" | 803 | boolean "Android Composite Gadget" |
804 | select USB_LIBCOMPOSITE | ||
804 | help | 805 | help |
805 | The Android Composite Gadget supports multiple USB | 806 | The Android Composite Gadget supports multiple USB |
806 | functions: adb, acm, mass storage, mtp, accessory | 807 | functions: adb, acm, mass storage, mtp, accessory |
@@ -808,6 +809,12 @@ config USB_G_ANDROID | |||
808 | Each function can be configured and enabled/disabled | 809 | Each function can be configured and enabled/disabled |
809 | dynamically from userspace through a sysfs interface. | 810 | dynamically from userspace through a sysfs interface. |
810 | 811 | ||
812 | config USB_ANDROID_RNDIS_DWORD_ALIGNED | ||
813 | boolean "Use double word aligned" | ||
814 | depends on USB_G_ANDROID | ||
815 | help | ||
816 | Provides dword aligned for DMA controller. | ||
817 | |||
811 | config USB_CDC_COMPOSITE | 818 | config USB_CDC_COMPOSITE |
812 | tristate "CDC Composite Device (Ethernet and ACM)" | 819 | tristate "CDC Composite Device (Ethernet and ACM)" |
813 | depends on NET | 820 | depends on NET |
diff --git a/drivers/usb/gadget/android.c b/drivers/usb/gadget/android.c index 23b5c46eadf..11d247cc0e9 100644 --- a/drivers/usb/gadget/android.c +++ b/drivers/usb/gadget/android.c | |||
@@ -30,24 +30,11 @@ | |||
30 | 30 | ||
31 | #include "gadget_chips.h" | 31 | #include "gadget_chips.h" |
32 | 32 | ||
33 | /* | ||
34 | * Kbuild is not very cooperative with respect to linking separately | ||
35 | * compiled library objects into one module. So for now we won't use | ||
36 | * separate compilation ... ensuring init/exit sections work to shrink | ||
37 | * the runtime footprint, and giving us at least some parts of what | ||
38 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
39 | */ | ||
40 | #include "usbstring.c" | ||
41 | #include "config.c" | ||
42 | #include "epautoconf.c" | ||
43 | #include "composite.c" | ||
44 | |||
45 | #include "f_fs.c" | 33 | #include "f_fs.c" |
46 | #include "f_audio_source.c" | 34 | #include "f_audio_source.c" |
47 | #include "f_mass_storage.c" | 35 | #include "f_mass_storage.c" |
48 | #include "u_serial.c" | 36 | #include "u_serial.c" |
49 | #include "f_acm.c" | 37 | #include "f_acm.c" |
50 | #include "f_adb.c" | ||
51 | #include "f_mtp.c" | 38 | #include "f_mtp.c" |
52 | #include "f_accessory.c" | 39 | #include "f_accessory.c" |
53 | #define USB_ETH_RNDIS y | 40 | #define USB_ETH_RNDIS y |
@@ -376,99 +363,6 @@ static void functionfs_release_dev_callback(struct ffs_data *ffs_data) | |||
376 | { | 363 | { |
377 | } | 364 | } |
378 | 365 | ||
379 | struct adb_data { | ||
380 | bool opened; | ||
381 | bool enabled; | ||
382 | }; | ||
383 | |||
384 | static int | ||
385 | adb_function_init(struct android_usb_function *f, | ||
386 | struct usb_composite_dev *cdev) | ||
387 | { | ||
388 | f->config = kzalloc(sizeof(struct adb_data), GFP_KERNEL); | ||
389 | if (!f->config) | ||
390 | return -ENOMEM; | ||
391 | |||
392 | return adb_setup(); | ||
393 | } | ||
394 | |||
395 | static void adb_function_cleanup(struct android_usb_function *f) | ||
396 | { | ||
397 | adb_cleanup(); | ||
398 | kfree(f->config); | ||
399 | } | ||
400 | |||
401 | static int | ||
402 | adb_function_bind_config(struct android_usb_function *f, | ||
403 | struct usb_configuration *c) | ||
404 | { | ||
405 | return adb_bind_config(c); | ||
406 | } | ||
407 | |||
408 | static void adb_android_function_enable(struct android_usb_function *f) | ||
409 | { | ||
410 | struct android_dev *dev = _android_dev; | ||
411 | struct adb_data *data = f->config; | ||
412 | |||
413 | data->enabled = true; | ||
414 | |||
415 | /* Disable the gadget until adbd is ready */ | ||
416 | if (!data->opened) | ||
417 | android_disable(dev); | ||
418 | } | ||
419 | |||
420 | static void adb_android_function_disable(struct android_usb_function *f) | ||
421 | { | ||
422 | struct android_dev *dev = _android_dev; | ||
423 | struct adb_data *data = f->config; | ||
424 | |||
425 | data->enabled = false; | ||
426 | |||
427 | /* Balance the disable that was called in closed_callback */ | ||
428 | if (!data->opened) | ||
429 | android_enable(dev); | ||
430 | } | ||
431 | |||
432 | static struct android_usb_function adb_function = { | ||
433 | .name = "adb", | ||
434 | .enable = adb_android_function_enable, | ||
435 | .disable = adb_android_function_disable, | ||
436 | .init = adb_function_init, | ||
437 | .cleanup = adb_function_cleanup, | ||
438 | .bind_config = adb_function_bind_config, | ||
439 | }; | ||
440 | |||
441 | static void adb_ready_callback(void) | ||
442 | { | ||
443 | struct android_dev *dev = _android_dev; | ||
444 | struct adb_data *data = adb_function.config; | ||
445 | |||
446 | mutex_lock(&dev->mutex); | ||
447 | |||
448 | data->opened = true; | ||
449 | |||
450 | if (data->enabled) | ||
451 | android_enable(dev); | ||
452 | |||
453 | mutex_unlock(&dev->mutex); | ||
454 | } | ||
455 | |||
456 | static void adb_closed_callback(void) | ||
457 | { | ||
458 | struct android_dev *dev = _android_dev; | ||
459 | struct adb_data *data = adb_function.config; | ||
460 | |||
461 | mutex_lock(&dev->mutex); | ||
462 | |||
463 | data->opened = false; | ||
464 | |||
465 | if (data->enabled) | ||
466 | android_disable(dev); | ||
467 | |||
468 | mutex_unlock(&dev->mutex); | ||
469 | } | ||
470 | |||
471 | |||
472 | #define MAX_ACM_INSTANCES 4 | 366 | #define MAX_ACM_INSTANCES 4 |
473 | struct acm_function_config { | 367 | struct acm_function_config { |
474 | int instances; | 368 | int instances; |
@@ -985,7 +879,6 @@ static struct android_usb_function audio_source_function = { | |||
985 | 879 | ||
986 | static struct android_usb_function *supported_functions[] = { | 880 | static struct android_usb_function *supported_functions[] = { |
987 | &ffs_function, | 881 | &ffs_function, |
988 | &adb_function, | ||
989 | &acm_function, | 882 | &acm_function, |
990 | &mtp_function, | 883 | &mtp_function, |
991 | &ptp_function, | 884 | &ptp_function, |
@@ -1417,13 +1310,8 @@ static int android_usb_unbind(struct usb_composite_dev *cdev) | |||
1417 | return 0; | 1310 | return 0; |
1418 | } | 1311 | } |
1419 | 1312 | ||
1420 | static struct usb_composite_driver android_usb_driver = { | 1313 | /* HACK: android needs to override setup for accessory to work */ |
1421 | .name = "android_usb", | 1314 | static int (*composite_setup)(struct usb_gadget *gadget, const struct usb_ctrlrequest *c); |
1422 | .dev = &device_desc, | ||
1423 | .strings = dev_strings, | ||
1424 | .unbind = android_usb_unbind, | ||
1425 | .max_speed = USB_SPEED_HIGH, | ||
1426 | }; | ||
1427 | 1315 | ||
1428 | static int | 1316 | static int |
1429 | android_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *c) | 1317 | android_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *c) |
@@ -1436,7 +1324,6 @@ android_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *c) | |||
1436 | unsigned long flags; | 1324 | unsigned long flags; |
1437 | 1325 | ||
1438 | req->zero = 0; | 1326 | req->zero = 0; |
1439 | req->complete = composite_setup_complete; | ||
1440 | req->length = 0; | 1327 | req->length = 0; |
1441 | gadget->ep0->driver_data = cdev; | 1328 | gadget->ep0->driver_data = cdev; |
1442 | 1329 | ||
@@ -1470,25 +1357,30 @@ android_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *c) | |||
1470 | return value; | 1357 | return value; |
1471 | } | 1358 | } |
1472 | 1359 | ||
1473 | static void android_disconnect(struct usb_gadget *gadget) | 1360 | static void android_disconnect(struct usb_composite_dev *cdev) |
1474 | { | 1361 | { |
1475 | struct android_dev *dev = _android_dev; | 1362 | struct android_dev *dev = _android_dev; |
1476 | struct usb_composite_dev *cdev = get_gadget_data(gadget); | ||
1477 | unsigned long flags; | ||
1478 | 1363 | ||
1479 | composite_disconnect(gadget); | ||
1480 | /* accessory HID support can be active while the | 1364 | /* accessory HID support can be active while the |
1481 | accessory function is not actually enabled, | 1365 | accessory function is not actually enabled, |
1482 | so we need to inform it when we are disconnected. | 1366 | so we need to inform it when we are disconnected. |
1483 | */ | 1367 | */ |
1484 | acc_disconnect(); | 1368 | acc_disconnect(); |
1485 | 1369 | ||
1486 | spin_lock_irqsave(&cdev->lock, flags); | ||
1487 | dev->connected = 0; | 1370 | dev->connected = 0; |
1488 | schedule_work(&dev->work); | 1371 | schedule_work(&dev->work); |
1489 | spin_unlock_irqrestore(&cdev->lock, flags); | ||
1490 | } | 1372 | } |
1491 | 1373 | ||
1374 | static struct usb_composite_driver android_usb_driver = { | ||
1375 | .name = "android_usb", | ||
1376 | .dev = &device_desc, | ||
1377 | .strings = dev_strings, | ||
1378 | .bind = android_bind, | ||
1379 | .unbind = android_usb_unbind, | ||
1380 | .disconnect = android_disconnect, | ||
1381 | .max_speed = USB_SPEED_HIGH, | ||
1382 | }; | ||
1383 | |||
1492 | static int android_create_device(struct android_dev *dev) | 1384 | static int android_create_device(struct android_dev *dev) |
1493 | { | 1385 | { |
1494 | struct device_attribute **attrs = android_usb_attributes; | 1386 | struct device_attribute **attrs = android_usb_attributes; |
@@ -1523,8 +1415,10 @@ static int __init init(void) | |||
1523 | return PTR_ERR(android_class); | 1415 | return PTR_ERR(android_class); |
1524 | 1416 | ||
1525 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | 1417 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
1526 | if (!dev) | 1418 | if (!dev) { |
1527 | return -ENOMEM; | 1419 | err = -ENOMEM; |
1420 | goto err_dev; | ||
1421 | } | ||
1528 | 1422 | ||
1529 | dev->disable_depth = 1; | 1423 | dev->disable_depth = 1; |
1530 | dev->functions = supported_functions; | 1424 | dev->functions = supported_functions; |
@@ -1534,18 +1428,29 @@ static int __init init(void) | |||
1534 | 1428 | ||
1535 | err = android_create_device(dev); | 1429 | err = android_create_device(dev); |
1536 | if (err) { | 1430 | if (err) { |
1537 | class_destroy(android_class); | 1431 | pr_err("%s: failed to create android device %d", __func__, err); |
1538 | kfree(dev); | 1432 | goto err_create; |
1539 | return err; | ||
1540 | } | 1433 | } |
1541 | 1434 | ||
1542 | _android_dev = dev; | 1435 | _android_dev = dev; |
1543 | 1436 | ||
1544 | /* Override composite driver functions */ | 1437 | err = usb_composite_probe(&android_usb_driver); |
1545 | composite_driver.setup = android_setup; | 1438 | if (err) { |
1546 | composite_driver.disconnect = android_disconnect; | 1439 | pr_err("%s: failed to probe driver %d", __func__, err); |
1440 | goto err_create; | ||
1441 | } | ||
1442 | |||
1443 | /* HACK: exchange composite's setup with ours */ | ||
1444 | composite_setup = android_usb_driver.gadget_driver.setup; | ||
1445 | android_usb_driver.gadget_driver.setup = android_setup; | ||
1547 | 1446 | ||
1548 | return usb_composite_probe(&android_usb_driver, android_bind); | 1447 | return 0; |
1448 | |||
1449 | err_create: | ||
1450 | kfree(dev); | ||
1451 | err_dev: | ||
1452 | class_destroy(android_class); | ||
1453 | return err; | ||
1549 | } | 1454 | } |
1550 | module_init(init); | 1455 | module_init(init); |
1551 | 1456 | ||
diff --git a/drivers/usb/gadget/f_adb.c b/drivers/usb/gadget/f_adb.c deleted file mode 100644 index a1d70d27695..00000000000 --- a/drivers/usb/gadget/f_adb.c +++ /dev/null | |||
@@ -1,619 +0,0 @@ | |||
1 | /* | ||
2 | * Gadget Driver for Android ADB | ||
3 | * | ||
4 | * Copyright (C) 2008 Google, Inc. | ||
5 | * Author: Mike Lockwood <lockwood@android.com> | ||
6 | * | ||
7 | * This software is licensed under the terms of the GNU General Public | ||
8 | * License version 2, as published by the Free Software Foundation, and | ||
9 | * may be copied, distributed, and modified under those terms. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | */ | ||
17 | |||
18 | #include <linux/module.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/poll.h> | ||
21 | #include <linux/delay.h> | ||
22 | #include <linux/wait.h> | ||
23 | #include <linux/err.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/sched.h> | ||
26 | #include <linux/types.h> | ||
27 | #include <linux/device.h> | ||
28 | #include <linux/miscdevice.h> | ||
29 | |||
30 | #define ADB_BULK_BUFFER_SIZE 4096 | ||
31 | |||
32 | /* number of tx requests to allocate */ | ||
33 | #define TX_REQ_MAX 4 | ||
34 | |||
35 | static const char adb_shortname[] = "android_adb"; | ||
36 | |||
37 | struct adb_dev { | ||
38 | struct usb_function function; | ||
39 | struct usb_composite_dev *cdev; | ||
40 | spinlock_t lock; | ||
41 | |||
42 | struct usb_ep *ep_in; | ||
43 | struct usb_ep *ep_out; | ||
44 | |||
45 | int online; | ||
46 | int error; | ||
47 | |||
48 | atomic_t read_excl; | ||
49 | atomic_t write_excl; | ||
50 | atomic_t open_excl; | ||
51 | |||
52 | struct list_head tx_idle; | ||
53 | |||
54 | wait_queue_head_t read_wq; | ||
55 | wait_queue_head_t write_wq; | ||
56 | struct usb_request *rx_req; | ||
57 | int rx_done; | ||
58 | }; | ||
59 | |||
60 | static struct usb_interface_descriptor adb_interface_desc = { | ||
61 | .bLength = USB_DT_INTERFACE_SIZE, | ||
62 | .bDescriptorType = USB_DT_INTERFACE, | ||
63 | .bInterfaceNumber = 0, | ||
64 | .bNumEndpoints = 2, | ||
65 | .bInterfaceClass = 0xFF, | ||
66 | .bInterfaceSubClass = 0x42, | ||
67 | .bInterfaceProtocol = 1, | ||
68 | }; | ||
69 | |||
70 | static struct usb_endpoint_descriptor adb_highspeed_in_desc = { | ||
71 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
72 | .bDescriptorType = USB_DT_ENDPOINT, | ||
73 | .bEndpointAddress = USB_DIR_IN, | ||
74 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
75 | .wMaxPacketSize = __constant_cpu_to_le16(512), | ||
76 | }; | ||
77 | |||
78 | static struct usb_endpoint_descriptor adb_highspeed_out_desc = { | ||
79 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
80 | .bDescriptorType = USB_DT_ENDPOINT, | ||
81 | .bEndpointAddress = USB_DIR_OUT, | ||
82 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
83 | .wMaxPacketSize = __constant_cpu_to_le16(512), | ||
84 | }; | ||
85 | |||
86 | static struct usb_endpoint_descriptor adb_fullspeed_in_desc = { | ||
87 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
88 | .bDescriptorType = USB_DT_ENDPOINT, | ||
89 | .bEndpointAddress = USB_DIR_IN, | ||
90 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
91 | }; | ||
92 | |||
93 | static struct usb_endpoint_descriptor adb_fullspeed_out_desc = { | ||
94 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
95 | .bDescriptorType = USB_DT_ENDPOINT, | ||
96 | .bEndpointAddress = USB_DIR_OUT, | ||
97 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
98 | }; | ||
99 | |||
100 | static struct usb_descriptor_header *fs_adb_descs[] = { | ||
101 | (struct usb_descriptor_header *) &adb_interface_desc, | ||
102 | (struct usb_descriptor_header *) &adb_fullspeed_in_desc, | ||
103 | (struct usb_descriptor_header *) &adb_fullspeed_out_desc, | ||
104 | NULL, | ||
105 | }; | ||
106 | |||
107 | static struct usb_descriptor_header *hs_adb_descs[] = { | ||
108 | (struct usb_descriptor_header *) &adb_interface_desc, | ||
109 | (struct usb_descriptor_header *) &adb_highspeed_in_desc, | ||
110 | (struct usb_descriptor_header *) &adb_highspeed_out_desc, | ||
111 | NULL, | ||
112 | }; | ||
113 | |||
114 | static void adb_ready_callback(void); | ||
115 | static void adb_closed_callback(void); | ||
116 | |||
117 | /* temporary variable used between adb_open() and adb_gadget_bind() */ | ||
118 | static struct adb_dev *_adb_dev; | ||
119 | |||
120 | static inline struct adb_dev *func_to_adb(struct usb_function *f) | ||
121 | { | ||
122 | return container_of(f, struct adb_dev, function); | ||
123 | } | ||
124 | |||
125 | |||
126 | static struct usb_request *adb_request_new(struct usb_ep *ep, int buffer_size) | ||
127 | { | ||
128 | struct usb_request *req = usb_ep_alloc_request(ep, GFP_KERNEL); | ||
129 | if (!req) | ||
130 | return NULL; | ||
131 | |||
132 | /* now allocate buffers for the requests */ | ||
133 | req->buf = kmalloc(buffer_size, GFP_KERNEL); | ||
134 | if (!req->buf) { | ||
135 | usb_ep_free_request(ep, req); | ||
136 | return NULL; | ||
137 | } | ||
138 | |||
139 | return req; | ||
140 | } | ||
141 | |||
142 | static void adb_request_free(struct usb_request *req, struct usb_ep *ep) | ||
143 | { | ||
144 | if (req) { | ||
145 | kfree(req->buf); | ||
146 | usb_ep_free_request(ep, req); | ||
147 | } | ||
148 | } | ||
149 | |||
150 | static inline int adb_lock(atomic_t *excl) | ||
151 | { | ||
152 | if (atomic_inc_return(excl) == 1) { | ||
153 | return 0; | ||
154 | } else { | ||
155 | atomic_dec(excl); | ||
156 | return -1; | ||
157 | } | ||
158 | } | ||
159 | |||
160 | static inline void adb_unlock(atomic_t *excl) | ||
161 | { | ||
162 | atomic_dec(excl); | ||
163 | } | ||
164 | |||
165 | /* add a request to the tail of a list */ | ||
166 | void adb_req_put(struct adb_dev *dev, struct list_head *head, | ||
167 | struct usb_request *req) | ||
168 | { | ||
169 | unsigned long flags; | ||
170 | |||
171 | spin_lock_irqsave(&dev->lock, flags); | ||
172 | list_add_tail(&req->list, head); | ||
173 | spin_unlock_irqrestore(&dev->lock, flags); | ||
174 | } | ||
175 | |||
176 | /* remove a request from the head of a list */ | ||
177 | struct usb_request *adb_req_get(struct adb_dev *dev, struct list_head *head) | ||
178 | { | ||
179 | unsigned long flags; | ||
180 | struct usb_request *req; | ||
181 | |||
182 | spin_lock_irqsave(&dev->lock, flags); | ||
183 | if (list_empty(head)) { | ||
184 | req = 0; | ||
185 | } else { | ||
186 | req = list_first_entry(head, struct usb_request, list); | ||
187 | list_del(&req->list); | ||
188 | } | ||
189 | spin_unlock_irqrestore(&dev->lock, flags); | ||
190 | return req; | ||
191 | } | ||
192 | |||
193 | static void adb_complete_in(struct usb_ep *ep, struct usb_request *req) | ||
194 | { | ||
195 | struct adb_dev *dev = _adb_dev; | ||
196 | |||
197 | if (req->status != 0) | ||
198 | dev->error = 1; | ||
199 | |||
200 | adb_req_put(dev, &dev->tx_idle, req); | ||
201 | |||
202 | wake_up(&dev->write_wq); | ||
203 | } | ||
204 | |||
205 | static void adb_complete_out(struct usb_ep *ep, struct usb_request *req) | ||
206 | { | ||
207 | struct adb_dev *dev = _adb_dev; | ||
208 | |||
209 | dev->rx_done = 1; | ||
210 | if (req->status != 0 && req->status != -ECONNRESET) | ||
211 | dev->error = 1; | ||
212 | |||
213 | wake_up(&dev->read_wq); | ||
214 | } | ||
215 | |||
216 | static int adb_create_bulk_endpoints(struct adb_dev *dev, | ||
217 | struct usb_endpoint_descriptor *in_desc, | ||
218 | struct usb_endpoint_descriptor *out_desc) | ||
219 | { | ||
220 | struct usb_composite_dev *cdev = dev->cdev; | ||
221 | struct usb_request *req; | ||
222 | struct usb_ep *ep; | ||
223 | int i; | ||
224 | |||
225 | DBG(cdev, "create_bulk_endpoints dev: %p\n", dev); | ||
226 | |||
227 | ep = usb_ep_autoconfig(cdev->gadget, in_desc); | ||
228 | if (!ep) { | ||
229 | DBG(cdev, "usb_ep_autoconfig for ep_in failed\n"); | ||
230 | return -ENODEV; | ||
231 | } | ||
232 | DBG(cdev, "usb_ep_autoconfig for ep_in got %s\n", ep->name); | ||
233 | ep->driver_data = dev; /* claim the endpoint */ | ||
234 | dev->ep_in = ep; | ||
235 | |||
236 | ep = usb_ep_autoconfig(cdev->gadget, out_desc); | ||
237 | if (!ep) { | ||
238 | DBG(cdev, "usb_ep_autoconfig for ep_out failed\n"); | ||
239 | return -ENODEV; | ||
240 | } | ||
241 | DBG(cdev, "usb_ep_autoconfig for adb ep_out got %s\n", ep->name); | ||
242 | ep->driver_data = dev; /* claim the endpoint */ | ||
243 | dev->ep_out = ep; | ||
244 | |||
245 | /* now allocate requests for our endpoints */ | ||
246 | req = adb_request_new(dev->ep_out, ADB_BULK_BUFFER_SIZE); | ||
247 | if (!req) | ||
248 | goto fail; | ||
249 | req->complete = adb_complete_out; | ||
250 | dev->rx_req = req; | ||
251 | |||
252 | for (i = 0; i < TX_REQ_MAX; i++) { | ||
253 | req = adb_request_new(dev->ep_in, ADB_BULK_BUFFER_SIZE); | ||
254 | if (!req) | ||
255 | goto fail; | ||
256 | req->complete = adb_complete_in; | ||
257 | adb_req_put(dev, &dev->tx_idle, req); | ||
258 | } | ||
259 | |||
260 | return 0; | ||
261 | |||
262 | fail: | ||
263 | printk(KERN_ERR "adb_bind() could not allocate requests\n"); | ||
264 | return -1; | ||
265 | } | ||
266 | |||
267 | static ssize_t adb_read(struct file *fp, char __user *buf, | ||
268 | size_t count, loff_t *pos) | ||
269 | { | ||
270 | struct adb_dev *dev = fp->private_data; | ||
271 | struct usb_request *req; | ||
272 | int r = count, xfer; | ||
273 | int ret; | ||
274 | |||
275 | pr_debug("adb_read(%d)\n", count); | ||
276 | if (!_adb_dev) | ||
277 | return -ENODEV; | ||
278 | |||
279 | if (count > ADB_BULK_BUFFER_SIZE) | ||
280 | return -EINVAL; | ||
281 | |||
282 | if (adb_lock(&dev->read_excl)) | ||
283 | return -EBUSY; | ||
284 | |||
285 | /* we will block until we're online */ | ||
286 | while (!(dev->online || dev->error)) { | ||
287 | pr_debug("adb_read: waiting for online state\n"); | ||
288 | ret = wait_event_interruptible(dev->read_wq, | ||
289 | (dev->online || dev->error)); | ||
290 | if (ret < 0) { | ||
291 | adb_unlock(&dev->read_excl); | ||
292 | return ret; | ||
293 | } | ||
294 | } | ||
295 | if (dev->error) { | ||
296 | r = -EIO; | ||
297 | goto done; | ||
298 | } | ||
299 | |||
300 | requeue_req: | ||
301 | /* queue a request */ | ||
302 | req = dev->rx_req; | ||
303 | req->length = count; | ||
304 | dev->rx_done = 0; | ||
305 | ret = usb_ep_queue(dev->ep_out, req, GFP_ATOMIC); | ||
306 | if (ret < 0) { | ||
307 | pr_debug("adb_read: failed to queue req %p (%d)\n", req, ret); | ||
308 | r = -EIO; | ||
309 | dev->error = 1; | ||
310 | goto done; | ||
311 | } else { | ||
312 | pr_debug("rx %p queue\n", req); | ||
313 | } | ||
314 | |||
315 | /* wait for a request to complete */ | ||
316 | ret = wait_event_interruptible(dev->read_wq, dev->rx_done); | ||
317 | if (ret < 0) { | ||
318 | if (ret != -ERESTARTSYS) | ||
319 | dev->error = 1; | ||
320 | r = ret; | ||
321 | usb_ep_dequeue(dev->ep_out, req); | ||
322 | goto done; | ||
323 | } | ||
324 | if (!dev->error) { | ||
325 | /* If we got a 0-len packet, throw it back and try again. */ | ||
326 | if (req->actual == 0) | ||
327 | goto requeue_req; | ||
328 | |||
329 | pr_debug("rx %p %d\n", req, req->actual); | ||
330 | xfer = (req->actual < count) ? req->actual : count; | ||
331 | if (copy_to_user(buf, req->buf, xfer)) | ||
332 | r = -EFAULT; | ||
333 | |||
334 | } else | ||
335 | r = -EIO; | ||
336 | |||
337 | done: | ||
338 | adb_unlock(&dev->read_excl); | ||
339 | pr_debug("adb_read returning %d\n", r); | ||
340 | return r; | ||
341 | } | ||
342 | |||
343 | static ssize_t adb_write(struct file *fp, const char __user *buf, | ||
344 | size_t count, loff_t *pos) | ||
345 | { | ||
346 | struct adb_dev *dev = fp->private_data; | ||
347 | struct usb_request *req = 0; | ||
348 | int r = count, xfer; | ||
349 | int ret; | ||
350 | |||
351 | if (!_adb_dev) | ||
352 | return -ENODEV; | ||
353 | pr_debug("adb_write(%d)\n", count); | ||
354 | |||
355 | if (adb_lock(&dev->write_excl)) | ||
356 | return -EBUSY; | ||
357 | |||
358 | while (count > 0) { | ||
359 | if (dev->error) { | ||
360 | pr_debug("adb_write dev->error\n"); | ||
361 | r = -EIO; | ||
362 | break; | ||
363 | } | ||
364 | |||
365 | /* get an idle tx request to use */ | ||
366 | req = 0; | ||
367 | ret = wait_event_interruptible(dev->write_wq, | ||
368 | (req = adb_req_get(dev, &dev->tx_idle)) || dev->error); | ||
369 | |||
370 | if (ret < 0) { | ||
371 | r = ret; | ||
372 | break; | ||
373 | } | ||
374 | |||
375 | if (req != 0) { | ||
376 | if (count > ADB_BULK_BUFFER_SIZE) | ||
377 | xfer = ADB_BULK_BUFFER_SIZE; | ||
378 | else | ||
379 | xfer = count; | ||
380 | if (copy_from_user(req->buf, buf, xfer)) { | ||
381 | r = -EFAULT; | ||
382 | break; | ||
383 | } | ||
384 | |||
385 | req->length = xfer; | ||
386 | ret = usb_ep_queue(dev->ep_in, req, GFP_ATOMIC); | ||
387 | if (ret < 0) { | ||
388 | pr_debug("adb_write: xfer error %d\n", ret); | ||
389 | dev->error = 1; | ||
390 | r = -EIO; | ||
391 | break; | ||
392 | } | ||
393 | |||
394 | buf += xfer; | ||
395 | count -= xfer; | ||
396 | |||
397 | /* zero this so we don't try to free it on error exit */ | ||
398 | req = 0; | ||
399 | } | ||
400 | } | ||
401 | |||
402 | if (req) | ||
403 | adb_req_put(dev, &dev->tx_idle, req); | ||
404 | |||
405 | adb_unlock(&dev->write_excl); | ||
406 | pr_debug("adb_write returning %d\n", r); | ||
407 | return r; | ||
408 | } | ||
409 | |||
410 | static int adb_open(struct inode *ip, struct file *fp) | ||
411 | { | ||
412 | pr_info("adb_open\n"); | ||
413 | if (!_adb_dev) | ||
414 | return -ENODEV; | ||
415 | |||
416 | if (adb_lock(&_adb_dev->open_excl)) | ||
417 | return -EBUSY; | ||
418 | |||
419 | fp->private_data = _adb_dev; | ||
420 | |||
421 | /* clear the error latch */ | ||
422 | _adb_dev->error = 0; | ||
423 | |||
424 | adb_ready_callback(); | ||
425 | |||
426 | return 0; | ||
427 | } | ||
428 | |||
429 | static int adb_release(struct inode *ip, struct file *fp) | ||
430 | { | ||
431 | pr_info("adb_release\n"); | ||
432 | |||
433 | adb_closed_callback(); | ||
434 | |||
435 | adb_unlock(&_adb_dev->open_excl); | ||
436 | return 0; | ||
437 | } | ||
438 | |||
439 | /* file operations for ADB device /dev/android_adb */ | ||
440 | static const struct file_operations adb_fops = { | ||
441 | .owner = THIS_MODULE, | ||
442 | .read = adb_read, | ||
443 | .write = adb_write, | ||
444 | .open = adb_open, | ||
445 | .release = adb_release, | ||
446 | }; | ||
447 | |||
448 | static struct miscdevice adb_device = { | ||
449 | .minor = MISC_DYNAMIC_MINOR, | ||
450 | .name = adb_shortname, | ||
451 | .fops = &adb_fops, | ||
452 | }; | ||
453 | |||
454 | |||
455 | |||
456 | |||
457 | static int | ||
458 | adb_function_bind(struct usb_configuration *c, struct usb_function *f) | ||
459 | { | ||
460 | struct usb_composite_dev *cdev = c->cdev; | ||
461 | struct adb_dev *dev = func_to_adb(f); | ||
462 | int id; | ||
463 | int ret; | ||
464 | |||
465 | dev->cdev = cdev; | ||
466 | DBG(cdev, "adb_function_bind dev: %p\n", dev); | ||
467 | |||
468 | /* allocate interface ID(s) */ | ||
469 | id = usb_interface_id(c, f); | ||
470 | if (id < 0) | ||
471 | return id; | ||
472 | adb_interface_desc.bInterfaceNumber = id; | ||
473 | |||
474 | /* allocate endpoints */ | ||
475 | ret = adb_create_bulk_endpoints(dev, &adb_fullspeed_in_desc, | ||
476 | &adb_fullspeed_out_desc); | ||
477 | if (ret) | ||
478 | return ret; | ||
479 | |||
480 | /* support high speed hardware */ | ||
481 | if (gadget_is_dualspeed(c->cdev->gadget)) { | ||
482 | adb_highspeed_in_desc.bEndpointAddress = | ||
483 | adb_fullspeed_in_desc.bEndpointAddress; | ||
484 | adb_highspeed_out_desc.bEndpointAddress = | ||
485 | adb_fullspeed_out_desc.bEndpointAddress; | ||
486 | } | ||
487 | |||
488 | DBG(cdev, "%s speed %s: IN/%s, OUT/%s\n", | ||
489 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", | ||
490 | f->name, dev->ep_in->name, dev->ep_out->name); | ||
491 | return 0; | ||
492 | } | ||
493 | |||
494 | static void | ||
495 | adb_function_unbind(struct usb_configuration *c, struct usb_function *f) | ||
496 | { | ||
497 | struct adb_dev *dev = func_to_adb(f); | ||
498 | struct usb_request *req; | ||
499 | |||
500 | |||
501 | dev->online = 0; | ||
502 | dev->error = 1; | ||
503 | |||
504 | wake_up(&dev->read_wq); | ||
505 | |||
506 | adb_request_free(dev->rx_req, dev->ep_out); | ||
507 | while ((req = adb_req_get(dev, &dev->tx_idle))) | ||
508 | adb_request_free(req, dev->ep_in); | ||
509 | } | ||
510 | |||
511 | static int adb_function_set_alt(struct usb_function *f, | ||
512 | unsigned intf, unsigned alt) | ||
513 | { | ||
514 | struct adb_dev *dev = func_to_adb(f); | ||
515 | struct usb_composite_dev *cdev = f->config->cdev; | ||
516 | int ret; | ||
517 | |||
518 | DBG(cdev, "adb_function_set_alt intf: %d alt: %d\n", intf, alt); | ||
519 | |||
520 | ret = config_ep_by_speed(cdev->gadget, f, dev->ep_in); | ||
521 | if (ret) | ||
522 | return ret; | ||
523 | |||
524 | ret = usb_ep_enable(dev->ep_in); | ||
525 | if (ret) | ||
526 | return ret; | ||
527 | |||
528 | ret = config_ep_by_speed(cdev->gadget, f, dev->ep_out); | ||
529 | if (ret) | ||
530 | return ret; | ||
531 | |||
532 | ret = usb_ep_enable(dev->ep_out); | ||
533 | if (ret) { | ||
534 | usb_ep_disable(dev->ep_in); | ||
535 | return ret; | ||
536 | } | ||
537 | dev->online = 1; | ||
538 | |||
539 | /* readers may be blocked waiting for us to go online */ | ||
540 | wake_up(&dev->read_wq); | ||
541 | return 0; | ||
542 | } | ||
543 | |||
544 | static void adb_function_disable(struct usb_function *f) | ||
545 | { | ||
546 | struct adb_dev *dev = func_to_adb(f); | ||
547 | struct usb_composite_dev *cdev = dev->cdev; | ||
548 | |||
549 | DBG(cdev, "adb_function_disable cdev %p\n", cdev); | ||
550 | dev->online = 0; | ||
551 | dev->error = 1; | ||
552 | usb_ep_disable(dev->ep_in); | ||
553 | usb_ep_disable(dev->ep_out); | ||
554 | |||
555 | /* readers may be blocked waiting for us to go online */ | ||
556 | wake_up(&dev->read_wq); | ||
557 | |||
558 | VDBG(cdev, "%s disabled\n", dev->function.name); | ||
559 | } | ||
560 | |||
561 | static int adb_bind_config(struct usb_configuration *c) | ||
562 | { | ||
563 | struct adb_dev *dev = _adb_dev; | ||
564 | |||
565 | printk(KERN_INFO "adb_bind_config\n"); | ||
566 | |||
567 | dev->cdev = c->cdev; | ||
568 | dev->function.name = "adb"; | ||
569 | dev->function.fs_descriptors = fs_adb_descs; | ||
570 | dev->function.hs_descriptors = hs_adb_descs; | ||
571 | dev->function.bind = adb_function_bind; | ||
572 | dev->function.unbind = adb_function_unbind; | ||
573 | dev->function.set_alt = adb_function_set_alt; | ||
574 | dev->function.disable = adb_function_disable; | ||
575 | |||
576 | return usb_add_function(c, &dev->function); | ||
577 | } | ||
578 | |||
579 | static int adb_setup(void) | ||
580 | { | ||
581 | struct adb_dev *dev; | ||
582 | int ret; | ||
583 | |||
584 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
585 | if (!dev) | ||
586 | return -ENOMEM; | ||
587 | |||
588 | spin_lock_init(&dev->lock); | ||
589 | |||
590 | init_waitqueue_head(&dev->read_wq); | ||
591 | init_waitqueue_head(&dev->write_wq); | ||
592 | |||
593 | atomic_set(&dev->open_excl, 0); | ||
594 | atomic_set(&dev->read_excl, 0); | ||
595 | atomic_set(&dev->write_excl, 0); | ||
596 | |||
597 | INIT_LIST_HEAD(&dev->tx_idle); | ||
598 | |||
599 | _adb_dev = dev; | ||
600 | |||
601 | ret = misc_register(&adb_device); | ||
602 | if (ret) | ||
603 | goto err; | ||
604 | |||
605 | return 0; | ||
606 | |||
607 | err: | ||
608 | kfree(dev); | ||
609 | printk(KERN_ERR "adb gadget driver failed to initialize\n"); | ||
610 | return ret; | ||
611 | } | ||
612 | |||
613 | static void adb_cleanup(void) | ||
614 | { | ||
615 | misc_deregister(&adb_device); | ||
616 | |||
617 | kfree(_adb_dev); | ||
618 | _adb_dev = NULL; | ||
619 | } | ||
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c index 598dcc1212f..83e44fec333 100644 --- a/drivers/usb/gadget/u_serial.c +++ b/drivers/usb/gadget/u_serial.c | |||
@@ -1133,8 +1133,7 @@ int gserial_setup(struct usb_gadget *g, unsigned count) | |||
1133 | for (i = 0; i < count; i++) { | 1133 | for (i = 0; i < count; i++) { |
1134 | struct device *tty_dev; | 1134 | struct device *tty_dev; |
1135 | 1135 | ||
1136 | tty_dev = tty_port_register_device(&ports[i].port->port, | 1136 | tty_dev = tty_register_device(gs_tty_driver, i, &g->dev); |
1137 | gs_tty_driver, i, &g->dev); | ||
1138 | if (IS_ERR(tty_dev)) | 1137 | if (IS_ERR(tty_dev)) |
1139 | pr_warning("%s: no classdev for port %d, err %ld\n", | 1138 | pr_warning("%s: no classdev for port %d, err %ld\n", |
1140 | __func__, i, PTR_ERR(tty_dev)); | 1139 | __func__, i, PTR_ERR(tty_dev)); |