blob: 94f86b3a306c21ea5fd79b2e63035f0e7ffc1d14 [file] [log] [blame]
wdenk381669a2003-06-16 23:50:08 +00001/*
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
wdenk381669a2003-06-16 23:50:08 +000037#include "config.h"
38
wdenk86765902003-12-06 23:55:10 +000039/*number of protected area*/
Stelian Pop03c684d2008-03-26 21:52:36 +010040#define NB_DATAFLASH_AREA 5
Peter Pearsede5b02c2007-08-14 10:10:52 +010041
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020042#ifdef CONFIG_SYS_NO_FLASH
Peter Pearsede5b02c2007-08-14 10:10:52 +010043
44/*-----------------------------------------------------------------------
45 * return codes from flash_write():
46 */
47# define ERR_OK 0
48# define ERR_TIMOUT 1
49# define ERR_NOT_ERASED 2
50# define ERR_PROTECTED 4
51# define ERR_INVAL 8
52# define ERR_ALIGN 16
53# define ERR_UNKNOWN_FLASH_VENDOR 32
54# define ERR_UNKNOWN_FLASH_TYPE 64
55# define ERR_PROG_ERROR 128
56
57/*-----------------------------------------------------------------------
58 * Protection Flags for flash_protect():
59 */
60# define FLAG_PROTECT_SET 0x01
61# define FLAG_PROTECT_CLEAR 0x02
62# define FLAG_PROTECT_INVALID 0x03
63
64/*-----------------------------------------------------------------------
65 * Set Environment according to label:
66 */
67# define FLAG_SETENV 0x80
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020068#endif /* CONFIG_SYS_NO_FLASH */
wdenk381669a2003-06-16 23:50:08 +000069
wdenk86765902003-12-06 23:55:10 +000070/*define the area structure*/
wdenk381669a2003-06-16 23:50:08 +000071typedef struct {
wdenk86765902003-12-06 23:55:10 +000072 unsigned long start;
73 unsigned long end;
74 unsigned char protected;
Peter Pearsede5b02c2007-08-14 10:10:52 +010075 unsigned char setenv;
Wolfgang Denk0611c492007-08-14 18:42:36 +020076 unsigned char label[20];
wdenk86765902003-12-06 23:55:10 +000077} dataflash_protect_t;
wdenk381669a2003-06-16 23:50:08 +000078
79typedef unsigned int AT91S_DataFlashStatus;
80
81/*----------------------------------------------------------------------*/
82/* DataFlash Structures */
83/*----------------------------------------------------------------------*/
84
85/*---------------------------------------------*/
86/* DataFlash Descriptor Structure Definition */
87/*---------------------------------------------*/
88typedef struct _AT91S_DataflashDesc {
89 unsigned char *tx_cmd_pt;
90 unsigned int tx_cmd_size;
91 unsigned char *rx_cmd_pt;
92 unsigned int rx_cmd_size;
93 unsigned char *tx_data_pt;
94 unsigned int tx_data_size;
95 unsigned char *rx_data_pt;
96 unsigned int rx_data_size;
97 volatile unsigned char state;
98 volatile unsigned char DataFlash_state;
99 unsigned char command[8];
100} AT91S_DataflashDesc, *AT91PS_DataflashDesc;
101
102/*---------------------------------------------*/
103/* DataFlash device definition structure */
104/*---------------------------------------------*/
105typedef struct _AT91S_Dataflash {
106 int pages_number; /* dataflash page number */
107 int pages_size; /* dataflash page size */
108 int page_offset; /* page offset in command */
109 int byte_mask; /* byte mask in command */
110 int cs;
wdenk86765902003-12-06 23:55:10 +0000111 dataflash_protect_t area_list[NB_DATAFLASH_AREA]; /* area protection status */
wdenk381669a2003-06-16 23:50:08 +0000112} AT91S_DataflashFeatures, *AT91PS_DataflashFeatures;
113
114/*---------------------------------------------*/
115/* DataFlash Structure Definition */
116/*---------------------------------------------*/
117typedef struct _AT91S_DataFlash {
118 AT91PS_DataflashDesc pDataFlashDesc; /* dataflash descriptor */
119 AT91PS_DataflashFeatures pDevice; /* Pointer on a dataflash features array */
120} AT91S_DataFlash, *AT91PS_DataFlash;
121
122
wdenk381669a2003-06-16 23:50:08 +0000123typedef struct _AT91S_DATAFLASH_INFO {
124
125 AT91S_DataflashDesc Desc;
126 AT91S_DataflashFeatures Device; /* Pointer on a dataflash features array */
127 unsigned long logical_address;
Peter Pearsede5b02c2007-08-14 10:10:52 +0100128 unsigned long end_address;
wdenk381669a2003-06-16 23:50:08 +0000129 unsigned int id; /* device id */
wdenk381669a2003-06-16 23:50:08 +0000130} AT91S_DATAFLASH_INFO, *AT91PS_DATAFLASH_INFO;
131
Ulf Samuelsson616fe572008-04-12 20:29:44 +0200132struct dataflash_addr {
133 unsigned long addr;
134 int cs;
135};
wdenk381669a2003-06-16 23:50:08 +0000136/*-------------------------------------------------------------------------------------------------*/
wdenk381669a2003-06-16 23:50:08 +0000137#define AT45DB161 0x2c
Sergey Lapin07b16c72008-06-05 11:06:29 +0400138#define AT45DB021 0x14
Sergey Lapinbb6c0a32008-08-09 01:39:09 +0400139#define AT45DB081 0x24
wdenk381669a2003-06-16 23:50:08 +0000140#define AT45DB321 0x34
141#define AT45DB642 0x3c
wdenk86765902003-12-06 23:55:10 +0000142#define AT45DB128 0x10
Peter Pearsede5b02c2007-08-14 10:10:52 +0100143#define PAGES_PER_BLOCK 8
wdenk381669a2003-06-16 23:50:08 +0000144
145#define AT91C_DATAFLASH_TIMEOUT 10000 /* For AT91F_DataFlashWaitReady */
146
147/* DataFlash return value */
148#define DATAFLASH_BUSY 0x00
149#define DATAFLASH_OK 0x01
150#define DATAFLASH_ERROR 0x02
151#define DATAFLASH_MEMORY_OVERFLOW 0x03
152#define DATAFLASH_BAD_COMMAND 0x04
153#define DATAFLASH_BAD_ADDRESS 0x05
154
155
156/* Driver State */
157#define IDLE 0x0
158#define BUSY 0x1
159#define ERROR 0x2
160
161/* DataFlash Driver State */
162#define GET_STATUS 0x0F
163
164/*-------------------------------------------------------------------------------------------------*/
165/* Command Definition */
166/*-------------------------------------------------------------------------------------------------*/
167
168/* READ COMMANDS */
169#define DB_CONTINUOUS_ARRAY_READ 0xE8 /* Continuous array read */
170#define DB_BURST_ARRAY_READ 0xE8 /* Burst array read */
171#define DB_PAGE_READ 0xD2 /* Main memory page read */
172#define DB_BUF1_READ 0xD4 /* Buffer 1 read */
173#define DB_BUF2_READ 0xD6 /* Buffer 2 read */
174#define DB_STATUS 0xD7 /* Status Register */
175
176/* PROGRAM and ERASE COMMANDS */
177#define DB_BUF1_WRITE 0x84 /* Buffer 1 write */
178#define DB_BUF2_WRITE 0x87 /* Buffer 2 write */
179#define DB_BUF1_PAGE_ERASE_PGM 0x83 /* Buffer 1 to main memory page program with built-In erase */
180#define DB_BUF1_PAGE_ERASE_FASTPGM 0x93 /* Buffer 1 to main memory page program with built-In erase, Fast program */
181#define DB_BUF2_PAGE_ERASE_PGM 0x86 /* Buffer 2 to main memory page program with built-In erase */
182#define DB_BUF2_PAGE_ERASE_FASTPGM 0x96 /* Buffer 1 to main memory page program with built-In erase, Fast program */
183#define DB_BUF1_PAGE_PGM 0x88 /* Buffer 1 to main memory page program without built-In erase */
184#define DB_BUF1_PAGE_FASTPGM 0x98 /* Buffer 1 to main memory page program without built-In erase, Fast program */
185#define DB_BUF2_PAGE_PGM 0x89 /* Buffer 2 to main memory page program without built-In erase */
186#define DB_BUF2_PAGE_FASTPGM 0x99 /* Buffer 1 to main memory page program without built-In erase, Fast program */
187#define DB_PAGE_ERASE 0x81 /* Page Erase */
188#define DB_BLOCK_ERASE 0x50 /* Block Erase */
189#define DB_PAGE_PGM_BUF1 0x82 /* Main memory page through buffer 1 */
190#define DB_PAGE_FASTPGM_BUF1 0x92 /* Main memory page through buffer 1, Fast program */
191#define DB_PAGE_PGM_BUF2 0x85 /* Main memory page through buffer 2 */
192#define DB_PAGE_FastPGM_BUF2 0x95 /* Main memory page through buffer 2, Fast program */
193
194/* ADDITIONAL COMMANDS */
195#define DB_PAGE_2_BUF1_TRF 0x53 /* Main memory page to buffer 1 transfert */
196#define DB_PAGE_2_BUF2_TRF 0x55 /* Main memory page to buffer 2 transfert */
197#define DB_PAGE_2_BUF1_CMP 0x60 /* Main memory page to buffer 1 compare */
198#define DB_PAGE_2_BUF2_CMP 0x61 /* Main memory page to buffer 2 compare */
199#define DB_AUTO_PAGE_PGM_BUF1 0x58 /* Auto page rewrite throught buffer 1 */
200#define DB_AUTO_PAGE_PGM_BUF2 0x59 /* Auto page rewrite throught buffer 2 */
201
202/*-------------------------------------------------------------------------------------------------*/
203
wdenk86765902003-12-06 23:55:10 +0000204extern int size_dataflash (AT91PS_DataFlash pdataFlash, unsigned long addr, unsigned long size);
205extern int prot_dataflash (AT91PS_DataFlash pdataFlash, unsigned long addr);
Peter Pearsede5b02c2007-08-14 10:10:52 +0100206extern int addr2ram(ulong addr);
wdenk86765902003-12-06 23:55:10 +0000207extern int dataflash_real_protect (int flag, unsigned long start_addr, unsigned long end_addr);
wdenk381669a2003-06-16 23:50:08 +0000208extern int addr_dataflash (unsigned long addr);
209extern int read_dataflash (unsigned long addr, unsigned long size, char *result);
Igor Grinberg104be712011-11-26 23:06:46 +0000210extern int write_dataflash(unsigned long addr_dest, unsigned long addr_src,
211 unsigned long size);
Igor Grinbergb90c1fc2011-11-07 01:14:02 +0000212extern int AT91F_DataflashInit(void);
213
wdenk381669a2003-06-16 23:50:08 +0000214extern void dataflash_print_info (void);
215extern void dataflash_perror (int err);
Ulf Samuelsson616fe572008-04-12 20:29:44 +0200216extern void AT91F_DataflashSetEnv (void);
Peter Pearsede5b02c2007-08-14 10:10:52 +0100217
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200218extern struct dataflash_addr cs[CONFIG_SYS_MAX_DATAFLASH_BANKS];
Ulf Samuelsson616fe572008-04-12 20:29:44 +0200219extern dataflash_protect_t area_list[NB_DATAFLASH_AREA];
220extern AT91S_DATAFLASH_INFO dataflash_info[];
wdenk381669a2003-06-16 23:50:08 +0000221#endif