255 lines
7.7 KiB
C
255 lines
7.7 KiB
C
|
/* ==========================================================================
|
||
|
* BLX HS OTG Linux Software Driver and documentation (hereinafter,
|
||
|
* "Software") is an Unsupported proprietary work of BLX, Inc. unless
|
||
|
* otherwise expressly agreed to in writing between BLX and you.
|
||
|
*
|
||
|
* The Software IS NOT an item of Licensed Software or Licensed Product under
|
||
|
* any End User Software License Agreement or Agreement for Licensed Product
|
||
|
* with BLX or any supplement thereto. You are permitted to use and
|
||
|
* redistribute this Software in source and binary forms, with or without
|
||
|
* modification, provided that redistributions of source code must retain this
|
||
|
* notice. You may not view, use, disclose, copy or distribute this file or
|
||
|
* any information contained herein except pursuant to this license grant from
|
||
|
* BLX. If you do not agree with this notice, including the disclaimer
|
||
|
* below, then you are not authorized to use the Software.
|
||
|
*
|
||
|
* THIS SOFTWARE IS BEING DISTRIBUTED BY BLX SOLELY ON AN "AS IS" BASIS
|
||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||
|
* ARE HEREBY DISCLAIMED. IN NO EVENT SHALL BLX BE LIABLE FOR ANY DIRECT,
|
||
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||
|
* DAMAGE.
|
||
|
* ========================================================================== */
|
||
|
#ifndef GSC3280_HOST_ONLY
|
||
|
#if !defined(__GSC3280_PCD_H__)
|
||
|
#define __GSC3280_PCD_H__
|
||
|
|
||
|
#include "gsc3280_otg_os_dep.h"
|
||
|
#include "usb.h"
|
||
|
#include "gsc3280_otg_cil.h"
|
||
|
#include "gsc3280_otg_pcd_if.h"
|
||
|
struct cfiobject;
|
||
|
|
||
|
/**
|
||
|
* @file
|
||
|
*
|
||
|
* This file contains the structures, constants, and interfaces for
|
||
|
* the Perpherial Contoller Driver (PCD).
|
||
|
*
|
||
|
* The Peripheral Controller Driver (PCD) for Linux will implement the
|
||
|
* Gadget API, so that the existing Gadget drivers can be used. For
|
||
|
* the Mass Storage Function driver the File-backed USB Storage Gadget
|
||
|
* (FBS) driver will be used. The FBS driver supports the
|
||
|
* Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
|
||
|
* transports.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
/** Invalid DMA Address */
|
||
|
#define GSC3280_DMA_ADDR_INVALID (~(gsc3280_dma_t)0)
|
||
|
|
||
|
/** Max Transfer size for any EP */
|
||
|
#define DDMA_MAX_TRANSFER_SIZE 65535
|
||
|
|
||
|
/** Max DMA Descriptor count for any EP */
|
||
|
#define MAX_DMA_DESC_CNT 256
|
||
|
|
||
|
/**
|
||
|
* Get the pointer to the core_if from the pcd pointer.
|
||
|
*/
|
||
|
#define GET_CORE_IF( _pcd ) (_pcd->core_if)
|
||
|
|
||
|
/**
|
||
|
* States of EP0.
|
||
|
*/
|
||
|
typedef enum ep0_state {
|
||
|
EP0_DISCONNECT, /* no host */
|
||
|
EP0_IDLE,
|
||
|
EP0_IN_DATA_PHASE,
|
||
|
EP0_OUT_DATA_PHASE,
|
||
|
EP0_IN_STATUS_PHASE,
|
||
|
EP0_OUT_STATUS_PHASE,
|
||
|
EP0_STALL,
|
||
|
} ep0state_e;
|
||
|
|
||
|
/** Fordward declaration.*/
|
||
|
struct gsc3280_otg_pcd;
|
||
|
|
||
|
/** GSC3280_otg iso request structure.
|
||
|
*
|
||
|
*/
|
||
|
typedef struct usb_iso_request gsc3280_otg_pcd_iso_request_t;
|
||
|
|
||
|
#ifdef GSC3280_UTE_PER_IO
|
||
|
|
||
|
/**
|
||
|
* This shall be the exact analogy of the same type structure defined in the
|
||
|
* usb_gadget.h. Each descriptor contains
|
||
|
*/
|
||
|
struct gsc3280_iso_pkt_desc_port {
|
||
|
uint32_t offset;
|
||
|
uint32_t length; /* expected length */
|
||
|
uint32_t actual_length;
|
||
|
uint32_t status;
|
||
|
};
|
||
|
|
||
|
struct gsc3280_iso_xreq_port {
|
||
|
/** transfer/submission flag */
|
||
|
uint32_t tr_sub_flags;
|
||
|
/** Start the request ASAP */
|
||
|
#define GSC3280_EREQ_TF_ASAP 0x00000002
|
||
|
/** Just enqueue the request w/o initiating a transfer */
|
||
|
#define GSC3280_EREQ_TF_ENQUEUE 0x00000004
|
||
|
|
||
|
/**
|
||
|
* count of ISO packets attached to this request - shall
|
||
|
* not exceed the pio_alloc_pkt_count
|
||
|
*/
|
||
|
uint32_t pio_pkt_count;
|
||
|
/** count of ISO packets allocated for this request */
|
||
|
uint32_t pio_alloc_pkt_count;
|
||
|
/** number of ISO packet errors */
|
||
|
uint32_t error_count;
|
||
|
/** reserved for future extension */
|
||
|
uint32_t res;
|
||
|
/** Will be allocated and freed in the UTE gadget and based on the CFC value */
|
||
|
struct gsc3280_iso_pkt_desc_port *per_io_frame_descs;
|
||
|
};
|
||
|
#endif
|
||
|
/** GSC3280_otg request structure.
|
||
|
* This structure is a list of requests.
|
||
|
*/
|
||
|
typedef struct gsc3280_otg_pcd_request {
|
||
|
void *priv;
|
||
|
void *buf;
|
||
|
gsc3280_dma_t dma;
|
||
|
uint32_t length;
|
||
|
uint32_t actual;
|
||
|
unsigned sent_zlp:1;
|
||
|
|
||
|
GSC3280_CIRCLEQ_ENTRY(gsc3280_otg_pcd_request) queue_entry;
|
||
|
#ifdef GSC3280_UTE_PER_IO
|
||
|
struct gsc3280_iso_xreq_port ext_req;
|
||
|
//void *priv_ereq_nport; /* */
|
||
|
#endif
|
||
|
} gsc3280_otg_pcd_request_t;
|
||
|
|
||
|
GSC3280_CIRCLEQ_HEAD(req_list, gsc3280_otg_pcd_request);
|
||
|
|
||
|
/** PCD EP structure.
|
||
|
* This structure describes an EP, there is an array of EPs in the PCD
|
||
|
* structure.
|
||
|
*/
|
||
|
typedef struct gsc3280_otg_pcd_ep {
|
||
|
/** USB EP Descriptor */
|
||
|
const usb_endpoint_descriptor_t *desc;
|
||
|
|
||
|
/** queue of gsc3280_otg_pcd_requests. */
|
||
|
struct req_list queue;
|
||
|
unsigned stopped:1;
|
||
|
unsigned disabling:1;
|
||
|
unsigned dma:1;
|
||
|
unsigned queue_sof:1;
|
||
|
|
||
|
#ifdef GSC3280_EN_ISOC
|
||
|
/** ISOC req handle passed */
|
||
|
void *iso_req_handle;
|
||
|
#endif //_EN_ISOC_
|
||
|
|
||
|
/** GSC3280_otg ep data. */
|
||
|
gsc3280_ep_t gsc3280_ep;
|
||
|
|
||
|
/** Pointer to PCD */
|
||
|
struct gsc3280_otg_pcd *pcd;
|
||
|
|
||
|
void *priv;
|
||
|
} gsc3280_otg_pcd_ep_t;
|
||
|
|
||
|
/** GSC3280_otg PCD Structure.
|
||
|
* This structure encapsulates the data for the gsc3280_otg PCD.
|
||
|
*/
|
||
|
struct gsc3280_otg_pcd {
|
||
|
const struct gsc3280_otg_pcd_function_ops *fops;
|
||
|
/** The GSC3280 otg device pointer */
|
||
|
struct gsc3280_otg_device *otg_dev;
|
||
|
/** Core Interface */
|
||
|
gsc3280_otg_core_if_t *core_if;
|
||
|
/** State of EP0 */
|
||
|
ep0state_e ep0state;
|
||
|
/** EP0 Request is pending */
|
||
|
unsigned ep0_pending:1;
|
||
|
/** Indicates when SET CONFIGURATION Request is in process */
|
||
|
unsigned request_config:1;
|
||
|
/** The state of the Remote Wakeup Enable. */
|
||
|
unsigned remote_wakeup_enable:1;
|
||
|
/** The state of the B-Device HNP Enable. */
|
||
|
unsigned b_hnp_enable:1;
|
||
|
/** The state of A-Device HNP Support. */
|
||
|
unsigned a_hnp_support:1;
|
||
|
/** The state of the A-Device Alt HNP support. */
|
||
|
unsigned a_alt_hnp_support:1;
|
||
|
/** Count of pending Requests */
|
||
|
unsigned request_pending;
|
||
|
|
||
|
/** SETUP packet for EP0
|
||
|
* This structure is allocated as a DMA buffer on PCD initialization
|
||
|
* with enough space for up to 3 setup packets.
|
||
|
*/
|
||
|
union {
|
||
|
usb_device_request_t req;
|
||
|
uint32_t d32[2];
|
||
|
} *setup_pkt;
|
||
|
|
||
|
gsc3280_dma_t setup_pkt_dma_handle;
|
||
|
|
||
|
/** 2-byte dma buffer used to return status from GET_STATUS */
|
||
|
uint16_t *status_buf;
|
||
|
gsc3280_dma_t status_buf_dma_handle;
|
||
|
|
||
|
/** EP0 */
|
||
|
gsc3280_otg_pcd_ep_t ep0;
|
||
|
|
||
|
/** Array of IN EPs. */
|
||
|
gsc3280_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
|
||
|
/** Array of OUT EPs. */
|
||
|
gsc3280_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
|
||
|
/** number of valid EPs in the above array. */
|
||
|
// unsigned num_eps : 4;
|
||
|
gsc3280_spinlock_t *lock;
|
||
|
|
||
|
/** Tasklet to defer starting of TEST mode transmissions until
|
||
|
* Status Phase has been completed.
|
||
|
*/
|
||
|
gsc3280_tasklet_t *test_mode_tasklet;
|
||
|
|
||
|
/** Tasklet to delay starting of xfer in DMA mode */
|
||
|
gsc3280_tasklet_t *start_xfer_tasklet;
|
||
|
|
||
|
/** The test mode to enter when the tasklet is executed. */
|
||
|
unsigned test_mode;
|
||
|
/** The cfi_api structure that implements most of the CFI API
|
||
|
* and OTG specific core configuration functionality
|
||
|
*/
|
||
|
#ifdef GSC3280_UTE_CFI
|
||
|
struct cfiobject *cfi;
|
||
|
#endif
|
||
|
|
||
|
};
|
||
|
|
||
|
//FIXME this functions should be static, and this prototypes should be removed
|
||
|
extern void gsc3280_otg_request_nuke(gsc3280_otg_pcd_ep_t * ep);
|
||
|
extern void gsc3280_otg_request_done(gsc3280_otg_pcd_ep_t * ep,
|
||
|
gsc3280_otg_pcd_request_t * req, int32_t status);
|
||
|
|
||
|
void gsc3280_otg_iso_buffer_done(gsc3280_otg_pcd_t * pcd, gsc3280_otg_pcd_ep_t * ep,
|
||
|
void *req_handle);
|
||
|
|
||
|
extern void do_test_mode(void *data);
|
||
|
#endif
|
||
|
#endif /* GSC3280_HOST_ONLY */
|