/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished proprietary information of BroadOn Communications Corp.,
 *  and are protected by federal copyright law. They may not be disclosed
 *  to third parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 *  Description:
 *      This file defines internal utility functions used by the flash
 *      device driver
 *
 * $Id: flash.h,v 1.2 2006/02/20 01:52:20 jlivesey Exp $
 */


#ifndef __FLASH_H__
#define __FLASH_H__

/* 
 * Structures for defining device specific information 
 */
typedef struct {
    u8      makerID;
    u8      deviceID;
} FLIdentifier;

/* 
 * Flash device capabilities 
 */
typedef struct {
    u32     totalSzShift;
    u32     erasableBlockSzShift;
    u32     pageSzShift;
    u32     pageSpareSzShift;
    u32     userSpareSzShift;
    u16     numPlanes;
    u16     supportCopy;
    u16     statusByteOffset;
} FLDevCap;

typedef struct {
    u8      reset;
    u8      readSetup;
    u8      read;
    u8      readSecondHalf;
    u8      readSpare;
    u8      readForCopy;
    u8      readForMultiplane;
    u8      programSetup;
    u8      program;
    u8      programForCopy;
    u8      programMultiplane;
    u8      cache;
    u8      copyBack;
    u8      eraseSetup;
    u8      eraseSetupMultiplane;
    u8      erase;
    u8      randomOutputSetup;
    u8      randomOutput;
    u8      randomInput;
    u8      readOpStatus;
    u8      readOpStatusMultiplane;
    u8      addrBytePhase;
} FLCommandSet;

typedef struct {
    u8      eoc;
    u8      rsa;
    u8      rea;
    u8      wea;
    u8      caa;
} FLConfig;

typedef struct {
    FLIdentifier    flashID;
    FLCommandSet    cmdSet;
    FLDevCap        cap;
    FLConfig        cfg;
} FLDev;

/*
 *  Description:
 *      Flash device driver statistics information
 *
 */
#define FL_FAILED_ENTRIES           32
#define FL_FAILED_ENTRIES_SHIFT     7

#define FL_OP_ERASE                 0
#define FL_OP_WRITE                 1
#define FL_OP_READ                  2
#define FL_OP_COPY                  3

/* Statistics records */
typedef struct {
    u32         blockIndex;
    u32         opType;
    IOSError    reason;
} FLFailRecord;

typedef struct {
    u32                 numErasesSinceInit;
    u32                 numWritesSinceInit;
    u32                 numReadsSinceInit;
    u32                 numCopiesSinceInit;
    u32                 failRecordStart;
    u32                 failRecordNum;
    FLFailRecord        failRecord[FL_FAILED_ENTRIES];
} FLStats;

/*
 *  Description:
 *      Flash logical block data and spare size
 *
 */
#define FL_LOGI_BLOCK_SIZE          (2 * 1024) /* Flash logical block size */
#define FL_LOGI_BLOCK_SIZE_SHIFT    11

#define FL_VIRT_SPARE_SIZE          64         /* Spare for a logical block */
#define FL_VIRT_SPARE_SIZE_SHIFT    6


/* Cacheline alignment */
#define FL_BASE_ALIGN_SZ            16

/*
 *  Description:
 *      Flash device driver manufacturing ID
 *
 */
#define FL_SAMSUNG_ID               0xEC
#define FL_SAMSUNG_128MB_ID         0xF1
#define FL_SAMSUNG_512MB_ID         0xDC
#define FL_HYNIX_ID                 0xAD
#define FL_HYNIX_512MB_ID           0xDC

#endif /* __FLASH_H__ */

/* eof */
