/*
 * (C) Copyright 2002
 * Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net
 *
 * (C) Copyright 2002
 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
 * Marius Groeger <mgroeger@sysgo.de>
 *
 * (C) Copyright 2002
 * Robert Schwebel, Pengutronix, <r.schwebel@pengutronix.de>
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * 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 <common.h>
#include <asm/arch/pxa-regs.h>

#if defined CFG_JFFS_CUSTOM_PART
#include <jffs2/jffs2.h>
#endif

/* Debugging macros ------------------------------------------------------  */

#undef FLASH_DEBUG
//#define FLASH_DEBUG 1

/* Some debug macros */
#if (FLASH_DEBUG > 2 )
#define PRINTK3(args...) printf(args)
#else
#define PRINTK3(args...)
#endif

#if FLASH_DEBUG > 1
#define PRINTK2(args...) printf(args)
#else
#define PRINTK2(args...)
#endif

#ifdef FLASH_DEBUG
#define PRINTK(args...) printf(args)
#else
#define PRINTK(args...)
#endif

/* ------------------------------------------------------------------------ */

/* Development system: we have only 16 MB Flash                             */
#ifdef CONFIG_MTD_INNOKOM_16MB
#define FLASH_BANK_SIZE 0x01000000	/* 16 MB (during development)       */
#define MAIN_SECT_SIZE  0x00020000	/* 128k per sector                  */
#endif

/* Production system: we have 64 MB Flash                                   */
#ifdef CONFIG_MTD_INNOKOM_64MB
#define FLASH_BANK_SIZE 0x04000000	/* 64 MB                            */
#define MAIN_SECT_SIZE  0x00020000	/* 128k per sector                  */
#endif

flash_info_t    flash_info[CFG_MAX_FLASH_BANKS];


#if defined CFG_JFFS_CUSTOM_PART

/**
 * jffs2_part_info - get information about a JFFS2 partition
 *
 * @part_num: number of the partition you want to get info about
 * @return:   struct part_info* in case of success, 0 if failure
 */

static struct part_info part;
static int current_part = -1;

#ifdef CONFIG_MTD_INNOKOM_16MB
#ifdef CONFIG_MTD_INNOKOM_64MB
#error Please define only one CONFIG_MTD_INNOKOM_XXMB option.
#endif
struct part_info* jffs2_part_info(int part_num) {
	void *jffs2_priv_saved = part.jffs2_priv;

	PRINTK2("jffs2_part_info: part_num=%i\n",part_num);

	if (current_part == part_num)
		return &part;

	/* u-boot partition                                                 */
	if(part_num==0){
		memset(&part, 0, sizeof(part));
		
		part.offset=(char*)0x00000000;
		part.size=256*1024;
		
		/* Mark the struct as ready */
		current_part = part_num;

		PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
		PRINTK("part.size   = 0x%08x\n",(unsigned int)part.size);
	}

	/* primary OS+firmware partition                                    */
	if(part_num==1){
		memset(&part, 0, sizeof(part));
		
		part.offset=(char*)0x00040000;
		part.size=768*1024;
		
		/* Mark the struct as ready */
		current_part = part_num;

		PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
		PRINTK("part.size   = 0x%08x\n",(unsigned int)part.size);
	}
	
	/* secondary OS+firmware partition                                  */
	if(part_num==2){
		memset(&part, 0, sizeof(part));
		
		part.offset=(char*)0x00100000;
		part.size=8*1024*1024;
		
		/* Mark the struct as ready */
		current_part = part_num;

		PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
		PRINTK("part.size   = 0x%08x\n",(unsigned int)part.size);
	}

	/* data partition */
	if(part_num==3){
		memset(&part, 0, sizeof(part));
		
		part.offset=(char*)0x00900000;
		part.size=7*1024*1024;
		
		/* Mark the struct as ready */
		current_part = part_num;

		PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
		PRINTK("part.size   = 0x%08x\n",(unsigned int)part.size);
	}
	
