| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: hpet.c,v 1.11 2011/06/15 09:09:48 jruoho Exp $ */ | | 1 | /* $NetBSD: hpet.c,v 1.12 2011/07/29 19:19:14 jakllsch Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2006 Nicolas Joly | | 4 | * Copyright (c) 2006 Nicolas Joly |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -23,27 +23,27 @@ | | | @@ -23,27 +23,27 @@ |
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
28 | * POSSIBILITY OF SUCH DAMAGE. | | 28 | * POSSIBILITY OF SUCH DAMAGE. |
29 | */ | | 29 | */ |
30 | | | 30 | |
31 | /* | | 31 | /* |
32 | * High Precision Event Timer. | | 32 | * High Precision Event Timer. |
33 | */ | | 33 | */ |
34 | | | 34 | |
35 | #include <sys/cdefs.h> | | 35 | #include <sys/cdefs.h> |
36 | __KERNEL_RCSID(0, "$NetBSD: hpet.c,v 1.11 2011/06/15 09:09:48 jruoho Exp $"); | | 36 | __KERNEL_RCSID(0, "$NetBSD: hpet.c,v 1.12 2011/07/29 19:19:14 jakllsch Exp $"); |
37 | | | 37 | |
38 | #include <sys/systm.h> | | 38 | #include <sys/systm.h> |
39 | #include <sys/device.h> | | 39 | #include <sys/device.h> |
40 | #include <sys/module.h> | | 40 | #include <sys/module.h> |
41 | | | 41 | |
42 | #include <sys/time.h> | | 42 | #include <sys/time.h> |
43 | #include <sys/timetc.h> | | 43 | #include <sys/timetc.h> |
44 | | | 44 | |
45 | #include <sys/bus.h> | | 45 | #include <sys/bus.h> |
46 | | | 46 | |
47 | #include <dev/ic/hpetreg.h> | | 47 | #include <dev/ic/hpetreg.h> |
48 | #include <dev/ic/hpetvar.h> | | 48 | #include <dev/ic/hpetvar.h> |
49 | | | 49 | |
| @@ -77,27 +77,28 @@ hpet_attach_subr(device_t dv) | | | @@ -77,27 +77,28 @@ hpet_attach_subr(device_t dv) |
77 | | | 77 | |
78 | tc->tc_name = device_xname(dv); | | 78 | tc->tc_name = device_xname(dv); |
79 | tc->tc_get_timecount = hpet_get_timecount; | | 79 | tc->tc_get_timecount = hpet_get_timecount; |
80 | tc->tc_quality = 2000; | | 80 | tc->tc_quality = 2000; |
81 | | | 81 | |
82 | tc->tc_counter_mask = 0xffffffff; | | 82 | tc->tc_counter_mask = 0xffffffff; |
83 | | | 83 | |
84 | /* Get frequency */ | | 84 | /* Get frequency */ |
85 | val = bus_space_read_4(sc->sc_memt, sc->sc_memh, HPET_PERIOD); | | 85 | val = bus_space_read_4(sc->sc_memt, sc->sc_memh, HPET_PERIOD); |
86 | if (val == 0) { | | 86 | if (val == 0) { |
87 | aprint_error_dev(dv, "invalid timer period\n"); | | 87 | aprint_error_dev(dv, "invalid timer period\n"); |
88 | return; | | 88 | return; |
89 | } | | 89 | } |
90 | tc->tc_frequency = 1000000000000000ULL / val; | | 90 | val = (1000000000000000ULL * 2) / val; |
| | | 91 | tc->tc_frequency = (val / 2) + (val & 1); |
91 | | | 92 | |
92 | /* Enable timer */ | | 93 | /* Enable timer */ |
93 | val = bus_space_read_4(sc->sc_memt, sc->sc_memh, HPET_CONFIG); | | 94 | val = bus_space_read_4(sc->sc_memt, sc->sc_memh, HPET_CONFIG); |
94 | sc->sc_config = val; | | 95 | sc->sc_config = val; |
95 | if ((val & HPET_CONFIG_ENABLE) == 0) { | | 96 | if ((val & HPET_CONFIG_ENABLE) == 0) { |
96 | val |= HPET_CONFIG_ENABLE; | | 97 | val |= HPET_CONFIG_ENABLE; |
97 | bus_space_write_4(sc->sc_memt, sc->sc_memh, HPET_CONFIG, val); | | 98 | bus_space_write_4(sc->sc_memt, sc->sc_memh, HPET_CONFIG, val); |
98 | } | | 99 | } |
99 | | | 100 | |
100 | tc->tc_priv = sc; | | 101 | tc->tc_priv = sc; |
101 | tc_init(tc); | | 102 | tc_init(tc); |
102 | | | 103 | |
103 | if (!pmf_device_register(dv, NULL, hpet_resume)) | | 104 | if (!pmf_device_register(dv, NULL, hpet_resume)) |