dev.c 5.8 KB

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