[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.2, Mon Oct 29 15:10:34 2007 UTC (16 years, 7 months ago) by init
Branch: MAIN
Changes since 1.1: +32 -4 lines

driver for testarm Real Time Clock; for now it only reads seconds past Epoch on attach;
still more work to do (including design of kernel time stuff, timer interrupt support..)

/*
 * $Id: tartc.c,v 1.2 2007/10/29 15:10:34 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);


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


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);

	return(0);

}