diff options
author | Li Yang <leoli@freescale.com> | 2008-09-24 03:50:26 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-10-17 17:41:08 -0400 |
commit | 928dfa6c625c17d810ae3ee6c73dc37fc4b91bcd (patch) | |
tree | c09f8b615d76f81c3db67c1b4146b477e453c7b6 /drivers | |
parent | 23d7cd040e1f43113da3e8763becf576ab86b39a (diff) |
usb/fsl_qe_udc: fix response to get status request
The original code didn't respond correctly to get status request on
device and endpoint. Although normal operations can work without the
fix. It is not compliant with USB spec chapter9 and fails USBCV ch9
tests. The patch fix this and a few style/typo problems.
Signed-off-by: Li Yang <leoli@freescale.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/usb/gadget/fsl_qe_udc.c | 101 | ||||
-rw-r--r-- | drivers/usb/gadget/fsl_qe_udc.h | 1 |
2 files changed, 68 insertions, 34 deletions
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c index e9400e62f171..d9aad6894b3e 100644 --- a/drivers/usb/gadget/fsl_qe_udc.c +++ b/drivers/usb/gadget/fsl_qe_udc.c | |||
@@ -1138,7 +1138,7 @@ static int qe_ep_tx(struct qe_ep *ep, struct qe_frame *frame) | |||
1138 | } | 1138 | } |
1139 | } | 1139 | } |
1140 | 1140 | ||
1141 | /* when an bd was transmitted, the function can * | 1141 | /* when a bd was transmitted, the function can |
1142 | * handle the tx_req, not include ep0 */ | 1142 | * handle the tx_req, not include ep0 */ |
1143 | static int txcomplete(struct qe_ep *ep, unsigned char restart) | 1143 | static int txcomplete(struct qe_ep *ep, unsigned char restart) |
1144 | { | 1144 | { |
@@ -1174,7 +1174,7 @@ static int txcomplete(struct qe_ep *ep, unsigned char restart) | |||
1174 | return 0; | 1174 | return 0; |
1175 | } | 1175 | } |
1176 | 1176 | ||
1177 | /* give a frame and a tx_req,send some data */ | 1177 | /* give a frame and a tx_req, send some data */ |
1178 | static int qe_usb_senddata(struct qe_ep *ep, struct qe_frame *frame) | 1178 | static int qe_usb_senddata(struct qe_ep *ep, struct qe_frame *frame) |
1179 | { | 1179 | { |
1180 | unsigned int size; | 1180 | unsigned int size; |
@@ -1797,11 +1797,6 @@ static int qe_ep_set_halt(struct usb_ep *_ep, int value) | |||
1797 | goto out; | 1797 | goto out; |
1798 | } | 1798 | } |
1799 | 1799 | ||
1800 | if (ep->epnum != 0) { | ||
1801 | status = 0; | ||
1802 | goto out; | ||
1803 | } | ||
1804 | |||
1805 | udc = ep->udc; | 1800 | udc = ep->udc; |
1806 | /* Attempt to halt IN ep will fail if any transfer requests | 1801 | /* Attempt to halt IN ep will fail if any transfer requests |
1807 | * are still queue */ | 1802 | * are still queue */ |
@@ -1821,7 +1816,7 @@ static int qe_ep_set_halt(struct usb_ep *_ep, int value) | |||
1821 | udc->ep0_dir = 0; | 1816 | udc->ep0_dir = 0; |
1822 | } | 1817 | } |
1823 | out: | 1818 | out: |
1824 | dev_vdbg(udc->dev, " %s %s halt stat %d\n", ep->ep.name, | 1819 | dev_vdbg(udc->dev, "%s %s halt stat %d\n", ep->ep.name, |
1825 | value ? "set" : "clear", status); | 1820 | value ? "set" : "clear", status); |
1826 | 1821 | ||
1827 | return status; | 1822 | return status; |
@@ -1953,22 +1948,51 @@ static void ownercomplete(struct usb_ep *_ep, struct usb_request *_req) | |||
1953 | kfree(req); | 1948 | kfree(req); |
1954 | } | 1949 | } |
1955 | 1950 | ||
1956 | static void ch9getstatus(struct qe_udc *udc, u16 value, u16 index, | 1951 | static void ch9getstatus(struct qe_udc *udc, u8 request_type, u16 value, |
1957 | u16 length) | 1952 | u16 index, u16 length) |
1958 | { | 1953 | { |
1959 | u16 usb_status = 0; /* fix me to give correct status */ | 1954 | u16 usb_status = 0; |
1960 | |||
1961 | struct qe_req *req; | 1955 | struct qe_req *req; |
1962 | struct qe_ep *ep; | 1956 | struct qe_ep *ep; |
1963 | int status = 0; | 1957 | int status = 0; |
1964 | 1958 | ||
1965 | ep = &udc->eps[0]; | 1959 | ep = &udc->eps[0]; |
1960 | if ((request_type & USB_RECIP_MASK) == USB_RECIP_DEVICE) { | ||
1961 | /* Get device status */ | ||
1962 | usb_status = 1 << USB_DEVICE_SELF_POWERED; | ||
1963 | } else if ((request_type & USB_RECIP_MASK) == USB_RECIP_INTERFACE) { | ||
1964 | /* Get interface status */ | ||
1965 | /* We don't have interface information in udc driver */ | ||
1966 | usb_status = 0; | ||
1967 | } else if ((request_type & USB_RECIP_MASK) == USB_RECIP_ENDPOINT) { | ||
1968 | /* Get endpoint status */ | ||
1969 | int pipe = index & USB_ENDPOINT_NUMBER_MASK; | ||
1970 | struct qe_ep *target_ep = &udc->eps[pipe]; | ||
1971 | u16 usep; | ||
1972 | |||
1973 | /* stall if endpoint doesn't exist */ | ||
1974 | if (!target_ep->desc) | ||
1975 | goto stall; | ||
1976 | |||
1977 | usep = in_be16(&udc->usb_regs->usb_usep[pipe]); | ||
1978 | if (index & USB_DIR_IN) { | ||
1979 | if (target_ep->dir != USB_DIR_IN) | ||
1980 | goto stall; | ||
1981 | if ((usep & USB_THS_MASK) == USB_THS_STALL) | ||
1982 | usb_status = 1 << USB_ENDPOINT_HALT; | ||
1983 | } else { | ||
1984 | if (target_ep->dir != USB_DIR_OUT) | ||
1985 | goto stall; | ||
1986 | if ((usep & USB_RHS_MASK) == USB_RHS_STALL) | ||
1987 | usb_status = 1 << USB_ENDPOINT_HALT; | ||
1988 | } | ||
1989 | } | ||
1966 | 1990 | ||
1967 | req = container_of(qe_alloc_request(&ep->ep, GFP_KERNEL), | 1991 | req = container_of(qe_alloc_request(&ep->ep, GFP_KERNEL), |
1968 | struct qe_req, req); | 1992 | struct qe_req, req); |
1969 | req->req.length = 2; | 1993 | req->req.length = 2; |
1970 | req->req.buf = udc->nullbuf; | 1994 | req->req.buf = udc->statusbuf; |
1971 | memcpy(req->req.buf, (u8 *)&usb_status, 2); | 1995 | *(u16 *)req->req.buf = cpu_to_le16(usb_status); |
1972 | req->req.status = -EINPROGRESS; | 1996 | req->req.status = -EINPROGRESS; |
1973 | req->req.actual = 0; | 1997 | req->req.actual = 0; |
1974 | req->req.complete = ownercomplete; | 1998 | req->req.complete = ownercomplete; |
@@ -1978,10 +2002,11 @@ static void ch9getstatus(struct qe_udc *udc, u16 value, u16 index, | |||
1978 | /* data phase */ | 2002 | /* data phase */ |
1979 | status = qe_ep_queue(&ep->ep, &req->req, GFP_ATOMIC); | 2003 | status = qe_ep_queue(&ep->ep, &req->req, GFP_ATOMIC); |
1980 | 2004 | ||
1981 | if (status) { | 2005 | if (status == 0) |
1982 | dev_err(udc->dev, "Can't respond to getstatus request \n"); | 2006 | return; |
1983 | qe_ep0_stall(udc); | 2007 | stall: |
1984 | } | 2008 | dev_err(udc->dev, "Can't respond to getstatus request \n"); |
2009 | qe_ep0_stall(udc); | ||
1985 | } | 2010 | } |
1986 | 2011 | ||
1987 | /* only handle the setup request, suppose the device in normal status */ | 2012 | /* only handle the setup request, suppose the device in normal status */ |
@@ -2007,7 +2032,8 @@ static void setup_received_handle(struct qe_udc *udc, | |||
2007 | if ((setup->bRequestType & (USB_DIR_IN | USB_TYPE_MASK)) | 2032 | if ((setup->bRequestType & (USB_DIR_IN | USB_TYPE_MASK)) |
2008 | != (USB_DIR_IN | USB_TYPE_STANDARD)) | 2033 | != (USB_DIR_IN | USB_TYPE_STANDARD)) |
2009 | break; | 2034 | break; |
2010 | ch9getstatus(udc, wValue, wIndex, wLength); | 2035 | ch9getstatus(udc, setup->bRequestType, wValue, wIndex, |
2036 | wLength); | ||
2011 | return; | 2037 | return; |
2012 | 2038 | ||
2013 | case USB_REQ_SET_ADDRESS: | 2039 | case USB_REQ_SET_ADDRESS: |
@@ -2021,7 +2047,7 @@ static void setup_received_handle(struct qe_udc *udc, | |||
2021 | case USB_REQ_CLEAR_FEATURE: | 2047 | case USB_REQ_CLEAR_FEATURE: |
2022 | case USB_REQ_SET_FEATURE: | 2048 | case USB_REQ_SET_FEATURE: |
2023 | /* Requests with no data phase, status phase from udc */ | 2049 | /* Requests with no data phase, status phase from udc */ |
2024 | if ((setup->bRequestType & USB_TYPE_MASK) | 2050 | if ((setup->bRequestType & USB_TYPE_MASK) |
2025 | != USB_TYPE_STANDARD) | 2051 | != USB_TYPE_STANDARD) |
2026 | break; | 2052 | break; |
2027 | 2053 | ||
@@ -2055,7 +2081,7 @@ static void setup_received_handle(struct qe_udc *udc, | |||
2055 | if (setup->bRequestType & USB_DIR_IN) { | 2081 | if (setup->bRequestType & USB_DIR_IN) { |
2056 | udc->ep0_state = DATA_STATE_XMIT; | 2082 | udc->ep0_state = DATA_STATE_XMIT; |
2057 | udc->ep0_dir = USB_DIR_IN; | 2083 | udc->ep0_dir = USB_DIR_IN; |
2058 | } else{ | 2084 | } else { |
2059 | udc->ep0_state = DATA_STATE_RECV; | 2085 | udc->ep0_state = DATA_STATE_RECV; |
2060 | udc->ep0_dir = USB_DIR_OUT; | 2086 | udc->ep0_dir = USB_DIR_OUT; |
2061 | } | 2087 | } |
@@ -2160,13 +2186,11 @@ static int tx_irq(struct qe_udc *udc) | |||
2160 | bd = ep->c_txbd; | 2186 | bd = ep->c_txbd; |
2161 | if (!(in_be32((u32 __iomem *)bd) & T_R) | 2187 | if (!(in_be32((u32 __iomem *)bd) & T_R) |
2162 | && (in_be32(&bd->buf))) { | 2188 | && (in_be32(&bd->buf))) { |
2163 | /* Disable the TX Interrupt */ | 2189 | /* confirm the transmitted bd */ |
2164 | /*confirm the transmitted bd*/ | ||
2165 | if (ep->epnum == 0) | 2190 | if (ep->epnum == 0) |
2166 | res = qe_ep0_txconf(ep); | 2191 | res = qe_ep0_txconf(ep); |
2167 | else | 2192 | else |
2168 | res = qe_ep_txconf(ep); | 2193 | res = qe_ep_txconf(ep); |
2169 | /* Enable the TX Interrupt */ | ||
2170 | } | 2194 | } |
2171 | } | 2195 | } |
2172 | } | 2196 | } |
@@ -2205,7 +2229,6 @@ static irqreturn_t qe_udc_irq(int irq, void *_udc) | |||
2205 | irqreturn_t status = IRQ_NONE; | 2229 | irqreturn_t status = IRQ_NONE; |
2206 | unsigned long flags; | 2230 | unsigned long flags; |
2207 | 2231 | ||
2208 | |||
2209 | spin_lock_irqsave(&udc->lock, flags); | 2232 | spin_lock_irqsave(&udc->lock, flags); |
2210 | 2233 | ||
2211 | irq_src = in_be16(&udc->usb_regs->usb_usber) & | 2234 | irq_src = in_be16(&udc->usb_regs->usb_usber) & |
@@ -2520,10 +2543,9 @@ static int __devinit qe_udc_probe(struct of_device *ofdev, | |||
2520 | udc_controller->gadget.dev.release = qe_udc_release; | 2543 | udc_controller->gadget.dev.release = qe_udc_release; |
2521 | udc_controller->gadget.dev.parent = &ofdev->dev; | 2544 | udc_controller->gadget.dev.parent = &ofdev->dev; |
2522 | 2545 | ||
2523 | 2546 | /* initialize qe_ep struct */ | |
2524 | /* EP:intialization qe_ep struct */ | ||
2525 | for (i = 0; i < USB_MAX_ENDPOINTS ; i++) { | 2547 | for (i = 0; i < USB_MAX_ENDPOINTS ; i++) { |
2526 | /*because the ep type isn't decide here so | 2548 | /* because the ep type isn't decide here so |
2527 | * qe_ep_init() should be called in ep_enable() */ | 2549 | * qe_ep_init() should be called in ep_enable() */ |
2528 | 2550 | ||
2529 | /* setup the qe_ep struct and link ep.ep.list | 2551 | /* setup the qe_ep struct and link ep.ep.list |
@@ -2536,7 +2558,7 @@ static int __devinit qe_udc_probe(struct of_device *ofdev, | |||
2536 | if (ret) | 2558 | if (ret) |
2537 | goto err2; | 2559 | goto err2; |
2538 | 2560 | ||
2539 | /* create a buf for ZLP send */ | 2561 | /* create a buf for ZLP send, need to remain zeroed */ |
2540 | udc_controller->nullbuf = kzalloc(256, GFP_KERNEL); | 2562 | udc_controller->nullbuf = kzalloc(256, GFP_KERNEL); |
2541 | if (udc_controller->nullbuf == NULL) { | 2563 | if (udc_controller->nullbuf == NULL) { |
2542 | dev_dbg(udc_controller->dev, "cannot alloc nullbuf\n"); | 2564 | dev_dbg(udc_controller->dev, "cannot alloc nullbuf\n"); |
@@ -2544,6 +2566,13 @@ static int __devinit qe_udc_probe(struct of_device *ofdev, | |||
2544 | goto err3; | 2566 | goto err3; |
2545 | } | 2567 | } |
2546 | 2568 | ||
2569 | /* buffer for data of get_status request */ | ||
2570 | udc_controller->statusbuf = kzalloc(2, GFP_KERNEL); | ||
2571 | if (udc_controller->statusbuf == NULL) { | ||
2572 | ret = -ENOMEM; | ||
2573 | goto err4; | ||
2574 | } | ||
2575 | |||
2547 | udc_controller->nullp = virt_to_phys((void *)udc_controller->nullbuf); | 2576 | udc_controller->nullp = virt_to_phys((void *)udc_controller->nullbuf); |
2548 | if (udc_controller->nullp == DMA_ADDR_INVALID) { | 2577 | if (udc_controller->nullp == DMA_ADDR_INVALID) { |
2549 | udc_controller->nullp = dma_map_single( | 2578 | udc_controller->nullp = dma_map_single( |
@@ -2568,20 +2597,21 @@ static int __devinit qe_udc_probe(struct of_device *ofdev, | |||
2568 | if (ret) { | 2597 | if (ret) { |
2569 | dev_err(udc_controller->dev, "cannot request irq %d err %d \n", | 2598 | dev_err(udc_controller->dev, "cannot request irq %d err %d \n", |
2570 | udc_controller->usb_irq, ret); | 2599 | udc_controller->usb_irq, ret); |
2571 | goto err4; | 2600 | goto err5; |
2572 | } | 2601 | } |
2573 | 2602 | ||
2574 | ret = device_add(&udc_controller->gadget.dev); | 2603 | ret = device_add(&udc_controller->gadget.dev); |
2575 | if (ret) | 2604 | if (ret) |
2576 | goto err5; | 2605 | goto err6; |
2577 | 2606 | ||
2578 | dev_info(udc_controller->dev, | 2607 | dev_info(udc_controller->dev, |
2579 | "QE/CPM USB controller initialized as device\n"); | 2608 | "%s USB controller initialized as device\n", |
2609 | (udc_controller->soc_type == PORT_QE) ? "QE" : "CPM"); | ||
2580 | return 0; | 2610 | return 0; |
2581 | 2611 | ||
2582 | err5: | 2612 | err6: |
2583 | free_irq(udc_controller->usb_irq, udc_controller); | 2613 | free_irq(udc_controller->usb_irq, udc_controller); |
2584 | err4: | 2614 | err5: |
2585 | if (udc_controller->nullmap) { | 2615 | if (udc_controller->nullmap) { |
2586 | dma_unmap_single(udc_controller->gadget.dev.parent, | 2616 | dma_unmap_single(udc_controller->gadget.dev.parent, |
2587 | udc_controller->nullp, 256, | 2617 | udc_controller->nullp, 256, |
@@ -2592,6 +2622,8 @@ err4: | |||
2592 | udc_controller->nullp, 256, | 2622 | udc_controller->nullp, 256, |
2593 | DMA_TO_DEVICE); | 2623 | DMA_TO_DEVICE); |
2594 | } | 2624 | } |
2625 | kfree(udc_controller->statusbuf); | ||
2626 | err4: | ||
2595 | kfree(udc_controller->nullbuf); | 2627 | kfree(udc_controller->nullbuf); |
2596 | err3: | 2628 | err3: |
2597 | ep = &udc_controller->eps[0]; | 2629 | ep = &udc_controller->eps[0]; |
@@ -2642,6 +2674,7 @@ static int __devexit qe_udc_remove(struct of_device *ofdev) | |||
2642 | udc_controller->nullp, 256, | 2674 | udc_controller->nullp, 256, |
2643 | DMA_TO_DEVICE); | 2675 | DMA_TO_DEVICE); |
2644 | } | 2676 | } |
2677 | kfree(udc_controller->statusbuf); | ||
2645 | kfree(udc_controller->nullbuf); | 2678 | kfree(udc_controller->nullbuf); |
2646 | 2679 | ||
2647 | ep = &udc_controller->eps[0]; | 2680 | ep = &udc_controller->eps[0]; |
diff --git a/drivers/usb/gadget/fsl_qe_udc.h b/drivers/usb/gadget/fsl_qe_udc.h index b4c07a22e8e7..31b2710882e4 100644 --- a/drivers/usb/gadget/fsl_qe_udc.h +++ b/drivers/usb/gadget/fsl_qe_udc.h | |||
@@ -349,6 +349,7 @@ struct qe_udc { | |||
349 | u32 c_end; | 349 | u32 c_end; |
350 | 350 | ||
351 | u8 *nullbuf; | 351 | u8 *nullbuf; |
352 | u8 *statusbuf; | ||
352 | dma_addr_t nullp; | 353 | dma_addr_t nullp; |
353 | u8 nullmap; | 354 | u8 nullmap; |
354 | u8 device_address; /* Device USB address */ | 355 | u8 device_address; /* Device USB address */ |