GNU Linux-libre 4.4.287-gnu1
[releases.git] / drivers / gpu / drm / msm / adreno / adreno_device.c
1 /*
2  * Copyright (C) 2013-2014 Red Hat
3  * Author: Rob Clark <robdclark@gmail.com>
4  *
5  * Copyright (c) 2014 The Linux Foundation. All rights reserved.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License version 2 as published by
9  * the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "adreno_gpu.h"
21
22 #if defined(DOWNSTREAM_CONFIG_MSM_BUS_SCALING) && !defined(CONFIG_OF)
23 #  include <mach/kgsl.h>
24 #endif
25
26 #define ANY_ID 0xff
27
28 bool hang_debug = false;
29 MODULE_PARM_DESC(hang_debug, "Dump registers when hang is detected (can be slow!)");
30 module_param_named(hang_debug, hang_debug, bool, 0600);
31
32 struct msm_gpu *a3xx_gpu_init(struct drm_device *dev);
33 struct msm_gpu *a4xx_gpu_init(struct drm_device *dev);
34
35 static const struct adreno_info gpulist[] = {
36         {
37                 .rev   = ADRENO_REV(3, 0, 5, ANY_ID),
38                 .revn  = 305,
39                 .name  = "A305",
40                 .pm4fw = "/*(DEBLOBBED)*/",
41                 .pfpfw = "/*(DEBLOBBED)*/",
42                 .gmem  = SZ_256K,
43                 .init  = a3xx_gpu_init,
44         }, {
45                 .rev   = ADRENO_REV(3, 0, 6, 0),
46                 .revn  = 307,        /* because a305c is revn==306 */
47                 .name  = "A306",
48                 .pm4fw = "/*(DEBLOBBED)*/",
49                 .pfpfw = "/*(DEBLOBBED)*/",
50                 .gmem  = SZ_128K,
51                 .init  = a3xx_gpu_init,
52         }, {
53                 .rev   = ADRENO_REV(3, 2, ANY_ID, ANY_ID),
54                 .revn  = 320,
55                 .name  = "A320",
56                 .pm4fw = "/*(DEBLOBBED)*/",
57                 .pfpfw = "/*(DEBLOBBED)*/",
58                 .gmem  = SZ_512K,
59                 .init  = a3xx_gpu_init,
60         }, {
61                 .rev   = ADRENO_REV(3, 3, 0, ANY_ID),
62                 .revn  = 330,
63                 .name  = "A330",
64                 .pm4fw = "/*(DEBLOBBED)*/",
65                 .pfpfw = "/*(DEBLOBBED)*/",
66                 .gmem  = SZ_1M,
67                 .init  = a3xx_gpu_init,
68         }, {
69                 .rev   = ADRENO_REV(4, 2, 0, ANY_ID),
70                 .revn  = 420,
71                 .name  = "A420",
72                 .pm4fw = "/*(DEBLOBBED)*/",
73                 .pfpfw = "/*(DEBLOBBED)*/",
74                 .gmem  = (SZ_1M + SZ_512K),
75                 .init  = a4xx_gpu_init,
76         },
77 };
78
79 /*(DEBLOBBED)*/
80
81 static inline bool _rev_match(uint8_t entry, uint8_t id)
82 {
83         return (entry == ANY_ID) || (entry == id);
84 }
85
86 const struct adreno_info *adreno_info(struct adreno_rev rev)
87 {
88         int i;
89
90         /* identify gpu: */
91         for (i = 0; i < ARRAY_SIZE(gpulist); i++) {
92                 const struct adreno_info *info = &gpulist[i];
93                 if (_rev_match(info->rev.core, rev.core) &&
94                                 _rev_match(info->rev.major, rev.major) &&
95                                 _rev_match(info->rev.minor, rev.minor) &&
96                                 _rev_match(info->rev.patchid, rev.patchid))
97                         return info;
98         }
99
100         return NULL;
101 }
102
103 struct msm_gpu *adreno_load_gpu(struct drm_device *dev)
104 {
105         struct msm_drm_private *priv = dev->dev_private;
106         struct platform_device *pdev = priv->gpu_pdev;
107         struct adreno_platform_config *config;
108         struct adreno_rev rev;
109         const struct adreno_info *info;
110         struct msm_gpu *gpu = NULL;
111
112         if (!pdev) {
113                 dev_err(dev->dev, "no adreno device\n");
114                 return NULL;
115         }
116
117         config = pdev->dev.platform_data;
118         rev = config->rev;
119         info = adreno_info(config->rev);
120
121         if (!info) {
122                 dev_warn(dev->dev, "Unknown GPU revision: %u.%u.%u.%u\n",
123                                 rev.core, rev.major, rev.minor, rev.patchid);
124                 return NULL;
125         }
126
127         DBG("Found GPU: %u.%u.%u.%u",  rev.core, rev.major,
128                         rev.minor, rev.patchid);
129
130         gpu = info->init(dev);
131         if (IS_ERR(gpu)) {
132                 dev_warn(dev->dev, "failed to load adreno gpu\n");
133                 gpu = NULL;
134                 /* not fatal */
135         }
136
137         if (gpu) {
138                 int ret;
139                 mutex_lock(&dev->struct_mutex);
140                 gpu->funcs->pm_resume(gpu);
141                 mutex_unlock(&dev->struct_mutex);
142                 ret = gpu->funcs->hw_init(gpu);
143                 if (ret) {
144                         dev_err(dev->dev, "gpu hw init failed: %d\n", ret);
145                         gpu->funcs->destroy(gpu);
146                         gpu = NULL;
147                 } else {
148                         /* give inactive pm a chance to kick in: */
149                         msm_gpu_retire(gpu);
150                 }
151         }
152
153         return gpu;
154 }
155
156 static void set_gpu_pdev(struct drm_device *dev,
157                 struct platform_device *pdev)
158 {
159         struct msm_drm_private *priv = dev->dev_private;
160         priv->gpu_pdev = pdev;
161 }
162
163 static int adreno_bind(struct device *dev, struct device *master, void *data)
164 {
165         static struct adreno_platform_config config = {};
166 #ifdef CONFIG_OF
167         struct device_node *child, *node = dev->of_node;
168         u32 val;
169         int ret;
170
171         ret = of_property_read_u32(node, "qcom,chipid", &val);
172         if (ret) {
173                 dev_err(dev, "could not find chipid: %d\n", ret);
174                 return ret;
175         }
176
177         config.rev = ADRENO_REV((val >> 24) & 0xff,
178                         (val >> 16) & 0xff, (val >> 8) & 0xff, val & 0xff);
179
180         /* find clock rates: */
181         config.fast_rate = 0;
182         config.slow_rate = ~0;
183         for_each_child_of_node(node, child) {
184                 if (of_device_is_compatible(child, "qcom,gpu-pwrlevels")) {
185                         struct device_node *pwrlvl;
186                         for_each_child_of_node(child, pwrlvl) {
187                                 ret = of_property_read_u32(pwrlvl, "qcom,gpu-freq", &val);
188                                 if (ret) {
189                                         dev_err(dev, "could not find gpu-freq: %d\n", ret);
190                                         return ret;
191                                 }
192                                 config.fast_rate = max(config.fast_rate, val);
193                                 config.slow_rate = min(config.slow_rate, val);
194                         }
195                 }
196         }
197
198         if (!config.fast_rate) {
199                 dev_err(dev, "could not find clk rates\n");
200                 return -ENXIO;
201         }
202
203 #else
204         struct kgsl_device_platform_data *pdata = dev->platform_data;
205         uint32_t version = socinfo_get_version();
206         if (cpu_is_apq8064ab()) {
207                 config.fast_rate = 450000000;
208                 config.slow_rate = 27000000;
209                 config.bus_freq  = 4;
210                 config.rev = ADRENO_REV(3, 2, 1, 0);
211         } else if (cpu_is_apq8064()) {
212                 config.fast_rate = 400000000;
213                 config.slow_rate = 27000000;
214                 config.bus_freq  = 4;
215
216                 if (SOCINFO_VERSION_MAJOR(version) == 2)
217                         config.rev = ADRENO_REV(3, 2, 0, 2);
218                 else if ((SOCINFO_VERSION_MAJOR(version) == 1) &&
219                                 (SOCINFO_VERSION_MINOR(version) == 1))
220                         config.rev = ADRENO_REV(3, 2, 0, 1);
221                 else
222                         config.rev = ADRENO_REV(3, 2, 0, 0);
223
224         } else if (cpu_is_msm8960ab()) {
225                 config.fast_rate = 400000000;
226                 config.slow_rate = 320000000;
227                 config.bus_freq  = 4;
228
229                 if (SOCINFO_VERSION_MINOR(version) == 0)
230                         config.rev = ADRENO_REV(3, 2, 1, 0);
231                 else
232                         config.rev = ADRENO_REV(3, 2, 1, 1);
233
234         } else if (cpu_is_msm8930()) {
235                 config.fast_rate = 400000000;
236                 config.slow_rate = 27000000;
237                 config.bus_freq  = 3;
238
239                 if ((SOCINFO_VERSION_MAJOR(version) == 1) &&
240                         (SOCINFO_VERSION_MINOR(version) == 2))
241                         config.rev = ADRENO_REV(3, 0, 5, 2);
242                 else
243                         config.rev = ADRENO_REV(3, 0, 5, 0);
244
245         }
246 #  ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING
247         config.bus_scale_table = pdata->bus_scale_table;
248 #  endif
249 #endif
250         dev->platform_data = &config;
251         set_gpu_pdev(dev_get_drvdata(master), to_platform_device(dev));
252         return 0;
253 }
254
255 static void adreno_unbind(struct device *dev, struct device *master,
256                 void *data)
257 {
258         set_gpu_pdev(dev_get_drvdata(master), NULL);
259 }
260
261 static const struct component_ops a3xx_ops = {
262                 .bind   = adreno_bind,
263                 .unbind = adreno_unbind,
264 };
265
266 static int adreno_probe(struct platform_device *pdev)
267 {
268         return component_add(&pdev->dev, &a3xx_ops);
269 }
270
271 static int adreno_remove(struct platform_device *pdev)
272 {
273         component_del(&pdev->dev, &a3xx_ops);
274         return 0;
275 }
276
277 static const struct of_device_id dt_match[] = {
278         { .compatible = "qcom,adreno-3xx" },
279         /* for backwards compat w/ downstream kgsl DT files: */
280         { .compatible = "qcom,kgsl-3d0" },
281         {}
282 };
283
284 static struct platform_driver adreno_driver = {
285         .probe = adreno_probe,
286         .remove = adreno_remove,
287         .driver = {
288                 .name = "adreno",
289                 .of_match_table = dt_match,
290         },
291 };
292
293 void __init adreno_register(void)
294 {
295         platform_driver_register(&adreno_driver);
296 }
297
298 void __exit adreno_unregister(void)
299 {
300         platform_driver_unregister(&adreno_driver);
301 }