merge omap3 parts from 1.5.15.2766
authorGrazvydas Ignotas <notasas@gmail.com>
Sat, 12 May 2012 17:47:28 +0000 (20:47 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Sun, 13 May 2012 22:11:54 +0000 (01:11 +0300)
services4/3rdparty/dc_omap3_linux/omaplfb.h
services4/3rdparty/dc_omap3_linux/omaplfb_displayclass.c
services4/3rdparty/dc_omap3_linux/omaplfb_linux.c
services4/srvkm/devices/sgx/sgxinfokm.h
services4/system/omap3/sysconfig.c
services4/system/omap3/sysconfig.h
services4/system/omap3/sysinfo.h
services4/system/omap3/syslocal.h
services4/system/omap3/sysutils_linux.c

index da63959..a0a8369 100644 (file)
 #ifndef __OMAPLFB_H__
 #define __OMAPLFB_H__
 
-extern IMG_BOOL PVRGetDisplayClassJTable(PVRSRV_DC_DISP2SRV_KMJTABLE *psJTable);
+#if defined(SGX_EARLYSUSPEND)
+#include <linux/earlysuspend.h>
+#endif
 
-#define OMAPLCD_IRQ                    25
-
-#define OMAPLCD_SYSCONFIG           0x0410
-#define OMAPLCD_CONFIG              0x0444
-#define OMAPLCD_DEFAULT_COLOR0      0x044C
-#define OMAPLCD_TIMING_H            0x0464
-#define OMAPLCD_TIMING_V            0x0468
-#define OMAPLCD_POL_FREQ            0x046C
-#define OMAPLCD_DIVISOR             0x0470
-#define OMAPLCD_SIZE_DIG            0x0478
-#define OMAPLCD_SIZE_LCD            0x047C
-#define OMAPLCD_GFX_POSITION        0x0488
-#define OMAPLCD_GFX_SIZE            0x048C
-#define OMAPLCD_GFX_ATTRIBUTES      0x04a0
-#define OMAPLCD_GFX_FIFO_THRESHOLD  0x04a4
-#define OMAPLCD_GFX_WINDOW_SKIP     0x04b4
-
-#define OMAPLCD_IRQSTATUS       0x0418
-#define OMAPLCD_IRQENABLE       0x041c
-#define OMAPLCD_CONTROL         0x0440
-#define OMAPLCD_GFX_BA0         0x0480
-#define OMAPLCD_GFX_BA1         0x0484
-#define OMAPLCD_GFX_ROW_INC     0x04ac
-#define OMAPLCD_GFX_PIX_INC     0x04b0
-#define OMAPLCD_VID1_BA0        0x04bc
-#define OMAPLCD_VID1_BA1        0x04c0
-#define OMAPLCD_VID1_ROW_INC    0x04d8
-#define OMAPLCD_VID1_PIX_INC    0x04dc
-
-#define        OMAP_CONTROL_GODIGITAL      (1 << 6)
-#define        OMAP_CONTROL_GOLCD          (1 << 5)
-#define        OMAP_CONTROL_DIGITALENABLE  (1 << 1)
-#define        OMAP_CONTROL_LCDENABLE      (1 << 0)
-
-#define OMAPLCD_INTMASK_VSYNC       (1 << 1)
-#define OMAPLCD_INTMASK_OFF            0
+extern IMG_BOOL PVRGetDisplayClassJTable(PVRSRV_DC_DISP2SRV_KMJTABLE *psJTable);
 
 typedef void *       OMAP_HANDLE;
 
@@ -126,9 +93,6 @@ typedef struct PVRPDP_SWAPCHAIN_TAG
        unsigned long       ulRemoveIndex;
 
        
-       void *pvRegs;
-
-       
        PVRSRV_DC_DISP2SRV_KMJTABLE     *psPVRJTable;
 
        
@@ -140,8 +104,8 @@ typedef struct PVRPDP_SWAPCHAIN_TAG
        
        OMAP_BOOL           bBlanked;
 
-       
-       spinlock_t         *psSwapChainLock;
+
+       void*   pvDevInfo;
 } OMAPLFB_SWAPCHAIN;
 
 typedef struct OMAPLFB_FBINFO_TAG
@@ -152,14 +116,16 @@ typedef struct OMAPLFB_FBINFO_TAG
        unsigned long       ulWidth;
        unsigned long       ulHeight;
        unsigned long       ulByteStride;
-
-       
        
        IMG_SYS_PHYADDR     sSysAddr;
        IMG_CPU_VIRTADDR    sCPUVAddr;
 
-       
        PVRSRV_PIXEL_FORMAT ePixelFormat;
+
+#if defined(SGX_EARLYSUSPEND)
+        struct early_suspend early_suspend;
+#endif
+
 }OMAPLFB_FBINFO;
 
 typedef struct OMAPLFB_DEVINFO_TAG
@@ -189,30 +155,25 @@ typedef struct OMAPLFB_DEVINFO_TAG
 
        
        struct fb_info         *psLINFBInfo;
-
        
        struct notifier_block   sLINNotifBlock;
-
        
        OMAP_BOOL               bDeviceSuspended;
-
-       
-       spinlock_t             sSwapChainLock;
-
-       
        
-
+        struct mutex            sSwapChainLockMutex;   
        
        IMG_DEV_VIRTADDR                sDisplayDevVAddr;
 
        DISPLAY_INFO            sDisplayInfo;
-
        
        DISPLAY_FORMAT          sDisplayFormat;
        
-       
        DISPLAY_DIMS            sDisplayDim;
 
+       struct workqueue_struct *vsync_isr_wq;
+
+       struct work_struct      vsync_work;
+
 }  OMAPLFB_DEVINFO;
 
 #define        OMAPLFB_PAGE_SIZE 4096
@@ -221,7 +182,7 @@ typedef struct OMAPLFB_DEVINFO_TAG
 
 #define        OMAPLFB_PAGE_ROUNDUP(x) (((x) + OMAPLFB_PAGE_MASK) & OMAPLFB_PAGE_TRUNC)
 
-#ifdef DEBUG
+#ifdef DEBUG_PVR
 #define        DEBUG_PRINTK(x) printk x
 #else
 #define        DEBUG_PRINTK(x)
@@ -261,20 +222,13 @@ void OMAPLFBDriverResume(void);
 void *OMAPLFBAllocKernelMem(unsigned long ulSize);
 void OMAPLFBFreeKernelMem(void *pvMem);
 OMAP_ERROR OMAPLFBGetLibFuncAddr(char *szFunctionName, PFN_DC_GET_PVRJTABLE *ppfnFuncTable);
-OMAP_ERROR OMAPLFBInstallVSyncISR (OMAPLFB_SWAPCHAIN *psSwapChain);
-OMAP_ERROR OMAPLFBUninstallVSyncISR(OMAPLFB_SWAPCHAIN *psSwapChain);
-OMAP_BOOL OMAPLFBVSyncIHandler(OMAPLFB_SWAPCHAIN *psSwapChain);
-void OMAPLFBEnableVSyncInterrupt(OMAPLFB_SWAPCHAIN *psSwapChain);
-void OMAPLFBDisableVSyncInterrupt(OMAPLFB_SWAPCHAIN *psSwapChain);
-#if defined (SUPPORT_TI_DSS_FW)
-void OMAPLFBEnableDisplayRegisterAccess(void);
-void OMAPLFBDisableDisplayRegisterAccess(void);
-#endif
+void OMAPLFBWaitForVSync(void);
 #if defined (CONFIG_OMAP2_DSS)
 IMG_VOID OMAPLFBFlipDSS2(OMAPLFB_SWAPCHAIN *psSwapChain,
                                                  IMG_UINT32 aPhyAddr);
 #endif
 void OMAPLFBFlip(OMAPLFB_SWAPCHAIN *psSwapChain, unsigned long aPhyAddr);
+OMAPLFB_DEVINFO * GetAnchorPtr(void);
 
 #endif 
 
index 0e6802d..521de95 100644 (file)
@@ -31,7 +31,6 @@
 #include <linux/module.h>
 #include <linux/string.h>
 #include <linux/notifier.h>
-#include <linux/spinlock.h>
 
 #include "img_defs.h"
 #include "servicesext.h"
@@ -42,6 +41,7 @@
 #define acquire_console_sem console_lock
 #define release_console_sem console_unlock
 #endif
+
 static void *gpvAnchor;
 
 static int fb_idx = 0;
@@ -49,8 +49,9 @@ static int fb_idx = 0;
 #define OMAPLFB_COMMAND_COUNT          1
 
 static PFN_DC_GET_PVRJTABLE pfnGetPVRJTable = 0;
+static void OMAPLFBVSyncIHandler(struct work_struct*);
 
-static OMAPLFB_DEVINFO * GetAnchorPtr(void)
+OMAPLFB_DEVINFO * GetAnchorPtr(void)
 {
        return (OMAPLFB_DEVINFO *)gpvAnchor;
 }
