2 * QEMU model of the Canon DIGIC SoC.
4 * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com>
6 * This model is based on reverse engineering efforts
7 * made by CHDK (http://chdk.wikia.com) and
8 * Magic Lantern (http://www.magiclantern.fm) projects
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
23 #include "hw/arm/digic.h"
25 #define DIGIC4_TIMER_BASE(n) (0xc0210000 + (n) * 0x100)
27 static void digic_init(Object
*obj
)
29 DigicState
*s
= DIGIC(obj
);
33 object_initialize(&s
->cpu
, sizeof(s
->cpu
), "arm946-" TYPE_ARM_CPU
);
34 object_property_add_child(obj
, "cpu", OBJECT(&s
->cpu
), NULL
);
36 for (i
= 0; i
< DIGIC4_NB_TIMERS
; i
++) {
37 #define DIGIC_TIMER_NAME_MLEN 11
38 char name
[DIGIC_TIMER_NAME_MLEN
];
40 object_initialize(&s
->timer
[i
], sizeof(s
->timer
[i
]), TYPE_DIGIC_TIMER
);
41 dev
= DEVICE(&s
->timer
[i
]);
42 qdev_set_parent_bus(dev
, sysbus_get_default());
43 snprintf(name
, DIGIC_TIMER_NAME_MLEN
, "timer[%d]", i
);
44 object_property_add_child(obj
, name
, OBJECT(&s
->timer
[i
]), NULL
);
48 static void digic_realize(DeviceState
*dev
, Error
**errp
)
50 DigicState
*s
= DIGIC(dev
);
55 object_property_set_bool(OBJECT(&s
->cpu
), true, "reset-hivecs", &err
);
57 error_propagate(errp
, err
);
61 object_property_set_bool(OBJECT(&s
->cpu
), true, "realized", &err
);
63 error_propagate(errp
, err
);
67 for (i
= 0; i
< DIGIC4_NB_TIMERS
; i
++) {
68 object_property_set_bool(OBJECT(&s
->timer
[i
]), true, "realized", &err
);
70 error_propagate(errp
, err
);
74 sbd
= SYS_BUS_DEVICE(&s
->timer
[i
]);
75 sysbus_mmio_map(sbd
, 0, DIGIC4_TIMER_BASE(i
));
79 static void digic_class_init(ObjectClass
*oc
, void *data
)
81 DeviceClass
*dc
= DEVICE_CLASS(oc
);
83 dc
->realize
= digic_realize
;
86 static const TypeInfo digic_type_info
= {
88 .parent
= TYPE_DEVICE
,
89 .instance_size
= sizeof(DigicState
),
90 .instance_init
= digic_init
,
91 .class_init
= digic_class_init
,
94 static void digic_register_types(void)
96 type_register_static(&digic_type_info
);
99 type_init(digic_register_types
)