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"
14 #include "qom/object.h"
17 #include "hw/unicore32/puv3.h"
18 #include "qemu/module.h"
21 #define TYPE_PUV3_PM "puv3_pm"
22 OBJECT_DECLARE_SIMPLE_TYPE(PUV3PMState
, PUV3_PM
)
25 SysBusDevice parent_obj
;
31 uint32_t reg_PLL_SYS_CFG
;
32 uint32_t reg_PLL_DDR_CFG
;
33 uint32_t reg_PLL_VGA_CFG
;
37 static uint64_t puv3_pm_read(void *opaque
, hwaddr offset
,
40 PUV3PMState
*s
= opaque
;
48 ret
= s
->reg_PLL_SYS_CFG
;
51 ret
= s
->reg_PLL_DDR_CFG
;
54 ret
= s
->reg_PLL_VGA_CFG
;
59 case 0x28: /* PLL SYS STATUS */
62 case 0x2c: /* PLL DDR STATUS */
65 case 0x30: /* PLL VGA STATUS */
68 case 0x34: /* DIV STATUS */
71 case 0x38: /* SW RESET */
74 case 0x44: /* PLL DFC DONE */
78 qemu_log_mask(LOG_GUEST_ERROR
,
79 "%s: Bad read offset 0x%"HWADDR_PRIx
"\n",
82 DPRINTF("offset 0x%x, value 0x%x\n", offset
, ret
);
87 static void puv3_pm_write(void *opaque
, hwaddr offset
,
88 uint64_t value
, unsigned size
)
90 PUV3PMState
*s
= opaque
;
100 s
->reg_PLL_SYS_CFG
= value
;
103 s
->reg_PLL_DDR_CFG
= value
;
106 s
->reg_PLL_VGA_CFG
= value
;
112 qemu_log_mask(LOG_GUEST_ERROR
,
113 "%s: Bad write offset 0x%"HWADDR_PRIx
"\n",
116 DPRINTF("offset 0x%x, value 0x%x\n", offset
, value
);
119 static const MemoryRegionOps puv3_pm_ops
= {
120 .read
= puv3_pm_read
,
121 .write
= puv3_pm_write
,
123 .min_access_size
= 4,
124 .max_access_size
= 4,
126 .endianness
= DEVICE_NATIVE_ENDIAN
,
129 static void puv3_pm_realize(DeviceState
*dev
, Error
**errp
)
131 PUV3PMState
*s
= PUV3_PM(dev
);
135 memory_region_init_io(&s
->iomem
, OBJECT(s
), &puv3_pm_ops
, s
, "puv3_pm",
137 sysbus_init_mmio(SYS_BUS_DEVICE(dev
), &s
->iomem
);
140 static void puv3_pm_class_init(ObjectClass
*klass
, void *data
)
142 DeviceClass
*dc
= DEVICE_CLASS(klass
);
144 dc
->realize
= puv3_pm_realize
;
147 static const TypeInfo puv3_pm_info
= {
148 .name
= TYPE_PUV3_PM
,
149 .parent
= TYPE_SYS_BUS_DEVICE
,
150 .instance_size
= sizeof(PUV3PMState
),
151 .class_init
= puv3_pm_class_init
,
154 static void puv3_pm_register_type(void)
156 type_register_static(&puv3_pm_info
);
159 type_init(puv3_pm_register_type
)