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"
24 bool hang_debug = false;
25 MODULE_PARM_DESC(hang_debug, "Dump registers when hang is detected (can be slow!)");
26 module_param_named(hang_debug, hang_debug, bool, 0600);
28 struct msm_gpu *a3xx_gpu_init(struct drm_device *dev);
29 struct msm_gpu *a4xx_gpu_init(struct drm_device *dev);
31 static const struct adreno_info gpulist[] = {
33 .rev = ADRENO_REV(3, 0, 5, ANY_ID),
36 .pm4fw = "/*(DEBLOBBED)*/",
37 .pfpfw = "/*(DEBLOBBED)*/",
39 .init = a3xx_gpu_init,
41 .rev = ADRENO_REV(3, 0, 6, 0),
42 .revn = 307, /* because a305c is revn==306 */
44 .pm4fw = "/*(DEBLOBBED)*/",
45 .pfpfw = "/*(DEBLOBBED)*/",
47 .init = a3xx_gpu_init,
49 .rev = ADRENO_REV(3, 2, ANY_ID, ANY_ID),
52 .pm4fw = "/*(DEBLOBBED)*/",
53 .pfpfw = "/*(DEBLOBBED)*/",
55 .init = a3xx_gpu_init,
57 .rev = ADRENO_REV(3, 3, 0, ANY_ID),
60 .pm4fw = "/*(DEBLOBBED)*/",
61 .pfpfw = "/*(DEBLOBBED)*/",
63 .init = a3xx_gpu_init,
65 .rev = ADRENO_REV(4, 2, 0, ANY_ID),
68 .pm4fw = "/*(DEBLOBBED)*/",
69 .pfpfw = "/*(DEBLOBBED)*/",
70 .gmem = (SZ_1M + SZ_512K),
71 .init = a4xx_gpu_init,
73 .rev = ADRENO_REV(4, 3, 0, ANY_ID),
76 .pm4fw = "/*(DEBLOBBED)*/",
77 .pfpfw = "/*(DEBLOBBED)*/",
78 .gmem = (SZ_1M + SZ_512K),
79 .init = a4xx_gpu_init,
85 static inline bool _rev_match(uint8_t entry, uint8_t id)
87 return (entry == ANY_ID) || (entry == id);
90 const struct adreno_info *adreno_info(struct adreno_rev rev)
95 for (i = 0; i < ARRAY_SIZE(gpulist); i++) {
96 const struct adreno_info *info = &gpulist[i];
97 if (_rev_match(info->rev.core, rev.core) &&
98 _rev_match(info->rev.major, rev.major) &&
99 _rev_match(info->rev.minor, rev.minor) &&
100 _rev_match(info->rev.patchid, rev.patchid))
107 struct msm_gpu *adreno_load_gpu(struct drm_device *dev)
109 struct msm_drm_private *priv = dev->dev_private;
110 struct platform_device *pdev = priv->gpu_pdev;
111 struct adreno_platform_config *config;
112 struct adreno_rev rev;
113 const struct adreno_info *info;
114 struct msm_gpu *gpu = NULL;
117 dev_err(dev->dev, "no adreno device\n");
121 config = pdev->dev.platform_data;
123 info = adreno_info(config->rev);
126 dev_warn(dev->dev, "Unknown GPU revision: %u.%u.%u.%u\n",
127 rev.core, rev.major, rev.minor, rev.patchid);
131 DBG("Found GPU: %u.%u.%u.%u", rev.core, rev.major,
132 rev.minor, rev.patchid);
134 gpu = info->init(dev);
136 dev_warn(dev->dev, "failed to load adreno gpu\n");
143 mutex_lock(&dev->struct_mutex);
144 gpu->funcs->pm_resume(gpu);
145 mutex_unlock(&dev->struct_mutex);
146 ret = gpu->funcs->hw_init(gpu);
148 dev_err(dev->dev, "gpu hw init failed: %d\n", ret);
149 gpu->funcs->destroy(gpu);
152 /* give inactive pm a chance to kick in: */
160 static void set_gpu_pdev(struct drm_device *dev,
161 struct platform_device *pdev)
163 struct msm_drm_private *priv = dev->dev_private;
164 priv->gpu_pdev = pdev;
167 static int adreno_bind(struct device *dev, struct device *master, void *data)
169 static struct adreno_platform_config config = {};
170 struct device_node *child, *node = dev->of_node;
174 ret = of_property_read_u32(node, "qcom,chipid", &val);
176 dev_err(dev, "could not find chipid: %d\n", ret);
180 config.rev = ADRENO_REV((val >> 24) & 0xff,
181 (val >> 16) & 0xff, (val >> 8) & 0xff, val & 0xff);
183 /* find clock rates: */
184 config.fast_rate = 0;
185 config.slow_rate = ~0;
186 for_each_child_of_node(node, child) {
187 if (of_device_is_compatible(child, "qcom,gpu-pwrlevels")) {
188 struct device_node *pwrlvl;
189 for_each_child_of_node(child, pwrlvl) {
190 ret = of_property_read_u32(pwrlvl, "qcom,gpu-freq", &val);
192 dev_err(dev, "could not find gpu-freq: %d\n", ret);
195 config.fast_rate = max(config.fast_rate, val);
196 config.slow_rate = min(config.slow_rate, val);
201 if (!config.fast_rate) {
202 dev_err(dev, "could not find clk rates\n");
206 dev->platform_data = &config;
207 set_gpu_pdev(dev_get_drvdata(master), to_platform_device(dev));
211 static void adreno_unbind(struct device *dev, struct device *master,
214 set_gpu_pdev(dev_get_drvdata(master), NULL);
217 static const struct component_ops a3xx_ops = {
219 .unbind = adreno_unbind,
222 static int adreno_probe(struct platform_device *pdev)
224 return component_add(&pdev->dev, &a3xx_ops);
227 static int adreno_remove(struct platform_device *pdev)
229 component_del(&pdev->dev, &a3xx_ops);
233 static const struct of_device_id dt_match[] = {
234 { .compatible = "qcom,adreno-3xx" },
235 /* for backwards compat w/ downstream kgsl DT files: */
236 { .compatible = "qcom,kgsl-3d0" },
240 static struct platform_driver adreno_driver = {
241 .probe = adreno_probe,
242 .remove = adreno_remove,
245 .of_match_table = dt_match,
249 void __init adreno_register(void)
251 platform_driver_register(&adreno_driver);
254 void __exit adreno_unregister(void)
256 platform_driver_unregister(&adreno_driver);