0
|
1 |
/*
|
|
2 |
* Copyright (c) 2003-2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <kernel/kernel.h>
|
|
20 |
|
|
21 |
#include <drivers/sdio/sdiocard.h>
|
|
22 |
#include <drivers/sdio/interrupt.h>
|
|
23 |
#include <drivers/sdio/regifc.h>
|
|
24 |
#include <drivers/sdio/function.h>
|
|
25 |
#include <drivers/sdio/callback.h>
|
|
26 |
#include "utraceepbussdio.h"
|
|
27 |
|
|
28 |
|
|
29 |
TSDIOInterruptController::TSDIOInterruptController() :
|
|
30 |
/**
|
|
31 |
Contructs the TSDIOInterruptController
|
|
32 |
*/
|
|
33 |
iCardP(NULL),
|
|
34 |
iInterruptSessionP(NULL),
|
|
35 |
iSessionEndCallBack(TSDIOInterruptController::SessionEndCallBack, this),
|
|
36 |
iPending(0)
|
|
37 |
{
|
|
38 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "TSDIOInterruptController::TSDIOInterruptController, construct")); // @SymTraceDataInternalTechnology
|
|
39 |
}
|
|
40 |
|
|
41 |
TSDIOInterruptController::~TSDIOInterruptController()
|
|
42 |
/**
|
|
43 |
Destroys the TSDIOInterruptControllerinstance.
|
|
44 |
*/
|
|
45 |
{
|
|
46 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "TSDIOInterruptController::~TSDIOInterruptController, destruct")); // @SymTraceDataInternalTechnology
|
|
47 |
}
|
|
48 |
|
|
49 |
TInt TSDIOInterruptController::Create(DSDIOStack* aStackP, TSDIOCard* aCardP)
|
|
50 |
/**
|
|
51 |
Contructs the TSDIOInterruptController
|
|
52 |
*/
|
|
53 |
{
|
|
54 |
__ASSERT_ALWAYS((aStackP != NULL) && (aCardP != NULL), Panic(EBadParameter));
|
|
55 |
|
|
56 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "TSDIOInterruptController::Create")); // @SymTraceDataInternalTechnology
|
|
57 |
|
|
58 |
TInt err = KErrNone;
|
|
59 |
|
|
60 |
iCardP = aCardP;
|
|
61 |
|
|
62 |
if(!iInterruptSessionP)
|
|
63 |
{
|
|
64 |
iInterruptSessionP = static_cast<DSDIOSession*>(aStackP->AllocSession(iSessionEndCallBack));
|
|
65 |
if (iInterruptSessionP)
|
|
66 |
{
|
|
67 |
iInterruptSessionP->SetStack(aStackP);
|
|
68 |
iInterruptSessionP->SetCard((TMMCard*)aCardP);
|
|
69 |
}
|
|
70 |
else
|
|
71 |
{
|
|
72 |
err = KErrNoMemory;
|
|
73 |
}
|
|
74 |
}
|
|
75 |
|
|
76 |
return(err);
|
|
77 |
}
|
|
78 |
|
|
79 |
|
|
80 |
TInt TSDIOInterruptController::EnableInterrupt(TUint8 aFunctionNumber)
|
|
81 |
/**
|
|
82 |
Enables an SDIO interrupt
|
|
83 |
*/
|
|
84 |
{
|
|
85 |
__ASSERT_DEBUG(aFunctionNumber > 0 && aFunctionNumber <= KMaxSDIOFunctions,
|
|
86 |
TSDIOInterruptController::Panic(TSDIOInterruptController::EParameterOutOfRange));
|
|
87 |
|
|
88 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "TSDIOInterruptController::EnableInterrupt for function %d", aFunctionNumber)); // @SymTraceDataInternalTechnology
|
|
89 |
|
|
90 |
TInt err = KErrNone;
|
|
91 |
|
|
92 |
if((err = Start()) == KErrNone)
|
|
93 |
{
|
|
94 |
DSDIORegisterInterface* pRegIfc = iCardP->CommonRegisterInterface();
|
|
95 |
err = pRegIfc->Modify8(KSDIOCCCRIntEnable, (TUint8)(0x01 << aFunctionNumber), 0);
|
|
96 |
}
|
|
97 |
|
|
98 |
return(err);
|
|
99 |
}
|
|
100 |
|
|
101 |
|
|
102 |
TInt TSDIOInterruptController::DisableInterrupt(TUint8 aFunctionNumber)
|
|
103 |
/**
|
|
104 |
Enables an SDIO interrupt. If no interrupts remain enabled, this DOES NOT
|
|
105 |
abort the Interrupt Handler session. This shall be aborted when the stack times out.
|
|
106 |
*/
|
|
107 |
{
|
|
108 |
__ASSERT_DEBUG(aFunctionNumber > 0 && aFunctionNumber <= KMaxSDIOFunctions,
|
|
109 |
TSDIOInterruptController::Panic(TSDIOInterruptController::EParameterOutOfRange));
|
|
110 |
|
|
111 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "TSDIOInterruptController::DisableInterrupt for function %d", aFunctionNumber)); // @SymTraceDataInternalTechnology
|
|
112 |
|
|
113 |
TInt err = KErrNone;
|
|
114 |
|
|
115 |
DSDIORegisterInterface* pRegIfc = iCardP->CommonRegisterInterface();
|
|
116 |
err = pRegIfc->Modify8(KSDIOCCCRIntEnable, 0x00, (TUint8)(0x01 << aFunctionNumber));
|
|
117 |
|
|
118 |
return(err);
|
|
119 |
}
|
|
120 |
|
|
121 |
|
|
122 |
TInt TSDIOInterruptController::Start()
|
|
123 |
/**
|
|
124 |
Starts the interrupt handler session. (This is a long-running
|
|
125 |
session that blocks until the interrupt occurs to improve latency)
|
|
126 |
*/
|
|
127 |
{
|
|
128 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "TSDIOInterruptController::Start")); // @SymTraceDataInternalTechnology
|
|
129 |
|
|
130 |
TInt err = KErrNone;
|
|
131 |
if(!iInterruptSessionP->IsEngaged())
|
|
132 |
{
|
|
133 |
iInterruptSessionP->SetupCIMIoInterruptHandler(&iPending);
|
|
134 |
err = iInterruptSessionP->Engage();
|
|
135 |
}
|
|
136 |
|
|
137 |
return(err);
|
|
138 |
}
|
|
139 |
|
|
140 |
TInt TSDIOInterruptController::Stop()
|
|
141 |
/**
|
|
142 |
Stops the TSDIOInterruptController (aborts the session if engaged)
|
|
143 |
and clears the Master Interrupt Enable bit in the CCCR
|
|
144 |
|
|
145 |
This should not block
|
|
146 |
|
|
147 |
@todo Clearing IENM should happen in the session end callback (after abort)
|
|
148 |
*/
|
|
149 |
{
|
|
150 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "TSDIOInterruptController::Stop")); // @SymTraceDataInternalTechnology
|
|
151 |
|
|
152 |
if(iInterruptSessionP->IsEngaged())
|
|
153 |
{
|
|
154 |
iInterruptSessionP->Abort();
|
|
155 |
}
|
|
156 |
|
|
157 |
return(KErrNone);
|
|
158 |
}
|
|
159 |
|
|
160 |
TInt TSDIOInterruptController::Schedule()
|
|
161 |
/**
|
|
162 |
Service the SDIO interrupt. Called from ISR context.
|
|
163 |
*/
|
|
164 |
{
|
|
165 |
TInt err = KErrNone;
|
|
166 |
|
|
167 |
if(iInterruptSessionP->IsEngaged())
|
|
168 |
{
|
|
169 |
iInterruptSessionP->UnblockInterrupt(KMMCErrNone);
|
|
170 |
}
|
|
171 |
else
|
|
172 |
{
|
|
173 |
err = KErrNotReady;
|
|
174 |
}
|
|
175 |
|
|
176 |
return(err);
|
|
177 |
}
|
|
178 |
|
|
179 |
void TSDIOInterruptController::Service()
|
|
180 |
/**
|
|
181 |
Called by then ISR state machine when a pending interrupt is detected
|
|
182 |
*/
|
|
183 |
{
|
|
184 |
TInt shiftVal = iPending;
|
|
185 |
TUint8 functionNo = 1;
|
|
186 |
while(shiftVal)
|
|
187 |
{
|
|
188 |
shiftVal >>= 1;
|
|
189 |
if(shiftVal & 0x01)
|
|
190 |
{
|
|
191 |
TSDIOFunction* functionP = iCardP->IoFunction(functionNo);
|
|
192 |
if(functionP)
|
|
193 |
{
|
|
194 |
functionP->Interrupt().Service();
|
|
195 |
}
|
|
196 |
}
|
|
197 |
functionNo++;
|
|
198 |
}
|
|
199 |
}
|
|
200 |
|
|
201 |
#ifndef __DISABLE_SDIO_DEBUG
|
|
202 |
void TSDIOInterruptController::SessionEndCallBack(TAny* aSelfP)
|
|
203 |
#else
|
|
204 |
void TSDIOInterruptController::SessionEndCallBack(TAny* /*aSelfP*/)
|
|
205 |
#endif
|
|
206 |
/**
|
|
207 |
Called when the interrupt controller session terminates with an
|
|
208 |
error or is stopped (not aborted, which is the usual exit case).
|
|
209 |
@param aSelfP 'this' pointer.
|
|
210 |
*/
|
|
211 |
{
|
|
212 |
// The interrupt session has completed (in response to either a stop request,
|
|
213 |
// or some other problem. In any case, disable interrupts completely
|
|
214 |
#if defined(SYMBIAN_TRACE_SDIO_VERBOSE)
|
|
215 |
TSDIOInterruptController& self = *static_cast<TSDIOInterruptController*>(aSelfP);
|
|
216 |
Printf(TTraceContext(EInternals), "ISR::Abort(%d)", self.iInterruptSessionP->EpocErrorCode()); // @SymTraceDataInternalTechnology
|
|
217 |
#endif
|
|
218 |
}
|
|
219 |
|
|
220 |
|
|
221 |
void TSDIOInterruptController::Panic(TSDIOInterruptController::TPanic aPanic)
|
|
222 |
/**
|
|
223 |
Panic the interrupt controller
|
|
224 |
*/
|
|
225 |
{
|
|
226 |
Kern::Fault("SDIO_IC", aPanic);
|
|
227 |
}
|
|
228 |
|
|
229 |
EXPORT_C TSDIOInterrupt::TSDIOInterrupt(TSDIOInterruptController* aControllerP, TUint8 aFunctionNumber)
|
|
230 |
/**
|
|
231 |
Contructs a TSDIOInterrupt for the specified function.
|
|
232 |
|
|
233 |
@param aFunctionP A pointer to the associated TSDIOFunction class.
|
|
234 |
*/
|
|
235 |
: iControllerP(aControllerP),
|
|
236 |
iFunctionNumber(aFunctionNumber),
|
|
237 |
iPtr(this)
|
|
238 |
{
|
|
239 |
TRACE2(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOInterruptConstructor, reinterpret_cast<TUint32>(this), aFunctionNumber); // @SymTraceDataPublishedTvk
|
|
240 |
|
|
241 |
iIsr = TSDIOInterrupt::UnhookedIsr;
|
|
242 |
|
|
243 |
TRACE1(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOInterruptConstructorReturning, reinterpret_cast<TUint32>(this)); // @SymTraceDataPublishedTvk
|
|
244 |
}
|
|
245 |
|
|
246 |
EXPORT_C TSDIOInterrupt::~TSDIOInterrupt()
|
|
247 |
/**
|
|
248 |
Destroys the TSDIOInterrupt instance.
|
|
249 |
*/
|
|
250 |
{
|
|
251 |
TRACE1(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOInterruptDestructor, reinterpret_cast<TUint32>(this)); // @SymTraceDataPublishedTvk
|
|
252 |
TRACE1(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOInterruptDestructorReturning, reinterpret_cast<TUint32>(this)); // @SymTraceDataPublishedTvk
|
|
253 |
}
|
|
254 |
|
|
255 |
EXPORT_C TInt TSDIOInterrupt::Bind(TSDIOIsr aIsr, TAny* aPtr)
|
|
256 |
/**
|
|
257 |
@publishedPartner
|
|
258 |
@released
|
|
259 |
|
|
260 |
Binds the TSDIOIsr callback to the functions interrupt through the Interrupt Controller.
|
|
261 |
|
|
262 |
Should the functionality of the DSDIORegInterface class be used within the ISR,
|
|
263 |
then the callback should queue a DFC within which the interrupt processing can occur.
|
|
264 |
This will ensure that the interrupt is serviced as soon as any active requests have completed.
|
|
265 |
|
|
266 |
Alternatively, if it is a requirement that the client thread does not block while servicing
|
|
267 |
the interrupt, then a seperate DSDIORegInterface (or a raw DSIOSession) may be used to handle
|
|
268 |
the interrupt asynchronously.
|
|
269 |
|
|
270 |
Once bound, interrupts should be enabled for the function by calling Enable().
|
|
271 |
It may also be necessary to enable interrupts in a function-defined manner by writing to the
|
|
272 |
appropriate register within the function.
|
|
273 |
|
|
274 |
Bind shall fail with the error KErrAlreadyExists if an ISR is already bound to the function interrupt.
|
|
275 |
|
|
276 |
@param aIsr The ISR used to handle the functions interrupt
|
|
277 |
@param aPtr User defined data for use within the ISR
|
|
278 |
|
|
279 |
@return KErrNone if successful, KErrAlreadyExists if already bound, or a standard Symbian OS error code.
|
|
280 |
|
|
281 |
@see TSDIOInterrupt::Unbind
|
|
282 |
*/
|
|
283 |
{
|
|
284 |
TRACE2(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOInterruptBind, reinterpret_cast<TUint32>(this), reinterpret_cast<TUint32>(aIsr)); // @SymTraceDataPublishedTvk
|
|
285 |
|
|
286 |
if(iIsr != TSDIOInterrupt::UnhookedIsr)
|
|
287 |
{
|
|
288 |
return(KErrAlreadyExists);
|
|
289 |
}
|
|
290 |
|
|
291 |
iIsr = aIsr;
|
|
292 |
iPtr = aPtr;
|
|
293 |
|
|
294 |
TRACE2(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOInterruptBind, reinterpret_cast<TUint32>(this), KErrNone); // @SymTraceDataPublishedTvk
|
|
295 |
return(KErrNone);
|
|
296 |
}
|
|
297 |
|
|
298 |
EXPORT_C TInt TSDIOInterrupt::Unbind()
|
|
299 |
/**
|
|
300 |
@publishedPartner
|
|
301 |
@released
|
|
302 |
|
|
303 |
Unbinds the callback from the interrupt controller, replacing the callback with a dummy handler.
|
|
304 |
|
|
305 |
@return KErrNone if successful, otherwise a standard Symbian OS error code.
|
|
306 |
|
|
307 |
@see TSDIOInterrupt::Bind
|
|
308 |
*/
|
|
309 |
{
|
|
310 |
TRACE1(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOInterruptUnbind, reinterpret_cast<TUint32>(this)); // @SymTraceDataPublishedTvk
|
|
311 |
|
|
312 |
if(iIsr == TSDIOInterrupt::UnhookedIsr)
|
|
313 |
{
|
|
314 |
return(KErrNotSupported);
|
|
315 |
}
|
|
316 |
|
|
317 |
iIsr = UnhookedIsr;
|
|
318 |
iPtr = NULL;
|
|
319 |
|
|
320 |
TRACE2(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOInterruptUnbindReturning, reinterpret_cast<TUint32>(this), KErrNone); // @SymTraceDataPublishedTvk
|
|
321 |
return(KErrNone);
|
|
322 |
}
|
|
323 |
|
|
324 |
EXPORT_C TInt TSDIOInterrupt::Enable()
|
|
325 |
/**
|
|
326 |
@publishedPartner
|
|
327 |
@released
|
|
328 |
|
|
329 |
Enables the functions interrupt by setting to the appropriate IEN bit in the CCCR.
|
|
330 |
|
|
331 |
Note that this only unmasks the global function interrupt - it is the responsibility
|
|
332 |
of the client to perform any function-specific interrupt enabling that may be required.
|
|
333 |
|
|
334 |
@return KErrNone if successful, otherwise a standard Symbian OS error code.
|
|
335 |
|
|
336 |
@see TSDIOInterrupt::Disable
|
|
337 |
*/
|
|
338 |
{
|
|
339 |
TRACE1(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOInterruptEnable, reinterpret_cast<TUint32>(this)); // @SymTraceDataPublishedTvk
|
|
340 |
TInt ret = iControllerP->EnableInterrupt(iFunctionNumber);
|
|
341 |
TRACE2(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOInterruptEnableReturning, reinterpret_cast<TUint32>(this), ret); // @SymTraceDataPublishedTvk
|
|
342 |
return(ret);
|
|
343 |
}
|
|
344 |
|
|
345 |
EXPORT_C TInt TSDIOInterrupt::Disable()
|
|
346 |
/**
|
|
347 |
@publishedPartner
|
|
348 |
@released
|
|
349 |
|
|
350 |
Disables the functions interrupt by clearing to the appropriate IEN bit in the CCCR.
|
|
351 |
|
|
352 |
Note that this only masks the global function interrupt - it is the responsibility
|
|
353 |
of the client to perform any function-specific interrupt disabling that may be required.
|
|
354 |
|
|
355 |
@return KErrNone if successful, otherwise a standard Symbian OS error code.
|
|
356 |
|
|
357 |
@see TSDIOInterrupt::Enable
|
|
358 |
*/
|
|
359 |
{
|
|
360 |
TRACE1(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOInterruptDisable, reinterpret_cast<TUint32>(this)); // @SymTraceDataPublishedTvk
|
|
361 |
TInt ret = iControllerP->DisableInterrupt(iFunctionNumber);
|
|
362 |
TRACE2(TTraceContext(EBorder), UTraceModuleEPBusSDIO::ESDIOTSDIOInterruptDisableReturning, reinterpret_cast<TUint32>(this), ret); // @SymTraceDataPublishedTvk
|
|
363 |
return(ret);
|
|
364 |
}
|
|
365 |
|
|
366 |
void TSDIOInterrupt::UnhookedIsr(TAny* /*aPtr*/)
|
|
367 |
/**
|
|
368 |
Dummy ISR for unhooked interrupts.
|
|
369 |
*/
|
|
370 |
{
|
|
371 |
SYMBIAN_TRACE_SDIO_VERBOSE_ONLY(Printf(TTraceContext(EInternals), "TSDIOInterrupt::UnhookedIsr")); // @SymTraceDataInternalTechnology
|
|
372 |
}
|
|
373 |
|
|
374 |
void TSDIOInterrupt::Service()
|
|
375 |
/**
|
|
376 |
Services the interrupt
|
|
377 |
*/
|
|
378 |
{
|
|
379 |
iIsr(iPtr);
|
|
380 |
}
|