usbd.h 15.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
#ifndef	_USBD_H_
#define	_USBD_H_

//#include "usbconfig.h"
#include "stdDespt.h"
#include "hstack.h"


//#define IPOD_USB_AUDIO_CHARGE_ONLY


//move from "usbd.c"
#define	GET_CONFIG_1ST_LEN		8
#define	GET_CONFIG_TRY_LOOPS	32

#define	U16_BYTE_SWAP( x16 )	( x16 )


/*
	usb dev request
*/
typedef struct {
	U8	bmRequestType;
	U8	bRequest;
	U16 wValue;
	U16 wIndex;
	U16 wLength;
} __attribute__ ((packed)) USB_DEV_REQEUST;


 //for USB Audio Class 2.0
#define UAC20
extern BOOL UACver2;	// UAC2 version

#ifdef UAC20
//jj+ for UAC2
extern BOOL gIAD;		//IAD descriptor exists

typedef struct {    //Audio20 4.6 Table 4-3: Standard Interface Association Descriptor jj+
	U8	bLength;
	U8	bDescriptorType;
	U8	bFirstInterface;
	U8	bInterfaceCount;
	U8	bFunctionClass;
	U8	bFunctionSubClass;
	U8	bFunctionProtocol;
	U8	iFunction;
}	__attribute__  ((packed)) USB_IAD_DESCRIPTOR;
#define	USB_IAD_DESCRIPTOR_LENGTH		8

typedef struct {    //Audio20 4.7.2.1 Clock Source Descriptor: Table 4-6: Clock Source Descriptor jj+
	U8	bLength;	//8
	U8	bDescriptorType;
	U8	bDescriptorSubtype;
	U8	bClockID;
	U8	bmAttributes;
	U8	bmControls;
	U8	bAssocTerminal;
	U8	iClockSource;
}	__attribute__  ((packed)) USB_CSD_DESCRIPTOR;
#define	USB_CSD_DESCRIPTOR_LENGTH		8

typedef struct {    //Audio20 4.7.2.2 Clock Selector Descriptor: Table 4-7: Clock Selector Descriptor jj+
	U8	bLength;	//variable
	U8	bDescriptorType;
	U8	bDescriptorSubtype;
	U8	bClockID;
	U8	bNrInPins;
	U8	baCSourceID[10];	//p max to 10
	U8	bmControls;
	U8	iClockSelector;
}	__attribute__  ((packed)) USB_CXD_DESCRIPTOR;
#define	USB_CXD_DESCRIPTOR_LENGTH		10

typedef struct {    //Audio20 4.7.2.3 Clock Multiplier Descriptor: Table 4-8: Clock Multiplier Descriptor jj+
	U8	bLength;	//7
	U8	bDescriptorType;
	U8	bDescriptorSubtype;
	U8	bClockID;
	U8	bCSourceID;
	U8	bmControls;
	U8	iClockMultiplier;
}	__attribute__  ((packed)) USB_CMD_DESCRIPTOR;
#define	USB_CMD_DESCRIPTOR_LENGTH		7

typedef struct {     //USB20 9.5 Table 9-13. Standard Endpoint Descriptor
	U8	bLength;	//7
	U8	bDescriptorType;
	U8	bEndpointAddress;
	U8	bmAttributes;
	U16	wMaxPacketSize;
	U8	bInterval;
}	__attribute__  ((packed)) USB_ENDPOINT_UAC2_DESCRIPTOR;
#define	USB_ENDPOINT_UAC2_DESCRIPTOR_LENGTH			7

typedef struct {     //audio20 4.10.1.2 Class-Specific AS Isochronous Audio Data Endpoint Descriptor,Table 4-34: Class-Specific AS Isochronous Audio Data Endpoint Descriptor
	U8	bLength;	//8
	U8	bDescriptorType;
	U8	bDescriptorSubtype;
	U8	bmAttributes;
	U8	bmControls;
	U8	bLockDelayUnits;
	U16	wLockDelay;
}	__attribute__  ((packed)) USB_CSENDPOINT_UAC2_DESCRIPTOR;
#define	USB_CSENDPOINT_UAC2_DESCRIPTOR_LENGTH			7

