0
|
1 |
// Copyright (c) 2003-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 |
//
|
|
15 |
|
|
16 |
#include <drivers/sdio/sdio.h>
|
|
17 |
#include <drivers/sdio/sdiocard.h>
|
|
18 |
#include <drivers/sdio/regifc.h>
|
|
19 |
#include <drivers/sdio/function.h>
|
|
20 |
#include <drivers/sdio/cisreader.h>
|
|
21 |
#include "utraceepbussdio.h"
|
|
22 |
|
|
23 |
// ======== TSDIOCardConfig ========
|
|
24 |
|
|
25 |
EXPORT_C TSDIOCardConfig::TSDIOCardConfig()
|
|
26 |
/**
|
|
27 |
@publishedPartner
|
|
28 |
@released
|
|
29 |
|
|
30 |
Constructs a TSDIOCardConfig object
|
|
31 |
*/
|
|
32 |
{
|
|
33 |
TRACE1(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIODSDIOCardConfigConstructor, reinterpret_cast<TUint32>(this)); // @SymTraceDataPublishedTvk
|
|
34 |
Reset();
|
|
35 |
TRACE1(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIODSDIOCardConfigConstructorReturning, reinterpret_cast<TUint32>(this)); // @SymTraceDataPublishedTvk
|
|
36 |
}
|
|
37 |
|
|
38 |
// ======== TSDIOCard ========
|
|
39 |
|
|
40 |
TSDIOCard::TSDIOCard()
|
|
41 |
/**
|
|
42 |
Constructs a TSDIOCard object
|
|
43 |
*/
|
|
44 |
: iFunctionCount(0),
|
|
45 |
iCommonRegIfcP(NULL),
|
|
46 |
iMutexLock(NULL),
|
|
47 |
iInterruptController(),
|
|
48 |
iCardState(ECardNotReady),
|
|
49 |
iCisState(ECisNotReady),
|
|
50 |
iClientCount(0),
|
|
51 |
iStackP(NULL)
|
|
52 |
{
|
|
53 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "TSDIOCard::TSDIOCard, constructing a card")); // @SymTraceDataInternalTechnology
|
|
54 |
}
|
|
55 |
|
|
56 |
TSDIOCard::~TSDIOCard()
|
|
57 |
/**
|
|
58 |
Destroys the TSDIOCard object
|
|
59 |
*/
|
|
60 |
{
|
|
61 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "TSDIOCard::TSDIOCard, destructing a card")); // @SymTraceDataInternalTechnology
|
|
62 |
}
|
|
63 |
|
|
64 |
_LIT(KLitSDIOMutexName, "SDIO_MUTEX");
|
|
65 |
TInt TSDIOCard::Create(DMMCStack* aStackP)
|
|
66 |
/**
|
|
67 |
Creates the TSDIOCard object
|
|
68 |
|
|
69 |
@param aStackP The SDIO stack associated with the card
|
|
70 |
|
|
71 |
@return Standard Symbian OS error code
|
|
72 |
*/
|
|
73 |
{
|
|
74 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "TSDIOCard::Create")); // @SymTraceDataInternalTechnology
|
|
75 |
|
|
76 |
iUsingSessionP = 0;
|
|
77 |
|
|
78 |
iStackP = aStackP;
|
|
79 |
|
|
80 |
//
|
|
81 |
// Create the access mutex
|
|
82 |
//
|
|
83 |
TInt err = KErrNone;
|
|
84 |
if((err = Kern::MutexCreate(iMutexLock, KLitSDIOMutexName, KMutexOrdNone)) != KErrNone)
|
|
85 |
{
|
|
86 |
return(err);
|
|
87 |
}
|
|
88 |
|
|
89 |
//
|
|
90 |
// Create the common register interface
|
|
91 |
//
|
|
92 |
if((iCommonRegIfcP = new DSDIORegisterInterface(this, 0, iMutexLock)) == 0)
|
|
93 |
{
|
|
94 |
iMutexLock->Close(NULL);
|
|
95 |
|
|
96 |
return(KErrNoMemory);
|
|
97 |
}
|
|
98 |
|
|
99 |
for(TUint8 i=0; i<KMaxSDIOFunctions; i++)
|
|
100 |
{
|
|
101 |
iFunctions[i] = NULL;
|
|
102 |
}
|
|
103 |
|
|
104 |
if((err = iInterruptController.Create(static_cast<DSDIOStack*>(aStackP), this)) != KErrNone)
|
|
105 |
{
|
|
106 |
return(err);
|
|
107 |
}
|
|
108 |
|
|
109 |
return(KErrNone);
|
|
110 |
}
|
|
111 |
|
|
112 |
TInt TSDIOCard::Open(TUint8 aFunctionCount)
|
|
113 |
/**
|
|
114 |
Called when the card is powered up
|
|
115 |
*/
|
|
116 |
{
|
|
117 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "TSDIOCard::Open for function %d", aFunctionCount)); // @SymTraceDataInternalTechnology
|
|
118 |
|
|
119 |
iFunctionCount = aFunctionCount;
|
|
120 |
|
|
121 |
iCardState = ECardReady;
|
|
122 |
|
|
123 |
return(KErrNone);
|
|
124 |
}
|
|
125 |
|
|
126 |
TInt TSDIOCard::Close()
|
|
127 |
/**
|
|
128 |
Called when the card is powered down or removed
|
|
129 |
*/
|
|
130 |
{
|
|
131 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "TSDIOCard::Close")); // @SymTraceDataInternalTechnology
|
|
132 |
|
|
133 |
iCardState = ECardNotReady;
|
|
134 |
iCisState = ECisNotReady;
|
|
135 |
|
|
136 |
// De-Allocate the IO functions
|
|
137 |
for(TUint fn=0; fn<KMaxSDIOFunctions; fn++)
|
|
138 |
{
|
|
139 |
if(iFunctions[fn] != NULL)
|
|
140 |
{
|
|
141 |
iFunctions[fn]->Close();
|
|
142 |
iFunctions[fn] = NULL;
|
|
143 |
}
|
|
144 |
}
|
|
145 |
|
|
146 |
iFunctionCount = 0;
|
|
147 |
iInterruptController.Stop();
|
|
148 |
|
|
149 |
iCommonConfig.Reset();
|
|
150 |
|
|
151 |
return(KErrNone);
|
|
152 |
}
|
|
153 |
|
|
154 |
|
|
155 |
TInt TSDIOCard::CreateFunction(TUint8 aFunctionNumber)
|
|
156 |
/**
|
|
157 |
Allocate the specified IO function. These are instance-counted, so
|
|
158 |
are destroyed when they have been de-registered by the client driver.
|
|
159 |
*/
|
|
160 |
{
|
|
161 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "TSDIOCard::CreateFunction for function %d", aFunctionNumber)); // @SymTraceDataInternalTechnology
|
|
162 |
|
|
163 |
if(aFunctionNumber < 1 || aFunctionNumber > KMaxSDIOFunctions)
|
|
164 |
{
|
|
165 |
return(KErrArgument);
|
|
166 |
}
|
|
167 |
|
|
168 |
if(iFunctions[aFunctionNumber-1] != NULL)
|
|
169 |
{
|
|
170 |
return(KErrAlreadyExists);
|
|
171 |
}
|
|
172 |
|
|
173 |
if((iFunctions[aFunctionNumber-1] = new TSDIOFunction(this, aFunctionNumber)) == 0)
|
|
174 |
{
|
|
175 |
return(KErrNoMemory);
|
|
176 |
}
|
|
177 |
|
|
178 |
return(KErrNone);
|
|
179 |
}
|
|
180 |
|
|
181 |
|
|
182 |
EXPORT_C TSDIOFunction* TSDIOCard::FindFunction(TSDIOFunctionCaps& aCaps, TUint32 aMatchFlags, TSDIOFunction* aFunctionP) const
|
|
183 |
/**
|
|
184 |
@publishedPartner
|
|
185 |
@released
|
|
186 |
|
|
187 |
Provides support for the validation and enumeration of the card functions.
|
|
188 |
|
|
189 |
To assist in the detection of card functions, the SDIO specification provides the capability to identify
|
|
190 |
the functions available within the card through the Function Basic Registers (FBR). This provides a simple
|
|
191 |
means of identifying the type of function, and also provides a pointer to the functions CIS and the CSA.
|
|
192 |
|
|
193 |
Upon initialisation of a device driver, the client specifies the required capabilities (i.e. - function type, revision).
|
|
194 |
If a function containing the desired capabilities exists on the card, a pointer to the function is returned.
|
|
195 |
|
|
196 |
@param aCaps TSDIOFunctionCaps class containing the desired capabilities.
|
|
197 |
@param aMatchFlags A bitmask specifying the capabilities to be matched.
|
|
198 |
@param aFunctionP A pointer to the currently matched function.
|
|
199 |
|
|
200 |
@return A pointer to the next matching function (NULL if no more functions can be found).
|
|
201 |
|
|
202 |
@see TSDIOFunctionCaps
|
|
203 |
@see TSDIOCapsMatch
|
|
204 |
*/
|
|
205 |
{
|
|
206 |
TRACE2(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOCardFindFunction, reinterpret_cast<TUint32>(this), aMatchFlags); // @SymTraceDataPublishedTvk
|
|
207 |
|
|
208 |
TSDIOFunction* nextFunctionP = NULL;
|
|
209 |
TSDIOFunctionCaps functionCaps;
|
|
210 |
|
|
211 |
if(iFunctionCount > 0)
|
|
212 |
{
|
|
213 |
TUint8 nextFunctionNo = (TUint8)(aFunctionP ? aFunctionP->FunctionNumber() + 1 : 1);
|
|
214 |
|
|
215 |
TBool found = EFalse;
|
|
216 |
while(nextFunctionNo <= KMaxSDIOFunctions && !found)
|
|
217 |
{
|
|
218 |
if((nextFunctionP = IoFunction(nextFunctionNo++)) != NULL)
|
|
219 |
{
|
|
220 |
functionCaps = nextFunctionP->Capabilities();
|
|
221 |
found = functionCaps.CapabilitiesMatch(aCaps, aMatchFlags);
|
|
222 |
}
|
|
223 |
}
|
|
224 |
}
|
|
225 |
|
|
226 |
if(nextFunctionP)
|
|
227 |
{
|
|
228 |
// If the capabilites match, then fill in the clients data.
|
|
229 |
aCaps = functionCaps;
|
|
230 |
}
|
|
231 |
|
|
232 |
TRACE2(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOCardFindFunction, reinterpret_cast<TUint32>(this), reinterpret_cast<TUint32>(nextFunctionP)); // @SymTraceDataPublishedTvk
|
|
233 |
|
|
234 |
return(nextFunctionP);
|
|
235 |
}
|
|
236 |
|
|
237 |
|
|
238 |
EXPORT_C TInt TSDIOCard::CheckCIS()
|
|
239 |
/**
|
|
240 |
Performs parsing of the Card's common CIS and the each function's CIS
|
|
241 |
NOTE: This uses the Synchronous Register Interface Class.
|
|
242 |
@TODO: Do we need an asynchronous version of the CIS Reader?
|
|
243 |
@see TSDIOCisState
|
|
244 |
@return The state of the operation (TSDIOCisState).
|
|
245 |
*/
|
|
246 |
{
|
|
247 |
TRACE1(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOCardCheckCIS, reinterpret_cast<TUint32>(this)); // @SymTraceDataPublishedTvk
|
|
248 |
|
|
249 |
TCisReader iCisRd;
|
|
250 |
|
|
251 |
TInt err = KErrNone;
|
|
252 |
if(iCisState != ECisReady)
|
|
253 |
{
|
|
254 |
const TInt socketNum = iStackP->MMCSocket()->iSocketNumber;
|
|
255 |
if((err = iCisRd.SelectCis(socketNum,0,0,0)) == KErrNone)
|
|
256 |
{
|
|
257 |
if((err = iCisRd.FindReadCommonConfig(iCommonConfig)) == KErrNone)
|
|
258 |
{
|
|
259 |
for(TUint8 fn = 1; fn <= KMaxSDIOFunctions && err == KErrNone; fn++)
|
|
260 |
{
|
|
261 |
TSDIOFunction* functionP = IoFunction(fn);
|
|
262 |
if(functionP)
|
|
263 |
{
|
|
264 |
err = functionP->ParseCIS();
|
|
265 |
}
|
|
266 |
}
|
|
267 |
}
|
|
268 |
}
|
|
269 |
|
|
270 |
iCisState = (err == KErrNone ? ECisReady : ECisCorrupt);
|
|
271 |
}
|
|
272 |
|
|
273 |
TRACE2(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOCardCheckCIS, reinterpret_cast<TUint32>(this), err); // @SymTraceDataPublishedTvk
|
|
274 |
|
|
275 |
return(err);
|
|
276 |
}
|
|
277 |
|
|
278 |
TUint TSDIOCard::MaxTranSpeedInKilohertz() const
|
|
279 |
/**
|
|
280 |
* Returns the maximum supported clock rate for the card, in Kilohertz.
|
|
281 |
* @return Speed, in Kilohertz
|
|
282 |
*/
|
|
283 |
{
|
|
284 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), ">TSDIOCard::MaxTranSpeedInKilohertz")); // @SymTraceDataInternalTechnology
|
|
285 |
|
|
286 |
TUint speed = 0;
|
|
287 |
if(IsIOCard())
|
|
288 |
{
|
|
289 |
speed = iCommonConfig.MaxTranSpeedInKilohertz();
|
|
290 |
|
|
291 |
if(IsSDCard())
|
|
292 |
{
|
|
293 |
// This implies Combo Card...
|
|
294 |
// The specification states that Combo-Cards must be High-Speed cards
|
|
295 |
// but to be safe we check the CSD anyway.
|
|
296 |
TUint speedMem = TSDCard::MaxTranSpeedInKilohertz();
|
|
297 |
if(speedMem < speed)
|
|
298 |
{
|
|
299 |
speed = speedMem;
|
|
300 |
}
|
|
301 |
}
|
|
302 |
}
|
|
303 |
else
|
|
304 |
{
|
|
305 |
// If the card is not an IO card, then it could be SD or MMC only
|
|
306 |
speed = TSDCard::MaxTranSpeedInKilohertz();
|
|
307 |
}
|
|
308 |
|
|
309 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "<TSDIOCard::MaxTranSpeedInKilohertz (Speed:%dKHz)",speed)); // @SymTraceDataInternalTechnology
|
|
310 |
|
|
311 |
return(speed);
|
|
312 |
}
|
|
313 |
|
|
314 |
// ======== TSDIOCardArray ========
|
|
315 |
|
|
316 |
EXPORT_C TInt TSDIOCardArray::AllocCards()
|
|
317 |
/**
|
|
318 |
Allocate TSDIOCard objects for iCards and iNewCardsArray. This function
|
|
319 |
is called at bootup as part of stack allocation so there is no cleanup
|
|
320 |
if it fails.
|
|
321 |
|
|
322 |
@return Standard Symbian OS error code
|
|
323 |
*/
|
|
324 |
{
|
|
325 |
TRACE1(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOCardArrayAllocCards, reinterpret_cast<TUint32>(this)); // @SymTraceDataPublishedTvk
|
|
326 |
|
|
327 |
TInt err = KErrNone;
|
|
328 |
for (TInt i = 0; i < (TInt) KMaxMMCardsPerStack; ++i)
|
|
329 |
{
|
|
330 |
// zeroing the card data used to be implicit because embedded in
|
|
331 |
// CBase-derived DMMCStack.
|
|
332 |
TSDIOCard* sdioCard;
|
|
333 |
if((sdioCard = new TSDIOCard()) == 0)
|
|
334 |
{
|
|
335 |
err = KErrNoMemory;
|
|
336 |
break;
|
|
337 |
}
|
|
338 |
|
|
339 |
err = sdioCard->Create(iOwningStack);
|
|
340 |
if(err != KErrNone)
|
|
341 |
{
|
|
342 |
break;
|
|
343 |
}
|
|
344 |
|
|
345 |
iCards[i] = sdioCard;
|
|
346 |
|
|
347 |
if((sdioCard = new TSDIOCard()) == 0)
|
|
348 |
{
|
|
349 |
err = KErrNoMemory;
|
|
350 |
break;
|
|
351 |
}
|
|
352 |
|
|
353 |
iNewCards[i] = sdioCard;
|
|
354 |
}
|
|
355 |
|
|
356 |
TRACE2(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOCardArrayAllocCards, reinterpret_cast<TUint32>(this), err); // @SymTraceDataPublishedTvk
|
|
357 |
|
|
358 |
return(err);
|
|
359 |
}
|
|
360 |
|
|
361 |
TInt TSDIOCardArray::AddSDCard(TUint aCardNumber, TRCA& anRCA)
|
|
362 |
/**
|
|
363 |
This adds an SD card to the card array (first checking that no other array element
|
|
364 |
has the same RCA value 'anRCA'.
|
|
365 |
*/
|
|
366 |
{
|
|
367 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), ">TSDIOCardArray::AddSDCard for card %d", aCardNumber)); // @SymTraceDataInternalTechnology
|
|
368 |
|
|
369 |
TSDCard* ioCard = static_cast<TSDCard*>(CardP(aCardNumber));
|
|
370 |
|
|
371 |
if (anRCA==0)
|
|
372 |
{
|
|
373 |
return(KErrGeneral);
|
|
374 |
}
|
|
375 |
|
|
376 |
Card(aCardNumber).iRCA=0;
|
|
377 |
|
|
378 |
// Now let's look if we've seen this card before
|
|
379 |
for (TUint card=0; card<iOwningStack->iMaxCardsInStack; card++)
|
|
380 |
{
|
|
381 |
if (Card(card).IsPresent() && Card(card).iRCA==anRCA)
|
|
382 |
{
|
|
383 |
return(KErrInUse);
|
|
384 |
}
|
|
385 |
}
|
|
386 |
|
|
387 |
Card(aCardNumber).iRCA=anRCA;
|
|
388 |
ioCard->iIndex=(aCardNumber+1); // Mark card as being present
|
|
389 |
|
|
390 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "<TSDIOCardArray::AddSDCard: Card %d added", aCardNumber));
|
|
391 |
|
|
392 |
return(KErrNone);
|
|
393 |
}
|
|
394 |
|
|
395 |
|
|
396 |
TInt TSDIOCardArray::AddSDIOCard(TUint aCardNumber, TRCA& anRCA, TUint8 aFunctionCount)
|
|
397 |
/**
|
|
398 |
This adds an SDIO card to the card array (first checking that no other array element
|
|
399 |
has the same RCA value 'anRCA'. This clears the CID and CSD, which shall be initialised
|
|
400 |
by the SD Memory Controller should the card contain memory.
|
|
401 |
*/
|
|
402 |
{
|
|
403 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), ">TSDIOCardArray::AddSDIOCard for card %d", aCardNumber)); // @SymTraceDataInternalTechnology
|
|
404 |
|
|
405 |
TInt err = KErrNone;
|
|
406 |
|
|
407 |
TSDIOCard* ioCard = static_cast<TSDIOCard*>(CardP(aCardNumber));
|
|
408 |
|
|
409 |
if((err = AddSDCard(aCardNumber, anRCA)) == KErrNone)
|
|
410 |
{
|
|
411 |
ioCard->Open(aFunctionCount);
|
|
412 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "Adding SD Card"));
|
|
413 |
}
|
|
414 |
|
|
415 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "<TSDIOCardArray::AddSDIOCard: Card %d added", aCardNumber));
|
|
416 |
|
|
417 |
return(err);
|
|
418 |
}
|
|
419 |
|
|
420 |
|
|
421 |
EXPORT_C void TSDIOCardArray::DeclareCardAsGone(TUint aCardNumber)
|
|
422 |
/**
|
|
423 |
Reset SDIO specific fields to initial values and then reset generic controller
|
|
424 |
*/
|
|
425 |
{
|
|
426 |
TRACE2(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOCardArrayDeclareCardAsGone, reinterpret_cast<TUint32>(this), aCardNumber); // @SymTraceDataPublishedTvk
|
|
427 |
|
|
428 |
Card(aCardNumber).SetBusWidth(0);
|
|
429 |
TMMCardArray::DeclareCardAsGone(aCardNumber);
|
|
430 |
|
|
431 |
TSDIOCard* ioCard = static_cast<TSDIOCard*>(CardP(aCardNumber));
|
|
432 |
ioCard->Close();
|
|
433 |
|
|
434 |
TRACE1(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOCardArrayDeclareCardAsGoneReturning, reinterpret_cast<TUint32>(this)); // @SymTraceDataPublishedTvk
|
|
435 |
}
|
|
436 |
|