[BACK]Return to tartc.c CVS log [TXT][DIR] Up to [local] / funnyos / arch / testarm / dev

File: [local] / funnyos / arch / testarm / dev / tartc.c (download)

Revision 1.4, Sun Nov 4 22:55:58 2007 UTC (16 years, 7 months ago) by init
Branch: MAIN
Changes since 1.3: +16 -1 lines

minimal interrupt handler code: acknowledge pending timer interrupt and trigger clockupdate on device.
in tartc_attach() set timer frequency to 1 Hz.

/*
 * $Id: tartc.c,v 1.4 2007/11/04 22:55:58 init Exp $
 */
#include <sys/types.h>
#include <sys/device.h>
#include <sys/bus.h>

#include <arch/testarm/dev/tartcvar.h>
#include <arch/testarm/dev/tartcreg.h>
#include <libkern/printf.h>

/*
 * testarm Real Time Clock driver.
 */
int 	tartc_attach(struct device *, uint32_t loc, uint8_t flags);
void 	tartc_interrupt(struct device *);


struct driver tartc_dr = {
	sizeof(struct tartc_dd),
	tartc_attach,
	NULL,
	tartc_interrupt
};


int
tartc_attach(struct device *self, uint32_t loc, uint8_t flags)
{
	struct tartc_dd *ddp = self->dv_devdata;
	uint32_t seconds;
	
	/* acquire bus_handle from parent */
	ddp->td_bushandlep = self->dv_parent->dv_aux;

	/* save our location on parent (or use default if loc == 0) */
	ddp->td_ioaddr = (loc != 0) ? loc : TARTC_REG_BASE;

	/*
	 * Read seconds past Epoch.
	 */
	/* trigger clock update on host */
	bus_write_1(ddp->td_bushandlep, ddp->td_ioaddr + TARTC_OFF_CLOCKUPDATE, 1);

	/* get seconds past Epoch */
	seconds = bus_read_4(ddp->td_bushandlep, ddp->td_ioaddr + TARTC_OFF_READSECONDS);

	printf("testarm Real Time Clock (%d seconds past Epoch)\n", seconds);

	/* XXX set timer */
	bus_write_1(ddp->td_bushandlep, ddp->td_ioaddr + TARTC_OFF_TMRINTRFREQ, 1);

	return(0);

}


void
tartc_interrupt(struct device *self)
{
	/* TODO */
	struct tartc_dd *ddp = self->dv_devdata;

	/* acknowledge one timer intr */
	bus_write_1(ddp->td_bushandlep, ddp->td_ioaddr + TARTC_OFF_TMRINTRACK, 0xff);

	/*
	 * Update seconds and print it.
	 */
	bus_write_1(ddp->td_bushandlep, ddp->td_ioaddr + TARTC_OFF_CLOCKUPDATE, 0xff);
	printf("tartc intr: %d seconds past Epoch\n",
		bus_read_4(ddp->td_bushandlep, ddp->td_ioaddr + TARTC_OFF_READSECONDS));

	printf("tartc intr\n");
}