typedef struct {     //audio20 4.10.2.1 Standard AS Isochronous Feedback Endpoint Descriptor,Table 4-35: Standard AS Isochronous Feedback Endpoint Descriptor
	U8	bLength;	//7
	U8	bDescriptorType;
	U8	bEndpointAddress;
	U8	bmAttributes;
	U16	wMaxPacketSize;
	U8	bInterval;
}	__attribute__  ((packed)) USB_FBENDPOINT_UAC2_DESCRIPTOR;
#define	USB_FBENDPOINT_UAC2_DESCRIPTOR_LENGTH			7

#endif //UAC20


#define	FILL_USB_REQUEST( PREQ,	REQTYPE,	REQUEST,	VALUE,	INDEX,	LENGTH ) \
	do {	\
		(PREQ)->bmRequestType	=	REQTYPE;	\
		(PREQ)->bRequest		=	REQUEST;	\
		(PREQ)->wValue			=	(VALUE);		\
		(PREQ)->wIndex			=	(INDEX);		\
		(PREQ)->wLength			=	(LENGTH);		\
	} while(0)	
	//DBG_Printf("FILL UR %x,%x,%x\n",(PREQ)->bmRequestType,(PREQ)->bRequest,(PREQ)->wLength);\

#define	FILL_GET_DESP_USB_REQUEST( PREQ,	REQTYPE,	REQUEST,	DTYPE, DINDEX,	LANGID,	LENGTH ) \
	do {	\
		(PREQ)->bmRequestType	=	REQTYPE;	\
		(PREQ)->bRequest		=	REQUEST;	\
		(PREQ)->wValue			=	(DTYPE << 8) | DINDEX;		\
		(PREQ)->wIndex			=	(LANGID);		\
		(PREQ)->wLength			=	(LENGTH);		\
	} while(0)	
	//DBG_Printf("FILL GDUR %x,%x,%x\n",(PREQ)->bmRequestType,(PREQ)->bRequest,(PREQ)->wLength);\


#define	REQUEST_TYPE	\
	(REQUEST_TYPE_DIR_D2H | REQUEST_TYPE_TYPE_STANDARD | REQUEST_TYPE_RECIPIENT_DEVICE)

#define	REQUEST_TYPE_CLRFEATURE_ENDPSTALL	\
	(REQUEST_TYPE_DIR_H2D | REQUEST_TYPE_TYPE_STANDARD | REQUEST_TYPE_RECIPIENT_ENDPOINT)

#define	USBDEV_STDREQ_CLEAR_FEATURE				(0x0200 | USB_REQUEST_CLEAR_FEATURE)	//3 type
#define	USBDEV_STDREQ_GET_CONFIGURATION			(0x8000 | USB_REQUEST_GET_CONFIGURATION)
#define	USBDEV_STDREQ_GET_DESCRIPTOR			(0x8000 | USB_REQUEST_GET_DESCRIPTOR)
#define	USBDEV_STDREQ_GET_STATUS				(0x8000 | USB_REQUEST_GET_STATUS)		//3 type
#define	USBDEV_STDREQ_SET_ADDRESS				(0x0000 | USB_REQUEST_SET_ADDRESS)
#define	USBDEV_STDREQ_SET_CONFIGURATION			(0x0000 | USB_REQUEST_SET_CONFIGURATION)
#define	USBDEV_STDREQ_SET_FEATURE				(0x0000 | USB_REQUEST_SET_FEATURE)		//3 type
#define	USBDEV_STDREQ_SET_INTERFACE				(0x0100 | USB_REQUEST_SET_INTERFACE)

#define	USBDEV_MSCREQ_GET_MAX_LUN				(0xa100 | USB_REQUEST_GET_MAX_LUN )
#define	USBDEV_MSCREQ_BULK_RESET				(0x2100 | USB_REQUEST_BULK_ONLY_MASS_STORAGE_RESET )

#define	USBDEV_MSREQTYPE_GET_MS_DESPT			0xC0



//jj+ Table 11-15. bmRequestType for USB Hub, Hub Class Requests.
#define USBDEV_STDREQ_GET_STATUS_DEVICE		(0x80)

#define	HUBClassREQTYPE_CLR_HUBFEATURE		(0x20)
#define	HUBClassREQTYPE_CLR_PORTFEATURE		(0x23)

#define	HUBClassREQTYPE_GET_HUBDESCPT		(0xA0)
#define	HUBClassREQTYPE_GET_HUBSTATUS		(0xA0)
#define	HUBClassREQTYPE_GET_PORTSTATUS		(0xA3)

#define	HUBClassREQTYPE_SET_HUBDESCPT		(0x20)
#define	HUBClassREQTYPE_SET_HUBFEATURE		(0x20)
#define	HUBClassREQTYPE_SET_PORTFEATURE		(0x23)

