xref: /openbmc/linux/drivers/mtd/maps/nettel.c (revision 8dd06ef34b6e2f41b29fbf5fc1663780f2524285)
109c434b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
21da177e4SLinus Torvalds /****************************************************************************/
31da177e4SLinus Torvalds 
41da177e4SLinus Torvalds /*
51da177e4SLinus Torvalds  *      nettel.c -- mappings for NETtel/SecureEdge/SnapGear (x86) boards.
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  *      (C) Copyright 2000-2001, Greg Ungerer (gerg@snapgear.com)
81da177e4SLinus Torvalds  *      (C) Copyright 2001-2002, SnapGear (www.snapgear.com)
91da177e4SLinus Torvalds  */
101da177e4SLinus Torvalds 
111da177e4SLinus Torvalds /****************************************************************************/
121da177e4SLinus Torvalds 
131da177e4SLinus Torvalds #include <linux/module.h>
141da177e4SLinus Torvalds #include <linux/init.h>
151da177e4SLinus Torvalds #include <linux/types.h>
161da177e4SLinus Torvalds #include <linux/kernel.h>
171da177e4SLinus Torvalds #include <linux/mtd/mtd.h>
181da177e4SLinus Torvalds #include <linux/mtd/map.h>
191da177e4SLinus Torvalds #include <linux/mtd/partitions.h>
201da177e4SLinus Torvalds #include <linux/mtd/cfi.h>
211da177e4SLinus Torvalds #include <linux/reboot.h>
229c74034fSArtem Bityutskiy #include <linux/err.h>
236cc449c7SJesper Juhl #include <linux/kdev_t.h>
246cc449c7SJesper Juhl #include <linux/root_dev.h>
251da177e4SLinus Torvalds #include <asm/io.h>
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds /****************************************************************************/
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds #define INTEL_BUSWIDTH		1
301da177e4SLinus Torvalds #define AMD_WINDOW_MAXSIZE	0x00200000
311da177e4SLinus Torvalds #define AMD_BUSWIDTH	 	1
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds /*
341da177e4SLinus Torvalds  *	PAR masks and shifts, assuming 64K pages.
351da177e4SLinus Torvalds  */
361da177e4SLinus Torvalds #define SC520_PAR_ADDR_MASK	0x00003fff
371da177e4SLinus Torvalds #define SC520_PAR_ADDR_SHIFT	16
381da177e4SLinus Torvalds #define SC520_PAR_TO_ADDR(par) \
391da177e4SLinus Torvalds 	(((par)&SC520_PAR_ADDR_MASK) << SC520_PAR_ADDR_SHIFT)
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds #define SC520_PAR_SIZE_MASK	0x01ffc000
421da177e4SLinus Torvalds #define SC520_PAR_SIZE_SHIFT	2
431da177e4SLinus Torvalds #define SC520_PAR_TO_SIZE(par) \
441da177e4SLinus Torvalds 	((((par)&SC520_PAR_SIZE_MASK) << SC520_PAR_SIZE_SHIFT) + (64*1024))
451da177e4SLinus Torvalds 
461da177e4SLinus Torvalds #define SC520_PAR(cs, addr, size) \
471da177e4SLinus Torvalds 	((cs) | \
481da177e4SLinus Torvalds 	((((size)-(64*1024)) >> SC520_PAR_SIZE_SHIFT) & SC520_PAR_SIZE_MASK) | \
491da177e4SLinus Torvalds 	(((addr) >> SC520_PAR_ADDR_SHIFT) & SC520_PAR_ADDR_MASK))
501da177e4SLinus Torvalds 
511da177e4SLinus Torvalds #define SC520_PAR_BOOTCS	0x8a000000
521da177e4SLinus Torvalds #define	SC520_PAR_ROMCS1	0xaa000000
531da177e4SLinus Torvalds #define SC520_PAR_ROMCS2	0xca000000	/* Cache disabled, 64K page */
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds static void *nettel_mmcrp = NULL;
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds #ifdef CONFIG_MTD_CFI_INTELEXT
581da177e4SLinus Torvalds static struct mtd_info *intel_mtd;
591da177e4SLinus Torvalds #endif
601da177e4SLinus Torvalds static struct mtd_info *amd_mtd;
611da177e4SLinus Torvalds 
621da177e4SLinus Torvalds /****************************************************************************/
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds /****************************************************************************/
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds #ifdef CONFIG_MTD_CFI_INTELEXT
671da177e4SLinus Torvalds static struct map_info nettel_intel_map = {
681da177e4SLinus Torvalds 	.name = "SnapGear Intel",
691da177e4SLinus Torvalds 	.size = 0,
701da177e4SLinus Torvalds 	.bankwidth = INTEL_BUSWIDTH,
711da177e4SLinus Torvalds };
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds static struct mtd_partition nettel_intel_partitions[] = {
741da177e4SLinus Torvalds 	{
751da177e4SLinus Torvalds 		.name = "SnapGear kernel",
761da177e4SLinus Torvalds 		.offset = 0,
771da177e4SLinus Torvalds 		.size = 0x000e0000
781da177e4SLinus Torvalds 	},
791da177e4SLinus Torvalds 	{
801da177e4SLinus Torvalds 		.name = "SnapGear filesystem",
811da177e4SLinus Torvalds 		.offset = 0x00100000,
821da177e4SLinus Torvalds 	},
831da177e4SLinus Torvalds 	{
841da177e4SLinus Torvalds 		.name = "SnapGear config",
851da177e4SLinus Torvalds 		.offset = 0x000e0000,
861da177e4SLinus Torvalds 		.size = 0x00020000
871da177e4SLinus Torvalds 	},
881da177e4SLinus Torvalds 	{
891da177e4SLinus Torvalds 		.name = "SnapGear Intel",
901da177e4SLinus Torvalds 		.offset = 0
911da177e4SLinus Torvalds 	},
921da177e4SLinus Torvalds 	{
931da177e4SLinus Torvalds 		.name = "SnapGear BIOS Config",
941da177e4SLinus Torvalds 		.offset = 0x007e0000,
951da177e4SLinus Torvalds 		.size = 0x00020000
961da177e4SLinus Torvalds 	},
971da177e4SLinus Torvalds 	{
981da177e4SLinus Torvalds 		.name = "SnapGear BIOS",
991da177e4SLinus Torvalds 		.offset = 0x007e0000,
1001da177e4SLinus Torvalds 		.size = 0x00020000
1011da177e4SLinus Torvalds 	},
1021da177e4SLinus Torvalds };
1031da177e4SLinus Torvalds #endif
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds static struct map_info nettel_amd_map = {
1061da177e4SLinus Torvalds 	.name = "SnapGear AMD",
1071da177e4SLinus Torvalds 	.size = AMD_WINDOW_MAXSIZE,
1081da177e4SLinus Torvalds 	.bankwidth = AMD_BUSWIDTH,
1091da177e4SLinus Torvalds };
1101da177e4SLinus Torvalds 
111d4906688SArvind Yadav static const struct mtd_partition nettel_amd_partitions[] = {
1121da177e4SLinus Torvalds 	{
1131da177e4SLinus Torvalds 		.name = "SnapGear BIOS config",
1141da177e4SLinus Torvalds 		.offset = 0x000e0000,
1151da177e4SLinus Torvalds 		.size = 0x00010000
1161da177e4SLinus Torvalds 	},
1171da177e4SLinus Torvalds 	{
1181da177e4SLinus Torvalds 		.name = "SnapGear BIOS",
1191da177e4SLinus Torvalds 		.offset = 0x000f0000,
1201da177e4SLinus Torvalds 		.size = 0x00010000
1211da177e4SLinus Torvalds 	},
1221da177e4SLinus Torvalds 	{
1231da177e4SLinus Torvalds 		.name = "SnapGear AMD",
1241da177e4SLinus Torvalds 		.offset = 0
1251da177e4SLinus Torvalds 	},
1261da177e4SLinus Torvalds 	{
1271da177e4SLinus Torvalds 		.name = "SnapGear high BIOS",
1281da177e4SLinus Torvalds 		.offset = 0x001f0000,
1291da177e4SLinus Torvalds 		.size = 0x00010000
1301da177e4SLinus Torvalds 	}
1311da177e4SLinus Torvalds };
1321da177e4SLinus Torvalds 
13387d10f3cSTobias Klauser #define NUM_AMD_PARTITIONS ARRAY_SIZE(nettel_amd_partitions)
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds /****************************************************************************/
1361da177e4SLinus Torvalds 
1371da177e4SLinus Torvalds #ifdef CONFIG_MTD_CFI_INTELEXT
1381da177e4SLinus Torvalds 
1391da177e4SLinus Torvalds /*
1401da177e4SLinus Torvalds  *	Set the Intel flash back to read mode since some old boot
1411da177e4SLinus Torvalds  *	loaders don't.
1421da177e4SLinus Torvalds  */
nettel_reboot_notifier(struct notifier_block * nb,unsigned long val,void * v)1431da177e4SLinus Torvalds static int nettel_reboot_notifier(struct notifier_block *nb, unsigned long val, void *v)
1441da177e4SLinus Torvalds {
1451da177e4SLinus Torvalds 	struct cfi_private *cfi = nettel_intel_map.fldrv_priv;
1461da177e4SLinus Torvalds 	unsigned long b;
1471da177e4SLinus Torvalds 
1481da177e4SLinus Torvalds 	/* Make sure all FLASH chips are put back into read mode */
1491da177e4SLinus Torvalds 	for (b = 0; (b < nettel_intel_partitions[3].size); b += 0x100000) {
1501da177e4SLinus Torvalds 		cfi_send_gen_cmd(0xff, 0x55, b, &nettel_intel_map, cfi,
1511da177e4SLinus Torvalds 			cfi->device_type, NULL);
1521da177e4SLinus Torvalds 	}
1531da177e4SLinus Torvalds 	return(NOTIFY_OK);
1541da177e4SLinus Torvalds }
1551da177e4SLinus Torvalds 
1561da177e4SLinus Torvalds static struct notifier_block nettel_notifier_block = {
1571da177e4SLinus Torvalds 	nettel_reboot_notifier, NULL, 0
1581da177e4SLinus Torvalds };
1591da177e4SLinus Torvalds 
1601da177e4SLinus Torvalds #endif
1611da177e4SLinus Torvalds 
1621da177e4SLinus Torvalds /****************************************************************************/
1631da177e4SLinus Torvalds 
nettel_init(void)164663d77a7SAdrian Bunk static int __init nettel_init(void)
1651da177e4SLinus Torvalds {
1661da177e4SLinus Torvalds 	volatile unsigned long *amdpar;
1671da177e4SLinus Torvalds 	unsigned long amdaddr, maxsize;
1681da177e4SLinus Torvalds 	int num_amd_partitions=0;
1691da177e4SLinus Torvalds #ifdef CONFIG_MTD_CFI_INTELEXT
1701da177e4SLinus Torvalds 	volatile unsigned long *intel0par, *intel1par;
1711da177e4SLinus Torvalds 	unsigned long orig_bootcspar, orig_romcs1par;
1721da177e4SLinus Torvalds 	unsigned long intel0addr, intel0size;
1731da177e4SLinus Torvalds 	unsigned long intel1addr, intel1size;
1741da177e4SLinus Torvalds 	int intelboot, intel0cs, intel1cs;
1751da177e4SLinus Torvalds 	int num_intel_partitions;
1761da177e4SLinus Torvalds #endif
1771da177e4SLinus Torvalds 	int rc = 0;
1781da177e4SLinus Torvalds 
179*4bdc0d67SChristoph Hellwig 	nettel_mmcrp = (void *) ioremap(0xfffef000, 4096);
1801da177e4SLinus Torvalds 	if (nettel_mmcrp == NULL) {
1811da177e4SLinus Torvalds 		printk("SNAPGEAR: failed to disable MMCR cache??\n");
1821da177e4SLinus Torvalds 		return(-EIO);
1831da177e4SLinus Torvalds 	}
1841da177e4SLinus Torvalds 
1851da177e4SLinus Torvalds 	/* Set CPU clock to be 33.000MHz */
1861da177e4SLinus Torvalds 	*((unsigned char *) (nettel_mmcrp + 0xc64)) = 0x01;
1871da177e4SLinus Torvalds 
1881da177e4SLinus Torvalds 	amdpar = (volatile unsigned long *) (nettel_mmcrp + 0xc4);
1891da177e4SLinus Torvalds 
1901da177e4SLinus Torvalds #ifdef CONFIG_MTD_CFI_INTELEXT
1911da177e4SLinus Torvalds 	intelboot = 0;
1921da177e4SLinus Torvalds 	intel0cs = SC520_PAR_ROMCS1;
1931da177e4SLinus Torvalds 	intel0par = (volatile unsigned long *) (nettel_mmcrp + 0xc0);
1941da177e4SLinus Torvalds 	intel1cs = SC520_PAR_ROMCS2;
1951da177e4SLinus Torvalds 	intel1par = (volatile unsigned long *) (nettel_mmcrp + 0xbc);
1961da177e4SLinus Torvalds 
1971da177e4SLinus Torvalds 	/*
1981da177e4SLinus Torvalds 	 *	Save the CS settings then ensure ROMCS1 and ROMCS2 are off,
1991da177e4SLinus Torvalds 	 *	otherwise they might clash with where we try to map BOOTCS.
2001da177e4SLinus Torvalds 	 */
2011da177e4SLinus Torvalds 	orig_bootcspar = *amdpar;
2021da177e4SLinus Torvalds 	orig_romcs1par = *intel0par;
2031da177e4SLinus Torvalds 	*intel0par = 0;
2041da177e4SLinus Torvalds 	*intel1par = 0;
2051da177e4SLinus Torvalds #endif
2061da177e4SLinus Torvalds 
2071da177e4SLinus Torvalds 	/*
2081da177e4SLinus Torvalds 	 *	The first thing to do is determine if we have a separate
2091da177e4SLinus Torvalds 	 *	boot FLASH device. Typically this is a small (1 to 2MB)
2101da177e4SLinus Torvalds 	 *	AMD FLASH part. It seems that device size is about the
2111da177e4SLinus Torvalds 	 *	only way to tell if this is the case...
2121da177e4SLinus Torvalds 	 */
2131da177e4SLinus Torvalds 	amdaddr = 0x20000000;
2141da177e4SLinus Torvalds 	maxsize = AMD_WINDOW_MAXSIZE;
2151da177e4SLinus Torvalds 
2161da177e4SLinus Torvalds 	*amdpar = SC520_PAR(SC520_PAR_BOOTCS, amdaddr, maxsize);
2171da177e4SLinus Torvalds 	__asm__ ("wbinvd");
2181da177e4SLinus Torvalds 
2191da177e4SLinus Torvalds 	nettel_amd_map.phys = amdaddr;
220*4bdc0d67SChristoph Hellwig 	nettel_amd_map.virt = ioremap(amdaddr, maxsize);
2211da177e4SLinus Torvalds 	if (!nettel_amd_map.virt) {
2221da177e4SLinus Torvalds 		printk("SNAPGEAR: failed to ioremap() BOOTCS\n");
22325f0c659SAmol Lad 		iounmap(nettel_mmcrp);
2241da177e4SLinus Torvalds 		return(-EIO);
2251da177e4SLinus Torvalds 	}
2261da177e4SLinus Torvalds 	simple_map_init(&nettel_amd_map);
2271da177e4SLinus Torvalds 
2281da177e4SLinus Torvalds 	if ((amd_mtd = do_map_probe("jedec_probe", &nettel_amd_map))) {
2291da177e4SLinus Torvalds 		printk(KERN_NOTICE "SNAPGEAR: AMD flash device size = %dK\n",
23069423d99SAdrian Hunter 			(int)(amd_mtd->size>>10));
2311da177e4SLinus Torvalds 
2321da177e4SLinus Torvalds 		amd_mtd->owner = THIS_MODULE;
2331da177e4SLinus Torvalds 
2341da177e4SLinus Torvalds 		/* The high BIOS partition is only present for 2MB units */
2351da177e4SLinus Torvalds 		num_amd_partitions = NUM_AMD_PARTITIONS;
2361da177e4SLinus Torvalds 		if (amd_mtd->size < AMD_WINDOW_MAXSIZE)
2371da177e4SLinus Torvalds 			num_amd_partitions--;
2381da177e4SLinus Torvalds 		/* Don't add the partition until after the primary INTEL's */
2391da177e4SLinus Torvalds 
2401da177e4SLinus Torvalds #ifdef CONFIG_MTD_CFI_INTELEXT
2411da177e4SLinus Torvalds 		/*
2421da177e4SLinus Torvalds 		 *	Map the Intel flash into memory after the AMD
2431da177e4SLinus Torvalds 		 *	It has to start on a multiple of maxsize.
2441da177e4SLinus Torvalds 		 */
2451da177e4SLinus Torvalds 		maxsize = SC520_PAR_TO_SIZE(orig_romcs1par);
2461da177e4SLinus Torvalds 		if (maxsize < (32 * 1024 * 1024))
2471da177e4SLinus Torvalds 			maxsize = (32 * 1024 * 1024);
2481da177e4SLinus Torvalds 		intel0addr = amdaddr + maxsize;
2491da177e4SLinus Torvalds #endif
2501da177e4SLinus Torvalds 	} else {
2511da177e4SLinus Torvalds #ifdef CONFIG_MTD_CFI_INTELEXT
2521da177e4SLinus Torvalds 		/* INTEL boot FLASH */
2531da177e4SLinus Torvalds 		intelboot++;
2541da177e4SLinus Torvalds 
2551da177e4SLinus Torvalds 		if (!orig_romcs1par) {
2561da177e4SLinus Torvalds 			intel0cs = SC520_PAR_BOOTCS;
2571da177e4SLinus Torvalds 			intel0par = (volatile unsigned long *)
2581da177e4SLinus Torvalds 				(nettel_mmcrp + 0xc4);
2591da177e4SLinus Torvalds 			intel1cs = SC520_PAR_ROMCS1;
2601da177e4SLinus Torvalds 			intel1par = (volatile unsigned long *)
2611da177e4SLinus Torvalds 				(nettel_mmcrp + 0xc0);
2621da177e4SLinus Torvalds 
2631da177e4SLinus Torvalds 			intel0addr = SC520_PAR_TO_ADDR(orig_bootcspar);
2641da177e4SLinus Torvalds 			maxsize = SC520_PAR_TO_SIZE(orig_bootcspar);
2651da177e4SLinus Torvalds 		} else {
2661da177e4SLinus Torvalds 			/* Kernel base is on ROMCS1, not BOOTCS */
2671da177e4SLinus Torvalds 			intel0cs = SC520_PAR_ROMCS1;
2681da177e4SLinus Torvalds 			intel0par = (volatile unsigned long *)
2691da177e4SLinus Torvalds 				(nettel_mmcrp + 0xc0);
2701da177e4SLinus Torvalds 			intel1cs = SC520_PAR_BOOTCS;
2711da177e4SLinus Torvalds 			intel1par = (volatile unsigned long *)
2721da177e4SLinus Torvalds 				(nettel_mmcrp + 0xc4);
2731da177e4SLinus Torvalds 
2741da177e4SLinus Torvalds 			intel0addr = SC520_PAR_TO_ADDR(orig_romcs1par);
2751da177e4SLinus Torvalds 			maxsize = SC520_PAR_TO_SIZE(orig_romcs1par);
2761da177e4SLinus Torvalds 		}
2771da177e4SLinus Torvalds 
2781da177e4SLinus Torvalds 		/* Destroy useless AMD MTD mapping */
2791da177e4SLinus Torvalds 		amd_mtd = NULL;
2801da177e4SLinus Torvalds 		iounmap(nettel_amd_map.virt);
2811da177e4SLinus Torvalds 		nettel_amd_map.virt = NULL;
2821da177e4SLinus Torvalds #else
2831da177e4SLinus Torvalds 		/* Only AMD flash supported */
28425f0c659SAmol Lad 		rc = -ENXIO;
28525f0c659SAmol Lad 		goto out_unmap2;
2861da177e4SLinus Torvalds #endif
2871da177e4SLinus Torvalds 	}
2881da177e4SLinus Torvalds 
2891da177e4SLinus Torvalds #ifdef CONFIG_MTD_CFI_INTELEXT
2901da177e4SLinus Torvalds 	/*
2911da177e4SLinus Torvalds 	 *	We have determined the INTEL FLASH configuration, so lets
2921da177e4SLinus Torvalds 	 *	go ahead and probe for them now.
2931da177e4SLinus Torvalds 	 */
2941da177e4SLinus Torvalds 
2951da177e4SLinus Torvalds 	/* Set PAR to the maximum size */
2961da177e4SLinus Torvalds 	if (maxsize < (32 * 1024 * 1024))
2971da177e4SLinus Torvalds 		maxsize = (32 * 1024 * 1024);
2981da177e4SLinus Torvalds 	*intel0par = SC520_PAR(intel0cs, intel0addr, maxsize);
2991da177e4SLinus Torvalds 
3001da177e4SLinus Torvalds 	/* Turn other PAR off so the first probe doesn't find it */
3011da177e4SLinus Torvalds 	*intel1par = 0;
3021da177e4SLinus Torvalds 
30359c51591SMichael Opdenacker 	/* Probe for the size of the first Intel flash */
3041da177e4SLinus Torvalds 	nettel_intel_map.size = maxsize;
3051da177e4SLinus Torvalds 	nettel_intel_map.phys = intel0addr;
306*4bdc0d67SChristoph Hellwig 	nettel_intel_map.virt = ioremap(intel0addr, maxsize);
3071da177e4SLinus Torvalds 	if (!nettel_intel_map.virt) {
3081da177e4SLinus Torvalds 		printk("SNAPGEAR: failed to ioremap() ROMCS1\n");
30925f0c659SAmol Lad 		rc = -EIO;
31025f0c659SAmol Lad 		goto out_unmap2;
3111da177e4SLinus Torvalds 	}
3121da177e4SLinus Torvalds 	simple_map_init(&nettel_intel_map);
3131da177e4SLinus Torvalds 
3141da177e4SLinus Torvalds 	intel_mtd = do_map_probe("cfi_probe", &nettel_intel_map);
3151da177e4SLinus Torvalds 	if (!intel_mtd) {
31625f0c659SAmol Lad 		rc = -ENXIO;
31725f0c659SAmol Lad 		goto out_unmap1;
3181da177e4SLinus Torvalds 	}
3191da177e4SLinus Torvalds 
3201da177e4SLinus Torvalds 	/* Set PAR to the detected size */
3211da177e4SLinus Torvalds 	intel0size = intel_mtd->size;
3221da177e4SLinus Torvalds 	*intel0par = SC520_PAR(intel0cs, intel0addr, intel0size);
3231da177e4SLinus Torvalds 
3241da177e4SLinus Torvalds 	/*
3251da177e4SLinus Torvalds 	 *	Map second Intel FLASH right after first. Set its size to the
3261da177e4SLinus Torvalds 	 *	same maxsize used for the first Intel FLASH.
3271da177e4SLinus Torvalds 	 */
3281da177e4SLinus Torvalds 	intel1addr = intel0addr + intel0size;
3291da177e4SLinus Torvalds 	*intel1par = SC520_PAR(intel1cs, intel1addr, maxsize);
3301da177e4SLinus Torvalds 	__asm__ ("wbinvd");
3311da177e4SLinus Torvalds 
3321da177e4SLinus Torvalds 	maxsize += intel0size;
3331da177e4SLinus Torvalds 
3341da177e4SLinus Torvalds 	/* Delete the old map and probe again to do both chips */
3351da177e4SLinus Torvalds 	map_destroy(intel_mtd);
3361da177e4SLinus Torvalds 	intel_mtd = NULL;
3371da177e4SLinus Torvalds 	iounmap(nettel_intel_map.virt);
3381da177e4SLinus Torvalds 
3391da177e4SLinus Torvalds 	nettel_intel_map.size = maxsize;
340*4bdc0d67SChristoph Hellwig 	nettel_intel_map.virt = ioremap(intel0addr, maxsize);
3411da177e4SLinus Torvalds 	if (!nettel_intel_map.virt) {
3421da177e4SLinus Torvalds 		printk("SNAPGEAR: failed to ioremap() ROMCS1/2\n");
34325f0c659SAmol Lad 		rc = -EIO;
34425f0c659SAmol Lad 		goto out_unmap2;
3451da177e4SLinus Torvalds 	}
3461da177e4SLinus Torvalds 
3471da177e4SLinus Torvalds 	intel_mtd = do_map_probe("cfi_probe", &nettel_intel_map);
3481da177e4SLinus Torvalds 	if (! intel_mtd) {
34925f0c659SAmol Lad 		rc = -ENXIO;
35025f0c659SAmol Lad 		goto out_unmap1;
3511da177e4SLinus Torvalds 	}
3521da177e4SLinus Torvalds 
3531da177e4SLinus Torvalds 	intel1size = intel_mtd->size - intel0size;
3541da177e4SLinus Torvalds 	if (intel1size > 0) {
3551da177e4SLinus Torvalds 		*intel1par = SC520_PAR(intel1cs, intel1addr, intel1size);
3561da177e4SLinus Torvalds 		__asm__ ("wbinvd");
3571da177e4SLinus Torvalds 	} else {
3581da177e4SLinus Torvalds 		*intel1par = 0;
3591da177e4SLinus Torvalds 	}
3601da177e4SLinus Torvalds 
36185795dacSDavid Woodhouse 	printk(KERN_NOTICE "SNAPGEAR: Intel flash device size = %lldKiB\n",
36285795dacSDavid Woodhouse 	       (unsigned long long)(intel_mtd->size >> 10));
3631da177e4SLinus Torvalds 
3641da177e4SLinus Torvalds 	intel_mtd->owner = THIS_MODULE;
3651da177e4SLinus Torvalds 
366002f6aabSJulia Lawall 	num_intel_partitions = ARRAY_SIZE(nettel_intel_partitions);
3671da177e4SLinus Torvalds 
3681da177e4SLinus Torvalds 	if (intelboot) {
3691da177e4SLinus Torvalds 		/*
3701da177e4SLinus Torvalds 		 *	Adjust offset and size of last boot partition.
3711da177e4SLinus Torvalds 		 *	Must allow for BIOS region at end of FLASH.
3721da177e4SLinus Torvalds 		 */
3731da177e4SLinus Torvalds 		nettel_intel_partitions[1].size = (intel0size + intel1size) -
3741da177e4SLinus Torvalds 			(1024*1024 + intel_mtd->erasesize);
3751da177e4SLinus Torvalds 		nettel_intel_partitions[3].size = intel0size + intel1size;
3761da177e4SLinus Torvalds 		nettel_intel_partitions[4].offset =
3771da177e4SLinus Torvalds 			(intel0size + intel1size) - intel_mtd->erasesize;
3781da177e4SLinus Torvalds 		nettel_intel_partitions[4].size = intel_mtd->erasesize;
3791da177e4SLinus Torvalds 		nettel_intel_partitions[5].offset =
3801da177e4SLinus Torvalds 			nettel_intel_partitions[4].offset;
3811da177e4SLinus Torvalds 		nettel_intel_partitions[5].size =
3821da177e4SLinus Torvalds 			nettel_intel_partitions[4].size;
3831da177e4SLinus Torvalds 	} else {
3841da177e4SLinus Torvalds 		/* No BIOS regions when AMD boot */
3851da177e4SLinus Torvalds 		num_intel_partitions -= 2;
3861da177e4SLinus Torvalds 	}
387ee0e87b1SJamie Iles 	rc = mtd_device_register(intel_mtd, nettel_intel_partitions,
3881da177e4SLinus Torvalds 				 num_intel_partitions);
38911c7e0e2SAlexey Khoroshilov 	if (rc)
39011c7e0e2SAlexey Khoroshilov 		goto out_map_destroy;
3911da177e4SLinus Torvalds #endif
3921da177e4SLinus Torvalds 
3931da177e4SLinus Torvalds 	if (amd_mtd) {
394ee0e87b1SJamie Iles 		rc = mtd_device_register(amd_mtd, nettel_amd_partitions,
3951da177e4SLinus Torvalds 					 num_amd_partitions);
39611c7e0e2SAlexey Khoroshilov 		if (rc)
39711c7e0e2SAlexey Khoroshilov 			goto out_mtd_unreg;
3981da177e4SLinus Torvalds 	}
3991da177e4SLinus Torvalds 
4001da177e4SLinus Torvalds #ifdef CONFIG_MTD_CFI_INTELEXT
4011da177e4SLinus Torvalds 	register_reboot_notifier(&nettel_notifier_block);
4021da177e4SLinus Torvalds #endif
4031da177e4SLinus Torvalds 
40411c7e0e2SAlexey Khoroshilov 	return rc;
40525f0c659SAmol Lad 
40611c7e0e2SAlexey Khoroshilov out_mtd_unreg:
40725f0c659SAmol Lad #ifdef CONFIG_MTD_CFI_INTELEXT
40811c7e0e2SAlexey Khoroshilov 	mtd_device_unregister(intel_mtd);
40911c7e0e2SAlexey Khoroshilov out_map_destroy:
41011c7e0e2SAlexey Khoroshilov 	map_destroy(intel_mtd);
41125f0c659SAmol Lad out_unmap1:
41276a5027cSAmol Lad 	iounmap(nettel_intel_map.virt);
41325f0c659SAmol Lad #endif
41425f0c659SAmol Lad 
41525f0c659SAmol Lad out_unmap2:
41625f0c659SAmol Lad 	iounmap(nettel_mmcrp);
41725f0c659SAmol Lad 	iounmap(nettel_amd_map.virt);
41825f0c659SAmol Lad 
41911c7e0e2SAlexey Khoroshilov 	return rc;
4201da177e4SLinus Torvalds }
4211da177e4SLinus Torvalds 
4221da177e4SLinus Torvalds /****************************************************************************/
4231da177e4SLinus Torvalds 
nettel_cleanup(void)424663d77a7SAdrian Bunk static void __exit nettel_cleanup(void)
4251da177e4SLinus Torvalds {
4261da177e4SLinus Torvalds #ifdef CONFIG_MTD_CFI_INTELEXT
4271da177e4SLinus Torvalds 	unregister_reboot_notifier(&nettel_notifier_block);
4281da177e4SLinus Torvalds #endif
4291da177e4SLinus Torvalds 	if (amd_mtd) {
430ee0e87b1SJamie Iles 		mtd_device_unregister(amd_mtd);
4311da177e4SLinus Torvalds 		map_destroy(amd_mtd);
4321da177e4SLinus Torvalds 	}
43325f0c659SAmol Lad 	if (nettel_mmcrp) {
43425f0c659SAmol Lad 		iounmap(nettel_mmcrp);
43525f0c659SAmol Lad 		nettel_mmcrp = NULL;
43625f0c659SAmol Lad 	}
4371da177e4SLinus Torvalds 	if (nettel_amd_map.virt) {
4381da177e4SLinus Torvalds 		iounmap(nettel_amd_map.virt);
4391da177e4SLinus Torvalds 		nettel_amd_map.virt = NULL;
4401da177e4SLinus Torvalds 	}
4411da177e4SLinus Torvalds #ifdef CONFIG_MTD_CFI_INTELEXT
4421da177e4SLinus Torvalds 	if (intel_mtd) {
443ee0e87b1SJamie Iles 		mtd_device_unregister(intel_mtd);
4441da177e4SLinus Torvalds 		map_destroy(intel_mtd);
4451da177e4SLinus Torvalds 	}
4461da177e4SLinus Torvalds 	if (nettel_intel_map.virt) {
4471da177e4SLinus Torvalds 		iounmap(nettel_intel_map.virt);
448e2602b34SLuiz Capitulino 		nettel_intel_map.virt = NULL;
4491da177e4SLinus Torvalds 	}
4501da177e4SLinus Torvalds #endif
4511da177e4SLinus Torvalds }
4521da177e4SLinus Torvalds 
4531da177e4SLinus Torvalds /****************************************************************************/
4541da177e4SLinus Torvalds 
4551da177e4SLinus Torvalds module_init(nettel_init);
4561da177e4SLinus Torvalds module_exit(nettel_cleanup);
4571da177e4SLinus Torvalds 
4581da177e4SLinus Torvalds MODULE_LICENSE("GPL");
4591da177e4SLinus Torvalds MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
4601da177e4SLinus Torvalds MODULE_DESCRIPTION("SnapGear/SecureEdge FLASH support");
4611da177e4SLinus Torvalds 
4621da177e4SLinus Torvalds /****************************************************************************/
463