xref: /netbsd-src/sys/arch/emips/stand/common/clock.c (revision 60d0010e25c99fef9d29ed13934d84702b3ee0bb)
1*60d0010eSchristos /*      $NetBSD: clock.c,v 1.2 2014/02/24 22:31:56 christos Exp $ */
25f7e80a8Spooka 
35f7e80a8Spooka /*-
45f7e80a8Spooka  * Copyright (c) 2010 The NetBSD Foundation, Inc.
55f7e80a8Spooka  * Copyright (c) 1999 The NetBSD Foundation, Inc.
65f7e80a8Spooka  * All rights reserved.
75f7e80a8Spooka  *
85f7e80a8Spooka  * This code was written by Alessandro Forin and Neil Pittman
95f7e80a8Spooka  * at Microsoft Research and contributed to The NetBSD Foundation
105f7e80a8Spooka  * by Microsoft Corporation.
115f7e80a8Spooka  *
125f7e80a8Spooka  * Redistribution and use in source and binary forms, with or without
135f7e80a8Spooka  * modification, are permitted provided that the following conditions
145f7e80a8Spooka  * are met:
155f7e80a8Spooka  * 1. Redistributions of source code must retain the above copyright
165f7e80a8Spooka  *    notice, this list of conditions and the following disclaimer.
175f7e80a8Spooka  * 2. Redistributions in binary form must reproduce the above copyright
185f7e80a8Spooka  *    notice, this list of conditions and the following disclaimer in the
195f7e80a8Spooka  *    documentation and/or other materials provided with the distribution.
205f7e80a8Spooka  *
215f7e80a8Spooka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
225f7e80a8Spooka  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
235f7e80a8Spooka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
245f7e80a8Spooka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
255f7e80a8Spooka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
265f7e80a8Spooka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
275f7e80a8Spooka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
285f7e80a8Spooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
295f7e80a8Spooka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
305f7e80a8Spooka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
315f7e80a8Spooka  * POSSIBILITY OF SUCH DAMAGE.
325f7e80a8Spooka  */
335f7e80a8Spooka 
345f7e80a8Spooka #include <sys/types.h>
355f7e80a8Spooka #include <machine/emipsreg.h>
36*60d0010eSchristos #include <lib/libsa/net.h>
375f7e80a8Spooka 
385f7e80a8Spooka #include <stand/common/common.h>
395f7e80a8Spooka 
40*60d0010eSchristos satime_t
getsecs(void)41*60d0010eSchristos getsecs(void)
425f7e80a8Spooka {
435f7e80a8Spooka     struct _Tc *Tc = (struct _Tc *)TIMER_DEFAULT_ADDRESS;
445f7e80a8Spooka 	uint64_t now;
455f7e80a8Spooka     static int inited = 0;
465f7e80a8Spooka 
475f7e80a8Spooka     if (!inited) {
485f7e80a8Spooka         inited = 1;
495f7e80a8Spooka         Tc->Control = TCCT_ENABLE;
505f7e80a8Spooka     }
515f7e80a8Spooka 
525f7e80a8Spooka     /* starts from 0 at powerup, and counts up */
535f7e80a8Spooka 	now = Tc->FreeRunning;
545f7e80a8Spooka #if 0
555f7e80a8Spooka     /* requires full 64bit math support */
565f7e80a8Spooka     now = now / 10*1000*1000;
575f7e80a8Spooka #else
585f7e80a8Spooka     /* good nuf */
595f7e80a8Spooka     now = now >> 23;
605f7e80a8Spooka #endif
615f7e80a8Spooka     return (long) now;
625f7e80a8Spooka }
63