//jj+ Table 9-4. Standard Request Codes
#define DEVREQUEST_GET_STATUS					(0x00)
#define DEVREQUEST_CLEAR_FEATURE				(0x01)
#define DEVREQUEST_SET_FEATURE					(0x03)
#define DEVREQUEST_SET_ADDRESS					(0x05)
#define DEVREQUEST_GET_DESCRIPTOR				(0x06)
#define DEVREQUEST_SET_DESCRIPTOR				(0x07)
#define DEVREQUEST_GET_CONFIGURATION			(0x08)
#define DEVREQUEST_SET_CONFIGURATION			(0x09)
#define DEVREQUEST_GET_INTERFACE				(0x0A)
#define DEVREQUEST_SET_INTERFACE				(0x0B)

//jj+ for Table 11-17. Hub Class Feature Selectors
#define	HUBC_FSEL_C_HUB_LOCAL_POWER 			(0)
#define	HUBC_FSEL_C_HUB_OVER_CURRENT  			(1)
#define	HUBC_FSEL_PORT_CONNECTION  				(0)
#define	HUBC_FSEL_PORT_ENABLE  					(1)
#define	HUBC_FSEL_PORT_SUSPEND  				(2)
#define	HUBC_FSEL_PORT_OVER_CURRENT  			(3)
#define	HUBC_FSEL_PORT_RESET  					(4)
#define	HUBC_FSEL_PORT_POWER  					(8)
#define	HUBC_FSEL_PORT_LOW_SPEED  				(9)
#define	HUBC_FSEL_C_PORT_CONNECTION  			(0x10)
#define	HUBC_FSEL_C_PORT_ENABLE  				(0x11)
#define	HUBC_FSEL_C_PORT_SUSPEND  				(0x12)
#define	HUBC_FSEL_C_PORT_OVER_CURRENT  			(0x13)
#define	HUBC_FSEL_C_PORT_RESET  				(0x14)
#define	HUBC_FSEL_PORT_TEST  					(0x15)
#define	HUBC_FSEL_PORT_INDICATOR  				(0x16)



typedef	struct {
	U16	vid;
	U16	pid;
}	USBDEV_ID;

/*
	BUS / device
*/
#define	USBBUS_MAX_DEVICES			4
#define	USBBUS_DEFAULT_DEV_ADDR		0

#define	USBBUS_MAX_DEV_ADDR			128
#define	USBBUS_ADDR_BUF_SIZE		(USBBUS_MAX_DEV_ADDR/8)

struct _USB_DEVICE;
typedef struct _USB_BUS {
//	U8	nextAllocDevNum;		//dev addr to allocate
	//struct hcd
	struct _USB_DEVICE	*rootHub;
	struct _USB_DEVICE	*singleDevice;
	
//	struct _USB_DEVICE	*deviceArray[USBBUS_MAX_DEVICES];
	U8	totalConDevs;
//	U8	bulkDevNum;
//	U8	hubNum;

	U32	maxControlFrameLimit;	// 0 is un-limited
	U32	maxBulkFrameLimit;

	U32	bandwidthAlloc;
	U8	addrBuf[USBBUS_ADDR_BUF_SIZE];
}	USB_BUS;

typedef enum {
	enDEV_STAT_DEATTACHED	=	0,
	enDEV_STAT_ATTACHED,
	enDEV_STAT_POWERED,
	enDEV_STAT_DEFAULT,
	enDEV_STAT_ADDRESS,
	enDEV_STAT_CONFIGED,
	enDEV_STAT_SUSPENDED
}	enum_USBDEV_STATE;

typedef enum {
	enSPEED_UNKNOWN,
	enSPEED_LOW,
	enSPEED_FULL,
	enSPEED_HIGH
}	enum_USB_SPEED;

typedef struct {
	USB_CONFIGURATION_DESCRIPTOR	config;
	USB_INTERFACE_DESCRIPTOR		intf;
	USB_ENDPOINT_DESCRIPTOR			endp[2];	
}	__attribute__ ((packed)) USB_DEV_CONFIG;

#define	ENDPOINT_DESCRIPTOR_NUM		0x02
#define	CONFIGURATION_TOTAL_LEN		(USB_CONFIGURATION_DESCRIPTOR_LENGTH +	\
									USB_INTERFACE_DESCRIPTOR_LENGTH +		\
									USB_ENDPOINT_DESCRIPTOR_LENGTH*ENDPOINT_DESCRIPTOR_NUM )
