1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include "qemu/osdep.h"
27#include "hw/sysbus.h"
28
29#include "hw/fdt_generic_util.h"
30
31#define TYPE_FIXED_CLOCK "fixed-clock"
32
33#define FIXED_CLOCK(obj) \
34 OBJECT_CHECK(FixedClock, (obj), TYPE_FIXED_CLOCK)
35
36typedef struct FixedClock {
37
38 DeviceState parent_obj;
39
40 uint32_t freq_hz;
41 qemu_irq clk;
42} FixedClock;
43
44static void fixed_clock_reset(DeviceState *dev)
45{
46 FixedClock *s = FIXED_CLOCK(dev);
47
48 qemu_set_irq(s->clk, s->freq_hz);
49}
50
51static void fixed_clock_init(Object *obj)
52{
53 FixedClock *s = FIXED_CLOCK(obj);
54
55 qdev_init_gpio_out(DEVICE(obj), &s->clk, 1);
56}
57
58static Property fixed_clock_properties [] = {
59 DEFINE_PROP_UINT32("clock-frequency", FixedClock, freq_hz, 10000000),
60 DEFINE_PROP_END_OF_LIST(),
61};
62
63static void fixed_clock_class_init(ObjectClass *oc, void *data)
64{
65 DeviceClass *dc = DEVICE_CLASS(oc);
66
67 dc->reset = fixed_clock_reset;
68 dc->props = fixed_clock_properties;
69}
70
71static const TypeInfo fixed_clock_info = {
72 .name = "fixed-clock",
73 .parent = TYPE_DEVICE,
74 .instance_size = sizeof(FixedClock),
75 .class_init = fixed_clock_class_init,
76 .instance_init = fixed_clock_init,
77 .interfaces = (InterfaceInfo []) {
78 { TYPE_FDT_GENERIC_GPIO },
79 { },
80 },
81};
82
83static void fixed_clock_register_types(void)
84{
85 type_register_static(&fixed_clock_info);
86}
87
88type_init(fixed_clock_register_types)
89