	if (current_part == part_num) {
		part.usr_priv = &current_part;
		part.jffs2_priv = jffs2_priv_saved;
		return &part;
	}

	PRINTK("jffs2_part_info: end of partition table\n");
	return 0;
}
#endif /* CONFIG_MTD_INNOKOM_16MB */

#ifdef CONFIG_MTD_INNOKOM_64MB
#ifdef CONFIG_MTD_INNOKOM_16MB
#error Please define only one CONFIG_MTD_INNOKOM_XXMB option.
#endif
struct part_info* jffs2_part_info(int part_num) {
	void *jffs2_priv_saved = part.jffs2_priv;

	PRINTK2("jffs2_part_info: part_num=%i\n",part_num);

	if (current_part == part_num)
		return &part;

	/* u-boot partition                                                 */
	if(part_num==0){
		memset(&part, 0, sizeof(part));
		
		part.offset=(char*)0x00000000;
		part.size=256*1024;
		
		/* Mark the struct as ready */
		current_part = part_num;

		PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
		PRINTK("part.size   = 0x%08x\n",(unsigned int)part.size);
	}

	/* primary OS+firmware partition                                    */
	if(part_num==1){
		memset(&part, 0, sizeof(part));
		
		part.offset=(char*)0x00040000;
		part.size=16*1024*1024-128*1024;
		
		/* Mark the struct as ready */
		current_part = part_num;

		PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
		PRINTK("part.size   = 0x%08x\n",(unsigned int)part.size);
	}
	
	/* secondary OS+firmware partition                                  */
	if(part_num==2){
		memset(&part, 0, sizeof(part));
		
		part.offset=(char*)0x01020000;
		part.size=16*1024*1024-128*1024;
		
		/* Mark the struct as ready */
		current_part = part_num;

		PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
		PRINTK("part.size   = 0x%08x\n",(unsigned int)part.size);
	}

	/* data partition */
	if(part_num==3){
		memset(&part, 0, sizeof(part));
		
		part.offset=(char*)0x02000000;
		part.size=32*1024*1024;
		
		/* Mark the struct as ready */
		current_part = part_num;

		PRINTK("part.offset = 0x%08x\n",(unsigned int)part.offset);
		PRINTK("part.size   = 0x%08x\n",(unsigned int)part.size);
	}
	
	if (current_part == part_num) {
		part.usr_priv = &current_part;
		part.jffs2_priv = jffs2_priv_saved;
		return &part;
	}

	PRINTK("jffs2_part_info: end of partition table\n");
	return 0;
}
#endif /* CONFIG_MTD_INNOKOM_64MB */
#endif /* defined CFG_JFFS_CUSTOM_PART */


/**
 * flash_init: - initialize data structures for flash chips
 *
 * @return: size of the flash
 */

ulong flash_init(void)
{
	int i, j;
	ulong size = 0;

	for (i = 0; i < CFG_MAX_FLASH_BANKS; i++) {
		ulong flashbase = 0;
		flash_info[i].flash_id =
	  		(INTEL_MANUFACT & FLASH_VENDMASK) |
	  		(INTEL_ID_28F128J3 & FLASH_TYPEMASK);
		flash_info[i].size = FLASH_BANK_SIZE;
		flash_info[i].sector_count = CFG_MAX_FLASH_SECT;
		memset(flash_info[i].protect, 0, CFG_MAX_FLASH_SECT);

		switch (i) {
			case 0:
				flashbase = PHYS_FLASH_1;
				break;
			default:
				panic("configured to many flash banks!\n");
				break;
		}
		for (j = 0; j < flash_info[i].sector_count; j++) {
			flash_info[i].start[j] = flashbase + j*MAIN_SECT_SIZE;
		}
		size += flash_info[i].size;
	}

	/* Protect u-boot sectors */
	flash_protect(FLAG_PROTECT_SET,
			CFG_FLASH_BASE,
			CFG_FLASH_BASE + (256*1024) - 1,
			&flash_info[0]);

#ifdef CFG_ENV_IS_IN_FLASH
	flash_protect(FLAG_PROTECT_SET,
			CFG_ENV_ADDR,
			CFG_ENV_ADDR + CFG_ENV_SIZE - 1,
			&flash_info[0]);
#endif

	return size;
}