@@ -128,7 +129,6 @@ static void SetFlushStateInternalNoLock(OMAPLFB_DEVINFO* psDevInfo,
        {
                if (psSwapChain->ulSetFlushStateRefCount == 0)
                {
-                       OMAPLFBDisableVSyncInterrupt(psSwapChain);
                        psSwapChain->bFlushCommands = OMAP_TRUE;
                        FlushInternalVSyncQueue(psSwapChain);
                }
@@ -142,7 +142,6 @@ static void SetFlushStateInternalNoLock(OMAPLFB_DEVINFO* psDevInfo,
                        if (psSwapChain->ulSetFlushStateRefCount == 0)
                        {
                                psSwapChain->bFlushCommands = OMAP_FALSE;
-                               OMAPLFBEnableVSyncInterrupt(psSwapChain);
                        }
                }
        }
@@ -151,21 +150,17 @@ static void SetFlushStateInternalNoLock(OMAPLFB_DEVINFO* psDevInfo,
 static IMG_VOID SetFlushStateInternal(OMAPLFB_DEVINFO* psDevInfo,
                                       OMAP_BOOL bFlushState)
 {
-       unsigned long ulLockFlags;
-
-       spin_lock_irqsave(&psDevInfo->sSwapChainLock, ulLockFlags);
-
+       mutex_lock(&psDevInfo->sSwapChainLockMutex);
+       
        SetFlushStateInternalNoLock(psDevInfo, bFlushState);
 
-       spin_unlock_irqrestore(&psDevInfo->sSwapChainLock, ulLockFlags);
+       mutex_unlock(&psDevInfo->sSwapChainLockMutex);
 }
 
 static void SetFlushStateExternal(OMAPLFB_DEVINFO* psDevInfo,
                                   OMAP_BOOL bFlushState)
 {
-       unsigned long ulLockFlags;
-
-       spin_lock_irqsave(&psDevInfo->sSwapChainLock, ulLockFlags);
+       mutex_lock(&psDevInfo->sSwapChainLockMutex);
 
        
        if (psDevInfo->bFlushCommands != bFlushState)
@@ -174,7 +169,7 @@ static void SetFlushStateExternal(OMAPLFB_DEVINFO* psDevInfo,
                SetFlushStateInternalNoLock(psDevInfo, bFlushState);
        }
 
-       spin_unlock_irqrestore(&psDevInfo->sSwapChainLock, ulLockFlags);
+       mutex_unlock(&psDevInfo->sSwapChainLockMutex);
 }
 
 static IMG_VOID SetDCState(IMG_HANDLE hDevice, IMG_UINT32 ui32State)
@@ -242,15 +237,12 @@ static OMAP_ERROR UnblankDisplay(OMAPLFB_DEVINFO *psDevInfo)
        acquire_console_sem();
        res = fb_blank(psDevInfo->psLINFBInfo, 0);
        release_console_sem();
-#if !defined (CONFIG_OMAP2_DSS)
-       /* DSS2 returns error if unblank from a non-suspend state */
-       if (res != 0)
+       if (res != 0 && res != -EINVAL)
        {
                printk(KERN_WARNING DRIVER_PREFIX
                        ": fb_blank failed (%d)", res);
                return (OMAP_ERROR_GENERIC);
        }
-#endif
 
        return (OMAP_OK);
 }
@@ -527,9 +519,7 @@ static PVRSRV_ERROR CreateDCSwapChain(IMG_HANDLE hDevice,
        OMAPLFB_VSYNC_FLIP_ITEM *psVSyncFlips;
        IMG_UINT32 i;
        PVRSRV_ERROR eError = PVRSRV_ERROR_GENERIC;
-       unsigned long ulLockFlags;
        IMG_UINT32 ui32BuffersToSkip;
-
        UNREFERENCED_PARAMETER(ui32OEMFlags);
        UNREFERENCED_PARAMETER(pui32SwapChainID);
        
@@ -620,8 +610,11 @@ static PVRSRV_ERROR CreateDCSwapChain(IMG_HANDLE hDevice,
        psSwapChain->ulInsertIndex = 0;
        psSwapChain->ulRemoveIndex = 0;
        psSwapChain->psPVRJTable = &psDevInfo->sPVRJTable;
-       psSwapChain->psSwapChainLock = &psDevInfo->sSwapChainLock;
+       psSwapChain->pvDevInfo = (void*)psDevInfo;
 
+       /* Init the workqueue and its own work */
+       INIT_WORK(&psDevInfo->vsync_work, OMAPLFBVSyncIHandler);
+       psDevInfo->vsync_isr_wq = create_workqueue("pvr_vsync_wq");
        
        for(i=0; i<ui32BufferCount-1; i++)
        {
@@ -641,7 +634,6 @@ static PVRSRV_ERROR CreateDCSwapChain(IMG_HANDLE hDevice,
                psBuffer[i].sSysAddr.uiAddr = psDevInfo->sFBInfo.sSysAddr.uiAddr + ui32BufferOffset;
                psBuffer[i].sCPUVAddr = psDevInfo->sFBInfo.sCPUVAddr + ui32BufferOffset;
        }
-
        
        for(i=0; i<ui32BufferCount; i++)
        {
@@ -649,29 +641,10 @@ static PVRSRV_ERROR CreateDCSwapChain(IMG_HANDLE hDevice,
                psVSyncFlips[i].bFlipped = OMAP_FALSE;
                psVSyncFlips[i].bCmdCompleted = OMAP_FALSE;
        }
-#if defined (SUPPORT_TI_DSS_FW)
-
-       OMAPLFBEnableDisplayRegisterAccess();
-
        
-       psSwapChain->pvRegs = ioremap(psDevInfo->psLINFBInfo->fix.mmio_start, psDevInfo->psLINFBInfo->fix.mmio_len);
-       if (psSwapChain->pvRegs == NULL)
-       {
-               printk(KERN_WARNING DRIVER_PREFIX ": Couldn't map registers needed for flipping\n");
-               goto ErrorDisableDisplayRegisters;
-       }
-#endif
-       if (OMAPLFBInstallVSyncISR(psSwapChain) != OMAP_OK)
-       {
-               printk(KERN_WARNING DRIVER_PREFIX ": ISR handler failed to register\n");
-               goto ErrorUnmapRegisters;
-       }
-
-       spin_lock_irqsave(&psDevInfo->sSwapChainLock, ulLockFlags);
+       mutex_lock(&psDevInfo->sSwapChainLockMutex);
 
-       
        psDevInfo->psSwapChain = psSwapChain;
-
        
        psSwapChain->bFlushCommands = psDevInfo->bFlushCommands;
 
@@ -682,15 +655,14 @@ static PVRSRV_ERROR CreateDCSwapChain(IMG_HANDLE hDevice,
        else
        {
                psSwapChain->ulSetFlushStateRefCount = 0;
-               OMAPLFBEnableVSyncInterrupt(psSwapChain);
        }
                
-       spin_unlock_irqrestore(&psDevInfo->sSwapChainLock, ulLockFlags);
+       mutex_unlock(&psDevInfo->sSwapChainLockMutex);
 
        if (EnableLFBEventNotification(psDevInfo)!= OMAP_OK)
        {
                printk(KERN_WARNING DRIVER_PREFIX ": Couldn't enable framebuffer event notification\n");
-               goto ErrorUninstallVSyncInterrupt;
+               goto ErrorDisableDisplayRegisters;
        }
 
        
@@ -698,17 +670,7 @@ static PVRSRV_ERROR CreateDCSwapChain(IMG_HANDLE hDevice,
 
        return (PVRSRV_OK);
 
-ErrorUninstallVSyncInterrupt:
-       if(OMAPLFBUninstallVSyncISR(psSwapChain) != OMAP_OK)
-       {
-               printk(KERN_WARNING DRIVER_PREFIX ": Couldn't uninstall VSync ISR\n");
-       }
-ErrorUnmapRegisters:
-#if defined (SUPPORT_TI_DSS_FW)
-       iounmap(psSwapChain->pvRegs);
 ErrorDisableDisplayRegisters:
-       OMAPLFBDisableDisplayRegisterAccess();
-#endif
        OMAPLFBFreeKernelMem(psVSyncFlips);
 ErrorFreeBuffers:
        OMAPLFBFreeKernelMem(psBuffer);
@@ -723,7 +685,6 @@ static PVRSRV_ERROR DestroyDCSwapChain(IMG_HANDLE hDevice,
 {
        OMAPLFB_DEVINFO *psDevInfo;
        OMAPLFB_SWAPCHAIN *psSwapChain;
-       unsigned long ulLockFlags;
        OMAP_ERROR eError;
 
        
@@ -745,33 +706,19 @@ static PVRSRV_ERROR DestroyDCSwapChain(IMG_HANDLE hDevice,
                printk(KERN_WARNING DRIVER_PREFIX ": Couldn't disable framebuffer event notification\n");
        }
 
-       spin_lock_irqsave(&psDevInfo->sSwapChainLock, ulLockFlags);
-
-       OMAPLFBDisableVSyncInterrupt(psSwapChain);
-
+       mutex_lock(&psDevInfo->sSwapChainLockMutex);    
        
        FlushInternalVSyncQueue(psSwapChain);
-
        
        OMAPLFBFlip(psSwapChain, (unsigned long)psDevInfo->sFBInfo.sSysAddr.uiAddr);
-
        
        psDevInfo->psSwapChain = NULL;
+       mutex_unlock(&psDevInfo->sSwapChainLockMutex);
 
-       spin_unlock_irqrestore(&psDevInfo->sSwapChainLock, ulLockFlags);
-
-       if(OMAPLFBUninstallVSyncISR(psSwapChain) != OMAP_OK)
-       {
-               printk(KERN_WARNING DRIVER_PREFIX ": Couldn't uninstall VSync ISR\n");
-               return (PVRSRV_ERROR_GENERIC);
-       }
-
-#if defined (SUPPORT_TI_DSS_FW)
-       
-       iounmap(psSwapChain->pvRegs);
-
-       OMAPLFBDisableDisplayRegisterAccess();
-#endif
+       /* Destroy the workqueue */
+       flush_workqueue(psDevInfo->vsync_isr_wq);
+       destroy_workqueue(psDevInfo->vsync_isr_wq);
        
        OMAPLFBFreeKernelMem(psSwapChain->psVSyncFlips);
        OMAPLFBFreeKernelMem(psSwapChain->psBuffer);
@@ -900,7 +847,6 @@ static PVRSRV_ERROR SwapToDCSystem(IMG_HANDLE hDevice,
 {
        OMAPLFB_DEVINFO   *psDevInfo;
        OMAPLFB_SWAPCHAIN *psSwapChain;
-       unsigned long      ulLockFlags;
 
        if(!hDevice || !hSwapChain)
        {
@@ -914,36 +860,35 @@ static PVRSRV_ERROR SwapToDCSystem(IMG_HANDLE hDevice,
                return (PVRSRV_ERROR_INVALID_PARAMS);
        }
        
-       spin_lock_irqsave(&psDevInfo->sSwapChainLock, ulLockFlags);
-
+       mutex_lock(&psDevInfo->sSwapChainLockMutex);
        
        FlushInternalVSyncQueue(psSwapChain);
-
        
        OMAPLFBFlip(psSwapChain, (unsigned long)psDevInfo->sFBInfo.sSysAddr.uiAddr);
 
-       spin_unlock_irqrestore(&psDevInfo->sSwapChainLock, ulLockFlags);
+       mutex_unlock(&psDevInfo->sSwapChainLockMutex);
 
        return (PVRSRV_OK);
 }
 
-OMAP_BOOL OMAPLFBVSyncIHandler(OMAPLFB_SWAPCHAIN *psSwapChain)
+static void OMAPLFBVSyncIHandler(struct work_struct *work)
 {
-       OMAP_BOOL bStatus = OMAP_FALSE;
+       OMAPLFB_DEVINFO *psDevInfo = container_of(work, OMAPLFB_DEVINFO, vsync_work);
        OMAPLFB_VSYNC_FLIP_ITEM *psFlipItem;
+       OMAPLFB_SWAPCHAIN *psSwapChain;
        unsigned long ulMaxIndex;
-       unsigned long ulLockFlags;
 
-       psFlipItem = &psSwapChain->psVSyncFlips[psSwapChain->ulRemoveIndex];
-       ulMaxIndex = psSwapChain->ulBufferCount - 1;
+       mutex_lock(&psDevInfo->sSwapChainLockMutex);
 
-       spin_lock_irqsave(psSwapChain->psSwapChainLock, ulLockFlags);
+       psSwapChain = psDevInfo->psSwapChain;
+       if (!psSwapChain || psSwapChain->bFlushCommands)
+               goto ExitUnlock;
 
+       psFlipItem = &psSwapChain->psVSyncFlips[psSwapChain->ulRemoveIndex];
+       ulMaxIndex = psSwapChain->ulBufferCount - 1;
        
-       if (psSwapChain->bFlushCommands)
-       {
-               goto ExitUnlock;
-       }
+       /* VSync with the display here */
+       OMAPLFBWaitForVSync();
 
        while(psFlipItem->bValid)
        {       
@@ -983,30 +928,33 @@ OMAP_BOOL OMAPLFBVSyncIHandler(OMAPLFB_SWAPCHAIN *psSwapChain)
                        }
                        else
                        {
-                               
-                               break;
+                               queue_work(psDevInfo->vsync_isr_wq, &psDevInfo->vsync_work);
+                               goto ExitUnlock;        
                        }
                }
                else
                {
                        
                        OMAPLFBFlip(psSwapChain, (unsigned long)psFlipItem->sSysAddr);
-                       
-                       
+                                               
                        psFlipItem->bFlipped = OMAP_TRUE;
-                       
-                       
-                       break;
+
+                       /* 
+                        * If the flip has been presented here then we need in the next
+                        * VSYNC execute the command complete, schedule another work
+                        */
+                       queue_work(psDevInfo->vsync_isr_wq, &psDevInfo->vsync_work);
+
+                       goto ExitUnlock;        
                }
                
                
                psFlipItem = &psSwapChain->psVSyncFlips[psSwapChain->ulRemoveIndex];
        }
-               
+
 ExitUnlock:
-       spin_unlock_irqrestore(psSwapChain->psSwapChainLock, ulLockFlags);
+       mutex_unlock(&psDevInfo->sSwapChainLockMutex);
 
-       return bStatus;
 }
 
 static IMG_BOOL ProcessFlip(IMG_HANDLE  hCmdCookie,
@@ -1020,8 +968,6 @@ static IMG_BOOL ProcessFlip(IMG_HANDLE  hCmdCookie,
 #if defined(SYS_USING_INTERRUPTS)
        OMAPLFB_VSYNC_FLIP_ITEM* psFlipItem;
 #endif
-       unsigned long ulLockFlags;
-
        
        if(!hCmdCookie || !pvData)
        {
@@ -1042,8 +988,7 @@ static IMG_BOOL ProcessFlip(IMG_HANDLE  hCmdCookie,
        psBuffer = (OMAPLFB_BUFFER*)psFlipCmd->hExtBuffer;
        psSwapChain = (OMAPLFB_SWAPCHAIN*) psFlipCmd->hExtSwapChain;
 
-       spin_lock_irqsave(&psDevInfo->sSwapChainLock, ulLockFlags);
-
+       mutex_lock(&psDevInfo->sSwapChainLockMutex);
        
        if (psDevInfo->bDeviceSuspended)
        {
@@ -1075,7 +1020,7 @@ static IMG_BOOL ProcessFlip(IMG_HANDLE  hCmdCookie,
                
                if(psSwapChain->ulInsertIndex == psSwapChain->ulRemoveIndex)
                {
-                       
+                       /* If both indexes are equal the queue is empty, present immediatly */
                        OMAPLFBFlip(psSwapChain, (unsigned long)psBuffer->sSysAddr.uiAddr);
 
                        psFlipItem->bFlipped = OMAP_TRUE;
@@ -1085,6 +1030,7 @@ static IMG_BOOL ProcessFlip(IMG_HANDLE  hCmdCookie,
                        psFlipItem->bFlipped = OMAP_FALSE;
                }
 
+               /* The buffer is queued here, must be consumed by the VSYNC workqueue */
                psFlipItem->hCmdComplete = (OMAP_HANDLE)hCmdCookie;
                psFlipItem->ulSwapInterval = (unsigned long)psFlipCmd->ui32SwapInterval;
                psFlipItem->sSysAddr = &psBuffer->sSysAddr;
@@ -1096,15 +1042,19 @@ static IMG_BOOL ProcessFlip(IMG_HANDLE  hCmdCookie,
                        psSwapChain->ulInsertIndex = 0;
                }
 
+               /* Give work to the workqueue to sync with the display */                               
+               queue_work(psDevInfo->vsync_isr_wq, &psDevInfo->vsync_work);
+
                goto ExitTrueUnlock;
        }
        
-       spin_unlock_irqrestore(&psDevInfo->sSwapChainLock, ulLockFlags);
+       mutex_unlock(&psDevInfo->sSwapChainLockMutex);
+
        return IMG_FALSE;
 #endif
 
 ExitTrueUnlock:
-       spin_unlock_irqrestore(&psDevInfo->sSwapChainLock, ulLockFlags);
+       mutex_unlock(&psDevInfo->sSwapChainLockMutex);
        return IMG_TRUE;
 }
 
@@ -1183,26 +1133,19 @@ static OMAP_ERROR InitDev(OMAPLFB_DEVINFO *psDevInfo)
        
        psPVRFBInfo->sSysAddr.uiAddr = psLINFBInfo->fix.smem_start;
        psPVRFBInfo->sCPUVAddr = psLINFBInfo->screen_base;
-       if ((psLINFBInfo->var.rotate == FB_ROTATE_CW)
-               || (psLINFBInfo->var.rotate == FB_ROTATE_CCW) ) {
-          psPVRFBInfo->ulWidth = psLINFBInfo->var.yres;
-          psPVRFBInfo->ulHeight = psLINFBInfo->var.xres;
-    } else {
+
        psPVRFBInfo->ulWidth = psLINFBInfo->var.xres;
        psPVRFBInfo->ulHeight = psLINFBInfo->var.yres;
-    }
-
        psPVRFBInfo->ulByteStride =  psLINFBInfo->fix.line_length;
        psPVRFBInfo->ulFBSize = FBSize;
        psPVRFBInfo->ulBufferSize = psPVRFBInfo->ulHeight * psPVRFBInfo->ulByteStride;
-       
-
 
-#ifdef CONFIG_OMAP2_DSS        
+#ifdef CONFIG_OMAP2_DSS        
     psPVRFBInfo->ulRoundedBufferSize = psPVRFBInfo->ulBufferSize;
 #else
        psPVRFBInfo->ulRoundedBufferSize = OMAPLFB_PAGE_ROUNDUP(psPVRFBInfo->ulBufferSize);
 #endif
+
        if(psLINFBInfo->var.bits_per_pixel == 16)
        {
                if((psLINFBInfo->var.red.length == 5) &&
@@ -1230,7 +1173,6 @@ static OMAP_ERROR InitDev(OMAPLFB_DEVINFO *psDevInfo)
                        (psLINFBInfo->var.blue.offset == 0) && 
                        (psLINFBInfo->var.red.msb_right == 0))
                {
-                       printk ("PVRSRV_PIXEL_FORMAT_ARGB8888\n");
                        psPVRFBInfo->ePixelFormat = PVRSRV_PIXEL_FORMAT_ARGB8888;
                }
                else
@@ -1324,8 +1266,7 @@ OMAP_ERROR OMAPLFBInit(void)
                        return (OMAP_ERROR_INIT_FAILURE);
                }
 
-                               
-               spin_lock_init(&psDevInfo->sSwapChainLock);
+               mutex_init(&psDevInfo->sSwapChainLockMutex);
 
                psDevInfo->psSwapChain = 0;
                psDevInfo->bFlushCommands = OMAP_FALSE;
@@ -1333,11 +1274,10 @@ OMAP_ERROR OMAPLFBInit(void)
 
                psDevInfo->sDisplayInfo.ui32MaxSwapChainBuffers = (IMG_UINT32)(psDevInfo->sFBInfo.ulFBSize / psDevInfo->sFBInfo.ulRoundedBufferSize);
 #if !defined (SUPPORT_TI_DSS_FW)
-               /* DSS2 have trouble with ui32MaxSwapChainBuffers > 3 */
+               /*  Limiting the ui32MaxSwapChainBuffers to 3 */
                if (psDevInfo->sDisplayInfo.ui32MaxSwapChainBuffers > 3)
                        psDevInfo->sDisplayInfo.ui32MaxSwapChainBuffers = 3;
 #endif
-
                if (psDevInfo->sDisplayInfo.ui32MaxSwapChainBuffers == 0)
                {
                        psDevInfo->sDisplayInfo.ui32MaxSwapChains = 0;
@@ -1394,8 +1334,7 @@ OMAP_ERROR OMAPLFBInit(void)
                {
                        return (OMAP_ERROR_DEVICE_REGISTER_FAILED);
                }
-               
-               
+
                pfnCmdProcList[DC_FLIP_COMMAND] = ProcessFlip;
 
                
@@ -1456,7 +1395,7 @@ OMAP_ERROR OMAPLFBDeinit(void)
                {
                        return (OMAP_ERROR_GENERIC);
                }
-               
+
                DeInitDev(psDevInfo);
 
                
@@ -1475,9 +1414,8 @@ OMAP_ERROR OMAPLFBDeinit(void)
 void OMAPLFBDriverSuspend(void)
 {
        OMAPLFB_DEVINFO *psDevInfo = GetAnchorPtr();
-       unsigned long    ulLockFlags;
 
-       spin_lock_irqsave(&psDevInfo->sSwapChainLock, ulLockFlags);
+       mutex_lock(&psDevInfo->sSwapChainLockMutex);
 
        if (psDevInfo->bDeviceSuspended)
        {
@@ -1488,44 +1426,30 @@ void OMAPLFBDriverSuspend(void)
        
        SetFlushStateInternalNoLock(psDevInfo, OMAP_TRUE);
 
-       spin_unlock_irqrestore(&psDevInfo->sSwapChainLock, ulLockFlags);
-
+       mutex_unlock(&psDevInfo->sSwapChainLockMutex);
        
-#if defined (SUPPORT_TI_DSS_FW)                
-       if (psDevInfo->psSwapChain != NULL)
-       {
-               OMAPLFBDisableDisplayRegisterAccess();
-       }
-#endif
        return;
 
 ExitUnlock:
-       spin_unlock_irqrestore(&psDevInfo->sSwapChainLock, ulLockFlags);
+       mutex_unlock(&psDevInfo->sSwapChainLockMutex);
 }
 
 void OMAPLFBDriverResume(void)
 {
        OMAPLFB_DEVINFO *psDevInfo = GetAnchorPtr();
-       unsigned long    ulLockFlags;
 
        if (psDevInfo->bDeviceSuspended == OMAP_FALSE)
        {
                return;
        }
-#if defined (SUPPORT_TI_DSS_FW)
-       if (psDevInfo->psSwapChain != NULL)
-       {
-               OMAPLFBEnableDisplayRegisterAccess();
-       }
-#endif
-       spin_lock_irqsave(&psDevInfo->sSwapChainLock, ulLockFlags);
 
+       mutex_lock(&psDevInfo->sSwapChainLockMutex);
        
        SetFlushStateInternalNoLock(psDevInfo, OMAP_FALSE);
 
        psDevInfo->bDeviceSuspended = OMAP_FALSE;
 
-       spin_unlock_irqrestore(&psDevInfo->sSwapChainLock, ulLockFlags);
+       mutex_unlock(&psDevInfo->sSwapChainLockMutex);
 }
 #endif
 
index 61a3686..4a80f1c 100644 (file)
 #include <linux/version.h>
 #include <linux/module.h>
 
-#include <linux/pci.h>
-#include <asm/uaccess.h>
-#include <linux/slab.h>
-#include <linux/errno.h>
-#include <linux/interrupt.h>
+#include <linux/fb.h>
+#include <linux/omapfb.h>
+
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
+#include <plat/vrfb.h>
+#else
+#include <mach/vrfb.h>
+#endif
+#include <../drivers/video/omap2/omapfb/omapfb.h>
 
 #if defined(LDM_PLATFORM)
 #include <linux/platform_device.h>
 #endif 
 
-#if defined (SUPPORT_TI_DSS_FW)
 #include <asm/io.h>
 
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26))
-#include <plat/display.h>
-#else 
-#include <asm/arch-omap/display.h>
-#endif 
-#else
-#if !defined (CONFIG_OMAP2_DSS)
-#define DISPC_IRQ_VSYNC 0x0002
-extern int omap_dispc_request_irq(unsigned long, void (*)(void *), void *);
-extern void omap_dispc_free_irq(unsigned long, void (*)(void *), void *);
-extern void omap_dispc_set_plane_base(int plane, IMG_UINT32 phys_addr);
-#else
 #if   (LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0))
 #include <video/omapdss.h>
 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32))
 #include <plat/display.h>
-#else
+#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26))
 #include <mach/display.h>
-#endif
-#include <linux/console.h>
-#include <linux/fb.h>
-static omap_dispc_isr_t *pOMAPLFBVSyncISRHandle = NULL;
-#endif
-#endif
-
-
+#else 
+#include <asm/arch-omap/display.h>
+#endif 
 
 #include "img_defs.h"
 #include "servicesext.h"
@@ -81,6 +67,8 @@ MODULE_SUPPORTED_DEVICE(DEVNAME);
 
 #define unref__ __attribute__ ((unused))
 
+static struct omap_overlay_manager* lcd_mgr = 0;
+
 void *OMAPLFBAllocKernelMem(unsigned long ulSize)
 {
        return kmalloc(ulSize, GFP_KERNEL);
@@ -104,165 +92,80 @@ OMAP_ERROR OMAPLFBGetLibFuncAddr (char *szFunctionName, PFN_DC_GET_PVRJTABLE *pp
 
        return (OMAP_OK);
 }
-#if !defined (SUPPORT_TI_DSS_FW) 
-IMG_VOID OMAPLFBEnableVSyncInterrupt(OMAPLFB_SWAPCHAIN *psSwapChain)
-{
-       if (pOMAPLFBVSyncISRHandle == NULL)
-               OMAPLFBInstallVSyncISR (psSwapChain);
-}
 
-IMG_VOID OMAPLFBDisableVSyncInterrupt(OMAPLFB_SWAPCHAIN *psSwapChain)
-{
-       if (pOMAPLFBVSyncISRHandle != NULL)
-               OMAPLFBUninstallVSyncISR (psSwapChain);
-}
-#else
-static void OMAPLFBVSyncWriteReg(OMAPLFB_SWAPCHAIN *psSwapChain, unsigned long ulOffset, unsigned long ulValue)
-{
-       void *pvRegAddr = (void *)((char *)psSwapChain->pvRegs + ulOffset);
+static void GetLcdManager(void){
+    lcd_mgr = omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_LCD);
+    if(!lcd_mgr)
+    {
+       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": GetLcdManager couldn't find lcd overlay manager\n"));
+    }
 
-       
-       writel(ulValue, pvRegAddr);
 }
 
-static unsigned long OMAPLFBVSyncReadReg(OMAPLFB_SWAPCHAIN *psSwapChain, unsigned long ulOffset)
-{
-       return readl((char *)psSwapChain->pvRegs + ulOffset);
-}
 
-void OMAPLFBEnableVSyncInterrupt(OMAPLFB_SWAPCHAIN *psSwapChain)
+void OMAPLFBFlip(OMAPLFB_SWAPCHAIN *psSwapChain, unsigned long aPhyAddr)
 {
-#if defined(SYS_USING_INTERRUPTS)
-       
-       unsigned long ulInterruptEnable  = OMAPLFBVSyncReadReg(psSwapChain, OMAPLCD_IRQENABLE);
-       ulInterruptEnable |= OMAPLCD_INTMASK_VSYNC;
-       OMAPLFBVSyncWriteReg(psSwapChain, OMAPLCD_IRQENABLE, ulInterruptEnable );
-#endif
+       OMAPLFBFlipDSS2 (psSwapChain, aPhyAddr);
 }
 
-void OMAPLFBDisableVSyncInterrupt(OMAPLFB_SWAPCHAIN *psSwapChain)
+void OMAPLFBWaitForVSync(void)
 {
-#if defined(SYS_USING_INTERRUPTS)
-       
-       unsigned long ulInterruptEnable = OMAPLFBVSyncReadReg(psSwapChain, OMAPLCD_IRQENABLE);
-       ulInterruptEnable &= ~(OMAPLCD_INTMASK_VSYNC);
-       OMAPLFBVSyncWriteReg(psSwapChain, OMAPLCD_IRQENABLE, ulInterruptEnable);
+#if 0
+       if (lcd_mgr && lcd_mgr->device) 
+               lcd_mgr->device->wait_vsync(lcd_mgr->device);
 #endif
 }
-#endif
-#if defined(SYS_USING_INTERRUPTS)
-static void
-#if defined (SUPPORT_TI_DSS_FW)
-OMAPLFBVSyncISR(void *arg, struct pt_regs unref__ *regs)
-#else
-#if defined (CONFIG_OMAP2_DSS)
-OMAPLFBVSyncISR(void *arg, u32 mask)
-#else
-OMAPLFBVSyncISR(void *arg)
-#endif
-#endif
-{
-       OMAPLFB_SWAPCHAIN *psSwapChain= (OMAPLFB_SWAPCHAIN *)arg;
-       
-       (void) OMAPLFBVSyncIHandler(psSwapChain);
-}
-#endif
-#if !defined (SUPPORT_TI_DSS_FW)
-OMAP_ERROR OMAPLFBInstallVSyncISR(OMAPLFB_SWAPCHAIN *psSwapChain)
-{
-#if !defined (CONFIG_OMAP2_DSS)
-       if (omap_dispc_request_irq(DISPC_IRQ_VSYNC, OMAPLFBVSyncISR, psSwapChain) != 0)
-#else
-        pOMAPLFBVSyncISRHandle = omap_dispc_register_isr(
-                       (omap_dispc_isr_t)OMAPLFBVSyncISR, psSwapChain, DISPC_IRQ_VSYNC);
-
-       if (pOMAPLFBVSyncISRHandle != NULL)
-#endif
-               return PVRSRV_ERROR_OUT_OF_MEMORY; /* not worth a proper mapping */
-       return OMAP_OK;
-}
 
 
-OMAP_ERROR OMAPLFBUninstallVSyncISR (OMAPLFB_SWAPCHAIN *psSwapChain)
-{
-#if !defined (CONFIG_OMAP2_DSS)
-       omap_dispc_free_irq(DISPC_IRQ_VSYNC, OMAPLFBVSyncISR, psSwapChain);
-#else
-       omap_dispc_unregister_isr (OMAPLFBVSyncISR, psSwapChain, DISPC_IRQ_VSYNC);
-#endif
-       return OMAP_OK;         
-} 
+#if defined(LDM_PLATFORM)
 
+static volatile OMAP_BOOL bDeviceSuspended;
 
-IMG_VOID OMAPLFBFlip(OMAPLFB_SWAPCHAIN *psSwapChain,
-                                                 IMG_UINT32 aPhyAddr)
-{
-#if !defined (CONFIG_OMAP2_DSS)
-       omap_dispc_set_plane_base(0, aPhyAddr);
-#else
-       OMAPLFBFlipDSS2 (psSwapChain, aPhyAddr);
-#endif
-}
-#else
+#if !defined(SGX_EARLYSUSPEND)
 
-OMAP_ERROR OMAPLFBInstallVSyncISR(OMAPLFB_SWAPCHAIN *psSwapChain)
+static void OMAPLFBCommonSuspend(void)
 {
-#if defined(SYS_USING_INTERRUPTS)
-       OMAPLFBDisableVSyncInterrupt(psSwapChain);
-
-       if (omap2_disp_register_isr(OMAPLFBVSyncISR, psSwapChain,
-                                   DISPC_IRQSTATUS_VSYNC))
+       if (bDeviceSuspended)
        {
-               printk(KERN_INFO DRIVER_PREFIX ": OMAPLFBInstallVSyncISR: Request OMAPLCD IRQ failed\n");
-               return (OMAP_ERROR_INIT_FAILURE);
+               return;
        }
 
-#endif
-       return (OMAP_OK);
-}
+       OMAPLFBDriverSuspend();
 
+       bDeviceSuspended = OMAP_TRUE;
+}
 
-OMAP_ERROR OMAPLFBUninstallVSyncISR (OMAPLFB_SWAPCHAIN *psSwapChain)
+static int OMAPLFBDriverSuspend_Entry(struct platform_device unref__ *pDevice, pm_message_t unref__ state)
 {
-#if defined(SYS_USING_INTERRUPTS)
-       OMAPLFBDisableVSyncInterrupt(psSwapChain);
-
-       omap2_disp_unregister_isr(OMAPLFBVSyncISR);
+       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": OMAPLFBDriverSuspend_Entry\n"));
 
-#endif
-       return (OMAP_OK);
-}
+       OMAPLFBCommonSuspend();
 
-void OMAPLFBEnableDisplayRegisterAccess(void)
-{
-       omap2_disp_get_dss();
+       return 0;
 }
 
-void OMAPLFBDisableDisplayRegisterAccess(void)
+static int OMAPLFBDriverResume_Entry(struct platform_device unref__ *pDevice)
 {
-       omap2_disp_put_dss();
-}
+       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": OMAPLFBDriverResume_Entry\n"));
 
-void OMAPLFBFlip(OMAPLFB_SWAPCHAIN *psSwapChain, unsigned long aPhyAddr)
-{
-       unsigned long control;
+       OMAPLFBDriverResume();
 
-       
-       OMAPLFBVSyncWriteReg(psSwapChain, OMAPLCD_GFX_BA0, aPhyAddr);
-       OMAPLFBVSyncWriteReg(psSwapChain, OMAPLCD_GFX_BA1, aPhyAddr);
+       bDeviceSuspended = OMAP_FALSE;
 
-       control = OMAPLFBVSyncReadReg(psSwapChain, OMAPLCD_CONTROL);
-       control |= OMAP_CONTROL_GOLCD;
-       OMAPLFBVSyncWriteReg(psSwapChain, OMAPLCD_CONTROL, control);
+       return 0;
 }
-#endif
 
-#if defined(LDM_PLATFORM)
+static IMG_VOID OMAPLFBDriverShutdown_Entry(struct platform_device unref__ *pDevice)
+{
+       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": OMAPLFBDriverShutdown_Entry\n"));
 
-static OMAP_BOOL bDeviceSuspended;
+       OMAPLFBCommonSuspend();
+}
 
+#else /* !defined(SGX_EARLYSUSPEND) */
 static void OMAPLFBCommonSuspend(void)
 {
+
        if (bDeviceSuspended)
        {
                return;
@@ -271,51 +174,52 @@ static void OMAPLFBCommonSuspend(void)
        OMAPLFBDriverSuspend();
 
        bDeviceSuspended = OMAP_TRUE;
+
 }
 
-static int OMAPLFBDriverSuspend_Entry(struct platform_device unref__ *pDevice, pm_message_t unref__ state)
+static void OMAPLFBDriverSuspend_Entry(struct early_suspend *h)
 {
        DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": OMAPLFBDriverSuspend_Entry\n"));
 
+       printk(KERN_WARNING DRIVER_PREFIX ": **** SUSPEND\n");
+       
        OMAPLFBCommonSuspend();
 
-       return 0;
 }
 
-static int OMAPLFBDriverResume_Entry(struct platform_device unref__ *pDevice)
+static void OMAPLFBDriverResume_Entry(struct early_suspend *h)
 {
        DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": OMAPLFBDriverResume_Entry\n"));
 
-       OMAPLFBDriverResume();
-
-       bDeviceSuspended = OMAP_FALSE;
-
-       return 0;
-}
-
-static IMG_VOID OMAPLFBDriverShutdown_Entry(struct platform_device unref__ *pDevice)
-{
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": OMAPLFBDriverShutdown_Entry\n"));
+       printk(KERN_WARNING DRIVER_PREFIX ": **** RESUME\n");   
 
