2 * Power Management device simulation in PKUnity SoC
4 * Copyright (C) 2010-2012 Guan Xuetao
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation, or any later version.
9 * See the COPYING file in the top-level directory.
11 #include "qemu/osdep.h"
13 #include "hw/sysbus.h"
16 #include "hw/unicore32/puv3.h"
18 #define TYPE_PUV3_PM "puv3_pm"
19 #define PUV3_PM(obj) OBJECT_CHECK(PUV3PMState, (obj), TYPE_PUV3_PM)
21 typedef struct PUV3PMState {
22 SysBusDevice parent_obj;
28 uint32_t reg_PLL_SYS_CFG;
29 uint32_t reg_PLL_DDR_CFG;
30 uint32_t reg_PLL_VGA_CFG;
34 static uint64_t puv3_pm_read(void *opaque, hwaddr offset,
37 PUV3PMState *s = opaque;
45 ret = s->reg_PLL_SYS_CFG;
48 ret = s->reg_PLL_DDR_CFG;
51 ret = s->reg_PLL_VGA_CFG;
56 case 0x28: /* PLL SYS STATUS */
59 case 0x2c: /* PLL DDR STATUS */
62 case 0x30: /* PLL VGA STATUS */
65 case 0x34: /* DIV STATUS */
68 case 0x38: /* SW RESET */
71 case 0x44: /* PLL DFC DONE */
75 DPRINTF("Bad offset 0x%x\n", offset);
77 DPRINTF("offset 0x%x, value 0x%x\n", offset, ret);
82 static void puv3_pm_write(void *opaque, hwaddr offset,
83 uint64_t value, unsigned size)
85 PUV3PMState *s = opaque;
95 s->reg_PLL_SYS_CFG = value;
98 s->reg_PLL_DDR_CFG = value;
101 s->reg_PLL_VGA_CFG = value;
107 DPRINTF("Bad offset 0x%x\n", offset);
109 DPRINTF("offset 0x%x, value 0x%x\n", offset, value);
112 static const MemoryRegionOps puv3_pm_ops = {
113 .read = puv3_pm_read,
114 .write = puv3_pm_write,
116 .min_access_size = 4,
117 .max_access_size = 4,
119 .endianness = DEVICE_NATIVE_ENDIAN,
122 static void puv3_pm_realize(DeviceState *dev, Error **errp)
124 PUV3PMState *s = PUV3_PM(dev);
128 memory_region_init_io(&s->iomem, OBJECT(s), &puv3_pm_ops, s, "puv3_pm",
130 sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
133 static void puv3_pm_class_init(ObjectClass *klass, void *data)
135 DeviceClass *dc = DEVICE_CLASS(klass);
137 dc->realize = puv3_pm_realize;
140 static const TypeInfo puv3_pm_info = {
141 .name = TYPE_PUV3_PM,
142 .parent = TYPE_SYS_BUS_DEVICE,
143 .instance_size = sizeof(PUV3PMState),
144 .class_init = puv3_pm_class_init,
147 static void puv3_pm_register_type(void)
149 type_register_static(&puv3_pm_info);
152 type_init(puv3_pm_register_type)