omap3530/beagle_drivers/lcd/lcd.cpp
changeset 34 161f6b2f6990
parent 25 524118fd998f
child 76 0d34a4aa948d
child 78 cf5d4fe2473f
equal deleted inserted replaced
33:c3f5d7eacc87 34:161f6b2f6990
     7 //
     7 //
     8 // Initial Contributors:
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
     9 // Nokia Corporation - initial contribution.
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    12 //
    12 // iwanj@users.sourceforge.net added NGA support based on Syborg display PDD
       
    13 
    13 // Description:
    14 // Description:
    14 // omap3530/beagle_drivers/lcd/lcd.cpp
    15 // omap3530/beagle_drivers/lcd/lcd.cpp
    15 // Implementation of an LCD driver. 
    16 // Implementation of an LCD driver. 
    16 // This file is part of the Beagle Base port
    17 // This file is part of the Beagle Base port
    17 // N.B. This sample code assumes that the display supports setting the backlight on or off, 
    18 // N.B. This sample code assumes that the display supports setting the backlight on or off, 
    18 // as well as adjusting the contrast and the brightness.
    19 // as well as adjusting the contrast and the brightness.
    19 //
    20 //
    20 
       
    21 
       
    22 
       
    23 
       
    24 
    21 
    25 #include <videodriver.h>
    22 #include <videodriver.h>
    26 #include <platform.h>
    23 #include <platform.h>
    27 #include <nkern.h>
    24 #include <nkern.h>
    28 #include <kernel.h>
    25 #include <kernel.h>
    30 #include <kpower.h>
    27 #include <kpower.h>
    31 #include <assp/omap3530_assp/omap3530_assp_priv.h>
    28 #include <assp/omap3530_assp/omap3530_assp_priv.h>
    32 #include <assp/omap3530_assp/omap3530_hardware_base.h>
    29 #include <assp/omap3530_assp/omap3530_hardware_base.h>
    33 #include <assp/omap3530_assp/omap3530_prcm.h>
    30 #include <assp/omap3530_assp/omap3530_prcm.h>
    34 
    31 
       
    32 //#undef __KTRACE_OPT
       
    33 //#define __KTRACE_OPT(c,p)	p
       
    34 
    35 #define DSS_SYSCONFIG				0x48050010
    35 #define DSS_SYSCONFIG				0x48050010
    36 #define DISPC_SYSSTATUS				0x48050414
    36 #define DISPC_SYSSTATUS				0x48050414
    37 
    37 
    38 #define DISPC_SYSCONFIG				0x48050410
    38 #define DISPC_SYSCONFIG				0x48050410
    39 #define DISPC_CONFIG				0x48050444
    39 #define DISPC_CONFIG				0x48050444
    64 #define GET_REGISTER(Reg)		*( (TUint *) Omap3530HwBase::TVirtual<Reg>::Value )
    64 #define GET_REGISTER(Reg)		*( (TUint *) Omap3530HwBase::TVirtual<Reg>::Value )
    65 #define SET_REGISTER(Reg,Val)	*( (TUint *) Omap3530HwBase::TVirtual<Reg>::Value ) = Val
    65 #define SET_REGISTER(Reg,Val)	*( (TUint *) Omap3530HwBase::TVirtual<Reg>::Value ) = Val
    66 
    66 
    67 #define _MODE_1280x1024_
    67 #define _MODE_1280x1024_
    68 //#define _MODE_1024x768_
    68 //#define _MODE_1024x768_
       
    69 
    69 #ifdef _MODE_800x600_
    70 #ifdef _MODE_800x600_
    70 // ModeLine       "800x600@60" 40.0 800 840 968 1056 600 601 605 628 +hsync +vsync
    71 // ModeLine       "800x600@60" 40.0 800 840 968 1056 600 601 605 628 +hsync +vsync
    71 // Decoded by: http://www.tkk.fi/Misc/Electronics/faq/vga2rgb/calc.html
    72 // Decoded by: http://www.tkk.fi/Misc/Electronics/faq/vga2rgb/calc.html
    72 #	define PIXEL_CLK	40000
    73 #	define PIXEL_CLK	40000
    73 #	define H_DISP		800
    74 #	define H_DISP		800
   136 																
   137 																
   137 
   138 
   138 // TO DO: (mandatory)
   139 // TO DO: (mandatory)
   139 // define the physical screen dimensions
   140 // define the physical screen dimensions
   140 // This is only example code... you need to modify it for your hardware
   141 // This is only example code... you need to modify it for your hardware
   141 
       
   142 
       
   143 /*
       
   144 Modified to scale up the display size to a 640x640 , which could be used for VGA layouts as well
       
   145 
       
   146 const TUint	KConfigLcdWidth					= 360;//640;		// 640 pixels per line
   142 const TUint	KConfigLcdWidth					= 360;//640;		// 640 pixels per line
   147 const TUint	KConfigLcdHeight				= 640;//480;		// 480 lines per panel
   143 const TUint	KConfigLcdHeight				= 640;//480;		// 480 lines per panel
   148 */
       
   149 
       
   150 const TUint	KConfigLcdWidth					= 640;		// 640 pixels per line
       
   151 const TUint	KConfigLcdHeight				= 640;		// 640 lines per panel
       
   152 
       
   153 
       
   154 
   144 
   155 // TO DO: (mandatory)
   145 // TO DO: (mandatory)
   156 // define the characteristics of the LCD display
   146 // define the characteristics of the LCD display
   157 // This is only example code... you need to modify it for your hardware
   147 // This is only example code... you need to modify it for your hardware
   158 const TBool	KConfigLcdIsMono				= EFalse;
   148 const TBool	KConfigLcdIsMono				= EFalse;
   159 const TBool	KConfigLcdPixelOrderLandscape	= ETrue;
   149 const TBool	KConfigLcdPixelOrderLandscape	= ETrue;
   160 const TBool	KConfigLcdPixelOrderRGB			= ETrue;
   150 const TBool	KConfigLcdPixelOrderRGB			= ETrue;
   161 const TInt	KConfigLcdMaxDisplayColors		= 65536;	//24bit: 16777216;
   151 const TInt	KConfigLcdMaxDisplayColors		= 16777216;//65536;	//24bit: 16777216;
   162 
   152 
   163 
   153 
   164 // TO DO: (mandatory)
   154 // TO DO: (mandatory)
   165 // define the display dimensions in TWIPs
   155 // define the display dimensions in TWIPs
   166 // A TWIP is a 20th of a point.  A point is a 72nd of an inch
   156 // A TWIP is a 20th of a point.  A point is a 72nd of an inch
   167 // Therefore a TWIP is a 1440th of an inch
   157 // Therefore a TWIP is a 1440th of an inch
   168 // This is only example code... you need to modify it for your hardware
   158 // This is only example code... you need to modify it for your hardware
   169 //const TInt	KConfigLcdWidthInTwips			= 9638;//10800;		// = 6.69 inches	//15*1440;
       
   170 //const TInt	KConfigLcdHeightInTwips			= 7370;//11232;//5616;		// = 5.11 inches	//12*1440;
       
   171 
       
   172 // Modified Twips in accordance with VGA changes - Not sure if it helps or is needed
       
   173 
       
   174 const TInt	KConfigLcdWidthInTwips			= 2670;		// = 6.69 inches	//15*1440;
   159 const TInt	KConfigLcdWidthInTwips			= 2670;		// = 6.69 inches	//15*1440;
   175 const TInt	KConfigLcdHeightInTwips			= 3550;		//5616;		// = 5.11 inches	//12*1440;
   160 const TInt	KConfigLcdHeightInTwips			= 3550;		//5616;		// = 5.11 inches	//12*1440;
   176 
   161 
   177 // TO DO: (mandatory)
   162 // TO DO: (mandatory)
   178 // define the available display modes
   163 // define the available display modes
   191 static const SLcdConfig Lcd_Mode_Config[KConfigLcdNumberOfDisplayModes]=
   176 static const SLcdConfig Lcd_Mode_Config[KConfigLcdNumberOfDisplayModes]=
   192 	{
   177 	{
   193 		{
   178 		{
   194 		0,								// iMode
   179 		0,								// iMode
   195 		0,								// iOffsetToFirstVideoBuffer
   180 		0,								// iOffsetToFirstVideoBuffer
   196 		FRAME_BUFFER_SIZE(16, KConfigLcdWidth, KConfigLcdHeight),	// iLenghtOfVideoBufferInBytes
   181 		FRAME_BUFFER_SIZE(32/*16*/, KConfigLcdWidth, KConfigLcdHeight),	// iLenghtOfVideoBufferInBytes
   197 		KConfigLcdWidth*2,				// iOffsetBetweenLines
   182 		KConfigLcdWidth*4,//2,				// iOffsetBetweenLines
   198 		EFalse,							// iIsPalettized
   183 		EFalse,							// iIsPalettized
   199 		16								// iBitsPerPixel
   184 		32,//16								// iBitsPerPixel
   200 		}
   185 		}
   201 	};	
   186 	};	
   202 
   187 
   203 
   188 
   204 
   189 
   238 	void SetBacklightState(TBool aState);
   223 	void SetBacklightState(TBool aState);
   239 	void BacklightOn();
   224 	void BacklightOn();
   240 	void BacklightOff();
   225 	void BacklightOff();
   241 	TInt SetContrast(TInt aContrast);
   226 	TInt SetContrast(TInt aContrast);
   242 	TInt SetBrightness(TInt aBrightness);
   227 	TInt SetBrightness(TInt aBrightness);
       
   228 
       
   229 #ifdef ENABLE_GCE_MODE
       
   230 	void ChangeFrameBufferAddress(TUint32 aFbAddr);
       
   231 #endif
   243 
   232 
   244 private:
   233 private:
   245 	TInt SetPaletteEntry(TInt aEntry, TInt aColor);
   234 	TInt SetPaletteEntry(TInt aEntry, TInt aColor);
   246 	TInt GetPaletteEntry(TInt aEntry, TInt* aColor);
   235 	TInt GetPaletteEntry(TInt aEntry, TInt* aColor);
   247 	TInt NumberOfPaletteEntries();
   236 	TInt NumberOfPaletteEntries();
   249 	TInt GetSpecifiedDisplayModeInfo(TInt aMode, TVideoInfoV01& aInfo);
   238 	TInt GetSpecifiedDisplayModeInfo(TInt aMode, TVideoInfoV01& aInfo);
   250 	TInt SetDisplayMode(TInt aMode);
   239 	TInt SetDisplayMode(TInt aMode);
   251 	void SplashScreen();
   240 	void SplashScreen();
   252 	TInt GetDisplayColors(TInt* aColors);
   241 	TInt GetDisplayColors(TInt* aColors);
   253 
   242 
       
   243 #ifdef ENABLE_GCE_MODE
       
   244 public:
       
   245 	static DLcdPowerHandler* pLcd;
       
   246 	TInt iSize;
       
   247 	TPhysAddr iCompositionPhysical;
       
   248 	TVideoInfoV01 iVideoInfo;
       
   249 	TDfcQue* iDfcQ;
       
   250 	TPhysAddr ivRamPhys;
       
   251 #endif
       
   252 
   254 private:
   253 private:
   255 	TBool iIsPalettized;
   254 	TBool iIsPalettized;
   256 	TBool iDisplayOn;				// to prevent a race condition with WServer trying to power up/down at the same time
   255 	TBool iDisplayOn;				// to prevent a race condition with WServer trying to power up/down at the same time
   257 	DPlatChunkHw* iChunk;
   256 	DPlatChunkHw* iChunk;
   258 	DPlatChunkHw* iSecureChunk;
   257 	DPlatChunkHw* iSecureChunk;
   259 	TBool iWsSwitchOnScreen;
   258 	TBool iWsSwitchOnScreen;
   260  	TBool iSecureDisplay;
   259  	TBool iSecureDisplay;
   261 	TDfcQue* iDfcQ;
       
   262 	TMessageQue iMsgQ;
   260 	TMessageQue iMsgQ;
   263 	TDfc iPowerUpDfc;
   261 	TDfc iPowerUpDfc;
   264 	TDfc iPowerDownDfc;	
   262 	TDfc iPowerDownDfc;	
       
   263 
       
   264 #ifndef ENABLE_GCE_MODE
       
   265 	TDfcQue* iDfcQ;
   265 	TVideoInfoV01 iVideoInfo;
   266 	TVideoInfoV01 iVideoInfo;
       
   267 	TPhysAddr ivRamPhys;
       
   268 #endif
       
   269 
   266 	TVideoInfoV01 iSecureVideoInfo;
   270 	TVideoInfoV01 iSecureVideoInfo;
   267 	NFastMutex iLock;				// protects against being preempted whilst manipulating iVideoInfo/iSecureVideoInfo
   271 	NFastMutex iLock;				// protects against being preempted whilst manipulating iVideoInfo/iSecureVideoInfo
   268 	TPhysAddr ivRamPhys;
       
   269 	TPhysAddr iSecurevRamPhys;
   272 	TPhysAddr iSecurevRamPhys;
   270 	
   273 	
   271 	TBool iBacklightOn;
   274 	TBool iBacklightOn;
   272 	TInt iContrast;
   275 	TInt iContrast;
   273 	TInt iBrightness;
   276 	TInt iBrightness;
   339 
   342 
   340 Called by factory function at ordinal 0
   343 Called by factory function at ordinal 0
   341 */
   344 */
   342 TInt DLcdPowerHandler::Create()
   345 TInt DLcdPowerHandler::Create()
   343 	{
   346 	{
       
   347 #ifdef ENABLE_GCE_MODE
       
   348 	pLcd = this;
       
   349 #endif
       
   350 
   344 	iDfcQ=Kern::DfcQue0();	// use low priority DFC queue for this driver 
   351 	iDfcQ=Kern::DfcQue0();	// use low priority DFC queue for this driver 
   345 
   352 
   346 	// map the video RAM
   353 	// map the video RAM
   347 	
   354 	
   348 	//TPhysAddr videoRamPhys;
   355 	//TPhysAddr videoRamPhys;
   402 	iSecureVideoInfo = iVideoInfo;
   409 	iSecureVideoInfo = iVideoInfo;
   403 	iSecureVideoInfo.iVideoAddress = (TInt)pV2;
   410 	iSecureVideoInfo.iVideoAddress = (TInt)pV2;
   404 
   411 
   405 	iDisplayOn = EFalse;
   412 	iDisplayOn = EFalse;
   406 	iSecureDisplay = EFalse;
   413 	iSecureDisplay = EFalse;
       
   414 
       
   415 #ifdef ENABLE_GCE_MODE
       
   416 	// Alloc Physical RAM for the Composition Buffers used by the GCE
       
   417 	iSize = Lcd_Mode_Config[KConfigLcdInitialDisplayMode].iLenghtOfVideoBufferInBytes;
       
   418 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DLcdPowerHandler.iSize  = %d", iSize));
       
   419 
       
   420 	// double and round the page size
       
   421 	TUint round = 2*Kern::RoundToPageSize(iSize);
       
   422 	r = Epoc::AllocPhysicalRam(round , iCompositionPhysical);
       
   423 	if(r != KErrNone)
       
   424 		{
       
   425 		__KTRACE_OPT(KEXTENSION, Kern::Printf("Failed to allocate physical RAM for composition buffer %d", r));
       
   426 		return r;
       
   427 		}
       
   428 #endif
   407 
   429 
   408 	// install the HAL function
   430 	// install the HAL function
   409 	r=Kern::AddHalEntry(EHalGroupDisplay, halFunction, this);
   431 	r=Kern::AddHalEntry(EHalGroupDisplay, halFunction, this);
   410 	if (r!=KErrNone)
   432 	if (r!=KErrNone)
   411 		return r;
   433 		return r;
   639 	TInt8 GFXENDIANNESS			= 0x0;
   661 	TInt8 GFXENDIANNESS			= 0x0;
   640 	TInt8 GFXNIBBLEMODE			= 0x0;
   662 	TInt8 GFXNIBBLEMODE			= 0x0;
   641 	TInt8 GFXCHANNELOUT			= 0x0;
   663 	TInt8 GFXCHANNELOUT			= 0x0;
   642 	TInt8 GFXBURSTSIZE			= 0x2;	// 16x32bit bursts
   664 	TInt8 GFXBURSTSIZE			= 0x2;	// 16x32bit bursts
   643 	TInt8 GFXREPLICATIONENABLE	= 0x0;	// Disable Graphics replication logic
   665 	TInt8 GFXREPLICATIONENABLE	= 0x0;	// Disable Graphics replication logic
   644 	TInt8 GFXFORMAT				= 0x6;	// RGB16=0x6, RGB24-unpacked=0x8, RGB24-packed=0x9
   666 	TInt8 GFXFORMAT				= 0x8;//0x6;	// RGB16=0x6, RGB24-unpacked=0x8, RGB24-packed=0x9
   645 	TInt8 GFXENABLE				= 0x1;	// Graphics enabled
   667 	TInt8 GFXENABLE				= 0x1;	// Graphics enabled
   646 	l = GFXSELFREFRESH<<15 | GFXARBITRATION<<14 | GFXROTATION<<12 | GFXFIFOPRELOAD<<11 | GFXENDIANNESS<<10 | GFXNIBBLEMODE<<9 | GFXCHANNELOUT<8 | GFXBURSTSIZE<<6 | GFXREPLICATIONENABLE<<5 | GFXFORMAT<<1 | GFXENABLE;
   668 	l = GFXSELFREFRESH<<15 | GFXARBITRATION<<14 | GFXROTATION<<12 | GFXFIFOPRELOAD<<11 | GFXENDIANNESS<<10 | GFXNIBBLEMODE<<9 | GFXCHANNELOUT<8 | GFXBURSTSIZE<<6 | GFXREPLICATIONENABLE<<5 | GFXFORMAT<<1 | GFXENABLE;
   647 	SET_REGISTER( DISPC_GFX_ATTRIBUTES, l );
   669 	SET_REGISTER( DISPC_GFX_ATTRIBUTES, l );
   648 	
   670 	
   649 	TInt16 GFXFIFOHIGHTHRESHOLD	= 0x3fc;	// Graphics FIFO High Threshold
   671 	TInt16 GFXFIFOHIGHTHRESHOLD	= 0x3fc;	// Graphics FIFO High Threshold
  1239 		}
  1261 		}
  1240 	return r;
  1262 	return r;
  1241 	}
  1263 	}
  1242 
  1264 
  1243 
  1265 
       
  1266 #ifdef ENABLE_GCE_MODE
       
  1267 DLcdPowerHandler* DLcdPowerHandler::pLcd = NULL;
       
  1268 
       
  1269 void DLcdPowerHandler::ChangeFrameBufferAddress(TUint32 aFbAddr)
       
  1270 	{
       
  1271 	//TODO: this is guess work
       
  1272 	//find out the correct sequence to change LCD DMA address
       
  1273 	//
       
  1274 	const TInt8 DISPC_GODIGITAL_BITSHIFT = 6;
       
  1275 	const TInt8 DISPC_GOLCD_BITSHIFT = 5;
       
  1276 	const TUint32 goFlags = (1 << DISPC_GODIGITAL_BITSHIFT) | (1 << DISPC_GOLCD_BITSHIFT);
       
  1277 
       
  1278 	const TUint32 ctl = GET_REGISTER(DISPC_CONTROL);
       
  1279 	SET_REGISTER(DISPC_GFX_BA1, aFbAddr);
       
  1280 	SET_REGISTER(DISPC_CONTROL, ctl | goFlags);
       
  1281 	}
       
  1282 
       
  1283 #include <display.h>
       
  1284 
       
  1285 class DDisplayPddBeagle : public DDisplayPdd
       
  1286 	{
       
  1287 public:
       
  1288 	DDisplayPddBeagle();
       
  1289 	~DDisplayPddBeagle();
       
  1290     virtual TInt  SetLegacyMode();
       
  1291     virtual TInt  SetGceMode();
       
  1292     virtual TInt  SetRotation(RDisplayChannel::TDisplayRotation aRotation);
       
  1293 	virtual TInt  PostUserBuffer(TBufferNode* aNode);
       
  1294 	virtual TInt  PostCompositionBuffer(TBufferNode* aNode);
       
  1295     virtual TInt  PostLegacyBuffer();
       
  1296     virtual TInt  CloseMsg();
       
  1297     virtual TInt  CreateChannelSetup(TInt aUnit);
       
  1298    	virtual TBool  PostPending();
       
  1299     virtual TDfcQue* DfcQ(TInt  aUnit);    
       
  1300             
       
  1301 public:
       
  1302 	static void VSyncDfcFn(TAny* aChannel);
       
  1303 
       
  1304 private:
       
  1305 	TDfcQue* 			iDfcQ;
       
  1306 	TVideoInfoV01    	iScreenInfo;
       
  1307     TBufferNode*     	iPendingBuffer;
       
  1308     TBufferNode*     	iActiveBuffer;
       
  1309     DChunk* 		 	iChunk;
       
  1310 
       
  1311 public:
       
  1312 	TDfc 		     	iVSyncDfc;
       
  1313 	};
       
  1314 
       
  1315 class DDisplayPddFactory : public DPhysicalDevice
       
  1316 	{
       
  1317 public:
       
  1318 	DDisplayPddFactory();
       
  1319 
       
  1320 	virtual TInt Install();
       
  1321 	virtual void GetCaps(TDes8& aDes) const;
       
  1322 	virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* aInfo, const TVersion& aVer);
       
  1323 	virtual TInt Validate(TInt aDeviceType, const TDesC8* anInfo, const TVersion& aVer);
       
  1324 	};
       
  1325 
       
  1326 const TInt KVSyncDfcPriority = 7 ;   //priority of DFC within the queue (0 to 7, where 7 is highest)
       
  1327 
       
  1328 DDisplayPddBeagle::DDisplayPddBeagle():
       
  1329 	iPendingBuffer(NULL),
       
  1330 	iActiveBuffer(NULL),
       
  1331 	iChunk(NULL),
       
  1332 	iVSyncDfc(&VSyncDfcFn, this, KVSyncDfcPriority)
       
  1333 	{
       
  1334 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddBeagle::DDisplayPddBeagle"));
       
  1335 
       
  1336 	iPostFlag = EFalse;
       
  1337 	}
       
  1338 
       
  1339 DDisplayPddBeagle::~DDisplayPddBeagle()
       
  1340 	{
       
  1341 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddBeagle::~DDisplayPddBeagle()"));
       
  1342 
       
  1343 	//The DFC Queue is owned by DLcdPowerHandler so we shouldn't call Destroy() at this point.
       
  1344 	if (iDfcQ)
       
  1345 		{
       
  1346 		iDfcQ=NULL;
       
  1347 		}
       
  1348 
       
  1349 	DChunk* chunk = (DChunk*) __e32_atomic_swp_ord_ptr(&iChunk, 0);
       
  1350 
       
  1351 	if(chunk)
       
  1352 		{
       
  1353 		Kern::ChunkClose(chunk);
       
  1354 		}
       
  1355 
       
  1356 	}
       
  1357 
       
  1358 TInt DDisplayPddBeagle::SetLegacyMode()
       
  1359 	{
       
  1360 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddBeagle::SetLegacyMode()"));
       
  1361     return KErrNone;
       
  1362 	}
       
  1363 
       
  1364 TInt DDisplayPddBeagle::SetGceMode()
       
  1365 	{
       
  1366 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddBeagle::SetGceMode()"));
       
  1367     PostCompositionBuffer(&iLdd->iCompositionBuffer[0]);
       
  1368     return KErrNone;
       
  1369 	}
       
  1370 
       
  1371 TInt DDisplayPddBeagle::SetRotation(RDisplayChannel::TDisplayRotation aDegOfRot)
       
  1372 	{
       
  1373 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddBeagle::SetRotation()"));
       
  1374 	return KErrNone;
       
  1375 	}
       
  1376 
       
  1377 TInt DDisplayPddBeagle::PostUserBuffer(TBufferNode* aNode)
       
  1378 	{
       
  1379 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddBeagle::PostUserBuffer :  aNode->iAddress = %08x\n", aNode->iAddress));
       
  1380 	if(iPendingBuffer)
       
  1381 		{
       
  1382 		iPendingBuffer->iState = EBufferFree;
       
  1383 		if (!(iPendingBuffer->iType == EBufferTypeUser) )
       
  1384 			{
       
  1385 			iPendingBuffer->iFree  = ETrue;
       
  1386 			}
       
  1387 		}
       
  1388 	aNode->iState   = EBufferPending;
       
  1389 	iPendingBuffer	= aNode;
       
  1390 	iPostFlag		= ETrue;
       
  1391 	
       
  1392   	// Activate the posted buffer
       
  1393 	TUint32 physicalAddress = Epoc::LinearToPhysical( aNode->iAddress );
       
  1394 	DLcdPowerHandler::pLcd->ChangeFrameBufferAddress(physicalAddress);
       
  1395 
       
  1396 	/* Queue a DFC to complete the request*/
       
  1397 	iVSyncDfc.Enque();
       
  1398 
       
  1399 	return KErrNone;
       
  1400 	}
       
  1401 
       
  1402 TInt DDisplayPddBeagle::PostCompositionBuffer(TBufferNode* aNode)
       
  1403 	{
       
  1404 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddBeagle::PostCompositionBuffer :  aNode->iAddress = %08x\n", aNode->iAddress));
       
  1405 
       
  1406 	if(iPendingBuffer)
       
  1407 		{
       
  1408 		iPendingBuffer->iState = EBufferFree;
       
  1409 		if (iPendingBuffer->iType == EBufferTypeUser)
       
  1410 			{
       
  1411 			RequestComplete(RDisplayChannel::EReqPostUserBuffer, KErrCancel);
       
  1412 			}
       
  1413 		else
       
  1414 			{
       
  1415 			iPendingBuffer->iFree  = ETrue;
       
  1416 			}
       
  1417 		}
       
  1418 
       
  1419 	aNode->iState	= EBufferPending;
       
  1420 	aNode->iFree	= EFalse;
       
  1421 	iPendingBuffer	= aNode;
       
  1422 	iPostFlag		= ETrue;
       
  1423 
       
  1424   	// Activate the posted buffer
       
  1425 	TUint32 physicalAddress = Epoc::LinearToPhysical( aNode->iAddress );
       
  1426 	DLcdPowerHandler::pLcd->ChangeFrameBufferAddress(physicalAddress);
       
  1427 	
       
  1428 	/* Queue a DFC to complete the request*/
       
  1429 	iVSyncDfc.Enque();
       
  1430 
       
  1431 	return KErrNone;
       
  1432 	}
       
  1433 
       
  1434 TInt DDisplayPddBeagle::PostLegacyBuffer()
       
  1435 	{
       
  1436 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddBeagle::PostLegacyBuffer()"));
       
  1437 
       
  1438 	if(iPendingBuffer)
       
  1439 		{
       
  1440 		iPendingBuffer->iState = EBufferFree;
       
  1441 		if (iPendingBuffer->iType == EBufferTypeUser)
       
  1442 			{
       
  1443 
       
  1444 			RequestComplete(RDisplayChannel::EReqPostUserBuffer, KErrCancel);
       
  1445 			}
       
  1446 		else
       
  1447 			{
       
  1448 			iPendingBuffer->iFree  = ETrue;
       
  1449 			}
       
  1450 		}
       
  1451 
       
  1452 	iLdd->iLegacyBuffer[0].iState		= EBufferPending;
       
  1453 	iLdd->iLegacyBuffer[0].iFree		= EFalse;
       
  1454 	iPendingBuffer						= &iLdd->iLegacyBuffer[0];
       
  1455 	iPostFlag		= ETrue;
       
  1456 
       
  1457   	// Activate the posted buffer
       
  1458 	DLcdPowerHandler::pLcd->ChangeFrameBufferAddress(DLcdPowerHandler::pLcd->ivRamPhys);
       
  1459 
       
  1460 	/* Queue a DFC to complete the request*/
       
  1461 	iVSyncDfc.Enque();
       
  1462 
       
  1463 	return KErrNone;
       
  1464 	}
       
  1465 
       
  1466 TInt DDisplayPddBeagle::CloseMsg()
       
  1467 	{
       
  1468 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddBeagle::CloseMsg()"));
       
  1469 
       
  1470 	iPendingBuffer  = NULL;
       
  1471 	iActiveBuffer	= NULL;
       
  1472 	iVSyncDfc.Cancel();
       
  1473     return KErrNone;
       
  1474 	}
       
  1475 
       
  1476 TInt DDisplayPddBeagle::CreateChannelSetup(TInt aUnit)
       
  1477 	{
       
  1478 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddBeagle::CreateChannelSetup()"));
       
  1479 
       
  1480 	iScreenInfo = DLcdPowerHandler::pLcd->iVideoInfo;
       
  1481 	iLdd->iUnit = aUnit;
       
  1482 
       
  1483 	iLdd->iDisplayInfo.iAvailableRotations			= RDisplayChannel::ERotationNormal;
       
  1484 	iLdd->iDisplayInfo.iNormal.iOffsetBetweenLines	= iScreenInfo.iOffsetBetweenLines;
       
  1485 	iLdd->iDisplayInfo.iNormal.iHeight				= iScreenInfo.iSizeInPixels.iHeight;
       
  1486 	iLdd->iDisplayInfo.iNormal.iWidth				= iScreenInfo.iSizeInPixels.iWidth;
       
  1487 	iLdd->iDisplayInfo.iNumCompositionBuffers		= KDisplayCBMax;
       
  1488 	iLdd->iDisplayInfo.iBitsPerPixel				= iScreenInfo.iBitsPerPixel;
       
  1489     iLdd->iDisplayInfo.iRefreshRateHz = 60;
       
  1490 
       
  1491 
       
  1492 	switch (iScreenInfo.iBitsPerPixel)
       
  1493 		{
       
  1494 		case 16:
       
  1495 			iLdd->iDisplayInfo.iPixelFormat = EUidPixelFormatRGB_565;
       
  1496 			break;
       
  1497 		case 24:
       
  1498 			iLdd->iDisplayInfo.iPixelFormat = EUidPixelFormatRGB_888;
       
  1499 			break;
       
  1500 		case 32:
       
  1501 			iLdd->iDisplayInfo.iPixelFormat = EUidPixelFormatARGB_8888;
       
  1502 			break;
       
  1503 		default:
       
  1504 			iLdd->iDisplayInfo.iPixelFormat = EUidPixelFormatUnknown;
       
  1505 			break;
       
  1506 		}
       
  1507 
       
  1508 	iLdd->iCurrentRotation = RDisplayChannel::ERotationNormal;
       
  1509 
       
  1510 	// Open shared chunk to the composition framebuffer
       
  1511 
       
  1512 	DChunk* chunk = 0;
       
  1513 	TLinAddr chunkKernelAddr  = 0;
       
  1514 	TUint32 chunkMapAttr = 0;
       
  1515 
       
  1516 	// round to twice the page size
       
  1517 	TUint round  =  2*Kern::RoundToPageSize(DLcdPowerHandler::pLcd->iSize);
       
  1518 
       
  1519 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddBeagle::CreateChannelSetup DLcdPowerHandler::pLcd->iSize  = %d\n", DLcdPowerHandler::pLcd->iSize));
       
  1520 
       
  1521 	TChunkCreateInfo info;
       
  1522 	info.iType					 = TChunkCreateInfo::ESharedKernelMultiple;
       
  1523 	info.iMaxSize				 = round;
       
  1524 	info.iMapAttr				 = EMapAttrFullyBlocking;
       
  1525 	info.iOwnsMemory			 = EFalse;
       
  1526 	info.iDestroyedDfc			 = 0;
       
  1527 
       
  1528 	TInt r = Kern::ChunkCreate(info, chunk, chunkKernelAddr, chunkMapAttr);
       
  1529 
       
  1530 	__KTRACE_OPT(KEXTENSION, Kern::Printf("CreateChannelSetup:ChunkCreate called for composition chunk. Set iChunkKernelAddr  = %08x\n", chunkKernelAddr));
       
  1531 
       
  1532 	if( r == KErrNone)
       
  1533 		{
       
  1534 		// map our chunk
       
  1535 		r = Kern::ChunkCommitPhysical(chunk, 0,round , DLcdPowerHandler::pLcd->iCompositionPhysical);
       
  1536 		__KTRACE_OPT(KEXTENSION, Kern::Printf("Mapping chunk %d", r));
       
  1537 		if(r != KErrNone)
       
  1538 			{
       
  1539 			Kern::ChunkClose(chunk);
       
  1540 			}
       
  1541 		}
       
  1542 
       
  1543 	if ( r!= KErrNone)
       
  1544 		{
       
  1545 		return r;
       
  1546 		}
       
  1547 
       
  1548 	iChunk	= chunk;
       
  1549 
       
  1550 	// init CB 0
       
  1551 	iLdd->iCompositionBuffer[0].iType			= EBufferTypeComposition;
       
  1552 	iLdd->iCompositionBuffer[0].iBufferId		= 0;
       
  1553 	iLdd->iCompositionBuffer[0].iFree			= ETrue;
       
  1554 	iLdd->iCompositionBuffer[0].iState			= EBufferFree;
       
  1555 	iLdd->iCompositionBuffer[0].iAddress		= chunkKernelAddr;
       
  1556 	iLdd->iCompositionBuffer[0].iPhysicalAddress = Epoc::LinearToPhysical(chunkKernelAddr);
       
  1557 	iLdd->iCompositionBuffer[0].iChunk			= chunk;
       
  1558 	iLdd->iCompositionBuffer[0].iHandle			= 0;
       
  1559 	iLdd->iCompositionBuffer[0].iOffset			= 0;
       
  1560 	iLdd->iCompositionBuffer[0].iSize			= DLcdPowerHandler::pLcd->iSize;
       
  1561 	iLdd->iCompositionBuffer[0].iPendingRequest = 0;
       
  1562 
       
  1563 	// init CB 1
       
  1564 	iLdd->iCompositionBuffer[1].iType			= EBufferTypeComposition;
       
  1565 	iLdd->iCompositionBuffer[1].iBufferId		= 1;
       
  1566 	iLdd->iCompositionBuffer[1].iFree			= ETrue;
       
  1567 	iLdd->iCompositionBuffer[1].iState			= EBufferFree;
       
  1568 	iLdd->iCompositionBuffer[1].iAddress		= chunkKernelAddr + DLcdPowerHandler::pLcd->iSize;
       
  1569 	iLdd->iCompositionBuffer[1].iPhysicalAddress = Epoc::LinearToPhysical(chunkKernelAddr + DLcdPowerHandler::pLcd->iSize);
       
  1570 	iLdd->iCompositionBuffer[1].iChunk			= chunk;
       
  1571 	iLdd->iCompositionBuffer[1].iHandle			= 0;
       
  1572 	iLdd->iCompositionBuffer[1].iOffset			= DLcdPowerHandler::pLcd->iSize;
       
  1573 	iLdd->iCompositionBuffer[1].iSize			= DLcdPowerHandler::pLcd->iSize;
       
  1574 	iLdd->iCompositionBuffer[1].iPendingRequest = 0;
       
  1575 
       
  1576 	iLdd->iCompositionBuffIdx					= 0;
       
  1577 	//Use the same DFC queue created by the DLcdPowerHandler so all hardware accesses are executed under the same DFC thread.
       
  1578 	iDfcQ= DLcdPowerHandler::pLcd->iDfcQ;
       
  1579 
       
  1580 	// Set the Post DFC.
       
  1581 	iVSyncDfc.SetDfcQ(iDfcQ);
       
  1582 
       
  1583 
       
  1584 	return KErrNone;
       
  1585 	}
       
  1586 
       
  1587 TBool DDisplayPddBeagle::PostPending()
       
  1588 	{
       
  1589 	return (iPendingBuffer != NULL);
       
  1590 	}
       
  1591 
       
  1592 TDfcQue * DDisplayPddBeagle::DfcQ(TInt aUnit)
       
  1593 	{
       
  1594 	return iDfcQ;
       
  1595 	}
       
  1596 
       
  1597 void DDisplayPddBeagle::VSyncDfcFn(TAny* aChannel)
       
  1598 	{
       
  1599 	DDisplayPddBeagle * channel =(DDisplayPddBeagle*)aChannel;
       
  1600 
       
  1601 	if (channel->iPostFlag)
       
  1602 		{
       
  1603 		 channel->iPostFlag = EFalse;
       
  1604 
       
  1605 		if (channel->iActiveBuffer)
       
  1606 			{
       
  1607 			//When a User buffer is registered its iFree member becomes EFalse and Deregister sets it
       
  1608 			//back to ETrue. Composition and Legacy buffers are not free when they are in the pending or
       
  1609 			//active state.
       
  1610 			if (channel->iActiveBuffer->iType == EBufferTypeUser)
       
  1611 				{
       
  1612 				channel->RequestComplete(RDisplayChannel::EReqPostUserBuffer, KErrNone);
       
  1613 				}
       
  1614 			else
       
  1615 				{
       
  1616 				channel->iActiveBuffer->iFree	= ETrue;
       
  1617 				}
       
  1618 
       
  1619 			channel->iActiveBuffer->iState		= EBufferFree;
       
  1620 
       
  1621 
       
  1622 			//If no buffer was available during a call to GetCompositionBuffer the active buffer has
       
  1623 			//been returned as the next available one, so we must set the buffer to the proper state before we
       
  1624 			//send the notification.
       
  1625 			TInt pendingIndex = channel->iLdd->iPendingIndex[RDisplayChannel::EReqGetCompositionBuffer];
       
  1626 			if(channel->iLdd->iPendingReq[RDisplayChannel::EReqGetCompositionBuffer][pendingIndex].iTClientReq)
       
  1627 				{
       
  1628 				if(channel->iLdd->iPendingReq[RDisplayChannel::EReqGetCompositionBuffer][pendingIndex].iTClientReq->IsReady())
       
  1629 					{
       
  1630 					channel->iActiveBuffer->iState = EBufferCompose;
       
  1631 				    channel->RequestComplete(RDisplayChannel::EReqGetCompositionBuffer,KErrNone);
       
  1632 				    }
       
  1633 			    }
       
  1634 
       
  1635 			channel->iActiveBuffer				= NULL;
       
  1636 			}
       
  1637 
       
  1638 		if (channel->iPendingBuffer)
       
  1639 			{
       
  1640 			__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddBeagle::VSyncDfcFn moving pending buffer at address %08x to the active state\n", channel->iPendingBuffer->iAddress));
       
  1641 			channel->iActiveBuffer			= channel->iPendingBuffer;
       
  1642 			channel->iActiveBuffer->iState	= EBufferActive;
       
  1643 			channel->iPendingBuffer			= NULL;
       
  1644 
       
  1645 			channel->RequestComplete(RDisplayChannel::EReqWaitForPost,  KErrNone);
       
  1646 			}
       
  1647 		}
       
  1648 	}
       
  1649 
       
  1650 DDisplayPddFactory::DDisplayPddFactory()
       
  1651 	{
       
  1652 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddFactory::DDisplayPddFactory()"));
       
  1653 
       
  1654 	iVersion		= TVersion(KDisplayChMajorVersionNumber,
       
  1655                       KDisplayChMinorVersionNumber,
       
  1656                       KDisplayChBuildVersionNumber);
       
  1657 	}
       
  1658 
       
  1659 TInt DDisplayPddFactory::Create(DBase*& aChannel, TInt aUnit, const TDesC8* aInfo, const TVersion& aVer)
       
  1660 	{
       
  1661 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddFactory::Create()"));
       
  1662 
       
  1663 	DDisplayPddBeagle *device= new DDisplayPddBeagle() ;
       
  1664 	aChannel=device;
       
  1665 	if (!device)
       
  1666 		{
       
  1667 		return KErrNoMemory;
       
  1668 		}
       
  1669 	return KErrNone;
       
  1670 	}
       
  1671 
       
  1672 TInt DDisplayPddFactory::Install()
       
  1673 	{
       
  1674 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddFactory::Install()"));
       
  1675 
       
  1676 	TBuf<32> name(RDisplayChannel::Name());
       
  1677 	_LIT(KPddExtension,".pdd");
       
  1678 	name.Append(KPddExtension);
       
  1679 	return SetName(&name);
       
  1680 	}
       
  1681 
       
  1682 
       
  1683 void DDisplayPddFactory::GetCaps(TDes8& /*aDes*/) const
       
  1684 	{
       
  1685 	//Not supported
       
  1686 	}
       
  1687 
       
  1688 TInt DDisplayPddFactory::Validate(TInt aUnit, const TDesC8* /*anInfo*/, const TVersion& aVer)
       
  1689 	{
       
  1690 	__KTRACE_OPT(KEXTENSION, Kern::Printf("DDisplayPddFactory::Validate()"));
       
  1691 
       
  1692 	if (!Kern::QueryVersionSupported(iVersion,aVer))
       
  1693 		{
       
  1694 		return KErrNotSupported;
       
  1695 		}
       
  1696 
       
  1697 	if (aUnit != 0)
       
  1698 		{
       
  1699 		return KErrNotSupported;
       
  1700 		}
       
  1701 
       
  1702 	return KErrNone;
       
  1703 	}
       
  1704 
       
  1705 #endif //ENABLE_GCE_MODE
       
  1706 
  1244 DECLARE_STANDARD_EXTENSION()
  1707 DECLARE_STANDARD_EXTENSION()
  1245 	{
  1708 	{
  1246 	__KTRACE_OPT(KPOWER,Kern::Printf("Starting LCD power manager"));
  1709 	__KTRACE_OPT(KEXTENSION, Kern::Printf("Creating DLcdPowerHandler"));
  1247 
  1710 
  1248 	// create LCD power handler
  1711 	TInt r = KErrNoMemory;
  1249 	TInt r=KErrNoMemory;
       
  1250 	DLcdPowerHandler* pH=new DLcdPowerHandler;
  1712 	DLcdPowerHandler* pH=new DLcdPowerHandler;
  1251 	if (pH)
  1713 	if (!pH)
  1252 		r=pH->Create();
  1714 		{
  1253 
  1715 		__KTRACE_OPT(KEXTENSION, Kern::Printf("Failed to create DLcdPowerHandler %d", r));
  1254 	__KTRACE_OPT(KPOWER,Kern::Printf("Returns %d",r));
  1716 		return r;
       
  1717 		}
       
  1718 
       
  1719 	r = pH->Create();
       
  1720 	if (r != KErrNone)
       
  1721 		{
       
  1722 		__KTRACE_OPT(KEXTENSION, Kern::Printf("Failed to create DLcdPowerHandler %d", r));
       
  1723 		return r;
       
  1724 		}
       
  1725 
       
  1726 #ifdef ENABLE_GCE_MODE
       
  1727 	__KTRACE_OPT(KEXTENSION, Kern::Printf("Creating DDisplayPddFactory"));
       
  1728 	r = KErrNoMemory;
       
  1729 	DDisplayPddFactory * device = new DDisplayPddFactory;
       
  1730 	if (!device)
       
  1731 		{
       
  1732 		__KTRACE_OPT(KEXTENSION, Kern::Printf("Failed to create DLcdPowerHandler %d", r));
       
  1733 		return r;
       
  1734 		}
       
  1735 
       
  1736 	__KTRACE_OPT(KEXTENSION, Kern::Printf("Installing DDisplayPddFactory"));
       
  1737 	r = Kern::InstallPhysicalDevice(device);
       
  1738 	if (r != KErrNone)
       
  1739 		{
       
  1740 		__KTRACE_OPT(KEXTENSION, Kern::Printf("Failed to install DDisplayPddFactory %d", r));
       
  1741 		}
       
  1742 #endif
       
  1743 
  1255 	return r;
  1744 	return r;
  1256 	}
  1745 	}
  1257 
  1746