2 * QEMU model of the Milkymist High Performance Dynamic Memory Controller.
4 * Copyright (c) 2010 Michael Walle <michael@walle.cc>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 * Specification available at:
21 * http://www.milkymist.org/socdoc/hpdmc.pdf
27 #include "qemu-error.h"
38 IODELAY_DQSDELAY_RDY
= (1<<5),
39 IODELAY_PLL1_LOCKED
= (1<<6),
40 IODELAY_PLL2_LOCKED
= (1<<7),
43 struct MilkymistHpdmcState
{
48 typedef struct MilkymistHpdmcState MilkymistHpdmcState
;
50 static uint32_t hpdmc_read(void *opaque
, target_phys_addr_t addr
)
52 MilkymistHpdmcState
*s
= opaque
;
65 error_report("milkymist_hpdmc: read access to unknown register 0x"
66 TARGET_FMT_plx
, addr
<< 2);
70 trace_milkymist_hpdmc_memory_read(addr
<< 2, r
);
75 static void hpdmc_write(void *opaque
, target_phys_addr_t addr
, uint32_t value
)
77 MilkymistHpdmcState
*s
= opaque
;
79 trace_milkymist_hpdmc_memory_write(addr
, value
);
86 s
->regs
[addr
] = value
;
93 error_report("milkymist_hpdmc: write access to unknown register 0x"
94 TARGET_FMT_plx
, addr
<< 2);
99 static CPUReadMemoryFunc
* const hpdmc_read_fn
[] = {
105 static CPUWriteMemoryFunc
* const hpdmc_write_fn
[] = {
111 static void milkymist_hpdmc_reset(DeviceState
*d
)
113 MilkymistHpdmcState
*s
= container_of(d
, MilkymistHpdmcState
, busdev
.qdev
);
116 for (i
= 0; i
< R_MAX
; i
++) {
121 s
->regs
[R_IODELAY
] = IODELAY_DQSDELAY_RDY
| IODELAY_PLL1_LOCKED
122 | IODELAY_PLL2_LOCKED
;
125 static int milkymist_hpdmc_init(SysBusDevice
*dev
)
127 MilkymistHpdmcState
*s
= FROM_SYSBUS(typeof(*s
), dev
);
130 hpdmc_regs
= cpu_register_io_memory(hpdmc_read_fn
, hpdmc_write_fn
, s
,
131 DEVICE_NATIVE_ENDIAN
);
132 sysbus_init_mmio(dev
, R_MAX
* 4, hpdmc_regs
);
137 static const VMStateDescription vmstate_milkymist_hpdmc
= {
138 .name
= "milkymist-hpdmc",
140 .minimum_version_id
= 1,
141 .minimum_version_id_old
= 1,
142 .fields
= (VMStateField
[]) {
143 VMSTATE_UINT32_ARRAY(regs
, MilkymistHpdmcState
, R_MAX
),
144 VMSTATE_END_OF_LIST()
148 static SysBusDeviceInfo milkymist_hpdmc_info
= {
149 .init
= milkymist_hpdmc_init
,
150 .qdev
.name
= "milkymist-hpdmc",
151 .qdev
.size
= sizeof(MilkymistHpdmcState
),
152 .qdev
.vmsd
= &vmstate_milkymist_hpdmc
,
153 .qdev
.reset
= milkymist_hpdmc_reset
,
156 static void milkymist_hpdmc_register(void)
158 sysbus_register_withprop(&milkymist_hpdmc_info
);
161 device_init(milkymist_hpdmc_register
)