-       OMAPLFBCommonSuspend();
-}
+       OMAPLFBDriverResume();  
 
-static void OMAPLFBDeviceRelease_Entry(struct device unref__ *pDevice)
-{
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": OMAPLFBDriverRelease_Entry\n"));
+       bDeviceSuspended = OMAP_FALSE;
 
-       OMAPLFBCommonSuspend();
 }
+#endif /* !defined(SGX_EARLYSUSPEND) */
 
 static struct platform_driver omaplfb_driver = {
        .driver = {
                .name           = DRVNAME,
        },
+#if !defined(SGX_EARLYSUSPEND)
        .suspend        = OMAPLFBDriverSuspend_Entry,
        .resume         = OMAPLFBDriverResume_Entry,
        .shutdown       = OMAPLFBDriverShutdown_Entry,
+#endif
 };
 
+#if defined(MODULE)
+
+static void OMAPLFBDeviceRelease_Entry(struct device unref__ *pDevice)
+{
+       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": OMAPLFBDriverRelease_Entry\n"));
+
+       OMAPLFBCommonSuspend();
+}
+
 static struct platform_device omaplfb_device = {
        .name                   = DEVNAME,
        .id                             = -1,
@@ -323,6 +227,13 @@ static struct platform_device omaplfb_device = {
                .release                = OMAPLFBDeviceRelease_Entry
        }
 };
