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