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

Annotation of funnyos/arch/testarm/dev/tartc.c, Revision 1.5

1.1       init        1: /*
1.5     ! init        2:  * $Id: tartc.c,v 1.4 2007/11/04 22:55:58 init Exp $
1.1       init        3:  */
                      4: #include <sys/types.h>
                      5: #include <sys/device.h>
1.2       init        6: #include <sys/bus.h>
                      7:
1.5     ! init        8: #include <sys/kern_time.h>
1.2       init        9: #include <arch/testarm/dev/tartcvar.h>
                     10: #include <arch/testarm/dev/tartcreg.h>
1.1       init       11: #include <libkern/printf.h>
                     12:
                     13: /*
                     14:  * testarm Real Time Clock driver.
                     15:  */
1.2       init       16: int    tartc_attach(struct device *, uint32_t loc, uint8_t flags);
1.3       init       17: void   tartc_interrupt(struct device *);
1.5     ! init       18: void   tartc_sethz(uint8_t hz);
        !            19: uint32_t tartc_getsec(void);
        !            20: uint32_t tartc_getusec(void);
1.2       init       21:
                     22:
1.5     ! init       23: /* default tartc device to use; will bind to first tartc instance */
        !            24: struct tartc_dd *tartcdd = NULL;
        !            25: extern struct rtcops sysrtcops;
        !            26:
1.2       init       27: struct driver tartc_dr = {
                     28:        sizeof(struct tartc_dd),
                     29:        tartc_attach,
1.3       init       30:        NULL,
                     31:        tartc_interrupt
1.2       init       32: };
1.1       init       33:
                     34:
                     35: int
1.2       init       36: tartc_attach(struct device *self, uint32_t loc, uint8_t flags)
1.1       init       37: {
1.2       init       38:        struct tartc_dd *ddp = self->dv_devdata;
                     39:        uint32_t seconds;
1.1       init       40:
1.2       init       41:        /* acquire bus_handle from parent */
                     42:        ddp->td_bushandlep = self->dv_parent->dv_aux;
                     43:
                     44:        /* save our location on parent (or use default if loc == 0) */
                     45:        ddp->td_ioaddr = (loc != 0) ? loc : TARTC_REG_BASE;
                     46:
                     47:        /*
                     48:         * Read seconds past Epoch.
                     49:         */
                     50:        /* trigger clock update on host */
                     51:        bus_write_1(ddp->td_bushandlep, ddp->td_ioaddr + TARTC_OFF_CLOCKUPDATE, 1);
                     52:
                     53:        /* get seconds past Epoch */
                     54:        seconds = bus_read_4(ddp->td_bushandlep, ddp->td_ioaddr + TARTC_OFF_READSECONDS);
                     55:
                     56:        printf("testarm Real Time Clock (%d seconds past Epoch)\n", seconds);
1.1       init       57:
1.5     ! init       58:        /* set default tartc */
        !            59:        tartcdd = ddp;
        !            60:
        !            61:        /* fill-in rtcops to be used by kern_time */
        !            62:        sysrtcops.ro_sethz = tartc_sethz;
        !            63:        sysrtcops.ro_getsec = tartc_getsec;
        !            64:        sysrtcops.ro_getusec = tartc_getusec;
1.4       init       65:
1.1       init       66:        return(0);
1.3       init       67:
                     68: }
                     69:
                     70:
                     71: void
1.5     ! init       72: tartc_sethz(uint8_t hz)
        !            73: {
        !            74:        /*
        !            75:         * Set timer frequency.
        !            76:         */
        !            77:        if (tartcdd == NULL)
        !            78:                panic("can't calibrate not configured timer\n");
        !            79:
        !            80:        bus_write_1(tartcdd->td_bushandlep, tartcdd->td_ioaddr + TARTC_OFF_TMRINTRFREQ, hz);
        !            81: }
        !            82:
        !            83:
        !            84: uint32_t
        !            85: tartc_getsec(void)
        !            86: {
        !            87:        /*
        !            88:         * Get seconds.
        !            89:         */
        !            90:        if (tartcdd == NULL)
        !            91:                panic("tartc_getsec: can't get seconds from rtc: default device not configured\n");
        !            92:
        !            93:        /* trigger clock update on host */
        !            94:        bus_write_1(tartcdd->td_bushandlep, tartcdd->td_ioaddr + TARTC_OFF_CLOCKUPDATE, 1);
        !            95:
        !            96:        return( bus_read_4(tartcdd->td_bushandlep, tartcdd->td_ioaddr + TARTC_OFF_READSECONDS) );
        !            97: }
        !            98:
        !            99:
        !           100: uint32_t
        !           101: tartc_getusec(void)
        !           102: {
        !           103:        /*
        !           104:         * Get microseconds.
        !           105:         */
        !           106:        if (tartcdd == NULL)
        !           107:                panic("tartc_getusec: can't get microseconds from rtc: default device not configured\n");
        !           108:
        !           109:        /* trigger clock update on host */
        !           110:        bus_write_1(tartcdd->td_bushandlep, tartcdd->td_ioaddr + TARTC_OFF_CLOCKUPDATE, 1);
        !           111:
        !           112:        return( bus_read_4(tartcdd->td_bushandlep, tartcdd->td_ioaddr + TARTC_OFF_READUSECONDS) );
        !           113: }
        !           114:
        !           115:
        !           116: void
1.3       init      117: tartc_interrupt(struct device *self)
                    118: {
1.4       init      119:        struct tartc_dd *ddp = self->dv_devdata;
                    120:
1.5     ! init      121:        /* process system tick */
        !           122:        sysclock();
        !           123:
1.4       init      124:        /* acknowledge one timer intr */
                    125:        bus_write_1(ddp->td_bushandlep, ddp->td_ioaddr + TARTC_OFF_TMRINTRACK, 0xff);
1.1       init      126: }
                    127:

CVSweb