xref: /openbmc/linux/drivers/mtd/maps/cfi_flagadm.c (revision 1da177e4)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *  Copyright � 2001 Flaga hf. Medical Devices, K�ri Dav��sson <kd@flaga.is>
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *  $Id: cfi_flagadm.c,v 1.14 2004/11/04 13:24:14 gleixner Exp $
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *  This program is free software; you can redistribute  it and/or modify it
71da177e4SLinus Torvalds  *  under  the terms of  the GNU General  Public License as published by the
81da177e4SLinus Torvalds  *  Free Software Foundation;  either version 2 of the  License, or (at your
91da177e4SLinus Torvalds  *  option) any later version.
101da177e4SLinus Torvalds  *
111da177e4SLinus Torvalds  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
121da177e4SLinus Torvalds  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
131da177e4SLinus Torvalds  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
141da177e4SLinus Torvalds  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
151da177e4SLinus Torvalds  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
161da177e4SLinus Torvalds  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
171da177e4SLinus Torvalds  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
181da177e4SLinus Torvalds  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
191da177e4SLinus Torvalds  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
201da177e4SLinus Torvalds  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
211da177e4SLinus Torvalds  *
221da177e4SLinus Torvalds  *  You should have received a copy of the  GNU General Public License along
231da177e4SLinus Torvalds  *  with this program; if not, write  to the Free Software Foundation, Inc.,
241da177e4SLinus Torvalds  *  675 Mass Ave, Cambridge, MA 02139, USA.
251da177e4SLinus Torvalds  */
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds #include <linux/module.h>
281da177e4SLinus Torvalds #include <linux/types.h>
291da177e4SLinus Torvalds #include <linux/kernel.h>
301da177e4SLinus Torvalds #include <linux/init.h>
311da177e4SLinus Torvalds #include <asm/io.h>
321da177e4SLinus Torvalds #include <linux/mtd/mtd.h>
331da177e4SLinus Torvalds #include <linux/mtd/map.h>
341da177e4SLinus Torvalds #include <linux/mtd/partitions.h>
351da177e4SLinus Torvalds 
361da177e4SLinus Torvalds 
371da177e4SLinus Torvalds /* We split the flash chip up into four parts.
381da177e4SLinus Torvalds  * 1: bootloader firts 128k			(0x00000000 - 0x0001FFFF) size 0x020000
391da177e4SLinus Torvalds  * 2: kernel 640k					(0x00020000 - 0x000BFFFF) size 0x0A0000
401da177e4SLinus Torvalds  * 3: compressed 1536k root ramdisk	(0x000C0000 - 0x0023FFFF) size 0x180000
411da177e4SLinus Torvalds  * 4: writeable diskpartition (jffs)(0x00240000 - 0x003FFFFF) size 0x1C0000
421da177e4SLinus Torvalds  */
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds #define FLASH_PHYS_ADDR 0x40000000
451da177e4SLinus Torvalds #define FLASH_SIZE 0x400000
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds #define FLASH_PARTITION0_ADDR 0x00000000
481da177e4SLinus Torvalds #define FLASH_PARTITION0_SIZE 0x00020000
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds #define FLASH_PARTITION1_ADDR 0x00020000
511da177e4SLinus Torvalds #define FLASH_PARTITION1_SIZE 0x000A0000
521da177e4SLinus Torvalds 
531da177e4SLinus Torvalds #define FLASH_PARTITION2_ADDR 0x000C0000
541da177e4SLinus Torvalds #define FLASH_PARTITION2_SIZE 0x00180000
551da177e4SLinus Torvalds 
561da177e4SLinus Torvalds #define FLASH_PARTITION3_ADDR 0x00240000
571da177e4SLinus Torvalds #define FLASH_PARTITION3_SIZE 0x001C0000
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds 
601da177e4SLinus Torvalds struct map_info flagadm_map = {
611da177e4SLinus Torvalds 		.name =		"FlagaDM flash device",
621da177e4SLinus Torvalds 		.size =		FLASH_SIZE,
631da177e4SLinus Torvalds 		.bankwidth =	2,
641da177e4SLinus Torvalds };
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds struct mtd_partition flagadm_parts[] = {
671da177e4SLinus Torvalds 	{
681da177e4SLinus Torvalds 		.name =		"Bootloader",
691da177e4SLinus Torvalds 		.offset	=	FLASH_PARTITION0_ADDR,
701da177e4SLinus Torvalds 		.size =		FLASH_PARTITION0_SIZE
711da177e4SLinus Torvalds 	},
721da177e4SLinus Torvalds 	{
731da177e4SLinus Torvalds 		.name =		"Kernel image",
741da177e4SLinus Torvalds 		.offset =	FLASH_PARTITION1_ADDR,
751da177e4SLinus Torvalds 		.size =		FLASH_PARTITION1_SIZE
761da177e4SLinus Torvalds 	},
771da177e4SLinus Torvalds 	{
781da177e4SLinus Torvalds 		.name =		"Initial ramdisk image",
791da177e4SLinus Torvalds 		.offset =	FLASH_PARTITION2_ADDR,
801da177e4SLinus Torvalds 		.size =		FLASH_PARTITION2_SIZE
811da177e4SLinus Torvalds 	},
821da177e4SLinus Torvalds 	{
831da177e4SLinus Torvalds 		.name =		"Persistant storage",
841da177e4SLinus Torvalds 		.offset =	FLASH_PARTITION3_ADDR,
851da177e4SLinus Torvalds 		.size =		FLASH_PARTITION3_SIZE
861da177e4SLinus Torvalds 	}
871da177e4SLinus Torvalds };
881da177e4SLinus Torvalds 
891da177e4SLinus Torvalds #define PARTITION_COUNT (sizeof(flagadm_parts)/sizeof(struct mtd_partition))
901da177e4SLinus Torvalds 
911da177e4SLinus Torvalds static struct mtd_info *mymtd;
921da177e4SLinus Torvalds 
931da177e4SLinus Torvalds int __init init_flagadm(void)
941da177e4SLinus Torvalds {
951da177e4SLinus Torvalds 	printk(KERN_NOTICE "FlagaDM flash device: %x at %x\n",
961da177e4SLinus Torvalds 			FLASH_SIZE, FLASH_PHYS_ADDR);
971da177e4SLinus Torvalds 
981da177e4SLinus Torvalds 	flagadm_map.phys = FLASH_PHYS_ADDR;
991da177e4SLinus Torvalds 	flagadm_map.virt = ioremap(FLASH_PHYS_ADDR,
1001da177e4SLinus Torvalds 					FLASH_SIZE);
1011da177e4SLinus Torvalds 
1021da177e4SLinus Torvalds 	if (!flagadm_map.virt) {
1031da177e4SLinus Torvalds 		printk("Failed to ioremap\n");
1041da177e4SLinus Torvalds 		return -EIO;
1051da177e4SLinus Torvalds 	}
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds 	simple_map_init(&flagadm_map);
1081da177e4SLinus Torvalds 
1091da177e4SLinus Torvalds 	mymtd = do_map_probe("cfi_probe", &flagadm_map);
1101da177e4SLinus Torvalds 	if (mymtd) {
1111da177e4SLinus Torvalds 		mymtd->owner = THIS_MODULE;
1121da177e4SLinus Torvalds 		add_mtd_partitions(mymtd, flagadm_parts, PARTITION_COUNT);
1131da177e4SLinus Torvalds 		printk(KERN_NOTICE "FlagaDM flash device initialized\n");
1141da177e4SLinus Torvalds 		return 0;
1151da177e4SLinus Torvalds 	}
1161da177e4SLinus Torvalds 
1171da177e4SLinus Torvalds 	iounmap((void *)flagadm_map.virt);
1181da177e4SLinus Torvalds 	return -ENXIO;
1191da177e4SLinus Torvalds }
1201da177e4SLinus Torvalds 
1211da177e4SLinus Torvalds static void __exit cleanup_flagadm(void)
1221da177e4SLinus Torvalds {
1231da177e4SLinus Torvalds 	if (mymtd) {
1241da177e4SLinus Torvalds 		del_mtd_partitions(mymtd);
1251da177e4SLinus Torvalds 		map_destroy(mymtd);
1261da177e4SLinus Torvalds 	}
1271da177e4SLinus Torvalds 	if (flagadm_map.virt) {
1281da177e4SLinus Torvalds 		iounmap((void *)flagadm_map.virt);
1291da177e4SLinus Torvalds 		flagadm_map.virt = 0;
1301da177e4SLinus Torvalds 	}
1311da177e4SLinus Torvalds }
1321da177e4SLinus Torvalds 
1331da177e4SLinus Torvalds module_init(init_flagadm);
1341da177e4SLinus Torvalds module_exit(cleanup_flagadm);
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds 
1371da177e4SLinus Torvalds MODULE_LICENSE("GPL");
1381da177e4SLinus Torvalds MODULE_AUTHOR("K�ri Dav��sson <kd@flaga.is>");
1391da177e4SLinus Torvalds MODULE_DESCRIPTION("MTD map driver for Flaga digital module");
140