2 * Status and system control registers for ARM RealView/Versatile boards.
4 * Copyright (c) 2006-2007 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licenced under the GPL.
11 #include "qemu-timer.h"
13 #include "primecell.h"
16 #define LOCK_VALUE 0xa05f
31 static void arm_sysctl_reset(DeviceState
*d
)
33 arm_sysctl_state
*s
= FROM_SYSBUS(arm_sysctl_state
, sysbus_from_qdev(d
));
43 static uint32_t arm_sysctl_read(void *opaque
, target_phys_addr_t offset
)
45 arm_sysctl_state
*s
= (arm_sysctl_state
*)opaque
;
51 /* General purpose hardware switches.
52 We don't have a useful way of exposing these to the user. */
63 case 0x24: /* 100HZ */
64 /* ??? Implement these. */
66 case 0x28: /* CFGDATA1 */
68 case 0x2c: /* CFGDATA2 */
70 case 0x30: /* FLAGS */
72 case 0x38: /* NVFLAGS */
74 case 0x40: /* RESETCTL */
76 case 0x44: /* PCICTL */
80 case 0x4c: /* FLASH */
84 case 0x54: /* CLCDSER */
86 case 0x58: /* BOOTCS */
88 case 0x5c: /* 24MHz */
89 return muldiv64(qemu_get_clock(vm_clock
), 24000000, get_ticks_per_sec());
92 case 0x84: /* PROCID0 */
94 case 0x88: /* PROCID1 */
96 case 0x64: /* DMAPSR0 */
97 case 0x68: /* DMAPSR1 */
98 case 0x6c: /* DMAPSR2 */
99 case 0x70: /* IOSEL */
100 case 0x74: /* PLDCTL */
101 case 0x80: /* BUSID */
102 case 0x8c: /* OSCRESET0 */
103 case 0x90: /* OSCRESET1 */
104 case 0x94: /* OSCRESET2 */
105 case 0x98: /* OSCRESET3 */
106 case 0x9c: /* OSCRESET4 */
107 case 0xc0: /* SYS_TEST_OSC0 */
108 case 0xc4: /* SYS_TEST_OSC1 */
109 case 0xc8: /* SYS_TEST_OSC2 */
110 case 0xcc: /* SYS_TEST_OSC3 */
111 case 0xd0: /* SYS_TEST_OSC4 */
114 printf ("arm_sysctl_read: Bad register offset 0x%x\n", (int)offset
);
119 static void arm_sysctl_write(void *opaque
, target_phys_addr_t offset
,
122 arm_sysctl_state
*s
= (arm_sysctl_state
*)opaque
;
127 case 0x0c: /* OSC0 */
128 case 0x10: /* OSC1 */
129 case 0x14: /* OSC2 */
130 case 0x18: /* OSC3 */
131 case 0x1c: /* OSC4 */
134 case 0x20: /* LOCK */
135 if (val
== LOCK_VALUE
)
138 s
->lockval
= val
& 0x7fff;
140 case 0x28: /* CFGDATA1 */
141 /* ??? Need to implement this. */
144 case 0x2c: /* CFGDATA2 */
145 /* ??? Need to implement this. */
148 case 0x30: /* FLAGSSET */
151 case 0x34: /* FLAGSCLR */
154 case 0x38: /* NVFLAGSSET */
157 case 0x3c: /* NVFLAGSCLR */
160 case 0x40: /* RESETCTL */
161 if (s
->lockval
== LOCK_VALUE
) {
164 qemu_system_reset_request ();
167 case 0x44: /* PCICTL */
170 case 0x4c: /* FLASH */
171 case 0x50: /* CLCD */
172 case 0x54: /* CLCDSER */
173 case 0x64: /* DMAPSR0 */
174 case 0x68: /* DMAPSR1 */
175 case 0x6c: /* DMAPSR2 */
176 case 0x70: /* IOSEL */
177 case 0x74: /* PLDCTL */
178 case 0x80: /* BUSID */
179 case 0x84: /* PROCID0 */
180 case 0x88: /* PROCID1 */
181 case 0x8c: /* OSCRESET0 */
182 case 0x90: /* OSCRESET1 */
183 case 0x94: /* OSCRESET2 */
184 case 0x98: /* OSCRESET3 */
185 case 0x9c: /* OSCRESET4 */
188 printf ("arm_sysctl_write: Bad register offset 0x%x\n", (int)offset
);
193 static CPUReadMemoryFunc
* const arm_sysctl_readfn
[] = {
199 static CPUWriteMemoryFunc
* const arm_sysctl_writefn
[] = {
205 static int arm_sysctl_init1(SysBusDevice
*dev
)
207 arm_sysctl_state
*s
= FROM_SYSBUS(arm_sysctl_state
, dev
);
210 iomemtype
= cpu_register_io_memory(arm_sysctl_readfn
,
211 arm_sysctl_writefn
, s
);
212 sysbus_init_mmio(dev
, 0x1000, iomemtype
);
213 /* ??? Save/restore. */
217 /* Legacy helper function. */
218 void arm_sysctl_init(uint32_t base
, uint32_t sys_id
, uint32_t proc_id
)
222 dev
= qdev_create(NULL
, "realview_sysctl");
223 qdev_prop_set_uint32(dev
, "sys_id", sys_id
);
224 qdev_init_nofail(dev
);
225 qdev_prop_set_uint32(dev
, "proc_id", proc_id
);
226 sysbus_mmio_map(sysbus_from_qdev(dev
), 0, base
);
229 static SysBusDeviceInfo arm_sysctl_info
= {
230 .init
= arm_sysctl_init1
,
231 .qdev
.name
= "realview_sysctl",
232 .qdev
.size
= sizeof(arm_sysctl_state
),
233 .qdev
.reset
= arm_sysctl_reset
,
234 .qdev
.props
= (Property
[]) {
235 DEFINE_PROP_UINT32("sys_id", arm_sysctl_state
, sys_id
, 0),
236 DEFINE_PROP_UINT32("proc_id", arm_sysctl_state
, proc_id
, 0),
237 DEFINE_PROP_END_OF_LIST(),
241 static void arm_sysctl_register_devices(void)
243 sysbus_register_withprop(&arm_sysctl_info
);
246 device_init(arm_sysctl_register_devices
)