dataflash.h 8.2 KB

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