Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\drivers\pbus\pbusmedia.cpp
18 #include <drivers/pbusmedia.h>
19 #include "OstTraceDefinitions.h"
20 #ifdef OST_TRACE_COMPILER_IN_USE
21 #include "locmedia_ost.h"
23 #pragma warning(disable: 4127) // disabling warning "conditional expression is constant"
25 #include "pbusmediaTraces.h"
28 void mediaCallBack(TAny* aPtr, TInt aReason, TAny* a1, TAny* a2)
30 OstTraceFunctionEntry0( MEDIACALLBACK_ENTRY );
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));
33 OstTraceExt4( TRACE_INTERNALS, MEDIACALLBACK, "aPtr=0x%x; aReason=%d; a1=0x%x; a2=0x%x", ( TUint )( aPtr ), aReason, ( TUint )( a1 ), ( TUint )( a2 ) );
37 case TPBusCallBack::EPBusStateChange:
38 pM->PBusStateChange((TInt)a1,(TInt)a2);
41 OstTraceFunctionExit0( MEDIACALLBACK_EXIT );
45 Constructor for DPBusPrimaryMedia. Initializes the iSocket with aSocket.
46 @param aSocket Pointer to DPBusSocket object
47 @see DPBusPrimaryMedia::iSocket
50 DPBusPrimaryMedia::DPBusPrimaryMedia(DPBusSocket* aSocket)
53 OstTraceFunctionEntryExt( DPBUSPRIMARYMEDIA_DPBUSPRIMARYMEDIA_ENTRY, this );
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()
64 TInt DPBusPrimaryMedia::Create(TMediaDevice aDevice, TInt aMediaId, TInt aLastMediaId)
66 OstTraceExt4(TRACE_FLOW, DPBUSPRIMARYMEDIA_CREATE_ENTRY ,"DPBusPrimaryMedia::Create;aDevice=%d;aMediaId=%d;aLastMediaId=%d;this=%x", (TInt) aDevice, aMediaId, aLastMediaId, (TUint) this);
68 // Permanently install a media call back if for a removable media device
70 iPBusState=EPBusCardAbsent;
71 if (__IS_REMOVABLE(aDevice))
73 iBusCallBack.iFunction=mediaCallBack;
74 iBusCallBack.iPtr=this;
75 iBusCallBack.SetSocket(iSocket->iSocketNumber);
76 iDfcQ=&iSocket->iDfcQ;
77 r=DPrimaryMediaBase::Create(aDevice,aMediaId,aLastMediaId);
81 iPBusState=iSocket->State();
85 OstTraceFunctionExitExt( DPBUSPRIMARYMEDIA_CREATE_EXIT, this, r );
90 Checks the PBUS state.
91 @return KErrNone if successful,
92 KErrNotReady if card is absent.
95 TInt DPBusPrimaryMedia::QuickCheckStatus()
97 OstTraceFunctionEntry1( DPBUSPRIMARYMEDIA_QUICKCHECKSTATUS_ENTRY, this );
99 if (iSocket && iSocket->State()==EPBusCardAbsent)
101 __KTRACE_OPT(KLOCDRV,Kern::Printf("DPBusPrimaryMedia::QuickCheckStatus media %d returns %d",iMediaId,r));
102 OstTraceExt2(TRACE_INTERNALS, DPBUSPRIMARYMEDIA_QUICKCHECKSTATUS, "iMediaId=%d; retval=%d",iMediaId,r);
103 OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_QUICKCHECKSTATUS_EXIT, this );
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
114 TInt DPBusPrimaryMedia::ForceMediaChange(TInt aFlags)
116 OstTraceFunctionEntryExt( DPBUSPRIMARYMEDIA_FORCEMEDIACHANGE_ENTRY, this );
117 if ((aFlags != KMediaRemountForceMediaChange) || (iPBusState == EPBusCardAbsent))
119 TInt pbusState = iPBusState;
121 // This should ensure NotifyMediaChange() is called for ALL primary media attached to this socket
122 iSocket->ChangeState(EPBusCardAbsent, KErrNotReady);
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);
128 iSocket->ChangeState(pbusState == EPBusCardAbsent ? EPBusCardAbsent : EPBusOff, KErrNotReady);
130 OstTraceFunctionExitExt( DPBUSPRIMARYMEDIA_FORCEMEDIACHANGE_EXIT1, this, KErrCompletion );
131 return KErrCompletion;
134 iSocket->ForceMediaChange();
135 OstTraceFunctionExitExt( DPBUSPRIMARYMEDIA_FORCEMEDIACHANGE_EXIT2, this, KErrNone );
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()
145 TInt DPBusPrimaryMedia::InitiatePowerUp()
147 OstTraceFunctionEntry1( DPBUSPRIMARYMEDIA_INITIATEPOWERUP_ENTRY, this );
148 TInt r = iSocket->PowerUp();
149 OstTraceFunctionExitExt( DPBUSPRIMARYMEDIA_INITIATEPOWERUP_EXIT, this, r );
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()
159 TInt DPBusPrimaryMedia::DoInCritical()
161 OstTraceFunctionEntry1( DPBUSPRIMARYMEDIA_DOINCRITICAL_ENTRY, this );
162 TInt r = iSocket->InCritical();
163 OstTraceFunctionExitExt( DPBUSPRIMARYMEDIA_DOINCRITICAL_EXIT, this, r );
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()
173 void DPBusPrimaryMedia::DoEndInCritical()
175 OstTraceFunctionEntry1( DPBUSPRIMARYMEDIA_DOENDINCRITICAL_ENTRY, this );
176 iSocket->EndInCritical();
177 OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_DOENDINCRITICAL_EXIT, this );
181 Sets the incremental value of current consumption to aCurrent.
182 @param aCurrent Delta Current in Milliamps.
183 @see DPBusSocket::DeltaCurrentConsumption()
185 void DPBusPrimaryMedia::DeltaCurrentConsumption(TInt aCurrent)
187 OstTraceFunctionEntryExt( DPBUSPRIMARYMEDIA_DELTACURRENTCONSUMPTION_ENTRY, this );
188 iSocket->DeltaCurrentConsumption(aCurrent);
189 OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_DELTACURRENTCONSUMPTION_EXIT, this );
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
198 void DPBusPrimaryMedia::DefaultDriveCaps(TLocalDriveCapsV2& aCaps)
200 OstTraceFunctionEntry1( DPBUSPRIMARYMEDIA_DEFAULTDRIVECAPS_ENTRY, this );
201 // aCaps is zeroed beforehand
202 aCaps.iType = EMediaNotPresent;
203 aCaps.iDriveAtt = KDriveAttLocal|KDriveAttRemovable;
204 OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_DEFAULTDRIVECAPS_EXIT, this );
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.
212 TBool DPBusPrimaryMedia::IsRemovableDevice(TInt& aSocketNum)
214 OstTraceFunctionEntryExt( DPBUSPRIMARYMEDIA_ISREMOVABLEDEVICE_ENTRY, this );
215 aSocketNum=iSocket->iSocketNumber;
216 OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_ISREMOVABLEDEVICE_EXIT, this );
220 void DPBusPrimaryMedia::PBusStateChange(TInt aState, TInt anError)
222 OstTraceFunctionEntryExt( DPBUSPRIMARYMEDIA_PBUSSTATECHANGE_ENTRY, this );
223 // receive power down and media change notifications
224 __KTRACE_OPT(KLOCDRV,Kern::Printf("DPBusPrimaryMedia(%d)::PBusStateChange state %d, err %d",iMediaId,aState,anError));
225 OstTraceExt3(TRACE_INTERNALS, DPBUSPRIMARYMEDIA_PBUSSTATECHANGE, "iMediaId=%d; aState=%d; anError=%d", iMediaId,aState,anError);
226 if (aState!=iPBusState)
228 TInt oldState = iPBusState;
232 case EPBusCardAbsent:
239 // machine power down
243 // machine power down
245 if(oldState == EPBusCardAbsent)
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;
255 // card detected following door close
256 NotifyMediaPresent();
259 NotifyEmergencyPowerDown();
262 if (iState==EPoweringUp1 || iState==EPoweringUp2)
263 PowerUpComplete(anError);
266 case EPBusPoweringUp:
267 // no action required
270 // bus is now powered up
271 if (iState==EPoweringUp1 || iState==EPoweringUp2)
272 PowerUpComplete(anError);
275 NotifyPsuFault(anError);
277 case EPBusPowerUpPending:
278 // no action required
284 OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_PBUSSTATECHANGE_EXIT, this );