epoc32/include/assp/omap3530_assp/omap3530_usbc.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@4
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@4
     2
// All rights reserved.
williamr@4
     3
// This component and the accompanying materials are made available
williamr@4
     4
// under the terms of the License "Eclipse Public License v1.0"
williamr@4
     5
// which accompanies this distribution, and is available
williamr@4
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@4
     7
//
williamr@4
     8
// Initial Contributors:
williamr@4
     9
// Nokia Corporation - initial contribution.
williamr@4
    10
//
williamr@4
    11
// Contributors:
williamr@4
    12
//
williamr@4
    13
// Description:
williamr@4
    14
// omap3530/omap3530_drivers/usbcc/omap3530_usbc.h
williamr@4
    15
// Platform-dependent USB client controller layer (USB PSL).
williamr@4
    16
//
williamr@4
    17
williamr@4
    18
williamr@4
    19
#ifndef __OMAP3530_USBC_H__
williamr@4
    20
#define __OMAP3530_USBC_H__
williamr@4
    21
williamr@4
    22
#include <e32cmn.h>
williamr@4
    23
#include <drivers/usbc.h>
williamr@4
    24
#include <assp/omap3530_assp/omap3530_assp_priv.h>
williamr@4
    25
williamr@4
    26
// This is the header file for the implementation of the USB driver PSL layer for an imaginary USB client
williamr@4
    27
// (device) controller.
williamr@4
    28
// For simplicity's sake we assume the following endpoint layout of the controller.
williamr@4
    29
// We have 5 endpoints in total - two Bulk endpoints (IN and OUT), two Isochronous endpoint (IN and OUT),
williamr@4
    30
// one Interrupt endpoint (IN), and of course endpoint zero (Ep0).
williamr@4
    31
//
williamr@4
    32
// This is the mapping of "Hardware Endpoint Numbers" to "Real Endpoints" (and thus is also
williamr@4
    33
// used as the array index for our local TTemplateAsspUsbcc::iEndpoints[]):
williamr@4
    34
//
williamr@4
    35
//	0 -	 0 (Ep0 OUT)
williamr@4
    36
//	0 -	 1 (Ep0 IN)
williamr@4
    37
//	1 -	 3 (Bulk  IN, Address 0x11, -> EpAddr2Idx(0x11) =  3)
williamr@4
    38
//	2 -	 4 (Bulk OUT, Address 0x02, -> EpAddr2Idx(0x02) =  4)
williamr@4
    39
//	3 -	 7 (Iso   IN, Address 0x13, -> EpAddr2Idx(0x13) =  7)
williamr@4
    40
//	4 -	 8 (Iso  OUT, Address 0x04, -> EpAddr2Idx(0x04) =  8)
williamr@4
    41
//	5 - 11 (Int   IN, Address 0x15, -> EpAddr2Idx(0x15) = 11)
williamr@4
    42
//
williamr@4
    43
// For the reason why this is so (or rather for the perhaps not so obvious system behind it),
williamr@4
    44
// see the comment at the beginning of \e32\drivers\usbcc\ps_usbc.cpp and also the structure
williamr@4
    45
// DeviceEndpoints[] at the top of pa_usbc.cpp.
williamr@4
    46
williamr@4
    47
// The total number of endpoints in our local endpoint array:
williamr@4
    48
static const TInt KUsbTotalEndpoints = 16; //32; // Disabled due to limited FIFO space
williamr@4
    49
williamr@4
    50
// The numbers used in the following macros are 'aRealEndpoint's (i.e. array indices):
williamr@4
    51
#define IS_VALID_ENDPOINT(x)	((x) > 0 && (x) < KUsbTotalEndpoints)
williamr@4
    52
#define IS_OUT_ENDPOINT(x)		IS_VALID_ENDPOINT(x) && ((x) == 0 || (x) == 2 || (x) == 4 || (x) == 6 || (x) == 8 || (x) == 10 || (x) == 12 || (x) == 14 || (x) == 16 || (x) == 18 || (x) == 20 || (x) == 22 ||(x) == 24 || (x) == 26 ||(x) == 28) 
williamr@4
    53
#define IS_IN_ENDPOINT(x)		IS_VALID_ENDPOINT(x) && ((x) == 1 || (x) == 3 || (x) == 5 || (x) == 7 || (x) == 9 || (x) == 11 || (x) == 13 || (x) == 15 || (x) == 17 || (x) == 19 || (x) == 21 || (x) == 23 ||(x) == 25 || (x) == 27 ||(x) == 29)
williamr@4
    54
