sim: bfin: new port
[deliverable/binutils-gdb.git] / sim / bfin / dv-bfin_nfc.c
1 /* Blackfin NAND Flash Memory Controller (NFC) model
2
3 Copyright (C) 2010-2011 Free Software Foundation, Inc.
4 Contributed by Analog Devices, Inc.
5
6 This file is part of simulators.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 #include "config.h"
22
23 #include "sim-main.h"
24 #include "devices.h"
25 #include "dv-bfin_nfc.h"
26
27 /* XXX: This is merely a stub. */
28
29 struct bfin_nfc
30 {
31 /* This top portion matches common dv_bfin struct. */
32 bu32 base;
33 struct hw *dma_master;
34 bool acked;
35
36 struct hw_event *handler;
37 char saved_byte;
38 int saved_count;
39
40 /* Order after here is important -- matches hardware MMR layout. */
41 bu16 BFIN_MMR_16(ctl);
42 bu16 BFIN_MMR_16(stat);
43 bu16 BFIN_MMR_16(irqstat);
44 bu16 BFIN_MMR_16(irqmask);
45 bu16 BFIN_MMR_16(ecc0);
46 bu16 BFIN_MMR_16(ecc1);
47 bu16 BFIN_MMR_16(ecc2);
48 bu16 BFIN_MMR_16(ecc3);
49 bu16 BFIN_MMR_16(count);
50 bu16 BFIN_MMR_16(rst);
51 bu16 BFIN_MMR_16(pgctl);
52 bu16 BFIN_MMR_16(read);
53 bu32 _pad0[4];
54 bu16 BFIN_MMR_16(addr);
55 bu16 BFIN_MMR_16(cmd);
56 bu16 BFIN_MMR_16(data_wr);
57 bu16 BFIN_MMR_16(data_rd);
58 };
59 #define mmr_base() offsetof(struct bfin_nfc, ctl)
60 #define mmr_offset(mmr) (offsetof(struct bfin_nfc, mmr) - mmr_base())
61 #define mmr_idx(mmr) (mmr_offset (mmr) / 4)
62
63 static const char * const mmr_names[] = {
64 "NFC_CTL", "NFC_STAT", "NFC_IRQSTAT", "NFC_IRQMASK", "NFC_ECC0", "NFC_ECC1",
65 "NFC_ECC2", "NFC_ECC3", "NFC_COUNT", "NFC_RST", "NFC_PGCTL", "NFC_READ",
66 [mmr_idx (addr)] = "NFC_ADDR", "NFC_CMD", "NFC_DATA_WR", "NFC_DATA_RD",
67 };
68 #define mmr_name(off) (mmr_names[(off) / 4] ? : "<INV>")
69
70 static unsigned
71 bfin_nfc_io_write_buffer (struct hw *me, const void *source, int space,
72 address_word addr, unsigned nr_bytes)
73 {
74 struct bfin_nfc *nfc = hw_data (me);
75 bu32 mmr_off;
76 bu32 value;
77 bu16 *valuep;
78
79 value = dv_load_2 (source);
80 mmr_off = addr - nfc->base;
81 valuep = (void *)((unsigned long)nfc + mmr_base() + mmr_off);
82
83 HW_TRACE_WRITE ();
84
85 dv_bfin_mmr_require_16 (me, addr, nr_bytes, true);
86
87 switch (mmr_off)
88 {
89 case mmr_offset(ctl):
90 case mmr_offset(stat):
91 case mmr_offset(irqmask):
92 case mmr_offset(ecc0):
93 case mmr_offset(ecc1):
94 case mmr_offset(ecc2):
95 case mmr_offset(ecc3):
96 case mmr_offset(count):
97 case mmr_offset(rst):
98 case mmr_offset(pgctl):
99 case mmr_offset(read):
100 case mmr_offset(addr):
101 case mmr_offset(cmd):
102 case mmr_offset(data_wr):
103 *valuep = value;
104 break;
105 case mmr_offset(data_rd):
106 nfc->irqstat |= RD_RDY;
107 *valuep = value;
108 break;
109 case mmr_offset(irqstat):
110 dv_w1c_2 (valuep, value, 0);
111 break;
112 default:
113 dv_bfin_mmr_invalid (me, addr, nr_bytes, true);
114 break;
115 }
116
117 return nr_bytes;
118 }
119
120 static unsigned
121 bfin_nfc_io_read_buffer (struct hw *me, void *dest, int space,
122 address_word addr, unsigned nr_bytes)
123 {
124 struct bfin_nfc *nfc = hw_data (me);
125 bu32 mmr_off;
126 bu16 *valuep;
127
128 mmr_off = addr - nfc->base;
129 valuep = (void *)((unsigned long)nfc + mmr_base() + mmr_off);
130
131 HW_TRACE_READ ();
132
133 dv_bfin_mmr_require_16 (me, addr, nr_bytes, false);
134
135 switch (mmr_off)
136 {
137 case mmr_offset(ctl):
138 case mmr_offset(stat):
139 case mmr_offset(irqstat):
140 case mmr_offset(irqmask):
141 case mmr_offset(ecc0):
142 case mmr_offset(ecc1):
143 case mmr_offset(ecc2):
144 case mmr_offset(ecc3):
145 case mmr_offset(count):
146 case mmr_offset(rst):
147 case mmr_offset(read):
148 dv_store_2 (dest, *valuep);
149 break;
150 case mmr_offset(pgctl):
151 case mmr_offset(addr):
152 case mmr_offset(cmd):
153 case mmr_offset(data_wr):
154 case mmr_offset(data_rd):
155 /* These regs are write only. */
156 default:
157 dv_bfin_mmr_invalid (me, addr, nr_bytes, false);
158 break;
159 }
160
161 return nr_bytes;
162 }
163
164 static unsigned
165 bfin_nfc_dma_read_buffer (struct hw *me, void *dest, int space,
166 unsigned_word addr, unsigned nr_bytes)
167 {
168 HW_TRACE_DMA_READ ();
169 return 0;
170 }
171
172 static unsigned
173 bfin_nfc_dma_write_buffer (struct hw *me, const void *source,
174 int space, unsigned_word addr,
175 unsigned nr_bytes,
176 int violate_read_only_section)
177 {
178 HW_TRACE_DMA_WRITE ();
179 return nr_bytes;
180 }
181
182 static const struct hw_port_descriptor bfin_nfc_ports[] = {
183 { "stat", 0, 0, output_port, },
184 { NULL, 0, 0, 0, },
185 };
186
187 static void
188 attach_bfin_nfc_regs (struct hw *me, struct bfin_nfc *nfc)
189 {
190 address_word attach_address;
191 int attach_space;
192 unsigned attach_size;
193 reg_property_spec reg;
194
195 if (hw_find_property (me, "reg") == NULL)
196 hw_abort (me, "Missing \"reg\" property");
197
198 if (!hw_find_reg_array_property (me, "reg", 0, &reg))
199 hw_abort (me, "\"reg\" property must contain three addr/size entries");
200
201 hw_unit_address_to_attach_address (hw_parent (me),
202 &reg.address,
203 &attach_space, &attach_address, me);
204 hw_unit_size_to_attach_size (hw_parent (me), &reg.size, &attach_size, me);
205
206 if (attach_size != BFIN_MMR_NFC_SIZE)
207 hw_abort (me, "\"reg\" size must be %#x", BFIN_MMR_NFC_SIZE);
208
209 hw_attach_address (hw_parent (me),
210 0, attach_space, attach_address, attach_size, me);
211
212 nfc->base = attach_address;
213 }
214
215 static void
216 bfin_nfc_finish (struct hw *me)
217 {
218 struct bfin_nfc *nfc;
219
220 nfc = HW_ZALLOC (me, struct bfin_nfc);
221
222 set_hw_data (me, nfc);
223 set_hw_io_read_buffer (me, bfin_nfc_io_read_buffer);
224 set_hw_io_write_buffer (me, bfin_nfc_io_write_buffer);
225 set_hw_dma_read_buffer (me, bfin_nfc_dma_read_buffer);
226 set_hw_dma_write_buffer (me, bfin_nfc_dma_write_buffer);
227 set_hw_ports (me, bfin_nfc_ports);
228
229 attach_bfin_nfc_regs (me, nfc);
230
231 /* Initialize the NFC. */
232 nfc->ctl = 0x0200;
233 nfc->stat = 0x0011;
234 nfc->irqstat = 0x0004;
235 nfc->irqmask = 0x001F;
236 }
237
238 const struct hw_descriptor dv_bfin_nfc_descriptor[] = {
239 {"bfin_nfc", bfin_nfc_finish,},
240 {NULL, NULL},
241 };
This page took 0.036691 seconds and 4 git commands to generate.