dev.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Tegra host1x driver
  3. *
  4. * Copyright (c) 2010-2013, NVIDIA Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/module.h>
  19. #include <linux/list.h>
  20. #include <linux/slab.h>
  21. #include <linux/of.h>
  22. #include <linux/of_device.h>
  23. #include <linux/clk.h>
  24. #include <linux/io.h>
  25. #define CREATE_TRACE_POINTS
  26. #include <trace/events/host1x.h>
  27. #include "dev.h"
  28. #include "intr.h"
  29. #include "channel.h"
  30. #include "debug.h"
  31. #include "hw/host1x01.h"
  32. #include "host1x_client.h"
  33. void host1x_set_drm_data(struct device *dev, void *data)
  34. {
  35. struct host1x *host1x = dev_get_drvdata(dev);
  36. host1x->drm_data = data;
  37. }
  38. void *host1x_get_drm_data(struct device *dev)
  39. {
  40. struct host1x *host1x = dev_get_drvdata(dev);
  41. return host1x->drm_data;
  42. }
  43. void host1x_sync_writel(struct host1x *host1x, u32 v, u32 r)
  44. {
  45. void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
  46. writel(v, sync_regs + r);
  47. }
  48. u32 host1x_sync_readl(struct host1x *host1x, u32 r)
  49. {
  50. void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
  51. return readl(sync_regs + r);
  52. }
  53. void host1x_ch_writel(struct host1x_channel *ch, u32 v, u32 r)
  54. {
  55. writel(v, ch->regs + r);
  56. }
  57. u32 host1x_ch_readl(struct host1x_channel *ch, u32 r)
  58. {
  59. return readl(ch->regs + r);
  60. }
  61. static const struct host1x_info host1x01_info = {
  62. .nb_channels = 8,
  63. .nb_pts = 32,
  64. .nb_mlocks = 16,
  65. .nb_bases = 8,
  66. .init = host1x01_init,
  67. .sync_offset = 0x3000,
  68. };
  69. static struct of_device_id host1x_of_match[] = {
  70. { .compatible = "nvidia,tegra30-host1x", .data = &host1x01_info, },
  71. { .compatible = "nvidia,tegra20-host1x", .data = &host1x01_info, },
  72. { },
  73. };
  74. MODULE_DEVICE_TABLE(of, host1x_of_match);
  75. static int host1x_probe(struct platform_device *pdev)
  76. {
  77. const struct of_device_id *id;
  78. struct host1x *host;
  79. struct resource *regs;
  80. int syncpt_irq;
  81. int err;
  82. id = of_match_device(host1x_of_match, &pdev->dev);
  83. if (!id)
  84. return -EINVAL;
  85. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  86. if (!regs) {
  87. dev_err(&pdev->dev, "failed to get registers\n");
  88. return -ENXIO;
  89. }
  90. syncpt_irq = platform_get_irq(pdev, 0);
  91. if (syncpt_irq < 0) {
  92. dev_err(&pdev->dev, "failed to get IRQ\n");
  93. return -ENXIO;
  94. }
  95. host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
  96. if (!host)
  97. return -ENOMEM;
  98. host->dev = &pdev->dev;
  99. host->info = id->data;
  100. /* set common host1x device data */
  101. platform_set_drvdata(pdev, host);
  102. host->regs = devm_ioremap_resource(&pdev->dev, regs);
  103. if (IS_ERR(host->regs))
  104. return PTR_ERR(host->regs);
  105. if (host->info->init) {
  106. err = host->info->init(host);
  107. if (err)
  108. return err;
  109. }
  110. host->clk = devm_clk_get(&pdev->dev, NULL);
  111. if (IS_ERR(host->clk)) {
  112. dev_err(&pdev->dev, "failed to get clock\n");
  113. err = PTR_ERR(host->clk);
  114. return err;
  115. }
  116. err = host1x_channel_list_init(host);
  117. if (err) {
  118. dev_err(&pdev->dev, "failed to initialize channel list\n");
  119. return err;
  120. }
  121. err = clk_prepare_enable(host->clk);
  122. if (err < 0) {
  123. dev_err(&pdev->dev, "failed to enable clock\n");
  124. return err;
  125. }
  126. err = host1x_syncpt_init(host);
  127. if (err) {
  128. dev_err(&pdev->dev, "failed to initialize syncpts\n");
  129. return err;
  130. }
  131. err = host1x_intr_init(host, syncpt_irq);
  132. if (err) {
  133. dev_err(&pdev->dev, "failed to initialize interrupts\n");
  134. goto fail_deinit_syncpt;
  135. }
  136. host1x_debug_init(host);
  137. host1x_drm_alloc(pdev);
  138. return 0;
  139. fail_deinit_syncpt:
  140. host1x_syncpt_deinit(host);
  141. return err;
  142. }
  143. static int __exit host1x_remove(struct platform_device *pdev)
  144. {
  145. struct host1x *host = platform_get_drvdata(pdev);
  146. host1x_intr_deinit(host);
  147. host1x_syncpt_deinit(host);
  148. clk_disable_unprepare(host->clk);
  149. return 0;
  150. }
  151. static struct platform_driver tegra_host1x_driver = {
  152. .probe = host1x_probe,
  153. .remove = __exit_p(host1x_remove),
  154. .driver = {
  155. .owner = THIS_MODULE,
  156. .name = "tegra-host1x",
  157. .of_match_table = host1x_of_match,
  158. },
  159. };
  160. static int __init tegra_host1x_init(void)
  161. {
  162. int err;
  163. err = platform_driver_register(&tegra_host1x_driver);
  164. if (err < 0)
  165. return err;
  166. #ifdef CONFIG_DRM_TEGRA
  167. err = platform_driver_register(&tegra_dc_driver);
  168. if (err < 0)
  169. goto unregister_host1x;
  170. err = platform_driver_register(&tegra_hdmi_driver);
  171. if (err < 0)
  172. goto unregister_dc;
  173. err = platform_driver_register(&tegra_gr2d_driver);
  174. if (err < 0)
  175. goto unregister_hdmi;
  176. #endif
  177. return 0;
  178. #ifdef CONFIG_DRM_TEGRA
  179. unregister_hdmi:
  180. platform_driver_unregister(&tegra_hdmi_driver);
  181. unregister_dc:
  182. platform_driver_unregister(&tegra_dc_driver);
  183. unregister_host1x:
  184. platform_driver_unregister(&tegra_host1x_driver);
  185. return err;
  186. #endif
  187. }
  188. module_init(tegra_host1x_init);
  189. static void __exit tegra_host1x_exit(void)
  190. {
  191. #ifdef CONFIG_DRM_TEGRA
  192. platform_driver_unregister(&tegra_gr2d_driver);
  193. platform_driver_unregister(&tegra_hdmi_driver);
  194. platform_driver_unregister(&tegra_dc_driver);
  195. #endif
  196. platform_driver_unregister(&tegra_host1x_driver);
  197. }
  198. module_exit(tegra_host1x_exit);
  199. MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");
  200. MODULE_AUTHOR("Terje Bergstrom <tbergstrom@nvidia.com>");
  201. MODULE_DESCRIPTION("Host1x driver for Tegra products");
  202. MODULE_LICENSE("GPL");