blob: be035f9f1778c26f978cf0b9757c79979a2b73c8 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/******************************************************************************
2 *
3 * (C)Copyright 2005 - 2008 Marvell. All Rights Reserved.
4 *
5 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MARVELL.
6 * The copyright notice above does not evidence any actual or intended
7 * publication of such source code.
8 * This Module contains Proprietary Information of Marvell and should be
9 * treated as Confidential.
10 * The information in this file is provided for the exclusive use of the
11 * licensees of Marvell.
12 * Such users have the right to use, modify, and incorporate this code into
13 * products for purposes authorized by the license agreement provided they
14 * include this notice and the associated copyright notice with any such
15 * product.
16 * The information in this file is provided "AS IS" without warranty.
17 *
18 ******************************************************************************/
19
20/***********************************************************
21* SPIFlash.h
22* This is the header file for the SPIFlash driver.
23*
24* Revision History:
25* 5/2/07 - initial draft
26************************************************************/
27#ifndef __SPI_NAND_H__
28#define __SPI_NAND_H__
29
30
31
32#include "Typedef.h"
33#include "Flash.h"
34#include "SSP.h"
35#include "predefines.h"
36#include "platform_interrupts.h"
37#include "xllp_dmac.h"
38
39/*
40* SPI Command Set
41*/
42#define SN_WRITE_ENABLE 0x06
43#define SN_WRITE_DISABLE 0x04
44#define SN_GET_FEATURES 0x0F
45#define SN_SET_FEATURES 0x1F
46#define SN_CACHE_LOAD 0x13
47#define SN_CACHE_READ 0x03
48#define SN_READ_ID 0x9F
49#define SN_PROGRAM_LOAD 0x02
50#define SN_PROGRAM_EXECUTE 0x10
51#define SN_BLOCK_ERASE 0xD8
52#define SN_RESET 0xFF
53
54
55/*
56 * SPI NAND Feature Types
57 */
58
59typedef enum
60{
61 SN_PROTECTION = 0xA0,
62 SN_FEATURE = 0xB0,
63 SN_STATUS = 0xC0
64} SN_Feature_E;
65
66//
67// GigaDevice GD5F1GQ4RAYIG: protection register 0xa0
68//
69// 7 6 5 4 3 2 1 0
70// +------+------+------+------+------+------+------+------+
71// | BRWD | BP3 | BP2 | BP1 | BP0 | INV | CMP |Rerd |
72// +------+------+------+------+------+------+------+------+
73
74#define GIGA_SPINAND_PROTECTION_Rerd1 BIT_0 // Rserved
75#define GIGA_SPINAND_PROTECTION_CMP BIT_1 // level of protected blcok
76#define GIGA_SPINAND_PROTECTION_INV BIT_2 // level of protected blcok
77#define GIGA_SPINAND_PROTECTION_BP0 BIT_3 // level of protected blcok
78#define GIGA_SPINAND_PROTECTION_BP1 BIT_4 // level of protected blcok
79#define GIGA_SPINAND_PROTECTION_BP2 BIT_5 // level of protected blcok
80#define GIGA_SPINAND_PROTECTION_BP3 BIT_6 // level of protected blcok
81#define GIGA_SPINAND_PROTECTION_BRWD BIT_7 // block protection lock
82
83//
84// GigaDevice GD5F1GQ4RAYIG: feature register 0xb0
85//
86// 7 6 5 4 3 2 1 0
87// +-------+------+------+------+------+------+------+------+
88// |OTP_PRT|OTP_EN| Rerd |ECC_EN| Rerd | Rerd | Rerd | QE |
89// +-------+------+------+------+------+------+------+------+
90
91#define GIGA_SPINAND_FEATURE_QE BIT_0 // quad enable
92#define GIGA_SPINAND_FEATURE_Rerd3 BIT_1 // reserved
93#define GIGA_SPINAND_FEATURE_Rerd2 BIT_2 // reserved
94#define GIGA_SPINAND_FEATURE_Rerd1 BIT_3 // reserved
95#define GIGA_SPINAND_FEATURE_ECC_EN BIT_4 // ecc enable
96#define GIGA_SPINAND_FEATURE_Rerd BIT_5 // reserved
97#define GIGA_SPINAND_FEATURE_OTP_EN BIT_6 // one-time program
98#define GIGA_SPINAND_FEATURE_OTP_PRT BIT_7 // one-time program
99
100//
101// GigaDevice GD5F1GQ4RAYIG: status register 0xc0
102//
103// 7 6 5 4 3 2 1 0
104// +-----+------+------+------+------+------+------+------+
105// | Rerd| Rerd |ECCS1 |ECCS0 |P_FAIL|E_FAIL| WEL | OIP |
106// +-----+------+------+------+------+------+------+------+
107
108#define GIGA_SPINAND_STATUS_OIP BIT_0 // operation in progress
109#define GIGA_SPINAND_STATUS_WEL BIT_1 // write enable latch
110#define GIGA_SPINAND_STATUS_E_FAIL BIT_2 // erase fail
111#define GIGA_SPINAND_STATUS_P_FAIL BIT_3 // program fail
112#define GIGA_SPINAND_STATUS_ECCS0 BIT_4 // ecc status
113#define GIGA_SPINAND_STATUS_ECCS1 BIT_5 // ecc status
114#define GIGA_SPINAND_STATUS_Rerd BIT_6 // reserved
115#define GIGA_SPINAND_STATUS_Rerd1 BIT_7 // reserved
116
117/*
118 * SPI NAND Timeouts (all in MICRO seconds!!)
119 * NOTE: I roughly doubled all the values listed in the specification, as the
120 * core will be running slowly in BootROM and I wanted to avoid any situation
121 * where the operation finished at the edge of the timeout value, but the
122 * slow running core captures the timer value just after timeout
123 */
124
125#define SN_READ_TIMEOUT 0x100 //maximum time to load a page into the cache field
126#define SN_ERASE_TIMEOUT 0x800 //maximum time for the erase operation
127#define SN_PROGRAM_TIMEOUT 0x5000 //maximum time for the program operation
128
129#define SSP_READ_TIME_OUT 0x80000 //timeout for reading data from cache to internal memory
130 //this is dependent on CPU and DMA clock speeds, NOT the SPI device!
131
132/*
133 * SPI NAND: other values
134 */
135
136#define SN_PAGE_SIZE 0x800 //SPI NAND pages are 2KB
137#define SN_BLOCK_SIZE 0x20000 //SPI NAND blocks are 128KB
138
139
140struct SN_ADDRESS_FIELDS
141{
142 unsigned int CA :11; // 11 bits of column. there are 12 bits of column, but the highest bit is always 0
143 unsigned int RA :16; // RA[0:5] - this is the Page address
144 // RA[6:15] - this is the Block Number
145 unsigned int no :5; // unused upper 4 bits
146};
147
148typedef union
149{
150 unsigned int value;
151 struct SN_ADDRESS_FIELDS fields;
152} SN_ADDRESS_FIELD_T;
153
154
155//function definitions
156UINT_T InitializeSPINAND(UINT8_T FlashNum, UINT8_T* P_DefaultPartitionNum);
157void SPINAND_ReadID(unsigned char *mid, unsigned char *did);
158unsigned int SPINAND_Read(unsigned int FlashOffset, unsigned int Buffer, unsigned int Size);
159void SPINAND_CacheLoad(unsigned int Address);
160unsigned char SPINAND_GetFeatures(SN_Feature_E feature_type);
161unsigned char SPINAND_SetFeatures(SN_Feature_E feature_type, unsigned char feature);
162unsigned int SPINAND_CacheRead_4Bytes(unsigned int Offset, unsigned int Buffer, unsigned int Size);
163unsigned int SPINAND_CacheRead_1Byte(unsigned int Offset, unsigned int Buffer, unsigned int Size);
164
165
166unsigned int SPINAND_Write(unsigned int FlashOffset, unsigned int Buffer, unsigned int Size);
167unsigned int SPINAND_ProgramLoad_1Byte(unsigned int Address, unsigned int Buffer, unsigned int Size);
168unsigned int SPINAND_ProgramLoad_4Bytes(unsigned int Address, unsigned int Buffer, unsigned int Size);
169unsigned int SPINAND_ProgramLoadPIO(unsigned int Address, unsigned int Buffer, unsigned int Size);
170
171void SPINAND_WriteEnable(void);
172void SPINAND_ProgramExecute(unsigned int Address);
173unsigned int SPINAND_Erase(unsigned int FlashOffset, unsigned int Size);
174void SPINAND_BlockErase(unsigned int Address);
175unsigned int SPINAND_Reset(FlashBootType_T fbt);
176void SPINAND_UnProtectBlocks(void);
177UINT_T SPINAND_CheckReady(void);
178
179#endif
180