+
+#endif /* defined(MODULE) */  
+
+#endif /* defined(LDM_PLATFORM) */
+
+#if defined(SGX_EARLYSUSPEND)
+       OMAPLFB_DEVINFO *psDevInfo;
 #endif 
 
 static int __init OMAPLFB_Init(void)
@@ -337,6 +248,9 @@ static int __init OMAPLFB_Init(void)
                return -ENODEV;
        }
 
+       /* Get the LCD manager which corresponds to the primary display*/
+       GetLcdManager();
+
 #if defined(LDM_PLATFORM)
        if ((error = platform_driver_register(&omaplfb_driver)) != 0)
        {
@@ -345,35 +259,62 @@ static int __init OMAPLFB_Init(void)
                goto ExitDeinit;
        }
 
+#if defined(MODULE)
        if ((error = platform_device_register(&omaplfb_device)) != 0)
        {
-               printk(KERN_WARNING DRIVER_PREFIX ": OMAPLFB_Init:  Unable to register platform device (%d)\n", error);
+               printk(KERN_WARNING DRIVER_PREFIX ": OMAPLFB_Init: Unable to register platform device (%d)\n", error);
 
-               goto ExitDriverUnregister;
+               goto ExitDeinit;
        }
-#endif 
+#endif /* defined(MODULE) */
+
+#if defined(SGX_EARLYSUSPEND)
+       psDevInfo = NULL;
+       psDevInfo = GetAnchorPtr();
+
+       if (psDevInfo == NULL)
+       {
+               DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": OMAPLFB_Init: Unable to get DevInfo anchor pointer\n"));
+               goto ExitDeinit;
+       }
+
+       psDevInfo->sFBInfo.early_suspend.suspend = OMAPLFBDriverSuspend_Entry;
+        psDevInfo->sFBInfo.early_suspend.resume = OMAPLFBDriverResume_Entry;
+        psDevInfo->sFBInfo.early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB;
+        register_early_suspend(&psDevInfo->sFBInfo.early_suspend);
+#endif /* defined(SGX_EARLYSUSPEND) */
+
+#endif /* defined(LDM_PLATFORM) */
 
        return 0;
 
 #if defined(LDM_PLATFORM)
