bcp_usb.h 5.57 KB
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
		 BCP USB test head file : bcp_usb.h
	:set tabtop=4
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef __BCP_USB_HEADER__
#define __BCP_USB_HEADER__

#define USB_MI_INT         0x02
#define USB_REG_ADDR(wh, usb0_reg) (((wh)?USB1_BASE_REG:USB0_BASE_REG)+\
									((usb0_reg) - USB0_BASE_REG))

#define USB_SRAM0(addr)   (((addr) & USB0_BDT_SRAM)==USB0_BDT_SRAM)
#define USB_SRAM1(addr)   (((addr) & USB1_BDT_SRAM)==USB1_BDT_SRAM)
 
/* USB BDT data structure */
   
   /* note those two value have to be 512 aligned */ 
#define USB0_RX_BUF1  	  (0x00001000)
#define USB0_RX_BUF2  	  (0x00002000)
#define USB0_TX_BUF1  	  (0x00003000)
#define USB0_TX_BUF2   	  (0x00004000)

#define USB1_RX_BUF1  	  (0x0000a000)
#define USB1_RX_BUF2  	  (0x0000b000)
#define USB1_TX_BUF1  	  (0x0000c000)
#define USB1_TX_BUF2   	  (0x0000d000)

#ifdef BIGEN      
typedef volatile struct BufferDescriptor_Struct
{
  unsigned rsrvd31_26   :   6;
  unsigned bytecnt      :   10;
  unsigned rsrvd15_8    :   8;
  unsigned own          :   1; // 7: own
  unsigned data0_1      :   1; // 6: data0/1
  unsigned pid          :   4; // 5-2: pid
  unsigned rsrvd1_0     :   2;
  unsigned buffer_addr  :   32;
} BufferDescriptor ;
#else
typedef volatile struct BufferDescriptor_Struct
{
  unsigned rsrvd1_0     :   2;
  unsigned pid          :   4; // 5-2: pid
  unsigned data0_1      :   1; // 6: data0/1
  unsigned own          :   1; // 7: own
  unsigned rsrvd15_8    :   8;
  unsigned bytecnt      :   10;
  unsigned rsrvd31_26   :   6;
  unsigned buffer_addr  :   32;
} BufferDescriptor ;
#endif

typedef struct _BCP_USB_TRANSCTION {
	int host;			/* In host mode */
	int token_id;		/* which token id */
	int data_id;		/* data id, 0 after reset */ 
	char* pkt_data;
	int pkt_len;		/* pkt */
	int buf_addr;		/* memory address to hold pkt */
	int device_id;		/* USB device id */
	int ack_back;		/* Ack back ? */
	int bdt_addr;		/* BDT address in memory */
	void *bdt_ptr;		/* BDT point for test */
	int endpt;			/* Which end point */
} BCP_USB_TRANS;

/* BCP EXTEND MACRO */
/* Used to trigger the process of extenal USB model */

	/*  BCP_USB_TEST_ON Request */
#define BCP_USB_TEST_ON_SET		0x00010000  /* Bit 16 */
#define BCP_USB_TEST_ERR_SET	0x00020000  /* Bit 17 */
#define BCP_USB_PKT_LEN_SET		0x00040000  /* Bit 18 */
#define BCP_USB_TOKEN_PID		0x00080000	/* Bit 19 */
#define BCP_USB_PKT_PID			0x00100000  /* Bit 20 */
#define BCP_USB_ENDPT			0x00200000  /* Bit 21 */
#define BCP_USB_ACK				0x00400000	/* Bit 22 */
#define BCP_USB_DEVICE_ID		0x00800000  /* Bit 23 */

	/* BCP_USB_READ_STAT Request */
#define BCP_USB_TEST_MASK		0x000000FF  /* 7:0 */
#define BCP_USB_TEST_ERR		0x0000FF00  /* 15:8 */
#define BCP_USB_TEST_ERR_SHFT	8
	/* Max should be 0x3ff, but it does not matter in our case */
