omap-iommu.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * omap iommu: omap device registration
  3. *
  4. * Copyright (C) 2008-2009 Nokia Corporation
  5. *
  6. * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <plat/iommu.h>
  15. #include <plat/irqs.h>
  16. struct iommu_device {
  17. resource_size_t base;
  18. int irq;
  19. struct iommu_platform_data pdata;
  20. struct resource res[2];
  21. };
  22. static struct iommu_device *devices;
  23. static int num_iommu_devices;
  24. #ifdef CONFIG_ARCH_OMAP3
  25. static struct iommu_device omap3_devices[] = {
  26. {
  27. .base = 0x480bd400,
  28. .irq = 24,
  29. .pdata = {
  30. .name = "isp",
  31. .nr_tlb_entries = 8,
  32. .clk_name = "cam_ick",
  33. .da_start = 0x0,
  34. .da_end = 0xFFFFF000,
  35. },
  36. },
  37. #if defined(CONFIG_OMAP_IOMMU_IVA2)
  38. {
  39. .base = 0x5d000000,
  40. .irq = 28,
  41. .pdata = {
  42. .name = "iva2",
  43. .nr_tlb_entries = 32,
  44. .clk_name = "iva2_ck",
  45. .da_start = 0x11000000,
  46. .da_end = 0xFFFFF000,
  47. },
  48. },
  49. #endif
  50. };
  51. #define NR_OMAP3_IOMMU_DEVICES ARRAY_SIZE(omap3_devices)
  52. static struct platform_device *omap3_iommu_pdev[NR_OMAP3_IOMMU_DEVICES];
  53. #else
  54. #define omap3_devices NULL
  55. #define NR_OMAP3_IOMMU_DEVICES 0
  56. #define omap3_iommu_pdev NULL
  57. #endif
  58. #ifdef CONFIG_ARCH_OMAP4
  59. static struct iommu_device omap4_devices[] = {
  60. {
  61. .base = OMAP4_MMU1_BASE,
  62. .irq = OMAP44XX_IRQ_DUCATI_MMU,
  63. .pdata = {
  64. .name = "ducati",
  65. .nr_tlb_entries = 32,
  66. .clk_name = "ipu_fck",
  67. .da_start = 0x0,
  68. .da_end = 0xFFFFF000,
  69. },
  70. },
  71. {
  72. .base = OMAP4_MMU2_BASE,
  73. .irq = OMAP44XX_IRQ_TESLA_MMU,
  74. .pdata = {
  75. .name = "tesla",
  76. .nr_tlb_entries = 32,
  77. .clk_name = "dsp_fck",
  78. .da_start = 0x0,
  79. .da_end = 0xFFFFF000,
  80. },
  81. },
  82. };
  83. #define NR_OMAP4_IOMMU_DEVICES ARRAY_SIZE(omap4_devices)
  84. static struct platform_device *omap4_iommu_pdev[NR_OMAP4_IOMMU_DEVICES];
  85. #else
  86. #define omap4_devices NULL
  87. #define NR_OMAP4_IOMMU_DEVICES 0
  88. #define omap4_iommu_pdev NULL
  89. #endif
  90. static struct platform_device **omap_iommu_pdev;
  91. static int __init omap_iommu_init(void)
  92. {
  93. int i, err;
  94. struct resource res[] = {
  95. { .flags = IORESOURCE_MEM },
  96. { .flags = IORESOURCE_IRQ },
  97. };
  98. if (cpu_is_omap34xx()) {
  99. devices = omap3_devices;
  100. omap_iommu_pdev = omap3_iommu_pdev;
  101. num_iommu_devices = NR_OMAP3_IOMMU_DEVICES;
  102. } else if (cpu_is_omap44xx()) {
  103. devices = omap4_devices;
  104. omap_iommu_pdev = omap4_iommu_pdev;
  105. num_iommu_devices = NR_OMAP4_IOMMU_DEVICES;
  106. } else
  107. return -ENODEV;
  108. for (i = 0; i < num_iommu_devices; i++) {
  109. struct platform_device *pdev;
  110. const struct iommu_device *d = &devices[i];
  111. pdev = platform_device_alloc("omap-iommu", i);
  112. if (!pdev) {
  113. err = -ENOMEM;
  114. goto err_out;
  115. }
  116. res[0].start = d->base;
  117. res[0].end = d->base + MMU_REG_SIZE - 1;
  118. res[1].start = res[1].end = d->irq;
  119. err = platform_device_add_resources(pdev, res,
  120. ARRAY_SIZE(res));
  121. if (err)
  122. goto err_out;
  123. err = platform_device_add_data(pdev, &d->pdata,
  124. sizeof(d->pdata));
  125. if (err)
  126. goto err_out;
  127. err = platform_device_add(pdev);
  128. if (err)
  129. goto err_out;
  130. omap_iommu_pdev[i] = pdev;
  131. }
  132. return 0;
  133. err_out:
  134. while (i--)
  135. platform_device_put(omap_iommu_pdev[i]);
  136. return err;
  137. }
  138. /* must be ready before omap3isp is probed */
  139. subsys_initcall(omap_iommu_init);
  140. static void __exit omap_iommu_exit(void)
  141. {
  142. int i;
  143. for (i = 0; i < num_iommu_devices; i++)
  144. platform_device_unregister(omap_iommu_pdev[i]);
  145. }
  146. module_exit(omap_iommu_exit);
  147. MODULE_AUTHOR("Hiroshi DOYU");
  148. MODULE_DESCRIPTION("omap iommu: omap device registration");
  149. MODULE_LICENSE("GPL v2");