Commit c26c68e3 authored by Russell King's avatar Russell King

[MTD] sa1100: split out sub-device init/destruction.

parent 310f172b
...@@ -913,92 +913,117 @@ static int __init sa1100_static_partitions(struct mtd_partition **parts) ...@@ -913,92 +913,117 @@ static int __init sa1100_static_partitions(struct mtd_partition **parts)
} }
#endif #endif
struct sa_info { struct sa_subdev_info {
unsigned long base; unsigned long base;
unsigned long size; unsigned long size;
int width; int width;
void (*set_vpp)(struct map_info *, int); void (*set_vpp)(struct map_info *, int);
char name[16]; char name[16];
struct map_info *map; struct map_info map;
struct mtd_info *mtd; struct mtd_info *mtd;
}; };
#define NR_SUBMTD 4 #define NR_SUBMTD 4
static struct sa_info info[NR_SUBMTD]; static struct sa_subdev_info info[NR_SUBMTD];
static int __init sa1100_setup_mtd(struct sa_info *sa, int nr, struct mtd_info **rmtd) static void sa1100_destroy_subdev(struct sa_subdev_info *subdev)
{ {
struct mtd_info *subdev[nr]; if (subdev->mtd)
struct map_info *maps; map_destroy(subdev->mtd);
int i, found = 0, ret = 0; if (subdev->map.virt)
iounmap(subdev->map.virt);
release_mem_region(subdev->base, subdev->size);
}
/* static int sa1100_probe_subdev(struct sa_subdev_info *subdev)
* Allocate the map_info structs in one go. {
*/ unsigned long phys;
maps = kmalloc(sizeof(struct map_info) * nr, GFP_KERNEL); unsigned int size;
if (!maps) int ret;
return -ENOMEM;
memset(maps, 0, sizeof(struct map_info) * nr); phys = subdev->base;
size = subdev->size;
/* /*
* Claim and then map the memory regions. * Retrieve the bankwidth from the MSC registers.
* We currently only implement CS0 and CS1 here.
*/ */
for (i = 0; i < nr; i++) { switch (phys) {
if (sa[i].base == (unsigned long)-1) default:
printk(KERN_WARNING "SA1100 flash: unknown base address "
"0x%08lx, assuming CS0\n", phys);
case SA1100_CS0_PHYS:
subdev->map.bankwidth = (MSC0 & MSC_RBW) ? 2 : 4;
break; break;
sa[i].map = maps + i; case SA1100_CS1_PHYS:
sa[i].map->name = sa[i].name; subdev->map.bankwidth = ((MSC0 >> 16) & MSC_RBW) ? 2 : 4;
sprintf(sa[i].name, "sa1100-%d", i); break;
}
if (!request_mem_region(sa[i].base, sa[i].size, sa[i].name)) { if (!request_mem_region(phys, size, subdev->name)) {
i -= 1;
ret = -EBUSY; ret = -EBUSY;
break; goto out;
} }
sa[i].map->virt = ioremap(sa[i].base, sa[i].size); subdev->map.set_vpp = subdev->set_vpp;
if (!sa[i].map->virt) { subdev->map.phys = phys;
subdev->map.size = size;
subdev->map.virt = ioremap(phys, size);
if (!subdev->map.virt) {
ret = -ENOMEM; ret = -ENOMEM;
break; goto err;
} }
sa[i].map->phys = sa[i].base; simple_map_init(&subdev->map);
sa[i].map->set_vpp = sa[i].set_vpp;
sa[i].map->bankwidth = sa[i].width;
sa[i].map->size = sa[i].size;
simple_map_init(sa[i].map);
/* /*
* Now let's probe for the actual flash. Do it here since * Now let's probe for the actual flash. Do it here since
* specific machine settings might have been set above. * specific machine settings might have been set above.
*/ */
sa[i].mtd = do_map_probe("cfi_probe", sa[i].map); subdev->mtd = do_map_probe(subdev->data->map_name, &subdev->map);
if (sa[i].mtd == NULL) { if (subdev->mtd == NULL) {
ret = -ENXIO; ret = -ENXIO;
break; goto err;
} }
sa[i].mtd->owner = THIS_MODULE; subdev->mtd->owner = THIS_MODULE;
subdev[i] = sa[i].mtd;
printk(KERN_INFO "SA1100 flash: CFI device at 0x%08lx, %dMiB, " printk(KERN_INFO "SA1100 flash: CFI device at 0x%08lx, %dMiB, "
"%d-bit\n", sa[i].base, sa[i].mtd->size >> 20, "%d-bit\n", phys, subdev->mtd->size >> 20,
sa[i].width * 8); subdev->map.bankwidth * 8);
found += 1;
} return 0;
err:
sa1100_destroy_subdev(subdev);
out:
return ret;
}
static int __init sa1100_setup_mtd(struct sa_subdev_info *sa, int nr, struct mtd_info **rmtd)
{
struct mtd_info *cdev[nr];
int i, found = 0, ret = 0;
/* /*
* ENXIO is special. It means we didn't find a chip when * Claim and then map the memory regions.
* we probed. We need to tear down the mapping, free the
* resource and mark it as such.
*/ */
if (ret == -ENXIO) { for (i = 0; i < nr; i++) {
iounmap(sa[i].map->virt); struct sa_subdev_info *subdev = &sa[i];
sa[i].map->virt = NULL; if (subdev->base == (unsigned long)-1)
release_mem_region(sa[i].base, sa[i].size); break;
subdev->map.name = subdev->name;
sprintf(subdev->name, "sa1100-%d", i);
ret = sa1100_probe_subdev(subdev);
if (ret)
break;
cdev[i] = subdev->mtd;
found += 1;
} }
/* /*
...@@ -1008,7 +1033,7 @@ static int __init sa1100_setup_mtd(struct sa_info *sa, int nr, struct mtd_info * ...@@ -1008,7 +1033,7 @@ static int __init sa1100_setup_mtd(struct sa_info *sa, int nr, struct mtd_info *
*/ */
if (ret == 0 || ret == -ENXIO) { if (ret == 0 || ret == -ENXIO) {
if (found == 1) { if (found == 1) {
*rmtd = subdev[0]; *rmtd = cdev[0];
ret = 0; ret = 0;
} else if (found > 1) { } else if (found > 1) {
/* /*
...@@ -1016,7 +1041,7 @@ static int __init sa1100_setup_mtd(struct sa_info *sa, int nr, struct mtd_info * ...@@ -1016,7 +1041,7 @@ static int __init sa1100_setup_mtd(struct sa_info *sa, int nr, struct mtd_info *
* them together. * them together.
*/ */
#ifdef CONFIG_MTD_CONCAT #ifdef CONFIG_MTD_CONCAT
*rmtd = mtd_concat_create(subdev, found, *rmtd = mtd_concat_create(cdev, found,
"sa1100"); "sa1100");
if (*rmtd == NULL) if (*rmtd == NULL)
ret = -ENXIO; ret = -ENXIO;
...@@ -1033,20 +1058,14 @@ static int __init sa1100_setup_mtd(struct sa_info *sa, int nr, struct mtd_info * ...@@ -1033,20 +1058,14 @@ static int __init sa1100_setup_mtd(struct sa_info *sa, int nr, struct mtd_info *
*/ */
if (ret) { if (ret) {
do { do {
if (sa[i].mtd) sa1100_destroy_subdev(&sa[i]);
map_destroy(sa[i].mtd);
if (sa[i].map->virt)
iounmap(sa[i].map->virt);
release_mem_region(sa[i].base, sa[i].size);
} while (i-- > 0); } while (i-- > 0);
kfree(maps);
} }
return ret; return ret;
} }
static void __exit sa1100_destroy_mtd(struct sa_info *sa, struct mtd_info *mtd) static void __exit sa1100_destroy_mtd(struct sa_subdev_info *sa, struct mtd_info *mtd)
{ {
int i; int i;
...@@ -1057,14 +1076,8 @@ static void __exit sa1100_destroy_mtd(struct sa_info *sa, struct mtd_info *mtd) ...@@ -1057,14 +1076,8 @@ static void __exit sa1100_destroy_mtd(struct sa_info *sa, struct mtd_info *mtd)
mtd_concat_destroy(mtd); mtd_concat_destroy(mtd);
#endif #endif
for (i = NR_SUBMTD; i >= 0; i--) { for (i = NR_SUBMTD; i >= 0; i--)
if (sa[i].mtd) sa1100_destroy_subdev(&sa[i]);
map_destroy(sa[i].mtd);
if (sa[i].map->virt)
iounmap(sa[i].map->virt);
release_mem_region(sa[i].base, sa[i].size);
}
kfree(sa[0].map);
} }
static int __init sa1100_locate_flash(void) static int __init sa1100_locate_flash(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment