1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#ifndef _DataFlash_h
34#define _DataFlash_h
35
36
37#include "config.h"
38
39
40#define NB_DATAFLASH_AREA 5
41
42#ifdef CONFIG_SYS_NO_FLASH
43
44
45
46
47# define ERR_OK 0
48# define ERR_TIMOUT 1
49# define ERR_NOT_ERASED 2
50# define ERR_PROTECTED 4
51# define ERR_INVAL 8
52# define ERR_ALIGN 16
53# define ERR_UNKNOWN_FLASH_VENDOR 32
54# define ERR_UNKNOWN_FLASH_TYPE 64
55# define ERR_PROG_ERROR 128
56
57
58
59
60# define FLAG_PROTECT_SET 0x01
61# define FLAG_PROTECT_CLEAR 0x02
62# define FLAG_PROTECT_INVALID 0x03
63
64
65
66
67# define FLAG_SETENV 0x80
68#endif
69
70
71typedef struct {
72 unsigned long start;
73 unsigned long end;
74 unsigned char protected;
75 unsigned char setenv;
76 unsigned char label[20];
77} dataflash_protect_t;
78
79typedef unsigned int AT91S_DataFlashStatus;
80
81
82
83
84
85
86
87
88typedef struct _AT91S_DataflashDesc {
89 unsigned char *tx_cmd_pt;
90 unsigned int tx_cmd_size;
91 unsigned char *rx_cmd_pt;
92 unsigned int rx_cmd_size;
93 unsigned char *tx_data_pt;
94 unsigned int tx_data_size;
95 unsigned char *rx_data_pt;
96 unsigned int rx_data_size;
97 volatile unsigned char state;
98 volatile unsigned char DataFlash_state;
99 unsigned char command[8];
100} AT91S_DataflashDesc, *AT91PS_DataflashDesc;
101
102
103
104
105typedef struct _AT91S_Dataflash {
106 int pages_number;
107 int pages_size;
108 int page_offset;
109 int byte_mask;
110 int cs;
111 dataflash_protect_t area_list[NB_DATAFLASH_AREA];
112} AT91S_DataflashFeatures, *AT91PS_DataflashFeatures;
113
114
115
116
117typedef struct _AT91S_DataFlash {
118 AT91PS_DataflashDesc pDataFlashDesc;
119 AT91PS_DataflashFeatures pDevice;
120} AT91S_DataFlash, *AT91PS_DataFlash;
121
122
123typedef struct _AT91S_DATAFLASH_INFO {
124
125 AT91S_DataflashDesc Desc;
126 AT91S_DataflashFeatures Device;
127 unsigned long logical_address;
128 unsigned long end_address;
129 unsigned int id;
130} AT91S_DATAFLASH_INFO, *AT91PS_DATAFLASH_INFO;
131
132struct dataflash_addr {
133 unsigned long addr;
134 int cs;
135};
136
137#define AT45DB161 0x2c
138#define AT45DB021 0x14
139#define AT45DB081 0x24
140#define AT45DB321 0x34
141#define AT45DB642 0x3c
142#define AT45DB128 0x10
143#define PAGES_PER_BLOCK 8
144
145#define AT91C_DATAFLASH_TIMEOUT 10000
146
147
148#define DATAFLASH_BUSY 0x00
149#define DATAFLASH_OK 0x01
150#define DATAFLASH_ERROR 0x02
151#define DATAFLASH_MEMORY_OVERFLOW 0x03
152#define DATAFLASH_BAD_COMMAND 0x04
153#define DATAFLASH_BAD_ADDRESS 0x05
154
155
156
157#define IDLE 0x0
158#define BUSY 0x1
159#define ERROR 0x2
160
161
162#define GET_STATUS 0x0F
163
164
165
166
167
168
169#define DB_CONTINUOUS_ARRAY_READ 0xE8
170#define DB_BURST_ARRAY_READ 0xE8
171#define DB_PAGE_READ 0xD2
172#define DB_BUF1_READ 0xD4
173#define DB_BUF2_READ 0xD6
174#define DB_STATUS 0xD7
175
176
177#define DB_BUF1_WRITE 0x84
178#define DB_BUF2_WRITE 0x87
179#define DB_BUF1_PAGE_ERASE_PGM 0x83
180#define DB_BUF1_PAGE_ERASE_FASTPGM 0x93
181#define DB_BUF2_PAGE_ERASE_PGM 0x86
182#define DB_BUF2_PAGE_ERASE_FASTPGM 0x96
183#define DB_BUF1_PAGE_PGM 0x88
184#define DB_BUF1_PAGE_FASTPGM 0x98
185#define DB_BUF2_PAGE_PGM 0x89
186#define DB_BUF2_PAGE_FASTPGM 0x99
187#define DB_PAGE_ERASE 0x81
188#define DB_BLOCK_ERASE 0x50
189#define DB_PAGE_PGM_BUF1 0x82
190#define DB_PAGE_FASTPGM_BUF1 0x92
191#define DB_PAGE_PGM_BUF2 0x85
192#define DB_PAGE_FastPGM_BUF2 0x95
193
194
195#define DB_PAGE_2_BUF1_TRF 0x53
196#define DB_PAGE_2_BUF2_TRF 0x55
197#define DB_PAGE_2_BUF1_CMP 0x60
198#define DB_PAGE_2_BUF2_CMP 0x61
199#define DB_AUTO_PAGE_PGM_BUF1 0x58
200#define DB_AUTO_PAGE_PGM_BUF2 0x59
201
202
203
204extern int size_dataflash (AT91PS_DataFlash pdataFlash, unsigned long addr, unsigned long size);
205extern int prot_dataflash (AT91PS_DataFlash pdataFlash, unsigned long addr);
206extern int addr2ram(ulong addr);
207extern int dataflash_real_protect (int flag, unsigned long start_addr, unsigned long end_addr);
208extern int addr_dataflash (unsigned long addr);
209extern int read_dataflash (unsigned long addr, unsigned long size, char *result);
210extern int write_dataflash(unsigned long addr_dest, unsigned long addr_src,
211 unsigned long size);
212extern int AT91F_DataflashInit(void);
213
214extern void dataflash_print_info (void);
215extern void dataflash_perror (int err);
216extern void AT91F_DataflashSetEnv (void);
217
218extern struct dataflash_addr cs[CONFIG_SYS_MAX_DATAFLASH_BANKS];
219extern dataflash_protect_t area_list[NB_DATAFLASH_AREA];
220extern AT91S_DATAFLASH_INFO dataflash_info[];
221#endif
222