omap-iommu.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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/platform_device.h>
  13. #include <plat/iommu.h>
  14. #include <plat/irqs.h>
  15. struct iommu_device {
  16. resource_size_t base;
  17. int irq;
  18. struct iommu_platform_data pdata;
  19. struct resource res[2];
  20. };
  21. static struct iommu_device *devices;
  22. static int num_iommu_devices;
  23. #ifdef CONFIG_ARCH_OMAP3
  24. static struct iommu_device omap3_devices[] = {
  25. {
  26. .base = 0x480bd400,
  27. .irq = 24,
  28. .pdata = {
  29. .name = "isp",
  30. .nr_tlb_entries = 8,
  31. .clk_name = "cam_ick",
  32. },
  33. },
  34. #if defined(CONFIG_MPU_BRIDGE_IOMMU)
  35. {
  36. .base = 0x5d000000,
  37. .irq = 28,
  38. .pdata = {
  39. .name = "iva2",
  40. .nr_tlb_entries = 32,
  41. .clk_name = "iva2_ck",
  42. },
  43. },
  44. #endif
  45. };
  46. #define NR_OMAP3_IOMMU_DEVICES ARRAY_SIZE(omap3_devices)
  47. static struct platform_device *omap3_iommu_pdev[NR_OMAP3_IOMMU_DEVICES];
  48. #else
  49. #define omap3_devices NULL
  50. #define NR_OMAP3_IOMMU_DEVICES 0
  51. #define omap3_iommu_pdev NULL
  52. #endif
  53. #ifdef CONFIG_ARCH_OMAP4
  54. static struct iommu_device omap4_devices[] = {
  55. {
  56. .base = OMAP4_MMU1_BASE,
  57. .irq = OMAP44XX_IRQ_DUCATI_MMU,
  58. .pdata = {
  59. .name = "ducati",
  60. .nr_tlb_entries = 32,
  61. .clk_name = "ducati_ick",
  62. },
  63. },
  64. #if defined(CONFIG_MPU_TESLA_IOMMU)
  65. {
  66. .base = OMAP4_MMU2_BASE,
  67. .irq = INT_44XX_DSP_MMU,
  68. .pdata = {
  69. .name = "tesla",
  70. .nr_tlb_entries = 32,
  71. .clk_name = "tesla_ick",
  72. },
  73. },
  74. #endif
  75. };
  76. #define NR_OMAP4_IOMMU_DEVICES ARRAY_SIZE(omap4_devices)
  77. static struct platform_device *omap4_iommu_pdev[NR_OMAP4_IOMMU_DEVICES];
  78. #else
  79. #define omap4_devices NULL
  80. #define NR_OMAP4_IOMMU_DEVICES 0
  81. #define omap4_iommu_pdev NULL
  82. #endif
  83. static struct platform_device **omap_iommu_pdev;
  84. static int __init omap_iommu_init(void)
  85. {
  86. int i, err;
  87. struct resource res[] = {
  88. { .flags = IORESOURCE_MEM },
  89. { .flags = IORESOURCE_IRQ },
  90. };
  91. if (cpu_is_omap34xx()) {
  92. devices = omap3_devices;
  93. omap_iommu_pdev = omap3_iommu_pdev;
  94. num_iommu_devices = NR_OMAP3_IOMMU_DEVICES;
  95. } else if (cpu_is_omap44xx()) {
  96. devices = omap4_devices;
  97. omap_iommu_pdev = omap4_iommu_pdev;
  98. num_iommu_devices = NR_OMAP4_IOMMU_DEVICES;
  99. } else
  100. return -ENODEV;
  101. for (i = 0; i < num_iommu_devices; i++) {
  102. struct platform_device *pdev;
  103. const struct iommu_device *d = &devices[i];
  104. pdev = platform_device_alloc("omap-iommu", i);
  105. if (!pdev) {
  106. err = -ENOMEM;
  107. goto err_out;
  108. }
  109. res[0].start = d->base;
  110. res[0].end = d->base + MMU_REG_SIZE - 1;
  111. res[1].start = res[1].end = d->irq;
  112. err = platform_device_add_resources(pdev, res,
  113. ARRAY_SIZE(res));
  114. if (err)
  115. goto err_out;
  116. err = platform_device_add_data(pdev, &d->pdata,
  117. sizeof(d->pdata));
  118. if (err)
  119. goto err_out;
  120. err = platform_device_add(pdev);
  121. if (err)
  122. goto err_out;
  123. omap_iommu_pdev[i] = pdev;
  124. }
  125. return 0;
  126. err_out:
  127. while (i--)
  128. platform_device_put(omap_iommu_pdev[i]);
  129. return err;
  130. }
  131. module_init(omap_iommu_init);
  132. static void __exit omap_iommu_exit(void)
  133. {
  134. int i;
  135. for (i = 0; i < num_iommu_devices; i++)
  136. platform_device_unregister(omap_iommu_pdev[i]);
  137. }
  138. module_exit(omap_iommu_exit);
  139. MODULE_AUTHOR("Hiroshi DOYU");
  140. MODULE_DESCRIPTION("omap iommu: omap device registration");
  141. MODULE_LICENSE("GPL v2");