1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#define CHIP_ADDR_REG_MAN 0x000000
37#define CHIP_ADDR_REG_DEV 0x000001
38#define CHIP_ADDR_REG_CFGM 0x000003
39#define CHIP_ADDR_REG_CFG(b) (((b)<<16)|2)
40
41
42#define CHIP_CMD_RST 0xFF
43#define CHIP_CMD_RD_ID 0x90
44#define CHIP_CMD_RD_QUERY 0x98
45#define CHIP_CMD_RD_STAT 0x70
46#define CHIP_CMD_CLR_STAT 0x50
47#define CHIP_CMD_WR_BUF 0xE8
48#define CHIP_CMD_PROG 0x40
49#define CHIP_CMD_ERASE1 0x20
50#define CHIP_CMD_ERASE2 0xD0
51#define CHIP_CMD_ERASE_SUSP 0xB0
52#define CHIP_CMD_LOCK 0x60
53#define CHIP_CMD_SET_LOCK_BLK 0x01
54#define CHIP_CMD_SET_LOCK_MSTR 0xF1
55#define CHIP_CMD_CLR_LOCK_BLK 0xD0
56
57
58#define CHIP_STAT_DPS 0x02
59#define CHIP_STAT_VPPS 0x08
60#define CHIP_STAT_PSLBS 0x10
61#define CHIP_STAT_ECLBS 0x20
62#define CHIP_STAT_ESS 0x40
63#define CHIP_STAT_RDY 0x80
64
65#define CHIP_STAT_ERR (CHIP_STAT_VPPS | CHIP_STAT_DPS | \
66 CHIP_STAT_ECLBS | CHIP_STAT_PSLBS)
67
68
69#define CHIP_RD_ID_LOCK 0x01
70#define CHIP_RD_ID_MAN 0x89
71#define CHIP_RD_ID_DEV CONFIG_SYS_FLASH_ID
72
73
74#define CHIP_WIDTH 2
75#define CHIP_WSHIFT 1
76#define CHIP_NBLOCKS 128
77#define CHIP_BLKSZ (128 * 1024)
78#define CHIP_SIZE (CHIP_BLKSZ * CHIP_NBLOCKS)
79
80
81
82
83
84
85
86
87typedef unsigned short bank_word_t;
88typedef volatile bank_word_t *bank_addr_t;
89typedef unsigned long bank_size_t;
90
91#define BANK_CHIP_WIDTH 1
92#define BANK_CHIP_WSHIFT 0
93
94#define BANK_WIDTH (CHIP_WIDTH * BANK_CHIP_WIDTH)
95#define BANK_WSHIFT (CHIP_WSHIFT + BANK_CHIP_WSHIFT)
96#define BANK_NBLOCKS CHIP_NBLOCKS
97#define BANK_BLKSZ (CHIP_BLKSZ * BANK_CHIP_WIDTH)
98#define BANK_SIZE (CHIP_SIZE * BANK_CHIP_WIDTH)
99
100#define MAX_BANKS 1
101
102
103#define BANK_ADDR_WORD_ALIGN(a) ((bank_addr_t)((bank_size_t)(a) \
104 & ~(BANK_WIDTH - 1)))
105#define BANK_SIZE_WORD_ALIGN(s) ((bank_size_t)BANK_ADDR_WORD_ALIGN( \
106 (bank_size_t)(s) + (BANK_WIDTH - 1)))
107
108
109#define BANK_ADDR_BLK_ALIGN(a) ((bank_addr_t)((bank_size_t)(a) \
110 & ~(BANK_BLKSZ - 1)))
111#define BANK_SIZE_BLK_ALIGN(s) ((bank_size_t)BANK_ADDR_BLK_ALIGN( \
112 (bank_size_t)(s) + (BANK_BLKSZ - 1)))
113
114
115#define BANK_ADDR_BANK_ALIGN(a) ((bank_addr_t)((bank_size_t)(a) \
116 & ~(BANK_SIZE - 1)))
117#define BANK_SIZE_BANK_ALIGN(s) ((bank_size_t)BANK_ADDR_BANK_ALIGN( \
118 (bank_size_t)(s) + (BANK_SIZE - 1)))
119
120
121#define BANK_ADDR_OFFSET(a, o) (bank_addr_t)((bank_size_t)(a) + \
122 (bank_size_t)(o))
123
124
125#define BANK_ADDR_BASE(a, b) BANK_ADDR_OFFSET(BANK_ADDR_BANK_ALIGN(a), \
126 (bank_size_t)(b) * BANK_SIZE)
127
128
129#define BANK_ADDR_NEXT_WORD(a) BANK_ADDR_OFFSET(BANK_ADDR_WORD_ALIGN(a), \
130 BANK_WIDTH)
131#define BANK_ADDR_NEXT_BLK(a) BANK_ADDR_OFFSET(BANK_ADDR_BLK_ALIGN(a), \
132 BANK_BLKSZ)
133#define BANK_ADDR_NEXT_BANK(a) BANK_ADDR_OFFSET(BANK_ADDR_BANK_ALIGN(a), \
134 BANK_SIZE)
135
136
137#define BANK_ADDR_REG(a, r) BANK_ADDR_OFFSET(BANK_ADDR_BANK_ALIGN(a), \
138 ((bank_size_t)(r) << BANK_WSHIFT))
139
140
141
142#define BANK_ADDR_REG_MAN(a) BANK_ADDR_REG((a), CHIP_ADDR_REG_MAN)
143#define BANK_ADDR_REG_DEV(a) BANK_ADDR_REG((a), CHIP_ADDR_REG_DEV)
144#define BANK_ADDR_REG_CFGM(a) BANK_ADDR_REG((a), CHIP_ADDR_REG_CFGM)
145#define BANK_ADDR_REG_CFG(b,a) BANK_ADDR_REG((a), CHIP_ADDR_REG_CFG(b))
146
147
148
149
150
151
152
153
154
155#define BANK_FILL_WORD(o) ((bank_word_t)(o))
156
157
158
159
160#define BANK_CMD_RST BANK_FILL_WORD(CHIP_CMD_RST)
161#define BANK_CMD_RD_ID BANK_FILL_WORD(CHIP_CMD_RD_ID)
162#define BANK_CMD_RD_STAT BANK_FILL_WORD(CHIP_CMD_RD_STAT)
163#define BANK_CMD_CLR_STAT BANK_FILL_WORD(CHIP_CMD_CLR_STAT)
164#define BANK_CMD_ERASE1 BANK_FILL_WORD(CHIP_CMD_ERASE1)
165#define BANK_CMD_ERASE2 BANK_FILL_WORD(CHIP_CMD_ERASE2)
166#define BANK_CMD_PROG BANK_FILL_WORD(CHIP_CMD_PROG)
167#define BANK_CMD_LOCK BANK_FILL_WORD(CHIP_CMD_LOCK)
168#define BANK_CMD_SET_LOCK_BLK BANK_FILL_WORD(CHIP_CMD_SET_LOCK_BLK)
169#define BANK_CMD_SET_LOCK_MSTR BANK_FILL_WORD(CHIP_CMD_SET_LOCK_MSTR)
170#define BANK_CMD_CLR_LOCK_BLK BANK_FILL_WORD(CHIP_CMD_CLR_LOCK_BLK)
171
172
173#define BANK_STAT_DPS BANK_FILL_WORD(CHIP_STAT_DPS)
174#define BANK_STAT_PSS BANK_FILL_WORD(CHIP_STAT_PSS)
175#define BANK_STAT_VPPS BANK_FILL_WORD(CHIP_STAT_VPPS)
176#define BANK_STAT_PSLBS BANK_FILL_WORD(CHIP_STAT_PSLBS)
177#define BANK_STAT_ECLBS BANK_FILL_WORD(CHIP_STAT_ECLBS)
178#define BANK_STAT_ESS BANK_FILL_WORD(CHIP_STAT_ESS)
179#define BANK_STAT_RDY BANK_FILL_WORD(CHIP_STAT_RDY)
180
181#define BANK_STAT_ERR BANK_FILL_WORD(CHIP_STAT_ERR)
182
183
184#define BANK_RD_ID_LOCK BANK_FILL_WORD(CHIP_RD_ID_LOCK)
185#define BANK_RD_ID_MAN BANK_FILL_WORD(CHIP_RD_ID_MAN)
186#define BANK_RD_ID_DEV BANK_FILL_WORD(CHIP_RD_ID_DEV)
187