]> git.proxmox.com Git - mirror_qemu.git/blame - hw/riscv/sifive_e_prci.c
riscv: sifive_e: prci: Update the PRCI register block size
[mirror_qemu.git] / hw / riscv / sifive_e_prci.c
CommitLineData
e6b8552c 1/*
56449d20 2 * QEMU SiFive E PRCI (Power, Reset, Clock, Interrupt)
e6b8552c
MC
3 *
4 * Copyright (c) 2017 SiFive, Inc.
5 *
6 * Simple model of the PRCI to emulate register reads made by the SDK BSP
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2 or later, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "qemu/osdep.h"
22#include "hw/sysbus.h"
a2360c85 23#include "qemu/log.h"
0b8fa32f 24#include "qemu/module.h"
650d103d 25#include "hw/hw.h"
56449d20 26#include "hw/riscv/sifive_e_prci.h"
e6b8552c 27
56449d20 28static uint64_t sifive_e_prci_read(void *opaque, hwaddr addr, unsigned int size)
e6b8552c 29{
56449d20 30 SiFiveEPRCIState *s = opaque;
b9d1848e 31 switch (addr) {
56449d20 32 case SIFIVE_E_PRCI_HFROSCCFG:
b9d1848e 33 return s->hfrosccfg;
56449d20 34 case SIFIVE_E_PRCI_HFXOSCCFG:
b9d1848e 35 return s->hfxosccfg;
56449d20 36 case SIFIVE_E_PRCI_PLLCFG:
b9d1848e 37 return s->pllcfg;
56449d20 38 case SIFIVE_E_PRCI_PLLOUTDIV:
b9d1848e 39 return s->plloutdiv;
e6b8552c 40 }
a2360c85
BM
41 qemu_log_mask(LOG_GUEST_ERROR, "%s: read: addr=0x%x\n",
42 __func__, (int)addr);
e6b8552c
MC
43 return 0;
44}
45
56449d20
BM
46static void sifive_e_prci_write(void *opaque, hwaddr addr,
47 uint64_t val64, unsigned int size)
e6b8552c 48{
56449d20 49 SiFiveEPRCIState *s = opaque;
b9d1848e 50 switch (addr) {
56449d20 51 case SIFIVE_E_PRCI_HFROSCCFG:
b9d1848e
NG
52 s->hfrosccfg = (uint32_t) val64;
53 /* OSC stays ready */
56449d20 54 s->hfrosccfg |= SIFIVE_E_PRCI_HFROSCCFG_RDY;
b9d1848e 55 break;
56449d20 56 case SIFIVE_E_PRCI_HFXOSCCFG:
b9d1848e
NG
57 s->hfxosccfg = (uint32_t) val64;
58 /* OSC stays ready */
56449d20 59 s->hfxosccfg |= SIFIVE_E_PRCI_HFXOSCCFG_RDY;
b9d1848e 60 break;
56449d20 61 case SIFIVE_E_PRCI_PLLCFG:
b9d1848e
NG
62 s->pllcfg = (uint32_t) val64;
63 /* PLL stays locked */
56449d20 64 s->pllcfg |= SIFIVE_E_PRCI_PLLCFG_LOCK;
b9d1848e 65 break;
56449d20 66 case SIFIVE_E_PRCI_PLLOUTDIV:
b9d1848e
NG
67 s->plloutdiv = (uint32_t) val64;
68 break;
69 default:
a2360c85
BM
70 qemu_log_mask(LOG_GUEST_ERROR, "%s: bad write: addr=0x%x v=0x%x\n",
71 __func__, (int)addr, (int)val64);
b9d1848e 72 }
e6b8552c
MC
73}
74
56449d20
BM
75static const MemoryRegionOps sifive_e_prci_ops = {
76 .read = sifive_e_prci_read,
77 .write = sifive_e_prci_write,
e6b8552c
MC
78 .endianness = DEVICE_NATIVE_ENDIAN,
79 .valid = {
80 .min_access_size = 4,
81 .max_access_size = 4
82 }
83};
84
56449d20 85static void sifive_e_prci_init(Object *obj)
e6b8552c 86{
56449d20 87 SiFiveEPRCIState *s = SIFIVE_E_PRCI(obj);
e6b8552c 88
56449d20 89 memory_region_init_io(&s->mmio, obj, &sifive_e_prci_ops, s,
d0730344 90 TYPE_SIFIVE_E_PRCI, SIFIVE_E_PRCI_REG_SIZE);
e6b8552c 91 sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio);
b9d1848e 92
56449d20 93 s->hfrosccfg = (SIFIVE_E_PRCI_HFROSCCFG_RDY | SIFIVE_E_PRCI_HFROSCCFG_EN);
1a5938a0 94 s->hfxosccfg = (SIFIVE_E_PRCI_HFXOSCCFG_RDY | SIFIVE_E_PRCI_HFXOSCCFG_EN);
56449d20
BM
95 s->pllcfg = (SIFIVE_E_PRCI_PLLCFG_REFSEL | SIFIVE_E_PRCI_PLLCFG_BYPASS |
96 SIFIVE_E_PRCI_PLLCFG_LOCK);
97 s->plloutdiv = SIFIVE_E_PRCI_PLLOUTDIV_DIV1;
e6b8552c
MC
98}
99
56449d20
BM
100static const TypeInfo sifive_e_prci_info = {
101 .name = TYPE_SIFIVE_E_PRCI,
e6b8552c 102 .parent = TYPE_SYS_BUS_DEVICE,
56449d20
BM
103 .instance_size = sizeof(SiFiveEPRCIState),
104 .instance_init = sifive_e_prci_init,
e6b8552c
MC
105};
106
56449d20 107static void sifive_e_prci_register_types(void)
e6b8552c 108{
56449d20 109 type_register_static(&sifive_e_prci_info);
e6b8552c
MC
110}
111
56449d20 112type_init(sifive_e_prci_register_types)
e6b8552c
MC
113
114
115/*
116 * Create PRCI device.
117 */
56449d20 118DeviceState *sifive_e_prci_create(hwaddr addr)
e6b8552c 119{
56449d20 120 DeviceState *dev = qdev_create(NULL, TYPE_SIFIVE_E_PRCI);
e6b8552c
MC
121 qdev_init_nofail(dev);
122 sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr);
123 return dev;
124}