author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 23:56:21 +0300 | |
branch | RCL_3 |
changeset 45 | 9e2d4f7f5028 |
parent 19 | 4a8fed1c0ef6 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32\drivers\pbus\pbusmedia.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include <drivers/pbusmedia.h> |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
19 |
#include "OstTraceDefinitions.h" |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
20 |
#ifdef OST_TRACE_COMPILER_IN_USE |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
14
diff
changeset
|
21 |
#include "../../include/drivers/locmedia_ost.h" |
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
22 |
#ifdef __VC32__ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
23 |
#pragma warning(disable: 4127) // disabling warning "conditional expression is constant" |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
24 |
#endif |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
25 |
#include "pbusmediaTraces.h" |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
26 |
#endif |
0 | 27 |
|
28 |
void mediaCallBack(TAny* aPtr, TInt aReason, TAny* a1, TAny* a2) |
|
29 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
30 |
OstTraceFunctionEntry0( MEDIACALLBACK_ENTRY ); |
0 | 31 |
DPBusPrimaryMedia* pM=(DPBusPrimaryMedia*)aPtr; |
32 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("mediaCallBack media %d, reason %d, a1=0x%x, a2=0x%x",pM->iMediaId,aReason,a1,a2)); |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
33 |
OstTraceExt4( TRACE_INTERNALS, MEDIACALLBACK, "aPtr=0x%x; aReason=%d; a1=0x%x; a2=0x%x", ( TUint )( aPtr ), aReason, ( TUint )( a1 ), ( TUint )( a2 ) ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
34 |
|
0 | 35 |
switch (aReason) |
36 |
{ |
|
37 |
case TPBusCallBack::EPBusStateChange: |
|
38 |
pM->PBusStateChange((TInt)a1,(TInt)a2); |
|
39 |
break; |
|
40 |
} |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
41 |
OstTraceFunctionExit0( MEDIACALLBACK_EXIT ); |
0 | 42 |
} |
43 |
||
44 |
/** |
|
45 |
Constructor for DPBusPrimaryMedia. Initializes the iSocket with aSocket. |
|
46 |
@param aSocket Pointer to DPBusSocket object |
|
47 |
@see DPBusPrimaryMedia::iSocket |
|
48 |
*/ |
|
49 |
||
50 |
DPBusPrimaryMedia::DPBusPrimaryMedia(DPBusSocket* aSocket) |
|
51 |
: iSocket(aSocket) |
|
52 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
53 |
OstTraceFunctionEntryExt( DPBUSPRIMARYMEDIA_DPBUSPRIMARYMEDIA_ENTRY, this ); |
0 | 54 |
} |
55 |
/** |
|
56 |
This function install a media call back for a removable media device. |
|
57 |
@param aDevice Local media ID. |
|
58 |
@param aMediaId Media Id (unique for a media subsystem) |
|
59 |
@param aLastMediaId This indicates number of used media ids+ number of DMedia objects to be associated with the media driver |
|
60 |
@return KErrNone if successful, |
|
61 |
otherwise one of the other system wide error codes. |
|
62 |
@see DPrimaryMediaBase::Create() |
|
63 |
*/ |
|
64 |
TInt DPBusPrimaryMedia::Create(TMediaDevice aDevice, TInt aMediaId, TInt aLastMediaId) |
|
65 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
66 |
OstTraceExt4(TRACE_FLOW, DPBUSPRIMARYMEDIA_CREATE_ENTRY ,"DPBusPrimaryMedia::Create;aDevice=%d;aMediaId=%d;aLastMediaId=%d;this=%x", (TInt) aDevice, aMediaId, aLastMediaId, (TUint) this); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
67 |
|
0 | 68 |
// Permanently install a media call back if for a removable media device |
69 |
TInt r=KErrArgument; |
|
70 |
iPBusState=EPBusCardAbsent; |
|
71 |
if (__IS_REMOVABLE(aDevice)) |
|
72 |
{ |
|
73 |
iBusCallBack.iFunction=mediaCallBack; |
|
74 |
iBusCallBack.iPtr=this; |
|
75 |
iBusCallBack.SetSocket(iSocket->iSocketNumber); |
|
76 |
iDfcQ=&iSocket->iDfcQ; |
|
77 |
r=DPrimaryMediaBase::Create(aDevice,aMediaId,aLastMediaId); |
|
78 |
if (r==KErrNone) |
|
79 |
{ |
|
80 |
iBusCallBack.Add(); |
|
81 |
iPBusState=iSocket->State(); |
|
82 |
iMsgQ.Receive(); |
|
83 |
} |
|
84 |
} |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
OstTraceFunctionExitExt( DPBUSPRIMARYMEDIA_CREATE_EXIT, this, r ); |
0 | 86 |
return r; |
87 |
} |
|
88 |
||
89 |
/** |
|
90 |
Checks the PBUS state. |
|
91 |
@return KErrNone if successful, |
|
92 |
KErrNotReady if card is absent. |
|
93 |
@see TPBusState |
|
94 |
*/ |
|
95 |
TInt DPBusPrimaryMedia::QuickCheckStatus() |
|
96 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
OstTraceFunctionEntry1( DPBUSPRIMARYMEDIA_QUICKCHECKSTATUS_ENTRY, this ); |
0 | 98 |
TInt r=KErrNone; |
99 |
if (iSocket && iSocket->State()==EPBusCardAbsent) |
|
100 |
r=KErrNotReady; |
|
101 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPBusPrimaryMedia::QuickCheckStatus media %d returns %d",iMediaId,r)); |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
102 |
OstTraceExt2(TRACE_INTERNALS, DPBUSPRIMARYMEDIA_QUICKCHECKSTATUS, "iMediaId=%d; retval=%d",iMediaId,r); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
103 |
OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_QUICKCHECKSTATUS_EXIT, this ); |
0 | 104 |
return r; |
105 |
} |
|
106 |
||
107 |
/** |
|
108 |
This function is called by the local media device driver to force a remount of the media device. |
|
109 |
@param aFlags Corresponds to force media change. |
|
110 |
@return KErrNone if successful, |
|
111 |
otherwise one of the other system wide error codes. |
|
112 |
@see TForceMediaChangeFlags |
|
113 |
*/ |
|
114 |
TInt DPBusPrimaryMedia::ForceMediaChange(TInt aFlags) |
|
115 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
116 |
OstTraceFunctionEntryExt( DPBUSPRIMARYMEDIA_FORCEMEDIACHANGE_ENTRY, this ); |
0 | 117 |
if ((aFlags != KMediaRemountForceMediaChange) || (iPBusState == EPBusCardAbsent)) |
118 |
{ |
|
119 |
TInt pbusState = iPBusState; |
|
120 |
||
121 |
// This should ensure NotifyMediaChange() is called for ALL primary media attached to this socket |
|
122 |
iSocket->ChangeState(EPBusCardAbsent, KErrNotReady); |
|
123 |
||
124 |
// If a request was cancelled it's possible that the socket controller has been left in an |
|
125 |
// unusable state which might cause the next request to fail, so power down the socket to be safe |
|
126 |
iSocket->ResetSocket(EFalse); |
|
127 |
||
128 |
iSocket->ChangeState(pbusState == EPBusCardAbsent ? EPBusCardAbsent : EPBusOff, KErrNotReady); |
|
129 |
||
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
OstTraceFunctionExitExt( DPBUSPRIMARYMEDIA_FORCEMEDIACHANGE_EXIT1, this, KErrCompletion ); |
0 | 131 |
return KErrCompletion; |
132 |
} |
|
133 |
||
134 |
iSocket->ForceMediaChange(); |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
OstTraceFunctionExitExt( DPBUSPRIMARYMEDIA_FORCEMEDIACHANGE_EXIT2, this, KErrNone ); |
0 | 136 |
return KErrNone; |
137 |
} |
|
138 |
||
139 |
/** |
|
140 |
Called by clients to power up the PBUS. |
|
141 |
@return KErrNone if successful, |
|
142 |
otherwise one of the other system wide error codes. |
|
143 |
@see DPBusSocket::PowerUp() |
|
144 |
*/ |
|
145 |
TInt DPBusPrimaryMedia::InitiatePowerUp() |
|
146 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
OstTraceFunctionEntry1( DPBUSPRIMARYMEDIA_INITIATEPOWERUP_ENTRY, this ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
TInt r = iSocket->PowerUp(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
OstTraceFunctionExitExt( DPBUSPRIMARYMEDIA_INITIATEPOWERUP_EXIT, this, r ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
return r; |
0 | 151 |
} |
152 |
||
153 |
/** |
|
154 |
Flags the media driver as entering a critical part of its processing. |
|
155 |
@return KErrNone if successful, |
|
156 |
otherwise one of the other system wide error codes. |
|
157 |
@see DPBusSocket::InCritical() |
|
158 |
*/ |
|
159 |
TInt DPBusPrimaryMedia::DoInCritical() |
|
160 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
161 |
OstTraceFunctionEntry1( DPBUSPRIMARYMEDIA_DOINCRITICAL_ENTRY, this ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
TInt r = iSocket->InCritical(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
OstTraceFunctionExitExt( DPBUSPRIMARYMEDIA_DOINCRITICAL_EXIT, this, r ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
return r; |
0 | 165 |
} |
166 |
||
167 |
/** |
|
168 |
Flags the media driver as leaving a critical part of its processing. |
|
169 |
@return KErrNone if successful, |
|
170 |
otherwise one of the other system wide error codes. |
|
171 |
@see DPBusSocket::EndInCritical() |
|
172 |
*/ |
|
173 |
void DPBusPrimaryMedia::DoEndInCritical() |
|
174 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
175 |
OstTraceFunctionEntry1( DPBUSPRIMARYMEDIA_DOENDINCRITICAL_ENTRY, this ); |
0 | 176 |
iSocket->EndInCritical(); |
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_DOENDINCRITICAL_EXIT, this ); |
0 | 178 |
} |
179 |
||
180 |
/** |
|
181 |
Sets the incremental value of current consumption to aCurrent. |
|
182 |
@param aCurrent Delta Current in Milliamps. |
|
183 |
@see DPBusSocket::DeltaCurrentConsumption() |
|
184 |
*/ |
|
185 |
void DPBusPrimaryMedia::DeltaCurrentConsumption(TInt aCurrent) |
|
186 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
187 |
OstTraceFunctionEntryExt( DPBUSPRIMARYMEDIA_DELTACURRENTCONSUMPTION_ENTRY, this ); |
0 | 188 |
iSocket->DeltaCurrentConsumption(aCurrent); |
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_DELTACURRENTCONSUMPTION_EXIT, this ); |
0 | 190 |
} |
191 |
||
192 |
/** |
|
193 |
Gets the default drive capability/attributes. |
|
194 |
@param aCaps A reference to a client-supplied TLocalDriveCapsV2 class to be filled by this function. |
|
195 |
@see TLocalDriveCapsV2 |
|
196 |
@see TMediaType |
|
197 |
*/ |
|
198 |
void DPBusPrimaryMedia::DefaultDriveCaps(TLocalDriveCapsV2& aCaps) |
|
199 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
200 |
OstTraceFunctionEntry1( DPBUSPRIMARYMEDIA_DEFAULTDRIVECAPS_ENTRY, this ); |
0 | 201 |
// aCaps is zeroed beforehand |
202 |
aCaps.iType = EMediaNotPresent; |
|
203 |
aCaps.iDriveAtt = KDriveAttLocal|KDriveAttRemovable; |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
204 |
OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_DEFAULTDRIVECAPS_EXIT, this ); |
0 | 205 |
} |
206 |
||
207 |
/** |
|
208 |
Checks whether it is a removable media device or not. |
|
209 |
@param aSocketNum This will be updated with socket number |
|
210 |
@return ETrue if Removable Device, EFalse if the device is Non-Removable. |
|
211 |
*/ |
|
212 |
TBool DPBusPrimaryMedia::IsRemovableDevice(TInt& aSocketNum) |
|
213 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
214 |
OstTraceFunctionEntryExt( DPBUSPRIMARYMEDIA_ISREMOVABLEDEVICE_ENTRY, this ); |
0 | 215 |
aSocketNum=iSocket->iSocketNumber; |
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
216 |
OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_ISREMOVABLEDEVICE_EXIT, this ); |
0 | 217 |
return(ETrue); |
218 |
} |
|
219 |
||
220 |
void DPBusPrimaryMedia::PBusStateChange(TInt aState, TInt anError) |
|
221 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
222 |
OstTraceFunctionEntryExt( DPBUSPRIMARYMEDIA_PBUSSTATECHANGE_ENTRY, this ); |
0 | 223 |
// receive power down and media change notifications |
224 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPBusPrimaryMedia(%d)::PBusStateChange state %d, err %d",iMediaId,aState,anError)); |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
225 |
OstTraceExt3(TRACE_INTERNALS, DPBUSPRIMARYMEDIA_PBUSSTATECHANGE, "iMediaId=%d; aState=%d; anError=%d", iMediaId,aState,anError); |
0 | 226 |
if (aState!=iPBusState) |
227 |
{ |
|
228 |
TInt oldState = iPBusState; |
|
229 |
iPBusState=aState; |
|
230 |
switch (aState) |
|
231 |
{ |
|
232 |
case EPBusCardAbsent: |
|
233 |
NotifyMediaChange(); |
|
234 |
break; |
|
235 |
case EPBusOff: |
|
236 |
switch (anError) |
|
237 |
{ |
|
238 |
case KErrNone: |
|
239 |
// machine power down |
|
240 |
NotifyPowerDown(); |
|
241 |
break; |
|
242 |
case KErrTimedOut: |
|
243 |
// machine power down |
|
244 |
NotifyPowerDown(); |
|
245 |
if(oldState == EPBusCardAbsent) |
|
246 |
{ |
|
247 |
// powering down after power up with no card present. |
|
248 |
// ...to prevent the bus powering up again, maintain |
|
249 |
// the card state as absent. A media change will |
|
250 |
// update the status to allow the bus to power up. |
|
251 |
iPBusState = EPBusCardAbsent; |
|
252 |
} |
|
253 |
break; |
|
254 |
case KErrNotReady: |
|
255 |
// card detected following door close |
|
256 |
NotifyMediaPresent(); |
|
257 |
break; |
|
258 |
case KErrAbort: |
|
259 |
NotifyEmergencyPowerDown(); |
|
260 |
break; |
|
261 |
default: |
|
262 |
if (iState==EPoweringUp1 || iState==EPoweringUp2) |
|
263 |
PowerUpComplete(anError); |
|
264 |
break; |
|
265 |
} |
|
266 |
case EPBusPoweringUp: |
|
267 |
// no action required |
|
268 |
break; |
|
269 |
case EPBusOn: |
|
270 |
// bus is now powered up |
|
271 |
if (iState==EPoweringUp1 || iState==EPoweringUp2) |
|
272 |
PowerUpComplete(anError); |
|
273 |
break; |
|
274 |
case EPBusPsuFault: |
|
275 |
NotifyPsuFault(anError); |
|
276 |
break; |
|
277 |
case EPBusPowerUpPending: |
|
278 |
// no action required |
|
279 |
break; |
|
280 |
default: |
|
281 |
break; |
|
282 |
} |
|
283 |
} |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_PBUSSTATECHANGE_EXIT, this ); |
0 | 285 |
} |
286 |