xref: /linux/drivers/mtd/maps/sa1100-flash.c (revision 3ae5eaec1d2d9c0cf53745352e7d4b152810ba24)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Flash memory access on SA11x0 based devices
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * (C) 2000 Nicolas Pitre <nico@cam.org>
51da177e4SLinus Torvalds  *
669f34c98SThomas 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 	kfree(info->parts);
2451da177e4SLinus Torvalds 
2461da177e4SLinus Torvalds 	for (i = info->num_subdev - 1; i >= 0; i--)
2471da177e4SLinus Torvalds 		sa1100_destroy_subdev(&info->subdev[i]);
2481da177e4SLinus Torvalds 	kfree(info);
2490d2ef7d7SRussell King 
2500d2ef7d7SRussell King 	if (plat->exit)
2510d2ef7d7SRussell King 		plat->exit();
2521da177e4SLinus Torvalds }
2531da177e4SLinus Torvalds 
2541da177e4SLinus Torvalds static struct sa_info *__init
25557725f0aSRussell King sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *plat)
2561da177e4SLinus Torvalds {
2571da177e4SLinus Torvalds 	struct sa_info *info;
2581da177e4SLinus Torvalds 	int nr, size, i, ret = 0;
2591da177e4SLinus Torvalds 
2601da177e4SLinus Torvalds 	/*
2611da177e4SLinus Torvalds 	 * Count number of devices.
2621da177e4SLinus Torvalds 	 */
2631da177e4SLinus Torvalds 	for (nr = 0; ; nr++)
2641da177e4SLinus Torvalds 		if (!platform_get_resource(pdev, IORESOURCE_MEM, nr))
2651da177e4SLinus Torvalds 			break;
2661da177e4SLinus Torvalds 
2671da177e4SLinus Torvalds 	if (nr == 0) {
2681da177e4SLinus Torvalds 		ret = -ENODEV;
2691da177e4SLinus Torvalds 		goto out;
2701da177e4SLinus Torvalds 	}
2711da177e4SLinus Torvalds 
2721da177e4SLinus Torvalds 	size = sizeof(struct sa_info) + sizeof(struct sa_subdev_info) * nr;
2731da177e4SLinus Torvalds 
2741da177e4SLinus Torvalds 	/*
2751da177e4SLinus Torvalds 	 * Allocate the map_info structs in one go.
2761da177e4SLinus Torvalds 	 */
2771da177e4SLinus Torvalds 	info = kmalloc(size, GFP_KERNEL);
2781da177e4SLinus Torvalds 	if (!info) {
2791da177e4SLinus Torvalds 		ret = -ENOMEM;
2801da177e4SLinus Torvalds 		goto out;
2811da177e4SLinus Torvalds 	}
2821da177e4SLinus Torvalds 
2831da177e4SLinus Torvalds 	memset(info, 0, size);
2841da177e4SLinus Torvalds 
2850d2ef7d7SRussell King 	if (plat->init) {
2860d2ef7d7SRussell King 		ret = plat->init();
2870d2ef7d7SRussell King 		if (ret)
2880d2ef7d7SRussell King 			goto err;
2890d2ef7d7SRussell King 	}
2900d2ef7d7SRussell King 
2911da177e4SLinus Torvalds 	/*
2921da177e4SLinus Torvalds 	 * Claim and then map the memory regions.
2931da177e4SLinus Torvalds 	 */
2941da177e4SLinus Torvalds 	for (i = 0; i < nr; i++) {
2951da177e4SLinus Torvalds 		struct sa_subdev_info *subdev = &info->subdev[i];
2961da177e4SLinus Torvalds 		struct resource *res;
2971da177e4SLinus Torvalds 
2981da177e4SLinus Torvalds 		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
2991da177e4SLinus Torvalds 		if (!res)
3001da177e4SLinus Torvalds 			break;
3011da177e4SLinus Torvalds 
3021da177e4SLinus Torvalds 		subdev->map.name = subdev->name;
30314e66f76SRussell King 		sprintf(subdev->name, "%s-%d", plat->name, i);
30457725f0aSRussell King 		subdev->plat = plat;
3051da177e4SLinus Torvalds 
3061da177e4SLinus Torvalds 		ret = sa1100_probe_subdev(subdev, res);
3071da177e4SLinus Torvalds 		if (ret)
3081da177e4SLinus Torvalds 			break;
3091da177e4SLinus Torvalds 	}
3101da177e4SLinus Torvalds 
3111da177e4SLinus Torvalds 	info->num_subdev = i;
3121da177e4SLinus Torvalds 
3131da177e4SLinus Torvalds 	/*
3141da177e4SLinus Torvalds 	 * ENXIO is special.  It means we didn't find a chip when we probed.
3151da177e4SLinus Torvalds 	 */
3161da177e4SLinus Torvalds 	if (ret != 0 && !(ret == -ENXIO && info->num_subdev > 0))
3171da177e4SLinus Torvalds 		goto err;
3181da177e4SLinus Torvalds 
3191da177e4SLinus Torvalds 	/*
3201da177e4SLinus Torvalds 	 * If we found one device, don't bother with concat support.  If
3211da177e4SLinus Torvalds 	 * we found multiple devices, use concat if we have it available,
3221da177e4SLinus Torvalds 	 * otherwise fail.  Either way, it'll be called "sa1100".
3231da177e4SLinus Torvalds 	 */
3241da177e4SLinus Torvalds 	if (info->num_subdev == 1) {
32514e66f76SRussell King 		strcpy(info->subdev[0].name, plat->name);
3261da177e4SLinus Torvalds 		info->mtd = info->subdev[0].mtd;
3271da177e4SLinus Torvalds 		ret = 0;
3281da177e4SLinus Torvalds 	} else if (info->num_subdev > 1) {
3291da177e4SLinus Torvalds #ifdef CONFIG_MTD_CONCAT
3301da177e4SLinus Torvalds 		struct mtd_info *cdev[nr];
3311da177e4SLinus Torvalds 		/*
3321da177e4SLinus Torvalds 		 * We detected multiple devices.  Concatenate them together.
3331da177e4SLinus Torvalds 		 */
3341da177e4SLinus Torvalds 		for (i = 0; i < info->num_subdev; i++)
3351da177e4SLinus Torvalds 			cdev[i] = info->subdev[i].mtd;
3361da177e4SLinus Torvalds 
3371da177e4SLinus Torvalds 		info->mtd = mtd_concat_create(cdev, info->num_subdev,
33814e66f76SRussell King 					      plat->name);
3391da177e4SLinus Torvalds 		if (info->mtd == NULL)
3401da177e4SLinus Torvalds 			ret = -ENXIO;
3411da177e4SLinus Torvalds #else
3421da177e4SLinus Torvalds 		printk(KERN_ERR "SA1100 flash: multiple devices "
3431da177e4SLinus Torvalds 		       "found but MTD concat support disabled.\n");
3441da177e4SLinus Torvalds 		ret = -ENXIO;
3451da177e4SLinus Torvalds #endif
3461da177e4SLinus Torvalds 	}
3471da177e4SLinus Torvalds 
3481da177e4SLinus Torvalds 	if (ret == 0)
3491da177e4SLinus Torvalds 		return info;
3501da177e4SLinus Torvalds 
3511da177e4SLinus Torvalds  err:
3520d2ef7d7SRussell King 	sa1100_destroy(info, plat);
3531da177e4SLinus Torvalds  out:
3541da177e4SLinus Torvalds 	return ERR_PTR(ret);
3551da177e4SLinus Torvalds }
3561da177e4SLinus Torvalds 
3571da177e4SLinus Torvalds static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
3581da177e4SLinus Torvalds 
359*3ae5eaecSRussell King static int __init sa1100_mtd_probe(struct platform_device *pdev)
3601da177e4SLinus Torvalds {
36157725f0aSRussell King 	struct flash_platform_data *plat = pdev->dev.platform_data;
3621da177e4SLinus Torvalds 	struct mtd_partition *parts;
3631da177e4SLinus Torvalds 	const char *part_type = NULL;
3641da177e4SLinus Torvalds 	struct sa_info *info;
3651da177e4SLinus Torvalds 	int err, nr_parts = 0;
3661da177e4SLinus Torvalds 
36757725f0aSRussell King 	if (!plat)
3681da177e4SLinus Torvalds 		return -ENODEV;
3691da177e4SLinus Torvalds 
37057725f0aSRussell King 	info = sa1100_setup_mtd(pdev, plat);
3711da177e4SLinus Torvalds 	if (IS_ERR(info)) {
3721da177e4SLinus Torvalds 		err = PTR_ERR(info);
3731da177e4SLinus Torvalds 		goto out;
3741da177e4SLinus Torvalds 	}
3751da177e4SLinus Torvalds 
3761da177e4SLinus Torvalds 	/*
3771da177e4SLinus Torvalds 	 * Partition selection stuff.
3781da177e4SLinus Torvalds 	 */
3791da177e4SLinus Torvalds #ifdef CONFIG_MTD_PARTITIONS
3801da177e4SLinus Torvalds 	nr_parts = parse_mtd_partitions(info->mtd, part_probes, &parts, 0);
3811da177e4SLinus Torvalds 	if (nr_parts > 0) {
3821da177e4SLinus Torvalds 		info->parts = parts;
3831da177e4SLinus Torvalds 		part_type = "dynamic";
3841da177e4SLinus Torvalds 	} else
3851da177e4SLinus Torvalds #endif
3861da177e4SLinus Torvalds 	{
38757725f0aSRussell King 		parts = plat->parts;
38857725f0aSRussell King 		nr_parts = plat->nr_parts;
3891da177e4SLinus Torvalds 		part_type = "static";
3901da177e4SLinus Torvalds 	}
3911da177e4SLinus Torvalds 
3921da177e4SLinus Torvalds 	if (nr_parts == 0) {
3931da177e4SLinus Torvalds 		printk(KERN_NOTICE "SA1100 flash: no partition info "
3941da177e4SLinus Torvalds 			"available, registering whole flash\n");
3951da177e4SLinus Torvalds 		add_mtd_device(info->mtd);
3961da177e4SLinus Torvalds 	} else {
3971da177e4SLinus Torvalds 		printk(KERN_NOTICE "SA1100 flash: using %s partition "
3981da177e4SLinus Torvalds 			"definition\n", part_type);
3991da177e4SLinus Torvalds 		add_mtd_partitions(info->mtd, parts, nr_parts);
4001da177e4SLinus Torvalds 	}
4011da177e4SLinus Torvalds 
402822e5e72SRussell King 	info->nr_parts = nr_parts;
403822e5e72SRussell King 
404*3ae5eaecSRussell King 	platform_set_drvdata(pdev, info);
4051da177e4SLinus Torvalds 	err = 0;
4061da177e4SLinus Torvalds 
4071da177e4SLinus Torvalds  out:
4081da177e4SLinus Torvalds 	return err;
4091da177e4SLinus Torvalds }
4101da177e4SLinus Torvalds 
411*3ae5eaecSRussell King static int __exit sa1100_mtd_remove(struct platform_device *pdev)
4121da177e4SLinus Torvalds {
413*3ae5eaecSRussell King 	struct sa_info *info = platform_get_drvdata(pdev);
414*3ae5eaecSRussell King 	struct flash_platform_data *plat = pdev->dev.platform_data;
4150d2ef7d7SRussell King 
416*3ae5eaecSRussell King 	platform_set_drvdata(pdev, NULL);
4170d2ef7d7SRussell King 	sa1100_destroy(info, plat);
4180d2ef7d7SRussell King 
4191da177e4SLinus Torvalds 	return 0;
4201da177e4SLinus Torvalds }
4211da177e4SLinus Torvalds 
4221da177e4SLinus Torvalds #ifdef CONFIG_PM
423*3ae5eaecSRussell King static int sa1100_mtd_suspend(struct platform_device *dev, pm_message_t state)
4241da177e4SLinus Torvalds {
425*3ae5eaecSRussell King 	struct sa_info *info = platform_get_drvdata(dev);
4261da177e4SLinus Torvalds 	int ret = 0;
4271da177e4SLinus Torvalds 
4289480e307SRussell King 	if (info)
4291da177e4SLinus Torvalds 		ret = info->mtd->suspend(info->mtd);
4301da177e4SLinus Torvalds 
4311da177e4SLinus Torvalds 	return ret;
4321da177e4SLinus Torvalds }
4331da177e4SLinus Torvalds 
434*3ae5eaecSRussell King static int sa1100_mtd_resume(struct platform_device *dev)
4351da177e4SLinus Torvalds {
436*3ae5eaecSRussell King 	struct sa_info *info = platform_get_drvdata(dev);
4379480e307SRussell King 	if (info)
4381da177e4SLinus Torvalds 		info->mtd->resume(info->mtd);
4391da177e4SLinus Torvalds 	return 0;
4401da177e4SLinus Torvalds }
44113bfb34cSRussell King 
442*3ae5eaecSRussell King static void sa1100_mtd_shutdown(struct platform_device *dev)
44313bfb34cSRussell King {
444*3ae5eaecSRussell King 	struct sa_info *info = platform_get_drvdata(dev);
44513bfb34cSRussell King 	if (info && info->mtd->suspend(info->mtd) == 0)
44613bfb34cSRussell King 		info->mtd->resume(info->mtd);
44713bfb34cSRussell King }
4481da177e4SLinus Torvalds #else
4491da177e4SLinus Torvalds #define sa1100_mtd_suspend NULL
4501da177e4SLinus Torvalds #define sa1100_mtd_resume  NULL
45113bfb34cSRussell King #define sa1100_mtd_shutdown NULL
4521da177e4SLinus Torvalds #endif
4531da177e4SLinus Torvalds 
454*3ae5eaecSRussell King static struct platform_driver sa1100_mtd_driver = {
4551da177e4SLinus Torvalds 	.probe		= sa1100_mtd_probe,
4561da177e4SLinus Torvalds 	.remove		= __exit_p(sa1100_mtd_remove),
4571da177e4SLinus Torvalds 	.suspend	= sa1100_mtd_suspend,
4581da177e4SLinus Torvalds 	.resume		= sa1100_mtd_resume,
45913bfb34cSRussell King 	.shutdown	= sa1100_mtd_shutdown,
460*3ae5eaecSRussell King 	.driver		= {
461*3ae5eaecSRussell King 		.name	= "flash",
462*3ae5eaecSRussell King 	},
4631da177e4SLinus Torvalds };
4641da177e4SLinus Torvalds 
4651da177e4SLinus Torvalds static int __init sa1100_mtd_init(void)
4661da177e4SLinus Torvalds {
467*3ae5eaecSRussell King 	return platform_driver_register(&sa1100_mtd_driver);
4681da177e4SLinus Torvalds }
4691da177e4SLinus Torvalds 
4701da177e4SLinus Torvalds static void __exit sa1100_mtd_exit(void)
4711da177e4SLinus Torvalds {
472*3ae5eaecSRussell King 	platform_driver_unregister(&sa1100_mtd_driver);
4731da177e4SLinus Torvalds }
4741da177e4SLinus Torvalds 
4751da177e4SLinus Torvalds module_init(sa1100_mtd_init);
4761da177e4SLinus Torvalds module_exit(sa1100_mtd_exit);
4771da177e4SLinus Torvalds 
4781da177e4SLinus Torvalds MODULE_AUTHOR("Nicolas Pitre");
4791da177e4SLinus Torvalds MODULE_DESCRIPTION("SA1100 CFI map driver");
4801da177e4SLinus Torvalds MODULE_LICENSE("GPL");
481