Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / include / hw / timer / npcm7xx_timer.h
blobd45c051b56a998b6ce2d88a88bfa27d42ef1fc50
1 /*
2 * Nuvoton NPCM7xx Timer Controller
4 * Copyright 2020 Google LLC
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
16 #ifndef NPCM7XX_TIMER_H
17 #define NPCM7XX_TIMER_H
19 #include "exec/memory.h"
20 #include "hw/sysbus.h"
21 #include "qemu/timer.h"
23 /* Each Timer Module (TIM) instance holds five 25 MHz timers. */
24 #define NPCM7XX_TIMERS_PER_CTRL (5)
27 * Number of registers in our device state structure. Don't change this without
28 * incrementing the version_id in the vmstate.
30 #define NPCM7XX_TIMER_NR_REGS (0x54 / sizeof(uint32_t))
32 /* The basic watchdog timer period is 2^14 clock cycles. */
33 #define NPCM7XX_WATCHDOG_BASETIME_SHIFT 14
35 #define NPCM7XX_WATCHDOG_RESET_GPIO_OUT "npcm7xx-clk-watchdog-reset-gpio-out"
37 typedef struct NPCM7xxTimerCtrlState NPCM7xxTimerCtrlState;
39 /**
40 * struct NPCM7xxBaseTimer - Basic functionality that both regular timer and
41 * watchdog timer use.
42 * @qtimer: QEMU timer that notifies us on expiration.
43 * @expires_ns: Absolute virtual expiration time.
44 * @remaining_ns: Remaining time until expiration if timer is paused.
46 typedef struct NPCM7xxBaseTimer {
47 QEMUTimer qtimer;
48 int64_t expires_ns;
49 int64_t remaining_ns;
50 } NPCM7xxBaseTimer;
52 /**
53 * struct NPCM7xxTimer - Individual timer state.
54 * @ctrl: The timer module that owns this timer.
55 * @irq: GIC interrupt line to fire on expiration (if enabled).
56 * @base_timer: The basic timer functionality for this timer.
57 * @tcsr: The Timer Control and Status Register.
58 * @ticr: The Timer Initial Count Register.
60 typedef struct NPCM7xxTimer {
61 NPCM7xxTimerCtrlState *ctrl;
63 qemu_irq irq;
64 NPCM7xxBaseTimer base_timer;
66 uint32_t tcsr;
67 uint32_t ticr;
68 } NPCM7xxTimer;
70 /**
71 * struct NPCM7xxWatchdogTimer - The watchdog timer state.
72 * @ctrl: The timer module that owns this timer.
73 * @irq: GIC interrupt line to fire on expiration (if enabled).
74 * @reset_signal: The GPIO used to send a reset signal.
75 * @base_timer: The basic timer functionality for this timer.
76 * @wtcr: The Watchdog Timer Control Register.
78 typedef struct NPCM7xxWatchdogTimer {
79 NPCM7xxTimerCtrlState *ctrl;
81 qemu_irq irq;
82 qemu_irq reset_signal;
83 NPCM7xxBaseTimer base_timer;
85 uint32_t wtcr;
86 } NPCM7xxWatchdogTimer;
88 /**
89 * struct NPCM7xxTimerCtrlState - Timer Module device state.
90 * @parent: System bus device.
91 * @iomem: Memory region through which registers are accessed.
92 * @index: The index of this timer module.
93 * @tisr: The Timer Interrupt Status Register.
94 * @timer: The five individual timers managed by this module.
95 * @watchdog_timer: The watchdog timer managed by this module.
97 struct NPCM7xxTimerCtrlState {
98 SysBusDevice parent;
100 MemoryRegion iomem;
102 uint32_t tisr;
104 Clock *clock;
105 NPCM7xxTimer timer[NPCM7XX_TIMERS_PER_CTRL];
106 NPCM7xxWatchdogTimer watchdog_timer;
109 #define TYPE_NPCM7XX_TIMER "npcm7xx-timer"
110 #define NPCM7XX_TIMER(obj) \
111 OBJECT_CHECK(NPCM7xxTimerCtrlState, (obj), TYPE_NPCM7XX_TIMER)
113 #endif /* NPCM7XX_TIMER_H */