diff options
author | Russell King <rmk+kernel@arm.linux.org.uk> | 2009-09-24 16:22:33 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2009-09-24 16:22:33 -0400 |
commit | baea7b946f00a291b166ccae7fcfed6c01530cc6 (patch) | |
tree | 4aa275fbdbec9c7b9b4629e8bee2bbecd3c6a6af /drivers/usb/gadget | |
parent | ae19ffbadc1b2100285a5b5b3d0a4e0a11390904 (diff) | |
parent | 94e0fb086fc5663c38bbc0fe86d698be8314f82f (diff) |
Merge branch 'origin' into for-linus
Conflicts:
MAINTAINERS
Diffstat (limited to 'drivers/usb/gadget')
32 files changed, 3037 insertions, 347 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 7f8e83a954ac..33351312327f 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -124,7 +124,7 @@ choice | |||
124 | 124 | ||
125 | config USB_GADGET_AT91 | 125 | config USB_GADGET_AT91 |
126 | boolean "Atmel AT91 USB Device Port" | 126 | boolean "Atmel AT91 USB Device Port" |
127 | depends on ARCH_AT91 && !ARCH_AT91SAM9RL && !ARCH_AT91CAP9 | 127 | depends on ARCH_AT91 && !ARCH_AT91SAM9RL && !ARCH_AT91CAP9 && !ARCH_AT91SAM9G45 |
128 | select USB_GADGET_SELECTED | 128 | select USB_GADGET_SELECTED |
129 | help | 129 | help |
130 | Many Atmel AT91 processors (such as the AT91RM2000) have a | 130 | Many Atmel AT91 processors (such as the AT91RM2000) have a |
@@ -143,7 +143,7 @@ config USB_AT91 | |||
143 | config USB_GADGET_ATMEL_USBA | 143 | config USB_GADGET_ATMEL_USBA |
144 | boolean "Atmel USBA" | 144 | boolean "Atmel USBA" |
145 | select USB_GADGET_DUALSPEED | 145 | select USB_GADGET_DUALSPEED |
146 | depends on AVR32 || ARCH_AT91CAP9 || ARCH_AT91SAM9RL | 146 | depends on AVR32 || ARCH_AT91CAP9 || ARCH_AT91SAM9RL || ARCH_AT91SAM9G45 |
147 | help | 147 | help |
148 | USBA is the integrated high-speed USB Device controller on | 148 | USBA is the integrated high-speed USB Device controller on |
149 | the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel. | 149 | the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel. |
@@ -251,6 +251,24 @@ config USB_PXA25X_SMALL | |||
251 | default y if USB_ETH | 251 | default y if USB_ETH |
252 | default y if USB_G_SERIAL | 252 | default y if USB_G_SERIAL |
253 | 253 | ||
254 | config USB_GADGET_R8A66597 | ||
255 | boolean "Renesas R8A66597 USB Peripheral Controller" | ||
256 | select USB_GADGET_DUALSPEED | ||
257 | help | ||
258 | R8A66597 is a discrete USB host and peripheral controller chip that | ||
259 | supports both full and high speed USB 2.0 data transfers. | ||
260 | It has nine configurable endpoints, and endpoint zero. | ||
261 | |||
262 | Say "y" to link the driver statically, or "m" to build a | ||
263 | dynamically linked module called "r8a66597_udc" and force all | ||
264 | gadget drivers to also be dynamically linked. | ||
265 | |||
266 | config USB_R8A66597 | ||
267 | tristate | ||
268 | depends on USB_GADGET_R8A66597 | ||
269 | default USB_GADGET | ||
270 | select USB_GADGET_SELECTED | ||
271 | |||
254 | config USB_GADGET_PXA27X | 272 | config USB_GADGET_PXA27X |
255 | boolean "PXA 27x" | 273 | boolean "PXA 27x" |
256 | depends on ARCH_PXA && (PXA27x || PXA3xx) | 274 | depends on ARCH_PXA && (PXA27x || PXA3xx) |
@@ -360,16 +378,6 @@ config USB_M66592 | |||
360 | default USB_GADGET | 378 | default USB_GADGET |
361 | select USB_GADGET_SELECTED | 379 | select USB_GADGET_SELECTED |
362 | 380 | ||
363 | config SUPERH_BUILT_IN_M66592 | ||
364 | boolean "Enable SuperH built-in USB like the M66592" | ||
365 | depends on USB_GADGET_M66592 && CPU_SUBTYPE_SH7722 | ||
366 | help | ||
367 | SH7722 has USB like the M66592. | ||
368 | |||
369 | The transfer rate is very slow when use "Ethernet Gadget". | ||
370 | However, this problem is improved if change a value of | ||
371 | NET_IP_ALIGN to 4. | ||
372 | |||
373 | # | 381 | # |
374 | # Controllers available only in discrete form (and all PCI controllers) | 382 | # Controllers available only in discrete form (and all PCI controllers) |
375 | # | 383 | # |
@@ -619,9 +627,10 @@ config USB_AUDIO | |||
619 | config USB_ETH | 627 | config USB_ETH |
620 | tristate "Ethernet Gadget (with CDC Ethernet support)" | 628 | tristate "Ethernet Gadget (with CDC Ethernet support)" |
621 | depends on NET | 629 | depends on NET |
630 | select CRC32 | ||
622 | help | 631 | help |
623 | This driver implements Ethernet style communication, in either | 632 | This driver implements Ethernet style communication, in one of |
624 | of two ways: | 633 | several ways: |
625 | 634 | ||
626 | - The "Communication Device Class" (CDC) Ethernet Control Model. | 635 | - The "Communication Device Class" (CDC) Ethernet Control Model. |
627 | That protocol is often avoided with pure Ethernet adapters, in | 636 | That protocol is often avoided with pure Ethernet adapters, in |
@@ -631,7 +640,11 @@ config USB_ETH | |||
631 | - On hardware can't implement that protocol, a simple CDC subset | 640 | - On hardware can't implement that protocol, a simple CDC subset |
632 | is used, placing fewer demands on USB. | 641 | is used, placing fewer demands on USB. |
633 | 642 | ||
634 | RNDIS support is a third option, more demanding than that subset. | 643 | - CDC Ethernet Emulation Model (EEM) is a newer standard that has |
644 | a simpler interface that can be used by more USB hardware. | ||
645 | |||
646 | RNDIS support is an additional option, more demanding than than | ||
647 | subset. | ||
635 | 648 | ||
636 | Within the USB device, this gadget driver exposes a network device | 649 | Within the USB device, this gadget driver exposes a network device |
637 | "usbX", where X depends on what other networking devices you have. | 650 | "usbX", where X depends on what other networking devices you have. |
@@ -664,6 +677,22 @@ config USB_ETH_RNDIS | |||
664 | XP, you'll need to download drivers from Microsoft's website; a URL | 677 | XP, you'll need to download drivers from Microsoft's website; a URL |
665 | is given in comments found in that info file. | 678 | is given in comments found in that info file. |
666 | 679 | ||
680 | config USB_ETH_EEM | ||
681 | bool "Ethernet Emulation Model (EEM) support" | ||
682 | depends on USB_ETH | ||
683 | default n | ||
684 | help | ||
685 | CDC EEM is a newer USB standard that is somewhat simpler than CDC ECM | ||
686 | and therefore can be supported by more hardware. Technically ECM and | ||
687 | EEM are designed for different applications. The ECM model extends | ||
688 | the network interface to the target (e.g. a USB cable modem), and the | ||
689 | EEM model is for mobile devices to communicate with hosts using | ||
690 | ethernet over USB. For Linux gadgets, however, the interface with | ||
691 | the host is the same (a usbX device), so the differences are minimal. | ||
692 | |||
693 | If you say "y" here, the Ethernet gadget driver will use the EEM | ||
694 | protocol rather than ECM. If unsure, say "n". | ||
695 | |||
667 | config USB_GADGETFS | 696 | config USB_GADGETFS |
668 | tristate "Gadget Filesystem (EXPERIMENTAL)" | 697 | tristate "Gadget Filesystem (EXPERIMENTAL)" |
669 | depends on EXPERIMENTAL | 698 | depends on EXPERIMENTAL |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index e6017e6bf6da..9d7b87c52e9f 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -23,6 +23,7 @@ ifeq ($(CONFIG_ARCH_MXC),y) | |||
23 | fsl_usb2_udc-objs += fsl_mx3_udc.o | 23 | fsl_usb2_udc-objs += fsl_mx3_udc.o |
24 | endif | 24 | endif |
25 | obj-$(CONFIG_USB_M66592) += m66592-udc.o | 25 | obj-$(CONFIG_USB_M66592) += m66592-udc.o |
26 | obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o | ||
26 | obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o | 27 | obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o |
27 | obj-$(CONFIG_USB_CI13XXX) += ci13xxx_udc.o | 28 | obj-$(CONFIG_USB_CI13XXX) += ci13xxx_udc.o |
28 | obj-$(CONFIG_USB_S3C_HSOTG) += s3c-hsotg.o | 29 | obj-$(CONFIG_USB_S3C_HSOTG) += s3c-hsotg.o |
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c index 77352ccc245e..d5b65962dd36 100644 --- a/drivers/usb/gadget/amd5536udc.c +++ b/drivers/usb/gadget/amd5536udc.c | |||
@@ -2378,40 +2378,34 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int ep_ix) | |||
2378 | if (!ep->cancel_transfer && !list_empty(&ep->queue)) { | 2378 | if (!ep->cancel_transfer && !list_empty(&ep->queue)) { |
2379 | req = list_entry(ep->queue.next, | 2379 | req = list_entry(ep->queue.next, |
2380 | struct udc_request, queue); | 2380 | struct udc_request, queue); |
2381 | if (req) { | 2381 | /* |
2382 | /* | 2382 | * length bytes transfered |
2383 | * length bytes transfered | 2383 | * check dma done of last desc. in PPBDU mode |
2384 | * check dma done of last desc. in PPBDU mode | 2384 | */ |
2385 | */ | 2385 | if (use_dma_ppb_du) { |
2386 | if (use_dma_ppb_du) { | 2386 | td = udc_get_last_dma_desc(req); |
2387 | td = udc_get_last_dma_desc(req); | 2387 | if (td) { |
2388 | if (td) { | 2388 | dma_done = |
2389 | dma_done = | 2389 | AMD_GETBITS(td->status, |
2390 | AMD_GETBITS(td->status, | 2390 | UDC_DMA_IN_STS_BS); |
2391 | UDC_DMA_IN_STS_BS); | 2391 | /* don't care DMA done */ |
2392 | /* don't care DMA done */ | ||
2393 | req->req.actual = | ||
2394 | req->req.length; | ||
2395 | } | ||
2396 | } else { | ||
2397 | /* assume all bytes transferred */ | ||
2398 | req->req.actual = req->req.length; | 2392 | req->req.actual = req->req.length; |
2399 | } | 2393 | } |
2394 | } else { | ||
2395 | /* assume all bytes transferred */ | ||
2396 | req->req.actual = req->req.length; | ||
2397 | } | ||
2400 | 2398 | ||
2401 | if (req->req.actual == req->req.length) { | 2399 | if (req->req.actual == req->req.length) { |
2402 | /* complete req */ | 2400 | /* complete req */ |
2403 | complete_req(ep, req, 0); | 2401 | complete_req(ep, req, 0); |
2404 | req->dma_going = 0; | 2402 | req->dma_going = 0; |
2405 | /* further request available ? */ | 2403 | /* further request available ? */ |
2406 | if (list_empty(&ep->queue)) { | 2404 | if (list_empty(&ep->queue)) { |
2407 | /* disable interrupt */ | 2405 | /* disable interrupt */ |
2408 | tmp = readl( | 2406 | tmp = readl(&dev->regs->ep_irqmsk); |
2409 | &dev->regs->ep_irqmsk); | 2407 | tmp |= AMD_BIT(ep->num); |
2410 | tmp |= AMD_BIT(ep->num); | 2408 | writel(tmp, &dev->regs->ep_irqmsk); |
2411 | writel(tmp, | ||
2412 | &dev->regs->ep_irqmsk); | ||
2413 | } | ||
2414 | |||
2415 | } | 2409 | } |
2416 | } | 2410 | } |
2417 | } | 2411 | } |
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index 72bae8f39d81..66450a1abc22 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c | |||
@@ -1754,7 +1754,6 @@ static int __init at91udc_probe(struct platform_device *pdev) | |||
1754 | IRQF_DISABLED, driver_name, udc)) { | 1754 | IRQF_DISABLED, driver_name, udc)) { |
1755 | DBG("request vbus irq %d failed\n", | 1755 | DBG("request vbus irq %d failed\n", |
1756 | udc->board.vbus_pin); | 1756 | udc->board.vbus_pin); |
1757 | free_irq(udc->udp_irq, udc); | ||
1758 | retval = -EBUSY; | 1757 | retval = -EBUSY; |
1759 | goto fail3; | 1758 | goto fail3; |
1760 | } | 1759 | } |
diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c index 9f80f4e970bd..a3a0f4a27ef0 100644 --- a/drivers/usb/gadget/audio.c +++ b/drivers/usb/gadget/audio.c | |||
@@ -106,20 +106,20 @@ static int audio_set_endpoint_req(struct usb_configuration *c, | |||
106 | ctrl->bRequest, w_value, len, ep); | 106 | ctrl->bRequest, w_value, len, ep); |
107 | 107 | ||
108 | switch (ctrl->bRequest) { | 108 | switch (ctrl->bRequest) { |
109 | case SET_CUR: | 109 | case UAC_SET_CUR: |
110 | value = 0; | 110 | value = 0; |
111 | break; | 111 | break; |
112 | 112 | ||
113 | case SET_MIN: | 113 | case UAC_SET_MIN: |
114 | break; | 114 | break; |
115 | 115 | ||
116 | case SET_MAX: | 116 | case UAC_SET_MAX: |
117 | break; | 117 | break; |
118 | 118 | ||
119 | case SET_RES: | 119 | case UAC_SET_RES: |
120 | break; | 120 | break; |
121 | 121 | ||
122 | case SET_MEM: | 122 | case UAC_SET_MEM: |
123 | break; | 123 | break; |
124 | 124 | ||
125 | default: | 125 | default: |
@@ -142,13 +142,13 @@ static int audio_get_endpoint_req(struct usb_configuration *c, | |||
142 | ctrl->bRequest, w_value, len, ep); | 142 | ctrl->bRequest, w_value, len, ep); |
143 | 143 | ||
144 | switch (ctrl->bRequest) { | 144 | switch (ctrl->bRequest) { |
145 | case GET_CUR: | 145 | case UAC_GET_CUR: |
146 | case GET_MIN: | 146 | case UAC_GET_MIN: |
147 | case GET_MAX: | 147 | case UAC_GET_MAX: |
148 | case GET_RES: | 148 | case UAC_GET_RES: |
149 | value = 3; | 149 | value = 3; |
150 | break; | 150 | break; |
151 | case GET_MEM: | 151 | case UAC_GET_MEM: |
152 | break; | 152 | break; |
153 | default: | 153 | default: |
154 | break; | 154 | break; |
@@ -171,11 +171,11 @@ audio_setup(struct usb_configuration *c, const struct usb_ctrlrequest *ctrl) | |||
171 | * Audio class messages; interface activation uses set_alt(). | 171 | * Audio class messages; interface activation uses set_alt(). |
172 | */ | 172 | */ |
173 | switch (ctrl->bRequestType) { | 173 | switch (ctrl->bRequestType) { |
174 | case USB_AUDIO_SET_ENDPOINT: | 174 | case USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT: |
175 | value = audio_set_endpoint_req(c, ctrl); | 175 | value = audio_set_endpoint_req(c, ctrl); |
176 | break; | 176 | break; |
177 | 177 | ||
178 | case USB_AUDIO_GET_ENDPOINT: | 178 | case USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_ENDPOINT: |
179 | value = audio_get_endpoint_req(c, ctrl); | 179 | value = audio_get_endpoint_req(c, ctrl); |
180 | break; | 180 | break; |
181 | 181 | ||
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 59e85234fa0a..d05397ec8a18 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -602,7 +602,7 @@ static int get_string(struct usb_composite_dev *cdev, | |||
602 | } | 602 | } |
603 | } | 603 | } |
604 | 604 | ||
605 | for (len = 0; s->wData[len] && len <= 126; len++) | 605 | for (len = 0; len <= 126 && s->wData[len]; len++) |
606 | continue; | 606 | continue; |
607 | if (!len) | 607 | if (!len) |
608 | return -EINVAL; | 608 | return -EINVAL; |
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index a56b24d305f8..5e0966485188 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c | |||
@@ -1306,11 +1306,6 @@ restart: | |||
1306 | setup = *(struct usb_ctrlrequest*) urb->setup_packet; | 1306 | setup = *(struct usb_ctrlrequest*) urb->setup_packet; |
1307 | w_index = le16_to_cpu(setup.wIndex); | 1307 | w_index = le16_to_cpu(setup.wIndex); |
1308 | w_value = le16_to_cpu(setup.wValue); | 1308 | w_value = le16_to_cpu(setup.wValue); |
1309 | if (le16_to_cpu(setup.wLength) != | ||
1310 | urb->transfer_buffer_length) { | ||
1311 | status = -EOVERFLOW; | ||
1312 | goto return_urb; | ||
1313 | } | ||
1314 | 1309 | ||
1315 | /* paranoia, in case of stale queued data */ | 1310 | /* paranoia, in case of stale queued data */ |
1316 | list_for_each_entry (req, &ep->queue, queue) { | 1311 | list_for_each_entry (req, &ep->queue, queue) { |
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index bd102f5052ba..f37de283d0ab 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c | |||
@@ -61,6 +61,11 @@ | |||
61 | * simpler, Microsoft pushes their own approach: RNDIS. The published | 61 | * simpler, Microsoft pushes their own approach: RNDIS. The published |
62 | * RNDIS specs are ambiguous and appear to be incomplete, and are also | 62 | * RNDIS specs are ambiguous and appear to be incomplete, and are also |
63 | * needlessly complex. They borrow more from CDC ACM than CDC ECM. | 63 | * needlessly complex. They borrow more from CDC ACM than CDC ECM. |
64 | * | ||
65 | * While CDC ECM, CDC Subset, and RNDIS are designed to extend the ethernet | ||
66 | * interface to the target, CDC EEM was designed to use ethernet over the USB | ||
67 | * link between the host and target. CDC EEM is implemented as an alternative | ||
68 | * to those other protocols when that communication model is more appropriate | ||
64 | */ | 69 | */ |
65 | 70 | ||
66 | #define DRIVER_DESC "Ethernet Gadget" | 71 | #define DRIVER_DESC "Ethernet Gadget" |
@@ -114,6 +119,7 @@ static inline bool has_rndis(void) | |||
114 | #include "f_rndis.c" | 119 | #include "f_rndis.c" |
115 | #include "rndis.c" | 120 | #include "rndis.c" |
116 | #endif | 121 | #endif |
122 | #include "f_eem.c" | ||
117 | #include "u_ether.c" | 123 | #include "u_ether.c" |
118 | 124 | ||
119 | /*-------------------------------------------------------------------------*/ | 125 | /*-------------------------------------------------------------------------*/ |
@@ -150,6 +156,10 @@ static inline bool has_rndis(void) | |||
150 | #define RNDIS_VENDOR_NUM 0x0525 /* NetChip */ | 156 | #define RNDIS_VENDOR_NUM 0x0525 /* NetChip */ |
151 | #define RNDIS_PRODUCT_NUM 0xa4a2 /* Ethernet/RNDIS Gadget */ | 157 | #define RNDIS_PRODUCT_NUM 0xa4a2 /* Ethernet/RNDIS Gadget */ |
152 | 158 | ||
159 | /* For EEM gadgets */ | ||
160 | #define EEM_VENDOR_NUM 0x0525 /* INVALID - NEEDS TO BE ALLOCATED */ | ||
161 | #define EEM_PRODUCT_NUM 0xa4a1 /* INVALID - NEEDS TO BE ALLOCATED */ | ||
162 | |||
153 | /*-------------------------------------------------------------------------*/ | 163 | /*-------------------------------------------------------------------------*/ |
154 | 164 | ||
155 | static struct usb_device_descriptor device_desc = { | 165 | static struct usb_device_descriptor device_desc = { |
@@ -246,8 +256,16 @@ static struct usb_configuration rndis_config_driver = { | |||
246 | 256 | ||
247 | /*-------------------------------------------------------------------------*/ | 257 | /*-------------------------------------------------------------------------*/ |
248 | 258 | ||
259 | #ifdef CONFIG_USB_ETH_EEM | ||
260 | static int use_eem = 1; | ||
261 | #else | ||
262 | static int use_eem; | ||
263 | #endif | ||
264 | module_param(use_eem, bool, 0); | ||
265 | MODULE_PARM_DESC(use_eem, "use CDC EEM mode"); | ||
266 | |||
249 | /* | 267 | /* |
250 | * We _always_ have an ECM or CDC Subset configuration. | 268 | * We _always_ have an ECM, CDC Subset, or EEM configuration. |
251 | */ | 269 | */ |
252 | static int __init eth_do_config(struct usb_configuration *c) | 270 | static int __init eth_do_config(struct usb_configuration *c) |
253 | { | 271 | { |
@@ -258,7 +276,9 @@ static int __init eth_do_config(struct usb_configuration *c) | |||
258 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 276 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
259 | } | 277 | } |
260 | 278 | ||
261 | if (can_support_ecm(c->cdev->gadget)) | 279 | if (use_eem) |
280 | return eem_bind_config(c); | ||
281 | else if (can_support_ecm(c->cdev->gadget)) | ||
262 | return ecm_bind_config(c, hostaddr); | 282 | return ecm_bind_config(c, hostaddr); |
263 | else | 283 | else |
264 | return geth_bind_config(c, hostaddr); | 284 | return geth_bind_config(c, hostaddr); |
@@ -286,7 +306,12 @@ static int __init eth_bind(struct usb_composite_dev *cdev) | |||
286 | return status; | 306 | return status; |
287 | 307 | ||
288 | /* set up main config label and device descriptor */ | 308 | /* set up main config label and device descriptor */ |
289 | if (can_support_ecm(cdev->gadget)) { | 309 | if (use_eem) { |
310 | /* EEM */ | ||
311 | eth_config_driver.label = "CDC Ethernet (EEM)"; | ||
312 | device_desc.idVendor = cpu_to_le16(EEM_VENDOR_NUM); | ||
313 | device_desc.idProduct = cpu_to_le16(EEM_PRODUCT_NUM); | ||
314 | } else if (can_support_ecm(cdev->gadget)) { | ||
290 | /* ECM */ | 315 | /* ECM */ |
291 | eth_config_driver.label = "CDC Ethernet (ECM)"; | 316 | eth_config_driver.label = "CDC Ethernet (ECM)"; |
292 | } else { | 317 | } else { |
diff --git a/drivers/usb/gadget/f_audio.c b/drivers/usb/gadget/f_audio.c index 66527ba2d2ea..98e9bb977291 100644 --- a/drivers/usb/gadget/f_audio.c +++ b/drivers/usb/gadget/f_audio.c | |||
@@ -28,6 +28,9 @@ static int audio_buf_size = 48000; | |||
28 | module_param(audio_buf_size, int, S_IRUGO); | 28 | module_param(audio_buf_size, int, S_IRUGO); |
29 | MODULE_PARM_DESC(audio_buf_size, "Audio buffer size"); | 29 | MODULE_PARM_DESC(audio_buf_size, "Audio buffer size"); |
30 | 30 | ||
31 | static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value); | ||
32 | static int generic_get_cmd(struct usb_audio_control *con, u8 cmd); | ||
33 | |||
31 | /* | 34 | /* |
32 | * DESCRIPTORS ... most are static, but strings and full | 35 | * DESCRIPTORS ... most are static, but strings and full |
33 | * configuration descriptors are built on demand. | 36 | * configuration descriptors are built on demand. |
@@ -50,16 +53,16 @@ static struct usb_interface_descriptor ac_interface_desc __initdata = { | |||
50 | .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL, | 53 | .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL, |
51 | }; | 54 | }; |
52 | 55 | ||
53 | DECLARE_USB_AC_HEADER_DESCRIPTOR(2); | 56 | DECLARE_UAC_AC_HEADER_DESCRIPTOR(2); |
54 | 57 | ||
55 | #define USB_DT_AC_HEADER_LENGH USB_DT_AC_HEADER_SIZE(F_AUDIO_NUM_INTERFACES) | 58 | #define UAC_DT_AC_HEADER_LENGTH UAC_DT_AC_HEADER_SIZE(F_AUDIO_NUM_INTERFACES) |
56 | /* B.3.2 Class-Specific AC Interface Descriptor */ | 59 | /* B.3.2 Class-Specific AC Interface Descriptor */ |
57 | static struct usb_ac_header_descriptor_2 ac_header_desc = { | 60 | static struct uac_ac_header_descriptor_2 ac_header_desc = { |
58 | .bLength = USB_DT_AC_HEADER_LENGH, | 61 | .bLength = UAC_DT_AC_HEADER_LENGTH, |
59 | .bDescriptorType = USB_DT_CS_INTERFACE, | 62 | .bDescriptorType = USB_DT_CS_INTERFACE, |
60 | .bDescriptorSubtype = HEADER, | 63 | .bDescriptorSubtype = UAC_HEADER, |
61 | .bcdADC = __constant_cpu_to_le16(0x0100), | 64 | .bcdADC = __constant_cpu_to_le16(0x0100), |
62 | .wTotalLength = __constant_cpu_to_le16(USB_DT_AC_HEADER_LENGH), | 65 | .wTotalLength = __constant_cpu_to_le16(UAC_DT_AC_HEADER_LENGTH), |
63 | .bInCollection = F_AUDIO_NUM_INTERFACES, | 66 | .bInCollection = F_AUDIO_NUM_INTERFACES, |
64 | .baInterfaceNr = { | 67 | .baInterfaceNr = { |
65 | [0] = F_AUDIO_AC_INTERFACE, | 68 | [0] = F_AUDIO_AC_INTERFACE, |
@@ -68,33 +71,33 @@ static struct usb_ac_header_descriptor_2 ac_header_desc = { | |||
68 | }; | 71 | }; |
69 | 72 | ||
70 | #define INPUT_TERMINAL_ID 1 | 73 | #define INPUT_TERMINAL_ID 1 |
71 | static struct usb_input_terminal_descriptor input_terminal_desc = { | 74 | static struct uac_input_terminal_descriptor input_terminal_desc = { |
72 | .bLength = USB_DT_AC_INPUT_TERMINAL_SIZE, | 75 | .bLength = UAC_DT_INPUT_TERMINAL_SIZE, |
73 | .bDescriptorType = USB_DT_CS_INTERFACE, | 76 | .bDescriptorType = USB_DT_CS_INTERFACE, |
74 | .bDescriptorSubtype = INPUT_TERMINAL, | 77 | .bDescriptorSubtype = UAC_INPUT_TERMINAL, |
75 | .bTerminalID = INPUT_TERMINAL_ID, | 78 | .bTerminalID = INPUT_TERMINAL_ID, |
76 | .wTerminalType = USB_AC_TERMINAL_STREAMING, | 79 | .wTerminalType = UAC_TERMINAL_STREAMING, |
77 | .bAssocTerminal = 0, | 80 | .bAssocTerminal = 0, |
78 | .wChannelConfig = 0x3, | 81 | .wChannelConfig = 0x3, |
79 | }; | 82 | }; |
80 | 83 | ||
81 | DECLARE_USB_AC_FEATURE_UNIT_DESCRIPTOR(0); | 84 | DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(0); |
82 | 85 | ||
83 | #define FEATURE_UNIT_ID 2 | 86 | #define FEATURE_UNIT_ID 2 |
84 | static struct usb_ac_feature_unit_descriptor_0 feature_unit_desc = { | 87 | static struct uac_feature_unit_descriptor_0 feature_unit_desc = { |
85 | .bLength = USB_DT_AC_FEATURE_UNIT_SIZE(0), | 88 | .bLength = UAC_DT_FEATURE_UNIT_SIZE(0), |
86 | .bDescriptorType = USB_DT_CS_INTERFACE, | 89 | .bDescriptorType = USB_DT_CS_INTERFACE, |
87 | .bDescriptorSubtype = FEATURE_UNIT, | 90 | .bDescriptorSubtype = UAC_FEATURE_UNIT, |
88 | .bUnitID = FEATURE_UNIT_ID, | 91 | .bUnitID = FEATURE_UNIT_ID, |
89 | .bSourceID = INPUT_TERMINAL_ID, | 92 | .bSourceID = INPUT_TERMINAL_ID, |
90 | .bControlSize = 2, | 93 | .bControlSize = 2, |
91 | .bmaControls[0] = (FU_MUTE | FU_VOLUME), | 94 | .bmaControls[0] = (UAC_FU_MUTE | UAC_FU_VOLUME), |
92 | }; | 95 | }; |
93 | 96 | ||
94 | static struct usb_audio_control mute_control = { | 97 | static struct usb_audio_control mute_control = { |
95 | .list = LIST_HEAD_INIT(mute_control.list), | 98 | .list = LIST_HEAD_INIT(mute_control.list), |
96 | .name = "Mute Control", | 99 | .name = "Mute Control", |
97 | .type = MUTE_CONTROL, | 100 | .type = UAC_MUTE_CONTROL, |
98 | /* Todo: add real Mute control code */ | 101 | /* Todo: add real Mute control code */ |
99 | .set = generic_set_cmd, | 102 | .set = generic_set_cmd, |
100 | .get = generic_get_cmd, | 103 | .get = generic_get_cmd, |
@@ -103,7 +106,7 @@ static struct usb_audio_control mute_control = { | |||
103 | static struct usb_audio_control volume_control = { | 106 | static struct usb_audio_control volume_control = { |
104 | .list = LIST_HEAD_INIT(volume_control.list), | 107 | .list = LIST_HEAD_INIT(volume_control.list), |
105 | .name = "Volume Control", | 108 | .name = "Volume Control", |
106 | .type = VOLUME_CONTROL, | 109 | .type = UAC_VOLUME_CONTROL, |
107 | /* Todo: add real Volume control code */ | 110 | /* Todo: add real Volume control code */ |
108 | .set = generic_set_cmd, | 111 | .set = generic_set_cmd, |
109 | .get = generic_get_cmd, | 112 | .get = generic_get_cmd, |
@@ -113,17 +116,17 @@ static struct usb_audio_control_selector feature_unit = { | |||
113 | .list = LIST_HEAD_INIT(feature_unit.list), | 116 | .list = LIST_HEAD_INIT(feature_unit.list), |
114 | .id = FEATURE_UNIT_ID, | 117 | .id = FEATURE_UNIT_ID, |
115 | .name = "Mute & Volume Control", | 118 | .name = "Mute & Volume Control", |
116 | .type = FEATURE_UNIT, | 119 | .type = UAC_FEATURE_UNIT, |
117 | .desc = (struct usb_descriptor_header *)&feature_unit_desc, | 120 | .desc = (struct usb_descriptor_header *)&feature_unit_desc, |
118 | }; | 121 | }; |
119 | 122 | ||
120 | #define OUTPUT_TERMINAL_ID 3 | 123 | #define OUTPUT_TERMINAL_ID 3 |
121 | static struct usb_output_terminal_descriptor output_terminal_desc = { | 124 | static struct uac_output_terminal_descriptor output_terminal_desc = { |
122 | .bLength = USB_DT_AC_OUTPUT_TERMINAL_SIZE, | 125 | .bLength = UAC_DT_OUTPUT_TERMINAL_SIZE, |
123 | .bDescriptorType = USB_DT_CS_INTERFACE, | 126 | .bDescriptorType = USB_DT_CS_INTERFACE, |
124 | .bDescriptorSubtype = OUTPUT_TERMINAL, | 127 | .bDescriptorSubtype = UAC_OUTPUT_TERMINAL, |
125 | .bTerminalID = OUTPUT_TERMINAL_ID, | 128 | .bTerminalID = OUTPUT_TERMINAL_ID, |
126 | .wTerminalType = USB_AC_OUTPUT_TERMINAL_SPEAKER, | 129 | .wTerminalType = UAC_OUTPUT_TERMINAL_SPEAKER, |
127 | .bAssocTerminal = FEATURE_UNIT_ID, | 130 | .bAssocTerminal = FEATURE_UNIT_ID, |
128 | .bSourceID = FEATURE_UNIT_ID, | 131 | .bSourceID = FEATURE_UNIT_ID, |
129 | }; | 132 | }; |
@@ -148,22 +151,22 @@ static struct usb_interface_descriptor as_interface_alt_1_desc = { | |||
148 | }; | 151 | }; |
149 | 152 | ||
150 | /* B.4.2 Class-Specific AS Interface Descriptor */ | 153 | /* B.4.2 Class-Specific AS Interface Descriptor */ |
151 | static struct usb_as_header_descriptor as_header_desc = { | 154 | static struct uac_as_header_descriptor as_header_desc = { |
152 | .bLength = USB_DT_AS_HEADER_SIZE, | 155 | .bLength = UAC_DT_AS_HEADER_SIZE, |
153 | .bDescriptorType = USB_DT_CS_INTERFACE, | 156 | .bDescriptorType = USB_DT_CS_INTERFACE, |
154 | .bDescriptorSubtype = AS_GENERAL, | 157 | .bDescriptorSubtype = UAC_AS_GENERAL, |
155 | .bTerminalLink = INPUT_TERMINAL_ID, | 158 | .bTerminalLink = INPUT_TERMINAL_ID, |
156 | .bDelay = 1, | 159 | .bDelay = 1, |
157 | .wFormatTag = USB_AS_AUDIO_FORMAT_TYPE_I_PCM, | 160 | .wFormatTag = UAC_FORMAT_TYPE_I_PCM, |
158 | }; | 161 | }; |
159 | 162 | ||
160 | DECLARE_USB_AS_FORMAT_TYPE_I_DISCRETE_DESC(1); | 163 | DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(1); |
161 | 164 | ||
162 | static struct usb_as_formate_type_i_discrete_descriptor_1 as_type_i_desc = { | 165 | static struct uac_format_type_i_discrete_descriptor_1 as_type_i_desc = { |
163 | .bLength = USB_AS_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(1), | 166 | .bLength = UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(1), |
164 | .bDescriptorType = USB_DT_CS_INTERFACE, | 167 | .bDescriptorType = USB_DT_CS_INTERFACE, |
165 | .bDescriptorSubtype = FORMAT_TYPE, | 168 | .bDescriptorSubtype = UAC_FORMAT_TYPE, |
166 | .bFormatType = USB_AS_FORMAT_TYPE_I, | 169 | .bFormatType = UAC_FORMAT_TYPE_I, |
167 | .bSubframeSize = 2, | 170 | .bSubframeSize = 2, |
168 | .bBitResolution = 16, | 171 | .bBitResolution = 16, |
169 | .bSamFreqType = 1, | 172 | .bSamFreqType = 1, |
@@ -174,17 +177,17 @@ static struct usb_endpoint_descriptor as_out_ep_desc __initdata = { | |||
174 | .bLength = USB_DT_ENDPOINT_AUDIO_SIZE, | 177 | .bLength = USB_DT_ENDPOINT_AUDIO_SIZE, |
175 | .bDescriptorType = USB_DT_ENDPOINT, | 178 | .bDescriptorType = USB_DT_ENDPOINT, |
176 | .bEndpointAddress = USB_DIR_OUT, | 179 | .bEndpointAddress = USB_DIR_OUT, |
177 | .bmAttributes = USB_AS_ENDPOINT_ADAPTIVE | 180 | .bmAttributes = USB_ENDPOINT_SYNC_ADAPTIVE |
178 | | USB_ENDPOINT_XFER_ISOC, | 181 | | USB_ENDPOINT_XFER_ISOC, |
179 | .wMaxPacketSize = __constant_cpu_to_le16(OUT_EP_MAX_PACKET_SIZE), | 182 | .wMaxPacketSize = __constant_cpu_to_le16(OUT_EP_MAX_PACKET_SIZE), |
180 | .bInterval = 4, | 183 | .bInterval = 4, |
181 | }; | 184 | }; |
182 | 185 | ||
183 | /* Class-specific AS ISO OUT Endpoint Descriptor */ | 186 | /* Class-specific AS ISO OUT Endpoint Descriptor */ |
184 | static struct usb_as_iso_endpoint_descriptor as_iso_out_desc __initdata = { | 187 | static struct uac_iso_endpoint_descriptor as_iso_out_desc __initdata = { |
185 | .bLength = USB_AS_ISO_ENDPOINT_DESC_SIZE, | 188 | .bLength = UAC_ISO_ENDPOINT_DESC_SIZE, |
186 | .bDescriptorType = USB_DT_CS_ENDPOINT, | 189 | .bDescriptorType = USB_DT_CS_ENDPOINT, |
187 | .bDescriptorSubtype = EP_GENERAL, | 190 | .bDescriptorSubtype = UAC_EP_GENERAL, |
188 | .bmAttributes = 1, | 191 | .bmAttributes = 1, |
189 | .bLockDelayUnits = 1, | 192 | .bLockDelayUnits = 1, |
190 | .wLockDelay = __constant_cpu_to_le16(1), | 193 | .wLockDelay = __constant_cpu_to_le16(1), |
@@ -456,11 +459,11 @@ f_audio_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) | |||
456 | * Audio class messages; interface activation uses set_alt(). | 459 | * Audio class messages; interface activation uses set_alt(). |
457 | */ | 460 | */ |
458 | switch (ctrl->bRequestType) { | 461 | switch (ctrl->bRequestType) { |
459 | case USB_AUDIO_SET_INTF: | 462 | case USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE: |
460 | value = audio_set_intf_req(f, ctrl); | 463 | value = audio_set_intf_req(f, ctrl); |
461 | break; | 464 | break; |
462 | 465 | ||
463 | case USB_AUDIO_GET_INTF: | 466 | case USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE: |
464 | value = audio_get_intf_req(f, ctrl); | 467 | value = audio_get_intf_req(f, ctrl); |
465 | break; | 468 | break; |
466 | 469 | ||
@@ -632,6 +635,18 @@ f_audio_unbind(struct usb_configuration *c, struct usb_function *f) | |||
632 | 635 | ||
633 | /*-------------------------------------------------------------------------*/ | 636 | /*-------------------------------------------------------------------------*/ |
634 | 637 | ||
638 | static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value) | ||
639 | { | ||
640 | con->data[cmd] = value; | ||
641 | |||
642 | return 0; | ||
643 | } | ||
644 | |||
645 | static int generic_get_cmd(struct usb_audio_control *con, u8 cmd) | ||
646 | { | ||
647 | return con->data[cmd]; | ||
648 | } | ||
649 | |||
635 | /* Todo: add more control selecotor dynamically */ | 650 | /* Todo: add more control selecotor dynamically */ |
636 | int __init control_selector_init(struct f_audio *audio) | 651 | int __init control_selector_init(struct f_audio *audio) |
637 | { | 652 | { |
@@ -642,10 +657,10 @@ int __init control_selector_init(struct f_audio *audio) | |||
642 | list_add(&mute_control.list, &feature_unit.control); | 657 | list_add(&mute_control.list, &feature_unit.control); |
643 | list_add(&volume_control.list, &feature_unit.control); | 658 | list_add(&volume_control.list, &feature_unit.control); |
644 | 659 | ||
645 | volume_control.data[_CUR] = 0xffc0; | 660 | volume_control.data[UAC__CUR] = 0xffc0; |
646 | volume_control.data[_MIN] = 0xe3a0; | 661 | volume_control.data[UAC__MIN] = 0xe3a0; |
647 | volume_control.data[_MAX] = 0xfff0; | 662 | volume_control.data[UAC__MAX] = 0xfff0; |
648 | volume_control.data[_RES] = 0x0030; | 663 | volume_control.data[UAC__RES] = 0x0030; |
649 | 664 | ||
650 | return 0; | 665 | return 0; |
651 | } | 666 | } |
diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c new file mode 100644 index 000000000000..0a577d5694fd --- /dev/null +++ b/drivers/usb/gadget/f_eem.c | |||
@@ -0,0 +1,562 @@ | |||
1 | /* | ||
2 | * f_eem.c -- USB CDC Ethernet (EEM) link function driver | ||
3 | * | ||
4 | * Copyright (C) 2003-2005,2008 David Brownell | ||
5 | * Copyright (C) 2008 Nokia Corporation | ||
6 | * Copyright (C) 2009 EF Johnson Technologies | ||
7 | * | ||
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 | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
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 | |||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/device.h> | ||
25 | #include <linux/etherdevice.h> | ||
26 | #include <linux/crc32.h> | ||
27 | |||
28 | #include "u_ether.h" | ||
29 | |||
30 | #define EEM_HLEN 2 | ||
31 | |||
32 | /* | ||
33 | * This function is a "CDC Ethernet Emulation Model" (CDC EEM) | ||
34 | * Ethernet link. | ||
35 | */ | ||
36 | |||
37 | struct eem_ep_descs { | ||
38 | struct usb_endpoint_descriptor *in; | ||
39 | struct usb_endpoint_descriptor *out; | ||
40 | }; | ||
41 | |||
42 | struct f_eem { | ||
43 | struct gether port; | ||
44 | u8 ctrl_id; | ||
45 | |||
46 | struct eem_ep_descs fs; | ||
47 | struct eem_ep_descs hs; | ||
48 | }; | ||
49 | |||
50 | static inline struct f_eem *func_to_eem(struct usb_function *f) | ||
51 | { | ||
52 | return container_of(f, struct f_eem, port.func); | ||
53 | } | ||
54 | |||
55 | /*-------------------------------------------------------------------------*/ | ||
56 | |||
57 | /* interface descriptor: */ | ||
58 | |||
59 | static struct usb_interface_descriptor eem_intf __initdata = { | ||
60 | .bLength = sizeof eem_intf, | ||
61 | .bDescriptorType = USB_DT_INTERFACE, | ||
62 | |||
63 | /* .bInterfaceNumber = DYNAMIC */ | ||
64 | .bNumEndpoints = 2, | ||
65 | .bInterfaceClass = USB_CLASS_COMM, | ||
66 | .bInterfaceSubClass = USB_CDC_SUBCLASS_EEM, | ||
67 | .bInterfaceProtocol = USB_CDC_PROTO_EEM, | ||
68 | /* .iInterface = DYNAMIC */ | ||
69 | }; | ||
70 | |||
71 | /* full speed support: */ | ||
72 | |||
73 | static struct usb_endpoint_descriptor eem_fs_in_desc __initdata = { | ||
74 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
75 | .bDescriptorType = USB_DT_ENDPOINT, | ||
76 | |||
77 | .bEndpointAddress = USB_DIR_IN, | ||
78 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
79 | }; | ||
80 | |||
81 | static struct usb_endpoint_descriptor eem_fs_out_desc __initdata = { | ||
82 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
83 | .bDescriptorType = USB_DT_ENDPOINT, | ||
84 | |||
85 | .bEndpointAddress = USB_DIR_OUT, | ||
86 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
87 | }; | ||
88 | |||
89 | static struct usb_descriptor_header *eem_fs_function[] __initdata = { | ||
90 | /* CDC EEM control descriptors */ | ||
91 | (struct usb_descriptor_header *) &eem_intf, | ||
92 | (struct usb_descriptor_header *) &eem_fs_in_desc, | ||
93 | (struct usb_descriptor_header *) &eem_fs_out_desc, | ||
94 | NULL, | ||
95 | }; | ||
96 | |||
97 | /* high speed support: */ | ||
98 | |||
99 | static struct usb_endpoint_descriptor eem_hs_in_desc __initdata = { | ||
100 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
101 | .bDescriptorType = USB_DT_ENDPOINT, | ||
102 | |||
103 | .bEndpointAddress = USB_DIR_IN, | ||
104 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
105 | .wMaxPacketSize = cpu_to_le16(512), | ||
106 | }; | ||
107 | |||
108 | static struct usb_endpoint_descriptor eem_hs_out_desc __initdata = { | ||
109 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
110 | .bDescriptorType = USB_DT_ENDPOINT, | ||
111 | |||
112 | .bEndpointAddress = USB_DIR_OUT, | ||
113 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
114 | .wMaxPacketSize = cpu_to_le16(512), | ||
115 | }; | ||
116 | |||
117 | static struct usb_descriptor_header *eem_hs_function[] __initdata = { | ||
118 | /* CDC EEM control descriptors */ | ||
119 | (struct usb_descriptor_header *) &eem_intf, | ||
120 | (struct usb_descriptor_header *) &eem_hs_in_desc, | ||
121 | (struct usb_descriptor_header *) &eem_hs_out_desc, | ||
122 | NULL, | ||
123 | }; | ||
124 | |||
125 | /* string descriptors: */ | ||
126 | |||
127 | static struct usb_string eem_string_defs[] = { | ||
128 | [0].s = "CDC Ethernet Emulation Model (EEM)", | ||
129 | { } /* end of list */ | ||
130 | }; | ||
131 | |||
132 | static struct usb_gadget_strings eem_string_table = { | ||
133 | .language = 0x0409, /* en-us */ | ||
134 | .strings = eem_string_defs, | ||
135 | }; | ||
136 | |||
137 | static struct usb_gadget_strings *eem_strings[] = { | ||
138 | &eem_string_table, | ||
139 | NULL, | ||
140 | }; | ||
141 | |||
142 | /*-------------------------------------------------------------------------*/ | ||
143 | |||
144 | static int eem_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) | ||
145 | { | ||
146 | struct usb_composite_dev *cdev = f->config->cdev; | ||
147 | int value = -EOPNOTSUPP; | ||
148 | u16 w_index = le16_to_cpu(ctrl->wIndex); | ||
149 | u16 w_value = le16_to_cpu(ctrl->wValue); | ||
150 | u16 w_length = le16_to_cpu(ctrl->wLength); | ||
151 | |||
152 | DBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n", | ||
153 | ctrl->bRequestType, ctrl->bRequest, | ||
154 | w_value, w_index, w_length); | ||
155 | |||
156 | /* device either stalls (value < 0) or reports success */ | ||
157 | return value; | ||
158 | } | ||
159 | |||
160 | |||
161 | static int eem_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | ||
162 | { | ||
163 | struct f_eem *eem = func_to_eem(f); | ||
164 | struct usb_composite_dev *cdev = f->config->cdev; | ||
165 | struct net_device *net; | ||
166 | |||
167 | /* we know alt == 0, so this is an activation or a reset */ | ||
168 | if (alt != 0) | ||
169 | goto fail; | ||
170 | |||
171 | if (intf == eem->ctrl_id) { | ||
172 | |||
173 | if (eem->port.in_ep->driver_data) { | ||
174 | DBG(cdev, "reset eem\n"); | ||
175 | gether_disconnect(&eem->port); | ||
176 | } | ||
177 | |||
178 | if (!eem->port.in) { | ||
179 | DBG(cdev, "init eem\n"); | ||
180 | eem->port.in = ep_choose(cdev->gadget, | ||
181 | eem->hs.in, eem->fs.in); | ||
182 | eem->port.out = ep_choose(cdev->gadget, | ||
183 | eem->hs.out, eem->fs.out); | ||
184 | } | ||
185 | |||
186 | /* zlps should not occur because zero-length EEM packets | ||
187 | * will be inserted in those cases where they would occur | ||
188 | */ | ||
189 | eem->port.is_zlp_ok = 1; | ||
190 | eem->port.cdc_filter = DEFAULT_FILTER; | ||
191 | DBG(cdev, "activate eem\n"); | ||
192 | net = gether_connect(&eem->port); | ||
193 | if (IS_ERR(net)) | ||
194 | return PTR_ERR(net); | ||
195 | } else | ||
196 | goto fail; | ||
197 | |||
198 | return 0; | ||
199 | fail: | ||
200 | return -EINVAL; | ||
201 | } | ||
202 | |||
203 | static void eem_disable(struct usb_function *f) | ||
204 | { | ||
205 | struct f_eem *eem = func_to_eem(f); | ||
206 | struct usb_composite_dev *cdev = f->config->cdev; | ||
207 | |||
208 | DBG(cdev, "eem deactivated\n"); | ||
209 | |||
210 | if (eem->port.in_ep->driver_data) | ||
211 | gether_disconnect(&eem->port); | ||
212 | } | ||
213 | |||
214 | /*-------------------------------------------------------------------------*/ | ||
215 | |||
216 | /* EEM function driver setup/binding */ | ||
217 | |||
218 | static int __init | ||
219 | eem_bind(struct usb_configuration *c, struct usb_function *f) | ||
220 | { | ||
221 | struct usb_composite_dev *cdev = c->cdev; | ||
222 | struct f_eem *eem = func_to_eem(f); | ||
223 | int status; | ||
224 | struct usb_ep *ep; | ||
225 | |||
226 | /* allocate instance-specific interface IDs */ | ||
227 | status = usb_interface_id(c, f); | ||
228 | if (status < 0) | ||
229 | goto fail; | ||
230 | eem->ctrl_id = status; | ||
231 | eem_intf.bInterfaceNumber = status; | ||
232 | |||
233 | status = -ENODEV; | ||
234 | |||
235 | /* allocate instance-specific endpoints */ | ||
236 | ep = usb_ep_autoconfig(cdev->gadget, &eem_fs_in_desc); | ||
237 | if (!ep) | ||
238 | goto fail; | ||
239 | eem->port.in_ep = ep; | ||
240 | ep->driver_data = cdev; /* claim */ | ||
241 | |||
242 | ep = usb_ep_autoconfig(cdev->gadget, &eem_fs_out_desc); | ||
243 | if (!ep) | ||
244 | goto fail; | ||
245 | eem->port.out_ep = ep; | ||
246 | ep->driver_data = cdev; /* claim */ | ||
247 | |||
248 | status = -ENOMEM; | ||
249 | |||
250 | /* copy descriptors, and track endpoint copies */ | ||
251 | f->descriptors = usb_copy_descriptors(eem_fs_function); | ||
252 | if (!f->descriptors) | ||
253 | goto fail; | ||
254 | |||
255 | eem->fs.in = usb_find_endpoint(eem_fs_function, | ||
256 | f->descriptors, &eem_fs_in_desc); | ||
257 | eem->fs.out = usb_find_endpoint(eem_fs_function, | ||
258 | f->descriptors, &eem_fs_out_desc); | ||
259 | |||
260 | /* support all relevant hardware speeds... we expect that when | ||
261 | * hardware is dual speed, all bulk-capable endpoints work at | ||
262 | * both speeds | ||
263 | */ | ||
264 | if (gadget_is_dualspeed(c->cdev->gadget)) { | ||
265 | eem_hs_in_desc.bEndpointAddress = | ||
266 | eem_fs_in_desc.bEndpointAddress; | ||
267 | eem_hs_out_desc.bEndpointAddress = | ||
268 | eem_fs_out_desc.bEndpointAddress; | ||
269 | |||
270 | /* copy descriptors, and track endpoint copies */ | ||
271 | f->hs_descriptors = usb_copy_descriptors(eem_hs_function); | ||
272 | if (!f->hs_descriptors) | ||
273 | goto fail; | ||
274 | |||
275 | eem->hs.in = usb_find_endpoint(eem_hs_function, | ||
276 | f->hs_descriptors, &eem_hs_in_desc); | ||
277 | eem->hs.out = usb_find_endpoint(eem_hs_function, | ||
278 | f->hs_descriptors, &eem_hs_out_desc); | ||
279 | } | ||
280 | |||
281 | DBG(cdev, "CDC Ethernet (EEM): %s speed IN/%s OUT/%s\n", | ||
282 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", | ||
283 | eem->port.in_ep->name, eem->port.out_ep->name); | ||
284 | return 0; | ||
285 | |||
286 | fail: | ||
287 | if (f->descriptors) | ||
288 | usb_free_descriptors(f->descriptors); | ||
289 | |||
290 | /* we might as well release our claims on endpoints */ | ||
291 | if (eem->port.out) | ||
292 | eem->port.out_ep->driver_data = NULL; | ||
293 | if (eem->port.in) | ||
294 | eem->port.in_ep->driver_data = NULL; | ||
295 | |||
296 | ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); | ||
297 | |||
298 | return status; | ||
299 | } | ||
300 | |||
301 | static void | ||
302 | eem_unbind(struct usb_configuration *c, struct usb_function *f) | ||
303 | { | ||
304 | struct f_eem *eem = func_to_eem(f); | ||
305 | |||
306 | DBG(c->cdev, "eem unbind\n"); | ||
307 | |||
308 | if (gadget_is_dualspeed(c->cdev->gadget)) | ||
309 | usb_free_descriptors(f->hs_descriptors); | ||
310 | usb_free_descriptors(f->descriptors); | ||
311 | kfree(eem); | ||
312 | } | ||
313 | |||
314 | static void eem_cmd_complete(struct usb_ep *ep, struct usb_request *req) | ||
315 | { | ||
316 | } | ||
317 | |||
318 | /* | ||
319 | * Add the EEM header and ethernet checksum. | ||
320 | * We currently do not attempt to put multiple ethernet frames | ||
321 | * into a single USB transfer | ||
322 | */ | ||
323 | static struct sk_buff *eem_wrap(struct gether *port, struct sk_buff *skb) | ||
324 | { | ||
325 | struct sk_buff *skb2 = NULL; | ||
326 | struct usb_ep *in = port->in_ep; | ||
327 | int padlen = 0; | ||
328 | u16 len = skb->len; | ||
329 | |||
330 | if (!skb_cloned(skb)) { | ||
331 | int headroom = skb_headroom(skb); | ||
332 | int tailroom = skb_tailroom(skb); | ||
333 | |||
334 | /* When (len + EEM_HLEN + ETH_FCS_LEN) % in->maxpacket) is 0, | ||
335 | * stick two bytes of zero-length EEM packet on the end. | ||
336 | */ | ||
337 | if (((len + EEM_HLEN + ETH_FCS_LEN) % in->maxpacket) == 0) | ||
338 | padlen += 2; | ||
339 | |||
340 | if ((tailroom >= (ETH_FCS_LEN + padlen)) && | ||
341 | (headroom >= EEM_HLEN)) | ||
342 | goto done; | ||
343 | } | ||
344 | |||
345 | skb2 = skb_copy_expand(skb, EEM_HLEN, ETH_FCS_LEN + padlen, GFP_ATOMIC); | ||
346 | dev_kfree_skb_any(skb); | ||
347 | skb = skb2; | ||
348 | if (!skb) | ||
349 | return skb; | ||
350 | |||
351 | done: | ||
352 | /* use the "no CRC" option */ | ||
353 | put_unaligned_be32(0xdeadbeef, skb_put(skb, 4)); | ||
354 | |||
355 | /* EEM packet header format: | ||
356 | * b0..13: length of ethernet frame | ||
357 | * b14: bmCRC (0 == sentinel CRC) | ||
358 | * b15: bmType (0 == data) | ||
359 | */ | ||
360 | len = skb->len; | ||
361 | put_unaligned_le16((len & 0x3FFF) | BIT(14), skb_push(skb, 2)); | ||
362 | |||
363 | /* add a zero-length EEM packet, if needed */ | ||
364 | if (padlen) | ||
365 | put_unaligned_le16(0, skb_put(skb, 2)); | ||
366 | |||
367 | return skb; | ||
368 | } | ||
369 | |||
370 | /* | ||
371 | * Remove the EEM header. Note that there can be many EEM packets in a single | ||
372 | * USB transfer, so we need to break them out and handle them independently. | ||
373 | */ | ||
374 | static int eem_unwrap(struct gether *port, | ||
375 | struct sk_buff *skb, | ||
376 | struct sk_buff_head *list) | ||
377 | { | ||
378 | struct usb_composite_dev *cdev = port->func.config->cdev; | ||
379 | int status = 0; | ||
380 | |||
381 | do { | ||
382 | struct sk_buff *skb2; | ||
383 | u16 header; | ||
384 | u16 len = 0; | ||
385 | |||
386 | if (skb->len < EEM_HLEN) { | ||
387 | status = -EINVAL; | ||
388 | DBG(cdev, "invalid EEM header\n"); | ||
389 | goto error; | ||
390 | } | ||
391 | |||
392 | /* remove the EEM header */ | ||
393 | header = get_unaligned_le16(skb->data); | ||
394 | skb_pull(skb, EEM_HLEN); | ||
395 | |||
396 | /* EEM packet header format: | ||
397 | * b0..14: EEM type dependent (data or command) | ||
398 | * b15: bmType (0 == data, 1 == command) | ||
399 | */ | ||
400 | if (header & BIT(15)) { | ||
401 | struct usb_request *req = cdev->req; | ||
402 | u16 bmEEMCmd; | ||
403 | |||
404 | /* EEM command packet format: | ||
405 | * b0..10: bmEEMCmdParam | ||
406 | * b11..13: bmEEMCmd | ||
407 | * b14: reserved (must be zero) | ||
408 | * b15: bmType (1 == command) | ||
409 | */ | ||
410 | if (header & BIT(14)) | ||
411 | continue; | ||
412 | |||
413 | bmEEMCmd = (header >> 11) & 0x7; | ||
414 | switch (bmEEMCmd) { | ||
415 | case 0: /* echo */ | ||
416 | len = header & 0x7FF; | ||
417 | if (skb->len < len) { | ||
418 | status = -EOVERFLOW; | ||
419 | goto error; | ||
420 | } | ||
421 | |||
422 | skb2 = skb_clone(skb, GFP_ATOMIC); | ||
423 | if (unlikely(!skb2)) { | ||
424 | DBG(cdev, "EEM echo response error\n"); | ||
425 | goto next; | ||
426 | } | ||
427 | skb_trim(skb2, len); | ||
428 | put_unaligned_le16(BIT(15) | BIT(11) | len, | ||
429 | skb_push(skb2, 2)); | ||
430 | skb_copy_bits(skb, 0, req->buf, skb->len); | ||
431 | req->length = skb->len; | ||
432 | req->complete = eem_cmd_complete; | ||
433 | req->zero = 1; | ||
434 | if (usb_ep_queue(port->in_ep, req, GFP_ATOMIC)) | ||
435 | DBG(cdev, "echo response queue fail\n"); | ||
436 | break; | ||
437 | |||
438 | case 1: /* echo response */ | ||
439 | case 2: /* suspend hint */ | ||
440 | case 3: /* response hint */ | ||
441 | case 4: /* response complete hint */ | ||
442 | case 5: /* tickle */ | ||
443 | default: /* reserved */ | ||
444 | continue; | ||
445 | } | ||
446 | } else { | ||
447 | u32 crc, crc2; | ||
448 | struct sk_buff *skb3; | ||
449 | |||
450 | /* check for zero-length EEM packet */ | ||
451 | if (header == 0) | ||
452 | continue; | ||
453 | |||
454 | /* EEM data packet format: | ||
455 | * b0..13: length of ethernet frame | ||
456 | * b14: bmCRC (0 == sentinel, 1 == calculated) | ||
457 | * b15: bmType (0 == data) | ||
458 | */ | ||
459 | len = header & 0x3FFF; | ||
460 | if ((skb->len < len) | ||
461 | || (len < (ETH_HLEN + ETH_FCS_LEN))) { | ||
462 | status = -EINVAL; | ||
463 | goto error; | ||
464 | } | ||
465 | |||
466 | /* validate CRC */ | ||
467 | crc = get_unaligned_le32(skb->data + len - ETH_FCS_LEN); | ||
468 | if (header & BIT(14)) { | ||
469 | crc = get_unaligned_le32(skb->data + len | ||
470 | - ETH_FCS_LEN); | ||
471 | crc2 = ~crc32_le(~0, | ||
472 | skb->data, | ||
473 | skb->len - ETH_FCS_LEN); | ||
474 | } else { | ||
475 | crc = get_unaligned_be32(skb->data + len | ||
476 | - ETH_FCS_LEN); | ||
477 | crc2 = 0xdeadbeef; | ||
478 | } | ||
479 | if (crc != crc2) { | ||
480 | DBG(cdev, "invalid EEM CRC\n"); | ||
481 | goto next; | ||
482 | } | ||
483 | |||
484 | skb2 = skb_clone(skb, GFP_ATOMIC); | ||
485 | if (unlikely(!skb2)) { | ||
486 | DBG(cdev, "unable to unframe EEM packet\n"); | ||
487 | continue; | ||
488 | } | ||
489 | skb_trim(skb2, len - ETH_FCS_LEN); | ||
490 | |||
491 | skb3 = skb_copy_expand(skb2, | ||
492 | NET_IP_ALIGN, | ||
493 | 0, | ||
494 | GFP_ATOMIC); | ||
495 | if (unlikely(!skb3)) { | ||
496 | DBG(cdev, "unable to realign EEM packet\n"); | ||
497 | dev_kfree_skb_any(skb2); | ||
498 | continue; | ||
499 | } | ||
500 | dev_kfree_skb_any(skb2); | ||
501 | skb_queue_tail(list, skb3); | ||
502 | } | ||
503 | next: | ||
504 | skb_pull(skb, len); | ||
505 | } while (skb->len); | ||
506 | |||
507 | error: | ||
508 | dev_kfree_skb_any(skb); | ||
509 | return status; | ||
510 | } | ||
511 | |||
512 | /** | ||
513 | * eem_bind_config - add CDC Ethernet (EEM) network link to a configuration | ||
514 | * @c: the configuration to support the network link | ||
515 | * Context: single threaded during gadget setup | ||
516 | * | ||
517 | * Returns zero on success, else negative errno. | ||
518 | * | ||
519 | * Caller must have called @gether_setup(). Caller is also responsible | ||
520 | * for calling @gether_cleanup() before module unload. | ||
521 | */ | ||
522 | int __init eem_bind_config(struct usb_configuration *c) | ||
523 | { | ||
524 | struct f_eem *eem; | ||
525 | int status; | ||
526 | |||
527 | /* maybe allocate device-global string IDs */ | ||
528 | if (eem_string_defs[0].id == 0) { | ||
529 | |||
530 | /* control interface label */ | ||
531 | status = usb_string_id(c->cdev); | ||
532 | if (status < 0) | ||
533 | return status; | ||
534 | eem_string_defs[0].id = status; | ||
535 | eem_intf.iInterface = status; | ||
536 | } | ||
537 | |||
538 | /* allocate and initialize one new instance */ | ||
539 | eem = kzalloc(sizeof *eem, GFP_KERNEL); | ||
540 | if (!eem) | ||
541 | return -ENOMEM; | ||
542 | |||
543 | eem->port.cdc_filter = DEFAULT_FILTER; | ||
544 | |||
545 | eem->port.func.name = "cdc_eem"; | ||
546 | eem->port.func.strings = eem_strings; | ||
547 | /* descriptors are per-instance copies */ | ||
548 | eem->port.func.bind = eem_bind; | ||
549 | eem->port.func.unbind = eem_unbind; | ||
550 | eem->port.func.set_alt = eem_set_alt; | ||
551 | eem->port.func.setup = eem_setup; | ||
552 | eem->port.func.disable = eem_disable; | ||
553 | eem->port.wrap = eem_wrap; | ||
554 | eem->port.unwrap = eem_unwrap; | ||
555 | eem->port.header_len = EEM_HLEN; | ||
556 | |||
557 | status = usb_add_function(c, &eem->port.func); | ||
558 | if (status) | ||
559 | kfree(eem); | ||
560 | return status; | ||
561 | } | ||
562 | |||
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c index eb6ddfc20857..6cb29d3df575 100644 --- a/drivers/usb/gadget/f_loopback.c +++ b/drivers/usb/gadget/f_loopback.c | |||
@@ -22,7 +22,6 @@ | |||
22 | /* #define VERBOSE_DEBUG */ | 22 | /* #define VERBOSE_DEBUG */ |
23 | 23 | ||
24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
25 | #include <linux/utsname.h> | ||
26 | #include <linux/device.h> | 25 | #include <linux/device.h> |
27 | 26 | ||
28 | #include "g_zero.h" | 27 | #include "g_zero.h" |
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c index 46d6266f30ec..b4a3ba654ea5 100644 --- a/drivers/usb/gadget/f_obex.c +++ b/drivers/usb/gadget/f_obex.c | |||
@@ -24,7 +24,6 @@ | |||
24 | /* #define VERBOSE_DEBUG */ | 24 | /* #define VERBOSE_DEBUG */ |
25 | 25 | ||
26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
27 | #include <linux/utsname.h> | ||
28 | #include <linux/device.h> | 27 | #include <linux/device.h> |
29 | 28 | ||
30 | #include "u_serial.h" | 29 | #include "u_serial.h" |
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c index 424a37c5773f..c9966cc07d3a 100644 --- a/drivers/usb/gadget/f_rndis.c +++ b/drivers/usb/gadget/f_rndis.c | |||
@@ -286,12 +286,17 @@ static struct usb_gadget_strings *rndis_strings[] = { | |||
286 | 286 | ||
287 | /*-------------------------------------------------------------------------*/ | 287 | /*-------------------------------------------------------------------------*/ |
288 | 288 | ||
289 | static struct sk_buff *rndis_add_header(struct sk_buff *skb) | 289 | static struct sk_buff *rndis_add_header(struct gether *port, |
290 | struct sk_buff *skb) | ||
290 | { | 291 | { |
291 | skb = skb_realloc_headroom(skb, sizeof(struct rndis_packet_msg_type)); | 292 | struct sk_buff *skb2; |
292 | if (skb) | 293 | |
293 | rndis_add_hdr(skb); | 294 | skb2 = skb_realloc_headroom(skb, sizeof(struct rndis_packet_msg_type)); |
294 | return skb; | 295 | if (skb2) |
296 | rndis_add_hdr(skb2); | ||
297 | |||
298 | dev_kfree_skb_any(skb); | ||
299 | return skb2; | ||
295 | } | 300 | } |
296 | 301 | ||
297 | static void rndis_response_available(void *_rndis) | 302 | static void rndis_response_available(void *_rndis) |
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c index bffe91d525f9..09cba273d2db 100644 --- a/drivers/usb/gadget/f_sourcesink.c +++ b/drivers/usb/gadget/f_sourcesink.c | |||
@@ -22,7 +22,6 @@ | |||
22 | /* #define VERBOSE_DEBUG */ | 22 | /* #define VERBOSE_DEBUG */ |
23 | 23 | ||
24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
25 | #include <linux/utsname.h> | ||
26 | #include <linux/device.h> | 25 | #include <linux/device.h> |
27 | 26 | ||
28 | #include "g_zero.h" | 27 | #include "g_zero.h" |
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c index d701bf4698d2..7881f12413c4 100644 --- a/drivers/usb/gadget/fsl_qe_udc.c +++ b/drivers/usb/gadget/fsl_qe_udc.c | |||
@@ -2751,6 +2751,10 @@ static int __devexit qe_udc_remove(struct of_device *ofdev) | |||
2751 | /*-------------------------------------------------------------------------*/ | 2751 | /*-------------------------------------------------------------------------*/ |
2752 | static struct of_device_id __devinitdata qe_udc_match[] = { | 2752 | static struct of_device_id __devinitdata qe_udc_match[] = { |
2753 | { | 2753 | { |
2754 | .compatible = "fsl,mpc8323-qe-usb", | ||
2755 | .data = (void *)PORT_QE, | ||
2756 | }, | ||
2757 | { | ||
2754 | .compatible = "fsl,mpc8360-qe-usb", | 2758 | .compatible = "fsl,mpc8360-qe-usb", |
2755 | .data = (void *)PORT_QE, | 2759 | .data = (void *)PORT_QE, |
2756 | }, | 2760 | }, |
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h index 8e0e9a0b7364..f2d270b202f2 100644 --- a/drivers/usb/gadget/gadget_chips.h +++ b/drivers/usb/gadget/gadget_chips.h | |||
@@ -173,6 +173,12 @@ | |||
173 | // CONFIG_USB_GADGET_AU1X00 | 173 | // CONFIG_USB_GADGET_AU1X00 |
174 | // ... | 174 | // ... |
175 | 175 | ||
176 | #ifdef CONFIG_USB_GADGET_R8A66597 | ||
177 | #define gadget_is_r8a66597(g) !strcmp("r8a66597_udc", (g)->name) | ||
178 | #else | ||
179 | #define gadget_is_r8a66597(g) 0 | ||
180 | #endif | ||
181 | |||
176 | 182 | ||
177 | /** | 183 | /** |
178 | * usb_gadget_controller_number - support bcdDevice id convention | 184 | * usb_gadget_controller_number - support bcdDevice id convention |
@@ -239,6 +245,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget) | |||
239 | return 0x23; | 245 | return 0x23; |
240 | else if (gadget_is_langwell(gadget)) | 246 | else if (gadget_is_langwell(gadget)) |
241 | return 0x24; | 247 | return 0x24; |
248 | else if (gadget_is_r8a66597(gadget)) | ||
249 | return 0x25; | ||
242 | return -ENOENT; | 250 | return -ENOENT; |
243 | } | 251 | } |
244 | 252 | ||
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c index b9312dc6e041..d0b1e836f0e0 100644 --- a/drivers/usb/gadget/gmidi.c +++ b/drivers/usb/gadget/gmidi.c | |||
@@ -191,7 +191,7 @@ module_param(qlen, uint, S_IRUGO); | |||
191 | #define GMIDI_MS_INTERFACE 1 | 191 | #define GMIDI_MS_INTERFACE 1 |
192 | #define GMIDI_NUM_INTERFACES 2 | 192 | #define GMIDI_NUM_INTERFACES 2 |
193 | 193 | ||
194 | DECLARE_USB_AC_HEADER_DESCRIPTOR(1); | 194 | DECLARE_UAC_AC_HEADER_DESCRIPTOR(1); |
195 | DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1); | 195 | DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1); |
196 | DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(1); | 196 | DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(1); |
197 | 197 | ||
@@ -237,12 +237,12 @@ static const struct usb_interface_descriptor ac_interface_desc = { | |||
237 | }; | 237 | }; |
238 | 238 | ||
239 | /* B.3.2 Class-Specific AC Interface Descriptor */ | 239 | /* B.3.2 Class-Specific AC Interface Descriptor */ |
240 | static const struct usb_ac_header_descriptor_1 ac_header_desc = { | 240 | static const struct uac_ac_header_descriptor_1 ac_header_desc = { |
241 | .bLength = USB_DT_AC_HEADER_SIZE(1), | 241 | .bLength = UAC_DT_AC_HEADER_SIZE(1), |
242 | .bDescriptorType = USB_DT_CS_INTERFACE, | 242 | .bDescriptorType = USB_DT_CS_INTERFACE, |
243 | .bDescriptorSubtype = USB_MS_HEADER, | 243 | .bDescriptorSubtype = USB_MS_HEADER, |
244 | .bcdADC = cpu_to_le16(0x0100), | 244 | .bcdADC = cpu_to_le16(0x0100), |
245 | .wTotalLength = cpu_to_le16(USB_DT_AC_HEADER_SIZE(1)), | 245 | .wTotalLength = cpu_to_le16(UAC_DT_AC_HEADER_SIZE(1)), |
246 | .bInCollection = 1, | 246 | .bInCollection = 1, |
247 | .baInterfaceNr = { | 247 | .baInterfaceNr = { |
248 | [0] = GMIDI_MS_INTERFACE, | 248 | [0] = GMIDI_MS_INTERFACE, |
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c index 7d33f50b5874..c44367fea185 100644 --- a/drivers/usb/gadget/inode.c +++ b/drivers/usb/gadget/inode.c | |||
@@ -2033,7 +2033,7 @@ gadgetfs_create_file (struct super_block *sb, char const *name, | |||
2033 | return inode; | 2033 | return inode; |
2034 | } | 2034 | } |
2035 | 2035 | ||
2036 | static struct super_operations gadget_fs_operations = { | 2036 | static const struct super_operations gadget_fs_operations = { |
2037 | .statfs = simple_statfs, | 2037 | .statfs = simple_statfs, |
2038 | .drop_inode = generic_delete_inode, | 2038 | .drop_inode = generic_delete_inode, |
2039 | }; | 2039 | }; |
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index 43dcf9e1af6b..a8c8543d1b08 100644 --- a/drivers/usb/gadget/m66592-udc.c +++ b/drivers/usb/gadget/m66592-udc.c | |||
@@ -25,44 +25,18 @@ | |||
25 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
26 | #include <linux/io.h> | 26 | #include <linux/io.h> |
27 | #include <linux/platform_device.h> | 27 | #include <linux/platform_device.h> |
28 | 28 | #include <linux/err.h> | |
29 | #include <linux/usb/ch9.h> | 29 | #include <linux/usb/ch9.h> |
30 | #include <linux/usb/gadget.h> | 30 | #include <linux/usb/gadget.h> |
31 | 31 | ||
32 | #include "m66592-udc.h" | 32 | #include "m66592-udc.h" |
33 | 33 | ||
34 | |||
35 | MODULE_DESCRIPTION("M66592 USB gadget driver"); | 34 | MODULE_DESCRIPTION("M66592 USB gadget driver"); |
36 | MODULE_LICENSE("GPL"); | 35 | MODULE_LICENSE("GPL"); |
37 | MODULE_AUTHOR("Yoshihiro Shimoda"); | 36 | MODULE_AUTHOR("Yoshihiro Shimoda"); |
38 | MODULE_ALIAS("platform:m66592_udc"); | 37 | MODULE_ALIAS("platform:m66592_udc"); |
39 | 38 | ||
40 | #define DRIVER_VERSION "18 Oct 2007" | 39 | #define DRIVER_VERSION "21 July 2009" |
41 | |||
42 | /* module parameters */ | ||
43 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) | ||
44 | static unsigned short endian = M66592_LITTLE; | ||
45 | module_param(endian, ushort, 0644); | ||
46 | MODULE_PARM_DESC(endian, "data endian: big=0, little=0 (default=0)"); | ||
47 | #else | ||
48 | static unsigned short clock = M66592_XTAL24; | ||
49 | module_param(clock, ushort, 0644); | ||
50 | MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 " | ||
51 | "(default=16384)"); | ||
52 | |||
53 | static unsigned short vif = M66592_LDRV; | ||
54 | module_param(vif, ushort, 0644); | ||
55 | MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0 (default=32768)"); | ||
56 | |||
57 | static unsigned short endian; | ||
58 | module_param(endian, ushort, 0644); | ||
59 | MODULE_PARM_DESC(endian, "data endian: big=256, little=0 (default=0)"); | ||
60 | |||
61 | static unsigned short irq_sense = M66592_INTL; | ||
62 | module_param(irq_sense, ushort, 0644); | ||
63 | MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=2, falling edge=0 " | ||
64 | "(default=2)"); | ||
65 | #endif | ||
66 | 40 | ||
67 | static const char udc_name[] = "m66592_udc"; | 41 | static const char udc_name[] = "m66592_udc"; |
68 | static const char *m66592_ep_name[] = { | 42 | static const char *m66592_ep_name[] = { |
@@ -244,6 +218,7 @@ static inline int get_buffer_size(struct m66592 *m66592, u16 pipenum) | |||
244 | static inline void pipe_change(struct m66592 *m66592, u16 pipenum) | 218 | static inline void pipe_change(struct m66592 *m66592, u16 pipenum) |
245 | { | 219 | { |
246 | struct m66592_ep *ep = m66592->pipenum2ep[pipenum]; | 220 | struct m66592_ep *ep = m66592->pipenum2ep[pipenum]; |
221 | unsigned short mbw; | ||
247 | 222 | ||
248 | if (ep->use_dma) | 223 | if (ep->use_dma) |
249 | return; | 224 | return; |
@@ -252,7 +227,12 @@ static inline void pipe_change(struct m66592 *m66592, u16 pipenum) | |||
252 | 227 | ||
253 | ndelay(450); | 228 | ndelay(450); |
254 | 229 | ||
255 | m66592_bset(m66592, M66592_MBW, ep->fifosel); | 230 | if (m66592->pdata->on_chip) |
231 | mbw = M66592_MBW_32; | ||
232 | else | ||
233 | mbw = M66592_MBW_16; | ||
234 | |||
235 | m66592_bset(m66592, mbw, ep->fifosel); | ||
256 | } | 236 | } |
257 | 237 | ||
258 | static int pipe_buffer_setting(struct m66592 *m66592, | 238 | static int pipe_buffer_setting(struct m66592 *m66592, |
@@ -276,24 +256,27 @@ static int pipe_buffer_setting(struct m66592 *m66592, | |||
276 | buf_bsize = 0; | 256 | buf_bsize = 0; |
277 | break; | 257 | break; |
278 | case M66592_BULK: | 258 | case M66592_BULK: |
279 | bufnum = m66592->bi_bufnum + | 259 | /* isochronous pipes may be used as bulk pipes */ |
280 | (info->pipe - M66592_BASE_PIPENUM_BULK) * 16; | 260 | if (info->pipe > M66592_BASE_PIPENUM_BULK) |
281 | m66592->bi_bufnum += 16; | 261 | bufnum = info->pipe - M66592_BASE_PIPENUM_BULK; |
262 | else | ||
263 | bufnum = info->pipe - M66592_BASE_PIPENUM_ISOC; | ||
264 | |||
265 | bufnum = M66592_BASE_BUFNUM + (bufnum * 16); | ||
282 | buf_bsize = 7; | 266 | buf_bsize = 7; |
283 | pipecfg |= M66592_DBLB; | 267 | pipecfg |= M66592_DBLB; |
284 | if (!info->dir_in) | 268 | if (!info->dir_in) |
285 | pipecfg |= M66592_SHTNAK; | 269 | pipecfg |= M66592_SHTNAK; |
286 | break; | 270 | break; |
287 | case M66592_ISO: | 271 | case M66592_ISO: |
288 | bufnum = m66592->bi_bufnum + | 272 | bufnum = M66592_BASE_BUFNUM + |
289 | (info->pipe - M66592_BASE_PIPENUM_ISOC) * 16; | 273 | (info->pipe - M66592_BASE_PIPENUM_ISOC) * 16; |
290 | m66592->bi_bufnum += 16; | ||
291 | buf_bsize = 7; | 274 | buf_bsize = 7; |
292 | break; | 275 | break; |
293 | } | 276 | } |
294 | if (m66592->bi_bufnum > M66592_MAX_BUFNUM) { | 277 | |
295 | pr_err("m66592 pipe memory is insufficient(%d)\n", | 278 | if (buf_bsize && ((bufnum + 16) >= M66592_MAX_BUFNUM)) { |
296 | m66592->bi_bufnum); | 279 | pr_err("m66592 pipe memory is insufficient\n"); |
297 | return -ENOMEM; | 280 | return -ENOMEM; |
298 | } | 281 | } |
299 | 282 | ||
@@ -313,17 +296,6 @@ static void pipe_buffer_release(struct m66592 *m66592, | |||
313 | if (info->pipe == 0) | 296 | if (info->pipe == 0) |
314 | return; | 297 | return; |
315 | 298 | ||
316 | switch (info->type) { | ||
317 | case M66592_BULK: | ||
318 | if (is_bulk_pipe(info->pipe)) | ||
319 | m66592->bi_bufnum -= 16; | ||
320 | break; | ||
321 | case M66592_ISO: | ||
322 | if (is_isoc_pipe(info->pipe)) | ||
323 | m66592->bi_bufnum -= 16; | ||
324 | break; | ||
325 | } | ||
326 | |||
327 | if (is_bulk_pipe(info->pipe)) { | 299 | if (is_bulk_pipe(info->pipe)) { |
328 | m66592->bulk--; | 300 | m66592->bulk--; |
329 | } else if (is_interrupt_pipe(info->pipe)) | 301 | } else if (is_interrupt_pipe(info->pipe)) |
@@ -340,6 +312,7 @@ static void pipe_buffer_release(struct m66592 *m66592, | |||
340 | static void pipe_initialize(struct m66592_ep *ep) | 312 | static void pipe_initialize(struct m66592_ep *ep) |
341 | { | 313 | { |
342 | struct m66592 *m66592 = ep->m66592; | 314 | struct m66592 *m66592 = ep->m66592; |
315 | unsigned short mbw; | ||
343 | 316 | ||
344 | m66592_mdfy(m66592, 0, M66592_CURPIPE, ep->fifosel); | 317 | m66592_mdfy(m66592, 0, M66592_CURPIPE, ep->fifosel); |
345 | 318 | ||
@@ -351,7 +324,12 @@ static void pipe_initialize(struct m66592_ep *ep) | |||
351 | 324 | ||
352 | ndelay(450); | 325 | ndelay(450); |
353 | 326 | ||
354 | m66592_bset(m66592, M66592_MBW, ep->fifosel); | 327 | if (m66592->pdata->on_chip) |
328 | mbw = M66592_MBW_32; | ||
329 | else | ||
330 | mbw = M66592_MBW_16; | ||
331 | |||
332 | m66592_bset(m66592, mbw, ep->fifosel); | ||
355 | } | 333 | } |
356 | } | 334 | } |
357 | 335 | ||
@@ -367,15 +345,13 @@ static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep, | |||
367 | ep->fifosel = M66592_D0FIFOSEL; | 345 | ep->fifosel = M66592_D0FIFOSEL; |
368 | ep->fifoctr = M66592_D0FIFOCTR; | 346 | ep->fifoctr = M66592_D0FIFOCTR; |
369 | ep->fifotrn = M66592_D0FIFOTRN; | 347 | ep->fifotrn = M66592_D0FIFOTRN; |
370 | #if !defined(CONFIG_SUPERH_BUILT_IN_M66592) | 348 | } else if (!m66592->pdata->on_chip && m66592->num_dma == 1) { |
371 | } else if (m66592->num_dma == 1) { | ||
372 | m66592->num_dma++; | 349 | m66592->num_dma++; |
373 | ep->use_dma = 1; | 350 | ep->use_dma = 1; |
374 | ep->fifoaddr = M66592_D1FIFO; | 351 | ep->fifoaddr = M66592_D1FIFO; |
375 | ep->fifosel = M66592_D1FIFOSEL; | 352 | ep->fifosel = M66592_D1FIFOSEL; |
376 | ep->fifoctr = M66592_D1FIFOCTR; | 353 | ep->fifoctr = M66592_D1FIFOCTR; |
377 | ep->fifotrn = M66592_D1FIFOTRN; | 354 | ep->fifotrn = M66592_D1FIFOTRN; |
378 | #endif | ||
379 | } else { | 355 | } else { |
380 | ep->use_dma = 0; | 356 | ep->use_dma = 0; |
381 | ep->fifoaddr = M66592_CFIFO; | 357 | ep->fifoaddr = M66592_CFIFO; |
@@ -620,76 +596,120 @@ static void start_ep0(struct m66592_ep *ep, struct m66592_request *req) | |||
620 | } | 596 | } |
621 | } | 597 | } |
622 | 598 | ||
623 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) | ||
624 | static void init_controller(struct m66592 *m66592) | 599 | static void init_controller(struct m66592 *m66592) |
625 | { | 600 | { |
626 | m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */ | 601 | unsigned int endian; |
627 | m66592_bclr(m66592, M66592_USBE, M66592_SYSCFG); | ||
628 | m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG); | ||
629 | m66592_bset(m66592, M66592_USBE, M66592_SYSCFG); | ||
630 | 602 | ||
631 | /* This is a workaound for SH7722 2nd cut */ | 603 | if (m66592->pdata->on_chip) { |
632 | m66592_bset(m66592, 0x8000, M66592_DVSTCTR); | 604 | if (m66592->pdata->endian) |
633 | m66592_bset(m66592, 0x1000, M66592_TESTMODE); | 605 | endian = 0; /* big endian */ |
634 | m66592_bclr(m66592, 0x8000, M66592_DVSTCTR); | 606 | else |
607 | endian = M66592_LITTLE; /* little endian */ | ||
635 | 608 | ||
636 | m66592_bset(m66592, M66592_INTL, M66592_INTENB1); | 609 | m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */ |
610 | m66592_bclr(m66592, M66592_USBE, M66592_SYSCFG); | ||
611 | m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG); | ||
612 | m66592_bset(m66592, M66592_USBE, M66592_SYSCFG); | ||
637 | 613 | ||
638 | m66592_write(m66592, 0, M66592_CFBCFG); | 614 | /* This is a workaound for SH7722 2nd cut */ |
639 | m66592_write(m66592, 0, M66592_D0FBCFG); | 615 | m66592_bset(m66592, 0x8000, M66592_DVSTCTR); |
640 | m66592_bset(m66592, endian, M66592_CFBCFG); | 616 | m66592_bset(m66592, 0x1000, M66592_TESTMODE); |
641 | m66592_bset(m66592, endian, M66592_D0FBCFG); | 617 | m66592_bclr(m66592, 0x8000, M66592_DVSTCTR); |
642 | } | ||
643 | #else /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ | ||
644 | static void init_controller(struct m66592 *m66592) | ||
645 | { | ||
646 | m66592_bset(m66592, (vif & M66592_LDRV) | (endian & M66592_BIGEND), | ||
647 | M66592_PINCFG); | ||
648 | m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */ | ||
649 | m66592_mdfy(m66592, clock & M66592_XTAL, M66592_XTAL, M66592_SYSCFG); | ||
650 | 618 | ||
651 | m66592_bclr(m66592, M66592_USBE, M66592_SYSCFG); | 619 | m66592_bset(m66592, M66592_INTL, M66592_INTENB1); |
652 | m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG); | 620 | |
653 | m66592_bset(m66592, M66592_USBE, M66592_SYSCFG); | 621 | m66592_write(m66592, 0, M66592_CFBCFG); |
622 | m66592_write(m66592, 0, M66592_D0FBCFG); | ||
623 | m66592_bset(m66592, endian, M66592_CFBCFG); | ||
624 | m66592_bset(m66592, endian, M66592_D0FBCFG); | ||
625 | } else { | ||
626 | unsigned int clock, vif, irq_sense; | ||
627 | |||
628 | if (m66592->pdata->endian) | ||
629 | endian = M66592_BIGEND; /* big endian */ | ||
630 | else | ||
631 | endian = 0; /* little endian */ | ||
632 | |||
633 | if (m66592->pdata->vif) | ||
634 | vif = M66592_LDRV; /* 3.3v */ | ||
635 | else | ||
636 | vif = 0; /* 1.5v */ | ||
637 | |||
638 | switch (m66592->pdata->xtal) { | ||
639 | case M66592_PLATDATA_XTAL_12MHZ: | ||
640 | clock = M66592_XTAL12; | ||
641 | break; | ||
642 | case M66592_PLATDATA_XTAL_24MHZ: | ||
643 | clock = M66592_XTAL24; | ||
644 | break; | ||
645 | case M66592_PLATDATA_XTAL_48MHZ: | ||
646 | clock = M66592_XTAL48; | ||
647 | break; | ||
648 | default: | ||
649 | pr_warning("m66592-udc: xtal configuration error\n"); | ||
650 | clock = 0; | ||
651 | } | ||
652 | |||
653 | switch (m66592->irq_trigger) { | ||
654 | case IRQF_TRIGGER_LOW: | ||
655 | irq_sense = M66592_INTL; | ||
656 | break; | ||
657 | case IRQF_TRIGGER_FALLING: | ||
658 | irq_sense = 0; | ||
659 | break; | ||
660 | default: | ||
661 | pr_warning("m66592-udc: irq trigger config error\n"); | ||
662 | irq_sense = 0; | ||
663 | } | ||
654 | 664 | ||
655 | m66592_bset(m66592, M66592_XCKE, M66592_SYSCFG); | 665 | m66592_bset(m66592, |
666 | (vif & M66592_LDRV) | (endian & M66592_BIGEND), | ||
667 | M66592_PINCFG); | ||
668 | m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */ | ||
669 | m66592_mdfy(m66592, clock & M66592_XTAL, M66592_XTAL, | ||
670 | M66592_SYSCFG); | ||
671 | m66592_bclr(m66592, M66592_USBE, M66592_SYSCFG); | ||
672 | m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG); | ||
673 | m66592_bset(m66592, M66592_USBE, M66592_SYSCFG); | ||
674 | |||
675 | m66592_bset(m66592, M66592_XCKE, M66592_SYSCFG); | ||
656 | 676 | ||
657 | msleep(3); | 677 | msleep(3); |
658 | 678 | ||
659 | m66592_bset(m66592, M66592_RCKE | M66592_PLLC, M66592_SYSCFG); | 679 | m66592_bset(m66592, M66592_RCKE | M66592_PLLC, M66592_SYSCFG); |
660 | 680 | ||
661 | msleep(1); | 681 | msleep(1); |
662 | 682 | ||
663 | m66592_bset(m66592, M66592_SCKE, M66592_SYSCFG); | 683 | m66592_bset(m66592, M66592_SCKE, M66592_SYSCFG); |
664 | 684 | ||
665 | m66592_bset(m66592, irq_sense & M66592_INTL, M66592_INTENB1); | 685 | m66592_bset(m66592, irq_sense & M66592_INTL, M66592_INTENB1); |
666 | m66592_write(m66592, M66592_BURST | M66592_CPU_ADR_RD_WR, | 686 | m66592_write(m66592, M66592_BURST | M66592_CPU_ADR_RD_WR, |
667 | M66592_DMA0CFG); | 687 | M66592_DMA0CFG); |
688 | } | ||
668 | } | 689 | } |
669 | #endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ | ||
670 | 690 | ||
671 | static void disable_controller(struct m66592 *m66592) | 691 | static void disable_controller(struct m66592 *m66592) |
672 | { | 692 | { |
673 | #if !defined(CONFIG_SUPERH_BUILT_IN_M66592) | 693 | if (!m66592->pdata->on_chip) { |
674 | m66592_bclr(m66592, M66592_SCKE, M66592_SYSCFG); | 694 | m66592_bclr(m66592, M66592_SCKE, M66592_SYSCFG); |
675 | udelay(1); | 695 | udelay(1); |
676 | m66592_bclr(m66592, M66592_PLLC, M66592_SYSCFG); | 696 | m66592_bclr(m66592, M66592_PLLC, M66592_SYSCFG); |
677 | udelay(1); | 697 | udelay(1); |
678 | m66592_bclr(m66592, M66592_RCKE, M66592_SYSCFG); | 698 | m66592_bclr(m66592, M66592_RCKE, M66592_SYSCFG); |
679 | udelay(1); | 699 | udelay(1); |
680 | m66592_bclr(m66592, M66592_XCKE, M66592_SYSCFG); | 700 | m66592_bclr(m66592, M66592_XCKE, M66592_SYSCFG); |
681 | #endif | 701 | } |
682 | } | 702 | } |
683 | 703 | ||
684 | static void m66592_start_xclock(struct m66592 *m66592) | 704 | static void m66592_start_xclock(struct m66592 *m66592) |
685 | { | 705 | { |
686 | #if !defined(CONFIG_SUPERH_BUILT_IN_M66592) | ||
687 | u16 tmp; | 706 | u16 tmp; |
688 | 707 | ||
689 | tmp = m66592_read(m66592, M66592_SYSCFG); | 708 | if (!m66592->pdata->on_chip) { |
690 | if (!(tmp & M66592_XCKE)) | 709 | tmp = m66592_read(m66592, M66592_SYSCFG); |
691 | m66592_bset(m66592, M66592_XCKE, M66592_SYSCFG); | 710 | if (!(tmp & M66592_XCKE)) |
692 | #endif | 711 | m66592_bset(m66592, M66592_XCKE, M66592_SYSCFG); |
712 | } | ||
693 | } | 713 | } |
694 | 714 | ||
695 | /*-------------------------------------------------------------------------*/ | 715 | /*-------------------------------------------------------------------------*/ |
@@ -1177,8 +1197,7 @@ static irqreturn_t m66592_irq(int irq, void *_m66592) | |||
1177 | intsts0 = m66592_read(m66592, M66592_INTSTS0); | 1197 | intsts0 = m66592_read(m66592, M66592_INTSTS0); |
1178 | intenb0 = m66592_read(m66592, M66592_INTENB0); | 1198 | intenb0 = m66592_read(m66592, M66592_INTENB0); |
1179 | 1199 | ||
1180 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) | 1200 | if (m66592->pdata->on_chip && !intsts0 && !intenb0) { |
1181 | if (!intsts0 && !intenb0) { | ||
1182 | /* | 1201 | /* |
1183 | * When USB clock stops, it cannot read register. Even if a | 1202 | * When USB clock stops, it cannot read register. Even if a |
1184 | * clock stops, the interrupt occurs. So this driver turn on | 1203 | * clock stops, the interrupt occurs. So this driver turn on |
@@ -1188,7 +1207,6 @@ static irqreturn_t m66592_irq(int irq, void *_m66592) | |||
1188 | intsts0 = m66592_read(m66592, M66592_INTSTS0); | 1207 | intsts0 = m66592_read(m66592, M66592_INTSTS0); |
1189 | intenb0 = m66592_read(m66592, M66592_INTENB0); | 1208 | intenb0 = m66592_read(m66592, M66592_INTENB0); |
1190 | } | 1209 | } |
1191 | #endif | ||
1192 | 1210 | ||
1193 | savepipe = m66592_read(m66592, M66592_CFIFOSEL); | 1211 | savepipe = m66592_read(m66592, M66592_CFIFOSEL); |
1194 | 1212 | ||
@@ -1534,9 +1552,11 @@ static int __exit m66592_remove(struct platform_device *pdev) | |||
1534 | iounmap(m66592->reg); | 1552 | iounmap(m66592->reg); |
1535 | free_irq(platform_get_irq(pdev, 0), m66592); | 1553 | free_irq(platform_get_irq(pdev, 0), m66592); |
1536 | m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req); | 1554 | m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req); |
1537 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) && defined(CONFIG_HAVE_CLK) | 1555 | #ifdef CONFIG_HAVE_CLK |
1538 | clk_disable(m66592->clk); | 1556 | if (m66592->pdata->on_chip) { |
1539 | clk_put(m66592->clk); | 1557 | clk_disable(m66592->clk); |
1558 | clk_put(m66592->clk); | ||
1559 | } | ||
1540 | #endif | 1560 | #endif |
1541 | kfree(m66592); | 1561 | kfree(m66592); |
1542 | return 0; | 1562 | return 0; |
@@ -1548,11 +1568,10 @@ static void nop_completion(struct usb_ep *ep, struct usb_request *r) | |||
1548 | 1568 | ||
1549 | static int __init m66592_probe(struct platform_device *pdev) | 1569 | static int __init m66592_probe(struct platform_device *pdev) |
1550 | { | 1570 | { |
1551 | struct resource *res; | 1571 | struct resource *res, *ires; |
1552 | int irq; | ||
1553 | void __iomem *reg = NULL; | 1572 | void __iomem *reg = NULL; |
1554 | struct m66592 *m66592 = NULL; | 1573 | struct m66592 *m66592 = NULL; |
1555 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) && defined(CONFIG_HAVE_CLK) | 1574 | #ifdef CONFIG_HAVE_CLK |
1556 | char clk_name[8]; | 1575 | char clk_name[8]; |
1557 | #endif | 1576 | #endif |
1558 | int ret = 0; | 1577 | int ret = 0; |
@@ -1565,10 +1584,11 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1565 | goto clean_up; | 1584 | goto clean_up; |
1566 | } | 1585 | } |
1567 | 1586 | ||
1568 | irq = platform_get_irq(pdev, 0); | 1587 | ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
1569 | if (irq < 0) { | 1588 | if (!ires) { |
1570 | ret = -ENODEV; | 1589 | ret = -ENODEV; |
1571 | pr_err("platform_get_irq error.\n"); | 1590 | dev_err(&pdev->dev, |
1591 | "platform_get_resource IORESOURCE_IRQ error.\n"); | ||
1572 | goto clean_up; | 1592 | goto clean_up; |
1573 | } | 1593 | } |
1574 | 1594 | ||
@@ -1579,6 +1599,12 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1579 | goto clean_up; | 1599 | goto clean_up; |
1580 | } | 1600 | } |
1581 | 1601 | ||
1602 | if (pdev->dev.platform_data == NULL) { | ||
1603 | dev_err(&pdev->dev, "no platform data\n"); | ||
1604 | ret = -ENODEV; | ||
1605 | goto clean_up; | ||
1606 | } | ||
1607 | |||
1582 | /* initialize ucd */ | 1608 | /* initialize ucd */ |
1583 | m66592 = kzalloc(sizeof(struct m66592), GFP_KERNEL); | 1609 | m66592 = kzalloc(sizeof(struct m66592), GFP_KERNEL); |
1584 | if (m66592 == NULL) { | 1610 | if (m66592 == NULL) { |
@@ -1586,6 +1612,9 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1586 | goto clean_up; | 1612 | goto clean_up; |
1587 | } | 1613 | } |
1588 | 1614 | ||
1615 | m66592->pdata = pdev->dev.platform_data; | ||
1616 | m66592->irq_trigger = ires->flags & IRQF_TRIGGER_MASK; | ||
1617 | |||
1589 | spin_lock_init(&m66592->lock); | 1618 | spin_lock_init(&m66592->lock); |
1590 | dev_set_drvdata(&pdev->dev, m66592); | 1619 | dev_set_drvdata(&pdev->dev, m66592); |
1591 | 1620 | ||
@@ -1603,24 +1632,25 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1603 | m66592->timer.data = (unsigned long)m66592; | 1632 | m66592->timer.data = (unsigned long)m66592; |
1604 | m66592->reg = reg; | 1633 | m66592->reg = reg; |
1605 | 1634 | ||
1606 | m66592->bi_bufnum = M66592_BASE_BUFNUM; | 1635 | ret = request_irq(ires->start, m66592_irq, IRQF_DISABLED | IRQF_SHARED, |
1607 | |||
1608 | ret = request_irq(irq, m66592_irq, IRQF_DISABLED | IRQF_SHARED, | ||
1609 | udc_name, m66592); | 1636 | udc_name, m66592); |
1610 | if (ret < 0) { | 1637 | if (ret < 0) { |
1611 | pr_err("request_irq error (%d)\n", ret); | 1638 | pr_err("request_irq error (%d)\n", ret); |
1612 | goto clean_up; | 1639 | goto clean_up; |
1613 | } | 1640 | } |
1614 | 1641 | ||
1615 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) && defined(CONFIG_HAVE_CLK) | 1642 | #ifdef CONFIG_HAVE_CLK |
1616 | snprintf(clk_name, sizeof(clk_name), "usbf%d", pdev->id); | 1643 | if (m66592->pdata->on_chip) { |
1617 | m66592->clk = clk_get(&pdev->dev, clk_name); | 1644 | snprintf(clk_name, sizeof(clk_name), "usbf%d", pdev->id); |
1618 | if (IS_ERR(m66592->clk)) { | 1645 | m66592->clk = clk_get(&pdev->dev, clk_name); |
1619 | dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name); | 1646 | if (IS_ERR(m66592->clk)) { |
1620 | ret = PTR_ERR(m66592->clk); | 1647 | dev_err(&pdev->dev, "cannot get clock \"%s\"\n", |
1621 | goto clean_up2; | 1648 | clk_name); |
1649 | ret = PTR_ERR(m66592->clk); | ||
1650 | goto clean_up2; | ||
1651 | } | ||
1652 | clk_enable(m66592->clk); | ||
1622 | } | 1653 | } |
1623 | clk_enable(m66592->clk); | ||
1624 | #endif | 1654 | #endif |
1625 | INIT_LIST_HEAD(&m66592->gadget.ep_list); | 1655 | INIT_LIST_HEAD(&m66592->gadget.ep_list); |
1626 | m66592->gadget.ep0 = &m66592->ep[0].ep; | 1656 | m66592->gadget.ep0 = &m66592->ep[0].ep; |
@@ -1662,12 +1692,14 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1662 | return 0; | 1692 | return 0; |
1663 | 1693 | ||
1664 | clean_up3: | 1694 | clean_up3: |
1665 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) && defined(CONFIG_HAVE_CLK) | 1695 | #ifdef CONFIG_HAVE_CLK |
1666 | clk_disable(m66592->clk); | 1696 | if (m66592->pdata->on_chip) { |
1667 | clk_put(m66592->clk); | 1697 | clk_disable(m66592->clk); |
1698 | clk_put(m66592->clk); | ||
1699 | } | ||
1668 | clean_up2: | 1700 | clean_up2: |
1669 | #endif | 1701 | #endif |
1670 | free_irq(irq, m66592); | 1702 | free_irq(ires->start, m66592); |
1671 | clean_up: | 1703 | clean_up: |
1672 | if (m66592) { | 1704 | if (m66592) { |
1673 | if (m66592->ep0_req) | 1705 | if (m66592->ep0_req) |
diff --git a/drivers/usb/gadget/m66592-udc.h b/drivers/usb/gadget/m66592-udc.h index 286ce07e7960..8b960deed680 100644 --- a/drivers/usb/gadget/m66592-udc.h +++ b/drivers/usb/gadget/m66592-udc.h | |||
@@ -23,10 +23,12 @@ | |||
23 | #ifndef __M66592_UDC_H__ | 23 | #ifndef __M66592_UDC_H__ |
24 | #define __M66592_UDC_H__ | 24 | #define __M66592_UDC_H__ |
25 | 25 | ||
26 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) && defined(CONFIG_HAVE_CLK) | 26 | #ifdef CONFIG_HAVE_CLK |
27 | #include <linux/clk.h> | 27 | #include <linux/clk.h> |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | #include <linux/usb/m66592.h> | ||
31 | |||
30 | #define M66592_SYSCFG 0x00 | 32 | #define M66592_SYSCFG 0x00 |
31 | #define M66592_XTAL 0xC000 /* b15-14: Crystal selection */ | 33 | #define M66592_XTAL 0xC000 /* b15-14: Crystal selection */ |
32 | #define M66592_XTAL48 0x8000 /* 48MHz */ | 34 | #define M66592_XTAL48 0x8000 /* 48MHz */ |
@@ -76,11 +78,11 @@ | |||
76 | #define M66592_P_TST_J 0x0001 /* PERI TEST J */ | 78 | #define M66592_P_TST_J 0x0001 /* PERI TEST J */ |
77 | #define M66592_P_TST_NORMAL 0x0000 /* PERI Normal Mode */ | 79 | #define M66592_P_TST_NORMAL 0x0000 /* PERI Normal Mode */ |
78 | 80 | ||
79 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) | 81 | /* built-in registers */ |
80 | #define M66592_CFBCFG 0x0A | 82 | #define M66592_CFBCFG 0x0A |
81 | #define M66592_D0FBCFG 0x0C | 83 | #define M66592_D0FBCFG 0x0C |
82 | #define M66592_LITTLE 0x0100 /* b8: Little endian mode */ | 84 | #define M66592_LITTLE 0x0100 /* b8: Little endian mode */ |
83 | #else | 85 | /* external chip case */ |
84 | #define M66592_PINCFG 0x0A | 86 | #define M66592_PINCFG 0x0A |
85 | #define M66592_LDRV 0x8000 /* b15: Drive Current Adjust */ | 87 | #define M66592_LDRV 0x8000 /* b15: Drive Current Adjust */ |
86 | #define M66592_BIGEND 0x0100 /* b8: Big endian mode */ | 88 | #define M66592_BIGEND 0x0100 /* b8: Big endian mode */ |
@@ -100,8 +102,8 @@ | |||
100 | #define M66592_PKTM 0x0020 /* b5: Packet mode */ | 102 | #define M66592_PKTM 0x0020 /* b5: Packet mode */ |
101 | #define M66592_DENDE 0x0010 /* b4: Dend enable */ | 103 | #define M66592_DENDE 0x0010 /* b4: Dend enable */ |
102 | #define M66592_OBUS 0x0004 /* b2: OUTbus mode */ | 104 | #define M66592_OBUS 0x0004 /* b2: OUTbus mode */ |
103 | #endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ | ||
104 | 105 | ||
106 | /* common case */ | ||
105 | #define M66592_CFIFO 0x10 | 107 | #define M66592_CFIFO 0x10 |
106 | #define M66592_D0FIFO 0x14 | 108 | #define M66592_D0FIFO 0x14 |
107 | #define M66592_D1FIFO 0x18 | 109 | #define M66592_D1FIFO 0x18 |
@@ -113,13 +115,9 @@ | |||
113 | #define M66592_REW 0x4000 /* b14: Buffer rewind */ | 115 | #define M66592_REW 0x4000 /* b14: Buffer rewind */ |
114 | #define M66592_DCLRM 0x2000 /* b13: DMA buffer clear mode */ | 116 | #define M66592_DCLRM 0x2000 /* b13: DMA buffer clear mode */ |
115 | #define M66592_DREQE 0x1000 /* b12: DREQ output enable */ | 117 | #define M66592_DREQE 0x1000 /* b12: DREQ output enable */ |
116 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) | 118 | #define M66592_MBW_8 0x0000 /* 8bit */ |
117 | #define M66592_MBW 0x0800 /* b11: Maximum bit width for FIFO */ | 119 | #define M66592_MBW_16 0x0400 /* 16bit */ |
118 | #else | 120 | #define M66592_MBW_32 0x0800 /* 32bit */ |
119 | #define M66592_MBW 0x0400 /* b10: Maximum bit width for FIFO */ | ||
120 | #define M66592_MBW_8 0x0000 /* 8bit */ | ||
121 | #define M66592_MBW_16 0x0400 /* 16bit */ | ||
122 | #endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ | ||
123 | #define M66592_TRENB 0x0200 /* b9: Transaction counter enable */ | 121 | #define M66592_TRENB 0x0200 /* b9: Transaction counter enable */ |
124 | #define M66592_TRCLR 0x0100 /* b8: Transaction counter clear */ | 122 | #define M66592_TRCLR 0x0100 /* b8: Transaction counter clear */ |
125 | #define M66592_DEZPM 0x0080 /* b7: Zero-length packet mode */ | 123 | #define M66592_DEZPM 0x0080 /* b7: Zero-length packet mode */ |
@@ -480,9 +478,11 @@ struct m66592_ep { | |||
480 | struct m66592 { | 478 | struct m66592 { |
481 | spinlock_t lock; | 479 | spinlock_t lock; |
482 | void __iomem *reg; | 480 | void __iomem *reg; |
483 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) && defined(CONFIG_HAVE_CLK) | 481 | #ifdef CONFIG_HAVE_CLK |
484 | struct clk *clk; | 482 | struct clk *clk; |
485 | #endif | 483 | #endif |
484 | struct m66592_platdata *pdata; | ||
485 | unsigned long irq_trigger; | ||
486 | 486 | ||
487 | struct usb_gadget gadget; | 487 | struct usb_gadget gadget; |
488 | struct usb_gadget_driver *driver; | 488 | struct usb_gadget_driver *driver; |
@@ -506,7 +506,6 @@ struct m66592 { | |||
506 | int interrupt; | 506 | int interrupt; |
507 | int isochronous; | 507 | int isochronous; |
508 | int num_dma; | 508 | int num_dma; |
509 | int bi_bufnum; /* bulk and isochronous's bufnum */ | ||
510 | }; | 509 | }; |
511 | 510 | ||
512 | #define gadget_to_m66592(_gadget) container_of(_gadget, struct m66592, gadget) | 511 | #define gadget_to_m66592(_gadget) container_of(_gadget, struct m66592, gadget) |
@@ -547,13 +546,13 @@ static inline void m66592_read_fifo(struct m66592 *m66592, | |||
547 | { | 546 | { |
548 | unsigned long fifoaddr = (unsigned long)m66592->reg + offset; | 547 | unsigned long fifoaddr = (unsigned long)m66592->reg + offset; |
549 | 548 | ||
550 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) | 549 | if (m66592->pdata->on_chip) { |
551 | len = (len + 3) / 4; | 550 | len = (len + 3) / 4; |
552 | insl(fifoaddr, buf, len); | 551 | insl(fifoaddr, buf, len); |
553 | #else | 552 | } else { |
554 | len = (len + 1) / 2; | 553 | len = (len + 1) / 2; |
555 | insw(fifoaddr, buf, len); | 554 | insw(fifoaddr, buf, len); |
556 | #endif | 555 | } |
557 | } | 556 | } |
558 | 557 | ||
559 | static inline void m66592_write(struct m66592 *m66592, u16 val, | 558 | static inline void m66592_write(struct m66592 *m66592, u16 val, |
@@ -567,33 +566,34 @@ static inline void m66592_write_fifo(struct m66592 *m66592, | |||
567 | void *buf, unsigned long len) | 566 | void *buf, unsigned long len) |
568 | { | 567 | { |
569 | unsigned long fifoaddr = (unsigned long)m66592->reg + offset; | 568 | unsigned long fifoaddr = (unsigned long)m66592->reg + offset; |
570 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) | 569 | |
571 | unsigned long count; | 570 | if (m66592->pdata->on_chip) { |
572 | unsigned char *pb; | 571 | unsigned long count; |
573 | int i; | 572 | unsigned char *pb; |
574 | 573 | int i; | |
575 | count = len / 4; | 574 | |
576 | outsl(fifoaddr, buf, count); | 575 | count = len / 4; |
577 | 576 | outsl(fifoaddr, buf, count); | |
578 | if (len & 0x00000003) { | 577 | |
579 | pb = buf + count * 4; | 578 | if (len & 0x00000003) { |
580 | for (i = 0; i < (len & 0x00000003); i++) { | 579 | pb = buf + count * 4; |
581 | if (m66592_read(m66592, M66592_CFBCFG)) /* little */ | 580 | for (i = 0; i < (len & 0x00000003); i++) { |
582 | outb(pb[i], fifoaddr + (3 - i)); | 581 | if (m66592_read(m66592, M66592_CFBCFG)) /* le */ |
583 | else | 582 | outb(pb[i], fifoaddr + (3 - i)); |
584 | outb(pb[i], fifoaddr + i); | 583 | else |
584 | outb(pb[i], fifoaddr + i); | ||
585 | } | ||
586 | } | ||
587 | } else { | ||
588 | unsigned long odd = len & 0x0001; | ||
589 | |||
590 | len = len / 2; | ||
591 | outsw(fifoaddr, buf, len); | ||
592 | if (odd) { | ||
593 | unsigned char *p = buf + len*2; | ||
594 | outb(*p, fifoaddr); | ||
585 | } | 595 | } |
586 | } | 596 | } |
587 | #else | ||
588 | unsigned long odd = len & 0x0001; | ||
589 | |||
590 | len = len / 2; | ||
591 | outsw(fifoaddr, buf, len); | ||
592 | if (odd) { | ||
593 | unsigned char *p = buf + len*2; | ||
594 | outb(*p, fifoaddr); | ||
595 | } | ||
596 | #endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ | ||
597 | } | 597 | } |
598 | 598 | ||
599 | static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat, | 599 | static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat, |
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c index ed21e263f832..e6fedbd5a654 100644 --- a/drivers/usb/gadget/pxa25x_udc.c +++ b/drivers/usb/gadget/pxa25x_udc.c | |||
@@ -56,6 +56,7 @@ | |||
56 | 56 | ||
57 | #include <linux/usb/ch9.h> | 57 | #include <linux/usb/ch9.h> |
58 | #include <linux/usb/gadget.h> | 58 | #include <linux/usb/gadget.h> |
59 | #include <linux/usb/otg.h> | ||
59 | 60 | ||
60 | /* | 61 | /* |
61 | * This driver is PXA25x only. Grab the right register definitions. | 62 | * This driver is PXA25x only. Grab the right register definitions. |
@@ -1008,15 +1009,27 @@ static int pxa25x_udc_pullup(struct usb_gadget *_gadget, int is_active) | |||
1008 | return 0; | 1009 | return 0; |
1009 | } | 1010 | } |
1010 | 1011 | ||
1012 | /* boards may consume current from VBUS, up to 100-500mA based on config. | ||
1013 | * the 500uA suspend ceiling means that exclusively vbus-powered PXA designs | ||
1014 | * violate USB specs. | ||
1015 | */ | ||
1016 | static int pxa25x_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA) | ||
1017 | { | ||
1018 | struct pxa25x_udc *udc; | ||
1019 | |||
1020 | udc = container_of(_gadget, struct pxa25x_udc, gadget); | ||
1021 | |||
1022 | if (udc->transceiver) | ||
1023 | return otg_set_power(udc->transceiver, mA); | ||
1024 | return -EOPNOTSUPP; | ||
1025 | } | ||
1026 | |||
1011 | static const struct usb_gadget_ops pxa25x_udc_ops = { | 1027 | static const struct usb_gadget_ops pxa25x_udc_ops = { |
1012 | .get_frame = pxa25x_udc_get_frame, | 1028 | .get_frame = pxa25x_udc_get_frame, |
1013 | .wakeup = pxa25x_udc_wakeup, | 1029 | .wakeup = pxa25x_udc_wakeup, |
1014 | .vbus_session = pxa25x_udc_vbus_session, | 1030 | .vbus_session = pxa25x_udc_vbus_session, |
1015 | .pullup = pxa25x_udc_pullup, | 1031 | .pullup = pxa25x_udc_pullup, |
1016 | 1032 | .vbus_draw = pxa25x_udc_vbus_draw, | |
1017 | // .vbus_draw ... boards may consume current from VBUS, up to | ||
1018 | // 100-500mA based on config. the 500uA suspend ceiling means | ||
1019 | // that exclusively vbus-powered PXA designs violate USB specs. | ||
1020 | }; | 1033 | }; |
1021 | 1034 | ||
1022 | /*-------------------------------------------------------------------------*/ | 1035 | /*-------------------------------------------------------------------------*/ |
@@ -1303,9 +1316,23 @@ fail: | |||
1303 | * for set_configuration as well as eventual disconnect. | 1316 | * for set_configuration as well as eventual disconnect. |
1304 | */ | 1317 | */ |
1305 | DMSG("registered gadget driver '%s'\n", driver->driver.name); | 1318 | DMSG("registered gadget driver '%s'\n", driver->driver.name); |
1319 | |||
1320 | /* connect to bus through transceiver */ | ||
1321 | if (dev->transceiver) { | ||
1322 | retval = otg_set_peripheral(dev->transceiver, &dev->gadget); | ||
1323 | if (retval) { | ||
1324 | DMSG("can't bind to transceiver\n"); | ||
1325 | if (driver->unbind) | ||
1326 | driver->unbind(&dev->gadget); | ||
1327 | goto bind_fail; | ||
1328 | } | ||
1329 | } | ||
1330 | |||
1306 | pullup(dev); | 1331 | pullup(dev); |
1307 | dump_state(dev); | 1332 | dump_state(dev); |
1308 | return 0; | 1333 | return 0; |
1334 | bind_fail: | ||
1335 | return retval; | ||
1309 | } | 1336 | } |
1310 | EXPORT_SYMBOL(usb_gadget_register_driver); | 1337 | EXPORT_SYMBOL(usb_gadget_register_driver); |
1311 | 1338 | ||
@@ -1351,6 +1378,9 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1351 | stop_activity(dev, driver); | 1378 | stop_activity(dev, driver); |
1352 | local_irq_enable(); | 1379 | local_irq_enable(); |
1353 | 1380 | ||
1381 | if (dev->transceiver) | ||
1382 | (void) otg_set_peripheral(dev->transceiver, NULL); | ||
1383 | |||
1354 | driver->unbind(&dev->gadget); | 1384 | driver->unbind(&dev->gadget); |
1355 | dev->gadget.dev.driver = NULL; | 1385 | dev->gadget.dev.driver = NULL; |
1356 | dev->driver = NULL; | 1386 | dev->driver = NULL; |
@@ -2162,6 +2192,8 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev) | |||
2162 | dev->dev = &pdev->dev; | 2192 | dev->dev = &pdev->dev; |
2163 | dev->mach = pdev->dev.platform_data; | 2193 | dev->mach = pdev->dev.platform_data; |
2164 | 2194 | ||
2195 | dev->transceiver = otg_get_transceiver(); | ||
2196 | |||
2165 | if (gpio_is_valid(dev->mach->gpio_vbus)) { | 2197 | if (gpio_is_valid(dev->mach->gpio_vbus)) { |
2166 | if ((retval = gpio_request(dev->mach->gpio_vbus, | 2198 | if ((retval = gpio_request(dev->mach->gpio_vbus, |
2167 | "pxa25x_udc GPIO VBUS"))) { | 2199 | "pxa25x_udc GPIO VBUS"))) { |
@@ -2264,6 +2296,10 @@ lubbock_fail0: | |||
2264 | if (gpio_is_valid(dev->mach->gpio_vbus)) | 2296 | if (gpio_is_valid(dev->mach->gpio_vbus)) |
2265 | gpio_free(dev->mach->gpio_vbus); | 2297 | gpio_free(dev->mach->gpio_vbus); |
2266 | err_gpio_vbus: | 2298 | err_gpio_vbus: |
2299 | if (dev->transceiver) { | ||
2300 | otg_put_transceiver(dev->transceiver); | ||
2301 | dev->transceiver = NULL; | ||
2302 | } | ||
2267 | clk_put(dev->clk); | 2303 | clk_put(dev->clk); |
2268 | err_clk: | 2304 | err_clk: |
2269 | return retval; | 2305 | return retval; |
@@ -2305,6 +2341,11 @@ static int __exit pxa25x_udc_remove(struct platform_device *pdev) | |||
2305 | 2341 | ||
2306 | clk_put(dev->clk); | 2342 | clk_put(dev->clk); |
2307 | 2343 | ||
2344 | if (dev->transceiver) { | ||
2345 | otg_put_transceiver(dev->transceiver); | ||
2346 | dev->transceiver = NULL; | ||
2347 | } | ||
2348 | |||
2308 | platform_set_drvdata(pdev, NULL); | 2349 | platform_set_drvdata(pdev, NULL); |
2309 | the_controller = NULL; | 2350 | the_controller = NULL; |
2310 | return 0; | 2351 | return 0; |
diff --git a/drivers/usb/gadget/pxa25x_udc.h b/drivers/usb/gadget/pxa25x_udc.h index 1d51aa21e6eb..f572c5617462 100644 --- a/drivers/usb/gadget/pxa25x_udc.h +++ b/drivers/usb/gadget/pxa25x_udc.h | |||
@@ -128,6 +128,7 @@ struct pxa25x_udc { | |||
128 | struct device *dev; | 128 | struct device *dev; |
129 | struct clk *clk; | 129 | struct clk *clk; |
130 | struct pxa2xx_udc_mach_info *mach; | 130 | struct pxa2xx_udc_mach_info *mach; |
131 | struct otg_transceiver *transceiver; | ||
131 | u64 dma_mask; | 132 | u64 dma_mask; |
132 | struct pxa25x_ep ep [PXA_UDC_NUM_ENDPOINTS]; | 133 | struct pxa25x_ep ep [PXA_UDC_NUM_ENDPOINTS]; |
133 | 134 | ||
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c new file mode 100644 index 000000000000..e220fb8091a3 --- /dev/null +++ b/drivers/usb/gadget/r8a66597-udc.c | |||
@@ -0,0 +1,1689 @@ | |||
1 | /* | ||
2 | * R8A66597 UDC (USB gadget) | ||
3 | * | ||
4 | * Copyright (C) 2006-2009 Renesas Solutions Corp. | ||
5 | * | ||
6 | * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> | ||
7 | * | ||
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 | ||
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 | */ | ||
22 | |||
23 | #include <linux/module.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/io.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/clk.h> | ||
29 | |||
30 | #include <linux/usb/ch9.h> | ||
31 | #include <linux/usb/gadget.h> | ||
32 | |||
33 | #include "r8a66597-udc.h" | ||
34 | |||
35 | #define DRIVER_VERSION "2009-08-18" | ||
36 | |||
37 | static const char udc_name[] = "r8a66597_udc"; | ||
38 | static const char *r8a66597_ep_name[] = { | ||
39 | "ep0", "ep1", "ep2", "ep3", "ep4", "ep5", "ep6", "ep7", | ||
40 | "ep8", "ep9", | ||
41 | }; | ||
42 | |||
43 | static void disable_controller(struct r8a66597 *r8a66597); | ||
44 | static void irq_ep0_write(struct r8a66597_ep *ep, struct r8a66597_request *req); | ||
45 | static void irq_packet_write(struct r8a66597_ep *ep, | ||
46 | struct r8a66597_request *req); | ||
47 | static int r8a66597_queue(struct usb_ep *_ep, struct usb_request *_req, | ||
48 | gfp_t gfp_flags); | ||
49 | |||
50 | static void transfer_complete(struct r8a66597_ep *ep, | ||
51 | struct r8a66597_request *req, int status); | ||
52 | |||
53 | /*-------------------------------------------------------------------------*/ | ||
54 | static inline u16 get_usb_speed(struct r8a66597 *r8a66597) | ||
55 | { | ||
56 | return r8a66597_read(r8a66597, DVSTCTR0) & RHST; | ||
57 | } | ||
58 | |||
59 | static void enable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum, | ||
60 | unsigned long reg) | ||
61 | { | ||
62 | u16 tmp; | ||
63 | |||
64 | tmp = r8a66597_read(r8a66597, INTENB0); | ||
65 | r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE, | ||
66 | INTENB0); | ||
67 | r8a66597_bset(r8a66597, (1 << pipenum), reg); | ||
68 | r8a66597_write(r8a66597, tmp, INTENB0); | ||
69 | } | ||
70 | |||
71 | static void disable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum, | ||
72 | unsigned long reg) | ||
73 | { | ||
74 | u16 tmp; | ||
75 | |||
76 | tmp = r8a66597_read(r8a66597, INTENB0); | ||
77 | r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE, | ||
78 | INTENB0); | ||
79 | r8a66597_bclr(r8a66597, (1 << pipenum), reg); | ||
80 | r8a66597_write(r8a66597, tmp, INTENB0); | ||
81 | } | ||
82 | |||
83 | static void r8a66597_usb_connect(struct r8a66597 *r8a66597) | ||
84 | { | ||
85 | r8a66597_bset(r8a66597, CTRE, INTENB0); | ||
86 | r8a66597_bset(r8a66597, BEMPE | BRDYE, INTENB0); | ||
87 | |||
88 | r8a66597_bset(r8a66597, DPRPU, SYSCFG0); | ||
89 | } | ||
90 | |||
91 | static void r8a66597_usb_disconnect(struct r8a66597 *r8a66597) | ||
92 | __releases(r8a66597->lock) | ||
93 | __acquires(r8a66597->lock) | ||
94 | { | ||
95 | r8a66597_bclr(r8a66597, CTRE, INTENB0); | ||
96 | r8a66597_bclr(r8a66597, BEMPE | BRDYE, INTENB0); | ||
97 | r8a66597_bclr(r8a66597, DPRPU, SYSCFG0); | ||
98 | |||
99 | r8a66597->gadget.speed = USB_SPEED_UNKNOWN; | ||
100 | spin_unlock(&r8a66597->lock); | ||
101 | r8a66597->driver->disconnect(&r8a66597->gadget); | ||
102 | spin_lock(&r8a66597->lock); | ||
103 | |||
104 | disable_controller(r8a66597); | ||
105 | INIT_LIST_HEAD(&r8a66597->ep[0].queue); | ||
106 | } | ||
107 | |||
108 | static inline u16 control_reg_get_pid(struct r8a66597 *r8a66597, u16 pipenum) | ||
109 | { | ||
110 | u16 pid = 0; | ||
111 | unsigned long offset; | ||
112 | |||
113 | if (pipenum == 0) | ||
114 | pid = r8a66597_read(r8a66597, DCPCTR) & PID; | ||
115 | else if (pipenum < R8A66597_MAX_NUM_PIPE) { | ||
116 | offset = get_pipectr_addr(pipenum); | ||
117 | pid = r8a66597_read(r8a66597, offset) & PID; | ||
118 | } else | ||
119 | printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum); | ||
120 | |||
121 | return pid; | ||
122 | } | ||
123 | |||
124 | static inline void control_reg_set_pid(struct r8a66597 *r8a66597, u16 pipenum, | ||
125 | u16 pid) | ||
126 | { | ||
127 | unsigned long offset; | ||
128 | |||
129 | if (pipenum == 0) | ||
130 | r8a66597_mdfy(r8a66597, pid, PID, DCPCTR); | ||
131 | else if (pipenum < R8A66597_MAX_NUM_PIPE) { | ||
132 | offset = get_pipectr_addr(pipenum); | ||
133 | r8a66597_mdfy(r8a66597, pid, PID, offset); | ||
134 | } else | ||
135 | printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum); | ||
136 | } | ||
137 | |||
138 | static inline void pipe_start(struct r8a66597 *r8a66597, u16 pipenum) | ||
139 | { | ||
140 | control_reg_set_pid(r8a66597, pipenum, PID_BUF); | ||
141 | } | ||
142 | |||
143 | static inline void pipe_stop(struct r8a66597 *r8a66597, u16 pipenum) | ||
144 | { | ||
145 | control_reg_set_pid(r8a66597, pipenum, PID_NAK); | ||
146 | } | ||
147 | |||
148 | static inline void pipe_stall(struct r8a66597 *r8a66597, u16 pipenum) | ||
149 | { | ||
150 | control_reg_set_pid(r8a66597, pipenum, PID_STALL); | ||
151 | } | ||
152 | |||
153 | static inline u16 control_reg_get(struct r8a66597 *r8a66597, u16 pipenum) | ||
154 | { | ||
155 | u16 ret = 0; | ||
156 | unsigned long offset; | ||
157 | |||
158 | if (pipenum == 0) | ||
159 | ret = r8a66597_read(r8a66597, DCPCTR); | ||
160 | else if (pipenum < R8A66597_MAX_NUM_PIPE) { | ||
161 | offset = get_pipectr_addr(pipenum); | ||
162 | ret = r8a66597_read(r8a66597, offset); | ||
163 | } else | ||
164 | printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum); | ||
165 | |||
166 | return ret; | ||
167 | } | ||
168 | |||
169 | static inline void control_reg_sqclr(struct r8a66597 *r8a66597, u16 pipenum) | ||
170 | { | ||
171 | unsigned long offset; | ||
172 | |||
173 | pipe_stop(r8a66597, pipenum); | ||
174 | |||
175 | if (pipenum == 0) | ||
176 | r8a66597_bset(r8a66597, SQCLR, DCPCTR); | ||
177 | else if (pipenum < R8A66597_MAX_NUM_PIPE) { | ||
178 | offset = get_pipectr_addr(pipenum); | ||
179 | r8a66597_bset(r8a66597, SQCLR, offset); | ||
180 | } else | ||
181 | printk(KERN_ERR "unexpect pipe num(%d)\n", pipenum); | ||
182 | } | ||
183 | |||
184 | static inline int get_buffer_size(struct r8a66597 *r8a66597, u16 pipenum) | ||
185 | { | ||
186 | u16 tmp; | ||
187 | int size; | ||
188 | |||
189 | if (pipenum == 0) { | ||
190 | tmp = r8a66597_read(r8a66597, DCPCFG); | ||
191 | if ((tmp & R8A66597_CNTMD) != 0) | ||
192 | size = 256; | ||
193 | else { | ||
194 | tmp = r8a66597_read(r8a66597, DCPMAXP); | ||
195 | size = tmp & MAXP; | ||
196 | } | ||
197 | } else { | ||
198 | r8a66597_write(r8a66597, pipenum, PIPESEL); | ||
199 | tmp = r8a66597_read(r8a66597, PIPECFG); | ||
200 | if ((tmp & R8A66597_CNTMD) != 0) { | ||
201 | tmp = r8a66597_read(r8a66597, PIPEBUF); | ||
202 | size = ((tmp >> 10) + 1) * 64; | ||
203 | } else { | ||
204 | tmp = r8a66597_read(r8a66597, PIPEMAXP); | ||
205 | size = tmp & MXPS; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | return size; | ||
210 | } | ||
211 | |||
212 | static inline unsigned short mbw_value(struct r8a66597 *r8a66597) | ||
213 | { | ||
214 | if (r8a66597->pdata->on_chip) | ||
215 | return MBW_32; | ||
216 | else | ||
217 | return MBW_16; | ||
218 | } | ||
219 | |||
220 | static inline void pipe_change(struct r8a66597 *r8a66597, u16 pipenum) | ||
221 | { | ||
222 | struct r8a66597_ep *ep = r8a66597->pipenum2ep[pipenum]; | ||
223 | |||
224 | if (ep->use_dma) | ||
225 | return; | ||
226 | |||
227 | r8a66597_mdfy(r8a66597, pipenum, CURPIPE, ep->fifosel); | ||
228 | |||
229 | ndelay(450); | ||
230 | |||
231 | r8a66597_bset(r8a66597, mbw_value(r8a66597), ep->fifosel); | ||
232 | } | ||
233 | |||
234 | static int pipe_buffer_setting(struct r8a66597 *r8a66597, | ||
235 | struct r8a66597_pipe_info *info) | ||
236 | { | ||
237 | u16 bufnum = 0, buf_bsize = 0; | ||
238 | u16 pipecfg = 0; | ||
239 | |||
240 | if (info->pipe == 0) | ||
241 | return -EINVAL; | ||
242 | |||
243 | r8a66597_write(r8a66597, info->pipe, PIPESEL); | ||
244 | |||
245 | if (info->dir_in) | ||
246 | pipecfg |= R8A66597_DIR; | ||
247 | pipecfg |= info->type; | ||
248 | pipecfg |= info->epnum; | ||
249 | switch (info->type) { | ||
250 | case R8A66597_INT: | ||
251 | bufnum = 4 + (info->pipe - R8A66597_BASE_PIPENUM_INT); | ||
252 | buf_bsize = 0; | ||
253 | break; | ||
254 | case R8A66597_BULK: | ||
255 | /* isochronous pipes may be used as bulk pipes */ | ||
256 | if (info->pipe > R8A66597_BASE_PIPENUM_BULK) | ||
257 | bufnum = info->pipe - R8A66597_BASE_PIPENUM_BULK; | ||
258 | else | ||
259 | bufnum = info->pipe - R8A66597_BASE_PIPENUM_ISOC; | ||
260 | |||
261 | bufnum = R8A66597_BASE_BUFNUM + (bufnum * 16); | ||
262 | buf_bsize = 7; | ||
263 | pipecfg |= R8A66597_DBLB; | ||
264 | if (!info->dir_in) | ||
265 | pipecfg |= R8A66597_SHTNAK; | ||
266 | break; | ||
267 | case R8A66597_ISO: | ||
268 | bufnum = R8A66597_BASE_BUFNUM + | ||
269 | (info->pipe - R8A66597_BASE_PIPENUM_ISOC) * 16; | ||
270 | buf_bsize = 7; | ||
271 | break; | ||
272 | } | ||
273 | |||
274 | if (buf_bsize && ((bufnum + 16) >= R8A66597_MAX_BUFNUM)) { | ||
275 | pr_err(KERN_ERR "r8a66597 pipe memory is insufficient\n"); | ||
276 | return -ENOMEM; | ||
277 | } | ||
278 | |||
279 | r8a66597_write(r8a66597, pipecfg, PIPECFG); | ||
280 | r8a66597_write(r8a66597, (buf_bsize << 10) | (bufnum), PIPEBUF); | ||
281 | r8a66597_write(r8a66597, info->maxpacket, PIPEMAXP); | ||
282 | if (info->interval) | ||
283 | info->interval--; | ||
284 | r8a66597_write(r8a66597, info->interval, PIPEPERI); | ||
285 | |||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | static void pipe_buffer_release(struct r8a66597 *r8a66597, | ||
290 | struct r8a66597_pipe_info *info) | ||
291 | { | ||
292 | if (info->pipe == 0) | ||
293 | return; | ||
294 | |||
295 | if (is_bulk_pipe(info->pipe)) | ||
296 | r8a66597->bulk--; | ||
297 | else if (is_interrupt_pipe(info->pipe)) | ||
298 | r8a66597->interrupt--; | ||
299 | else if (is_isoc_pipe(info->pipe)) { | ||
300 | r8a66597->isochronous--; | ||
301 | if (info->type == R8A66597_BULK) | ||
302 | r8a66597->bulk--; | ||
303 | } else | ||
304 | printk(KERN_ERR "ep_release: unexpect pipenum (%d)\n", | ||
305 | info->pipe); | ||
306 | } | ||
307 | |||
308 | static void pipe_initialize(struct r8a66597_ep *ep) | ||
309 | { | ||
310 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
311 | |||
312 | r8a66597_mdfy(r8a66597, 0, CURPIPE, ep->fifosel); | ||
313 | |||
314 | r8a66597_write(r8a66597, ACLRM, ep->pipectr); | ||
315 | r8a66597_write(r8a66597, 0, ep->pipectr); | ||
316 | r8a66597_write(r8a66597, SQCLR, ep->pipectr); | ||
317 | if (ep->use_dma) { | ||
318 | r8a66597_mdfy(r8a66597, ep->pipenum, CURPIPE, ep->fifosel); | ||
319 | |||
320 | ndelay(450); | ||
321 | |||
322 | r8a66597_bset(r8a66597, mbw_value(r8a66597), ep->fifosel); | ||
323 | } | ||
324 | } | ||
325 | |||
326 | static void r8a66597_ep_setting(struct r8a66597 *r8a66597, | ||
327 | struct r8a66597_ep *ep, | ||
328 | const struct usb_endpoint_descriptor *desc, | ||
329 | u16 pipenum, int dma) | ||
330 | { | ||
331 | ep->use_dma = 0; | ||
332 | ep->fifoaddr = CFIFO; | ||
333 | ep->fifosel = CFIFOSEL; | ||
334 | ep->fifoctr = CFIFOCTR; | ||
335 | ep->fifotrn = 0; | ||
336 | |||
337 | ep->pipectr = get_pipectr_addr(pipenum); | ||
338 | ep->pipenum = pipenum; | ||
339 | ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize); | ||
340 | r8a66597->pipenum2ep[pipenum] = ep; | ||
341 | r8a66597->epaddr2ep[desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK] | ||
342 | = ep; | ||
343 | INIT_LIST_HEAD(&ep->queue); | ||
344 | } | ||
345 | |||
346 | static void r8a66597_ep_release(struct r8a66597_ep *ep) | ||
347 | { | ||
348 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
349 | u16 pipenum = ep->pipenum; | ||
350 | |||
351 | if (pipenum == 0) | ||
352 | return; | ||
353 | |||
354 | if (ep->use_dma) | ||
355 | r8a66597->num_dma--; | ||
356 | ep->pipenum = 0; | ||
357 | ep->busy = 0; | ||
358 | ep->use_dma = 0; | ||
359 | } | ||
360 | |||
361 | static int alloc_pipe_config(struct r8a66597_ep *ep, | ||
362 | const struct usb_endpoint_descriptor *desc) | ||
363 | { | ||
364 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
365 | struct r8a66597_pipe_info info; | ||
366 | int dma = 0; | ||
367 | unsigned char *counter; | ||
368 | int ret; | ||
369 | |||
370 | ep->desc = desc; | ||
371 | |||
372 | if (ep->pipenum) /* already allocated pipe */ | ||
373 | return 0; | ||
374 | |||
375 | switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { | ||
376 | case USB_ENDPOINT_XFER_BULK: | ||
377 | if (r8a66597->bulk >= R8A66597_MAX_NUM_BULK) { | ||
378 | if (r8a66597->isochronous >= R8A66597_MAX_NUM_ISOC) { | ||
379 | printk(KERN_ERR "bulk pipe is insufficient\n"); | ||
380 | return -ENODEV; | ||
381 | } else { | ||
382 | info.pipe = R8A66597_BASE_PIPENUM_ISOC | ||
383 | + r8a66597->isochronous; | ||
384 | counter = &r8a66597->isochronous; | ||
385 | } | ||
386 | } else { | ||
387 | info.pipe = R8A66597_BASE_PIPENUM_BULK + r8a66597->bulk; | ||
388 | counter = &r8a66597->bulk; | ||
389 | } | ||
390 | info.type = R8A66597_BULK; | ||
391 | dma = 1; | ||
392 | break; | ||
393 | case USB_ENDPOINT_XFER_INT: | ||
394 | if (r8a66597->interrupt >= R8A66597_MAX_NUM_INT) { | ||
395 | printk(KERN_ERR "interrupt pipe is insufficient\n"); | ||
396 | return -ENODEV; | ||
397 | } | ||
398 | info.pipe = R8A66597_BASE_PIPENUM_INT + r8a66597->interrupt; | ||
399 | info.type = R8A66597_INT; | ||
400 | counter = &r8a66597->interrupt; | ||
401 | break; | ||
402 | case USB_ENDPOINT_XFER_ISOC: | ||
403 | if (r8a66597->isochronous >= R8A66597_MAX_NUM_ISOC) { | ||
404 | printk(KERN_ERR "isochronous pipe is insufficient\n"); | ||
405 | return -ENODEV; | ||
406 | } | ||
407 | info.pipe = R8A66597_BASE_PIPENUM_ISOC + r8a66597->isochronous; | ||
408 | info.type = R8A66597_ISO; | ||
409 | counter = &r8a66597->isochronous; | ||
410 | break; | ||
411 | default: | ||
412 | printk(KERN_ERR "unexpect xfer type\n"); | ||
413 | return -EINVAL; | ||
414 | } | ||
415 | ep->type = info.type; | ||
416 | |||
417 | info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; | ||
418 | info.maxpacket = le16_to_cpu(desc->wMaxPacketSize); | ||
419 | info.interval = desc->bInterval; | ||
420 | if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) | ||
421 | info.dir_in = 1; | ||
422 | else | ||
423 | info.dir_in = 0; | ||
424 | |||
425 | ret = pipe_buffer_setting(r8a66597, &info); | ||
426 | if (ret < 0) { | ||
427 | printk(KERN_ERR "pipe_buffer_setting fail\n"); | ||
428 | return ret; | ||
429 | } | ||
430 | |||
431 | (*counter)++; | ||
432 | if ((counter == &r8a66597->isochronous) && info.type == R8A66597_BULK) | ||
433 | r8a66597->bulk++; | ||
434 | |||
435 | r8a66597_ep_setting(r8a66597, ep, desc, info.pipe, dma); | ||
436 | pipe_initialize(ep); | ||
437 | |||
438 | return 0; | ||
439 | } | ||
440 | |||
441 | static int free_pipe_config(struct r8a66597_ep *ep) | ||
442 | { | ||
443 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
444 | struct r8a66597_pipe_info info; | ||
445 | |||
446 | info.pipe = ep->pipenum; | ||
447 | info.type = ep->type; | ||
448 | pipe_buffer_release(r8a66597, &info); | ||
449 | r8a66597_ep_release(ep); | ||
450 | |||
451 | return 0; | ||
452 | } | ||
453 | |||
454 | /*-------------------------------------------------------------------------*/ | ||
455 | static void pipe_irq_enable(struct r8a66597 *r8a66597, u16 pipenum) | ||
456 | { | ||
457 | enable_irq_ready(r8a66597, pipenum); | ||
458 | enable_irq_nrdy(r8a66597, pipenum); | ||
459 | } | ||
460 | |||
461 | static void pipe_irq_disable(struct r8a66597 *r8a66597, u16 pipenum) | ||
462 | { | ||
463 | disable_irq_ready(r8a66597, pipenum); | ||
464 | disable_irq_nrdy(r8a66597, pipenum); | ||
465 | } | ||
466 | |||
467 | /* if complete is true, gadget driver complete function is not call */ | ||
468 | static void control_end(struct r8a66597 *r8a66597, unsigned ccpl) | ||
469 | { | ||
470 | r8a66597->ep[0].internal_ccpl = ccpl; | ||
471 | pipe_start(r8a66597, 0); | ||
472 | r8a66597_bset(r8a66597, CCPL, DCPCTR); | ||
473 | } | ||
474 | |||
475 | static void start_ep0_write(struct r8a66597_ep *ep, | ||
476 | struct r8a66597_request *req) | ||
477 | { | ||
478 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
479 | |||
480 | pipe_change(r8a66597, ep->pipenum); | ||
481 | r8a66597_mdfy(r8a66597, ISEL, (ISEL | CURPIPE), CFIFOSEL); | ||
482 | r8a66597_write(r8a66597, BCLR, ep->fifoctr); | ||
483 | if (req->req.length == 0) { | ||
484 | r8a66597_bset(r8a66597, BVAL, ep->fifoctr); | ||
485 | pipe_start(r8a66597, 0); | ||
486 | transfer_complete(ep, req, 0); | ||
487 | } else { | ||
488 | r8a66597_write(r8a66597, ~BEMP0, BEMPSTS); | ||
489 | irq_ep0_write(ep, req); | ||
490 | } | ||
491 | } | ||
492 | |||
493 | static void start_packet_write(struct r8a66597_ep *ep, | ||
494 | struct r8a66597_request *req) | ||
495 | { | ||
496 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
497 | u16 tmp; | ||
498 | |||
499 | pipe_change(r8a66597, ep->pipenum); | ||
500 | disable_irq_empty(r8a66597, ep->pipenum); | ||
501 | pipe_start(r8a66597, ep->pipenum); | ||
502 | |||
503 | tmp = r8a66597_read(r8a66597, ep->fifoctr); | ||
504 | if (unlikely((tmp & FRDY) == 0)) | ||
505 | pipe_irq_enable(r8a66597, ep->pipenum); | ||
506 | else | ||
507 | irq_packet_write(ep, req); | ||
508 | } | ||
509 | |||
510 | static void start_packet_read(struct r8a66597_ep *ep, | ||
511 | struct r8a66597_request *req) | ||
512 | { | ||
513 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
514 | u16 pipenum = ep->pipenum; | ||
515 | |||
516 | if (ep->pipenum == 0) { | ||
517 | r8a66597_mdfy(r8a66597, 0, (ISEL | CURPIPE), CFIFOSEL); | ||
518 | r8a66597_write(r8a66597, BCLR, ep->fifoctr); | ||
519 | pipe_start(r8a66597, pipenum); | ||
520 | pipe_irq_enable(r8a66597, pipenum); | ||
521 | } else { | ||
522 | if (ep->use_dma) { | ||
523 | r8a66597_bset(r8a66597, TRCLR, ep->fifosel); | ||
524 | pipe_change(r8a66597, pipenum); | ||
525 | r8a66597_bset(r8a66597, TRENB, ep->fifosel); | ||
526 | r8a66597_write(r8a66597, | ||
527 | (req->req.length + ep->ep.maxpacket - 1) | ||
528 | / ep->ep.maxpacket, | ||
529 | ep->fifotrn); | ||
530 | } | ||
531 | pipe_start(r8a66597, pipenum); /* trigger once */ | ||
532 | pipe_irq_enable(r8a66597, pipenum); | ||
533 | } | ||
534 | } | ||
535 | |||
536 | static void start_packet(struct r8a66597_ep *ep, struct r8a66597_request *req) | ||
537 | { | ||
538 | if (ep->desc->bEndpointAddress & USB_DIR_IN) | ||
539 | start_packet_write(ep, req); | ||
540 | else | ||
541 | start_packet_read(ep, req); | ||
542 | } | ||
543 | |||
544 | static void start_ep0(struct r8a66597_ep *ep, struct r8a66597_request *req) | ||
545 | { | ||
546 | u16 ctsq; | ||
547 | |||
548 | ctsq = r8a66597_read(ep->r8a66597, INTSTS0) & CTSQ; | ||
549 | |||
550 | switch (ctsq) { | ||
551 | case CS_RDDS: | ||
552 | start_ep0_write(ep, req); | ||
553 | break; | ||
554 | case CS_WRDS: | ||
555 | start_packet_read(ep, req); | ||
556 | break; | ||
557 | |||
558 | case CS_WRND: | ||
559 | control_end(ep->r8a66597, 0); | ||
560 | break; | ||
561 | default: | ||
562 | printk(KERN_ERR "start_ep0: unexpect ctsq(%x)\n", ctsq); | ||
563 | break; | ||
564 | } | ||
565 | } | ||
566 | |||
567 | static void init_controller(struct r8a66597 *r8a66597) | ||
568 | { | ||
569 | u16 vif = r8a66597->pdata->vif ? LDRV : 0; | ||
570 | u16 irq_sense = r8a66597->irq_sense_low ? INTL : 0; | ||
571 | u16 endian = r8a66597->pdata->endian ? BIGEND : 0; | ||
572 | |||
573 | if (r8a66597->pdata->on_chip) { | ||
574 | r8a66597_bset(r8a66597, 0x04, SYSCFG1); | ||
575 | r8a66597_bset(r8a66597, HSE, SYSCFG0); | ||
576 | |||
577 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); | ||
578 | r8a66597_bclr(r8a66597, DPRPU, SYSCFG0); | ||
579 | r8a66597_bset(r8a66597, USBE, SYSCFG0); | ||
580 | |||
581 | r8a66597_bset(r8a66597, SCKE, SYSCFG0); | ||
582 | |||
583 | r8a66597_bset(r8a66597, irq_sense, INTENB1); | ||
584 | r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR, | ||
585 | DMA0CFG); | ||
586 | } else { | ||
587 | r8a66597_bset(r8a66597, vif | endian, PINCFG); | ||
588 | r8a66597_bset(r8a66597, HSE, SYSCFG0); /* High spd */ | ||
589 | r8a66597_mdfy(r8a66597, get_xtal_from_pdata(r8a66597->pdata), | ||
590 | XTAL, SYSCFG0); | ||
591 | |||
592 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); | ||
593 | r8a66597_bclr(r8a66597, DPRPU, SYSCFG0); | ||
594 | r8a66597_bset(r8a66597, USBE, SYSCFG0); | ||
595 | |||
596 | r8a66597_bset(r8a66597, XCKE, SYSCFG0); | ||
597 | |||
598 | msleep(3); | ||
599 | |||
600 | r8a66597_bset(r8a66597, PLLC, SYSCFG0); | ||
601 | |||
602 | msleep(1); | ||
603 | |||
604 | r8a66597_bset(r8a66597, SCKE, SYSCFG0); | ||
605 | |||
606 | r8a66597_bset(r8a66597, irq_sense, INTENB1); | ||
607 | r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR, | ||
608 | DMA0CFG); | ||
609 | } | ||
610 | } | ||
611 | |||
612 | static void disable_controller(struct r8a66597 *r8a66597) | ||
613 | { | ||
614 | if (r8a66597->pdata->on_chip) { | ||
615 | r8a66597_bset(r8a66597, SCKE, SYSCFG0); | ||
616 | |||
617 | /* disable interrupts */ | ||
618 | r8a66597_write(r8a66597, 0, INTENB0); | ||
619 | r8a66597_write(r8a66597, 0, INTENB1); | ||
620 | r8a66597_write(r8a66597, 0, BRDYENB); | ||
621 | r8a66597_write(r8a66597, 0, BEMPENB); | ||
622 | r8a66597_write(r8a66597, 0, NRDYENB); | ||
623 | |||
624 | /* clear status */ | ||
625 | r8a66597_write(r8a66597, 0, BRDYSTS); | ||
626 | r8a66597_write(r8a66597, 0, NRDYSTS); | ||
627 | r8a66597_write(r8a66597, 0, BEMPSTS); | ||
628 | |||
629 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); | ||
630 | r8a66597_bclr(r8a66597, SCKE, SYSCFG0); | ||
631 | |||
632 | } else { | ||
633 | r8a66597_bclr(r8a66597, SCKE, SYSCFG0); | ||
634 | udelay(1); | ||
635 | r8a66597_bclr(r8a66597, PLLC, SYSCFG0); | ||
636 | udelay(1); | ||
637 | udelay(1); | ||
638 | r8a66597_bclr(r8a66597, XCKE, SYSCFG0); | ||
639 | } | ||
640 | } | ||
641 | |||
642 | static void r8a66597_start_xclock(struct r8a66597 *r8a66597) | ||
643 | { | ||
644 | u16 tmp; | ||
645 | |||
646 | if (!r8a66597->pdata->on_chip) { | ||
647 | tmp = r8a66597_read(r8a66597, SYSCFG0); | ||
648 | if (!(tmp & XCKE)) | ||
649 | r8a66597_bset(r8a66597, XCKE, SYSCFG0); | ||
650 | } | ||
651 | } | ||
652 | |||
653 | static struct r8a66597_request *get_request_from_ep(struct r8a66597_ep *ep) | ||
654 | { | ||
655 | return list_entry(ep->queue.next, struct r8a66597_request, queue); | ||
656 | } | ||
657 | |||
658 | /*-------------------------------------------------------------------------*/ | ||
659 | static void transfer_complete(struct r8a66597_ep *ep, | ||
660 | struct r8a66597_request *req, int status) | ||
661 | __releases(r8a66597->lock) | ||
662 | __acquires(r8a66597->lock) | ||
663 | { | ||
664 | int restart = 0; | ||
665 | |||
666 | if (unlikely(ep->pipenum == 0)) { | ||
667 | if (ep->internal_ccpl) { | ||
668 | ep->internal_ccpl = 0; | ||
669 | return; | ||
670 | } | ||
671 | } | ||
672 | |||
673 | list_del_init(&req->queue); | ||
674 | if (ep->r8a66597->gadget.speed == USB_SPEED_UNKNOWN) | ||
675 | req->req.status = -ESHUTDOWN; | ||
676 | else | ||
677 | req->req.status = status; | ||
678 | |||
679 | if (!list_empty(&ep->queue)) | ||
680 | restart = 1; | ||
681 | |||
682 | spin_unlock(&ep->r8a66597->lock); | ||
683 | req->req.complete(&ep->ep, &req->req); | ||
684 | spin_lock(&ep->r8a66597->lock); | ||
685 | |||
686 | if (restart) { | ||
687 | req = get_request_from_ep(ep); | ||
688 | if (ep->desc) | ||
689 | start_packet(ep, req); | ||
690 | } | ||
691 | } | ||
692 | |||
693 | static void irq_ep0_write(struct r8a66597_ep *ep, struct r8a66597_request *req) | ||
694 | { | ||
695 | int i; | ||
696 | u16 tmp; | ||
697 | unsigned bufsize; | ||
698 | size_t size; | ||
699 | void *buf; | ||
700 | u16 pipenum = ep->pipenum; | ||
701 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
702 | |||
703 | pipe_change(r8a66597, pipenum); | ||
704 | r8a66597_bset(r8a66597, ISEL, ep->fifosel); | ||
705 | |||
706 | i = 0; | ||
707 | do { | ||
708 | tmp = r8a66597_read(r8a66597, ep->fifoctr); | ||
709 | if (i++ > 100000) { | ||
710 | printk(KERN_ERR "pipe0 is busy. maybe cpu i/o bus" | ||
711 | "conflict. please power off this controller."); | ||
712 | return; | ||
713 | } | ||
714 | ndelay(1); | ||
715 | } while ((tmp & FRDY) == 0); | ||
716 | |||
717 | /* prepare parameters */ | ||
718 | bufsize = get_buffer_size(r8a66597, pipenum); | ||
719 | buf = req->req.buf + req->req.actual; | ||
720 | size = min(bufsize, req->req.length - req->req.actual); | ||
721 | |||
722 | /* write fifo */ | ||
723 | if (req->req.buf) { | ||
724 | if (size > 0) | ||
725 | r8a66597_write_fifo(r8a66597, ep->fifoaddr, buf, size); | ||
726 | if ((size == 0) || ((size % ep->ep.maxpacket) != 0)) | ||
727 | r8a66597_bset(r8a66597, BVAL, ep->fifoctr); | ||
728 | } | ||
729 | |||
730 | /* update parameters */ | ||
731 | req->req.actual += size; | ||
732 | |||
733 | /* check transfer finish */ | ||
734 | if ((!req->req.zero && (req->req.actual == req->req.length)) | ||
735 | || (size % ep->ep.maxpacket) | ||
736 | || (size == 0)) { | ||
737 | disable_irq_ready(r8a66597, pipenum); | ||
738 | disable_irq_empty(r8a66597, pipenum); | ||
739 | } else { | ||
740 | disable_irq_ready(r8a66597, pipenum); | ||
741 | enable_irq_empty(r8a66597, pipenum); | ||
742 | } | ||
743 | pipe_start(r8a66597, pipenum); | ||
744 | } | ||
745 | |||
746 | static void irq_packet_write(struct r8a66597_ep *ep, | ||
747 | struct r8a66597_request *req) | ||
748 | { | ||
749 | u16 tmp; | ||
750 | unsigned bufsize; | ||
751 | size_t size; | ||
752 | void *buf; | ||
753 | u16 pipenum = ep->pipenum; | ||
754 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
755 | |||
756 | pipe_change(r8a66597, pipenum); | ||
757 | tmp = r8a66597_read(r8a66597, ep->fifoctr); | ||
758 | if (unlikely((tmp & FRDY) == 0)) { | ||
759 | pipe_stop(r8a66597, pipenum); | ||
760 | pipe_irq_disable(r8a66597, pipenum); | ||
761 | printk(KERN_ERR "write fifo not ready. pipnum=%d\n", pipenum); | ||
762 | return; | ||
763 | } | ||
764 | |||
765 | /* prepare parameters */ | ||
766 | bufsize = get_buffer_size(r8a66597, pipenum); | ||
767 | buf = req->req.buf + req->req.actual; | ||
768 | size = min(bufsize, req->req.length - req->req.actual); | ||
769 | |||
770 | /* write fifo */ | ||
771 | if (req->req.buf) { | ||
772 | r8a66597_write_fifo(r8a66597, ep->fifoaddr, buf, size); | ||
773 | if ((size == 0) | ||
774 | || ((size % ep->ep.maxpacket) != 0) | ||
775 | || ((bufsize != ep->ep.maxpacket) | ||
776 | && (bufsize > size))) | ||
777 | r8a66597_bset(r8a66597, BVAL, ep->fifoctr); | ||
778 | } | ||
779 | |||
780 | /* update parameters */ | ||
781 | req->req.actual += size; | ||
782 | /* check transfer finish */ | ||
783 | if ((!req->req.zero && (req->req.actual == req->req.length)) | ||
784 | || (size % ep->ep.maxpacket) | ||
785 | || (size == 0)) { | ||
786 | disable_irq_ready(r8a66597, pipenum); | ||
787 | enable_irq_empty(r8a66597, pipenum); | ||
788 | } else { | ||
789 | disable_irq_empty(r8a66597, pipenum); | ||
790 | pipe_irq_enable(r8a66597, pipenum); | ||
791 | } | ||
792 | } | ||
793 | |||
794 | static void irq_packet_read(struct r8a66597_ep *ep, | ||
795 | struct r8a66597_request *req) | ||
796 | { | ||
797 | u16 tmp; | ||
798 | int rcv_len, bufsize, req_len; | ||
799 | int size; | ||
800 | void *buf; | ||
801 | u16 pipenum = ep->pipenum; | ||
802 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
803 | int finish = 0; | ||
804 | |||
805 | pipe_change(r8a66597, pipenum); | ||
806 | tmp = r8a66597_read(r8a66597, ep->fifoctr); | ||
807 | if (unlikely((tmp & FRDY) == 0)) { | ||
808 | req->req.status = -EPIPE; | ||
809 | pipe_stop(r8a66597, pipenum); | ||
810 | pipe_irq_disable(r8a66597, pipenum); | ||
811 | printk(KERN_ERR "read fifo not ready"); | ||
812 | return; | ||
813 | } | ||
814 | |||
815 | /* prepare parameters */ | ||
816 | rcv_len = tmp & DTLN; | ||
817 | bufsize = get_buffer_size(r8a66597, pipenum); | ||
818 | |||
819 | buf = req->req.buf + req->req.actual; | ||
820 | req_len = req->req.length - req->req.actual; | ||
821 | if (rcv_len < bufsize) | ||
822 | size = min(rcv_len, req_len); | ||
823 | else | ||
824 | size = min(bufsize, req_len); | ||
825 | |||
826 | /* update parameters */ | ||
827 | req->req.actual += size; | ||
828 | |||
829 | /* check transfer finish */ | ||
830 | if ((!req->req.zero && (req->req.actual == req->req.length)) | ||
831 | || (size % ep->ep.maxpacket) | ||
832 | || (size == 0)) { | ||
833 | pipe_stop(r8a66597, pipenum); | ||
834 | pipe_irq_disable(r8a66597, pipenum); | ||
835 | finish = 1; | ||
836 | } | ||
837 | |||
838 | /* read fifo */ | ||
839 | if (req->req.buf) { | ||
840 | if (size == 0) | ||
841 | r8a66597_write(r8a66597, BCLR, ep->fifoctr); | ||
842 | else | ||
843 | r8a66597_read_fifo(r8a66597, ep->fifoaddr, buf, size); | ||
844 | |||
845 | } | ||
846 | |||
847 | if ((ep->pipenum != 0) && finish) | ||
848 | transfer_complete(ep, req, 0); | ||
849 | } | ||
850 | |||
851 | static void irq_pipe_ready(struct r8a66597 *r8a66597, u16 status, u16 enb) | ||
852 | { | ||
853 | u16 check; | ||
854 | u16 pipenum; | ||
855 | struct r8a66597_ep *ep; | ||
856 | struct r8a66597_request *req; | ||
857 | |||
858 | if ((status & BRDY0) && (enb & BRDY0)) { | ||
859 | r8a66597_write(r8a66597, ~BRDY0, BRDYSTS); | ||
860 | r8a66597_mdfy(r8a66597, 0, CURPIPE, CFIFOSEL); | ||
861 | |||
862 | ep = &r8a66597->ep[0]; | ||
863 | req = get_request_from_ep(ep); | ||
864 | irq_packet_read(ep, req); | ||
865 | } else { | ||
866 | for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { | ||
867 | check = 1 << pipenum; | ||
868 | if ((status & check) && (enb & check)) { | ||
869 | r8a66597_write(r8a66597, ~check, BRDYSTS); | ||
870 | ep = r8a66597->pipenum2ep[pipenum]; | ||
871 | req = get_request_from_ep(ep); | ||
872 | if (ep->desc->bEndpointAddress & USB_DIR_IN) | ||
873 | irq_packet_write(ep, req); | ||
874 | else | ||
875 | irq_packet_read(ep, req); | ||
876 | } | ||
877 | } | ||
878 | } | ||
879 | } | ||
880 | |||
881 | static void irq_pipe_empty(struct r8a66597 *r8a66597, u16 status, u16 enb) | ||
882 | { | ||
883 | u16 tmp; | ||
884 | u16 check; | ||
885 | u16 pipenum; | ||
886 | struct r8a66597_ep *ep; | ||
887 | struct r8a66597_request *req; | ||
888 | |||
889 | if ((status & BEMP0) && (enb & BEMP0)) { | ||
890 | r8a66597_write(r8a66597, ~BEMP0, BEMPSTS); | ||
891 | |||
892 | ep = &r8a66597->ep[0]; | ||
893 | req = get_request_from_ep(ep); | ||
894 | irq_ep0_write(ep, req); | ||
895 | } else { | ||
896 | for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { | ||
897 | check = 1 << pipenum; | ||
898 | if ((status & check) && (enb & check)) { | ||
899 | r8a66597_write(r8a66597, ~check, BEMPSTS); | ||
900 | tmp = control_reg_get(r8a66597, pipenum); | ||
901 | if ((tmp & INBUFM) == 0) { | ||
902 | disable_irq_empty(r8a66597, pipenum); | ||
903 | pipe_irq_disable(r8a66597, pipenum); | ||
904 | pipe_stop(r8a66597, pipenum); | ||
905 | ep = r8a66597->pipenum2ep[pipenum]; | ||
906 | req = get_request_from_ep(ep); | ||
907 | if (!list_empty(&ep->queue)) | ||
908 | transfer_complete(ep, req, 0); | ||
909 | } | ||
910 | } | ||
911 | } | ||
912 | } | ||
913 | } | ||
914 | |||
915 | static void get_status(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl) | ||
916 | __releases(r8a66597->lock) | ||
917 | __acquires(r8a66597->lock) | ||
918 | { | ||
919 | struct r8a66597_ep *ep; | ||
920 | u16 pid; | ||
921 | u16 status = 0; | ||
922 | u16 w_index = le16_to_cpu(ctrl->wIndex); | ||
923 | |||
924 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | ||
925 | case USB_RECIP_DEVICE: | ||
926 | status = 1 << USB_DEVICE_SELF_POWERED; | ||
927 | break; | ||
928 | case USB_RECIP_INTERFACE: | ||
929 | status = 0; | ||
930 | break; | ||
931 | case USB_RECIP_ENDPOINT: | ||
932 | ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK]; | ||
933 | pid = control_reg_get_pid(r8a66597, ep->pipenum); | ||
934 | if (pid == PID_STALL) | ||
935 | status = 1 << USB_ENDPOINT_HALT; | ||
936 | else | ||
937 | status = 0; | ||
938 | break; | ||
939 | default: | ||
940 | pipe_stall(r8a66597, 0); | ||
941 | return; /* exit */ | ||
942 | } | ||
943 | |||
944 | r8a66597->ep0_data = cpu_to_le16(status); | ||
945 | r8a66597->ep0_req->buf = &r8a66597->ep0_data; | ||
946 | r8a66597->ep0_req->length = 2; | ||
947 | /* AV: what happens if we get called again before that gets through? */ | ||
948 | spin_unlock(&r8a66597->lock); | ||
949 | r8a66597_queue(r8a66597->gadget.ep0, r8a66597->ep0_req, GFP_KERNEL); | ||
950 | spin_lock(&r8a66597->lock); | ||
951 | } | ||
952 | |||
953 | static void clear_feature(struct r8a66597 *r8a66597, | ||
954 | struct usb_ctrlrequest *ctrl) | ||
955 | { | ||
956 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | ||
957 | case USB_RECIP_DEVICE: | ||
958 | control_end(r8a66597, 1); | ||
959 | break; | ||
960 | case USB_RECIP_INTERFACE: | ||
961 | control_end(r8a66597, 1); | ||
962 | break; | ||
963 | case USB_RECIP_ENDPOINT: { | ||
964 | struct r8a66597_ep *ep; | ||
965 | struct r8a66597_request *req; | ||
966 | u16 w_index = le16_to_cpu(ctrl->wIndex); | ||
967 | |||
968 | ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK]; | ||
969 | if (!ep->wedge) { | ||
970 | pipe_stop(r8a66597, ep->pipenum); | ||
971 | control_reg_sqclr(r8a66597, ep->pipenum); | ||
972 | spin_unlock(&r8a66597->lock); | ||
973 | usb_ep_clear_halt(&ep->ep); | ||
974 | spin_lock(&r8a66597->lock); | ||
975 | } | ||
976 | |||
977 | control_end(r8a66597, 1); | ||
978 | |||
979 | req = get_request_from_ep(ep); | ||
980 | if (ep->busy) { | ||
981 | ep->busy = 0; | ||
982 | if (list_empty(&ep->queue)) | ||
983 | break; | ||
984 | start_packet(ep, req); | ||
985 | } else if (!list_empty(&ep->queue)) | ||
986 | pipe_start(r8a66597, ep->pipenum); | ||
987 | } | ||
988 | break; | ||
989 | default: | ||
990 | pipe_stall(r8a66597, 0); | ||
991 | break; | ||
992 | } | ||
993 | } | ||
994 | |||
995 | static void set_feature(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl) | ||
996 | { | ||
997 | |||
998 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | ||
999 | case USB_RECIP_DEVICE: | ||
1000 | control_end(r8a66597, 1); | ||
1001 | break; | ||
1002 | case USB_RECIP_INTERFACE: | ||
1003 | control_end(r8a66597, 1); | ||
1004 | break; | ||
1005 | case USB_RECIP_ENDPOINT: { | ||
1006 | struct r8a66597_ep *ep; | ||
1007 | u16 w_index = le16_to_cpu(ctrl->wIndex); | ||
1008 | |||
1009 | ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK]; | ||
1010 | pipe_stall(r8a66597, ep->pipenum); | ||
1011 | |||
1012 | control_end(r8a66597, 1); | ||
1013 | } | ||
1014 | break; | ||
1015 | default: | ||
1016 | pipe_stall(r8a66597, 0); | ||
1017 | break; | ||
1018 | } | ||
1019 | } | ||
1020 | |||
1021 | /* if return value is true, call class driver's setup() */ | ||
1022 | static int setup_packet(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl) | ||
1023 | { | ||
1024 | u16 *p = (u16 *)ctrl; | ||
1025 | unsigned long offset = USBREQ; | ||
1026 | int i, ret = 0; | ||
1027 | |||
1028 | /* read fifo */ | ||
1029 | r8a66597_write(r8a66597, ~VALID, INTSTS0); | ||
1030 | |||
1031 | for (i = 0; i < 4; i++) | ||
1032 | p[i] = r8a66597_read(r8a66597, offset + i*2); | ||
1033 | |||
1034 | /* check request */ | ||
1035 | if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { | ||
1036 | switch (ctrl->bRequest) { | ||
1037 | case USB_REQ_GET_STATUS: | ||
1038 | get_status(r8a66597, ctrl); | ||
1039 | break; | ||
1040 | case USB_REQ_CLEAR_FEATURE: | ||
1041 | clear_feature(r8a66597, ctrl); | ||
1042 | break; | ||
1043 | case USB_REQ_SET_FEATURE: | ||
1044 | set_feature(r8a66597, ctrl); | ||
1045 | break; | ||
1046 | default: | ||
1047 | ret = 1; | ||
1048 | break; | ||
1049 | } | ||
1050 | } else | ||
1051 | ret = 1; | ||
1052 | return ret; | ||
1053 | } | ||
1054 | |||
1055 | static void r8a66597_update_usb_speed(struct r8a66597 *r8a66597) | ||
1056 | { | ||
1057 | u16 speed = get_usb_speed(r8a66597); | ||
1058 | |||
1059 | switch (speed) { | ||
1060 | case HSMODE: | ||
1061 | r8a66597->gadget.speed = USB_SPEED_HIGH; | ||
1062 | break; | ||
1063 | case FSMODE: | ||
1064 | r8a66597->gadget.speed = USB_SPEED_FULL; | ||
1065 | break; | ||
1066 | default: | ||
1067 | r8a66597->gadget.speed = USB_SPEED_UNKNOWN; | ||
1068 | printk(KERN_ERR "USB speed unknown\n"); | ||
1069 | } | ||
1070 | } | ||
1071 | |||
1072 | static void irq_device_state(struct r8a66597 *r8a66597) | ||
1073 | { | ||
1074 | u16 dvsq; | ||
1075 | |||
1076 | dvsq = r8a66597_read(r8a66597, INTSTS0) & DVSQ; | ||
1077 | r8a66597_write(r8a66597, ~DVST, INTSTS0); | ||
1078 | |||
1079 | if (dvsq == DS_DFLT) { | ||
1080 | /* bus reset */ | ||
1081 | r8a66597->driver->disconnect(&r8a66597->gadget); | ||
1082 | r8a66597_update_usb_speed(r8a66597); | ||
1083 | } | ||
1084 | if (r8a66597->old_dvsq == DS_CNFG && dvsq != DS_CNFG) | ||
1085 | r8a66597_update_usb_speed(r8a66597); | ||
1086 | if ((dvsq == DS_CNFG || dvsq == DS_ADDS) | ||
1087 | && r8a66597->gadget.speed == USB_SPEED_UNKNOWN) | ||
1088 | r8a66597_update_usb_speed(r8a66597); | ||
1089 | |||
1090 | r8a66597->old_dvsq = dvsq; | ||
1091 | } | ||
1092 | |||
1093 | static void irq_control_stage(struct r8a66597 *r8a66597) | ||
1094 | __releases(r8a66597->lock) | ||
1095 | __acquires(r8a66597->lock) | ||
1096 | { | ||
1097 | struct usb_ctrlrequest ctrl; | ||
1098 | u16 ctsq; | ||
1099 | |||
1100 | ctsq = r8a66597_read(r8a66597, INTSTS0) & CTSQ; | ||
1101 | r8a66597_write(r8a66597, ~CTRT, INTSTS0); | ||
1102 | |||
1103 | switch (ctsq) { | ||
1104 | case CS_IDST: { | ||
1105 | struct r8a66597_ep *ep; | ||
1106 | struct r8a66597_request *req; | ||
1107 | ep = &r8a66597->ep[0]; | ||
1108 | req = get_request_from_ep(ep); | ||
1109 | transfer_complete(ep, req, 0); | ||
1110 | } | ||
1111 | break; | ||
1112 | |||
1113 | case CS_RDDS: | ||
1114 | case CS_WRDS: | ||
1115 | case CS_WRND: | ||
1116 | if (setup_packet(r8a66597, &ctrl)) { | ||
1117 | spin_unlock(&r8a66597->lock); | ||
1118 | if (r8a66597->driver->setup(&r8a66597->gadget, &ctrl) | ||
1119 | < 0) | ||
1120 | pipe_stall(r8a66597, 0); | ||
1121 | spin_lock(&r8a66597->lock); | ||
1122 | } | ||
1123 | break; | ||
1124 | case CS_RDSS: | ||
1125 | case CS_WRSS: | ||
1126 | control_end(r8a66597, 0); | ||
1127 | break; | ||
1128 | default: | ||
1129 | printk(KERN_ERR "ctrl_stage: unexpect ctsq(%x)\n", ctsq); | ||
1130 | break; | ||
1131 | } | ||
1132 | } | ||
1133 | |||
1134 | static irqreturn_t r8a66597_irq(int irq, void *_r8a66597) | ||
1135 | { | ||
1136 | struct r8a66597 *r8a66597 = _r8a66597; | ||
1137 | u16 intsts0; | ||
1138 | u16 intenb0; | ||
1139 | u16 brdysts, nrdysts, bempsts; | ||
1140 | u16 brdyenb, nrdyenb, bempenb; | ||
1141 | u16 savepipe; | ||
1142 | u16 mask0; | ||
1143 | |||
1144 | spin_lock(&r8a66597->lock); | ||
1145 | |||
1146 | intsts0 = r8a66597_read(r8a66597, INTSTS0); | ||
1147 | intenb0 = r8a66597_read(r8a66597, INTENB0); | ||
1148 | |||
1149 | savepipe = r8a66597_read(r8a66597, CFIFOSEL); | ||
1150 | |||
1151 | mask0 = intsts0 & intenb0; | ||
1152 | if (mask0) { | ||
1153 | brdysts = r8a66597_read(r8a66597, BRDYSTS); | ||
1154 | nrdysts = r8a66597_read(r8a66597, NRDYSTS); | ||
1155 | bempsts = r8a66597_read(r8a66597, BEMPSTS); | ||
1156 | brdyenb = r8a66597_read(r8a66597, BRDYENB); | ||
1157 | nrdyenb = r8a66597_read(r8a66597, NRDYENB); | ||
1158 | bempenb = r8a66597_read(r8a66597, BEMPENB); | ||
1159 | |||
1160 | if (mask0 & VBINT) { | ||
1161 | r8a66597_write(r8a66597, 0xffff & ~VBINT, | ||
1162 | INTSTS0); | ||
1163 | r8a66597_start_xclock(r8a66597); | ||
1164 | |||
1165 | /* start vbus sampling */ | ||
1166 | r8a66597->old_vbus = r8a66597_read(r8a66597, INTSTS0) | ||
1167 | & VBSTS; | ||
1168 | r8a66597->scount = R8A66597_MAX_SAMPLING; | ||
1169 | |||
1170 | mod_timer(&r8a66597->timer, | ||
1171 | jiffies + msecs_to_jiffies(50)); | ||
1172 | } | ||
1173 | if (intsts0 & DVSQ) | ||
1174 | irq_device_state(r8a66597); | ||
1175 | |||
1176 | if ((intsts0 & BRDY) && (intenb0 & BRDYE) | ||
1177 | && (brdysts & brdyenb)) | ||
1178 | irq_pipe_ready(r8a66597, brdysts, brdyenb); | ||
1179 | if ((intsts0 & BEMP) && (intenb0 & BEMPE) | ||
1180 | && (bempsts & bempenb)) | ||
1181 | irq_pipe_empty(r8a66597, bempsts, bempenb); | ||
1182 | |||
1183 | if (intsts0 & CTRT) | ||
1184 | irq_control_stage(r8a66597); | ||
1185 | } | ||
1186 | |||
1187 | r8a66597_write(r8a66597, savepipe, CFIFOSEL); | ||
1188 | |||
1189 | spin_unlock(&r8a66597->lock); | ||
1190 | return IRQ_HANDLED; | ||
1191 | } | ||
1192 | |||
1193 | static void r8a66597_timer(unsigned long _r8a66597) | ||
1194 | { | ||
1195 | struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597; | ||
1196 | unsigned long flags; | ||
1197 | u16 tmp; | ||
1198 | |||
1199 | spin_lock_irqsave(&r8a66597->lock, flags); | ||
1200 | tmp = r8a66597_read(r8a66597, SYSCFG0); | ||
1201 | if (r8a66597->scount > 0) { | ||
1202 | tmp = r8a66597_read(r8a66597, INTSTS0) & VBSTS; | ||
1203 | if (tmp == r8a66597->old_vbus) { | ||
1204 | r8a66597->scount--; | ||
1205 | if (r8a66597->scount == 0) { | ||
1206 | if (tmp == VBSTS) | ||
1207 | r8a66597_usb_connect(r8a66597); | ||
1208 | else | ||
1209 | r8a66597_usb_disconnect(r8a66597); | ||
1210 | } else { | ||
1211 | mod_timer(&r8a66597->timer, | ||
1212 | jiffies + msecs_to_jiffies(50)); | ||
1213 | } | ||
1214 | } else { | ||
1215 | r8a66597->scount = R8A66597_MAX_SAMPLING; | ||
1216 | r8a66597->old_vbus = tmp; | ||
1217 | mod_timer(&r8a66597->timer, | ||
1218 | jiffies + msecs_to_jiffies(50)); | ||
1219 | } | ||
1220 | } | ||
1221 | spin_unlock_irqrestore(&r8a66597->lock, flags); | ||
1222 | } | ||
1223 | |||
1224 | /*-------------------------------------------------------------------------*/ | ||
1225 | static int r8a66597_enable(struct usb_ep *_ep, | ||
1226 | const struct usb_endpoint_descriptor *desc) | ||
1227 | { | ||
1228 | struct r8a66597_ep *ep; | ||
1229 | |||
1230 | ep = container_of(_ep, struct r8a66597_ep, ep); | ||
1231 | return alloc_pipe_config(ep, desc); | ||
1232 | } | ||
1233 | |||
1234 | static int r8a66597_disable(struct usb_ep *_ep) | ||
1235 | { | ||
1236 | struct r8a66597_ep *ep; | ||
1237 | struct r8a66597_request *req; | ||
1238 | unsigned long flags; | ||
1239 | |||
1240 | ep = container_of(_ep, struct r8a66597_ep, ep); | ||
1241 | BUG_ON(!ep); | ||
1242 | |||
1243 | while (!list_empty(&ep->queue)) { | ||
1244 | req = get_request_from_ep(ep); | ||
1245 | spin_lock_irqsave(&ep->r8a66597->lock, flags); | ||
1246 | transfer_complete(ep, req, -ECONNRESET); | ||
1247 | spin_unlock_irqrestore(&ep->r8a66597->lock, flags); | ||
1248 | } | ||
1249 | |||
1250 | pipe_irq_disable(ep->r8a66597, ep->pipenum); | ||
1251 | return free_pipe_config(ep); | ||
1252 | } | ||
1253 | |||
1254 | static struct usb_request *r8a66597_alloc_request(struct usb_ep *_ep, | ||
1255 | gfp_t gfp_flags) | ||
1256 | { | ||
1257 | struct r8a66597_request *req; | ||
1258 | |||
1259 | req = kzalloc(sizeof(struct r8a66597_request), gfp_flags); | ||
1260 | if (!req) | ||
1261 | return NULL; | ||
1262 | |||
1263 | INIT_LIST_HEAD(&req->queue); | ||
1264 | |||
1265 | return &req->req; | ||
1266 | } | ||
1267 | |||
1268 | static void r8a66597_free_request(struct usb_ep *_ep, struct usb_request *_req) | ||
1269 | { | ||
1270 | struct r8a66597_request *req; | ||
1271 | |||
1272 | req = container_of(_req, struct r8a66597_request, req); | ||
1273 | kfree(req); | ||
1274 | } | ||
1275 | |||
1276 | static int r8a66597_queue(struct usb_ep *_ep, struct usb_request *_req, | ||
1277 | gfp_t gfp_flags) | ||
1278 | { | ||
1279 | struct r8a66597_ep *ep; | ||
1280 | struct r8a66597_request *req; | ||
1281 | unsigned long flags; | ||
1282 | int request = 0; | ||
1283 | |||
1284 | ep = container_of(_ep, struct r8a66597_ep, ep); | ||
1285 | req = container_of(_req, struct r8a66597_request, req); | ||
1286 | |||
1287 | if (ep->r8a66597->gadget.speed == USB_SPEED_UNKNOWN) | ||
1288 | return -ESHUTDOWN; | ||
1289 | |||
1290 | spin_lock_irqsave(&ep->r8a66597->lock, flags); | ||
1291 | |||
1292 | if (list_empty(&ep->queue)) | ||
1293 | request = 1; | ||
1294 | |||
1295 | list_add_tail(&req->queue, &ep->queue); | ||
1296 | req->req.actual = 0; | ||
1297 | req->req.status = -EINPROGRESS; | ||
1298 | |||
1299 | if (ep->desc == NULL) /* control */ | ||
1300 | start_ep0(ep, req); | ||
1301 | else { | ||
1302 | if (request && !ep->busy) | ||
1303 | start_packet(ep, req); | ||
1304 | } | ||
1305 | |||
1306 | spin_unlock_irqrestore(&ep->r8a66597->lock, flags); | ||
1307 | |||
1308 | return 0; | ||
1309 | } | ||
1310 | |||
1311 | static int r8a66597_dequeue(struct usb_ep *_ep, struct usb_request *_req) | ||
1312 | { | ||
1313 | struct r8a66597_ep *ep; | ||
1314 | struct r8a66597_request *req; | ||
1315 | unsigned long flags; | ||
1316 | |||
1317 | ep = container_of(_ep, struct r8a66597_ep, ep); | ||
1318 | req = container_of(_req, struct r8a66597_request, req); | ||
1319 | |||
1320 | spin_lock_irqsave(&ep->r8a66597->lock, flags); | ||
1321 | if (!list_empty(&ep->queue)) | ||
1322 | transfer_complete(ep, req, -ECONNRESET); | ||
1323 | spin_unlock_irqrestore(&ep->r8a66597->lock, flags); | ||
1324 | |||
1325 | return 0; | ||
1326 | } | ||
1327 | |||
1328 | static int r8a66597_set_halt(struct usb_ep *_ep, int value) | ||
1329 | { | ||
1330 | struct r8a66597_ep *ep; | ||
1331 | struct r8a66597_request *req; | ||
1332 | unsigned long flags; | ||
1333 | int ret = 0; | ||
1334 | |||
1335 | ep = container_of(_ep, struct r8a66597_ep, ep); | ||
1336 | req = get_request_from_ep(ep); | ||
1337 | |||
1338 | spin_lock_irqsave(&ep->r8a66597->lock, flags); | ||
1339 | if (!list_empty(&ep->queue)) { | ||
1340 | ret = -EAGAIN; | ||
1341 | goto out; | ||
1342 | } | ||
1343 | if (value) { | ||
1344 | ep->busy = 1; | ||
1345 | pipe_stall(ep->r8a66597, ep->pipenum); | ||
1346 | } else { | ||
1347 | ep->busy = 0; | ||
1348 | ep->wedge = 0; | ||
1349 | pipe_stop(ep->r8a66597, ep->pipenum); | ||
1350 | } | ||
1351 | |||
1352 | out: | ||
1353 | spin_unlock_irqrestore(&ep->r8a66597->lock, flags); | ||
1354 | return ret; | ||
1355 | } | ||
1356 | |||
1357 | static int r8a66597_set_wedge(struct usb_ep *_ep) | ||
1358 | { | ||
1359 | struct r8a66597_ep *ep; | ||
1360 | unsigned long flags; | ||
1361 | |||
1362 | ep = container_of(_ep, struct r8a66597_ep, ep); | ||
1363 | |||
1364 | if (!ep || !ep->desc) | ||
1365 | return -EINVAL; | ||
1366 | |||
1367 | spin_lock_irqsave(&ep->r8a66597->lock, flags); | ||
1368 | ep->wedge = 1; | ||
1369 | spin_unlock_irqrestore(&ep->r8a66597->lock, flags); | ||
1370 | |||
1371 | return usb_ep_set_halt(_ep); | ||
1372 | } | ||
1373 | |||
1374 | static void r8a66597_fifo_flush(struct usb_ep *_ep) | ||
1375 | { | ||
1376 | struct r8a66597_ep *ep; | ||
1377 | unsigned long flags; | ||
1378 | |||
1379 | ep = container_of(_ep, struct r8a66597_ep, ep); | ||
1380 | spin_lock_irqsave(&ep->r8a66597->lock, flags); | ||
1381 | if (list_empty(&ep->queue) && !ep->busy) { | ||
1382 | pipe_stop(ep->r8a66597, ep->pipenum); | ||
1383 | r8a66597_bclr(ep->r8a66597, BCLR, ep->fifoctr); | ||
1384 | } | ||
1385 | spin_unlock_irqrestore(&ep->r8a66597->lock, flags); | ||
1386 | } | ||
1387 | |||
1388 | static struct usb_ep_ops r8a66597_ep_ops = { | ||
1389 | .enable = r8a66597_enable, | ||
1390 | .disable = r8a66597_disable, | ||
1391 | |||
1392 | .alloc_request = r8a66597_alloc_request, | ||
1393 | .free_request = r8a66597_free_request, | ||
1394 | |||
1395 | .queue = r8a66597_queue, | ||
1396 | .dequeue = r8a66597_dequeue, | ||
1397 | |||
1398 | .set_halt = r8a66597_set_halt, | ||
1399 | .set_wedge = r8a66597_set_wedge, | ||
1400 | .fifo_flush = r8a66597_fifo_flush, | ||
1401 | }; | ||
1402 | |||
1403 | /*-------------------------------------------------------------------------*/ | ||
1404 | static struct r8a66597 *the_controller; | ||
1405 | |||
1406 | int usb_gadget_register_driver(struct usb_gadget_driver *driver) | ||
1407 | { | ||
1408 | struct r8a66597 *r8a66597 = the_controller; | ||
1409 | int retval; | ||
1410 | |||
1411 | if (!driver | ||
1412 | || driver->speed != USB_SPEED_HIGH | ||
1413 | || !driver->bind | ||
1414 | || !driver->setup) | ||
1415 | return -EINVAL; | ||
1416 | if (!r8a66597) | ||
1417 | return -ENODEV; | ||
1418 | if (r8a66597->driver) | ||
1419 | return -EBUSY; | ||
1420 | |||
1421 | /* hook up the driver */ | ||
1422 | driver->driver.bus = NULL; | ||
1423 | r8a66597->driver = driver; | ||
1424 | r8a66597->gadget.dev.driver = &driver->driver; | ||
1425 | |||
1426 | retval = device_add(&r8a66597->gadget.dev); | ||
1427 | if (retval) { | ||
1428 | printk(KERN_ERR "device_add error (%d)\n", retval); | ||
1429 | goto error; | ||
1430 | } | ||
1431 | |||
1432 | retval = driver->bind(&r8a66597->gadget); | ||
1433 | if (retval) { | ||
1434 | printk(KERN_ERR "bind to driver error (%d)\n", retval); | ||
1435 | device_del(&r8a66597->gadget.dev); | ||
1436 | goto error; | ||
1437 | } | ||
1438 | |||
1439 | r8a66597_bset(r8a66597, VBSE, INTENB0); | ||
1440 | if (r8a66597_read(r8a66597, INTSTS0) & VBSTS) { | ||
1441 | r8a66597_start_xclock(r8a66597); | ||
1442 | /* start vbus sampling */ | ||
1443 | r8a66597->old_vbus = r8a66597_read(r8a66597, | ||
1444 | INTSTS0) & VBSTS; | ||
1445 | r8a66597->scount = R8A66597_MAX_SAMPLING; | ||
1446 | mod_timer(&r8a66597->timer, jiffies + msecs_to_jiffies(50)); | ||
1447 | } | ||
1448 | |||
1449 | return 0; | ||
1450 | |||
1451 | error: | ||
1452 | r8a66597->driver = NULL; | ||
1453 | r8a66597->gadget.dev.driver = NULL; | ||
1454 | |||
1455 | return retval; | ||
1456 | } | ||
1457 | EXPORT_SYMBOL(usb_gadget_register_driver); | ||
1458 | |||
1459 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | ||
1460 | { | ||
1461 | struct r8a66597 *r8a66597 = the_controller; | ||
1462 | unsigned long flags; | ||
1463 | |||
1464 | if (driver != r8a66597->driver || !driver->unbind) | ||
1465 | return -EINVAL; | ||
1466 | |||
1467 | spin_lock_irqsave(&r8a66597->lock, flags); | ||
1468 | if (r8a66597->gadget.speed != USB_SPEED_UNKNOWN) | ||
1469 | r8a66597_usb_disconnect(r8a66597); | ||
1470 | spin_unlock_irqrestore(&r8a66597->lock, flags); | ||
1471 | |||
1472 | r8a66597_bclr(r8a66597, VBSE, INTENB0); | ||
1473 | |||
1474 | driver->unbind(&r8a66597->gadget); | ||
1475 | |||
1476 | init_controller(r8a66597); | ||
1477 | disable_controller(r8a66597); | ||
1478 | |||
1479 | device_del(&r8a66597->gadget.dev); | ||
1480 | r8a66597->driver = NULL; | ||
1481 | return 0; | ||
1482 | } | ||
1483 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1484 | |||
1485 | /*-------------------------------------------------------------------------*/ | ||
1486 | static int r8a66597_get_frame(struct usb_gadget *_gadget) | ||
1487 | { | ||
1488 | struct r8a66597 *r8a66597 = gadget_to_r8a66597(_gadget); | ||
1489 | return r8a66597_read(r8a66597, FRMNUM) & 0x03FF; | ||
1490 | } | ||
1491 | |||
1492 | static struct usb_gadget_ops r8a66597_gadget_ops = { | ||
1493 | .get_frame = r8a66597_get_frame, | ||
1494 | }; | ||
1495 | |||
1496 | static int __exit r8a66597_remove(struct platform_device *pdev) | ||
1497 | { | ||
1498 | struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev); | ||
1499 | |||
1500 | del_timer_sync(&r8a66597->timer); | ||
1501 | iounmap((void *)r8a66597->reg); | ||
1502 | free_irq(platform_get_irq(pdev, 0), r8a66597); | ||
1503 | r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); | ||
1504 | #ifdef CONFIG_HAVE_CLK | ||
1505 | if (r8a66597->pdata->on_chip) { | ||
1506 | clk_disable(r8a66597->clk); | ||
1507 | clk_put(r8a66597->clk); | ||
1508 | } | ||
1509 | #endif | ||
1510 | kfree(r8a66597); | ||
1511 | return 0; | ||
1512 | } | ||
1513 | |||
1514 | static void nop_completion(struct usb_ep *ep, struct usb_request *r) | ||
1515 | { | ||
1516 | } | ||
1517 | |||
1518 | static int __init r8a66597_probe(struct platform_device *pdev) | ||
1519 | { | ||
1520 | #ifdef CONFIG_HAVE_CLK | ||
1521 | char clk_name[8]; | ||
1522 | #endif | ||
1523 | struct resource *res, *ires; | ||
1524 | int irq; | ||
1525 | void __iomem *reg = NULL; | ||
1526 | struct r8a66597 *r8a66597 = NULL; | ||
1527 | int ret = 0; | ||
1528 | int i; | ||
1529 | unsigned long irq_trigger; | ||
1530 | |||
1531 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
1532 | if (!res) { | ||
1533 | ret = -ENODEV; | ||
1534 | printk(KERN_ERR "platform_get_resource error.\n"); | ||
1535 | goto clean_up; | ||
1536 | } | ||
1537 | |||
1538 | ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
1539 | irq = ires->start; | ||
1540 | irq_trigger = ires->flags & IRQF_TRIGGER_MASK; | ||
1541 | |||
1542 | if (irq < 0) { | ||
1543 | ret = -ENODEV; | ||
1544 | printk(KERN_ERR "platform_get_irq error.\n"); | ||
1545 | goto clean_up; | ||
1546 | } | ||
1547 | |||
1548 | reg = ioremap(res->start, resource_size(res)); | ||
1549 | if (reg == NULL) { | ||
1550 | ret = -ENOMEM; | ||
1551 | printk(KERN_ERR "ioremap error.\n"); | ||
1552 | goto clean_up; | ||
1553 | } | ||
1554 | |||
1555 | /* initialize ucd */ | ||
1556 | r8a66597 = kzalloc(sizeof(struct r8a66597), GFP_KERNEL); | ||
1557 | if (r8a66597 == NULL) { | ||
1558 | printk(KERN_ERR "kzalloc error\n"); | ||
1559 | goto clean_up; | ||
1560 | } | ||
1561 | |||
1562 | spin_lock_init(&r8a66597->lock); | ||
1563 | dev_set_drvdata(&pdev->dev, r8a66597); | ||
1564 | r8a66597->pdata = pdev->dev.platform_data; | ||
1565 | r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW; | ||
1566 | |||
1567 | r8a66597->gadget.ops = &r8a66597_gadget_ops; | ||
1568 | device_initialize(&r8a66597->gadget.dev); | ||
1569 | dev_set_name(&r8a66597->gadget.dev, "gadget"); | ||
1570 | r8a66597->gadget.is_dualspeed = 1; | ||
1571 | r8a66597->gadget.dev.parent = &pdev->dev; | ||
1572 | r8a66597->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
1573 | r8a66597->gadget.dev.release = pdev->dev.release; | ||
1574 | r8a66597->gadget.name = udc_name; | ||
1575 | |||
1576 | init_timer(&r8a66597->timer); | ||
1577 | r8a66597->timer.function = r8a66597_timer; | ||
1578 | r8a66597->timer.data = (unsigned long)r8a66597; | ||
1579 | r8a66597->reg = (unsigned long)reg; | ||
1580 | |||
1581 | #ifdef CONFIG_HAVE_CLK | ||
1582 | if (r8a66597->pdata->on_chip) { | ||
1583 | snprintf(clk_name, sizeof(clk_name), "usb%d", pdev->id); | ||
1584 | r8a66597->clk = clk_get(&pdev->dev, clk_name); | ||
1585 | if (IS_ERR(r8a66597->clk)) { | ||
1586 | dev_err(&pdev->dev, "cannot get clock \"%s\"\n", | ||
1587 | clk_name); | ||
1588 | ret = PTR_ERR(r8a66597->clk); | ||
1589 | goto clean_up; | ||
1590 | } | ||
1591 | clk_enable(r8a66597->clk); | ||
1592 | } | ||
1593 | #endif | ||
1594 | |||
1595 | disable_controller(r8a66597); /* make sure controller is disabled */ | ||
1596 | |||
1597 | ret = request_irq(irq, r8a66597_irq, IRQF_DISABLED | IRQF_SHARED, | ||
1598 | udc_name, r8a66597); | ||
1599 | if (ret < 0) { | ||
1600 | printk(KERN_ERR "request_irq error (%d)\n", ret); | ||
1601 | goto clean_up2; | ||
1602 | } | ||
1603 | |||
1604 | INIT_LIST_HEAD(&r8a66597->gadget.ep_list); | ||
1605 | r8a66597->gadget.ep0 = &r8a66597->ep[0].ep; | ||
1606 | INIT_LIST_HEAD(&r8a66597->gadget.ep0->ep_list); | ||
1607 | for (i = 0; i < R8A66597_MAX_NUM_PIPE; i++) { | ||
1608 | struct r8a66597_ep *ep = &r8a66597->ep[i]; | ||
1609 | |||
1610 | if (i != 0) { | ||
1611 | INIT_LIST_HEAD(&r8a66597->ep[i].ep.ep_list); | ||
1612 | list_add_tail(&r8a66597->ep[i].ep.ep_list, | ||
1613 | &r8a66597->gadget.ep_list); | ||
1614 | } | ||
1615 | ep->r8a66597 = r8a66597; | ||
1616 | INIT_LIST_HEAD(&ep->queue); | ||
1617 | ep->ep.name = r8a66597_ep_name[i]; | ||
1618 | ep->ep.ops = &r8a66597_ep_ops; | ||
1619 | ep->ep.maxpacket = 512; | ||
1620 | } | ||
1621 | r8a66597->ep[0].ep.maxpacket = 64; | ||
1622 | r8a66597->ep[0].pipenum = 0; | ||
1623 | r8a66597->ep[0].fifoaddr = CFIFO; | ||
1624 | r8a66597->ep[0].fifosel = CFIFOSEL; | ||
1625 | r8a66597->ep[0].fifoctr = CFIFOCTR; | ||
1626 | r8a66597->ep[0].fifotrn = 0; | ||
1627 | r8a66597->ep[0].pipectr = get_pipectr_addr(0); | ||
1628 | r8a66597->pipenum2ep[0] = &r8a66597->ep[0]; | ||
1629 | r8a66597->epaddr2ep[0] = &r8a66597->ep[0]; | ||
1630 | |||
1631 | the_controller = r8a66597; | ||
1632 | |||
1633 | r8a66597->ep0_req = r8a66597_alloc_request(&r8a66597->ep[0].ep, | ||
1634 | GFP_KERNEL); | ||
1635 | if (r8a66597->ep0_req == NULL) | ||
1636 | goto clean_up3; | ||
1637 | r8a66597->ep0_req->complete = nop_completion; | ||
1638 | |||
1639 | init_controller(r8a66597); | ||
1640 | |||
1641 | dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); | ||
1642 | return 0; | ||
1643 | |||
1644 | clean_up3: | ||
1645 | free_irq(irq, r8a66597); | ||
1646 | clean_up2: | ||
1647 | #ifdef CONFIG_HAVE_CLK | ||
1648 | if (r8a66597->pdata->on_chip) { | ||
1649 | clk_disable(r8a66597->clk); | ||
1650 | clk_put(r8a66597->clk); | ||
1651 | } | ||
1652 | #endif | ||
1653 | clean_up: | ||
1654 | if (r8a66597) { | ||
1655 | if (r8a66597->ep0_req) | ||
1656 | r8a66597_free_request(&r8a66597->ep[0].ep, | ||
1657 | r8a66597->ep0_req); | ||
1658 | kfree(r8a66597); | ||
1659 | } | ||
1660 | if (reg) | ||
1661 | iounmap(reg); | ||
1662 | |||
1663 | return ret; | ||
1664 | } | ||
1665 | |||
1666 | /*-------------------------------------------------------------------------*/ | ||
1667 | static struct platform_driver r8a66597_driver = { | ||
1668 | .remove = __exit_p(r8a66597_remove), | ||
1669 | .driver = { | ||
1670 | .name = (char *) udc_name, | ||
1671 | }, | ||
1672 | }; | ||
1673 | |||
1674 | static int __init r8a66597_udc_init(void) | ||
1675 | { | ||
1676 | return platform_driver_probe(&r8a66597_driver, r8a66597_probe); | ||
1677 | } | ||
1678 | module_init(r8a66597_udc_init); | ||
1679 | |||
1680 | static void __exit r8a66597_udc_cleanup(void) | ||
1681 | { | ||
1682 | platform_driver_unregister(&r8a66597_driver); | ||
1683 | } | ||
1684 | module_exit(r8a66597_udc_cleanup); | ||
1685 | |||
1686 | MODULE_DESCRIPTION("R8A66597 USB gadget driver"); | ||
1687 | MODULE_LICENSE("GPL"); | ||
1688 | MODULE_AUTHOR("Yoshihiro Shimoda"); | ||
1689 | |||
diff --git a/drivers/usb/gadget/r8a66597-udc.h b/drivers/usb/gadget/r8a66597-udc.h new file mode 100644 index 000000000000..03087e7b9190 --- /dev/null +++ b/drivers/usb/gadget/r8a66597-udc.h | |||
@@ -0,0 +1,256 @@ | |||
1 | /* | ||
2 | * R8A66597 UDC | ||
3 | * | ||
4 | * Copyright (C) 2007-2009 Renesas Solutions Corp. | ||
5 | * | ||
6 | * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> | ||
7 | * | ||
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 | ||
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 | */ | ||
22 | |||
23 | #ifndef __R8A66597_H__ | ||
24 | #define __R8A66597_H__ | ||
25 | |||
26 | #ifdef CONFIG_HAVE_CLK | ||
27 | #include <linux/clk.h> | ||
28 | #endif | ||
29 | |||
30 | #include <linux/usb/r8a66597.h> | ||
31 | |||
32 | #define R8A66597_MAX_SAMPLING 10 | ||
33 | |||
34 | #define R8A66597_MAX_NUM_PIPE 8 | ||
35 | #define R8A66597_MAX_NUM_BULK 3 | ||
36 | #define R8A66597_MAX_NUM_ISOC 2 | ||
37 | #define R8A66597_MAX_NUM_INT 2 | ||
38 | |||
39 | #define R8A66597_BASE_PIPENUM_BULK 3 | ||
40 | #define R8A66597_BASE_PIPENUM_ISOC 1 | ||
41 | #define R8A66597_BASE_PIPENUM_INT 6 | ||
42 | |||
43 | #define R8A66597_BASE_BUFNUM 6 | ||
44 | #define R8A66597_MAX_BUFNUM 0x4F | ||
45 | |||
46 | #define is_bulk_pipe(pipenum) \ | ||
47 | ((pipenum >= R8A66597_BASE_PIPENUM_BULK) && \ | ||
48 | (pipenum < (R8A66597_BASE_PIPENUM_BULK + R8A66597_MAX_NUM_BULK))) | ||
49 | #define is_interrupt_pipe(pipenum) \ | ||
50 | ((pipenum >= R8A66597_BASE_PIPENUM_INT) && \ | ||
51 | (pipenum < (R8A66597_BASE_PIPENUM_INT + R8A66597_MAX_NUM_INT))) | ||
52 | #define is_isoc_pipe(pipenum) \ | ||
53 | ((pipenum >= R8A66597_BASE_PIPENUM_ISOC) && \ | ||
54 | (pipenum < (R8A66597_BASE_PIPENUM_ISOC + R8A66597_MAX_NUM_ISOC))) | ||
55 | |||
56 | struct r8a66597_pipe_info { | ||
57 | u16 pipe; | ||
58 | u16 epnum; | ||
59 | u16 maxpacket; | ||
60 | u16 type; | ||
61 | u16 interval; | ||
62 | u16 dir_in; | ||
63 | }; | ||
64 | |||
65 | struct r8a66597_request { | ||
66 | struct usb_request req; | ||
67 | struct list_head queue; | ||
68 | }; | ||
69 | |||
70 | struct r8a66597_ep { | ||
71 | struct usb_ep ep; | ||
72 | struct r8a66597 *r8a66597; | ||
73 | |||
74 | struct list_head queue; | ||
75 | unsigned busy:1; | ||
76 | unsigned wedge:1; | ||
77 | unsigned internal_ccpl:1; /* use only control */ | ||
78 | |||
79 | /* this member can able to after r8a66597_enable */ | ||
80 | unsigned use_dma:1; | ||
81 | u16 pipenum; | ||
82 | u16 type; | ||
83 | const struct usb_endpoint_descriptor *desc; | ||
84 | /* register address */ | ||
85 | unsigned char fifoaddr; | ||
86 | unsigned char fifosel; | ||
87 | unsigned char fifoctr; | ||
88 | unsigned char fifotrn; | ||
89 | unsigned char pipectr; | ||
90 | }; | ||
91 | |||
92 | struct r8a66597 { | ||
93 | spinlock_t lock; | ||
94 | unsigned long reg; | ||
95 | |||
96 | #ifdef CONFIG_HAVE_CLK | ||
97 | struct clk *clk; | ||
98 | #endif | ||
99 | struct r8a66597_platdata *pdata; | ||
100 | |||
101 | struct usb_gadget gadget; | ||
102 | struct usb_gadget_driver *driver; | ||
103 | |||
104 | struct r8a66597_ep ep[R8A66597_MAX_NUM_PIPE]; | ||
105 | struct r8a66597_ep *pipenum2ep[R8A66597_MAX_NUM_PIPE]; | ||
106 | struct r8a66597_ep *epaddr2ep[16]; | ||
107 | |||
108 | struct timer_list timer; | ||
109 | struct usb_request *ep0_req; /* for internal request */ | ||
110 | u16 ep0_data; /* for internal request */ | ||
111 | u16 old_vbus; | ||
112 | u16 scount; | ||
113 | u16 old_dvsq; | ||
114 | |||
115 | /* pipe config */ | ||
116 | unsigned char bulk; | ||
117 | unsigned char interrupt; | ||
118 | unsigned char isochronous; | ||
119 | unsigned char num_dma; | ||
120 | |||
121 | unsigned irq_sense_low:1; | ||
122 | }; | ||
123 | |||
124 | #define gadget_to_r8a66597(_gadget) \ | ||
125 | container_of(_gadget, struct r8a66597, gadget) | ||
126 | #define r8a66597_to_gadget(r8a66597) (&r8a66597->gadget) | ||
127 | |||
128 | static inline u16 r8a66597_read(struct r8a66597 *r8a66597, unsigned long offset) | ||
129 | { | ||
130 | return inw(r8a66597->reg + offset); | ||
131 | } | ||
132 | |||
133 | static inline void r8a66597_read_fifo(struct r8a66597 *r8a66597, | ||
134 | unsigned long offset, u16 *buf, | ||
135 | int len) | ||
136 | { | ||
137 | if (r8a66597->pdata->on_chip) { | ||
138 | unsigned long fifoaddr = r8a66597->reg + offset; | ||
139 | unsigned long count; | ||
140 | union { | ||
141 | unsigned long dword; | ||
142 | unsigned char byte[4]; | ||
143 | } data; | ||
144 | unsigned char *pb; | ||
145 | int i; | ||
146 | |||
147 | count = len / 4; | ||
148 | insl(fifoaddr, buf, count); | ||
149 | |||
150 | if (len & 0x00000003) { | ||
151 | data.dword = inl(fifoaddr); | ||
152 | pb = (unsigned char *)buf + count * 4; | ||
153 | for (i = 0; i < (len & 0x00000003); i++) | ||
154 | pb[i] = data.byte[i]; | ||
155 | } | ||
156 | } else { | ||
157 | len = (len + 1) / 2; | ||
158 | insw(r8a66597->reg + offset, buf, len); | ||
159 | } | ||
160 | } | ||
161 | |||
162 | static inline void r8a66597_write(struct r8a66597 *r8a66597, u16 val, | ||
163 | unsigned long offset) | ||
164 | { | ||
165 | outw(val, r8a66597->reg + offset); | ||
166 | } | ||
167 | |||
168 | static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597, | ||
169 | unsigned long offset, u16 *buf, | ||
170 | int len) | ||
171 | { | ||
172 | unsigned long fifoaddr = r8a66597->reg + offset; | ||
173 | |||
174 | if (r8a66597->pdata->on_chip) { | ||
175 | unsigned long count; | ||
176 | unsigned char *pb; | ||
177 | int i; | ||
178 | |||
179 | count = len / 4; | ||
180 | outsl(fifoaddr, buf, count); | ||
181 | |||
182 | if (len & 0x00000003) { | ||
183 | pb = (unsigned char *)buf + count * 4; | ||
184 | for (i = 0; i < (len & 0x00000003); i++) { | ||
185 | if (r8a66597_read(r8a66597, CFIFOSEL) & BIGEND) | ||
186 | outb(pb[i], fifoaddr + i); | ||
187 | else | ||
188 | outb(pb[i], fifoaddr + 3 - i); | ||
189 | } | ||
190 | } | ||
191 | } else { | ||
192 | int odd = len & 0x0001; | ||
193 | |||
194 | len = len / 2; | ||
195 | outsw(fifoaddr, buf, len); | ||
196 | if (unlikely(odd)) { | ||
197 | buf = &buf[len]; | ||
198 | outb((unsigned char)*buf, fifoaddr); | ||
199 | } | ||
200 | } | ||
201 | } | ||
202 | |||
203 | static inline void r8a66597_mdfy(struct r8a66597 *r8a66597, | ||
204 | u16 val, u16 pat, unsigned long offset) | ||
205 | { | ||
206 | u16 tmp; | ||
207 | tmp = r8a66597_read(r8a66597, offset); | ||
208 | tmp = tmp & (~pat); | ||
209 | tmp = tmp | val; | ||
210 | r8a66597_write(r8a66597, tmp, offset); | ||
211 | } | ||
212 | |||
213 | static inline u16 get_xtal_from_pdata(struct r8a66597_platdata *pdata) | ||
214 | { | ||
215 | u16 clock = 0; | ||
216 | |||
217 | switch (pdata->xtal) { | ||
218 | case R8A66597_PLATDATA_XTAL_12MHZ: | ||
219 | clock = XTAL12; | ||
220 | break; | ||
221 | case R8A66597_PLATDATA_XTAL_24MHZ: | ||
222 | clock = XTAL24; | ||
223 | break; | ||
224 | case R8A66597_PLATDATA_XTAL_48MHZ: | ||
225 | clock = XTAL48; | ||
226 | break; | ||
227 | default: | ||
228 | printk(KERN_ERR "r8a66597: platdata clock is wrong.\n"); | ||
229 | break; | ||
230 | } | ||
231 | |||
232 | return clock; | ||
233 | } | ||
234 | |||
235 | #define r8a66597_bclr(r8a66597, val, offset) \ | ||
236 | r8a66597_mdfy(r8a66597, 0, val, offset) | ||
237 | #define r8a66597_bset(r8a66597, val, offset) \ | ||
238 | r8a66597_mdfy(r8a66597, val, 0, offset) | ||
239 | |||
240 | #define get_pipectr_addr(pipenum) (PIPE1CTR + (pipenum - 1) * 2) | ||
241 | |||
242 | #define enable_irq_ready(r8a66597, pipenum) \ | ||
243 | enable_pipe_irq(r8a66597, pipenum, BRDYENB) | ||
244 | #define disable_irq_ready(r8a66597, pipenum) \ | ||
245 | disable_pipe_irq(r8a66597, pipenum, BRDYENB) | ||
246 | #define enable_irq_empty(r8a66597, pipenum) \ | ||
247 | enable_pipe_irq(r8a66597, pipenum, BEMPENB) | ||
248 | #define disable_irq_empty(r8a66597, pipenum) \ | ||
249 | disable_pipe_irq(r8a66597, pipenum, BEMPENB) | ||
250 | #define enable_irq_nrdy(r8a66597, pipenum) \ | ||
251 | enable_pipe_irq(r8a66597, pipenum, NRDYENB) | ||
252 | #define disable_irq_nrdy(r8a66597, pipenum) \ | ||
253 | disable_pipe_irq(r8a66597, pipenum, NRDYENB) | ||
254 | |||
255 | #endif /* __R8A66597_H__ */ | ||
256 | |||
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c index ca41b0b5afb3..48267bc0b2e0 100644 --- a/drivers/usb/gadget/rndis.c +++ b/drivers/usb/gadget/rndis.c | |||
@@ -1022,22 +1022,29 @@ static rndis_resp_t *rndis_add_response (int configNr, u32 length) | |||
1022 | return r; | 1022 | return r; |
1023 | } | 1023 | } |
1024 | 1024 | ||
1025 | int rndis_rm_hdr(struct sk_buff *skb) | 1025 | int rndis_rm_hdr(struct gether *port, |
1026 | struct sk_buff *skb, | ||
1027 | struct sk_buff_head *list) | ||
1026 | { | 1028 | { |
1027 | /* tmp points to a struct rndis_packet_msg_type */ | 1029 | /* tmp points to a struct rndis_packet_msg_type */ |
1028 | __le32 *tmp = (void *) skb->data; | 1030 | __le32 *tmp = (void *) skb->data; |
1029 | 1031 | ||
1030 | /* MessageType, MessageLength */ | 1032 | /* MessageType, MessageLength */ |
1031 | if (cpu_to_le32(REMOTE_NDIS_PACKET_MSG) | 1033 | if (cpu_to_le32(REMOTE_NDIS_PACKET_MSG) |
1032 | != get_unaligned(tmp++)) | 1034 | != get_unaligned(tmp++)) { |
1035 | dev_kfree_skb_any(skb); | ||
1033 | return -EINVAL; | 1036 | return -EINVAL; |
1037 | } | ||
1034 | tmp++; | 1038 | tmp++; |
1035 | 1039 | ||
1036 | /* DataOffset, DataLength */ | 1040 | /* DataOffset, DataLength */ |
1037 | if (!skb_pull(skb, get_unaligned_le32(tmp++) + 8)) | 1041 | if (!skb_pull(skb, get_unaligned_le32(tmp++) + 8)) { |
1042 | dev_kfree_skb_any(skb); | ||
1038 | return -EOVERFLOW; | 1043 | return -EOVERFLOW; |
1044 | } | ||
1039 | skb_trim(skb, get_unaligned_le32(tmp++)); | 1045 | skb_trim(skb, get_unaligned_le32(tmp++)); |
1040 | 1046 | ||
1047 | skb_queue_tail(list, skb); | ||
1041 | return 0; | 1048 | return 0; |
1042 | } | 1049 | } |
1043 | 1050 | ||
diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h index aac61dfe0f03..c236aaa9dcd1 100644 --- a/drivers/usb/gadget/rndis.h +++ b/drivers/usb/gadget/rndis.h | |||
@@ -251,7 +251,8 @@ int rndis_set_param_vendor (u8 configNr, u32 vendorID, | |||
251 | const char *vendorDescr); | 251 | const char *vendorDescr); |
252 | int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed); | 252 | int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed); |
253 | void rndis_add_hdr (struct sk_buff *skb); | 253 | void rndis_add_hdr (struct sk_buff *skb); |
254 | int rndis_rm_hdr (struct sk_buff *skb); | 254 | int rndis_rm_hdr(struct gether *port, struct sk_buff *skb, |
255 | struct sk_buff_head *list); | ||
255 | u8 *rndis_get_next_response (int configNr, u32 *length); | 256 | u8 *rndis_get_next_response (int configNr, u32 *length); |
256 | void rndis_free_response (int configNr, u8 *buf); | 257 | void rndis_free_response (int configNr, u8 *buf); |
257 | 258 | ||
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c index 50c71aae2cc2..4b5dbd0127f5 100644 --- a/drivers/usb/gadget/s3c-hsotg.c +++ b/drivers/usb/gadget/s3c-hsotg.c | |||
@@ -2392,7 +2392,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg) | |||
2392 | grstctl = readl(hsotg->regs + S3C_GRSTCTL); | 2392 | grstctl = readl(hsotg->regs + S3C_GRSTCTL); |
2393 | } while (!(grstctl & S3C_GRSTCTL_CSftRst) && timeout-- > 0); | 2393 | } while (!(grstctl & S3C_GRSTCTL_CSftRst) && timeout-- > 0); |
2394 | 2394 | ||
2395 | if (!grstctl & S3C_GRSTCTL_CSftRst) { | 2395 | if (!(grstctl & S3C_GRSTCTL_CSftRst)) { |
2396 | dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); | 2396 | dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); |
2397 | return -EINVAL; | 2397 | return -EINVAL; |
2398 | } | 2398 | } |
@@ -2514,8 +2514,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) | |||
2514 | * DMA mode we may need this. */ | 2514 | * DMA mode we may need this. */ |
2515 | writel(S3C_DOEPMSK_SetupMsk | S3C_DOEPMSK_AHBErrMsk | | 2515 | writel(S3C_DOEPMSK_SetupMsk | S3C_DOEPMSK_AHBErrMsk | |
2516 | S3C_DOEPMSK_EPDisbldMsk | | 2516 | S3C_DOEPMSK_EPDisbldMsk | |
2517 | using_dma(hsotg) ? (S3C_DIEPMSK_XferComplMsk | | 2517 | (using_dma(hsotg) ? (S3C_DIEPMSK_XferComplMsk | |
2518 | S3C_DIEPMSK_TimeOUTMsk) : 0, | 2518 | S3C_DIEPMSK_TimeOUTMsk) : 0), |
2519 | hsotg->regs + S3C_DOEPMSK); | 2519 | hsotg->regs + S3C_DOEPMSK); |
2520 | 2520 | ||
2521 | writel(0, hsotg->regs + S3C_DAINTMSK); | 2521 | writel(0, hsotg->regs + S3C_DAINTMSK); |
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c index a9b452fe6221..d5f4c1d45c97 100644 --- a/drivers/usb/gadget/s3c2410_udc.c +++ b/drivers/usb/gadget/s3c2410_udc.c | |||
@@ -1703,8 +1703,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1703 | dprintk(DEBUG_NORMAL,"usb_gadget_register_driver() '%s'\n", | 1703 | dprintk(DEBUG_NORMAL,"usb_gadget_register_driver() '%s'\n", |
1704 | driver->driver.name); | 1704 | driver->driver.name); |
1705 | 1705 | ||
1706 | if (driver->disconnect) | 1706 | driver->unbind(&udc->gadget); |
1707 | driver->disconnect(&udc->gadget); | ||
1708 | 1707 | ||
1709 | device_del(&udc->gadget.dev); | 1708 | device_del(&udc->gadget.dev); |
1710 | udc->driver = NULL; | 1709 | udc->driver = NULL; |
diff --git a/drivers/usb/gadget/u_audio.c b/drivers/usb/gadget/u_audio.c index 0f3d22fc030e..8252595d619d 100644 --- a/drivers/usb/gadget/u_audio.c +++ b/drivers/usb/gadget/u_audio.c | |||
@@ -10,7 +10,6 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/utsname.h> | ||
14 | #include <linux/device.h> | 13 | #include <linux/device.h> |
15 | #include <linux/delay.h> | 14 | #include <linux/delay.h> |
16 | #include <linux/ctype.h> | 15 | #include <linux/ctype.h> |
@@ -253,11 +252,13 @@ static int gaudio_open_snd_dev(struct gaudio *card) | |||
253 | snd->filp = filp_open(fn_cap, O_RDONLY, 0); | 252 | snd->filp = filp_open(fn_cap, O_RDONLY, 0); |
254 | if (IS_ERR(snd->filp)) { | 253 | if (IS_ERR(snd->filp)) { |
255 | ERROR(card, "No such PCM capture device: %s\n", fn_cap); | 254 | ERROR(card, "No such PCM capture device: %s\n", fn_cap); |
256 | snd->filp = NULL; | 255 | snd->substream = NULL; |
256 | snd->card = NULL; | ||
257 | } else { | ||
258 | pcm_file = snd->filp->private_data; | ||
259 | snd->substream = pcm_file->substream; | ||
260 | snd->card = card; | ||
257 | } | 261 | } |
258 | pcm_file = snd->filp->private_data; | ||
259 | snd->substream = pcm_file->substream; | ||
260 | snd->card = card; | ||
261 | 262 | ||
262 | return 0; | 263 | return 0; |
263 | } | 264 | } |
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index c66521953917..2fc02bd95848 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c | |||
@@ -23,7 +23,6 @@ | |||
23 | /* #define VERBOSE_DEBUG */ | 23 | /* #define VERBOSE_DEBUG */ |
24 | 24 | ||
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/utsname.h> | ||
27 | #include <linux/device.h> | 26 | #include <linux/device.h> |
28 | #include <linux/ctype.h> | 27 | #include <linux/ctype.h> |
29 | #include <linux/etherdevice.h> | 28 | #include <linux/etherdevice.h> |
@@ -37,8 +36,9 @@ | |||
37 | * one (!) network link through the USB gadget stack, normally "usb0". | 36 | * one (!) network link through the USB gadget stack, normally "usb0". |
38 | * | 37 | * |
39 | * The control and data models are handled by the function driver which | 38 | * The control and data models are handled by the function driver which |
40 | * connects to this code; such as CDC Ethernet, "CDC Subset", or RNDIS. | 39 | * connects to this code; such as CDC Ethernet (ECM or EEM), |
41 | * That includes all descriptor and endpoint management. | 40 | * "CDC Subset", or RNDIS. That includes all descriptor and endpoint |
41 | * management. | ||
42 | * | 42 | * |
43 | * Link level addressing is handled by this component using module | 43 | * Link level addressing is handled by this component using module |
44 | * parameters; if no such parameters are provided, random link level | 44 | * parameters; if no such parameters are provided, random link level |
@@ -68,9 +68,13 @@ struct eth_dev { | |||
68 | struct list_head tx_reqs, rx_reqs; | 68 | struct list_head tx_reqs, rx_reqs; |
69 | atomic_t tx_qlen; | 69 | atomic_t tx_qlen; |
70 | 70 | ||
71 | struct sk_buff_head rx_frames; | ||
72 | |||
71 | unsigned header_len; | 73 | unsigned header_len; |
72 | struct sk_buff *(*wrap)(struct sk_buff *skb); | 74 | struct sk_buff *(*wrap)(struct gether *, struct sk_buff *skb); |
73 | int (*unwrap)(struct sk_buff *skb); | 75 | int (*unwrap)(struct gether *, |
76 | struct sk_buff *skb, | ||
77 | struct sk_buff_head *list); | ||
74 | 78 | ||
75 | struct work_struct work; | 79 | struct work_struct work; |
76 | 80 | ||
@@ -269,7 +273,7 @@ enomem: | |||
269 | 273 | ||
270 | static void rx_complete(struct usb_ep *ep, struct usb_request *req) | 274 | static void rx_complete(struct usb_ep *ep, struct usb_request *req) |
271 | { | 275 | { |
272 | struct sk_buff *skb = req->context; | 276 | struct sk_buff *skb = req->context, *skb2; |
273 | struct eth_dev *dev = ep->driver_data; | 277 | struct eth_dev *dev = ep->driver_data; |
274 | int status = req->status; | 278 | int status = req->status; |
275 | 279 | ||
@@ -278,26 +282,47 @@ static void rx_complete(struct usb_ep *ep, struct usb_request *req) | |||
278 | /* normal completion */ | 282 | /* normal completion */ |
279 | case 0: | 283 | case 0: |
280 | skb_put(skb, req->actual); | 284 | skb_put(skb, req->actual); |
281 | if (dev->unwrap) | ||
282 | status = dev->unwrap(skb); | ||
283 | if (status < 0 | ||
284 | || ETH_HLEN > skb->len | ||
285 | || skb->len > ETH_FRAME_LEN) { | ||
286 | dev->net->stats.rx_errors++; | ||
287 | dev->net->stats.rx_length_errors++; | ||
288 | DBG(dev, "rx length %d\n", skb->len); | ||
289 | break; | ||
290 | } | ||
291 | 285 | ||
292 | skb->protocol = eth_type_trans(skb, dev->net); | 286 | if (dev->unwrap) { |
293 | dev->net->stats.rx_packets++; | 287 | unsigned long flags; |
294 | dev->net->stats.rx_bytes += skb->len; | ||
295 | 288 | ||
296 | /* no buffer copies needed, unless hardware can't | 289 | spin_lock_irqsave(&dev->lock, flags); |
297 | * use skb buffers. | 290 | if (dev->port_usb) { |
298 | */ | 291 | status = dev->unwrap(dev->port_usb, |
299 | status = netif_rx(skb); | 292 | skb, |
293 | &dev->rx_frames); | ||
294 | } else { | ||
295 | dev_kfree_skb_any(skb); | ||
296 | status = -ENOTCONN; | ||
297 | } | ||
298 | spin_unlock_irqrestore(&dev->lock, flags); | ||
299 | } else { | ||
300 | skb_queue_tail(&dev->rx_frames, skb); | ||
301 | } | ||
300 | skb = NULL; | 302 | skb = NULL; |
303 | |||
304 | skb2 = skb_dequeue(&dev->rx_frames); | ||
305 | while (skb2) { | ||
306 | if (status < 0 | ||
307 | || ETH_HLEN > skb2->len | ||
308 | || skb2->len > ETH_FRAME_LEN) { | ||
309 | dev->net->stats.rx_errors++; | ||
310 | dev->net->stats.rx_length_errors++; | ||
311 | DBG(dev, "rx length %d\n", skb2->len); | ||
312 | dev_kfree_skb_any(skb2); | ||
313 | goto next_frame; | ||
314 | } | ||
315 | skb2->protocol = eth_type_trans(skb2, dev->net); | ||
316 | dev->net->stats.rx_packets++; | ||
317 | dev->net->stats.rx_bytes += skb2->len; | ||
318 | |||
319 | /* no buffer copies needed, unless hardware can't | ||
320 | * use skb buffers. | ||
321 | */ | ||
322 | status = netif_rx(skb2); | ||
323 | next_frame: | ||
324 | skb2 = skb_dequeue(&dev->rx_frames); | ||
325 | } | ||
301 | break; | 326 | break; |
302 | 327 | ||
303 | /* software-driven interface shutdown */ | 328 | /* software-driven interface shutdown */ |
@@ -537,14 +562,15 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, | |||
537 | * or there's not enough space for extra headers we need | 562 | * or there's not enough space for extra headers we need |
538 | */ | 563 | */ |
539 | if (dev->wrap) { | 564 | if (dev->wrap) { |
540 | struct sk_buff *skb_new; | 565 | unsigned long flags; |
541 | 566 | ||
542 | skb_new = dev->wrap(skb); | 567 | spin_lock_irqsave(&dev->lock, flags); |
543 | if (!skb_new) | 568 | if (dev->port_usb) |
569 | skb = dev->wrap(dev->port_usb, skb); | ||
570 | spin_unlock_irqrestore(&dev->lock, flags); | ||
571 | if (!skb) | ||
544 | goto drop; | 572 | goto drop; |
545 | 573 | ||
546 | dev_kfree_skb_any(skb); | ||
547 | skb = skb_new; | ||
548 | length = skb->len; | 574 | length = skb->len; |
549 | } | 575 | } |
550 | req->buf = skb->data; | 576 | req->buf = skb->data; |
@@ -578,9 +604,9 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, | |||
578 | } | 604 | } |
579 | 605 | ||
580 | if (retval) { | 606 | if (retval) { |
607 | dev_kfree_skb_any(skb); | ||
581 | drop: | 608 | drop: |
582 | dev->net->stats.tx_dropped++; | 609 | dev->net->stats.tx_dropped++; |
583 | dev_kfree_skb_any(skb); | ||
584 | spin_lock_irqsave(&dev->req_lock, flags); | 610 | spin_lock_irqsave(&dev->req_lock, flags); |
585 | if (list_empty(&dev->tx_reqs)) | 611 | if (list_empty(&dev->tx_reqs)) |
586 | netif_start_queue(net); | 612 | netif_start_queue(net); |
@@ -753,6 +779,8 @@ int __init gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]) | |||
753 | INIT_LIST_HEAD(&dev->tx_reqs); | 779 | INIT_LIST_HEAD(&dev->tx_reqs); |
754 | INIT_LIST_HEAD(&dev->rx_reqs); | 780 | INIT_LIST_HEAD(&dev->rx_reqs); |
755 | 781 | ||
782 | skb_queue_head_init(&dev->rx_frames); | ||
783 | |||
756 | /* network device setup */ | 784 | /* network device setup */ |
757 | dev->net = net; | 785 | dev->net = net; |
758 | strcpy(net->name, "usb%d"); | 786 | strcpy(net->name, "usb%d"); |
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h index 0d1f7ae3b071..91b39ffdf6ea 100644 --- a/drivers/usb/gadget/u_ether.h +++ b/drivers/usb/gadget/u_ether.h | |||
@@ -60,12 +60,13 @@ struct gether { | |||
60 | 60 | ||
61 | u16 cdc_filter; | 61 | u16 cdc_filter; |
62 | 62 | ||
63 | /* hooks for added framing, as needed for RNDIS and EEM. | 63 | /* hooks for added framing, as needed for RNDIS and EEM. */ |
64 | * we currently don't support multiple frames per SKB. | ||
65 | */ | ||
66 | u32 header_len; | 64 | u32 header_len; |
67 | struct sk_buff *(*wrap)(struct sk_buff *skb); | 65 | struct sk_buff *(*wrap)(struct gether *port, |
68 | int (*unwrap)(struct sk_buff *skb); | 66 | struct sk_buff *skb); |
67 | int (*unwrap)(struct gether *port, | ||
68 | struct sk_buff *skb, | ||
69 | struct sk_buff_head *list); | ||
69 | 70 | ||
70 | /* called on network open/close */ | 71 | /* called on network open/close */ |
71 | void (*open)(struct gether *); | 72 | void (*open)(struct gether *); |
@@ -109,6 +110,7 @@ static inline bool can_support_ecm(struct usb_gadget *gadget) | |||
109 | /* each configuration may bind one instance of an ethernet link */ | 110 | /* each configuration may bind one instance of an ethernet link */ |
110 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); | 111 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); |
111 | int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); | 112 | int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); |
113 | int eem_bind_config(struct usb_configuration *c); | ||
112 | 114 | ||
113 | #ifdef CONFIG_USB_ETH_RNDIS | 115 | #ifdef CONFIG_USB_ETH_RNDIS |
114 | 116 | ||
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c index fc6e709f45b1..adf8260c3a6a 100644 --- a/drivers/usb/gadget/u_serial.c +++ b/drivers/usb/gadget/u_serial.c | |||
@@ -1114,7 +1114,6 @@ int __init gserial_setup(struct usb_gadget *g, unsigned count) | |||
1114 | /* export the driver ... */ | 1114 | /* export the driver ... */ |
1115 | status = tty_register_driver(gs_tty_driver); | 1115 | status = tty_register_driver(gs_tty_driver); |
1116 | if (status) { | 1116 | if (status) { |
1117 | put_tty_driver(gs_tty_driver); | ||
1118 | pr_err("%s: cannot register, err %d\n", | 1117 | pr_err("%s: cannot register, err %d\n", |
1119 | __func__, status); | 1118 | __func__, status); |
1120 | goto fail; | 1119 | goto fail; |