3 * Data Flash Atmel Description File
4 * Author : Hamid Ikdoumi (Atmel)
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 /* File Name : dataflash.h */
26 /* Object : Data Flash Atmel Description File */
29 /* 1.0 03/04/01 HI : Creation */
30 /* 1.2 20/10/02 FB : Adapatation Service and Lib v3 */
31 /*----------------------------------------------------------------------*/
37 #include <asm/arch/hardware.h>
40 /*number of protected area*/
41 #ifdef CONFIG_NEW_PARTITION
42 # define NB_DATAFLASH_AREA 6
44 # define NB_DATAFLASH_AREA 4
49 /*-----------------------------------------------------------------------
50 * return codes from flash_write():
54 # define ERR_NOT_ERASED 2
55 # define ERR_PROTECTED 4
58 # define ERR_UNKNOWN_FLASH_VENDOR 32
59 # define ERR_UNKNOWN_FLASH_TYPE 64
60 # define ERR_PROG_ERROR 128
62 /*-----------------------------------------------------------------------
63 * Protection Flags for flash_protect():
65 # define FLAG_PROTECT_SET 0x01
66 # define FLAG_PROTECT_CLEAR 0x02
67 # define FLAG_PROTECT_INVALID 0x03
69 /*-----------------------------------------------------------------------
70 * Set Environment according to label:
72 # define FLAG_SETENV 0x80
73 #endif /* CFG_NO_FLASH */
75 /*define the area structure*/
79 unsigned char protected;
81 unsigned char label[20];
82 } dataflash_protect_t;
84 typedef unsigned int AT91S_DataFlashStatus;
86 /*----------------------------------------------------------------------*/
87 /* DataFlash Structures */
88 /*----------------------------------------------------------------------*/
90 /*---------------------------------------------*/
91 /* DataFlash Descriptor Structure Definition */
92 /*---------------------------------------------*/
93 typedef struct _AT91S_DataflashDesc {
94 unsigned char *tx_cmd_pt;
95 unsigned int tx_cmd_size;
96 unsigned char *rx_cmd_pt;
97 unsigned int rx_cmd_size;
98 unsigned char *tx_data_pt;
99 unsigned int tx_data_size;
100 unsigned char *rx_data_pt;
101 unsigned int rx_data_size;
102 volatile unsigned char state;
103 volatile unsigned char DataFlash_state;
104 unsigned char command[8];
105 } AT91S_DataflashDesc, *AT91PS_DataflashDesc;
107 /*---------------------------------------------*/
108 /* DataFlash device definition structure */
109 /*---------------------------------------------*/
110 typedef struct _AT91S_Dataflash {
111 int pages_number; /* dataflash page number */
112 int pages_size; /* dataflash page size */
113 int page_offset; /* page offset in command */
114 int byte_mask; /* byte mask in command */
116 dataflash_protect_t area_list[NB_DATAFLASH_AREA]; /* area protection status */
117 } AT91S_DataflashFeatures, *AT91PS_DataflashFeatures;
119 /*---------------------------------------------*/
120 /* DataFlash Structure Definition */
121 /*---------------------------------------------*/
122 typedef struct _AT91S_DataFlash {
123 AT91PS_DataflashDesc pDataFlashDesc; /* dataflash descriptor */
124 AT91PS_DataflashFeatures pDevice; /* Pointer on a dataflash features array */
125 } AT91S_DataFlash, *AT91PS_DataFlash;
128 typedef struct _AT91S_DATAFLASH_INFO {
130 AT91S_DataflashDesc Desc;
131 AT91S_DataflashFeatures Device; /* Pointer on a dataflash features array */
132 unsigned long logical_address;
133 unsigned long end_address;
134 unsigned int id; /* device id */
135 } AT91S_DATAFLASH_INFO, *AT91PS_DATAFLASH_INFO;
138 /*-------------------------------------------------------------------------------------------------*/
140 #define AT45DB161 0x2c
141 #define AT45DB321 0x34
142 #define AT45DB642 0x3c
143 #define AT45DB128 0x10
144 #define PAGES_PER_BLOCK 8
146 #define AT91C_DATAFLASH_TIMEOUT 10000 /* For AT91F_DataFlashWaitReady */
148 /* DataFlash return value */
149 #define DATAFLASH_BUSY 0x00
150 #define DATAFLASH_OK 0x01
151 #define DATAFLASH_ERROR 0x02
152 #define DATAFLASH_MEMORY_OVERFLOW 0x03
153 #define DATAFLASH_BAD_COMMAND 0x04
154 #define DATAFLASH_BAD_ADDRESS 0x05
162 /* DataFlash Driver State */
163 #define GET_STATUS 0x0F
165 /*-------------------------------------------------------------------------------------------------*/
166 /* Command Definition */
167 /*-------------------------------------------------------------------------------------------------*/
170 #define DB_CONTINUOUS_ARRAY_READ 0xE8 /* Continuous array read */
171 #define DB_BURST_ARRAY_READ 0xE8 /* Burst array read */
172 #define DB_PAGE_READ 0xD2 /* Main memory page read */
173 #define DB_BUF1_READ 0xD4 /* Buffer 1 read */
174 #define DB_BUF2_READ 0xD6 /* Buffer 2 read */
175 #define DB_STATUS 0xD7 /* Status Register */
177 /* PROGRAM and ERASE COMMANDS */
178 #define DB_BUF1_WRITE 0x84 /* Buffer 1 write */
179 #define DB_BUF2_WRITE 0x87 /* Buffer 2 write */
180 #define DB_BUF1_PAGE_ERASE_PGM 0x83 /* Buffer 1 to main memory page program with built-In erase */
181 #define DB_BUF1_PAGE_ERASE_FASTPGM 0x93 /* Buffer 1 to main memory page program with built-In erase, Fast program */
182 #define DB_BUF2_PAGE_ERASE_PGM 0x86 /* Buffer 2 to main memory page program with built-In erase */
183 #define DB_BUF2_PAGE_ERASE_FASTPGM 0x96 /* Buffer 1 to main memory page program with built-In erase, Fast program */
184 #define DB_BUF1_PAGE_PGM 0x88 /* Buffer 1 to main memory page program without built-In erase */
185 #define DB_BUF1_PAGE_FASTPGM 0x98 /* Buffer 1 to main memory page program without built-In erase, Fast program */
186 #define DB_BUF2_PAGE_PGM 0x89 /* Buffer 2 to main memory page program without built-In erase */
187 #define DB_BUF2_PAGE_FASTPGM 0x99 /* Buffer 1 to main memory page program without built-In erase, Fast program */
188 #define DB_PAGE_ERASE 0x81 /* Page Erase */
189 #define DB_BLOCK_ERASE 0x50 /* Block Erase */
190 #define DB_PAGE_PGM_BUF1 0x82 /* Main memory page through buffer 1 */
191 #define DB_PAGE_FASTPGM_BUF1 0x92 /* Main memory page through buffer 1, Fast program */
192 #define DB_PAGE_PGM_BUF2 0x85 /* Main memory page through buffer 2 */
193 #define DB_PAGE_FastPGM_BUF2 0x95 /* Main memory page through buffer 2, Fast program */
195 /* ADDITIONAL COMMANDS */
196 #define DB_PAGE_2_BUF1_TRF 0x53 /* Main memory page to buffer 1 transfert */
197 #define DB_PAGE_2_BUF2_TRF 0x55 /* Main memory page to buffer 2 transfert */
198 #define DB_PAGE_2_BUF1_CMP 0x60 /* Main memory page to buffer 1 compare */
199 #define DB_PAGE_2_BUF2_CMP 0x61 /* Main memory page to buffer 2 compare */
200 #define DB_AUTO_PAGE_PGM_BUF1 0x58 /* Auto page rewrite throught buffer 1 */
201 #define DB_AUTO_PAGE_PGM_BUF2 0x59 /* Auto page rewrite throught buffer 2 */
203 /*-------------------------------------------------------------------------------------------------*/
205 extern int size_dataflash (AT91PS_DataFlash pdataFlash, unsigned long addr, unsigned long size);
206 extern int prot_dataflash (AT91PS_DataFlash pdataFlash, unsigned long addr);
207 extern int addr2ram(ulong addr);
208 extern int dataflash_real_protect (int flag, unsigned long start_addr, unsigned long end_addr);
209 extern int addr_dataflash (unsigned long addr);
210 extern int read_dataflash (unsigned long addr, unsigned long size, char *result);
211 extern int write_dataflash (unsigned long addr, unsigned long dest, unsigned long size);
212 extern void dataflash_print_info (void);
213 extern void dataflash_perror (int err);
215 #ifdef CONFIG_NEW_DF_PARTITION
216 extern int AT91F_DataflashSetEnv (void); #endif