HelenOS sources
This source file includes following definitions.
- amdm37x_gpt_timer_ticks_init
- amdm37x_gpt_timer_ticks_start
- amdm37x_gpt_irq_ack
#ifndef KERN_AMDM37x_GPT_H_
#define KERN_AMDM37x_GPT_H_
#include <assert.h>
#include <typedefs.h>
#include <mm/km.h>
#include <time/clock.h>
#define AMDM37x_GPT1_BASE_ADDRESS 0x48318000
#define AMDM37x_GPT1_SIZE 4096
#define AMDM37x_GPT1_IRQ 37
#define AMDM37x_GPT2_BASE_ADDRESS 0x49032000
#define AMDM37x_GPT2_SIZE 4096
#define AMDM37x_GPT2_IRQ 38
#define AMDM37x_GPT3_BASE_ADDRESS 0x49034000
#define AMDM37x_GPT3_SIZE 4096
#define AMDM37x_GPT3_IRQ 39
#define AMDM37x_GPT4_BASE_ADDRESS 0x49036000
#define AMDM37x_GPT4_SIZE 4096
#define AMDM37x_GPT4_IRQ 40
#define AMDM37x_GPT5_BASE_ADDRESS 0x49038000
#define AMDM37x_GPT5_SIZE 4096
#define AMDM37x_GPT5_IRQ 41
#define AMDM37x_GPT6_BASE_ADDRESS 0x4903a000
#define AMDM37x_GPT6_SIZE 4096
#define AMDM37x_GPT6_IRQ 42
#define AMDM37x_GPT7_BASE_ADDRESS 0x4903c000
#define AMDM37x_GPT7_SIZE 4096
#define AMDM37x_GPT7_IRQ 43
#define AMDM37x_GPT8_BASE_ADDRESS 0x4903e000
#define AMDM37x_GPT8_SIZE 4096
#define AMDM37x_GPT8_IRQ 44
#define AMDM37x_GPT9_BASE_ADDRESS 0x49040000
#define AMDM37x_GPT9_SIZE 4096
#define AMDM37x_GPT9_IRQ 45
#define AMDM37x_GPT10_BASE_ADDRESS 0x48086000
#define AMDM37x_GPT10_SIZE 4096
#define AMDM37x_GPT10_IRQ 46
#define AMDM37x_GPT11_BASE_ADDRESS 0x48088000
#define AMDM37x_GPT11_SIZE 4096
#define AMDM37x_GPT11_IRQ 47
typedef struct {
const ioport32_t tidr;
#define AMDM37x_GPT_TIDR_MINOR_MASK (0xf)
#define AMDM37x_GPT_TIDR_MINOR_SHIFT (0)
#define AMDM37x_GPT_TIDR_MAJOR_MASK (0xf)
#define AMDM37x_GPT_TIDR_MAJOR_SHIFT (4)
uint32_t padd0_[3];
ioport32_t tiocp_cfg;
#define AMDM37x_GPT_TIOCP_CFG_AUTOIDLE_FLAG (1 << 0)
#define AMDM37x_GPT_TIOCP_CFG_SOFTRESET_FLAG (1 << 1)
#define AMDM37x_GPT_TIOCP_CFG_ENWAKEUP_FLAG (1 << 2)
#define AMDM37x_GPT_TIOCP_CFG_IDLEMODE_MASK (0x3)
#define AMDM37x_GPT_TIOCP_CFG_IDLEMODE_SHIFT (3)
#define AMDM37x_GPT_TIOCP_CFG_EMUFREE_FlAG (1 << 5)
#define AMDM37x_GPT_TIOCP_CFG_CLOCKACTIVITY_MASK (0x3)
#define AMDM37x_GPT_TIOCP_CFG_CLOCKACTIVITY_SHIFT (8)
const ioport32_t tistat;
#define AMDM37x_GPT_TISTAT_RESET_DONE_FLAG (1 << 0)
ioport32_t tisr;
#define AMDM37x_GPT_TISR_MAT_IRQ_FLAG (1 << 0)
#define AMDM37x_GPT_TISR_OVF_IRQ_FLAG (1 << 1)
#define AMDM37x_GPT_TISR_TCAR_IRQ_FLAG (1 << 2)
ioport32_t tier;
#define AMDM37x_GPT_TIER_MAT_IRQ_FLAG (1 << 0)
#define AMDM37x_GPT_TIER_OVF_IRQ_FLAG (1 << 1)
#define AMDM37x_GPT_TIER_TCAR_IRQ_FLAG (1 << 2)
ioport32_t twer;
#define AMDM37x_GPT_TWER_MAT_IRQ_FLAG (1 << 0)
#define AMDM37x_GPT_TWER_OVF_IRQ_FLAG (1 << 1)
#define AMDM37x_GPT_TWER_TCAR_IRQ_FLAG (1 << 2)
ioport32_t tclr;
#define AMDM37x_GPT_TCLR_ST_FLAG (1 << 0)
#define AMDM37x_GPT_TCLR_AR_FLAG (1 << 1)
#define AMDM37x_GPT_TCLR_PTV_MASK (0x7)
#define AMDM37x_GPT_TCLR_PTV_SHIFT (2)
#define AMDM37x_GPT_TCLR_PRE_FLAG (1 << 5)
#define AMDM37x_GPT_TCLR_CE_FLAG (1 << 6)
#define AMDM37x_GPT_TCLR_SCPWM (1 << 7)
#define AMDM37x_GPT_TCLR_TCM_MASK (0x3 << 8)
#define AMDM37x_GPT_TCLR_TCM_NO_CAPTURE (0x0 << 8)
#define AMDM37x_GPT_TCLR_TCM_RAISE_CAPTURE (0x1 << 8)
#define AMDM37x_GPT_TCLR_TCM_FALL_CAPTURE (0x2 << 8)
#define AMDM37x_GPT_TCLR_TCM_BOTH_CAPTURE (0x3 << 8)
#define AMDM37x_GPT_TCLR_TRG_MASK (0x3 << 10)
#define AMDM37x_GPT_TCLR_TRG_NO (0x0 << 10)
#define AMDM37x_GPT_TCLR_TRG_OVERFLOW (0x1 << 10)
#define AMDM37x_GPT_TCLR_TRG_OVERMATCH (0x2 << 10)
#define AMDM37x_GPT_TCLR_PT_FLAG (1 << 12)
#define AMDM37x_GPT_TCLR_CAPT_MODE_FLAG (1 << 13)
#define AMDM37x_GPT_TCLR_GPO_CFG_FLAG (1 << 14)
ioport32_t tccr;
ioport32_t tldr;
ioport32_t ttgr;
const ioport32_t twps;
#define AMDM37x_GPT_TWPS_TCLR_FLAG (1 << 0)
#define AMDM37x_GPT_TWPS_TCRR_FLAG (1 << 1)
#define AMDM37x_GPT_TWPS_TLDR_FLAG (1 << 2)
#define AMDM37x_GPT_TWPS_TTGR_FLAG (1 << 3)
#define AMDM37x_GPT_TWPS_TMAR_FLAG (1 << 4)
#define AMDM37x_GPT_TWPS_TPIR_FLAG (1 << 5)
#define AMDM37x_GPT_TWPS_TNIR_FLAG (1 << 6)
#define AMDM37x_GPT_TWPS_TCVR_FLAG (1 << 7)
#define AMDM37x_GPT_TWPS_TOCR_FLAG (1 << 8)
#define AMDM37x_GPT_TWPS_TOWR_FLAG (1 << 9)
ioport32_t tmar;
const ioport32_t tcar1;
ioport32_t tsicr;
#define AMDM37x_GPT_TSICR_SFT_FLAG (1 << 1)
#define AMDM37x_GPT_TSICR_POSTED_FLAG (1 << 2)
const ioport32_t tcar2;
ioport32_t tpir;
ioport32_t tnir;
ioport32_t tcvr;
ioport32_t tocr;
ioport32_t towr;
} amdm37x_gpt_regs_t;
typedef struct {
amdm37x_gpt_regs_t *regs;
bool special_available;
} amdm37x_gpt_t;
static inline void amdm37x_gpt_timer_ticks_init(
amdm37x_gpt_t *timer, uintptr_t ioregs, size_t iosize, unsigned hz)
{
ioport32_t *clksel = (void *) km_map(0x48004C40, 4, PAGE_SIZE,
PAGE_NOT_CACHEABLE);
*clksel &= ~1;
km_unmap((uintptr_t)clksel, 4);
assert(timer);
timer->regs = (void *) km_map(ioregs, iosize, KM_NATURAL_ALIGNMENT,
PAGE_NOT_CACHEABLE);
timer->regs->tiocp_cfg |= AMDM37x_GPT_TIOCP_CFG_SOFTRESET_FLAG;
while (!(timer->regs->tistat & AMDM37x_GPT_TISTAT_RESET_DONE_FLAG))
;
timer->regs->tclr |= AMDM37x_GPT_TCLR_AR_FLAG;
timer->special_available = ((ioregs == AMDM37x_GPT1_BASE_ADDRESS) ||
(ioregs == AMDM37x_GPT2_BASE_ADDRESS) ||
(ioregs == AMDM37x_GPT10_BASE_ADDRESS));
timer->regs->tldr = 0xffffffff - (32768 / hz) + 1;
timer->regs->tccr = 0xffffffff - (32768 / hz) + 1;
if (timer->special_available) {
const uint32_t tpir =
((32768 / hz + 1) * 1000000) - (32768000L * (1000 / hz));
const uint32_t tnir =
((32768 / hz) * 1000000) - (32768000L * (1000 / hz));
timer->regs->tpir = tpir;
timer->regs->tnir = tnir;
}
}
static inline void amdm37x_gpt_timer_ticks_start(amdm37x_gpt_t *timer)
{
assert(timer);
assert(timer->regs);
timer->regs->tier |= AMDM37x_GPT_TIER_OVF_IRQ_FLAG;
timer->regs->tclr |= AMDM37x_GPT_TCLR_ST_FLAG;
}
static inline bool amdm37x_gpt_irq_ack(amdm37x_gpt_t *timer)
{
assert(timer);
assert(timer->regs);
const uint32_t tisr = timer->regs->tisr;
timer->regs->tisr = tisr;
return tisr != 0;
}
#endif
HelenOS homepage, sources at GitHub