|
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> |
|
19 |
|
20 void mediaCallBack(TAny* aPtr, TInt aReason, TAny* a1, TAny* a2) |
|
21 { |
|
22 DPBusPrimaryMedia* pM=(DPBusPrimaryMedia*)aPtr; |
|
23 __KTRACE_OPT(KLOCDRV,Kern::Printf("mediaCallBack media %d, reason %d, a1=0x%x, a2=0x%x",pM->iMediaId,aReason,a1,a2)); |
|
24 switch (aReason) |
|
25 { |
|
26 case TPBusCallBack::EPBusStateChange: |
|
27 pM->PBusStateChange((TInt)a1,(TInt)a2); |
|
28 break; |
|
29 } |
|
30 } |
|
31 |
|
32 /** |
|
33 Constructor for DPBusPrimaryMedia. Initializes the iSocket with aSocket. |
|
34 @param aSocket Pointer to DPBusSocket object |
|
35 @see DPBusPrimaryMedia::iSocket |
|
36 */ |
|
37 |
|
38 DPBusPrimaryMedia::DPBusPrimaryMedia(DPBusSocket* aSocket) |
|
39 : iSocket(aSocket) |
|
40 { |
|
41 } |
|
42 /** |
|
43 This function install a media call back for a removable media device. |
|
44 @param aDevice Local media ID. |
|
45 @param aMediaId Media Id (unique for a media subsystem) |
|
46 @param aLastMediaId This indicates number of used media ids+ number of DMedia objects to be associated with the media driver |
|
47 @return KErrNone if successful, |
|
48 otherwise one of the other system wide error codes. |
|
49 @see DPrimaryMediaBase::Create() |
|
50 */ |
|
51 TInt DPBusPrimaryMedia::Create(TMediaDevice aDevice, TInt aMediaId, TInt aLastMediaId) |
|
52 { |
|
53 // Permanently install a media call back if for a removable media device |
|
54 TInt r=KErrArgument; |
|
55 iPBusState=EPBusCardAbsent; |
|
56 if (__IS_REMOVABLE(aDevice)) |
|
57 { |
|
58 iBusCallBack.iFunction=mediaCallBack; |
|
59 iBusCallBack.iPtr=this; |
|
60 iBusCallBack.SetSocket(iSocket->iSocketNumber); |
|
61 iDfcQ=&iSocket->iDfcQ; |
|
62 r=DPrimaryMediaBase::Create(aDevice,aMediaId,aLastMediaId); |
|
63 if (r==KErrNone) |
|
64 { |
|
65 iBusCallBack.Add(); |
|
66 iPBusState=iSocket->State(); |
|
67 iMsgQ.Receive(); |
|
68 } |
|
69 } |
|
70 return r; |
|
71 } |
|
72 |
|
73 /** |
|
74 Checks the PBUS state. |
|
75 @return KErrNone if successful, |
|
76 KErrNotReady if card is absent. |
|
77 @see TPBusState |
|
78 */ |
|
79 TInt DPBusPrimaryMedia::QuickCheckStatus() |
|
80 { |
|
81 TInt r=KErrNone; |
|
82 if (iSocket && iSocket->State()==EPBusCardAbsent) |
|
83 r=KErrNotReady; |
|
84 __KTRACE_OPT(KLOCDRV,Kern::Printf("DPBusPrimaryMedia::QuickCheckStatus media %d returns %d",iMediaId,r)); |
|
85 return r; |
|
86 } |
|
87 |
|
88 /** |
|
89 This function is called by the local media device driver to force a remount of the media device. |
|
90 @param aFlags Corresponds to force media change. |
|
91 @return KErrNone if successful, |
|
92 otherwise one of the other system wide error codes. |
|
93 @see TForceMediaChangeFlags |
|
94 */ |
|
95 TInt DPBusPrimaryMedia::ForceMediaChange(TInt aFlags) |
|
96 { |
|
97 if ((aFlags != KMediaRemountForceMediaChange) || (iPBusState == EPBusCardAbsent)) |
|
98 { |
|
99 TInt pbusState = iPBusState; |
|
100 |
|
101 // This should ensure NotifyMediaChange() is called for ALL primary media attached to this socket |
|
102 iSocket->ChangeState(EPBusCardAbsent, KErrNotReady); |
|
103 |
|
104 // If a request was cancelled it's possible that the socket controller has been left in an |
|
105 // unusable state which might cause the next request to fail, so power down the socket to be safe |
|
106 iSocket->ResetSocket(EFalse); |
|
107 |
|
108 iSocket->ChangeState(pbusState == EPBusCardAbsent ? EPBusCardAbsent : EPBusOff, KErrNotReady); |
|
109 |
|
110 return KErrCompletion; |
|
111 } |
|
112 |
|
113 iSocket->ForceMediaChange(); |
|
114 return KErrNone; |
|
115 } |
|
116 |
|
117 /** |
|
118 Called by clients to power up the PBUS. |
|
119 @return KErrNone if successful, |
|
120 otherwise one of the other system wide error codes. |
|
121 @see DPBusSocket::PowerUp() |
|
122 */ |
|
123 TInt DPBusPrimaryMedia::InitiatePowerUp() |
|
124 { |
|
125 return iSocket->PowerUp(); |
|
126 } |
|
127 |
|
128 /** |
|
129 Flags the media driver as entering a critical part of its processing. |
|
130 @return KErrNone if successful, |
|
131 otherwise one of the other system wide error codes. |
|
132 @see DPBusSocket::InCritical() |
|
133 */ |
|
134 TInt DPBusPrimaryMedia::DoInCritical() |
|
135 { |
|
136 return iSocket->InCritical(); |
|
137 } |
|
138 |
|
139 /** |
|
140 Flags the media driver as leaving a critical part of its processing. |
|
141 @return KErrNone if successful, |
|
142 otherwise one of the other system wide error codes. |
|
143 @see DPBusSocket::EndInCritical() |
|
144 */ |
|
145 void DPBusPrimaryMedia::DoEndInCritical() |
|
146 { |
|
147 iSocket->EndInCritical(); |
|
148 } |
|
149 |
|
150 /** |
|
151 Sets the incremental value of current consumption to aCurrent. |
|
152 @param aCurrent Delta Current in Milliamps. |
|
153 @see DPBusSocket::DeltaCurrentConsumption() |
|
154 */ |
|
155 void DPBusPrimaryMedia::DeltaCurrentConsumption(TInt aCurrent) |
|
156 { |
|
157 iSocket->DeltaCurrentConsumption(aCurrent); |
|
158 } |
|
159 |
|
160 /** |
|
161 Gets the default drive capability/attributes. |
|
162 @param aCaps A reference to a client-supplied TLocalDriveCapsV2 class to be filled by this function. |
|
163 @see TLocalDriveCapsV2 |
|
164 @see TMediaType |
|
165 */ |
|
166 void DPBusPrimaryMedia::DefaultDriveCaps(TLocalDriveCapsV2& aCaps) |
|
167 { |
|
168 // aCaps is zeroed beforehand |
|
169 aCaps.iType = EMediaNotPresent; |
|
170 aCaps.iDriveAtt = KDriveAttLocal|KDriveAttRemovable; |
|
171 } |
|
172 |
|
173 /** |
|
174 Checks whether it is a removable media device or not. |
|
175 @param aSocketNum This will be updated with socket number |
|
176 @return ETrue if Removable Device, EFalse if the device is Non-Removable. |
|
177 */ |
|
178 TBool DPBusPrimaryMedia::IsRemovableDevice(TInt& aSocketNum) |
|
179 { |
|
180 aSocketNum=iSocket->iSocketNumber; |
|
181 return(ETrue); |
|
182 } |
|
183 |
|
184 void DPBusPrimaryMedia::PBusStateChange(TInt aState, TInt anError) |
|
185 { |
|
186 // receive power down and media change notifications |
|
187 __KTRACE_OPT(KLOCDRV,Kern::Printf("DPBusPrimaryMedia(%d)::PBusStateChange state %d, err %d",iMediaId,aState,anError)); |
|
188 if (aState!=iPBusState) |
|
189 { |
|
190 TInt oldState = iPBusState; |
|
191 iPBusState=aState; |
|
192 switch (aState) |
|
193 { |
|
194 case EPBusCardAbsent: |
|
195 NotifyMediaChange(); |
|
196 break; |
|
197 case EPBusOff: |
|
198 switch (anError) |
|
199 { |
|
200 case KErrNone: |
|
201 // machine power down |
|
202 NotifyPowerDown(); |
|
203 break; |
|
204 case KErrTimedOut: |
|
205 // machine power down |
|
206 NotifyPowerDown(); |
|
207 if(oldState == EPBusCardAbsent) |
|
208 { |
|
209 // powering down after power up with no card present. |
|
210 // ...to prevent the bus powering up again, maintain |
|
211 // the card state as absent. A media change will |
|
212 // update the status to allow the bus to power up. |
|
213 iPBusState = EPBusCardAbsent; |
|
214 } |
|
215 break; |
|
216 case KErrNotReady: |
|
217 // card detected following door close |
|
218 NotifyMediaPresent(); |
|
219 break; |
|
220 case KErrAbort: |
|
221 NotifyEmergencyPowerDown(); |
|
222 break; |
|
223 default: |
|
224 if (iState==EPoweringUp1 || iState==EPoweringUp2) |
|
225 PowerUpComplete(anError); |
|
226 break; |
|
227 } |
|
228 case EPBusPoweringUp: |
|
229 // no action required |
|
230 break; |
|
231 case EPBusOn: |
|
232 // bus is now powered up |
|
233 if (iState==EPoweringUp1 || iState==EPoweringUp2) |
|
234 PowerUpComplete(anError); |
|
235 break; |
|
236 case EPBusPsuFault: |
|
237 NotifyPsuFault(anError); |
|
238 break; |
|
239 case EPBusPowerUpPending: |
|
240 // no action required |
|
241 break; |
|
242 default: |
|
243 break; |
|
244 } |
|
245 } |
|
246 } |
|
247 |