-ExitDriverUnregister:
+ExitDeinit:
        platform_driver_unregister(&omaplfb_driver);
 
-ExitDeinit:
+#if defined(SGX_EARLYSUSPEND)
+        unregister_early_suspend(&psDevInfo->sFBInfo.early_suspend);
+#endif
        if(OMAPLFBDeinit() != OMAP_OK)
        {
                printk(KERN_WARNING DRIVER_PREFIX ": OMAPLFB_Init: OMAPLFBDeinit failed\n");
        }
 
        return -ENODEV;
-#endif 
+#endif /* defined(LDM_PLATFORM) */ 
 }
 
 static IMG_VOID __exit OMAPLFB_Cleanup(IMG_VOID)
 {    
 #if defined (LDM_PLATFORM)
+#if defined (MODULE)
        platform_device_unregister(&omaplfb_device);
+#endif
        platform_driver_unregister(&omaplfb_driver);
+#endif /* defined (LDM_PLATFORM) */
+
+#if defined(SGX_EARLYSUSPEND)
+       unregister_early_suspend(&psDevInfo->sFBInfo.early_suspend);
 #endif
 
        if(OMAPLFBDeinit() != OMAP_OK)
index 6a08c07..4c9f17f 100644 (file)
@@ -232,6 +232,7 @@ typedef struct _SGX_TIMING_INFORMATION_
 {
        IMG_UINT32                      ui32CoreClockSpeed;
        IMG_UINT32                      ui32HWRecoveryFreq;
+       IMG_BOOL                        bEnableActivePM;
        IMG_UINT32                      ui32ActivePowManLatencyms;
        IMG_UINT32                      ui32uKernelFreq;
 } SGX_TIMING_INFORMATION;
index 694b63c..0f22369 100644 (file)
@@ -56,6 +56,117 @@ IMG_UINT32 PVRSRV_BridgeDispatchKM(IMG_UINT32       Ioctl,
                                                                   IMG_UINT32   OutBufLen,
                                                                   IMG_UINT32   *pdwBytesTransferred);
 
+#if defined(DEBUG_PVR) && defined(DUMP_OMAP34xx_CLOCKS) && defined(__linux__)
+
+#pragma GCC diagnostic ignored "-Wstrict-prototypes"
+#include <mach/clock.h>
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
+#include <../mach-omap2/clock_34xx.h>
+#define ONCHIP_CLKS onchip_clks
+#else
+#include <../mach-omap2/clock34xx.h>
+#define ONCHIP_CLKS onchip_34xx_clks
+#endif
+
+static void omap3_clk_recalc(struct clk *clk) {}
+static void omap3_followparent_recalc(struct clk *clk) {}
+static void omap3_propagate_rate(struct clk *clk) {}
+static void omap3_table_recalc(struct clk *clk) {}
+static long omap3_round_to_table_rate(struct clk *clk, unsigned long rate) { return 0; }
+static int omap3_select_table_rate(struct clk *clk, unsigned long rate) { return 0; }
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
+static void omap3_dpll_recalc(struct clk *clk, unsigned long parent_rate,
+                                                         u8 rate_storage) {}
+static void omap3_clkoutx2_recalc(struct clk *clk, unsigned long parent_rate,
+                                                                 u8 rate_storage) {}
+static void omap3_dpll_allow_idle(struct clk *clk) {}
+static void omap3_dpll_deny_idle(struct clk *clk) {}
+static u32 omap3_dpll_autoidle_read(struct clk *clk) { return 0; }
+static int omap3_noncore_dpll_enable(struct clk *clk) { return 0; }
+static void omap3_noncore_dpll_disable(struct clk *clk) {}
+static int omap3_noncore_dpll_set_rate(struct clk *clk, unsigned long rate) { return 0; }
+static int omap3_core_dpll_m2_set_rate(struct clk *clk, unsigned long rate) { return 0; }
+void followparent_recalc(struct clk *clk, unsigned long new_parent_rate,
+                                                               u8 rate_storage) {}
+long omap2_dpll_round_rate(struct clk *clk, unsigned long target_rate) { return 0; }
+void omap2_clksel_recalc(struct clk *clk, unsigned long new_parent_rate,
+                                                               u8 rate_storage) {}
+long omap2_clksel_round_rate(struct clk *clk, unsigned long target_rate) { return 0; }
+int omap2_clksel_set_rate(struct clk *clk, unsigned long rate) { return 0; }
+void omap2_fixed_divisor_recalc(struct clk *clk, unsigned long new_parent_rate,
+                                                                          u8 rate_storage) {}
+void omap2_init_clksel_parent(struct clk *clk) {}
+#endif
+
+static void dump_omap34xx_clocks(void)
+{
+       struct clk **c;
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
+       struct vdd_prcm_config *t1 = vdd1_rate_table;
+       struct vdd_prcm_config *t2 = vdd2_rate_table;
+
+       t1 = t1;
+       t2 = t2;
+#else
+       
+       omap3_dpll_allow_idle(0);
+       omap3_dpll_deny_idle(0);
+       omap3_dpll_autoidle_read(0);
+       omap3_clk_recalc(0);
+       omap3_followparent_recalc(0);
+       omap3_propagate_rate(0);
+       omap3_table_recalc(0);
+       omap3_round_to_table_rate(0, 0);
+       omap3_select_table_rate(0, 0);
+#endif
+
+       for(c = ONCHIP_CLKS; c < ONCHIP_CLKS + ARRAY_SIZE(ONCHIP_CLKS); c++)
+       {
+               struct clk *cp = *c, *copy;
+               unsigned long rate;
+               copy = clk_get(NULL, cp->name);
+               if(!copy)
+                       continue;
+               rate = clk_get_rate(copy);
+               if (rate < 1000000)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "%s: clock %s is %lu KHz (%lu Hz)", __func__, cp->name, rate/1000, rate));
+               }
+               else
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "%s: clock %s is %lu MHz (%lu Hz)", __func__, cp->name, rate/1000000, rate));
+               }
+       }
+}
+
+#else  
+
+static INLINE void dump_omap34xx_clocks(void) {}
+
+#endif 
+
+static INLINE PVRSRV_ERROR EnableSGXClocksWrap(SYS_DATA *psSysData)
+{
+       return EnableSGXClocks(psSysData);
+}
+
+static INLINE PVRSRV_ERROR EnableSystemClocksWrap(SYS_DATA *psSysData)
+{
+       PVRSRV_ERROR eError = EnableSystemClocks(psSysData);
+
+#if !defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
+       if(eError == PVRSRV_OK)
+       {
+               
+               EnableSGXClocksWrap(psSysData);
+       }
+#endif
+
+       return eError;
+}
+
 static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
 {
 #if defined(NO_HARDWARE)
@@ -138,10 +249,7 @@ IMG_CHAR *SysCreateVersionString(IMG_CPU_PHYADDR sRegRegion)
        ui32SGXRevision = 0;
 #endif
 
-       if (SysAcquireData(&psSysData) != PVRSRV_OK)
-       {
-               return IMG_NULL;
-       }
+       SysAcquireData(&psSysData);
 
        i32Count = OSSNPrintf(aszVersionString, 100,
                                                  "SGX revision = %u.%u.%u",
@@ -190,7 +298,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR,"SysInitialise: Failed to setup env structure"));
-               SysDeinitialise(gpsSysData);
+               (IMG_VOID)SysDeinitialise(gpsSysData);
                gpsSysData = IMG_NULL;
                return eError;
        }
@@ -212,7 +320,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR,"SysInitialise: Failed in SysInitialiseCommon"));
-               SysDeinitialise(gpsSysData);
+               (IMG_VOID)SysDeinitialise(gpsSysData);
                gpsSysData = IMG_NULL;
                return eError;
        }
@@ -231,6 +339,11 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        psTimingInfo = &gsSGXDeviceMap.sTimingInfo;
        psTimingInfo->ui32CoreClockSpeed = SYS_SGX_CLOCK_SPEED;
        psTimingInfo->ui32HWRecoveryFreq = SYS_SGX_HWRECOVERY_TIMEOUT_FREQ; 
+#if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
+       psTimingInfo->bEnableActivePM = IMG_TRUE;
+#else  
+       psTimingInfo->bEnableActivePM = IMG_FALSE;
+#endif 
        psTimingInfo->ui32ActivePowManLatencyms = SYS_SGX_ACTIVE_POWER_LATENCY_MS; 
        psTimingInfo->ui32uKernelFreq = SYS_SGX_PDS_TIMER_FREQ; 
 #endif
@@ -247,12 +360,33 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR,"SysInitialise: Failed to locate devices"));
-               SysDeinitialise(gpsSysData);
+               (IMG_VOID)SysDeinitialise(gpsSysData);
                gpsSysData = IMG_NULL;
                return eError;
        }
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_LOCATEDEV);
 
+#if defined(SGX_OCP_REGS_ENABLED)
+       {
+               IMG_SYS_PHYADDR sOCPRegsSysPBase;
+               IMG_CPU_PHYADDR sOCPRegsCpuPBase;
+
+               sOCPRegsSysPBase.uiAddr = SYS_OMAP3430_OCP_REGS_SYS_PHYS_BASE;
+               sOCPRegsCpuPBase                = SysSysPAddrToCpuPAddr(sOCPRegsSysPBase);
+
+               gpvOCPRegsLinAddr               = OSMapPhysToLin(sOCPRegsCpuPBase,
+                                                                                                SYS_OMAP3430_OCP_REGS_SIZE,
+                                                                                                PVRSRV_HAP_UNCACHED|PVRSRV_HAP_KERNEL_ONLY,
+                                                                                                IMG_NULL);
+
+               if (gpvOCPRegsLinAddr == IMG_NULL)
+               {
+                       PVR_DPF((PVR_DBG_ERROR,"SysInitialise: Failed to map OCP registers"));
+                       return PVRSRV_ERROR_BAD_MAPPING;
+               }
+       }
+#endif
+
        
 
 
