[RFC,qemu,legoater/aspeed-3.1,2/4] timer: aspeed: Status register contains reload for stopped timer

Message ID 20190111035638.19725-3-andrew@aj.id.au
State Not Applicable, archived
Headers show
Series
  • Handle short timer periods
Related show

Commit Message

Andrew Jeffery Jan. 11, 2019, 3:56 a.m.
From the datasheet:

> This register stores the current status of counter #N. When timer
> enable bit TMC30[N * b] is disabled, the reload register will be
> loaded into this counter. When timer bit TMC30[N * b] is set, the
> counter will start to decrement. CPU can update this register value
> when enable bit is set.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 hw/timer/aspeed_timer.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Cédric Le Goater Jan. 11, 2019, 9:58 a.m. | #1
On 1/11/19 4:56 AM, Andrew Jeffery wrote:
> From the datasheet:
> 
>> This register stores the current status of counter #N. When timer
>> enable bit TMC30[N * b] is disabled, the reload register will be
>> loaded into this counter. When timer bit TMC30[N * b] is set, the
>> counter will start to decrement. CPU can update this register value
>> when enable bit is set.
> 
> Signed-off-by: Andrew Jeffery <andrew@aj.id.au>


Reviewed-by: Cédric Le Goater <clg@kaod.org>

Thanks,

C.

> ---
>  hw/timer/aspeed_timer.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
> index 54c75bf4f322..6adc14d62034 100644
> --- a/hw/timer/aspeed_timer.c
> +++ b/hw/timer/aspeed_timer.c
> @@ -182,7 +182,11 @@ static uint64_t aspeed_timer_get_value(AspeedTimer *t, int reg)
>  
>      switch (reg) {
>      case TIMER_REG_STATUS:
> -        value = calculate_ticks(t, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
> +        if (timer_enabled(t)) {
> +            value = calculate_ticks(t, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
> +        } else {
> +            value = t->reload;
> +        }
>          break;
>      case TIMER_REG_RELOAD:
>          value = t->reload;
>

Patch

diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
index 54c75bf4f322..6adc14d62034 100644
--- a/hw/timer/aspeed_timer.c
+++ b/hw/timer/aspeed_timer.c
@@ -182,7 +182,11 @@  static uint64_t aspeed_timer_get_value(AspeedTimer *t, int reg)
 
     switch (reg) {
     case TIMER_REG_STATUS:
-        value = calculate_ticks(t, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+        if (timer_enabled(t)) {
+            value = calculate_ticks(t, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+        } else {
+            value = t->reload;
+        }
         break;
     case TIMER_REG_RELOAD:
         value = t->reload;