adreno_device.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. #include "adreno_gpu.h"
  20. #if defined(DOWNSTREAM_CONFIG_MSM_BUS_SCALING) && !defined(CONFIG_OF)
  21. # include <mach/kgsl.h>
  22. #endif
  23. #define ANY_ID 0xff
  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);
  27. struct msm_gpu *a3xx_gpu_init(struct drm_device *dev);
  28. struct msm_gpu *a4xx_gpu_init(struct drm_device *dev);
  29. static const struct adreno_info gpulist[] = {
  30. {
  31. .rev = ADRENO_REV(3, 0, 5, ANY_ID),
  32. .revn = 305,
  33. .name = "A305",
  34. .pm4fw = "a300_pm4.fw",
  35. .pfpfw = "a300_pfp.fw",
  36. .gmem = SZ_256K,
  37. .init = a3xx_gpu_init,
  38. }, {
  39. .rev = ADRENO_REV(3, 0, 6, 0),
  40. .revn = 307, /* because a305c is revn==306 */
  41. .name = "A306",
  42. .pm4fw = "a300_pm4.fw",
  43. .pfpfw = "a300_pfp.fw",
  44. .gmem = SZ_128K,
  45. .init = a3xx_gpu_init,
  46. }, {
  47. .rev = ADRENO_REV(3, 2, ANY_ID, ANY_ID),
  48. .revn = 320,
  49. .name = "A320",
  50. .pm4fw = "a300_pm4.fw",
  51. .pfpfw = "a300_pfp.fw",
  52. .gmem = SZ_512K,
  53. .init = a3xx_gpu_init,
  54. }, {
  55. .rev = ADRENO_REV(3, 3, 0, ANY_ID),
  56. .revn = 330,
  57. .name = "A330",
  58. .pm4fw = "a330_pm4.fw",
  59. .pfpfw = "a330_pfp.fw",
  60. .gmem = SZ_1M,
  61. .init = a3xx_gpu_init,
  62. }, {
  63. .rev = ADRENO_REV(4, 2, 0, ANY_ID),
  64. .revn = 420,
  65. .name = "A420",
  66. .pm4fw = "a420_pm4.fw",
  67. .pfpfw = "a420_pfp.fw",
  68. .gmem = (SZ_1M + SZ_512K),
  69. .init = a4xx_gpu_init,
  70. },
  71. };
  72. MODULE_FIRMWARE("a300_pm4.fw");
  73. MODULE_FIRMWARE("a300_pfp.fw");
  74. MODULE_FIRMWARE("a330_pm4.fw");
  75. MODULE_FIRMWARE("a330_pfp.fw");
  76. MODULE_FIRMWARE("a420_pm4.fw");
  77. MODULE_FIRMWARE("a420_pfp.fw");
  78. static inline bool _rev_match(uint8_t entry, uint8_t id)
  79. {
  80. return (entry == ANY_ID) || (entry == id);
  81. }
  82. const struct adreno_info *adreno_info(struct adreno_rev rev)
  83. {
  84. int i;
  85. /* identify gpu: */
  86. for (i = 0; i < ARRAY_SIZE(gpulist); i++) {
  87. const struct adreno_info *info = &gpulist[i];
  88. if (_rev_match(info->rev.core, rev.core) &&
  89. _rev_match(info->rev.major, rev.major) &&
  90. _rev_match(info->rev.minor, rev.minor) &&
  91. _rev_match(info->rev.patchid, rev.patchid))
  92. return info;
  93. }
  94. return NULL;
  95. }
  96. struct msm_gpu *adreno_load_gpu(struct drm_device *dev)
  97. {
  98. struct msm_drm_private *priv = dev->dev_private;
  99. struct platform_device *pdev = priv->gpu_pdev;
  100. struct adreno_platform_config *config;
  101. struct adreno_rev rev;
  102. const struct adreno_info *info;
  103. struct msm_gpu *gpu = NULL;
  104. if (!pdev) {
  105. dev_err(dev->dev, "no adreno device\n");
  106. return NULL;
  107. }
  108. config = pdev->dev.platform_data;
  109. rev = config->rev;
  110. info = adreno_info(config->rev);
  111. if (!info) {
  112. dev_warn(dev->dev, "Unknown GPU revision: %u.%u.%u.%u\n",
  113. rev.core, rev.major, rev.minor, rev.patchid);
  114. return NULL;
  115. }
  116. DBG("Found GPU: %u.%u.%u.%u", rev.core, rev.major,
  117. rev.minor, rev.patchid);
  118. gpu = info->init(dev);
  119. if (IS_ERR(gpu)) {
  120. dev_warn(dev->dev, "failed to load adreno gpu\n");
  121. gpu = NULL;
  122. /* not fatal */
  123. }
  124. if (gpu) {
  125. int ret;
  126. mutex_lock(&dev->struct_mutex);
  127. gpu->funcs->pm_resume(gpu);
  128. mutex_unlock(&dev->struct_mutex);
  129. ret = gpu->funcs->hw_init(gpu);
  130. if (ret) {
  131. dev_err(dev->dev, "gpu hw init failed: %d\n", ret);
  132. gpu->funcs->destroy(gpu);
  133. gpu = NULL;
  134. } else {
  135. /* give inactive pm a chance to kick in: */
  136. msm_gpu_retire(gpu);
  137. }
  138. }
  139. return gpu;
  140. }
  141. static void set_gpu_pdev(struct drm_device *dev,
  142. struct platform_device *pdev)
  143. {
  144. struct msm_drm_private *priv = dev->dev_private;
  145. priv->gpu_pdev = pdev;
  146. }
  147. static int adreno_bind(struct device *dev, struct device *master, void *data)
  148. {
  149. static struct adreno_platform_config config = {};
  150. #ifdef CONFIG_OF
  151. struct device_node *child, *node = dev->of_node;
  152. u32 val;
  153. int ret;
  154. ret = of_property_read_u32(node, "qcom,chipid", &val);
  155. if (ret) {
  156. dev_err(dev, "could not find chipid: %d\n", ret);
  157. return ret;
  158. }
  159. config.rev = ADRENO_REV((val >> 24) & 0xff,
  160. (val >> 16) & 0xff, (val >> 8) & 0xff, val & 0xff);
  161. /* find clock rates: */
  162. config.fast_rate = 0;
  163. config.slow_rate = ~0;
  164. for_each_child_of_node(node, child) {
  165. if (of_device_is_compatible(child, "qcom,gpu-pwrlevels")) {
  166. struct device_node *pwrlvl;
  167. for_each_child_of_node(child, pwrlvl) {
  168. ret = of_property_read_u32(pwrlvl, "qcom,gpu-freq", &val);
  169. if (ret) {
  170. dev_err(dev, "could not find gpu-freq: %d\n", ret);
  171. return ret;
  172. }
  173. config.fast_rate = max(config.fast_rate, val);
  174. config.slow_rate = min(config.slow_rate, val);
  175. }
  176. }
  177. }
  178. if (!config.fast_rate) {
  179. dev_err(dev, "could not find clk rates\n");
  180. return -ENXIO;
  181. }
  182. #else
  183. struct kgsl_device_platform_data *pdata = dev->platform_data;
  184. uint32_t version = socinfo_get_version();
  185. if (cpu_is_apq8064ab()) {
  186. config.fast_rate = 450000000;
  187. config.slow_rate = 27000000;
  188. config.bus_freq = 4;
  189. config.rev = ADRENO_REV(3, 2, 1, 0);
  190. } else if (cpu_is_apq8064()) {
  191. config.fast_rate = 400000000;
  192. config.slow_rate = 27000000;
  193. config.bus_freq = 4;
  194. if (SOCINFO_VERSION_MAJOR(version) == 2)
  195. config.rev = ADRENO_REV(3, 2, 0, 2);
  196. else if ((SOCINFO_VERSION_MAJOR(version) == 1) &&
  197. (SOCINFO_VERSION_MINOR(version) == 1))
  198. config.rev = ADRENO_REV(3, 2, 0, 1);
  199. else
  200. config.rev = ADRENO_REV(3, 2, 0, 0);
  201. } else if (cpu_is_msm8960ab()) {
  202. config.fast_rate = 400000000;
  203. config.slow_rate = 320000000;
  204. config.bus_freq = 4;
  205. if (SOCINFO_VERSION_MINOR(version) == 0)
  206. config.rev = ADRENO_REV(3, 2, 1, 0);
  207. else
  208. config.rev = ADRENO_REV(3, 2, 1, 1);
  209. } else if (cpu_is_msm8930()) {
  210. config.fast_rate = 400000000;
  211. config.slow_rate = 27000000;
  212. config.bus_freq = 3;
  213. if ((SOCINFO_VERSION_MAJOR(version) == 1) &&
  214. (SOCINFO_VERSION_MINOR(version) == 2))
  215. config.rev = ADRENO_REV(3, 0, 5, 2);
  216. else
  217. config.rev = ADRENO_REV(3, 0, 5, 0);
  218. }
  219. # ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING
  220. config.bus_scale_table = pdata->bus_scale_table;
  221. # endif
  222. #endif
  223. dev->platform_data = &config;
  224. set_gpu_pdev(dev_get_drvdata(master), to_platform_device(dev));
  225. return 0;
  226. }
  227. static void adreno_unbind(struct device *dev, struct device *master,
  228. void *data)
  229. {
  230. set_gpu_pdev(dev_get_drvdata(master), NULL);
  231. }
  232. static const struct component_ops a3xx_ops = {
  233. .bind = adreno_bind,
  234. .unbind = adreno_unbind,
  235. };
  236. static int adreno_probe(struct platform_device *pdev)
  237. {
  238. return component_add(&pdev->dev, &a3xx_ops);
  239. }
  240. static int adreno_remove(struct platform_device *pdev)
  241. {
  242. component_del(&pdev->dev, &a3xx_ops);
  243. return 0;
  244. }
  245. static const struct of_device_id dt_match[] = {
  246. { .compatible = "qcom,adreno-3xx" },
  247. /* for backwards compat w/ downstream kgsl DT files: */
  248. { .compatible = "qcom,kgsl-3d0" },
  249. {}
  250. };
  251. static struct platform_driver adreno_driver = {
  252. .probe = adreno_probe,
  253. .remove = adreno_remove,
  254. .driver = {
  255. .name = "adreno",
  256. .of_match_table = dt_match,
  257. },
  258. };
  259. void __init adreno_register(void)
  260. {
  261. platform_driver_register(&adreno_driver);
  262. }
  263. void __exit adreno_unregister(void)
  264. {
  265. platform_driver_unregister(&adreno_driver);
  266. }