Fix some compiler warnings related to format strings
[qemu/ar7.git] / hw / arm / syborg_rtc.c
bloba3aeb5ff22b9c0ac4ab87b8eb732e88b49d63010
1 /*
2 * Syborg RTC
4 * Copyright (c) 2008 CodeSourcery
5 * Copyright (c) 2010, 2013 Stefan Weil
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
26 #include "qemu/osdep.h"
27 #include "hw/sysbus.h"
28 #include "qemu/timer.h"
29 #include "syborg.h"
31 enum {
32 RTC_ID = 0,
33 RTC_LATCH = 1,
34 RTC_DATA_LOW = 2,
35 RTC_DATA_HIGH = 3
38 typedef struct {
39 SysBusDevice busdev;
40 MemoryRegion iomem;
41 int64_t offset;
42 int64_t data;
43 qemu_irq irq;
44 } SyborgRTCState;
46 static uint64_t syborg_rtc_read(void *opaque, hwaddr offset,
47 unsigned size)
49 SyborgRTCState *s = (SyborgRTCState *)opaque;
50 offset &= 0xfff;
51 switch (offset >> 2) {
52 case RTC_ID:
53 return SYBORG_ID_RTC;
54 case RTC_DATA_LOW:
55 return (uint32_t)s->data;
56 case RTC_DATA_HIGH:
57 return (uint32_t)(s->data >> 32);
58 default:
59 cpu_abort(cpu_single_env, "syborg_rtc_read: Bad offset %x\n",
60 (int)offset);
61 return 0;
65 static void syborg_rtc_write(void *opaque, hwaddr offset,
66 uint64_t value, unsigned size)
68 SyborgRTCState *s = (SyborgRTCState *)opaque;
69 uint64_t now;
71 offset &= 0xfff;
72 switch (offset >> 2) {
73 case RTC_LATCH:
74 now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
75 if (value >= 4) {
76 s->offset = s->data - now;
77 } else {
78 s->data = now + s->offset;
79 while (value) {
80 s->data /= 1000;
81 value--;
84 break;
85 case RTC_DATA_LOW:
86 s->data = (s->data & ~(uint64_t)0xffffffffu) | value;
87 break;
88 case RTC_DATA_HIGH:
89 s->data = (s->data & 0xffffffffu) | ((uint64_t)value << 32);
90 break;
91 default:
92 cpu_abort(cpu_single_env, "syborg_rtc_write: Bad offset %x\n",
93 (int)offset);
94 break;
98 static const MemoryRegionOps syborg_rtc_ops = {
99 .read = syborg_rtc_read,
100 .write = syborg_rtc_write,
101 .endianness = DEVICE_NATIVE_ENDIAN,
104 static const VMStateDescription vmstate_syborg_rtc = {
105 .name = "syborg_keyboard",
106 .version_id = 1,
107 .minimum_version_id = 1,
108 .minimum_version_id_old = 1,
109 .fields = (VMStateField[]) {
110 VMSTATE_INT64(offset, SyborgRTCState),
111 VMSTATE_INT64(data, SyborgRTCState),
112 VMSTATE_END_OF_LIST()
116 static int syborg_rtc_init(SysBusDevice *sbd)
118 DeviceState *dev = DEVICE(sbd);
119 SyborgRTCState *s = SYBORG_RTC(dev);
120 struct tm tm;
122 memory_region_init_io(&s->iomem, &syborg_rtc_ops, s, "rtc", 0x1000);
123 sysbus_init_mmio(sbd, &s->iomem);
125 qemu_get_timedate(&tm, 0);
126 s->offset = (uint64_t)mktime(&tm) * 1000000000;
128 vmstate_register(&dev->qdev, -1, &vmstate_syborg_rtc, s);
129 return 0;
132 static void syborg_rtc_class_init(ObjectClass *klass, void *data)
134 DeviceClass *dc = DEVICE_CLASS(klass);
135 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
136 dc->desc = "syborg rtc";
137 //~ dc->reset = syborg_rtc_reset;
138 //~ dc->vmsd = &syborg_rtc_vmsd;
139 k->init = syborg_rtc_init;
142 static const TypeInfo syborg_rtc_info = {
143 .name = "syborg,rtc",
144 .parent = TYPE_SYS_BUS_DEVICE,
145 .instance_size = sizeof(SyborgRTCState),
146 .class_init = syborg_rtc_class_init
149 static void syborg_rtc_register_types(void)
151 type_register_static(&syborg_rtc_info);
154 type_init(syborg_rtc_register_types)