dataflash.h 7.5 KB

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