fix out-of-tree build and new kernel support
[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
36 #include <linux/platform_device.h>
37
38 #include <linux/io.h>
39
40 #include "img_defs.h"
41 #include "servicesext.h"
42 #include "kerneldisplay.h"
43 #include "omaplfb.h"
44 #include "pvrmodule.h"
45
46 #if   (LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0))
47 #include <video/omapdss.h>
48 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32))
49 #include <plat/display.h>
50 #else
51 #include <mach/display.h>
52 #endif
53
54 MODULE_SUPPORTED_DEVICE(DEVNAME);
55
56 #define unref__ __attribute__ ((unused))
57
58 void *OMAPLFBAllocKernelMem(u32 ui32Size)
59 {
60         return kmalloc(ui32Size, GFP_KERNEL);
61 }
62
63 void OMAPLFBFreeKernelMem(void *pvMem)
64 {
65         kfree(pvMem);
66 }
67
68 enum PVRSRV_ERROR OMAPLFBGetLibFuncAddr(char *szFunctionName,
69                IMG_BOOL (**ppfnFuncTable)(struct PVRSRV_DC_DISP2SRV_KMJTABLE *))
70 {
71         if (strcmp("PVRGetDisplayClassJTable", szFunctionName) != 0)
72                 return PVRSRV_ERROR_INVALID_PARAMS;
73
74         *ppfnFuncTable = PVRGetDisplayClassJTable;
75
76         return PVRSRV_OK;
77 }
78
79 static int OMAPLFBDriverSuspend_Entry(struct platform_device unref__ * pDevice,
80                                       pm_message_t unref__ state)
81 {
82         DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
83                       ": OMAPLFBDriverSuspend_Entry\n"));
84         return 0;
85 }
86
87 static int OMAPLFBDriverResume_Entry(struct platform_device unref__ * pDevice)
88 {
89         DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": OMAPLFBDriverResume_Entry\n"));
90         return 0;
91 }
92
93 static void OMAPLFBDriverShutdown_Entry(struct platform_device unref__ *
94                                         pDevice)
95 {
96         DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
97                       ": OMAPLFBDriverShutdown_Entry\n"));
98 }
99
100 static void OMAPLFBDeviceRelease_Entry(struct device unref__ * pDevice)
101 {
102         DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
103                       ": OMAPLFBDriverRelease_Entry\n"));
104 }
105
106 static struct platform_driver omaplfb_driver = {
107         .driver         = {
108                    .name = DRVNAME,
109         },
110         .suspend        = OMAPLFBDriverSuspend_Entry,
111         .resume         = OMAPLFBDriverResume_Entry,
112         .shutdown       = OMAPLFBDriverShutdown_Entry,
113 };
114
115 static struct platform_device omaplfb_device = {
116         .name           = DEVNAME,
117         .id             = -1,
118         .dev            = {
119                 .release = OMAPLFBDeviceRelease_Entry
120         }
121 };
122
123 static int __init OMAPLFB_Init(void)
124 {
125         int error;
126
127         if (OMAPLFBInit() != PVRSRV_OK) {
128                 printk(KERN_WARNING DRIVER_PREFIX
129                        ": OMAPLFB_Init: OMAPLFBInit failed\n");
130                 return -ENODEV;
131         }
132         error = platform_driver_register(&omaplfb_driver);
133         if (error) {
134                 printk(KERN_WARNING DRIVER_PREFIX
135                     ": OMAPLFB_Init: Unable to register platform driver (%d)\n",
136                        error);
137
138                 goto ExitDeinit;
139         }
140
141         error = platform_device_register(&omaplfb_device);
142         if (error) {
143                 printk(KERN_WARNING DRIVER_PREFIX
144                    ": OMAPLFB_Init:  Unable to register platform device (%d)\n",
145                        error);
146
147                 goto ExitDriverUnregister;
148         }
149
150         return 0;
151
152 ExitDriverUnregister:
153         platform_driver_unregister(&omaplfb_driver);
154
155 ExitDeinit:
156         if (OMAPLFBDeinit() != PVRSRV_OK)
157                 printk(KERN_WARNING DRIVER_PREFIX
158                        ": OMAPLFB_Init: OMAPLFBDeinit failed\n");
159
160         return -ENODEV;
161 }
162
163 static void __exit OMAPLFB_Cleanup(void)
164 {
165         platform_device_unregister(&omaplfb_device);
166         platform_driver_unregister(&omaplfb_driver);
167
168         if (OMAPLFBDeinit() != PVRSRV_OK)
169                 printk(KERN_WARNING DRIVER_PREFIX
170                        ": OMAPLFB_Cleanup: OMAPLFBDeinit failed\n");
171 }
172
173 module_init(OMAPLFB_Init);
174 module_exit(OMAPLFB_Cleanup);