version 1.3, 2007/10/29 21:10:03 |
version 1.5, 2007/11/06 22:57:45 |
|
|
#include <sys/device.h> |
#include <sys/device.h> |
#include <sys/bus.h> |
#include <sys/bus.h> |
|
|
|
#include <sys/kern_time.h> |
#include <arch/testarm/dev/tartcvar.h> |
#include <arch/testarm/dev/tartcvar.h> |
#include <arch/testarm/dev/tartcreg.h> |
#include <arch/testarm/dev/tartcreg.h> |
#include <libkern/printf.h> |
#include <libkern/printf.h> |
|
|
*/ |
*/ |
int tartc_attach(struct device *, uint32_t loc, uint8_t flags); |
int tartc_attach(struct device *, uint32_t loc, uint8_t flags); |
void tartc_interrupt(struct device *); |
void tartc_interrupt(struct device *); |
|
void tartc_sethz(uint8_t hz); |
|
uint32_t tartc_getsec(void); |
|
uint32_t tartc_getusec(void); |
|
|
|
|
|
/* default tartc device to use; will bind to first tartc instance */ |
|
struct tartc_dd *tartcdd = NULL; |
|
extern struct rtcops sysrtcops; |
|
|
struct driver tartc_dr = { |
struct driver tartc_dr = { |
sizeof(struct tartc_dd), |
sizeof(struct tartc_dd), |
tartc_attach, |
tartc_attach, |
|
|
|
|
printf("testarm Real Time Clock (%d seconds past Epoch)\n", seconds); |
printf("testarm Real Time Clock (%d seconds past Epoch)\n", seconds); |
|
|
|
/* set default tartc */ |
|
tartcdd = ddp; |
|
|
|
/* fill-in rtcops to be used by kern_time */ |
|
sysrtcops.ro_sethz = tartc_sethz; |
|
sysrtcops.ro_getsec = tartc_getsec; |
|
sysrtcops.ro_getusec = tartc_getusec; |
|
|
return(0); |
return(0); |
|
|
} |
} |
|
|
|
|
void |
void |
|
tartc_sethz(uint8_t hz) |
|
{ |
|
/* |
|
* Set timer frequency. |
|
*/ |
|
if (tartcdd == NULL) |
|
panic("can't calibrate not configured timer\n"); |
|
|
|
bus_write_1(tartcdd->td_bushandlep, tartcdd->td_ioaddr + TARTC_OFF_TMRINTRFREQ, hz); |
|
} |
|
|
|
|
|
uint32_t |
|
tartc_getsec(void) |
|
{ |
|
/* |
|
* Get seconds. |
|
*/ |
|
if (tartcdd == NULL) |
|
panic("tartc_getsec: can't get seconds from rtc: default device not configured\n"); |
|
|
|
/* trigger clock update on host */ |
|
bus_write_1(tartcdd->td_bushandlep, tartcdd->td_ioaddr + TARTC_OFF_CLOCKUPDATE, 1); |
|
|
|
return( bus_read_4(tartcdd->td_bushandlep, tartcdd->td_ioaddr + TARTC_OFF_READSECONDS) ); |
|
} |
|
|
|
|
|
uint32_t |
|
tartc_getusec(void) |
|
{ |
|
/* |
|
* Get microseconds. |
|
*/ |
|
if (tartcdd == NULL) |
|
panic("tartc_getusec: can't get microseconds from rtc: default device not configured\n"); |
|
|
|
/* trigger clock update on host */ |
|
bus_write_1(tartcdd->td_bushandlep, tartcdd->td_ioaddr + TARTC_OFF_CLOCKUPDATE, 1); |
|
|
|
return( bus_read_4(tartcdd->td_bushandlep, tartcdd->td_ioaddr + TARTC_OFF_READUSECONDS) ); |
|
} |
|
|
|
|
|
void |
tartc_interrupt(struct device *self) |
tartc_interrupt(struct device *self) |
{ |
{ |
/* TODO */ |
struct tartc_dd *ddp = self->dv_devdata; |
|
|
|
/* process system tick */ |
|
sysclock(); |
|
|
|
/* acknowledge one timer intr */ |
|
bus_write_1(ddp->td_bushandlep, ddp->td_ioaddr + TARTC_OFF_TMRINTRACK, 0xff); |
} |
} |
|
|