#define IS_BULK_IN_ENDPOINT(x)	IS_VALID_ENDPOINT(x) && ((x) == 1 || (x) == 3 || (x) == 5 || (x) == 7 || (x) == 9 || (x) == 11 || (x) == 13 || (x) == 15 || (x) == 17 || (x) == 19 || (x) == 21 || (x) == 23 ||(x) == 25 || (x) == 27)
williamr@4
    55
#define IS_BULK_OUT_ENDPOINT(x)		IS_VALID_ENDPOINT(x) &&((x) == 2 || (x) == 4 || (x) == 6 || (x) == 8 || (x) == 10 || (x) == 12 || (x) == 14 || (x) == 16 || (x) == 18 || (x) == 20 || (x) == 22 ||(x) == 24 || (x) == 26 ||(x) == 28) 
williamr@4
    56
#define IS_BULK_ENDPOINT(x)		(IS_BULK_IN_ENDPOINT(x) || IS_BULK_OUT_ENDPOINT(x))
williamr@4
    57
#define IS_ISO_IN_ENDPOINT(x)	EFalse
williamr@4
    58
#define IS_ISO_OUT_ENDPOINT(x)	EFalse
williamr@4
    59
#define IS_ISO_ENDPOINT(x)		(IS_ISO_IN_ENDPOINT(x) || IS_ISO_OUT_ENDPOINT(x))
williamr@4
    60
#define IS_INT_IN_ENDPOINT(x)	IS_VALID_ENDPOINT(x) && ((x) == 29)
williamr@4
    61
williamr@4
    62
// This takes as an index the TTemplateAsspUsbcc::iEndpoints index (== aRealEndpoint) 0..11
williamr@4
    63
// and returns the hardware endpoint number 0..5 (note that not all input indices are valid;
williamr@4
    64
// these will return -1):
williamr@4
    65
/*static const TInt TBeagleAsspEndpoints[KUsbTotalEndpoints] = 
williamr@4
    66
{0, 0, 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};*/
williamr@4
    67
