mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 11:56:10 +08:00
Add support for ONFI compatible NAND devices (NAND logic still incomplete)
This commit is contained in:
@@ -6065,3 +6065,7 @@
|
|||||||
* include/nuttx/mtd/mtd.h: Move include/nutt/mtd.h to
|
* include/nuttx/mtd/mtd.h: Move include/nutt/mtd.h to
|
||||||
include/nuttx/mtd/mtd.h where it will, hopefully, soon be joined by
|
include/nuttx/mtd/mtd.h where it will, hopefully, soon be joined by
|
||||||
other MTD-related header files (2013-11-15).
|
other MTD-related header files (2013-11-15).
|
||||||
|
* drivers/mtd/mtd_onfi.c and include/nuttx/mtd/onfi.h: Add sharedi
|
||||||
|
NAND routines for use with ONFI compatible NAND FLASH devices
|
||||||
|
(2013-11-15).
|
||||||
|
|
||||||
|
|||||||
@@ -164,6 +164,20 @@
|
|||||||
|
|
||||||
#define BUTTON_USER1_BIT (1 << BUTTON_USER1)
|
#define BUTTON_USER1_BIT (1 << BUTTON_USER1)
|
||||||
|
|
||||||
|
/* NAND *****************************************************************************/
|
||||||
|
|
||||||
|
/* Address for transferring command bytes to the nandflash, CLE A22*/
|
||||||
|
|
||||||
|
#define BOARD_NF_COMMAND_ADDR 0x60400000
|
||||||
|
|
||||||
|
/* Address for transferring address bytes to the nandflash, ALE A21*/
|
||||||
|
|
||||||
|
#define BOARD_NF_ADDRESS_ADDR 0x60200000
|
||||||
|
|
||||||
|
/* Address for transferring data bytes to the nandflash.*/
|
||||||
|
|
||||||
|
#define BOARD_NF_DATA_ADDR 0x60000000
|
||||||
|
|
||||||
/* PIO configuration ****************************************************************/
|
/* PIO configuration ****************************************************************/
|
||||||
/* LCDC */
|
/* LCDC */
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,15 @@ config MTD_NAND
|
|||||||
Enable support for NAND FLASH devices.
|
Enable support for NAND FLASH devices.
|
||||||
|
|
||||||
if MTD_NAND
|
if MTD_NAND
|
||||||
|
|
||||||
|
config MTD_NAND_EMBEDDEDECC
|
||||||
|
bool "Support devices with Embedded ECC"
|
||||||
|
default n
|
||||||
|
---help--
|
||||||
|
Some NAND devices have internal, embedded ECC function. One (the
|
||||||
|
only one supported) is Micron, 4-bit ECC, device size = 1Gb or 2Gb
|
||||||
|
or 4Gb.
|
||||||
|
|
||||||
endif # MTD_NAND
|
endif # MTD_NAND
|
||||||
|
|
||||||
config RAMMTD
|
config RAMMTD
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ ifeq ($(CONFIG_MTD_PARTITION),y)
|
|||||||
CSRCS += mtd_partition.c
|
CSRCS += mtd_partition.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_MTD_NAND),y)
|
||||||
|
CSRCS += mtd_onfi.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_RAMMTD),y)
|
ifeq ($(CONFIG_RAMMTD),y)
|
||||||
CSRCS += rammtd.c
|
CSRCS += rammtd.c
|
||||||
endif
|
endif
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,115 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* include/nuttx/mtd/nand_model.h
|
||||||
|
*
|
||||||
|
* ONFI Support. The Open NAND Flash Interface (ONFI) is an industry
|
||||||
|
* Workgroup made up of more than 100 companies that build, design-in, or
|
||||||
|
* enable NAND Flash memory. This file provides definitions for standardized
|
||||||
|
* ONFI NAND interfaces.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* This ogic 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_MODEL_H
|
||||||
|
#define __INCLUDE_NUTTX_MTD_NAND_MODEL_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-Processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* Number of NandFlash models inside the model list */
|
||||||
|
|
||||||
|
#define NAND_NMODELS 60
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* Describes a particular model of NandFlash device. */
|
||||||
|
|
||||||
|
struct nand_model_s
|
||||||
|
{
|
||||||
|
uint8_t devid; /* Identifier for the device */
|
||||||
|
uint8_t options; /* Special options for the NandFlash */
|
||||||
|
uint16_t pagesize; /* Size of the data area of a page in bytes */
|
||||||
|
uint16_t sparesize; /* Size of the spare area of a page in bytes */
|
||||||
|
uint16_t devsize; /* Size of the device in MB */
|
||||||
|
uint16_t blocksize; /* Size of one block in kilobytes */
|
||||||
|
|
||||||
|
/* Spare area placement scheme */
|
||||||
|
|
||||||
|
FAR const struct nand_scheme_s *scheme;
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* List of NandFlash models which can be recognized by the software */
|
||||||
|
|
||||||
|
EXTERN const struct nand_model_s g_nandmodels[NAND_NMODELS];
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __ASSEMBLY__ */
|
||||||
|
#endif /* __INCLUDE_NUTTX_MTD_NAND_MODEL_H */
|
||||||
@@ -0,0 +1,195 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* include/nuttx/mtd/onfi.h
|
||||||
|
*
|
||||||
|
* ONFI Support. The Open NAND Flash Interface (ONFI) is an industry
|
||||||
|
* Workgroup made up of more than 100 companies that build, design-in, or
|
||||||
|
* enable NAND Flash memory. This file provides definitions for standardized
|
||||||
|
* ONFI NAND interfaces.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* This ONFI 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) 2010, 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_ONFI_H
|
||||||
|
#define __INCLUDE_NUTTX_MTD_ONFI_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-Processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* Opaque handler used to interact with the ONFI module */
|
||||||
|
|
||||||
|
typedef FAR void *ONFI_HANDLE;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: onfi_compatible
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This function read an the ONFI signature at address of 20h to detect
|
||||||
|
* if the device is ONFI compatiable.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* cmdaddr - NAND command address base
|
||||||
|
* addraddr - NAND address address base
|
||||||
|
* dataaddr - NAND data address
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* True if ONFI compatible
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
bool onfi_compatible(uintptr_t cmdaddr, uintptr_t addraddr,
|
||||||
|
uintptr_t dataaddr);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: onfi_create
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* If the addresses refere to a compatible ONFI device, then create the
|
||||||
|
* ONFI handle that can be used to interact with the device.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* cmdaddr - NAND command address base
|
||||||
|
* addraddr - NAND address address base
|
||||||
|
* dataaddr - NAND data address
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* On success, a non-NULL ONFI handle is returned. This handle must be
|
||||||
|
* freed by calling onfi_destroy with it is no longer needed.
|
||||||
|
* NULL is returned on any failure. Failures include such things as
|
||||||
|
* memory allocation failures, ONFI incompatibility, timeouts, etc.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
ONFI_HANDLE *onfi_create(uintptr_t cmdaddr, uintptr_t addraddr,
|
||||||
|
uintptr_t dataaddr);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: onfi_destroy
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Free resources allocated on onfi_create() when the ONFI handle was
|
||||||
|
* created. Upon return, the ONFI handle is no longer valid and should not
|
||||||
|
* be used further.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* handle - An ONFI handle previously created by onfi_create().
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void onfi_destroy(ONFI_HANDLE handle);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: onfi_embeddedecc
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Enable or disable the NAND's embedded ECC controller.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* handle - An ONFI handle previously created by onfi_create().
|
||||||
|
* enable - True: enabled the embedded ECC function; False: disable it
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* True - Internal ECC enabled or disabled successfully
|
||||||
|
* False - Internal ECC not supported.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_MTD_NAND_EMBEDDEDECC
|
||||||
|
bool onfi_embeddedecc(ONFI_HANDLE handle, bool enable);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: onfi_ebidetect
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Detect Nand connection on EBI
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* cmdaddr - NAND command address base
|
||||||
|
* addraddr - NAND address address base
|
||||||
|
* dataaddr - NAND data address
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* True if the chip is detected; false otherwise.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
bool onfi_ebidetect(uintptr_t cmdaddr, uintptr_t addraddr, uintptr_t
|
||||||
|
dataaddr);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __ASSEMBLY__ */
|
||||||
|
#endif /* __INCLUDE_NUTTX_MTD_ONFI_H */
|
||||||
Reference in New Issue
Block a user