//	CONFIGURATION_TOTAL_LEN = 32

#define	INTF_MAX_ENDPS				6
typedef	struct {
	USB_INTERFACE_DESCRIPTOR		*intf;
	U8	actEndpIn;
	U8	actEndpOut;
	U8	actEndpIntIn;
	USB_ENDPOINT_DESCRIPTOR			*endps[INTF_MAX_ENDPS];
}	USB_INTERFACE;
#define	CONFIG_MAX_INTFS			6
typedef	struct {
	USB_CONFIGURATION_DESCRIPTOR	*config;	
	U8	activeIntf;
	USB_INTERFACE					intfs[CONFIG_MAX_INTFS];
}	USB_CONFIGURATION;

#define	MAX_CONFIGURATION		6

#define	MAX_STR_DESCRIPTOR		3
#define	MAX_STR_DESP_WORD		30
#define	MAX_STR_DESP_BYTE		(2*MAX_STR_DESP_WORD)

#define	ENDP_ADDR_IN_MASK		0x80

struct _MSOS_STRING_DESCRIPTOR;
struct _MS_OS_EXTENDED_CONFIGURATION_DESCRIPTOR;




typedef	enum {
	enPIPE_INDX_CTRL	=	0,
	enPIPE_INDX_BULK_OUT,
	enPIPE_INDX_BULK_IN,
	enPIPE_INDX_INT_OUT,
	enPIPE_INDX_INT_IN,
	enPIPE_INDX_ISO_OUT,
	enPIPE_INDX_ISO_IN,
	enPIPE_INDX_MAX			//7
}	enum_PIPE_INDEX;	


#if 1//def IPOD_USB_AUDIO
#include "audio.h"

typedef struct {
	USB_INTERFACE_DESCRIPTOR	*intf;
	USB_ENDPOINT_DESCRIPTOR	*bulkIn;
	USB_ENDPOINT_DESCRIPTOR	*bulkOut;
} MSC_INTF;

typedef struct _AUDIO_CTL_INTF {
	USB_INTERFACE_DESCRIPTOR	*intf;
	AUDIO_CTL_INTF_DESPT	*intfClass;
	USB_ENDPOINT_DESCRIPTOR	*intIn;

	U8	*tdud;
	int tdudSize;
	int tdudNums;	//don't parse
} AUDIO_CTL_INTF;

typedef struct _AUDIO_STREAM_INTF {
	USB_INTERFACE_DESCRIPTOR	*intfAlt0;	//zero band
	USB_INTERFACE_DESCRIPTOR	*intfAlt1;
	AUDIO_STREAM_INTF_DESPT		*intfClass;

	TYPEI_FORMAT_DESPT	*format;
	int	fmtNumSampleFreq;
	U8	*sampleFreq;

	USB_ENDPOINT_DESCRIPTOR	*isoEndp;
	AUDIO_ISO_ENDP_DESPT	*isoClassEndp;
} AUDIO_STREAM_INTF;
#endif


//The "IPOD_USB_AUDIO" macro is defined in the file of "oem_drogon.h"
//the head file must use the macro below.
#if (defined AOA_USB_AUDIO || defined USB_HOST_AUDIO_ENABLE)

struct _IPOD_DEVICE;

