xref: /linux/drivers/mtd/maps/sa1100-flash.c (revision 69f34c98c1416eb74c55e38a21dbf3e294966514)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Flash memory access on SA11x0 based devices
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * (C) 2000 Nicolas Pitre <nico@cam.org>
51da177e4SLinus Torvalds  *
6*69f34c98SThomas Gleixner  * $Id: sa1100-flash.c,v 1.51 2005/11/07 11:14:28 gleixner Exp $
71da177e4SLinus Torvalds  */
81da177e4SLinus Torvalds #include <linux/config.h>
91da177e4SLinus Torvalds #include <linux/module.h>
101da177e4SLinus Torvalds #include <linux/types.h>
111da177e4SLinus Torvalds #include <linux/ioport.h>
121da177e4SLinus Torvalds #include <linux/kernel.h>
131da177e4SLinus Torvalds #include <linux/init.h>
141da177e4SLinus Torvalds #include <linux/errno.h>
151da177e4SLinus Torvalds #include <linux/slab.h>
16d052d1beSRussell King #include <linux/platform_device.h>
171da177e4SLinus Torvalds #include <linux/err.h>
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds #include <linux/mtd/mtd.h>
201da177e4SLinus Torvalds #include <linux/mtd/map.h>
211da177e4SLinus Torvalds #include <linux/mtd/partitions.h>
221da177e4SLinus Torvalds #include <linux/mtd/concat.h>
231da177e4SLinus Torvalds 
24674c0453SRussell King #include <asm/hardware.h>
251da177e4SLinus Torvalds #include <asm/io.h>
261da177e4SLinus Torvalds #include <asm/sizes.h>
271da177e4SLinus Torvalds #include <asm/mach/flash.h>
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds #if 0
301da177e4SLinus Torvalds /*
311da177e4SLinus Torvalds  * This is here for documentation purposes only - until these people
321da177e4SLinus Torvalds  * submit their machine types.  It will be gone January 2005.
331da177e4SLinus Torvalds  */
341da177e4SLinus Torvalds static struct mtd_partition consus_partitions[] = {
351da177e4SLinus Torvalds 	{
361da177e4SLinus Torvalds 		.name		= "Consus boot firmware",
371da177e4SLinus Torvalds 		.offset		= 0,
381da177e4SLinus Torvalds 		.size		= 0x00040000,
391da177e4SLinus Torvalds 		.mask_flags	= MTD_WRITABLE, /* force read-only */
401da177e4SLinus Torvalds 	}, {
411da177e4SLinus Torvalds 		.name		= "Consus kernel",
421da177e4SLinus Torvalds 		.offset		= 0x00040000,
431da177e4SLinus Torvalds 		.size		= 0x00100000,
441da177e4SLinus Torvalds 		.mask_flags	= 0,
451da177e4SLinus Torvalds 	}, {
461da177e4SLinus Torvalds 		.name		= "Consus disk",
471da177e4SLinus Torvalds 		.offset		= 0x00140000,
481da177e4SLinus Torvalds 		/* The rest (up to 16M) for jffs.  We could put 0 and
491da177e4SLinus Torvalds 		   make it find the size automatically, but right now
501da177e4SLinus Torvalds 		   i have 32 megs.  jffs will use all 32 megs if given
511da177e4SLinus Torvalds 		   the chance, and this leads to horrible problems
521da177e4SLinus Torvalds 		   when you try to re-flash the image because blob
531da177e4SLinus Torvalds 		   won't erase the whole partition. */
541da177e4SLinus Torvalds 		.size		= 0x01000000 - 0x00140000,
551da177e4SLinus Torvalds 		.mask_flags	= 0,
561da177e4SLinus Torvalds 	}, {
571da177e4SLinus Torvalds 		/* this disk is a secondary disk, which can be used as
581da177e4SLinus Torvalds 		   needed, for simplicity, make it the size of the other
591da177e4SLinus Torvalds 		   consus partition, although realistically it could be
601da177e4SLinus Torvalds 		   the remainder of the disk (depending on the file
611da177e4SLinus Torvalds 		   system used) */
621da177e4SLinus Torvalds 		 .name		= "Consus disk2",
631da177e4SLinus Torvalds 		 .offset	= 0x01000000,
641da177e4SLinus Torvalds 		 .size		= 0x01000000 - 0x00140000,
651da177e4SLinus Torvalds 		 .mask_flags	= 0,
661da177e4SLinus Torvalds 	}
671da177e4SLinus Torvalds };
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds /* Frodo has 2 x 16M 28F128J3A flash chips in bank 0: */
701da177e4SLinus Torvalds static struct mtd_partition frodo_partitions[] =
711da177e4SLinus Torvalds {
721da177e4SLinus Torvalds 	{
731da177e4SLinus Torvalds 		.name		= "bootloader",
741da177e4SLinus Torvalds 		.size		= 0x00040000,
751da177e4SLinus Torvalds 		.offset		= 0x00000000,
761da177e4SLinus Torvalds 		.mask_flags	= MTD_WRITEABLE
771da177e4SLinus Torvalds 	}, {
781da177e4SLinus Torvalds 		.name		= "bootloader params",
791da177e4SLinus Torvalds 		.size		= 0x00040000,
801da177e4SLinus Torvalds 		.offset		= MTDPART_OFS_APPEND,
811da177e4SLinus Torvalds 		.mask_flags	= MTD_WRITEABLE
821da177e4SLinus Torvalds 	}, {
831da177e4SLinus Torvalds 		.name		= "kernel",
841da177e4SLinus Torvalds 		.size		= 0x00100000,
851da177e4SLinus Torvalds 		.offset		= MTDPART_OFS_APPEND,
861da177e4SLinus Torvalds 		.mask_flags	= MTD_WRITEABLE
871da177e4SLinus Torvalds 	}, {
881da177e4SLinus Torvalds 		.name		= "ramdisk",
891da177e4SLinus Torvalds 		.size		= 0x00400000,
901da177e4SLinus Torvalds 		.offset		= MTDPART_OFS_APPEND,
911da177e4SLinus Torvalds 		.mask_flags	= MTD_WRITEABLE
921da177e4SLinus Torvalds 	}, {
931da177e4SLinus Torvalds 		.name		= "file system",
941da177e4SLinus Torvalds 		.size		= MTDPART_SIZ_FULL,
951da177e4SLinus Torvalds 		.offset		= MTDPART_OFS_APPEND
961da177e4SLinus Torvalds 	}
971da177e4SLinus Torvalds };
981da177e4SLinus Torvalds 
991da177e4SLinus Torvalds static struct mtd_partition jornada56x_partitions[] = {
1001da177e4SLinus Torvalds 	{
1011da177e4SLinus Torvalds 		.name		= "bootldr",
1021da177e4SLinus Torvalds 		.size		= 0x00040000,
1031da177e4SLinus Torvalds 		.offset		= 0,
1041da177e4SLinus Torvalds 		.mask_flags	= MTD_WRITEABLE,
1051da177e4SLinus Torvalds 	}, {
1061da177e4SLinus Torvalds 		.name		= "rootfs",
1071da177e4SLinus Torvalds 		.size		= MTDPART_SIZ_FULL,
1081da177e4SLinus Torvalds 		.offset		= MTDPART_OFS_APPEND,
1091da177e4SLinus Torvalds 	}
1101da177e4SLinus Torvalds };
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds static void jornada56x_set_vpp(int vpp)
1131da177e4SLinus Torvalds {
1141da177e4SLinus Torvalds 	if (vpp)
1151da177e4SLinus Torvalds 		GPSR = GPIO_GPIO26;
1161da177e4SLinus Torvalds 	else
1171da177e4SLinus Torvalds 		GPCR = GPIO_GPIO26;
1181da177e4SLinus Torvalds 	GPDR |= GPIO_GPIO26;
1191da177e4SLinus Torvalds }
1201da177e4SLinus Torvalds 
1211da177e4SLinus Torvalds /*
1221da177e4SLinus Torvalds  * Machine        Phys          Size    set_vpp
1231da177e4SLinus Torvalds  * Consus    : SA1100_CS0_PHYS SZ_32M
1241da177e4SLinus Torvalds  * Frodo     : SA1100_CS0_PHYS SZ_32M
1251da177e4SLinus Torvalds  * Jornada56x: SA1100_CS0_PHYS SZ_32M jornada56x_set_vpp
1261da177e4SLinus Torvalds  */
1271da177e4SLinus Torvalds #endif
1281da177e4SLinus Torvalds 
1291da177e4SLinus Torvalds struct sa_subdev_info {
1301da177e4SLinus Torvalds 	char name[16];
1311da177e4SLinus Torvalds 	struct map_info map;
1321da177e4SLinus Torvalds 	struct mtd_info *mtd;
13357725f0aSRussell King 	struct flash_platform_data *plat;
1341da177e4SLinus Torvalds };
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds struct sa_info {
1371da177e4SLinus Torvalds 	struct mtd_partition	*parts;
1381da177e4SLinus Torvalds 	struct mtd_info		*mtd;
1391da177e4SLinus Torvalds 	int			num_subdev;
140822e5e72SRussell King 	unsigned int		nr_parts;
1411da177e4SLinus Torvalds 	struct sa_subdev_info	subdev[0];
1421da177e4SLinus Torvalds };
1431da177e4SLinus Torvalds 
1441da177e4SLinus Torvalds static void sa1100_set_vpp(struct map_info *map, int on)
1451da177e4SLinus Torvalds {
1461da177e4SLinus Torvalds 	struct sa_subdev_info *subdev = container_of(map, struct sa_subdev_info, map);
14757725f0aSRussell King 	subdev->plat->set_vpp(on);
1481da177e4SLinus Torvalds }
1491da177e4SLinus Torvalds 
1501da177e4SLinus Torvalds static void sa1100_destroy_subdev(struct sa_subdev_info *subdev)
1511da177e4SLinus Torvalds {
1521da177e4SLinus Torvalds 	if (subdev->mtd)
1531da177e4SLinus Torvalds 		map_destroy(subdev->mtd);
1541da177e4SLinus Torvalds 	if (subdev->map.virt)
1551da177e4SLinus Torvalds 		iounmap(subdev->map.virt);
1561da177e4SLinus Torvalds 	release_mem_region(subdev->map.phys, subdev->map.size);
1571da177e4SLinus Torvalds }
1581da177e4SLinus Torvalds 
1591da177e4SLinus Torvalds static int sa1100_probe_subdev(struct sa_subdev_info *subdev, struct resource *res)
1601da177e4SLinus Torvalds {
1611da177e4SLinus Torvalds 	unsigned long phys;
1621da177e4SLinus Torvalds 	unsigned int size;
1631da177e4SLinus Torvalds 	int ret;
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds 	phys = res->start;
1661da177e4SLinus Torvalds 	size = res->end - phys + 1;
1671da177e4SLinus Torvalds 
1681da177e4SLinus Torvalds 	/*
1691da177e4SLinus Torvalds 	 * Retrieve the bankwidth from the MSC registers.
1701da177e4SLinus Torvalds 	 * We currently only implement CS0 and CS1 here.
1711da177e4SLinus Torvalds 	 */
1721da177e4SLinus Torvalds 	switch (phys) {
1731da177e4SLinus Torvalds 	default:
1741da177e4SLinus Torvalds 		printk(KERN_WARNING "SA1100 flash: unknown base address "
1751da177e4SLinus Torvalds 		       "0x%08lx, assuming CS0\n", phys);
1761da177e4SLinus Torvalds 
1771da177e4SLinus Torvalds 	case SA1100_CS0_PHYS:
1781da177e4SLinus Torvalds 		subdev->map.bankwidth = (MSC0 & MSC_RBW) ? 2 : 4;
1791da177e4SLinus Torvalds 		break;
1801da177e4SLinus Torvalds 
1811da177e4SLinus Torvalds 	case SA1100_CS1_PHYS:
1821da177e4SLinus Torvalds 		subdev->map.bankwidth = ((MSC0 >> 16) & MSC_RBW) ? 2 : 4;
1831da177e4SLinus Torvalds 		break;
1841da177e4SLinus Torvalds 	}
1851da177e4SLinus Torvalds 
1861da177e4SLinus Torvalds 	if (!request_mem_region(phys, size, subdev->name)) {
1871da177e4SLinus Torvalds 		ret = -EBUSY;
1881da177e4SLinus Torvalds 		goto out;
1891da177e4SLinus Torvalds 	}
1901da177e4SLinus Torvalds 
19157725f0aSRussell King 	if (subdev->plat->set_vpp)
1921da177e4SLinus Torvalds 		subdev->map.set_vpp = sa1100_set_vpp;
1931da177e4SLinus Torvalds 
1941da177e4SLinus Torvalds 	subdev->map.phys = phys;
1951da177e4SLinus Torvalds 	subdev->map.size = size;
1961da177e4SLinus Torvalds 	subdev->map.virt = ioremap(phys, size);
1971da177e4SLinus Torvalds 	if (!subdev->map.virt) {
1981da177e4SLinus Torvalds 		ret = -ENOMEM;
1991da177e4SLinus Torvalds 		goto err;
2001da177e4SLinus Torvalds 	}
2011da177e4SLinus Torvalds 
2021da177e4SLinus Torvalds 	simple_map_init(&subdev->map);
2031da177e4SLinus Torvalds 
2041da177e4SLinus Torvalds 	/*
2051da177e4SLinus Torvalds 	 * Now let's probe for the actual flash.  Do it here since
2061da177e4SLinus Torvalds 	 * specific machine settings might have been set above.
2071da177e4SLinus Torvalds 	 */
20857725f0aSRussell King 	subdev->mtd = do_map_probe(subdev->plat->map_name, &subdev->map);
2091da177e4SLinus Torvalds 	if (subdev->mtd == NULL) {
2101da177e4SLinus Torvalds 		ret = -ENXIO;
2111da177e4SLinus Torvalds 		goto err;
2121da177e4SLinus Torvalds 	}
2131da177e4SLinus Torvalds 	subdev->mtd->owner = THIS_MODULE;
2141da177e4SLinus Torvalds 
2151da177e4SLinus Torvalds 	printk(KERN_INFO "SA1100 flash: CFI device at 0x%08lx, %dMiB, "
2161da177e4SLinus Torvalds 		"%d-bit\n", phys, subdev->mtd->size >> 20,
2171da177e4SLinus Torvalds 		subdev->map.bankwidth * 8);
2181da177e4SLinus Torvalds 
2191da177e4SLinus Torvalds 	return 0;
2201da177e4SLinus Torvalds 
2211da177e4SLinus Torvalds  err:
2221da177e4SLinus Torvalds 	sa1100_destroy_subdev(subdev);
2231da177e4SLinus Torvalds  out:
2241da177e4SLinus Torvalds 	return ret;
2251da177e4SLinus Torvalds }
2261da177e4SLinus Torvalds 
2270d2ef7d7SRussell King static void sa1100_destroy(struct sa_info *info, struct flash_platform_data *plat)
2281da177e4SLinus Torvalds {
2291da177e4SLinus Torvalds 	int i;
2301da177e4SLinus Torvalds 
2311da177e4SLinus Torvalds 	if (info->mtd) {
232822e5e72SRussell King 		if (info->nr_parts == 0)
233822e5e72SRussell King 			del_mtd_device(info->mtd);
234822e5e72SRussell King #ifdef CONFIG_MTD_PARTITIONS
235822e5e72SRussell King 		else
2361da177e4SLinus Torvalds 			del_mtd_partitions(info->mtd);
237822e5e72SRussell King #endif
2381da177e4SLinus Torvalds #ifdef CONFIG_MTD_CONCAT
2391da177e4SLinus Torvalds 		if (info->mtd != info->subdev[0].mtd)
2401da177e4SLinus Torvalds 			mtd_concat_destroy(info->mtd);
2411da177e4SLinus Torvalds #endif
2421da177e4SLinus Torvalds 	}
2431da177e4SLinus Torvalds 
2441da177e4SLinus Torvalds 	if (info->parts)
2451da177e4SLinus Torvalds 		kfree(info->parts);
2461da177e4SLinus Torvalds 
2471da177e4SLinus Torvalds 	for (i = info->num_subdev - 1; i >= 0; i--)
2481da177e4SLinus Torvalds 		sa1100_destroy_subdev(&info->subdev[i]);
2491da177e4SLinus Torvalds 	kfree(info);
2500d2ef7d7SRussell King 
2510d2ef7d7SRussell King 	if (plat->exit)
2520d2ef7d7SRussell King 		plat->exit();
2531da177e4SLinus Torvalds }
2541da177e4SLinus Torvalds 
2551da177e4SLinus Torvalds static struct sa_info *__init
25657725f0aSRussell King sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *plat)
2571da177e4SLinus Torvalds {
2581da177e4SLinus Torvalds 	struct sa_info *info;
2591da177e4SLinus Torvalds 	int nr, size, i, ret = 0;
2601da177e4SLinus Torvalds 
2611da177e4SLinus Torvalds 	/*
2621da177e4SLinus Torvalds 	 * Count number of devices.
2631da177e4SLinus Torvalds 	 */
2641da177e4SLinus Torvalds 	for (nr = 0; ; nr++)
2651da177e4SLinus Torvalds 		if (!platform_get_resource(pdev, IORESOURCE_MEM, nr))
2661da177e4SLinus Torvalds 			break;
2671da177e4SLinus Torvalds 
2681da177e4SLinus Torvalds 	if (nr == 0) {
2691da177e4SLinus Torvalds 		ret = -ENODEV;
2701da177e4SLinus Torvalds 		goto out;
2711da177e4SLinus Torvalds 	}
2721da177e4SLinus Torvalds 
2731da177e4SLinus Torvalds 	size = sizeof(struct sa_info) + sizeof(struct sa_subdev_info) * nr;
2741da177e4SLinus Torvalds 
2751da177e4SLinus Torvalds 	/*
2761da177e4SLinus Torvalds 	 * Allocate the map_info structs in one go.
2771da177e4SLinus Torvalds 	 */
2781da177e4SLinus Torvalds 	info = kmalloc(size, GFP_KERNEL);
2791da177e4SLinus Torvalds 	if (!info) {
2801da177e4SLinus Torvalds 		ret = -ENOMEM;
2811da177e4SLinus Torvalds 		goto out;
2821da177e4SLinus Torvalds 	}
2831da177e4SLinus Torvalds 
2841da177e4SLinus Torvalds 	memset(info, 0, size);
2851da177e4SLinus Torvalds 
2860d2ef7d7SRussell King 	if (plat->init) {
2870d2ef7d7SRussell King 		ret = plat->init();
2880d2ef7d7SRussell King 		if (ret)
2890d2ef7d7SRussell King 			goto err;
2900d2ef7d7SRussell King 	}
2910d2ef7d7SRussell King 
2921da177e4SLinus Torvalds 	/*
2931da177e4SLinus Torvalds 	 * Claim and then map the memory regions.
2941da177e4SLinus Torvalds 	 */
2951da177e4SLinus Torvalds 	for (i = 0; i < nr; i++) {
2961da177e4SLinus Torvalds 		struct sa_subdev_info *subdev = &info->subdev[i];
2971da177e4SLinus Torvalds 		struct resource *res;
2981da177e4SLinus Torvalds 
2991da177e4SLinus Torvalds 		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
3001da177e4SLinus Torvalds 		if (!res)
3011da177e4SLinus Torvalds 			break;
3021da177e4SLinus Torvalds 
3031da177e4SLinus Torvalds 		subdev->map.name = subdev->name;
30414e66f76SRussell King 		sprintf(subdev->name, "%s-%d", plat->name, i);
30557725f0aSRussell King 		subdev->plat = plat;
3061da177e4SLinus Torvalds 
3071da177e4SLinus Torvalds 		ret = sa1100_probe_subdev(subdev, res);
3081da177e4SLinus Torvalds 		if (ret)
3091da177e4SLinus Torvalds 			break;
3101da177e4SLinus Torvalds 	}
3111da177e4SLinus Torvalds 
3121da177e4SLinus Torvalds 	info->num_subdev = i;
3131da177e4SLinus Torvalds 
3141da177e4SLinus Torvalds 	/*
3151da177e4SLinus Torvalds 	 * ENXIO is special.  It means we didn't find a chip when we probed.
3161da177e4SLinus Torvalds 	 */
3171da177e4SLinus Torvalds 	if (ret != 0 && !(ret == -ENXIO && info->num_subdev > 0))
3181da177e4SLinus Torvalds 		goto err;
3191da177e4SLinus Torvalds 
3201da177e4SLinus Torvalds 	/*
3211da177e4SLinus Torvalds 	 * If we found one device, don't bother with concat support.  If
3221da177e4SLinus Torvalds 	 * we found multiple devices, use concat if we have it available,
3231da177e4SLinus Torvalds 	 * otherwise fail.  Either way, it'll be called "sa1100".
3241da177e4SLinus Torvalds 	 */
3251da177e4SLinus Torvalds 	if (info->num_subdev == 1) {
32614e66f76SRussell King 		strcpy(info->subdev[0].name, plat->name);
3271da177e4SLinus Torvalds 		info->mtd = info->subdev[0].mtd;
3281da177e4SLinus Torvalds 		ret = 0;
3291da177e4SLinus Torvalds 	} else if (info->num_subdev > 1) {
3301da177e4SLinus Torvalds #ifdef CONFIG_MTD_CONCAT
3311da177e4SLinus Torvalds 		struct mtd_info *cdev[nr];
3321da177e4SLinus Torvalds 		/*
3331da177e4SLinus Torvalds 		 * We detected multiple devices.  Concatenate them together.
3341da177e4SLinus Torvalds 		 */
3351da177e4SLinus Torvalds 		for (i = 0; i < info->num_subdev; i++)
3361da177e4SLinus Torvalds 			cdev[i] = info->subdev[i].mtd;
3371da177e4SLinus Torvalds 
3381da177e4SLinus Torvalds 		info->mtd = mtd_concat_create(cdev, info->num_subdev,
33914e66f76SRussell King 					      plat->name);
3401da177e4SLinus Torvalds 		if (info->mtd == NULL)
3411da177e4SLinus Torvalds 			ret = -ENXIO;
3421da177e4SLinus Torvalds #else
3431da177e4SLinus Torvalds 		printk(KERN_ERR "SA1100 flash: multiple devices "
3441da177e4SLinus Torvalds 		       "found but MTD concat support disabled.\n");
3451da177e4SLinus Torvalds 		ret = -ENXIO;
3461da177e4SLinus Torvalds #endif
3471da177e4SLinus Torvalds 	}
3481da177e4SLinus Torvalds 
3491da177e4SLinus Torvalds 	if (ret == 0)
3501da177e4SLinus Torvalds 		return info;
3511da177e4SLinus Torvalds 
3521da177e4SLinus Torvalds  err:
3530d2ef7d7SRussell King 	sa1100_destroy(info, plat);
3541da177e4SLinus Torvalds  out:
3551da177e4SLinus Torvalds 	return ERR_PTR(ret);
3561da177e4SLinus Torvalds }
3571da177e4SLinus Torvalds 
3581da177e4SLinus Torvalds static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
3591da177e4SLinus Torvalds 
3601da177e4SLinus Torvalds static int __init sa1100_mtd_probe(struct device *dev)
3611da177e4SLinus Torvalds {
3621da177e4SLinus Torvalds 	struct platform_device *pdev = to_platform_device(dev);
36357725f0aSRussell King 	struct flash_platform_data *plat = pdev->dev.platform_data;
3641da177e4SLinus Torvalds 	struct mtd_partition *parts;
3651da177e4SLinus Torvalds 	const char *part_type = NULL;
3661da177e4SLinus Torvalds 	struct sa_info *info;
3671da177e4SLinus Torvalds 	int err, nr_parts = 0;
3681da177e4SLinus Torvalds 
36957725f0aSRussell King 	if (!plat)
3701da177e4SLinus Torvalds 		return -ENODEV;
3711da177e4SLinus Torvalds 
37257725f0aSRussell King 	info = sa1100_setup_mtd(pdev, plat);
3731da177e4SLinus Torvalds 	if (IS_ERR(info)) {
3741da177e4SLinus Torvalds 		err = PTR_ERR(info);
3751da177e4SLinus Torvalds 		goto out;
3761da177e4SLinus Torvalds 	}
3771da177e4SLinus Torvalds 
3781da177e4SLinus Torvalds 	/*
3791da177e4SLinus Torvalds 	 * Partition selection stuff.
3801da177e4SLinus Torvalds 	 */
3811da177e4SLinus Torvalds #ifdef CONFIG_MTD_PARTITIONS
3821da177e4SLinus Torvalds 	nr_parts = parse_mtd_partitions(info->mtd, part_probes, &parts, 0);
3831da177e4SLinus Torvalds 	if (nr_parts > 0) {
3841da177e4SLinus Torvalds 		info->parts = parts;
3851da177e4SLinus Torvalds 		part_type = "dynamic";
3861da177e4SLinus Torvalds 	} else
3871da177e4SLinus Torvalds #endif
3881da177e4SLinus Torvalds 	{
38957725f0aSRussell King 		parts = plat->parts;
39057725f0aSRussell King 		nr_parts = plat->nr_parts;
3911da177e4SLinus Torvalds 		part_type = "static";
3921da177e4SLinus Torvalds 	}
3931da177e4SLinus Torvalds 
3941da177e4SLinus Torvalds 	if (nr_parts == 0) {
3951da177e4SLinus Torvalds 		printk(KERN_NOTICE "SA1100 flash: no partition info "
3961da177e4SLinus Torvalds 			"available, registering whole flash\n");
3971da177e4SLinus Torvalds 		add_mtd_device(info->mtd);
3981da177e4SLinus Torvalds 	} else {
3991da177e4SLinus Torvalds 		printk(KERN_NOTICE "SA1100 flash: using %s partition "
4001da177e4SLinus Torvalds 			"definition\n", part_type);
4011da177e4SLinus Torvalds 		add_mtd_partitions(info->mtd, parts, nr_parts);
4021da177e4SLinus Torvalds 	}
4031da177e4SLinus Torvalds 
404822e5e72SRussell King 	info->nr_parts = nr_parts;
405822e5e72SRussell King 
4061da177e4SLinus Torvalds 	dev_set_drvdata(dev, info);
4071da177e4SLinus Torvalds 	err = 0;
4081da177e4SLinus Torvalds 
4091da177e4SLinus Torvalds  out:
4101da177e4SLinus Torvalds 	return err;
4111da177e4SLinus Torvalds }
4121da177e4SLinus Torvalds 
4131da177e4SLinus Torvalds static int __exit sa1100_mtd_remove(struct device *dev)
4141da177e4SLinus Torvalds {
4151da177e4SLinus Torvalds 	struct sa_info *info = dev_get_drvdata(dev);
4160d2ef7d7SRussell King 	struct flash_platform_data *plat = dev->platform_data;
4170d2ef7d7SRussell King 
4181da177e4SLinus Torvalds 	dev_set_drvdata(dev, NULL);
4190d2ef7d7SRussell King 	sa1100_destroy(info, plat);
4200d2ef7d7SRussell King 
4211da177e4SLinus Torvalds 	return 0;
4221da177e4SLinus Torvalds }
4231da177e4SLinus Torvalds 
4241da177e4SLinus Torvalds #ifdef CONFIG_PM
4259480e307SRussell King static int sa1100_mtd_suspend(struct device *dev, pm_message_t state)
4261da177e4SLinus Torvalds {
4271da177e4SLinus Torvalds 	struct sa_info *info = dev_get_drvdata(dev);
4281da177e4SLinus Torvalds 	int ret = 0;
4291da177e4SLinus Torvalds 
4309480e307SRussell King 	if (info)
4311da177e4SLinus Torvalds 		ret = info->mtd->suspend(info->mtd);
4321da177e4SLinus Torvalds 
4331da177e4SLinus Torvalds 	return ret;
4341da177e4SLinus Torvalds }
4351da177e4SLinus Torvalds 
4369480e307SRussell King static int sa1100_mtd_resume(struct device *dev)
4371da177e4SLinus Torvalds {
4381da177e4SLinus Torvalds 	struct sa_info *info = dev_get_drvdata(dev);
4399480e307SRussell King 	if (info)
4401da177e4SLinus Torvalds 		info->mtd->resume(info->mtd);
4411da177e4SLinus Torvalds 	return 0;
4421da177e4SLinus Torvalds }
44313bfb34cSRussell King 
44413bfb34cSRussell King static void sa1100_mtd_shutdown(struct device *dev)
44513bfb34cSRussell King {
44613bfb34cSRussell King 	struct sa_info *info = dev_get_drvdata(dev);
44713bfb34cSRussell King 	if (info && info->mtd->suspend(info->mtd) == 0)
44813bfb34cSRussell King 		info->mtd->resume(info->mtd);
44913bfb34cSRussell King }
4501da177e4SLinus Torvalds #else
4511da177e4SLinus Torvalds #define sa1100_mtd_suspend NULL
4521da177e4SLinus Torvalds #define sa1100_mtd_resume  NULL
45313bfb34cSRussell King #define sa1100_mtd_shutdown NULL
4541da177e4SLinus Torvalds #endif
4551da177e4SLinus Torvalds 
4561da177e4SLinus Torvalds static struct device_driver sa1100_mtd_driver = {
4571da177e4SLinus Torvalds 	.name		= "flash",
4581da177e4SLinus Torvalds 	.bus		= &platform_bus_type,
4591da177e4SLinus Torvalds 	.probe		= sa1100_mtd_probe,
4601da177e4SLinus Torvalds 	.remove		= __exit_p(sa1100_mtd_remove),
4611da177e4SLinus Torvalds 	.suspend	= sa1100_mtd_suspend,
4621da177e4SLinus Torvalds 	.resume		= sa1100_mtd_resume,
46313bfb34cSRussell King 	.shutdown	= sa1100_mtd_shutdown,
4641da177e4SLinus Torvalds };
4651da177e4SLinus Torvalds 
4661da177e4SLinus Torvalds static int __init sa1100_mtd_init(void)
4671da177e4SLinus Torvalds {
4681da177e4SLinus Torvalds 	return driver_register(&sa1100_mtd_driver);
4691da177e4SLinus Torvalds }
4701da177e4SLinus Torvalds 
4711da177e4SLinus Torvalds static void __exit sa1100_mtd_exit(void)
4721da177e4SLinus Torvalds {
4731da177e4SLinus Torvalds 	driver_unregister(&sa1100_mtd_driver);
4741da177e4SLinus Torvalds }
4751da177e4SLinus Torvalds 
4761da177e4SLinus Torvalds module_init(sa1100_mtd_init);
4771da177e4SLinus Torvalds module_exit(sa1100_mtd_exit);
4781da177e4SLinus Torvalds 
4791da177e4SLinus Torvalds MODULE_AUTHOR("Nicolas Pitre");
4801da177e4SLinus Torvalds MODULE_DESCRIPTION("SA1100 CFI map driver");
4811da177e4SLinus Torvalds MODULE_LICENSE("GPL");
482