/**
 * flash_print_info: - print information about the flash situation
 *
 * @param info:
 */

void flash_print_info  (flash_info_t *info)
{
	int i, j;

	for (j=0; j<CFG_MAX_FLASH_BANKS; j++) {

		switch (info->flash_id & FLASH_VENDMASK) {

			case (INTEL_MANUFACT & FLASH_VENDMASK):
				printf("Intel: ");
				break;
			default:
				printf("Unknown Vendor ");
				break;
		}

		switch (info->flash_id & FLASH_TYPEMASK) {

			case (INTEL_ID_28F128J3 & FLASH_TYPEMASK):
				printf("28F128J3 (128Mbit)\n");
				break;
			default:
				printf("Unknown Chip Type\n");
				return;
		}

		printf("  Size: %ld MB in %d Sectors\n", 
			info->size >> 20, info->sector_count);

		printf("  Sector Start Addresses:");
		for (i = 0; i < info->sector_count; i++) {
			if ((i % 5) == 0) printf ("\n   ");
	        
			printf (" %08lX%s", info->start[i],
				info->protect[i] ? " (RO)" : "     ");
		}
		printf ("\n");
		info++;
	}
}


/**
 * flash_erase: - erase flash sectors
 *
 */

int flash_erase(flash_info_t *info, int s_first, int s_last)
{
	int flag, prot, sect;
	int rc = ERR_OK;

	if (info->flash_id == FLASH_UNKNOWN)
		return ERR_UNKNOWN_FLASH_TYPE;

	if ((s_first < 0) || (s_first > s_last)) {
		return ERR_INVAL;
	}

	if ((info->flash_id & FLASH_VENDMASK) != (INTEL_MANUFACT & FLASH_VENDMASK))
		return ERR_UNKNOWN_FLASH_VENDOR;
	
	prot = 0;
	for (sect=s_first; sect<=s_last; ++sect) {
		if (info->protect[sect]) prot++;
	}

	if (prot) return ERR_PROTECTED;

	/*
	 * Disable interrupts which might cause a timeout
	 * here. Remember that our exception vectors are
	 * at address 0 in the flash, and we don't want a
	 * (ticker) exception to happen while the flash
	 * chip is in programming mode.
	 */

	flag = disable_interrupts();

	/* Start erase on unprotected sectors */
	for (sect = s_first; sect<=s_last && !ctrlc(); sect++) {

		printf("Erasing sector %2d ... ", sect);

		PRINTK("\n");

		/* arm simple, non interrupt dependent timer */
		reset_timer_masked();

		if (info->protect[sect] == 0) {	/* not protected */
			u16 * volatile addr = (u16 * volatile)(info->start[sect]);

			PRINTK("unlocking sector\n");
			*addr = 0x0060;
			*addr = 0x00d0;
			*addr = 0x00ff;

			PRINTK("erasing sector\n");
			*addr = 0x0020;
			PRINTK("confirming erase\n");
			*addr = 0x00D0;

			while ((*addr & 0x0080) != 0x0080) {
				PRINTK(".");
				if (get_timer_masked() > CFG_FLASH_ERASE_TOUT) {
					*addr = 0x00B0; /* suspend erase*/
					*addr = 0x00FF; /* read mode    */
					rc = ERR_TIMOUT;
					goto outahere;
				}
			}
			
			PRINTK("clearing status register\n");
			*addr = 0x0050; 
			PRINTK("resetting to read mode");
			*addr = 0x00FF; 
		}
		
		printf("ok.\n");
	}

	if (ctrlc()) printf("User Interrupt!\n");

	outahere:

	/* allow flash to settle - wait 10 ms */
	udelay_masked(10000);

	if (flag) enable_interrupts();

	return rc;
}