#define BCP_USB_PKT_LEN_MASK	0x000007FF  /* max=1023 */
#define BCP_USB_PKT_LEN_SHFT	16
#define BCP_USB_INT_MASK		0x08000000  /* 27 */

	/* BCP_USB_READ_DATA & BCP_USB_WRITE_DATA REQ*/
	
	/* Which Test */
#define BCP_HOST_SETUP_ON		0x00000080	/* Bit 7 */
#define BCP_HOST_RCV_SOF_ON		0x00000040 	/* Bit 6 */
#define BCP_HOST_OUT_ON			0x00000020	/* Bit 5 */
#define BCP_HOST_IN_ON			0x00000010	/* Bit 4 */

#define BCP_DEVICE_SETUP_ON		0x00000008	/* Bit 3 */
#define BCP_DEVICE_RESET_ON		0x00000004  /* Bit 2 */
#define BCP_DEVICE_OUT_ON		0x00000002	/* Bit 1 */
#define BCP_DEVICE_IN_ON		0x00000001  /* Bit 0 */

	/* Which Error */
#define BCP_HOST_SETUP_ERR		0x00008000	/* Bit 15 */
#define BCP_HOST_RCV_SOF_ERR 	0x00004000	/* Bit 14 */
#define BCP_HOST_OUT_ERR		0x00002000  /* Bit 13 */
#define BCP_HOST_IN_ERR			0x00001000	/* Bit 12 */

#define BCP_DEVICE_SETUP_ERR	0x00000800	/* Bit 11 */
#define BCP_DEVICE_RESET_ERR	0x00000400	/* Bit 10 */
#define BCP_DEVICE_OUT_ERR		0x00000200	/* Bit  9 */
#define BCP_DEVICE_IN_ERR		0x00000100  /* Bit  8 */

#define BCP_TEST_IN_PID			0x9
#define BCP_TEST_OUT_PID		0x1
#define BCP_TEST_SETUP_PID		0xD
#define BCP_USB_DATA0_PID		0x3
#define BCP_USB_DATA1_PID		11

#define BCP_USB_BDT_SIZE		8

/* set up the buffer descriptor table
   BDT array is [endpt][tx][odd] 
   
   In our case, we also defined usb0_bdt and usb1_bdt
   (does not need to be 512 bytes algined) then we use
   ri function to read/write it to 
   USB?_BDT_ADDR(have to be 512 bytes algined)  
*/
#define MAX_ENDPNT   	    16        /* Max end point */ 
typedef BufferDescriptor BufferDescriptorTableType[MAX_ENDPNT][2][2];
extern BufferDescriptorTableType usb0_bdt, usb1_bdt;

/* Test  API */
int usb_read_reg_test(int which, int reg,  int exp, int extra);
int usb_reset_test(int which_usb, int a2, int a3, int a4);
int usb_reg_write_test(int which, int reg, int data, int extra);
int usb_reg_rw(int which, int reg, int data, int mask);
int usb_bdt_sram(int which, int times, int extra0, int extra1);

int usb_device_test(int which, int extra, int extra2, int extra3);
int usb_line_state_test(int which, int extra1, int extra2, int extra3);
int usb_otg_test(int which, int extra1, int extra2, int extra3);
int usb_simple_host_echo(int which, int a1, int a2, int a3);
int usb_simple_host_echo(int which, int a1, int a2, int a3);
int hosts_test(int, int, int, int);
int hosts_one_test(int, int, int, int);

/* Other functions */
int set_usb_int_mask(int which);
int clear_usb_int_mask(int which);
int usb_write_bdt_data(int which,
            BufferDescriptorTableType *bd_table_ptr, int endpt);
int usb_read_bdt_data(int which,
            BufferDescriptorTableType *bd_table_ptr, int endpt);

int hosts_setup(int usb0_host, int usb1_host, int bdt_addr0, int bdt_addr1);

int bcp_line_state_test(int which, int, int, int);

#endif