yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | /* ========================================================================== |
| 2 | * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $ |
| 3 | * $Revision: #48 $ |
| 4 | * $Date: 2012/08/10 $ |
| 5 | * $Change: 2047372 $ |
| 6 | * |
| 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. |
| 10 | * |
| 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. |
| 20 | * |
| 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 |
| 31 | * DAMAGE. |
| 32 | * ========================================================================== */ |
| 33 | #ifndef DWC_HOST_ONLY |
| 34 | #if !defined(__DWC_PCD_H__) |
| 35 | #define __DWC_PCD_H__ |
| 36 | #include "usb.h" |
| 37 | #include "dwc_otg_cil.h" |
| 38 | #include "dwc_otg_pcd_if.h" |
| 39 | /** |
| 40 | * @file |
| 41 | * |
| 42 | * This file contains the structures, constants, and interfaces for |
| 43 | * the Perpherial Contoller Driver (PCD). |
| 44 | * |
| 45 | * The Peripheral Controller Driver (PCD) for Linux will implement the |
| 46 | * Gadget API, so that the existing Gadget drivers can be used. For |
| 47 | * the Mass Storage Function driver the File-backed USB Storage Gadget |
| 48 | * (FBS) driver will be used. The FBS driver supports the |
| 49 | * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only |
| 50 | * transports. |
| 51 | * |
| 52 | */ |
| 53 | |
| 54 | /** |
| 55 | * Get the pointer to the core_if from the pcd pointer. |
| 56 | */ |
| 57 | #define GET_CORE_IF( _pcd ) (_pcd->core_if) |
| 58 | |
| 59 | /** |
| 60 | * States of EP0. |
| 61 | */ |
| 62 | typedef enum ep0_state |
| 63 | { |
| 64 | EP0_DISCONNECT, /* no host */ |
| 65 | EP0_IDLE, |
| 66 | EP0_IN_DATA_PHASE, |
| 67 | EP0_OUT_DATA_PHASE, |
| 68 | EP0_IN_STATUS_PHASE, |
| 69 | EP0_OUT_STATUS_PHASE, |
| 70 | EP0_STALL, |
| 71 | } ep0state_e; |
| 72 | |
| 73 | /** Fordward declaration.*/ |
| 74 | struct dwc_otg_pcd; |
| 75 | |
| 76 | /** DWC_otg request structure. |
| 77 | * This structure is a list of requests. |
| 78 | */ |
| 79 | typedef struct dwc_otg_pcd_request |
| 80 | { |
| 81 | void *priv; |
| 82 | void *buf; |
| 83 | uint32_t dma; |
| 84 | uint32_t length; |
| 85 | uint32_t actual; |
| 86 | unsigned sent_zlp:1; |
| 87 | /** |
| 88 | * Used instead of original buffer if |
| 89 | * it(physical address) is not dword-aligned. |
| 90 | **/ |
| 91 | uint8_t *dw_align_buf; |
| 92 | uint32_t dw_align_buf_dma; |
| 93 | } dwc_otg_pcd_request_t; |
| 94 | |
| 95 | /** PCD EP structure. |
| 96 | * This structure describes an EP, there is an array of EPs in the PCD |
| 97 | * structure. |
| 98 | */ |
| 99 | typedef struct dwc_otg_pcd_ep |
| 100 | { |
| 101 | /** USB EP Descriptor */ |
| 102 | usb_endpoint_descriptor_t *desc; |
| 103 | |
| 104 | /** queue of dwc_otg_pcd_requests. */ |
| 105 | unsigned stopped:1; |
| 106 | unsigned disabling:1; |
| 107 | unsigned dma:1; |
| 108 | unsigned queue_sof:1; |
| 109 | dwc_ep_t dwc_ep; |
| 110 | |
| 111 | /** Pointer to PCD */ |
| 112 | struct dwc_otg_pcd *pcd; |
| 113 | |
| 114 | void *priv; |
| 115 | } dwc_otg_pcd_ep_t; |
| 116 | |
| 117 | /** DWC_otg PCD Structure. |
| 118 | * This structure encapsulates the data for the dwc_otg PCD. |
| 119 | */ |
| 120 | |
| 121 | typedef union |
| 122 | { |
| 123 | usb_device_request_t req; |
| 124 | uint32_t d32[2]; |
| 125 | }u_setup_pkt; |
| 126 | |
| 127 | struct dwc_otg_pcd |
| 128 | { |
| 129 | /** The DWC otg device pointer */ |
| 130 | struct dwc_otg_device *otg_dev; |
| 131 | /** Core Interface */ |
| 132 | dwc_otg_core_if_t *core_if; |
| 133 | /** State of EP0 */ |
| 134 | ep0state_e ep0state; |
| 135 | /** EP0 Request is pending */ |
| 136 | unsigned ep0_pending; |
| 137 | /** Indicates when SET CONFIGURATION Request is in process */ |
| 138 | unsigned request_config; |
| 139 | unsigned request_pending; |
| 140 | |
| 141 | /** SETUP packet for EP0 |
| 142 | * This structure is allocated as a DMA buffer on PCD initialization |
| 143 | * with enough space for up to 3 setup packets. |
| 144 | */ |
| 145 | u_setup_pkt *setup_pkt; |
| 146 | |
| 147 | uint32_t setup_pkt_dma_handle; |
| 148 | /* Additional buffer and flag for CTRL_WR premature case */ |
| 149 | uint8_t *backup_buf; |
| 150 | unsigned data_terminated; |
| 151 | |
| 152 | /** 2-byte dma buffer used to return status from GET_STATUS */ |
| 153 | uint16_t *status_buf; |
| 154 | uint32_t status_buf_dma_handle; |
| 155 | /** EP0 */ |
| 156 | dwc_otg_pcd_ep_t ep0; |
| 157 | |
| 158 | /** Array of IN EPs. */ |
| 159 | dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1]; |
| 160 | /** Array of OUT EPs. */ |
| 161 | dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1]; |
| 162 | |
| 163 | #ifdef DWC_UTE_CFI |
| 164 | cfiobject_t *cfi; |
| 165 | #endif |
| 166 | |
| 167 | }; |
| 168 | |
| 169 | #define CLEAR_OUT_EP_INTR(__core_if,__epnum,__intr) \ |
| 170 | do { \ |
| 171 | doepint_data_t doepint ; \ |
| 172 | doepint.d32 = 0;\ |
| 173 | doepint.b.__intr = 1; \ |
| 174 | DWC_WRITE_REG32(&__core_if->dev_if->out_ep_regs[__epnum]->doepint, \ |
| 175 | doepint.d32); \ |
| 176 | } while (0) |
| 177 | |
| 178 | #define CLEAR_IN_EP_INTR(__core_if,__epnum,__intr) \ |
| 179 | do { \ |
| 180 | diepint_data_t diepint; \ |
| 181 | diepint.d32 = 0;\ |
| 182 | diepint.b.__intr = 1; \ |
| 183 | DWC_WRITE_REG32(&__core_if->dev_if->in_ep_regs[__epnum]->diepint, \ |
| 184 | diepint.d32); \ |
| 185 | } while (0) |
| 186 | |
| 187 | #endif |
| 188 | #endif /* DWC_HOST_ONLY */ |