clock.c revision 1.1 1 /* $NetBSD: clock.c,v 1.1 2014/11/22 15:17:02 macallan Exp $ */
2
3 /*-
4 * Copyright (c) 2014 Michael Lorenz
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.1 2014/11/22 15:17:02 macallan Exp $");
31
32 #include <sys/param.h>
33 #include <sys/cpu.h>
34 #include <sys/device.h>
35 #include <sys/kernel.h>
36 #include <sys/systm.h>
37 #include <mips/ingenic/ingenic_regs.h>
38
39 void
40 cpu_initclocks(void)
41 {
42
43 /* timecounter setup and such */
44 }
45
46 /* shamelessly stolen from mips3_clock.c */
47 void
48 delay(int n)
49 {
50 u_long divisor_delay;
51 uint32_t cur, last, delta, usecs;
52
53 last = readreg(JZ_OST_CNT_LO);
54 delta = usecs = 0;
55
56 divisor_delay = curcpu()->ci_divisor_delay;
57 if (divisor_delay == 0) {
58 /*
59 * Frequency values in curcpu() are not initialized.
60 * Assume faster frequency since longer delays are harmless.
61 * Note CPU_MIPS_DOUBLE_COUNT is ignored here.
62 */
63 #define FAST_FREQ (300 * 1000 * 1000) /* fast enough? */
64 divisor_delay = FAST_FREQ / (1000 * 1000);
65 }
66 while (n > usecs) {
67 cur = readreg(JZ_OST_CNT_LO);
68
69 /*
70 * We setup the OS timer to always counts upto UINT32_MAX,
71 * so no need to check wrapped around case.
72 */
73 delta += (cur - last);
74
75 last = cur;
76
77 while (delta >= divisor_delay) {
78 /*
79 * delta is not so larger than divisor_delay here,
80 * and using DIV/DIVU ops could be much slower.
81 * (though longer delay may be harmless)
82 */
83 usecs++;
84 delta -= divisor_delay;
85 }
86 }
87 }
88
89 void
90 setstatclockrate(int r)
91 {
92 /* nothing to see here */
93 }
94