diff options
Diffstat (limited to 'drivers/usb/gadget')
83 files changed, 2980 insertions, 2749 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 5a084b9cfa3c..b21cd376c11a 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -96,6 +96,22 @@ config USB_GADGET_VBUS_DRAW | |||
96 | This value will be used except for system-specific gadget | 96 | This value will be used except for system-specific gadget |
97 | drivers that have more specific information. | 97 | drivers that have more specific information. |
98 | 98 | ||
99 | config USB_GADGET_STORAGE_NUM_BUFFERS | ||
100 | int "Number of storage pipeline buffers" | ||
101 | range 2 4 | ||
102 | default 2 | ||
103 | help | ||
104 | Usually 2 buffers are enough to establish a good buffering | ||
105 | pipeline. The number may be increased in order to compensate | ||
106 | for a bursty VFS behaviour. For instance there may be CPU wake up | ||
107 | latencies that makes the VFS to appear bursty in a system with | ||
108 | an CPU on-demand governor. Especially if DMA is doing IO to | ||
109 | offload the CPU. In this case the CPU will go into power | ||
110 | save often and spin up occasionally to move data within VFS. | ||
111 | If selecting USB_GADGET_DEBUG_FILES this value may be set by | ||
112 | a module parameter as well. | ||
113 | If unsure, say 2. | ||
114 | |||
99 | # | 115 | # |
100 | # USB Peripheral Controller Support | 116 | # USB Peripheral Controller Support |
101 | # | 117 | # |
@@ -255,12 +271,11 @@ config USB_S3C_HSOTG | |||
255 | integrated into the S3C64XX series SoC. | 271 | integrated into the S3C64XX series SoC. |
256 | 272 | ||
257 | config USB_IMX | 273 | config USB_IMX |
258 | tristate "Freescale IMX USB Peripheral Controller" | 274 | tristate "Freescale i.MX1 USB Peripheral Controller" |
259 | depends on ARCH_MX1 | 275 | depends on ARCH_MXC |
260 | help | 276 | help |
261 | Freescale's IMX series include an integrated full speed | 277 | Freescale's i.MX1 includes an integrated full speed |
262 | USB 1.1 device controller. The controller in the IMX series | 278 | USB 1.1 device controller. |
263 | is register-compatible. | ||
264 | 279 | ||
265 | It has Six fixed-function endpoints, as well as endpoint | 280 | It has Six fixed-function endpoints, as well as endpoint |
266 | zero (for control transfers). | 281 | zero (for control transfers). |
@@ -303,6 +318,18 @@ config USB_PXA_U2O | |||
303 | PXA9xx Processor series include a high speed USB2.0 device | 318 | PXA9xx Processor series include a high speed USB2.0 device |
304 | controller, which support high speed and full speed USB peripheral. | 319 | controller, which support high speed and full speed USB peripheral. |
305 | 320 | ||
321 | config USB_GADGET_DWC3 | ||
322 | tristate "DesignWare USB3.0 (DRD) Controller" | ||
323 | depends on USB_DWC3 | ||
324 | select USB_GADGET_DUALSPEED | ||
325 | select USB_GADGET_SUPERSPEED | ||
326 | help | ||
327 | DesignWare USB3.0 controller is a SuperSpeed USB3.0 Controller | ||
328 | which can be configured for peripheral-only, host-only, hub-only | ||
329 | and Dual-Role operation. This Controller was first integrated into | ||
330 | the OMAP5 series of processors. More information about the OMAP5 | ||
331 | version of this controller, refer to http://www.ti.com/omap5. | ||
332 | |||
306 | # | 333 | # |
307 | # Controllers available in both integrated and discrete versions | 334 | # Controllers available in both integrated and discrete versions |
308 | # | 335 | # |
@@ -846,6 +873,16 @@ config USB_G_NOKIA | |||
846 | It's only really useful for N900 hardware. If you're building | 873 | It's only really useful for N900 hardware. If you're building |
847 | a kernel for N900, say Y or M here. If unsure, say N. | 874 | a kernel for N900, say Y or M here. If unsure, say N. |
848 | 875 | ||
876 | config USB_G_ACM_MS | ||
877 | tristate "CDC Composite Device (ACM and mass storage)" | ||
878 | depends on BLOCK | ||
879 | help | ||
880 | This driver provides two functions in one configuration: | ||
881 | a mass storage, and a CDC ACM (serial port) link. | ||
882 | |||
883 | Say "y" to link the driver statically, or "m" to build a | ||
884 | dynamically linked module called "g_acm_ms". | ||
885 | |||
849 | config USB_G_MULTI | 886 | config USB_G_MULTI |
850 | tristate "Multifunction Composite Gadget (EXPERIMENTAL)" | 887 | tristate "Multifunction Composite Gadget (EXPERIMENTAL)" |
851 | depends on BLOCK && NET | 888 | depends on BLOCK && NET |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 9ba725af4a08..b54ac6190890 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -28,7 +28,7 @@ obj-$(CONFIG_USB_S3C_HSUDC) += s3c-hsudc.o | |||
28 | obj-$(CONFIG_USB_LANGWELL) += langwell_udc.o | 28 | obj-$(CONFIG_USB_LANGWELL) += langwell_udc.o |
29 | obj-$(CONFIG_USB_EG20T) += pch_udc.o | 29 | obj-$(CONFIG_USB_EG20T) += pch_udc.o |
30 | obj-$(CONFIG_USB_PXA_U2O) += mv_udc.o | 30 | obj-$(CONFIG_USB_PXA_U2O) += mv_udc.o |
31 | mv_udc-y := mv_udc_core.o mv_udc_phy.o | 31 | mv_udc-y := mv_udc_core.o |
32 | obj-$(CONFIG_USB_CI13XXX_MSM) += ci13xxx_msm.o | 32 | obj-$(CONFIG_USB_CI13XXX_MSM) += ci13xxx_msm.o |
33 | obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o | 33 | obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o |
34 | 34 | ||
@@ -51,6 +51,7 @@ g_dbgp-y := dbgp.o | |||
51 | g_nokia-y := nokia.o | 51 | g_nokia-y := nokia.o |
52 | g_webcam-y := webcam.o | 52 | g_webcam-y := webcam.o |
53 | g_ncm-y := ncm.o | 53 | g_ncm-y := ncm.o |
54 | g_acm_ms-y := acm_ms.o | ||
54 | 55 | ||
55 | obj-$(CONFIG_USB_ZERO) += g_zero.o | 56 | obj-$(CONFIG_USB_ZERO) += g_zero.o |
56 | obj-$(CONFIG_USB_AUDIO) += g_audio.o | 57 | obj-$(CONFIG_USB_AUDIO) += g_audio.o |
@@ -69,3 +70,4 @@ obj-$(CONFIG_USB_G_MULTI) += g_multi.o | |||
69 | obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o | 70 | obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o |
70 | obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o | 71 | obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o |
71 | obj-$(CONFIG_USB_G_NCM) += g_ncm.o | 72 | obj-$(CONFIG_USB_G_NCM) += g_ncm.o |
73 | obj-$(CONFIG_USB_G_ACM_MS) += g_acm_ms.o | ||
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c new file mode 100644 index 000000000000..fdb7aec3bd0c --- /dev/null +++ b/drivers/usb/gadget/acm_ms.c | |||
@@ -0,0 +1,256 @@ | |||
1 | /* | ||
2 | * acm_ms.c -- Composite driver, with ACM and mass storage support | ||
3 | * | ||
4 | * Copyright (C) 2008 David Brownell | ||
5 | * Copyright (C) 2008 Nokia Corporation | ||
6 | * Author: David Brownell | ||
7 | * Modified: Klaus Schwarzkopf <schwarzkopf@sensortherm.de> | ||
8 | * | ||
9 | * Heavily based on multi.c and cdc2.c | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License as published by | ||
13 | * the Free Software Foundation; either version 2 of the License, or | ||
14 | * (at your option) any later version. | ||
15 | */ | ||
16 | |||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/utsname.h> | ||
19 | |||
20 | #include "u_serial.h" | ||
21 | |||
22 | #define DRIVER_DESC "Composite Gadget (ACM + MS)" | ||
23 | #define DRIVER_VERSION "2011/10/10" | ||
24 | |||
25 | /*-------------------------------------------------------------------------*/ | ||
26 | |||
27 | /* | ||
28 | * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! | ||
29 | * Instead: allocate your own, using normal USB-IF procedures. | ||
30 | */ | ||
31 | #define ACM_MS_VENDOR_NUM 0x1d6b /* Linux Foundation */ | ||
32 | #define ACM_MS_PRODUCT_NUM 0x0106 /* Composite Gadget: ACM + MS*/ | ||
33 | |||
34 | /*-------------------------------------------------------------------------*/ | ||
35 | |||
36 | /* | ||
37 | * Kbuild is not very cooperative with respect to linking separately | ||
38 | * compiled library objects into one module. So for now we won't use | ||
39 | * separate compilation ... ensuring init/exit sections work to shrink | ||
40 | * the runtime footprint, and giving us at least some parts of what | ||
41 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
42 | */ | ||
43 | |||
44 | #include "composite.c" | ||
45 | #include "usbstring.c" | ||
46 | #include "config.c" | ||
47 | #include "epautoconf.c" | ||
48 | #include "u_serial.c" | ||
49 | #include "f_acm.c" | ||
50 | #include "f_mass_storage.c" | ||
51 | |||
52 | /*-------------------------------------------------------------------------*/ | ||
53 | |||
54 | static struct usb_device_descriptor device_desc = { | ||
55 | .bLength = sizeof device_desc, | ||
56 | .bDescriptorType = USB_DT_DEVICE, | ||
57 | |||
58 | .bcdUSB = cpu_to_le16(0x0200), | ||
59 | |||
60 | .bDeviceClass = USB_CLASS_MISC /* 0xEF */, | ||
61 | .bDeviceSubClass = 2, | ||
62 | .bDeviceProtocol = 1, | ||
63 | |||
64 | /* .bMaxPacketSize0 = f(hardware) */ | ||
65 | |||
66 | /* Vendor and product id can be overridden by module parameters. */ | ||
67 | .idVendor = cpu_to_le16(ACM_MS_VENDOR_NUM), | ||
68 | .idProduct = cpu_to_le16(ACM_MS_PRODUCT_NUM), | ||
69 | /* .bcdDevice = f(hardware) */ | ||
70 | /* .iManufacturer = DYNAMIC */ | ||
71 | /* .iProduct = DYNAMIC */ | ||
72 | /* NO SERIAL NUMBER */ | ||
73 | /*.bNumConfigurations = DYNAMIC*/ | ||
74 | }; | ||
75 | |||
76 | static struct usb_otg_descriptor otg_descriptor = { | ||
77 | .bLength = sizeof otg_descriptor, | ||
78 | .bDescriptorType = USB_DT_OTG, | ||
79 | |||
80 | /* | ||
81 | * REVISIT SRP-only hardware is possible, although | ||
82 | * it would not be called "OTG" ... | ||
83 | */ | ||
84 | .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, | ||
85 | }; | ||
86 | |||
87 | static const struct usb_descriptor_header *otg_desc[] = { | ||
88 | (struct usb_descriptor_header *) &otg_descriptor, | ||
89 | NULL, | ||
90 | }; | ||
91 | |||
92 | |||
93 | /* string IDs are assigned dynamically */ | ||
94 | |||
95 | #define STRING_MANUFACTURER_IDX 0 | ||
96 | #define STRING_PRODUCT_IDX 1 | ||
97 | |||
98 | static char manufacturer[50]; | ||
99 | |||
100 | static struct usb_string strings_dev[] = { | ||
101 | [STRING_MANUFACTURER_IDX].s = manufacturer, | ||
102 | [STRING_PRODUCT_IDX].s = DRIVER_DESC, | ||
103 | { } /* end of list */ | ||
104 | }; | ||
105 | |||
106 | static struct usb_gadget_strings stringtab_dev = { | ||
107 | .language = 0x0409, /* en-us */ | ||
108 | .strings = strings_dev, | ||
109 | }; | ||
110 | |||
111 | static struct usb_gadget_strings *dev_strings[] = { | ||
112 | &stringtab_dev, | ||
113 | NULL, | ||
114 | }; | ||
115 | |||
116 | /****************************** Configurations ******************************/ | ||
117 | |||
118 | static struct fsg_module_parameters fsg_mod_data = { .stall = 1 }; | ||
119 | FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); | ||
120 | |||
121 | static struct fsg_common fsg_common; | ||
122 | |||
123 | /*-------------------------------------------------------------------------*/ | ||
124 | |||
125 | /* | ||
126 | * We _always_ have both ACM and mass storage functions. | ||
127 | */ | ||
128 | static int __init acm_ms_do_config(struct usb_configuration *c) | ||
129 | { | ||
130 | int status; | ||
131 | |||
132 | if (gadget_is_otg(c->cdev->gadget)) { | ||
133 | c->descriptors = otg_desc; | ||
134 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | ||
135 | } | ||
136 | |||
137 | |||
138 | status = acm_bind_config(c, 0); | ||
139 | if (status < 0) | ||
140 | return status; | ||
141 | |||
142 | status = fsg_bind_config(c->cdev, c, &fsg_common); | ||
143 | if (status < 0) | ||
144 | return status; | ||
145 | |||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | static struct usb_configuration acm_ms_config_driver = { | ||
150 | .label = DRIVER_DESC, | ||
151 | .bConfigurationValue = 1, | ||
152 | /* .iConfiguration = DYNAMIC */ | ||
153 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | ||
154 | }; | ||
155 | |||
156 | /*-------------------------------------------------------------------------*/ | ||
157 | |||
158 | static int __init acm_ms_bind(struct usb_composite_dev *cdev) | ||
159 | { | ||
160 | int gcnum; | ||
161 | struct usb_gadget *gadget = cdev->gadget; | ||
162 | int status; | ||
163 | void *retp; | ||
164 | |||
165 | /* set up serial link layer */ | ||
166 | status = gserial_setup(cdev->gadget, 1); | ||
167 | if (status < 0) | ||
168 | return status; | ||
169 | |||
170 | /* set up mass storage function */ | ||
171 | retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); | ||
172 | if (IS_ERR(retp)) { | ||
173 | status = PTR_ERR(retp); | ||
174 | goto fail0; | ||
175 | } | ||
176 | |||
177 | /* set bcdDevice */ | ||
178 | gcnum = usb_gadget_controller_number(gadget); | ||
179 | if (gcnum >= 0) { | ||
180 | device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum); | ||
181 | } else { | ||
182 | WARNING(cdev, "controller '%s' not recognized; trying %s\n", | ||
183 | gadget->name, | ||
184 | acm_ms_config_driver.label); | ||
185 | device_desc.bcdDevice = | ||
186 | cpu_to_le16(0x0300 | 0x0099); | ||
187 | } | ||
188 | |||
189 | /* | ||
190 | * Allocate string descriptor numbers ... note that string | ||
191 | * contents can be overridden by the composite_dev glue. | ||
192 | */ | ||
193 | |||
194 | /* device descriptor strings: manufacturer, product */ | ||
195 | snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", | ||
196 | init_utsname()->sysname, init_utsname()->release, | ||
197 | gadget->name); | ||
198 | status = usb_string_id(cdev); | ||
199 | if (status < 0) | ||
200 | goto fail1; | ||
201 | strings_dev[STRING_MANUFACTURER_IDX].id = status; | ||
202 | device_desc.iManufacturer = status; | ||
203 | |||
204 | status = usb_string_id(cdev); | ||
205 | if (status < 0) | ||
206 | goto fail1; | ||
207 | strings_dev[STRING_PRODUCT_IDX].id = status; | ||
208 | device_desc.iProduct = status; | ||
209 | |||
210 | /* register our configuration */ | ||
211 | status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config); | ||
212 | if (status < 0) | ||
213 | goto fail1; | ||
214 | |||
215 | dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", | ||
216 | DRIVER_DESC); | ||
217 | fsg_common_put(&fsg_common); | ||
218 | return 0; | ||
219 | |||
220 | /* error recovery */ | ||
221 | fail1: | ||
222 | fsg_common_put(&fsg_common); | ||
223 | fail0: | ||
224 | gserial_cleanup(); | ||
225 | return status; | ||
226 | } | ||
227 | |||
228 | static int __exit acm_ms_unbind(struct usb_composite_dev *cdev) | ||
229 | { | ||
230 | gserial_cleanup(); | ||
231 | |||
232 | return 0; | ||
233 | } | ||
234 | |||
235 | static struct usb_composite_driver acm_ms_driver = { | ||
236 | .name = "g_acm_ms", | ||
237 | .dev = &device_desc, | ||
238 | .strings = dev_strings, | ||
239 | .unbind = __exit_p(acm_ms_unbind), | ||
240 | }; | ||
241 | |||
242 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
243 | MODULE_AUTHOR("Klaus Schwarzkopf <schwarzkopf@sensortherm.de>"); | ||
244 | MODULE_LICENSE("GPL v2"); | ||
245 | |||
246 | static int __init init(void) | ||
247 | { | ||
248 | return usb_composite_probe(&acm_ms_driver, acm_ms_bind); | ||
249 | } | ||
250 | module_init(init); | ||
251 | |||
252 | static void __exit cleanup(void) | ||
253 | { | ||
254 | usb_composite_unregister(&acm_ms_driver); | ||
255 | } | ||
256 | module_exit(cleanup); | ||
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c index 70f2b376c86d..4730016d7cd4 100644 --- a/drivers/usb/gadget/amd5536udc.c +++ b/drivers/usb/gadget/amd5536udc.c | |||
@@ -8,15 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | 11 | */ |
21 | 12 | ||
22 | /* | 13 | /* |
@@ -354,7 +345,7 @@ udc_ep_enable(struct usb_ep *usbep, const struct usb_endpoint_descriptor *desc) | |||
354 | writel(tmp, &dev->ep[ep->num].regs->ctl); | 345 | writel(tmp, &dev->ep[ep->num].regs->ctl); |
355 | 346 | ||
356 | /* set max packet size */ | 347 | /* set max packet size */ |
357 | maxpacket = le16_to_cpu(desc->wMaxPacketSize); | 348 | maxpacket = usb_endpoint_maxp(desc); |
358 | tmp = readl(&dev->ep[ep->num].regs->bufout_maxpkt); | 349 | tmp = readl(&dev->ep[ep->num].regs->bufout_maxpkt); |
359 | tmp = AMD_ADDBITS(tmp, maxpacket, UDC_EP_MAX_PKT_SIZE); | 350 | tmp = AMD_ADDBITS(tmp, maxpacket, UDC_EP_MAX_PKT_SIZE); |
360 | ep->ep.maxpacket = maxpacket; | 351 | ep->ep.maxpacket = maxpacket; |
@@ -3014,13 +3005,8 @@ __acquires(dev->lock) | |||
3014 | 3005 | ||
3015 | /* link up all endpoints */ | 3006 | /* link up all endpoints */ |
3016 | udc_setup_endpoints(dev); | 3007 | udc_setup_endpoints(dev); |
3017 | if (dev->gadget.speed == USB_SPEED_HIGH) { | 3008 | dev_info(&dev->pdev->dev, "Connect: %s\n", |
3018 | dev_info(&dev->pdev->dev, "Connect: speed = %s\n", | 3009 | usb_speed_string(dev->gadget.speed)); |
3019 | "high"); | ||
3020 | } else if (dev->gadget.speed == USB_SPEED_FULL) { | ||
3021 | dev_info(&dev->pdev->dev, "Connect: speed = %s\n", | ||
3022 | "full"); | ||
3023 | } | ||
3024 | 3010 | ||
3025 | /* init ep 0 */ | 3011 | /* init ep 0 */ |
3026 | activate_control_endpoints(dev); | 3012 | activate_control_endpoints(dev); |
diff --git a/drivers/usb/gadget/amd5536udc.h b/drivers/usb/gadget/amd5536udc.h index 1d1c7543468e..f87e29c65325 100644 --- a/drivers/usb/gadget/amd5536udc.h +++ b/drivers/usb/gadget/amd5536udc.h | |||
@@ -8,15 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | 11 | */ |
21 | 12 | ||
22 | #ifndef AMD5536UDC_H | 13 | #ifndef AMD5536UDC_H |
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index ddb118a76807..8efe0fa9228d 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c | |||
@@ -9,16 +9,6 @@ | |||
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or | 10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. | 11 | * (at your option) any later version. |
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the | ||
20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
21 | * Boston, MA 02111-1307, USA. | ||
22 | */ | 12 | */ |
23 | 13 | ||
24 | #undef VERBOSE_DEBUG | 14 | #undef VERBOSE_DEBUG |
@@ -460,7 +450,7 @@ static void nuke(struct at91_ep *ep, int status) | |||
460 | { | 450 | { |
461 | struct at91_request *req; | 451 | struct at91_request *req; |
462 | 452 | ||
463 | // terminer chaque requete dans la queue | 453 | /* terminate any request in the queue */ |
464 | ep->stopped = 1; | 454 | ep->stopped = 1; |
465 | if (list_empty(&ep->queue)) | 455 | if (list_empty(&ep->queue)) |
466 | return; | 456 | return; |
@@ -487,7 +477,7 @@ static int at91_ep_enable(struct usb_ep *_ep, | |||
487 | || !desc || ep->desc | 477 | || !desc || ep->desc |
488 | || _ep->name == ep0name | 478 | || _ep->name == ep0name |
489 | || desc->bDescriptorType != USB_DT_ENDPOINT | 479 | || desc->bDescriptorType != USB_DT_ENDPOINT |
490 | || (maxpacket = le16_to_cpu(desc->wMaxPacketSize)) == 0 | 480 | || (maxpacket = usb_endpoint_maxp(desc)) == 0 |
491 | || maxpacket > ep->maxpacket) { | 481 | || maxpacket > ep->maxpacket) { |
492 | DBG("bad ep or descriptor\n"); | 482 | DBG("bad ep or descriptor\n"); |
493 | return -EINVAL; | 483 | return -EINVAL; |
@@ -788,7 +778,7 @@ static const struct usb_ep_ops at91_ep_ops = { | |||
788 | .queue = at91_ep_queue, | 778 | .queue = at91_ep_queue, |
789 | .dequeue = at91_ep_dequeue, | 779 | .dequeue = at91_ep_dequeue, |
790 | .set_halt = at91_ep_set_halt, | 780 | .set_halt = at91_ep_set_halt, |
791 | // there's only imprecise fifo status reporting | 781 | /* there's only imprecise fifo status reporting */ |
792 | }; | 782 | }; |
793 | 783 | ||
794 | /*-------------------------------------------------------------------------*/ | 784 | /*-------------------------------------------------------------------------*/ |
@@ -846,7 +836,7 @@ static void udc_reinit(struct at91_udc *udc) | |||
846 | ep->fifo_bank = 0; | 836 | ep->fifo_bank = 0; |
847 | ep->ep.maxpacket = ep->maxpacket; | 837 | ep->ep.maxpacket = ep->maxpacket; |
848 | ep->creg = (void __iomem *) udc->udp_baseaddr + AT91_UDP_CSR(i); | 838 | ep->creg = (void __iomem *) udc->udp_baseaddr + AT91_UDP_CSR(i); |
849 | // initialiser une queue par endpoint | 839 | /* initialize one queue per endpoint */ |
850 | INIT_LIST_HEAD(&ep->queue); | 840 | INIT_LIST_HEAD(&ep->queue); |
851 | } | 841 | } |
852 | } | 842 | } |
@@ -952,7 +942,7 @@ static int at91_vbus_session(struct usb_gadget *gadget, int is_active) | |||
952 | struct at91_udc *udc = to_udc(gadget); | 942 | struct at91_udc *udc = to_udc(gadget); |
953 | unsigned long flags; | 943 | unsigned long flags; |
954 | 944 | ||
955 | // VDBG("vbus %s\n", is_active ? "on" : "off"); | 945 | /* VDBG("vbus %s\n", is_active ? "on" : "off"); */ |
956 | spin_lock_irqsave(&udc->lock, flags); | 946 | spin_lock_irqsave(&udc->lock, flags); |
957 | udc->vbus = (is_active != 0); | 947 | udc->vbus = (is_active != 0); |
958 | if (udc->driver) | 948 | if (udc->driver) |
@@ -1003,7 +993,7 @@ static const struct usb_gadget_ops at91_udc_ops = { | |||
1003 | * VBUS-powered devices may also also want to support bigger | 993 | * VBUS-powered devices may also also want to support bigger |
1004 | * power budgets after an appropriate SET_CONFIGURATION. | 994 | * power budgets after an appropriate SET_CONFIGURATION. |
1005 | */ | 995 | */ |
1006 | // .vbus_power = at91_vbus_power, | 996 | /* .vbus_power = at91_vbus_power, */ |
1007 | }; | 997 | }; |
1008 | 998 | ||
1009 | /*-------------------------------------------------------------------------*/ | 999 | /*-------------------------------------------------------------------------*/ |
@@ -1072,7 +1062,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr) | |||
1072 | ep->is_in = 0; | 1062 | ep->is_in = 0; |
1073 | } | 1063 | } |
1074 | } else { | 1064 | } else { |
1075 | // REVISIT this happens sometimes under load; why?? | 1065 | /* REVISIT this happens sometimes under load; why?? */ |
1076 | ERR("SETUP len %d, csr %08x\n", rxcount, csr); | 1066 | ERR("SETUP len %d, csr %08x\n", rxcount, csr); |
1077 | status = -EINVAL; | 1067 | status = -EINVAL; |
1078 | } | 1068 | } |
@@ -1451,7 +1441,7 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc) | |||
1451 | at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXSUSP); | 1441 | at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXSUSP); |
1452 | at91_udp_write(udc, AT91_UDP_IER, AT91_UDP_RXRSM); | 1442 | at91_udp_write(udc, AT91_UDP_IER, AT91_UDP_RXRSM); |
1453 | at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXSUSP); | 1443 | at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXSUSP); |
1454 | // VDBG("bus suspend\n"); | 1444 | /* VDBG("bus suspend\n"); */ |
1455 | if (udc->suspended) | 1445 | if (udc->suspended) |
1456 | continue; | 1446 | continue; |
1457 | udc->suspended = 1; | 1447 | udc->suspended = 1; |
@@ -1473,7 +1463,7 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc) | |||
1473 | at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXRSM); | 1463 | at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXRSM); |
1474 | at91_udp_write(udc, AT91_UDP_IER, AT91_UDP_RXSUSP); | 1464 | at91_udp_write(udc, AT91_UDP_IER, AT91_UDP_RXSUSP); |
1475 | at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXRSM); | 1465 | at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXRSM); |
1476 | // VDBG("bus resume\n"); | 1466 | /* VDBG("bus resume\n"); */ |
1477 | if (!udc->suspended) | 1467 | if (!udc->suspended) |
1478 | continue; | 1468 | continue; |
1479 | udc->suspended = 0; | 1469 | udc->suspended = 0; |
@@ -1820,7 +1810,7 @@ static int __init at91udc_probe(struct platform_device *pdev) | |||
1820 | /* request UDC and maybe VBUS irqs */ | 1810 | /* request UDC and maybe VBUS irqs */ |
1821 | udc->udp_irq = platform_get_irq(pdev, 0); | 1811 | udc->udp_irq = platform_get_irq(pdev, 0); |
1822 | retval = request_irq(udc->udp_irq, at91_udc_irq, | 1812 | retval = request_irq(udc->udp_irq, at91_udc_irq, |
1823 | IRQF_DISABLED, driver_name, udc); | 1813 | 0, driver_name, udc); |
1824 | if (retval < 0) { | 1814 | if (retval < 0) { |
1825 | DBG("request irq %d failed\n", udc->udp_irq); | 1815 | DBG("request irq %d failed\n", udc->udp_irq); |
1826 | goto fail1; | 1816 | goto fail1; |
@@ -1848,7 +1838,7 @@ static int __init at91udc_probe(struct platform_device *pdev) | |||
1848 | jiffies + VBUS_POLL_TIMEOUT); | 1838 | jiffies + VBUS_POLL_TIMEOUT); |
1849 | } else { | 1839 | } else { |
1850 | if (request_irq(udc->board.vbus_pin, at91_vbus_irq, | 1840 | if (request_irq(udc->board.vbus_pin, at91_vbus_irq, |
1851 | IRQF_DISABLED, driver_name, udc)) { | 1841 | 0, driver_name, udc)) { |
1852 | DBG("request vbus irq %d failed\n", | 1842 | DBG("request vbus irq %d failed\n", |
1853 | udc->board.vbus_pin); | 1843 | udc->board.vbus_pin); |
1854 | retval = -EBUSY; | 1844 | retval = -EBUSY; |
diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h index 108ca54f9092..3c0315b86ace 100644 --- a/drivers/usb/gadget/at91_udc.h +++ b/drivers/usb/gadget/at91_udc.h | |||
@@ -7,16 +7,6 @@ | |||
7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or | 8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the | ||
18 | * Free Software Foundation, Inc., | ||
19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
20 | */ | 10 | */ |
21 | 11 | ||
22 | #ifndef AT91_UDC_H | 12 | #ifndef AT91_UDC_H |
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c index 5b1665eb1bef..271a9d873608 100644 --- a/drivers/usb/gadget/atmel_usba_udc.c +++ b/drivers/usb/gadget/atmel_usba_udc.c | |||
@@ -527,7 +527,7 @@ usba_ep_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
527 | 527 | ||
528 | DBG(DBG_GADGET, "%s: ep_enable: desc=%p\n", ep->ep.name, desc); | 528 | DBG(DBG_GADGET, "%s: ep_enable: desc=%p\n", ep->ep.name, desc); |
529 | 529 | ||
530 | maxpacket = le16_to_cpu(desc->wMaxPacketSize) & 0x7ff; | 530 | maxpacket = usb_endpoint_maxp(desc) & 0x7ff; |
531 | 531 | ||
532 | if (((desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) != ep->index) | 532 | if (((desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) != ep->index) |
533 | || ep->index == 0 | 533 | || ep->index == 0 |
@@ -571,7 +571,7 @@ usba_ep_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
571 | * Bits 11:12 specify number of _additional_ | 571 | * Bits 11:12 specify number of _additional_ |
572 | * transactions per microframe. | 572 | * transactions per microframe. |
573 | */ | 573 | */ |
574 | nr_trans = ((le16_to_cpu(desc->wMaxPacketSize) >> 11) & 3) + 1; | 574 | nr_trans = ((usb_endpoint_maxp(desc) >> 11) & 3) + 1; |
575 | if (nr_trans > 3) | 575 | if (nr_trans > 3) |
576 | return -EINVAL; | 576 | return -EINVAL; |
577 | 577 | ||
@@ -1718,13 +1718,12 @@ static irqreturn_t usba_udc_irq(int irq, void *devid) | |||
1718 | spin_lock(&udc->lock); | 1718 | spin_lock(&udc->lock); |
1719 | } | 1719 | } |
1720 | 1720 | ||
1721 | if (status & USBA_HIGH_SPEED) { | 1721 | if (status & USBA_HIGH_SPEED) |
1722 | DBG(DBG_BUS, "High-speed bus reset detected\n"); | ||
1723 | udc->gadget.speed = USB_SPEED_HIGH; | 1722 | udc->gadget.speed = USB_SPEED_HIGH; |
1724 | } else { | 1723 | else |
1725 | DBG(DBG_BUS, "Full-speed bus reset detected\n"); | ||
1726 | udc->gadget.speed = USB_SPEED_FULL; | 1724 | udc->gadget.speed = USB_SPEED_FULL; |
1727 | } | 1725 | DBG(DBG_BUS, "%s bus reset detected\n", |
1726 | usb_speed_string(udc->gadget.speed)); | ||
1728 | 1727 | ||
1729 | ep0 = &usba_ep[0]; | 1728 | ep0 = &usba_ep[0]; |
1730 | ep0->desc = &usba_ep0_desc; | 1729 | ep0->desc = &usba_ep0_desc; |
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c index b1c1afbb8750..672674c2fb3d 100644 --- a/drivers/usb/gadget/cdc2.c +++ b/drivers/usb/gadget/cdc2.c | |||
@@ -8,15 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | 11 | */ |
21 | 12 | ||
22 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
diff --git a/drivers/usb/gadget/ci13xxx_msm.c b/drivers/usb/gadget/ci13xxx_msm.c index 470981ad6f77..4eedfe557154 100644 --- a/drivers/usb/gadget/ci13xxx_msm.c +++ b/drivers/usb/gadget/ci13xxx_msm.c | |||
@@ -3,17 +3,6 @@ | |||
3 | * This program is free software; you can redistribute it and/or modify | 3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License version 2 and | 4 | * it under the terms of the GNU General Public License version 2 and |
5 | * only version 2 as published by the Free Software Foundation. | 5 | * only version 2 as published by the Free Software Foundation. |
6 | * | ||
7 | * This program is distributed in the hope that it will be useful, | ||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
10 | * GNU General Public License for more details. | ||
11 | * | ||
12 | * You should have received a copy of the GNU General Public License | ||
13 | * along with this program; if not, write to the Free Software | ||
14 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
15 | * 02110-1301, USA. | ||
16 | * | ||
17 | */ | 6 | */ |
18 | 7 | ||
19 | #include <linux/module.h> | 8 | #include <linux/module.h> |
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c index 1265a8502ea0..83428f56253b 100644 --- a/drivers/usb/gadget/ci13xxx_udc.c +++ b/drivers/usb/gadget/ci13xxx_udc.c | |||
@@ -2101,7 +2101,7 @@ static int ep_enable(struct usb_ep *ep, | |||
2101 | mEp->num = usb_endpoint_num(desc); | 2101 | mEp->num = usb_endpoint_num(desc); |
2102 | mEp->type = usb_endpoint_type(desc); | 2102 | mEp->type = usb_endpoint_type(desc); |
2103 | 2103 | ||
2104 | mEp->ep.maxpacket = __constant_le16_to_cpu(desc->wMaxPacketSize); | 2104 | mEp->ep.maxpacket = usb_endpoint_maxp(desc); |
2105 | 2105 | ||
2106 | dbg_event(_usb_addr(mEp), "ENABLE", 0); | 2106 | dbg_event(_usb_addr(mEp), "ENABLE", 0); |
2107 | 2107 | ||
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index aef47414f5d5..8a5529d214fb 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -7,15 +7,6 @@ | |||
7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or | 8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | */ | 10 | */ |
20 | 11 | ||
21 | /* #define VERBOSE_DEBUG */ | 12 | /* #define VERBOSE_DEBUG */ |
@@ -164,7 +155,7 @@ int config_ep_by_speed(struct usb_gadget *g, | |||
164 | 155 | ||
165 | ep_found: | 156 | ep_found: |
166 | /* commit results */ | 157 | /* commit results */ |
167 | _ep->maxpacket = le16_to_cpu(chosen_desc->wMaxPacketSize); | 158 | _ep->maxpacket = usb_endpoint_maxp(chosen_desc); |
168 | _ep->desc = chosen_desc; | 159 | _ep->desc = chosen_desc; |
169 | _ep->comp_desc = NULL; | 160 | _ep->comp_desc = NULL; |
170 | _ep->maxburst = 0; | 161 | _ep->maxburst = 0; |
@@ -551,9 +542,9 @@ static int bos_desc(struct usb_composite_dev *cdev) | |||
551 | if (cdev->gadget->ops->get_config_params) | 542 | if (cdev->gadget->ops->get_config_params) |
552 | cdev->gadget->ops->get_config_params(&dcd_config_params); | 543 | cdev->gadget->ops->get_config_params(&dcd_config_params); |
553 | else { | 544 | else { |
554 | dcd_config_params.bU1devExitLat = USB_DEFULT_U1_DEV_EXIT_LAT; | 545 | dcd_config_params.bU1devExitLat = USB_DEFAULT_U1_DEV_EXIT_LAT; |
555 | dcd_config_params.bU2DevExitLat = | 546 | dcd_config_params.bU2DevExitLat = |
556 | cpu_to_le16(USB_DEFULT_U2_DEV_EXIT_LAT); | 547 | cpu_to_le16(USB_DEFAULT_U2_DEV_EXIT_LAT); |
557 | } | 548 | } |
558 | ss_cap->bU1devExitLat = dcd_config_params.bU1devExitLat; | 549 | ss_cap->bU1devExitLat = dcd_config_params.bU1devExitLat; |
559 | ss_cap->bU2DevExitLat = dcd_config_params.bU2DevExitLat; | 550 | ss_cap->bU2DevExitLat = dcd_config_params.bU2DevExitLat; |
@@ -626,25 +617,9 @@ static int set_config(struct usb_composite_dev *cdev, | |||
626 | result = 0; | 617 | result = 0; |
627 | } | 618 | } |
628 | 619 | ||
629 | INFO(cdev, "%s speed config #%d: %s\n", | 620 | INFO(cdev, "%s config #%d: %s\n", |
630 | ({ char *speed; | 621 | usb_speed_string(gadget->speed), |
631 | switch (gadget->speed) { | 622 | number, c ? c->label : "unconfigured"); |
632 | case USB_SPEED_LOW: | ||
633 | speed = "low"; | ||
634 | break; | ||
635 | case USB_SPEED_FULL: | ||
636 | speed = "full"; | ||
637 | break; | ||
638 | case USB_SPEED_HIGH: | ||
639 | speed = "high"; | ||
640 | break; | ||
641 | case USB_SPEED_SUPER: | ||
642 | speed = "super"; | ||
643 | break; | ||
644 | default: | ||
645 | speed = "?"; | ||
646 | break; | ||
647 | } ; speed; }), number, c ? c->label : "unconfigured"); | ||
648 | 623 | ||
649 | if (!c) | 624 | if (!c) |
650 | goto done; | 625 | goto done; |
diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c index b2c001334876..7542a72ce51a 100644 --- a/drivers/usb/gadget/config.c +++ b/drivers/usb/gadget/config.c | |||
@@ -7,15 +7,6 @@ | |||
7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or | 8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | */ | 10 | */ |
20 | 11 | ||
21 | #include <linux/errno.h> | 12 | #include <linux/errno.h> |
diff --git a/drivers/usb/gadget/dbgp.c b/drivers/usb/gadget/dbgp.c index 8beefdd36787..f855ecf7a637 100644 --- a/drivers/usb/gadget/dbgp.c +++ b/drivers/usb/gadget/dbgp.c | |||
@@ -4,7 +4,6 @@ | |||
4 | * Copyright (C) 2010 Stephane Duverger | 4 | * Copyright (C) 2010 Stephane Duverger |
5 | * | 5 | * |
6 | * Released under the GPLv2. | 6 | * Released under the GPLv2. |
7 | * | ||
8 | */ | 7 | */ |
9 | 8 | ||
10 | /* verbose messages */ | 9 | /* verbose messages */ |
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index e755a9d267fc..ab8f1b488d54 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c | |||
@@ -10,15 +10,6 @@ | |||
10 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or | 11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. | 12 | * (at your option) any later version. |
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | */ | 13 | */ |
23 | 14 | ||
24 | 15 | ||
@@ -439,7 +430,7 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
439 | * maximum packet size. | 430 | * maximum packet size. |
440 | * For SS devices the wMaxPacketSize is limited by 1024. | 431 | * For SS devices the wMaxPacketSize is limited by 1024. |
441 | */ | 432 | */ |
442 | max = le16_to_cpu(desc->wMaxPacketSize) & 0x7ff; | 433 | max = usb_endpoint_maxp(desc) & 0x7ff; |
443 | 434 | ||
444 | /* drivers must not request bad settings, since lower levels | 435 | /* drivers must not request bad settings, since lower levels |
445 | * (hardware or its drivers) may not check. some endpoints | 436 | * (hardware or its drivers) may not check. some endpoints |
@@ -1277,7 +1268,7 @@ static int periodic_bytes (struct dummy *dum, struct dummy_ep *ep) | |||
1277 | int tmp; | 1268 | int tmp; |
1278 | 1269 | ||
1279 | /* high bandwidth mode */ | 1270 | /* high bandwidth mode */ |
1280 | tmp = le16_to_cpu(ep->desc->wMaxPacketSize); | 1271 | tmp = usb_endpoint_maxp(ep->desc); |
1281 | tmp = (tmp >> 11) & 0x03; | 1272 | tmp = (tmp >> 11) & 0x03; |
1282 | tmp *= 8 /* applies to entire frame */; | 1273 | tmp *= 8 /* applies to entire frame */; |
1283 | limit += limit * tmp; | 1274 | limit += limit * tmp; |
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c index 7a7e6b7e1fd6..596a0b464e61 100644 --- a/drivers/usb/gadget/epautoconf.c +++ b/drivers/usb/gadget/epautoconf.c | |||
@@ -7,16 +7,6 @@ | |||
7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or | 8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | * | ||
20 | */ | 10 | */ |
21 | 11 | ||
22 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
@@ -158,7 +148,7 @@ ep_matches ( | |||
158 | * where it's an output parameter representing the full speed limit. | 148 | * where it's an output parameter representing the full speed limit. |
159 | * the usb spec fixes high speed bulk maxpacket at 512 bytes. | 149 | * the usb spec fixes high speed bulk maxpacket at 512 bytes. |
160 | */ | 150 | */ |
161 | max = 0x7ff & le16_to_cpu(desc->wMaxPacketSize); | 151 | max = 0x7ff & usb_endpoint_maxp(desc); |
162 | switch (type) { | 152 | switch (type) { |
163 | case USB_ENDPOINT_XFER_INT: | 153 | case USB_ENDPOINT_XFER_INT: |
164 | /* INT: limit 64 bytes full speed, 1024 high/super speed */ | 154 | /* INT: limit 64 bytes full speed, 1024 high/super speed */ |
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index aafc84f33e26..0cd764d59351 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c | |||
@@ -9,15 +9,6 @@ | |||
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or | 10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. | 11 | * (at your option) any later version. |
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | 12 | */ |
22 | 13 | ||
23 | /* #define VERBOSE_DEBUG */ | 14 | /* #define VERBOSE_DEBUG */ |
diff --git a/drivers/usb/gadget/f_audio.c b/drivers/usb/gadget/f_audio.c index a9a4eade7e80..ec7ffcd0d0cd 100644 --- a/drivers/usb/gadget/f_audio.c +++ b/drivers/usb/gadget/f_audio.c | |||
@@ -460,7 +460,7 @@ static int audio_set_endpoint_req(struct usb_function *f, | |||
460 | 460 | ||
461 | switch (ctrl->bRequest) { | 461 | switch (ctrl->bRequest) { |
462 | case UAC_SET_CUR: | 462 | case UAC_SET_CUR: |
463 | value = 0; | 463 | value = len; |
464 | break; | 464 | break; |
465 | 465 | ||
466 | case UAC_SET_MIN: | 466 | case UAC_SET_MIN: |
@@ -499,7 +499,7 @@ static int audio_get_endpoint_req(struct usb_function *f, | |||
499 | case UAC_GET_MIN: | 499 | case UAC_GET_MIN: |
500 | case UAC_GET_MAX: | 500 | case UAC_GET_MAX: |
501 | case UAC_GET_RES: | 501 | case UAC_GET_RES: |
502 | value = 3; | 502 | value = len; |
503 | break; | 503 | break; |
504 | case UAC_GET_MEM: | 504 | case UAC_GET_MEM: |
505 | break; | 505 | break; |
@@ -681,17 +681,18 @@ f_audio_bind(struct usb_configuration *c, struct usb_function *f) | |||
681 | 681 | ||
682 | status = -ENOMEM; | 682 | status = -ENOMEM; |
683 | 683 | ||
684 | /* supcard all relevant hardware speeds... we expect that when | 684 | /* copy descriptors, and track endpoint copies */ |
685 | f->descriptors = usb_copy_descriptors(f_audio_desc); | ||
686 | |||
687 | /* | ||
688 | * support all relevant hardware speeds... we expect that when | ||
685 | * hardware is dual speed, all bulk-capable endpoints work at | 689 | * hardware is dual speed, all bulk-capable endpoints work at |
686 | * both speeds | 690 | * both speeds |
687 | */ | 691 | */ |
688 | |||
689 | /* copy descriptors, and track endpoint copies */ | ||
690 | if (gadget_is_dualspeed(c->cdev->gadget)) { | 692 | if (gadget_is_dualspeed(c->cdev->gadget)) { |
691 | c->highspeed = true; | 693 | c->highspeed = true; |
692 | f->hs_descriptors = usb_copy_descriptors(f_audio_desc); | 694 | f->hs_descriptors = usb_copy_descriptors(f_audio_desc); |
693 | } else | 695 | } |
694 | f->descriptors = usb_copy_descriptors(f_audio_desc); | ||
695 | 696 | ||
696 | return 0; | 697 | return 0; |
697 | 698 | ||
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c index 3691a0cb9465..11c07cb7d337 100644 --- a/drivers/usb/gadget/f_ecm.c +++ b/drivers/usb/gadget/f_ecm.c | |||
@@ -8,15 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | 11 | */ |
21 | 12 | ||
22 | /* #define VERBOSE_DEBUG */ | 13 | /* #define VERBOSE_DEBUG */ |
diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c index 046c6d0e6960..1a7b2dd7d408 100644 --- a/drivers/usb/gadget/f_eem.c +++ b/drivers/usb/gadget/f_eem.c | |||
@@ -9,15 +9,6 @@ | |||
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or | 10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. | 11 | * (at your option) any later version. |
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | 12 | */ |
22 | 13 | ||
23 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c index c161a9aaeb7e..6b1c20b6c9b2 100644 --- a/drivers/usb/gadget/f_fs.c +++ b/drivers/usb/gadget/f_fs.c | |||
@@ -12,15 +12,6 @@ | |||
12 | * it under the terms of the GNU General Public License as published by | 12 | * it under the terms of the GNU General Public License as published by |
13 | * the Free Software Foundation; either version 2 of the License, or | 13 | * the Free Software Foundation; either version 2 of the License, or |
14 | * (at your option) any later version. | 14 | * (at your option) any later version. |
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | * GNU General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public License | ||
22 | * along with this program; if not, write to the Free Software | ||
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
24 | */ | 15 | */ |
25 | 16 | ||
26 | 17 | ||
diff --git a/drivers/usb/gadget/f_hid.c b/drivers/usb/gadget/f_hid.c index 83a266bdb40e..b2113420b806 100644 --- a/drivers/usb/gadget/f_hid.c +++ b/drivers/usb/gadget/f_hid.c | |||
@@ -7,15 +7,6 @@ | |||
7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or | 8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | */ | 10 | */ |
20 | 11 | ||
21 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c index ca660d40b11a..6d87f288df4e 100644 --- a/drivers/usb/gadget/f_loopback.c +++ b/drivers/usb/gadget/f_loopback.c | |||
@@ -8,15 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | 11 | */ |
21 | 12 | ||
22 | /* #define VERBOSE_DEBUG */ | 13 | /* #define VERBOSE_DEBUG */ |
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 5b9339582007..52583a235330 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c | |||
@@ -112,8 +112,7 @@ | |||
112 | * is not loaded (an empty string as "filename" in the fsg_config | 112 | * is not loaded (an empty string as "filename" in the fsg_config |
113 | * structure causes error). The CD-ROM emulation includes a single | 113 | * structure causes error). The CD-ROM emulation includes a single |
114 | * data track and no audio tracks; hence there need be only one | 114 | * data track and no audio tracks; hence there need be only one |
115 | * backing file per LUN. Note also that the CD-ROM block length is | 115 | * backing file per LUN. |
116 | * set to 512 rather than the more common value 2048. | ||
117 | * | 116 | * |
118 | * | 117 | * |
119 | * MSF includes support for module parameters. If gadget using it | 118 | * MSF includes support for module parameters. If gadget using it |
@@ -363,7 +362,7 @@ struct fsg_common { | |||
363 | 362 | ||
364 | struct fsg_buffhd *next_buffhd_to_fill; | 363 | struct fsg_buffhd *next_buffhd_to_fill; |
365 | struct fsg_buffhd *next_buffhd_to_drain; | 364 | struct fsg_buffhd *next_buffhd_to_drain; |
366 | struct fsg_buffhd buffhds[FSG_NUM_BUFFERS]; | 365 | struct fsg_buffhd *buffhds; |
367 | 366 | ||
368 | int cmnd_size; | 367 | int cmnd_size; |
369 | u8 cmnd[MAX_COMMAND_SIZE]; | 368 | u8 cmnd[MAX_COMMAND_SIZE]; |
@@ -745,7 +744,6 @@ static int do_read(struct fsg_common *common) | |||
745 | u32 amount_left; | 744 | u32 amount_left; |
746 | loff_t file_offset, file_offset_tmp; | 745 | loff_t file_offset, file_offset_tmp; |
747 | unsigned int amount; | 746 | unsigned int amount; |
748 | unsigned int partial_page; | ||
749 | ssize_t nread; | 747 | ssize_t nread; |
750 | 748 | ||
751 | /* | 749 | /* |
@@ -771,7 +769,7 @@ static int do_read(struct fsg_common *common) | |||
771 | curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; | 769 | curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; |
772 | return -EINVAL; | 770 | return -EINVAL; |
773 | } | 771 | } |
774 | file_offset = ((loff_t) lba) << 9; | 772 | file_offset = ((loff_t) lba) << curlun->blkbits; |
775 | 773 | ||
776 | /* Carry out the file reads */ | 774 | /* Carry out the file reads */ |
777 | amount_left = common->data_size_from_cmnd; | 775 | amount_left = common->data_size_from_cmnd; |
@@ -784,18 +782,10 @@ static int do_read(struct fsg_common *common) | |||
784 | * Try to read the remaining amount. | 782 | * Try to read the remaining amount. |
785 | * But don't read more than the buffer size. | 783 | * But don't read more than the buffer size. |
786 | * And don't try to read past the end of the file. | 784 | * And don't try to read past the end of the file. |
787 | * Finally, if we're not at a page boundary, don't read past | ||
788 | * the next page. | ||
789 | * If this means reading 0 then we were asked to read past | ||
790 | * the end of file. | ||
791 | */ | 785 | */ |
792 | amount = min(amount_left, FSG_BUFLEN); | 786 | amount = min(amount_left, FSG_BUFLEN); |
793 | amount = min((loff_t)amount, | 787 | amount = min((loff_t)amount, |
794 | curlun->file_length - file_offset); | 788 | curlun->file_length - file_offset); |
795 | partial_page = file_offset & (PAGE_CACHE_SIZE - 1); | ||
796 | if (partial_page > 0) | ||
797 | amount = min(amount, (unsigned int)PAGE_CACHE_SIZE - | ||
798 | partial_page); | ||
799 | 789 | ||
800 | /* Wait for the next buffer to become available */ | 790 | /* Wait for the next buffer to become available */ |
801 | bh = common->next_buffhd_to_fill; | 791 | bh = common->next_buffhd_to_fill; |
@@ -812,7 +802,8 @@ static int do_read(struct fsg_common *common) | |||
812 | if (amount == 0) { | 802 | if (amount == 0) { |
813 | curlun->sense_data = | 803 | curlun->sense_data = |
814 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; | 804 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; |
815 | curlun->sense_data_info = file_offset >> 9; | 805 | curlun->sense_data_info = |
806 | file_offset >> curlun->blkbits; | ||
816 | curlun->info_valid = 1; | 807 | curlun->info_valid = 1; |
817 | bh->inreq->length = 0; | 808 | bh->inreq->length = 0; |
818 | bh->state = BUF_STATE_FULL; | 809 | bh->state = BUF_STATE_FULL; |
@@ -835,18 +826,25 @@ static int do_read(struct fsg_common *common) | |||
835 | } else if (nread < amount) { | 826 | } else if (nread < amount) { |
836 | LDBG(curlun, "partial file read: %d/%u\n", | 827 | LDBG(curlun, "partial file read: %d/%u\n", |
837 | (int)nread, amount); | 828 | (int)nread, amount); |
838 | nread -= (nread & 511); /* Round down to a block */ | 829 | nread = round_down(nread, curlun->blksize); |
839 | } | 830 | } |
840 | file_offset += nread; | 831 | file_offset += nread; |
841 | amount_left -= nread; | 832 | amount_left -= nread; |
842 | common->residue -= nread; | 833 | common->residue -= nread; |
834 | |||
835 | /* | ||
836 | * Except at the end of the transfer, nread will be | ||
837 | * equal to the buffer size, which is divisible by the | ||
838 | * bulk-in maxpacket size. | ||
839 | */ | ||
843 | bh->inreq->length = nread; | 840 | bh->inreq->length = nread; |
844 | bh->state = BUF_STATE_FULL; | 841 | bh->state = BUF_STATE_FULL; |
845 | 842 | ||
846 | /* If an error occurred, report it and its position */ | 843 | /* If an error occurred, report it and its position */ |
847 | if (nread < amount) { | 844 | if (nread < amount) { |
848 | curlun->sense_data = SS_UNRECOVERED_READ_ERROR; | 845 | curlun->sense_data = SS_UNRECOVERED_READ_ERROR; |
849 | curlun->sense_data_info = file_offset >> 9; | 846 | curlun->sense_data_info = |
847 | file_offset >> curlun->blkbits; | ||
850 | curlun->info_valid = 1; | 848 | curlun->info_valid = 1; |
851 | break; | 849 | break; |
852 | } | 850 | } |
@@ -877,7 +875,6 @@ static int do_write(struct fsg_common *common) | |||
877 | u32 amount_left_to_req, amount_left_to_write; | 875 | u32 amount_left_to_req, amount_left_to_write; |
878 | loff_t usb_offset, file_offset, file_offset_tmp; | 876 | loff_t usb_offset, file_offset, file_offset_tmp; |
879 | unsigned int amount; | 877 | unsigned int amount; |
880 | unsigned int partial_page; | ||
881 | ssize_t nwritten; | 878 | ssize_t nwritten; |
882 | int rc; | 879 | int rc; |
883 | 880 | ||
@@ -921,7 +918,7 @@ static int do_write(struct fsg_common *common) | |||
921 | 918 | ||
922 | /* Carry out the file writes */ | 919 | /* Carry out the file writes */ |
923 | get_some_more = 1; | 920 | get_some_more = 1; |
924 | file_offset = usb_offset = ((loff_t) lba) << 9; | 921 | file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits; |
925 | amount_left_to_req = common->data_size_from_cmnd; | 922 | amount_left_to_req = common->data_size_from_cmnd; |
926 | amount_left_to_write = common->data_size_from_cmnd; | 923 | amount_left_to_write = common->data_size_from_cmnd; |
927 | 924 | ||
@@ -933,41 +930,21 @@ static int do_write(struct fsg_common *common) | |||
933 | 930 | ||
934 | /* | 931 | /* |
935 | * Figure out how much we want to get: | 932 | * Figure out how much we want to get: |
936 | * Try to get the remaining amount. | 933 | * Try to get the remaining amount, |
937 | * But don't get more than the buffer size. | 934 | * but not more than the buffer size. |
938 | * And don't try to go past the end of the file. | ||
939 | * If we're not at a page boundary, | ||
940 | * don't go past the next page. | ||
941 | * If this means getting 0, then we were asked | ||
942 | * to write past the end of file. | ||
943 | * Finally, round down to a block boundary. | ||
944 | */ | 935 | */ |
945 | amount = min(amount_left_to_req, FSG_BUFLEN); | 936 | amount = min(amount_left_to_req, FSG_BUFLEN); |
946 | amount = min((loff_t)amount, | 937 | |
947 | curlun->file_length - usb_offset); | 938 | /* Beyond the end of the backing file? */ |
948 | partial_page = usb_offset & (PAGE_CACHE_SIZE - 1); | 939 | if (usb_offset >= curlun->file_length) { |
949 | if (partial_page > 0) | ||
950 | amount = min(amount, | ||
951 | (unsigned int)PAGE_CACHE_SIZE - partial_page); | ||
952 | |||
953 | if (amount == 0) { | ||
954 | get_some_more = 0; | 940 | get_some_more = 0; |
955 | curlun->sense_data = | 941 | curlun->sense_data = |
956 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; | 942 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; |
957 | curlun->sense_data_info = usb_offset >> 9; | 943 | curlun->sense_data_info = |
944 | usb_offset >> curlun->blkbits; | ||
958 | curlun->info_valid = 1; | 945 | curlun->info_valid = 1; |
959 | continue; | 946 | continue; |
960 | } | 947 | } |
961 | amount -= amount & 511; | ||
962 | if (amount == 0) { | ||
963 | |||
964 | /* | ||
965 | * Why were we were asked to transfer a | ||
966 | * partial block? | ||
967 | */ | ||
968 | get_some_more = 0; | ||
969 | continue; | ||
970 | } | ||
971 | 948 | ||
972 | /* Get the next buffer */ | 949 | /* Get the next buffer */ |
973 | usb_offset += amount; | 950 | usb_offset += amount; |
@@ -977,12 +954,11 @@ static int do_write(struct fsg_common *common) | |||
977 | get_some_more = 0; | 954 | get_some_more = 0; |
978 | 955 | ||
979 | /* | 956 | /* |
980 | * amount is always divisible by 512, hence by | 957 | * Except at the end of the transfer, amount will be |
981 | * the bulk-out maxpacket size | 958 | * equal to the buffer size, which is divisible by |
959 | * the bulk-out maxpacket size. | ||
982 | */ | 960 | */ |
983 | bh->outreq->length = amount; | 961 | set_bulk_out_req_length(common, bh, amount); |
984 | bh->bulk_out_intended_length = amount; | ||
985 | bh->outreq->short_not_ok = 1; | ||
986 | if (!start_out_transfer(common, bh)) | 962 | if (!start_out_transfer(common, bh)) |
987 | /* Dunno what to do if common->fsg is NULL */ | 963 | /* Dunno what to do if common->fsg is NULL */ |
988 | return -EIO; | 964 | return -EIO; |
@@ -1002,7 +978,8 @@ static int do_write(struct fsg_common *common) | |||
1002 | /* Did something go wrong with the transfer? */ | 978 | /* Did something go wrong with the transfer? */ |
1003 | if (bh->outreq->status != 0) { | 979 | if (bh->outreq->status != 0) { |
1004 | curlun->sense_data = SS_COMMUNICATION_FAILURE; | 980 | curlun->sense_data = SS_COMMUNICATION_FAILURE; |
1005 | curlun->sense_data_info = file_offset >> 9; | 981 | curlun->sense_data_info = |
982 | file_offset >> curlun->blkbits; | ||
1006 | curlun->info_valid = 1; | 983 | curlun->info_valid = 1; |
1007 | break; | 984 | break; |
1008 | } | 985 | } |
@@ -1016,6 +993,16 @@ static int do_write(struct fsg_common *common) | |||
1016 | amount = curlun->file_length - file_offset; | 993 | amount = curlun->file_length - file_offset; |
1017 | } | 994 | } |
1018 | 995 | ||
996 | /* Don't accept excess data. The spec doesn't say | ||
997 | * what to do in this case. We'll ignore the error. | ||
998 | */ | ||
999 | amount = min(amount, bh->bulk_out_intended_length); | ||
1000 | |||
1001 | /* Don't write a partial block */ | ||
1002 | amount = round_down(amount, curlun->blksize); | ||
1003 | if (amount == 0) | ||
1004 | goto empty_write; | ||
1005 | |||
1019 | /* Perform the write */ | 1006 | /* Perform the write */ |
1020 | file_offset_tmp = file_offset; | 1007 | file_offset_tmp = file_offset; |
1021 | nwritten = vfs_write(curlun->filp, | 1008 | nwritten = vfs_write(curlun->filp, |
@@ -1033,8 +1020,7 @@ static int do_write(struct fsg_common *common) | |||
1033 | } else if (nwritten < amount) { | 1020 | } else if (nwritten < amount) { |
1034 | LDBG(curlun, "partial file write: %d/%u\n", | 1021 | LDBG(curlun, "partial file write: %d/%u\n", |
1035 | (int)nwritten, amount); | 1022 | (int)nwritten, amount); |
1036 | nwritten -= (nwritten & 511); | 1023 | nwritten = round_down(nwritten, curlun->blksize); |
1037 | /* Round down to a block */ | ||
1038 | } | 1024 | } |
1039 | file_offset += nwritten; | 1025 | file_offset += nwritten; |
1040 | amount_left_to_write -= nwritten; | 1026 | amount_left_to_write -= nwritten; |
@@ -1043,13 +1029,15 @@ static int do_write(struct fsg_common *common) | |||
1043 | /* If an error occurred, report it and its position */ | 1029 | /* If an error occurred, report it and its position */ |
1044 | if (nwritten < amount) { | 1030 | if (nwritten < amount) { |
1045 | curlun->sense_data = SS_WRITE_ERROR; | 1031 | curlun->sense_data = SS_WRITE_ERROR; |
1046 | curlun->sense_data_info = file_offset >> 9; | 1032 | curlun->sense_data_info = |
1033 | file_offset >> curlun->blkbits; | ||
1047 | curlun->info_valid = 1; | 1034 | curlun->info_valid = 1; |
1048 | break; | 1035 | break; |
1049 | } | 1036 | } |
1050 | 1037 | ||
1038 | empty_write: | ||
1051 | /* Did the host decide to stop early? */ | 1039 | /* Did the host decide to stop early? */ |
1052 | if (bh->outreq->actual != bh->outreq->length) { | 1040 | if (bh->outreq->actual < bh->bulk_out_intended_length) { |
1053 | common->short_packet_received = 1; | 1041 | common->short_packet_received = 1; |
1054 | break; | 1042 | break; |
1055 | } | 1043 | } |
@@ -1129,8 +1117,8 @@ static int do_verify(struct fsg_common *common) | |||
1129 | return -EIO; /* No default reply */ | 1117 | return -EIO; /* No default reply */ |
1130 | 1118 | ||
1131 | /* Prepare to carry out the file verify */ | 1119 | /* Prepare to carry out the file verify */ |
1132 | amount_left = verification_length << 9; | 1120 | amount_left = verification_length << curlun->blkbits; |
1133 | file_offset = ((loff_t) lba) << 9; | 1121 | file_offset = ((loff_t) lba) << curlun->blkbits; |
1134 | 1122 | ||
1135 | /* Write out all the dirty buffers before invalidating them */ | 1123 | /* Write out all the dirty buffers before invalidating them */ |
1136 | fsg_lun_fsync_sub(curlun); | 1124 | fsg_lun_fsync_sub(curlun); |
@@ -1148,8 +1136,6 @@ static int do_verify(struct fsg_common *common) | |||
1148 | * Try to read the remaining amount, but not more than | 1136 | * Try to read the remaining amount, but not more than |
1149 | * the buffer size. | 1137 | * the buffer size. |
1150 | * And don't try to read past the end of the file. | 1138 | * And don't try to read past the end of the file. |
1151 | * If this means reading 0 then we were asked to read | ||
1152 | * past the end of file. | ||
1153 | */ | 1139 | */ |
1154 | amount = min(amount_left, FSG_BUFLEN); | 1140 | amount = min(amount_left, FSG_BUFLEN); |
1155 | amount = min((loff_t)amount, | 1141 | amount = min((loff_t)amount, |
@@ -1157,7 +1143,8 @@ static int do_verify(struct fsg_common *common) | |||
1157 | if (amount == 0) { | 1143 | if (amount == 0) { |
1158 | curlun->sense_data = | 1144 | curlun->sense_data = |
1159 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; | 1145 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; |
1160 | curlun->sense_data_info = file_offset >> 9; | 1146 | curlun->sense_data_info = |
1147 | file_offset >> curlun->blkbits; | ||
1161 | curlun->info_valid = 1; | 1148 | curlun->info_valid = 1; |
1162 | break; | 1149 | break; |
1163 | } | 1150 | } |
@@ -1179,11 +1166,12 @@ static int do_verify(struct fsg_common *common) | |||
1179 | } else if (nread < amount) { | 1166 | } else if (nread < amount) { |
1180 | LDBG(curlun, "partial file verify: %d/%u\n", | 1167 | LDBG(curlun, "partial file verify: %d/%u\n", |
1181 | (int)nread, amount); | 1168 | (int)nread, amount); |
1182 | nread -= nread & 511; /* Round down to a sector */ | 1169 | nread = round_down(nread, curlun->blksize); |
1183 | } | 1170 | } |
1184 | if (nread == 0) { | 1171 | if (nread == 0) { |
1185 | curlun->sense_data = SS_UNRECOVERED_READ_ERROR; | 1172 | curlun->sense_data = SS_UNRECOVERED_READ_ERROR; |
1186 | curlun->sense_data_info = file_offset >> 9; | 1173 | curlun->sense_data_info = |
1174 | file_offset >> curlun->blkbits; | ||
1187 | curlun->info_valid = 1; | 1175 | curlun->info_valid = 1; |
1188 | break; | 1176 | break; |
1189 | } | 1177 | } |
@@ -1289,7 +1277,7 @@ static int do_read_capacity(struct fsg_common *common, struct fsg_buffhd *bh) | |||
1289 | 1277 | ||
1290 | put_unaligned_be32(curlun->num_sectors - 1, &buf[0]); | 1278 | put_unaligned_be32(curlun->num_sectors - 1, &buf[0]); |
1291 | /* Max logical block */ | 1279 | /* Max logical block */ |
1292 | put_unaligned_be32(512, &buf[4]); /* Block length */ | 1280 | put_unaligned_be32(curlun->blksize, &buf[4]);/* Block length */ |
1293 | return 8; | 1281 | return 8; |
1294 | } | 1282 | } |
1295 | 1283 | ||
@@ -1527,7 +1515,7 @@ static int do_read_format_capacities(struct fsg_common *common, | |||
1527 | 1515 | ||
1528 | put_unaligned_be32(curlun->num_sectors, &buf[0]); | 1516 | put_unaligned_be32(curlun->num_sectors, &buf[0]); |
1529 | /* Number of blocks */ | 1517 | /* Number of blocks */ |
1530 | put_unaligned_be32(512, &buf[4]); /* Block length */ | 1518 | put_unaligned_be32(curlun->blksize, &buf[4]);/* Block length */ |
1531 | buf[4] = 0x02; /* Current capacity */ | 1519 | buf[4] = 0x02; /* Current capacity */ |
1532 | return 12; | 1520 | return 12; |
1533 | } | 1521 | } |
@@ -1607,7 +1595,7 @@ static int throw_away_data(struct fsg_common *common) | |||
1607 | common->next_buffhd_to_drain = bh->next; | 1595 | common->next_buffhd_to_drain = bh->next; |
1608 | 1596 | ||
1609 | /* A short packet or an error ends everything */ | 1597 | /* A short packet or an error ends everything */ |
1610 | if (bh->outreq->actual != bh->outreq->length || | 1598 | if (bh->outreq->actual < bh->bulk_out_intended_length || |
1611 | bh->outreq->status != 0) { | 1599 | bh->outreq->status != 0) { |
1612 | raise_exception(common, | 1600 | raise_exception(common, |
1613 | FSG_STATE_ABORT_BULK_OUT); | 1601 | FSG_STATE_ABORT_BULK_OUT); |
@@ -1623,12 +1611,11 @@ static int throw_away_data(struct fsg_common *common) | |||
1623 | amount = min(common->usb_amount_left, FSG_BUFLEN); | 1611 | amount = min(common->usb_amount_left, FSG_BUFLEN); |
1624 | 1612 | ||
1625 | /* | 1613 | /* |
1626 | * amount is always divisible by 512, hence by | 1614 | * Except at the end of the transfer, amount will be |
1615 | * equal to the buffer size, which is divisible by | ||
1627 | * the bulk-out maxpacket size. | 1616 | * the bulk-out maxpacket size. |
1628 | */ | 1617 | */ |
1629 | bh->outreq->length = amount; | 1618 | set_bulk_out_req_length(common, bh, amount); |
1630 | bh->bulk_out_intended_length = amount; | ||
1631 | bh->outreq->short_not_ok = 1; | ||
1632 | if (!start_out_transfer(common, bh)) | 1619 | if (!start_out_transfer(common, bh)) |
1633 | /* Dunno what to do if common->fsg is NULL */ | 1620 | /* Dunno what to do if common->fsg is NULL */ |
1634 | return -EIO; | 1621 | return -EIO; |
@@ -2022,7 +2009,8 @@ static int do_scsi_command(struct fsg_common *common) | |||
2022 | 2009 | ||
2023 | case READ_6: | 2010 | case READ_6: |
2024 | i = common->cmnd[4]; | 2011 | i = common->cmnd[4]; |
2025 | common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; | 2012 | common->data_size_from_cmnd = (i == 0 ? 256 : i) << |
2013 | common->curlun->blkbits; | ||
2026 | reply = check_command(common, 6, DATA_DIR_TO_HOST, | 2014 | reply = check_command(common, 6, DATA_DIR_TO_HOST, |
2027 | (7<<1) | (1<<4), 1, | 2015 | (7<<1) | (1<<4), 1, |
2028 | "READ(6)"); | 2016 | "READ(6)"); |
@@ -2032,7 +2020,8 @@ static int do_scsi_command(struct fsg_common *common) | |||
2032 | 2020 | ||
2033 | case READ_10: | 2021 | case READ_10: |
2034 | common->data_size_from_cmnd = | 2022 | common->data_size_from_cmnd = |
2035 | get_unaligned_be16(&common->cmnd[7]) << 9; | 2023 | get_unaligned_be16(&common->cmnd[7]) << |
2024 | common->curlun->blkbits; | ||
2036 | reply = check_command(common, 10, DATA_DIR_TO_HOST, | 2025 | reply = check_command(common, 10, DATA_DIR_TO_HOST, |
2037 | (1<<1) | (0xf<<2) | (3<<7), 1, | 2026 | (1<<1) | (0xf<<2) | (3<<7), 1, |
2038 | "READ(10)"); | 2027 | "READ(10)"); |
@@ -2042,7 +2031,8 @@ static int do_scsi_command(struct fsg_common *common) | |||
2042 | 2031 | ||
2043 | case READ_12: | 2032 | case READ_12: |
2044 | common->data_size_from_cmnd = | 2033 | common->data_size_from_cmnd = |
2045 | get_unaligned_be32(&common->cmnd[6]) << 9; | 2034 | get_unaligned_be32(&common->cmnd[6]) << |
2035 | common->curlun->blkbits; | ||
2046 | reply = check_command(common, 12, DATA_DIR_TO_HOST, | 2036 | reply = check_command(common, 12, DATA_DIR_TO_HOST, |
2047 | (1<<1) | (0xf<<2) | (0xf<<6), 1, | 2037 | (1<<1) | (0xf<<2) | (0xf<<6), 1, |
2048 | "READ(12)"); | 2038 | "READ(12)"); |
@@ -2142,7 +2132,8 @@ static int do_scsi_command(struct fsg_common *common) | |||
2142 | 2132 | ||
2143 | case WRITE_6: | 2133 | case WRITE_6: |
2144 | i = common->cmnd[4]; | 2134 | i = common->cmnd[4]; |
2145 | common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; | 2135 | common->data_size_from_cmnd = (i == 0 ? 256 : i) << |
2136 | common->curlun->blkbits; | ||
2146 | reply = check_command(common, 6, DATA_DIR_FROM_HOST, | 2137 | reply = check_command(common, 6, DATA_DIR_FROM_HOST, |
2147 | (7<<1) | (1<<4), 1, | 2138 | (7<<1) | (1<<4), 1, |
2148 | "WRITE(6)"); | 2139 | "WRITE(6)"); |
@@ -2152,7 +2143,8 @@ static int do_scsi_command(struct fsg_common *common) | |||
2152 | 2143 | ||
2153 | case WRITE_10: | 2144 | case WRITE_10: |
2154 | common->data_size_from_cmnd = | 2145 | common->data_size_from_cmnd = |
2155 | get_unaligned_be16(&common->cmnd[7]) << 9; | 2146 | get_unaligned_be16(&common->cmnd[7]) << |
2147 | common->curlun->blkbits; | ||
2156 | reply = check_command(common, 10, DATA_DIR_FROM_HOST, | 2148 | reply = check_command(common, 10, DATA_DIR_FROM_HOST, |
2157 | (1<<1) | (0xf<<2) | (3<<7), 1, | 2149 | (1<<1) | (0xf<<2) | (3<<7), 1, |
2158 | "WRITE(10)"); | 2150 | "WRITE(10)"); |
@@ -2162,7 +2154,8 @@ static int do_scsi_command(struct fsg_common *common) | |||
2162 | 2154 | ||
2163 | case WRITE_12: | 2155 | case WRITE_12: |
2164 | common->data_size_from_cmnd = | 2156 | common->data_size_from_cmnd = |
2165 | get_unaligned_be32(&common->cmnd[6]) << 9; | 2157 | get_unaligned_be32(&common->cmnd[6]) << |
2158 | common->curlun->blkbits; | ||
2166 | reply = check_command(common, 12, DATA_DIR_FROM_HOST, | 2159 | reply = check_command(common, 12, DATA_DIR_FROM_HOST, |
2167 | (1<<1) | (0xf<<2) | (0xf<<6), 1, | 2160 | (1<<1) | (0xf<<2) | (0xf<<6), 1, |
2168 | "WRITE(12)"); | 2161 | "WRITE(12)"); |
@@ -2297,7 +2290,6 @@ static int get_next_command(struct fsg_common *common) | |||
2297 | 2290 | ||
2298 | /* Queue a request to read a Bulk-only CBW */ | 2291 | /* Queue a request to read a Bulk-only CBW */ |
2299 | set_bulk_out_req_length(common, bh, USB_BULK_CB_WRAP_LEN); | 2292 | set_bulk_out_req_length(common, bh, USB_BULK_CB_WRAP_LEN); |
2300 | bh->outreq->short_not_ok = 1; | ||
2301 | if (!start_out_transfer(common, bh)) | 2293 | if (!start_out_transfer(common, bh)) |
2302 | /* Don't know what to do if common->fsg is NULL */ | 2294 | /* Don't know what to do if common->fsg is NULL */ |
2303 | return -EIO; | 2295 | return -EIO; |
@@ -2348,7 +2340,7 @@ reset: | |||
2348 | if (common->fsg) { | 2340 | if (common->fsg) { |
2349 | fsg = common->fsg; | 2341 | fsg = common->fsg; |
2350 | 2342 | ||
2351 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | 2343 | for (i = 0; i < fsg_num_buffers; ++i) { |
2352 | struct fsg_buffhd *bh = &common->buffhds[i]; | 2344 | struct fsg_buffhd *bh = &common->buffhds[i]; |
2353 | 2345 | ||
2354 | if (bh->inreq) { | 2346 | if (bh->inreq) { |
@@ -2401,12 +2393,11 @@ reset: | |||
2401 | goto reset; | 2393 | goto reset; |
2402 | fsg->bulk_out->driver_data = common; | 2394 | fsg->bulk_out->driver_data = common; |
2403 | fsg->bulk_out_enabled = 1; | 2395 | fsg->bulk_out_enabled = 1; |
2404 | common->bulk_out_maxpacket = | 2396 | common->bulk_out_maxpacket = usb_endpoint_maxp(fsg->bulk_out->desc); |
2405 | le16_to_cpu(fsg->bulk_out->desc->wMaxPacketSize); | ||
2406 | clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); | 2397 | clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); |
2407 | 2398 | ||
2408 | /* Allocate the requests */ | 2399 | /* Allocate the requests */ |
2409 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | 2400 | for (i = 0; i < fsg_num_buffers; ++i) { |
2410 | struct fsg_buffhd *bh = &common->buffhds[i]; | 2401 | struct fsg_buffhd *bh = &common->buffhds[i]; |
2411 | 2402 | ||
2412 | rc = alloc_request(common, fsg->bulk_in, &bh->inreq); | 2403 | rc = alloc_request(common, fsg->bulk_in, &bh->inreq); |
@@ -2475,7 +2466,7 @@ static void handle_exception(struct fsg_common *common) | |||
2475 | 2466 | ||
2476 | /* Cancel all the pending transfers */ | 2467 | /* Cancel all the pending transfers */ |
2477 | if (likely(common->fsg)) { | 2468 | if (likely(common->fsg)) { |
2478 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | 2469 | for (i = 0; i < fsg_num_buffers; ++i) { |
2479 | bh = &common->buffhds[i]; | 2470 | bh = &common->buffhds[i]; |
2480 | if (bh->inreq_busy) | 2471 | if (bh->inreq_busy) |
2481 | usb_ep_dequeue(common->fsg->bulk_in, bh->inreq); | 2472 | usb_ep_dequeue(common->fsg->bulk_in, bh->inreq); |
@@ -2487,7 +2478,7 @@ static void handle_exception(struct fsg_common *common) | |||
2487 | /* Wait until everything is idle */ | 2478 | /* Wait until everything is idle */ |
2488 | for (;;) { | 2479 | for (;;) { |
2489 | int num_active = 0; | 2480 | int num_active = 0; |
2490 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | 2481 | for (i = 0; i < fsg_num_buffers; ++i) { |
2491 | bh = &common->buffhds[i]; | 2482 | bh = &common->buffhds[i]; |
2492 | num_active += bh->inreq_busy + bh->outreq_busy; | 2483 | num_active += bh->inreq_busy + bh->outreq_busy; |
2493 | } | 2484 | } |
@@ -2510,7 +2501,7 @@ static void handle_exception(struct fsg_common *common) | |||
2510 | */ | 2501 | */ |
2511 | spin_lock_irq(&common->lock); | 2502 | spin_lock_irq(&common->lock); |
2512 | 2503 | ||
2513 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | 2504 | for (i = 0; i < fsg_num_buffers; ++i) { |
2514 | bh = &common->buffhds[i]; | 2505 | bh = &common->buffhds[i]; |
2515 | bh->state = BUF_STATE_EMPTY; | 2506 | bh->state = BUF_STATE_EMPTY; |
2516 | } | 2507 | } |
@@ -2719,6 +2710,10 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common, | |||
2719 | int nluns, i, rc; | 2710 | int nluns, i, rc; |
2720 | char *pathbuf; | 2711 | char *pathbuf; |
2721 | 2712 | ||
2713 | rc = fsg_num_buffers_validate(); | ||
2714 | if (rc != 0) | ||
2715 | return ERR_PTR(rc); | ||
2716 | |||
2722 | /* Find out how many LUNs there should be */ | 2717 | /* Find out how many LUNs there should be */ |
2723 | nluns = cfg->nluns; | 2718 | nluns = cfg->nluns; |
2724 | if (nluns < 1 || nluns > FSG_MAX_LUNS) { | 2719 | if (nluns < 1 || nluns > FSG_MAX_LUNS) { |
@@ -2737,6 +2732,14 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common, | |||
2737 | common->free_storage_on_release = 0; | 2732 | common->free_storage_on_release = 0; |
2738 | } | 2733 | } |
2739 | 2734 | ||
2735 | common->buffhds = kcalloc(fsg_num_buffers, | ||
2736 | sizeof *(common->buffhds), GFP_KERNEL); | ||
2737 | if (!common->buffhds) { | ||
2738 | if (common->free_storage_on_release) | ||
2739 | kfree(common); | ||
2740 | return ERR_PTR(-ENOMEM); | ||
2741 | } | ||
2742 | |||
2740 | common->ops = cfg->ops; | 2743 | common->ops = cfg->ops; |
2741 | common->private_data = cfg->private_data; | 2744 | common->private_data = cfg->private_data; |
2742 | 2745 | ||
@@ -2814,7 +2817,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common, | |||
2814 | 2817 | ||
2815 | /* Data buffers cyclic list */ | 2818 | /* Data buffers cyclic list */ |
2816 | bh = common->buffhds; | 2819 | bh = common->buffhds; |
2817 | i = FSG_NUM_BUFFERS; | 2820 | i = fsg_num_buffers; |
2818 | goto buffhds_first_it; | 2821 | goto buffhds_first_it; |
2819 | do { | 2822 | do { |
2820 | bh->next = bh + 1; | 2823 | bh->next = bh + 1; |
@@ -2940,12 +2943,13 @@ static void fsg_common_release(struct kref *ref) | |||
2940 | 2943 | ||
2941 | { | 2944 | { |
2942 | struct fsg_buffhd *bh = common->buffhds; | 2945 | struct fsg_buffhd *bh = common->buffhds; |
2943 | unsigned i = FSG_NUM_BUFFERS; | 2946 | unsigned i = fsg_num_buffers; |
2944 | do { | 2947 | do { |
2945 | kfree(bh->buf); | 2948 | kfree(bh->buf); |
2946 | } while (++bh, --i); | 2949 | } while (++bh, --i); |
2947 | } | 2950 | } |
2948 | 2951 | ||
2952 | kfree(common->buffhds); | ||
2949 | if (common->free_storage_on_release) | 2953 | if (common->free_storage_on_release) |
2950 | kfree(common); | 2954 | kfree(common); |
2951 | } | 2955 | } |
@@ -3019,6 +3023,28 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) | |||
3019 | } | 3023 | } |
3020 | } | 3024 | } |
3021 | 3025 | ||
3026 | if (gadget_is_superspeed(gadget)) { | ||
3027 | unsigned max_burst; | ||
3028 | |||
3029 | /* Calculate bMaxBurst, we know packet size is 1024 */ | ||
3030 | max_burst = min_t(unsigned, FSG_BUFLEN / 1024, 15); | ||
3031 | |||
3032 | fsg_ss_bulk_in_desc.bEndpointAddress = | ||
3033 | fsg_fs_bulk_in_desc.bEndpointAddress; | ||
3034 | fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst; | ||
3035 | |||
3036 | fsg_ss_bulk_out_desc.bEndpointAddress = | ||
3037 | fsg_fs_bulk_out_desc.bEndpointAddress; | ||
3038 | fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst; | ||
3039 | |||
3040 | f->ss_descriptors = usb_copy_descriptors(fsg_ss_function); | ||
3041 | if (unlikely(!f->ss_descriptors)) { | ||
3042 | usb_free_descriptors(f->hs_descriptors); | ||
3043 | usb_free_descriptors(f->descriptors); | ||
3044 | return -ENOMEM; | ||
3045 | } | ||
3046 | } | ||
3047 | |||
3022 | return 0; | 3048 | return 0; |
3023 | 3049 | ||
3024 | autoconf_fail: | 3050 | autoconf_fail: |
diff --git a/drivers/usb/gadget/f_midi.c b/drivers/usb/gadget/f_midi.c new file mode 100644 index 000000000000..67b222908cf9 --- /dev/null +++ b/drivers/usb/gadget/f_midi.c | |||
@@ -0,0 +1,998 @@ | |||
1 | /* | ||
2 | * f_midi.c -- USB MIDI class function driver | ||
3 | * | ||
4 | * Copyright (C) 2006 Thumtronics Pty Ltd. | ||
5 | * Developed for Thumtronics by Grey Innovation | ||
6 | * Ben Williamson <ben.williamson@greyinnovation.com> | ||
7 | * | ||
8 | * Rewritten for the composite framework | ||
9 | * Copyright (C) 2011 Daniel Mack <zonque@gmail.com> | ||
10 | * | ||
11 | * Based on drivers/usb/gadget/f_audio.c, | ||
12 | * Copyright (C) 2008 Bryan Wu <cooloney@kernel.org> | ||
13 | * Copyright (C) 2008 Analog Devices, Inc | ||
14 | * | ||
15 | * and drivers/usb/gadget/midi.c, | ||
16 | * Copyright (C) 2006 Thumtronics Pty Ltd. | ||
17 | * Ben Williamson <ben.williamson@greyinnovation.com> | ||
18 | * | ||
19 | * Licensed under the GPL-2 or later. | ||
20 | */ | ||
21 | |||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/slab.h> | ||
24 | #include <linux/utsname.h> | ||
25 | #include <linux/device.h> | ||
26 | |||
27 | #include <sound/core.h> | ||
28 | #include <sound/initval.h> | ||
29 | #include <sound/rawmidi.h> | ||
30 | |||
31 | #include <linux/usb/ch9.h> | ||
32 | #include <linux/usb/gadget.h> | ||
33 | #include <linux/usb/audio.h> | ||
34 | #include <linux/usb/midi.h> | ||
35 | |||
36 | MODULE_AUTHOR("Ben Williamson"); | ||
37 | MODULE_LICENSE("GPL v2"); | ||
38 | |||
39 | static const char f_midi_shortname[] = "f_midi"; | ||
40 | static const char f_midi_longname[] = "MIDI Gadget"; | ||
41 | |||
42 | /* | ||
43 | * We can only handle 16 cables on one single endpoint, as cable numbers are | ||
44 | * stored in 4-bit fields. And as the interface currently only holds one | ||
45 | * single endpoint, this is the maximum number of ports we can allow. | ||
46 | */ | ||
47 | #define MAX_PORTS 16 | ||
48 | |||
49 | /* | ||
50 | * This is a gadget, and the IN/OUT naming is from the host's perspective. | ||
51 | * USB -> OUT endpoint -> rawmidi | ||
52 | * USB <- IN endpoint <- rawmidi | ||
53 | */ | ||
54 | struct gmidi_in_port { | ||
55 | struct f_midi *midi; | ||
56 | int active; | ||
57 | uint8_t cable; | ||
58 | uint8_t state; | ||
59 | #define STATE_UNKNOWN 0 | ||
60 | #define STATE_1PARAM 1 | ||
61 | #define STATE_2PARAM_1 2 | ||
62 | #define STATE_2PARAM_2 3 | ||
63 | #define STATE_SYSEX_0 4 | ||
64 | #define STATE_SYSEX_1 5 | ||
65 | #define STATE_SYSEX_2 6 | ||
66 | uint8_t data[2]; | ||
67 | }; | ||
68 | |||
69 | struct f_midi { | ||
70 | struct usb_function func; | ||
71 | struct usb_gadget *gadget; | ||
72 | struct usb_ep *in_ep, *out_ep; | ||
73 | struct snd_card *card; | ||
74 | struct snd_rawmidi *rmidi; | ||
75 | |||
76 | struct snd_rawmidi_substream *in_substream[MAX_PORTS]; | ||
77 | struct snd_rawmidi_substream *out_substream[MAX_PORTS]; | ||
78 | struct gmidi_in_port *in_port[MAX_PORTS]; | ||
79 | |||
80 | unsigned long out_triggered; | ||
81 | struct tasklet_struct tasklet; | ||
82 | unsigned int in_ports; | ||
83 | unsigned int out_ports; | ||
84 | int index; | ||
85 | char *id; | ||
86 | unsigned int buflen, qlen; | ||
87 | }; | ||
88 | |||
89 | static inline struct f_midi *func_to_midi(struct usb_function *f) | ||
90 | { | ||
91 | return container_of(f, struct f_midi, func); | ||
92 | } | ||
93 | |||
94 | static void f_midi_transmit(struct f_midi *midi, struct usb_request *req); | ||
95 | |||
96 | DECLARE_UAC_AC_HEADER_DESCRIPTOR(1); | ||
97 | DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1); | ||
98 | DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(16); | ||
99 | DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(16); | ||
100 | |||
101 | /* B.3.1 Standard AC Interface Descriptor */ | ||
102 | static struct usb_interface_descriptor ac_interface_desc __initdata = { | ||
103 | .bLength = USB_DT_INTERFACE_SIZE, | ||
104 | .bDescriptorType = USB_DT_INTERFACE, | ||
105 | /* .bInterfaceNumber = DYNAMIC */ | ||
106 | /* .bNumEndpoints = DYNAMIC */ | ||
107 | .bInterfaceClass = USB_CLASS_AUDIO, | ||
108 | .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL, | ||
109 | /* .iInterface = DYNAMIC */ | ||
110 | }; | ||
111 | |||
112 | /* B.3.2 Class-Specific AC Interface Descriptor */ | ||
113 | static struct uac1_ac_header_descriptor_1 ac_header_desc __initdata = { | ||
114 | .bLength = UAC_DT_AC_HEADER_SIZE(1), | ||
115 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
116 | .bDescriptorSubtype = USB_MS_HEADER, | ||
117 | .bcdADC = cpu_to_le16(0x0100), | ||
118 | .wTotalLength = cpu_to_le16(UAC_DT_AC_HEADER_SIZE(1)), | ||
119 | .bInCollection = 1, | ||
120 | /* .baInterfaceNr = DYNAMIC */ | ||
121 | }; | ||
122 | |||
123 | /* B.4.1 Standard MS Interface Descriptor */ | ||
124 | static struct usb_interface_descriptor ms_interface_desc __initdata = { | ||
125 | .bLength = USB_DT_INTERFACE_SIZE, | ||
126 | .bDescriptorType = USB_DT_INTERFACE, | ||
127 | /* .bInterfaceNumber = DYNAMIC */ | ||
128 | .bNumEndpoints = 2, | ||
129 | .bInterfaceClass = USB_CLASS_AUDIO, | ||
130 | .bInterfaceSubClass = USB_SUBCLASS_MIDISTREAMING, | ||
131 | /* .iInterface = DYNAMIC */ | ||
132 | }; | ||
133 | |||
134 | /* B.4.2 Class-Specific MS Interface Descriptor */ | ||
135 | static struct usb_ms_header_descriptor ms_header_desc __initdata = { | ||
136 | .bLength = USB_DT_MS_HEADER_SIZE, | ||
137 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
138 | .bDescriptorSubtype = USB_MS_HEADER, | ||
139 | .bcdMSC = cpu_to_le16(0x0100), | ||
140 | /* .wTotalLength = DYNAMIC */ | ||
141 | }; | ||
142 | |||
143 | /* B.4.3 Embedded MIDI IN Jack Descriptor */ | ||
144 | static struct usb_midi_in_jack_descriptor jack_in_emb_desc = { | ||
145 | .bLength = USB_DT_MIDI_IN_SIZE, | ||
146 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
147 | .bDescriptorSubtype = USB_MS_MIDI_IN_JACK, | ||
148 | .bJackType = USB_MS_EMBEDDED, | ||
149 | /* .bJackID = DYNAMIC */ | ||
150 | }; | ||
151 | |||
152 | /* B.4.4 Embedded MIDI OUT Jack Descriptor */ | ||
153 | static struct usb_midi_out_jack_descriptor_16 jack_out_emb_desc = { | ||
154 | /* .bLength = DYNAMIC */ | ||
155 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
156 | .bDescriptorSubtype = USB_MS_MIDI_OUT_JACK, | ||
157 | .bJackType = USB_MS_EMBEDDED, | ||
158 | /* .bJackID = DYNAMIC */ | ||
159 | /* .bNrInputPins = DYNAMIC */ | ||
160 | /* .pins = DYNAMIC */ | ||
161 | }; | ||
162 | |||
163 | /* B.5.1 Standard Bulk OUT Endpoint Descriptor */ | ||
164 | static struct usb_endpoint_descriptor bulk_out_desc = { | ||
165 | .bLength = USB_DT_ENDPOINT_AUDIO_SIZE, | ||
166 | .bDescriptorType = USB_DT_ENDPOINT, | ||
167 | .bEndpointAddress = USB_DIR_OUT, | ||
168 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
169 | }; | ||
170 | |||
171 | /* B.5.2 Class-specific MS Bulk OUT Endpoint Descriptor */ | ||
172 | static struct usb_ms_endpoint_descriptor_16 ms_out_desc = { | ||
173 | /* .bLength = DYNAMIC */ | ||
174 | .bDescriptorType = USB_DT_CS_ENDPOINT, | ||
175 | .bDescriptorSubtype = USB_MS_GENERAL, | ||
176 | /* .bNumEmbMIDIJack = DYNAMIC */ | ||
177 | /* .baAssocJackID = DYNAMIC */ | ||
178 | }; | ||
179 | |||
180 | /* B.6.1 Standard Bulk IN Endpoint Descriptor */ | ||
181 | static struct usb_endpoint_descriptor bulk_in_desc = { | ||
182 | .bLength = USB_DT_ENDPOINT_AUDIO_SIZE, | ||
183 | .bDescriptorType = USB_DT_ENDPOINT, | ||
184 | .bEndpointAddress = USB_DIR_IN, | ||
185 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
186 | }; | ||
187 | |||
188 | /* B.6.2 Class-specific MS Bulk IN Endpoint Descriptor */ | ||
189 | static struct usb_ms_endpoint_descriptor_16 ms_in_desc = { | ||
190 | /* .bLength = DYNAMIC */ | ||
191 | .bDescriptorType = USB_DT_CS_ENDPOINT, | ||
192 | .bDescriptorSubtype = USB_MS_GENERAL, | ||
193 | /* .bNumEmbMIDIJack = DYNAMIC */ | ||
194 | /* .baAssocJackID = DYNAMIC */ | ||
195 | }; | ||
196 | |||
197 | /* string IDs are assigned dynamically */ | ||
198 | |||
199 | #define STRING_FUNC_IDX 0 | ||
200 | |||
201 | static struct usb_string midi_string_defs[] = { | ||
202 | [STRING_FUNC_IDX].s = "MIDI function", | ||
203 | { } /* end of list */ | ||
204 | }; | ||
205 | |||
206 | static struct usb_gadget_strings midi_stringtab = { | ||
207 | .language = 0x0409, /* en-us */ | ||
208 | .strings = midi_string_defs, | ||
209 | }; | ||
210 | |||
211 | static struct usb_gadget_strings *midi_strings[] = { | ||
212 | &midi_stringtab, | ||
213 | NULL, | ||
214 | }; | ||
215 | |||
216 | static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length) | ||
217 | { | ||
218 | struct usb_request *req; | ||
219 | |||
220 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); | ||
221 | if (req) { | ||
222 | req->length = length; | ||
223 | req->buf = kmalloc(length, GFP_ATOMIC); | ||
224 | if (!req->buf) { | ||
225 | usb_ep_free_request(ep, req); | ||
226 | req = NULL; | ||
227 | } | ||
228 | } | ||
229 | return req; | ||
230 | } | ||
231 | |||
232 | static void free_ep_req(struct usb_ep *ep, struct usb_request *req) | ||
233 | { | ||
234 | kfree(req->buf); | ||
235 | usb_ep_free_request(ep, req); | ||
236 | } | ||
237 | |||
238 | static const uint8_t f_midi_cin_length[] = { | ||
239 | 0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1 | ||
240 | }; | ||
241 | |||
242 | /* | ||
243 | * Receives a chunk of MIDI data. | ||
244 | */ | ||
245 | static void f_midi_read_data(struct usb_ep *ep, int cable, | ||
246 | uint8_t *data, int length) | ||
247 | { | ||
248 | struct f_midi *midi = ep->driver_data; | ||
249 | struct snd_rawmidi_substream *substream = midi->out_substream[cable]; | ||
250 | |||
251 | if (!substream) | ||
252 | /* Nobody is listening - throw it on the floor. */ | ||
253 | return; | ||
254 | |||
255 | if (!test_bit(cable, &midi->out_triggered)) | ||
256 | return; | ||
257 | |||
258 | snd_rawmidi_receive(substream, data, length); | ||
259 | } | ||
260 | |||
261 | static void f_midi_handle_out_data(struct usb_ep *ep, struct usb_request *req) | ||
262 | { | ||
263 | unsigned int i; | ||
264 | u8 *buf = req->buf; | ||
265 | |||
266 | for (i = 0; i + 3 < req->actual; i += 4) | ||
267 | if (buf[i] != 0) { | ||
268 | int cable = buf[i] >> 4; | ||
269 | int length = f_midi_cin_length[buf[i] & 0x0f]; | ||
270 | f_midi_read_data(ep, cable, &buf[i + 1], length); | ||
271 | } | ||
272 | } | ||
273 | |||
274 | static void | ||
275 | f_midi_complete(struct usb_ep *ep, struct usb_request *req) | ||
276 | { | ||
277 | struct f_midi *midi = ep->driver_data; | ||
278 | struct usb_composite_dev *cdev = midi->func.config->cdev; | ||
279 | int status = req->status; | ||
280 | |||
281 | switch (status) { | ||
282 | case 0: /* normal completion */ | ||
283 | if (ep == midi->out_ep) { | ||
284 | /* We received stuff. req is queued again, below */ | ||
285 | f_midi_handle_out_data(ep, req); | ||
286 | } else if (ep == midi->in_ep) { | ||
287 | /* Our transmit completed. See if there's more to go. | ||
288 | * f_midi_transmit eats req, don't queue it again. */ | ||
289 | f_midi_transmit(midi, req); | ||
290 | return; | ||
291 | } | ||
292 | break; | ||
293 | |||
294 | /* this endpoint is normally active while we're configured */ | ||
295 | case -ECONNABORTED: /* hardware forced ep reset */ | ||
296 | case -ECONNRESET: /* request dequeued */ | ||
297 | case -ESHUTDOWN: /* disconnect from host */ | ||
298 | VDBG(cdev, "%s gone (%d), %d/%d\n", ep->name, status, | ||
299 | req->actual, req->length); | ||
300 | if (ep == midi->out_ep) | ||
301 | f_midi_handle_out_data(ep, req); | ||
302 | |||
303 | free_ep_req(ep, req); | ||
304 | return; | ||
305 | |||
306 | case -EOVERFLOW: /* buffer overrun on read means that | ||
307 | * we didn't provide a big enough buffer. | ||
308 | */ | ||
309 | default: | ||
310 | DBG(cdev, "%s complete --> %d, %d/%d\n", ep->name, | ||
311 | status, req->actual, req->length); | ||
312 | break; | ||
313 | case -EREMOTEIO: /* short read */ | ||
314 | break; | ||
315 | } | ||
316 | |||
317 | status = usb_ep_queue(ep, req, GFP_ATOMIC); | ||
318 | if (status) { | ||
319 | ERROR(cdev, "kill %s: resubmit %d bytes --> %d\n", | ||
320 | ep->name, req->length, status); | ||
321 | usb_ep_set_halt(ep); | ||
322 | /* FIXME recover later ... somehow */ | ||
323 | } | ||
324 | } | ||
325 | |||
326 | static int f_midi_start_ep(struct f_midi *midi, | ||
327 | struct usb_function *f, | ||
328 | struct usb_ep *ep) | ||
329 | { | ||
330 | int err; | ||
331 | struct usb_composite_dev *cdev = f->config->cdev; | ||
332 | |||
333 | if (ep->driver_data) | ||
334 | usb_ep_disable(ep); | ||
335 | |||
336 | err = config_ep_by_speed(midi->gadget, f, ep); | ||
337 | if (err) { | ||
338 | ERROR(cdev, "can't configure %s: %d\n", ep->name, err); | ||
339 | return err; | ||
340 | } | ||
341 | |||
342 | err = usb_ep_enable(ep); | ||
343 | if (err) { | ||
344 | ERROR(cdev, "can't start %s: %d\n", ep->name, err); | ||
345 | return err; | ||
346 | } | ||
347 | |||
348 | ep->driver_data = midi; | ||
349 | |||
350 | return 0; | ||
351 | } | ||
352 | |||
353 | static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | ||
354 | { | ||
355 | struct f_midi *midi = func_to_midi(f); | ||
356 | struct usb_composite_dev *cdev = f->config->cdev; | ||
357 | unsigned i; | ||
358 | int err; | ||
359 | |||
360 | err = f_midi_start_ep(midi, f, midi->in_ep); | ||
361 | if (err) | ||
362 | return err; | ||
363 | |||
364 | err = f_midi_start_ep(midi, f, midi->out_ep); | ||
365 | if (err) | ||
366 | return err; | ||
367 | |||
368 | if (midi->out_ep->driver_data) | ||
369 | usb_ep_disable(midi->out_ep); | ||
370 | |||
371 | err = config_ep_by_speed(midi->gadget, f, midi->out_ep); | ||
372 | if (err) { | ||
373 | ERROR(cdev, "can't configure %s: %d\n", | ||
374 | midi->out_ep->name, err); | ||
375 | return err; | ||
376 | } | ||
377 | |||
378 | err = usb_ep_enable(midi->out_ep); | ||
379 | if (err) { | ||
380 | ERROR(cdev, "can't start %s: %d\n", | ||
381 | midi->out_ep->name, err); | ||
382 | return err; | ||
383 | } | ||
384 | |||
385 | midi->out_ep->driver_data = midi; | ||
386 | |||
387 | /* allocate a bunch of read buffers and queue them all at once. */ | ||
388 | for (i = 0; i < midi->qlen && err == 0; i++) { | ||
389 | struct usb_request *req = | ||
390 | alloc_ep_req(midi->out_ep, midi->buflen); | ||
391 | if (req == NULL) | ||
392 | return -ENOMEM; | ||
393 | |||
394 | req->complete = f_midi_complete; | ||
395 | err = usb_ep_queue(midi->out_ep, req, GFP_ATOMIC); | ||
396 | if (err) { | ||
397 | ERROR(midi, "%s queue req: %d\n", | ||
398 | midi->out_ep->name, err); | ||
399 | } | ||
400 | } | ||
401 | |||
402 | return 0; | ||
403 | } | ||
404 | |||
405 | static void f_midi_disable(struct usb_function *f) | ||
406 | { | ||
407 | struct f_midi *midi = func_to_midi(f); | ||
408 | struct usb_composite_dev *cdev = f->config->cdev; | ||
409 | |||
410 | DBG(cdev, "disable\n"); | ||
411 | |||
412 | /* | ||
413 | * just disable endpoints, forcing completion of pending i/o. | ||
414 | * all our completion handlers free their requests in this case. | ||
415 | */ | ||
416 | usb_ep_disable(midi->in_ep); | ||
417 | usb_ep_disable(midi->out_ep); | ||
418 | } | ||
419 | |||
420 | static void f_midi_unbind(struct usb_configuration *c, struct usb_function *f) | ||
421 | { | ||
422 | struct usb_composite_dev *cdev = f->config->cdev; | ||
423 | struct f_midi *midi = func_to_midi(f); | ||
424 | struct snd_card *card; | ||
425 | |||
426 | DBG(cdev, "unbind\n"); | ||
427 | |||
428 | /* just to be sure */ | ||
429 | f_midi_disable(f); | ||
430 | |||
431 | card = midi->card; | ||
432 | midi->card = NULL; | ||
433 | if (card) | ||
434 | snd_card_free(card); | ||
435 | |||
436 | kfree(midi->id); | ||
437 | midi->id = NULL; | ||
438 | |||
439 | usb_free_descriptors(f->descriptors); | ||
440 | kfree(midi); | ||
441 | } | ||
442 | |||
443 | static int f_midi_snd_free(struct snd_device *device) | ||
444 | { | ||
445 | return 0; | ||
446 | } | ||
447 | |||
448 | static void f_midi_transmit_packet(struct usb_request *req, uint8_t p0, | ||
449 | uint8_t p1, uint8_t p2, uint8_t p3) | ||
450 | { | ||
451 | unsigned length = req->length; | ||
452 | u8 *buf = (u8 *)req->buf + length; | ||
453 | |||
454 | buf[0] = p0; | ||
455 | buf[1] = p1; | ||
456 | buf[2] = p2; | ||
457 | buf[3] = p3; | ||
458 | req->length = length + 4; | ||
459 | } | ||
460 | |||
461 | /* | ||
462 | * Converts MIDI commands to USB MIDI packets. | ||
463 | */ | ||
464 | static void f_midi_transmit_byte(struct usb_request *req, | ||
465 | struct gmidi_in_port *port, uint8_t b) | ||
466 | { | ||
467 | uint8_t p0 = port->cable << 4; | ||
468 | |||
469 | if (b >= 0xf8) { | ||
470 | f_midi_transmit_packet(req, p0 | 0x0f, b, 0, 0); | ||
471 | } else if (b >= 0xf0) { | ||
472 | switch (b) { | ||
473 | case 0xf0: | ||
474 | port->data[0] = b; | ||
475 | port->state = STATE_SYSEX_1; | ||
476 | break; | ||
477 | case 0xf1: | ||
478 | case 0xf3: | ||
479 | port->data[0] = b; | ||
480 | port->state = STATE_1PARAM; | ||
481 | break; | ||
482 | case 0xf2: | ||
483 | port->data[0] = b; | ||
484 | port->state = STATE_2PARAM_1; | ||
485 | break; | ||
486 | case 0xf4: | ||
487 | case 0xf5: | ||
488 | port->state = STATE_UNKNOWN; | ||
489 | break; | ||
490 | case 0xf6: | ||
491 | f_midi_transmit_packet(req, p0 | 0x05, 0xf6, 0, 0); | ||
492 | port->state = STATE_UNKNOWN; | ||
493 | break; | ||
494 | case 0xf7: | ||
495 | switch (port->state) { | ||
496 | case STATE_SYSEX_0: | ||
497 | f_midi_transmit_packet(req, | ||
498 | p0 | 0x05, 0xf7, 0, 0); | ||
499 | break; | ||
500 | case STATE_SYSEX_1: | ||
501 | f_midi_transmit_packet(req, | ||
502 | p0 | 0x06, port->data[0], 0xf7, 0); | ||
503 | break; | ||
504 | case STATE_SYSEX_2: | ||
505 | f_midi_transmit_packet(req, | ||
506 | p0 | 0x07, port->data[0], | ||
507 | port->data[1], 0xf7); | ||
508 | break; | ||
509 | } | ||
510 | port->state = STATE_UNKNOWN; | ||
511 | break; | ||
512 | } | ||
513 | } else if (b >= 0x80) { | ||
514 | port->data[0] = b; | ||
515 | if (b >= 0xc0 && b <= 0xdf) | ||
516 | port->state = STATE_1PARAM; | ||
517 | else | ||
518 | port->state = STATE_2PARAM_1; | ||
519 | } else { /* b < 0x80 */ | ||
520 | switch (port->state) { | ||
521 | case STATE_1PARAM: | ||
522 | if (port->data[0] < 0xf0) { | ||
523 | p0 |= port->data[0] >> 4; | ||
524 | } else { | ||
525 | p0 |= 0x02; | ||
526 | port->state = STATE_UNKNOWN; | ||
527 | } | ||
528 | f_midi_transmit_packet(req, p0, port->data[0], b, 0); | ||
529 | break; | ||
530 | case STATE_2PARAM_1: | ||
531 | port->data[1] = b; | ||
532 | port->state = STATE_2PARAM_2; | ||
533 | break; | ||
534 | case STATE_2PARAM_2: | ||
535 | if (port->data[0] < 0xf0) { | ||
536 | p0 |= port->data[0] >> 4; | ||
537 | port->state = STATE_2PARAM_1; | ||
538 | } else { | ||
539 | p0 |= 0x03; | ||
540 | port->state = STATE_UNKNOWN; | ||
541 | } | ||
542 | f_midi_transmit_packet(req, | ||
543 | p0, port->data[0], port->data[1], b); | ||
544 | break; | ||
545 | case STATE_SYSEX_0: | ||
546 | port->data[0] = b; | ||
547 | port->state = STATE_SYSEX_1; | ||
548 | break; | ||
549 | case STATE_SYSEX_1: | ||
550 | port->data[1] = b; | ||
551 | port->state = STATE_SYSEX_2; | ||
552 | break; | ||
553 | case STATE_SYSEX_2: | ||
554 | f_midi_transmit_packet(req, | ||
555 | p0 | 0x04, port->data[0], port->data[1], b); | ||
556 | port->state = STATE_SYSEX_0; | ||
557 | break; | ||
558 | } | ||
559 | } | ||
560 | } | ||
561 | |||
562 | static void f_midi_transmit(struct f_midi *midi, struct usb_request *req) | ||
563 | { | ||
564 | struct usb_ep *ep = midi->in_ep; | ||
565 | int i; | ||
566 | |||
567 | if (!ep) | ||
568 | return; | ||
569 | |||
570 | if (!req) | ||
571 | req = alloc_ep_req(ep, midi->buflen); | ||
572 | |||
573 | if (!req) { | ||
574 | ERROR(midi, "gmidi_transmit: alloc_ep_request failed\n"); | ||
575 | return; | ||
576 | } | ||
577 | req->length = 0; | ||
578 | req->complete = f_midi_complete; | ||
579 | |||
580 | for (i = 0; i < MAX_PORTS; i++) { | ||
581 | struct gmidi_in_port *port = midi->in_port[i]; | ||
582 | struct snd_rawmidi_substream *substream = midi->in_substream[i]; | ||
583 | |||
584 | if (!port || !port->active || !substream) | ||
585 | continue; | ||
586 | |||
587 | while (req->length + 3 < midi->buflen) { | ||
588 | uint8_t b; | ||
589 | if (snd_rawmidi_transmit(substream, &b, 1) != 1) { | ||
590 | port->active = 0; | ||
591 | break; | ||
592 | } | ||
593 | f_midi_transmit_byte(req, port, b); | ||
594 | } | ||
595 | } | ||
596 | |||
597 | if (req->length > 0) | ||
598 | usb_ep_queue(ep, req, GFP_ATOMIC); | ||
599 | else | ||
600 | free_ep_req(ep, req); | ||
601 | } | ||
602 | |||
603 | static void f_midi_in_tasklet(unsigned long data) | ||
604 | { | ||
605 | struct f_midi *midi = (struct f_midi *) data; | ||
606 | f_midi_transmit(midi, NULL); | ||
607 | } | ||
608 | |||
609 | static int f_midi_in_open(struct snd_rawmidi_substream *substream) | ||
610 | { | ||
611 | struct f_midi *midi = substream->rmidi->private_data; | ||
612 | |||
613 | if (!midi->in_port[substream->number]) | ||
614 | return -EINVAL; | ||
615 | |||
616 | VDBG(midi, "%s()\n", __func__); | ||
617 | midi->in_substream[substream->number] = substream; | ||
618 | midi->in_port[substream->number]->state = STATE_UNKNOWN; | ||
619 | return 0; | ||
620 | } | ||
621 | |||
622 | static int f_midi_in_close(struct snd_rawmidi_substream *substream) | ||
623 | { | ||
624 | struct f_midi *midi = substream->rmidi->private_data; | ||
625 | |||
626 | VDBG(midi, "%s()\n", __func__); | ||
627 | return 0; | ||
628 | } | ||
629 | |||
630 | static void f_midi_in_trigger(struct snd_rawmidi_substream *substream, int up) | ||
631 | { | ||
632 | struct f_midi *midi = substream->rmidi->private_data; | ||
633 | |||
634 | if (!midi->in_port[substream->number]) | ||
635 | return; | ||
636 | |||
637 | VDBG(midi, "%s() %d\n", __func__, up); | ||
638 | midi->in_port[substream->number]->active = up; | ||
639 | if (up) | ||
640 | tasklet_hi_schedule(&midi->tasklet); | ||
641 | } | ||
642 | |||
643 | static int f_midi_out_open(struct snd_rawmidi_substream *substream) | ||
644 | { | ||
645 | struct f_midi *midi = substream->rmidi->private_data; | ||
646 | |||
647 | if (substream->number >= MAX_PORTS) | ||
648 | return -EINVAL; | ||
649 | |||
650 | VDBG(midi, "%s()\n", __func__); | ||
651 | midi->out_substream[substream->number] = substream; | ||
652 | return 0; | ||
653 | } | ||
654 | |||
655 | static int f_midi_out_close(struct snd_rawmidi_substream *substream) | ||
656 | { | ||
657 | struct f_midi *midi = substream->rmidi->private_data; | ||
658 | |||
659 | VDBG(midi, "%s()\n", __func__); | ||
660 | return 0; | ||
661 | } | ||
662 | |||
663 | static void f_midi_out_trigger(struct snd_rawmidi_substream *substream, int up) | ||
664 | { | ||
665 | struct f_midi *midi = substream->rmidi->private_data; | ||
666 | |||
667 | VDBG(midi, "%s()\n", __func__); | ||
668 | |||
669 | if (up) | ||
670 | set_bit(substream->number, &midi->out_triggered); | ||
671 | else | ||
672 | clear_bit(substream->number, &midi->out_triggered); | ||
673 | } | ||
674 | |||
675 | static struct snd_rawmidi_ops gmidi_in_ops = { | ||
676 | .open = f_midi_in_open, | ||
677 | .close = f_midi_in_close, | ||
678 | .trigger = f_midi_in_trigger, | ||
679 | }; | ||
680 | |||
681 | static struct snd_rawmidi_ops gmidi_out_ops = { | ||
682 | .open = f_midi_out_open, | ||
683 | .close = f_midi_out_close, | ||
684 | .trigger = f_midi_out_trigger | ||
685 | }; | ||
686 | |||
687 | /* register as a sound "card" */ | ||
688 | static int f_midi_register_card(struct f_midi *midi) | ||
689 | { | ||
690 | struct snd_card *card; | ||
691 | struct snd_rawmidi *rmidi; | ||
692 | int err; | ||
693 | static struct snd_device_ops ops = { | ||
694 | .dev_free = f_midi_snd_free, | ||
695 | }; | ||
696 | |||
697 | err = snd_card_create(midi->index, midi->id, THIS_MODULE, 0, &card); | ||
698 | if (err < 0) { | ||
699 | ERROR(midi, "snd_card_create() failed\n"); | ||
700 | goto fail; | ||
701 | } | ||
702 | midi->card = card; | ||
703 | |||
704 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, midi, &ops); | ||
705 | if (err < 0) { | ||
706 | ERROR(midi, "snd_device_new() failed: error %d\n", err); | ||
707 | goto fail; | ||
708 | } | ||
709 | |||
710 | strcpy(card->driver, f_midi_longname); | ||
711 | strcpy(card->longname, f_midi_longname); | ||
712 | strcpy(card->shortname, f_midi_shortname); | ||
713 | |||
714 | /* Set up rawmidi */ | ||
715 | snd_component_add(card, "MIDI"); | ||
716 | err = snd_rawmidi_new(card, card->longname, 0, | ||
717 | midi->out_ports, midi->in_ports, &rmidi); | ||
718 | if (err < 0) { | ||
719 | ERROR(midi, "snd_rawmidi_new() failed: error %d\n", err); | ||
720 | goto fail; | ||
721 | } | ||
722 | midi->rmidi = rmidi; | ||
723 | strcpy(rmidi->name, card->shortname); | ||
724 | rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | | ||
725 | SNDRV_RAWMIDI_INFO_INPUT | | ||
726 | SNDRV_RAWMIDI_INFO_DUPLEX; | ||
727 | rmidi->private_data = midi; | ||
728 | |||
729 | /* | ||
730 | * Yes, rawmidi OUTPUT = USB IN, and rawmidi INPUT = USB OUT. | ||
731 | * It's an upside-down world being a gadget. | ||
732 | */ | ||
733 | snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &gmidi_in_ops); | ||
734 | snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &gmidi_out_ops); | ||
735 | |||
736 | snd_card_set_dev(card, &midi->gadget->dev); | ||
737 | |||
738 | /* register it - we're ready to go */ | ||
739 | err = snd_card_register(card); | ||
740 | if (err < 0) { | ||
741 | ERROR(midi, "snd_card_register() failed\n"); | ||
742 | goto fail; | ||
743 | } | ||
744 | |||
745 | VDBG(midi, "%s() finished ok\n", __func__); | ||
746 | return 0; | ||
747 | |||
748 | fail: | ||
749 | if (midi->card) { | ||
750 | snd_card_free(midi->card); | ||
751 | midi->card = NULL; | ||
752 | } | ||
753 | return err; | ||
754 | } | ||
755 | |||
756 | /* MIDI function driver setup/binding */ | ||
757 | |||
758 | static int __init | ||
759 | f_midi_bind(struct usb_configuration *c, struct usb_function *f) | ||
760 | { | ||
761 | struct usb_descriptor_header *midi_function[(MAX_PORTS * 2) + 12]; | ||
762 | struct usb_midi_in_jack_descriptor jack_in_ext_desc[MAX_PORTS]; | ||
763 | struct usb_midi_out_jack_descriptor_1 jack_out_ext_desc[MAX_PORTS]; | ||
764 | struct usb_composite_dev *cdev = c->cdev; | ||
765 | struct f_midi *midi = func_to_midi(f); | ||
766 | int status, n, jack = 1, i = 0; | ||
767 | |||
768 | /* maybe allocate device-global string ID */ | ||
769 | if (midi_string_defs[0].id == 0) { | ||
770 | status = usb_string_id(c->cdev); | ||
771 | if (status < 0) | ||
772 | goto fail; | ||
773 | midi_string_defs[0].id = status; | ||
774 | } | ||
775 | |||
776 | /* We have two interfaces, AudioControl and MIDIStreaming */ | ||
777 | status = usb_interface_id(c, f); | ||
778 | if (status < 0) | ||
779 | goto fail; | ||
780 | ac_interface_desc.bInterfaceNumber = status; | ||
781 | |||
782 | status = usb_interface_id(c, f); | ||
783 | if (status < 0) | ||
784 | goto fail; | ||
785 | ms_interface_desc.bInterfaceNumber = status; | ||
786 | ac_header_desc.baInterfaceNr[0] = status; | ||
787 | |||
788 | status = -ENODEV; | ||
789 | |||
790 | /* allocate instance-specific endpoints */ | ||
791 | midi->in_ep = usb_ep_autoconfig(cdev->gadget, &bulk_in_desc); | ||
792 | if (!midi->in_ep) | ||
793 | goto fail; | ||
794 | midi->in_ep->driver_data = cdev; /* claim */ | ||
795 | |||
796 | midi->out_ep = usb_ep_autoconfig(cdev->gadget, &bulk_out_desc); | ||
797 | if (!midi->out_ep) | ||
798 | goto fail; | ||
799 | midi->out_ep->driver_data = cdev; /* claim */ | ||
800 | |||
801 | /* | ||
802 | * construct the function's descriptor set. As the number of | ||
803 | * input and output MIDI ports is configurable, we have to do | ||
804 | * it that way. | ||
805 | */ | ||
806 | |||
807 | /* add the headers - these are always the same */ | ||
808 | midi_function[i++] = (struct usb_descriptor_header *) &ac_interface_desc; | ||
809 | midi_function[i++] = (struct usb_descriptor_header *) &ac_header_desc; | ||
810 | midi_function[i++] = (struct usb_descriptor_header *) &ms_interface_desc; | ||
811 | |||
812 | /* calculate the header's wTotalLength */ | ||
813 | n = USB_DT_MS_HEADER_SIZE | ||
814 | + (1 + midi->in_ports) * USB_DT_MIDI_IN_SIZE | ||
815 | + (1 + midi->out_ports) * USB_DT_MIDI_OUT_SIZE(1); | ||
816 | ms_header_desc.wTotalLength = cpu_to_le16(n); | ||
817 | |||
818 | midi_function[i++] = (struct usb_descriptor_header *) &ms_header_desc; | ||
819 | |||
820 | /* we have one embedded IN jack */ | ||
821 | jack_in_emb_desc.bJackID = jack++; | ||
822 | midi_function[i++] = (struct usb_descriptor_header *) &jack_in_emb_desc; | ||
823 | |||
824 | /* and a dynamic amount of external IN jacks */ | ||
825 | for (n = 0; n < midi->in_ports; n++) { | ||
826 | struct usb_midi_in_jack_descriptor *ext = &jack_in_ext_desc[n]; | ||
827 | |||
828 | ext->bLength = USB_DT_MIDI_IN_SIZE; | ||
829 | ext->bDescriptorType = USB_DT_CS_INTERFACE; | ||
830 | ext->bDescriptorSubtype = USB_MS_MIDI_IN_JACK; | ||
831 | ext->bJackType = USB_MS_EXTERNAL; | ||
832 | ext->bJackID = jack++; | ||
833 | ext->iJack = 0; | ||
834 | |||
835 | midi_function[i++] = (struct usb_descriptor_header *) ext; | ||
836 | } | ||
837 | |||
838 | /* one embedded OUT jack ... */ | ||
839 | jack_out_emb_desc.bLength = USB_DT_MIDI_OUT_SIZE(midi->in_ports); | ||
840 | jack_out_emb_desc.bJackID = jack++; | ||
841 | jack_out_emb_desc.bNrInputPins = midi->in_ports; | ||
842 | /* ... which referencess all external IN jacks */ | ||
843 | for (n = 0; n < midi->in_ports; n++) { | ||
844 | jack_out_emb_desc.pins[n].baSourceID = jack_in_ext_desc[n].bJackID; | ||
845 | jack_out_emb_desc.pins[n].baSourcePin = 1; | ||
846 | } | ||
847 | |||
848 | midi_function[i++] = (struct usb_descriptor_header *) &jack_out_emb_desc; | ||
849 | |||
850 | /* and multiple external OUT jacks ... */ | ||
851 | for (n = 0; n < midi->out_ports; n++) { | ||
852 | struct usb_midi_out_jack_descriptor_1 *ext = &jack_out_ext_desc[n]; | ||
853 | int m; | ||
854 | |||
855 | ext->bLength = USB_DT_MIDI_OUT_SIZE(1); | ||
856 | ext->bDescriptorType = USB_DT_CS_INTERFACE; | ||
857 | ext->bDescriptorSubtype = USB_MS_MIDI_OUT_JACK; | ||
858 | ext->bJackType = USB_MS_EXTERNAL; | ||
859 | ext->bJackID = jack++; | ||
860 | ext->bNrInputPins = 1; | ||
861 | ext->iJack = 0; | ||
862 | /* ... which all reference the same embedded IN jack */ | ||
863 | for (m = 0; m < midi->out_ports; m++) { | ||
864 | ext->pins[m].baSourceID = jack_in_emb_desc.bJackID; | ||
865 | ext->pins[m].baSourcePin = 1; | ||
866 | } | ||
867 | |||
868 | midi_function[i++] = (struct usb_descriptor_header *) ext; | ||
869 | } | ||
870 | |||
871 | /* configure the endpoint descriptors ... */ | ||
872 | ms_out_desc.bLength = USB_DT_MS_ENDPOINT_SIZE(midi->in_ports); | ||
873 | ms_out_desc.bNumEmbMIDIJack = midi->in_ports; | ||
874 | for (n = 0; n < midi->in_ports; n++) | ||
875 | ms_out_desc.baAssocJackID[n] = jack_in_emb_desc.bJackID; | ||
876 | |||
877 | ms_in_desc.bLength = USB_DT_MS_ENDPOINT_SIZE(midi->out_ports); | ||
878 | ms_in_desc.bNumEmbMIDIJack = midi->out_ports; | ||
879 | for (n = 0; n < midi->out_ports; n++) | ||
880 | ms_in_desc.baAssocJackID[n] = jack_out_emb_desc.bJackID; | ||
881 | |||
882 | /* ... and add them to the list */ | ||
883 | midi_function[i++] = (struct usb_descriptor_header *) &bulk_out_desc; | ||
884 | midi_function[i++] = (struct usb_descriptor_header *) &ms_out_desc; | ||
885 | midi_function[i++] = (struct usb_descriptor_header *) &bulk_in_desc; | ||
886 | midi_function[i++] = (struct usb_descriptor_header *) &ms_in_desc; | ||
887 | midi_function[i++] = NULL; | ||
888 | |||
889 | /* | ||
890 | * support all relevant hardware speeds... we expect that when | ||
891 | * hardware is dual speed, all bulk-capable endpoints work at | ||
892 | * both speeds | ||
893 | */ | ||
894 | /* copy descriptors, and track endpoint copies */ | ||
895 | if (gadget_is_dualspeed(c->cdev->gadget)) { | ||
896 | c->highspeed = true; | ||
897 | bulk_in_desc.wMaxPacketSize = cpu_to_le16(512); | ||
898 | bulk_out_desc.wMaxPacketSize = cpu_to_le16(512); | ||
899 | f->hs_descriptors = usb_copy_descriptors(midi_function); | ||
900 | } else { | ||
901 | f->descriptors = usb_copy_descriptors(midi_function); | ||
902 | } | ||
903 | |||
904 | return 0; | ||
905 | |||
906 | fail: | ||
907 | /* we might as well release our claims on endpoints */ | ||
908 | if (midi->out_ep) | ||
909 | midi->out_ep->driver_data = NULL; | ||
910 | if (midi->in_ep) | ||
911 | midi->in_ep->driver_data = NULL; | ||
912 | |||
913 | ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); | ||
914 | |||
915 | return status; | ||
916 | } | ||
917 | |||
918 | /** | ||
919 | * f_midi_bind_config - add USB MIDI function to a configuration | ||
920 | * @c: the configuration to supcard the USB audio function | ||
921 | * @index: the soundcard index to use for the ALSA device creation | ||
922 | * @id: the soundcard id to use for the ALSA device creation | ||
923 | * @buflen: the buffer length to use | ||
924 | * @qlen the number of read requests to pre-allocate | ||
925 | * Context: single threaded during gadget setup | ||
926 | * | ||
927 | * Returns zero on success, else negative errno. | ||
928 | */ | ||
929 | int __init f_midi_bind_config(struct usb_configuration *c, | ||
930 | int index, char *id, | ||
931 | unsigned int in_ports, | ||
932 | unsigned int out_ports, | ||
933 | unsigned int buflen, | ||
934 | unsigned int qlen) | ||
935 | { | ||
936 | struct f_midi *midi; | ||
937 | int status, i; | ||
938 | |||
939 | /* sanity check */ | ||
940 | if (in_ports > MAX_PORTS || out_ports > MAX_PORTS) | ||
941 | return -EINVAL; | ||
942 | |||
943 | /* allocate and initialize one new instance */ | ||
944 | midi = kzalloc(sizeof *midi, GFP_KERNEL); | ||
945 | if (!midi) { | ||
946 | status = -ENOMEM; | ||
947 | goto fail; | ||
948 | } | ||
949 | |||
950 | for (i = 0; i < in_ports; i++) { | ||
951 | struct gmidi_in_port *port = kzalloc(sizeof(*port), GFP_KERNEL); | ||
952 | if (!port) { | ||
953 | status = -ENOMEM; | ||
954 | goto setup_fail; | ||
955 | } | ||
956 | |||
957 | port->midi = midi; | ||
958 | port->active = 0; | ||
959 | port->cable = i; | ||
960 | midi->in_port[i] = port; | ||
961 | } | ||
962 | |||
963 | midi->gadget = c->cdev->gadget; | ||
964 | tasklet_init(&midi->tasklet, f_midi_in_tasklet, (unsigned long) midi); | ||
965 | |||
966 | /* set up ALSA midi devices */ | ||
967 | midi->in_ports = in_ports; | ||
968 | midi->out_ports = out_ports; | ||
969 | status = f_midi_register_card(midi); | ||
970 | if (status < 0) | ||
971 | goto setup_fail; | ||
972 | |||
973 | midi->func.name = "gmidi function"; | ||
974 | midi->func.strings = midi_strings; | ||
975 | midi->func.bind = f_midi_bind; | ||
976 | midi->func.unbind = f_midi_unbind; | ||
977 | midi->func.set_alt = f_midi_set_alt; | ||
978 | midi->func.disable = f_midi_disable; | ||
979 | |||
980 | midi->id = kstrdup(id, GFP_KERNEL); | ||
981 | midi->index = index; | ||
982 | midi->buflen = buflen; | ||
983 | midi->qlen = qlen; | ||
984 | |||
985 | status = usb_add_function(c, &midi->func); | ||
986 | if (status) | ||
987 | goto setup_fail; | ||
988 | |||
989 | return 0; | ||
990 | |||
991 | setup_fail: | ||
992 | for (--i; i >= 0; i--) | ||
993 | kfree(midi->in_port[i]); | ||
994 | kfree(midi); | ||
995 | fail: | ||
996 | return status; | ||
997 | } | ||
998 | |||
diff --git a/drivers/usb/gadget/f_ncm.c b/drivers/usb/gadget/f_ncm.c index ae69ed7e6b99..aab8eded045b 100644 --- a/drivers/usb/gadget/f_ncm.c +++ b/drivers/usb/gadget/f_ncm.c | |||
@@ -13,15 +13,6 @@ | |||
13 | * it under the terms of the GNU General Public License as published by | 13 | * it under the terms of the GNU General Public License as published by |
14 | * the Free Software Foundation; either version 2 of the License, or | 14 | * the Free Software Foundation; either version 2 of the License, or |
15 | * (at your option) any later version. | 15 | * (at your option) any later version. |
16 | * | ||
17 | * This program is distributed in the hope that it will be useful, | ||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | * GNU General Public License for more details. | ||
21 | * | ||
22 | * You should have received a copy of the GNU General Public License | ||
23 | * along with this program; if not, write to the Free Software | ||
24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
25 | */ | 16 | */ |
26 | 17 | ||
27 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c index 394502abeb96..e3f74bf5da2d 100644 --- a/drivers/usb/gadget/f_obex.c +++ b/drivers/usb/gadget/f_obex.c | |||
@@ -10,15 +10,6 @@ | |||
10 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or | 11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. | 12 | * (at your option) any later version. |
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | */ | 13 | */ |
23 | 14 | ||
24 | /* #define VERBOSE_DEBUG */ | 15 | /* #define VERBOSE_DEBUG */ |
diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c index 8f3eab1af885..349077033338 100644 --- a/drivers/usb/gadget/f_phonet.c +++ b/drivers/usb/gadget/f_phonet.c | |||
@@ -8,16 +8,6 @@ | |||
8 | * This program is free software; you can redistribute it and/or | 8 | * This program is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU General Public License | 9 | * modify it under the terms of the GNU General Public License |
10 | * version 2 as published by the Free Software Foundation. | 10 | * version 2 as published by the Free Software Foundation. |
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but | ||
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Â See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
20 | * 02110-1301 USA | ||
21 | */ | 11 | */ |
22 | 12 | ||
23 | #include <linux/mm.h> | 13 | #include <linux/mm.h> |
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c index 3ea4666be3d0..704d1d94f72a 100644 --- a/drivers/usb/gadget/f_rndis.c +++ b/drivers/usb/gadget/f_rndis.c | |||
@@ -11,15 +11,6 @@ | |||
11 | * it under the terms of the GNU General Public License as published by | 11 | * it under the terms of the GNU General Public License as published by |
12 | * the Free Software Foundation; either version 2 of the License, or | 12 | * the Free Software Foundation; either version 2 of the License, or |
13 | * (at your option) any later version. | 13 | * (at your option) any later version. |
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | */ | 14 | */ |
24 | 15 | ||
25 | /* #define VERBOSE_DEBUG */ | 16 | /* #define VERBOSE_DEBUG */ |
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c index e18b4f520951..168906d2b5d4 100644 --- a/drivers/usb/gadget/f_sourcesink.c +++ b/drivers/usb/gadget/f_sourcesink.c | |||
@@ -8,15 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | 11 | */ |
21 | 12 | ||
22 | /* #define VERBOSE_DEBUG */ | 13 | /* #define VERBOSE_DEBUG */ |
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c index 3dc53754ab60..c1540648125a 100644 --- a/drivers/usb/gadget/f_subset.c +++ b/drivers/usb/gadget/f_subset.c | |||
@@ -8,15 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | 11 | */ |
21 | 12 | ||
22 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c index 7a8b9aa4aea5..2022fe492148 100644 --- a/drivers/usb/gadget/f_uvc.c +++ b/drivers/usb/gadget/f_uvc.c | |||
@@ -8,7 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
11 | * | ||
12 | */ | 11 | */ |
13 | 12 | ||
14 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
diff --git a/drivers/usb/gadget/f_uvc.h b/drivers/usb/gadget/f_uvc.h index e18a6636c283..abf832935134 100644 --- a/drivers/usb/gadget/f_uvc.h +++ b/drivers/usb/gadget/f_uvc.h | |||
@@ -8,7 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
11 | * | ||
12 | */ | 11 | */ |
13 | 12 | ||
14 | #ifndef _F_UVC_H_ | 13 | #ifndef _F_UVC_H_ |
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index 639e14a2fd15..3ac4f51cd0bb 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c | |||
@@ -69,8 +69,7 @@ | |||
69 | * each LUN would be settable independently as a disk drive or a CD-ROM | 69 | * each LUN would be settable independently as a disk drive or a CD-ROM |
70 | * drive, but currently all LUNs have to be the same type. The CD-ROM | 70 | * drive, but currently all LUNs have to be the same type. The CD-ROM |
71 | * emulation includes a single data track and no audio tracks; hence there | 71 | * emulation includes a single data track and no audio tracks; hence there |
72 | * need be only one backing file per LUN. Note also that the CD-ROM block | 72 | * need be only one backing file per LUN. |
73 | * length is set to 512 rather than the more common value 2048. | ||
74 | * | 73 | * |
75 | * Requirements are modest; only a bulk-in and a bulk-out endpoint are | 74 | * Requirements are modest; only a bulk-in and a bulk-out endpoint are |
76 | * needed (an interrupt-out endpoint is also needed for CBI). The memory | 75 | * needed (an interrupt-out endpoint is also needed for CBI). The memory |
@@ -461,7 +460,6 @@ struct fsg_dev { | |||
461 | 460 | ||
462 | struct fsg_buffhd *next_buffhd_to_fill; | 461 | struct fsg_buffhd *next_buffhd_to_fill; |
463 | struct fsg_buffhd *next_buffhd_to_drain; | 462 | struct fsg_buffhd *next_buffhd_to_drain; |
464 | struct fsg_buffhd buffhds[FSG_NUM_BUFFERS]; | ||
465 | 463 | ||
466 | int thread_wakeup_needed; | 464 | int thread_wakeup_needed; |
467 | struct completion thread_notifier; | 465 | struct completion thread_notifier; |
@@ -488,6 +486,8 @@ struct fsg_dev { | |||
488 | unsigned int nluns; | 486 | unsigned int nluns; |
489 | struct fsg_lun *luns; | 487 | struct fsg_lun *luns; |
490 | struct fsg_lun *curlun; | 488 | struct fsg_lun *curlun; |
489 | /* Must be the last entry */ | ||
490 | struct fsg_buffhd buffhds[]; | ||
491 | }; | 491 | }; |
492 | 492 | ||
493 | typedef void (*fsg_routine_t)(struct fsg_dev *); | 493 | typedef void (*fsg_routine_t)(struct fsg_dev *); |
@@ -586,7 +586,19 @@ dev_qualifier = { | |||
586 | .bNumConfigurations = 1, | 586 | .bNumConfigurations = 1, |
587 | }; | 587 | }; |
588 | 588 | ||
589 | static int populate_bos(struct fsg_dev *fsg, u8 *buf) | ||
590 | { | ||
591 | memcpy(buf, &fsg_bos_desc, USB_DT_BOS_SIZE); | ||
592 | buf += USB_DT_BOS_SIZE; | ||
593 | |||
594 | memcpy(buf, &fsg_ext_cap_desc, USB_DT_USB_EXT_CAP_SIZE); | ||
595 | buf += USB_DT_USB_EXT_CAP_SIZE; | ||
589 | 596 | ||
597 | memcpy(buf, &fsg_ss_cap_desc, USB_DT_USB_SS_CAP_SIZE); | ||
598 | |||
599 | return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE | ||
600 | + USB_DT_USB_EXT_CAP_SIZE; | ||
601 | } | ||
590 | 602 | ||
591 | /* | 603 | /* |
592 | * Config descriptors must agree with the code that sets configurations | 604 | * Config descriptors must agree with the code that sets configurations |
@@ -935,7 +947,8 @@ static int standard_setup_req(struct fsg_dev *fsg, | |||
935 | break; | 947 | break; |
936 | case USB_DT_DEVICE_QUALIFIER: | 948 | case USB_DT_DEVICE_QUALIFIER: |
937 | VDBG(fsg, "get device qualifier\n"); | 949 | VDBG(fsg, "get device qualifier\n"); |
938 | if (!gadget_is_dualspeed(fsg->gadget)) | 950 | if (!gadget_is_dualspeed(fsg->gadget) || |
951 | fsg->gadget->speed == USB_SPEED_SUPER) | ||
939 | break; | 952 | break; |
940 | /* | 953 | /* |
941 | * Assume ep0 uses the same maxpacket value for both | 954 | * Assume ep0 uses the same maxpacket value for both |
@@ -948,7 +961,8 @@ static int standard_setup_req(struct fsg_dev *fsg, | |||
948 | 961 | ||
949 | case USB_DT_OTHER_SPEED_CONFIG: | 962 | case USB_DT_OTHER_SPEED_CONFIG: |
950 | VDBG(fsg, "get other-speed config descriptor\n"); | 963 | VDBG(fsg, "get other-speed config descriptor\n"); |
951 | if (!gadget_is_dualspeed(fsg->gadget)) | 964 | if (!gadget_is_dualspeed(fsg->gadget) || |
965 | fsg->gadget->speed == USB_SPEED_SUPER) | ||
952 | break; | 966 | break; |
953 | goto get_config; | 967 | goto get_config; |
954 | case USB_DT_CONFIG: | 968 | case USB_DT_CONFIG: |
@@ -967,7 +981,15 @@ get_config: | |||
967 | value = usb_gadget_get_string(&fsg_stringtab, | 981 | value = usb_gadget_get_string(&fsg_stringtab, |
968 | w_value & 0xff, req->buf); | 982 | w_value & 0xff, req->buf); |
969 | break; | 983 | break; |
984 | |||
985 | case USB_DT_BOS: | ||
986 | VDBG(fsg, "get bos descriptor\n"); | ||
987 | |||
988 | if (gadget_is_superspeed(fsg->gadget)) | ||
989 | value = populate_bos(fsg, req->buf); | ||
990 | break; | ||
970 | } | 991 | } |
992 | |||
971 | break; | 993 | break; |
972 | 994 | ||
973 | /* One config, two speeds */ | 995 | /* One config, two speeds */ |
@@ -1136,7 +1158,6 @@ static int do_read(struct fsg_dev *fsg) | |||
1136 | u32 amount_left; | 1158 | u32 amount_left; |
1137 | loff_t file_offset, file_offset_tmp; | 1159 | loff_t file_offset, file_offset_tmp; |
1138 | unsigned int amount; | 1160 | unsigned int amount; |
1139 | unsigned int partial_page; | ||
1140 | ssize_t nread; | 1161 | ssize_t nread; |
1141 | 1162 | ||
1142 | /* Get the starting Logical Block Address and check that it's | 1163 | /* Get the starting Logical Block Address and check that it's |
@@ -1158,7 +1179,7 @@ static int do_read(struct fsg_dev *fsg) | |||
1158 | curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; | 1179 | curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; |
1159 | return -EINVAL; | 1180 | return -EINVAL; |
1160 | } | 1181 | } |
1161 | file_offset = ((loff_t) lba) << 9; | 1182 | file_offset = ((loff_t) lba) << curlun->blkbits; |
1162 | 1183 | ||
1163 | /* Carry out the file reads */ | 1184 | /* Carry out the file reads */ |
1164 | amount_left = fsg->data_size_from_cmnd; | 1185 | amount_left = fsg->data_size_from_cmnd; |
@@ -1171,17 +1192,10 @@ static int do_read(struct fsg_dev *fsg) | |||
1171 | * Try to read the remaining amount. | 1192 | * Try to read the remaining amount. |
1172 | * But don't read more than the buffer size. | 1193 | * But don't read more than the buffer size. |
1173 | * And don't try to read past the end of the file. | 1194 | * And don't try to read past the end of the file. |
1174 | * Finally, if we're not at a page boundary, don't read past | 1195 | */ |
1175 | * the next page. | ||
1176 | * If this means reading 0 then we were asked to read past | ||
1177 | * the end of file. */ | ||
1178 | amount = min((unsigned int) amount_left, mod_data.buflen); | 1196 | amount = min((unsigned int) amount_left, mod_data.buflen); |
1179 | amount = min((loff_t) amount, | 1197 | amount = min((loff_t) amount, |
1180 | curlun->file_length - file_offset); | 1198 | curlun->file_length - file_offset); |
1181 | partial_page = file_offset & (PAGE_CACHE_SIZE - 1); | ||
1182 | if (partial_page > 0) | ||
1183 | amount = min(amount, (unsigned int) PAGE_CACHE_SIZE - | ||
1184 | partial_page); | ||
1185 | 1199 | ||
1186 | /* Wait for the next buffer to become available */ | 1200 | /* Wait for the next buffer to become available */ |
1187 | bh = fsg->next_buffhd_to_fill; | 1201 | bh = fsg->next_buffhd_to_fill; |
@@ -1196,7 +1210,7 @@ static int do_read(struct fsg_dev *fsg) | |||
1196 | if (amount == 0) { | 1210 | if (amount == 0) { |
1197 | curlun->sense_data = | 1211 | curlun->sense_data = |
1198 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; | 1212 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; |
1199 | curlun->sense_data_info = file_offset >> 9; | 1213 | curlun->sense_data_info = file_offset >> curlun->blkbits; |
1200 | curlun->info_valid = 1; | 1214 | curlun->info_valid = 1; |
1201 | bh->inreq->length = 0; | 1215 | bh->inreq->length = 0; |
1202 | bh->state = BUF_STATE_FULL; | 1216 | bh->state = BUF_STATE_FULL; |
@@ -1221,18 +1235,23 @@ static int do_read(struct fsg_dev *fsg) | |||
1221 | } else if (nread < amount) { | 1235 | } else if (nread < amount) { |
1222 | LDBG(curlun, "partial file read: %d/%u\n", | 1236 | LDBG(curlun, "partial file read: %d/%u\n", |
1223 | (int) nread, amount); | 1237 | (int) nread, amount); |
1224 | nread -= (nread & 511); // Round down to a block | 1238 | nread = round_down(nread, curlun->blksize); |
1225 | } | 1239 | } |
1226 | file_offset += nread; | 1240 | file_offset += nread; |
1227 | amount_left -= nread; | 1241 | amount_left -= nread; |
1228 | fsg->residue -= nread; | 1242 | fsg->residue -= nread; |
1243 | |||
1244 | /* Except at the end of the transfer, nread will be | ||
1245 | * equal to the buffer size, which is divisible by the | ||
1246 | * bulk-in maxpacket size. | ||
1247 | */ | ||
1229 | bh->inreq->length = nread; | 1248 | bh->inreq->length = nread; |
1230 | bh->state = BUF_STATE_FULL; | 1249 | bh->state = BUF_STATE_FULL; |
1231 | 1250 | ||
1232 | /* If an error occurred, report it and its position */ | 1251 | /* If an error occurred, report it and its position */ |
1233 | if (nread < amount) { | 1252 | if (nread < amount) { |
1234 | curlun->sense_data = SS_UNRECOVERED_READ_ERROR; | 1253 | curlun->sense_data = SS_UNRECOVERED_READ_ERROR; |
1235 | curlun->sense_data_info = file_offset >> 9; | 1254 | curlun->sense_data_info = file_offset >> curlun->blkbits; |
1236 | curlun->info_valid = 1; | 1255 | curlun->info_valid = 1; |
1237 | break; | 1256 | break; |
1238 | } | 1257 | } |
@@ -1262,7 +1281,6 @@ static int do_write(struct fsg_dev *fsg) | |||
1262 | u32 amount_left_to_req, amount_left_to_write; | 1281 | u32 amount_left_to_req, amount_left_to_write; |
1263 | loff_t usb_offset, file_offset, file_offset_tmp; | 1282 | loff_t usb_offset, file_offset, file_offset_tmp; |
1264 | unsigned int amount; | 1283 | unsigned int amount; |
1265 | unsigned int partial_page; | ||
1266 | ssize_t nwritten; | 1284 | ssize_t nwritten; |
1267 | int rc; | 1285 | int rc; |
1268 | 1286 | ||
@@ -1303,7 +1321,7 @@ static int do_write(struct fsg_dev *fsg) | |||
1303 | 1321 | ||
1304 | /* Carry out the file writes */ | 1322 | /* Carry out the file writes */ |
1305 | get_some_more = 1; | 1323 | get_some_more = 1; |
1306 | file_offset = usb_offset = ((loff_t) lba) << 9; | 1324 | file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits; |
1307 | amount_left_to_req = amount_left_to_write = fsg->data_size_from_cmnd; | 1325 | amount_left_to_req = amount_left_to_write = fsg->data_size_from_cmnd; |
1308 | 1326 | ||
1309 | while (amount_left_to_write > 0) { | 1327 | while (amount_left_to_write > 0) { |
@@ -1313,38 +1331,20 @@ static int do_write(struct fsg_dev *fsg) | |||
1313 | if (bh->state == BUF_STATE_EMPTY && get_some_more) { | 1331 | if (bh->state == BUF_STATE_EMPTY && get_some_more) { |
1314 | 1332 | ||
1315 | /* Figure out how much we want to get: | 1333 | /* Figure out how much we want to get: |
1316 | * Try to get the remaining amount. | 1334 | * Try to get the remaining amount, |
1317 | * But don't get more than the buffer size. | 1335 | * but not more than the buffer size. |
1318 | * And don't try to go past the end of the file. | 1336 | */ |
1319 | * If we're not at a page boundary, | ||
1320 | * don't go past the next page. | ||
1321 | * If this means getting 0, then we were asked | ||
1322 | * to write past the end of file. | ||
1323 | * Finally, round down to a block boundary. */ | ||
1324 | amount = min(amount_left_to_req, mod_data.buflen); | 1337 | amount = min(amount_left_to_req, mod_data.buflen); |
1325 | amount = min((loff_t) amount, curlun->file_length - | 1338 | |
1326 | usb_offset); | 1339 | /* Beyond the end of the backing file? */ |
1327 | partial_page = usb_offset & (PAGE_CACHE_SIZE - 1); | 1340 | if (usb_offset >= curlun->file_length) { |
1328 | if (partial_page > 0) | ||
1329 | amount = min(amount, | ||
1330 | (unsigned int) PAGE_CACHE_SIZE - partial_page); | ||
1331 | |||
1332 | if (amount == 0) { | ||
1333 | get_some_more = 0; | 1341 | get_some_more = 0; |
1334 | curlun->sense_data = | 1342 | curlun->sense_data = |
1335 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; | 1343 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; |
1336 | curlun->sense_data_info = usb_offset >> 9; | 1344 | curlun->sense_data_info = usb_offset >> curlun->blkbits; |
1337 | curlun->info_valid = 1; | 1345 | curlun->info_valid = 1; |
1338 | continue; | 1346 | continue; |
1339 | } | 1347 | } |
1340 | amount -= (amount & 511); | ||
1341 | if (amount == 0) { | ||
1342 | |||
1343 | /* Why were we were asked to transfer a | ||
1344 | * partial block? */ | ||
1345 | get_some_more = 0; | ||
1346 | continue; | ||
1347 | } | ||
1348 | 1348 | ||
1349 | /* Get the next buffer */ | 1349 | /* Get the next buffer */ |
1350 | usb_offset += amount; | 1350 | usb_offset += amount; |
@@ -1353,11 +1353,11 @@ static int do_write(struct fsg_dev *fsg) | |||
1353 | if (amount_left_to_req == 0) | 1353 | if (amount_left_to_req == 0) |
1354 | get_some_more = 0; | 1354 | get_some_more = 0; |
1355 | 1355 | ||
1356 | /* amount is always divisible by 512, hence by | 1356 | /* Except at the end of the transfer, amount will be |
1357 | * the bulk-out maxpacket size */ | 1357 | * equal to the buffer size, which is divisible by |
1358 | bh->outreq->length = bh->bulk_out_intended_length = | 1358 | * the bulk-out maxpacket size. |
1359 | amount; | 1359 | */ |
1360 | bh->outreq->short_not_ok = 1; | 1360 | set_bulk_out_req_length(fsg, bh, amount); |
1361 | start_transfer(fsg, fsg->bulk_out, bh->outreq, | 1361 | start_transfer(fsg, fsg->bulk_out, bh->outreq, |
1362 | &bh->outreq_busy, &bh->state); | 1362 | &bh->outreq_busy, &bh->state); |
1363 | fsg->next_buffhd_to_fill = bh->next; | 1363 | fsg->next_buffhd_to_fill = bh->next; |
@@ -1376,7 +1376,7 @@ static int do_write(struct fsg_dev *fsg) | |||
1376 | /* Did something go wrong with the transfer? */ | 1376 | /* Did something go wrong with the transfer? */ |
1377 | if (bh->outreq->status != 0) { | 1377 | if (bh->outreq->status != 0) { |
1378 | curlun->sense_data = SS_COMMUNICATION_FAILURE; | 1378 | curlun->sense_data = SS_COMMUNICATION_FAILURE; |
1379 | curlun->sense_data_info = file_offset >> 9; | 1379 | curlun->sense_data_info = file_offset >> curlun->blkbits; |
1380 | curlun->info_valid = 1; | 1380 | curlun->info_valid = 1; |
1381 | break; | 1381 | break; |
1382 | } | 1382 | } |
@@ -1390,6 +1390,16 @@ static int do_write(struct fsg_dev *fsg) | |||
1390 | amount = curlun->file_length - file_offset; | 1390 | amount = curlun->file_length - file_offset; |
1391 | } | 1391 | } |
1392 | 1392 | ||
1393 | /* Don't accept excess data. The spec doesn't say | ||
1394 | * what to do in this case. We'll ignore the error. | ||
1395 | */ | ||
1396 | amount = min(amount, bh->bulk_out_intended_length); | ||
1397 | |||
1398 | /* Don't write a partial block */ | ||
1399 | amount = round_down(amount, curlun->blksize); | ||
1400 | if (amount == 0) | ||
1401 | goto empty_write; | ||
1402 | |||
1393 | /* Perform the write */ | 1403 | /* Perform the write */ |
1394 | file_offset_tmp = file_offset; | 1404 | file_offset_tmp = file_offset; |
1395 | nwritten = vfs_write(curlun->filp, | 1405 | nwritten = vfs_write(curlun->filp, |
@@ -1408,8 +1418,7 @@ static int do_write(struct fsg_dev *fsg) | |||
1408 | } else if (nwritten < amount) { | 1418 | } else if (nwritten < amount) { |
1409 | LDBG(curlun, "partial file write: %d/%u\n", | 1419 | LDBG(curlun, "partial file write: %d/%u\n", |
1410 | (int) nwritten, amount); | 1420 | (int) nwritten, amount); |
1411 | nwritten -= (nwritten & 511); | 1421 | nwritten = round_down(nwritten, curlun->blksize); |
1412 | // Round down to a block | ||
1413 | } | 1422 | } |
1414 | file_offset += nwritten; | 1423 | file_offset += nwritten; |
1415 | amount_left_to_write -= nwritten; | 1424 | amount_left_to_write -= nwritten; |
@@ -1418,13 +1427,14 @@ static int do_write(struct fsg_dev *fsg) | |||
1418 | /* If an error occurred, report it and its position */ | 1427 | /* If an error occurred, report it and its position */ |
1419 | if (nwritten < amount) { | 1428 | if (nwritten < amount) { |
1420 | curlun->sense_data = SS_WRITE_ERROR; | 1429 | curlun->sense_data = SS_WRITE_ERROR; |
1421 | curlun->sense_data_info = file_offset >> 9; | 1430 | curlun->sense_data_info = file_offset >> curlun->blkbits; |
1422 | curlun->info_valid = 1; | 1431 | curlun->info_valid = 1; |
1423 | break; | 1432 | break; |
1424 | } | 1433 | } |
1425 | 1434 | ||
1435 | empty_write: | ||
1426 | /* Did the host decide to stop early? */ | 1436 | /* Did the host decide to stop early? */ |
1427 | if (bh->outreq->actual != bh->outreq->length) { | 1437 | if (bh->outreq->actual < bh->bulk_out_intended_length) { |
1428 | fsg->short_packet_received = 1; | 1438 | fsg->short_packet_received = 1; |
1429 | break; | 1439 | break; |
1430 | } | 1440 | } |
@@ -1500,8 +1510,8 @@ static int do_verify(struct fsg_dev *fsg) | |||
1500 | return -EIO; // No default reply | 1510 | return -EIO; // No default reply |
1501 | 1511 | ||
1502 | /* Prepare to carry out the file verify */ | 1512 | /* Prepare to carry out the file verify */ |
1503 | amount_left = verification_length << 9; | 1513 | amount_left = verification_length << curlun->blkbits; |
1504 | file_offset = ((loff_t) lba) << 9; | 1514 | file_offset = ((loff_t) lba) << curlun->blkbits; |
1505 | 1515 | ||
1506 | /* Write out all the dirty buffers before invalidating them */ | 1516 | /* Write out all the dirty buffers before invalidating them */ |
1507 | fsg_lun_fsync_sub(curlun); | 1517 | fsg_lun_fsync_sub(curlun); |
@@ -1519,15 +1529,14 @@ static int do_verify(struct fsg_dev *fsg) | |||
1519 | * Try to read the remaining amount, but not more than | 1529 | * Try to read the remaining amount, but not more than |
1520 | * the buffer size. | 1530 | * the buffer size. |
1521 | * And don't try to read past the end of the file. | 1531 | * And don't try to read past the end of the file. |
1522 | * If this means reading 0 then we were asked to read | 1532 | */ |
1523 | * past the end of file. */ | ||
1524 | amount = min((unsigned int) amount_left, mod_data.buflen); | 1533 | amount = min((unsigned int) amount_left, mod_data.buflen); |
1525 | amount = min((loff_t) amount, | 1534 | amount = min((loff_t) amount, |
1526 | curlun->file_length - file_offset); | 1535 | curlun->file_length - file_offset); |
1527 | if (amount == 0) { | 1536 | if (amount == 0) { |
1528 | curlun->sense_data = | 1537 | curlun->sense_data = |
1529 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; | 1538 | SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; |
1530 | curlun->sense_data_info = file_offset >> 9; | 1539 | curlun->sense_data_info = file_offset >> curlun->blkbits; |
1531 | curlun->info_valid = 1; | 1540 | curlun->info_valid = 1; |
1532 | break; | 1541 | break; |
1533 | } | 1542 | } |
@@ -1550,11 +1559,11 @@ static int do_verify(struct fsg_dev *fsg) | |||
1550 | } else if (nread < amount) { | 1559 | } else if (nread < amount) { |
1551 | LDBG(curlun, "partial file verify: %d/%u\n", | 1560 | LDBG(curlun, "partial file verify: %d/%u\n", |
1552 | (int) nread, amount); | 1561 | (int) nread, amount); |
1553 | nread -= (nread & 511); // Round down to a sector | 1562 | nread = round_down(nread, curlun->blksize); |
1554 | } | 1563 | } |
1555 | if (nread == 0) { | 1564 | if (nread == 0) { |
1556 | curlun->sense_data = SS_UNRECOVERED_READ_ERROR; | 1565 | curlun->sense_data = SS_UNRECOVERED_READ_ERROR; |
1557 | curlun->sense_data_info = file_offset >> 9; | 1566 | curlun->sense_data_info = file_offset >> curlun->blkbits; |
1558 | curlun->info_valid = 1; | 1567 | curlun->info_valid = 1; |
1559 | break; | 1568 | break; |
1560 | } | 1569 | } |
@@ -1668,7 +1677,7 @@ static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh) | |||
1668 | 1677 | ||
1669 | put_unaligned_be32(curlun->num_sectors - 1, &buf[0]); | 1678 | put_unaligned_be32(curlun->num_sectors - 1, &buf[0]); |
1670 | /* Max logical block */ | 1679 | /* Max logical block */ |
1671 | put_unaligned_be32(512, &buf[4]); /* Block length */ | 1680 | put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */ |
1672 | return 8; | 1681 | return 8; |
1673 | } | 1682 | } |
1674 | 1683 | ||
@@ -1890,7 +1899,7 @@ static int do_read_format_capacities(struct fsg_dev *fsg, | |||
1890 | 1899 | ||
1891 | put_unaligned_be32(curlun->num_sectors, &buf[0]); | 1900 | put_unaligned_be32(curlun->num_sectors, &buf[0]); |
1892 | /* Number of blocks */ | 1901 | /* Number of blocks */ |
1893 | put_unaligned_be32(512, &buf[4]); /* Block length */ | 1902 | put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */ |
1894 | buf[4] = 0x02; /* Current capacity */ | 1903 | buf[4] = 0x02; /* Current capacity */ |
1895 | return 12; | 1904 | return 12; |
1896 | } | 1905 | } |
@@ -1969,7 +1978,7 @@ static int throw_away_data(struct fsg_dev *fsg) | |||
1969 | fsg->next_buffhd_to_drain = bh->next; | 1978 | fsg->next_buffhd_to_drain = bh->next; |
1970 | 1979 | ||
1971 | /* A short packet or an error ends everything */ | 1980 | /* A short packet or an error ends everything */ |
1972 | if (bh->outreq->actual != bh->outreq->length || | 1981 | if (bh->outreq->actual < bh->bulk_out_intended_length || |
1973 | bh->outreq->status != 0) { | 1982 | bh->outreq->status != 0) { |
1974 | raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT); | 1983 | raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT); |
1975 | return -EINTR; | 1984 | return -EINTR; |
@@ -1983,11 +1992,11 @@ static int throw_away_data(struct fsg_dev *fsg) | |||
1983 | amount = min(fsg->usb_amount_left, | 1992 | amount = min(fsg->usb_amount_left, |
1984 | (u32) mod_data.buflen); | 1993 | (u32) mod_data.buflen); |
1985 | 1994 | ||
1986 | /* amount is always divisible by 512, hence by | 1995 | /* Except at the end of the transfer, amount will be |
1987 | * the bulk-out maxpacket size */ | 1996 | * equal to the buffer size, which is divisible by |
1988 | bh->outreq->length = bh->bulk_out_intended_length = | 1997 | * the bulk-out maxpacket size. |
1989 | amount; | 1998 | */ |
1990 | bh->outreq->short_not_ok = 1; | 1999 | set_bulk_out_req_length(fsg, bh, amount); |
1991 | start_transfer(fsg, fsg->bulk_out, bh->outreq, | 2000 | start_transfer(fsg, fsg->bulk_out, bh->outreq, |
1992 | &bh->outreq_busy, &bh->state); | 2001 | &bh->outreq_busy, &bh->state); |
1993 | fsg->next_buffhd_to_fill = bh->next; | 2002 | fsg->next_buffhd_to_fill = bh->next; |
@@ -2415,7 +2424,7 @@ static int do_scsi_command(struct fsg_dev *fsg) | |||
2415 | 2424 | ||
2416 | case READ_6: | 2425 | case READ_6: |
2417 | i = fsg->cmnd[4]; | 2426 | i = fsg->cmnd[4]; |
2418 | fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; | 2427 | fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << fsg->curlun->blkbits; |
2419 | if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST, | 2428 | if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST, |
2420 | (7<<1) | (1<<4), 1, | 2429 | (7<<1) | (1<<4), 1, |
2421 | "READ(6)")) == 0) | 2430 | "READ(6)")) == 0) |
@@ -2424,7 +2433,7 @@ static int do_scsi_command(struct fsg_dev *fsg) | |||
2424 | 2433 | ||
2425 | case READ_10: | 2434 | case READ_10: |
2426 | fsg->data_size_from_cmnd = | 2435 | fsg->data_size_from_cmnd = |
2427 | get_unaligned_be16(&fsg->cmnd[7]) << 9; | 2436 | get_unaligned_be16(&fsg->cmnd[7]) << fsg->curlun->blkbits; |
2428 | if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, | 2437 | if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, |
2429 | (1<<1) | (0xf<<2) | (3<<7), 1, | 2438 | (1<<1) | (0xf<<2) | (3<<7), 1, |
2430 | "READ(10)")) == 0) | 2439 | "READ(10)")) == 0) |
@@ -2433,7 +2442,7 @@ static int do_scsi_command(struct fsg_dev *fsg) | |||
2433 | 2442 | ||
2434 | case READ_12: | 2443 | case READ_12: |
2435 | fsg->data_size_from_cmnd = | 2444 | fsg->data_size_from_cmnd = |
2436 | get_unaligned_be32(&fsg->cmnd[6]) << 9; | 2445 | get_unaligned_be32(&fsg->cmnd[6]) << fsg->curlun->blkbits; |
2437 | if ((reply = check_command(fsg, 12, DATA_DIR_TO_HOST, | 2446 | if ((reply = check_command(fsg, 12, DATA_DIR_TO_HOST, |
2438 | (1<<1) | (0xf<<2) | (0xf<<6), 1, | 2447 | (1<<1) | (0xf<<2) | (0xf<<6), 1, |
2439 | "READ(12)")) == 0) | 2448 | "READ(12)")) == 0) |
@@ -2519,7 +2528,7 @@ static int do_scsi_command(struct fsg_dev *fsg) | |||
2519 | 2528 | ||
2520 | case WRITE_6: | 2529 | case WRITE_6: |
2521 | i = fsg->cmnd[4]; | 2530 | i = fsg->cmnd[4]; |
2522 | fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; | 2531 | fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << fsg->curlun->blkbits; |
2523 | if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST, | 2532 | if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST, |
2524 | (7<<1) | (1<<4), 1, | 2533 | (7<<1) | (1<<4), 1, |
2525 | "WRITE(6)")) == 0) | 2534 | "WRITE(6)")) == 0) |
@@ -2528,7 +2537,7 @@ static int do_scsi_command(struct fsg_dev *fsg) | |||
2528 | 2537 | ||
2529 | case WRITE_10: | 2538 | case WRITE_10: |
2530 | fsg->data_size_from_cmnd = | 2539 | fsg->data_size_from_cmnd = |
2531 | get_unaligned_be16(&fsg->cmnd[7]) << 9; | 2540 | get_unaligned_be16(&fsg->cmnd[7]) << fsg->curlun->blkbits; |
2532 | if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST, | 2541 | if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST, |
2533 | (1<<1) | (0xf<<2) | (3<<7), 1, | 2542 | (1<<1) | (0xf<<2) | (3<<7), 1, |
2534 | "WRITE(10)")) == 0) | 2543 | "WRITE(10)")) == 0) |
@@ -2537,7 +2546,7 @@ static int do_scsi_command(struct fsg_dev *fsg) | |||
2537 | 2546 | ||
2538 | case WRITE_12: | 2547 | case WRITE_12: |
2539 | fsg->data_size_from_cmnd = | 2548 | fsg->data_size_from_cmnd = |
2540 | get_unaligned_be32(&fsg->cmnd[6]) << 9; | 2549 | get_unaligned_be32(&fsg->cmnd[6]) << fsg->curlun->blkbits; |
2541 | if ((reply = check_command(fsg, 12, DATA_DIR_FROM_HOST, | 2550 | if ((reply = check_command(fsg, 12, DATA_DIR_FROM_HOST, |
2542 | (1<<1) | (0xf<<2) | (0xf<<6), 1, | 2551 | (1<<1) | (0xf<<2) | (0xf<<6), 1, |
2543 | "WRITE(12)")) == 0) | 2552 | "WRITE(12)")) == 0) |
@@ -2666,7 +2675,6 @@ static int get_next_command(struct fsg_dev *fsg) | |||
2666 | 2675 | ||
2667 | /* Queue a request to read a Bulk-only CBW */ | 2676 | /* Queue a request to read a Bulk-only CBW */ |
2668 | set_bulk_out_req_length(fsg, bh, USB_BULK_CB_WRAP_LEN); | 2677 | set_bulk_out_req_length(fsg, bh, USB_BULK_CB_WRAP_LEN); |
2669 | bh->outreq->short_not_ok = 1; | ||
2670 | start_transfer(fsg, fsg->bulk_out, bh->outreq, | 2678 | start_transfer(fsg, fsg->bulk_out, bh->outreq, |
2671 | &bh->outreq_busy, &bh->state); | 2679 | &bh->outreq_busy, &bh->state); |
2672 | 2680 | ||
@@ -2752,7 +2760,7 @@ static int do_set_interface(struct fsg_dev *fsg, int altsetting) | |||
2752 | 2760 | ||
2753 | reset: | 2761 | reset: |
2754 | /* Deallocate the requests */ | 2762 | /* Deallocate the requests */ |
2755 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | 2763 | for (i = 0; i < fsg_num_buffers; ++i) { |
2756 | struct fsg_buffhd *bh = &fsg->buffhds[i]; | 2764 | struct fsg_buffhd *bh = &fsg->buffhds[i]; |
2757 | 2765 | ||
2758 | if (bh->inreq) { | 2766 | if (bh->inreq) { |
@@ -2791,29 +2799,32 @@ reset: | |||
2791 | 2799 | ||
2792 | /* Enable the endpoints */ | 2800 | /* Enable the endpoints */ |
2793 | d = fsg_ep_desc(fsg->gadget, | 2801 | d = fsg_ep_desc(fsg->gadget, |
2794 | &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc); | 2802 | &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc, |
2803 | &fsg_ss_bulk_in_desc); | ||
2795 | if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0) | 2804 | if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0) |
2796 | goto reset; | 2805 | goto reset; |
2797 | fsg->bulk_in_enabled = 1; | 2806 | fsg->bulk_in_enabled = 1; |
2798 | 2807 | ||
2799 | d = fsg_ep_desc(fsg->gadget, | 2808 | d = fsg_ep_desc(fsg->gadget, |
2800 | &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc); | 2809 | &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc, |
2810 | &fsg_ss_bulk_out_desc); | ||
2801 | if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0) | 2811 | if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0) |
2802 | goto reset; | 2812 | goto reset; |
2803 | fsg->bulk_out_enabled = 1; | 2813 | fsg->bulk_out_enabled = 1; |
2804 | fsg->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize); | 2814 | fsg->bulk_out_maxpacket = usb_endpoint_maxp(d); |
2805 | clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); | 2815 | clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); |
2806 | 2816 | ||
2807 | if (transport_is_cbi()) { | 2817 | if (transport_is_cbi()) { |
2808 | d = fsg_ep_desc(fsg->gadget, | 2818 | d = fsg_ep_desc(fsg->gadget, |
2809 | &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc); | 2819 | &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc, |
2820 | &fsg_ss_intr_in_desc); | ||
2810 | if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0) | 2821 | if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0) |
2811 | goto reset; | 2822 | goto reset; |
2812 | fsg->intr_in_enabled = 1; | 2823 | fsg->intr_in_enabled = 1; |
2813 | } | 2824 | } |
2814 | 2825 | ||
2815 | /* Allocate the requests */ | 2826 | /* Allocate the requests */ |
2816 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | 2827 | for (i = 0; i < fsg_num_buffers; ++i) { |
2817 | struct fsg_buffhd *bh = &fsg->buffhds[i]; | 2828 | struct fsg_buffhd *bh = &fsg->buffhds[i]; |
2818 | 2829 | ||
2819 | if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0) | 2830 | if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0) |
@@ -2862,17 +2873,10 @@ static int do_set_config(struct fsg_dev *fsg, u8 new_config) | |||
2862 | fsg->config = new_config; | 2873 | fsg->config = new_config; |
2863 | if ((rc = do_set_interface(fsg, 0)) != 0) | 2874 | if ((rc = do_set_interface(fsg, 0)) != 0) |
2864 | fsg->config = 0; // Reset on errors | 2875 | fsg->config = 0; // Reset on errors |
2865 | else { | 2876 | else |
2866 | char *speed; | 2877 | INFO(fsg, "%s config #%d\n", |
2867 | 2878 | usb_speed_string(fsg->gadget->speed), | |
2868 | switch (fsg->gadget->speed) { | 2879 | fsg->config); |
2869 | case USB_SPEED_LOW: speed = "low"; break; | ||
2870 | case USB_SPEED_FULL: speed = "full"; break; | ||
2871 | case USB_SPEED_HIGH: speed = "high"; break; | ||
2872 | default: speed = "?"; break; | ||
2873 | } | ||
2874 | INFO(fsg, "%s speed config #%d\n", speed, fsg->config); | ||
2875 | } | ||
2876 | } | 2880 | } |
2877 | return rc; | 2881 | return rc; |
2878 | } | 2882 | } |
@@ -2909,7 +2913,7 @@ static void handle_exception(struct fsg_dev *fsg) | |||
2909 | /* Cancel all the pending transfers */ | 2913 | /* Cancel all the pending transfers */ |
2910 | if (fsg->intreq_busy) | 2914 | if (fsg->intreq_busy) |
2911 | usb_ep_dequeue(fsg->intr_in, fsg->intreq); | 2915 | usb_ep_dequeue(fsg->intr_in, fsg->intreq); |
2912 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | 2916 | for (i = 0; i < fsg_num_buffers; ++i) { |
2913 | bh = &fsg->buffhds[i]; | 2917 | bh = &fsg->buffhds[i]; |
2914 | if (bh->inreq_busy) | 2918 | if (bh->inreq_busy) |
2915 | usb_ep_dequeue(fsg->bulk_in, bh->inreq); | 2919 | usb_ep_dequeue(fsg->bulk_in, bh->inreq); |
@@ -2920,7 +2924,7 @@ static void handle_exception(struct fsg_dev *fsg) | |||
2920 | /* Wait until everything is idle */ | 2924 | /* Wait until everything is idle */ |
2921 | for (;;) { | 2925 | for (;;) { |
2922 | num_active = fsg->intreq_busy; | 2926 | num_active = fsg->intreq_busy; |
2923 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | 2927 | for (i = 0; i < fsg_num_buffers; ++i) { |
2924 | bh = &fsg->buffhds[i]; | 2928 | bh = &fsg->buffhds[i]; |
2925 | num_active += bh->inreq_busy + bh->outreq_busy; | 2929 | num_active += bh->inreq_busy + bh->outreq_busy; |
2926 | } | 2930 | } |
@@ -2942,7 +2946,7 @@ static void handle_exception(struct fsg_dev *fsg) | |||
2942 | * state, and the exception. Then invoke the handler. */ | 2946 | * state, and the exception. Then invoke the handler. */ |
2943 | spin_lock_irq(&fsg->lock); | 2947 | spin_lock_irq(&fsg->lock); |
2944 | 2948 | ||
2945 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | 2949 | for (i = 0; i < fsg_num_buffers; ++i) { |
2946 | bh = &fsg->buffhds[i]; | 2950 | bh = &fsg->buffhds[i]; |
2947 | bh->state = BUF_STATE_EMPTY; | 2951 | bh->state = BUF_STATE_EMPTY; |
2948 | } | 2952 | } |
@@ -3149,6 +3153,15 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget) | |||
3149 | DBG(fsg, "unbind\n"); | 3153 | DBG(fsg, "unbind\n"); |
3150 | clear_bit(REGISTERED, &fsg->atomic_bitflags); | 3154 | clear_bit(REGISTERED, &fsg->atomic_bitflags); |
3151 | 3155 | ||
3156 | /* If the thread isn't already dead, tell it to exit now */ | ||
3157 | if (fsg->state != FSG_STATE_TERMINATED) { | ||
3158 | raise_exception(fsg, FSG_STATE_EXIT); | ||
3159 | wait_for_completion(&fsg->thread_notifier); | ||
3160 | |||
3161 | /* The cleanup routine waits for this completion also */ | ||
3162 | complete(&fsg->thread_notifier); | ||
3163 | } | ||
3164 | |||
3152 | /* Unregister the sysfs attribute files and the LUNs */ | 3165 | /* Unregister the sysfs attribute files and the LUNs */ |
3153 | for (i = 0; i < fsg->nluns; ++i) { | 3166 | for (i = 0; i < fsg->nluns; ++i) { |
3154 | curlun = &fsg->luns[i]; | 3167 | curlun = &fsg->luns[i]; |
@@ -3162,17 +3175,8 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget) | |||
3162 | } | 3175 | } |
3163 | } | 3176 | } |
3164 | 3177 | ||
3165 | /* If the thread isn't already dead, tell it to exit now */ | ||
3166 | if (fsg->state != FSG_STATE_TERMINATED) { | ||
3167 | raise_exception(fsg, FSG_STATE_EXIT); | ||
3168 | wait_for_completion(&fsg->thread_notifier); | ||
3169 | |||
3170 | /* The cleanup routine waits for this completion also */ | ||
3171 | complete(&fsg->thread_notifier); | ||
3172 | } | ||
3173 | |||
3174 | /* Free the data buffers */ | 3178 | /* Free the data buffers */ |
3175 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) | 3179 | for (i = 0; i < fsg_num_buffers; ++i) |
3176 | kfree(fsg->buffhds[i].buf); | 3180 | kfree(fsg->buffhds[i].buf); |
3177 | 3181 | ||
3178 | /* Free the request and buffer for endpoint 0 */ | 3182 | /* Free the request and buffer for endpoint 0 */ |
@@ -3445,6 +3449,24 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
3445 | fsg_fs_intr_in_desc.bEndpointAddress; | 3449 | fsg_fs_intr_in_desc.bEndpointAddress; |
3446 | } | 3450 | } |
3447 | 3451 | ||
3452 | if (gadget_is_superspeed(gadget)) { | ||
3453 | unsigned max_burst; | ||
3454 | |||
3455 | fsg_ss_function[i + FSG_SS_FUNCTION_PRE_EP_ENTRIES] = NULL; | ||
3456 | |||
3457 | /* Calculate bMaxBurst, we know packet size is 1024 */ | ||
3458 | max_burst = min_t(unsigned, mod_data.buflen / 1024, 15); | ||
3459 | |||
3460 | /* Assume endpoint addresses are the same for both speeds */ | ||
3461 | fsg_ss_bulk_in_desc.bEndpointAddress = | ||
3462 | fsg_fs_bulk_in_desc.bEndpointAddress; | ||
3463 | fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst; | ||
3464 | |||
3465 | fsg_ss_bulk_out_desc.bEndpointAddress = | ||
3466 | fsg_fs_bulk_out_desc.bEndpointAddress; | ||
3467 | fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst; | ||
3468 | } | ||
3469 | |||
3448 | if (gadget_is_otg(gadget)) | 3470 | if (gadget_is_otg(gadget)) |
3449 | fsg_otg_desc.bmAttributes |= USB_OTG_HNP; | 3471 | fsg_otg_desc.bmAttributes |= USB_OTG_HNP; |
3450 | 3472 | ||
@@ -3460,7 +3482,7 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
3460 | req->complete = ep0_complete; | 3482 | req->complete = ep0_complete; |
3461 | 3483 | ||
3462 | /* Allocate the data buffers */ | 3484 | /* Allocate the data buffers */ |
3463 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | 3485 | for (i = 0; i < fsg_num_buffers; ++i) { |
3464 | struct fsg_buffhd *bh = &fsg->buffhds[i]; | 3486 | struct fsg_buffhd *bh = &fsg->buffhds[i]; |
3465 | 3487 | ||
3466 | /* Allocate for the bulk-in endpoint. We assume that | 3488 | /* Allocate for the bulk-in endpoint. We assume that |
@@ -3471,7 +3493,7 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
3471 | goto out; | 3493 | goto out; |
3472 | bh->next = bh + 1; | 3494 | bh->next = bh + 1; |
3473 | } | 3495 | } |
3474 | fsg->buffhds[FSG_NUM_BUFFERS - 1].next = &fsg->buffhds[0]; | 3496 | fsg->buffhds[fsg_num_buffers - 1].next = &fsg->buffhds[0]; |
3475 | 3497 | ||
3476 | /* This should reflect the actual gadget power source */ | 3498 | /* This should reflect the actual gadget power source */ |
3477 | usb_gadget_set_selfpowered(gadget); | 3499 | usb_gadget_set_selfpowered(gadget); |
@@ -3561,11 +3583,7 @@ static void fsg_resume(struct usb_gadget *gadget) | |||
3561 | /*-------------------------------------------------------------------------*/ | 3583 | /*-------------------------------------------------------------------------*/ |
3562 | 3584 | ||
3563 | static struct usb_gadget_driver fsg_driver = { | 3585 | static struct usb_gadget_driver fsg_driver = { |
3564 | #ifdef CONFIG_USB_GADGET_DUALSPEED | 3586 | .speed = USB_SPEED_SUPER, |
3565 | .speed = USB_SPEED_HIGH, | ||
3566 | #else | ||
3567 | .speed = USB_SPEED_FULL, | ||
3568 | #endif | ||
3569 | .function = (char *) fsg_string_product, | 3587 | .function = (char *) fsg_string_product, |
3570 | .unbind = fsg_unbind, | 3588 | .unbind = fsg_unbind, |
3571 | .disconnect = fsg_disconnect, | 3589 | .disconnect = fsg_disconnect, |
@@ -3587,7 +3605,9 @@ static int __init fsg_alloc(void) | |||
3587 | { | 3605 | { |
3588 | struct fsg_dev *fsg; | 3606 | struct fsg_dev *fsg; |
3589 | 3607 | ||
3590 | fsg = kzalloc(sizeof *fsg, GFP_KERNEL); | 3608 | fsg = kzalloc(sizeof *fsg + |
3609 | fsg_num_buffers * sizeof *(fsg->buffhds), GFP_KERNEL); | ||
3610 | |||
3591 | if (!fsg) | 3611 | if (!fsg) |
3592 | return -ENOMEM; | 3612 | return -ENOMEM; |
3593 | spin_lock_init(&fsg->lock); | 3613 | spin_lock_init(&fsg->lock); |
@@ -3605,6 +3625,10 @@ static int __init fsg_init(void) | |||
3605 | int rc; | 3625 | int rc; |
3606 | struct fsg_dev *fsg; | 3626 | struct fsg_dev *fsg; |
3607 | 3627 | ||
3628 | rc = fsg_num_buffers_validate(); | ||
3629 | if (rc != 0) | ||
3630 | return rc; | ||
3631 | |||
3608 | if ((rc = fsg_alloc()) != 0) | 3632 | if ((rc = fsg_alloc()) != 0) |
3609 | return rc; | 3633 | return rc; |
3610 | fsg = the_fsg; | 3634 | fsg = the_fsg; |
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c index 3bf872e1ad39..2a03e4de11c1 100644 --- a/drivers/usb/gadget/fsl_qe_udc.c +++ b/drivers/usb/gadget/fsl_qe_udc.c | |||
@@ -540,7 +540,7 @@ static int qe_ep_init(struct qe_udc *udc, | |||
540 | int reval = 0; | 540 | int reval = 0; |
541 | u16 max = 0; | 541 | u16 max = 0; |
542 | 542 | ||
543 | max = le16_to_cpu(desc->wMaxPacketSize); | 543 | max = usb_endpoint_maxp(desc); |
544 | 544 | ||
545 | /* check the max package size validate for this endpoint */ | 545 | /* check the max package size validate for this endpoint */ |
546 | /* Refer to USB2.0 spec table 9-13, | 546 | /* Refer to USB2.0 spec table 9-13, |
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c index de24a4233c25..b2c44e1d5813 100644 --- a/drivers/usb/gadget/fsl_udc_core.c +++ b/drivers/usb/gadget/fsl_udc_core.c | |||
@@ -559,7 +559,7 @@ static int fsl_ep_enable(struct usb_ep *_ep, | |||
559 | if (!udc->driver || (udc->gadget.speed == USB_SPEED_UNKNOWN)) | 559 | if (!udc->driver || (udc->gadget.speed == USB_SPEED_UNKNOWN)) |
560 | return -ESHUTDOWN; | 560 | return -ESHUTDOWN; |
561 | 561 | ||
562 | max = le16_to_cpu(desc->wMaxPacketSize); | 562 | max = usb_endpoint_maxp(desc); |
563 | 563 | ||
564 | /* Disable automatic zlp generation. Driver is responsible to indicate | 564 | /* Disable automatic zlp generation. Driver is responsible to indicate |
565 | * explicitly through req->req.zero. This is needed to enable multi-td | 565 | * explicitly through req->req.zero. This is needed to enable multi-td |
@@ -1715,34 +1715,31 @@ static void dtd_complete_irq(struct fsl_udc *udc) | |||
1715 | } | 1715 | } |
1716 | } | 1716 | } |
1717 | 1717 | ||
1718 | static inline enum usb_device_speed portscx_device_speed(u32 reg) | ||
1719 | { | ||
1720 | switch (speed & PORTSCX_PORT_SPEED_MASK) { | ||
1721 | case PORTSCX_PORT_SPEED_HIGH: | ||
1722 | return USB_SPEED_HIGH; | ||
1723 | case PORTSCX_PORT_SPEED_FULL: | ||
1724 | return USB_SPEED_FULL; | ||
1725 | case PORTSCX_PORT_SPEED_LOW: | ||
1726 | return USB_SPEED_LOW; | ||
1727 | default: | ||
1728 | return USB_SPEED_UNKNOWN; | ||
1729 | } | ||
1730 | } | ||
1731 | |||
1718 | /* Process a port change interrupt */ | 1732 | /* Process a port change interrupt */ |
1719 | static void port_change_irq(struct fsl_udc *udc) | 1733 | static void port_change_irq(struct fsl_udc *udc) |
1720 | { | 1734 | { |
1721 | u32 speed; | ||
1722 | |||
1723 | if (udc->bus_reset) | 1735 | if (udc->bus_reset) |
1724 | udc->bus_reset = 0; | 1736 | udc->bus_reset = 0; |
1725 | 1737 | ||
1726 | /* Bus resetting is finished */ | 1738 | /* Bus resetting is finished */ |
1727 | if (!(fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET)) { | 1739 | if (!(fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET)) |
1728 | /* Get the speed */ | 1740 | /* Get the speed */ |
1729 | speed = (fsl_readl(&dr_regs->portsc1) | 1741 | udc->gadget.speed = |
1730 | & PORTSCX_PORT_SPEED_MASK); | 1742 | portscx_device_speed(fsl_readl(&dr_regs->portsc1)); |
1731 | switch (speed) { | ||
1732 | case PORTSCX_PORT_SPEED_HIGH: | ||
1733 | udc->gadget.speed = USB_SPEED_HIGH; | ||
1734 | break; | ||
1735 | case PORTSCX_PORT_SPEED_FULL: | ||
1736 | udc->gadget.speed = USB_SPEED_FULL; | ||
1737 | break; | ||
1738 | case PORTSCX_PORT_SPEED_LOW: | ||
1739 | udc->gadget.speed = USB_SPEED_LOW; | ||
1740 | break; | ||
1741 | default: | ||
1742 | udc->gadget.speed = USB_SPEED_UNKNOWN; | ||
1743 | break; | ||
1744 | } | ||
1745 | } | ||
1746 | 1743 | ||
1747 | /* Update USB state */ | 1744 | /* Update USB state */ |
1748 | if (!udc->resume_state) | 1745 | if (!udc->resume_state) |
@@ -2167,20 +2164,8 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count, | |||
2167 | default: | 2164 | default: |
2168 | s = "None"; break; | 2165 | s = "None"; break; |
2169 | } | 2166 | } |
2170 | s;} ), ( { | 2167 | s;} ), |
2171 | char *s; | 2168 | usb_speed_string(portscx_device_speed(tmp_reg)), |
2172 | switch (tmp_reg & PORTSCX_PORT_SPEED_UNDEF) { | ||
2173 | case PORTSCX_PORT_SPEED_FULL: | ||
2174 | s = "Full Speed"; break; | ||
2175 | case PORTSCX_PORT_SPEED_LOW: | ||
2176 | s = "Low Speed"; break; | ||
2177 | case PORTSCX_PORT_SPEED_HIGH: | ||
2178 | s = "High Speed"; break; | ||
2179 | default: | ||
2180 | s = "Undefined"; break; | ||
2181 | } | ||
2182 | s; | ||
2183 | } ), | ||
2184 | (tmp_reg & PORTSCX_PHY_LOW_POWER_SPD) ? | 2169 | (tmp_reg & PORTSCX_PHY_LOW_POWER_SPD) ? |
2185 | "Normal PHY mode" : "Low power mode", | 2170 | "Normal PHY mode" : "Low power mode", |
2186 | (tmp_reg & PORTSCX_PORT_RESET) ? "In Reset" : | 2171 | (tmp_reg & PORTSCX_PORT_RESET) ? "In Reset" : |
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c index 4ec888f90002..e593f2849fa9 100644 --- a/drivers/usb/gadget/fusb300_udc.c +++ b/drivers/usb/gadget/fusb300_udc.c | |||
@@ -8,16 +8,6 @@ | |||
8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; version 2 of the License. | 10 | * the Free Software Foundation; version 2 of the License. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | * | ||
21 | */ | 11 | */ |
22 | #include <linux/dma-mapping.h> | 12 | #include <linux/dma-mapping.h> |
23 | #include <linux/err.h> | 13 | #include <linux/err.h> |
@@ -220,7 +210,7 @@ static int config_ep(struct fusb300_ep *ep, | |||
220 | 210 | ||
221 | info.type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; | 211 | info.type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; |
222 | info.dir_in = (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ? 1 : 0; | 212 | info.dir_in = (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ? 1 : 0; |
223 | info.maxpacket = le16_to_cpu(desc->wMaxPacketSize); | 213 | info.maxpacket = usb_endpoint_maxp(desc); |
224 | info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; | 214 | info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; |
225 | 215 | ||
226 | if ((info.type == USB_ENDPOINT_XFER_INT) || | 216 | if ((info.type == USB_ENDPOINT_XFER_INT) || |
@@ -1479,7 +1469,7 @@ static int __init fusb300_probe(struct platform_device *pdev) | |||
1479 | fusb300->gadget.name = udc_name; | 1469 | fusb300->gadget.name = udc_name; |
1480 | fusb300->reg = reg; | 1470 | fusb300->reg = reg; |
1481 | 1471 | ||
1482 | ret = request_irq(ires->start, fusb300_irq, IRQF_DISABLED | IRQF_SHARED, | 1472 | ret = request_irq(ires->start, fusb300_irq, IRQF_SHARED, |
1483 | udc_name, fusb300); | 1473 | udc_name, fusb300); |
1484 | if (ret < 0) { | 1474 | if (ret < 0) { |
1485 | pr_err("request_irq error (%d)\n", ret); | 1475 | pr_err("request_irq error (%d)\n", ret); |
@@ -1487,7 +1477,7 @@ static int __init fusb300_probe(struct platform_device *pdev) | |||
1487 | } | 1477 | } |
1488 | 1478 | ||
1489 | ret = request_irq(ires1->start, fusb300_irq, | 1479 | ret = request_irq(ires1->start, fusb300_irq, |
1490 | IRQF_DISABLED | IRQF_SHARED, udc_name, fusb300); | 1480 | IRQF_SHARED, udc_name, fusb300); |
1491 | if (ret < 0) { | 1481 | if (ret < 0) { |
1492 | pr_err("request_irq1 error (%d)\n", ret); | 1482 | pr_err("request_irq1 error (%d)\n", ret); |
1493 | goto clean_up; | 1483 | goto clean_up; |
diff --git a/drivers/usb/gadget/fusb300_udc.h b/drivers/usb/gadget/fusb300_udc.h index f51aa2ef1f90..92745bd03064 100644 --- a/drivers/usb/gadget/fusb300_udc.h +++ b/drivers/usb/gadget/fusb300_udc.h | |||
@@ -8,16 +8,6 @@ | |||
8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; version 2 of the License. | 10 | * the Free Software Foundation; version 2 of the License. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | * | ||
21 | */ | 11 | */ |
22 | 12 | ||
23 | 13 | ||
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c index 704c2800ac00..0519d77915ec 100644 --- a/drivers/usb/gadget/g_ffs.c +++ b/drivers/usb/gadget/g_ffs.c | |||
@@ -8,15 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | 11 | */ |
21 | 12 | ||
22 | #define pr_fmt(fmt) "g_ffs: " fmt | 13 | #define pr_fmt(fmt) "g_ffs: " fmt |
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h index f3a83cd0ef50..a8855d0b7f3b 100644 --- a/drivers/usb/gadget/gadget_chips.h +++ b/drivers/usb/gadget/gadget_chips.h | |||
@@ -31,6 +31,7 @@ | |||
31 | #define gadget_is_ci13xxx_msm(g) (!strcmp("ci13xxx_msm", (g)->name)) | 31 | #define gadget_is_ci13xxx_msm(g) (!strcmp("ci13xxx_msm", (g)->name)) |
32 | #define gadget_is_ci13xxx_pci(g) (!strcmp("ci13xxx_pci", (g)->name)) | 32 | #define gadget_is_ci13xxx_pci(g) (!strcmp("ci13xxx_pci", (g)->name)) |
33 | #define gadget_is_dummy(g) (!strcmp("dummy_udc", (g)->name)) | 33 | #define gadget_is_dummy(g) (!strcmp("dummy_udc", (g)->name)) |
34 | #define gadget_is_dwc3(g) (!strcmp("dwc3-gadget", (g)->name)) | ||
34 | #define gadget_is_fsl_qe(g) (!strcmp("fsl_qe_udc", (g)->name)) | 35 | #define gadget_is_fsl_qe(g) (!strcmp("fsl_qe_udc", (g)->name)) |
35 | #define gadget_is_fsl_usb2(g) (!strcmp("fsl-usb2-udc", (g)->name)) | 36 | #define gadget_is_fsl_usb2(g) (!strcmp("fsl-usb2-udc", (g)->name)) |
36 | #define gadget_is_goku(g) (!strcmp("goku_udc", (g)->name)) | 37 | #define gadget_is_goku(g) (!strcmp("goku_udc", (g)->name)) |
@@ -115,6 +116,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget) | |||
115 | return 0x30; | 116 | return 0x30; |
116 | else if (gadget_is_net2272(gadget)) | 117 | else if (gadget_is_net2272(gadget)) |
117 | return 0x31; | 118 | return 0x31; |
119 | else if (gadget_is_dwc3(gadget)) | ||
120 | return 0x32; | ||
118 | 121 | ||
119 | return -ENOENT; | 122 | return -ENOENT; |
120 | } | 123 | } |
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c index 8b9220e128a7..8fcde37aa6d4 100644 --- a/drivers/usb/gadget/gmidi.c +++ b/drivers/usb/gadget/gmidi.c | |||
@@ -36,134 +36,43 @@ | |||
36 | 36 | ||
37 | #include "gadget_chips.h" | 37 | #include "gadget_chips.h" |
38 | 38 | ||
39 | 39 | #include "composite.c" | |
40 | /* | ||
41 | * Kbuild is not very cooperative with respect to linking separately | ||
42 | * compiled library objects into one module. So for now we won't use | ||
43 | * separate compilation ... ensuring init/exit sections work to shrink | ||
44 | * the runtime footprint, and giving us at least some parts of what | ||
45 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
46 | */ | ||
47 | #include "usbstring.c" | 40 | #include "usbstring.c" |
48 | #include "config.c" | 41 | #include "config.c" |
49 | #include "epautoconf.c" | 42 | #include "epautoconf.c" |
43 | #include "f_midi.c" | ||
50 | 44 | ||
51 | /*-------------------------------------------------------------------------*/ | 45 | /*-------------------------------------------------------------------------*/ |
52 | 46 | ||
53 | |||
54 | MODULE_AUTHOR("Ben Williamson"); | 47 | MODULE_AUTHOR("Ben Williamson"); |
55 | MODULE_LICENSE("GPL v2"); | 48 | MODULE_LICENSE("GPL v2"); |
56 | 49 | ||
57 | #define DRIVER_VERSION "25 Jul 2006" | ||
58 | |||
59 | static const char shortname[] = "g_midi"; | 50 | static const char shortname[] = "g_midi"; |
60 | static const char longname[] = "MIDI Gadget"; | 51 | static const char longname[] = "MIDI Gadget"; |
61 | 52 | ||
62 | static int index = SNDRV_DEFAULT_IDX1; | 53 | static int index = SNDRV_DEFAULT_IDX1; |
63 | static char *id = SNDRV_DEFAULT_STR1; | 54 | module_param(index, int, S_IRUGO); |
64 | |||
65 | module_param(index, int, 0444); | ||
66 | MODULE_PARM_DESC(index, "Index value for the USB MIDI Gadget adapter."); | 55 | MODULE_PARM_DESC(index, "Index value for the USB MIDI Gadget adapter."); |
67 | module_param(id, charp, 0444); | ||
68 | MODULE_PARM_DESC(id, "ID string for the USB MIDI Gadget adapter."); | ||
69 | |||
70 | /* Some systems will want different product identifiers published in the | ||
71 | * device descriptor, either numbers or strings or both. These string | ||
72 | * parameters are in UTF-8 (superset of ASCII's 7 bit characters). | ||
73 | */ | ||
74 | |||
75 | static ushort idVendor; | ||
76 | module_param(idVendor, ushort, S_IRUGO); | ||
77 | MODULE_PARM_DESC(idVendor, "USB Vendor ID"); | ||
78 | |||
79 | static ushort idProduct; | ||
80 | module_param(idProduct, ushort, S_IRUGO); | ||
81 | MODULE_PARM_DESC(idProduct, "USB Product ID"); | ||
82 | |||
83 | static ushort bcdDevice; | ||
84 | module_param(bcdDevice, ushort, S_IRUGO); | ||
85 | MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); | ||
86 | |||
87 | static char *iManufacturer; | ||
88 | module_param(iManufacturer, charp, S_IRUGO); | ||
89 | MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string"); | ||
90 | |||
91 | static char *iProduct; | ||
92 | module_param(iProduct, charp, S_IRUGO); | ||
93 | MODULE_PARM_DESC(iProduct, "USB Product string"); | ||
94 | |||
95 | static char *iSerialNumber; | ||
96 | module_param(iSerialNumber, charp, S_IRUGO); | ||
97 | MODULE_PARM_DESC(iSerialNumber, "SerialNumber"); | ||
98 | |||
99 | /* | ||
100 | * this version autoconfigures as much as possible, | ||
101 | * which is reasonable for most "bulk-only" drivers. | ||
102 | */ | ||
103 | static const char *EP_IN_NAME; | ||
104 | static const char *EP_OUT_NAME; | ||
105 | 56 | ||
57 | static char *id = SNDRV_DEFAULT_STR1; | ||
58 | module_param(id, charp, S_IRUGO); | ||
59 | MODULE_PARM_DESC(id, "ID string for the USB MIDI Gadget adapter."); | ||
106 | 60 | ||
107 | /* big enough to hold our biggest descriptor */ | 61 | static unsigned int buflen = 256; |
108 | #define USB_BUFSIZ 256 | ||
109 | |||
110 | |||
111 | /* This is a gadget, and the IN/OUT naming is from the host's perspective. | ||
112 | USB -> OUT endpoint -> rawmidi | ||
113 | USB <- IN endpoint <- rawmidi */ | ||
114 | struct gmidi_in_port { | ||
115 | struct gmidi_device* dev; | ||
116 | int active; | ||
117 | uint8_t cable; /* cable number << 4 */ | ||
118 | uint8_t state; | ||
119 | #define STATE_UNKNOWN 0 | ||
120 | #define STATE_1PARAM 1 | ||
121 | #define STATE_2PARAM_1 2 | ||
122 | #define STATE_2PARAM_2 3 | ||
123 | #define STATE_SYSEX_0 4 | ||
124 | #define STATE_SYSEX_1 5 | ||
125 | #define STATE_SYSEX_2 6 | ||
126 | uint8_t data[2]; | ||
127 | }; | ||
128 | |||
129 | struct gmidi_device { | ||
130 | spinlock_t lock; | ||
131 | struct usb_gadget *gadget; | ||
132 | struct usb_request *req; /* for control responses */ | ||
133 | u8 config; | ||
134 | struct usb_ep *in_ep, *out_ep; | ||
135 | struct snd_card *card; | ||
136 | struct snd_rawmidi *rmidi; | ||
137 | struct snd_rawmidi_substream *in_substream; | ||
138 | struct snd_rawmidi_substream *out_substream; | ||
139 | |||
140 | /* For the moment we only support one port in | ||
141 | each direction, but in_port is kept as a | ||
142 | separate struct so we can have more later. */ | ||
143 | struct gmidi_in_port in_port; | ||
144 | unsigned long out_triggered; | ||
145 | struct tasklet_struct tasklet; | ||
146 | }; | ||
147 | |||
148 | static void gmidi_transmit(struct gmidi_device* dev, struct usb_request* req); | ||
149 | |||
150 | |||
151 | #define DBG(d, fmt, args...) \ | ||
152 | dev_dbg(&(d)->gadget->dev , fmt , ## args) | ||
153 | #define VDBG(d, fmt, args...) \ | ||
154 | dev_vdbg(&(d)->gadget->dev , fmt , ## args) | ||
155 | #define ERROR(d, fmt, args...) \ | ||
156 | dev_err(&(d)->gadget->dev , fmt , ## args) | ||
157 | #define INFO(d, fmt, args...) \ | ||
158 | dev_info(&(d)->gadget->dev , fmt , ## args) | ||
159 | |||
160 | |||
161 | static unsigned buflen = 256; | ||
162 | static unsigned qlen = 32; | ||
163 | |||
164 | module_param(buflen, uint, S_IRUGO); | 62 | module_param(buflen, uint, S_IRUGO); |
63 | MODULE_PARM_DESC(buflen, "MIDI buffer length"); | ||
64 | |||
65 | static unsigned int qlen = 32; | ||
165 | module_param(qlen, uint, S_IRUGO); | 66 | module_param(qlen, uint, S_IRUGO); |
67 | MODULE_PARM_DESC(qlen, "USB read request queue length"); | ||
166 | 68 | ||
69 | static unsigned int in_ports = 1; | ||
70 | module_param(in_ports, uint, S_IRUGO); | ||
71 | MODULE_PARM_DESC(in_ports, "Number of MIDI input ports"); | ||
72 | |||
73 | static unsigned int out_ports = 1; | ||
74 | module_param(out_ports, uint, S_IRUGO); | ||
75 | MODULE_PARM_DESC(out_ports, "Number of MIDI output ports"); | ||
167 | 76 | ||
168 | /* Thanks to Grey Innovation for donating this product ID. | 77 | /* Thanks to Grey Innovation for donating this product ID. |
169 | * | 78 | * |
@@ -173,1149 +82,124 @@ module_param(qlen, uint, S_IRUGO); | |||
173 | #define DRIVER_VENDOR_NUM 0x17b3 /* Grey Innovation */ | 82 | #define DRIVER_VENDOR_NUM 0x17b3 /* Grey Innovation */ |
174 | #define DRIVER_PRODUCT_NUM 0x0004 /* Linux-USB "MIDI Gadget" */ | 83 | #define DRIVER_PRODUCT_NUM 0x0004 /* Linux-USB "MIDI Gadget" */ |
175 | 84 | ||
85 | /* string IDs are assigned dynamically */ | ||
176 | 86 | ||
177 | /* | 87 | #define STRING_MANUFACTURER_IDX 0 |
178 | * DESCRIPTORS ... most are static, but strings and (full) | 88 | #define STRING_PRODUCT_IDX 1 |
179 | * configuration descriptors are built on demand. | 89 | #define STRING_DESCRIPTION_IDX 2 |
180 | */ | ||
181 | |||
182 | #define STRING_MANUFACTURER 25 | ||
183 | #define STRING_PRODUCT 42 | ||
184 | #define STRING_SERIAL 101 | ||
185 | #define STRING_MIDI_GADGET 250 | ||
186 | 90 | ||
187 | /* We only have the one configuration, it's number 1. */ | ||
188 | #define GMIDI_CONFIG 1 | ||
189 | |||
190 | /* We have two interfaces- AudioControl and MIDIStreaming */ | ||
191 | #define GMIDI_AC_INTERFACE 0 | ||
192 | #define GMIDI_MS_INTERFACE 1 | ||
193 | #define GMIDI_NUM_INTERFACES 2 | ||
194 | |||
195 | DECLARE_UAC_AC_HEADER_DESCRIPTOR(1); | ||
196 | DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1); | ||
197 | DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(1); | ||
198 | |||
199 | /* B.1 Device Descriptor */ | ||
200 | static struct usb_device_descriptor device_desc = { | 91 | static struct usb_device_descriptor device_desc = { |
201 | .bLength = USB_DT_DEVICE_SIZE, | 92 | .bLength = USB_DT_DEVICE_SIZE, |
202 | .bDescriptorType = USB_DT_DEVICE, | 93 | .bDescriptorType = USB_DT_DEVICE, |
203 | .bcdUSB = cpu_to_le16(0x0200), | 94 | .bcdUSB = __constant_cpu_to_le16(0x0200), |
204 | .bDeviceClass = USB_CLASS_PER_INTERFACE, | 95 | .bDeviceClass = USB_CLASS_PER_INTERFACE, |
205 | .idVendor = cpu_to_le16(DRIVER_VENDOR_NUM), | 96 | .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM), |
206 | .idProduct = cpu_to_le16(DRIVER_PRODUCT_NUM), | 97 | .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_NUM), |
207 | .iManufacturer = STRING_MANUFACTURER, | 98 | /* .iManufacturer = DYNAMIC */ |
208 | .iProduct = STRING_PRODUCT, | 99 | /* .iProduct = DYNAMIC */ |
209 | .bNumConfigurations = 1, | 100 | .bNumConfigurations = 1, |
210 | }; | 101 | }; |
211 | 102 | ||
212 | /* B.2 Configuration Descriptor */ | 103 | static struct usb_string strings_dev[] = { |
213 | static struct usb_config_descriptor config_desc = { | 104 | [STRING_MANUFACTURER_IDX].s = "Grey Innovation", |
214 | .bLength = USB_DT_CONFIG_SIZE, | 105 | [STRING_PRODUCT_IDX].s = "MIDI Gadget", |
215 | .bDescriptorType = USB_DT_CONFIG, | 106 | [STRING_DESCRIPTION_IDX].s = "MIDI", |
216 | /* compute wTotalLength on the fly */ | 107 | { } /* end of list */ |
217 | .bNumInterfaces = GMIDI_NUM_INTERFACES, | ||
218 | .bConfigurationValue = GMIDI_CONFIG, | ||
219 | .iConfiguration = STRING_MIDI_GADGET, | ||
220 | /* | ||
221 | * FIXME: When embedding this driver in a device, | ||
222 | * these need to be set to reflect the actual | ||
223 | * power properties of the device. Is it selfpowered? | ||
224 | */ | ||
225 | .bmAttributes = USB_CONFIG_ATT_ONE, | ||
226 | .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, | ||
227 | }; | ||
228 | |||
229 | /* B.3.1 Standard AC Interface Descriptor */ | ||
230 | static const struct usb_interface_descriptor ac_interface_desc = { | ||
231 | .bLength = USB_DT_INTERFACE_SIZE, | ||
232 | .bDescriptorType = USB_DT_INTERFACE, | ||
233 | .bInterfaceNumber = GMIDI_AC_INTERFACE, | ||
234 | .bNumEndpoints = 0, | ||
235 | .bInterfaceClass = USB_CLASS_AUDIO, | ||
236 | .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL, | ||
237 | .iInterface = STRING_MIDI_GADGET, | ||
238 | }; | ||
239 | |||
240 | /* B.3.2 Class-Specific AC Interface Descriptor */ | ||
241 | static const struct uac1_ac_header_descriptor_1 ac_header_desc = { | ||
242 | .bLength = UAC_DT_AC_HEADER_SIZE(1), | ||
243 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
244 | .bDescriptorSubtype = USB_MS_HEADER, | ||
245 | .bcdADC = cpu_to_le16(0x0100), | ||
246 | .wTotalLength = cpu_to_le16(UAC_DT_AC_HEADER_SIZE(1)), | ||
247 | .bInCollection = 1, | ||
248 | .baInterfaceNr = { | ||
249 | [0] = GMIDI_MS_INTERFACE, | ||
250 | } | ||
251 | }; | ||
252 | |||
253 | /* B.4.1 Standard MS Interface Descriptor */ | ||
254 | static const struct usb_interface_descriptor ms_interface_desc = { | ||
255 | .bLength = USB_DT_INTERFACE_SIZE, | ||
256 | .bDescriptorType = USB_DT_INTERFACE, | ||
257 | .bInterfaceNumber = GMIDI_MS_INTERFACE, | ||
258 | .bNumEndpoints = 2, | ||
259 | .bInterfaceClass = USB_CLASS_AUDIO, | ||
260 | .bInterfaceSubClass = USB_SUBCLASS_MIDISTREAMING, | ||
261 | .iInterface = STRING_MIDI_GADGET, | ||
262 | }; | 108 | }; |
263 | 109 | ||
264 | /* B.4.2 Class-Specific MS Interface Descriptor */ | 110 | static struct usb_gadget_strings stringtab_dev = { |
265 | static const struct usb_ms_header_descriptor ms_header_desc = { | ||
266 | .bLength = USB_DT_MS_HEADER_SIZE, | ||
267 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
268 | .bDescriptorSubtype = USB_MS_HEADER, | ||
269 | .bcdMSC = cpu_to_le16(0x0100), | ||
270 | .wTotalLength = cpu_to_le16(USB_DT_MS_HEADER_SIZE | ||
271 | + 2*USB_DT_MIDI_IN_SIZE | ||
272 | + 2*USB_DT_MIDI_OUT_SIZE(1)), | ||
273 | }; | ||
274 | |||
275 | #define JACK_IN_EMB 1 | ||
276 | #define JACK_IN_EXT 2 | ||
277 | #define JACK_OUT_EMB 3 | ||
278 | #define JACK_OUT_EXT 4 | ||
279 | |||
280 | /* B.4.3 MIDI IN Jack Descriptors */ | ||
281 | static const struct usb_midi_in_jack_descriptor jack_in_emb_desc = { | ||
282 | .bLength = USB_DT_MIDI_IN_SIZE, | ||
283 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
284 | .bDescriptorSubtype = USB_MS_MIDI_IN_JACK, | ||
285 | .bJackType = USB_MS_EMBEDDED, | ||
286 | .bJackID = JACK_IN_EMB, | ||
287 | }; | ||
288 | |||
289 | static const struct usb_midi_in_jack_descriptor jack_in_ext_desc = { | ||
290 | .bLength = USB_DT_MIDI_IN_SIZE, | ||
291 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
292 | .bDescriptorSubtype = USB_MS_MIDI_IN_JACK, | ||
293 | .bJackType = USB_MS_EXTERNAL, | ||
294 | .bJackID = JACK_IN_EXT, | ||
295 | }; | ||
296 | |||
297 | /* B.4.4 MIDI OUT Jack Descriptors */ | ||
298 | static const struct usb_midi_out_jack_descriptor_1 jack_out_emb_desc = { | ||
299 | .bLength = USB_DT_MIDI_OUT_SIZE(1), | ||
300 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
301 | .bDescriptorSubtype = USB_MS_MIDI_OUT_JACK, | ||
302 | .bJackType = USB_MS_EMBEDDED, | ||
303 | .bJackID = JACK_OUT_EMB, | ||
304 | .bNrInputPins = 1, | ||
305 | .pins = { | ||
306 | [0] = { | ||
307 | .baSourceID = JACK_IN_EXT, | ||
308 | .baSourcePin = 1, | ||
309 | } | ||
310 | } | ||
311 | }; | ||
312 | |||
313 | static const struct usb_midi_out_jack_descriptor_1 jack_out_ext_desc = { | ||
314 | .bLength = USB_DT_MIDI_OUT_SIZE(1), | ||
315 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
316 | .bDescriptorSubtype = USB_MS_MIDI_OUT_JACK, | ||
317 | .bJackType = USB_MS_EXTERNAL, | ||
318 | .bJackID = JACK_OUT_EXT, | ||
319 | .bNrInputPins = 1, | ||
320 | .pins = { | ||
321 | [0] = { | ||
322 | .baSourceID = JACK_IN_EMB, | ||
323 | .baSourcePin = 1, | ||
324 | } | ||
325 | } | ||
326 | }; | ||
327 | |||
328 | /* B.5.1 Standard Bulk OUT Endpoint Descriptor */ | ||
329 | static struct usb_endpoint_descriptor bulk_out_desc = { | ||
330 | .bLength = USB_DT_ENDPOINT_AUDIO_SIZE, | ||
331 | .bDescriptorType = USB_DT_ENDPOINT, | ||
332 | .bEndpointAddress = USB_DIR_OUT, | ||
333 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
334 | }; | ||
335 | |||
336 | /* B.5.2 Class-specific MS Bulk OUT Endpoint Descriptor */ | ||
337 | static const struct usb_ms_endpoint_descriptor_1 ms_out_desc = { | ||
338 | .bLength = USB_DT_MS_ENDPOINT_SIZE(1), | ||
339 | .bDescriptorType = USB_DT_CS_ENDPOINT, | ||
340 | .bDescriptorSubtype = USB_MS_GENERAL, | ||
341 | .bNumEmbMIDIJack = 1, | ||
342 | .baAssocJackID = { | ||
343 | [0] = JACK_IN_EMB, | ||
344 | } | ||
345 | }; | ||
346 | |||
347 | /* B.6.1 Standard Bulk IN Endpoint Descriptor */ | ||
348 | static struct usb_endpoint_descriptor bulk_in_desc = { | ||
349 | .bLength = USB_DT_ENDPOINT_AUDIO_SIZE, | ||
350 | .bDescriptorType = USB_DT_ENDPOINT, | ||
351 | .bEndpointAddress = USB_DIR_IN, | ||
352 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
353 | }; | ||
354 | |||
355 | /* B.6.2 Class-specific MS Bulk IN Endpoint Descriptor */ | ||
356 | static const struct usb_ms_endpoint_descriptor_1 ms_in_desc = { | ||
357 | .bLength = USB_DT_MS_ENDPOINT_SIZE(1), | ||
358 | .bDescriptorType = USB_DT_CS_ENDPOINT, | ||
359 | .bDescriptorSubtype = USB_MS_GENERAL, | ||
360 | .bNumEmbMIDIJack = 1, | ||
361 | .baAssocJackID = { | ||
362 | [0] = JACK_OUT_EMB, | ||
363 | } | ||
364 | }; | ||
365 | |||
366 | static const struct usb_descriptor_header *gmidi_function [] = { | ||
367 | (struct usb_descriptor_header *)&ac_interface_desc, | ||
368 | (struct usb_descriptor_header *)&ac_header_desc, | ||
369 | (struct usb_descriptor_header *)&ms_interface_desc, | ||
370 | |||
371 | (struct usb_descriptor_header *)&ms_header_desc, | ||
372 | (struct usb_descriptor_header *)&jack_in_emb_desc, | ||
373 | (struct usb_descriptor_header *)&jack_in_ext_desc, | ||
374 | (struct usb_descriptor_header *)&jack_out_emb_desc, | ||
375 | (struct usb_descriptor_header *)&jack_out_ext_desc, | ||
376 | /* If you add more jacks, update ms_header_desc.wTotalLength */ | ||
377 | |||
378 | (struct usb_descriptor_header *)&bulk_out_desc, | ||
379 | (struct usb_descriptor_header *)&ms_out_desc, | ||
380 | (struct usb_descriptor_header *)&bulk_in_desc, | ||
381 | (struct usb_descriptor_header *)&ms_in_desc, | ||
382 | NULL, | ||
383 | }; | ||
384 | |||
385 | static char manufacturer[50]; | ||
386 | static char product_desc[40] = "MIDI Gadget"; | ||
387 | static char serial_number[20]; | ||
388 | |||
389 | /* static strings, in UTF-8 */ | ||
390 | static struct usb_string strings [] = { | ||
391 | { STRING_MANUFACTURER, manufacturer, }, | ||
392 | { STRING_PRODUCT, product_desc, }, | ||
393 | { STRING_SERIAL, serial_number, }, | ||
394 | { STRING_MIDI_GADGET, longname, }, | ||
395 | { } /* end of list */ | ||
396 | }; | ||
397 | |||
398 | static struct usb_gadget_strings stringtab = { | ||
399 | .language = 0x0409, /* en-us */ | 111 | .language = 0x0409, /* en-us */ |
400 | .strings = strings, | 112 | .strings = strings_dev, |
401 | }; | 113 | }; |
402 | 114 | ||
403 | static int config_buf(struct usb_gadget *gadget, | 115 | static struct usb_gadget_strings *dev_strings[] = { |
404 | u8 *buf, u8 type, unsigned index) | 116 | &stringtab_dev, |
405 | { | 117 | NULL, |
406 | int len; | ||
407 | |||
408 | /* only one configuration */ | ||
409 | if (index != 0) { | ||
410 | return -EINVAL; | ||
411 | } | ||
412 | len = usb_gadget_config_buf(&config_desc, | ||
413 | buf, USB_BUFSIZ, gmidi_function); | ||
414 | if (len < 0) { | ||
415 | return len; | ||
416 | } | ||
417 | ((struct usb_config_descriptor *)buf)->bDescriptorType = type; | ||
418 | return len; | ||
419 | } | ||
420 | |||
421 | static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length) | ||
422 | { | ||
423 | struct usb_request *req; | ||
424 | |||
425 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); | ||
426 | if (req) { | ||
427 | req->length = length; | ||
428 | req->buf = kmalloc(length, GFP_ATOMIC); | ||
429 | if (!req->buf) { | ||
430 | usb_ep_free_request(ep, req); | ||
431 | req = NULL; | ||
432 | } | ||
433 | } | ||
434 | return req; | ||
435 | } | ||
436 | |||
437 | static void free_ep_req(struct usb_ep *ep, struct usb_request *req) | ||
438 | { | ||
439 | kfree(req->buf); | ||
440 | usb_ep_free_request(ep, req); | ||
441 | } | ||
442 | |||
443 | static const uint8_t gmidi_cin_length[] = { | ||
444 | 0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1 | ||
445 | }; | 118 | }; |
446 | 119 | ||
447 | /* | 120 | static int __exit midi_unbind(struct usb_composite_dev *dev) |
448 | * Receives a chunk of MIDI data. | ||
449 | */ | ||
450 | static void gmidi_read_data(struct usb_ep *ep, int cable, | ||
451 | uint8_t *data, int length) | ||
452 | { | ||
453 | struct gmidi_device *dev = ep->driver_data; | ||
454 | /* cable is ignored, because for now we only have one. */ | ||
455 | |||
456 | if (!dev->out_substream) { | ||
457 | /* Nobody is listening - throw it on the floor. */ | ||
458 | return; | ||
459 | } | ||
460 | if (!test_bit(dev->out_substream->number, &dev->out_triggered)) { | ||
461 | return; | ||
462 | } | ||
463 | snd_rawmidi_receive(dev->out_substream, data, length); | ||
464 | } | ||
465 | |||
466 | static void gmidi_handle_out_data(struct usb_ep *ep, struct usb_request *req) | ||
467 | { | ||
468 | unsigned i; | ||
469 | u8 *buf = req->buf; | ||
470 | |||
471 | for (i = 0; i + 3 < req->actual; i += 4) { | ||
472 | if (buf[i] != 0) { | ||
473 | int cable = buf[i] >> 4; | ||
474 | int length = gmidi_cin_length[buf[i] & 0x0f]; | ||
475 | gmidi_read_data(ep, cable, &buf[i + 1], length); | ||
476 | } | ||
477 | } | ||
478 | } | ||
479 | |||
480 | static void gmidi_complete(struct usb_ep *ep, struct usb_request *req) | ||
481 | { | ||
482 | struct gmidi_device *dev = ep->driver_data; | ||
483 | int status = req->status; | ||
484 | |||
485 | switch (status) { | ||
486 | case 0: /* normal completion */ | ||
487 | if (ep == dev->out_ep) { | ||
488 | /* we received stuff. | ||
489 | req is queued again, below */ | ||
490 | gmidi_handle_out_data(ep, req); | ||
491 | } else if (ep == dev->in_ep) { | ||
492 | /* our transmit completed. | ||
493 | see if there's more to go. | ||
494 | gmidi_transmit eats req, don't queue it again. */ | ||
495 | gmidi_transmit(dev, req); | ||
496 | return; | ||
497 | } | ||
498 | break; | ||
499 | |||
500 | /* this endpoint is normally active while we're configured */ | ||
501 | case -ECONNABORTED: /* hardware forced ep reset */ | ||
502 | case -ECONNRESET: /* request dequeued */ | ||
503 | case -ESHUTDOWN: /* disconnect from host */ | ||
504 | VDBG(dev, "%s gone (%d), %d/%d\n", ep->name, status, | ||
505 | req->actual, req->length); | ||
506 | if (ep == dev->out_ep) { | ||
507 | gmidi_handle_out_data(ep, req); | ||
508 | } | ||
509 | free_ep_req(ep, req); | ||
510 | return; | ||
511 | |||
512 | case -EOVERFLOW: /* buffer overrun on read means that | ||
513 | * we didn't provide a big enough | ||
514 | * buffer. | ||
515 | */ | ||
516 | default: | ||
517 | DBG(dev, "%s complete --> %d, %d/%d\n", ep->name, | ||
518 | status, req->actual, req->length); | ||
519 | break; | ||
520 | case -EREMOTEIO: /* short read */ | ||
521 | break; | ||
522 | } | ||
523 | |||
524 | status = usb_ep_queue(ep, req, GFP_ATOMIC); | ||
525 | if (status) { | ||
526 | ERROR(dev, "kill %s: resubmit %d bytes --> %d\n", | ||
527 | ep->name, req->length, status); | ||
528 | usb_ep_set_halt(ep); | ||
529 | /* FIXME recover later ... somehow */ | ||
530 | } | ||
531 | } | ||
532 | |||
533 | static int set_gmidi_config(struct gmidi_device *dev, gfp_t gfp_flags) | ||
534 | { | ||
535 | int err = 0; | ||
536 | struct usb_request *req; | ||
537 | struct usb_ep *ep; | ||
538 | unsigned i; | ||
539 | |||
540 | dev->in_ep->desc = &bulk_in_desc; | ||
541 | err = usb_ep_enable(dev->in_ep); | ||
542 | if (err) { | ||
543 | ERROR(dev, "can't start %s: %d\n", dev->in_ep->name, err); | ||
544 | goto fail; | ||
545 | } | ||
546 | dev->in_ep->driver_data = dev; | ||
547 | |||
548 | dev->out_ep->desc = &bulk_out_desc; | ||
549 | err = usb_ep_enable(dev->out_ep); | ||
550 | if (err) { | ||
551 | ERROR(dev, "can't start %s: %d\n", dev->out_ep->name, err); | ||
552 | goto fail; | ||
553 | } | ||
554 | dev->out_ep->driver_data = dev; | ||
555 | |||
556 | /* allocate a bunch of read buffers and queue them all at once. */ | ||
557 | ep = dev->out_ep; | ||
558 | for (i = 0; i < qlen && err == 0; i++) { | ||
559 | req = alloc_ep_req(ep, buflen); | ||
560 | if (req) { | ||
561 | req->complete = gmidi_complete; | ||
562 | err = usb_ep_queue(ep, req, GFP_ATOMIC); | ||
563 | if (err) { | ||
564 | DBG(dev, "%s queue req: %d\n", ep->name, err); | ||
565 | } | ||
566 | } else { | ||
567 | err = -ENOMEM; | ||
568 | } | ||
569 | } | ||
570 | fail: | ||
571 | /* caller is responsible for cleanup on error */ | ||
572 | return err; | ||
573 | } | ||
574 | |||
575 | |||
576 | static void gmidi_reset_config(struct gmidi_device *dev) | ||
577 | { | ||
578 | if (dev->config == 0) { | ||
579 | return; | ||
580 | } | ||
581 | |||
582 | DBG(dev, "reset config\n"); | ||
583 | |||
584 | /* just disable endpoints, forcing completion of pending i/o. | ||
585 | * all our completion handlers free their requests in this case. | ||
586 | */ | ||
587 | usb_ep_disable(dev->in_ep); | ||
588 | usb_ep_disable(dev->out_ep); | ||
589 | dev->config = 0; | ||
590 | } | ||
591 | |||
592 | /* change our operational config. this code must agree with the code | ||
593 | * that returns config descriptors, and altsetting code. | ||
594 | * | ||
595 | * it's also responsible for power management interactions. some | ||
596 | * configurations might not work with our current power sources. | ||
597 | * | ||
598 | * note that some device controller hardware will constrain what this | ||
599 | * code can do, perhaps by disallowing more than one configuration or | ||
600 | * by limiting configuration choices (like the pxa2xx). | ||
601 | */ | ||
602 | static int | ||
603 | gmidi_set_config(struct gmidi_device *dev, unsigned number, gfp_t gfp_flags) | ||
604 | { | ||
605 | int result = 0; | ||
606 | struct usb_gadget *gadget = dev->gadget; | ||
607 | |||
608 | #if 0 | ||
609 | /* FIXME */ | ||
610 | /* Hacking this bit out fixes a bug where on receipt of two | ||
611 | USB_REQ_SET_CONFIGURATION messages, we end up with no | ||
612 | buffered OUT requests waiting for data. This is clearly | ||
613 | hiding a bug elsewhere, because if the config didn't | ||
614 | change then we really shouldn't do anything. */ | ||
615 | /* Having said that, when we do "change" from config 1 | ||
616 | to config 1, we at least gmidi_reset_config() which | ||
617 | clears out any requests on endpoints, so it's not like | ||
618 | we leak or anything. */ | ||
619 | if (number == dev->config) { | ||
620 | return 0; | ||
621 | } | ||
622 | #endif | ||
623 | |||
624 | gmidi_reset_config(dev); | ||
625 | |||
626 | switch (number) { | ||
627 | case GMIDI_CONFIG: | ||
628 | result = set_gmidi_config(dev, gfp_flags); | ||
629 | break; | ||
630 | default: | ||
631 | result = -EINVAL; | ||
632 | /* FALL THROUGH */ | ||
633 | case 0: | ||
634 | return result; | ||
635 | } | ||
636 | |||
637 | if (!result && (!dev->in_ep || !dev->out_ep)) { | ||
638 | result = -ENODEV; | ||
639 | } | ||
640 | if (result) { | ||
641 | gmidi_reset_config(dev); | ||
642 | } else { | ||
643 | char *speed; | ||
644 | |||
645 | switch (gadget->speed) { | ||
646 | case USB_SPEED_LOW: speed = "low"; break; | ||
647 | case USB_SPEED_FULL: speed = "full"; break; | ||
648 | case USB_SPEED_HIGH: speed = "high"; break; | ||
649 | default: speed = "?"; break; | ||
650 | } | ||
651 | |||
652 | dev->config = number; | ||
653 | INFO(dev, "%s speed\n", speed); | ||
654 | } | ||
655 | return result; | ||
656 | } | ||
657 | |||
658 | |||
659 | static void gmidi_setup_complete(struct usb_ep *ep, struct usb_request *req) | ||
660 | { | ||
661 | if (req->status || req->actual != req->length) { | ||
662 | DBG((struct gmidi_device *) ep->driver_data, | ||
663 | "setup complete --> %d, %d/%d\n", | ||
664 | req->status, req->actual, req->length); | ||
665 | } | ||
666 | } | ||
667 | |||
668 | /* | ||
669 | * The setup() callback implements all the ep0 functionality that's | ||
670 | * not handled lower down, in hardware or the hardware driver (like | ||
671 | * device and endpoint feature flags, and their status). It's all | ||
672 | * housekeeping for the gadget function we're implementing. Most of | ||
673 | * the work is in config-specific setup. | ||
674 | */ | ||
675 | static int gmidi_setup(struct usb_gadget *gadget, | ||
676 | const struct usb_ctrlrequest *ctrl) | ||
677 | { | ||
678 | struct gmidi_device *dev = get_gadget_data(gadget); | ||
679 | struct usb_request *req = dev->req; | ||
680 | int value = -EOPNOTSUPP; | ||
681 | u16 w_index = le16_to_cpu(ctrl->wIndex); | ||
682 | u16 w_value = le16_to_cpu(ctrl->wValue); | ||
683 | u16 w_length = le16_to_cpu(ctrl->wLength); | ||
684 | |||
685 | /* usually this stores reply data in the pre-allocated ep0 buffer, | ||
686 | * but config change events will reconfigure hardware. | ||
687 | */ | ||
688 | req->zero = 0; | ||
689 | switch (ctrl->bRequest) { | ||
690 | |||
691 | case USB_REQ_GET_DESCRIPTOR: | ||
692 | if (ctrl->bRequestType != USB_DIR_IN) { | ||
693 | goto unknown; | ||
694 | } | ||
695 | switch (w_value >> 8) { | ||
696 | |||
697 | case USB_DT_DEVICE: | ||
698 | device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket; | ||
699 | value = min(w_length, (u16) sizeof(device_desc)); | ||
700 | memcpy(req->buf, &device_desc, value); | ||
701 | break; | ||
702 | case USB_DT_CONFIG: | ||
703 | value = config_buf(gadget, req->buf, | ||
704 | w_value >> 8, | ||
705 | w_value & 0xff); | ||
706 | if (value >= 0) { | ||
707 | value = min(w_length, (u16)value); | ||
708 | } | ||
709 | break; | ||
710 | |||
711 | case USB_DT_STRING: | ||
712 | /* wIndex == language code. | ||
713 | * this driver only handles one language, you can | ||
714 | * add string tables for other languages, using | ||
715 | * any UTF-8 characters | ||
716 | */ | ||
717 | value = usb_gadget_get_string(&stringtab, | ||
718 | w_value & 0xff, req->buf); | ||
719 | if (value >= 0) { | ||
720 | value = min(w_length, (u16)value); | ||
721 | } | ||
722 | break; | ||
723 | } | ||
724 | break; | ||
725 | |||
726 | /* currently two configs, two speeds */ | ||
727 | case USB_REQ_SET_CONFIGURATION: | ||
728 | if (ctrl->bRequestType != 0) { | ||
729 | goto unknown; | ||
730 | } | ||
731 | if (gadget->a_hnp_support) { | ||
732 | DBG(dev, "HNP available\n"); | ||
733 | } else if (gadget->a_alt_hnp_support) { | ||
734 | DBG(dev, "HNP needs a different root port\n"); | ||
735 | } else { | ||
736 | VDBG(dev, "HNP inactive\n"); | ||
737 | } | ||
738 | spin_lock(&dev->lock); | ||
739 | value = gmidi_set_config(dev, w_value, GFP_ATOMIC); | ||
740 | spin_unlock(&dev->lock); | ||
741 | break; | ||
742 | case USB_REQ_GET_CONFIGURATION: | ||
743 | if (ctrl->bRequestType != USB_DIR_IN) { | ||
744 | goto unknown; | ||
745 | } | ||
746 | *(u8 *)req->buf = dev->config; | ||
747 | value = min(w_length, (u16)1); | ||
748 | break; | ||
749 | |||
750 | /* until we add altsetting support, or other interfaces, | ||
751 | * only 0/0 are possible. pxa2xx only supports 0/0 (poorly) | ||
752 | * and already killed pending endpoint I/O. | ||
753 | */ | ||
754 | case USB_REQ_SET_INTERFACE: | ||
755 | if (ctrl->bRequestType != USB_RECIP_INTERFACE) { | ||
756 | goto unknown; | ||
757 | } | ||
758 | spin_lock(&dev->lock); | ||
759 | if (dev->config && w_index < GMIDI_NUM_INTERFACES | ||
760 | && w_value == 0) | ||
761 | { | ||
762 | u8 config = dev->config; | ||
763 | |||
764 | /* resets interface configuration, forgets about | ||
765 | * previous transaction state (queued bufs, etc) | ||
766 | * and re-inits endpoint state (toggle etc) | ||
767 | * no response queued, just zero status == success. | ||
768 | * if we had more than one interface we couldn't | ||
769 | * use this "reset the config" shortcut. | ||
770 | */ | ||
771 | gmidi_reset_config(dev); | ||
772 | gmidi_set_config(dev, config, GFP_ATOMIC); | ||
773 | value = 0; | ||
774 | } | ||
775 | spin_unlock(&dev->lock); | ||
776 | break; | ||
777 | case USB_REQ_GET_INTERFACE: | ||
778 | if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)) { | ||
779 | goto unknown; | ||
780 | } | ||
781 | if (!dev->config) { | ||
782 | break; | ||
783 | } | ||
784 | if (w_index >= GMIDI_NUM_INTERFACES) { | ||
785 | value = -EDOM; | ||
786 | break; | ||
787 | } | ||
788 | *(u8 *)req->buf = 0; | ||
789 | value = min(w_length, (u16)1); | ||
790 | break; | ||
791 | |||
792 | default: | ||
793 | unknown: | ||
794 | VDBG(dev, "unknown control req%02x.%02x v%04x i%04x l%d\n", | ||
795 | ctrl->bRequestType, ctrl->bRequest, | ||
796 | w_value, w_index, w_length); | ||
797 | } | ||
798 | |||
799 | /* respond with data transfer before status phase? */ | ||
800 | if (value >= 0) { | ||
801 | req->length = value; | ||
802 | req->zero = value < w_length; | ||
803 | value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); | ||
804 | if (value < 0) { | ||
805 | DBG(dev, "ep_queue --> %d\n", value); | ||
806 | req->status = 0; | ||
807 | gmidi_setup_complete(gadget->ep0, req); | ||
808 | } | ||
809 | } | ||
810 | |||
811 | /* device either stalls (value < 0) or reports success */ | ||
812 | return value; | ||
813 | } | ||
814 | |||
815 | static void gmidi_disconnect(struct usb_gadget *gadget) | ||
816 | { | ||
817 | struct gmidi_device *dev = get_gadget_data(gadget); | ||
818 | unsigned long flags; | ||
819 | |||
820 | spin_lock_irqsave(&dev->lock, flags); | ||
821 | gmidi_reset_config(dev); | ||
822 | |||
823 | /* a more significant application might have some non-usb | ||
824 | * activities to quiesce here, saving resources like power | ||
825 | * or pushing the notification up a network stack. | ||
826 | */ | ||
827 | spin_unlock_irqrestore(&dev->lock, flags); | ||
828 | |||
829 | /* next we may get setup() calls to enumerate new connections; | ||
830 | * or an unbind() during shutdown (including removing module). | ||
831 | */ | ||
832 | } | ||
833 | |||
834 | static void /* __init_or_exit */ gmidi_unbind(struct usb_gadget *gadget) | ||
835 | { | ||
836 | struct gmidi_device *dev = get_gadget_data(gadget); | ||
837 | struct snd_card *card; | ||
838 | |||
839 | DBG(dev, "unbind\n"); | ||
840 | |||
841 | card = dev->card; | ||
842 | dev->card = NULL; | ||
843 | if (card) { | ||
844 | snd_card_free(card); | ||
845 | } | ||
846 | |||
847 | /* we've already been disconnected ... no i/o is active */ | ||
848 | if (dev->req) { | ||
849 | dev->req->length = USB_BUFSIZ; | ||
850 | free_ep_req(gadget->ep0, dev->req); | ||
851 | } | ||
852 | kfree(dev); | ||
853 | set_gadget_data(gadget, NULL); | ||
854 | } | ||
855 | |||
856 | static int gmidi_snd_free(struct snd_device *device) | ||
857 | { | 121 | { |
858 | return 0; | 122 | return 0; |
859 | } | 123 | } |
860 | 124 | ||
861 | static void gmidi_transmit_packet(struct usb_request *req, uint8_t p0, | 125 | static struct usb_configuration midi_config = { |
862 | uint8_t p1, uint8_t p2, uint8_t p3) | 126 | .label = "MIDI Gadget", |
863 | { | 127 | .bConfigurationValue = 1, |
864 | unsigned length = req->length; | 128 | /* .iConfiguration = DYNAMIC */ |
865 | u8 *buf = (u8 *)req->buf + length; | 129 | .bmAttributes = USB_CONFIG_ATT_ONE, |
866 | 130 | .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, | |
867 | buf[0] = p0; | ||
868 | buf[1] = p1; | ||
869 | buf[2] = p2; | ||
870 | buf[3] = p3; | ||
871 | req->length = length + 4; | ||
872 | } | ||
873 | |||
874 | /* | ||
875 | * Converts MIDI commands to USB MIDI packets. | ||
876 | */ | ||
877 | static void gmidi_transmit_byte(struct usb_request *req, | ||
878 | struct gmidi_in_port *port, uint8_t b) | ||
879 | { | ||
880 | uint8_t p0 = port->cable; | ||
881 | |||
882 | if (b >= 0xf8) { | ||
883 | gmidi_transmit_packet(req, p0 | 0x0f, b, 0, 0); | ||
884 | } else if (b >= 0xf0) { | ||
885 | switch (b) { | ||
886 | case 0xf0: | ||
887 | port->data[0] = b; | ||
888 | port->state = STATE_SYSEX_1; | ||
889 | break; | ||
890 | case 0xf1: | ||
891 | case 0xf3: | ||
892 | port->data[0] = b; | ||
893 | port->state = STATE_1PARAM; | ||
894 | break; | ||
895 | case 0xf2: | ||
896 | port->data[0] = b; | ||
897 | port->state = STATE_2PARAM_1; | ||
898 | break; | ||
899 | case 0xf4: | ||
900 | case 0xf5: | ||
901 | port->state = STATE_UNKNOWN; | ||
902 | break; | ||
903 | case 0xf6: | ||
904 | gmidi_transmit_packet(req, p0 | 0x05, 0xf6, 0, 0); | ||
905 | port->state = STATE_UNKNOWN; | ||
906 | break; | ||
907 | case 0xf7: | ||
908 | switch (port->state) { | ||
909 | case STATE_SYSEX_0: | ||
910 | gmidi_transmit_packet(req, | ||
911 | p0 | 0x05, 0xf7, 0, 0); | ||
912 | break; | ||
913 | case STATE_SYSEX_1: | ||
914 | gmidi_transmit_packet(req, | ||
915 | p0 | 0x06, port->data[0], 0xf7, 0); | ||
916 | break; | ||
917 | case STATE_SYSEX_2: | ||
918 | gmidi_transmit_packet(req, | ||
919 | p0 | 0x07, port->data[0], | ||
920 | port->data[1], 0xf7); | ||
921 | break; | ||
922 | } | ||
923 | port->state = STATE_UNKNOWN; | ||
924 | break; | ||
925 | } | ||
926 | } else if (b >= 0x80) { | ||
927 | port->data[0] = b; | ||
928 | if (b >= 0xc0 && b <= 0xdf) | ||
929 | port->state = STATE_1PARAM; | ||
930 | else | ||
931 | port->state = STATE_2PARAM_1; | ||
932 | } else { /* b < 0x80 */ | ||
933 | switch (port->state) { | ||
934 | case STATE_1PARAM: | ||
935 | if (port->data[0] < 0xf0) { | ||
936 | p0 |= port->data[0] >> 4; | ||
937 | } else { | ||
938 | p0 |= 0x02; | ||
939 | port->state = STATE_UNKNOWN; | ||
940 | } | ||
941 | gmidi_transmit_packet(req, p0, port->data[0], b, 0); | ||
942 | break; | ||
943 | case STATE_2PARAM_1: | ||
944 | port->data[1] = b; | ||
945 | port->state = STATE_2PARAM_2; | ||
946 | break; | ||
947 | case STATE_2PARAM_2: | ||
948 | if (port->data[0] < 0xf0) { | ||
949 | p0 |= port->data[0] >> 4; | ||
950 | port->state = STATE_2PARAM_1; | ||
951 | } else { | ||
952 | p0 |= 0x03; | ||
953 | port->state = STATE_UNKNOWN; | ||
954 | } | ||
955 | gmidi_transmit_packet(req, | ||
956 | p0, port->data[0], port->data[1], b); | ||
957 | break; | ||
958 | case STATE_SYSEX_0: | ||
959 | port->data[0] = b; | ||
960 | port->state = STATE_SYSEX_1; | ||
961 | break; | ||
962 | case STATE_SYSEX_1: | ||
963 | port->data[1] = b; | ||
964 | port->state = STATE_SYSEX_2; | ||
965 | break; | ||
966 | case STATE_SYSEX_2: | ||
967 | gmidi_transmit_packet(req, | ||
968 | p0 | 0x04, port->data[0], port->data[1], b); | ||
969 | port->state = STATE_SYSEX_0; | ||
970 | break; | ||
971 | } | ||
972 | } | ||
973 | } | ||
974 | |||
975 | static void gmidi_transmit(struct gmidi_device *dev, struct usb_request *req) | ||
976 | { | ||
977 | struct usb_ep *ep = dev->in_ep; | ||
978 | struct gmidi_in_port *port = &dev->in_port; | ||
979 | |||
980 | if (!ep) { | ||
981 | return; | ||
982 | } | ||
983 | if (!req) { | ||
984 | req = alloc_ep_req(ep, buflen); | ||
985 | } | ||
986 | if (!req) { | ||
987 | ERROR(dev, "gmidi_transmit: alloc_ep_request failed\n"); | ||
988 | return; | ||
989 | } | ||
990 | req->length = 0; | ||
991 | req->complete = gmidi_complete; | ||
992 | |||
993 | if (port->active) { | ||
994 | while (req->length + 3 < buflen) { | ||
995 | uint8_t b; | ||
996 | if (snd_rawmidi_transmit(dev->in_substream, &b, 1) | ||
997 | != 1) | ||
998 | { | ||
999 | port->active = 0; | ||
1000 | break; | ||
1001 | } | ||
1002 | gmidi_transmit_byte(req, port, b); | ||
1003 | } | ||
1004 | } | ||
1005 | if (req->length > 0) { | ||
1006 | usb_ep_queue(ep, req, GFP_ATOMIC); | ||
1007 | } else { | ||
1008 | free_ep_req(ep, req); | ||
1009 | } | ||
1010 | } | ||
1011 | |||
1012 | static void gmidi_in_tasklet(unsigned long data) | ||
1013 | { | ||
1014 | struct gmidi_device *dev = (struct gmidi_device *)data; | ||
1015 | |||
1016 | gmidi_transmit(dev, NULL); | ||
1017 | } | ||
1018 | |||
1019 | static int gmidi_in_open(struct snd_rawmidi_substream *substream) | ||
1020 | { | ||
1021 | struct gmidi_device *dev = substream->rmidi->private_data; | ||
1022 | |||
1023 | VDBG(dev, "gmidi_in_open\n"); | ||
1024 | dev->in_substream = substream; | ||
1025 | dev->in_port.state = STATE_UNKNOWN; | ||
1026 | return 0; | ||
1027 | } | ||
1028 | |||
1029 | static int gmidi_in_close(struct snd_rawmidi_substream *substream) | ||
1030 | { | ||
1031 | struct gmidi_device *dev = substream->rmidi->private_data; | ||
1032 | |||
1033 | VDBG(dev, "gmidi_in_close\n"); | ||
1034 | return 0; | ||
1035 | } | ||
1036 | |||
1037 | static void gmidi_in_trigger(struct snd_rawmidi_substream *substream, int up) | ||
1038 | { | ||
1039 | struct gmidi_device *dev = substream->rmidi->private_data; | ||
1040 | |||
1041 | VDBG(dev, "gmidi_in_trigger %d\n", up); | ||
1042 | dev->in_port.active = up; | ||
1043 | if (up) { | ||
1044 | tasklet_hi_schedule(&dev->tasklet); | ||
1045 | } | ||
1046 | } | ||
1047 | |||
1048 | static int gmidi_out_open(struct snd_rawmidi_substream *substream) | ||
1049 | { | ||
1050 | struct gmidi_device *dev = substream->rmidi->private_data; | ||
1051 | |||
1052 | VDBG(dev, "gmidi_out_open\n"); | ||
1053 | dev->out_substream = substream; | ||
1054 | return 0; | ||
1055 | } | ||
1056 | |||
1057 | static int gmidi_out_close(struct snd_rawmidi_substream *substream) | ||
1058 | { | ||
1059 | struct gmidi_device *dev = substream->rmidi->private_data; | ||
1060 | |||
1061 | VDBG(dev, "gmidi_out_close\n"); | ||
1062 | return 0; | ||
1063 | } | ||
1064 | |||
1065 | static void gmidi_out_trigger(struct snd_rawmidi_substream *substream, int up) | ||
1066 | { | ||
1067 | struct gmidi_device *dev = substream->rmidi->private_data; | ||
1068 | |||
1069 | VDBG(dev, "gmidi_out_trigger %d\n", up); | ||
1070 | if (up) { | ||
1071 | set_bit(substream->number, &dev->out_triggered); | ||
1072 | } else { | ||
1073 | clear_bit(substream->number, &dev->out_triggered); | ||
1074 | } | ||
1075 | } | ||
1076 | |||
1077 | static struct snd_rawmidi_ops gmidi_in_ops = { | ||
1078 | .open = gmidi_in_open, | ||
1079 | .close = gmidi_in_close, | ||
1080 | .trigger = gmidi_in_trigger, | ||
1081 | }; | 131 | }; |
1082 | 132 | ||
1083 | static struct snd_rawmidi_ops gmidi_out_ops = { | 133 | static int __init midi_bind_config(struct usb_configuration *c) |
1084 | .open = gmidi_out_open, | ||
1085 | .close = gmidi_out_close, | ||
1086 | .trigger = gmidi_out_trigger | ||
1087 | }; | ||
1088 | |||
1089 | /* register as a sound "card" */ | ||
1090 | static int gmidi_register_card(struct gmidi_device *dev) | ||
1091 | { | 134 | { |
1092 | struct snd_card *card; | 135 | return f_midi_bind_config(c, index, id, |
1093 | struct snd_rawmidi *rmidi; | 136 | in_ports, out_ports, |
1094 | int err; | 137 | buflen, qlen); |
1095 | int out_ports = 1; | ||
1096 | int in_ports = 1; | ||
1097 | static struct snd_device_ops ops = { | ||
1098 | .dev_free = gmidi_snd_free, | ||
1099 | }; | ||
1100 | |||
1101 | err = snd_card_create(index, id, THIS_MODULE, 0, &card); | ||
1102 | if (err < 0) { | ||
1103 | ERROR(dev, "snd_card_create failed\n"); | ||
1104 | goto fail; | ||
1105 | } | ||
1106 | dev->card = card; | ||
1107 | |||
1108 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, dev, &ops); | ||
1109 | if (err < 0) { | ||
1110 | ERROR(dev, "snd_device_new failed: error %d\n", err); | ||
1111 | goto fail; | ||
1112 | } | ||
1113 | |||
1114 | strcpy(card->driver, longname); | ||
1115 | strcpy(card->longname, longname); | ||
1116 | strcpy(card->shortname, shortname); | ||
1117 | |||
1118 | /* Set up rawmidi */ | ||
1119 | dev->in_port.dev = dev; | ||
1120 | dev->in_port.active = 0; | ||
1121 | snd_component_add(card, "MIDI"); | ||
1122 | err = snd_rawmidi_new(card, "USB MIDI Gadget", 0, | ||
1123 | out_ports, in_ports, &rmidi); | ||
1124 | if (err < 0) { | ||
1125 | ERROR(dev, "snd_rawmidi_new failed: error %d\n", err); | ||
1126 | goto fail; | ||
1127 | } | ||
1128 | dev->rmidi = rmidi; | ||
1129 | strcpy(rmidi->name, card->shortname); | ||
1130 | rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | | ||
1131 | SNDRV_RAWMIDI_INFO_INPUT | | ||
1132 | SNDRV_RAWMIDI_INFO_DUPLEX; | ||
1133 | rmidi->private_data = dev; | ||
1134 | |||
1135 | /* Yes, rawmidi OUTPUT = USB IN, and rawmidi INPUT = USB OUT. | ||
1136 | It's an upside-down world being a gadget. */ | ||
1137 | snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &gmidi_in_ops); | ||
1138 | snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &gmidi_out_ops); | ||
1139 | |||
1140 | snd_card_set_dev(card, &dev->gadget->dev); | ||
1141 | |||
1142 | /* register it - we're ready to go */ | ||
1143 | err = snd_card_register(card); | ||
1144 | if (err < 0) { | ||
1145 | ERROR(dev, "snd_card_register failed\n"); | ||
1146 | goto fail; | ||
1147 | } | ||
1148 | |||
1149 | VDBG(dev, "gmidi_register_card finished ok\n"); | ||
1150 | return 0; | ||
1151 | |||
1152 | fail: | ||
1153 | if (dev->card) { | ||
1154 | snd_card_free(dev->card); | ||
1155 | dev->card = NULL; | ||
1156 | } | ||
1157 | return err; | ||
1158 | } | 138 | } |
1159 | 139 | ||
1160 | /* | 140 | static int __init midi_bind(struct usb_composite_dev *cdev) |
1161 | * Creates an output endpoint, and initializes output ports. | ||
1162 | */ | ||
1163 | static int __init gmidi_bind(struct usb_gadget *gadget) | ||
1164 | { | 141 | { |
1165 | struct gmidi_device *dev; | 142 | struct usb_gadget *gadget = cdev->gadget; |
1166 | struct usb_ep *in_ep, *out_ep; | 143 | int gcnum, status; |
1167 | int gcnum, err = 0; | ||
1168 | 144 | ||
1169 | /* support optional vendor/distro customization */ | 145 | status = usb_string_id(cdev); |
1170 | if (idVendor) { | 146 | if (status < 0) |
1171 | if (!idProduct) { | 147 | return status; |
1172 | pr_err("idVendor needs idProduct!\n"); | 148 | strings_dev[STRING_MANUFACTURER_IDX].id = status; |
1173 | return -ENODEV; | 149 | device_desc.iManufacturer = status; |
1174 | } | ||
1175 | device_desc.idVendor = cpu_to_le16(idVendor); | ||
1176 | device_desc.idProduct = cpu_to_le16(idProduct); | ||
1177 | if (bcdDevice) { | ||
1178 | device_desc.bcdDevice = cpu_to_le16(bcdDevice); | ||
1179 | } | ||
1180 | } | ||
1181 | if (iManufacturer) { | ||
1182 | strlcpy(manufacturer, iManufacturer, sizeof(manufacturer)); | ||
1183 | } else { | ||
1184 | snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s", | ||
1185 | init_utsname()->sysname, init_utsname()->release, | ||
1186 | gadget->name); | ||
1187 | } | ||
1188 | if (iProduct) { | ||
1189 | strlcpy(product_desc, iProduct, sizeof(product_desc)); | ||
1190 | } | ||
1191 | if (iSerialNumber) { | ||
1192 | device_desc.iSerialNumber = STRING_SERIAL, | ||
1193 | strlcpy(serial_number, iSerialNumber, sizeof(serial_number)); | ||
1194 | } | ||
1195 | 150 | ||
1196 | /* Bulk-only drivers like this one SHOULD be able to | 151 | status = usb_string_id(cdev); |
1197 | * autoconfigure on any sane usb controller driver, | 152 | if (status < 0) |
1198 | * but there may also be important quirks to address. | 153 | return status; |
1199 | */ | 154 | strings_dev[STRING_PRODUCT_IDX].id = status; |
1200 | usb_ep_autoconfig_reset(gadget); | 155 | device_desc.iProduct = status; |
1201 | in_ep = usb_ep_autoconfig(gadget, &bulk_in_desc); | ||
1202 | if (!in_ep) { | ||
1203 | autoconf_fail: | ||
1204 | pr_err("%s: can't autoconfigure on %s\n", | ||
1205 | shortname, gadget->name); | ||
1206 | return -ENODEV; | ||
1207 | } | ||
1208 | EP_IN_NAME = in_ep->name; | ||
1209 | in_ep->driver_data = in_ep; /* claim */ | ||
1210 | 156 | ||
1211 | out_ep = usb_ep_autoconfig(gadget, &bulk_out_desc); | 157 | /* config description */ |
1212 | if (!out_ep) { | 158 | status = usb_string_id(cdev); |
1213 | goto autoconf_fail; | 159 | if (status < 0) |
1214 | } | 160 | return status; |
1215 | EP_OUT_NAME = out_ep->name; | 161 | strings_dev[STRING_DESCRIPTION_IDX].id = status; |
1216 | out_ep->driver_data = out_ep; /* claim */ | 162 | |
163 | midi_config.iConfiguration = status; | ||
1217 | 164 | ||
1218 | gcnum = usb_gadget_controller_number(gadget); | 165 | gcnum = usb_gadget_controller_number(gadget); |
1219 | if (gcnum >= 0) { | 166 | if (gcnum < 0) { |
1220 | device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum); | ||
1221 | } else { | ||
1222 | /* gmidi is so simple (no altsettings) that | 167 | /* gmidi is so simple (no altsettings) that |
1223 | * it SHOULD NOT have problems with bulk-capable hardware. | 168 | * it SHOULD NOT have problems with bulk-capable hardware. |
1224 | * so warn about unrecognized controllers, don't panic. | 169 | * so warn about unrecognized controllers, don't panic. |
1225 | */ | 170 | */ |
1226 | pr_warning("%s: controller '%s' not recognized\n", | 171 | pr_warning("%s: controller '%s' not recognized\n", |
1227 | shortname, gadget->name); | 172 | __func__, gadget->name); |
1228 | device_desc.bcdDevice = cpu_to_le16(0x9999); | 173 | device_desc.bcdDevice = cpu_to_le16(0x9999); |
174 | } else { | ||
175 | device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum); | ||
1229 | } | 176 | } |
1230 | 177 | ||
178 | status = usb_add_config(cdev, &midi_config, midi_bind_config); | ||
179 | if (status < 0) | ||
180 | return status; | ||
1231 | 181 | ||
1232 | /* ok, we made sense of the hardware ... */ | 182 | pr_info("%s\n", longname); |
1233 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
1234 | if (!dev) { | ||
1235 | return -ENOMEM; | ||
1236 | } | ||
1237 | spin_lock_init(&dev->lock); | ||
1238 | dev->gadget = gadget; | ||
1239 | dev->in_ep = in_ep; | ||
1240 | dev->out_ep = out_ep; | ||
1241 | set_gadget_data(gadget, dev); | ||
1242 | tasklet_init(&dev->tasklet, gmidi_in_tasklet, (unsigned long)dev); | ||
1243 | |||
1244 | /* preallocate control response and buffer */ | ||
1245 | dev->req = alloc_ep_req(gadget->ep0, USB_BUFSIZ); | ||
1246 | if (!dev->req) { | ||
1247 | err = -ENOMEM; | ||
1248 | goto fail; | ||
1249 | } | ||
1250 | |||
1251 | dev->req->complete = gmidi_setup_complete; | ||
1252 | |||
1253 | gadget->ep0->driver_data = dev; | ||
1254 | |||
1255 | INFO(dev, "%s, version: " DRIVER_VERSION "\n", longname); | ||
1256 | INFO(dev, "using %s, OUT %s IN %s\n", gadget->name, | ||
1257 | EP_OUT_NAME, EP_IN_NAME); | ||
1258 | |||
1259 | /* register as an ALSA sound card */ | ||
1260 | err = gmidi_register_card(dev); | ||
1261 | if (err < 0) { | ||
1262 | goto fail; | ||
1263 | } | ||
1264 | |||
1265 | VDBG(dev, "gmidi_bind finished ok\n"); | ||
1266 | return 0; | 183 | return 0; |
1267 | |||
1268 | fail: | ||
1269 | gmidi_unbind(gadget); | ||
1270 | return err; | ||
1271 | } | ||
1272 | |||
1273 | |||
1274 | static void gmidi_suspend(struct usb_gadget *gadget) | ||
1275 | { | ||
1276 | struct gmidi_device *dev = get_gadget_data(gadget); | ||
1277 | |||
1278 | if (gadget->speed == USB_SPEED_UNKNOWN) { | ||
1279 | return; | ||
1280 | } | ||
1281 | |||
1282 | DBG(dev, "suspend\n"); | ||
1283 | } | ||
1284 | |||
1285 | static void gmidi_resume(struct usb_gadget *gadget) | ||
1286 | { | ||
1287 | struct gmidi_device *dev = get_gadget_data(gadget); | ||
1288 | |||
1289 | DBG(dev, "resume\n"); | ||
1290 | } | 184 | } |
1291 | 185 | ||
1292 | 186 | static struct usb_composite_driver midi_driver = { | |
1293 | static struct usb_gadget_driver gmidi_driver = { | 187 | .name = (char *) longname, |
1294 | .speed = USB_SPEED_FULL, | 188 | .dev = &device_desc, |
1295 | .function = (char *)longname, | 189 | .strings = dev_strings, |
1296 | .unbind = gmidi_unbind, | 190 | .max_speed = USB_SPEED_HIGH, |
1297 | 191 | .unbind = __exit_p(midi_unbind), | |
1298 | .setup = gmidi_setup, | ||
1299 | .disconnect = gmidi_disconnect, | ||
1300 | |||
1301 | .suspend = gmidi_suspend, | ||
1302 | .resume = gmidi_resume, | ||
1303 | |||
1304 | .driver = { | ||
1305 | .name = (char *)shortname, | ||
1306 | .owner = THIS_MODULE, | ||
1307 | }, | ||
1308 | }; | 192 | }; |
1309 | 193 | ||
1310 | static int __init gmidi_init(void) | 194 | static int __init midi_init(void) |
1311 | { | 195 | { |
1312 | return usb_gadget_probe_driver(&gmidi_driver, gmidi_bind); | 196 | return usb_composite_probe(&midi_driver, midi_bind); |
1313 | } | 197 | } |
1314 | module_init(gmidi_init); | 198 | module_init(midi_init); |
1315 | 199 | ||
1316 | static void __exit gmidi_cleanup(void) | 200 | static void __exit midi_cleanup(void) |
1317 | { | 201 | { |
1318 | usb_gadget_unregister_driver(&gmidi_driver); | 202 | usb_composite_unregister(&midi_driver); |
1319 | } | 203 | } |
1320 | module_exit(gmidi_cleanup); | 204 | module_exit(midi_cleanup); |
1321 | 205 | ||
diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c index 9fb575034a0e..f888c3ede860 100644 --- a/drivers/usb/gadget/hid.c +++ b/drivers/usb/gadget/hid.c | |||
@@ -9,15 +9,6 @@ | |||
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or | 10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. | 11 | * (at your option) any later version. |
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | 12 | */ |
22 | 13 | ||
23 | 14 | ||
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c index 692fd9b2248b..2d978c0e7ced 100644 --- a/drivers/usb/gadget/imx_udc.c +++ b/drivers/usb/gadget/imx_udc.c | |||
@@ -689,7 +689,7 @@ static int imx_ep_enable(struct usb_ep *usb_ep, | |||
689 | return -EINVAL; | 689 | return -EINVAL; |
690 | } | 690 | } |
691 | 691 | ||
692 | if (imx_ep->fifosize < le16_to_cpu(desc->wMaxPacketSize)) { | 692 | if (imx_ep->fifosize < usb_endpoint_maxp(desc)) { |
693 | D_ERR(imx_usb->dev, | 693 | D_ERR(imx_usb->dev, |
694 | "<%s> bad %s maxpacket\n", __func__, usb_ep->name); | 694 | "<%s> bad %s maxpacket\n", __func__, usb_ep->name); |
695 | return -ERANGE; | 695 | return -ERANGE; |
@@ -1478,7 +1478,7 @@ static int __init imx_udc_probe(struct platform_device *pdev) | |||
1478 | 1478 | ||
1479 | for (i = 0; i < IMX_USB_NB_EP + 1; i++) { | 1479 | for (i = 0; i < IMX_USB_NB_EP + 1; i++) { |
1480 | ret = request_irq(imx_usb->usbd_int[i], intr_handler(i), | 1480 | ret = request_irq(imx_usb->usbd_int[i], intr_handler(i), |
1481 | IRQF_DISABLED, driver_name, imx_usb); | 1481 | 0, driver_name, imx_usb); |
1482 | if (ret) { | 1482 | if (ret) { |
1483 | dev_err(&pdev->dev, "can't get irq %i, err %d\n", | 1483 | dev_err(&pdev->dev, "can't get irq %i, err %d\n", |
1484 | imx_usb->usbd_int[i], ret); | 1484 | imx_usb->usbd_int[i], ret); |
diff --git a/drivers/usb/gadget/imx_udc.h b/drivers/usb/gadget/imx_udc.h index 7136c242b4ec..d118fb777840 100644 --- a/drivers/usb/gadget/imx_udc.h +++ b/drivers/usb/gadget/imx_udc.h | |||
@@ -8,11 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
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 | */ | 11 | */ |
17 | 12 | ||
18 | #ifndef __LINUX_USB_GADGET_IMX_H | 13 | #ifndef __LINUX_USB_GADGET_IMX_H |
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c index 1b240990448f..a392ec0d2d51 100644 --- a/drivers/usb/gadget/inode.c +++ b/drivers/usb/gadget/inode.c | |||
@@ -8,15 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | 11 | */ |
21 | 12 | ||
22 | 13 | ||
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c index ff4d40d77c30..c9fa3bf5b377 100644 --- a/drivers/usb/gadget/langwell_udc.c +++ b/drivers/usb/gadget/langwell_udc.c | |||
@@ -5,16 +5,6 @@ | |||
5 | * This program is free software; you can redistribute it and/or modify it | 5 | * This program is free software; you can redistribute it and/or modify it |
6 | * under the terms and conditions of the GNU General Public License, | 6 | * under the terms and conditions of the GNU General Public License, |
7 | * version 2, as published by the Free Software Foundation. | 7 | * version 2, as published by the Free Software Foundation. |
8 | * | ||
9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
17 | * | ||
18 | */ | 8 | */ |
19 | 9 | ||
20 | 10 | ||
@@ -60,9 +50,6 @@ static const char driver_name[] = "langwell_udc"; | |||
60 | static const char driver_desc[] = DRIVER_DESC; | 50 | static const char driver_desc[] = DRIVER_DESC; |
61 | 51 | ||
62 | 52 | ||
63 | /* controller device global variable */ | ||
64 | static struct langwell_udc *the_controller; | ||
65 | |||
66 | /* for endpoint 0 operations */ | 53 | /* for endpoint 0 operations */ |
67 | static const struct usb_endpoint_descriptor | 54 | static const struct usb_endpoint_descriptor |
68 | langwell_ep0_desc = { | 55 | langwell_ep0_desc = { |
@@ -283,7 +270,7 @@ static int langwell_ep_enable(struct usb_ep *_ep, | |||
283 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | 270 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) |
284 | return -ESHUTDOWN; | 271 | return -ESHUTDOWN; |
285 | 272 | ||
286 | max = le16_to_cpu(desc->wMaxPacketSize); | 273 | max = usb_endpoint_maxp(desc); |
287 | 274 | ||
288 | /* | 275 | /* |
289 | * disable HW zero length termination select | 276 | * disable HW zero length termination select |
@@ -1321,9 +1308,12 @@ static int langwell_pullup(struct usb_gadget *_gadget, int is_on) | |||
1321 | return 0; | 1308 | return 0; |
1322 | } | 1309 | } |
1323 | 1310 | ||
1324 | static int langwell_start(struct usb_gadget_driver *driver, | 1311 | static int langwell_start(struct usb_gadget *g, |
1325 | int (*bind)(struct usb_gadget *)); | 1312 | struct usb_gadget_driver *driver); |
1326 | static int langwell_stop(struct usb_gadget_driver *driver); | 1313 | |
1314 | static int langwell_stop(struct usb_gadget *g, | ||
1315 | struct usb_gadget_driver *driver); | ||
1316 | |||
1327 | /* device controller usb_gadget_ops structure */ | 1317 | /* device controller usb_gadget_ops structure */ |
1328 | static const struct usb_gadget_ops langwell_ops = { | 1318 | static const struct usb_gadget_ops langwell_ops = { |
1329 | 1319 | ||
@@ -1345,8 +1335,8 @@ static const struct usb_gadget_ops langwell_ops = { | |||
1345 | /* D+ pullup, software-controlled connect/disconnect to USB host */ | 1335 | /* D+ pullup, software-controlled connect/disconnect to USB host */ |
1346 | .pullup = langwell_pullup, | 1336 | .pullup = langwell_pullup, |
1347 | 1337 | ||
1348 | .start = langwell_start, | 1338 | .udc_start = langwell_start, |
1349 | .stop = langwell_stop, | 1339 | .udc_stop = langwell_stop, |
1350 | }; | 1340 | }; |
1351 | 1341 | ||
1352 | 1342 | ||
@@ -1561,7 +1551,7 @@ static void stop_activity(struct langwell_udc *dev, | |||
1561 | static ssize_t show_function(struct device *_dev, | 1551 | static ssize_t show_function(struct device *_dev, |
1562 | struct device_attribute *attr, char *buf) | 1552 | struct device_attribute *attr, char *buf) |
1563 | { | 1553 | { |
1564 | struct langwell_udc *dev = the_controller; | 1554 | struct langwell_udc *dev = dev_get_drvdata(_dev); |
1565 | 1555 | ||
1566 | if (!dev->driver || !dev->driver->function | 1556 | if (!dev->driver || !dev->driver->function |
1567 | || strlen(dev->driver->function) > PAGE_SIZE) | 1557 | || strlen(dev->driver->function) > PAGE_SIZE) |
@@ -1572,11 +1562,25 @@ static ssize_t show_function(struct device *_dev, | |||
1572 | static DEVICE_ATTR(function, S_IRUGO, show_function, NULL); | 1562 | static DEVICE_ATTR(function, S_IRUGO, show_function, NULL); |
1573 | 1563 | ||
1574 | 1564 | ||
1565 | static inline enum usb_device_speed lpm_device_speed(u32 reg) | ||
1566 | { | ||
1567 | switch (LPM_PSPD(reg)) { | ||
1568 | case LPM_SPEED_HIGH: | ||
1569 | return USB_SPEED_HIGH; | ||
1570 | case LPM_SPEED_FULL: | ||
1571 | return USB_SPEED_FULL; | ||
1572 | case LPM_SPEED_LOW: | ||
1573 | return USB_SPEED_LOW; | ||
1574 | default: | ||
1575 | return USB_SPEED_UNKNOWN; | ||
1576 | } | ||
1577 | } | ||
1578 | |||
1575 | /* device "langwell_udc" sysfs attribute file */ | 1579 | /* device "langwell_udc" sysfs attribute file */ |
1576 | static ssize_t show_langwell_udc(struct device *_dev, | 1580 | static ssize_t show_langwell_udc(struct device *_dev, |
1577 | struct device_attribute *attr, char *buf) | 1581 | struct device_attribute *attr, char *buf) |
1578 | { | 1582 | { |
1579 | struct langwell_udc *dev = the_controller; | 1583 | struct langwell_udc *dev = dev_get_drvdata(_dev); |
1580 | struct langwell_request *req; | 1584 | struct langwell_request *req; |
1581 | struct langwell_ep *ep = NULL; | 1585 | struct langwell_ep *ep = NULL; |
1582 | char *next; | 1586 | char *next; |
@@ -1700,20 +1704,7 @@ static ssize_t show_langwell_udc(struct device *_dev, | |||
1700 | "BmAttributes: %d\n\n", | 1704 | "BmAttributes: %d\n\n", |
1701 | LPM_PTS(tmp_reg), | 1705 | LPM_PTS(tmp_reg), |
1702 | (tmp_reg & LPM_STS) ? 1 : 0, | 1706 | (tmp_reg & LPM_STS) ? 1 : 0, |
1703 | ({ | 1707 | usb_speed_string(lpm_device_speed(tmp_reg)), |
1704 | char *s; | ||
1705 | switch (LPM_PSPD(tmp_reg)) { | ||
1706 | case LPM_SPEED_FULL: | ||
1707 | s = "Full Speed"; break; | ||
1708 | case LPM_SPEED_LOW: | ||
1709 | s = "Low Speed"; break; | ||
1710 | case LPM_SPEED_HIGH: | ||
1711 | s = "High Speed"; break; | ||
1712 | default: | ||
1713 | s = "Unknown Speed"; break; | ||
1714 | } | ||
1715 | s; | ||
1716 | }), | ||
1717 | (tmp_reg & LPM_PFSC) ? "Force Full Speed" : "Not Force", | 1708 | (tmp_reg & LPM_PFSC) ? "Force Full Speed" : "Not Force", |
1718 | (tmp_reg & LPM_PHCD) ? "Disabled" : "Enabled", | 1709 | (tmp_reg & LPM_PHCD) ? "Disabled" : "Enabled", |
1719 | LPM_BA(tmp_reg)); | 1710 | LPM_BA(tmp_reg)); |
@@ -1821,7 +1812,7 @@ static DEVICE_ATTR(langwell_udc, S_IRUGO, show_langwell_udc, NULL); | |||
1821 | static ssize_t store_remote_wakeup(struct device *_dev, | 1812 | static ssize_t store_remote_wakeup(struct device *_dev, |
1822 | struct device_attribute *attr, const char *buf, size_t count) | 1813 | struct device_attribute *attr, const char *buf, size_t count) |
1823 | { | 1814 | { |
1824 | struct langwell_udc *dev = the_controller; | 1815 | struct langwell_udc *dev = dev_get_drvdata(_dev); |
1825 | unsigned long flags; | 1816 | unsigned long flags; |
1826 | ssize_t rc = count; | 1817 | ssize_t rc = count; |
1827 | 1818 | ||
@@ -1857,21 +1848,15 @@ static DEVICE_ATTR(remote_wakeup, S_IWUSR, NULL, store_remote_wakeup); | |||
1857 | * the driver might get unbound. | 1848 | * the driver might get unbound. |
1858 | */ | 1849 | */ |
1859 | 1850 | ||
1860 | static int langwell_start(struct usb_gadget_driver *driver, | 1851 | static int langwell_start(struct usb_gadget *g, |
1861 | int (*bind)(struct usb_gadget *)) | 1852 | struct usb_gadget_driver *driver) |
1862 | { | 1853 | { |
1863 | struct langwell_udc *dev = the_controller; | 1854 | struct langwell_udc *dev = gadget_to_langwell(g); |
1864 | unsigned long flags; | 1855 | unsigned long flags; |
1865 | int retval; | 1856 | int retval; |
1866 | 1857 | ||
1867 | if (!dev) | ||
1868 | return -ENODEV; | ||
1869 | |||
1870 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | 1858 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); |
1871 | 1859 | ||
1872 | if (dev->driver) | ||
1873 | return -EBUSY; | ||
1874 | |||
1875 | spin_lock_irqsave(&dev->lock, flags); | 1860 | spin_lock_irqsave(&dev->lock, flags); |
1876 | 1861 | ||
1877 | /* hook up the driver ... */ | 1862 | /* hook up the driver ... */ |
@@ -1881,18 +1866,9 @@ static int langwell_start(struct usb_gadget_driver *driver, | |||
1881 | 1866 | ||
1882 | spin_unlock_irqrestore(&dev->lock, flags); | 1867 | spin_unlock_irqrestore(&dev->lock, flags); |
1883 | 1868 | ||
1884 | retval = bind(&dev->gadget); | ||
1885 | if (retval) { | ||
1886 | dev_dbg(&dev->pdev->dev, "bind to driver %s --> %d\n", | ||
1887 | driver->driver.name, retval); | ||
1888 | dev->driver = NULL; | ||
1889 | dev->gadget.dev.driver = NULL; | ||
1890 | return retval; | ||
1891 | } | ||
1892 | |||
1893 | retval = device_create_file(&dev->pdev->dev, &dev_attr_function); | 1869 | retval = device_create_file(&dev->pdev->dev, &dev_attr_function); |
1894 | if (retval) | 1870 | if (retval) |
1895 | goto err_unbind; | 1871 | goto err; |
1896 | 1872 | ||
1897 | dev->usb_state = USB_STATE_ATTACHED; | 1873 | dev->usb_state = USB_STATE_ATTACHED; |
1898 | dev->ep0_state = WAIT_FOR_SETUP; | 1874 | dev->ep0_state = WAIT_FOR_SETUP; |
@@ -1909,31 +1885,27 @@ static int langwell_start(struct usb_gadget_driver *driver, | |||
1909 | dev_info(&dev->pdev->dev, "register driver: %s\n", | 1885 | dev_info(&dev->pdev->dev, "register driver: %s\n", |
1910 | driver->driver.name); | 1886 | driver->driver.name); |
1911 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | 1887 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); |
1888 | |||
1912 | return 0; | 1889 | return 0; |
1913 | 1890 | ||
1914 | err_unbind: | 1891 | err: |
1915 | driver->unbind(&dev->gadget); | ||
1916 | dev->gadget.dev.driver = NULL; | 1892 | dev->gadget.dev.driver = NULL; |
1917 | dev->driver = NULL; | 1893 | dev->driver = NULL; |
1918 | 1894 | ||
1919 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | 1895 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); |
1896 | |||
1920 | return retval; | 1897 | return retval; |
1921 | } | 1898 | } |
1922 | 1899 | ||
1923 | /* unregister gadget driver */ | 1900 | /* unregister gadget driver */ |
1924 | static int langwell_stop(struct usb_gadget_driver *driver) | 1901 | static int langwell_stop(struct usb_gadget *g, |
1902 | struct usb_gadget_driver *driver) | ||
1925 | { | 1903 | { |
1926 | struct langwell_udc *dev = the_controller; | 1904 | struct langwell_udc *dev = gadget_to_langwell(g); |
1927 | unsigned long flags; | 1905 | unsigned long flags; |
1928 | 1906 | ||
1929 | if (!dev) | ||
1930 | return -ENODEV; | ||
1931 | |||
1932 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | 1907 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); |
1933 | 1908 | ||
1934 | if (unlikely(!driver || !driver->unbind)) | ||
1935 | return -EINVAL; | ||
1936 | |||
1937 | /* exit PHY low power suspend */ | 1909 | /* exit PHY low power suspend */ |
1938 | if (dev->pdev->device != 0x0829) | 1910 | if (dev->pdev->device != 0x0829) |
1939 | langwell_phy_low_power(dev, 0); | 1911 | langwell_phy_low_power(dev, 0); |
@@ -1956,8 +1928,6 @@ static int langwell_stop(struct usb_gadget_driver *driver) | |||
1956 | stop_activity(dev, driver); | 1928 | stop_activity(dev, driver); |
1957 | spin_unlock_irqrestore(&dev->lock, flags); | 1929 | spin_unlock_irqrestore(&dev->lock, flags); |
1958 | 1930 | ||
1959 | /* unbind gadget driver */ | ||
1960 | driver->unbind(&dev->gadget); | ||
1961 | dev->gadget.dev.driver = NULL; | 1931 | dev->gadget.dev.driver = NULL; |
1962 | dev->driver = NULL; | 1932 | dev->driver = NULL; |
1963 | 1933 | ||
@@ -1966,6 +1936,7 @@ static int langwell_stop(struct usb_gadget_driver *driver) | |||
1966 | dev_info(&dev->pdev->dev, "unregistered driver '%s'\n", | 1936 | dev_info(&dev->pdev->dev, "unregistered driver '%s'\n", |
1967 | driver->driver.name); | 1937 | driver->driver.name); |
1968 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | 1938 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); |
1939 | |||
1969 | return 0; | 1940 | return 0; |
1970 | } | 1941 | } |
1971 | 1942 | ||
@@ -2657,12 +2628,10 @@ done: | |||
2657 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | 2628 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); |
2658 | } | 2629 | } |
2659 | 2630 | ||
2660 | |||
2661 | /* port change detect interrupt handler */ | 2631 | /* port change detect interrupt handler */ |
2662 | static void handle_port_change(struct langwell_udc *dev) | 2632 | static void handle_port_change(struct langwell_udc *dev) |
2663 | { | 2633 | { |
2664 | u32 portsc1, devlc; | 2634 | u32 portsc1, devlc; |
2665 | u32 speed; | ||
2666 | 2635 | ||
2667 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | 2636 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); |
2668 | 2637 | ||
@@ -2677,24 +2646,9 @@ static void handle_port_change(struct langwell_udc *dev) | |||
2677 | /* bus reset is finished */ | 2646 | /* bus reset is finished */ |
2678 | if (!(portsc1 & PORTS_PR)) { | 2647 | if (!(portsc1 & PORTS_PR)) { |
2679 | /* get the speed */ | 2648 | /* get the speed */ |
2680 | speed = LPM_PSPD(devlc); | 2649 | dev->gadget.speed = lpm_device_speed(devlc); |
2681 | switch (speed) { | 2650 | dev_vdbg(&dev->pdev->dev, "dev->gadget.speed = %d\n", |
2682 | case LPM_SPEED_HIGH: | 2651 | dev->gadget.speed); |
2683 | dev->gadget.speed = USB_SPEED_HIGH; | ||
2684 | break; | ||
2685 | case LPM_SPEED_FULL: | ||
2686 | dev->gadget.speed = USB_SPEED_FULL; | ||
2687 | break; | ||
2688 | case LPM_SPEED_LOW: | ||
2689 | dev->gadget.speed = USB_SPEED_LOW; | ||
2690 | break; | ||
2691 | default: | ||
2692 | dev->gadget.speed = USB_SPEED_UNKNOWN; | ||
2693 | break; | ||
2694 | } | ||
2695 | dev_vdbg(&dev->pdev->dev, | ||
2696 | "speed = %d, dev->gadget.speed = %d\n", | ||
2697 | speed, dev->gadget.speed); | ||
2698 | } | 2652 | } |
2699 | 2653 | ||
2700 | /* LPM L0 to L1 */ | 2654 | /* LPM L0 to L1 */ |
@@ -2999,7 +2953,7 @@ static irqreturn_t langwell_irq(int irq, void *_dev) | |||
2999 | /* release device structure */ | 2953 | /* release device structure */ |
3000 | static void gadget_release(struct device *_dev) | 2954 | static void gadget_release(struct device *_dev) |
3001 | { | 2955 | { |
3002 | struct langwell_udc *dev = the_controller; | 2956 | struct langwell_udc *dev = dev_get_drvdata(_dev); |
3003 | 2957 | ||
3004 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | 2958 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); |
3005 | 2959 | ||
@@ -3057,7 +3011,7 @@ static void sram_deinit(struct langwell_udc *dev) | |||
3057 | /* tear down the binding between this driver and the pci device */ | 3011 | /* tear down the binding between this driver and the pci device */ |
3058 | static void langwell_udc_remove(struct pci_dev *pdev) | 3012 | static void langwell_udc_remove(struct pci_dev *pdev) |
3059 | { | 3013 | { |
3060 | struct langwell_udc *dev = the_controller; | 3014 | struct langwell_udc *dev = pci_get_drvdata(pdev); |
3061 | 3015 | ||
3062 | DECLARE_COMPLETION(done); | 3016 | DECLARE_COMPLETION(done); |
3063 | 3017 | ||
@@ -3124,8 +3078,6 @@ static void langwell_udc_remove(struct pci_dev *pdev) | |||
3124 | 3078 | ||
3125 | /* free dev, wait for the release() finished */ | 3079 | /* free dev, wait for the release() finished */ |
3126 | wait_for_completion(&done); | 3080 | wait_for_completion(&done); |
3127 | |||
3128 | the_controller = NULL; | ||
3129 | } | 3081 | } |
3130 | 3082 | ||
3131 | 3083 | ||
@@ -3144,11 +3096,6 @@ static int langwell_udc_probe(struct pci_dev *pdev, | |||
3144 | size_t size; | 3096 | size_t size; |
3145 | int retval; | 3097 | int retval; |
3146 | 3098 | ||
3147 | if (the_controller) { | ||
3148 | dev_warn(&pdev->dev, "ignoring\n"); | ||
3149 | return -EBUSY; | ||
3150 | } | ||
3151 | |||
3152 | /* alloc, and start init */ | 3099 | /* alloc, and start init */ |
3153 | dev = kzalloc(sizeof *dev, GFP_KERNEL); | 3100 | dev = kzalloc(sizeof *dev, GFP_KERNEL); |
3154 | if (dev == NULL) { | 3101 | if (dev == NULL) { |
@@ -3368,8 +3315,6 @@ static int langwell_udc_probe(struct pci_dev *pdev, | |||
3368 | "After langwell_udc_probe(), print all registers:\n"); | 3315 | "After langwell_udc_probe(), print all registers:\n"); |
3369 | print_all_registers(dev); | 3316 | print_all_registers(dev); |
3370 | 3317 | ||
3371 | the_controller = dev; | ||
3372 | |||
3373 | retval = device_register(&dev->gadget.dev); | 3318 | retval = device_register(&dev->gadget.dev); |
3374 | if (retval) | 3319 | if (retval) |
3375 | goto error; | 3320 | goto error; |
@@ -3404,7 +3349,7 @@ error: | |||
3404 | /* device controller suspend */ | 3349 | /* device controller suspend */ |
3405 | static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state) | 3350 | static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state) |
3406 | { | 3351 | { |
3407 | struct langwell_udc *dev = the_controller; | 3352 | struct langwell_udc *dev = pci_get_drvdata(pdev); |
3408 | 3353 | ||
3409 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | 3354 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); |
3410 | 3355 | ||
@@ -3452,7 +3397,7 @@ static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state) | |||
3452 | /* device controller resume */ | 3397 | /* device controller resume */ |
3453 | static int langwell_udc_resume(struct pci_dev *pdev) | 3398 | static int langwell_udc_resume(struct pci_dev *pdev) |
3454 | { | 3399 | { |
3455 | struct langwell_udc *dev = the_controller; | 3400 | struct langwell_udc *dev = pci_get_drvdata(pdev); |
3456 | size_t size; | 3401 | size_t size; |
3457 | 3402 | ||
3458 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | 3403 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); |
@@ -3534,7 +3479,7 @@ static int langwell_udc_resume(struct pci_dev *pdev) | |||
3534 | /* pci driver shutdown */ | 3479 | /* pci driver shutdown */ |
3535 | static void langwell_udc_shutdown(struct pci_dev *pdev) | 3480 | static void langwell_udc_shutdown(struct pci_dev *pdev) |
3536 | { | 3481 | { |
3537 | struct langwell_udc *dev = the_controller; | 3482 | struct langwell_udc *dev = pci_get_drvdata(pdev); |
3538 | u32 usbmode; | 3483 | u32 usbmode; |
3539 | 3484 | ||
3540 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | 3485 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); |
diff --git a/drivers/usb/gadget/langwell_udc.h b/drivers/usb/gadget/langwell_udc.h index f1d9c1bb04f3..ef79e242b7b0 100644 --- a/drivers/usb/gadget/langwell_udc.h +++ b/drivers/usb/gadget/langwell_udc.h | |||
@@ -5,16 +5,6 @@ | |||
5 | * This program is free software; you can redistribute it and/or modify it | 5 | * This program is free software; you can redistribute it and/or modify it |
6 | * under the terms and conditions of the GNU General Public License, | 6 | * under the terms and conditions of the GNU General Public License, |
7 | * version 2, as published by the Free Software Foundation. | 7 | * version 2, as published by the Free Software Foundation. |
8 | * | ||
9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
17 | * | ||
18 | */ | 8 | */ |
19 | 9 | ||
20 | #include <linux/usb/langwell_udc.h> | 10 | #include <linux/usb/langwell_udc.h> |
@@ -231,3 +221,5 @@ struct langwell_udc { | |||
231 | u16 dev_status; | 221 | u16 dev_status; |
232 | }; | 222 | }; |
233 | 223 | ||
224 | #define gadget_to_langwell(g) container_of((g), struct langwell_udc, gadget) | ||
225 | |||
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index 491f825ed5c9..91d0af2a24a8 100644 --- a/drivers/usb/gadget/m66592-udc.c +++ b/drivers/usb/gadget/m66592-udc.c | |||
@@ -8,16 +8,6 @@ | |||
8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; version 2 of the License. | 10 | * the Free Software Foundation; version 2 of the License. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | * | ||
21 | */ | 11 | */ |
22 | 12 | ||
23 | #include <linux/module.h> | 13 | #include <linux/module.h> |
@@ -370,7 +360,7 @@ static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep, | |||
370 | 360 | ||
371 | ep->pipectr = get_pipectr_addr(pipenum); | 361 | ep->pipectr = get_pipectr_addr(pipenum); |
372 | ep->pipenum = pipenum; | 362 | ep->pipenum = pipenum; |
373 | ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize); | 363 | ep->ep.maxpacket = usb_endpoint_maxp(desc); |
374 | m66592->pipenum2ep[pipenum] = ep; | 364 | m66592->pipenum2ep[pipenum] = ep; |
375 | m66592->epaddr2ep[desc->bEndpointAddress&USB_ENDPOINT_NUMBER_MASK] = ep; | 365 | m66592->epaddr2ep[desc->bEndpointAddress&USB_ENDPOINT_NUMBER_MASK] = ep; |
376 | INIT_LIST_HEAD(&ep->queue); | 366 | INIT_LIST_HEAD(&ep->queue); |
@@ -447,7 +437,7 @@ static int alloc_pipe_config(struct m66592_ep *ep, | |||
447 | ep->type = info.type; | 437 | ep->type = info.type; |
448 | 438 | ||
449 | info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; | 439 | info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; |
450 | info.maxpacket = le16_to_cpu(desc->wMaxPacketSize); | 440 | info.maxpacket = usb_endpoint_maxp(desc); |
451 | info.interval = desc->bInterval; | 441 | info.interval = desc->bInterval; |
452 | if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) | 442 | if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) |
453 | info.dir_in = 1; | 443 | info.dir_in = 1; |
@@ -1674,7 +1664,7 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1674 | m66592->timer.data = (unsigned long)m66592; | 1664 | m66592->timer.data = (unsigned long)m66592; |
1675 | m66592->reg = reg; | 1665 | m66592->reg = reg; |
1676 | 1666 | ||
1677 | ret = request_irq(ires->start, m66592_irq, IRQF_DISABLED | IRQF_SHARED, | 1667 | ret = request_irq(ires->start, m66592_irq, IRQF_SHARED, |
1678 | udc_name, m66592); | 1668 | udc_name, m66592); |
1679 | if (ret < 0) { | 1669 | if (ret < 0) { |
1680 | pr_err("request_irq error (%d)\n", ret); | 1670 | pr_err("request_irq error (%d)\n", ret); |
diff --git a/drivers/usb/gadget/m66592-udc.h b/drivers/usb/gadget/m66592-udc.h index 7b93d579af37..9d9f7e39f037 100644 --- a/drivers/usb/gadget/m66592-udc.h +++ b/drivers/usb/gadget/m66592-udc.h | |||
@@ -8,16 +8,6 @@ | |||
8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; version 2 of the License. | 10 | * the Free Software Foundation; version 2 of the License. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | * | ||
21 | */ | 11 | */ |
22 | 12 | ||
23 | #ifndef __M66592_UDC_H__ | 13 | #ifndef __M66592_UDC_H__ |
diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c index d3eb27427c58..e24f72f82a47 100644 --- a/drivers/usb/gadget/mass_storage.c +++ b/drivers/usb/gadget/mass_storage.c | |||
@@ -10,15 +10,6 @@ | |||
10 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or | 11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. | 12 | * (at your option) any later version. |
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | */ | 13 | */ |
23 | 14 | ||
24 | 15 | ||
@@ -169,7 +160,7 @@ static struct usb_composite_driver msg_driver = { | |||
169 | .name = "g_mass_storage", | 160 | .name = "g_mass_storage", |
170 | .dev = &msg_device_desc, | 161 | .dev = &msg_device_desc, |
171 | .iProduct = DRIVER_DESC, | 162 | .iProduct = DRIVER_DESC, |
172 | .max_speed = USB_SPEED_HIGH, | 163 | .max_speed = USB_SPEED_SUPER, |
173 | .needs_serial = 1, | 164 | .needs_serial = 1, |
174 | }; | 165 | }; |
175 | 166 | ||
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c index 8c7b74717d85..7e7f515b8b19 100644 --- a/drivers/usb/gadget/multi.c +++ b/drivers/usb/gadget/multi.c | |||
@@ -10,15 +10,6 @@ | |||
10 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or | 11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. | 12 | * (at your option) any later version. |
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | */ | 13 | */ |
23 | 14 | ||
24 | 15 | ||
diff --git a/drivers/usb/gadget/mv_udc.h b/drivers/usb/gadget/mv_udc.h index 65f1f7c3bd4e..daa75c12f336 100644 --- a/drivers/usb/gadget/mv_udc.h +++ b/drivers/usb/gadget/mv_udc.h | |||
@@ -1,3 +1,11 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011 Marvell International Ltd. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms of the GNU General Public License as published by the | ||
6 | * Free Software Foundation; either version 2 of the License, or (at your | ||
7 | * option) any later version. | ||
8 | */ | ||
1 | 9 | ||
2 | #ifndef __MV_UDC_H | 10 | #ifndef __MV_UDC_H |
3 | #define __MV_UDC_H | 11 | #define __MV_UDC_H |
@@ -194,14 +202,25 @@ struct mv_udc { | |||
194 | unsigned int ep0_dir; | 202 | unsigned int ep0_dir; |
195 | 203 | ||
196 | unsigned int dev_addr; | 204 | unsigned int dev_addr; |
205 | unsigned int test_mode; | ||
197 | 206 | ||
198 | int errors; | 207 | int errors; |
199 | unsigned softconnect:1, | 208 | unsigned softconnect:1, |
200 | vbus_active:1, | 209 | vbus_active:1, |
201 | remote_wakeup:1, | 210 | remote_wakeup:1, |
202 | softconnected:1, | 211 | softconnected:1, |
203 | force_fs:1; | 212 | force_fs:1, |
204 | struct clk *clk; | 213 | clock_gating:1, |
214 | active:1; | ||
215 | |||
216 | struct work_struct vbus_work; | ||
217 | struct workqueue_struct *qwork; | ||
218 | |||
219 | struct mv_usb_platform_data *pdata; | ||
220 | |||
221 | /* some SOC has mutiple clock sources for USB*/ | ||
222 | unsigned int clknum; | ||
223 | struct clk *clk[0]; | ||
205 | }; | 224 | }; |
206 | 225 | ||
207 | /* endpoint data structure */ | 226 | /* endpoint data structure */ |
@@ -225,6 +244,7 @@ struct mv_req { | |||
225 | struct mv_dtd *dtd, *head, *tail; | 244 | struct mv_dtd *dtd, *head, *tail; |
226 | struct mv_ep *ep; | 245 | struct mv_ep *ep; |
227 | struct list_head queue; | 246 | struct list_head queue; |
247 | unsigned int test_mode; | ||
228 | unsigned dtd_count; | 248 | unsigned dtd_count; |
229 | unsigned mapped:1; | 249 | unsigned mapped:1; |
230 | }; | 250 | }; |
@@ -289,6 +309,4 @@ struct mv_dtd { | |||
289 | struct mv_dtd *next_dtd_virt; | 309 | struct mv_dtd *next_dtd_virt; |
290 | }; | 310 | }; |
291 | 311 | ||
292 | extern int mv_udc_phy_init(unsigned int base); | ||
293 | |||
294 | #endif | 312 | #endif |
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c index 0b3b8d0462db..892412103dd8 100644 --- a/drivers/usb/gadget/mv_udc_core.c +++ b/drivers/usb/gadget/mv_udc_core.c | |||
@@ -1,3 +1,14 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011 Marvell International Ltd. All rights reserved. | ||
3 | * Author: Chao Xie <chao.xie@marvell.com> | ||
4 | * Neil Zhang <zhangwm@marvell.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | */ | ||
11 | |||
1 | #include <linux/module.h> | 12 | #include <linux/module.h> |
2 | #include <linux/pci.h> | 13 | #include <linux/pci.h> |
3 | #include <linux/dma-mapping.h> | 14 | #include <linux/dma-mapping.h> |
@@ -22,6 +33,7 @@ | |||
22 | #include <linux/irq.h> | 33 | #include <linux/irq.h> |
23 | #include <linux/platform_device.h> | 34 | #include <linux/platform_device.h> |
24 | #include <linux/clk.h> | 35 | #include <linux/clk.h> |
36 | #include <linux/platform_data/mv_usb.h> | ||
25 | #include <asm/system.h> | 37 | #include <asm/system.h> |
26 | #include <asm/unaligned.h> | 38 | #include <asm/unaligned.h> |
27 | 39 | ||
@@ -45,6 +57,8 @@ | |||
45 | #define LOOPS_USEC (1 << LOOPS_USEC_SHIFT) | 57 | #define LOOPS_USEC (1 << LOOPS_USEC_SHIFT) |
46 | #define LOOPS(timeout) ((timeout) >> LOOPS_USEC_SHIFT) | 58 | #define LOOPS(timeout) ((timeout) >> LOOPS_USEC_SHIFT) |
47 | 59 | ||
60 | static DECLARE_COMPLETION(release_done); | ||
61 | |||
48 | static const char driver_name[] = "mv_udc"; | 62 | static const char driver_name[] = "mv_udc"; |
49 | static const char driver_desc[] = DRIVER_DESC; | 63 | static const char driver_desc[] = DRIVER_DESC; |
50 | 64 | ||
@@ -53,6 +67,7 @@ static struct mv_udc *the_controller; | |||
53 | int mv_usb_otgsc; | 67 | int mv_usb_otgsc; |
54 | 68 | ||
55 | static void nuke(struct mv_ep *ep, int status); | 69 | static void nuke(struct mv_ep *ep, int status); |
70 | static void stop_activity(struct mv_udc *udc, struct usb_gadget_driver *driver); | ||
56 | 71 | ||
57 | /* for endpoint 0 operations */ | 72 | /* for endpoint 0 operations */ |
58 | static const struct usb_endpoint_descriptor mv_ep0_desc = { | 73 | static const struct usb_endpoint_descriptor mv_ep0_desc = { |
@@ -82,14 +97,16 @@ static void ep0_reset(struct mv_udc *udc) | |||
82 | (EP0_MAX_PKT_SIZE << EP_QUEUE_HEAD_MAX_PKT_LEN_POS) | 97 | (EP0_MAX_PKT_SIZE << EP_QUEUE_HEAD_MAX_PKT_LEN_POS) |
83 | | EP_QUEUE_HEAD_IOS; | 98 | | EP_QUEUE_HEAD_IOS; |
84 | 99 | ||
100 | ep->dqh->next_dtd_ptr = EP_QUEUE_HEAD_NEXT_TERMINATE; | ||
101 | |||
85 | epctrlx = readl(&udc->op_regs->epctrlx[0]); | 102 | epctrlx = readl(&udc->op_regs->epctrlx[0]); |
86 | if (i) { /* TX */ | 103 | if (i) { /* TX */ |
87 | epctrlx |= EPCTRL_TX_ENABLE | EPCTRL_TX_DATA_TOGGLE_RST | 104 | epctrlx |= EPCTRL_TX_ENABLE |
88 | | (USB_ENDPOINT_XFER_CONTROL | 105 | | (USB_ENDPOINT_XFER_CONTROL |
89 | << EPCTRL_TX_EP_TYPE_SHIFT); | 106 | << EPCTRL_TX_EP_TYPE_SHIFT); |
90 | 107 | ||
91 | } else { /* RX */ | 108 | } else { /* RX */ |
92 | epctrlx |= EPCTRL_RX_ENABLE | EPCTRL_RX_DATA_TOGGLE_RST | 109 | epctrlx |= EPCTRL_RX_ENABLE |
93 | | (USB_ENDPOINT_XFER_CONTROL | 110 | | (USB_ENDPOINT_XFER_CONTROL |
94 | << EPCTRL_RX_EP_TYPE_SHIFT); | 111 | << EPCTRL_RX_EP_TYPE_SHIFT); |
95 | } | 112 | } |
@@ -122,6 +139,7 @@ static int process_ep_req(struct mv_udc *udc, int index, | |||
122 | int i, direction; | 139 | int i, direction; |
123 | int retval = 0; | 140 | int retval = 0; |
124 | u32 errors; | 141 | u32 errors; |
142 | u32 bit_pos; | ||
125 | 143 | ||
126 | curr_dqh = &udc->ep_dqh[index]; | 144 | curr_dqh = &udc->ep_dqh[index]; |
127 | direction = index % 2; | 145 | direction = index % 2; |
@@ -139,10 +157,20 @@ static int process_ep_req(struct mv_udc *udc, int index, | |||
139 | 157 | ||
140 | errors = curr_dtd->size_ioc_sts & DTD_ERROR_MASK; | 158 | errors = curr_dtd->size_ioc_sts & DTD_ERROR_MASK; |
141 | if (!errors) { | 159 | if (!errors) { |
142 | remaining_length += | 160 | remaining_length = |
143 | (curr_dtd->size_ioc_sts & DTD_PACKET_SIZE) | 161 | (curr_dtd->size_ioc_sts & DTD_PACKET_SIZE) |
144 | >> DTD_LENGTH_BIT_POS; | 162 | >> DTD_LENGTH_BIT_POS; |
145 | actual -= remaining_length; | 163 | actual -= remaining_length; |
164 | |||
165 | if (remaining_length) { | ||
166 | if (direction) { | ||
167 | dev_dbg(&udc->dev->dev, | ||
168 | "TX dTD remains data\n"); | ||
169 | retval = -EPROTO; | ||
170 | break; | ||
171 | } else | ||
172 | break; | ||
173 | } | ||
146 | } else { | 174 | } else { |
147 | dev_info(&udc->dev->dev, | 175 | dev_info(&udc->dev->dev, |
148 | "complete_tr error: ep=%d %s: error = 0x%x\n", | 176 | "complete_tr error: ep=%d %s: error = 0x%x\n", |
@@ -164,6 +192,20 @@ static int process_ep_req(struct mv_udc *udc, int index, | |||
164 | if (retval) | 192 | if (retval) |
165 | return retval; | 193 | return retval; |
166 | 194 | ||
195 | if (direction == EP_DIR_OUT) | ||
196 | bit_pos = 1 << curr_req->ep->ep_num; | ||
197 | else | ||
198 | bit_pos = 1 << (16 + curr_req->ep->ep_num); | ||
199 | |||
200 | while ((curr_dqh->curr_dtd_ptr == curr_dtd->td_dma)) { | ||
201 | if (curr_dtd->dtd_next == EP_QUEUE_HEAD_NEXT_TERMINATE) { | ||
202 | while (readl(&udc->op_regs->epstatus) & bit_pos) | ||
203 | udelay(1); | ||
204 | break; | ||
205 | } | ||
206 | udelay(1); | ||
207 | } | ||
208 | |||
167 | curr_req->req.actual = actual; | 209 | curr_req->req.actual = actual; |
168 | 210 | ||
169 | return 0; | 211 | return 0; |
@@ -481,6 +523,7 @@ static int mv_ep_enable(struct usb_ep *_ep, | |||
481 | u16 max = 0; | 523 | u16 max = 0; |
482 | u32 bit_pos, epctrlx, direction; | 524 | u32 bit_pos, epctrlx, direction; |
483 | unsigned char zlt = 0, ios = 0, mult = 0; | 525 | unsigned char zlt = 0, ios = 0, mult = 0; |
526 | unsigned long flags; | ||
484 | 527 | ||
485 | ep = container_of(_ep, struct mv_ep, ep); | 528 | ep = container_of(_ep, struct mv_ep, ep); |
486 | udc = ep->udc; | 529 | udc = ep->udc; |
@@ -493,7 +536,7 @@ static int mv_ep_enable(struct usb_ep *_ep, | |||
493 | return -ESHUTDOWN; | 536 | return -ESHUTDOWN; |
494 | 537 | ||
495 | direction = ep_dir(ep); | 538 | direction = ep_dir(ep); |
496 | max = le16_to_cpu(desc->wMaxPacketSize); | 539 | max = usb_endpoint_maxp(desc); |
497 | 540 | ||
498 | /* | 541 | /* |
499 | * disable HW zero length termination select | 542 | * disable HW zero length termination select |
@@ -501,9 +544,6 @@ static int mv_ep_enable(struct usb_ep *_ep, | |||
501 | */ | 544 | */ |
502 | zlt = 1; | 545 | zlt = 1; |
503 | 546 | ||
504 | /* Get the endpoint queue head address */ | ||
505 | dqh = (struct mv_dqh *)ep->dqh; | ||
506 | |||
507 | bit_pos = 1 << ((direction == EP_DIR_OUT ? 0 : 16) + ep->ep_num); | 547 | bit_pos = 1 << ((direction == EP_DIR_OUT ? 0 : 16) + ep->ep_num); |
508 | 548 | ||
509 | /* Check if the Endpoint is Primed */ | 549 | /* Check if the Endpoint is Primed */ |
@@ -532,7 +572,7 @@ static int mv_ep_enable(struct usb_ep *_ep, | |||
532 | case USB_ENDPOINT_XFER_ISOC: | 572 | case USB_ENDPOINT_XFER_ISOC: |
533 | /* Calculate transactions needed for high bandwidth iso */ | 573 | /* Calculate transactions needed for high bandwidth iso */ |
534 | mult = (unsigned char)(1 + ((max >> 11) & 0x03)); | 574 | mult = (unsigned char)(1 + ((max >> 11) & 0x03)); |
535 | max = max & 0x8ff; /* bit 0~10 */ | 575 | max = max & 0x7ff; /* bit 0~10 */ |
536 | /* 3 transactions at most */ | 576 | /* 3 transactions at most */ |
537 | if (mult > 3) | 577 | if (mult > 3) |
538 | goto en_done; | 578 | goto en_done; |
@@ -540,6 +580,10 @@ static int mv_ep_enable(struct usb_ep *_ep, | |||
540 | default: | 580 | default: |
541 | goto en_done; | 581 | goto en_done; |
542 | } | 582 | } |
583 | |||
584 | spin_lock_irqsave(&udc->lock, flags); | ||
585 | /* Get the endpoint queue head address */ | ||
586 | dqh = ep->dqh; | ||
543 | dqh->max_packet_length = (max << EP_QUEUE_HEAD_MAX_PKT_LEN_POS) | 587 | dqh->max_packet_length = (max << EP_QUEUE_HEAD_MAX_PKT_LEN_POS) |
544 | | (mult << EP_QUEUE_HEAD_MULT_POS) | 588 | | (mult << EP_QUEUE_HEAD_MULT_POS) |
545 | | (zlt ? EP_QUEUE_HEAD_ZLT_SEL : 0) | 589 | | (zlt ? EP_QUEUE_HEAD_ZLT_SEL : 0) |
@@ -572,18 +616,20 @@ static int mv_ep_enable(struct usb_ep *_ep, | |||
572 | */ | 616 | */ |
573 | epctrlx = readl(&udc->op_regs->epctrlx[ep->ep_num]); | 617 | epctrlx = readl(&udc->op_regs->epctrlx[ep->ep_num]); |
574 | if ((epctrlx & EPCTRL_RX_ENABLE) == 0) { | 618 | if ((epctrlx & EPCTRL_RX_ENABLE) == 0) { |
575 | epctrlx |= ((desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) | 619 | epctrlx |= (USB_ENDPOINT_XFER_BULK |
576 | << EPCTRL_RX_EP_TYPE_SHIFT); | 620 | << EPCTRL_RX_EP_TYPE_SHIFT); |
577 | writel(epctrlx, &udc->op_regs->epctrlx[ep->ep_num]); | 621 | writel(epctrlx, &udc->op_regs->epctrlx[ep->ep_num]); |
578 | } | 622 | } |
579 | 623 | ||
580 | epctrlx = readl(&udc->op_regs->epctrlx[ep->ep_num]); | 624 | epctrlx = readl(&udc->op_regs->epctrlx[ep->ep_num]); |
581 | if ((epctrlx & EPCTRL_TX_ENABLE) == 0) { | 625 | if ((epctrlx & EPCTRL_TX_ENABLE) == 0) { |
582 | epctrlx |= ((desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) | 626 | epctrlx |= (USB_ENDPOINT_XFER_BULK |
583 | << EPCTRL_TX_EP_TYPE_SHIFT); | 627 | << EPCTRL_TX_EP_TYPE_SHIFT); |
584 | writel(epctrlx, &udc->op_regs->epctrlx[ep->ep_num]); | 628 | writel(epctrlx, &udc->op_regs->epctrlx[ep->ep_num]); |
585 | } | 629 | } |
586 | 630 | ||
631 | spin_unlock_irqrestore(&udc->lock, flags); | ||
632 | |||
587 | return 0; | 633 | return 0; |
588 | en_done: | 634 | en_done: |
589 | return -EINVAL; | 635 | return -EINVAL; |
@@ -595,6 +641,7 @@ static int mv_ep_disable(struct usb_ep *_ep) | |||
595 | struct mv_ep *ep; | 641 | struct mv_ep *ep; |
596 | struct mv_dqh *dqh; | 642 | struct mv_dqh *dqh; |
597 | u32 bit_pos, epctrlx, direction; | 643 | u32 bit_pos, epctrlx, direction; |
644 | unsigned long flags; | ||
598 | 645 | ||
599 | ep = container_of(_ep, struct mv_ep, ep); | 646 | ep = container_of(_ep, struct mv_ep, ep); |
600 | if ((_ep == NULL) || !ep->desc) | 647 | if ((_ep == NULL) || !ep->desc) |
@@ -605,6 +652,8 @@ static int mv_ep_disable(struct usb_ep *_ep) | |||
605 | /* Get the endpoint queue head address */ | 652 | /* Get the endpoint queue head address */ |
606 | dqh = ep->dqh; | 653 | dqh = ep->dqh; |
607 | 654 | ||
655 | spin_lock_irqsave(&udc->lock, flags); | ||
656 | |||
608 | direction = ep_dir(ep); | 657 | direction = ep_dir(ep); |
609 | bit_pos = 1 << ((direction == EP_DIR_OUT ? 0 : 16) + ep->ep_num); | 658 | bit_pos = 1 << ((direction == EP_DIR_OUT ? 0 : 16) + ep->ep_num); |
610 | 659 | ||
@@ -623,6 +672,9 @@ static int mv_ep_disable(struct usb_ep *_ep) | |||
623 | 672 | ||
624 | ep->desc = NULL; | 673 | ep->desc = NULL; |
625 | ep->stopped = 1; | 674 | ep->stopped = 1; |
675 | |||
676 | spin_unlock_irqrestore(&udc->lock, flags); | ||
677 | |||
626 | return 0; | 678 | return 0; |
627 | } | 679 | } |
628 | 680 | ||
@@ -655,37 +707,28 @@ static void mv_ep_fifo_flush(struct usb_ep *_ep) | |||
655 | { | 707 | { |
656 | struct mv_udc *udc; | 708 | struct mv_udc *udc; |
657 | u32 bit_pos, direction; | 709 | u32 bit_pos, direction; |
658 | struct mv_ep *ep = container_of(_ep, struct mv_ep, ep); | 710 | struct mv_ep *ep; |
659 | unsigned int loops; | 711 | unsigned int loops; |
660 | 712 | ||
713 | if (!_ep) | ||
714 | return; | ||
715 | |||
716 | ep = container_of(_ep, struct mv_ep, ep); | ||
717 | if (!ep->desc) | ||
718 | return; | ||
719 | |||
661 | udc = ep->udc; | 720 | udc = ep->udc; |
662 | direction = ep_dir(ep); | 721 | direction = ep_dir(ep); |
663 | bit_pos = 1 << ((direction == EP_DIR_OUT ? 0 : 16) + ep->ep_num); | ||
664 | /* | ||
665 | * Flushing will halt the pipe | ||
666 | * Write 1 to the Flush register | ||
667 | */ | ||
668 | writel(bit_pos, &udc->op_regs->epflush); | ||
669 | 722 | ||
670 | /* Wait until flushing completed */ | 723 | if (ep->ep_num == 0) |
671 | loops = LOOPS(FLUSH_TIMEOUT); | 724 | bit_pos = (1 << 16) | 1; |
672 | while (readl(&udc->op_regs->epflush) & bit_pos) { | 725 | else if (direction == EP_DIR_OUT) |
673 | /* | 726 | bit_pos = 1 << ep->ep_num; |
674 | * ENDPTFLUSH bit should be cleared to indicate this | 727 | else |
675 | * operation is complete | 728 | bit_pos = 1 << (16 + ep->ep_num); |
676 | */ | 729 | |
677 | if (loops == 0) { | ||
678 | dev_err(&udc->dev->dev, | ||
679 | "TIMEOUT for ENDPTFLUSH=0x%x, bit_pos=0x%x\n", | ||
680 | (unsigned)readl(&udc->op_regs->epflush), | ||
681 | (unsigned)bit_pos); | ||
682 | return; | ||
683 | } | ||
684 | loops--; | ||
685 | udelay(LOOPS_USEC); | ||
686 | } | ||
687 | loops = LOOPS(EPSTATUS_TIMEOUT); | 730 | loops = LOOPS(EPSTATUS_TIMEOUT); |
688 | while (readl(&udc->op_regs->epstatus) & bit_pos) { | 731 | do { |
689 | unsigned int inter_loops; | 732 | unsigned int inter_loops; |
690 | 733 | ||
691 | if (loops == 0) { | 734 | if (loops == 0) { |
@@ -700,7 +743,7 @@ static void mv_ep_fifo_flush(struct usb_ep *_ep) | |||
700 | 743 | ||
701 | /* Wait until flushing completed */ | 744 | /* Wait until flushing completed */ |
702 | inter_loops = LOOPS(FLUSH_TIMEOUT); | 745 | inter_loops = LOOPS(FLUSH_TIMEOUT); |
703 | while (readl(&udc->op_regs->epflush) & bit_pos) { | 746 | while (readl(&udc->op_regs->epflush)) { |
704 | /* | 747 | /* |
705 | * ENDPTFLUSH bit should be cleared to indicate this | 748 | * ENDPTFLUSH bit should be cleared to indicate this |
706 | * operation is complete | 749 | * operation is complete |
@@ -717,7 +760,7 @@ static void mv_ep_fifo_flush(struct usb_ep *_ep) | |||
717 | udelay(LOOPS_USEC); | 760 | udelay(LOOPS_USEC); |
718 | } | 761 | } |
719 | loops--; | 762 | loops--; |
720 | } | 763 | } while (readl(&udc->op_regs->epstatus) & bit_pos); |
721 | } | 764 | } |
722 | 765 | ||
723 | /* queues (submits) an I/O request to an endpoint */ | 766 | /* queues (submits) an I/O request to an endpoint */ |
@@ -987,6 +1030,22 @@ static struct usb_ep_ops mv_ep_ops = { | |||
987 | .fifo_flush = mv_ep_fifo_flush, /* flush fifo */ | 1030 | .fifo_flush = mv_ep_fifo_flush, /* flush fifo */ |
988 | }; | 1031 | }; |
989 | 1032 | ||
1033 | static void udc_clock_enable(struct mv_udc *udc) | ||
1034 | { | ||
1035 | unsigned int i; | ||
1036 | |||
1037 | for (i = 0; i < udc->clknum; i++) | ||
1038 | clk_enable(udc->clk[i]); | ||
1039 | } | ||
1040 | |||
1041 | static void udc_clock_disable(struct mv_udc *udc) | ||
1042 | { | ||
1043 | unsigned int i; | ||
1044 | |||
1045 | for (i = 0; i < udc->clknum; i++) | ||
1046 | clk_disable(udc->clk[i]); | ||
1047 | } | ||
1048 | |||
990 | static void udc_stop(struct mv_udc *udc) | 1049 | static void udc_stop(struct mv_udc *udc) |
991 | { | 1050 | { |
992 | u32 tmp; | 1051 | u32 tmp; |
@@ -1075,6 +1134,40 @@ static int udc_reset(struct mv_udc *udc) | |||
1075 | return 0; | 1134 | return 0; |
1076 | } | 1135 | } |
1077 | 1136 | ||
1137 | static int mv_udc_enable(struct mv_udc *udc) | ||
1138 | { | ||
1139 | int retval; | ||
1140 | |||
1141 | if (udc->clock_gating == 0 || udc->active) | ||
1142 | return 0; | ||
1143 | |||
1144 | dev_dbg(&udc->dev->dev, "enable udc\n"); | ||
1145 | udc_clock_enable(udc); | ||
1146 | if (udc->pdata->phy_init) { | ||
1147 | retval = udc->pdata->phy_init(udc->phy_regs); | ||
1148 | if (retval) { | ||
1149 | dev_err(&udc->dev->dev, | ||
1150 | "init phy error %d\n", retval); | ||
1151 | udc_clock_disable(udc); | ||
1152 | return retval; | ||
1153 | } | ||
1154 | } | ||
1155 | udc->active = 1; | ||
1156 | |||
1157 | return 0; | ||
1158 | } | ||
1159 | |||
1160 | static void mv_udc_disable(struct mv_udc *udc) | ||
1161 | { | ||
1162 | if (udc->clock_gating && udc->active) { | ||
1163 | dev_dbg(&udc->dev->dev, "disable udc\n"); | ||
1164 | if (udc->pdata->phy_deinit) | ||
1165 | udc->pdata->phy_deinit(udc->phy_regs); | ||
1166 | udc_clock_disable(udc); | ||
1167 | udc->active = 0; | ||
1168 | } | ||
1169 | } | ||
1170 | |||
1078 | static int mv_udc_get_frame(struct usb_gadget *gadget) | 1171 | static int mv_udc_get_frame(struct usb_gadget *gadget) |
1079 | { | 1172 | { |
1080 | struct mv_udc *udc; | 1173 | struct mv_udc *udc; |
@@ -1110,22 +1203,68 @@ static int mv_udc_wakeup(struct usb_gadget *gadget) | |||
1110 | return 0; | 1203 | return 0; |
1111 | } | 1204 | } |
1112 | 1205 | ||
1206 | static int mv_udc_vbus_session(struct usb_gadget *gadget, int is_active) | ||
1207 | { | ||
1208 | struct mv_udc *udc; | ||
1209 | unsigned long flags; | ||
1210 | int retval = 0; | ||
1211 | |||
1212 | udc = container_of(gadget, struct mv_udc, gadget); | ||
1213 | spin_lock_irqsave(&udc->lock, flags); | ||
1214 | |||
1215 | dev_dbg(&udc->dev->dev, "%s: softconnect %d, vbus_active %d\n", | ||
1216 | __func__, udc->softconnect, udc->vbus_active); | ||
1217 | |||
1218 | udc->vbus_active = (is_active != 0); | ||
1219 | if (udc->driver && udc->softconnect && udc->vbus_active) { | ||
1220 | retval = mv_udc_enable(udc); | ||
1221 | if (retval == 0) { | ||
1222 | /* Clock is disabled, need re-init registers */ | ||
1223 | udc_reset(udc); | ||
1224 | ep0_reset(udc); | ||
1225 | udc_start(udc); | ||
1226 | } | ||
1227 | } else if (udc->driver && udc->softconnect) { | ||
1228 | /* stop all the transfer in queue*/ | ||
1229 | stop_activity(udc, udc->driver); | ||
1230 | udc_stop(udc); | ||
1231 | mv_udc_disable(udc); | ||
1232 | } | ||
1233 | |||
1234 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1235 | return retval; | ||
1236 | } | ||
1237 | |||
1113 | static int mv_udc_pullup(struct usb_gadget *gadget, int is_on) | 1238 | static int mv_udc_pullup(struct usb_gadget *gadget, int is_on) |
1114 | { | 1239 | { |
1115 | struct mv_udc *udc; | 1240 | struct mv_udc *udc; |
1116 | unsigned long flags; | 1241 | unsigned long flags; |
1242 | int retval = 0; | ||
1117 | 1243 | ||
1118 | udc = container_of(gadget, struct mv_udc, gadget); | 1244 | udc = container_of(gadget, struct mv_udc, gadget); |
1119 | spin_lock_irqsave(&udc->lock, flags); | 1245 | spin_lock_irqsave(&udc->lock, flags); |
1120 | 1246 | ||
1247 | dev_dbg(&udc->dev->dev, "%s: softconnect %d, vbus_active %d\n", | ||
1248 | __func__, udc->softconnect, udc->vbus_active); | ||
1249 | |||
1121 | udc->softconnect = (is_on != 0); | 1250 | udc->softconnect = (is_on != 0); |
1122 | if (udc->driver && udc->softconnect) | 1251 | if (udc->driver && udc->softconnect && udc->vbus_active) { |
1123 | udc_start(udc); | 1252 | retval = mv_udc_enable(udc); |
1124 | else | 1253 | if (retval == 0) { |
1254 | /* Clock is disabled, need re-init registers */ | ||
1255 | udc_reset(udc); | ||
1256 | ep0_reset(udc); | ||
1257 | udc_start(udc); | ||
1258 | } | ||
1259 | } else if (udc->driver && udc->vbus_active) { | ||
1260 | /* stop all the transfer in queue*/ | ||
1261 | stop_activity(udc, udc->driver); | ||
1125 | udc_stop(udc); | 1262 | udc_stop(udc); |
1263 | mv_udc_disable(udc); | ||
1264 | } | ||
1126 | 1265 | ||
1127 | spin_unlock_irqrestore(&udc->lock, flags); | 1266 | spin_unlock_irqrestore(&udc->lock, flags); |
1128 | return 0; | 1267 | return retval; |
1129 | } | 1268 | } |
1130 | 1269 | ||
1131 | static int mv_udc_start(struct usb_gadget_driver *driver, | 1270 | static int mv_udc_start(struct usb_gadget_driver *driver, |
@@ -1140,17 +1279,15 @@ static const struct usb_gadget_ops mv_ops = { | |||
1140 | /* tries to wake up the host connected to this gadget */ | 1279 | /* tries to wake up the host connected to this gadget */ |
1141 | .wakeup = mv_udc_wakeup, | 1280 | .wakeup = mv_udc_wakeup, |
1142 | 1281 | ||
1282 | /* notify controller that VBUS is powered or not */ | ||
1283 | .vbus_session = mv_udc_vbus_session, | ||
1284 | |||
1143 | /* D+ pullup, software-controlled connect/disconnect to USB host */ | 1285 | /* D+ pullup, software-controlled connect/disconnect to USB host */ |
1144 | .pullup = mv_udc_pullup, | 1286 | .pullup = mv_udc_pullup, |
1145 | .start = mv_udc_start, | 1287 | .start = mv_udc_start, |
1146 | .stop = mv_udc_stop, | 1288 | .stop = mv_udc_stop, |
1147 | }; | 1289 | }; |
1148 | 1290 | ||
1149 | static void mv_udc_testmode(struct mv_udc *udc, u16 index, bool enter) | ||
1150 | { | ||
1151 | dev_info(&udc->dev->dev, "Test Mode is not support yet\n"); | ||
1152 | } | ||
1153 | |||
1154 | static int eps_init(struct mv_udc *udc) | 1291 | static int eps_init(struct mv_udc *udc) |
1155 | { | 1292 | { |
1156 | struct mv_ep *ep; | 1293 | struct mv_ep *ep; |
@@ -1257,7 +1394,7 @@ static int mv_udc_start(struct usb_gadget_driver *driver, | |||
1257 | 1394 | ||
1258 | udc->usb_state = USB_STATE_ATTACHED; | 1395 | udc->usb_state = USB_STATE_ATTACHED; |
1259 | udc->ep0_state = WAIT_FOR_SETUP; | 1396 | udc->ep0_state = WAIT_FOR_SETUP; |
1260 | udc->ep0_dir = USB_DIR_OUT; | 1397 | udc->ep0_dir = EP_DIR_OUT; |
1261 | 1398 | ||
1262 | spin_unlock_irqrestore(&udc->lock, flags); | 1399 | spin_unlock_irqrestore(&udc->lock, flags); |
1263 | 1400 | ||
@@ -1269,9 +1406,13 @@ static int mv_udc_start(struct usb_gadget_driver *driver, | |||
1269 | udc->gadget.dev.driver = NULL; | 1406 | udc->gadget.dev.driver = NULL; |
1270 | return retval; | 1407 | return retval; |
1271 | } | 1408 | } |
1272 | udc_reset(udc); | 1409 | |
1273 | ep0_reset(udc); | 1410 | /* pullup is always on */ |
1274 | udc_start(udc); | 1411 | mv_udc_pullup(&udc->gadget, 1); |
1412 | |||
1413 | /* When boot with cable attached, there will be no vbus irq occurred */ | ||
1414 | if (udc->qwork) | ||
1415 | queue_work(udc->qwork, &udc->vbus_work); | ||
1275 | 1416 | ||
1276 | return 0; | 1417 | return 0; |
1277 | } | 1418 | } |
@@ -1284,13 +1425,16 @@ static int mv_udc_stop(struct usb_gadget_driver *driver) | |||
1284 | if (!udc) | 1425 | if (!udc) |
1285 | return -ENODEV; | 1426 | return -ENODEV; |
1286 | 1427 | ||
1287 | udc_stop(udc); | ||
1288 | |||
1289 | spin_lock_irqsave(&udc->lock, flags); | 1428 | spin_lock_irqsave(&udc->lock, flags); |
1290 | 1429 | ||
1430 | mv_udc_enable(udc); | ||
1431 | udc_stop(udc); | ||
1432 | |||
1291 | /* stop all usb activities */ | 1433 | /* stop all usb activities */ |
1292 | udc->gadget.speed = USB_SPEED_UNKNOWN; | 1434 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
1293 | stop_activity(udc, driver); | 1435 | stop_activity(udc, driver); |
1436 | mv_udc_disable(udc); | ||
1437 | |||
1294 | spin_unlock_irqrestore(&udc->lock, flags); | 1438 | spin_unlock_irqrestore(&udc->lock, flags); |
1295 | 1439 | ||
1296 | /* unbind gadget driver */ | 1440 | /* unbind gadget driver */ |
@@ -1301,6 +1445,31 @@ static int mv_udc_stop(struct usb_gadget_driver *driver) | |||
1301 | return 0; | 1445 | return 0; |
1302 | } | 1446 | } |
1303 | 1447 | ||
1448 | static void mv_set_ptc(struct mv_udc *udc, u32 mode) | ||
1449 | { | ||
1450 | u32 portsc; | ||
1451 | |||
1452 | portsc = readl(&udc->op_regs->portsc[0]); | ||
1453 | portsc |= mode << 16; | ||
1454 | writel(portsc, &udc->op_regs->portsc[0]); | ||
1455 | } | ||
1456 | |||
1457 | static void prime_status_complete(struct usb_ep *ep, struct usb_request *_req) | ||
1458 | { | ||
1459 | struct mv_udc *udc = the_controller; | ||
1460 | struct mv_req *req = container_of(_req, struct mv_req, req); | ||
1461 | unsigned long flags; | ||
1462 | |||
1463 | dev_info(&udc->dev->dev, "switch to test mode %d\n", req->test_mode); | ||
1464 | |||
1465 | spin_lock_irqsave(&udc->lock, flags); | ||
1466 | if (req->test_mode) { | ||
1467 | mv_set_ptc(udc, req->test_mode); | ||
1468 | req->test_mode = 0; | ||
1469 | } | ||
1470 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1471 | } | ||
1472 | |||
1304 | static int | 1473 | static int |
1305 | udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty) | 1474 | udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty) |
1306 | { | 1475 | { |
@@ -1310,6 +1479,7 @@ udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty) | |||
1310 | 1479 | ||
1311 | ep = &udc->eps[0]; | 1480 | ep = &udc->eps[0]; |
1312 | udc->ep0_dir = direction; | 1481 | udc->ep0_dir = direction; |
1482 | udc->ep0_state = WAIT_FOR_OUT_STATUS; | ||
1313 | 1483 | ||
1314 | req = udc->status_req; | 1484 | req = udc->status_req; |
1315 | 1485 | ||
@@ -1323,9 +1493,21 @@ udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty) | |||
1323 | req->ep = ep; | 1493 | req->ep = ep; |
1324 | req->req.status = -EINPROGRESS; | 1494 | req->req.status = -EINPROGRESS; |
1325 | req->req.actual = 0; | 1495 | req->req.actual = 0; |
1326 | req->req.complete = NULL; | 1496 | if (udc->test_mode) { |
1497 | req->req.complete = prime_status_complete; | ||
1498 | req->test_mode = udc->test_mode; | ||
1499 | udc->test_mode = 0; | ||
1500 | } else | ||
1501 | req->req.complete = NULL; | ||
1327 | req->dtd_count = 0; | 1502 | req->dtd_count = 0; |
1328 | 1503 | ||
1504 | if (req->req.dma == DMA_ADDR_INVALID) { | ||
1505 | req->req.dma = dma_map_single(ep->udc->gadget.dev.parent, | ||
1506 | req->req.buf, req->req.length, | ||
1507 | ep_dir(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
1508 | req->mapped = 1; | ||
1509 | } | ||
1510 | |||
1329 | /* prime the data phase */ | 1511 | /* prime the data phase */ |
1330 | if (!req_to_dtd(req)) | 1512 | if (!req_to_dtd(req)) |
1331 | retval = queue_dtd(ep, req); | 1513 | retval = queue_dtd(ep, req); |
@@ -1346,6 +1528,17 @@ out: | |||
1346 | return retval; | 1528 | return retval; |
1347 | } | 1529 | } |
1348 | 1530 | ||
1531 | static void mv_udc_testmode(struct mv_udc *udc, u16 index) | ||
1532 | { | ||
1533 | if (index <= TEST_FORCE_EN) { | ||
1534 | udc->test_mode = index; | ||
1535 | if (udc_prime_status(udc, EP_DIR_IN, 0, true)) | ||
1536 | ep0_stall(udc); | ||
1537 | } else | ||
1538 | dev_err(&udc->dev->dev, | ||
1539 | "This test mode(%d) is not supported\n", index); | ||
1540 | } | ||
1541 | |||
1349 | static void ch9setaddress(struct mv_udc *udc, struct usb_ctrlrequest *setup) | 1542 | static void ch9setaddress(struct mv_udc *udc, struct usb_ctrlrequest *setup) |
1350 | { | 1543 | { |
1351 | udc->dev_addr = (u8)setup->wValue; | 1544 | udc->dev_addr = (u8)setup->wValue; |
@@ -1360,7 +1553,7 @@ static void ch9setaddress(struct mv_udc *udc, struct usb_ctrlrequest *setup) | |||
1360 | static void ch9getstatus(struct mv_udc *udc, u8 ep_num, | 1553 | static void ch9getstatus(struct mv_udc *udc, u8 ep_num, |
1361 | struct usb_ctrlrequest *setup) | 1554 | struct usb_ctrlrequest *setup) |
1362 | { | 1555 | { |
1363 | u16 status; | 1556 | u16 status = 0; |
1364 | int retval; | 1557 | int retval; |
1365 | 1558 | ||
1366 | if ((setup->bRequestType & (USB_DIR_IN | USB_TYPE_MASK)) | 1559 | if ((setup->bRequestType & (USB_DIR_IN | USB_TYPE_MASK)) |
@@ -1388,6 +1581,8 @@ static void ch9getstatus(struct mv_udc *udc, u8 ep_num, | |||
1388 | retval = udc_prime_status(udc, EP_DIR_IN, status, false); | 1581 | retval = udc_prime_status(udc, EP_DIR_IN, status, false); |
1389 | if (retval) | 1582 | if (retval) |
1390 | ep0_stall(udc); | 1583 | ep0_stall(udc); |
1584 | else | ||
1585 | udc->ep0_state = DATA_STATE_XMIT; | ||
1391 | } | 1586 | } |
1392 | 1587 | ||
1393 | static void ch9clearfeature(struct mv_udc *udc, struct usb_ctrlrequest *setup) | 1588 | static void ch9clearfeature(struct mv_udc *udc, struct usb_ctrlrequest *setup) |
@@ -1402,9 +1597,6 @@ static void ch9clearfeature(struct mv_udc *udc, struct usb_ctrlrequest *setup) | |||
1402 | case USB_DEVICE_REMOTE_WAKEUP: | 1597 | case USB_DEVICE_REMOTE_WAKEUP: |
1403 | udc->remote_wakeup = 0; | 1598 | udc->remote_wakeup = 0; |
1404 | break; | 1599 | break; |
1405 | case USB_DEVICE_TEST_MODE: | ||
1406 | mv_udc_testmode(udc, 0, false); | ||
1407 | break; | ||
1408 | default: | 1600 | default: |
1409 | goto out; | 1601 | goto out; |
1410 | } | 1602 | } |
@@ -1433,8 +1625,6 @@ static void ch9clearfeature(struct mv_udc *udc, struct usb_ctrlrequest *setup) | |||
1433 | 1625 | ||
1434 | if (udc_prime_status(udc, EP_DIR_IN, 0, true)) | 1626 | if (udc_prime_status(udc, EP_DIR_IN, 0, true)) |
1435 | ep0_stall(udc); | 1627 | ep0_stall(udc); |
1436 | else | ||
1437 | udc->ep0_state = DATA_STATE_XMIT; | ||
1438 | out: | 1628 | out: |
1439 | return; | 1629 | return; |
1440 | } | 1630 | } |
@@ -1452,16 +1642,16 @@ static void ch9setfeature(struct mv_udc *udc, struct usb_ctrlrequest *setup) | |||
1452 | break; | 1642 | break; |
1453 | case USB_DEVICE_TEST_MODE: | 1643 | case USB_DEVICE_TEST_MODE: |
1454 | if (setup->wIndex & 0xFF | 1644 | if (setup->wIndex & 0xFF |
1455 | && udc->gadget.speed != USB_SPEED_HIGH) | 1645 | || udc->gadget.speed != USB_SPEED_HIGH) |
1456 | goto out; | 1646 | ep0_stall(udc); |
1457 | if (udc->usb_state == USB_STATE_CONFIGURED | 1647 | |
1458 | || udc->usb_state == USB_STATE_ADDRESS | 1648 | if (udc->usb_state != USB_STATE_CONFIGURED |
1459 | || udc->usb_state == USB_STATE_DEFAULT) | 1649 | && udc->usb_state != USB_STATE_ADDRESS |
1460 | mv_udc_testmode(udc, | 1650 | && udc->usb_state != USB_STATE_DEFAULT) |
1461 | setup->wIndex & 0xFF00, true); | 1651 | ep0_stall(udc); |
1462 | else | 1652 | |
1463 | goto out; | 1653 | mv_udc_testmode(udc, (setup->wIndex >> 8)); |
1464 | break; | 1654 | goto out; |
1465 | default: | 1655 | default: |
1466 | goto out; | 1656 | goto out; |
1467 | } | 1657 | } |
@@ -1599,8 +1789,7 @@ static void get_setup_data(struct mv_udc *udc, u8 ep_num, u8 *buffer_ptr) | |||
1599 | dqh = &udc->ep_dqh[ep_num * 2 + EP_DIR_OUT]; | 1789 | dqh = &udc->ep_dqh[ep_num * 2 + EP_DIR_OUT]; |
1600 | 1790 | ||
1601 | /* Clear bit in ENDPTSETUPSTAT */ | 1791 | /* Clear bit in ENDPTSETUPSTAT */ |
1602 | temp = readl(&udc->op_regs->epsetupstat); | 1792 | writel((1 << ep_num), &udc->op_regs->epsetupstat); |
1603 | writel(temp | (1 << ep_num), &udc->op_regs->epsetupstat); | ||
1604 | 1793 | ||
1605 | /* while a hazard exists when setup package arrives */ | 1794 | /* while a hazard exists when setup package arrives */ |
1606 | do { | 1795 | do { |
@@ -1871,23 +2060,57 @@ static irqreturn_t mv_udc_irq(int irq, void *dev) | |||
1871 | return IRQ_HANDLED; | 2060 | return IRQ_HANDLED; |
1872 | } | 2061 | } |
1873 | 2062 | ||
2063 | static irqreturn_t mv_udc_vbus_irq(int irq, void *dev) | ||
2064 | { | ||
2065 | struct mv_udc *udc = (struct mv_udc *)dev; | ||
2066 | |||
2067 | /* polling VBUS and init phy may cause too much time*/ | ||
2068 | if (udc->qwork) | ||
2069 | queue_work(udc->qwork, &udc->vbus_work); | ||
2070 | |||
2071 | return IRQ_HANDLED; | ||
2072 | } | ||
2073 | |||
2074 | static void mv_udc_vbus_work(struct work_struct *work) | ||
2075 | { | ||
2076 | struct mv_udc *udc; | ||
2077 | unsigned int vbus; | ||
2078 | |||
2079 | udc = container_of(work, struct mv_udc, vbus_work); | ||
2080 | if (!udc->pdata->vbus) | ||
2081 | return; | ||
2082 | |||
2083 | vbus = udc->pdata->vbus->poll(); | ||
2084 | dev_info(&udc->dev->dev, "vbus is %d\n", vbus); | ||
2085 | |||
2086 | if (vbus == VBUS_HIGH) | ||
2087 | mv_udc_vbus_session(&udc->gadget, 1); | ||
2088 | else if (vbus == VBUS_LOW) | ||
2089 | mv_udc_vbus_session(&udc->gadget, 0); | ||
2090 | } | ||
2091 | |||
1874 | /* release device structure */ | 2092 | /* release device structure */ |
1875 | static void gadget_release(struct device *_dev) | 2093 | static void gadget_release(struct device *_dev) |
1876 | { | 2094 | { |
1877 | struct mv_udc *udc = the_controller; | 2095 | struct mv_udc *udc = the_controller; |
1878 | 2096 | ||
1879 | complete(udc->done); | 2097 | complete(udc->done); |
1880 | kfree(udc); | ||
1881 | } | 2098 | } |
1882 | 2099 | ||
1883 | static int mv_udc_remove(struct platform_device *dev) | 2100 | static int __devexit mv_udc_remove(struct platform_device *dev) |
1884 | { | 2101 | { |
1885 | struct mv_udc *udc = the_controller; | 2102 | struct mv_udc *udc = the_controller; |
1886 | DECLARE_COMPLETION(done); | 2103 | int clk_i; |
1887 | 2104 | ||
1888 | usb_del_gadget_udc(&udc->gadget); | 2105 | usb_del_gadget_udc(&udc->gadget); |
1889 | 2106 | ||
1890 | udc->done = &done; | 2107 | if (udc->qwork) { |
2108 | flush_workqueue(udc->qwork); | ||
2109 | destroy_workqueue(udc->qwork); | ||
2110 | } | ||
2111 | |||
2112 | if (udc->pdata && udc->pdata->vbus && udc->clock_gating) | ||
2113 | free_irq(udc->pdata->vbus->irq, &dev->dev); | ||
1891 | 2114 | ||
1892 | /* free memory allocated in probe */ | 2115 | /* free memory allocated in probe */ |
1893 | if (udc->dtd_pool) | 2116 | if (udc->dtd_pool) |
@@ -1902,6 +2125,8 @@ static int mv_udc_remove(struct platform_device *dev) | |||
1902 | if (udc->irq) | 2125 | if (udc->irq) |
1903 | free_irq(udc->irq, &dev->dev); | 2126 | free_irq(udc->irq, &dev->dev); |
1904 | 2127 | ||
2128 | mv_udc_disable(udc); | ||
2129 | |||
1905 | if (udc->cap_regs) | 2130 | if (udc->cap_regs) |
1906 | iounmap(udc->cap_regs); | 2131 | iounmap(udc->cap_regs); |
1907 | udc->cap_regs = NULL; | 2132 | udc->cap_regs = NULL; |
@@ -1915,45 +2140,62 @@ static int mv_udc_remove(struct platform_device *dev) | |||
1915 | kfree(udc->status_req); | 2140 | kfree(udc->status_req); |
1916 | } | 2141 | } |
1917 | 2142 | ||
2143 | for (clk_i = 0; clk_i <= udc->clknum; clk_i++) | ||
2144 | clk_put(udc->clk[clk_i]); | ||
2145 | |||
1918 | device_unregister(&udc->gadget.dev); | 2146 | device_unregister(&udc->gadget.dev); |
1919 | 2147 | ||
1920 | /* free dev, wait for the release() finished */ | 2148 | /* free dev, wait for the release() finished */ |
1921 | wait_for_completion(&done); | 2149 | wait_for_completion(udc->done); |
2150 | kfree(udc); | ||
1922 | 2151 | ||
1923 | the_controller = NULL; | 2152 | the_controller = NULL; |
1924 | 2153 | ||
1925 | return 0; | 2154 | return 0; |
1926 | } | 2155 | } |
1927 | 2156 | ||
1928 | int mv_udc_probe(struct platform_device *dev) | 2157 | static int __devinit mv_udc_probe(struct platform_device *dev) |
1929 | { | 2158 | { |
2159 | struct mv_usb_platform_data *pdata = dev->dev.platform_data; | ||
1930 | struct mv_udc *udc; | 2160 | struct mv_udc *udc; |
1931 | int retval = 0; | 2161 | int retval = 0; |
2162 | int clk_i = 0; | ||
1932 | struct resource *r; | 2163 | struct resource *r; |
1933 | size_t size; | 2164 | size_t size; |
1934 | 2165 | ||
1935 | udc = kzalloc(sizeof *udc, GFP_KERNEL); | 2166 | if (pdata == NULL) { |
2167 | dev_err(&dev->dev, "missing platform_data\n"); | ||
2168 | return -ENODEV; | ||
2169 | } | ||
2170 | |||
2171 | size = sizeof(*udc) + sizeof(struct clk *) * pdata->clknum; | ||
2172 | udc = kzalloc(size, GFP_KERNEL); | ||
1936 | if (udc == NULL) { | 2173 | if (udc == NULL) { |
1937 | dev_err(&dev->dev, "failed to allocate memory for udc\n"); | 2174 | dev_err(&dev->dev, "failed to allocate memory for udc\n"); |
1938 | retval = -ENOMEM; | 2175 | return -ENOMEM; |
1939 | goto error; | ||
1940 | } | 2176 | } |
1941 | 2177 | ||
2178 | the_controller = udc; | ||
2179 | udc->done = &release_done; | ||
2180 | udc->pdata = dev->dev.platform_data; | ||
1942 | spin_lock_init(&udc->lock); | 2181 | spin_lock_init(&udc->lock); |
1943 | 2182 | ||
1944 | udc->dev = dev; | 2183 | udc->dev = dev; |
1945 | 2184 | ||
1946 | udc->clk = clk_get(&dev->dev, "U2OCLK"); | 2185 | udc->clknum = pdata->clknum; |
1947 | if (IS_ERR(udc->clk)) { | 2186 | for (clk_i = 0; clk_i < udc->clknum; clk_i++) { |
1948 | retval = PTR_ERR(udc->clk); | 2187 | udc->clk[clk_i] = clk_get(&dev->dev, pdata->clkname[clk_i]); |
1949 | goto error; | 2188 | if (IS_ERR(udc->clk[clk_i])) { |
2189 | retval = PTR_ERR(udc->clk[clk_i]); | ||
2190 | goto err_put_clk; | ||
2191 | } | ||
1950 | } | 2192 | } |
1951 | 2193 | ||
1952 | r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "u2o"); | 2194 | r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "capregs"); |
1953 | if (r == NULL) { | 2195 | if (r == NULL) { |
1954 | dev_err(&dev->dev, "no I/O memory resource defined\n"); | 2196 | dev_err(&dev->dev, "no I/O memory resource defined\n"); |
1955 | retval = -ENODEV; | 2197 | retval = -ENODEV; |
1956 | goto error; | 2198 | goto err_put_clk; |
1957 | } | 2199 | } |
1958 | 2200 | ||
1959 | udc->cap_regs = (struct mv_cap_regs __iomem *) | 2201 | udc->cap_regs = (struct mv_cap_regs __iomem *) |
@@ -1961,29 +2203,31 @@ int mv_udc_probe(struct platform_device *dev) | |||
1961 | if (udc->cap_regs == NULL) { | 2203 | if (udc->cap_regs == NULL) { |
1962 | dev_err(&dev->dev, "failed to map I/O memory\n"); | 2204 | dev_err(&dev->dev, "failed to map I/O memory\n"); |
1963 | retval = -EBUSY; | 2205 | retval = -EBUSY; |
1964 | goto error; | 2206 | goto err_put_clk; |
1965 | } | 2207 | } |
1966 | 2208 | ||
1967 | r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "u2ophy"); | 2209 | r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "phyregs"); |
1968 | if (r == NULL) { | 2210 | if (r == NULL) { |
1969 | dev_err(&dev->dev, "no phy I/O memory resource defined\n"); | 2211 | dev_err(&dev->dev, "no phy I/O memory resource defined\n"); |
1970 | retval = -ENODEV; | 2212 | retval = -ENODEV; |
1971 | goto error; | 2213 | goto err_iounmap_capreg; |
1972 | } | 2214 | } |
1973 | 2215 | ||
1974 | udc->phy_regs = (unsigned int)ioremap(r->start, resource_size(r)); | 2216 | udc->phy_regs = (unsigned int)ioremap(r->start, resource_size(r)); |
1975 | if (udc->phy_regs == 0) { | 2217 | if (udc->phy_regs == 0) { |
1976 | dev_err(&dev->dev, "failed to map phy I/O memory\n"); | 2218 | dev_err(&dev->dev, "failed to map phy I/O memory\n"); |
1977 | retval = -EBUSY; | 2219 | retval = -EBUSY; |
1978 | goto error; | 2220 | goto err_iounmap_capreg; |
1979 | } | 2221 | } |
1980 | 2222 | ||
1981 | /* we will acces controller register, so enable the clk */ | 2223 | /* we will acces controller register, so enable the clk */ |
1982 | clk_enable(udc->clk); | 2224 | udc_clock_enable(udc); |
1983 | retval = mv_udc_phy_init(udc->phy_regs); | 2225 | if (pdata->phy_init) { |
1984 | if (retval) { | 2226 | retval = pdata->phy_init(udc->phy_regs); |
1985 | dev_err(&dev->dev, "phy initialization error %d\n", retval); | 2227 | if (retval) { |
1986 | goto error; | 2228 | dev_err(&dev->dev, "phy init error %d\n", retval); |
2229 | goto err_iounmap_phyreg; | ||
2230 | } | ||
1987 | } | 2231 | } |
1988 | 2232 | ||
1989 | udc->op_regs = (struct mv_op_regs __iomem *)((u32)udc->cap_regs | 2233 | udc->op_regs = (struct mv_op_regs __iomem *)((u32)udc->cap_regs |
@@ -1991,6 +2235,13 @@ int mv_udc_probe(struct platform_device *dev) | |||
1991 | & CAPLENGTH_MASK)); | 2235 | & CAPLENGTH_MASK)); |
1992 | udc->max_eps = readl(&udc->cap_regs->dccparams) & DCCPARAMS_DEN_MASK; | 2236 | udc->max_eps = readl(&udc->cap_regs->dccparams) & DCCPARAMS_DEN_MASK; |
1993 | 2237 | ||
2238 | /* | ||
2239 | * some platform will use usb to download image, it may not disconnect | ||
2240 | * usb gadget before loading kernel. So first stop udc here. | ||
2241 | */ | ||
2242 | udc_stop(udc); | ||
2243 | writel(0xFFFFFFFF, &udc->op_regs->usbsts); | ||
2244 | |||
1994 | size = udc->max_eps * sizeof(struct mv_dqh) *2; | 2245 | size = udc->max_eps * sizeof(struct mv_dqh) *2; |
1995 | size = (size + DQH_ALIGNMENT - 1) & ~(DQH_ALIGNMENT - 1); | 2246 | size = (size + DQH_ALIGNMENT - 1) & ~(DQH_ALIGNMENT - 1); |
1996 | udc->ep_dqh = dma_alloc_coherent(&dev->dev, size, | 2247 | udc->ep_dqh = dma_alloc_coherent(&dev->dev, size, |
@@ -1999,7 +2250,7 @@ int mv_udc_probe(struct platform_device *dev) | |||
1999 | if (udc->ep_dqh == NULL) { | 2250 | if (udc->ep_dqh == NULL) { |
2000 | dev_err(&dev->dev, "allocate dQH memory failed\n"); | 2251 | dev_err(&dev->dev, "allocate dQH memory failed\n"); |
2001 | retval = -ENOMEM; | 2252 | retval = -ENOMEM; |
2002 | goto error; | 2253 | goto err_disable_clock; |
2003 | } | 2254 | } |
2004 | udc->ep_dqh_size = size; | 2255 | udc->ep_dqh_size = size; |
2005 | 2256 | ||
@@ -2012,7 +2263,7 @@ int mv_udc_probe(struct platform_device *dev) | |||
2012 | 2263 | ||
2013 | if (!udc->dtd_pool) { | 2264 | if (!udc->dtd_pool) { |
2014 | retval = -ENOMEM; | 2265 | retval = -ENOMEM; |
2015 | goto error; | 2266 | goto err_free_dma; |
2016 | } | 2267 | } |
2017 | 2268 | ||
2018 | size = udc->max_eps * sizeof(struct mv_ep) *2; | 2269 | size = udc->max_eps * sizeof(struct mv_ep) *2; |
@@ -2020,7 +2271,7 @@ int mv_udc_probe(struct platform_device *dev) | |||
2020 | if (udc->eps == NULL) { | 2271 | if (udc->eps == NULL) { |
2021 | dev_err(&dev->dev, "allocate ep memory failed\n"); | 2272 | dev_err(&dev->dev, "allocate ep memory failed\n"); |
2022 | retval = -ENOMEM; | 2273 | retval = -ENOMEM; |
2023 | goto error; | 2274 | goto err_destroy_dma; |
2024 | } | 2275 | } |
2025 | 2276 | ||
2026 | /* initialize ep0 status request structure */ | 2277 | /* initialize ep0 status request structure */ |
@@ -2028,13 +2279,13 @@ int mv_udc_probe(struct platform_device *dev) | |||
2028 | if (!udc->status_req) { | 2279 | if (!udc->status_req) { |
2029 | dev_err(&dev->dev, "allocate status_req memory failed\n"); | 2280 | dev_err(&dev->dev, "allocate status_req memory failed\n"); |
2030 | retval = -ENOMEM; | 2281 | retval = -ENOMEM; |
2031 | goto error; | 2282 | goto err_free_eps; |
2032 | } | 2283 | } |
2033 | INIT_LIST_HEAD(&udc->status_req->queue); | 2284 | INIT_LIST_HEAD(&udc->status_req->queue); |
2034 | 2285 | ||
2035 | /* allocate a small amount of memory to get valid address */ | 2286 | /* allocate a small amount of memory to get valid address */ |
2036 | udc->status_req->req.buf = kzalloc(8, GFP_KERNEL); | 2287 | udc->status_req->req.buf = kzalloc(8, GFP_KERNEL); |
2037 | udc->status_req->req.dma = virt_to_phys(udc->status_req->req.buf); | 2288 | udc->status_req->req.dma = DMA_ADDR_INVALID; |
2038 | 2289 | ||
2039 | udc->resume_state = USB_STATE_NOTATTACHED; | 2290 | udc->resume_state = USB_STATE_NOTATTACHED; |
2040 | udc->usb_state = USB_STATE_POWERED; | 2291 | udc->usb_state = USB_STATE_POWERED; |
@@ -2045,15 +2296,15 @@ int mv_udc_probe(struct platform_device *dev) | |||
2045 | if (r == NULL) { | 2296 | if (r == NULL) { |
2046 | dev_err(&dev->dev, "no IRQ resource defined\n"); | 2297 | dev_err(&dev->dev, "no IRQ resource defined\n"); |
2047 | retval = -ENODEV; | 2298 | retval = -ENODEV; |
2048 | goto error; | 2299 | goto err_free_status_req; |
2049 | } | 2300 | } |
2050 | udc->irq = r->start; | 2301 | udc->irq = r->start; |
2051 | if (request_irq(udc->irq, mv_udc_irq, | 2302 | if (request_irq(udc->irq, mv_udc_irq, |
2052 | IRQF_DISABLED | IRQF_SHARED, driver_name, udc)) { | 2303 | IRQF_SHARED, driver_name, udc)) { |
2053 | dev_err(&dev->dev, "Request irq %d for UDC failed\n", | 2304 | dev_err(&dev->dev, "Request irq %d for UDC failed\n", |
2054 | udc->irq); | 2305 | udc->irq); |
2055 | retval = -ENODEV; | 2306 | retval = -ENODEV; |
2056 | goto error; | 2307 | goto err_free_status_req; |
2057 | } | 2308 | } |
2058 | 2309 | ||
2059 | /* initialize gadget structure */ | 2310 | /* initialize gadget structure */ |
@@ -2072,18 +2323,82 @@ int mv_udc_probe(struct platform_device *dev) | |||
2072 | 2323 | ||
2073 | retval = device_register(&udc->gadget.dev); | 2324 | retval = device_register(&udc->gadget.dev); |
2074 | if (retval) | 2325 | if (retval) |
2075 | goto error; | 2326 | goto err_free_irq; |
2076 | 2327 | ||
2077 | eps_init(udc); | 2328 | eps_init(udc); |
2078 | 2329 | ||
2079 | the_controller = udc; | 2330 | /* VBUS detect: we can disable/enable clock on demand.*/ |
2331 | if (pdata->vbus) { | ||
2332 | udc->clock_gating = 1; | ||
2333 | retval = request_threaded_irq(pdata->vbus->irq, NULL, | ||
2334 | mv_udc_vbus_irq, IRQF_ONESHOT, "vbus", udc); | ||
2335 | if (retval) { | ||
2336 | dev_info(&dev->dev, | ||
2337 | "Can not request irq for VBUS, " | ||
2338 | "disable clock gating\n"); | ||
2339 | udc->clock_gating = 0; | ||
2340 | } | ||
2341 | |||
2342 | udc->qwork = create_singlethread_workqueue("mv_udc_queue"); | ||
2343 | if (!udc->qwork) { | ||
2344 | dev_err(&dev->dev, "cannot create workqueue\n"); | ||
2345 | retval = -ENOMEM; | ||
2346 | goto err_unregister; | ||
2347 | } | ||
2348 | |||
2349 | INIT_WORK(&udc->vbus_work, mv_udc_vbus_work); | ||
2350 | } | ||
2351 | |||
2352 | /* | ||
2353 | * When clock gating is supported, we can disable clk and phy. | ||
2354 | * If not, it means that VBUS detection is not supported, we | ||
2355 | * have to enable vbus active all the time to let controller work. | ||
2356 | */ | ||
2357 | if (udc->clock_gating) { | ||
2358 | if (udc->pdata->phy_deinit) | ||
2359 | udc->pdata->phy_deinit(udc->phy_regs); | ||
2360 | udc_clock_disable(udc); | ||
2361 | } else | ||
2362 | udc->vbus_active = 1; | ||
2080 | 2363 | ||
2081 | retval = usb_add_gadget_udc(&dev->dev, &udc->gadget); | 2364 | retval = usb_add_gadget_udc(&dev->dev, &udc->gadget); |
2082 | if (!retval) | 2365 | if (retval) |
2083 | return retval; | 2366 | goto err_unregister; |
2084 | error: | 2367 | |
2085 | if (udc) | 2368 | dev_info(&dev->dev, "successful probe UDC device %s clock gating.\n", |
2086 | mv_udc_remove(udc->dev); | 2369 | udc->clock_gating ? "with" : "without"); |
2370 | |||
2371 | return 0; | ||
2372 | |||
2373 | err_unregister: | ||
2374 | if (udc->pdata && udc->pdata->vbus && udc->clock_gating) | ||
2375 | free_irq(pdata->vbus->irq, &dev->dev); | ||
2376 | device_unregister(&udc->gadget.dev); | ||
2377 | err_free_irq: | ||
2378 | free_irq(udc->irq, &dev->dev); | ||
2379 | err_free_status_req: | ||
2380 | kfree(udc->status_req->req.buf); | ||
2381 | kfree(udc->status_req); | ||
2382 | err_free_eps: | ||
2383 | kfree(udc->eps); | ||
2384 | err_destroy_dma: | ||
2385 | dma_pool_destroy(udc->dtd_pool); | ||
2386 | err_free_dma: | ||
2387 | dma_free_coherent(&dev->dev, udc->ep_dqh_size, | ||
2388 | udc->ep_dqh, udc->ep_dqh_dma); | ||
2389 | err_disable_clock: | ||
2390 | if (udc->pdata->phy_deinit) | ||
2391 | udc->pdata->phy_deinit(udc->phy_regs); | ||
2392 | udc_clock_disable(udc); | ||
2393 | err_iounmap_phyreg: | ||
2394 | iounmap((void *)udc->phy_regs); | ||
2395 | err_iounmap_capreg: | ||
2396 | iounmap(udc->cap_regs); | ||
2397 | err_put_clk: | ||
2398 | for (clk_i--; clk_i >= 0; clk_i--) | ||
2399 | clk_put(udc->clk[clk_i]); | ||
2400 | the_controller = NULL; | ||
2401 | kfree(udc); | ||
2087 | return retval; | 2402 | return retval; |
2088 | } | 2403 | } |
2089 | 2404 | ||
@@ -2102,11 +2417,16 @@ static int mv_udc_resume(struct device *_dev) | |||
2102 | struct mv_udc *udc = the_controller; | 2417 | struct mv_udc *udc = the_controller; |
2103 | int retval; | 2418 | int retval; |
2104 | 2419 | ||
2105 | retval = mv_udc_phy_init(udc->phy_regs); | 2420 | if (udc->pdata->phy_init) { |
2106 | if (retval) { | 2421 | retval = udc->pdata->phy_init(udc->phy_regs); |
2107 | dev_err(_dev, "phy initialization error %d\n", retval); | 2422 | if (retval) { |
2108 | return retval; | 2423 | dev_err(&udc->dev->dev, |
2424 | "init phy error %d when resume back\n", | ||
2425 | retval); | ||
2426 | return retval; | ||
2427 | } | ||
2109 | } | 2428 | } |
2429 | |||
2110 | udc_reset(udc); | 2430 | udc_reset(udc); |
2111 | ep0_reset(udc); | 2431 | ep0_reset(udc); |
2112 | udc_start(udc); | 2432 | udc_start(udc); |
@@ -2120,9 +2440,21 @@ static const struct dev_pm_ops mv_udc_pm_ops = { | |||
2120 | }; | 2440 | }; |
2121 | #endif | 2441 | #endif |
2122 | 2442 | ||
2443 | static void mv_udc_shutdown(struct platform_device *dev) | ||
2444 | { | ||
2445 | struct mv_udc *udc = the_controller; | ||
2446 | u32 mode; | ||
2447 | |||
2448 | /* reset controller mode to IDLE */ | ||
2449 | mode = readl(&udc->op_regs->usbmode); | ||
2450 | mode &= ~3; | ||
2451 | writel(mode, &udc->op_regs->usbmode); | ||
2452 | } | ||
2453 | |||
2123 | static struct platform_driver udc_driver = { | 2454 | static struct platform_driver udc_driver = { |
2124 | .probe = mv_udc_probe, | 2455 | .probe = mv_udc_probe, |
2125 | .remove = __exit_p(mv_udc_remove), | 2456 | .remove = __exit_p(mv_udc_remove), |
2457 | .shutdown = mv_udc_shutdown, | ||
2126 | .driver = { | 2458 | .driver = { |
2127 | .owner = THIS_MODULE, | 2459 | .owner = THIS_MODULE, |
2128 | .name = "pxa-u2o", | 2460 | .name = "pxa-u2o", |
diff --git a/drivers/usb/gadget/mv_udc_phy.c b/drivers/usb/gadget/mv_udc_phy.c deleted file mode 100644 index d4dea97e38a5..000000000000 --- a/drivers/usb/gadget/mv_udc_phy.c +++ /dev/null | |||
@@ -1,214 +0,0 @@ | |||
1 | #include <linux/delay.h> | ||
2 | #include <linux/timer.h> | ||
3 | #include <linux/io.h> | ||
4 | #include <linux/errno.h> | ||
5 | |||
6 | #include <mach/cputype.h> | ||
7 | |||
8 | #ifdef CONFIG_ARCH_MMP | ||
9 | |||
10 | #define UTMI_REVISION 0x0 | ||
11 | #define UTMI_CTRL 0x4 | ||
12 | #define UTMI_PLL 0x8 | ||
13 | #define UTMI_TX 0xc | ||
14 | #define UTMI_RX 0x10 | ||
15 | #define UTMI_IVREF 0x14 | ||
16 | #define UTMI_T0 0x18 | ||
17 | #define UTMI_T1 0x1c | ||
18 | #define UTMI_T2 0x20 | ||
19 | #define UTMI_T3 0x24 | ||
20 | #define UTMI_T4 0x28 | ||
21 | #define UTMI_T5 0x2c | ||
22 | #define UTMI_RESERVE 0x30 | ||
23 | #define UTMI_USB_INT 0x34 | ||
24 | #define UTMI_DBG_CTL 0x38 | ||
25 | #define UTMI_OTG_ADDON 0x3c | ||
26 | |||
27 | /* For UTMICTRL Register */ | ||
28 | #define UTMI_CTRL_USB_CLK_EN (1 << 31) | ||
29 | /* pxa168 */ | ||
30 | #define UTMI_CTRL_SUSPEND_SET1 (1 << 30) | ||
31 | #define UTMI_CTRL_SUSPEND_SET2 (1 << 29) | ||
32 | #define UTMI_CTRL_RXBUF_PDWN (1 << 24) | ||
33 | #define UTMI_CTRL_TXBUF_PDWN (1 << 11) | ||
34 | |||
35 | #define UTMI_CTRL_INPKT_DELAY_SHIFT 30 | ||
36 | #define UTMI_CTRL_INPKT_DELAY_SOF_SHIFT 28 | ||
37 | #define UTMI_CTRL_PU_REF_SHIFT 20 | ||
38 | #define UTMI_CTRL_ARC_PULLDN_SHIFT 12 | ||
39 | #define UTMI_CTRL_PLL_PWR_UP_SHIFT 1 | ||
40 | #define UTMI_CTRL_PWR_UP_SHIFT 0 | ||
41 | /* For UTMI_PLL Register */ | ||
42 | #define UTMI_PLL_CLK_BLK_EN_SHIFT 24 | ||
43 | #define UTMI_PLL_FBDIV_SHIFT 4 | ||
44 | #define UTMI_PLL_REFDIV_SHIFT 0 | ||
45 | #define UTMI_PLL_FBDIV_MASK 0x00000FF0 | ||
46 | #define UTMI_PLL_REFDIV_MASK 0x0000000F | ||
47 | #define UTMI_PLL_ICP_MASK 0x00007000 | ||
48 | #define UTMI_PLL_KVCO_MASK 0x00031000 | ||
49 | #define UTMI_PLL_PLLCALI12_SHIFT 29 | ||
50 | #define UTMI_PLL_PLLCALI12_MASK (0x3 << 29) | ||
51 | #define UTMI_PLL_PLLVDD18_SHIFT 27 | ||
52 | #define UTMI_PLL_PLLVDD18_MASK (0x3 << 27) | ||
53 | #define UTMI_PLL_PLLVDD12_SHIFT 25 | ||
54 | #define UTMI_PLL_PLLVDD12_MASK (0x3 << 25) | ||
55 | #define UTMI_PLL_KVCO_SHIFT 15 | ||
56 | #define UTMI_PLL_ICP_SHIFT 12 | ||
57 | /* For UTMI_TX Register */ | ||
58 | #define UTMI_TX_REG_EXT_FS_RCAL_SHIFT 27 | ||
59 | #define UTMI_TX_REG_EXT_FS_RCAL_MASK (0xf << 27) | ||
60 | #define UTMI_TX_REG_EXT_FS_RCAL_EN_MASK 26 | ||
61 | #define UTMI_TX_REG_EXT_FS_RCAL_EN (0x1 << 26) | ||
62 | #define UTMI_TX_LOW_VDD_EN_SHIFT 11 | ||
63 | #define UTMI_TX_IMPCAL_VTH_SHIFT 14 | ||
64 | #define UTMI_TX_IMPCAL_VTH_MASK (0x7 << 14) | ||
65 | #define UTMI_TX_CK60_PHSEL_SHIFT 17 | ||
66 | #define UTMI_TX_CK60_PHSEL_MASK (0xf << 17) | ||
67 | #define UTMI_TX_TXVDD12_SHIFT 22 | ||
68 | #define UTMI_TX_TXVDD12_MASK (0x3 << 22) | ||
69 | #define UTMI_TX_AMP_SHIFT 0 | ||
70 | #define UTMI_TX_AMP_MASK (0x7 << 0) | ||
71 | /* For UTMI_RX Register */ | ||
72 | #define UTMI_RX_SQ_THRESH_SHIFT 4 | ||
73 | #define UTMI_RX_SQ_THRESH_MASK (0xf << 4) | ||
74 | #define UTMI_REG_SQ_LENGTH_SHIFT 15 | ||
75 | #define UTMI_REG_SQ_LENGTH_MASK (0x3 << 15) | ||
76 | |||
77 | #define REG_RCAL_START 0x00001000 | ||
78 | #define VCOCAL_START 0x00200000 | ||
79 | #define KVCO_EXT 0x00400000 | ||
80 | #define PLL_READY 0x00800000 | ||
81 | #define CLK_BLK_EN 0x01000000 | ||
82 | #endif | ||
83 | |||
84 | static unsigned int u2o_read(unsigned int base, unsigned int offset) | ||
85 | { | ||
86 | return readl(base + offset); | ||
87 | } | ||
88 | |||
89 | static void u2o_set(unsigned int base, unsigned int offset, unsigned int value) | ||
90 | { | ||
91 | unsigned int reg; | ||
92 | |||
93 | reg = readl(base + offset); | ||
94 | reg |= value; | ||
95 | writel(reg, base + offset); | ||
96 | readl(base + offset); | ||
97 | } | ||
98 | |||
99 | static void u2o_clear(unsigned int base, unsigned int offset, | ||
100 | unsigned int value) | ||
101 | { | ||
102 | unsigned int reg; | ||
103 | |||
104 | reg = readl(base + offset); | ||
105 | reg &= ~value; | ||
106 | writel(reg, base + offset); | ||
107 | readl(base + offset); | ||
108 | } | ||
109 | |||
110 | static void u2o_write(unsigned int base, unsigned int offset, | ||
111 | unsigned int value) | ||
112 | { | ||
113 | writel(value, base + offset); | ||
114 | readl(base + offset); | ||
115 | } | ||
116 | |||
117 | #ifdef CONFIG_ARCH_MMP | ||
118 | int mv_udc_phy_init(unsigned int base) | ||
119 | { | ||
120 | unsigned long timeout; | ||
121 | |||
122 | /* Initialize the USB PHY power */ | ||
123 | if (cpu_is_pxa910()) { | ||
124 | u2o_set(base, UTMI_CTRL, (1 << UTMI_CTRL_INPKT_DELAY_SOF_SHIFT) | ||
125 | | (1 << UTMI_CTRL_PU_REF_SHIFT)); | ||
126 | } | ||
127 | |||
128 | u2o_set(base, UTMI_CTRL, 1 << UTMI_CTRL_PLL_PWR_UP_SHIFT); | ||
129 | u2o_set(base, UTMI_CTRL, 1 << UTMI_CTRL_PWR_UP_SHIFT); | ||
130 | |||
131 | /* UTMI_PLL settings */ | ||
132 | u2o_clear(base, UTMI_PLL, UTMI_PLL_PLLVDD18_MASK | ||
133 | | UTMI_PLL_PLLVDD12_MASK | UTMI_PLL_PLLCALI12_MASK | ||
134 | | UTMI_PLL_FBDIV_MASK | UTMI_PLL_REFDIV_MASK | ||
135 | | UTMI_PLL_ICP_MASK | UTMI_PLL_KVCO_MASK); | ||
136 | |||
137 | u2o_set(base, UTMI_PLL, (0xee << UTMI_PLL_FBDIV_SHIFT) | ||
138 | | (0xb << UTMI_PLL_REFDIV_SHIFT) | ||
139 | | (3 << UTMI_PLL_PLLVDD18_SHIFT) | ||
140 | | (3 << UTMI_PLL_PLLVDD12_SHIFT) | ||
141 | | (3 << UTMI_PLL_PLLCALI12_SHIFT) | ||
142 | | (1 << UTMI_PLL_ICP_SHIFT) | (3 << UTMI_PLL_KVCO_SHIFT)); | ||
143 | |||
144 | /* UTMI_TX */ | ||
145 | u2o_clear(base, UTMI_TX, UTMI_TX_REG_EXT_FS_RCAL_EN_MASK | ||
146 | | UTMI_TX_TXVDD12_MASK | ||
147 | | UTMI_TX_CK60_PHSEL_MASK | UTMI_TX_IMPCAL_VTH_MASK | ||
148 | | UTMI_TX_REG_EXT_FS_RCAL_MASK | UTMI_TX_AMP_MASK); | ||
149 | u2o_set(base, UTMI_TX, (3 << UTMI_TX_TXVDD12_SHIFT) | ||
150 | | (4 << UTMI_TX_CK60_PHSEL_SHIFT) | ||
151 | | (4 << UTMI_TX_IMPCAL_VTH_SHIFT) | ||
152 | | (8 << UTMI_TX_REG_EXT_FS_RCAL_SHIFT) | ||
153 | | (3 << UTMI_TX_AMP_SHIFT)); | ||
154 | |||
155 | /* UTMI_RX */ | ||
156 | u2o_clear(base, UTMI_RX, UTMI_RX_SQ_THRESH_MASK | ||
157 | | UTMI_REG_SQ_LENGTH_MASK); | ||
158 | if (cpu_is_pxa168()) | ||
159 | u2o_set(base, UTMI_RX, (7 << UTMI_RX_SQ_THRESH_SHIFT) | ||
160 | | (2 << UTMI_REG_SQ_LENGTH_SHIFT)); | ||
161 | else | ||
162 | u2o_set(base, UTMI_RX, (0x7 << UTMI_RX_SQ_THRESH_SHIFT) | ||
163 | | (2 << UTMI_REG_SQ_LENGTH_SHIFT)); | ||
164 | |||
165 | /* UTMI_IVREF */ | ||
166 | if (cpu_is_pxa168()) | ||
167 | /* | ||
168 | * fixing Microsoft Altair board interface with NEC hub issue - | ||
169 | * Set UTMI_IVREF from 0x4a3 to 0x4bf | ||
170 | */ | ||
171 | u2o_write(base, UTMI_IVREF, 0x4bf); | ||
172 | |||
173 | /* calibrate */ | ||
174 | timeout = jiffies + 100; | ||
175 | while ((u2o_read(base, UTMI_PLL) & PLL_READY) == 0) { | ||
176 | if (time_after(jiffies, timeout)) | ||
177 | return -ETIME; | ||
178 | cpu_relax(); | ||
179 | } | ||
180 | |||
181 | /* toggle VCOCAL_START bit of UTMI_PLL */ | ||
182 | udelay(200); | ||
183 | u2o_set(base, UTMI_PLL, VCOCAL_START); | ||
184 | udelay(40); | ||
185 | u2o_clear(base, UTMI_PLL, VCOCAL_START); | ||
186 | |||
187 | /* toggle REG_RCAL_START bit of UTMI_TX */ | ||
188 | udelay(200); | ||
189 | u2o_set(base, UTMI_TX, REG_RCAL_START); | ||
190 | udelay(40); | ||
191 | u2o_clear(base, UTMI_TX, REG_RCAL_START); | ||
192 | udelay(200); | ||
193 | |||
194 | /* make sure phy is ready */ | ||
195 | timeout = jiffies + 100; | ||
196 | while ((u2o_read(base, UTMI_PLL) & PLL_READY) == 0) { | ||
197 | if (time_after(jiffies, timeout)) | ||
198 | return -ETIME; | ||
199 | cpu_relax(); | ||
200 | } | ||
201 | |||
202 | if (cpu_is_pxa168()) { | ||
203 | u2o_set(base, UTMI_RESERVE, 1 << 5); | ||
204 | /* Turn on UTMI PHY OTG extension */ | ||
205 | u2o_write(base, UTMI_OTG_ADDON, 1); | ||
206 | } | ||
207 | return 0; | ||
208 | } | ||
209 | #else | ||
210 | int mv_udc_phy_init(unsigned int base) | ||
211 | { | ||
212 | return 0; | ||
213 | } | ||
214 | #endif | ||
diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c index 62ee5087dcac..89530034dff1 100644 --- a/drivers/usb/gadget/ncm.c +++ b/drivers/usb/gadget/ncm.c | |||
@@ -14,15 +14,6 @@ | |||
14 | * it under the terms of the GNU General Public License as published by | 14 | * it under the terms of the GNU General Public License as published by |
15 | * the Free Software Foundation; either version 2 of the License, or | 15 | * the Free Software Foundation; either version 2 of the License, or |
16 | * (at your option) any later version. | 16 | * (at your option) any later version. |
17 | * | ||
18 | * This program is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | * GNU General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU General Public License | ||
24 | * along with this program; if not, write to the Free Software | ||
25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
26 | */ | 17 | */ |
27 | 18 | ||
28 | /* #define DEBUG */ | 19 | /* #define DEBUG */ |
diff --git a/drivers/usb/gadget/ndis.h b/drivers/usb/gadget/ndis.h index df886cec5ef4..b0e52fc277b4 100644 --- a/drivers/usb/gadget/ndis.h +++ b/drivers/usb/gadget/ndis.h | |||
@@ -10,12 +10,6 @@ | |||
10 | * | 10 | * |
11 | * This source code is offered for use in the public domain. You may | 11 | * This source code is offered for use in the public domain. You may |
12 | * use, modify or distribute it freely. | 12 | * use, modify or distribute it freely. |
13 | * | ||
14 | * This code is distributed in the hope that it will be useful but | ||
15 | * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY | ||
16 | * DISCLAIMED. This includes but is not limited to warranties of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
18 | * | ||
19 | */ | 13 | */ |
20 | 14 | ||
21 | #ifndef _LINUX_NDIS_H | 15 | #ifndef _LINUX_NDIS_H |
diff --git a/drivers/usb/gadget/net2272.c b/drivers/usb/gadget/net2272.c index ab98ea926a11..d1b76368472f 100644 --- a/drivers/usb/gadget/net2272.c +++ b/drivers/usb/gadget/net2272.c | |||
@@ -204,7 +204,7 @@ net2272_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
204 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | 204 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) |
205 | return -ESHUTDOWN; | 205 | return -ESHUTDOWN; |
206 | 206 | ||
207 | max = le16_to_cpu(desc->wMaxPacketSize) & 0x1fff; | 207 | max = usb_endpoint_maxp(desc) & 0x1fff; |
208 | 208 | ||
209 | spin_lock_irqsave(&dev->lock, flags); | 209 | spin_lock_irqsave(&dev->lock, flags); |
210 | _ep->maxpacket = max & 0x7fff; | 210 | _ep->maxpacket = max & 0x7fff; |
@@ -1172,17 +1172,18 @@ net2272_pullup(struct usb_gadget *_gadget, int is_on) | |||
1172 | return 0; | 1172 | return 0; |
1173 | } | 1173 | } |
1174 | 1174 | ||
1175 | static int net2272_start(struct usb_gadget_driver *driver, | 1175 | static int net2272_start(struct usb_gadget *_gadget, |
1176 | int (*bind)(struct usb_gadget *)); | 1176 | struct usb_gadget_driver *driver); |
1177 | static int net2272_stop(struct usb_gadget_driver *driver); | 1177 | static int net2272_stop(struct usb_gadget *_gadget, |
1178 | struct usb_gadget_driver *driver); | ||
1178 | 1179 | ||
1179 | static const struct usb_gadget_ops net2272_ops = { | 1180 | static const struct usb_gadget_ops net2272_ops = { |
1180 | .get_frame = net2272_get_frame, | 1181 | .get_frame = net2272_get_frame, |
1181 | .wakeup = net2272_wakeup, | 1182 | .wakeup = net2272_wakeup, |
1182 | .set_selfpowered = net2272_set_selfpowered, | 1183 | .set_selfpowered = net2272_set_selfpowered, |
1183 | .pullup = net2272_pullup, | 1184 | .pullup = net2272_pullup, |
1184 | .start = net2272_start, | 1185 | .udc_start = net2272_start, |
1185 | .stop = net2272_stop, | 1186 | .udc_stop = net2272_stop, |
1186 | }; | 1187 | }; |
1187 | 1188 | ||
1188 | /*---------------------------------------------------------------------------*/ | 1189 | /*---------------------------------------------------------------------------*/ |
@@ -1356,8 +1357,6 @@ net2272_set_fifo_mode(struct net2272 *dev, int mode) | |||
1356 | 1357 | ||
1357 | /*---------------------------------------------------------------------------*/ | 1358 | /*---------------------------------------------------------------------------*/ |
1358 | 1359 | ||
1359 | static struct net2272 *the_controller; | ||
1360 | |||
1361 | static void | 1360 | static void |
1362 | net2272_usb_reset(struct net2272 *dev) | 1361 | net2272_usb_reset(struct net2272 *dev) |
1363 | { | 1362 | { |
@@ -1453,20 +1452,17 @@ net2272_ep0_start(struct net2272 *dev) | |||
1453 | * disconnect is reported. then a host may connect again, or | 1452 | * disconnect is reported. then a host may connect again, or |
1454 | * the driver might get unbound. | 1453 | * the driver might get unbound. |
1455 | */ | 1454 | */ |
1456 | static int net2272_start(struct usb_gadget_driver *driver, | 1455 | static int net2272_start(struct usb_gadget *_gadget, |
1457 | int (*bind)(struct usb_gadget *)) | 1456 | struct usb_gadget_driver *driver) |
1458 | { | 1457 | { |
1459 | struct net2272 *dev = the_controller; | 1458 | struct net2272 *dev; |
1460 | int ret; | ||
1461 | unsigned i; | 1459 | unsigned i; |
1462 | 1460 | ||
1463 | if (!driver || !bind || !driver->unbind || !driver->setup || | 1461 | if (!driver || !driver->unbind || !driver->setup || |
1464 | driver->speed != USB_SPEED_HIGH) | 1462 | driver->speed != USB_SPEED_HIGH) |
1465 | return -EINVAL; | 1463 | return -EINVAL; |
1466 | if (!dev) | 1464 | |
1467 | return -ENODEV; | 1465 | dev = container_of(_gadget, struct net2272, gadget); |
1468 | if (dev->driver) | ||
1469 | return -EBUSY; | ||
1470 | 1466 | ||
1471 | for (i = 0; i < 4; ++i) | 1467 | for (i = 0; i < 4; ++i) |
1472 | dev->ep[i].irqs = 0; | 1468 | dev->ep[i].irqs = 0; |
@@ -1475,14 +1471,6 @@ static int net2272_start(struct usb_gadget_driver *driver, | |||
1475 | driver->driver.bus = NULL; | 1471 | driver->driver.bus = NULL; |
1476 | dev->driver = driver; | 1472 | dev->driver = driver; |
1477 | dev->gadget.dev.driver = &driver->driver; | 1473 | dev->gadget.dev.driver = &driver->driver; |
1478 | ret = bind(&dev->gadget); | ||
1479 | if (ret) { | ||
1480 | dev_dbg(dev->dev, "bind to driver %s --> %d\n", | ||
1481 | driver->driver.name, ret); | ||
1482 | dev->driver = NULL; | ||
1483 | dev->gadget.dev.driver = NULL; | ||
1484 | return ret; | ||
1485 | } | ||
1486 | 1474 | ||
1487 | /* ... then enable host detection and ep0; and we're ready | 1475 | /* ... then enable host detection and ep0; and we're ready |
1488 | * for set_configuration as well as eventual disconnect. | 1476 | * for set_configuration as well as eventual disconnect. |
@@ -1510,33 +1498,21 @@ stop_activity(struct net2272 *dev, struct usb_gadget_driver *driver) | |||
1510 | for (i = 0; i < 4; ++i) | 1498 | for (i = 0; i < 4; ++i) |
1511 | net2272_dequeue_all(&dev->ep[i]); | 1499 | net2272_dequeue_all(&dev->ep[i]); |
1512 | 1500 | ||
1513 | /* report disconnect; the driver is already quiesced */ | ||
1514 | if (driver) { | ||
1515 | spin_unlock(&dev->lock); | ||
1516 | driver->disconnect(&dev->gadget); | ||
1517 | spin_lock(&dev->lock); | ||
1518 | |||
1519 | } | ||
1520 | net2272_usb_reinit(dev); | 1501 | net2272_usb_reinit(dev); |
1521 | } | 1502 | } |
1522 | 1503 | ||
1523 | static int net2272_stop(struct usb_gadget_driver *driver) | 1504 | static int net2272_stop(struct usb_gadget *_gadget, |
1505 | struct usb_gadget_driver *driver) | ||
1524 | { | 1506 | { |
1525 | struct net2272 *dev = the_controller; | 1507 | struct net2272 *dev; |
1526 | unsigned long flags; | 1508 | unsigned long flags; |
1527 | 1509 | ||
1528 | if (!dev) | 1510 | dev = container_of(_gadget, struct net2272, gadget); |
1529 | return -ENODEV; | ||
1530 | if (!driver || driver != dev->driver) | ||
1531 | return -EINVAL; | ||
1532 | 1511 | ||
1533 | spin_lock_irqsave(&dev->lock, flags); | 1512 | spin_lock_irqsave(&dev->lock, flags); |
1534 | stop_activity(dev, driver); | 1513 | stop_activity(dev, driver); |
1535 | spin_unlock_irqrestore(&dev->lock, flags); | 1514 | spin_unlock_irqrestore(&dev->lock, flags); |
1536 | 1515 | ||
1537 | net2272_pullup(&dev->gadget, 0); | ||
1538 | |||
1539 | driver->unbind(&dev->gadget); | ||
1540 | dev->gadget.dev.driver = NULL; | 1516 | dev->gadget.dev.driver = NULL; |
1541 | dev->driver = NULL; | 1517 | dev->driver = NULL; |
1542 | 1518 | ||
@@ -1764,8 +1740,8 @@ net2272_handle_stat0_irqs(struct net2272 *dev, u8 stat) | |||
1764 | dev->gadget.speed = USB_SPEED_HIGH; | 1740 | dev->gadget.speed = USB_SPEED_HIGH; |
1765 | else | 1741 | else |
1766 | dev->gadget.speed = USB_SPEED_FULL; | 1742 | dev->gadget.speed = USB_SPEED_FULL; |
1767 | dev_dbg(dev->dev, "%s speed\n", | 1743 | dev_dbg(dev->dev, "%s\n", |
1768 | (dev->gadget.speed == USB_SPEED_HIGH) ? "high" : "full"); | 1744 | usb_speed_string(dev->gadget.speed)); |
1769 | } | 1745 | } |
1770 | 1746 | ||
1771 | ep = &dev->ep[0]; | 1747 | ep = &dev->ep[0]; |
@@ -2238,7 +2214,6 @@ net2272_remove(struct net2272 *dev) | |||
2238 | device_remove_file(dev->dev, &dev_attr_registers); | 2214 | device_remove_file(dev->dev, &dev_attr_registers); |
2239 | 2215 | ||
2240 | dev_info(dev->dev, "unbind\n"); | 2216 | dev_info(dev->dev, "unbind\n"); |
2241 | the_controller = NULL; | ||
2242 | } | 2217 | } |
2243 | 2218 | ||
2244 | static struct net2272 * __devinit | 2219 | static struct net2272 * __devinit |
@@ -2246,11 +2221,6 @@ net2272_probe_init(struct device *dev, unsigned int irq) | |||
2246 | { | 2221 | { |
2247 | struct net2272 *ret; | 2222 | struct net2272 *ret; |
2248 | 2223 | ||
2249 | if (the_controller) { | ||
2250 | dev_warn(dev, "ignoring\n"); | ||
2251 | return ERR_PTR(-EBUSY); | ||
2252 | } | ||
2253 | |||
2254 | if (!irq) { | 2224 | if (!irq) { |
2255 | dev_dbg(dev, "No IRQ!\n"); | 2225 | dev_dbg(dev, "No IRQ!\n"); |
2256 | return ERR_PTR(-ENODEV); | 2226 | return ERR_PTR(-ENODEV); |
@@ -2307,8 +2277,6 @@ net2272_probe_fin(struct net2272 *dev, unsigned int irqflags) | |||
2307 | dma_mode_string()); | 2277 | dma_mode_string()); |
2308 | dev_info(dev->dev, "version: %s\n", driver_vers); | 2278 | dev_info(dev->dev, "version: %s\n", driver_vers); |
2309 | 2279 | ||
2310 | the_controller = dev; | ||
2311 | |||
2312 | ret = device_register(&dev->gadget.dev); | 2280 | ret = device_register(&dev->gadget.dev); |
2313 | if (ret) | 2281 | if (ret) |
2314 | goto err_irq; | 2282 | goto err_irq; |
@@ -2684,8 +2652,6 @@ net2272_plat_probe(struct platform_device *pdev) | |||
2684 | dev_info(&pdev->dev, "running in 16-bit, %sbyte swap local bus mode\n", | 2652 | dev_info(&pdev->dev, "running in 16-bit, %sbyte swap local bus mode\n", |
2685 | (net2272_read(dev, LOCCTL) & (1 << BYTE_SWAP)) ? "" : "no "); | 2653 | (net2272_read(dev, LOCCTL) & (1 << BYTE_SWAP)) ? "" : "no "); |
2686 | 2654 | ||
2687 | the_controller = dev; | ||
2688 | |||
2689 | return 0; | 2655 | return 0; |
2690 | 2656 | ||
2691 | err_io: | 2657 | err_io: |
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c index a218a4de5dc9..7f1bc9a73cda 100644 --- a/drivers/usb/gadget/net2280.c +++ b/drivers/usb/gadget/net2280.c | |||
@@ -33,15 +33,6 @@ | |||
33 | * it under the terms of the GNU General Public License as published by | 33 | * it under the terms of the GNU General Public License as published by |
34 | * the Free Software Foundation; either version 2 of the License, or | 34 | * the Free Software Foundation; either version 2 of the License, or |
35 | * (at your option) any later version. | 35 | * (at your option) any later version. |
36 | * | ||
37 | * This program is distributed in the hope that it will be useful, | ||
38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
40 | * GNU General Public License for more details. | ||
41 | * | ||
42 | * You should have received a copy of the GNU General Public License | ||
43 | * along with this program; if not, write to the Free Software | ||
44 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
45 | */ | 36 | */ |
46 | 37 | ||
47 | #undef DEBUG /* messages on error and most fault paths */ | 38 | #undef DEBUG /* messages on error and most fault paths */ |
@@ -169,7 +160,7 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
169 | return -EDOM; | 160 | return -EDOM; |
170 | 161 | ||
171 | /* sanity check ep-e/ep-f since their fifos are small */ | 162 | /* sanity check ep-e/ep-f since their fifos are small */ |
172 | max = le16_to_cpu (desc->wMaxPacketSize) & 0x1fff; | 163 | max = usb_endpoint_maxp (desc) & 0x1fff; |
173 | if (ep->num > 4 && max > 64) | 164 | if (ep->num > 4 && max > 64) |
174 | return -ERANGE; | 165 | return -ERANGE; |
175 | 166 | ||
@@ -1410,17 +1401,18 @@ static int net2280_pullup(struct usb_gadget *_gadget, int is_on) | |||
1410 | return 0; | 1401 | return 0; |
1411 | } | 1402 | } |
1412 | 1403 | ||
1413 | static int net2280_start(struct usb_gadget_driver *driver, | 1404 | static int net2280_start(struct usb_gadget *_gadget, |
1414 | int (*bind)(struct usb_gadget *)); | 1405 | struct usb_gadget_driver *driver); |
1415 | static int net2280_stop(struct usb_gadget_driver *driver); | 1406 | static int net2280_stop(struct usb_gadget *_gadget, |
1407 | struct usb_gadget_driver *driver); | ||
1416 | 1408 | ||
1417 | static const struct usb_gadget_ops net2280_ops = { | 1409 | static const struct usb_gadget_ops net2280_ops = { |
1418 | .get_frame = net2280_get_frame, | 1410 | .get_frame = net2280_get_frame, |
1419 | .wakeup = net2280_wakeup, | 1411 | .wakeup = net2280_wakeup, |
1420 | .set_selfpowered = net2280_set_selfpowered, | 1412 | .set_selfpowered = net2280_set_selfpowered, |
1421 | .pullup = net2280_pullup, | 1413 | .pullup = net2280_pullup, |
1422 | .start = net2280_start, | 1414 | .udc_start = net2280_start, |
1423 | .stop = net2280_stop, | 1415 | .udc_stop = net2280_stop, |
1424 | }; | 1416 | }; |
1425 | 1417 | ||
1426 | /*-------------------------------------------------------------------------*/ | 1418 | /*-------------------------------------------------------------------------*/ |
@@ -1640,7 +1632,7 @@ show_queues (struct device *_dev, struct device_attribute *attr, char *buf) | |||
1640 | default: | 1632 | default: |
1641 | val = "iso"; break; | 1633 | val = "iso"; break; |
1642 | }; val; }), | 1634 | }; val; }), |
1643 | le16_to_cpu (d->wMaxPacketSize) & 0x1fff, | 1635 | usb_endpoint_maxp (d) & 0x1fff, |
1644 | ep->dma ? "dma" : "pio", ep->fifo_size | 1636 | ep->dma ? "dma" : "pio", ep->fifo_size |
1645 | ); | 1637 | ); |
1646 | } else /* ep0 should only have one transfer queued */ | 1638 | } else /* ep0 should only have one transfer queued */ |
@@ -1753,8 +1745,6 @@ static void set_fifo_mode (struct net2280 *dev, int mode) | |||
1753 | * perhaps to bind specific drivers to specific devices. | 1745 | * perhaps to bind specific drivers to specific devices. |
1754 | */ | 1746 | */ |
1755 | 1747 | ||
1756 | static struct net2280 *the_controller; | ||
1757 | |||
1758 | static void usb_reset (struct net2280 *dev) | 1748 | static void usb_reset (struct net2280 *dev) |
1759 | { | 1749 | { |
1760 | u32 tmp; | 1750 | u32 tmp; |
@@ -1880,10 +1870,10 @@ static void ep0_start (struct net2280 *dev) | |||
1880 | * disconnect is reported. then a host may connect again, or | 1870 | * disconnect is reported. then a host may connect again, or |
1881 | * the driver might get unbound. | 1871 | * the driver might get unbound. |
1882 | */ | 1872 | */ |
1883 | static int net2280_start(struct usb_gadget_driver *driver, | 1873 | static int net2280_start(struct usb_gadget *_gadget, |
1884 | int (*bind)(struct usb_gadget *)) | 1874 | struct usb_gadget_driver *driver) |
1885 | { | 1875 | { |
1886 | struct net2280 *dev = the_controller; | 1876 | struct net2280 *dev; |
1887 | int retval; | 1877 | int retval; |
1888 | unsigned i; | 1878 | unsigned i; |
1889 | 1879 | ||
@@ -1891,14 +1881,11 @@ static int net2280_start(struct usb_gadget_driver *driver, | |||
1891 | * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE) | 1881 | * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE) |
1892 | * "must not be used in normal operation" | 1882 | * "must not be used in normal operation" |
1893 | */ | 1883 | */ |
1894 | if (!driver | 1884 | if (!driver || driver->speed != USB_SPEED_HIGH |
1895 | || driver->speed != USB_SPEED_HIGH | 1885 | || !driver->setup) |
1896 | || !bind || !driver->setup) | ||
1897 | return -EINVAL; | 1886 | return -EINVAL; |
1898 | if (!dev) | 1887 | |
1899 | return -ENODEV; | 1888 | dev = container_of (_gadget, struct net2280, gadget); |
1900 | if (dev->driver) | ||
1901 | return -EBUSY; | ||
1902 | 1889 | ||
1903 | for (i = 0; i < 7; i++) | 1890 | for (i = 0; i < 7; i++) |
1904 | dev->ep [i].irqs = 0; | 1891 | dev->ep [i].irqs = 0; |
@@ -1908,14 +1895,6 @@ static int net2280_start(struct usb_gadget_driver *driver, | |||
1908 | driver->driver.bus = NULL; | 1895 | driver->driver.bus = NULL; |
1909 | dev->driver = driver; | 1896 | dev->driver = driver; |
1910 | dev->gadget.dev.driver = &driver->driver; | 1897 | dev->gadget.dev.driver = &driver->driver; |
1911 | retval = bind(&dev->gadget); | ||
1912 | if (retval) { | ||
1913 | DEBUG (dev, "bind to driver %s --> %d\n", | ||
1914 | driver->driver.name, retval); | ||
1915 | dev->driver = NULL; | ||
1916 | dev->gadget.dev.driver = NULL; | ||
1917 | return retval; | ||
1918 | } | ||
1919 | 1898 | ||
1920 | retval = device_create_file (&dev->pdev->dev, &dev_attr_function); | 1899 | retval = device_create_file (&dev->pdev->dev, &dev_attr_function); |
1921 | if (retval) goto err_unbind; | 1900 | if (retval) goto err_unbind; |
@@ -1961,33 +1940,21 @@ stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver) | |||
1961 | for (i = 0; i < 7; i++) | 1940 | for (i = 0; i < 7; i++) |
1962 | nuke (&dev->ep [i]); | 1941 | nuke (&dev->ep [i]); |
1963 | 1942 | ||
1964 | /* report disconnect; the driver is already quiesced */ | ||
1965 | if (driver) { | ||
1966 | spin_unlock (&dev->lock); | ||
1967 | driver->disconnect (&dev->gadget); | ||
1968 | spin_lock (&dev->lock); | ||
1969 | } | ||
1970 | |||
1971 | usb_reinit (dev); | 1943 | usb_reinit (dev); |
1972 | } | 1944 | } |
1973 | 1945 | ||
1974 | static int net2280_stop(struct usb_gadget_driver *driver) | 1946 | static int net2280_stop(struct usb_gadget *_gadget, |
1947 | struct usb_gadget_driver *driver) | ||
1975 | { | 1948 | { |
1976 | struct net2280 *dev = the_controller; | 1949 | struct net2280 *dev; |
1977 | unsigned long flags; | 1950 | unsigned long flags; |
1978 | 1951 | ||
1979 | if (!dev) | 1952 | dev = container_of (_gadget, struct net2280, gadget); |
1980 | return -ENODEV; | ||
1981 | if (!driver || driver != dev->driver || !driver->unbind) | ||
1982 | return -EINVAL; | ||
1983 | 1953 | ||
1984 | spin_lock_irqsave (&dev->lock, flags); | 1954 | spin_lock_irqsave (&dev->lock, flags); |
1985 | stop_activity (dev, driver); | 1955 | stop_activity (dev, driver); |
1986 | spin_unlock_irqrestore (&dev->lock, flags); | 1956 | spin_unlock_irqrestore (&dev->lock, flags); |
1987 | 1957 | ||
1988 | net2280_pullup (&dev->gadget, 0); | ||
1989 | |||
1990 | driver->unbind (&dev->gadget); | ||
1991 | dev->gadget.dev.driver = NULL; | 1958 | dev->gadget.dev.driver = NULL; |
1992 | dev->driver = NULL; | 1959 | dev->driver = NULL; |
1993 | 1960 | ||
@@ -2266,9 +2233,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat) | |||
2266 | else | 2233 | else |
2267 | dev->gadget.speed = USB_SPEED_FULL; | 2234 | dev->gadget.speed = USB_SPEED_FULL; |
2268 | net2280_led_speed (dev, dev->gadget.speed); | 2235 | net2280_led_speed (dev, dev->gadget.speed); |
2269 | DEBUG (dev, "%s speed\n", | 2236 | DEBUG(dev, "%s\n", usb_speed_string(dev->gadget.speed)); |
2270 | (dev->gadget.speed == USB_SPEED_HIGH) | ||
2271 | ? "high" : "full"); | ||
2272 | } | 2237 | } |
2273 | 2238 | ||
2274 | ep = &dev->ep [0]; | 2239 | ep = &dev->ep [0]; |
@@ -2709,8 +2674,6 @@ static void net2280_remove (struct pci_dev *pdev) | |||
2709 | pci_set_drvdata (pdev, NULL); | 2674 | pci_set_drvdata (pdev, NULL); |
2710 | 2675 | ||
2711 | INFO (dev, "unbind\n"); | 2676 | INFO (dev, "unbind\n"); |
2712 | |||
2713 | the_controller = NULL; | ||
2714 | } | 2677 | } |
2715 | 2678 | ||
2716 | /* wrap this driver around the specified device, but | 2679 | /* wrap this driver around the specified device, but |
@@ -2724,14 +2687,6 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id) | |||
2724 | void __iomem *base = NULL; | 2687 | void __iomem *base = NULL; |
2725 | int retval, i; | 2688 | int retval, i; |
2726 | 2689 | ||
2727 | /* if you want to support more than one controller in a system, | ||
2728 | * usb_gadget_driver_{register,unregister}() must change. | ||
2729 | */ | ||
2730 | if (the_controller) { | ||
2731 | dev_warn (&pdev->dev, "ignoring\n"); | ||
2732 | return -EBUSY; | ||
2733 | } | ||
2734 | |||
2735 | /* alloc, and start init */ | 2690 | /* alloc, and start init */ |
2736 | dev = kzalloc (sizeof *dev, GFP_KERNEL); | 2691 | dev = kzalloc (sizeof *dev, GFP_KERNEL); |
2737 | if (dev == NULL){ | 2692 | if (dev == NULL){ |
@@ -2858,8 +2813,6 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id) | |||
2858 | use_dma | 2813 | use_dma |
2859 | ? (use_dma_chaining ? "chaining" : "enabled") | 2814 | ? (use_dma_chaining ? "chaining" : "enabled") |
2860 | : "disabled"); | 2815 | : "disabled"); |
2861 | the_controller = dev; | ||
2862 | |||
2863 | retval = device_register (&dev->gadget.dev); | 2816 | retval = device_register (&dev->gadget.dev); |
2864 | if (retval) goto done; | 2817 | if (retval) goto done; |
2865 | retval = device_create_file (&pdev->dev, &dev_attr_registers); | 2818 | retval = device_create_file (&pdev->dev, &dev_attr_registers); |
diff --git a/drivers/usb/gadget/net2280.h b/drivers/usb/gadget/net2280.h index c36852263d93..a844be0d683a 100644 --- a/drivers/usb/gadget/net2280.h +++ b/drivers/usb/gadget/net2280.h | |||
@@ -11,15 +11,6 @@ | |||
11 | * it under the terms of the GNU General Public License as published by | 11 | * it under the terms of the GNU General Public License as published by |
12 | * the Free Software Foundation; either version 2 of the License, or | 12 | * the Free Software Foundation; either version 2 of the License, or |
13 | * (at your option) any later version. | 13 | * (at your option) any later version. |
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | */ | 14 | */ |
24 | 15 | ||
25 | #include <linux/usb/net2280.h> | 16 | #include <linux/usb/net2280.h> |
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c index 740c7daed279..788989a10223 100644 --- a/drivers/usb/gadget/omap_udc.c +++ b/drivers/usb/gadget/omap_udc.c | |||
@@ -10,15 +10,6 @@ | |||
10 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or | 11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. | 12 | * (at your option) any later version. |
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | */ | 13 | */ |
23 | 14 | ||
24 | #undef DEBUG | 15 | #undef DEBUG |
@@ -166,15 +157,14 @@ static int omap_ep_enable(struct usb_ep *_ep, | |||
166 | if (!_ep || !desc || ep->desc | 157 | if (!_ep || !desc || ep->desc |
167 | || desc->bDescriptorType != USB_DT_ENDPOINT | 158 | || desc->bDescriptorType != USB_DT_ENDPOINT |
168 | || ep->bEndpointAddress != desc->bEndpointAddress | 159 | || ep->bEndpointAddress != desc->bEndpointAddress |
169 | || ep->maxpacket < le16_to_cpu | 160 | || ep->maxpacket < usb_endpoint_maxp(desc)) { |
170 | (desc->wMaxPacketSize)) { | ||
171 | DBG("%s, bad ep or descriptor\n", __func__); | 161 | DBG("%s, bad ep or descriptor\n", __func__); |
172 | return -EINVAL; | 162 | return -EINVAL; |
173 | } | 163 | } |
174 | maxp = le16_to_cpu (desc->wMaxPacketSize); | 164 | maxp = usb_endpoint_maxp(desc); |
175 | if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK | 165 | if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK |
176 | && maxp != ep->maxpacket) | 166 | && maxp != ep->maxpacket) |
177 | || le16_to_cpu(desc->wMaxPacketSize) > ep->maxpacket | 167 | || usb_endpoint_maxp(desc) > ep->maxpacket |
178 | || !desc->wMaxPacketSize) { | 168 | || !desc->wMaxPacketSize) { |
179 | DBG("%s, bad %s maxpacket\n", __func__, _ep->name); | 169 | DBG("%s, bad %s maxpacket\n", __func__, _ep->name); |
180 | return -ERANGE; | 170 | return -ERANGE; |
@@ -2968,7 +2958,7 @@ known: | |||
2968 | } | 2958 | } |
2969 | #ifdef USE_ISO | 2959 | #ifdef USE_ISO |
2970 | status = request_irq(pdev->resource[3].start, omap_udc_iso_irq, | 2960 | status = request_irq(pdev->resource[3].start, omap_udc_iso_irq, |
2971 | IRQF_DISABLED, "omap_udc iso", udc); | 2961 | 0, "omap_udc iso", udc); |
2972 | if (status != 0) { | 2962 | if (status != 0) { |
2973 | ERR("can't get irq %d, err %d\n", | 2963 | ERR("can't get irq %d, err %d\n", |
2974 | (int) pdev->resource[3].start, status); | 2964 | (int) pdev->resource[3].start, status); |
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c index f96615ab6b77..550d6dcdf104 100644 --- a/drivers/usb/gadget/pch_udc.c +++ b/drivers/usb/gadget/pch_udc.c | |||
@@ -4,15 +4,6 @@ | |||
4 | * This program is free software; you can redistribute it and/or modify | 4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by | 5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; version 2 of the License. | 6 | * the Free Software Foundation; version 2 of the License. |
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program; if not, write to the Free Software | ||
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | ||
16 | */ | 7 | */ |
17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
18 | #include <linux/kernel.h> | 9 | #include <linux/kernel.h> |
@@ -947,7 +938,7 @@ static void pch_udc_ep_enable(struct pch_udc_ep *ep, | |||
947 | else | 938 | else |
948 | buff_size = UDC_EPOUT_BUFF_SIZE; | 939 | buff_size = UDC_EPOUT_BUFF_SIZE; |
949 | pch_udc_ep_set_bufsz(ep, buff_size, ep->in); | 940 | pch_udc_ep_set_bufsz(ep, buff_size, ep->in); |
950 | pch_udc_ep_set_maxpkt(ep, le16_to_cpu(desc->wMaxPacketSize)); | 941 | pch_udc_ep_set_maxpkt(ep, usb_endpoint_maxp(desc)); |
951 | pch_udc_ep_set_nak(ep); | 942 | pch_udc_ep_set_nak(ep); |
952 | pch_udc_ep_fifo_flush(ep, ep->in); | 943 | pch_udc_ep_fifo_flush(ep, ep->in); |
953 | /* Configure the endpoint */ | 944 | /* Configure the endpoint */ |
@@ -957,7 +948,7 @@ static void pch_udc_ep_enable(struct pch_udc_ep *ep, | |||
957 | (cfg->cur_cfg << UDC_CSR_NE_CFG_SHIFT) | | 948 | (cfg->cur_cfg << UDC_CSR_NE_CFG_SHIFT) | |
958 | (cfg->cur_intf << UDC_CSR_NE_INTF_SHIFT) | | 949 | (cfg->cur_intf << UDC_CSR_NE_INTF_SHIFT) | |
959 | (cfg->cur_alt << UDC_CSR_NE_ALT_SHIFT) | | 950 | (cfg->cur_alt << UDC_CSR_NE_ALT_SHIFT) | |
960 | le16_to_cpu(desc->wMaxPacketSize) << UDC_CSR_NE_MAX_PKT_SHIFT; | 951 | usb_endpoint_maxp(desc) << UDC_CSR_NE_MAX_PKT_SHIFT; |
961 | 952 | ||
962 | if (ep->in) | 953 | if (ep->in) |
963 | pch_udc_write_csr(ep->dev, val, UDC_EPIN_IDX(ep->num)); | 954 | pch_udc_write_csr(ep->dev, val, UDC_EPIN_IDX(ep->num)); |
@@ -1466,7 +1457,7 @@ static int pch_udc_pcd_ep_enable(struct usb_ep *usbep, | |||
1466 | ep->desc = desc; | 1457 | ep->desc = desc; |
1467 | ep->halted = 0; | 1458 | ep->halted = 0; |
1468 | pch_udc_ep_enable(ep, &ep->dev->cfg_data, desc); | 1459 | pch_udc_ep_enable(ep, &ep->dev->cfg_data, desc); |
1469 | ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize); | 1460 | ep->ep.maxpacket = usb_endpoint_maxp(desc); |
1470 | pch_udc_enable_ep_interrupts(ep->dev, PCH_UDC_EPINT(ep->in, ep->num)); | 1461 | pch_udc_enable_ep_interrupts(ep->dev, PCH_UDC_EPINT(ep->in, ep->num)); |
1471 | spin_unlock_irqrestore(&dev->lock, iflags); | 1462 | spin_unlock_irqrestore(&dev->lock, iflags); |
1472 | return 0; | 1463 | return 0; |
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c index a341dde6f9c3..65a8834f274b 100644 --- a/drivers/usb/gadget/printer.c +++ b/drivers/usb/gadget/printer.c | |||
@@ -8,15 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | 11 | */ |
21 | 12 | ||
22 | #include <linux/module.h> | 13 | #include <linux/module.h> |
@@ -971,23 +962,15 @@ printer_set_config(struct printer_dev *dev, unsigned number) | |||
971 | usb_gadget_vbus_draw(dev->gadget, | 962 | usb_gadget_vbus_draw(dev->gadget, |
972 | dev->gadget->is_otg ? 8 : 100); | 963 | dev->gadget->is_otg ? 8 : 100); |
973 | } else { | 964 | } else { |
974 | char *speed; | ||
975 | unsigned power; | 965 | unsigned power; |
976 | 966 | ||
977 | power = 2 * config_desc.bMaxPower; | 967 | power = 2 * config_desc.bMaxPower; |
978 | usb_gadget_vbus_draw(dev->gadget, power); | 968 | usb_gadget_vbus_draw(dev->gadget, power); |
979 | 969 | ||
980 | switch (gadget->speed) { | ||
981 | case USB_SPEED_FULL: speed = "full"; break; | ||
982 | #ifdef CONFIG_USB_GADGET_DUALSPEED | ||
983 | case USB_SPEED_HIGH: speed = "high"; break; | ||
984 | #endif | ||
985 | default: speed = "?"; break; | ||
986 | } | ||
987 | |||
988 | dev->config = number; | 970 | dev->config = number; |
989 | INFO(dev, "%s speed config #%d: %d mA, %s\n", | 971 | INFO(dev, "%s config #%d: %d mA, %s\n", |
990 | speed, number, power, driver_desc); | 972 | usb_speed_string(gadget->speed), |
973 | number, power, driver_desc); | ||
991 | } | 974 | } |
992 | return result; | 975 | return result; |
993 | } | 976 | } |
@@ -1611,7 +1594,7 @@ cleanup(void) | |||
1611 | if (status) | 1594 | if (status) |
1612 | ERROR(dev, "usb_gadget_unregister_driver %x\n", status); | 1595 | ERROR(dev, "usb_gadget_unregister_driver %x\n", status); |
1613 | 1596 | ||
1614 | unregister_chrdev_region(g_printer_devno, 2); | 1597 | unregister_chrdev_region(g_printer_devno, 1); |
1615 | class_destroy(usb_gadget_class); | 1598 | class_destroy(usb_gadget_class); |
1616 | mutex_unlock(&usb_printer_gadget.lock_printer_io); | 1599 | mutex_unlock(&usb_printer_gadget.lock_printer_io); |
1617 | } | 1600 | } |
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c index e4e59b4de25d..c090a7e3ecf8 100644 --- a/drivers/usb/gadget/pxa25x_udc.c +++ b/drivers/usb/gadget/pxa25x_udc.c | |||
@@ -11,16 +11,6 @@ | |||
11 | * it under the terms of the GNU General Public License as published by | 11 | * it under the terms of the GNU General Public License as published by |
12 | * the Free Software Foundation; either version 2 of the License, or | 12 | * the Free Software Foundation; either version 2 of the License, or |
13 | * (at your option) any later version. | 13 | * (at your option) any later version. |
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | * | ||
24 | */ | 14 | */ |
25 | 15 | ||
26 | /* #define VERBOSE_DEBUG */ | 16 | /* #define VERBOSE_DEBUG */ |
@@ -232,8 +222,7 @@ static int pxa25x_ep_enable (struct usb_ep *_ep, | |||
232 | if (!_ep || !desc || ep->desc || _ep->name == ep0name | 222 | if (!_ep || !desc || ep->desc || _ep->name == ep0name |
233 | || desc->bDescriptorType != USB_DT_ENDPOINT | 223 | || desc->bDescriptorType != USB_DT_ENDPOINT |
234 | || ep->bEndpointAddress != desc->bEndpointAddress | 224 | || ep->bEndpointAddress != desc->bEndpointAddress |
235 | || ep->fifo_size < le16_to_cpu | 225 | || ep->fifo_size < usb_endpoint_maxp (desc)) { |
236 | (desc->wMaxPacketSize)) { | ||
237 | DMSG("%s, bad ep or descriptor\n", __func__); | 226 | DMSG("%s, bad ep or descriptor\n", __func__); |
238 | return -EINVAL; | 227 | return -EINVAL; |
239 | } | 228 | } |
@@ -248,7 +237,7 @@ static int pxa25x_ep_enable (struct usb_ep *_ep, | |||
248 | 237 | ||
249 | /* hardware _could_ do smaller, but driver doesn't */ | 238 | /* hardware _could_ do smaller, but driver doesn't */ |
250 | if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK | 239 | if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK |
251 | && le16_to_cpu (desc->wMaxPacketSize) | 240 | && usb_endpoint_maxp (desc) |
252 | != BULK_FIFO_SIZE) | 241 | != BULK_FIFO_SIZE) |
253 | || !desc->wMaxPacketSize) { | 242 | || !desc->wMaxPacketSize) { |
254 | DMSG("%s, bad %s maxpacket\n", __func__, _ep->name); | 243 | DMSG("%s, bad %s maxpacket\n", __func__, _ep->name); |
@@ -264,7 +253,7 @@ static int pxa25x_ep_enable (struct usb_ep *_ep, | |||
264 | ep->desc = desc; | 253 | ep->desc = desc; |
265 | ep->stopped = 0; | 254 | ep->stopped = 0; |
266 | ep->pio_irqs = 0; | 255 | ep->pio_irqs = 0; |
267 | ep->ep.maxpacket = le16_to_cpu (desc->wMaxPacketSize); | 256 | ep->ep.maxpacket = usb_endpoint_maxp (desc); |
268 | 257 | ||
269 | /* flush fifo (mostly for OUT buffers) */ | 258 | /* flush fifo (mostly for OUT buffers) */ |
270 | pxa25x_ep_fifo_flush (_ep); | 259 | pxa25x_ep_fifo_flush (_ep); |
@@ -401,7 +390,7 @@ write_fifo (struct pxa25x_ep *ep, struct pxa25x_request *req) | |||
401 | { | 390 | { |
402 | unsigned max; | 391 | unsigned max; |
403 | 392 | ||
404 | max = le16_to_cpu(ep->desc->wMaxPacketSize); | 393 | max = usb_endpoint_maxp(ep->desc); |
405 | do { | 394 | do { |
406 | unsigned count; | 395 | unsigned count; |
407 | int is_last, is_short; | 396 | int is_last, is_short; |
@@ -671,8 +660,7 @@ pxa25x_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
671 | * we can report per-packet status. that also helps with dma. | 660 | * we can report per-packet status. that also helps with dma. |
672 | */ | 661 | */ |
673 | if (unlikely (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC | 662 | if (unlikely (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC |
674 | && req->req.length > le16_to_cpu | 663 | && req->req.length > usb_endpoint_maxp (ep->desc))) |
675 | (ep->desc->wMaxPacketSize))) | ||
676 | return -EMSGSIZE; | 664 | return -EMSGSIZE; |
677 | 665 | ||
678 | DBG(DBG_NOISY, "%s queue req %p, len %d buf %p\n", | 666 | DBG(DBG_NOISY, "%s queue req %p, len %d buf %p\n", |
@@ -1105,7 +1093,7 @@ udc_seq_show(struct seq_file *m, void *_d) | |||
1105 | tmp = *dev->ep [i].reg_udccs; | 1093 | tmp = *dev->ep [i].reg_udccs; |
1106 | seq_printf(m, | 1094 | seq_printf(m, |
1107 | "%s max %d %s udccs %02x irqs %lu\n", | 1095 | "%s max %d %s udccs %02x irqs %lu\n", |
1108 | ep->ep.name, le16_to_cpu(desc->wMaxPacketSize), | 1096 | ep->ep.name, usb_endpoint_maxp(desc), |
1109 | "pio", tmp, ep->pio_irqs); | 1097 | "pio", tmp, ep->pio_irqs); |
1110 | /* TODO translate all five groups of udccs bits! */ | 1098 | /* TODO translate all five groups of udccs bits! */ |
1111 | 1099 | ||
@@ -2202,7 +2190,7 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev) | |||
2202 | 2190 | ||
2203 | /* irq setup after old hardware state is cleaned up */ | 2191 | /* irq setup after old hardware state is cleaned up */ |
2204 | retval = request_irq(irq, pxa25x_udc_irq, | 2192 | retval = request_irq(irq, pxa25x_udc_irq, |
2205 | IRQF_DISABLED, driver_name, dev); | 2193 | 0, driver_name, dev); |
2206 | if (retval != 0) { | 2194 | if (retval != 0) { |
2207 | pr_err("%s: can't get irq %d, err %d\n", | 2195 | pr_err("%s: can't get irq %d, err %d\n", |
2208 | driver_name, irq, retval); | 2196 | driver_name, irq, retval); |
@@ -2214,7 +2202,7 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev) | |||
2214 | if (machine_is_lubbock()) { | 2202 | if (machine_is_lubbock()) { |
2215 | retval = request_irq(LUBBOCK_USB_DISC_IRQ, | 2203 | retval = request_irq(LUBBOCK_USB_DISC_IRQ, |
2216 | lubbock_vbus_irq, | 2204 | lubbock_vbus_irq, |
2217 | IRQF_DISABLED | IRQF_SAMPLE_RANDOM, | 2205 | IRQF_SAMPLE_RANDOM, |
2218 | driver_name, dev); | 2206 | driver_name, dev); |
2219 | if (retval != 0) { | 2207 | if (retval != 0) { |
2220 | pr_err("%s: can't get irq %i, err %d\n", | 2208 | pr_err("%s: can't get irq %i, err %d\n", |
@@ -2223,7 +2211,7 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev) | |||
2223 | } | 2211 | } |
2224 | retval = request_irq(LUBBOCK_USB_IRQ, | 2212 | retval = request_irq(LUBBOCK_USB_IRQ, |
2225 | lubbock_vbus_irq, | 2213 | lubbock_vbus_irq, |
2226 | IRQF_DISABLED | IRQF_SAMPLE_RANDOM, | 2214 | IRQF_SAMPLE_RANDOM, |
2227 | driver_name, dev); | 2215 | driver_name, dev); |
2228 | if (retval != 0) { | 2216 | if (retval != 0) { |
2229 | pr_err("%s: can't get irq %i, err %d\n", | 2217 | pr_err("%s: can't get irq %i, err %d\n", |
diff --git a/drivers/usb/gadget/pxa25x_udc.h b/drivers/usb/gadget/pxa25x_udc.h index f572c5617462..8eaf4e43726b 100644 --- a/drivers/usb/gadget/pxa25x_udc.h +++ b/drivers/usb/gadget/pxa25x_udc.h | |||
@@ -9,15 +9,6 @@ | |||
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or | 10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. | 11 | * (at your option) any later version. |
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | 12 | */ |
22 | 13 | ||
23 | #ifndef __LINUX_USB_GADGET_PXA25X_H | 14 | #ifndef __LINUX_USB_GADGET_PXA25X_H |
@@ -161,8 +152,6 @@ static struct pxa25x_udc *the_controller; | |||
161 | 152 | ||
162 | #ifdef DEBUG | 153 | #ifdef DEBUG |
163 | 154 | ||
164 | static int is_vbus_present(void); | ||
165 | |||
166 | static const char *state_name[] = { | 155 | static const char *state_name[] = { |
167 | "EP0_IDLE", | 156 | "EP0_IDLE", |
168 | "EP0_IN_DATA_PHASE", "EP0_OUT_DATA_PHASE", | 157 | "EP0_IN_DATA_PHASE", "EP0_OUT_DATA_PHASE", |
@@ -214,8 +203,7 @@ dump_state(struct pxa25x_udc *dev) | |||
214 | u32 tmp; | 203 | u32 tmp; |
215 | unsigned i; | 204 | unsigned i; |
216 | 205 | ||
217 | DMSG("%s %s, uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n", | 206 | DMSG("%s, uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n", |
218 | is_vbus_present() ? "host " : "disconnected", | ||
219 | state_name[dev->ep0state], | 207 | state_name[dev->ep0state], |
220 | UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL); | 208 | UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL); |
221 | dump_udccr("udccr"); | 209 | dump_udccr("udccr"); |
@@ -232,9 +220,6 @@ dump_state(struct pxa25x_udc *dev) | |||
232 | } else | 220 | } else |
233 | DMSG("ep0 driver '%s'\n", dev->driver->driver.name); | 221 | DMSG("ep0 driver '%s'\n", dev->driver->driver.name); |
234 | 222 | ||
235 | if (!is_vbus_present()) | ||
236 | return; | ||
237 | |||
238 | dump_udccs0 ("udccs0"); | 223 | dump_udccs0 ("udccs0"); |
239 | DMSG("ep0 IN %lu/%lu, OUT %lu/%lu\n", | 224 | DMSG("ep0 IN %lu/%lu, OUT %lu/%lu\n", |
240 | dev->stats.write.bytes, dev->stats.write.ops, | 225 | dev->stats.write.bytes, dev->stats.write.ops, |
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c index 85b68c75dc9d..18b6b091f2a6 100644 --- a/drivers/usb/gadget/pxa27x_udc.c +++ b/drivers/usb/gadget/pxa27x_udc.c | |||
@@ -8,16 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | 11 | */ |
22 | #include <linux/module.h> | 12 | #include <linux/module.h> |
23 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
@@ -1439,7 +1429,7 @@ static int pxa_ep_enable(struct usb_ep *_ep, | |||
1439 | return -EINVAL; | 1429 | return -EINVAL; |
1440 | } | 1430 | } |
1441 | 1431 | ||
1442 | if (ep->fifo_size < le16_to_cpu(desc->wMaxPacketSize)) { | 1432 | if (ep->fifo_size < usb_endpoint_maxp(desc)) { |
1443 | ep_err(ep, "bad maxpacket\n"); | 1433 | ep_err(ep, "bad maxpacket\n"); |
1444 | return -ERANGE; | 1434 | return -ERANGE; |
1445 | } | 1435 | } |
diff --git a/drivers/usb/gadget/pxa27x_udc.h b/drivers/usb/gadget/pxa27x_udc.h index b01696eab068..7f4e8f424e80 100644 --- a/drivers/usb/gadget/pxa27x_udc.h +++ b/drivers/usb/gadget/pxa27x_udc.h | |||
@@ -9,15 +9,6 @@ | |||
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or | 10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. | 11 | * (at your option) any later version. |
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | 12 | */ |
22 | 13 | ||
23 | #ifndef __LINUX_USB_GADGET_PXA27X_H | 14 | #ifndef __LINUX_USB_GADGET_PXA27X_H |
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c index 50991e5bd5e8..68a826a1b866 100644 --- a/drivers/usb/gadget/r8a66597-udc.c +++ b/drivers/usb/gadget/r8a66597-udc.c | |||
@@ -8,16 +8,6 @@ | |||
8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; version 2 of the License. | 10 | * the Free Software Foundation; version 2 of the License. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | * | ||
21 | */ | 11 | */ |
22 | 12 | ||
23 | #include <linux/module.h> | 13 | #include <linux/module.h> |
@@ -28,13 +18,14 @@ | |||
28 | #include <linux/clk.h> | 18 | #include <linux/clk.h> |
29 | #include <linux/err.h> | 19 | #include <linux/err.h> |
30 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
21 | #include <linux/dma-mapping.h> | ||
31 | 22 | ||
32 | #include <linux/usb/ch9.h> | 23 | #include <linux/usb/ch9.h> |
33 | #include <linux/usb/gadget.h> | 24 | #include <linux/usb/gadget.h> |
34 | 25 | ||
35 | #include "r8a66597-udc.h" | 26 | #include "r8a66597-udc.h" |
36 | 27 | ||
37 | #define DRIVER_VERSION "2009-08-18" | 28 | #define DRIVER_VERSION "2011-09-26" |
38 | 29 | ||
39 | static const char udc_name[] = "r8a66597_udc"; | 30 | static const char udc_name[] = "r8a66597_udc"; |
40 | static const char *r8a66597_ep_name[] = { | 31 | static const char *r8a66597_ep_name[] = { |
@@ -115,13 +106,15 @@ static inline u16 control_reg_get_pid(struct r8a66597 *r8a66597, u16 pipenum) | |||
115 | u16 pid = 0; | 106 | u16 pid = 0; |
116 | unsigned long offset; | 107 | unsigned long offset; |
117 | 108 | ||
118 | if (pipenum == 0) | 109 | if (pipenum == 0) { |
119 | pid = r8a66597_read(r8a66597, DCPCTR) & PID; | 110 | pid = r8a66597_read(r8a66597, DCPCTR) & PID; |
120 | else if (pipenum < R8A66597_MAX_NUM_PIPE) { | 111 | } else if (pipenum < R8A66597_MAX_NUM_PIPE) { |
121 | offset = get_pipectr_addr(pipenum); | 112 | offset = get_pipectr_addr(pipenum); |
122 | pid = r8a66597_read(r8a66597, offset) & PID; | 113 | pid = r8a66597_read(r8a66597, offset) & PID; |
123 | } else | 114 | } else { |
124 | printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum); | 115 | dev_err(r8a66597_to_dev(r8a66597), "unexpect pipe num (%d)\n", |
116 | pipenum); | ||
117 | } | ||
125 | 118 | ||
126 | return pid; | 119 | return pid; |
127 | } | 120 | } |
@@ -131,13 +124,15 @@ static inline void control_reg_set_pid(struct r8a66597 *r8a66597, u16 pipenum, | |||
131 | { | 124 | { |
132 | unsigned long offset; | 125 | unsigned long offset; |
133 | 126 | ||
134 | if (pipenum == 0) | 127 | if (pipenum == 0) { |
135 | r8a66597_mdfy(r8a66597, pid, PID, DCPCTR); | 128 | r8a66597_mdfy(r8a66597, pid, PID, DCPCTR); |
136 | else if (pipenum < R8A66597_MAX_NUM_PIPE) { | 129 | } else if (pipenum < R8A66597_MAX_NUM_PIPE) { |
137 | offset = get_pipectr_addr(pipenum); | 130 | offset = get_pipectr_addr(pipenum); |
138 | r8a66597_mdfy(r8a66597, pid, PID, offset); | 131 | r8a66597_mdfy(r8a66597, pid, PID, offset); |
139 | } else | 132 | } else { |
140 | printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum); | 133 | dev_err(r8a66597_to_dev(r8a66597), "unexpect pipe num (%d)\n", |
134 | pipenum); | ||
135 | } | ||
141 | } | 136 | } |
142 | 137 | ||
143 | static inline void pipe_start(struct r8a66597 *r8a66597, u16 pipenum) | 138 | static inline void pipe_start(struct r8a66597 *r8a66597, u16 pipenum) |
@@ -160,13 +155,15 @@ static inline u16 control_reg_get(struct r8a66597 *r8a66597, u16 pipenum) | |||
160 | u16 ret = 0; | 155 | u16 ret = 0; |
161 | unsigned long offset; | 156 | unsigned long offset; |
162 | 157 | ||
163 | if (pipenum == 0) | 158 | if (pipenum == 0) { |
164 | ret = r8a66597_read(r8a66597, DCPCTR); | 159 | ret = r8a66597_read(r8a66597, DCPCTR); |
165 | else if (pipenum < R8A66597_MAX_NUM_PIPE) { | 160 | } else if (pipenum < R8A66597_MAX_NUM_PIPE) { |
166 | offset = get_pipectr_addr(pipenum); | 161 | offset = get_pipectr_addr(pipenum); |
167 | ret = r8a66597_read(r8a66597, offset); | 162 | ret = r8a66597_read(r8a66597, offset); |
168 | } else | 163 | } else { |
169 | printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum); | 164 | dev_err(r8a66597_to_dev(r8a66597), "unexpect pipe num (%d)\n", |
165 | pipenum); | ||
166 | } | ||
170 | 167 | ||
171 | return ret; | 168 | return ret; |
172 | } | 169 | } |
@@ -177,13 +174,63 @@ static inline void control_reg_sqclr(struct r8a66597 *r8a66597, u16 pipenum) | |||
177 | 174 | ||
178 | pipe_stop(r8a66597, pipenum); | 175 | pipe_stop(r8a66597, pipenum); |
179 | 176 | ||
180 | if (pipenum == 0) | 177 | if (pipenum == 0) { |
181 | r8a66597_bset(r8a66597, SQCLR, DCPCTR); | 178 | r8a66597_bset(r8a66597, SQCLR, DCPCTR); |
182 | else if (pipenum < R8A66597_MAX_NUM_PIPE) { | 179 | } else if (pipenum < R8A66597_MAX_NUM_PIPE) { |
183 | offset = get_pipectr_addr(pipenum); | 180 | offset = get_pipectr_addr(pipenum); |
184 | r8a66597_bset(r8a66597, SQCLR, offset); | 181 | r8a66597_bset(r8a66597, SQCLR, offset); |
185 | } else | 182 | } else { |
186 | printk(KERN_ERR "unexpect pipe num(%d)\n", pipenum); | 183 | dev_err(r8a66597_to_dev(r8a66597), "unexpect pipe num (%d)\n", |
184 | pipenum); | ||
185 | } | ||
186 | } | ||
187 | |||
188 | static void control_reg_sqset(struct r8a66597 *r8a66597, u16 pipenum) | ||
189 | { | ||
190 | unsigned long offset; | ||
191 | |||
192 | pipe_stop(r8a66597, pipenum); | ||
193 | |||
194 | if (pipenum == 0) { | ||
195 | r8a66597_bset(r8a66597, SQSET, DCPCTR); | ||
196 | } else if (pipenum < R8A66597_MAX_NUM_PIPE) { | ||
197 | offset = get_pipectr_addr(pipenum); | ||
198 | r8a66597_bset(r8a66597, SQSET, offset); | ||
199 | } else { | ||
200 | dev_err(r8a66597_to_dev(r8a66597), | ||
201 | "unexpect pipe num(%d)\n", pipenum); | ||
202 | } | ||
203 | } | ||
204 | |||
205 | static u16 control_reg_sqmon(struct r8a66597 *r8a66597, u16 pipenum) | ||
206 | { | ||
207 | unsigned long offset; | ||
208 | |||
209 | if (pipenum == 0) { | ||
210 | return r8a66597_read(r8a66597, DCPCTR) & SQMON; | ||
211 | } else if (pipenum < R8A66597_MAX_NUM_PIPE) { | ||
212 | offset = get_pipectr_addr(pipenum); | ||
213 | return r8a66597_read(r8a66597, offset) & SQMON; | ||
214 | } else { | ||
215 | dev_err(r8a66597_to_dev(r8a66597), | ||
216 | "unexpect pipe num(%d)\n", pipenum); | ||
217 | } | ||
218 | |||
219 | return 0; | ||
220 | } | ||
221 | |||
222 | static u16 save_usb_toggle(struct r8a66597 *r8a66597, u16 pipenum) | ||
223 | { | ||
224 | return control_reg_sqmon(r8a66597, pipenum); | ||
225 | } | ||
226 | |||
227 | static void restore_usb_toggle(struct r8a66597 *r8a66597, u16 pipenum, | ||
228 | u16 toggle) | ||
229 | { | ||
230 | if (toggle) | ||
231 | control_reg_sqset(r8a66597, pipenum); | ||
232 | else | ||
233 | control_reg_sqclr(r8a66597, pipenum); | ||
187 | } | 234 | } |
188 | 235 | ||
189 | static inline int get_buffer_size(struct r8a66597 *r8a66597, u16 pipenum) | 236 | static inline int get_buffer_size(struct r8a66597 *r8a66597, u16 pipenum) |
@@ -222,18 +269,51 @@ static inline unsigned short mbw_value(struct r8a66597 *r8a66597) | |||
222 | return MBW_16; | 269 | return MBW_16; |
223 | } | 270 | } |
224 | 271 | ||
272 | static void r8a66597_change_curpipe(struct r8a66597 *r8a66597, u16 pipenum, | ||
273 | u16 isel, u16 fifosel) | ||
274 | { | ||
275 | u16 tmp, mask, loop; | ||
276 | int i = 0; | ||
277 | |||
278 | if (!pipenum) { | ||
279 | mask = ISEL | CURPIPE; | ||
280 | loop = isel; | ||
281 | } else { | ||
282 | mask = CURPIPE; | ||
283 | loop = pipenum; | ||
284 | } | ||
285 | r8a66597_mdfy(r8a66597, loop, mask, fifosel); | ||
286 | |||
287 | do { | ||
288 | tmp = r8a66597_read(r8a66597, fifosel); | ||
289 | if (i++ > 1000000) { | ||
290 | dev_err(r8a66597_to_dev(r8a66597), | ||
291 | "r8a66597: register%x, loop %x " | ||
292 | "is timeout\n", fifosel, loop); | ||
293 | break; | ||
294 | } | ||
295 | ndelay(1); | ||
296 | } while ((tmp & mask) != loop); | ||
297 | } | ||
298 | |||
225 | static inline void pipe_change(struct r8a66597 *r8a66597, u16 pipenum) | 299 | static inline void pipe_change(struct r8a66597 *r8a66597, u16 pipenum) |
226 | { | 300 | { |
227 | struct r8a66597_ep *ep = r8a66597->pipenum2ep[pipenum]; | 301 | struct r8a66597_ep *ep = r8a66597->pipenum2ep[pipenum]; |
228 | 302 | ||
229 | if (ep->use_dma) | 303 | if (ep->use_dma) |
230 | return; | 304 | r8a66597_bclr(r8a66597, DREQE, ep->fifosel); |
231 | 305 | ||
232 | r8a66597_mdfy(r8a66597, pipenum, CURPIPE, ep->fifosel); | 306 | r8a66597_mdfy(r8a66597, pipenum, CURPIPE, ep->fifosel); |
233 | 307 | ||
234 | ndelay(450); | 308 | ndelay(450); |
235 | 309 | ||
236 | r8a66597_bset(r8a66597, mbw_value(r8a66597), ep->fifosel); | 310 | if (r8a66597_is_sudmac(r8a66597) && ep->use_dma) |
311 | r8a66597_bclr(r8a66597, mbw_value(r8a66597), ep->fifosel); | ||
312 | else | ||
313 | r8a66597_bset(r8a66597, mbw_value(r8a66597), ep->fifosel); | ||
314 | |||
315 | if (ep->use_dma) | ||
316 | r8a66597_bset(r8a66597, DREQE, ep->fifosel); | ||
237 | } | 317 | } |
238 | 318 | ||
239 | static int pipe_buffer_setting(struct r8a66597 *r8a66597, | 319 | static int pipe_buffer_setting(struct r8a66597 *r8a66597, |
@@ -297,17 +377,18 @@ static void pipe_buffer_release(struct r8a66597 *r8a66597, | |||
297 | if (info->pipe == 0) | 377 | if (info->pipe == 0) |
298 | return; | 378 | return; |
299 | 379 | ||
300 | if (is_bulk_pipe(info->pipe)) | 380 | if (is_bulk_pipe(info->pipe)) { |
301 | r8a66597->bulk--; | 381 | r8a66597->bulk--; |
302 | else if (is_interrupt_pipe(info->pipe)) | 382 | } else if (is_interrupt_pipe(info->pipe)) { |
303 | r8a66597->interrupt--; | 383 | r8a66597->interrupt--; |
304 | else if (is_isoc_pipe(info->pipe)) { | 384 | } else if (is_isoc_pipe(info->pipe)) { |
305 | r8a66597->isochronous--; | 385 | r8a66597->isochronous--; |
306 | if (info->type == R8A66597_BULK) | 386 | if (info->type == R8A66597_BULK) |
307 | r8a66597->bulk--; | 387 | r8a66597->bulk--; |
308 | } else | 388 | } else { |
309 | printk(KERN_ERR "ep_release: unexpect pipenum (%d)\n", | 389 | dev_err(r8a66597_to_dev(r8a66597), |
310 | info->pipe); | 390 | "ep_release: unexpect pipenum (%d)\n", info->pipe); |
391 | } | ||
311 | } | 392 | } |
312 | 393 | ||
313 | static void pipe_initialize(struct r8a66597_ep *ep) | 394 | static void pipe_initialize(struct r8a66597_ep *ep) |
@@ -337,11 +418,17 @@ static void r8a66597_ep_setting(struct r8a66597 *r8a66597, | |||
337 | ep->fifoaddr = CFIFO; | 418 | ep->fifoaddr = CFIFO; |
338 | ep->fifosel = CFIFOSEL; | 419 | ep->fifosel = CFIFOSEL; |
339 | ep->fifoctr = CFIFOCTR; | 420 | ep->fifoctr = CFIFOCTR; |
340 | ep->fifotrn = 0; | ||
341 | 421 | ||
342 | ep->pipectr = get_pipectr_addr(pipenum); | 422 | ep->pipectr = get_pipectr_addr(pipenum); |
423 | if (is_bulk_pipe(pipenum) || is_isoc_pipe(pipenum)) { | ||
424 | ep->pipetre = get_pipetre_addr(pipenum); | ||
425 | ep->pipetrn = get_pipetrn_addr(pipenum); | ||
426 | } else { | ||
427 | ep->pipetre = 0; | ||
428 | ep->pipetrn = 0; | ||
429 | } | ||
343 | ep->pipenum = pipenum; | 430 | ep->pipenum = pipenum; |
344 | ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize); | 431 | ep->ep.maxpacket = usb_endpoint_maxp(desc); |
345 | r8a66597->pipenum2ep[pipenum] = ep; | 432 | r8a66597->pipenum2ep[pipenum] = ep; |
346 | r8a66597->epaddr2ep[desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK] | 433 | r8a66597->epaddr2ep[desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK] |
347 | = ep; | 434 | = ep; |
@@ -381,7 +468,8 @@ static int alloc_pipe_config(struct r8a66597_ep *ep, | |||
381 | case USB_ENDPOINT_XFER_BULK: | 468 | case USB_ENDPOINT_XFER_BULK: |
382 | if (r8a66597->bulk >= R8A66597_MAX_NUM_BULK) { | 469 | if (r8a66597->bulk >= R8A66597_MAX_NUM_BULK) { |
383 | if (r8a66597->isochronous >= R8A66597_MAX_NUM_ISOC) { | 470 | if (r8a66597->isochronous >= R8A66597_MAX_NUM_ISOC) { |
384 | printk(KERN_ERR "bulk pipe is insufficient\n"); | 471 | dev_err(r8a66597_to_dev(r8a66597), |
472 | "bulk pipe is insufficient\n"); | ||
385 | return -ENODEV; | 473 | return -ENODEV; |
386 | } else { | 474 | } else { |
387 | info.pipe = R8A66597_BASE_PIPENUM_ISOC | 475 | info.pipe = R8A66597_BASE_PIPENUM_ISOC |
@@ -397,7 +485,8 @@ static int alloc_pipe_config(struct r8a66597_ep *ep, | |||
397 | break; | 485 | break; |
398 | case USB_ENDPOINT_XFER_INT: | 486 | case USB_ENDPOINT_XFER_INT: |
399 | if (r8a66597->interrupt >= R8A66597_MAX_NUM_INT) { | 487 | if (r8a66597->interrupt >= R8A66597_MAX_NUM_INT) { |
400 | printk(KERN_ERR "interrupt pipe is insufficient\n"); | 488 | dev_err(r8a66597_to_dev(r8a66597), |
489 | "interrupt pipe is insufficient\n"); | ||
401 | return -ENODEV; | 490 | return -ENODEV; |
402 | } | 491 | } |
403 | info.pipe = R8A66597_BASE_PIPENUM_INT + r8a66597->interrupt; | 492 | info.pipe = R8A66597_BASE_PIPENUM_INT + r8a66597->interrupt; |
@@ -406,7 +495,8 @@ static int alloc_pipe_config(struct r8a66597_ep *ep, | |||
406 | break; | 495 | break; |
407 | case USB_ENDPOINT_XFER_ISOC: | 496 | case USB_ENDPOINT_XFER_ISOC: |
408 | if (r8a66597->isochronous >= R8A66597_MAX_NUM_ISOC) { | 497 | if (r8a66597->isochronous >= R8A66597_MAX_NUM_ISOC) { |
409 | printk(KERN_ERR "isochronous pipe is insufficient\n"); | 498 | dev_err(r8a66597_to_dev(r8a66597), |
499 | "isochronous pipe is insufficient\n"); | ||
410 | return -ENODEV; | 500 | return -ENODEV; |
411 | } | 501 | } |
412 | info.pipe = R8A66597_BASE_PIPENUM_ISOC + r8a66597->isochronous; | 502 | info.pipe = R8A66597_BASE_PIPENUM_ISOC + r8a66597->isochronous; |
@@ -414,13 +504,13 @@ static int alloc_pipe_config(struct r8a66597_ep *ep, | |||
414 | counter = &r8a66597->isochronous; | 504 | counter = &r8a66597->isochronous; |
415 | break; | 505 | break; |
416 | default: | 506 | default: |
417 | printk(KERN_ERR "unexpect xfer type\n"); | 507 | dev_err(r8a66597_to_dev(r8a66597), "unexpect xfer type\n"); |
418 | return -EINVAL; | 508 | return -EINVAL; |
419 | } | 509 | } |
420 | ep->type = info.type; | 510 | ep->type = info.type; |
421 | 511 | ||
422 | info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; | 512 | info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; |
423 | info.maxpacket = le16_to_cpu(desc->wMaxPacketSize); | 513 | info.maxpacket = usb_endpoint_maxp(desc); |
424 | info.interval = desc->bInterval; | 514 | info.interval = desc->bInterval; |
425 | if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) | 515 | if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) |
426 | info.dir_in = 1; | 516 | info.dir_in = 1; |
@@ -429,7 +519,8 @@ static int alloc_pipe_config(struct r8a66597_ep *ep, | |||
429 | 519 | ||
430 | ret = pipe_buffer_setting(r8a66597, &info); | 520 | ret = pipe_buffer_setting(r8a66597, &info); |
431 | if (ret < 0) { | 521 | if (ret < 0) { |
432 | printk(KERN_ERR "pipe_buffer_setting fail\n"); | 522 | dev_err(r8a66597_to_dev(r8a66597), |
523 | "pipe_buffer_setting fail\n"); | ||
433 | return ret; | 524 | return ret; |
434 | } | 525 | } |
435 | 526 | ||
@@ -495,6 +586,124 @@ static void start_ep0_write(struct r8a66597_ep *ep, | |||
495 | } | 586 | } |
496 | } | 587 | } |
497 | 588 | ||
589 | static void disable_fifosel(struct r8a66597 *r8a66597, u16 pipenum, | ||
590 | u16 fifosel) | ||
591 | { | ||
592 | u16 tmp; | ||
593 | |||
594 | tmp = r8a66597_read(r8a66597, fifosel) & CURPIPE; | ||
595 | if (tmp == pipenum) | ||
596 | r8a66597_change_curpipe(r8a66597, 0, 0, fifosel); | ||
597 | } | ||
598 | |||
599 | static void change_bfre_mode(struct r8a66597 *r8a66597, u16 pipenum, | ||
600 | int enable) | ||
601 | { | ||
602 | struct r8a66597_ep *ep = r8a66597->pipenum2ep[pipenum]; | ||
603 | u16 tmp, toggle; | ||
604 | |||
605 | /* check current BFRE bit */ | ||
606 | r8a66597_write(r8a66597, pipenum, PIPESEL); | ||
607 | tmp = r8a66597_read(r8a66597, PIPECFG) & R8A66597_BFRE; | ||
608 | if ((enable && tmp) || (!enable && !tmp)) | ||
609 | return; | ||
610 | |||
611 | /* change BFRE bit */ | ||
612 | pipe_stop(r8a66597, pipenum); | ||
613 | disable_fifosel(r8a66597, pipenum, CFIFOSEL); | ||
614 | disable_fifosel(r8a66597, pipenum, D0FIFOSEL); | ||
615 | disable_fifosel(r8a66597, pipenum, D1FIFOSEL); | ||
616 | |||
617 | toggle = save_usb_toggle(r8a66597, pipenum); | ||
618 | |||
619 | r8a66597_write(r8a66597, pipenum, PIPESEL); | ||
620 | if (enable) | ||
621 | r8a66597_bset(r8a66597, R8A66597_BFRE, PIPECFG); | ||
622 | else | ||
623 | r8a66597_bclr(r8a66597, R8A66597_BFRE, PIPECFG); | ||
624 | |||
625 | /* initialize for internal BFRE flag */ | ||
626 | r8a66597_bset(r8a66597, ACLRM, ep->pipectr); | ||
627 | r8a66597_bclr(r8a66597, ACLRM, ep->pipectr); | ||
628 | |||
629 | restore_usb_toggle(r8a66597, pipenum, toggle); | ||
630 | } | ||
631 | |||
632 | static int sudmac_alloc_channel(struct r8a66597 *r8a66597, | ||
633 | struct r8a66597_ep *ep, | ||
634 | struct r8a66597_request *req) | ||
635 | { | ||
636 | struct r8a66597_dma *dma; | ||
637 | |||
638 | if (!r8a66597_is_sudmac(r8a66597)) | ||
639 | return -ENODEV; | ||
640 | |||
641 | /* Check transfer type */ | ||
642 | if (!is_bulk_pipe(ep->pipenum)) | ||
643 | return -EIO; | ||
644 | |||
645 | if (r8a66597->dma.used) | ||
646 | return -EBUSY; | ||
647 | |||
648 | /* set SUDMAC parameters */ | ||
649 | dma = &r8a66597->dma; | ||
650 | dma->used = 1; | ||
651 | if (ep->desc->bEndpointAddress & USB_DIR_IN) { | ||
652 | dma->dir = 1; | ||
653 | } else { | ||
654 | dma->dir = 0; | ||
655 | change_bfre_mode(r8a66597, ep->pipenum, 1); | ||
656 | } | ||
657 | |||
658 | /* set r8a66597_ep paramters */ | ||
659 | ep->use_dma = 1; | ||
660 | ep->dma = dma; | ||
661 | ep->fifoaddr = D0FIFO; | ||
662 | ep->fifosel = D0FIFOSEL; | ||
663 | ep->fifoctr = D0FIFOCTR; | ||
664 | |||
665 | /* dma mapping */ | ||
666 | req->req.dma = dma_map_single(r8a66597_to_dev(ep->r8a66597), | ||
667 | req->req.buf, req->req.length, | ||
668 | dma->dir ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
669 | |||
670 | return 0; | ||
671 | } | ||
672 | |||
673 | static void sudmac_free_channel(struct r8a66597 *r8a66597, | ||
674 | struct r8a66597_ep *ep, | ||
675 | struct r8a66597_request *req) | ||
676 | { | ||
677 | if (!r8a66597_is_sudmac(r8a66597)) | ||
678 | return; | ||
679 | |||
680 | dma_unmap_single(r8a66597_to_dev(ep->r8a66597), | ||
681 | req->req.dma, req->req.length, | ||
682 | ep->dma->dir ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
683 | |||
684 | r8a66597_bclr(r8a66597, DREQE, ep->fifosel); | ||
685 | r8a66597_change_curpipe(r8a66597, 0, 0, ep->fifosel); | ||
686 | |||
687 | ep->dma->used = 0; | ||
688 | ep->use_dma = 0; | ||
689 | ep->fifoaddr = CFIFO; | ||
690 | ep->fifosel = CFIFOSEL; | ||
691 | ep->fifoctr = CFIFOCTR; | ||
692 | } | ||
693 | |||
694 | static void sudmac_start(struct r8a66597 *r8a66597, struct r8a66597_ep *ep, | ||
695 | struct r8a66597_request *req) | ||
696 | { | ||
697 | BUG_ON(req->req.length == 0); | ||
698 | |||
699 | r8a66597_sudmac_write(r8a66597, LBA_WAIT, CH0CFG); | ||
700 | r8a66597_sudmac_write(r8a66597, req->req.dma, CH0BA); | ||
701 | r8a66597_sudmac_write(r8a66597, req->req.length, CH0BBC); | ||
702 | r8a66597_sudmac_write(r8a66597, CH0ENDE, DINTCTRL); | ||
703 | |||
704 | r8a66597_sudmac_write(r8a66597, DEN, CH0DEN); | ||
705 | } | ||
706 | |||
498 | static void start_packet_write(struct r8a66597_ep *ep, | 707 | static void start_packet_write(struct r8a66597_ep *ep, |
499 | struct r8a66597_request *req) | 708 | struct r8a66597_request *req) |
500 | { | 709 | { |
@@ -505,11 +714,29 @@ static void start_packet_write(struct r8a66597_ep *ep, | |||
505 | disable_irq_empty(r8a66597, ep->pipenum); | 714 | disable_irq_empty(r8a66597, ep->pipenum); |
506 | pipe_start(r8a66597, ep->pipenum); | 715 | pipe_start(r8a66597, ep->pipenum); |
507 | 716 | ||
508 | tmp = r8a66597_read(r8a66597, ep->fifoctr); | 717 | if (req->req.length == 0) { |
509 | if (unlikely((tmp & FRDY) == 0)) | 718 | transfer_complete(ep, req, 0); |
510 | pipe_irq_enable(r8a66597, ep->pipenum); | 719 | } else { |
511 | else | 720 | r8a66597_write(r8a66597, ~(1 << ep->pipenum), BRDYSTS); |
512 | irq_packet_write(ep, req); | 721 | if (sudmac_alloc_channel(r8a66597, ep, req) < 0) { |
722 | /* PIO mode */ | ||
723 | pipe_change(r8a66597, ep->pipenum); | ||
724 | disable_irq_empty(r8a66597, ep->pipenum); | ||
725 | pipe_start(r8a66597, ep->pipenum); | ||
726 | tmp = r8a66597_read(r8a66597, ep->fifoctr); | ||
727 | if (unlikely((tmp & FRDY) == 0)) | ||
728 | pipe_irq_enable(r8a66597, ep->pipenum); | ||
729 | else | ||
730 | irq_packet_write(ep, req); | ||
731 | } else { | ||
732 | /* DMA mode */ | ||
733 | pipe_change(r8a66597, ep->pipenum); | ||
734 | disable_irq_nrdy(r8a66597, ep->pipenum); | ||
735 | pipe_start(r8a66597, ep->pipenum); | ||
736 | enable_irq_nrdy(r8a66597, ep->pipenum); | ||
737 | sudmac_start(r8a66597, ep, req); | ||
738 | } | ||
739 | } | ||
513 | } | 740 | } |
514 | 741 | ||
515 | static void start_packet_read(struct r8a66597_ep *ep, | 742 | static void start_packet_read(struct r8a66597_ep *ep, |
@@ -524,17 +751,26 @@ static void start_packet_read(struct r8a66597_ep *ep, | |||
524 | pipe_start(r8a66597, pipenum); | 751 | pipe_start(r8a66597, pipenum); |
525 | pipe_irq_enable(r8a66597, pipenum); | 752 | pipe_irq_enable(r8a66597, pipenum); |
526 | } else { | 753 | } else { |
527 | if (ep->use_dma) { | 754 | pipe_stop(r8a66597, pipenum); |
528 | r8a66597_bset(r8a66597, TRCLR, ep->fifosel); | 755 | if (ep->pipetre) { |
529 | pipe_change(r8a66597, pipenum); | 756 | enable_irq_nrdy(r8a66597, pipenum); |
530 | r8a66597_bset(r8a66597, TRENB, ep->fifosel); | 757 | r8a66597_write(r8a66597, TRCLR, ep->pipetre); |
531 | r8a66597_write(r8a66597, | 758 | r8a66597_write(r8a66597, |
532 | (req->req.length + ep->ep.maxpacket - 1) | 759 | DIV_ROUND_UP(req->req.length, ep->ep.maxpacket), |
533 | / ep->ep.maxpacket, | 760 | ep->pipetrn); |
534 | ep->fifotrn); | 761 | r8a66597_bset(r8a66597, TRENB, ep->pipetre); |
762 | } | ||
763 | |||
764 | if (sudmac_alloc_channel(r8a66597, ep, req) < 0) { | ||
765 | /* PIO mode */ | ||
766 | change_bfre_mode(r8a66597, ep->pipenum, 0); | ||
767 | pipe_start(r8a66597, pipenum); /* trigger once */ | ||
768 | pipe_irq_enable(r8a66597, pipenum); | ||
769 | } else { | ||
770 | pipe_change(r8a66597, pipenum); | ||
771 | sudmac_start(r8a66597, ep, req); | ||
772 | pipe_start(r8a66597, pipenum); /* trigger once */ | ||
535 | } | 773 | } |
536 | pipe_start(r8a66597, pipenum); /* trigger once */ | ||
537 | pipe_irq_enable(r8a66597, pipenum); | ||
538 | } | 774 | } |
539 | } | 775 | } |
540 | 776 | ||
@@ -564,7 +800,8 @@ static void start_ep0(struct r8a66597_ep *ep, struct r8a66597_request *req) | |||
564 | control_end(ep->r8a66597, 0); | 800 | control_end(ep->r8a66597, 0); |
565 | break; | 801 | break; |
566 | default: | 802 | default: |
567 | printk(KERN_ERR "start_ep0: unexpect ctsq(%x)\n", ctsq); | 803 | dev_err(r8a66597_to_dev(ep->r8a66597), |
804 | "start_ep0: unexpect ctsq(%x)\n", ctsq); | ||
568 | break; | 805 | break; |
569 | } | 806 | } |
570 | } | 807 | } |
@@ -690,6 +927,9 @@ __acquires(r8a66597->lock) | |||
690 | if (!list_empty(&ep->queue)) | 927 | if (!list_empty(&ep->queue)) |
691 | restart = 1; | 928 | restart = 1; |
692 | 929 | ||
930 | if (ep->use_dma) | ||
931 | sudmac_free_channel(ep->r8a66597, ep, req); | ||
932 | |||
693 | spin_unlock(&ep->r8a66597->lock); | 933 | spin_unlock(&ep->r8a66597->lock); |
694 | req->req.complete(&ep->ep, &req->req); | 934 | req->req.complete(&ep->ep, &req->req); |
695 | spin_lock(&ep->r8a66597->lock); | 935 | spin_lock(&ep->r8a66597->lock); |
@@ -718,7 +958,8 @@ static void irq_ep0_write(struct r8a66597_ep *ep, struct r8a66597_request *req) | |||
718 | do { | 958 | do { |
719 | tmp = r8a66597_read(r8a66597, ep->fifoctr); | 959 | tmp = r8a66597_read(r8a66597, ep->fifoctr); |
720 | if (i++ > 100000) { | 960 | if (i++ > 100000) { |
721 | printk(KERN_ERR "pipe0 is busy. maybe cpu i/o bus" | 961 | dev_err(r8a66597_to_dev(r8a66597), |
962 | "pipe0 is busy. maybe cpu i/o bus " | ||
722 | "conflict. please power off this controller."); | 963 | "conflict. please power off this controller."); |
723 | return; | 964 | return; |
724 | } | 965 | } |
@@ -733,7 +974,7 @@ static void irq_ep0_write(struct r8a66597_ep *ep, struct r8a66597_request *req) | |||
733 | /* write fifo */ | 974 | /* write fifo */ |
734 | if (req->req.buf) { | 975 | if (req->req.buf) { |
735 | if (size > 0) | 976 | if (size > 0) |
736 | r8a66597_write_fifo(r8a66597, ep->fifoaddr, buf, size); | 977 | r8a66597_write_fifo(r8a66597, ep, buf, size); |
737 | if ((size == 0) || ((size % ep->ep.maxpacket) != 0)) | 978 | if ((size == 0) || ((size % ep->ep.maxpacket) != 0)) |
738 | r8a66597_bset(r8a66597, BVAL, ep->fifoctr); | 979 | r8a66597_bset(r8a66597, BVAL, ep->fifoctr); |
739 | } | 980 | } |
@@ -769,7 +1010,8 @@ static void irq_packet_write(struct r8a66597_ep *ep, | |||
769 | if (unlikely((tmp & FRDY) == 0)) { | 1010 | if (unlikely((tmp & FRDY) == 0)) { |
770 | pipe_stop(r8a66597, pipenum); | 1011 | pipe_stop(r8a66597, pipenum); |
771 | pipe_irq_disable(r8a66597, pipenum); | 1012 | pipe_irq_disable(r8a66597, pipenum); |
772 | printk(KERN_ERR "write fifo not ready. pipnum=%d\n", pipenum); | 1013 | dev_err(r8a66597_to_dev(r8a66597), |
1014 | "write fifo not ready. pipnum=%d\n", pipenum); | ||
773 | return; | 1015 | return; |
774 | } | 1016 | } |
775 | 1017 | ||
@@ -780,7 +1022,7 @@ static void irq_packet_write(struct r8a66597_ep *ep, | |||
780 | 1022 | ||
781 | /* write fifo */ | 1023 | /* write fifo */ |
782 | if (req->req.buf) { | 1024 | if (req->req.buf) { |
783 | r8a66597_write_fifo(r8a66597, ep->fifoaddr, buf, size); | 1025 | r8a66597_write_fifo(r8a66597, ep, buf, size); |
784 | if ((size == 0) | 1026 | if ((size == 0) |
785 | || ((size % ep->ep.maxpacket) != 0) | 1027 | || ((size % ep->ep.maxpacket) != 0) |
786 | || ((bufsize != ep->ep.maxpacket) | 1028 | || ((bufsize != ep->ep.maxpacket) |
@@ -819,7 +1061,7 @@ static void irq_packet_read(struct r8a66597_ep *ep, | |||
819 | req->req.status = -EPIPE; | 1061 | req->req.status = -EPIPE; |
820 | pipe_stop(r8a66597, pipenum); | 1062 | pipe_stop(r8a66597, pipenum); |
821 | pipe_irq_disable(r8a66597, pipenum); | 1063 | pipe_irq_disable(r8a66597, pipenum); |
822 | printk(KERN_ERR "read fifo not ready"); | 1064 | dev_err(r8a66597_to_dev(r8a66597), "read fifo not ready"); |
823 | return; | 1065 | return; |
824 | } | 1066 | } |
825 | 1067 | ||
@@ -1095,7 +1337,7 @@ static void r8a66597_update_usb_speed(struct r8a66597 *r8a66597) | |||
1095 | break; | 1337 | break; |
1096 | default: | 1338 | default: |
1097 | r8a66597->gadget.speed = USB_SPEED_UNKNOWN; | 1339 | r8a66597->gadget.speed = USB_SPEED_UNKNOWN; |
1098 | printk(KERN_ERR "USB speed unknown\n"); | 1340 | dev_err(r8a66597_to_dev(r8a66597), "USB speed unknown\n"); |
1099 | } | 1341 | } |
1100 | } | 1342 | } |
1101 | 1343 | ||
@@ -1158,11 +1400,71 @@ __acquires(r8a66597->lock) | |||
1158 | control_end(r8a66597, 0); | 1400 | control_end(r8a66597, 0); |
1159 | break; | 1401 | break; |
1160 | default: | 1402 | default: |
1161 | printk(KERN_ERR "ctrl_stage: unexpect ctsq(%x)\n", ctsq); | 1403 | dev_err(r8a66597_to_dev(r8a66597), |
1404 | "ctrl_stage: unexpect ctsq(%x)\n", ctsq); | ||
1162 | break; | 1405 | break; |
1163 | } | 1406 | } |
1164 | } | 1407 | } |
1165 | 1408 | ||
1409 | static void sudmac_finish(struct r8a66597 *r8a66597, struct r8a66597_ep *ep) | ||
1410 | { | ||
1411 | u16 pipenum; | ||
1412 | struct r8a66597_request *req; | ||
1413 | u32 len; | ||
1414 | int i = 0; | ||
1415 | |||
1416 | pipenum = ep->pipenum; | ||
1417 | pipe_change(r8a66597, pipenum); | ||
1418 | |||
1419 | while (!(r8a66597_read(r8a66597, ep->fifoctr) & FRDY)) { | ||
1420 | udelay(1); | ||
1421 | if (unlikely(i++ >= 10000)) { /* timeout = 10 msec */ | ||
1422 | dev_err(r8a66597_to_dev(r8a66597), | ||
1423 | "%s: FRDY was not set (%d)\n", | ||
1424 | __func__, pipenum); | ||
1425 | return; | ||
1426 | } | ||
1427 | } | ||
1428 | |||
1429 | r8a66597_bset(r8a66597, BCLR, ep->fifoctr); | ||
1430 | req = get_request_from_ep(ep); | ||
1431 | |||
1432 | /* prepare parameters */ | ||
1433 | len = r8a66597_sudmac_read(r8a66597, CH0CBC); | ||
1434 | req->req.actual += len; | ||
1435 | |||
1436 | /* clear */ | ||
1437 | r8a66597_sudmac_write(r8a66597, CH0STCLR, DSTSCLR); | ||
1438 | |||
1439 | /* check transfer finish */ | ||
1440 | if ((!req->req.zero && (req->req.actual == req->req.length)) | ||
1441 | || (len % ep->ep.maxpacket)) { | ||
1442 | if (ep->dma->dir) { | ||
1443 | disable_irq_ready(r8a66597, pipenum); | ||
1444 | enable_irq_empty(r8a66597, pipenum); | ||
1445 | } else { | ||
1446 | /* Clear the interrupt flag for next transfer */ | ||
1447 | r8a66597_write(r8a66597, ~(1 << pipenum), BRDYSTS); | ||
1448 | transfer_complete(ep, req, 0); | ||
1449 | } | ||
1450 | } | ||
1451 | } | ||
1452 | |||
1453 | static void r8a66597_sudmac_irq(struct r8a66597 *r8a66597) | ||
1454 | { | ||
1455 | u32 irqsts; | ||
1456 | struct r8a66597_ep *ep; | ||
1457 | u16 pipenum; | ||
1458 | |||
1459 | irqsts = r8a66597_sudmac_read(r8a66597, DINTSTS); | ||
1460 | if (irqsts & CH0ENDS) { | ||
1461 | r8a66597_sudmac_write(r8a66597, CH0ENDC, DINTSTSCLR); | ||
1462 | pipenum = (r8a66597_read(r8a66597, D0FIFOSEL) & CURPIPE); | ||
1463 | ep = r8a66597->pipenum2ep[pipenum]; | ||
1464 | sudmac_finish(r8a66597, ep); | ||
1465 | } | ||
1466 | } | ||
1467 | |||
1166 | static irqreturn_t r8a66597_irq(int irq, void *_r8a66597) | 1468 | static irqreturn_t r8a66597_irq(int irq, void *_r8a66597) |
1167 | { | 1469 | { |
1168 | struct r8a66597 *r8a66597 = _r8a66597; | 1470 | struct r8a66597 *r8a66597 = _r8a66597; |
@@ -1173,6 +1475,9 @@ static irqreturn_t r8a66597_irq(int irq, void *_r8a66597) | |||
1173 | u16 savepipe; | 1475 | u16 savepipe; |
1174 | u16 mask0; | 1476 | u16 mask0; |
1175 | 1477 | ||
1478 | if (r8a66597_is_sudmac(r8a66597)) | ||
1479 | r8a66597_sudmac_irq(r8a66597); | ||
1480 | |||
1176 | spin_lock(&r8a66597->lock); | 1481 | spin_lock(&r8a66597->lock); |
1177 | 1482 | ||
1178 | intsts0 = r8a66597_read(r8a66597, INTSTS0); | 1483 | intsts0 = r8a66597_read(r8a66597, INTSTS0); |
@@ -1433,23 +1738,18 @@ static struct usb_ep_ops r8a66597_ep_ops = { | |||
1433 | }; | 1738 | }; |
1434 | 1739 | ||
1435 | /*-------------------------------------------------------------------------*/ | 1740 | /*-------------------------------------------------------------------------*/ |
1436 | static struct r8a66597 *the_controller; | 1741 | static int r8a66597_start(struct usb_gadget *gadget, |
1437 | 1742 | struct usb_gadget_driver *driver) | |
1438 | static int r8a66597_start(struct usb_gadget_driver *driver, | ||
1439 | int (*bind)(struct usb_gadget *)) | ||
1440 | { | 1743 | { |
1441 | struct r8a66597 *r8a66597 = the_controller; | 1744 | struct r8a66597 *r8a66597 = gadget_to_r8a66597(gadget); |
1442 | int retval; | 1745 | int retval; |
1443 | 1746 | ||
1444 | if (!driver | 1747 | if (!driver |
1445 | || driver->speed != USB_SPEED_HIGH | 1748 | || driver->speed != USB_SPEED_HIGH |
1446 | || !bind | ||
1447 | || !driver->setup) | 1749 | || !driver->setup) |
1448 | return -EINVAL; | 1750 | return -EINVAL; |
1449 | if (!r8a66597) | 1751 | if (!r8a66597) |
1450 | return -ENODEV; | 1752 | return -ENODEV; |
1451 | if (r8a66597->driver) | ||
1452 | return -EBUSY; | ||
1453 | 1753 | ||
1454 | /* hook up the driver */ | 1754 | /* hook up the driver */ |
1455 | driver->driver.bus = NULL; | 1755 | driver->driver.bus = NULL; |
@@ -1458,14 +1758,8 @@ static int r8a66597_start(struct usb_gadget_driver *driver, | |||
1458 | 1758 | ||
1459 | retval = device_add(&r8a66597->gadget.dev); | 1759 | retval = device_add(&r8a66597->gadget.dev); |
1460 | if (retval) { | 1760 | if (retval) { |
1461 | printk(KERN_ERR "device_add error (%d)\n", retval); | 1761 | dev_err(r8a66597_to_dev(r8a66597), "device_add error (%d)\n", |
1462 | goto error; | 1762 | retval); |
1463 | } | ||
1464 | |||
1465 | retval = bind(&r8a66597->gadget); | ||
1466 | if (retval) { | ||
1467 | printk(KERN_ERR "bind to driver error (%d)\n", retval); | ||
1468 | device_del(&r8a66597->gadget.dev); | ||
1469 | goto error; | 1763 | goto error; |
1470 | } | 1764 | } |
1471 | 1765 | ||
@@ -1489,23 +1783,17 @@ error: | |||
1489 | return retval; | 1783 | return retval; |
1490 | } | 1784 | } |
1491 | 1785 | ||
1492 | static int r8a66597_stop(struct usb_gadget_driver *driver) | 1786 | static int r8a66597_stop(struct usb_gadget *gadget, |
1787 | struct usb_gadget_driver *driver) | ||
1493 | { | 1788 | { |
1494 | struct r8a66597 *r8a66597 = the_controller; | 1789 | struct r8a66597 *r8a66597 = gadget_to_r8a66597(gadget); |
1495 | unsigned long flags; | 1790 | unsigned long flags; |
1496 | 1791 | ||
1497 | if (driver != r8a66597->driver || !driver->unbind) | ||
1498 | return -EINVAL; | ||
1499 | |||
1500 | spin_lock_irqsave(&r8a66597->lock, flags); | 1792 | spin_lock_irqsave(&r8a66597->lock, flags); |
1501 | if (r8a66597->gadget.speed != USB_SPEED_UNKNOWN) | ||
1502 | r8a66597_usb_disconnect(r8a66597); | ||
1503 | r8a66597_bclr(r8a66597, VBSE, INTENB0); | 1793 | r8a66597_bclr(r8a66597, VBSE, INTENB0); |
1504 | disable_controller(r8a66597); | 1794 | disable_controller(r8a66597); |
1505 | spin_unlock_irqrestore(&r8a66597->lock, flags); | 1795 | spin_unlock_irqrestore(&r8a66597->lock, flags); |
1506 | 1796 | ||
1507 | driver->unbind(&r8a66597->gadget); | ||
1508 | |||
1509 | device_del(&r8a66597->gadget.dev); | 1797 | device_del(&r8a66597->gadget.dev); |
1510 | r8a66597->driver = NULL; | 1798 | r8a66597->driver = NULL; |
1511 | return 0; | 1799 | return 0; |
@@ -1535,8 +1823,8 @@ static int r8a66597_pullup(struct usb_gadget *gadget, int is_on) | |||
1535 | 1823 | ||
1536 | static struct usb_gadget_ops r8a66597_gadget_ops = { | 1824 | static struct usb_gadget_ops r8a66597_gadget_ops = { |
1537 | .get_frame = r8a66597_get_frame, | 1825 | .get_frame = r8a66597_get_frame, |
1538 | .start = r8a66597_start, | 1826 | .udc_start = r8a66597_start, |
1539 | .stop = r8a66597_stop, | 1827 | .udc_stop = r8a66597_stop, |
1540 | .pullup = r8a66597_pullup, | 1828 | .pullup = r8a66597_pullup, |
1541 | }; | 1829 | }; |
1542 | 1830 | ||
@@ -1547,6 +1835,8 @@ static int __exit r8a66597_remove(struct platform_device *pdev) | |||
1547 | usb_del_gadget_udc(&r8a66597->gadget); | 1835 | usb_del_gadget_udc(&r8a66597->gadget); |
1548 | del_timer_sync(&r8a66597->timer); | 1836 | del_timer_sync(&r8a66597->timer); |
1549 | iounmap(r8a66597->reg); | 1837 | iounmap(r8a66597->reg); |
1838 | if (r8a66597->pdata->sudmac) | ||
1839 | iounmap(r8a66597->sudmac_reg); | ||
1550 | free_irq(platform_get_irq(pdev, 0), r8a66597); | 1840 | free_irq(platform_get_irq(pdev, 0), r8a66597); |
1551 | r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); | 1841 | r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); |
1552 | #ifdef CONFIG_HAVE_CLK | 1842 | #ifdef CONFIG_HAVE_CLK |
@@ -1563,6 +1853,26 @@ static void nop_completion(struct usb_ep *ep, struct usb_request *r) | |||
1563 | { | 1853 | { |
1564 | } | 1854 | } |
1565 | 1855 | ||
1856 | static int __init r8a66597_sudmac_ioremap(struct r8a66597 *r8a66597, | ||
1857 | struct platform_device *pdev) | ||
1858 | { | ||
1859 | struct resource *res; | ||
1860 | |||
1861 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sudmac"); | ||
1862 | if (!res) { | ||
1863 | dev_err(&pdev->dev, "platform_get_resource error(sudmac).\n"); | ||
1864 | return -ENODEV; | ||
1865 | } | ||
1866 | |||
1867 | r8a66597->sudmac_reg = ioremap(res->start, resource_size(res)); | ||
1868 | if (r8a66597->sudmac_reg == NULL) { | ||
1869 | dev_err(&pdev->dev, "ioremap error(sudmac).\n"); | ||
1870 | return -ENOMEM; | ||
1871 | } | ||
1872 | |||
1873 | return 0; | ||
1874 | } | ||
1875 | |||
1566 | static int __init r8a66597_probe(struct platform_device *pdev) | 1876 | static int __init r8a66597_probe(struct platform_device *pdev) |
1567 | { | 1877 | { |
1568 | #ifdef CONFIG_HAVE_CLK | 1878 | #ifdef CONFIG_HAVE_CLK |
@@ -1579,7 +1889,7 @@ static int __init r8a66597_probe(struct platform_device *pdev) | |||
1579 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1889 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1580 | if (!res) { | 1890 | if (!res) { |
1581 | ret = -ENODEV; | 1891 | ret = -ENODEV; |
1582 | printk(KERN_ERR "platform_get_resource error.\n"); | 1892 | dev_err(&pdev->dev, "platform_get_resource error.\n"); |
1583 | goto clean_up; | 1893 | goto clean_up; |
1584 | } | 1894 | } |
1585 | 1895 | ||
@@ -1589,14 +1899,14 @@ static int __init r8a66597_probe(struct platform_device *pdev) | |||
1589 | 1899 | ||
1590 | if (irq < 0) { | 1900 | if (irq < 0) { |
1591 | ret = -ENODEV; | 1901 | ret = -ENODEV; |
1592 | printk(KERN_ERR "platform_get_irq error.\n"); | 1902 | dev_err(&pdev->dev, "platform_get_irq error.\n"); |
1593 | goto clean_up; | 1903 | goto clean_up; |
1594 | } | 1904 | } |
1595 | 1905 | ||
1596 | reg = ioremap(res->start, resource_size(res)); | 1906 | reg = ioremap(res->start, resource_size(res)); |
1597 | if (reg == NULL) { | 1907 | if (reg == NULL) { |
1598 | ret = -ENOMEM; | 1908 | ret = -ENOMEM; |
1599 | printk(KERN_ERR "ioremap error.\n"); | 1909 | dev_err(&pdev->dev, "ioremap error.\n"); |
1600 | goto clean_up; | 1910 | goto clean_up; |
1601 | } | 1911 | } |
1602 | 1912 | ||
@@ -1604,7 +1914,7 @@ static int __init r8a66597_probe(struct platform_device *pdev) | |||
1604 | r8a66597 = kzalloc(sizeof(struct r8a66597), GFP_KERNEL); | 1914 | r8a66597 = kzalloc(sizeof(struct r8a66597), GFP_KERNEL); |
1605 | if (r8a66597 == NULL) { | 1915 | if (r8a66597 == NULL) { |
1606 | ret = -ENOMEM; | 1916 | ret = -ENOMEM; |
1607 | printk(KERN_ERR "kzalloc error\n"); | 1917 | dev_err(&pdev->dev, "kzalloc error\n"); |
1608 | goto clean_up; | 1918 | goto clean_up; |
1609 | } | 1919 | } |
1610 | 1920 | ||
@@ -1640,13 +1950,18 @@ static int __init r8a66597_probe(struct platform_device *pdev) | |||
1640 | clk_enable(r8a66597->clk); | 1950 | clk_enable(r8a66597->clk); |
1641 | } | 1951 | } |
1642 | #endif | 1952 | #endif |
1953 | if (r8a66597->pdata->sudmac) { | ||
1954 | ret = r8a66597_sudmac_ioremap(r8a66597, pdev); | ||
1955 | if (ret < 0) | ||
1956 | goto clean_up2; | ||
1957 | } | ||
1643 | 1958 | ||
1644 | disable_controller(r8a66597); /* make sure controller is disabled */ | 1959 | disable_controller(r8a66597); /* make sure controller is disabled */ |
1645 | 1960 | ||
1646 | ret = request_irq(irq, r8a66597_irq, IRQF_DISABLED | IRQF_SHARED, | 1961 | ret = request_irq(irq, r8a66597_irq, IRQF_SHARED, |
1647 | udc_name, r8a66597); | 1962 | udc_name, r8a66597); |
1648 | if (ret < 0) { | 1963 | if (ret < 0) { |
1649 | printk(KERN_ERR "request_irq error (%d)\n", ret); | 1964 | dev_err(&pdev->dev, "request_irq error (%d)\n", ret); |
1650 | goto clean_up2; | 1965 | goto clean_up2; |
1651 | } | 1966 | } |
1652 | 1967 | ||
@@ -1672,13 +1987,10 @@ static int __init r8a66597_probe(struct platform_device *pdev) | |||
1672 | r8a66597->ep[0].fifoaddr = CFIFO; | 1987 | r8a66597->ep[0].fifoaddr = CFIFO; |
1673 | r8a66597->ep[0].fifosel = CFIFOSEL; | 1988 | r8a66597->ep[0].fifosel = CFIFOSEL; |
1674 | r8a66597->ep[0].fifoctr = CFIFOCTR; | 1989 | r8a66597->ep[0].fifoctr = CFIFOCTR; |
1675 | r8a66597->ep[0].fifotrn = 0; | ||
1676 | r8a66597->ep[0].pipectr = get_pipectr_addr(0); | 1990 | r8a66597->ep[0].pipectr = get_pipectr_addr(0); |
1677 | r8a66597->pipenum2ep[0] = &r8a66597->ep[0]; | 1991 | r8a66597->pipenum2ep[0] = &r8a66597->ep[0]; |
1678 | r8a66597->epaddr2ep[0] = &r8a66597->ep[0]; | 1992 | r8a66597->epaddr2ep[0] = &r8a66597->ep[0]; |
1679 | 1993 | ||
1680 | the_controller = r8a66597; | ||
1681 | |||
1682 | r8a66597->ep0_req = r8a66597_alloc_request(&r8a66597->ep[0].ep, | 1994 | r8a66597->ep0_req = r8a66597_alloc_request(&r8a66597->ep[0].ep, |
1683 | GFP_KERNEL); | 1995 | GFP_KERNEL); |
1684 | if (r8a66597->ep0_req == NULL) | 1996 | if (r8a66597->ep0_req == NULL) |
@@ -1705,6 +2017,8 @@ clean_up2: | |||
1705 | #endif | 2017 | #endif |
1706 | clean_up: | 2018 | clean_up: |
1707 | if (r8a66597) { | 2019 | if (r8a66597) { |
2020 | if (r8a66597->sudmac_reg) | ||
2021 | iounmap(r8a66597->sudmac_reg); | ||
1708 | if (r8a66597->ep0_req) | 2022 | if (r8a66597->ep0_req) |
1709 | r8a66597_free_request(&r8a66597->ep[0].ep, | 2023 | r8a66597_free_request(&r8a66597->ep[0].ep, |
1710 | r8a66597->ep0_req); | 2024 | r8a66597->ep0_req); |
diff --git a/drivers/usb/gadget/r8a66597-udc.h b/drivers/usb/gadget/r8a66597-udc.h index 503f766c23a7..8e3de61cd4b8 100644 --- a/drivers/usb/gadget/r8a66597-udc.h +++ b/drivers/usb/gadget/r8a66597-udc.h | |||
@@ -8,16 +8,6 @@ | |||
8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; version 2 of the License. | 10 | * the Free Software Foundation; version 2 of the License. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | * | ||
21 | */ | 11 | */ |
22 | 12 | ||
23 | #ifndef __R8A66597_H__ | 13 | #ifndef __R8A66597_H__ |
@@ -53,6 +43,7 @@ | |||
53 | ((pipenum >= R8A66597_BASE_PIPENUM_ISOC) && \ | 43 | ((pipenum >= R8A66597_BASE_PIPENUM_ISOC) && \ |
54 | (pipenum < (R8A66597_BASE_PIPENUM_ISOC + R8A66597_MAX_NUM_ISOC))) | 44 | (pipenum < (R8A66597_BASE_PIPENUM_ISOC + R8A66597_MAX_NUM_ISOC))) |
55 | 45 | ||
46 | #define r8a66597_is_sudmac(r8a66597) (r8a66597->pdata->sudmac) | ||
56 | struct r8a66597_pipe_info { | 47 | struct r8a66597_pipe_info { |
57 | u16 pipe; | 48 | u16 pipe; |
58 | u16 epnum; | 49 | u16 epnum; |
@@ -70,6 +61,7 @@ struct r8a66597_request { | |||
70 | struct r8a66597_ep { | 61 | struct r8a66597_ep { |
71 | struct usb_ep ep; | 62 | struct usb_ep ep; |
72 | struct r8a66597 *r8a66597; | 63 | struct r8a66597 *r8a66597; |
64 | struct r8a66597_dma *dma; | ||
73 | 65 | ||
74 | struct list_head queue; | 66 | struct list_head queue; |
75 | unsigned busy:1; | 67 | unsigned busy:1; |
@@ -85,13 +77,20 @@ struct r8a66597_ep { | |||
85 | unsigned char fifoaddr; | 77 | unsigned char fifoaddr; |
86 | unsigned char fifosel; | 78 | unsigned char fifosel; |
87 | unsigned char fifoctr; | 79 | unsigned char fifoctr; |
88 | unsigned char fifotrn; | ||
89 | unsigned char pipectr; | 80 | unsigned char pipectr; |
81 | unsigned char pipetre; | ||
82 | unsigned char pipetrn; | ||
83 | }; | ||
84 | |||
85 | struct r8a66597_dma { | ||
86 | unsigned used:1; | ||
87 | unsigned dir:1; /* 1 = IN(write), 0 = OUT(read) */ | ||
90 | }; | 88 | }; |
91 | 89 | ||
92 | struct r8a66597 { | 90 | struct r8a66597 { |
93 | spinlock_t lock; | 91 | spinlock_t lock; |
94 | void __iomem *reg; | 92 | void __iomem *reg; |
93 | void __iomem *sudmac_reg; | ||
95 | 94 | ||
96 | #ifdef CONFIG_HAVE_CLK | 95 | #ifdef CONFIG_HAVE_CLK |
97 | struct clk *clk; | 96 | struct clk *clk; |
@@ -104,6 +103,7 @@ struct r8a66597 { | |||
104 | struct r8a66597_ep ep[R8A66597_MAX_NUM_PIPE]; | 103 | struct r8a66597_ep ep[R8A66597_MAX_NUM_PIPE]; |
105 | struct r8a66597_ep *pipenum2ep[R8A66597_MAX_NUM_PIPE]; | 104 | struct r8a66597_ep *pipenum2ep[R8A66597_MAX_NUM_PIPE]; |
106 | struct r8a66597_ep *epaddr2ep[16]; | 105 | struct r8a66597_ep *epaddr2ep[16]; |
106 | struct r8a66597_dma dma; | ||
107 | 107 | ||
108 | struct timer_list timer; | 108 | struct timer_list timer; |
109 | struct usb_request *ep0_req; /* for internal request */ | 109 | struct usb_request *ep0_req; /* for internal request */ |
@@ -124,6 +124,7 @@ struct r8a66597 { | |||
124 | #define gadget_to_r8a66597(_gadget) \ | 124 | #define gadget_to_r8a66597(_gadget) \ |
125 | container_of(_gadget, struct r8a66597, gadget) | 125 | container_of(_gadget, struct r8a66597, gadget) |
126 | #define r8a66597_to_gadget(r8a66597) (&r8a66597->gadget) | 126 | #define r8a66597_to_gadget(r8a66597) (&r8a66597->gadget) |
127 | #define r8a66597_to_dev(r8a66597) (r8a66597->gadget.dev.parent) | ||
127 | 128 | ||
128 | static inline u16 r8a66597_read(struct r8a66597 *r8a66597, unsigned long offset) | 129 | static inline u16 r8a66597_read(struct r8a66597 *r8a66597, unsigned long offset) |
129 | { | 130 | { |
@@ -182,12 +183,27 @@ static inline void r8a66597_write(struct r8a66597 *r8a66597, u16 val, | |||
182 | iowrite16(val, r8a66597->reg + offset); | 183 | iowrite16(val, r8a66597->reg + offset); |
183 | } | 184 | } |
184 | 185 | ||
186 | static inline void r8a66597_mdfy(struct r8a66597 *r8a66597, | ||
187 | u16 val, u16 pat, unsigned long offset) | ||
188 | { | ||
189 | u16 tmp; | ||
190 | tmp = r8a66597_read(r8a66597, offset); | ||
191 | tmp = tmp & (~pat); | ||
192 | tmp = tmp | val; | ||
193 | r8a66597_write(r8a66597, tmp, offset); | ||
194 | } | ||
195 | |||
196 | #define r8a66597_bclr(r8a66597, val, offset) \ | ||
197 | r8a66597_mdfy(r8a66597, 0, val, offset) | ||
198 | #define r8a66597_bset(r8a66597, val, offset) \ | ||
199 | r8a66597_mdfy(r8a66597, val, 0, offset) | ||
200 | |||
185 | static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597, | 201 | static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597, |
186 | unsigned long offset, | 202 | struct r8a66597_ep *ep, |
187 | unsigned char *buf, | 203 | unsigned char *buf, |
188 | int len) | 204 | int len) |
189 | { | 205 | { |
190 | void __iomem *fifoaddr = r8a66597->reg + offset; | 206 | void __iomem *fifoaddr = r8a66597->reg + ep->fifoaddr; |
191 | int adj = 0; | 207 | int adj = 0; |
192 | int i; | 208 | int i; |
193 | 209 | ||
@@ -215,18 +231,12 @@ static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597, | |||
215 | adj = 0x01; /* 16-bit wide */ | 231 | adj = 0x01; /* 16-bit wide */ |
216 | } | 232 | } |
217 | 233 | ||
234 | if (r8a66597->pdata->wr0_shorted_to_wr1) | ||
235 | r8a66597_bclr(r8a66597, MBW_16, ep->fifosel); | ||
218 | for (i = 0; i < len; i++) | 236 | for (i = 0; i < len; i++) |
219 | iowrite8(buf[i], fifoaddr + adj - (i & adj)); | 237 | iowrite8(buf[i], fifoaddr + adj - (i & adj)); |
220 | } | 238 | if (r8a66597->pdata->wr0_shorted_to_wr1) |
221 | 239 | r8a66597_bclr(r8a66597, MBW_16, ep->fifosel); | |
222 | static inline void r8a66597_mdfy(struct r8a66597 *r8a66597, | ||
223 | u16 val, u16 pat, unsigned long offset) | ||
224 | { | ||
225 | u16 tmp; | ||
226 | tmp = r8a66597_read(r8a66597, offset); | ||
227 | tmp = tmp & (~pat); | ||
228 | tmp = tmp | val; | ||
229 | r8a66597_write(r8a66597, tmp, offset); | ||
230 | } | 240 | } |
231 | 241 | ||
232 | static inline u16 get_xtal_from_pdata(struct r8a66597_platdata *pdata) | 242 | static inline u16 get_xtal_from_pdata(struct r8a66597_platdata *pdata) |
@@ -251,12 +261,21 @@ static inline u16 get_xtal_from_pdata(struct r8a66597_platdata *pdata) | |||
251 | return clock; | 261 | return clock; |
252 | } | 262 | } |
253 | 263 | ||
254 | #define r8a66597_bclr(r8a66597, val, offset) \ | 264 | static inline u32 r8a66597_sudmac_read(struct r8a66597 *r8a66597, |
255 | r8a66597_mdfy(r8a66597, 0, val, offset) | 265 | unsigned long offset) |
256 | #define r8a66597_bset(r8a66597, val, offset) \ | 266 | { |
257 | r8a66597_mdfy(r8a66597, val, 0, offset) | 267 | return ioread32(r8a66597->sudmac_reg + offset); |
268 | } | ||
269 | |||
270 | static inline void r8a66597_sudmac_write(struct r8a66597 *r8a66597, u32 val, | ||
271 | unsigned long offset) | ||
272 | { | ||
273 | iowrite32(val, r8a66597->sudmac_reg + offset); | ||
274 | } | ||
258 | 275 | ||
259 | #define get_pipectr_addr(pipenum) (PIPE1CTR + (pipenum - 1) * 2) | 276 | #define get_pipectr_addr(pipenum) (PIPE1CTR + (pipenum - 1) * 2) |
277 | #define get_pipetre_addr(pipenum) (PIPE1TRE + (pipenum - 1) * 4) | ||
278 | #define get_pipetrn_addr(pipenum) (PIPE1TRN + (pipenum - 1) * 4) | ||
260 | 279 | ||
261 | #define enable_irq_ready(r8a66597, pipenum) \ | 280 | #define enable_irq_ready(r8a66597, pipenum) \ |
262 | enable_pipe_irq(r8a66597, pipenum, BRDYENB) | 281 | enable_pipe_irq(r8a66597, pipenum, BRDYENB) |
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c index 8bdee67ce09a..a552453dc946 100644 --- a/drivers/usb/gadget/s3c-hsotg.c +++ b/drivers/usb/gadget/s3c-hsotg.c | |||
@@ -1951,30 +1951,26 @@ static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) | |||
1951 | case S3C_DSTS_EnumSpd_FS: | 1951 | case S3C_DSTS_EnumSpd_FS: |
1952 | case S3C_DSTS_EnumSpd_FS48: | 1952 | case S3C_DSTS_EnumSpd_FS48: |
1953 | hsotg->gadget.speed = USB_SPEED_FULL; | 1953 | hsotg->gadget.speed = USB_SPEED_FULL; |
1954 | dev_info(hsotg->dev, "new device is full-speed\n"); | ||
1955 | |||
1956 | ep0_mps = EP0_MPS_LIMIT; | 1954 | ep0_mps = EP0_MPS_LIMIT; |
1957 | ep_mps = 64; | 1955 | ep_mps = 64; |
1958 | break; | 1956 | break; |
1959 | 1957 | ||
1960 | case S3C_DSTS_EnumSpd_HS: | 1958 | case S3C_DSTS_EnumSpd_HS: |
1961 | dev_info(hsotg->dev, "new device is high-speed\n"); | ||
1962 | hsotg->gadget.speed = USB_SPEED_HIGH; | 1959 | hsotg->gadget.speed = USB_SPEED_HIGH; |
1963 | |||
1964 | ep0_mps = EP0_MPS_LIMIT; | 1960 | ep0_mps = EP0_MPS_LIMIT; |
1965 | ep_mps = 512; | 1961 | ep_mps = 512; |
1966 | break; | 1962 | break; |
1967 | 1963 | ||
1968 | case S3C_DSTS_EnumSpd_LS: | 1964 | case S3C_DSTS_EnumSpd_LS: |
1969 | hsotg->gadget.speed = USB_SPEED_LOW; | 1965 | hsotg->gadget.speed = USB_SPEED_LOW; |
1970 | dev_info(hsotg->dev, "new device is low-speed\n"); | ||
1971 | |||
1972 | /* note, we don't actually support LS in this driver at the | 1966 | /* note, we don't actually support LS in this driver at the |
1973 | * moment, and the documentation seems to imply that it isn't | 1967 | * moment, and the documentation seems to imply that it isn't |
1974 | * supported by the PHYs on some of the devices. | 1968 | * supported by the PHYs on some of the devices. |
1975 | */ | 1969 | */ |
1976 | break; | 1970 | break; |
1977 | } | 1971 | } |
1972 | dev_info(hsotg->dev, "new device is %s\n", | ||
1973 | usb_speed_string(hsotg->gadget.speed)); | ||
1978 | 1974 | ||
1979 | /* we should now know the maximum packet size for an | 1975 | /* we should now know the maximum packet size for an |
1980 | * endpoint, so set the endpoints to a default value. */ | 1976 | * endpoint, so set the endpoints to a default value. */ |
@@ -2297,7 +2293,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2297 | return -EINVAL; | 2293 | return -EINVAL; |
2298 | } | 2294 | } |
2299 | 2295 | ||
2300 | mps = le16_to_cpu(desc->wMaxPacketSize); | 2296 | mps = usb_endpoint_maxp(desc); |
2301 | 2297 | ||
2302 | /* note, we handle this here instead of s3c_hsotg_set_ep_maxpacket */ | 2298 | /* note, we handle this here instead of s3c_hsotg_set_ep_maxpacket */ |
2303 | 2299 | ||
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c index 3fa717c5f4bc..8d54f893cefe 100644 --- a/drivers/usb/gadget/s3c-hsudc.c +++ b/drivers/usb/gadget/s3c-hsudc.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/clk.h> | 26 | #include <linux/clk.h> |
27 | #include <linux/usb/ch9.h> | 27 | #include <linux/usb/ch9.h> |
28 | #include <linux/usb/gadget.h> | 28 | #include <linux/usb/gadget.h> |
29 | #include <linux/usb/otg.h> | ||
29 | #include <linux/prefetch.h> | 30 | #include <linux/prefetch.h> |
30 | 31 | ||
31 | #include <mach/regs-s3c2443-clock.h> | 32 | #include <mach/regs-s3c2443-clock.h> |
@@ -137,6 +138,7 @@ struct s3c_hsudc { | |||
137 | struct usb_gadget_driver *driver; | 138 | struct usb_gadget_driver *driver; |
138 | struct device *dev; | 139 | struct device *dev; |
139 | struct s3c24xx_hsudc_platdata *pd; | 140 | struct s3c24xx_hsudc_platdata *pd; |
141 | struct otg_transceiver *transceiver; | ||
140 | spinlock_t lock; | 142 | spinlock_t lock; |
141 | void __iomem *regs; | 143 | void __iomem *regs; |
142 | struct resource *mem_rsrc; | 144 | struct resource *mem_rsrc; |
@@ -759,11 +761,11 @@ static int s3c_hsudc_ep_enable(struct usb_ep *_ep, | |||
759 | if (!_ep || !desc || hsep->desc || _ep->name == ep0name | 761 | if (!_ep || !desc || hsep->desc || _ep->name == ep0name |
760 | || desc->bDescriptorType != USB_DT_ENDPOINT | 762 | || desc->bDescriptorType != USB_DT_ENDPOINT |
761 | || hsep->bEndpointAddress != desc->bEndpointAddress | 763 | || hsep->bEndpointAddress != desc->bEndpointAddress |
762 | || ep_maxpacket(hsep) < le16_to_cpu(desc->wMaxPacketSize)) | 764 | || ep_maxpacket(hsep) < usb_endpoint_maxp(desc)) |
763 | return -EINVAL; | 765 | return -EINVAL; |
764 | 766 | ||
765 | if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK | 767 | if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK |
766 | && le16_to_cpu(desc->wMaxPacketSize) != ep_maxpacket(hsep)) | 768 | && usb_endpoint_maxp(desc) != ep_maxpacket(hsep)) |
767 | || !desc->wMaxPacketSize) | 769 | || !desc->wMaxPacketSize) |
768 | return -ERANGE; | 770 | return -ERANGE; |
769 | 771 | ||
@@ -779,7 +781,7 @@ static int s3c_hsudc_ep_enable(struct usb_ep *_ep, | |||
779 | 781 | ||
780 | hsep->stopped = hsep->wedge = 0; | 782 | hsep->stopped = hsep->wedge = 0; |
781 | hsep->desc = desc; | 783 | hsep->desc = desc; |
782 | hsep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize); | 784 | hsep->ep.maxpacket = usb_endpoint_maxp(desc); |
783 | 785 | ||
784 | s3c_hsudc_set_halt(_ep, 0); | 786 | s3c_hsudc_set_halt(_ep, 0); |
785 | __set_bit(ep_index(hsep), hsudc->regs + S3C_EIER); | 787 | __set_bit(ep_index(hsep), hsudc->regs + S3C_EIER); |
@@ -1171,6 +1173,22 @@ static int s3c_hsudc_start(struct usb_gadget_driver *driver, | |||
1171 | return ret; | 1173 | return ret; |
1172 | } | 1174 | } |
1173 | 1175 | ||
1176 | /* connect to bus through transceiver */ | ||
1177 | if (hsudc->transceiver) { | ||
1178 | ret = otg_set_peripheral(hsudc->transceiver, &hsudc->gadget); | ||
1179 | if (ret) { | ||
1180 | dev_err(hsudc->dev, "%s: can't bind to transceiver\n", | ||
1181 | hsudc->gadget.name); | ||
1182 | driver->unbind(&hsudc->gadget); | ||
1183 | |||
1184 | device_del(&hsudc->gadget.dev); | ||
1185 | |||
1186 | hsudc->driver = NULL; | ||
1187 | hsudc->gadget.dev.driver = NULL; | ||
1188 | return ret; | ||
1189 | } | ||
1190 | } | ||
1191 | |||
1174 | enable_irq(hsudc->irq); | 1192 | enable_irq(hsudc->irq); |
1175 | dev_info(hsudc->dev, "bound driver %s\n", driver->driver.name); | 1193 | dev_info(hsudc->dev, "bound driver %s\n", driver->driver.name); |
1176 | 1194 | ||
@@ -1201,6 +1219,9 @@ static int s3c_hsudc_stop(struct usb_gadget_driver *driver) | |||
1201 | s3c_hsudc_stop_activity(hsudc, driver); | 1219 | s3c_hsudc_stop_activity(hsudc, driver); |
1202 | spin_unlock_irqrestore(&hsudc->lock, flags); | 1220 | spin_unlock_irqrestore(&hsudc->lock, flags); |
1203 | 1221 | ||
1222 | if (hsudc->transceiver) | ||
1223 | (void) otg_set_peripheral(hsudc->transceiver, NULL); | ||
1224 | |||
1204 | driver->unbind(&hsudc->gadget); | 1225 | driver->unbind(&hsudc->gadget); |
1205 | device_del(&hsudc->gadget.dev); | 1226 | device_del(&hsudc->gadget.dev); |
1206 | disable_irq(hsudc->irq); | 1227 | disable_irq(hsudc->irq); |
@@ -1220,10 +1241,24 @@ static int s3c_hsudc_gadget_getframe(struct usb_gadget *gadget) | |||
1220 | return s3c_hsudc_read_frameno(to_hsudc(gadget)); | 1241 | return s3c_hsudc_read_frameno(to_hsudc(gadget)); |
1221 | } | 1242 | } |
1222 | 1243 | ||
1244 | static int s3c_hsudc_vbus_draw(struct usb_gadget *gadget, unsigned mA) | ||
1245 | { | ||
1246 | struct s3c_hsudc *hsudc = the_controller; | ||
1247 | |||
1248 | if (!hsudc) | ||
1249 | return -ENODEV; | ||
1250 | |||
1251 | if (hsudc->transceiver) | ||
1252 | return otg_set_power(hsudc->transceiver, mA); | ||
1253 | |||
1254 | return -EOPNOTSUPP; | ||
1255 | } | ||
1256 | |||
1223 | static struct usb_gadget_ops s3c_hsudc_gadget_ops = { | 1257 | static struct usb_gadget_ops s3c_hsudc_gadget_ops = { |
1224 | .get_frame = s3c_hsudc_gadget_getframe, | 1258 | .get_frame = s3c_hsudc_gadget_getframe, |
1225 | .start = s3c_hsudc_start, | 1259 | .start = s3c_hsudc_start, |
1226 | .stop = s3c_hsudc_stop, | 1260 | .stop = s3c_hsudc_stop, |
1261 | .vbus_draw = s3c_hsudc_vbus_draw, | ||
1227 | }; | 1262 | }; |
1228 | 1263 | ||
1229 | static int s3c_hsudc_probe(struct platform_device *pdev) | 1264 | static int s3c_hsudc_probe(struct platform_device *pdev) |
@@ -1247,6 +1282,8 @@ static int s3c_hsudc_probe(struct platform_device *pdev) | |||
1247 | hsudc->dev = dev; | 1282 | hsudc->dev = dev; |
1248 | hsudc->pd = pdev->dev.platform_data; | 1283 | hsudc->pd = pdev->dev.platform_data; |
1249 | 1284 | ||
1285 | hsudc->transceiver = otg_get_transceiver(); | ||
1286 | |||
1250 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1287 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1251 | if (!res) { | 1288 | if (!res) { |
1252 | dev_err(dev, "unable to obtain driver resource data\n"); | 1289 | dev_err(dev, "unable to obtain driver resource data\n"); |
@@ -1269,19 +1306,6 @@ static int s3c_hsudc_probe(struct platform_device *pdev) | |||
1269 | goto err_remap; | 1306 | goto err_remap; |
1270 | } | 1307 | } |
1271 | 1308 | ||
1272 | ret = platform_get_irq(pdev, 0); | ||
1273 | if (ret < 0) { | ||
1274 | dev_err(dev, "unable to obtain IRQ number\n"); | ||
1275 | goto err_irq; | ||
1276 | } | ||
1277 | hsudc->irq = ret; | ||
1278 | |||
1279 | ret = request_irq(hsudc->irq, s3c_hsudc_irq, 0, driver_name, hsudc); | ||
1280 | if (ret < 0) { | ||
1281 | dev_err(dev, "irq request failed\n"); | ||
1282 | goto err_irq; | ||
1283 | } | ||
1284 | |||
1285 | spin_lock_init(&hsudc->lock); | 1309 | spin_lock_init(&hsudc->lock); |
1286 | 1310 | ||
1287 | device_initialize(&hsudc->gadget.dev); | 1311 | device_initialize(&hsudc->gadget.dev); |
@@ -1299,6 +1323,19 @@ static int s3c_hsudc_probe(struct platform_device *pdev) | |||
1299 | 1323 | ||
1300 | s3c_hsudc_setup_ep(hsudc); | 1324 | s3c_hsudc_setup_ep(hsudc); |
1301 | 1325 | ||
1326 | ret = platform_get_irq(pdev, 0); | ||
1327 | if (ret < 0) { | ||
1328 | dev_err(dev, "unable to obtain IRQ number\n"); | ||
1329 | goto err_irq; | ||
1330 | } | ||
1331 | hsudc->irq = ret; | ||
1332 | |||
1333 | ret = request_irq(hsudc->irq, s3c_hsudc_irq, 0, driver_name, hsudc); | ||
1334 | if (ret < 0) { | ||
1335 | dev_err(dev, "irq request failed\n"); | ||
1336 | goto err_irq; | ||
1337 | } | ||
1338 | |||
1302 | hsudc->uclk = clk_get(&pdev->dev, "usb-device"); | 1339 | hsudc->uclk = clk_get(&pdev->dev, "usb-device"); |
1303 | if (IS_ERR(hsudc->uclk)) { | 1340 | if (IS_ERR(hsudc->uclk)) { |
1304 | dev_err(dev, "failed to find usb-device clock source\n"); | 1341 | dev_err(dev, "failed to find usb-device clock source\n"); |
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c index 8d31848aab09..b8643771fa80 100644 --- a/drivers/usb/gadget/s3c2410_udc.c +++ b/drivers/usb/gadget/s3c2410_udc.c | |||
@@ -10,16 +10,6 @@ | |||
10 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or | 11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. | 12 | * (at your option) any later version. |
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | */ | 13 | */ |
24 | 14 | ||
25 | #include <linux/module.h> | 15 | #include <linux/module.h> |
@@ -1082,7 +1072,7 @@ static int s3c2410_udc_ep_enable(struct usb_ep *_ep, | |||
1082 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | 1072 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) |
1083 | return -ESHUTDOWN; | 1073 | return -ESHUTDOWN; |
1084 | 1074 | ||
1085 | max = le16_to_cpu(desc->wMaxPacketSize) & 0x1fff; | 1075 | max = usb_endpoint_maxp(desc) & 0x1fff; |
1086 | 1076 | ||
1087 | local_irq_save (flags); | 1077 | local_irq_save (flags); |
1088 | _ep->maxpacket = max & 0x7ff; | 1078 | _ep->maxpacket = max & 0x7ff; |
@@ -1903,7 +1893,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev) | |||
1903 | 1893 | ||
1904 | /* irq setup after old hardware state is cleaned up */ | 1894 | /* irq setup after old hardware state is cleaned up */ |
1905 | retval = request_irq(IRQ_USBD, s3c2410_udc_irq, | 1895 | retval = request_irq(IRQ_USBD, s3c2410_udc_irq, |
1906 | IRQF_DISABLED, gadget_name, udc); | 1896 | 0, gadget_name, udc); |
1907 | 1897 | ||
1908 | if (retval != 0) { | 1898 | if (retval != 0) { |
1909 | dev_err(dev, "cannot get irq %i, err %d\n", IRQ_USBD, retval); | 1899 | dev_err(dev, "cannot get irq %i, err %d\n", IRQ_USBD, retval); |
@@ -1927,7 +1917,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev) | |||
1927 | } | 1917 | } |
1928 | 1918 | ||
1929 | retval = request_irq(irq, s3c2410_udc_vbus_irq, | 1919 | retval = request_irq(irq, s3c2410_udc_vbus_irq, |
1930 | IRQF_DISABLED | IRQF_TRIGGER_RISING | 1920 | IRQF_TRIGGER_RISING |
1931 | | IRQF_TRIGGER_FALLING | IRQF_SHARED, | 1921 | | IRQF_TRIGGER_FALLING | IRQF_SHARED, |
1932 | gadget_name, udc); | 1922 | gadget_name, udc); |
1933 | 1923 | ||
diff --git a/drivers/usb/gadget/s3c2410_udc.h b/drivers/usb/gadget/s3c2410_udc.h index 9e0bece4f241..a48f619cb1cc 100644 --- a/drivers/usb/gadget/s3c2410_udc.h +++ b/drivers/usb/gadget/s3c2410_udc.h | |||
@@ -9,16 +9,6 @@ | |||
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or | 10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. | 11 | * (at your option) any later version. |
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | * | ||
22 | */ | 12 | */ |
23 | 13 | ||
24 | #ifndef _S3C2410_UDC_H | 14 | #ifndef _S3C2410_UDC_H |
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index d3dd227a2bfc..c7f291a331df 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c | |||
@@ -9,15 +9,6 @@ | |||
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or | 10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. | 11 | * (at your option) any later version. |
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | 12 | */ |
22 | 13 | ||
23 | 14 | ||
@@ -52,6 +43,12 @@ | |||
52 | * characters rather then a pointer to void. | 43 | * characters rather then a pointer to void. |
53 | */ | 44 | */ |
54 | 45 | ||
46 | /* | ||
47 | * When USB_GADGET_DEBUG_FILES is defined the module param num_buffers | ||
48 | * sets the number of pipeline buffers (length of the fsg_buffhd array). | ||
49 | * The valid range of num_buffers is: num >= 2 && num <= 4. | ||
50 | */ | ||
51 | |||
55 | 52 | ||
56 | #include <linux/usb/storage.h> | 53 | #include <linux/usb/storage.h> |
57 | #include <scsi/scsi.h> | 54 | #include <scsi/scsi.h> |
@@ -247,6 +244,8 @@ struct fsg_lun { | |||
247 | u32 sense_data_info; | 244 | u32 sense_data_info; |
248 | u32 unit_attention_data; | 245 | u32 unit_attention_data; |
249 | 246 | ||
247 | unsigned int blkbits; /* Bits of logical block size of bound block device */ | ||
248 | unsigned int blksize; /* logical block size of bound block device */ | ||
250 | struct device dev; | 249 | struct device dev; |
251 | }; | 250 | }; |
252 | 251 | ||
@@ -262,8 +261,31 @@ static struct fsg_lun *fsg_lun_from_dev(struct device *dev) | |||
262 | #define EP0_BUFSIZE 256 | 261 | #define EP0_BUFSIZE 256 |
263 | #define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */ | 262 | #define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */ |
264 | 263 | ||
265 | /* Number of buffers we will use. 2 is enough for double-buffering */ | 264 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
266 | #define FSG_NUM_BUFFERS 2 | 265 | |
266 | static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; | ||
267 | module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO); | ||
268 | MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers"); | ||
269 | |||
270 | #else | ||
271 | |||
272 | /* | ||
273 | * Number of buffers we will use. | ||
274 | * 2 is usually enough for good buffering pipeline | ||
275 | */ | ||
276 | #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS | ||
277 | |||
278 | #endif /* CONFIG_USB_DEBUG */ | ||
279 | |||
280 | /* check if fsg_num_buffers is within a valid range */ | ||
281 | static inline int fsg_num_buffers_validate(void) | ||
282 | { | ||
283 | if (fsg_num_buffers >= 2 && fsg_num_buffers <= 4) | ||
284 | return 0; | ||
285 | pr_err("fsg_num_buffers %u is out of range (%d to %d)\n", | ||
286 | fsg_num_buffers, 2 ,4); | ||
287 | return -EINVAL; | ||
288 | } | ||
267 | 289 | ||
268 | /* Default size of buffer length. */ | 290 | /* Default size of buffer length. */ |
269 | #define FSG_BUFLEN ((u32)16384) | 291 | #define FSG_BUFLEN ((u32)16384) |
@@ -493,12 +515,128 @@ static struct usb_descriptor_header *fsg_hs_function[] = { | |||
493 | NULL, | 515 | NULL, |
494 | }; | 516 | }; |
495 | 517 | ||
518 | static struct usb_endpoint_descriptor | ||
519 | fsg_ss_bulk_in_desc = { | ||
520 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
521 | .bDescriptorType = USB_DT_ENDPOINT, | ||
522 | |||
523 | /* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */ | ||
524 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
525 | .wMaxPacketSize = cpu_to_le16(1024), | ||
526 | }; | ||
527 | |||
528 | static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = { | ||
529 | .bLength = sizeof(fsg_ss_bulk_in_comp_desc), | ||
530 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
531 | |||
532 | /*.bMaxBurst = DYNAMIC, */ | ||
533 | }; | ||
534 | |||
535 | static struct usb_endpoint_descriptor | ||
536 | fsg_ss_bulk_out_desc = { | ||
537 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
538 | .bDescriptorType = USB_DT_ENDPOINT, | ||
539 | |||
540 | /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */ | ||
541 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
542 | .wMaxPacketSize = cpu_to_le16(1024), | ||
543 | }; | ||
544 | |||
545 | static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = { | ||
546 | .bLength = sizeof(fsg_ss_bulk_in_comp_desc), | ||
547 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
548 | |||
549 | /*.bMaxBurst = DYNAMIC, */ | ||
550 | }; | ||
551 | |||
552 | #ifndef FSG_NO_INTR_EP | ||
553 | |||
554 | static struct usb_endpoint_descriptor | ||
555 | fsg_ss_intr_in_desc = { | ||
556 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
557 | .bDescriptorType = USB_DT_ENDPOINT, | ||
558 | |||
559 | /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */ | ||
560 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
561 | .wMaxPacketSize = cpu_to_le16(2), | ||
562 | .bInterval = 9, /* 2**(9-1) = 256 uframes -> 32 ms */ | ||
563 | }; | ||
564 | |||
565 | static struct usb_ss_ep_comp_descriptor fsg_ss_intr_in_comp_desc = { | ||
566 | .bLength = sizeof(fsg_ss_bulk_in_comp_desc), | ||
567 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
568 | |||
569 | .wBytesPerInterval = cpu_to_le16(2), | ||
570 | }; | ||
571 | |||
572 | #ifndef FSG_NO_OTG | ||
573 | # define FSG_SS_FUNCTION_PRE_EP_ENTRIES 2 | ||
574 | #else | ||
575 | # define FSG_SS_FUNCTION_PRE_EP_ENTRIES 1 | ||
576 | #endif | ||
577 | |||
578 | #endif | ||
579 | |||
580 | static __maybe_unused struct usb_ext_cap_descriptor fsg_ext_cap_desc = { | ||
581 | .bLength = USB_DT_USB_EXT_CAP_SIZE, | ||
582 | .bDescriptorType = USB_DT_DEVICE_CAPABILITY, | ||
583 | .bDevCapabilityType = USB_CAP_TYPE_EXT, | ||
584 | |||
585 | .bmAttributes = cpu_to_le32(USB_LPM_SUPPORT), | ||
586 | }; | ||
587 | |||
588 | static __maybe_unused struct usb_ss_cap_descriptor fsg_ss_cap_desc = { | ||
589 | .bLength = USB_DT_USB_SS_CAP_SIZE, | ||
590 | .bDescriptorType = USB_DT_DEVICE_CAPABILITY, | ||
591 | .bDevCapabilityType = USB_SS_CAP_TYPE, | ||
592 | |||
593 | /* .bmAttributes = LTM is not supported yet */ | ||
594 | |||
595 | .wSpeedSupported = cpu_to_le16(USB_LOW_SPEED_OPERATION | ||
596 | | USB_FULL_SPEED_OPERATION | ||
597 | | USB_HIGH_SPEED_OPERATION | ||
598 | | USB_5GBPS_OPERATION), | ||
599 | .bFunctionalitySupport = USB_LOW_SPEED_OPERATION, | ||
600 | .bU1devExitLat = USB_DEFAULT_U1_DEV_EXIT_LAT, | ||
601 | .bU2DevExitLat = USB_DEFAULT_U2_DEV_EXIT_LAT, | ||
602 | }; | ||
603 | |||
604 | static __maybe_unused struct usb_bos_descriptor fsg_bos_desc = { | ||
605 | .bLength = USB_DT_BOS_SIZE, | ||
606 | .bDescriptorType = USB_DT_BOS, | ||
607 | |||
608 | .wTotalLength = USB_DT_BOS_SIZE | ||
609 | + USB_DT_USB_EXT_CAP_SIZE | ||
610 | + USB_DT_USB_SS_CAP_SIZE, | ||
611 | |||
612 | .bNumDeviceCaps = 2, | ||
613 | }; | ||
614 | |||
615 | static struct usb_descriptor_header *fsg_ss_function[] = { | ||
616 | #ifndef FSG_NO_OTG | ||
617 | (struct usb_descriptor_header *) &fsg_otg_desc, | ||
618 | #endif | ||
619 | (struct usb_descriptor_header *) &fsg_intf_desc, | ||
620 | (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc, | ||
621 | (struct usb_descriptor_header *) &fsg_ss_bulk_in_comp_desc, | ||
622 | (struct usb_descriptor_header *) &fsg_ss_bulk_out_desc, | ||
623 | (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc, | ||
624 | #ifndef FSG_NO_INTR_EP | ||
625 | (struct usb_descriptor_header *) &fsg_ss_intr_in_desc, | ||
626 | (struct usb_descriptor_header *) &fsg_ss_intr_in_comp_desc, | ||
627 | #endif | ||
628 | NULL, | ||
629 | }; | ||
630 | |||
496 | /* Maxpacket and other transfer characteristics vary by speed. */ | 631 | /* Maxpacket and other transfer characteristics vary by speed. */ |
497 | static __maybe_unused struct usb_endpoint_descriptor * | 632 | static __maybe_unused struct usb_endpoint_descriptor * |
498 | fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs, | 633 | fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs, |
499 | struct usb_endpoint_descriptor *hs) | 634 | struct usb_endpoint_descriptor *hs, |
635 | struct usb_endpoint_descriptor *ss) | ||
500 | { | 636 | { |
501 | if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) | 637 | if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER) |
638 | return ss; | ||
639 | else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) | ||
502 | return hs; | 640 | return hs; |
503 | return fs; | 641 | return fs; |
504 | } | 642 | } |
@@ -580,13 +718,24 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename) | |||
580 | rc = (int) size; | 718 | rc = (int) size; |
581 | goto out; | 719 | goto out; |
582 | } | 720 | } |
583 | num_sectors = size >> 9; /* File size in 512-byte blocks */ | 721 | |
722 | if (curlun->cdrom) { | ||
723 | curlun->blksize = 2048; | ||
724 | curlun->blkbits = 11; | ||
725 | } else if (inode->i_bdev) { | ||
726 | curlun->blksize = bdev_logical_block_size(inode->i_bdev); | ||
727 | curlun->blkbits = blksize_bits(curlun->blksize); | ||
728 | } else { | ||
729 | curlun->blksize = 512; | ||
730 | curlun->blkbits = 9; | ||
731 | } | ||
732 | |||
733 | num_sectors = size >> curlun->blkbits; /* File size in logic-block-size blocks */ | ||
584 | min_sectors = 1; | 734 | min_sectors = 1; |
585 | if (curlun->cdrom) { | 735 | if (curlun->cdrom) { |
586 | num_sectors &= ~3; /* Reduce to a multiple of 2048 */ | 736 | min_sectors = 300; /* Smallest track is 300 frames */ |
587 | min_sectors = 300*4; /* Smallest track is 300 frames */ | 737 | if (num_sectors >= 256*60*75) { |
588 | if (num_sectors >= 256*60*75*4) { | 738 | num_sectors = 256*60*75 - 1; |
589 | num_sectors = (256*60*75 - 1) * 4; | ||
590 | LINFO(curlun, "file too big: %s\n", filename); | 739 | LINFO(curlun, "file too big: %s\n", filename); |
591 | LINFO(curlun, "using only first %d blocks\n", | 740 | LINFO(curlun, "using only first %d blocks\n", |
592 | (int) num_sectors); | 741 | (int) num_sectors); |
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index dfed4c1d96c0..29c854bbca44 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c | |||
@@ -9,15 +9,6 @@ | |||
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or | 10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. | 11 | * (at your option) any later version. |
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | 12 | */ |
22 | 13 | ||
23 | /* #define VERBOSE_DEBUG */ | 14 | /* #define VERBOSE_DEBUG */ |
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h index c966440ddd70..8012357e98aa 100644 --- a/drivers/usb/gadget/u_ether.h +++ b/drivers/usb/gadget/u_ether.h | |||
@@ -9,15 +9,6 @@ | |||
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or | 10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. | 11 | * (at your option) any later version. |
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | 12 | */ |
22 | 13 | ||
23 | #ifndef __U_ETHER_H | 14 | #ifndef __U_ETHER_H |
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c index a8aa46962d81..3a4a664bab44 100644 --- a/drivers/usb/gadget/u_serial.c +++ b/drivers/usb/gadget/u_serial.c | |||
@@ -552,9 +552,8 @@ recycle: | |||
552 | /* Push from tty to ldisc; without low_latency set this is handled by | 552 | /* Push from tty to ldisc; without low_latency set this is handled by |
553 | * a workqueue, so we won't get callbacks and can hold port_lock | 553 | * a workqueue, so we won't get callbacks and can hold port_lock |
554 | */ | 554 | */ |
555 | if (tty && do_push) { | 555 | if (tty && do_push) |
556 | tty_flip_buffer_push(tty); | 556 | tty_flip_buffer_push(tty); |
557 | } | ||
558 | 557 | ||
559 | 558 | ||
560 | /* We want our data queue to become empty ASAP, keeping data | 559 | /* We want our data queue to become empty ASAP, keeping data |
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c index 05ba47214361..022baeca7c94 100644 --- a/drivers/usb/gadget/udc-core.c +++ b/drivers/usb/gadget/udc-core.c | |||
@@ -356,7 +356,7 @@ static DEVICE_ATTR(srp, S_IWUSR, NULL, usb_udc_srp_store); | |||
356 | static ssize_t usb_udc_softconn_store(struct device *dev, | 356 | static ssize_t usb_udc_softconn_store(struct device *dev, |
357 | struct device_attribute *attr, const char *buf, size_t n) | 357 | struct device_attribute *attr, const char *buf, size_t n) |
358 | { | 358 | { |
359 | struct usb_udc *udc = dev_get_drvdata(dev); | 359 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); |
360 | 360 | ||
361 | if (sysfs_streq(buf, "connect")) { | 361 | if (sysfs_streq(buf, "connect")) { |
362 | usb_gadget_connect(udc->gadget); | 362 | usb_gadget_connect(udc->gadget); |
@@ -375,23 +375,8 @@ static ssize_t usb_udc_speed_show(struct device *dev, | |||
375 | struct device_attribute *attr, char *buf) | 375 | struct device_attribute *attr, char *buf) |
376 | { | 376 | { |
377 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); | 377 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); |
378 | struct usb_gadget *gadget = udc->gadget; | 378 | return snprintf(buf, PAGE_SIZE, "%s\n", |
379 | 379 | usb_speed_string(udc->gadget->speed)); | |
380 | switch (gadget->speed) { | ||
381 | case USB_SPEED_LOW: | ||
382 | return snprintf(buf, PAGE_SIZE, "low-speed\n"); | ||
383 | case USB_SPEED_FULL: | ||
384 | return snprintf(buf, PAGE_SIZE, "full-speed\n"); | ||
385 | case USB_SPEED_HIGH: | ||
386 | return snprintf(buf, PAGE_SIZE, "high-speed\n"); | ||
387 | case USB_SPEED_WIRELESS: | ||
388 | return snprintf(buf, PAGE_SIZE, "wireless\n"); | ||
389 | case USB_SPEED_SUPER: | ||
390 | return snprintf(buf, PAGE_SIZE, "super-speed\n"); | ||
391 | case USB_SPEED_UNKNOWN: /* FALLTHROUGH */ | ||
392 | default: | ||
393 | return snprintf(buf, PAGE_SIZE, "UNKNOWN\n"); | ||
394 | } | ||
395 | } | 380 | } |
396 | static DEVICE_ATTR(speed, S_IRUSR, usb_udc_speed_show, NULL); | 381 | static DEVICE_ATTR(speed, S_IRUSR, usb_udc_speed_show, NULL); |
397 | 382 | ||
diff --git a/drivers/usb/gadget/uvc.h b/drivers/usb/gadget/uvc.h index 81971fbc7ea5..bc78c606c12b 100644 --- a/drivers/usb/gadget/uvc.h +++ b/drivers/usb/gadget/uvc.h | |||
@@ -8,7 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
11 | * | ||
12 | */ | 11 | */ |
13 | 12 | ||
14 | #ifndef _UVC_GADGET_H_ | 13 | #ifndef _UVC_GADGET_H_ |
diff --git a/drivers/usb/gadget/uvc_queue.c b/drivers/usb/gadget/uvc_queue.c index aa0ad34e0f1f..d776adb2da67 100644 --- a/drivers/usb/gadget/uvc_queue.c +++ b/drivers/usb/gadget/uvc_queue.c | |||
@@ -8,7 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
11 | * | ||
12 | */ | 11 | */ |
13 | 12 | ||
14 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
diff --git a/drivers/usb/gadget/uvc_v4l2.c b/drivers/usb/gadget/uvc_v4l2.c index cfb58384394d..f6e083b50191 100644 --- a/drivers/usb/gadget/uvc_v4l2.c +++ b/drivers/usb/gadget/uvc_v4l2.c | |||
@@ -8,7 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
11 | * | ||
12 | */ | 11 | */ |
13 | 12 | ||
14 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
diff --git a/drivers/usb/gadget/uvc_video.c b/drivers/usb/gadget/uvc_video.c index b08f35438d70..b0e53a8ea4f7 100644 --- a/drivers/usb/gadget/uvc_video.c +++ b/drivers/usb/gadget/uvc_video.c | |||
@@ -8,7 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
11 | * | ||
12 | */ | 11 | */ |
13 | 12 | ||
14 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c index df6882de50bf..668fe128f2ef 100644 --- a/drivers/usb/gadget/webcam.c +++ b/drivers/usb/gadget/webcam.c | |||
@@ -8,8 +8,8 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
11 | * | ||
12 | */ | 11 | */ |
12 | |||
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/device.h> | 14 | #include <linux/device.h> |
15 | #include <linux/usb/video.h> | 15 | #include <linux/usb/video.h> |
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c index 00e2fd2d4791..20697cc132d1 100644 --- a/drivers/usb/gadget/zero.c +++ b/drivers/usb/gadget/zero.c | |||
@@ -8,15 +8,6 @@ | |||
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | 11 | */ |
21 | 12 | ||
22 | 13 | ||