/**
 * write_word: - copy memory to flash
 *
 * @param info:
 * @param dest:
 * @param data:
 * @return:
 */

static int write_word (flash_info_t *info, ulong dest, ushort data)
{
	volatile u16 *addr = (u16 *)dest, val;
	int rc = ERR_OK;
	int flag;

	/* Check if Flash is (sufficiently) erased */
	if ((*addr & data) != data) return ERR_NOT_ERASED;

	/*
	 * Disable interrupts which might cause a timeout
	 * here. Remember that our exception vectors are
	 * at address 0 in the flash, and we don't want a
	 * (ticker) exception to happen while the flash
	 * chip is in programming mode.
	 */
	flag = disable_interrupts();

	/* clear status register command */
	*addr = 0x50;

	/* program set-up command */
	*addr = 0x40;

	/* latch address/data */
	*addr = data;

	/* arm simple, non interrupt dependent timer */
	reset_timer_masked();

	/* wait while polling the status register */
	while(((val = *addr) & 0x80) != 0x80) {
		if (get_timer_masked() > CFG_FLASH_WRITE_TOUT) {
			rc = ERR_TIMOUT;
			*addr = 0xB0; /* suspend program command */
			goto outahere;
		}
	}

	if(val & 0x1A) {	/* check for error */
		printf("\nFlash write error %02x at address %08lx\n",
			(int)val, (unsigned long)dest);
		if(val & (1<<3)) {
			printf("Voltage range error.\n");
			rc = ERR_PROG_ERROR;
			goto outahere;
		}
		if(val & (1<<1)) {
			printf("Device protect error.\n");
			rc = ERR_PROTECTED;
			goto outahere;
		}
		if(val & (1<<4)) {
			printf("Programming error.\n");
			rc = ERR_PROG_ERROR;
			goto outahere;
		}
		rc = ERR_PROG_ERROR;
		goto outahere;
	}

	outahere:

	*addr = 0xFF; /* read array command */
	if (flag) enable_interrupts();

	return rc;
}


/**
 * write_buf: - Copy memory to flash.
 *
 * @param info:
 * @param src:	source of copy transaction
 * @param addr:	where to copy to
 * @param cnt: 	number of bytes to copy
 *
 * @return	error code
 */

int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)
{
	ulong cp, wp;
	ushort data;
	int l;
	int i, rc;

	wp = (addr & ~1);	/* get lower word aligned address */

	/*
	 * handle unaligned start bytes
	 */
	if ((l = addr - wp) != 0) {
		data = 0;
		for (i=0, cp=wp; i<l; ++i, ++cp) {
			data = (data >> 8) | (*(uchar *)cp << 8);
		}
		for (; i<2 && cnt>0; ++i) {
			data = (data >> 8) | (*src++ << 8);
			--cnt;
			++cp;
		}
		for (; cnt==0 && i<2; ++i, ++cp) {
			data = (data >> 8) | (*(uchar *)cp << 8);
		}

		if ((rc = write_word(info, wp, data)) != 0) {
			return (rc);
		}
		wp += 2;
	}

	/*
	 * handle word aligned part
	 */
	while (cnt >= 2) {
		/* data = *((vushort*)src); */
		data = *((ushort*)src);
		if ((rc = write_word(info, wp, data)) != 0) {
			return (rc);
		}
		src += 2;
		wp  += 2;
		cnt -= 2;
	}

	if (cnt == 0) return ERR_OK;

	/*
	 * handle unaligned tail bytes
	 */
	data = 0;
	for (i=0, cp=wp; i<2 && cnt>0; ++i, ++cp) {
		data = (data >> 8) | (*src++ << 8);
		--cnt;
	}
	for (; i<2; ++i, ++cp) {
		data = (data >> 8) | (*(uchar *)cp << 8);
	}

	return write_word(info, wp, data);
}

