kernel/eka/include/d32usbcshared.h
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32/include/d32usbcshared.h
       
    15 // User side class definitions for USB Device support.
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file d32usbcshared.h
       
    21  @publishedPartner
       
    22  @released
       
    23 */
       
    24 
       
    25 #ifndef __D32USBCSHARED_H__
       
    26 #define __D32USBCSHARED_H__
       
    27 
       
    28 // USB driver error codes
       
    29 
       
    30 /** USB driver specific error codes start from here
       
    31 */
       
    32 const TInt KErrUsbDriverBase = -6701;
       
    33 
       
    34 /**	Attempt at data transfer, or something interface related,
       
    35 	when neither an Interface has been set up nor Device Control is owned by
       
    36 	the channel
       
    37 */
       
    38 const TInt KErrUsbInterfaceNotReady = -6702;
       
    39 
       
    40 /**	Attempt at data transfer on an endpoint that does not belong to the active interface
       
    41 */
       
    42 const TInt KErrUsbEpNotInInterface = -6703;
       
    43 
       
    44 /**	Attempt at data transfer in a direction not supported by the endpoint
       
    45 */
       
    46 const TInt KErrUsbEpBadDirection = -6704;
       
    47 
       
    48 /**	The data transfer size specified exceeds that of the source or
       
    49 	destination buffer descriptor
       
    50 */
       
    51 const TInt KErrUsbTransferSize = -6705;
       
    52 
       
    53 /**	This has multiple uses:
       
    54 	1) User request completed because device is no longer in configured state
       
    55 	2) Something endpoint related, stall, unstall, status enquiry etc,
       
    56 	   that requires the device to be configured
       
    57 */
       
    58 const TInt KErrUsbDeviceNotConfigured = -6706;
       
    59 
       
    60 /**	Requested endpoint properties inconsistent during Interface setup
       
    61 */
       
    62 const TInt KErrUsbBadEndpoint = -6707;
       
    63 
       
    64 /**	User data request completed because channel is closing (channel destructor called)
       
    65 */
       
    66 const TInt KErrUsbDeviceClosing = -6708;
       
    67 
       
    68 /**	User data request completed because current endpoint set is being
       
    69 	replaced since alternate setting is changing
       
    70 */
       
    71 const TInt KErrUsbInterfaceChange = -6709;
       
    72 
       
    73 /**	User data request completed because cable has been detached (or equivalent)
       
    74 */
       
    75 const TInt KErrUsbCableDetached = -6710;
       
    76 
       
    77 /**	User data request completed because cable has been detached (or equivalent)
       
    78 */
       
    79 const TInt KErrUsbDeviceBusReset = -6711;
       
    80 
       
    81 /**	This means that read data is still available when a write request is made.
       
    82 	Relates to bidirectional eps only (ep0).
       
    83 	A bidirectional ep must consume all of its read data before attempting to write.
       
    84 */
       
    85 const TInt KErrUsbEpNotReady = -6712;
       
    86 
       
    87 /** These are states that are described in the USB standard.
       
    88 
       
    89 	@see RDevUsbcClient::DeviceStatus()
       
    90 	@see RDevUsbcClient::AlternateDeviceStatusNotify()
       
    91 */
       
    92 enum TUsbcDeviceState
       
    93 	{
       
    94 	EUsbcDeviceStateUndefined,								// 0
       
    95 	EUsbcDeviceStateAttached,								// 1
       
    96 	EUsbcDeviceStatePowered,								// 2
       
    97 	EUsbcDeviceStateDefault,								// 3
       
    98 	EUsbcDeviceStateAddress,								// 4
       
    99 	EUsbcDeviceStateConfigured,								// 5
       
   100 	EUsbcDeviceStateSuspended,								// 6
       
   101  	EUsbcNoState = 0xff										// 255 (used as a place holder)
       
   102 	};
       
   103 
       
   104 /** The endpoint states.
       
   105 
       
   106 	@see RDevUsbcClient::EndpointStatus()
       
   107 	@see RDevUsbcClient::EndpointStatusNotify()
       
   108 */
       
   109 enum TEndpointState
       
   110 	{
       
   111 	EEndpointStateNotStalled,
       
   112 	EEndpointStateStalled,
       
   113 	EEndpointStateUnknown
       
   114 	};
       
   115 
       
   116 /** Endpoint resources/behaviours.
       
   117 
       
   118 	@see AllocateEndpointResource()
       
   119 	@see DeAllocateEndpointResource()
       
   120 	@see QueryEndpointResourceUse()
       
   121 */
       
   122 enum TUsbcEndpointResource
       
   123 	{
       
   124 	/** Requests the use of DMA. */
       
   125 	EUsbcEndpointResourceDMA = 0,
       
   126 	/** Requests the use of double FIFO buffering. */
       
   127 	EUsbcEndpointResourceDoubleBuffering = 1
       
   128 	};
       
   129 
       
   130 
       
   131 /** The USB client device capability class.
       
   132 */
       
   133 class TCapsDevUsbc
       
   134 	{
       
   135 public:
       
   136 	/** The device version. */
       
   137 	TVersion version;
       
   138 	};
       
   139 
       
   140 
       
   141 /** The maximum number of endpoints supported by the device, excluding ep0.
       
   142 */
       
   143 const TInt KUsbcMaxEndpoints = 30;
       
   144 
       
   145 /** The maximum number of endpoints per interface, excluding ep0.
       
   146 */
       
   147 const TInt KMaxEndpointsPerClient = 5;
       
   148 
       
   149 /** @internalComponent
       
   150 */
       
   151 const TInt KInvalidEndpointNumber = 31;
       
   152 
       
   153 /** The alternate setting flag; when this bit is set the state change notified by
       
   154 	RDevUsbcClient::AlternateDeviceStatusNotify() is an alternate setting number.
       
   155 */
       
   156 const TUint KUsbAlternateSetting = 0x80000000;
       
   157 
       
   158 /** The USB cable detection feature flag; used by TUsbDeviceCapsV01::iFeatureWord1.
       
   159 	When this bit is set then the USB controller hardware (UDC) supports detection
       
   160 	of a plugged-in USB cable even when not powered.
       
   161 
       
   162 	@see TUsbDeviceCapsV01
       
   163 */
       
   164 const TUint KUsbDevCapsFeatureWord1_CableDetectWithoutPower = 0x00000001;
       
   165 
       
   166 /** If this flag is set then the driver supports the new endpoint resource
       
   167 	allocation scheme for DMA and Double-buffering via
       
   168 	TUsbcEndpointInfo::iFeatureWord1.
       
   169 
       
   170 	@see TUsbDeviceCapsV01
       
   171 */
       
   172 const TUint KUsbDevCapsFeatureWord1_EndpointResourceAllocV2 = 0x00000002;
       
   173 
       
   174 
       
   175 /** Device USB capabilities.
       
   176 */
       
   177 class TUsbDeviceCapsV01
       
   178 	{
       
   179 public:
       
   180 	/** The total number of endpoints on the device. */
       
   181 	TInt iTotalEndpoints;
       
   182 	/** Indicates whether the device supports software connect/disconnect. */
       
   183 	TBool iConnect;
       
   184 	/** Indicates whether the device is self powered. */
       
   185 	TBool iSelfPowered;
       
   186 	/** Indicates whether the device can send Remote Wakeup. */
       
   187 	TBool iRemoteWakeup;
       
   188 	/** Indicates whether the device supports High-speed mode. */
       
   189 	TBool iHighSpeed;
       
   190 	/** 32 flag bits indicating miscellaneous UDC/device features.
       
   191 		Currently defined are:
       
   192 		- KUsbDevCapsFeatureWord1_CableDetectWithoutPower = 0x00000001
       
   193 		- KUsbDevCapsFeatureWord1_EndpointResourceAllocV2 = 0x00000002
       
   194 	*/
       
   195 	TUint32 iFeatureWord1;
       
   196 	/** Reserved for future use. */
       
   197 	TUint32 iReserved;
       
   198 	};
       
   199 
       
   200 /** Package buffer for a TUsbDeviceCapsV01 object.
       
   201 
       
   202 	@see TUsbDeviceCapsV01
       
   203 */
       
   204 typedef TPckgBuf<TUsbDeviceCapsV01> TUsbDeviceCaps;
       
   205 
       
   206 /** Bitmaps for TUsbcEndpointCaps.iSizes.
       
   207 
       
   208 	This endpoint is not available (= no size).
       
   209 */
       
   210 const TUint KUsbEpNotAvailable = 0x00000000;
       
   211 /**	Max packet size is continuously variable up to some size specified.
       
   212 	(Interrupt and Isochronous endpoints only.)
       
   213 */
       
   214 const TUint KUsbEpSizeCont     = 0x00000001;
       
   215 /** Max packet size 8 bytes is supported
       
   216 */
       
   217 const TUint KUsbEpSize8        = 0x00000008;
       
   218 /** Max packet size 16 bytes is supported
       
   219 */
       
   220 const TUint KUsbEpSize16       = 0x00000010;
       
   221 /** Max packet size 32 bytes is supported
       
   222 */
       
   223 const TUint KUsbEpSize32       = 0x00000020;
       
   224 /** Max packet size 64 bytes is supported
       
   225 */
       
   226 const TUint KUsbEpSize64       = 0x00000040;
       
   227 /** Max packet size 128 bytes is supported
       
   228 */
       
   229 const TUint KUsbEpSize128      = 0x00000080;
       
   230 /** Max packet size 256 bytes is supported
       
   231 */
       
   232 const TUint KUsbEpSize256      = 0x00000100;
       
   233 /** Max packet size 512 bytes is supported
       
   234 */
       
   235 const TUint KUsbEpSize512      = 0x00000200;
       
   236 /** Max packet size 1023 bytes is supported
       
   237 */
       
   238 const TUint KUsbEpSize1023     = 0x00000400;
       
   239 /** Max packet size 1024 bytes is supported
       
   240 */
       
   241 const TUint KUsbEpSize1024     = 0x00000800;
       
   242 
       
   243 
       
   244 /** Bitmaps for TUsbcEndpointCaps.iSupportedTypesAndDir.
       
   245 
       
   246 	Endpoint supports Control transfer type.
       
   247 */
       
   248 const TUint KUsbEpTypeControl     = 0x00000001;
       
   249 /** Endpoint supports Isochronous transfer type.
       
   250 */
       
   251 const TUint KUsbEpTypeIsochronous = 0x00000002;
       
   252 /** Endpoint supports Bulk transfer type.
       
   253 */
       
   254 const TUint KUsbEpTypeBulk        = 0x00000004;
       
   255 /** Endpoint supports Interrupt transfer type.
       
   256 */
       
   257 const TUint KUsbEpTypeInterrupt   = 0x00000008;
       
   258 /** Endpoint supports IN transfers.
       
   259 */
       
   260 const TUint KUsbEpDirIn           = 0x80000000;
       
   261 /** Endpoint supports OUT transfers.
       
   262 */
       
   263 const TUint KUsbEpDirOut          = 0x40000000;
       
   264 /** Endpoint supports bidirectional (Control) transfers only.
       
   265 */
       
   266 const TUint KUsbEpDirBidirect     = 0x20000000;
       
   267 
       
   268 
       
   269 /** Converts an absolute size value into a KUsbEpSize... mask.
       
   270 */
       
   271 static inline TUint PacketSize2Mask(TInt aSize);
       
   272 
       
   273 /** Converts an endpoint type mask KUsbEpType...  into an endpoint attribute
       
   274 	value KUsbEpAttr_....
       
   275 */
       
   276 static inline TUint EpTypeMask2Value(TInt aType);
       
   277 
       
   278 
       
   279 /** Endpoint capabilities as reported by the driver.
       
   280 */
       
   281 class TUsbcEndpointCaps
       
   282 	{
       
   283 public:
       
   284 	/** Returns the greatest available packet size for this endpoint. */
       
   285 	TInt MaxPacketSize() const;
       
   286 	/** Returns the smallest available packet size for this endpoint. */
       
   287 	TInt MinPacketSize() const;
       
   288 public:
       
   289 	/** The supported maximum packet sizes. */
       
   290 	TUint iSizes;
       
   291 	/** The supported endpoint types and directions. */
       
   292 	TUint iTypesAndDir;
       
   293 	/** This is a 'high-speed, high bandwidth' endpoint. */
       
   294 	TBool iHighBandwidth;
       
   295 	/** Reserved for future use. */
       
   296 	TUint32 iReserved[2];
       
   297 	};
       
   298 
       
   299 
       
   300 /** Endpoint capabilities as returned by RDevUsbcClient::EndpointCaps().
       
   301 */
       
   302 class TUsbcEndpointData
       
   303 	{
       
   304 public:
       
   305 	/** Detail of endpoint capabilities. */
       
   306 	TUsbcEndpointCaps iCaps;
       
   307 	/** Indicates whether this endpoint is already claimed. */
       
   308 	TBool iInUse;
       
   309 	};
       
   310 
       
   311 /** The endpoint resource allocation flags;
       
   312 	used by TUsbcEndpointInfo::iFeatureWord1.
       
   313 
       
   314 	@see TUsbcEndpointInfo
       
   315 */
       
   316 const TUint KUsbcEndpointInfoFeatureWord1_DMA             = 0x00000001;
       
   317 const TUint KUsbcEndpointInfoFeatureWord1_DoubleBuffering = 0x00000002;
       
   318 
       
   319 /** The desired endpoint capabilities used in RDevUsbcClient::SetInterface().
       
   320 */
       
   321 class TUsbcEndpointInfo
       
   322 	{
       
   323 public:
       
   324 	TUsbcEndpointInfo(TUint aType=KUsbEpTypeBulk, TUint aDir=KUsbEpDirOut,
       
   325 					  TInt aSize=0, TInt aInterval=0, TInt aExtra=0);
       
   326 	/** @internalComponent */
       
   327 	TInt AdjustEpSizes(TInt& aEpSize_Fs, TInt& aEpSize_Hs) const;
       
   328 	/** @internalComponent */
       
   329 	TInt AdjustPollInterval();
       
   330 public:
       
   331 	/** Endpoint type (mask: KUsbEpTypeControl, etc., but used as value). */
       
   332 	TUint iType;
       
   333 	/** Direction (mask: KUsbEpDirIn, etc., but used as value). */
       
   334 	TUint iDir;
       
   335 	/** Maximum packet size (literal, no mask). */
       
   336 	TInt iSize;
       
   337 	/** Interval for polling full-speed interrupt and isochronous endpoints.
       
   338 		Expressed either directly in milliseconds with a valid range 1..255
       
   339 		(interrupt), or for use as 'value' in the expression interval=2^(value-1)
       
   340 		with a valid range 1..16 (isochronous).
       
   341 	*/
       
   342 	TInt iInterval;
       
   343 	/** Interval for polling high-speed interrupt and isochronous endpoints,
       
   344 		or to specify the NAK rate for high-speed control and bulk OUT endpoints.
       
   345 		Expressed either for use as 'value' in the expression interval=2^(value-1)
       
   346 		with a valid range 1..16 (interrupt and isochronous), or directly as the
       
   347 		maximum NAK rate with a valid range 0..255 (control and bulk).
       
   348 	*/
       
   349 	TInt iInterval_Hs;
       
   350 	/** The number of additional transactions per uframe to be scheduled (0..2)
       
   351 		(A value greater than zero is only valid for high-speed high bandwidth
       
   352 		 interrupt and isochronous endpoints. Also note that there are endpoint size
       
   353 		 restrictions associated with additional transactions - see 9.6.6.)
       
   354 	*/
       
   355 	TInt iTransactions;
       
   356 	/** The number of extra bytes that the standard endpoint descriptor should be extended by.
       
   357 		In almost all cases, this should be 0 (zero).
       
   358 	*/
       
   359 	TInt iExtra;
       
   360 	/** 32 flag bits indicating miscellaneous endpoint features.
       
   361 		Currently defined are:
       
   362 		- KUsbcEndpointInfoFeatureWord1_DMA             = 0x00000001
       
   363 		- KUsbcEndpointInfoFeatureWord1_DoubleBuffering = 0x00000002
       
   364 	*/
       
   365 	TUint32 iFeatureWord1;
       
   366 	/** Reserved for future use. */
       
   367 	TUint32 iReserved;
       
   368 	};
       
   369 
       
   370 /** USB Class information used in RDevUsbcClient::SetInterface().
       
   371 */
       
   372 class TUsbcClassInfo
       
   373 	{
       
   374 public:
       
   375 	TUsbcClassInfo(TInt aClass=0, TInt aSubClass=0, TInt aProtocol=0);
       
   376 public:
       
   377 	/** The class type number. */
       
   378 	TInt iClassNum;
       
   379 	/** The sub-class type number. */
       
   380 	TInt iSubClassNum;
       
   381 	/** The protocol number. */
       
   382 	TInt iProtocolNum;
       
   383 	/** Reserved for future use. */
       
   384 	TUint32 iReserved;
       
   385 	};
       
   386 
       
   387 
       
   388 /** The Ep0 Setup request 'unsubscribe' flag; used by
       
   389 	TUsbcInterfaceInfo::iFeatureWord. When this bit is set then valid vendor-
       
   390 	or class-specific Ep0 requests addressed to this interface or any of its
       
   391 	endpoints will be stalled by the USB PDD PIL.
       
   392 
       
   393 	@see TUsbcInterfaceInfo
       
   394 */
       
   395 const TUint KUsbcInterfaceInfo_NoEp0RequestsPlease = 0x00000001;
       
   396 
       
   397 #include <d32usbcshared.inl>
       
   398 
       
   399 #endif