xref: /openbmc/qemu/hw/arm/digic.c (revision 28298069afff3eb696e4995e63b2579b27adf378)
1c6f09eb4SAntony Pavlov /*
2c6f09eb4SAntony Pavlov  * QEMU model of the Canon DIGIC SoC.
3c6f09eb4SAntony Pavlov  *
4c6f09eb4SAntony Pavlov  * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com>
5c6f09eb4SAntony Pavlov  *
6c6f09eb4SAntony Pavlov  * This model is based on reverse engineering efforts
7c6f09eb4SAntony Pavlov  * made by CHDK (http://chdk.wikia.com) and
8c6f09eb4SAntony Pavlov  * Magic Lantern (http://www.magiclantern.fm) projects
9c6f09eb4SAntony Pavlov  * contributors.
10c6f09eb4SAntony Pavlov  *
11c6f09eb4SAntony Pavlov  * This program is free software; you can redistribute it and/or modify
12c6f09eb4SAntony Pavlov  * it under the terms of the GNU General Public License as published by
13c6f09eb4SAntony Pavlov  * the Free Software Foundation; either version 2 of the License, or
14c6f09eb4SAntony Pavlov  * (at your option) any later version.
15c6f09eb4SAntony Pavlov  *
16c6f09eb4SAntony Pavlov  * This program is distributed in the hope that it will be useful,
17c6f09eb4SAntony Pavlov  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18c6f09eb4SAntony Pavlov  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19c6f09eb4SAntony Pavlov  * GNU General Public License for more details.
20c6f09eb4SAntony Pavlov  *
21c6f09eb4SAntony Pavlov  */
22c6f09eb4SAntony Pavlov 
2312b16722SPeter Maydell #include "qemu/osdep.h"
24da34e65cSMarkus Armbruster #include "qapi/error.h"
250b8fa32fSMarkus Armbruster #include "qemu/module.h"
26c6f09eb4SAntony Pavlov #include "hw/arm/digic.h"
27a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
28746c3b3eSxiaoqiang zhao #include "sysemu/sysemu.h"
29c6f09eb4SAntony Pavlov 
30576e99cbSAntony Pavlov #define DIGIC4_TIMER_BASE(n)    (0xc0210000 + (n) * 0x100)
31576e99cbSAntony Pavlov 
32142593c9SAntony Pavlov #define DIGIC_UART_BASE          0xc0800000
33142593c9SAntony Pavlov 
digic_init(Object * obj)34c6f09eb4SAntony Pavlov static void digic_init(Object *obj)
35c6f09eb4SAntony Pavlov {
36c6f09eb4SAntony Pavlov     DigicState *s = DIGIC(obj);
37576e99cbSAntony Pavlov     int i;
38c6f09eb4SAntony Pavlov 
399fc7fc4dSMarkus Armbruster     object_initialize_child(obj, "cpu", &s->cpu, ARM_CPU_TYPE_NAME("arm946"));
40576e99cbSAntony Pavlov 
41576e99cbSAntony Pavlov     for (i = 0; i < DIGIC4_NB_TIMERS; i++) {
42*e5c41835SMarc-André Lureau         g_autofree char *name = g_strdup_printf("timer[%d]", i);
43db873cc5SMarkus Armbruster         object_initialize_child(obj, name, &s->timer[i], TYPE_DIGIC_TIMER);
44576e99cbSAntony Pavlov     }
45142593c9SAntony Pavlov 
46db873cc5SMarkus Armbruster     object_initialize_child(obj, "uart", &s->uart, TYPE_DIGIC_UART);
47c6f09eb4SAntony Pavlov }
48c6f09eb4SAntony Pavlov 
digic_realize(DeviceState * dev,Error ** errp)49c6f09eb4SAntony Pavlov static void digic_realize(DeviceState *dev, Error **errp)
50c6f09eb4SAntony Pavlov {
51c6f09eb4SAntony Pavlov     DigicState *s = DIGIC(dev);
52576e99cbSAntony Pavlov     SysBusDevice *sbd;
53576e99cbSAntony Pavlov     int i;
54c6f09eb4SAntony Pavlov 
55778a2dc5SMarkus Armbruster     if (!object_property_set_bool(OBJECT(&s->cpu), "reset-hivecs", true,
56668f62ecSMarkus Armbruster                                   errp)) {
57c6f09eb4SAntony Pavlov         return;
58c6f09eb4SAntony Pavlov     }
59c6f09eb4SAntony Pavlov 
60668f62ecSMarkus Armbruster     if (!qdev_realize(DEVICE(&s->cpu), NULL, errp)) {
61c6f09eb4SAntony Pavlov         return;
62c6f09eb4SAntony Pavlov     }
63576e99cbSAntony Pavlov 
64576e99cbSAntony Pavlov     for (i = 0; i < DIGIC4_NB_TIMERS; i++) {
65668f62ecSMarkus Armbruster         if (!sysbus_realize(SYS_BUS_DEVICE(&s->timer[i]), errp)) {
66576e99cbSAntony Pavlov             return;
67576e99cbSAntony Pavlov         }
68576e99cbSAntony Pavlov 
69576e99cbSAntony Pavlov         sbd = SYS_BUS_DEVICE(&s->timer[i]);
70576e99cbSAntony Pavlov         sysbus_mmio_map(sbd, 0, DIGIC4_TIMER_BASE(i));
71576e99cbSAntony Pavlov     }
72142593c9SAntony Pavlov 
739bca0edbSPeter Maydell     qdev_prop_set_chr(DEVICE(&s->uart), "chardev", serial_hd(0));
74668f62ecSMarkus Armbruster     if (!sysbus_realize(SYS_BUS_DEVICE(&s->uart), errp)) {
75142593c9SAntony Pavlov         return;
76142593c9SAntony Pavlov     }
77142593c9SAntony Pavlov 
78142593c9SAntony Pavlov     sbd = SYS_BUS_DEVICE(&s->uart);
79142593c9SAntony Pavlov     sysbus_mmio_map(sbd, 0, DIGIC_UART_BASE);
80c6f09eb4SAntony Pavlov }
81c6f09eb4SAntony Pavlov 
digic_class_init(ObjectClass * oc,void * data)82c6f09eb4SAntony Pavlov static void digic_class_init(ObjectClass *oc, void *data)
83c6f09eb4SAntony Pavlov {
84c6f09eb4SAntony Pavlov     DeviceClass *dc = DEVICE_CLASS(oc);
85c6f09eb4SAntony Pavlov 
86c6f09eb4SAntony Pavlov     dc->realize = digic_realize;
87f58f2559SThomas Huth     /* Reason: Uses serial_hds in the realize function --> not usable twice */
88f58f2559SThomas Huth     dc->user_creatable = false;
89c6f09eb4SAntony Pavlov }
90c6f09eb4SAntony Pavlov 
91c6f09eb4SAntony Pavlov static const TypeInfo digic_type_info = {
92c6f09eb4SAntony Pavlov     .name = TYPE_DIGIC,
93c6f09eb4SAntony Pavlov     .parent = TYPE_DEVICE,
94c6f09eb4SAntony Pavlov     .instance_size = sizeof(DigicState),
95c6f09eb4SAntony Pavlov     .instance_init = digic_init,
96c6f09eb4SAntony Pavlov     .class_init = digic_class_init,
97c6f09eb4SAntony Pavlov };
98c6f09eb4SAntony Pavlov 
digic_register_types(void)99c6f09eb4SAntony Pavlov static void digic_register_types(void)
100c6f09eb4SAntony Pavlov {
101c6f09eb4SAntony Pavlov     type_register_static(&digic_type_info);
102c6f09eb4SAntony Pavlov }
103c6f09eb4SAntony Pavlov 
104c6f09eb4SAntony Pavlov type_init(digic_register_types)
105