tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / gpu / arm / mali400 / r4p0_rel0 / platform / sc7710 / mali_platform.c
1 /*
2  * Copyright (C) 2010-2011 ARM Limited. All rights reserved.
3  * 
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  * 
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
9  */
10
11 /**
12  * @file mali_platform.c
13  * Platform specific Mali driver functions for a default platform
14  */
15
16 #include <linux/platform_device.h>
17 #include <linux/version.h>
18 #include <linux/delay.h>
19 #include <linux/clk.h>
20 #include <linux/pm.h>
21 #ifdef CONFIG_PM_RUNTIME
22 #include <linux/pm_runtime.h>
23 #endif
24 #include <asm/io.h>
25 #include <linux/mali/mali_utgard.h>
26          
27 #include <mach/globalregs.h>
28 #include "mali_kernel_common.h"
29 #include "mali_kernel_linux.h"
30 #include "base.h"
31
32 #define SPRD_MALI_PHYS 0xA0010000
33 #define IRQ_G3D_INT 25
34          
35 void mali_platform_device_release(struct device *device);
36 void mali_platform_utilization(unsigned int);
37
38 static struct resource mali_gpu_resources[] =
39 {
40         MALI_GPU_RESOURCES_MALI300_PMU(SPRD_MALI_PHYS, IRQ_G3D_INT, IRQ_G3D_INT,
41                                                                                                         IRQ_G3D_INT, IRQ_G3D_INT)
42 };
43
44 static struct mali_gpu_device_data mali_gpu_data =
45 {
46         .shared_mem_size = ARCH_MALI_MEMORY_SIZE_DEFAULT,
47         .utilization_interval = 300,
48         .utilization_handler = mali_platform_utilization,
49 };
50
51 static struct platform_device mali_gpu_device =
52 {
53         .name = MALI_GPU_NAME_UTGARD,
54         .id = 0,
55         .num_resources = ARRAY_SIZE(mali_gpu_resources),
56         .resource = mali_gpu_resources,
57         .dev.platform_data = &mali_gpu_data,
58         .dev.release = mali_platform_device_release,
59 };
60
61 static int g_gpu_clock_on = 0;
62 static int g_gpu_power_on = 0;
63
64 int mali_platform_device_register(void)
65 {
66         int err = -1;
67
68         MALI_DEBUG_PRINT(4, ("mali_platform_device_register() called\n"));
69
70         if(!g_gpu_power_on)
71         {
72                 g_gpu_power_on = 1;
73                 sprd_greg_clear_bits(REG_TYPE_GLOBAL, BIT(23), GR_G3D_PWR_CTRL);
74                 udelay(300);
75         }
76         if(!g_gpu_clock_on)
77         {
78                 g_gpu_clock_on = 1;
79                 sprd_greg_set_bits(REG_TYPE_AHB_GLOBAL, BIT(21), AHB_CTL0);
80         }
81
82         err = platform_device_register(&mali_gpu_device);
83         if (0 == err)
84         {
85 #ifdef CONFIG_PM_RUNTIME
86 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
87                 pm_runtime_set_autosuspend_delay(&(mali_gpu_device.dev), 50);
88                 pm_runtime_use_autosuspend(&(mali_gpu_device.dev));
89 #endif
90                 pm_runtime_enable(&(mali_gpu_device.dev));
91 #endif
92  
93                 return 0;
94         }
95
96         platform_device_unregister(&mali_gpu_device);
97  
98         if(g_gpu_clock_on)
99         {
100                 g_gpu_clock_on = 0;
101                 sprd_greg_clear_bits(REG_TYPE_AHB_GLOBAL, BIT(21), AHB_CTL0);
102         }
103         if(g_gpu_power_on)
104         {
105                 g_gpu_power_on = 0;
106                 sprd_greg_set_bits(REG_TYPE_GLOBAL, BIT(23), GR_G3D_PWR_CTRL);
107         }
108  
109         return err;
110 }
111  
112 void mali_platform_device_unregister(void)
113 {
114         MALI_DEBUG_PRINT(4, ("mali_platform_device_unregister() called\n"));
115
116         platform_device_unregister(&mali_gpu_device);
117  
118         if(g_gpu_clock_on)
119         {
120                 g_gpu_clock_on = 0;
121                 sprd_greg_clear_bits(REG_TYPE_AHB_GLOBAL, BIT(21), AHB_CTL0);
122         }
123         if(g_gpu_power_on)
124         {
125                 g_gpu_power_on = 0;
126                 sprd_greg_set_bits(REG_TYPE_GLOBAL, BIT(23), GR_G3D_PWR_CTRL);
127         }
128 }
129
130 void mali_platform_device_release(struct device *device)
131 {
132         MALI_DEBUG_PRINT(4, ("mali_platform_device_release() called\n"));
133 }
134
135 void mali_platform_power_mode_change(int power_mode)
136 {
137         switch(power_mode)
138         {
139         case 0://MALI_POWER_MODE_ON:
140                 sprd_greg_set_bits(REG_TYPE_AHB_GLOBAL, BIT(21), AHB_CTL0);
141                 break;
142         case 1://MALI_POWER_MODE_LIGHT_SLEEP:
143                 sprd_greg_clear_bits(REG_TYPE_AHB_GLOBAL, BIT(21), AHB_CTL0);
144                 break;
145         case 2://MALI_POWER_MODE_DEEP_SLEEP:
146                 sprd_greg_clear_bits(REG_TYPE_AHB_GLOBAL, BIT(21), AHB_CTL0);
147                 break;
148         };
149 }
150         
151 void mali_platform_utilization(u32 utilization)
152 {
153 }
154