First public contribution.
1 // Copyright (c) 2000-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\include\drivers\usbcshared.h
15 // Kernel side definitions for the USB Device driver stack (PIL + LDD).
24 #ifndef __USBCSHARED_H__
25 #define __USBCSHARED_H__
27 #include <drivers/usbcque.h>
29 // Define here what options are required:
30 // (USB_SUPPORTS_CONTROLENDPOINTS and USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
31 // have never been tested though...)
32 //#define USB_SUPPORTS_CONTROLENDPOINTS
33 //#define USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
35 #include <drivers/usbcdesc.h>
39 // Use for debugging purposes only (commented out for normal operation):
40 //#define USBC_LDD_BUFFER_TRACE
42 static const char KUsbPILPanicCat[] = "USB PIL FAULT"; // kernel fault category
43 _LIT(KUsbPILKillCat, "USB PIL KILL"); // thread kill category
44 _LIT(KUsbLDDKillCat, "USB LDD KILL"); // thread kill category
46 /** Error code for stalled endpoint.
48 const TInt KErrEndpointStall = KErrLocked;
50 /** Error code for Ep0 write prematurely ended by a host OUT token.
52 const TInt KErrPrematureEnd = KErrDiskFull;
54 /** The following constants control the buffer arrangement for OUT transfers (IN transfers have only 1
55 buffer). The total size of buffering for an OUT endpoint will be number of buffers * buffersize,
56 so that, for example, a Bulk OUT endpoint will have KUsbcDmaBufNumBulk * KUsbcDmaBufSzBulk bytes of
58 These buffers will be physically contiguous, so that DMA may be used.
59 The number of buffers MUST be >=2 - otherwise the buffering scheme won't work.
60 The buffer sizes should be an exact fraction of 4kB and the number of buffers such that the
61 buffersize * number of buffers is an exact multiple of 4kB, otherwise memory will be wasted.
63 /** Size of a Control ep buffer.
65 const TInt KUsbcDmaBufSzControl = 1024;
67 /** Size of a Bulk ep buffer.
69 const TInt KUsbcDmaBufSzBulk = 4096;
71 /** Size of an Interrupt ep buffer.
73 const TInt KUsbcDmaBufSzInterrupt = 4096;
75 /** Size of an Isochronous ep buffer.
77 const TInt KUsbcDmaBufSzIsochronous = 4096;
79 /** Number of buffers for Control OUT endpoints.
81 const TInt KUsbcDmaBufNumControl = 2;
83 /** Number of buffers for Isochronous OUT endpoints.
85 const TInt KUsbcDmaBufNumIsochronous = 2;
87 /** Number of buffers for Bulk OUT endpoints.
89 const TInt KUsbcDmaBufNumBulk = 2;
91 /** Number of buffers for Interrupt OUT endpoints.
93 const TInt KUsbcDmaBufNumInterrupt = 2;
95 /** Maximum buffer number.
97 const TInt KUsbcDmaBufNumMax = MAX4(KUsbcDmaBufNumControl, KUsbcDmaBufNumIsochronous,
98 KUsbcDmaBufNumBulk, KUsbcDmaBufNumInterrupt);
100 /** Maximum number of recorded packets possible.
102 const TUint KUsbcDmaBufMaxPkts = 2;
104 /** Number of arrays.
106 const TInt KUsbcDmaBufNumArrays = 2;
108 /** Max size that Ep0 packets might have.
110 const TInt KUsbcBufSzControl = 64;
112 /** The Ep0 RX data collection buffer area.
113 (Arbitrary size, judged to be sufficient for SET_DESCRIPTOR requests)
115 const TInt KUsbcBufSz_Ep0Rx = 1024;
117 /** The Ep0 TX buffer area.
118 (Size sufficient to hold as much data as can be requested via GET_DESCRIPTOR)
120 const TInt KUsbcBufSz_Ep0Tx = 1024 * 64;
123 /** The USB version the stack is compliant with: 2.0 (BCD).
125 const TUint16 KUsbcUsbVersion = 0x0200;
127 /** Maximum number of endpoints an interface (i.e. LDD) may have.
129 const TInt KUsbcMaxEpNumber = 5;
131 /** Status FIFO depth; enough for 2 complete configs.
133 const TInt KUsbDeviceStatusQueueDepth = 15;
135 /** = 'no status info'.
137 const TUint32 KUsbDeviceStatusNull = 0xffffffffu;
139 /** = 'no buffer available'.
141 const TInt KUsbcInvalidBufferIndex = -1;
143 /** = 'no packet available'.
145 const TUint KUsbcInvalidPacketIndex = (TUint)(-1);
147 /** = 'no drainable buffers'.
149 const TInt KUsbcInvalidDrainQueueIndex = -1;
151 /** Number of possible bandwidth priorities.
153 const TInt KUsbcDmaBufMaxPriorities = 4;
155 // The following buffer sizes are used within the LDD for the different
156 // user-selectable endpoint bandwidth priorities
157 // (EUsbcBandwidthOUTDefault/Plus1/Plus2/Maximum + the same for 'IN').
158 // These values, in particular those for the Maximum setting, were obtained
161 /** Bulk IN buffer sizes for different priorities (4K, 16K, 64K, 512K).
163 const TInt KUsbcDmaBufSizesBulkIN[KUsbcDmaBufMaxPriorities] =
164 {KUsbcDmaBufSzBulk, 0x4000, 0x10000, 0x80000};
166 /** Bulk OUT buffer sizes for different priorities (4K, 16K, 64K, 512K).
168 const TInt KUsbcDmaBufSizesBulkOUT[KUsbcDmaBufMaxPriorities] =
169 {KUsbcDmaBufSzBulk, 0x4000, 0x10000, 0x80000};
171 /** Number of UDCs supported in the system.
172 (Support for more than one UDC is preliminary.)
174 const TInt KUsbcMaxUdcs = 2;
176 /** Number of endpoints a USB device can have.
177 (30 regular endpoints + 2 x Ep0)
179 const TInt KUsbcEpArraySize = KUsbcMaxEndpoints + 2;
181 /** Number of notification requests of the same kind that can be registered at
182 a time. As normally not more than one request per kind per LDD is
183 permitted, this number is roughly equivalent to the maximum number of LDDs
184 that can be operating at the same time.
185 This constant is used by the PIL while maintaining its request lists
186 (iClientCallbacks, iStatusCallbacks, iEpStatusCallbacks, iOtgCallbacks) to
187 ensure that the lists are of a finite length and thus the list traverse
189 This value is chosen with the maximum number of USB interfaces (not
190 settings) allowed by the spec for a single device in mind.
192 const TInt KUsbcMaxListLength = 256;
196 typedef TUint32 TUsbcPacketArray;
199 /** Used as a return value from DUsbClientController::EnquireEp0NextState(),
200 the purpose of which is to enable the PSL to find out what the next stage
201 will be for a newly received Setup packet.
203 The enum values are self-explanatory.
216 /** Used to show the direction of a transfer request to the Controller.
218 @see TUsbcRequestCallback
220 enum TTransferDirection {EControllerNone, EControllerRead, EControllerWrite};
223 /** These event codes are used by the PSL to tell the PIL what has happened.
228 enum TUsbcDeviceEvent
230 /** The USB Suspend bus state has been detected. */
232 /** USB Resume signalling has been detected. */
234 /** A USB Reset condition has been detected. */
236 /** Physical removal of the USB cable has been detected. */
237 EUsbEventCableRemoved,
238 /** Physical insertion of the USB cable has been detected. */
239 EUsbEventCableInserted
243 /** USB LDD client callback.
245 class TUsbcClientCallback
248 inline TUsbcClientCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
249 inline DBase* Owner() const;
250 inline TInt DoCallback();
251 inline void Cancel();
252 inline void SetDfcQ(TDfcQue* aDfcQ);
254 /** Used by the PIL to queue callback objects into a TSglQue. */
262 /** The endpoint halt/clear_halt status.
264 class TUsbcEndpointStatusCallback
267 inline TUsbcEndpointStatusCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
268 inline void SetState(TUint aState);
269 inline TUint State() const;
270 inline DBase* Owner() const;
271 inline TInt DoCallback();
272 inline void Cancel();
273 inline void SetDfcQ(TDfcQue* aDfcQ);
275 /** Used by the PIL to queue callback objects into a TSglQue. */
284 /** Maximum number of device status requests that can be queued at a time.
285 The value chosen is thought to be sufficient in all situations.
287 const TInt KUsbcDeviceStateRequests = 8;
290 /** The USB device status.
292 class TUsbcStatusCallback
295 inline TUsbcStatusCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
296 inline void SetState(TUsbcDeviceState aState);
297 inline TUsbcDeviceState State(TInt aIndex) const;
298 inline void ResetState();
299 inline DBase* Owner() const;
300 inline TInt DoCallback();
301 inline void Cancel();
302 inline void SetDfcQ(TDfcQue* aDfcQ);
304 /** Used by the PIL to queue callback objects into a TSglQue. */
309 TUsbcDeviceState iState[KUsbcDeviceStateRequests];
313 /** A USB transfer request.
318 class TUsbcRequestCallback
321 /** @internalTechnology */
322 inline TUsbcRequestCallback(const DBase* aOwner, TInt aEndpointNum, TDfcFn aDfcFunc,
323 TAny* aEndpoint, TDfcQue* aDfcQ, TInt aPriority);
324 /** @internalTechnology */
325 inline ~TUsbcRequestCallback();
326 /** @internalTechnology */
327 inline void SetRxBufferInfo(TUint8* aBufferStart, TPhysAddr aBufferAddr,
328 TUsbcPacketArray* aPacketIndex, TUsbcPacketArray* aPacketSize,
330 /** @internalTechnology */
331 inline void SetTxBufferInfo(TUint8* aBufferStart, TPhysAddr aBufferAddr, TInt aLength);
332 /** @internalTechnology */
333 inline void SetTransferDirection(TTransferDirection aTransferDir);
334 /** @internalTechnology */
335 inline const DBase* Owner() const;
336 /** @internalTechnology */
337 inline TInt DoCallback();
338 /** @internalTechnology */
339 inline void Cancel();
341 /** Used by the PIL to queue callback objects into a TSglQue.
346 /** The endpoint number. */
347 const TInt iEndpointNum;
348 /** The 'real' endpoint number, as used by the PDD. */
350 /** Indicates the LDD client for this transfer. */
351 const DBase* const iOwner;
352 /** DFC, used by PIL to call back the LDD when transfer completes to the LDD. */
354 /** Direction of transfer request. */
355 TTransferDirection iTransferDir;
356 /** Start address of this buffer. */
357 TUint8* iBufferStart;
358 /** Physical address of buffer start (used for DMA). */
359 TPhysAddr iBufferAddr;
360 /** Array of pointers into iBufferStart (actually TUsbcPacketArray (*)[]). */
361 TUsbcPacketArray* iPacketIndex;
362 /** Array of packet sizes (actually TUsbcPacketArray (*)[]). */
363 TUsbcPacketArray* iPacketSize;
364 /** Length in bytes of buffer (iBufferStart). */
366 /** For IN transfers, if a zlp might be required at the end of this transfer. */
368 /** Number of bytes transmitted; changed by the PSL. */
370 /** Number of packets received (if it is a read); changed by the PSL. */
372 /** The error code upon completion of the request; changed by the PSL. */
376 /** USB On-The-Go feature change callback.
378 class TUsbcOtgFeatureCallback
381 inline TUsbcOtgFeatureCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
382 inline void SetFeatures(TUint8 aFeatures);
383 inline TUint8 Features() const;
384 inline DBase* Owner() const;
385 inline TInt DoCallback();
386 inline void Cancel();
387 inline void SetDfcQ(TDfcQue* aDfcQ);
389 /** Used by the PIL to queue callback objects into a TSglQue. */
398 //########################### Physical Device Driver (PIL + PSL) ######################
401 class TUsbcLogicalEndpoint;
403 /** This models a physical (real) endpoint of the UDC.
405 class TUsbcPhysicalEndpoint
408 TUsbcPhysicalEndpoint();
409 ~TUsbcPhysicalEndpoint();
410 TBool EndpointSuitable(const TUsbcEndpointInfo* aEpInfo, TInt aIfcNumber) const; // Check Todo, SC will pass pointer to derived class
411 TInt TypeAvailable(TUint aType) const;
412 TInt DirAvailable(TUint aDir) const;
414 /** This endpoint's capabilities. */
415 TUsbcEndpointCaps iCaps;
416 /** USB address: 0x00, 0x80, 0x01, 0x81, etc. */
417 TUint8 iEndpointAddr;
418 /** Pointer to interface # this endpoint has been assigned to. */
419 const TUint8* iIfcNumber;
420 /** Pointer to corresponding logical endpoint or NULL. */
421 const TUsbcLogicalEndpoint* iLEndpoint;
422 /** Only used when searching for available endpoints. */
423 TBool iSettingReserve;
424 /** True if endpoint is halted (i.e. issues STALL handshakes), false otherwise. */
429 class DUsbClientController;
430 class TUsbcInterface;
432 /** This is a 'logical' endpoint, as used by our device configuration model.
434 class TUsbcLogicalEndpoint
437 TUsbcLogicalEndpoint(DUsbClientController* aController, TUint aEndpointNum,
438 const TUsbcEndpointInfo& aEpInfo, TUsbcInterface* aInterface,
439 TUsbcPhysicalEndpoint* aPEndpoint); // Check Todo, SC will pass pointer to derived class
440 ~TUsbcLogicalEndpoint();
442 /** Pointer to controller object. */
443 DUsbClientController* iController;
444 /** The virtual (logical) endpoint number. */
445 const TInt iLEndpointNum;
446 /** This endpoint's info structure. */
447 TUsbcEndpointInfo iInfo; // Check Todo, SC will pass pointer to derived class
448 /** Stores the endpoint size to be used for FS. */
450 /** Stores the endpoint size to be used for HS. */
452 /** 'Back' pointer. */
453 const TUsbcInterface* iInterface;
454 /** Pointer to corresponding physical endpoint, never NULL. */
455 TUsbcPhysicalEndpoint* const iPEndpoint;
459 class TUsbcInterfaceSet;
461 /** This is an 'alternate setting' of an interface.
466 TUsbcInterface(TUsbcInterfaceSet* aIfcSet, TUint8 aSetting, TBool aNoEp0Requests);
469 /** Array of endpoints making up (belonging to) this setting. */
470 RPointerArray<TUsbcLogicalEndpoint> iEndpoints;
471 /** 'Back' pointer. */
472 TUsbcInterfaceSet* const iInterfaceSet;
473 /** bAlternateSetting (zero-based). */
474 const TUint8 iSettingCode;
475 /** KUsbcInterfaceInfo_NoEp0RequestsPlease: stall non-std Setup requests. */
476 const TBool iNoEp0Requests;
480 /** This is an 'interface' (owning 1 or more alternate settings).
484 class TUsbcInterfaceSet
487 TUsbcInterfaceSet(const DBase* aClientId, TUint8 aIfcNum);
488 ~TUsbcInterfaceSet();
489 inline const TUsbcInterface* CurrentInterface() const;
490 inline TUsbcInterface* CurrentInterface();
492 /** Array of alternate settings provided by (belonging to) this interface. */
493 RPointerArray<TUsbcInterface> iInterfaces;
494 /** Pointer to the LDD which created and owns this interface. */
495 const DBase* const iClientId;
496 /** bInterfaceNumber (zero-based). */
497 TUint8 iInterfaceNumber;
498 /** bAlternateSetting (zero-based). */
499 TUint8 iCurrentInterface;
503 /** This is a 'configuration' of the USB device.
504 Currently we support only one configuration.
506 class TUsbcConfiguration
509 TUsbcConfiguration(TUint8 aConfigVal);
510 ~TUsbcConfiguration();
512 /** Array of interfaces making up (belonging to) this configuration. */
513 RPointerArray<TUsbcInterfaceSet> iInterfaceSets;
514 /** bConfigurationValue (one-based). */
515 const TUint8 iConfigValue;
519 /** A USB Setup packet.
521 Used mainly internally by the PIL but also by
522 DUsbClientController::ProcessSetConfiguration(const TUsbcSetup&),
523 which is classified as publishedPartner.
525 @publishedPartner @released
542 /** The USB controller's power handler class.
544 class DUsbcPowerHandler : public DPowerHandler
548 void PowerDown(TPowerState);
550 DUsbcPowerHandler(DUsbClientController* aController);
552 DUsbClientController* iController;
557 This is the EndpointInfo class used by the usb shared chunk client driver.
560 class TUsbcScEndpointInfo;
564 Used to represent an array of (or inheriting from) TUsbcEndpointInfo objects.
566 @see DUsbClientController::SetInterface
569 class TUsbcEndpointInfoArray
572 typedef enum {EUsbcEndpointInfo, EUsbcScEndpointInfo} TArrayType;
574 TUsbcEndpointInfoArray(const TUsbcEndpointInfo* aData, TInt aDataSize=0);
575 TUsbcEndpointInfoArray(const TUsbcScEndpointInfo* aData, TInt aDataSize=0);
576 inline TUsbcEndpointInfo& operator[](TInt aIndex) const;
584 class TUsbcRequestCallback; // todo?? required only for class below
586 /** The USB Device software controller class.
588 Implements the platform-independent layer (PIL), and defines the interface to the
589 platform-specific layer PSL).
591 The implementation of the platform-specific layer interfaces with the hardware.
593 class DUsbClientController : public DBase
595 friend class DUsbcPowerHandler;
596 friend TUsbcLogicalEndpoint::~TUsbcLogicalEndpoint();
598 // --- Platform Independent Layer (PIL) ---
604 // --- The following functions constitute the PIL interface to the LDD ---
607 virtual ~DUsbClientController();
608 IMPORT_C void DisableClientStack();
609 IMPORT_C void EnableClientStack();
610 IMPORT_C TBool IsActive();
611 IMPORT_C TInt RegisterClientCallback(TUsbcClientCallback& aCallback);
612 IMPORT_C static DUsbClientController* UsbcControllerPointer(TInt aUdc=0);
613 IMPORT_C void EndpointCaps(const DBase* aClientId, TDes8 &aCapsBuf) const;
614 IMPORT_C void DeviceCaps(const DBase* aClientId, TDes8 &aCapsBuf) const;
615 IMPORT_C TInt SetInterface(const DBase* aClientId, DThread* aThread, TInt aInterfaceNum,
616 TUsbcClassInfo& aClass, TDesC8* aString, TInt aTotalEndpointsUsed,
617 const TUsbcEndpointInfo aEndpointData[], TInt (*aRealEpNumbers)[6],
618 TUint32 aFeatureWord);
619 IMPORT_C TInt SetInterface(const DBase* aClientId, DThread* aThread,
620 TInt aInterfaceNum, TUsbcClassInfo& aClass,
621 TDesC8* aString, TInt aTotalEndpointsUsed,
622 const TUsbcEndpointInfoArray aEndpointData,
623 TInt aRealEpNumbers[], TUint32 aFeatureWord);
624 IMPORT_C TInt ReleaseInterface(const DBase* aClientId, TInt aInterfaceNum);
625 IMPORT_C TInt ReEnumerate();
626 IMPORT_C TInt PowerUpUdc();
627 IMPORT_C TInt UsbConnect();
628 IMPORT_C TInt UsbDisconnect();
629 IMPORT_C TInt RegisterForStatusChange(TUsbcStatusCallback& aCallback);
630 IMPORT_C TInt DeRegisterForStatusChange(const DBase* aClientId);
631 IMPORT_C TInt RegisterForEndpointStatusChange(TUsbcEndpointStatusCallback& aCallback);
632 IMPORT_C TInt DeRegisterForEndpointStatusChange(const DBase* aClientId);
633 IMPORT_C TInt GetInterfaceNumber(const DBase* aClientId, TInt& aInterfaceNum) const;
634 IMPORT_C TInt DeRegisterClient(const DBase* aClientId);
635 IMPORT_C TInt Ep0PacketSize() const;
636 IMPORT_C TInt Ep0Stall(const DBase* aClientId);
637 IMPORT_C void SendEp0StatusPacket(const DBase* aClientId);
638 IMPORT_C TUsbcDeviceState GetDeviceStatus() const;
639 IMPORT_C TEndpointState GetEndpointStatus(const DBase* aClientId, TInt aEndpointNum) const;
640 IMPORT_C TInt SetupReadBuffer(TUsbcRequestCallback& aCallback);
641 IMPORT_C TInt SetupWriteBuffer(TUsbcRequestCallback& aCallback);
642 IMPORT_C void CancelReadBuffer(const DBase* aClientId, TInt aRealEndpoint);
643 IMPORT_C void CancelWriteBuffer(const DBase* aClientId, TInt aRealEndpoint);
644 IMPORT_C TInt HaltEndpoint(const DBase* aClientId, TInt aEndpointNum);
645 IMPORT_C TInt ClearHaltEndpoint(const DBase* aClientId, TInt aEndpointNum);
646 IMPORT_C TInt SetDeviceControl(const DBase* aClientId);
647 IMPORT_C TInt ReleaseDeviceControl(const DBase* aClientId);
648 IMPORT_C TUint EndpointZeroMaxPacketSizes() const;
649 IMPORT_C TInt SetEndpointZeroMaxPacketSize(TInt aMaxPacketSize);
650 IMPORT_C TInt GetDeviceDescriptor(DThread* aThread, TDes8& aDeviceDescriptor);
651 IMPORT_C TInt SetDeviceDescriptor(DThread* aThread, const TDes8& aDeviceDescriptor);
652 IMPORT_C TInt GetDeviceDescriptorSize(DThread* aThread, TDes8& aSize);
653 IMPORT_C TInt GetConfigurationDescriptor(DThread* aThread, TDes8& aConfigurationDescriptor);
654 IMPORT_C TInt SetConfigurationDescriptor(DThread* aThread, const TDes8& aConfigurationDescriptor);
655 IMPORT_C TInt GetConfigurationDescriptorSize(DThread* aThread, TDes8& aSize);
656 IMPORT_C TInt SetOtgDescriptor(DThread* aThread, const TDesC8& aOtgDesc);
657 IMPORT_C TInt GetOtgDescriptor(DThread* aThread, TDes8& aOtgDesc) const;
658 IMPORT_C TInt GetOtgFeatures(DThread* aThread, TDes8& aFeatures) const;
659 IMPORT_C TInt GetCurrentOtgFeatures(TUint8& aFeatures) const;
660 IMPORT_C TInt RegisterForOtgFeatureChange(TUsbcOtgFeatureCallback& aCallback);
661 IMPORT_C TInt DeRegisterForOtgFeatureChange(const DBase* aClientId);
662 IMPORT_C TInt GetInterfaceDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
663 TDes8& aInterfaceDescriptor);
664 IMPORT_C TInt SetInterfaceDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
665 const TDes8& aInterfaceDescriptor);
666 IMPORT_C TInt GetInterfaceDescriptorSize(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
668 IMPORT_C TInt GetEndpointDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
669 TInt aEndpointNum, TDes8& aEndpointDescriptor);
670 IMPORT_C TInt SetEndpointDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
671 TInt aEndpointNum, const TDes8& aEndpointDescriptor);
672 IMPORT_C TInt GetEndpointDescriptorSize(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
673 TInt aEndpointNum, TDes8& aSize);
674 IMPORT_C TInt GetDeviceQualifierDescriptor(DThread* aThread, TDes8& aDeviceQualifierDescriptor);
675 IMPORT_C TInt SetDeviceQualifierDescriptor(DThread* aThread, const TDes8& aDeviceQualifierDescriptor);
676 IMPORT_C TInt GetOtherSpeedConfigurationDescriptor(DThread* aThread, TDes8& aConfigurationDescriptor);
677 IMPORT_C TInt SetOtherSpeedConfigurationDescriptor(DThread* aThread, const TDes8& aConfigurationDescriptor);
678 IMPORT_C TInt GetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
679 TDes8& aInterfaceDescriptor);
680 IMPORT_C TInt SetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
681 const TDes8& aInterfaceDescriptor, TInt aSize);
682 IMPORT_C TInt GetCSInterfaceDescriptorBlockSize(DThread* aThread, const DBase* aClientId,
683 TInt aSettingNum, TDes8& aSize);
684 IMPORT_C TInt GetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
685 TInt aEndpointNum, TDes8& aEndpointDescriptor);
686 IMPORT_C TInt SetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
687 TInt aEndpointNum, const TDes8& aEndpointDescriptor,
689 IMPORT_C TInt GetCSEndpointDescriptorBlockSize(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
690 TInt aEndpointNum, TDes8& aSize);
691 IMPORT_C TInt GetStringDescriptorLangId(DThread* aThread, TDes8& aLangId);
692 IMPORT_C TInt SetStringDescriptorLangId(TUint16 aLangId);
693 IMPORT_C TInt GetManufacturerStringDescriptor(DThread* aThread, TDes8& aString);
694 IMPORT_C TInt SetManufacturerStringDescriptor(DThread* aThread, const TDes8& aString);
695 IMPORT_C TInt RemoveManufacturerStringDescriptor();
696 IMPORT_C TInt GetProductStringDescriptor(DThread* aThread, TDes8& aString);
697 IMPORT_C TInt SetProductStringDescriptor(DThread* aThread, const TDes8& aString);
698 IMPORT_C TInt RemoveProductStringDescriptor();
699 IMPORT_C TInt GetSerialNumberStringDescriptor(DThread* aThread, TDes8& aString);
700 IMPORT_C TInt SetSerialNumberStringDescriptor(DThread* aThread, const TDes8& aString);
701 IMPORT_C TInt RemoveSerialNumberStringDescriptor();
702 IMPORT_C TInt GetConfigurationStringDescriptor(DThread* aThread, TDes8& aString);
703 IMPORT_C TInt SetConfigurationStringDescriptor(DThread* aThread, const TDes8& aString);
704 IMPORT_C TInt RemoveConfigurationStringDescriptor();
705 IMPORT_C TInt GetStringDescriptor(DThread* aThread, TUint8 aIndex, TDes8& aString);
706 IMPORT_C TInt SetStringDescriptor(DThread* aThread, TUint8 aIndex, const TDes8& aString);
707 IMPORT_C TInt RemoveStringDescriptor(TUint8 aIndex);
708 IMPORT_C TInt AllocateEndpointResource(const DBase* aClientId, TInt aEndpointNum,
709 TUsbcEndpointResource aResource);
710 IMPORT_C TInt DeAllocateEndpointResource(const DBase* aClientId, TInt aEndpointNum,
711 TUsbcEndpointResource aResource);
712 IMPORT_C TBool QueryEndpointResource(const DBase* aClientId, TInt aEndpointNum,
713 TUsbcEndpointResource aResource);
714 IMPORT_C TInt EndpointPacketSize(const DBase* aClientId, TInt aEndpointNum);
717 // --- Public (pure) virtual (implemented by PSL, used by LDD) ---
720 /** Forces the UDC into a non-idle state to perform a USB remote wakeup operation.
722 The PSL should first check the current value of iRmWakeupStatus_Enabled
723 to determine whether or not to actually send a Remote Wakeup.
725 @see iRmWakeupStatus_Enabled
727 @return KErrGeneral if Remote Wakeup feature is not enabled or an error is encountered,
730 @publishedPartner @released
732 IMPORT_C virtual TInt SignalRemoteWakeup() =0;
734 /** Dumps the contents of (all or part of) the UDC registers to the serial console.
735 This is for debugging purposes only.
737 @publishedPartner @released
739 IMPORT_C virtual void DumpRegisters() =0;
741 /** Returns a pointer to the DFC queue that should be used by the USB LDD.
743 @return A pointer to the DFC queue that should be used by the USB LDD.
745 @publishedPartner @released
747 IMPORT_C virtual TDfcQue* DfcQ(TInt aUnit) =0;
749 /** Returns information about the current operating speed of the UDC.
751 (Function is not 'pure virtual' for backwards compatibility with existing USB PSLs.
752 The default implementation in the PIL returns EFalse.)
754 @return ETrue if the UDC is currently operating at High speed, EFalse
755 otherwise (i.e. controller is operating at Full speed).
757 @publishedPartner @released
759 IMPORT_C virtual TBool CurrentlyUsingHighSpeed();
762 // --- Public PIL functions ---
765 DUsbClientController* RegisterUdc(TInt aUdc);
770 // --- Functions and data members provided by PIL, called by PSL ---
773 TBool InitialiseBaseClass(TUsbcDeviceDescriptor* aDeviceDesc,
774 TUsbcConfigDescriptor* aConfigDesc,
775 TUsbcLangIdDescriptor* aLangId,
776 TUsbcStringDescriptor* aManufacturer =0,
777 TUsbcStringDescriptor* aProduct =0,
778 TUsbcStringDescriptor* aSerialNum =0,
779 TUsbcStringDescriptor* aConfig =0,
780 TUsbcOtgDescriptor* aOtgDesc =0);
781 DUsbClientController();
782 TInt DeviceEventNotification(TUsbcDeviceEvent aEvent);
783 void EndpointRequestComplete(TUsbcRequestCallback* aCallback);
784 TInt Ep0RequestComplete(TInt aRealEndpoint, TInt aCount, TInt aError);
785 void MoveToAddressState();
786 void SetCurrent(TInt aCurrent);
787 TUsbcEp0State EnquireEp0NextState(const TUint8* aSetupBuf) const;
788 TInt ProcessSetConfiguration(const TUsbcSetup& aPacket);
789 void HandleHnpRequest(TInt aHnpState);
791 /** This info can be used by the PSL before sending ZLPs.
793 @publishedPartner @released
795 TBool iEp0ReceivedNonStdRequest;
797 /** True if RMW is currently enabled (set by either PIL or PSL).
799 @publishedPartner @released
801 TBool iRmWakeupStatus_Enabled;
803 /** Ep0 incoming (rx) data is placed here (one packet).
805 @publishedPartner @released
807 TUint8 iEp0_RxBuf[KUsbcBufSzControl];
812 // --- Platform Specific Layer (PSL) ---
815 /** This function will be called by the PIL upon decoding a SET_ADDRESS request.
817 UDCs which require a manual setting of the USB device address should do that in this function.
819 @param aAddress A valid USB device address that was received with the SET_ADDRESS request.
821 @return KErrNone if address was set successfully or if this UDC's address cannot be set manually,
822 KErrGeneral otherwise.
824 @publishedPartner @released
826 virtual TInt SetDeviceAddress(TInt aAddress) =0;
828 /** Configures (enables) an endpoint (incl. Ep0) for data transmission or reception.
830 @param aRealEndpoint The number of the endpoint to be enabled.
831 @param aEndpointInfo A reference to a properly filled-in endpoint info structure.
833 @return KErrArgument if endpoint number or endpoint info invalid, KErrNone if endpoint
834 successfully configured, KErrGeneral otherwise.
836 @publishedPartner @released
838 virtual TInt ConfigureEndpoint(TInt aRealEndpoint, const TUsbcEndpointInfo& aEndpointInfo) =0;
840 /** De-configures (disables) an endpoint (incl. Ep0).
842 @param aRealEndpoint The number of the endpoint to be disabled.
844 @return KErrArgument if endpoint number invalid, KErrNone if endpoint successfully de-configured,
845 KErrGeneral otherwise.
847 @publishedPartner @released
849 virtual TInt DeConfigureEndpoint(TInt aRealEndpoint) =0;
851 /** Allocates an endpoint resource.
853 If the resource gets successfully allocated, it will be used from when the current bus transfer
856 @param aRealEndpoint The number of the endpoint.
857 @param aResource The endpoint resource to be allocated.
859 @return KErrNone if the resource has been successfully allocated, KErrNotSupported if the endpoint
860 does not support the resource requested, and KErrInUse if the resource is already consumed and
863 @publishedPartner @deprecated
865 virtual TInt AllocateEndpointResource(TInt aRealEndpoint, TUsbcEndpointResource aResource) =0;
867 /** Deallocates (frees) an endpoint resource.
869 The resource will be removed from when the current bus transfer has been completed.
871 @param aRealEndpoint The number of the endpoint.
872 @param aResource The endpoint resource to be deallocated.
874 @return KErrNone if the resource has been successfully deallocated, KErrNotSupported if the endpoint
875 does not support the resource requested.
877 @publishedPartner @deprecated
879 virtual TInt DeAllocateEndpointResource(TInt aRealEndpoint, TUsbcEndpointResource aResource) =0;
881 /** Queries the use of and endpoint resource.
883 @param aRealEndpoint The number of the endpoint.
884 @param aResource The endpoint resource to be queried.
886 @return ETrue if the specified resource is in use at the endpoint, EFalse if not.
888 @publishedPartner @released
890 virtual TBool QueryEndpointResource(TInt aRealEndpoint, TUsbcEndpointResource aResource) const =0;
892 /** Opens a DMA channel (if possible).
894 @param aRealEndpoint The number of the endpoint for which to open the DMA channel.
896 @return KErrArgument if endpoint number invalid, KErrNone if channel successfully opened or if
897 endpoint not DMA-capable, KErrGeneral otherwise.
899 @publishedPartner @released
901 virtual TInt OpenDmaChannel(TInt aRealEndpoint);
903 /** Closes a DMA channel (if possible).
905 @param aRealEndpoint The number of the endpoint for which to close the DMA channel.
907 @publishedPartner @released
909 virtual void CloseDmaChannel(TInt aRealEndpoint);
911 /** Sets up a read request on an endpoint (excl. Ep0) for data reception.
913 For endpoint 0 read requests, SetupEndpointZeroRead() is used instead.
915 @param aRealEndpoint The number of the endpoint to be used.
916 @param aCallback A reference to a properly filled-in request callback structure.
918 @return KErrArgument if endpoint number invalid, KErrNone if read successfully set up,
919 KErrGeneral otherwise.
921 @publishedPartner @released
923 virtual TInt SetupEndpointRead(TInt aRealEndpoint, TUsbcRequestCallback& aCallback) =0;
925 /** Sets up a write request on an endpoint (excl. Ep0) for data transmission.
927 For endpoint 0 write requests, SetupEndpointZeroWrite() is used instead.
929 @param aRealEndpoint The number of the endpoint to be used.
930 @param aCallback A reference to a properly filled-in request callback structure.
932 @return KErrArgument if endpoint number invalid, KErrNone if write successfully set up,
933 KErrGeneral otherwise.
935 @publishedPartner @released
937 virtual TInt SetupEndpointWrite(TInt aRealEndpoint, TUsbcRequestCallback& aCallback) =0;
939 /** Cancels a read request on an endpoint (excl. Ep0).
941 Note that endpoint 0 read requests are never cancelled by the PIL, so
942 there is also no CancelEndpointZeroRead() function.
944 @param aRealEndpoint The number of the endpoint to be used.
946 @return KErrArgument if endpoint number invalid, KErrNone if read successfully cancelled,
947 KErrGeneral otherwise.
949 @publishedPartner @released
951 virtual TInt CancelEndpointRead(TInt aRealEndpoint) =0;
953 /** Cancels a write request on an endpoint (incl. Ep0).
955 The PIL calls this function also to cancel endpoint zero write requests.
957 @param aRealEndpoint The number of the endpoint to be used.
959 @return KErrArgument if endpoint number invalid, KErrNone if write successfully cancelled,
960 KErrGeneral otherwise.
962 @publishedPartner @released
964 virtual TInt CancelEndpointWrite(TInt aRealEndpoint) =0;
966 /** Same as SetupEndpointRead(), but for endpoint zero only.
968 No callback is used here as this function is only used internally by the PIL and no user side request
969 exists for it. The data buffer to be used (filled) is iEp0_RxBuf.
971 @return KErrGeneral if (&iEndpoints[KEp0_Out]->iRxBuf != NULL) or some other error occurs,
972 KErrNone if read successfully set up.
974 @publishedPartner @released
976 virtual TInt SetupEndpointZeroRead() =0;
978 /** Same as SetupEndpointWrite(), but for endpoint zero only.
980 No callback is used here as this function is only used internally by the PIL and no user side request
983 @param aBuffer This points to the beginning of the data to be sent.
984 @param aLength The number of bytes to be sent.
985 @param aZlpReqd ETrue if a zero-length packet (ZLP) is to be sent after the data.
987 @return KErrGeneral if (&iEndpoints[KEp0_In]->iTxBuf != NULL) or some other error occurs,
988 KErrNone if write successfully set up.
990 @publishedPartner @released
992 virtual TInt SetupEndpointZeroWrite(const TUint8* aBuffer, TInt aLength, TBool aZlpReqd=EFalse) =0;
994 /** Sets up on Ep0 the transmission of a single zero-length packet (ZLP).
996 @return KErrNone if ZLP successfully set up, KErrGeneral otherwise..
998 @publishedPartner @released
1000 virtual TInt SendEp0ZeroByteStatusPacket() =0;
1002 /** Stalls an endpoint (incl. Ep0).
1004 Isochronous endpoints cannot be stalled.
1006 @param aRealEndpoint The number of the endpoint to be stalled.
1008 @return KErrArgument if endpoint number invalid, KErrNone if endpoint successfully stalled,
1009 KErrGeneral otherwise.
1011 @publishedPartner @released
1013 virtual TInt StallEndpoint(TInt aRealEndpoint) =0;
1015 /** Clears the stall condition on an endpoint (incl. Ep0).
1017 Isochronous endpoints cannot be stalled.
1019 @param aRealEndpoint The number of the endpoint to be stalled.
1021 @return KErrArgument if endpoint number invalid, KErrNone if endpoint successfully de-stalled,
1022 KErrGeneral otherwise.
1024 @publishedPartner @released
1026 virtual TInt ClearStallEndpoint(TInt aRealEndpoint) =0;
1028 /** Returns the stall status of an endpoint (incl. Ep0).
1030 Isochronous endpoints cannot be stalled.
1032 @param aRealEndpoint The number of the endpoint to be used.
1034 @return KErrArgument if endpoint number invalid, 1 if endpoint is currently stalled, 0 if not.
1036 @publishedPartner @released
1038 virtual TInt EndpointStallStatus(TInt aRealEndpoint) const =0;
1040 /** Returns the error status of an endpoint (incl. Ep0).
1042 @param aRealEndpoint The number of the endpoint to be used.
1044 @return KErrArgument if endpoint number invalid, KErrNone if no error at this endpoint,
1045 KErrGeneral if there is an error.
1047 @publishedPartner @released
1049 virtual TInt EndpointErrorStatus(TInt aRealEndpoint) const =0;
1051 /** Resets the data toggle bit for an endpoint (incl. Ep0).
1053 Isochronous endpoints don't use data toggles.
1055 @param aRealEndpoint The number of the endpoint to be used.
1057 @return KErrArgument if endpoint number invalid, KErrNone if data toggle successfully reset,
1058 KErrGeneral otherwise.
1060 @publishedPartner @released
1062 virtual TInt ResetDataToggle(TInt aRealEndpoint) =0;
1064 /** Returns the (11-bit) frame number contained in the last received SOF packet.
1066 This information is used for isochronous transfers.
1068 @return The (11-bit) frame number contained in the last received SOF packet.
1070 @publishedPartner @released
1072 virtual TInt SynchFrameNumber() const =0;
1074 /** Stores the (11-bit) frame number that should be sent in response to the next SYNCH_FRAME request(s).
1076 @publishedPartner @released
1078 virtual void SetSynchFrameNumber(TInt aFrameNumber) =0;
1082 This initializes the device controller hardware before any other operation can be
1083 performed. Tasks to be carried out here might include
1084 - resetting the whole UDC design
1085 - enabling the UDC's clock
1086 - binding & enabling the UDC (primary) interrupt
1087 - write meaningful values to some general UDC registers
1088 - enabling the USB Reset interrupt
1089 - enabling the UDC proper (for instance by setting an Enable bit)
1091 @return KErrNone if UDC successfully started, KErrGeneral if there was an error.
1093 @publishedPartner @released
1095 virtual TInt StartUdc() =0;
1099 This basically makes undone what happened in StartUdc(). Tasks to be carried out
1101 - disabling the UDC proper (for instance by clearing an Enable bit)
1102 - disabling the USB Reset interrupt
1103 - disabling & unbinding the UDC (primary) interrupt
1104 - disabling the UDC's clock
1106 @return KErrNone if UDC successfully stopped, KErrGeneral if there was an error.
1108 @publishedPartner @released
1110 virtual TInt StopUdc() =0;
1112 /** Connects the UDC - and thus the USB device - physically to the bus.
1114 This might involve a call into the Variant DLL, as the mechanism to achieve the connection can be
1115 specific to the platform (rather than UDC specific). Since this functionality is not part of the USB
1116 specification it has to be explicitly supported, either by the UDC itself or by the hardware
1117 platform. If it is supported, then the member function SoftConnectCaps should be implemented to return
1120 @see SoftConnectCaps()
1122 @return KErrNone if UDC successfully connected, KErrGeneral if there was an error.
1124 @publishedPartner @released
1126 virtual TInt UdcConnect() =0;
1128 /** Disconnects the UDC - and thus the USB device - physically from the bus.
1130 This might involve a call into the Variant DLL, as the mechanism to achieve the disconnection can be
1131 specific to the platform (rather than UDC specific). Since this functionality is not part of the USB
1132 specification it has to be explicitly supported, either by the UDC itself or by the hardware
1133 platform. If it is supported, then the member function SoftConnectCaps should be implemented to return
1136 @see SoftConnectCaps()
1138 @return KErrNone if UDC successfully disconnected, KErrGeneral if there was an error.
1140 @publishedPartner @released
1142 virtual TInt UdcDisconnect() =0;
1144 /** Returns the USB cable connection status.
1146 @return ETrue if the device is connected (via the USB cable) to a USB host, EFalse if not.
1148 @publishedPartner @released
1150 virtual TBool UsbConnectionStatus() const =0;
1152 /** Returns a truth value showing if the VBUS line is powered or not.
1154 Lack of power may indicate an unpowered host or upstream hub, or a disconnected cable.
1156 @return ETrue if VBUS is powered, EFalse otherwise.
1158 @publishedPartner @released
1160 virtual TBool UsbPowerStatus() const =0;
1162 /** Returns the current power status of the USB device.
1164 @return ETrue if the device is currently self-powered, EFalse if not.
1166 @publishedPartner @released
1168 virtual TBool DeviceSelfPowered() const =0;
1170 /** Returns a pointer to an array of TUsbcEndpointCaps structures, which describe the endpoint
1171 capabilities of this UDC.
1173 The dimension of the array can be obtained by calling the member function DeviceTotalEndpoints().
1174 Note that there might be gaps in the array, as the endpoints are numbered using the 'real endpoint'
1175 numbering scheme. Here is how an array could look like:
1178 static const TInt KUsbTotalEndpoints = 5;
1179 static const TUsbcEndpointCaps DeviceEndpoints[KUsbTotalEndpoints] =
1181 // UDC # iEndpoints index
1182 {KEp0MaxPktSzMask, (KUsbEpTypeControl | KUsbEpDirOut)}, // 0 - 0
1183 {KEp0MaxPktSzMask, (KUsbEpTypeControl | KUsbEpDirIn )}, // 0 - 1
1184 {KUsbEpNotAvailable, KUsbEpNotAvailable}, // --- Not present
1185 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirIn )}, // 1 - 3
1186 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)} // 2 - 4
1190 For the endpoint max packet sizes on a USB 2.0 High-speed UDC, the PSL should provide
1191 the overlaid values for both FS and HS, as the PIL can deduce the appropriate values
1194 @see TUsbcEndpointCaps
1195 @see DeviceTotalEndpoints()
1197 @return A pointer to an array of TUsbcEndpointCaps structures, which describe the endpoint
1198 capabilities of this UDC.
1200 @publishedPartner @released
1202 virtual const TUsbcEndpointCaps* DeviceEndpointCaps() const =0;
1204 /** Returns the number of elements in the array pointed to by the return value of DeviceEndpointCaps().
1206 Note that this is not necessarily equal to the number of usable endpoints. In the example to the
1207 DeviceEndpointCaps() function, this value would be 5 even though there are only 4 endpoints.
1209 @see DeviceEndpointCaps()
1211 @return The number of elements in the array pointed to by the return value of DeviceEndpointCaps().
1213 @publishedPartner @released
1215 virtual TInt DeviceTotalEndpoints() const =0;
1217 /** Returns a truth value indicating whether or not this UDC or platform has the capability to disconnect
1218 and re-connect the USB D+ line under software control.
1221 @see UdcDisconnect()
1223 @return ETrue if software connect/disconnect is supported, EFalse otherwise.
1225 @publishedPartner @released
1227 virtual TBool SoftConnectCaps() const =0;
1229 /** Returns a truth value indicating whether or not this UDC allows the accurate tracking of the USB
1232 This capability affects how device state change notifications to the LDD/user are being handled.
1234 @return ETrue if this UDC allows the tracking of the USB device state, EFalse otherwise.
1236 @publishedPartner @released
1238 virtual TBool DeviceStateChangeCaps() const =0;
1240 /** Returns a truth value indicating whether the USB device controller (UDC) hardware supports
1241 detection of a plugged-in USB cable even when not powered.
1243 This capability affects the power management strategy used by the USB Manager.
1245 (Function is not 'pure virtual' for backwards compatibility with existing USB PSLs.
1246 The default implementation in the PIL returns EFalse.)
1248 @return ETrue if this UDC supports USB cable detection when not powered, EFalse otherwise.
1250 @publishedPartner @released
1252 virtual TBool CableDetectWithoutPowerCaps() const;
1254 /** Returns a truth value indicating whether the USB device controller (UDC) hardware supports
1255 USB High-speed operation.
1257 This capability affects driver functionality and behaviour throughout the implementation.
1259 (Function is not 'pure virtual' for backwards compatibility with existing USB PSLs.
1260 The default implementation in the PIL returns EFalse.)
1262 @return ETrue if this UDC supports USB High-speed operation, EFalse otherwise.
1264 @publishedPartner @released
1266 virtual TBool DeviceHighSpeedCaps() const;
1268 /** Returns a truth value indicating whether this PSL supports the new
1269 ('V2') endpoint resource request scheme.
1271 This capability can be queried from the user-side and may determine the
1272 way the USB application issues resource allocation requests.
1274 (Function is not 'pure virtual' for backwards compatibility with existing USB PSLs.
1275 The default implementation in the PIL returns EFalse.)
1277 @return ETrue if PSL supports the new endpoint resource request scheme,
1280 @publishedPartner @released
1282 virtual TBool DeviceResourceAllocV2Caps() const;
1284 /** Returns a truth value indicating whether this UDC handles OTG HNP bus
1285 connects/disconnects automatically in hardware.
1287 This capability will be queried by the PIL and determines the way the
1288 PIL calls the functions behind the
1289 iEnablePullUpOnDPlus / iDisablePullUpOnDPlus pointers.
1291 If HNP is handled by hardware (TBool = ETrue) then the PIL will (in
1294 1) make calls to those function pointers dependent only on the
1295 readiness or otherwise of user-side USB Client support (i.e. the Client
1296 LDD calls DeviceConnectToHost() / DeviceDisconnectFromHost()), as
1297 opposed to also evaluating Client PDD EnableClientStack() /
1298 DisableClientStack() calls from the OTG driver.
1300 2) delay its USB Reset processing incl. the notification of upper
1301 layers (LDD + user-side), plus the initial setting up of an Ep0 read
1302 until user-side USB Client support readiness has been signalled
1303 (i.e. until after a call to DeviceConnectToHost()).
1305 (Function is not 'pure virtual' for backwards compatibility with
1306 existing USB PSLs. The default implementation in the PIL returns EFalse.)
1308 @return ETrue if UDC/PSL handles HNP connects/disconnects in hardware,
1311 @publishedPartner @released
1313 virtual TBool DeviceHnpHandledByHardwareCaps() const;
1315 /** Implements anything the UDC (PSL) might require following bus Suspend signalling.
1317 This function gets called by the PIL after it has been notified (by the PSL) about the Suspend
1320 @publishedPartner @released
1322 virtual void Suspend() =0;
1324 /** Implements anything the UDC (PSL) might require following bus Resume signalling.
1326 This function gets called by the PIL after it has been notified (by the PSL) about the Resume event.
1328 @publishedPartner @released
1330 virtual void Resume() =0;
1332 /** Implements anything the UDC (PSL) might require following bus Reset signalling.
1334 This function gets called by the PIL after it has been notified (by the PSL) about the Reset event.
1336 @publishedPartner @released
1338 virtual void Reset() =0;
1340 /** Called by the PIL to signal to the PSL that it has finished processing a received Setup packet (on
1341 Ep0) and that the PSL can now prepare itself for the next Ep0 reception (for instance by re-enabling
1344 The reason for having this function is the situation where no Ep0 read has been set up by the user and
1345 thus a received Setup packet cannot immediately be delivered to the user. Once the user however sets
1346 up an Ep0 read, the PIL completes the request and eventually calls this function. This way we can
1347 implement some sort of flow-control.
1349 @publishedPartner @released
1351 virtual void Ep0ReadSetupPktProceed() =0;
1353 /** Called by the PIL to signal to the PSL that it has finished processing a received Ep0 data packet and
1354 that the PSL can now prepare itself for the next Ep0 reception (for instance by re-enabling the Ep0
1357 The reason for having this function is the situation where no Ep0 read has been set up by the user and
1358 thus a received packet cannot immediately be delivered to the user. Once the user however sets up an
1359 Ep0 read, the PIL completes the request and eventually calls this function. This way we can implement
1360 some sort of flow-control.
1362 @publishedPartner @released
1364 virtual void Ep0ReceiveProceed() =0;
1366 /** Returns a truth value indicating whether the USB controller hardware (UDC) supports being powered
1367 down while (a configuration is) active.
1369 This capability affects the power management strategy used by the USB Manager.
1371 (Function is not 'pure virtual' for backwards compatibility with existing USB PSLs. The default
1372 implementation in the PIL - to be on the safe side - returns EFalse.)
1374 @return ETrue if this UDC supports power-down while active, EFalse otherwise.
1376 @publishedPartner @released
1378 virtual TBool PowerDownWhenActive() const;
1380 /** Powers the UDC down, i.e. puts it into a (hardware-dependent) power-saving mode. Note that this
1381 function is not the same as StopUdc(). The difference is that while StopUdc() effectively turns the
1382 UDC off and so may invalidate all its settings, after a call to PowerDown() the UDC is expected to
1383 return to its previous state when PowerUp() is called. This function is also not the same as
1384 Suspend() which gets called by the PIL in response to a Suspend event on the bus, and only then
1385 (but apart from that the two functions are very similar).
1387 This function won't be called by the PIL once the UDC is active if PowerDownWhenActive() returns
1388 EFalse (which it by default does).
1390 (Function is not 'pure virtual' for backwards compatibility with existing USB PSLs. The default
1391 implementation in the PIL does nothing.)
1394 @see PowerDownWhenActive()
1396 @return KErrNone if UDC was successfully powered down, KErrGeneral otherwise.
1398 @publishedPartner @released
1400 virtual TInt PowerDown();
1402 /** Powers the UDC up by exiting a (hardware-dependent) power-saving mode. Note that this function is not
1403 the same as StartUdc(). The difference is that while StartUdc() starts the UDC from zero and merely
1404 leads to the default state (i.e. not an active configuration), after a call to PowerUp() the UDC is
1405 expected to have returned to the state it was in before PowerDown() was called.
1407 (Function is not 'pure virtual' for backwards compatibility with existing USB PSLs. The default
1408 implementation in the PIL does nothing.)
1412 @return KErrNone if UDC was successfully powered up, KErrGeneral otherwise.
1414 @publishedPartner @released
1416 virtual TInt PowerUp();
1418 /** Puts the controller into a specific test mode (during HS operation only).
1420 9.4.9 Set Feature: "The transition to test mode must be complete no later than 3 ms after the
1421 completion of the status stage of the request." (The status stage will have been completed
1422 immediately before this function gets called.)
1424 (Function is not 'pure virtual' for backwards compatibility with existing USB PSLs.
1425 The default implementation in the PIL returns KErrNotSupported.)
1427 @param aTestSelector The specific test mode selector (@see usb.h).
1429 @return KErrNone if the specified test mode was entered successfully,
1430 KErrGeneral otherwise.
1432 @publishedPartner @released
1434 virtual TInt EnterTestMode(TInt aTestSelector);
1436 /** Turn on USB client functionality in an OTG/Host setup.
1438 This PSL function is called by the PIL when the OTG stack calls the PIL
1439 function EnableClientStack(). Immediately afterwards the PIL may
1440 connect the B-device to the bus (via the OTG stack). OtgEnableUdc() is
1441 called always after StartUdc().
1443 There is no equivalent to this function in the non-OTG version of the
1446 @return KErrNone if UDC successfully enabled, KErrGeneral otherwise.
1448 @publishedPartner @released
1450 virtual TInt OtgEnableUdc();
1452 /** Turn off USB client functionality in an OTG/Host setup.
1454 This function is called by the PIL when the OTG stack calls the PIL
1455 function DisableClientStack(); the PIL will do this immediately after
1456 it has disconnected the B-device from the bus (via the OTG stack) and
1457 before calling StopUdc().
1459 There is no equivalent to this function in the non-OTG version of the
1462 @return KErrNone if UDC successfully disabled, KErrGeneral otherwise.
1464 @publishedPartner @released
1466 virtual TInt OtgDisableUdc();
1471 // --- Private member functions (used by PIL) ---
1474 TInt DeRegisterClientCallback(const DBase* aClientId);
1475 TBool CheckEpAvailability(TInt aEndpointsUsed, const TUsbcEndpointInfoArray& aEndpointData, TInt aIfcNumber)
1477 TUsbcInterface* CreateInterface(const DBase* aClientId, TInt aIfc, TUint32 aFeatureWord);
1478 TInt CreateEndpoints(TUsbcInterface* aIfc, TInt aEndpointsUsed, const TUsbcEndpointInfoArray& aEndpointData,
1479 TInt *aRealEpNumbers);
1480 TInt SetupIfcDescriptor(TUsbcInterface* aIfc, TUsbcClassInfo& aClass, DThread* aThread, TDesC8* aString,
1481 const TUsbcEndpointInfoArray& aEndpointData);
1482 TInt ClientId2InterfaceNumber(const DBase* aClientId) const;
1483 TUsbcInterfaceSet* ClientId2InterfacePointer(const DBase* aClientId) const;
1484 const DBase* InterfaceNumber2ClientId(TInt aIfcSet) const;
1485 TUsbcInterfaceSet* InterfaceNumber2InterfacePointer(TInt aIfcSet) const;
1486 inline const DBase* PEndpoint2ClientId(TInt aRealEndpoint) const;
1487 inline TInt PEndpoint2LEndpoint(TInt aRealEndpoint) const;
1488 TInt ActivateHardwareController();
1489 void DeActivateHardwareController();
1490 void DeleteInterfaceSet(TInt aIfcSet);
1491 void DeleteInterface(TInt aIfcSet, TInt aIfc);
1492 void CancelTransferRequests(TInt aRealEndpoint);
1493 void DeleteRequestCallback(const DBase* aClientId, TInt aEndpointNum, TTransferDirection aTransferDir);
1494 void DeleteRequestCallbacks(const DBase* aClientId);
1495 void StatusNotify(TUsbcDeviceState aState, const DBase* aClientId=NULL);
1496 void EpStatusNotify(TInt aRealEndpoint);
1497 void OtgFeaturesNotify();
1498 void RunClientCallbacks();
1499 void ProcessDataTransferDone(TUsbcRequestCallback& aRcb);
1500 void NextDeviceState(TUsbcDeviceState aNextState);
1501 TInt ProcessSuspendEvent();
1502 TInt ProcessSuspendEventProceed();
1503 TInt ProcessResumeEvent();
1504 TInt ProcessResetEvent(TBool aPslUpcall=ETrue);
1505 TInt ProcessCableInsertEvent();
1506 TInt ProcessCableRemoveEvent();
1507 TInt ProcessEp0ReceiveDone(TInt aCount);
1508 TInt ProcessEp0TransmitDone(TInt aCount, TInt aError);
1509 TInt ProcessEp0SetupReceived(TInt aCount);
1510 TInt ProcessEp0DataReceived(TInt aCount);
1511 TInt ProcessGetDeviceStatus(const TUsbcSetup& aPacket);
1512 TInt ProcessGetInterfaceStatus(const TUsbcSetup& aPacket);
1513 TInt ProcessGetEndpointStatus(const TUsbcSetup& aPacket);
1514 TInt ProcessSetClearDevFeature(const TUsbcSetup& aPacket);
1515 TInt ProcessSetClearIfcFeature(const TUsbcSetup& aPacket);
1516 TInt ProcessSetClearEpFeature(const TUsbcSetup& aPacket);
1517 TInt ProcessSetAddress(const TUsbcSetup& aPacket);
1518 TInt ProcessGetDescriptor(const TUsbcSetup& aPacket);
1519 TInt ProcessSetDescriptor(const TUsbcSetup& aPacket);
1520 TInt ProcessGetConfiguration(const TUsbcSetup& aPacket);
1521 TInt ProcessGetInterface(const TUsbcSetup& aPacket);
1522 TInt ProcessSetInterface(const TUsbcSetup& aPacket);
1523 TInt ProcessSynchFrame(const TUsbcSetup& aPacket);
1524 void ProceedSetDescriptor();
1525 void SetClearHaltFeature(TInt aRealEndpoint, TUint8 aRequest);
1526 TInt ClearHaltFeature(TInt aRealEndpoint);
1527 void ChangeConfiguration(TUint16 aValue);
1528 void InterfaceSetup(TUsbcInterface* aIfc);
1529 void InterfaceSetTeardown(TUsbcInterfaceSet* aIfc);
1530 void ChangeInterface(TUsbcInterface* aIfc);
1531 TInt DoForEveryEndpointInUse(TInt (DUsbClientController::*aFunction)(TInt), TInt& aCount);
1532 void EnterFullSpeed();
1533 void EnterHighSpeed();
1534 TInt EvaluateOtgConnectFlags();
1535 inline const TUsbcConfiguration* CurrentConfig() const;
1536 inline TUsbcConfiguration* CurrentConfig();
1537 inline TBool InterfaceExists(TInt aNumber) const;
1538 inline TBool EndpointExists(TUint aAddress) const;
1539 inline void Buffer2Setup(const TAny* aBuf, TUsbcSetup& aSetup) const;
1540 inline TUint EpIdx2Addr(TUint aRealEndpoint) const;
1541 inline TUint EpAddr2Idx(TUint aAddress) const;
1542 inline void SetEp0DataOutVars(const TUsbcSetup& aPacket, const DBase* aClientId = NULL);
1543 inline void ResetEp0DataOutVars();
1544 inline TBool IsInTheStatusList(const TUsbcStatusCallback& aCallback);
1545 inline TBool IsInTheEpStatusList(const TUsbcEndpointStatusCallback& aCallback);
1546 inline TBool IsInTheOtgFeatureList(const TUsbcOtgFeatureCallback& aCallback);
1547 inline TBool IsInTheRequestList(const TUsbcRequestCallback& aCallback);
1548 static void ReconnectTimerCallback(TAny* aPtr);
1549 static void CableStatusTimerCallback(TAny* aPtr);
1550 static void PowerUpDfc(TAny* aPtr);
1551 static void PowerDownDfc(TAny* aPtr);
1556 // --- Private data members ---
1559 static DUsbClientController* UsbClientController[KUsbcMaxUdcs];
1561 TInt iDeviceTotalEndpoints; // number of endpoints reported by PSL
1562 TInt iDeviceUsableEndpoints; // number of endpoints reported to LDD
1563 TUsbcDeviceState iDeviceState; // states as of USB spec chapter 9.1
1564 TUsbcDeviceState iDeviceStateB4Suspend; // state before entering suspend state
1565 TBool iSelfPowered; // true if device is capable of beeing self-powered
1566 TBool iRemoteWakeup; // true if device is capable of signalling rmwakeup
1567 TBool iTrackDeviceState; // true if we should track the device state in s/w
1568 TBool iHardwareActivated; // true if controller silicon is in operating state
1569 TBool iOtgSupport; // true if OTG is supported by this device
1570 TBool iOtgHnpHandledByHw; // true if HNP dis/connect is handled by hardware
1571 TUint8 iOtgFuncMap; // bitmap indicating OTG extension features
1572 TBool iHighSpeed; // true if currently operating at high-speed
1573 TUsbcSetup iSetup; // storage for a setup packet during its DATA_OUT
1574 TInt iEp0MaxPacketSize; // currently configured max packet size for Ep0
1575 const DBase* iEp0ClientId; // see comment at the begin of ps_usbc.cpp
1576 TUint16 iEp0DataReceived; // indicates how many bytes have already been received
1577 TBool iEp0DataReceiving; // true if ep0's in DATA_OUT stage
1578 TBool iEp0WritePending; // true if a write on ep0 has been set up
1579 TBool iEp0ClientDataTransmitting; // true if ep0's in DATA_IN on behalf of a client
1580 const DBase* iEp0DeviceControl; // Device Ep0 requests are delivered to this LDD
1581 TUsbcDescriptorPool iDescriptors; // the descriptors as of USB spec chapter 9.5
1582 TUint8 iCurrentConfig; // bConfigurationValue of current Config (1-based!)
1583 RPointerArray<TUsbcConfiguration> iConfigs; // the root of the modelled USB device
1584 TUsbcPhysicalEndpoint iRealEndpoints[KUsbcEpArraySize]; // array will be filled once at startup
1585 TUint8 iEp0_TxBuf[KUsbcBufSz_Ep0Tx]; // ep0 outgoing (tx) data is placed here
1586 #ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
1587 TUint8 iEp0_RxCollectionBuf[KUsbcBufSz_Ep0Rx]; // used for (optional) SET_DESCRIPTOR request
1589 TInt iEp0_RxExtraCount; // number of bytes received but not yet delivered
1590 TBool iEp0_RxExtraData; // true if iEp0_RxExtraCount is valid
1591 TInt iEp0_TxNonStdCount; // number of bytes requested by non-std Ep0 request
1592 TUsbcRequestCallback* iRequestCallbacks[KUsbcEpArraySize]; // xfer requests; indexed by real ep number
1593 TSglQue<TUsbcRequestCallback> iEp0ReadRequestCallbacks; // list of ep0 read requests
1594 TSglQue<TUsbcClientCallback> iClientCallbacks; // registered LDD clients and their callback functions
1595 TSglQue<TUsbcStatusCallback> iStatusCallbacks; // list of device state notification requests
1596 TSglQue<TUsbcEndpointStatusCallback> iEpStatusCallbacks; // list of endpoint state notification requests
1597 TSglQue<TUsbcOtgFeatureCallback> iOtgCallbacks; // list of OTG feature change requests
1598 NTimer iReconnectTimer; // implements USB re-enumeration delay
1599 NTimer iCableStatusTimer; // implements USB cable status detection delay
1600 DUsbcPowerHandler* iPowerHandler; // pointer to USB power handler object
1603 TDfc iPowerUpDfc; // queued by power handler upon power-up
1604 TDfc iPowerDownDfc; // queued by power handler upon power-down
1607 TBool iStandby; // toggled by power handler as appropriate
1608 TBool iStackIsActive; // client stack's function is usable
1609 TBool iOtgClientConnect; // OTG stack wishes to connect to the host
1610 TBool iClientSupportReady; // user-side USB Client support is loaded & active
1611 TBool iDPlusEnabled; // set if both sides agree and DPLUS is asserted
1612 TBool iUsbResetDeferred; // set when user-side wasn't ready yet
1615 TInt (*iEnablePullUpOnDPlus)(TAny* aOtgContext); // these are to be filled in by the Host component
1616 TInt (*iDisablePullUpOnDPlus)(TAny* aOtgContext); // in an OTG setup (otherwise unused)
1617 TAny* iOtgContext; // to be passed into the above 2 functions
1621 /** Simple queue of status changes to be recorded.
1622 Items are fetched by userside when able.
1624 class TUsbcDeviceStatusQueue
1627 TUsbcDeviceStatusQueue();
1628 void AddStatusToQueue(TUint32 aDeviceStatus);
1629 TInt GetDeviceQueuedStatus(TUint32& aDeviceStatus);
1633 TUint32 iDeviceStatusQueue[KUsbDeviceStatusQueueDepth];
1634 TInt iStatusQueueHead;
1637 #include <drivers/usbcshared.inl>
1639 #endif // __USBCSHARED_H__