typedef struct _USB_DEVICE {
	U8	addr;				//addr

	U8	state;				//enum_USBDEV_STATE
	U8	speed;				//enum_USB_SPEED

	U32	epMaxInPacket[16];
	U32 epMaxOutPacket[16];
	//U32	epMaxPacket[2][16];	//USB_DIR_IN/USB_DIR_OUT in hcd.h
	U32	epToggle[2];		
	U8	epBulk[2];			
	U8	epInt[2];
#ifdef USB_HOST_AUDIO_ENABLE
	//U8	epIso[2];	//jj+ for Host Audio
#endif

	PIPE pipes[enPIPE_INDX_MAX];

	USB_DEVICE_DESCRIPTOR	devDescriptor;

#if 0
	USB_HUB_DESCRIPTOR hubDescriptor; //JJ+, don't support USB Hub
#endif

	U16 stringDescriptor[MAX_STR_DESCRIPTOR][MAX_STR_DESP_WORD];

#if (defined IPOD_USB_AUDIO || defined IPOD_USB_AUDIO_CHARGE_ONLY)
	struct _IPOD_DEVICE *ipodDev; //added by IPOD_USB_AUDIO
#endif

	//obsolete
//	U8	activeConfigVal;
//	USB_DEV_CONFIG	activeConfig;
//	U8	*tmpConfigBuf;
//	U32	tmpConfigBufTotalLen;
//	U32	tmpConfigTotalLen;

	#if 1
	#if 1//(defined AOA_USB_AUDIO || defined USB_HOST_AUDIO_ENABLE)
	#define	CONFIG_BUF_SIZE     256 /*changed for AOA & USB Host Audio*/
	#else
	#define	CONFIG_BUF_SIZE		64
	#endif
	#endif
	
	#if 0
	#if 1//(defined AOA_USB_AUDIO || defined USB_HOST_AUDIO_ENABLE)
	#define	CONFIG_BUF_SIZE     512 /*changed for AOA & USB Host Audio*/
	//#define CONFIG_BUF_SIZE     384 /*changed for AOA & USB Host Audio*/
	#else
	#define CONFIG_BUF_SIZE     64
	#endif
	#endif
	
	//CONFIG despt + audioCtl i/f despt + 2x audioStream i/f despt + hid i/f

	U8	activeConfigVal;
	USB_CONFIGURATION	activeConfig;
	U8	configBuffer[CONFIG_BUF_SIZE];
	U32	configBufTotLen;
	U32	configTotLen;

	U8	totLUNs;	//total present
	U8	maxLUN;		//supported

	USB_BUS	*usbBus;
	struct _USB_DEVICE *parent;
	U8	port;

	U8	devType;
	void *classDev;
	char ipodType;
	
	U8	msDevType;
	struct _MSOS_STRING_DESCRIPTOR	*msosStringDespt;
	struct _MS_OS_EXTENDED_CONFIGURATION_DESCRIPTOR	*msosConfigDespt;

}	USB_DEVICE;

#else

typedef struct _USB_DEVICE {
	U8	addr;				//addr

	U8	state;				//enum_USBDEV_STATE
	U8	speed;				//enum_USB_SPEED

	U32	epMaxInPacket[16];
	U32 epMaxOutPacket[16];
	//U32	epMaxPacket[2][16];	//USB_DIR_IN/USB_DIR_OUT in hcd.h
	U32	epToggle[2];		
	U8	epBulk[2];			
	U8	epInt[2];
#ifdef USB_HOST_AUDIO_ENABLE
	//U8	epIso[2];	//jj+ for Host Audio
#endif
	
	PIPE pipes[enPIPE_INDX_MAX];

	USB_DEVICE_DESCRIPTOR	devDescriptor;
	U16 stringDescriptor[MAX_STR_DESCRIPTOR][MAX_STR_DESP_WORD];

	//obsolete
//	U8	activeConfigVal;
//	USB_DEV_CONFIG	activeConfig;
//	U8	*tmpConfigBuf;
//	U32	tmpConfigBufTotalLen;
//	U32	tmpConfigTotalLen;

#define	CONFIG_BUF_SIZE		64
	//CONFIG despt + audioCtl i/f despt + 2x audioStream i/f despt + hid i/f

	U8	activeConfigVal;
	USB_CONFIGURATION	activeConfig;
	U8	configBuffer[CONFIG_BUF_SIZE];
	U32	configBufTotLen;
	U32	configTotLen;

	U8	totLUNs;	//total present
	U8	maxLUN;		//supportted

	USB_BUS	*usbBus;
	struct _USB_DEVICE *parent;
	U8	port;

	U8	devType;
	void *classDev;
	char ipodType;
	
	U8	msDevType;
	struct _MSOS_STRING_DESCRIPTOR	*msosStringDespt;
	struct _MS_OS_EXTENDED_CONFIGURATION_DESCRIPTOR	*msosConfigDespt;

}	USB_DEVICE;

#endif



#ifdef USB_HOST_AUDIO_ENABLE
//#include "ipoddev.h"
//#include "hid.h"
//#include "ipod.h"

U8 installAudioDeviceDriver( USB_DEVICE * usbDev );

#endif //USB_HOST_AUDIO_ENABLE



#if (defined IPOD_USB_AUDIO || defined USB_HOST_AUDIO_ENABLE)

//#include "ipoddev.h"
#include "hid.h"
//#include "ipod.h"

