blob: 650454e7ee594ef7f30565178e3a013b09d3583e [file] [log] [blame]
wdenk2abbe072003-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
37#include <asm/arch/hardware.h>
38#include "config.h"
39
wdenk5779d8d2003-12-06 23:55:10 +000040/*number of protected area*/
41#define NB_DATAFLASH_AREA 4
wdenk2abbe072003-06-16 23:50:08 +000042
wdenk5779d8d2003-12-06 23:55:10 +000043/*define the area structure*/
wdenk2abbe072003-06-16 23:50:08 +000044typedef struct {
wdenk5779d8d2003-12-06 23:55:10 +000045 unsigned long start;
46 unsigned long end;
47 unsigned char protected;
48} dataflash_protect_t;
wdenk2abbe072003-06-16 23:50:08 +000049
50typedef unsigned int AT91S_DataFlashStatus;
51
52/*----------------------------------------------------------------------*/
53/* DataFlash Structures */
54/*----------------------------------------------------------------------*/
55
56/*---------------------------------------------*/
57/* DataFlash Descriptor Structure Definition */
58/*---------------------------------------------*/
59typedef 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/*---------------------------------------------*/
74/* DataFlash device definition structure */
75/*---------------------------------------------*/
76typedef struct _AT91S_Dataflash {
77 int pages_number; /* dataflash page number */
78 int pages_size; /* dataflash page size */
79 int page_offset; /* page offset in command */
80 int byte_mask; /* byte mask in command */
81 int cs;
wdenk5779d8d2003-12-06 23:55:10 +000082 dataflash_protect_t area_list[NB_DATAFLASH_AREA]; /* area protection status */
wdenk2abbe072003-06-16 23:50:08 +000083} AT91S_DataflashFeatures, *AT91PS_DataflashFeatures;
84
85/*---------------------------------------------*/
86/* DataFlash Structure Definition */
87/*---------------------------------------------*/
88typedef struct _AT91S_DataFlash {
89 AT91PS_DataflashDesc pDataFlashDesc; /* dataflash descriptor */
90 AT91PS_DataflashFeatures pDevice; /* Pointer on a dataflash features array */
91} AT91S_DataFlash, *AT91PS_DataFlash;
92
93
wdenk2abbe072003-06-16 23:50:08 +000094typedef struct _AT91S_DATAFLASH_INFO {
95
96 AT91S_DataflashDesc Desc;
97 AT91S_DataflashFeatures Device; /* Pointer on a dataflash features array */
98 unsigned long logical_address;
99 unsigned int id; /* device id */
wdenk2abbe072003-06-16 23:50:08 +0000100} AT91S_DATAFLASH_INFO, *AT91PS_DATAFLASH_INFO;
101
102
103/*-------------------------------------------------------------------------------------------------*/
104
105#define AT45DB161 0x2c
106#define AT45DB321 0x34
107#define AT45DB642 0x3c
wdenk5779d8d2003-12-06 23:55:10 +0000108#define AT45DB128 0x10
wdenk2abbe072003-06-16 23:50:08 +0000109
110#define AT91C_DATAFLASH_TIMEOUT 10000 /* For AT91F_DataFlashWaitReady */
111
112/* DataFlash return value */
113#define DATAFLASH_BUSY 0x00
114#define DATAFLASH_OK 0x01
115#define DATAFLASH_ERROR 0x02
116#define DATAFLASH_MEMORY_OVERFLOW 0x03
117#define DATAFLASH_BAD_COMMAND 0x04
118#define DATAFLASH_BAD_ADDRESS 0x05
119
120
121/* Driver State */
122#define IDLE 0x0
123#define BUSY 0x1
124#define ERROR 0x2
125
126/* DataFlash Driver State */
127#define GET_STATUS 0x0F
128
129/*-------------------------------------------------------------------------------------------------*/
130/* Command Definition */
131/*-------------------------------------------------------------------------------------------------*/
132
133/* READ COMMANDS */
134#define DB_CONTINUOUS_ARRAY_READ 0xE8 /* Continuous array read */
135#define DB_BURST_ARRAY_READ 0xE8 /* Burst array read */
136#define DB_PAGE_READ 0xD2 /* Main memory page read */
137#define DB_BUF1_READ 0xD4 /* Buffer 1 read */
138#define DB_BUF2_READ 0xD6 /* Buffer 2 read */
139#define DB_STATUS 0xD7 /* Status Register */
140
141/* PROGRAM and ERASE COMMANDS */
142#define DB_BUF1_WRITE 0x84 /* Buffer 1 write */
143#define DB_BUF2_WRITE 0x87 /* Buffer 2 write */
144#define DB_BUF1_PAGE_ERASE_PGM 0x83 /* Buffer 1 to main memory page program with built-In erase */
145#define DB_BUF1_PAGE_ERASE_FASTPGM 0x93 /* Buffer 1 to main memory page program with built-In erase, Fast program */
146#define DB_BUF2_PAGE_ERASE_PGM 0x86 /* Buffer 2 to main memory page program with built-In erase */
147#define DB_BUF2_PAGE_ERASE_FASTPGM 0x96 /* Buffer 1 to main memory page program with built-In erase, Fast program */
148#define DB_BUF1_PAGE_PGM 0x88 /* Buffer 1 to main memory page program without built-In erase */
149#define DB_BUF1_PAGE_FASTPGM 0x98 /* Buffer 1 to main memory page program without built-In erase, Fast program */
150#define DB_BUF2_PAGE_PGM 0x89 /* Buffer 2 to main memory page program without built-In erase */
151#define DB_BUF2_PAGE_FASTPGM 0x99 /* Buffer 1 to main memory page program without built-In erase, Fast program */
152#define DB_PAGE_ERASE 0x81 /* Page Erase */
153#define DB_BLOCK_ERASE 0x50 /* Block Erase */
154#define DB_PAGE_PGM_BUF1 0x82 /* Main memory page through buffer 1 */
155#define DB_PAGE_FASTPGM_BUF1 0x92 /* Main memory page through buffer 1, Fast program */
156#define DB_PAGE_PGM_BUF2 0x85 /* Main memory page through buffer 2 */
157#define DB_PAGE_FastPGM_BUF2 0x95 /* Main memory page through buffer 2, Fast program */
158
159/* ADDITIONAL COMMANDS */
160#define DB_PAGE_2_BUF1_TRF 0x53 /* Main memory page to buffer 1 transfert */
161#define DB_PAGE_2_BUF2_TRF 0x55 /* Main memory page to buffer 2 transfert */
162#define DB_PAGE_2_BUF1_CMP 0x60 /* Main memory page to buffer 1 compare */
163#define DB_PAGE_2_BUF2_CMP 0x61 /* Main memory page to buffer 2 compare */
164#define DB_AUTO_PAGE_PGM_BUF1 0x58 /* Auto page rewrite throught buffer 1 */
165#define DB_AUTO_PAGE_PGM_BUF2 0x59 /* Auto page rewrite throught buffer 2 */
166
167/*-------------------------------------------------------------------------------------------------*/
168
wdenk5779d8d2003-12-06 23:55:10 +0000169extern int size_dataflash (AT91PS_DataFlash pdataFlash, unsigned long addr, unsigned long size);
170extern int prot_dataflash (AT91PS_DataFlash pdataFlash, unsigned long addr);
171extern int dataflash_real_protect (int flag, unsigned long start_addr, unsigned long end_addr);
wdenk2abbe072003-06-16 23:50:08 +0000172extern int addr_dataflash (unsigned long addr);
173extern int read_dataflash (unsigned long addr, unsigned long size, char *result);
174extern int write_dataflash (unsigned long addr, unsigned long dest, unsigned long size);
175extern void dataflash_print_info (void);
176extern void dataflash_perror (int err);
177
178#endif