adreno_device.c 7.3 KB

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