wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Data Flash Atmel Description File |
| 4 | * Author : Hamid Ikdoumi (Atmel) |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 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. |
| 13 | * |
| 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. |
| 18 | * |
| 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, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | /* File Name : dataflash.h */ |
| 26 | /* Object : Data Flash Atmel Description File */ |
| 27 | /* Translator : */ |
| 28 | /* */ |
| 29 | /* 1.0 03/04/01 HI : Creation */ |
| 30 | /* 1.2 20/10/02 FB : Adapatation Service and Lib v3 */ |
| 31 | /*----------------------------------------------------------------------*/ |
| 32 | |
| 33 | #ifndef _DataFlash_h |
| 34 | #define _DataFlash_h |
| 35 | |
| 36 | |
| 37 | #include <asm/arch/hardware.h> |
| 38 | #include "config.h" |
| 39 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 40 | /*number of protected area*/ |
Stelian Pop | 5604e21 | 2008-03-26 21:52:36 +0100 | [diff] [blame^] | 41 | #define NB_DATAFLASH_AREA 5 |
Peter Pearse | d4fc601 | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 42 | |
| 43 | #ifdef CFG_NO_FLASH |
| 44 | |
| 45 | /*----------------------------------------------------------------------- |
| 46 | * return codes from flash_write(): |
| 47 | */ |
| 48 | # define ERR_OK 0 |
| 49 | # define ERR_TIMOUT 1 |
| 50 | # define ERR_NOT_ERASED 2 |
| 51 | # define ERR_PROTECTED 4 |
| 52 | # define ERR_INVAL 8 |
| 53 | # define ERR_ALIGN 16 |
| 54 | # define ERR_UNKNOWN_FLASH_VENDOR 32 |
| 55 | # define ERR_UNKNOWN_FLASH_TYPE 64 |
| 56 | # define ERR_PROG_ERROR 128 |
| 57 | |
| 58 | /*----------------------------------------------------------------------- |
| 59 | * Protection Flags for flash_protect(): |
| 60 | */ |
| 61 | # define FLAG_PROTECT_SET 0x01 |
| 62 | # define FLAG_PROTECT_CLEAR 0x02 |
| 63 | # define FLAG_PROTECT_INVALID 0x03 |
| 64 | |
| 65 | /*----------------------------------------------------------------------- |
| 66 | * Set Environment according to label: |
| 67 | */ |
| 68 | # define FLAG_SETENV 0x80 |
| 69 | #endif /* CFG_NO_FLASH */ |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 70 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 71 | /*define the area structure*/ |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 72 | typedef struct { |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 73 | unsigned long start; |
| 74 | unsigned long end; |
| 75 | unsigned char protected; |
Peter Pearse | d4fc601 | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 76 | unsigned char setenv; |
Wolfgang Denk | f01dbb5 | 2007-08-14 18:42:36 +0200 | [diff] [blame] | 77 | unsigned char label[20]; |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 78 | } dataflash_protect_t; |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 79 | |
| 80 | typedef unsigned int AT91S_DataFlashStatus; |
| 81 | |
| 82 | /*----------------------------------------------------------------------*/ |
| 83 | /* DataFlash Structures */ |
| 84 | /*----------------------------------------------------------------------*/ |
| 85 | |
| 86 | /*---------------------------------------------*/ |
| 87 | /* DataFlash Descriptor Structure Definition */ |
| 88 | /*---------------------------------------------*/ |
| 89 | typedef struct _AT91S_DataflashDesc { |
| 90 | unsigned char *tx_cmd_pt; |
| 91 | unsigned int tx_cmd_size; |
| 92 | unsigned char *rx_cmd_pt; |
| 93 | unsigned int rx_cmd_size; |
| 94 | unsigned char *tx_data_pt; |
| 95 | unsigned int tx_data_size; |
| 96 | unsigned char *rx_data_pt; |
| 97 | unsigned int rx_data_size; |
| 98 | volatile unsigned char state; |
| 99 | volatile unsigned char DataFlash_state; |
| 100 | unsigned char command[8]; |
| 101 | } AT91S_DataflashDesc, *AT91PS_DataflashDesc; |
| 102 | |
| 103 | /*---------------------------------------------*/ |
| 104 | /* DataFlash device definition structure */ |
| 105 | /*---------------------------------------------*/ |
| 106 | typedef struct _AT91S_Dataflash { |
| 107 | int pages_number; /* dataflash page number */ |
| 108 | int pages_size; /* dataflash page size */ |
| 109 | int page_offset; /* page offset in command */ |
| 110 | int byte_mask; /* byte mask in command */ |
| 111 | int cs; |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 112 | dataflash_protect_t area_list[NB_DATAFLASH_AREA]; /* area protection status */ |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 113 | } AT91S_DataflashFeatures, *AT91PS_DataflashFeatures; |
| 114 | |
| 115 | /*---------------------------------------------*/ |
| 116 | /* DataFlash Structure Definition */ |
| 117 | /*---------------------------------------------*/ |
| 118 | typedef struct _AT91S_DataFlash { |
| 119 | AT91PS_DataflashDesc pDataFlashDesc; /* dataflash descriptor */ |
| 120 | AT91PS_DataflashFeatures pDevice; /* Pointer on a dataflash features array */ |
| 121 | } AT91S_DataFlash, *AT91PS_DataFlash; |
| 122 | |
| 123 | |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 124 | typedef struct _AT91S_DATAFLASH_INFO { |
| 125 | |
| 126 | AT91S_DataflashDesc Desc; |
| 127 | AT91S_DataflashFeatures Device; /* Pointer on a dataflash features array */ |
| 128 | unsigned long logical_address; |
Peter Pearse | d4fc601 | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 129 | unsigned long end_address; |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 130 | unsigned int id; /* device id */ |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 131 | } AT91S_DATAFLASH_INFO, *AT91PS_DATAFLASH_INFO; |
| 132 | |
| 133 | |
| 134 | /*-------------------------------------------------------------------------------------------------*/ |
| 135 | |
| 136 | #define AT45DB161 0x2c |
| 137 | #define AT45DB321 0x34 |
| 138 | #define AT45DB642 0x3c |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 139 | #define AT45DB128 0x10 |
Peter Pearse | d4fc601 | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 140 | #define PAGES_PER_BLOCK 8 |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 141 | |
| 142 | #define AT91C_DATAFLASH_TIMEOUT 10000 /* For AT91F_DataFlashWaitReady */ |
| 143 | |
| 144 | /* DataFlash return value */ |
| 145 | #define DATAFLASH_BUSY 0x00 |
| 146 | #define DATAFLASH_OK 0x01 |
| 147 | #define DATAFLASH_ERROR 0x02 |
| 148 | #define DATAFLASH_MEMORY_OVERFLOW 0x03 |
| 149 | #define DATAFLASH_BAD_COMMAND 0x04 |
| 150 | #define DATAFLASH_BAD_ADDRESS 0x05 |
| 151 | |
| 152 | |
| 153 | /* Driver State */ |
| 154 | #define IDLE 0x0 |
| 155 | #define BUSY 0x1 |
| 156 | #define ERROR 0x2 |
| 157 | |
| 158 | /* DataFlash Driver State */ |
| 159 | #define GET_STATUS 0x0F |
| 160 | |
| 161 | /*-------------------------------------------------------------------------------------------------*/ |
| 162 | /* Command Definition */ |
| 163 | /*-------------------------------------------------------------------------------------------------*/ |
| 164 | |
| 165 | /* READ COMMANDS */ |
| 166 | #define DB_CONTINUOUS_ARRAY_READ 0xE8 /* Continuous array read */ |
| 167 | #define DB_BURST_ARRAY_READ 0xE8 /* Burst array read */ |
| 168 | #define DB_PAGE_READ 0xD2 /* Main memory page read */ |
| 169 | #define DB_BUF1_READ 0xD4 /* Buffer 1 read */ |
| 170 | #define DB_BUF2_READ 0xD6 /* Buffer 2 read */ |
| 171 | #define DB_STATUS 0xD7 /* Status Register */ |
| 172 | |
| 173 | /* PROGRAM and ERASE COMMANDS */ |
| 174 | #define DB_BUF1_WRITE 0x84 /* Buffer 1 write */ |
| 175 | #define DB_BUF2_WRITE 0x87 /* Buffer 2 write */ |
| 176 | #define DB_BUF1_PAGE_ERASE_PGM 0x83 /* Buffer 1 to main memory page program with built-In erase */ |
| 177 | #define DB_BUF1_PAGE_ERASE_FASTPGM 0x93 /* Buffer 1 to main memory page program with built-In erase, Fast program */ |
| 178 | #define DB_BUF2_PAGE_ERASE_PGM 0x86 /* Buffer 2 to main memory page program with built-In erase */ |
| 179 | #define DB_BUF2_PAGE_ERASE_FASTPGM 0x96 /* Buffer 1 to main memory page program with built-In erase, Fast program */ |
| 180 | #define DB_BUF1_PAGE_PGM 0x88 /* Buffer 1 to main memory page program without built-In erase */ |
| 181 | #define DB_BUF1_PAGE_FASTPGM 0x98 /* Buffer 1 to main memory page program without built-In erase, Fast program */ |
| 182 | #define DB_BUF2_PAGE_PGM 0x89 /* Buffer 2 to main memory page program without built-In erase */ |
| 183 | #define DB_BUF2_PAGE_FASTPGM 0x99 /* Buffer 1 to main memory page program without built-In erase, Fast program */ |
| 184 | #define DB_PAGE_ERASE 0x81 /* Page Erase */ |
| 185 | #define DB_BLOCK_ERASE 0x50 /* Block Erase */ |
| 186 | #define DB_PAGE_PGM_BUF1 0x82 /* Main memory page through buffer 1 */ |
| 187 | #define DB_PAGE_FASTPGM_BUF1 0x92 /* Main memory page through buffer 1, Fast program */ |
| 188 | #define DB_PAGE_PGM_BUF2 0x85 /* Main memory page through buffer 2 */ |
| 189 | #define DB_PAGE_FastPGM_BUF2 0x95 /* Main memory page through buffer 2, Fast program */ |
| 190 | |
| 191 | /* ADDITIONAL COMMANDS */ |
| 192 | #define DB_PAGE_2_BUF1_TRF 0x53 /* Main memory page to buffer 1 transfert */ |
| 193 | #define DB_PAGE_2_BUF2_TRF 0x55 /* Main memory page to buffer 2 transfert */ |
| 194 | #define DB_PAGE_2_BUF1_CMP 0x60 /* Main memory page to buffer 1 compare */ |
| 195 | #define DB_PAGE_2_BUF2_CMP 0x61 /* Main memory page to buffer 2 compare */ |
| 196 | #define DB_AUTO_PAGE_PGM_BUF1 0x58 /* Auto page rewrite throught buffer 1 */ |
| 197 | #define DB_AUTO_PAGE_PGM_BUF2 0x59 /* Auto page rewrite throught buffer 2 */ |
| 198 | |
| 199 | /*-------------------------------------------------------------------------------------------------*/ |
| 200 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 201 | extern int size_dataflash (AT91PS_DataFlash pdataFlash, unsigned long addr, unsigned long size); |
| 202 | extern int prot_dataflash (AT91PS_DataFlash pdataFlash, unsigned long addr); |
Peter Pearse | d4fc601 | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 203 | extern int addr2ram(ulong addr); |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 204 | extern int dataflash_real_protect (int flag, unsigned long start_addr, unsigned long end_addr); |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 205 | extern int addr_dataflash (unsigned long addr); |
| 206 | extern int read_dataflash (unsigned long addr, unsigned long size, char *result); |
| 207 | extern int write_dataflash (unsigned long addr, unsigned long dest, unsigned long size); |
| 208 | extern void dataflash_print_info (void); |
| 209 | extern void dataflash_perror (int err); |
| 210 | |
Peter Pearse | d4fc601 | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 211 | #ifdef CONFIG_NEW_DF_PARTITION |
| 212 | extern int AT91F_DataflashSetEnv (void); #endif |
| 213 | #endif |
| 214 | |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 215 | #endif |