More NAND logic (still not complete)

This commit is contained in:
Gregory Nutt
2013-11-16 18:26:07 -06:00
parent d421eb4fd6
commit 03b9f5a8e6
7 changed files with 1029 additions and 50 deletions
+20 -3
View File
@@ -52,6 +52,7 @@
#include <stdbool.h>
#include <nuttx/mtd/mtd.h>
#include <nuttx/mtd/nand_model.h>
/****************************************************************************
* Pre-Processor Definitions
@@ -61,6 +62,18 @@
* Public Types
****************************************************************************/
/* This type represents the state of the NAND MTD device. The struct
* mtd_dev_s must appear at the beginning of the definition so that you can
* freely cast between pointers to struct mtd_dev_s and struct nand_dev_s.
*/
struct nand_dev_s
{
struct mtd_dev_s mtd; /* Externally visible part of the driver */
struct mtd_dev_s *raw; /* The lower-half, "raw" nand MTD driver */
struct nand_model_s *model; /* Reference to the model (in the raw data structure) */
};
/****************************************************************************
* Public Data
****************************************************************************/
@@ -90,14 +103,18 @@ extern "C"
* cmdaddr - NAND command address base
* addraddr - NAND address address base
* dataaddr - NAND data address
* model - A pointer to the model data (probably in the raw MTD
* driver instance.
*
* Returned value.
* OK is returned on success; A negated errno value is returned on failure.
* A non-NULL MTD driver intstance is returned on success. NULL is
* returned on any failaure.
*
****************************************************************************/
int nand_initialize(FAR struct mtd_dev_s *raw,
uintptr_t cmdaddr, uintptr_t addraddr, uintptr_t dataaddr);
FAR struct mtd_dev_s *nand_initialize(FAR struct mtd_dev_s *raw,
uintptr_t cmdaddr, uintptr_t addraddr,
uintptr_t dataaddr, FAR struct nand_model_s *model);
#undef EXTERN
#ifdef __cplusplus
+279
View File
@@ -113,6 +113,285 @@ EXTERN const struct nand_model_s g_nandmodels[NAND_NMODELS];
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: nandmodel_find
*
* Description:
* Looks for a nand_model_s corresponding to the given ID inside a list of
* model. If found, the model variable is filled with the correct values.
*
* Input Parameters:
* modeltab List of nand_model_s instances.
* size Number of models in list.
* chipid Identifier returned by the Nand(id1|(id2<<8)|(id3<<16)|(id4<<24)).
* model nand_model_s instance to update with the model parameters.
*
* Returned Values:
* OK is returned on success; -ENODEV is returned on failure.
*
****************************************************************************/
int nandmodel_find(FAR const struct nand_model_s *modeltab, size_t size,
uint32_t chipid, FAR struct nand_model_s *model);
/****************************************************************************
* Name: nandmodel_translate
*
* Description:
* Translates address/size access of a nand_model_s to block, page and
* offset values. The values are stored in the provided variables if their
* pointer is not 0.
*
* Input Parameters:
* model Pointer to a nand_model_s instance.
* address Access address.
* size Access size in bytes.
* block Stores the first accessed block number.
* page Stores the first accessed page number inside the first block.
* offset Stores the byte offset inside the first accessed page.
*
* Returned Values:
* OK on success; -EPIPE on failure.
*
****************************************************************************/
int nandmodel_translate(FAR const struct nand_model_s *model, off_t address,
size_t size, FAR off_t *block, off_t *page,
off_t *offset);
/****************************************************************************
* Name: nandmodel_getscheme
*
* Description:
* Returns the spare area placement scheme used by a particular nandflash
* model.
*
* Input Parameters:
* model Pointer to a nand_model_s instance.
*
* Returned Values:
* Spare placement scheme
*
****************************************************************************/
FAR const struct nand_dev_scheme_s *
nandmodel_getscheme(FAR const struct nand_model_s *model);
/****************************************************************************
* Name: nandmodel_getdevid
*
* Description:
* Returns the device ID of a particular NAND FLASH model.
*
* Input Parameters:
* model Pointer to a nand_model_s instance.
*
* Returned Values:
* Device ID
*
****************************************************************************/
uint8_t nandmodel_getdevid(FAR const struct nand_model_s *model);
/****************************************************************************
* Name: nandmodel_getdevblocksize
*
* Description:
* Returns the number of blocks in the entire device.
*
* Input Parameters:
* model Pointer to a nand_model_s instance.
*
* Returned Values:
* Number of blocks in the device
*
****************************************************************************/
off_t nandmodel_getdevblocksize(FAR const struct nand_model_s *model);
/****************************************************************************
* Name: nandmodel_getdevpagesize
*
* Description:
* Returns the number of pages in the entire device.
*
* Input Parameters:
* model Pointer to a nand_model_s instance.
*
* Returned Values:
* Number of pages in the device
*
****************************************************************************/
size_t nandmodel_getdevpagesize(FAR const struct nand_model_s *model);
/****************************************************************************
* Name: nandmodel_getdevbytesize
*
* Description:
* Returns the size of the whole device in bytes (this does not include
* the size of the spare zones).
*
* Input Parameters:
* model Pointer to a nand_model_s instance.
*
* Returned Values:
* Size of the device in bytes
*
****************************************************************************/
uint64_t nandmodel_getdevbytesize(FAR const struct nand_model_s *model);
/****************************************************************************
* Name: nandmodel_getdevmbsize
*
* Description:
* Returns the size of the whole device in Mega bytes (this does not
* include the size of the spare zones).
*
* Input Parameters:
* model Pointer to a nand_model_s instance.
*
* Returned Values:
* size of the device in MB.
*
****************************************************************************/
uint32_t nandmodel_getdevmbsize(FAR const struct nand_model_s *model);
/****************************************************************************
* Name: nandmodel_getblocksize
*
* Description:
* Returns the number of pages in one single block of a device.
*
* Input Parameters:
* model Pointer to a nand_model_s instance.
*
* Returned Values:
*
*
****************************************************************************/
unsigned int nandmodel_getblocksize(FAR const struct nand_model_s *model);
/****************************************************************************
* Name: nandmodel_getblockpagesize
*
* Description:
* Returns the number of pages in one single block of a device.
*
* Input Parameters:
* model Pointer to a nand_model_s instance.
*
* Returned Values:
* Block size in pages
*
****************************************************************************/
unsigned int nandmodel_getblockpagesize(FAR const struct nand_model_s *model);
/****************************************************************************
* Name: nandmodel_getblockbytesize
*
* Description:
* Returns the size in bytes of one single block of a device. This does not
* take into account the spare zones size.
*
* Input Parameters:
* model Pointer to a nand_model_s instance.
*
* Returned Values:
* Block size in bytes
*
****************************************************************************/
unsigned int nandmodel_getblockbytesize(FAR const struct nand_model_s *model);
/****************************************************************************
* Name: nandmodel_getpagesize
*
* Description:
* Returns the size of the data area of a page in bytes.
*
* Input Parameters:
* model Pointer to a nand_model_s instance.
*
* Returned Values:
* Size of data area in bytes
*
****************************************************************************/
unsigned int nandmodel_getpagesize(FAR const struct nand_model_s *model);
/****************************************************************************
* Name: nandmodel_getsparesize
*
* Description:
* Returns the size of the spare area of a page in bytes.
*
* Input Parameters:
* model Pointer to a nand_model_s instance.
*
* Returned Values:
* size of spare area in bytes
*
****************************************************************************/
unsigned int nandmodel_getsparesize(FAR const struct nand_model_s *model);
/****************************************************************************
* Name: nandmodel_getbuswidth
*
* Description:
* Returns the number of bits used by the data bus of a NAND FLASH device.
*
* Input Parameters:
* model Pointer to a nand_model_s instance.
*
* Returned Values:
* data width
*
****************************************************************************/
unsigned int nandmodel_getbuswidth(FAR const struct nand_model_s *model);
/****************************************************************************
* Name: nandmodel_havesmallblocks
*
* Description:
* Returns true if the given NAND FLASH model uses the "small blocks/pages"
* command set; otherwise returns false.
*
* Input Parameters:
* model Pointer to a nand_model_s instance.
*
* Returned Values:
* Returns true if the given NAND FLASH model uses the "small blocks/pages"
* command set; otherwise returns false.
*
****************************************************************************/
bool nandmodel_havesmallblocks(FAR const struct nand_model_s *model);
/****************************************************************************
* Name: nandmodel_havecopyback
*
* Description:
* Returns true if the device supports the copy-back operation. Otherwise
* returns false.
*
* Input Parameters:
* model Pointer to a nand_model_s instance.
*
* Returned Values:
* Returns true if the device supports the copy-back operation. Otherwise
* returns false.
*
****************************************************************************/
bool nandmodel_havecopyback(FAR const struct nand_model_s *model);
#undef EXTERN
#ifdef __cplusplus
}