/*
 * drivers/mtd/maps/hmi1001.c
 *
 * MTD mapping for the HMI1001 board.
 *
 */
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <asm/io.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>
#include <linux/mtd/partitions.h>

#ifdef CONFIG_UBOOT
#include <asm/ppcboot.h>

extern unsigned char __res[];
bd_t *bd = (bd_t *)__res;

#define FLASH_ADDR  (bd->bi_flashstart)
#define FLASH_SIZE  (bd->bi_flashsize)
#else
#define FLASH_ADDR  CONFIG_PPC_5xxx_FLASH_ADDR
#define FLASH_SIZE  CONFIG_PPC_5xxx_FLASH_SIZE
#endif

#ifndef CONFIG_MTD_PARTITIONS
#error need to define CONFIG_MTD_PARTITIONS
#endif
static struct mtd_info *mymtd;

struct map_info hmi1001_map = {
	name:		"HMI1001",
	bankwidth:	1,
};

static struct mtd_partition hmi1001_partition[] =
{
	{
		name:		"Kernel",
                size:           0x00100000,
		offset:		0
	},
	{
		name:		"RootFS",
		size:		0x00600000,
		offset:		MTDPART_OFS_APPEND
	},
	{
		name:		"U-boot",
		size:		0x00100000,
		offset:		MTDPART_OFS_APPEND
	},
};

#define NB_OF(x)	(sizeof(x)/sizeof(x[0]))

static int __init init_hmi1001 (void)
{
	printk (KERN_ALERT "HMI1001 flash device: %lx at %lx\n", FLASH_SIZE,
		FLASH_ADDR);
	hmi1001_map.virt = hmi1001_map.phys = FLASH_ADDR;
	hmi1001_map.size = FLASH_SIZE;
	hmi1001_map.bankwidth = 4;
	simple_map_init(&hmi1001_map);

	mymtd = do_map_probe ("cfi_probe", &hmi1001_map);
	if (!mymtd) {
		printk ("cfi_probe failed\n");
		return -ENXIO;
	}

	mymtd->owner = THIS_MODULE;
	printk (KERN_NOTICE "Using static partition definition\n");
	add_mtd_partitions (mymtd, hmi1001_partition, NB_OF (hmi1001_partition));

	return 0;
}


static void __exit cleanup_hmi1001 (void)
{
	if (mymtd) {
		del_mtd_device (mymtd);
		map_destroy (mymtd);
	}
}
module_init(init_hmi1001);
module_exit(cleanup_hmi1001);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("");
MODULE_DESCRIPTION("MTD map driver for HMI1001 board");
