os/kernelhwsrv/kernel/eka/include/drivers/usbcshared.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/include/drivers/usbcshared.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1657 @@
     1.4 +// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32\include\drivers\usbcshared.h
    1.18 +// Kernel side definitions for the USB Device driver stack (PIL + LDD).
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +/**
    1.23 + @file usbcshared.h
    1.24 + @internalTechnology
    1.25 +*/
    1.26 +
    1.27 +#ifndef __USBCSHARED_H__
    1.28 +#define __USBCSHARED_H__
    1.29 +
    1.30 +#include <drivers/usbcque.h>
    1.31 +
    1.32 +// Define here what options are required:
    1.33 +// (USB_SUPPORTS_CONTROLENDPOINTS and USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
    1.34 +//  have never been tested though...)
    1.35 +//#define USB_SUPPORTS_CONTROLENDPOINTS
    1.36 +//#define USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
    1.37 +
    1.38 +#include <drivers/usbcdesc.h>
    1.39 +
    1.40 +// Debug Support
    1.41 +
    1.42 +// Use for debugging purposes only (commented out for normal operation):
    1.43 +//#define USBC_LDD_BUFFER_TRACE
    1.44 +
    1.45 +static const char KUsbPILPanicCat[] = "USB PIL FAULT"; // kernel fault category
    1.46 +_LIT(KUsbPILKillCat, "USB PIL KILL");					// thread kill category
    1.47 +_LIT(KUsbLDDKillCat, "USB LDD KILL");					// thread kill category
    1.48 +
    1.49 +/** Error code for stalled endpoint.
    1.50 +*/
    1.51 +const TInt KErrEndpointStall = KErrLocked;
    1.52 +
    1.53 +/** Error code for Ep0 write prematurely ended by a host OUT token.
    1.54 +*/
    1.55 +const TInt KErrPrematureEnd = KErrDiskFull;
    1.56 +
    1.57 +/** The following constants control the buffer arrangement for OUT transfers (IN transfers have only 1
    1.58 +	buffer). The total size of buffering for an OUT endpoint will be number of buffers * buffersize,
    1.59 +	so that, for example, a Bulk OUT endpoint will have KUsbcDmaBufNumBulk * KUsbcDmaBufSzBulk bytes of
    1.60 +	buffering.
    1.61 +	These buffers will be physically contiguous, so that DMA may be used.
    1.62 +	The number of buffers MUST be >=2 - otherwise the buffering scheme won't work.
    1.63 +	The buffer sizes should be an exact fraction of 4kB and the number of buffers such that the
    1.64 +	buffersize * number of buffers is an exact multiple of 4kB, otherwise memory will be wasted.
    1.65 +*/
    1.66 +/** Size of a Control ep buffer.
    1.67 +*/
    1.68 +const TInt KUsbcDmaBufSzControl = 1024;
    1.69 +
    1.70 +/** Size of a Bulk ep buffer.
    1.71 +*/
    1.72 +const TInt KUsbcDmaBufSzBulk = 4096;
    1.73 +
    1.74 +/** Size of an Interrupt ep buffer.
    1.75 +*/
    1.76 +const TInt KUsbcDmaBufSzInterrupt = 4096;
    1.77 +
    1.78 +/** Size of an Isochronous ep buffer.
    1.79 +*/
    1.80 +const TInt KUsbcDmaBufSzIsochronous = 4096;
    1.81 +
    1.82 +/** Number of buffers for Control OUT endpoints.
    1.83 +*/
    1.84 +const TInt KUsbcDmaBufNumControl = 2;
    1.85 +
    1.86 +/** Number of buffers for Isochronous OUT endpoints.
    1.87 +*/
    1.88 +const TInt KUsbcDmaBufNumIsochronous = 2;
    1.89 +
    1.90 +/** Number of buffers for Bulk OUT endpoints.
    1.91 +*/
    1.92 +const TInt KUsbcDmaBufNumBulk = 2;
    1.93 +
    1.94 +/** Number of buffers for Interrupt OUT endpoints.
    1.95 +*/
    1.96 +const TInt KUsbcDmaBufNumInterrupt = 2;
    1.97 +
    1.98 +/** Maximum buffer number.
    1.99 +*/
   1.100 +const TInt KUsbcDmaBufNumMax = MAX4(KUsbcDmaBufNumControl, KUsbcDmaBufNumIsochronous,
   1.101 +									KUsbcDmaBufNumBulk, KUsbcDmaBufNumInterrupt);
   1.102 +
   1.103 +/** Maximum number of recorded packets possible.
   1.104 +*/
   1.105 +const TUint KUsbcDmaBufMaxPkts = 2;
   1.106 +
   1.107 +/** Number of arrays.
   1.108 +*/
   1.109 +const TInt KUsbcDmaBufNumArrays = 2;
   1.110 +
   1.111 +/** Max size that Ep0 packets might have.
   1.112 +*/
   1.113 +const TInt KUsbcBufSzControl = 64;
   1.114 +
   1.115 +/** The Ep0 RX data collection buffer area.
   1.116 +	(Arbitrary size, judged to be sufficient for SET_DESCRIPTOR requests)
   1.117 +*/
   1.118 +const TInt KUsbcBufSz_Ep0Rx = 1024;
   1.119 +
   1.120 +/** The Ep0 TX buffer area.
   1.121 +	(Size sufficient to hold as much data as can be requested via GET_DESCRIPTOR)
   1.122 +*/
   1.123 +const TInt KUsbcBufSz_Ep0Tx = 1024 * 64; 
   1.124 +
   1.125 +
   1.126 +/** The USB version the stack is compliant with: 2.0 (BCD).
   1.127 +*/
   1.128 +const TUint16 KUsbcUsbVersion = 0x0200;
   1.129 +
   1.130 +/** Maximum number of endpoints an interface (i.e. LDD) may have.
   1.131 +*/
   1.132 +const TInt KUsbcMaxEpNumber = 5;
   1.133 +
   1.134 +/** Status FIFO depth; enough for 2 complete configs.
   1.135 +*/
   1.136 +const TInt KUsbDeviceStatusQueueDepth = 15;
   1.137 +
   1.138 +/** = 'no status info'.
   1.139 +*/
   1.140 +const TUint32 KUsbDeviceStatusNull = 0xffffffffu;
   1.141 +
   1.142 +/** = 'no buffer available'.
   1.143 +*/
   1.144 +const TInt KUsbcInvalidBufferIndex = -1;
   1.145 +
   1.146 +/** = 'no packet available'.
   1.147 +*/
   1.148 +const TUint KUsbcInvalidPacketIndex = (TUint)(-1);
   1.149 +
   1.150 +/** = 'no drainable buffers'.
   1.151 +*/
   1.152 +const TInt KUsbcInvalidDrainQueueIndex = -1;
   1.153 +
   1.154 +/** Number of possible bandwidth priorities.
   1.155 +*/
   1.156 +const TInt KUsbcDmaBufMaxPriorities = 4;
   1.157 +
   1.158 +// The following buffer sizes are used within the LDD for the different
   1.159 +// user-selectable endpoint bandwidth priorities
   1.160 +// (EUsbcBandwidthOUTDefault/Plus1/Plus2/Maximum + the same for 'IN').
   1.161 +// These values, in particular those for the Maximum setting, were obtained
   1.162 +// empirically.
   1.163 +
   1.164 +/** Bulk IN buffer sizes for different priorities (4K, 16K, 64K, 512K).
   1.165 +*/
   1.166 +const TInt KUsbcDmaBufSizesBulkIN[KUsbcDmaBufMaxPriorities] =
   1.167 +	{KUsbcDmaBufSzBulk, 0x4000, 0x10000, 0x80000};
   1.168 +
   1.169 +/** Bulk OUT buffer sizes for different priorities (4K, 16K, 64K, 512K).
   1.170 +*/
   1.171 +const TInt KUsbcDmaBufSizesBulkOUT[KUsbcDmaBufMaxPriorities] =
   1.172 +	{KUsbcDmaBufSzBulk, 0x4000, 0x10000, 0x80000};
   1.173 +
   1.174 +/** Number of UDCs supported in the system.
   1.175 +	(Support for more than one UDC is preliminary.)
   1.176 +*/
   1.177 +const TInt KUsbcMaxUdcs = 2;
   1.178 +
   1.179 +/** Number of endpoints a USB device can have.
   1.180 +	(30 regular endpoints + 2 x Ep0)
   1.181 +*/
   1.182 +const TInt KUsbcEpArraySize = KUsbcMaxEndpoints + 2;
   1.183 +
   1.184 +/** Number of notification requests of the same kind that can be registered at
   1.185 +	a time. As normally not more than one request per kind per LDD is
   1.186 +	permitted, this number is roughly equivalent to the maximum number of LDDs
   1.187 +	that can be operating at the same time.
   1.188 +	This constant is used by the PIL while maintaining its request lists
   1.189 +	(iClientCallbacks, iStatusCallbacks, iEpStatusCallbacks, iOtgCallbacks) to
   1.190 +	ensure that the lists are of a finite length and thus the list traverse
   1.191 +	time is bounded.
   1.192 +	This value is chosen with the maximum number of USB interfaces (not
   1.193 +	settings) allowed by the spec for a single device in mind.
   1.194 +*/
   1.195 +const TInt KUsbcMaxListLength = 256;
   1.196 +
   1.197 +/** Used by the LDD.
   1.198 +*/
   1.199 +typedef TUint32 TUsbcPacketArray;
   1.200 +
   1.201 +
   1.202 +/** Used as a return value from DUsbClientController::EnquireEp0NextState(),
   1.203 +	the purpose of which is to enable the PSL to find out what the next stage
   1.204 +	will be for a newly received Setup packet.
   1.205 +
   1.206 +	The enum values are self-explanatory.
   1.207 +
   1.208 +	@publishedPartner
   1.209 +	@released
   1.210 +*/
   1.211 +enum TUsbcEp0State
   1.212 +	{
   1.213 +	EEp0StateDataIn,
   1.214 +	EEp0StateDataOut,
   1.215 +	EEp0StateStatusIn
   1.216 +	};
   1.217 +
   1.218 +
   1.219 +/** Used to show the direction of a transfer request to the Controller.
   1.220 +
   1.221 +	@see TUsbcRequestCallback
   1.222 +*/
   1.223 +enum TTransferDirection {EControllerNone, EControllerRead, EControllerWrite};
   1.224 +
   1.225 +
   1.226 +/** These event codes are used by the PSL to tell the PIL what has happened.
   1.227 +
   1.228 +	@publishedPartner
   1.229 +	@released
   1.230 +*/
   1.231 +enum TUsbcDeviceEvent
   1.232 +	{
   1.233 +	/** The USB Suspend bus state has been detected. */
   1.234 +	EUsbEventSuspend,
   1.235 +	/** USB Resume signalling has been detected. */
   1.236 +	EUsbEventResume,
   1.237 +	/** A USB Reset condition has been detected. */
   1.238 +	EUsbEventReset,
   1.239 +	/** Physical removal of the USB cable has been detected. */
   1.240 +	EUsbEventCableRemoved,
   1.241 +	/** Physical insertion of the USB cable has been detected. */
   1.242 +	EUsbEventCableInserted
   1.243 +	};
   1.244 +
   1.245 +
   1.246 +/** USB LDD client callback.
   1.247 +*/
   1.248 +class TUsbcClientCallback
   1.249 +    {
   1.250 +public:
   1.251 +	inline TUsbcClientCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
   1.252 +	inline DBase* Owner() const;
   1.253 +	inline TInt DoCallback();
   1.254 +	inline void Cancel();
   1.255 +	inline void SetDfcQ(TDfcQue* aDfcQ);
   1.256 +public:
   1.257 +	/** Used by the PIL to queue callback objects into a TSglQue. */
   1.258 +	TSglQueLink iLink;
   1.259 +private:
   1.260 +	DBase* iOwner;
   1.261 +	TDfc iDfc;
   1.262 +    };
   1.263 +
   1.264 +
   1.265 +/** The endpoint halt/clear_halt status.
   1.266 +*/
   1.267 +class TUsbcEndpointStatusCallback
   1.268 +	{
   1.269 +public:
   1.270 +	inline TUsbcEndpointStatusCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
   1.271 +	inline void SetState(TUint aState);
   1.272 +	inline TUint State() const;
   1.273 +	inline DBase* Owner() const;
   1.274 +	inline TInt DoCallback();
   1.275 +	inline void Cancel();
   1.276 +	inline void SetDfcQ(TDfcQue* aDfcQ);
   1.277 +public:
   1.278 +	/** Used by the PIL to queue callback objects into a TSglQue. */
   1.279 +	TSglQueLink iLink;
   1.280 +private:
   1.281 +	DBase* iOwner;
   1.282 +	TDfc iDfc;
   1.283 +	TUint iState;
   1.284 +	};
   1.285 +
   1.286 +
   1.287 +/** Maximum number of device status requests that can be queued at a time.
   1.288 +	The value chosen is thought to be sufficient in all situations.
   1.289 +*/
   1.290 +const TInt KUsbcDeviceStateRequests = 8;
   1.291 +
   1.292 +
   1.293 +/** The USB device status.
   1.294 +*/
   1.295 +class TUsbcStatusCallback
   1.296 +	{
   1.297 +public:
   1.298 +	inline TUsbcStatusCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
   1.299 +	inline void SetState(TUsbcDeviceState aState);
   1.300 +	inline TUsbcDeviceState State(TInt aIndex) const;
   1.301 +	inline void ResetState();
   1.302 +	inline DBase* Owner() const;
   1.303 +	inline TInt DoCallback();
   1.304 +	inline void Cancel();
   1.305 +	inline void SetDfcQ(TDfcQue* aDfcQ);
   1.306 +public:
   1.307 +	/** Used by the PIL to queue callback objects into a TSglQue. */
   1.308 +	TSglQueLink iLink;
   1.309 +private:
   1.310 +	DBase* iOwner;
   1.311 +	TDfc iDfc;
   1.312 +	TUsbcDeviceState iState[KUsbcDeviceStateRequests];
   1.313 +	};
   1.314 +
   1.315 +
   1.316 +/** A USB transfer request.
   1.317 +
   1.318 +	@publishedPartner
   1.319 +	@released
   1.320 +*/
   1.321 +class TUsbcRequestCallback
   1.322 +	{
   1.323 +public:
   1.324 +	/** @internalTechnology */
   1.325 +	inline TUsbcRequestCallback(const DBase* aOwner, TInt aEndpointNum, TDfcFn aDfcFunc,
   1.326 +						 TAny* aEndpoint, TDfcQue* aDfcQ, TInt aPriority);
   1.327 +	/** @internalTechnology	*/
   1.328 +	inline ~TUsbcRequestCallback();
   1.329 +	/** @internalTechnology	*/
   1.330 +	inline void SetRxBufferInfo(TUint8* aBufferStart, TPhysAddr aBufferAddr,
   1.331 +								TUsbcPacketArray* aPacketIndex, TUsbcPacketArray* aPacketSize,
   1.332 +								TInt aLength);
   1.333 +	/** @internalTechnology	*/
   1.334 +	inline void SetTxBufferInfo(TUint8* aBufferStart, TPhysAddr aBufferAddr, TInt aLength);
   1.335 +	/** @internalTechnology	*/
   1.336 +	inline void SetTransferDirection(TTransferDirection aTransferDir);
   1.337 +	/** @internalTechnology	*/
   1.338 +	inline const DBase* Owner() const;
   1.339 +	/** @internalTechnology	*/
   1.340 +	inline TInt DoCallback();
   1.341 +	/** @internalTechnology	*/
   1.342 +	inline void Cancel();
   1.343 +public:
   1.344 +	/** Used by the PIL to queue callback objects into a TSglQue.
   1.345 +		@internalTechnology
   1.346 +	*/
   1.347 +	TSglQueLink iLink;
   1.348 +public:
   1.349 +	/** The endpoint number. */
   1.350 +	const TInt iEndpointNum;
   1.351 +	/** The 'real' endpoint number, as used by the PDD. */
   1.352 +	TInt iRealEpNum;
   1.353 +	/** Indicates the LDD client for this transfer. */
   1.354 +	const DBase* const iOwner;
   1.355 +	/** DFC, used by PIL to call back the LDD when transfer completes to the LDD. */
   1.356 +	TDfc iDfc;
   1.357 +	/** Direction of transfer request. */
   1.358 +	TTransferDirection iTransferDir;
   1.359 +	/** Start address of this buffer. */
   1.360 +	TUint8* iBufferStart;
   1.361 +	/** Physical address of buffer start (used for DMA). */
   1.362 +	TPhysAddr iBufferAddr;
   1.363 +	/** Array of pointers into iBufferStart (actually TUsbcPacketArray (*)[]). */
   1.364 +	TUsbcPacketArray* iPacketIndex;
   1.365 +	/** Array of packet sizes (actually TUsbcPacketArray (*)[]). */
   1.366 +	TUsbcPacketArray* iPacketSize;
   1.367 +	/** Length in bytes of buffer (iBufferStart). */
   1.368 +	TInt iLength;
   1.369 +	/** For IN transfers, if a zlp might be required at the end of this transfer. */
   1.370 +	TBool iZlpReqd;
   1.371 +	/** Number of bytes transmitted; changed by the PSL. */
   1.372 +	TUint iTxBytes;
   1.373 +	/** Number of packets received (if it is a read); changed by the PSL. */
   1.374 +	TUint iRxPackets;
   1.375 +	/** The error code upon completion of the request; changed by the PSL. */
   1.376 +	TInt iError;
   1.377 +	};
   1.378 +
   1.379 +/** USB On-The-Go feature change callback.
   1.380 +*/
   1.381 +class TUsbcOtgFeatureCallback
   1.382 +    {
   1.383 +public:
   1.384 +	inline TUsbcOtgFeatureCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
   1.385 +	inline void SetFeatures(TUint8 aFeatures);
   1.386 +	inline TUint8 Features() const;
   1.387 +	inline DBase* Owner() const;
   1.388 +	inline TInt DoCallback();
   1.389 +	inline void Cancel();
   1.390 +	inline void SetDfcQ(TDfcQue* aDfcQ);
   1.391 +public:
   1.392 +	/** Used by the PIL to queue callback objects into a TSglQue. */
   1.393 +	TSglQueLink iLink;
   1.394 +private:
   1.395 +	DBase* iOwner;
   1.396 +	TDfc iDfc;
   1.397 +	TUint8 iValue;
   1.398 +    };
   1.399 +
   1.400 +//
   1.401 +//########################### Physical Device Driver (PIL + PSL) ######################
   1.402 +//
   1.403 +
   1.404 +class TUsbcLogicalEndpoint;
   1.405 +
   1.406 +/** This models a physical (real) endpoint of the UDC.
   1.407 +*/
   1.408 +class TUsbcPhysicalEndpoint
   1.409 +	{
   1.410 +public:
   1.411 +	TUsbcPhysicalEndpoint();
   1.412 +	~TUsbcPhysicalEndpoint();
   1.413 +	TBool EndpointSuitable(const TUsbcEndpointInfo* aEpInfo, TInt aIfcNumber) const; // Check Todo, SC will pass pointer to derived class
   1.414 +	TInt TypeAvailable(TUint aType) const;
   1.415 +	TInt DirAvailable(TUint aDir) const;
   1.416 +public:
   1.417 +	/** This endpoint's capabilities. */
   1.418 +	TUsbcEndpointCaps iCaps;
   1.419 +	/** USB address: 0x00, 0x80, 0x01, 0x81, etc. */
   1.420 +	TUint8 iEndpointAddr;
   1.421 +	/** Pointer to interface # this endpoint has been assigned to. */
   1.422 +	const TUint8* iIfcNumber;
   1.423 +	/** Pointer to corresponding logical endpoint or NULL. */
   1.424 +	const TUsbcLogicalEndpoint* iLEndpoint;
   1.425 +	/** Only used when searching for available endpoints. */
   1.426 +	TBool iSettingReserve;
   1.427 +	/** True if endpoint is halted (i.e. issues STALL handshakes), false otherwise. */
   1.428 +	TBool iHalt;
   1.429 +	};
   1.430 +
   1.431 +
   1.432 +class DUsbClientController;
   1.433 +class TUsbcInterface;
   1.434 +
   1.435 +/** This is a 'logical' endpoint, as used by our device configuration model.
   1.436 +*/
   1.437 +class TUsbcLogicalEndpoint
   1.438 +	{
   1.439 +public:
   1.440 +	TUsbcLogicalEndpoint(DUsbClientController* aController, TUint aEndpointNum,
   1.441 +						 const TUsbcEndpointInfo& aEpInfo, TUsbcInterface* aInterface,
   1.442 +						 TUsbcPhysicalEndpoint* aPEndpoint);		// Check Todo, SC will pass pointer to derived class
   1.443 +	~TUsbcLogicalEndpoint();
   1.444 +public:
   1.445 +	/** Pointer to controller object. */
   1.446 +	DUsbClientController* iController;
   1.447 +	/** The virtual (logical) endpoint number. */
   1.448 +	const TInt iLEndpointNum;
   1.449 +	/** This endpoint's info structure. */
   1.450 +	TUsbcEndpointInfo iInfo;										// Check Todo, SC will pass pointer to derived class
   1.451 +	/** Stores the endpoint size to be used for FS. */
   1.452 +	TInt iEpSize_Fs;
   1.453 +	/** Stores the endpoint size to be used for HS. */
   1.454 +	TInt iEpSize_Hs;
   1.455 +	/** 'Back' pointer. */
   1.456 +	const TUsbcInterface* iInterface;
   1.457 +	/** Pointer to corresponding physical endpoint, never NULL. */
   1.458 +	TUsbcPhysicalEndpoint* const iPEndpoint;
   1.459 +	};
   1.460 +
   1.461 +
   1.462 +class TUsbcInterfaceSet;
   1.463 +
   1.464 +/** This is an 'alternate setting' of an interface.
   1.465 +*/
   1.466 +class TUsbcInterface
   1.467 +	{
   1.468 +public:
   1.469 +	TUsbcInterface(TUsbcInterfaceSet* aIfcSet, TUint8 aSetting, TBool aNoEp0Requests);
   1.470 +	~TUsbcInterface();
   1.471 +public:
   1.472 +	/** Array of endpoints making up (belonging to) this setting. */
   1.473 +	RPointerArray<TUsbcLogicalEndpoint> iEndpoints;
   1.474 +	/** 'Back' pointer. */
   1.475 +	TUsbcInterfaceSet* const iInterfaceSet;
   1.476 +	/** bAlternateSetting (zero-based). */
   1.477 +	const TUint8 iSettingCode;
   1.478 +	/** KUsbcInterfaceInfo_NoEp0RequestsPlease: stall non-std Setup requests. */
   1.479 +	const TBool iNoEp0Requests;
   1.480 +	};
   1.481 +
   1.482 +
   1.483 +/** This is an 'interface' (owning 1 or more alternate settings).
   1.484 +
   1.485 +	@see TUsbcInterface
   1.486 +*/
   1.487 +class TUsbcInterfaceSet
   1.488 +	{
   1.489 +public:
   1.490 +	TUsbcInterfaceSet(const DBase* aClientId, TUint8 aIfcNum);
   1.491 +	~TUsbcInterfaceSet();
   1.492 +	inline const TUsbcInterface* CurrentInterface() const;
   1.493 +	inline TUsbcInterface* CurrentInterface();
   1.494 +public:
   1.495 +	/** Array of alternate settings provided by (belonging to) this interface. */
   1.496 +	RPointerArray<TUsbcInterface> iInterfaces;
   1.497 +	/** Pointer to the LDD which created and owns this interface. */
   1.498 +	const DBase* const iClientId;
   1.499 +	/** bInterfaceNumber (zero-based). */
   1.500 +	TUint8 iInterfaceNumber;
   1.501 +	/** bAlternateSetting (zero-based). */
   1.502 +	TUint8 iCurrentInterface;
   1.503 +	};
   1.504 +
   1.505 +
   1.506 +/** This is a 'configuration' of the USB device.
   1.507 +	Currently we support only one configuration.
   1.508 +*/
   1.509 +class TUsbcConfiguration
   1.510 +	{
   1.511 +public:
   1.512 +	TUsbcConfiguration(TUint8 aConfigVal);
   1.513 +	~TUsbcConfiguration();
   1.514 +public:
   1.515 +	/** Array of interfaces making up (belonging to) this configuration. */
   1.516 +	RPointerArray<TUsbcInterfaceSet> iInterfaceSets;
   1.517 +	/** bConfigurationValue (one-based). */
   1.518 +	const TUint8 iConfigValue;
   1.519 +	};
   1.520 +
   1.521 +
   1.522 +/** A USB Setup packet.
   1.523 +
   1.524 +	Used mainly internally by the PIL but also by
   1.525 +	DUsbClientController::ProcessSetConfiguration(const TUsbcSetup&),
   1.526 +	which is classified as publishedPartner.
   1.527 +
   1.528 +	@publishedPartner @released
   1.529 +*/
   1.530 +struct TUsbcSetup
   1.531 +	{
   1.532 +	/** bmRequestType */
   1.533 +	TUint8 iRequestType;
   1.534 +	/** bRequest */
   1.535 +	TUint8 iRequest;
   1.536 +	/** wValue */
   1.537 +	TUint16 iValue;
   1.538 +	/** wIndex */
   1.539 +	TUint16 iIndex;
   1.540 +	/** wLength */
   1.541 +	TUint16 iLength;
   1.542 +	};
   1.543 +
   1.544 +
   1.545 +/** The USB controller's power handler class.
   1.546 +*/
   1.547 +class DUsbcPowerHandler : public DPowerHandler
   1.548 +	{
   1.549 +public:
   1.550 +	void PowerUp();
   1.551 +	void PowerDown(TPowerState);
   1.552 +public:
   1.553 +	DUsbcPowerHandler(DUsbClientController* aController);
   1.554 +private:
   1.555 +	DUsbClientController* iController;
   1.556 +	};
   1.557 +
   1.558 +
   1.559 +/*
   1.560 +This is the EndpointInfo class used by the usb shared chunk client driver. 
   1.561 +*/
   1.562 +
   1.563 +class TUsbcScEndpointInfo;
   1.564 +
   1.565 +
   1.566 +/**
   1.567 +Used to represent an array of (or inheriting from) TUsbcEndpointInfo objects.
   1.568 +
   1.569 +@see DUsbClientController::SetInterface
   1.570 +*/
   1.571 +
   1.572 +class TUsbcEndpointInfoArray
   1.573 +	{
   1.574 +public:
   1.575 +	typedef enum {EUsbcEndpointInfo, EUsbcScEndpointInfo} TArrayType;
   1.576 +
   1.577 +	TUsbcEndpointInfoArray(const TUsbcEndpointInfo* aData, TInt aDataSize=0);
   1.578 +	TUsbcEndpointInfoArray(const TUsbcScEndpointInfo* aData, TInt aDataSize=0);
   1.579 +	inline TUsbcEndpointInfo& operator[](TInt aIndex) const; 
   1.580 +
   1.581 +	TArrayType iType;
   1.582 +private:
   1.583 +	TUint8* iData;
   1.584 +	TInt iDataSize;
   1.585 +	};
   1.586 +
   1.587 +class TUsbcRequestCallback; // todo?? required only for class below
   1.588 +
   1.589 +/** The USB Device software controller class.
   1.590 +
   1.591 +	Implements the platform-independent layer (PIL), and defines the interface to the
   1.592 +	platform-specific layer PSL).
   1.593 +
   1.594 +	The implementation of the platform-specific layer interfaces with the hardware.
   1.595 +*/
   1.596 +class DUsbClientController : public DBase
   1.597 +	{
   1.598 +friend class DUsbcPowerHandler;
   1.599 +friend TUsbcLogicalEndpoint::~TUsbcLogicalEndpoint();
   1.600 +	//
   1.601 +	// --- Platform Independent Layer (PIL) ---
   1.602 +	//
   1.603 +
   1.604 +public:
   1.605 +
   1.606 +	//
   1.607 +	// --- The following functions constitute the PIL interface to the LDD ---
   1.608 +	//
   1.609 +
   1.610 +	virtual ~DUsbClientController();
   1.611 +	IMPORT_C void DisableClientStack();
   1.612 +	IMPORT_C void EnableClientStack();
   1.613 +	IMPORT_C TBool IsActive();
   1.614 +	IMPORT_C TInt RegisterClientCallback(TUsbcClientCallback& aCallback);
   1.615 +	IMPORT_C static DUsbClientController* UsbcControllerPointer(TInt aUdc=0);
   1.616 +	IMPORT_C void EndpointCaps(const DBase* aClientId, TDes8 &aCapsBuf) const;
   1.617 +	IMPORT_C void DeviceCaps(const DBase* aClientId, TDes8 &aCapsBuf) const;
   1.618 +	IMPORT_C TInt SetInterface(const DBase* aClientId, DThread* aThread, TInt aInterfaceNum,
   1.619 +							   TUsbcClassInfo& aClass, TDesC8* aString, TInt aTotalEndpointsUsed,
   1.620 +							   const TUsbcEndpointInfo aEndpointData[], TInt (*aRealEpNumbers)[6],
   1.621 +							   TUint32 aFeatureWord);
   1.622 +	IMPORT_C TInt SetInterface(const DBase* aClientId, DThread* aThread,
   1.623 +												 TInt aInterfaceNum, TUsbcClassInfo& aClass,
   1.624 +												 TDesC8* aString, TInt aTotalEndpointsUsed,
   1.625 +												 const TUsbcEndpointInfoArray aEndpointData,
   1.626 +												 TInt aRealEpNumbers[], TUint32 aFeatureWord);
   1.627 +	IMPORT_C TInt ReleaseInterface(const DBase* aClientId, TInt aInterfaceNum);
   1.628 +	IMPORT_C TInt ReEnumerate();
   1.629 +	IMPORT_C TInt PowerUpUdc();
   1.630 +	IMPORT_C TInt UsbConnect();
   1.631 +	IMPORT_C TInt UsbDisconnect();
   1.632 +	IMPORT_C TInt RegisterForStatusChange(TUsbcStatusCallback& aCallback);
   1.633 +	IMPORT_C TInt DeRegisterForStatusChange(const DBase* aClientId);
   1.634 +	IMPORT_C TInt RegisterForEndpointStatusChange(TUsbcEndpointStatusCallback& aCallback);
   1.635 +	IMPORT_C TInt DeRegisterForEndpointStatusChange(const DBase* aClientId);
   1.636 +	IMPORT_C TInt GetInterfaceNumber(const DBase* aClientId, TInt& aInterfaceNum) const;
   1.637 +	IMPORT_C TInt DeRegisterClient(const DBase* aClientId);
   1.638 +	IMPORT_C TInt Ep0PacketSize() const;
   1.639 +	IMPORT_C TInt Ep0Stall(const DBase* aClientId);
   1.640 +	IMPORT_C void SendEp0StatusPacket(const DBase* aClientId);
   1.641 +	IMPORT_C TUsbcDeviceState GetDeviceStatus() const;
   1.642 +	IMPORT_C TEndpointState GetEndpointStatus(const DBase* aClientId, TInt aEndpointNum) const;
   1.643 +	IMPORT_C TInt SetupReadBuffer(TUsbcRequestCallback& aCallback);
   1.644 +	IMPORT_C TInt SetupWriteBuffer(TUsbcRequestCallback& aCallback);
   1.645 +	IMPORT_C void CancelReadBuffer(const DBase* aClientId, TInt aRealEndpoint);
   1.646 +	IMPORT_C void CancelWriteBuffer(const DBase* aClientId, TInt aRealEndpoint);
   1.647 +	IMPORT_C TInt HaltEndpoint(const DBase* aClientId, TInt aEndpointNum);
   1.648 +	IMPORT_C TInt ClearHaltEndpoint(const DBase* aClientId, TInt aEndpointNum);
   1.649 +	IMPORT_C TInt SetDeviceControl(const DBase* aClientId);
   1.650 +	IMPORT_C TInt ReleaseDeviceControl(const DBase* aClientId);
   1.651 +	IMPORT_C TUint EndpointZeroMaxPacketSizes() const;
   1.652 +	IMPORT_C TInt SetEndpointZeroMaxPacketSize(TInt aMaxPacketSize);
   1.653 +	IMPORT_C TInt GetDeviceDescriptor(DThread* aThread, TDes8& aDeviceDescriptor);
   1.654 +	IMPORT_C TInt SetDeviceDescriptor(DThread* aThread, const TDes8& aDeviceDescriptor);
   1.655 +	IMPORT_C TInt GetDeviceDescriptorSize(DThread* aThread, TDes8& aSize);
   1.656 +	IMPORT_C TInt GetConfigurationDescriptor(DThread* aThread, TDes8& aConfigurationDescriptor);
   1.657 +	IMPORT_C TInt SetConfigurationDescriptor(DThread* aThread, const TDes8& aConfigurationDescriptor);
   1.658 +	IMPORT_C TInt GetConfigurationDescriptorSize(DThread* aThread, TDes8& aSize);
   1.659 +	IMPORT_C TInt SetOtgDescriptor(DThread* aThread, const TDesC8& aOtgDesc);
   1.660 +	IMPORT_C TInt GetOtgDescriptor(DThread* aThread, TDes8& aOtgDesc) const;
   1.661 +	IMPORT_C TInt GetOtgFeatures(DThread* aThread, TDes8& aFeatures) const;
   1.662 +	IMPORT_C TInt GetCurrentOtgFeatures(TUint8& aFeatures) const;
   1.663 +	IMPORT_C TInt RegisterForOtgFeatureChange(TUsbcOtgFeatureCallback& aCallback);
   1.664 +	IMPORT_C TInt DeRegisterForOtgFeatureChange(const DBase* aClientId);
   1.665 +	IMPORT_C TInt GetInterfaceDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
   1.666 +										 TDes8& aInterfaceDescriptor);
   1.667 +	IMPORT_C TInt SetInterfaceDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
   1.668 +										 const TDes8& aInterfaceDescriptor);
   1.669 +	IMPORT_C TInt GetInterfaceDescriptorSize(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
   1.670 +											 TDes8& aSize);
   1.671 +	IMPORT_C TInt GetEndpointDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
   1.672 +										TInt aEndpointNum, TDes8& aEndpointDescriptor);
   1.673 +	IMPORT_C TInt SetEndpointDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
   1.674 +										TInt aEndpointNum, const TDes8& aEndpointDescriptor);
   1.675 +	IMPORT_C TInt GetEndpointDescriptorSize(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
   1.676 +											TInt aEndpointNum, TDes8& aSize);
   1.677 +	IMPORT_C TInt GetDeviceQualifierDescriptor(DThread* aThread, TDes8& aDeviceQualifierDescriptor);
   1.678 +	IMPORT_C TInt SetDeviceQualifierDescriptor(DThread* aThread, const TDes8& aDeviceQualifierDescriptor);
   1.679 +	IMPORT_C TInt GetOtherSpeedConfigurationDescriptor(DThread* aThread, TDes8& aConfigurationDescriptor);
   1.680 +	IMPORT_C TInt SetOtherSpeedConfigurationDescriptor(DThread* aThread, const TDes8& aConfigurationDescriptor);
   1.681 +	IMPORT_C TInt GetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
   1.682 +												TDes8& aInterfaceDescriptor);
   1.683 +	IMPORT_C TInt SetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
   1.684 +												const TDes8& aInterfaceDescriptor, TInt aSize);
   1.685 +	IMPORT_C TInt GetCSInterfaceDescriptorBlockSize(DThread* aThread, const DBase* aClientId,
   1.686 +													TInt aSettingNum, TDes8& aSize);
   1.687 +	IMPORT_C TInt GetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
   1.688 +											   TInt aEndpointNum, TDes8& aEndpointDescriptor);
   1.689 +	IMPORT_C TInt SetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
   1.690 +											   TInt aEndpointNum, const TDes8& aEndpointDescriptor,
   1.691 +											   TInt aSize);
   1.692 +	IMPORT_C TInt GetCSEndpointDescriptorBlockSize(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
   1.693 +												   TInt aEndpointNum, TDes8& aSize);
   1.694 +	IMPORT_C TInt GetStringDescriptorLangId(DThread* aThread, TDes8& aLangId);
   1.695 +	IMPORT_C TInt SetStringDescriptorLangId(TUint16 aLangId);
   1.696 +	IMPORT_C TInt GetManufacturerStringDescriptor(DThread* aThread, TDes8& aString);
   1.697 +	IMPORT_C TInt SetManufacturerStringDescriptor(DThread* aThread, const TDes8& aString);
   1.698 +	IMPORT_C TInt RemoveManufacturerStringDescriptor();
   1.699 +	IMPORT_C TInt GetProductStringDescriptor(DThread* aThread, TDes8& aString);
   1.700 +	IMPORT_C TInt SetProductStringDescriptor(DThread* aThread, const TDes8& aString);
   1.701 +	IMPORT_C TInt RemoveProductStringDescriptor();
   1.702 +	IMPORT_C TInt GetSerialNumberStringDescriptor(DThread* aThread, TDes8& aString);
   1.703 +	IMPORT_C TInt SetSerialNumberStringDescriptor(DThread* aThread, const TDes8& aString);
   1.704 +	IMPORT_C TInt RemoveSerialNumberStringDescriptor();
   1.705 +	IMPORT_C TInt GetConfigurationStringDescriptor(DThread* aThread, TDes8& aString);
   1.706 +	IMPORT_C TInt SetConfigurationStringDescriptor(DThread* aThread, const TDes8& aString);
   1.707 +	IMPORT_C TInt RemoveConfigurationStringDescriptor();
   1.708 +	IMPORT_C TInt GetStringDescriptor(DThread* aThread, TUint8 aIndex, TDes8& aString);
   1.709 +	IMPORT_C TInt SetStringDescriptor(DThread* aThread, TUint8 aIndex, const TDes8& aString);
   1.710 +	IMPORT_C TInt RemoveStringDescriptor(TUint8 aIndex);
   1.711 +	IMPORT_C TInt AllocateEndpointResource(const DBase* aClientId, TInt aEndpointNum,
   1.712 +										   TUsbcEndpointResource aResource);
   1.713 +	IMPORT_C TInt DeAllocateEndpointResource(const DBase* aClientId, TInt aEndpointNum,
   1.714 +											 TUsbcEndpointResource aResource);
   1.715 +	IMPORT_C TBool QueryEndpointResource(const DBase* aClientId, TInt aEndpointNum,
   1.716 +										 TUsbcEndpointResource aResource);
   1.717 +	IMPORT_C TInt EndpointPacketSize(const DBase* aClientId, TInt aEndpointNum);
   1.718 +
   1.719 +	//
   1.720 +	// --- Public (pure) virtual (implemented by PSL, used by LDD) ---
   1.721 +	//
   1.722 +
   1.723 +	/** Forces the UDC into a non-idle state to perform a USB remote wakeup operation.
   1.724 +
   1.725 +		The PSL should first check the current value of iRmWakeupStatus_Enabled
   1.726 +		to determine whether or not to actually send a Remote Wakeup.
   1.727 +
   1.728 +		@see iRmWakeupStatus_Enabled
   1.729 +
   1.730 +		@return KErrGeneral if Remote Wakeup feature is not enabled or an error is encountered,
   1.731 +		KErrNone otherwise.
   1.732 +
   1.733 +		@publishedPartner @released
   1.734 +	*/
   1.735 +	IMPORT_C virtual TInt SignalRemoteWakeup() =0;
   1.736 +
   1.737 +	/** Dumps the contents of (all or part of) the UDC registers to the serial console.
   1.738 +		This is for debugging purposes only.
   1.739 +
   1.740 +		@publishedPartner @released
   1.741 +	*/
   1.742 +	IMPORT_C virtual void DumpRegisters() =0;
   1.743 +
   1.744 +	/** Returns a pointer to the DFC queue that should be used by the USB LDD.
   1.745 +
   1.746 +		@return A pointer to the DFC queue that should be used by the USB LDD.
   1.747 +
   1.748 +		@publishedPartner @released
   1.749 +	*/
   1.750 +	IMPORT_C virtual TDfcQue* DfcQ(TInt aUnit) =0;
   1.751 +
   1.752 +	/** Returns information about the current operating speed of the UDC.
   1.753 +
   1.754 +		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs.
   1.755 +		 The default implementation in the PIL returns EFalse.)
   1.756 +
   1.757 +		@return ETrue if the UDC is currently operating at High speed, EFalse
   1.758 +		otherwise (i.e. controller is operating at Full speed).
   1.759 +
   1.760 +		@publishedPartner @released
   1.761 +	*/
   1.762 +	IMPORT_C virtual TBool CurrentlyUsingHighSpeed();
   1.763 +
   1.764 +	//
   1.765 +	// --- Public PIL functions ---
   1.766 +	//
   1.767 +
   1.768 +	DUsbClientController* RegisterUdc(TInt aUdc);
   1.769 +
   1.770 +protected:
   1.771 +
   1.772 +	//
   1.773 +	// --- Functions and data members provided by PIL, called by PSL ---
   1.774 +	//
   1.775 +
   1.776 +	TBool InitialiseBaseClass(TUsbcDeviceDescriptor* aDeviceDesc,
   1.777 +							  TUsbcConfigDescriptor* aConfigDesc,
   1.778 +							  TUsbcLangIdDescriptor* aLangId,
   1.779 +							  TUsbcStringDescriptor* aManufacturer =0,
   1.780 +							  TUsbcStringDescriptor* aProduct =0,
   1.781 +							  TUsbcStringDescriptor* aSerialNum =0,
   1.782 +							  TUsbcStringDescriptor* aConfig =0,
   1.783 +							  TUsbcOtgDescriptor* aOtgDesc =0);
   1.784 +	DUsbClientController();
   1.785 +	TInt DeviceEventNotification(TUsbcDeviceEvent aEvent);
   1.786 +	void EndpointRequestComplete(TUsbcRequestCallback* aCallback);
   1.787 +	TInt Ep0RequestComplete(TInt aRealEndpoint, TInt aCount, TInt aError);
   1.788 +	void MoveToAddressState();
   1.789 +	void SetCurrent(TInt aCurrent);
   1.790 +	TUsbcEp0State EnquireEp0NextState(const TUint8* aSetupBuf) const;
   1.791 +	TInt ProcessSetConfiguration(const TUsbcSetup& aPacket);
   1.792 +	void HandleHnpRequest(TInt aHnpState);
   1.793 +
   1.794 +	/** This info can be used by the PSL before sending ZLPs.
   1.795 +
   1.796 +		@publishedPartner @released
   1.797 +	*/
   1.798 +	TBool iEp0ReceivedNonStdRequest;
   1.799 +
   1.800 +	/** True if RMW is currently enabled (set by either PIL or PSL).
   1.801 +
   1.802 +		@publishedPartner @released
   1.803 +	*/
   1.804 +	TBool iRmWakeupStatus_Enabled;
   1.805 +
   1.806 +	/** Ep0 incoming (rx) data is placed here (one packet).
   1.807 +
   1.808 +		@publishedPartner @released
   1.809 +	*/
   1.810 +	TUint8 iEp0_RxBuf[KUsbcBufSzControl];
   1.811 +
   1.812 +private:
   1.813 +
   1.814 +	//
   1.815 +	// --- Platform Specific Layer (PSL) ---
   1.816 +	//
   1.817 +
   1.818 +	/** This function will be called by the PIL upon decoding a SET_ADDRESS request.
   1.819 +
   1.820 +		UDCs which require a manual setting of the USB device address should do that in this function.
   1.821 +
   1.822 +		@param aAddress A valid USB device address that was received with the SET_ADDRESS request.
   1.823 +
   1.824 +		@return KErrNone if address was set successfully or if this UDC's address cannot be set manually,
   1.825 +		KErrGeneral otherwise.
   1.826 +
   1.827 +		@publishedPartner @released
   1.828 +	*/
   1.829 +	virtual TInt SetDeviceAddress(TInt aAddress) =0;
   1.830 +
   1.831 +	/** Configures (enables) an endpoint (incl. Ep0) for data transmission or reception.
   1.832 +
   1.833 +		@param aRealEndpoint The number of the endpoint to be enabled.
   1.834 +		@param aEndpointInfo A reference to a properly filled-in endpoint info structure.
   1.835 +
   1.836 +		@return KErrArgument if endpoint number or endpoint info invalid, KErrNone if endpoint
   1.837 +		successfully configured, KErrGeneral otherwise.
   1.838 +
   1.839 +		@publishedPartner @released
   1.840 +	*/
   1.841 +	virtual TInt ConfigureEndpoint(TInt aRealEndpoint, const TUsbcEndpointInfo& aEndpointInfo) =0;
   1.842 +
   1.843 +	/** De-configures (disables) an endpoint (incl. Ep0).
   1.844 +
   1.845 +		@param aRealEndpoint The number of the endpoint to be disabled.
   1.846 +
   1.847 +		@return KErrArgument if endpoint number invalid, KErrNone if endpoint successfully de-configured,
   1.848 +		KErrGeneral otherwise.
   1.849 +
   1.850 +		@publishedPartner @released
   1.851 +	*/
   1.852 +	virtual TInt DeConfigureEndpoint(TInt aRealEndpoint) =0;
   1.853 +
   1.854 +	/** Allocates an endpoint resource.
   1.855 +
   1.856 +		If the resource gets successfully allocated, it will be used from when the current bus transfer
   1.857 +		has been completed.
   1.858 +
   1.859 +		@param aRealEndpoint The number of the endpoint.
   1.860 +		@param aResource The endpoint resource to be allocated.
   1.861 +
   1.862 +		@return KErrNone if the resource has been successfully allocated, KErrNotSupported if the endpoint
   1.863 +		does not support the resource requested, and KErrInUse if the resource is already consumed and
   1.864 +		cannot be allocated.
   1.865 +
   1.866 +		@publishedPartner @deprecated
   1.867 +	*/
   1.868 +	virtual TInt AllocateEndpointResource(TInt aRealEndpoint, TUsbcEndpointResource aResource) =0;
   1.869 +
   1.870 +	/** Deallocates (frees) an endpoint resource.
   1.871 +
   1.872 +		The resource will be removed from when the current bus transfer has been completed.
   1.873 +
   1.874 +		@param aRealEndpoint The number of the endpoint.
   1.875 +		@param aResource The endpoint resource to be deallocated.
   1.876 +
   1.877 +		@return KErrNone if the resource has been successfully deallocated, KErrNotSupported if the endpoint
   1.878 +		does not support the resource requested.
   1.879 +
   1.880 +		@publishedPartner @deprecated
   1.881 +	*/
   1.882 +	virtual TInt DeAllocateEndpointResource(TInt aRealEndpoint, TUsbcEndpointResource aResource) =0;
   1.883 +
   1.884 +	/** Queries the use of and endpoint resource.
   1.885 +
   1.886 +		@param aRealEndpoint The number of the endpoint.
   1.887 +		@param aResource The endpoint resource to be queried.
   1.888 +
   1.889 +		@return ETrue if the specified resource is in use at the endpoint, EFalse if not.
   1.890 +
   1.891 +		@publishedPartner @released
   1.892 +	*/
   1.893 +	virtual TBool QueryEndpointResource(TInt aRealEndpoint, TUsbcEndpointResource aResource) const =0;
   1.894 +
   1.895 +	/** Opens a DMA channel (if possible).
   1.896 +
   1.897 +		@param aRealEndpoint The number of the endpoint for which to open the DMA channel.
   1.898 +
   1.899 +		@return KErrArgument if endpoint number invalid, KErrNone if channel successfully opened or if
   1.900 +		endpoint not DMA-capable, KErrGeneral otherwise.
   1.901 +
   1.902 +		@publishedPartner @released
   1.903 +	*/
   1.904 +	virtual TInt OpenDmaChannel(TInt aRealEndpoint);
   1.905 +
   1.906 +	/** Closes a DMA channel (if possible).
   1.907 +
   1.908 +		@param aRealEndpoint The number of the endpoint for which to close the DMA channel.
   1.909 +
   1.910 +		@publishedPartner @released
   1.911 +	*/
   1.912 +	virtual void CloseDmaChannel(TInt aRealEndpoint);
   1.913 +
   1.914 +	/** Sets up a read request on an endpoint (excl. Ep0) for data reception.
   1.915 +
   1.916 +		For endpoint 0 read requests, SetupEndpointZeroRead() is used instead.
   1.917 +
   1.918 +		@param aRealEndpoint The number of the endpoint to be used.
   1.919 +		@param aCallback A reference to a properly filled-in request callback structure.
   1.920 +
   1.921 +		@return KErrArgument if endpoint number invalid, KErrNone if read successfully set up,
   1.922 +		KErrGeneral otherwise.
   1.923 +
   1.924 +		@publishedPartner @released
   1.925 +	*/
   1.926 +	virtual TInt SetupEndpointRead(TInt aRealEndpoint, TUsbcRequestCallback& aCallback) =0;
   1.927 +
   1.928 +	/** Sets up a write request on an endpoint (excl. Ep0) for data transmission.
   1.929 +
   1.930 +		For endpoint 0 write requests, SetupEndpointZeroWrite() is used instead.
   1.931 +
   1.932 +		@param aRealEndpoint The number of the endpoint to be used.
   1.933 +		@param aCallback A reference to a properly filled-in request callback structure.
   1.934 +
   1.935 +		@return KErrArgument if endpoint number invalid, KErrNone if write successfully set up,
   1.936 +		KErrGeneral otherwise.
   1.937 +
   1.938 +		@publishedPartner @released
   1.939 +	*/
   1.940 +	virtual TInt SetupEndpointWrite(TInt aRealEndpoint, TUsbcRequestCallback& aCallback) =0;
   1.941 +
   1.942 +	/** Cancels a read request on an endpoint (excl. Ep0).
   1.943 +
   1.944 +		Note that endpoint 0 read requests are never cancelled by the PIL, so
   1.945 +		there is also no CancelEndpointZeroRead() function.
   1.946 +
   1.947 +		@param aRealEndpoint The number of the endpoint to be used.
   1.948 +
   1.949 +		@return KErrArgument if endpoint number invalid, KErrNone if read successfully cancelled,
   1.950 +		KErrGeneral otherwise.
   1.951 +
   1.952 +		@publishedPartner @released
   1.953 +	*/
   1.954 +	virtual TInt CancelEndpointRead(TInt aRealEndpoint) =0;
   1.955 +
   1.956 +	/** Cancels a write request on an endpoint (incl. Ep0).
   1.957 +
   1.958 +		The PIL calls this function also to cancel endpoint zero write requests.
   1.959 +
   1.960 +		@param aRealEndpoint The number of the endpoint to be used.
   1.961 +
   1.962 +		@return KErrArgument if endpoint number invalid, KErrNone if write successfully cancelled,
   1.963 +		KErrGeneral otherwise.
   1.964 +
   1.965 +		@publishedPartner @released
   1.966 +	*/
   1.967 +	virtual TInt CancelEndpointWrite(TInt aRealEndpoint) =0;
   1.968 +
   1.969 +	/** Same as SetupEndpointRead(), but for endpoint zero only.
   1.970 +
   1.971 +		No callback is used here as this function is only used internally by the PIL and no user side request
   1.972 +		exists for it. The data buffer to be used (filled) is iEp0_RxBuf.
   1.973 +
   1.974 +		@return KErrGeneral if (&iEndpoints[KEp0_Out]->iRxBuf != NULL) or some other error occurs,
   1.975 +		KErrNone if read successfully set up.
   1.976 +
   1.977 +		@publishedPartner @released
   1.978 +	*/
   1.979 +	virtual TInt SetupEndpointZeroRead() =0;
   1.980 +
   1.981 +	/** Same as SetupEndpointWrite(), but for endpoint zero only.
   1.982 +
   1.983 +		No callback is used here as this function is only used internally by the PIL and no user side request
   1.984 +		exists for it.
   1.985 +
   1.986 +		@param aBuffer This points to the beginning of the data to be sent.
   1.987 +		@param aLength The number of bytes to be sent.
   1.988 +		@param aZlpReqd ETrue if a zero-length packet (ZLP) is to be sent after the data.
   1.989 +
   1.990 +		@return KErrGeneral if (&iEndpoints[KEp0_In]->iTxBuf != NULL) or some other error occurs,
   1.991 +		KErrNone if write successfully set up.
   1.992 +
   1.993 +		@publishedPartner @released
   1.994 +	*/
   1.995 +	virtual TInt SetupEndpointZeroWrite(const TUint8* aBuffer, TInt aLength, TBool aZlpReqd=EFalse) =0;
   1.996 +
   1.997 +	/** Sets up on Ep0 the transmission of a single zero-length packet (ZLP).
   1.998 +
   1.999 +		@return KErrNone if ZLP successfully set up, KErrGeneral otherwise..
  1.1000 +
  1.1001 +		@publishedPartner @released
  1.1002 +	*/
  1.1003 +	virtual TInt SendEp0ZeroByteStatusPacket() =0;
  1.1004 +
  1.1005 +	/** Stalls an endpoint (incl. Ep0).
  1.1006 +
  1.1007 +		Isochronous endpoints cannot be stalled.
  1.1008 +
  1.1009 +		@param aRealEndpoint The number of the endpoint to be stalled.
  1.1010 +
  1.1011 +		@return KErrArgument if endpoint number invalid, KErrNone if endpoint successfully stalled,
  1.1012 +		KErrGeneral otherwise.
  1.1013 +
  1.1014 +		@publishedPartner @released
  1.1015 +	*/
  1.1016 +	virtual TInt StallEndpoint(TInt aRealEndpoint) =0;
  1.1017 +
  1.1018 +	/** Clears the stall condition on an endpoint (incl. Ep0).
  1.1019 +
  1.1020 +		Isochronous endpoints cannot be stalled.
  1.1021 +
  1.1022 +		@param aRealEndpoint The number of the endpoint to be stalled.
  1.1023 +
  1.1024 +		@return KErrArgument if endpoint number invalid, KErrNone if endpoint successfully de-stalled,
  1.1025 +		KErrGeneral otherwise.
  1.1026 +
  1.1027 +		@publishedPartner @released
  1.1028 +	*/
  1.1029 +	virtual TInt ClearStallEndpoint(TInt aRealEndpoint) =0;
  1.1030 +
  1.1031 +	/** Returns the stall status of an endpoint (incl. Ep0).
  1.1032 +
  1.1033 +		Isochronous endpoints cannot be stalled.
  1.1034 +
  1.1035 +		@param aRealEndpoint The number of the endpoint to be used.
  1.1036 +
  1.1037 +		@return KErrArgument if endpoint number invalid, 1 if endpoint is currently stalled, 0 if not.
  1.1038 +
  1.1039 +		@publishedPartner @released
  1.1040 +	*/
  1.1041 +	virtual TInt EndpointStallStatus(TInt aRealEndpoint) const =0;
  1.1042 +
  1.1043 +	/** Returns the error status of an endpoint (incl. Ep0).
  1.1044 +
  1.1045 +		@param aRealEndpoint The number of the endpoint to be used.
  1.1046 +
  1.1047 +		@return KErrArgument if endpoint number invalid, KErrNone if no error at this endpoint,
  1.1048 +		KErrGeneral if there is an error.
  1.1049 +
  1.1050 +		@publishedPartner @released
  1.1051 +	*/
  1.1052 +	virtual TInt EndpointErrorStatus(TInt aRealEndpoint) const =0;
  1.1053 +
  1.1054 +	/** Resets the data toggle bit for an endpoint (incl. Ep0).
  1.1055 +
  1.1056 +		Isochronous endpoints don't use data toggles.
  1.1057 +
  1.1058 +		@param aRealEndpoint The number of the endpoint to be used.
  1.1059 +
  1.1060 +		@return KErrArgument if endpoint number invalid, KErrNone if data toggle successfully reset,
  1.1061 +		KErrGeneral otherwise.
  1.1062 +
  1.1063 +		@publishedPartner @released
  1.1064 +	*/
  1.1065 +	virtual TInt ResetDataToggle(TInt aRealEndpoint) =0;
  1.1066 +
  1.1067 +	/** Returns the (11-bit) frame number contained in the last received SOF packet.
  1.1068 +
  1.1069 +		This information is used for isochronous transfers.
  1.1070 +
  1.1071 +		@return The (11-bit) frame number contained in the last received SOF packet.
  1.1072 +
  1.1073 +		@publishedPartner @released
  1.1074 +	*/
  1.1075 +	virtual TInt SynchFrameNumber() const =0;
  1.1076 +
  1.1077 +	/** Stores the (11-bit) frame number that should be sent in response to the next SYNCH_FRAME request(s).
  1.1078 +
  1.1079 +		@publishedPartner @released
  1.1080 +	 */
  1.1081 +	virtual void SetSynchFrameNumber(TInt aFrameNumber) =0;
  1.1082 +
  1.1083 +	/** Starts the UDC.
  1.1084 +
  1.1085 +		This initializes the device controller hardware before any other operation can be
  1.1086 +		performed. Tasks to be carried out here might include
  1.1087 +		- resetting the whole UDC design
  1.1088 +		- enabling the UDC's clock
  1.1089 +		- binding & enabling the UDC (primary) interrupt
  1.1090 +		- write meaningful values to some general UDC registers
  1.1091 +		- enabling the USB Reset interrupt
  1.1092 +		- enabling the UDC proper (for instance by setting an Enable bit)
  1.1093 +
  1.1094 +		@return KErrNone if UDC successfully started, KErrGeneral if there was an error.
  1.1095 +
  1.1096 +		@publishedPartner @released
  1.1097 +	*/
  1.1098 +	virtual TInt StartUdc() =0;
  1.1099 +
  1.1100 +	/** Stops the UDC.
  1.1101 +
  1.1102 +		This basically makes undone what happened in StartUdc(). Tasks to be carried out
  1.1103 +		here might include:
  1.1104 +		- disabling the UDC proper (for instance by clearing an Enable bit)
  1.1105 +		- disabling the USB Reset interrupt
  1.1106 +		- disabling & unbinding the UDC (primary) interrupt
  1.1107 +		- disabling the UDC's clock
  1.1108 +
  1.1109 +		@return KErrNone if UDC successfully stopped, KErrGeneral if there was an error.
  1.1110 +
  1.1111 +		@publishedPartner @released
  1.1112 +	*/
  1.1113 +	virtual TInt StopUdc() =0;
  1.1114 +
  1.1115 +	/** Connects the UDC  - and thus the USB device - physically to the bus.
  1.1116 +
  1.1117 +		This might involve a call into the Variant DLL, as the mechanism to achieve the connection can be
  1.1118 +		specific to the platform (rather than UDC specific). Since this functionality is not part of the USB
  1.1119 +		specification it has to be explicitly supported, either by the UDC itself or by the hardware
  1.1120 +		platform. If it is supported, then the member function SoftConnectCaps should be implemented to return
  1.1121 +		ETrue.
  1.1122 +
  1.1123 +		@see SoftConnectCaps()
  1.1124 +
  1.1125 +		@return KErrNone if UDC successfully connected, KErrGeneral if there was an error.
  1.1126 +
  1.1127 +		@publishedPartner @released
  1.1128 +	*/
  1.1129 +	virtual TInt UdcConnect() =0;
  1.1130 +
  1.1131 +	/** Disconnects the UDC	 - and thus the USB device - physically from the bus.
  1.1132 +
  1.1133 +		This might involve a call into the Variant DLL, as the mechanism to achieve the disconnection can be
  1.1134 +		specific to the platform (rather than UDC specific). Since this functionality is not part of the USB
  1.1135 +		specification it has to be explicitly supported, either by the UDC itself or by the hardware
  1.1136 +		platform. If it is supported, then the member function SoftConnectCaps should be implemented to return
  1.1137 +		ETrue.
  1.1138 +
  1.1139 +		@see SoftConnectCaps()
  1.1140 +
  1.1141 +		@return KErrNone if UDC successfully disconnected, KErrGeneral if there was an error.
  1.1142 +
  1.1143 +		@publishedPartner @released
  1.1144 +	*/
  1.1145 +	virtual TInt UdcDisconnect() =0;
  1.1146 +
  1.1147 +	/** Returns the USB cable connection status.
  1.1148 +
  1.1149 +		@return ETrue if the device is connected (via the USB cable) to a USB host, EFalse if not.
  1.1150 +
  1.1151 +		@publishedPartner @released
  1.1152 +	*/
  1.1153 +	virtual TBool UsbConnectionStatus() const  =0;
  1.1154 +
  1.1155 +	/** Returns a truth value showing if the VBUS line is powered or not.
  1.1156 +
  1.1157 +		Lack of power may indicate an unpowered host or upstream hub, or a disconnected cable.
  1.1158 +
  1.1159 +		@return ETrue if VBUS is powered, EFalse otherwise.
  1.1160 +
  1.1161 +		@publishedPartner @released
  1.1162 +	*/
  1.1163 +	virtual TBool UsbPowerStatus() const =0;
  1.1164 +
  1.1165 +	/** Returns the current power status of the USB device.
  1.1166 +
  1.1167 +		@return ETrue if the device is currently self-powered, EFalse if not.
  1.1168 +
  1.1169 +		@publishedPartner @released
  1.1170 +	*/
  1.1171 +	virtual TBool DeviceSelfPowered() const =0;
  1.1172 +
  1.1173 +	/** Returns a pointer to an array of TUsbcEndpointCaps structures, which describe the endpoint
  1.1174 +		capabilities of this UDC.
  1.1175 +
  1.1176 +		The dimension of the array can be obtained by calling the member function DeviceTotalEndpoints().
  1.1177 +		Note that there might be gaps in the array, as the endpoints are numbered using the 'real endpoint'
  1.1178 +		numbering scheme. Here is how an array could look like:
  1.1179 +
  1.1180 +		@code
  1.1181 +		static const TInt KUsbTotalEndpoints = 5;
  1.1182 +		static const TUsbcEndpointCaps DeviceEndpoints[KUsbTotalEndpoints] =
  1.1183 +		{
  1.1184 +		//															 UDC #	  iEndpoints index
  1.1185 +		{KEp0MaxPktSzMask,	(KUsbEpTypeControl	   | KUsbEpDirOut)}, //	 0 -  0
  1.1186 +		{KEp0MaxPktSzMask,	(KUsbEpTypeControl	   | KUsbEpDirIn )}, //	 0 -  1
  1.1187 +		{KUsbEpNotAvailable, KUsbEpNotAvailable},					 // --- Not present
  1.1188 +		{KBlkMaxPktSzMask,	(KUsbEpTypeBulk		   | KUsbEpDirIn )}, //	 1 -  3
  1.1189 +		{KBlkMaxPktSzMask,	(KUsbEpTypeBulk		   | KUsbEpDirOut)}	 //	 2 -  4
  1.1190 +		};
  1.1191 +		@endcode
  1.1192 +
  1.1193 +		For the endpoint max packet sizes on a USB 2.0 High-speed UDC, the PSL should provide
  1.1194 +		the overlaid values for both FS and HS, as the PIL can deduce the appropriate values
  1.1195 +		for either speed.
  1.1196 +
  1.1197 +		@see TUsbcEndpointCaps
  1.1198 +		@see DeviceTotalEndpoints()
  1.1199 +
  1.1200 +		@return A pointer to an array of TUsbcEndpointCaps structures, which describe the endpoint
  1.1201 +		capabilities of this UDC.
  1.1202 +
  1.1203 +		@publishedPartner @released
  1.1204 +	*/
  1.1205 +	virtual const TUsbcEndpointCaps* DeviceEndpointCaps() const =0;
  1.1206 +
  1.1207 +	/** Returns the number of elements in the array pointed to by the return value of DeviceEndpointCaps().
  1.1208 +
  1.1209 +		Note that this is not necessarily equal to the number of usable endpoints. In the example to the
  1.1210 +		DeviceEndpointCaps() function, this value would be 5 even though there are only 4 endpoints.
  1.1211 +
  1.1212 +		@see DeviceEndpointCaps()
  1.1213 +
  1.1214 +		@return The number of elements in the array pointed to by the return value of DeviceEndpointCaps().
  1.1215 +
  1.1216 +		@publishedPartner @released
  1.1217 +	*/
  1.1218 +	virtual TInt DeviceTotalEndpoints() const =0;
  1.1219 +
  1.1220 +	/** Returns a truth value indicating whether or not this UDC or platform has the capability to disconnect
  1.1221 +		and re-connect the USB D+ line under software control.
  1.1222 +
  1.1223 +		@see UdcConnect()
  1.1224 +		@see UdcDisconnect()
  1.1225 +
  1.1226 +		@return ETrue if software connect/disconnect is supported, EFalse otherwise.
  1.1227 +
  1.1228 +		@publishedPartner @released
  1.1229 +	*/
  1.1230 +	virtual TBool SoftConnectCaps() const =0;
  1.1231 +
  1.1232 +	/** Returns a truth value indicating whether or not this UDC allows the accurate tracking of the USB
  1.1233 +		device state.
  1.1234 +
  1.1235 +		This capability affects how device state change notifications to the LDD/user are being handled.
  1.1236 +
  1.1237 +		@return ETrue if this UDC allows the tracking of the USB device state, EFalse otherwise.
  1.1238 +
  1.1239 +		@publishedPartner @released
  1.1240 +	*/
  1.1241 +	virtual TBool DeviceStateChangeCaps() const =0;
  1.1242 +
  1.1243 +	/** Returns a truth value indicating whether the USB device controller (UDC) hardware supports
  1.1244 +		detection of a plugged-in USB cable even when not powered.
  1.1245 +
  1.1246 +		This capability affects the power management strategy used by the USB Manager.
  1.1247 +
  1.1248 +		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs.
  1.1249 +		 The default implementation in the PIL returns EFalse.)
  1.1250 +
  1.1251 +		@return ETrue if this UDC supports USB cable detection when not powered, EFalse otherwise.
  1.1252 +
  1.1253 +		@publishedPartner @released
  1.1254 +	*/
  1.1255 +	virtual TBool CableDetectWithoutPowerCaps() const;
  1.1256 +
  1.1257 +	/** Returns a truth value indicating whether the USB device controller (UDC) hardware supports
  1.1258 +		USB High-speed operation.
  1.1259 +
  1.1260 +		This capability affects driver functionality and behaviour throughout the implementation.
  1.1261 +
  1.1262 +		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs.
  1.1263 +		 The default implementation in the PIL returns EFalse.)
  1.1264 +
  1.1265 +		@return ETrue if this UDC supports USB High-speed operation, EFalse otherwise.
  1.1266 +
  1.1267 +		@publishedPartner @released
  1.1268 +	*/
  1.1269 +	virtual TBool DeviceHighSpeedCaps() const;
  1.1270 +
  1.1271 +	/** Returns a truth value indicating whether this PSL supports the new
  1.1272 +		('V2') endpoint resource request scheme.
  1.1273 +
  1.1274 +		This capability can be queried from the user-side and may determine the
  1.1275 +		way the USB application issues resource allocation requests.
  1.1276 +
  1.1277 +		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs.
  1.1278 +		 The default implementation in the PIL returns EFalse.)
  1.1279 +
  1.1280 +		@return ETrue if PSL supports the new endpoint resource request scheme,
  1.1281 +		EFalse otherwise.
  1.1282 +
  1.1283 +		@publishedPartner @released
  1.1284 +	*/
  1.1285 +	virtual TBool DeviceResourceAllocV2Caps() const;
  1.1286 +
  1.1287 +	/** Returns a truth value indicating whether this UDC handles OTG HNP bus
  1.1288 +		connects/disconnects automatically in hardware.
  1.1289 +
  1.1290 +		This capability will be queried by the PIL and determines the way the
  1.1291 +		PIL calls the functions behind the
  1.1292 +		iEnablePullUpOnDPlus / iDisablePullUpOnDPlus pointers.
  1.1293 +
  1.1294 +		If HNP is handled by hardware (TBool = ETrue) then the PIL will (in
  1.1295 +		that order)
  1.1296 +
  1.1297 +		1) make calls to those function pointers dependent only on the
  1.1298 +		readiness or otherwise of user-side USB Client support (i.e. the Client
  1.1299 +		LDD calls DeviceConnectToHost() / DeviceDisconnectFromHost()), as
  1.1300 +		opposed to also evaluating Client PDD EnableClientStack() /
  1.1301 +		DisableClientStack() calls from the OTG driver.
  1.1302 +
  1.1303 +		2) delay its USB Reset processing incl. the notification of upper
  1.1304 +		layers (LDD + user-side), plus the initial setting up of an Ep0 read
  1.1305 +		until user-side USB Client support readiness has been signalled
  1.1306 +		(i.e. until after a call to DeviceConnectToHost()).
  1.1307 +
  1.1308 +		(Function is not 'pure virtual' for backwards compatibility with
  1.1309 +		 existing USB PSLs. The default implementation in the PIL returns EFalse.)
  1.1310 +
  1.1311 +		@return ETrue if UDC/PSL handles HNP connects/disconnects in hardware,
  1.1312 +		EFalse otherwise.
  1.1313 +
  1.1314 +		@publishedPartner @released
  1.1315 +	*/
  1.1316 +	virtual TBool DeviceHnpHandledByHardwareCaps() const;
  1.1317 +
  1.1318 +	/** Implements anything the UDC (PSL) might require following bus Suspend signalling.
  1.1319 +
  1.1320 +		This function gets called by the PIL after it has been notified (by the PSL) about the Suspend
  1.1321 +		condition.
  1.1322 +
  1.1323 +		@publishedPartner @released
  1.1324 +	*/
  1.1325 +	virtual void Suspend() =0;
  1.1326 +
  1.1327 +	/** Implements anything the UDC (PSL) might require following bus Resume signalling.
  1.1328 +
  1.1329 +		This function gets called by the PIL after it has been notified (by the PSL) about the Resume event.
  1.1330 +
  1.1331 +		@publishedPartner @released
  1.1332 +	*/
  1.1333 +	virtual void Resume() =0;
  1.1334 +
  1.1335 +	/** Implements anything the UDC (PSL) might require following bus Reset signalling.
  1.1336 +
  1.1337 +		This function gets called by the PIL after it has been notified (by the PSL) about the Reset event.
  1.1338 +
  1.1339 +		@publishedPartner @released
  1.1340 +	*/
  1.1341 +	virtual void Reset() =0;
  1.1342 +
  1.1343 +	/** Called by the PIL to signal to the PSL that it has finished processing a received Setup packet (on
  1.1344 +		Ep0) and that the PSL can now prepare itself for the next Ep0 reception (for instance by re-enabling
  1.1345 +		the Ep0 interrupt).
  1.1346 +
  1.1347 +		The reason for having this function is the situation where no Ep0 read has been set up by the user and
  1.1348 +		thus a received Setup packet cannot immediately be delivered to the user. Once the user however sets
  1.1349 +		up an Ep0 read, the PIL completes the request and eventually calls this function. This way we can
  1.1350 +		implement some sort of flow-control.
  1.1351 +
  1.1352 +		@publishedPartner @released
  1.1353 +	*/
  1.1354 +	virtual void Ep0ReadSetupPktProceed() =0;
  1.1355 +
  1.1356 +	/** Called by the PIL to signal to the PSL that it has finished processing a received Ep0 data packet and
  1.1357 +		that the PSL can now prepare itself for the next Ep0 reception (for instance by re-enabling the Ep0
  1.1358 +		interrupt).
  1.1359 +
  1.1360 +		The reason for having this function is the situation where no Ep0 read has been set up by the user and
  1.1361 +		thus a received packet cannot immediately be delivered to the user. Once the user however sets up an
  1.1362 +		Ep0 read, the PIL completes the request and eventually calls this function. This way we can implement
  1.1363 +		some sort of flow-control.
  1.1364 +
  1.1365 +		@publishedPartner @released
  1.1366 +	*/
  1.1367 +	virtual void Ep0ReceiveProceed() =0;
  1.1368 +
  1.1369 +	/** Returns a truth value indicating whether the USB controller hardware (UDC) supports being powered
  1.1370 +		down while (a configuration is) active.
  1.1371 +
  1.1372 +		This capability affects the power management strategy used by the USB Manager.
  1.1373 +
  1.1374 +		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs. The default
  1.1375 +		implementation in the PIL - to be on the safe side - returns EFalse.)
  1.1376 +
  1.1377 +		@return ETrue if this UDC supports power-down while active, EFalse otherwise.
  1.1378 +
  1.1379 +		@publishedPartner @released
  1.1380 +	*/
  1.1381 +	virtual TBool PowerDownWhenActive() const;
  1.1382 +
  1.1383 +	/** Powers the UDC down, i.e. puts it into a (hardware-dependent) power-saving mode. Note that this
  1.1384 +		function is not the same as StopUdc(). The difference is that while StopUdc() effectively turns the
  1.1385 +		UDC off and so may invalidate all its settings, after a call to PowerDown() the UDC is expected to
  1.1386 +		return to its previous state when PowerUp() is called. This function is also not the same as
  1.1387 +		Suspend() which gets called by the PIL in response to a Suspend event on the bus, and only then
  1.1388 +		(but apart from that the two functions are very similar).
  1.1389 +
  1.1390 +		This function won't be called by the PIL once the UDC is active if PowerDownWhenActive() returns
  1.1391 +		EFalse (which it by default does).
  1.1392 +
  1.1393 +		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs. The default
  1.1394 +		implementation in the PIL does nothing.)
  1.1395 +
  1.1396 +		@see PowerUp()
  1.1397 +		@see PowerDownWhenActive()
  1.1398 +
  1.1399 +		@return KErrNone if UDC was successfully powered down, KErrGeneral otherwise.
  1.1400 +
  1.1401 +		@publishedPartner @released
  1.1402 +	*/
  1.1403 +	virtual TInt PowerDown();
  1.1404 +
  1.1405 +	/** Powers the UDC up by exiting a (hardware-dependent) power-saving mode. Note that this function is not
  1.1406 +		the same as StartUdc(). The difference is that while StartUdc() starts the UDC from zero and merely
  1.1407 +		leads to the default state (i.e. not an active configuration), after a call to PowerUp() the UDC is
  1.1408 +		expected to have returned to the state it was in before PowerDown() was called.
  1.1409 +
  1.1410 +		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs. The default
  1.1411 +		implementation in the PIL does nothing.)
  1.1412 +
  1.1413 +		@see PowerDown()
  1.1414 +
  1.1415 +		@return KErrNone if UDC was successfully powered up, KErrGeneral otherwise.
  1.1416 +
  1.1417 +		@publishedPartner @released
  1.1418 +	*/
  1.1419 +	virtual TInt PowerUp();
  1.1420 +
  1.1421 +	/** Puts the controller into a specific test mode (during HS operation only).
  1.1422 +
  1.1423 +		9.4.9 Set Feature: "The transition to test mode must be complete no later than 3 ms after the
  1.1424 +		completion of the status stage of the request." (The status stage will have been completed
  1.1425 +		immediately before this function gets called.)
  1.1426 +
  1.1427 +		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs.
  1.1428 +		 The default implementation in the PIL returns KErrNotSupported.)
  1.1429 +
  1.1430 +		@param aTestSelector The specific test mode selector (@see usb.h).
  1.1431 +
  1.1432 +		@return KErrNone if the specified test mode was entered successfully,
  1.1433 +		KErrGeneral otherwise.
  1.1434 +
  1.1435 +		@publishedPartner @released
  1.1436 +	*/
  1.1437 +	virtual TInt EnterTestMode(TInt aTestSelector);
  1.1438 +
  1.1439 +	/** Turn on USB client functionality in an OTG/Host setup.
  1.1440 +
  1.1441 +		This PSL function is called by the PIL when the OTG stack calls the PIL
  1.1442 +		function EnableClientStack(). Immediately afterwards the PIL may
  1.1443 +		connect the B-device to the bus (via the OTG stack). OtgEnableUdc() is
  1.1444 +		called always after StartUdc().
  1.1445 +
  1.1446 +		There is no equivalent to this function in the non-OTG version of the
  1.1447 +		USB PDD.
  1.1448 +
  1.1449 +		@return KErrNone if UDC successfully enabled, KErrGeneral otherwise.
  1.1450 +
  1.1451 +		@publishedPartner @released
  1.1452 +	*/
  1.1453 +	virtual TInt OtgEnableUdc();
  1.1454 +
  1.1455 +	/** Turn off USB client functionality in an OTG/Host setup.
  1.1456 +
  1.1457 +		This function is called by the PIL when the OTG stack calls the PIL
  1.1458 +		function DisableClientStack(); the PIL will do this immediately after
  1.1459 +		it has disconnected the B-device from the bus (via the OTG stack) and
  1.1460 +		before calling StopUdc().
  1.1461 +
  1.1462 +		There is no equivalent to this function in the non-OTG version of the
  1.1463 +		USB PDD.
  1.1464 +
  1.1465 +		@return KErrNone if UDC successfully disabled, KErrGeneral otherwise.
  1.1466 +
  1.1467 +		@publishedPartner @released
  1.1468 +	*/
  1.1469 +	virtual TInt OtgDisableUdc();
  1.1470 +
  1.1471 +private:
  1.1472 +
  1.1473 +	//
  1.1474 +	// --- Private member functions (used by PIL) ---
  1.1475 +	//
  1.1476 +
  1.1477 +	TInt DeRegisterClientCallback(const DBase* aClientId);
  1.1478 +	TBool CheckEpAvailability(TInt aEndpointsUsed, const TUsbcEndpointInfoArray& aEndpointData, TInt aIfcNumber)
  1.1479 +		const;
  1.1480 +	TUsbcInterface* CreateInterface(const DBase* aClientId, TInt aIfc, TUint32 aFeatureWord);
  1.1481 +	TInt CreateEndpoints(TUsbcInterface* aIfc, TInt aEndpointsUsed, const TUsbcEndpointInfoArray& aEndpointData,
  1.1482 +						 TInt *aRealEpNumbers);
  1.1483 +	TInt SetupIfcDescriptor(TUsbcInterface* aIfc, TUsbcClassInfo& aClass, DThread* aThread, TDesC8* aString,
  1.1484 +							const TUsbcEndpointInfoArray& aEndpointData);
  1.1485 +	TInt ClientId2InterfaceNumber(const DBase* aClientId) const;
  1.1486 +	TUsbcInterfaceSet* ClientId2InterfacePointer(const DBase* aClientId) const;
  1.1487 +	const DBase* InterfaceNumber2ClientId(TInt aIfcSet) const;
  1.1488 +	TUsbcInterfaceSet* InterfaceNumber2InterfacePointer(TInt aIfcSet) const;
  1.1489 +	inline const DBase* PEndpoint2ClientId(TInt aRealEndpoint) const;
  1.1490 +	inline TInt PEndpoint2LEndpoint(TInt aRealEndpoint) const;
  1.1491 +	TInt ActivateHardwareController();
  1.1492 +	void DeActivateHardwareController();
  1.1493 +	void DeleteInterfaceSet(TInt aIfcSet);
  1.1494 +	void DeleteInterface(TInt aIfcSet, TInt aIfc);
  1.1495 +	void CancelTransferRequests(TInt aRealEndpoint);
  1.1496 +	void DeleteRequestCallback(const DBase* aClientId, TInt aEndpointNum, TTransferDirection aTransferDir);
  1.1497 +	void DeleteRequestCallbacks(const DBase* aClientId);
  1.1498 +	void StatusNotify(TUsbcDeviceState aState, const DBase* aClientId=NULL);
  1.1499 +	void EpStatusNotify(TInt aRealEndpoint);
  1.1500 +	void OtgFeaturesNotify();
  1.1501 +	void RunClientCallbacks();
  1.1502 +	void ProcessDataTransferDone(TUsbcRequestCallback& aRcb);
  1.1503 +	void NextDeviceState(TUsbcDeviceState aNextState);
  1.1504 +	TInt ProcessSuspendEvent();
  1.1505 +	TInt ProcessSuspendEventProceed();
  1.1506 +	TInt ProcessResumeEvent();
  1.1507 +	TInt ProcessResetEvent(TBool aPslUpcall=ETrue);
  1.1508 +	TInt ProcessCableInsertEvent();
  1.1509 +	TInt ProcessCableRemoveEvent();
  1.1510 +	TInt ProcessEp0ReceiveDone(TInt aCount);
  1.1511 +	TInt ProcessEp0TransmitDone(TInt aCount, TInt aError);
  1.1512 +	TInt ProcessEp0SetupReceived(TInt aCount);
  1.1513 +	TInt ProcessEp0DataReceived(TInt aCount);
  1.1514 +	TInt ProcessGetDeviceStatus(const TUsbcSetup& aPacket);
  1.1515 +	TInt ProcessGetInterfaceStatus(const TUsbcSetup& aPacket);
  1.1516 +	TInt ProcessGetEndpointStatus(const TUsbcSetup& aPacket);
  1.1517 +	TInt ProcessSetClearDevFeature(const TUsbcSetup& aPacket);
  1.1518 +	TInt ProcessSetClearIfcFeature(const TUsbcSetup& aPacket);
  1.1519 +	TInt ProcessSetClearEpFeature(const TUsbcSetup& aPacket);
  1.1520 +	TInt ProcessSetAddress(const TUsbcSetup& aPacket);
  1.1521 +	TInt ProcessGetDescriptor(const TUsbcSetup& aPacket);
  1.1522 +	TInt ProcessSetDescriptor(const TUsbcSetup& aPacket);
  1.1523 +	TInt ProcessGetConfiguration(const TUsbcSetup& aPacket);
  1.1524 +	TInt ProcessGetInterface(const TUsbcSetup& aPacket);
  1.1525 +	TInt ProcessSetInterface(const TUsbcSetup& aPacket);
  1.1526 +	TInt ProcessSynchFrame(const TUsbcSetup& aPacket);
  1.1527 +	void ProceedSetDescriptor();
  1.1528 +	void SetClearHaltFeature(TInt aRealEndpoint, TUint8 aRequest);
  1.1529 +	TInt ClearHaltFeature(TInt aRealEndpoint);
  1.1530 +	void ChangeConfiguration(TUint16 aValue);
  1.1531 +	void InterfaceSetup(TUsbcInterface* aIfc);
  1.1532 +	void InterfaceSetTeardown(TUsbcInterfaceSet* aIfc);
  1.1533 +	void ChangeInterface(TUsbcInterface* aIfc);
  1.1534 +	TInt DoForEveryEndpointInUse(TInt (DUsbClientController::*aFunction)(TInt), TInt& aCount);
  1.1535 +	void EnterFullSpeed();
  1.1536 +	void EnterHighSpeed();
  1.1537 +	TInt EvaluateOtgConnectFlags();
  1.1538 +	inline const TUsbcConfiguration* CurrentConfig() const;
  1.1539 +	inline TUsbcConfiguration* CurrentConfig();
  1.1540 +	inline TBool InterfaceExists(TInt aNumber) const;
  1.1541 +	inline TBool EndpointExists(TUint aAddress) const;
  1.1542 +	inline void Buffer2Setup(const TAny* aBuf, TUsbcSetup& aSetup) const;
  1.1543 +	inline TUint EpIdx2Addr(TUint aRealEndpoint) const;
  1.1544 +	inline TUint EpAddr2Idx(TUint aAddress) const;
  1.1545 +	inline void SetEp0DataOutVars(const TUsbcSetup& aPacket, const DBase* aClientId = NULL);
  1.1546 +	inline void ResetEp0DataOutVars();
  1.1547 +	inline TBool IsInTheStatusList(const TUsbcStatusCallback& aCallback);
  1.1548 +	inline TBool IsInTheEpStatusList(const TUsbcEndpointStatusCallback& aCallback);
  1.1549 +	inline TBool IsInTheOtgFeatureList(const TUsbcOtgFeatureCallback& aCallback);
  1.1550 +	inline TBool IsInTheRequestList(const TUsbcRequestCallback& aCallback);
  1.1551 +	static void ReconnectTimerCallback(TAny* aPtr);
  1.1552 +	static void CableStatusTimerCallback(TAny* aPtr);
  1.1553 +	static void PowerUpDfc(TAny* aPtr);
  1.1554 +	static void PowerDownDfc(TAny* aPtr);
  1.1555 +
  1.1556 +private:
  1.1557 +
  1.1558 +	//
  1.1559 +	// --- Private data members ---
  1.1560 +	//
  1.1561 +
  1.1562 +	static DUsbClientController* UsbClientController[KUsbcMaxUdcs];
  1.1563 +
  1.1564 +	TInt iDeviceTotalEndpoints;								// number of endpoints reported by PSL
  1.1565 +	TInt iDeviceUsableEndpoints;							// number of endpoints reported to LDD
  1.1566 +	TUsbcDeviceState iDeviceState;							// states as of USB spec chapter 9.1
  1.1567 +	TUsbcDeviceState iDeviceStateB4Suspend;					// state before entering suspend state
  1.1568 +	TBool iSelfPowered;										// true if device is capable of beeing self-powered
  1.1569 +	TBool iRemoteWakeup;									// true if device is capable of signalling rmwakeup
  1.1570 +	TBool iTrackDeviceState;								// true if we should track the device state in s/w
  1.1571 +	TBool iHardwareActivated;								// true if controller silicon is in operating state
  1.1572 +	TBool iOtgSupport;										// true if OTG is supported by this device
  1.1573 +	TBool iOtgHnpHandledByHw;								// true if HNP dis/connect is handled by hardware
  1.1574 +	TUint8 iOtgFuncMap;										// bitmap indicating OTG extension features
  1.1575 +	TBool iHighSpeed;										// true if currently operating at high-speed
  1.1576 +	TUsbcSetup iSetup;										// storage for a setup packet during its DATA_OUT
  1.1577 +	TInt iEp0MaxPacketSize;									// currently configured max packet size for Ep0
  1.1578 +	const DBase* iEp0ClientId;								// see comment at the begin of ps_usbc.cpp
  1.1579 +	TUint16 iEp0DataReceived;								// indicates how many bytes have already been received
  1.1580 +	TBool iEp0DataReceiving;								// true if ep0's in DATA_OUT stage
  1.1581 +	TBool iEp0WritePending;									// true if a write on ep0 has been set up
  1.1582 +	TBool iEp0ClientDataTransmitting;						// true if ep0's in DATA_IN on behalf of a client
  1.1583 +	const DBase* iEp0DeviceControl;							// Device Ep0 requests are delivered to this LDD
  1.1584 +	TUsbcDescriptorPool iDescriptors;						// the descriptors as of USB spec chapter 9.5
  1.1585 +	TUint8 iCurrentConfig;									// bConfigurationValue of current Config (1-based!)
  1.1586 +	RPointerArray<TUsbcConfiguration> iConfigs;				// the root of the modelled USB device
  1.1587 +	TUsbcPhysicalEndpoint iRealEndpoints[KUsbcEpArraySize]; // array will be filled once at startup
  1.1588 +	TUint8 iEp0_TxBuf[KUsbcBufSz_Ep0Tx];					// ep0 outgoing (tx) data is placed here
  1.1589 +#ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
  1.1590 +	TUint8 iEp0_RxCollectionBuf[KUsbcBufSz_Ep0Rx];			// used for (optional) SET_DESCRIPTOR request
  1.1591 +#endif
  1.1592 +	TInt iEp0_RxExtraCount;									// number of bytes received but not yet delivered
  1.1593 +	TBool iEp0_RxExtraData;									// true if iEp0_RxExtraCount is valid
  1.1594 +	TInt iEp0_TxNonStdCount;								// number of bytes requested by non-std Ep0 request
  1.1595 +	TUsbcRequestCallback* iRequestCallbacks[KUsbcEpArraySize]; // xfer requests; indexed by real ep number
  1.1596 +	TSglQue<TUsbcRequestCallback> iEp0ReadRequestCallbacks;	// list of ep0 read requests
  1.1597 +	TSglQue<TUsbcClientCallback> iClientCallbacks;          // registered LDD clients and their callback functions
  1.1598 +	TSglQue<TUsbcStatusCallback> iStatusCallbacks;			// list of device state notification requests
  1.1599 +	TSglQue<TUsbcEndpointStatusCallback> iEpStatusCallbacks; // list of endpoint state notification requests
  1.1600 +	TSglQue<TUsbcOtgFeatureCallback> iOtgCallbacks;		    // list of OTG feature change requests
  1.1601 +	NTimer iReconnectTimer;									// implements USB re-enumeration delay
  1.1602 +	NTimer iCableStatusTimer;								// implements USB cable status detection delay
  1.1603 +	DUsbcPowerHandler* iPowerHandler;						// pointer to USB power handler object
  1.1604 +
  1.1605 +protected:
  1.1606 +	TDfc iPowerUpDfc;										// queued by power handler upon power-up
  1.1607 +	TDfc iPowerDownDfc;										// queued by power handler upon power-down
  1.1608 +
  1.1609 +private:
  1.1610 +	TBool iStandby;											// toggled by power handler as appropriate
  1.1611 +	TBool iStackIsActive;									// client stack's function is usable
  1.1612 +	TBool iOtgClientConnect;								// OTG stack wishes to connect to the host
  1.1613 +	TBool iClientSupportReady;								// user-side USB Client support is loaded & active
  1.1614 +	TBool iDPlusEnabled;									// set if both sides agree and DPLUS is asserted
  1.1615 +	TBool iUsbResetDeferred;								// set when user-side wasn't ready yet
  1.1616 +
  1.1617 +public:
  1.1618 +	TInt (*iEnablePullUpOnDPlus)(TAny* aOtgContext);		// these are to be filled in by the Host component
  1.1619 +	TInt (*iDisablePullUpOnDPlus)(TAny* aOtgContext);		// in an OTG setup (otherwise unused)
  1.1620 +	TAny* iOtgContext;										// to be passed into the above 2 functions
  1.1621 +	};
  1.1622 +
  1.1623 +
  1.1624 +/** Simple queue of status changes to be recorded.
  1.1625 +	Items are fetched by userside when able.
  1.1626 +*/
  1.1627 +class TUsbcDeviceStatusQueue
  1.1628 +	{
  1.1629 +public:
  1.1630 +	TUsbcDeviceStatusQueue();
  1.1631 +	void AddStatusToQueue(TUint32 aDeviceStatus);
  1.1632 +	TInt GetDeviceQueuedStatus(TUint32& aDeviceStatus);
  1.1633 +	void FlushQueue();
  1.1634 +
  1.1635 +private:
  1.1636 +	TUint32 iDeviceStatusQueue[KUsbDeviceStatusQueueDepth];
  1.1637 +	TInt iStatusQueueHead;
  1.1638 +	};
  1.1639 +
  1.1640 +#include <drivers/usbcshared.inl>
  1.1641 +
  1.1642 +#endif	// __USBCSHARED_H__
  1.1643 +
  1.1644 +
  1.1645 +
  1.1646 +
  1.1647 +
  1.1648 +
  1.1649 +
  1.1650 +
  1.1651 +
  1.1652 +
  1.1653 +
  1.1654 +
  1.1655 +
  1.1656 +
  1.1657 +
  1.1658 +
  1.1659 +
  1.1660 +