@@ -261,7 +395,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR,"SysInitialise: Failed to register device!"));
-               SysDeinitialise(gpsSysData);
+               (IMG_VOID)SysDeinitialise(gpsSysData);
                gpsSysData = IMG_NULL;
                return eError;
        }
@@ -314,31 +448,33 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        PDUMPINIT();
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_PDUMPINIT);
 
-       eError = EnableSystemClocks(gpsSysData);
+       eError = EnableSystemClocksWrap(gpsSysData);
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR,"SysInitialise: Failed to Enable system clocks (%d)", eError));
-               SysDeinitialise(gpsSysData);
+               (IMG_VOID)SysDeinitialise(gpsSysData);
                gpsSysData = IMG_NULL;
                return eError;
        }
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS);
 #if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
-       eError = EnableSGXClocks(gpsSysData);
+       eError = EnableSGXClocksWrap(gpsSysData);
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR,"SysInitialise: Failed to Enable SGX clocks (%d)", eError));
-               SysDeinitialise(gpsSysData);
+               (IMG_VOID)SysDeinitialise(gpsSysData);
                gpsSysData = IMG_NULL;
                return eError;
        }
 #endif 
 
+       dump_omap34xx_clocks();
+
        eError = PVRSRVInitialiseDevice(gui32SGXDeviceID);
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR,"SysInitialise: Failed to initialise device!"));
-               SysDeinitialise(gpsSysData);
+               (IMG_VOID)SysDeinitialise(gpsSysData);
                gpsSysData = IMG_NULL;
                return eError;
        }
@@ -358,11 +494,11 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
        PVRSRV_ERROR eError = PVRSRV_OK;
 
 #if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
-       eError = EnableSGXClocks(gpsSysData);
+       eError = EnableSGXClocksWrap(gpsSysData);
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR,"SysInitialise: Failed to Enable SGX clocks (%d)", eError));
-               SysDeinitialise(gpsSysData);
+               (IMG_VOID)SysDeinitialise(gpsSysData);
                gpsSysData = IMG_NULL;
                return eError;
        }
@@ -374,7 +510,7 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR,"SysFinalise: Failed to install MISR"));
-               SysDeinitialise(gpsSysData);
+               (IMG_VOID)SysDeinitialise(gpsSysData);
                gpsSysData = IMG_NULL;
                return eError;
        }
@@ -385,7 +521,7 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR,"SysFinalise: Failed to install ISR"));
-               SysDeinitialise(gpsSysData);
+               (IMG_VOID)SysDeinitialise(gpsSysData);
                gpsSysData = IMG_NULL;
                return eError;
        }
@@ -442,12 +578,19 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
        PVR_UNREFERENCED_PARAMETER(psSysData);
 #endif 
 
+#if defined(SGX_OCP_REGS_ENABLED)
+       OSUnMapPhysToLin(gpvOCPRegsLinAddr,
+                                        SYS_OMAP3430_OCP_REGS_SIZE,
+                                        PVRSRV_HAP_UNCACHED|PVRSRV_HAP_KERNEL_ONLY,
+                                        IMG_NULL);
+#endif
+
        if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_INITDEV))
        {
 #if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
                PVR_ASSERT(SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS));
                
-               eError = EnableSGXClocks(gpsSysData);
+               eError = EnableSGXClocksWrap(gpsSysData);
                if (eError != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: EnableSGXClocks failed"));
@@ -685,10 +828,10 @@ PVRSRV_ERROR SysSystemPostPowerState(PVRSRV_SYS_POWER_STATE eNewPowerState)
 
                if (SYS_SPECIFIC_DATA_TEST(&gsSysSpecificData, SYS_SPECIFIC_DATA_PM_DISABLE_SYSCLOCKS))
                {
-                       eError = EnableSystemClocks(gpsSysData);
+                       eError = EnableSystemClocksWrap(gpsSysData);
                        if (eError != PVRSRV_OK)
                        {
-                               PVR_DPF((PVR_DBG_ERROR,"SysSystemPostPowerState: EnableSystemClocks failed (%d)", eError));
+                               PVR_DPF((PVR_DBG_ERROR,"SysSystemPostPowerState: EnableSystemClocksWrap failed (%d)", eError));
                                return eError;
                        }
                        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS);
@@ -739,7 +882,6 @@ PVRSRV_ERROR SysDevicePrePowerState(IMG_UINT32                              ui32DeviceIndex,
        {
                PVR_DPF((PVR_DBG_MESSAGE, "SysDevicePrePowerState: SGX Entering state D3"));
                DisableSGXClocks(gpsSysData);
-               PVRSRVSetDCState(DC_STATE_SUSPEND_COMMANDS);
        }
 #else  
        PVR_UNREFERENCED_PARAMETER(eNewPowerState );
@@ -765,8 +907,7 @@ PVRSRV_ERROR SysDevicePostPowerState(IMG_UINT32                             ui32DeviceIndex,
        if (eCurrentPowerState == PVRSRV_DEV_POWER_STATE_OFF)
        {
                PVR_DPF((PVR_DBG_MESSAGE, "SysDevicePostPowerState: SGX Leaving state D3"));
-               PVRSRVSetDCState(DC_STATE_RESUME_COMMANDS);
-               eError = EnableSGXClocks(gpsSysData);
+               eError = EnableSGXClocksWrap(gpsSysData);
        }
 #else  
        PVR_UNREFERENCED_PARAMETER(eCurrentPowerState);
index 1055404..6c60d17 100644 (file)
 
 #include "syscommon.h"
 
-#define VS_PRODUCT_NAME        "OMAP3430"
+#define VS_PRODUCT_NAME        "OMAP3"
+
+#if defined(SGX530) && (SGX_CORE_REV == 125)
+#define SYS_SGX_CLOCK_SPEED            200000000
+#else
+#define SYS_SGX_CLOCK_SPEED            110666666
+#endif
 
-#define SYS_SGX_CLOCK_SPEED    110666666
 #define SYS_SGX_HWRECOVERY_TIMEOUT_FREQ                (100)   
-#define SYS_SGX_PDS_TIMER_FREQ                 (1000)  
-#define SYS_SGX_ACTIVE_POWER_LATENCY_MS                (1)
+#define SYS_SGX_PDS_TIMER_FREQ                         (1000)  
 
+#if !defined(SYS_SGX_ACTIVE_POWER_LATENCY_MS)
+#define SYS_SGX_ACTIVE_POWER_LATENCY_MS                (1)
+#endif
 
-#define        SYS_OMAP3430_VDD2_OPP3_SGX_CLOCK_SPEED SYS_SGX_CLOCK_SPEED
-#define SYS_OMAP3430_VDD2_OPP2_SGX_CLOCK_SPEED (SYS_SGX_CLOCK_SPEED / 2)
 
 #define SYS_OMAP3430_SGX_REGS_SYS_PHYS_BASE  0x50000000
 #define SYS_OMAP3430_SGX_REGS_SIZE           0x10000
index 89622fe..ac23c6a 100644 (file)
 #define MAX_HW_TIME_US                         (500000)
 #define WAIT_TRY_COUNT                         (10000)
 
-typedef enum _SYS_DEVICE_TYPE_
-{
-       SYS_DEVICE_SGX                                          = 0,
-
-       SYS_DEVICE_FORCE_I16                            = 0x7fff
-
-} SYS_DEVICE_TYPE;
-
 #define SYS_DEVICE_COUNT 3 
 
-#define PRM_REG32(offset)        (offset)
-#define CM_REG32(offset)         (offset)
-
-#define CM_FCLKEN_SGX          CM_REG32(0xB00)
-#define                CM_FCLKEN_SGX_EN_3D                                     0x00000002
-
-#define CM_ICLKEN_SGX          CM_REG32(0xB10)
-#define                CM_ICLKEN_SGX_EN_SGX                            0x00000001
-
-#define CM_IDLEST_SGX          CM_REG32(0xB20)
-#define                CM_IDLEST_SGX_ST_SGX                            0x00000001
-
-#define CM_CLKSEL_SGX          CM_REG32(0xB40)
-#define                CM_CLKSEL_SGX_MASK                                      0x0000000f
-#define                CM_CLKSEL_SGX_L3DIV3                            0x00000000
-#define                CM_CLKSEL_SGX_L3DIV4                            0x00000001
-#define                CM_CLKSEL_SGX_L3DIV6                            0x00000002
-#define                CM_CLKSEL_SGX_96M                                       0x00000003
-
-#define CM_SLEEPDEP_SGX                CM_REG32(0xB44)
-#define CM_CLKSTCTRL_SGX       CM_REG32(0xB48)
-#define        CM_CLKSTCTRL_SGX_AUTOSTATE                      0x00008001
-
-#define CM_CLKSTST_SGX         CM_REG32(0xB4C)
-#define        CM_CLKSTST_SGX_STATUS_VALID                     0x00000001
-
-#define RM_RSTST_SGX           PRM_REG32(0xB58)
-#define        RM_RSTST_SGX_RST_MASK                           0x0000000F
-#define        RM_RSTST_SGX_COREDOMAINWKUP_RST         0x00000008
-#define        RM_RSTST_SGX_DOMAINWKUP_RST                     0x00000004
-#define        RM_RSTST_SGX_GLOBALWARM_RST                     0x00000002
-#define        RM_RSTST_SGX_GLOBALCOLD_RST                     0x00000001
-
-#define PM_WKDEP_SGX           PRM_REG32(0xBC8)
-#define        PM_WKDEP_SGX_EN_WAKEUP                          0x00000010
-#define        PM_WKDEP_SGX_EN_MPU                                     0x00000002
-#define        PM_WKDEP_SGX_EN_CORE                            0x00000001
-
-#define PM_PWSTCTRL_SGX                PRM_REG32(0xBE0)
-#define                PM_PWSTCTRL_SGX_POWERSTATE_MASK         0x00000003
-#define                        PM_PWSTCTRL_SGX_OFF                             0x00000000
-#define                        PM_PWSTCTRL_SGX_RETENTION               0x00000001
-#define                        PM_PWSTCTRL_SGX_ON                              0x00000003
-
-#define PM_PWSTST_SGX          PRM_REG32(0xBE4)
-#define                PM_PWSTST_SGX_INTRANSITION                      0x00100000
-#define                PM_PWSTST_SGX_CLKACTIVITY                       0x00080000
-#define                PM_PWSTST_SGX_POWERSTATE_MASK           0x00000003
-#define                        PM_PWSTST_SGX_OFF                               0x00000003
-#define                        PM_PWSTST_SGX_RETENTION                 0x00000001
-#define                        PM_PWSTST_SGX_ON                                0x00000000
-
-#define PM_PREPWSTST_SGX       PRM_REG32(0xBE8)
-
-
 #endif 
index b97c0e2..92b77e2 100644 (file)
@@ -92,7 +92,7 @@ typedef struct _SYS_SPECIFIC_DATA_TAG_
        IMG_BOOL        bSysClocksOneTimeInit;
        IMG_BOOL        bConstraintNotificationsEnabled;
        atomic_t        sSGXClocksEnabled;
-       spinlock_t      sPowerLock;
+       struct mutex    sPowerLock;
        atomic_t        sPowerLockCPU;
        spinlock_t      sNotifyLock;
        atomic_t        sNotifyLockCPU;
@@ -102,7 +102,7 @@ typedef struct _SYS_SPECIFIC_DATA_TAG_
        struct clk      *psSGX_FCK;
        struct clk      *psSGX_ICK;
        struct clk      *psMPU_CK;
-#if defined(DEBUG) || defined(TIMING)
+#if defined(DEBUG_PVR) || defined(TIMING)
        struct clk      *psGPT11_FCK;
        struct clk      *psGPT11_ICK;
 #endif
index 618da6e..f3fb317 100644 (file)
 #include <linux/hardirq.h>
 #include <linux/spinlock.h>
 #include <asm/bug.h>
+#include <linux/platform_device.h>
 
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31))
 #include <linux/semaphore.h>
-#include <linux/smp.h>
-#include <asm-generic/resource.h>
-#include <plat/omap-pm.h>
-#else
 
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26))
-#include <linux/semaphore.h>
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
+#include <plat/omap-pm.h>
 #else
