1 /* Blackfin External Bus Interface Unit (EBIU) DDR Controller (DDRC) 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_ebiu_ddrc.h"
30 bu32 base
, reg_size
, bank_size
;
32 /* Order after here is important -- matches hardware MMR layout. */
34 struct { bu32 ddrctl0
, ddrctl1
, ddrctl2
, ddrctl3
; };
38 bu16
BFIN_MMR_16(errmst
);
39 bu16
BFIN_MMR_16(rstctl
);
40 bu32 ddrbrc
[8], ddrbwc
[8];
41 bu32 ddracct
, ddrtact
, ddrarct
;
43 bu32 ddrmcen
, ddrmccl
;
45 #define mmr_base() offsetof(struct bfin_ebiu_ddrc, ddrctl0)
46 #define mmr_offset(mmr) (offsetof(struct bfin_ebiu_ddrc, mmr) - mmr_base())
48 static const char * const mmr_names
[] =
50 "EBIU_DDRCTL0", "EBIU_DDRCTL1", "EBIU_DDRCTL2", "EBIU_DDRCTL3", "EBIU_DDRQUE",
51 "EBIU_ERRADD", "EBIU_ERRMST", "EBIU_RSTCTL", "EBIU_DDRBRC0", "EBIU_DDRBRC1",
52 "EBIU_DDRBRC2", "EBIU_DDRBRC3", "EBIU_DDRBRC4", "EBIU_DDRBRC5",
53 "EBIU_DDRBRC6", "EBIU_DDRBRC7", "EBIU_DDRBWC0", "EBIU_DDRBWC1"
54 "EBIU_DDRBWC2", "EBIU_DDRBWC3", "EBIU_DDRBWC4", "EBIU_DDRBWC5",
55 "EBIU_DDRBWC6", "EBIU_DDRBWC7", "EBIU_DDRACCT", "EBIU_DDRTACT",
56 "EBIU_ARCT", "EBIU_DDRGC0", "EBIU_DDRGC1", "EBIU_DDRGC2", "EBIU_DDRGC3",
57 "EBIU_DDRMCEN", "EBIU_DDRMCCL",
59 #define mmr_name(off) mmr_names[(off) / 4]
62 bfin_ebiu_ddrc_io_write_buffer (struct hw
*me
, const void *source
,
63 int space
, address_word addr
, unsigned nr_bytes
)
65 struct bfin_ebiu_ddrc
*ddrc
= hw_data (me
);
72 /* Invalid access mode is higher priority than missing register. */
73 if (!dv_bfin_mmr_require_16_32 (me
, addr
, nr_bytes
, true))
77 value
= dv_load_4 (source
);
79 value
= dv_load_2 (source
);
81 mmr_off
= addr
- ddrc
->base
;
82 valuep
= (void *)((uintptr_t)ddrc
+ mmr_base() + mmr_off
);
90 case mmr_offset(errmst
):
91 case mmr_offset(rstctl
):
92 if (!dv_bfin_mmr_require_16 (me
, addr
, nr_bytes
, true))
97 if (!dv_bfin_mmr_require_32 (me
, addr
, nr_bytes
, true))
107 bfin_ebiu_ddrc_io_read_buffer (struct hw
*me
, void *dest
,
108 int space
, address_word addr
, unsigned nr_bytes
)
110 struct bfin_ebiu_ddrc
*ddrc
= hw_data (me
);
116 /* Invalid access mode is higher priority than missing register. */
117 if (!dv_bfin_mmr_require_16_32 (me
, addr
, nr_bytes
, true))
120 mmr_off
= addr
- ddrc
->base
;
121 valuep
= (void *)((uintptr_t)ddrc
+ mmr_base() + mmr_off
);
129 case mmr_offset(errmst
):
130 case mmr_offset(rstctl
):
131 if (!dv_bfin_mmr_require_16 (me
, addr
, nr_bytes
, false))
133 dv_store_2 (dest
, *value16p
);
136 if (!dv_bfin_mmr_require_32 (me
, addr
, nr_bytes
, false))
138 dv_store_4 (dest
, *value32p
);
146 attach_bfin_ebiu_ddrc_regs (struct hw
*me
, struct bfin_ebiu_ddrc
*ddrc
)
148 address_word attach_address
;
150 unsigned attach_size
;
151 reg_property_spec reg
;
153 if (hw_find_property (me
, "reg") == NULL
)
154 hw_abort (me
, "Missing \"reg\" property");
156 if (!hw_find_reg_array_property (me
, "reg", 0, ®
))
157 hw_abort (me
, "\"reg\" property must contain three addr/size entries");
159 hw_unit_address_to_attach_address (hw_parent (me
),
161 &attach_space
, &attach_address
, me
);
162 hw_unit_size_to_attach_size (hw_parent (me
), ®
.size
, &attach_size
, me
);
164 if (attach_size
!= BFIN_MMR_EBIU_DDRC_SIZE
)
165 hw_abort (me
, "\"reg\" size must be %#x", BFIN_MMR_EBIU_DDRC_SIZE
);
167 hw_attach_address (hw_parent (me
),
168 0, attach_space
, attach_address
, attach_size
, me
);
170 ddrc
->base
= attach_address
;
174 bfin_ebiu_ddrc_finish (struct hw
*me
)
176 struct bfin_ebiu_ddrc
*ddrc
;
178 ddrc
= HW_ZALLOC (me
, struct bfin_ebiu_ddrc
);
180 set_hw_data (me
, ddrc
);
181 set_hw_io_read_buffer (me
, bfin_ebiu_ddrc_io_read_buffer
);
182 set_hw_io_write_buffer (me
, bfin_ebiu_ddrc_io_write_buffer
);
184 attach_bfin_ebiu_ddrc_regs (me
, ddrc
);
186 /* Initialize the DDRC. */
187 ddrc
->ddrctl0
= 0x098E8411;
188 ddrc
->ddrctl1
= 0x10026223;
189 ddrc
->ddrctl2
= 0x00000021;
190 ddrc
->ddrctl3
= 0x00000003; /* XXX: MDDR is 0x20 ... */
191 ddrc
->ddrque
= 0x00001115;
192 ddrc
->rstctl
= 0x0002;
195 const struct hw_descriptor dv_bfin_ebiu_ddrc_descriptor
[] =
197 {"bfin_ebiu_ddrc", bfin_ebiu_ddrc_finish
,},