2007-04-30 09:48:07 +08:00
|
|
|
/*
|
|
|
|
* Intel XScale PXA255/270 OS Timers.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Openedhand Ltd.
|
|
|
|
* Copyright (c) 2006 Thorsten Zitterell
|
|
|
|
*
|
2011-06-26 10:21:35 +08:00
|
|
|
* This code is licensed under the GPL.
|
2007-04-30 09:48:07 +08:00
|
|
|
*/
|
|
|
|
|
2007-11-18 01:14:51 +08:00
|
|
|
#include "hw.h"
|
2012-12-18 01:20:00 +08:00
|
|
|
#include "qemu/timer.h"
|
2012-12-18 01:20:04 +08:00
|
|
|
#include "sysemu/sysemu.h"
|
2007-11-18 01:14:51 +08:00
|
|
|
#include "pxa.h"
|
2011-03-03 21:14:44 +08:00
|
|
|
#include "sysbus.h"
|
2007-04-30 09:48:07 +08:00
|
|
|
|
|
|
|
#define OSMR0 0x00
|
|
|
|
#define OSMR1 0x04
|
|
|
|
#define OSMR2 0x08
|
|
|
|
#define OSMR3 0x0c
|
|
|
|
#define OSMR4 0x80
|
|
|
|
#define OSMR5 0x84
|
|
|
|
#define OSMR6 0x88
|
|
|
|
#define OSMR7 0x8c
|
|
|
|
#define OSMR8 0x90
|
|
|
|
#define OSMR9 0x94
|
|
|
|
#define OSMR10 0x98
|
|
|
|
#define OSMR11 0x9c
|
|
|
|
#define OSCR 0x10 /* OS Timer Count */
|
|
|
|
#define OSCR4 0x40
|
|
|
|
#define OSCR5 0x44
|
|
|
|
#define OSCR6 0x48
|
|
|
|
#define OSCR7 0x4c
|
|
|
|
#define OSCR8 0x50
|
|
|
|
#define OSCR9 0x54
|
|
|
|
#define OSCR10 0x58
|
|
|
|
#define OSCR11 0x5c
|
|
|
|
#define OSSR 0x14 /* Timer status register */
|
|
|
|
#define OWER 0x18
|
|
|
|
#define OIER 0x1c /* Interrupt enable register 3-0 to E3-E0 */
|
|
|
|
#define OMCR4 0xc0 /* OS Match Control registers */
|
|
|
|
#define OMCR5 0xc4
|
|
|
|
#define OMCR6 0xc8
|
|
|
|
#define OMCR7 0xcc
|
|
|
|
#define OMCR8 0xd0
|
|
|
|
#define OMCR9 0xd4
|
|
|
|
#define OMCR10 0xd8
|
|
|
|
#define OMCR11 0xdc
|
|
|
|
#define OSNR 0x20
|
|
|
|
|
|
|
|
#define PXA25X_FREQ 3686400 /* 3.6864 MHz */
|
|
|
|
#define PXA27X_FREQ 3250000 /* 3.25 MHz */
|
|
|
|
|
|
|
|
static int pxa2xx_timer4_freq[8] = {
|
|
|
|
[0] = 0,
|
|
|
|
[1] = 32768,
|
|
|
|
[2] = 1000,
|
|
|
|
[3] = 1,
|
|
|
|
[4] = 1000000,
|
|
|
|
/* [5] is the "Externally supplied clock". Assign if necessary. */
|
|
|
|
[5 ... 7] = 0,
|
|
|
|
};
|
|
|
|
|
2011-03-03 21:14:44 +08:00
|
|
|
typedef struct PXA2xxTimerInfo PXA2xxTimerInfo;
|
|
|
|
|
2009-05-10 08:44:56 +08:00
|
|
|
typedef struct {
|
2007-04-30 09:48:07 +08:00
|
|
|
uint32_t value;
|
2011-03-03 21:24:25 +08:00
|
|
|
qemu_irq irq;
|
2007-04-30 09:48:07 +08:00
|
|
|
QEMUTimer *qtimer;
|
|
|
|
int num;
|
2011-03-03 21:14:44 +08:00
|
|
|
PXA2xxTimerInfo *info;
|
2009-05-10 08:44:56 +08:00
|
|
|
} PXA2xxTimer0;
|
2007-04-30 09:48:07 +08:00
|
|
|
|
2009-05-10 08:44:56 +08:00
|
|
|
typedef struct {
|
|
|
|
PXA2xxTimer0 tm;
|
2007-04-30 09:48:07 +08:00
|
|
|
int32_t oldclock;
|
|
|
|
int32_t clock;
|
|
|
|
uint64_t lastload;
|
|
|
|
uint32_t freq;
|
|
|
|
uint32_t control;
|
2009-05-10 08:44:56 +08:00
|
|
|
} PXA2xxTimer4;
|
2007-04-30 09:48:07 +08:00
|
|
|
|
2011-03-03 21:14:44 +08:00
|
|
|
struct PXA2xxTimerInfo {
|
|
|
|
SysBusDevice busdev;
|
2011-10-30 21:50:16 +08:00
|
|
|
MemoryRegion iomem;
|
2011-03-03 21:14:44 +08:00
|
|
|
uint32_t flags;
|
|
|
|
|
2007-04-30 09:48:07 +08:00
|
|
|
int32_t clock;
|
|
|
|
int32_t oldclock;
|
|
|
|
uint64_t lastload;
|
|
|
|
uint32_t freq;
|
2009-05-10 08:44:56 +08:00
|
|
|
PXA2xxTimer0 timer[4];
|
2007-04-30 09:48:07 +08:00
|
|
|
uint32_t events;
|
|
|
|
uint32_t irq_enabled;
|
|
|
|
uint32_t reset3;
|
|
|
|
uint32_t snapshot;
|
2011-03-03 21:14:44 +08:00
|
|
|
|
2011-03-04 08:40:59 +08:00
|
|
|
qemu_irq irq4;
|
2011-03-03 21:14:44 +08:00
|
|
|
PXA2xxTimer4 tm4[8];
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PXA2XX_TIMER_HAVE_TM4 0
|
|
|
|
|
|
|
|
static inline int pxa2xx_timer_has_tm4(PXA2xxTimerInfo *s)
|
|
|
|
{
|
|
|
|
return s->flags & (1 << PXA2XX_TIMER_HAVE_TM4);
|
|
|
|
}
|
2007-04-30 09:48:07 +08:00
|
|
|
|
|
|
|
static void pxa2xx_timer_update(void *opaque, uint64_t now_qemu)
|
|
|
|
{
|
2011-02-20 21:50:33 +08:00
|
|
|
PXA2xxTimerInfo *s = (PXA2xxTimerInfo *) opaque;
|
2007-04-30 09:48:07 +08:00
|
|
|
int i;
|
|
|
|
uint32_t now_vm;
|
|
|
|
uint64_t new_qemu;
|
|
|
|
|
|
|
|
now_vm = s->clock +
|
2009-09-10 09:04:26 +08:00
|
|
|
muldiv64(now_qemu - s->lastload, s->freq, get_ticks_per_sec());
|
2007-04-30 09:48:07 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i ++) {
|
|
|
|
new_qemu = now_qemu + muldiv64((uint32_t) (s->timer[i].value - now_vm),
|
2009-09-10 09:04:26 +08:00
|
|
|
get_ticks_per_sec(), s->freq);
|
2007-04-30 09:48:07 +08:00
|
|
|
qemu_mod_timer(s->timer[i].qtimer, new_qemu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pxa2xx_timer_update4(void *opaque, uint64_t now_qemu, int n)
|
|
|
|
{
|
2011-02-20 21:50:33 +08:00
|
|
|
PXA2xxTimerInfo *s = (PXA2xxTimerInfo *) opaque;
|
2007-04-30 09:48:07 +08:00
|
|
|
uint32_t now_vm;
|
|
|
|
uint64_t new_qemu;
|
|
|
|
static const int counters[8] = { 0, 0, 0, 0, 4, 4, 6, 6 };
|
|
|
|
int counter;
|
|
|
|
|
|
|
|
if (s->tm4[n].control & (1 << 7))
|
|
|
|
counter = n;
|
|
|
|
else
|
|
|
|
counter = counters[n];
|
|
|
|
|
|
|
|
if (!s->tm4[counter].freq) {
|
2007-05-24 05:47:51 +08:00
|
|
|
qemu_del_timer(s->tm4[n].tm.qtimer);
|
2007-04-30 09:48:07 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
now_vm = s->tm4[counter].clock + muldiv64(now_qemu -
|
|
|
|
s->tm4[counter].lastload,
|
2009-09-10 09:04:26 +08:00
|
|
|
s->tm4[counter].freq, get_ticks_per_sec());
|
2007-04-30 09:48:07 +08:00
|
|
|
|
2007-05-09 06:51:00 +08:00
|
|
|
new_qemu = now_qemu + muldiv64((uint32_t) (s->tm4[n].tm.value - now_vm),
|
2009-09-10 09:04:26 +08:00
|
|
|
get_ticks_per_sec(), s->tm4[counter].freq);
|
2007-05-24 05:47:51 +08:00
|
|
|
qemu_mod_timer(s->tm4[n].tm.qtimer, new_qemu);
|
2007-04-30 09:48:07 +08:00
|
|
|
}
|
|
|
|
|
2012-10-23 18:30:10 +08:00
|
|
|
static uint64_t pxa2xx_timer_read(void *opaque, hwaddr offset,
|
2011-10-30 21:50:16 +08:00
|
|
|
unsigned size)
|
2007-04-30 09:48:07 +08:00
|
|
|
{
|
2011-02-20 21:50:33 +08:00
|
|
|
PXA2xxTimerInfo *s = (PXA2xxTimerInfo *) opaque;
|
2007-04-30 09:48:07 +08:00
|
|
|
int tm = 0;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case OSMR3: tm ++;
|
|
|
|
case OSMR2: tm ++;
|
|
|
|
case OSMR1: tm ++;
|
|
|
|
case OSMR0:
|
|
|
|
return s->timer[tm].value;
|
|
|
|
case OSMR11: tm ++;
|
|
|
|
case OSMR10: tm ++;
|
|
|
|
case OSMR9: tm ++;
|
|
|
|
case OSMR8: tm ++;
|
|
|
|
case OSMR7: tm ++;
|
|
|
|
case OSMR6: tm ++;
|
|
|
|
case OSMR5: tm ++;
|
|
|
|
case OSMR4:
|
2011-03-03 21:14:44 +08:00
|
|
|
if (!pxa2xx_timer_has_tm4(s))
|
2007-04-30 09:48:07 +08:00
|
|
|
goto badreg;
|
2007-05-09 06:51:00 +08:00
|
|
|
return s->tm4[tm].tm.value;
|
2007-04-30 09:48:07 +08:00
|
|
|
case OSCR:
|
2011-03-11 23:47:48 +08:00
|
|
|
return s->clock + muldiv64(qemu_get_clock_ns(vm_clock) -
|
2009-09-10 09:04:26 +08:00
|
|
|
s->lastload, s->freq, get_ticks_per_sec());
|
2007-04-30 09:48:07 +08:00
|
|
|
case OSCR11: tm ++;
|
|
|
|
case OSCR10: tm ++;
|
|
|
|
case OSCR9: tm ++;
|
|
|
|
case OSCR8: tm ++;
|
|
|
|
case OSCR7: tm ++;
|
|
|
|
case OSCR6: tm ++;
|
|
|
|
case OSCR5: tm ++;
|
|
|
|
case OSCR4:
|
2011-03-03 21:14:44 +08:00
|
|
|
if (!pxa2xx_timer_has_tm4(s))
|
2007-04-30 09:48:07 +08:00
|
|
|
goto badreg;
|
|
|
|
|
|
|
|
if ((tm == 9 - 4 || tm == 11 - 4) && (s->tm4[tm].control & (1 << 9))) {
|
|
|
|
if (s->tm4[tm - 1].freq)
|
|
|
|
s->snapshot = s->tm4[tm - 1].clock + muldiv64(
|
2011-03-11 23:47:48 +08:00
|
|
|
qemu_get_clock_ns(vm_clock) -
|
2007-04-30 09:48:07 +08:00
|
|
|
s->tm4[tm - 1].lastload,
|
2009-09-10 09:04:26 +08:00
|
|
|
s->tm4[tm - 1].freq, get_ticks_per_sec());
|
2007-04-30 09:48:07 +08:00
|
|
|
else
|
|
|
|
s->snapshot = s->tm4[tm - 1].clock;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!s->tm4[tm].freq)
|
|
|
|
return s->tm4[tm].clock;
|
2011-03-11 23:47:48 +08:00
|
|
|
return s->tm4[tm].clock + muldiv64(qemu_get_clock_ns(vm_clock) -
|
2009-09-10 09:04:26 +08:00
|
|
|
s->tm4[tm].lastload, s->tm4[tm].freq, get_ticks_per_sec());
|
2007-04-30 09:48:07 +08:00
|
|
|
case OIER:
|
|
|
|
return s->irq_enabled;
|
|
|
|
case OSSR: /* Status register */
|
|
|
|
return s->events;
|
|
|
|
case OWER:
|
|
|
|
return s->reset3;
|
|
|
|
case OMCR11: tm ++;
|
|
|
|
case OMCR10: tm ++;
|
|
|
|
case OMCR9: tm ++;
|
|
|
|
case OMCR8: tm ++;
|
|
|
|
case OMCR7: tm ++;
|
|
|
|
case OMCR6: tm ++;
|
|
|
|
case OMCR5: tm ++;
|
|
|
|
case OMCR4:
|
2011-03-03 21:14:44 +08:00
|
|
|
if (!pxa2xx_timer_has_tm4(s))
|
2007-04-30 09:48:07 +08:00
|
|
|
goto badreg;
|
|
|
|
return s->tm4[tm].control;
|
|
|
|
case OSNR:
|
|
|
|
return s->snapshot;
|
|
|
|
default:
|
|
|
|
badreg:
|
2009-05-08 09:35:15 +08:00
|
|
|
hw_error("pxa2xx_timer_read: Bad offset " REG_FMT "\n", offset);
|
2007-04-30 09:48:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-23 18:30:10 +08:00
|
|
|
static void pxa2xx_timer_write(void *opaque, hwaddr offset,
|
2011-10-30 21:50:16 +08:00
|
|
|
uint64_t value, unsigned size)
|
2007-04-30 09:48:07 +08:00
|
|
|
{
|
|
|
|
int i, tm = 0;
|
2011-02-20 21:50:33 +08:00
|
|
|
PXA2xxTimerInfo *s = (PXA2xxTimerInfo *) opaque;
|
2007-04-30 09:48:07 +08:00
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case OSMR3: tm ++;
|
|
|
|
case OSMR2: tm ++;
|
|
|
|
case OSMR1: tm ++;
|
|
|
|
case OSMR0:
|
|
|
|
s->timer[tm].value = value;
|
2011-03-11 23:47:48 +08:00
|
|
|
pxa2xx_timer_update(s, qemu_get_clock_ns(vm_clock));
|
2007-04-30 09:48:07 +08:00
|
|
|
break;
|
|
|
|
case OSMR11: tm ++;
|
|
|
|
case OSMR10: tm ++;
|
|
|
|
case OSMR9: tm ++;
|
|
|
|
case OSMR8: tm ++;
|
|
|
|
case OSMR7: tm ++;
|
|
|
|
case OSMR6: tm ++;
|
|
|
|
case OSMR5: tm ++;
|
|
|
|
case OSMR4:
|
2011-03-03 21:14:44 +08:00
|
|
|
if (!pxa2xx_timer_has_tm4(s))
|
2007-04-30 09:48:07 +08:00
|
|
|
goto badreg;
|
2007-05-09 06:51:00 +08:00
|
|
|
s->tm4[tm].tm.value = value;
|
2011-03-11 23:47:48 +08:00
|
|
|
pxa2xx_timer_update4(s, qemu_get_clock_ns(vm_clock), tm);
|
2007-04-30 09:48:07 +08:00
|
|
|
break;
|
|
|
|
case OSCR:
|
|
|
|
s->oldclock = s->clock;
|
2011-03-11 23:47:48 +08:00
|
|
|
s->lastload = qemu_get_clock_ns(vm_clock);
|
2007-04-30 09:48:07 +08:00
|
|
|
s->clock = value;
|
|
|
|
pxa2xx_timer_update(s, s->lastload);
|
|
|
|
break;
|
|
|
|
case OSCR11: tm ++;
|
|
|
|
case OSCR10: tm ++;
|
|
|
|
case OSCR9: tm ++;
|
|
|
|
case OSCR8: tm ++;
|
|
|
|
case OSCR7: tm ++;
|
|
|
|
case OSCR6: tm ++;
|
|
|
|
case OSCR5: tm ++;
|
|
|
|
case OSCR4:
|
2011-03-03 21:14:44 +08:00
|
|
|
if (!pxa2xx_timer_has_tm4(s))
|
2007-04-30 09:48:07 +08:00
|
|
|
goto badreg;
|
|
|
|
s->tm4[tm].oldclock = s->tm4[tm].clock;
|
2011-03-11 23:47:48 +08:00
|
|
|
s->tm4[tm].lastload = qemu_get_clock_ns(vm_clock);
|
2007-04-30 09:48:07 +08:00
|
|
|
s->tm4[tm].clock = value;
|
|
|
|
pxa2xx_timer_update4(s, s->tm4[tm].lastload, tm);
|
|
|
|
break;
|
|
|
|
case OIER:
|
|
|
|
s->irq_enabled = value & 0xfff;
|
|
|
|
break;
|
|
|
|
case OSSR: /* Status register */
|
2011-03-10 10:31:02 +08:00
|
|
|
value &= s->events;
|
2007-04-30 09:48:07 +08:00
|
|
|
s->events &= ~value;
|
2011-03-10 10:31:02 +08:00
|
|
|
for (i = 0; i < 4; i ++, value >>= 1)
|
|
|
|
if (value & 1)
|
2011-03-03 21:24:25 +08:00
|
|
|
qemu_irq_lower(s->timer[i].irq);
|
2011-03-10 10:31:02 +08:00
|
|
|
if (pxa2xx_timer_has_tm4(s) && !(s->events & 0xff0) && value)
|
|
|
|
qemu_irq_lower(s->irq4);
|
2007-04-30 09:48:07 +08:00
|
|
|
break;
|
|
|
|
case OWER: /* XXX: Reset on OSMR3 match? */
|
|
|
|
s->reset3 = value;
|
|
|
|
break;
|
|
|
|
case OMCR7: tm ++;
|
|
|
|
case OMCR6: tm ++;
|
|
|
|
case OMCR5: tm ++;
|
|
|
|
case OMCR4:
|
2011-03-03 21:14:44 +08:00
|
|
|
if (!pxa2xx_timer_has_tm4(s))
|
2007-04-30 09:48:07 +08:00
|
|
|
goto badreg;
|
|
|
|
s->tm4[tm].control = value & 0x0ff;
|
|
|
|
/* XXX Stop if running (shouldn't happen) */
|
|
|
|
if ((value & (1 << 7)) || tm == 0)
|
|
|
|
s->tm4[tm].freq = pxa2xx_timer4_freq[value & 7];
|
|
|
|
else {
|
|
|
|
s->tm4[tm].freq = 0;
|
2011-03-11 23:47:48 +08:00
|
|
|
pxa2xx_timer_update4(s, qemu_get_clock_ns(vm_clock), tm);
|
2007-04-30 09:48:07 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OMCR11: tm ++;
|
|
|
|
case OMCR10: tm ++;
|
|
|
|
case OMCR9: tm ++;
|
|
|
|
case OMCR8: tm += 4;
|
2011-03-03 21:14:44 +08:00
|
|
|
if (!pxa2xx_timer_has_tm4(s))
|
2007-04-30 09:48:07 +08:00
|
|
|
goto badreg;
|
|
|
|
s->tm4[tm].control = value & 0x3ff;
|
|
|
|
/* XXX Stop if running (shouldn't happen) */
|
|
|
|
if ((value & (1 << 7)) || !(tm & 1))
|
|
|
|
s->tm4[tm].freq =
|
|
|
|
pxa2xx_timer4_freq[(value & (1 << 8)) ? 0 : (value & 7)];
|
|
|
|
else {
|
|
|
|
s->tm4[tm].freq = 0;
|
2011-03-11 23:47:48 +08:00
|
|
|
pxa2xx_timer_update4(s, qemu_get_clock_ns(vm_clock), tm);
|
2007-04-30 09:48:07 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
badreg:
|
2009-05-08 09:35:15 +08:00
|
|
|
hw_error("pxa2xx_timer_write: Bad offset " REG_FMT "\n", offset);
|
2007-04-30 09:48:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-30 21:50:16 +08:00
|
|
|
static const MemoryRegionOps pxa2xx_timer_ops = {
|
|
|
|
.read = pxa2xx_timer_read,
|
|
|
|
.write = pxa2xx_timer_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2007-04-30 09:48:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void pxa2xx_timer_tick(void *opaque)
|
|
|
|
{
|
2009-05-10 08:44:56 +08:00
|
|
|
PXA2xxTimer0 *t = (PXA2xxTimer0 *) opaque;
|
2011-03-03 21:14:44 +08:00
|
|
|
PXA2xxTimerInfo *i = t->info;
|
2007-04-30 09:48:07 +08:00
|
|
|
|
|
|
|
if (i->irq_enabled & (1 << t->num)) {
|
|
|
|
i->events |= 1 << t->num;
|
2011-03-03 21:24:25 +08:00
|
|
|
qemu_irq_raise(t->irq);
|
2007-04-30 09:48:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (t->num == 3)
|
|
|
|
if (i->reset3 & 1) {
|
|
|
|
i->reset3 = 0;
|
2007-05-24 05:47:51 +08:00
|
|
|
qemu_system_reset_request();
|
2007-04-30 09:48:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pxa2xx_timer_tick4(void *opaque)
|
|
|
|
{
|
2009-05-10 08:44:56 +08:00
|
|
|
PXA2xxTimer4 *t = (PXA2xxTimer4 *) opaque;
|
2011-02-20 21:50:33 +08:00
|
|
|
PXA2xxTimerInfo *i = (PXA2xxTimerInfo *) t->tm.info;
|
2007-04-30 09:48:07 +08:00
|
|
|
|
2007-05-09 06:51:00 +08:00
|
|
|
pxa2xx_timer_tick(&t->tm);
|
2007-04-30 09:48:07 +08:00
|
|
|
if (t->control & (1 << 3))
|
|
|
|
t->clock = 0;
|
|
|
|
if (t->control & (1 << 6))
|
2011-03-11 23:47:48 +08:00
|
|
|
pxa2xx_timer_update4(i, qemu_get_clock_ns(vm_clock), t->tm.num - 4);
|
2011-03-04 08:40:59 +08:00
|
|
|
if (i->events & 0xff0)
|
|
|
|
qemu_irq_raise(i->irq4);
|
2007-04-30 09:48:07 +08:00
|
|
|
}
|
|
|
|
|
2011-03-03 21:14:44 +08:00
|
|
|
static int pxa25x_timer_post_load(void *opaque, int version_id)
|
2007-05-25 02:50:09 +08:00
|
|
|
{
|
2011-02-20 21:50:33 +08:00
|
|
|
PXA2xxTimerInfo *s = (PXA2xxTimerInfo *) opaque;
|
2007-05-25 02:50:09 +08:00
|
|
|
int64_t now;
|
|
|
|
int i;
|
|
|
|
|
2011-03-11 23:47:48 +08:00
|
|
|
now = qemu_get_clock_ns(vm_clock);
|
2007-05-25 02:50:09 +08:00
|
|
|
pxa2xx_timer_update(s, now);
|
|
|
|
|
2011-03-03 21:14:44 +08:00
|
|
|
if (pxa2xx_timer_has_tm4(s))
|
|
|
|
for (i = 0; i < 8; i ++)
|
2007-05-25 02:50:09 +08:00
|
|
|
pxa2xx_timer_update4(s, now, i);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-03 21:14:44 +08:00
|
|
|
static int pxa2xx_timer_init(SysBusDevice *dev)
|
2007-04-30 09:48:07 +08:00
|
|
|
{
|
|
|
|
int i;
|
2011-02-20 21:50:33 +08:00
|
|
|
PXA2xxTimerInfo *s;
|
2007-04-30 09:48:07 +08:00
|
|
|
|
2011-03-03 21:14:44 +08:00
|
|
|
s = FROM_SYSBUS(PXA2xxTimerInfo, dev);
|
2007-04-30 09:48:07 +08:00
|
|
|
s->irq_enabled = 0;
|
|
|
|
s->oldclock = 0;
|
|
|
|
s->clock = 0;
|
2011-03-11 23:47:48 +08:00
|
|
|
s->lastload = qemu_get_clock_ns(vm_clock);
|
2007-04-30 09:48:07 +08:00
|
|
|
s->reset3 = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i ++) {
|
|
|
|
s->timer[i].value = 0;
|
2011-03-03 21:24:25 +08:00
|
|
|
sysbus_init_irq(dev, &s->timer[i].irq);
|
2007-04-30 09:48:07 +08:00
|
|
|
s->timer[i].info = s;
|
|
|
|
s->timer[i].num = i;
|
2011-03-11 23:47:48 +08:00
|
|
|
s->timer[i].qtimer = qemu_new_timer_ns(vm_clock,
|
2007-04-30 09:48:07 +08:00
|
|
|
pxa2xx_timer_tick, &s->timer[i]);
|
|
|
|
}
|
2011-03-03 21:14:44 +08:00
|
|
|
if (s->flags & (1 << PXA2XX_TIMER_HAVE_TM4)) {
|
2011-03-04 08:40:59 +08:00
|
|
|
sysbus_init_irq(dev, &s->irq4);
|
2011-03-03 21:14:44 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 8; i ++) {
|
|
|
|
s->tm4[i].tm.value = 0;
|
|
|
|
s->tm4[i].tm.info = s;
|
|
|
|
s->tm4[i].tm.num = i + 4;
|
|
|
|
s->tm4[i].freq = 0;
|
|
|
|
s->tm4[i].control = 0x0;
|
2011-03-11 23:47:48 +08:00
|
|
|
s->tm4[i].tm.qtimer = qemu_new_timer_ns(vm_clock,
|
2011-03-03 21:14:44 +08:00
|
|
|
pxa2xx_timer_tick4, &s->tm4[i]);
|
|
|
|
}
|
|
|
|
}
|
2007-04-30 09:48:07 +08:00
|
|
|
|
2011-10-30 21:50:16 +08:00
|
|
|
memory_region_init_io(&s->iomem, &pxa2xx_timer_ops, s,
|
|
|
|
"pxa2xx-timer", 0x00001000);
|
2011-11-27 17:38:10 +08:00
|
|
|
sysbus_init_mmio(dev, &s->iomem);
|
2007-05-25 02:50:09 +08:00
|
|
|
|
2011-03-03 21:14:44 +08:00
|
|
|
return 0;
|
2007-04-30 09:48:07 +08:00
|
|
|
}
|
|
|
|
|
2011-03-03 21:14:44 +08:00
|
|
|
static const VMStateDescription vmstate_pxa2xx_timer0_regs = {
|
|
|
|
.name = "pxa2xx_timer0",
|
2011-03-10 10:31:02 +08:00
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
|
|
|
.minimum_version_id_old = 2,
|
2011-03-03 21:14:44 +08:00
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(value, PXA2xxTimer0),
|
|
|
|
VMSTATE_END_OF_LIST(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_pxa2xx_timer4_regs = {
|
|
|
|
.name = "pxa2xx_timer4",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.minimum_version_id_old = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_STRUCT(tm, PXA2xxTimer4, 1,
|
|
|
|
vmstate_pxa2xx_timer0_regs, PXA2xxTimer0),
|
|
|
|
VMSTATE_INT32(oldclock, PXA2xxTimer4),
|
|
|
|
VMSTATE_INT32(clock, PXA2xxTimer4),
|
|
|
|
VMSTATE_UINT64(lastload, PXA2xxTimer4),
|
|
|
|
VMSTATE_UINT32(freq, PXA2xxTimer4),
|
|
|
|
VMSTATE_UINT32(control, PXA2xxTimer4),
|
|
|
|
VMSTATE_END_OF_LIST(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool pxa2xx_timer_has_tm4_test(void *opaque, int version_id)
|
2007-04-30 09:48:07 +08:00
|
|
|
{
|
2011-03-03 21:14:44 +08:00
|
|
|
return pxa2xx_timer_has_tm4(opaque);
|
2007-04-30 09:48:07 +08:00
|
|
|
}
|
|
|
|
|
2011-03-03 21:14:44 +08:00
|
|
|
static const VMStateDescription vmstate_pxa2xx_timer_regs = {
|
|
|
|
.name = "pxa2xx_timer",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.minimum_version_id_old = 1,
|
|
|
|
.post_load = pxa25x_timer_post_load,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_INT32(clock, PXA2xxTimerInfo),
|
|
|
|
VMSTATE_INT32(oldclock, PXA2xxTimerInfo),
|
|
|
|
VMSTATE_UINT64(lastload, PXA2xxTimerInfo),
|
|
|
|
VMSTATE_STRUCT_ARRAY(timer, PXA2xxTimerInfo, 4, 1,
|
|
|
|
vmstate_pxa2xx_timer0_regs, PXA2xxTimer0),
|
|
|
|
VMSTATE_UINT32(events, PXA2xxTimerInfo),
|
|
|
|
VMSTATE_UINT32(irq_enabled, PXA2xxTimerInfo),
|
|
|
|
VMSTATE_UINT32(reset3, PXA2xxTimerInfo),
|
|
|
|
VMSTATE_UINT32(snapshot, PXA2xxTimerInfo),
|
|
|
|
VMSTATE_STRUCT_ARRAY_TEST(tm4, PXA2xxTimerInfo, 8,
|
|
|
|
pxa2xx_timer_has_tm4_test, 0,
|
|
|
|
vmstate_pxa2xx_timer4_regs, PXA2xxTimer4),
|
|
|
|
VMSTATE_END_OF_LIST(),
|
2007-04-30 09:48:07 +08:00
|
|
|
}
|
2011-03-03 21:14:44 +08:00
|
|
|
};
|
|
|
|
|
2012-01-25 03:12:29 +08:00
|
|
|
static Property pxa25x_timer_dev_properties[] = {
|
|
|
|
DEFINE_PROP_UINT32("freq", PXA2xxTimerInfo, freq, PXA25X_FREQ),
|
|
|
|
DEFINE_PROP_BIT("tm4", PXA2xxTimerInfo, flags,
|
|
|
|
PXA2XX_TIMER_HAVE_TM4, false),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
2011-03-03 21:14:44 +08:00
|
|
|
};
|
|
|
|
|
2012-01-25 03:12:29 +08:00
|
|
|
static void pxa25x_timer_dev_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 11:34:16 +08:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-25 03:12:29 +08:00
|
|
|
SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
k->init = pxa2xx_timer_init;
|
2011-12-08 11:34:16 +08:00
|
|
|
dc->desc = "PXA25x timer";
|
|
|
|
dc->vmsd = &vmstate_pxa2xx_timer_regs;
|
|
|
|
dc->props = pxa25x_timer_dev_properties;
|
2012-01-25 03:12:29 +08:00
|
|
|
}
|
|
|
|
|
2011-12-08 11:34:16 +08:00
|
|
|
static TypeInfo pxa25x_timer_dev_info = {
|
|
|
|
.name = "pxa25x-timer",
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(PXA2xxTimerInfo),
|
|
|
|
.class_init = pxa25x_timer_dev_class_init,
|
2012-01-25 03:12:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static Property pxa27x_timer_dev_properties[] = {
|
|
|
|
DEFINE_PROP_UINT32("freq", PXA2xxTimerInfo, freq, PXA27X_FREQ),
|
|
|
|
DEFINE_PROP_BIT("tm4", PXA2xxTimerInfo, flags,
|
|
|
|
PXA2XX_TIMER_HAVE_TM4, true),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void pxa27x_timer_dev_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 11:34:16 +08:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-25 03:12:29 +08:00
|
|
|
SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
k->init = pxa2xx_timer_init;
|
2011-12-08 11:34:16 +08:00
|
|
|
dc->desc = "PXA27x timer";
|
|
|
|
dc->vmsd = &vmstate_pxa2xx_timer_regs;
|
|
|
|
dc->props = pxa27x_timer_dev_properties;
|
2012-01-25 03:12:29 +08:00
|
|
|
}
|
|
|
|
|
2011-12-08 11:34:16 +08:00
|
|
|
static TypeInfo pxa27x_timer_dev_info = {
|
|
|
|
.name = "pxa27x-timer",
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(PXA2xxTimerInfo),
|
|
|
|
.class_init = pxa27x_timer_dev_class_init,
|
2011-03-03 21:14:44 +08:00
|
|
|
};
|
|
|
|
|
2012-02-09 22:20:55 +08:00
|
|
|
static void pxa2xx_timer_register_types(void)
|
2011-03-03 21:14:44 +08:00
|
|
|
{
|
2011-12-08 11:34:16 +08:00
|
|
|
type_register_static(&pxa25x_timer_dev_info);
|
|
|
|
type_register_static(&pxa27x_timer_dev_info);
|
2012-02-09 22:20:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type_init(pxa2xx_timer_register_types)
|