xref: /linux/drivers/mtd/maps/sa1100-flash.c (revision 674c04538284736c4a44224c78cb784b2c972f98)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Flash memory access on SA11x0 based devices
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * (C) 2000 Nicolas Pitre <nico@cam.org>
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * $Id: sa1100-flash.c,v 1.47 2004/11/01 13:44:36 rmk 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>
161da177e4SLinus Torvalds #include <linux/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 
24*674c0453SRussell 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;
1331da177e4SLinus Torvalds 	struct flash_platform_data *data;
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;
1401da177e4SLinus Torvalds 	struct sa_subdev_info	subdev[0];
1411da177e4SLinus Torvalds };
1421da177e4SLinus Torvalds 
1431da177e4SLinus Torvalds static void sa1100_set_vpp(struct map_info *map, int on)
1441da177e4SLinus Torvalds {
1451da177e4SLinus Torvalds 	struct sa_subdev_info *subdev = container_of(map, struct sa_subdev_info, map);
1461da177e4SLinus Torvalds 	subdev->data->set_vpp(on);
1471da177e4SLinus Torvalds }
1481da177e4SLinus Torvalds 
1491da177e4SLinus Torvalds static void sa1100_destroy_subdev(struct sa_subdev_info *subdev)
1501da177e4SLinus Torvalds {
1511da177e4SLinus Torvalds 	if (subdev->mtd)
1521da177e4SLinus Torvalds 		map_destroy(subdev->mtd);
1531da177e4SLinus Torvalds 	if (subdev->map.virt)
1541da177e4SLinus Torvalds 		iounmap(subdev->map.virt);
1551da177e4SLinus Torvalds 	release_mem_region(subdev->map.phys, subdev->map.size);
1561da177e4SLinus Torvalds }
1571da177e4SLinus Torvalds 
1581da177e4SLinus Torvalds static int sa1100_probe_subdev(struct sa_subdev_info *subdev, struct resource *res)
1591da177e4SLinus Torvalds {
1601da177e4SLinus Torvalds 	unsigned long phys;
1611da177e4SLinus Torvalds 	unsigned int size;
1621da177e4SLinus Torvalds 	int ret;
1631da177e4SLinus Torvalds 
1641da177e4SLinus Torvalds 	phys = res->start;
1651da177e4SLinus Torvalds 	size = res->end - phys + 1;
1661da177e4SLinus Torvalds 
1671da177e4SLinus Torvalds 	/*
1681da177e4SLinus Torvalds 	 * Retrieve the bankwidth from the MSC registers.
1691da177e4SLinus Torvalds 	 * We currently only implement CS0 and CS1 here.
1701da177e4SLinus Torvalds 	 */
1711da177e4SLinus Torvalds 	switch (phys) {
1721da177e4SLinus Torvalds 	default:
1731da177e4SLinus Torvalds 		printk(KERN_WARNING "SA1100 flash: unknown base address "
1741da177e4SLinus Torvalds 		       "0x%08lx, assuming CS0\n", phys);
1751da177e4SLinus Torvalds 
1761da177e4SLinus Torvalds 	case SA1100_CS0_PHYS:
1771da177e4SLinus Torvalds 		subdev->map.bankwidth = (MSC0 & MSC_RBW) ? 2 : 4;
1781da177e4SLinus Torvalds 		break;
1791da177e4SLinus Torvalds 
1801da177e4SLinus Torvalds 	case SA1100_CS1_PHYS:
1811da177e4SLinus Torvalds 		subdev->map.bankwidth = ((MSC0 >> 16) & MSC_RBW) ? 2 : 4;
1821da177e4SLinus Torvalds 		break;
1831da177e4SLinus Torvalds 	}
1841da177e4SLinus Torvalds 
1851da177e4SLinus Torvalds 	if (!request_mem_region(phys, size, subdev->name)) {
1861da177e4SLinus Torvalds 		ret = -EBUSY;
1871da177e4SLinus Torvalds 		goto out;
1881da177e4SLinus Torvalds 	}
1891da177e4SLinus Torvalds 
1901da177e4SLinus Torvalds 	if (subdev->data->set_vpp)
1911da177e4SLinus Torvalds 		subdev->map.set_vpp = sa1100_set_vpp;
1921da177e4SLinus Torvalds 
1931da177e4SLinus Torvalds 	subdev->map.phys = phys;
1941da177e4SLinus Torvalds 	subdev->map.size = size;
1951da177e4SLinus Torvalds 	subdev->map.virt = ioremap(phys, size);
1961da177e4SLinus Torvalds 	if (!subdev->map.virt) {
1971da177e4SLinus Torvalds 		ret = -ENOMEM;
1981da177e4SLinus Torvalds 		goto err;
1991da177e4SLinus Torvalds 	}
2001da177e4SLinus Torvalds 
2011da177e4SLinus Torvalds 	simple_map_init(&subdev->map);
2021da177e4SLinus Torvalds 
2031da177e4SLinus Torvalds 	/*
2041da177e4SLinus Torvalds 	 * Now let's probe for the actual flash.  Do it here since
2051da177e4SLinus Torvalds 	 * specific machine settings might have been set above.
2061da177e4SLinus Torvalds 	 */
2071da177e4SLinus Torvalds 	subdev->mtd = do_map_probe(subdev->data->map_name, &subdev->map);
2081da177e4SLinus Torvalds 	if (subdev->mtd == NULL) {
2091da177e4SLinus Torvalds 		ret = -ENXIO;
2101da177e4SLinus Torvalds 		goto err;
2111da177e4SLinus Torvalds 	}
2121da177e4SLinus Torvalds 	subdev->mtd->owner = THIS_MODULE;
2131da177e4SLinus Torvalds 
2141da177e4SLinus Torvalds 	printk(KERN_INFO "SA1100 flash: CFI device at 0x%08lx, %dMiB, "
2151da177e4SLinus Torvalds 		"%d-bit\n", phys, subdev->mtd->size >> 20,
2161da177e4SLinus Torvalds 		subdev->map.bankwidth * 8);
2171da177e4SLinus Torvalds 
2181da177e4SLinus Torvalds 	return 0;
2191da177e4SLinus Torvalds 
2201da177e4SLinus Torvalds  err:
2211da177e4SLinus Torvalds 	sa1100_destroy_subdev(subdev);
2221da177e4SLinus Torvalds  out:
2231da177e4SLinus Torvalds 	return ret;
2241da177e4SLinus Torvalds }
2251da177e4SLinus Torvalds 
2261da177e4SLinus Torvalds static void sa1100_destroy(struct sa_info *info)
2271da177e4SLinus Torvalds {
2281da177e4SLinus Torvalds 	int i;
2291da177e4SLinus Torvalds 
2301da177e4SLinus Torvalds 	if (info->mtd) {
2311da177e4SLinus Torvalds 		del_mtd_partitions(info->mtd);
2321da177e4SLinus Torvalds 
2331da177e4SLinus Torvalds #ifdef CONFIG_MTD_CONCAT
2341da177e4SLinus Torvalds 		if (info->mtd != info->subdev[0].mtd)
2351da177e4SLinus Torvalds 			mtd_concat_destroy(info->mtd);
2361da177e4SLinus Torvalds #endif
2371da177e4SLinus Torvalds 	}
2381da177e4SLinus Torvalds 
2391da177e4SLinus Torvalds 	if (info->parts)
2401da177e4SLinus Torvalds 		kfree(info->parts);
2411da177e4SLinus Torvalds 
2421da177e4SLinus Torvalds 	for (i = info->num_subdev - 1; i >= 0; i--)
2431da177e4SLinus Torvalds 		sa1100_destroy_subdev(&info->subdev[i]);
2441da177e4SLinus Torvalds 	kfree(info);
2451da177e4SLinus Torvalds }
2461da177e4SLinus Torvalds 
2471da177e4SLinus Torvalds static struct sa_info *__init
2481da177e4SLinus Torvalds sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *flash)
2491da177e4SLinus Torvalds {
2501da177e4SLinus Torvalds 	struct sa_info *info;
2511da177e4SLinus Torvalds 	int nr, size, i, ret = 0;
2521da177e4SLinus Torvalds 
2531da177e4SLinus Torvalds 	/*
2541da177e4SLinus Torvalds 	 * Count number of devices.
2551da177e4SLinus Torvalds 	 */
2561da177e4SLinus Torvalds 	for (nr = 0; ; nr++)
2571da177e4SLinus Torvalds 		if (!platform_get_resource(pdev, IORESOURCE_MEM, nr))
2581da177e4SLinus Torvalds 			break;
2591da177e4SLinus Torvalds 
2601da177e4SLinus Torvalds 	if (nr == 0) {
2611da177e4SLinus Torvalds 		ret = -ENODEV;
2621da177e4SLinus Torvalds 		goto out;
2631da177e4SLinus Torvalds 	}
2641da177e4SLinus Torvalds 
2651da177e4SLinus Torvalds 	size = sizeof(struct sa_info) + sizeof(struct sa_subdev_info) * nr;
2661da177e4SLinus Torvalds 
2671da177e4SLinus Torvalds 	/*
2681da177e4SLinus Torvalds 	 * Allocate the map_info structs in one go.
2691da177e4SLinus Torvalds 	 */
2701da177e4SLinus Torvalds 	info = kmalloc(size, GFP_KERNEL);
2711da177e4SLinus Torvalds 	if (!info) {
2721da177e4SLinus Torvalds 		ret = -ENOMEM;
2731da177e4SLinus Torvalds 		goto out;
2741da177e4SLinus Torvalds 	}
2751da177e4SLinus Torvalds 
2761da177e4SLinus Torvalds 	memset(info, 0, size);
2771da177e4SLinus Torvalds 
2781da177e4SLinus Torvalds 	/*
2791da177e4SLinus Torvalds 	 * Claim and then map the memory regions.
2801da177e4SLinus Torvalds 	 */
2811da177e4SLinus Torvalds 	for (i = 0; i < nr; i++) {
2821da177e4SLinus Torvalds 		struct sa_subdev_info *subdev = &info->subdev[i];
2831da177e4SLinus Torvalds 		struct resource *res;
2841da177e4SLinus Torvalds 
2851da177e4SLinus Torvalds 		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
2861da177e4SLinus Torvalds 		if (!res)
2871da177e4SLinus Torvalds 			break;
2881da177e4SLinus Torvalds 
2891da177e4SLinus Torvalds 		subdev->map.name = subdev->name;
2901da177e4SLinus Torvalds 		sprintf(subdev->name, "sa1100-%d", i);
2911da177e4SLinus Torvalds 		subdev->data = flash;
2921da177e4SLinus Torvalds 
2931da177e4SLinus Torvalds 		ret = sa1100_probe_subdev(subdev, res);
2941da177e4SLinus Torvalds 		if (ret)
2951da177e4SLinus Torvalds 			break;
2961da177e4SLinus Torvalds 	}
2971da177e4SLinus Torvalds 
2981da177e4SLinus Torvalds 	info->num_subdev = i;
2991da177e4SLinus Torvalds 
3001da177e4SLinus Torvalds 	/*
3011da177e4SLinus Torvalds 	 * ENXIO is special.  It means we didn't find a chip when we probed.
3021da177e4SLinus Torvalds 	 */
3031da177e4SLinus Torvalds 	if (ret != 0 && !(ret == -ENXIO && info->num_subdev > 0))
3041da177e4SLinus Torvalds 		goto err;
3051da177e4SLinus Torvalds 
3061da177e4SLinus Torvalds 	/*
3071da177e4SLinus Torvalds 	 * If we found one device, don't bother with concat support.  If
3081da177e4SLinus Torvalds 	 * we found multiple devices, use concat if we have it available,
3091da177e4SLinus Torvalds 	 * otherwise fail.  Either way, it'll be called "sa1100".
3101da177e4SLinus Torvalds 	 */
3111da177e4SLinus Torvalds 	if (info->num_subdev == 1) {
3121da177e4SLinus Torvalds 		strcpy(info->subdev[0].name, "sa1100");
3131da177e4SLinus Torvalds 		info->mtd = info->subdev[0].mtd;
3141da177e4SLinus Torvalds 		ret = 0;
3151da177e4SLinus Torvalds 	} else if (info->num_subdev > 1) {
3161da177e4SLinus Torvalds #ifdef CONFIG_MTD_CONCAT
3171da177e4SLinus Torvalds 		struct mtd_info *cdev[nr];
3181da177e4SLinus Torvalds 		/*
3191da177e4SLinus Torvalds 		 * We detected multiple devices.  Concatenate them together.
3201da177e4SLinus Torvalds 		 */
3211da177e4SLinus Torvalds 		for (i = 0; i < info->num_subdev; i++)
3221da177e4SLinus Torvalds 			cdev[i] = info->subdev[i].mtd;
3231da177e4SLinus Torvalds 
3241da177e4SLinus Torvalds 		info->mtd = mtd_concat_create(cdev, info->num_subdev,
3251da177e4SLinus Torvalds 					      "sa1100");
3261da177e4SLinus Torvalds 		if (info->mtd == NULL)
3271da177e4SLinus Torvalds 			ret = -ENXIO;
3281da177e4SLinus Torvalds #else
3291da177e4SLinus Torvalds 		printk(KERN_ERR "SA1100 flash: multiple devices "
3301da177e4SLinus Torvalds 		       "found but MTD concat support disabled.\n");
3311da177e4SLinus Torvalds 		ret = -ENXIO;
3321da177e4SLinus Torvalds #endif
3331da177e4SLinus Torvalds 	}
3341da177e4SLinus Torvalds 
3351da177e4SLinus Torvalds 	if (ret == 0)
3361da177e4SLinus Torvalds 		return info;
3371da177e4SLinus Torvalds 
3381da177e4SLinus Torvalds  err:
3391da177e4SLinus Torvalds 	sa1100_destroy(info);
3401da177e4SLinus Torvalds  out:
3411da177e4SLinus Torvalds 	return ERR_PTR(ret);
3421da177e4SLinus Torvalds }
3431da177e4SLinus Torvalds 
3441da177e4SLinus Torvalds static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
3451da177e4SLinus Torvalds 
3461da177e4SLinus Torvalds static int __init sa1100_mtd_probe(struct device *dev)
3471da177e4SLinus Torvalds {
3481da177e4SLinus Torvalds 	struct platform_device *pdev = to_platform_device(dev);
3491da177e4SLinus Torvalds 	struct flash_platform_data *flash = pdev->dev.platform_data;
3501da177e4SLinus Torvalds 	struct mtd_partition *parts;
3511da177e4SLinus Torvalds 	const char *part_type = NULL;
3521da177e4SLinus Torvalds 	struct sa_info *info;
3531da177e4SLinus Torvalds 	int err, nr_parts = 0;
3541da177e4SLinus Torvalds 
3551da177e4SLinus Torvalds 	if (!flash)
3561da177e4SLinus Torvalds 		return -ENODEV;
3571da177e4SLinus Torvalds 
3581da177e4SLinus Torvalds 	info = sa1100_setup_mtd(pdev, flash);
3591da177e4SLinus Torvalds 	if (IS_ERR(info)) {
3601da177e4SLinus Torvalds 		err = PTR_ERR(info);
3611da177e4SLinus Torvalds 		goto out;
3621da177e4SLinus Torvalds 	}
3631da177e4SLinus Torvalds 
3641da177e4SLinus Torvalds 	/*
3651da177e4SLinus Torvalds 	 * Partition selection stuff.
3661da177e4SLinus Torvalds 	 */
3671da177e4SLinus Torvalds #ifdef CONFIG_MTD_PARTITIONS
3681da177e4SLinus Torvalds 	nr_parts = parse_mtd_partitions(info->mtd, part_probes, &parts, 0);
3691da177e4SLinus Torvalds 	if (nr_parts > 0) {
3701da177e4SLinus Torvalds 		info->parts = parts;
3711da177e4SLinus Torvalds 		part_type = "dynamic";
3721da177e4SLinus Torvalds 	} else
3731da177e4SLinus Torvalds #endif
3741da177e4SLinus Torvalds 	{
3751da177e4SLinus Torvalds 		parts = flash->parts;
3761da177e4SLinus Torvalds 		nr_parts = flash->nr_parts;
3771da177e4SLinus Torvalds 		part_type = "static";
3781da177e4SLinus Torvalds 	}
3791da177e4SLinus Torvalds 
3801da177e4SLinus Torvalds 	if (nr_parts == 0) {
3811da177e4SLinus Torvalds 		printk(KERN_NOTICE "SA1100 flash: no partition info "
3821da177e4SLinus Torvalds 			"available, registering whole flash\n");
3831da177e4SLinus Torvalds 		add_mtd_device(info->mtd);
3841da177e4SLinus Torvalds 	} else {
3851da177e4SLinus Torvalds 		printk(KERN_NOTICE "SA1100 flash: using %s partition "
3861da177e4SLinus Torvalds 			"definition\n", part_type);
3871da177e4SLinus Torvalds 		add_mtd_partitions(info->mtd, parts, nr_parts);
3881da177e4SLinus Torvalds 	}
3891da177e4SLinus Torvalds 
3901da177e4SLinus Torvalds 	dev_set_drvdata(dev, info);
3911da177e4SLinus Torvalds 	err = 0;
3921da177e4SLinus Torvalds 
3931da177e4SLinus Torvalds  out:
3941da177e4SLinus Torvalds 	return err;
3951da177e4SLinus Torvalds }
3961da177e4SLinus Torvalds 
3971da177e4SLinus Torvalds static int __exit sa1100_mtd_remove(struct device *dev)
3981da177e4SLinus Torvalds {
3991da177e4SLinus Torvalds 	struct sa_info *info = dev_get_drvdata(dev);
4001da177e4SLinus Torvalds 	dev_set_drvdata(dev, NULL);
4011da177e4SLinus Torvalds 	sa1100_destroy(info);
4021da177e4SLinus Torvalds 	return 0;
4031da177e4SLinus Torvalds }
4041da177e4SLinus Torvalds 
4051da177e4SLinus Torvalds #ifdef CONFIG_PM
406e5378ca8SPavel Machek static int sa1100_mtd_suspend(struct device *dev, pm_message_t state, u32 level)
4071da177e4SLinus Torvalds {
4081da177e4SLinus Torvalds 	struct sa_info *info = dev_get_drvdata(dev);
4091da177e4SLinus Torvalds 	int ret = 0;
4101da177e4SLinus Torvalds 
4111da177e4SLinus Torvalds 	if (info && level == SUSPEND_SAVE_STATE)
4121da177e4SLinus Torvalds 		ret = info->mtd->suspend(info->mtd);
4131da177e4SLinus Torvalds 
4141da177e4SLinus Torvalds 	return ret;
4151da177e4SLinus Torvalds }
4161da177e4SLinus Torvalds 
4171da177e4SLinus Torvalds static int sa1100_mtd_resume(struct device *dev, u32 level)
4181da177e4SLinus Torvalds {
4191da177e4SLinus Torvalds 	struct sa_info *info = dev_get_drvdata(dev);
4201da177e4SLinus Torvalds 	if (info && level == RESUME_RESTORE_STATE)
4211da177e4SLinus Torvalds 		info->mtd->resume(info->mtd);
4221da177e4SLinus Torvalds 	return 0;
4231da177e4SLinus Torvalds }
4241da177e4SLinus Torvalds #else
4251da177e4SLinus Torvalds #define sa1100_mtd_suspend NULL
4261da177e4SLinus Torvalds #define sa1100_mtd_resume  NULL
4271da177e4SLinus Torvalds #endif
4281da177e4SLinus Torvalds 
4291da177e4SLinus Torvalds static struct device_driver sa1100_mtd_driver = {
4301da177e4SLinus Torvalds 	.name		= "flash",
4311da177e4SLinus Torvalds 	.bus		= &platform_bus_type,
4321da177e4SLinus Torvalds 	.probe		= sa1100_mtd_probe,
4331da177e4SLinus Torvalds 	.remove		= __exit_p(sa1100_mtd_remove),
4341da177e4SLinus Torvalds 	.suspend	= sa1100_mtd_suspend,
4351da177e4SLinus Torvalds 	.resume		= sa1100_mtd_resume,
4361da177e4SLinus Torvalds };
4371da177e4SLinus Torvalds 
4381da177e4SLinus Torvalds static int __init sa1100_mtd_init(void)
4391da177e4SLinus Torvalds {
4401da177e4SLinus Torvalds 	return driver_register(&sa1100_mtd_driver);
4411da177e4SLinus Torvalds }
4421da177e4SLinus Torvalds 
4431da177e4SLinus Torvalds static void __exit sa1100_mtd_exit(void)
4441da177e4SLinus Torvalds {
4451da177e4SLinus Torvalds 	driver_unregister(&sa1100_mtd_driver);
4461da177e4SLinus Torvalds }
4471da177e4SLinus Torvalds 
4481da177e4SLinus Torvalds module_init(sa1100_mtd_init);
4491da177e4SLinus Torvalds module_exit(sa1100_mtd_exit);
4501da177e4SLinus Torvalds 
4511da177e4SLinus Torvalds MODULE_AUTHOR("Nicolas Pitre");
4521da177e4SLinus Torvalds MODULE_DESCRIPTION("SA1100 CFI map driver");
4531da177e4SLinus Torvalds MODULE_LICENSE("GPL");
454