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>
42 unsigned long base; /* logical base address for a bank */
43 unsigned long size; /* total bank size */
44 unsigned long page_count;
45 unsigned long page_size;
46 unsigned long id; /* device id */
47 unsigned char protect[CFG_MAX_DATAFLASH_PAGES]; /* page protection status */
51 typedef unsigned int AT91S_DataFlashStatus;
53 /*----------------------------------------------------------------------*/
54 /* DataFlash Structures */
55 /*----------------------------------------------------------------------*/
57 /*---------------------------------------------*/
58 /* DataFlash Descriptor Structure Definition */
59 /*---------------------------------------------*/
60 typedef struct _AT91S_DataflashDesc {
61 unsigned char *tx_cmd_pt;
62 unsigned int tx_cmd_size;
63 unsigned char *rx_cmd_pt;
64 unsigned int rx_cmd_size;
65 unsigned char *tx_data_pt;
66 unsigned int tx_data_size;
67 unsigned char *rx_data_pt;
68 unsigned int rx_data_size;
69 volatile unsigned char state;
70 volatile unsigned char DataFlash_state;
71 unsigned char command[8];
72 } AT91S_DataflashDesc, *AT91PS_DataflashDesc;
74 /*---------------------------------------------*/
75 /* DataFlash device definition structure */
76 /*---------------------------------------------*/
77 typedef struct _AT91S_Dataflash {
78 int pages_number; /* dataflash page number */
79 int pages_size; /* dataflash page size */
80 int page_offset; /* page offset in command */
81 int byte_mask; /* byte mask in command */
83 } AT91S_DataflashFeatures, *AT91PS_DataflashFeatures;
85 /*---------------------------------------------*/
86 /* DataFlash Structure Definition */
87 /*---------------------------------------------*/
88 typedef struct _AT91S_DataFlash {
89 AT91PS_DataflashDesc pDataFlashDesc; /* dataflash descriptor */
90 AT91PS_DataflashFeatures pDevice; /* Pointer on a dataflash features array */
91 } AT91S_DataFlash, *AT91PS_DataFlash;
95 typedef struct _AT91S_DATAFLASH_INFO {
97 AT91S_DataflashDesc Desc;
98 AT91S_DataflashFeatures Device; /* Pointer on a dataflash features array */
99 unsigned long logical_address;
100 unsigned int id; /* device id */
101 unsigned char protect[CFG_MAX_DATAFLASH_PAGES]; /* page protection status */
102 } AT91S_DATAFLASH_INFO, *AT91PS_DATAFLASH_INFO;
105 /*-------------------------------------------------------------------------------------------------*/
107 #define AT45DB161 0x2c
108 #define AT45DB321 0x34
109 #define AT45DB642 0x3c
111 #define AT91C_DATAFLASH_TIMEOUT 10000 /* For AT91F_DataFlashWaitReady */
113 /* DataFlash return value */
114 #define DATAFLASH_BUSY 0x00
115 #define DATAFLASH_OK 0x01
116 #define DATAFLASH_ERROR 0x02
117 #define DATAFLASH_MEMORY_OVERFLOW 0x03
118 #define DATAFLASH_BAD_COMMAND 0x04
119 #define DATAFLASH_BAD_ADDRESS 0x05
127 /* DataFlash Driver State */
128 #define GET_STATUS 0x0F
130 /*-------------------------------------------------------------------------------------------------*/
131 /* Command Definition */
132 /*-------------------------------------------------------------------------------------------------*/
135 #define DB_CONTINUOUS_ARRAY_READ 0xE8 /* Continuous array read */
136 #define DB_BURST_ARRAY_READ 0xE8 /* Burst array read */
137 #define DB_PAGE_READ 0xD2 /* Main memory page read */
138 #define DB_BUF1_READ 0xD4 /* Buffer 1 read */
139 #define DB_BUF2_READ 0xD6 /* Buffer 2 read */
140 #define DB_STATUS 0xD7 /* Status Register */
142 /* PROGRAM and ERASE COMMANDS */
143 #define DB_BUF1_WRITE 0x84 /* Buffer 1 write */
144 #define DB_BUF2_WRITE 0x87 /* Buffer 2 write */
145 #define DB_BUF1_PAGE_ERASE_PGM 0x83 /* Buffer 1 to main memory page program with built-In erase */
146 #define DB_BUF1_PAGE_ERASE_FASTPGM 0x93 /* Buffer 1 to main memory page program with built-In erase, Fast program */
147 #define DB_BUF2_PAGE_ERASE_PGM 0x86 /* Buffer 2 to main memory page program with built-In erase */
148 #define DB_BUF2_PAGE_ERASE_FASTPGM 0x96 /* Buffer 1 to main memory page program with built-In erase, Fast program */
149 #define DB_BUF1_PAGE_PGM 0x88 /* Buffer 1 to main memory page program without built-In erase */
150 #define DB_BUF1_PAGE_FASTPGM 0x98 /* Buffer 1 to main memory page program without built-In erase, Fast program */
151 #define DB_BUF2_PAGE_PGM 0x89 /* Buffer 2 to main memory page program without built-In erase */
152 #define DB_BUF2_PAGE_FASTPGM 0x99 /* Buffer 1 to main memory page program without built-In erase, Fast program */
153 #define DB_PAGE_ERASE 0x81 /* Page Erase */
154 #define DB_BLOCK_ERASE 0x50 /* Block Erase */
155 #define DB_PAGE_PGM_BUF1 0x82 /* Main memory page through buffer 1 */
156 #define DB_PAGE_FASTPGM_BUF1 0x92 /* Main memory page through buffer 1, Fast program */
157 #define DB_PAGE_PGM_BUF2 0x85 /* Main memory page through buffer 2 */
158 #define DB_PAGE_FastPGM_BUF2 0x95 /* Main memory page through buffer 2, Fast program */
160 /* ADDITIONAL COMMANDS */
161 #define DB_PAGE_2_BUF1_TRF 0x53 /* Main memory page to buffer 1 transfert */
162 #define DB_PAGE_2_BUF2_TRF 0x55 /* Main memory page to buffer 2 transfert */
163 #define DB_PAGE_2_BUF1_CMP 0x60 /* Main memory page to buffer 1 compare */
164 #define DB_PAGE_2_BUF2_CMP 0x61 /* Main memory page to buffer 2 compare */
165 #define DB_AUTO_PAGE_PGM_BUF1 0x58 /* Auto page rewrite throught buffer 1 */
166 #define DB_AUTO_PAGE_PGM_BUF2 0x59 /* Auto page rewrite throught buffer 2 */
168 /*-------------------------------------------------------------------------------------------------*/
170 extern int addr_dataflash (unsigned long addr);
171 extern int read_dataflash (unsigned long addr, unsigned long size, char *result);
172 extern int write_dataflash (unsigned long addr, unsigned long dest, unsigned long size);
173 extern void dataflash_print_info (void);
174 extern void dataflash_perror (int err);