omap-iommu.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. #if defined(CONFIG_MPU_TESLA_IOMMU)
  72. {
  73. .base = OMAP4_MMU2_BASE,
  74. .irq = INT_44XX_DSP_MMU,
  75. .pdata = {
  76. .name = "tesla",
  77. .nr_tlb_entries = 32,
  78. .clk_name = "tesla_ick",
  79. .da_start = 0x0,
  80. .da_end = 0xFFFFF000,
  81. },
  82. },
  83. #endif
  84. };
  85. #define NR_OMAP4_IOMMU_DEVICES ARRAY_SIZE(omap4_devices)
  86. static struct platform_device *omap4_iommu_pdev[NR_OMAP4_IOMMU_DEVICES];
  87. #else
  88. #define omap4_devices NULL
  89. #define NR_OMAP4_IOMMU_DEVICES 0
  90. #define omap4_iommu_pdev NULL
  91. #endif
  92. static struct platform_device **omap_iommu_pdev;
  93. static int __init omap_iommu_init(void)
  94. {
  95. int i, err;
  96. struct resource res[] = {
  97. { .flags = IORESOURCE_MEM },
  98. { .flags = IORESOURCE_IRQ },
  99. };
  100. if (cpu_is_omap34xx()) {
  101. devices = omap3_devices;
  102. omap_iommu_pdev = omap3_iommu_pdev;
  103. num_iommu_devices = NR_OMAP3_IOMMU_DEVICES;
  104. } else if (cpu_is_omap44xx()) {
  105. devices = omap4_devices;
  106. omap_iommu_pdev = omap4_iommu_pdev;
  107. num_iommu_devices = NR_OMAP4_IOMMU_DEVICES;
  108. } else
  109. return -ENODEV;
  110. for (i = 0; i < num_iommu_devices; i++) {
  111. struct platform_device *pdev;
  112. const struct iommu_device *d = &devices[i];
  113. pdev = platform_device_alloc("omap-iommu", i);
  114. if (!pdev) {
  115. err = -ENOMEM;
  116. goto err_out;
  117. }
  118. res[0].start = d->base;
  119. res[0].end = d->base + MMU_REG_SIZE - 1;
  120. res[1].start = res[1].end = d->irq;
  121. err = platform_device_add_resources(pdev, res,
  122. ARRAY_SIZE(res));
  123. if (err)
  124. goto err_out;
  125. err = platform_device_add_data(pdev, &d->pdata,
  126. sizeof(d->pdata));
  127. if (err)
  128. goto err_out;
  129. err = platform_device_add(pdev);
  130. if (err)
  131. goto err_out;
  132. omap_iommu_pdev[i] = pdev;
  133. }
  134. return 0;
  135. err_out:
  136. while (i--)
  137. platform_device_put(omap_iommu_pdev[i]);
  138. return err;
  139. }
  140. /* must be ready before omap3isp is probed */
  141. subsys_initcall(omap_iommu_init);
  142. static void __exit omap_iommu_exit(void)
  143. {
  144. int i;
  145. for (i = 0; i < num_iommu_devices; i++)
  146. platform_device_unregister(omap_iommu_pdev[i]);
  147. }
  148. module_exit(omap_iommu_exit);
  149. MODULE_AUTHOR("Hiroshi DOYU");
  150. MODULE_DESCRIPTION("omap iommu: omap device registration");
  151. MODULE_LICENSE("GPL v2");