Home | History | Annotate | Download | only in Flash
      1 /** @file
      2 
      3   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
      4 
      5   This program and the accompanying materials
      6   are licensed and made available under the terms and conditions of the BSD License
      7   which accompanies this distribution.  The full text of the license may be found at
      8   http://opensource.org/licenses/bsd-license.php
      9 
     10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12 
     13 **/
     14 
     15 #ifndef FLASH_H
     16 #define FLASH_H
     17 
     18 #include <Uefi.h>
     19 
     20 #include <Library/BaseLib.h>
     21 #include <Library/BaseMemoryLib.h>
     22 #include <Library/MemoryAllocationLib.h>
     23 #include <Library/DebugLib.h>
     24 #include <Library/IoLib.h>
     25 #include <Library/PcdLib.h>
     26 #include <Library/UefiBootServicesTableLib.h>
     27 #include <Library/IoLib.h>
     28 
     29 #include <Protocol/BlockIo.h>
     30 #include <Protocol/Cpu.h>
     31 #include <Omap3530/Omap3530.h>
     32 
     33 #define PAGE_SIZE(x)             ((x) & 0x01)
     34 #define PAGE_SIZE_2K_VAL         (0x01UL)
     35 
     36 #define SPARE_AREA_SIZE(x)       (((x) >> 2) & 0x01)
     37 #define SPARE_AREA_SIZE_64B_VAL  (0x1UL)
     38 
     39 #define BLOCK_SIZE(x)            (((x) >> 4) & 0x01)
     40 #define BLOCK_SIZE_128K_VAL      (0x01UL)
     41 
     42 #define ORGANIZATION(x)          (((x) >> 6) & 0x01)
     43 #define ORGANIZATION_X8          (0x0UL)
     44 #define ORGANIZATION_X16         (0x1UL)
     45 
     46 #define PAGE_SIZE_512B           (512)
     47 #define PAGE_SIZE_2K             (2048)
     48 #define PAGE_SIZE_4K             (4096)
     49 #define SPARE_AREA_SIZE_16B      (16)
     50 #define SPARE_AREA_SIZE_64B      (64)
     51 
     52 #define BLOCK_SIZE_16K           (16*1024)
     53 #define BLOCK_SIZE_128K          (128*1024)
     54 
     55 #define BLOCK_COUNT              (2048)
     56 #define LAST_BLOCK               (BLOCK_COUNT - 1)
     57 
     58 #define ECC_POSITION             2
     59 
     60 //List of commands.
     61 #define RESET_CMD                0xFF
     62 #define READ_ID_CMD              0x90
     63 
     64 #define READ_STATUS_CMD          0x70
     65 
     66 #define PAGE_READ_CMD            0x00
     67 #define PAGE_READ_CONFIRM_CMD    0x30
     68 
     69 #define BLOCK_ERASE_CMD          0x60
     70 #define BLOCK_ERASE_CONFIRM_CMD  0xD0
     71 
     72 #define PROGRAM_PAGE_CMD         0x80
     73 #define PROGRAM_PAGE_CONFIRM_CMD 0x10
     74 
     75 //Nand status register bit definition
     76 #define NAND_SUCCESS             (0x0UL << 0)
     77 #define NAND_FAILURE             BIT0
     78 
     79 #define NAND_BUSY                (0x0UL << 6)
     80 #define NAND_READY               BIT6
     81 
     82 #define NAND_RESET_STATUS        (0x60UL << 0)
     83 
     84 #define MAX_RETRY_COUNT          1500
     85 
     86 
     87 typedef struct {
     88   UINT8 ManufactureId;
     89   UINT8 DeviceId;
     90   UINT8 BlockAddressStart; //Start of the Block address in actual NAND
     91   UINT8 PageAddressStart;  //Start of the Page address in actual NAND
     92 } NAND_PART_INFO_TABLE;
     93 
     94 typedef struct {
     95   UINT8     ManufactureId;
     96   UINT8     DeviceId;
     97   UINT8     Organization;      //x8 or x16
     98   UINT32    PageSize;
     99   UINT32    SparePageSize;
    100   UINT32    BlockSize;
    101   UINT32    NumPagesPerBlock;
    102   UINT8     BlockAddressStart; //Start of the Block address in actual NAND
    103   UINT8     PageAddressStart;  //Start of the Page address in actual NAND
    104 } NAND_FLASH_INFO;
    105 
    106 #endif //FLASH_H
    107