]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/io/flash/v2_0/include/flash_dev.h
Initial revision
[karo-tx-redboot.git] / packages / io / flash / v2_0 / include / flash_dev.h
1 #ifndef CYGONCE_IO_FLASH_FLASH_DEV_H
2 #define CYGONCE_IO_FLASH_FLASH_DEV_H
3 //==========================================================================
4 //
5 //      flash_dev.h
6 //
7 //      Common flash device driver definitions
8 //
9 //==========================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14 //
15 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version.
18 //
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22 // for more details.
23 //
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 //
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
34 //
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
37 //
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 // at http://sources.redhat.com/ecos/ecos-license/
40 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND####
42 //==========================================================================
43 //#####DESCRIPTIONBEGIN####
44 //
45 // Author(s):    hmt
46 // Contributors: hmt, jskov, Jose Pascual <josepascual@almudi.com>
47 // Date:         2001-02-22
48 // Purpose:      Define common flash device driver definitions
49 // Description:  The flash_data_t type is used for accessing
50 //               devices at the correct width.
51 //               The FLASHWORD macro must be used to create constants
52 //               of suitable width.
53 //               The FLASH_P2V macro can be used to fix up non-linear
54 //               mappings of flash blocks (defaults to a linear 
55 //               implementation).
56 //              
57 //####DESCRIPTIONEND####
58 //
59 //==========================================================================
60
61 #ifdef _FLASH_PRIVATE_
62 #include <cyg/infra/cyg_type.h>
63
64 // ------------------------------------------------------------------------
65 //
66 // No mapping on this target - but these casts would be needed if some
67 // manipulation did occur.  An example of this might be:
68 // // First 4K page of flash at physical address zero is
69 // // virtually mapped at address 0xa0000000.
70 // #define FLASH_P2V(x) ((volatile flash_t *)(((unsigned)(x) < 0x1000) ?
71 //                            ((unsigned)(x) | 0xa0000000) :
72 //                            (unsigned)(x)))
73
74 #ifndef FLASH_P2V
75 #define FLASH_P2V( _a_ ) ((volatile flash_t *)((CYG_ADDRWORD)(_a_)))
76 #endif
77
78 // ------------------------------------------------------------------------
79 //
80 // This generic code is intended to deal with all shapes and orientations
81 // of Intel StrataFlash.  Trademarks &c belong to their respective owners.
82 //
83 // It therefore needs some trickery to define the constants and accessor
84 // types that we use to interact with the device or devices.
85 //
86 // The assumptions are that
87 //  o Parallel devices, we write to, with the "opcode" replicated per
88 //    device
89 //  o The "opcode" and status returns exist only in the low byte of the
90 //    device's interface regardless of its width.
91 //  o Hence opcodes and status are only one byte.
92 // An exception is the test for succesfully erased data.
93 //
94 // ------------------------------------------------------------------------
95
96 #if 8 == CYGNUM_FLASH_WIDTH
97
98 # if 1 == CYGNUM_FLASH_INTERLEAVE
99 #  define FLASHWORD( k ) ((flash_data_t)(k)) // To narrow a 16-bit constant
100 typedef cyg_uint8 flash_data_t;
101 # elif 2 == CYGNUM_FLASH_INTERLEAVE
102 // 2 devices to make 16-bit
103 #  define FLASHWORD( k ) ((k)+((k)<<8))
104 typedef cyg_uint16 flash_data_t;
105 # elif 4 == CYGNUM_FLASH_INTERLEAVE
106 // 4 devices to make 32-bit
107 #  define FLASHWORD( k ) ((k)+((k)<<8)+((k)<<16)+((k)<<24))
108 typedef cyg_uint32 flash_data_t;
109 # elif 8 == CYGNUM_FLASH_INTERLEAVE
110 // 8 devices to make 64-bit - intermediate requires explicit widening
111 #  define FLASHWORD32( k ) ((flash_data_t)((k)+((k)<<8)+((k)<<16)+((k)<<24)))
112 #  define FLASHWORD( k ) (FLASHWORD32( k ) + (FLASHWORD32( k ) << 32));
113 typedef cyg_uint64 flash_data_t;
114 # else
115 #  error How many 8-bit flash devices?
116 # endif
117
118 #elif 16 == CYGNUM_FLASH_WIDTH
119
120 # if 1 == CYGNUM_FLASH_INTERLEAVE
121 #  define FLASHWORD( k ) (k)
122 typedef cyg_uint16 flash_data_t;
123 # elif 2 == CYGNUM_FLASH_INTERLEAVE
124 // 2 devices to make 32-bit
125 #  define FLASHWORD( k ) ((k)+((k)<<16))
126 typedef cyg_uint32 flash_data_t;
127 # elif 4 == CYGNUM_FLASH_INTERLEAVE
128 // 4 devices to make 64-bit - intermediate requires explicit widening
129 #  define FLASHWORD32( k ) ((flash_data_t)((k)+((k)<<16)))
130 #  define FLASHWORD( k ) (FLASHWORD32( k ) + (FLASHWORD32( k ) << 32));
131 typedef cyg_uint64 flash_data_t;
132 # else
133 #  error How many 16-bit flash devices?
134 # endif
135
136 #elif 32 == CYGNUM_FLASH_WIDTH
137
138 # if 1 == CYGNUM_FLASH_INTERLEAVE
139 #  define FLASHWORD( k ) (k)
140 typedef cyg_uint32 flash_data_t;
141 # elif 2 == CYGNUM_FLASH_INTERLEAVE
142 // 2 devices to make 64-bit - intermediate requires explicit widening
143 #  define FLASHWORD32( k ) ((flash_data_t)(k))
144 #  define FLASHWORD( k ) (FLASHWORD32( k ) + (FLASHWORD32( k ) << 32));
145 typedef cyg_uint64 flash_data_t;
146 # else
147 #  error How many 32-bit flash devices?
148 # endif
149
150 #else
151 # error What flash width?
152 #endif
153
154 // Data (not) that we read back:
155 #if 0 == CYGNUM_FLASH_BLANK
156 # define FLASH_BlankValue ((flash_data_t)0)
157 #elif 1 == CYGNUM_FLASH_BLANK
158 # define FLASH_BlankValue ((flash_data_t)(-1ll))
159 #else
160 # error What blank value?
161 #endif
162
163 #endif // _FLASH_PRIVATE_
164
165 #endif // CYGONCE_IO_FLASH_FLASH_DEV_H
166 //----------------------------------------------------------------------------
167 // end of flash_dev.h