33
|
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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32\include\drivers\usbcshared.h
|
|
15 |
// Kernel side definitions for the USB Device driver stack (PIL + LDD).
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
/**
|
|
20 |
@file usbcshared.h
|
|
21 |
@internalTechnology
|
|
22 |
*/
|
|
23 |
|
|
24 |
#ifndef __USBCSHARED_H__
|
|
25 |
#define __USBCSHARED_H__
|
|
26 |
|
|
27 |
//#include <drivers/usbcque.h>
|
|
28 |
#include <usb/usbcque.h>
|
|
29 |
|
|
30 |
// Define here what options are required:
|
|
31 |
// (USB_SUPPORTS_CONTROLENDPOINTS and USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
|
|
32 |
// have never been tested though...)
|
|
33 |
//#define USB_SUPPORTS_CONTROLENDPOINTS
|
|
34 |
//#define USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
|
|
35 |
|
|
36 |
//#include <drivers/usbcdesc.h>
|
|
37 |
#include <usb/usbcdesc.h>
|
|
38 |
//#include <drivers/usbotgperipheralcontrolif.h>
|
|
39 |
#include <usb/usbotgperipheralcontrolif.h>
|
|
40 |
|
|
41 |
#include <usb/usb_peripheral_shai.h>
|
|
42 |
#include <usb/usb_charger_detection_shai.h>
|
|
43 |
|
|
44 |
#include <usb/usbcontrolxferif.h>
|
|
45 |
|
|
46 |
// FIXME: Remove this typedef once PIL and LDD are ready for SHAI
|
|
47 |
typedef UsbShai::TUsbPeripheralEvent TUsbcDeviceEvent;
|
|
48 |
typedef UsbShai::TUsbPeripheralPacketArray TUsbcPacketArray;
|
|
49 |
|
|
50 |
// Forward declaration
|
|
51 |
class DControlTransferManager;
|
|
52 |
class TUsbcSetup;
|
|
53 |
|
|
54 |
// Debug Support
|
|
55 |
|
|
56 |
// Use for debugging purposes only (commented out for normal operation):
|
|
57 |
//#define USBC_LDD_BUFFER_TRACE
|
|
58 |
|
|
59 |
static const char KUsbPILPanicCat[] = "USB PIL FAULT"; // kernel fault category
|
|
60 |
_LIT(KUsbPILKillCat, "USB PIL KILL"); // thread kill category
|
|
61 |
_LIT(KUsbLDDKillCat, "USB LDD KILL"); // thread kill category
|
|
62 |
|
|
63 |
/** Error code for stalled endpoint.
|
|
64 |
*/
|
|
65 |
const TInt KErrEndpointStall = KErrLocked;
|
|
66 |
|
|
67 |
/** Error code for Ep0 write prematurely ended by a host OUT token.
|
|
68 |
*/
|
|
69 |
const TInt KErrPrematureEnd = KErrDiskFull;
|
|
70 |
|
|
71 |
/** The following constants control the buffer arrangement for OUT transfers (IN transfers have only 1
|
|
72 |
buffer). The total size of buffering for an OUT endpoint will be number of buffers * buffersize,
|
|
73 |
so that, for example, a Bulk OUT endpoint will have KUsbcDmaBufNumBulk * KUsbcDmaBufSzBulk bytes of
|
|
74 |
buffering.
|
|
75 |
These buffers will be physically contiguous, so that DMA may be used.
|
|
76 |
The number of buffers MUST be >=2 - otherwise the buffering scheme won't work.
|
|
77 |
The buffer sizes should be an exact fraction of 4kB and the number of buffers such that the
|
|
78 |
buffersize * number of buffers is an exact multiple of 4kB, otherwise memory will be wasted.
|
|
79 |
*/
|
|
80 |
/** Size of a Control ep buffer.
|
|
81 |
*/
|
|
82 |
const TInt KUsbcDmaBufSzControl = 1024;
|
|
83 |
|
|
84 |
/** Size of a Bulk ep buffer.
|
|
85 |
*/
|
|
86 |
const TInt KUsbcDmaBufSzBulk = 4096;
|
|
87 |
|
|
88 |
/** Size of an Interrupt ep buffer.
|
|
89 |
*/
|
|
90 |
const TInt KUsbcDmaBufSzInterrupt = 4096;
|
|
91 |
|
|
92 |
/** Size of an Isochronous ep buffer.
|
|
93 |
*/
|
|
94 |
const TInt KUsbcDmaBufSzIsochronous = 4096;
|
|
95 |
|
|
96 |
/** Number of buffers for Control OUT endpoints.
|
|
97 |
*/
|
|
98 |
const TInt KUsbcDmaBufNumControl = 2;
|
|
99 |
|
|
100 |
/** Number of buffers for Isochronous OUT endpoints.
|
|
101 |
*/
|
|
102 |
const TInt KUsbcDmaBufNumIsochronous = 2;
|
|
103 |
|
|
104 |
/** Number of buffers for Bulk OUT endpoints.
|
|
105 |
*/
|
|
106 |
const TInt KUsbcDmaBufNumBulk = 2;
|
|
107 |
|
|
108 |
/** Number of buffers for Interrupt OUT endpoints.
|
|
109 |
*/
|
|
110 |
const TInt KUsbcDmaBufNumInterrupt = 2;
|
|
111 |
|
|
112 |
/** Maximum buffer number.
|
|
113 |
*/
|
|
114 |
const TInt KUsbcDmaBufNumMax = MAX4(KUsbcDmaBufNumControl, KUsbcDmaBufNumIsochronous,
|
|
115 |
KUsbcDmaBufNumBulk, KUsbcDmaBufNumInterrupt);
|
|
116 |
|
|
117 |
/** Maximum number of recorded packets possible.
|
|
118 |
*/
|
|
119 |
const TUint KUsbcDmaBufMaxPkts = 2;
|
|
120 |
|
|
121 |
/** Number of arrays.
|
|
122 |
*/
|
|
123 |
const TInt KUsbcDmaBufNumArrays = 2;
|
|
124 |
|
|
125 |
/** Max size that Ep0 packets might have.
|
|
126 |
*/
|
|
127 |
const TInt KUsbcBufSzControl = 64;
|
|
128 |
|
|
129 |
/** The Ep0 RX data collection buffer area.
|
|
130 |
(Arbitrary size, judged to be sufficient for SET_DESCRIPTOR requests)
|
|
131 |
*/
|
|
132 |
const TInt KUsbcBufSz_Ep0Rx = 1024;
|
|
133 |
|
|
134 |
/** The Ep0 TX buffer area.
|
|
135 |
(Size sufficient to hold as much data as can be requested via GET_DESCRIPTOR)
|
|
136 |
*/
|
|
137 |
const TInt KUsbcBufSz_Ep0Tx = 1024 * 64;
|
|
138 |
|
|
139 |
|
|
140 |
/** The USB version the stack is compliant with: 2.0 (BCD).
|
|
141 |
*/
|
|
142 |
const TUint16 KUsbcUsbVersion = 0x0200;
|
|
143 |
|
|
144 |
/** Maximum number of endpoints an interface (i.e. LDD) may have.
|
|
145 |
*/
|
|
146 |
const TInt KUsbcMaxEpNumber = 5;
|
|
147 |
|
|
148 |
/** Status FIFO depth; enough for 2 complete configs.
|
|
149 |
*/
|
|
150 |
const TInt KUsbDeviceStatusQueueDepth = 15;
|
|
151 |
|
|
152 |
/** = 'no status info'.
|
|
153 |
*/
|
|
154 |
const TUint32 KUsbDeviceStatusNull = 0xffffffffu;
|
|
155 |
|
|
156 |
/** = 'no buffer available'.
|
|
157 |
*/
|
|
158 |
const TInt KUsbcInvalidBufferIndex = -1;
|
|
159 |
|
|
160 |
/** = 'no packet available'.
|
|
161 |
*/
|
|
162 |
const TUint KUsbcInvalidPacketIndex = (TUint)(-1);
|
|
163 |
|
|
164 |
/** = 'no drainable buffers'.
|
|
165 |
*/
|
|
166 |
const TInt KUsbcInvalidDrainQueueIndex = -1;
|
|
167 |
|
|
168 |
/** Number of possible bandwidth priorities.
|
|
169 |
*/
|
|
170 |
const TInt KUsbcDmaBufMaxPriorities = 4;
|
|
171 |
|
|
172 |
// The following buffer sizes are used within the LDD for the different
|
|
173 |
// user-selectable endpoint bandwidth priorities
|
|
174 |
// (EUsbcBandwidthOUTDefault/Plus1/Plus2/Maximum + the same for 'IN').
|
|
175 |
// These values, in particular those for the Maximum setting, were obtained
|
|
176 |
// empirically.
|
|
177 |
|
|
178 |
/** Bulk IN buffer sizes for different priorities (4K, 16K, 64K, 512K).
|
|
179 |
*/
|
|
180 |
const TInt KUsbcDmaBufSizesBulkIN[KUsbcDmaBufMaxPriorities] =
|
|
181 |
{KUsbcDmaBufSzBulk, 0x4000, 0x10000, 0x80000};
|
|
182 |
|
|
183 |
/** Bulk OUT buffer sizes for different priorities (4K, 16K, 64K, 512K).
|
|
184 |
*/
|
|
185 |
const TInt KUsbcDmaBufSizesBulkOUT[KUsbcDmaBufMaxPriorities] =
|
|
186 |
{KUsbcDmaBufSzBulk, 0x4000, 0x10000, 0x80000};
|
|
187 |
|
|
188 |
/** Number of UDCs supported in the system.
|
|
189 |
(Support for more than one UDC is preliminary.)
|
|
190 |
*/
|
|
191 |
const TInt KUsbcMaxUdcs = 2;
|
|
192 |
|
|
193 |
/** Number of endpoints a USB device can have.
|
|
194 |
(30 regular endpoints + 2 x Ep0)
|
|
195 |
*/
|
|
196 |
const TInt KUsbcEpArraySize = KUsbcMaxEndpoints + 2;
|
|
197 |
|
|
198 |
/** Number of notification requests of the same kind that can be registered at
|
|
199 |
a time. As normally not more than one request per kind per LDD is
|
|
200 |
permitted, this number is roughly equivalent to the maximum number of LDDs
|
|
201 |
that can be operating at the same time.
|
|
202 |
This constant is used by the PIL while maintaining its request lists
|
|
203 |
(iClientCallbacks, iStatusCallbacks, iEpStatusCallbacks, iOtgCallbacks) to
|
|
204 |
ensure that the lists are of a finite length and thus the list traverse
|
|
205 |
time is bounded.
|
|
206 |
This value is chosen with the maximum number of USB interfaces (not
|
|
207 |
settings) allowed by the spec for a single device in mind.
|
|
208 |
*/
|
|
209 |
const TInt KUsbcMaxListLength = 256;
|
|
210 |
|
|
211 |
/**
|
|
212 |
* device event FIFO depth, there are 5 different event define currently,
|
|
213 |
* 10 should be enough
|
|
214 |
*/
|
|
215 |
const TInt KUsbDeviceEventQueueDepth = 10;
|
|
216 |
|
|
217 |
/** USB LDD client callback.
|
|
218 |
*/
|
|
219 |
class TUsbcClientCallback
|
|
220 |
{
|
|
221 |
public:
|
|
222 |
inline TUsbcClientCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
|
|
223 |
inline DBase* Owner() const;
|
|
224 |
inline TInt DoCallback();
|
|
225 |
inline void Cancel();
|
|
226 |
inline void SetDfcQ(TDfcQue* aDfcQ);
|
|
227 |
public:
|
|
228 |
/** Used by the PIL to queue callback objects into a TSglQue. */
|
|
229 |
TSglQueLink iLink;
|
|
230 |
private:
|
|
231 |
DBase* iOwner;
|
|
232 |
TDfc iDfc;
|
|
233 |
};
|
|
234 |
|
|
235 |
|
|
236 |
/** The endpoint halt/clear_halt status.
|
|
237 |
*/
|
|
238 |
class TUsbcEndpointStatusCallback
|
|
239 |
{
|
|
240 |
public:
|
|
241 |
inline TUsbcEndpointStatusCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
|
|
242 |
inline void SetState(TUint aState);
|
|
243 |
inline TUint State() const;
|
|
244 |
inline DBase* Owner() const;
|
|
245 |
inline TInt DoCallback();
|
|
246 |
inline void Cancel();
|
|
247 |
inline void SetDfcQ(TDfcQue* aDfcQ);
|
|
248 |
public:
|
|
249 |
/** Used by the PIL to queue callback objects into a TSglQue. */
|
|
250 |
TSglQueLink iLink;
|
|
251 |
private:
|
|
252 |
DBase* iOwner;
|
|
253 |
TDfc iDfc;
|
|
254 |
TUint iState;
|
|
255 |
};
|
|
256 |
|
|
257 |
|
|
258 |
/** Maximum number of device status requests that can be queued at a time.
|
|
259 |
The value chosen is thought to be sufficient in all situations.
|
|
260 |
*/
|
|
261 |
const TInt KUsbcDeviceStateRequests = 8;
|
|
262 |
|
|
263 |
|
|
264 |
/** The USB device status.
|
|
265 |
*/
|
|
266 |
class TUsbcStatusCallback
|
|
267 |
{
|
|
268 |
public:
|
|
269 |
inline TUsbcStatusCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
|
|
270 |
inline void SetState(UsbShai::TUsbPeripheralState aState);
|
|
271 |
inline UsbShai::TUsbPeripheralState State(TInt aIndex) const;
|
|
272 |
inline void ResetState();
|
|
273 |
inline DBase* Owner() const;
|
|
274 |
inline TInt DoCallback();
|
|
275 |
inline void Cancel();
|
|
276 |
inline void SetDfcQ(TDfcQue* aDfcQ);
|
|
277 |
public:
|
|
278 |
/** Used by the PIL to queue callback objects into a TSglQue. */
|
|
279 |
TSglQueLink iLink;
|
|
280 |
private:
|
|
281 |
DBase* iOwner;
|
|
282 |
TDfc iDfc;
|
|
283 |
UsbShai::TUsbPeripheralState iState[KUsbcDeviceStateRequests];
|
|
284 |
};
|
|
285 |
|
|
286 |
|
|
287 |
/** A USB transfer request.
|
|
288 |
|
|
289 |
@publishedPartner
|
|
290 |
@released
|
|
291 |
*/
|
|
292 |
class TUsbcRequestCallback : public UsbShai::TUsbPeripheralRequest
|
|
293 |
{
|
|
294 |
public:
|
|
295 |
/** @internalTechnology */
|
|
296 |
inline TUsbcRequestCallback(const DBase* aOwner, TInt aEndpointNum, TDfcFn aDfcFunc,
|
|
297 |
TAny* aEndpoint, TDfcQue* aDfcQ, TInt aPriority);
|
|
298 |
/** @internalTechnology */
|
|
299 |
inline ~TUsbcRequestCallback();
|
|
300 |
|
|
301 |
IMPORT_C void SetRxBufferInfo(TUint8* aBufferStart,
|
|
302 |
TUintPtr aBufferAddr,
|
|
303 |
TUint32* aPacketIndex,
|
|
304 |
TUint32* aPacketSize,
|
|
305 |
TInt aLength);
|
|
306 |
|
|
307 |
IMPORT_C void SetTxBufferInfo(TUint8* aBufferStart,
|
|
308 |
TUintPtr aBufferAddr,
|
|
309 |
TInt aLength);
|
|
310 |
|
|
311 |
/** @internalTechnology */
|
|
312 |
inline void SetTransferDirection(UsbShai::TTransferDirection aTransferDir);
|
|
313 |
/** @internalTechnology */
|
|
314 |
inline const DBase* Owner() const;
|
|
315 |
/** @internalTechnology */
|
|
316 |
inline TInt DoCallback();
|
|
317 |
/** @internalTechnology */
|
|
318 |
inline void Cancel();
|
|
319 |
public:
|
|
320 |
/** Used by the PIL to queue callback objects into a TSglQue.
|
|
321 |
@internalTechnology
|
|
322 |
*/
|
|
323 |
TSglQueLink iLink;
|
|
324 |
public:
|
|
325 |
/** The endpoint number. */
|
|
326 |
const TInt iEndpointNum;
|
|
327 |
|
|
328 |
/** Indicates the LDD client for this transfer. */
|
|
329 |
const DBase* const iOwner;
|
|
330 |
/** DFC, used by PIL to call back the LDD when transfer completes to the LDD. */
|
|
331 |
TDfc iDfc;
|
|
332 |
};
|
|
333 |
|
|
334 |
/** USB On-The-Go feature change callback.
|
|
335 |
*/
|
|
336 |
class TUsbcOtgFeatureCallback
|
|
337 |
{
|
|
338 |
public:
|
|
339 |
inline TUsbcOtgFeatureCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
|
|
340 |
inline void SetFeatures(TUint8 aFeatures);
|
|
341 |
inline TUint8 Features() const;
|
|
342 |
inline DBase* Owner() const;
|
|
343 |
inline TInt DoCallback();
|
|
344 |
inline void Cancel();
|
|
345 |
inline void SetDfcQ(TDfcQue* aDfcQ);
|
|
346 |
public:
|
|
347 |
/** Used by the PIL to queue callback objects into a TSglQue. */
|
|
348 |
TSglQueLink iLink;
|
|
349 |
private:
|
|
350 |
DBase* iOwner;
|
|
351 |
TDfc iDfc;
|
|
352 |
TUint8 iValue;
|
|
353 |
};
|
|
354 |
|
|
355 |
//
|
|
356 |
//########################### Physical Device Driver (PIL + PSL) ######################
|
|
357 |
//
|
|
358 |
|
|
359 |
class TUsbcLogicalEndpoint;
|
|
360 |
|
|
361 |
/** This models a physical (real) endpoint of the UDC.
|
|
362 |
*/
|
|
363 |
class TUsbcPhysicalEndpoint
|
|
364 |
{
|
|
365 |
public:
|
|
366 |
TUsbcPhysicalEndpoint();
|
|
367 |
~TUsbcPhysicalEndpoint();
|
|
368 |
TBool EndpointSuitable(const TUsbcEndpointInfo* aEpInfo, TInt aIfcNumber) const; // Check Todo, SC will pass pointer to derived class
|
|
369 |
TInt TypeAvailable(TUint aType) const;
|
|
370 |
TInt DirAvailable(TUint aDir) const;
|
|
371 |
public:
|
|
372 |
/** This endpoint's capabilities. */
|
|
373 |
UsbShai::TUsbPeripheralEndpointCaps iCaps;
|
|
374 |
/** USB address: 0x00, 0x80, 0x01, 0x81, etc. */
|
|
375 |
TUint8 iEndpointAddr;
|
|
376 |
/** Pointer to interface # this endpoint has been assigned to. */
|
|
377 |
const TUint8* iIfcNumber;
|
|
378 |
/** Pointer to corresponding logical endpoint or NULL. */
|
|
379 |
const TUsbcLogicalEndpoint* iLEndpoint;
|
|
380 |
/** Only used when searching for available endpoints. */
|
|
381 |
TBool iSettingReserve;
|
|
382 |
/** True if endpoint is halted (i.e. issues STALL handshakes), false otherwise. */
|
|
383 |
TBool iHalt;
|
|
384 |
};
|
|
385 |
|
|
386 |
|
|
387 |
class DUsbClientController;
|
|
388 |
class TUsbcInterface;
|
|
389 |
|
|
390 |
/** This is a 'logical' endpoint, as used by our device configuration model.
|
|
391 |
*/
|
|
392 |
class TUsbcLogicalEndpoint
|
|
393 |
{
|
|
394 |
public:
|
|
395 |
TUsbcLogicalEndpoint(DUsbClientController* aController, TUint aEndpointNum,
|
|
396 |
const TUsbcEndpointInfo& aEpInfo, TUsbcInterface* aInterface,
|
|
397 |
TUsbcPhysicalEndpoint* aPEndpoint); // Check Todo, SC will pass pointer to derived class
|
|
398 |
~TUsbcLogicalEndpoint();
|
|
399 |
public:
|
|
400 |
/** Pointer to controller object. */
|
|
401 |
DUsbClientController* iController;
|
|
402 |
/** The virtual (logical) endpoint number. */
|
|
403 |
const TInt iLEndpointNum;
|
|
404 |
/** This endpoint's info structure. */
|
|
405 |
TUsbcEndpointInfo iInfo; // Check Todo, SC will pass pointer to derived class
|
|
406 |
/** Stores the endpoint size to be used for FS. */
|
|
407 |
TInt iEpSize_Fs;
|
|
408 |
/** Stores the endpoint size to be used for HS. */
|
|
409 |
TInt iEpSize_Hs;
|
|
410 |
/** 'Back' pointer. */
|
|
411 |
const TUsbcInterface* iInterface;
|
|
412 |
/** Pointer to corresponding physical endpoint, never NULL. */
|
|
413 |
TUsbcPhysicalEndpoint* const iPEndpoint;
|
|
414 |
};
|
|
415 |
|
|
416 |
|
|
417 |
class TUsbcInterfaceSet;
|
|
418 |
|
|
419 |
/** This is an 'alternate setting' of an interface.
|
|
420 |
*/
|
|
421 |
class TUsbcInterface
|
|
422 |
{
|
|
423 |
public:
|
|
424 |
TUsbcInterface(TUsbcInterfaceSet* aIfcSet, TUint8 aSetting, TBool aNoEp0Requests);
|
|
425 |
~TUsbcInterface();
|
|
426 |
public:
|
|
427 |
/** Array of endpoints making up (belonging to) this setting. */
|
|
428 |
RPointerArray<TUsbcLogicalEndpoint> iEndpoints;
|
|
429 |
/** 'Back' pointer. */
|
|
430 |
TUsbcInterfaceSet* const iInterfaceSet;
|
|
431 |
/** bAlternateSetting (zero-based). */
|
|
432 |
const TUint8 iSettingCode;
|
|
433 |
/** KUsbcInterfaceInfo_NoEp0RequestsPlease: stall non-std Setup requests. */
|
|
434 |
const TBool iNoEp0Requests;
|
|
435 |
};
|
|
436 |
|
|
437 |
|
|
438 |
/** This is an 'interface' (owning 1 or more alternate settings).
|
|
439 |
|
|
440 |
@see TUsbcInterface
|
|
441 |
*/
|
|
442 |
class TUsbcInterfaceSet
|
|
443 |
{
|
|
444 |
public:
|
|
445 |
TUsbcInterfaceSet(const DBase* aClientId, TUint8 aIfcNum);
|
|
446 |
~TUsbcInterfaceSet();
|
|
447 |
inline const TUsbcInterface* CurrentInterface() const;
|
|
448 |
inline TUsbcInterface* CurrentInterface();
|
|
449 |
public:
|
|
450 |
/** Array of alternate settings provided by (belonging to) this interface. */
|
|
451 |
RPointerArray<TUsbcInterface> iInterfaces;
|
|
452 |
/** Pointer to the LDD which created and owns this interface. */
|
|
453 |
const DBase* const iClientId;
|
|
454 |
/** bInterfaceNumber (zero-based). */
|
|
455 |
TUint8 iInterfaceNumber;
|
|
456 |
/** bAlternateSetting (zero-based). */
|
|
457 |
TUint8 iCurrentInterface;
|
|
458 |
};
|
|
459 |
|
|
460 |
|
|
461 |
/** This is a 'configuration' of the USB device.
|
|
462 |
Currently we support only one configuration.
|
|
463 |
*/
|
|
464 |
class TUsbcConfiguration
|
|
465 |
{
|
|
466 |
public:
|
|
467 |
TUsbcConfiguration(TUint8 aConfigVal);
|
|
468 |
~TUsbcConfiguration();
|
|
469 |
public:
|
|
470 |
/** Array of interfaces making up (belonging to) this configuration. */
|
|
471 |
RPointerArray<TUsbcInterfaceSet> iInterfaceSets;
|
|
472 |
/** bConfigurationValue (one-based). */
|
|
473 |
const TUint8 iConfigValue;
|
|
474 |
};
|
|
475 |
|
|
476 |
|
|
477 |
/** The USB controller's power handler class.
|
|
478 |
*/
|
|
479 |
NONSHARABLE_CLASS(DUsbcPowerHandler) : public DPowerHandler
|
|
480 |
{
|
|
481 |
public:
|
|
482 |
void PowerUp();
|
|
483 |
void PowerDown(TPowerState);
|
|
484 |
public:
|
|
485 |
DUsbcPowerHandler(DUsbClientController* aController);
|
|
486 |
private:
|
|
487 |
DUsbClientController* iController;
|
|
488 |
};
|
|
489 |
|
|
490 |
|
|
491 |
/*
|
|
492 |
This is the EndpointInfo class used by the usb shared chunk client driver.
|
|
493 |
*/
|
|
494 |
|
|
495 |
class TUsbcScEndpointInfo;
|
|
496 |
|
|
497 |
|
|
498 |
/**
|
|
499 |
Used to represent an array of (or inheriting from) TUsbcEndpointInfo objects.
|
|
500 |
|
|
501 |
@see DUsbClientController::SetInterface
|
|
502 |
*/
|
|
503 |
|
|
504 |
class TUsbcEndpointInfoArray
|
|
505 |
{
|
|
506 |
public:
|
|
507 |
typedef enum {EUsbcEndpointInfo, EUsbcScEndpointInfo} TArrayType;
|
|
508 |
|
|
509 |
TUsbcEndpointInfoArray(const TUsbcEndpointInfo* aData, TInt aDataSize=0);
|
|
510 |
TUsbcEndpointInfoArray(const TUsbcScEndpointInfo* aData, TInt aDataSize=0);
|
|
511 |
inline TUsbcEndpointInfo& operator[](TInt aIndex) const;
|
|
512 |
|
|
513 |
TArrayType iType;
|
|
514 |
private:
|
|
515 |
TUint8* iData;
|
|
516 |
TInt iDataSize;
|
|
517 |
};
|
|
518 |
|
|
519 |
class TUsbPeriDeviceEventQueue
|
|
520 |
{
|
|
521 |
public:
|
|
522 |
TUsbPeriDeviceEventQueue();
|
|
523 |
|
|
524 |
void FifoAdd(TUsbcDeviceEvent aDeviceStatus);
|
|
525 |
TUsbcDeviceEvent FifoGet();
|
|
526 |
|
|
527 |
private:
|
|
528 |
TUsbcDeviceEvent iDeviceEventQueue[KUsbDeviceEventQueueDepth];
|
|
529 |
TInt iDeviceQueueHead;
|
|
530 |
TInt iDeviceQueueTail;
|
|
531 |
};
|
|
532 |
|
|
533 |
class TUsbcRequestCallback; // todo?? required only for class below
|
|
534 |
|
|
535 |
/** The USB Device software controller class.
|
|
536 |
|
|
537 |
Implements the platform-independent layer (PIL), and defines the interface to the
|
|
538 |
platform-specific layer PSL).
|
|
539 |
|
|
540 |
The implementation of the platform-specific layer interfaces with the hardware.
|
|
541 |
*/
|
|
542 |
NONSHARABLE_CLASS(DUsbClientController) : public DBase,
|
|
543 |
public MUsbOtgPeripheralControlIf,
|
|
544 |
public UsbShai::MUsbPeripheralPilCallbackIf,
|
|
545 |
public MControlTransferIf,
|
|
546 |
public UsbShai::MChargerDetectorObserverIf
|
|
547 |
{
|
|
548 |
friend class UsbShai::UsbPeripheralPil;
|
|
549 |
friend class TUsbHostWrapperEntry;
|
|
550 |
friend class DUsbcPowerHandler;
|
|
551 |
friend TUsbcLogicalEndpoint::~TUsbcLogicalEndpoint();
|
|
552 |
//
|
|
553 |
// --- Platform Independent Layer (PIL) ---
|
|
554 |
//
|
|
555 |
|
|
556 |
|
|
557 |
private:
|
|
558 |
/**
|
|
559 |
* Two-phase constructor used by the friend classes that receive
|
|
560 |
* the registration calls for peripheral controllers.
|
|
561 |
*
|
|
562 |
* @param aPeripheralControllerIf Reference to the Peripheral
|
|
563 |
* Controller interface implemented by the registering PSL.
|
|
564 |
*
|
|
565 |
* @param aProperties Reference to an object describing the
|
|
566 |
* static properties of the Peripheral Controller. The PIL
|
|
567 |
* layer requires that the supplied reference remains valid
|
|
568 |
* indefinitely, as a Peripheral Controller cannot unregister.
|
|
569 |
*
|
|
570 |
* @param aIsOtgPort ETrue if this Peripheral Controller is part
|
|
571 |
* of an OTG port. EFalse otherwise.
|
|
572 |
*
|
|
573 |
* @return Pointer to a new instance or NULL if failed
|
|
574 |
*/
|
|
575 |
IMPORT_C static DUsbClientController* Create(UsbShai::MPeripheralControllerIf& aPeripheralControllerIf,
|
|
576 |
const UsbShai::TPeripheralControllerProperties& aProperties,
|
|
577 |
TBool aIsOtgPort);
|
|
578 |
|
|
579 |
|
|
580 |
public:
|
|
581 |
|
|
582 |
//
|
|
583 |
// --- The following functions constitute the PIL interface to the LDD ---
|
|
584 |
//
|
|
585 |
virtual ~DUsbClientController();
|
|
586 |
IMPORT_C void DisableClientStack();
|
|
587 |
IMPORT_C void EnableClientStack();
|
|
588 |
IMPORT_C TBool IsActive();
|
|
589 |
IMPORT_C TInt RegisterClientCallback(TUsbcClientCallback& aCallback);
|
|
590 |
IMPORT_C static DUsbClientController* UsbcControllerPointer(TInt aUdc=0);
|
|
591 |
IMPORT_C void EndpointCaps(const DBase* aClientId, TDes8 &aCapsBuf) const;
|
|
592 |
IMPORT_C void DeviceCaps(const DBase* aClientId, TDes8 &aCapsBuf) const;
|
|
593 |
IMPORT_C TInt SetInterface(const DBase* aClientId, DThread* aThread, TInt aInterfaceNum,
|
|
594 |
TUsbcClassInfo& aClass, TDesC8* aString, TInt aTotalEndpointsUsed,
|
|
595 |
const TUsbcEndpointInfo aEndpointData[], TInt (*aRealEpNumbers)[6],
|
|
596 |
TUint32 aFeatureWord);
|
|
597 |
IMPORT_C TInt SetInterface(const DBase* aClientId, DThread* aThread,
|
|
598 |
TInt aInterfaceNum, TUsbcClassInfo& aClass,
|
|
599 |
TDesC8* aString, TInt aTotalEndpointsUsed,
|
|
600 |
const TUsbcEndpointInfoArray aEndpointData,
|
|
601 |
TInt aRealEpNumbers[], TUint32 aFeatureWord);
|
|
602 |
IMPORT_C TInt ReleaseInterface(const DBase* aClientId, TInt aInterfaceNum);
|
|
603 |
IMPORT_C TInt ReEnumerate();
|
|
604 |
IMPORT_C TInt PowerUpUdc();
|
|
605 |
IMPORT_C TInt UsbConnect();
|
|
606 |
IMPORT_C TInt UsbDisconnect();
|
|
607 |
IMPORT_C TInt RegisterForStatusChange(TUsbcStatusCallback& aCallback);
|
|
608 |
IMPORT_C TInt DeRegisterForStatusChange(const DBase* aClientId);
|
|
609 |
IMPORT_C TInt RegisterForEndpointStatusChange(TUsbcEndpointStatusCallback& aCallback);
|
|
610 |
IMPORT_C TInt DeRegisterForEndpointStatusChange(const DBase* aClientId);
|
|
611 |
IMPORT_C TInt GetInterfaceNumber(const DBase* aClientId, TInt& aInterfaceNum) const;
|
|
612 |
IMPORT_C TInt DeRegisterClient(const DBase* aClientId);
|
|
613 |
IMPORT_C TInt Ep0PacketSize() const;
|
|
614 |
IMPORT_C TInt Ep0Stall(const DBase* aClientId);
|
|
615 |
IMPORT_C void SendEp0StatusPacket(const DBase* aClientId);
|
|
616 |
IMPORT_C UsbShai::TUsbPeripheralState GetDeviceStatus() const;
|
|
617 |
IMPORT_C TEndpointState GetEndpointStatus(const DBase* aClientId, TInt aEndpointNum) const;
|
|
618 |
IMPORT_C TInt SetupReadBuffer(TUsbcRequestCallback& aCallback);
|
|
619 |
IMPORT_C TInt SetupWriteBuffer(TUsbcRequestCallback& aCallback);
|
|
620 |
IMPORT_C void CancelReadBuffer(const DBase* aClientId, TInt aRealEndpoint);
|
|
621 |
IMPORT_C void CancelWriteBuffer(const DBase* aClientId, TInt aRealEndpoint);
|
|
622 |
IMPORT_C TInt HaltEndpoint(const DBase* aClientId, TInt aEndpointNum);
|
|
623 |
IMPORT_C TInt ClearHaltEndpoint(const DBase* aClientId, TInt aEndpointNum);
|
|
624 |
IMPORT_C TInt SetDeviceControl(const DBase* aClientId);
|
|
625 |
IMPORT_C TInt ReleaseDeviceControl(const DBase* aClientId);
|
|
626 |
IMPORT_C TUint EndpointZeroMaxPacketSizes() const;
|
|
627 |
IMPORT_C TInt SetEndpointZeroMaxPacketSize(TInt aMaxPacketSize);
|
|
628 |
IMPORT_C TInt GetDeviceDescriptor(DThread* aThread, TDes8& aDeviceDescriptor);
|
|
629 |
IMPORT_C TInt SetDeviceDescriptor(DThread* aThread, const TDes8& aDeviceDescriptor);
|
|
630 |
IMPORT_C TInt GetDeviceDescriptorSize(DThread* aThread, TDes8& aSize);
|
|
631 |
IMPORT_C TInt GetConfigurationDescriptor(DThread* aThread, TDes8& aConfigurationDescriptor);
|
|
632 |
IMPORT_C TInt SetConfigurationDescriptor(DThread* aThread, const TDes8& aConfigurationDescriptor);
|
|
633 |
IMPORT_C TInt GetConfigurationDescriptorSize(DThread* aThread, TDes8& aSize);
|
|
634 |
IMPORT_C TInt SetOtgDescriptor(DThread* aThread, const TDesC8& aOtgDesc);
|
|
635 |
IMPORT_C TInt GetOtgDescriptor(DThread* aThread, TDes8& aOtgDesc) const;
|
|
636 |
IMPORT_C TInt GetOtgFeatures(DThread* aThread, TDes8& aFeatures) const;
|
|
637 |
IMPORT_C TInt GetCurrentOtgFeatures(TUint8& aFeatures) const;
|
|
638 |
IMPORT_C TInt RegisterForOtgFeatureChange(TUsbcOtgFeatureCallback& aCallback);
|
|
639 |
IMPORT_C TInt DeRegisterForOtgFeatureChange(const DBase* aClientId);
|
|
640 |
IMPORT_C TInt GetInterfaceDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
|
|
641 |
TDes8& aInterfaceDescriptor);
|
|
642 |
IMPORT_C TInt SetInterfaceDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
|
|
643 |
const TDes8& aInterfaceDescriptor);
|
|
644 |
IMPORT_C TInt GetInterfaceDescriptorSize(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
|
|
645 |
TDes8& aSize);
|
|
646 |
IMPORT_C TInt GetEndpointDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
|
|
647 |
TInt aEndpointNum, TDes8& aEndpointDescriptor);
|
|
648 |
IMPORT_C TInt SetEndpointDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
|
|
649 |
TInt aEndpointNum, const TDes8& aEndpointDescriptor);
|
|
650 |
IMPORT_C TInt GetEndpointDescriptorSize(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
|
|
651 |
TInt aEndpointNum, TDes8& aSize);
|
|
652 |
IMPORT_C TInt GetDeviceQualifierDescriptor(DThread* aThread, TDes8& aDeviceQualifierDescriptor);
|
|
653 |
IMPORT_C TInt SetDeviceQualifierDescriptor(DThread* aThread, const TDes8& aDeviceQualifierDescriptor);
|
|
654 |
IMPORT_C TInt GetOtherSpeedConfigurationDescriptor(DThread* aThread, TDes8& aConfigurationDescriptor);
|
|
655 |
IMPORT_C TInt SetOtherSpeedConfigurationDescriptor(DThread* aThread, const TDes8& aConfigurationDescriptor);
|
|
656 |
IMPORT_C TInt GetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
|
|
657 |
TDes8& aInterfaceDescriptor);
|
|
658 |
IMPORT_C TInt SetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
|
|
659 |
const TDes8& aInterfaceDescriptor, TInt aSize);
|
|
660 |
IMPORT_C TInt GetCSInterfaceDescriptorBlockSize(DThread* aThread, const DBase* aClientId,
|
|
661 |
TInt aSettingNum, TDes8& aSize);
|
|
662 |
IMPORT_C TInt GetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
|
|
663 |
TInt aEndpointNum, TDes8& aEndpointDescriptor);
|
|
664 |
IMPORT_C TInt SetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
|
|
665 |
TInt aEndpointNum, const TDes8& aEndpointDescriptor,
|
|
666 |
TInt aSize);
|
|
667 |
IMPORT_C TInt GetCSEndpointDescriptorBlockSize(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
|
|
668 |
TInt aEndpointNum, TDes8& aSize);
|
|
669 |
IMPORT_C TInt GetStringDescriptorLangId(DThread* aThread, TDes8& aLangId);
|
|
670 |
IMPORT_C TInt SetStringDescriptorLangId(TUint16 aLangId);
|
|
671 |
IMPORT_C TInt GetManufacturerStringDescriptor(DThread* aThread, TDes8& aString);
|
|
672 |
IMPORT_C TInt SetManufacturerStringDescriptor(DThread* aThread, const TDes8& aString);
|
|
673 |
IMPORT_C TInt RemoveManufacturerStringDescriptor();
|
|
674 |
IMPORT_C TInt GetProductStringDescriptor(DThread* aThread, TDes8& aString);
|
|
675 |
IMPORT_C TInt SetProductStringDescriptor(DThread* aThread, const TDes8& aString);
|
|
676 |
IMPORT_C TInt RemoveProductStringDescriptor();
|
|
677 |
IMPORT_C TInt GetSerialNumberStringDescriptor(DThread* aThread, TDes8& aString);
|
|
678 |
IMPORT_C TInt SetSerialNumberStringDescriptor(DThread* aThread, const TDes8& aString);
|
|
679 |
IMPORT_C TInt RemoveSerialNumberStringDescriptor();
|
|
680 |
IMPORT_C TInt GetConfigurationStringDescriptor(DThread* aThread, TDes8& aString);
|
|
681 |
IMPORT_C TInt SetConfigurationStringDescriptor(DThread* aThread, const TDes8& aString);
|
|
682 |
IMPORT_C TInt RemoveConfigurationStringDescriptor();
|
|
683 |
IMPORT_C TInt GetStringDescriptor(DThread* aThread, TUint8 aIndex, TDes8& aString);
|
|
684 |
IMPORT_C TInt SetStringDescriptor(DThread* aThread, TUint8 aIndex, const TDes8& aString);
|
|
685 |
IMPORT_C TInt RemoveStringDescriptor(TUint8 aIndex);
|
|
686 |
IMPORT_C TBool QueryEndpointResource(const DBase* aClientId, TInt aEndpointNum,
|
|
687 |
TUsbcEndpointResource aResource);
|
|
688 |
IMPORT_C TInt EndpointPacketSize(const DBase* aClientId, TInt aEndpointNum);
|
|
689 |
|
|
690 |
// Called by LDD
|
|
691 |
IMPORT_C TDfcQue* DfcQ(TInt aIndex);
|
|
692 |
IMPORT_C void DumpRegisters();
|
|
693 |
IMPORT_C TInt SignalRemoteWakeup();
|
|
694 |
IMPORT_C TBool CurrentlyUsingHighSpeed();
|
|
695 |
|
|
696 |
TInt RegisterUdc(TInt aUdc);
|
|
697 |
|
|
698 |
protected:
|
|
699 |
|
|
700 |
// From base class MUsbPeripheralPilCallbackIf
|
|
701 |
void EnablePeripheralStack();
|
|
702 |
void DisablePeripheralStack();
|
|
703 |
void SetOtgObserver(MUsbOtgPeripheralObserverIf* aObserver);
|
|
704 |
|
|
705 |
// Function derived from MUsbPeripheralPilCallbackIf
|
|
706 |
UsbShai::TControlStage EnquireEp0NextStage(const TUint8* aSetupBuf) const;
|
|
707 |
TInt Ep0RequestComplete(TInt aRealEndpoint, TInt aCount, TInt aError,UsbShai::TControlPacketType aPktType);
|
|
708 |
void EndpointRequestComplete(UsbShai::TUsbPeripheralRequest* aCallback);
|
|
709 |
TInt DeviceEventNotification(TUsbcDeviceEvent aEvent);
|
|
710 |
void MoveToAddressState();
|
|
711 |
TInt ProcessSetConfiguration(const TUsbcSetup& aPacket);
|
|
712 |
void HandleHnpRequest(TInt aHnpState);
|
|
713 |
void GetEp0RxBufferInfo(TUint8*& aBuffer, TInt& aBufferLen);
|
|
714 |
void SetRmWakeupStatusEnabled(TBool aRmEnabled);
|
|
715 |
UsbShai::TUsbPeripheralState DeviceStatus() const;
|
|
716 |
TBool Ep0ReceivedNonStdRequest();
|
|
717 |
|
|
718 |
// Functions derived from MControlTransferIf
|
|
719 |
// PSL -> PIL
|
|
720 |
void ProcessDataInPacket(TInt aCount,TInt aErrCode);
|
|
721 |
void ProcessStatusInPacket(TInt aErrCode);
|
|
722 |
void ProcessDataOutPacket(TInt aCount,TInt aErrCode);
|
|
723 |
void ProcessStatusOutPacket(TInt aErrCode);
|
|
724 |
void ProcessSetupPacket(TInt aCount,TInt aErrCode);
|
|
725 |
|
|
726 |
// Request from PIL -> PSL
|
|
727 |
TInt ProcessSetupEndpointZeroRead();
|
|
728 |
TInt ProcessSetupEndpointZeroWrite(const TUint8* aBuffer, TInt aLength, TBool aZlpReqd=EFalse);
|
|
729 |
TInt ProcessSendEp0ZeroByteStatusPacket();
|
|
730 |
TInt ProcessStallEndpoint(TInt aRealEndpoint);
|
|
731 |
|
|
732 |
// Flow control PIL <--> PSL
|
|
733 |
void ProcessEp0SetupPacketProceed();
|
|
734 |
void ProcessEp0DataPacketProceed();
|
|
735 |
|
|
736 |
// Functions from MChargerDetectorObserverIf
|
|
737 |
void NotifyPortType(UsbShai::TPortType aPortType);
|
|
738 |
//
|
|
739 |
//
|
|
740 |
// --- Functions and data members provided by PIL, called by PSL ---
|
|
741 |
//
|
|
742 |
private:
|
|
743 |
struct TUsbPeripheralDescriptorPool
|
|
744 |
{
|
|
745 |
TUsbcDeviceDescriptor* iDeviceDesc;
|
|
746 |
TUsbcConfigDescriptor* iConfigDesc;
|
|
747 |
TUsbcLangIdDescriptor* iLangId;
|
|
748 |
TUsbcStringDescriptor* iManufacturer;
|
|
749 |
TUsbcStringDescriptor* iProduct;
|
|
750 |
TUsbcStringDescriptor* iSerialNum;
|
|
751 |
TUsbcStringDescriptor* iConfig;
|
|
752 |
TUsbcOtgDescriptor* iOtgDesc;
|
|
753 |
};
|
|
754 |
|
|
755 |
private:
|
|
756 |
// Internal functions that used in Construct only
|
|
757 |
// This function will new a set of descriptors
|
|
758 |
TBool CreateDescriptors(TUsbPeripheralDescriptorPool& aOutput);
|
|
759 |
|
|
760 |
TBool Initialise(TUsbPeripheralDescriptorPool& aDescPool,
|
|
761 |
const UsbShai::TUsbPeripheralEndpointCaps* aEndpointCaps,
|
|
762 |
TInt aTotalEndpoint);
|
|
763 |
|
|
764 |
DUsbClientController(UsbShai::MPeripheralControllerIf& aPeripheralControllerIf,
|
|
765 |
const UsbShai::TPeripheralControllerProperties& aProperties,
|
|
766 |
TBool aIsOtgPort);
|
|
767 |
|
|
768 |
TInt Construct();
|
|
769 |
|
|
770 |
void ProcessStandardRequest(TInt aCount,const TUsbcSetup& aPacket);
|
|
771 |
void ProcessNonStandardRequest(TInt aCount,const TUsbcSetup& aPacket);
|
|
772 |
|
|
773 |
const DBase* FindNonStandardRequestClient(TUint8 aPacketTypeDestination,const TUsbcSetup& aPacket);
|
|
774 |
|
|
775 |
TInt SetupEp0StateMachine();
|
|
776 |
|
|
777 |
private:
|
|
778 |
|
|
779 |
/** This info can be used by the PSL before sending ZLPs.
|
|
780 |
|
|
781 |
@publishedPartner @released
|
|
782 |
*/
|
|
783 |
TBool iEp0ReceivedNonStdRequest;
|
|
784 |
|
|
785 |
/** True if RMW is currently enabled (set by either PIL or PSL).
|
|
786 |
|
|
787 |
@publishedPartner @released
|
|
788 |
*/
|
|
789 |
TBool iRmWakeupStatus_Enabled;
|
|
790 |
|
|
791 |
/** Ep0 incoming (rx) data is placed here (one packet).
|
|
792 |
|
|
793 |
@publishedPartner @released
|
|
794 |
*/
|
|
795 |
TUint8 iEp0_RxBuf[KUsbcBufSzControl];
|
|
796 |
|
|
797 |
private:
|
|
798 |
|
|
799 |
//
|
|
800 |
// --- Private member functions (used by PIL) ---
|
|
801 |
//
|
|
802 |
TInt DeRegisterClientCallback(const DBase* aClientId);
|
|
803 |
TBool CheckEpAvailability(TInt aEndpointsUsed, const TUsbcEndpointInfoArray& aEndpointData, TInt aIfcNumber)
|
|
804 |
const;
|
|
805 |
TUsbcInterface* CreateInterface(const DBase* aClientId, TInt aIfc, TUint32 aFeatureWord);
|
|
806 |
TInt CreateEndpoints(TUsbcInterface* aIfc, TInt aEndpointsUsed, const TUsbcEndpointInfoArray& aEndpointData,
|
|
807 |
TInt *aRealEpNumbers);
|
|
808 |
TInt SetupIfcDescriptor(TUsbcInterface* aIfc, TUsbcClassInfo& aClass, DThread* aThread, TDesC8* aString,
|
|
809 |
const TUsbcEndpointInfoArray& aEndpointData);
|
|
810 |
TInt ClientId2InterfaceNumber(const DBase* aClientId) const;
|
|
811 |
TUsbcInterfaceSet* ClientId2InterfacePointer(const DBase* aClientId) const;
|
|
812 |
const DBase* InterfaceNumber2ClientId(TInt aIfcSet) const;
|
|
813 |
TUsbcInterfaceSet* InterfaceNumber2InterfacePointer(TInt aIfcSet) const;
|
|
814 |
inline const DBase* PEndpoint2ClientId(TInt aRealEndpoint) const;
|
|
815 |
inline TInt PEndpoint2LEndpoint(TInt aRealEndpoint) const;
|
|
816 |
TInt ActivateHardwareController();
|
|
817 |
void DeActivateHardwareController();
|
|
818 |
void DeleteInterfaceSet(TInt aIfcSet);
|
|
819 |
void DeleteInterface(TInt aIfcSet, TInt aIfc);
|
|
820 |
void CancelTransferRequests(TInt aRealEndpoint);
|
|
821 |
void DeleteRequestCallback(const DBase* aClientId, TInt aEndpointNum, UsbShai::TTransferDirection aTransferDir);
|
|
822 |
void DeleteRequestCallbacks(const DBase* aClientId);
|
|
823 |
void StatusNotify(UsbShai::TUsbPeripheralState aState, const DBase* aClientId=NULL);
|
|
824 |
void EpStatusNotify(TInt aRealEndpoint);
|
|
825 |
void OtgFeaturesNotify();
|
|
826 |
void RunClientCallbacks();
|
|
827 |
void ProcessDataTransferDone(TUsbcRequestCallback& aRcb);
|
|
828 |
void NextDeviceState(UsbShai::TUsbPeripheralState aNextState);
|
|
829 |
TInt ProcessSuspendEvent();
|
|
830 |
TInt ProcessSuspendEventProceed();
|
|
831 |
TInt ProcessResumeEvent();
|
|
832 |
TInt ProcessResetEvent(TBool aPslUpcall=ETrue);
|
|
833 |
TInt ProcessVbusRisenEvent();
|
|
834 |
TInt ProcessVbusFallenEvent();
|
|
835 |
|
|
836 |
void ProcessGetDeviceStatus(const TUsbcSetup& aPacket);
|
|
837 |
void ProcessGetInterfaceStatus(const TUsbcSetup& aPacket);
|
|
838 |
void ProcessGetEndpointStatus(const TUsbcSetup& aPacket);
|
|
839 |
void ProcessSetClearDevFeature(const TUsbcSetup& aPacket);
|
|
840 |
void ProcessSetClearIfcFeature(const TUsbcSetup& aPacket);
|
|
841 |
void ProcessSetClearEpFeature(const TUsbcSetup& aPacket);
|
|
842 |
void ProcessSetAddress(const TUsbcSetup& aPacket);
|
|
843 |
void ProcessGetDescriptor(const TUsbcSetup& aPacket);
|
|
844 |
void ProcessSetDescriptor(const TUsbcSetup& aPacket);
|
|
845 |
void ProcessGetConfiguration(const TUsbcSetup& aPacket);
|
|
846 |
void ProcessGetInterface(const TUsbcSetup& aPacket);
|
|
847 |
void ProcessSetInterface(const TUsbcSetup& aPacket);
|
|
848 |
void ProcessSynchFrame(const TUsbcSetup& aPacket);
|
|
849 |
|
|
850 |
void ProceedSetDescriptor();
|
|
851 |
void ProcessDeviceEventNotification(TUsbcDeviceEvent aEvent);
|
|
852 |
|
|
853 |
void SetClearHaltFeature(TInt aRealEndpoint, TUint8 aRequest);
|
|
854 |
TInt ClearHaltFeature(TInt aRealEndpoint);
|
|
855 |
void ChangeConfiguration(TUint16 aValue);
|
|
856 |
void InterfaceSetup(TUsbcInterface* aIfc);
|
|
857 |
void InterfaceSetTeardown(TUsbcInterfaceSet* aIfc);
|
|
858 |
void ChangeInterface(TUsbcInterface* aIfc);
|
|
859 |
TInt DoForEveryEndpointInUse(TInt (DUsbClientController::*aFunction)(TInt), TInt& aCount);
|
|
860 |
void EnterFullSpeed();
|
|
861 |
void EnterHighSpeed();
|
|
862 |
TInt EvaluateOtgConnectFlags();
|
|
863 |
inline const TUsbcConfiguration* CurrentConfig() const;
|
|
864 |
inline TUsbcConfiguration* CurrentConfig();
|
|
865 |
inline TBool InterfaceExists(TInt aNumber) const;
|
|
866 |
inline TBool EndpointExists(TUint aAddress) const;
|
|
867 |
void Buffer2Setup(const TAny* aBuf, TUsbcSetup& aSetup) const;
|
|
868 |
inline TUint EpIdx2Addr(TUint aRealEndpoint) const;
|
|
869 |
inline TUint EpAddr2Idx(TUint aAddress) const;
|
|
870 |
inline void SetEp0DataOutVars(const DBase* aClientId = NULL);
|
|
871 |
inline void ResetEp0DataOutVars();
|
|
872 |
inline TBool IsInTheStatusList(const TUsbcStatusCallback& aCallback);
|
|
873 |
inline TBool IsInTheEpStatusList(const TUsbcEndpointStatusCallback& aCallback);
|
|
874 |
inline TBool IsInTheOtgFeatureList(const TUsbcOtgFeatureCallback& aCallback);
|
|
875 |
inline TBool IsInTheRequestList(const TUsbcRequestCallback& aCallback);
|
|
876 |
static void ReconnectTimerCallback(TAny* aPtr);
|
|
877 |
static void CableStatusTimerCallback(TAny* aPtr);
|
|
878 |
static void PowerUpDfc(TAny* aPtr);
|
|
879 |
static void PowerDownDfc(TAny* aPtr);
|
|
880 |
static void DeviceEventNotifyDfc(TAny* aPtr);
|
|
881 |
static void ThreadContextFinderDfc(TAny* aPtr);
|
|
882 |
|
|
883 |
private:
|
|
884 |
|
|
885 |
//
|
|
886 |
// --- Private data members ---
|
|
887 |
//
|
|
888 |
|
|
889 |
static DUsbClientController* UsbClientController[KUsbcMaxUdcs];
|
|
890 |
|
|
891 |
TInt iDeviceTotalEndpoints; // number of endpoints reported by PSL
|
|
892 |
TInt iDeviceUsableEndpoints; // number of endpoints reported to LDD
|
|
893 |
|
|
894 |
UsbShai::TUsbPeripheralState iDeviceState; // states as of USB spec chapter 9.1
|
|
895 |
UsbShai::TUsbPeripheralState iDeviceStateB4Suspend; // state before entering suspend state
|
|
896 |
|
|
897 |
TBool iSelfPowered; // true if device is capable of beeing self-powered
|
|
898 |
TBool iRemoteWakeup; // true if device is capable of signalling rmwakeup
|
|
899 |
TBool iHardwareActivated; // true if controller silicon is in operating state
|
|
900 |
TBool iOtgSupport; // true if OTG is supported by this device
|
|
901 |
TUint8 iOtgFuncMap; // bitmap indicating OTG extension features
|
|
902 |
TBool iHighSpeed; // true if currently operating at high-speed
|
|
903 |
|
|
904 |
TInt iEp0MaxPacketSize; // currently configured max packet size for Ep0
|
|
905 |
const DBase* iEp0ClientId; // see comment at the begin of ps_usbc.cpp
|
|
906 |
TUint16 iEp0DataReceived; // indicates how many bytes have already been received
|
|
907 |
TBool iEp0WritePending; // true if a write on ep0 has been set up
|
|
908 |
TBool iEp0ClientDataTransmitting; // true if ep0's in DATA_IN on behalf of a client
|
|
909 |
const DBase* iEp0DeviceControl; // Device Ep0 requests are delivered to this LDD
|
|
910 |
|
|
911 |
TUsbcDescriptorPool iDescriptors; // the descriptors as of USB spec chapter 9.5
|
|
912 |
TUint8 iCurrentConfig; // bConfigurationValue of current Config (1-based!)
|
|
913 |
RPointerArray<TUsbcConfiguration> iConfigs; // the root of the modelled USB device
|
|
914 |
TUsbcPhysicalEndpoint iRealEndpoints[KUsbcEpArraySize]; // array will be filled once at startup
|
|
915 |
TUint8 iEp0_TxBuf[KUsbcBufSz_Ep0Tx]; // ep0 outgoing (tx) data is placed here
|
|
916 |
#ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
|
|
917 |
TUint8 iEp0_RxCollectionBuf[KUsbcBufSz_Ep0Rx]; // used for (optional) SET_DESCRIPTOR request
|
|
918 |
#endif
|
|
919 |
TInt iEp0_RxExtraCount; // number of bytes received but not yet delivered
|
|
920 |
TBool iEp0_RxExtraData; // true if iEp0_RxExtraCount is valid
|
|
921 |
TInt iEp0_TxNonStdCount; // number of bytes requested by non-std Ep0 request
|
|
922 |
|
|
923 |
TUsbcRequestCallback* iRequestCallbacks[KUsbcEpArraySize]; // xfer requests; indexed by real ep number
|
|
924 |
TSglQue<TUsbcRequestCallback> iEp0ReadRequestCallbacks; // list of ep0 read requests
|
|
925 |
TSglQue<TUsbcClientCallback> iClientCallbacks; // registered LDD clients and their callback functions
|
|
926 |
TSglQue<TUsbcStatusCallback> iStatusCallbacks; // list of device state notification requests
|
|
927 |
TSglQue<TUsbcEndpointStatusCallback> iEpStatusCallbacks; // list of endpoint state notification requests
|
|
928 |
TSglQue<TUsbcOtgFeatureCallback> iOtgCallbacks; // list of OTG feature change requests
|
|
929 |
|
|
930 |
NTimer iReconnectTimer; // implements USB re-enumeration delay
|
|
931 |
NTimer iCableStatusTimer; // implements USB cable status detection delay
|
|
932 |
DUsbcPowerHandler* iPowerHandler; // pointer to USB power handler object
|
|
933 |
TSpinLock iUsbLock; // implement SMP for USB PDD and LDD
|
|
934 |
NFastMutex iMutex; // To pretect interface set with NFastMutex
|
|
935 |
UsbShai::MPeripheralControllerIf& iController; // PSL code
|
|
936 |
|
|
937 |
const UsbShai::TPeripheralControllerProperties& iControllerProperties; // Static configuration from PSL
|
|
938 |
TBool iIsOtgPort; // Is this instance a driver for otg port,
|
|
939 |
// Set at construction time.
|
|
940 |
|
|
941 |
/**
|
|
942 |
* Pointer to the currently set OTG Observer, if any. Not owned.
|
|
943 |
*/
|
|
944 |
MUsbOtgPeripheralObserverIf* iOtgObserver; // Otg interface which is used to listen event from DeviceEventNotification
|
|
945 |
|
|
946 |
DControlTransferManager* iConTransferMgr; // Usb Control transfer manager, responsible for chaptor9
|
|
947 |
|
|
948 |
TInt iLastError; // Used by chaptor9 sm. No else.
|
|
949 |
TBool iSetupPacketPending; // Indicate whether the no-req-callback data is a setup packet
|
|
950 |
|
|
951 |
TUsbPeriDeviceEventQueue iDevEventQueue; // PSL can call DeviceEventNotification(...) at any context,
|
|
952 |
// but for PIL, we want to serialize the execution of each event
|
|
953 |
|
|
954 |
// The thread context for the DfcQ pass by PSL to us.
|
|
955 |
NThread* iCommonDfcQThread;
|
|
956 |
|
|
957 |
protected:
|
|
958 |
TDfc iPowerUpDfc; // queued by power handler upon power-up
|
|
959 |
TDfc iPowerDownDfc; // queued by power handler upon power-down
|
|
960 |
TDfc iDeviceEventNotifyDfc; // queued by device event notification
|
|
961 |
TDfc iThreadContextFinder; // this is used to find which thread does the DfcQ passed by PSL
|
|
962 |
// is runing.
|
|
963 |
|
|
964 |
private:
|
|
965 |
TBool iStandby; // toggled by power handler as appropriate
|
|
966 |
TBool iStackIsActive; // client stack's function is usable
|
|
967 |
TBool iClientSupportReady; // user-side USB Client support is loaded & active
|
|
968 |
TBool iUsbResetDeferred; // set when user-side wasn't ready yet
|
|
969 |
|
|
970 |
public:
|
|
971 |
// FIXME: These used to be filled by the OTG component Dummy DCD
|
|
972 |
// so that the PIL layer can call it to enable and disable the D+
|
|
973 |
// pull-up. This mechanism is no longer used
|
|
974 |
TInt (*iEnablePullUpOnDPlus)(TAny* aOtgContext);
|
|
975 |
TInt (*iDisablePullUpOnDPlus)(TAny* aOtgContext);
|
|
976 |
TAny* iOtgContext;
|
|
977 |
};
|
|
978 |
|
|
979 |
/** Simple queue of status changes to be recorded.
|
|
980 |
Items are fetched by userside when able.
|
|
981 |
*/
|
|
982 |
class TUsbcDeviceStatusQueue
|
|
983 |
{
|
|
984 |
public:
|
|
985 |
TUsbcDeviceStatusQueue();
|
|
986 |
void AddStatusToQueue(TUint32 aDeviceStatus);
|
|
987 |
TInt GetDeviceQueuedStatus(TUint32& aDeviceStatus);
|
|
988 |
void FlushQueue();
|
|
989 |
|
|
990 |
private:
|
|
991 |
TUint32 iDeviceStatusQueue[KUsbDeviceStatusQueueDepth];
|
|
992 |
TInt iStatusQueueHead;
|
|
993 |
};
|
|
994 |
|
|
995 |
#include <usb/usbcshared.inl>
|
|
996 |
|
|
997 |
#endif // __USBCSHARED_H__
|