fixes for bc_cat
[sgx.git] / pvr / omaplfb_linux.c
1 /**********************************************************************
2  *
3  * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful but, except
10  * as otherwise stated in writing, without any warranty; without even the
11  * implied warranty of merchantability or fitness for a particular purpose.
12  * See the GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * The full GNU General Public License is included in this distribution in
19  * the file called "COPYING".
20  *
21  * Contact Information:
22  * Imagination Technologies Ltd. <gpl-support@imgtec.com>
23  * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
24  *
25  ******************************************************************************/
26
27 #include <linux/version.h>
28 #include <linux/module.h>
29
30 #include <linux/pci.h>
31 #include <linux/uaccess.h>
32 #include <linux/slab.h>
33 #include <linux/errno.h>
34 #include <linux/interrupt.h>
35 #include <linux/fb.h>
36
37 #include <linux/platform_device.h>
38
39 #include <linux/io.h>
40
41 #include "img_defs.h"
42 #include "servicesext.h"
43 #include "kerneldisplay.h"
44 #include "omaplfb.h"
45 #include "pvrmodule.h"
46
47 #if   (LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0))
48 #include <video/omapdss.h>
49 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32))
50 #include <plat/display.h>
51 #else
52 #include <mach/display.h>
53 #endif
54
55 MODULE_SUPPORTED_DEVICE(DEVNAME);
56
57 #define unref__ __attribute__ ((unused))
58
59 void *OMAPLFBAllocKernelMem(u32 ui32Size)
60 {
61         return kmalloc(ui32Size, GFP_KERNEL);
62 }
63
64 void OMAPLFBFreeKernelMem(void *pvMem)
65 {
66         kfree(pvMem);
67 }
68
69 enum PVRSRV_ERROR OMAPLFBGetLibFuncAddr(char *szFunctionName,
70                IMG_BOOL (**ppfnFuncTable)(struct PVRSRV_DC_DISP2SRV_KMJTABLE *))
71 {
72         if (strcmp("PVRGetDisplayClassJTable", szFunctionName) != 0)
73                 return PVRSRV_ERROR_INVALID_PARAMS;
74
75         *ppfnFuncTable = PVRGetDisplayClassJTable;
76
77         return PVRSRV_OK;
78 }
79
80 static int OMAPLFBDriverSuspend_Entry(struct platform_device unref__ * pDevice,
81                                       pm_message_t unref__ state)
82 {
83         DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
84                       ": OMAPLFBDriverSuspend_Entry\n"));
85         return 0;
86 }
87
88 static int OMAPLFBDriverResume_Entry(struct platform_device unref__ * pDevice)
89 {
90         DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": OMAPLFBDriverResume_Entry\n"));
91         return 0;
92 }
93
94 static void OMAPLFBDriverShutdown_Entry(struct platform_device unref__ *
95                                         pDevice)
96 {
97         DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
98                       ": OMAPLFBDriverShutdown_Entry\n"));
99 }
100
101 static void OMAPLFBDeviceRelease_Entry(struct device unref__ * pDevice)
102 {
103         DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
104                       ": OMAPLFBDriverRelease_Entry\n"));
105 }
106
107 static struct platform_driver omaplfb_driver = {
108         .driver         = {
109                    .name = DRVNAME,
110         },
111         .suspend        = OMAPLFBDriverSuspend_Entry,
112         .resume         = OMAPLFBDriverResume_Entry,
113         .shutdown       = OMAPLFBDriverShutdown_Entry,
114 };
115
116 static struct platform_device omaplfb_device = {
117         .name           = DEVNAME,
118         .id             = -1,
119         .dev            = {
120                 .release = OMAPLFBDeviceRelease_Entry
121         }
122 };
123
124 static int __init OMAPLFB_Init(void)
125 {
126         int error;
127
128         if (OMAPLFBInit() != PVRSRV_OK) {
129                 printk(KERN_WARNING DRIVER_PREFIX
130                        ": OMAPLFB_Init: OMAPLFBInit failed\n");
131                 return -ENODEV;
132         }
133         error = platform_driver_register(&omaplfb_driver);
134         if (error) {
135                 printk(KERN_WARNING DRIVER_PREFIX
136                     ": OMAPLFB_Init: Unable to register platform driver (%d)\n",
137                        error);
138
139                 goto ExitDeinit;
140         }
141
142         error = platform_device_register(&omaplfb_device);
143         if (error) {
144                 printk(KERN_WARNING DRIVER_PREFIX
145                    ": OMAPLFB_Init:  Unable to register platform device (%d)\n",
146                        error);
147
148                 goto ExitDriverUnregister;
149         }
150
151         return 0;
152
153 ExitDriverUnregister:
154         platform_driver_unregister(&omaplfb_driver);
155
156 ExitDeinit:
157         if (OMAPLFBDeinit() != PVRSRV_OK)
158                 printk(KERN_WARNING DRIVER_PREFIX
159                        ": OMAPLFB_Init: OMAPLFBDeinit failed\n");
160
161         return -ENODEV;
162 }
163
164 static void __exit OMAPLFB_Cleanup(void)
165 {
166         platform_device_unregister(&omaplfb_device);
167         platform_driver_unregister(&omaplfb_driver);
168
169         if (OMAPLFBDeinit() != PVRSRV_OK)
170                 printk(KERN_WARNING DRIVER_PREFIX
171                        ": OMAPLFB_Cleanup: OMAPLFBDeinit failed\n");
172 }
173
174 module_init(OMAPLFB_Init);
175 module_exit(OMAPLFB_Cleanup);