typedef	struct {
	U8	type;

	union {
		MSC_INTF	mscIntf;
		HID_INTF	hidIntf;
		AUDIO_CTL_INTF	audioCtlIntf;
		AUDIO_STREAM_INTF	audioStreamIntf;

		//FIXME: add AOA/ADB
	} intfs;

} USB_INTF;

typedef	struct {
	U8	type;
	USB_CONFIGURATION_DESCRIPTOR	*configDespt;

	int	maxIntfs;
	int	intfnum;

	USB_INTF intfs[CONFIG_MAX_INTFS];
} USB_CONFIGS;

#endif //(defined IPOD_USB_AUDIO || defined USB_HOST_AUDIO_ENABLE


typedef enum {
	enINTF_UNKOWN,
	enINTF_IMAGE,
	enINTF_MSC,
	enINTF_HID,
	enINTF_AUDIO_CTL,
	enINTF_AUDIO_STREAM,
	enINTF_AOA,
	enINTF_ADB
}	enum_INTF_TYPE;

typedef enum {
	enCONFIG_UNKOWN,
	enCONFIG_IMAGE,
	enCONFIG_MSC,
	enCONFIG_HID,
	enCONFIG_AUDIO,
	enCONFIG_IPOD_DIGI_AUDIO	//audio+hid
}	enum_CONFIG_TYPE;

typedef enum {
	enNON_IPOD,
	enIPOD_DEV,
	enIPOD_ANALOG_MSC,		//only msc, no hid
	enIPOD_ANALOG_HID,
	enIPOD_DIGITAL_AUDIO,
	enIPOD_CHARGE_ONLY,
	enIPOD_UNKNOWN			//only support uart ?
}	enum_IPOD_TYPE;

typedef	enum {
	enMS_DEV_UNKOWN,
	enMS_DEV_MTP,

	enMS_DEV_MAX
}	enum_MS_DEV_TYPE;

typedef	enum {
	enUSB_DEV_MSC=0,
	enUSB_DEV_HUB,
	
	enUSB_DEV_IMAGE,	//PTP

	enUSB_DEV_IPOD,
	enUSB_DEV_AOA,
	
	enUSB_DEV_UNKOWN,	//0x05
	enUSB_DEV_MTP,

	enUSB_DEV_IPOD_CHARGE_ONLY,
	
	enUSB_DEV_DISCONNECT,	

	enUSB_DEV_TEST,
	enUSB_DEV_TEST_UNKOWN,
	enUSB_DEV_TEST_BYPASS,

#ifdef USB_HOST_AUDIO_ENABLE
	enUSB_DEV_AUDIO,	//0x0c, jj+ for Host Audio
#endif

	enUSB_DEV_MAX
}	enum_USB_DEV_TYPE;


typedef	struct {
	U32	urbMaxTimoutRetry;
	U32	urbMaxUncompRetry;
	U32	urbMaxIntUncompRetry;
}	CONFIG_PARAM;

extern CONFIG_PARAM *pconfigParam;
extern USB_DEVICE singleUsbDevice;

void usbd_init( void );
void usbd_open(void);
void usbd_close( void );


U8 usbd_bulkTransaction( USB_DEVICE *usbDev, U8 *buf, U32 *totalLen, U16 pipe );
U8 usbd_controlTransaction( USB_DEVICE *usbDev, U8 *setupPacket, U8 *buf, U32 *totalLen, U16 pipe );
U8 usbd_intTransaction( USB_DEVICE *usbDev, U8 *buf, U32 *totalLen, U16 pipe, U32 interval );

U8 usbd_mscResetRecovery( USB_DEVICE *usbDev );
U8 usbd_clearFeatureEndpHalt( USB_DEVICE *usbDev, U16 endp );

USB_DEVICE *usbd_getRootHub( void );
BOOL usbd_isDevHub( USB_DEVICE *dev );
BOOL usbd_isDevActive ( USB_DEVICE *dev );

//return enum_USB_DEV_TYPE
int usbd_getActiveDevType(void);


int usbd_mtpRequestCancel( USB_DEVICE *usbDev, U32 transID );
int usbd_mtpRequestGetStatus( USB_DEVICE *usbDev, U16 *statCode );

extern volatile U8 gwUsbDeviceReady;

int usbd_isIpodNoSrc( void );
int usbd_getActiveDev( USB_DEVICE **dev );
int usbd_isIpodExtModeProhibit( void );

int usbd_getCurrentDeviceType( void );
int usbd_get_usbhost_audio_device_status(void);


#endif //_USBD_H_