reduce size
[romboot.git] / dataflash.h
blobc8dfb91aa5a57607ad274a92f16f125d70f34bc6
1 //*---------------------------------------------------------------------------
2 //* ATMEL Microcontroller Software Support - ROUSSET -
3 //*---------------------------------------------------------------------------
4 //* The software is delivered "AS IS" without warranty or condition of any
5 //* kind, either express, implied or statutory. This includes without
6 //* limitation any warranty or condition with respect to merchantability or
7 //* fitness for any particular purpose, or against the infringements of
8 //* intellectual property rights of others.
9 //*---------------------------------------------------------------------------
10 //* File Name : AT91_SpiDataFlash.h
11 //* Object : Data Flash Atmel Description File
12 //* Translator :
13 //*
14 //* 1.0 03/04/01 HI : Creation
15 //*
16 //*---------------------------------------------------------------------------
18 #ifndef _DataFlash_h
19 #define _DataFlash_h
21 #define CFG_MAX_DATAFLASH_BANKS 4
22 #define CFG_DATAFLASH_LOGIC_ADDR_CS0 0xC0000000
23 #define CFG_DATAFLASH_LOGIC_ADDR_CS1 0xC1000000
24 #define CFG_DATAFLASH_LOGIC_ADDR_CS2 0xC2000000
25 #define CFG_DATAFLASH_LOGIC_ADDR_CS3 0xC3000000
28 typedef struct {
29 unsigned long base; /* logical base address for a bank */
30 unsigned long size; /* total bank size */
31 unsigned long page_count;
32 unsigned long page_size;
33 unsigned long id; /* device id */
34 } dataflash_info_t;
36 typedef unsigned int AT91S_DataFlashStatus;
38 /*----------------------------------------------------------------------*/
39 /* DataFlash Structures */
40 /*----------------------------------------------------------------------*/
42 /*---------------------------------------------*/
43 /* DataFlash Descriptor Structure Definition */
44 /*---------------------------------------------*/
45 typedef struct _AT91S_DataflashDesc {
46 unsigned char *tx_cmd_pt;
47 unsigned int tx_cmd_size;
48 unsigned char *rx_cmd_pt;
49 unsigned int rx_cmd_size;
50 unsigned char *tx_data_pt;
51 unsigned int tx_data_size;
52 unsigned char *rx_data_pt;
53 unsigned int rx_data_size;
54 volatile unsigned char state;
55 volatile unsigned char DataFlash_state;
56 unsigned char command[8];
57 } AT91S_DataflashDesc, *AT91PS_DataflashDesc;
59 /*---------------------------------------------*/
60 /* DataFlash device definition structure */
61 /*---------------------------------------------*/
62 typedef struct _AT91S_Dataflash {
63 int pages_number; /* dataflash page number */
64 int pages_size; /* dataflash page size */
65 int page_offset; /* page offset in command */
66 int byte_mask; /* byte mask in command */
67 int cs;
68 } AT91S_DataflashFeatures, *AT91PS_DataflashFeatures;
71 /*---------------------------------------------*/
72 /* DataFlash Structure Definition */
73 /*---------------------------------------------*/
74 typedef struct _AT91S_DataFlash {
75 AT91PS_DataflashDesc pDataFlashDesc; /* dataflash descriptor */
76 AT91PS_DataflashFeatures pDevice; /* Pointer on a dataflash features array */
77 } AT91S_DataFlash, *AT91PS_DataFlash;
80 typedef struct _AT91S_DATAFLASH_INFO {
82 AT91S_DataflashDesc Desc;
83 AT91S_DataflashFeatures Device; /* Pointer on a dataflash features array */
84 unsigned long logical_address;
85 unsigned int id; /* device id */
86 } AT91S_DATAFLASH_INFO, *AT91PS_DATAFLASH_INFO;
89 /*-------------------------------------------------------------------------------------------------*/
91 #define AT45DB161 0x2c
92 #define AT45DB321 0x34
93 #define AT45DB642 0x3c
94 #define AT45DB128 0x10
96 #define AT91C_DATAFLASH_TIMEOUT 20000 /* For AT91F_DataFlashWaitReady */
98 /* DataFlash return value */
99 #define AT91C_DATAFLASH_BUSY 0x00
100 #define AT91C_DATAFLASH_OK 0x01
101 #define AT91C_DATAFLASH_ERROR 0x02
102 #define AT91C_DATAFLASH_MEMORY_OVERFLOW 0x03
103 #define AT91C_DATAFLASH_BAD_COMMAND 0x04
104 #define AT91C_DATAFLASH_BAD_ADDRESS 0x05
107 /* Driver State */
108 #define IDLE 0x0
109 #define BUSY 0x1
110 #define ERROR 0x2
112 /* DataFlash Driver State */
113 #define GET_STATUS 0x0F
115 /*-------------------------------------------------------------------------------------------------*/
116 /* Command Definition */
117 /*-------------------------------------------------------------------------------------------------*/
119 /* READ COMMANDS */
120 #define DB_CONTINUOUS_ARRAY_READ 0xE8 /* Continuous array read */
121 #define DB_BURST_ARRAY_READ 0xE8 /* Burst array read */
122 #define DB_PAGE_READ 0xD2 /* Main memory page read */
123 #define DB_BUF1_READ 0xD4 /* Buffer 1 read */
124 #define DB_BUF2_READ 0xD6 /* Buffer 2 read */
125 #define DB_STATUS 0xD7 /* Status Register */
127 /* PROGRAM and ERASE COMMANDS */
128 #define DB_BUF1_WRITE 0x84 /* Buffer 1 write */
129 #define DB_BUF2_WRITE 0x87 /* Buffer 2 write */
130 #define DB_BUF1_PAGE_ERASE_PGM 0x83 /* Buffer 1 to main memory page program with built-In erase */
131 #define DB_BUF1_PAGE_ERASE_FASTPGM 0x93 /* Buffer 1 to main memory page program with built-In erase, Fast program */
132 #define DB_BUF2_PAGE_ERASE_PGM 0x86 /* Buffer 2 to main memory page program with built-In erase */
133 #define DB_BUF2_PAGE_ERASE_FASTPGM 0x96 /* Buffer 1 to main memory page program with built-In erase, Fast program */
134 #define DB_BUF1_PAGE_PGM 0x88 /* Buffer 1 to main memory page program without built-In erase */
135 #define DB_BUF1_PAGE_FASTPGM 0x98 /* Buffer 1 to main memory page program without built-In erase, Fast program */
136 #define DB_BUF2_PAGE_PGM 0x89 /* Buffer 2 to main memory page program without built-In erase */
137 #define DB_BUF2_PAGE_FASTPGM 0x99 /* Buffer 1 to main memory page program without built-In erase, Fast program */
138 #define DB_PAGE_ERASE 0x81 /* Page Erase */
139 #define DB_BLOCK_ERASE 0x50 /* Block Erase */
140 #define DB_PAGE_PGM_BUF1 0x82 /* Main memory page through buffer 1 */
141 #define DB_PAGE_FASTPGM_BUF1 0x92 /* Main memory page through buffer 1, Fast program */
142 #define DB_PAGE_PGM_BUF2 0x85 /* Main memory page through buffer 2 */
143 #define DB_PAGE_FastPGM_BUF2 0x95 /* Main memory page through buffer 2, Fast program */
145 /* ADDITIONAL COMMANDS */
146 #define DB_PAGE_2_BUF1_TRF 0x53 /* Main memory page to buffer 1 transfert */
147 #define DB_PAGE_2_BUF2_TRF 0x55 /* Main memory page to buffer 2 transfert */
148 #define DB_PAGE_2_BUF1_CMP 0x60 /* Main memory page to buffer 1 compare */
149 #define DB_PAGE_2_BUF2_CMP 0x61 /* Main memory page to buffer 2 compare */
150 #define DB_AUTO_PAGE_PGM_BUF1 0x58 /* Auto page rewrite throught buffer 1 */
151 #define DB_AUTO_PAGE_PGM_BUF2 0x59 /* Auto page rewrite throught buffer 2 */
153 /*-------------------------------------------------------------------------------------------------*/
156 typedef struct read_lock_cmd
158 unsigned char cmd[4];
159 int rxsize;
160 int txsize;
161 } t_read_lock_cmd;
164 extern AT91S_DATAFLASH_INFO dataflash_info[CFG_MAX_DATAFLASH_BANKS];
165 unsigned int AT91F_SpiWrite ( AT91PS_DataflashDesc pDesc);
166 extern void AT91F_SpiInit (void);
167 extern int AT91F_DataflashProbe (int i, AT91PS_DataflashDesc pDesc);
168 extern int AT91F_DataFlashRead (AT91PS_DataFlash, unsigned long , unsigned long, char *);
169 extern AT91S_DataFlashStatus AT91F_DataFlashWrite(AT91PS_DataFlash ,unsigned char *, int, int);
170 extern int AT91F_DataflashInit (void);
171 extern void AT91F_DataflashPrintInfo(void);
172 AT91S_DataFlashStatus AT91F_DataFlashWaitReady(AT91PS_DataflashDesc pDataFlashDesc, unsigned int timeout);
173 void AT91F_SpiEnable(int cs);
175 extern int addr_dataflash (unsigned long addr);
176 extern int read_dataflash (unsigned long addr, unsigned long size, char *result);
177 extern int write_dataflash (unsigned long addr_dest, unsigned int addr_src, unsigned int size);
178 AT91S_DataFlashStatus AT91F_PageErase( AT91PS_DataFlash pDataFlash,unsigned int page);
180 int get_size_reg(void);
182 int erase_dataflash(int nb);
183 // static void clear_desc( AT91S_DataflashDesc *d);
184 void read_lock_reg(t_read_lock_cmd *ptrcmd);
185 void erase_lock_reg(int fl_nb);
186 void program_lock_reg(int fl_nb);
187 void flash_enable_lock(int fl_nb);
188 void flash_disable_lock(int fl_nb);
189 void erase_chip(int);
191 extern t_read_lock_cmd read_lock_cmd_sector;
192 extern read_lock_cmd read_lock_cmd_lockdown;
193 extern read_lock_cmd read_lock_cmd_security;
195 #endif