1 /* Blackfin NAND Flash Memory Controller (NFC) model
3 Copyright (C) 2010-2023 Free Software Foundation, Inc.
4 Contributed by Analog Devices, Inc.
6 This file is part of simulators.
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.
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.
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/>. */
21 /* This must come before any other includes. */
26 #include "dv-bfin_nfc.h"
28 /* XXX: This is merely a stub. */
32 /* This top portion matches common dv_bfin struct. */
34 struct hw
*dma_master
;
37 struct hw_event
*handler
;
41 /* Order after here is important -- matches hardware MMR layout. */
42 bu16
BFIN_MMR_16(ctl
);
43 bu16
BFIN_MMR_16(stat
);
44 bu16
BFIN_MMR_16(irqstat
);
45 bu16
BFIN_MMR_16(irqmask
);
46 bu16
BFIN_MMR_16(ecc0
);
47 bu16
BFIN_MMR_16(ecc1
);
48 bu16
BFIN_MMR_16(ecc2
);
49 bu16
BFIN_MMR_16(ecc3
);
50 bu16
BFIN_MMR_16(count
);
51 bu16
BFIN_MMR_16(rst
);
52 bu16
BFIN_MMR_16(pgctl
);
53 bu16
BFIN_MMR_16(read
);
55 bu16
BFIN_MMR_16(addr
);
56 bu16
BFIN_MMR_16(cmd
);
57 bu16
BFIN_MMR_16(data_wr
);
58 bu16
BFIN_MMR_16(data_rd
);
60 #define mmr_base() offsetof(struct bfin_nfc, ctl)
61 #define mmr_offset(mmr) (offsetof(struct bfin_nfc, mmr) - mmr_base())
62 #define mmr_idx(mmr) (mmr_offset (mmr) / 4)
64 static const char * const mmr_names
[] =
66 "NFC_CTL", "NFC_STAT", "NFC_IRQSTAT", "NFC_IRQMASK", "NFC_ECC0", "NFC_ECC1",
67 "NFC_ECC2", "NFC_ECC3", "NFC_COUNT", "NFC_RST", "NFC_PGCTL", "NFC_READ",
68 [mmr_idx (addr
)] = "NFC_ADDR", "NFC_CMD", "NFC_DATA_WR", "NFC_DATA_RD",
70 #define mmr_name(off) (mmr_names[(off) / 4] ? : "<INV>")
73 bfin_nfc_io_write_buffer (struct hw
*me
, const void *source
, int space
,
74 address_word addr
, unsigned nr_bytes
)
76 struct bfin_nfc
*nfc
= hw_data (me
);
81 /* Invalid access mode is higher priority than missing register. */
82 if (!dv_bfin_mmr_require_16 (me
, addr
, nr_bytes
, true))
85 value
= dv_load_2 (source
);
86 mmr_off
= addr
- nfc
->base
;
87 valuep
= (void *)((uintptr_t)nfc
+ mmr_base() + mmr_off
);
94 case mmr_offset(stat
):
95 case mmr_offset(irqmask
):
96 case mmr_offset(ecc0
):
97 case mmr_offset(ecc1
):
98 case mmr_offset(ecc2
):
99 case mmr_offset(ecc3
):
100 case mmr_offset(count
):
101 case mmr_offset(rst
):
102 case mmr_offset(pgctl
):
103 case mmr_offset(read
):
104 case mmr_offset(addr
):
105 case mmr_offset(cmd
):
106 case mmr_offset(data_wr
):
109 case mmr_offset(data_rd
):
110 nfc
->irqstat
|= RD_RDY
;
113 case mmr_offset(irqstat
):
114 dv_w1c_2 (valuep
, value
, -1);
117 dv_bfin_mmr_invalid (me
, addr
, nr_bytes
, true);
125 bfin_nfc_io_read_buffer (struct hw
*me
, void *dest
, int space
,
126 address_word addr
, unsigned nr_bytes
)
128 struct bfin_nfc
*nfc
= hw_data (me
);
132 /* Invalid access mode is higher priority than missing register. */
133 if (!dv_bfin_mmr_require_16 (me
, addr
, nr_bytes
, false))
136 mmr_off
= addr
- nfc
->base
;
137 valuep
= (void *)((uintptr_t)nfc
+ mmr_base() + mmr_off
);
143 case mmr_offset(ctl
):
144 case mmr_offset(stat
):
145 case mmr_offset(irqstat
):
146 case mmr_offset(irqmask
):
147 case mmr_offset(ecc0
):
148 case mmr_offset(ecc1
):
149 case mmr_offset(ecc2
):
150 case mmr_offset(ecc3
):
151 case mmr_offset(count
):
152 case mmr_offset(rst
):
153 case mmr_offset(read
):
154 dv_store_2 (dest
, *valuep
);
156 case mmr_offset(pgctl
):
157 case mmr_offset(addr
):
158 case mmr_offset(cmd
):
159 case mmr_offset(data_wr
):
160 case mmr_offset(data_rd
):
161 /* These regs are write only. */
163 dv_bfin_mmr_invalid (me
, addr
, nr_bytes
, false);
171 bfin_nfc_dma_read_buffer (struct hw
*me
, void *dest
, int space
,
172 unsigned_word addr
, unsigned nr_bytes
)
174 HW_TRACE_DMA_READ ();
179 bfin_nfc_dma_write_buffer (struct hw
*me
, const void *source
,
180 int space
, unsigned_word addr
,
182 int violate_read_only_section
)
184 HW_TRACE_DMA_WRITE ();
188 static const struct hw_port_descriptor bfin_nfc_ports
[] =
190 { "stat", 0, 0, output_port
, },
195 attach_bfin_nfc_regs (struct hw
*me
, struct bfin_nfc
*nfc
)
197 address_word attach_address
;
199 unsigned attach_size
;
200 reg_property_spec reg
;
202 if (hw_find_property (me
, "reg") == NULL
)
203 hw_abort (me
, "Missing \"reg\" property");
205 if (!hw_find_reg_array_property (me
, "reg", 0, ®
))
206 hw_abort (me
, "\"reg\" property must contain three addr/size entries");
208 hw_unit_address_to_attach_address (hw_parent (me
),
210 &attach_space
, &attach_address
, me
);
211 hw_unit_size_to_attach_size (hw_parent (me
), ®
.size
, &attach_size
, me
);
213 if (attach_size
!= BFIN_MMR_NFC_SIZE
)
214 hw_abort (me
, "\"reg\" size must be %#x", BFIN_MMR_NFC_SIZE
);
216 hw_attach_address (hw_parent (me
),
217 0, attach_space
, attach_address
, attach_size
, me
);
219 nfc
->base
= attach_address
;
223 bfin_nfc_finish (struct hw
*me
)
225 struct bfin_nfc
*nfc
;
227 nfc
= HW_ZALLOC (me
, struct bfin_nfc
);
229 set_hw_data (me
, nfc
);
230 set_hw_io_read_buffer (me
, bfin_nfc_io_read_buffer
);
231 set_hw_io_write_buffer (me
, bfin_nfc_io_write_buffer
);
232 set_hw_dma_read_buffer (me
, bfin_nfc_dma_read_buffer
);
233 set_hw_dma_write_buffer (me
, bfin_nfc_dma_write_buffer
);
234 set_hw_ports (me
, bfin_nfc_ports
);
236 attach_bfin_nfc_regs (me
, nfc
);
238 /* Initialize the NFC. */
241 nfc
->irqstat
= 0x0004;
242 nfc
->irqmask
= 0x001F;
245 const struct hw_descriptor dv_bfin_nfc_descriptor
[] =
247 {"bfin_nfc", bfin_nfc_finish
,},