|
1 // Copyright (c) 2004-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 // omap3530/omap3530_drivers/usbcc/pa_usbc.cpp |
|
15 // |
|
16 |
|
17 #include <usbc.h> |
|
18 //#include <resourceman.h> |
|
19 #include <assp/omap3530_assp/omap3530_assp_priv.h> |
|
20 #include <assp/omap3530_assp/omap3530_irqmap.h> |
|
21 #include <assp/omap3530_assp/omap3530_usbc.h> |
|
22 //#include <assp/omap3530_assp/omap3530_prm.h> |
|
23 #include <assp/omap3530_assp/omap3530_prcm.h> |
|
24 |
|
25 |
|
26 // Debug support |
|
27 #ifdef _DEBUG |
|
28 static const char KUsbPanicCat[] = "USB PSL"; |
|
29 #endif |
|
30 |
|
31 _LIT(KDfcName, "USB_DFC"); |
|
32 |
|
33 // Register definitions - move to a seperate header file at some point.. |
|
34 |
|
35 const TUint KCM_ICLKEN1_CORE = Omap3530HwBase::TVirtual<0x48004A10>::Value; |
|
36 const TUint KENHOSTOTGUSB_BIT = KBit4; |
|
37 const TUint KCM_AUTOIDLE1_CORE = Omap3530HwBase::TVirtual<0x48004A30>::Value; |
|
38 const TUint KAUTO_HOSTOTGUSB_BIT = KBit4; |
|
39 |
|
40 |
|
41 const TInt KSetupPacketSize = 8; |
|
42 const TInt KMaxPayload = 0x400; |
|
43 const TInt KUsbDfcPriority = 45; |
|
44 const TUint KUSBBase = Omap3530HwBase::TVirtual<0x480AB000>::Value; |
|
45 |
|
46 // USB registers - need the slave clock enabled to access most of these |
|
47 const TUint KFADDR_REG = 0x0; |
|
48 const TUint KADDRESS_MSK = 0x7F; |
|
49 const TUint KPOWER_REG = 0x1; |
|
50 const TUint KSOFTCONNECT_BIT = KBit6; |
|
51 const TUint KSUSPENDM_BIT = KBit1; |
|
52 const TUint KRESUME_BIT = KBit2; |
|
53 const TUint KHSEN_BIT = KBit5; |
|
54 // const TUint KRESET_BIT = KBit3; |
|
55 const TUint K_INTRTX_REG =0x2; |
|
56 const TUint K_INTRRX_REG =0x4; |
|
57 const TUint K_INTRTXE_REG =0x6; |
|
58 const TUint K_INTRRXE_REG =0x8; |
|
59 const TUint K_INTRUSB_REG = 0xA; |
|
60 const TUint K_INTRUSBE_REG = 0xB; |
|
61 const TUint K_INT_RESET = KBit2; |
|
62 const TUint K_INT_RESUME = KBit1; |
|
63 const TUint K_INT_SUSPEND = KBit0; |
|
64 //const TUint K_DEVCTRL_REG = 0x60; |
|
65 const TUint K_FIFO0_REG = 0x20; |
|
66 const TUint K_FIFO_OFFSET = 0x4; |
|
67 const TUint K_COUNT0_REG = 0x18; |
|
68 const TUint K_RXCOUNT_REG = 0x18; |
|
69 const TUint K_CONFIGDATA_REG = 0x1F; |
|
70 const TUint K_MPRXE = KBit7; |
|
71 const TUint K_MPTXE = KBit6; |
|
72 const TUint K_DYNFIFO = KBit2; |
|
73 const TUint K_SOFTCONNECT = KBit1; |
|
74 const TUint K_INDEX_REG = 0xE; |
|
75 const TUint K_PERI_CSR0_REG = 0x12; |
|
76 const TUint K_EP0_FLUSHFIFO = KBit8; |
|
77 const TUint K_EP0_SERV_SETUPEND = KBit7; |
|
78 const TUint K_EP0_SERV_RXPKTRDY = KBit6; |
|
79 const TUint K_EP0_SETUPEND = KBit4; |
|
80 const TUint K_EP0_SENDSTALL = KBit5; |
|
81 const TUint K_EP0_DATAEND = KBit3; |
|
82 const TUint K_EP0_SENTSTALL = KBit2; |
|
83 const TUint K_EP0_TXPKTRDY = KBit1; |
|
84 const TUint K_EP0_RXPKTRDY = KBit0; |
|
85 const TUint K_TXMAXP_REG = 0x10; |
|
86 const TUint K_RXMAXP_REG = 0x14; |
|
87 const TUint K_PERI_TXCSR_REG = 0x12; |
|
88 const TUint K_TX_ISO = KBit14; |
|
89 const TUint K_TX_DMAEN = KBit12; |
|
90 const TUint K_TX_DMAMODE = KBit10; |
|
91 const TUint K_TX_CLRDATATOG = KBit6; |
|
92 const TUint K_TX_SENTSTALL = KBit5; |
|
93 const TUint K_TX_SENDSTALL = KBit4; |
|
94 const TUint K_TX_FLUSHFIFO = KBit3; |
|
95 const TUint K_TX_UNDERRUN = KBit2; |
|
96 // const TUint K_TX_FIFONOTEMPTY = KBit1; |
|
97 const TUint K_TX_TXPKTRDY = KBit0; |
|
98 const TUint K_PERI_RXCSR_REG = 0x16; |
|
99 const TUint K_RX_ISO = KBit14; |
|
100 const TUint K_RX_DMAEN = KBit13; |
|
101 const TUint K_RX_DISNYET = KBit12; |
|
102 const TUint K_RX_CLRDATATOG = KBit7; |
|
103 const TUint K_RX_SENTSTALL = KBit6; |
|
104 const TUint K_RX_SENDSTALL = KBit5; |
|
105 const TUint K_RX_FLUSHFIFO = KBit4; |
|
106 const TUint K_RX_OVERRUN = KBit2; |
|
107 const TUint K_RX_RXPKTRDY = KBit0; |
|
108 const TUint K_TXFIFOSZ_REG = 0x62; |
|
109 const TUint K_RXFIFOSZ_REG = 0x63; |
|
110 const TUint K_TXFIFOADDR_REG = 0x64; |
|
111 const TUint K_RXFIFOADDR_REG = 0x66; |
|
112 const TUint K_OTG_SYSCONFIG_REG = 0x404; |
|
113 const TUint K_ENABLEWAKEUP = KBit2; |
|
114 //const TUint K_OTG_SYSSTATUS_REG = 0x408; |
|
115 |
|
116 // End of Register definitions |
|
117 |
|
118 // Define USB_SUPPORTS_PREMATURE_STATUS_IN to enable proper handling of a premature STATUS_IN stage, i.e. a |
|
119 // situation where the host sends less data than first announced and instead of more data (OUT) will send an |
|
120 // IN token to start the status stage. What we do in order to implement this here is to prime the TX fifo with |
|
121 // a ZLP immediately when we find out that we're dealing with a DATA_OUT request. This way, as soon as the |
|
122 // premature IN token is received, we complete the transaction by sending off the ZLP. If we don't prime the |
|
123 // TX fifo then there is no way for us to recognise a premature status because the IN token itself doesn't |
|
124 // raise an interrupt. We would simply wait forever for more data, or rather we would time out and the host |
|
125 // would move on and send the next Setup packet. |
|
126 // The reason why we would not want to implement the proper behaviour is this: After having primed the TX fifo |
|
127 // with a ZLP, it is impossible for a user to reject such a (class/vendor specific) Setup request, basically |
|
128 // because the successful status stage happens automatically. At the time the user has received and decoded |
|
129 // the Setup request there's for her no way to stall Ep0 in order to show to the host that this Setup packet |
|
130 // is invalid or inappropriate or whatever, because she cannot prevent the status stage from happening. |
|
131 // (All this is strictly true only if the amount of data in the data stage is less than or equal to Ep0's max |
|
132 // packet size. However this is almost always the case.) |
|
133 //#define USB_SUPPORTS_PREMATURE_STATUS_IN |
|
134 |
|
135 |
|
136 static const TUsbcEndpointCaps DeviceEndpoints[KUsbTotalEndpoints] = |
|
137 { |
|
138 // Hardware # iEndpoints index |
|
139 {KEp0MaxPktSzMask, (KUsbEpTypeControl | KUsbEpDirOut)}, // 0 - 0 |
|
140 {KEp0MaxPktSzMask, (KUsbEpTypeControl | KUsbEpDirIn )}, // 0 - 1 |
|
141 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)}, // 1 - 2 |
|
142 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirIn )}, // 2 - 3 |
|
143 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)}, // 3 - 4 |
|
144 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirIn )}, // 4 - 5 |
|
145 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)}, // 5 - 6 |
|
146 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirIn )}, // 6 - 7 |
|
147 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)}, // 7 - 8 |
|
148 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirIn )}, // 8 - 9 |
|
149 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)}, // 9 - 10 |
|
150 {KEp0MaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirIn )}, // 10 - 11 |
|
151 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)}, // 11 - 12 |
|
152 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirIn )}, // 12 - 13 |
|
153 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)}, // 13 - 14 |
|
154 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirIn )}, // 14 - 15 |
|
155 // Disabled due to limited FIFO space |
|
156 /*{KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)}, // 15 - 16 |
|
157 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirIn )}, // 16 - 17 |
|
158 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)}, // 17 - 18 |
|
159 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirIn )}, // 18 - 19 |
|
160 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)}, // 19 - 20 |
|
161 {KEp0MaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirIn )}, // 20 - 21 |
|
162 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)}, // 21 - 22 |
|
163 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirIn )}, // 22 - 23 |
|
164 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)}, // 23 - 24 |
|
165 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirIn )}, // 24 - 25 |
|
166 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)}, // 25 - 26 |
|
167 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirIn )}, // 26 - 27 |
|
168 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)}, // 27 - 28 |
|
169 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirIn )}, // 28 - 29 |
|
170 {KBlkMaxPktSzMask, (KUsbEpTypeBulk | KUsbEpDirOut)}, // 29 - 30 |
|
171 {KIntMaxPktSzMask, (KUsbEpTypeInterrupt | KUsbEpDirIn )} // 30- 31*/ |
|
172 }; |
|
173 |
|
174 |
|
175 // --- TEndpoint -------------------------------------------------------------- |
|
176 |
|
177 TEndpoint::TEndpoint() |
|
178 // |
|
179 // Constructor |
|
180 // |
|
181 : iRxBuf(NULL), iReceived(0), iLength(0), iZlpReqd(EFalse), iNoBuffer(EFalse), iDisabled(EFalse), |
|
182 iPackets(0), iLastError(KErrNone), iRequest(NULL), iRxTimer(RxTimerCallback, this), |
|
183 iRxTimerSet(EFalse), iRxMoreDataRcvd(EFalse), iPacketIndex(NULL), iPacketSize(NULL) |
|
184 { |
|
185 __KTRACE_OPT(KUSB, Kern::Printf("TEndpoint::TEndpoint")); |
|
186 } |
|
187 |
|
188 |
|
189 void TEndpoint::RxTimerCallback(TAny* aPtr) |
|
190 // |
|
191 // (This function is static.) |
|
192 // |
|
193 { |
|
194 TEndpoint* const ep = static_cast<TEndpoint*>(aPtr); |
|
195 if (!ep) |
|
196 { |
|
197 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: !ep")); |
|
198 } |
|
199 else if (!ep->iRxTimerSet) |
|
200 { |
|
201 // Timer 'stop' substitute (instead of stopping it, |
|
202 // we just let it expire after clearing iRxTimerSet) |
|
203 __KTRACE_OPT(KUSB, Kern::Printf("!ep->iRxTimerSet - returning")); |
|
204 } |
|
205 else if (!ep->iRxBuf) |
|
206 { |
|
207 // Request already completed |
|
208 __KTRACE_OPT(KUSB, Kern::Printf("!ep->iRxBuf - returning")); |
|
209 } |
|
210 else if (ep->iRxMoreDataRcvd) |
|
211 { |
|
212 __KTRACE_OPT(KUSB, Kern::Printf(" > rx timer cb: not yet completing...")); |
|
213 ep->iRxMoreDataRcvd = EFalse; |
|
214 ep->iRxTimer.Again(KRxTimerTimeout); |
|
215 } |
|
216 else |
|
217 { |
|
218 __KTRACE_OPT(KUSB, Kern::Printf(" > rx timer cb: completing now...")); |
|
219 *ep->iPacketSize = ep->iReceived; |
|
220 ep->iController->RxComplete(ep); |
|
221 } |
|
222 } |
|
223 |
|
224 |
|
225 // --- DOmap3530Usbcc public --------------------------------------------------- |
|
226 |
|
227 DOmap3530Usbcc::DOmap3530Usbcc() |
|
228 // |
|
229 // Constructor. |
|
230 // |
|
231 : iCableConnected(ETrue), iBusIsPowered(EFalse), |
|
232 iInitialized(EFalse), iUsbClientConnectorCallback(UsbClientConnectorCallback), |
|
233 iAssp( static_cast<Omap3530Assp*>( Arch::TheAsic() ) ), |
|
234 iEp0Configured(EFalse), iSuspendDfc(SuspendDfcFn, this, 7), |
|
235 iResumeDfc(ResumeDfcFn, this, 7), iResetDfc(ResetDfcFn, this, 7) |
|
236 { |
|
237 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::DOmap3530Usbcc")); |
|
238 |
|
239 TInt r = Kern::DfcQCreate(iDfcQueue, KUsbDfcPriority, &KDfcName); |
|
240 |
|
241 iSuspendDfc.SetDfcQ(iDfcQueue); |
|
242 iResetDfc.SetDfcQ(iDfcQueue); |
|
243 iResumeDfc.SetDfcQ(iDfcQueue); |
|
244 |
|
245 iSoftwareConnectable = iAssp->UsbSoftwareConnectable(); |
|
246 |
|
247 iCableDetectable = iAssp->UsbClientConnectorDetectable(); |
|
248 |
|
249 if (iCableDetectable) |
|
250 { |
|
251 // Register our callback for detecting USB cable insertion/removal. |
|
252 // We ignore the error code: if the registration fails, we just won't get any events. |
|
253 // (Which of course is bad enough...) |
|
254 (void) iAssp->RegisterUsbClientConnectorCallback(iUsbClientConnectorCallback, this); |
|
255 // Call the callback straight away so we get the proper PIL state from the beginning. |
|
256 (void) UsbClientConnectorCallback(this); |
|
257 } |
|
258 |
|
259 for (TInt i = 0; i < KUsbTotalEndpoints; i++) |
|
260 { |
|
261 iEndpoints[i].iController = this; |
|
262 } |
|
263 |
|
264 __KTRACE_OPT(KUSB, Kern::Printf("-DOmap3530Usbcc::DOmap3530Usbcc")); |
|
265 } |
|
266 |
|
267 |
|
268 TInt DOmap3530Usbcc::Construct() |
|
269 // |
|
270 // Construct. |
|
271 // |
|
272 { |
|
273 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::Construct")); |
|
274 |
|
275 iPhy = MOmap3530UsbPhy::New(); |
|
276 if( !iPhy ) |
|
277 { |
|
278 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Failed to get pointer to USB PHY")); |
|
279 return KErrNoMemory; |
|
280 } |
|
281 |
|
282 //TInt r = PowerResourceManager::RegisterClient( iPrmClientId, KDfcName ); |
|
283 //if( r != KErrNone ) |
|
284 // { |
|
285 // __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Failed to connect to PRM")); |
|
286 // return r; |
|
287 // } |
|
288 |
|
289 |
|
290 TUsbcDeviceDescriptor* DeviceDesc = TUsbcDeviceDescriptor::New( |
|
291 0x00, // aDeviceClass |
|
292 0x00, // aDeviceSubClass |
|
293 0x00, // aDeviceProtocol |
|
294 KEp0MaxPktSz, // aMaxPacketSize0 |
|
295 KUsbVendorId, // aVendorId |
|
296 KUsbProductId, // aProductId |
|
297 KUsbDevRelease, // aDeviceRelease |
|
298 1); // aNumConfigurations |
|
299 if (!DeviceDesc) |
|
300 { |
|
301 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Memory allocation for dev desc failed.")); |
|
302 return KErrGeneral; |
|
303 } |
|
304 |
|
305 TUsbcConfigDescriptor* ConfigDesc = TUsbcConfigDescriptor::New( |
|
306 1, // aConfigurationValue |
|
307 ETrue, // aSelfPowered (see 12.4.2 "Bus-Powered Devices") |
|
308 ETrue, // aRemoteWakeup |
|
309 0); // aMaxPower (mA) |
|
310 if (!ConfigDesc) |
|
311 { |
|
312 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Memory allocation for config desc failed.")); |
|
313 return KErrGeneral; |
|
314 } |
|
315 |
|
316 TUsbcLangIdDescriptor* StringDescLang = TUsbcLangIdDescriptor::New(KUsbLangId); |
|
317 if (!StringDescLang) |
|
318 { |
|
319 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Memory allocation for lang id $ desc failed.")); |
|
320 return KErrGeneral; |
|
321 } |
|
322 |
|
323 // ('sizeof(x) - 2' because 'wchar_t KStringXyz' created a wide string that ends in '\0\0'.) |
|
324 |
|
325 TUsbcStringDescriptor* StringDescManu = |
|
326 TUsbcStringDescriptor::New(TPtr8( |
|
327 const_cast<TUint8*>(reinterpret_cast<const TUint8*>(KStringManufacturer)), |
|
328 sizeof(KStringManufacturer) - 2, sizeof(KStringManufacturer) - 2)); |
|
329 if (!StringDescManu) |
|
330 { |
|
331 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Memory allocation for manufacturer $ desc failed.")); |
|
332 return KErrGeneral; |
|
333 } |
|
334 |
|
335 TUsbcStringDescriptor* StringDescProd = |
|
336 TUsbcStringDescriptor::New(TPtr8( |
|
337 const_cast<TUint8*>(reinterpret_cast<const TUint8*>(KStringProduct)), |
|
338 sizeof(KStringProduct) - 2, sizeof(KStringProduct) - 2)); |
|
339 if (!StringDescProd) |
|
340 { |
|
341 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Memory allocation for product $ desc failed.")); |
|
342 return KErrGeneral; |
|
343 } |
|
344 |
|
345 TUsbcStringDescriptor* StringDescSer = |
|
346 TUsbcStringDescriptor::New(TPtr8( |
|
347 const_cast<TUint8*>(reinterpret_cast<const TUint8*>(KStringSerialNo)), |
|
348 sizeof(KStringSerialNo) - 2, sizeof(KStringSerialNo) - 2)); |
|
349 if (!StringDescSer) |
|
350 { |
|
351 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Memory allocation for serial no $ desc failed.")); |
|
352 return KErrGeneral; |
|
353 } |
|
354 |
|
355 TUsbcStringDescriptor* StringDescConf = |
|
356 TUsbcStringDescriptor::New(TPtr8( |
|
357 const_cast<TUint8*>(reinterpret_cast<const TUint8*>(KStringConfig)), |
|
358 sizeof(KStringConfig) - 2, sizeof(KStringConfig) - 2)); |
|
359 if (!StringDescConf) |
|
360 { |
|
361 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Memory allocation for config $ desc failed.")); |
|
362 return KErrGeneral; |
|
363 } |
|
364 |
|
365 const TBool b = InitialiseBaseClass(DeviceDesc, |
|
366 ConfigDesc, |
|
367 StringDescLang, |
|
368 StringDescManu, |
|
369 StringDescProd, |
|
370 StringDescSer, |
|
371 StringDescConf); |
|
372 if (!b) |
|
373 { |
|
374 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: UsbClientController::InitialiseBaseClass failed.")); |
|
375 return KErrGeneral; |
|
376 } |
|
377 |
|
378 return KErrNone; |
|
379 } |
|
380 |
|
381 |
|
382 DOmap3530Usbcc::~DOmap3530Usbcc() |
|
383 // |
|
384 // Destructor. |
|
385 // |
|
386 { |
|
387 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::~DOmap3530Usbcc")); |
|
388 |
|
389 // Unregister our callback for detecting USB cable insertion/removal |
|
390 if (iCableDetectable) |
|
391 { |
|
392 iAssp->UnregisterUsbClientConnectorCallback(); |
|
393 } |
|
394 if (iInitialized) |
|
395 { |
|
396 // (The explicit scope operator is used against Lint warning #1506.) |
|
397 DOmap3530Usbcc::StopUdc(); |
|
398 } |
|
399 } |
|
400 |
|
401 |
|
402 TBool DOmap3530Usbcc::DeviceStateChangeCaps() const |
|
403 // |
|
404 // Returns capability of hardware to accurately track the device state (Chapter 9 state). |
|
405 // |
|
406 { |
|
407 return EFalse; |
|
408 } |
|
409 |
|
410 |
|
411 TInt DOmap3530Usbcc::SignalRemoteWakeup() |
|
412 // |
|
413 // Forces the UDC into a non-idle state to perform a remote wakeup operation. |
|
414 // |
|
415 { |
|
416 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::SignalRemoteWakeup")); |
|
417 Kern::Printf("DOmap3530Usbcc::SignalRemoteWakeup"); |
|
418 // Resume signal |
|
419 |
|
420 TInt sysconfig = AsspRegister::Read32(KUSBBase+K_OTG_SYSCONFIG_REG ); |
|
421 if(sysconfig&K_ENABLEWAKEUP && iRmWakeupStatus_Enabled) |
|
422 { |
|
423 AsspRegister::Modify8(KUSBBase+KPOWER_REG, KClearNone , KRESUME_BIT); |
|
424 Kern::NanoWait(10000000); // Wait 10ms - Use a callback instead! |
|
425 AsspRegister::Modify8(KUSBBase+KPOWER_REG, KRESUME_BIT, KSetNone); |
|
426 } |
|
427 return KErrNone; |
|
428 } |
|
429 |
|
430 |
|
431 void DOmap3530Usbcc::DumpRegisters() |
|
432 // |
|
433 // Dumps the contents of a number of UDC registers to the screen (using Kern::Printf()). |
|
434 // Rarely used, but might prove helpful when needed. |
|
435 // |
|
436 { |
|
437 Kern::Printf("DOmap3530Usbcc::DumpRegisters:"); |
|
438 } |
|
439 |
|
440 |
|
441 TDfcQue* DOmap3530Usbcc::DfcQ(TInt /* aUnit */) |
|
442 // |
|
443 // Returns a pointer to the kernel DFC queue to be used buy the USB LDD. |
|
444 // |
|
445 { |
|
446 return iDfcQueue; |
|
447 } |
|
448 |
|
449 |
|
450 // --- DOmap3530Usbcc private virtual ------------------------------------------ |
|
451 |
|
452 TInt DOmap3530Usbcc::SetDeviceAddress(TInt aAddress) |
|
453 // |
|
454 // Sets the PIL-provided device address manually (if possible - otherwise do nothing). |
|
455 // |
|
456 { |
|
457 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::SetDeviceAddress: %d", aAddress)); |
|
458 |
|
459 AsspRegister::Write8(KUSBBase+KFADDR_REG, aAddress & KADDRESS_MSK); |
|
460 |
|
461 if (aAddress || GetDeviceStatus()==EUsbcDeviceStateAddress) |
|
462 { |
|
463 // Address can be zero. |
|
464 MoveToAddressState(); |
|
465 } |
|
466 |
|
467 return KErrNone; |
|
468 } |
|
469 |
|
470 |
|
471 TInt DOmap3530Usbcc::ConfigureEndpoint(TInt aRealEndpoint, const TUsbcEndpointInfo& aEndpointInfo) |
|
472 // |
|
473 // Prepares (enables) an endpoint (incl. Ep0) for data transmission or reception. |
|
474 // |
|
475 { |
|
476 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::ConfigureEndpoint(%d)", aRealEndpoint)); |
|
477 |
|
478 const TInt n = ArrayIdx2TemplateEp(aRealEndpoint); |
|
479 if (n < 0) |
|
480 return KErrArgument; |
|
481 |
|
482 TEndpoint* const ep = &iEndpoints[aRealEndpoint]; |
|
483 if (ep->iDisabled == EFalse) |
|
484 { |
|
485 EnableEndpointInterrupt(aRealEndpoint); |
|
486 if(n!=0) |
|
487 { |
|
488 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aRealEndpoint/2)); |
|
489 if(aRealEndpoint%2==0) |
|
490 { |
|
491 |
|
492 AsspRegister::Write16(KUSBBase+K_PERI_RXCSR_REG, K_RX_CLRDATATOG | K_RX_DISNYET); |
|
493 } |
|
494 else |
|
495 { |
|
496 AsspRegister::Write16(KUSBBase+K_PERI_TXCSR_REG, K_TX_CLRDATATOG); |
|
497 } |
|
498 } |
|
499 else |
|
500 { |
|
501 AsspRegister::Write8(KUSBBase+K_INDEX_REG, 0x0); |
|
502 AsspRegister::Write16(KUSBBase+K_PERI_CSR0_REG, K_EP0_FLUSHFIFO); // FlushFifo; |
|
503 } |
|
504 } |
|
505 ep->iNoBuffer = EFalse; |
|
506 if (n == 0) |
|
507 iEp0Configured = ETrue; |
|
508 |
|
509 return KErrNone; |
|
510 } |
|
511 |
|
512 |
|
513 TInt DOmap3530Usbcc::DeConfigureEndpoint(TInt aRealEndpoint) |
|
514 // |
|
515 // Disables an endpoint (incl. Ep0). |
|
516 // |
|
517 { |
|
518 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::DeConfigureEndpoint(%d)", aRealEndpoint)); |
|
519 |
|
520 const TInt n = ArrayIdx2TemplateEp(aRealEndpoint); |
|
521 if (n < 0) |
|
522 return KErrArgument; |
|
523 |
|
524 DisableEndpointInterrupt(aRealEndpoint); |
|
525 if (n == 0) |
|
526 { |
|
527 iEp0Configured = EFalse; |
|
528 AsspRegister::Write8(KUSBBase+K_INDEX_REG, 0); |
|
529 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_FLUSHFIFO); |
|
530 } |
|
531 else |
|
532 { |
|
533 if(aRealEndpoint%2==0) |
|
534 { |
|
535 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aRealEndpoint/2)); |
|
536 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, KClearNone, K_RX_FLUSHFIFO); |
|
537 } |
|
538 else |
|
539 { |
|
540 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aRealEndpoint/2)); |
|
541 AsspRegister::Modify16(KUSBBase+K_PERI_TXCSR_REG, KClearNone, K_TX_FLUSHFIFO); |
|
542 } |
|
543 } |
|
544 return KErrNone; |
|
545 } |
|
546 |
|
547 |
|
548 TInt DOmap3530Usbcc::AllocateEndpointResource(TInt aRealEndpoint, TUsbcEndpointResource aResource) |
|
549 // |
|
550 // Puts the requested endpoint resource to use, if possible. |
|
551 // |
|
552 { |
|
553 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::AllocateEndpointResource(%d): %d", |
|
554 aRealEndpoint, aResource)); |
|
555 |
|
556 // TO DO: Allocate endpoint resource here. |
|
557 |
|
558 return KErrNone; |
|
559 } |
|
560 |
|
561 |
|
562 TInt DOmap3530Usbcc::DeAllocateEndpointResource(TInt aRealEndpoint, TUsbcEndpointResource aResource) |
|
563 // |
|
564 // Stops the use of the indicated endpoint resource, if beneficial. |
|
565 // |
|
566 { |
|
567 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::DeAllocateEndpointResource(%d): %d", |
|
568 aRealEndpoint, aResource)); |
|
569 |
|
570 // TO DO: Deallocate endpoint resource here. |
|
571 |
|
572 return KErrNone; |
|
573 } |
|
574 |
|
575 |
|
576 TBool DOmap3530Usbcc::QueryEndpointResource(TInt aRealEndpoint, TUsbcEndpointResource aResource) const |
|
577 // |
|
578 // Returns the status of the indicated resource and endpoint. |
|
579 // |
|
580 { |
|
581 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::QueryEndpointResource(%d): %d", |
|
582 aRealEndpoint, aResource)); |
|
583 |
|
584 // TO DO: Query endpoint resource here. The return value should reflect the actual state. |
|
585 return ETrue; |
|
586 } |
|
587 |
|
588 |
|
589 TInt DOmap3530Usbcc::OpenDmaChannel(TInt aRealEndpoint) |
|
590 // |
|
591 // Opens a DMA channel for this endpoint. This function is always called during the creation of an endpoint |
|
592 // in the PIL. If DMA channels are a scarce resource, it's possible to do nothing here and wait for an |
|
593 // AllocateEndpointResource call instead. |
|
594 // |
|
595 { |
|
596 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::OpenDmaChannel(%d)", aRealEndpoint)); |
|
597 |
|
598 // TO DO (optional): Open DMA channel here. |
|
599 |
|
600 // An error should only be returned in case of an actual DMA problem. |
|
601 return KErrNone; |
|
602 } |
|
603 |
|
604 |
|
605 void DOmap3530Usbcc::CloseDmaChannel(TInt aRealEndpoint) |
|
606 // |
|
607 // Closes a DMA channel for this endpoint. This function is always called during the destruction of an |
|
608 // endpoint in the PIL. |
|
609 // |
|
610 { |
|
611 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::CloseDmaChannel(%d)", aRealEndpoint)); |
|
612 |
|
613 // TO DO (optional): Close DMA channel here (only if it was opened via OpenDmaChannel). |
|
614 } |
|
615 |
|
616 |
|
617 TInt DOmap3530Usbcc::SetupEndpointRead(TInt aRealEndpoint, TUsbcRequestCallback& aCallback) |
|
618 // |
|
619 // Sets up a read request for an endpoint on behalf of the LDD. |
|
620 // |
|
621 { |
|
622 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::SetupEndpointRead(%d)", aRealEndpoint)); |
|
623 if (!IS_OUT_ENDPOINT(aRealEndpoint)) |
|
624 { |
|
625 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: !IS_OUT_ENDPOINT(%d)", aRealEndpoint)); |
|
626 return KErrArgument; |
|
627 } |
|
628 TEndpoint* const ep = &iEndpoints[aRealEndpoint]; |
|
629 if (ep->iRxBuf != NULL) |
|
630 { |
|
631 __KTRACE_OPT(KUSB, Kern::Printf(" > WARNING: iEndpoints[%d].iRxBuf != NULL", aRealEndpoint)); |
|
632 return KErrGeneral; |
|
633 } |
|
634 ep->iRxBuf = aCallback.iBufferStart; |
|
635 ep->iReceived = 0; |
|
636 ep->iLength = aCallback.iLength; |
|
637 |
|
638 // For Bulk reads we start out with the assumption of 1 packet (see BulkReceive for why): |
|
639 ep->iPackets = IS_BULK_OUT_ENDPOINT(aRealEndpoint) ? 1 : 0; |
|
640 ep->iRequest = &aCallback; |
|
641 ep->iPacketIndex = aCallback.iPacketIndex; |
|
642 if (IS_BULK_OUT_ENDPOINT(aRealEndpoint)) |
|
643 *ep->iPacketIndex = 0; // a one-off optimization |
|
644 ep->iPacketSize = aCallback.iPacketSize; |
|
645 |
|
646 if (ep->iDisabled) |
|
647 { |
|
648 ep->iDisabled = EFalse; |
|
649 EnableEndpointInterrupt(aRealEndpoint); |
|
650 } |
|
651 else if (ep->iNoBuffer) |
|
652 { |
|
653 __KTRACE_OPT(KUSB, Kern::Printf(" > There had been no Rx buffer available: reading Rx FIFO now")); |
|
654 ep->iNoBuffer = EFalse; |
|
655 if (IS_BULK_OUT_ENDPOINT(aRealEndpoint)) |
|
656 { |
|
657 BulkReadRxFifo(aRealEndpoint); |
|
658 } |
|
659 else if (IS_ISO_OUT_ENDPOINT(aRealEndpoint)) |
|
660 { |
|
661 IsoReadRxFifo(aRealEndpoint); |
|
662 } |
|
663 else |
|
664 { |
|
665 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint not found")); |
|
666 } |
|
667 } |
|
668 |
|
669 return KErrNone; |
|
670 } |
|
671 |
|
672 |
|
673 TInt DOmap3530Usbcc::SetupEndpointWrite(TInt aRealEndpoint, TUsbcRequestCallback& aCallback) |
|
674 // |
|
675 // Sets up a write request for an endpoint on behalf of the LDD. |
|
676 // |
|
677 { |
|
678 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::SetupEndpointWrite(%d)", aRealEndpoint)); |
|
679 |
|
680 if (!IS_IN_ENDPOINT(aRealEndpoint)) |
|
681 { |
|
682 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: !IS_IN_ENDPOINT(%d)", aRealEndpoint)); |
|
683 return KErrArgument; |
|
684 } |
|
685 TEndpoint* const ep = &iEndpoints[aRealEndpoint]; |
|
686 if (ep->iTxBuf != NULL) |
|
687 { |
|
688 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: iEndpoints[%d].iTxBuf != NULL", aRealEndpoint)); |
|
689 return KErrGeneral; |
|
690 } |
|
691 ep->iTxBuf = aCallback.iBufferStart; |
|
692 ep->iTransmitted = 0; |
|
693 ep->iLength = aCallback.iLength; |
|
694 ep->iPackets = 0; |
|
695 ep->iZlpReqd = aCallback.iZlpReqd; |
|
696 ep->iRequest = &aCallback; |
|
697 |
|
698 if (IS_BULK_IN_ENDPOINT(aRealEndpoint)) |
|
699 { |
|
700 if (ep->iDisabled) |
|
701 { |
|
702 ep->iDisabled = EFalse; |
|
703 EnableEndpointInterrupt(aRealEndpoint); |
|
704 } |
|
705 BulkTransmit(aRealEndpoint); |
|
706 } |
|
707 else if (IS_ISO_IN_ENDPOINT(aRealEndpoint)) |
|
708 { |
|
709 IsoTransmit(aRealEndpoint); |
|
710 } |
|
711 else if (IS_INT_IN_ENDPOINT(aRealEndpoint)) |
|
712 { |
|
713 IntTransmit(aRealEndpoint); |
|
714 } |
|
715 else |
|
716 { |
|
717 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint not found")); |
|
718 } |
|
719 |
|
720 return KErrNone; |
|
721 } |
|
722 |
|
723 |
|
724 TInt DOmap3530Usbcc::CancelEndpointRead(TInt aRealEndpoint) |
|
725 // |
|
726 // Cancels a read request for an endpoint on behalf of the LDD. |
|
727 // No completion to the PIL occurs. |
|
728 // |
|
729 { |
|
730 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::CancelEndpointRead(%d)", aRealEndpoint)); |
|
731 |
|
732 if (!IS_OUT_ENDPOINT(aRealEndpoint)) |
|
733 { |
|
734 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: !IS_OUT_ENDPOINT(%d)", aRealEndpoint)); |
|
735 return KErrArgument; |
|
736 } |
|
737 TEndpoint* const ep = &iEndpoints[aRealEndpoint]; |
|
738 if (ep->iRxBuf == NULL) |
|
739 { |
|
740 __KTRACE_OPT(KUSB, Kern::Printf(" > WARNING: iEndpoints[%d].iRxBuf == NULL", aRealEndpoint)); |
|
741 return KErrNone; |
|
742 } |
|
743 |
|
744 // : Flush the Ep's Rx FIFO here |
|
745 if(aRealEndpoint==KEp0_Out || aRealEndpoint==KEp0_In) |
|
746 { |
|
747 AsspRegister::Write8(KUSBBase+K_INDEX_REG, 0); |
|
748 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_FLUSHFIFO ); |
|
749 } |
|
750 else |
|
751 { |
|
752 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aRealEndpoint/2)); |
|
753 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, KClearNone, K_RX_FLUSHFIFO ); |
|
754 } |
|
755 |
|
756 ep->iRxBuf = NULL; |
|
757 ep->iReceived = 0; |
|
758 ep->iNoBuffer = EFalse; |
|
759 |
|
760 return KErrNone; |
|
761 } |
|
762 |
|
763 |
|
764 TInt DOmap3530Usbcc::CancelEndpointWrite(TInt aRealEndpoint) |
|
765 // |
|
766 // Cancels a write request for an endpoint on behalf of the LDD. |
|
767 // No completion to the PIL occurs. |
|
768 // |
|
769 { |
|
770 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::CancelEndpointWrite(%d)", aRealEndpoint)); |
|
771 |
|
772 if (!IS_IN_ENDPOINT(aRealEndpoint)) |
|
773 { |
|
774 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: !IS_IN_ENDPOINT(%d)", aRealEndpoint)); |
|
775 return KErrArgument; |
|
776 } |
|
777 TEndpoint* const ep = &iEndpoints[aRealEndpoint]; |
|
778 if (ep->iTxBuf == NULL) |
|
779 { |
|
780 __KTRACE_OPT(KUSB, Kern::Printf(" > WARNING: iEndpoints[%d].iTxBuf == NULL", aRealEndpoint)); |
|
781 return KErrNone; |
|
782 } |
|
783 |
|
784 // TO DO (optional): Flush the Ep's Tx FIFO here, if possible. |
|
785 if(aRealEndpoint==KEp0_Out || aRealEndpoint==KEp0_In) |
|
786 { |
|
787 AsspRegister::Write8(KUSBBase+K_INDEX_REG, 0); |
|
788 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_FLUSHFIFO ); |
|
789 } |
|
790 else |
|
791 { |
|
792 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aRealEndpoint/2)); |
|
793 AsspRegister::Modify16(KUSBBase+K_PERI_TXCSR_REG, KClearNone, K_TX_FLUSHFIFO ); |
|
794 } |
|
795 |
|
796 ep->iTxBuf = NULL; |
|
797 ep->iTransmitted = 0; |
|
798 ep->iNoBuffer = EFalse; |
|
799 |
|
800 return KErrNone; |
|
801 } |
|
802 |
|
803 |
|
804 TInt DOmap3530Usbcc::SetupEndpointZeroRead() |
|
805 // |
|
806 // Sets up an Ep0 read request (own function due to Ep0's special status). |
|
807 // |
|
808 { |
|
809 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::SetupEndpointZeroRead")); |
|
810 |
|
811 TEndpoint* const ep = &iEndpoints[KEp0_Out]; |
|
812 if (ep->iRxBuf != NULL) |
|
813 { |
|
814 __KTRACE_OPT(KUSB, Kern::Printf(" > WARNING: iEndpoints[%d].iRxBuf != NULL", KEp0_Out)); |
|
815 return KErrGeneral; |
|
816 } |
|
817 ep->iRxBuf = iEp0_RxBuf; |
|
818 ep->iReceived = 0; |
|
819 |
|
820 return KErrNone; |
|
821 } |
|
822 |
|
823 |
|
824 TInt DOmap3530Usbcc::SetupEndpointZeroWrite(const TUint8* aBuffer, TInt aLength, TBool aZlpReqd) |
|
825 // |
|
826 // Sets up an Ep0 write request (own function due to Ep0's special status). |
|
827 // |
|
828 { |
|
829 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::SetupEndpointZeroWrite")); |
|
830 |
|
831 TEndpoint* const ep = &iEndpoints[KEp0_In]; |
|
832 if (ep->iTxBuf != NULL) |
|
833 { |
|
834 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: iEndpoints[%d].iTxBuf != NULL", KEp0_In)); |
|
835 return KErrGeneral; |
|
836 } |
|
837 ep->iTxBuf = aBuffer; |
|
838 ep->iTransmitted = 0; |
|
839 ep->iLength = aLength; |
|
840 ep->iZlpReqd = aZlpReqd; |
|
841 ep->iRequest = NULL; |
|
842 Ep0Transmit(); |
|
843 |
|
844 return KErrNone; |
|
845 } |
|
846 |
|
847 |
|
848 TInt DOmap3530Usbcc::SendEp0ZeroByteStatusPacket() |
|
849 // |
|
850 // Sets up an Ep0 write request for zero bytes. |
|
851 // This is a separate function because no data transfer is involved here. |
|
852 // |
|
853 { |
|
854 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::SendEp0ZeroByteStatusPacket")); |
|
855 |
|
856 // This is possibly a bit tricky. When this function is called it just means that the higher layer wants a |
|
857 // ZLP to be sent. Whether we actually send one manually here depends on a number of factors, as the |
|
858 // current Ep0 state (i.e. the stage of the Ep0 Control transfer), and, in case the hardware handles some |
|
859 // ZLPs itself, whether it might already handle this one. |
|
860 |
|
861 // Here is an example of what the checking of the conditions might look like: |
|
862 |
|
863 #ifndef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST |
|
864 if ((!iEp0ReceivedNonStdRequest && iEp0State == EP0_IN_DATA_PHASE) || |
|
865 #else |
|
866 if ((!iEp0ReceivedNonStdRequest && iEp0State != EP0_IDLE) || |
|
867 #endif |
|
868 #ifdef USB_SUPPORTS_PREMATURE_STATUS_IN |
|
869 (iEp0ReceivedNonStdRequest && iEp0State != EP0_OUT_DATA_PHASE)) |
|
870 #else |
|
871 (iEp0ReceivedNonStdRequest)) |
|
872 #endif |
|
873 |
|
874 { |
|
875 // TO DO: Arrange for the sending of a ZLP here. |
|
876 Kern::Printf("ZLP!"); |
|
877 AsspRegister::Write8(KUSBBase+K_INDEX_REG, 0x0); |
|
878 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_TXPKTRDY | K_EP0_DATAEND ); |
|
879 } |
|
880 |
|
881 return KErrNone; |
|
882 } |
|
883 |
|
884 |
|
885 TInt DOmap3530Usbcc::StallEndpoint(TInt aRealEndpoint) |
|
886 // |
|
887 // Stalls an endpoint. |
|
888 // |
|
889 { |
|
890 __KTRACE_OPT(KPANIC, Kern::Printf("DOmap3530Usbcc::StallEndpoint(%d)", aRealEndpoint)); |
|
891 |
|
892 if (IS_ISO_ENDPOINT(aRealEndpoint)) |
|
893 { |
|
894 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Iso endpoint cannot be stalled")); |
|
895 return KErrArgument; |
|
896 } |
|
897 |
|
898 // Stall the endpoint here. |
|
899 if(aRealEndpoint==KEp0_Out || aRealEndpoint==KEp0_In) |
|
900 { |
|
901 AsspRegister::Write8(KUSBBase+K_INDEX_REG, 0x0); |
|
902 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_SENDSTALL); |
|
903 } |
|
904 else |
|
905 if(aRealEndpoint%2==0) |
|
906 { |
|
907 // RX stall |
|
908 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aRealEndpoint/2)); |
|
909 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, KClearNone, K_RX_SENDSTALL); |
|
910 } |
|
911 else |
|
912 { |
|
913 // TX stall |
|
914 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aRealEndpoint/2)); |
|
915 AsspRegister::Modify16(KUSBBase+K_PERI_TXCSR_REG, KClearNone, K_TX_SENDSTALL ); |
|
916 } |
|
917 return KErrNone; |
|
918 } |
|
919 |
|
920 |
|
921 TInt DOmap3530Usbcc::ClearStallEndpoint(TInt aRealEndpoint) |
|
922 // |
|
923 // Clears the stall condition of an endpoint. |
|
924 // |
|
925 { |
|
926 __KTRACE_OPT(KPANIC, Kern::Printf("DOmap3530Usbcc::ClearStallEndpoint(%d)", aRealEndpoint)); |
|
927 |
|
928 if (IS_ISO_ENDPOINT(aRealEndpoint)) |
|
929 { |
|
930 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Iso endpoint cannot be unstalled")); |
|
931 return KErrArgument; |
|
932 } |
|
933 |
|
934 // De-stall the endpoint here. |
|
935 |
|
936 if(aRealEndpoint==KEp0_Out || aRealEndpoint==KEp0_In) |
|
937 { |
|
938 AsspRegister::Write8(KUSBBase+K_INDEX_REG, 0x0); |
|
939 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, K_EP0_SENTSTALL, KSetNone ); |
|
940 } |
|
941 else |
|
942 if(aRealEndpoint%2==0) |
|
943 { |
|
944 //Clear RX stall |
|
945 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aRealEndpoint/2)); |
|
946 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, K_RX_SENDSTALL, KSetNone ); |
|
947 } |
|
948 else |
|
949 { |
|
950 //Clear TX stall |
|
951 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aRealEndpoint/2)); |
|
952 AsspRegister::Modify16(KUSBBase+K_PERI_TXCSR_REG, K_TX_SENDSTALL, KSetNone ); |
|
953 } |
|
954 |
|
955 return KErrNone; |
|
956 } |
|
957 |
|
958 |
|
959 TInt DOmap3530Usbcc::EndpointStallStatus(TInt aRealEndpoint) const |
|
960 // |
|
961 // Reports the stall status of an endpoint. |
|
962 // |
|
963 { |
|
964 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::EndpointStallStatus(%d)", aRealEndpoint)); |
|
965 if (IS_ISO_ENDPOINT(aRealEndpoint)) |
|
966 { |
|
967 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Iso endpoint has no stall status")); |
|
968 return KErrArgument; |
|
969 } |
|
970 |
|
971 // Query endpoint stall status here. The return value should reflect the actual state. |
|
972 if(aRealEndpoint==KEp0_Out || aRealEndpoint==KEp0_In) |
|
973 { |
|
974 AsspRegister::Write8(KUSBBase+K_INDEX_REG, 0x0); |
|
975 TInt status = AsspRegister::Read16(KUSBBase+K_PERI_CSR0_REG); |
|
976 return status & K_EP0_SENTSTALL; |
|
977 } |
|
978 else |
|
979 if(aRealEndpoint%2==0) |
|
980 { |
|
981 //Clear RX stall |
|
982 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aRealEndpoint/2)); |
|
983 TInt status = AsspRegister::Read16(KUSBBase+K_PERI_RXCSR_REG); |
|
984 return status & K_RX_SENDSTALL; |
|
985 } |
|
986 else |
|
987 { |
|
988 //Clear TX stall |
|
989 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aRealEndpoint/2)); |
|
990 TInt status = AsspRegister::Read16(KUSBBase+K_PERI_TXCSR_REG); |
|
991 return status & K_TX_SENDSTALL; |
|
992 |
|
993 } |
|
994 } |
|
995 |
|
996 |
|
997 TInt DOmap3530Usbcc::EndpointErrorStatus(TInt aRealEndpoint) const |
|
998 // |
|
999 // Reports the error status of an endpoint. |
|
1000 // |
|
1001 { |
|
1002 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::EndpointErrorStatus(%d)", aRealEndpoint)); |
|
1003 |
|
1004 if (!IS_VALID_ENDPOINT(aRealEndpoint)) |
|
1005 { |
|
1006 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: !IS_VALID_ENDPOINT(%d)", aRealEndpoint)); |
|
1007 return KErrArgument; |
|
1008 } |
|
1009 |
|
1010 // TO DO: Query endpoint error status here. The return value should reflect the actual state. |
|
1011 // With some UDCs there is no way of inquiring the endpoint error status; say 'ETrue' in that case. |
|
1012 |
|
1013 // Bulk EP's don't have an error status |
|
1014 return ETrue; |
|
1015 } |
|
1016 |
|
1017 |
|
1018 TInt DOmap3530Usbcc::ResetDataToggle(TInt aRealEndpoint) |
|
1019 // |
|
1020 // Resets to zero the data toggle bit of an endpoint. |
|
1021 // |
|
1022 { |
|
1023 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::ResetDataToggle(%d)", aRealEndpoint)); |
|
1024 |
|
1025 // Reset the endpoint's data toggle bit here. |
|
1026 // With some UDCs there is no way to individually reset the endpoint's toggle bits; just return KErrNone |
|
1027 // in that case. |
|
1028 |
|
1029 if(aRealEndpoint==KEp0_Out || aRealEndpoint==KEp0_In) |
|
1030 { |
|
1031 // No way of setting data toggle for EP0 |
|
1032 } |
|
1033 else |
|
1034 if(aRealEndpoint%2==0) |
|
1035 { |
|
1036 //Clear RX stall |
|
1037 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aRealEndpoint/2)); |
|
1038 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, KClearNone, K_RX_CLRDATATOG); |
|
1039 } |
|
1040 else |
|
1041 { |
|
1042 //Clear TX stall |
|
1043 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aRealEndpoint/2)); |
|
1044 AsspRegister::Modify16(KUSBBase+K_PERI_TXCSR_REG, KClearNone, K_TX_CLRDATATOG); |
|
1045 } |
|
1046 |
|
1047 return KErrNone; |
|
1048 } |
|
1049 |
|
1050 |
|
1051 TInt DOmap3530Usbcc::SynchFrameNumber() const |
|
1052 // |
|
1053 // For use with isochronous endpoints only. Causes the SOF frame number to be returned. |
|
1054 // |
|
1055 { |
|
1056 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::SynchFrameNumber")); |
|
1057 |
|
1058 // TO DO: Query and return the SOF frame number here. |
|
1059 return 0; |
|
1060 } |
|
1061 |
|
1062 void DOmap3530Usbcc::SetSynchFrameNumber(TInt aFrameNumber) |
|
1063 // |
|
1064 // For use with isochronous endpoints only. Causes the SOF frame number to be stored. |
|
1065 // |
|
1066 { |
|
1067 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::SetSynchFrameNumber(%d)", aFrameNumber)); |
|
1068 |
|
1069 // We should actually store this number somewhere. But the PIL always sends '0x00' |
|
1070 // in response to a SYNCH_FRAME request... |
|
1071 // TO DO: Store the frame number. Alternatively (until SYNCH_FRAME request specification changes): Do |
|
1072 // nothing. |
|
1073 } |
|
1074 |
|
1075 TInt DOmap3530Usbcc::StartUdc() |
|
1076 // |
|
1077 // Called to initialize the device controller hardware before any operation can be performed. |
|
1078 // |
|
1079 { |
|
1080 __KTRACE_OPT(KUSB,Kern::Printf("DOmap3530Usbcc::StartUdc")); |
|
1081 |
|
1082 if (iInitialized) |
|
1083 { |
|
1084 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: UDC already initialised")); |
|
1085 return KErrNone; |
|
1086 } |
|
1087 |
|
1088 // Disable UDC (might also reset the entire design): |
|
1089 UdcDisable(); |
|
1090 |
|
1091 // Bind & enable the UDC interrupt |
|
1092 if (SetupUdcInterrupt() != KErrNone) |
|
1093 { |
|
1094 return KErrGeneral; |
|
1095 } |
|
1096 // Enable the slave clock |
|
1097 EnableSICLK(); |
|
1098 |
|
1099 // Write meaningful values to some registers: |
|
1100 InitialiseUdcRegisters(); |
|
1101 |
|
1102 // Finally, turn on the UDC: |
|
1103 UdcEnable(); |
|
1104 |
|
1105 // and enable the PHY |
|
1106 iPhy->StartPHY(); |
|
1107 iPhy->SetPHYMode(ENormal); |
|
1108 |
|
1109 // Even if only one USB feature has been enabled, we later need to undo it: |
|
1110 iInitialized = ETrue; |
|
1111 |
|
1112 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc: UDC Enabled")); |
|
1113 |
|
1114 return KErrNone; |
|
1115 } |
|
1116 |
|
1117 |
|
1118 TInt DOmap3530Usbcc::StopUdc() |
|
1119 // |
|
1120 // Basically, makes undone what happened in StartUdc. |
|
1121 // |
|
1122 { |
|
1123 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::StopUdc")); |
|
1124 |
|
1125 if (!iInitialized) |
|
1126 { |
|
1127 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: UDC not initialized")); |
|
1128 return KErrNone; |
|
1129 } |
|
1130 |
|
1131 // Disable UDC: |
|
1132 UdcDisable(); |
|
1133 // Disable & unbind the UDC interrupt: |
|
1134 ReleaseUdcInterrupt(); |
|
1135 iPhy->SetPHYMode(EUART); |
|
1136 |
|
1137 // Finally turn off slave clock |
|
1138 DisableSICLK(); |
|
1139 |
|
1140 // Only when all USB features have been disabled we'll call it a day: |
|
1141 iInitialized = EFalse; |
|
1142 |
|
1143 return KErrNone; |
|
1144 } |
|
1145 |
|
1146 |
|
1147 TInt DOmap3530Usbcc::UdcConnect() |
|
1148 // |
|
1149 // Connects the UDC to the bus under software control. How this is achieved depends on the UDC; the |
|
1150 // functionality might also be part of the Variant component (instead of the ASSP). |
|
1151 // |
|
1152 { |
|
1153 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::UdcConnect")); |
|
1154 |
|
1155 //AsspRegister::Modify8(KUSBBase+KPOWER_REG , KClearNone, KSOFTCONNECT_BIT); |
|
1156 AsspRegister::Write8(KUSBBase+KPOWER_REG , KSOFTCONNECT_BIT | KHSEN_BIT); |
|
1157 iPhy->EnablePHY(); |
|
1158 |
|
1159 // Here: A call into the Variant-provided function. |
|
1160 return iAssp->UsbConnect(); |
|
1161 } |
|
1162 |
|
1163 |
|
1164 TInt DOmap3530Usbcc::UdcDisconnect() |
|
1165 // |
|
1166 // Disconnects the UDC from the bus under software control. How this is achieved depends on the UDC; the |
|
1167 // functionality might also be part of the Variant component (instead of the ASSP). |
|
1168 // |
|
1169 { |
|
1170 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::UdcDisconnect")); |
|
1171 |
|
1172 // Here: A call into the Variant-provided function. |
|
1173 return iAssp->UsbDisconnect(); |
|
1174 } |
|
1175 |
|
1176 |
|
1177 TBool DOmap3530Usbcc::UsbConnectionStatus() const |
|
1178 // |
|
1179 // Returns a value showing the USB cable connection status of the device. |
|
1180 // |
|
1181 { |
|
1182 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::UsbConnectionStatus")); |
|
1183 |
|
1184 return iCableConnected; |
|
1185 } |
|
1186 |
|
1187 |
|
1188 TBool DOmap3530Usbcc::UsbPowerStatus() const |
|
1189 // |
|
1190 // Returns a truth value showing whether VBUS is currently powered or not. |
|
1191 // |
|
1192 { |
|
1193 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::UsbPowerStatus")); |
|
1194 |
|
1195 return iBusIsPowered; |
|
1196 } |
|
1197 |
|
1198 |
|
1199 TBool DOmap3530Usbcc::DeviceSelfPowered() const |
|
1200 // |
|
1201 // Returns a truth value showing whether the device is currently self-powered or not. |
|
1202 // |
|
1203 { |
|
1204 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::DeviceSelfPowered")); |
|
1205 |
|
1206 // TO DO: Query and return self powered status here. The return value should reflect the actual state. |
|
1207 // (This can be always 'ETrue' if the UDC does not support bus-powered devices.) |
|
1208 return ETrue; |
|
1209 } |
|
1210 |
|
1211 const TUsbcEndpointCaps* DOmap3530Usbcc::DeviceEndpointCaps() const |
|
1212 // |
|
1213 // Returns a pointer to an array of elements, each of which describes the capabilities of one endpoint. |
|
1214 // |
|
1215 { |
|
1216 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::DeviceEndpointCaps")); |
|
1217 __KTRACE_OPT(KUSB, Kern::Printf(" > Ep: Sizes Mask, Types Mask")); |
|
1218 __KTRACE_OPT(KUSB, Kern::Printf(" > --------------------------")); |
|
1219 for (TInt i = 0; i < KUsbTotalEndpoints; ++i) |
|
1220 { |
|
1221 __KTRACE_OPT(KUSB, Kern::Printf(" > %02d: 0x%08x, 0x%08x", |
|
1222 i, DeviceEndpoints[i].iSizes, DeviceEndpoints[i].iTypesAndDir)); |
|
1223 } |
|
1224 return DeviceEndpoints; |
|
1225 } |
|
1226 |
|
1227 |
|
1228 TInt DOmap3530Usbcc::DeviceTotalEndpoints() const |
|
1229 // |
|
1230 // Returns the element number of the endpoints array a pointer to which is returned by DeviceEndpointCaps. |
|
1231 // |
|
1232 { |
|
1233 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::DeviceTotalEndpoints")); |
|
1234 |
|
1235 return KUsbTotalEndpoints; |
|
1236 } |
|
1237 |
|
1238 |
|
1239 TBool DOmap3530Usbcc::SoftConnectCaps() const |
|
1240 // |
|
1241 // Returns a truth value showing whether or not there is the capability to disconnect and re-connect the D+ |
|
1242 // line under software control. |
|
1243 // |
|
1244 { |
|
1245 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::SoftConnectCaps")); |
|
1246 |
|
1247 return iSoftwareConnectable; |
|
1248 } |
|
1249 |
|
1250 |
|
1251 void DOmap3530Usbcc::Suspend() |
|
1252 // |
|
1253 // Called by the PIL after a Suspend event has been reported (by us). |
|
1254 // |
|
1255 { |
|
1256 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::Suspend")); |
|
1257 |
|
1258 if (NKern::CurrentContext() == EThread) |
|
1259 { |
|
1260 iSuspendDfc.Enque(); |
|
1261 } |
|
1262 else |
|
1263 { |
|
1264 iSuspendDfc.Add(); |
|
1265 } |
|
1266 // TO DO (optional): Implement here anything the device might require after bus SUSPEND signalling. |
|
1267 // Need to put the transceiver into suspend too. Can't do it here as it requries I2C and we are in an interrupt context. |
|
1268 AsspRegister::Modify8(KUSBBase+KPOWER_REG , KClearNone, KSUSPENDM_BIT); |
|
1269 } |
|
1270 |
|
1271 |
|
1272 void DOmap3530Usbcc::Resume() |
|
1273 // |
|
1274 // Called by the PIL after a Resume event has been reported (by us). |
|
1275 // |
|
1276 { |
|
1277 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::Resume")); |
|
1278 if (NKern::CurrentContext() == EThread) |
|
1279 { |
|
1280 iResumeDfc.Enque(); |
|
1281 } |
|
1282 else |
|
1283 { |
|
1284 iResumeDfc.Add(); |
|
1285 } |
|
1286 |
|
1287 // TO DO (optional): Implement here anything the device might require after bus RESUME signalling. |
|
1288 // Need to put the transceiver into resume too. Can't do it here as it requries I2C and we are in an interrupt context. |
|
1289 AsspRegister::Modify8(KUSBBase+KPOWER_REG, KClearNone , KRESUME_BIT); |
|
1290 Kern::NanoWait(10000000); // Wait 10ms - Use a callback instead! |
|
1291 AsspRegister::Modify8(KUSBBase+KPOWER_REG, KRESUME_BIT, KSetNone); |
|
1292 } |
|
1293 |
|
1294 |
|
1295 void DOmap3530Usbcc::Reset() |
|
1296 // |
|
1297 // Called by the PIL after a Reset event has been reported (by us). |
|
1298 // |
|
1299 { |
|
1300 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::Reset")); |
|
1301 |
|
1302 // This does not really belong here, but has to do with the way the PIL sets |
|
1303 // up Ep0 reads and writes. |
|
1304 TEndpoint* ep = &iEndpoints[0]; |
|
1305 ep->iRxBuf = NULL; |
|
1306 ++ep; |
|
1307 ep->iTxBuf = NULL; |
|
1308 // Idle |
|
1309 Ep0NextState(EP0_IDLE); |
|
1310 // TO DO (optional): Implement here anything the device might require after bus RESET signalling. |
|
1311 // Need to put the transceiver into reset too. Can't do it here as it requries I2C and we are in an interrupt context. |
|
1312 if (NKern::CurrentContext() == EThread) |
|
1313 { |
|
1314 iResetDfc.Enque(); |
|
1315 } |
|
1316 else |
|
1317 { |
|
1318 iResetDfc.Add(); |
|
1319 } |
|
1320 |
|
1321 // Write meaningful values to some registers |
|
1322 InitialiseUdcRegisters(); |
|
1323 UdcEnable(); |
|
1324 if (iEp0Configured) |
|
1325 EnableEndpointInterrupt(0); |
|
1326 } |
|
1327 |
|
1328 |
|
1329 // --- DOmap3530Usbcc private -------------------------------------------------- |
|
1330 |
|
1331 void DOmap3530Usbcc::InitialiseUdcRegisters() |
|
1332 // |
|
1333 // Called after every USB Reset etc. |
|
1334 // |
|
1335 { |
|
1336 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::InitialiseUdcRegisters")); |
|
1337 |
|
1338 AsspRegister::Write8(KUSBBase+K_INDEX_REG, 0); |
|
1339 AsspRegister::Write8(KUSBBase+K_CONFIGDATA_REG, K_SOFTCONNECT | K_DYNFIFO | K_MPTXE | K_MPRXE);// Dynamic FIFO |
|
1340 |
|
1341 // Configure FIFO's |
|
1342 for(TUint n=1; n<KUsbTotalEndpoints; n++) // Fifo for EP 0 is fixed. Size 0x200 (512) for the ISO ep is wrong! FIXME!!!!!!!!!!!! Hacked to make all FIFO's 1024 bytes (ignore ep>16!) |
|
1343 { |
|
1344 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)((n+1)/2)); |
|
1345 if(n%2==0) |
|
1346 { |
|
1347 AsspRegister::Write16(KUSBBase+K_TXMAXP_REG, KMaxPayload | 0x1<<11); // Not sure how many packets we want to split into. Use 2 because it is OK for Bulk and INT |
|
1348 AsspRegister::Write8(KUSBBase+K_TXFIFOSZ_REG, 0x7); // No double buffering, FIFO size == 2^(7+3) = 1024 |
|
1349 AsspRegister::Write16(KUSBBase+K_TXFIFOADDR_REG, 128*((TInt)n/2)); // We have 16kb of memory and 16 endpoints. Start each fifo on a 1kb boundary |
|
1350 AsspRegister::Modify16(KUSBBase+K_PERI_TXCSR_REG, K_TX_DMAMODE | K_TX_ISO | K_TX_DMAEN, K_TX_CLRDATATOG | K_TX_FLUSHFIFO); |
|
1351 } |
|
1352 else |
|
1353 { |
|
1354 AsspRegister::Write16(KUSBBase+K_RXMAXP_REG, KMaxPayload | 0x1<<11); // Not sure how many packets we want to split into. Use 2 because it is OK for Bulk and INT |
|
1355 AsspRegister::Write8(KUSBBase+K_RXFIFOSZ_REG, 0x7); // No double buffering, FIFO size == 2^(7+3) = 1024 |
|
1356 AsspRegister::Write16(KUSBBase+K_RXFIFOADDR_REG, 128*((TInt)(n/2)+8)); // We have 16kb of memory and 16 endpoints. Start each fifo on a 1kb boundary |
|
1357 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, K_RX_ISO | K_RX_DMAEN, K_RX_CLRDATATOG | K_RX_FLUSHFIFO | K_RX_DISNYET); |
|
1358 } |
|
1359 } |
|
1360 |
|
1361 // Disable interrupt requests for all endpoints |
|
1362 AsspRegister::Modify16(KUSBBase+K_INTRTXE_REG, 0xFFFF, KSetNone); |
|
1363 AsspRegister::Modify16(KUSBBase+K_INTRRXE_REG, 0XFFFE, KSetNone); |
|
1364 |
|
1365 AsspRegister::Modify32(KUSBBase+K_OTG_SYSCONFIG_REG, KClearNone, K_ENABLEWAKEUP); |
|
1366 } |
|
1367 |
|
1368 |
|
1369 void DOmap3530Usbcc::UdcEnable() |
|
1370 // |
|
1371 // Enables the UDC for USB transmission or reception. |
|
1372 // |
|
1373 { |
|
1374 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::UdcEnable")); |
|
1375 EnableSICLK(); |
|
1376 // TO DO: Do whatever is necessary to enable the UDC here. This might include enabling (unmasking) |
|
1377 // the USB Reset interrupt, setting a UDC enable bit, etc. |
|
1378 AsspRegister::Read8(KUSBBase+K_INTRUSB_REG); // Reading this register clears it |
|
1379 AsspRegister::Write8(KUSBBase+K_INTRUSBE_REG, K_INT_SUSPEND | K_INT_RESUME | K_INT_RESET); |
|
1380 DisableSICLK(); |
|
1381 } |
|
1382 |
|
1383 |
|
1384 void DOmap3530Usbcc::UdcDisable() |
|
1385 // |
|
1386 // Disables the UDC. |
|
1387 // |
|
1388 { |
|
1389 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::UdcDisable")); |
|
1390 EnableSICLK(); |
|
1391 // TO DO: Do whatever is necessary to disable the UDC here. This might include disabling (masking) |
|
1392 // the USB Reset interrupt, clearing a UDC enable bit, etc. |
|
1393 AsspRegister::Write8(KUSBBase+K_INTRUSBE_REG, 0x0); |
|
1394 AsspRegister::Read8(KUSBBase+K_INTRUSB_REG); // Reading this register clears it |
|
1395 DisableSICLK(); |
|
1396 } |
|
1397 |
|
1398 |
|
1399 void DOmap3530Usbcc::EnableEndpointInterrupt(TInt aEndpoint) |
|
1400 // |
|
1401 // Enables interrupt requests for an endpoint. |
|
1402 // |
|
1403 { |
|
1404 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::EnableEndpointInterrupt(%d)", aEndpoint)); |
|
1405 |
|
1406 // Enable (unmask) interrupt requests for this endpoint: |
|
1407 if(aEndpoint==0) |
|
1408 { |
|
1409 AsspRegister::Modify16(KUSBBase+K_INTRTXE_REG , KClearNone, 1<<(int)(aEndpoint/2)); |
|
1410 } |
|
1411 else |
|
1412 { |
|
1413 if(aEndpoint%2==0) |
|
1414 { |
|
1415 AsspRegister::Modify16(KUSBBase+K_INTRRXE_REG , KClearNone, 1<<(int)((aEndpoint)/2)); |
|
1416 } |
|
1417 else |
|
1418 { |
|
1419 AsspRegister::Modify16(KUSBBase+K_INTRTXE_REG, KClearNone, 1<<(int)((aEndpoint)/2)); |
|
1420 } |
|
1421 } |
|
1422 } |
|
1423 |
|
1424 |
|
1425 void DOmap3530Usbcc::DisableEndpointInterrupt(TInt aEndpoint) |
|
1426 // |
|
1427 // Disables interrupt requests for an endpoint. |
|
1428 // |
|
1429 { |
|
1430 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::DisableEndpointInterrupt(%d)", aEndpoint)); |
|
1431 |
|
1432 // Disable (mask) interrupt requests for this endpoint: |
|
1433 if(aEndpoint==0) |
|
1434 { |
|
1435 AsspRegister::Modify16(KUSBBase+K_INTRTXE_REG , 1<<(int)(aEndpoint/2), KSetNone); |
|
1436 } |
|
1437 else |
|
1438 { |
|
1439 if(aEndpoint%2==0) |
|
1440 { |
|
1441 AsspRegister::Modify16(KUSBBase+K_INTRRXE_REG , 1<<(int)((aEndpoint)/2), KSetNone); |
|
1442 } |
|
1443 else |
|
1444 { |
|
1445 AsspRegister::Modify16(KUSBBase+K_INTRTXE_REG, 1<<(int)((aEndpoint)/2), KSetNone); |
|
1446 } |
|
1447 } |
|
1448 } |
|
1449 |
|
1450 |
|
1451 void DOmap3530Usbcc::ClearEndpointInterrupt(TInt aEndpoint) |
|
1452 // |
|
1453 // Clears a pending interrupt request for an endpoint. |
|
1454 // |
|
1455 { |
|
1456 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::ClearEndpointInterrupt(%d)", aEndpoint)); |
|
1457 |
|
1458 // Clear (reset) pending interrupt request for this endpoint: |
|
1459 if(aEndpoint==0) |
|
1460 { |
|
1461 AsspRegister::Modify16(KUSBBase+K_INTRTX_REG , 1<<(int)(aEndpoint/2), KSetNone); |
|
1462 } |
|
1463 else |
|
1464 { |
|
1465 if(aEndpoint%2==0) |
|
1466 { |
|
1467 AsspRegister::Modify16(KUSBBase+K_INTRRX_REG , 1<<(int)((aEndpoint)/2), KSetNone); |
|
1468 } |
|
1469 else |
|
1470 { |
|
1471 AsspRegister::Modify16(KUSBBase+K_INTRTX_REG, 1<<(int)((aEndpoint)/2), KSetNone); |
|
1472 } |
|
1473 } |
|
1474 } |
|
1475 |
|
1476 |
|
1477 void DOmap3530Usbcc::Ep0IntService() |
|
1478 // |
|
1479 // ISR for endpoint zero interrupt. |
|
1480 // |
|
1481 { |
|
1482 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::Ep0IntService")); |
|
1483 Interrupt::Disable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
1484 |
|
1485 // Enquire about Ep0 status & the interrupt cause here. Depending on the event and the Ep0 state, |
|
1486 |
|
1487 AsspRegister::Write8(KUSBBase+K_INDEX_REG, 0x0); |
|
1488 TUint ep0 = AsspRegister::Read16(KUSBBase+K_PERI_CSR0_REG); |
|
1489 |
|
1490 if(ep0 & K_EP0_SETUPEND) |
|
1491 { |
|
1492 // Setupend is set - A setup transaction ended unexpectedly |
|
1493 Ep0Cancel(); |
|
1494 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_SERV_SETUPEND); |
|
1495 Ep0NextState(EP0_IDLE); |
|
1496 } |
|
1497 if(ep0&K_EP0_SENTSTALL) |
|
1498 { |
|
1499 // Stalled! Complete the stall handshake |
|
1500 ClearStallEndpoint(0); |
|
1501 } |
|
1502 |
|
1503 switch(iEp0State) |
|
1504 { |
|
1505 case EP0_END_XFER: |
|
1506 Ep0EndXfer(); |
|
1507 break; |
|
1508 case EP0_IDLE: |
|
1509 if(ep0&K_EP0_RXPKTRDY) |
|
1510 { |
|
1511 Ep0ReadSetupPkt(); |
|
1512 } |
|
1513 else |
|
1514 { |
|
1515 Ep0StatusIn(); |
|
1516 } |
|
1517 break; |
|
1518 case EP0_OUT_DATA_PHASE: |
|
1519 Ep0Receive(); |
|
1520 break; |
|
1521 case EP0_IN_DATA_PHASE: |
|
1522 Ep0Transmit(); |
|
1523 break; |
|
1524 default: |
|
1525 break; // Do nothing |
|
1526 } |
|
1527 |
|
1528 ClearEndpointInterrupt(0); |
|
1529 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
1530 } |
|
1531 |
|
1532 |
|
1533 void DOmap3530Usbcc::Ep0ReadSetupPkt() |
|
1534 // |
|
1535 // Called from the Ep0 ISR when a new Setup packet has been received. |
|
1536 // |
|
1537 { |
|
1538 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::Ep0ReadSetupPkt")); |
|
1539 |
|
1540 TEndpoint* const ep = &iEndpoints[KEp0_Out]; |
|
1541 TUint8* buf = ep->iRxBuf; |
|
1542 if (!buf) |
|
1543 { |
|
1544 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: No Ep0 Rx buffer available (1)")); |
|
1545 StallEndpoint(KEp0_Out); |
|
1546 return; |
|
1547 } |
|
1548 |
|
1549 // Read Setup packet data from Rx FIFO into 'buf' here. |
|
1550 // (In this function we don't need to use "ep->iReceived" since Setup packets |
|
1551 // are always 8 bytes long.) |
|
1552 for(TInt x=0; x<KSetupPacketSize; x++) |
|
1553 { |
|
1554 // Should try and check we aren't running out of FIFO! |
|
1555 buf[x] = AsspRegister::Read8(KUSBBase+K_FIFO0_REG); |
|
1556 } |
|
1557 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_SERV_RXPKTRDY); // The packet has been retrieved from the FIFO |
|
1558 |
|
1559 // Upcall into PIL to determine next Ep0 state: |
|
1560 TUsbcEp0State state = EnquireEp0NextState(ep->iRxBuf); |
|
1561 |
|
1562 if (state == EEp0StateStatusIn) |
|
1563 { |
|
1564 Ep0NextState(EP0_IDLE); // Ep0 No Data |
|
1565 } |
|
1566 else if (state == EEp0StateDataIn) |
|
1567 { |
|
1568 Ep0NextState(EP0_IN_DATA_PHASE); // Ep0 Control Read |
|
1569 } |
|
1570 else |
|
1571 { |
|
1572 Ep0NextState(EP0_OUT_DATA_PHASE); // Ep0 Control Write |
|
1573 } |
|
1574 |
|
1575 ep->iRxBuf = NULL; |
|
1576 const TInt r = Ep0RequestComplete(KEp0_Out, KSetupPacketSize, KErrNone); |
|
1577 |
|
1578 // Don't finish (proceed) if request completion returned 'KErrNotFound'! |
|
1579 if (!(r == KErrNone || r == KErrGeneral)) |
|
1580 { |
|
1581 DisableEndpointInterrupt(0); |
|
1582 } |
|
1583 |
|
1584 #ifdef USB_SUPPORTS_PREMATURE_STATUS_IN |
|
1585 if (iEp0State == EP0_OUT_DATA_PHASE) |
|
1586 { |
|
1587 // Allow for a premature STATUS IN |
|
1588 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_TXPKTRDY | K_EP0_DATAEND); // TXPKTRDY, DATAEND |
|
1589 } |
|
1590 #endif |
|
1591 } |
|
1592 |
|
1593 |
|
1594 void DOmap3530Usbcc::Ep0ReadSetupPktProceed() |
|
1595 // |
|
1596 // Called by the PIL to signal that it has finished processing a received Setup packet and that the PSL can |
|
1597 // now prepare itself for the next Ep0 reception (for instance by re-enabling the Ep0 interrupt). |
|
1598 // |
|
1599 { |
|
1600 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::Ep0ReadSetupPktProceed")); |
|
1601 |
|
1602 EnableEndpointInterrupt(0); |
|
1603 } |
|
1604 |
|
1605 |
|
1606 void DOmap3530Usbcc::Ep0Receive() |
|
1607 // |
|
1608 // Called from the Ep0 ISR when a data packet has been received. |
|
1609 // |
|
1610 { |
|
1611 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::Ep0Receive")); |
|
1612 AsspRegister::Write8(KUSBBase+K_INDEX_REG, 0); |
|
1613 TEndpoint* const ep = &iEndpoints[KEp0_Out]; |
|
1614 TUint8* buf = ep->iRxBuf; |
|
1615 if (!buf) |
|
1616 { |
|
1617 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: No Ep0 Rx buffer available (2)")); |
|
1618 StallEndpoint(KEp0_Out); |
|
1619 return; |
|
1620 } |
|
1621 |
|
1622 TInt n = 0; |
|
1623 // Read packet data from Rx FIFO into 'buf' and update 'n' (# of received bytes) here. |
|
1624 TInt FIFOCount = AsspRegister::Read8(KUSBBase+K_COUNT0_REG); |
|
1625 for(; n<FIFOCount; n++) |
|
1626 { |
|
1627 // Should try and check we aren't running out of FIFO! |
|
1628 buf[n] = AsspRegister::Read8(KUSBBase+K_FIFO0_REG); |
|
1629 } |
|
1630 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_SERV_RXPKTRDY); // The packet has been retrieved from the FIFO |
|
1631 |
|
1632 ep->iReceived = n; |
|
1633 ep->iRxBuf = NULL; |
|
1634 const TInt r = Ep0RequestComplete(KEp0_Out, n, KErrNone); |
|
1635 |
|
1636 // Don't finish (proceed) if request was 'KErrNotFound'! |
|
1637 if (!(r == KErrNone || r == KErrGeneral)) |
|
1638 { |
|
1639 DisableEndpointInterrupt(0); |
|
1640 } |
|
1641 |
|
1642 #ifdef USB_SUPPORTS_PREMATURE_STATUS_IN |
|
1643 // Allow for a premature STATUS IN |
|
1644 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_TXPKTRDY | K_EP0_DATAEND); // TXPKTRDY, DATAEND |
|
1645 #endif |
|
1646 } |
|
1647 |
|
1648 |
|
1649 void DOmap3530Usbcc::Ep0ReceiveProceed() |
|
1650 // |
|
1651 // Called by the PIL to signal that it has finished processing a received Ep0 data packet and that the PSL can |
|
1652 // now prepare itself for the next Ep0 reception (for instance by re-enabling the Ep0 Ep0ReadSetupPkt). |
|
1653 // |
|
1654 { |
|
1655 Ep0ReadSetupPktProceed(); |
|
1656 } |
|
1657 |
|
1658 |
|
1659 void DOmap3530Usbcc::Ep0Transmit() |
|
1660 // |
|
1661 // Called from either the Ep0 ISR or the PIL when a data packet has been or is to be transmitted. |
|
1662 // |
|
1663 { |
|
1664 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::Ep0Transmit")); |
|
1665 AsspRegister::Write8(KUSBBase+K_INDEX_REG, 0); |
|
1666 if (iEp0State != EP0_IN_DATA_PHASE) |
|
1667 { |
|
1668 __KTRACE_OPT(KUSB, Kern::Printf(" > WARNING: Invalid Ep0 state when trying to handle EP0 IN (0x%x)", iEp0State)); |
|
1669 // TO DO (optional): Do something about this warning. |
|
1670 } |
|
1671 |
|
1672 TEndpoint* const ep = &iEndpoints[KEp0_In]; |
|
1673 const TUint8* buf = ep->iTxBuf; |
|
1674 if (!buf) |
|
1675 { |
|
1676 __KTRACE_OPT(KUSB, Kern::Printf(" > No Tx buffer available: returning")); |
|
1677 return; |
|
1678 } |
|
1679 const TInt t = ep->iTransmitted; // already transmitted |
|
1680 buf += t; |
|
1681 TInt n = 0; // now transmitted |
|
1682 |
|
1683 // Write packet data (if any) into Tx FIFO from 'buf' and update 'n' (# of tx'ed bytes) here. |
|
1684 for(; n<ep->iLength-ep->iTransmitted && n<KEp0MaxPktSz; n++) |
|
1685 { |
|
1686 // Should try and check we aren't running out of FIFO! |
|
1687 AsspRegister::Write8(KUSBBase+K_FIFO0_REG, buf[n]); |
|
1688 } |
|
1689 |
|
1690 ep->iTransmitted += n; |
|
1691 if (n == KEp0MaxPktSz) |
|
1692 { |
|
1693 if (ep->iTransmitted == ep->iLength && !(ep->iZlpReqd)) |
|
1694 { |
|
1695 Ep0NextState(EP0_END_XFER); |
|
1696 } |
|
1697 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_TXPKTRDY); // TXPKTY, |
|
1698 } |
|
1699 else if (n && n != KEp0MaxPktSz) |
|
1700 { |
|
1701 // Send off the data |
|
1702 __ASSERT_DEBUG((ep->iTransmitted == ep->iLength), |
|
1703 Kern::Printf(" > ERROR: Short packet in mid-transfer")); |
|
1704 Ep0NextState(EP0_END_XFER); |
|
1705 // Send off the data here. |
|
1706 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_TXPKTRDY); // TXPKTRDY, |
|
1707 } |
|
1708 else // if (n == 0) |
|
1709 { |
|
1710 __ASSERT_DEBUG((ep->iTransmitted == ep->iLength), |
|
1711 Kern::Printf(" > ERROR: Nothing transmitted but still not finished")); |
|
1712 if (ep->iZlpReqd) |
|
1713 { |
|
1714 // Send a zero length packet |
|
1715 ep->iZlpReqd = EFalse; |
|
1716 Ep0NextState(EP0_END_XFER); |
|
1717 // Arrange for the sending of a ZLP here. |
|
1718 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_TXPKTRDY | K_EP0_DATAEND); // TXPKTRDY, DATAEND |
|
1719 } |
|
1720 else |
|
1721 { |
|
1722 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: nothing transmitted & no ZLP req'd")); |
|
1723 } |
|
1724 } |
|
1725 } |
|
1726 |
|
1727 |
|
1728 void DOmap3530Usbcc::Ep0EndXfer() |
|
1729 // |
|
1730 // Called at the end of a Ep0 Control transfer. |
|
1731 // |
|
1732 { |
|
1733 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::Ep0EndXfer")); |
|
1734 // Clear Ep0 Rx condition flags here. |
|
1735 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_SERV_RXPKTRDY | K_EP0_DATAEND); // DATAEND |
|
1736 |
|
1737 Ep0NextState(EP0_IDLE); |
|
1738 TEndpoint* const ep = &iEndpoints[KEp0_In]; |
|
1739 ep->iTxBuf = NULL; |
|
1740 (void) Ep0RequestComplete(KEp0_In, ep->iTransmitted, KErrNone); |
|
1741 } |
|
1742 |
|
1743 |
|
1744 void DOmap3530Usbcc::Ep0Cancel() |
|
1745 // |
|
1746 // Called when an ongoing Ep0 Control transfer has to be aborted prematurely (for instance when receiving a |
|
1747 // new Setup packet before the processing of the old one has completed). |
|
1748 // |
|
1749 { |
|
1750 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::Ep0Cancel")); |
|
1751 |
|
1752 Ep0NextState(EP0_IDLE); |
|
1753 TEndpoint* const ep = &iEndpoints[KEp0_In]; |
|
1754 if (ep->iTxBuf) |
|
1755 { |
|
1756 ep->iTxBuf = NULL; |
|
1757 const TInt err = (ep->iTransmitted == ep->iLength) ? KErrNone : KErrCancel; |
|
1758 (void) Ep0RequestComplete(KEp0_In, ep->iTransmitted, err); |
|
1759 } |
|
1760 } |
|
1761 |
|
1762 |
|
1763 void DOmap3530Usbcc::Ep0PrematureStatusOut() |
|
1764 // |
|
1765 // Called when an ongoing Ep0 Control transfer encounters a premature Status OUT condition. |
|
1766 // |
|
1767 { |
|
1768 __KTRACE_OPT(KPANIC, Kern::Printf("DOmap3530Usbcc::Ep0PrematureStatusOut")); |
|
1769 |
|
1770 // Clear Ep0 Rx condition flags here. |
|
1771 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_SERV_RXPKTRDY | K_EP0_DATAEND); // DATAEND |
|
1772 Ep0NextState(EP0_IDLE); |
|
1773 |
|
1774 // Flush the Ep0 Tx FIFO here, if possible. |
|
1775 AsspRegister::Modify16(KUSBBase+K_PERI_CSR0_REG, KClearNone, K_EP0_FLUSHFIFO); |
|
1776 |
|
1777 TEndpoint* const ep = &iEndpoints[KEp0_In]; |
|
1778 if (ep->iTxBuf) |
|
1779 { |
|
1780 ep->iTxBuf = NULL; |
|
1781 (void) Ep0RequestComplete(KEp0_In, ep->iTransmitted, KErrPrematureEnd); |
|
1782 } |
|
1783 } |
|
1784 |
|
1785 |
|
1786 void DOmap3530Usbcc::Ep0StatusIn() |
|
1787 // |
|
1788 // Called when an ongoing Ep0 Control transfer moves to a Status IN stage. |
|
1789 // |
|
1790 { |
|
1791 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::Ep0StatusIn")); |
|
1792 |
|
1793 Ep0NextState(EP0_IDLE); |
|
1794 } |
|
1795 |
|
1796 |
|
1797 void DOmap3530Usbcc::BulkTransmit(TInt aEndpoint) |
|
1798 // |
|
1799 // Endpoint 1 (BULK IN). |
|
1800 // Called from either the Ep ISR or the PIL when a data packet has been or is to be transmitted. |
|
1801 // |
|
1802 { |
|
1803 Interrupt::Disable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
1804 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::BulkTransmit(%d)", aEndpoint)); |
|
1805 |
|
1806 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aEndpoint/2)); |
|
1807 |
|
1808 TInt status = AsspRegister::Read16(KUSBBase+K_PERI_TXCSR_REG); |
|
1809 |
|
1810 if(status & K_TX_UNDERRUN) |
|
1811 { |
|
1812 // TX UNDERRUN |
|
1813 AsspRegister::Modify16(KUSBBase+K_PERI_TXCSR_REG, K_TX_UNDERRUN, KSetNone); |
|
1814 } |
|
1815 if(status & K_TX_SENTSTALL) |
|
1816 { |
|
1817 __KTRACE_OPT(KPANIC, Kern::Printf(" Stall Handshake")); |
|
1818 // Complete stall handshake |
|
1819 AsspRegister::Modify16(KUSBBase+K_PERI_TXCSR_REG, K_TX_SENTSTALL, KSetNone); |
|
1820 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
1821 return; |
|
1822 } |
|
1823 if(status & K_TX_SENDSTALL) |
|
1824 { |
|
1825 __KTRACE_OPT(KPANIC, Kern::Printf(" Stalled")); |
|
1826 // We are stalled |
|
1827 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
1828 return; |
|
1829 } |
|
1830 |
|
1831 TBool calledFromISR=AsspRegister::Read16(KUSBBase+K_INTRTX_REG) & 1<<(aEndpoint/2)==1; |
|
1832 |
|
1833 const TInt idx = aEndpoint; // only in our special case of course! |
|
1834 TEndpoint* const ep = &iEndpoints[idx]; |
|
1835 const TUint8* buf = ep->iTxBuf; |
|
1836 |
|
1837 if (!buf) |
|
1838 { |
|
1839 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: No Tx buffer has been set up")); |
|
1840 DisableEndpointInterrupt(aEndpoint); |
|
1841 ep->iDisabled = ETrue; |
|
1842 ClearEndpointInterrupt(aEndpoint); |
|
1843 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
1844 return; |
|
1845 } |
|
1846 const TInt t = ep->iTransmitted; // already transmitted |
|
1847 const TInt len = ep->iLength; // to be sent in total |
|
1848 // (len || ep->iPackets): Don't complete for a zero bytes request straight away. |
|
1849 if (t >= len && (len || ep->iPackets)) |
|
1850 { |
|
1851 if (ep->iZlpReqd) |
|
1852 { |
|
1853 __KTRACE_OPT(KPANIC, Kern::Printf(" > 'Transmit Short Packet' explicitly")); |
|
1854 // Arrange for the sending of a ZLP here. |
|
1855 AsspRegister::Modify16(KUSBBase+K_PERI_TXCSR_REG, KClearNone, K_TX_TXPKTRDY); // FIFO_NOT_EMPTY, TXPKTRDY |
|
1856 ep->iZlpReqd = EFalse; |
|
1857 } |
|
1858 else |
|
1859 { |
|
1860 __KTRACE_OPT(KUSB, Kern::Printf(" > All data sent: %d --> completing", len)); |
|
1861 ep->iTxBuf = NULL; |
|
1862 ep->iRequest->iTxBytes = ep->iTransmitted; |
|
1863 ep->iRequest->iError = KErrNone; |
|
1864 EndpointRequestComplete(ep->iRequest); |
|
1865 ep->iRequest = NULL; |
|
1866 } |
|
1867 } |
|
1868 else |
|
1869 { |
|
1870 buf += t; |
|
1871 TInt left = len - t; // left in total |
|
1872 TInt n = (left >= KBlkMaxPktSz) ? KBlkMaxPktSz : left; // now to be transmitted |
|
1873 __KTRACE_OPT(KUSB, Kern::Printf(" > About to send %d bytes (%d bytes left in total)", n, left)); |
|
1874 |
|
1875 // Write data into Tx FIFO from 'buf' here... |
|
1876 TInt x=0; |
|
1877 TInt FIFOAddr = K_FIFO0_REG+K_FIFO_OFFSET*(TInt)((aEndpoint)/2); |
|
1878 for(; x<n; x++) // While FIFO is not full... |
|
1879 { |
|
1880 // Should try and check we aren't running out of FIFO! |
|
1881 AsspRegister::Write8(KUSBBase+FIFOAddr, buf[x]); |
|
1882 } |
|
1883 AsspRegister::Modify16(KUSBBase+K_PERI_TXCSR_REG, KClearNone, /*K_TX_FIFONOTEMPTY | */K_TX_TXPKTRDY); // TXPKTRDY |
|
1884 ep->iTransmitted += x; |
|
1885 ep->iPackets++; // only used for (len == 0) case |
|
1886 left -= n; // (still) left in total |
|
1887 |
|
1888 // If double-buffering is available, it might be possible to stick a second packet |
|
1889 // into the FIFO here. |
|
1890 |
|
1891 // TO DO (optional): Send another packet if possible (& available) here. |
|
1892 |
|
1893 } |
|
1894 if(calledFromISR) |
|
1895 { |
|
1896 ClearEndpointInterrupt(aEndpoint); |
|
1897 } |
|
1898 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
1899 } |
|
1900 |
|
1901 |
|
1902 |
|
1903 void DOmap3530Usbcc::BulkReceive(TInt aEndpoint) |
|
1904 // |
|
1905 // Endpoint 2 (BULK OUT) (This one is called in an ISR.) |
|
1906 // |
|
1907 { |
|
1908 Interrupt::Disable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
1909 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::BulkReceive(%d)", aEndpoint)); |
|
1910 |
|
1911 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aEndpoint/2)); |
|
1912 |
|
1913 // Start NYETTING packets.. |
|
1914 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, K_RX_DISNYET, KSetNone); |
|
1915 |
|
1916 TInt status = AsspRegister::Read16(KUSBBase+K_PERI_RXCSR_REG); |
|
1917 |
|
1918 if(status & K_RX_OVERRUN) |
|
1919 { |
|
1920 // RX OVERRUN |
|
1921 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, K_RX_OVERRUN, KSetNone); |
|
1922 } |
|
1923 if(status & K_RX_SENTSTALL) |
|
1924 { |
|
1925 // Complete stall handshake |
|
1926 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, K_RX_SENTSTALL, K_RX_DISNYET); |
|
1927 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
1928 return; |
|
1929 } |
|
1930 |
|
1931 if(status & K_RX_SENDSTALL) |
|
1932 { |
|
1933 // We are stalled |
|
1934 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, KClearNone, K_RX_DISNYET); |
|
1935 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
1936 return; |
|
1937 } |
|
1938 |
|
1939 TBool calledFromISR=AsspRegister::Read16(KUSBBase+K_INTRRX_REG) & 1<<(aEndpoint/2)==1; |
|
1940 |
|
1941 const TInt idx = aEndpoint; // only in our special case of course! |
|
1942 TEndpoint* const ep = &iEndpoints[idx]; |
|
1943 TUint8* buf = ep->iRxBuf; |
|
1944 if (!buf) |
|
1945 { |
|
1946 __KTRACE_OPT(KUSB, Kern::Printf(" > No Rx buffer available: setting iNoBuffer")); |
|
1947 ep->iNoBuffer = ETrue; |
|
1948 DisableEndpointInterrupt(aEndpoint); |
|
1949 ep->iDisabled = ETrue; |
|
1950 ClearEndpointInterrupt(aEndpoint); |
|
1951 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
1952 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, KClearNone, K_RX_DISNYET); |
|
1953 return; |
|
1954 } |
|
1955 TInt bytes = AsspRegister::Read16(KUSBBase+K_RXCOUNT_REG); |
|
1956 const TInt r = ep->iReceived; // already received |
|
1957 // Check whether a ZLP was received here: |
|
1958 if (bytes==0) |
|
1959 { |
|
1960 __KTRACE_OPT(KUSB, Kern::Printf(" > received zero-length packet")); |
|
1961 } |
|
1962 else// if (status & 2) // some other condition |
|
1963 { |
|
1964 __KTRACE_OPT(KUSB, Kern::Printf(" > Bulk received: %d bytes", bytes)); |
|
1965 if (r + bytes > ep->iLength) |
|
1966 { |
|
1967 __KTRACE_OPT(KUSB, Kern::Printf(" > not enough space in rx buffer: setting iNoBuffer")); |
|
1968 ep->iNoBuffer = ETrue; |
|
1969 StopRxTimer(ep); |
|
1970 *ep->iPacketSize = ep->iReceived; |
|
1971 RxComplete(ep); |
|
1972 |
|
1973 if(calledFromISR) |
|
1974 { |
|
1975 ClearEndpointInterrupt(aEndpoint); |
|
1976 } |
|
1977 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, KClearNone, K_RX_DISNYET); |
|
1978 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
1979 return; |
|
1980 } |
|
1981 buf += r; // set buffer pointer |
|
1982 |
|
1983 // Read 'bytes' bytes from Rx FIFO into 'buf' here. |
|
1984 TInt FIFOAddr = K_FIFO0_REG+K_FIFO_OFFSET*(TInt)((aEndpoint)/2); |
|
1985 for(TInt n=0; n<bytes; n++) |
|
1986 { |
|
1987 // Should try and check we aren't running out of FIFO! |
|
1988 buf[n] = AsspRegister::Read8(KUSBBase+FIFOAddr); |
|
1989 } |
|
1990 |
|
1991 ep->iReceived += bytes; |
|
1992 } |
|
1993 |
|
1994 if (bytes == 0) |
|
1995 { |
|
1996 // ZLPs must be recorded separately |
|
1997 const TInt i = ep->iReceived ? 1 : 0; |
|
1998 ep->iPacketIndex[i] = r; |
|
1999 ep->iPacketSize[i] = 0; |
|
2000 // If there were data packets before: total packets reported 1 -> 2 |
|
2001 ep->iPackets += i; |
|
2002 } |
|
2003 |
|
2004 if ((bytes < KBlkMaxPktSz) || |
|
2005 (ep->iReceived == ep->iLength)) |
|
2006 { |
|
2007 StopRxTimer(ep); |
|
2008 *ep->iPacketSize = ep->iReceived; |
|
2009 RxComplete(ep); |
|
2010 // since we have no buffer any longer we disable interrupts: |
|
2011 DisableEndpointInterrupt(aEndpoint); |
|
2012 ep->iDisabled = ETrue; |
|
2013 } |
|
2014 else |
|
2015 { |
|
2016 if (!ep->iRxTimerSet) |
|
2017 { |
|
2018 __KTRACE_OPT(KUSB, Kern::Printf(" > setting rx timer")); |
|
2019 ep->iRxTimerSet = ETrue; |
|
2020 ep->iRxTimer.OneShot(KRxTimerTimeout); |
|
2021 } |
|
2022 else |
|
2023 { |
|
2024 ep->iRxMoreDataRcvd = ETrue; |
|
2025 } |
|
2026 } |
|
2027 if(calledFromISR) |
|
2028 { |
|
2029 ClearEndpointInterrupt(aEndpoint); |
|
2030 } |
|
2031 // Clear Ep Rx condition flags here. |
|
2032 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, K_RX_RXPKTRDY, K_RX_DISNYET); |
|
2033 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
2034 } |
|
2035 |
|
2036 |
|
2037 void DOmap3530Usbcc::BulkReadRxFifo(TInt aEndpoint) |
|
2038 // |
|
2039 // Endpoint 2 (BULK OUT) (This one is called w/o interrupt to be served.) |
|
2040 // |
|
2041 { |
|
2042 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::BulkReadRxFifo(%d)", aEndpoint)); |
|
2043 Interrupt::Disable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
2044 |
|
2045 AsspRegister::Write8(KUSBBase+K_INDEX_REG, (TInt)(aEndpoint/2)); |
|
2046 |
|
2047 // Start NYETTING packets.. |
|
2048 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, K_RX_DISNYET, KSetNone); |
|
2049 |
|
2050 TInt status = AsspRegister::Read16(KUSBBase+K_PERI_RXCSR_REG); |
|
2051 if(status & K_RX_OVERRUN) |
|
2052 { |
|
2053 // RX OVERRUN |
|
2054 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, K_RX_OVERRUN, KSetNone); |
|
2055 } |
|
2056 if(status & K_RX_SENTSTALL) |
|
2057 { |
|
2058 // Complete stall handshake |
|
2059 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, K_RX_SENTSTALL, K_RX_DISNYET); |
|
2060 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
2061 return; |
|
2062 } |
|
2063 if(status & K_RX_SENTSTALL) |
|
2064 { |
|
2065 // We are stalled |
|
2066 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, KClearNone, K_RX_DISNYET); |
|
2067 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
2068 return; |
|
2069 } |
|
2070 |
|
2071 TBool calledFromISR=AsspRegister::Read16(KUSBBase+K_INTRRX_REG) & 1<<(aEndpoint/2)==1; |
|
2072 |
|
2073 const TInt idx = aEndpoint; // only in our special case of course! |
|
2074 TEndpoint* const ep = &iEndpoints[idx]; |
|
2075 TUint8* buf = ep->iRxBuf; |
|
2076 if (!buf) |
|
2077 { |
|
2078 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: No Rx buffer has been set up")); |
|
2079 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
2080 return; |
|
2081 } |
|
2082 TInt bytes = AsspRegister::Read16(KUSBBase+K_RXCOUNT_REG); |
|
2083 const TInt r = ep->iReceived; // already received |
|
2084 // Check whether a ZLP was received here: |
|
2085 if (bytes==0) // some condition |
|
2086 { |
|
2087 __KTRACE_OPT(KUSB, Kern::Printf(" > received zero-length packet")); |
|
2088 } |
|
2089 else //if (status & 2) // some other condition |
|
2090 { |
|
2091 __KTRACE_OPT(KUSB, Kern::Printf(" > Bulk received: %d bytes", bytes)); |
|
2092 if (r + bytes > ep->iLength) |
|
2093 { |
|
2094 __KTRACE_OPT(KUSB, Kern::Printf(" > not enough space in rx buffer: setting iNoBuffer")); |
|
2095 ep->iNoBuffer = ETrue; |
|
2096 *ep->iPacketSize = ep->iReceived; |
|
2097 RxComplete(ep); |
|
2098 |
|
2099 // Stop NYETting packets |
|
2100 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, KClearNone, K_RX_DISNYET); |
|
2101 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
2102 return; |
|
2103 } |
|
2104 buf += r; // set buffer pointer |
|
2105 |
|
2106 // TO DO: Read 'bytes' bytes from Rx FIFO into 'buf' here. |
|
2107 TInt FIFOAddr = K_FIFO0_REG+K_FIFO_OFFSET*(TInt)((aEndpoint)/2); |
|
2108 for(TInt n=0; n<bytes; n++) |
|
2109 { |
|
2110 // Should try and check we aren't running out of FIFO! |
|
2111 buf[n] = AsspRegister::Read8(KUSBBase+FIFOAddr); |
|
2112 } |
|
2113 ep->iReceived += bytes; |
|
2114 } |
|
2115 if (bytes == 0) |
|
2116 { |
|
2117 // ZLPs must be recorded separately |
|
2118 const TInt i = ep->iReceived ? 1 : 0; |
|
2119 ep->iPacketIndex[i] = r; |
|
2120 ep->iPacketSize[i] = 0; |
|
2121 // If there were data packets before: total packets reported 1 -> 2 |
|
2122 ep->iPackets += i; |
|
2123 } |
|
2124 |
|
2125 if ((bytes < KBlkMaxPktSz) || |
|
2126 (ep->iReceived == ep->iLength)) |
|
2127 { |
|
2128 *ep->iPacketSize = ep->iReceived; |
|
2129 RxComplete(ep); |
|
2130 } |
|
2131 else |
|
2132 { |
|
2133 if (!ep->iRxTimerSet) |
|
2134 { |
|
2135 __KTRACE_OPT(KUSB, Kern::Printf(" > setting rx timer")); |
|
2136 ep->iRxTimerSet = ETrue; |
|
2137 ep->iRxTimer.OneShot(KRxTimerTimeout); |
|
2138 } |
|
2139 else |
|
2140 { |
|
2141 ep->iRxMoreDataRcvd = ETrue; |
|
2142 } |
|
2143 } |
|
2144 |
|
2145 if(calledFromISR) |
|
2146 { |
|
2147 ClearEndpointInterrupt(aEndpoint); |
|
2148 } |
|
2149 |
|
2150 // Stop NYETting packets and Clear Ep Rx condition flags here. |
|
2151 AsspRegister::Modify16(KUSBBase+K_PERI_RXCSR_REG, K_RX_RXPKTRDY, K_RX_DISNYET); |
|
2152 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
2153 } |
|
2154 |
|
2155 |
|
2156 void DOmap3530Usbcc::IsoTransmit(TInt aEndpoint) |
|
2157 // |
|
2158 // Endpoint 3 (ISOCHRONOUS IN). |
|
2159 // |
|
2160 { |
|
2161 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::IsoTransmit(%d)", aEndpoint)); |
|
2162 |
|
2163 // TO DO: Write data to endpoint FIFO. Might be similar to BulkTransmit. |
|
2164 |
|
2165 } |
|
2166 |
|
2167 |
|
2168 void DOmap3530Usbcc::IsoReceive(TInt aEndpoint) |
|
2169 // |
|
2170 // Endpoint 4 (ISOCHRONOUS OUT) (This one is called in an ISR.) |
|
2171 // |
|
2172 { |
|
2173 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::IsoReceive(%d)", aEndpoint)); |
|
2174 |
|
2175 // TO DO: Read data from endpoint FIFO. Might be similar to BulkReceive. |
|
2176 } |
|
2177 |
|
2178 |
|
2179 void DOmap3530Usbcc::IsoReadRxFifo(TInt aEndpoint) |
|
2180 // |
|
2181 // Endpoint 4 (ISOCHRONOUS OUT) (This one is called w/o interrupt to be served.) |
|
2182 // |
|
2183 { |
|
2184 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::IsoReadRxFifo(%d)", aEndpoint)); |
|
2185 |
|
2186 // TO DO: Read data from endpoint FIFO. Might be similar to BulkReadRxFifo. |
|
2187 } |
|
2188 |
|
2189 |
|
2190 void DOmap3530Usbcc::IntTransmit(TInt aEndpoint) |
|
2191 // |
|
2192 // Endpoint 5 (INTERRUPT IN). |
|
2193 // |
|
2194 { |
|
2195 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::IntTransmit(%d)", aEndpoint)); |
|
2196 |
|
2197 // TO DO: Write data to endpoint FIFO. Might be similar to BulkTransmit. |
|
2198 } |
|
2199 |
|
2200 |
|
2201 void DOmap3530Usbcc::RxComplete(TEndpoint* aEndpoint) |
|
2202 // |
|
2203 // Called at the end of an Rx (OUT) transfer to complete to the PIL. |
|
2204 // |
|
2205 { |
|
2206 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::RxComplete")); |
|
2207 TUsbcRequestCallback* const req = aEndpoint->iRequest; |
|
2208 |
|
2209 __ASSERT_DEBUG((req != NULL), Kern::Fault(KUsbPanicCat, __LINE__)); |
|
2210 |
|
2211 aEndpoint->iRxBuf = NULL; |
|
2212 aEndpoint->iRxTimerSet = EFalse; |
|
2213 aEndpoint->iRxMoreDataRcvd = EFalse; |
|
2214 req->iRxPackets = aEndpoint->iPackets; |
|
2215 req->iError = aEndpoint->iLastError; |
|
2216 EndpointRequestComplete(req); |
|
2217 aEndpoint->iRequest = NULL; |
|
2218 } |
|
2219 |
|
2220 |
|
2221 void DOmap3530Usbcc::StopRxTimer(TEndpoint* aEndpoint) |
|
2222 // |
|
2223 // Stops (cancels) the Rx timer for an endpoint. |
|
2224 // |
|
2225 { |
|
2226 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::StopRxTimer")); |
|
2227 |
|
2228 if (aEndpoint->iRxTimerSet) |
|
2229 { |
|
2230 __KTRACE_OPT(KUSB, Kern::Printf(" > stopping rx timer")); |
|
2231 aEndpoint->iRxTimer.Cancel(); |
|
2232 aEndpoint->iRxTimerSet = EFalse; |
|
2233 } |
|
2234 } |
|
2235 |
|
2236 |
|
2237 void DOmap3530Usbcc::EndpointIntService(TInt aEndpoint) |
|
2238 // |
|
2239 // ISR for endpoint interrupts. |
|
2240 // Note: the aEndpoint here is a "hardware endpoint", not a aRealEndpoint. |
|
2241 // |
|
2242 { |
|
2243 switch (aEndpoint) |
|
2244 { |
|
2245 case 0: |
|
2246 Ep0IntService(); |
|
2247 break; |
|
2248 case 3: |
|
2249 case 5: |
|
2250 case 7: |
|
2251 case 9: |
|
2252 case 11: |
|
2253 case 13: |
|
2254 case 15: |
|
2255 case 17: |
|
2256 case 19: |
|
2257 case 21: |
|
2258 case 23: |
|
2259 case 25: |
|
2260 case 27: |
|
2261 case 29: |
|
2262 BulkTransmit(aEndpoint); |
|
2263 break; |
|
2264 case 2: |
|
2265 case 4: |
|
2266 case 6: |
|
2267 case 8: |
|
2268 case 10: |
|
2269 case 12: |
|
2270 case 14: |
|
2271 case 16: |
|
2272 case 18: |
|
2273 case 20: |
|
2274 case 22: |
|
2275 case 24: |
|
2276 case 26: |
|
2277 case 28: |
|
2278 BulkReceive(aEndpoint); |
|
2279 break; |
|
2280 case 30: |
|
2281 IntTransmit(aEndpoint); |
|
2282 break; |
|
2283 default: |
|
2284 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Endpoint not found")); |
|
2285 break; |
|
2286 } |
|
2287 } |
|
2288 |
|
2289 |
|
2290 TInt DOmap3530Usbcc::ResetIntService() |
|
2291 // |
|
2292 // ISR for a USB Reset event interrupt. |
|
2293 // This function returns a value which can be used on the calling end to decide how to proceed. |
|
2294 // |
|
2295 { |
|
2296 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::ResetIntService")); |
|
2297 |
|
2298 // Clear an interrupt: |
|
2299 // TO DO: Clear reset interrupt flag here. |
|
2300 |
|
2301 // TO DO (optional): Enquire about special conditions and possibly return here. |
|
2302 |
|
2303 DeviceEventNotification(EUsbEventReset); |
|
2304 |
|
2305 return KErrNone; |
|
2306 } |
|
2307 |
|
2308 |
|
2309 void DOmap3530Usbcc::SuspendIntService() |
|
2310 // |
|
2311 // ISR for a USB Suspend event interrupt. |
|
2312 // |
|
2313 { |
|
2314 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::SuspendIntService")); |
|
2315 |
|
2316 // Clear an interrupt: |
|
2317 // TO DO: Clear suspend interrupt flag here. |
|
2318 |
|
2319 DeviceEventNotification(EUsbEventSuspend); |
|
2320 } |
|
2321 |
|
2322 |
|
2323 void DOmap3530Usbcc::ResumeIntService() |
|
2324 // |
|
2325 // ISR for a USB Resume event interrupt. |
|
2326 // |
|
2327 { |
|
2328 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::ResumeIntService")); |
|
2329 |
|
2330 // Clear an interrupt: |
|
2331 // TO DO: Clear resume interrupt flag here. |
|
2332 |
|
2333 DeviceEventNotification(EUsbEventResume); |
|
2334 } |
|
2335 |
|
2336 |
|
2337 void DOmap3530Usbcc::SofIntService() |
|
2338 // |
|
2339 // ISR for a USB Start-of-Frame event interrupt. |
|
2340 // |
|
2341 { |
|
2342 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::SofIntService")); |
|
2343 |
|
2344 // Clear an interrupt: |
|
2345 // TO DO: Clear SOF interrupt flag here. |
|
2346 |
|
2347 // TO DO (optional): Do something about the SOF condition. |
|
2348 } |
|
2349 |
|
2350 |
|
2351 void DOmap3530Usbcc::UdcInterruptService() |
|
2352 // |
|
2353 // Main UDC ISR - determines the cause of the interrupt, clears the condition, dispatches further for service. |
|
2354 // |
|
2355 { |
|
2356 Interrupt::Disable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
2357 TUint status = AsspRegister::Read8(KUSBBase+K_INTRUSB_REG); |
|
2358 |
|
2359 // Reset interrupt |
|
2360 if (status & K_INT_RESET) |
|
2361 { |
|
2362 ResetIntService(); |
|
2363 } |
|
2364 |
|
2365 // Resume interrupt |
|
2366 if (status & K_INT_RESUME) |
|
2367 { |
|
2368 ResumeIntService(); |
|
2369 } |
|
2370 |
|
2371 // Endpoint interrupt |
|
2372 TUint TxEpInt = AsspRegister::Read16(KUSBBase+K_INTRTX_REG); |
|
2373 |
|
2374 TInt ep=0; |
|
2375 for(TInt x=0; TxEpInt!=0 && x<16 ; x++) |
|
2376 { |
|
2377 if(TxEpInt&(1<<x)) |
|
2378 { |
|
2379 EndpointIntService(ep); |
|
2380 } |
|
2381 if(ep==0) { ep++; } // TX EP's are odd numbered - numbers are array indicies so we start from 2 |
|
2382 ep+=2; |
|
2383 } |
|
2384 TUint RxEpInt = AsspRegister::Read16(KUSBBase+K_INTRRX_REG); |
|
2385 ep=2; |
|
2386 for(TInt x=1; RxEpInt!=0 && x<16; x++) |
|
2387 { |
|
2388 if(RxEpInt&(1<<x)) |
|
2389 { |
|
2390 EndpointIntService(ep); |
|
2391 } |
|
2392 ep+=2; |
|
2393 } |
|
2394 |
|
2395 // Suspend interrupt should be serviced last |
|
2396 if (status & K_INT_SUSPEND) |
|
2397 { |
|
2398 SuspendIntService(); |
|
2399 } |
|
2400 |
|
2401 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
2402 } |
|
2403 |
|
2404 |
|
2405 void DOmap3530Usbcc::Ep0NextState(TEp0State aNextState) |
|
2406 // |
|
2407 // Moves the Ep0 state to aNextState. |
|
2408 // |
|
2409 { |
|
2410 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::Ep0NextState")); |
|
2411 iEp0State = aNextState; |
|
2412 } |
|
2413 |
|
2414 |
|
2415 void DOmap3530Usbcc::UdcIsr(TAny* aPtr) |
|
2416 // |
|
2417 // This is the static ASSP first-level UDC interrupt service routine. It dispatches the call to the |
|
2418 // actual controller's ISR. |
|
2419 // |
|
2420 { |
|
2421 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::UdcIsr")); |
|
2422 static_cast<DOmap3530Usbcc*>(aPtr)->UdcInterruptService(); |
|
2423 } |
|
2424 |
|
2425 |
|
2426 TInt DOmap3530Usbcc::UsbClientConnectorCallback(TAny* aPtr) |
|
2427 // |
|
2428 // This function is called in ISR context by the Variant's UsbClientConnectorInterruptService. |
|
2429 // (This function is static.) |
|
2430 // |
|
2431 { |
|
2432 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::UsbClientConnectorCallback")); |
|
2433 |
|
2434 DOmap3530Usbcc* const ptr = static_cast<DOmap3530Usbcc*>(aPtr); |
|
2435 ptr->iCableConnected = ptr->iAssp->UsbClientConnectorInserted(); |
|
2436 #ifdef _DEBUG |
|
2437 _LIT(KIns, "inserted"); |
|
2438 _LIT(KRem, "removed"); |
|
2439 __KTRACE_OPT(KUSB, Kern::Printf(" > USB cable now %lS", ptr->iCableConnected ? &KIns : &KRem)); |
|
2440 #endif |
|
2441 if (ptr->iCableConnected) |
|
2442 { |
|
2443 ptr->DeviceEventNotification(EUsbEventCableInserted); |
|
2444 } |
|
2445 else |
|
2446 { |
|
2447 ptr->DeviceEventNotification(EUsbEventCableRemoved); |
|
2448 } |
|
2449 |
|
2450 return KErrNone; |
|
2451 } |
|
2452 |
|
2453 |
|
2454 TInt DOmap3530Usbcc::SetupUdcInterrupt() |
|
2455 // |
|
2456 // Registers and enables the UDC interrupt (ASSP first level interrupt). |
|
2457 // |
|
2458 { |
|
2459 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::SetupUdcInterrupt")); |
|
2460 |
|
2461 TInt error = Interrupt::Bind(EOmap3530_IRQ92_HSUSB_MC_NINT, UdcIsr, this); |
|
2462 if (error != KErrNone) |
|
2463 { |
|
2464 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Binding UDC interrupt failed")); |
|
2465 return error; |
|
2466 } |
|
2467 Interrupt::Enable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
2468 return KErrNone; |
|
2469 } |
|
2470 |
|
2471 |
|
2472 void DOmap3530Usbcc::ReleaseUdcInterrupt() |
|
2473 // |
|
2474 // Disables and unbinds the UDC interrupt. |
|
2475 // |
|
2476 { |
|
2477 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::ReleaseUdcInterrupt")); |
|
2478 |
|
2479 Interrupt::Disable(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
2480 Interrupt::Unbind(EOmap3530_IRQ92_HSUSB_MC_NINT); |
|
2481 } |
|
2482 |
|
2483 |
|
2484 void DOmap3530Usbcc::EnableSICLK() |
|
2485 { |
|
2486 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::EnableSICLK")); |
|
2487 if(iSICLKEnabled==0) |
|
2488 { |
|
2489 //TInt r = PowerResourceManager::ChangeResourceState( iPrmClientId, Omap3530Prm::EPrmClkHsUsbOtg_I, Prcm::EClkAuto ); |
|
2490 // What are we supposed to do with errors from PRM? |
|
2491 |
|
2492 |
|
2493 AsspRegister::Modify32(KCM_ICLKEN1_CORE, KClearNone, KENHOSTOTGUSB_BIT); |
|
2494 AsspRegister::Modify32(KCM_AUTOIDLE1_CORE, KClearNone, KAUTO_HOSTOTGUSB_BIT); |
|
2495 |
|
2496 |
|
2497 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc: SICLK Enabled")); |
|
2498 } |
|
2499 iSICLKEnabled++; |
|
2500 } |
|
2501 |
|
2502 void DOmap3530Usbcc::DisableSICLK() |
|
2503 { |
|
2504 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::DisableSICLK")); |
|
2505 if(iSICLKEnabled==1) |
|
2506 { |
|
2507 //TInt r = PowerResourceManager::ChangeResourceState( iPrmClientId, Omap3530Prm::EPrmClkHsUsbOtg_I, Prcm::EClkOff ); |
|
2508 // What are we supposed to do with errors from PRM? |
|
2509 |
|
2510 AsspRegister::Modify32(KCM_ICLKEN1_CORE, KENHOSTOTGUSB_BIT, KSetNone); |
|
2511 AsspRegister::Modify32(KCM_AUTOIDLE1_CORE, KAUTO_HOSTOTGUSB_BIT, KSetNone); |
|
2512 |
|
2513 |
|
2514 } |
|
2515 if(iSICLKEnabled>0) |
|
2516 { |
|
2517 iSICLKEnabled--; |
|
2518 } |
|
2519 } |
|
2520 |
|
2521 TBool DOmap3530Usbcc::CurrentlyUsingHighSpeed() |
|
2522 { |
|
2523 return ETrue; |
|
2524 } |
|
2525 |
|
2526 void DOmap3530Usbcc::SuspendDfcFn(TAny *aPtr) |
|
2527 { |
|
2528 |
|
2529 } |
|
2530 |
|
2531 void DOmap3530Usbcc::ResumeDfcFn(TAny *aPtr) |
|
2532 { |
|
2533 |
|
2534 } |
|
2535 |
|
2536 void DOmap3530Usbcc::ResetDfcFn(TAny *aPtr) |
|
2537 { |
|
2538 DOmap3530Usbcc* self = reinterpret_cast<DOmap3530Usbcc*>(aPtr); |
|
2539 // Put the Transceiver into normal mode |
|
2540 self->iPhy->EnablePHY(); |
|
2541 self->iPhy->SetPHYMode(ENormal); |
|
2542 self->iPhy->DisablePHY(); |
|
2543 } |
|
2544 |
|
2545 TBool DOmap3530Usbcc::DeviceHighSpeedCaps() const |
|
2546 { |
|
2547 __KTRACE_OPT(KUSB, Kern::Printf("DOmap3530Usbcc::DeviceHighSpeedCaps()")); |
|
2548 return ETrue; |
|
2549 } |
|
2550 |
|
2551 |
|
2552 // |
|
2553 // --- DLL Exported Function -------------------------------------------------- |
|
2554 // |
|
2555 |
|
2556 DECLARE_STANDARD_EXTENSION() |
|
2557 { |
|
2558 __KTRACE_OPT(KUSB, Kern::Printf(" > Initializing USB client support (Udcc)...")); |
|
2559 |
|
2560 DOmap3530Usbcc* const usbcc = new DOmap3530Usbcc(); |
|
2561 if (!usbcc) |
|
2562 { |
|
2563 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Memory allocation for DOmap3530Usbcc failed")); |
|
2564 return KErrNoMemory; |
|
2565 } |
|
2566 Kern::Printf( "$1" ); |
|
2567 TInt r; |
|
2568 if ((r = usbcc->Construct()) != KErrNone) |
|
2569 { |
|
2570 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Construction of DOmap3530Usbcc failed (%d)", r)); |
|
2571 delete usbcc; |
|
2572 return r; |
|
2573 } |
|
2574 Kern::Printf( "$2" ); |
|
2575 |
|
2576 if (usbcc->RegisterUdc(0) == NULL) |
|
2577 { |
|
2578 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: PIL registration of PSL failed")); |
|
2579 delete usbcc; |
|
2580 return KErrGeneral; |
|
2581 } |
|
2582 |
|
2583 __KTRACE_OPT(KUSB, Kern::Printf(" > Initializing USB client support: Done")); |
|
2584 |
|
2585 return KErrNone; |
|
2586 } |
|
2587 |
|
2588 |
|
2589 // --- EOF -------------------------------------------------------------------- |