GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / arch / mips / board / bcm9635x / include / flash.h
blobf03f8fc9c041a65288986f32be3c0ac39ea8dad1
1 /*
2 <:copyright-gpl
4 Copyright 2002 Broadcom Corp. All Rights Reserved.
6 This program is free software; you can distribute it and/or modify it
7 under the terms of the GNU General Public License (Version 2) as
8 published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
21 //**************************************************************************
22 // Filename: flash.h
23 // Author: Dannie Gay
24 // Creation Date: 2-mar-97
26 //**************************************************************************
27 // Description:
29 // CM MAC FLASH Memory definitions for Intel 28F016SV Flash.
30 //
31 //**************************************************************************
32 // Revision History:
33 // 0.1 add support for AMD flash. 10-15-99 ytl
35 //**************************************************************************
36 #ifndef flash_h
37 #define flash_h
40 #if defined __cplusplus
41 extern "C" {
42 #endif
44 /* include board/CPU specific definitions */
45 #include "bcmtypes.h"
46 #include "board.h"
48 /* macro to convert logical data addresses to physical */
49 /* DMA hardware must see physical address */
50 #define LtoP( x ) ( (uint32)x & 0x1fffffff )
51 #define PtoL( x ) ( LtoP(x) | 0xa0000000 )
53 #define FLASH_BASE_ADDR_REG FLASH_BASE
55 /* Flash block lock request */
56 #define UNLOCK 0
57 #define LOCK 1
60 // this information is returned by the function DetectFlashInfo. DetectFlashInfo should only be
61 // called after the flash has been detected.
62 typedef struct _FLASH_INFO
64 unsigned long flash_base; // the base of the flash
65 unsigned long flash_block_size; // size of each block
66 unsigned long flash_block_mask; // mask of the block
67 unsigned short flash_block_total; // total number of blocks
68 unsigned short flashId; // yt flash id
69 } FLASH_INFO;
72 //------------------------------------------------------------------
73 // Flash Block (word) Size
74 //------------------------------------------------------------------
75 #define FLASH64K_BLOCK_SIZE 0x10000 //64K bytes
76 #define FLASH64K_BLOCK_SIZE_MASK 0xffff0000L
77 #define TOTAL64K_FLASH_BLOCKS 64 // 32
79 #define STRATA_FLASH_BLOCK_SIZE 0x20000 //128K bytes
80 #define STRATA_FLASH_BLOCK_SIZE_MASK 0xfffe0000L
81 #define STRATA_FLASH64_TOTAL_FLASH_BLOCKS 32 // onlly 32 can be used 64
82 #define STRATA_FLASH32_TOTAL_FLASH_BLOCKS 32
84 /* Strata Flash Specific Defines */
85 #define STRATA32_PHYS_FLASH_BASE 0x1FC00000
86 #define STRATA64_PHYS_FLASH_BASE 0x1FC00000
88 #define STRATA32_FLASH_BASE PHYS_TO_K1(STRATA32_PHYS_FLASH_BASE)
89 #define STRATA64_FLASH_BASE PHYS_TO_K1(STRATA64_PHYS_FLASH_BASE)
91 //------------------------------------------------------------------
92 // manufacturer/device ID codes
93 //------------------------------------------------------------------
94 #define STRATA_FLASH_MAN_CODE 0x0089
95 #define STRATA_FLASH32_DEV_CODE 0x0016
96 #define STRATA_FLASH64_DEV_CODE 0x0017
98 #define FLASH_ID ((FLASH_AMD29LV160B_MAN_CODE<<8)|FLASH_AMD29LV160BB_DEV_CODE)
100 #define FLASH_016_MAN_CODE 0x0089
101 #define FLASH_016_DEV_CODE 0x00a0
103 #define FLASH_160_MAN_CODE 0x00b0
104 #define FLASH_160_DEV_CODE 0x00d0
106 #define FLASH_320_MAN_CODE 0x00b0
107 #define FLASH_320_DEV_CODE 0x00d4
109 #define FLASH_28F320C3_MAN_CODE 0x0089
110 #define FLASH_28F320C3_DEV_CODE 0x00C5
112 #define FLASH_AMD29LV160B_MAN_CODE 0x0001
113 #define FLASH_AMD29LV160BB_DEV_CODE 0x0049
114 #define FLASH_AMD29LV160BT_DEV_CODE 0x00c4
116 #define FLASH_AMD29LV160BB_ID ((FLASH_AMD29LV160B_MAN_CODE<<8)|FLASH_AMD29LV160BB_DEV_CODE)
118 //------------------------------------------------------------------
119 // error codes
120 //------------------------------------------------------------------
121 #define NO_ERROR 0
122 #define VPP_LOW 1
123 #define OP_ABORTED 2
124 #define BLOCK_LOCKED 3
125 #define COMMAND_SEQ_ERROR 4
126 #define WP_LOW 5
127 #define OPERATION_STATUS_ERR 0x2020
129 //------------------------------------------------------------------
130 // Flash (28F00SA) Compatible Commands
131 //------------------------------------------------------------------
132 #define ALT_WORD_WRITE_CMD 0x1010
133 #define SINGLE_BLOCK_ERASE_CMD 0x2020
134 #define WORD_WRITE_CMD 0x4040
135 #define CLR_STATUS_REGS_CMD 0x5050
136 #define READ_CSR_CMD 0x7070
137 #define READ_ID_CODES_CMD 0x9090
138 #define ERASE_SUSPEND_CMD 0xb0b0
139 #define CONFIRM_RESUME_CMD 0xd0d0
140 #define READ_ARRAY_CMD 0xffff
141 #define CFG_SETUP_CMD 0x6060
142 #define BLOCK_LOCK_CMD 0x0101
143 #define BLOCK_UNLOCK_CMD 0xd0d0
146 //------------------------------------------------------------------
147 // Flash (28F016SA) Performance-Enhancement Commands
148 //------------------------------------------------------------------
149 #define PAGE_BUF_WRITE_CMD 0x0c0c
150 #define ESR_READ_CMD 0x7171
151 #define PAGE_BUF_SWAP_CMD 0x7272
152 #define SINGLE_LD_PAGE_BUF_CMD 0x7474
153 #define READ_PAGE_BUF_CMD 0x7575
154 #define LOCK_BLOCK_CMD 0x7777
155 #define ABORT_CMD 0x8080
156 #define UPL0AD_BSRS_WLCKBIT_CMD 0x9797
157 #define UPLOAD_DEV_INFO_CMD 0x9999
158 #define ERASE_ALL_UNLCK_BLKS_CMD 0xa7a7
159 #define SEQ_LOAD_PAGE_BUF_CMD 0xe0e0
160 #define SLEEP_CMD 0xf0f0
162 //------------------------------------------------------------------
163 // Flash (28F160S5) Commands and error codes
164 //------------------------------------------------------------------
165 #define READ_SR_CMD 0x7070
166 #define WRITE_BUFFER_CMD 0xe8e8
167 #define OPERATION_STATUS_ERR_2 0x0030
169 //------------------------------------------------------------------
170 // Various Bit Masks
171 //------------------------------------------------------------------
172 #define BIT_0 0x0001
173 #define BIT_1 0x0002
174 #define BIT_2 0x0004
175 #define BIT_3 0x0008
176 #define BIT_4 0x0010
177 #define BIT_5 0x0020
178 #define BIT_6 0x0040
179 #define BIT_7 0x0080
181 #define LOW_BYTE 0x00ff
182 #define HIGH_BYTE 0xff00
185 //------------------------------------------------------------------
186 // Flash (AMD29LV160B) Commands Sequence
187 //------------------------------------------------------------------
189 //macros for reading and writing to AMD flash directly using flashBasePtr as base pointer
190 #define AMDFLASH_READ_RAW(_addr) ( *( flashBasePtr + _addr ) )
191 #define AMDFLASH_WRITE_RAW(_sword, _addr) ( *( flashBasePtr + _addr ) = _sword )
193 #define AMD_MAN_ID_ADDR 0x00
194 #define AMD_DEV_ID_ADDR 0x01
195 #define AMD_SEC_PROTECT_ADDR 0x02
197 #define AMD_AUTOSELECT_CMD 0x9090
198 #define AMD_PROGRAM_CMD 0xa0a0
199 #define AMD_ULBYPASS_MOD_CMD 0x2020
200 #define AMD_ULBYPASS_PGM_CMD 0xa0a0
201 #define AMD_ULBYPASS_RST_CMD 0x9090
204 #define AMD_ERASE_CMD 0x8080
205 #define AMD_CHIP_ERASE_CMD 0x1010
206 #define AMD_SECTOR_ERASE_CMD 0x3030
208 #define AMD_ERASE_SUSPEND_CMD 0xb0b0
209 #define AMD_ERASE_RESUME_CMD 0x3030
211 #define AMD_RESET_CMD 0xf0f0
214 #define DQ2 0x04
215 #define DQ5 0x20
216 #define DQ6 0x40
217 #define DQ7 0x80
219 #define B6B2TOGGLE (DQ6+DQ2)
221 //------------------------------------------------------------------
222 // Functions
223 //------------------------------------------------------------------
224 // Debug macro: magical dissapearing BDGPrint() funcion for release built.
225 // Place BDGPrint() function anywhere during development for console debug.
226 // For production build, just undefine DEBUG_BUILD, the BDGPrint() will disappear.
227 // No need to comment out BDGPrint() statements in the code.
228 // Comment the following for release build, Uncomment the following for debug build
230 //#define DEBUG_BUILD
232 // usage
233 #ifdef DEBUG_BUILD
234 #define BDGPrint(x) Print x
235 #else
236 #define BDGPrint(x)
237 #endif
240 // flash read array macro
241 //#define READ_ARRAY *((unsigned short *)FLASH_BASE_ADDR_REG) = READ_ARRAY_CMD
242 #define READ_ARRAY Set_Read_Array()
244 extern void Delayms(uint16 n);
246 void sDelay(unsigned long cnt);
247 unsigned short * Base(unsigned short * dataPtr);
248 int BlkWriteProtect(unsigned short blk, int on);
249 int AddrWriteProtect(unsigned short * dest, int on);
250 int FlashBlockLock(volatile unsigned short * blockBase, int on);
251 int IsBlockProtected(unsigned short blk);
252 int EraseFlashAddressBlock(unsigned short * dest, unsigned short * esr);
253 int EraseFlashBlock(unsigned short blk);
254 int FlashWordWrite(unsigned short * dest, unsigned short * src, unsigned long count, unsigned short * esr);
255 unsigned short SuspendEraseToReadArray(unsigned short * dataPtr, unsigned short * result);
256 unsigned char ReadFlashCsrStatus(void);
257 unsigned short ReadDeviceInformation(void);
258 unsigned short ReadFlashIdCodes(void);
259 //dg-mod, added debugMsg parm, don't need AutoDetectFlash2() anymore
260 void AutoDetectFlash(unsigned char debugMsg);
261 void DetectFlashInfo(FLASH_INFO *);
262 void Set_Read_Array(void);
264 unsigned char flash_init(void);
265 unsigned char flash_reset(void);
266 unsigned char flash_sector_erase_int(unsigned char sector);
267 int flash_get_numsectors(void);
268 int flash_get_sector_size( unsigned char sector );
269 unsigned char *flash_get_memptr( unsigned char sector );
270 int flash_get_blk( int addr );
271 int flash_get_total_size(void);
272 #if defined __cplusplus
274 #endif
276 #endif