1 /* ==========================================================================
2 * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_linux.c $
7 * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
8 * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
9 * otherwise expressly agreed to in writing between Synopsys and you.
11 * The Software IS NOT an item of Licensed Software or Licensed Product under
12 * any End User Software License Agreement or Agreement for Licensed Product
13 * with Synopsys or any supplement thereto. You are permitted to use and
14 * redistribute this Software in source and binary forms, with or without
15 * modification, provided that redistributions of source code must retain this
16 * notice. You may not view, use, disclose, copy or distribute this file or
17 * any information contained herein except pursuant to this license grant from
18 * Synopsys. If you do not agree with this notice, including the disclaimer
19 * below, then you are not authorized to use the Software.
21 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
32 * ========================================================================== */
36 * This file implements the Peripheral Controller Driver.
38 * The Peripheral Controller Driver (PCD) is responsible for
39 * translating requests from the Function Driver into the appropriate
40 * actions on the DWC_otg controller. It isolates the Function Driver
41 * from the specifics of the controller by providing an API to the
44 * The Peripheral Controller Driver for Linux will implement the
45 * Gadget API, so that the existing Gadget drivers can be used.
46 * (Gadget Driver is the Linux terminology for a Function Driver.)
48 * The Linux Gadget API is defined in the header file
49 * <code><linux/usb_gadget.h></code>. The USB EP operations API is
50 * defined in the structure <code>usb_ep_ops</code> and the USB
51 * Controller API is defined in the structure
52 * <code>usb_gadget_ops</code>.
56 #include "dwc_otg_os_dep.h"
57 #include "dwc_otg_pcd_if.h"
58 #include "dwc_otg_pcd.h"
59 #include "dwc_otg_driver.h"
60 #include "dwc_otg_dbg.h"
61 #include "dwc_otg_attr.h"
63 #include "usbdev_rk.h"
64 static struct gadget_wrapper {
67 struct usb_gadget gadget;
68 struct usb_gadget_driver *driver;
71 struct usb_ep in_ep[16];
72 struct usb_ep out_ep[16];
76 /* Display the contents of the buffer */
77 extern void dump_msg(const u8 *buf, unsigned int length);
80 * Get the dwc_otg_pcd_ep_t* from usb_ep* pointer - NULL in case
81 * if the endpoint is not found
83 static struct dwc_otg_pcd_ep *ep_from_handle(dwc_otg_pcd_t *pcd, void *handle)
86 if (pcd->ep0.priv == handle) {
90 for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
91 if (pcd->in_ep[i].priv == handle)
92 return &pcd->in_ep[i];
93 if (pcd->out_ep[i].priv == handle)
94 return &pcd->out_ep[i];
100 /* USB Endpoint Operations */
102 * The following sections briefly describe the behavior of the Gadget
103 * API endpoint operations implemented in the DWC_otg driver
104 * software. Detailed descriptions of the generic behavior of each of
105 * these functions can be found in the Linux header file
106 * include/linux/usb_gadget.h.
108 * The Gadget API provides wrapper functions for each of the function
109 * pointers defined in usb_ep_ops. The Gadget Driver calls the wrapper
110 * function, which then calls the underlying PCD function. The
111 * following sections are named according to the wrapper
112 * functions. Within each section, the corresponding DWC_otg PCD
113 * function name is specified.
118 * This function is called by the Gadget Driver for each EP to be
119 * configured for the current configuration (SET_CONFIGURATION).
121 * This function initializes the dwc_otg_ep_t data structure, and then
122 * calls dwc_otg_ep_activate.
124 static int ep_enable(struct usb_ep *usb_ep,
125 const struct usb_endpoint_descriptor *ep_desc)
129 DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, ep_desc);
131 if (!usb_ep || !ep_desc || ep_desc->bDescriptorType != USB_DT_ENDPOINT) {
132 DWC_WARN("%s, bad ep or descriptor\n", __func__);
135 if (usb_ep == &gadget_wrapper->ep0) {
136 DWC_WARN("%s, bad ep(0)\n", __func__);
140 /* Check FIFO size? */
141 if (!ep_desc->wMaxPacketSize) {
142 DWC_WARN("%s, bad %s maxpacket\n", __func__, usb_ep->name);
146 if (!gadget_wrapper->driver ||
147 gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
148 DWC_WARN("%s, bogus device state\n", __func__);
152 /* Delete after check - MAS */
154 nat = (uint32_t) ep_desc->wMaxPacketSize;
155 printk(KERN_ALERT "%s: nat (before) =%d\n", __func__, nat);
156 nat = (nat >> 11) & 0x03;
157 printk(KERN_ALERT "%s: nat (after) =%d\n", __func__, nat);
159 retval = dwc_otg_pcd_ep_enable(gadget_wrapper->pcd,
160 (const uint8_t *)ep_desc,
163 DWC_WARN("dwc_otg_pcd_ep_enable failed\n");
167 usb_ep->maxpacket = le16_to_cpu(ep_desc->wMaxPacketSize);
173 * This function is called when an EP is disabled due to disconnect or
174 * change in configuration. Any pending requests will terminate with a
175 * status of -ESHUTDOWN.
177 * This function modifies the dwc_otg_ep_t data structure for this EP,
178 * and then calls dwc_otg_ep_deactivate.
180 static int ep_disable(struct usb_ep *usb_ep)
184 DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, usb_ep);
186 DWC_DEBUGPL(DBG_PCD, "%s, %s not enabled\n", __func__,
187 usb_ep ? usb_ep->name : NULL);
191 retval = dwc_otg_pcd_ep_disable(gadget_wrapper->pcd, usb_ep);
200 * This function allocates a request object to use with the specified
203 * @param ep The endpoint to be used with with the request
204 * @param gfp_flags the GFP_* flags to use.
206 static struct usb_request *dwc_otg_pcd_alloc_request(struct usb_ep *ep,
209 struct usb_request *usb_req;
211 DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d)\n", __func__, ep, gfp_flags);
213 DWC_WARN("%s() %s\n", __func__, "Invalid EP!\n");
216 usb_req = kmalloc(sizeof(*usb_req), gfp_flags);
218 DWC_WARN("%s() %s\n", __func__, "request allocation failed!\n");
221 memset(usb_req, 0, sizeof(*usb_req));
222 usb_req->dma = DWC_DMA_ADDR_INVALID;
228 * This function frees a request object.
230 * @param ep The endpoint associated with the request
231 * @param req The request being freed
233 static void dwc_otg_pcd_free_request(struct usb_ep *ep, struct usb_request *req)
235 DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, ep, req);
237 if (0 == ep || 0 == req) {
238 DWC_WARN("%s() %s\n", __func__,
239 "Invalid ep or req argument!\n");
246 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28)
248 * This function allocates an I/O buffer to be used for a transfer
249 * to/from the specified endpoint.
251 * @param usb_ep The endpoint to be used with with the request
252 * @param bytes The desired number of bytes for the buffer
253 * @param dma Pointer to the buffer's DMA address; must be valid
254 * @param gfp_flags the GFP_* flags to use.
255 * @return address of a new buffer or null is buffer could not be allocated.
257 static void *dwc_otg_pcd_alloc_buffer(struct usb_ep *usb_ep, unsigned bytes,
258 dma_addr_t *dma, gfp_t gfp_flags)
261 dwc_otg_pcd_t *pcd = 0;
263 pcd = gadget_wrapper->pcd;
265 DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d,%p,%0x)\n", __func__, usb_ep, bytes,
268 /* Check dword alignment */
269 if ((bytes & 0x3UL) != 0) {
270 DWC_WARN("%s() Buffer size is not a multiple of"
271 "DWORD size (%d)", __func__, bytes);
274 buf = dma_alloc_coherent(NULL, bytes, dma, gfp_flags);
276 /* Check dword alignment */
277 if (((int)buf & 0x3UL) != 0) {
278 DWC_WARN("%s() Buffer is not DWORD aligned (%p)",
286 * This function frees an I/O buffer that was allocated by alloc_buffer.
288 * @param usb_ep the endpoint associated with the buffer
289 * @param buf address of the buffer
290 * @param dma The buffer's DMA address
291 * @param bytes The number of bytes of the buffer
293 static void dwc_otg_pcd_free_buffer(struct usb_ep *usb_ep, void *buf,
294 dma_addr_t dma, unsigned bytes)
296 dwc_otg_pcd_t *pcd = 0;
298 pcd = gadget_wrapper->pcd;
300 DWC_DEBUGPL(DBG_PCDV, "%s(%p,%0x,%d)\n", __func__, buf, dma, bytes);
302 dma_free_coherent(NULL, bytes, buf, dma);
307 * This function is used to submit an I/O Request to an EP.
309 * - When the request completes the request's completion callback
310 * is called to return the request to the driver.
311 * - An EP, except control EPs, may have multiple requests
313 * - Once submitted the request cannot be examined or modified.
314 * - Each request is turned into one or more packets.
315 * - A BULK EP can queue any amount of data; the transfer is
317 * - Zero length Packets are specified with the request 'zero'
320 static int ep_queue(struct usb_ep *usb_ep, struct usb_request *usb_req,
324 struct dwc_otg_pcd_ep *ep = NULL;
325 int retval = 0, is_isoc_ep = 0;
326 dma_addr_t dma_addr = DWC_DMA_ADDR_INVALID;
328 DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p,%d)\n",
329 __func__, usb_ep, usb_req, gfp_flags);
331 if (!usb_req || !usb_req->complete || !usb_req->buf) {
332 DWC_WARN("bad params\n");
337 DWC_WARN("bad ep\n");
341 pcd = gadget_wrapper->pcd;
342 if (!gadget_wrapper->driver ||
343 gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
344 DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
345 gadget_wrapper->gadget.speed);
346 DWC_WARN("bogus device state\n");
350 DWC_DEBUGPL(DBG_PCD, "%s queue req %p, len %d buf %p\n",
351 usb_ep->name, usb_req, usb_req->length, usb_req->buf);
353 usb_req->status = -EINPROGRESS;
356 ep = ep_from_handle(pcd, usb_ep);
360 is_isoc_ep = (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) ? 1 : 0;
361 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28)
362 dma_addr = usb_req->dma;
364 if (GET_CORE_IF(pcd)->dma_enable) {
365 /* if (usb_req->length != 0) {*/
366 /* In device DMA mode when gadget perform ep_queue request
367 * with buffer length 0, Kernel stack dump occurred. For 0
368 * length buffers perform dma_map_single() with length 4.*/
369 if (usb_req->dma == DWC_DMA_ADDR_INVALID) {
371 dma_map_single(gadget_wrapper->gadget.dev.parent,
374 0 ? usb_req->length : 4,
376 is_in ? DMA_TO_DEVICE :
378 usb_req->dma = dma_addr;
380 dma_addr = usb_req->dma;
386 #ifdef DWC_UTE_PER_IO
387 if (is_isoc_ep == 1) {
389 dwc_otg_pcd_xiso_ep_queue(pcd, usb_ep, usb_req->buf,
390 dma_addr, usb_req->length,
391 usb_req->zero, usb_req,
392 gfp_flags == GFP_ATOMIC ? 1 : 0,
400 retval = dwc_otg_pcd_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
401 usb_req->length, usb_req->zero, usb_req,
402 gfp_flags == GFP_ATOMIC ? 1 : 0);
411 * This function cancels an I/O request from an EP.
413 static int ep_dequeue(struct usb_ep *usb_ep, struct usb_request *usb_req)
415 DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, usb_req);
417 if (!usb_ep || !usb_req) {
418 DWC_WARN("bad argument\n");
421 if (!gadget_wrapper->driver ||
422 gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
423 DWC_WARN("bogus device state\n");
426 if (dwc_otg_pcd_ep_dequeue(gadget_wrapper->pcd, usb_ep, usb_req)) {
434 * usb_ep_set_halt stalls an endpoint.
436 * usb_ep_clear_halt clears an endpoint halt and resets its data
439 * Both of these functions are implemented with the same underlying
440 * function. The behavior depends on the value argument.
442 * @param[in] usb_ep the Endpoint to halt or clear halt.
444 * - 0 means clear_halt.
445 * - 1 means set_halt,
446 * - 2 means clear stall lock flag.
447 * - 3 means set stall lock flag.
449 static int ep_halt(struct usb_ep *usb_ep, int value)
453 DWC_DEBUGPL(DBG_PCD, "HALT %s %d\n", usb_ep->name, value);
456 DWC_WARN("bad ep\n");
460 retval = dwc_otg_pcd_ep_halt(gadget_wrapper->pcd, usb_ep, value);
461 if (retval == -DWC_E_AGAIN) {
470 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
471 static int ep_wedge(struct usb_ep *usb_ep)
473 DWC_DEBUGPL(DBG_PCD, "WEDGE %s\n", usb_ep->name);
475 return ep_halt(usb_ep, 3);
481 * This function is used to submit an ISOC Transfer Request to an EP.
483 * - Every time a sync period completes the request's completion callback
484 * is called to provide data to the gadget driver.
485 * - Once submitted the request cannot be modified.
486 * - Each request is turned into periodic data packets untill ISO
487 * Transfer is stopped..
489 static int iso_ep_start(struct usb_ep *usb_ep, struct usb_iso_request *req,
494 if (!req || !req->process_buffer || !req->buf0 || !req->buf1) {
495 DWC_WARN("bad params\n");
500 DWC_PRINTF("bad params\n");
504 req->status = -EINPROGRESS;
507 dwc_otg_pcd_iso_ep_start(gadget_wrapper->pcd, usb_ep, req->buf0,
508 req->buf1, req->dma0, req->dma1,
509 req->sync_frame, req->data_pattern_frame,
511 req->flags & USB_REQ_ISO_ASAP ? -1 :
512 req->start_frame, req->buf_proc_intrvl,
513 req, gfp_flags == GFP_ATOMIC ? 1 : 0);
523 * This function stops ISO EP Periodic Data Transfer.
525 static int iso_ep_stop(struct usb_ep *usb_ep, struct usb_iso_request *req)
529 DWC_WARN("bad ep\n");
532 if (!gadget_wrapper->driver ||
533 gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
534 DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
535 gadget_wrapper->gadget.speed);
536 DWC_WARN("bogus device state\n");
539 dwc_otg_pcd_iso_ep_stop(gadget_wrapper->pcd, usb_ep, req);
547 static struct usb_iso_request *alloc_iso_request(struct usb_ep *ep,
548 int packets, gfp_t gfp_flags)
550 struct usb_iso_request *pReq = NULL;
553 req_size = sizeof(struct usb_iso_request);
555 (2 * packets * (sizeof(struct usb_gadget_iso_packet_descriptor)));
557 pReq = kmalloc(req_size, gfp_flags);
559 DWC_WARN("Can't allocate Iso Request\n");
562 pReq->iso_packet_desc0 = (void *)(pReq + 1);
564 pReq->iso_packet_desc1 = pReq->iso_packet_desc0 + packets;
569 static void free_iso_request(struct usb_ep *ep, struct usb_iso_request *req)
574 static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops = {
577 .disable = ep_disable,
579 .alloc_request = dwc_otg_pcd_alloc_request,
580 .free_request = dwc_otg_pcd_free_request,
582 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28)
583 .alloc_buffer = dwc_otg_pcd_alloc_buffer,
584 .free_buffer = dwc_otg_pcd_free_buffer,
588 .dequeue = ep_dequeue,
592 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
593 .set_wedge = ep_wedge,
599 .iso_ep_start = iso_ep_start,
600 .iso_ep_stop = iso_ep_stop,
601 .alloc_iso_request = alloc_iso_request,
602 .free_iso_request = free_iso_request,
607 static struct usb_ep_ops dwc_otg_pcd_ep_ops = {
609 .disable = ep_disable,
611 .alloc_request = dwc_otg_pcd_alloc_request,
612 .free_request = dwc_otg_pcd_free_request,
614 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28)
615 .alloc_buffer = dwc_otg_pcd_alloc_buffer,
616 .free_buffer = dwc_otg_pcd_free_buffer,
620 .dequeue = ep_dequeue,
624 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
625 .set_wedge = ep_wedge,
633 #endif /* _EN_ISOC_ */
634 /* Gadget Operations */
636 * The following gadget operations will be implemented in the DWC_otg
637 * PCD. Functions in the API that are not described below are not
640 * The Gadget API provides wrapper functions for each of the function
641 * pointers defined in usb_gadget_ops. The Gadget Driver calls the
642 * wrapper function, which then calls the underlying PCD function. The
643 * following sections are named according to the wrapper functions
644 * (except for ioctl, which doesn't have a wrapper function). Within
645 * each section, the corresponding DWC_otg PCD function name is
651 *Gets the USB Frame number of the last SOF.
653 static int get_frame_number(struct usb_gadget *gadget)
655 struct gadget_wrapper *d;
657 DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
663 d = container_of(gadget, struct gadget_wrapper, gadget);
664 return dwc_otg_pcd_get_frame_number(d->pcd);
667 #ifdef CONFIG_USB_DWC_OTG_LPM
668 static int test_lpm_enabled(struct usb_gadget *gadget)
670 struct gadget_wrapper *d;
672 d = container_of(gadget, struct gadget_wrapper, gadget);
674 return dwc_otg_pcd_is_lpm_enabled(d->pcd);
677 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)
678 static int test_besl_enabled(struct usb_gadget *gadget)
680 struct gadget_wrapper *d;
682 d = container_of(gadget, struct gadget_wrapper, gadget);
684 return dwc_otg_pcd_is_besl_enabled(d->pcd);
687 static int get_param_baseline_besl(struct usb_gadget *gadget)
689 struct gadget_wrapper *d;
691 d = container_of(gadget, struct gadget_wrapper, gadget);
693 return dwc_otg_pcd_get_param_baseline_besl(d->pcd);
696 static int get_param_deep_besl(struct usb_gadget *gadget)
698 struct gadget_wrapper *d;
700 d = container_of(gadget, struct gadget_wrapper, gadget);
702 return dwc_otg_pcd_get_param_deep_besl(d->pcd);
708 * Initiates Session Request Protocol (SRP) to wakeup the host if no
709 * session is in progress. If a session is already in progress, but
710 * the device is suspended, remote wakeup signaling is started.
713 static int wakeup(struct usb_gadget *gadget)
715 struct gadget_wrapper *d;
717 DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
722 d = container_of(gadget, struct gadget_wrapper, gadget);
724 dwc_otg_pcd_wakeup(d->pcd);
728 static int dwc_otg_pcd_pullup(struct usb_gadget *_gadget, int is_on)
730 struct gadget_wrapper *d;
732 dwc_otg_core_if_t *core_if;
734 printk("pcd_pullup, is_on %d\n", is_on);
738 d = container_of(_gadget, struct gadget_wrapper, gadget);
740 core_if = GET_CORE_IF(d->pcd);
744 /* dwc_otg_pcd_pullup_enable(pcd); */
746 pcd->conn_status = 0;
748 dwc_otg_pcd_pullup_disable(pcd);
749 pcd->conn_status = 2;
756 static int dwc_otg_gadget_start(struct usb_gadget *g,
757 struct usb_gadget_driver *driver)
759 DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n",
760 driver->driver.name);
761 if (gadget_wrapper == 0) {
762 DWC_ERROR("ENODEV\n");
765 if (gadget_wrapper->driver != 0) {
766 DWC_ERROR("EBUSY (%p)\n", gadget_wrapper->driver);
769 /* hook up the driver */
770 gadget_wrapper->driver = driver;
771 gadget_wrapper->gadget.dev.driver = &driver->driver;
773 DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
778 static int dwc_otg_gadget_stop(struct usb_gadget *g,
779 struct usb_gadget_driver *driver)
784 static const struct usb_gadget_ops dwc_otg_pcd_ops = {
785 .get_frame = get_frame_number,
787 .pullup = dwc_otg_pcd_pullup,
788 #ifdef CONFIG_USB_DWC_OTG_LPM
789 .lpm_support = test_lpm_enabled,
790 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)
791 .besl_support = test_besl_enabled,
792 .get_baseline_besl = get_param_baseline_besl,
793 .get_deep_besl = get_param_deep_besl,
796 .udc_start = dwc_otg_gadget_start,
797 .udc_stop = dwc_otg_gadget_stop,
799 /* current versions must always be self-powered */
802 static int _setup(dwc_otg_pcd_t *pcd, uint8_t *bytes)
804 int retval = -DWC_E_NOT_SUPPORTED;
805 if (gadget_wrapper->driver && gadget_wrapper->driver->setup) {
806 retval = gadget_wrapper->driver->setup(&gadget_wrapper->gadget,
807 (struct usb_ctrlrequest
811 if (retval == -ENOTSUPP) {
812 retval = -DWC_E_NOT_SUPPORTED;
813 } else if (retval < 0) {
814 retval = -DWC_E_INVALID;
821 static int _isoc_complete(dwc_otg_pcd_t *pcd, void *ep_handle,
822 void *req_handle, int proc_buf_num)
825 struct usb_gadget_iso_packet_descriptor *iso_packet = 0;
826 struct usb_iso_request *iso_req = req_handle;
829 iso_packet = iso_req->iso_packet_desc1;
831 iso_packet = iso_req->iso_packet_desc0;
834 dwc_otg_pcd_get_iso_packet_count(pcd, ep_handle, req_handle);
835 for (i = 0; i < packet_count; ++i) {
839 dwc_otg_pcd_get_iso_packet_params(pcd, ep_handle, req_handle,
840 i, &status, &actual, &offset);
847 DWC_PRINTF("unknown status in isoc packet\n");
851 iso_packet[i].status = status;
852 iso_packet[i].offset = offset;
853 iso_packet[i].actual_length = actual;
857 iso_req->process_buffer(ep_handle, iso_req);
861 #endif /* DWC_EN_ISOC */
863 #ifdef DWC_UTE_PER_IO
865 * Copy the contents of the extended request to the Linux usb_request's
866 * extended part and call the gadget's completion.
868 * @param pcd Pointer to the pcd structure
869 * @param ep_handle Void pointer to the usb_ep structure
870 * @param req_handle Void pointer to the usb_request structure
871 * @param status Request status returned from the portable logic
872 * @param ereq_port Void pointer to the extended request structure
873 * created in the the portable part that contains the
874 * results of the processed iso packets.
876 static int _xisoc_complete(dwc_otg_pcd_t *pcd, void *ep_handle,
877 void *req_handle, int32_t status, void *ereq_port)
879 struct dwc_ute_iso_req_ext *ereqorg = NULL;
880 struct dwc_iso_xreq_port *ereqport = NULL;
881 struct dwc_ute_iso_packet_descriptor *desc_org = NULL;
883 struct usb_request *req;
884 /* struct dwc_ute_iso_packet_descriptor * */
885 /* int status = 0; */
887 req = (struct usb_request *)req_handle;
888 ereqorg = &req->ext_req;
889 ereqport = (struct dwc_iso_xreq_port *)ereq_port;
890 desc_org = ereqorg->per_io_frame_descs;
892 if (req && req->complete) {
893 /* Copy the request data from the portable logic to our request */
894 for (i = 0; i < ereqport->pio_pkt_count; i++) {
895 desc_org[i].actual_length =
896 ereqport->per_io_frame_descs[i].actual_length;
898 ereqport->per_io_frame_descs[i].status;
902 case -DWC_E_SHUTDOWN:
903 req->status = -ESHUTDOWN;
906 req->status = -ECONNRESET;
909 req->status = -EINVAL;
912 req->status = -ETIMEDOUT;
915 req->status = status;
918 /* And call the gadget's completion */
919 req->complete(ep_handle, req);
924 #endif /* DWC_UTE_PER_IO */
926 static int _complete(dwc_otg_pcd_t *pcd, void *ep_handle,
927 void *req_handle, int32_t status, uint32_t actual)
929 struct usb_request *req = (struct usb_request *)req_handle;
930 struct dwc_otg_pcd_ep *ep = NULL;
932 ep = ep_from_handle(pcd, ep_handle);
934 if (GET_CORE_IF(pcd)->dma_enable) {
935 /* if (req->length != 0) */
936 if (req->dma != DWC_DMA_ADDR_INVALID) {
937 dma_unmap_single(gadget_wrapper->gadget.dev.parent,
942 ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
943 req->dma = DWC_DMA_ADDR_INVALID;
947 if (req && req->complete) {
949 case -DWC_E_SHUTDOWN:
950 req->status = -ESHUTDOWN;
953 req->status = -ECONNRESET;
956 req->status = -EINVAL;
959 req->status = -ETIMEDOUT;
962 req->status = status;
966 req->actual = actual;
967 DWC_SPINUNLOCK(pcd->lock);
968 req->complete(ep_handle, req);
969 DWC_SPINLOCK(pcd->lock);
976 static int _connect(dwc_otg_pcd_t *pcd, int speed)
978 gadget_wrapper->gadget.speed = speed;
982 static int _disconnect(dwc_otg_pcd_t *pcd)
984 if (gadget_wrapper->driver && gadget_wrapper->driver->disconnect) {
985 gadget_wrapper->driver->disconnect(&gadget_wrapper->gadget);
990 static int _resume(dwc_otg_pcd_t *pcd)
992 if (gadget_wrapper->driver && gadget_wrapper->driver->resume) {
993 gadget_wrapper->driver->resume(&gadget_wrapper->gadget);
999 static int _suspend(dwc_otg_pcd_t *pcd)
1001 if (gadget_wrapper->driver && gadget_wrapper->driver->suspend) {
1002 gadget_wrapper->driver->suspend(&gadget_wrapper->gadget);
1008 * This function updates the otg values in the gadget structure.
1010 static int _hnp_changed(dwc_otg_pcd_t *pcd)
1013 if (!gadget_wrapper->gadget.is_otg)
1016 gadget_wrapper->gadget.b_hnp_enable = get_b_hnp_enable(pcd);
1017 gadget_wrapper->gadget.a_hnp_support = get_a_hnp_support(pcd);
1018 gadget_wrapper->gadget.a_alt_hnp_support = get_a_alt_hnp_support(pcd);
1022 static int _reset(dwc_otg_pcd_t *pcd)
1028 static int _cfi_setup(dwc_otg_pcd_t *pcd, void *cfi_req)
1030 int retval = -DWC_E_INVALID;
1031 if (gadget_wrapper->driver->cfi_feature_setup) {
1033 gadget_wrapper->driver->cfi_feature_setup(&gadget_wrapper->
1044 static const struct dwc_otg_pcd_function_ops fops = {
1045 .complete = _complete,
1047 .isoc_complete = _isoc_complete,
1050 .disconnect = _disconnect,
1051 .connect = _connect,
1053 .suspend = _suspend,
1054 .hnp_changed = _hnp_changed,
1057 .cfi_setup = _cfi_setup,
1059 #ifdef DWC_UTE_PER_IO
1060 .xisoc_complete = _xisoc_complete,
1065 * This function is the top level PCD interrupt handler.
1067 static irqreturn_t dwc_otg_pcd_irq(int irq, void *dev)
1069 dwc_otg_pcd_t *pcd = dev;
1070 int32_t retval = IRQ_NONE;
1072 retval = dwc_otg_pcd_handle_intr(pcd);
1074 /* S3C2410X_CLEAR_EINTPEND();*/
1076 return IRQ_RETVAL(retval);
1080 * This function initialized the usb_ep structures to there default
1083 * @param d Pointer on gadget_wrapper.
1085 void gadget_add_eps(struct gadget_wrapper *d)
1087 static const char *names[] = {
1124 int8_t dev_endpoints;
1126 DWC_DEBUGPL(DBG_PCDV, "%s\n", __func__);
1128 INIT_LIST_HEAD(&d->gadget.ep_list);
1129 d->gadget.ep0 = &d->ep0;
1130 d->gadget.speed = USB_SPEED_UNKNOWN;
1131 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0)
1132 d->gadget.max_speed = USB_SPEED_HIGH;
1135 INIT_LIST_HEAD(&d->gadget.ep0->ep_list);
1138 * Initialize the EP0 structure.
1142 /* Init the usb_ep structure. */
1143 ep->name = names[0];
1144 ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
1147 * @todo NGS: What should the max packet size be set to
1148 * here? Before EP type is set?
1150 ep->maxpacket = MAX_PACKET_SIZE;
1151 dwc_otg_pcd_ep_enable(d->pcd, NULL, ep);
1153 list_add_tail(&ep->ep_list, &d->gadget.ep_list);
1156 * Initialize the EP structures.
1158 dev_endpoints = d->pcd->core_if->dev_if->num_in_eps;
1160 for (i = 0; i < dev_endpoints; i++) {
1163 /* Init the usb_ep structure. */
1164 ep->name = names[d->pcd->in_ep[i].dwc_ep.num];
1165 ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
1168 * @todo NGS: What should the max packet size be set to
1169 * here? Before EP type is set?
1171 ep->maxpacket = MAX_PACKET_SIZE;
1172 list_add_tail(&ep->ep_list, &d->gadget.ep_list);
1175 dev_endpoints = d->pcd->core_if->dev_if->num_out_eps;
1177 for (i = 0; i < dev_endpoints; i++) {
1180 /* Init the usb_ep structure. */
1181 ep->name = names[15 + d->pcd->out_ep[i].dwc_ep.num];
1182 ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
1185 * @todo NGS: What should the max packet size be set to
1186 * here? Before EP type is set?
1188 ep->maxpacket = MAX_PACKET_SIZE;
1190 list_add_tail(&ep->ep_list, &d->gadget.ep_list);
1193 /* remove ep0 from the list. There is a ep0 pointer. */
1194 list_del_init(&d->ep0.ep_list);
1196 d->ep0.maxpacket = MAX_EP0_SIZE;
1200 * This function releases the Gadget device.
1201 * required by device_unregister().
1203 * @todo Should this do something? Should it free the PCD?
1205 static void dwc_otg_pcd_gadget_release(struct device *dev)
1207 DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, dev);
1210 static struct gadget_wrapper *alloc_wrapper(struct platform_device *_dev)
1212 static char pcd_name[] = "dwc_otg_pcd";
1214 dwc_otg_device_t *otg_dev = dwc_get_device_platform_data(_dev);
1215 struct gadget_wrapper *d;
1218 d = DWC_ALLOC(sizeof(*d));
1223 memset(d, 0, sizeof(*d));
1225 d->gadget.name = pcd_name;
1226 d->pcd = otg_dev->pcd;
1228 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30)
1229 strcpy(d->gadget.dev.bus_id, "gadget");
1231 dev_set_name(&d->gadget.dev, "%s", "gadget");
1234 d->gadget.dev.parent = &_dev->dev;
1235 d->gadget.dev.release = dwc_otg_pcd_gadget_release;
1236 d->gadget.ops = &dwc_otg_pcd_ops;
1237 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0)
1238 d->gadget.is_dualspeed = dwc_otg_pcd_is_dualspeed(otg_dev->pcd);
1240 d->gadget.is_otg = dwc_otg_pcd_is_otg(otg_dev->pcd);
1242 d->gadget.max_speed = USB_SPEED_HIGH;
1244 d->pcd->conn_en = 0;
1245 /* Register the gadget device */
1246 retval = usb_add_gadget_udc(&_dev->dev, &d->gadget);
1248 DWC_ERROR("device_register failed\n");
1256 static void free_wrapper(struct gadget_wrapper *d)
1259 /* should have been done already by driver model core */
1260 DWC_WARN("driver '%s' is still registered\n",
1261 d->driver->driver.name);
1262 usb_gadget_unregister_driver(d->driver);
1265 usb_del_gadget_udc(&d->gadget);
1269 static void dwc_otg_pcd_work_init(dwc_otg_pcd_t *pcd,
1270 struct platform_device *dev);
1273 * This function initialized the PCD portion of the driver.
1276 int pcd_init(struct platform_device *_dev)
1279 dwc_otg_device_t *otg_dev = dwc_get_device_platform_data(_dev);
1283 DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _dev);
1285 otg_dev->pcd = dwc_otg_pcd_init(otg_dev->core_if);
1286 printk("pcd_init otg_dev = %p\n", otg_dev);
1288 if (!otg_dev->pcd) {
1289 DWC_ERROR("dwc_otg_pcd_init failed\n");
1293 otg_dev->pcd->otg_dev = otg_dev;
1294 gadget_wrapper = alloc_wrapper(_dev);
1297 * Initialize EP structures
1299 gadget_add_eps(gadget_wrapper);
1301 * Setup interupt handler
1303 irq = platform_get_irq(_dev, 0);
1304 DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n", irq);
1305 retval = request_irq(irq, dwc_otg_pcd_irq,
1307 gadget_wrapper->gadget.name, otg_dev->pcd);
1309 DWC_ERROR("request of irq%d failed\n", irq);
1310 free_wrapper(gadget_wrapper);
1314 dwc_otg_pcd_start(gadget_wrapper->pcd, &fops);
1316 dwc_otg_pcd_work_init(otg_dev->pcd, _dev);
1324 void pcd_remove(struct platform_device *_dev)
1327 dwc_otg_device_t *otg_dev = dwc_get_device_platform_data(_dev);
1328 dwc_otg_pcd_t *pcd = otg_dev->pcd;
1331 DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _dev);
1336 irq = platform_get_irq(_dev, 0);
1338 free_wrapper(gadget_wrapper);
1339 dwc_otg_pcd_remove(otg_dev->pcd);
1344 * This function registers a gadget driver with the PCD.
1346 * When a driver is successfully registered, it will receive control
1347 * requests including set_configuration(), which enables non-control
1348 * requests. then usb traffic follows until a disconnect is reported.
1349 * then a host may connect again, or the driver might get unbound.
1351 * @param driver The driver being registered
1352 * @param bind The bind function of gadget driver
1355 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37)
1356 int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1358 int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1359 int (*bind) (struct usb_gadget *))
1364 DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n",
1365 driver->driver.name);
1368 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
1369 driver->speed == USB_SPEED_UNKNOWN ||
1371 driver->max_speed == USB_SPEED_UNKNOWN ||
1373 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37)
1378 !driver->unbind || !driver->disconnect || !driver->setup) {
1379 DWC_DEBUGPL(DBG_PCDV, "EINVAL\n");
1382 if (gadget_wrapper == 0) {
1383 DWC_DEBUGPL(DBG_PCDV, "ENODEV\n");
1386 if (gadget_wrapper->driver != 0) {
1387 DWC_DEBUGPL(DBG_PCDV, "EBUSY (%p)\n", gadget_wrapper->driver);
1391 /* hook up the driver */
1392 gadget_wrapper->driver = driver;
1393 gadget_wrapper->gadget.dev.driver = &driver->driver;
1395 DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
1396 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37)
1397 retval = driver->bind(&gadget_wrapper->gadget);
1399 retval = bind(&gadget_wrapper->gadget);
1402 DWC_ERROR("bind to driver %s --> error %d\n",
1403 driver->driver.name, retval);
1404 gadget_wrapper->driver = 0;
1405 gadget_wrapper->gadget.dev.driver = 0;
1408 DWC_DEBUGPL(DBG_ANY, "registered gadget driver '%s'\n",
1409 driver->driver.name);
1413 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37)
1414 EXPORT_SYMBOL(usb_gadget_register_driver);
1416 EXPORT_SYMBOL(usb_gadget_probe_driver);
1420 * This function unregisters a gadget driver
1422 * @param driver The driver being unregistered
1424 int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1426 /* DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _driver); */
1428 if (gadget_wrapper == 0) {
1429 DWC_DEBUGPL(DBG_ANY, "%s Return(%d): s_pcd==0\n", __func__,
1433 if (driver == 0 || driver != gadget_wrapper->driver) {
1434 DWC_DEBUGPL(DBG_ANY, "%s Return(%d): driver?\n", __func__,
1439 driver->unbind(&gadget_wrapper->gadget);
1440 gadget_wrapper->driver = 0;
1442 DWC_DEBUGPL(DBG_ANY, "unregistered driver '%s'\n", driver->driver.name);
1446 EXPORT_SYMBOL(usb_gadget_unregister_driver);
1450 /************************ for RK platform ************************/
1452 void dwc_otg_msc_lock(dwc_otg_pcd_t *pcd)
1454 unsigned long flags;
1455 local_irq_save(flags);
1456 wake_lock(&pcd->wake_lock);
1457 local_irq_restore(flags);
1460 void dwc_otg_msc_unlock(dwc_otg_pcd_t *pcd)
1462 unsigned long flags;
1463 local_irq_save(flags);
1464 wake_unlock(&pcd->wake_lock);
1465 local_irq_restore(flags);
1468 unsigned int dwc_otg_battery_detect(bool det_type)
1470 printk("%s\n", __func__);
1474 static void dwc_phy_reconnect(struct work_struct *work)
1477 dwc_otg_core_if_t *core_if;
1478 gotgctl_data_t gctrl;
1479 dctl_data_t dctl = {.d32 = 0 };
1480 struct dwc_otg_platform_data *pldata;
1482 pcd = container_of(work, dwc_otg_pcd_t, reconnect.work);
1483 pldata = pcd->otg_dev->pldata;
1484 core_if = GET_CORE_IF(pcd);
1485 gctrl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
1487 if (gctrl.b.bsesvld) {
1489 pldata->soft_reset(pldata, RST_RECNT);
1492 * Enable the global interrupt after all the interrupt
1493 * handlers are installed.
1496 DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
1497 dctl.b.sftdiscon = 0;
1498 DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
1501 ("*******************soft connect!!!*******************\n");
1505 static void id_status_change(dwc_otg_core_if_t *p, bool current_id)
1507 dwc_otg_core_if_t *core_if = p;
1509 gotgctl_data_t gotgctl = {.d32 = 0 };
1510 dwc_otg_pcd_t *pcd = core_if->otg_dev->pcd;
1512 gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
1513 DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
1514 DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
1516 if (core_if->usb_mode != USB_MODE_NORMAL)
1519 /* B-Device connector (Device Mode) */
1521 gotgctl_data_t gotgctl_local;
1522 /* Wait for switch to device mode. */
1523 while (!dwc_otg_is_device_mode(core_if)) {
1525 DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
1526 DWC_DEBUGPL(DBG_ANY,
1527 "Waiting for Peripheral Mode, Mode=%s count = %d gotgctl=%08x\n",
1528 (dwc_otg_is_host_mode(core_if) ? "Host" :
1529 "Peripheral"), count, gotgctl_local.d32);
1535 DWC_PRINTF("Connection id status change timed out");
1538 dwc_otg_set_force_mode(core_if, USB_MODE_FORCE_DEVICE);
1539 core_if->op_state = B_PERIPHERAL;
1540 cil_hcd_stop(core_if);
1541 /* pcd->phy_suspend = 1; */
1542 pcd->vbus_status = 0;
1543 dwc_otg_core_init(core_if);
1544 cil_pcd_start(core_if);
1545 dwc_otg_pcd_start_check_vbus_work(pcd);
1547 /* A-Device connector (Host Mode) */
1548 while (!dwc_otg_is_host_mode(core_if)) {
1549 DWC_DEBUGPL(DBG_ANY, "Waiting for Host Mode, Mode=%s\n",
1550 (dwc_otg_is_host_mode(core_if) ? "Host" :
1552 dwc_mdelay(1); /* vahrama previously was 100 */
1557 DWC_PRINTF("Connection id status change timed out");
1561 core_if->op_state = A_HOST;
1562 dwc_otg_set_force_mode(core_if, USB_MODE_FORCE_HOST);
1564 cancel_delayed_work(&pcd->check_vbus_work);
1567 * Initialize the Core for Host mode.
1569 dwc_otg_core_init(core_if);
1570 cil_hcd_start(core_if);
1571 dwc_otg_enable_global_interrupts(core_if);
1576 static void check_id(struct work_struct *work)
1578 dwc_otg_pcd_t *_pcd =
1579 container_of(work, dwc_otg_pcd_t, check_id_work.work);
1580 struct dwc_otg_device *otg_dev = _pcd->otg_dev;
1581 struct dwc_otg_platform_data *pldata = otg_dev->pldata;
1582 static int last_id = -1;
1583 int id = pldata->get_status(USB_STATUS_ID);
1585 if (last_id != id) {
1586 pr_info("[otg id chg] last id %d current id %d\n", last_id, id);
1587 if (!id) { /* Force Host */
1588 if (pldata->phy_status == USB_PHY_SUSPEND) {
1589 pldata->clock_enable(pldata, 1);
1590 pldata->phy_suspend(pldata, USB_PHY_ENABLED);
1592 id_status_change(otg_dev->core_if, id);
1593 } else { /* Force Device */
1594 id_status_change(otg_dev->core_if, id);
1598 schedule_delayed_work(&_pcd->check_id_work, (HZ));
1601 static void dwc_otg_pcd_check_vbus_work(struct work_struct *work)
1603 dwc_otg_pcd_t *_pcd =
1604 container_of(work, dwc_otg_pcd_t, check_vbus_work.work);
1605 struct dwc_otg_device *otg_dev = _pcd->otg_dev;
1606 struct dwc_otg_platform_data *pldata = otg_dev->pldata;
1608 if (pldata->get_status(USB_STATUS_BVABLID)) {
1609 /* if usb not connect before ,then start connect */
1610 if (_pcd->vbus_status == USB_BC_TYPE_DISCNT) {
1611 printk("***************vbus detect*****************\n");
1612 if( pldata->bc_detect_cb != NULL )
1613 pldata->bc_detect_cb(_pcd->vbus_status =
1614 usb_battery_charger_detect(1));
1616 _pcd->vbus_status = USB_BC_TYPE_SDP;
1617 if (_pcd->conn_en) {
1619 } else if (pldata->phy_status == USB_PHY_ENABLED) {
1620 /* do not allow to connect, suspend phy */
1621 pldata->phy_suspend(pldata, USB_PHY_SUSPEND);
1623 pldata->clock_enable(pldata, 0);
1625 } else if ((_pcd->conn_en) && (_pcd->conn_status >= 0)
1626 && (_pcd->conn_status < 2)) {
1627 printk("**************soft reconnect**************\n");
1629 } else if (_pcd->conn_status == 2) {
1630 /* release pcd->wake_lock if fail to connect,
1631 * allow system to enter second sleep.
1633 dwc_otg_msc_unlock(_pcd);
1634 _pcd->conn_status++;
1635 if (pldata->bc_detect_cb != NULL) {
1636 pldata->bc_detect_cb(_pcd->vbus_status =
1639 _pcd->vbus_status = USB_BC_TYPE_DCP;
1641 /* fail to connect, suspend usb phy and disable clk */
1642 if (pldata->phy_status == USB_PHY_ENABLED) {
1643 pldata->phy_suspend(pldata, USB_PHY_SUSPEND);
1645 pldata->clock_enable(pldata, 0);
1649 if (pldata->bc_detect_cb != NULL)
1650 pldata->bc_detect_cb(_pcd->vbus_status =
1651 usb_battery_charger_detect(0));
1653 _pcd->vbus_status = USB_BC_TYPE_DISCNT;
1655 if (_pcd->conn_status) {
1656 _pcd->conn_status = 0;
1659 if (pldata->phy_status == USB_PHY_ENABLED) {
1660 /* release wake lock */
1661 dwc_otg_msc_unlock(_pcd);
1662 /* no vbus detect here , close usb phy */
1663 pldata->phy_suspend(pldata, USB_PHY_SUSPEND);
1665 pldata->clock_enable(pldata, 0);
1668 /* usb phy bypass to uart mode */
1669 if (pldata->dwc_otg_uart_mode != NULL)
1670 pldata->dwc_otg_uart_mode(pldata, PHY_UART_MODE);
1673 schedule_delayed_work(&_pcd->check_vbus_work, HZ);
1677 if (pldata->phy_status) {
1678 pldata->clock_enable(pldata, 1);
1679 pldata->phy_suspend(pldata, USB_PHY_ENABLED);
1682 if (_pcd->conn_status == 0)
1683 dwc_otg_msc_lock(_pcd);
1685 schedule_delayed_work(&_pcd->reconnect, 8); /* delay 8 jiffies */
1686 schedule_delayed_work(&_pcd->check_vbus_work, (HZ));
1690 void dwc_otg_pcd_start_check_vbus_work(dwc_otg_pcd_t *pcd)
1693 * when receive reset int,the vbus state may not be update,so
1694 * always start vbus work here.
1696 schedule_delayed_work(&pcd->check_vbus_work, HZ/2);
1701 * 20091228,HSL@RK,to get the current vbus status.
1703 int dwc_vbus_status(void)
1705 #ifdef CONFIG_USB20_OTG
1706 dwc_otg_pcd_t *pcd = 0;
1707 if (gadget_wrapper) {
1708 pcd = gadget_wrapper->pcd;
1714 return pcd->vbus_status;
1720 EXPORT_SYMBOL(dwc_vbus_status);
1722 static void dwc_otg_pcd_work_init(dwc_otg_pcd_t *pcd,
1723 struct platform_device *dev)
1726 struct dwc_otg_device *otg_dev = pcd->otg_dev;
1727 struct dwc_otg_platform_data *pldata = otg_dev->pldata;
1729 pcd->vbus_status = USB_BC_TYPE_DISCNT;
1730 pcd->phy_suspend = USB_PHY_ENABLED;
1732 INIT_DELAYED_WORK(&pcd->reconnect, dwc_phy_reconnect);
1733 INIT_DELAYED_WORK(&pcd->check_vbus_work, dwc_otg_pcd_check_vbus_work);
1734 INIT_DELAYED_WORK(&pcd->check_id_work, check_id);
1736 wake_lock_init(&pcd->wake_lock, WAKE_LOCK_SUSPEND, "usb_pcd");
1738 if (dwc_otg_is_device_mode(pcd->core_if) &&
1739 (otg_dev->core_if->usb_mode != USB_MODE_FORCE_HOST)) {
1740 if (pldata->get_status(USB_STATUS_BVABLID)) {
1741 /* enter usb phy mode */
1742 pldata->dwc_otg_uart_mode(pldata, PHY_USB_MODE);
1744 /* usb phy bypass to uart mode */
1745 pldata->dwc_otg_uart_mode(pldata, PHY_UART_MODE);
1747 } else if (pldata->dwc_otg_uart_mode != NULL) {
1748 /* host mode,enter usb phy mode */
1749 pldata->dwc_otg_uart_mode(pldata, PHY_USB_MODE);
1751 schedule_delayed_work(&pcd->check_id_work, HZ);
1754 #endif /* DWC_HOST_ONLY */