1 /* -*- mode: c; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* vi: set ts=8 sw=8 sts=8: */
3 /*************************************************************************/ /*!
5 @Title PowerVR DRM platform driver
6 @Codingstyle LinuxKernel
7 @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
8 @License Dual MIT/GPLv2
10 The contents of this file are subject to the MIT license as set out below.
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
19 The above copyright notice and this permission notice shall be included in
20 all copies or substantial portions of the Software.
22 Alternatively, the contents of this file may be used under the terms of
23 the GNU General Public License Version 2 ("GPL") in which case the provisions
24 of GPL are applicable instead of those above.
26 If you wish to allow use of your version of this file only under the terms of
27 GPL, and not to allow others to use your version of this file under the terms
28 of the MIT license, indicate your decision by deleting the provisions above
29 and replace them with the notice and other provisions required by GPL as set
30 out in the file called "GPL-COPYING" included in this distribution. If you do
31 not delete the provisions above, a recipient may use your version of this file
32 under the terms of either the MIT license or GPL.
34 This License is also included in this distribution in the file called
37 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
38 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
39 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
40 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
41 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
42 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
43 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44 */ /**************************************************************************/
47 #include <linux/module.h>
48 #include <linux/platform_device.h>
49 #include <linux/version.h>
51 #include "module_common.h"
53 #include "pvrmodule.h"
55 #include "pvrversion.h" //add by zxl
57 #if defined(CONFIG_OF)
59 #include <linux/of_device.h>
62 struct platform_device *gpsPVRLDMDev=NULL;
64 static struct drm_driver pvr_drm_platform_driver;
66 #if defined(MODULE) && !defined(PVR_LDM_PLATFORM_PRE_REGISTERED)
68 * This is an arbitrary value. If it's changed then the 'num_devices' module
69 * parameter description should also be updated to match.
71 #define MAX_DEVICES 16
73 static unsigned int pvr_num_devices = 1;
74 static struct platform_device **pvr_devices;
76 #if defined(NO_HARDWARE)
77 static int pvr_num_devices_set(const char *val,
78 const struct kernel_param *param)
82 err = param_set_uint(val, param);
86 if (pvr_num_devices == 0 || pvr_num_devices > MAX_DEVICES)
92 static const struct kernel_param_ops pvr_num_devices_ops = {
93 .set = pvr_num_devices_set,
94 .get = param_get_uint,
97 module_param_cb(num_devices, &pvr_num_devices_ops, &pvr_num_devices,
98 S_IRUSR | S_IRGRP | S_IROTH);
99 MODULE_PARM_DESC(num_devices,
100 "Number of platform devices to register (default: 1 - max: 16)");
101 #endif /* defined(NO_HARDWARE) */
102 #endif /* defined(MODULE) && !defined(PVR_LDM_PLATFORM_PRE_REGISTERED) */
104 static int pvr_devices_register(void)
106 #if defined(MODULE) && !defined(PVR_LDM_PLATFORM_PRE_REGISTERED)
107 struct platform_device_info pvr_dev_info = {
108 .name = SYS_RGX_DEV_NAME,
110 #if defined(NO_HARDWARE)
111 /* Not all cores have 40 bit physical support, but this
112 * will work unless > 32 bit address is returned on those cores.
113 * In the future this will be fixed more correctly.
115 .dma_mask = DMA_BIT_MASK(40),
117 .dma_mask = DMA_BIT_MASK(32),
122 BUG_ON(pvr_num_devices == 0 || pvr_num_devices > MAX_DEVICES);
124 pvr_devices = kmalloc_array(pvr_num_devices, sizeof(*pvr_devices),
129 for (i = 0; i < pvr_num_devices; i++) {
130 pvr_devices[i] = platform_device_register_full(&pvr_dev_info);
131 if (IS_ERR(pvr_devices[i])) {
132 DRM_ERROR("unable to register device %u (err=%ld)\n",
133 i, PTR_ERR(pvr_devices[i]));
134 pvr_devices[i] = NULL;
138 #endif /* defined(MODULE) && !defined(PVR_LDM_PLATFORM_PRE_REGISTERED) */
143 static void pvr_devices_unregister(void)
145 #if defined(MODULE) && !defined(PVR_LDM_PLATFORM_PRE_REGISTERED)
148 BUG_ON(!pvr_devices);
150 for (i = 0; i < pvr_num_devices && pvr_devices[i]; i++)
151 platform_device_unregister(pvr_devices[i]);
155 #endif /* defined(MODULE) && !defined(PVR_LDM_PLATFORM_PRE_REGISTERED) */
158 static int pvr_probe(struct platform_device *pdev)
160 DRM_DEBUG_DRIVER("device %p\n", &pdev->dev);
162 //zxl:print gpu version on boot time
163 printk("PVR_K: sys.gpvr.version=%s\n",RKVERSION);
166 return drm_platform_init(&pvr_drm_platform_driver, pdev);
169 static int pvr_remove(struct platform_device *pdev)
171 struct drm_device *ddev = platform_get_drvdata(pdev);
173 DRM_DEBUG_DRIVER("device %p\n", &pdev->dev);
180 static void pvr_shutdown(struct platform_device *pdev)
182 struct drm_device *ddev = platform_get_drvdata(pdev);
184 DRM_DEBUG_DRIVER("device %p\n", &pdev->dev);
186 PVRSRVCommonDeviceShutdown(ddev->dev_private);
189 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
190 static const struct of_device_id pvr_of_ids[] = {
191 #if defined(SYS_RGX_OF_COMPATIBLE)
192 { .compatible = SYS_RGX_OF_COMPATIBLE, },
194 { .compatible = "arm,rogue-G6110", },
195 { .compatible = "arm,rk3368-gpu", },
199 MODULE_DEVICE_TABLE(of, pvr_of_ids);
202 static struct platform_device_id pvr_platform_ids[] = {
203 #if defined(SYS_RGX_DEV_NAME)
204 { SYS_RGX_DEV_NAME, 0 },
208 MODULE_DEVICE_TABLE(platform, pvr_platform_ids);
210 static struct platform_driver pvr_platform_driver = {
213 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
214 .of_match_table = of_match_ptr(pvr_of_ids),
218 .id_table = pvr_platform_ids,
220 .remove = pvr_remove,
221 .shutdown = pvr_shutdown,
224 static int __init pvr_init(void)
228 struct device_node *np;
230 DRM_DEBUG_DRIVER("\n");
232 for_each_compatible_node(np, NULL, "arm,rogue-G6110") {
236 printk("It doesn't contain Rogue gpu\n");
240 pvr_drm_platform_driver = pvr_drm_generic_driver;
241 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0)) && \
242 (LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0))
243 pvr_drm_platform_driver.set_busid = drm_platform_set_busid;
246 err = PVRSRVCommonDriverInit();
250 err = platform_driver_register(&pvr_platform_driver);
254 return pvr_devices_register();
257 static void __exit pvr_exit(void)
259 DRM_DEBUG_DRIVER("\n");
261 pvr_devices_unregister();
262 platform_driver_unregister(&pvr_platform_driver);
263 PVRSRVCommonDriverDeinit();
265 DRM_DEBUG_DRIVER("done\n");
268 late_initcall(pvr_init);
269 module_exit(pvr_exit);