⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flash_nand_toshiba.c

📁 Flash的驱动程序。包括市面上常见的Nor Flash和Nand Flash.基本上所有的Flash只需要简单修改就可以移植到其他应用。
💻 C
字号:
/********************************************************************** * flash_nand_toshiba.c * * Toshiba NAND device level operations * * This file implements the functions specific to Toshiba nand * devices.  * * Copyright (C) 2004-2006 Qualcomm, Inc.  All Rights Reserved. * **********************************************************************//*===========================================================================                        EDIT HISTORY FOR MODULE  This section contains comments describing changes made to the module.  Notice that changes are listed in reverse chronological order.  $Header: //depot/asic/msmshared/drivers/flash/MSM_FLASH.01.04/flash_nand_toshiba.c#4 $ $DateTime: 2006/05/16 22:40:13 $ $Author: dhamimp $when         who     what, where, why--------     ---     ----------------------------------------------------------2006-05-04   dp      Adding controller abstraction layer2006-02-18   rt      Modularize the bad_block marking and check functions2006-02-17   rt      Add support for 2K page NAND devices2005-11-16   yug     Changed Offset location dependent on NAND Controller. FOZ controller is New.2005-09-27   yug     Corrected typo in badblock offset.2005-08-25   drh     Correct re-init of NAND config registers after NAND controller reset2005-08-02   drh     Changes to compile in L4 environment2005-07-29   drh     Modify bad block flag usage to be configurable2005-05-13   drh     Correct limit handling2005-04-28   drh     Add support for Toshiba TC58DDM92F2.  Remove macros for                     clear status bits, done in NAND CMD macro instead2005-01-28   drh     Add fix for 8-bit NAND after reset2004-10-04   drh     Add NAND specific partition header file2004-09-30   drh     Move partition functions out to partition specific file2004-09-29   drh     Support for dynamic 8/16 bit use2004-09-24   drh     Correct handling of block numbers by using variable                     instead of #define2004-08-26   drh     Conditionally compile out functions not needed by                     boot loader.2004-08-11   drh     Add support for turning ECC off when needed2004-07-20    gr     Added multi-threading support.2004-07-20   drh     Remove use of NAND_NON_DMSS, use BOOT_LOADER and                     BUILD_JNAND instead.                     Fix bug in mark_block_bad function.2004-07-08   drh     Add 8/16 bit protection2004-06-10   drh     Remove variation and use common write page.2004-05-17   drh     Move variation for Toshiba 16-bit write from common                     to toshiba specific file.2004-05-06  jkl/hw   Added 16 bit NAND support.2004-03-08   dlb     Rename FS_NAND... to FLASH_NAND...2004-03-26   drh     Use single common ops table for all devices.                     Modify probe to fill in device structure.2004-03-19   drh     Change partition manipulation function names.2004-02-23   drh     Move device specific function dispatch tables out of                     device common file and put them here.                     Remove functions that merely returned constants as they                     are replaced by generic functions in flash_nand_device.c.2004-01-21   drh     Came from services/efs/fs_nand_toshiba.c===========================================================================*/#include "flash_nand_toshiba.h"#include "flash_msg.h"/* Forward and External Function Declarations */static int toshiba_nand_bad_block_check(fs_device_t self, block_id block);/* Device specific data, unique to each flash device */static const struct flash_device_config_data toshiba_devices_array[] = {  /*==========================================================*/  {    /* Toshiba TC58512F flash */    /* Device specific data */    "toshiba_tc58512ft",            /* Device Name           */    4096,                           /* Block Count           */    32,                             /* Page Count            */    512,                            /* Page Size             */    528,                            /* Total Page Size       */    0x98,                           /* Maker ID              */    0x76,                           /* Device ID             */    FLASHI_NAND_8BIT,               /* Device width          */    0x0, 0x0,                       /* dev_specfic_flag1/2   */  }, /* END Toshiba TC58512F flash */  /*==========================================================*/  /*==========================================================*/  {    /* Toshiba TCDAM82F1 flash(16bit NAND device) */    /* Device specific data */    "toshiba_tcdam82f1",            /* Device Name           */    2048,                           /* Block Count           */    32,                             /* Page Count            */    512,                            /* Page Size             */    528,                            /* Total Page Size       */    0x98,                           /* Maker ID              */    0x75,                           /* Device ID             */    FLASHI_NAND_16BIT,              /* Device width          */    0x0, 0x0,                       /* dev_specfic_flag1/2   */  }, /* END Toshiba TC58512F flash */  /*==========================================================*/  /*==========================================================*/  {    /* Toshiba TC58DDM92F2 flash */    /* Device specific data */    "toshiba_tc58ddm92f2",            /* Device Name           */    4096,                           /* Block Count           */    32,                             /* Page Count            */    512,                            /* Page Size             */    528,                            /* Total Page Size       */    0x98,                           /* Maker ID              */    0x46,                           /* Device ID             */    FLASHI_NAND_16BIT,              /* Device width          */    0x0, 0x0,                       /* dev_specfic_flag1/2   */  }, /* END Toshiba TC58DDM92F2 flash */  /*==========================================================*/};/***********************************************************************FUNCTION      toshiba_probeDESCRIPTION   This function looks through the devices it knows about              to find a match on both maker ID and device ID, and if              it finds a match, returns a pointer to the device              structure.RETURN VALUE  FS_DEVICE_OK             if match found              FSI_NO_DEVICE            if match not found **********************************************************************/inttoshiba_probe (fsi_device_t priv, int maker_id, int device_id){  int dev_no;  int total_no_devices = sizeof (toshiba_devices_array) /                          sizeof (struct flash_device_config_data);  for (dev_no = 0; dev_no < total_no_devices; dev_no++)  {    if ((toshiba_devices_array[dev_no].maker_id == maker_id) &&        (toshiba_devices_array[dev_no].device_id == device_id))    {      /* We have found a match of IDs. */      /* Fill in device structures, public, then private */      priv->pub_dev.bad_block_check = toshiba_nand_bad_block_check;            priv->dev_info = toshiba_devices_array[dev_no];      /*        * Fill in individual value fields.        *     For right now, allow access to entire flash.       */      priv->partition_blk_start = 0;      priv->partition_blk_limit = toshiba_devices_array[dev_no].block_count;      return FS_DEVICE_OK;    }  }  return FSI_NO_DEVICE;}/***********************************************************************FUNCTION      toshiba_nand_bad_block_checkDESCRIPTION   This function should be called to determine the initial              bad blocks marked by the device maker. If the 517th column              of the 1st or 2nd page of a block has non FFh data then              that block is considered invalid.RETURN VALUE  FS_DEVICE_OK if the block is ok, else FS_DEVICE_BAD_BLOCK**********************************************************************/static inttoshiba_nand_bad_block_check (fs_device_t self, block_id block){  fsi_device_t priv = (fsi_device_t)self;  page_id page;  page_id page_offset;  uint32 status;  uint32 spare_unit = 0;  int  result = FS_DEVICE_OK;  int spare_offset;  int len;  spare_offset = priv->ctlr.get_bad_block_offset(self);  len = (priv->dev_info.device_width == FLASHI_NAND_16BIT) ? 2 : 1;  /* Set the first page number */  page = (block << priv->block_size_shift);   /* Check the first page of the block */  for (page_offset = 0; page_offset < 1; page_offset++)  {    status = flash_nand_read_spare_bytes(self, (page + page_offset),                spare_offset, len, &spare_unit);    if (status != FS_DEVICE_OK)    {      /* Error encountered while reading the spare bytes. Return bad block         so as not to have this block erased by mistake and allow the issue          to be debugged */      return FS_DEVICE_BAD_BLOCK;    }      result = flash_nand_check_bad_block_marker (self, spare_unit);        if(result == FS_DEVICE_BAD_BLOCK)    {      TPRINTF(3,("Spare unit value 0x%x for block 0x%x\n", spare_unit, block));      break;    }  }  return result;} /* End of toshiba_nand_bad_block_check */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -