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.
12 #include "hw/sysbus.h"
15 #include "hw/unicore32/puv3.h"
17 #define TYPE_PUV3_PM "puv3_pm"
18 #define PUV3_PM(obj) OBJECT_CHECK(PUV3PMState, (obj), TYPE_PUV3_PM)
20 typedef struct PUV3PMState {
21 SysBusDevice parent_obj;
27 uint32_t reg_PLL_SYS_CFG;
28 uint32_t reg_PLL_DDR_CFG;
29 uint32_t reg_PLL_VGA_CFG;
33 static uint64_t puv3_pm_read(void *opaque, hwaddr offset,
36 PUV3PMState *s = opaque;
44 ret = s->reg_PLL_SYS_CFG;
47 ret = s->reg_PLL_DDR_CFG;
50 ret = s->reg_PLL_VGA_CFG;
55 case 0x28: /* PLL SYS STATUS */
58 case 0x2c: /* PLL DDR STATUS */
61 case 0x30: /* PLL VGA STATUS */
64 case 0x34: /* DIV STATUS */
67 case 0x38: /* SW RESET */
70 case 0x44: /* PLL DFC DONE */
74 DPRINTF("Bad offset 0x%x\n", offset);
76 DPRINTF("offset 0x%x, value 0x%x\n", offset, ret);
81 static void puv3_pm_write(void *opaque, hwaddr offset,
82 uint64_t value, unsigned size)
84 PUV3PMState *s = opaque;
94 s->reg_PLL_SYS_CFG = value;
97 s->reg_PLL_DDR_CFG = value;
100 s->reg_PLL_VGA_CFG = value;
106 DPRINTF("Bad offset 0x%x\n", offset);
108 DPRINTF("offset 0x%x, value 0x%x\n", offset, value);
111 static const MemoryRegionOps puv3_pm_ops = {
112 .read = puv3_pm_read,
113 .write = puv3_pm_write,
115 .min_access_size = 4,
116 .max_access_size = 4,
118 .endianness = DEVICE_NATIVE_ENDIAN,
121 static int puv3_pm_init(SysBusDevice *dev)
123 PUV3PMState *s = PUV3_PM(dev);
127 memory_region_init_io(&s->iomem, OBJECT(s), &puv3_pm_ops, s, "puv3_pm",
129 sysbus_init_mmio(dev, &s->iomem);
134 static void puv3_pm_class_init(ObjectClass *klass, void *data)
136 SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
138 sdc->init = puv3_pm_init;
141 static const TypeInfo puv3_pm_info = {
142 .name = TYPE_PUV3_PM,
143 .parent = TYPE_SYS_BUS_DEVICE,
144 .instance_size = sizeof(PUV3PMState),
145 .class_init = puv3_pm_class_init,
148 static void puv3_pm_register_type(void)
150 type_register_static(&puv3_pm_info);
153 type_init(puv3_pm_register_type)