dev.c 5.7 KB

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