os/kernelhwsrv/kernel/eka/drivers/pbus/pccard/epoc/pccd_socket.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1995-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\pccard\epoc\pccd_socket.cpp
    15 // 
    16 //
    17 
    18 #include <pccd_socket.h>
    19 
    20 DPlatPcCardSocket::DPlatPcCardSocket(TSocket aSocketNum)
    21 //
    22 // Constructor.
    23 //
    24 	: DPcCardSocket(aSocketNum)
    25 	{
    26 	}
    27 
    28 TInt DPlatPcCardSocket::Create(const TDesC* aName)
    29 //
    30 // Allocate any resources.
    31 //
    32 	{
    33 
    34 	__KTRACE_OPT(KPBUS1,Kern::Printf(">PlatSkt:Create"));
    35 	TInt r=DPcCardSocket::Create(aName);
    36 	if (r!=KErrNone)
    37 		return r;
    38 
    39 	// Bind to the PC card interrupts for this socket
    40 	iCardIReqIntId=ThePccdCntrlInterface->IntIdIReq(iSocketNumber);
    41 	iStatusChangeIntId=ThePccdCntrlInterface->IntIdStsC(iSocketNumber);
    42 	iReadyChangeIntId=ThePccdCntrlInterface->IntIdRdyC(iSocketNumber);
    43 	if (iCardIReqIntId!=-1)
    44 		{
    45 		r=Interrupt::Bind(iCardIReqIntId,CardIReqIsr,this);
    46 		if (r!=KErrNone)
    47 			return r;
    48 		}
    49 	if (iStatusChangeIntId!=-1)
    50 		{
    51 		r=Interrupt::Bind(iStatusChangeIntId,StatusChangeIsr,this);
    52 		if (r!=KErrNone)
    53 			return r;
    54 		}
    55 	if (iReadyChangeIntId!=-1)
    56 		{
    57 		r=Interrupt::Bind(iReadyChangeIntId,ReadyChangeIsr,this);
    58 		if (r!=KErrNone)
    59 			return r;
    60 		}
    61 	return KErrNone;
    62 	}
    63 
    64 void DPlatPcCardSocket::Reset1()
    65 //
    66 // Reset the socket
    67 //
    68 	{
    69 
    70 	__KTRACE_OPT(KPBUS1,Kern::Printf(">PlatSkt(%d):Rst1",iSocketNumber));
    71 	if (iCardIReqIntId!=-1)
    72 		Interrupt::Disable(iCardIReqIntId);
    73 	ThePccdCntrlInterface->InterfaceOff(iSocketNumber);
    74 	DPcCardSocket::Reset1();
    75 	}
    76 
    77 DPccdChunkBase *DPlatPcCardSocket::NewPccdChunk(TPccdMemType aType)
    78 //
    79 // Create a new pc card hw chunk.
    80 //
    81 	{
    82 	return PccdIfc::NewChunk(aType);
    83 	}
    84 
    85 TInt DPlatPcCardSocket::Indicators(TSocketIndicators &anInd)
    86 //
    87 // Return the current state of this sockets indicators
    88 //
    89 	{
    90 
    91 	ThePccdCntrlInterface->Indicators(iSocketNumber,anInd);
    92 	__KTRACE_OPT(KPBUS1,Kern::Printf("<PlatSkt:Indicators(C:%dV:%dW:%dB:%d)",anInd.iCardDetected,anInd.iVoltSense,anInd.iBatState,anInd.iWriteProtected));
    93 	return(KErrNone) ;
    94 	}
    95 
    96 void DPlatPcCardSocket::HwReset(TBool anAssert)
    97 //
    98 // Apply/remove h/w reset.
    99 //
   100 	{
   101 
   102 	__KTRACE_OPT(KPBUS1,Kern::Printf(">PlatSkt:HwRst(%d)",anAssert));
   103     ThePccdCntrlInterface->CardReset(iSocketNumber,anAssert);
   104 	}
   105 
   106 TBool DPlatPcCardSocket::Ready(TInt aCardFunc)
   107 //
   108 // Return the current state of the Card Ready signal. When a function
   109 // isn't specified then it always reads the Ready pin.
   110 //
   111 	{
   112 	// If a function has been specified and this is in I/O mode then read from
   113 	// the configuration register (Pin replacement register).
   114 //	if (aCardFunc!=KInvalidFuncNum)
   115 //		{
   116 //		if ( iStatus==ESocketReady && CardFunc(aCardFunc)->IsConfigured() )
   117 //			{
   118 //			TUint8 reg;
   119 //			if ( ReadConfigReg(aCardFunc,KPinReplacementReg,reg) != KErrNone)
   120 //				return(EFalse);
   121 //			else
   122 //				return(reg&KPinRepReadyM);
   123 //			}
   124 //		}
   125 	TBool rdy=ThePccdCntrlInterface->CardReady(iSocketNumber);
   126 	__KTRACE_OPT(KPBUS1,Kern::Printf("<PlatSkt:Rdy-%d",(TInt)rdy));
   127 	return(rdy);
   128 	}
   129 
   130 TInt DPlatPcCardSocket::InterruptEnable(TPccdInt anInt, TUint aFlag)
   131 //
   132 // Enable the specified interrupt
   133 //
   134 	{
   135 
   136 	TInt err=KErrNone;
   137 	switch(anInt)
   138 		{
   139 		case EPccdIntIReq:
   140 			{
   141 			if (iCardIReqIntId==-1)
   142 				break;
   143 			if (aFlag&KPccdEvFlagReserved)
   144 				iIReqLevelMode=(aFlag&KPccdEvFlagIReqLevelMode);
   145 			TInt irqLevel=NKern::DisableAllInterrupts(); // Disable FIQs while we enable IREQ.
   146 			// IREQ must never be active when Vpc off. Need to check that emergency
   147 			// power down hasn't just happened since this removes Vpc without altering iStatus.
   148 			if (iState==EPBusOn && Kern::PowerGood())
   149 				Interrupt::Enable(iCardIReqIntId);
   150 			else
   151 				err=KErrGeneral;
   152 			NKern::RestoreInterrupts(irqLevel);
   153 			break;
   154 			}
   155 		case EPccdIntRdyChange:
   156 			if (iReadyChangeIntId!=-1)
   157 				Interrupt::Enable(iReadyChangeIntId);
   158 			break;
   159 		case EPccdIntIndChange:
   160 			if (iStatusChangeIntId!=-1)
   161 				Interrupt::Enable(iStatusChangeIntId);
   162 			break;
   163 		default:
   164 			break;
   165 		}
   166 	return(err);
   167 	}
   168 
   169 void DPlatPcCardSocket::InterruptDisable(TPccdInt anInt)
   170 //
   171 // Disable the specified event callback
   172 //
   173 	{
   174 
   175 	switch(anInt)
   176 		{
   177 		case EPccdIntIReq:
   178 			if (iCardIReqIntId!=-1)
   179 				Interrupt::Disable(iCardIReqIntId);
   180 			break;
   181 		case EPccdIntRdyChange:
   182 			if (iReadyChangeIntId!=-1)
   183 				Interrupt::Disable(iReadyChangeIntId);
   184 			break;
   185 		case EPccdIntIndChange:
   186 			if (iStatusChangeIntId!=-1)
   187 				Interrupt::Disable(iStatusChangeIntId);
   188 			break;
   189 		default:
   190 			break;
   191 		}
   192 	}
   193 
   194 
   195 void DPlatPcCardSocket::SocketInfo(TPcCardSocketInfo& anInfo)
   196 //
   197 // Return machine info relating to a particular Pc Card socket 
   198 //
   199 	{
   200 
   201 	ThePccdCntrlInterface->SocketInfo(iSocketNumber,anInfo);
   202 	}
   203 
   204 TBool DPlatPcCardSocket::CardIsPresent()
   205 	{
   206 
   207 	return ThePccdCntrlInterface->CardIsPresent(iSocketNumber);
   208 	}
   209 
   210 void DPlatPcCardSocket::CardIReqIsr(TAny* aPtr)
   211 	{
   212 	DPlatPcCardSocket* pS=(DPlatPcCardSocket*)aPtr;
   213 	if (pS->iIReqLevelMode)
   214 		{
   215 		pS->Isr(EPccdIntIReq);
   216 		Interrupt::Clear(pS->iCardIReqIntId);
   217 		}
   218 	else
   219 		{
   220 		Interrupt::Clear(pS->iCardIReqIntId);
   221 		pS->Isr(EPccdIntIReq);
   222 		}
   223 	}
   224 
   225 void DPlatPcCardSocket::ReadyChangeIsr(TAny* aPtr)
   226 	{
   227 	DPlatPcCardSocket* pS=(DPlatPcCardSocket*)aPtr;
   228 	Interrupt::Clear(pS->iReadyChangeIntId);
   229 	pS->Isr(EPccdIntRdyChange);
   230 	}
   231 
   232 void DPlatPcCardSocket::StatusChangeIsr(TAny* aPtr)
   233 	{
   234 	DPlatPcCardSocket* pS=(DPlatPcCardSocket*)aPtr;
   235 	Interrupt::Clear(pS->iStatusChangeIntId);
   236 	pS->Isr(EPccdIntIndChange);
   237 	}
   238