Continuing NAND integration

This commit is contained in:
Gregory Nutt
2013-11-17 08:56:30 -06:00
parent 03b9f5a8e6
commit 0e7a8668a5
9 changed files with 379 additions and 335 deletions
+8 -16
View File
@@ -52,7 +52,7 @@
#include <stdbool.h>
#include <nuttx/mtd/mtd.h>
#include <nuttx/mtd/nand_model.h>
#include <nuttx/mtd/nand_raw.h>
/****************************************************************************
* Pre-Processor Definitions
@@ -61,17 +61,16 @@
/****************************************************************************
* 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.
/* This type represents the state of the upper-half 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) */
FAR struct nand_raw_s *raw; /* Retained reference to the lower half */
};
/****************************************************************************
@@ -99,12 +98,7 @@ extern "C"
* Probe and initialize NAND.
*
* Input parameters:
* raw - Raw NAND FLASH MTD interface
* 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.
* raw - Lower-half, raw NAND FLASH interface
*
* Returned value.
* A non-NULL MTD driver intstance is returned on success. NULL is
@@ -112,9 +106,7 @@ extern "C"
*
****************************************************************************/
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);
FAR struct mtd_dev_s *nand_initialize(FAR struct nand_raw_s *raw);
#undef EXTERN
#ifdef __cplusplus
+33 -30
View File
@@ -174,8 +174,7 @@ int nandmodel_translate(FAR const struct nand_model_s *model, off_t address,
*
****************************************************************************/
FAR const struct nand_dev_scheme_s *
nandmodel_getscheme(FAR const struct nand_model_s *model);
#define nandmodel_getscheme(m) ((m)->scheme)
/****************************************************************************
* Name: nandmodel_getdevid
@@ -191,7 +190,7 @@ nandmodel_getscheme(FAR const struct nand_model_s *model);
*
****************************************************************************/
uint8_t nandmodel_getdevid(FAR const struct nand_model_s *model);
#define nandmodel_getdevid(m) ((m)->devid)
/****************************************************************************
* Name: nandmodel_getdevblocksize
@@ -207,23 +206,8 @@ uint8_t nandmodel_getdevid(FAR const struct nand_model_s *model);
*
****************************************************************************/
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);
#define nandmodel_getdevblocksize(m) \
((off_t)((m)->devsize << 10) / (m)->blocksize)
/****************************************************************************
* Name: nandmodel_getdevbytesize
@@ -240,7 +224,7 @@ size_t nandmodel_getdevpagesize(FAR const struct nand_model_s *model);
*
****************************************************************************/
uint64_t nandmodel_getdevbytesize(FAR const struct nand_model_s *model);
#define nandmodel_getdevbytesize(m) (((uint64_t)((m)->devsize) << 20))
/****************************************************************************
* Name: nandmodel_getdevmbsize
@@ -257,7 +241,7 @@ uint64_t nandmodel_getdevbytesize(FAR const struct nand_model_s *model);
*
****************************************************************************/
uint32_t nandmodel_getdevmbsize(FAR const struct nand_model_s *model);
#define nandmodel_getdevmbsize(m) ((uint32_t)((m)->devsize))
/****************************************************************************
* Name: nandmodel_getblocksize
@@ -276,7 +260,7 @@ uint32_t nandmodel_getdevmbsize(FAR const struct nand_model_s *model);
unsigned int nandmodel_getblocksize(FAR const struct nand_model_s *model);
/****************************************************************************
* Name: nandmodel_getblockpagesize
* Name: nandmodel_getpageblocksize
*
* Description:
* Returns the number of pages in one single block of a device.
@@ -289,10 +273,28 @@ unsigned int nandmodel_getblocksize(FAR const struct nand_model_s *model);
*
****************************************************************************/
unsigned int nandmodel_getblockpagesize(FAR const struct nand_model_s *model);
#define nandmodel_getpageblocksize(m) \
((uint32_t)((m)->blocksize << 10) / model->pagesize)
/****************************************************************************
* Name: nandmodel_getblockbytesize
* 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
*
****************************************************************************/
#define nandmodel_getdevpagesize(m) \
((uint32_t)nandmodel_getdevblocksize(m) * nandmodel_getpageblocksize(m))
/****************************************************************************
* Name: nandmodel_getbyteblocksize
*
* Description:
* Returns the size in bytes of one single block of a device. This does not
@@ -306,7 +308,7 @@ unsigned int nandmodel_getblockpagesize(FAR const struct nand_model_s *model);
*
****************************************************************************/
unsigned int nandmodel_getblockbytesize(FAR const struct nand_model_s *model);
#define nandmodel_getbyteblocksize(m) ((unsigned int)(m)->blocksize << 10)
/****************************************************************************
* Name: nandmodel_getpagesize
@@ -322,7 +324,7 @@ unsigned int nandmodel_getblockbytesize(FAR const struct nand_model_s *model);
*
****************************************************************************/
unsigned int nandmodel_getpagesize(FAR const struct nand_model_s *model);
#define nandmodel_getpagesize(m) ((m)->pagesize)
/****************************************************************************
* Name: nandmodel_getsparesize
@@ -354,7 +356,8 @@ unsigned int nandmodel_getsparesize(FAR const struct nand_model_s *model);
*
****************************************************************************/
unsigned int nandmodel_getbuswidth(FAR const struct nand_model_s *model);
#define nandmodel_getbuswidth(m) \
(((m)->options & NANDMODEL_DATAWIDTH16) ? 16 : 8)
/****************************************************************************
* Name: nandmodel_havesmallblocks
@@ -372,7 +375,7 @@ unsigned int nandmodel_getbuswidth(FAR const struct nand_model_s *model);
*
****************************************************************************/
bool nandmodel_havesmallblocks(FAR const struct nand_model_s *model);
#define nandmodel_havesmallblocks(m) ((m)->pagesize <= 512)
/****************************************************************************
* Name: nandmodel_havecopyback
@@ -390,7 +393,7 @@ bool nandmodel_havesmallblocks(FAR const struct nand_model_s *model);
*
****************************************************************************/
bool nandmodel_havecopyback(FAR const struct nand_model_s *model);
#define nandmodel_havecopyback(m) (((m)->options & NANDMODEL_COPYBACK) != 0)
#undef EXTERN
#ifdef __cplusplus
+165
View File
@@ -0,0 +1,165 @@
/****************************************************************************
* include/nuttx/mtd/nand_raw.h
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* This logic was based largely on Atmel sample code with modifications for
* better integration with NuttX. The Atmel sample code has a BSD
* compatibile license that requires this copyright notice:
*
* Copyright (c) 2012, Atmel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the names NuttX nor Atmel nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_MTD_NAND_RAW_H
#define __INCLUDE_NUTTX_MTD_NAND_RAW_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/mtd/mtd.h>
#include <nuttx/mtd/nand_model.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/* Nand flash commands */
#define COMMAND_READ_1 0x00
#define COMMAND_READ_2 0x30
#define COMMAND_COPYBACK_READ_1 0x00
#define COMMAND_COPYBACK_READ_2 0x35
#define COMMAND_COPYBACK_PROGRAM_1 0x85
#define COMMAND_COPYBACK_PROGRAM_2 0x10
#define COMMAND_RANDOM_OUT 0x05
#define COMMAND_RANDOM_OUT_2 0xe0
#define COMMAND_RANDOM_IN 0x85
#define COMMAND_READID 0x90
#define COMMAND_WRITE_1 0x80
#define COMMAND_WRITE_2 0x10
#define COMMAND_ERASE_1 0x60
#define COMMAND_ERASE_2 0xd0
#define COMMAND_STATUS 0x70
#define COMMAND_RESET 0xff
/* Nand flash commands (small blocks) */
#define COMMAND_READ_A 0x00
#define COMMAND_READ_C 0x50
/* NAND access macros */
#define WRITE_COMMAND8(raw, command) \
{*((volatile uint8_t *)raw->cmdaddr) = (uint8_t)command;}
#define WRITE_COMMAND16(raw, command) \
{*((volatile uint16_t *)raw->cmdaddr) = (uint16_t)command;}
#define WRITE_ADDRESS8(raw, address) \
{*((volatile uint8_t *)raw->addraddr) = (uint8_t)address;}
#define WRITE_ADDRESS16(raw, address) \
{*((volatile uint16_t *)raw->addraddr) = (uint16_t)address;}
#define WRITE_DATA8(raw, data) \
{*((volatile uint8_t *)raw->dataaddr) = (uint8_t)data;}
#define READ_DATA8(raw) \
(*((volatile uint8_t *)raw->dataaddr))
#define WRITE_DATA16(raw, data) \
{*((volatile uint16_t *) raw->dataaddr) = (uint16_t)data;}
#define READ_DATA16(raw) \
(*((volatile uint16_t *)raw->dataaddr))
/****************************************************************************
* Public Types
****************************************************************************/
/* This type represents the visible portion of the lower-half, raw NAND MTD
* device. Rules:
*
* 1. 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_raw_s.
* 2. The lower-half driver may freely append additional information after
* this required header information.
*/
struct nand_raw_s
{
struct mtd_dev_s mtd; /* Externally visible part of the driver */
struct nand_model_s model; /* The NAND model storage */
uintptr_t cmdaddr; /* NAND command address base */
uintptr_t addraddr; /* NAND address address base */
uintptr_t dataaddr; /* NAND data address */
};
/****************************************************************************
* Public Data
****************************************************************************/
#ifndef __ASSEMBLY__
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: nand_chipid
*
* Description:
* Reads and returns the identifiers of a NAND FLASH chip
*
* Input Parameters:
* raw - Pointer to a struct nand_raw_s instance.
*
* Returned Value:
* id1|(id2<<8)|(id3<<16)|(id4<<24)
*
****************************************************************************/
uint32_t nand_chipid(FAR struct nand_raw_s *raw);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __INCLUDE_NUTTX_MTD_NAND_RAW_H */