ARM64: DTS: Add rk3399-firefly uart4 device, node as /dev/ttyS1
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / platform / juno_soc / mali_kbase_config_juno_soc.c
1 /*
2  *
3  * (C) COPYRIGHT 2011-2016 ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the
6  * GNU General Public License version 2 as published by the Free Software
7  * Foundation, and any use by you of this program is subject to the terms
8  * of such GNU licence.
9  *
10  * A copy of the licence is included with the program, and can also be obtained
11  * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12  * Boston, MA  02110-1301, USA.
13  *
14  */
15
16
17
18 #include <linux/ioport.h>
19 #include <linux/thermal.h>
20 #include <mali_kbase.h>
21 #include <mali_kbase_defs.h>
22 #include <mali_kbase_config.h>
23 #include <mali_kbase_smc.h>
24
25 /* Versatile Express (VE) Juno Development Platform */
26
27 #define HARD_RESET_AT_POWER_OFF 0
28
29 #ifndef CONFIG_OF
30 static struct kbase_io_resources io_resources = {
31         .job_irq_number = 65,
32         .mmu_irq_number = 66,
33         .gpu_irq_number = 64,
34         .io_memory_region = {
35                              .start = 0x2D000000,
36                              .end = 0x2D000000 + (4096 * 4) - 1}
37 };
38 #endif
39
40 static int pm_callback_power_on(struct kbase_device *kbdev)
41 {
42         /* Nothing is needed on VExpress, but we may have destroyed GPU state (if the below HARD_RESET code is active) */
43         return 1;
44 }
45
46 static void pm_callback_power_off(struct kbase_device *kbdev)
47 {
48 #if HARD_RESET_AT_POWER_OFF
49         /* Cause a GPU hard reset to test whether we have actually idled the GPU
50          * and that we properly reconfigure the GPU on power up.
51          * Usually this would be dangerous, but if the GPU is working correctly it should
52          * be completely safe as the GPU should not be active at this point.
53          * However this is disabled normally because it will most likely interfere with
54          * bus logging etc.
55          */
56         KBASE_TRACE_ADD(kbdev, CORE_GPU_HARD_RESET, NULL, NULL, 0u, 0);
57         kbase_os_reg_write(kbdev, GPU_CONTROL_REG(GPU_COMMAND), GPU_COMMAND_HARD_RESET);
58 #endif
59 }
60
61 struct kbase_pm_callback_conf pm_callbacks = {
62         .power_on_callback = pm_callback_power_on,
63         .power_off_callback = pm_callback_power_off,
64         .power_suspend_callback  = NULL,
65         .power_resume_callback = NULL
66 };
67
68 /*
69  * Juno Protected Mode integration
70  */
71
72 /* SMC Function Numbers */
73 #define JUNO_SMC_PROTECTED_ENTER_FUNC  0xff06
74 #define JUNO_SMC_PROTECTED_RESET_FUNC 0xff07
75
76 static int juno_protected_mode_enter(struct kbase_device *kbdev)
77 {
78         /* T62X in SoC detected */
79         u64 ret = kbase_invoke_smc(SMC_OEN_SIP,
80                 JUNO_SMC_PROTECTED_ENTER_FUNC, false,
81                 0, 0, 0);
82         return ret;
83 }
84
85 /* TODO: Remove these externs, reset should should be done by the firmware */
86 extern void kbase_reg_write(struct kbase_device *kbdev, u16 offset, u32 value,
87                                                 struct kbase_context *kctx);
88
89 extern u32 kbase_reg_read(struct kbase_device *kbdev, u16 offset,
90                                                 struct kbase_context *kctx);
91
92 static int juno_protected_mode_reset(struct kbase_device *kbdev)
93 {
94
95         /* T62X in SoC detected */
96         u64 ret = kbase_invoke_smc(SMC_OEN_SIP,
97                 JUNO_SMC_PROTECTED_RESET_FUNC, false,
98                 0, 0, 0);
99
100         /* TODO: Remove this reset, it should be done by the firmware */
101         kbase_reg_write(kbdev, GPU_CONTROL_REG(GPU_COMMAND),
102                                                 GPU_COMMAND_HARD_RESET, NULL);
103
104         while ((kbase_reg_read(kbdev, GPU_CONTROL_REG(GPU_IRQ_RAWSTAT), NULL)
105                         & RESET_COMPLETED) != RESET_COMPLETED)
106                 ;
107
108         return ret;
109 }
110
111 static bool juno_protected_mode_supported(struct kbase_device *kbdev)
112 {
113         u32 gpu_id = kbdev->gpu_props.props.raw_props.gpu_id;
114
115         /*
116          * Protected mode is only supported for the built in GPU
117          * _and_ only if the right firmware is running.
118          *
119          * Given that at init time the GPU is not powered up the
120          * juno_protected_mode_reset function can't be used as
121          * is needs to access GPU registers.
122          * However, although we don't want the GPU to boot into
123          * protected mode we know a GPU reset will be done after
124          * this function is called so although we set the GPU to
125          * protected mode it will exit protected mode before the
126          * driver is ready to run work.
127          */
128         if (gpu_id == GPU_ID_MAKE(GPU_ID_PI_T62X, 0, 1, 0) &&
129                         (kbdev->reg_start == 0x2d000000))
130                 return juno_protected_mode_enter(kbdev) == 0;
131
132         return false;
133 }
134
135 struct kbase_protected_ops juno_protected_ops = {
136         .protected_mode_enter = juno_protected_mode_enter,
137         .protected_mode_reset = juno_protected_mode_reset,
138         .protected_mode_supported = juno_protected_mode_supported,
139 };
140
141 static struct kbase_platform_config versatile_platform_config = {
142 #ifndef CONFIG_OF
143         .io_resources = &io_resources
144 #endif
145 };
146
147 struct kbase_platform_config *kbase_get_platform_config(void)
148 {
149         return &versatile_platform_config;
150 }
151
152 int kbase_platform_early_init(void)
153 {
154         /* Nothing needed at this stage */
155         return 0;
156 }