-#include <asm/semaphore.h>
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22))
-#include <asm/arch/resource.h>
-#endif
-#endif
+#include <mach/resource.h>
+#include <mach/omap-pm.h>
 #endif
 
 #include "sgxdefs.h"
 #undef SYS_SGX_CLOCK_SPEED
 #define SYS_SGX_CLOCK_SPEED sgx_clock_speed
 static int sgx_clock_speed;
+extern struct platform_device *gpsPVRLDMDev;
 
-#if !defined(PDUMP) && !defined(NO_HARDWARE)
-static IMG_BOOL PowerLockWrappedOnCPU(SYS_SPECIFIC_DATA *psSysSpecData)
+static PVRSRV_ERROR ForceMaxSGXClocks(SYS_SPECIFIC_DATA *psSysSpecData)
 {
-       IMG_INT iCPU;
-       IMG_BOOL bLocked = IMG_FALSE;
+       PVR_UNREFERENCED_PARAMETER(psSysSpecData);
 
-       if (!in_interrupt())
-       {
-               iCPU = get_cpu();
-               bLocked = (iCPU == atomic_read(&psSysSpecData->sPowerLockCPU));
+       /* Pin the memory bus bw to the highest value according to CORE_REV */
+#if 0
+#if defined(SGX530) && (SGX_CORE_REV == 125)
+       if(cpu_is_omap3630())
+               omap_pm_set_min_bus_tput(&gpsPVRLDMDev->dev, OCP_INITIATOR_AGENT, 800000);
+#else
+       omap_pm_set_min_bus_tput(&gpsPVRLDMDev->dev, OCP_INITIATOR_AGENT, 664000);
+#endif
+#endif
+       return PVRSRV_OK;
+}
 
-               put_cpu();
-       }
 
-       return bLocked;
+#if !defined(PDUMP) && !defined(NO_HARDWARE)
+static IMG_BOOL PowerLockWrappedOnCPU(SYS_SPECIFIC_DATA *psSysSpecData)
+{
+
+       PVR_UNREFERENCED_PARAMETER(psSysSpecData);
+       return IMG_TRUE;
 }
 
 static IMG_VOID PowerLockWrap(SYS_SPECIFIC_DATA *psSysSpecData)
 {
-       IMG_INT iCPU;
-
        if (!in_interrupt())
        {
-               
-               iCPU = get_cpu();
-
-               
-               PVR_ASSERT(iCPU != -1);
-
-               PVR_ASSERT(!PowerLockWrappedOnCPU(psSysSpecData));
-
-               spin_lock(&psSysSpecData->sPowerLock);
-
-               atomic_set(&psSysSpecData->sPowerLockCPU, iCPU);
+               BUG_ON(in_atomic());
+               mutex_lock(&psSysSpecData->sPowerLock);
        }
 }
 
@@ -110,94 +101,46 @@ static IMG_VOID PowerLockUnwrap(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        if (!in_interrupt())
        {
-               PVR_ASSERT(PowerLockWrappedOnCPU(psSysSpecData));
-
-               atomic_set(&psSysSpecData->sPowerLockCPU, -1);
-
-               spin_unlock(&psSysSpecData->sPowerLock);
-
-               put_cpu();
+               BUG_ON(in_atomic());
+               mutex_unlock(&psSysSpecData->sPowerLock);
        }
 }
 
-PVRSRV_ERROR SysPowerLockWrap(SYS_DATA *psSysData)
-{
-       SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
-
-       PowerLockWrap(psSysSpecData);
-
-       return PVRSRV_OK;
-}
+#else /* !defined(PDUMP) && !defined(NO_HARDWARE) */
 
-IMG_VOID SysPowerLockUnwrap(SYS_DATA *psSysData)
-{
-       SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
-
-       PowerLockUnwrap(psSysSpecData);
-}
-
-static IMG_BOOL NotifyLockedOnCPU(SYS_SPECIFIC_DATA *psSysSpecData)
+static IMG_BOOL PowerLockWrappedOnCPU(SYS_SPECIFIC_DATA *psSysSpecData)
 {
-       IMG_INT iCPU = get_cpu();
-       IMG_BOOL bLocked = (iCPU == atomic_read(&psSysSpecData->sNotifyLockCPU));
-
-       put_cpu();
-
-       return bLocked;
+       PVR_UNREFERENCED_PARAMETER(psSysSpecData);
+       return IMG_FALSE;
 }
 
-static IMG_VOID NotifyLock(SYS_SPECIFIC_DATA *psSysSpecData)
+static IMG_VOID PowerLockWrap(SYS_SPECIFIC_DATA *psSysSpecData)
 {
-       IMG_INT iCPU;
-
-       BUG_ON(in_interrupt());
-
-       
-       iCPU = get_cpu();
-
+       PVR_UNREFERENCED_PARAMETER(psSysSpecData);
        
-       PVR_ASSERT(iCPU != -1);
-
-       PVR_ASSERT(!NotifyLockedOnCPU(psSysSpecData));
-
-       spin_lock(&psSysSpecData->sNotifyLock);
-
-       atomic_set(&psSysSpecData->sNotifyLockCPU, iCPU);
-}
-
-static IMG_VOID NotifyUnlock(SYS_SPECIFIC_DATA *psSysSpecData)
-{
-       PVR_ASSERT(NotifyLockedOnCPU(psSysSpecData));
-
-       spin_unlock(&psSysSpecData->sNotifyLock);
-
-       atomic_set(&psSysSpecData->sNotifyLockCPU, -1);
-
-       put_cpu();
 }
-#else  
-static IMG_BOOL PowerLockWrappedOnCPU(SYS_SPECIFIC_DATA unref__ *psSysSpecData)
+static IMG_VOID PowerLockUnwrap(SYS_SPECIFIC_DATA *psSysSpecData)
 {
-       return IMG_FALSE;
-}
+       PVR_UNREFERENCED_PARAMETER(psSysSpecData);
+ }
+#endif /* !defined(PDUMP) && !defined(NO_HARDWARE) */
 
-static IMG_VOID PowerLockWrap(SYS_SPECIFIC_DATA unref__ *psSysSpecData)
+PVRSRV_ERROR SysPowerLockWrap(SYS_DATA *psSysData)
 {
-}
+       SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
 
-static IMG_VOID PowerLockUnwrap(SYS_SPECIFIC_DATA unref__ *psSysSpecData)
-{
-}
+       PowerLockWrap(psSysSpecData);
 
-PVRSRV_ERROR SysPowerLockWrap(SYS_DATA unref__ *psSysData)
-{
        return PVRSRV_OK;
 }
 
-IMG_VOID SysPowerLockUnwrap(SYS_DATA unref__ *psSysData)
+IMG_VOID SysPowerLockUnwrap(SYS_DATA *psSysData)
 {
+       SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
+
+       PowerLockUnwrap(psSysSpecData);
 }
-#endif 
 
 IMG_BOOL WrapSystemPowerChange(SYS_SPECIFIC_DATA *psSysSpecData)
 {
@@ -251,175 +194,24 @@ IMG_VOID SysGetSGXTimingInformation(SGX_TIMING_INFORMATION *psTimingInfo)
        psTimingInfo->ui32CoreClockSpeed = rate;
        psTimingInfo->ui32HWRecoveryFreq = scale_prop_to_SGX_clock(SYS_SGX_HWRECOVERY_TIMEOUT_FREQ, rate);
        psTimingInfo->ui32uKernelFreq = scale_prop_to_SGX_clock(SYS_SGX_PDS_TIMER_FREQ, rate); 
-       psTimingInfo->ui32ActivePowManLatencyms = SYS_SGX_ACTIVE_POWER_LATENCY_MS; 
-}
-
-#if defined(CONSTRAINT_NOTIFICATIONS)
-#if !defined(SGX_DYNAMIC_TIMING_INFO)
-#error "SGX_DYNAMIC_TIMING_INFO must be defined for this platform"
-#endif
-
-static struct constraint_id cnstr_id_vdd2 = {
-       .type = RES_OPP_CO,
-       .data = (IMG_VOID *)"vdd2_opp"
-};
-
-#if !defined(PDUMP) && !defined(NO_HARDWARE)
-static inline IMG_BOOL ConstraintNotificationsEnabled(SYS_SPECIFIC_DATA *psSysSpecData)
-{
-       return (atomic_read(&psSysSpecData->sSGXClocksEnabled) != 0) && psSysSpecData->bSGXInitComplete && psSysSpecData->bConstraintNotificationsEnabled;
-
-}
-
-static IMG_INT VDD2PostFunc(struct notifier_block *n, IMG_UINT32 event, IMG_VOID *ptr)
-{
-       PVR_UNREFERENCED_PARAMETER(n);
-       PVR_UNREFERENCED_PARAMETER(event);
-       PVR_UNREFERENCED_PARAMETER(ptr);
-
-       if (in_interrupt())
-       {
-               PVR_DPF((PVR_DBG_ERROR, "%s Called in interrupt context.  Ignoring.", __FUNCTION__));
-               return 0;
-       }
-
-       
-       if (!NotifyLockedOnCPU(gpsSysSpecificData))
-       {
-               return 0;
-       }
-
-#if defined(DEBUG)
-       if (ConstraintNotificationsEnabled(gpsSysSpecificData))
-       {
-               IMG_UINT32 rate;
-
-               rate = clk_get_rate(gpsSysSpecificData->psSGX_FCK);
-
-               PVR_ASSERT(rate != 0);
-
-               PVR_DPF((PVR_DBG_MESSAGE, "%s: SGX clock rate: %dMHz", __FUNCTION__, HZ_TO_MHZ(rate)));
-       }
+#if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
+       psTimingInfo->bEnableActivePM = IMG_TRUE;
+#else  
+       psTimingInfo->bEnableActivePM = IMG_FALSE;
 #endif
-       if (gpsSysSpecificData->bCallVDD2PostFunc)
-       {
-               PVRSRVDevicePostClockSpeedChange(gpsSysSpecificData->psSGXDevNode->sDevId.ui32DeviceIndex, IMG_TRUE, IMG_NULL);
-
-               gpsSysSpecificData->bCallVDD2PostFunc = IMG_FALSE;
-       }
-       else
-       {
-               if (ConstraintNotificationsEnabled(gpsSysSpecificData))
-               {
-                       PVR_TRACE(("%s: Not calling PVR clock speed notification functions", __FUNCTION__));
-               }
-       }
-
-       NotifyUnlock(gpsSysSpecificData);
-
-       return 0;
-}
-
-static IMG_INT VDD2PreFunc(struct notifier_block *n, IMG_UINT32 event, IMG_VOID *ptr)
-{
-       PVR_UNREFERENCED_PARAMETER(n);
-       PVR_UNREFERENCED_PARAMETER(event);
-       PVR_UNREFERENCED_PARAMETER(ptr);
-
-       if (in_interrupt())
-       {
-               PVR_DPF((PVR_DBG_WARNING, "%s Called in interrupt context.  Ignoring.", __FUNCTION__));
-               return 0;
-       }
-
-       if (PowerLockWrappedOnCPU(gpsSysSpecificData))
-       {
-               PVR_DPF((PVR_DBG_WARNING, "%s Called from within a power transition.  Ignoring.", __FUNCTION__));
-               return 0;
-       }
-
-       NotifyLock(gpsSysSpecificData);
-
-       PVR_ASSERT(!gpsSysSpecificData->bCallVDD2PostFunc);
-
-       if (ConstraintNotificationsEnabled(gpsSysSpecificData))
-       {
-               PVRSRV_ERROR eError;
-
-               eError = PVRSRVDevicePreClockSpeedChange(gpsSysSpecificData->psSGXDevNode->sDevId.ui32DeviceIndex, IMG_TRUE, IMG_NULL);
-
-               gpsSysSpecificData->bCallVDD2PostFunc = (eError == PVRSRV_OK);
-
-       }
-
-       return 0;
-}
-
-static struct notifier_block sVDD2Pre = {
-       VDD2PreFunc,
-        NULL
-};
-
-static struct notifier_block sVDD2Post = {
-       VDD2PostFunc,
-        NULL
-};
-
-static IMG_VOID RegisterConstraintNotifications(IMG_VOID)
-{
-       PVR_TRACE(("Registering constraint notifications"));
-
-       PVR_ASSERT(!gpsSysSpecificData->bConstraintNotificationsEnabled);
-
-       constraint_register_pre_notification(gpsSysSpecificData->pVdd2Handle, &sVDD2Pre,
-                                               max_vdd2_opp+1);
-
-       constraint_register_post_notification(gpsSysSpecificData->pVdd2Handle, &sVDD2Post,
-                                               max_vdd2_opp+1);
-
-       
-       NotifyLock(gpsSysSpecificData);
-       gpsSysSpecificData->bConstraintNotificationsEnabled = IMG_TRUE;
-       NotifyUnlock(gpsSysSpecificData);
-
-       PVR_TRACE(("VDD2 constraint notifications registered"));
-}
-
-static IMG_VOID UnRegisterConstraintNotifications(IMG_VOID)
-{
-       PVR_TRACE(("Unregistering constraint notifications"));
-
-       
-       NotifyLock(gpsSysSpecificData);
-       gpsSysSpecificData->bConstraintNotificationsEnabled = IMG_FALSE;
-       NotifyUnlock(gpsSysSpecificData);
-
-       
-       constraint_unregister_pre_notification(gpsSysSpecificData->pVdd2Handle, &sVDD2Pre,
-                                               max_vdd2_opp+1);
-
-       constraint_unregister_post_notification(gpsSysSpecificData->pVdd2Handle, &sVDD2Post,
-                                               max_vdd2_opp+1);
-}
-#else
-static IMG_VOID RegisterConstraintNotifications(IMG_VOID)
-{
-}
-
-static IMG_VOID UnRegisterConstraintNotifications(IMG_VOID)
-{
+       psTimingInfo->ui32ActivePowManLatencyms = SYS_SGX_ACTIVE_POWER_LATENCY_MS;
 }
