2013-06-03 18:17:45 +02:00
|
|
|
/*
|
|
|
|
* IMX EPIT Timer
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 OK Labs
|
|
|
|
* Copyright (c) 2011 NICTA Pty Ltd
|
|
|
|
* Originally written by Hans Jiang
|
|
|
|
* Updated by Peter Chubb
|
2015-08-13 12:26:20 +02:00
|
|
|
* Updated by Jean-Christophe Dubois <jcd@tribudubois.net>
|
2013-06-03 18:17:45 +02:00
|
|
|
*
|
|
|
|
* This code is licensed under GPL version 2 or later. See
|
|
|
|
* the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:05 +01:00
|
|
|
#include "qemu/osdep.h"
|
2015-08-13 12:26:20 +02:00
|
|
|
#include "hw/timer/imx_epit.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2019-08-12 07:23:42 +02:00
|
|
|
#include "hw/irq.h"
|
2015-08-13 12:26:20 +02:00
|
|
|
#include "hw/misc/imx_ccm.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2015-12-15 13:16:16 +01:00
|
|
|
#include "qemu/log.h"
|
2013-06-03 18:17:45 +02:00
|
|
|
|
2015-10-25 15:16:24 +01:00
|
|
|
#ifndef DEBUG_IMX_EPIT
|
|
|
|
#define DEBUG_IMX_EPIT 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DPRINTF(fmt, args...) \
|
|
|
|
do { \
|
|
|
|
if (DEBUG_IMX_EPIT) { \
|
|
|
|
fprintf(stderr, "[%s]%s: " fmt , TYPE_IMX_EPIT, \
|
|
|
|
__func__, ##args); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2013-06-03 18:17:46 +02:00
|
|
|
|
2016-09-22 19:13:09 +02:00
|
|
|
static const char *imx_epit_reg_name(uint32_t reg)
|
2013-06-03 18:17:46 +02:00
|
|
|
{
|
|
|
|
switch (reg) {
|
|
|
|
case 0:
|
|
|
|
return "CR";
|
|
|
|
case 1:
|
|
|
|
return "SR";
|
|
|
|
case 2:
|
|
|
|
return "LR";
|
|
|
|
case 3:
|
|
|
|
return "CMP";
|
|
|
|
case 4:
|
|
|
|
return "CNT";
|
|
|
|
default:
|
|
|
|
return "[?]";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-03 18:17:45 +02:00
|
|
|
/*
|
|
|
|
* Exact clock frequencies vary from board to board.
|
|
|
|
* These are typical.
|
|
|
|
*/
|
2013-06-03 18:17:46 +02:00
|
|
|
static const IMXClk imx_epit_clocks[] = {
|
2016-03-16 18:06:00 +01:00
|
|
|
CLK_NONE, /* 00 disabled */
|
|
|
|
CLK_IPG, /* 01 ipg_clk, ~532MHz */
|
|
|
|
CLK_IPG_HIGH, /* 10 ipg_clk_highfreq */
|
|
|
|
CLK_32k, /* 11 ipg_clk_32k -- ~32kHz */
|
2013-06-03 18:17:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update interrupt status
|
|
|
|
*/
|
2013-06-03 18:17:46 +02:00
|
|
|
static void imx_epit_update_int(IMXEPITState *s)
|
2013-06-03 18:17:45 +02:00
|
|
|
{
|
2022-11-19 15:59:40 +01:00
|
|
|
if ((s->sr & SR_OCIF) && (s->cr & CR_OCIEN) && (s->cr & CR_EN)) {
|
2013-06-03 18:17:45 +02:00
|
|
|
qemu_irq_raise(s->irq);
|
|
|
|
} else {
|
|
|
|
qemu_irq_lower(s->irq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-08 19:17:36 +02:00
|
|
|
/*
|
|
|
|
* Must be called from within a ptimer_transaction_begin/commit block
|
|
|
|
* for both s->timer_cmp and s->timer_reload.
|
|
|
|
*/
|
2013-06-03 18:17:46 +02:00
|
|
|
static void imx_epit_set_freq(IMXEPITState *s)
|
2013-06-03 18:17:45 +02:00
|
|
|
{
|
2013-06-03 18:17:46 +02:00
|
|
|
uint32_t clksrc;
|
|
|
|
uint32_t prescaler;
|
2013-06-03 18:17:45 +02:00
|
|
|
|
2022-10-31 00:59:29 +01:00
|
|
|
clksrc = extract32(s->cr, CR_CLKSRC_SHIFT, CR_CLKSRC_BITS);
|
|
|
|
prescaler = 1 + extract32(s->cr, CR_PRESCALE_SHIFT, CR_PRESCALE_BITS);
|
2013-06-03 18:17:45 +02:00
|
|
|
|
2015-12-17 14:37:15 +01:00
|
|
|
s->freq = imx_ccm_get_clock_frequency(s->ccm,
|
|
|
|
imx_epit_clocks[clksrc]) / prescaler;
|
2013-06-03 18:17:45 +02:00
|
|
|
|
2015-12-17 14:37:15 +01:00
|
|
|
DPRINTF("Setting ptimer frequency to %u\n", s->freq);
|
2013-06-03 18:17:46 +02:00
|
|
|
|
2015-12-17 14:37:15 +01:00
|
|
|
if (s->freq) {
|
|
|
|
ptimer_set_freq(s->timer_reload, s->freq);
|
|
|
|
ptimer_set_freq(s->timer_cmp, s->freq);
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-25 17:33:43 +02:00
|
|
|
/*
|
|
|
|
* This is called both on hardware (device) reset and software reset.
|
|
|
|
*/
|
2022-11-19 17:09:59 +01:00
|
|
|
static void imx_epit_reset(IMXEPITState *s, bool is_hard_reset)
|
2013-06-03 18:17:45 +02:00
|
|
|
{
|
2022-10-25 17:33:43 +02:00
|
|
|
/* Soft reset doesn't touch some bits; hard reset clears them */
|
2022-11-19 17:09:59 +01:00
|
|
|
if (is_hard_reset) {
|
|
|
|
s->cr = 0;
|
|
|
|
} else {
|
|
|
|
s->cr &= (CR_EN|CR_ENMOD|CR_STOPEN|CR_DOZEN|CR_WAITEN|CR_DBGEN);
|
|
|
|
}
|
2013-06-03 18:17:45 +02:00
|
|
|
s->sr = 0;
|
2014-08-01 22:14:48 +02:00
|
|
|
s->lr = EPIT_TIMER_MAX;
|
2013-06-03 18:17:45 +02:00
|
|
|
s->cmp = 0;
|
|
|
|
s->cnt = 0;
|
2019-10-08 19:17:36 +02:00
|
|
|
ptimer_transaction_begin(s->timer_cmp);
|
|
|
|
ptimer_transaction_begin(s->timer_reload);
|
2013-06-03 18:17:45 +02:00
|
|
|
/* stop both timers */
|
|
|
|
ptimer_stop(s->timer_cmp);
|
|
|
|
ptimer_stop(s->timer_reload);
|
|
|
|
/* compute new frequency */
|
2013-06-03 18:17:46 +02:00
|
|
|
imx_epit_set_freq(s);
|
2014-08-01 22:14:48 +02:00
|
|
|
/* init both timers to EPIT_TIMER_MAX */
|
|
|
|
ptimer_set_limit(s->timer_cmp, EPIT_TIMER_MAX, 1);
|
|
|
|
ptimer_set_limit(s->timer_reload, EPIT_TIMER_MAX, 1);
|
2013-06-03 18:17:45 +02:00
|
|
|
if (s->freq && (s->cr & CR_EN)) {
|
|
|
|
/* if the timer is still enabled, restart it */
|
2013-08-20 15:54:32 +02:00
|
|
|
ptimer_run(s->timer_reload, 0);
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
2019-10-08 19:17:36 +02:00
|
|
|
ptimer_transaction_commit(s->timer_cmp);
|
|
|
|
ptimer_transaction_commit(s->timer_reload);
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
|
|
|
|
2013-06-03 18:17:46 +02:00
|
|
|
static uint32_t imx_epit_update_count(IMXEPITState *s)
|
2013-06-03 18:17:45 +02:00
|
|
|
{
|
2015-08-13 12:26:20 +02:00
|
|
|
s->cnt = ptimer_get_count(s->timer_reload);
|
2013-06-03 18:17:45 +02:00
|
|
|
|
2015-08-13 12:26:20 +02:00
|
|
|
return s->cnt;
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
|
|
|
|
2013-06-03 18:17:46 +02:00
|
|
|
static uint64_t imx_epit_read(void *opaque, hwaddr offset, unsigned size)
|
2013-06-03 18:17:45 +02:00
|
|
|
{
|
2013-06-03 18:17:46 +02:00
|
|
|
IMXEPITState *s = IMX_EPIT(opaque);
|
|
|
|
uint32_t reg_value = 0;
|
2013-06-03 18:17:45 +02:00
|
|
|
|
2015-10-25 15:16:24 +01:00
|
|
|
switch (offset >> 2) {
|
2013-06-03 18:17:45 +02:00
|
|
|
case 0: /* Control Register */
|
2013-06-03 18:17:46 +02:00
|
|
|
reg_value = s->cr;
|
|
|
|
break;
|
2013-06-03 18:17:45 +02:00
|
|
|
|
|
|
|
case 1: /* Status Register */
|
2013-06-03 18:17:46 +02:00
|
|
|
reg_value = s->sr;
|
|
|
|
break;
|
2013-06-03 18:17:45 +02:00
|
|
|
|
|
|
|
case 2: /* LR - ticks*/
|
2013-06-03 18:17:46 +02:00
|
|
|
reg_value = s->lr;
|
|
|
|
break;
|
2013-06-03 18:17:45 +02:00
|
|
|
|
|
|
|
case 3: /* CMP */
|
2013-06-03 18:17:46 +02:00
|
|
|
reg_value = s->cmp;
|
|
|
|
break;
|
2013-06-03 18:17:45 +02:00
|
|
|
|
|
|
|
case 4: /* CNT */
|
2013-06-03 18:17:46 +02:00
|
|
|
imx_epit_update_count(s);
|
|
|
|
reg_value = s->cnt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-10-25 15:16:24 +01:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Bad register at offset 0x%"
|
|
|
|
HWADDR_PRIx "\n", TYPE_IMX_EPIT, __func__, offset);
|
2013-06-03 18:17:46 +02:00
|
|
|
break;
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
|
|
|
|
2015-10-25 15:16:24 +01:00
|
|
|
DPRINTF("(%s) = 0x%08x\n", imx_epit_reg_name(offset >> 2), reg_value);
|
2013-06-03 18:17:46 +02:00
|
|
|
|
|
|
|
return reg_value;
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
|
|
|
|
2019-10-08 19:17:36 +02:00
|
|
|
/* Must be called from ptimer_transaction_begin/commit block for s->timer_cmp */
|
2013-06-03 18:17:46 +02:00
|
|
|
static void imx_epit_reload_compare_timer(IMXEPITState *s)
|
2013-06-03 18:17:45 +02:00
|
|
|
{
|
2013-08-20 15:54:32 +02:00
|
|
|
if ((s->cr & (CR_EN | CR_OCIEN)) == (CR_EN | CR_OCIEN)) {
|
|
|
|
/* if the compare feature is on and timers are running */
|
2013-06-03 18:17:46 +02:00
|
|
|
uint32_t tmp = imx_epit_update_count(s);
|
2013-08-20 15:54:32 +02:00
|
|
|
uint64_t next;
|
2013-06-03 18:17:45 +02:00
|
|
|
if (tmp > s->cmp) {
|
2013-08-20 15:54:32 +02:00
|
|
|
/* It'll fire in this round of the timer */
|
|
|
|
next = tmp - s->cmp;
|
|
|
|
} else { /* catch it next time around */
|
2014-08-01 22:14:48 +02:00
|
|
|
next = tmp - s->cmp + ((s->cr & CR_RLD) ? EPIT_TIMER_MAX : s->lr);
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
2013-08-20 15:54:32 +02:00
|
|
|
ptimer_set_count(s->timer_cmp, next);
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-03 18:17:46 +02:00
|
|
|
static void imx_epit_write(void *opaque, hwaddr offset, uint64_t value,
|
|
|
|
unsigned size)
|
2013-06-03 18:17:45 +02:00
|
|
|
{
|
2013-06-03 18:17:46 +02:00
|
|
|
IMXEPITState *s = IMX_EPIT(opaque);
|
2013-08-20 15:54:32 +02:00
|
|
|
uint64_t oldcr;
|
2013-06-03 18:17:46 +02:00
|
|
|
|
2015-10-25 15:16:24 +01:00
|
|
|
DPRINTF("(%s, value = 0x%08x)\n", imx_epit_reg_name(offset >> 2),
|
|
|
|
(uint32_t)value);
|
2013-06-03 18:17:45 +02:00
|
|
|
|
2015-10-25 15:16:24 +01:00
|
|
|
switch (offset >> 2) {
|
2013-06-03 18:17:45 +02:00
|
|
|
case 0: /* CR */
|
2013-08-20 15:54:32 +02:00
|
|
|
|
|
|
|
oldcr = s->cr;
|
2013-06-03 18:17:45 +02:00
|
|
|
s->cr = value & 0x03ffffff;
|
|
|
|
if (s->cr & CR_SWR) {
|
|
|
|
/* handle the reset */
|
2022-11-19 17:09:59 +01:00
|
|
|
imx_epit_reset(s, false);
|
2020-07-27 17:45:50 +02:00
|
|
|
}
|
|
|
|
|
2022-10-25 20:32:30 +02:00
|
|
|
/*
|
|
|
|
* The interrupt state can change due to:
|
|
|
|
* - reset clears both SR.OCIF and CR.OCIE
|
|
|
|
* - write to CR.EN or CR.OCIE
|
|
|
|
*/
|
|
|
|
imx_epit_update_int(s);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: could we 'break' here for reset? following operations appear
|
|
|
|
* to duplicate the work imx_epit_reset() already did.
|
|
|
|
*/
|
|
|
|
|
2020-07-27 17:45:50 +02:00
|
|
|
ptimer_transaction_begin(s->timer_cmp);
|
|
|
|
ptimer_transaction_begin(s->timer_reload);
|
|
|
|
|
2022-10-25 17:33:43 +02:00
|
|
|
/* Update the frequency. Has been done already in case of a reset. */
|
2020-07-27 17:45:50 +02:00
|
|
|
if (!(s->cr & CR_SWR)) {
|
2013-06-03 18:17:46 +02:00
|
|
|
imx_epit_set_freq(s);
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
|
|
|
|
2013-08-20 15:54:32 +02:00
|
|
|
if (s->freq && (s->cr & CR_EN) && !(oldcr & CR_EN)) {
|
2013-06-03 18:17:45 +02:00
|
|
|
if (s->cr & CR_ENMOD) {
|
|
|
|
if (s->cr & CR_RLD) {
|
|
|
|
ptimer_set_limit(s->timer_reload, s->lr, 1);
|
2013-08-20 15:54:32 +02:00
|
|
|
ptimer_set_limit(s->timer_cmp, s->lr, 1);
|
2013-06-03 18:17:45 +02:00
|
|
|
} else {
|
2014-08-01 22:14:48 +02:00
|
|
|
ptimer_set_limit(s->timer_reload, EPIT_TIMER_MAX, 1);
|
|
|
|
ptimer_set_limit(s->timer_cmp, EPIT_TIMER_MAX, 1);
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-03 18:17:46 +02:00
|
|
|
imx_epit_reload_compare_timer(s);
|
2013-08-20 15:54:32 +02:00
|
|
|
ptimer_run(s->timer_reload, 0);
|
|
|
|
if (s->cr & CR_OCIEN) {
|
|
|
|
ptimer_run(s->timer_cmp, 0);
|
|
|
|
} else {
|
|
|
|
ptimer_stop(s->timer_cmp);
|
|
|
|
}
|
|
|
|
} else if (!(s->cr & CR_EN)) {
|
2013-06-03 18:17:45 +02:00
|
|
|
/* stop both timers */
|
|
|
|
ptimer_stop(s->timer_reload);
|
|
|
|
ptimer_stop(s->timer_cmp);
|
2013-08-20 15:54:32 +02:00
|
|
|
} else if (s->cr & CR_OCIEN) {
|
|
|
|
if (!(oldcr & CR_OCIEN)) {
|
|
|
|
imx_epit_reload_compare_timer(s);
|
|
|
|
ptimer_run(s->timer_cmp, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ptimer_stop(s->timer_cmp);
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
2019-10-08 19:17:36 +02:00
|
|
|
|
|
|
|
ptimer_transaction_commit(s->timer_cmp);
|
|
|
|
ptimer_transaction_commit(s->timer_reload);
|
2013-06-03 18:17:45 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* SR - ACK*/
|
2022-11-19 15:59:40 +01:00
|
|
|
/* writing 1 to SR.OCIF clears this bit and turns the interrupt off */
|
|
|
|
if (value & SR_OCIF) {
|
|
|
|
s->sr = 0; /* SR.OCIF is the only bit in this register anyway */
|
2013-06-03 18:17:46 +02:00
|
|
|
imx_epit_update_int(s);
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* LR - set ticks */
|
|
|
|
s->lr = value;
|
|
|
|
|
2019-10-08 19:17:36 +02:00
|
|
|
ptimer_transaction_begin(s->timer_cmp);
|
|
|
|
ptimer_transaction_begin(s->timer_reload);
|
2013-06-03 18:17:45 +02:00
|
|
|
if (s->cr & CR_RLD) {
|
|
|
|
/* Also set the limit if the LRD bit is set */
|
|
|
|
/* If IOVW bit is set then set the timer value */
|
|
|
|
ptimer_set_limit(s->timer_reload, s->lr, s->cr & CR_IOVW);
|
2013-08-20 15:54:32 +02:00
|
|
|
ptimer_set_limit(s->timer_cmp, s->lr, 0);
|
2013-06-03 18:17:45 +02:00
|
|
|
} else if (s->cr & CR_IOVW) {
|
|
|
|
/* If IOVW bit is set then set the timer value */
|
|
|
|
ptimer_set_count(s->timer_reload, s->lr);
|
|
|
|
}
|
2022-10-19 15:09:50 +02:00
|
|
|
/*
|
|
|
|
* Commit the change to s->timer_reload, so it can propagate. Otherwise
|
|
|
|
* the timer interrupt may not fire properly. The commit must happen
|
|
|
|
* before calling imx_epit_reload_compare_timer(), which reads
|
|
|
|
* s->timer_reload internally again.
|
|
|
|
*/
|
|
|
|
ptimer_transaction_commit(s->timer_reload);
|
2013-06-03 18:17:46 +02:00
|
|
|
imx_epit_reload_compare_timer(s);
|
2019-10-08 19:17:36 +02:00
|
|
|
ptimer_transaction_commit(s->timer_cmp);
|
2013-06-03 18:17:45 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* CMP */
|
|
|
|
s->cmp = value;
|
|
|
|
|
2019-10-08 19:17:36 +02:00
|
|
|
ptimer_transaction_begin(s->timer_cmp);
|
2013-06-03 18:17:46 +02:00
|
|
|
imx_epit_reload_compare_timer(s);
|
2019-10-08 19:17:36 +02:00
|
|
|
ptimer_transaction_commit(s->timer_cmp);
|
2013-06-03 18:17:45 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-10-25 15:16:24 +01:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Bad register at offset 0x%"
|
|
|
|
HWADDR_PRIx "\n", TYPE_IMX_EPIT, __func__, offset);
|
2013-06-03 18:17:46 +02:00
|
|
|
|
|
|
|
break;
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-03 18:17:46 +02:00
|
|
|
static void imx_epit_cmp(void *opaque)
|
2013-06-03 18:17:45 +02:00
|
|
|
{
|
2013-06-03 18:17:46 +02:00
|
|
|
IMXEPITState *s = IMX_EPIT(opaque);
|
2013-06-03 18:17:45 +02:00
|
|
|
|
2013-08-20 15:54:32 +02:00
|
|
|
DPRINTF("sr was %d\n", s->sr);
|
2022-11-19 15:59:40 +01:00
|
|
|
/* Set interrupt status bit SR.OCIF and update the interrupt state */
|
|
|
|
s->sr |= SR_OCIF;
|
2013-08-20 15:54:32 +02:00
|
|
|
imx_epit_update_int(s);
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
|
|
|
|
2019-10-08 19:17:36 +02:00
|
|
|
static void imx_epit_reload(void *opaque)
|
|
|
|
{
|
|
|
|
/* No action required on rollover of timer_reload */
|
|
|
|
}
|
|
|
|
|
2013-06-03 18:17:46 +02:00
|
|
|
static const MemoryRegionOps imx_epit_ops = {
|
2015-08-13 12:26:20 +02:00
|
|
|
.read = imx_epit_read,
|
|
|
|
.write = imx_epit_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2013-06-03 18:17:45 +02:00
|
|
|
};
|
|
|
|
|
2013-06-03 18:17:46 +02:00
|
|
|
static const VMStateDescription vmstate_imx_timer_epit = {
|
2015-08-13 12:26:20 +02:00
|
|
|
.name = TYPE_IMX_EPIT,
|
2013-06-03 18:17:45 +02:00
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
2014-05-13 17:09:35 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2013-06-03 18:17:46 +02:00
|
|
|
VMSTATE_UINT32(cr, IMXEPITState),
|
|
|
|
VMSTATE_UINT32(sr, IMXEPITState),
|
|
|
|
VMSTATE_UINT32(lr, IMXEPITState),
|
|
|
|
VMSTATE_UINT32(cmp, IMXEPITState),
|
|
|
|
VMSTATE_UINT32(cnt, IMXEPITState),
|
|
|
|
VMSTATE_UINT32(freq, IMXEPITState),
|
|
|
|
VMSTATE_PTIMER(timer_reload, IMXEPITState),
|
|
|
|
VMSTATE_PTIMER(timer_cmp, IMXEPITState),
|
2013-06-03 18:17:45 +02:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-03 18:17:46 +02:00
|
|
|
static void imx_epit_realize(DeviceState *dev, Error **errp)
|
2013-06-03 18:17:45 +02:00
|
|
|
{
|
2013-06-03 18:17:46 +02:00
|
|
|
IMXEPITState *s = IMX_EPIT(dev);
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
|
2013-06-03 18:17:45 +02:00
|
|
|
|
2013-06-03 18:17:46 +02:00
|
|
|
DPRINTF("\n");
|
|
|
|
|
|
|
|
sysbus_init_irq(sbd, &s->irq);
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(&s->iomem, OBJECT(s), &imx_epit_ops, s, TYPE_IMX_EPIT,
|
2013-06-03 18:17:45 +02:00
|
|
|
0x00001000);
|
2013-06-03 18:17:46 +02:00
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
2013-06-03 18:17:45 +02:00
|
|
|
|
2022-10-25 17:33:43 +02:00
|
|
|
/*
|
|
|
|
* The reload timer keeps running when the peripheral is enabled. It is a
|
|
|
|
* kind of wall clock that does not generate any interrupts. The callback
|
|
|
|
* needs to be provided, but it does nothing as the ptimer already supports
|
|
|
|
* all necessary reloading functionality.
|
|
|
|
*/
|
2022-05-16 12:30:58 +02:00
|
|
|
s->timer_reload = ptimer_init(imx_epit_reload, s, PTIMER_POLICY_LEGACY);
|
2013-06-03 18:17:45 +02:00
|
|
|
|
2022-10-25 17:33:43 +02:00
|
|
|
/*
|
|
|
|
* The compare timer is running only when the peripheral configuration is
|
|
|
|
* in a state that will generate compare interrupts.
|
|
|
|
*/
|
2022-05-16 12:30:58 +02:00
|
|
|
s->timer_cmp = ptimer_init(imx_epit_cmp, s, PTIMER_POLICY_LEGACY);
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
|
|
|
|
2022-11-19 17:09:59 +01:00
|
|
|
static void imx_epit_dev_reset(DeviceState *dev)
|
|
|
|
{
|
|
|
|
IMXEPITState *s = IMX_EPIT(dev);
|
|
|
|
imx_epit_reset(s, true);
|
|
|
|
}
|
|
|
|
|
2013-06-03 18:17:46 +02:00
|
|
|
static void imx_epit_class_init(ObjectClass *klass, void *data)
|
2013-06-03 18:17:45 +02:00
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2013-06-03 18:17:46 +02:00
|
|
|
|
|
|
|
dc->realize = imx_epit_realize;
|
2022-11-19 17:09:59 +01:00
|
|
|
dc->reset = imx_epit_dev_reset;
|
2013-06-03 18:17:46 +02:00
|
|
|
dc->vmsd = &vmstate_imx_timer_epit;
|
2013-06-03 18:17:45 +02:00
|
|
|
dc->desc = "i.MX periodic timer";
|
|
|
|
}
|
|
|
|
|
2013-06-03 18:17:46 +02:00
|
|
|
static const TypeInfo imx_epit_info = {
|
|
|
|
.name = TYPE_IMX_EPIT,
|
2013-06-03 18:17:45 +02:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
2013-06-03 18:17:46 +02:00
|
|
|
.instance_size = sizeof(IMXEPITState),
|
|
|
|
.class_init = imx_epit_class_init,
|
2013-06-03 18:17:45 +02:00
|
|
|
};
|
|
|
|
|
2013-06-03 18:17:46 +02:00
|
|
|
static void imx_epit_register_types(void)
|
2013-06-03 18:17:45 +02:00
|
|
|
{
|
2013-06-03 18:17:46 +02:00
|
|
|
type_register_static(&imx_epit_info);
|
2013-06-03 18:17:45 +02:00
|
|
|
}
|
|
|
|
|
2013-06-03 18:17:46 +02:00
|
|
|
type_init(imx_epit_register_types)
|