2013-11-15 09:30:05 -06:00
|
|
|
/****************************************************************************
|
|
|
|
* arch/arm/src/sama5/sam_nand.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* 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 name NuttX 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 __ARCH_ARM_SRC_SAMA5_SAM_NAND_H
|
|
|
|
#define __ARCH_ARM_SRC_SAMA5_SAM_NAND_H
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2013-11-20 13:55:23 -06:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2013-11-18 09:43:44 -06:00
|
|
|
#include <nuttx/mtd/nand_raw.h>
|
|
|
|
|
2013-11-15 09:30:05 -06:00
|
|
|
#include "chip.h"
|
|
|
|
#include "chip/sam_hsmc.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
2013-11-19 08:50:12 -06:00
|
|
|
/* Configuration ************************************************************/
|
|
|
|
/* Block checking and H/W ECC support must be enabled for HSIAO ECC */
|
|
|
|
|
|
|
|
#if !defined(CONFIG_MTD_NAND_BLOCKCHECK) || !defined(MTD_NAND_HWECC)
|
|
|
|
# undef CONFIG_SAMA5_EBICS0_HSIAO
|
|
|
|
# undef CONFIG_SAMA5_EBICS1_HSIAO
|
|
|
|
# undef CONFIG_SAMA5_EBICS2_HSIAO
|
|
|
|
# undef CONFIG_SAMA5_EBICS3_HSIAO
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Disable HSIAO support for any banks not enabled or configured for NAND */
|
|
|
|
|
|
|
|
#if !defined(SAMA5_EBICS0) || !defined(SAMA5_EBICS0_NAND)
|
|
|
|
# undef CONFIG_SAMA5_EBICS0_HSIAO
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(SAMA5_EBICS1) || !defined(SAMA5_EBICS1_NAND)
|
|
|
|
# undef CONFIG_SAMA5_EBICS1_HSIAO
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(SAMA5_EBICS2) || !defined(SAMA5_EBICS2_NAND)
|
|
|
|
# undef CONFIG_SAMA5_EBICS2_HSIAO
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(SAMA5_EBICS3) || !defined(SAMA5_EBICS3_NAND)
|
|
|
|
# undef CONFIG_SAMA5_EBICS3_HSIAO
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef NAND_HAVE_HSIAO
|
|
|
|
#if defined(CONFIG_SAMA5_EBICS0_HSIAO) || defined(CONFIG_SAMA5_EBICS1_HSIAO) || \
|
|
|
|
defined(CONFIG_SAMA5_EBICS2_HSIAO) || defined(CONFIG_SAMA5_EBICS3_HSIAO)
|
|
|
|
# define NAND_HAVE_HSIAO
|
|
|
|
#endif
|
|
|
|
|
2013-11-18 09:43:44 -06:00
|
|
|
/* Hardware ECC types. These are extensions to the NANDECC_HWECC value
|
|
|
|
* defined in include/nuttx/mtd/nand_raw.h.
|
|
|
|
*
|
|
|
|
* NANDECC_CHIPECC ECC is performed internal to chip
|
|
|
|
* NANDECC_PMECC Programmable Multibit Error Correcting Code (PMECC)
|
|
|
|
* NANDECC_HSIAO HSIAO ECC
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NANDECC_CHIPECC (NANDECC_HWECC + 0)
|
|
|
|
#define NANDECC_PMECC (NANDECC_HWECC + 1)
|
|
|
|
#define NANDECC_HSIAO (NANDECC_HWECC + 2)
|
|
|
|
|
2013-11-20 13:55:23 -06:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
|
|
|
/* This type represents the state of a raw NAND MTD device on a single chip
|
|
|
|
* select. The struct nand_raw_s must appear at the beginning of the
|
|
|
|
* definition so that you can freely cast between pointers to struct
|
|
|
|
* nand_raw_s and struct sam_nandcs_s.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct sam_nandcs_s
|
|
|
|
{
|
|
|
|
struct nand_raw_s raw; /* Externally visible part of the driver */
|
|
|
|
uint8_t cs :2; /* Chip select number (0..3) */
|
|
|
|
uint8_t nfcen :1; /* True: NFC is enabled */
|
|
|
|
uint8_t nfcsram :1; /* True: Use NFC SRAM */
|
|
|
|
uint8_t dmaxfr :1; /* True: Use DMA transfers */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Register debug state */
|
|
|
|
|
|
|
|
#ifdef CONFIG_SAMA5_NAND_REGDEBUG
|
|
|
|
struct sam_nanddbg_s
|
|
|
|
{
|
|
|
|
bool wr; /* Last was a write */
|
|
|
|
uint32_t regadddr; /* Last address */
|
|
|
|
uint32_t regval; /* Last value */
|
|
|
|
int ntimes; /* Number of times */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2013-11-18 09:43:44 -06:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
2013-11-15 09:30:05 -06:00
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C" {
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2013-11-20 13:55:23 -06:00
|
|
|
/* NAND regiser debug state */
|
|
|
|
|
|
|
|
#ifdef CONFIG_SAMA5_NAND_REGDEBUG
|
|
|
|
EXTERN struct sam_nanddbg_s g_nanddbg;
|
|
|
|
#endif
|
|
|
|
|
2013-11-15 09:30:05 -06:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: sam_nand_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
2013-11-17 12:22:09 -06:00
|
|
|
* Create and initialize an raw NAND device instance. This driver
|
|
|
|
* implements the RAW NAND interface: No software ECC or sparing is
|
2013-11-15 09:30:05 -06:00
|
|
|
* performed here. Those necessary NAND features are provided by common,
|
2013-11-17 12:22:09 -06:00
|
|
|
* higher level NAND MTD layers found in drivers/mtd.
|
|
|
|
*
|
2013-11-15 09:30:05 -06:00
|
|
|
* Input parameters:
|
|
|
|
* cs - Chip select number (in the event that multiple NAND devices
|
|
|
|
* are connected on-board).
|
2013-11-17 12:22:09 -06:00
|
|
|
*
|
2013-11-15 09:30:05 -06:00
|
|
|
* Returned value.
|
|
|
|
* On success a non-NULL pointer to an MTD device structure is returned;
|
|
|
|
* NULL is returned on a failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct mtd_dev_s;
|
|
|
|
struct mtd_dev_s *sam_nand_initialize(int cs);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: board_nandflash_config
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* If CONFIG_SAMA5_BOOT_CS3FLASH is defined, then NAND FLASH support is
|
|
|
|
* enabled. This function provides the board-specific implementation of
|
|
|
|
* the logic to reprogram the SMC to support NAND FLASH on the specified
|
|
|
|
* CS.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* cs - Chip select number (in the event that multiple NAND devices
|
|
|
|
* are connected on-board).
|
|
|
|
*
|
|
|
|
* Returned Values:
|
|
|
|
* OK if the HSMC was successfully configured for this CS. A negated
|
|
|
|
* errno value is returned on a failure. This would fail with -ENODEV,
|
|
|
|
* for example, if the board does not support NAND FLASH on the requested
|
|
|
|
* CS.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int board_nandflash_config(int cs);
|
|
|
|
|
2013-11-16 13:19:09 -06:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: board_nand_busy
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Must be provided if the board logic supports and interface to detect
|
|
|
|
* NAND Busy/Ready signal.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* cs - Chip select number (in the event that multiple NAND devices
|
|
|
|
* are connected on-board).
|
|
|
|
*
|
|
|
|
* Returned Values:
|
|
|
|
* True: NAND is busy, False: NAND is ready
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SAMA5_NAND_READYBUSY
|
|
|
|
bool board_nand_busy(int cs);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: board_nandflash_config
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Must be provided if the board logic supports and interface to control
|
|
|
|
* the NAND Chip Enable signal.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* cs - Chip select number (in the event that multiple NAND devices
|
|
|
|
* are connected on-board).
|
|
|
|
* enable - True: enable Chip Select, False: Disable Chip select
|
|
|
|
*
|
|
|
|
* Returned Values:
|
|
|
|
* OK if the HSMC was successfully configured for this CS. A negated
|
|
|
|
* errno value is returned on a failure. This would fail with -ENODEV,
|
|
|
|
* for example, if the board does not support NAND FLASH on the requested
|
|
|
|
* CS.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SAMA5_NAND_CE
|
|
|
|
void board_nand_ce(int cs, bool enable);
|
|
|
|
#endif
|
|
|
|
|
2013-11-20 13:55:23 -06:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nand_checkreg
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if the current HSMC register access is a duplicate of the preceding.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* regval - The value to be written
|
|
|
|
* regaddr - The address of the register to write to
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* true: This is the first register access of this type.
|
|
|
|
* flase: This is the same as the preceding register access.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SAMA5_NAND_REGDEBUG
|
|
|
|
bool nand_checkreg(bool wr, uintptr_t regaddr, uint32_t regval);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nand_getreg
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read an HSMC register
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline uint32_t nand_getreg(uintptr_t regaddr)
|
|
|
|
{
|
|
|
|
uint32_t regval = getreg32(regaddr);
|
|
|
|
|
|
|
|
#ifdef CONFIG_SAMA5_NAND_REGDEBUG
|
|
|
|
if (nand_checkreg(false, regaddr, regval))
|
|
|
|
{
|
|
|
|
lldbg("%08x->%08x\n", regaddr, regval);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return regval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nand_putreg
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Write a value to an HSMC register
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void nand_putreg(uintptr_t regaddr, uint32_t regval)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SAMA5_NAND_REGDEBUG
|
|
|
|
if (nand_checkreg(true, regaddr, regval))
|
|
|
|
{
|
|
|
|
lldbg("%08x<-%08x\n", regaddr, regval);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
putreg32(regval, regaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nand_nfc_enable
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Enable the NAND FLASH controller
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void nand_nfc_enable(struct sam_nandcs_s *priv)
|
|
|
|
{
|
|
|
|
priv->nfcen = true;
|
|
|
|
nand_putreg(SAM_HSMC_CTRL, HSMC_CTRL_NFCEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nand_nfc_enable
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Enable the NAND FLASH controller
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - A reference to the NAND chip select data structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void nand_nfc_disable(struct sam_nandcs_s *priv)
|
|
|
|
{
|
|
|
|
priv->nfcen = false;
|
|
|
|
nand_putreg(SAM_HSMC_CTRL, HSMC_CTRL_NFCDIS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nand_nfc_enabled
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the state of the NAND FLASH controller
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - A reference to the NAND chip select data structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* True if the NAND FLASH controller is enabled
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline uint8_t nand_nfc_enabled(struct sam_nandcs_s *priv)
|
|
|
|
{
|
|
|
|
return (bool)priv->nfcen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nand_nfcsram_enable
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Enable use of NFC Host SRAM
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - A reference to the NAND chip select data structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void nand_nfcsram_enable(struct sam_nandcs_s *priv)
|
|
|
|
{
|
|
|
|
priv->nfcsram = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nand_nfcsram_disable
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Disable use of NFC Host SRAM
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - A reference to the NAND chip select data structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void nand_nfcsram_disable(struct sam_nandcs_s *priv)
|
|
|
|
{
|
|
|
|
priv->nfcsram = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nand_nfcsram_enabled
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Returrn the state of the NFS Host SRAM
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - A reference to the NAND chip select data structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* True if the NFC Host SRAM is used
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline bool nand_nfcsram_enabled(struct sam_nandcs_s *priv)
|
|
|
|
{
|
|
|
|
return (bool)priv->nfcsram;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nand_nanddma_enable
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Enable use of DMA to perform transfers
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - A reference to the NAND chip select data structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void nand_nanddma_enable(struct sam_nandcs_s *priv)
|
|
|
|
{
|
|
|
|
priv->dmaxfr = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nand_nanddma_disable
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Disable use of DMA to perform transfers
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - A reference to the NAND chip select data structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void nand_nanddma_disable(struct sam_nandcs_s *priv)
|
|
|
|
{
|
|
|
|
priv->dmaxfr = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nand_nanddma_enabled
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Returrn the state of the DMA usage
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - A reference to the NAND chip select data structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* True if transfers are performed using DMA
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
bool nand_nanddma_enabled(struct sam_nandcs_s *priv)
|
|
|
|
{
|
|
|
|
return priv->dmaxfr;
|
|
|
|
}
|
|
|
|
|
2013-11-15 09:30:05 -06:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
#endif /* __ARCH_ARM_SRC_SAMA5_SAM_NAND_H */
|