-#endif 
-#endif 
 
 PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
 {
 #if !defined(NO_HARDWARE)
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
+
+#if 1
        long lNewRate;
+#endif
        IMG_INT res;
 
-       
        if (atomic_read(&psSysSpecData->sSGXClocksEnabled) != 0)
        {
                return PVRSRV_OK;
@@ -427,7 +219,7 @@ PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
 
        PVR_DPF((PVR_DBG_MESSAGE, "EnableSGXClocks: Enabling SGX Clocks"));
 
-#if defined(DEBUG)
+#if defined(DEBUG_PVR)
        {
                
                IMG_UINT32 rate = clk_get_rate(psSysSpecData->psMPU_CK);
@@ -451,34 +243,39 @@ PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
                return PVRSRV_ERROR_GENERIC;
        }
 
-       lNewRate = clk_round_rate(psSysSpecData->psSGX_FCK, SYS_SGX_CLOCK_SPEED + ONE_MHZ);
-       if (lNewRate <= 0)
-       {
-               PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Couldn't round SGX functional clock rate"));
-               return PVRSRV_ERROR_GENERIC;
-       }
-
-       res = clk_set_rate(psSysSpecData->psSGX_FCK, lNewRate);
-       if (res < 0)
-       {
-               PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Couldn't set SGX function clock rate (%d)", res));
-               return PVRSRV_ERROR_GENERIC;
+#if 1
+       if(1){
+               lNewRate = clk_round_rate(psSysSpecData->psSGX_FCK, SYS_SGX_CLOCK_SPEED + ONE_MHZ);
+               if (lNewRate <= 0)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Couldn't round SGX functional clock rate"));
+                       return PVRSRV_ERROR_GENERIC;
+               }
+       
+               res = clk_set_rate(psSysSpecData->psSGX_FCK, lNewRate);
+               if (res < 0)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Couldn't set SGX function clock rate (%d)", res));
+                       return PVRSRV_ERROR_GENERIC;
+               }
+               {
+                       static int logged;
+                       if (!logged) {
+                               printk(KERN_INFO "SGX clock rate: %ld\n", lNewRate);
+                               logged = 1;
+                       }
+               }
        }
 
-#if defined(DEBUG)
-       {
-               
-               IMG_UINT32 rate = clk_get_rate(psSysSpecData->psSGX_FCK);
-               PVR_DPF((PVR_DBG_MESSAGE, "EnableSGXClocks: SGX Functional Clock is %dMhz", HZ_TO_MHZ(rate)));
-       }
 #endif
 
+       ForceMaxSGXClocks(psSysSpecData);
        
        atomic_set(&psSysSpecData->sSGXClocksEnabled, 1);
 
-#else  
+#else  /* !defined(NO_HARDWARE) */
        PVR_UNREFERENCED_PARAMETER(psSysData);
-#endif 
+#endif /* !defined(NO_HARDWARE) */
        return PVRSRV_OK;
 }
 
@@ -488,7 +285,6 @@ IMG_VOID DisableSGXClocks(SYS_DATA *psSysData)
 #if !defined(NO_HARDWARE)
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
 
-       
        if (atomic_read(&psSysSpecData->sSGXClocksEnabled) == 0)
        {
                return;
@@ -506,7 +302,9 @@ IMG_VOID DisableSGXClocks(SYS_DATA *psSysData)
                clk_disable(psSysSpecData->psSGX_FCK);
        }
 
-       
+#if 0
+       omap_pm_set_min_bus_tput(&gpsPVRLDMDev->dev, OCP_INITIATOR_AGENT, 0);
+#endif
        atomic_set(&psSysSpecData->sSGXClocksEnabled, 0);
 
 #else  
@@ -522,7 +320,7 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
        PVRSRV_ERROR eError;
        IMG_BOOL bPowerLock;
 
-#if defined(DEBUG) || defined(TIMING)
+#if defined(DEBUG_PVR) || defined(TIMING)
        IMG_INT rate;
        struct clk *sys_ck;
        IMG_CPU_PHYADDR     TimerRegPhysBase;
@@ -539,7 +337,7 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
 
                sgx_clock_speed = cpu_is_omap3630() ? 200000000 : 110666666;
 
-               spin_lock_init(&psSysSpecData->sPowerLock);
+               mutex_init(&psSysSpecData->sPowerLock);
                atomic_set(&psSysSpecData->sPowerLockCPU, -1);
                spin_lock_init(&psSysSpecData->sNotifyLock);
                atomic_set(&psSysSpecData->sNotifyLockCPU, -1);
@@ -570,7 +368,7 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
                }
                psSysSpecData->psSGX_ICK = psCLK;
 
-#if defined(DEBUG)
+#if defined(DEBUG_PVR)
                psCLK = clk_get(NULL, "mpu_ck");
                if (IS_ERR(psCLK))
                {
@@ -598,12 +396,8 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
                }
        }
 
-#if defined(CONSTRAINT_NOTIFICATIONS)
-
-       RegisterConstraintNotifications();
-#endif
 
-#if defined(DEBUG) || defined(TIMING)
+#if defined(DEBUG_PVR) || defined(TIMING)
        
        psCLK = clk_get(NULL, "gpt11_fck");
        if (IS_ERR(psCLK))
@@ -704,36 +498,17 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
                    PVRSRV_HAP_KERNEL_ONLY|PVRSRV_HAP_UNCACHED,
                    hTimerEnable);
 
-#endif 
-
-#if defined(PDUMP) && !defined(NO_HARDWARE) && (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22))
-       PVR_TRACE(("EnableSystemClocks: Setting SGX OPP constraint"));
-
-       
-       res = constraint_set(psSysSpecData->pVdd2Handle, max_vdd2_opp);
-       if (res != 0)
-       {
-               PVR_DPF((PVR_DBG_ERROR, "EnableSystemClocks: constraint_set failed (%d)", res));
-               goto ExitConstraintSetFailed;
-       }
 #endif
        eError = PVRSRV_OK;
        goto Exit;
 
-#if defined(PDUMP) && !defined(NO_HARDWARE) && (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22))
-ExitConstraintSetFailed:
-#endif
-#if defined(DEBUG) || defined(TIMING)
+#if defined(DEBUG_PVR) || defined(TIMING)
 ExitDisableGPT11ICK:
        clk_disable(psSysSpecData->psGPT11_ICK);
 ExitDisableGPT11FCK:
        clk_disable(psSysSpecData->psGPT11_FCK);
 ExitUnRegisterConstraintNotifications:
 #endif 
-#if defined(CONSTRAINT_NOTIFICATIONS)
-       UnRegisterConstraintNotifications();
-
-#endif
 ExitError:
        eError = PVRSRV_ERROR_GENERIC;
 Exit:
@@ -742,13 +517,6 @@ Exit:
                PowerLockWrap(psSysSpecData);
        }
 
-#if !defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
-       if (eError == PVRSRV_OK)
-       {
-               
-               eError = EnableSGXClocks(psSysData);
-       }
-#endif
        return eError;
 }
 
@@ -756,7 +524,7 @@ IMG_VOID DisableSystemClocks(SYS_DATA *psSysData)
 {
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
        IMG_BOOL bPowerLock;
-#if defined(DEBUG) || defined(TIMING)
+#if defined(DEBUG_PVR) || defined(TIMING)
        IMG_CPU_PHYADDR TimerRegPhysBase;
        IMG_HANDLE hTimerDisable;
        IMG_UINT32 *pui32TimerDisable;
@@ -774,11 +542,7 @@ IMG_VOID DisableSystemClocks(SYS_DATA *psSysData)
                PowerLockUnwrap(psSysSpecData);
        }
 
-#if defined(CONSTRAINT_NOTIFICATIONS)
-       UnRegisterConstraintNotifications();
-#endif
-
-#if defined(DEBUG) || defined(TIMING)
+#if defined(DEBUG_PVR) || defined(TIMING)
        
        TimerRegPhysBase.uiAddr = SYS_OMAP3430_GP11TIMER_ENABLE_SYS_PHYS_BASE;
        pui32TimerDisable = OSMapPhysToLin(TimerRegPhysBase,
@@ -804,7 +568,7 @@ IMG_VOID DisableSystemClocks(SYS_DATA *psSysData)
 
        clk_disable(psSysSpecData->psGPT11_FCK);
 
-#endif 
+#endif 
        if (bPowerLock)
        {
                PowerLockWrap(psSysSpecData);