omap3530/omap3530_drivers/spi/omap3530_spi.inl
branchBeagle_BSP_dev
changeset 82 65b40f262685
parent 77 e5fd00cbb70a
child 84 09e266454dcf
--- a/omap3530/omap3530_drivers/spi/omap3530_spi.inl	Tue Sep 21 02:30:11 2010 +0100
+++ b/omap3530/omap3530_drivers/spi/omap3530_spi.inl	Wed Sep 22 23:33:25 2010 +0100
@@ -18,28 +18,28 @@
 
 
 // This sets the CS line to inactive mode (Specify aActiveMode as appropriate for configuration)
-// The CS pin will be put back to the opposite mode - using GPIO..
+// The CS pin will be put back to the opposite mode - using GPIO.. THis is in order to always keep
+// the CS line in an 'inactive' state (de-asserted) when the SPI is disabled.
 inline void SetCsInactive(TInt aModule, TInt aChannel, TSpiSsPinMode aActiveMode)
 	{
 	//__ASSERT_DEBUG(aModule < KMaxSpiChannelsPerModule, Kern::Fault("omap3530_spi.inl, line: ", __LINE__)); // aChannel > module channels
 	// set the pin to the opposite to the currently active CS mode..
-	TUint16 csPinOptions = aActiveMode == ESpiCSPinActiveLow ? KCsPinModeUp : KCsPinModeDown;
 	const TPinConfig& csConf = ModulePinConfig[aModule].iCs[aChannel];
 	__ASSERT_DEBUG(csConf.iAddress, Kern::Fault("omap3530_spi.inl, line: ", __LINE__)); // aChannel > module channels
 
-	// now switch the pin mode..
-	SCM::SetPadConfig(csConf.iAddress, csConf.iMswLsw, SCM::EMode4 | csPinOptions); // always go to mode 4 (gpio)
+	// now switch the pin mode..(making sure it is at the proper level before that)
+	GPIO::SetOutputState(csConf.iPinNumber, aActiveMode == ESpiCSPinActiveLow ? GPIO::EHigh : GPIO::ELow);
+	SCM::SetPadConfig(csConf.iAddress, csConf.iMswLsw, SCM::EMode4); // always go to mode 4 (gpio)
 	}
 
-void SetCsActive(TInt aModule, TInt aChannel, TSpiSsPinMode aActiveMode)
+void SetCsActive(TInt aModule, TInt aChannel)
 	{
 	//__ASSERT_DEBUG(aModule < KMaxSpiChannelsPerModule, Kern::Fault("omap3530_spi.inl, line: ", __LINE__)); // aChannel > module channels
-	TUint16 csPinOptions = aActiveMode == ESpiCSPinActiveLow ? KCsPinModeUp : KCsPinModeDown;
 	const TPinConfig &csConf = ModulePinConfig[aModule].iCs[aChannel];
 	__ASSERT_DEBUG(csConf.iAddress, Kern::Fault("omap3530_spi.inl, line: ", __LINE__)); // aChannel > module channels
 
 	// now switch the pin mode back to the SPI
-	SCM::SetPadConfig(csConf.iAddress, csConf.iMswLsw, csConf.iFlags | csPinOptions); // revert to intended mode
+	SCM::SetPadConfig(csConf.iAddress, csConf.iMswLsw, csConf.iFlags | SCM::EInputEnable); // revert to intended mode
 	}
 
 
@@ -51,7 +51,20 @@
 	SCM::SetPadConfig(pinCnf.iClk.iAddress, pinCnf.iClk.iMswLsw, pinCnf.iClk.iFlags);
 	SCM::SetPadConfig(pinCnf.iSimo.iAddress, pinCnf.iSimo.iMswLsw, pinCnf.iSimo.iFlags);
 	SCM::SetPadConfig(pinCnf.iSomi.iAddress, pinCnf.iSomi.iMswLsw, pinCnf.iSomi.iFlags);
-	// Cs pins are set dynamically during operations.
+
+	// Setup GPIO mode/direction for all CS pins only once - here.
+	for(TInt i = 0; i < KMaxSpiChannelsPerModule; i++)
+		{
+		if(pinCnf.iCs[i].iPinNumber)
+			{
+			GPIO::SetPinDirection(pinCnf.iCs[i].iPinNumber, GPIO::EOutput);
+			GPIO::SetPinMode(pinCnf.iCs[i].iPinNumber, GPIO::EEnabled);
+			}
+		else
+			{
+			break;
+			}
+		}
 	}
 
 // helper function - returns appropriate value for the register for a given mode