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