dev.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. #include <linux/dma-mapping.h>
  26. #define CREATE_TRACE_POINTS
  27. #include <trace/events/host1x.h>
  28. #include "bus.h"
  29. #include "dev.h"
  30. #include "intr.h"
  31. #include "channel.h"
  32. #include "debug.h"
  33. #include "hw/host1x01.h"
  34. #include "hw/host1x02.h"
  35. #include "hw/host1x04.h"
  36. #include "hw/host1x05.h"
  37. void host1x_sync_writel(struct host1x *host1x, u32 v, u32 r)
  38. {
  39. void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
  40. writel(v, sync_regs + r);
  41. }
  42. u32 host1x_sync_readl(struct host1x *host1x, u32 r)
  43. {
  44. void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
  45. return readl(sync_regs + r);
  46. }
  47. void host1x_ch_writel(struct host1x_channel *ch, u32 v, u32 r)
  48. {
  49. writel(v, ch->regs + r);
  50. }
  51. u32 host1x_ch_readl(struct host1x_channel *ch, u32 r)
  52. {
  53. return readl(ch->regs + r);
  54. }
  55. static const struct host1x_info host1x01_info = {
  56. .nb_channels = 8,
  57. .nb_pts = 32,
  58. .nb_mlocks = 16,
  59. .nb_bases = 8,
  60. .init = host1x01_init,
  61. .sync_offset = 0x3000,
  62. .dma_mask = DMA_BIT_MASK(32),
  63. };
  64. static const struct host1x_info host1x02_info = {
  65. .nb_channels = 9,
  66. .nb_pts = 32,
  67. .nb_mlocks = 16,
  68. .nb_bases = 12,
  69. .init = host1x02_init,
  70. .sync_offset = 0x3000,
  71. .dma_mask = DMA_BIT_MASK(32),
  72. };
  73. static const struct host1x_info host1x04_info = {
  74. .nb_channels = 12,
  75. .nb_pts = 192,
  76. .nb_mlocks = 16,
  77. .nb_bases = 64,
  78. .init = host1x04_init,
  79. .sync_offset = 0x2100,
  80. .dma_mask = DMA_BIT_MASK(34),
  81. };
  82. static const struct host1x_info host1x05_info = {
  83. .nb_channels = 14,
  84. .nb_pts = 192,
  85. .nb_mlocks = 16,
  86. .nb_bases = 64,
  87. .init = host1x05_init,
  88. .sync_offset = 0x2100,
  89. .dma_mask = DMA_BIT_MASK(34),
  90. };
  91. static const struct of_device_id host1x_of_match[] = {
  92. { .compatible = "nvidia,tegra210-host1x", .data = &host1x05_info, },
  93. { .compatible = "nvidia,tegra124-host1x", .data = &host1x04_info, },
  94. { .compatible = "nvidia,tegra114-host1x", .data = &host1x02_info, },
  95. { .compatible = "nvidia,tegra30-host1x", .data = &host1x01_info, },
  96. { .compatible = "nvidia,tegra20-host1x", .data = &host1x01_info, },
  97. { },
  98. };
  99. MODULE_DEVICE_TABLE(of, host1x_of_match);
  100. static int host1x_probe(struct platform_device *pdev)
  101. {
  102. const struct of_device_id *id;
  103. struct host1x *host;
  104. struct resource *regs;
  105. int syncpt_irq;
  106. int err;
  107. id = of_match_device(host1x_of_match, &pdev->dev);
  108. if (!id)
  109. return -EINVAL;
  110. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  111. if (!regs) {
  112. dev_err(&pdev->dev, "failed to get registers\n");
  113. return -ENXIO;
  114. }
  115. syncpt_irq = platform_get_irq(pdev, 0);
  116. if (syncpt_irq < 0) {
  117. dev_err(&pdev->dev, "failed to get IRQ\n");
  118. return -ENXIO;
  119. }
  120. host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
  121. if (!host)
  122. return -ENOMEM;
  123. mutex_init(&host->devices_lock);
  124. INIT_LIST_HEAD(&host->devices);
  125. INIT_LIST_HEAD(&host->list);
  126. host->dev = &pdev->dev;
  127. host->info = id->data;
  128. /* set common host1x device data */
  129. platform_set_drvdata(pdev, host);
  130. host->regs = devm_ioremap_resource(&pdev->dev, regs);
  131. if (IS_ERR(host->regs))
  132. return PTR_ERR(host->regs);
  133. dma_set_mask_and_coherent(host->dev, host->info->dma_mask);
  134. if (host->info->init) {
  135. err = host->info->init(host);
  136. if (err)
  137. return err;
  138. }
  139. host->clk = devm_clk_get(&pdev->dev, NULL);
  140. if (IS_ERR(host->clk)) {
  141. dev_err(&pdev->dev, "failed to get clock\n");
  142. err = PTR_ERR(host->clk);
  143. return err;
  144. }
  145. err = host1x_channel_list_init(host);
  146. if (err) {
  147. dev_err(&pdev->dev, "failed to initialize channel list\n");
  148. return err;
  149. }
  150. err = clk_prepare_enable(host->clk);
  151. if (err < 0) {
  152. dev_err(&pdev->dev, "failed to enable clock\n");
  153. return err;
  154. }
  155. err = host1x_syncpt_init(host);
  156. if (err) {
  157. dev_err(&pdev->dev, "failed to initialize syncpts\n");
  158. goto fail_unprepare_disable;
  159. }
  160. err = host1x_intr_init(host, syncpt_irq);
  161. if (err) {
  162. dev_err(&pdev->dev, "failed to initialize interrupts\n");
  163. goto fail_deinit_syncpt;
  164. }
  165. host1x_debug_init(host);
  166. err = host1x_register(host);
  167. if (err < 0)
  168. goto fail_deinit_intr;
  169. return 0;
  170. fail_deinit_intr:
  171. host1x_intr_deinit(host);
  172. fail_deinit_syncpt:
  173. host1x_syncpt_deinit(host);
  174. fail_unprepare_disable:
  175. clk_disable_unprepare(host->clk);
  176. return err;
  177. }
  178. static int host1x_remove(struct platform_device *pdev)
  179. {
  180. struct host1x *host = platform_get_drvdata(pdev);
  181. host1x_unregister(host);
  182. host1x_intr_deinit(host);
  183. host1x_syncpt_deinit(host);
  184. clk_disable_unprepare(host->clk);
  185. return 0;
  186. }
  187. static struct platform_driver tegra_host1x_driver = {
  188. .driver = {
  189. .name = "tegra-host1x",
  190. .of_match_table = host1x_of_match,
  191. },
  192. .probe = host1x_probe,
  193. .remove = host1x_remove,
  194. };
  195. static struct platform_driver * const drivers[] = {
  196. &tegra_host1x_driver,
  197. &tegra_mipi_driver,
  198. };
  199. static int __init tegra_host1x_init(void)
  200. {
  201. int err;
  202. err = bus_register(&host1x_bus_type);
  203. if (err < 0)
  204. return err;
  205. err = platform_register_drivers(drivers, ARRAY_SIZE(drivers));
  206. if (err < 0)
  207. bus_unregister(&host1x_bus_type);
  208. return err;
  209. }
  210. module_init(tegra_host1x_init);
  211. static void __exit tegra_host1x_exit(void)
  212. {
  213. platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
  214. bus_unregister(&host1x_bus_type);
  215. }
  216. module_exit(tegra_host1x_exit);
  217. MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");
  218. MODULE_AUTHOR("Terje Bergstrom <tbergstrom@nvidia.com>");
  219. MODULE_DESCRIPTION("Host1x driver for Tegra products");
  220. MODULE_LICENSE("GPL");