#ifndef __FLASHHAL_H__
#define __FLASHHAL_H__

#include <asm/tc3162.h>

#include <asm/arch-en7523/spi_controller.h>
#include <asm/arch-en7523/spi_nand_flash.h>

#define isParallelNAND				0

#define KB_SHIFT 10
#define MB_SHIFT 20

extern int flash_partial_write(unsigned long to, unsigned long len, const unsigned char *buf);

extern int flash_init(unsigned long rom_base);
extern int flash_read(unsigned long from,
	unsigned long len, unsigned long *retlen, unsigned char *buf);
extern int flash_write(unsigned long to,
	unsigned long len, unsigned long *retlen, const unsigned char *buf);
extern int flash_erase(unsigned long addr, unsigned long size);
extern int flash_erase_non_block(unsigned long addr, unsigned long size);
extern int FlashBlockDFU(unsigned long dst, unsigned long src, unsigned long len);

extern unsigned long flash_base;
extern unsigned long flash_tclinux_start;

extern unsigned char ReadNandCache(unsigned long index);
extern unsigned char ReadNandByte(unsigned long index);
extern unsigned long ReadNandDWord(unsigned long index);

extern unsigned char ReadSPICache(unsigned long index);
extern unsigned char ReadSPIByte(unsigned long index);
extern unsigned long ReadSPIDWord(unsigned long index);

#define isSpiNandAndCtrlECC ((IS_NANDFLASH && isSpiControllerECC) || isParallelNAND)

#define READ_FLASH_CACHE(i, status)			( IS_NANDFLASH ? SPI_NAND_Flash_Read_Byte(i, status): ReadSPICache(i)  )
#define READ_FLASH_BYTE(i, status)			( IS_NANDFLASH ? SPI_NAND_Flash_Read_Byte(i, status): ReadSPIByte(i)   )
#define READ_FLASH_DWORD(i, status)			( IS_NANDFLASH ? SPI_NAND_Flash_Read_DWord(i, status): ReadSPIDWord(i) )

#endif /* __FLASHHAL_H__ */
