adreno_device.c 6.9 KB

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