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 "qemu/osdep.h"
13 #include "hw/sysbus.h"
16 #include "hw/unicore32/puv3.h"
17 #include "qemu/module.h"
20 #define TYPE_PUV3_PM "puv3_pm"
21 #define PUV3_PM(obj) OBJECT_CHECK(PUV3PMState, (obj), TYPE_PUV3_PM)
23 typedef struct PUV3PMState
{
24 SysBusDevice parent_obj
;
30 uint32_t reg_PLL_SYS_CFG
;
31 uint32_t reg_PLL_DDR_CFG
;
32 uint32_t reg_PLL_VGA_CFG
;
36 static uint64_t puv3_pm_read(void *opaque
, hwaddr offset
,
39 PUV3PMState
*s
= opaque
;
47 ret
= s
->reg_PLL_SYS_CFG
;
50 ret
= s
->reg_PLL_DDR_CFG
;
53 ret
= s
->reg_PLL_VGA_CFG
;
58 case 0x28: /* PLL SYS STATUS */
61 case 0x2c: /* PLL DDR STATUS */
64 case 0x30: /* PLL VGA STATUS */
67 case 0x34: /* DIV STATUS */
70 case 0x38: /* SW RESET */
73 case 0x44: /* PLL DFC DONE */
77 qemu_log_mask(LOG_GUEST_ERROR
,
78 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
81 DPRINTF("offset 0x%x, value 0x%x\n", offset
, ret
);
86 static void puv3_pm_write(void *opaque
, hwaddr offset
,
87 uint64_t value
, unsigned size
)
89 PUV3PMState
*s
= opaque
;
99 s
->reg_PLL_SYS_CFG
= value
;
102 s
->reg_PLL_DDR_CFG
= value
;
105 s
->reg_PLL_VGA_CFG
= value
;
111 qemu_log_mask(LOG_GUEST_ERROR
,
112 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
115 DPRINTF("offset 0x%x, value 0x%x\n", offset
, value
);
118 static const MemoryRegionOps puv3_pm_ops
= {
119 .read
= puv3_pm_read
,
120 .write
= puv3_pm_write
,
122 .min_access_size
= 4,
123 .max_access_size
= 4,
125 .endianness
= DEVICE_NATIVE_ENDIAN
,
128 static void puv3_pm_realize(DeviceState
*dev
, Error
**errp
)
130 PUV3PMState
*s
= PUV3_PM(dev
);
134 memory_region_init_io(&s
->iomem
, OBJECT(s
), &puv3_pm_ops
, s
, "puv3_pm",
136 sysbus_init_mmio(SYS_BUS_DEVICE(dev
), &s
->iomem
);
139 static void puv3_pm_class_init(ObjectClass
*klass
, void *data
)
141 DeviceClass
*dc
= DEVICE_CLASS(klass
);
143 dc
->realize
= puv3_pm_realize
;
146 static const TypeInfo puv3_pm_info
= {
147 .name
= TYPE_PUV3_PM
,
148 .parent
= TYPE_SYS_BUS_DEVICE
,
149 .instance_size
= sizeof(PUV3PMState
),
150 .class_init
= puv3_pm_class_init
,
153 static void puv3_pm_register_type(void)
155 type_register_static(&puv3_pm_info
);
158 type_init(puv3_pm_register_type
)