@@ -45,43 +45,65 @@ static struct iommu_device devices[] = {
static struct platform_device *omap3_iommu_pdev[NR_IOMMU_DEVICES];
-static int __init omap3_iommu_init(void)
+static struct platform_device *omap_iommu_add(const char *name)
{
- int i, err;
-
- for (i = 0; i < NR_IOMMU_DEVICES; i++) {
- struct platform_device *pdev;
- const struct iommu_device *d = &devices[i];
- struct resource res[] = {
- { .flags = IORESOURCE_MEM },
- { .flags = IORESOURCE_IRQ },
- };
-
- pdev = platform_device_alloc("omap-iommu", i + 1);
- if (!pdev) {
- err = -ENOMEM;
- goto err_out;
+ struct platform_device *pdev;
+ const struct iommu_device *d = NULL;
+ struct resource res[] = {
+ { .flags = IORESOURCE_MEM },
+ { .flags = IORESOURCE_IRQ },
+ };
+ int err, i;
+
+ for (i = 0; i < ARRAY_SIZE(devices); i++)
+ if (strcmp(devices[i].pdata.name, name) == 0) {
+ d = &devices[i];
+ break;
}
- res[0].start = d->base;
- res[0].end = d->base + MMU_REG_SIZE - 1;
+ if (!d)
+ return NULL;
- res[1].start = d->irq;
+ pdev = platform_device_alloc("omap-iommu", i + 1);
+ if (!pdev)
+ return NULL;
- err = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
- if (err)
- goto err_out;
+ res[0].start = d->base;
+ res[0].end = d->base + MMU_REG_SIZE - 1;
- err = platform_device_add_data(pdev, &d->pdata, sizeof(d->pdata));
- if (err)
- goto err_out;
+ res[1].start = d->irq;
- err = platform_device_add(pdev);
- if (err)
- goto err_out;
+ err = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
+ if (err)
+ goto err_out;
+
+ err = platform_device_add_data(pdev, &d->pdata, sizeof(d->pdata));
+ if (err)
+ goto err_out;
+
+ err = platform_device_add(pdev);
+ if (err)
+ goto err_out;
+
+ return pdev;
+err_out:
+ platform_device_put(pdev);
+ return NULL;
+}
+
+static int __init omap3_iommu_init(void)
+{
+ struct platform_device *pdev;
+ int i, err;
+
+ for (i = 0; i < ARRAY_SIZE(devices); i++) {
+ pdev = omap_iommu_add(devices[i].pdata.name);
+ if (!pdev)
+ goto err_out;
omap3_iommu_pdev[i] = pdev;
}
+
return 0;
err_out:
In preparation for external registration. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> --- arch/arm/mach-omap2/omap3-iommu.c | 76 ++++++++++++++++++++++++------------- 1 files changed, 49 insertions(+), 27 deletions(-)