xref: /openbmc/qemu/hw/timer/aspeed_timer.c (revision c20375dd8678eae2462a986938e6d119cb5abefa)
1 /*
2  * ASPEED AST2400 Timer
3  *
4  * Andrew Jeffery <andrew@aj.id.au>
5  *
6  * Copyright (C) 2016 IBM Corp.
7  *
8  * This code is licensed under the GPL version 2 or later.  See
9  * the COPYING file in the top-level directory.
10  */
11 
12 #include "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "hw/irq.h"
15 #include "hw/sysbus.h"
16 #include "hw/timer/aspeed_timer.h"
17 #include "migration/vmstate.h"
18 #include "qemu/bitops.h"
19 #include "qemu/timer.h"
20 #include "qemu/log.h"
21 #include "qemu/module.h"
22 #include "trace.h"
23 
24 #define TIMER_NR_REGS 4
25 
26 #define TIMER_CTRL_BITS 4
27 #define TIMER_CTRL_MASK ((1 << TIMER_CTRL_BITS) - 1)
28 
29 #define TIMER_CLOCK_USE_EXT true
30 #define TIMER_CLOCK_EXT_HZ 1000000
31 #define TIMER_CLOCK_USE_APB false
32 
33 #define TIMER_REG_STATUS 0
34 #define TIMER_REG_RELOAD 1
35 #define TIMER_REG_MATCH_FIRST 2
36 #define TIMER_REG_MATCH_SECOND 3
37 
38 #define TIMER_FIRST_CAP_PULSE 4
39 
40 enum timer_ctrl_op {
41     op_enable = 0,
42     op_external_clock,
43     op_overflow_interrupt,
44     op_pulse_enable
45 };
46 
47 /*
48  * Minimum value of the reload register to filter out short period
49  * timers which have a noticeable impact in emulation. 5us should be
50  * enough, use 20us for "safety".
51  */
52 #define TIMER_MIN_NS (20 * SCALE_US)
53 
54 /**
55  * Avoid mutual references between AspeedTimerCtrlState and AspeedTimer
56  * structs, as it's a waste of memory. The ptimer BH callback needs to know
57  * whether a specific AspeedTimer is enabled, but this information is held in
58  * AspeedTimerCtrlState. So, provide a helper to hoist ourselves from an
59  * arbitrary AspeedTimer to AspeedTimerCtrlState.
60  */
61 static inline AspeedTimerCtrlState *timer_to_ctrl(AspeedTimer *t)
62 {
63     const AspeedTimer (*timers)[] = (void *)t - (t->id * sizeof(*t));
64     return container_of(timers, AspeedTimerCtrlState, timers);
65 }
66 
67 static inline bool timer_ctrl_status(AspeedTimer *t, enum timer_ctrl_op op)
68 {
69     return !!(timer_to_ctrl(t)->ctrl & BIT(t->id * TIMER_CTRL_BITS + op));
70 }
71 
72 static inline bool timer_enabled(AspeedTimer *t)
73 {
74     return timer_ctrl_status(t, op_enable);
75 }
76 
77 static inline bool timer_overflow_interrupt(AspeedTimer *t)
78 {
79     return timer_ctrl_status(t, op_overflow_interrupt);
80 }
81 
82 static inline bool timer_can_pulse(AspeedTimer *t)
83 {
84     return t->id >= TIMER_FIRST_CAP_PULSE;
85 }
86 
87 static inline bool timer_external_clock(AspeedTimer *t)
88 {
89     return timer_ctrl_status(t, op_external_clock);
90 }
91 
92 static inline uint32_t calculate_rate(struct AspeedTimer *t)
93 {
94     AspeedTimerCtrlState *s = timer_to_ctrl(t);
95 
96     return timer_external_clock(t) ? TIMER_CLOCK_EXT_HZ :
97         aspeed_scu_get_apb_freq(s->scu);
98 }
99 
100 static inline uint32_t calculate_ticks(struct AspeedTimer *t, uint64_t now_ns)
101 {
102     uint64_t delta_ns = now_ns - MIN(now_ns, t->start);
103     uint32_t rate = calculate_rate(t);
104     uint64_t ticks = muldiv64(delta_ns, rate, NANOSECONDS_PER_SECOND);
105 
106     return t->reload - MIN(t->reload, ticks);
107 }
108 
109 static uint32_t calculate_min_ticks(AspeedTimer *t, uint32_t value)
110 {
111     uint32_t rate = calculate_rate(t);
112     uint32_t min_ticks = muldiv64(TIMER_MIN_NS, rate, NANOSECONDS_PER_SECOND);
113 
114     return  value < min_ticks ? min_ticks : value;
115 }
116 
117 static inline uint64_t calculate_time(struct AspeedTimer *t, uint32_t ticks)
118 {
119     uint64_t delta_ns;
120     uint64_t delta_ticks;
121 
122     delta_ticks = t->reload - MIN(t->reload, ticks);
123     delta_ns = muldiv64(delta_ticks, NANOSECONDS_PER_SECOND, calculate_rate(t));
124 
125     return t->start + delta_ns;
126 }
127 
128 static inline uint32_t calculate_match(struct AspeedTimer *t, int i)
129 {
130     return t->match[i] < t->reload ? t->match[i] : 0;
131 }
132 
133 static uint64_t calculate_next(struct AspeedTimer *t)
134 {
135     uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
136     uint64_t next;
137 
138     /*
139      * We don't know the relationship between the values in the match
140      * registers, so sort using MAX/MIN/zero. We sort in that order as
141      * the timer counts down to zero.
142      */
143 
144     next = calculate_time(t, MAX(calculate_match(t, 0), calculate_match(t, 1)));
145     if (now < next) {
146         return next;
147     }
148 
149     next = calculate_time(t, MIN(calculate_match(t, 0), calculate_match(t, 1)));
150     if (now < next) {
151         return next;
152     }
153 
154     next = calculate_time(t, 0);
155     if (now < next) {
156         return next;
157     }
158 
159     /* We've missed all deadlines, fire interrupt and try again */
160     timer_del(&t->timer);
161 
162     if (timer_overflow_interrupt(t)) {
163         t->level = !t->level;
164         qemu_set_irq(t->irq, t->level);
165     }
166 
167     next = MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0);
168     t->start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
169 
170     return calculate_time(t, next);
171 }
172 
173 static void aspeed_timer_mod(AspeedTimer *t)
174 {
175     uint64_t next = calculate_next(t);
176     if (next) {
177         timer_mod(&t->timer, next);
178     }
179 }
180 
181 static void aspeed_timer_expire(void *opaque)
182 {
183     AspeedTimer *t = opaque;
184     bool interrupt = false;
185     uint32_t ticks;
186 
187     if (!timer_enabled(t)) {
188         return;
189     }
190 
191     ticks = calculate_ticks(t, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
192 
193     if (!ticks) {
194         interrupt = timer_overflow_interrupt(t) || !t->match[0] || !t->match[1];
195     } else if (ticks <= MIN(t->match[0], t->match[1])) {
196         interrupt = true;
197     } else if (ticks <= MAX(t->match[0], t->match[1])) {
198         interrupt = true;
199     }
200 
201     if (interrupt) {
202         t->level = !t->level;
203         qemu_set_irq(t->irq, t->level);
204     }
205 
206     aspeed_timer_mod(t);
207 }
208 
209 static uint64_t aspeed_timer_get_value(AspeedTimer *t, int reg)
210 {
211     uint64_t value;
212 
213     switch (reg) {
214     case TIMER_REG_STATUS:
215         if (timer_enabled(t)) {
216             value = calculate_ticks(t, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
217         } else {
218             value = t->reload;
219         }
220         break;
221     case TIMER_REG_RELOAD:
222         value = t->reload;
223         break;
224     case TIMER_REG_MATCH_FIRST:
225     case TIMER_REG_MATCH_SECOND:
226         value = t->match[reg - 2];
227         break;
228     default:
229         qemu_log_mask(LOG_UNIMP, "%s: Programming error: unexpected reg: %d\n",
230                       __func__, reg);
231         value = 0;
232         break;
233     }
234     return value;
235 }
236 
237 static uint64_t aspeed_timer_read(void *opaque, hwaddr offset, unsigned size)
238 {
239     AspeedTimerCtrlState *s = opaque;
240     const int reg = (offset & 0xf) / 4;
241     uint64_t value;
242 
243     switch (offset) {
244     case 0x30: /* Control Register */
245         value = s->ctrl;
246         break;
247     case 0x34: /* Control Register 2 */
248         value = s->ctrl2;
249         break;
250     case 0x00 ... 0x2c: /* Timers 1 - 4 */
251         value = aspeed_timer_get_value(&s->timers[(offset >> 4)], reg);
252         break;
253     case 0x40 ... 0x8c: /* Timers 5 - 8 */
254         value = aspeed_timer_get_value(&s->timers[(offset >> 4) - 1], reg);
255         break;
256     default:
257         value = ASPEED_TIMER_GET_CLASS(s)->read(s, offset);
258         break;
259     }
260     trace_aspeed_timer_read(offset, size, value);
261     return value;
262 }
263 
264 static void aspeed_timer_set_value(AspeedTimerCtrlState *s, int timer, int reg,
265                                    uint32_t value)
266 {
267     AspeedTimer *t;
268     uint32_t old_reload;
269 
270     trace_aspeed_timer_set_value(timer, reg, value);
271     t = &s->timers[timer];
272     switch (reg) {
273     case TIMER_REG_RELOAD:
274         old_reload = t->reload;
275         t->reload = calculate_min_ticks(t, value);
276 
277         /* If the reload value was not previously set, or zero, and
278          * the current value is valid, try to start the timer if it is
279          * enabled.
280          */
281         if (old_reload || !t->reload) {
282             break;
283         }
284 
285     case TIMER_REG_STATUS:
286         if (timer_enabled(t)) {
287             uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
288             int64_t delta = (int64_t) value - (int64_t) calculate_ticks(t, now);
289             uint32_t rate = calculate_rate(t);
290 
291             if (delta >= 0) {
292                 t->start += muldiv64(delta, NANOSECONDS_PER_SECOND, rate);
293             } else {
294                 t->start -= muldiv64(-delta, NANOSECONDS_PER_SECOND, rate);
295             }
296             aspeed_timer_mod(t);
297         }
298         break;
299     case TIMER_REG_MATCH_FIRST:
300     case TIMER_REG_MATCH_SECOND:
301         t->match[reg - 2] = value;
302         if (timer_enabled(t)) {
303             aspeed_timer_mod(t);
304         }
305         break;
306     default:
307         qemu_log_mask(LOG_UNIMP, "%s: Programming error: unexpected reg: %d\n",
308                       __func__, reg);
309         break;
310     }
311 }
312 
313 /* Control register operations are broken out into helpers that can be
314  * explicitly called on aspeed_timer_reset(), but also from
315  * aspeed_timer_ctrl_op().
316  */
317 
318 static void aspeed_timer_ctrl_enable(AspeedTimer *t, bool enable)
319 {
320     trace_aspeed_timer_ctrl_enable(t->id, enable);
321     if (enable) {
322         t->start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
323         aspeed_timer_mod(t);
324     } else {
325         timer_del(&t->timer);
326     }
327 }
328 
329 static void aspeed_timer_ctrl_external_clock(AspeedTimer *t, bool enable)
330 {
331     trace_aspeed_timer_ctrl_external_clock(t->id, enable);
332 }
333 
334 static void aspeed_timer_ctrl_overflow_interrupt(AspeedTimer *t, bool enable)
335 {
336     trace_aspeed_timer_ctrl_overflow_interrupt(t->id, enable);
337 }
338 
339 static void aspeed_timer_ctrl_pulse_enable(AspeedTimer *t, bool enable)
340 {
341     if (timer_can_pulse(t)) {
342         trace_aspeed_timer_ctrl_pulse_enable(t->id, enable);
343     } else {
344         qemu_log_mask(LOG_GUEST_ERROR,
345                 "%s: Timer does not support pulse mode\n", __func__);
346     }
347 }
348 
349 /**
350  * Given the actions are fixed in number and completely described in helper
351  * functions, dispatch with a lookup table rather than manage control flow with
352  * a switch statement.
353  */
354 static void (*const ctrl_ops[])(AspeedTimer *, bool) = {
355     [op_enable] = aspeed_timer_ctrl_enable,
356     [op_external_clock] = aspeed_timer_ctrl_external_clock,
357     [op_overflow_interrupt] = aspeed_timer_ctrl_overflow_interrupt,
358     [op_pulse_enable] = aspeed_timer_ctrl_pulse_enable,
359 };
360 
361 /**
362  * Conditionally affect changes chosen by a timer's control bit.
363  *
364  * The aspeed_timer_ctrl_op() interface is convenient for the
365  * aspeed_timer_set_ctrl() function as the "no change" early exit can be
366  * calculated for all operations, which cleans up the caller code. However the
367  * interface isn't convenient for the reset function where we want to enter a
368  * specific state without artificially constructing old and new values that
369  * will fall through the change guard (and motivates extracting the actions
370  * out to helper functions).
371  *
372  * @t: The timer to manipulate
373  * @op: The type of operation to be performed
374  * @old: The old state of the timer's control bits
375  * @new: The incoming state for the timer's control bits
376  */
377 static void aspeed_timer_ctrl_op(AspeedTimer *t, enum timer_ctrl_op op,
378                                  uint8_t old, uint8_t new)
379 {
380     const uint8_t mask = BIT(op);
381     const bool enable = !!(new & mask);
382     const bool changed = ((old ^ new) & mask);
383     if (!changed) {
384         return;
385     }
386     ctrl_ops[op](t, enable);
387 }
388 
389 static void aspeed_timer_set_ctrl(AspeedTimerCtrlState *s, uint32_t reg)
390 {
391     int i;
392     int shift;
393     uint8_t t_old, t_new;
394     AspeedTimer *t;
395     const uint8_t enable_mask = BIT(op_enable);
396 
397     /* Handle a dependency between the 'enable' and remaining three
398      * configuration bits - i.e. if more than one bit in the control set has
399      * changed, including the 'enable' bit, then we want either disable the
400      * timer and perform configuration, or perform configuration and then
401      * enable the timer
402      */
403     for (i = 0; i < ASPEED_TIMER_NR_TIMERS; i++) {
404         t = &s->timers[i];
405         shift = (i * TIMER_CTRL_BITS);
406         t_old = (s->ctrl >> shift) & TIMER_CTRL_MASK;
407         t_new = (reg >> shift) & TIMER_CTRL_MASK;
408 
409         /* If we are disabling, do so first */
410         if ((t_old & enable_mask) && !(t_new & enable_mask)) {
411             aspeed_timer_ctrl_enable(t, false);
412         }
413         aspeed_timer_ctrl_op(t, op_external_clock, t_old, t_new);
414         aspeed_timer_ctrl_op(t, op_overflow_interrupt, t_old, t_new);
415         aspeed_timer_ctrl_op(t, op_pulse_enable, t_old, t_new);
416         /* If we are enabling, do so last */
417         if (!(t_old & enable_mask) && (t_new & enable_mask)) {
418             aspeed_timer_ctrl_enable(t, true);
419         }
420     }
421     s->ctrl = reg;
422 }
423 
424 static void aspeed_timer_set_ctrl2(AspeedTimerCtrlState *s, uint32_t value)
425 {
426     trace_aspeed_timer_set_ctrl2(value);
427 }
428 
429 static void aspeed_timer_write(void *opaque, hwaddr offset, uint64_t value,
430                                unsigned size)
431 {
432     const uint32_t tv = (uint32_t)(value & 0xFFFFFFFF);
433     const int reg = (offset & 0xf) / 4;
434     AspeedTimerCtrlState *s = opaque;
435 
436     switch (offset) {
437     /* Control Registers */
438     case 0x30:
439         aspeed_timer_set_ctrl(s, tv);
440         break;
441     case 0x34:
442         aspeed_timer_set_ctrl2(s, tv);
443         break;
444     /* Timer Registers */
445     case 0x00 ... 0x2c:
446         aspeed_timer_set_value(s, (offset >> TIMER_NR_REGS), reg, tv);
447         break;
448     case 0x40 ... 0x8c:
449         aspeed_timer_set_value(s, (offset >> TIMER_NR_REGS) - 1, reg, tv);
450         break;
451     default:
452         ASPEED_TIMER_GET_CLASS(s)->write(s, offset, value);
453         break;
454     }
455 }
456 
457 static const MemoryRegionOps aspeed_timer_ops = {
458     .read = aspeed_timer_read,
459     .write = aspeed_timer_write,
460     .endianness = DEVICE_LITTLE_ENDIAN,
461     .valid.min_access_size = 4,
462     .valid.max_access_size = 4,
463     .valid.unaligned = false,
464 };
465 
466 static uint64_t aspeed_2400_timer_read(AspeedTimerCtrlState *s, hwaddr offset)
467 {
468     uint64_t value;
469 
470     switch (offset) {
471     case 0x38:
472     case 0x3C:
473     default:
474         qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
475                 __func__, offset);
476         value = 0;
477         break;
478     }
479     return value;
480 }
481 
482 static void aspeed_2400_timer_write(AspeedTimerCtrlState *s, hwaddr offset,
483                                     uint64_t value)
484 {
485     switch (offset) {
486     case 0x38:
487     case 0x3C:
488     default:
489         qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
490                 __func__, offset);
491         break;
492     }
493 }
494 
495 static uint64_t aspeed_2500_timer_read(AspeedTimerCtrlState *s, hwaddr offset)
496 {
497     uint64_t value;
498 
499     switch (offset) {
500     case 0x38:
501         value = s->ctrl3 & BIT(0);
502         break;
503     case 0x3C:
504     default:
505         qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
506                 __func__, offset);
507         value = 0;
508         break;
509     }
510     return value;
511 }
512 
513 static void aspeed_2500_timer_write(AspeedTimerCtrlState *s, hwaddr offset,
514                                     uint64_t value)
515 {
516     const uint32_t tv = (uint32_t)(value & 0xFFFFFFFF);
517     uint8_t command;
518 
519     switch (offset) {
520     case 0x38:
521         command = (value >> 1) & 0xFF;
522         if (command == 0xAE) {
523             s->ctrl3 = 0x1;
524         } else if (command == 0xEA) {
525             s->ctrl3 = 0x0;
526         }
527         break;
528     case 0x3C:
529         if (s->ctrl3 & BIT(0)) {
530             aspeed_timer_set_ctrl(s, s->ctrl & ~tv);
531         }
532         break;
533 
534     default:
535         qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
536                 __func__, offset);
537         break;
538     }
539 }
540 
541 static uint64_t aspeed_2600_timer_read(AspeedTimerCtrlState *s, hwaddr offset)
542 {
543     uint64_t value;
544 
545     switch (offset) {
546     case 0x38:
547     case 0x3C:
548     default:
549         qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
550                 __func__, offset);
551         value = 0;
552         break;
553     }
554     return value;
555 }
556 
557 static void aspeed_2600_timer_write(AspeedTimerCtrlState *s, hwaddr offset,
558                                     uint64_t value)
559 {
560     const uint32_t tv = (uint32_t)(value & 0xFFFFFFFF);
561 
562     switch (offset) {
563     case 0x3C:
564         aspeed_timer_set_ctrl(s, s->ctrl & ~tv);
565         break;
566 
567     case 0x38:
568     default:
569         qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
570                 __func__, offset);
571         break;
572     }
573 }
574 
575 static void aspeed_init_one_timer(AspeedTimerCtrlState *s, uint8_t id)
576 {
577     AspeedTimer *t = &s->timers[id];
578 
579     t->id = id;
580     timer_init_ns(&t->timer, QEMU_CLOCK_VIRTUAL, aspeed_timer_expire, t);
581 }
582 
583 static void aspeed_timer_realize(DeviceState *dev, Error **errp)
584 {
585     int i;
586     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
587     AspeedTimerCtrlState *s = ASPEED_TIMER(dev);
588     Object *obj;
589     Error *err = NULL;
590 
591     obj = object_property_get_link(OBJECT(dev), "scu", &err);
592     if (!obj) {
593         error_propagate_prepend(errp, err, "required link 'scu' not found: ");
594         return;
595     }
596     s->scu = ASPEED_SCU(obj);
597 
598     for (i = 0; i < ASPEED_TIMER_NR_TIMERS; i++) {
599         aspeed_init_one_timer(s, i);
600         sysbus_init_irq(sbd, &s->timers[i].irq);
601     }
602     memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_timer_ops, s,
603                           TYPE_ASPEED_TIMER, 0x1000);
604     sysbus_init_mmio(sbd, &s->iomem);
605 }
606 
607 static void aspeed_timer_reset(DeviceState *dev)
608 {
609     int i;
610     AspeedTimerCtrlState *s = ASPEED_TIMER(dev);
611 
612     for (i = 0; i < ASPEED_TIMER_NR_TIMERS; i++) {
613         AspeedTimer *t = &s->timers[i];
614         /* Explicitly call helpers to avoid any conditional behaviour through
615          * aspeed_timer_set_ctrl().
616          */
617         aspeed_timer_ctrl_enable(t, false);
618         aspeed_timer_ctrl_external_clock(t, TIMER_CLOCK_USE_APB);
619         aspeed_timer_ctrl_overflow_interrupt(t, false);
620         aspeed_timer_ctrl_pulse_enable(t, false);
621         t->level = 0;
622         t->reload = 0;
623         t->match[0] = 0;
624         t->match[1] = 0;
625     }
626     s->ctrl = 0;
627     s->ctrl2 = 0;
628     s->ctrl3 = 0;
629 }
630 
631 static const VMStateDescription vmstate_aspeed_timer = {
632     .name = "aspeed.timer",
633     .version_id = 2,
634     .minimum_version_id = 2,
635     .fields = (VMStateField[]) {
636         VMSTATE_UINT8(id, AspeedTimer),
637         VMSTATE_INT32(level, AspeedTimer),
638         VMSTATE_TIMER(timer, AspeedTimer),
639         VMSTATE_UINT32(reload, AspeedTimer),
640         VMSTATE_UINT32_ARRAY(match, AspeedTimer, 2),
641         VMSTATE_END_OF_LIST()
642     }
643 };
644 
645 static const VMStateDescription vmstate_aspeed_timer_state = {
646     .name = "aspeed.timerctrl",
647     .version_id = 1,
648     .minimum_version_id = 1,
649     .fields = (VMStateField[]) {
650         VMSTATE_UINT32(ctrl, AspeedTimerCtrlState),
651         VMSTATE_UINT32(ctrl2, AspeedTimerCtrlState),
652         VMSTATE_UINT32(ctrl3, AspeedTimerCtrlState),
653         VMSTATE_STRUCT_ARRAY(timers, AspeedTimerCtrlState,
654                              ASPEED_TIMER_NR_TIMERS, 1, vmstate_aspeed_timer,
655                              AspeedTimer),
656         VMSTATE_END_OF_LIST()
657     }
658 };
659 
660 static void timer_class_init(ObjectClass *klass, void *data)
661 {
662     DeviceClass *dc = DEVICE_CLASS(klass);
663 
664     dc->realize = aspeed_timer_realize;
665     dc->reset = aspeed_timer_reset;
666     dc->desc = "ASPEED Timer";
667     dc->vmsd = &vmstate_aspeed_timer_state;
668 }
669 
670 static const TypeInfo aspeed_timer_info = {
671     .name = TYPE_ASPEED_TIMER,
672     .parent = TYPE_SYS_BUS_DEVICE,
673     .instance_size = sizeof(AspeedTimerCtrlState),
674     .class_init = timer_class_init,
675     .class_size = sizeof(AspeedTimerClass),
676     .abstract   = true,
677 };
678 
679 static void aspeed_2400_timer_class_init(ObjectClass *klass, void *data)
680 {
681     DeviceClass *dc = DEVICE_CLASS(klass);
682     AspeedTimerClass *awc = ASPEED_TIMER_CLASS(klass);
683 
684     dc->desc = "ASPEED 2400 Timer";
685     awc->read = aspeed_2400_timer_read;
686     awc->write = aspeed_2400_timer_write;
687 }
688 
689 static const TypeInfo aspeed_2400_timer_info = {
690     .name = TYPE_ASPEED_2400_TIMER,
691     .parent = TYPE_ASPEED_TIMER,
692     .class_init = aspeed_2400_timer_class_init,
693 };
694 
695 static void aspeed_2500_timer_class_init(ObjectClass *klass, void *data)
696 {
697     DeviceClass *dc = DEVICE_CLASS(klass);
698     AspeedTimerClass *awc = ASPEED_TIMER_CLASS(klass);
699 
700     dc->desc = "ASPEED 2500 Timer";
701     awc->read = aspeed_2500_timer_read;
702     awc->write = aspeed_2500_timer_write;
703 }
704 
705 static const TypeInfo aspeed_2500_timer_info = {
706     .name = TYPE_ASPEED_2500_TIMER,
707     .parent = TYPE_ASPEED_TIMER,
708     .class_init = aspeed_2500_timer_class_init,
709 };
710 
711 static void aspeed_2600_timer_class_init(ObjectClass *klass, void *data)
712 {
713     DeviceClass *dc = DEVICE_CLASS(klass);
714     AspeedTimerClass *awc = ASPEED_TIMER_CLASS(klass);
715 
716     dc->desc = "ASPEED 2600 Timer";
717     awc->read = aspeed_2600_timer_read;
718     awc->write = aspeed_2600_timer_write;
719 }
720 
721 static const TypeInfo aspeed_2600_timer_info = {
722     .name = TYPE_ASPEED_2600_TIMER,
723     .parent = TYPE_ASPEED_TIMER,
724     .class_init = aspeed_2600_timer_class_init,
725 };
726 
727 static void aspeed_timer_register_types(void)
728 {
729     type_register_static(&aspeed_timer_info);
730     type_register_static(&aspeed_2400_timer_info);
731     type_register_static(&aspeed_2500_timer_info);
732     type_register_static(&aspeed_2600_timer_info);
733 }
734 
735 type_init(aspeed_timer_register_types)
736