2 * Copyright (C) 2013-2014 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
5 * Copyright (c) 2014 The Linux Foundation. All rights reserved.
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.
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
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/>.
20 #include "adreno_gpu.h"
22 #if defined(DOWNSTREAM_CONFIG_MSM_BUS_SCALING) && !defined(CONFIG_OF)
23 # include <mach/kgsl.h>
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);
32 struct msm_gpu
*a3xx_gpu_init(struct drm_device
*dev
);
33 struct msm_gpu
*a4xx_gpu_init(struct drm_device
*dev
);
35 static const struct adreno_info gpulist
[] = {
37 .rev
= ADRENO_REV(3, 0, 5, ANY_ID
),
40 .pm4fw
= "a300_pm4.fw",
41 .pfpfw
= "a300_pfp.fw",
43 .init
= a3xx_gpu_init
,
45 .rev
= ADRENO_REV(3, 0, 6, 0),
46 .revn
= 307, /* because a305c is revn==306 */
48 .pm4fw
= "a300_pm4.fw",
49 .pfpfw
= "a300_pfp.fw",
51 .init
= a3xx_gpu_init
,
53 .rev
= ADRENO_REV(3, 2, ANY_ID
, ANY_ID
),
56 .pm4fw
= "a300_pm4.fw",
57 .pfpfw
= "a300_pfp.fw",
59 .init
= a3xx_gpu_init
,
61 .rev
= ADRENO_REV(3, 3, 0, ANY_ID
),
64 .pm4fw
= "a330_pm4.fw",
65 .pfpfw
= "a330_pfp.fw",
67 .init
= a3xx_gpu_init
,
69 .rev
= ADRENO_REV(4, 2, 0, ANY_ID
),
72 .pm4fw
= "a420_pm4.fw",
73 .pfpfw
= "a420_pfp.fw",
74 .gmem
= (SZ_1M
+ SZ_512K
),
75 .init
= a4xx_gpu_init
,
79 MODULE_FIRMWARE("a300_pm4.fw");
80 MODULE_FIRMWARE("a300_pfp.fw");
81 MODULE_FIRMWARE("a330_pm4.fw");
82 MODULE_FIRMWARE("a330_pfp.fw");
83 MODULE_FIRMWARE("a420_pm4.fw");
84 MODULE_FIRMWARE("a420_pfp.fw");
86 static inline bool _rev_match(uint8_t entry
, uint8_t id
)
88 return (entry
== ANY_ID
) || (entry
== id
);
91 const struct adreno_info
*adreno_info(struct adreno_rev rev
)
96 for (i
= 0; i
< ARRAY_SIZE(gpulist
); i
++) {
97 const struct adreno_info
*info
= &gpulist
[i
];
98 if (_rev_match(info
->rev
.core
, rev
.core
) &&
99 _rev_match(info
->rev
.major
, rev
.major
) &&
100 _rev_match(info
->rev
.minor
, rev
.minor
) &&
101 _rev_match(info
->rev
.patchid
, rev
.patchid
))
108 struct msm_gpu
*adreno_load_gpu(struct drm_device
*dev
)
110 struct msm_drm_private
*priv
= dev
->dev_private
;
111 struct platform_device
*pdev
= priv
->gpu_pdev
;
112 struct adreno_platform_config
*config
;
113 struct adreno_rev rev
;
114 const struct adreno_info
*info
;
115 struct msm_gpu
*gpu
= NULL
;
118 dev_err(dev
->dev
, "no adreno device\n");
122 config
= pdev
->dev
.platform_data
;
124 info
= adreno_info(config
->rev
);
127 dev_warn(dev
->dev
, "Unknown GPU revision: %u.%u.%u.%u\n",
128 rev
.core
, rev
.major
, rev
.minor
, rev
.patchid
);
132 DBG("Found GPU: %u.%u.%u.%u", rev
.core
, rev
.major
,
133 rev
.minor
, rev
.patchid
);
135 gpu
= info
->init(dev
);
137 dev_warn(dev
->dev
, "failed to load adreno gpu\n");
144 mutex_lock(&dev
->struct_mutex
);
145 gpu
->funcs
->pm_resume(gpu
);
146 mutex_unlock(&dev
->struct_mutex
);
147 ret
= gpu
->funcs
->hw_init(gpu
);
149 dev_err(dev
->dev
, "gpu hw init failed: %d\n", ret
);
150 gpu
->funcs
->destroy(gpu
);
153 /* give inactive pm a chance to kick in: */
161 static void set_gpu_pdev(struct drm_device
*dev
,
162 struct platform_device
*pdev
)
164 struct msm_drm_private
*priv
= dev
->dev_private
;
165 priv
->gpu_pdev
= pdev
;
168 static int adreno_bind(struct device
*dev
, struct device
*master
, void *data
)
170 static struct adreno_platform_config config
= {};
172 struct device_node
*child
, *node
= dev
->of_node
;
176 ret
= of_property_read_u32(node
, "qcom,chipid", &val
);
178 dev_err(dev
, "could not find chipid: %d\n", ret
);
182 config
.rev
= ADRENO_REV((val
>> 24) & 0xff,
183 (val
>> 16) & 0xff, (val
>> 8) & 0xff, val
& 0xff);
185 /* find clock rates: */
186 config
.fast_rate
= 0;
187 config
.slow_rate
= ~0;
188 for_each_child_of_node(node
, child
) {
189 if (of_device_is_compatible(child
, "qcom,gpu-pwrlevels")) {
190 struct device_node
*pwrlvl
;
191 for_each_child_of_node(child
, pwrlvl
) {
192 ret
= of_property_read_u32(pwrlvl
, "qcom,gpu-freq", &val
);
194 dev_err(dev
, "could not find gpu-freq: %d\n", ret
);
197 config
.fast_rate
= max(config
.fast_rate
, val
);
198 config
.slow_rate
= min(config
.slow_rate
, val
);
203 if (!config
.fast_rate
) {
204 dev_err(dev
, "could not find clk rates\n");
209 struct kgsl_device_platform_data
*pdata
= dev
->platform_data
;
210 uint32_t version
= socinfo_get_version();
211 if (cpu_is_apq8064ab()) {
212 config
.fast_rate
= 450000000;
213 config
.slow_rate
= 27000000;
215 config
.rev
= ADRENO_REV(3, 2, 1, 0);
216 } else if (cpu_is_apq8064()) {
217 config
.fast_rate
= 400000000;
218 config
.slow_rate
= 27000000;
221 if (SOCINFO_VERSION_MAJOR(version
) == 2)
222 config
.rev
= ADRENO_REV(3, 2, 0, 2);
223 else if ((SOCINFO_VERSION_MAJOR(version
) == 1) &&
224 (SOCINFO_VERSION_MINOR(version
) == 1))
225 config
.rev
= ADRENO_REV(3, 2, 0, 1);
227 config
.rev
= ADRENO_REV(3, 2, 0, 0);
229 } else if (cpu_is_msm8960ab()) {
230 config
.fast_rate
= 400000000;
231 config
.slow_rate
= 320000000;
234 if (SOCINFO_VERSION_MINOR(version
) == 0)
235 config
.rev
= ADRENO_REV(3, 2, 1, 0);
237 config
.rev
= ADRENO_REV(3, 2, 1, 1);
239 } else if (cpu_is_msm8930()) {
240 config
.fast_rate
= 400000000;
241 config
.slow_rate
= 27000000;
244 if ((SOCINFO_VERSION_MAJOR(version
) == 1) &&
245 (SOCINFO_VERSION_MINOR(version
) == 2))
246 config
.rev
= ADRENO_REV(3, 0, 5, 2);
248 config
.rev
= ADRENO_REV(3, 0, 5, 0);
251 # ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING
252 config
.bus_scale_table
= pdata
->bus_scale_table
;
255 dev
->platform_data
= &config
;
256 set_gpu_pdev(dev_get_drvdata(master
), to_platform_device(dev
));
260 static void adreno_unbind(struct device
*dev
, struct device
*master
,
263 set_gpu_pdev(dev_get_drvdata(master
), NULL
);
266 static const struct component_ops a3xx_ops
= {
268 .unbind
= adreno_unbind
,
271 static int adreno_probe(struct platform_device
*pdev
)
273 return component_add(&pdev
->dev
, &a3xx_ops
);
276 static int adreno_remove(struct platform_device
*pdev
)
278 component_del(&pdev
->dev
, &a3xx_ops
);
282 static const struct of_device_id dt_match
[] = {
283 { .compatible
= "qcom,adreno-3xx" },
284 /* for backwards compat w/ downstream kgsl DT files: */
285 { .compatible
= "qcom,kgsl-3d0" },
289 static struct platform_driver adreno_driver
= {
290 .probe
= adreno_probe
,
291 .remove
= adreno_remove
,
294 .of_match_table
= dt_match
,
298 void __init
adreno_register(void)
300 platform_driver_register(&adreno_driver
);
303 void __exit
adreno_unregister(void)
305 platform_driver_unregister(&adreno_driver
);