static const TInt TBeagleAsspEndpoints[KUsbTotalEndpoints] = 
williamr@4
    68
{0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
williamr@4
    69
williamr@4
    70
// And here is a function to use the above array:
williamr@4
    71
static inline TInt ArrayIdx2TemplateEp(TInt aRealEndpoint)
williamr@4
    72
	{
williamr@4
    73
	if (IS_VALID_ENDPOINT(aRealEndpoint)) return TBeagleAsspEndpoints[aRealEndpoint];
williamr@4
    74
	else return -1;
williamr@4
    75
	}
williamr@4
    76
	
williamr@4
    77
static inline TInt TemplateEp2ArrayIdx(TInt aRealEndpoint)
williamr@4
    78
	{
williamr@4
    79
	for(TInt x=0; x<KUsbTotalEndpoints; x++)
williamr@4
    80
		{
williamr@4
    81
		if(TBeagleAsspEndpoints[x]==aRealEndpoint)
williamr@4
    82
			return x;
williamr@4
    83
		}
williamr@4
    84
	return -1;
williamr@4
    85
	}
williamr@4
    86
williamr@4
    87
// Access to clocks is reference counted
williamr@4
    88
static TInt iSICLKEnabled;
williamr@4
    89
williamr@4
    90
// Endpoint max packet sizes
williamr@4
    91
static const TInt KEp0MaxPktSz = 64;						// Control
williamr@4
    92
static const TInt KIntMaxPktSz = 64;							// Interrupt
williamr@4
    93
static const TInt KBlkMaxPktSz = 512;						// Bulk
williamr@4
    94
static const TInt KIsoMaxPktSz = 256;						// Isochronous
williamr@4
    95
static const TInt KEp0MaxPktSzMask = KUsbEpSize64;			// Control
williamr@4
    96
static const TInt KIntMaxPktSzMask = KUsbEpSize64;			// Interrupt
williamr@4
    97
static const TInt KBlkMaxPktSzMask = /*KUsbEpSize64 | */KUsbEpSize512;			// Bulk
williamr@4
    98
static const TInt KIsoMaxPktSzMask = KUsbEpSize256;			// Isochronous
williamr@4
    99
williamr@4
   100
// 1 ms (i.e. the shortest delay possible with the sort of timer used) seems to give
williamr@4
   101
// the best results, both for Bulk and Iso, and also (in the USBRFLCT test program)
williamr@4
   102
// both for loop tests as well as unidirectional transfers.
williamr@4
   103
static const TInt KRxTimerTimeout = 5;						// milliseconds
williamr@4
   104
williamr@4
   105
// Used in descriptors
williamr@4
   106
static const TUint16 KUsbVendorId	= KUsbVendorId_Symbian;	// Symbian
williamr@4
   107
static const TUint16 KUsbProductId	= 0x0666;				// bogus...
williamr@4
   108
static const TUint16 KUsbDevRelease = 0x0100;				// bogus... (BCD!)
williamr@4
   109
static const TUint16 KUsbLangId		= 0x0409;				// English (US) Language ID
williamr@4
   110
williamr@4
   111
// String descriptor default values
williamr@4
   112
static const wchar_t KStringManufacturer[] = L"Symbian Software Ltd.";
williamr@4
   113
static const wchar_t KStringProduct[]	   = L"BeagleBoard";
williamr@4
   114
static const wchar_t KStringSerialNo[]	   = L"0123456789";
williamr@4
   115
static const wchar_t KStringConfig[]	   = L"First and Last and Always";
williamr@4
   116
williamr@4
   117
williamr@4
   118
// We use our own Ep0 state enum:
williamr@4
   119
enum TEp0State
williamr@4
   120
	{
williamr@4
   121
	EP0_IDLE = 0,											// These identifiers don't conform to
williamr@4
   122
	EP0_OUT_DATA_PHASE = 1,									// Symbian's coding standard... ;)
williamr@4
   123
	EP0_IN_DATA_PHASE = 2,
williamr@4
   124
	EP0_END_XFER = 3,
williamr@4
   125
	};
williamr@4
   126
williamr@4
   127
williamr@4
   128
williamr@4
   129
class DOmap3530Usbcc;
williamr@4
   130
// The lowest level endpoint abstraction
williamr@4
   131
struct TEndpoint
williamr@4
   132
	{
williamr@4
   133
	TEndpoint();
williamr@4
   134
	static void RxTimerCallback(TAny* aPtr);
williamr@4
   135
	// data
williamr@4
   136
	DOmap3530Usbcc* iController;						// pointer to controller object
williamr@4
   137
	union
williamr@4
   138
		{
williamr@4
   139
		TUint8* iRxBuf;										// where to store /
williamr@4
   140
		const TUint8* iTxBuf;								// from where to send
williamr@4
   141
		};
williamr@4
   142
	union
williamr@4
   143
		{
williamr@4
   144
		TInt iReceived;										// bytes already rx'ed /
williamr@4
   145
		TInt iTransmitted;									// bytes already tx'ed
williamr@4
   146
		};
williamr@4
   147
	TInt iLength;											// number of bytes to be transferred
williamr@4
   148
	TBool iZlpReqd;											// ZeroLengthPacketRequired
williamr@4
   149
	TBool iNoBuffer;										// no data buffer was available when it was needed
williamr@4
   150
	TBool iDisabled;										// dto but stronger
williamr@4
   151
	TInt iPackets;											// number of packets rx'ed or tx'ed
williamr@4
   152
	TInt iLastError;										//
williamr@4
   153
	TUsbcRequestCallback* iRequest;							//
williamr@4
   154
	NTimer iRxTimer;										//
williamr@4
   155
	TBool iRxTimerSet;										// true if iRxTimer is running
williamr@4
   156
	TBool iRxMoreDataRcvd;									// true if after setting timer data have arrived
williamr@4
   157
	TUsbcPacketArray* iPacketIndex;							// actually TUsbcPacketArray (*)[]
williamr@4
   158
	TUsbcPacketArray* iPacketSize;							// actually TUsbcPacketArray (*)[]
williamr@4
   159
	};
williamr@4
   160
williamr@4
   161
williamr@4
   162
// The hardware driver object proper
williamr@4
   163
class Omap3530BoardAssp;
williamr@4
   164
class MOmap3530UsbPhy;
williamr@4
   165
williamr@4
   166
NONSHARABLE_CLASS( DOmap3530Usbcc ) : public DUsbClientController
williamr@4
   167
	{
williamr@4
   168
friend void TEndpoint::RxTimerCallback(TAny*);
williamr@4
   169
williamr@4
   170
public:
williamr@4
   171
	enum TPHYMode
williamr@4
   172
		{
williamr@4
   173
		ENormal,
williamr@4
   174
		EPowerUp,
williamr@4
   175
		EPeripheralChirp,
williamr@4
   176
		EUART
williamr@4
   177
		};
williamr@4
   178
williamr@4
   179
public:
williamr@4
   180
	DOmap3530Usbcc();
williamr@4
   181
	TInt Construct();
williamr@4
   182
	virtual ~DOmap3530Usbcc();
williamr@4
   183
	virtual void DumpRegisters();
williamr@4
   184
williamr@4
   185
private:
williamr@4
   186
	virtual TInt SetDeviceAddress(TInt aAddress);
williamr@4
   187
	virtual TInt ConfigureEndpoint(TInt aRealEndpoint, const TUsbcEndpointInfo& aEndpointInfo);
williamr@4
   188
	virtual TInt DeConfigureEndpoint(TInt aRealEndpoint);
williamr@4
   189
	virtual TInt AllocateEndpointResource(TInt aRealEndpoint, TUsbcEndpointResource aResource);
williamr@4
   190
	virtual TInt DeAllocateEndpointResource(TInt aRealEndpoint, TUsbcEndpointResource aResource);
williamr@4
   191
	virtual TBool QueryEndpointResource(TInt aRealEndpoint, TUsbcEndpointResource aResource) const;
williamr@4
   192
	virtual TInt OpenDmaChannel(TInt aRealEndpoint);
williamr@4
   193
	virtual void CloseDmaChannel(TInt aRealEndpoint);
williamr@4
   194
	virtual TInt SetupEndpointRead(TInt aRealEndpoint, TUsbcRequestCallback& aCallback);
williamr@4
   195
	virtual TInt SetupEndpointWrite(TInt aRealEndpoint, TUsbcRequestCallback& aCallback);
williamr@4
   196
	virtual TInt CancelEndpointRead(TInt aRealEndpoint);
williamr@4
   197
	virtual TInt CancelEndpointWrite(TInt aRealEndpoint);
williamr@4
   198
	virtual TInt SetupEndpointZeroRead();
williamr@4
   199
	virtual TInt SetupEndpointZeroWrite(const TUint8* aBuffer, TInt aLength, TBool aZlpReqd = EFalse);
williamr@4
   200
	virtual TInt SendEp0ZeroByteStatusPacket();
williamr@4
   201
	virtual TInt StallEndpoint(TInt aRealEndpoint);
williamr@4
   202
	virtual TInt ClearStallEndpoint(TInt aRealEndpoint);
williamr@4
   203
	virtual TInt EndpointStallStatus(TInt aRealEndpoint) const;
williamr@4
   204
	virtual TInt EndpointErrorStatus(TInt aRealEndpoint) const;
williamr@4
   205
	virtual TInt ResetDataToggle(TInt aRealEndpoint);
williamr@4
   206
	virtual TInt SynchFrameNumber() const;
williamr@4
   207
	virtual void SetSynchFrameNumber(TInt aFrameNumber);
williamr@4
   208
	virtual TInt StartUdc();
williamr@4
   209
	virtual TInt StopUdc();
williamr@4
   210
	virtual TInt UdcConnect();
williamr@4
   211
	virtual TInt UdcDisconnect();
williamr@4
   212
	virtual TBool UsbConnectionStatus() const;
williamr@4
   213
	virtual TBool UsbPowerStatus() const;
williamr@4
   214
	virtual TBool DeviceSelfPowered() const;
williamr@4
   215
	virtual const TUsbcEndpointCaps* DeviceEndpointCaps() const;
williamr@4
   216
	virtual TInt DeviceTotalEndpoints() const;
williamr@4
   217
	virtual TBool SoftConnectCaps() const;
williamr@4
   218
	virtual TBool DeviceStateChangeCaps() const;
williamr@4
   219
	virtual void Suspend();
williamr@4
   220
	virtual void Resume();
williamr@4
   221
	virtual void Reset();
williamr@4
   222
	virtual TInt SignalRemoteWakeup();
williamr@4
   223
	virtual void Ep0ReadSetupPktProceed();
williamr@4
   224
	virtual void Ep0ReceiveProceed();
williamr@4
   225
	virtual TDfcQue* DfcQ(TInt aUnit);
williamr@4
   226
	virtual TBool CurrentlyUsingHighSpeed();
williamr@4
   227
williamr@4
   228
private:
williamr@4
   229
	// general
williamr@4
   230
	void EnableEndpointInterrupt(TInt aEndpoint);
williamr@4
   231
	void DisableEndpointInterrupt(TInt aEndpoint);
williamr@4
   232
	void ClearEndpointInterrupt(TInt aEndpoint);
williamr@4
   233
	void InitialiseUdcRegisters();
williamr@4
   234
	void UdcEnable();
williamr@4
   235
	void UdcDisable();
williamr@4
   236
	TInt SetupUdcInterrupt();
williamr@4
   237
	void ReleaseUdcInterrupt();
williamr@4
   238
	void UdcInterruptService();
williamr@4
   239
	void EndpointIntService(TInt aEndpoint);
williamr@4
   240
	TInt ResetIntService();
williamr@4
   241
	void SuspendIntService();
williamr@4
   242
	void ResumeIntService();
williamr@4
   243
	void SofIntService();
williamr@4
   244
	static void UdcIsr(TAny* aPtr);
williamr@4
   245
	static TInt UsbClientConnectorCallback(TAny* aPtr);
williamr@4
   246
	// endpoint zero
williamr@4
   247
	void Ep0IntService();
williamr@4
   248
	void Ep0ReadSetupPkt();
williamr@4
   249
	void Ep0Receive();
williamr@4
   250
	void Ep0Transmit();
williamr@4
   251
	void Ep0EndXfer();
williamr@4
   252
	void Ep0Cancel();
williamr@4
   253
	void Ep0PrematureStatusOut();
williamr@4
   254
	void Ep0StatusIn();
williamr@4
   255
	void Ep0NextState(TEp0State aNextState);
williamr@4
   256
	// endpoint n with n != 0
williamr@4
   257
	void BulkTransmit(TInt aEndpoint);
williamr@4
   258
	void BulkReceive(TInt aEndpoint);
williamr@4
   259
	void BulkReadRxFifo(TInt aEndpoint);
williamr@4
   260
	void IsoTransmit(TInt aEndpoint);
williamr@4
   261
	void IsoReceive(TInt aEndpoint);
williamr@4
   262
	void IsoReadRxFifo(TInt aEndpoint);
williamr@4
   263
	void IntTransmit(TInt aEndpoint);
williamr@4
   264
	void RxComplete(TEndpoint* aEndpoint);
williamr@4
   265
	void StopRxTimer(TEndpoint* aEndpoint);
williamr@4
   266
	
williamr@4
   267
private:
williamr@4
   268
	void EnableSICLK();
williamr@4
   269
	void DisableSICLK();
williamr@4
   270
	
williamr@4
   271
	// Dfc functions
williamr@4
   272
	static void SuspendDfcFn(TAny *aPtr);
williamr@4
   273
	static void ResumeDfcFn(TAny *aPtr);
williamr@4
   274
	static void ResetDfcFn(TAny *aPtr);
williamr@4
   275
	
williamr@4
   276
public:
williamr@4
   277
	TBool DeviceHighSpeedCaps() const;
williamr@4
   278
williamr@4
   279
private:
williamr@4
   280
	// general
williamr@4
   281
	TBool iSoftwareConnectable;
williamr@4
   282
	TBool iCableDetectable;
williamr@4
   283
	TBool iCableConnected;
williamr@4
   284
	TBool iBusIsPowered;
williamr@4
   285
	TBool iInitialized;
williamr@4
   286
	TInt (*iUsbClientConnectorCallback)(TAny *);
williamr@4
   287
	Omap3530Assp* iAssp;
williamr@4
   288
	// endpoint zero
williamr@4
   289
	TBool iEp0Configured;
williamr@4
   290
	TEp0State iEp0State;
williamr@4
   291
	// endpoints n
williamr@4
   292
	TEndpoint iEndpoints[KUsbTotalEndpoints];				// for how this is indexed, see top of pa_usbc.cpp
williamr@4
   293
		
williamr@4
   294
	// Dfc's for configuring the Tranceiver when we get a Suspend/Resume/Reset interrupt.
williamr@4
   295
	TDfcQue* iDfcQueue;
williamr@4
   296
	
williamr@4
   297
	TDfc iSuspendDfc;
williamr@4
   298
	TDfc iResumeDfc;
williamr@4
   299
	TDfc iResetDfc;
williamr@4
   300
williamr@4
   301
	MOmap3530UsbPhy*	iPhy;
williamr@4
   302
	TUint	iPrmClientId;
williamr@4
   303
	};
williamr@4
   304
williamr@4
   305
williamr@4
   306
class MOmap3530UsbPhy
williamr@4
   307
	{
williamr@4
   308
public:
williamr@4
   309
	IMPORT_C static MOmap3530UsbPhy* New();
williamr@4
   310
williamr@4
   311
	virtual void StartPHY() = 0;
williamr@4
   312
	virtual void SetPHYMode( DOmap3530Usbcc::TPHYMode aMode ) = 0;
williamr@4
   313
	virtual void EnablePHY() = 0;
williamr@4
   314
	virtual void DisablePHY() = 0;
williamr@4
   315
	};
williamr@4
   316
williamr@4
   317
williamr@4
   318
#endif // __PA_USBC_H__