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 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | /* File Name : dataflash.h */ |
| 10 | /* Object : Data Flash Atmel Description File */ |
| 11 | /* Translator : */ |
| 12 | /* */ |
| 13 | /* 1.0 03/04/01 HI : Creation */ |
| 14 | /* 1.2 20/10/02 FB : Adapatation Service and Lib v3 */ |
| 15 | /*----------------------------------------------------------------------*/ |
| 16 | |
| 17 | #ifndef _DataFlash_h |
| 18 | #define _DataFlash_h |
| 19 | |
| 20 | |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 21 | #include "config.h" |
| 22 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 23 | /*number of protected area*/ |
Stelian Pop | 5604e21 | 2008-03-26 21:52:36 +0100 | [diff] [blame] | 24 | #define NB_DATAFLASH_AREA 5 |
Peter Pearse | d4fc601 | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 25 | |
Masahiro Yamada | e856bdc | 2017-02-11 22:43:54 +0900 | [diff] [blame] | 26 | #ifndef CONFIG_MTD_NOR_FLASH |
Peter Pearse | d4fc601 | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 27 | |
| 28 | /*----------------------------------------------------------------------- |
| 29 | * return codes from flash_write(): |
| 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 | * Protection Flags for flash_protect(): |
| 43 | */ |
| 44 | # define FLAG_PROTECT_SET 0x01 |
| 45 | # define FLAG_PROTECT_CLEAR 0x02 |
| 46 | # define FLAG_PROTECT_INVALID 0x03 |
| 47 | |
| 48 | /*----------------------------------------------------------------------- |
| 49 | * Set Environment according to label: |
| 50 | */ |
| 51 | # define FLAG_SETENV 0x80 |
Masahiro Yamada | e856bdc | 2017-02-11 22:43:54 +0900 | [diff] [blame] | 52 | #endif /* CONFIG_MTD_NOR_FLASH */ |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 53 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 54 | /*define the area structure*/ |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 55 | typedef struct { |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 56 | unsigned long start; |
| 57 | unsigned long end; |
| 58 | unsigned char protected; |
Peter Pearse | d4fc601 | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 59 | unsigned char setenv; |
Wolfgang Denk | f01dbb5 | 2007-08-14 18:42:36 +0200 | [diff] [blame] | 60 | unsigned char label[20]; |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 61 | } dataflash_protect_t; |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 62 | |
| 63 | typedef unsigned int AT91S_DataFlashStatus; |
| 64 | |
| 65 | /*----------------------------------------------------------------------*/ |
| 66 | /* DataFlash Structures */ |
| 67 | /*----------------------------------------------------------------------*/ |
| 68 | |
| 69 | /*---------------------------------------------*/ |
| 70 | /* DataFlash Descriptor Structure Definition */ |
| 71 | /*---------------------------------------------*/ |
| 72 | typedef 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 | /* DataFlash device definition structure */ |
| 88 | /*---------------------------------------------*/ |
| 89 | typedef struct _AT91S_Dataflash { |
| 90 | int pages_number; /* dataflash page number */ |
| 91 | int pages_size; /* dataflash page size */ |
| 92 | int page_offset; /* page offset in command */ |
| 93 | int byte_mask; /* byte mask in command */ |
| 94 | int cs; |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 95 | dataflash_protect_t area_list[NB_DATAFLASH_AREA]; /* area protection status */ |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 96 | } AT91S_DataflashFeatures, *AT91PS_DataflashFeatures; |
| 97 | |
| 98 | /*---------------------------------------------*/ |
| 99 | /* DataFlash Structure Definition */ |
| 100 | /*---------------------------------------------*/ |
| 101 | typedef struct _AT91S_DataFlash { |
| 102 | AT91PS_DataflashDesc pDataFlashDesc; /* dataflash descriptor */ |
| 103 | AT91PS_DataflashFeatures pDevice; /* Pointer on a dataflash features array */ |
| 104 | } AT91S_DataFlash, *AT91PS_DataFlash; |
| 105 | |
| 106 | |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 107 | typedef struct _AT91S_DATAFLASH_INFO { |
| 108 | |
| 109 | AT91S_DataflashDesc Desc; |
| 110 | AT91S_DataflashFeatures Device; /* Pointer on a dataflash features array */ |
| 111 | unsigned long logical_address; |
Peter Pearse | d4fc601 | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 112 | unsigned long end_address; |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 113 | unsigned int id; /* device id */ |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 114 | } AT91S_DATAFLASH_INFO, *AT91PS_DATAFLASH_INFO; |
| 115 | |
Ulf Samuelsson | c3a60cb | 2008-04-12 20:29:44 +0200 | [diff] [blame] | 116 | struct dataflash_addr { |
| 117 | unsigned long addr; |
| 118 | int cs; |
| 119 | }; |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 120 | /*-------------------------------------------------------------------------------------------------*/ |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 121 | #define AT45DB161 0x2c |
Sergey Lapin | c6457e3 | 2008-06-05 11:06:29 +0400 | [diff] [blame] | 122 | #define AT45DB021 0x14 |
Sergey Lapin | f77d92a | 2008-08-09 01:39:09 +0400 | [diff] [blame] | 123 | #define AT45DB081 0x24 |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 124 | #define AT45DB321 0x34 |
| 125 | #define AT45DB642 0x3c |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 126 | #define AT45DB128 0x10 |
Peter Pearse | d4fc601 | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 127 | #define PAGES_PER_BLOCK 8 |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 128 | |
| 129 | #define AT91C_DATAFLASH_TIMEOUT 10000 /* For AT91F_DataFlashWaitReady */ |
| 130 | |
| 131 | /* DataFlash return value */ |
| 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 | /* Driver State */ |
| 141 | #define IDLE 0x0 |
| 142 | #define BUSY 0x1 |
| 143 | #define ERROR 0x2 |
| 144 | |
| 145 | /* DataFlash Driver State */ |
| 146 | #define GET_STATUS 0x0F |
| 147 | |
| 148 | /*-------------------------------------------------------------------------------------------------*/ |
| 149 | /* Command Definition */ |
| 150 | /*-------------------------------------------------------------------------------------------------*/ |
| 151 | |
| 152 | /* READ COMMANDS */ |
| 153 | #define DB_CONTINUOUS_ARRAY_READ 0xE8 /* Continuous array read */ |
| 154 | #define DB_BURST_ARRAY_READ 0xE8 /* Burst array read */ |
| 155 | #define DB_PAGE_READ 0xD2 /* Main memory page read */ |
| 156 | #define DB_BUF1_READ 0xD4 /* Buffer 1 read */ |
| 157 | #define DB_BUF2_READ 0xD6 /* Buffer 2 read */ |
| 158 | #define DB_STATUS 0xD7 /* Status Register */ |
| 159 | |
| 160 | /* PROGRAM and ERASE COMMANDS */ |
| 161 | #define DB_BUF1_WRITE 0x84 /* Buffer 1 write */ |
| 162 | #define DB_BUF2_WRITE 0x87 /* Buffer 2 write */ |
| 163 | #define DB_BUF1_PAGE_ERASE_PGM 0x83 /* Buffer 1 to main memory page program with built-In erase */ |
| 164 | #define DB_BUF1_PAGE_ERASE_FASTPGM 0x93 /* Buffer 1 to main memory page program with built-In erase, Fast program */ |
| 165 | #define DB_BUF2_PAGE_ERASE_PGM 0x86 /* Buffer 2 to main memory page program with built-In erase */ |
| 166 | #define DB_BUF2_PAGE_ERASE_FASTPGM 0x96 /* Buffer 1 to main memory page program with built-In erase, Fast program */ |
| 167 | #define DB_BUF1_PAGE_PGM 0x88 /* Buffer 1 to main memory page program without built-In erase */ |
| 168 | #define DB_BUF1_PAGE_FASTPGM 0x98 /* Buffer 1 to main memory page program without built-In erase, Fast program */ |
| 169 | #define DB_BUF2_PAGE_PGM 0x89 /* Buffer 2 to main memory page program without built-In erase */ |
| 170 | #define DB_BUF2_PAGE_FASTPGM 0x99 /* Buffer 1 to main memory page program without built-In erase, Fast program */ |
| 171 | #define DB_PAGE_ERASE 0x81 /* Page Erase */ |
| 172 | #define DB_BLOCK_ERASE 0x50 /* Block Erase */ |
| 173 | #define DB_PAGE_PGM_BUF1 0x82 /* Main memory page through buffer 1 */ |
| 174 | #define DB_PAGE_FASTPGM_BUF1 0x92 /* Main memory page through buffer 1, Fast program */ |
| 175 | #define DB_PAGE_PGM_BUF2 0x85 /* Main memory page through buffer 2 */ |
| 176 | #define DB_PAGE_FastPGM_BUF2 0x95 /* Main memory page through buffer 2, Fast program */ |
| 177 | |
| 178 | /* ADDITIONAL COMMANDS */ |
| 179 | #define DB_PAGE_2_BUF1_TRF 0x53 /* Main memory page to buffer 1 transfert */ |
| 180 | #define DB_PAGE_2_BUF2_TRF 0x55 /* Main memory page to buffer 2 transfert */ |
| 181 | #define DB_PAGE_2_BUF1_CMP 0x60 /* Main memory page to buffer 1 compare */ |
| 182 | #define DB_PAGE_2_BUF2_CMP 0x61 /* Main memory page to buffer 2 compare */ |
| 183 | #define DB_AUTO_PAGE_PGM_BUF1 0x58 /* Auto page rewrite throught buffer 1 */ |
| 184 | #define DB_AUTO_PAGE_PGM_BUF2 0x59 /* Auto page rewrite throught buffer 2 */ |
| 185 | |
| 186 | /*-------------------------------------------------------------------------------------------------*/ |
| 187 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 188 | extern int size_dataflash (AT91PS_DataFlash pdataFlash, unsigned long addr, unsigned long size); |
| 189 | extern int prot_dataflash (AT91PS_DataFlash pdataFlash, unsigned long addr); |
Peter Pearse | d4fc601 | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 190 | extern int addr2ram(ulong addr); |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 191 | 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] | 192 | extern int addr_dataflash (unsigned long addr); |
| 193 | extern int read_dataflash (unsigned long addr, unsigned long size, char *result); |
Igor Grinberg | abdbd67 | 2011-11-26 23:06:46 +0000 | [diff] [blame] | 194 | extern int write_dataflash(unsigned long addr_dest, unsigned long addr_src, |
| 195 | unsigned long size); |
Igor Grinberg | 0901d9f | 2011-11-07 01:14:02 +0000 | [diff] [blame] | 196 | extern int AT91F_DataflashInit(void); |
| 197 | |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 198 | extern void dataflash_print_info (void); |
| 199 | extern void dataflash_perror (int err); |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame^] | 200 | extern void AT91F_Dataflashenv_set(void); |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 201 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 202 | extern struct dataflash_addr cs[CONFIG_SYS_MAX_DATAFLASH_BANKS]; |
Ulf Samuelsson | c3a60cb | 2008-04-12 20:29:44 +0200 | [diff] [blame] | 203 | extern dataflash_protect_t area_list[NB_DATAFLASH_AREA]; |
| 204 | extern AT91S_DATAFLASH_INFO dataflash_info[]; |
wdenk | 2abbe07 | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 205 | #endif |