/*
 * Copyright 2004 Freescale Semiconductor, Inc. All Rights Reserved.
 * (c) 2005 MontaVista Software, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>
#include <linux/mtd/partitions.h>
#include <linux/mtd/physmap.h>
#include <asm/mach-types.h>

/*!
 * @defgroup NOR_MTD NOR Flash MTD Driver
 */

/*!
 * @file mxc_nor.c
 *
 * @brief This file contains the MTD Mapping information on the MXC.
 *
 * @ingroup NOR_MTD
 */

/*!
 * The PA of the NOR flash memory base on the MXC board at CS0
 */
#define MXC_FLASH_BASE_PA       0xA0000000
/*!
 * The size in bytes for the NOR flash memory on the MXC board
 */
#define MXC_FLASH_SIZE          0x02000000

/*!
 * This table contains the static partition information for the MXC
 * NOR flash. This table is registered with the MTD physmap driver
 * via physmap_set_partitions(). It is then used by the MTD physmap
 * driver to register static partition table entries with the upper
 * MTD driver. See include/linux/mtd/partitions.h for definition
 * of the mtd_partition structure.
 */
static struct mtd_partition mxc_mtd_partitions[] = {
	{
		.name		= "Bootloader",
		.size		= 1 * 1024 * 1024,
		.offset		= 0x00000000,
		.mask_flags	= MTD_WRITEABLE	/* force read-only */
	 }, {
		.name		= "Kernel",
		.size		= 2 * 1024 * 1024,
		.offset		= MTDPART_OFS_APPEND,
		.mask_flags	= MTD_WRITEABLE	/* force read-only */
	}, {
		.name		= "root",
		.size		= 24 * 1024 * 1024,
		.offset		= MTDPART_OFS_APPEND,
		.mask_flags	= MTD_WRITEABLE	/* force read-only */
	}, {
		.name		= "var",
		.size		= MTDPART_SIZ_FULL,
		.offset		= MTDPART_OFS_APPEND,
	}
};

#define NUM_MXC_MTD_PARTITIONS	\
	(sizeof(mxc_mtd_partitions)/sizeof(mxc_mtd_partitions[0]))

/*!
 * This is the module's entry function. It passes board specific
 * config details into the MTD physmap driver which then does the
 * real work for us. After this function runs, our job is done.
 *
 * @return  0 if successful; non-zero otherwise
 */
static int __init mxc_mtd_init(void)
{
	if (machine_is_scma11bb()) {
		mxc_mtd_partitions[1].size = 3 * 1024 * 1024;
		mxc_mtd_partitions[2].size = 23 * 1024 * 1024;
	}

	physmap_configure(MXC_FLASH_BASE_PA, MXC_FLASH_SIZE, 2, NULL);
	physmap_set_partitions(mxc_mtd_partitions, NUM_MXC_MTD_PARTITIONS);

	return 0;
}

/*!
 * This function is the module's exit function. It's empty because the
 * MTD physmap driver is doing the real work and our job was done after
 * mxc_mtd_init() runs.
 */
static void __exit mxc_mtd_exit(void)
{
	return;
}

module_init(mxc_mtd_init);
module_exit(mxc_mtd_exit);

MODULE_AUTHOR("Freescale Semiconductor, Inc.");
MODULE_DESCRIPTION("MTD map and partitions for Freescale MXC boards");
MODULE_LICENSE("GPL");
