/************************************************************************/
#ifndef CFIFLASH_H
#define CFIFLASH_H

#include "libsys.h"

#define	SR_BIT_DPS		0x00020002
#define	SR_BIT_PSS		0x00040004
#define	SR_BIT_VPENS	0x00080008
#define	SR_BIT_PSLBS	0x00100010
#define	SR_BIT_ECLBS	0x00200020
#define	SR_BIT_ESS		0x00400040
#define	SR_BIT_ISMS		0x00800080

typedef struct _sflash_info_t
{
	UINT32 flashsize;
	UINT32 blocksize;
	UINT32 nblocks;
	UINT32 wbuf_size;
	UINT32 if_width;
	UINT32 num_flash;

} flash_info_t;

typedef struct _sflash_t
{
	void *pBase;
	flash_info_t info;

} flash_t;

void cfi_init(flash_t *pObj, UINT32 base_addr);
UINT32 cfi_find(flash_t *pObj);
UINT32 cfi_block_erase(flash_t *pObj, UINT32 word_index);
UINT32 cfi_program_single(flash_t *pObj, UINT32 word_index, UINT32 word);
UINT32 cfi_program_multi(flash_t *pObj, UINT32 word_index, UINT32 *pWords, UINT32 num_words);

UINT32 flash_get_nextblock(flash_t *pObj, UINT32 offset);
UINT32 flash_find(flash_t *pObj, UINT32 base_addr);
UINT32 flash_erase(flash_t *pObj, UINT32 offset, UINT32 size);
UINT32 flash_program(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size);
UINT32 flash_verify(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size);

#endif // CFIFLASH_H
